From: Tom Spink <tspink@gmail.com>
To: linux-kernel@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, Tom Spink <tspink@gmail.com>
Subject: [RFC PATCH 1/2] vfs: Introduce on-demand filesystem initialisation
Date: Sun, 1 Jun 2008 15:51:54 +0100 [thread overview]
Message-ID: <1212331915-22856-2-git-send-email-tspink@gmail.com> (raw)
In-Reply-To: <1212331915-22856-1-git-send-email-tspink@gmail.com>
This patch adds on-demand filesystem initialisation capabilities to the VFS,
whereby an init routine will be executed on first use of a particular
filesystem type. Also, an exit routine will be executed when the last
superblock of a filesystem type is deactivated.
This is useful for filesystems that share global resources between all
instances of the filesystem, but only need those resources when there are
any users of the filesystem. This lets the filesystem initialise those
resources (kernel threads or caches, say) when the first superblock is
created. It also lets the filesystem clean up those resources when the
last superblock is deactivated.
Signed-off-by: Tom Spink <tspink@gmail.com>
---
fs/filesystems.c | 2 ++
fs/super.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++-
include/linux/fs.h | 3 +++
3 files changed, 51 insertions(+), 1 deletions(-)
diff --git a/fs/filesystems.c b/fs/filesystems.c
index f37f872..59b2eaa 100644
--- a/fs/filesystems.c
+++ b/fs/filesystems.c
@@ -79,6 +79,7 @@ int register_filesystem(struct file_system_type * fs)
res = -EBUSY;
else
*p = fs;
+ mutex_init(&fs->fs_supers_lock);
write_unlock(&file_systems_lock);
return res;
}
@@ -105,6 +106,7 @@ int unregister_filesystem(struct file_system_type * fs)
tmp = &file_systems;
while (*tmp) {
if (fs == *tmp) {
+ mutex_destroy(&fs->fs_supers_lock);
*tmp = fs->next;
fs->next = NULL;
write_unlock(&file_systems_lock);
diff --git a/fs/super.c b/fs/super.c
index 453877c..af20175 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -181,7 +181,21 @@ void deactivate_super(struct super_block *s)
spin_unlock(&sb_lock);
DQUOT_OFF(s, 0);
down_write(&s->s_umount);
+
+ /* Take the mutex before calling kill_sb, because it may
+ * modify the fs_supers list.
+ */
+ mutex_lock(&fs->fs_supers_lock);
fs->kill_sb(s);
+
+ /* Check to see if this is the last superblock of the
+ * filesystem going down, and if it is, then run the exit
+ * routine.
+ */
+ if (list_empty(&fs->fs_supers) && fs->exit)
+ fs->exit();
+ mutex_unlock(&fs->fs_supers_lock);
+
put_filesystem(fs);
put_super(s);
}
@@ -338,6 +352,7 @@ struct super_block *sget(struct file_system_type *type,
struct super_block *old;
int err;
+ mutex_lock(&type->fs_supers_lock);
retry:
spin_lock(&sb_lock);
if (test) {
@@ -348,14 +363,17 @@ retry:
goto retry;
if (s)
destroy_super(s);
+ mutex_unlock(&type->fs_supers_lock);
return old;
}
}
if (!s) {
spin_unlock(&sb_lock);
s = alloc_super(type);
- if (!s)
+ if (!s) {
+ mutex_unlock(&type->fs_supers_lock);
return ERR_PTR(-ENOMEM);
+ }
goto retry;
}
@@ -363,14 +381,41 @@ retry:
if (err) {
spin_unlock(&sb_lock);
destroy_super(s);
+ mutex_unlock(&type->fs_supers_lock);
return ERR_PTR(err);
}
+
+ /* If this is the first superblock of this particular filesystem,
+ * run the init routine, if any. If we're going to do this, then we
+ * also need to drop the sb_lock spinlock.
+ */
+ if (list_empty(&type->fs_supers) && type->init) {
+ spin_unlock(&sb_lock);
+
+ /* We can do this, because we're holding the fs_supers_lock
+ * mutex.
+ */
+ err = type->init();
+ if (err < 0) {
+ /* If the filesystem failed to initialise, then back
+ * out, destroy the superblock and return the error.
+ */
+ destroy_super(s);
+ mutex_unlock(&type->fs_supers_lock);
+ return ERR_PTR(err);
+ }
+
+ spin_lock(&sb_lock);
+ }
+
s->s_type = type;
strlcpy(s->s_id, type->name, sizeof(s->s_id));
list_add_tail(&s->s_list, &super_blocks);
list_add(&s->s_instances, &type->fs_supers);
spin_unlock(&sb_lock);
get_filesystem(type);
+
+ mutex_unlock(&type->fs_supers_lock);
return s;
}
diff --git a/include/linux/fs.h b/include/linux/fs.h
index f413085..92d446f 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1477,8 +1477,11 @@ struct file_system_type {
int (*get_sb) (struct file_system_type *, int,
const char *, void *, struct vfsmount *);
void (*kill_sb) (struct super_block *);
+ int (*init) (void);
+ void (*exit) (void);
struct module *owner;
struct file_system_type * next;
+ struct mutex fs_supers_lock;
struct list_head fs_supers;
struct lock_class_key s_lock_key;
--
1.5.4.3
next prev parent reply other threads:[~2008-06-01 14:51 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-06-01 14:51 [RFC PATCH 0/2] On-demand Filesystem Initialisation Tom Spink
2008-06-01 14:51 ` Tom Spink [this message]
2008-06-01 14:51 ` [RFC PATCH 2/2] xfs: Make XFS use the new file system init infrastructure Tom Spink
2008-06-01 15:32 ` [RFC PATCH 1/2] vfs: Introduce on-demand filesystem initialisation Al Viro
2008-06-02 13:38 ` Tom Spink
2008-06-02 1:58 ` [RFC PATCH 0/2] On-demand Filesystem Initialisation Dave Chinner
2008-06-02 13:39 ` Tom Spink
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=1212331915-22856-2-git-send-email-tspink@gmail.com \
--to=tspink@gmail.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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).