2006-06-23 17:05:06 +08:00
|
|
|
/*
|
2006-09-20 21:58:44 +08:00
|
|
|
* arch/s390/hypfs/inode.c
|
2006-06-23 17:05:06 +08:00
|
|
|
* Hypervisor filesystem for Linux on s390.
|
|
|
|
*
|
2008-12-25 20:39:39 +08:00
|
|
|
* Copyright IBM Corp. 2006, 2008
|
2006-06-23 17:05:06 +08:00
|
|
|
* Author(s): Michael Holzheu <holzheu@de.ibm.com>
|
|
|
|
*/
|
|
|
|
|
2008-12-25 20:39:39 +08:00
|
|
|
#define KMSG_COMPONENT "hypfs"
|
|
|
|
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
|
|
|
|
|
2006-06-23 17:05:06 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/vfs.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2006-06-23 17:05:06 +08:00
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/time.h>
|
|
|
|
#include <linux/parser.h>
|
|
|
|
#include <linux/sysfs.h>
|
|
|
|
#include <linux/module.h>
|
2007-08-10 20:32:27 +08:00
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/mount.h>
|
2006-06-23 17:05:06 +08:00
|
|
|
#include <asm/ebcdic.h>
|
|
|
|
#include "hypfs.h"
|
|
|
|
|
|
|
|
#define HYPFS_MAGIC 0x687970 /* ASCII 'hyp' */
|
|
|
|
#define TMP_SIZE 64 /* size of temporary buffers */
|
|
|
|
|
|
|
|
static struct dentry *hypfs_create_update_file(struct super_block *sb,
|
|
|
|
struct dentry *dir);
|
|
|
|
|
|
|
|
struct hypfs_sb_info {
|
|
|
|
uid_t uid; /* uid used for files and dirs */
|
|
|
|
gid_t gid; /* gid used for files and dirs */
|
|
|
|
struct dentry *update_file; /* file to trigger update */
|
|
|
|
time_t last_update; /* last update time in secs since 1970 */
|
|
|
|
struct mutex lock; /* lock to protect update process */
|
|
|
|
};
|
|
|
|
|
2007-02-12 16:55:31 +08:00
|
|
|
static const struct file_operations hypfs_file_ops;
|
2006-06-23 17:05:06 +08:00
|
|
|
static struct file_system_type hypfs_type;
|
2009-09-22 08:01:09 +08:00
|
|
|
static const struct super_operations hypfs_s_ops;
|
2006-06-23 17:05:06 +08:00
|
|
|
|
|
|
|
/* start of list of all dentries, which have to be deleted on update */
|
|
|
|
static struct dentry *hypfs_last_dentry;
|
|
|
|
|
|
|
|
static void hypfs_update_update(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct hypfs_sb_info *sb_info = sb->s_fs_info;
|
|
|
|
struct inode *inode = sb_info->update_file->d_inode;
|
|
|
|
|
|
|
|
sb_info->last_update = get_seconds();
|
|
|
|
inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* directory tree removal functions */
|
|
|
|
|
|
|
|
static void hypfs_add_dentry(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
dentry->d_fsdata = hypfs_last_dentry;
|
|
|
|
hypfs_last_dentry = dentry;
|
|
|
|
}
|
|
|
|
|
2007-08-22 19:51:43 +08:00
|
|
|
static inline int hypfs_positive(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
return dentry->d_inode && !d_unhashed(dentry);
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:05:06 +08:00
|
|
|
static void hypfs_remove(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct dentry *parent;
|
|
|
|
|
|
|
|
parent = dentry->d_parent;
|
2007-08-22 19:51:43 +08:00
|
|
|
if (!parent || !parent->d_inode)
|
|
|
|
return;
|
|
|
|
mutex_lock(&parent->d_inode->i_mutex);
|
|
|
|
if (hypfs_positive(dentry)) {
|
|
|
|
if (S_ISDIR(dentry->d_inode->i_mode))
|
|
|
|
simple_rmdir(parent->d_inode, dentry);
|
|
|
|
else
|
|
|
|
simple_unlink(parent->d_inode, dentry);
|
|
|
|
}
|
2006-06-23 17:05:06 +08:00
|
|
|
d_delete(dentry);
|
|
|
|
dput(dentry);
|
2007-08-22 19:51:43 +08:00
|
|
|
mutex_unlock(&parent->d_inode->i_mutex);
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hypfs_delete_tree(struct dentry *root)
|
|
|
|
{
|
|
|
|
while (hypfs_last_dentry) {
|
|
|
|
struct dentry *next_dentry;
|
|
|
|
next_dentry = hypfs_last_dentry->d_fsdata;
|
|
|
|
hypfs_remove(hypfs_last_dentry);
|
|
|
|
hypfs_last_dentry = next_dentry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct inode *hypfs_make_inode(struct super_block *sb, int mode)
|
|
|
|
{
|
|
|
|
struct inode *ret = new_inode(sb);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
struct hypfs_sb_info *hypfs_info = sb->s_fs_info;
|
|
|
|
ret->i_mode = mode;
|
|
|
|
ret->i_uid = hypfs_info->uid;
|
|
|
|
ret->i_gid = hypfs_info->gid;
|
|
|
|
ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME;
|
|
|
|
if (mode & S_IFDIR)
|
|
|
|
ret->i_nlink = 2;
|
|
|
|
else
|
|
|
|
ret->i_nlink = 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hypfs_drop_inode(struct inode *inode)
|
|
|
|
{
|
2006-09-27 16:50:46 +08:00
|
|
|
kfree(inode->i_private);
|
2006-06-23 17:05:06 +08:00
|
|
|
generic_delete_inode(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hypfs_open(struct inode *inode, struct file *filp)
|
|
|
|
{
|
2006-12-08 18:37:35 +08:00
|
|
|
char *data = filp->f_path.dentry->d_inode->i_private;
|
2006-06-23 17:05:06 +08:00
|
|
|
struct hypfs_sb_info *fs_info;
|
|
|
|
|
|
|
|
if (filp->f_mode & FMODE_WRITE) {
|
|
|
|
if (!(inode->i_mode & S_IWUGO))
|
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
if (filp->f_mode & FMODE_READ) {
|
|
|
|
if (!(inode->i_mode & S_IRUGO))
|
|
|
|
return -EACCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
fs_info = inode->i_sb->s_fs_info;
|
|
|
|
if(data) {
|
|
|
|
mutex_lock(&fs_info->lock);
|
|
|
|
filp->private_data = kstrdup(data, GFP_KERNEL);
|
|
|
|
if (!filp->private_data) {
|
|
|
|
mutex_unlock(&fs_info->lock);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
mutex_unlock(&fs_info->lock);
|
|
|
|
}
|
2010-05-17 16:00:07 +08:00
|
|
|
return nonseekable_open(inode, filp);
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
|
|
|
|
2006-10-01 14:28:46 +08:00
|
|
|
static ssize_t hypfs_aio_read(struct kiocb *iocb, const struct iovec *iov,
|
|
|
|
unsigned long nr_segs, loff_t offset)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
|
|
|
char *data;
|
2008-07-14 15:59:16 +08:00
|
|
|
ssize_t ret;
|
2006-06-23 17:05:06 +08:00
|
|
|
struct file *filp = iocb->ki_filp;
|
2006-10-01 14:28:46 +08:00
|
|
|
/* XXX: temporary */
|
|
|
|
char __user *buf = iov[0].iov_base;
|
|
|
|
size_t count = iov[0].iov_len;
|
|
|
|
|
2008-07-14 15:59:16 +08:00
|
|
|
if (nr_segs != 1)
|
|
|
|
return -EINVAL;
|
2006-06-23 17:05:06 +08:00
|
|
|
|
|
|
|
data = filp->private_data;
|
2008-07-14 15:59:16 +08:00
|
|
|
ret = simple_read_from_buffer(buf, count, &offset, data, strlen(data));
|
|
|
|
if (ret <= 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
iocb->ki_pos += ret;
|
2006-06-23 17:05:06 +08:00
|
|
|
file_accessed(filp);
|
2008-07-14 15:59:16 +08:00
|
|
|
|
|
|
|
return ret;
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
2006-10-01 14:28:46 +08:00
|
|
|
static ssize_t hypfs_aio_write(struct kiocb *iocb, const struct iovec *iov,
|
|
|
|
unsigned long nr_segs, loff_t offset)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct super_block *sb;
|
|
|
|
struct hypfs_sb_info *fs_info;
|
2006-10-01 14:28:46 +08:00
|
|
|
size_t count = iov_length(iov, nr_segs);
|
2006-06-23 17:05:06 +08:00
|
|
|
|
2006-12-08 18:37:35 +08:00
|
|
|
sb = iocb->ki_filp->f_path.dentry->d_inode->i_sb;
|
2006-06-23 17:05:06 +08:00
|
|
|
fs_info = sb->s_fs_info;
|
|
|
|
/*
|
|
|
|
* Currently we only allow one update per second for two reasons:
|
|
|
|
* 1. diag 204 is VERY expensive
|
|
|
|
* 2. If several processes do updates in parallel and then read the
|
|
|
|
* hypfs data, the likelihood of collisions is reduced, if we restrict
|
|
|
|
* the minimum update interval. A collision occurs, if during the
|
|
|
|
* data gathering of one process another process triggers an update
|
|
|
|
* If the first process wants to ensure consistent data, it has
|
|
|
|
* to restart data collection in this case.
|
|
|
|
*/
|
|
|
|
mutex_lock(&fs_info->lock);
|
|
|
|
if (fs_info->last_update == get_seconds()) {
|
|
|
|
rc = -EBUSY;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
hypfs_delete_tree(sb->s_root);
|
2007-02-06 04:18:29 +08:00
|
|
|
if (MACHINE_IS_VM)
|
|
|
|
rc = hypfs_vm_create_files(sb, sb->s_root);
|
|
|
|
else
|
|
|
|
rc = hypfs_diag_create_files(sb, sb->s_root);
|
2006-06-23 17:05:06 +08:00
|
|
|
if (rc) {
|
2008-12-25 20:39:39 +08:00
|
|
|
pr_err("Updating the hypfs tree failed\n");
|
2006-06-23 17:05:06 +08:00
|
|
|
hypfs_delete_tree(sb->s_root);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
hypfs_update_update(sb);
|
|
|
|
rc = count;
|
|
|
|
out:
|
|
|
|
mutex_unlock(&fs_info->lock);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hypfs_release(struct inode *inode, struct file *filp)
|
|
|
|
{
|
|
|
|
kfree(filp->private_data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum { opt_uid, opt_gid, opt_err };
|
|
|
|
|
2008-10-13 17:46:57 +08:00
|
|
|
static const match_table_t hypfs_tokens = {
|
2006-06-23 17:05:06 +08:00
|
|
|
{opt_uid, "uid=%u"},
|
|
|
|
{opt_gid, "gid=%u"},
|
|
|
|
{opt_err, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int hypfs_parse_options(char *options, struct super_block *sb)
|
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
substring_t args[MAX_OPT_ARGS];
|
|
|
|
|
|
|
|
if (!options)
|
|
|
|
return 0;
|
|
|
|
while ((str = strsep(&options, ",")) != NULL) {
|
|
|
|
int token, option;
|
|
|
|
struct hypfs_sb_info *hypfs_info = sb->s_fs_info;
|
|
|
|
|
|
|
|
if (!*str)
|
|
|
|
continue;
|
|
|
|
token = match_token(str, hypfs_tokens, args);
|
|
|
|
switch (token) {
|
|
|
|
case opt_uid:
|
|
|
|
if (match_int(&args[0], &option))
|
|
|
|
return -EINVAL;
|
|
|
|
hypfs_info->uid = option;
|
|
|
|
break;
|
|
|
|
case opt_gid:
|
|
|
|
if (match_int(&args[0], &option))
|
|
|
|
return -EINVAL;
|
|
|
|
hypfs_info->gid = option;
|
|
|
|
break;
|
|
|
|
case opt_err:
|
|
|
|
default:
|
2008-12-25 20:39:39 +08:00
|
|
|
pr_err("%s is not a valid mount option\n", str);
|
2006-06-23 17:05:06 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-10 20:32:27 +08:00
|
|
|
static int hypfs_show_options(struct seq_file *s, struct vfsmount *mnt)
|
|
|
|
{
|
|
|
|
struct hypfs_sb_info *hypfs_info = mnt->mnt_sb->s_fs_info;
|
|
|
|
|
|
|
|
seq_printf(s, ",uid=%u", hypfs_info->uid);
|
|
|
|
seq_printf(s, ",gid=%u", hypfs_info->gid);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-23 17:05:06 +08:00
|
|
|
static int hypfs_fill_super(struct super_block *sb, void *data, int silent)
|
|
|
|
{
|
|
|
|
struct inode *root_inode;
|
|
|
|
struct dentry *root_dentry;
|
|
|
|
int rc = 0;
|
|
|
|
struct hypfs_sb_info *sbi;
|
|
|
|
|
|
|
|
sbi = kzalloc(sizeof(struct hypfs_sb_info), GFP_KERNEL);
|
|
|
|
if (!sbi)
|
|
|
|
return -ENOMEM;
|
|
|
|
mutex_init(&sbi->lock);
|
2008-11-14 07:38:39 +08:00
|
|
|
sbi->uid = current_uid();
|
|
|
|
sbi->gid = current_gid();
|
2006-06-23 17:05:06 +08:00
|
|
|
sb->s_fs_info = sbi;
|
|
|
|
sb->s_blocksize = PAGE_CACHE_SIZE;
|
|
|
|
sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
|
|
|
|
sb->s_magic = HYPFS_MAGIC;
|
|
|
|
sb->s_op = &hypfs_s_ops;
|
2010-01-26 07:36:07 +08:00
|
|
|
if (hypfs_parse_options(data, sb))
|
|
|
|
return -EINVAL;
|
2006-06-23 17:05:06 +08:00
|
|
|
root_inode = hypfs_make_inode(sb, S_IFDIR | 0755);
|
2010-01-26 07:36:07 +08:00
|
|
|
if (!root_inode)
|
|
|
|
return -ENOMEM;
|
2006-06-23 17:05:06 +08:00
|
|
|
root_inode->i_op = &simple_dir_inode_operations;
|
|
|
|
root_inode->i_fop = &simple_dir_operations;
|
2010-01-26 07:36:07 +08:00
|
|
|
sb->s_root = root_dentry = d_alloc_root(root_inode);
|
2006-06-23 17:05:06 +08:00
|
|
|
if (!root_dentry) {
|
|
|
|
iput(root_inode);
|
2010-01-26 07:36:07 +08:00
|
|
|
return -ENOMEM;
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
2007-02-06 04:18:29 +08:00
|
|
|
if (MACHINE_IS_VM)
|
|
|
|
rc = hypfs_vm_create_files(sb, root_dentry);
|
|
|
|
else
|
|
|
|
rc = hypfs_diag_create_files(sb, root_dentry);
|
2006-06-23 17:05:06 +08:00
|
|
|
if (rc)
|
2010-01-26 07:36:07 +08:00
|
|
|
return rc;
|
2006-06-23 17:05:06 +08:00
|
|
|
sbi->update_file = hypfs_create_update_file(sb, root_dentry);
|
2010-01-26 07:36:07 +08:00
|
|
|
if (IS_ERR(sbi->update_file))
|
|
|
|
return PTR_ERR(sbi->update_file);
|
2006-06-23 17:05:06 +08:00
|
|
|
hypfs_update_update(sb);
|
2008-12-25 20:39:39 +08:00
|
|
|
pr_info("Hypervisor filesystem mounted\n");
|
2006-06-23 17:05:06 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-23 19:01:35 +08:00
|
|
|
static int hypfs_get_super(struct file_system_type *fst, int flags,
|
|
|
|
const char *devname, void *data, struct vfsmount *mnt)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
2006-06-23 19:01:35 +08:00
|
|
|
return get_sb_single(fst, flags, data, hypfs_fill_super, mnt);
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void hypfs_kill_super(struct super_block *sb)
|
|
|
|
{
|
|
|
|
struct hypfs_sb_info *sb_info = sb->s_fs_info;
|
|
|
|
|
2010-01-26 07:36:07 +08:00
|
|
|
if (sb->s_root)
|
2006-09-20 22:00:04 +08:00
|
|
|
hypfs_delete_tree(sb->s_root);
|
2010-01-26 07:36:07 +08:00
|
|
|
if (sb_info->update_file)
|
2006-09-20 22:00:04 +08:00
|
|
|
hypfs_remove(sb_info->update_file);
|
2010-01-26 07:36:07 +08:00
|
|
|
kfree(sb->s_fs_info);
|
|
|
|
sb->s_fs_info = NULL;
|
2006-06-23 17:05:06 +08:00
|
|
|
kill_litter_super(sb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *hypfs_create_file(struct super_block *sb,
|
|
|
|
struct dentry *parent, const char *name,
|
|
|
|
char *data, mode_t mode)
|
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
struct inode *inode;
|
|
|
|
|
2007-08-22 19:51:43 +08:00
|
|
|
mutex_lock(&parent->d_inode->i_mutex);
|
2006-06-23 17:05:06 +08:00
|
|
|
dentry = lookup_one_len(name, parent, strlen(name));
|
2007-08-22 19:51:43 +08:00
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
dentry = ERR_PTR(-ENOMEM);
|
|
|
|
goto fail;
|
|
|
|
}
|
2006-06-23 17:05:06 +08:00
|
|
|
inode = hypfs_make_inode(sb, mode);
|
|
|
|
if (!inode) {
|
|
|
|
dput(dentry);
|
2007-08-22 19:51:43 +08:00
|
|
|
dentry = ERR_PTR(-ENOMEM);
|
|
|
|
goto fail;
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
|
|
|
if (mode & S_IFREG) {
|
|
|
|
inode->i_fop = &hypfs_file_ops;
|
|
|
|
if (data)
|
|
|
|
inode->i_size = strlen(data);
|
|
|
|
else
|
|
|
|
inode->i_size = 0;
|
|
|
|
} else if (mode & S_IFDIR) {
|
|
|
|
inode->i_op = &simple_dir_inode_operations;
|
|
|
|
inode->i_fop = &simple_dir_operations;
|
|
|
|
parent->d_inode->i_nlink++;
|
|
|
|
} else
|
|
|
|
BUG();
|
2006-09-27 16:50:46 +08:00
|
|
|
inode->i_private = data;
|
2006-06-23 17:05:06 +08:00
|
|
|
d_instantiate(dentry, inode);
|
|
|
|
dget(dentry);
|
2007-08-22 19:51:43 +08:00
|
|
|
fail:
|
|
|
|
mutex_unlock(&parent->d_inode->i_mutex);
|
2006-06-23 17:05:06 +08:00
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry *hypfs_mkdir(struct super_block *sb, struct dentry *parent,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
|
|
|
dentry = hypfs_create_file(sb, parent, name, NULL, S_IFDIR | DIR_MODE);
|
|
|
|
if (IS_ERR(dentry))
|
|
|
|
return dentry;
|
|
|
|
hypfs_add_dentry(dentry);
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct dentry *hypfs_create_update_file(struct super_block *sb,
|
|
|
|
struct dentry *dir)
|
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
|
|
|
dentry = hypfs_create_file(sb, dir, "update", NULL,
|
|
|
|
S_IFREG | UPDATE_FILE_MODE);
|
|
|
|
/*
|
|
|
|
* We do not put the update file on the 'delete' list with
|
|
|
|
* hypfs_add_dentry(), since it should not be removed when the tree
|
|
|
|
* is updated.
|
|
|
|
*/
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry *hypfs_create_u64(struct super_block *sb, struct dentry *dir,
|
|
|
|
const char *name, __u64 value)
|
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
char tmp[TMP_SIZE];
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
2009-09-11 16:28:54 +08:00
|
|
|
snprintf(tmp, TMP_SIZE, "%llu\n", (unsigned long long int)value);
|
2006-06-23 17:05:06 +08:00
|
|
|
buffer = kstrdup(tmp, GFP_KERNEL);
|
|
|
|
if (!buffer)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
dentry =
|
|
|
|
hypfs_create_file(sb, dir, name, buffer, S_IFREG | REG_FILE_MODE);
|
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
kfree(buffer);
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
hypfs_add_dentry(dentry);
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct dentry *hypfs_create_str(struct super_block *sb, struct dentry *dir,
|
|
|
|
const char *name, char *string)
|
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
|
|
|
buffer = kmalloc(strlen(string) + 2, GFP_KERNEL);
|
|
|
|
if (!buffer)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
sprintf(buffer, "%s\n", string);
|
|
|
|
dentry =
|
|
|
|
hypfs_create_file(sb, dir, name, buffer, S_IFREG | REG_FILE_MODE);
|
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
kfree(buffer);
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
hypfs_add_dentry(dentry);
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
2007-02-12 16:55:31 +08:00
|
|
|
static const struct file_operations hypfs_file_ops = {
|
2006-06-23 17:05:06 +08:00
|
|
|
.open = hypfs_open,
|
|
|
|
.release = hypfs_release,
|
|
|
|
.read = do_sync_read,
|
|
|
|
.write = do_sync_write,
|
|
|
|
.aio_read = hypfs_aio_read,
|
|
|
|
.aio_write = hypfs_aio_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct file_system_type hypfs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "s390_hypfs",
|
|
|
|
.get_sb = hypfs_get_super,
|
|
|
|
.kill_sb = hypfs_kill_super
|
|
|
|
};
|
|
|
|
|
2009-09-22 08:01:09 +08:00
|
|
|
static const struct super_operations hypfs_s_ops = {
|
2006-06-23 17:05:06 +08:00
|
|
|
.statfs = simple_statfs,
|
|
|
|
.drop_inode = hypfs_drop_inode,
|
2007-08-10 20:32:27 +08:00
|
|
|
.show_options = hypfs_show_options,
|
2006-06-23 17:05:06 +08:00
|
|
|
};
|
|
|
|
|
2007-11-01 23:29:06 +08:00
|
|
|
static struct kobject *s390_kobj;
|
2006-06-23 17:05:06 +08:00
|
|
|
|
|
|
|
static int __init hypfs_init(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2007-02-06 04:18:29 +08:00
|
|
|
if (MACHINE_IS_VM) {
|
|
|
|
if (hypfs_vm_init())
|
|
|
|
/* no diag 2fc, just exit */
|
|
|
|
return -ENODATA;
|
|
|
|
} else {
|
|
|
|
if (hypfs_diag_init()) {
|
|
|
|
rc = -ENODATA;
|
|
|
|
goto fail_diag;
|
|
|
|
}
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
2007-11-01 23:29:06 +08:00
|
|
|
s390_kobj = kobject_create_and_add("s390", hypervisor_kobj);
|
|
|
|
if (!s390_kobj) {
|
2009-08-19 02:18:35 +08:00
|
|
|
rc = -ENOMEM;
|
2006-06-23 17:05:06 +08:00
|
|
|
goto fail_sysfs;
|
2007-11-01 23:29:06 +08:00
|
|
|
}
|
2006-06-23 17:05:06 +08:00
|
|
|
rc = register_filesystem(&hypfs_type);
|
|
|
|
if (rc)
|
|
|
|
goto fail_filesystem;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_filesystem:
|
2007-12-21 00:13:05 +08:00
|
|
|
kobject_put(s390_kobj);
|
2006-06-23 17:05:06 +08:00
|
|
|
fail_sysfs:
|
2007-02-06 04:18:29 +08:00
|
|
|
if (!MACHINE_IS_VM)
|
|
|
|
hypfs_diag_exit();
|
2006-06-23 17:05:06 +08:00
|
|
|
fail_diag:
|
2008-12-25 20:39:39 +08:00
|
|
|
pr_err("Initialization of hypfs failed with rc=%i\n", rc);
|
2006-06-23 17:05:06 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit hypfs_exit(void)
|
|
|
|
{
|
2007-02-06 04:18:29 +08:00
|
|
|
if (!MACHINE_IS_VM)
|
|
|
|
hypfs_diag_exit();
|
2006-06-23 17:05:06 +08:00
|
|
|
unregister_filesystem(&hypfs_type);
|
2007-12-21 00:13:05 +08:00
|
|
|
kobject_put(s390_kobj);
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(hypfs_init)
|
|
|
|
module_exit(hypfs_exit)
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Michael Holzheu <holzheu@de.ibm.com>");
|
|
|
|
MODULE_DESCRIPTION("s390 Hypervisor Filesystem");
|