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 #define DEBUG_SUBSYSTEM S_FILTER
27 #include <libcfs/libcfs.h>
29 #include <obd_class.h>
31 #include "ptlrpc_internal.h"
33 /* refine later and change to seqlock or simlar from libcfs */
34 /* Debugging check only needed during development */
36 # define ASSERT_CTXT_MAGIC(magic) LASSERT((magic) == OBD_RUN_CTXT_MAGIC)
37 # define ASSERT_NOT_KERNEL_CTXT(msg) LASSERTF(!segment_eq(get_fs(), get_ds()),\
39 # define ASSERT_KERNEL_CTXT(msg) LASSERTF(segment_eq(get_fs(), get_ds()), msg)
41 # define ASSERT_CTXT_MAGIC(magic) do {} while(0)
42 # define ASSERT_NOT_KERNEL_CTXT(msg) do {} while(0)
43 # define ASSERT_KERNEL_CTXT(msg) do {} while(0)
46 /* push / pop to root of obd store */
47 void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx)
49 /* if there is underlaying dt_device then push_ctxt is not needed */
50 if (new_ctx->dt != NULL)
53 //ASSERT_NOT_KERNEL_CTXT("already in kernel context!\n");
54 ASSERT_CTXT_MAGIC(new_ctx->magic);
55 OBD_SET_CTXT_MAGIC(save);
58 LASSERT(ll_d_count(current->fs->pwd.dentry));
59 LASSERT(ll_d_count(new_ctx->pwd));
60 save->pwd = dget(current->fs->pwd.dentry);
61 save->pwdmnt = mntget(current->fs->pwd.mnt);
62 save->umask = current_umask();
65 LASSERT(save->pwdmnt);
66 LASSERT(new_ctx->pwd);
67 LASSERT(new_ctx->pwdmnt);
69 current->fs->umask = 0; /* umask already applied on client */
71 ll_set_fs_pwd(current->fs, new_ctx->pwdmnt, new_ctx->pwd);
73 EXPORT_SYMBOL(push_ctxt);
75 void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx)
77 /* if there is underlaying dt_device then pop_ctxt is not needed */
78 if (new_ctx->dt != NULL)
81 ASSERT_CTXT_MAGIC(saved->magic);
82 ASSERT_KERNEL_CTXT("popping non-kernel context!\n");
84 LASSERTF(current->fs->pwd.dentry == new_ctx->pwd, "%p != %p\n",
85 current->fs->pwd.dentry, new_ctx->pwd);
86 LASSERTF(current->fs->pwd.mnt == new_ctx->pwdmnt, "%p != %p\n",
87 current->fs->pwd.mnt, new_ctx->pwdmnt);
90 ll_set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
93 mntput(saved->pwdmnt);
94 current->fs->umask = saved->umask;
96 EXPORT_SYMBOL(pop_ctxt);
98 /* utility to rename a file */
99 int lustre_rename(struct dentry *dir, struct vfsmount *mnt,
100 char *oldname, char *newname)
102 struct dentry *dchild_old, *dchild_new;
106 ASSERT_KERNEL_CTXT("kernel doing rename outside kernel context\n");
107 CDEBUG(D_INODE, "renaming file %.*s to %.*s\n",
108 (int)strlen(oldname), oldname, (int)strlen(newname), newname);
110 dchild_old = ll_lookup_one_len(oldname, dir, strlen(oldname));
111 if (IS_ERR(dchild_old))
112 RETURN(PTR_ERR(dchild_old));
114 if (!dchild_old->d_inode)
115 GOTO(put_old, err = -ENOENT);
117 dchild_new = ll_lookup_one_len(newname, dir, strlen(newname));
118 if (IS_ERR(dchild_new))
119 GOTO(put_old, err = PTR_ERR(dchild_new));
121 err = ll_vfs_rename(dir->d_inode, dchild_old, dir->d_inode, dchild_new);