]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - fs/cifs/smb2pdu.c
CIFS: Separate SMB2 header structure
[mirror_ubuntu-zesty-kernel.git] / fs / cifs / smb2pdu.c
index 5ca5ea4668a1482ef9643cd525ded6ebbaa7e326..0a668c756d56232d19d03b9ecfb52ffd423addda 100644 (file)
@@ -83,6 +83,7 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
                  const struct cifs_tcon *tcon)
 {
        struct smb2_pdu *pdu = (struct smb2_pdu *)hdr;
+       struct smb2_sync_hdr *shdr = get_sync_hdr(hdr);
        char *temp = (char *)hdr;
        /* lookup word count ie StructureSize from table */
        __u16 parmsize = smb2_req_struct_sizes[le16_to_cpu(smb2_cmd)];
@@ -94,28 +95,28 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
        memset(temp, 0, 256);
 
        /* Note this is only network field converted to big endian */
-       hdr->smb2_buf_length = cpu_to_be32(parmsize + sizeof(struct smb2_hdr)
-                       - 4 /*  RFC 1001 length field itself not counted */);
+       hdr->smb2_buf_length =
+                       cpu_to_be32(parmsize + sizeof(struct smb2_sync_hdr));
 
-       hdr->ProtocolId = SMB2_PROTO_NUMBER;
-       hdr->StructureSize = cpu_to_le16(64);
-       hdr->Command = smb2_cmd;
+       shdr->ProtocolId = SMB2_PROTO_NUMBER;
+       shdr->StructureSize = cpu_to_le16(64);
+       shdr->Command = smb2_cmd;
        if (tcon && tcon->ses && tcon->ses->server) {
                struct TCP_Server_Info *server = tcon->ses->server;
 
                spin_lock(&server->req_lock);
                /* Request up to 2 credits but don't go over the limit. */
                if (server->credits >= server->max_credits)
-                       hdr->CreditRequest = cpu_to_le16(0);
+                       shdr->CreditRequest = cpu_to_le16(0);
                else
-                       hdr->CreditRequest = cpu_to_le16(
+                       shdr->CreditRequest = cpu_to_le16(
                                min_t(int, server->max_credits -
                                                server->credits, 2));
                spin_unlock(&server->req_lock);
        } else {
-               hdr->CreditRequest = cpu_to_le16(2);
+               shdr->CreditRequest = cpu_to_le16(2);
        }
-       hdr->ProcessId = cpu_to_le32((__u16)current->tgid);
+       shdr->ProcessId = cpu_to_le32((__u16)current->tgid);
 
        if (!tcon)
                goto out;
@@ -124,13 +125,13 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
        /* See sections 2.2.4 and 3.2.4.1.5 of MS-SMB2 */
        if ((tcon->ses) && (tcon->ses->server) &&
            (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LARGE_MTU))
-               hdr->CreditCharge = cpu_to_le16(1);
+               shdr->CreditCharge = cpu_to_le16(1);
        /* else CreditCharge MBZ */
 
-       hdr->TreeId = tcon->tid;
+       shdr->TreeId = tcon->tid;
        /* Uid is not converted */
        if (tcon->ses)
-               hdr->SessionId = tcon->ses->Suid;
+               shdr->SessionId = tcon->ses->Suid;
 
        /*
         * If we would set SMB2_FLAGS_DFS_OPERATIONS on open we also would have
@@ -143,10 +144,10 @@ smb2_hdr_assemble(struct smb2_hdr *hdr, __le16 smb2_cmd /* command */ ,
         * but it is safer to net set it for now.
         */
 /*     if (tcon->share_flags & SHI1005_FLAGS_DFS)
-               hdr->Flags |= SMB2_FLAGS_DFS_OPERATIONS; */
+               shdr->Flags |= SMB2_FLAGS_DFS_OPERATIONS; */
 
        if (tcon->ses && tcon->ses->server && tcon->ses->server->sign)
-               hdr->Flags |= SMB2_FLAGS_SIGNED;
+               shdr->Flags |= SMB2_FLAGS_SIGNED;
 out:
        pdu->StructureSize2 = cpu_to_le16(parmsize);
        return;
@@ -250,16 +251,19 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon)
        }
 
        cifs_mark_open_files_invalid(tcon);
