cifs: remove rfc1002 header from smb2 read/write requests
authorRonnie Sahlberg <lsahlber@redhat.com>
Mon, 20 Nov 2017 00:24:41 +0000 (11:24 +1100)
committerSteve French <smfrench@gmail.com>
Thu, 25 Jan 2018 01:49:04 +0000 (19:49 -0600)
Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <smfrench@gmail.com>
Acked-by: Pavel Shilovsky <pshilov@microsoft.com>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
fs/cifs/smb2pdu.c
fs/cifs/smb2pdu.h

index 1b0f3c9d1426e6024720456eb352cbab51336798..9cce02d20576751be3052f9c138cf957009e81c9 100644 (file)
@@ -2666,10 +2666,9 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
        struct smb2_read_plain_req *req = NULL;
        struct smb2_read_rsp *rsp = NULL;
        struct smb2_sync_hdr *shdr;
-       struct kvec iov[2];
+       struct kvec iov[1];
        struct kvec rsp_iov;
        unsigned int total_len;
-       __be32 req_len;
        struct smb_rqst rqst = { .rq_iov = iov,
                                 .rq_nvec = 2 };
        int flags = CIFS_LOG_ERROR;
@@ -2683,14 +2682,10 @@ SMB2_read(const unsigned int xid, struct cifs_io_parms *io_parms,
        if (encryption_required(io_parms->tcon))
                flags |= CIFS_TRANSFORM_REQ;
 
-       req_len = cpu_to_be32(total_len);
-
-       iov[0].iov_base = &req_len;
-       iov[0].iov_len = sizeof(__be32);
-       iov[1].iov_base = req;
-       iov[1].iov_len = total_len;
+       iov[0].iov_base = (char *)req;
+       iov[0].iov_len = total_len;
 
-       rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags, &rsp_iov);
+       rc = smb2_send_recv(xid, ses, iov, 1, &resp_buftype, flags, &rsp_iov);
        cifs_small_buf_release(req);
 
        rsp = (struct smb2_read_rsp *)rsp_iov.iov_base;
@@ -2792,8 +2787,10 @@ smb2_async_writev(struct cifs_writedata *wdata,
        struct TCP_Server_Info *server = tcon->ses->server;
        struct kvec iov[2];
        struct smb_rqst rqst = { };
+       unsigned int total_len;
+       __be32 rfc1002_marker;
 
-       rc = small_smb2_init(SMB2_WRITE, tcon, (void **) &req);
+       rc = smb2_plain_req_init(SMB2_WRITE, tcon, (void **) &req, &total_len);
        if (rc) {
                if (rc == -EAGAIN && wdata->credits) {
                        /* credits was reset by reconnect */
@@ -2809,7 +2806,7 @@ smb2_async_writev(struct cifs_writedata *wdata,
        if (encryption_required(tcon))
                flags |= CIFS_TRANSFORM_REQ;
 
-       shdr = get_sync_hdr(req);
+       shdr = (struct smb2_sync_hdr *)req;
        shdr->ProcessId = cpu_to_le32(wdata->cfile->pid);
 
        req->PersistentFileId = wdata->cfile->fid.persistent_fid;
@@ -2818,16 +2815,16 @@ smb2_async_writev(struct cifs_writedata *wdata,
        req->WriteChannelInfoLength = 0;
        req->Channel = 0;
        req->Offset = cpu_to_le64(wdata->offset);
-       /* 4 for rfc1002 length field */
        req->DataOffset = cpu_to_le16(
-                               offsetof(struct smb2_write_req, Buffer) - 4);
+                               offsetof(struct smb2_write_req, Buffer));
        req->RemainingBytes = 0;
 
        /* 4 for rfc1002 length field and 1 for Buffer */
        iov[0].iov_len = 4;
-       iov[0].iov_base = req;
-       iov[1].iov_len = get_rfc1002_length(req) - 1;
-       iov[1].iov_base = (char *)req + 4;
+       rfc1002_marker = cpu_to_be32(total_len - 1 + wdata->bytes);
+       iov[0].iov_base = &rfc1002_marker;
+       iov[1].iov_len = total_len - 1;
+       iov[1].iov_base = (char *)req;
 
        rqst.rq_iov = iov;
        rqst.rq_nvec = 2;
@@ -2841,8 +2838,6 @@ smb2_async_writev(struct cifs_writedata *wdata,
 
        req->Length = cpu_to_le32(wdata->bytes);
 
-       inc_rfc1001_len(&req->hdr, wdata->bytes - 1 /* Buffer */);
-
        if (wdata->credits) {
                shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes,
                                                    SMB2_MAX_BUFFER_SIZE));
@@ -2885,13 +2880,15 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
        int resp_buftype;
        struct kvec rsp_iov;
        int flags = 0;
+       unsigned int total_len;
 
        *nbytes = 0;
 
        if (n_vec < 1)
                return rc;
 
-       rc = small_smb2_init(SMB2_WRITE, io_parms->tcon, (void **) &req);
+       rc = smb2_plain_req_init(SMB2_WRITE, io_parms->tcon, (void **) &req,
+                            &total_len);
        if (rc)
                return rc;
 
@@ -2901,7 +2898,7 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
        if (encryption_required(io_parms->tcon))
                flags |= CIFS_TRANSFORM_REQ;
 
-       req->hdr.sync_hdr.ProcessId = cpu_to_le32(io_parms->pid);
+       req->sync_hdr.ProcessId = cpu_to_le32(io_parms->pid);
 
        req->PersistentFileId = io_parms->persistent_fid;
        req->VolatileFileId = io_parms->volatile_fid;
@@ -2910,20 +2907,16 @@ SMB2_write(const unsigned int xid, struct cifs_io_parms *io_parms,
        req->Channel = 0;
        req->Length = cpu_to_le32(io_parms->length);
        req->Offset = cpu_to_le64(io_parms->offset);
-       /* 4 for rfc1002 length field */
        req->DataOffset = cpu_to_le16(
-                               offsetof(struct smb2_write_req, Buffer) - 4);
+                               offsetof(struct smb2_write_req, Buffer));
        req->RemainingBytes = 0;
 
        iov[0].iov_base = (char *)req;
-       /* 4 for rfc1002 length field and 1 for Buffer */
-       iov[0].iov_len = get_rfc1002_length(req) + 4 - 1;
-
-       /* length of entire message including data to be written */
-       inc_rfc1001_len(req, io_parms->length - 1 /* Buffer */);
+       /* 1 for Buffer */
+       iov[0].iov_len = total_len - 1;
 
-       rc = SendReceive2(xid, io_parms->tcon->ses, iov, n_vec + 1,
-                         &resp_buftype, flags, &rsp_iov);
+       rc = smb2_send_recv(xid, io_parms->tcon->ses, iov, n_vec + 1,
+                           &resp_buftype, flags, &rsp_iov);
        cifs_small_buf_release(req);
        rsp = (struct smb2_write_rsp *)rsp_iov.iov_base;
 
index 0c33fc8cce717e0907c398fc6fcb8e042de54d05..3c856f058be7aa12640e6180ffa60492266890f0 100644 (file)
@@ -868,7 +868,7 @@ struct smb2_read_rsp {
 #define SMB2_WRITEFLAG_WRITE_UNBUFFERED        0x00000002      /* SMB3.02 or later */
 
 struct smb2_write_req {
-       struct smb2_hdr hdr;
+       struct smb2_sync_hdr sync_hdr;
        __le16 StructureSize; /* Must be 49 */
        __le16 DataOffset; /* offset from start of SMB2 header to write data */
        __le32 Length;