#define DEBUG_SUBSYSTEM S_FILTER
+#include <linux/obd_support.h>
+#include <linux/obd.h>
#include <linux/lustre_mds.h>
#include <linux/lustre_lib.h>
#include <linux/lustre_net.h>
#endif
/* push / pop to root of obd store */
-void push_ctxt(struct obd_run_ctxt *save, struct obd_run_ctxt *new)
+void push_ctxt(struct obd_run_ctxt *save, struct obd_run_ctxt *new,
+ struct obd_ucred *uc)
{
//ASSERT_NOT_KERNEL_CTXT("already in kernel context!\n");
ASSERT_CTXT_MAGIC(new->magic);
LASSERT(new->pwd);
LASSERT(new->pwdmnt);
+ save->fsuid = current->fsuid;
+ save->fsgid = current->fsgid;
+ save->cap = current->cap_effective;
+ if (uc) {
+ current->fsuid = uc->ouc_fsuid;
+ current->fsgid = uc->ouc_fsgid;
+ current->cap_effective = uc->ouc_cap;
+ }
set_fs(new->fs);
set_fs_pwd(current->fs, new->pwdmnt, new->pwd);
+ //if (save->override)
+ // cap_lower(current->cap_effective, CAP_DAC_OVERRIDE);
}
void pop_ctxt(struct obd_run_ctxt *saved)
{
+ //printk("pc0");
ASSERT_CTXT_MAGIC(saved->magic);
+ //printk("pc1");
ASSERT_KERNEL_CTXT("popping non-kernel context!\n");
+ //printk("pc2");
set_fs(saved->fs);
- LASSERT(saved->pwd);
- LASSERT(saved->pwdmnt);
+ //printk("pc3\n");
set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);
+ //printk("pc4");
dput(saved->pwd);
+ //printk("pc5");
mntput(saved->pwdmnt);
+ //printk("pc6\n");
+ current->fsuid = saved->fsuid;
+ current->fsgid = saved->fsgid;
+ current->cap_effective = saved->cap;
+
+ // if (saved->override)
+ // cap_raise(current->cap_effective, CAP_DAC_OVERRIDE);
+}
+
+/* utility to make a file */
+struct dentry *simple_mknod(struct dentry *dir, char *name, int mode)
+{
+ struct dentry *dchild;
+ int err = 0;
+ ENTRY;
+
+ ASSERT_KERNEL_CTXT("kernel doing mknod outside kernel context\n");
+ CDEBUG(D_INODE, "creating file %*s\n", (int)strlen(name), name);
+
+ down(&dir->d_inode->i_sem);
+ dchild = lookup_one_len(name, dir, strlen(name));
+ if (IS_ERR(dchild))
+ GOTO(out, PTR_ERR(dchild));
+
+ if (dchild->d_inode) {
+ if ((dchild->d_inode->i_mode & S_IFMT) != S_IFREG)
+ GOTO(out, err = -EEXIST);
+
+ GOTO(out, dchild);
+ }
+
+ err = vfs_create(dir->d_inode, dchild, (mode & ~S_IFMT) | S_IFREG);
+ EXIT;
+out:
+ up(&dir->d_inode->i_sem);
+ if (err) {
+ dput(dchild);
+ RETURN(ERR_PTR(err));
+ }
+
+ RETURN(dchild);
}
/* utility to make a directory */
struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode)
{
struct dentry *dchild;
- int err;
+ int err = 0;
ENTRY;
ASSERT_KERNEL_CTXT("kernel doing mkdir outside kernel context\n");
- CDEBUG(D_INODE, "creating directory %*s\n", strlen(name), name);
+ CDEBUG(D_INODE, "creating directory %*s\n", (int)strlen(name), name);
+ down(&dir->d_inode->i_sem);
dchild = lookup_one_len(name, dir, strlen(name));
if (IS_ERR(dchild))
- RETURN(dchild);
+ GOTO(out, PTR_ERR(dchild));
if (dchild->d_inode) {
if (!S_ISDIR(dchild->d_inode->i_mode))
GOTO(out, err = -ENOTDIR);
- RETURN(dchild);
+ GOTO(out, dchild);
}
err = vfs_mkdir(dir->d_inode, dchild, mode);
EXIT;
out:
+ up(&dir->d_inode->i_sem);
if (err) {
dput(dchild);
RETURN(ERR_PTR(err));