|
@@ -16,6 +16,8 @@
|
|
static int __remove_xattr(struct ceph_inode_info *ci,
|
|
static int __remove_xattr(struct ceph_inode_info *ci,
|
|
struct ceph_inode_xattr *xattr);
|
|
struct ceph_inode_xattr *xattr);
|
|
|
|
|
|
|
|
+const struct xattr_handler ceph_other_xattr_handler;
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* List of handlers for synthetic system.* attributes. Other
|
|
* List of handlers for synthetic system.* attributes. Other
|
|
* attributes are handled directly.
|
|
* attributes are handled directly.
|
|
@@ -25,6 +27,7 @@ const struct xattr_handler *ceph_xattr_handlers[] = {
|
|
&posix_acl_access_xattr_handler,
|
|
&posix_acl_access_xattr_handler,
|
|
&posix_acl_default_xattr_handler,
|
|
&posix_acl_default_xattr_handler,
|
|
#endif
|
|
#endif
|
|
|
|
+ &ceph_other_xattr_handler,
|
|
NULL,
|
|
NULL,
|
|
};
|
|
};
|
|
|
|
|
|
@@ -33,7 +36,6 @@ static bool ceph_is_valid_xattr(const char *name)
|
|
return !strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN) ||
|
|
return !strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN) ||
|
|
!strncmp(name, XATTR_SECURITY_PREFIX,
|
|
!strncmp(name, XATTR_SECURITY_PREFIX,
|
|
XATTR_SECURITY_PREFIX_LEN) ||
|
|
XATTR_SECURITY_PREFIX_LEN) ||
|
|
- !strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) ||
|
|
|
|
!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) ||
|
|
!strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) ||
|
|
!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
|
|
!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN);
|
|
}
|
|
}
|
|
@@ -496,19 +498,6 @@ static int __remove_xattr(struct ceph_inode_info *ci,
|
|
return 0;
|
|
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,
|
|
static char *__copy_xattr_names(struct ceph_inode_info *ci,
|
|
char *dest)
|
|
char *dest)
|
|
{
|
|
{
|
|
@@ -740,9 +729,6 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
|
|
int req_mask;
|
|
int req_mask;
|
|
int err;
|
|
int err;
|
|
|
|
|
|
- if (!ceph_is_valid_xattr(name))
|
|
|
|
- return -ENODATA;
|
|
|
|
-
|
|
|
|
/* let's see if a virtual xattr was requested */
|
|
/* let's see if a virtual xattr was requested */
|
|
vxattr = ceph_match_vxattr(inode, name);
|
|
vxattr = ceph_match_vxattr(inode, name);
|
|
if (vxattr) {
|
|
if (vxattr) {
|
|
@@ -804,15 +790,6 @@ out:
|
|
return err;
|
|
return err;
|
|
}
|
|
}
|
|
|
|
|
|
-ssize_t ceph_getxattr(struct dentry *dentry, struct inode *inode,
|
|
|
|
- const char *name, void *value, size_t size)
|
|
|
|
-{
|
|
|
|
- if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
|
|
|
- return generic_getxattr(dentry, inode, name, value, size);
|
|
|
|
-
|
|
|
|
- return __ceph_getxattr(inode, name, value, size);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
|
|
ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
|
|
{
|
|
{
|
|
struct inode *inode = d_inode(dentry);
|
|
struct inode *inode = d_inode(dentry);
|
|
@@ -877,11 +854,10 @@ out:
|
|
return err;
|
|
return err;
|
|
}
|
|
}
|
|
|
|
|
|
-static int ceph_sync_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
|
|
+static int ceph_sync_setxattr(struct inode *inode, const char *name,
|
|
const char *value, size_t size, int flags)
|
|
const char *value, size_t size, int flags)
|
|
{
|
|
{
|
|
- struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
|
|
|
|
- struct inode *inode = d_inode(dentry);
|
|
|
|
|
|
+ struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
struct ceph_mds_request *req;
|
|
struct ceph_mds_request *req;
|
|
struct ceph_mds_client *mdsc = fsc->mdsc;
|
|
struct ceph_mds_client *mdsc = fsc->mdsc;
|
|
@@ -939,13 +915,12 @@ out:
|
|
return err;
|
|
return err;
|
|
}
|
|
}
|
|
|
|
|
|
-int __ceph_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
|
|
+int __ceph_setxattr(struct inode *inode, const char *name,
|
|
const void *value, size_t size, int flags)
|
|
const void *value, size_t size, int flags)
|
|
{
|
|
{
|
|
- struct inode *inode = d_inode(dentry);
|
|
|
|
struct ceph_vxattr *vxattr;
|
|
struct ceph_vxattr *vxattr;
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
struct ceph_inode_info *ci = ceph_inode(inode);
|
|
- struct ceph_mds_client *mdsc = ceph_sb_to_client(dentry->d_sb)->mdsc;
|
|
|
|
|
|
+ struct ceph_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
|
|
struct ceph_cap_flush *prealloc_cf = NULL;
|
|
struct ceph_cap_flush *prealloc_cf = NULL;
|
|
int issued;
|
|
int issued;
|
|
int err;
|
|
int err;
|
|
@@ -958,8 +933,8 @@ int __ceph_setxattr(struct dentry *dentry, const char *name,
|
|
int required_blob_size;
|
|
int required_blob_size;
|
|
bool lock_snap_rwsem = false;
|
|
bool lock_snap_rwsem = false;
|
|
|
|
|
|
- if (!ceph_is_valid_xattr(name))
|
|
|
|
- return -EOPNOTSUPP;
|
|
|
|
|
|
+ if (ceph_snap(inode) != CEPH_NOSNAP)
|
|
|
|
+ return -EROFS;
|
|
|
|
|
|
vxattr = ceph_match_vxattr(inode, name);
|
|
vxattr = ceph_match_vxattr(inode, name);
|
|
if (vxattr && vxattr->readonly)
|
|
if (vxattr && vxattr->readonly)
|
|
@@ -1056,7 +1031,7 @@ do_sync_unlocked:
|
|
"during filling trace\n", inode);
|
|
"during filling trace\n", inode);
|
|
err = -EBUSY;
|
|
err = -EBUSY;
|
|
} else {
|
|
} else {
|
|
- err = ceph_sync_setxattr(dentry, name, value, size, flags);
|
|
|
|
|
|
+ err = ceph_sync_setxattr(inode, name, value, size, flags);
|
|
}
|
|
}
|
|
out:
|
|
out:
|
|
ceph_free_cap_flush(prealloc_cf);
|
|
ceph_free_cap_flush(prealloc_cf);
|
|
@@ -1066,146 +1041,29 @@ out:
|
|
return err;
|
|
return err;
|
|
}
|
|
}
|
|
|
|
|
|
-int ceph_setxattr(struct dentry *dentry, const char *name,
|
|
|
|
- const void *value, size_t size, int flags)
|
|
|
|
-{
|
|
|
|
- if (ceph_snap(d_inode(dentry)) != CEPH_NOSNAP)
|
|
|
|
- return -EROFS;
|
|
|
|
-
|
|
|
|
- if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
|
|
|
- return generic_setxattr(dentry, name, value, size, flags);
|
|
|
|
-
|
|
|
|
- if (size == 0)
|
|
|
|
- value = ""; /* empty EA, do not remove */
|
|
|
|
-
|
|
|
|
- return __ceph_setxattr(dentry, name, value, size, flags);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static int ceph_send_removexattr(struct dentry *dentry, const char *name)
|
|
|
|
|
|
+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)
|
|
{
|
|
{
|
|
- struct ceph_fs_client *fsc = ceph_sb_to_client(dentry->d_sb);
|
|
|
|
- struct ceph_mds_client *mdsc = fsc->mdsc;
|
|
|
|
- struct inode *inode = d_inode(dentry);
|
|
|
|
- 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);
|
|
|
|
- req->r_path2 = kstrdup(name, GFP_NOFS);
|
|
|
|
- if (!req->r_path2)
|
|
|
|
- return -ENOMEM;
|
|
|
|
-
|
|
|
|
- req->r_inode = inode;
|
|
|
|
- ihold(inode);
|
|
|
|
- req->r_num_caps = 1;
|
|
|
|
- req->r_inode_drop = CEPH_CAP_XATTR_SHARED;
|
|
|
|
- err = ceph_mdsc_do_request(mdsc, NULL, req);
|
|
|
|
- ceph_mdsc_put_request(req);
|
|
|
|
- return err;
|
|
|
|
|
|
+ if (!ceph_is_valid_xattr(name))
|
|
|
|
+ return -EOPNOTSUPP;
|
|
|
|
+ return __ceph_getxattr(inode, name, value, size);
|
|
}
|
|
}
|
|
|
|
|
|
-int __ceph_removexattr(struct dentry *dentry, const char *name)
|
|
|
|
|
|
+static int ceph_set_xattr_handler(const struct xattr_handler *handler,
|
|
|
|
+ struct dentry *dentry, const char *name,
|
|
|
|
+ const void *value, size_t size, int flags)
|
|
{
|
|
{
|
|
- struct inode *inode = d_inode(dentry);
|
|
|
|
- struct ceph_vxattr *vxattr;
|
|
|
|
- struct ceph_inode_info *ci = ceph_inode(inode);
|
|
|
|
- struct ceph_mds_client *mdsc = ceph_sb_to_client(dentry->d_sb)->mdsc;
|
|
|
|
- struct ceph_cap_flush *prealloc_cf = NULL;
|
|
|
|
- int issued;
|
|
|
|
- int err;
|
|
|
|
- int required_blob_size;
|
|
|
|
- int dirty;
|
|
|
|
- bool lock_snap_rwsem = false;
|
|
|
|
-
|
|
|
|
if (!ceph_is_valid_xattr(name))
|
|
if (!ceph_is_valid_xattr(name))
|
|
return -EOPNOTSUPP;
|
|
return -EOPNOTSUPP;
|
|
-
|
|
|
|
- vxattr = ceph_match_vxattr(inode, name);
|
|
|
|
- if (vxattr && vxattr->readonly)
|
|
|
|
- return -EOPNOTSUPP;
|
|
|
|
-
|
|
|
|
- /* pass any unhandled ceph.* xattrs through to the MDS */
|
|
|
|
- if (!strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN))
|
|
|
|
- goto do_sync_unlocked;
|
|
|
|
-
|
|
|
|
- prealloc_cf = ceph_alloc_cap_flush();
|
|
|
|
- if (!prealloc_cf)
|
|
|
|
- return -ENOMEM;
|
|
|
|
-
|
|
|
|
- err = -ENOMEM;
|
|
|
|
- spin_lock(&ci->i_ceph_lock);
|
|
|
|
-retry:
|
|
|
|
- issued = __ceph_caps_issued(ci, NULL);
|
|
|
|
- if (ci->i_xattrs.version == 0 || !(issued & CEPH_CAP_XATTR_EXCL))
|
|
|
|
- goto do_sync;
|
|
|
|
-
|
|
|
|
- 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;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- dout("removexattr %p issued %s\n", inode, ceph_cap_string(issued));
|
|
|
|
-
|
|
|
|
- __build_xattrs(inode);
|
|
|
|
-
|
|
|
|
- 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 do_sync_unlocked;
|
|
|
|
- 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;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- err = __remove_xattr_by_name(ceph_inode(inode), name);
|
|
|
|
-
|
|
|
|
- dirty = __ceph_mark_dirty_caps(ci, CEPH_CAP_XATTR_EXCL,
|
|
|
|
- &prealloc_cf);
|
|
|
|
- ci->i_xattrs.dirty = true;
|
|
|
|
- inode->i_ctime = current_fs_time(inode->i_sb);
|
|
|
|
- spin_unlock(&ci->i_ceph_lock);
|
|
|
|
- if (lock_snap_rwsem)
|
|
|
|
- up_read(&mdsc->snap_rwsem);
|
|
|
|
- if (dirty)
|
|
|
|
- __mark_inode_dirty(inode, dirty);
|
|
|
|
- ceph_free_cap_flush(prealloc_cf);
|
|
|
|
- return err;
|
|
|
|
-do_sync:
|
|
|
|
- spin_unlock(&ci->i_ceph_lock);
|
|
|
|
-do_sync_unlocked:
|
|
|
|
- if (lock_snap_rwsem)
|
|
|
|
- up_read(&mdsc->snap_rwsem);
|
|
|
|
- ceph_free_cap_flush(prealloc_cf);
|
|
|
|
- err = ceph_send_removexattr(dentry, name);
|
|
|
|
- return err;
|
|
|
|
|
|
+ return __ceph_setxattr(d_inode(dentry), name, value, size, flags);
|
|
}
|
|
}
|
|
|
|
|
|
-int ceph_removexattr(struct dentry *dentry, const char *name)
|
|
|
|
-{
|
|
|
|
- if (ceph_snap(d_inode(dentry)) != CEPH_NOSNAP)
|
|
|
|
- return -EROFS;
|
|
|
|
-
|
|
|
|
- if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
|
|
|
- return generic_removexattr(dentry, name);
|
|
|
|
-
|
|
|
|
- return __ceph_removexattr(dentry, name);
|
|
|
|
-}
|
|
|
|
|
|
+const struct xattr_handler ceph_other_xattr_handler = {
|
|
|
|
+ .prefix = "", /* match any name => handlers called with full name */
|
|
|
|
+ .get = ceph_get_xattr_handler,
|
|
|
|
+ .set = ceph_set_xattr_handler,
|
|
|
|
+};
|
|
|
|
|
|
#ifdef CONFIG_SECURITY
|
|
#ifdef CONFIG_SECURITY
|
|
bool ceph_security_xattr_wanted(struct inode *in)
|
|
bool ceph_security_xattr_wanted(struct inode *in)
|