diff options
author | Miklos Szeredi <mszeredi@redhat.com> | 2016-06-28 05:47:32 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2016-07-24 16:36:29 -0400 |
commit | 285b102d3b745f3c2c110c9c327741d87e64aacc (patch) | |
tree | c0d13e12f96b7730a1db2633f8e3743fbc267ade | |
parent | 17648b871d3cecf310f55ce8c6ce5821d135f6ec (diff) |
vfs: new d_init method
Allow filesystem to initialize dentry at allocation time.
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | Documentation/filesystems/Locking | 2 | ||||
-rw-r--r-- | Documentation/filesystems/vfs.txt | 3 | ||||
-rw-r--r-- | fs/dcache.c | 11 | ||||
-rw-r--r-- | include/linux/dcache.h | 1 |
4 files changed, 17 insertions, 0 deletions
diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index a38da93865c2..794adbe55399 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking | |||
@@ -15,6 +15,7 @@ prototypes: | |||
15 | int (*d_compare)(const struct dentry *, const struct dentry *, | 15 | int (*d_compare)(const struct dentry *, const struct dentry *, |
16 | unsigned int, const char *, const struct qstr *); | 16 | unsigned int, const char *, const struct qstr *); |
17 | int (*d_delete)(struct dentry *); | 17 | int (*d_delete)(struct dentry *); |
18 | int (*d_init)(struct dentry *); | ||
18 | void (*d_release)(struct dentry *); | 19 | void (*d_release)(struct dentry *); |
19 | void (*d_iput)(struct dentry *, struct inode *); | 20 | void (*d_iput)(struct dentry *, struct inode *); |
20 | char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen); | 21 | char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen); |
@@ -30,6 +31,7 @@ d_weak_revalidate:no no yes no | |||
30 | d_hash no no no maybe | 31 | d_hash no no no maybe |
31 | d_compare: yes no no maybe | 32 | d_compare: yes no no maybe |
32 | d_delete: no yes no no | 33 | d_delete: no yes no no |
34 | d_init: no no yes no | ||
33 | d_release: no no yes no | 35 | d_release: no no yes no |
34 | d_prune: no yes no no | 36 | d_prune: no yes no no |
35 | d_iput: no no yes no | 37 | d_iput: no no yes no |
diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index 70a056fe51a3..15c3fa7c89cc 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt | |||
@@ -923,6 +923,7 @@ struct dentry_operations { | |||
923 | int (*d_compare)(const struct dentry *, const struct dentry *, | 923 | int (*d_compare)(const struct dentry *, const struct dentry *, |
924 | unsigned int, const char *, const struct qstr *); | 924 | unsigned int, const char *, const struct qstr *); |
925 | int (*d_delete)(const struct dentry *); | 925 | int (*d_delete)(const struct dentry *); |
926 | int (*d_init)(struct dentry *); | ||
926 | void (*d_release)(struct dentry *); | 927 | void (*d_release)(struct dentry *); |
927 | void (*d_iput)(struct dentry *, struct inode *); | 928 | void (*d_iput)(struct dentry *, struct inode *); |
928 | char *(*d_dname)(struct dentry *, char *, int); | 929 | char *(*d_dname)(struct dentry *, char *, int); |
@@ -995,6 +996,8 @@ struct dentry_operations { | |||
995 | always cache a reachable dentry. d_delete must be constant and | 996 | always cache a reachable dentry. d_delete must be constant and |
996 | idempotent. | 997 | idempotent. |
997 | 998 | ||
999 | d_init: called when a dentry is allocated | ||
1000 | |||
998 | d_release: called when a dentry is really deallocated | 1001 | d_release: called when a dentry is really deallocated |
999 | 1002 | ||
1000 | d_iput: called when a dentry loses its inode (just prior to its | 1003 | d_iput: called when a dentry loses its inode (just prior to its |
diff --git a/fs/dcache.c b/fs/dcache.c index d5beef01cdfc..6d60a764c848 100644 --- a/fs/dcache.c +++ b/fs/dcache.c | |||
@@ -1569,6 +1569,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) | |||
1569 | { | 1569 | { |
1570 | struct dentry *dentry; | 1570 | struct dentry *dentry; |
1571 | char *dname; | 1571 | char *dname; |
1572 | int err; | ||
1572 | 1573 | ||
1573 | dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); | 1574 | dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL); |
1574 | if (!dentry) | 1575 | if (!dentry) |
@@ -1627,6 +1628,16 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) | |||
1627 | INIT_LIST_HEAD(&dentry->d_child); | 1628 | INIT_LIST_HEAD(&dentry->d_child); |
1628 | d_set_d_op(dentry, dentry->d_sb->s_d_op); | 1629 | d_set_d_op(dentry, dentry->d_sb->s_d_op); |
1629 | 1630 | ||
1631 | if (dentry->d_op && dentry->d_op->d_init) { | ||
1632 | err = dentry->d_op->d_init(dentry); | ||
1633 | if (err) { | ||
1634 | if (dname_external(dentry)) | ||
1635 | kfree(external_name(dentry)); | ||
1636 | kmem_cache_free(dentry_cache, dentry); | ||
1637 | return NULL; | ||
1638 | } | ||
1639 | } | ||
1640 | |||
1630 | this_cpu_inc(nr_dentry); | 1641 | this_cpu_inc(nr_dentry); |
1631 | 1642 | ||
1632 | return dentry; | 1643 | return dentry; |
diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 14df83609c7f..98044a8d1487 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h | |||
@@ -133,6 +133,7 @@ struct dentry_operations { | |||
133 | int (*d_compare)(const struct dentry *, const struct dentry *, | 133 | int (*d_compare)(const struct dentry *, const struct dentry *, |
134 | unsigned int, const char *, const struct qstr *); | 134 | unsigned int, const char *, const struct qstr *); |
135 | int (*d_delete)(const struct dentry *); | 135 | int (*d_delete)(const struct dentry *); |
136 | int (*d_init)(struct dentry *); | ||
136 | void (*d_release)(struct dentry *); | 137 | void (*d_release)(struct dentry *); |
137 | void (*d_prune)(struct dentry *); | 138 | void (*d_prune)(struct dentry *); |
138 | void (*d_iput)(struct dentry *, struct inode *); | 139 | void (*d_iput)(struct dentry *, struct inode *); |