+       if (tcon->use_persistent)
+               tcon->need_reopen_files = true;
 
        rc = SMB2_tcon(0, tcon->ses, tcon->treeName, tcon, nls_codepage);
        mutex_unlock(&tcon->ses->session_mutex);
 
-       if (tcon->use_persistent)
-               cifs_reopen_persistent_handles(tcon);
-
        cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc);
        if (rc)
                goto out;
+
+       if (smb2_command != SMB2_INTERNAL_CMD)
+               queue_delayed_work(cifsiod_wq, &server->reconnect, 0);
+
        atomic_inc(&tconInfoReconnectCount);
 out:
        /*
@@ -280,7 +284,7 @@ out:
        case SMB2_CHANGE_NOTIFY:
        case SMB2_QUERY_INFO:
        case SMB2_SET_INFO:
-               return -EAGAIN;
+               rc = -EAGAIN;
        }
        unload_nls(nls_codepage);
        return rc;
@@ -413,7 +417,7 @@ SMB2_negotiate(const unsigned int xid, struct cifs_ses *ses)
        if (rc)
                return rc;
 
-       req->hdr.SessionId = 0;
+       req->hdr.sync_hdr.SessionId = 0;
 
        req->Dialects[0] = cpu_to_le16(ses->server->vals->protocol_id);
 
@@ -624,14 +628,15 @@ SMB2_sess_alloc_buffer(struct SMB2_sess_data *sess_data)
        if (rc)
                return rc;
 
-       req->hdr.SessionId = 0; /* First session, not a reauthenticate */
+       /* First session, not a reauthenticate */
+       req->hdr.sync_hdr.SessionId = 0;
 
        /* if reconnect, we need to send previous sess id, otherwise it is 0 */
        req->PreviousSessionId = sess_data->previous_session;
 
        req->Flags = 0; /* MBZ */
        /* to enable echos and oplocks */
-       req->hdr.CreditRequest = cpu_to_le16(3);
+       req->hdr.sync_hdr.CreditRequest = cpu_to_le16(3);
 
        /* only one of SMB2 signing flags may be set in SMB2 request */
        if (server->sign)
@@ -778,7 +783,7 @@ SMB2_auth_kerberos(struct SMB2_sess_data *sess_data)
                goto out_put_spnego_key;
 
        rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base;
-       ses->Suid = rsp->hdr.SessionId;
+       ses->Suid = rsp->hdr.sync_hdr.SessionId;
 
        ses->session_flags = le16_to_cpu(rsp->SessionFlags);
        if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
@@ -856,7 +861,7 @@ SMB2_sess_auth_rawntlmssp_negotiate(struct SMB2_sess_data *sess_data)
 
        /* If true, rc here is expected and not an error */
        if (sess_data->buf0_type != CIFS_NO_BUFFER &&
-               rsp->hdr.Status == STATUS_MORE_PROCESSING_REQUIRED)
+               rsp->hdr.sync_hdr.Status == STATUS_MORE_PROCESSING_REQUIRED)
                rc = 0;
 
        if (rc)
@@ -877,7 +882,7 @@ SMB2_sess_auth_rawntlmssp_negotiate(struct SMB2_sess_data *sess_data)
        cifs_dbg(FYI, "rawntlmssp session setup challenge phase\n");
 
 
-       ses->Suid = rsp->hdr.SessionId;
+       ses->Suid = rsp->hdr.sync_hdr.SessionId;
        ses->session_flags = le16_to_cpu(rsp->SessionFlags);
        if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
                cifs_dbg(VFS, "SMB3 encryption not supported yet\n");
@@ -913,7 +918,7 @@ SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data)
                goto out;
 
        req = (struct smb2_sess_setup_req *) sess_data->iov[0].iov_base;
