Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/super.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | * |
| 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 |
| 12 | * |
| 13 | * GK 2/5/95 - Changed to support mounting the root fs via NFS |
| 14 | * |
| 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 |
| 21 | */ |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/slab.h> |
| 25 | #include <linux/init.h> |
| 26 | #include <linux/smp_lock.h> |
| 27 | #include <linux/acct.h> |
| 28 | #include <linux/blkdev.h> |
| 29 | #include <linux/quotaops.h> |
| 30 | #include <linux/namei.h> |
| 31 | #include <linux/buffer_head.h> /* for fsync_super() */ |
| 32 | #include <linux/mount.h> |
| 33 | #include <linux/security.h> |
| 34 | #include <linux/syscalls.h> |
| 35 | #include <linux/vfs.h> |
| 36 | #include <linux/writeback.h> /* for the emergency remount stuff */ |
| 37 | #include <linux/idr.h> |
| 38 | #include <linux/kobject.h> |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 39 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #include <asm/uaccess.h> |
| 41 | |
| 42 | |
| 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); |
| 46 | |
| 47 | LIST_HEAD(super_blocks); |
| 48 | DEFINE_SPINLOCK(sb_lock); |
| 49 | |
| 50 | /** |
| 51 | * alloc_super - create new superblock |
Henrik Kretzschmar | fe2bbc4 | 2006-09-06 00:03:41 -0700 | [diff] [blame] | 52 | * @type: filesystem type superblock should belong to |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | * |
| 54 | * Allocates and initializes a new &struct super_block. alloc_super() |
| 55 | * returns a pointer new superblock or %NULL if allocation had failed. |
| 56 | */ |
Ingo Molnar | cf51624 | 2006-07-03 00:25:27 -0700 | [diff] [blame] | 57 | static struct super_block *alloc_super(struct file_system_type *type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | { |
Oliver Neukum | 11b0b5a | 2006-03-25 03:08:13 -0800 | [diff] [blame] | 59 | struct super_block *s = kzalloc(sizeof(struct super_block), GFP_USER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static struct super_operations default_op; |
| 61 | |
| 62 | if (s) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | if (security_sb_alloc(s)) { |
| 64 | kfree(s); |
| 65 | s = NULL; |
| 66 | goto out; |
| 67 | } |
| 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); |
Ingo Molnar | 7892f2f | 2006-01-09 15:59:25 -0800 | [diff] [blame] | 75 | mutex_init(&s->s_lock); |
Arjan van de Ven | 897c6ff | 2006-07-03 00:25:28 -0700 | [diff] [blame] | 76 | lockdep_set_class(&s->s_umount, &type->s_umount_key); |
Ingo Molnar | cf51624 | 2006-07-03 00:25:27 -0700 | [diff] [blame] | 77 | /* |
| 78 | * The locking rules for s_lock are up to the |
| 79 | * filesystem. For example ext3fs has different |
| 80 | * lock ordering than usbfs: |
| 81 | */ |
| 82 | lockdep_set_class(&s->s_lock, &type->s_lock_key); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | down_write(&s->s_umount); |
| 84 | s->s_count = S_BIAS; |
| 85 | atomic_set(&s->s_active, 1); |
Arjan van de Ven | a11f3a0 | 2006-03-23 03:00:33 -0800 | [diff] [blame] | 86 | mutex_init(&s->s_vfs_rename_mutex); |
Ingo Molnar | d3be915 | 2006-03-23 03:00:29 -0800 | [diff] [blame] | 87 | mutex_init(&s->s_dquot.dqio_mutex); |
| 88 | mutex_init(&s->s_dquot.dqonoff_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | init_rwsem(&s->s_dquot.dqptr_sem); |
| 90 | init_waitqueue_head(&s->s_wait_unfrozen); |
| 91 | s->s_maxbytes = MAX_NON_LFS; |
| 92 | s->dq_op = sb_dquot_ops; |
| 93 | s->s_qcop = sb_quotactl_ops; |
| 94 | s->s_op = &default_op; |
| 95 | s->s_time_gran = 1000000000; |
| 96 | } |
| 97 | out: |
| 98 | return s; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * destroy_super - frees a superblock |
| 103 | * @s: superblock to free |
| 104 | * |
| 105 | * Frees a superblock. |
| 106 | */ |
| 107 | static inline void destroy_super(struct super_block *s) |
| 108 | { |
| 109 | security_sb_free(s); |
| 110 | kfree(s); |
| 111 | } |
| 112 | |
| 113 | /* Superblock refcounting */ |
| 114 | |
| 115 | /* |
| 116 | * Drop a superblock's refcount. Returns non-zero if the superblock was |
| 117 | * destroyed. The caller must hold sb_lock. |
| 118 | */ |
| 119 | int __put_super(struct super_block *sb) |
| 120 | { |
| 121 | int ret = 0; |
| 122 | |
| 123 | if (!--sb->s_count) { |
| 124 | destroy_super(sb); |
| 125 | ret = 1; |
| 126 | } |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Drop a superblock's refcount. |
| 132 | * Returns non-zero if the superblock is about to be destroyed and |
| 133 | * at least is already removed from super_blocks list, so if we are |
| 134 | * making a loop through super blocks then we need to restart. |
| 135 | * The caller must hold sb_lock. |
| 136 | */ |
| 137 | int __put_super_and_need_restart(struct super_block *sb) |
| 138 | { |
| 139 | /* check for race with generic_shutdown_super() */ |
| 140 | if (list_empty(&sb->s_list)) { |
| 141 | /* super block is removed, need to restart... */ |
| 142 | __put_super(sb); |
| 143 | return 1; |
| 144 | } |
| 145 | /* can't be the last, since s_list is still in use */ |
| 146 | sb->s_count--; |
| 147 | BUG_ON(sb->s_count == 0); |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * put_super - drop a temporary reference to superblock |
| 153 | * @sb: superblock in question |
| 154 | * |
| 155 | * Drops a temporary reference, frees superblock if there's no |
| 156 | * references left. |
| 157 | */ |
| 158 | static void put_super(struct super_block *sb) |
| 159 | { |
| 160 | spin_lock(&sb_lock); |
| 161 | __put_super(sb); |
| 162 | spin_unlock(&sb_lock); |
| 163 | } |
| 164 | |
| 165 | |
| 166 | /** |
| 167 | * deactivate_super - drop an active reference to superblock |
| 168 | * @s: superblock to deactivate |
| 169 | * |
| 170 | * Drops an active reference to superblock, acquiring a temprory one if |
| 171 | * there is no active references left. In that case we lock superblock, |
| 172 | * tell fs driver to shut it down and drop the temporary reference we |
| 173 | * had just acquired. |
| 174 | */ |
| 175 | void deactivate_super(struct super_block *s) |
| 176 | { |
| 177 | struct file_system_type *fs = s->s_type; |
| 178 | if (atomic_dec_and_lock(&s->s_active, &sb_lock)) { |
| 179 | s->s_count -= S_BIAS-1; |
| 180 | spin_unlock(&sb_lock); |
Al Viro | 7b7b1ac | 2005-11-07 17:13:39 -0500 | [diff] [blame] | 181 | DQUOT_OFF(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | down_write(&s->s_umount); |
| 183 | fs->kill_sb(s); |
| 184 | put_filesystem(fs); |
| 185 | put_super(s); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | EXPORT_SYMBOL(deactivate_super); |
| 190 | |
| 191 | /** |
| 192 | * grab_super - acquire an active reference |
| 193 | * @s: reference we are trying to make active |
| 194 | * |
| 195 | * Tries to acquire an active reference. grab_super() is used when we |
| 196 | * had just found a superblock in super_blocks or fs_type->fs_supers |
| 197 | * and want to turn it into a full-blown active reference. grab_super() |
| 198 | * is called with sb_lock held and drops it. Returns 1 in case of |
| 199 | * success, 0 if we had failed (superblock contents was already dead or |
| 200 | * dying when grab_super() had been called). |
| 201 | */ |
Josh Triplett | 9c4dbee | 2006-09-29 01:59:29 -0700 | [diff] [blame] | 202 | static int grab_super(struct super_block *s) __releases(sb_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | { |
| 204 | s->s_count++; |
| 205 | spin_unlock(&sb_lock); |
| 206 | down_write(&s->s_umount); |
| 207 | if (s->s_root) { |
| 208 | spin_lock(&sb_lock); |
| 209 | if (s->s_count > S_BIAS) { |
| 210 | atomic_inc(&s->s_active); |
| 211 | s->s_count--; |
| 212 | spin_unlock(&sb_lock); |
| 213 | return 1; |
| 214 | } |
| 215 | spin_unlock(&sb_lock); |
| 216 | } |
| 217 | up_write(&s->s_umount); |
| 218 | put_super(s); |
| 219 | yield(); |
| 220 | return 0; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * generic_shutdown_super - common helper for ->kill_sb() |
| 225 | * @sb: superblock to kill |
| 226 | * |
| 227 | * generic_shutdown_super() does all fs-independent work on superblock |
| 228 | * shutdown. Typical ->kill_sb() should pick all fs-specific objects |
| 229 | * that need destruction out of superblock, call generic_shutdown_super() |
| 230 | * and release aforementioned objects. Note: dentries and inodes _are_ |
| 231 | * taken care of and do not need specific handling. |
| 232 | */ |
| 233 | void generic_shutdown_super(struct super_block *sb) |
| 234 | { |
| 235 | struct dentry *root = sb->s_root; |
| 236 | struct super_operations *sop = sb->s_op; |
| 237 | |
| 238 | if (root) { |
| 239 | sb->s_root = NULL; |
| 240 | shrink_dcache_parent(root); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 241 | shrink_dcache_sb(sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | dput(root); |
| 243 | fsync_super(sb); |
| 244 | lock_super(sb); |
| 245 | sb->s_flags &= ~MS_ACTIVE; |
| 246 | /* bad name - it should be evict_inodes() */ |
| 247 | invalidate_inodes(sb); |
| 248 | lock_kernel(); |
| 249 | |
| 250 | if (sop->write_super && sb->s_dirt) |
| 251 | sop->write_super(sb); |
| 252 | if (sop->put_super) |
| 253 | sop->put_super(sb); |
| 254 | |
| 255 | /* Forget any remaining inodes */ |
| 256 | if (invalidate_inodes(sb)) { |
Dave Jones | 7b4fe29 | 2006-02-07 12:58:48 -0800 | [diff] [blame] | 257 | printk("VFS: Busy inodes after unmount of %s. " |
| 258 | "Self-destruct in 5 seconds. Have a nice day...\n", |
| 259 | sb->s_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | unlock_kernel(); |
| 263 | unlock_super(sb); |
| 264 | } |
| 265 | spin_lock(&sb_lock); |
| 266 | /* should be initialized for __put_super_and_need_restart() */ |
| 267 | list_del_init(&sb->s_list); |
| 268 | list_del(&sb->s_instances); |
| 269 | spin_unlock(&sb_lock); |
| 270 | up_write(&sb->s_umount); |
| 271 | } |
| 272 | |
| 273 | EXPORT_SYMBOL(generic_shutdown_super); |
| 274 | |
| 275 | /** |
| 276 | * sget - find or create a superblock |
| 277 | * @type: filesystem type superblock should belong to |
| 278 | * @test: comparison callback |
| 279 | * @set: setup callback |
| 280 | * @data: argument to each of them |
| 281 | */ |
| 282 | struct super_block *sget(struct file_system_type *type, |
| 283 | int (*test)(struct super_block *,void *), |
| 284 | int (*set)(struct super_block *,void *), |
| 285 | void *data) |
| 286 | { |
| 287 | struct super_block *s = NULL; |
| 288 | struct list_head *p; |
| 289 | int err; |
| 290 | |
| 291 | retry: |
| 292 | spin_lock(&sb_lock); |
| 293 | if (test) list_for_each(p, &type->fs_supers) { |
| 294 | struct super_block *old; |
| 295 | old = list_entry(p, struct super_block, s_instances); |
| 296 | if (!test(old, data)) |
| 297 | continue; |
| 298 | if (!grab_super(old)) |
| 299 | goto retry; |
| 300 | if (s) |
| 301 | destroy_super(s); |
| 302 | return old; |
| 303 | } |
| 304 | if (!s) { |
| 305 | spin_unlock(&sb_lock); |
Ingo Molnar | cf51624 | 2006-07-03 00:25:27 -0700 | [diff] [blame] | 306 | s = alloc_super(type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | if (!s) |
| 308 | return ERR_PTR(-ENOMEM); |
| 309 | goto retry; |
| 310 | } |
| 311 | |
| 312 | err = set(s, data); |
| 313 | if (err) { |
| 314 | spin_unlock(&sb_lock); |
| 315 | destroy_super(s); |
| 316 | return ERR_PTR(err); |
| 317 | } |
| 318 | s->s_type = type; |
| 319 | strlcpy(s->s_id, type->name, sizeof(s->s_id)); |
| 320 | list_add_tail(&s->s_list, &super_blocks); |
| 321 | list_add(&s->s_instances, &type->fs_supers); |
| 322 | spin_unlock(&sb_lock); |
| 323 | get_filesystem(type); |
| 324 | return s; |
| 325 | } |
| 326 | |
| 327 | EXPORT_SYMBOL(sget); |
| 328 | |
| 329 | void drop_super(struct super_block *sb) |
| 330 | { |
| 331 | up_read(&sb->s_umount); |
| 332 | put_super(sb); |
| 333 | } |
| 334 | |
| 335 | EXPORT_SYMBOL(drop_super); |
| 336 | |
| 337 | static inline void write_super(struct super_block *sb) |
| 338 | { |
| 339 | lock_super(sb); |
| 340 | if (sb->s_root && sb->s_dirt) |
| 341 | if (sb->s_op->write_super) |
| 342 | sb->s_op->write_super(sb); |
| 343 | unlock_super(sb); |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Note: check the dirty flag before waiting, so we don't |
| 348 | * hold up the sync while mounting a device. (The newly |
| 349 | * mounted device won't need syncing.) |
| 350 | */ |
| 351 | void sync_supers(void) |
| 352 | { |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 353 | struct super_block *sb; |
| 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | spin_lock(&sb_lock); |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 356 | restart: |
| 357 | list_for_each_entry(sb, &super_blocks, s_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | if (sb->s_dirt) { |
| 359 | sb->s_count++; |
| 360 | spin_unlock(&sb_lock); |
| 361 | down_read(&sb->s_umount); |
| 362 | write_super(sb); |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 363 | up_read(&sb->s_umount); |
| 364 | spin_lock(&sb_lock); |
| 365 | if (__put_super_and_need_restart(sb)) |
| 366 | goto restart; |
| 367 | } |
| 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | spin_unlock(&sb_lock); |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * Call the ->sync_fs super_op against all filesytems which are r/w and |
| 374 | * which implement it. |
| 375 | * |
| 376 | * This operation is careful to avoid the livelock which could easily happen |
| 377 | * if two or more filesystems are being continuously dirtied. s_need_sync_fs |
| 378 | * is used only here. We set it against all filesystems and then clear it as |
| 379 | * we sync them. So redirtied filesystems are skipped. |
| 380 | * |
| 381 | * But if process A is currently running sync_filesytems and then process B |
| 382 | * calls sync_filesystems as well, process B will set all the s_need_sync_fs |
| 383 | * flags again, which will cause process A to resync everything. Fix that with |
| 384 | * a local mutex. |
| 385 | * |
| 386 | * (Fabian) Avoid sync_fs with clean fs & wait mode 0 |
| 387 | */ |
| 388 | void sync_filesystems(int wait) |
| 389 | { |
| 390 | struct super_block *sb; |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 391 | static DEFINE_MUTEX(mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 393 | mutex_lock(&mutex); /* Could be down_interruptible */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | spin_lock(&sb_lock); |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 395 | list_for_each_entry(sb, &super_blocks, s_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | if (!sb->s_op->sync_fs) |
| 397 | continue; |
| 398 | if (sb->s_flags & MS_RDONLY) |
| 399 | continue; |
| 400 | sb->s_need_sync_fs = 1; |
| 401 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | |
| 403 | restart: |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 404 | list_for_each_entry(sb, &super_blocks, s_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | if (!sb->s_need_sync_fs) |
| 406 | continue; |
| 407 | sb->s_need_sync_fs = 0; |
| 408 | if (sb->s_flags & MS_RDONLY) |
| 409 | continue; /* hm. Was remounted r/o meanwhile */ |
| 410 | sb->s_count++; |
| 411 | spin_unlock(&sb_lock); |
| 412 | down_read(&sb->s_umount); |
| 413 | if (sb->s_root && (wait || sb->s_dirt)) |
| 414 | sb->s_op->sync_fs(sb, wait); |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 415 | up_read(&sb->s_umount); |
| 416 | /* restart only when sb is no longer on the list */ |
| 417 | spin_lock(&sb_lock); |
| 418 | if (__put_super_and_need_restart(sb)) |
| 419 | goto restart; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } |
| 421 | spin_unlock(&sb_lock); |
Ingo Molnar | 353ab6e | 2006-03-26 01:37:12 -0800 | [diff] [blame] | 422 | mutex_unlock(&mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | /** |
| 426 | * get_super - get the superblock of a device |
| 427 | * @bdev: device to get the superblock for |
| 428 | * |
| 429 | * Scans the superblock list and finds the superblock of the file system |
| 430 | * mounted on the device given. %NULL is returned if no match is found. |
| 431 | */ |
| 432 | |
| 433 | struct super_block * get_super(struct block_device *bdev) |
| 434 | { |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 435 | struct super_block *sb; |
| 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | if (!bdev) |
| 438 | return NULL; |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 439 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | spin_lock(&sb_lock); |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 441 | rescan: |
| 442 | list_for_each_entry(sb, &super_blocks, s_list) { |
| 443 | if (sb->s_bdev == bdev) { |
| 444 | sb->s_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | spin_unlock(&sb_lock); |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 446 | down_read(&sb->s_umount); |
| 447 | if (sb->s_root) |
| 448 | return sb; |
| 449 | up_read(&sb->s_umount); |
| 450 | /* restart only when sb is no longer on the list */ |
| 451 | spin_lock(&sb_lock); |
| 452 | if (__put_super_and_need_restart(sb)) |
| 453 | goto rescan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | spin_unlock(&sb_lock); |
| 457 | return NULL; |
| 458 | } |
| 459 | |
| 460 | EXPORT_SYMBOL(get_super); |
| 461 | |
| 462 | struct super_block * user_get_super(dev_t dev) |
| 463 | { |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 464 | struct super_block *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | spin_lock(&sb_lock); |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 467 | rescan: |
| 468 | list_for_each_entry(sb, &super_blocks, s_list) { |
| 469 | if (sb->s_dev == dev) { |
| 470 | sb->s_count++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | spin_unlock(&sb_lock); |
Kirill Korotaev | 618f063 | 2005-06-23 00:09:54 -0700 | [diff] [blame] | 472 | down_read(&sb->s_umount); |
| 473 | if (sb->s_root) |
| 474 | return sb; |
| 475 | up_read(&sb->s_umount); |
| 476 | /* restart only when sb is no longer on the list */ |
| 477 | spin_lock(&sb_lock); |
| 478 | if (__put_super_and_need_restart(sb)) |
| 479 | goto rescan; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | } |
| 481 | } |
| 482 | spin_unlock(&sb_lock); |
| 483 | return NULL; |
| 484 | } |
| 485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | asmlinkage long sys_ustat(unsigned dev, struct ustat __user * ubuf) |
| 487 | { |
| 488 | struct super_block *s; |
| 489 | struct ustat tmp; |
| 490 | struct kstatfs sbuf; |
| 491 | int err = -EINVAL; |
| 492 | |
| 493 | s = user_get_super(new_decode_dev(dev)); |
| 494 | if (s == NULL) |
| 495 | goto out; |
David Howells | 726c334 | 2006-06-23 02:02:58 -0700 | [diff] [blame] | 496 | err = vfs_statfs(s->s_root, &sbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | drop_super(s); |
| 498 | if (err) |
| 499 | goto out; |
| 500 | |
| 501 | memset(&tmp,0,sizeof(struct ustat)); |
| 502 | tmp.f_tfree = sbuf.f_bfree; |
| 503 | tmp.f_tinode = sbuf.f_ffree; |
| 504 | |
| 505 | err = copy_to_user(ubuf,&tmp,sizeof(struct ustat)) ? -EFAULT : 0; |
| 506 | out: |
| 507 | return err; |
| 508 | } |
| 509 | |
| 510 | /** |
| 511 | * mark_files_ro |
| 512 | * @sb: superblock in question |
| 513 | * |
| 514 | * All files are marked read/only. We don't care about pending |
| 515 | * delete files so this should be used in 'force' mode only |
| 516 | */ |
| 517 | |
| 518 | static void mark_files_ro(struct super_block *sb) |
| 519 | { |
| 520 | struct file *f; |
| 521 | |
| 522 | file_list_lock(); |
Eric Dumazet | 2f51201 | 2005-10-30 15:02:16 -0800 | [diff] [blame] | 523 | list_for_each_entry(f, &sb->s_files, f_u.fu_list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (S_ISREG(f->f_dentry->d_inode->i_mode) && file_count(f)) |
| 525 | f->f_mode &= ~FMODE_WRITE; |
| 526 | } |
| 527 | file_list_unlock(); |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * do_remount_sb - asks filesystem to change mount options. |
| 532 | * @sb: superblock in question |
| 533 | * @flags: numeric part of options |
| 534 | * @data: the rest of options |
| 535 | * @force: whether or not to force the change |
| 536 | * |
| 537 | * Alters the mount options of a mounted file system. |
| 538 | */ |
| 539 | int do_remount_sb(struct super_block *sb, int flags, void *data, int force) |
| 540 | { |
| 541 | int retval; |
| 542 | |
| 543 | if (!(flags & MS_RDONLY) && bdev_read_only(sb->s_bdev)) |
| 544 | return -EACCES; |
| 545 | if (flags & MS_RDONLY) |
| 546 | acct_auto_close(sb); |
| 547 | shrink_dcache_sb(sb); |
| 548 | fsync_super(sb); |
| 549 | |
| 550 | /* If we are remounting RDONLY and current sb is read/write, |
| 551 | make sure there are no rw files opened */ |
| 552 | if ((flags & MS_RDONLY) && !(sb->s_flags & MS_RDONLY)) { |
| 553 | if (force) |
| 554 | mark_files_ro(sb); |
| 555 | else if (!fs_may_remount_ro(sb)) |
| 556 | return -EBUSY; |
| 557 | } |
| 558 | |
| 559 | if (sb->s_op->remount_fs) { |
| 560 | lock_super(sb); |
| 561 | retval = sb->s_op->remount_fs(sb, &flags, data); |
| 562 | unlock_super(sb); |
| 563 | if (retval) |
| 564 | return retval; |
| 565 | } |
| 566 | sb->s_flags = (sb->s_flags & ~MS_RMT_MASK) | (flags & MS_RMT_MASK); |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | static void do_emergency_remount(unsigned long foo) |
| 571 | { |
| 572 | struct super_block *sb; |
| 573 | |
| 574 | spin_lock(&sb_lock); |
| 575 | list_for_each_entry(sb, &super_blocks, s_list) { |
| 576 | sb->s_count++; |
| 577 | spin_unlock(&sb_lock); |
| 578 | down_read(&sb->s_umount); |
| 579 | if (sb->s_root && sb->s_bdev && !(sb->s_flags & MS_RDONLY)) { |
| 580 | /* |
| 581 | * ->remount_fs needs lock_kernel(). |
| 582 | * |
| 583 | * What lock protects sb->s_flags?? |
| 584 | */ |
| 585 | lock_kernel(); |
| 586 | do_remount_sb(sb, MS_RDONLY, NULL, 1); |
| 587 | unlock_kernel(); |
| 588 | } |
| 589 | drop_super(sb); |
| 590 | spin_lock(&sb_lock); |
| 591 | } |
| 592 | spin_unlock(&sb_lock); |
| 593 | printk("Emergency Remount complete\n"); |
| 594 | } |
| 595 | |
| 596 | void emergency_remount(void) |
| 597 | { |
| 598 | pdflush_operation(do_emergency_remount, 0); |
| 599 | } |
| 600 | |
| 601 | /* |
| 602 | * Unnamed block devices are dummy devices used by virtual |
| 603 | * filesystems which don't use real block-devices. -- jrs |
| 604 | */ |
| 605 | |
| 606 | static struct idr unnamed_dev_idr; |
| 607 | static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */ |
| 608 | |
| 609 | int set_anon_super(struct super_block *s, void *data) |
| 610 | { |
| 611 | int dev; |
| 612 | int error; |
| 613 | |
| 614 | retry: |
| 615 | if (idr_pre_get(&unnamed_dev_idr, GFP_ATOMIC) == 0) |
| 616 | return -ENOMEM; |
| 617 | spin_lock(&unnamed_dev_lock); |
| 618 | error = idr_get_new(&unnamed_dev_idr, NULL, &dev); |
| 619 | spin_unlock(&unnamed_dev_lock); |
| 620 | if (error == -EAGAIN) |
| 621 | /* We raced and lost with another CPU. */ |
| 622 | goto retry; |
| 623 | else if (error) |
| 624 | return -EAGAIN; |
| 625 | |
| 626 | if ((dev & MAX_ID_MASK) == (1 << MINORBITS)) { |
| 627 | spin_lock(&unnamed_dev_lock); |
| 628 | idr_remove(&unnamed_dev_idr, dev); |
| 629 | spin_unlock(&unnamed_dev_lock); |
| 630 | return -EMFILE; |
| 631 | } |
| 632 | s->s_dev = MKDEV(0, dev & MINORMASK); |
| 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | EXPORT_SYMBOL(set_anon_super); |
| 637 | |
| 638 | void kill_anon_super(struct super_block *sb) |
| 639 | { |
| 640 | int slot = MINOR(sb->s_dev); |
| 641 | |
| 642 | generic_shutdown_super(sb); |
| 643 | spin_lock(&unnamed_dev_lock); |
| 644 | idr_remove(&unnamed_dev_idr, slot); |
| 645 | spin_unlock(&unnamed_dev_lock); |
| 646 | } |
| 647 | |
| 648 | EXPORT_SYMBOL(kill_anon_super); |
| 649 | |
| 650 | void __init unnamed_dev_init(void) |
| 651 | { |
| 652 | idr_init(&unnamed_dev_idr); |
| 653 | } |
| 654 | |
| 655 | void kill_litter_super(struct super_block *sb) |
| 656 | { |
| 657 | if (sb->s_root) |
| 658 | d_genocide(sb->s_root); |
| 659 | kill_anon_super(sb); |
| 660 | } |
| 661 | |
| 662 | EXPORT_SYMBOL(kill_litter_super); |
| 663 | |
| 664 | static int set_bdev_super(struct super_block *s, void *data) |
| 665 | { |
| 666 | s->s_bdev = data; |
| 667 | s->s_dev = s->s_bdev->bd_dev; |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | static int test_bdev_super(struct super_block *s, void *data) |
| 672 | { |
| 673 | return (void *)s->s_bdev == data; |
| 674 | } |
| 675 | |
Greg Kroah-Hartman | fa67576 | 2006-02-22 09:39:02 -0800 | [diff] [blame] | 676 | static void bdev_uevent(struct block_device *bdev, enum kobject_action action) |
| 677 | { |
| 678 | if (bdev->bd_disk) { |
| 679 | if (bdev->bd_part) |
| 680 | kobject_uevent(&bdev->bd_part->kobj, action); |
| 681 | else |
| 682 | kobject_uevent(&bdev->bd_disk->kobj, action); |
| 683 | } |
| 684 | } |
| 685 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 686 | int get_sb_bdev(struct file_system_type *fs_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | int flags, const char *dev_name, void *data, |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 688 | int (*fill_super)(struct super_block *, void *, int), |
| 689 | struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | { |
| 691 | struct block_device *bdev; |
| 692 | struct super_block *s; |
| 693 | int error = 0; |
| 694 | |
| 695 | bdev = open_bdev_excl(dev_name, flags, fs_type); |
| 696 | if (IS_ERR(bdev)) |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 697 | return PTR_ERR(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | |
| 699 | /* |
| 700 | * once the super is inserted into the list by sget, s_umount |
| 701 | * will protect the lockfs code from trying to start a snapshot |
| 702 | * while we are mounting |
| 703 | */ |
Arjan van de Ven | c039e31 | 2006-03-23 03:00:28 -0800 | [diff] [blame] | 704 | mutex_lock(&bdev->bd_mount_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | s = sget(fs_type, test_bdev_super, set_bdev_super, bdev); |
Arjan van de Ven | c039e31 | 2006-03-23 03:00:28 -0800 | [diff] [blame] | 706 | mutex_unlock(&bdev->bd_mount_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | if (IS_ERR(s)) |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 708 | goto error_s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
| 710 | if (s->s_root) { |
| 711 | if ((flags ^ s->s_flags) & MS_RDONLY) { |
| 712 | up_write(&s->s_umount); |
| 713 | deactivate_super(s); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 714 | error = -EBUSY; |
| 715 | goto error_bdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | } |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 717 | |
| 718 | close_bdev_excl(bdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | } else { |
| 720 | char b[BDEVNAME_SIZE]; |
| 721 | |
| 722 | s->s_flags = flags; |
| 723 | strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id)); |
Pekka Enberg | e78c9a0 | 2006-01-08 01:03:39 -0800 | [diff] [blame] | 724 | sb_set_blocksize(s, block_size(bdev)); |
Theodore Ts'o | 9b04c99 | 2006-03-24 03:15:10 -0800 | [diff] [blame] | 725 | error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | if (error) { |
| 727 | up_write(&s->s_umount); |
| 728 | deactivate_super(s); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 729 | goto error; |
Greg Kroah-Hartman | fa67576 | 2006-02-22 09:39:02 -0800 | [diff] [blame] | 730 | } |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 731 | |
| 732 | s->s_flags |= MS_ACTIVE; |
| 733 | bdev_uevent(bdev, KOBJ_MOUNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | } |
| 735 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 736 | return simple_set_mnt(mnt, s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 738 | error_s: |
| 739 | error = PTR_ERR(s); |
| 740 | error_bdev: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | close_bdev_excl(bdev); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 742 | error: |
| 743 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | EXPORT_SYMBOL(get_sb_bdev); |
| 747 | |
| 748 | void kill_block_super(struct super_block *sb) |
| 749 | { |
| 750 | struct block_device *bdev = sb->s_bdev; |
| 751 | |
Greg Kroah-Hartman | fa67576 | 2006-02-22 09:39:02 -0800 | [diff] [blame] | 752 | bdev_uevent(bdev, KOBJ_UMOUNT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | generic_shutdown_super(sb); |
| 754 | sync_blockdev(bdev); |
| 755 | close_bdev_excl(bdev); |
| 756 | } |
| 757 | |
| 758 | EXPORT_SYMBOL(kill_block_super); |
| 759 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 760 | int get_sb_nodev(struct file_system_type *fs_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | int flags, void *data, |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 762 | int (*fill_super)(struct super_block *, void *, int), |
| 763 | struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | { |
| 765 | int error; |
| 766 | struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL); |
| 767 | |
| 768 | if (IS_ERR(s)) |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 769 | return PTR_ERR(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
| 771 | s->s_flags = flags; |
| 772 | |
Theodore Ts'o | 9b04c99 | 2006-03-24 03:15:10 -0800 | [diff] [blame] | 773 | error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | if (error) { |
| 775 | up_write(&s->s_umount); |
| 776 | deactivate_super(s); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 777 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | } |
| 779 | s->s_flags |= MS_ACTIVE; |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 780 | return simple_set_mnt(mnt, s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
| 782 | |
| 783 | EXPORT_SYMBOL(get_sb_nodev); |
| 784 | |
| 785 | static int compare_single(struct super_block *s, void *p) |
| 786 | { |
| 787 | return 1; |
| 788 | } |
| 789 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 790 | int get_sb_single(struct file_system_type *fs_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | int flags, void *data, |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 792 | int (*fill_super)(struct super_block *, void *, int), |
| 793 | struct vfsmount *mnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | { |
| 795 | struct super_block *s; |
| 796 | int error; |
| 797 | |
| 798 | s = sget(fs_type, compare_single, set_anon_super, NULL); |
| 799 | if (IS_ERR(s)) |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 800 | return PTR_ERR(s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | if (!s->s_root) { |
| 802 | s->s_flags = flags; |
Theodore Ts'o | 9b04c99 | 2006-03-24 03:15:10 -0800 | [diff] [blame] | 803 | error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | if (error) { |
| 805 | up_write(&s->s_umount); |
| 806 | deactivate_super(s); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 807 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | s->s_flags |= MS_ACTIVE; |
| 810 | } |
| 811 | do_remount_sb(s, flags, data, 0); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 812 | return simple_set_mnt(mnt, s); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | EXPORT_SYMBOL(get_sb_single); |
| 816 | |
| 817 | struct vfsmount * |
Trond Myklebust | bb4a58b | 2006-06-09 09:34:15 -0400 | [diff] [blame] | 818 | vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | struct vfsmount *mnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | char *secdata = NULL; |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 822 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | if (!type) |
| 825 | return ERR_PTR(-ENODEV); |
| 826 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 827 | error = -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | mnt = alloc_vfsmnt(name); |
| 829 | if (!mnt) |
| 830 | goto out; |
| 831 | |
| 832 | if (data) { |
| 833 | secdata = alloc_secdata(); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 834 | if (!secdata) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 835 | goto out_mnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | |
| 837 | error = security_sb_copy_data(type, data, secdata); |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 838 | if (error) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | goto out_free_secdata; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | } |
| 841 | |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 842 | error = type->get_sb(type, flags, name, data, mnt); |
| 843 | if (error < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | goto out_free_secdata; |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 845 | |
| 846 | error = security_sb_kern_mount(mnt->mnt_sb, secdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | if (error) |
| 848 | goto out_sb; |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 849 | |
| 850 | mnt->mnt_mountpoint = mnt->mnt_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | mnt->mnt_parent = mnt; |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 852 | up_write(&mnt->mnt_sb->s_umount); |
Gerald Schaefer | 8680e22 | 2005-06-21 17:15:16 -0700 | [diff] [blame] | 853 | free_secdata(secdata); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | return mnt; |
| 855 | out_sb: |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 856 | dput(mnt->mnt_root); |
| 857 | up_write(&mnt->mnt_sb->s_umount); |
| 858 | deactivate_super(mnt->mnt_sb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | out_free_secdata: |
| 860 | free_secdata(secdata); |
| 861 | out_mnt: |
| 862 | free_vfsmnt(mnt); |
| 863 | out: |
David Howells | 454e239 | 2006-06-23 02:02:57 -0700 | [diff] [blame] | 864 | return ERR_PTR(error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | } |
| 866 | |
Trond Myklebust | bb4a58b | 2006-06-09 09:34:15 -0400 | [diff] [blame] | 867 | EXPORT_SYMBOL_GPL(vfs_kern_mount); |
| 868 | |
| 869 | struct vfsmount * |
| 870 | do_kern_mount(const char *fstype, int flags, const char *name, void *data) |
| 871 | { |
| 872 | struct file_system_type *type = get_fs_type(fstype); |
| 873 | struct vfsmount *mnt; |
| 874 | if (!type) |
| 875 | return ERR_PTR(-ENODEV); |
| 876 | mnt = vfs_kern_mount(type, flags, name, data); |
| 877 | put_filesystem(type); |
| 878 | return mnt; |
| 879 | } |
| 880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | struct vfsmount *kern_mount(struct file_system_type *type) |
| 882 | { |
Trond Myklebust | 1f5ce9e | 2006-06-09 09:34:16 -0400 | [diff] [blame] | 883 | return vfs_kern_mount(type, 0, type->name, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | EXPORT_SYMBOL(kern_mount); |