[SCSI] lpfc: Cleanup code in lpfc_get_stats().
[linux-2.6.22.y-op.git] / fs / super.c
blob6e57ee252e14e1cd2982bb865fdebbbe24fb6ef7
1 /*
2 * linux/fs/super.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
6 * super.c contains code to handle: - mount structures
7 * - super-block tables
8 * - filesystem drivers list
9 * - mount system call
10 * - umount system call
11 * - ustat 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/config.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 #include <linux/init.h>
27 #include <linux/smp_lock.h>
28 #include <linux/acct.h>
29 #include <linux/blkdev.h>
30 #include <linux/quotaops.h>
31 #include <linux/namei.h>
32 #include <linux/buffer_head.h> /* for fsync_super() */
33 #include <linux/mount.h>
34 #include <linux/security.h>
35 #include <linux/syscalls.h>
36 #include <linux/vfs.h>
37 #include <linux/writeback.h> /* for the emergency remount stuff */
38 #include <linux/idr.h>
39 #include <linux/kobject.h>
40 #include <asm/uaccess.h>
43 void get_filesystem(struct file_system_type *fs);
44 void put_filesystem(struct file_system_type *fs);
45 struct file_system_type *get_fs_type(const char *name);
47 LIST_HEAD(super_blocks);
48 DEFINE_SPINLOCK(sb_lock);
50 /**
51 * alloc_super - create new superblock
53 * Allocates and initializes a new &struct super_block. alloc_super()
54 * returns a pointer new superblock or %NULL if allocation had failed.
56 static struct super_block *alloc_super(void)
58 struct super_block *s = kmalloc(sizeof(struct super_block), GFP_USER);
59 static struct super_operations default_op;
61 if (s) {
62 memset(s, 0, sizeof(struct super_block));
63 if (security_sb_alloc(s)) {
64 kfree(s);
65 s = NULL;
66 goto out;
68 INIT_LIST_HEAD(&s->s_dirty);
69 INIT_LIST_HEAD(&s->s_io);
70 INIT_LIST_HEAD(&s->s_files);
71 INIT_LIST_HEAD(&s->s_instances);
72 INIT_HLIST_HEAD(&s->s_anon);
73 INIT_LIST_HEAD(&s->s_inodes);
74 init_rwsem(&s->s_umount);
75 sema_init(&s->s_lock, 1);
76 down_write(&s->s_umount);
77 s->s_count = S_BIAS;
78 atomic_set(&s->s_active, 1);
79 sema_init(&s->s_vfs_rename_sem,1);
80 sema_init(&s->s_dquot.dqio_sem, 1);
81 sema_init(&s->s_dquot.dqonoff_sem, 1);
82 init_rwsem(&s->s_dquot.dqptr_sem);
83 init_waitqueue_head(&s->s_wait_unfrozen);
84 s->s_maxbytes = MAX_NON_LFS;
85 s->dq_op = sb_dquot_ops;
86 s->s_qcop = sb_quotactl_ops;
87 s->s_op = &default_op;
88 s->s_time_gran = 1000000000;
90 out:
91 return s;
94 /**
95 * destroy_super - frees a superblock
96 * @s: superblock to free
98 * Frees a superblock.
100 static inline void destroy_super(struct super_block *s)
102 security_sb_free(s);
103 kfree(s);
106 /* Superblock refcounting */
109 * Drop a superblock's refcount. Returns non-zero if the superblock was
110 * destroyed. The caller must hold sb_lock.
112 int __put_super(struct super_block *sb)
114 int ret = 0;
116 if (!--sb->s_count) {
117 destroy_super(sb);
118 ret = 1;
120 return ret;
124 * Drop a superblock's refcount.
125 * Returns non-zero if the superblock is about to be destroyed and
126 * at least is already removed from super_blocks list, so if we are
127 * making a loop through super blocks then we need to restart.
128 * The caller must hold sb_lock.
130 int __put_super_and_need_restart(struct super_block *sb)
132 /* check for race with generic_shutdown_super() */
133 if (list_empty(&sb->s_list)) {
134 /* super block is removed, need to restart... */
135 __put_super(sb);
136 return 1;
138 /* can't be the last, since s_list is still in use */
139 sb->s_count--;
140 BUG_ON(sb->s_count == 0);
141 return 0;
145 * put_super - drop a temporary reference to superblock
146 * @sb: superblock in question
148 * Drops a temporary reference, frees superblock if there's no
149 * references left.
151 static void put_super(struct super_block *sb)
153 spin_lock(&sb_lock);
154 __put_super(sb);
155 spin_unlock(&sb_lock);
160 * deactivate_super - drop an active reference to superblock
161 * @s: superblock to deactivate
163 * Drops an active reference to superblock, acquiring a temprory one if
164 * there is no active references left. In that case we lock superblock,
165 * tell fs driver to shut it down and drop the temporary reference we
166 * had just acquired.
168 void deactivate_super(struct super_block *s)
170 struct file_system_type *fs = s->s_type;
171 if (atomic_dec_and_lock(&s->s_active, &sb_lock)) {
172 s->s_count -= S_BIAS-1;
173 spin_unlock(&sb_lock);
174 down_write(&s->s_umount);
175 fs->kill_sb(s);
176 put_filesystem(fs);
177 put_super(s);
181 EXPORT_SYMBOL(deactivate_super);
184 * grab_super - acquire an active reference
185 * @s: reference we are trying to make active
187 * Tries to acquire an active reference. grab_super() is used when we
188 * had just found a superblock in super_blocks or fs_type->fs_supers
189 * and want to turn it into a full-blown active reference. grab_super()
190 * is called with sb_lock held and drops it. Returns 1 in case of
191 * success, 0 if we had failed (superblock contents was already dead or
192 * dying when grab_super() had been called).
194 static int grab_super(struct super_block *s)
196 s->s_count++;
197 spin_unlock(&sb_lock);
198 down_write(&s->s_umount);
199 if (s->s_root) {
200 spin_lock(&sb_lock);
201 if (s->s_count > S_BIAS) {
202 atomic_inc(&s->s_active);
203 s->s_count--;
204 spin_unlock(&sb_lock);
205 return 1;
207 spin_unlock(&sb_lock);
209 up_write(&s->s_umount);
210 put_super(s);
211 yield();
212 return 0;
216 * generic_shutdown_super - common helper for ->kill_sb()
217 * @sb: superblock to kill
219 * generic_shutdown_super() does all fs-independent work on superblock
220 * shutdown. Typical ->kill_sb() should pick all fs-specific objects
221 * that need destruction out of superblock, call generic_shutdown_super()
222 * and release aforementioned objects. Note: dentries and inodes _are_
223 * taken care of and do not need specific handling.
225 void generic_shutdown_super(struct super_block *sb)
227 struct dentry *root = sb->s_root;
228 struct super_operations *sop = sb->s_op;
230 if (root) {
231 sb->s_root = NULL;
232 shrink_dcache_parent(root);
233 shrink_dcache_anon(&sb->s_anon);
234 dput(root);
235 fsync_super(sb);
236 lock_super(sb);
237 sb->s_flags &= ~MS_ACTIVE;
238 /* bad name - it should be evict_inodes() */
239 invalidate_inodes(sb);
240 lock_kernel();
242 if (sop->write_super && sb->s_dirt)
243 sop->write_super(sb);
244 if (sop->put_super)
245 sop->put_super(sb);
247 /* Forget any remaining inodes */
248 if (invalidate_inodes(sb)) {
249 printk("VFS: Busy inodes after unmount. "
250 "Self-destruct in 5 seconds. Have a nice day...\n");
253 unlock_kernel();
254 unlock_super(sb);
256 spin_lock(&sb_lock);
257 /* should be initialized for __put_super_and_need_restart() */
258 list_del_init(&sb->s_list);
259 list_del(&sb->s_instances);
260 spin_unlock(&sb_lock);
261 up_write(&sb->s_umount);
264 EXPORT_SYMBOL(generic_shutdown_super);
267 * sget - find or create a superblock
268 * @type: filesystem type superblock should belong to
269 * @test: comparison callback
270 * @set: setup callback
271 * @data: argument to each of them
273 struct super_block *sget(struct file_system_type *type,
274 int (*test)(struct super_block *,void *),
275 int (*set)(struct super_block *,void *),
276 void *data)
278 struct super_block *s = NULL;
279 struct list_head *p;
280 int err;
282 retry:
283 spin_lock(&sb_lock);
284 if (test) list_for_each(p, &type->fs_supers) {
285 struct super_block *old;
286 old = list_entry(p, struct super_block, s_instances);
287 if (!test(old, data))
288 continue;
289 if (!grab_super(old))
290 goto retry;
291 if (s)
292 destroy_super(s);
293 return old;
295 if (!s) {
296 spin_unlock(&sb_lock);
297 s = alloc_super();
298 if (!s)
299 return ERR_PTR(-ENOMEM);
300 goto retry;
303 err = set(s, data);
304 if (err) {
305 spin_unlock(&sb_lock);
306 destroy_super(s);
307 return ERR_PTR(err);
309 s->s_type = type;
310 strlcpy(s->s_id, type->name, sizeof(s->s_id));
311 list_add_tail(&s->s_list, &super_blocks);
312 list_add(&s->s_instances, &type->fs_supers);
313 spin_unlock(&sb_lock);
314 get_filesystem(type);
315 return s;
318 EXPORT_SYMBOL(sget);
320 void drop_super(struct super_block *sb)
322 up_read(&sb->s_umount);
323 put_super(sb);
326 EXPORT_SYMBOL(drop_super);
328 static inline void write_super(struct super_block *sb)
330 lock_super(sb);
331 if (sb->s_root && sb->s_dirt)
332 if (sb->s_op->write_super)
333 sb->s_op->write_super(sb);
334 unlock_super(sb);
338 * Note: check the dirty flag before waiting, so we don't
339 * hold up the sync while mounting a device. (The newly
340 * mounted device won't need syncing.)
342 void sync_supers(void)
344 struct super_block *sb;
346 spin_lock(&sb_lock);
347 restart:
348 list_for_each_entry(sb, &super_blocks, s_list) {
349 if (sb->s_dirt) {
350 sb->s_count++;
351 spin_unlock(&sb_lock);
352 down_read(&sb->s_umount);
353 write_super(sb);
354 up_read(&sb->s_umount);
355 spin_lock(&sb_lock);
356 if (__put_super_and_need_restart(sb))
357 goto restart;
360 spin_unlock(&sb_lock);
364 * Call the ->sync_fs super_op against all filesytems which are r/w and
365 * which implement it.
367 * This operation is careful to avoid the livelock which could easily happen
368 * if two or more filesystems are being continuously dirtied. s_need_sync_fs
369 * is used only here. We set it against all filesystems and then clear it as
370 * we sync them. So redirtied filesystems are skipped.
372 * But if process A is currently running sync_filesytems and then process B
373 * calls sync_filesystems as well, process B will set all the s_need_sync_fs
374 * flags again, which will cause process A to resync everything. Fix that with
375 * a local mutex.
377 * (Fabian) Avoid sync_fs with clean fs & wait mode 0
379 void sync_filesystems(int wait)
381 struct super_block *sb;
382 static DECLARE_MUTEX(mutex);
384 down(&mutex); /* Could be down_interruptible */
385 spin_lock(&sb_lock);
386 list_for_each_entry(sb, &super_blocks, s_list) {
387 if (!sb->s_op->sync_fs)
388 continue;
389 if (sb->s_flags & MS_RDONLY)
390 continue;
391 sb->s_need_sync_fs = 1;
394 restart:
395 list_for_each_entry(sb, &super_blocks, s_list) {
396 if (!sb->s_need_sync_fs)
397 continue;
398 sb->s_need_sync_fs = 0;
399 if (sb->s_flags & MS_RDONLY)
400 continue; /* hm. Was remounted r/o meanwhile */
401 sb->s_count++;
402 spin_unlock(&sb_lock);
403 down_read(&sb->s_umount);
404 if (sb->s_root && (wait || sb->s_dirt))
405 sb->s_op->sync_fs(sb, wait);
406 up_read(&sb->s_umount);
407 /* restart only when sb is no longer on the list */
408 spin_lock(&sb_lock);
409 if (__put_super_and_need_restart(sb))
410 goto restart;
412 spin_unlock(&sb_lock);
413 up(&mutex);
417 * get_super - get the superblock of a device
418 * @bdev: device to get the superblock for
420 * Scans the superblock list and finds the superblock of the file system
421 * mounted on the device given. %NULL is returned if no match is found.
424 struct super_block * get_super(struct block_device *bdev)
426 struct super_block *sb;
428 if (!bdev)
429 return NULL;
431 spin_lock(&sb_lock);
432 rescan:
433 list_for_each_entry(sb, &super_blocks, s_list) {
434 if (sb->s_bdev == bdev) {
435 sb->s_count++;
436 spin_unlock(&sb_lock);
437 down_read(&sb->s_umount);
438 if (sb->s_root)
439 return sb;
440 up_read(&sb->s_umount);
441 /* restart only when sb is no longer on the list */
442 spin_lock(&sb_lock);
443 if (__put_super_and_need_restart(sb))
444 goto rescan;
447 spin_unlock(&sb_lock);
448 return NULL;
451 EXPORT_SYMBOL(get_super);
453 struct super_block * user_get_super(dev_t dev)
455 struct super_block *sb;
457 spin_lock(&sb_lock);
458 rescan:
459 list_for_each_entry(sb, &super_blocks, s_list) {
460 if (sb->s_dev == dev) {
461 sb->s_count++;
462 spin_unlock(&sb_lock);
463 down_read(&sb->s_umount);
464 if (sb->s_root)
465 return sb;
466 up_read(&sb->s_umount);
467 /* restart only when sb is no longer on the list */
468 spin_lock(&sb_lock);
469 if (__put_super_and_need_restart(sb))
470 goto rescan;
473 spin_unlock(&sb_lock);
474 return NULL;
477 EXPORT_SYMBOL(user_get_super);
479 asmlinkage long sys_ustat(unsigned dev, struct ustat __user * ubuf)
481 struct super_block *s;
482 struct ustat tmp;
483 struct kstatfs sbuf;
484 int err = -EINVAL;
486 s = user_get_super(new_decode_dev(dev));
487 if (s == NULL)
488 goto out;
489 err = vfs_statfs(s, &sbuf);
490 drop_super(s);
491 if (err)
492 goto out;
494 memset(&tmp,0,sizeof(struct ustat));
495 tmp.f_tfree = sbuf.f_bfree;
496 tmp.f_tinode = sbuf.f_ffree;
498 err = copy_to_user(ubuf,&tmp,sizeof(struct ustat)) ? -EFAULT : 0;
499 out:
500 return err;
504 * mark_files_ro
505 * @sb: superblock in question
507 * All files are marked read/only. We don't care about pending
508 * delete files so this should be used in 'force' mode only
511 static void mark_files_ro(struct super_block *sb)
513 struct file *f;
515 file_list_lock();
516 list_for_each_entry(f, &sb->s_files, f_list) {
517 if (S_ISREG(f->f_dentry->d_inode->i_mode) && file_count(f))
518 f->f_mode &= ~FMODE_WRITE;
520 file_list_unlock();
524 * do_remount_sb - asks filesystem to change mount options.
525 * @sb: superblock in question
526 * @flags: numeric part of options
527 * @data: the rest of options
528 * @force: whether or not to force the change
530 * Alters the mount options of a mounted file system.
532 int do_remount_sb(struct super_block *sb, int flags, void *data, int force)
534 int retval;
536 if (!(flags & MS_RDONLY) && bdev_read_only(sb->s_bdev))
537 return -EACCES;
538 if (flags & MS_RDONLY)
539 acct_auto_close(sb);
540 shrink_dcache_sb(sb);
541 fsync_super(sb);
543 /* If we are remounting RDONLY and current sb is read/write,
544 make sure there are no rw files opened */
545 if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) {
546 if (force)
547 mark_files_ro(sb);
548 else if (!fs_may_remount_ro(sb))
549 return -EBUSY;
552 if (sb->s_op->remount_fs) {
553 lock_super(sb);
554 retval = sb->s_op->remount_fs(sb, &flags, data);
555 unlock_super(sb);
556 if (retval)
557 return retval;
559 sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK);
560 return 0;
563 static void do_emergency_remount(unsigned long foo)
565 struct super_block *sb;
567 spin_lock(&sb_lock);
568 list_for_each_entry(sb, &super_blocks, s_list) {
569 sb->s_count++;
570 spin_unlock(&sb_lock);
571 down_read(&sb->s_umount);
572 if (sb->s_root && sb->s_bdev && !(sb->s_flags & MS_RDONLY)) {
574 * ->remount_fs needs lock_kernel().
576 * What lock protects sb->s_flags??
578 lock_kernel();
579 do_remount_sb(sb, MS_RDONLY, NULL, 1);
580 unlock_kernel();
582 drop_super(sb);
583 spin_lock(&sb_lock);
585 spin_unlock(&sb_lock);
586 printk("Emergency Remount complete\n");
589 void emergency_remount(void)
591 pdflush_operation(do_emergency_remount, 0);
595 * Unnamed block devices are dummy devices used by virtual
596 * filesystems which don't use real block-devices. -- jrs
599 static struct idr unnamed_dev_idr;
600 static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */
602 int set_anon_super(struct super_block *s, void *data)
604 int dev;
605 int error;
607 retry:
608 if (idr_pre_get(&unnamed_dev_idr, GFP_ATOMIC) == 0)
609 return -ENOMEM;
610 spin_lock(&unnamed_dev_lock);
611 error = idr_get_new(&unnamed_dev_idr, NULL, &dev);
612 spin_unlock(&unnamed_dev_lock);
613 if (error == -EAGAIN)
614 /* We raced and lost with another CPU. */
615 goto retry;
616 else if (error)
617 return -EAGAIN;
619 if ((dev & MAX_ID_MASK) == (1 << MINORBITS)) {
620 spin_lock(&unnamed_dev_lock);
621 idr_remove(&unnamed_dev_idr, dev);
622 spin_unlock(&unnamed_dev_lock);
623 return -EMFILE;
625 s->s_dev = MKDEV(0, dev & MINORMASK);
626 return 0;
629 EXPORT_SYMBOL(set_anon_super);
631 void kill_anon_super(struct super_block *sb)
633 int slot = MINOR(sb->s_dev);
635 generic_shutdown_super(sb);
636 spin_lock(&unnamed_dev_lock);
637 idr_remove(&unnamed_dev_idr, slot);
638 spin_unlock(&unnamed_dev_lock);
641 EXPORT_SYMBOL(kill_anon_super);
643 void __init unnamed_dev_init(void)
645 idr_init(&unnamed_dev_idr);
648 void kill_litter_super(struct super_block *sb)
650 if (sb->s_root)
651 d_genocide(sb->s_root);
652 kill_anon_super(sb);
655 EXPORT_SYMBOL(kill_litter_super);
657 static int set_bdev_super(struct super_block *s, void *data)
659 s->s_bdev = data;
660 s->s_dev = s->s_bdev->bd_dev;
661 return 0;
664 static int test_bdev_super(struct super_block *s, void *data)
666 return (void *)s->s_bdev == data;
669 static void bdev_uevent(struct block_device *bdev, enum kobject_action action)
671 if (bdev->bd_disk) {
672 if (bdev->bd_part)
673 kobject_uevent(&bdev->bd_part->kobj, action, NULL);
674 else
675 kobject_uevent(&bdev->bd_disk->kobj, action, NULL);
679 struct super_block *get_sb_bdev(struct file_system_type *fs_type,
680 int flags, const char *dev_name, void *data,
681 int (*fill_super)(struct super_block *, void *, int))
683 struct block_device *bdev;
684 struct super_block *s;
685 int error = 0;
687 bdev = open_bdev_excl(dev_name, flags, fs_type);
688 if (IS_ERR(bdev))
689 return (struct super_block *)bdev;
692 * once the super is inserted into the list by sget, s_umount
693 * will protect the lockfs code from trying to start a snapshot
694 * while we are mounting
696 down(&bdev->bd_mount_sem);
697 s = sget(fs_type, test_bdev_super, set_bdev_super, bdev);
698 up(&bdev->bd_mount_sem);
699 if (IS_ERR(s))
700 goto out;
702 if (s->s_root) {
703 if ((flags ^ s->s_flags) & MS_RDONLY) {
704 up_write(&s->s_umount);
705 deactivate_super(s);
706 s = ERR_PTR(-EBUSY);
708 goto out;
709 } else {
710 char b[BDEVNAME_SIZE];
712 s->s_flags = flags;
713 strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id));
714 s->s_old_blocksize = block_size(bdev);
715 sb_set_blocksize(s, s->s_old_blocksize);
716 error = fill_super(s, data, flags & MS_VERBOSE ? 1 : 0);
717 if (error) {
718 up_write(&s->s_umount);
719 deactivate_super(s);
720 s = ERR_PTR(error);
721 } else {
722 s->s_flags |= MS_ACTIVE;
723 bdev_uevent(bdev, KOBJ_MOUNT);
727 return s;
729 out:
730 close_bdev_excl(bdev);
731 return s;
734 EXPORT_SYMBOL(get_sb_bdev);
736 void kill_block_super(struct super_block *sb)
738 struct block_device *bdev = sb->s_bdev;
740 bdev_uevent(bdev, KOBJ_UMOUNT);
741 generic_shutdown_super(sb);
742 sync_blockdev(bdev);
743 close_bdev_excl(bdev);
746 EXPORT_SYMBOL(kill_block_super);
748 struct super_block *get_sb_nodev(struct file_system_type *fs_type,
749 int flags, void *data,
750 int (*fill_super)(struct super_block *, void *, int))
752 int error;
753 struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL);
755 if (IS_ERR(s))
756 return s;
758 s->s_flags = flags;
760 error = fill_super(s, data, flags & MS_VERBOSE ? 1 : 0);
761 if (error) {
762 up_write(&s->s_umount);
763 deactivate_super(s);
764 return ERR_PTR(error);
766 s->s_flags |= MS_ACTIVE;
767 return s;
770 EXPORT_SYMBOL(get_sb_nodev);
772 static int compare_single(struct super_block *s, void *p)
774 return 1;
777 struct super_block *get_sb_single(struct file_system_type *fs_type,
778 int flags, void *data,
779 int (*fill_super)(struct super_block *, void *, int))
781 struct super_block *s;
782 int error;
784 s = sget(fs_type, compare_single, set_anon_super, NULL);
785 if (IS_ERR(s))
786 return s;
787 if (!s->s_root) {
788 s->s_flags = flags;
789 error = fill_super(s, data, flags & MS_VERBOSE ? 1 : 0);
790 if (error) {
791 up_write(&s->s_umount);
792 deactivate_super(s);
793 return ERR_PTR(error);
795 s->s_flags |= MS_ACTIVE;
797 do_remount_sb(s, flags, data, 0);
798 return s;
801 EXPORT_SYMBOL(get_sb_single);
803 struct vfsmount *
804 do_kern_mount(const char *fstype, int flags, const char *name, void *data)
806 struct file_system_type *type = get_fs_type(fstype);
807 struct super_block *sb = ERR_PTR(-ENOMEM);
808 struct vfsmount *mnt;
809 int error;
810 char *secdata = NULL;
812 if (!type)
813 return ERR_PTR(-ENODEV);
815 mnt = alloc_vfsmnt(name);
816 if (!mnt)
817 goto out;
819 if (data) {
820 secdata = alloc_secdata();
821 if (!secdata) {
822 sb = ERR_PTR(-ENOMEM);
823 goto out_mnt;
826 error = security_sb_copy_data(type, data, secdata);
827 if (error) {
828 sb = ERR_PTR(error);
829 goto out_free_secdata;
833 sb = type->get_sb(type, flags, name, data);
834 if (IS_ERR(sb))
835 goto out_free_secdata;
836 error = security_sb_kern_mount(sb, secdata);
837 if (error)
838 goto out_sb;
839 mnt->mnt_sb = sb;
840 mnt->mnt_root = dget(sb->s_root);
841 mnt->mnt_mountpoint = sb->s_root;
842 mnt->mnt_parent = mnt;
843 up_write(&sb->s_umount);
844 free_secdata(secdata);
845 put_filesystem(type);
846 return mnt;
847 out_sb:
848 up_write(&sb->s_umount);
849 deactivate_super(sb);
850 sb = ERR_PTR(error);
851 out_free_secdata:
852 free_secdata(secdata);
853 out_mnt:
854 free_vfsmnt(mnt);
855 out:
856 put_filesystem(type);
857 return (struct vfsmount *)sb;
860 EXPORT_SYMBOL_GPL(do_kern_mount);
862 struct vfsmount *kern_mount(struct file_system_type *type)
864 return do_kern_mount(type->name, 0, type->name, NULL);
867 EXPORT_SYMBOL(kern_mount);