[CIFS] Fix minor endian error in durable handle patch series
[deliverable/linux.git] / fs / cifs / smb2pdu.c
index e65ccdb528cf05343ff1a9d9f2bb3de6deb5c673..abc9c2809b519c50623209d341733c31a752b2b3 100644 (file)
@@ -847,6 +847,52 @@ create_lease_buf(u8 *lease_key, u8 oplock)
        return buf;
 }
 
+static struct create_durable *
+create_durable_buf(void)
+{
+       struct create_durable *buf;
+
+       buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL);
+       if (!buf)
+               return NULL;
+
+       buf->ccontext.DataOffset = cpu_to_le16(offsetof
+                                       (struct create_durable, Data));
+       buf->ccontext.DataLength = cpu_to_le32(16);
+       buf->ccontext.NameOffset = cpu_to_le16(offsetof
+                               (struct create_durable, Name));
+       buf->ccontext.NameLength = cpu_to_le16(4);
+       buf->Name[0] = 'D';
+       buf->Name[1] = 'H';
+       buf->Name[2] = 'n';
+       buf->Name[3] = 'Q';
+       return buf;
+}
+
+static struct create_durable *
+create_reconnect_durable_buf(struct cifs_fid *fid)
+{
+       struct create_durable *buf;
+
+       buf = kzalloc(sizeof(struct create_durable), GFP_KERNEL);
+       if (!buf)
+               return NULL;
+
+       buf->ccontext.DataOffset = cpu_to_le16(offsetof
+                                       (struct create_durable, Data));
+       buf->ccontext.DataLength = cpu_to_le32(16);
+       buf->ccontext.NameOffset = cpu_to_le16(offsetof
+                               (struct create_durable, Name));
+       buf->ccontext.NameLength = cpu_to_le16(4);
+       buf->Data.Fid.PersistentFileId = fid->persistent_fid;
+       buf->Data.Fid.VolatileFileId = fid->volatile_fid;
+       buf->Name[0] = 'D';
+       buf->Name[1] = 'H';
+       buf->Name[2] = 'n';
+       buf->Name[3] = 'C';
+       return buf;
+}
+
 static __u8
 parse_lease_state(struct smb2_create_rsp *rsp)
 {
@@ -901,17 +947,44 @@ add_lease_context(struct kvec *iov, unsigned int *num_iovec, __u8 *oplock)
        return 0;
 }
 
+static int
+add_durable_context(struct kvec *iov, unsigned int *num_iovec,
+                   struct cifs_open_parms *oparms)
+{
+       struct smb2_create_req *req = iov[0].iov_base;
+       unsigned int num = *num_iovec;
+
+       if (oparms->reconnect) {
+               iov[num].iov_base = create_reconnect_durable_buf(oparms->fid);
+               /* indicate that we don't need to relock the file */
+               oparms->reconnect = false;
+       } else
+               iov[num].iov_base = create_durable_buf();
+       if (iov[num].iov_base == NULL)
+               return -ENOMEM;
+       iov[num].iov_len = sizeof(struct create_durable);
+       if (!req->CreateContextsOffset)
+               req->CreateContextsOffset =
+                       cpu_to_le32(sizeof(struct smb2_create_req) - 4 +
+                                                               iov[1].iov_len);
+       req->CreateContextsLength =
+                       cpu_to_le32(le32_to_cpu(req->CreateContextsLength) +
+                                               sizeof(struct create_durable));
+       inc_rfc1001_len(&req->hdr, sizeof(struct create_durable));
+       *num_iovec = num + 1;
+       return 0;
+}
+
 int
-SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path,
-         u64 *persistent_fid, u64 *volatile_fid, __u32 desired_access,
-         __u32 create_disposition, __u32 create_options, __u8 *oplock,
-         struct smb2_file_all_info *buf)
+SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
+         __u8 *oplock, struct smb2_file_all_info *buf)
 {
        struct smb2_create_req *req;
        struct smb2_create_rsp *rsp;
        struct TCP_Server_Info *server;
+       struct cifs_tcon *tcon = oparms->tcon;
        struct cifs_ses *ses = tcon->ses;
-       struct kvec iov[3];
+       struct kvec iov[4];
        int resp_buftype;
        int uni_path_len;
        __le16 *copy_path = NULL;
@@ -931,16 +1004,16 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path,
        if (rc)
                return rc;
 
-       if (create_options & CREATE_OPTION_READONLY)
+       if (oparms->create_options & CREATE_OPTION_READONLY)
                file_attributes |= ATTR_READONLY;
 
        req->ImpersonationLevel = IL_IMPERSONATION;
-       req->DesiredAccess = cpu_to_le32(desired_access);
+       req->DesiredAccess = cpu_to_le32(oparms->desired_access);
        /* File attributes ignored on open (used in create though) */
        req->FileAttributes = cpu_to_le32(file_attributes);
        req->ShareAccess = FILE_SHARE_ALL_LE;
-       req->CreateDisposition = cpu_to_le32(create_disposition);
-       req->CreateOptions = cpu_to_le32(create_options & CREATE_OPTIONS_MASK);
+       req->CreateDisposition = cpu_to_le32(oparms->disposition);
+       req->CreateOptions = cpu_to_le32(oparms->create_options & CREATE_OPTIONS_MASK);
        uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2;
        /* do not count rfc1001 len field */
        req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req) - 4);
@@ -987,6 +1060,23 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path,
                }
        }
 
+       if (*oplock == SMB2_OPLOCK_LEVEL_BATCH) {
+               /* need to set Next field of lease context if we request it */
+               if (tcon->ses->server->capabilities & SMB2_GLOBAL_CAP_LEASING) {
+                       struct create_context *ccontext =
+                           (struct create_context *)iov[num_iovecs-1].iov_base;
+                       ccontext->Next =
+                               cpu_to_le32(sizeof(struct create_lease));
+               }
+               rc = add_durable_context(iov, &num_iovecs, oparms);
+               if (rc) {
+                       cifs_small_buf_release(req);
+                       kfree(copy_path);
+                       kfree(iov[num_iovecs-1].iov_base);
+                       return rc;
+               }
+       }
+
        rc = SendReceive2(xid, ses, iov, num_iovecs, &resp_buftype, 0);
        rsp = (struct smb2_create_rsp *)iov[0].iov_base;
 
@@ -995,8 +1085,8 @@ SMB2_open(const unsigned int xid, struct cifs_tcon *tcon, __le16 *path,
                goto creat_exit;
        }
 
-       *persistent_fid = rsp->PersistentFileId;
-       *volatile_fid = rsp->VolatileFileId;
+       oparms->fid->persistent_fid = rsp->PersistentFileId;
+       oparms->fid->volatile_fid = rsp->VolatileFileId;
 
        if (buf) {
                memcpy(buf, &rsp->CreationTime, 32);
This page took 0.026851 seconds and 5 git commands to generate.