Skip to content

Commit fe15ce4

Browse files
author
Nick Piggin
committed
fs: change d_delete semantics
Change d_delete from a dentry deletion notification to a dentry caching advise, more like ->drop_inode. Require it to be constant and idempotent, and not take d_lock. This is how all existing filesystems use the callback anyway. This makes fine grained dentry locking of dput and dentry lru scanning much simpler. Signed-off-by: Nick Piggin <npiggin@kernel.dk>
1 parent 5eef7fa commit fe15ce4

22 files changed

Lines changed: 47 additions & 42 deletions

File tree

‎Documentation/filesystems/porting‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,11 @@ if it's zero is not *and* *never* *had* *been* enough. Final unlink() and iput(
318318
may happen while the inode is in the middle of ->write_inode(); e.g. if you blindly
319319
free the on-disk inode, you may end up doing that while ->write_inode() is writing
320320
to it.
321+
322+
---
323+
[mandatory]
324+
325+
.d_delete() now only advises the dcache as to whether or not to cache
326+
unreferenced dentries, and is now only called when the dentry refcount goes to
327+
0. Even on 0 refcount transition, it must be able to tolerate being called 0,
328+
1, or more times (eg. constant, idempotent).

‎Documentation/filesystems/vfs.txt‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,9 @@ defined:
847847

