Skip to content

Commit c6ffe10

Browse files
committed
ceph: use new D_COMPLETE dentry flag
We used to use a flag on the directory inode to track whether the dcache contents for a directory were a complete cached copy. Switch to a dentry flag CEPH_D_COMPLETE that is safely updated by ->d_prune(). Signed-off-by: Sage Weil <sage@newdream.net>
1 parent b58dc41 commit c6ffe10

5 files changed

Lines changed: 68 additions & 23 deletions

File tree

‎fs/ceph/caps.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,17 +487,15 @@ static void __check_cap_issue(struct ceph_inode_info *ci, struct ceph_cap *cap,
487487
ci->i_rdcache_gen++;
488488

489489
/*
490-
* if we are newly issued FILE_SHARED, clear I_COMPLETE; we
490+
* if we are newly issued FILE_SHARED, clear D_COMPLETE; we
491491
* don't know what happened to this directory while we didn't
492492
* have the cap.
493493
*/
494494
if ((issued & CEPH_CAP_FILE_SHARED) &&
495495
(had & CEPH_CAP_FILE_SHARED) == 0) {
496496
ci->i_shared_gen++;
497-
if (S_ISDIR(ci->vfs_inode.i_mode)) {
498-
dout(" marking %p NOT complete\n", &ci->vfs_inode);
499-
ci->i_ceph_flags &= ~CEPH_I_COMPLETE;
500-
}
497+
if (S_ISDIR(ci->vfs_inode.i_mode))
498+
ceph_dir_clear_complete(&ci->vfs_inode);
501499
}
502500
}
503501

‎fs/ceph/dir.c‎

