Simplify SMB2_open_init
Subsystems (2)
cover Simplify SMB2_open_init
Stitching together can be done in one place, there's no need to do this in every add_*_context function.
This supersedes the patchet in
https://www.spinics.net/lists/linux-cifs/msg28087.html.
Volker Lendecke (3):
cifs: Simplify SMB2_open_init()
cifs: Simplify SMB2_open_init()
cifs: Simplify SMB2_open_init()
fs/cifs/smb2pdu.c | 106 +++++++++++----------------------------------- 1 file changed, 25 insertions(+), 81 deletions(-)
Signature · 1 line
2.30.2
PATCH 1/3 cifs: Simplify SMB2_open_init()
We can point to the create contexts in just one place, we don't have to do this in every add_*_context routine.
--- fs/cifs/smb2pdu.c | 45 +++++++++++++-------------------------------- 1 file changed, 13 insertions(+), 32 deletions(-)
fs/cifs/smb2pdu.c +13 -32
@@ -810,10 +810,6 @@ add_posix_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode)if (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len =sizeof (struct create_posix ); -if (!req->CreateContextsOffset) - req->CreateContextsOffset =cpu_to_le32 ( -sizeof (struct smb2_create_req ) + - iov[num -1 ].iov_len);le32_add_cpu (&req->CreateContextsLength,sizeof (struct create_posix )); *num_iovec = num +1 ;return 0 ;
@@ -2163,10 +2159,6 @@ add_lease_context(struct TCP_Server_Info *server, struct kvec *iov,return -ENOMEM ; iov[num].iov_len = server->vals->create_lease_size; req->RequestedOplockLevel =SMB2_OPLOCK_LEVEL_LEASE ; -if (!req->CreateContextsOffset) - req->CreateContextsOffset =cpu_to_le32 ( -sizeof (struct smb2_create_req ) + - iov[num -1 ].iov_len);le32_add_cpu (&req->CreateContextsLength, server->vals->create_lease_size); *num_iovec = num +1 ;
@@ -2254,10 +2246,6 @@ add_durable_v2_context(struct kvec *iov, unsigned int *num_iovec,if (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len =sizeof (struct create_durable_v2 ); -if (!req->CreateContextsOffset) - req->CreateContextsOffset = -cpu_to_le32 (sizeof (struct smb2_create_req ) + - iov[1 ].iov_len);le32_add_cpu (&req->CreateContextsLength,sizeof (struct create_durable_v2 )); *num_iovec = num +1 ;return 0 ;
@@ -2277,10 +2265,6 @@ add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec,if (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len =sizeof (struct create_durable_handle_reconnect_v2 ); -if (!req->CreateContextsOffset) - req->CreateContextsOffset = -cpu_to_le32 (sizeof (struct smb2_create_req ) + - iov[1 ].iov_len);le32_add_cpu (&req->CreateContextsLength,sizeof (struct create_durable_handle_reconnect_v2 )); *num_iovec = num +1 ;
@@ -2311,10 +2295,6 @@ add_durable_context(struct kvec *iov, unsigned int *num_iovec,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 ) + - iov[1 ].iov_len);le32_add_cpu (&req->CreateContextsLength,sizeof (struct create_durable )); *num_iovec = num +1 ;return 0 ;
@@ -2356,10 +2336,6 @@ add_twarp_context(struct kvec *iov, unsigned int *num_iovec, __u64 timewarp)if (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len =sizeof (struct crt_twarp_ctxt ); -if (!req->CreateContextsOffset) - req->CreateContextsOffset =cpu_to_le32 ( -sizeof (struct smb2_create_req ) + - iov[num -1 ].iov_len);le32_add_cpu (&req->CreateContextsLength,sizeof (struct crt_twarp_ctxt )); *num_iovec = num +1 ;return 0 ;
@@ -2491,10 +2467,6 @@ add_sd_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode, bool setif (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len = len; -if (!req->CreateContextsOffset) - req->CreateContextsOffset =cpu_to_le32 ( -sizeof (struct smb2_create_req ) + - iov[num -1 ].iov_len);le32_add_cpu (&req->CreateContextsLength, len); *num_iovec = num +1 ;return 0 ;
@@ -2533,10 +2505,6 @@ add_query_id_context(struct kvec *iov, unsigned int *num_iovec)if (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len =sizeof (struct crt_query_id_ctxt ); -if (!req->CreateContextsOffset) - req->CreateContextsOffset =cpu_to_le32 ( -sizeof (struct smb2_create_req ) + - iov[num -1 ].iov_len);le32_add_cpu (&req->CreateContextsLength,sizeof (struct crt_query_id_ctxt )); *num_iovec = num +1 ;return 0 ;
@@ -2700,6 +2668,9 @@ int smb311_posix_mkdir(const unsigned int xid, struct inode *inode, rc =add_posix_context (iov, &n_iov, mode);if (rc) goto err_free_req; + req->CreateContextsOffset =cpu_to_le32 ( +sizeof (struct smb2_create_req ) + + iov[1 ].iov_len); pc_buf = iov[n_iov-1 ].iov_base; }
@@ -2923,6 +2894,16 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, }add_query_id_context (iov, &n_iov); +if (n_iov >2 ) { +/* +* We have create contexts behind iov[1] (the file +* name), point at them from the main create request +*/ + req->CreateContextsOffset =cpu_to_le32 ( +sizeof (struct smb2_create_req ) + + iov[1 ].iov_len); + } + rqst->rq_nvec = n_iov;return 0 ; }
Signature · 1 line
2.30.2
PATCH 2/3 cifs: Simplify SMB2_open_init()
In reply to Volker LendeckeReduce code duplication by stitching together create contexts in one place.
--- fs/cifs/smb2pdu.c | 42 +++++++++--------------------------------- 1 file changed, 9 insertions(+), 33 deletions(-)
fs/cifs/smb2pdu.c +9 -33
@@ -2815,14 +2815,6 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, }if (*oplock ==SMB2_OPLOCK_LEVEL_BATCH ) { -/* need to set Next field of lease context if we request it */ -if (server->capabilities &SMB2_GLOBAL_CAP_LEASING ) { -struct create_context *ccontext = - (struct create_context *)iov[n_iov-1 ].iov_base; - ccontext->Next = -cpu_to_le32 (server->vals->create_lease_size); - } - rc =add_durable_context (iov, &n_iov, oparms, tcon->use_persistent);if (rc)
@@ -2830,13 +2822,6 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, }if (tcon->posix_extensions) { -if (n_iov >2 ) { -struct create_context *ccontext = - (struct create_context *)iov[n_iov-1 ].iov_base; - ccontext->Next = -cpu_to_le32 (iov[n_iov-1 ].iov_len); - } - rc =add_posix_context (iov, &n_iov, oparms->mode);if (rc)return rc;
@@ -2844,13 +2829,6 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server,if (tcon->snapshot_time) {cifs_dbg (FYI ,"adding snapshot context\n" ); -if (n_iov >2 ) { -struct create_context *ccontext = - (struct create_context *)iov[n_iov-1 ].iov_base; - ccontext->Next = -cpu_to_le32 (iov[n_iov-1 ].iov_len); - } - rc =add_twarp_context (iov, &n_iov, tcon->snapshot_time);if (rc)return rc;
@@ -2874,12 +2852,6 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, set_owner = false;if (set_owner | set_mode) { -if (n_iov >2 ) { -struct create_context *ccontext = - (struct create_context *)iov[n_iov-1 ].iov_base; - ccontext->Next =cpu_to_le32 (iov[n_iov-1 ].iov_len); - } -cifs_dbg (FYI ,"add sd with mode 0x%x\n" , oparms->mode); rc =add_sd_context (iov, &n_iov, oparms->mode, set_owner);if (rc)
@@ -2887,11 +2859,6 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, } } -if (n_iov >2 ) { -struct create_context *ccontext = - (struct create_context *)iov[n_iov-1 ].iov_base; - ccontext->Next =cpu_to_le32 (iov[n_iov-1 ].iov_len); - }add_query_id_context (iov, &n_iov);if (n_iov >2 ) {
@@ -2902,6 +2869,15 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, req->CreateContextsOffset =cpu_to_le32 (sizeof (struct smb2_create_req ) + iov[1 ].iov_len); + +for (unsigned int i =2 ; i < (n_iov-1 ); i++) { +struct kvec *v = &iov[i]; +size_t len = v->iov_len; +struct create_context *cctx = + (struct create_context *)v->iov_base; + + cctx->Next =cpu_to_le32 (len); + } } rqst->rq_nvec = n_iov;
Signature · 1 line
2.30.2
PATCH 3/3 cifs: Simplify SMB2_open_init()
In reply to Volker LendeckeReduce code duplication by calculating req->CreateContextsLength in one place.
This is the last reference to "req" in the add_*_context functions, remove that parameter.
--- fs/cifs/smb2pdu.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-)
fs/cifs/smb2pdu.c +4 -17
@@ -801,7 +801,6 @@ create_posix_buf(umode_t mode)static int 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; iov[num].iov_base =create_posix_buf (mode);
@@ -810,7 +809,6 @@ add_posix_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode)if (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len =sizeof (struct create_posix ); -le32_add_cpu (&req->CreateContextsLength,sizeof (struct create_posix )); *num_iovec = num +1 ;return 0 ; }
@@ -2159,8 +2157,6 @@ add_lease_context(struct TCP_Server_Info *server, struct kvec *iov,return -ENOMEM ; iov[num].iov_len = server->vals->create_lease_size; req->RequestedOplockLevel =SMB2_OPLOCK_LEVEL_LEASE ; -le32_add_cpu (&req->CreateContextsLength, - server->vals->create_lease_size); *num_iovec = num +1 ;return 0 ; }
@@ -2239,14 +2235,12 @@ static int add_durable_v2_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; iov[num].iov_base =create_durable_v2_buf (oparms);if (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len =sizeof (struct create_durable_v2 ); -le32_add_cpu (&req->CreateContextsLength,sizeof (struct create_durable_v2 )); *num_iovec = num +1 ;return 0 ; }
@@ -2255,7 +2249,6 @@ static int add_durable_reconnect_v2_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;/* indicate that we don't need to relock the file */
@@ -2265,8 +2258,6 @@ add_durable_reconnect_v2_context(struct kvec *iov, unsigned int *num_iovec,if (iov[num].iov_base ==NULL )return -ENOMEM ; 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 ;return 0 ; }
@@ -2275,7 +2266,6 @@ static int add_durable_context(struct kvec *iov, unsigned int *num_iovec, struct cifs_open_parms *oparms, bool use_persistent) { - struct smb2_create_req *req = iov[0].iov_base; unsigned int num = *num_iovec;if (use_persistent) {
@@ -2295,7 +2285,6 @@ add_durable_context(struct kvec *iov, unsigned int *num_iovec,if (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len =sizeof (struct create_durable ); -le32_add_cpu (&req->CreateContextsLength,sizeof (struct create_durable )); *num_iovec = num +1 ;return 0 ; }
@@ -2329,14 +2318,12 @@ create_twarp_buf(__u64 timewarp)static int 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; iov[num].iov_base =create_twarp_buf (timewarp);if (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len =sizeof (struct crt_twarp_ctxt ); -le32_add_cpu (&req->CreateContextsLength,sizeof (struct crt_twarp_ctxt )); *num_iovec = num +1 ;return 0 ; }
@@ -2459,7 +2446,6 @@ create_sd_buf(umode_t mode, bool set_owner, unsigned int *len)static int 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 len =0 ;
@@ -2467,7 +2453,6 @@ add_sd_context(struct kvec *iov, unsigned int *num_iovec, umode_t mode, bool setif (iov[num].iov_base ==NULL )return -ENOMEM ; iov[num].iov_len = len; -le32_add_cpu (&req->CreateContextsLength, len); *num_iovec = num +1 ;return 0 ; }
@@ -2498,14 +2483,12 @@ create_query_id_buf(void)static int 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; iov[num].iov_base =create_query_id_buf ();if (iov[num].iov_base ==NULL )return -ENOMEM ; 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 ;return 0 ; }
@@ -2869,6 +2852,7 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, req->CreateContextsOffset =cpu_to_le32 (sizeof (struct smb2_create_req ) + iov[1 ].iov_len); + req->CreateContextsLength =0 ;for (unsigned int i =2 ; i < (n_iov-1 ); i++) {struct kvec *v = &iov[i];
@@ -2877,7 +2861,10 @@ SMB2_open_init(struct cifs_tcon *tcon, struct TCP_Server_Info *server, (struct create_context *)v->iov_base; 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;
Signature · 1 line
2.30.2
Hi Volker,
Quoted 7 lines · Volker Lendecke
Stitching together can be done in one place, there's no need to do this in every add_*_context function.
This supersedes the patchet in
Quoted 7 lines
Volker Lendecke (3):
cifs: SimplifySMB2_open_init()
cifs: SimplifySMB2_open_init()
cifs: SimplifySMB2_open_init()
fs/cifs/smb2pdu.c| 106 +++++++++++-----------------------------------1 file changed, 25 insertions(+), 81 deletions(-)
Would you mind using more descriptive titles please? To make referencing/backporting easier.
Also IMHO patches 1/3 and 3/3 could be merged into a single patch.
Aside from that, Reviewed-by: Enzo Matsumiya <[email protected]>
Cheers,
Enzo
My main worry is that these are done in the way that makes it easier for Ronnie/Enzo/Paulo etc. to backport - since we have plenty of bugs/features to work on that they will be wanting to backport over the next few releases - and don't want to make their life too much harder - but these changes look reasonably small
Quoted 30 lines · Enzo Matsumiya
Hi Volker,
Quoted 7 lines · Volker Lendecke
Stitching together can be done in one place, there's no need to do this in every add_*_context function.
This supersedes the patchet in
Quoted 7 lines
Volker Lendecke (3):
cifs: SimplifySMB2_open_init()
cifs: SimplifySMB2_open_init()
cifs: SimplifySMB2_open_init()
fs/cifs/smb2pdu.c| 106 +++++++++++-----------------------------------1 file changed, 25 insertions(+), 81 deletions(-)Would you mind using more descriptive titles please? To make referencing/backporting easier.
Also IMHO patches 1/3 and 3/3 could be merged into a single patch.
Aside from that, Reviewed-by: Enzo Matsumiya <[email protected]>
Cheers,
Enzo
Signature · 3 lines
Thanks, Steve
Let me know if any updated patches (with merge window approaching soon)
Quoted 19 lines · Volker Lendecke
Stitching together can be done in one place, there's no need to do this in every add_*_context function.
This supersedes the patchet in
https://www.spinics.net/lists/linux-cifs/msg28087.html.
Volker Lendecke (3):
cifs: SimplifySMB2_open_init()
cifs: SimplifySMB2_open_init()
cifs: SimplifySMB2_open_init()fs/cifs/smb2pdu.c | 106 +++++++++++----------------------------------- 1 file changed, 25 insertions(+), 81 deletions(-)--
2.30.2
Signature · 3 lines
Thanks, Steve