Commit d2ec43b5 authored by Volker Lendecke's avatar Volker Lendecke Committed by Steve French

cifs: Simplify SMB2_open_init()

Reduce code duplication by calculating req->CreateContextsLength in
one place.

This is the last reference to "req" in the add_*_context functions,
remove that parameter.
Signed-off-by: default avatarVolker Lendecke <vl@samba.org>
Reviewed-by: default avatarEnzo Matsumiya <ematsumiya@suse.de>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 2a8d1387
...@@ -821,7 +821,6 @@ create_posix_buf(umode_t mode) ...@@ -821,7 +821,6 @@ create_posix_buf(umode_t mode)
static int static int
add_posix_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode) add_posix_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode)
{ {
struct smb2_create_req *req = iov[0].iov_base;
unsigned int num = *num_iovec; unsigned int num = *num_iovec;
iov[num].iov_base = create_posix_buf(mode); iov[num].iov_base = create_posix_buf(mode);
...@@ -830,7 +829,6 @@ add_posix_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode) ...@@ -830,7 +829,6 @@ add_posix_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode)
if (iov[num].iov_base == NULL) if (iov[num].iov_base == NULL)
return -ENOMEM; return -ENOMEM;
iov[num].iov_len = sizeof(struct create_posix); iov[num].iov_len = sizeof(struct create_posix);
le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_posix));
*num_iovec = num + 1; *num_iovec = num + 1;
return 0; return 0;
} }
...@@ -2179,8 +2177,6 @@ add_lease_context(struct TCP_Server_Info *server, struct kvec *iov, ...@@ -2179,8 +2177,6 @@ add_lease_context(struct TCP_Server_Info *server, struct kvec *iov,
return -ENOMEM; return -ENOMEM;
iov[num].iov_len = server->vals->create_lease_size; iov[num].iov_len = server->vals->create_lease_size;
req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE; req->RequestedOplockLevel = SMB2_OPLOCK_LEVEL_LEASE;
le32_add_cpu(&req->CreateContextsLength,
server->vals->create_lease_size);
*num_iovec = num + 1; *num_iovec = num + 1;
return 0; return 0;
} }
...@@ -2259,14 +2255,12 @@ static int ...@@ -2259,14 +2255,12 @@ static int
add_durable_v2_context(struct kvec *iov, unsigned int *num_iovec, add_durable_v2_context(struct kvec *iov, unsigned int *num_iovec,
struct cifs_open_parms *oparms) struct cifs_open_parms *oparms)
{ {
struct smb2_create_req *req = iov[0].iov_base;
unsigned int num = *num_iovec; unsigned int num = *num_iovec;
iov[num].iov_base = create_durable_v2_buf(oparms); iov[num].iov_base = create_durable_v2_buf(oparms);
if (iov[num].iov_base == NULL) if (iov[num].iov_base == NULL)
return -ENOMEM; return -ENOMEM;
iov[num].iov_len = sizeof(struct create_durable_v2); iov[num].iov_len = sizeof(struct create_durable_v2);
le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable_v2));
*num_iovec = num + 1; *num_iovec = num + 1;
return 0; return 0;
} }
...@@ -2275,7 +2269,6 @@ static int ...@@ -2275,7 +2269,6 @@ static int
add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec, add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec,
struct cifs_open_parms *oparms) struct cifs_open_parms *oparms)
{ {
struct smb2_create_req *req = iov[0].iov_base;
unsigned int num = *num_iovec; unsigned int num = *num_iovec;
/* indicate that we don't need to relock the file */ /* indicate that we don't need to relock the file */
...@@ -2285,8 +2278,6 @@ add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec, ...@@ -2285,8 +2278,6 @@ add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec,
if (iov[num].iov_base == NULL) if (iov[num].iov_base == NULL)
return -ENOMEM; return -ENOMEM;
iov[num].iov_len = sizeof(struct create_durable_handle_reconnect_v2); iov[num].iov_len = sizeof(struct create_durable_handle_reconnect_v2);
le32_add_cpu(&req->CreateContextsLength,
sizeof(struct create_durable_handle_reconnect_v2));
*num_iovec = num + 1; *num_iovec = num + 1;
return 0; return 0;
} }
...@@ -2295,7 +2286,6 @@ static int ...@@ -2295,7 +2286,6 @@ static int
add_durable_context(struct kvec *iov, unsigned int *num_iovec, add_durable_context(struct kvec *iov, unsigned int *num_iovec,
struct cifs_open_parms *oparms, bool use_persistent) struct cifs_open_parms *oparms, bool use_persistent)
{ {
struct smb2_create_req *req = iov[0].iov_base;
unsigned int num = *num_iovec; unsigned int num = *num_iovec;
if (use_persistent) { if (use_persistent) {
...@@ -2315,7 +2305,6 @@ add_durable_context(struct kvec *iov, unsigned int *num_iovec, ...@@ -2315,7 +2305,6 @@ add_durable_context(struct kvec *iov, unsigned int *num_iovec,
if (iov[num].iov_base == NULL) if (iov[num].iov_base == NULL)
return -ENOMEM; return -ENOMEM;
iov[num].iov_len = sizeof(struct create_durable); iov[num].iov_len = sizeof(struct create_durable);
le32_add_cpu(&req->CreateContextsLength, sizeof(struct create_durable));
*num_iovec = num + 1; *num_iovec = num + 1;
return 0; return 0;
} }
...@@ -2349,14 +2338,12 @@ create_twarp_buf(__u64 timewarp) ...@@ -2349,14 +2338,12 @@ create_twarp_buf(__u64 timewarp)
static int static int
add_twarp_context(struct kvec *iov, unsigned int *num_iovec, __u64 timewarp) add_twarp_context(struct kvec *iov, unsigned int *num_iovec, __u64 timewarp)
{ {
struct smb2_create_req *req = iov[0].iov_base;
unsigned int num = *num_iovec; unsigned int num = *num_iovec;
iov[num].iov_base = create_twarp_buf(timewarp); iov[num].iov_base = create_twarp_buf(timewarp);
if (iov[num].iov_base == NULL) if (iov[num].iov_base == NULL)
return -ENOMEM; return -ENOMEM;
iov[num].iov_len = sizeof(struct crt_twarp_ctxt); iov[num].iov_len = sizeof(struct crt_twarp_ctxt);
le32_add_cpu(&req->CreateContextsLength, sizeof(struct crt_twarp_ctxt));
*num_iovec = num + 1; *num_iovec = num + 1;
return 0; return 0;
} }
...@@ -2479,7 +2466,6 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned int *len) ...@@ -2479,7 +2466,6 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned int *len)
static int static int
add_sd_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode, bool set_owner) add_sd_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode, bool set_owner)
{ {
struct smb2_create_req *req = iov[0].iov_base;
unsigned int num = *num_iovec; unsigned int num = *num_iovec;
unsigned int len = 0; unsigned int len = 0;
...@@ -2487,7 +2473,6 @@ add_sd_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode, bool set ...@@ -2487,7 +2473,6 @@ add_sd_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode, bool set
if (iov[num].iov_base == NULL) if (iov[num].iov_base == NULL)
return -ENOMEM; return -ENOMEM;
iov[num].iov_len = len; iov[num].iov_len = len;
le32_add_cpu(&req->CreateContextsLength, len);
*num_iovec = num + 1; *num_iovec = num + 1;
return 0; return 0;
} }
...@@ -2518,14 +2503,12 @@ create_query_id_buf(void) ...@@ -2518,14 +2503,12 @@ create_query_id_buf(void)
static int static int
add_query_id_context(struct kvec *iov, unsigned int *num_iovec) add_query_id_context(struct kvec *iov, unsigned int *num_iovec)
{ {
struct smb2_create_req *req = iov[0].iov_base;
unsigned int num = *num_iovec; unsigned int num = *num_iovec;
iov[num].iov_base = create_query_id_buf(); iov[num].iov_base = create_query_id_buf();
if (iov[num].iov_base == NULL) if (iov[num].iov_base == NULL)
return -ENOMEM; return -ENOMEM;
iov[num].iov_len = sizeof(struct crt_query_id_ctxt); iov[num].iov_len = sizeof(struct crt_query_id_ctxt);
le32_add_cpu(&req->CreateContextsLength, sizeof(struct crt_query_id_ctxt));
*num_iovec = num + 1; *num_iovec = num + 1;
return 0; return 0;
} }
...@@ -2889,6 +2872,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, ...@@ -2889,6 +2872,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
req->CreateContextsOffset = cpu_to_le32( req->CreateContextsOffset = cpu_to_le32(
sizeof(struct smb2_create_req) + sizeof(struct smb2_create_req) +
iov[1].iov_len); iov[1].iov_len);
req->CreateContextsLength = 0;
for (unsigned int i = 2; i < (n_iov-1); i++) { for (unsigned int i = 2; i < (n_iov-1); i++) {
struct kvec *v = &iov[i]; struct kvec *v = &iov[i];
...@@ -2897,7 +2881,10 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, ...@@ -2897,7 +2881,10 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,
(struct create_context *)v->iov_base; (struct create_context *)v->iov_base;
cctx->Next = cpu_to_le32(len); cctx->Next = cpu_to_le32(len);
le32_add_cpu(&req->CreateContextsLength, len);
} }
le32_add_cpu(&req->CreateContextsLength,
iov[n_iov-1].iov_len);
} }
rqst->rq_nvec = n_iov; rqst->rq_nvec = n_iov;
......
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