2017-11-24 22:00:38 +08:00
|
|
|
// SPDX-License-Identifier: GPL-1.0+
|
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>
|
2016-10-31 04:37:30 +08:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kobject.h>
|
2007-08-10 20:32:27 +08:00
|
|
|
#include <linux/seq_file.h>
|
|
|
|
#include <linux/mount.h>
|
2015-02-23 00:58:50 +08:00
|
|
|
#include <linux/uio.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 */
|
|
|
|
|
2013-07-19 22:05:21 +08:00
|
|
|
static struct dentry *hypfs_create_update_file(struct dentry *dir);
|
2006-06-23 17:05:06 +08:00
|
|
|
|
|
|
|
struct hypfs_sb_info {
|
2012-08-07 18:47:41 +08:00
|
|
|
kuid_t uid; /* uid used for files and dirs */
|
|
|
|
kgid_t gid; /* gid used for files and dirs */
|
2006-06-23 17:05:06 +08:00
|
|
|
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;
|
2015-03-18 06:26:12 +08:00
|
|
|
struct inode *inode = d_inode(sb_info->update_file);
|
2006-06-23 17:05:06 +08:00
|
|
|
|
|
|
|
sb_info->last_update = get_seconds();
|
2016-09-14 22:48:04 +08:00
|
|
|
inode->i_atime = inode->i_mtime = inode->i_ctime = current_time(inode);
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* directory tree removal functions */
|
|
|
|
|
|
|
|
static void hypfs_add_dentry(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
dentry->d_fsdata = hypfs_last_dentry;
|
|
|
|
hypfs_last_dentry = dentry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void hypfs_remove(struct dentry *dentry)
|
|
|
|
{
|
|
|
|
struct dentry *parent;
|
|
|
|
|
|
|
|
parent = dentry->d_parent;
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock(d_inode(parent));
|
2015-05-18 22:10:34 +08:00
|
|
|
if (simple_positive(dentry)) {
|
VFS: (Scripted) Convert S_ISLNK/DIR/REG(dentry->d_inode) to d_is_*(dentry)
Convert the following where appropriate:
(1) S_ISLNK(dentry->d_inode) to d_is_symlink(dentry).
(2) S_ISREG(dentry->d_inode) to d_is_reg(dentry).
(3) S_ISDIR(dentry->d_inode) to d_is_dir(dentry). This is actually more
complicated than it appears as some calls should be converted to
d_can_lookup() instead. The difference is whether the directory in
question is a real dir with a ->lookup op or whether it's a fake dir with
a ->d_automount op.
In some circumstances, we can subsume checks for dentry->d_inode not being
NULL into this, provided we the code isn't in a filesystem that expects
d_inode to be NULL if the dirent really *is* negative (ie. if we're going to
use d_inode() rather than d_backing_inode() to get the inode pointer).
Note that the dentry type field may be set to something other than
DCACHE_MISS_TYPE when d_inode is NULL in the case of unionmount, where the VFS
manages the fall-through from a negative dentry to a lower layer. In such a
case, the dentry type of the negative union dentry is set to the same as the
type of the lower dentry.
However, if you know d_inode is not NULL at the call site, then you can use
the d_is_xxx() functions even in a filesystem.
There is one further complication: a 0,0 chardev dentry may be labelled
DCACHE_WHITEOUT_TYPE rather than DCACHE_SPECIAL_TYPE. Strictly, this was
intended for special directory entry types that don't have attached inodes.
The following perl+coccinelle script was used:
use strict;
my @callers;
open($fd, 'git grep -l \'S_IS[A-Z].*->d_inode\' |') ||
die "Can't grep for S_ISDIR and co. callers";
@callers = <$fd>;
close($fd);
unless (@callers) {
print "No matches\n";
exit(0);
}
my @cocci = (
'@@',
'expression E;',
'@@',
'',
'- S_ISLNK(E->d_inode->i_mode)',
'+ d_is_symlink(E)',
'',
'@@',
'expression E;',
'@@',
'',
'- S_ISDIR(E->d_inode->i_mode)',
'+ d_is_dir(E)',
'',
'@@',
'expression E;',
'@@',
'',
'- S_ISREG(E->d_inode->i_mode)',
'+ d_is_reg(E)' );
my $coccifile = "tmp.sp.cocci";
open($fd, ">$coccifile") || die $coccifile;
print($fd "$_\n") || die $coccifile foreach (@cocci);
close($fd);
foreach my $file (@callers) {
chomp $file;
print "Processing ", $file, "\n";
system("spatch", "--sp-file", $coccifile, $file, "--in-place", "--no-show-diff") == 0 ||
die "spatch failed";
}
[AV: overlayfs parts skipped]
Signed-off-by: David Howells <dhowells@redhat.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
2015-01-29 20:02:35 +08:00
|
|
|
if (d_is_dir(dentry))
|
2015-03-18 06:26:12 +08:00
|
|
|
simple_rmdir(d_inode(parent), dentry);
|
2007-08-22 19:51:43 +08:00
|
|
|
else
|
2015-03-18 06:26:12 +08:00
|
|
|
simple_unlink(d_inode(parent), dentry);
|
2007-08-22 19:51:43 +08:00
|
|
|
}
|
2006-06-23 17:05:06 +08:00
|
|
|
d_delete(dentry);
|
|
|
|
dput(dentry);
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(parent));
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-25 11:30:19 +08:00
|
|
|
static struct inode *hypfs_make_inode(struct super_block *sb, umode_t mode)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
|
|
|
struct inode *ret = new_inode(sb);
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
struct hypfs_sb_info *hypfs_info = sb->s_fs_info;
|
2012-06-29 20:48:09 +08:00
|
|
|
ret->i_ino = get_next_ino();
|
2006-06-23 17:05:06 +08:00
|
|
|
ret->i_mode = mode;
|
|
|
|
ret->i_uid = hypfs_info->uid;
|
|
|
|
ret->i_gid = hypfs_info->gid;
|
2016-09-14 22:48:04 +08:00
|
|
|
ret->i_atime = ret->i_mtime = ret->i_ctime = current_time(ret);
|
2011-07-25 11:30:19 +08:00
|
|
|
if (S_ISDIR(mode))
|
2011-10-28 20:13:29 +08:00
|
|
|
set_nlink(ret, 2);
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-06-05 09:02:59 +08:00
|
|
|
static void hypfs_evict_inode(struct inode *inode)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
2012-05-03 20:48:02 +08:00
|
|
|
clear_inode(inode);
|
2006-09-27 16:50:46 +08:00
|
|
|
kfree(inode->i_private);
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hypfs_open(struct inode *inode, struct file *filp)
|
|
|
|
{
|
2013-01-24 06:07:38 +08:00
|
|
|
char *data = file_inode(filp)->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
|
|
|
}
|
|
|
|
|
2015-02-05 05:17:45 +08:00
|
|
|
static ssize_t hypfs_read_iter(struct kiocb *iocb, struct iov_iter *to)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
2015-02-05 05:17:45 +08:00
|
|
|
struct file *file = iocb->ki_filp;
|
|
|
|
char *data = file->private_data;
|
|
|
|
size_t available = strlen(data);
|
|
|
|
loff_t pos = iocb->ki_pos;
|
|
|
|
size_t count;
|
2008-07-14 15:59:16 +08:00
|
|
|
|
2015-02-05 05:17:45 +08:00
|
|
|
if (pos < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
if (pos >= available || !iov_iter_count(to))
|
|
|
|
return 0;
|
|
|
|
count = copy_to_iter(data + pos, available - pos, to);
|
|
|
|
if (!count)
|
|
|
|
return -EFAULT;
|
|
|
|
iocb->ki_pos = pos + count;
|
|
|
|
file_accessed(file);
|
|
|
|
return count;
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
2015-02-05 05:17:45 +08:00
|
|
|
|
|
|
|
static ssize_t hypfs_write_iter(struct kiocb *iocb, struct iov_iter *from)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
|
|
|
int rc;
|
2013-02-28 05:59:05 +08:00
|
|
|
struct super_block *sb = file_inode(iocb->ki_filp)->i_sb;
|
|
|
|
struct hypfs_sb_info *fs_info = sb->s_fs_info;
|
2015-02-05 05:17:45 +08:00
|
|
|
size_t count = iov_iter_count(from);
|
2006-06-23 17:05:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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)
|
2013-07-19 21:03:49 +08:00
|
|
|
rc = hypfs_vm_create_files(sb->s_root);
|
2007-02-06 04:18:29 +08:00
|
|
|
else
|
2013-07-19 21:10:21 +08:00
|
|
|
rc = hypfs_diag_create_files(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;
|
2015-02-05 05:17:45 +08:00
|
|
|
iov_iter_advance(from, count);
|
2006-06-23 17:05:06 +08:00
|
|
|
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];
|
2012-08-07 18:47:41 +08:00
|
|
|
kuid_t uid;
|
|
|
|
kgid_t gid;
|
2006-06-23 17:05:06 +08:00
|
|
|
|
|
|
|
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;
|
2012-08-07 18:47:41 +08:00
|
|
|
uid = make_kuid(current_user_ns(), option);
|
|
|
|
if (!uid_valid(uid))
|
|
|
|
return -EINVAL;
|
|
|
|
hypfs_info->uid = uid;
|
2006-06-23 17:05:06 +08:00
|
|
|
break;
|
|
|
|
case opt_gid:
|
|
|
|
if (match_int(&args[0], &option))
|
|
|
|
return -EINVAL;
|
2012-08-07 18:47:41 +08:00
|
|
|
gid = make_kgid(current_user_ns(), option);
|
|
|
|
if (!gid_valid(gid))
|
|
|
|
return -EINVAL;
|
|
|
|
hypfs_info->gid = gid;
|
2006-06-23 17:05:06 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-12-09 10:32:45 +08:00
|
|
|
static int hypfs_show_options(struct seq_file *s, struct dentry *root)
|
2007-08-10 20:32:27 +08:00
|
|
|
{
|
2011-12-09 10:32:45 +08:00
|
|
|
struct hypfs_sb_info *hypfs_info = root->d_sb->s_fs_info;
|
2007-08-10 20:32:27 +08:00
|
|
|
|
2012-08-07 18:47:41 +08:00
|
|
|
seq_printf(s, ",uid=%u", from_kuid_munged(&init_user_ns, hypfs_info->uid));
|
|
|
|
seq_printf(s, ",gid=%u", from_kgid_munged(&init_user_ns, hypfs_info->gid));
|
2007-08-10 20:32:27 +08:00
|
|
|
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;
|
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;
|
2006-06-23 17:05:06 +08:00
|
|
|
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;
|
2012-01-09 11:15:13 +08:00
|
|
|
sb->s_root = root_dentry = d_make_root(root_inode);
|
|
|
|
if (!root_dentry)
|
2010-01-26 07:36:07 +08:00
|
|
|
return -ENOMEM;
|
2007-02-06 04:18:29 +08:00
|
|
|
if (MACHINE_IS_VM)
|
2013-07-19 21:03:49 +08:00
|
|
|
rc = hypfs_vm_create_files(root_dentry);
|
2007-02-06 04:18:29 +08:00
|
|
|
else
|
2013-07-19 21:10:21 +08:00
|
|
|
rc = hypfs_diag_create_files(root_dentry);
|
2006-06-23 17:05:06 +08:00
|
|
|
if (rc)
|
2010-01-26 07:36:07 +08:00
|
|
|
return rc;
|
2013-07-19 22:05:21 +08:00
|
|
|
sbi->update_file = hypfs_create_update_file(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;
|
|
|
|
}
|
|
|
|
|
2010-07-25 05:48:30 +08:00
|
|
|
static struct dentry *hypfs_mount(struct file_system_type *fst, int flags,
|
|
|
|
const char *devname, void *data)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
2010-07-25 05:48:30 +08:00
|
|
|
return mount_single(fst, flags, data, hypfs_fill_super);
|
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);
|
2018-04-03 11:50:31 +08:00
|
|
|
if (sb_info && 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);
|
|
|
|
}
|
|
|
|
|
2013-07-19 22:05:21 +08:00
|
|
|
static struct dentry *hypfs_create_file(struct dentry *parent, const char *name,
|
2011-07-25 11:30:19 +08:00
|
|
|
char *data, umode_t mode)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
struct inode *inode;
|
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock(d_inode(parent));
|
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;
|
|
|
|
}
|
2013-07-19 22:05:21 +08:00
|
|
|
inode = hypfs_make_inode(parent->d_sb, mode);
|
2006-06-23 17:05:06 +08:00
|
|
|
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
|
|
|
}
|
2011-07-25 11:30:19 +08:00
|
|
|
if (S_ISREG(mode)) {
|
2006-06-23 17:05:06 +08:00
|
|
|
inode->i_fop = &hypfs_file_ops;
|
|
|
|
if (data)
|
|
|
|
inode->i_size = strlen(data);
|
|
|
|
else
|
|
|
|
inode->i_size = 0;
|
2011-07-25 11:30:19 +08:00
|
|
|
} else if (S_ISDIR(mode)) {
|
2006-06-23 17:05:06 +08:00
|
|
|
inode->i_op = &simple_dir_inode_operations;
|
|
|
|
inode->i_fop = &simple_dir_operations;
|
2015-03-18 06:26:12 +08:00
|
|
|
inc_nlink(d_inode(parent));
|
2006-06-23 17:05:06 +08:00
|
|
|
} 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:
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(parent));
|
2006-06-23 17:05:06 +08:00
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
2013-07-19 22:05:21 +08:00
|
|
|
struct dentry *hypfs_mkdir(struct dentry *parent, const char *name)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
2013-07-19 22:05:21 +08:00
|
|
|
dentry = hypfs_create_file(parent, name, NULL, S_IFDIR | DIR_MODE);
|
2006-06-23 17:05:06 +08:00
|
|
|
if (IS_ERR(dentry))
|
|
|
|
return dentry;
|
|
|
|
hypfs_add_dentry(dentry);
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
2013-07-19 22:05:21 +08:00
|
|
|
static struct dentry *hypfs_create_update_file(struct dentry *dir)
|
2006-06-23 17:05:06 +08:00
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
|
2013-07-19 22:05:21 +08:00
|
|
|
dentry = hypfs_create_file(dir, "update", NULL,
|
2006-06-23 17:05:06 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-19 22:05:21 +08:00
|
|
|
struct dentry *hypfs_create_u64(struct dentry *dir,
|
2006-06-23 17:05:06 +08:00
|
|
|
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 =
|
2013-07-19 22:05:21 +08:00
|
|
|
hypfs_create_file(dir, name, buffer, S_IFREG | REG_FILE_MODE);
|
2006-06-23 17:05:06 +08:00
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
kfree(buffer);
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
hypfs_add_dentry(dentry);
|
|
|
|
return dentry;
|
|
|
|
}
|
|
|
|
|
2013-07-19 22:05:21 +08:00
|
|
|
struct dentry *hypfs_create_str(struct dentry *dir,
|
2006-06-23 17:05:06 +08:00
|
|
|
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 =
|
2013-07-19 22:05:21 +08:00
|
|
|
hypfs_create_file(dir, name, buffer, S_IFREG | REG_FILE_MODE);
|
2006-06-23 17:05:06 +08:00
|
|
|
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,
|
2015-02-05 05:17:45 +08:00
|
|
|
.read_iter = hypfs_read_iter,
|
|
|
|
.write_iter = hypfs_write_iter,
|
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 = no_llseek,
|
2006-06-23 17:05:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct file_system_type hypfs_type = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.name = "s390_hypfs",
|
2010-07-25 05:48:30 +08:00
|
|
|
.mount = hypfs_mount,
|
2006-06-23 17:05:06 +08:00
|
|
|
.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,
|
2010-06-05 09:02:59 +08:00
|
|
|
.evict_inode = hypfs_evict_inode,
|
2007-08-10 20:32:27 +08:00
|
|
|
.show_options = hypfs_show_options,
|
2006-06-23 17:05:06 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init hypfs_init(void)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2011-01-05 19:47:43 +08:00
|
|
|
rc = hypfs_dbfs_init();
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
2010-05-17 16:00:20 +08:00
|
|
|
if (hypfs_diag_init()) {
|
|
|
|
rc = -ENODATA;
|
2011-01-05 19:47:43 +08:00
|
|
|
goto fail_dbfs_exit;
|
2010-05-17 16:00:20 +08:00
|
|
|
}
|
|
|
|
if (hypfs_vm_init()) {
|
|
|
|
rc = -ENODATA;
|
|
|
|
goto fail_hypfs_diag_exit;
|
2006-06-23 17:05:06 +08:00
|
|
|
}
|
2014-01-24 16:18:52 +08:00
|
|
|
if (hypfs_sprp_init()) {
|
|
|
|
rc = -ENODATA;
|
|
|
|
goto fail_hypfs_vm_exit;
|
|
|
|
}
|
2015-02-09 21:49:10 +08:00
|
|
|
if (hypfs_diag0c_init()) {
|
|
|
|
rc = -ENODATA;
|
|
|
|
goto fail_hypfs_sprp_exit;
|
|
|
|
}
|
2015-05-14 06:35:41 +08:00
|
|
|
rc = sysfs_create_mount_point(hypervisor_kobj, "s390");
|
|
|
|
if (rc)
|
2015-02-09 21:49:10 +08:00
|
|
|
goto fail_hypfs_diag0c_exit;
|
2006-06-23 17:05:06 +08:00
|
|
|
rc = register_filesystem(&hypfs_type);
|
|
|
|
if (rc)
|
|
|
|
goto fail_filesystem;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
fail_filesystem:
|
2015-05-14 06:35:41 +08:00
|
|
|
sysfs_remove_mount_point(hypervisor_kobj, "s390");
|
2015-02-09 21:49:10 +08:00
|
|
|
fail_hypfs_diag0c_exit:
|
|
|
|
hypfs_diag0c_exit();
|
2014-01-24 16:18:52 +08:00
|
|
|
fail_hypfs_sprp_exit:
|
|
|
|
hypfs_sprp_exit();
|
2010-05-17 16:00:20 +08:00
|
|
|
fail_hypfs_vm_exit:
|
|
|
|
hypfs_vm_exit();
|
|
|
|
fail_hypfs_diag_exit:
|
|
|
|
hypfs_diag_exit();
|
2011-01-05 19:47:43 +08:00
|
|
|
fail_dbfs_exit:
|
|
|
|
hypfs_dbfs_exit();
|
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;
|
|
|
|
}
|
2016-10-31 04:37:30 +08:00
|
|
|
device_initcall(hypfs_init)
|