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, 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(), get_ds()),\
42 # define ASSERT_KERNEL_CTXT(msg) LASSERTF(segment_eq(get_fs(), get_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 /* push / pop to root of obd store */
50 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx)
52 /* if there is underlaying dt_device then push_ctxt is not needed */
53 if (new_ctx->dt != NULL)
56 //ASSERT_NOT_KERNEL_CTXT("already in kernel context!\n");
57 ASSERT_CTXT_MAGIC(new_ctx->magic);
58 OBD_SET_CTXT_MAGIC(save);
61 LASSERT(ll_d_count(current->fs->pwd.dentry));
62 LASSERT(ll_d_count(new_ctx->pwd));
63 save->pwd = dget(current->fs->pwd.dentry);
64 save->pwdmnt = mntget(current->fs->pwd.mnt);
65 save->umask = current_umask();
68 LASSERT(save->pwdmnt);
69 LASSERT(new_ctx->pwd);
70 LASSERT(new_ctx->pwdmnt);
72 current->fs->umask = 0; /* umask already applied on client */
74 ll_set_fs_pwd(current->fs, new_ctx->pwdmnt, new_ctx->pwd);
76 EXPORT_SYMBOL(push_ctxt);
78 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx)
80 /* if there is underlaying dt_device then pop_ctxt is not needed */
81 if (new_ctx->dt != NULL)
84 ASSERT_CTXT_MAGIC(saved->magic);
85 ASSERT_KERNEL_CTXT("popping non-kernel context!\n");
87 LASSERTF(current->fs->pwd.dentry == new_ctx->pwd, "%p != %p\n",
88 current->fs->pwd.dentry, new_ctx->pwd);
89 LASSERTF(current->fs->pwd.mnt == new_ctx->pwdmnt, "%p != %p\n",
90 current->fs->pwd.mnt, new_ctx->pwdmnt);
93 ll_set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
96 mntput(saved->pwdmnt);
97 current->fs->umask = saved->umask;
99 EXPORT_SYMBOL(pop_ctxt);