From: Alexander Viro <viro@math.psu.edu>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: [PATCH] fs/super.c fixes - second series (6/11)
Date: Sun, 12 Aug 2001 21:28:12 -0400 (EDT) [thread overview]
Message-ID: <Pine.GSO.4.21.0108122127560.7092-100000@weyl.math.psu.edu> (raw)
In-Reply-To: <Pine.GSO.4.21.0108122127320.7092-100000@weyl.math.psu.edu>
Part 6/11
* get_sb_single() doesn't rely on kern_mount() being already done.
It simply checks list_empty(&type->fs_supers) and if we already have a
superblocks - grabs and returns it. If we don't have one it does the
right thing - inserts preallocated superblock into the ->fs_supers (and
super_blocks, indeed) and does ->read_super() on it, etc.
It means that get_sb_single() works regardless of the kern_mount() -
if the latter had been done the thing will pick the superblock as it used
to do, if not - no problems.
diff -urN S9-pre1-fs_supers/fs/super.c S9-pre1-get_sb_single/fs/super.c
--- S9-pre1-fs_supers/fs/super.c Sun Aug 12 20:45:50 2001
+++ S9-pre1-get_sb_single/fs/super.c Sun Aug 12 20:45:50 2001
@@ -1031,19 +1031,62 @@
static struct super_block *get_sb_single(struct file_system_type *fs_type,
int flags, void *data)
{
- struct super_block * sb;
+ struct super_block * s = alloc_super();
+ if (!s)
+ return ERR_PTR(-ENOMEM);
+ down_write(&s->s_umount);
/*
* Get the superblock of kernel-wide instance, but
* keep the reference to fs_type.
*/
down(&mount_sem);
- sb = fs_type->kern_mnt->mnt_sb;
- if (!sb)
- BUG();
- atomic_inc(&sb->s_active);
- down_write(&sb->s_umount);
- do_remount_sb(sb, flags, data);
- return sb;
+retry:
+ spin_lock(&sb_lock);
+ if (!list_empty(&fs_type->fs_supers)) {
+ struct super_block *old;
+ old = list_entry(fs_type->fs_supers.next, struct super_block,
+ s_instances);
+ if (!grab_super(old))
+ goto retry;
+ atomic_dec(&s->s_active);
+ put_super(s);
+ do_remount_sb(old, flags, data);
+ return old;
+ } else {
+ kdev_t dev = get_unnamed_dev();
+ if (!dev) {
+ atomic_dec(&s->s_active);
+ put_super(s);
+ up(&mount_sem);
+ return ERR_PTR(-EMFILE);
+ }
+ s->s_dev = dev;
+ s->s_flags = flags;
+ s->s_type = fs_type;
+ list_add (&s->s_list, super_blocks.prev);
+ list_add (&s->s_instances, &fs_type->fs_supers);
+ spin_unlock(&sb_lock);
+ lock_super(s);
+ if (!fs_type->read_super(s, data, 0))
+ goto out_fail;
+ unlock_super(s);
+ return s;
+
+ out_fail:
+ s->s_dev = 0;
+ s->s_bdev = 0;
+ s->s_type = NULL;
+ unlock_super(s);
+ atomic_dec(&s->s_active);
+ spin_lock(&sb_lock);
+ list_del(&s->s_list);
+ list_del(&s->s_instances);
+ spin_unlock(&sb_lock);
+ put_super(s);
+ put_unnamed_dev(dev);
+ up(&mount_sem);
+ return ERR_PTR(-EINVAL);
+ }
}
static void kill_super(struct super_block *sb)
next prev parent reply other threads:[~2001-08-13 1:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-11 4:17 Linux-2.4.8 Linus Torvalds
2001-08-13 1:25 ` [PATCH] fs/super.c fixes - second series (1/11) Alexander Viro
2001-08-13 1:26 ` [PATCH] fs/super.c fixes - second series (2/11) Alexander Viro
2001-08-13 1:26 ` [PATCH] fs/super.c fixes - second series (3/11) Alexander Viro
2001-08-13 1:27 ` [PATCH] fs/super.c fixes - second series (4/11) Alexander Viro
2001-08-13 1:27 ` [PATCH] fs/super.c fixes - second series (5/11) Alexander Viro
2001-08-13 1:28 ` Alexander Viro [this message]
2001-08-13 1:28 ` [PATCH] fs/super.c fixes - second series (7/11) Alexander Viro
2001-08-13 1:28 ` [PATCH] fs/super.c fixes - second series (8/11) Alexander Viro
2001-08-13 1:29 ` [PATCH] fs/super.c fixes - second series (9/11) Alexander Viro
2001-08-13 1:29 ` [PATCH] fs/super.c fixes - second series (10/11) Alexander Viro
2001-08-13 1:29 ` [PATCH] fs/super.c fixes - second series (11/11) Alexander Viro
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=Pine.GSO.4.21.0108122127560.7092-100000@weyl.math.psu.edu \
--to=viro@math.psu.edu \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@transmeta.com \
/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).