848848
struct dentry_operations {
849849
int (*d_revalidate)(struct dentry *, struct nameidata *);
850-
int (*d_hash) (struct dentry *, struct qstr *);
851-
int (*d_compare) (struct dentry *, struct qstr *, struct qstr *);
852-
int (*d_delete)(struct dentry *);
850+
int (*d_hash)(struct dentry *, struct qstr *);
851+
int (*d_compare)(struct dentry *, struct qstr *, struct qstr *);
852+
int (*d_delete)(const struct dentry *);
853853
void (*d_release)(struct dentry *);
854854
void (*d_iput)(struct dentry *, struct inode *);
855855
char *(*d_dname)(struct dentry *, char *, int);
@@ -864,9 +864,11 @@ struct dentry_operations {
864864

865865
d_compare: called when a dentry should be compared with another
866866

867-
d_delete: called when the last reference to a dentry is
868-
deleted. This means no-one is using the dentry, however it is
869-
still valid and in the dcache
867+
d_delete: called when the last reference to a dentry is dropped and the
868+
dcache is deciding whether or not to cache it. Return 1 to delete
869+
immediately, or 0 to cache the dentry. Default is NULL which means to
870+
always cache a reachable dentry. d_delete must be constant and
871+
idempotent.
870872

871873
d_release: called when a dentry is really deallocated
872874

@@ -910,14 +912,11 @@ manipulate dentries:
910912
the usage count)
911913

912914
dput: close a handle for a dentry (decrements the usage count). If
913-
the usage count drops to 0, the "d_delete" method is called
914-
and the dentry is placed on the unused list if the dentry is
915-
still in its parents hash list. Putting the dentry on the
916-
unused list just means that if the system needs some RAM, it
917-
goes through the unused list of dentries and deallocates them.
918-
If the dentry has already been unhashed and the usage count
919-
drops to 0, in this case the dentry is deallocated after the
920-
"d_delete" method is called
915+
the usage count drops to 0, and the dentry is still in its
916+
parent's hash, the "d_delete" method is called to check whether
917+
it should be cached. If it should not be cached, or if the dentry
918+
is not hashed, it is deleted. Otherwise cached dentries are put
919+
into an LRU list to be reclaimed on memory shortage.
921920

922921
d_drop: this unhashes a dentry from its parents hash list. A
923922
subsequent call to dput() will deallocate the dentry if its

‎arch/ia64/kernel/perfmon.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2185,7 +2185,7 @@ static const struct file_operations pfm_file_ops = {
21852185
};
21862186

21872187
static int
2188-
pfmfs_delete_dentry(struct dentry *dentry)
2188+
pfmfs_delete_dentry(const struct dentry *dentry)
21892189
{
21902190
return 1;
21912191
}

‎drivers/staging/smbfs/dir.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ smb_dir_open(struct inode *dir, struct file *file)
276276
static int smb_lookup_validate(struct dentry *, struct nameidata *);
277277
static int smb_hash_dentry(struct dentry *, struct qstr *);
278278
static int smb_compare_dentry(struct dentry *, struct qstr *, struct qstr *);
279-
static int smb_delete_dentry(struct dentry *);
279+
static int smb_delete_dentry(const struct dentry *);
280280

281281
static const struct dentry_operations smbfs_dentry_operations =
282282
{
@@ -367,7 +367,7 @@ smb_compare_dentry(struct dentry *dir, struct qstr *a, struct qstr *b)
367367
* We use this to unhash dentries with bad inodes.
368368
*/
369369
static int
370-
smb_delete_dentry(struct dentry * dentry)
370+
smb_delete_dentry(const struct dentry *dentry)
371371
{
372372
if (dentry->d_inode) {
373373
if (is_bad_inode(dentry->d_inode)) {

‎fs/9p/vfs_dentry.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
*
5252
*/
5353

54-
static int v9fs_dentry_delete(struct dentry *dentry)
54+
static int v9fs_dentry_delete(const struct dentry *dentry)
5555
{
5656
P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_name.name,
5757
dentry);
@@ -68,7 +68,7 @@ static int v9fs_dentry_delete(struct dentry *dentry)
6868
*
6969
*/
7070

71-
static int v9fs_cached_dentry_delete(struct dentry *dentry)
71+
static int v9fs_cached_dentry_delete(const struct dentry *dentry)
7272
{
7373
struct inode *inode = dentry->d_inode;
7474
P9_DPRINTK(P9_DEBUG_VFS, " dentry: %s (%p)\n", dentry->d_name.name,

‎fs/afs/dir.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry,
2323
static int afs_dir_open(struct inode *inode, struct file *file);
2424
static int afs_readdir(struct file *file, void *dirent, filldir_t filldir);
2525
static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd);
26-
static int afs_d_delete(struct dentry *dentry);
26+
static int afs_d_delete(const struct dentry *dentry);
2727
static void afs_d_release(struct dentry *dentry);
2828
static int afs_lookup_filldir(void *_cookie, const char *name, int nlen,
2929
loff_t fpos, u64 ino, unsigned dtype);
@@ -730,7 +730,7 @@ static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)
730730
* - called from dput() when d_count is going to 0.
731731
* - return 1 to request dentry be unhashed, 0 otherwise
732732
*/
733-
static int afs_d_delete(struct dentry *dentry)
733+
static int afs_d_delete(const struct dentry *dentry)
734734
{
735735
_enter("%s", dentry->d_name.name);
736736

‎fs/btrfs/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4127,7 +4127,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry)
41274127
return inode;
41284128
}
41294129

4130-
static int btrfs_dentry_delete(struct dentry *dentry)
4130+
static int btrfs_dentry_delete(const struct dentry *dentry)
41314131
{
41324132
struct btrfs_root *root;
41334133

‎fs/coda/dir.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static int coda_readdir(struct file *file, void *buf, filldir_t filldir);
4747

4848
/* dentry ops */
4949
static int coda_dentry_revalidate(struct dentry *de, struct nameidata *nd);
50-
static int coda_dentry_delete(struct dentry *);
50+
static int coda_dentry_delete(const struct dentry *);
5151

5252
/* support routines */
5353
static int coda_venus_readdir(struct file *coda_file, void *buf,
@@ -577,7 +577,7 @@ static int coda_dentry_revalidate(struct dentry *de, struct nameidata *nd)
577577
* This is the callback from dput() when d_count is going to 0.
578578
* We use this to unhash dentries with bad inodes.
579579
*/
580-
static int coda_dentry_delete(struct dentry * dentry)
580+
static int coda_dentry_delete(const struct dentry * dentry)
581581
{
582582
int flags;
583583

‎fs/configfs/dir.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static void configfs_d_iput(struct dentry * dentry,
6767
* We _must_ delete our dentries on last dput, as the chain-to-parent
6868
* behavior is required to clear the parents of default_groups.
6969
*/
70-
static int configfs_d_delete(struct dentry *dentry)
70+
static int configfs_d_delete(const struct dentry *dentry)
7171
{
7272
return 1;
7373
}

‎fs/dcache.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,6 @@ static void prune_one_dentry(struct dentry * dentry)
453453
if (!atomic_dec_and_lock(&dentry->d_count, &dentry->d_lock))
454454
return;
455455

456-
if (dentry->d_op && dentry->d_op->d_delete)
457-
dentry->d_op->d_delete(dentry);
458456
dentry_lru_del(dentry);
459457
__d_drop(dentry);
460458
dentry = d_kill(dentry);

0 commit comments

Comments
 (0)