2010-04-07 05:14:15 +07:00
|
|
|
#include <linux/ceph/ceph_debug.h>
|
2014-09-16 18:15:28 +07:00
|
|
|
#include <linux/ceph/pagelist.h>
|
2010-04-07 05:14:15 +07:00
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
#include "super.h"
|
2010-04-07 05:14:15 +07:00
|
|
|
#include "mds_client.h"
|
|
|
|
|
|
|
|
#include <linux/ceph/decode.h>
|
2009-10-07 01:31:08 +07:00
|
|
|
|
|
|
|
#include <linux/xattr.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 09:06:18 +07: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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-10-07 01:31:08 +07:00
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
#define XATTR_CEPH_PREFIX "ceph."
|
|
|
|
#define XATTR_CEPH_PREFIX_LEN (sizeof (XATTR_CEPH_PREFIX) - 1)
|
|
|
|
|
2014-02-11 12:04:19 +07:00
|
|
|
static int __remove_xattr(struct ceph_inode_info *ci,
|
|
|
|
struct ceph_inode_xattr *xattr);
|
|
|
|
|
2013-11-11 14:18:03 +07:00
|
|
|
/*
|
|
|
|
* List of handlers for synthetic system.* attributes. Other
|
|
|
|
* attributes are handled directly.
|
|
|
|
*/
|
|
|
|
const struct xattr_handler *ceph_xattr_handlers[] = {
|
|
|
|
#ifdef CONFIG_CEPH_FS_POSIX_ACL
|
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 09:06:18 +07:00
|
|
|
&posix_acl_access_xattr_handler,
|
|
|
|
&posix_acl_default_xattr_handler,
|
2013-11-11 14:18:03 +07:00
|
|
|
#endif
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
static bool ceph_is_valid_xattr(const char *name)
|
|
|
|
{
|
2012-01-24 04:49:28 +07:00
|
|
|
return !strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN) ||
|
2010-05-12 01:40:25 +07:00
|
|
|
!strncmp(name, XATTR_SECURITY_PREFIX,
|
2009-10-07 01:31:08 +07:00
|
|
|
XATTR_SECURITY_PREFIX_LEN) ||
|
2013-11-11 14:18:03 +07:00
|
|
|
!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) ||
|
2009-10-07 01:31:08 +07: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 04:49:28 +07:00
|
|
|
struct ceph_vxattr {
|
2009-10-07 01:31:08 +07:00
|
|
|
char *name;
|
2012-01-24 04:49:28 +07:00
|
|
|
size_t name_size; /* strlen(name) + 1 (for '\0') */
|
2009-10-07 01:31:08 +07:00
|
|
|
size_t (*getxattr_cb)(struct ceph_inode_info *ci, char *val,
|
|
|
|
size_t size);
|
2013-02-01 02:53:27 +07:00
|
|
|
bool readonly, hidden;
|
2013-01-21 12:59:29 +07:00
|
|
|
bool (*exists_cb)(struct ceph_inode_info *ci);
|
2009-10-07 01:31:08 +07:00
|
|
|
};
|
|
|
|
|
2013-01-20 07:46:32 +07:00
|
|
|
/* layouts */
|
|
|
|
|
|
|
|
static bool ceph_vxattrcb_layout_exists(struct ceph_inode_info *ci)
|
|
|
|
{
|
|
|
|
size_t s;
|
|
|
|
char *p = (char *)&ci->i_layout;
|
|
|
|
|
|
|
|
for (s = 0; s < sizeof(ci->i_layout); s++, p++)
|
|
|
|
if (*p)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t ceph_vxattrcb_layout(struct ceph_inode_info *ci, char *val,
|
2014-03-24 12:00:54 +07:00
|
|
|
size_t size)
|
2013-01-20 07:46:32 +07:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct ceph_fs_client *fsc = ceph_sb_to_client(ci->vfs_inode.i_sb);
|
|
|
|
struct ceph_osd_client *osdc = &fsc->client->osdc;
|
|
|
|
s64 pool = ceph_file_layout_pg_pool(ci->i_layout);
|
|
|
|
const char *pool_name;
|
2014-03-24 12:00:54 +07:00
|
|
|
char buf[128];
|
2013-01-20 07:46:32 +07:00
|
|
|
|
|
|
|
dout("ceph_vxattrcb_layout %p\n", &ci->vfs_inode);
|
|
|
|
down_read(&osdc->map_sem);
|
|
|
|
pool_name = ceph_pg_pool_name_by_id(osdc->osdmap, pool);
|
2014-03-24 12:00:54 +07:00
|
|
|
if (pool_name) {
|
|
|
|
size_t len = strlen(pool_name);
|
|
|
|
ret = snprintf(buf, sizeof(buf),
|
|
|
|
"stripe_unit=%lld stripe_count=%lld object_size=%lld pool=",
|
2013-01-20 07:46:32 +07:00
|
|
|
(unsigned long long)ceph_file_layout_su(ci->i_layout),
|
|
|
|
(unsigned long long)ceph_file_layout_stripe_count(ci->i_layout),
|
2014-03-24 12:00:54 +07:00
|
|
|
(unsigned long long)ceph_file_layout_object_size(ci->i_layout));
|
|
|
|
if (!size) {
|
|
|
|
ret += len;
|
|
|
|
} else if (ret + len > size) {
|
|
|
|
ret = -ERANGE;
|
|
|
|
} else {
|
|
|
|
memcpy(val, buf, ret);
|
|
|
|
memcpy(val + ret, pool_name, len);
|
|
|
|
ret += len;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ret = snprintf(buf, sizeof(buf),
|
2013-01-20 07:46:32 +07:00
|
|
|
"stripe_unit=%lld stripe_count=%lld object_size=%lld pool=%lld",
|
|
|
|
(unsigned long long)ceph_file_layout_su(ci->i_layout),
|
|
|
|
(unsigned long long)ceph_file_layout_stripe_count(ci->i_layout),
|
|
|
|
(unsigned long long)ceph_file_layout_object_size(ci->i_layout),
|
|
|
|
(unsigned long long)pool);
|
2014-03-24 12:00:54 +07:00
|
|
|
if (size) {
|
|
|
|
if (ret <= size)
|
|
|
|
memcpy(val, buf, ret);
|
|
|
|
else
|
|
|
|
ret = -ERANGE;
|
|
|
|
}
|
|
|
|
}
|
2013-01-20 07:46:32 +07:00
|
|
|
up_read(&osdc->map_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-21 13:08:33 +07:00
|
|
|
static size_t ceph_vxattrcb_layout_stripe_unit(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
|
|
|
{
|
|
|
|
return snprintf(val, size, "%lld",
|
|
|
|
(unsigned long long)ceph_file_layout_su(ci->i_layout));
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t ceph_vxattrcb_layout_stripe_count(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
|
|
|
{
|
|
|
|
return snprintf(val, size, "%lld",
|
|
|
|
(unsigned long long)ceph_file_layout_stripe_count(ci->i_layout));
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t ceph_vxattrcb_layout_object_size(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
|
|
|
{
|
|
|
|
return snprintf(val, size, "%lld",
|
|
|
|
(unsigned long long)ceph_file_layout_object_size(ci->i_layout));
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t ceph_vxattrcb_layout_pool(struct ceph_inode_info *ci,
|
|
|
|
char *val, size_t size)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct ceph_fs_client *fsc = ceph_sb_to_client(ci->vfs_inode.i_sb);
|
|
|
|
struct ceph_osd_client *osdc = &fsc->client->osdc;
|
|
|
|
s64 pool = ceph_file_layout_pg_pool(ci->i_layout);
|
|
|
|
const char *pool_name;
|
|
|
|
|
|
|
|
down_read(&osdc->map_sem);
|
|
|
|
pool_name = ceph_pg_pool_name_by_id(osdc->osdmap, pool);
|
|
|
|
if (pool_name)
|
|
|
|
ret = snprintf(val, size, "%s", pool_name);
|
|
|
|
else
|
|
|
|
ret = snprintf(val, size, "%lld", (unsigned long long)pool);
|
|
|
|
up_read(&osdc->map_sem);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
/* directories */
|
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static size_t ceph_vxattrcb_dir_entries(struct ceph_inode_info *ci, char *val,
|
2009-10-07 01:31:08 +07:00
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
return snprintf(val, size, "%lld", ci->i_files + ci->i_subdirs);
|
|
|
|
}
|
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static size_t ceph_vxattrcb_dir_files(struct ceph_inode_info *ci, char *val,
|
2009-10-07 01:31:08 +07:00
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
return snprintf(val, size, "%lld", ci->i_files);
|
|
|
|
}
|
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static size_t ceph_vxattrcb_dir_subdirs(struct ceph_inode_info *ci, char *val,
|
2009-10-07 01:31:08 +07:00
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
return snprintf(val, size, "%lld", ci->i_subdirs);
|
|
|
|
}
|
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static size_t ceph_vxattrcb_dir_rentries(struct ceph_inode_info *ci, char *val,
|
2009-10-07 01:31:08 +07:00
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
return snprintf(val, size, "%lld", ci->i_rfiles + ci->i_rsubdirs);
|
|
|
|
}
|
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static size_t ceph_vxattrcb_dir_rfiles(struct ceph_inode_info *ci, char *val,
|
2009-10-07 01:31:08 +07:00
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
return snprintf(val, size, "%lld", ci->i_rfiles);
|
|
|
|
}
|
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static size_t ceph_vxattrcb_dir_rsubdirs(struct ceph_inode_info *ci, char *val,
|
2009-10-07 01:31:08 +07:00
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
return snprintf(val, size, "%lld", ci->i_rsubdirs);
|
|
|
|
}
|
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static size_t ceph_vxattrcb_dir_rbytes(struct ceph_inode_info *ci, char *val,
|
2009-10-07 01:31:08 +07:00
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
return snprintf(val, size, "%lld", ci->i_rbytes);
|
|
|
|
}
|
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static size_t ceph_vxattrcb_dir_rctime(struct ceph_inode_info *ci, char *val,
|
2009-10-07 01:31:08 +07:00
|
|
|
size_t size)
|
|
|
|
{
|
ceph: fix three bugs, two in ceph_vxattrcb_file_layout()
In ceph_vxattrcb_file_layout(), there is a check to determine
whether a preferred PG should be formatted into the output buffer.
That check assumes that a preferred PG number of 0 indicates "no
preference," but that is wrong. No preference is indicated by a
negative (specifically, -1) PG number.
In addition, if that condition yields true, the preferred value
is formatted into a sized buffer, but the size consumed by the
earlier snprintf() call is not accounted for, opening up the
possibilty of a buffer overrun.
Finally, in ceph_vxattrcb_dir_rctime() where the nanoseconds part of
the time displayed did not include leading 0's, which led to
erroneous (sub-second portion of) time values being shown.
This fixes these three issues:
http://tracker.newdream.net/issues/2155
http://tracker.newdream.net/issues/2156
http://tracker.newdream.net/issues/2157
Signed-off-by: Alex Elder <elder@dreamhost.com>
Reviewed-by: Sage Weil <sage@newdream.net>
2012-03-09 05:50:09 +07:00
|
|
|
return snprintf(val, size, "%ld.09%ld", (long)ci->i_rctime.tv_sec,
|
2009-10-07 01:31:08 +07:00
|
|
|
(long)ci->i_rctime.tv_nsec);
|
|
|
|
}
|
|
|
|
|
2013-01-20 07:46:32 +07:00
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
#define CEPH_XATTR_NAME(_type, _name) XATTR_CEPH_PREFIX #_type "." #_name
|
2013-01-21 13:08:33 +07:00
|
|
|
#define CEPH_XATTR_NAME2(_type, _name, _name2) \
|
|
|
|
XATTR_CEPH_PREFIX #_type "." #_name "." #_name2
|
2012-01-24 04:49:28 +07:00
|
|
|
|
2013-02-01 02:53:27 +07:00
|
|
|
#define XATTR_NAME_CEPH(_type, _name) \
|
|
|
|
{ \
|
|
|
|
.name = CEPH_XATTR_NAME(_type, _name), \
|
|
|
|
.name_size = sizeof (CEPH_XATTR_NAME(_type, _name)), \
|
|
|
|
.getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
|
|
|
|
.readonly = true, \
|
|
|
|
.hidden = false, \
|
2013-01-21 12:59:29 +07:00
|
|
|
.exists_cb = NULL, \
|
2013-02-01 02:53:27 +07:00
|
|
|
}
|
2013-01-21 13:08:33 +07: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, \
|
|
|
|
.readonly = false, \
|
|
|
|
.hidden = true, \
|
|
|
|
.exists_cb = ceph_vxattrcb_layout_exists, \
|
|
|
|
}
|
2012-01-24 04:49:28 +07:00
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static struct ceph_vxattr ceph_dir_vxattrs[] = {
|
2013-01-21 13:07:12 +07:00
|
|
|
{
|
|
|
|
.name = "ceph.dir.layout",
|
|
|
|
.name_size = sizeof("ceph.dir.layout"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_layout,
|
|
|
|
.readonly = false,
|
2014-03-24 18:15:05 +07:00
|
|
|
.hidden = true,
|
2013-01-21 13:07:12 +07:00
|
|
|
.exists_cb = ceph_vxattrcb_layout_exists,
|
|
|
|
},
|
2013-01-21 13:08:33 +07: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),
|
2012-01-24 04:49:28 +07:00
|
|
|
XATTR_NAME_CEPH(dir, entries),
|
|
|
|
XATTR_NAME_CEPH(dir, files),
|
|
|
|
XATTR_NAME_CEPH(dir, subdirs),
|
|
|
|
XATTR_NAME_CEPH(dir, rentries),
|
|
|
|
XATTR_NAME_CEPH(dir, rfiles),
|
|
|
|
XATTR_NAME_CEPH(dir, rsubdirs),
|
|
|
|
XATTR_NAME_CEPH(dir, rbytes),
|
|
|
|
XATTR_NAME_CEPH(dir, rctime),
|
2013-02-20 01:25:56 +07:00
|
|
|
{ .name = NULL, 0 } /* Required table terminator */
|
2009-10-07 01:31:08 +07:00
|
|
|
};
|
2012-01-24 04:49:28 +07:00
|
|
|
static size_t ceph_dir_vxattrs_name_size; /* total size of all names */
|
2009-10-07 01:31:08 +07:00
|
|
|
|
|
|
|
/* files */
|
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static struct ceph_vxattr ceph_file_vxattrs[] = {
|
2013-01-20 07:46:32 +07:00
|
|
|
{
|
|
|
|
.name = "ceph.file.layout",
|
|
|
|
.name_size = sizeof("ceph.file.layout"),
|
|
|
|
.getxattr_cb = ceph_vxattrcb_layout,
|
|
|
|
.readonly = false,
|
2014-03-24 18:15:05 +07:00
|
|
|
.hidden = true,
|
2013-01-20 07:46:32 +07:00
|
|
|
.exists_cb = ceph_vxattrcb_layout_exists,
|
|
|
|
},
|
2013-01-21 13:08:33 +07: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),
|
2013-02-20 01:25:56 +07:00
|
|
|
{ .name = NULL, 0 } /* Required table terminator */
|
2009-10-07 01:31:08 +07:00
|
|
|
};
|
2012-01-24 04:49:28 +07:00
|
|
|
static size_t ceph_file_vxattrs_name_size; /* total size of all names */
|
2009-10-07 01:31:08 +07:00
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static struct ceph_vxattr *ceph_inode_vxattrs(struct inode *inode)
|
2009-10-07 01:31:08 +07: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 04:49:28 +07:00
|
|
|
static size_t ceph_vxattrs_name_size(struct ceph_vxattr *vxattrs)
|
|
|
|
{
|
|
|
|
if (vxattrs == ceph_dir_vxattrs)
|
|
|
|
return ceph_dir_vxattrs_name_size;
|
|
|
|
if (vxattrs == ceph_file_vxattrs)
|
|
|
|
return ceph_file_vxattrs_name_size;
|
2014-09-18 15:11:12 +07:00
|
|
|
BUG_ON(vxattrs);
|
2012-01-24 04:49:28 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compute the aggregate size (including terminating '\0') of all
|
|
|
|
* virtual extended attribute names in the given vxattr table.
|
|
|
|
*/
|
|
|
|
static size_t __init vxattrs_name_size(struct ceph_vxattr *vxattrs)
|
|
|
|
{
|
|
|
|
struct ceph_vxattr *vxattr;
|
|
|
|
size_t size = 0;
|
|
|
|
|
|
|
|
for (vxattr = vxattrs; vxattr->name; vxattr++)
|
2013-02-01 02:53:27 +07:00
|
|
|
if (!vxattr->hidden)
|
|
|
|
size += vxattr->name_size;
|
2012-01-24 04:49:28 +07:00
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Routines called at initialization and exit time */
|
|
|
|
|
|
|
|
void __init ceph_xattr_init(void)
|
|
|
|
{
|
|
|
|
ceph_dir_vxattrs_name_size = vxattrs_name_size(ceph_dir_vxattrs);
|
|
|
|
ceph_file_vxattrs_name_size = vxattrs_name_size(ceph_file_vxattrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ceph_xattr_exit(void)
|
|
|
|
{
|
|
|
|
ceph_dir_vxattrs_name_size = 0;
|
|
|
|
ceph_file_vxattrs_name_size = 0;
|
|
|
|
}
|
|
|
|
|
2012-01-24 04:49:28 +07:00
|
|
|
static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,
|
2009-10-07 01:31:08 +07:00
|
|
|
const char *name)
|
|
|
|
{
|
2012-01-24 04:49:28 +07:00
|
|
|
struct ceph_vxattr *vxattr = ceph_inode_vxattrs(inode);
|
2012-01-24 04:49:27 +07:00
|
|
|
|
|
|
|
if (vxattr) {
|
|
|
|
while (vxattr->name) {
|
|
|
|
if (!strcmp(vxattr->name, name))
|
|
|
|
return vxattr;
|
|
|
|
vxattr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __set_xattr(struct ceph_inode_info *ci,
|
|
|
|
const char *name, int name_len,
|
|
|
|
const char *val, int val_len,
|
2014-02-11 12:01:19 +07:00
|
|
|
int flags, int update_xattr,
|
2009-10-07 01:31:08 +07:00
|
|
|
struct ceph_inode_xattr **newxattr)
|
|
|
|
{
|
|
|
|
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 12:01:19 +07:00
|
|
|
if (update_xattr) {
|
|
|
|
int err = 0;
|
|
|
|
if (xattr && (flags & XATTR_CREATE))
|
|
|
|
err = -EEXIST;
|
|
|
|
else if (!xattr && (flags & XATTR_REPLACE))
|
|
|
|
err = -ENODATA;
|
|
|
|
if (err) {
|
|
|
|
kfree(name);
|
|
|
|
kfree(val);
|
|
|
|
return err;
|
|
|
|
}
|
2014-02-11 12:04:19 +07:00
|
|
|
if (update_xattr < 0) {
|
|
|
|
if (xattr)
|
|
|
|
__remove_xattr(ci, xattr);
|
|
|
|
kfree(name);
|
|
|
|
return 0;
|
|
|
|
}
|
2014-02-11 12:01:19 +07:00
|
|
|
}
|
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
if (!xattr) {
|
|
|
|
new = 1;
|
|
|
|
xattr = *newxattr;
|
|
|
|
xattr->name = name;
|
|
|
|
xattr->name_len = name_len;
|
2014-02-11 12:01:19 +07:00
|
|
|
xattr->should_free_name = update_xattr;
|
2009-10-07 01:31:08 +07:00
|
|
|
|
|
|
|
ci->i_xattrs.count++;
|
|
|
|
dout("__set_xattr count=%d\n", ci->i_xattrs.count);
|
|
|
|
} else {
|
|
|
|
kfree(*newxattr);
|
|
|
|
*newxattr = NULL;
|
|
|
|
if (xattr->should_free_val)
|
|
|
|
kfree((void *)xattr->val);
|
|
|
|
|
2014-02-11 12:01:19 +07:00
|
|
|
if (update_xattr) {
|
2009-10-07 01:31:08 +07:00
|
|
|
kfree((void *)name);
|
|
|
|
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 12:01:19 +07:00
|
|
|
xattr->dirty = update_xattr;
|
|
|
|
xattr->should_free_val = (val && update_xattr);
|
2009-10-07 01:31:08 +07:00
|
|
|
|
|
|
|
if (new) {
|
|
|
|
rb_link_node(&xattr->node, parent, p);
|
|
|
|
rb_insert_color(&xattr->node, &ci->i_xattrs.index);
|
|
|
|
dout("__set_xattr_val p=%p\n", p);
|
|
|
|
}
|
|
|
|
|
|
|
|
dout("__set_xattr_val added %llx.%llx xattr %p %s=%.*s\n",
|
|
|
|
ceph_vinop(&ci->vfs_inode), xattr, name, val_len, val);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ceph_inode_xattr *__get_xattr(struct ceph_inode_info *ci,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct rb_node **p;
|
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct ceph_inode_xattr *xattr = NULL;
|
2011-01-14 06:27:29 +07:00
|
|
|
int name_len = strlen(name);
|
2009-10-07 01:31:08 +07: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 06:27:29 +07:00
|
|
|
if (c == 0 && name_len > xattr->name_len)
|
|
|
|
c = 1;
|
2009-10-07 01:31:08 +07:00
|
|
|
if (c < 0)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else if (c > 0)
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
else {
|
|
|
|
dout("__get_xattr %s: found %.*s\n", name,
|
|
|
|
xattr->val_len, xattr->val);
|
|
|
|
return xattr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dout("__get_xattr %s: not found\n", name);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __free_xattr(struct ceph_inode_xattr *xattr)
|
|
|
|
{
|
|
|
|
BUG_ON(!xattr);
|
|
|
|
|
|
|
|
if (xattr->should_free_name)
|
|
|
|
kfree((void *)xattr->name);
|
|
|
|
if (xattr->should_free_val)
|
|
|
|
kfree((void *)xattr->val);
|
|
|
|
|
|
|
|
kfree(xattr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __remove_xattr(struct ceph_inode_info *ci,
|
|
|
|
struct ceph_inode_xattr *xattr)
|
|
|
|
{
|
|
|
|
if (!xattr)
|
2014-02-11 12:23:09 +07:00
|
|
|
return -ENODATA;
|
2009-10-07 01:31:08 +07:00
|
|
|
|
|
|
|
rb_erase(&xattr->node, &ci->i_xattrs.index);
|
|
|
|
|
|
|
|
if (xattr->should_free_name)
|
|
|
|
kfree((void *)xattr->name);
|
|
|
|
if (xattr->should_free_val)
|
|
|
|
kfree((void *)xattr->val);
|
|
|
|
|
|
|
|
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 int __remove_xattr_by_name(struct ceph_inode_info *ci,
|
|
|
|
const char *name)
|
|
|
|
{
|
|
|
|
struct rb_node **p;
|
|
|
|
struct ceph_inode_xattr *xattr;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
p = &ci->i_xattrs.index.rb_node;
|
|
|
|
xattr = __get_xattr(ci, name);
|
|
|
|
err = __remove_xattr(ci, xattr);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *__copy_xattr_names(struct ceph_inode_info *ci,
|
|
|
|
char *dest)
|
|
|
|
{
|
|
|
|
struct rb_node *p;
|
|
|
|
struct ceph_inode_xattr *xattr = NULL;
|
|
|
|
|
|
|
|
p = rb_first(&ci->i_xattrs.index);
|
|
|
|
dout("__copy_xattr_names count=%d\n", ci->i_xattrs.count);
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
xattr = rb_entry(p, struct ceph_inode_xattr, node);
|
|
|
|
memcpy(dest, xattr->name, xattr->name_len);
|
|
|
|
dest[xattr->name_len] = '\0';
|
|
|
|
|
|
|
|
dout("dest=%s %p (%s) (%d/%d)\n", dest, xattr, xattr->name,
|
|
|
|
xattr->name_len, ci->i_xattrs.names_size);
|
|
|
|
|
|
|
|
dest += xattr->name_len + 1;
|
|
|
|
p = rb_next(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
void __ceph_destroy_xattrs(struct ceph_inode_info *ci)
|
|
|
|
{
|
|
|
|
struct rb_node *p, *tmp;
|
|
|
|
struct ceph_inode_xattr *xattr = NULL;
|
|
|
|
|
|
|
|
p = rb_first(&ci->i_xattrs.index);
|
|
|
|
|
|
|
|
dout("__ceph_destroy_xattrs p=%p\n", p);
|
|
|
|
|
|
|
|
while (p) {
|
|
|
|
xattr = rb_entry(p, struct ceph_inode_xattr, node);
|
|
|
|
tmp = p;
|
|
|
|
p = rb_next(tmp);
|
|
|
|
dout("__ceph_destroy_xattrs next p=%p (%.*s)\n", p,
|
|
|
|
xattr->name_len, xattr->name);
|
|
|
|
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 00:47:09 +07:00
|
|
|
__releases(ci->i_ceph_lock)
|
|
|
|
__acquires(ci->i_ceph_lock)
|
2009-10-07 01:31:08 +07:00
|
|
|
{
|
|
|
|
u32 namelen;
|
|
|
|
u32 numattr = 0;
|
|
|
|
void *p, *end;
|
|
|
|
u32 len;
|
|
|
|
const char *name, *val;
|
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
int xattr_version;
|
|
|
|
struct ceph_inode_xattr **xattrs = NULL;
|
2009-11-02 08:51:15 +07:00
|
|
|
int err = 0;
|
2009-10-07 01:31:08 +07:00
|
|
|
int i;
|
|
|
|
|
|
|
|
dout("__build_xattrs() len=%d\n",
|
|
|
|
ci->i_xattrs.blob ? (int)ci->i_xattrs.blob->vec.iov_len : 0);
|
|
|
|
|
|
|
|
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 00:47:09 +07:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07:00
|
|
|
|
2014-07-25 14:47:21 +07:00
|
|
|
xattrs = kcalloc(numattr, sizeof(struct ceph_inode_xattr *),
|
2009-10-07 01:31:08 +07:00
|
|
|
GFP_NOFS);
|
|
|
|
err = -ENOMEM;
|
|
|
|
if (!xattrs)
|
|
|
|
goto bad_lock;
|
2014-07-25 15:44:58 +07:00
|
|
|
|
2009-10-07 01:31:08 +07: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 00:47:09 +07:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07: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 20:18:36 +07:00
|
|
|
xattrs = NULL;
|
2009-10-07 01:31:08 +07: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 12:01:19 +07:00
|
|
|
0, 0, &xattrs[numattr]);
|
2009-10-07 01:31:08 +07: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 00:47:09 +07:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07: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)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
dout("__get_required_blob_size c=%d names.size=%d vals.size=%d\n",
|
|
|
|
ci->i_xattrs.count, ci->i_xattrs.names_size,
|
|
|
|
ci->i_xattrs.vals_size);
|
|
|
|
|
|
|
|
if (name_size)
|
|
|
|
size += 4 + 4 + name_size + val_size;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If there are dirty xattrs, reencode xattrs into the prealloc_blob
|
|
|
|
* and swap into place.
|
|
|
|
*/
|
|
|
|
void __ceph_build_xattrs_blob(struct ceph_inode_info *ci)
|
|
|
|
{
|
|
|
|
struct rb_node *p;
|
|
|
|
struct ceph_inode_xattr *xattr = NULL;
|
|
|
|
void *dest;
|
|
|
|
|
|
|
|
dout("__build_xattrs_blob %p\n", &ci->vfs_inode);
|
|
|
|
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 03:17:17 +07:00
|
|
|
if (ci->i_xattrs.blob)
|
|
|
|
ceph_buffer_put(ci->i_xattrs.blob);
|
2009-10-07 01:31:08 +07:00
|
|
|
ci->i_xattrs.blob = ci->i_xattrs.prealloc_blob;
|
|
|
|
ci->i_xattrs.prealloc_blob = NULL;
|
|
|
|
ci->i_xattrs.dirty = false;
|
2010-08-23 05:03:56 +07:00
|
|
|
ci->i_xattrs.version++;
|
2009-10-07 01:31:08 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-11 14:18:03 +07:00
|
|
|
ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
|
2009-10-07 01:31:08 +07:00
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
int err;
|
|
|
|
struct ceph_inode_xattr *xattr;
|
2012-01-24 04:49:28 +07:00
|
|
|
struct ceph_vxattr *vxattr = NULL;
|
2009-10-07 01:31:08 +07:00
|
|
|
|
|
|
|
if (!ceph_is_valid_xattr(name))
|
|
|
|
return -ENODATA;
|
|
|
|
|
2013-01-21 13:00:58 +07:00
|
|
|
/* let's see if a virtual xattr was requested */
|
|
|
|
vxattr = ceph_match_vxattr(inode, name);
|
|
|
|
if (vxattr && !(vxattr->exists_cb && !vxattr->exists_cb(ci))) {
|
|
|
|
err = vxattr->getxattr_cb(ci, value, size);
|
2013-06-19 13:58:10 +07:00
|
|
|
return err;
|
2013-01-21 13:00:58 +07:00
|
|
|
}
|
|
|
|
|
2013-06-19 13:58:10 +07:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
|
|
|
dout("getxattr %p ver=%lld index_ver=%lld\n", inode,
|
|
|
|
ci->i_xattrs.version, ci->i_xattrs.index_version);
|
|
|
|
|
2014-09-16 20:46:17 +07:00
|
|
|
if (ci->i_xattrs.version == 0 ||
|
|
|
|
!__ceph_caps_issued_mask(ci, CEPH_CAP_XATTR_SHARED, 1)) {
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07:00
|
|
|
/* get xattrs from mds (if we don't already have them) */
|
2014-09-16 20:46:17 +07:00
|
|
|
err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR, true);
|
2009-10-07 01:31:08 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
2014-09-16 20:46:17 +07:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
err = __build_xattrs(inode);
|
|
|
|
if (err < 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
err = -ENODATA; /* == ENOATTR */
|
|
|
|
xattr = __get_xattr(ci, name);
|
2013-01-21 13:00:58 +07:00
|
|
|
if (!xattr)
|
2009-10-07 01:31:08 +07: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);
|
|
|
|
|
|
|
|
out:
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-11-11 14:18:03 +07:00
|
|
|
ssize_t ceph_getxattr(struct dentry *dentry, const char *name, void *value,
|
|
|
|
size_t size)
|
|
|
|
{
|
|
|
|
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
|
|
|
return generic_getxattr(dentry, name, value, size);
|
|
|
|
|
2015-03-18 05:25:59 +07:00
|
|
|
return __ceph_getxattr(d_inode(dentry), name, value, size);
|
2013-11-11 14:18:03 +07:00
|
|
|
}
|
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
|
|
|
|
{
|
2015-03-18 05:25:59 +07:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2009-10-07 01:31:08 +07:00
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
2012-01-24 04:49:28 +07:00
|
|
|
struct ceph_vxattr *vxattrs = ceph_inode_vxattrs(inode);
|
2009-10-07 01:31:08 +07:00
|
|
|
u32 vir_namelen = 0;
|
|
|
|
u32 namelen;
|
|
|
|
int err;
|
|
|
|
u32 len;
|
|
|
|
int i;
|
|
|
|
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07:00
|
|
|
dout("listxattr %p ver=%lld index_ver=%lld\n", inode,
|
|
|
|
ci->i_xattrs.version, ci->i_xattrs.index_version);
|
|
|
|
|
2014-09-16 20:46:17 +07:00
|
|
|
if (ci->i_xattrs.version == 0 ||
|
|
|
|
!__ceph_caps_issued_mask(ci, CEPH_CAP_XATTR_SHARED, 1)) {
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2014-09-16 20:46:17 +07:00
|
|
|
err = ceph_do_getattr(inode, CEPH_STAT_CAP_XATTR, true);
|
2009-10-07 01:31:08 +07:00
|
|
|
if (err)
|
|
|
|
return err;
|
2014-09-16 20:46:17 +07:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
err = __build_xattrs(inode);
|
|
|
|
if (err < 0)
|
|
|
|
goto out;
|
2012-01-24 04:49:28 +07:00
|
|
|
/*
|
|
|
|
* Start with virtual dir xattr names (if any) (including
|
|
|
|
* terminating '\0' characters for each).
|
|
|
|
*/
|
|
|
|
vir_namelen = ceph_vxattrs_name_size(vxattrs);
|
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
/* adding 1 byte per each variable due to the null termination */
|
2013-01-21 13:02:39 +07:00
|
|
|
namelen = ci->i_xattrs.names_size + ci->i_xattrs.count;
|
2009-10-07 01:31:08 +07:00
|
|
|
err = -ERANGE;
|
2013-01-21 13:02:39 +07:00
|
|
|
if (size && vir_namelen + namelen > size)
|
2009-10-07 01:31:08 +07:00
|
|
|
goto out;
|
|
|
|
|
2013-01-21 13:02:39 +07:00
|
|
|
err = namelen + vir_namelen;
|
2009-10-07 01:31:08 +07:00
|
|
|
if (size == 0)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
names = __copy_xattr_names(ci, names);
|
|
|
|
|
|
|
|
/* virtual xattr names, too */
|
2013-01-21 13:02:39 +07:00
|
|
|
err = namelen;
|
|
|
|
if (vxattrs) {
|
2009-10-07 01:31:08 +07:00
|
|
|
for (i = 0; vxattrs[i].name; i++) {
|
2013-01-21 13:02:39 +07:00
|
|
|
if (!vxattrs[i].hidden &&
|
|
|
|
!(vxattrs[i].exists_cb &&
|
|
|
|
!vxattrs[i].exists_cb(ci))) {
|
|
|
|
len = sprintf(names, "%s", vxattrs[i].name);
|
|
|
|
names += len + 1;
|
|
|
|
err += len + 1;
|
|
|
|
}
|
2009-10-07 01:31:08 +07:00
|
|
|
}
|
2013-01-21 13:02:39 +07:00
|
|
|
}
|
2009-10-07 01:31:08 +07:00
|
|
|
|
|
|
|
out:
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
const char *value, size_t size, int flags)
|
|
|
|
{
|
2010-04-07 05:14:15 +07:00
|
|
|
struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
|
2015-03-18 05:25:59 +07:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2009-10-07 01:31:08 +07:00
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
struct ceph_mds_request *req;
|
2010-04-07 05:14:15 +07:00
|
|
|
struct ceph_mds_client *mdsc = fsc->mdsc;
|
2014-09-16 18:15:28 +07:00
|
|
|
struct ceph_pagelist *pagelist = NULL;
|
2009-10-07 01:31:08 +07:00
|
|
|
int err;
|
2014-09-16 18:15:28 +07:00
|
|
|
|
2014-12-17 20:26:47 +07:00
|
|
|
if (size > 0) {
|
2014-09-16 18:15:28 +07:00
|
|
|
/* copy value into pagelist */
|
|
|
|
pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS);
|
|
|
|
if (!pagelist)
|
2009-10-07 01:31:08 +07:00
|
|
|
return -ENOMEM;
|
2014-09-16 18:15:28 +07:00
|
|
|
|
|
|
|
ceph_pagelist_init(pagelist);
|
|
|
|
err = ceph_pagelist_append(pagelist, value, size);
|
|
|
|
if (err)
|
|
|
|
goto out;
|
2014-12-17 20:26:47 +07:00
|
|
|
} else if (!value) {
|
2014-09-16 18:15:28 +07:00
|
|
|
flags |= CEPH_XATTR_REMOVE;
|
2009-10-07 01:31:08 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
dout("setxattr value=%.*s\n", (int)size, value);
|
|
|
|
|
|
|
|
/* do request */
|
|
|
|
req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_SETXATTR,
|
|
|
|
USE_AUTH_MDS);
|
2009-11-21 18:53:08 +07:00
|
|
|
if (IS_ERR(req)) {
|
|
|
|
err = PTR_ERR(req);
|
|
|
|
goto out;
|
|
|
|
}
|
2015-03-21 23:54:58 +07:00
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
req->r_args.setxattr.flags = cpu_to_le32(flags);
|
|
|
|
req->r_path2 = kstrdup(name, GFP_NOFS);
|
2015-03-21 23:54:58 +07:00
|
|
|
if (!req->r_path2) {
|
|
|
|
ceph_mdsc_put_request(req);
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2009-10-07 01:31:08 +07:00
|
|
|
|
2014-09-16 18:15:28 +07:00
|
|
|
req->r_pagelist = pagelist;
|
|
|
|
pagelist = NULL;
|
2009-10-07 01:31:08 +07:00
|
|
|
|
2015-03-21 23:54:58 +07:00
|
|
|
req->r_inode = inode;
|
|
|
|
ihold(inode);
|
|
|
|
req->r_num_caps = 1;
|
|
|
|
req->r_inode_drop = CEPH_CAP_XATTR_SHARED;
|
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
dout("xattr.ver (before): %lld\n", ci->i_xattrs.version);
|
2013-02-06 04:52:29 +07:00
|
|
|
err = ceph_mdsc_do_request(mdsc, NULL, req);
|
2009-10-07 01:31:08 +07:00
|
|
|
ceph_mdsc_put_request(req);
|
|
|
|
dout("xattr.ver (after): %lld\n", ci->i_xattrs.version);
|
|
|
|
|
|
|
|
out:
|
2014-09-16 18:15:28 +07:00
|
|
|
if (pagelist)
|
|
|
|
ceph_pagelist_release(pagelist);
|
2009-10-07 01:31:08 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-11-11 14:18:03 +07:00
|
|
|
int __ceph_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
const void *value, size_t size, int flags)
|
2009-10-07 01:31:08 +07:00
|
|
|
{
|
2015-03-18 05:25:59 +07:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2012-01-24 04:49:28 +07:00
|
|
|
struct ceph_vxattr *vxattr;
|
2009-10-07 01:31:08 +07:00
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
2012-01-24 04:49:28 +07:00
|
|
|
int issued;
|
2009-10-07 01:31:08 +07:00
|
|
|
int err;
|
2014-02-11 12:01:19 +07:00
|
|
|
int dirty = 0;
|
2009-10-07 01:31:08 +07: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;
|
|
|
|
|
|
|
|
if (!ceph_is_valid_xattr(name))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2012-01-24 04:49:27 +07:00
|
|
|
vxattr = ceph_match_vxattr(inode, name);
|
|
|
|
if (vxattr && vxattr->readonly)
|
|
|
|
return -EOPNOTSUPP;
|
2009-10-07 01:31:08 +07:00
|
|
|
|
2013-02-01 02:53:41 +07: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 01:31:08 +07:00
|
|
|
/* preallocate memory for xattr name, value, index node */
|
|
|
|
err = -ENOMEM;
|
2010-10-18 02:55:21 +07:00
|
|
|
newname = kmemdup(name, name_len + 1, GFP_NOFS);
|
2009-10-07 01:31:08 +07:00
|
|
|
if (!newname)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (val_len) {
|
2012-01-24 04:49:27 +07:00
|
|
|
newval = kmemdup(value, val_len, GFP_NOFS);
|
2009-10-07 01:31:08 +07:00
|
|
|
if (!newval)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
xattr = kmalloc(sizeof(struct ceph_inode_xattr), GFP_NOFS);
|
|
|
|
if (!xattr)
|
|
|
|
goto out;
|
|
|
|
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07:00
|
|
|
retry:
|
|
|
|
issued = __ceph_caps_issued(ci, NULL);
|
2012-01-24 04:49:28 +07:00
|
|
|
dout("setxattr %p issued %s\n", inode, ceph_cap_string(issued));
|
2014-09-16 20:46:17 +07:00
|
|
|
if (ci->i_xattrs.version == 0 || !(issued & CEPH_CAP_XATTR_EXCL))
|
2009-10-07 01:31:08 +07:00
|
|
|
goto do_sync;
|
|
|
|
__build_xattrs(inode);
|
|
|
|
|
|
|
|
required_blob_size = __get_required_blob_size(ci, name_len, val_len);
|
|
|
|
|
|
|
|
if (!ci->i_xattrs.prealloc_blob ||
|
|
|
|
required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
|
2012-01-24 04:49:28 +07:00
|
|
|
struct ceph_buffer *blob;
|
2009-10-07 01:31:08 +07:00
|
|
|
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2009-10-07 01:31:08 +07:00
|
|
|
dout(" preaallocating new blob size=%d\n", required_blob_size);
|
2009-12-08 03:17:17 +07:00
|
|
|
blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
|
2009-10-07 01:31:08 +07:00
|
|
|
if (!blob)
|
|
|
|
goto out;
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2009-12-08 03:17:17 +07:00
|
|
|
if (ci->i_xattrs.prealloc_blob)
|
|
|
|
ceph_buffer_put(ci->i_xattrs.prealloc_blob);
|
2009-10-07 01:31:08 +07:00
|
|
|
ci->i_xattrs.prealloc_blob = blob;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2014-02-11 12:04:19 +07:00
|
|
|
err = __set_xattr(ci, newname, name_len, newval, val_len,
|
|
|
|
flags, value ? 1 : -1, &xattr);
|
2012-01-24 04:49:28 +07:00
|
|
|
|
2014-02-11 12:01:19 +07:00
|
|
|
if (!err) {
|
|
|
|
dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
|
|
|
|
ci->i_xattrs.dirty = true;
|
|
|
|
inode->i_ctime = CURRENT_TIME;
|
|
|
|
}
|
2012-01-24 04:49:28 +07:00
|
|
|
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2011-05-05 01:33:47 +07:00
|
|
|
if (dirty)
|
|
|
|
__mark_inode_dirty(inode, dirty);
|
2009-10-07 01:31:08 +07:00
|
|
|
return err;
|
|
|
|
|
|
|
|
do_sync:
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2013-02-01 02:53:41 +07:00
|
|
|
do_sync_unlocked:
|
2009-10-07 01:31:08 +07:00
|
|
|
err = ceph_sync_setxattr(dentry, name, value, size, flags);
|
|
|
|
out:
|
|
|
|
kfree(newname);
|
|
|
|
kfree(newval);
|
|
|
|
kfree(xattr);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-11-11 14:18:03 +07:00
|
|
|
int ceph_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
const void *value, size_t size, int flags)
|
|
|
|
{
|
2015-03-18 05:25:59 +07:00
|
|
|
if (ceph_snap(d_inode(dentry)) != CEPH_NOSNAP)
|
2013-11-11 14:18:03 +07:00
|
|
|
return -EROFS;
|
|
|
|
|
|
|
|
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
|
|
|
return generic_setxattr(dentry, name, value, size, flags);
|
|
|
|
|
2014-12-17 20:26:47 +07:00
|
|
|
if (size == 0)
|
|
|
|
value = ""; /* empty EA, do not remove */
|
|
|
|
|
2013-11-11 14:18:03 +07:00
|
|
|
return __ceph_setxattr(dentry, name, value, size, flags);
|
|
|
|
}
|
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
static int ceph_send_removexattr(struct dentry *dentry, const char *name)
|
|
|
|
{
|
2010-04-07 05:14:15 +07:00
|
|
|
struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
|
|
|
|
struct ceph_mds_client *mdsc = fsc->mdsc;
|
2015-03-18 05:25:59 +07:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2009-10-07 01:31:08 +07:00
|
|
|
struct ceph_mds_request *req;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
req = ceph_mdsc_create_request(mdsc, CEPH_MDS_OP_RMXATTR,
|
|
|
|
USE_AUTH_MDS);
|
|
|
|
if (IS_ERR(req))
|
|
|
|
return PTR_ERR(req);
|
2015-03-21 23:54:58 +07:00
|
|
|
req->r_path2 = kstrdup(name, GFP_NOFS);
|
|
|
|
if (!req->r_path2)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-05-27 23:24:26 +07:00
|
|
|
req->r_inode = inode;
|
|
|
|
ihold(inode);
|
2009-10-07 01:31:08 +07:00
|
|
|
req->r_num_caps = 1;
|
2015-03-21 23:54:58 +07:00
|
|
|
req->r_inode_drop = CEPH_CAP_XATTR_SHARED;
|
2013-02-06 04:52:29 +07:00
|
|
|
err = ceph_mdsc_do_request(mdsc, NULL, req);
|
2009-10-07 01:31:08 +07:00
|
|
|
ceph_mdsc_put_request(req);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-11-11 14:18:03 +07:00
|
|
|
int __ceph_removexattr(struct dentry *dentry, const char *name)
|
2009-10-07 01:31:08 +07:00
|
|
|
{
|
2015-03-18 05:25:59 +07:00
|
|
|
struct inode *inode = d_inode(dentry);
|
2012-01-24 04:49:28 +07:00
|
|
|
struct ceph_vxattr *vxattr;
|
2009-10-07 01:31:08 +07:00
|
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
int issued;
|
|
|
|
int err;
|
2012-01-12 08:41:01 +07:00
|
|
|
int required_blob_size;
|
2011-05-05 01:33:47 +07:00
|
|
|
int dirty;
|
2009-10-07 01:31:08 +07:00
|
|
|
|
|
|
|
if (!ceph_is_valid_xattr(name))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2012-01-24 04:49:27 +07:00
|
|
|
vxattr = ceph_match_vxattr(inode, name);
|
|
|
|
if (vxattr && vxattr->readonly)
|
|
|
|
return -EOPNOTSUPP;
|
2009-10-07 01:31:08 +07:00
|
|
|
|
2013-01-21 12:55:30 +07:00
|
|
|
/* pass any unhandled ceph.* xattrs through to the MDS */
|
|
|
|
if (!strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN))
|
|
|
|
goto do_sync_unlocked;
|
|
|
|
|
2012-01-12 08:41:01 +07:00
|
|
|
err = -ENOMEM;
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_lock(&ci->i_ceph_lock);
|
2012-01-12 08:41:01 +07:00
|
|
|
retry:
|
2009-10-07 01:31:08 +07:00
|
|
|
issued = __ceph_caps_issued(ci, NULL);
|
|
|
|
dout("removexattr %p issued %s\n", inode, ceph_cap_string(issued));
|
|
|
|
|
2014-09-16 20:46:17 +07:00
|
|
|
if (ci->i_xattrs.version == 0 || !(issued & CEPH_CAP_XATTR_EXCL))
|
2009-10-07 01:31:08 +07:00
|
|
|
goto do_sync;
|
2012-01-24 04:49:28 +07:00
|
|
|
__build_xattrs(inode);
|
2009-10-07 01:31:08 +07:00
|
|
|
|
2012-01-12 08:41:01 +07:00
|
|
|
required_blob_size = __get_required_blob_size(ci, 0, 0);
|
|
|
|
|
|
|
|
if (!ci->i_xattrs.prealloc_blob ||
|
|
|
|
required_blob_size > ci->i_xattrs.prealloc_blob->alloc_len) {
|
|
|
|
struct ceph_buffer *blob;
|
|
|
|
|
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
|
|
|
dout(" preaallocating new blob size=%d\n", required_blob_size);
|
|
|
|
blob = ceph_buffer_new(required_blob_size, GFP_NOFS);
|
|
|
|
if (!blob)
|
|
|
|
goto out;
|
|
|
|
spin_lock(&ci->i_ceph_lock);
|
|
|
|
if (ci->i_xattrs.prealloc_blob)
|
|
|
|
ceph_buffer_put(ci->i_xattrs.prealloc_blob);
|
|
|
|
ci->i_xattrs.prealloc_blob = blob;
|
|
|
|
goto retry;
|
|
|
|
}
|
|
|
|
|
2009-10-07 01:31:08 +07:00
|
|
|
err = __remove_xattr_by_name(ceph_inode(inode), name);
|
2012-01-24 04:49:28 +07:00
|
|
|
|
2011-05-05 01:33:47 +07:00
|
|
|
dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL);
|
2009-10-07 01:31:08 +07:00
|
|
|
ci->i_xattrs.dirty = true;
|
|
|
|
inode->i_ctime = CURRENT_TIME;
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2011-05-05 01:33:47 +07:00
|
|
|
if (dirty)
|
|
|
|
__mark_inode_dirty(inode, dirty);
|
2009-10-07 01:31:08 +07:00
|
|
|
return err;
|
|
|
|
do_sync:
|
2011-12-01 00:47:09 +07:00
|
|
|
spin_unlock(&ci->i_ceph_lock);
|
2013-01-21 12:55:30 +07:00
|
|
|
do_sync_unlocked:
|
2009-10-07 01:31:08 +07:00
|
|
|
err = ceph_send_removexattr(dentry, name);
|
2012-01-12 08:41:01 +07:00
|
|
|
out:
|
2009-10-07 01:31:08 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-11-11 14:18:03 +07:00
|
|
|
int ceph_removexattr(struct dentry *dentry, const char *name)
|
|
|
|
{
|
2015-03-18 05:25:59 +07:00
|
|
|
if (ceph_snap(d_inode(dentry)) != CEPH_NOSNAP)
|
2013-11-11 14:18:03 +07:00
|
|
|
return -EROFS;
|
|
|
|
|
|
|
|
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
|
|
|
return generic_removexattr(dentry, name);
|
|
|
|
|
|
|
|
return __ceph_removexattr(dentry, name);
|
|
|
|
}
|