aboutsummaryrefslogtreecommitdiffstats
path: root/fs/super.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/super.c')
-rw-r--r--fs/super.c46
1 files changed, 34 insertions, 12 deletions
diff --git a/fs/super.c b/fs/super.c
index 786fe7d72790..a9dc4c33ef4d 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -208,6 +208,34 @@ void deactivate_super(struct super_block *s)
208EXPORT_SYMBOL(deactivate_super); 208EXPORT_SYMBOL(deactivate_super);
209 209
210/** 210/**
211 * deactivate_locked_super - drop an active reference to superblock
212 * @s: superblock to deactivate
213 *
214 * Equivalent of up_write(&s->s_umount); deactivate_super(s);, except that
215 * it does not unlock it until it's all over. As the result, it's safe to
216 * use to dispose of new superblock on ->get_sb() failure exits - nobody
217 * will see the sucker until it's all over. Equivalent using up_write +
218 * deactivate_super is safe for that purpose only if superblock is either
219 * safe to use or has NULL ->s_root when we unlock.
220 */
221void deactivate_locked_super(struct super_block *s)
222{
223 struct file_system_type *fs = s->s_type;
224 if (atomic_dec_and_lock(&s->s_active, &sb_lock)) {
225 s->s_count -= S_BIAS-1;
226 spin_unlock(&sb_lock);
227 vfs_dq_off(s, 0);
228 fs->kill_sb(s);
229 put_filesystem(fs);
230 put_super(s);
231 } else {
232 up_write(&s->s_umount);
233 }
234}
235
236EXPORT_SYMBOL(deactivate_locked_super);
237
238/**
211 * grab_super - acquire an active reference 239 * grab_super - acquire an active reference
212 * @s: reference we are trying to make active 240 * @s: reference we are trying to make active
213 * 241 *
@@ -797,8 +825,7 @@ int get_sb_ns(struct file_system_type *fs_type, int flags, void *data,
797 sb->s_flags = flags; 825 sb->s_flags = flags;
798 err = fill_super(sb, data, flags & MS_SILENT ? 1 : 0); 826 err = fill_super(sb, data, flags & MS_SILENT ? 1 : 0);
799 if (err) { 827 if (err) {
800 up_write(&sb->s_umount); 828 deactivate_locked_super(sb);
801 deactivate_super(sb);
802 return err; 829 return err;
803 } 830 }
804 831
@@ -854,8 +881,7 @@ int get_sb_bdev(struct file_system_type *fs_type,
854 881
855 if (s->s_root) { 882 if (s->s_root) {
856 if ((flags ^ s->s_flags) & MS_RDONLY) { 883 if ((flags ^ s->s_flags) & MS_RDONLY) {
857 up_write(&s->s_umount); 884 deactivate_locked_super(s);
858 deactivate_super(s);
859 error = -EBUSY; 885 error = -EBUSY;
860 goto error_bdev; 886 goto error_bdev;
861 } 887 }
@@ -870,8 +896,7 @@ int get_sb_bdev(struct file_system_type *fs_type,
870 sb_set_blocksize(s, block_size(bdev)); 896 sb_set_blocksize(s, block_size(bdev));
871 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); 897 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
872 if (error) { 898 if (error) {
873 up_write(&s->s_umount); 899 deactivate_locked_super(s);
874 deactivate_super(s);
875 goto error; 900 goto error;
876 } 901 }
877 902
@@ -921,8 +946,7 @@ int get_sb_nodev(struct file_system_type *fs_type,
921 946
922 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); 947 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
923 if (error) { 948 if (error) {
924 up_write(&s->s_umount); 949 deactivate_locked_super(s);
925 deactivate_super(s);
926 return error; 950 return error;
927 } 951 }
928 s->s_flags |= MS_ACTIVE; 952 s->s_flags |= MS_ACTIVE;
@@ -952,8 +976,7 @@ int get_sb_single(struct file_system_type *fs_type,
952 s->s_flags = flags; 976 s->s_flags = flags;
953 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); 977 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
954 if (error) { 978 if (error) {
955 up_write(&s->s_umount); 979 deactivate_locked_super(s);
956 deactivate_super(s);
957 return error; 980 return error;
958 } 981 }
959 s->s_flags |= MS_ACTIVE; 982 s->s_flags |= MS_ACTIVE;
@@ -1006,8 +1029,7 @@ vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void
1006 return mnt; 1029 return mnt;
1007out_sb: 1030out_sb:
1008 dput(mnt->mnt_root); 1031 dput(mnt->mnt_root);
1009 up_write(&mnt->mnt_sb->s_umount); 1032 deactivate_locked_super(mnt->mnt_sb);
1010 deactivate_super(mnt->mnt_sb);
1011out_free_secdata: 1033out_free_secdata:
1012 free_secdata(secdata); 1034 free_secdata(secdata);
1013out_mnt: 1035out_mnt: