Whamcloud - gitweb
LU-17888 osd-ldiskfs: osd_scrub_refresh_mapping deadlock
[fs/lustre-release.git] / lustre / ptlrpc / sec_ctx.c
index 9f426b8..065a13d 100644 (file)
@@ -27,6 +27,7 @@
 #define DEBUG_SUBSYSTEM S_FILTER
 
 #include <linux/fs.h>
+#include <linux/fs_struct.h>
 #include <libcfs/libcfs.h>
 #include <lvfs.h>
 #include <obd_class.h>
 /* Debugging check only needed during development */
 #ifdef OBD_CTXT_DEBUG
 # define ASSERT_CTXT_MAGIC(magic) LASSERT((magic) == OBD_RUN_CTXT_MAGIC)
-# define ASSERT_NOT_KERNEL_CTXT(msg) LASSERTF(!segment_eq(get_fs(), KERNEL_DS),\
-                                             msg)
-# define ASSERT_KERNEL_CTXT(msg) LASSERTF(segment_eq(get_fs(), KERNEL_DS), msg)
 #else
 # define ASSERT_CTXT_MAGIC(magic) do {} while(0)
-# define ASSERT_NOT_KERNEL_CTXT(msg) do {} while(0)
-# define ASSERT_KERNEL_CTXT(msg) do {} while(0)
 #endif
 
+static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
+                                struct dentry *dentry)
+{
+       struct path path;
+       struct path old_pwd;
+
+       path.mnt = mnt;
+       path.dentry = dentry;
+       path_get(&path);
+       spin_lock(&fs->lock);
+       write_seqcount_begin(&fs->seq);
+       old_pwd = fs->pwd;
+       fs->pwd = path;
+       write_seqcount_end(&fs->seq);
+       spin_unlock(&fs->lock);
+
+       if (old_pwd.dentry)
+               path_put(&old_pwd);
+}
+
 /* push / pop to root of obd store */
 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx)
 {
@@ -53,11 +69,9 @@ void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx)
        if (new_ctx->dt != NULL)
                return;
 
-       //ASSERT_NOT_KERNEL_CTXT("already in kernel context!\n");
        ASSERT_CTXT_MAGIC(new_ctx->magic);
        OBD_SET_CTXT_MAGIC(save);
 
-       save->fs = get_fs();
        LASSERT(ll_d_count(current->fs->pwd.dentry));
        LASSERT(ll_d_count(new_ctx->pwd));
        save->pwd = dget(current->fs->pwd.dentry);
@@ -70,7 +84,6 @@ void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx)
        LASSERT(new_ctx->pwdmnt);
 
        current->fs->umask = 0; /* umask already applied on client */
-       set_fs(new_ctx->fs);
        ll_set_fs_pwd(current->fs, new_ctx->pwdmnt, new_ctx->pwd);
 }
 EXPORT_SYMBOL(push_ctxt);
@@ -82,14 +95,12 @@ void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx)
                return;
 
        ASSERT_CTXT_MAGIC(saved->magic);
-       ASSERT_KERNEL_CTXT("popping non-kernel context!\n");
 
-       LASSERTF(current->fs->pwd.dentry == new_ctx->pwd, "%p != %p\n",
+       LASSERTF(current->fs->pwd.dentry == new_ctx->pwd, "%px != %px\n",
                 current->fs->pwd.dentry, new_ctx->pwd);
-       LASSERTF(current->fs->pwd.mnt == new_ctx->pwdmnt, "%p != %p\n",
+       LASSERTF(current->fs->pwd.mnt == new_ctx->pwdmnt, "%px != %px\n",
                 current->fs->pwd.mnt, new_ctx->pwdmnt);
 
-       set_fs(saved->fs);
        ll_set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
 
        dput(saved->pwd);