Commit 1eb9fb52 authored by Ronnie Sahlberg's avatar Ronnie Sahlberg Committed by Steve French

cifs: create SMB2_open_init()/SMB2_open_free() helpers.

Signed-off-by: default avatarRonnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
Reviewed-by: default avatarPaulo Alcantara <palcantara@suse.com>
Reviewed-by: default avatarPavel Shilovsky <pshilov@microsoft.com>
parent 296ecbae
...@@ -2052,43 +2052,27 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode, ...@@ -2052,43 +2052,27 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode,
} }
int int
SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, SMB2_open_init(struct cifs_tcon *tcon, struct smb_rqst *rqst, __u8 *oplock,
__u8 *oplock, struct smb2_file_all_info *buf, struct cifs_open_parms *oparms, __le16 *path)
struct kvec *err_iov, int *buftype)
{ {
struct smb_rqst rqst; struct TCP_Server_Info *server = tcon->ses->server;
struct smb2_create_req *req; 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[5]; /* make sure at least one for each open context */
struct kvec rsp_iov = {NULL, 0};
int resp_buftype;
int uni_path_len;
__le16 *copy_path = NULL;
int copy_size;
int rc = 0;
unsigned int n_iov = 2; unsigned int n_iov = 2;
__u32 file_attributes = 0; __u32 file_attributes = 0;
char *dhc_buf = NULL, *lc_buf = NULL, *pc_buf = NULL; int copy_size;
int flags = 0; int uni_path_len;
unsigned int total_len; unsigned int total_len;
struct kvec *iov = rqst->rq_iov;
cifs_dbg(FYI, "create/open\n"); __le16 *copy_path;
int rc;
if (ses && (ses->server))
server = ses->server;
else
return -EIO;
rc = smb2_plain_req_init(SMB2_CREATE, tcon, (void **) &req, &total_len); rc = smb2_plain_req_init(SMB2_CREATE, tcon, (void **) &req, &total_len);
if (rc) if (rc)
return rc; return rc;
if (smb3_encryption_required(tcon)) iov[0].iov_base = (char *)req;
flags |= CIFS_TRANSFORM_REQ; /* -1 since last byte is buf[0] which is sent below (path) */
iov[0].iov_len = total_len - 1;
if (oparms->create_options & CREATE_OPTION_READONLY) if (oparms->create_options & CREATE_OPTION_READONLY)
file_attributes |= ATTR_READONLY; file_attributes |= ATTR_READONLY;
...@@ -2102,11 +2086,6 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, ...@@ -2102,11 +2086,6 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
req->ShareAccess = FILE_SHARE_ALL_LE; req->ShareAccess = FILE_SHARE_ALL_LE;
req->CreateDisposition = cpu_to_le32(oparms->disposition); req->CreateDisposition = cpu_to_le32(oparms->disposition);
req->CreateOptions = cpu_to_le32(oparms->create_options & CREATE_OPTIONS_MASK); req->CreateOptions = cpu_to_le32(oparms->create_options & CREATE_OPTIONS_MASK);
iov[0].iov_base = (char *)req;
/* -1 since last byte is buf[0] which is sent below (path) */
iov[0].iov_len = total_len - 1;
req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req)); req->NameOffset = cpu_to_le16(sizeof(struct smb2_create_req));
/* [MS-SMB2] 2.2.13 NameOffset: /* [MS-SMB2] 2.2.13 NameOffset:
...@@ -2124,10 +2103,8 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, ...@@ -2124,10 +2103,8 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
rc = alloc_path_with_tree_prefix(&copy_path, &copy_size, rc = alloc_path_with_tree_prefix(&copy_path, &copy_size,
&name_len, &name_len,
tcon->treeName, path); tcon->treeName, path);
if (rc) { if (rc)
cifs_small_buf_release(req);
return rc; return rc;
}
req->NameLength = cpu_to_le16(name_len * 2); req->NameLength = cpu_to_le16(name_len * 2);
uni_path_len = copy_size; uni_path_len = copy_size;
path = copy_path; path = copy_path;
...@@ -2135,19 +2112,17 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, ...@@ -2135,19 +2112,17 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2; uni_path_len = (2 * UniStrnlen((wchar_t *)path, PATH_MAX)) + 2;
/* MUST set path len (NameLength) to 0 opening root of share */ /* MUST set path len (NameLength) to 0 opening root of share */
req->NameLength = cpu_to_le16(uni_path_len - 2); req->NameLength = cpu_to_le16(uni_path_len - 2);
if (uni_path_len % 8 != 0) { copy_size = uni_path_len;
copy_size = roundup(uni_path_len, 8); if (copy_size % 8 != 0)
copy_size = roundup(copy_size, 8);
copy_path = kzalloc(copy_size, GFP_KERNEL); copy_path = kzalloc(copy_size, GFP_KERNEL);
if (!copy_path) { if (!copy_path)
cifs_small_buf_release(req);
return -ENOMEM; return -ENOMEM;
}
memcpy((char *)copy_path, (const char *)path, memcpy((char *)copy_path, (const char *)path,
uni_path_len); uni_path_len);
uni_path_len = copy_size; uni_path_len = copy_size;
path = copy_path; path = copy_path;
} }
}
iov[1].iov_len = uni_path_len; iov[1].iov_len = uni_path_len;
iov[1].iov_base = path; iov[1].iov_base = path;
...@@ -2161,13 +2136,9 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, ...@@ -2161,13 +2136,9 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
else { else {
rc = add_lease_context(server, iov, &n_iov, rc = add_lease_context(server, iov, &n_iov,
oparms->fid->lease_key, oplock); oparms->fid->lease_key, oplock);
if (rc) { if (rc)
cifs_small_buf_release(req);
kfree(copy_path);
return rc; return rc;
} }
lc_buf = iov[n_iov-1].iov_base;
}
if (*oplock == SMB2_OPLOCK_LEVEL_BATCH) { if (*oplock == SMB2_OPLOCK_LEVEL_BATCH) {
/* need to set Next field of lease context if we request it */ /* need to set Next field of lease context if we request it */
...@@ -2180,14 +2151,9 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, ...@@ -2180,14 +2151,9 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
rc = add_durable_context(iov, &n_iov, oparms, rc = add_durable_context(iov, &n_iov, oparms,
tcon->use_persistent); tcon->use_persistent);
if (rc) { if (rc)
cifs_small_buf_release(req);
kfree(copy_path);
kfree(lc_buf);
return rc; return rc;
} }
dhc_buf = iov[n_iov-1].iov_base;
}
if (tcon->posix_extensions) { if (tcon->posix_extensions) {
if (n_iov > 2) { if (n_iov > 2) {
...@@ -2198,23 +2164,63 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, ...@@ -2198,23 +2164,63 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
} }
rc = add_posix_context(iov, &n_iov, oparms->mode); rc = add_posix_context(iov, &n_iov, oparms->mode);
if (rc) { if (rc)
cifs_small_buf_release(req);
kfree(copy_path);
kfree(lc_buf);
kfree(dhc_buf);
return rc; return rc;
} }
pc_buf = iov[n_iov-1].iov_base;
} rqst->rq_nvec = n_iov;
return 0;
}
/* rq_iov[0] is the request and is released by cifs_small_buf_release().
* All other vectors are freed by kfree().
*/
void
SMB2_open_free(struct smb_rqst *rqst)
{
int i;
cifs_small_buf_release(rqst->rq_iov[0].iov_base);
for (i = 1; i < rqst->rq_nvec; i++)
kfree(rqst->rq_iov[i].iov_base);
}
int
SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
__u8 *oplock, struct smb2_file_all_info *buf,
struct kvec *err_iov, int *buftype)
{
struct smb_rqst rqst;
struct smb2_create_rsp *rsp = NULL;
struct TCP_Server_Info *server;
struct cifs_tcon *tcon = oparms->tcon;
struct cifs_ses *ses = tcon->ses;
struct kvec iov[5]; /* make sure at least one for each open context */
struct kvec rsp_iov = {NULL, 0};
int resp_buftype;
int rc = 0;
int flags = 0;
cifs_dbg(FYI, "create/open\n");
if (ses && (ses->server))
server = ses->server;
else
return -EIO;
if (smb3_encryption_required(tcon))
flags |= CIFS_TRANSFORM_REQ;
memset(&rqst, 0, sizeof(struct smb_rqst)); memset(&rqst, 0, sizeof(struct smb_rqst));
memset(&iov, 0, sizeof(iov));
rqst.rq_iov = iov; rqst.rq_iov = iov;
rqst.rq_nvec = n_iov; rqst.rq_nvec = 5;
rc = SMB2_open_init(tcon, &rqst, oplock, oparms, path);
if (rc)
goto creat_exit;
rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags, rc = cifs_send_recv(xid, ses, &rqst, &resp_buftype, flags,
&rsp_iov); &rsp_iov);
cifs_small_buf_release(req);
rsp = (struct smb2_create_rsp *)rsp_iov.iov_base; rsp = (struct smb2_create_rsp *)rsp_iov.iov_base;
if (rc != 0) { if (rc != 0) {
...@@ -2251,10 +2257,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path, ...@@ -2251,10 +2257,7 @@ SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, __le16 *path,
else else
*oplock = rsp->OplockLevel; *oplock = rsp->OplockLevel;
creat_exit: creat_exit:
kfree(copy_path); SMB2_open_free(&rqst);
kfree(lc_buf);
kfree(dhc_buf);
kfree(pc_buf);
free_rsp_buf(resp_buftype, rsp); free_rsp_buf(resp_buftype, rsp);
return rc; return rc;
} }
......
...@@ -133,6 +133,10 @@ extern int SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms, ...@@ -133,6 +133,10 @@ extern int SMB2_open(const unsigned int xid, struct cifs_open_parms *oparms,
__le16 *path, __u8 *oplock, __le16 *path, __u8 *oplock,
struct smb2_file_all_info *buf, struct smb2_file_all_info *buf,
struct kvec *err_iov, int *resp_buftype); struct kvec *err_iov, int *resp_buftype);
extern int SMB2_open_init(struct cifs_tcon *tcon, struct smb_rqst *rqst,
__u8 *oplock, struct cifs_open_parms *oparms,
__le16 *path);
extern void SMB2_open_free(struct smb_rqst *rqst);
extern int SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon, extern int SMB2_ioctl(const unsigned int xid, struct cifs_tcon *tcon,
u64 persistent_fid, u64 volatile_fid, u32 opcode, u64 persistent_fid, u64 volatile_fid, u32 opcode,
bool is_fsctl, char *in_data, u32 indatalen, bool is_fsctl, char *in_data, u32 indatalen,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment