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 <linux/fs_struct.h>
31 #include <libcfs/libcfs.h>
33 #include <obd_class.h>
35 #include "ptlrpc_internal.h"
37 /* refine later and change to seqlock or simlar from libcfs */
38 /* Debugging check only needed during development */
40 # define ASSERT_CTXT_MAGIC(magic) LASSERT((magic) == OBD_RUN_CTXT_MAGIC)
42 # define ASSERT_CTXT_MAGIC(magic) do {} while(0)
45 static inline void ll_set_fs_pwd(struct fs_struct *fs, struct vfsmount *mnt,
46 struct dentry *dentry)
55 write_seqcount_begin(&fs->seq);
58 write_seqcount_end(&fs->seq);
59 spin_unlock(&fs->lock);
65 /* push / pop to root of obd store */
66 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx)
68 /* if there is underlaying dt_device then push_ctxt is not needed */
69 if (new_ctx->dt != NULL)
72 ASSERT_CTXT_MAGIC(new_ctx->magic);
73 OBD_SET_CTXT_MAGIC(save);
75 LASSERT(ll_d_count(current->fs->pwd.dentry));
76 LASSERT(ll_d_count(new_ctx->pwd));
77 save->pwd = dget(current->fs->pwd.dentry);
78 save->pwdmnt = mntget(current->fs->pwd.mnt);
79 save->umask = current_umask();
82 LASSERT(save->pwdmnt);
83 LASSERT(new_ctx->pwd);
84 LASSERT(new_ctx->pwdmnt);
86 current->fs->umask = 0; /* umask already applied on client */
87 ll_set_fs_pwd(current->fs, new_ctx->pwdmnt, new_ctx->pwd);
89 EXPORT_SYMBOL(push_ctxt);
91 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx)
93 /* if there is underlaying dt_device then pop_ctxt is not needed */
94 if (new_ctx->dt != NULL)
97 ASSERT_CTXT_MAGIC(saved->magic);
99 LASSERTF(current->fs->pwd.dentry == new_ctx->pwd, "%p != %p\n",
100 current->fs->pwd.dentry, new_ctx->pwd);
101 LASSERTF(current->fs->pwd.mnt == new_ctx->pwdmnt, "%p != %p\n",
102 current->fs->pwd.mnt, new_ctx->pwdmnt);
104 ll_set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
107 mntput(saved->pwdmnt);
108 current->fs->umask = saved->umask;
110 EXPORT_SYMBOL(pop_ctxt);