-       req->hdr.SessionId = ses->Suid;
+       req->hdr.sync_hdr.SessionId = ses->Suid;
 
        rc = build_ntlmssp_auth_blob(&ntlmssp_blob, &blob_length, ses,
                                        sess_data->nls_cp);
@@ -937,7 +942,7 @@ SMB2_sess_auth_rawntlmssp_authenticate(struct SMB2_sess_data *sess_data)
 
        rsp = (struct smb2_sess_setup_rsp *)sess_data->iov[0].iov_base;
 
-       ses->Suid = rsp->hdr.SessionId;
+       ses->Suid = rsp->hdr.sync_hdr.SessionId;
        ses->session_flags = le16_to_cpu(rsp->SessionFlags);
        if (ses->session_flags & SMB2_SESSION_FLAG_ENCRYPT_DATA)
                cifs_dbg(VFS, "SMB3 encryption not supported yet\n");
@@ -1032,9 +1037,9 @@ SMB2_logoff(const unsigned int xid, struct cifs_ses *ses)
                return rc;
 
         /* since no tcon, smb2_init can not do this, so do here */
-       req->hdr.SessionId = ses->Suid;
+       req->hdr.sync_hdr.SessionId = ses->Suid;
        if (server->sign)
-               req->hdr.Flags |= SMB2_FLAGS_SIGNED;
+               req->hdr.sync_hdr.Flags |= SMB2_FLAGS_SIGNED;
 
        rc = SendReceiveNoRsp(xid, ses, (char *) &req->hdr, 0);
        /*
@@ -1109,7 +1114,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
 
        if (tcon == NULL) {
                /* since no tcon, smb2_init can not do this, so do here */
-               req->hdr.SessionId = ses->Suid;
+               req->hdr.sync_hdr.SessionId = ses->Suid;
                /* if (ses->server->sec_mode & SECMODE_SIGN_REQUIRED)
                        req->hdr.Flags |= SMB2_FLAGS_SIGNED; */
        }
@@ -1139,7 +1144,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
        }
 
        if (tcon == NULL) {
-               ses->ipc_tid = rsp->hdr.TreeId;
+               ses->ipc_tid = rsp->hdr.sync_hdr.TreeId;
                goto tcon_exit;
        }
 
@@ -1162,7 +1167,7 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
        tcon->maximal_access = le32_to_cpu(rsp->MaximalAccess);
        tcon->tidStatus = CifsGood;
        tcon->need_reconnect = false;
