Skip to content

Commit 8e77860

Browse files
Ronnie Sahlbergsmfrench
authored andcommitted
cifs: drop the lease for cached directories on rmdir or rename
When we delete or rename a directory we must also drop any cached lease we have on the directory. Fixes: a350d6e ("cifs: enable caching of directories for which a lease is held") Reviewed-by: Paulo Alcantara (SUSE) <[email protected]> Signed-off-by: Ronnie Sahlberg <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 096bbee commit 8e77860

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

fs/cifs/cached_dir.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,27 @@ smb2_close_cached_fid(struct kref *ref)
340340
free_cached_dir(cfid);
341341
}
342342

343+
void drop_cached_dir_by_name(const unsigned int xid, struct cifs_tcon *tcon,
344+
const char *name, struct cifs_sb_info *cifs_sb)
345+
{
346+
struct cached_fid *cfid = NULL;
347+
int rc;
348+
349+
rc = open_cached_dir(xid, tcon, name, cifs_sb, true, &cfid);
350+
if (rc) {
351+
cifs_dbg(FYI, "no cached dir found for rmdir(%s)\n", name);
352+
return;
353+
}
354+
spin_lock(&cfid->cfids->cfid_list_lock);
355+
if (cfid->has_lease) {
356+
cfid->has_lease = false;
357+
kref_put(&cfid->refcount, smb2_close_cached_fid);
358+
}
359+
spin_unlock(&cfid->cfids->cfid_list_lock);
360+
close_cached_dir(cfid);
361+
}
362+
363+
343364
void close_cached_dir(struct cached_fid *cfid)
344365
{
345366
kref_put(&cfid->refcount, smb2_close_cached_fid);

fs/cifs/cached_dir.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ extern int open_cached_dir_by_dentry(struct cifs_tcon *tcon,
6969
struct dentry *dentry,
7070
struct cached_fid **cfid);
7171
extern void close_cached_dir(struct cached_fid *cfid);
72+
extern void drop_cached_dir_by_name(const unsigned int xid,
73+
struct cifs_tcon *tcon,
74+
const char *name,
75+
struct cifs_sb_info *cifs_sb);
7276
extern void close_all_cached_dirs(struct cifs_sb_info *cifs_sb);
7377
extern void invalidate_all_cached_dirs(struct cifs_tcon *tcon);
7478
extern int cached_dir_lease_break(struct cifs_tcon *tcon, __u8 lease_key[16]);

fs/cifs/smb2inode.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ int
655655
smb2_rmdir(const unsigned int xid, struct cifs_tcon *tcon, const char *name,
656656
struct cifs_sb_info *cifs_sb)
657657
{
658+
drop_cached_dir_by_name(xid, tcon, name, cifs_sb);
658659
return smb2_compound_op(xid, tcon, cifs_sb, name, DELETE, FILE_OPEN,
659660
CREATE_NOT_FILE, ACL_NO_MODE,
660661
NULL, SMB2_OP_RMDIR, NULL, NULL, NULL);
@@ -698,6 +699,7 @@ smb2_rename_path(const unsigned int xid, struct cifs_tcon *tcon,
698699
{
699700
struct cifsFileInfo *cfile;
700701

702+
drop_cached_dir_by_name(xid, tcon, from_name, cifs_sb);
701703
cifs_get_writable_path(tcon, from_name, FIND_WR_WITH_DELETE, &cfile);
702704

703705
return smb2_set_path_attr(xid, tcon, from_name, to_name,

0 commit comments

Comments
 (0)