use compounding to speed up readdir()
Subsystems (2)
cover use compounding to speed up readdir()
Steve, List
This three patches are the first step in using compounding to speed up readdir() which currently takes a minimum of 4 roundtrips for any non-empty directory.
With these patches we reduce one roundtrip and we can list a directory in just 3, instead of 4, roundtrips which will benefit use-cases where latency to the server is high.
I.e. this changes the sequence of operations for a small directory from 1, Open
2, Query and get data
3, Query loop until we get STATUS_NO_MORE_FILES
4, Close
To be the slightly better
1, Open + Query and get data
2, Query and get STATUS_NO_MORE_FILES
3, Close
In later patches we can do even better and drive this down to just 2 roundtrips for a small nonempty directory by using
1, Open + Query + Query
2, Close
for the case where we get STATUS_NO_MORE_FILES for the second Query. And bring it down to just two roundtrips.
That is probably the best we can do for Windows based servers since without support for the SMB2_INDEX_SPECIFIED flag in the QueryDirectory request we can not put the Close() as part of the compound.
IF we had SMB2_INDEX_SPECIFIED support on some server (Azure?) and IF we
had a way to reliably detect if the server supports this flag or not then
we could change the sequence to be
Open + Query + Query + Close
and if the second Query returned STATUS_NO_MORE_FILES we would have finished thereaddir() in a single roundtrip. If the directory is large and the second query did not return this error then
we could just continue and use this compound instead to loop until we get to the end :Open() + Query(SMB2_INDEX_SPECIFIED, Index) + Close()
regards
Ronnie Sahlberg
PATCH 1/3 cifs: prepare SMB2_query_directory to be used with compounding
--- fs/cifs/smb2pdu.c | 108 +++++++++++++++++++++++++++++++++++----------------- fs/cifs/smb2pdu.h | 2 + fs/cifs/smb2proto.h | 5 +++ 3 files changed, 80 insertions(+), 35 deletions(-)
fs/cifs/smb2pdu.c +73 -35
@@ -4214,56 +4214,36 @@ num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size)/* * Readdir/FindFirst */ -int -SMB2_query_directory (const unsigned int xid,struct cifs_tcon *tcon, -u64 persistent_fid,u64 volatile_fid,int index, -struct cifs_search_info *srch_inf) +int SMB2_query_directory_init (const unsigned int xid, +struct cifs_tcon *tcon,struct smb_rqst *rqst, +u64 persistent_fid,u64 volatile_fid, +int index,int info_level) { -struct smb_rqst rqst; +struct TCP_Server_Info *server = tcon->ses->server;struct smb2_query_directory_req *req; -struct smb2_query_directory_rsp *rsp =NULL ; -struct kvec iov[2 ]; -struct kvec rsp_iov; -int rc =0 ; -int len; -int resp_buftype =CIFS_NO_BUFFER ;unsigned char *bufptr; -struct TCP_Server_Info *server; -struct cifs_ses *ses = tcon->ses;__le16 asteriks =cpu_to_le16 ('*' ); -char *end_of_smb;unsigned int output_size = CIFSMaxBufSize; -size_t info_buf_size; -int flags =0 ;unsigned int total_len; - -if (ses && (ses->server)) - server = ses->server; -else -return -EIO ; +struct kvec *iov = rqst->rq_iov; +int len, rc; rc =smb2_plain_req_init (SMB2_QUERY_DIRECTORY , tcon, (void **) &req, &total_len);if (rc)return rc; -if (smb3_encryption_required (tcon)) - flags |=CIFS_TRANSFORM_REQ ; - -switch (srch_inf->info_level) { +switch (info_level) {case SMB_FIND_FILE_DIRECTORY_INFO : req->FileInformationClass =FILE_DIRECTORY_INFORMATION ; - info_buf_size =sizeof (FILE_DIRECTORY_INFO ) -1 ;break ;case SMB_FIND_FILE_ID_FULL_DIR_INFO : req->FileInformationClass =FILEID_FULL_DIRECTORY_INFORMATION ; - info_buf_size =sizeof (SEARCH_ID_FULL_DIR_INFO ) -1 ;break ;default :cifs_tcon_dbg (VFS ,"info level %u isn't supported\n" , - srch_inf->info_level); - rc = -EINVAL ; - goto qdir_exit; + info_level); +return -EINVAL ; } req->FileIndex =cpu_to_le32 (index);
@@ -4292,15 +4272,56 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, iov[1 ].iov_base = (char *)(req->Buffer); iov[1 ].iov_len = len; +trace_smb3_query_dir_enter (xid, persistent_fid, tcon->tid, + tcon->ses->Suid, index, output_size); + +return 0 ; +} + +void SMB2_query_directory_free (struct smb_rqst *rqst) +{ +if (rqst && rqst->rq_iov) { +cifs_small_buf_release (rqst->rq_iov[0 ].iov_base);/* request */ + } +} + +int +SMB2_query_directory (const unsigned int xid,struct cifs_tcon *tcon, +u64 persistent_fid,u64 volatile_fid,int index, +struct cifs_search_info *srch_inf) +{ +struct smb_rqst rqst; +struct kvec iov[SMB2_QUERY_DIRECTORY_IOV_SIZE ]; +struct smb2_query_directory_rsp *rsp =NULL ; +int resp_buftype =CIFS_NO_BUFFER ; +struct kvec rsp_iov; +int rc =0 ; +struct TCP_Server_Info *server; +struct cifs_ses *ses = tcon->ses; +char *end_of_smb; +size_t info_buf_size; +int flags =0 ; + +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 (&iov,0 ,sizeof (iov)); rqst.rq_iov = iov; - rqst.rq_nvec =2 ; + rqst.rq_nvec =SMB2_QUERY_DIRECTORY_IOV_SIZE ; -trace_smb3_query_dir_enter (xid, persistent_fid, tcon->tid, - tcon->ses->Suid, index, output_size); + rc =SMB2_query_directory_init (xid, tcon, &rqst, persistent_fid, + volatile_fid, index, + srch_inf->info_level); +if (rc) + goto qdir_exit; rc =cifs_send_recv (xid, ses, &rqst, &resp_buftype, flags, &rsp_iov); -cifs_small_buf_release (req); rsp = (struct smb2_query_directory_rsp *)rsp_iov.iov_base;if (rc) {
@@ -4318,6 +4339,20 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, goto qdir_exit; } +switch (srch_inf->info_level) { +case SMB_FIND_FILE_DIRECTORY_INFO : + info_buf_size =sizeof (FILE_DIRECTORY_INFO ) -1 ; +break ; +case SMB_FIND_FILE_ID_FULL_DIR_INFO : + info_buf_size =sizeof (SEARCH_ID_FULL_DIR_INFO ) -1 ; +break ; +default : +cifs_tcon_dbg (VFS ,"info level %u isn't supported\n" , + srch_inf->info_level); + rc = -EINVAL ; + goto qdir_exit; + } + rc =smb2_validate_iov (le16_to_cpu (rsp->OutputBufferOffset),le32_to_cpu (rsp->OutputBufferLength), &rsp_iov, info_buf_size);
@@ -4353,11 +4388,14 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,else cifs_tcon_dbg (VFS ,"illegal search buffer type\n" ); + rsp =NULL ; + resp_buftype =CIFS_NO_BUFFER ; +trace_smb3_query_dir_done (xid, persistent_fid, tcon->tid, tcon->ses->Suid, index, srch_inf->entries_in_buffer); -return rc; qdir_exit: +SMB2_query_directory_free (&rqst);free_rsp_buf (resp_buftype, rsp);return rc; }
fs/cifs/smb2pdu.h +2 -0
@@ -1272,6 +1272,8 @@ struct smb2_echo_rsp {#define SMB2_INDEX_SPECIFIED 0x04#define SMB2_REOPEN 0x10 +#define SMB2_QUERY_DIRECTORY_IOV_SIZE 2 +struct smb2_query_directory_req {struct smb2_sync_hdr sync_hdr;__le16 StructureSize;/* Must be 33 */
fs/cifs/smb2proto.h +5 -0
@@ -194,6 +194,11 @@ extern int SMB2_echo(struct TCP_Server_Info *server);extern int SMB2_query_directory (const unsigned int xid,struct cifs_tcon *tcon,u64 persistent_fid,u64 volatile_fid,int index,struct cifs_search_info *srch_inf); +extern int SMB2_query_directory_init (unsigned int xid,struct cifs_tcon *tcon, +struct smb_rqst *rqst, +u64 persistent_fid,u64 volatile_fid, +int index,int info_level); +extern void SMB2_query_directory_free (struct smb_rqst *rqst);extern int SMB2_set_eof (const unsigned int xid,struct cifs_tcon *tcon,u64 persistent_fid,u64 volatile_fid,u32 pid,__le64 *eof);
Signature · 1 line
2.13.6
Re: [PATCH 1/3] cifs: prepare SMB2_query_directory to be used with compounding
ср, 4 дек. 2019 г. в 14:54, Ronnie Sahlberg <[email protected]>:
Quoted 30 lines
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2pdu.c | 108 +++++++++++++++++++++++++++++++++++----------------- fs/cifs/smb2pdu.h | 2 + fs/cifs/smb2proto.h | 5 +++ 3 files changed, 80 insertions(+), 35 deletions(-)fs/cifs/smb2pdu.c +5
-7@@ -4214,56 +4214,36 @@ num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size)/* * Readdir/FindFirst */ -int -SMB2_query_directory (const unsigned int xid,struct cifs_tcon *tcon, -u64 persistent_fid,u64 volatile_fid,int index, -struct cifs_search_info *srch_inf) +int SMB2_query_directory_init (const unsigned int xid, +struct cifs_tcon *tcon,struct smb_rqst *rqst, +u64 persistent_fid,u64 volatile_fid, +int index,int info_level) { -struct smb_rqst rqst; +struct TCP_Server_Info *server = tcon->ses->server;struct smb2_query_directory_req *req; -struct smb2_query_directory_rsp *rsp =NULL ; -struct kvec iov[2 ];
fs/cifs/smb2pdu.c num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size) · line 4226
Quoted 10 lines
fs/cifs/smb2pdu.c +0
-7-struct kvec rsp_iov; -int rc =0 ; -int len; -int resp_buftype =CIFS_NO_BUFFER ;unsigned char *bufptr; -struct TCP_Server_Info *server; -struct cifs_ses *ses = tcon->ses;__le16 asteriks =cpu_to_le16 ('*' ); -char *end_of_smb;unsigned int output_size = CIFSMaxBufSize;
I think we need to account for compound responses here. The response buffer size is MAX_SMB2_HDR_SIZE + CIFSMaxBufSize, where MAX_SMB2_HDR_SIZE is 52 transform hdr + 64 hdr + 88 create rsp. While output_size being CIFSMaxBufSize worked for non-compounded query directory responses it may not fit into buffer for compounded ones when encryption is used.
It seem like we need to set it to CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE - MAX_SMB2_CLOSE_RESPONSE_SIZE like to do in smb2_query_eas().
I found other occurrences of the similar issue in smb2_query_symlink() and smb2_ioctl_query_info(): SMB2_ioctl_init() should use CIFSMaxBufSize - MAX_SMB2_CREATE_RESPONSE_SIZE - MAX_SMB2_CLOSE_RESPONSE_SIZE too instead of CIFSMaxBufSize. Could you fix those together with this one?
Quoted 122 lines
fs/cifs/smb2pdu.c +64
-20-size_t info_buf_size; -int flags =0 ;unsigned int total_len; - -if (ses && (ses->server)) - server = ses->server; -else -return -EIO ; +struct kvec *iov = rqst->rq_iov; +int len, rc; rc =smb2_plain_req_init (SMB2_QUERY_DIRECTORY , tcon, (void **) &req, &total_len);if (rc)return rc; -if (smb3_encryption_required (tcon)) - flags |=CIFS_TRANSFORM_REQ ; - -switch (srch_inf->info_level) { +switch (info_level) {case SMB_FIND_FILE_DIRECTORY_INFO : req->FileInformationClass =FILE_DIRECTORY_INFORMATION ; - info_buf_size =sizeof (FILE_DIRECTORY_INFO ) -1 ;break ;case SMB_FIND_FILE_ID_FULL_DIR_INFO : req->FileInformationClass =FILEID_FULL_DIRECTORY_INFORMATION ; - info_buf_size =sizeof (SEARCH_ID_FULL_DIR_INFO ) -1 ;break ;default :cifs_tcon_dbg (VFS ,"info level %u isn't supported\n" , - srch_inf->info_level); - rc = -EINVAL ; - goto qdir_exit; + info_level); +return -EINVAL ; } req->FileIndex =cpu_to_le32 (index);@@ -4292,15 +4272,56 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, iov[1 ].iov_base = (char *)(req->Buffer); iov[1 ].iov_len = len; +trace_smb3_query_dir_enter (xid, persistent_fid, tcon->tid, + tcon->ses->Suid, index, output_size); + +return 0 ; +} + +void SMB2_query_directory_free (struct smb_rqst *rqst) +{ +if (rqst && rqst->rq_iov) { +cifs_small_buf_release (rqst->rq_iov[0 ].iov_base);/* request */ + } +} + +int +SMB2_query_directory (const unsigned int xid,struct cifs_tcon *tcon, +u64 persistent_fid,u64 volatile_fid,int index, +struct cifs_search_info *srch_inf) +{ +struct smb_rqst rqst; +struct kvec iov[SMB2_QUERY_DIRECTORY_IOV_SIZE ]; +struct smb2_query_directory_rsp *rsp =NULL ; +int resp_buftype =CIFS_NO_BUFFER ; +struct kvec rsp_iov; +int rc =0 ; +struct TCP_Server_Info *server; +struct cifs_ses *ses = tcon->ses; +char *end_of_smb; +size_t info_buf_size; +int flags =0 ; + +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 (&iov,0 ,sizeof (iov)); rqst.rq_iov = iov; - rqst.rq_nvec =2 ; + rqst.rq_nvec =SMB2_QUERY_DIRECTORY_IOV_SIZE ; -trace_smb3_query_dir_enter (xid, persistent_fid, tcon->tid, - tcon->ses->Suid, index, output_size); + rc =SMB2_query_directory_init (xid, tcon, &rqst, persistent_fid, + volatile_fid, index, + srch_inf->info_level); +if (rc) + goto qdir_exit; rc =cifs_send_recv (xid, ses, &rqst, &resp_buftype, flags, &rsp_iov); -cifs_small_buf_release (req); rsp = (struct smb2_query_directory_rsp *)rsp_iov.iov_base;if (rc) {@@ -4318,6 +4339,20 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, goto qdir_exit; } +switch (srch_inf->info_level) { +case SMB_FIND_FILE_DIRECTORY_INFO : + info_buf_size =sizeof (FILE_DIRECTORY_INFO ) -1 ; +break ; +case SMB_FIND_FILE_ID_FULL_DIR_INFO : + info_buf_size =sizeof (SEARCH_ID_FULL_DIR_INFO ) -1 ; +break ; +default : +cifs_tcon_dbg (VFS ,"info level %u isn't supported\n" , + srch_inf->info_level); + rc = -EINVAL ; + goto qdir_exit; + } + rc =smb2_validate_iov (le16_to_cpu (rsp->OutputBufferOffset),le32_to_cpu (rsp->OutputBufferLength), &rsp_iov, info_buf_size);
fs/cifs/smb2pdu.c SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, · line 4391
Quoted 4 lines
fs/cifs/smb2pdu.c +1
-0@@ -4353,11 +4388,14 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,else cifs_tcon_dbg (VFS ,"illegal search buffer type\n" ); + rsp =NULL ;
minor: the subsequent patch removes this assignment, probably better to not do it here.
Quoted 41 lines
fs/cifs/smb2pdu.c +3
-1+ resp_buftype =CIFS_NO_BUFFER ; +trace_smb3_query_dir_done (xid, persistent_fid, tcon->tid, tcon->ses->Suid, index, srch_inf->entries_in_buffer); -return rc; qdir_exit: +SMB2_query_directory_free (&rqst);free_rsp_buf (resp_buftype, rsp);return rc; }fs/cifs/smb2pdu.h +2
-0@@ -1272,6 +1272,8 @@ struct smb2_echo_rsp {#define SMB2_INDEX_SPECIFIED 0x04#define SMB2_REOPEN 0x10 +#define SMB2_QUERY_DIRECTORY_IOV_SIZE 2 +struct smb2_query_directory_req {struct smb2_sync_hdr sync_hdr;__le16 StructureSize;/* Must be 33 */ fs/cifs/smb2proto.h +5
-1@@ -194,6 +194,11 @@ extern int SMB2_echo(struct TCP_Server_Info *server);extern int SMB2_query_directory (const unsigned int xid,struct cifs_tcon *tcon,u64 persistent_fid,u64 volatile_fid,int index,struct cifs_search_info *srch_inf); +extern int SMB2_query_directory_init (unsigned int xid,struct cifs_tcon *tcon, +struct smb_rqst *rqst, +u64 persistent_fid,u64 volatile_fid, +int index,int info_level); +extern void SMB2_query_directory_free (struct smb_rqst *rqst);extern int SMB2_set_eof (const unsigned int xid,struct cifs_tcon *tcon,u64 persistent_fid,u64 volatile_fid,u32 pid,__le64 *eof); --
Quoted 2 lines
2.13.6
Other than the note about buffer sizes above the series looks good at the first glance.
--
Best regards,
Pavel Shilovsky
ronnie sahlberg
reviewerRe: [PATCH 1/3] cifs: prepare SMB2_query_directory to be used with compounding
Thanks,
I have resent it after addressing your concerns.
I added an extra patch to fix the two places calling smb2_ioctl_init() that were unrelated to opendir/readdir
regards
ronnie sahlberg
Quoted 241 lines · Pavel Shilovsky
ср, 4 дек. 2019 г. в 14:54, Ronnie Sahlberg <[email protected]>:
Quoted 30 lines
Signed-off-by Ronnie Sahlberg <[email protected]>--- fs/cifs/smb2pdu.c | 108 +++++++++++++++++++++++++++++++++++----------------- fs/cifs/smb2pdu.h | 2 + fs/cifs/smb2proto.h | 5 +++ 3 files changed, 80 insertions(+), 35 deletions(-)fs/cifs/smb2pdu.c +5
-7@@ -4214,56 +4214,36 @@ num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size)/* * Readdir/FindFirst */ -int -SMB2_query_directory (const unsigned int xid,struct cifs_tcon *tcon, -u64 persistent_fid,u64 volatile_fid,int index, -struct cifs_search_info *srch_inf) +int SMB2_query_directory_init (const unsigned int xid, +struct cifs_tcon *tcon,struct smb_rqst *rqst, +u64 persistent_fid,u64 volatile_fid, +int index,int info_level) { -struct smb_rqst rqst; +struct TCP_Server_Info *server = tcon->ses->server;struct smb2_query_directory_req *req; -struct smb2_query_directory_rsp *rsp =NULL ; -struct kvec iov[2 ];fs/cifs/smb2pdu.c num_entries(char *bufstart, char *end_of_buf, char **lastentry, size_t size) · line 4226
Quoted 10 lines
fs/cifs/smb2pdu.c +0
-7-struct kvec rsp_iov; -int rc =0 ; -int len; -int resp_buftype =CIFS_NO_BUFFER ;unsigned char *bufptr; -struct TCP_Server_Info *server; -struct cifs_ses *ses = tcon->ses;__le16 asteriks =cpu_to_le16 ('*' ); -char *end_of_smb;unsigned int output_size = CIFSMaxBufSize;I think we need to account for compound responses here. The response buffer size is
MAX_SMB2_HDR_SIZE+ CIFSMaxBufSize, whereMAX_SMB2_HDR_SIZEis 52 transform hdr + 64 hdr + 88 create rsp. Whileoutput_sizebeing CIFSMaxBufSize worked for non-compounded query directory responses it may not fit into buffer for compounded ones when encryption is used.It seem like we need to set it to CIFSMaxBufSize -
MAX_SMB2_CREATE_RESPONSE_SIZE-MAX_SMB2_CLOSE_RESPONSE_SIZElike to do insmb2_query_eas().I found other occurrences of the similar issue in
smb2_query_symlink()andsmb2_ioctl_query_info():SMB2_ioctl_init()should use CIFSMaxBufSize -MAX_SMB2_CREATE_RESPONSE_SIZE-MAX_SMB2_CLOSE_RESPONSE_SIZEtoo instead of CIFSMaxBufSize. Could you fix those together with this one?Quoted 122 lines
fs/cifs/smb2pdu.c +64
-20-size_t info_buf_size; -int flags =0 ;unsigned int total_len; - -if (ses && (ses->server)) - server = ses->server; -else -return -EIO ; +struct kvec *iov = rqst->rq_iov; +int len, rc; rc =smb2_plain_req_init (SMB2_QUERY_DIRECTORY , tcon, (void **) &req, &total_len);if (rc)return rc; -if (smb3_encryption_required (tcon)) - flags |=CIFS_TRANSFORM_REQ ; - -switch (srch_inf->info_level) { +switch (info_level) {case SMB_FIND_FILE_DIRECTORY_INFO : req->FileInformationClass =FILE_DIRECTORY_INFORMATION ; - info_buf_size =sizeof (FILE_DIRECTORY_INFO ) -1 ;break ;case SMB_FIND_FILE_ID_FULL_DIR_INFO : req->FileInformationClass =FILEID_FULL_DIRECTORY_INFORMATION ; - info_buf_size =sizeof (SEARCH_ID_FULL_DIR_INFO ) -1 ;break ;default :cifs_tcon_dbg (VFS ,"info level %u isn't supported\n" , - srch_inf->info_level); - rc = -EINVAL ; - goto qdir_exit; + info_level); +return -EINVAL ; } req->FileIndex =cpu_to_le32 (index);@@ -4292,15 +4272,56 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, iov[1 ].iov_base = (char *)(req->Buffer); iov[1 ].iov_len = len; +trace_smb3_query_dir_enter (xid, persistent_fid, tcon->tid, + tcon->ses->Suid, index, output_size); + +return 0 ; +} + +void SMB2_query_directory_free (struct smb_rqst *rqst) +{ +if (rqst && rqst->rq_iov) { +cifs_small_buf_release (rqst->rq_iov[0 ].iov_base);/* request */ + } +} + +int +SMB2_query_directory (const unsigned int xid,struct cifs_tcon *tcon, +u64 persistent_fid,u64 volatile_fid,int index, +struct cifs_search_info *srch_inf) +{ +struct smb_rqst rqst; +struct kvec iov[SMB2_QUERY_DIRECTORY_IOV_SIZE ]; +struct smb2_query_directory_rsp *rsp =NULL ; +int resp_buftype =CIFS_NO_BUFFER ; +struct kvec rsp_iov; +int rc =0 ; +struct TCP_Server_Info *server; +struct cifs_ses *ses = tcon->ses; +char *end_of_smb; +size_t info_buf_size; +int flags =0 ; + +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 (&iov,0 ,sizeof (iov)); rqst.rq_iov = iov; - rqst.rq_nvec =2 ; + rqst.rq_nvec =SMB2_QUERY_DIRECTORY_IOV_SIZE ; -trace_smb3_query_dir_enter (xid, persistent_fid, tcon->tid, - tcon->ses->Suid, index, output_size); + rc =SMB2_query_directory_init (xid, tcon, &rqst, persistent_fid, + volatile_fid, index, + srch_inf->info_level); +if (rc) + goto qdir_exit; rc =cifs_send_recv (xid, ses, &rqst, &resp_buftype, flags, &rsp_iov); -cifs_small_buf_release (req); rsp = (struct smb2_query_directory_rsp *)rsp_iov.iov_base;if (rc) {@@ -4318,6 +4339,20 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, goto qdir_exit; } +switch (srch_inf->info_level) { +case SMB_FIND_FILE_DIRECTORY_INFO : + info_buf_size =sizeof (FILE_DIRECTORY_INFO ) -1 ; +break ; +case SMB_FIND_FILE_ID_FULL_DIR_INFO : + info_buf_size =sizeof (SEARCH_ID_FULL_DIR_INFO ) -1 ; +break ; +default : +cifs_tcon_dbg (VFS ,"info level %u isn't supported\n" , + srch_inf->info_level); + rc = -EINVAL ; + goto qdir_exit; + } + rc =smb2_validate_iov (le16_to_cpu (rsp->OutputBufferOffset),le32_to_cpu (rsp->OutputBufferLength), &rsp_iov, info_buf_size);fs/cifs/smb2pdu.c SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, · line 4391
Quoted 4 lines
fs/cifs/smb2pdu.c +1
-0@@ -4353,11 +4388,14 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,else cifs_tcon_dbg (VFS ,"illegal search buffer type\n" ); + rsp =NULL ;minor: the subsequent patch removes this assignment, probably better to not do it here.
Quoted 41 lines
fs/cifs/smb2pdu.c +3
-1+ resp_buftype =CIFS_NO_BUFFER ; +trace_smb3_query_dir_done (xid, persistent_fid, tcon->tid, tcon->ses->Suid, index, srch_inf->entries_in_buffer); -return rc; qdir_exit: +SMB2_query_directory_free (&rqst);free_rsp_buf (resp_buftype, rsp);return rc; }fs/cifs/smb2pdu.h +2
-0@@ -1272,6 +1272,8 @@ struct smb2_echo_rsp {#define SMB2_INDEX_SPECIFIED 0x04#define SMB2_REOPEN 0x10 +#define SMB2_QUERY_DIRECTORY_IOV_SIZE 2 +struct smb2_query_directory_req {struct smb2_sync_hdr sync_hdr;__le16 StructureSize;/* Must be 33 */ fs/cifs/smb2proto.h +5
-1@@ -194,6 +194,11 @@ extern int SMB2_echo(struct TCP_Server_Info *server);extern int SMB2_query_directory (const unsigned int xid,struct cifs_tcon *tcon,u64 persistent_fid,u64 volatile_fid,int index,struct cifs_search_info *srch_inf); +extern int SMB2_query_directory_init (unsigned int xid,struct cifs_tcon *tcon, +struct smb_rqst *rqst, +u64 persistent_fid,u64 volatile_fid, +int index,int info_level); +extern void SMB2_query_directory_free (struct smb_rqst *rqst);extern int SMB2_set_eof (const unsigned int xid,struct cifs_tcon *tcon,u64 persistent_fid,u64 volatile_fid,u32 pid,__le64 *eof); --Quoted 2 lines
2.13.6
Other than the note about buffer sizes above the series looks good at the first glance.
--
Best regards,
Pavel Shilovsky
PATCH 2/3 cifs: create a helper function to parse the query-directory response buffer
In reply to Ronnie Sahlberg--- fs/cifs/smb2pdu.c | 110 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 63 insertions(+), 47 deletions(-)
fs/cifs/smb2pdu.c +63 -47
@@ -4286,6 +4286,67 @@ void SMB2_query_directory_free(struct smb_rqst *rqst) }int +smb2_parse_query_directory (struct cifs_tcon *tcon, +struct kvec *rsp_iov, +int resp_buftype, +struct cifs_search_info *srch_inf) +{ +struct smb2_query_directory_rsp *rsp; +size_t info_buf_size; +char *end_of_smb; +int rc; + + rsp = (struct smb2_query_directory_rsp *)rsp_iov->iov_base; + +switch (srch_inf->info_level) { +case SMB_FIND_FILE_DIRECTORY_INFO : + info_buf_size =sizeof (FILE_DIRECTORY_INFO ) -1 ; +break ; +case SMB_FIND_FILE_ID_FULL_DIR_INFO : + info_buf_size =sizeof (SEARCH_ID_FULL_DIR_INFO ) -1 ; +break ; +default : +cifs_tcon_dbg (VFS ,"info level %u isn't supported\n" , + srch_inf->info_level); +return -EINVAL ; + } + + rc =smb2_validate_iov (le16_to_cpu (rsp->OutputBufferOffset), +le32_to_cpu (rsp->OutputBufferLength), rsp_iov, + info_buf_size); +if (rc) +return rc; + + srch_inf->unicode = true; + +if (srch_inf->ntwrk_buf_start) { +if (srch_inf->smallBuf) +cifs_small_buf_release (srch_inf->ntwrk_buf_start); +else +cifs_buf_release (srch_inf->ntwrk_buf_start); + } + srch_inf->ntwrk_buf_start = (char *)rsp; + srch_inf->srch_entries_start = srch_inf->last_entry = + (char *)rsp +le16_to_cpu (rsp->OutputBufferOffset); + end_of_smb = rsp_iov->iov_len + (char *)rsp; + srch_inf->entries_in_buffer = +num_entries (srch_inf->srch_entries_start, end_of_smb, + &srch_inf->last_entry, info_buf_size); + srch_inf->index_of_last_entry += srch_inf->entries_in_buffer; +cifs_dbg (FYI ,"num entries %d last_index %lld srch start %p srch end %p\n" , + srch_inf->entries_in_buffer, srch_inf->index_of_last_entry, + srch_inf->srch_entries_start, srch_inf->last_entry); +if (resp_buftype ==CIFS_LARGE_BUFFER ) + srch_inf->smallBuf = false; +else if (resp_buftype ==CIFS_SMALL_BUFFER ) + srch_inf->smallBuf = true; +else +cifs_tcon_dbg (VFS ,"illegal search buffer type\n" ); + +return 0 ; +} + +int SMB2_query_directory (const unsigned int xid,struct cifs_tcon *tcon,u64 persistent_fid,u64 volatile_fid,int index,struct cifs_search_info *srch_inf)
@@ -4298,8 +4359,6 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,int rc =0 ;struct TCP_Server_Info *server;struct cifs_ses *ses = tcon->ses; -char *end_of_smb; -size_t info_buf_size;int flags =0 ;if (ses && (ses->server))
@@ -4339,56 +4398,13 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon, goto qdir_exit; } -switch (srch_inf->info_level) { -case SMB_FIND_FILE_DIRECTORY_INFO : - info_buf_size =sizeof (FILE_DIRECTORY_INFO ) -1 ; -break ; -case SMB_FIND_FILE_ID_FULL_DIR_INFO : - info_buf_size =sizeof (SEARCH_ID_FULL_DIR_INFO ) -1 ; -break ; -default : -cifs_tcon_dbg (VFS ,"info level %u isn't supported\n" , - srch_inf->info_level); - rc = -EINVAL ; - goto qdir_exit; - } - - rc =smb2_validate_iov (le16_to_cpu (rsp->OutputBufferOffset), -le32_to_cpu (rsp->OutputBufferLength), &rsp_iov, - info_buf_size); + rc =smb2_parse_query_directory (tcon, &rsp_iov, resp_buftype, + srch_inf);if (rc) {trace_smb3_query_dir_err (xid, persistent_fid, tcon->tid, tcon->ses->Suid, index,0 , rc); goto qdir_exit; } - - srch_inf->unicode = true; - -if (srch_inf->ntwrk_buf_start) { -if (srch_inf->smallBuf) -cifs_small_buf_release (srch_inf->ntwrk_buf_start); -else -cifs_buf_release (srch_inf->ntwrk_buf_start); - } - srch_inf->ntwrk_buf_start = (char *)rsp; - srch_inf->srch_entries_start = srch_inf->last_entry = - (char *)rsp +le16_to_cpu (rsp->OutputBufferOffset); - end_of_smb = rsp_iov.iov_len + (char *)rsp; - srch_inf->entries_in_buffer = -num_entries (srch_inf->srch_entries_start, end_of_smb, - &srch_inf->last_entry, info_buf_size); - srch_inf->index_of_last_entry += srch_inf->entries_in_buffer; -cifs_dbg (FYI ,"num entries %d last_index %lld srch start %p srch end %p\n" , - srch_inf->entries_in_buffer, srch_inf->index_of_last_entry, - srch_inf->srch_entries_start, srch_inf->last_entry); -if (resp_buftype ==CIFS_LARGE_BUFFER ) - srch_inf->smallBuf = false; -else if (resp_buftype ==CIFS_SMALL_BUFFER ) - srch_inf->smallBuf = true; -else -cifs_tcon_dbg (VFS ,"illegal search buffer type\n" ); - - rsp =NULL ; resp_buftype =CIFS_NO_BUFFER ; trace_smb3_query_dir_done(xid, persistent_fid, tcon->tid,
Signature · 1 line
2.13.6
PATCH 3/3 cifs: use compounding for open and first query-dir for readdir()
In reply to Ronnie SahlbergCombine the initial SMB2_Open and the first SMB2_Query_Directory in a compound. This shaves one round-trip of each directory listing, changing it from 4 to 3 for small directories.
--- fs/cifs/cifsproto.h | 3 ++ fs/cifs/smb2ops.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 87 insertions(+), 12 deletions(-)
fs/cifs/cifsproto.h +3 -0
@@ -595,6 +595,9 @@ bool is_ses_using_iface(struct cifs_ses *ses, struct cifs_server_iface *iface);void extract_unc_hostname (const char *unc,const char **h,size_t *len);int copy_path_name (char *dst,const char *src); +int smb2_parse_query_directory (struct cifs_tcon *tcon,struct kvec *rsp_iov, +int resp_buftype, +struct cifs_search_info *srch_inf);#ifdef CONFIG_CIFS_DFS_UPCALL static inline int get_dfs_path(const unsigned int xid, struct cifs_ses *ses,
fs/cifs/smb2ops.c +84 -12
120 lines not on this page · raw message
Signature · 1 line
2.13.6