4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
19 * http://www.gnu.org/licenses/gpl-2.0.html
24 * Copyright (c) 2014, 2017, Intel Corporation.
27 #define DEBUG_SUBSYSTEM S_FILTER
30 #include <libcfs/libcfs.h>
32 #include <obd_class.h>
34 #include "ptlrpc_internal.h"
36 /* refine later and change to seqlock or simlar from libcfs */
37 /* Debugging check only needed during development */
39 # define ASSERT_CTXT_MAGIC(magic) LASSERT((magic) == OBD_RUN_CTXT_MAGIC)
40 # define ASSERT_NOT_KERNEL_CTXT(msg) LASSERTF(!segment_eq(get_fs(), KERNEL_DS),\
42 # define ASSERT_KERNEL_CTXT(msg) LASSERTF(segment_eq(get_fs(), KERNEL_DS), msg)
44 # define ASSERT_CTXT_MAGIC(magic) do {} while(0)
45 # define ASSERT_NOT_KERNEL_CTXT(msg) do {} while(0)
46 # define ASSERT_KERNEL_CTXT(msg) do {} while(0)
49 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
50 struct dentry *dentry)
59 write_seqcount_begin(&fs->seq);
62 write_seqcount_end(&fs->seq);
63 spin_unlock(&fs->lock);
69 /* push / pop to root of obd store */
70 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx)
72 /* if there is underlaying dt_device then push_ctxt is not needed */
73 if (new_ctx->dt != NULL)
76 //ASSERT_NOT_KERNEL_CTXT("already in kernel context!\n");
77 ASSERT_CTXT_MAGIC(new_ctx->magic);
78 OBD_SET_CTXT_MAGIC(save);
81 LASSERT(ll_d_count(current->fs->pwd.dentry));
82 LASSERT(ll_d_count(new_ctx->pwd));
83 save->pwd = dget(current->fs->pwd.dentry);
84 save->pwdmnt = mntget(current->fs->pwd.mnt);
85 save->umask = current_umask();
88 LASSERT(save->pwdmnt);
89 LASSERT(new_ctx->pwd);
90 LASSERT(new_ctx->pwdmnt);
92 current->fs->umask = 0; /* umask already applied on client */
94 ll_set_fs_pwd(current->fs, new_ctx->pwdmnt, new_ctx->pwd);
96 EXPORT_SYMBOL(push_ctxt);
98 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx)
100 /* if there is underlaying dt_device then pop_ctxt is not needed */
101 if (new_ctx->dt != NULL)
104 ASSERT_CTXT_MAGIC(saved->magic);
105 ASSERT_KERNEL_CTXT("popping non-kernel context!\n");
107 LASSERTF(current->fs->pwd.dentry == new_ctx->pwd, "%p != %p\n",
108 current->fs->pwd.dentry, new_ctx->pwd);
109 LASSERTF(current->fs->pwd.mnt == new_ctx->pwdmnt, "%p != %p\n",
110 current->fs->pwd.mnt, new_ctx->pwdmnt);
113 ll_set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
116 mntput(saved->pwdmnt);
117 current->fs->umask = saved->umask;
119 EXPORT_SYMBOL(pop_ctxt);