Skip to content

Commit 41b02e1

Browse files
committed
ceph: explicitly reference rename old_dentry parent dir in request
We carry a pin on the parent directory for the rename source and dest dentries. For the source it's r_locked_dir; we need to explicitly reference the old_dentry parent as well, since the dentry's d_parent may change between when the request was created and pinned and when it is freed. Reviewed-by: Yehuda Sadeh <yehuda@hq.newdream.net> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 4f17726 commit 41b02e1

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

‎fs/ceph/debugfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int mdsc_show(struct seq_file *s, void *p)
102102
path = NULL;
103103
spin_lock(&req->r_old_dentry->d_lock);
104104
seq_printf(s, " #%llx/%.*s (%s)",
105-
ceph_ino(req->r_old_dentry->d_parent->d_inode),
105+
ceph_ino(req->r_old_dentry_dir),
106106
req->r_old_dentry->d_name.len,
107107
req->r_old_dentry->d_name.name,
108108
path ? path : "");

‎fs/ceph/dir.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,7 @@ static int ceph_link(struct dentry *old_dentry, struct inode *dir,
811811
req->r_dentry = dget(dentry);
812812
req->r_num_caps = 2;
813813
req->r_old_dentry = dget(old_dentry); /* or inode? hrm. */
814+
req->r_old_dentry_dir = ceph_get_dentry_parent_inode(old_dentry);
814815
req->r_locked_dir = dir;
815816
req->r_dentry_drop = CEPH_CAP_FILE_SHARED;
816817
req->r_dentry_unless = CEPH_CAP_FILE_EXCL;
@@ -909,6 +910,7 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry,
909910
req->r_dentry = dget(new_dentry);
910911
req->r_num_caps = 2;
911912
req->r_old_dentry = dget(old_dentry);
913+
req->r_old_dentry_dir = ceph_get_dentry_parent_inode(old_dentry);
912914
req->r_locked_dir = new_dir;
913915
req->r_old_dentry_drop = CEPH_CAP_FILE_SHARED;
914916
req->r_old_dentry_unless = CEPH_CAP_FILE_EXCL;

‎fs/ceph/mds_client.c‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,22 +483,26 @@ void ceph_mdsc_release_request(struct kref *kref)
483483
destroy_reply_info(&req->r_reply_info);
484484
}
485485
if (req->r_inode) {
486-
ceph_put_cap_refs(ceph_inode(req->r_inode),
487-
CEPH_CAP_PIN);
486+
ceph_put_cap_refs(ceph_inode(req->r_inode), CEPH_CAP_PIN);
488487
iput(req->r_inode);
489488
}
490489
if (req->r_locked_dir)
491-
ceph_put_cap_refs(ceph_inode(req->r_locked_dir),
492-
CEPH_CAP_PIN);
490+
ceph_put_cap_refs(ceph_inode(req->r_locked_dir), CEPH_CAP_PIN);
493491
if (req->r_target_inode)
494492
iput(req->r_target_inode);
495493
if (req->r_dentry)
496494
dput(req->r_dentry);
497495
if (req->r_old_dentry) {
498-
ceph_put_cap_refs(
499-
ceph_inode(req->r_old_dentry->d_parent->d_inode),
500-
CEPH_CAP_PIN);
496+
/*
497+
* track (and drop pins for) r_old_dentry_dir
498+
* separately, since r_old_dentry's d_parent may have
499+
* changed between the dir mutex being dropped and
500+
* this request being freed.
501+
*/
502+
ceph_put_cap_refs(ceph_inode(req->r_old_dentry_dir),
503+
CEPH_CAP_PIN);
501504
dput(req->r_old_dentry);
505+
iput(req->r_old_dentry_dir);
502506
}
503507
kfree(req->r_path1);
504508
kfree(req->r_path2);
@@ -1931,9 +1935,8 @@ int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
19311935
if (req->r_locked_dir)
19321936
ceph_get_cap_refs(ceph_inode(req->r_locked_dir), CEPH_CAP_PIN);
19331937
if (req->r_old_dentry)
1934-
ceph_get_cap_refs(
1935-
ceph_inode(req->r_old_dentry->d_parent->d_inode),
1936-
CEPH_CAP_PIN);
1938+
ceph_get_cap_refs(ceph_inode(req->r_old_dentry_dir),
1939+
CEPH_CAP_PIN);
19371940

19381941
/* issue */
19391942
mutex_lock(&mdsc->mutex);

‎fs/ceph/mds_client.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ struct ceph_mds_request {
171171
struct inode *r_inode; /* arg1 */
172172
struct dentry *r_dentry; /* arg1 */
173173
struct dentry *r_old_dentry; /* arg2: rename from or link from */
174+
struct inode *r_old_dentry_dir; /* arg2: old dentry's parent dir */
174175
char *r_path1, *r_path2;
175176
struct ceph_vino r_ino1, r_ino2;
176177

0 commit comments

Comments
 (0)