linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Miklos Szeredi <mszeredi@redhat.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 1/8] vfs: new d_allocate method
Date: Wed, 22 Jun 2016 16:35:03 +0200	[thread overview]
Message-ID: <1466606110-24297-2-git-send-email-mszeredi@redhat.com> (raw)
In-Reply-To: <1466606110-24297-1-git-send-email-mszeredi@redhat.com>

Allow filesystem to initialize dentry (->d_fsdata to be explicit) at
allocation time.

Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
---
 Documentation/filesystems/Locking |  2 ++
 Documentation/filesystems/vfs.txt |  3 +++
 fs/dcache.c                       | 11 +++++++++++
 include/linux/dcache.h            |  1 +
 4 files changed, 17 insertions(+)

diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking
index 75eea7ce3d7c..6da7d7363709 100644
--- a/Documentation/filesystems/Locking
+++ b/Documentation/filesystems/Locking
@@ -15,6 +15,7 @@ prototypes:
 	int (*d_compare)(const struct dentry *, const struct dentry *,
 			unsigned int, const char *, const struct qstr *);
 	int (*d_delete)(struct dentry *);
+	int (*d_allocate)(struct dentry *);
 	void (*d_release)(struct dentry *);
 	void (*d_iput)(struct dentry *, struct inode *);
 	char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen);
@@ -28,6 +29,7 @@ d_weak_revalidate:no		no		yes	 	no
 d_hash		no		no		no		maybe
 d_compare:	yes		no		no		maybe
 d_delete:	no		yes		no		no
+d_allocate:	no		no		yes		no
 d_release:	no		no		yes		no
 d_prune:        no              yes             no              no
 d_iput:		no		no		yes		no
diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt
index c61a223ef3ff..4d8f1a5d8936 100644
--- a/Documentation/filesystems/vfs.txt
+++ b/Documentation/filesystems/vfs.txt
@@ -933,6 +933,7 @@ struct dentry_operations {
 	int (*d_compare)(const struct dentry *, const struct dentry *,
 			unsigned int, const char *, const struct qstr *);
 	int (*d_delete)(const struct dentry *);
+	int (*d_allocate)(struct dentry *);
 	void (*d_release)(struct dentry *);
 	void (*d_iput)(struct dentry *, struct inode *);
 	char *(*d_dname)(struct dentry *, char *, int);
@@ -1003,6 +1004,8 @@ struct dentry_operations {
 	always cache a reachable dentry. d_delete must be constant and
 	idempotent.
 
+  d_allocate: called when a dentry is really allocated
+
   d_release: called when a dentry is really deallocated
 
   d_iput: called when a dentry loses its inode (just prior to its
diff --git a/fs/dcache.c b/fs/dcache.c
index 817c243c1ff1..dc573af50edc 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1559,6 +1559,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
 {
 	struct dentry *dentry;
 	char *dname;
+	int err;
 
 	dentry = kmem_cache_alloc(dentry_cache, GFP_KERNEL);
 	if (!dentry)
@@ -1617,6 +1618,16 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
 	INIT_LIST_HEAD(&dentry->d_child);
 	d_set_d_op(dentry, dentry->d_sb->s_d_op);
 
+	if (dentry->d_op && dentry->d_op->d_allocate) {
+		err = dentry->d_op->d_allocate(dentry);
+		if (err) {
+			if (dname_external(dentry))
+				kfree(external_name(dentry));
+			kmem_cache_free(dentry_cache, dentry);
+			return NULL;
+		}
+	}
+
 	this_cpu_inc(nr_dentry);
 
 	return dentry;
diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index f28100f6b556..a2f01284b277 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -133,6 +133,7 @@ struct dentry_operations {
 	int (*d_compare)(const struct dentry *, const struct dentry *,
 			unsigned int, const char *, const struct qstr *);
 	int (*d_delete)(const struct dentry *);
+	int (*d_allocate)(struct dentry *);
 	void (*d_release)(struct dentry *);
 	void (*d_prune)(struct dentry *);
 	void (*d_iput)(struct dentry *, struct inode *);
-- 
2.5.5

  reply	other threads:[~2016-06-22 14:37 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-22 14:35 [PATCH 0/8] remove d_time from dentry Miklos Szeredi
2016-06-22 14:35 ` Miklos Szeredi [this message]
2016-06-22 17:02   ` [PATCH 1/8] vfs: new d_allocate method Al Viro
2016-06-22 20:33     ` Miklos Szeredi
2016-06-22 14:35 ` [PATCH 2/8] ceph: don't use ->d_time Miklos Szeredi
2016-06-23  6:21   ` Yan, Zheng
2016-06-28  8:09     ` Miklos Szeredi
2016-06-28  8:39       ` Yan, Zheng
2016-06-22 14:35 ` [PATCH 3/8] cifs: " Miklos Szeredi
2016-06-22 14:35 ` [PATCH 4/8] vfat: " Miklos Szeredi
2016-06-22 14:35 ` [PATCH 5/8] fuse: " Miklos Szeredi
2016-06-22 16:46   ` Al Viro
2016-06-22 14:35 ` [PATCH 6/8] nfs: " Miklos Szeredi
2016-06-22 16:48   ` Al Viro
2016-06-22 14:35 ` [PATCH 7/8] ncpfs: " Miklos Szeredi
2016-06-22 16:52   ` Al Viro
2016-06-22 14:35 ` [PATCH 8/8] vfs: remove ->d_time Miklos Szeredi
2016-06-22 21:21 ` [PATCH 0/8] remove d_time from dentry Miklos Szeredi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1466606110-24297-2-git-send-email-mszeredi@redhat.com \
    --to=mszeredi@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@ZenIV.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).