lvfs_linux.c

来自「lustre 1.6.5 source code」· C语言 代码 · 共 511 行 · 第 1/2 页

C
511
字号
/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- * vim:expandtab:shiftwidth=8:tabstop=8: * *  lustre/lib/lvfs_linux.c *  Lustre filesystem abstraction routines * *  Copyright (C) 2002, 2003 Cluster File Systems, Inc. *   Author: Andreas Dilger <adilger@clusterfs.com> * *   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. */#ifndef EXPORT_SYMTAB# define EXPORT_SYMTAB#endif#define DEBUG_SUBSYSTEM S_FILTER#include <linux/version.h>#include <linux/fs.h>#include <asm/unistd.h>#include <linux/slab.h>#include <linux/pagemap.h>#include <linux/quotaops.h>#include <linux/version.h>#include <libcfs/kp30.h>#include <lustre_fsfilt.h>#include <obd.h>#include <linux/module.h>#include <linux/init.h>#include <linux/lustre_compat25.h>#include <lvfs.h>#include "lvfs_internal.h"#include <obd.h>#include <lustre_lib.h>#include <lustre_quota.h>/* 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) LASSERTF(!segment_eq(get_fs(), get_ds()),\                                              msg)# define ASSERT_KERNEL_CTXT(msg) LASSERTF(segment_eq(get_fs(), get_ds()), msg)#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)#endifstatic void push_group_info(struct lvfs_run_ctxt *save,                            struct upcall_cache_entry *uce){        struct group_info *ginfo = uce ? uce->ue_group_info : NULL;        if (!ginfo) {                save->ngroups = current_ngroups;                current_ngroups = 0;        } else {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)                task_lock(current);                save->group_info = current->group_info;                current->group_info = ginfo;                task_unlock(current);#else                LASSERT(ginfo->ngroups <= NGROUPS);                LASSERT(current->ngroups <= NGROUPS_SMALL);                /* save old */                save->group_info.ngroups = current->ngroups;                if (current->ngroups)                        memcpy(save->group_info.small_block, current->groups,                               current->ngroups * sizeof(gid_t));                /* push new */                current->ngroups = ginfo->ngroups;                if (ginfo->ngroups)                        memcpy(current->groups, ginfo->small_block,                               current->ngroups * sizeof(gid_t));#endif        }}static void pop_group_info(struct lvfs_run_ctxt *save,                           struct upcall_cache_entry *uce){        struct group_info *ginfo = uce ? uce->ue_group_info : NULL;        if (!ginfo) {                current_ngroups = save->ngroups;        } else {#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,4)                task_lock(current);                current->group_info = save->group_info;                task_unlock(current);#else                current->ngroups = save->group_info.ngroups;                if (current->ngroups)                        memcpy(current->groups, save->group_info.small_block,                               current->ngroups * sizeof(gid_t));#endif        }}/* push / pop to root of obd store */void push_ctxt(struct lvfs_run_ctxt *save, struct lvfs_run_ctxt *new_ctx,               struct lvfs_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(&current->fs->pwd->d_count),               atomic_read(&current->fs->pwd->d_inode->i_count),               current->fs->pwd->d_name.len, current->fs->pwd->d_name.name,               current->fs->pwdmnt,               atomic_read(&current->fs->pwdmnt->mnt_count));        */        save->fs = get_fs();        LASSERT(atomic_read(&current->fs->pwd->d_count));        LASSERT(atomic_read(&new_ctx->pwd->d_count));        save->pwd = dget(current->fs->pwd);        save->pwdmnt = mntget(current->fs->pwdmnt);        save->luc.luc_umask = current->fs->umask;        LASSERT(save->pwd);        LASSERT(save->pwdmnt);        LASSERT(new_ctx->pwd);        LASSERT(new_ctx->pwdmnt);        if (uc) {                save->luc.luc_fsuid = current->fsuid;                save->luc.luc_fsgid = current->fsgid;                save->luc.luc_cap = current->cap_effective;                current->fsuid = uc->luc_fsuid;                current->fsgid = uc->luc_fsgid;                current->cap_effective = uc->luc_cap;                push_group_info(save, uc->luc_uce);        }        current->fs->umask = 0; /* umask already applied on client */        set_fs(new_ctx->fs);        ll_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(&current->fs->pwd->d_count),               atomic_read(&current->fs->pwd->d_inode->i_count),               current->fs->pwd->d_name.len, current->fs->pwd->d_name.name,               current->fs->pwdmnt,               atomic_read(&current->fs->pwdmnt->mnt_count));        */}EXPORT_SYMBOL(push_ctxt);void pop_ctxt(struct lvfs_run_ctxt *saved, struct lvfs_run_ctxt *new_ctx,              struct lvfs_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(&current->fs->pwd->d_count),               atomic_read(&current->fs->pwd->d_inode->i_count),               current->fs->pwd->d_name.len, current->fs->pwd->d_name.name,               current->fs->pwdmnt,               atomic_read(&current->fs->pwdmnt->mnt_count));        */        LASSERTF(current->fs->pwd == new_ctx->pwd, "%p != %p\n",                 current->fs->pwd, new_ctx->pwd);        LASSERTF(current->fs->pwdmnt == new_ctx->pwdmnt, "%p != %p\n",                 current->fs->pwdmnt, new_ctx->pwdmnt);        set_fs(saved->fs);        ll_set_fs_pwd(current->fs, saved->pwdmnt, saved->pwd);        dput(saved->pwd);        mntput(saved->pwdmnt);        current->fs->umask = saved->luc.luc_umask;        if (uc) {                current->fsuid = saved->luc.luc_fsuid;                current->fsgid = saved->luc.luc_fsgid;                current->cap_effective = saved->luc.luc_cap;                pop_group_info(saved, uc->luc_uce);        }        /*        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(&current->fs->pwd->d_count),               atomic_read(&current->fs->pwd->d_inode->i_count),               current->fs->pwd->d_name.len, current->fs->pwd->d_name.name,               current->fs->pwdmnt,               atomic_read(&current->fs->pwdmnt->mnt_count));        */}EXPORT_SYMBOL(pop_ctxt);/* utility to make a file */struct dentry *simple_mknod(struct dentry *dir, char *name, int mode, int fix){        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 = ll_lookup_one_len(name, dir, strlen(name));        if (IS_ERR(dchild))                GOTO(out_up, dchild);        if (dchild->d_inode) {                int old_mode = dchild->d_inode->i_mode;                if (!S_ISREG(old_mode))                        GOTO(out_err, err = -EEXIST);                /* Fixup file permissions if necessary */                if (fix && (old_mode & S_IALLUGO) != (mode & S_IALLUGO)) {                        CWARN("fixing permissions on %s from %o to %o\n",                              name, old_mode, mode);                        dchild->d_inode->i_mode = (mode & S_IALLUGO) |                                                  (old_mode & ~S_IALLUGO);                        mark_inode_dirty(dchild->d_inode);                }                GOTO(out_up, dchild);        }        err = ll_vfs_create(dir->d_inode, dchild, (mode & ~S_IFMT) | S_IFREG,                            NULL);        if (err)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?