hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/cifs/transport.c
....@@ -33,6 +33,7 @@
3333 #include <linux/uaccess.h>
3434 #include <asm/processor.h>
3535 #include <linux/mempool.h>
36
+#include <linux/sched/signal.h>
3637 #include "cifspdu.h"
3738 #include "cifsglob.h"
3839 #include "cifsproto.h"
....@@ -75,6 +76,8 @@
7576 * The default is for the mid to be synchronous, so the
7677 * default callback just wakes up the current task.
7778 */
79
+ get_task_struct(current);
80
+ temp->creator = current;
7881 temp->callback = cifs_wake_up_task;
7982 temp->callback_data = current;
8083
....@@ -85,10 +88,81 @@
8588
8689 static void _cifs_mid_q_entry_release(struct kref *refcount)
8790 {
88
- struct mid_q_entry *mid = container_of(refcount, struct mid_q_entry,
89
- refcount);
91
+ struct mid_q_entry *midEntry =
92
+ container_of(refcount, struct mid_q_entry, refcount);
93
+#ifdef CONFIG_CIFS_STATS2
94
+ __le16 command = midEntry->server->vals->lock_cmd;
95
+ __u16 smb_cmd = le16_to_cpu(midEntry->command);
96
+ unsigned long now;
97
+ unsigned long roundtrip_time;
98
+#endif
99
+ struct TCP_Server_Info *server = midEntry->server;
90100
91
- mempool_free(mid, cifs_mid_poolp);
101
+ if (midEntry->resp_buf && (midEntry->mid_flags & MID_WAIT_CANCELLED) &&
102
+ midEntry->mid_state == MID_RESPONSE_RECEIVED &&
103
+ server->ops->handle_cancelled_mid)
104
+ server->ops->handle_cancelled_mid(midEntry, server);
105
+
106
+ midEntry->mid_state = MID_FREE;
107
+ atomic_dec(&midCount);
108
+ if (midEntry->large_buf)
109
+ cifs_buf_release(midEntry->resp_buf);
110
+ else
111
+ cifs_small_buf_release(midEntry->resp_buf);
112
+#ifdef CONFIG_CIFS_STATS2
113
+ now = jiffies;
114
+ if (now < midEntry->when_alloc)
115
+ cifs_server_dbg(VFS, "Invalid mid allocation time\n");
116
+ roundtrip_time = now - midEntry->when_alloc;
117
+
118
+ if (smb_cmd < NUMBER_OF_SMB2_COMMANDS) {
119
+ if (atomic_read(&server->num_cmds[smb_cmd]) == 0) {
120
+ server->slowest_cmd[smb_cmd] = roundtrip_time;
121
+ server->fastest_cmd[smb_cmd] = roundtrip_time;
122
+ } else {
123
+ if (server->slowest_cmd[smb_cmd] < roundtrip_time)
124
+ server->slowest_cmd[smb_cmd] = roundtrip_time;
125
+ else if (server->fastest_cmd[smb_cmd] > roundtrip_time)
126
+ server->fastest_cmd[smb_cmd] = roundtrip_time;
127
+ }
128
+ cifs_stats_inc(&server->num_cmds[smb_cmd]);
129
+ server->time_per_cmd[smb_cmd] += roundtrip_time;
130
+ }
131
+ /*
132
+ * commands taking longer than one second (default) can be indications
133
+ * that something is wrong, unless it is quite a slow link or a very
134
+ * busy server. Note that this calc is unlikely or impossible to wrap
135
+ * as long as slow_rsp_threshold is not set way above recommended max
136
+ * value (32767 ie 9 hours) and is generally harmless even if wrong
137
+ * since only affects debug counters - so leaving the calc as simple
138
+ * comparison rather than doing multiple conversions and overflow
139
+ * checks
140
+ */
141
+ if ((slow_rsp_threshold != 0) &&
142
+ time_after(now, midEntry->when_alloc + (slow_rsp_threshold * HZ)) &&
143
+ (midEntry->command != command)) {
144
+ /*
145
+ * smb2slowcmd[NUMBER_OF_SMB2_COMMANDS] counts by command
146
+ * NB: le16_to_cpu returns unsigned so can not be negative below
147
+ */
148
+ if (smb_cmd < NUMBER_OF_SMB2_COMMANDS)
149
+ cifs_stats_inc(&server->smb2slowcmd[smb_cmd]);
150
+
151
+ trace_smb3_slow_rsp(smb_cmd, midEntry->mid, midEntry->pid,
152
+ midEntry->when_sent, midEntry->when_received);
153
+ if (cifsFYI & CIFS_TIMER) {
154
+ pr_debug("slow rsp: cmd %d mid %llu",
155
+ midEntry->command, midEntry->mid);
156
+ cifs_info("A: 0x%lx S: 0x%lx R: 0x%lx\n",
157
+ now - midEntry->when_alloc,
158
+ now - midEntry->when_sent,
159
+ now - midEntry->when_received);
160
+ }
161
+ }
162
+#endif
163
+ put_task_struct(midEntry->creator);
164
+
165
+ mempool_free(midEntry, cifs_mid_poolp);
92166 }
93167
94168 void cifs_mid_q_entry_release(struct mid_q_entry *midEntry)
....@@ -98,43 +172,8 @@
98172 spin_unlock(&GlobalMid_Lock);
99173 }
100174
101
-void
102
-DeleteMidQEntry(struct mid_q_entry *midEntry)
175
+void DeleteMidQEntry(struct mid_q_entry *midEntry)
103176 {
104
-#ifdef CONFIG_CIFS_STATS2
105
- __le16 command = midEntry->server->vals->lock_cmd;
106
- unsigned long now;
107
-#endif
108
- midEntry->mid_state = MID_FREE;
109
- atomic_dec(&midCount);
110
- if (midEntry->large_buf)
111
- cifs_buf_release(midEntry->resp_buf);
112
- else
113
- cifs_small_buf_release(midEntry->resp_buf);
114
-#ifdef CONFIG_CIFS_STATS2
115
- now = jiffies;
116
- /* commands taking longer than one second are indications that
117
- something is wrong, unless it is quite a slow link or server */
118
- if (time_after(now, midEntry->when_alloc + HZ) &&
119
- (midEntry->command != command)) {
120
- /* smb2slowcmd[NUMBER_OF_SMB2_COMMANDS] counts by command */
121
- if ((le16_to_cpu(midEntry->command) < NUMBER_OF_SMB2_COMMANDS) &&
122
- (le16_to_cpu(midEntry->command) >= 0))
123
- cifs_stats_inc(&midEntry->server->smb2slowcmd[le16_to_cpu(midEntry->command)]);
124
-
125
- trace_smb3_slow_rsp(le16_to_cpu(midEntry->command),
126
- midEntry->mid, midEntry->pid,
127
- midEntry->when_sent, midEntry->when_received);
128
- if (cifsFYI & CIFS_TIMER) {
129
- pr_debug(" CIFS slow rsp: cmd %d mid %llu",
130
- midEntry->command, midEntry->mid);
131
- pr_info(" A: 0x%lx S: 0x%lx R: 0x%lx\n",
132
- now - midEntry->when_alloc,
133
- now - midEntry->when_sent,
134
- now - midEntry->when_received);
135
- }
136
- }
137
-#endif
138177 cifs_mid_q_entry_release(midEntry);
139178 }
140179
....@@ -142,8 +181,10 @@
142181 cifs_delete_mid(struct mid_q_entry *mid)
143182 {
144183 spin_lock(&GlobalMid_Lock);
145
- list_del_init(&mid->qhead);
146
- mid->mid_flags |= MID_DELETED;
184
+ if (!(mid->mid_flags & MID_DELETED)) {
185
+ list_del_init(&mid->qhead);
186
+ mid->mid_flags |= MID_DELETED;
187
+ }
147188 spin_unlock(&GlobalMid_Lock);
148189
149190 DeleteMidQEntry(mid);
....@@ -168,10 +209,6 @@
168209
169210 *sent = 0;
170211
171
- smb_msg->msg_name = (struct sockaddr *) &server->dstaddr;
172
- smb_msg->msg_namelen = sizeof(struct sockaddr);
173
- smb_msg->msg_control = NULL;
174
- smb_msg->msg_controllen = 0;
175212 if (server->noblocksnd)
176213 smb_msg->msg_flags = MSG_DONTWAIT + MSG_NOSIGNAL;
177214 else
....@@ -201,7 +238,7 @@
201238 retries++;
202239 if (retries >= 14 ||
203240 (!server->noblocksnd && (retries > 2))) {
204
- cifs_dbg(VFS, "sends on sock %p stuck for 15 seconds\n",
241
+ cifs_server_dbg(VFS, "sends on sock %p stuck for 15 seconds\n",
205242 ssocket);
206243 return -EAGAIN;
207244 }
....@@ -215,7 +252,7 @@
215252 if (rc == 0) {
216253 /* should never happen, letting socket clear before
217254 retrying is our only obvious option here */
218
- cifs_dbg(VFS, "tcp sent no data\n");
255
+ cifs_server_dbg(VFS, "tcp sent no data\n");
219256 msleep(500);
220257 continue;
221258 }
....@@ -275,17 +312,18 @@
275312 __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
276313 struct smb_rqst *rqst)
277314 {
278
- int rc = 0;
315
+ int rc;
279316 struct kvec *iov;
280317 int n_vec;
281318 unsigned int send_length = 0;
282319 unsigned int i, j;
320
+ sigset_t mask, oldmask;
283321 size_t total_len = 0, sent, size;
284322 struct socket *ssocket = server->ssocket;
285
- struct msghdr smb_msg;
286
- int val = 1;
323
+ struct msghdr smb_msg = {};
287324 __be32 rfc1002_marker;
288325
326
+ cifs_in_send_inc(server);
289327 if (cifs_rdma_enabled(server)) {
290328 /* return -EAGAIN when connecting or reconnecting */
291329 rc = -EAGAIN;
....@@ -293,16 +331,34 @@
293331 rc = smbd_send(server, num_rqst, rqst);
294332 goto smbd_done;
295333 }
296
- if (ssocket == NULL)
297
- return -ENOTSOCK;
298334
335
+ rc = -EAGAIN;
336
+ if (ssocket == NULL)
337
+ goto out;
338
+
339
+ rc = -ERESTARTSYS;
340
+ if (fatal_signal_pending(current)) {
341
+ cifs_dbg(FYI, "signal pending before send request\n");
342
+ goto out;
343
+ }
344
+
345
+ rc = 0;
299346 /* cork the socket */
300
- kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK,
301
- (char *)&val, sizeof(val));
347
+ tcp_sock_set_cork(ssocket->sk, true);
302348
303349 for (j = 0; j < num_rqst; j++)
304350 send_length += smb_rqst_len(server, &rqst[j]);
305351 rfc1002_marker = cpu_to_be32(send_length);
352
+
353
+ /*
354
+ * We should not allow signals to interrupt the network send because
355
+ * any partial send will cause session reconnects thus increasing
356
+ * latency of system calls and overload a server with unnecessary
357
+ * requests.
358
+ */
359
+
360
+ sigfillset(&mask);
361
+ sigprocmask(SIG_BLOCK, &mask, &oldmask);
306362
307363 /* Generate a rfc1002 marker for SMB2+ */
308364 if (server->vals->header_preamble_size == 0) {
....@@ -310,11 +366,10 @@
310366 .iov_base = &rfc1002_marker,
311367 .iov_len = 4
312368 };
313
- iov_iter_kvec(&smb_msg.msg_iter, WRITE | ITER_KVEC, &hiov,
314
- 1, 4);
369
+ iov_iter_kvec(&smb_msg.msg_iter, WRITE, &hiov, 1, 4);
315370 rc = smb_send_kvec(server, &smb_msg, &sent);
316371 if (rc < 0)
317
- goto uncork;
372
+ goto unmask;
318373
319374 total_len += sent;
320375 send_length += 4;
....@@ -332,12 +387,11 @@
332387 size += iov[i].iov_len;
333388 }
334389
335
- iov_iter_kvec(&smb_msg.msg_iter, WRITE | ITER_KVEC,
336
- iov, n_vec, size);
390
+ iov_iter_kvec(&smb_msg.msg_iter, WRITE, iov, n_vec, size);
337391
338392 rc = smb_send_kvec(server, &smb_msg, &sent);
339393 if (rc < 0)
340
- goto uncork;
394
+ goto unmask;
341395
342396 total_len += sent;
343397
....@@ -349,7 +403,7 @@
349403 rqst_page_get_length(&rqst[j], i, &bvec.bv_len,
350404 &bvec.bv_offset);
351405
352
- iov_iter_bvec(&smb_msg.msg_iter, WRITE | ITER_BVEC,
406
+ iov_iter_bvec(&smb_msg.msg_iter, WRITE,
353407 &bvec, 1, bvec.bv_len);
354408 rc = smb_send_kvec(server, &smb_msg, &sent);
355409 if (rc < 0)
....@@ -359,11 +413,27 @@
359413 }
360414 }
361415
362
-uncork:
416
+unmask:
417
+ sigprocmask(SIG_SETMASK, &oldmask, NULL);
418
+
419
+ /*
420
+ * If signal is pending but we have already sent the whole packet to
421
+ * the server we need to return success status to allow a corresponding
422
+ * mid entry to be kept in the pending requests queue thus allowing
423
+ * to handle responses from the server by the client.
424
+ *
425
+ * If only part of the packet has been sent there is no need to hide
426
+ * interrupt because the session will be reconnected anyway, so there
427
+ * won't be any response from the server to handle.
428
+ */
429
+
430
+ if (signal_pending(current) && (total_len != send_length)) {
431
+ cifs_dbg(FYI, "signal is pending after attempt to send\n");
432
+ rc = -ERESTARTSYS;
433
+ }
434
+
363435 /* uncork it */
364
- val = 0;
365
- kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK,
366
- (char *)&val, sizeof(val));
436
+ tcp_sock_set_cork(ssocket->sk, false);
367437
368438 if ((total_len > 0) && (total_len != send_length)) {
369439 cifs_dbg(FYI, "partial send (wanted=%u sent=%zu): terminating session\n",
....@@ -379,11 +449,12 @@
379449 }
380450 smbd_done:
381451 if (rc < 0 && rc != -EINTR)
382
- cifs_dbg(VFS, "Error %d sending data on socket to server\n",
452
+ cifs_server_dbg(VFS, "Error %d sending data on socket to server\n",
383453 rc);
384454 else if (rc > 0)
385455 rc = 0;
386
-
456
+out:
457
+ cifs_in_send_dec(server);
387458 return rc;
388459 }
389460
....@@ -403,8 +474,7 @@
403474 return -ENOMEM;
404475
405476 if (!server->ops->init_transform_rq) {
406
- cifs_dbg(VFS, "Encryption requested but transform callback "
407
- "is missing\n");
477
+ cifs_server_dbg(VFS, "Encryption requested but transform callback is missing\n");
408478 return -EIO;
409479 }
410480
....@@ -450,29 +520,57 @@
450520 }
451521
452522 static int
453
-wait_for_free_credits(struct TCP_Server_Info *server, const int timeout,
454
- int *credits)
523
+wait_for_free_credits(struct TCP_Server_Info *server, const int num_credits,
524
+ const int timeout, const int flags,
525
+ unsigned int *instance)
455526 {
456
- int rc;
527
+ long rc;
528
+ int *credits;
529
+ int optype;
530
+ long int t;
531
+
532
+ if (timeout < 0)
533
+ t = MAX_JIFFY_OFFSET;
534
+ else
535
+ t = msecs_to_jiffies(timeout);
536
+
537
+ optype = flags & CIFS_OP_MASK;
538
+
539
+ *instance = 0;
540
+
541
+ credits = server->ops->get_credits_field(server, optype);
542
+ /* Since an echo is already inflight, no need to wait to send another */
543
+ if (*credits <= 0 && optype == CIFS_ECHO_OP)
544
+ return -EAGAIN;
457545
458546 spin_lock(&server->req_lock);
459
- if (timeout == CIFS_ASYNC_OP) {
547
+ if ((flags & CIFS_TIMEOUT_MASK) == CIFS_NON_BLOCKING) {
460548 /* oplock breaks must not be held up */
461549 server->in_flight++;
550
+ if (server->in_flight > server->max_in_flight)
551
+ server->max_in_flight = server->in_flight;
462552 *credits -= 1;
553
+ *instance = server->reconnect_instance;
463554 spin_unlock(&server->req_lock);
464555 return 0;
465556 }
466557
467558 while (1) {
468
- if (*credits <= 0) {
559
+ if (*credits < num_credits) {
469560 spin_unlock(&server->req_lock);
470561 cifs_num_waiters_inc(server);
471
- rc = wait_event_killable(server->request_q,
472
- has_credits(server, credits));
562
+ rc = wait_event_killable_timeout(server->request_q,
563
+ has_credits(server, credits, num_credits), t);
473564 cifs_num_waiters_dec(server);
474
- if (rc)
475
- return rc;
565
+ if (!rc) {
566
+ trace_smb3_credit_timeout(server->CurrentMid,
567
+ server->hostname, num_credits, 0);
568
+ cifs_server_dbg(VFS, "wait timed out after %d ms\n",
569
+ timeout);
570
+ return -ENOTSUPP;
571
+ }
572
+ if (rc == -ERESTARTSYS)
573
+ return -ERESTARTSYS;
476574 spin_lock(&server->req_lock);
477575 } else {
478576 if (server->tcpStatus == CifsExiting) {
....@@ -481,14 +579,56 @@
481579 }
482580
483581 /*
582
+ * For normal commands, reserve the last MAX_COMPOUND
583
+ * credits to compound requests.
584
+ * Otherwise these compounds could be permanently
585
+ * starved for credits by single-credit requests.
586
+ *
587
+ * To prevent spinning CPU, block this thread until
588
+ * there are >MAX_COMPOUND credits available.
589
+ * But only do this is we already have a lot of
590
+ * credits in flight to avoid triggering this check
591
+ * for servers that are slow to hand out credits on
592
+ * new sessions.
593
+ */
594
+ if (!optype && num_credits == 1 &&
595
+ server->in_flight > 2 * MAX_COMPOUND &&
596
+ *credits <= MAX_COMPOUND) {
597
+ spin_unlock(&server->req_lock);
598
+ cifs_num_waiters_inc(server);
599
+ rc = wait_event_killable_timeout(
600
+ server->request_q,
601
+ has_credits(server, credits,
602
+ MAX_COMPOUND + 1),
603
+ t);
604
+ cifs_num_waiters_dec(server);
605
+ if (!rc) {
606
+ trace_smb3_credit_timeout(
607
+ server->CurrentMid,
608
+ server->hostname, num_credits,
609
+ 0);
610
+ cifs_server_dbg(VFS, "wait timed out after %d ms\n",
611
+ timeout);
612
+ return -ENOTSUPP;
613
+ }
614
+ if (rc == -ERESTARTSYS)
615
+ return -ERESTARTSYS;
616
+ spin_lock(&server->req_lock);
617
+ continue;
618
+ }
619
+
620
+ /*
484621 * Can not count locking commands against total
485622 * as they are allowed to block on server.
486623 */
487624
488625 /* update # of requests on the wire to server */
489
- if (timeout != CIFS_BLOCKING_OP) {
490
- *credits -= 1;
491
- server->in_flight++;
626
+ if ((flags & CIFS_TIMEOUT_MASK) != CIFS_BLOCKING_OP) {
627
+ *credits -= num_credits;
628
+ server->in_flight += num_credits;
629
+ if (server->in_flight > server->max_in_flight)
630
+ server->max_in_flight = server->in_flight;
631
+ *instance = server->reconnect_instance;
492632 }
493633 spin_unlock(&server->req_lock);
494634 break;
....@@ -498,24 +638,57 @@
498638 }
499639
500640 static int
501
-wait_for_free_request(struct TCP_Server_Info *server, const int timeout,
502
- const int optype)
641
+wait_for_free_request(struct TCP_Server_Info *server, const int flags,
642
+ unsigned int *instance)
503643 {
504
- int *val;
644
+ return wait_for_free_credits(server, 1, -1, flags,
645
+ instance);
646
+}
505647
506
- val = server->ops->get_credits_field(server, optype);
507
- /* Since an echo is already inflight, no need to wait to send another */
508
- if (*val <= 0 && optype == CIFS_ECHO_OP)
509
- return -EAGAIN;
510
- return wait_for_free_credits(server, timeout, val);
648
+static int
649
+wait_for_compound_request(struct TCP_Server_Info *server, int num,
650
+ const int flags, unsigned int *instance)
651
+{
652
+ int *credits;
653
+
654
+ credits = server->ops->get_credits_field(server, flags & CIFS_OP_MASK);
655
+
656
+ spin_lock(&server->req_lock);
657
+ if (*credits < num) {
658
+ /*
659
+ * If the server is tight on resources or just gives us less
660
+ * credits for other reasons (e.g. requests are coming out of
661
+ * order and the server delays granting more credits until it
662
+ * processes a missing mid) and we exhausted most available
663
+ * credits there may be situations when we try to send
664
+ * a compound request but we don't have enough credits. At this
665
+ * point the client needs to decide if it should wait for
666
+ * additional credits or fail the request. If at least one
667
+ * request is in flight there is a high probability that the
668
+ * server will return enough credits to satisfy this compound
669
+ * request.
670
+ *
671
+ * Return immediately if no requests in flight since we will be
672
+ * stuck on waiting for credits.
673
+ */
674
+ if (server->in_flight == 0) {
675
+ spin_unlock(&server->req_lock);
676
+ return -ENOTSUPP;
677
+ }
678
+ }
679
+ spin_unlock(&server->req_lock);
680
+
681
+ return wait_for_free_credits(server, num, 60000, flags,
682
+ instance);
511683 }
512684
513685 int
514686 cifs_wait_mtu_credits(struct TCP_Server_Info *server, unsigned int size,
515
- unsigned int *num, unsigned int *credits)
687
+ unsigned int *num, struct cifs_credits *credits)
516688 {
517689 *num = size;
518
- *credits = 0;
690
+ credits->value = 0;
691
+ credits->instance = server->reconnect_instance;
519692 return 0;
520693 }
521694
....@@ -602,27 +775,43 @@
602775 int
603776 cifs_call_async(struct TCP_Server_Info *server, struct smb_rqst *rqst,
604777 mid_receive_t *receive, mid_callback_t *callback,
605
- mid_handle_t *handle, void *cbdata, const int flags)
778
+ mid_handle_t *handle, void *cbdata, const int flags,
779
+ const struct cifs_credits *exist_credits)
606780 {
607
- int rc, timeout, optype;
781
+ int rc;
608782 struct mid_q_entry *mid;
609
- unsigned int credits = 0;
783
+ struct cifs_credits credits = { .value = 0, .instance = 0 };
784
+ unsigned int instance;
785
+ int optype;
610786
611
- timeout = flags & CIFS_TIMEOUT_MASK;
612787 optype = flags & CIFS_OP_MASK;
613788
614789 if ((flags & CIFS_HAS_CREDITS) == 0) {
615
- rc = wait_for_free_request(server, timeout, optype);
790
+ rc = wait_for_free_request(server, flags, &instance);
616791 if (rc)
617792 return rc;
618
- credits = 1;
619
- }
793
+ credits.value = 1;
794
+ credits.instance = instance;
795
+ } else
796
+ instance = exist_credits->instance;
620797
621798 mutex_lock(&server->srv_mutex);
799
+
800
+ /*
801
+ * We can't use credits obtained from the previous session to send this
802
+ * request. Check if there were reconnects after we obtained credits and
803
+ * return -EAGAIN in such cases to let callers handle it.
804
+ */
805
+ if (instance != server->reconnect_instance) {
806
+ mutex_unlock(&server->srv_mutex);
807
+ add_credits_and_wake_if(server, &credits, optype);
808
+ return -EAGAIN;
809
+ }
810
+
622811 mid = server->ops->setup_async_request(server, rqst);
623812 if (IS_ERR(mid)) {
624813 mutex_unlock(&server->srv_mutex);
625
- add_credits_and_wake_if(server, credits, optype);
814
+ add_credits_and_wake_if(server, &credits, optype);
626815 return PTR_ERR(mid);
627816 }
628817
....@@ -642,9 +831,7 @@
642831 * I/O response may come back and free the mid entry on another thread.
643832 */
644833 cifs_save_when_sent(mid);
645
- cifs_in_send_inc(server);
646834 rc = smb_send_rqst(server, 1, rqst, flags);
647
- cifs_in_send_dec(server);
648835
649836 if (rc < 0) {
650837 revert_current_mid(server, mid->credits);
....@@ -657,7 +844,7 @@
657844 if (rc == 0)
658845 return 0;
659846
660
- add_credits_and_wake_if(server, credits, optype);
847
+ add_credits_and_wake_if(server, &credits, optype);
661848 return rc;
662849 }
663850
....@@ -681,7 +868,7 @@
681868
682869 iov[0].iov_base = in_buf;
683870 iov[0].iov_len = get_rfc1002_length(in_buf) + 4;
684
- flags |= CIFS_NO_RESP;
871
+ flags |= CIFS_NO_RSP_BUF;
685872 rc = SendReceive2(xid, ses, iov, 1, &resp_buf_type, flags, &rsp_iov);
686873 cifs_dbg(NOISY, "SendRcvNoRsp flags %d rc %d\n", flags, rc);
687874
....@@ -711,8 +898,11 @@
711898 rc = -EHOSTDOWN;
712899 break;
713900 default:
714
- list_del_init(&mid->qhead);
715
- cifs_dbg(VFS, "%s: invalid mid state mid=%llu state=%d\n",
901
+ if (!(mid->mid_flags & MID_DELETED)) {
902
+ list_del_init(&mid->qhead);
903
+ mid->mid_flags |= MID_DELETED;
904
+ }
905
+ cifs_server_dbg(VFS, "%s: invalid mid state mid=%llu state=%d\n",
716906 __func__, mid->mid, mid->mid_state);
717907 rc = -EIO;
718908 }
....@@ -753,16 +943,17 @@
753943 rc = cifs_verify_signature(&rqst, server,
754944 mid->sequence_number);
755945 if (rc)
756
- cifs_dbg(VFS, "SMB signature verification returned error = %d\n",
946
+ cifs_server_dbg(VFS, "SMB signature verification returned error = %d\n",
757947 rc);
758948 }
759949
760950 /* BB special case reconnect tid and uid here? */
761
- return map_smb_to_linux_error(mid->resp_buf, log_error);
951
+ return map_and_check_smb_error(mid, log_error);
762952 }
763953
764954 struct mid_q_entry *
765
-cifs_setup_request(struct cifs_ses *ses, struct smb_rqst *rqst)
955
+cifs_setup_request(struct cifs_ses *ses, struct TCP_Server_Info *ignored,
956
+ struct smb_rqst *rqst)
766957 {
767958 int rc;
768959 struct smb_hdr *hdr = (struct smb_hdr *)rqst->rq_iov[0].iov_base;
....@@ -784,61 +975,101 @@
784975 }
785976
786977 static void
787
-cifs_noop_callback(struct mid_q_entry *mid)
978
+cifs_compound_callback(struct mid_q_entry *mid)
788979 {
980
+ struct TCP_Server_Info *server = mid->server;
981
+ struct cifs_credits credits;
982
+
983
+ credits.value = server->ops->get_credits(mid);
984
+ credits.instance = server->reconnect_instance;
985
+
986
+ add_credits(server, &credits, mid->optype);
987
+}
988
+
989
+static void
990
+cifs_compound_last_callback(struct mid_q_entry *mid)
991
+{
992
+ cifs_compound_callback(mid);
993
+ cifs_wake_up_task(mid);
994
+}
995
+
996
+static void
997
+cifs_cancelled_callback(struct mid_q_entry *mid)
998
+{
999
+ cifs_compound_callback(mid);
1000
+ DeleteMidQEntry(mid);
1001
+}
1002
+
1003
+/*
1004
+ * Return a channel (master if none) of @ses that can be used to send
1005
+ * regular requests.
1006
+ *
1007
+ * If we are currently binding a new channel (negprot/sess.setup),
1008
+ * return the new incomplete channel.
1009
+ */
1010
+struct TCP_Server_Info *cifs_pick_channel(struct cifs_ses *ses)
1011
+{
1012
+ uint index = 0;
1013
+
1014
+ if (!ses)
1015
+ return NULL;
1016
+
1017
+ if (!ses->binding) {
1018
+ /* round robin */
1019
+ if (ses->chan_count > 1) {
1020
+ index = (uint)atomic_inc_return(&ses->chan_seq);
1021
+ index %= ses->chan_count;
1022
+ }
1023
+ return ses->chans[index].server;
1024
+ } else {
1025
+ return cifs_ses_server(ses);
1026
+ }
7891027 }
7901028
7911029 int
7921030 compound_send_recv(const unsigned int xid, struct cifs_ses *ses,
1031
+ struct TCP_Server_Info *server,
7931032 const int flags, const int num_rqst, struct smb_rqst *rqst,
7941033 int *resp_buf_type, struct kvec *resp_iov)
7951034 {
796
- int i, j, rc = 0;
797
- int timeout, optype;
1035
+ int i, j, optype, rc = 0;
7981036 struct mid_q_entry *midQ[MAX_COMPOUND];
7991037 bool cancelled_mid[MAX_COMPOUND] = {false};
800
- unsigned int credits[MAX_COMPOUND] = {0};
1038
+ struct cifs_credits credits[MAX_COMPOUND] = {
1039
+ { .value = 0, .instance = 0 }
1040
+ };
1041
+ unsigned int instance;
8011042 char *buf;
8021043
803
- timeout = flags & CIFS_TIMEOUT_MASK;
8041044 optype = flags & CIFS_OP_MASK;
8051045
8061046 for (i = 0; i < num_rqst; i++)
8071047 resp_buf_type[i] = CIFS_NO_BUFFER; /* no response buf yet */
8081048
809
- if ((ses == NULL) || (ses->server == NULL)) {
1049
+ if (!ses || !ses->server || !server) {
8101050 cifs_dbg(VFS, "Null session\n");
8111051 return -EIO;
8121052 }
8131053
814
- if (ses->server->tcpStatus == CifsExiting)
1054
+ if (server->tcpStatus == CifsExiting)
8151055 return -ENOENT;
8161056
8171057 /*
818
- * Ensure we obtain 1 credit per request in the compound chain.
819
- * It can be optimized further by waiting for all the credits
820
- * at once but this can wait long enough if we don't have enough
821
- * credits due to some heavy operations in progress or the server
822
- * not granting us much, so a fallback to the current approach is
823
- * needed anyway.
1058
+ * Wait for all the requests to become available.
1059
+ * This approach still leaves the possibility to be stuck waiting for
1060
+ * credits if the server doesn't grant credits to the outstanding
1061
+ * requests and if the client is completely idle, not generating any
1062
+ * other requests.
1063
+ * This can be handled by the eventual session reconnect.
8241064 */
1065
+ rc = wait_for_compound_request(server, num_rqst, flags,
1066
+ &instance);
1067
+ if (rc)
1068
+ return rc;
1069
+
8251070 for (i = 0; i < num_rqst; i++) {
826
- rc = wait_for_free_request(ses->server, timeout, optype);
827
- if (rc) {
828
- /*
829
- * We haven't sent an SMB packet to the server yet but
830
- * we already obtained credits for i requests in the
831
- * compound chain - need to return those credits back
832
- * for future use. Note that we need to call add_credits
833
- * multiple times to match the way we obtained credits
834
- * in the first place and to account for in flight
835
- * requests correctly.
836
- */
837
- for (j = 0; j < i; j++)
838
- add_credits(ses->server, 1, optype);
839
- return rc;
840
- }
841
- credits[i] = 1;
1071
+ credits[i].value = 1;
1072
+ credits[i].instance = instance;
8421073 }
8431074
8441075 /*
....@@ -847,86 +1078,114 @@
8471078 * of smb data.
8481079 */
8491080
850
- mutex_lock(&ses->server->srv_mutex);
1081
+ mutex_lock(&server->srv_mutex);
1082
+
1083
+ /*
1084
+ * All the parts of the compound chain belong obtained credits from the
1085
+ * same session. We can not use credits obtained from the previous
1086
+ * session to send this request. Check if there were reconnects after
1087
+ * we obtained credits and return -EAGAIN in such cases to let callers
1088
+ * handle it.
1089
+ */
1090
+ if (instance != server->reconnect_instance) {
1091
+ mutex_unlock(&server->srv_mutex);
1092
+ for (j = 0; j < num_rqst; j++)
1093
+ add_credits(server, &credits[j], optype);
1094
+ return -EAGAIN;
1095
+ }
8511096
8521097 for (i = 0; i < num_rqst; i++) {
853
- midQ[i] = ses->server->ops->setup_request(ses, &rqst[i]);
1098
+ midQ[i] = server->ops->setup_request(ses, server, &rqst[i]);
8541099 if (IS_ERR(midQ[i])) {
855
- revert_current_mid(ses->server, i);
1100
+ revert_current_mid(server, i);
8561101 for (j = 0; j < i; j++)
8571102 cifs_delete_mid(midQ[j]);
858
- mutex_unlock(&ses->server->srv_mutex);
1103
+ mutex_unlock(&server->srv_mutex);
8591104
8601105 /* Update # of requests on wire to server */
8611106 for (j = 0; j < num_rqst; j++)
862
- add_credits(ses->server, credits[j], optype);
1107
+ add_credits(server, &credits[j], optype);
8631108 return PTR_ERR(midQ[i]);
8641109 }
8651110
8661111 midQ[i]->mid_state = MID_REQUEST_SUBMITTED;
1112
+ midQ[i]->optype = optype;
8671113 /*
868
- * We don't invoke the callback compounds unless it is the last
869
- * request.
1114
+ * Invoke callback for every part of the compound chain
1115
+ * to calculate credits properly. Wake up this thread only when
1116
+ * the last element is received.
8701117 */
8711118 if (i < num_rqst - 1)
872
- midQ[i]->callback = cifs_noop_callback;
1119
+ midQ[i]->callback = cifs_compound_callback;
1120
+ else
1121
+ midQ[i]->callback = cifs_compound_last_callback;
8731122 }
874
- cifs_in_send_inc(ses->server);
875
- rc = smb_send_rqst(ses->server, num_rqst, rqst, flags);
876
- cifs_in_send_dec(ses->server);
1123
+ rc = smb_send_rqst(server, num_rqst, rqst, flags);
8771124
8781125 for (i = 0; i < num_rqst; i++)
8791126 cifs_save_when_sent(midQ[i]);
8801127
8811128 if (rc < 0) {
882
- revert_current_mid(ses->server, num_rqst);
883
- ses->server->sequence_number -= 2;
1129
+ revert_current_mid(server, num_rqst);
1130
+ server->sequence_number -= 2;
8841131 }
8851132
886
- mutex_unlock(&ses->server->srv_mutex);
1133
+ mutex_unlock(&server->srv_mutex);
8871134
888
- if (rc < 0)
1135
+ /*
1136
+ * If sending failed for some reason or it is an oplock break that we
1137
+ * will not receive a response to - return credits back
1138
+ */
1139
+ if (rc < 0 || (flags & CIFS_NO_SRV_RSP)) {
1140
+ for (i = 0; i < num_rqst; i++)
1141
+ add_credits(server, &credits[i], optype);
8891142 goto out;
1143
+ }
1144
+
1145
+ /*
1146
+ * At this point the request is passed to the network stack - we assume
1147
+ * that any credits taken from the server structure on the client have
1148
+ * been spent and we can't return them back. Once we receive responses
1149
+ * we will collect credits granted by the server in the mid callbacks
1150
+ * and add those credits to the server structure.
1151
+ */
8901152
8911153 /*
8921154 * Compounding is never used during session establish.
8931155 */
8941156 if ((ses->status == CifsNew) || (optype & CIFS_NEG_OP)) {
895
- mutex_lock(&ses->server->srv_mutex);
1157
+ mutex_lock(&server->srv_mutex);
8961158 smb311_update_preauth_hash(ses, rqst[0].rq_iov,
8971159 rqst[0].rq_nvec);
898
- mutex_unlock(&ses->server->srv_mutex);
1160
+ mutex_unlock(&server->srv_mutex);
8991161 }
9001162
901
- if (timeout == CIFS_ASYNC_OP)
902
- goto out;
903
-
9041163 for (i = 0; i < num_rqst; i++) {
905
- rc = wait_for_response(ses->server, midQ[i]);
906
- if (rc != 0) {
907
- cifs_dbg(FYI, "Cancelling wait for mid %llu\n",
908
- midQ[i]->mid);
909
- send_cancel(ses->server, &rqst[i], midQ[i]);
1164
+ rc = wait_for_response(server, midQ[i]);
1165
+ if (rc != 0)
1166
+ break;
1167
+ }
1168
+ if (rc != 0) {
1169
+ for (; i < num_rqst; i++) {
1170
+ cifs_server_dbg(FYI, "Cancelling wait for mid %llu cmd: %d\n",
1171
+ midQ[i]->mid, le16_to_cpu(midQ[i]->command));
1172
+ send_cancel(server, &rqst[i], midQ[i]);
9101173 spin_lock(&GlobalMid_Lock);
1174
+ midQ[i]->mid_flags |= MID_WAIT_CANCELLED;
9111175 if (midQ[i]->mid_state == MID_REQUEST_SUBMITTED) {
912
- midQ[i]->mid_flags |= MID_WAIT_CANCELLED;
913
- midQ[i]->callback = DeleteMidQEntry;
1176
+ midQ[i]->callback = cifs_cancelled_callback;
9141177 cancelled_mid[i] = true;
1178
+ credits[i].value = 0;
9151179 }
9161180 spin_unlock(&GlobalMid_Lock);
9171181 }
9181182 }
9191183
920
- for (i = 0; i < num_rqst; i++)
921
- if (!cancelled_mid[i] && midQ[i]->resp_buf
922
- && (midQ[i]->mid_state == MID_RESPONSE_RECEIVED))
923
- credits[i] = ses->server->ops->get_credits(midQ[i]);
924
-
9251184 for (i = 0; i < num_rqst; i++) {
9261185 if (rc < 0)
9271186 goto out;
9281187
929
- rc = cifs_sync_mid_result(midQ[i], ses->server);
1188
+ rc = cifs_sync_mid_result(midQ[i], server);
9301189 if (rc != 0) {
9311190 /* mark this mid as cancelled to not free it below */
9321191 cancelled_mid[i] = true;
....@@ -943,18 +1202,18 @@
9431202 buf = (char *)midQ[i]->resp_buf;
9441203 resp_iov[i].iov_base = buf;
9451204 resp_iov[i].iov_len = midQ[i]->resp_buf_size +
946
- ses->server->vals->header_preamble_size;
1205
+ server->vals->header_preamble_size;
9471206
9481207 if (midQ[i]->large_buf)
9491208 resp_buf_type[i] = CIFS_LARGE_BUFFER;
9501209 else
9511210 resp_buf_type[i] = CIFS_SMALL_BUFFER;
9521211
953
- rc = ses->server->ops->check_receive(midQ[i], ses->server,
1212
+ rc = server->ops->check_receive(midQ[i], server,
9541213 flags & CIFS_LOG_ERROR);
9551214
9561215 /* mark it so buf will not be freed by cifs_delete_mid */
957
- if ((flags & CIFS_NO_RESP) == 0)
1216
+ if ((flags & CIFS_NO_RSP_BUF) == 0)
9581217 midQ[i]->resp_buf = NULL;
9591218
9601219 }
....@@ -967,9 +1226,9 @@
9671226 .iov_base = resp_iov[0].iov_base,
9681227 .iov_len = resp_iov[0].iov_len
9691228 };
970
- mutex_lock(&ses->server->srv_mutex);
1229
+ mutex_lock(&server->srv_mutex);
9711230 smb311_update_preauth_hash(ses, &iov, 1);
972
- mutex_unlock(&ses->server->srv_mutex);
1231
+ mutex_unlock(&server->srv_mutex);
9731232 }
9741233
9751234 out:
....@@ -982,7 +1241,6 @@
9821241 for (i = 0; i < num_rqst; i++) {
9831242 if (!cancelled_mid[i])
9841243 cifs_delete_mid(midQ[i]);
985
- add_credits(ses->server, credits[i], optype);
9861244 }
9871245
9881246 return rc;
....@@ -990,11 +1248,12 @@
9901248
9911249 int
9921250 cifs_send_recv(const unsigned int xid, struct cifs_ses *ses,
1251
+ struct TCP_Server_Info *server,
9931252 struct smb_rqst *rqst, int *resp_buf_type, const int flags,
9941253 struct kvec *resp_iov)
9951254 {
996
- return compound_send_recv(xid, ses, flags, 1, rqst, resp_buf_type,
997
- resp_iov);
1255
+ return compound_send_recv(xid, ses, server, flags, 1,
1256
+ rqst, resp_buf_type, resp_iov);
9981257 }
9991258
10001259 int
....@@ -1029,7 +1288,8 @@
10291288 rqst.rq_iov = new_iov;
10301289 rqst.rq_nvec = n_vec + 1;
10311290
1032
- rc = cifs_send_recv(xid, ses, &rqst, resp_buf_type, flags, resp_iov);
1291
+ rc = cifs_send_recv(xid, ses, ses->server,
1292
+ &rqst, resp_buf_type, flags, resp_iov);
10331293 if (n_vec + 1 > CIFS_MAX_IOV_SIZE)
10341294 kfree(new_iov);
10351295 return rc;
....@@ -1038,24 +1298,27 @@
10381298 int
10391299 SendReceive(const unsigned int xid, struct cifs_ses *ses,
10401300 struct smb_hdr *in_buf, struct smb_hdr *out_buf,
1041
- int *pbytes_returned, const int timeout)
1301
+ int *pbytes_returned, const int flags)
10421302 {
10431303 int rc = 0;
10441304 struct mid_q_entry *midQ;
10451305 unsigned int len = be32_to_cpu(in_buf->smb_buf_length);
10461306 struct kvec iov = { .iov_base = in_buf, .iov_len = len };
10471307 struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec = 1 };
1308
+ struct cifs_credits credits = { .value = 1, .instance = 0 };
1309
+ struct TCP_Server_Info *server;
10481310
10491311 if (ses == NULL) {
10501312 cifs_dbg(VFS, "Null smb session\n");
10511313 return -EIO;
10521314 }
1053
- if (ses->server == NULL) {
1315
+ server = ses->server;
1316
+ if (server == NULL) {
10541317 cifs_dbg(VFS, "Null tcp session\n");
10551318 return -EIO;
10561319 }
10571320
1058
- if (ses->server->tcpStatus == CifsExiting)
1321
+ if (server->tcpStatus == CifsExiting)
10591322 return -ENOENT;
10601323
10611324 /* Ensure that we do not send more than 50 overlapping requests
....@@ -1063,12 +1326,12 @@
10631326 use ses->maxReq */
10641327
10651328 if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) {
1066
- cifs_dbg(VFS, "Illegal length, greater than maximum frame, %d\n",
1067
- len);
1329
+ cifs_server_dbg(VFS, "Invalid length, greater than maximum frame, %d\n",
1330
+ len);
10681331 return -EIO;
10691332 }
10701333
1071
- rc = wait_for_free_request(ses->server, timeout, 0);
1334
+ rc = wait_for_free_request(server, flags, &credits.instance);
10721335 if (rc)
10731336 return rc;
10741337
....@@ -1076,73 +1339,68 @@
10761339 and avoid races inside tcp sendmsg code that could cause corruption
10771340 of smb data */
10781341
1079
- mutex_lock(&ses->server->srv_mutex);
1342
+ mutex_lock(&server->srv_mutex);
10801343
10811344 rc = allocate_mid(ses, in_buf, &midQ);
10821345 if (rc) {
1083
- mutex_unlock(&ses->server->srv_mutex);
1346
+ mutex_unlock(&server->srv_mutex);
10841347 /* Update # of requests on wire to server */
1085
- add_credits(ses->server, 1, 0);
1348
+ add_credits(server, &credits, 0);
10861349 return rc;
10871350 }
10881351
1089
- rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number);
1352
+ rc = cifs_sign_smb(in_buf, server, &midQ->sequence_number);
10901353 if (rc) {
1091
- mutex_unlock(&ses->server->srv_mutex);
1354
+ mutex_unlock(&server->srv_mutex);
10921355 goto out;
10931356 }
10941357
10951358 midQ->mid_state = MID_REQUEST_SUBMITTED;
10961359
1097
- cifs_in_send_inc(ses->server);
1098
- rc = smb_send(ses->server, in_buf, len);
1099
- cifs_in_send_dec(ses->server);
1360
+ rc = smb_send(server, in_buf, len);
11001361 cifs_save_when_sent(midQ);
11011362
11021363 if (rc < 0)
1103
- ses->server->sequence_number -= 2;
1364
+ server->sequence_number -= 2;
11041365
1105
- mutex_unlock(&ses->server->srv_mutex);
1366
+ mutex_unlock(&server->srv_mutex);
11061367
11071368 if (rc < 0)
11081369 goto out;
11091370
1110
- if (timeout == CIFS_ASYNC_OP)
1111
- goto out;
1112
-
1113
- rc = wait_for_response(ses->server, midQ);
1371
+ rc = wait_for_response(server, midQ);
11141372 if (rc != 0) {
1115
- send_cancel(ses->server, &rqst, midQ);
1373
+ send_cancel(server, &rqst, midQ);
11161374 spin_lock(&GlobalMid_Lock);
11171375 if (midQ->mid_state == MID_REQUEST_SUBMITTED) {
11181376 /* no longer considered to be "in-flight" */
11191377 midQ->callback = DeleteMidQEntry;
11201378 spin_unlock(&GlobalMid_Lock);
1121
- add_credits(ses->server, 1, 0);
1379
+ add_credits(server, &credits, 0);
11221380 return rc;
11231381 }
11241382 spin_unlock(&GlobalMid_Lock);
11251383 }
11261384
1127
- rc = cifs_sync_mid_result(midQ, ses->server);
1385
+ rc = cifs_sync_mid_result(midQ, server);
11281386 if (rc != 0) {
1129
- add_credits(ses->server, 1, 0);
1387
+ add_credits(server, &credits, 0);
11301388 return rc;
11311389 }
11321390
11331391 if (!midQ->resp_buf || !out_buf ||
11341392 midQ->mid_state != MID_RESPONSE_RECEIVED) {
11351393 rc = -EIO;
1136
- cifs_dbg(VFS, "Bad MID state?\n");
1394
+ cifs_server_dbg(VFS, "Bad MID state?\n");
11371395 goto out;
11381396 }
11391397
11401398 *pbytes_returned = get_rfc1002_length(midQ->resp_buf);
11411399 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4);
1142
- rc = cifs_check_receive(midQ, ses->server, 0);
1400
+ rc = cifs_check_receive(midQ, server, 0);
11431401 out:
11441402 cifs_delete_mid(midQ);
1145
- add_credits(ses->server, 1, 0);
1403
+ add_credits(server, &credits, 0);
11461404
11471405 return rc;
11481406 }
....@@ -1184,19 +1442,22 @@
11841442 unsigned int len = be32_to_cpu(in_buf->smb_buf_length);
11851443 struct kvec iov = { .iov_base = in_buf, .iov_len = len };
11861444 struct smb_rqst rqst = { .rq_iov = &iov, .rq_nvec = 1 };
1445
+ unsigned int instance;
1446
+ struct TCP_Server_Info *server;
11871447
11881448 if (tcon == NULL || tcon->ses == NULL) {
11891449 cifs_dbg(VFS, "Null smb session\n");
11901450 return -EIO;
11911451 }
11921452 ses = tcon->ses;
1453
+ server = ses->server;
11931454
1194
- if (ses->server == NULL) {
1455
+ if (server == NULL) {
11951456 cifs_dbg(VFS, "Null tcp session\n");
11961457 return -EIO;
11971458 }
11981459
1199
- if (ses->server->tcpStatus == CifsExiting)
1460
+ if (server->tcpStatus == CifsExiting)
12001461 return -ENOENT;
12011462
12021463 /* Ensure that we do not send more than 50 overlapping requests
....@@ -1204,12 +1465,12 @@
12041465 use ses->maxReq */
12051466
12061467 if (len > CIFSMaxBufSize + MAX_CIFS_HDR_SIZE - 4) {
1207
- cifs_dbg(VFS, "Illegal length, greater than maximum frame, %d\n",
1208
- len);
1468
+ cifs_tcon_dbg(VFS, "Invalid length, greater than maximum frame, %d\n",
1469
+ len);
12091470 return -EIO;
12101471 }
12111472
1212
- rc = wait_for_free_request(ses->server, CIFS_BLOCKING_OP, 0);
1473
+ rc = wait_for_free_request(server, CIFS_BLOCKING_OP, &instance);
12131474 if (rc)
12141475 return rc;
12151476
....@@ -1217,31 +1478,29 @@
12171478 and avoid races inside tcp sendmsg code that could cause corruption
12181479 of smb data */
12191480
1220
- mutex_lock(&ses->server->srv_mutex);
1481
+ mutex_lock(&server->srv_mutex);
12211482
12221483 rc = allocate_mid(ses, in_buf, &midQ);
12231484 if (rc) {
1224
- mutex_unlock(&ses->server->srv_mutex);
1485
+ mutex_unlock(&server->srv_mutex);
12251486 return rc;
12261487 }
12271488
1228
- rc = cifs_sign_smb(in_buf, ses->server, &midQ->sequence_number);
1489
+ rc = cifs_sign_smb(in_buf, server, &midQ->sequence_number);
12291490 if (rc) {
12301491 cifs_delete_mid(midQ);
1231
- mutex_unlock(&ses->server->srv_mutex);
1492
+ mutex_unlock(&server->srv_mutex);
12321493 return rc;
12331494 }
12341495
12351496 midQ->mid_state = MID_REQUEST_SUBMITTED;
1236
- cifs_in_send_inc(ses->server);
1237
- rc = smb_send(ses->server, in_buf, len);
1238
- cifs_in_send_dec(ses->server);
1497
+ rc = smb_send(server, in_buf, len);
12391498 cifs_save_when_sent(midQ);
12401499
12411500 if (rc < 0)
1242
- ses->server->sequence_number -= 2;
1501
+ server->sequence_number -= 2;
12431502
1244
- mutex_unlock(&ses->server->srv_mutex);
1503
+ mutex_unlock(&server->srv_mutex);
12451504
12461505 if (rc < 0) {
12471506 cifs_delete_mid(midQ);
....@@ -1249,21 +1508,21 @@
12491508 }
12501509
12511510 /* Wait for a reply - allow signals to interrupt. */
1252
- rc = wait_event_interruptible(ses->server->response_q,
1511
+ rc = wait_event_interruptible(server->response_q,
12531512 (!(midQ->mid_state == MID_REQUEST_SUBMITTED)) ||
1254
- ((ses->server->tcpStatus != CifsGood) &&
1255
- (ses->server->tcpStatus != CifsNew)));
1513
+ ((server->tcpStatus != CifsGood) &&
1514
+ (server->tcpStatus != CifsNew)));
12561515
12571516 /* Were we interrupted by a signal ? */
12581517 if ((rc == -ERESTARTSYS) &&
12591518 (midQ->mid_state == MID_REQUEST_SUBMITTED) &&
1260
- ((ses->server->tcpStatus == CifsGood) ||
1261
- (ses->server->tcpStatus == CifsNew))) {
1519
+ ((server->tcpStatus == CifsGood) ||
1520
+ (server->tcpStatus == CifsNew))) {
12621521
12631522 if (in_buf->Command == SMB_COM_TRANSACTION2) {
12641523 /* POSIX lock. We send a NT_CANCEL SMB to cause the
12651524 blocking lock to return. */
1266
- rc = send_cancel(ses->server, &rqst, midQ);
1525
+ rc = send_cancel(server, &rqst, midQ);
12671526 if (rc) {
12681527 cifs_delete_mid(midQ);
12691528 return rc;
....@@ -1282,9 +1541,9 @@
12821541 }
12831542 }
12841543
1285
- rc = wait_for_response(ses->server, midQ);
1544
+ rc = wait_for_response(server, midQ);
12861545 if (rc) {
1287
- send_cancel(ses->server, &rqst, midQ);
1546
+ send_cancel(server, &rqst, midQ);
12881547 spin_lock(&GlobalMid_Lock);
12891548 if (midQ->mid_state == MID_REQUEST_SUBMITTED) {
12901549 /* no longer considered to be "in-flight" */
....@@ -1299,20 +1558,20 @@
12991558 rstart = 1;
13001559 }
13011560
1302
- rc = cifs_sync_mid_result(midQ, ses->server);
1561
+ rc = cifs_sync_mid_result(midQ, server);
13031562 if (rc != 0)
13041563 return rc;
13051564
13061565 /* rcvd frame is ok */
13071566 if (out_buf == NULL || midQ->mid_state != MID_RESPONSE_RECEIVED) {
13081567 rc = -EIO;
1309
- cifs_dbg(VFS, "Bad MID state?\n");
1568
+ cifs_tcon_dbg(VFS, "Bad MID state?\n");
13101569 goto out;
13111570 }
13121571
13131572 *pbytes_returned = get_rfc1002_length(midQ->resp_buf);
13141573 memcpy(out_buf, midQ->resp_buf, *pbytes_returned + 4);
1315
- rc = cifs_check_receive(midQ, ses->server, 0);
1574
+ rc = cifs_check_receive(midQ, server, 0);
13161575 out:
13171576 cifs_delete_mid(midQ);
13181577 if (rstart && rc == -EACCES)