aboutsummaryrefslogtreecommitdiff
path: root/fs/fs_struct.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/fs_struct.c')
-rw-r--r--fs/fs_struct.c99
1 files changed, 44 insertions, 55 deletions
diff --git a/fs/fs_struct.c b/fs/fs_struct.c
index eee059052db..7dca743b2ce 100644
--- a/fs/fs_struct.c
+++ b/fs/fs_struct.c
@@ -1,23 +1,26 @@
-#include <linux/module.h>
+#include <linux/export.h>
#include <linux/sched.h>
#include <linux/fs.h>
#include <linux/path.h>
#include <linux/slab.h>
#include <linux/fs_struct.h>
+#include "internal.h"
/*
* Replace the fs->{rootmnt,root} with {mnt,dentry}. Put the old values.
* It can block.
*/
-void set_fs_root(struct fs_struct *fs, struct path *path)
+void set_fs_root(struct fs_struct *fs, const struct path *path)
{
struct path old_root;
- write_lock(&fs->lock);
+ path_get(path);
+ spin_lock(&fs->lock);
+ write_seqcount_begin(&fs->seq);
old_root = fs->root;
fs->root = *path;
- path_get(path);
- write_unlock(&fs->lock);
+ write_seqcount_end(&fs->seq);
+ spin_unlock(&fs->lock);
if (old_root.dentry)
path_put(&old_root);
}
@@ -26,21 +29,31 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
* Replace the fs->{pwdmnt,pwd} with {mnt,dentry}. Put the old values.
* It can block.
*/
-void set_fs_pwd(struct fs_struct *fs, struct path *path)
+void set_fs_pwd(struct fs_struct *fs, const struct path *path)
{
struct path old_pwd;
- write_lock(&fs->lock);
+ path_get(path);
+ spin_lock(&fs->lock);
+ write_seqcount_begin(&fs->seq);
old_pwd = fs->pwd;
fs->pwd = *path;
- path_get(path);
- write_unlock(&fs->lock);
+ write_seqcount_end(&fs->seq);
+ spin_unlock(&fs->lock);
if (old_pwd.dentry)
path_put(&old_pwd);
}
-void chroot_fs_refs(struct path *old_root, struct path *new_root)
+static inline int replace_path(struct path *p, const struct path *old, const struct path *new)
+{
+ if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
+ return 0;
+ *p = *new;
+ return 1;
+}
+
+void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
{
struct task_struct *g, *p;
struct fs_struct *fs;
@@ -51,20 +64,17 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
task_lock(p);
fs = p->fs;
if (fs) {
- write_lock(&fs->lock);
- if (fs->root.dentry == old_root->dentry
- && fs->root.mnt == old_root->mnt) {
- path_get(new_root);
- fs->root = *new_root;
+ int hits = 0;
+ spin_lock(&fs->lock);
+ write_seqcount_begin(&fs->seq);
+ hits += replace_path(&fs->root, old_root, new_root);
+ hits += replace_path(&fs->pwd, old_root, new_root);
+ write_seqcount_end(&fs->seq);
+ while (hits--) {
count++;
- }
- if (fs->pwd.dentry == old_root->dentry
- && fs->pwd.mnt == old_root->mnt) {
path_get(new_root);
- fs->pwd = *new_root;
- count++;
}
- write_unlock(&fs->lock);
+ spin_unlock(&fs->lock);
}
task_unlock(p);
} while_each_thread(g, p);
@@ -87,10 +97,10 @@ void exit_fs(struct task_struct *tsk)
if (fs) {
int kill;
task_lock(tsk);
- write_lock(&fs->lock);
+ spin_lock(&fs->lock);
tsk->fs = NULL;
kill = !--fs->users;
- write_unlock(&fs->lock);
+ spin_unlock(&fs->lock);
task_unlock(tsk);
if (kill)
free_fs_struct(fs);
@@ -104,14 +114,16 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
if (fs) {
fs->users = 1;
fs->in_exec = 0;
- rwlock_init(&fs->lock);
+ spin_lock_init(&fs->lock);
+ seqcount_init(&fs->seq);
fs->umask = old->umask;
- read_lock(&old->lock);
+
+ spin_lock(&old->lock);
fs->root = old->root;
- path_get(&old->root);
+ path_get(&fs->root);
fs->pwd = old->pwd;
- path_get(&old->pwd);
- read_unlock(&old->lock);
+ path_get(&fs->pwd);
+ spin_unlock(&old->lock);
}
return fs;
}
@@ -126,10 +138,10 @@ int unshare_fs_struct(void)
return -ENOMEM;
task_lock(current);
- write_lock(&fs->lock);
+ spin_lock(&fs->lock);
kill = !--fs->users;
current->fs = new_fs;
- write_unlock(&fs->lock);
+ spin_unlock(&fs->lock);
task_unlock(current);
if (kill)
@@ -148,30 +160,7 @@ EXPORT_SYMBOL(current_umask);
/* to be mentioned only in INIT_TASK */
struct fs_struct init_fs = {
.users = 1,
- .lock = __RW_LOCK_UNLOCKED(init_fs.lock),
+ .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
+ .seq = SEQCNT_ZERO(init_fs.seq),
.umask = 0022,
};
-
-void daemonize_fs_struct(void)
-{
- struct fs_struct *fs = current->fs;
-
- if (fs) {
- int kill;
-
- task_lock(current);
-
- write_lock(&init_fs.lock);
- init_fs.users++;
- write_unlock(&init_fs.lock);
-
- write_lock(&fs->lock);
- current->fs = &init_fs;
- kill = !--fs->users;
- write_unlock(&fs->lock);
-
- task_unlock(current);
- if (kill)
- free_fs_struct(fs);
- }
-}