Skip to content

Commit

Permalink
cifs: change smb2_query_info_compound to use a cached fid, if available
Browse files Browse the repository at this point in the history
This will reduce the number of Open/Close we send on the wire and replace
a Open/GetInfo/Close compound with just a simple GetInfo request
IF we have a cached handle for the object.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Ronnie Sahlberg authored and Steve French committed Mar 23, 2022
1 parent 5e0c969 commit 8708b10
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions fs/cifs/smb2ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,7 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
struct cifs_fid fid;
int rc;
__le16 *utf16_path;
struct cached_fid *cfid = NULL;

if (!path)
path = "";
Expand All @@ -2673,6 +2674,8 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
memset(rsp_iov, 0, sizeof(rsp_iov));

rc = open_cached_dir(xid, tcon, path, cifs_sb, &cfid);

memset(&open_iov, 0, sizeof(open_iov));
rqst[0].rq_iov = open_iov;
rqst[0].rq_nvec = SMB2_CREATE_IOV_SIZE;
Expand All @@ -2694,15 +2697,29 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
rqst[1].rq_iov = qi_iov;
rqst[1].rq_nvec = 1;

rc = SMB2_query_info_init(tcon, server,
&rqst[1], COMPOUND_FID, COMPOUND_FID,
class, type, 0,
output_len, 0,
NULL);
if (cfid) {
rc = SMB2_query_info_init(tcon, server,
&rqst[1],
cfid->fid->persistent_fid,
cfid->fid->volatile_fid,
class, type, 0,
output_len, 0,
NULL);
} else {
rc = SMB2_query_info_init(tcon, server,
&rqst[1],
COMPOUND_FID,
COMPOUND_FID,
class, type, 0,
output_len, 0,
NULL);
}
if (rc)
goto qic_exit;
smb2_set_next_command(tcon, &rqst[1]);
smb2_set_related(&rqst[1]);
if (!cfid) {
smb2_set_next_command(tcon, &rqst[1]);
smb2_set_related(&rqst[1]);
}

memset(&close_iov, 0, sizeof(close_iov));
rqst[2].rq_iov = close_iov;
Expand All @@ -2714,9 +2731,15 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
goto qic_exit;
smb2_set_related(&rqst[2]);

rc = compound_send_recv(xid, ses, server,
flags, 3, rqst,
resp_buftype, rsp_iov);
if (cfid) {
rc = compound_send_recv(xid, ses, server,
flags, 1, &rqst[1],
&resp_buftype[1], &rsp_iov[1]);
} else {
rc = compound_send_recv(xid, ses, server,
flags, 3, rqst,
resp_buftype, rsp_iov);
}
if (rc) {
free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
if (rc == -EREMCHG) {
Expand All @@ -2736,6 +2759,8 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
SMB2_close_free(&rqst[2]);
free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
free_rsp_buf(resp_buftype[2], rsp_iov[2].iov_base);
if (cfid)
close_cached_dir(cfid);
return rc;
}

Expand Down

0 comments on commit 8708b10

Please sign in to comment.