2005-12-16 06:31:23 +08:00
|
|
|
/* -*- mode: c; c-basic-offset: 8; -*-
|
|
|
|
* vim: noexpandtab sw=8 ts=8 sts=0:
|
|
|
|
*
|
|
|
|
* dlmfs.c
|
|
|
|
*
|
|
|
|
* Code which implements the kernel side of a minimal userspace
|
|
|
|
* interface to our DLM. This file handles the virtual file system
|
|
|
|
* used for communication with userspace. Credit should go to ramfs,
|
|
|
|
* which was a template for the fs side of this module.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003, 2004 Oracle. All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 021110-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Simple VFS hooks based on: */
|
|
|
|
/*
|
|
|
|
* Resizable simple ram filesystem for Linux.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2000 Linus Torvalds.
|
|
|
|
* 2000 Transmeta Corp.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/string.h>
|
|
|
|
#include <linux/backing-dev.h>
|
2010-01-27 14:14:20 +08:00
|
|
|
#include <linux/poll.h>
|
2005-12-16 06:31:23 +08:00
|
|
|
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-12-16 06:31:23 +08:00
|
|
|
|
2010-01-30 20:33:50 +08:00
|
|
|
#include "stackglue.h"
|
2005-12-16 06:31:23 +08:00
|
|
|
#include "userdlm.h"
|
|
|
|
|
|
|
|
#define MLOG_MASK_PREFIX ML_DLMFS
|
|
|
|
#include "cluster/masklog.h"
|
|
|
|
|
2008-01-26 09:02:21 +08:00
|
|
|
|
2007-02-12 16:55:41 +08:00
|
|
|
static const struct super_operations dlmfs_ops;
|
2007-02-12 16:55:34 +08:00
|
|
|
static const struct file_operations dlmfs_file_operations;
|
2007-02-12 16:55:39 +08:00
|
|
|
static const struct inode_operations dlmfs_dir_inode_operations;
|
|
|
|
static const struct inode_operations dlmfs_root_inode_operations;
|
|
|
|
static const struct inode_operations dlmfs_file_inode_operations;
|
2006-12-07 12:33:20 +08:00
|
|
|
static struct kmem_cache *dlmfs_inode_cache;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
struct workqueue_struct *user_dlm_worker;
|
|
|
|
|
2008-01-26 09:02:21 +08:00
|
|
|
|
2010-02-05 07:37:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the ABI capabilities of dlmfs.
|
|
|
|
*
|
|
|
|
* Over time, dlmfs has added some features that were not part of the
|
|
|
|
* initial ABI. Unfortunately, some of these features are not detectable
|
|
|
|
* via standard usage. For example, Linux's default poll always returns
|
2018-02-12 06:34:03 +08:00
|
|
|
* EPOLLIN, so there is no way for a caller of poll(2) to know when dlmfs
|
2010-02-05 07:37:27 +08:00
|
|
|
* added poll support. Instead, we provide this list of new capabilities.
|
|
|
|
*
|
|
|
|
* Capabilities is a read-only attribute. We do it as a module parameter
|
|
|
|
* so we can discover it whether dlmfs is built in, loaded, or even not
|
|
|
|
* loaded.
|
|
|
|
*
|
|
|
|
* The ABI features are local to this machine's dlmfs mount. This is
|
|
|
|
* distinct from the locking protocol, which is concerned with inter-node
|
|
|
|
* interaction.
|
2010-01-27 14:14:20 +08:00
|
|
|
*
|
|
|
|
* Capabilities:
|
2018-02-12 06:34:03 +08:00
|
|
|
* - bast : EPOLLIN against the file descriptor of a held lock
|
2010-01-27 14:14:20 +08:00
|
|
|
* signifies a bast fired on the lock.
|
2010-02-05 07:37:27 +08:00
|
|
|
*/
|
2010-01-30 22:02:10 +08:00
|
|
|
#define DLMFS_CAPABILITIES "bast stackglue"
|
2011-05-06 16:01:40 +08:00
|
|
|
static int param_set_dlmfs_capabilities(const char *val,
|
treewide: Fix function prototypes for module_param_call()
Several function prototypes for the set/get functions defined by
module_param_call() have a slightly wrong argument types. This fixes
those in an effort to clean up the calls when running under type-enforced
compiler instrumentation for CFI. This is the result of running the
following semantic patch:
@match_module_param_call_function@
declarer name module_param_call;
identifier _name, _set_func, _get_func;
expression _arg, _mode;
@@
module_param_call(_name, _set_func, _get_func, _arg, _mode);
@fix_set_prototype
depends on match_module_param_call_function@
identifier match_module_param_call_function._set_func;
identifier _val, _param;
type _val_type, _param_type;
@@
int _set_func(
-_val_type _val
+const char * _val
,
-_param_type _param
+const struct kernel_param * _param
) { ... }
@fix_get_prototype
depends on match_module_param_call_function@
identifier match_module_param_call_function._get_func;
identifier _val, _param;
type _val_type, _param_type;
@@
int _get_func(
-_val_type _val
+char * _val
,
-_param_type _param
+const struct kernel_param * _param
) { ... }
Two additional by-hand changes are included for places where the above
Coccinelle script didn't notice them:
drivers/platform/x86/thinkpad_acpi.c
fs/lockd/svc.c
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
2017-10-18 10:04:42 +08:00
|
|
|
const struct kernel_param *kp)
|
2010-02-05 07:37:27 +08:00
|
|
|
{
|
|
|
|
printk(KERN_ERR "%s: readonly parameter\n", kp->name);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
static int param_get_dlmfs_capabilities(char *buffer,
|
treewide: Fix function prototypes for module_param_call()
Several function prototypes for the set/get functions defined by
module_param_call() have a slightly wrong argument types. This fixes
those in an effort to clean up the calls when running under type-enforced
compiler instrumentation for CFI. This is the result of running the
following semantic patch:
@match_module_param_call_function@
declarer name module_param_call;
identifier _name, _set_func, _get_func;
expression _arg, _mode;
@@
module_param_call(_name, _set_func, _get_func, _arg, _mode);
@fix_set_prototype
depends on match_module_param_call_function@
identifier match_module_param_call_function._set_func;
identifier _val, _param;
type _val_type, _param_type;
@@
int _set_func(
-_val_type _val
+const char * _val
,
-_param_type _param
+const struct kernel_param * _param
) { ... }
@fix_get_prototype
depends on match_module_param_call_function@
identifier match_module_param_call_function._get_func;
identifier _val, _param;
type _val_type, _param_type;
@@
int _get_func(
-_val_type _val
+char * _val
,
-_param_type _param
+const struct kernel_param * _param
) { ... }
Two additional by-hand changes are included for places where the above
Coccinelle script didn't notice them:
drivers/platform/x86/thinkpad_acpi.c
fs/lockd/svc.c
Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Jessica Yu <jeyu@kernel.org>
2017-10-18 10:04:42 +08:00
|
|
|
const struct kernel_param *kp)
|
2010-02-05 07:37:27 +08:00
|
|
|
{
|
|
|
|
return strlcpy(buffer, DLMFS_CAPABILITIES,
|
|
|
|
strlen(DLMFS_CAPABILITIES) + 1);
|
|
|
|
}
|
|
|
|
module_param_call(capabilities, param_set_dlmfs_capabilities,
|
|
|
|
param_get_dlmfs_capabilities, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(capabilities, DLMFS_CAPABILITIES);
|
|
|
|
|
|
|
|
|
2005-12-16 06:31:23 +08:00
|
|
|
/*
|
|
|
|
* decodes a set of open flags into a valid lock level and a set of flags.
|
|
|
|
* returns < 0 if we have invalid flags
|
|
|
|
* flags which mean something to us:
|
|
|
|
* O_RDONLY -> PRMODE level
|
|
|
|
* O_WRONLY -> EXMODE level
|
|
|
|
*
|
2010-03-30 13:21:31 +08:00
|
|
|
* O_NONBLOCK -> NOQUEUE
|
2005-12-16 06:31:23 +08:00
|
|
|
*/
|
|
|
|
static int dlmfs_decode_open_flags(int open_flags,
|
|
|
|
int *level,
|
|
|
|
int *flags)
|
|
|
|
{
|
|
|
|
if (open_flags & (O_WRONLY|O_RDWR))
|
2010-03-30 13:21:31 +08:00
|
|
|
*level = DLM_LOCK_EX;
|
2005-12-16 06:31:23 +08:00
|
|
|
else
|
2010-03-30 13:21:31 +08:00
|
|
|
*level = DLM_LOCK_PR;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
*flags = 0;
|
|
|
|
if (open_flags & O_NONBLOCK)
|
2010-03-30 13:21:31 +08:00
|
|
|
*flags |= DLM_LKF_NOQUEUE;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dlmfs_file_open(struct inode *inode,
|
|
|
|
struct file *file)
|
|
|
|
{
|
|
|
|
int status, level, flags;
|
|
|
|
struct dlmfs_filp_private *fp = NULL;
|
|
|
|
struct dlmfs_inode_private *ip;
|
|
|
|
|
|
|
|
if (S_ISDIR(inode->i_mode))
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
mlog(0, "open called on inode %lu, flags 0x%x\n", inode->i_ino,
|
|
|
|
file->f_flags);
|
|
|
|
|
|
|
|
status = dlmfs_decode_open_flags(file->f_flags, &level, &flags);
|
|
|
|
if (status < 0)
|
|
|
|
goto bail;
|
|
|
|
|
|
|
|
/* We don't want to honor O_APPEND at read/write time as it
|
|
|
|
* doesn't make sense for LVB writes. */
|
|
|
|
file->f_flags &= ~O_APPEND;
|
|
|
|
|
2006-05-02 05:25:21 +08:00
|
|
|
fp = kmalloc(sizeof(*fp), GFP_NOFS);
|
2005-12-16 06:31:23 +08:00
|
|
|
if (!fp) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
fp->fp_lock_level = level;
|
|
|
|
|
|
|
|
ip = DLMFS_I(inode);
|
|
|
|
|
|
|
|
status = user_dlm_cluster_lock(&ip->ip_lockres, level, flags);
|
|
|
|
if (status < 0) {
|
|
|
|
/* this is a strange error to return here but I want
|
|
|
|
* to be able userspace to be able to distinguish a
|
|
|
|
* valid lock request from one that simply couldn't be
|
|
|
|
* granted. */
|
2010-03-30 13:21:31 +08:00
|
|
|
if (flags & DLM_LKF_NOQUEUE && status == -EAGAIN)
|
2005-12-16 06:31:23 +08:00
|
|
|
status = -ETXTBSY;
|
|
|
|
kfree(fp);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
file->private_data = fp;
|
|
|
|
bail:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dlmfs_file_release(struct inode *inode,
|
|
|
|
struct file *file)
|
|
|
|
{
|
2018-12-28 16:32:39 +08:00
|
|
|
int level;
|
2005-12-16 06:31:23 +08:00
|
|
|
struct dlmfs_inode_private *ip = DLMFS_I(inode);
|
2010-07-13 04:50:19 +08:00
|
|
|
struct dlmfs_filp_private *fp = file->private_data;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
if (S_ISDIR(inode->i_mode))
|
|
|
|
BUG();
|
|
|
|
|
|
|
|
mlog(0, "close called on inode %lu\n", inode->i_ino);
|
|
|
|
|
|
|
|
if (fp) {
|
|
|
|
level = fp->fp_lock_level;
|
2010-03-30 13:21:31 +08:00
|
|
|
if (level != DLM_LOCK_IV)
|
2005-12-16 06:31:23 +08:00
|
|
|
user_dlm_cluster_unlock(&ip->ip_lockres, level);
|
|
|
|
|
|
|
|
kfree(fp);
|
|
|
|
file->private_data = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-02-10 09:52:13 +08:00
|
|
|
/*
|
|
|
|
* We do ->setattr() just to override size changes. Our size is the size
|
|
|
|
* of the LVB and nothing else.
|
|
|
|
*/
|
|
|
|
static int dlmfs_file_setattr(struct dentry *dentry, struct iattr *attr)
|
|
|
|
{
|
|
|
|
int error;
|
2015-03-18 06:25:59 +08:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2010-02-10 09:52:13 +08:00
|
|
|
|
|
|
|
attr->ia_valid &= ~ATTR_SIZE;
|
2016-05-26 22:55:18 +08:00
|
|
|
error = setattr_prepare(dentry, attr);
|
2010-06-04 17:30:02 +08:00
|
|
|
if (error)
|
|
|
|
return error;
|
2010-02-10 09:52:13 +08:00
|
|
|
|
2010-06-04 17:30:02 +08:00
|
|
|
setattr_copy(inode, attr);
|
|
|
|
mark_inode_dirty(inode);
|
|
|
|
return 0;
|
2010-02-10 09:52:13 +08:00
|
|
|
}
|
|
|
|
|
2017-07-03 13:02:18 +08:00
|
|
|
static __poll_t dlmfs_file_poll(struct file *file, poll_table *wait)
|
2010-01-27 14:14:20 +08:00
|
|
|
{
|
2017-07-03 13:02:18 +08:00
|
|
|
__poll_t event = 0;
|
2013-01-24 06:07:38 +08:00
|
|
|
struct inode *inode = file_inode(file);
|
2010-01-27 14:14:20 +08:00
|
|
|
struct dlmfs_inode_private *ip = DLMFS_I(inode);
|
|
|
|
|
|
|
|
poll_wait(file, &ip->ip_lockres.l_event, wait);
|
|
|
|
|
|
|
|
spin_lock(&ip->ip_lockres.l_lock);
|
|
|
|
if (ip->ip_lockres.l_flags & USER_LOCK_BLOCKED)
|
2018-02-12 06:34:03 +08:00
|
|
|
event = EPOLLIN | EPOLLRDNORM;
|
2010-01-27 14:14:20 +08:00
|
|
|
spin_unlock(&ip->ip_lockres.l_lock);
|
|
|
|
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
|
2005-12-16 06:31:23 +08:00
|
|
|
static ssize_t dlmfs_file_read(struct file *filp,
|
|
|
|
char __user *buf,
|
|
|
|
size_t count,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
int bytes_left;
|
2010-01-30 20:33:50 +08:00
|
|
|
ssize_t readlen, got;
|
2005-12-16 06:31:23 +08:00
|
|
|
char *lvb_buf;
|
2013-01-24 06:07:38 +08:00
|
|
|
struct inode *inode = file_inode(filp);
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
mlog(0, "inode %lu, count = %zu, *ppos = %llu\n",
|
|
|
|
inode->i_ino, count, *ppos);
|
|
|
|
|
|
|
|
if (*ppos >= i_size_read(inode))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!access_ok(VERIFY_WRITE, buf, count))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
/* don't read past the lvb */
|
|
|
|
if ((count + *ppos) > i_size_read(inode))
|
|
|
|
readlen = i_size_read(inode) - *ppos;
|
|
|
|
else
|
2010-04-24 06:24:59 +08:00
|
|
|
readlen = count;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
2006-05-02 05:25:21 +08:00
|
|
|
lvb_buf = kmalloc(readlen, GFP_NOFS);
|
2005-12-16 06:31:23 +08:00
|
|
|
if (!lvb_buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2010-01-30 20:33:50 +08:00
|
|
|
got = user_dlm_read_lvb(inode, lvb_buf, readlen);
|
|
|
|
if (got) {
|
|
|
|
BUG_ON(got != readlen);
|
|
|
|
bytes_left = __copy_to_user(buf, lvb_buf, readlen);
|
|
|
|
readlen -= bytes_left;
|
|
|
|
} else
|
|
|
|
readlen = 0;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
kfree(lvb_buf);
|
|
|
|
|
|
|
|
*ppos = *ppos + readlen;
|
|
|
|
|
|
|
|
mlog(0, "read %zd bytes\n", readlen);
|
|
|
|
return readlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t dlmfs_file_write(struct file *filp,
|
|
|
|
const char __user *buf,
|
|
|
|
size_t count,
|
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
int bytes_left;
|
|
|
|
ssize_t writelen;
|
|
|
|
char *lvb_buf;
|
2013-01-24 06:07:38 +08:00
|
|
|
struct inode *inode = file_inode(filp);
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
mlog(0, "inode %lu, count = %zu, *ppos = %llu\n",
|
|
|
|
inode->i_ino, count, *ppos);
|
|
|
|
|
|
|
|
if (*ppos >= i_size_read(inode))
|
|
|
|
return -ENOSPC;
|
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!access_ok(VERIFY_READ, buf, count))
|
|
|
|
return -EFAULT;
|
|
|
|
|
|
|
|
/* don't write past the lvb */
|
|
|
|
if ((count + *ppos) > i_size_read(inode))
|
|
|
|
writelen = i_size_read(inode) - *ppos;
|
|
|
|
else
|
|
|
|
writelen = count - *ppos;
|
|
|
|
|
2006-05-02 05:25:21 +08:00
|
|
|
lvb_buf = kmalloc(writelen, GFP_NOFS);
|
2005-12-16 06:31:23 +08:00
|
|
|
if (!lvb_buf)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
bytes_left = copy_from_user(lvb_buf, buf, writelen);
|
|
|
|
writelen -= bytes_left;
|
|
|
|
if (writelen)
|
|
|
|
user_dlm_write_lvb(inode, lvb_buf, writelen);
|
|
|
|
|
|
|
|
kfree(lvb_buf);
|
|
|
|
|
|
|
|
*ppos = *ppos + writelen;
|
|
|
|
mlog(0, "wrote %zd bytes\n", writelen);
|
|
|
|
return writelen;
|
|
|
|
}
|
|
|
|
|
2008-07-26 10:45:34 +08:00
|
|
|
static void dlmfs_init_once(void *foo)
|
2005-12-16 06:31:23 +08:00
|
|
|
{
|
|
|
|
struct dlmfs_inode_private *ip =
|
|
|
|
(struct dlmfs_inode_private *) foo;
|
|
|
|
|
2010-01-30 20:33:50 +08:00
|
|
|
ip->ip_conn = NULL;
|
2007-05-17 13:10:57 +08:00
|
|
|
ip->ip_parent = NULL;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
2007-05-17 13:10:57 +08:00
|
|
|
inode_init_once(&ip->ip_vfs_inode);
|
2005-12-16 06:31:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct inode *dlmfs_alloc_inode(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct dlmfs_inode_private *ip;
|
|
|
|
|
2006-12-07 12:33:14 +08:00
|
|
|
ip = kmem_cache_alloc(dlmfs_inode_cache, GFP_NOFS);
|
2005-12-16 06:31:23 +08:00
|
|
|
if (!ip)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return &ip->ip_vfs_inode;
|
|
|
|
}
|
|
|
|
|
2011-01-07 14:49:49 +08:00
|
|
|
static void dlmfs_i_callback(struct rcu_head *head)
|
2005-12-16 06:31:23 +08:00
|
|
|
{
|
2011-01-07 14:49:49 +08:00
|
|
|
struct inode *inode = container_of(head, struct inode, i_rcu);
|
2005-12-16 06:31:23 +08:00
|
|
|
kmem_cache_free(dlmfs_inode_cache, DLMFS_I(inode));
|
|
|
|
}
|
|
|
|
|
2011-01-07 14:49:49 +08:00
|
|
|
static void dlmfs_destroy_inode(struct inode *inode)
|
|
|
|
{
|
|
|
|
call_rcu(&inode->i_rcu, dlmfs_i_callback);
|
|
|
|
}
|
|
|
|
|
2010-06-08 02:34:48 +08:00
|
|
|
static void dlmfs_evict_inode(struct inode *inode)
|
2005-12-16 06:31:23 +08:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct dlmfs_inode_private *ip;
|
|
|
|
|
2012-05-03 20:48:02 +08:00
|
|
|
clear_inode(inode);
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
mlog(0, "inode %lu\n", inode->i_ino);
|
|
|
|
|
|
|
|
ip = DLMFS_I(inode);
|
|
|
|
|
|
|
|
if (S_ISREG(inode->i_mode)) {
|
|
|
|
status = user_dlm_destroy_lock(&ip->ip_lockres);
|
|
|
|
if (status < 0)
|
|
|
|
mlog_errno(status);
|
|
|
|
iput(ip->ip_parent);
|
|
|
|
goto clear_fields;
|
|
|
|
}
|
|
|
|
|
2010-01-30 20:33:50 +08:00
|
|
|
mlog(0, "we're a directory, ip->ip_conn = 0x%p\n", ip->ip_conn);
|
2005-12-16 06:31:23 +08:00
|
|
|
/* we must be a directory. If required, lets unregister the
|
|
|
|
* dlm context now. */
|
2010-01-30 20:33:50 +08:00
|
|
|
if (ip->ip_conn)
|
|
|
|
user_dlm_unregister(ip->ip_conn);
|
2005-12-16 06:31:23 +08:00
|
|
|
clear_fields:
|
|
|
|
ip->ip_parent = NULL;
|
2010-01-30 20:33:50 +08:00
|
|
|
ip->ip_conn = NULL;
|
2005-12-16 06:31:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct inode *dlmfs_get_root_inode(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct inode *inode = new_inode(sb);
|
2011-07-26 14:55:32 +08:00
|
|
|
umode_t mode = S_IFDIR | 0755;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
if (inode) {
|
2010-10-23 23:19:54 +08:00
|
|
|
inode->i_ino = get_next_ino();
|
2011-07-25 01:43:19 +08:00
|
|
|
inode_init_owner(inode, NULL, mode);
|
2016-09-14 22:48:04 +08:00
|
|
|
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
|
2006-10-01 14:29:04 +08:00
|
|
|
inc_nlink(inode);
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
inode->i_fop = &simple_dir_operations;
|
|
|
|
inode->i_op = &dlmfs_root_inode_operations;
|
|
|
|
}
|
|
|
|
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct inode *dlmfs_get_inode(struct inode *parent,
|
|
|
|
struct dentry *dentry,
|
2011-07-26 14:55:32 +08:00
|
|
|
umode_t mode)
|
2005-12-16 06:31:23 +08:00
|
|
|
{
|
|
|
|
struct super_block *sb = parent->i_sb;
|
|
|
|
struct inode * inode = new_inode(sb);
|
|
|
|
struct dlmfs_inode_private *ip;
|
|
|
|
|
|
|
|
if (!inode)
|
|
|
|
return NULL;
|
|
|
|
|
2010-10-23 23:19:54 +08:00
|
|
|
inode->i_ino = get_next_ino();
|
2011-07-25 01:43:19 +08:00
|
|
|
inode_init_owner(inode, parent, mode);
|
2016-09-14 22:48:04 +08:00
|
|
|
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
ip = DLMFS_I(inode);
|
2010-01-30 20:33:50 +08:00
|
|
|
ip->ip_conn = DLMFS_I(parent)->ip_conn;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
switch (mode & S_IFMT) {
|
|
|
|
default:
|
|
|
|
/* for now we don't support anything other than
|
|
|
|
* directories and regular files. */
|
|
|
|
BUG();
|
|
|
|
break;
|
|
|
|
case S_IFREG:
|
|
|
|
inode->i_op = &dlmfs_file_inode_operations;
|
|
|
|
inode->i_fop = &dlmfs_file_operations;
|
|
|
|
|
|
|
|
i_size_write(inode, DLM_LVB_LEN);
|
|
|
|
|
|
|
|
user_dlm_lock_res_init(&ip->ip_lockres, dentry);
|
|
|
|
|
|
|
|
/* released at clear_inode time, this insures that we
|
|
|
|
* get to drop the dlm reference on each lock *before*
|
|
|
|
* we call the unregister code for releasing parent
|
|
|
|
* directories. */
|
|
|
|
ip->ip_parent = igrab(parent);
|
|
|
|
BUG_ON(!ip->ip_parent);
|
|
|
|
break;
|
|
|
|
case S_IFDIR:
|
|
|
|
inode->i_op = &dlmfs_dir_inode_operations;
|
|
|
|
inode->i_fop = &simple_dir_operations;
|
|
|
|
|
|
|
|
/* directory inodes start off with i_nlink ==
|
|
|
|
* 2 (for "." entry) */
|
2006-10-01 14:29:04 +08:00
|
|
|
inc_nlink(inode);
|
2005-12-16 06:31:23 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return inode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* File creation. Allocate an inode, and we're done..
|
|
|
|
*/
|
|
|
|
/* SMP-safe */
|
|
|
|
static int dlmfs_mkdir(struct inode * dir,
|
|
|
|
struct dentry * dentry,
|
2011-07-26 13:41:39 +08:00
|
|
|
umode_t mode)
|
2005-12-16 06:31:23 +08:00
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct inode *inode = NULL;
|
2016-07-21 04:27:42 +08:00
|
|
|
const struct qstr *domain = &dentry->d_name;
|
2005-12-16 06:31:23 +08:00
|
|
|
struct dlmfs_inode_private *ip;
|
2010-01-30 20:33:50 +08:00
|
|
|
struct ocfs2_cluster_connection *conn;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
mlog(0, "mkdir %.*s\n", domain->len, domain->name);
|
|
|
|
|
|
|
|
/* verify that we have a proper domain */
|
2010-01-30 20:33:50 +08:00
|
|
|
if (domain->len >= GROUP_NAME_MAX) {
|
2005-12-16 06:31:23 +08:00
|
|
|
status = -EINVAL;
|
|
|
|
mlog(ML_ERROR, "invalid domain name for directory.\n");
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
inode = dlmfs_get_inode(dir, dentry, mode | S_IFDIR);
|
|
|
|
if (!inode) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
mlog_errno(status);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
ip = DLMFS_I(inode);
|
|
|
|
|
2010-01-30 20:33:50 +08:00
|
|
|
conn = user_dlm_register(domain);
|
|
|
|
if (IS_ERR(conn)) {
|
|
|
|
status = PTR_ERR(conn);
|
2005-12-16 06:31:23 +08:00
|
|
|
mlog(ML_ERROR, "Error %d could not register domain \"%.*s\"\n",
|
|
|
|
status, domain->len, domain->name);
|
|
|
|
goto bail;
|
|
|
|
}
|
2010-01-30 20:33:50 +08:00
|
|
|
ip->ip_conn = conn;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
2006-10-01 14:29:04 +08:00
|
|
|
inc_nlink(dir);
|
2005-12-16 06:31:23 +08:00
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
dget(dentry); /* Extra count - pin the dentry in core */
|
|
|
|
|
|
|
|
status = 0;
|
|
|
|
bail:
|
|
|
|
if (status < 0)
|
|
|
|
iput(inode);
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dlmfs_create(struct inode *dir,
|
|
|
|
struct dentry *dentry,
|
2011-07-26 13:42:34 +08:00
|
|
|
umode_t mode,
|
2012-06-11 06:05:36 +08:00
|
|
|
bool excl)
|
2005-12-16 06:31:23 +08:00
|
|
|
{
|
|
|
|
int status = 0;
|
|
|
|
struct inode *inode;
|
2016-07-21 04:27:42 +08:00
|
|
|
const struct qstr *name = &dentry->d_name;
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
mlog(0, "create %.*s\n", name->len, name->name);
|
|
|
|
|
|
|
|
/* verify name is valid and doesn't contain any dlm reserved
|
|
|
|
* characters */
|
|
|
|
if (name->len >= USER_DLM_LOCK_ID_MAX_LEN ||
|
|
|
|
name->name[0] == '$') {
|
|
|
|
status = -EINVAL;
|
|
|
|
mlog(ML_ERROR, "invalid lock name, %.*s\n", name->len,
|
|
|
|
name->name);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
inode = dlmfs_get_inode(dir, dentry, mode | S_IFREG);
|
|
|
|
if (!inode) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
mlog_errno(status);
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
|
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
dget(dentry); /* Extra count - pin the dentry in core */
|
|
|
|
bail:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dlmfs_unlink(struct inode *dir,
|
|
|
|
struct dentry *dentry)
|
|
|
|
{
|
|
|
|
int status;
|
2015-03-18 06:25:59 +08:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
mlog(0, "unlink inode %lu\n", inode->i_ino);
|
|
|
|
|
|
|
|
/* if there are no current holders, or none that are waiting
|
|
|
|
* to acquire a lock, this basically destroys our lockres. */
|
|
|
|
status = user_dlm_destroy_lock(&DLMFS_I(inode)->ip_lockres);
|
|
|
|
if (status < 0) {
|
2014-10-22 08:11:25 +08:00
|
|
|
mlog(ML_ERROR, "unlink %pd, error %d from destroy\n",
|
|
|
|
dentry, status);
|
2005-12-16 06:31:23 +08:00
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
status = simple_unlink(dir, dentry);
|
|
|
|
bail:
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dlmfs_fill_super(struct super_block * sb,
|
|
|
|
void * data,
|
|
|
|
int silent)
|
|
|
|
{
|
|
|
|
sb->s_maxbytes = MAX_LFS_FILESIZE;
|
mm, fs: get rid of PAGE_CACHE_* and page_cache_{get,release} macros
PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} macros were introduced *long* time
ago with promise that one day it will be possible to implement page
cache with bigger chunks than PAGE_SIZE.
This promise never materialized. And unlikely will.
We have many places where PAGE_CACHE_SIZE assumed to be equal to
PAGE_SIZE. And it's constant source of confusion on whether
PAGE_CACHE_* or PAGE_* constant should be used in a particular case,
especially on the border between fs and mm.
Global switching to PAGE_CACHE_SIZE != PAGE_SIZE would cause to much
breakage to be doable.
Let's stop pretending that pages in page cache are special. They are
not.
The changes are pretty straight-forward:
- <foo> << (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- <foo> >> (PAGE_CACHE_SHIFT - PAGE_SHIFT) -> <foo>;
- PAGE_CACHE_{SIZE,SHIFT,MASK,ALIGN} -> PAGE_{SIZE,SHIFT,MASK,ALIGN};
- page_cache_get() -> get_page();
- page_cache_release() -> put_page();
This patch contains automated changes generated with coccinelle using
script below. For some reason, coccinelle doesn't patch header files.
I've called spatch for them manually.
The only adjustment after coccinelle is revert of changes to
PAGE_CAHCE_ALIGN definition: we are going to drop it later.
There are few places in the code where coccinelle didn't reach. I'll
fix them manually in a separate patch. Comments and documentation also
will be addressed with the separate patch.
virtual patch
@@
expression E;
@@
- E << (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
expression E;
@@
- E >> (PAGE_CACHE_SHIFT - PAGE_SHIFT)
+ E
@@
@@
- PAGE_CACHE_SHIFT
+ PAGE_SHIFT
@@
@@
- PAGE_CACHE_SIZE
+ PAGE_SIZE
@@
@@
- PAGE_CACHE_MASK
+ PAGE_MASK
@@
expression E;
@@
- PAGE_CACHE_ALIGN(E)
+ PAGE_ALIGN(E)
@@
expression E;
@@
- page_cache_get(E)
+ get_page(E)
@@
expression E;
@@
- page_cache_release(E)
+ put_page(E)
Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Michal Hocko <mhocko@suse.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-04-01 20:29:47 +08:00
|
|
|
sb->s_blocksize = PAGE_SIZE;
|
|
|
|
sb->s_blocksize_bits = PAGE_SHIFT;
|
2005-12-16 06:31:23 +08:00
|
|
|
sb->s_magic = DLMFS_MAGIC;
|
|
|
|
sb->s_op = &dlmfs_ops;
|
2012-01-09 11:15:13 +08:00
|
|
|
sb->s_root = d_make_root(dlmfs_get_root_inode(sb));
|
|
|
|
if (!sb->s_root)
|
2005-12-16 06:31:23 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-12 16:55:34 +08:00
|
|
|
static const struct file_operations dlmfs_file_operations = {
|
2005-12-16 06:31:23 +08:00
|
|
|
.open = dlmfs_file_open,
|
|
|
|
.release = dlmfs_file_release,
|
2010-01-27 14:14:20 +08:00
|
|
|
.poll = dlmfs_file_poll,
|
2005-12-16 06:31:23 +08:00
|
|
|
.read = dlmfs_file_read,
|
|
|
|
.write = dlmfs_file_write,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-16 00:52:59 +08:00
|
|
|
.llseek = default_llseek,
|
2005-12-16 06:31:23 +08:00
|
|
|
};
|
|
|
|
|
2007-02-12 16:55:39 +08:00
|
|
|
static const struct inode_operations dlmfs_dir_inode_operations = {
|
2005-12-16 06:31:23 +08:00
|
|
|
.create = dlmfs_create,
|
|
|
|
.lookup = simple_lookup,
|
|
|
|
.unlink = dlmfs_unlink,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* this way we can restrict mkdir to only the toplevel of the fs. */
|
2007-02-12 16:55:39 +08:00
|
|
|
static const struct inode_operations dlmfs_root_inode_operations = {
|
2005-12-16 06:31:23 +08:00
|
|
|
.lookup = simple_lookup,
|
|
|
|
.mkdir = dlmfs_mkdir,
|
|
|
|
.rmdir = simple_rmdir,
|
|
|
|
};
|
|
|
|
|
2007-02-12 16:55:41 +08:00
|
|
|
static const struct super_operations dlmfs_ops = {
|
2005-12-16 06:31:23 +08:00
|
|
|
.statfs = simple_statfs,
|
|
|
|
.alloc_inode = dlmfs_alloc_inode,
|
|
|
|
.destroy_inode = dlmfs_destroy_inode,
|
2010-06-08 02:34:48 +08:00
|
|
|
.evict_inode = dlmfs_evict_inode,
|
2005-12-16 06:31:23 +08:00
|
|
|
.drop_inode = generic_delete_inode,
|
|
|
|
};
|
|
|
|
|
2007-02-12 16:55:39 +08:00
|
|
|
static const struct inode_operations dlmfs_file_inode_operations = {
|
2005-12-16 06:31:23 +08:00
|
|
|
.getattr = simple_getattr,
|
2010-02-10 09:52:13 +08:00
|
|
|
.setattr = dlmfs_file_setattr,
|
2005-12-16 06:31:23 +08:00
|
|
|
};
|
|
|
|
|
2010-07-25 15:46:36 +08:00
|
|
|
static struct dentry *dlmfs_mount(struct file_system_type *fs_type,
|
|
|
|
int flags, const char *dev_name, void *data)
|
2005-12-16 06:31:23 +08:00
|
|
|
{
|
2010-07-25 15:46:36 +08:00
|
|
|
return mount_nodev(fs_type, flags, data, dlmfs_fill_super);
|
2005-12-16 06:31:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct file_system_type dlmfs_fs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "ocfs2_dlmfs",
|
2010-07-25 15:46:36 +08:00
|
|
|
.mount = dlmfs_mount,
|
2005-12-16 06:31:23 +08:00
|
|
|
.kill_sb = kill_litter_super,
|
|
|
|
};
|
2013-03-03 11:39:14 +08:00
|
|
|
MODULE_ALIAS_FS("ocfs2_dlmfs");
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
static int __init init_dlmfs_fs(void)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
int cleanup_inode = 0, cleanup_worker = 0;
|
|
|
|
|
|
|
|
dlmfs_inode_cache = kmem_cache_create("dlmfs_inode_cache",
|
|
|
|
sizeof(struct dlmfs_inode_private),
|
2006-03-24 19:16:06 +08:00
|
|
|
0, (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
|
2016-01-15 07:18:21 +08:00
|
|
|
SLAB_MEM_SPREAD|SLAB_ACCOUNT),
|
2007-07-20 09:11:58 +08:00
|
|
|
dlmfs_init_once);
|
2008-11-17 12:38:22 +08:00
|
|
|
if (!dlmfs_inode_cache) {
|
|
|
|
status = -ENOMEM;
|
2007-10-17 14:25:46 +08:00
|
|
|
goto bail;
|
2008-11-17 12:38:22 +08:00
|
|
|
}
|
2005-12-16 06:31:23 +08:00
|
|
|
cleanup_inode = 1;
|
|
|
|
|
2016-10-08 07:57:07 +08:00
|
|
|
user_dlm_worker = alloc_workqueue("user_dlm", WQ_MEM_RECLAIM, 0);
|
2005-12-16 06:31:23 +08:00
|
|
|
if (!user_dlm_worker) {
|
|
|
|
status = -ENOMEM;
|
|
|
|
goto bail;
|
|
|
|
}
|
|
|
|
cleanup_worker = 1;
|
|
|
|
|
2010-01-30 20:33:50 +08:00
|
|
|
user_dlm_set_locking_protocol();
|
2005-12-16 06:31:23 +08:00
|
|
|
status = register_filesystem(&dlmfs_fs_type);
|
|
|
|
bail:
|
|
|
|
if (status) {
|
|
|
|
if (cleanup_inode)
|
|
|
|
kmem_cache_destroy(dlmfs_inode_cache);
|
|
|
|
if (cleanup_worker)
|
|
|
|
destroy_workqueue(user_dlm_worker);
|
|
|
|
} else
|
|
|
|
printk("OCFS2 User DLM kernel interface loaded\n");
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit exit_dlmfs_fs(void)
|
|
|
|
{
|
|
|
|
unregister_filesystem(&dlmfs_fs_type);
|
|
|
|
|
|
|
|
destroy_workqueue(user_dlm_worker);
|
|
|
|
|
2012-09-26 09:33:07 +08:00
|
|
|
/*
|
|
|
|
* Make sure all delayed rcu free inodes are flushed before we
|
|
|
|
* destroy cache.
|
|
|
|
*/
|
|
|
|
rcu_barrier();
|
2006-09-27 16:49:40 +08:00
|
|
|
kmem_cache_destroy(dlmfs_inode_cache);
|
2007-10-17 14:25:46 +08:00
|
|
|
|
2005-12-16 06:31:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Oracle");
|
|
|
|
MODULE_LICENSE("GPL");
|
2014-01-22 07:48:20 +08:00
|
|
|
MODULE_DESCRIPTION("OCFS2 DLM-Filesystem");
|
2005-12-16 06:31:23 +08:00
|
|
|
|
|
|
|
module_init(init_dlmfs_fs)
|
|
|
|
module_exit(exit_dlmfs_fs)
|