License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* linux/fs/reiserfs/xattr.c
|
|
|
|
*
|
|
|
|
* Copyright (c) 2002 by Jeff Mahoney, <jeffm@suse.com>
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In order to implement EA/ACLs in a clean, backwards compatible manner,
|
|
|
|
* they are implemented as files in a "private" directory.
|
|
|
|
* Each EA is in it's own file, with the directory layout like so (/ is assumed
|
|
|
|
* to be relative to fs root). Inside the /.reiserfs_priv/xattrs directory,
|
|
|
|
* directories named using the capital-hex form of the objectid and
|
|
|
|
* generation number are used. Inside each directory are individual files
|
|
|
|
* named with the name of the extended attribute.
|
|
|
|
*
|
|
|
|
* So, for objectid 12648430, we could have:
|
|
|
|
* /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_access
|
|
|
|
* /.reiserfs_priv/xattrs/C0FFEE.0/system.posix_acl_default
|
|
|
|
* /.reiserfs_priv/xattrs/C0FFEE.0/user.Content-Type
|
|
|
|
* .. or similar.
|
|
|
|
*
|
|
|
|
* The file contents are the text of the EA. The size is known based on the
|
|
|
|
* stat data describing the file.
|
|
|
|
*
|
|
|
|
* In the case of system.posix_acl_access and system.posix_acl_default, since
|
|
|
|
* these are special cases for filesystem ACLs, they are interpreted by the
|
|
|
|
* kernel, in addition, they are negatively and positively cached and attached
|
|
|
|
* to the inode so that unnecessary lookups are avoided.
|
2009-03-31 02:02:35 +08:00
|
|
|
*
|
|
|
|
* Locking works like so:
|
2009-03-31 02:02:36 +08:00
|
|
|
* Directory components (xattr root, xattr dir) are protectd by their i_mutex.
|
|
|
|
* The xattrs themselves are protected by the xattr_sem.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2012-03-17 13:16:43 +08:00
|
|
|
#include "reiserfs.h"
|
2006-01-12 04:17:46 +08:00
|
|
|
#include <linux/capability.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/dcache.h>
|
|
|
|
#include <linux/namei.h>
|
|
|
|
#include <linux/errno.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/gfp.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/file.h>
|
|
|
|
#include <linux/pagemap.h>
|
|
|
|
#include <linux/xattr.h>
|
2012-03-17 12:59:06 +08:00
|
|
|
#include "xattr.h"
|
2012-03-17 13:03:10 +08:00
|
|
|
#include "acl.h"
|
2014-08-09 05:21:12 +08:00
|
|
|
#include <linux/uaccess.h>
|
2006-11-15 13:13:53 +08:00
|
|
|
#include <net/checksum.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/stat.h>
|
2009-03-31 02:02:34 +08:00
|
|
|
#include <linux/quotaops.h>
|
2009-11-13 17:52:56 +08:00
|
|
|
#include <linux/security.h>
|
2013-12-20 21:16:49 +08:00
|
|
|
#include <linux/posix_acl_xattr.h>
|
2023-02-01 21:14:57 +08:00
|
|
|
#include <linux/xattr.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#define PRIVROOT_NAME ".reiserfs_priv"
|
|
|
|
#define XAROOT_NAME "xattrs"
|
|
|
|
|
|
|
|
|
2014-04-23 22:00:36 +08:00
|
|
|
/*
|
|
|
|
* Helpers for inode ops. We do this so that we don't have all the VFS
|
2009-03-31 02:02:34 +08:00
|
|
|
* overhead and also for proper i_mutex annotation.
|
2014-04-23 22:00:36 +08:00
|
|
|
* dir->i_mutex must be held for all of them.
|
|
|
|
*/
|
2009-03-31 04:49:58 +08:00
|
|
|
#ifdef CONFIG_REISERFS_FS_XATTR
|
2009-03-31 02:02:34 +08:00
|
|
|
static int xattr_create(struct inode *dir, struct dentry *dentry, int mode)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2016-01-23 04:40:57 +08:00
|
|
|
BUG_ON(!inode_is_locked(dir));
|
2023-01-13 19:49:13 +08:00
|
|
|
return dir->i_op->create(&nop_mnt_idmap, dir, dentry, mode, true);
|
2009-03-31 02:02:34 +08:00
|
|
|
}
|
2009-03-31 04:49:58 +08:00
|
|
|
#endif
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2011-07-26 13:41:39 +08:00
|
|
|
static int xattr_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
|
2009-03-31 02:02:34 +08:00
|
|
|
{
|
2016-01-23 04:40:57 +08:00
|
|
|
BUG_ON(!inode_is_locked(dir));
|
2023-01-13 19:49:15 +08:00
|
|
|
return dir->i_op->mkdir(&nop_mnt_idmap, dir, dentry, mode);
|
2009-03-31 02:02:34 +08:00
|
|
|
}
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2014-04-23 22:00:36 +08:00
|
|
|
/*
|
|
|
|
* We use I_MUTEX_CHILD here to silence lockdep. It's safe because xattr
|
2009-03-31 02:02:34 +08:00
|
|
|
* mutation ops aren't called during rename or splace, which are the
|
|
|
|
* only other users of I_MUTEX_CHILD. It violates the ordering, but that's
|
2014-04-23 22:00:36 +08:00
|
|
|
* better than allocating another subclass just for this code.
|
|
|
|
*/
|
2009-03-31 02:02:34 +08:00
|
|
|
static int xattr_unlink(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
int error;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
BUG_ON(!inode_is_locked(dir));
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(dentry), I_MUTEX_CHILD);
|
2009-03-31 02:02:34 +08:00
|
|
|
error = dir->i_op->unlink(dir, dentry);
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(dentry));
|
2009-03-31 02:02:34 +08:00
|
|
|
|
|
|
|
if (!error)
|
|
|
|
d_delete(dentry);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int xattr_rmdir(struct inode *dir, struct dentry *dentry)
|
|
|
|
{
|
|
|
|
int error;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
BUG_ON(!inode_is_locked(dir));
|
2009-03-31 02:02:34 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(dentry), I_MUTEX_CHILD);
|
2009-03-31 02:02:34 +08:00
|
|
|
error = dir->i_op->rmdir(dir, dentry);
|
|
|
|
if (!error)
|
2015-03-18 06:25:59 +08:00
|
|
|
d_inode(dentry)->i_flags |= S_DEAD;
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(dentry));
|
2009-03-31 02:02:34 +08:00
|
|
|
if (!error)
|
|
|
|
d_delete(dentry);
|
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define xattr_may_create(flags) (!flags || flags & XATTR_CREATE)
|
|
|
|
|
2009-05-06 03:30:15 +08:00
|
|
|
static struct dentry *open_xa_root(struct super_block *sb, int flags)
|
2009-03-31 02:02:34 +08:00
|
|
|
{
|
2009-05-06 03:30:15 +08:00
|
|
|
struct dentry *privroot = REISERFS_SB(sb)->priv_root;
|
|
|
|
struct dentry *xaroot;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
if (d_really_is_negative(privroot))
|
2019-10-24 22:31:27 +08:00
|
|
|
return ERR_PTR(-EOPNOTSUPP);
|
2009-03-31 02:02:34 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(privroot), I_MUTEX_XATTR);
|
2009-03-31 02:02:34 +08:00
|
|
|
|
2009-05-06 03:30:15 +08:00
|
|
|
xaroot = dget(REISERFS_SB(sb)->xattr_root);
|
2009-05-17 13:02:02 +08:00
|
|
|
if (!xaroot)
|
2019-10-24 22:31:27 +08:00
|
|
|
xaroot = ERR_PTR(-EOPNOTSUPP);
|
2015-03-18 06:25:59 +08:00
|
|
|
else if (d_really_is_negative(xaroot)) {
|
2009-05-06 03:30:15 +08:00
|
|
|
int err = -ENODATA;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2009-05-02 00:11:12 +08:00
|
|
|
if (xattr_may_create(flags))
|
2015-03-18 06:25:59 +08:00
|
|
|
err = xattr_mkdir(d_inode(privroot), xaroot, 0700);
|
2007-04-24 05:41:17 +08:00
|
|
|
if (err) {
|
2009-05-06 03:30:15 +08:00
|
|
|
dput(xaroot);
|
|
|
|
xaroot = ERR_PTR(err);
|
2007-04-24 05:41:17 +08:00
|
|
|
}
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
2009-03-31 02:02:34 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(privroot));
|
2009-05-06 03:30:15 +08:00
|
|
|
return xaroot;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
static struct dentry *open_xa_dir(const struct inode *inode, int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-13 11:21:28 +08:00
|
|
|
struct dentry *xaroot, *xadir;
|
|
|
|
char namebuf[17];
|
|
|
|
|
2009-03-31 02:02:34 +08:00
|
|
|
xaroot = open_xa_root(inode->i_sb, flags);
|
2007-04-24 05:41:17 +08:00
|
|
|
if (IS_ERR(xaroot))
|
2005-07-13 11:21:28 +08:00
|
|
|
return xaroot;
|
|
|
|
|
|
|
|
snprintf(namebuf, sizeof(namebuf), "%X.%X",
|
|
|
|
le32_to_cpu(INODE_PKEY(inode)->k_objectid),
|
|
|
|
inode->i_generation);
|
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(xaroot), I_MUTEX_XATTR);
|
2009-05-06 03:30:15 +08:00
|
|
|
|
|
|
|
xadir = lookup_one_len(namebuf, xaroot, strlen(namebuf));
|
2015-03-18 06:25:59 +08:00
|
|
|
if (!IS_ERR(xadir) && d_really_is_negative(xadir)) {
|
2009-05-06 03:30:15 +08:00
|
|
|
int err = -ENODATA;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2009-05-06 03:30:15 +08:00
|
|
|
if (xattr_may_create(flags))
|
2015-03-18 06:25:59 +08:00
|
|
|
err = xattr_mkdir(d_inode(xaroot), xadir, 0700);
|
2009-05-06 03:30:15 +08:00
|
|
|
if (err) {
|
|
|
|
dput(xadir);
|
|
|
|
xadir = ERR_PTR(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(xaroot));
|
2005-07-13 11:21:28 +08:00
|
|
|
dput(xaroot);
|
|
|
|
return xadir;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2014-04-23 22:00:36 +08:00
|
|
|
/*
|
|
|
|
* The following are side effects of other operations that aren't explicitly
|
2009-03-31 02:02:38 +08:00
|
|
|
* modifying extended attributes. This includes operations such as permissions
|
2014-04-23 22:00:36 +08:00
|
|
|
* or ownership changes, object deletions, etc.
|
|
|
|
*/
|
2009-03-31 02:02:40 +08:00
|
|
|
struct reiserfs_dentry_buf {
|
2013-05-18 10:42:17 +08:00
|
|
|
struct dir_context ctx;
|
2009-03-31 02:02:40 +08:00
|
|
|
struct dentry *xadir;
|
|
|
|
int count;
|
2018-10-31 06:06:38 +08:00
|
|
|
int err;
|
2009-03-31 02:02:40 +08:00
|
|
|
struct dentry *dentries[8];
|
|
|
|
};
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2022-08-16 23:57:56 +08:00
|
|
|
static bool
|
2014-10-31 00:37:34 +08:00
|
|
|
fill_with_dentries(struct dir_context *ctx, const char *name, int namelen,
|
|
|
|
loff_t offset, u64 ino, unsigned int d_type)
|
2009-03-31 02:02:33 +08:00
|
|
|
{
|
2014-10-31 00:37:34 +08:00
|
|
|
struct reiserfs_dentry_buf *dbuf =
|
|
|
|
container_of(ctx, struct reiserfs_dentry_buf, ctx);
|
2009-03-31 02:02:33 +08:00
|
|
|
struct dentry *dentry;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
WARN_ON_ONCE(!inode_is_locked(d_inode(dbuf->xadir)));
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
if (dbuf->count == ARRAY_SIZE(dbuf->dentries))
|
2022-08-16 23:57:56 +08:00
|
|
|
return false;
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2013-03-29 22:39:16 +08:00
|
|
|
if (name[0] == '.' && (namelen < 2 ||
|
|
|
|
(namelen == 2 && name[1] == '.')))
|
2022-08-16 23:57:56 +08:00
|
|
|
return true;
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
dentry = lookup_one_len(name, dbuf->xadir, namelen);
|
2009-03-31 02:02:33 +08:00
|
|
|
if (IS_ERR(dentry)) {
|
2018-10-31 06:06:38 +08:00
|
|
|
dbuf->err = PTR_ERR(dentry);
|
2022-08-16 23:57:56 +08:00
|
|
|
return false;
|
2015-03-18 06:25:59 +08:00
|
|
|
} else if (d_really_is_negative(dentry)) {
|
2009-03-31 02:02:40 +08:00
|
|
|
/* A directory entry exists, but no file? */
|
|
|
|
reiserfs_error(dentry->d_sb, "xattr-20003",
|
2014-10-22 08:11:25 +08:00
|
|
|
"Corrupted directory: xattr %pd listed but "
|
|
|
|
"not found for file %pd.\n",
|
|
|
|
dentry, dbuf->xadir);
|
2009-03-31 02:02:40 +08:00
|
|
|
dput(dentry);
|
2018-10-31 06:06:38 +08:00
|
|
|
dbuf->err = -EIO;
|
2022-08-16 23:57:56 +08:00
|
|
|
return false;
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
dbuf->dentries[dbuf->count++] = dentry;
|
2022-08-16 23:57:56 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
static void
|
|
|
|
cleanup_dentry_buf(struct reiserfs_dentry_buf *buf)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-03-31 02:02:40 +08:00
|
|
|
int i;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
for (i = 0; i < buf->count; i++)
|
|
|
|
if (buf->dentries[i])
|
|
|
|
dput(buf->dentries[i]);
|
2009-03-31 02:02:33 +08:00
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
static int reiserfs_for_each_xattr(struct inode *inode,
|
|
|
|
int (*action)(struct dentry *, void *),
|
|
|
|
void *data)
|
2009-03-31 02:02:33 +08:00
|
|
|
{
|
2009-03-31 02:02:40 +08:00
|
|
|
struct dentry *dir;
|
|
|
|
int i, err = 0;
|
|
|
|
struct reiserfs_dentry_buf buf = {
|
2013-05-18 10:42:17 +08:00
|
|
|
.ctx.actor = fill_with_dentries,
|
2009-03-31 02:02:40 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:33 +08:00
|
|
|
/* Skip out, an xattr has no xattrs associated with it */
|
|
|
|
if (IS_PRIVATE(inode) || get_inode_sd_version(inode) == STAT_DATA_V1)
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:34 +08:00
|
|
|
dir = open_xa_dir(inode, XATTR_REPLACE);
|
2009-03-31 02:02:33 +08:00
|
|
|
if (IS_ERR(dir)) {
|
|
|
|
err = PTR_ERR(dir);
|
|
|
|
goto out;
|
2015-03-18 06:25:59 +08:00
|
|
|
} else if (d_really_is_negative(dir)) {
|
2009-03-31 02:02:40 +08:00
|
|
|
err = 0;
|
|
|
|
goto out_dir;
|
2009-03-31 02:02:33 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(dir), I_MUTEX_XATTR);
|
2009-12-30 12:06:21 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
buf.xadir = dir;
|
2013-05-18 10:58:58 +08:00
|
|
|
while (1) {
|
2015-03-18 06:25:59 +08:00
|
|
|
err = reiserfs_readdir_inode(d_inode(dir), &buf.ctx);
|
2013-05-18 10:58:58 +08:00
|
|
|
if (err)
|
|
|
|
break;
|
2018-10-31 06:06:38 +08:00
|
|
|
if (buf.err) {
|
|
|
|
err = buf.err;
|
|
|
|
break;
|
|
|
|
}
|
2013-05-18 10:58:58 +08:00
|
|
|
if (!buf.count)
|
|
|
|
break;
|
|
|
|
for (i = 0; !err && i < buf.count && buf.dentries[i]; i++) {
|
2009-03-31 02:02:40 +08:00
|
|
|
struct dentry *dentry = buf.dentries[i];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
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))
|
2013-05-18 10:58:58 +08:00
|
|
|
err = action(dentry, data);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
dput(dentry);
|
|
|
|
buf.dentries[i] = NULL;
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
2013-05-18 10:58:58 +08:00
|
|
|
if (err)
|
|
|
|
break;
|
2009-03-31 02:02:40 +08:00
|
|
|
buf.count = 0;
|
2009-03-31 02:02:36 +08:00
|
|
|
}
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(dir));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
cleanup_dentry_buf(&buf);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:35 +08:00
|
|
|
if (!err) {
|
2014-04-23 22:00:36 +08:00
|
|
|
/*
|
|
|
|
* We start a transaction here to avoid a ABBA situation
|
2009-03-31 02:02:40 +08:00
|
|
|
* between the xattr root's i_mutex and the journal lock.
|
|
|
|
* This doesn't incur much additional overhead since the
|
|
|
|
* new transaction will just nest inside the
|
2014-04-23 22:00:36 +08:00
|
|
|
* outer transaction.
|
|
|
|
*/
|
2009-03-31 02:02:40 +08:00
|
|
|
int blocks = JOURNAL_PER_BALANCE_CNT * 2 + 2 +
|
|
|
|
4 * REISERFS_QUOTA_TRANS_BLOCKS(inode->i_sb);
|
|
|
|
struct reiserfs_transaction_handle th;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2013-08-09 05:27:19 +08:00
|
|
|
reiserfs_write_lock(inode->i_sb);
|
2009-03-31 02:02:40 +08:00
|
|
|
err = journal_begin(&th, inode->i_sb, blocks);
|
2013-08-09 05:27:19 +08:00
|
|
|
reiserfs_write_unlock(inode->i_sb);
|
2009-03-31 02:02:40 +08:00
|
|
|
if (!err) {
|
|
|
|
int jerror;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(dir->d_parent),
|
2013-08-09 05:27:19 +08:00
|
|
|
I_MUTEX_XATTR);
|
2009-03-31 02:02:40 +08:00
|
|
|
err = action(dir, data);
|
2013-08-09 05:27:19 +08:00
|
|
|
reiserfs_write_lock(inode->i_sb);
|
2014-04-23 22:00:38 +08:00
|
|
|
jerror = journal_end(&th);
|
2013-08-09 05:27:19 +08:00
|
|
|
reiserfs_write_unlock(inode->i_sb);
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(dir->d_parent));
|
2009-03-31 02:02:40 +08:00
|
|
|
err = jerror ?: err;
|
|
|
|
}
|
2009-03-31 02:02:33 +08:00
|
|
|
}
|
2009-03-31 02:02:40 +08:00
|
|
|
out_dir:
|
|
|
|
dput(dir);
|
2009-03-31 02:02:33 +08:00
|
|
|
out:
|
2020-01-16 02:00:59 +08:00
|
|
|
/*
|
|
|
|
* -ENODATA: this object doesn't have any xattrs
|
|
|
|
* -EOPNOTSUPP: this file system doesn't have xattrs enabled on disk.
|
|
|
|
* Neither are errors
|
|
|
|
*/
|
|
|
|
if (err == -ENODATA || err == -EOPNOTSUPP)
|
2009-03-31 02:02:40 +08:00
|
|
|
err = 0;
|
2009-03-31 02:02:33 +08:00
|
|
|
return err;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
static int delete_one_xattr(struct dentry *dentry, void *data)
|
2009-03-31 02:02:33 +08:00
|
|
|
{
|
2015-03-18 06:25:59 +08:00
|
|
|
struct inode *dir = d_inode(dentry->d_parent);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
/* This is the xattr dir, handle specially. */
|
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))
|
2009-03-31 02:02:40 +08:00
|
|
|
return xattr_rmdir(dir, dentry);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
return xattr_unlink(dir, dentry);
|
|
|
|
}
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
static int chown_one_xattr(struct dentry *dentry, void *data)
|
|
|
|
{
|
|
|
|
struct iattr *attrs = data;
|
2013-06-01 03:54:17 +08:00
|
|
|
int ia_valid = attrs->ia_valid;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We only want the ownership bits. Otherwise, we'll do
|
|
|
|
* things like change a directory to a regular file if
|
|
|
|
* ATTR_MODE is set.
|
|
|
|
*/
|
|
|
|
attrs->ia_valid &= (ATTR_UID|ATTR_GID);
|
2023-01-13 19:49:11 +08:00
|
|
|
err = reiserfs_setattr(&nop_mnt_idmap, dentry, attrs);
|
2013-06-01 03:54:17 +08:00
|
|
|
attrs->ia_valid = ia_valid;
|
|
|
|
|
|
|
|
return err;
|
2009-03-31 02:02:40 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
/* No i_mutex, but the inode is unconnected. */
|
|
|
|
int reiserfs_delete_xattrs(struct inode *inode)
|
|
|
|
{
|
|
|
|
int err = reiserfs_for_each_xattr(inode, delete_one_xattr, NULL);
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
if (err)
|
|
|
|
reiserfs_warning(inode->i_sb, "jdm-20004",
|
|
|
|
"Couldn't delete all xattrs (%d)\n", err);
|
2009-03-31 02:02:33 +08:00
|
|
|
return err;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:40 +08:00
|
|
|
/* inode->i_mutex: down */
|
2009-03-31 02:02:33 +08:00
|
|
|
int reiserfs_chown_xattrs(struct inode *inode, struct iattr *attrs)
|
|
|
|
{
|
2009-03-31 02:02:40 +08:00
|
|
|
int err = reiserfs_for_each_xattr(inode, chown_one_xattr, attrs);
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2009-03-31 02:02:36 +08:00
|
|
|
if (err)
|
|
|
|
reiserfs_warning(inode->i_sb, "jdm-20007",
|
|
|
|
"Couldn't chown all xattrs (%d)\n", err);
|
2009-03-31 02:02:33 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:33 +08:00
|
|
|
#ifdef CONFIG_REISERFS_FS_XATTR
|
2014-04-23 22:00:36 +08:00
|
|
|
/*
|
|
|
|
* Returns a dentry corresponding to a specific extended attribute file
|
2009-03-31 02:02:33 +08:00
|
|
|
* for the inode. If flags allow, the file is created. Otherwise, a
|
2014-04-23 22:00:36 +08:00
|
|
|
* valid or negative dentry, or an error is returned.
|
|
|
|
*/
|
2009-03-31 02:02:38 +08:00
|
|
|
static struct dentry *xattr_lookup(struct inode *inode, const char *name,
|
|
|
|
int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-03-31 02:02:33 +08:00
|
|
|
struct dentry *xadir, *xafile;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
xadir = open_xa_dir(inode, flags);
|
2009-03-31 02:02:34 +08:00
|
|
|
if (IS_ERR(xadir))
|
2009-03-31 02:02:33 +08:00
|
|
|
return ERR_CAST(xadir);
|
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(xadir), I_MUTEX_XATTR);
|
2009-03-31 02:02:33 +08:00
|
|
|
xafile = lookup_one_len(name, xadir, strlen(name));
|
|
|
|
if (IS_ERR(xafile)) {
|
2009-03-31 02:02:34 +08:00
|
|
|
err = PTR_ERR(xafile);
|
|
|
|
goto out;
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
2009-03-31 02:02:33 +08:00
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
if (d_really_is_positive(xafile) && (flags & XATTR_CREATE))
|
2009-03-31 02:02:34 +08:00
|
|
|
err = -EEXIST;
|
2009-03-31 02:02:33 +08:00
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
if (d_really_is_negative(xafile)) {
|
2009-03-31 02:02:34 +08:00
|
|
|
err = -ENODATA;
|
2009-05-02 00:11:12 +08:00
|
|
|
if (xattr_may_create(flags))
|
2015-03-18 06:25:59 +08:00
|
|
|
err = xattr_create(d_inode(xadir), xafile,
|
2009-03-31 02:02:34 +08:00
|
|
|
0700|S_IFREG);
|
2009-03-31 02:02:33 +08:00
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:34 +08:00
|
|
|
if (err)
|
|
|
|
dput(xafile);
|
2009-03-31 02:02:33 +08:00
|
|
|
out:
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(xadir));
|
2009-03-31 02:02:33 +08:00
|
|
|
dput(xadir);
|
|
|
|
if (err)
|
2009-03-31 02:02:34 +08:00
|
|
|
return ERR_PTR(err);
|
2009-03-31 02:02:33 +08:00
|
|
|
return xafile;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Internal operations on file data */
|
2005-07-13 11:21:28 +08:00
|
|
|
static inline void reiserfs_put_page(struct page *page)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-13 11:21:28 +08:00
|
|
|
kunmap(page);
|
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
|
|
|
put_page(page);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:30 +08:00
|
|
|
static struct page *reiserfs_get_page(struct inode *dir, size_t n)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-13 11:21:28 +08:00
|
|
|
struct address_space *mapping = dir->i_mapping;
|
|
|
|
struct page *page;
|
2014-04-23 22:00:36 +08:00
|
|
|
/*
|
|
|
|
* We can deadlock if we try to free dentries,
|
|
|
|
* and an unlink/rmdir has just occurred - GFP_NOFS avoids this
|
|
|
|
*/
|
2005-10-21 15:22:39 +08:00
|
|
|
mapping_set_gfp_mask(mapping, GFP_NOFS);
|
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
|
|
|
page = read_mapping_page(mapping, n >> PAGE_SHIFT, NULL);
|
2022-05-18 06:12:25 +08:00
|
|
|
if (!IS_ERR(page))
|
2005-07-13 11:21:28 +08:00
|
|
|
kmap(page);
|
|
|
|
return page;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
static inline __u32 xattr_hash(const char *msg, int len)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2019-05-15 06:44:29 +08:00
|
|
|
/*
|
|
|
|
* csum_partial() gives different results for little-endian and
|
|
|
|
* big endian hosts. Images created on little-endian hosts and
|
|
|
|
* mounted on big-endian hosts(and vice versa) will see csum mismatches
|
|
|
|
* when trying to fetch xattrs. Treating the hash as __wsum_t would
|
|
|
|
* lower the frequency of mismatch. This is an endianness bug in
|
|
|
|
* reiserfs. The return statement would result in a sparse warning. Do
|
|
|
|
* not fix the sparse warning so as to not hide a reminder of the bug.
|
|
|
|
*/
|
2005-07-13 11:21:28 +08:00
|
|
|
return csum_partial(msg, len, 0);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-10-16 16:25:14 +08:00
|
|
|
int reiserfs_commit_write(struct file *f, struct page *page,
|
|
|
|
unsigned from, unsigned to);
|
|
|
|
|
2009-03-31 02:02:38 +08:00
|
|
|
static void update_ctime(struct inode *inode)
|
|
|
|
{
|
vfs: change inode times to use struct timespec64
struct timespec is not y2038 safe. Transition vfs to use
y2038 safe struct timespec64 instead.
The change was made with the help of the following cocinelle
script. This catches about 80% of the changes.
All the header file and logic changes are included in the
first 5 rules. The rest are trivial substitutions.
I avoid changing any of the function signatures or any other
filesystem specific data structures to keep the patch simple
for review.
The script can be a little shorter by combining different cases.
But, this version was sufficient for my usecase.
virtual patch
@ depends on patch @
identifier now;
@@
- struct timespec
+ struct timespec64
current_time ( ... )
{
- struct timespec now = current_kernel_time();
+ struct timespec64 now = current_kernel_time64();
...
- return timespec_trunc(
+ return timespec64_trunc(
... );
}
@ depends on patch @
identifier xtime;
@@
struct \( iattr \| inode \| kstat \) {
...
- struct timespec xtime;
+ struct timespec64 xtime;
...
}
@ depends on patch @
identifier t;
@@
struct inode_operations {
...
int (*update_time) (...,
- struct timespec t,
+ struct timespec64 t,
...);
...
}
@ depends on patch @
identifier t;
identifier fn_update_time =~ "update_time$";
@@
fn_update_time (...,
- struct timespec *t,
+ struct timespec64 *t,
...) { ... }
@ depends on patch @
identifier t;
@@
lease_get_mtime( ... ,
- struct timespec *t
+ struct timespec64 *t
) { ... }
@te depends on patch forall@
identifier ts;
local idexpression struct inode *inode_node;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn_update_time =~ "update_time$";
identifier fn;
expression e, E3;
local idexpression struct inode *node1;
local idexpression struct inode *node2;
local idexpression struct iattr *attr1;
local idexpression struct iattr *attr2;
local idexpression struct iattr attr;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
@@
(
(
- struct timespec ts;
+ struct timespec64 ts;
|
- struct timespec ts = current_time(inode_node);
+ struct timespec64 ts = current_time(inode_node);
)
<+... when != ts
(
- timespec_equal(&inode_node->i_xtime, &ts)
+ timespec64_equal(&inode_node->i_xtime, &ts)
|
- timespec_equal(&ts, &inode_node->i_xtime)
+ timespec64_equal(&ts, &inode_node->i_xtime)
|
- timespec_compare(&inode_node->i_xtime, &ts)
+ timespec64_compare(&inode_node->i_xtime, &ts)
|
- timespec_compare(&ts, &inode_node->i_xtime)
+ timespec64_compare(&ts, &inode_node->i_xtime)
|
ts = current_time(e)
|
fn_update_time(..., &ts,...)
|
inode_node->i_xtime = ts
|
node1->i_xtime = ts
|
ts = inode_node->i_xtime
|
<+... attr1->ia_xtime ...+> = ts
|
ts = attr1->ia_xtime
|
ts.tv_sec
|
ts.tv_nsec
|
btrfs_set_stack_timespec_sec(..., ts.tv_sec)
|
btrfs_set_stack_timespec_nsec(..., ts.tv_nsec)
|
- ts = timespec64_to_timespec(
+ ts =
...
-)
|
- ts = ktime_to_timespec(
+ ts = ktime_to_timespec64(
...)
|
- ts = E3
+ ts = timespec_to_timespec64(E3)
|
- ktime_get_real_ts(&ts)
+ ktime_get_real_ts64(&ts)
|
fn(...,
- ts
+ timespec64_to_timespec(ts)
,...)
)
...+>
(
<... when != ts
- return ts;
+ return timespec64_to_timespec(ts);
...>
)
|
- timespec_equal(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_equal(&node1->i_xtime2, &node2->i_xtime2)
|
- timespec_equal(&node1->i_xtime1, &attr2->ia_xtime2)
+ timespec64_equal(&node1->i_xtime2, &attr2->ia_xtime2)
|
- timespec_compare(&node1->i_xtime1, &node2->i_xtime2)
+ timespec64_compare(&node1->i_xtime1, &node2->i_xtime2)
|
node1->i_xtime1 =
- timespec_trunc(attr1->ia_xtime1,
+ timespec64_trunc(attr1->ia_xtime1,
...)
|
- attr1->ia_xtime1 = timespec_trunc(attr2->ia_xtime2,
+ attr1->ia_xtime1 = timespec64_trunc(attr2->ia_xtime2,
...)
|
- ktime_get_real_ts(&attr1->ia_xtime1)
+ ktime_get_real_ts64(&attr1->ia_xtime1)
|
- ktime_get_real_ts(&attr.ia_xtime1)
+ ktime_get_real_ts64(&attr.ia_xtime1)
)
@ depends on patch @
struct inode *node;
struct iattr *attr;
identifier fn;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
expression e;
@@
(
- fn(node->i_xtime);
+ fn(timespec64_to_timespec(node->i_xtime));
|
fn(...,
- node->i_xtime);
+ timespec64_to_timespec(node->i_xtime));
|
- e = fn(attr->ia_xtime);
+ e = fn(timespec64_to_timespec(attr->ia_xtime));
)
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
identifier i_xtime =~ "^i_[acm]time$";
identifier ia_xtime =~ "^ia_[acm]time$";
identifier fn;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
fn (...,
- &attr->ia_xtime,
+ &ts,
...);
)
...+>
}
@ depends on patch forall @
struct inode *node;
struct iattr *attr;
struct kstat *stat;
identifier ia_xtime =~ "^ia_[acm]time$";
identifier i_xtime =~ "^i_[acm]time$";
identifier xtime =~ "^[acm]time$";
identifier fn, ret;
@@
{
+ struct timespec ts;
<+...
(
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(node->i_xtime);
ret = fn (...,
- &node->i_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime,
+ &ts,
...);
|
+ ts = timespec64_to_timespec(attr->ia_xtime);
ret = fn (...,
- &attr->ia_xtime);
+ &ts);
|
+ ts = timespec64_to_timespec(stat->xtime);
ret = fn (...,
- &stat->xtime);
+ &ts);
)
...+>
}
@ depends on patch @
struct inode *node;
struct inode *node2;
identifier i_xtime1 =~ "^i_[acm]time$";
identifier i_xtime2 =~ "^i_[acm]time$";
identifier i_xtime3 =~ "^i_[acm]time$";
struct iattr *attrp;
struct iattr *attrp2;
struct iattr attr ;
identifier ia_xtime1 =~ "^ia_[acm]time$";
identifier ia_xtime2 =~ "^ia_[acm]time$";
struct kstat *stat;
struct kstat stat1;
struct timespec64 ts;
identifier xtime =~ "^[acmb]time$";
expression e;
@@
(
( node->i_xtime2 \| attrp->ia_xtime2 \| attr.ia_xtime2 \) = node->i_xtime1 ;
|
node->i_xtime2 = \( node2->i_xtime1 \| timespec64_trunc(...) \);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
node->i_xtime1 = node->i_xtime3 = \(ts \| current_time(...) \);
|
stat->xtime = node2->i_xtime1;
|
stat1.xtime = node2->i_xtime1;
|
( node->i_xtime2 \| attrp->ia_xtime2 \) = attrp->ia_xtime1 ;
|
( attrp->ia_xtime1 \| attr.ia_xtime1 \) = attrp2->ia_xtime2;
|
- e = node->i_xtime1;
+ e = timespec64_to_timespec( node->i_xtime1 );
|
- e = attrp->ia_xtime1;
+ e = timespec64_to_timespec( attrp->ia_xtime1 );
|
node->i_xtime1 = current_time(...);
|
node->i_xtime2 = node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
node->i_xtime1 = node->i_xtime3 =
- e;
+ timespec_to_timespec64(e);
|
- node->i_xtime1 = e;
+ node->i_xtime1 = timespec_to_timespec64(e);
)
Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Cc: <anton@tuxera.com>
Cc: <balbi@kernel.org>
Cc: <bfields@fieldses.org>
Cc: <darrick.wong@oracle.com>
Cc: <dhowells@redhat.com>
Cc: <dsterba@suse.com>
Cc: <dwmw2@infradead.org>
Cc: <hch@lst.de>
Cc: <hirofumi@mail.parknet.co.jp>
Cc: <hubcap@omnibond.com>
Cc: <jack@suse.com>
Cc: <jaegeuk@kernel.org>
Cc: <jaharkes@cs.cmu.edu>
Cc: <jslaby@suse.com>
Cc: <keescook@chromium.org>
Cc: <mark@fasheh.com>
Cc: <miklos@szeredi.hu>
Cc: <nico@linaro.org>
Cc: <reiserfs-devel@vger.kernel.org>
Cc: <richard@nod.at>
Cc: <sage@redhat.com>
Cc: <sfrench@samba.org>
Cc: <swhiteho@redhat.com>
Cc: <tj@kernel.org>
Cc: <trond.myklebust@primarydata.com>
Cc: <tytso@mit.edu>
Cc: <viro@zeniv.linux.org.uk>
2018-05-09 10:36:02 +08:00
|
|
|
struct timespec64 now = current_time(inode);
|
2023-07-06 03:01:37 +08:00
|
|
|
struct timespec64 ctime = inode_get_ctime(inode);
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2010-10-24 03:19:20 +08:00
|
|
|
if (inode_unhashed(inode) || !inode->i_nlink ||
|
2023-07-06 03:01:37 +08:00
|
|
|
timespec64_equal(&ctime, &now))
|
2009-03-31 02:02:38 +08:00
|
|
|
return;
|
|
|
|
|
2023-07-06 03:01:37 +08:00
|
|
|
inode_set_ctime_to_ts(inode, now);
|
2009-03-31 02:02:38 +08:00
|
|
|
mark_inode_dirty(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int lookup_and_delete_xattr(struct inode *inode, const char *name)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct dentry *dentry, *xadir;
|
|
|
|
|
|
|
|
xadir = open_xa_dir(inode, XATTR_REPLACE);
|
|
|
|
if (IS_ERR(xadir))
|
|
|
|
return PTR_ERR(xadir);
|
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(xadir), I_MUTEX_XATTR);
|
2009-03-31 02:02:38 +08:00
|
|
|
dentry = lookup_one_len(name, xadir, strlen(name));
|
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
err = PTR_ERR(dentry);
|
|
|
|
goto out_dput;
|
|
|
|
}
|
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
if (d_really_is_positive(dentry)) {
|
|
|
|
err = xattr_unlink(d_inode(xadir), dentry);
|
2009-03-31 02:02:38 +08:00
|
|
|
update_ctime(inode);
|
|
|
|
}
|
|
|
|
|
|
|
|
dput(dentry);
|
|
|
|
out_dput:
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(xadir));
|
2009-03-31 02:02:38 +08:00
|
|
|
dput(xadir);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-10-16 16:25:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Generic extended attribute operations that can be used by xa plugins */
|
|
|
|
|
|
|
|
/*
|
2006-01-10 07:59:24 +08:00
|
|
|
* inode->i_mutex: down
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
int
|
2009-03-31 02:02:39 +08:00
|
|
|
reiserfs_xattr_set_handle(struct reiserfs_transaction_handle *th,
|
|
|
|
struct inode *inode, const char *name,
|
|
|
|
const void *buffer, size_t buffer_size, int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-13 11:21:28 +08:00
|
|
|
int err = 0;
|
2008-02-16 06:37:22 +08:00
|
|
|
struct dentry *dentry;
|
2005-07-13 11:21:28 +08:00
|
|
|
struct page *page;
|
|
|
|
char *data;
|
|
|
|
size_t file_pos = 0;
|
|
|
|
size_t buffer_pos = 0;
|
2009-03-31 02:02:38 +08:00
|
|
|
size_t new_size;
|
2005-07-13 11:21:28 +08:00
|
|
|
__u32 xahash = 0;
|
|
|
|
|
|
|
|
if (get_inode_sd_version(inode) == STAT_DATA_V1)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2010-01-05 09:14:30 +08:00
|
|
|
if (!buffer) {
|
|
|
|
err = lookup_and_delete_xattr(inode, name);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:38 +08:00
|
|
|
dentry = xattr_lookup(inode, name, flags);
|
2013-08-09 05:27:19 +08:00
|
|
|
if (IS_ERR(dentry))
|
2009-03-31 02:02:38 +08:00
|
|
|
return PTR_ERR(dentry);
|
reiserfs: Relax lock before open xattr dir in reiserfs_xattr_set_handle()
We call xattr_lookup() from reiserfs_xattr_get(). We then hold
the reiserfs lock when we grab the i_mutex. But later, we may
relax the reiserfs lock, creating dependency inversion between
both locks.
The lookups and creation jobs ar already protected by the
inode mutex, so we can safely relax the reiserfs lock, dropping
the unwanted reiserfs lock -> i_mutex dependency, as shown
in the following lockdep report:
=======================================================
[ INFO: possible circular locking dependency detected ]
2.6.32-atom #173
-------------------------------------------------------
cp/3204 is trying to acquire lock:
(&REISERFS_SB(s)->lock){+.+.+.}, at: [<c11432b9>] reiserfs_write_lock_once+0x29/0x50
but task is already holding lock:
(&sb->s_type->i_mutex_key#4/3){+.+.+.}, at: [<c1141e18>] open_xa_dir+0xd8/0x1b0
which lock already depends on the new lock.
the existing dependency chain (in reverse order) is:
-> #1 (&sb->s_type->i_mutex_key#4/3){+.+.+.}:
[<c105ea7f>] __lock_acquire+0x11ff/0x19e0
[<c105f2c8>] lock_acquire+0x68/0x90
[<c1401a2b>] mutex_lock_nested+0x5b/0x340
[<c1141d83>] open_xa_dir+0x43/0x1b0
[<c1142722>] reiserfs_for_each_xattr+0x62/0x260
[<c114299a>] reiserfs_delete_xattrs+0x1a/0x60
[<c111ea1f>] reiserfs_delete_inode+0x9f/0x150
[<c10c9c32>] generic_delete_inode+0xa2/0x170
[<c10c9d4f>] generic_drop_inode+0x4f/0x70
[<c10c8b07>] iput+0x47/0x50
[<c10c0965>] do_unlinkat+0xd5/0x160
[<c10c0a00>] sys_unlink+0x10/0x20
[<c1002ec4>] sysenter_do_call+0x12/0x32
-> #0 (&REISERFS_SB(s)->lock){+.+.+.}:
[<c105f176>] __lock_acquire+0x18f6/0x19e0
[<c105f2c8>] lock_acquire+0x68/0x90
[<c1401a2b>] mutex_lock_nested+0x5b/0x340
[<c11432b9>] reiserfs_write_lock_once+0x29/0x50
[<c1117012>] reiserfs_lookup+0x62/0x140
[<c10bd85f>] __lookup_hash+0xef/0x110
[<c10bf21d>] lookup_one_len+0x8d/0xc0
[<c1141e2a>] open_xa_dir+0xea/0x1b0
[<c1141fe5>] xattr_lookup+0x15/0x160
[<c1142476>] reiserfs_xattr_get+0x56/0x2a0
[<c1144042>] reiserfs_get_acl+0xa2/0x360
[<c114461a>] reiserfs_cache_default_acl+0x3a/0x160
[<c111789c>] reiserfs_mkdir+0x6c/0x2c0
[<c10bea96>] vfs_mkdir+0xd6/0x180
[<c10c0c10>] sys_mkdirat+0xc0/0xd0
[<c10c0c40>] sys_mkdir+0x20/0x30
[<c1002ec4>] sysenter_do_call+0x12/0x32
other info that might help us debug this:
2 locks held by cp/3204:
#0: (&sb->s_type->i_mutex_key#4/1){+.+.+.}, at: [<c10bd8d6>] lookup_create+0x26/0xa0
#1: (&sb->s_type->i_mutex_key#4/3){+.+.+.}, at: [<c1141e18>] open_xa_dir+0xd8/0x1b0
stack backtrace:
Pid: 3204, comm: cp Not tainted 2.6.32-atom #173
Call Trace:
[<c13ff993>] ? printk+0x18/0x1a
[<c105d33a>] print_circular_bug+0xca/0xd0
[<c105f176>] __lock_acquire+0x18f6/0x19e0
[<c105d3aa>] ? check_usage+0x6a/0x460
[<c105f2c8>] lock_acquire+0x68/0x90
[<c11432b9>] ? reiserfs_write_lock_once+0x29/0x50
[<c11432b9>] ? reiserfs_write_lock_once+0x29/0x50
[<c1401a2b>] mutex_lock_nested+0x5b/0x340
[<c11432b9>] ? reiserfs_write_lock_once+0x29/0x50
[<c11432b9>] reiserfs_write_lock_once+0x29/0x50
[<c1117012>] reiserfs_lookup+0x62/0x140
[<c105ccca>] ? debug_check_no_locks_freed+0x8a/0x140
[<c105cbe4>] ? trace_hardirqs_on_caller+0x124/0x170
[<c10bd85f>] __lookup_hash+0xef/0x110
[<c10bf21d>] lookup_one_len+0x8d/0xc0
[<c1141e2a>] open_xa_dir+0xea/0x1b0
[<c1141fe5>] xattr_lookup+0x15/0x160
[<c1142476>] reiserfs_xattr_get+0x56/0x2a0
[<c1144042>] reiserfs_get_acl+0xa2/0x360
[<c10ca2e7>] ? new_inode+0x27/0xa0
[<c114461a>] reiserfs_cache_default_acl+0x3a/0x160
[<c1402eb7>] ? _spin_unlock+0x27/0x40
[<c111789c>] reiserfs_mkdir+0x6c/0x2c0
[<c10c7cb8>] ? __d_lookup+0x108/0x190
[<c105c932>] ? mark_held_locks+0x62/0x80
[<c1401c8d>] ? mutex_lock_nested+0x2bd/0x340
[<c10bd17a>] ? generic_permission+0x1a/0xa0
[<c11788fe>] ? security_inode_permission+0x1e/0x20
[<c10bea96>] vfs_mkdir+0xd6/0x180
[<c10c0c10>] sys_mkdirat+0xc0/0xd0
[<c10505c6>] ? up_read+0x16/0x30
[<c1002fd8>] ? restore_all_notrace+0x0/0x18
[<c10c0c40>] sys_mkdir+0x20/0x30
[<c1002ec4>] sysenter_do_call+0x12/0x32
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Tested-by: Christian Kujau <lists@nerdbynature.de>
Cc: Alexander Beregalov <a.beregalov@gmail.com>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Ingo Molnar <mingo@elte.hu>
2009-12-30 14:03:53 +08:00
|
|
|
|
2010-01-03 10:44:53 +08:00
|
|
|
down_write(&REISERFS_I(inode)->i_xattr_sem);
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-03-31 02:02:36 +08:00
|
|
|
xahash = xattr_hash(buffer, buffer_size);
|
2005-07-13 11:21:28 +08:00
|
|
|
while (buffer_pos < buffer_size || buffer_pos == 0) {
|
|
|
|
size_t chunk;
|
|
|
|
size_t skip = 0;
|
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
|
|
|
size_t page_offset = (file_pos & (PAGE_SIZE - 1));
|
2014-08-09 05:21:14 +08:00
|
|
|
|
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
|
|
|
if (buffer_size - buffer_pos > PAGE_SIZE)
|
|
|
|
chunk = PAGE_SIZE;
|
2005-07-13 11:21:28 +08:00
|
|
|
else
|
|
|
|
chunk = buffer_size - buffer_pos;
|
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
page = reiserfs_get_page(d_inode(dentry), file_pos);
|
2005-07-13 11:21:28 +08:00
|
|
|
if (IS_ERR(page)) {
|
|
|
|
err = PTR_ERR(page);
|
2009-03-31 02:02:38 +08:00
|
|
|
goto out_unlock;
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lock_page(page);
|
|
|
|
data = page_address(page);
|
|
|
|
|
|
|
|
if (file_pos == 0) {
|
|
|
|
struct reiserfs_xattr_header *rxh;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2005-07-13 11:21:28 +08:00
|
|
|
skip = file_pos = sizeof(struct reiserfs_xattr_header);
|
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
|
|
|
if (chunk + skip > PAGE_SIZE)
|
|
|
|
chunk = PAGE_SIZE - skip;
|
2005-07-13 11:21:28 +08:00
|
|
|
rxh = (struct reiserfs_xattr_header *)data;
|
|
|
|
rxh->h_magic = cpu_to_le32(REISERFS_XATTR_MAGIC);
|
|
|
|
rxh->h_hash = cpu_to_le32(xahash);
|
|
|
|
}
|
|
|
|
|
2013-08-09 05:27:19 +08:00
|
|
|
reiserfs_write_lock(inode->i_sb);
|
2010-10-06 16:47:23 +08:00
|
|
|
err = __reiserfs_write_begin(page, page_offset, chunk + skip);
|
2005-07-13 11:21:28 +08:00
|
|
|
if (!err) {
|
|
|
|
if (buffer)
|
|
|
|
memcpy(data + skip, buffer + buffer_pos, chunk);
|
2008-02-16 06:37:22 +08:00
|
|
|
err = reiserfs_commit_write(NULL, page, page_offset,
|
|
|
|
page_offset + chunk +
|
|
|
|
skip);
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
2013-08-09 05:27:19 +08:00
|
|
|
reiserfs_write_unlock(inode->i_sb);
|
2005-07-13 11:21:28 +08:00
|
|
|
unlock_page(page);
|
|
|
|
reiserfs_put_page(page);
|
|
|
|
buffer_pos += chunk;
|
|
|
|
file_pos += chunk;
|
|
|
|
skip = 0;
|
|
|
|
if (err || buffer_size == 0 || !buffer)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:38 +08:00
|
|
|
new_size = buffer_size + sizeof(struct reiserfs_xattr_header);
|
2015-03-18 06:25:59 +08:00
|
|
|
if (!err && new_size < i_size_read(d_inode(dentry))) {
|
2009-03-31 02:02:38 +08:00
|
|
|
struct iattr newattrs = {
|
2016-09-14 22:48:05 +08:00
|
|
|
.ia_ctime = current_time(inode),
|
2010-04-24 01:17:41 +08:00
|
|
|
.ia_size = new_size,
|
2009-03-31 02:02:38 +08:00
|
|
|
.ia_valid = ATTR_SIZE | ATTR_CTIME,
|
|
|
|
};
|
2010-01-07 22:55:31 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(dentry), I_MUTEX_XATTR);
|
2015-03-18 06:25:59 +08:00
|
|
|
inode_dio_wait(d_inode(dentry));
|
2010-01-07 22:55:31 +08:00
|
|
|
|
2023-01-13 19:49:11 +08:00
|
|
|
err = reiserfs_setattr(&nop_mnt_idmap, dentry, &newattrs);
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(dentry));
|
2009-03-31 02:02:38 +08:00
|
|
|
} else
|
|
|
|
update_ctime(inode);
|
|
|
|
out_unlock:
|
2009-03-31 02:02:36 +08:00
|
|
|
up_write(&REISERFS_I(inode)->i_xattr_sem);
|
2008-02-16 06:37:22 +08:00
|
|
|
dput(dentry);
|
2009-03-31 02:02:38 +08:00
|
|
|
return err;
|
|
|
|
}
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-03-31 02:02:39 +08:00
|
|
|
/* We need to start a transaction to maintain lock ordering */
|
|
|
|
int reiserfs_xattr_set(struct inode *inode, const char *name,
|
|
|
|
const void *buffer, size_t buffer_size, int flags)
|
2009-03-31 02:02:38 +08:00
|
|
|
{
|
2009-03-31 02:02:39 +08:00
|
|
|
|
|
|
|
struct reiserfs_transaction_handle th;
|
|
|
|
int error, error2;
|
|
|
|
size_t jbegin_count = reiserfs_xattr_nblocks(inode, buffer_size);
|
|
|
|
|
2019-10-24 22:31:27 +08:00
|
|
|
/* Check before we start a transaction and then do nothing. */
|
|
|
|
if (!d_really_is_positive(REISERFS_SB(inode->i_sb)->priv_root))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2009-03-31 02:02:39 +08:00
|
|
|
if (!(flags & XATTR_REPLACE))
|
|
|
|
jbegin_count += reiserfs_xattr_jcreate_nblocks(inode);
|
|
|
|
|
|
|
|
reiserfs_write_lock(inode->i_sb);
|
|
|
|
error = journal_begin(&th, inode->i_sb, jbegin_count);
|
2013-08-09 05:27:19 +08:00
|
|
|
reiserfs_write_unlock(inode->i_sb);
|
2009-03-31 02:02:39 +08:00
|
|
|
if (error) {
|
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-03-31 02:02:39 +08:00
|
|
|
error = reiserfs_xattr_set_handle(&th, inode, name,
|
|
|
|
buffer, buffer_size, flags);
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2013-08-09 05:27:19 +08:00
|
|
|
reiserfs_write_lock(inode->i_sb);
|
2014-04-23 22:00:38 +08:00
|
|
|
error2 = journal_end(&th);
|
2013-08-09 05:27:19 +08:00
|
|
|
reiserfs_write_unlock(inode->i_sb);
|
2009-03-31 02:02:39 +08:00
|
|
|
if (error == 0)
|
|
|
|
error = error2;
|
|
|
|
|
|
|
|
return error;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2006-01-10 07:59:24 +08:00
|
|
|
* inode->i_mutex: down
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
int
|
2009-03-31 02:02:38 +08:00
|
|
|
reiserfs_xattr_get(struct inode *inode, const char *name, void *buffer,
|
2005-07-13 11:21:28 +08:00
|
|
|
size_t buffer_size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-13 11:21:28 +08:00
|
|
|
ssize_t err = 0;
|
2008-02-16 06:37:22 +08:00
|
|
|
struct dentry *dentry;
|
2005-07-13 11:21:28 +08:00
|
|
|
size_t isize;
|
|
|
|
size_t file_pos = 0;
|
|
|
|
size_t buffer_pos = 0;
|
|
|
|
struct page *page;
|
|
|
|
__u32 hash = 0;
|
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2014-04-23 22:00:36 +08:00
|
|
|
/*
|
|
|
|
* We can't have xattrs attached to v1 items since they don't have
|
|
|
|
* generation numbers
|
|
|
|
*/
|
2005-07-13 11:21:28 +08:00
|
|
|
if (get_inode_sd_version(inode) == STAT_DATA_V1)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2020-09-30 23:08:20 +08:00
|
|
|
/*
|
|
|
|
* priv_root needn't be initialized during mount so allow initial
|
|
|
|
* lookups to succeed.
|
|
|
|
*/
|
|
|
|
if (!REISERFS_SB(inode->i_sb)->priv_root)
|
|
|
|
return 0;
|
|
|
|
|
2009-03-31 02:02:38 +08:00
|
|
|
dentry = xattr_lookup(inode, name, XATTR_REPLACE);
|
2008-02-16 06:37:22 +08:00
|
|
|
if (IS_ERR(dentry)) {
|
|
|
|
err = PTR_ERR(dentry);
|
2005-07-13 11:21:28 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:36 +08:00
|
|
|
down_read(&REISERFS_I(inode)->i_xattr_sem);
|
2009-03-31 02:02:35 +08:00
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
isize = i_size_read(d_inode(dentry));
|
2005-07-13 11:21:28 +08:00
|
|
|
|
|
|
|
/* Just return the size needed */
|
|
|
|
if (buffer == NULL) {
|
|
|
|
err = isize - sizeof(struct reiserfs_xattr_header);
|
2009-03-31 02:02:36 +08:00
|
|
|
goto out_unlock;
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (buffer_size < isize - sizeof(struct reiserfs_xattr_header)) {
|
|
|
|
err = -ERANGE;
|
2009-03-31 02:02:36 +08:00
|
|
|
goto out_unlock;
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (file_pos < isize) {
|
|
|
|
size_t chunk;
|
|
|
|
char *data;
|
|
|
|
size_t skip = 0;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
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
|
|
|
if (isize - file_pos > PAGE_SIZE)
|
|
|
|
chunk = PAGE_SIZE;
|
2005-07-13 11:21:28 +08:00
|
|
|
else
|
|
|
|
chunk = isize - file_pos;
|
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
page = reiserfs_get_page(d_inode(dentry), file_pos);
|
2005-07-13 11:21:28 +08:00
|
|
|
if (IS_ERR(page)) {
|
|
|
|
err = PTR_ERR(page);
|
2009-03-31 02:02:36 +08:00
|
|
|
goto out_unlock;
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
lock_page(page);
|
|
|
|
data = page_address(page);
|
|
|
|
if (file_pos == 0) {
|
|
|
|
struct reiserfs_xattr_header *rxh =
|
|
|
|
(struct reiserfs_xattr_header *)data;
|
|
|
|
skip = file_pos = sizeof(struct reiserfs_xattr_header);
|
|
|
|
chunk -= skip;
|
|
|
|
/* Magic doesn't match up.. */
|
|
|
|
if (rxh->h_magic != cpu_to_le32(REISERFS_XATTR_MAGIC)) {
|
|
|
|
unlock_page(page);
|
|
|
|
reiserfs_put_page(page);
|
2009-03-31 02:02:33 +08:00
|
|
|
reiserfs_warning(inode->i_sb, "jdm-20001",
|
2005-07-13 11:21:28 +08:00
|
|
|
"Invalid magic for xattr (%s) "
|
|
|
|
"associated with %k", name,
|
|
|
|
INODE_PKEY(inode));
|
|
|
|
err = -EIO;
|
2009-03-31 02:02:36 +08:00
|
|
|
goto out_unlock;
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
hash = le32_to_cpu(rxh->h_hash);
|
|
|
|
}
|
|
|
|
memcpy(buffer + buffer_pos, data + skip, chunk);
|
|
|
|
unlock_page(page);
|
|
|
|
reiserfs_put_page(page);
|
|
|
|
file_pos += chunk;
|
|
|
|
buffer_pos += chunk;
|
|
|
|
skip = 0;
|
|
|
|
}
|
|
|
|
err = isize - sizeof(struct reiserfs_xattr_header);
|
|
|
|
|
|
|
|
if (xattr_hash(buffer, isize - sizeof(struct reiserfs_xattr_header)) !=
|
|
|
|
hash) {
|
2009-03-31 02:02:33 +08:00
|
|
|
reiserfs_warning(inode->i_sb, "jdm-20002",
|
2005-07-13 11:21:28 +08:00
|
|
|
"Invalid hash for xattr (%s) associated "
|
|
|
|
"with %k", name, INODE_PKEY(inode));
|
|
|
|
err = -EIO;
|
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:36 +08:00
|
|
|
out_unlock:
|
|
|
|
up_read(&REISERFS_I(inode)->i_xattr_sem);
|
2008-02-16 06:37:22 +08:00
|
|
|
dput(dentry);
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-03-31 02:02:33 +08:00
|
|
|
out:
|
2005-07-13 11:21:28 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:38 +08:00
|
|
|
/*
|
|
|
|
* In order to implement different sets of xattr operations for each xattr
|
|
|
|
* prefix with the generic xattr API, a filesystem should create a
|
|
|
|
* null-terminated array of struct xattr_handler (one for each prefix) and
|
|
|
|
* hang a pointer to it off of the s_xattr field of the superblock.
|
|
|
|
*
|
|
|
|
* The generic_fooxattr() functions will use this list to dispatch xattr
|
|
|
|
* operations to the correct xattr_handler.
|
|
|
|
*/
|
|
|
|
#define for_each_xattr_handler(handlers, handler) \
|
|
|
|
for ((handler) = *(handlers)++; \
|
|
|
|
(handler) != NULL; \
|
|
|
|
(handler) = *(handlers)++)
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2023-02-01 21:14:57 +08:00
|
|
|
static inline bool reiserfs_posix_acl_list(const char *name,
|
|
|
|
struct dentry *dentry)
|
|
|
|
{
|
|
|
|
return (posix_acl_type(name) >= 0) &&
|
|
|
|
IS_POSIXACL(d_backing_inode(dentry));
|
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:38 +08:00
|
|
|
/* This is the implementation for the xattr plugin infrastructure */
|
2023-02-01 21:14:57 +08:00
|
|
|
static inline bool reiserfs_xattr_list(const struct xattr_handler **handlers,
|
|
|
|
const char *name, struct dentry *dentry)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2023-02-01 21:14:57 +08:00
|
|
|
if (handlers) {
|
|
|
|
const struct xattr_handler *xah = NULL;
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2023-02-01 21:14:57 +08:00
|
|
|
for_each_xattr_handler(handlers, xah) {
|
|
|
|
const char *prefix = xattr_prefix(xah);
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2023-02-01 21:14:57 +08:00
|
|
|
if (strncmp(prefix, name, strlen(prefix)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!xattr_handler_can_list(xah, dentry))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
|
2023-02-01 21:14:57 +08:00
|
|
|
return reiserfs_posix_acl_list(name, dentry);
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-31 02:02:38 +08:00
|
|
|
struct listxattr_buf {
|
2013-05-18 10:42:17 +08:00
|
|
|
struct dir_context ctx;
|
2009-03-31 02:02:38 +08:00
|
|
|
size_t size;
|
|
|
|
size_t pos;
|
|
|
|
char *buf;
|
2009-11-13 17:52:56 +08:00
|
|
|
struct dentry *dentry;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2022-08-16 23:57:56 +08:00
|
|
|
static bool listxattr_filler(struct dir_context *ctx, const char *name,
|
2014-10-31 00:37:34 +08:00
|
|
|
int namelen, loff_t offset, u64 ino,
|
|
|
|
unsigned int d_type)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-10-31 00:37:34 +08:00
|
|
|
struct listxattr_buf *b =
|
|
|
|
container_of(ctx, struct listxattr_buf, ctx);
|
2009-03-31 02:02:38 +08:00
|
|
|
size_t size;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2009-03-31 02:02:38 +08:00
|
|
|
if (name[0] != '.' ||
|
|
|
|
(namelen != 1 && (name[1] != '.' || namelen != 2))) {
|
2023-02-01 21:14:57 +08:00
|
|
|
if (!reiserfs_xattr_list(b->dentry->d_sb->s_xattr, name,
|
|
|
|
b->dentry))
|
2022-08-16 23:57:56 +08:00
|
|
|
return true;
|
2015-12-02 21:44:43 +08:00
|
|
|
size = namelen + 1;
|
2009-03-31 02:02:38 +08:00
|
|
|
if (b->buf) {
|
2018-08-22 12:59:37 +08:00
|
|
|
if (b->pos + size > b->size) {
|
|
|
|
b->pos = -ERANGE;
|
2022-08-16 23:57:56 +08:00
|
|
|
return false;
|
2018-08-22 12:59:37 +08:00
|
|
|
}
|
2015-12-02 21:44:43 +08:00
|
|
|
memcpy(b->buf + b->pos, name, namelen);
|
|
|
|
b->buf[b->pos + namelen] = 0;
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
2009-03-31 02:02:38 +08:00
|
|
|
b->pos += size;
|
|
|
|
}
|
2022-08-16 23:57:56 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Inode operation listxattr()
|
|
|
|
*
|
2009-03-31 02:02:38 +08:00
|
|
|
* We totally ignore the generic listxattr here because it would be stupid
|
|
|
|
* not to. Since the xattrs are organized in a directory, we can just
|
|
|
|
* readdir to find them.
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2005-07-13 11:21:28 +08:00
|
|
|
ssize_t reiserfs_listxattr(struct dentry * dentry, char *buffer, size_t size)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-13 11:21:28 +08:00
|
|
|
struct dentry *dir;
|
|
|
|
int err = 0;
|
2009-03-31 02:02:38 +08:00
|
|
|
struct listxattr_buf buf = {
|
2013-05-18 10:42:17 +08:00
|
|
|
.ctx.actor = listxattr_filler,
|
2009-11-13 17:52:56 +08:00
|
|
|
.dentry = dentry,
|
2009-03-31 02:02:38 +08:00
|
|
|
.buf = buffer,
|
|
|
|
.size = buffer ? size : 0,
|
|
|
|
};
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
if (d_really_is_negative(dentry))
|
2005-07-13 11:21:28 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2019-10-24 22:31:27 +08:00
|
|
|
if (get_inode_sd_version(d_inode(dentry)) == STAT_DATA_V1)
|
2005-07-13 11:21:28 +08:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
dir = open_xa_dir(d_inode(dentry), XATTR_REPLACE);
|
2005-07-13 11:21:28 +08:00
|
|
|
if (IS_ERR(dir)) {
|
|
|
|
err = PTR_ERR(dir);
|
|
|
|
if (err == -ENODATA)
|
2009-03-31 02:02:38 +08:00
|
|
|
err = 0; /* Not an error if there aren't any xattrs */
|
2005-07-13 11:21:28 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock_nested(d_inode(dir), I_MUTEX_XATTR);
|
2015-03-18 06:25:59 +08:00
|
|
|
err = reiserfs_readdir_inode(d_inode(dir), &buf.ctx);
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(dir));
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-03-31 02:02:38 +08:00
|
|
|
if (!err)
|
|
|
|
err = buf.pos;
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2008-02-16 06:37:22 +08:00
|
|
|
dput(dir);
|
2009-03-31 02:02:36 +08:00
|
|
|
out:
|
2005-07-13 11:21:28 +08:00
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-31 02:02:33 +08:00
|
|
|
static int create_privroot(struct dentry *dentry)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-03-31 02:02:33 +08:00
|
|
|
int err;
|
2015-03-18 06:25:59 +08:00
|
|
|
struct inode *inode = d_inode(dentry->d_parent);
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2016-01-23 04:40:57 +08:00
|
|
|
WARN_ON_ONCE(!inode_is_locked(inode));
|
2009-05-02 00:11:12 +08:00
|
|
|
|
2009-03-31 02:02:34 +08:00
|
|
|
err = xattr_mkdir(inode, dentry, 0700);
|
2015-03-18 06:25:59 +08:00
|
|
|
if (err || d_really_is_negative(dentry)) {
|
2009-05-03 18:00:05 +08:00
|
|
|
reiserfs_warning(dentry->d_sb, "jdm-20006",
|
|
|
|
"xattrs/ACLs enabled and couldn't "
|
|
|
|
"find/create .reiserfs_priv. "
|
|
|
|
"Failing mount.");
|
|
|
|
return -EOPNOTSUPP;
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
|
2023-02-01 21:14:59 +08:00
|
|
|
reiserfs_init_priv_inode(d_inode(dentry));
|
2009-05-03 18:00:05 +08:00
|
|
|
reiserfs_info(dentry->d_sb, "Created %s - reserved for xattr "
|
|
|
|
"storage.\n", PRIVROOT_NAME);
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-05-03 18:00:05 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-05-17 13:02:01 +08:00
|
|
|
#else
|
|
|
|
int __init reiserfs_xattr_register_handlers(void) { return 0; }
|
|
|
|
void reiserfs_xattr_unregister_handlers(void) {}
|
|
|
|
static int create_privroot(struct dentry *dentry) { return 0; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Actual operations that are exported to VFS-land */
|
2019-10-24 22:31:27 +08:00
|
|
|
const struct xattr_handler *reiserfs_xattr_handlers[] = {
|
2009-05-17 13:02:01 +08:00
|
|
|
#ifdef CONFIG_REISERFS_FS_XATTR
|
|
|
|
&reiserfs_xattr_user_handler,
|
|
|
|
&reiserfs_xattr_trusted_handler,
|
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_REISERFS_FS_SECURITY
|
|
|
|
&reiserfs_xattr_security_handler,
|
|
|
|
#endif
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-03-31 02:02:33 +08:00
|
|
|
static int xattr_mount_check(struct super_block *s)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2014-04-23 22:00:36 +08:00
|
|
|
/*
|
|
|
|
* We need generation numbers to ensure that the oid mapping is correct
|
|
|
|
* v3.5 filesystems don't have them.
|
|
|
|
*/
|
2009-03-31 02:02:38 +08:00
|
|
|
if (old_format_only(s)) {
|
|
|
|
if (reiserfs_xattrs_optional(s)) {
|
2014-04-23 22:00:36 +08:00
|
|
|
/*
|
|
|
|
* Old format filesystem, but optional xattrs have
|
|
|
|
* been enabled. Error out.
|
|
|
|
*/
|
2009-03-31 02:02:38 +08:00
|
|
|
reiserfs_warning(s, "jdm-2005",
|
|
|
|
"xattrs/ACLs not supported "
|
|
|
|
"on pre-v3.6 format filesystems. "
|
|
|
|
"Failing mount.");
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
}
|
2009-03-31 02:02:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2023-01-13 19:49:22 +08:00
|
|
|
int reiserfs_permission(struct mnt_idmap *idmap, struct inode *inode,
|
2021-01-21 21:19:43 +08:00
|
|
|
int mask)
|
2009-05-17 13:02:03 +08:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We don't do permission checks on the internal objects.
|
|
|
|
* Permissions are determined by the "owning" object.
|
|
|
|
*/
|
|
|
|
if (IS_PRIVATE(inode))
|
|
|
|
return 0;
|
|
|
|
|
2023-01-13 19:49:22 +08:00
|
|
|
return generic_permission(&nop_mnt_idmap, inode, mask);
|
2009-05-17 13:02:03 +08:00
|
|
|
}
|
|
|
|
|
2012-06-11 04:03:43 +08:00
|
|
|
static int xattr_hide_revalidate(struct dentry *dentry, unsigned int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2010-04-24 01:17:37 +08:00
|
|
|
return -EPERM;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-02-20 13:55:13 +08:00
|
|
|
static const struct dentry_operations xattr_lookup_poison_ops = {
|
2010-04-24 01:17:37 +08:00
|
|
|
.d_revalidate = xattr_hide_revalidate,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2009-05-03 18:00:05 +08:00
|
|
|
int reiserfs_lookup_privroot(struct super_block *s)
|
|
|
|
{
|
|
|
|
struct dentry *dentry;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
/* If we don't have the privroot located yet - go find it */
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock(d_inode(s->s_root));
|
2009-05-03 18:00:05 +08:00
|
|
|
dentry = lookup_one_len(PRIVROOT_NAME, s->s_root,
|
|
|
|
strlen(PRIVROOT_NAME));
|
|
|
|
if (!IS_ERR(dentry)) {
|
|
|
|
REISERFS_SB(s)->priv_root = dentry;
|
2011-01-07 14:49:55 +08:00
|
|
|
d_set_d_op(dentry, &xattr_lookup_poison_ops);
|
2023-02-01 21:14:59 +08:00
|
|
|
if (d_really_is_positive(dentry))
|
|
|
|
reiserfs_init_priv_inode(d_inode(dentry));
|
2009-05-03 18:00:05 +08:00
|
|
|
} else
|
|
|
|
err = PTR_ERR(dentry);
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(s->s_root));
|
2009-05-03 18:00:05 +08:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2014-04-23 22:00:36 +08:00
|
|
|
/*
|
|
|
|
* We need to take a copy of the mount flags since things like
|
2017-11-28 05:05:09 +08:00
|
|
|
* SB_RDONLY don't get set until *after* we're called.
|
2014-04-23 22:00:36 +08:00
|
|
|
* mount_flags != mount_options
|
|
|
|
*/
|
2005-07-13 11:21:28 +08:00
|
|
|
int reiserfs_xattr_init(struct super_block *s, int mount_flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-07-13 11:21:28 +08:00
|
|
|
int err = 0;
|
2009-05-06 03:30:15 +08:00
|
|
|
struct dentry *privroot = REISERFS_SB(s)->priv_root;
|
2005-07-13 11:21:28 +08:00
|
|
|
|
2009-03-31 02:02:33 +08:00
|
|
|
err = xattr_mount_check(s);
|
|
|
|
if (err)
|
2005-07-13 11:21:28 +08:00
|
|
|
goto error;
|
|
|
|
|
2017-11-28 05:05:09 +08:00
|
|
|
if (d_really_is_negative(privroot) && !(mount_flags & SB_RDONLY)) {
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock(d_inode(s->s_root));
|
2009-05-03 18:00:05 +08:00
|
|
|
err = create_privroot(REISERFS_SB(s)->priv_root);
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(s->s_root));
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
2009-05-06 03:30:15 +08:00
|
|
|
|
2015-03-18 06:25:59 +08:00
|
|
|
if (d_really_is_positive(privroot)) {
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_lock(d_inode(privroot));
|
2009-05-06 03:30:15 +08:00
|
|
|
if (!REISERFS_SB(s)->xattr_root) {
|
|
|
|
struct dentry *dentry;
|
2014-08-09 05:21:14 +08:00
|
|
|
|
2009-05-06 03:30:15 +08:00
|
|
|
dentry = lookup_one_len(XAROOT_NAME, privroot,
|
|
|
|
strlen(XAROOT_NAME));
|
|
|
|
if (!IS_ERR(dentry))
|
|
|
|
REISERFS_SB(s)->xattr_root = dentry;
|
|
|
|
else
|
|
|
|
err = PTR_ERR(dentry);
|
|
|
|
}
|
2016-01-23 04:40:57 +08:00
|
|
|
inode_unlock(d_inode(privroot));
|
2009-05-06 03:30:15 +08:00
|
|
|
}
|
2009-03-31 02:02:38 +08:00
|
|
|
|
2009-03-31 02:02:33 +08:00
|
|
|
error:
|
2005-07-13 11:21:28 +08:00
|
|
|
if (err) {
|
2014-04-23 22:00:42 +08:00
|
|
|
clear_bit(REISERFS_XATTRS_USER, &REISERFS_SB(s)->s_mount_opt);
|
|
|
|
clear_bit(REISERFS_POSIXACL, &REISERFS_SB(s)->s_mount_opt);
|
2005-07-13 11:21:28 +08:00
|
|
|
}
|
|
|
|
|
2017-11-28 05:05:09 +08:00
|
|
|
/* The super_block SB_POSIXACL must mirror the (no)acl mount option. */
|
2005-07-13 11:21:28 +08:00
|
|
|
if (reiserfs_posixacl(s))
|
2017-11-28 05:05:09 +08:00
|
|
|
s->s_flags |= SB_POSIXACL;
|
2009-05-06 03:30:15 +08:00
|
|
|
else
|
2017-11-28 05:05:09 +08:00
|
|
|
s->s_flags &= ~SB_POSIXACL;
|
2005-07-13 11:21:28 +08:00
|
|
|
|
|
|
|
return err;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|