4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * super.c contains code to handle: - mount structures
8 * - filesystem drivers list
10 * - umount system call
13 * GK 2/5/95 - Changed to support mounting the root fs via NFS
15 * Added kerneld support: Jacques Gelinas and Bjorn Ekwall
16 * Added change_root: Werner Almesberger & Hans Lermen, Feb '96
17 * Added options to /proc/mounts:
18 * Torbjörn Lindh (torbjorn.lindh@gopta.se), April 14, 1996.
19 * Added devfs support: Richard Gooch <rgooch@atnf.csiro.au>, 13-JAN-1998
20 * Heavily rewritten for 'one fs - one tree' dcache architecture. AV, Mar 2000
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/acct.h>
26 #include <linux/blkdev.h>
27 #include <linux/mount.h>
28 #include <linux/security.h>
29 #include <linux/writeback.h> /* for the emergency remount stuff */
30 #include <linux/idr.h>
31 #include <linux/mutex.h>
32 #include <linux/backing-dev.h>
33 #include <linux/rculist_bl.h>
37 LIST_HEAD(super_blocks);
38 DEFINE_SPINLOCK(sb_lock);
41 * alloc_super - create new superblock
42 * @type: filesystem type superblock should belong to
44 * Allocates and initializes a new &struct super_block. alloc_super()
45 * returns a pointer new superblock or %NULL if allocation had failed.
47 static struct super_block *alloc_super(struct file_system_type *type)
49 struct super_block *s = kzalloc(sizeof(struct super_block), GFP_USER);
50 static const struct super_operations default_op;
53 if (security_sb_alloc(s)) {
59 s->s_files = alloc_percpu(struct list_head);
68 for_each_possible_cpu(i)
69 INIT_LIST_HEAD(per_cpu_ptr(s->s_files, i));
72 INIT_LIST_HEAD(&s->s_files);
74 s->s_bdi = &default_backing_dev_info;
75 INIT_LIST_HEAD(&s->s_instances);
76 INIT_HLIST_BL_HEAD(&s->s_anon);
77 INIT_LIST_HEAD(&s->s_inodes);
78 INIT_LIST_HEAD(&s->s_dentry_lru);
79 init_rwsem(&s->s_umount);
80 mutex_init(&s->s_lock);
81 lockdep_set_class(&s->s_umount, &type->s_umount_key);
83 * The locking rules for s_lock are up to the
84 * filesystem. For example ext3fs has different
85 * lock ordering than usbfs:
87 lockdep_set_class(&s->s_lock, &type->s_lock_key);
89 * sget() can have s_umount recursion.
91 * When it cannot find a suitable sb, it allocates a new
92 * one (this one), and tries again to find a suitable old
95 * In case that succeeds, it will acquire the s_umount
96 * lock of the old one. Since these are clearly distrinct
97 * locks, and this object isn't exposed yet, there's no
100 * Annotate this by putting this lock in a different
103 down_write_nested(&s->s_umount, SINGLE_DEPTH_NESTING);
105 atomic_set(&s->s_active, 1);
106 mutex_init(&s->s_vfs_rename_mutex);
107 lockdep_set_class(&s->s_vfs_rename_mutex, &type->s_vfs_rename_key);
108 mutex_init(&s->s_dquot.dqio_mutex);
109 mutex_init(&s->s_dquot.dqonoff_mutex);
110 init_rwsem(&s->s_dquot.dqptr_sem);
111 init_waitqueue_head(&s->s_wait_unfrozen);
112 s->s_maxbytes = MAX_NON_LFS;
113 s->s_op = &default_op;
114 s->s_time_gran = 1000000000;
121 * destroy_super - frees a superblock
122 * @s: superblock to free
124 * Frees a superblock.
126 static inline void destroy_super(struct super_block *s)
129 free_percpu(s->s_files);
137 /* Superblock refcounting */
140 * Drop a superblock's refcount. The caller must hold sb_lock.
142 void __put_super(struct super_block *sb)
144 if (!--sb->s_count) {
145 list_del_init(&sb->s_list);
151 * put_super - drop a temporary reference to superblock
152 * @sb: superblock in question
154 * Drops a temporary reference, frees superblock if there's no
157 void put_super(struct super_block *sb)
161 spin_unlock(&sb_lock);
166 * deactivate_locked_super - drop an active reference to superblock
167 * @s: superblock to deactivate
169 * Drops an active reference to superblock, converting it into a temprory
170 * one if there is no other active references left. In that case we
171 * tell fs driver to shut it down and drop the temporary reference we
174 * Caller holds exclusive lock on superblock; that lock is released.
176 void deactivate_locked_super(struct super_block *s)
178 struct file_system_type *fs = s->s_type;
179 if (atomic_dec_and_test(&s->s_active)) {
182 * We need to call rcu_barrier so all the delayed rcu free
183 * inodes are flushed before we release the fs module.
189 up_write(&s->s_umount);
193 EXPORT_SYMBOL(deactivate_locked_super);
196 * deactivate_super - drop an active reference to superblock
197 * @s: superblock to deactivate
199 * Variant of deactivate_locked_super(), except that superblock is *not*
200 * locked by caller. If we are going to drop the final active reference,
201 * lock will be acquired prior to that.
203 void deactivate_super(struct super_block *s)
205 if (!atomic_add_unless(&s->s_active, -1, 1)) {
206 down_write(&s->s_umount);
207 deactivate_locked_super(s);
211 EXPORT_SYMBOL(deactivate_super);
214 * grab_super - acquire an active reference
215 * @s: reference we are trying to make active
217 * Tries to acquire an active reference. grab_super() is used when we
218 * had just found a superblock in super_blocks or fs_type->fs_supers
219 * and want to turn it into a full-blown active reference. grab_super()
220 * is called with sb_lock held and drops it. Returns 1 in case of
221 * success, 0 if we had failed (superblock contents was already dead or
222 * dying when grab_super() had been called).
224 static int grab_super(struct super_block *s) __releases(sb_lock)
226 if (atomic_inc_not_zero(&s->s_active)) {
227 spin_unlock(&sb_lock);
230 /* it's going away */
232 spin_unlock(&sb_lock);
233 /* wait for it to die */
234 down_write(&s->s_umount);
235 up_write(&s->s_umount);
241 * Superblock locking. We really ought to get rid of these two.
243 void lock_super(struct super_block * sb)
246 mutex_lock(&sb->s_lock);
249 void unlock_super(struct super_block * sb)
252 mutex_unlock(&sb->s_lock);
255 EXPORT_SYMBOL(lock_super);
256 EXPORT_SYMBOL(unlock_super);
259 * generic_shutdown_super - common helper for ->kill_sb()
260 * @sb: superblock to kill
262 * generic_shutdown_super() does all fs-independent work on superblock
263 * shutdown. Typical ->kill_sb() should pick all fs-specific objects
264 * that need destruction out of superblock, call generic_shutdown_super()
265 * and release aforementioned objects. Note: dentries and inodes _are_
266 * taken care of and do not need specific handling.
268 * Upon calling this function, the filesystem may no longer alter or
269 * rearrange the set of dentries belonging to this super_block, nor may it
270 * change the attachments of dentries to inodes.
272 void generic_shutdown_super(struct super_block *sb)
274 const struct super_operations *sop = sb->s_op;
278 shrink_dcache_for_umount(sb);
281 sb->s_flags &= ~MS_ACTIVE;
283 fsnotify_unmount_inodes(&sb->s_inodes);
290 if (!list_empty(&sb->s_inodes)) {
291 printk("VFS: Busy inodes after unmount of %s. "
292 "Self-destruct in 5 seconds. Have a nice day...\n",
298 /* should be initialized for __put_super_and_need_restart() */
299 list_del_init(&sb->s_instances);
300 spin_unlock(&sb_lock);
301 up_write(&sb->s_umount);
304 EXPORT_SYMBOL(generic_shutdown_super);
307 * sget - find or create a superblock
308 * @type: filesystem type superblock should belong to
309 * @test: comparison callback
310 * @set: setup callback
311 * @data: argument to each of them
313 struct super_block *sget(struct file_system_type *type,
314 int (*test)(struct super_block *,void *),
315 int (*set)(struct super_block *,void *),
318 struct super_block *s = NULL;
319 struct super_block *old;
325 list_for_each_entry(old, &type->fs_supers, s_instances) {
326 if (!test(old, data))
328 if (!grab_super(old))
331 up_write(&s->s_umount);
335 down_write(&old->s_umount);
336 if (unlikely(!(old->s_flags & MS_BORN))) {
337 deactivate_locked_super(old);
344 spin_unlock(&sb_lock);
345 s = alloc_super(type);
347 return ERR_PTR(-ENOMEM);
353 spin_unlock(&sb_lock);
354 up_write(&s->s_umount);
359 strlcpy(s->s_id, type->name, sizeof(s->s_id));
360 list_add_tail(&s->s_list, &super_blocks);
361 list_add(&s->s_instances, &type->fs_supers);
362 spin_unlock(&sb_lock);
363 get_filesystem(type);
369 void drop_super(struct super_block *sb)
371 up_read(&sb->s_umount);
375 EXPORT_SYMBOL(drop_super);
378 * sync_supers - helper for periodic superblock writeback
380 * Call the write_super method if present on all dirty superblocks in
381 * the system. This is for the periodic writeback used by most older
382 * filesystems. For data integrity superblock writeback use
383 * sync_filesystems() instead.
385 * Note: check the dirty flag before waiting, so we don't
386 * hold up the sync while mounting a device. (The newly
387 * mounted device won't need syncing.)
389 void sync_supers(void)
391 struct super_block *sb, *p = NULL;
394 list_for_each_entry(sb, &super_blocks, s_list) {
395 if (list_empty(&sb->s_instances))
397 if (sb->s_op->write_super && sb->s_dirt) {
399 spin_unlock(&sb_lock);
401 down_read(&sb->s_umount);
402 if (sb->s_root && sb->s_dirt)
403 sb->s_op->write_super(sb);
404 up_read(&sb->s_umount);
414 spin_unlock(&sb_lock);
418 * iterate_supers - call function for all active superblocks
419 * @f: function to call
420 * @arg: argument to pass to it
422 * Scans the superblock list and calls given function, passing it
423 * locked superblock and given argument.
425 void iterate_supers(void (*f)(struct super_block *, void *), void *arg)
427 struct super_block *sb, *p = NULL;
430 list_for_each_entry(sb, &super_blocks, s_list) {
431 if (list_empty(&sb->s_instances))
434 spin_unlock(&sb_lock);
436 down_read(&sb->s_umount);
439 up_read(&sb->s_umount);
448 spin_unlock(&sb_lock);
452 * get_super - get the superblock of a device
453 * @bdev: device to get the superblock for
455 * Scans the superblock list and finds the superblock of the file system
456 * mounted on the device given. %NULL is returned if no match is found.
459 struct super_block *get_super(struct block_device *bdev)
461 struct super_block *sb;
468 list_for_each_entry(sb, &super_blocks, s_list) {
469 if (list_empty(&sb->s_instances))
471 if (sb->s_bdev == bdev) {
473 spin_unlock(&sb_lock);
474 down_read(&sb->s_umount);
478 up_read(&sb->s_umount);
479 /* nope, got unmounted */
485 spin_unlock(&sb_lock);
489 EXPORT_SYMBOL(get_super);
492 * get_active_super - get an active reference to the superblock of a device
493 * @bdev: device to get the superblock for
495 * Scans the superblock list and finds the superblock of the file system
496 * mounted on the device given. Returns the superblock with an active
497 * reference or %NULL if none was found.
499 struct super_block *get_active_super(struct block_device *bdev)
501 struct super_block *sb;
508 list_for_each_entry(sb, &super_blocks, s_list) {
509 if (list_empty(&sb->s_instances))
511 if (sb->s_bdev == bdev) {
512 if (grab_super(sb)) /* drops sb_lock */
518 spin_unlock(&sb_lock);
522 struct super_block *user_get_super(dev_t dev)
524 struct super_block *sb;
528 list_for_each_entry(sb, &super_blocks, s_list) {
529 if (list_empty(&sb->s_instances))
531 if (sb->s_dev == dev) {
533 spin_unlock(&sb_lock);
534 down_read(&sb->s_umount);
538 up_read(&sb->s_umount);
539 /* nope, got unmounted */
545 spin_unlock(&sb_lock);
550 * do_remount_sb - asks filesystem to change mount options.
551 * @sb: superblock in question
552 * @flags: numeric part of options
553 * @data: the rest of options
554 * @force: whether or not to force the change
556 * Alters the mount options of a mounted file system.
558 int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
563 if (sb->s_frozen != SB_UNFROZEN)
567 if (!(flags & MS_RDONLY) && bdev_read_only(sb->s_bdev))
571 if (flags & MS_RDONLY)
573 shrink_dcache_sb(sb);
576 remount_ro = (flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY);
578 /* If we are remounting RDONLY and current sb is read/write,
579 make sure there are no rw files opened */
583 else if (!fs_may_remount_ro(sb))
587 if (sb->s_op->remount_fs) {
588 retval = sb->s_op->remount_fs(sb, &flags, data);
592 sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK);
595 * Some filesystems modify their metadata via some other path than the
596 * bdev buffer cache (eg. use a private mapping, or directories in
597 * pagecache, etc). Also file data modifications go via their own
598 * mappings. So If we try to mount readonly then copy the filesystem
599 * from bdev, we could get stale data, so invalidate it to give a best
600 * effort at coherency.
602 if (remount_ro && sb->s_bdev)
603 invalidate_bdev(sb->s_bdev);
607 static void do_emergency_remount(struct work_struct *work)
609 struct super_block *sb, *p = NULL;
612 list_for_each_entry(sb, &super_blocks, s_list) {
613 if (list_empty(&sb->s_instances))
616 spin_unlock(&sb_lock);
617 down_write(&sb->s_umount);
618 if (sb->s_root && sb->s_bdev && !(sb->s_flags & MS_RDONLY)) {
620 * What lock protects sb->s_flags??
622 do_remount_sb(sb, MS_RDONLY, NULL, 1);
624 up_write(&sb->s_umount);
632 spin_unlock(&sb_lock);
634 printk("Emergency Remount complete\n");
637 void emergency_remount(void)
639 struct work_struct *work;
641 work = kmalloc(sizeof(*work), GFP_ATOMIC);
643 INIT_WORK(work, do_emergency_remount);
649 * Unnamed block devices are dummy devices used by virtual
650 * filesystems which don't use real block-devices. -- jrs
653 static DEFINE_IDA(unnamed_dev_ida);
654 static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */
655 static int unnamed_dev_start = 0; /* don't bother trying below it */
657 int set_anon_super(struct super_block *s, void *data)
663 if (ida_pre_get(&unnamed_dev_ida, GFP_ATOMIC) == 0)
665 spin_lock(&unnamed_dev_lock);
666 error = ida_get_new_above(&unnamed_dev_ida, unnamed_dev_start, &dev);
668 unnamed_dev_start = dev + 1;
669 spin_unlock(&unnamed_dev_lock);
670 if (error == -EAGAIN)
671 /* We raced and lost with another CPU. */
676 if ((dev & MAX_ID_MASK) == (1 << MINORBITS)) {
677 spin_lock(&unnamed_dev_lock);
678 ida_remove(&unnamed_dev_ida, dev);
679 if (unnamed_dev_start > dev)
680 unnamed_dev_start = dev;
681 spin_unlock(&unnamed_dev_lock);
684 s->s_dev = MKDEV(0, dev & MINORMASK);
685 s->s_bdi = &noop_backing_dev_info;
689 EXPORT_SYMBOL(set_anon_super);
691 void kill_anon_super(struct super_block *sb)
693 int slot = MINOR(sb->s_dev);
695 generic_shutdown_super(sb);
696 spin_lock(&unnamed_dev_lock);
697 ida_remove(&unnamed_dev_ida, slot);
698 if (slot < unnamed_dev_start)
699 unnamed_dev_start = slot;
700 spin_unlock(&unnamed_dev_lock);
703 EXPORT_SYMBOL(kill_anon_super);
705 void kill_litter_super(struct super_block *sb)
708 d_genocide(sb->s_root);
712 EXPORT_SYMBOL(kill_litter_super);
714 static int ns_test_super(struct super_block *sb, void *data)
716 return sb->s_fs_info == data;
719 static int ns_set_super(struct super_block *sb, void *data)
721 sb->s_fs_info = data;
722 return set_anon_super(sb, NULL);
725 struct dentry *mount_ns(struct file_system_type *fs_type, int flags,
726 void *data, int (*fill_super)(struct super_block *, void *, int))
728 struct super_block *sb;
730 sb = sget(fs_type, ns_test_super, ns_set_super, data);
737 err = fill_super(sb, data, flags & MS_SILENT ? 1 : 0);
739 deactivate_locked_super(sb);
743 sb->s_flags |= MS_ACTIVE;
746 return dget(sb->s_root);
749 EXPORT_SYMBOL(mount_ns);
752 static int set_bdev_super(struct super_block *s, void *data)
755 s->s_dev = s->s_bdev->bd_dev;
758 * We set the bdi here to the queue backing, file systems can
759 * overwrite this in ->fill_super()
761 s->s_bdi = &bdev_get_queue(s->s_bdev)->backing_dev_info;
765 static int test_bdev_super(struct super_block *s, void *data)
767 return (void *)s->s_bdev == data;
770 struct dentry *mount_bdev(struct file_system_type *fs_type,
771 int flags, const char *dev_name, void *data,
772 int (*fill_super)(struct super_block *, void *, int))
774 struct block_device *bdev;
775 struct super_block *s;
776 fmode_t mode = FMODE_READ | FMODE_EXCL;
779 if (!(flags & MS_RDONLY))
782 bdev = blkdev_get_by_path(dev_name, mode, fs_type);
784 return ERR_CAST(bdev);
787 * once the super is inserted into the list by sget, s_umount
788 * will protect the lockfs code from trying to start a snapshot
789 * while we are mounting
791 mutex_lock(&bdev->bd_fsfreeze_mutex);
792 if (bdev->bd_fsfreeze_count > 0) {
793 mutex_unlock(&bdev->bd_fsfreeze_mutex);
797 s = sget(fs_type, test_bdev_super, set_bdev_super, bdev);
798 mutex_unlock(&bdev->bd_fsfreeze_mutex);
803 if ((flags ^ s->s_flags) & MS_RDONLY) {
804 deactivate_locked_super(s);
810 * s_umount nests inside bd_mutex during
811 * __invalidate_device(). blkdev_put() acquires
812 * bd_mutex and can't be called under s_umount. Drop
813 * s_umount temporarily. This is safe as we're
814 * holding an active reference.
816 up_write(&s->s_umount);
817 blkdev_put(bdev, mode);
818 down_write(&s->s_umount);
820 char b[BDEVNAME_SIZE];
824 strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
825 sb_set_blocksize(s, block_size(bdev));
826 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
828 deactivate_locked_super(s);
832 s->s_flags |= MS_ACTIVE;
836 return dget(s->s_root);
841 blkdev_put(bdev, mode);
843 return ERR_PTR(error);
845 EXPORT_SYMBOL(mount_bdev);
847 int get_sb_bdev(struct file_system_type *fs_type,
848 int flags, const char *dev_name, void *data,
849 int (*fill_super)(struct super_block *, void *, int),
850 struct vfsmount *mnt)
854 root = mount_bdev(fs_type, flags, dev_name, data, fill_super);
856 return PTR_ERR(root);
857 mnt->mnt_root = root;
858 mnt->mnt_sb = root->d_sb;
862 EXPORT_SYMBOL(get_sb_bdev);
864 void kill_block_super(struct super_block *sb)
866 struct block_device *bdev = sb->s_bdev;
867 fmode_t mode = sb->s_mode;
869 bdev->bd_super = NULL;
870 generic_shutdown_super(sb);
872 WARN_ON_ONCE(!(mode & FMODE_EXCL));
873 blkdev_put(bdev, mode | FMODE_EXCL);
876 EXPORT_SYMBOL(kill_block_super);
879 struct dentry *mount_nodev(struct file_system_type *fs_type,
880 int flags, void *data,
881 int (*fill_super)(struct super_block *, void *, int))
884 struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL);
891 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
893 deactivate_locked_super(s);
894 return ERR_PTR(error);
896 s->s_flags |= MS_ACTIVE;
897 return dget(s->s_root);
899 EXPORT_SYMBOL(mount_nodev);
901 int get_sb_nodev(struct file_system_type *fs_type,
902 int flags, void *data,
903 int (*fill_super)(struct super_block *, void *, int),
904 struct vfsmount *mnt)
908 root = mount_nodev(fs_type, flags, data, fill_super);
910 return PTR_ERR(root);
911 mnt->mnt_root = root;
912 mnt->mnt_sb = root->d_sb;
915 EXPORT_SYMBOL(get_sb_nodev);
917 static int compare_single(struct super_block *s, void *p)
922 struct dentry *mount_single(struct file_system_type *fs_type,
923 int flags, void *data,
924 int (*fill_super)(struct super_block *, void *, int))
926 struct super_block *s;
929 s = sget(fs_type, compare_single, set_anon_super, NULL);
934 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
936 deactivate_locked_super(s);
937 return ERR_PTR(error);
939 s->s_flags |= MS_ACTIVE;
941 do_remount_sb(s, flags, data, 0);
943 return dget(s->s_root);
945 EXPORT_SYMBOL(mount_single);
947 int get_sb_single(struct file_system_type *fs_type,
948 int flags, void *data,
949 int (*fill_super)(struct super_block *, void *, int),
950 struct vfsmount *mnt)
953 root = mount_single(fs_type, flags, data, fill_super);
955 return PTR_ERR(root);
956 mnt->mnt_root = root;
957 mnt->mnt_sb = root->d_sb;
961 EXPORT_SYMBOL(get_sb_single);
964 vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
966 struct vfsmount *mnt;
968 char *secdata = NULL;
972 return ERR_PTR(-ENODEV);
975 mnt = alloc_vfsmnt(name);
979 if (flags & MS_KERNMOUNT)
980 mnt->mnt_flags = MNT_INTERNAL;
982 if (data && !(type->fs_flags & FS_BINARY_MOUNTDATA)) {
983 secdata = alloc_secdata();
987 error = security_sb_copy_data(data, secdata);
989 goto out_free_secdata;
993 root = type->mount(type, flags, name, data);
995 error = PTR_ERR(root);
996 goto out_free_secdata;
998 mnt->mnt_root = root;
999 mnt->mnt_sb = root->d_sb;
1001 error = type->get_sb(type, flags, name, data, mnt);
1003 goto out_free_secdata;
1005 BUG_ON(!mnt->mnt_sb);
1006 WARN_ON(!mnt->mnt_sb->s_bdi);
1007 WARN_ON(mnt->mnt_sb->s_bdi == &default_backing_dev_info);
1008 mnt->mnt_sb->s_flags |= MS_BORN;
1010 error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata);
1015 * filesystems should never set s_maxbytes larger than MAX_LFS_FILESIZE
1016 * but s_maxbytes was an unsigned long long for many releases. Throw
1017 * this warning for a little while to try and catch filesystems that
1018 * violate this rule. This warning should be either removed or
1019 * converted to a BUG() in 2.6.34.
1021 WARN((mnt->mnt_sb->s_maxbytes < 0), "%s set sb->s_maxbytes to "
1022 "negative value (%lld)\n", type->name, mnt->mnt_sb->s_maxbytes);
1024 mnt->mnt_mountpoint = mnt->mnt_root;
1025 mnt->mnt_parent = mnt;
1026 up_write(&mnt->mnt_sb->s_umount);
1027 free_secdata(secdata);
1030 dput(mnt->mnt_root);
1031 deactivate_locked_super(mnt->mnt_sb);
1033 free_secdata(secdata);
1037 return ERR_PTR(error);
1040 EXPORT_SYMBOL_GPL(vfs_kern_mount);
1043 * freeze_super - lock the filesystem and force it into a consistent state
1044 * @sb: the super to lock
1046 * Syncs the super to make sure the filesystem is consistent and calls the fs's
1047 * freeze_fs. Subsequent calls to this without first thawing the fs will return
1050 int freeze_super(struct super_block *sb)
1054 atomic_inc(&sb->s_active);
1055 down_write(&sb->s_umount);
1057 deactivate_locked_super(sb);
1061 if (sb->s_flags & MS_RDONLY) {
1062 sb->s_frozen = SB_FREEZE_TRANS;
1064 up_write(&sb->s_umount);
1068 sb->s_frozen = SB_FREEZE_WRITE;
1071 sync_filesystem(sb);
1073 sb->s_frozen = SB_FREEZE_TRANS;
1076 sync_blockdev(sb->s_bdev);
1077 if (sb->s_op->freeze_fs) {
1078 ret = sb->s_op->freeze_fs(sb);
1081 "VFS:Filesystem freeze failed\n");
1082 sb->s_frozen = SB_UNFROZEN;
1083 deactivate_locked_super(sb);
1087 up_write(&sb->s_umount);
1090 EXPORT_SYMBOL(freeze_super);
1093 * thaw_super -- unlock filesystem
1094 * @sb: the super to thaw
1096 * Unlocks the filesystem and marks it writeable again after freeze_super().
1098 int thaw_super(struct super_block *sb)
1102 down_write(&sb->s_umount);
1103 if (sb->s_frozen == SB_UNFROZEN) {
1104 up_write(&sb->s_umount);
1108 if (sb->s_flags & MS_RDONLY)
1111 if (sb->s_op->unfreeze_fs) {
1112 error = sb->s_op->unfreeze_fs(sb);
1115 "VFS:Filesystem thaw failed\n");
1116 sb->s_frozen = SB_FREEZE_TRANS;
1117 up_write(&sb->s_umount);
1123 sb->s_frozen = SB_UNFROZEN;
1125 wake_up(&sb->s_wait_unfrozen);
1126 deactivate_locked_super(sb);
1130 EXPORT_SYMBOL(thaw_super);
1132 static struct vfsmount *fs_set_subtype(struct vfsmount *mnt, const char *fstype)
1135 const char *subtype = strchr(fstype, '.');
1144 mnt->mnt_sb->s_subtype = kstrdup(subtype, GFP_KERNEL);
1146 if (!mnt->mnt_sb->s_subtype)
1152 return ERR_PTR(err);
1156 do_kern_mount(const char *fstype, int flags, const char *name, void *data)
1158 struct file_system_type *type = get_fs_type(fstype);
1159 struct vfsmount *mnt;
1161 return ERR_PTR(-ENODEV);
1162 mnt = vfs_kern_mount(type, flags, name, data);
1163 if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) &&
1164 !mnt->mnt_sb->s_subtype)
1165 mnt = fs_set_subtype(mnt, fstype);
1166 put_filesystem(type);
1169 EXPORT_SYMBOL_GPL(do_kern_mount);
1171 struct vfsmount *kern_mount_data(struct file_system_type *type, void *data)
1173 return vfs_kern_mount(type, MS_KERNMOUNT, type->name, data);
1176 EXPORT_SYMBOL_GPL(kern_mount_data);