cifs: compute full_path already in cifs_readdir()
authorRonnie Sahlberg <lsahlber@redhat.com>
Mon, 5 Oct 2020 02:37:53 +0000 (12:37 +1000)
committerSteve French <stfrench@microsoft.com>
Mon, 12 Oct 2020 04:57:19 +0000 (23:57 -0500)
Cleanup patch for followon to cache additional information for the root directory
when directory lease held.

Signed-off-by: Ronnie Sahlberg <lsahlber@redhat.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/readdir.c

index 6df0922..31a18aa 100644 (file)
@@ -360,11 +360,11 @@ int get_symlink_reparse_path(char *full_path, struct cifs_sb_info *cifs_sb,
  */
 
 static int
-initiate_cifs_search(const unsigned int xid, struct file *file)
+initiate_cifs_search(const unsigned int xid, struct file *file,
+                    char *full_path)
 {
        __u16 search_flags;
        int rc = 0;
-       char *full_path = NULL;
        struct cifsFileInfo *cifsFile;
        struct cifs_sb_info *cifs_sb = CIFS_FILE_SB(file);
        struct tcon_link *tlink = NULL;
@@ -400,12 +400,6 @@ initiate_cifs_search(const unsigned int xid, struct file *file)
        cifsFile->invalidHandle = true;
        cifsFile->srch_inf.endOfSearch = false;
 
-       full_path = build_path_from_dentry(file_dentry(file));
-       if (full_path == NULL) {
-               rc = -ENOMEM;
-               goto error_exit;
-       }
-
        cifs_dbg(FYI, "Full path: %s start at: %lld\n", full_path, file->f_pos);
 
 ffirst_retry:
@@ -444,7 +438,6 @@ ffirst_retry:
                goto ffirst_retry;
        }
 error_exit:
-       kfree(full_path);
        cifs_put_tlink(tlink);
        return rc;
 }
@@ -688,7 +681,8 @@ static int cifs_save_resume_key(const char *current_entry,
  */
 static int
 find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos,
-               struct file *file, char **current_entry, int *num_to_ret)
+               struct file *file, char *full_path,
+               char **current_entry, int *num_to_ret)
 {
        __u16 search_flags;
        int rc = 0;
@@ -741,7 +735,7 @@ find_cifs_entry(const unsigned int xid, struct cifs_tcon *tcon, loff_t pos,
                                                ntwrk_buf_start);
                        cfile->srch_inf.ntwrk_buf_start = NULL;
                }
-               rc = initiate_cifs_search(xid, file);
+               rc = initiate_cifs_search(xid, file, full_path);
                if (rc) {
                        cifs_dbg(FYI, "error %d reinitiating a search on rewind\n",
                                 rc);
@@ -925,15 +919,22 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
        char *tmp_buf = NULL;
        char *end_of_smb;
        unsigned int max_len;
+       char *full_path = NULL;
 
        xid = get_xid();
 
+       full_path = build_path_from_dentry(file_dentry(file));
+       if (full_path == NULL) {
+               rc = -ENOMEM;
+               goto rddir2_exit;
+       }
+
        /*
         * Ensure FindFirst doesn't fail before doing filldir() for '.' and
         * '..'. Otherwise we won't be able to notify VFS in case of failure.
         */
        if (file->private_data == NULL) {
-               rc = initiate_cifs_search(xid, file);
+               rc = initiate_cifs_search(xid, file, full_path);
                cifs_dbg(FYI, "initiate cifs search rc %d\n", rc);
                if (rc)
                        goto rddir2_exit;
@@ -960,8 +961,8 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
        } */
 
        tcon = tlink_tcon(cifsFile->tlink);
-       rc = find_cifs_entry(xid, tcon, ctx->pos, file, &current_entry,
-                            &num_to_fill);
+       rc = find_cifs_entry(xid, tcon, ctx->pos, file, full_path,
+                            &current_entry, &num_to_fill);
        if (rc) {
                cifs_dbg(FYI, "fce error %d\n", rc);
                goto rddir2_exit;
@@ -1019,6 +1020,7 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
        kfree(tmp_buf);
 
 rddir2_exit:
+       kfree(full_path);
        free_xid(xid);
        return rc;
 }