-       tcon->tid = rsp->hdr.TreeId;
+       tcon->tid = rsp->hdr.sync_hdr.TreeId;
        strlcpy(tcon->treeName, tree, sizeof(tcon->treeName));
 
        if ((rsp->Capabilities & SMB2_SHARE_CAP_DFS) &&
@@ -1179,7 +1184,7 @@ tcon_exit:
        return rc;
 
 tcon_error_exit:
-       if (rsp->hdr.Status == STATUS_BAD_NETWORK_NAME) {
+       if (rsp->hdr.sync_hdr.Status == STATUS_BAD_NETWORK_NAME) {
                cifs_dbg(VFS, "BAD_NETWORK_NAME: %s\n", tree);
                if (tcon)
                        tcon->bad_network_name = true;
@@ -1615,6 +1620,7 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
 {
        struct smb2_ioctl_req *req;
        struct smb2_ioctl_rsp *rsp;
+       struct smb2_sync_hdr *shdr;
        struct TCP_Server_Info *server;
        struct cifs_ses *ses;
        struct kvec iov[2];
@@ -1739,9 +1745,8 @@ SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, u64 persistent_fid,
                goto ioctl_exit;
        }
 
-       memcpy(*out_data,
-              (char *)&rsp->hdr.ProtocolId + le32_to_cpu(rsp->OutputOffset),
-              *plen);
+       shdr = get_sync_hdr(rsp);
+       memcpy(*out_data, (char *)shdr + le32_to_cpu(rsp->OutputOffset), *plen);
 ioctl_exit:
        free_rsp_buf(resp_buftype, rsp);
        return rc;
@@ -1960,11 +1965,11 @@ static void
 smb2_echo_callback(struct mid_q_entry *mid)
 {
        struct TCP_Server_Info *server = mid->callback_data;
-       struct smb2_echo_rsp *smb2 = (struct smb2_echo_rsp *)mid->resp_buf;
+       struct smb2_echo_rsp *rsp = (struct smb2_echo_rsp *)mid->resp_buf;
        unsigned int credits_received = 1;
 
        if (mid->mid_state == MID_RESPONSE_RECEIVED)
-               credits_received = le16_to_cpu(smb2->hdr.CreditRequest);
+               credits_received = le16_to_cpu(rsp->hdr.sync_hdr.CreditRequest);
 
        mutex_lock(&server->srv_mutex);
        DeleteMidQEntry(mid);
@@ -1972,6 +1977,55 @@ smb2_echo_callback(struct mid_q_entry *mid)
        add_credits(server, credits_received, CIFS_ECHO_OP);
 }
 
+void smb2_reconnect_server(struct work_struct *work)
+{
+       struct TCP_Server_Info *server = container_of(work,
+                                       struct TCP_Server_Info, reconnect.work);
+       struct cifs_ses *ses;
+       struct cifs_tcon *tcon, *tcon2;
+       struct list_head tmp_list;
+       int tcon_exist = false;
+
+       /* Prevent simultaneous reconnects that can corrupt tcon->rlist list */
+       mutex_lock(&server->reconnect_mutex);
+
+       INIT_LIST_HEAD(&tmp_list);
+       cifs_dbg(FYI, "Need negotiate, reconnecting tcons\n");
+
+       spin_lock(&cifs_tcp_ses_lock);
+       list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
+               list_for_each_entry(tcon, &ses->tcon_list, tcon_list) {
+                       if (tcon->need_reconnect || tcon->need_reopen_files) {
+                               tcon->tc_count++;
+                               list_add_tail(&tcon->rlist, &tmp_list);
+                               tcon_exist = true;
+                       }
+               }
+       }
+       /*
+        * Get the reference to server struct to be sure that the last call of
+        * cifs_put_tcon() in the loop below won't release the server pointer.
+        */
+       if (tcon_exist)
+               server->srv_count++;
+
+       spin_unlock(&cifs_tcp_ses_lock);
+
+       list_for_each_entry_safe(tcon, tcon2, &tmp_list, rlist) {
+               if (!smb2_reconnect(SMB2_INTERNAL_CMD, tcon))
+                       cifs_reopen_persistent_handles(tcon);
+               list_del_init(&tcon->rlist);
+               cifs_put_tcon(tcon);
+       }
+
+       cifs_dbg(FYI, "Reconnecting tcons finished\n");
+       mutex_unlock(&server->reconnect_mutex);
+
+       /* now we can safely release srv struct */
+       if (tcon_exist)
+               cifs_put_tcp_session(server, 1);
+}
+
 int
 SMB2_echo(struct TCP_Server_Info *server)
 {
@@ -1984,37 +2038,16 @@ SMB2_echo(struct TCP_Server_Info *server)
        cifs_dbg(FYI, "In echo request\n");
 
        if (server->tcpStatus == CifsNeedNegotiate) {
-               struct list_head *tmp, *tmp2;
-               struct cifs_ses *ses;
-               struct cifs_tcon *tcon;
-
-               cifs_dbg(FYI, "Need negotiate, reconnecting tcons\n");
-               spin_lock(&cifs_tcp_ses_lock);
-               list_for_each(tmp, &server->smb_ses_list) {
-                       ses = list_entry(tmp, struct cifs_ses, smb_ses_list);
-                       list_for_each(tmp2, &ses->tcon_list) {
-                               tcon = list_entry(tmp2, struct cifs_tcon,
-                                                 tcon_list);
-                               /* add check for persistent handle reconnect */
-                               if (tcon && tcon->need_reconnect) {
-                                       spin_unlock(&cifs_tcp_ses_lock);
-                                       rc = smb2_reconnect(SMB2_ECHO, tcon);
-                                       spin_lock(&cifs_tcp_ses_lock);
-                               }
-                       }
-               }
-               spin_unlock(&cifs_tcp_ses_lock);
+               /* No need to send echo on newly established connections */
+               queue_delayed_work(cifsiod_wq, &server->reconnect, 0);
+               return rc;
        }
 
-       /* if no session, renegotiate failed above */
-       if (server->tcpStatus == CifsNeedNegotiate)
-               return -EIO;
-
        rc = small_smb2_init(SMB2_ECHO, NULL, (void **)&req);
        if (rc)
                return rc;
 
-       req->hdr.CreditRequest = cpu_to_le16(1);
+       req->hdr.sync_hdr.CreditRequest = cpu_to_le16(1);
 
        iov.iov_base = (char *)req;
        /* 4 for rfc1002 length field */
@@ -2077,6 +2110,7 @@ smb2_new_read_req(struct kvec *iov, struct cifs_io_parms *io_parms,
 {
        int rc = -EACCES;
        struct smb2_read_req *req = NULL;
+       struct smb2_sync_hdr *shdr;
 
        rc = small_smb2_init(SMB2_READ, io_parms->tcon, (void **) &req);
        if (rc)
@@ -2084,7 +2118,8 @@ smb2_new_read_req(struct kvec *iov, struct cifs_io_parms *io_parms,
        if (io_parms->tcon->ses->server == NULL)
                return -ECONNABORTED;
 
-       req->hdr.ProcessId = cpu_to_le32(io_parms->pid);
+       shdr = get_sync_hdr(req);
+       shdr->ProcessId = cpu_to_le32(io_parms->pid);
 
        req->PersistentFileId = io_parms->persistent_fid;
        req->VolatileFileId = io_parms->volatile_fid;
@@ -2098,18 +2133,18 @@ smb2_new_read_req(struct kvec *iov, struct cifs_io_parms *io_parms,
        if (request_type & CHAINED_REQUEST) {
                if (!(request_type & END_OF_CHAIN)) {
                        /* 4 for rfc1002 length field */
-                       req->hdr.NextCommand =
+                       shdr->NextCommand =
                                cpu_to_le32(get_rfc1002_length(req) + 4);
                } else /* END_OF_CHAIN */
-                       req->hdr.NextCommand = 0;
+                       shdr->NextCommand = 0;
                if (request_type & RELATED_REQUEST) {
-                       req->hdr.Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
+                       shdr->Flags |= SMB2_FLAGS_RELATED_OPERATIONS;
                        /*
                         * Related requests use info from previous read request
                         * in chain.
                         */
-                       req->hdr.SessionId = 0xFFFFFFFF;
-                       req->hdr.TreeId = 0xFFFFFFFF;
+                       shdr->SessionId = 0xFFFFFFFF;
+                       shdr->TreeId = 0xFFFFFFFF;
                        req->PersistentFileId = 0xFFFFFFFF;
                        req->VolatileFileId = 0xFFFFFFFF;
                }
@@ -2131,7 +2166,7 @@ smb2_readv_callback(struct mid_q_entry *mid)
        struct cifs_readdata *rdata = mid->callback_data;
        struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink);
        struct TCP_Server_Info *server = tcon->ses->server;
-       struct smb2_hdr *buf = (struct smb2_hdr *)rdata->iov.iov_base;
+       struct smb2_sync_hdr *shdr = get_sync_hdr(rdata->iov.iov_base);
        unsigned int credits_received = 1;
        struct smb_rqst rqst = { .rq_iov = &rdata->iov,
                                 .rq_nvec = 1,
@@ -2146,7 +2181,7 @@ smb2_readv_callback(struct mid_q_entry *mid)
 
        switch (mid->mid_state) {
        case MID_RESPONSE_RECEIVED:
-               credits_received = le16_to_cpu(buf->CreditRequest);
+               credits_received = le16_to_cpu(shdr->CreditRequest);
                /* result already set, check signature */
                if (server->sign) {
                        int rc;
@@ -2190,7 +2225,8 @@ int
 smb2_async_readv(struct cifs_readdata *rdata)
 {
        int rc, flags = 0;
-       struct smb2_hdr *buf;
+       char *buf;
+       struct smb2_sync_hdr *shdr;
        struct cifs_io_parms io_parms;
        struct smb_rqst rqst = { .rq_iov = &rdata->iov,
                                 .rq_nvec = 1 };
@@ -2221,17 +2257,18 @@ smb2_async_readv(struct cifs_readdata *rdata)
                return rc;
        }
 
-       buf = (struct smb2_hdr *)rdata->iov.iov_base;
+       buf = rdata->iov.iov_base;
+       shdr = get_sync_hdr(buf);
        /* 4 for rfc1002 length field */
        rdata->iov.iov_len = get_rfc1002_length(rdata->iov.iov_base) + 4;
 
        if (rdata->credits) {
-               buf->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes,
+               shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes,
                                                SMB2_MAX_BUFFER_SIZE));
-               buf->CreditRequest = buf->CreditCharge;
+               shdr->CreditRequest = shdr->CreditCharge;
                spin_lock(&server->req_lock);
                server->credits += rdata->credits -
-                                               le16_to_cpu(buf->CreditCharge);
+                                               le16_to_cpu(shdr->CreditCharge);
                spin_unlock(&server->req_lock);
                wake_up(&server->request_q);
                flags = CIFS_HAS_CREDITS;
@@ -2256,6 +2293,7 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
 {
        int resp_buftype, rc = -EACCES;
        struct smb2_read_rsp *rsp = NULL;
+       struct smb2_sync_hdr *shdr;
        struct kvec iov[1];
 
        *nbytes = 0;
@@ -2267,8 +2305,9 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
                          &resp_buftype, CIFS_LOG_ERROR);
 
        rsp = (struct smb2_read_rsp *)iov[0].iov_base;
+       shdr = get_sync_hdr(rsp);
 
-       if (rsp->hdr.Status == STATUS_END_OF_FILE) {
+       if (shdr->Status == STATUS_END_OF_FILE) {
                free_rsp_buf(resp_buftype, iov[0].iov_base);
                return 0;
        }
@@ -2288,8 +2327,7 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
        }
 
        if (*buf) {
-               memcpy(*buf, (char *)&rsp->hdr.ProtocolId + rsp->DataOffset,
-                      *nbytes);
+               memcpy(*buf, (char *)shdr + rsp->DataOffset, *nbytes);
                free_rsp_buf(resp_buftype, iov[0].iov_base);
        } else if (resp_buftype != CIFS_NO_BUFFER) {
                *buf = iov[0].iov_base;
@@ -2317,7 +2355,7 @@ smb2_writev_callback(struct mid_q_entry *mid)
 
        switch (mid->mid_state) {
        case MID_RESPONSE_RECEIVED:
-               credits_received = le16_to_cpu(rsp->hdr.CreditRequest);
+               credits_received = le16_to_cpu(rsp->hdr.sync_hdr.CreditRequest);
                wdata->result = smb2_check_receive(mid, tcon->ses->server, 0);
                if (wdata->result != 0)
                        break;
@@ -2363,6 +2401,7 @@ smb2_async_writev(struct cifs_writedata *wdata,
 {
        int rc = -EACCES, flags = 0;
        struct smb2_write_req *req = NULL;
+       struct smb2_sync_hdr *shdr;
        struct cifs_tcon *tcon = tlink_tcon(wdata->cfile->tlink);
        struct TCP_Server_Info *server = tcon->ses->server;
        struct kvec iov;
@@ -2381,7 +2420,8 @@ smb2_async_writev(struct cifs_writedata *wdata,
                goto async_writev_out;
        }
 
-       req->hdr.ProcessId = cpu_to_le32(wdata->cfile->pid);
+       shdr = get_sync_hdr(req);
+       shdr->ProcessId = cpu_to_le32(wdata->cfile->pid);
 
        req->PersistentFileId = wdata->cfile->fid.persistent_fid;
        req->VolatileFileId = wdata->cfile->fid.volatile_fid;
@@ -2413,12 +2453,12 @@ smb2_async_writev(struct cifs_writedata *wdata,
        inc_rfc1001_len(&req->hdr, wdata->bytes - 1 /* Buffer */);
 
        if (wdata->credits) {
-               req->hdr.CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes,
+               shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes,
                                                    SMB2_MAX_BUFFER_SIZE));
-               req->hdr.CreditRequest = req->hdr.CreditCharge;
+               shdr->CreditRequest = shdr->CreditCharge;
                spin_lock(&server->req_lock);
                server->credits += wdata->credits -
-                                       le16_to_cpu(req->hdr.CreditCharge);
+                                               le16_to_cpu(shdr->CreditCharge);
                spin_unlock(&server->req_lock);
                wake_up(&server->request_q);
                flags = CIFS_HAS_CREDITS;
@@ -2464,7 +2504,7 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
        if (io_parms->tcon->ses->server == NULL)
                return -ECONNABORTED;
 
-       req->hdr.ProcessId = cpu_to_le32(io_parms->pid);
+       req->hdr.sync_hdr.ProcessId = cpu_to_le32(io_parms->pid);
 
        req->PersistentFileId = io_parms->persistent_fid;
        req->VolatileFileId = io_parms->volatile_fid;
@@ -2618,7 +2658,8 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
        rsp = (struct smb2_query_directory_rsp *)iov[0].iov_base;
 
        if (rc) {
-               if (rc == -ENODATA && rsp->hdr.Status == STATUS_NO_MORE_FILES) {
+               if (rc == -ENODATA &&
+                   rsp->hdr.sync_hdr.Status == STATUS_NO_MORE_FILES) {
                        srch_inf->endOfSearch = true;
                        rc = 0;
                }
@@ -2698,7 +2739,7 @@ send_set_info(const unsigned int xid, struct cifs_tcon *tcon,
                return rc;
        }
 
-       req->hdr.ProcessId = cpu_to_le32(pid);
+       req->hdr.sync_hdr.ProcessId = cpu_to_le32(pid);
 
        req->InfoType = SMB2_O_INFO_FILE;
        req->FileInfoClass = info_class;
@@ -2864,7 +2905,7 @@ SMB2_oplock_break(const unsigned int xid, struct cifs_tcon *tcon,
        req->VolatileFid = volatile_fid;
        req->PersistentFid = persistent_fid;
        req->OplockLevel = oplock_level;
-       req->hdr.CreditRequest = cpu_to_le16(1);
+       req->hdr.sync_hdr.CreditRequest = cpu_to_le16(1);
 
        rc = SendReceiveNoRsp(xid, tcon->ses, (char *) req, CIFS_OBREAK_OP);
        /* SMB2 buffer freed by function above */
@@ -3038,7 +3079,7 @@ smb2_lockv(const unsigned int xid, struct cifs_tcon *tcon,
        if (rc)
                return rc;
 
-       req->hdr.ProcessId = cpu_to_le32(pid);
+       req->hdr.sync_hdr.ProcessId = cpu_to_le32(pid);
        req->LockCount = cpu_to_le16(num_lock);
 
        req->PersistentFileId = persist_fid;
@@ -3093,7 +3134,7 @@ SMB2_lease_break(const unsigned int xid, struct cifs_tcon *tcon,
        if (rc)
                return rc;
 
-       req->hdr.CreditRequest = cpu_to_le16(1);
+       req->hdr.sync_hdr.CreditRequest = cpu_to_le16(1);
        req->StructureSize = cpu_to_le16(36);
        inc_rfc1001_len(req, 12);