Skip to content

Commit

Permalink
cifs: return cached_fid from open_shroot
Browse files Browse the repository at this point in the history
Cleanup patch for followon to cache additional information for the root directory
when directory lease held.

Signed-off-by: Ronnie Sahlberg <[email protected]>
Signed-off-by: Steve French <[email protected]>
  • Loading branch information
Ronnie Sahlberg authored and Steve French committed Oct 12, 2020
1 parent 3984bdc commit 9e81e8f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
11 changes: 6 additions & 5 deletions fs/cifs/smb2inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
int rc;
struct smb2_file_all_info *smb2_data;
__u32 create_options = 0;
struct cifs_fid fid;
bool no_cached_open = tcon->nohandlecache;
struct cifsFileInfo *cfile;
struct cached_fid *cfid = NULL;

*adjust_tz = false;
*symlink = false;
Expand All @@ -525,20 +525,21 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,

/* If it is a root and its handle is cached then use it */
if (!strlen(full_path) && !no_cached_open) {
rc = open_shroot(xid, tcon, cifs_sb, &fid);
rc = open_shroot(xid, tcon, cifs_sb, &cfid);
if (rc)
goto out;

if (tcon->crfid.file_all_info_is_valid) {
move_smb2_info_to_cifs(data,
&tcon->crfid.file_all_info);
} else {
rc = SMB2_query_info(xid, tcon, fid.persistent_fid,
fid.volatile_fid, smb2_data);
rc = SMB2_query_info(xid, tcon,
cfid->fid->persistent_fid,
cfid->fid->volatile_fid, smb2_data);
if (!rc)
move_smb2_info_to_cifs(data, smb2_data);
}
close_shroot(&tcon->crfid);
close_shroot(cfid);
goto out;
}

Expand Down
22 changes: 15 additions & 7 deletions fs/cifs/smb2ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,8 @@ smb2_cached_lease_break(struct work_struct *work)
* Open the directory at the root of a share
*/
int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
struct cifs_sb_info *cifs_sb, struct cifs_fid *pfid)
struct cifs_sb_info *cifs_sb,
struct cached_fid **cfid)
{
struct cifs_ses *ses = tcon->ses;
struct TCP_Server_Info *server = ses->server;
Expand All @@ -666,11 +667,12 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
int rc, flags = 0;
__le16 utf16_path = 0; /* Null - since an open of top of share */
u8 oplock = SMB2_OPLOCK_LEVEL_II;
struct cifs_fid *pfid;

mutex_lock(&tcon->crfid.fid_mutex);
if (tcon->crfid.is_valid) {
cifs_dbg(FYI, "found a cached root file handle\n");
memcpy(pfid, tcon->crfid.fid, sizeof(struct cifs_fid));
*cfid = &tcon->crfid;
kref_get(&tcon->crfid.refcount);
mutex_unlock(&tcon->crfid.fid_mutex);
return 0;
Expand All @@ -691,6 +693,7 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
if (!server->ops->new_lease_key)
return -EIO;

pfid = tcon->crfid.fid;
server->ops->new_lease_key(pfid);

memset(rqst, 0, sizeof(rqst));
Expand Down Expand Up @@ -820,6 +823,8 @@ int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
SMB2_query_info_free(&rqst[1]);
free_rsp_buf(resp_buftype[0], rsp_iov[0].iov_base);
free_rsp_buf(resp_buftype[1], rsp_iov[1].iov_base);
if (rc == 0)
*cfid = &tcon->crfid;
return rc;
}

Expand All @@ -833,6 +838,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
struct cifs_open_parms oparms;
struct cifs_fid fid;
bool no_cached_open = tcon->nohandlecache;
struct cached_fid *cfid = NULL;

oparms.tcon = tcon;
oparms.desired_access = FILE_READ_ATTRIBUTES;
Expand All @@ -841,12 +847,14 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
oparms.fid = &fid;
oparms.reconnect = false;

if (no_cached_open)
if (no_cached_open) {
rc = SMB2_open(xid, &oparms, &srch_path, &oplock, NULL, NULL,
NULL, NULL);
else
rc = open_shroot(xid, tcon, cifs_sb, &fid);

} else {
rc = open_shroot(xid, tcon, cifs_sb, &cfid);
if (rc == 0)
memcpy(&fid, cfid->fid, sizeof(struct cifs_fid));
}
if (rc)
return;

Expand All @@ -863,7 +871,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
if (no_cached_open)
SMB2_close(xid, tcon, fid.persistent_fid, fid.volatile_fid);
else
close_shroot(&tcon->crfid);
close_shroot(cfid);
}

static void
Expand Down
3 changes: 2 additions & 1 deletion fs/cifs/smb2proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ extern int smb3_handle_read_data(struct TCP_Server_Info *server,
struct mid_q_entry *mid);

extern int open_shroot(unsigned int xid, struct cifs_tcon *tcon,
struct cifs_sb_info *cifs_sb, struct cifs_fid *pfid);
struct cifs_sb_info *cifs_sb,
struct cached_fid **cfid);
extern void close_shroot(struct cached_fid *cfid);
extern void close_shroot_lease(struct cached_fid *cfid);
extern void close_shroot_lease_locked(struct cached_fid *cfid);
Expand Down

0 comments on commit 9e81e8f

Please sign in to comment.