提交 274dcf55 编写于 作者: M Mike Marshall

Orangefs: kernel client part 3

Signed-off-by: NMike Marshall <hubcap@omnibond.com>
上级 5db11c21
/*
* (C) 2001 Clemson University and The University of Chicago
*
* See COPYING in top-level directory.
*/
/*
* Linux VFS namei operations.
*/
#include "protocol.h"
#include "pvfs2-kernel.h"
/*
* Get a newly allocated inode to go with a negative dentry.
*/
static int pvfs2_create(struct inode *dir,
struct dentry *dentry,
umode_t mode,
bool exclusive)
{
struct pvfs2_inode_s *parent = PVFS2_I(dir);
struct pvfs2_kernel_op_s *new_op;
struct inode *inode;
int ret;
gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
new_op = op_alloc(PVFS2_VFS_OP_CREATE);
if (!new_op)
return -ENOMEM;
new_op->upcall.req.create.parent_refn = parent->refn;
fill_default_sys_attrs(new_op->upcall.req.create.attributes,
PVFS_TYPE_METAFILE, mode);
strncpy(new_op->upcall.req.create.d_name,
dentry->d_name.name, PVFS2_NAME_LEN);
ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
gossip_debug(GOSSIP_NAME_DEBUG,
"Create Got PVFS2 handle %pU on fsid %d (ret=%d)\n",
&new_op->downcall.resp.create.refn.khandle,
new_op->downcall.resp.create.refn.fs_id, ret);
if (ret < 0) {
gossip_debug(GOSSIP_NAME_DEBUG,
"%s: failed with error code %d\n",
__func__, ret);
goto out;
}
inode = pvfs2_new_inode(dir->i_sb, dir, S_IFREG | mode, 0,
&new_op->downcall.resp.create.refn);
if (IS_ERR(inode)) {
gossip_err("*** Failed to allocate pvfs2 file inode\n");
ret = PTR_ERR(inode);
goto out;
}
gossip_debug(GOSSIP_NAME_DEBUG,
"Assigned file inode new number of %pU\n",
get_khandle_from_ino(inode));
d_instantiate(dentry, inode);
unlock_new_inode(inode);
gossip_debug(GOSSIP_NAME_DEBUG,
"Inode (Regular File) %pU -> %s\n",
get_khandle_from_ino(inode),
dentry->d_name.name);
SetMtimeFlag(parent);
dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
mark_inode_dirty_sync(dir);
ret = 0;
out:
op_release(new_op);
gossip_debug(GOSSIP_NAME_DEBUG, "%s: returning %d\n", __func__, ret);
return ret;
}
/*
* Attempt to resolve an object name (dentry->d_name), parent handle, and
* fsid into a handle for the object.
*/
static struct dentry *pvfs2_lookup(struct inode *dir, struct dentry *dentry,
unsigned int flags)
{
struct pvfs2_inode_s *parent = PVFS2_I(dir);
struct pvfs2_kernel_op_s *new_op;
struct inode *inode;
struct dentry *res;
int ret = -EINVAL;
/*
* in theory we could skip a lookup here (if the intent is to
* create) in order to avoid a potentially failed lookup, but
* leaving it in can skip a valid lookup and try to create a file
* that already exists (e.g. the vfs already handles checking for
* -EEXIST on O_EXCL opens, which is broken if we skip this lookup
* in the create path)
*/
gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %s\n",
__func__, dentry->d_name.name);
if (dentry->d_name.len > (PVFS2_NAME_LEN - 1))
return ERR_PTR(-ENAMETOOLONG);
new_op = op_alloc(PVFS2_VFS_OP_LOOKUP);
if (!new_op)
return ERR_PTR(-ENOMEM);
new_op->upcall.req.lookup.sym_follow = flags & LOOKUP_FOLLOW;
gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n",
__FILE__,
__func__,
__LINE__,
&parent->refn.khandle);
new_op->upcall.req.lookup.parent_refn = parent->refn;
strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
PVFS2_NAME_LEN);
gossip_debug(GOSSIP_NAME_DEBUG,
"%s: doing lookup on %s under %pU,%d (follow=%s)\n",
__func__,
new_op->upcall.req.lookup.d_name,
&new_op->upcall.req.lookup.parent_refn.khandle,
new_op->upcall.req.lookup.parent_refn.fs_id,
((new_op->upcall.req.lookup.sym_follow ==
PVFS2_LOOKUP_LINK_FOLLOW) ? "yes" : "no"));
ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
gossip_debug(GOSSIP_NAME_DEBUG,
"Lookup Got %pU, fsid %d (ret=%d)\n",
&new_op->downcall.resp.lookup.refn.khandle,
new_op->downcall.resp.lookup.refn.fs_id,
ret);
if (ret < 0) {
if (ret == -ENOENT) {
/*
* if no inode was found, add a negative dentry to
* dcache anyway; if we don't, we don't hold expected
* lookup semantics and we most noticeably break
* during directory renames.
*
* however, if the operation failed or exited, do not
* add the dentry (e.g. in the case that a touch is
* issued on a file that already exists that was
* interrupted during this lookup -- no need to add
* another negative dentry for an existing file)
*/
gossip_debug(GOSSIP_NAME_DEBUG,
"pvfs2_lookup: Adding *negative* dentry "
"%p for %s\n",
dentry,
dentry->d_name.name);
d_add(dentry, NULL);
res = NULL;
goto out;
}
/* must be a non-recoverable error */
res = ERR_PTR(ret);
goto out;
}
inode = pvfs2_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
if (IS_ERR(inode)) {
gossip_debug(GOSSIP_NAME_DEBUG,
"error %ld from iget\n", PTR_ERR(inode));
res = ERR_CAST(inode);
goto out;
}
gossip_debug(GOSSIP_NAME_DEBUG,
"%s:%s:%d "
"Found good inode [%lu] with count [%d]\n",
__FILE__,
__func__,
__LINE__,
inode->i_ino,
(int)atomic_read(&inode->i_count));
/* update dentry/inode pair into dcache */
res = d_splice_alias(inode, dentry);
gossip_debug(GOSSIP_NAME_DEBUG,
"Lookup success (inode ct = %d)\n",
(int)atomic_read(&inode->i_count));
out:
op_release(new_op);
return res;
}
/* return 0 on success; non-zero otherwise */
static int pvfs2_unlink(struct inode *dir, struct dentry *dentry)
{
struct inode *inode = dentry->d_inode;
struct pvfs2_inode_s *parent = PVFS2_I(dir);
struct pvfs2_kernel_op_s *new_op;
int ret;
gossip_debug(GOSSIP_NAME_DEBUG,
"%s: called on %s\n"
" (inode %pU): Parent is %pU | fs_id %d\n",
__func__,
dentry->d_name.name,
get_khandle_from_ino(inode),
&parent->refn.khandle,
parent->refn.fs_id);
new_op = op_alloc(PVFS2_VFS_OP_REMOVE);
if (!new_op)
return -ENOMEM;
new_op->upcall.req.remove.parent_refn = parent->refn;
strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
PVFS2_NAME_LEN);
ret = service_operation(new_op, "pvfs2_unlink",
get_interruptible_flag(inode));
/* when request is serviced properly, free req op struct */
op_release(new_op);
if (!ret) {
drop_nlink(inode);
SetMtimeFlag(parent);
dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
mark_inode_dirty_sync(dir);
}
return ret;
}
/*
* pvfs2_link() is only implemented here to make sure that we return a
* reasonable error code (the kernel will return a misleading EPERM
* otherwise). PVFS2 does not support hard links.
*/
static int pvfs2_link(struct dentry *old_dentry,
struct inode *dir,
struct dentry *dentry)
{
return -EOPNOTSUPP;
}
/*
* pvfs2_mknod() is only implemented here to make sure that we return a
* reasonable error code (the kernel will return a misleading EPERM
* otherwise). PVFS2 does not support special files such as fifos or devices.
*/
static int pvfs2_mknod(struct inode *dir,
struct dentry *dentry,
umode_t mode,
dev_t rdev)
{
return -EOPNOTSUPP;
}
static int pvfs2_symlink(struct inode *dir,
struct dentry *dentry,
const char *symname)
{
struct pvfs2_inode_s *parent = PVFS2_I(dir);
struct pvfs2_kernel_op_s *new_op;
struct inode *inode;
int mode = 755;
int ret;
gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
if (!symname)
return -EINVAL;
new_op = op_alloc(PVFS2_VFS_OP_SYMLINK);
if (!new_op)
return -ENOMEM;
new_op->upcall.req.sym.parent_refn = parent->refn;
fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
PVFS_TYPE_SYMLINK,
mode);
strncpy(new_op->upcall.req.sym.entry_name,
dentry->d_name.name,
PVFS2_NAME_LEN);
strncpy(new_op->upcall.req.sym.target, symname, PVFS2_NAME_LEN);
ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
gossip_debug(GOSSIP_NAME_DEBUG,
"Symlink Got PVFS2 handle %pU on fsid %d (ret=%d)\n",
&new_op->downcall.resp.sym.refn.khandle,
new_op->downcall.resp.sym.refn.fs_id, ret);
if (ret < 0) {
gossip_debug(GOSSIP_NAME_DEBUG,
"%s: failed with error code %d\n",
__func__, ret);
goto out;
}
inode = pvfs2_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0,
&new_op->downcall.resp.sym.refn);
if (IS_ERR(inode)) {
gossip_err
("*** Failed to allocate pvfs2 symlink inode\n");
ret = PTR_ERR(inode);
goto out;
}
gossip_debug(GOSSIP_NAME_DEBUG,
"Assigned symlink inode new number of %pU\n",
get_khandle_from_ino(inode));
d_instantiate(dentry, inode);
unlock_new_inode(inode);
gossip_debug(GOSSIP_NAME_DEBUG,
"Inode (Symlink) %pU -> %s\n",
get_khandle_from_ino(inode),
dentry->d_name.name);
SetMtimeFlag(parent);
dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
mark_inode_dirty_sync(dir);
ret = 0;
out:
op_release(new_op);
return ret;
}
static int pvfs2_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
{
struct pvfs2_inode_s *parent = PVFS2_I(dir);
struct pvfs2_kernel_op_s *new_op;
struct inode *inode;
int ret;
new_op = op_alloc(PVFS2_VFS_OP_MKDIR);
if (!new_op)
return -ENOMEM;
new_op->upcall.req.mkdir.parent_refn = parent->refn;
fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
PVFS_TYPE_DIRECTORY, mode);
strncpy(new_op->upcall.req.mkdir.d_name,
dentry->d_name.name, PVFS2_NAME_LEN);
ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
gossip_debug(GOSSIP_NAME_DEBUG,
"Mkdir Got PVFS2 handle %pU on fsid %d\n",
&new_op->downcall.resp.mkdir.refn.khandle,
new_op->downcall.resp.mkdir.refn.fs_id);
if (ret < 0) {
gossip_debug(GOSSIP_NAME_DEBUG,
"%s: failed with error code %d\n",
__func__, ret);
goto out;
}
inode = pvfs2_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0,
&new_op->downcall.resp.mkdir.refn);
if (IS_ERR(inode)) {
gossip_err("*** Failed to allocate pvfs2 dir inode\n");
ret = PTR_ERR(inode);
goto out;
}
gossip_debug(GOSSIP_NAME_DEBUG,
"Assigned dir inode new number of %pU\n",
get_khandle_from_ino(inode));
d_instantiate(dentry, inode);
unlock_new_inode(inode);
gossip_debug(GOSSIP_NAME_DEBUG,
"Inode (Directory) %pU -> %s\n",
get_khandle_from_ino(inode),
dentry->d_name.name);
/*
* NOTE: we have no good way to keep nlink consistent for directories
* across clients; keep constant at 1.
*/
SetMtimeFlag(parent);
dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
mark_inode_dirty_sync(dir);
out:
op_release(new_op);
return ret;
}
static int pvfs2_rename(struct inode *old_dir,
struct dentry *old_dentry,
struct inode *new_dir,
struct dentry *new_dentry)
{
struct pvfs2_kernel_op_s *new_op;
int ret;
gossip_debug(GOSSIP_NAME_DEBUG,
"pvfs2_rename: called (%s/%s => %s/%s) ct=%d\n",
old_dentry->d_parent->d_name.name,
old_dentry->d_name.name,
new_dentry->d_parent->d_name.name,
new_dentry->d_name.name,
d_count(new_dentry));
new_op = op_alloc(PVFS2_VFS_OP_RENAME);
if (!new_op)
return -EINVAL;
new_op->upcall.req.rename.old_parent_refn = PVFS2_I(old_dir)->refn;
new_op->upcall.req.rename.new_parent_refn = PVFS2_I(new_dir)->refn;
strncpy(new_op->upcall.req.rename.d_old_name,
old_dentry->d_name.name,
PVFS2_NAME_LEN);
strncpy(new_op->upcall.req.rename.d_new_name,
new_dentry->d_name.name,
PVFS2_NAME_LEN);
ret = service_operation(new_op,
"pvfs2_rename",
get_interruptible_flag(old_dentry->d_inode));
gossip_debug(GOSSIP_NAME_DEBUG,
"pvfs2_rename: got downcall status %d\n",
ret);
if (new_dentry->d_inode)
new_dentry->d_inode->i_ctime = CURRENT_TIME;
op_release(new_op);
return ret;
}
/* PVFS2 implementation of VFS inode operations for directories */
struct inode_operations pvfs2_dir_inode_operations = {
.lookup = pvfs2_lookup,
.get_acl = pvfs2_get_acl,
.set_acl = pvfs2_set_acl,
.create = pvfs2_create,
.link = pvfs2_link,
.unlink = pvfs2_unlink,
.symlink = pvfs2_symlink,
.mkdir = pvfs2_mkdir,
.rmdir = pvfs2_unlink,
.mknod = pvfs2_mknod,
.rename = pvfs2_rename,
.setattr = pvfs2_setattr,
.getattr = pvfs2_getattr,
.setxattr = generic_setxattr,
.getxattr = generic_getxattr,
.removexattr = generic_removexattr,
.listxattr = pvfs2_listxattr,
};
此差异已折叠。
/*
* (C) 2001 Clemson University and The University of Chicago
*
* See COPYING in top-level directory.
*/
#include "protocol.h"
#include "pvfs2-kernel.h"
/* tags assigned to kernel upcall operations */
static __u64 next_tag_value;
static DEFINE_SPINLOCK(next_tag_value_lock);
/* the pvfs2 memory caches */
/* a cache for pvfs2 upcall/downcall operations */
static struct kmem_cache *op_cache;
/* a cache for device (/dev/pvfs2-req) communication */
static struct kmem_cache *dev_req_cache;
/* a cache for pvfs2_kiocb objects (i.e pvfs2 iocb structures ) */
static struct kmem_cache *pvfs2_kiocb_cache;
int op_cache_initialize(void)
{
op_cache = kmem_cache_create("pvfs2_op_cache",
sizeof(struct pvfs2_kernel_op_s),
0,
PVFS2_CACHE_CREATE_FLAGS,
NULL);
if (!op_cache) {
gossip_err("Cannot create pvfs2_op_cache\n");
return -ENOMEM;
}
/* initialize our atomic tag counter */
spin_lock(&next_tag_value_lock);
next_tag_value = 100;
spin_unlock(&next_tag_value_lock);
return 0;
}
int op_cache_finalize(void)
{
kmem_cache_destroy(op_cache);
return 0;
}
char *get_opname_string(struct pvfs2_kernel_op_s *new_op)
{
if (new_op) {
__s32 type = new_op->upcall.type;
if (type == PVFS2_VFS_OP_FILE_IO)
return "OP_FILE_IO";
else if (type == PVFS2_VFS_OP_LOOKUP)
return "OP_LOOKUP";
else if (type == PVFS2_VFS_OP_CREATE)
return "OP_CREATE";
else if (type == PVFS2_VFS_OP_GETATTR)
return "OP_GETATTR";
else if (type == PVFS2_VFS_OP_REMOVE)
return "OP_REMOVE";
else if (type == PVFS2_VFS_OP_MKDIR)
return "OP_MKDIR";
else if (type == PVFS2_VFS_OP_READDIR)
return "OP_READDIR";
else if (type == PVFS2_VFS_OP_READDIRPLUS)
return "OP_READDIRPLUS";
else if (type == PVFS2_VFS_OP_SETATTR)
return "OP_SETATTR";
else if (type == PVFS2_VFS_OP_SYMLINK)
return "OP_SYMLINK";
else if (type == PVFS2_VFS_OP_RENAME)
return "OP_RENAME";
else if (type == PVFS2_VFS_OP_STATFS)
return "OP_STATFS";
else if (type == PVFS2_VFS_OP_TRUNCATE)
return "OP_TRUNCATE";
else if (type == PVFS2_VFS_OP_MMAP_RA_FLUSH)
return "OP_MMAP_RA_FLUSH";
else if (type == PVFS2_VFS_OP_FS_MOUNT)
return "OP_FS_MOUNT";
else if (type == PVFS2_VFS_OP_FS_UMOUNT)
return "OP_FS_UMOUNT";
else if (type == PVFS2_VFS_OP_GETXATTR)
return "OP_GETXATTR";
else if (type == PVFS2_VFS_OP_SETXATTR)
return "OP_SETXATTR";
else if (type == PVFS2_VFS_OP_LISTXATTR)
return "OP_LISTXATTR";
else if (type == PVFS2_VFS_OP_REMOVEXATTR)
return "OP_REMOVEXATTR";
else if (type == PVFS2_VFS_OP_PARAM)
return "OP_PARAM";
else if (type == PVFS2_VFS_OP_PERF_COUNT)
return "OP_PERF_COUNT";
else if (type == PVFS2_VFS_OP_CANCEL)
return "OP_CANCEL";
else if (type == PVFS2_VFS_OP_FSYNC)
return "OP_FSYNC";
else if (type == PVFS2_VFS_OP_FSKEY)
return "OP_FSKEY";
else if (type == PVFS2_VFS_OP_FILE_IOX)
return "OP_FILE_IOX";
}
return "OP_UNKNOWN?";
}
static struct pvfs2_kernel_op_s *op_alloc_common(__s32 op_linger, __s32 type)
{
struct pvfs2_kernel_op_s *new_op = NULL;
new_op = kmem_cache_alloc(op_cache, PVFS2_CACHE_ALLOC_FLAGS);
if (new_op) {
memset(new_op, 0, sizeof(struct pvfs2_kernel_op_s));
INIT_LIST_HEAD(&new_op->list);
spin_lock_init(&new_op->lock);
init_waitqueue_head(&new_op->waitq);
init_waitqueue_head(&new_op->io_completion_waitq);
atomic_set(&new_op->aio_ref_count, 0);
pvfs2_op_initialize(new_op);
/* initialize the op specific tag and upcall credentials */
spin_lock(&next_tag_value_lock);
new_op->tag = next_tag_value++;
if (next_tag_value == 0)
next_tag_value = 100;
spin_unlock(&next_tag_value_lock);
new_op->upcall.type = type;
new_op->attempts = 0;
gossip_debug(GOSSIP_CACHE_DEBUG,
"Alloced OP (%p: %llu %s)\n",
new_op,
llu(new_op->tag),
get_opname_string(new_op));
new_op->upcall.uid = from_kuid(current_user_ns(),
current_fsuid());
new_op->upcall.gid = from_kgid(current_user_ns(),
current_fsgid());
new_op->op_linger = new_op->op_linger_tmp = op_linger;
} else {
gossip_err("op_alloc: kmem_cache_alloc failed!\n");
}
return new_op;
}
struct pvfs2_kernel_op_s *op_alloc(__s32 type)
{
return op_alloc_common(1, type);
}
struct pvfs2_kernel_op_s *op_alloc_trailer(__s32 type)
{
return op_alloc_common(2, type);
}
void op_release(struct pvfs2_kernel_op_s *pvfs2_op)
{
if (pvfs2_op) {
gossip_debug(GOSSIP_CACHE_DEBUG,
"Releasing OP (%p: %llu)\n",
pvfs2_op,
llu(pvfs2_op->tag));
pvfs2_op_initialize(pvfs2_op);
kmem_cache_free(op_cache, pvfs2_op);
} else {
gossip_err("NULL pointer in op_release\n");
}
}
int dev_req_cache_initialize(void)
{
dev_req_cache = kmem_cache_create("pvfs2_devreqcache",
MAX_ALIGNED_DEV_REQ_DOWNSIZE,
0,
PVFS2_CACHE_CREATE_FLAGS,
NULL);
if (!dev_req_cache) {
gossip_err("Cannot create pvfs2_dev_req_cache\n");
return -ENOMEM;
}
return 0;
}
int dev_req_cache_finalize(void)
{
kmem_cache_destroy(dev_req_cache);
return 0;
}
void *dev_req_alloc(void)
{
void *buffer;
buffer = kmem_cache_alloc(dev_req_cache, PVFS2_CACHE_ALLOC_FLAGS);
if (buffer == NULL)
gossip_err("Failed to allocate from dev_req_cache\n");
else
memset(buffer, 0, sizeof(MAX_ALIGNED_DEV_REQ_DOWNSIZE));
return buffer;
}
void dev_req_release(void *buffer)
{
if (buffer)
kmem_cache_free(dev_req_cache, buffer);
else
gossip_err("NULL pointer passed to dev_req_release\n");
}
int kiocb_cache_initialize(void)
{
pvfs2_kiocb_cache = kmem_cache_create("pvfs2_kiocbcache",
sizeof(struct pvfs2_kiocb_s),
0,
PVFS2_CACHE_CREATE_FLAGS,
NULL);
if (!pvfs2_kiocb_cache) {
gossip_err("Cannot create pvfs2_kiocb_cache!\n");
return -ENOMEM;
}
return 0;
}
int kiocb_cache_finalize(void)
{
kmem_cache_destroy(pvfs2_kiocb_cache);
return 0;
}
struct pvfs2_kiocb_s *kiocb_alloc(void)
{
struct pvfs2_kiocb_s *x = NULL;
x = kmem_cache_alloc(pvfs2_kiocb_cache, PVFS2_CACHE_ALLOC_FLAGS);
if (x == NULL)
gossip_err("kiocb_alloc: kmem_cache_alloc failed!\n");
else
memset(x, 0, sizeof(struct pvfs2_kiocb_s));
return x;
}
void kiocb_release(struct pvfs2_kiocb_s *x)
{
if (x)
kmem_cache_free(pvfs2_kiocb_cache, x);
else
gossip_err("kiocb_release: kmem_cache_free NULL pointer!\n");
}
/*
* What: /sys/kernel/debug/orangefs/debug-help
* Date: June 2015
* Contact: Mike Marshall <hubcap@omnibond.com>
* Description:
* List of client and kernel debug keywords.
*
*
* What: /sys/kernel/debug/orangefs/client-debug
* Date: June 2015
* Contact: Mike Marshall <hubcap@omnibond.com>
* Description:
* Debug setting for "the client", the userspace
* helper for the kernel module.
*
*
* What: /sys/kernel/debug/orangefs/kernel-debug
* Date: June 2015
* Contact: Mike Marshall <hubcap@omnibond.com>
* Description:
* Debug setting for the orangefs kernel module.
*
* Any of the keywords, or comma-separated lists
* of keywords, from debug-help can be catted to
* client-debug or kernel-debug.
*
* "none", "all" and "verbose" are special keywords
* for client-debug. Setting client-debug to "all"
* is kind of like trying to drink water from a
* fire hose, "verbose" triggers most of the same
* output except for the constant flow of output
* from the main wait loop.
*
* "none" and "all" are similar settings for kernel-debug
* no need for a "verbose".
*/
#include <linux/debugfs.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include "pvfs2-debugfs.h"
#include "protocol.h"
#include "pvfs2-kernel.h"
static int orangefs_debug_disabled = 1;
static int orangefs_debug_help_open(struct inode *, struct file *);
const struct file_operations debug_help_fops = {
.open = orangefs_debug_help_open,
.read = seq_read,
.release = seq_release,
.llseek = seq_lseek,
};
static void *help_start(struct seq_file *, loff_t *);
static void *help_next(struct seq_file *, void *, loff_t *);
static void help_stop(struct seq_file *, void *);
static int help_show(struct seq_file *, void *);
static const struct seq_operations help_debug_ops = {
.start = help_start,
.next = help_next,
.stop = help_stop,
.show = help_show,
};
/*
* Used to protect data in ORANGEFS_KMOD_DEBUG_FILE and
* ORANGEFS_KMOD_DEBUG_FILE.
*/
DEFINE_MUTEX(orangefs_debug_lock);
int orangefs_debug_open(struct inode *, struct file *);
static ssize_t orangefs_debug_read(struct file *,
char __user *,
size_t,
loff_t *);
static ssize_t orangefs_debug_write(struct file *,
const char __user *,
size_t,
loff_t *);
static const struct file_operations kernel_debug_fops = {
.open = orangefs_debug_open,
.read = orangefs_debug_read,
.write = orangefs_debug_write,
.llseek = generic_file_llseek,
};
/*
* initialize kmod debug operations, create orangefs debugfs dir and
* ORANGEFS_KMOD_DEBUG_HELP_FILE.
*/
int pvfs2_debugfs_init(void)
{
int rc = -ENOMEM;
debug_dir = debugfs_create_dir("orangefs", NULL);
if (!debug_dir)
goto out;
help_file_dentry = debugfs_create_file(ORANGEFS_KMOD_DEBUG_HELP_FILE,
0444,
debug_dir,
debug_help_string,
&debug_help_fops);
if (!help_file_dentry)
goto out;
orangefs_debug_disabled = 0;
rc = 0;
out:
if (rc)
pvfs2_debugfs_cleanup();
return rc;
}
void pvfs2_debugfs_cleanup(void)
{
debugfs_remove_recursive(debug_dir);
}
/* open ORANGEFS_KMOD_DEBUG_HELP_FILE */
static int orangefs_debug_help_open(struct inode *inode, struct file *file)
{
int rc = -ENODEV;
int ret;
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
"orangefs_debug_help_open: start\n");
if (orangefs_debug_disabled)
goto out;
ret = seq_open(file, &help_debug_ops);
if (ret)
goto out;
((struct seq_file *)(file->private_data))->private = inode->i_private;
rc = 0;
out:
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
"orangefs_debug_help_open: rc:%d:\n",
rc);
return rc;
}
/*
* I think start always gets called again after stop. Start
* needs to return NULL when it is done. The whole "payload"
* in this case is a single (long) string, so by the second
* time we get to start (pos = 1), we're done.
*/
static void *help_start(struct seq_file *m, loff_t *pos)
{
void *payload = NULL;
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_start: start\n");
if (*pos == 0)
payload = m->private;
return payload;
}
static void *help_next(struct seq_file *m, void *v, loff_t *pos)
{
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_next: start\n");
return NULL;
}
static void help_stop(struct seq_file *m, void *p)
{
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_stop: start\n");
}
static int help_show(struct seq_file *m, void *v)
{
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "help_show: start\n");
seq_puts(m, v);
return 0;
}
/*
* initialize the kernel-debug file.
*/
int pvfs2_kernel_debug_init(void)
{
int rc = -ENOMEM;
struct dentry *ret;
char *k_buffer = NULL;
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: start\n", __func__);
k_buffer = kzalloc(PVFS2_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
if (!k_buffer)
goto out;
if (strlen(kernel_debug_string) + 1 < PVFS2_MAX_DEBUG_STRING_LEN) {
strcpy(k_buffer, kernel_debug_string);
strcat(k_buffer, "\n");
} else {
strcpy(k_buffer, "none\n");
pr_info("%s: overflow 1!\n", __func__);
}
ret = debugfs_create_file(ORANGEFS_KMOD_DEBUG_FILE,
0444,
debug_dir,
k_buffer,
&kernel_debug_fops);
if (!ret) {
pr_info("%s: failed to create %s.\n",
__func__,
ORANGEFS_KMOD_DEBUG_FILE);
goto out;
}
rc = 0;
out:
if (rc)
pvfs2_debugfs_cleanup();
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: rc:%d:\n", __func__, rc);
return rc;
}
/*
* initialize the client-debug file.
*/
int pvfs2_client_debug_init(void)
{
int rc = -ENOMEM;
char *c_buffer = NULL;
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: start\n", __func__);
c_buffer = kzalloc(PVFS2_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
if (!c_buffer)
goto out;
if (strlen(client_debug_string) + 1 < PVFS2_MAX_DEBUG_STRING_LEN) {
strcpy(c_buffer, client_debug_string);
strcat(c_buffer, "\n");
} else {
strcpy(c_buffer, "none\n");
pr_info("%s: overflow! 2\n", __func__);
}
client_debug_dentry = debugfs_create_file(ORANGEFS_CLIENT_DEBUG_FILE,
0444,
debug_dir,
c_buffer,
&kernel_debug_fops);
if (!client_debug_dentry) {
pr_info("%s: failed to create %s.\n",
__func__,
ORANGEFS_CLIENT_DEBUG_FILE);
goto out;
}
rc = 0;
out:
if (rc)
pvfs2_debugfs_cleanup();
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "%s: rc:%d:\n", __func__, rc);
return rc;
}
/* open ORANGEFS_KMOD_DEBUG_FILE or ORANGEFS_CLIENT_DEBUG_FILE.*/
int orangefs_debug_open(struct inode *inode, struct file *file)
{
int rc = -ENODEV;
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
"%s: orangefs_debug_disabled: %d\n",
__func__,
orangefs_debug_disabled);
if (orangefs_debug_disabled)
goto out;
rc = 0;
mutex_lock(&orangefs_debug_lock);
file->private_data = inode->i_private;
mutex_unlock(&orangefs_debug_lock);
out:
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
"orangefs_debug_open: rc: %d\n",
rc);
return rc;
}
static ssize_t orangefs_debug_read(struct file *file,
char __user *ubuf,
size_t count,
loff_t *ppos)
{
char *buf;
int sprintf_ret;
ssize_t read_ret = -ENOMEM;
gossip_debug(GOSSIP_DEBUGFS_DEBUG, "orangefs_debug_read: start\n");
buf = kmalloc(PVFS2_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
if (!buf)
goto out;
mutex_lock(&orangefs_debug_lock);
sprintf_ret = sprintf(buf, "%s", (char *)file->private_data);
mutex_unlock(&orangefs_debug_lock);
read_ret = simple_read_from_buffer(ubuf, count, ppos, buf, sprintf_ret);
kfree(buf);
out:
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
"orangefs_debug_read: ret: %zu\n",
read_ret);
return read_ret;
}
static ssize_t orangefs_debug_write(struct file *file,
const char __user *ubuf,
size_t count,
loff_t *ppos)
{
char *buf;
int rc = -EFAULT;
size_t silly = 0;
char *debug_string;
struct pvfs2_kernel_op_s *new_op = NULL;
struct client_debug_mask c_mask = { NULL, 0, 0 };
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
"orangefs_debug_write: %s\n",
file->f_path.dentry->d_name.name);
/*
* Thwart users who try to jamb a ridiculous number
* of bytes into the debug file...
*/
if (count > PVFS2_MAX_DEBUG_STRING_LEN + 1) {
silly = count;
count = PVFS2_MAX_DEBUG_STRING_LEN + 1;
}
buf = kmalloc(PVFS2_MAX_DEBUG_STRING_LEN, GFP_KERNEL);
if (!buf)
goto out;
memset(buf, 0, PVFS2_MAX_DEBUG_STRING_LEN);
if (copy_from_user(buf, ubuf, count - 1)) {
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
"%s: copy_from_user failed!\n",
__func__);
goto out;
}
/*
* Map the keyword string from userspace into a valid debug mask.
* The mapping process involves mapping the human-inputted string
* into a valid mask, and then rebuilding the string from the
* verified valid mask.
*
* A service operation is required to set a new client-side
* debug mask.
*/
if (!strcmp(file->f_path.dentry->d_name.name,
ORANGEFS_KMOD_DEBUG_FILE)) {
debug_string_to_mask(buf, &gossip_debug_mask, 0);
debug_mask_to_string(&gossip_debug_mask, 0);
debug_string = kernel_debug_string;
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
"New kernel debug string is %s\n",
kernel_debug_string);
} else {
/* Can't reset client debug mask if client is not running. */
if (is_daemon_in_service()) {
pr_info("%s: Client not running :%d:\n",
__func__,
is_daemon_in_service());
goto out;
}
debug_string_to_mask(buf, &c_mask, 1);
debug_mask_to_string(&c_mask, 1);
debug_string = client_debug_string;
new_op = op_alloc(PVFS2_VFS_OP_PARAM);
if (!new_op) {
pr_info("%s: op_alloc failed!\n", __func__);
goto out;
}
new_op->upcall.req.param.op =
PVFS2_PARAM_REQUEST_OP_TWO_MASK_VALUES;
new_op->upcall.req.param.type = PVFS2_PARAM_REQUEST_SET;
memset(new_op->upcall.req.param.s_value,
0,
PVFS2_MAX_DEBUG_STRING_LEN);
sprintf(new_op->upcall.req.param.s_value,
"%llx %llx\n",
c_mask.mask1,
c_mask.mask2);
/* service_operation returns 0 on success... */
rc = service_operation(new_op,
"pvfs2_param",
PVFS2_OP_INTERRUPTIBLE);
if (rc)
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
"%s: service_operation failed! rc:%d:\n",
__func__,
rc);
op_release(new_op);
}
mutex_lock(&orangefs_debug_lock);
memset(file->f_inode->i_private, 0, PVFS2_MAX_DEBUG_STRING_LEN);
sprintf((char *)file->f_inode->i_private, "%s\n", debug_string);
mutex_unlock(&orangefs_debug_lock);
*ppos += count;
if (silly)
rc = silly;
else
rc = count;
out:
gossip_debug(GOSSIP_DEBUGFS_DEBUG,
"orangefs_debug_write: rc: %d\n",
rc);
kfree(buf);
return rc;
}
/*
* (C) 2001 Clemson University and The University of Chicago
*
* Changes by Acxiom Corporation to add proc file handler for pvfs2 client
* parameters, Copyright Acxiom Corporation, 2005.
*
* See COPYING in top-level directory.
*/
#include "protocol.h"
#include "pvfs2-kernel.h"
#include "pvfs2-debugfs.h"
#include "pvfs2-sysfs.h"
/* PVFS2_VERSION is a ./configure define */
#ifndef PVFS2_VERSION
#define PVFS2_VERSION "Unknown"
#endif
/*
* global variables declared here
*/
/* array of client debug keyword/mask values */
struct client_debug_mask *cdm_array;
int cdm_element_count;
char kernel_debug_string[PVFS2_MAX_DEBUG_STRING_LEN] = "none";
char client_debug_string[PVFS2_MAX_DEBUG_STRING_LEN];
char client_debug_array_string[PVFS2_MAX_DEBUG_STRING_LEN];
char *debug_help_string;
int help_string_initialized;
struct dentry *help_file_dentry;
struct dentry *client_debug_dentry;
struct dentry *debug_dir;
int client_verbose_index;
int client_all_index;
struct pvfs2_stats g_pvfs2_stats;
/* the size of the hash tables for ops in progress */
int hash_table_size = 509;
static ulong module_parm_debug_mask;
__u64 gossip_debug_mask;
struct client_debug_mask client_debug_mask = { NULL, 0, 0 };
unsigned int kernel_mask_set_mod_init; /* implicitly false */
int op_timeout_secs = PVFS2_DEFAULT_OP_TIMEOUT_SECS;
int slot_timeout_secs = PVFS2_DEFAULT_SLOT_TIMEOUT_SECS;
__u32 DEBUG_LINE = 50;
MODULE_LICENSE("GPL");
MODULE_AUTHOR("PVFS2 Development Team");
MODULE_DESCRIPTION("The Linux Kernel VFS interface to PVFS2");
MODULE_PARM_DESC(module_parm_debug_mask, "debugging level (see pvfs2-debug.h for values)");
MODULE_PARM_DESC(op_timeout_secs, "Operation timeout in seconds");
MODULE_PARM_DESC(slot_timeout_secs, "Slot timeout in seconds");
MODULE_PARM_DESC(hash_table_size,
"size of hash table for operations in progress");
static struct file_system_type pvfs2_fs_type = {
.name = "pvfs2",
.mount = pvfs2_mount,
.kill_sb = pvfs2_kill_sb,
.owner = THIS_MODULE,
};
module_param(hash_table_size, int, 0);
module_param(module_parm_debug_mask, ulong, 0755);
module_param(op_timeout_secs, int, 0);
module_param(slot_timeout_secs, int, 0);
/* synchronizes the request device file */
struct mutex devreq_mutex;
/*
blocks non-priority requests from being queued for servicing. this
could be used for protecting the request list data structure, but
for now it's only being used to stall the op addition to the request
list
*/
struct mutex request_mutex;
/* hash table for storing operations waiting for matching downcall */
struct list_head *htable_ops_in_progress;
DEFINE_SPINLOCK(htable_ops_in_progress_lock);
/* list for queueing upcall operations */
LIST_HEAD(pvfs2_request_list);
/* used to protect the above pvfs2_request_list */
DEFINE_SPINLOCK(pvfs2_request_list_lock);
/* used for incoming request notification */
DECLARE_WAIT_QUEUE_HEAD(pvfs2_request_list_waitq);
static int __init pvfs2_init(void)
{
int ret = -1;
__u32 i = 0;
/* convert input debug mask to a 64-bit unsigned integer */
gossip_debug_mask = (unsigned long long) module_parm_debug_mask;
/*
* set the kernel's gossip debug string; invalid mask values will
* be ignored.
*/
debug_mask_to_string(&gossip_debug_mask, 0);
/* remove any invalid values from the mask */
debug_string_to_mask(kernel_debug_string, &gossip_debug_mask, 0);
/*
* if the mask has a non-zero value, then indicate that the mask
* was set when the kernel module was loaded. The pvfs2 dev ioctl
* command will look at this boolean to determine if the kernel's
* debug mask should be overwritten when the client-core is started.
*/
if (gossip_debug_mask != 0)
kernel_mask_set_mod_init = true;
/* print information message to the system log */
pr_info("pvfs2: pvfs2_init called with debug mask: :%s: :%llx:\n",
kernel_debug_string,
(unsigned long long)gossip_debug_mask);
ret = bdi_init(&pvfs2_backing_dev_info);
if (ret)
return ret;
if (op_timeout_secs < 0)
op_timeout_secs = 0;
if (slot_timeout_secs < 0)
slot_timeout_secs = 0;
/* initialize global book keeping data structures */
ret = op_cache_initialize();
if (ret < 0)
goto err;
ret = dev_req_cache_initialize();
if (ret < 0)
goto cleanup_op;
ret = pvfs2_inode_cache_initialize();
if (ret < 0)
goto cleanup_req;
ret = kiocb_cache_initialize();
if (ret < 0)
goto cleanup_inode;
/* Initialize the pvfsdev subsystem. */
ret = pvfs2_dev_init();
if (ret < 0) {
gossip_err("pvfs2: could not initialize device subsystem %d!\n",
ret);
goto cleanup_kiocb;
}
mutex_init(&devreq_mutex);
mutex_init(&request_mutex);
htable_ops_in_progress =
kcalloc(hash_table_size, sizeof(struct list_head), GFP_KERNEL);
if (!htable_ops_in_progress) {
gossip_err("Failed to initialize op hashtable");
ret = -ENOMEM;
goto cleanup_device;
}
/* initialize a doubly linked at each hash table index */
for (i = 0; i < hash_table_size; i++)
INIT_LIST_HEAD(&htable_ops_in_progress[i]);
ret = fsid_key_table_initialize();
if (ret < 0)
goto cleanup_progress_table;
/*
* Build the contents of /sys/kernel/debug/orangefs/debug-help
* from the keywords in the kernel keyword/mask array.
*
* The keywords in the client keyword/mask array are
* unknown at boot time.
*
* orangefs_prepare_debugfs_help_string will be used again
* later to rebuild the debug-help file after the client starts
* and passes along the needed info. The argument signifies
* which time orangefs_prepare_debugfs_help_string is being
* called.
*
*/
ret = orangefs_prepare_debugfs_help_string(1);
if (ret)
goto out;
pvfs2_debugfs_init();
pvfs2_kernel_debug_init();
orangefs_sysfs_init();
ret = register_filesystem(&pvfs2_fs_type);
if (ret == 0) {
pr_info("pvfs2: module version %s loaded\n", PVFS2_VERSION);
return 0;
}
pvfs2_debugfs_cleanup();
orangefs_sysfs_exit();
fsid_key_table_finalize();
cleanup_progress_table:
kfree(htable_ops_in_progress);
cleanup_device:
pvfs2_dev_cleanup();
cleanup_kiocb:
kiocb_cache_finalize();
cleanup_inode:
pvfs2_inode_cache_finalize();
cleanup_req:
dev_req_cache_finalize();
cleanup_op:
op_cache_finalize();
err:
bdi_destroy(&pvfs2_backing_dev_info);
out:
return ret;
}
static void __exit pvfs2_exit(void)
{
int i = 0;
struct pvfs2_kernel_op_s *cur_op = NULL;
gossip_debug(GOSSIP_INIT_DEBUG, "pvfs2: pvfs2_exit called\n");
unregister_filesystem(&pvfs2_fs_type);
pvfs2_debugfs_cleanup();
orangefs_sysfs_exit();
fsid_key_table_finalize();
pvfs2_dev_cleanup();
/* clear out all pending upcall op requests */
spin_lock(&pvfs2_request_list_lock);
while (!list_empty(&pvfs2_request_list)) {
cur_op = list_entry(pvfs2_request_list.next,
struct pvfs2_kernel_op_s,
list);
list_del(&cur_op->list);
gossip_debug(GOSSIP_INIT_DEBUG,
"Freeing unhandled upcall request type %d\n",
cur_op->upcall.type);
op_release(cur_op);
}
spin_unlock(&pvfs2_request_list_lock);
for (i = 0; i < hash_table_size; i++)
while (!list_empty(&htable_ops_in_progress[i])) {
cur_op = list_entry(htable_ops_in_progress[i].next,
struct pvfs2_kernel_op_s,
list);
op_release(cur_op);
}
kiocb_cache_finalize();
pvfs2_inode_cache_finalize();
dev_req_cache_finalize();
op_cache_finalize();
kfree(htable_ops_in_progress);
bdi_destroy(&pvfs2_backing_dev_info);
pr_info("pvfs2: module version %s unloaded\n", PVFS2_VERSION);
}
/*
* What we do in this function is to walk the list of operations
* that are in progress in the hash table and mark them as purged as well.
*/
void purge_inprogress_ops(void)
{
int i;
for (i = 0; i < hash_table_size; i++) {
struct pvfs2_kernel_op_s *op;
struct pvfs2_kernel_op_s *next;
list_for_each_entry_safe(op,
next,
&htable_ops_in_progress[i],
list) {
spin_lock(&op->lock);
gossip_debug(GOSSIP_INIT_DEBUG,
"pvfs2-client-core: purging in-progress op tag "
"%llu %s\n",
llu(op->tag),
get_opname_string(op));
set_op_state_purged(op);
spin_unlock(&op->lock);
wake_up_interruptible(&op->waitq);
}
}
}
module_init(pvfs2_init);
module_exit(pvfs2_exit);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册