cifs: change smb2_query_info_compound to use a cached fid, if available
authorRonnie Sahlberg <lsahlber@redhat.com>
Tue, 22 Mar 2022 06:29:03 +0000 (16:29 +1000)
committerSteve French <stfrench@microsoft.com>
Wed, 23 Mar 2022 20:20:14 +0000 (15:20 -0500)
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>
fs/cifs/smb2ops.c

index 024adb91dd575a483b800817e763c1da4eb52e8c..629ab45faf7b4e1c359d5caef193b58d9f64d251 100644 (file)
@@ -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 = "";
@@ -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;
@@ -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;
@@ -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) {
@@ -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;
 }