Skip to content

Commit 7eb59a9

Browse files
Ronnie SahlbergSteve French
authored andcommitted
cifs: Do not access tcon->cfids->cfid directly from is_path_accessible
cfids will soon keep a list of cached fids so we should not access this directly from outside of cached_dir.c Reviewed-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent a63ec83 commit 7eb59a9

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

fs/cifs/cached_dir.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* If error then *cfid is not initialized.
1717
*/
1818
int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
19-
const char *path,
20-
struct cifs_sb_info *cifs_sb,
21-
struct cached_fid **ret_cfid)
19+
const char *path,
20+
struct cifs_sb_info *cifs_sb,
21+
bool lookup_only, struct cached_fid **ret_cfid)
2222
{
2323
struct cifs_ses *ses;
2424
struct TCP_Server_Info *server;
@@ -68,9 +68,11 @@ int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
6868
* cifs_mark_open_files_invalid() which takes the lock again
6969
* thus causing a deadlock
7070
*/
71-
7271
mutex_unlock(&cfid->fid_mutex);
7372

73+
if (lookup_only)
74+
return -ENOENT;
75+
7476
if (smb3_encryption_required(tcon))
7577
flags |= CIFS_TRANSFORM_REQ;
7678

fs/cifs/cached_dir.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ extern void free_cached_dir(struct cifs_tcon *tcon);
5050
extern int open_cached_dir(unsigned int xid, struct cifs_tcon *tcon,
5151
const char *path,
5252
struct cifs_sb_info *cifs_sb,
53-
struct cached_fid **cfid);
53+
bool lookup_only, struct cached_fid **cfid);
5454
extern int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
5555
struct dentry *dentry,
5656
struct cached_fid **cfid);

fs/cifs/readdir.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
10721072
tcon = tlink_tcon(cifsFile->tlink);
10731073
}
10741074

1075-
rc = open_cached_dir(xid, tcon, full_path, cifs_sb, &cfid);
1075+
rc = open_cached_dir(xid, tcon, full_path, cifs_sb, false, &cfid);
10761076
cifs_put_tlink(tlink);
10771077
if (rc)
10781078
goto cache_not_found;
@@ -1143,7 +1143,7 @@ int cifs_readdir(struct file *file, struct dir_context *ctx)
11431143
tcon = tlink_tcon(cifsFile->tlink);
11441144
rc = find_cifs_entry(xid, tcon, ctx->pos, file, full_path,
11451145
&current_entry, &num_to_fill);
1146-
open_cached_dir(xid, tcon, full_path, cifs_sb, &cfid);
1146+
open_cached_dir(xid, tcon, full_path, cifs_sb, false, &cfid);
11471147
if (rc) {
11481148
cifs_dbg(FYI, "fce error %d\n", rc);
11491149
goto rddir2_exit;

fs/cifs/smb2inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ smb2_query_path_info(const unsigned int xid, struct cifs_tcon *tcon,
516516
if (strcmp(full_path, ""))
517517
rc = -ENOENT;
518518
else
519-
rc = open_cached_dir(xid, tcon, full_path, cifs_sb, &cfid);
519+
rc = open_cached_dir(xid, tcon, full_path, cifs_sb, false, &cfid);
520520
/* If it is a root and its handle is cached then use it */
521521
if (!rc) {
522522
if (cfid->file_all_info_is_valid) {

fs/cifs/smb2ops.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ smb3_qfs_tcon(const unsigned int xid, struct cifs_tcon *tcon,
720720
oparms.fid = &fid;
721721
oparms.reconnect = false;
722722

723-
rc = open_cached_dir(xid, tcon, "", cifs_sb, &cfid);
723+
rc = open_cached_dir(xid, tcon, "", cifs_sb, false, &cfid);
724724
if (rc == 0)
725725
memcpy(&fid, &cfid->fid, sizeof(struct cifs_fid));
726726
else
@@ -783,9 +783,16 @@ smb2_is_path_accessible(const unsigned int xid, struct cifs_tcon *tcon,
783783
__u8 oplock = SMB2_OPLOCK_LEVEL_NONE;
784784
struct cifs_open_parms oparms;
785785
struct cifs_fid fid;
786+
struct cached_fid *cfid;
786787

787-
if ((*full_path == 0) && tcon->cfid->is_valid)
788-
return 0;
788+
rc = open_cached_dir(xid, tcon, full_path, cifs_sb, true, &cfid);
789+
if (!rc) {
790+
if (cfid->is_valid) {
791+
close_cached_dir(cfid);
792+
return 0;
793+
}
794+
close_cached_dir(cfid);
795+
}
789796

790797
utf16_path = cifs_convert_path_to_utf16(full_path, cifs_sb);
791798
if (!utf16_path)
@@ -2430,8 +2437,12 @@ smb2_query_info_compound(const unsigned int xid, struct cifs_tcon *tcon,
24302437
resp_buftype[0] = resp_buftype[1] = resp_buftype[2] = CIFS_NO_BUFFER;
24312438
memset(rsp_iov, 0, sizeof(rsp_iov));
24322439

2440+
/*
2441+
* We can only call this for things we know are directories.
2442+
*/
24332443
if (!strcmp(path, ""))
2434-
open_cached_dir(xid, tcon, path, cifs_sb, &cfid); /* cfid null if open dir failed */
2444+
open_cached_dir(xid, tcon, path, cifs_sb, false,
2445+
&cfid); /* cfid null if open dir failed */
24352446

24362447
memset(&open_iov, 0, sizeof(open_iov));
24372448
rqst[0].rq_iov = open_iov;

0 commit comments

Comments
 (0)