From 5a21acc84837c80b03acdac679b4f49da3023294 Mon Sep 17 00:00:00 2001 From: adilger Date: Wed, 28 May 2003 18:28:35 +0000 Subject: [PATCH] More from b_devel->b_orphan merge (I guess I didn't commit anything last night). DEVEL_ORPHAN_UPDATE_PARENT_20030522->DEVEL_ORPHAN_UPDATE_PARENT_20030528 --- lustre/mds/mds_internal.h | 12 ++ lustre/obdclass/simple.c | 274 ++++++++++++++++++++++++++++++++++++++++++++++ lustre/tests/runvmstat | 2 +- 3 files changed, 287 insertions(+), 1 deletion(-) create mode 100644 lustre/obdclass/simple.c diff --git a/lustre/mds/mds_internal.h b/lustre/mds/mds_internal.h index 9373231..39734bb 100644 --- a/lustre/mds/mds_internal.h +++ b/lustre/mds/mds_internal.h @@ -1,3 +1,5 @@ +#ifndef _MDS_INTERNAL_H +#define _MDS_INTERNAL_H static inline struct mds_obd *mds_req2mds(struct ptlrpc_request *req) { return &req->rq_export->exp_obd->u.mds; @@ -24,3 +26,13 @@ int mds_finish_transno(struct mds_obd *mds, struct inode *inode, void *handle, fsfilt_cb_t cb_fn, void *cb_data); +/* mds/mds_lib.c */ +int mds_update_unpack(struct ptlrpc_request *, int offset, + struct mds_update_record *); + +#ifdef __KERNEL__ +void mds_pack_inode2fid(struct ll_fid *fid, struct inode *inode); +void mds_pack_inode2body(struct mds_body *body, struct inode *inode); +#endif + +#endif /* _MDS_INTERNAL_H */ diff --git a/lustre/obdclass/simple.c b/lustre/obdclass/simple.c new file mode 100644 index 0000000..0675ff9 --- /dev/null +++ b/lustre/obdclass/simple.c @@ -0,0 +1,274 @@ +/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- + * vim:expandtab:shiftwidth=8:tabstop=8: + * + * Copyright (C) 2002, 2003 Cluster File Systems, Inc. + * Author: Peter Braam + * Aurhot: Andreas Dilger + * + * This file is part of Lustre, http://www.lustre.org. + * + * Lustre is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * Lustre is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Lustre; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#define EXPORT_SYMTAB + +#include +#include +#include + +#define DEBUG_SUBSYSTEM S_FILTER + +#include +#include + +/* Debugging check only needed during development */ +#ifdef OBD_CTXT_DEBUG +# define ASSERT_CTXT_MAGIC(magic) LASSERT((magic) == OBD_RUN_CTXT_MAGIC) +# define ASSERT_NOT_KERNEL_CTXT(msg) LASSERT(!segment_eq(get_fs(), get_ds())) +# define ASSERT_KERNEL_CTXT(msg) LASSERT(segment_eq(get_fs(), get_ds())) +#else +# define ASSERT_CTXT_MAGIC(magic) do {} while(0) +# define ASSERT_NOT_KERNEL_CTXT(msg) do {} while(0) +# define ASSERT_KERNEL_CTXT(msg) do {} while(0) +#endif + +/* push / pop to root of obd store */ +void push_ctxt(struct obd_run_ctxt *save, struct obd_run_ctxt *new_ctx, + struct obd_ucred *uc) +{ + //ASSERT_NOT_KERNEL_CTXT("already in kernel context!\n"); + ASSERT_CTXT_MAGIC(new_ctx->magic); + OBD_SET_CTXT_MAGIC(save); + + /* + CDEBUG(D_INFO, + "= push %p->%p = cur fs %p pwd %p:d%d:i%d (%*s), pwdmnt %p:%d\n", + save, current, current->fs, current->fs->pwd, + atomic_read(¤t->fs->pwd->d_count), + atomic_read(¤t->fs->pwd->d_inode->i_count), + current->fs->pwd->d_name.len, current->fs->pwd->d_name.name, + current->fs->pwdmnt, + atomic_read(¤t->fs->pwdmnt->mnt_count)); + */ + + save->fs = get_fs(); + LASSERT(atomic_read(¤t->fs->pwd->d_count)); + LASSERT(atomic_read(&new_ctx->pwd->d_count)); + save->pwd = dget(current->fs->pwd); + save->pwdmnt = mntget(current->fs->pwdmnt); + + LASSERT(save->pwd); + LASSERT(save->pwdmnt); + LASSERT(new_ctx->pwd); + LASSERT(new_ctx->pwdmnt); + + if (uc) { + save->fsuid = current->fsuid; + save->fsgid = current->fsgid; + save->cap = current->cap_effective; + + current->fsuid = uc->ouc_fsuid; + current->fsgid = uc->ouc_fsgid; + current->cap_effective = uc->ouc_cap; + if (uc->ouc_suppgid1 != -1) + current->groups[current->ngroups++] = uc->ouc_suppgid1; + if (uc->ouc_suppgid2 != -1) + current->groups[current->ngroups++] = uc->ouc_suppgid2; + } + set_fs(new_ctx->fs); + set_fs_pwd(current->fs, new_ctx->pwdmnt, new_ctx->pwd); + + /* + CDEBUG(D_INFO, + "= push %p->%p = cur fs %p pwd %p:d%d:i%d (%*s), pwdmnt %p:%d\n", + new_ctx, current, current->fs, current->fs->pwd, + atomic_read(¤t->fs->pwd->d_count), + atomic_read(¤t->fs->pwd->d_inode->i_count), + current->fs->pwd->d_name.len, current->fs->pwd->d_name.name, + current->fs->pwdmnt, + atomic_read(¤t->fs->pwdmnt->mnt_count)); + */ +} +EXPORT_SYMBOL(push_ctxt); + +void pop_ctxt(struct obd_run_ctxt *saved, struct obd_run_ctxt *new_ctx, + struct obd_ucred *uc) +{ + //printk("pc0"); + ASSERT_CTXT_MAGIC(saved->magic); + //printk("pc1"); + ASSERT_KERNEL_CTXT("popping non-kernel context!\n"); + + /* + CDEBUG(D_INFO, + " = pop %p==%p = cur %p pwd %p:d%d:i%d (%*s), pwdmnt %p:%d\n", + new_ctx, current, current->fs, current->fs->pwd, + atomic_read(¤t->fs->pwd->d_count), + atomic_read(¤t->fs->pwd->d_inode->i_count), + current->fs->pwd->d_name.len, current->fs->pwd->d_name.name, + current->fs->pwdmnt, + atomic_read(¤t->fs->pwdmnt->mnt_count)); + */ + + LASSERT(current->fs->pwd == new_ctx->pwd); + LASSERT(current->fs->pwdmnt == new_ctx->pwdmnt); + + set_fs(saved->fs); + set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd); + + dput(saved->pwd); + mntput(saved->pwdmnt); + if (uc) { + current->fsuid = saved->fsuid; + current->fsgid = saved->fsgid; + current->cap_effective = saved->cap; + + if (uc->ouc_suppgid1 != -1) + current->ngroups--; + if (uc->ouc_suppgid2 != -1) + current->ngroups--; + } + + /* + CDEBUG(D_INFO, + "= pop %p->%p = cur fs %p pwd %p:d%d:i%d (%*s), pwdmnt %p:%d\n", + saved, current, current->fs, current->fs->pwd, + atomic_read(¤t->fs->pwd->d_count), + atomic_read(¤t->fs->pwd->d_inode->i_count), + current->fs->pwd->d_name.len, current->fs->pwd->d_name.name, + current->fs->pwdmnt, + atomic_read(¤t->fs->pwdmnt->mnt_count)); + */ +} +EXPORT_SYMBOL(pop_ctxt); + +/* 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); + + dchild = lookup_one_len(name, dir, strlen(name)); + if (IS_ERR(dchild)) + GOTO(out_up, dchild); + + if (dchild->d_inode) { + if (!S_ISREG(dchild->d_inode->i_mode)) + GOTO(out_err, err = -EEXIST); + + GOTO(out_up, dchild); + } + + err = vfs_create(dir->d_inode, dchild, (mode & ~S_IFMT) | S_IFREG); + if (err) + GOTO(out_err, err); + + RETURN(dchild); + +out_err: + dput(dchild); + dchild = ERR_PTR(err); +out_up: + return dchild; +} +EXPORT_SYMBOL(simple_mknod); + +/* utility to make a directory */ +struct dentry *simple_mkdir(struct dentry *dir, char *name, int mode) +{ + struct dentry *dchild; + int err = 0; + ENTRY; + + ASSERT_KERNEL_CTXT("kernel doing mkdir outside kernel context\n"); + CDEBUG(D_INODE, "creating directory %*s\n", (int)strlen(name), name); + dchild = lookup_one_len(name, dir, strlen(name)); + if (IS_ERR(dchild)) + GOTO(out_up, dchild); + + if (dchild->d_inode) { + if (!S_ISDIR(dchild->d_inode->i_mode)) + GOTO(out_err, err = -ENOTDIR); + + GOTO(out_up, dchild); + } + + err = vfs_mkdir(dir->d_inode, dchild, mode); + if (err) + GOTO(out_err, err); + + RETURN(dchild); + +out_err: + dput(dchild); + dchild = ERR_PTR(err); +out_up: + return dchild; +} +EXPORT_SYMBOL(simple_mkdir); + +/* + * Read a file from within kernel context. Prior to calling this + * function we should already have done a push_ctxt(). + */ +int lustre_fread(struct file *file, void *buf, int len, loff_t *off) +{ + ASSERT_KERNEL_CTXT("kernel doing read outside kernel context\n"); + if (!file || !file->f_op || !file->f_op->read || !off) + RETURN(-ENOSYS); + + return file->f_op->read(file, buf, len, off); +} +EXPORT_SYMBOL(lustre_fread); + +/* + * Write a file from within kernel context. Prior to calling this + * function we should already have done a push_ctxt(). + */ +int lustre_fwrite(struct file *file, const void *buf, int len, loff_t *off) +{ + ENTRY; + ASSERT_KERNEL_CTXT("kernel doing write outside kernel context\n"); + if (!file) + RETURN(-ENOENT); + if (!file->f_op) + RETURN(-ENOSYS); + if (!off) + RETURN(-EINVAL); + + if (!file->f_op->write) + RETURN(-EROFS); + + RETURN(file->f_op->write(file, buf, len, off)); +} +EXPORT_SYMBOL(lustre_fwrite); + +/* + * Sync a file from within kernel context. Prior to calling this + * function we should already have done a push_ctxt(). + */ +int lustre_fsync(struct file *file) +{ + ENTRY; + ASSERT_KERNEL_CTXT("kernel doing sync outside kernel context\n"); + if (!file || !file->f_op || !file->f_op->fsync) + RETURN(-ENOSYS); + + RETURN(file->f_op->fsync(file, file->f_dentry, 0)); +} +EXPORT_SYMBOL(lustre_fsync); diff --git a/lustre/tests/runvmstat b/lustre/tests/runvmstat index 6bff5ce..a8917f7 100755 --- a/lustre/tests/runvmstat +++ b/lustre/tests/runvmstat @@ -1,2 +1,2 @@ #!/bin/sh -vmstat 1 | while read LINE ; do echo "`date +%H:%M:%S`: $LINE" ; done +vmstat 1 | while read LINE ; do echo "`date +%s`: $LINE" ; done -- 1.8.3.1