diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2009-03-29 19:00:13 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2009-03-31 23:00:26 -0400 |
commit | 3e93cd671813e204c258f1e6c797959920cf7772 (patch) | |
tree | a1e0b2d2da7d296cc1c53be9cd6efa5b94b01b5c /kernel | |
parent | f8ef3ed2bebd2c4cb9ece92efa185d7aead8831a (diff) |
Take fs_struct handling to new file (fs/fs_struct.c)
Pure code move; two new helper functions for nfsd and daemonize
(unshare_fs_struct() and daemonize_fs_struct() resp.; for now -
the same code as used to be in callers). unshare_fs_struct()
exported (for nfsd, as copy_fs_struct()/exit_fs() used to be),
copy_fs_struct() and exit_fs() don't need exports anymore.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/exit.c | 31 | ||||
-rw-r--r-- | kernel/fork.c | 29 |
2 files changed, 3 insertions, 57 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index 167e1e3ad7c6..ad8375758a79 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -429,7 +429,6 @@ EXPORT_SYMBOL(disallow_signal); | |||
429 | void daemonize(const char *name, ...) | 429 | void daemonize(const char *name, ...) |
430 | { | 430 | { |
431 | va_list args; | 431 | va_list args; |
432 | struct fs_struct *fs; | ||
433 | sigset_t blocked; | 432 | sigset_t blocked; |
434 | 433 | ||
435 | va_start(args, name); | 434 | va_start(args, name); |
@@ -462,11 +461,7 @@ void daemonize(const char *name, ...) | |||
462 | 461 | ||
463 | /* Become as one with the init task */ | 462 | /* Become as one with the init task */ |
464 | 463 | ||
465 | exit_fs(current); /* current->fs->count--; */ | 464 | daemonize_fs_struct(); |
466 | fs = init_task.fs; | ||
467 | current->fs = fs; | ||
468 | atomic_inc(&fs->count); | ||
469 | |||
470 | exit_files(current); | 465 | exit_files(current); |
471 | current->files = init_task.files; | 466 | current->files = init_task.files; |
472 | atomic_inc(¤t->files->count); | 467 | atomic_inc(¤t->files->count); |
@@ -565,30 +560,6 @@ void exit_files(struct task_struct *tsk) | |||
565 | } | 560 | } |
566 | } | 561 | } |
567 | 562 | ||
568 | void put_fs_struct(struct fs_struct *fs) | ||
569 | { | ||
570 | /* No need to hold fs->lock if we are killing it */ | ||
571 | if (atomic_dec_and_test(&fs->count)) { | ||
572 | path_put(&fs->root); | ||
573 | path_put(&fs->pwd); | ||
574 | kmem_cache_free(fs_cachep, fs); | ||
575 | } | ||
576 | } | ||
577 | |||
578 | void exit_fs(struct task_struct *tsk) | ||
579 | { | ||
580 | struct fs_struct * fs = tsk->fs; | ||
581 | |||
582 | if (fs) { | ||
583 | task_lock(tsk); | ||
584 | tsk->fs = NULL; | ||
585 | task_unlock(tsk); | ||
586 | put_fs_struct(fs); | ||
587 | } | ||
588 | } | ||
589 | |||
590 | EXPORT_SYMBOL_GPL(exit_fs); | ||
591 | |||
592 | #ifdef CONFIG_MM_OWNER | 563 | #ifdef CONFIG_MM_OWNER |
593 | /* | 564 | /* |
594 | * Task p is exiting and it owned mm, lets find a new owner for it | 565 | * Task p is exiting and it owned mm, lets find a new owner for it |
diff --git a/kernel/fork.c b/kernel/fork.c index 47c15840a381..05c02dc586b1 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -681,38 +681,13 @@ fail_nomem: | |||
681 | return retval; | 681 | return retval; |
682 | } | 682 | } |
683 | 683 | ||
684 | static struct fs_struct *__copy_fs_struct(struct fs_struct *old) | ||
685 | { | ||
686 | struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL); | ||
687 | /* We don't need to lock fs - think why ;-) */ | ||
688 | if (fs) { | ||
689 | atomic_set(&fs->count, 1); | ||
690 | rwlock_init(&fs->lock); | ||
691 | fs->umask = old->umask; | ||
692 | read_lock(&old->lock); | ||
693 | fs->root = old->root; | ||
694 | path_get(&old->root); | ||
695 | fs->pwd = old->pwd; | ||
696 | path_get(&old->pwd); | ||
697 | read_unlock(&old->lock); | ||
698 | } | ||
699 | return fs; | ||
700 | } | ||
701 | |||
702 | struct fs_struct *copy_fs_struct(struct fs_struct *old) | ||
703 | { | ||
704 | return __copy_fs_struct(old); | ||
705 | } | ||
706 | |||
707 | EXPORT_SYMBOL_GPL(copy_fs_struct); | ||
708 | |||
709 | static int copy_fs(unsigned long clone_flags, struct task_struct *tsk) | 684 | static int copy_fs(unsigned long clone_flags, struct task_struct *tsk) |
710 | { | 685 | { |
711 | if (clone_flags & CLONE_FS) { | 686 | if (clone_flags & CLONE_FS) { |
712 | atomic_inc(¤t->fs->count); | 687 | atomic_inc(¤t->fs->count); |
713 | return 0; | 688 | return 0; |
714 | } | 689 | } |
715 | tsk->fs = __copy_fs_struct(current->fs); | 690 | tsk->fs = copy_fs_struct(current->fs); |
716 | if (!tsk->fs) | 691 | if (!tsk->fs) |
717 | return -ENOMEM; | 692 | return -ENOMEM; |
718 | return 0; | 693 | return 0; |
@@ -1545,7 +1520,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp) | |||
1545 | 1520 | ||
1546 | if ((unshare_flags & CLONE_FS) && | 1521 | if ((unshare_flags & CLONE_FS) && |
1547 | (fs && atomic_read(&fs->count) > 1)) { | 1522 | (fs && atomic_read(&fs->count) > 1)) { |
1548 | *new_fsp = __copy_fs_struct(current->fs); | 1523 | *new_fsp = copy_fs_struct(current->fs); |
1549 | if (!*new_fsp) | 1524 | if (!*new_fsp) |
1550 | return -ENOMEM; | 1525 | return -ENOMEM; |
1551 | } | 1526 | } |