forked from cifsd-team/ksmbd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransport_tcp.c
777 lines (659 loc) · 17.8 KB
/
transport_tcp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (C) 2016 Namjae Jeon <[email protected]>
* Copyright (C) 2018 Samsung Electronics Co., Ltd.
*/
#include <linux/mutex.h>
#include "server.h"
#include "auth.h"
#include "buffer_pool.h"
#include "transport_tcp.h"
#include "mgmt/cifsd_ida.h"
#include "smb_common.h"
static struct task_struct *cifsd_kthread;
static struct socket *cifsd_socket = NULL;
static struct cifsd_tcp_conn_ops default_tcp_conn_ops;
static DEFINE_MUTEX(init_lock);
static LIST_HEAD(tcp_conn_list);
static DEFINE_RWLOCK(tcp_conn_list_lock);
#define CIFSD_TCP_RECV_TIMEOUT (7 * HZ)
#define CIFSD_TCP_SEND_TIMEOUT (5 * HZ)
static inline void cifsd_tcp_cork(struct socket *sock)
{
int val = 1;
kernel_setsockopt(sock, SOL_TCP, TCP_CORK,
(char *)&val, sizeof(val));
}
static inline void cifsd_tcp_uncork(struct socket *sock)
{
int val = 0;
kernel_setsockopt(sock, SOL_TCP, TCP_CORK,
(char *)&val, sizeof(val));
}
static inline void cifsd_tcp_nodelay(struct socket *sock)
{
int val = 1;
kernel_setsockopt(sock, SOL_TCP, TCP_NODELAY,
(char *)&val, sizeof(val));
}
static inline void cifsd_tcp_reuseaddr(struct socket *sock)
{
int val = 1;
kernel_setsockopt(sock, SOL_TCP, SO_REUSEADDR,
(char *)&val, sizeof(val));
}
static bool cifsd_tcp_conn_alive(struct cifsd_tcp_conn *conn)
{
if (!cifsd_server_running())
return false;
if (conn->tcp_status == CIFSD_SESS_EXITING)
return false;
if (kthread_should_stop())
return false;
if (conn->stats.open_files_count > 0)
return true;
/*
* Stop current session if the time that get last request from client
* is bigger than deadtime user configured and openning file count is
* zero.
*/
if (server_conf.deadtime > 0 &&
time_after(jiffies, conn->last_active + server_conf.deadtime)) {
cifsd_debug("No response from client in %lu minutes\n",
server_conf.deadtime);
return false;
}
return true;
}
/**
* cifsd_tcp_conn_free() - shutdown/release the socket and free server
* resources
* @conn: - server instance for which socket is to be cleaned
*
* During the thread termination, the corresponding conn instance
* resources(sock/memory) are released and finally the conn object is freed.
*/
static void cifsd_tcp_conn_free(struct cifsd_tcp_conn *conn)
{
write_lock(&tcp_conn_list_lock);
list_del(&conn->tcp_conns);
write_unlock(&tcp_conn_list_lock);
kernel_sock_shutdown(conn->sock, SHUT_RDWR);
sock_release(conn->sock);
conn->sock = NULL;
cifsd_free_conn_secmech(conn);
cifsd_free_request(conn->request_buf);
cifsd_ida_free(conn->async_ida);
kfree(conn->preauth_info);
kfree(conn);
}
/**
* cifsd_tcp_conn_alloc() - initialize tcp server thread for a new connection
* @conn: TCP server instance of connection
* @sock: socket associated with new connection
*
* Return: 0 on success, otherwise -ENOMEM
*/
static struct cifsd_tcp_conn *cifsd_tcp_conn_alloc(struct socket *sock)
{
struct cifsd_tcp_conn *conn;
conn = kzalloc(sizeof(struct cifsd_tcp_conn), GFP_KERNEL);
if (!conn)
return NULL;
conn->need_neg = true;
conn->tcp_status = CIFSD_SESS_NEW;
conn->sock = sock;
conn->local_nls = load_nls("utf8");
if (!conn->local_nls)
conn->local_nls = load_nls_default();
atomic_set(&conn->req_running, 0);
atomic_set(&conn->r_count, 0);
conn->max_credits = 0;
conn->credits_granted = 0;
init_waitqueue_head(&conn->req_running_q);
INIT_LIST_HEAD(&conn->tcp_conns);
INIT_LIST_HEAD(&conn->sessions);
INIT_LIST_HEAD(&conn->requests);
INIT_LIST_HEAD(&conn->async_requests);
spin_lock_init(&conn->request_lock);
conn->srv_cap = 0;
conn->async_ida = cifsd_ida_alloc();
write_lock(&tcp_conn_list_lock);
list_add(&conn->tcp_conns, &tcp_conn_list);
write_unlock(&tcp_conn_list_lock);
return conn;
}
/**
* kvec_array_init() - initialize a IO vector segment
* @new: IO vector to be intialized
* @iov: base IO vector
* @nr_segs: number of segments in base iov
* @bytes: total iovec length so far for read
*
* Return: Number of IO segments
*/
static unsigned int kvec_array_init(struct kvec *new, struct kvec *iov,
unsigned int nr_segs, size_t bytes)
{
size_t base = 0;
while (bytes || !iov->iov_len) {
int copy = min(bytes, iov->iov_len);
bytes -= copy;
base += copy;
if (iov->iov_len == base) {
iov++;
nr_segs--;
base = 0;
}
}
memcpy(new, iov, sizeof(*iov) * nr_segs);
new->iov_base += base;
new->iov_len -= base;
return nr_segs;
}
/**
* get_conn_iovec() - get connection iovec for reading from socket
* @conn: TCP server instance of connection
* @nr_segs: number of segments in iov
*
* Return: return existing or newly allocate iovec
*/
static struct kvec *get_conn_iovec(struct cifsd_tcp_conn *conn,
unsigned int nr_segs)
{
struct kvec *new_iov;
if (conn->iov && nr_segs <= conn->nr_iov)
return conn->iov;
/* not big enough -- allocate a new one and release the old */
new_iov = kmalloc(sizeof(*new_iov) * nr_segs, GFP_KERNEL);
if (new_iov) {
kfree(conn->iov);
conn->iov = new_iov;
conn->nr_iov = nr_segs;
}
return new_iov;
}
/**
* cifsd_tcp_conn_handler_loop() - session thread to listen on new smb requests
* @p: TCP conn instance of connection
*
* One thread each per connection
*
* Return: 0 on success
*/
static int cifsd_tcp_conn_handler_loop(void *p)
{
struct cifsd_tcp_conn *conn = (struct cifsd_tcp_conn *)p;
unsigned int pdu_size;
char hdr_buf[4] = {0,};
int size;
mutex_init(&conn->srv_mutex);
__module_get(THIS_MODULE);
conn->last_active = jiffies;
while (cifsd_tcp_conn_alive(conn)) {
if (try_to_freeze())
continue;
cifsd_free_request(conn->request_buf);
conn->request_buf = NULL;
size = cifsd_tcp_read(conn, hdr_buf, sizeof(hdr_buf));
if (size != sizeof(hdr_buf))
break;
pdu_size = get_rfc1002_length(hdr_buf);
cifsd_debug("RFC1002 header %u bytes\n", pdu_size);
/* make sure we have enough to get to SMB header end */
if (!cifsd_pdu_size_has_room(pdu_size)) {
cifsd_debug("SMB request too short (%u bytes)\n",
pdu_size);
continue;
}
/* 4 for rfc1002 length field */
size = pdu_size + 4;
conn->request_buf = cifsd_alloc_request(size);
if (!conn->request_buf)
continue;
memcpy(conn->request_buf, hdr_buf, sizeof(hdr_buf));
if (!cifsd_smb_request(conn))
break;
/*
* We already read 4 bytes to find out PDU size, now
* read in PDU
*/
size = cifsd_tcp_read(conn, conn->request_buf + 4, pdu_size);
if (size < 0) {
cifsd_err("sock_read failed: %d\n", size);
break;
}
if (size != pdu_size) {
cifsd_err("PDU error. Read: %d, Expected: %d\n",
size,
pdu_size);
continue;
}
if (!conn->conn_ops->process_fn) {
cifsd_err("No connection request callback\n");
break;
}
if (conn->conn_ops->process_fn(conn)) {
cifsd_err("Cannot handle request\n");
break;
}
}
/* Wait till all reference dropped to the Server object*/
while (atomic_read(&conn->r_count) > 0)
schedule_timeout(HZ);
unload_nls(conn->local_nls);
if (conn->conn_ops->terminate_fn)
conn->conn_ops->terminate_fn(conn);
cifsd_tcp_conn_free(conn);
module_put(THIS_MODULE);
return 0;
}
static unsigned short cifsd_tcp_get_port(const struct sockaddr *sa)
{
switch (sa->sa_family) {
case AF_INET:
return ntohs(((struct sockaddr_in *)sa)->sin_port);
case AF_INET6:
return ntohs(((struct sockaddr_in6 *)sa)->sin6_port);
}
return 0;
}
/**
* cifsd_tcp_new_connection() - create a new tcp session on mount
* @sock: socket associated with new connection
*
* whenever a new connection is requested, create a conn thread
* (session thread) to handle new incoming smb requests from the connection
*
* Return: 0 on success, otherwise error
*/
static int cifsd_tcp_new_connection(struct socket *client_sk)
{
struct sockaddr *csin;
int rc = 0;
struct cifsd_tcp_conn *conn;
conn = cifsd_tcp_conn_alloc(client_sk);
if (!conn)
return -ENOMEM;
csin = CIFSD_TCP_PEER_SOCKADDR(conn);
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 16, 0)
if (kernel_getpeername(client_sk, csin, &rc) < 0) {
cifsd_err("client ip resolution failed\n");
rc = -EINVAL;
goto out_error;
}
rc = 0;
#else
if (kernel_getpeername(client_sk, csin) < 0) {
cifsd_err("client ip resolution failed\n");
rc = -EINVAL;
goto out_error;
}
#endif
conn->conn_ops = &default_tcp_conn_ops;
conn->handler = kthread_run(cifsd_tcp_conn_handler_loop,
conn,
"kcifsd:%u",
cifsd_tcp_get_port(csin));
if (IS_ERR(conn->handler)) {
cifsd_err("cannot start conn thread\n");
rc = PTR_ERR(conn->handler);
cifsd_tcp_conn_free(conn);
}
return rc;
out_error:
cifsd_tcp_conn_free(conn);
return rc;
}
/**
* cifsd_kthread_fn() - listen to new SMB connections and callback server
* @p: arguments to forker thread
*
* Return: Returns a task_struct or ERR_PTR
*/
static int cifsd_kthread_fn(void *p)
{
struct socket *client_sk = NULL;
int ret;
while (!kthread_should_stop()) {
if (cifsd_server_daemon_heartbeat()) {
schedule_timeout_interruptible(HZ);
continue;
}
ret = kernel_accept(cifsd_socket, &client_sk, O_NONBLOCK);
if (ret) {
if (ret == -EAGAIN)
/* check for new connections every 100 msecs */
schedule_timeout_interruptible(HZ / 10);
continue;
}
cifsd_debug("connect success: accepted new connection\n");
client_sk->sk->sk_rcvtimeo = 7 * HZ;
client_sk->sk->sk_sndtimeo = 5 * HZ;
cifsd_tcp_new_connection(client_sk);
}
cifsd_debug("releasing socket\n");
return 0;
}
/**
* cifsd_create_cifsd_kthread() - start forker thread
*
* start forker thread(kcifsd/0) at module init time to listen
* on port 445 for new SMB connection requests. It creates per connection
* server threads(kcifsd/x)
*
* Return: 0 on success or error number
*/
static int cifsd_tcp_run_kthread(void)
{
int rc;
cifsd_kthread = kthread_run(cifsd_kthread_fn, NULL, "kcifsd");
if (IS_ERR(cifsd_kthread)) {
rc = PTR_ERR(cifsd_kthread);
cifsd_kthread = NULL;
return rc;
}
return 0;
}
/**
* cifsd_tcp_readv() - read data from socket in given iovec
* @conn: TCP server instance of connection
* @iov_orig: base IO vector
* @nr_segs: number of segments in base iov
* @to_read: number of bytes to read from socket
*
* Return: on success return number of bytes read from socket,
* otherwise return error number
*/
static int cifsd_tcp_readv(struct cifsd_tcp_conn *conn,
struct kvec *iov_orig,
unsigned int nr_segs,
unsigned int to_read)
{
int length = 0;
int total_read;
unsigned int segs;
struct msghdr cifsd_msg;
struct kvec *iov;
iov = get_conn_iovec(conn, nr_segs);
if (!iov)
return -ENOMEM;
cifsd_msg.msg_control = NULL;
cifsd_msg.msg_controllen = 0;
for (total_read = 0; to_read; total_read += length, to_read -= length) {
try_to_freeze();
if (!cifsd_tcp_conn_alive(conn)) {
total_read = -ESHUTDOWN;
break;
}
segs = kvec_array_init(iov, iov_orig, nr_segs, total_read);
length = kernel_recvmsg(conn->sock, &cifsd_msg,
iov, segs, to_read, 0);
if (length == -EINTR) {
total_read = -ESHUTDOWN;
break;
} else if (conn->tcp_status == CIFSD_SESS_NEED_RECONNECT) {
total_read = -EAGAIN;
break;
} else if (length == -ERESTARTSYS || length == -EAGAIN) {
usleep_range(1000, 2000);
length = 0;
continue;
} else if (length <= 0) {
total_read = -EAGAIN;
break;
}
}
return total_read;
}
/**
* cifsd_tcp_read() - read data from socket in given buffer
* @conn: TCP server instance of connection
* @buf: buffer to store read data from socket
* @to_read: number of bytes to read from socket
*
* Return: on success return number of bytes read from socket,
* otherwise return error number
*/
int cifsd_tcp_read(struct cifsd_tcp_conn *conn,
char *buf,
unsigned int to_read)
{
struct kvec iov;
iov.iov_base = buf;
iov.iov_len = to_read;
return cifsd_tcp_readv(conn, &iov, 1, to_read);
}
/**
* cifsd_tcp_write() - send smb response over network socket
* @cifsd_work: smb work containing response buffer
*
* TODO: change this function for smb2 currently is working for
* smb1/smb2 both as smb*_buf_length is at beginning of the packet
*
* Return: 0 on success, otherwise error
*/
int cifsd_tcp_write(struct cifsd_work *work)
{
struct cifsd_tcp_conn *conn = work->conn;
struct smb_hdr *rsp_hdr = RESPONSE_BUF(work);
struct msghdr smb_msg = {.msg_flags = MSG_NOSIGNAL};
size_t len = 0;
int sent;
struct kvec iov[3];
int iov_idx = 0;
cifsd_tcp_try_dequeue_request(work);
if (!rsp_hdr) {
cifsd_err("NULL response header\n");
return -EINVAL;
}
if (HAS_TRANSFORM_BUF(work)) {
iov[iov_idx] = (struct kvec) { work->tr_buf,
sizeof(struct smb2_transform_hdr) };
len += iov[iov_idx++].iov_len;
}
if (HAS_AUX_PAYLOAD(work)) {
iov[iov_idx] = (struct kvec) { rsp_hdr, RESP_HDR_SIZE(work) };
len += iov[iov_idx++].iov_len;
iov[iov_idx] = (struct kvec) { AUX_PAYLOAD(work),
AUX_PAYLOAD_SIZE(work) };
len += iov[iov_idx++].iov_len;
cifsd_tcp_cork(conn->sock);
} else {
if (HAS_TRANSFORM_BUF(work))
iov[iov_idx].iov_len = RESP_HDR_SIZE(work);
else
iov[iov_idx].iov_len =
get_rfc1002_length(rsp_hdr) + 4;
iov[iov_idx].iov_base = rsp_hdr;
len += iov[iov_idx++].iov_len;
}
sent = kernel_sendmsg(conn->sock, &smb_msg, iov, iov_idx, len);
if (HAS_AUX_PAYLOAD(work))
cifsd_tcp_uncork(conn->sock);
if (sent < 0) {
cifsd_err("Failed to send message: %d\n", sent);
return sent;
}
return 0;
}
void cifsd_tcp_conn_lock(struct cifsd_tcp_conn *conn)
{
mutex_lock(&conn->srv_mutex);
atomic_inc(&conn->req_running);
}
void cifsd_tcp_conn_unlock(struct cifsd_tcp_conn *conn)
{
atomic_dec(&conn->req_running);
mutex_unlock(&conn->srv_mutex);
if (waitqueue_active(&conn->req_running_q))
wake_up_all(&conn->req_running_q);
}
void cifsd_tcp_conn_wait_idle(struct cifsd_tcp_conn *conn)
{
wait_event(conn->req_running_q, atomic_read(&conn->req_running) < 2);
}
int cifsd_tcp_for_each_conn(int (*match)(struct cifsd_tcp_conn *, void *),
void *arg)
{
struct cifsd_tcp_conn *t;
int ret = 0;
read_lock(&tcp_conn_list_lock);
list_for_each_entry(t, &tcp_conn_list, tcp_conns)
if (match(t, arg)) {
ret = 1;
break;
}
read_unlock(&tcp_conn_list_lock);
return ret;
}
static void tcp_destroy_socket(void)
{
int ret;
if (!cifsd_socket)
return;
ret = kernel_sock_shutdown(cifsd_socket, SHUT_RDWR);
if (ret) {
cifsd_err("Failed to shutdown socket: %d\n", ret);
} else {
sock_release(cifsd_socket);
cifsd_socket = NULL;
}
}
/**
* cifsd_tcp_init - create socket for kcifsd/0
*
* Return: Returns a task_struct or ERR_PTR
*/
int cifsd_tcp_init(void)
{
int ret;
struct sockaddr_in sin;
struct interface *iface;
struct list_head *tmp;
mutex_lock(&init_lock);
if (cifsd_socket) {
mutex_unlock(&init_lock);
return 0;
}
ret = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &cifsd_socket);
if (ret) {
cifsd_err("Can't create socket: %d\n", ret);
goto out_error;
}
sin.sin_addr.s_addr = htonl(INADDR_ANY);
sin.sin_family = PF_INET;
sin.sin_port = htons(server_conf.tcp_port);
cifsd_tcp_nodelay(cifsd_socket);
cifsd_tcp_reuseaddr(cifsd_socket);
list_for_each(tmp, &server_conf.iface_list) {
iface = list_entry(tmp, struct interface, entry);
ret = kernel_setsockopt(cifsd_socket, SOL_SOCKET,
SO_BINDTODEVICE, iface->name, strlen(iface->name));
if (ret != -ENODEV && ret < 0) {
cifsd_err("Failed to set SO_BINDTODEVICE: %d\n", ret);
goto out_error;
}
}
ret = kernel_bind(cifsd_socket, (struct sockaddr *)&sin, sizeof(sin));
if (ret) {
cifsd_err("Failed to bind socket: %d\n", ret);
goto out_error;
}
cifsd_socket->sk->sk_rcvtimeo = CIFSD_TCP_RECV_TIMEOUT;
cifsd_socket->sk->sk_sndtimeo = CIFSD_TCP_SEND_TIMEOUT;
ret = cifsd_socket->ops->listen(cifsd_socket, CIFSD_SOCKET_BACKLOG);
if (ret) {
cifsd_err("Port listen() error: %d\n", ret);
goto out_error;
}
ret = cifsd_tcp_run_kthread();
if (ret) {
cifsd_err("Can't start cifsd main kthread: %d\n", ret);
goto out_error;
}
mutex_unlock(&init_lock);
return 0;
out_error:
tcp_destroy_socket();
mutex_unlock(&init_lock);
return ret;
}
static void tcp_stop_sessions(void)
{
struct cifsd_tcp_conn *conn;
again:
read_lock(&tcp_conn_list_lock);
list_for_each_entry(conn, &tcp_conn_list, tcp_conns) {
conn->tcp_status = CIFSD_SESS_EXITING;
cifsd_err("Stop session handler %s/%d\n",
conn->handler->comm,
task_pid_nr(conn->handler));
}
read_unlock(&tcp_conn_list_lock);
if (!list_empty(&tcp_conn_list)) {
schedule_timeout_interruptible(CIFSD_TCP_RECV_TIMEOUT / 2);
goto again;
}
}
static void tcp_stop_kthread(void)
{
int ret;
if (!cifsd_kthread)
return;
ret = kthread_stop(cifsd_kthread);
if (ret)
cifsd_err("failed to stop forker thread\n");
else
cifsd_kthread = NULL;
}
void cifsd_tcp_destroy(void)
{
mutex_lock(&init_lock);
tcp_destroy_socket();
tcp_stop_kthread();
tcp_stop_sessions();
mutex_unlock(&init_lock);
}
void cifsd_tcp_enqueue_request(struct cifsd_work *work)
{
struct cifsd_tcp_conn *conn = work->conn;
struct list_head *requests_queue = NULL;
struct smb2_hdr *hdr = REQUEST_BUF(work);
if (hdr->ProtocolId == SMB2_PROTO_NUMBER) {
unsigned int command = conn->ops->get_cmd_val(work);
if (command != SMB2_CANCEL) {
requests_queue = &conn->requests;
work->type = SYNC;
}
} else {
if (conn->ops->get_cmd_val(work) != SMB_COM_NT_CANCEL)
requests_queue = &conn->requests;
}
if (requests_queue) {
spin_lock(&conn->request_lock);
list_add_tail(&work->request_entry, requests_queue);
work->on_request_list = 1;
spin_unlock(&conn->request_lock);
}
}
int cifsd_tcp_try_dequeue_request(struct cifsd_work *work)
{
struct cifsd_tcp_conn *conn = work->conn;
int ret = 1;
if (!work->on_request_list)
return 0;
spin_lock(&conn->request_lock);
if (!work->multiRsp) {
list_del_init(&work->request_entry);
work->on_request_list = 0;
ret = 0;
}
spin_unlock(&conn->request_lock);
return ret;
}
void cifsd_tcp_init_server_callbacks(struct cifsd_tcp_conn_ops *ops)
{
default_tcp_conn_ops.process_fn = ops->process_fn;
default_tcp_conn_ops.terminate_fn = ops->terminate_fn;
}