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
|
2010-04-07 06:14:15 +08:00
|
|
|
#include <linux/ceph/ceph_debug.h>
|
2014-09-16 19:15:28 +08:00
|
|
|
#include <linux/ceph/pagelist.h>
|
2010-04-07 06:14:15 +08:00
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
#include "super.h"
|
2010-04-07 06:14:15 +08:00
|
|
|
#include "mds_client.h"
|
|
|
|
|
|
|
|
#include <linux/ceph/decode.h>
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
#include <linux/xattr.h>
|
2019-05-26 16:27:56 +08:00
|
|
|
#include <linux/security.h>
|
ceph: Fix up after semantic merge conflict
The previous ceph-client merge resulted in ceph not even building,
because there was a merge conflict that wasn't visible as an actual data
conflict: commit 7221fe4c2ed7 ("ceph: add acl for cephfs") added support
for POSIX ACL's into Ceph, but unluckily we also had the VFS tree change
a lot of the POSIX ACL helper functions to be much more helpful to
filesystems (see for example commits 2aeccbe957d0 "fs: add generic
xattr_acl handlers", 5bf3258fd2ac "fs: make posix_acl_chmod more useful"
and 37bc15392a23 "fs: make posix_acl_create more useful")
The reason this conflict wasn't obvious was many-fold: because it was a
semantic conflict rather than a data conflict, it wasn't visible in the
git merge as a conflict. And because the VFS tree hadn't been in
linux-next, people hadn't become aware of it that way. And because I
was at jury duty this morning, I was using my laptop and as a result not
doing constant "allmodconfig" builds.
Anyway, this fixes the build and generally removes a fair chunk of the
Ceph POSIX ACL support code, since the improved helpers seem to match
really well for Ceph too. But I don't actually have any way to *test*
the end result, and I was really hoping for some ACK's for this. Oh,
well.
Not compiling certainly doesn't make things easier to test, so I'm
committing this without the acks after having waited for four hours...
Plus it's what I would have done for the merge had I noticed the
semantic conflict..
Reported-by: Dave Jones <davej@redhat.com>
Cc: Sage Weil <sage@inktank.com>
Cc: Guangliang Zhao <lucienchao@gmail.com>
Cc: Li Wang <li.wang@ubuntykylin.com>
Cc: Christoph Hellwig <hch@infradead.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2014-01-29 10:06:18 +08:00
|
|
|
#include <linux/posix_acl_xattr.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>
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2012-01-24 05:49:28 +08:00
|
|
|
#define XATTR_CEPH_PREFIX "ceph."
|
|
|
|
#define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
|
|
|
|
|
2014-02-11 13:04:19 +08:00
|
|
|
static int __remove_xattr(struct ceph_inode_info *ci,
|
|
|
|
struct ceph_inode_xattr *xattr);
|
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
static bool ceph_is_valid_xattr(const char *name)
|
|
|
|
{
|
2019-08-06 22:55:41 +08:00
|
|
|
return !strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) ||
|
|
|
|
!strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN) ||
|
2009-10-07 02:31:08 +08:00
|
|
|
!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) ||
|
|
|
|
!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These define virtual xattrs exposing the recursive directory
|
|
|
|
* statistics and layout metadata.
|
|
|
|
*/
|
2012-01-24 05:49:28 +08:00
|
|
|
struct ceph_vxattr {
|
2009-10-07 02:31:08 +08:00
|
|
|
char *name;
|
2012-01-24 05:49:28 +08:00
|
|
|
size_t name_size; /* strlen(name) + 1 (for '\0') */
|
2019-06-24 19:39:18 +08:00
|
|
|
ssize_t (*getxattr_cb)(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size);
|
2013-01-21 13:59:29 +08:00
|
|
|
bool (*exists_cb)(struct ceph_inode_info *ci);
|
2018-04-25 17:14:05 +08:00
|
|
|
unsigned int flags;
|
2009-10-07 02:31:08 +08:00
|
|
|
};
|
|
|
|
|
2018-04-25 17:14:05 +08:00
|
|
|
#define VXATTR_FLAG_READONLY (1<<0)
|
|
|
|
#define VXATTR_FLAG_HIDDEN (1<<1)
|
2018-04-25 17:30:23 +08:00
|
|
|
#define VXATTR_FLAG_RSTAT (1<<2)
|
2020-11-04 03:00:26 +08:00
|
|
|
#define VXATTR_FLAG_DIRSTAT (1<<3)
|
2018-04-25 17:14:05 +08:00
|
|
|
|
2013-01-20 08:46:32 +08:00
|
|
|
/* layouts */
|
|
|
|
|
|
|
|
static bool ceph_vxattrcb_layout_exists(struct ceph_inode_info *ci)
|
|
|
|
{
|
2016-03-07 09:35:06 +08:00
|
|
|
struct ceph_file_layout *fl = &ci->i_layout;
|
|
|
|
return (fl->stripe_unit > 0 || fl->stripe_count > 0 ||
|
|
|
|
fl->object_size > 0 || fl->pool_id >= 0 ||
|
|
|
|
rcu_dereference_raw(fl->pool_ns) != NULL);
|
2013-01-20 08:46:32 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_layout(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2013-01-20 08:46:32 +08:00
|
|
|
{
|
2023-06-12 10:50:38 +08:00
|
|
|
struct ceph_fs_client *fsc = ceph_sb_to_fs_client(ci->netfs.inode.i_sb);
|
2023-06-12 09:04:07 +08:00
|
|
|
struct ceph_client *cl = fsc->client;
|
2013-01-20 08:46:32 +08:00
|
|
|
struct ceph_osd_client *osdc = &fsc->client->osdc;
|
2016-03-07 09:35:06 +08:00
|
|
|
struct ceph_string *pool_ns;
|
2016-02-03 21:24:49 +08:00
|
|
|
s64 pool = ci->i_layout.pool_id;
|
2013-01-20 08:46:32 +08:00
|
|
|
const char *pool_name;
|
2016-03-07 09:35:06 +08:00
|
|
|
const char *ns_field = " pool_namespace=";
|
2014-03-24 13:00:54 +08:00
|
|
|
char buf[128];
|
2016-03-07 09:35:06 +08:00
|
|
|
size_t len, total_len = 0;
|
2019-06-14 03:17:00 +08:00
|
|
|
ssize_t ret;
|
2016-03-07 09:35:06 +08:00
|
|
|
|
|
|
|
pool_ns = ceph_try_get_string(ci->i_layout.pool_ns);
|
2013-01-20 08:46:32 +08:00
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "%p\n", &ci->netfs.inode);
|
2016-04-28 22:07:26 +08:00
|
|
|
down_read(&osdc->lock);
|
2013-01-20 08:46:32 +08:00
|
|
|
pool_name = ceph_pg_pool_name_by_id(osdc->osdmap, pool);
|
2014-03-24 13:00:54 +08:00
|
|
|
if (pool_name) {
|
2016-03-07 09:35:06 +08:00
|
|
|
len = snprintf(buf, sizeof(buf),
|
2016-02-03 21:24:49 +08:00
|
|
|
"stripe_unit=%u stripe_count=%u object_size=%u pool=",
|
|
|
|
ci->i_layout.stripe_unit, ci->i_layout.stripe_count,
|
|
|
|
ci->i_layout.object_size);
|
2016-03-07 09:35:06 +08:00
|
|
|
total_len = len + strlen(pool_name);
|
2014-03-24 13:00:54 +08:00
|
|
|
} else {
|
2016-03-07 09:35:06 +08:00
|
|
|
len = snprintf(buf, sizeof(buf),
|
2016-02-03 21:24:49 +08:00
|
|
|
"stripe_unit=%u stripe_count=%u object_size=%u pool=%lld",
|
|
|
|
ci->i_layout.stripe_unit, ci->i_layout.stripe_count,
|
2019-06-24 19:39:18 +08:00
|
|
|
ci->i_layout.object_size, pool);
|
2016-03-07 09:35:06 +08:00
|
|
|
total_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool_ns)
|
|
|
|
total_len += strlen(ns_field) + pool_ns->len;
|
|
|
|
|
2019-06-14 03:17:00 +08:00
|
|
|
ret = total_len;
|
|
|
|
if (size >= total_len) {
|
2016-03-07 09:35:06 +08:00
|
|
|
memcpy(val, buf, len);
|
|
|
|
ret = len;
|
|
|
|
if (pool_name) {
|
|
|
|
len = strlen(pool_name);
|
|
|
|
memcpy(val + ret, pool_name, len);
|
|
|
|
ret += len;
|
|
|
|
}
|
|
|
|
if (pool_ns) {
|
|
|
|
len = strlen(ns_field);
|
|
|
|
memcpy(val + ret, ns_field, len);
|
|
|
|
ret += len;
|
|
|
|
memcpy(val + ret, pool_ns->str, pool_ns->len);
|
|
|
|
ret += pool_ns->len;
|
2014-03-24 13:00:54 +08:00
|
|
|
}
|
|
|
|
}
|
2016-04-28 22:07:26 +08:00
|
|
|
up_read(&osdc->lock);
|
2016-03-07 09:35:06 +08:00
|
|
|
ceph_put_string(pool_ns);
|
2013-01-20 08:46:32 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-24 19:32:21 +08:00
|
|
|
/*
|
|
|
|
* The convention with strings in xattrs is that they should not be NULL
|
|
|
|
* terminated, since we're returning the length with them. snprintf always
|
|
|
|
* NULL terminates however, so call it on a temporary buffer and then memcpy
|
|
|
|
* the result into place.
|
|
|
|
*/
|
2020-09-18 00:45:44 +08:00
|
|
|
static __printf(3, 4)
|
|
|
|
int ceph_fmt_xattr(char *val, size_t size, const char *fmt, ...)
|
2019-06-24 19:32:21 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
va_list args;
|
|
|
|
char buf[96]; /* NB: reevaluate size if new vxattrs are added */
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
ret = vsnprintf(buf, size ? sizeof(buf) : 0, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (size && ret + 1 > sizeof(buf)) {
|
|
|
|
WARN_ONCE(true, "Returned length too big (%d)", ret);
|
|
|
|
return -E2BIG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret <= size)
|
|
|
|
memcpy(val, buf, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_layout_stripe_unit(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
2013-01-21 14:08:33 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%u", ci->i_layout.stripe_unit);
|
2013-01-21 14:08:33 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_layout_stripe_count(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
2013-01-21 14:08:33 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%u", ci->i_layout.stripe_count);
|
2013-01-21 14:08:33 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_layout_object_size(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
2013-01-21 14:08:33 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%u", ci->i_layout.object_size);
|
2013-01-21 14:08:33 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_layout_pool(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
2013-01-21 14:08:33 +08:00
|
|
|
{
|
2019-06-24 19:39:18 +08:00
|
|
|
ssize_t ret;
|
2023-06-12 10:50:38 +08:00
|
|
|
struct ceph_fs_client *fsc = ceph_sb_to_fs_client(ci->netfs.inode.i_sb);
|
2013-01-21 14:08:33 +08:00
|
|
|
struct ceph_osd_client *osdc = &fsc->client->osdc;
|
2016-02-03 21:24:49 +08:00
|
|
|
s64 pool = ci->i_layout.pool_id;
|
2013-01-21 14:08:33 +08:00
|
|
|
const char *pool_name;
|
|
|
|
|
2016-04-28 22:07:26 +08:00
|
|
|
down_read(&osdc->lock);
|
2013-01-21 14:08:33 +08:00
|
|
|
pool_name = ceph_pg_pool_name_by_id(osdc->osdmap, pool);
|
2019-06-24 19:32:21 +08:00
|
|
|
if (pool_name) {
|
|
|
|
ret = strlen(pool_name);
|
|
|
|
if (ret <= size)
|
|
|
|
memcpy(val, pool_name, ret);
|
|
|
|
} else {
|
|
|
|
ret = ceph_fmt_xattr(val, size, "%lld", pool);
|
|
|
|
}
|
2016-04-28 22:07:26 +08:00
|
|
|
up_read(&osdc->lock);
|
2013-01-21 14:08:33 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_layout_pool_namespace(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
2016-03-07 09:35:06 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
ssize_t ret = 0;
|
2016-03-07 09:35:06 +08:00
|
|
|
struct ceph_string *ns = ceph_try_get_string(ci->i_layout.pool_ns);
|
2019-06-24 19:32:21 +08:00
|
|
|
|
2016-03-07 09:35:06 +08:00
|
|
|
if (ns) {
|
2019-06-24 19:32:21 +08:00
|
|
|
ret = ns->len;
|
|
|
|
if (ret <= size)
|
|
|
|
memcpy(val, ns->str, ret);
|
2016-03-07 09:35:06 +08:00
|
|
|
ceph_put_string(ns);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
/* directories */
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_dir_entries(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%lld", ci->i_files + ci->i_subdirs);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_dir_files(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%lld", ci->i_files);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_dir_subdirs(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%lld", ci->i_subdirs);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_dir_rentries(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%lld",
|
|
|
|
ci->i_rfiles + ci->i_rsubdirs);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_dir_rfiles(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%lld", ci->i_rfiles);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_dir_rsubdirs(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%lld", ci->i_rsubdirs);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2020-08-28 09:28:44 +08:00
|
|
|
static ssize_t ceph_vxattrcb_dir_rsnaps(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
return ceph_fmt_xattr(val, size, "%lld", ci->i_rsnaps);
|
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_dir_rbytes(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%lld", ci->i_rbytes);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_dir_rctime(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%lld.%09ld", ci->i_rctime.tv_sec,
|
|
|
|
ci->i_rctime.tv_nsec);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2019-01-09 11:07:02 +08:00
|
|
|
/* dir pin */
|
|
|
|
static bool ceph_vxattrcb_dir_pin_exists(struct ceph_inode_info *ci)
|
|
|
|
{
|
|
|
|
return ci->i_dir_pin != -ENODATA;
|
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_dir_pin(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2019-01-09 11:07:02 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%d", (int)ci->i_dir_pin);
|
2019-01-09 11:07:02 +08:00
|
|
|
}
|
2018-01-05 18:47:18 +08:00
|
|
|
|
2019-01-09 11:07:02 +08:00
|
|
|
/* quotas */
|
2018-01-05 18:47:18 +08:00
|
|
|
static bool ceph_vxattrcb_quota_exists(struct ceph_inode_info *ci)
|
|
|
|
{
|
2018-04-08 09:54:39 +08:00
|
|
|
bool ret = false;
|
|
|
|
spin_lock(&ci->i_ceph_lock);
|
|
|
|
if ((ci->i_max_files || ci->i_max_bytes) &&
|
|
|
|
ci->i_vino.snap == CEPH_NOSNAP &&
|
|
|
|
ci->i_snap_realm &&
|
|
|
|
ci->i_snap_realm->ino == ci->i_vino.ino)
|
|
|
|
ret = true;
|
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
|
|
|
return ret;
|
2018-01-05 18:47:18 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_quota(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2018-01-05 18:47:18 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "max_bytes=%llu max_files=%llu",
|
|
|
|
ci->i_max_bytes, ci->i_max_files);
|
2018-01-05 18:47:18 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_quota_max_bytes(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
2018-01-05 18:47:18 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%llu", ci->i_max_bytes);
|
2018-01-05 18:47:18 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_quota_max_files(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
2018-01-05 18:47:18 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%llu", ci->i_max_files);
|
2018-01-05 18:47:18 +08:00
|
|
|
}
|
2013-01-20 08:46:32 +08:00
|
|
|
|
2019-04-18 20:15:47 +08:00
|
|
|
/* snapshots */
|
|
|
|
static bool ceph_vxattrcb_snap_btime_exists(struct ceph_inode_info *ci)
|
|
|
|
{
|
|
|
|
return (ci->i_snap_btime.tv_sec != 0 || ci->i_snap_btime.tv_nsec != 0);
|
|
|
|
}
|
|
|
|
|
2019-06-24 19:39:18 +08:00
|
|
|
static ssize_t ceph_vxattrcb_snap_btime(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
2019-04-18 20:15:47 +08:00
|
|
|
{
|
2019-06-24 19:32:21 +08:00
|
|
|
return ceph_fmt_xattr(val, size, "%lld.%09ld", ci->i_snap_btime.tv_sec,
|
|
|
|
ci->i_snap_btime.tv_nsec);
|
2019-04-18 20:15:47 +08:00
|
|
|
}
|
|
|
|
|
2020-11-11 09:29:40 +08:00
|
|
|
static ssize_t ceph_vxattrcb_cluster_fsid(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
|
|
|
{
|
2023-06-12 10:50:38 +08:00
|
|
|
struct ceph_fs_client *fsc = ceph_sb_to_fs_client(ci->netfs.inode.i_sb);
|
2020-11-11 09:29:40 +08:00
|
|
|
|
|
|
|
return ceph_fmt_xattr(val, size, "%pU", &fsc->client->fsid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ceph_vxattrcb_client_id(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
|
|
|
{
|
2023-06-12 10:50:38 +08:00
|
|
|
struct ceph_fs_client *fsc = ceph_sb_to_fs_client(ci->netfs.inode.i_sb);
|
2020-11-11 09:29:40 +08:00
|
|
|
|
|
|
|
return ceph_fmt_xattr(val, size, "client%lld",
|
|
|
|
ceph_client_gid(fsc->client));
|
|
|
|
}
|
|
|
|
|
2020-11-24 01:38:46 +08:00
|
|
|
static ssize_t ceph_vxattrcb_caps(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
int issued;
|
|
|
|
|
|
|
|
spin_lock(&ci->i_ceph_lock);
|
|
|
|
issued = __ceph_caps_issued(ci, NULL);
|
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
|
|
|
|
|
|
|
return ceph_fmt_xattr(val, size, "%s/0x%x",
|
|
|
|
ceph_cap_string(issued), issued);
|
|
|
|
}
|
|
|
|
|
2021-07-26 19:07:50 +08:00
|
|
|
static ssize_t ceph_vxattrcb_auth_mds(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
spin_lock(&ci->i_ceph_lock);
|
|
|
|
ret = ceph_fmt_xattr(val, size, "%d",
|
|
|
|
ci->i_auth_cap ? ci->i_auth_cap->session->s_mds : -1);
|
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-07-28 21:58:43 +08:00
|
|
|
#if IS_ENABLED(CONFIG_FS_ENCRYPTION)
|
|
|
|
static bool ceph_vxattrcb_fscrypt_auth_exists(struct ceph_inode_info *ci)
|
|
|
|
{
|
|
|
|
return ci->fscrypt_auth_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t ceph_vxattrcb_fscrypt_auth(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
|
|
|
{
|
|
|
|
if (size) {
|
|
|
|
if (size < ci->fscrypt_auth_len)
|
|
|
|
return -ERANGE;
|
|
|
|
memcpy(val, ci->fscrypt_auth, ci->fscrypt_auth_len);
|
|
|
|
}
|
|
|
|
return ci->fscrypt_auth_len;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FS_ENCRYPTION */
|
|
|
|
|
2012-01-24 05:49:28 +08:00
|
|
|
#define CEPH_XATTR_NAME(_type, _name) XATTR_CEPH_PREFIX #_type "." #_name
|
2013-01-21 14:08:33 +08:00
|
|
|
#define CEPH_XATTR_NAME2(_type, _name, _name2) \
|
|
|
|
XATTR_CEPH_PREFIX #_type "." #_name "." #_name2
|
2012-01-24 05:49:28 +08:00
|
|
|
|
2018-04-25 17:30:23 +08:00
|
|
|
#define XATTR_NAME_CEPH(_type, _name, _flags) \
|
2013-02-01 03:53:27 +08:00
|
|
|
{ \
|
|
|
|
.name = CEPH_XATTR_NAME(_type, _name), \
|
|
|
|
.name_size = sizeof (CEPH_XATTR_NAME(_type, _name)), \
|
|
|
|
.getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
|
2018-04-25 17:30:23 +08:00
|
|
|
.exists_cb = NULL, \
|
|
|
|
.flags = (VXATTR_FLAG_READONLY | _flags), \
|
2013-02-01 03:53:27 +08:00
|
|
|
}
|
2018-04-25 17:30:23 +08:00
|
|
|
#define XATTR_RSTAT_FIELD(_type, _name) \
|
|
|
|
XATTR_NAME_CEPH(_type, _name, VXATTR_FLAG_RSTAT)
|
2022-03-10 22:34:19 +08:00
|
|
|
#define XATTR_RSTAT_FIELD_UPDATABLE(_type, _name) \
|
|
|
|
{ \
|
|
|
|
.name = CEPH_XATTR_NAME(_type, _name), \
|
|
|
|
.name_size = sizeof (CEPH_XATTR_NAME(_type, _name)), \
|
|
|
|
.getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
|
|
|
|
.exists_cb = NULL, \
|
|
|
|
.flags = VXATTR_FLAG_RSTAT, \
|
|
|
|
}
|
2013-01-21 14:08:33 +08:00
|
|
|
#define XATTR_LAYOUT_FIELD(_type, _name, _field) \
|
|
|
|
{ \
|
|
|
|
.name = CEPH_XATTR_NAME2(_type, _name, _field), \
|
|
|
|
.name_size = sizeof (CEPH_XATTR_NAME2(_type, _name, _field)), \
|
|
|
|
.getxattr_cb = ceph_vxattrcb_ ## _name ## _ ## _field, \
|
|
|
|
.exists_cb = ceph_vxattrcb_layout_exists, \
|
2018-04-25 17:14:05 +08:00
|
|
|
.flags = VXATTR_FLAG_HIDDEN, \
|
2013-01-21 14:08:33 +08:00
|
|
|
}
|
2018-01-05 18:47:18 +08:00
|
|
|
#define XATTR_QUOTA_FIELD(_type, _name) \
|
|
|
|
{ \
|
|
|
|
.name = CEPH_XATTR_NAME(_type, _name), \
|
|
|
|
.name_size = sizeof(CEPH_XATTR_NAME(_type, _name)), \
|
|
|
|
.getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
|
|
|
|
.exists_cb = ceph_vxattrcb_quota_exists, \
|
2018-04-25 17:14:05 +08:00
|
|
|
.flags = VXATTR_FLAG_HIDDEN, \
|
2018-01-05 18:47:18 +08:00
|
|
|
}
|
2012-01-24 05:49:28 +08:00
|
|
|
|
2012-01-24 05:49:28 +08:00
|
|
|
static struct ceph_vxattr ceph_dir_vxattrs[] = {
|
2013-01-21 14:07:12 +08:00
|
|
|
{
|
|
|
|
.name = "ceph.dir.layout",
|
|
|
|
.name_size = sizeof("ceph.dir.layout"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_layout,
|
|
|
|
.exists_cb = ceph_vxattrcb_layout_exists,
|
2018-04-25 17:14:05 +08:00
|
|
|
.flags = VXATTR_FLAG_HIDDEN,
|
2013-01-21 14:07:12 +08:00
|
|
|
},
|
2013-01-21 14:08:33 +08:00
|
|
|
XATTR_LAYOUT_FIELD(dir, layout, stripe_unit),
|
|
|
|
XATTR_LAYOUT_FIELD(dir, layout, stripe_count),
|
|
|
|
XATTR_LAYOUT_FIELD(dir, layout, object_size),
|
|
|
|
XATTR_LAYOUT_FIELD(dir, layout, pool),
|
2016-03-07 09:35:06 +08:00
|
|
|
XATTR_LAYOUT_FIELD(dir, layout, pool_namespace),
|
2020-11-04 03:00:26 +08:00
|
|
|
XATTR_NAME_CEPH(dir, entries, VXATTR_FLAG_DIRSTAT),
|
|
|
|
XATTR_NAME_CEPH(dir, files, VXATTR_FLAG_DIRSTAT),
|
|
|
|
XATTR_NAME_CEPH(dir, subdirs, VXATTR_FLAG_DIRSTAT),
|
2018-04-25 17:30:23 +08:00
|
|
|
XATTR_RSTAT_FIELD(dir, rentries),
|
|
|
|
XATTR_RSTAT_FIELD(dir, rfiles),
|
|
|
|
XATTR_RSTAT_FIELD(dir, rsubdirs),
|
2020-08-28 09:28:44 +08:00
|
|
|
XATTR_RSTAT_FIELD(dir, rsnaps),
|
2018-04-25 17:30:23 +08:00
|
|
|
XATTR_RSTAT_FIELD(dir, rbytes),
|
2022-03-10 22:34:19 +08:00
|
|
|
XATTR_RSTAT_FIELD_UPDATABLE(dir, rctime),
|
2019-01-09 11:07:02 +08:00
|
|
|
{
|
|
|
|
.name = "ceph.dir.pin",
|
2019-04-18 20:15:45 +08:00
|
|
|
.name_size = sizeof("ceph.dir.pin"),
|
2019-01-09 11:07:02 +08:00
|
|
|
.getxattr_cb = ceph_vxattrcb_dir_pin,
|
|
|
|
.exists_cb = ceph_vxattrcb_dir_pin_exists,
|
|
|
|
.flags = VXATTR_FLAG_HIDDEN,
|
|
|
|
},
|
2018-01-05 18:47:18 +08:00
|
|
|
{
|
|
|
|
.name = "ceph.quota",
|
|
|
|
.name_size = sizeof("ceph.quota"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_quota,
|
|
|
|
.exists_cb = ceph_vxattrcb_quota_exists,
|
2018-04-25 17:14:05 +08:00
|
|
|
.flags = VXATTR_FLAG_HIDDEN,
|
2018-01-05 18:47:18 +08:00
|
|
|
},
|
|
|
|
XATTR_QUOTA_FIELD(quota, max_bytes),
|
|
|
|
XATTR_QUOTA_FIELD(quota, max_files),
|
2019-04-18 20:15:47 +08:00
|
|
|
{
|
|
|
|
.name = "ceph.snap.btime",
|
|
|
|
.name_size = sizeof("ceph.snap.btime"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_snap_btime,
|
|
|
|
.exists_cb = ceph_vxattrcb_snap_btime_exists,
|
|
|
|
.flags = VXATTR_FLAG_READONLY,
|
|
|
|
},
|
2020-11-24 01:38:46 +08:00
|
|
|
{
|
|
|
|
.name = "ceph.caps",
|
|
|
|
.name_size = sizeof("ceph.caps"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_caps,
|
|
|
|
.exists_cb = NULL,
|
|
|
|
.flags = VXATTR_FLAG_HIDDEN,
|
|
|
|
},
|
2013-02-20 02:25:56 +08:00
|
|
|
{ .name = NULL, 0 } /* Required table terminator */
|
2009-10-07 02:31:08 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* files */
|
|
|
|
|
2012-01-24 05:49:28 +08:00
|
|
|
static struct ceph_vxattr ceph_file_vxattrs[] = {
|
2013-01-20 08:46:32 +08:00
|
|
|
{
|
|
|
|
.name = "ceph.file.layout",
|
|
|
|
.name_size = sizeof("ceph.file.layout"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_layout,
|
|
|
|
.exists_cb = ceph_vxattrcb_layout_exists,
|
2018-04-25 17:14:05 +08:00
|
|
|
.flags = VXATTR_FLAG_HIDDEN,
|
2013-01-20 08:46:32 +08:00
|
|
|
},
|
2013-01-21 14:08:33 +08:00
|
|
|
XATTR_LAYOUT_FIELD(file, layout, stripe_unit),
|
|
|
|
XATTR_LAYOUT_FIELD(file, layout, stripe_count),
|
|
|
|
XATTR_LAYOUT_FIELD(file, layout, object_size),
|
|
|
|
XATTR_LAYOUT_FIELD(file, layout, pool),
|
2016-03-07 09:35:06 +08:00
|
|
|
XATTR_LAYOUT_FIELD(file, layout, pool_namespace),
|
2019-04-18 20:15:47 +08:00
|
|
|
{
|
|
|
|
.name = "ceph.snap.btime",
|
|
|
|
.name_size = sizeof("ceph.snap.btime"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_snap_btime,
|
|
|
|
.exists_cb = ceph_vxattrcb_snap_btime_exists,
|
|
|
|
.flags = VXATTR_FLAG_READONLY,
|
|
|
|
},
|
2020-11-24 01:38:46 +08:00
|
|
|
{
|
|
|
|
.name = "ceph.caps",
|
|
|
|
.name_size = sizeof("ceph.caps"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_caps,
|
|
|
|
.exists_cb = NULL,
|
|
|
|
.flags = VXATTR_FLAG_HIDDEN,
|
|
|
|
},
|
2013-02-20 02:25:56 +08:00
|
|
|
{ .name = NULL, 0 } /* Required table terminator */
|
2009-10-07 02:31:08 +08:00
|
|
|
};
|
|
|
|
|
2020-11-11 09:29:40 +08:00
|
|
|
static struct ceph_vxattr ceph_common_vxattrs[] = {
|
|
|
|
{
|
|
|
|
.name = "ceph.cluster_fsid",
|
|
|
|
.name_size = sizeof("ceph.cluster_fsid"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_cluster_fsid,
|
|
|
|
.exists_cb = NULL,
|
|
|
|
.flags = VXATTR_FLAG_READONLY,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "ceph.client_id",
|
|
|
|
.name_size = sizeof("ceph.client_id"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_client_id,
|
|
|
|
.exists_cb = NULL,
|
|
|
|
.flags = VXATTR_FLAG_READONLY,
|
|
|
|
},
|
2021-07-26 19:07:50 +08:00
|
|
|
{
|
|
|
|
.name = "ceph.auth_mds",
|
|
|
|
.name_size = sizeof("ceph.auth_mds"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_auth_mds,
|
|
|
|
.exists_cb = NULL,
|
|
|
|
.flags = VXATTR_FLAG_READONLY,
|
|
|
|
},
|
2020-07-28 21:58:43 +08:00
|
|
|
#if IS_ENABLED(CONFIG_FS_ENCRYPTION)
|
|
|
|
{
|
|
|
|
.name = "ceph.fscrypt.auth",
|
|
|
|
.name_size = sizeof("ceph.fscrypt.auth"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_fscrypt_auth,
|
|
|
|
.exists_cb = ceph_vxattrcb_fscrypt_auth_exists,
|
|
|
|
.flags = VXATTR_FLAG_READONLY,
|
|
|
|
},
|
|
|
|
#endif /* CONFIG_FS_ENCRYPTION */
|
2020-11-11 09:29:40 +08:00
|
|
|
{ .name = NULL, 0 } /* Required table terminator */
|
|
|
|
};
|
|
|
|
|
2012-01-24 05:49:28 +08:00
|
|
|
static struct ceph_vxattr *ceph_inode_vxattrs(struct inode *inode)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
|
|
|
if (S_ISDIR(inode->i_mode))
|
|
|
|
return ceph_dir_vxattrs;
|
|
|
|
else if (S_ISREG(inode->i_mode))
|
|
|
|
return ceph_file_vxattrs;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-01-24 05:49:28 +08:00
|
|
|
static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,
|
2009-10-07 02:31:08 +08:00
|
|
|
const char *name)
|
|
|
|
{
|
2012-01-24 05:49:28 +08:00
|
|
|
struct ceph_vxattr *vxattr = ceph_inode_vxattrs(inode);
|
2012-01-24 05:49:27 +08:00
|
|
|
|
|
|
|
if (vxattr) {
|
|
|
|
while (vxattr->name) {
|
|
|
|
if (!strcmp(vxattr->name, name))
|
|
|
|
return vxattr;
|
|
|
|
vxattr++;
|
|
|
|
}
|
|
|
|
}
|
2020-11-11 09:29:40 +08:00
|
|
|
|
|
|
|
vxattr = ceph_common_vxattrs;
|
|
|
|
while (vxattr->name) {
|
|
|
|
if (!strcmp(vxattr->name, name))
|
|
|
|
return vxattr;
|
|
|
|
vxattr++;
|
|
|
|
}
|
2012-01-24 05:49:27 +08:00
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-02-28 20:40:51 +08:00
|
|
|
#define MAX_XATTR_VAL_PRINT_LEN 256
|
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
static int __set_xattr(struct ceph_inode_info *ci,
|
|
|
|
const char *name, int name_len,
|
|
|
|
const char *val, int val_len,
|
2014-02-11 13:01:19 +08:00
|
|
|
int flags, int update_xattr,
|
2009-10-07 02:31:08 +08:00
|
|
|
struct ceph_inode_xattr **newxattr)
|
|
|
|
{
|
2023-06-12 09:04:07 +08:00
|
|
|
struct inode *inode = &ci->netfs.inode;
|
|
|
|
struct ceph_client *cl = ceph_inode_to_client(inode);
|
2009-10-07 02:31:08 +08:00
|
|
|
struct rb_node **p;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct ceph_inode_xattr *xattr = NULL;
|
|
|
|
int c;
|
|
|
|
int new = 0;
|
|
|
|
|
|
|
|
p = &ci->i_xattrs.index.rb_node;
|
|
|
|
while (*p) {
|
|
|
|
parent = *p;
|
|
|
|
xattr = rb_entry(parent, struct ceph_inode_xattr, node);
|
|
|
|
c = strncmp(name, xattr->name, min(name_len, xattr->name_len));
|
|
|
|
if (c < 0)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else if (c > 0)
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
else {
|
|
|
|
if (name_len == xattr->name_len)
|
|
|
|
break;
|
|
|
|
else if (name_len < xattr->name_len)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
xattr = NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:01:19 +08:00
|
|
|
if (update_xattr) {
|
|
|
|
int err = 0;
|
2017-04-28 18:14:04 +08:00
|
|
|
|
2014-02-11 13:01:19 +08:00
|
|
|
if (xattr && (flags & XATTR_CREATE))
|
|
|
|
err = -EEXIST;
|
|
|
|
else if (!xattr && (flags & XATTR_REPLACE))
|
|
|
|
err = -ENODATA;
|
|
|
|
if (err) {
|
|
|
|
kfree(name);
|
|
|
|
kfree(val);
|
2017-04-28 18:14:04 +08:00
|
|
|
kfree(*newxattr);
|
2014-02-11 13:01:19 +08:00
|
|
|
return err;
|
|
|
|
}
|
2014-02-11 13:04:19 +08:00
|
|
|
if (update_xattr < 0) {
|
|
|
|
if (xattr)
|
|
|
|
__remove_xattr(ci, xattr);
|
|
|
|
kfree(name);
|
2017-04-28 18:14:04 +08:00
|
|
|
kfree(*newxattr);
|
2014-02-11 13:04:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2014-02-11 13:01:19 +08:00
|
|
|
}
|
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
if (!xattr) {
|
|
|
|
new = 1;
|
|
|
|
xattr = *newxattr;
|
|
|
|
xattr->name = name;
|
|
|
|
xattr->name_len = name_len;
|
2014-02-11 13:01:19 +08:00
|
|
|
xattr->should_free_name = update_xattr;
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
ci->i_xattrs.count++;
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "count=%d\n", ci->i_xattrs.count);
|
2009-10-07 02:31:08 +08:00
|
|
|
} else {
|
|
|
|
kfree(*newxattr);
|
|
|
|
*newxattr = NULL;
|
|
|
|
if (xattr->should_free_val)
|
2020-07-08 15:03:22 +08:00
|
|
|
kfree(xattr->val);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2014-02-11 13:01:19 +08:00
|
|
|
if (update_xattr) {
|
2020-07-08 15:03:22 +08:00
|
|
|
kfree(name);
|
2009-10-07 02:31:08 +08:00
|
|
|
name = xattr->name;
|
|
|
|
}
|
|
|
|
ci->i_xattrs.names_size -= xattr->name_len;
|
|
|
|
ci->i_xattrs.vals_size -= xattr->val_len;
|
|
|
|
}
|
|
|
|
ci->i_xattrs.names_size += name_len;
|
|
|
|
ci->i_xattrs.vals_size += val_len;
|
|
|
|
if (val)
|
|
|
|
xattr->val = val;
|
|
|
|
else
|
|
|
|
xattr->val = "";
|
|
|
|
|
|
|
|
xattr->val_len = val_len;
|
2014-02-11 13:01:19 +08:00
|
|
|
xattr->dirty = update_xattr;
|
|
|
|
xattr->should_free_val = (val && update_xattr);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
if (new) {
|
|
|
|
rb_link_node(&xattr->node, parent, p);
|
|
|
|
rb_insert_color(&xattr->node, &ci->i_xattrs.index);
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "p=%p\n", p);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "added %p %llx.%llx xattr %p %.*s=%.*s%s\n", inode,
|
|
|
|
ceph_vinop(inode), xattr, name_len, name, min(val_len,
|
|
|
|
MAX_XATTR_VAL_PRINT_LEN), val,
|
|
|
|
val_len > MAX_XATTR_VAL_PRINT_LEN ? "..." : "");
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,
|
|
|
|
const char *name)
|
|
|
|
{
|
2023-06-12 09:04:07 +08:00
|
|
|
struct ceph_client *cl = ceph_inode_to_client(&ci->netfs.inode);
|
2009-10-07 02:31:08 +08:00
|
|
|
struct rb_node **p;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct ceph_inode_xattr *xattr = NULL;
|
2011-01-14 07:27:29 +08:00
|
|
|
int name_len = strlen(name);
|
2009-10-07 02:31:08 +08:00
|
|
|
int c;
|
|
|
|
|
|
|
|
p = &ci->i_xattrs.index.rb_node;
|
|
|
|
while (*p) {
|
|
|
|
parent = *p;
|
|
|
|
xattr = rb_entry(parent, struct ceph_inode_xattr, node);
|
|
|
|
c = strncmp(name, xattr->name, xattr->name_len);
|
2011-01-14 07:27:29 +08:00
|
|
|
if (c == 0 && name_len > xattr->name_len)
|
|
|
|
c = 1;
|
2009-10-07 02:31:08 +08:00
|
|
|
if (c < 0)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else if (c > 0)
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
else {
|
2023-02-28 20:40:51 +08:00
|
|
|
int len = min(xattr->val_len, MAX_XATTR_VAL_PRINT_LEN);
|
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "%s found %.*s%s\n", name, len, xattr->val,
|
|
|
|
xattr->val_len > len ? "..." : "");
|
2009-10-07 02:31:08 +08:00
|
|
|
return xattr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "%s not found\n", name);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __free_xattr(struct ceph_inode_xattr *xattr)
|
|
|
|
{
|
|
|
|
BUG_ON(!xattr);
|
|
|
|
|
|
|
|
if (xattr->should_free_name)
|
2020-07-08 15:03:22 +08:00
|
|
|
kfree(xattr->name);
|
2009-10-07 02:31:08 +08:00
|
|
|
if (xattr->should_free_val)
|
2020-07-08 15:03:22 +08:00
|
|
|
kfree(xattr->val);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
kfree(xattr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __remove_xattr(struct ceph_inode_info *ci,
|
|
|
|
struct ceph_inode_xattr *xattr)
|
|
|
|
{
|
|
|
|
if (!xattr)
|
2014-02-11 13:23:09 +08:00
|
|
|
return -ENODATA;
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
rb_erase(&xattr->node, &ci->i_xattrs.index);
|
|
|
|
|
|
|
|
if (xattr->should_free_name)
|
2020-07-08 15:03:22 +08:00
|
|
|
kfree(xattr->name);
|
2009-10-07 02:31:08 +08:00
|
|
|
if (xattr->should_free_val)
|
2020-07-08 15:03:22 +08:00
|
|
|
kfree(xattr->val);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
ci->i_xattrs.names_size -= xattr->name_len;
|
|
|
|
ci->i_xattrs.vals_size -= xattr->val_len;
|
|
|
|
ci->i_xattrs.count--;
|
|
|
|
kfree(xattr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *__copy_xattr_names(struct ceph_inode_info *ci,
|
|
|
|
char *dest)
|
|
|
|
{
|
2023-06-12 09:04:07 +08:00
|
|
|
struct ceph_client *cl = ceph_inode_to_client(&ci->netfs.inode);
|
2009-10-07 02:31:08 +08:00
|
|
|
struct rb_node *p;
|
|
|
|
struct ceph_inode_xattr *xattr = NULL;
|
|
|
|
|
|
|
|
p = rb_first(&ci->i_xattrs.index);
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "count=%d\n", ci->i_xattrs.count);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
while (p) {
|
|
|
|
xattr = rb_entry(p, struct ceph_inode_xattr, node);
|
|
|
|
memcpy(dest, xattr->name, xattr->name_len);
|
|
|
|
dest[xattr->name_len] = '\0';
|
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "dest=%s %p (%s) (%d/%d)\n", dest, xattr, xattr->name,
|
|
|
|
xattr->name_len, ci->i_xattrs.names_size);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
dest += xattr->name_len + 1;
|
|
|
|
p = rb_next(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __ceph_destroy_xattrs(struct ceph_inode_info *ci)
|
|
|
|
{
|
2023-06-12 09:04:07 +08:00
|
|
|
struct ceph_client *cl = ceph_inode_to_client(&ci->netfs.inode);
|
2009-10-07 02:31:08 +08:00
|
|
|
struct rb_node *p, *tmp;
|
|
|
|
struct ceph_inode_xattr *xattr = NULL;
|
|
|
|
|
|
|
|
p = rb_first(&ci->i_xattrs.index);
|
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "p=%p\n", p);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
while (p) {
|
|
|
|
xattr = rb_entry(p, struct ceph_inode_xattr, node);
|
|
|
|
tmp = p;
|
|
|
|
p = rb_next(tmp);
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "next p=%p (%.*s)\n", p, xattr->name_len, xattr->name);
|
2009-10-07 02:31:08 +08:00
|
|
|
rb_erase(tmp, &ci->i_xattrs.index);
|
|
|
|
|
|
|
|
__free_xattr(xattr);
|
|
|
|
}
|
|
|
|
|
|
|
|
ci->i_xattrs.names_size = 0;
|
|
|
|
ci->i_xattrs.vals_size = 0;
|
|
|
|
ci->i_xattrs.index_version = 0;
|
|
|
|
ci->i_xattrs.count = 0;
|
|
|
|
ci->i_xattrs.index = RB_ROOT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __build_xattrs(struct inode *inode)
|
2011-12-01 01:47:09 +08:00
|
|
|
__releases(ci->i_ceph_lock)
|
|
|
|
__acquires(ci->i_ceph_lock)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2023-06-12 09:04:07 +08:00
|
|
|
struct ceph_client *cl = ceph_inode_to_client(inode);
|
2009-10-07 02:31:08 +08:00
|
|
|
u32 namelen;
|
|
|
|
u32 numattr = 0;
|
|
|
|
void *p, *end;
|
|
|
|
u32 len;
|
|
|
|
const char *name, *val;
|
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
2019-12-19 10:15:18 +08:00
|
|
|
u64 xattr_version;
|
2009-10-07 02:31:08 +08:00
|
|
|
struct ceph_inode_xattr **xattrs = NULL;
|
2009-11-02 09:51:15 +08:00
|
|
|
int err = 0;
|
2009-10-07 02:31:08 +08:00
|
|
|
int i;
|
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "len=%d\n",
|
|
|
|
ci->i_xattrs.blob ? (int)ci->i_xattrs.blob->vec.iov_len : 0);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
if (ci->i_xattrs.index_version >= ci->i_xattrs.version)
|
|
|
|
return 0; /* already built */
|
|
|
|
|
|
|
|
__ceph_destroy_xattrs(ci);
|
|
|
|
|
|
|
|
start:
|
|
|
|
/* updated internal xattr rb tree */
|
|
|
|
if (ci->i_xattrs.blob && ci->i_xattrs.blob->vec.iov_len > 4) {
|
|
|
|
p = ci->i_xattrs.blob->vec.iov_base;
|
|
|
|
end = p + ci->i_xattrs.blob->vec.iov_len;
|
|
|
|
ceph_decode_32_safe(&p, end, numattr, bad);
|
|
|
|
xattr_version = ci->i_xattrs.version;
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2014-07-25 15:47:21 +08:00
|
|
|
xattrs = kcalloc(numattr, sizeof(struct ceph_inode_xattr *),
|
2009-10-07 02:31:08 +08:00
|
|
|
GFP_NOFS);
|
|
|
|
err = -ENOMEM;
|
|
|
|
if (!xattrs)
|
|
|
|
goto bad_lock;
|
2014-07-25 16:44:58 +08:00
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
for (i = 0; i < numattr; i++) {
|
|
|
|
xattrs[i] = kmalloc(sizeof(struct ceph_inode_xattr),
|
|
|
|
GFP_NOFS);
|
|
|
|
if (!xattrs[i])
|
|
|
|
goto bad_lock;
|
|
|
|
}
|
|
|
|
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 02:31:08 +08:00
|
|
|
if (ci->i_xattrs.version != xattr_version) {
|
|
|
|
/* lost a race, retry */
|
|
|
|
for (i = 0; i < numattr; i++)
|
|
|
|
kfree(xattrs[i]);
|
|
|
|
kfree(xattrs);
|
2012-07-20 21:18:36 +08:00
|
|
|
xattrs = NULL;
|
2009-10-07 02:31:08 +08:00
|
|
|
goto start;
|
|
|
|
}
|
|
|
|
err = -EIO;
|
|
|
|
while (numattr--) {
|
|
|
|
ceph_decode_32_safe(&p, end, len, bad);
|
|
|
|
namelen = len;
|
|
|
|
name = p;
|
|
|
|
p += len;
|
|
|
|
ceph_decode_32_safe(&p, end, len, bad);
|
|
|
|
val = p;
|
|
|
|
p += len;
|
|
|
|
|
|
|
|
err = __set_xattr(ci, name, namelen, val, len,
|
2014-02-11 13:01:19 +08:00
|
|
|
0, 0, &xattrs[numattr]);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
if (err < 0)
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
kfree(xattrs);
|
|
|
|
}
|
|
|
|
ci->i_xattrs.index_version = ci->i_xattrs.version;
|
|
|
|
ci->i_xattrs.dirty = false;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
bad_lock:
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 02:31:08 +08:00
|
|
|
bad:
|
|
|
|
if (xattrs) {
|
|
|
|
for (i = 0; i < numattr; i++)
|
|
|
|
kfree(xattrs[i]);
|
|
|
|
kfree(xattrs);
|
|
|
|
}
|
|
|
|
ci->i_xattrs.names_size = 0;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __get_required_blob_size(struct ceph_inode_info *ci, int name_size,
|
|
|
|
int val_size)
|
|
|
|
{
|
2023-06-12 09:04:07 +08:00
|
|
|
struct ceph_client *cl = ceph_inode_to_client(&ci->netfs.inode);
|
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
/*
|
|
|
|
* 4 bytes for the length, and additional 4 bytes per each xattr name,
|
|
|
|
* 4 bytes per each value
|
|
|
|
*/
|
|
|
|
int size = 4 + ci->i_xattrs.count*(4 + 4) +
|
|
|
|
ci->i_xattrs.names_size +
|
|
|
|
ci->i_xattrs.vals_size;
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "c=%d names.size=%d vals.size=%d\n", ci->i_xattrs.count,
|
|
|
|
ci->i_xattrs.names_size, ci->i_xattrs.vals_size);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
if (name_size)
|
|
|
|
size += 4 + 4 + name_size + val_size;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are dirty xattrs, reencode xattrs into the prealloc_blob
|
2019-07-19 22:32:21 +08:00
|
|
|
* and swap into place. It returns the old i_xattrs.blob (or NULL) so
|
|
|
|
* that it can be freed by the caller as the i_ceph_lock is likely to be
|
|
|
|
* held.
|
2009-10-07 02:31:08 +08:00
|
|
|
*/
|
2019-07-19 22:32:21 +08:00
|
|
|
struct ceph_buffer *__ceph_build_xattrs_blob(struct ceph_inode_info *ci)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2023-06-12 09:04:07 +08:00
|
|
|
struct inode *inode = &ci->netfs.inode;
|
|
|
|
struct ceph_client *cl = ceph_inode_to_client(inode);
|
2009-10-07 02:31:08 +08:00
|
|
|
struct rb_node *p;
|
|
|
|
struct ceph_inode_xattr *xattr = NULL;
|
2019-07-19 22:32:21 +08:00
|
|
|
struct ceph_buffer *old_blob = NULL;
|
2009-10-07 02:31:08 +08:00
|
|
|
void *dest;
|
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "%p %llx.%llx\n", inode, ceph_vinop(inode));
|
2009-10-07 02:31:08 +08:00
|
|
|
if (ci->i_xattrs.dirty) {
|
|
|
|
int need = __get_required_blob_size(ci, 0, 0);
|
|
|
|
|
|
|
|
BUG_ON(need > ci->i_xattrs.prealloc_blob->alloc_len);
|
|
|
|
|
|
|
|
p = rb_first(&ci->i_xattrs.index);
|
|
|
|
dest = ci->i_xattrs.prealloc_blob->vec.iov_base;
|
|
|
|
|
|
|
|
ceph_encode_32(&dest, ci->i_xattrs.count);
|
|
|
|
while (p) {
|
|
|
|
xattr = rb_entry(p, struct ceph_inode_xattr, node);
|
|
|
|
|
|
|
|
ceph_encode_32(&dest, xattr->name_len);
|
|
|
|
memcpy(dest, xattr->name, xattr->name_len);
|
|
|
|
dest += xattr->name_len;
|
|
|
|
ceph_encode_32(&dest, xattr->val_len);
|
|
|
|
memcpy(dest, xattr->val, xattr->val_len);
|
|
|
|
dest += xattr->val_len;
|
|
|
|
|
|
|
|
p = rb_next(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* adjust buffer len; it may be larger than we need */
|
|
|
|
ci->i_xattrs.prealloc_blob->vec.iov_len =
|
|
|
|
dest - ci->i_xattrs.prealloc_blob->vec.iov_base;
|
|
|
|
|
2009-12-08 04:17:17 +08:00
|
|
|
if (ci->i_xattrs.blob)
|
2019-07-19 22:32:21 +08:00
|
|
|
old_blob = ci->i_xattrs.blob;
|
2009-10-07 02:31:08 +08:00
|
|
|
ci->i_xattrs.blob = ci->i_xattrs.prealloc_blob;
|
|
|
|
ci->i_xattrs.prealloc_blob = NULL;
|
|
|
|
ci->i_xattrs.dirty = false;
|
2010-08-23 06:03:56 +08:00
|
|
|
ci->i_xattrs.version++;
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
2019-07-19 22:32:21 +08:00
|
|
|
|
|
|
|
return old_blob;
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2016-03-07 10:34:50 +08:00
|
|
|
static inline int __get_request_mask(struct inode *in) {
|
|
|
|
struct ceph_mds_request *req = current->journal_info;
|
|
|
|
int mask = 0;
|
|
|
|
if (req && req->r_target_inode == in) {
|
|
|
|
if (req->r_op == CEPH_MDS_OP_LOOKUP ||
|
|
|
|
req->r_op == CEPH_MDS_OP_LOOKUPINO ||
|
|
|
|
req->r_op == CEPH_MDS_OP_LOOKUPPARENT ||
|
|
|
|
req->r_op == CEPH_MDS_OP_GETATTR) {
|
|
|
|
mask = le32_to_cpu(req->r_args.getattr.mask);
|
|
|
|
} else if (req->r_op == CEPH_MDS_OP_OPEN ||
|
|
|
|
req->r_op == CEPH_MDS_OP_CREATE) {
|
|
|
|
mask = le32_to_cpu(req->r_args.open.mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2013-11-11 15:18:03 +08:00
|
|
|
ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
|
2009-10-07 02:31:08 +08:00
|
|
|
size_t size)
|
|
|
|
{
|
2023-06-12 09:04:07 +08:00
|
|
|
struct ceph_client *cl = ceph_inode_to_client(inode);
|
2009-10-07 02:31:08 +08:00
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
struct ceph_inode_xattr *xattr;
|
2022-02-14 13:01:01 +08:00
|
|
|
struct ceph_vxattr *vxattr;
|
2016-03-07 10:34:50 +08:00
|
|
|
int req_mask;
|
2019-06-24 19:39:18 +08:00
|
|
|
ssize_t err;
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2022-02-14 13:01:01 +08:00
|
|
|
if (strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN))
|
|
|
|
goto handle_non_vxattrs;
|
|
|
|
|
2013-01-21 14:00:58 +08:00
|
|
|
/* let's see if a virtual xattr was requested */
|
|
|
|
vxattr = ceph_match_vxattr(inode, name);
|
2016-03-12 13:32:16 +08:00
|
|
|
if (vxattr) {
|
2018-04-25 17:30:23 +08:00
|
|
|
int mask = 0;
|
|
|
|
if (vxattr->flags & VXATTR_FLAG_RSTAT)
|
|
|
|
mask |= CEPH_STAT_RSTAT;
|
2020-11-04 03:00:26 +08:00
|
|
|
if (vxattr->flags & VXATTR_FLAG_DIRSTAT)
|
|
|
|
mask |= CEPH_CAP_FILE_SHARED;
|
2018-04-25 17:30:23 +08:00
|
|
|
err = ceph_do_getattr(inode, mask, true);
|
2017-06-14 15:54:56 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2016-03-12 13:32:16 +08:00
|
|
|
err = -ENODATA;
|
2019-06-14 03:17:00 +08:00
|
|
|
if (!(vxattr->exists_cb && !vxattr->exists_cb(ci))) {
|
2016-03-12 13:32:16 +08:00
|
|
|
err = vxattr->getxattr_cb(ci, value, size);
|
2019-06-14 03:17:00 +08:00
|
|
|
if (size && size < err)
|
|
|
|
err = -ERANGE;
|
|
|
|
}
|
2013-06-19 14:58:10 +08:00
|
|
|
return err;
|
2022-02-14 13:01:01 +08:00
|
|
|
} else {
|
|
|
|
err = ceph_do_getvxattr(inode, name, value, size);
|
|
|
|
/* this would happen with a new client and old server combo */
|
|
|
|
if (err == -EOPNOTSUPP)
|
|
|
|
err = -ENODATA;
|
|
|
|
return err;
|
2013-01-21 14:00:58 +08:00
|
|
|
}
|
2022-02-14 13:01:01 +08:00
|
|
|
handle_non_vxattrs:
|
2016-03-07 10:34:50 +08:00
|
|
|
req_mask = __get_request_mask(inode);
|
|
|
|
|
2013-06-19 14:58:10 +08:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "%p %llx.%llx name '%s' ver=%lld index_ver=%lld\n", inode,
|
|
|
|
ceph_vinop(inode), name, ci->i_xattrs.version,
|
|
|
|
ci->i_xattrs.index_version);
|
2013-06-19 14:58:10 +08:00
|
|
|
|
2014-09-16 21:46:17 +08:00
|
|
|
if (ci->i_xattrs.version == 0 ||
|
2016-03-07 10:34:50 +08:00
|
|
|
!((req_mask & CEPH_CAP_XATTR_SHARED) ||
|
2020-03-20 11:45:00 +08:00
|
|
|
__ceph_caps_issued_mask_metric(ci, CEPH_CAP_XATTR_SHARED, 1))) {
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2016-03-07 10:34:50 +08:00
|
|
|
|
|
|
|
/* security module gets xattr while filling trace */
|
2017-08-21 02:22:02 +08:00
|
|
|
if (current->journal_info) {
|
2023-06-12 09:04:07 +08:00
|
|
|
pr_warn_ratelimited_client(cl,
|
|
|
|
"sync %p %llx.%llx during filling trace\n",
|
|
|
|
inode, ceph_vinop(inode));
|
2016-03-07 10:34:50 +08:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
/* get xattrs from mds (if we don't already have them) */
|
2014-09-16 21:46:17 +08:00
|
|
|
err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR, true);
|
2009-10-07 02:31:08 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2014-09-16 21:46:17 +08:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
err = __build_xattrs(inode);
|
|
|
|
if (err < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = -ENODATA; /* == ENOATTR */
|
|
|
|
xattr = __get_xattr(ci, name);
|
2013-01-21 14:00:58 +08:00
|
|
|
if (!xattr)
|
2009-10-07 02:31:08 +08:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = -ERANGE;
|
|
|
|
if (size && size < xattr->val_len)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = xattr->val_len;
|
|
|
|
if (size == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
memcpy(value, xattr->val, xattr->val_len);
|
|
|
|
|
2017-08-21 02:22:02 +08:00
|
|
|
if (current->journal_info &&
|
2019-08-06 22:41:40 +08:00
|
|
|
!strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) &&
|
|
|
|
security_ismaclabel(name + XATTR_SECURITY_PREFIX_LEN))
|
2016-03-07 10:34:50 +08:00
|
|
|
ci->i_ceph_flags |= CEPH_I_SEC_INITED;
|
2009-10-07 02:31:08 +08:00
|
|
|
out:
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2009-10-07 02:31:08 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
|
|
|
|
{
|
2015-03-18 06:25:59 +08:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2023-06-12 09:04:07 +08:00
|
|
|
struct ceph_client *cl = ceph_inode_to_client(inode);
|
2009-10-07 02:31:08 +08:00
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
2019-04-18 20:15:48 +08:00
|
|
|
bool len_only = (size == 0);
|
2009-10-07 02:31:08 +08:00
|
|
|
u32 namelen;
|
|
|
|
int err;
|
|
|
|
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "%p %llx.%llx ver=%lld index_ver=%lld\n", inode,
|
|
|
|
ceph_vinop(inode), ci->i_xattrs.version,
|
|
|
|
ci->i_xattrs.index_version);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2014-09-16 21:46:17 +08:00
|
|
|
if (ci->i_xattrs.version == 0 ||
|
2020-03-20 11:45:00 +08:00
|
|
|
!__ceph_caps_issued_mask_metric(ci, CEPH_CAP_XATTR_SHARED, 1)) {
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2014-09-16 21:46:17 +08:00
|
|
|
err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR, true);
|
2009-10-07 02:31:08 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2014-09-16 21:46:17 +08:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
err = __build_xattrs(inode);
|
|
|
|
if (err < 0)
|
|
|
|
goto out;
|
2012-01-24 05:49:28 +08:00
|
|
|
|
2019-04-18 20:15:48 +08:00
|
|
|
/* add 1 byte for each xattr due to the null termination */
|
2013-01-21 14:02:39 +08:00
|
|
|
namelen = ci->i_xattrs.names_size + ci->i_xattrs.count;
|
2019-04-18 20:15:48 +08:00
|
|
|
if (!len_only) {
|
|
|
|
if (namelen > size) {
|
|
|
|
err = -ERANGE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
names = __copy_xattr_names(ci, names);
|
|
|
|
size -= namelen;
|
|
|
|
}
|
|
|
|
err = namelen;
|
2009-10-07 02:31:08 +08:00
|
|
|
out:
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2009-10-07 02:31:08 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-04-14 06:30:16 +08:00
|
|
|
static int ceph_sync_setxattr(struct inode *inode, const char *name,
|
2009-10-07 02:31:08 +08:00
|
|
|
const char *value, size_t size, int flags)
|
|
|
|
{
|
2023-06-12 10:50:38 +08:00
|
|
|
struct ceph_fs_client *fsc = ceph_sb_to_fs_client(inode->i_sb);
|
2023-06-12 09:04:07 +08:00
|
|
|
struct ceph_client *cl = ceph_inode_to_client(inode);
|
2009-10-07 02:31:08 +08:00
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
struct ceph_mds_request *req;
|
2010-04-07 06:14:15 +08:00
|
|
|
struct ceph_mds_client *mdsc = fsc->mdsc;
|
2020-12-09 10:52:20 +08:00
|
|
|
struct ceph_osd_client *osdc = &fsc->client->osdc;
|
2014-09-16 19:15:28 +08:00
|
|
|
struct ceph_pagelist *pagelist = NULL;
|
2016-04-21 12:11:54 +08:00
|
|
|
int op = CEPH_MDS_OP_SETXATTR;
|
2009-10-07 02:31:08 +08:00
|
|
|
int err;
|
2014-09-16 19:15:28 +08:00
|
|
|
|
2014-12-17 21:26:47 +08:00
|
|
|
if (size > 0) {
|
2014-09-16 19:15:28 +08:00
|
|
|
/* copy value into pagelist */
|
2018-09-28 21:38:34 +08:00
|
|
|
pagelist = ceph_pagelist_alloc(GFP_NOFS);
|
2014-09-16 19:15:28 +08:00
|
|
|
if (!pagelist)
|
2009-10-07 02:31:08 +08:00
|
|
|
return -ENOMEM;
|
2014-09-16 19:15:28 +08:00
|
|
|
|
|
|
|
err = ceph_pagelist_append(pagelist, value, size);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2014-12-17 21:26:47 +08:00
|
|
|
} else if (!value) {
|
2016-04-21 12:11:54 +08:00
|
|
|
if (flags & CEPH_XATTR_REPLACE)
|
|
|
|
op = CEPH_MDS_OP_RMXATTR;
|
|
|
|
else
|
|
|
|
flags |= CEPH_XATTR_REMOVE;
|
2009-10-07 02:31:08 +08:00
|
|
|
}
|
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "name %s value size %zu\n", name, size);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
/* do request */
|
2016-04-21 12:11:54 +08:00
|
|
|
req = ceph_mdsc_create_request(mdsc, op, USE_AUTH_MDS);
|
2009-11-21 19:53:08 +08:00
|
|
|
if (IS_ERR(req)) {
|
|
|
|
err = PTR_ERR(req);
|
|
|
|
goto out;
|
|
|
|
}
|
2015-03-22 00:54:58 +08:00
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
req->r_path2 = kstrdup(name, GFP_NOFS);
|
2015-03-22 00:54:58 +08:00
|
|
|
if (!req->r_path2) {
|
|
|
|
ceph_mdsc_put_request(req);
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2016-04-21 12:11:54 +08:00
|
|
|
if (op == CEPH_MDS_OP_SETXATTR) {
|
|
|
|
req->r_args.setxattr.flags = cpu_to_le32(flags);
|
2020-12-09 10:52:20 +08:00
|
|
|
req->r_args.setxattr.osdmap_epoch =
|
|
|
|
cpu_to_le32(osdc->osdmap->epoch);
|
2016-04-21 12:11:54 +08:00
|
|
|
req->r_pagelist = pagelist;
|
|
|
|
pagelist = NULL;
|
|
|
|
}
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2015-03-22 00:54:58 +08:00
|
|
|
req->r_inode = inode;
|
|
|
|
ihold(inode);
|
|
|
|
req->r_num_caps = 1;
|
|
|
|
req->r_inode_drop = CEPH_CAP_XATTR_SHARED;
|
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "xattr.ver (before): %lld\n", ci->i_xattrs.version);
|
2013-02-06 05:52:29 +08:00
|
|
|
err = ceph_mdsc_do_request(mdsc, NULL, req);
|
2009-10-07 02:31:08 +08:00
|
|
|
ceph_mdsc_put_request(req);
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "xattr.ver (after): %lld\n", ci->i_xattrs.version);
|
2009-10-07 02:31:08 +08:00
|
|
|
|
|
|
|
out:
|
2014-09-16 19:15:28 +08:00
|
|
|
if (pagelist)
|
|
|
|
ceph_pagelist_release(pagelist);
|
2009-10-07 02:31:08 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-04-14 06:30:16 +08:00
|
|
|
int __ceph_setxattr(struct inode *inode, const char *name,
|
2013-11-11 15:18:03 +08:00
|
|
|
const void *value, size_t size, int flags)
|
2009-10-07 02:31:08 +08:00
|
|
|
{
|
2023-06-12 09:04:07 +08:00
|
|
|
struct ceph_client *cl = ceph_inode_to_client(inode);
|
2012-01-24 05:49:28 +08:00
|
|
|
struct ceph_vxattr *vxattr;
|
2009-10-07 02:31:08 +08:00
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
2023-06-12 10:50:38 +08:00
|
|
|
struct ceph_mds_client *mdsc = ceph_sb_to_fs_client(inode->i_sb)->mdsc;
|
2015-06-10 17:26:13 +08:00
|
|
|
struct ceph_cap_flush *prealloc_cf = NULL;
|
2019-07-19 22:32:20 +08:00
|
|
|
struct ceph_buffer *old_blob = NULL;
|
2012-01-24 05:49:28 +08:00
|
|
|
int issued;
|
2009-10-07 02:31:08 +08:00
|
|
|
int err;
|
2014-02-11 13:01:19 +08:00
|
|
|
int dirty = 0;
|
2009-10-07 02:31:08 +08:00
|
|
|
int name_len = strlen(name);
|
|
|
|
int val_len = size;
|
|
|
|
char *newname = NULL;
|
|
|
|
char *newval = NULL;
|
|
|
|
struct ceph_inode_xattr *xattr = NULL;
|
|
|
|
int required_blob_size;
|
2018-04-08 09:54:39 +08:00
|
|
|
bool check_realm = false;
|
2015-05-01 17:49:16 +08:00
|
|
|
bool lock_snap_rwsem = false;
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2016-04-14 06:30:17 +08:00
|
|
|
if (ceph_snap(inode) != CEPH_NOSNAP)
|
|
|
|
return -EROFS;
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2012-01-24 05:49:27 +08:00
|
|
|
vxattr = ceph_match_vxattr(inode, name);
|
2018-04-08 09:54:39 +08:00
|
|
|
if (vxattr) {
|
2018-04-25 17:14:05 +08:00
|
|
|
if (vxattr->flags & VXATTR_FLAG_READONLY)
|
2018-04-08 09:54:39 +08:00
|
|
|
return -EOPNOTSUPP;
|
|
|
|
if (value && !strncmp(vxattr->name, "ceph.quota", 10))
|
|
|
|
check_realm = true;
|
|
|
|
}
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2013-02-01 03:53:41 +08:00
|
|
|
/* pass any unhandled ceph.* xattrs through to the MDS */
|
|
|
|
if (!strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN))
|
|
|
|
goto do_sync_unlocked;
|
|
|
|
|
2009-10-07 02:31:08 +08:00
|
|
|
/* preallocate memory for xattr name, value, index node */
|
|
|
|
err = -ENOMEM;
|
2010-10-18 03:55:21 +08:00
|
|
|
newname = kmemdup(name, name_len + 1, GFP_NOFS);
|
2009-10-07 02:31:08 +08:00
|
|
|
if (!newname)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (val_len) {
|
2012-01-24 05:49:27 +08:00
|
|
|
newval = kmemdup(value, val_len, GFP_NOFS);
|
2009-10-07 02:31:08 +08:00
|
|
|
if (!newval)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
xattr = kmalloc(sizeof(struct ceph_inode_xattr), GFP_NOFS);
|
|
|
|
if (!xattr)
|
|
|
|
goto out;
|
|
|
|
|
2015-06-10 17:26:13 +08:00
|
|
|
prealloc_cf = ceph_alloc_cap_flush();
|
|
|
|
if (!prealloc_cf)
|
|
|
|
goto out;
|
|
|
|
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 02:31:08 +08:00
|
|
|
retry:
|
|
|
|
issued = __ceph_caps_issued(ci, NULL);
|
2022-06-03 21:29:09 +08:00
|
|
|
required_blob_size = __get_required_blob_size(ci, name_len, val_len);
|
|
|
|
if ((ci->i_xattrs.version == 0) || !(issued & CEPH_CAP_XATTR_EXCL) ||
|
|
|
|
(required_blob_size > mdsc->mdsmap->m_max_xattr_size)) {
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "sync version: %llu size: %d max: %llu\n",
|
|
|
|
ci->i_xattrs.version, required_blob_size,
|
|
|
|
mdsc->mdsmap->m_max_xattr_size);
|
2009-10-07 02:31:08 +08:00
|
|
|
goto do_sync;
|
2022-06-03 21:29:09 +08:00
|
|
|
}
|
2015-05-01 17:49:16 +08:00
|
|
|
|
|
|
|
if (!lock_snap_rwsem && !ci->i_head_snapc) {
|
|
|
|
lock_snap_rwsem = true;
|
|
|
|
if (!down_read_trylock(&mdsc->snap_rwsem)) {
|
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
|
|
|
down_read(&mdsc->snap_rwsem);
|
|
|
|
spin_lock(&ci->i_ceph_lock);
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, "%p %llx.%llx name '%s' issued %s\n", inode,
|
|
|
|
ceph_vinop(inode), name, ceph_cap_string(issued));
|
2009-10-07 02:31:08 +08:00
|
|
|
__build_xattrs(inode);
|
|
|
|
|
|
|
|
if (!ci->i_xattrs.prealloc_blob ||
|
|
|
|
required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
|
2012-01-24 05:49:28 +08:00
|
|
|
struct ceph_buffer *blob;
|
2009-10-07 02:31:08 +08:00
|
|
|
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2019-07-19 22:32:20 +08:00
|
|
|
ceph_buffer_put(old_blob); /* Shouldn't be required */
|
2023-06-12 09:04:07 +08:00
|
|
|
doutc(cl, " pre-allocating new blob size=%d\n",
|
|
|
|
required_blob_size);
|
2009-12-08 04:17:17 +08:00
|
|
|
blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
|
2009-10-07 02:31:08 +08:00
|
|
|
if (!blob)
|
2015-05-01 17:49:16 +08:00
|
|
|
goto do_sync_unlocked;
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2019-07-19 22:32:20 +08:00
|
|
|
/* prealloc_blob can't be released while holding i_ceph_lock */
|
2009-12-08 04:17:17 +08:00
|
|
|
if (ci->i_xattrs.prealloc_blob)
|
2019-07-19 22:32:20 +08:00
|
|
|
old_blob = ci->i_xattrs.prealloc_blob;
|
2009-10-07 02:31:08 +08:00
|
|
|
ci->i_xattrs.prealloc_blob = blob;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2014-02-11 13:04:19 +08:00
|
|
|
err = __set_xattr(ci, newname, name_len, newval, val_len,
|
|
|
|
flags, value ? 1 : -1, &xattr);
|
2012-01-24 05:49:28 +08:00
|
|
|
|
2014-02-11 13:01:19 +08:00
|
|
|
if (!err) {
|
2015-06-10 17:26:13 +08:00
|
|
|
dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL,
|
|
|
|
&prealloc_cf);
|
2014-02-11 13:01:19 +08:00
|
|
|
ci->i_xattrs.dirty = true;
|
2023-07-06 03:00:55 +08:00
|
|
|
inode_set_ctime_current(inode);
|
2014-02-11 13:01:19 +08:00
|
|
|
}
|
2012-01-24 05:49:28 +08:00
|
|
|
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2019-07-19 22:32:20 +08:00
|
|
|
ceph_buffer_put(old_blob);
|
2015-05-01 17:49:16 +08:00
|
|
|
if (lock_snap_rwsem)
|
|
|
|
up_read(&mdsc->snap_rwsem);
|
2011-05-05 02:33:47 +08:00
|
|
|
if (dirty)
|
|
|
|
__mark_inode_dirty(inode, dirty);
|
2015-06-10 17:26:13 +08:00
|
|
|
ceph_free_cap_flush(prealloc_cf);
|
2009-10-07 02:31:08 +08:00
|
|
|
return err;
|
|
|
|
|
|
|
|
do_sync:
|
2011-12-01 01:47:09 +08:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2013-02-01 03:53:41 +08:00
|
|
|
do_sync_unlocked:
|
2015-05-01 17:49:16 +08:00
|
|
|
if (lock_snap_rwsem)
|
|
|
|
up_read(&mdsc->snap_rwsem);
|
2016-03-07 10:34:50 +08:00
|
|
|
|
|
|
|
/* security module set xattr while filling trace */
|
2017-08-21 02:22:02 +08:00
|
|
|
if (current->journal_info) {
|
2023-06-12 09:04:07 +08:00
|
|
|
pr_warn_ratelimited_client(cl,
|
|
|
|
"sync %p %llx.%llx during filling trace\n",
|
|
|
|
inode, ceph_vinop(inode));
|
2016-03-07 10:34:50 +08:00
|
|
|
err = -EBUSY;
|
|
|
|
} else {
|
2016-04-14 06:30:16 +08:00
|
|
|
err = ceph_sync_setxattr(inode, name, value, size, flags);
|
2018-04-08 09:54:39 +08:00
|
|
|
if (err >= 0 && check_realm) {
|
|
|
|
/* check if snaprealm was created for quota inode */
|
|
|
|
spin_lock(&ci->i_ceph_lock);
|
|
|
|
if ((ci->i_max_files || ci->i_max_bytes) &&
|
|
|
|
!(ci->i_snap_realm &&
|
|
|
|
ci->i_snap_realm->ino == ci->i_vino.ino))
|
|
|
|
err = -EOPNOTSUPP;
|
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
|
|
|
}
|
2016-03-07 10:34:50 +08:00
|
|
|
}
|
2009-10-07 02:31:08 +08:00
|
|
|
out:
|
2015-06-10 17:26:13 +08:00
|
|
|
ceph_free_cap_flush(prealloc_cf);
|
2009-10-07 02:31:08 +08:00
|
|
|
kfree(newname);
|
|
|
|
kfree(newval);
|
|
|
|
kfree(xattr);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2016-04-14 06:30:17 +08:00
|
|
|
static int ceph_get_xattr_handler(const struct xattr_handler *handler,
|
|
|
|
struct dentry *dentry, struct inode *inode,
|
|
|
|
const char *name, void *value, size_t size)
|
2013-11-11 15:18:03 +08:00
|
|
|
{
|
2016-04-14 06:30:17 +08:00
|
|
|
if (!ceph_is_valid_xattr(name))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
return __ceph_getxattr(inode, name, value, size);
|
|
|
|
}
|
2013-11-11 15:18:03 +08:00
|
|
|
|
2016-04-14 06:30:17 +08:00
|
|
|
static int ceph_set_xattr_handler(const struct xattr_handler *handler,
|
2023-01-13 19:49:23 +08:00
|
|
|
struct mnt_idmap *idmap,
|
2016-05-27 22:19:30 +08:00
|
|
|
struct dentry *unused, struct inode *inode,
|
|
|
|
const char *name, const void *value,
|
|
|
|
size_t size, int flags)
|
2016-04-14 06:30:17 +08:00
|
|
|
{
|
|
|
|
if (!ceph_is_valid_xattr(name))
|
|
|
|
return -EOPNOTSUPP;
|
2016-05-27 22:19:30 +08:00
|
|
|
return __ceph_setxattr(inode, name, value, size, flags);
|
2013-11-11 15:18:03 +08:00
|
|
|
}
|
2016-03-07 10:34:50 +08:00
|
|
|
|
2016-10-17 23:11:29 +08:00
|
|
|
static const struct xattr_handler ceph_other_xattr_handler = {
|
2016-04-14 06:30:17 +08:00
|
|
|
.prefix = "", /* match any name => handlers called with full name */
|
|
|
|
.get = ceph_get_xattr_handler,
|
|
|
|
.set = ceph_set_xattr_handler,
|
|
|
|
};
|
|
|
|
|
2016-03-07 10:34:50 +08:00
|
|
|
#ifdef CONFIG_SECURITY
|
|
|
|
bool ceph_security_xattr_wanted(struct inode *in)
|
|
|
|
{
|
|
|
|
return in->i_security != NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ceph_security_xattr_deadlock(struct inode *in)
|
|
|
|
{
|
|
|
|
struct ceph_inode_info *ci;
|
|
|
|
bool ret;
|
2017-08-21 02:22:02 +08:00
|
|
|
if (!in->i_security)
|
2016-03-07 10:34:50 +08:00
|
|
|
return false;
|
|
|
|
ci = ceph_inode(in);
|
|
|
|
spin_lock(&ci->i_ceph_lock);
|
|
|
|
ret = !(ci->i_ceph_flags & CEPH_I_SEC_INITED) &&
|
|
|
|
!(ci->i_xattrs.version > 0 &&
|
|
|
|
__ceph_caps_issued_mask(ci, CEPH_CAP_XATTR_SHARED, 0));
|
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
|
|
|
return ret;
|
|
|
|
}
|
2019-05-26 16:27:56 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_CEPH_FS_SECURITY_LABEL
|
|
|
|
int ceph_security_init_secctx(struct dentry *dentry, umode_t mode,
|
|
|
|
struct ceph_acl_sec_ctx *as_ctx)
|
|
|
|
{
|
|
|
|
struct ceph_pagelist *pagelist = as_ctx->pagelist;
|
|
|
|
const char *name;
|
|
|
|
size_t name_len;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = security_dentry_init_security(dentry, mode, &dentry->d_name,
|
2021-10-12 21:23:07 +08:00
|
|
|
&name, &as_ctx->sec_ctx,
|
2019-05-26 16:27:56 +08:00
|
|
|
&as_ctx->sec_ctxlen);
|
|
|
|
if (err < 0) {
|
|
|
|
WARN_ON_ONCE(err != -EOPNOTSUPP);
|
|
|
|
err = 0; /* do nothing */
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
if (!pagelist) {
|
|
|
|
pagelist = ceph_pagelist_alloc(GFP_KERNEL);
|
|
|
|
if (!pagelist)
|
|
|
|
goto out;
|
|
|
|
err = ceph_pagelist_reserve(pagelist, PAGE_SIZE);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
ceph_pagelist_encode_32(pagelist, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* FIXME: Make security_dentry_init_security() generic. Currently
|
|
|
|
* It only supports single security module and only selinux has
|
|
|
|
* dentry_init_security hook.
|
|
|
|
*/
|
|
|
|
name_len = strlen(name);
|
|
|
|
err = ceph_pagelist_reserve(pagelist,
|
|
|
|
4 * 2 + name_len + as_ctx->sec_ctxlen);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (as_ctx->pagelist) {
|
|
|
|
/* update count of KV pairs */
|
|
|
|
BUG_ON(pagelist->length <= sizeof(__le32));
|
|
|
|
if (list_is_singular(&pagelist->head)) {
|
|
|
|
le32_add_cpu((__le32*)pagelist->mapped_tail, 1);
|
|
|
|
} else {
|
|
|
|
struct page *page = list_first_entry(&pagelist->head,
|
|
|
|
struct page, lru);
|
|
|
|
void *addr = kmap_atomic(page);
|
|
|
|
le32_add_cpu((__le32*)addr, 1);
|
|
|
|
kunmap_atomic(addr);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
as_ctx->pagelist = pagelist;
|
|
|
|
}
|
|
|
|
|
|
|
|
ceph_pagelist_encode_32(pagelist, name_len);
|
|
|
|
ceph_pagelist_append(pagelist, name, name_len);
|
|
|
|
|
|
|
|
ceph_pagelist_encode_32(pagelist, as_ctx->sec_ctxlen);
|
|
|
|
ceph_pagelist_append(pagelist, as_ctx->sec_ctx, as_ctx->sec_ctxlen);
|
|
|
|
|
|
|
|
err = 0;
|
|
|
|
out:
|
|
|
|
if (pagelist && !as_ctx->pagelist)
|
|
|
|
ceph_pagelist_release(pagelist);
|
|
|
|
return err;
|
|
|
|
}
|
2019-08-06 21:07:51 +08:00
|
|
|
#endif /* CONFIG_CEPH_FS_SECURITY_LABEL */
|
|
|
|
#endif /* CONFIG_SECURITY */
|
2019-05-26 15:35:39 +08:00
|
|
|
|
|
|
|
void ceph_release_acl_sec_ctx(struct ceph_acl_sec_ctx *as_ctx)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_CEPH_FS_POSIX_ACL
|
|
|
|
posix_acl_release(as_ctx->acl);
|
|
|
|
posix_acl_release(as_ctx->default_acl);
|
2019-05-26 16:27:56 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_CEPH_FS_SECURITY_LABEL
|
|
|
|
security_release_secctx(as_ctx->sec_ctx, as_ctx->sec_ctxlen);
|
2020-09-08 21:47:40 +08:00
|
|
|
#endif
|
|
|
|
#ifdef CONFIG_FS_ENCRYPTION
|
|
|
|
kfree(as_ctx->fscrypt_auth);
|
2019-05-26 15:35:39 +08:00
|
|
|
#endif
|
|
|
|
if (as_ctx->pagelist)
|
|
|
|
ceph_pagelist_release(as_ctx->pagelist);
|
|
|
|
}
|
2019-05-26 16:27:56 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* List of handlers for synthetic system.* attributes. Other
|
|
|
|
* attributes are handled directly.
|
|
|
|
*/
|
2023-09-30 13:00:10 +08:00
|
|
|
const struct xattr_handler * const ceph_xattr_handlers[] = {
|
2019-05-26 16:27:56 +08:00
|
|
|
&ceph_other_xattr_handler,
|
|
|
|
NULL,
|
|
|
|
};
|