Lines changed: 50 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static unsigned fpos_off(loff_t p)
108108
* falling back to a "normal" sync readdir if any dentries in the dir
109109
* are dropped.
110110
*
111-
* I_COMPLETE tells indicates we have all dentries in the dir. It is
111+
* D_COMPLETE tells indicates we have all dentries in the dir. It is
112112
* defined IFF we hold CEPH_CAP_FILE_SHARED (which will be revoked by
113113
* the MDS if/when the directory is modified).
114114
*/
@@ -199,8 +199,8 @@ static int __dcache_readdir(struct file *filp,
199199
filp->f_pos++;
200200

201201
/* make sure a dentry wasn't dropped while we didn't have parent lock */
202-
if (!ceph_i_test(dir, CEPH_I_COMPLETE)) {
203-
dout(" lost I_COMPLETE on %p; falling back to mds\n", dir);
202+
if (!ceph_dir_test_complete(dir)) {
203+
dout(" lost D_COMPLETE on %p; falling back to mds\n", dir);
204204
err = -EAGAIN;
205205
goto out;
206206
}
@@ -285,7 +285,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
285285
if ((filp->f_pos == 2 || fi->dentry) &&
286286
!ceph_test_mount_opt(fsc, NOASYNCREADDIR) &&
287287
ceph_snap(inode) != CEPH_SNAPDIR &&
288-
(ci->i_ceph_flags & CEPH_I_COMPLETE) &&
288+
ceph_dir_test_complete(inode) &&
289289
__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1)) {
290290
spin_unlock(&inode->i_lock);
291291
err = __dcache_readdir(filp, dirent, filldir);
@@ -351,7 +351,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
351351

352352
if (!req->r_did_prepopulate) {
353353
dout("readdir !did_prepopulate");
354-
fi->dir_release_count--; /* preclude I_COMPLETE */
354+
fi->dir_release_count--; /* preclude D_COMPLETE */
355355
}
356356

357357
/* note next offset and last dentry name */
@@ -430,8 +430,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
430430
*/
431431
spin_lock(&inode->i_lock);
432432
if (ci->i_release_count == fi->dir_release_count) {
433-
dout(" marking %p complete\n", inode);
434-
/* ci->i_ceph_flags |= CEPH_I_COMPLETE; */
433+
ceph_dir_set_complete(inode);
435434
ci->i_max_offset = filp->f_pos;
436435
}
437436
spin_unlock(&inode->i_lock);
@@ -614,7 +613,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
614613
fsc->mount_options->snapdir_name,
615614
dentry->d_name.len) &&
616615
!is_root_ceph_dentry(dir, dentry) &&
617-
(ci->i_ceph_flags & CEPH_I_COMPLETE) &&
616+
ceph_dir_test_complete(dir) &&
618617
(__ceph_caps_issued_mask(ci, CEPH_CAP_FILE_SHARED, 1))) {
619618
spin_unlock(&dir->i_lock);
620619
dout(" dir %p complete, -ENOENT\n", dir);
@@ -934,7 +933,7 @@ static int ceph_rename(struct inode *old_dir, struct dentry *old_dentry,
934933
*/
935934

936935
/* d_move screws up d_subdirs order */
937-
ceph_i_clear(new_dir, CEPH_I_COMPLETE);
936+
ceph_dir_clear_complete(new_dir);
938937

939938
d_move(old_dentry, new_dentry);
940939

@@ -1092,6 +1091,48 @@ static int ceph_snapdir_d_revalidate(struct dentry *dentry,
10921091
return 1;
10931092
}
10941093

1094+
/*
1095+
* Set/clear/test dir complete flag on the dir's dentry.
1096+
*/
1097+
static struct dentry * __d_find_any_alias(struct inode *inode)
1098+
{
1099+
struct dentry *alias;
1100+
1101+
if (list_empty(&inode->i_dentry))
1102+
return NULL;
1103+
alias = list_first_entry(&inode->i_dentry, struct dentry, d_alias);
1104+
return alias;
1105+
}
1106+
1107+
void ceph_dir_set_complete(struct inode *inode)
1108+
{
1109+
struct dentry *dentry = __d_find_any_alias(inode);
1110+
1111+
if (dentry && ceph_dentry(dentry)) {
1112+
dout(" marking %p (%p) complete\n", inode, dentry);
1113+
set_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
1114+
}
1115+
}
1116+
1117+
void ceph_dir_clear_complete(struct inode *inode)
1118+
{
1119+
struct dentry *dentry = __d_find_any_alias(inode);
1120+
1121+
if (dentry && ceph_dentry(dentry)) {
1122+
dout(" marking %p (%p) NOT complete\n", inode, dentry);
1123+
clear_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
1124+
}
1125+
}
1126+
1127+
bool ceph_dir_test_complete(struct inode *inode)
1128+
{
1129+
struct dentry *dentry = __d_find_any_alias(inode);
1130+
1131+
if (dentry && ceph_dentry(dentry))
1132+
return test_bit(CEPH_D_COMPLETE, &ceph_dentry(dentry)->flags);
1133+
return false;
1134+
}
1135+
10951136
/*
10961137
* When the VFS prunes a dentry from the cache, we need to clear the
10971138
* complete flag on the parent directory.

‎fs/ceph/inode.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -771,9 +771,9 @@ static int fill_inode(struct inode *inode,
771771
ceph_snap(inode) == CEPH_NOSNAP &&
772772
(le32_to_cpu(info->cap.caps) & CEPH_CAP_FILE_SHARED) &&
773773
(issued & CEPH_CAP_FILE_EXCL) == 0 &&
774-
(ci->i_ceph_flags & CEPH_I_COMPLETE) == 0) {
774+
!ceph_dir_test_complete(inode)) {
775775
dout(" marking %p complete (empty)\n", inode);
776-
/* ci->i_ceph_flags |= CEPH_I_COMPLETE; */
776+
ceph_dir_set_complete(inode);
777777
ci->i_max_offset = 2;
778778
}
779779

@@ -856,7 +856,7 @@ static void ceph_set_dentry_offset(struct dentry *dn)
856856
di = ceph_dentry(dn);
857857

858858
spin_lock(&inode->i_lock);
859-
if ((ceph_inode(inode)->i_ceph_flags & CEPH_I_COMPLETE) == 0) {
859+
if (!ceph_dir_test_complete(inode)) {
860860
spin_unlock(&inode->i_lock);
861861
return;
862862
}
@@ -1056,7 +1056,7 @@ int ceph_fill_trace(struct super_block *sb, struct ceph_mds_request *req,
10561056
* d_move() puts the renamed dentry at the end of
10571057
* d_subdirs. We need to assign it an appropriate
10581058
* directory offset so we can behave when holding
1059-
* I_COMPLETE.
1059+
* D_COMPLETE.
10601060
*/
10611061
ceph_set_dentry_offset(req->r_old_dentry);
10621062
dout("dn %p gets new offset %lld\n", req->r_old_dentry,

‎fs/ceph/mds_client.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,17 +2002,17 @@ int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
20022002
}
20032003

20042004
/*
2005-
* Invalidate dir I_COMPLETE, dentry lease state on an aborted MDS
2005+
* Invalidate dir D_COMPLETE, dentry lease state on an aborted MDS
20062006
* namespace request.
20072007
*/
20082008
void ceph_invalidate_dir_request(struct ceph_mds_request *req)
20092009
{
20102010
struct inode *inode = req->r_locked_dir;
20112011
struct ceph_inode_info *ci = ceph_inode(inode);
20122012

2013-
dout("invalidate_dir_request %p (I_COMPLETE, lease(s))\n", inode);
2013+
dout("invalidate_dir_request %p (D_COMPLETE, lease(s))\n", inode);
20142014
spin_lock(&inode->i_lock);
2015-
ci->i_ceph_flags &= ~CEPH_I_COMPLETE;
2015+
ceph_dir_clear_complete(inode);
20162016
ci->i_release_count++;
20172017
spin_unlock(&inode->i_lock);
20182018

‎fs/ceph/super.h‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ struct ceph_inode_info {
264264
struct timespec i_rctime;
265265
u64 i_rbytes, i_rfiles, i_rsubdirs;
266266
u64 i_files, i_subdirs;
267-
u64 i_max_offset; /* largest readdir offset, set with I_COMPLETE */
267+
u64 i_max_offset; /* largest readdir offset, set with D_COMPLETE */
268268

269269
struct rb_root i_fragtree;
270270
struct mutex i_fragtree_mutex;
@@ -429,7 +429,6 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,
429429
/*
430430
* Ceph inode.
431431
*/
432-
#define CEPH_I_COMPLETE 1 /* we have complete directory cached */
433432
#define CEPH_I_NODELAY 4 /* do not delay cap release */
434433
#define CEPH_I_FLUSH 8 /* do not delay flush of dirty metadata */
435434
#define CEPH_I_NOFLUSH 16 /* do not flush dirty caps */
@@ -486,6 +485,13 @@ static inline loff_t ceph_make_fpos(unsigned frag, unsigned off)
486485
return ((loff_t)frag << 32) | (loff_t)off;
487486
}
488487

488+
/*
489+
* set/clear directory D_COMPLETE flag
490+
*/
491+
void ceph_dir_set_complete(struct inode *inode);
492+
void ceph_dir_clear_complete(struct inode *inode);
493+
bool ceph_dir_test_complete(struct inode *inode);
494+
489495
/*
490496
* caps helpers
491497
*/

0 commit comments

Comments
 (0)