diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-27 19:23:12 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-03-27 19:23:12 -0400 |
commit | 3ae5080f4c2e293229508dabe7c8a90af4e4c460 (patch) | |
tree | 9cb11f26905a82b7fac9d3b8f9d61d58bc5c94b0 /fs/devpts/inode.c | |
parent | 2c9e15a011c55ff96b2b8d2b126d1b9a96abba20 (diff) | |
parent | aabb8fdb41128705fd1627f56fdd571e45fdbcdb (diff) |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6: (37 commits)
fs: avoid I_NEW inodes
Merge code for single and multiple-instance mounts
Remove get_init_pts_sb()
Move common mknod_ptmx() calls into caller
Parse mount options just once and copy them to super block
Unroll essentials of do_remount_sb() into devpts
vfs: simple_set_mnt() should return void
fs: move bdev code out of buffer.c
constify dentry_operations: rest
constify dentry_operations: configfs
constify dentry_operations: sysfs
constify dentry_operations: JFS
constify dentry_operations: OCFS2
constify dentry_operations: GFS2
constify dentry_operations: FAT
constify dentry_operations: FUSE
constify dentry_operations: procfs
constify dentry_operations: ecryptfs
constify dentry_operations: CIFS
constify dentry_operations: AFS
...
Diffstat (limited to 'fs/devpts/inode.c')
-rw-r--r-- | fs/devpts/inode.c | 188 |
1 files changed, 46 insertions, 142 deletions
diff --git a/fs/devpts/inode.c b/fs/devpts/inode.c index bff4052b05e7..63a4a59e4148 100644 --- a/fs/devpts/inode.c +++ b/fs/devpts/inode.c | |||
@@ -322,177 +322,81 @@ static int compare_init_pts_sb(struct super_block *s, void *p) | |||
322 | } | 322 | } |
323 | 323 | ||
324 | /* | 324 | /* |
325 | * Safely parse the mount options in @data and update @opts. | 325 | * devpts_get_sb() |
326 | * | 326 | * |
327 | * devpts ends up parsing options two times during mount, due to the | 327 | * If the '-o newinstance' mount option was specified, mount a new |
328 | * two modes of operation it supports. The first parse occurs in | 328 | * (private) instance of devpts. PTYs created in this instance are |
329 | * devpts_get_sb() when determining the mode (single-instance or | 329 | * independent of the PTYs in other devpts instances. |
330 | * multi-instance mode). The second parse happens in devpts_remount() | ||
331 | * or new_pts_mount() depending on the mode. | ||
332 | * | 330 | * |
333 | * Parsing of options modifies the @data making subsequent parsing | 331 | * If the '-o newinstance' option was not specified, mount/remount the |
334 | * incorrect. So make a local copy of @data and parse it. | 332 | * initial kernel mount of devpts. This type of mount gives the |
333 | * legacy, single-instance semantics. | ||
335 | * | 334 | * |
336 | * Return: 0 On success, -errno on error | 335 | * The 'newinstance' option is needed to support multiple namespace |
337 | */ | 336 | * semantics in devpts while preserving backward compatibility of the |
338 | static int safe_parse_mount_options(void *data, struct pts_mount_opts *opts) | 337 | * current 'single-namespace' semantics. i.e all mounts of devpts |
339 | { | 338 | * without the 'newinstance' mount option should bind to the initial |
340 | int rc; | 339 | * kernel mount, like get_sb_single(). |
341 | void *datacp; | ||
342 | |||
343 | if (!data) | ||
344 | return 0; | ||
345 | |||
346 | /* Use kstrdup() ? */ | ||
347 | datacp = kmalloc(PAGE_SIZE, GFP_KERNEL); | ||
348 | if (!datacp) | ||
349 | return -ENOMEM; | ||
350 | |||
351 | memcpy(datacp, data, PAGE_SIZE); | ||
352 | rc = parse_mount_options((char *)datacp, PARSE_MOUNT, opts); | ||
353 | kfree(datacp); | ||
354 | |||
355 | return rc; | ||
356 | } | ||
357 | |||
358 | /* | ||
359 | * Mount a new (private) instance of devpts. PTYs created in this | ||
360 | * instance are independent of the PTYs in other devpts instances. | ||
361 | */ | ||
362 | static int new_pts_mount(struct file_system_type *fs_type, int flags, | ||
363 | void *data, struct vfsmount *mnt) | ||
364 | { | ||
365 | int err; | ||
366 | struct pts_fs_info *fsi; | ||
367 | struct pts_mount_opts *opts; | ||
368 | |||
369 | err = get_sb_nodev(fs_type, flags, data, devpts_fill_super, mnt); | ||
370 | if (err) | ||
371 | return err; | ||
372 | |||
373 | fsi = DEVPTS_SB(mnt->mnt_sb); | ||
374 | opts = &fsi->mount_opts; | ||
375 | |||
376 | err = parse_mount_options(data, PARSE_MOUNT, opts); | ||
377 | if (err) | ||
378 | goto fail; | ||
379 | |||
380 | err = mknod_ptmx(mnt->mnt_sb); | ||
381 | if (err) | ||
382 | goto fail; | ||
383 | |||
384 | return 0; | ||
385 | |||
386 | fail: | ||
387 | dput(mnt->mnt_sb->s_root); | ||
388 | deactivate_super(mnt->mnt_sb); | ||
389 | return err; | ||
390 | } | ||
391 | |||
392 | /* | ||
393 | * Check if 'newinstance' mount option was specified in @data. | ||
394 | * | 340 | * |
395 | * Return: -errno on error (eg: invalid mount options specified) | 341 | * Mounts with 'newinstance' option create a new, private namespace. |
396 | * : 1 if 'newinstance' mount option was specified | ||
397 | * : 0 if 'newinstance' mount option was NOT specified | ||
398 | */ | ||
399 | static int is_new_instance_mount(void *data) | ||
400 | { | ||
401 | int rc; | ||
402 | struct pts_mount_opts opts; | ||
403 | |||
404 | if (!data) | ||
405 | return 0; | ||
406 | |||
407 | rc = safe_parse_mount_options(data, &opts); | ||
408 | if (!rc) | ||
409 | rc = opts.newinstance; | ||
410 | |||
411 | return rc; | ||
412 | } | ||
413 | |||
414 | /* | ||
415 | * get_init_pts_sb() | ||
416 | * | ||
417 | * This interface is needed to support multiple namespace semantics in | ||
418 | * devpts while preserving backward compatibility of the current 'single- | ||
419 | * namespace' semantics. i.e all mounts of devpts without the 'newinstance' | ||
420 | * mount option should bind to the initial kernel mount, like | ||
421 | * get_sb_single(). | ||
422 | * | 342 | * |
423 | * Mounts with 'newinstance' option create a new private namespace. | 343 | * NOTE: |
424 | * | 344 | * |
425 | * But for single-mount semantics, devpts cannot use get_sb_single(), | 345 | * For single-mount semantics, devpts cannot use get_sb_single(), |
426 | * because get_sb_single()/sget() find and use the super-block from | 346 | * because get_sb_single()/sget() find and use the super-block from |
427 | * the most recent mount of devpts. But that recent mount may be a | 347 | * the most recent mount of devpts. But that recent mount may be a |
428 | * 'newinstance' mount and get_sb_single() would pick the newinstance | 348 | * 'newinstance' mount and get_sb_single() would pick the newinstance |
429 | * super-block instead of the initial super-block. | 349 | * super-block instead of the initial super-block. |
430 | * | ||
431 | * This interface is identical to get_sb_single() except that it | ||
432 | * consistently selects the 'single-namespace' superblock even in the | ||
433 | * presence of the private namespace (i.e 'newinstance') super-blocks. | ||
434 | */ | 350 | */ |
435 | static int get_init_pts_sb(struct file_system_type *fs_type, int flags, | 351 | static int devpts_get_sb(struct file_system_type *fs_type, |
436 | void *data, struct vfsmount *mnt) | 352 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) |
437 | { | 353 | { |
438 | struct super_block *s; | ||
439 | int error; | 354 | int error; |
355 | struct pts_mount_opts opts; | ||
356 | struct super_block *s; | ||
357 | |||
358 | memset(&opts, 0, sizeof(opts)); | ||
359 | if (data) { | ||
360 | error = parse_mount_options(data, PARSE_MOUNT, &opts); | ||
361 | if (error) | ||
362 | return error; | ||
363 | } | ||
364 | |||
365 | if (opts.newinstance) | ||
366 | s = sget(fs_type, NULL, set_anon_super, NULL); | ||
367 | else | ||
368 | s = sget(fs_type, compare_init_pts_sb, set_anon_super, NULL); | ||
440 | 369 | ||
441 | s = sget(fs_type, compare_init_pts_sb, set_anon_super, NULL); | ||
442 | if (IS_ERR(s)) | 370 | if (IS_ERR(s)) |
443 | return PTR_ERR(s); | 371 | return PTR_ERR(s); |
444 | 372 | ||
445 | if (!s->s_root) { | 373 | if (!s->s_root) { |
446 | s->s_flags = flags; | 374 | s->s_flags = flags; |
447 | error = devpts_fill_super(s, data, flags & MS_SILENT ? 1 : 0); | 375 | error = devpts_fill_super(s, data, flags & MS_SILENT ? 1 : 0); |
448 | if (error) { | 376 | if (error) |
449 | up_write(&s->s_umount); | 377 | goto out_undo_sget; |
450 | deactivate_super(s); | ||
451 | return error; | ||
452 | } | ||
453 | s->s_flags |= MS_ACTIVE; | 378 | s->s_flags |= MS_ACTIVE; |
454 | } | 379 | } |
455 | do_remount_sb(s, flags, data, 0); | ||
456 | return simple_set_mnt(mnt, s); | ||
457 | } | ||
458 | 380 | ||
459 | /* | 381 | simple_set_mnt(mnt, s); |
460 | * Mount or remount the initial kernel mount of devpts. This type of | ||
461 | * mount maintains the legacy, single-instance semantics, while the | ||
462 | * kernel still allows multiple-instances. | ||
463 | */ | ||
464 | static int init_pts_mount(struct file_system_type *fs_type, int flags, | ||
465 | void *data, struct vfsmount *mnt) | ||
466 | { | ||
467 | int err; | ||
468 | 382 | ||
469 | err = get_init_pts_sb(fs_type, flags, data, mnt); | 383 | memcpy(&(DEVPTS_SB(s))->mount_opts, &opts, sizeof(opts)); |
470 | if (err) | ||
471 | return err; | ||
472 | 384 | ||
473 | err = mknod_ptmx(mnt->mnt_sb); | 385 | error = mknod_ptmx(s); |
474 | if (err) { | 386 | if (error) |
475 | dput(mnt->mnt_sb->s_root); | 387 | goto out_dput; |
476 | deactivate_super(mnt->mnt_sb); | ||
477 | } | ||
478 | 388 | ||
479 | return err; | 389 | return 0; |
480 | } | ||
481 | |||
482 | static int devpts_get_sb(struct file_system_type *fs_type, | ||
483 | int flags, const char *dev_name, void *data, struct vfsmount *mnt) | ||
484 | { | ||
485 | int new; | ||
486 | |||
487 | new = is_new_instance_mount(data); | ||
488 | if (new < 0) | ||
489 | return new; | ||
490 | 390 | ||
491 | if (new) | 391 | out_dput: |
492 | return new_pts_mount(fs_type, flags, data, mnt); | 392 | dput(s->s_root); |
493 | 393 | ||
494 | return init_pts_mount(fs_type, flags, data, mnt); | 394 | out_undo_sget: |
395 | up_write(&s->s_umount); | ||
396 | deactivate_super(s); | ||
397 | return error; | ||
495 | } | 398 | } |
399 | |||
496 | #else | 400 | #else |
497 | /* | 401 | /* |
498 | * This supports only the legacy single-instance semantics (no | 402 | * This supports only the legacy single-instance semantics (no |