Merge tag 'pci-v3.13-fixes-1' of git://git.kernel.org/pub/scm/linux/kernel/git/helgaa...
[firefly-linux-kernel-4.4.55.git] / fs / cifs / transport.c
index 6fdcb1b4a106747779ae77ed365116256e79edec..b375709528467b5a1a74e078fae2aeb7813e1a1e 100644 (file)
@@ -58,7 +58,7 @@ AllocMidQEntry(const struct smb_hdr *smb_buffer, struct TCP_Server_Info *server)
                return temp;
        else {
                memset(temp, 0, sizeof(struct mid_q_entry));
-               temp->mid = smb_buffer->Mid;    /* always LE */
+               temp->mid = get_mid(smb_buffer);
                temp->pid = current->pid;
                temp->command = cpu_to_le16(smb_buffer->Command);
                cifs_dbg(FYI, "For smb_command %d\n", smb_buffer->Command);
@@ -410,8 +410,13 @@ static int
 wait_for_free_request(struct TCP_Server_Info *server, const int timeout,
                      const int optype)
 {
-       return wait_for_free_credits(server, timeout,
-                               server->ops->get_credits_field(server, optype));
+       int *val;
+
+       val = server->ops->get_credits_field(server, optype);
+       /* Since an echo is already inflight, no need to wait to send another */
+       if (*val <= 0 && optype == CIFS_ECHO_OP)
+               return -EAGAIN;
+       return wait_for_free_credits(server, timeout, val);
 }
 
 static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
@@ -426,13 +431,20 @@ static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
                return -EAGAIN;
        }
 
-       if (ses->status != CifsGood) {
-               /* check if SMB session is bad because we are setting it up */
+       if (ses->status == CifsNew) {
                if ((in_buf->Command != SMB_COM_SESSION_SETUP_ANDX) &&
                        (in_buf->Command != SMB_COM_NEGOTIATE))
                        return -EAGAIN;
                /* else ok - we are setting up session */
        }
+
+       if (ses->status == CifsExiting) {
+               /* check if SMB session is bad because we are setting it up */
+               if (in_buf->Command != SMB_COM_LOGOFF_ANDX)
+                       return -EAGAIN;
+               /* else ok - we are shutting down session */
+       }
+
        *ppmidQ = AllocMidQEntry(in_buf, ses->server);
        if (*ppmidQ == NULL)
                return -ENOMEM;