mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-11-26 03:24:10 +08:00
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull remaining vfs xattr work from Al Viro: "The rest of work.xattr (non-cifs conversions)" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: btrfs: Switch to generic xattr handlers ubifs: Switch to generic xattr handlers jfs: Switch to generic xattr handlers jfs: Clean up xattr name mapping gfs2: Switch to generic xattr handlers ceph: kill __ceph_removexattr() ceph: Switch to generic xattr handlers ceph: Get rid of d_find_alias in ceph_set_acl
This commit is contained in:
commit
ba5a2655c2
@ -10160,10 +10160,10 @@ static const struct inode_operations btrfs_dir_inode_operations = {
|
||||
.symlink = btrfs_symlink,
|
||||
.setattr = btrfs_setattr,
|
||||
.mknod = btrfs_mknod,
|
||||
.setxattr = btrfs_setxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = btrfs_listxattr,
|
||||
.removexattr = btrfs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.permission = btrfs_permission,
|
||||
.get_acl = btrfs_get_acl,
|
||||
.set_acl = btrfs_set_acl,
|
||||
@ -10237,10 +10237,10 @@ static const struct address_space_operations btrfs_symlink_aops = {
|
||||
static const struct inode_operations btrfs_file_inode_operations = {
|
||||
.getattr = btrfs_getattr,
|
||||
.setattr = btrfs_setattr,
|
||||
.setxattr = btrfs_setxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = btrfs_listxattr,
|
||||
.removexattr = btrfs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.permission = btrfs_permission,
|
||||
.fiemap = btrfs_fiemap,
|
||||
.get_acl = btrfs_get_acl,
|
||||
@ -10251,10 +10251,10 @@ static const struct inode_operations btrfs_special_inode_operations = {
|
||||
.getattr = btrfs_getattr,
|
||||
.setattr = btrfs_setattr,
|
||||
.permission = btrfs_permission,
|
||||
.setxattr = btrfs_setxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = btrfs_listxattr,
|
||||
.removexattr = btrfs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.get_acl = btrfs_get_acl,
|
||||
.set_acl = btrfs_set_acl,
|
||||
.update_time = btrfs_update_time,
|
||||
@ -10265,10 +10265,10 @@ static const struct inode_operations btrfs_symlink_inode_operations = {
|
||||
.getattr = btrfs_getattr,
|
||||
.setattr = btrfs_setattr,
|
||||
.permission = btrfs_permission,
|
||||
.setxattr = btrfs_setxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = btrfs_listxattr,
|
||||
.removexattr = btrfs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.update_time = btrfs_update_time,
|
||||
};
|
||||
|
||||
|
@ -237,6 +237,9 @@ int __btrfs_setxattr(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_root *root = BTRFS_I(inode)->root;
|
||||
int ret;
|
||||
|
||||
if (btrfs_root_readonly(root))
|
||||
return -EROFS;
|
||||
|
||||
if (trans)
|
||||
return do_setxattr(trans, inode, name, value, size, flags);
|
||||
|
||||
@ -432,25 +435,6 @@ const struct xattr_handler *btrfs_xattr_handlers[] = {
|
||||
NULL,
|
||||
};
|
||||
|
||||
int btrfs_setxattr(struct dentry *dentry, const char *name, const void *value,
|
||||
size_t size, int flags)
|
||||
{
|
||||
struct btrfs_root *root = BTRFS_I(d_inode(dentry))->root;
|
||||
|
||||
if (btrfs_root_readonly(root))
|
||||
return -EROFS;
|
||||
return generic_setxattr(dentry, name, value, size, flags);
|
||||
}
|
||||
|
||||
int btrfs_removexattr(struct dentry *dentry, const char *name)
|
||||
{
|
||||
struct btrfs_root *root = BTRFS_I(d_inode(dentry))->root;
|
||||
|
||||
if (btrfs_root_readonly(root))
|
||||
return -EROFS;
|
||||
return generic_removexattr(dentry, name);
|
||||
}
|
||||
|
||||
static int btrfs_initxattrs(struct inode *inode,
|
||||
const struct xattr *xattr_array, void *fs_info)
|
||||
{
|
||||
|
@ -28,9 +28,6 @@ extern ssize_t __btrfs_getxattr(struct inode *inode, const char *name,
|
||||
extern int __btrfs_setxattr(struct btrfs_trans_handle *trans,
|
||||
struct inode *inode, const char *name,
|
||||
const void *value, size_t size, int flags);
|
||||
extern int btrfs_setxattr(struct dentry *dentry, const char *name,
|
||||
const void *value, size_t size, int flags);
|
||||
extern int btrfs_removexattr(struct dentry *dentry, const char *name);
|
||||
|
||||
extern int btrfs_xattr_security_init(struct btrfs_trans_handle *trans,
|
||||
struct inode *inode, struct inode *dir,
|
||||
|
@ -90,7 +90,6 @@ int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
char *value = NULL;
|
||||
struct iattr newattrs;
|
||||
umode_t new_mode = inode->i_mode, old_mode = inode->i_mode;
|
||||
struct dentry *dentry;
|
||||
|
||||
switch (type) {
|
||||
case ACL_TYPE_ACCESS:
|
||||
@ -128,29 +127,26 @@ int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
dentry = d_find_alias(inode);
|
||||
if (new_mode != old_mode) {
|
||||
newattrs.ia_mode = new_mode;
|
||||
newattrs.ia_valid = ATTR_MODE;
|
||||
ret = ceph_setattr(dentry, &newattrs);
|
||||
ret = __ceph_setattr(inode, &newattrs);
|
||||
if (ret)
|
||||
goto out_dput;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
ret = __ceph_setxattr(dentry, name, value, size, 0);
|
||||
ret = __ceph_setxattr(inode, name, value, size, 0);
|
||||
if (ret) {
|
||||
if (new_mode != old_mode) {
|
||||
newattrs.ia_mode = old_mode;
|
||||
newattrs.ia_valid = ATTR_MODE;
|
||||
ceph_setattr(dentry, &newattrs);
|
||||
__ceph_setattr(inode, &newattrs);
|
||||
}
|
||||
goto out_dput;
|
||||
goto out_free;
|
||||
}
|
||||
|
||||
ceph_set_cached_acl(inode, type, acl);
|
||||
|
||||
out_dput:
|
||||
dput(dentry);
|
||||
out_free:
|
||||
kfree(value);
|
||||
out:
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <linux/namei.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/sched.h>
|
||||
#include <linux/xattr.h>
|
||||
|
||||
#include "super.h"
|
||||
#include "mds_client.h"
|
||||
@ -1342,10 +1343,10 @@ const struct inode_operations ceph_dir_iops = {
|
||||
.permission = ceph_permission,
|
||||
.getattr = ceph_getattr,
|
||||
.setattr = ceph_setattr,
|
||||
.setxattr = ceph_setxattr,
|
||||
.getxattr = ceph_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = ceph_listxattr,
|
||||
.removexattr = ceph_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.get_acl = ceph_get_acl,
|
||||
.set_acl = ceph_set_acl,
|
||||
.mknod = ceph_mknod,
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/writeback.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/xattr.h>
|
||||
#include <linux/posix_acl.h>
|
||||
#include <linux/random.h>
|
||||
|
||||
@ -92,10 +93,10 @@ const struct inode_operations ceph_file_iops = {
|
||||
.permission = ceph_permission,
|
||||
.setattr = ceph_setattr,
|
||||
.getattr = ceph_getattr,
|
||||
.setxattr = ceph_setxattr,
|
||||
.getxattr = ceph_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = ceph_listxattr,
|
||||
.removexattr = ceph_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.get_acl = ceph_get_acl,
|
||||
.set_acl = ceph_set_acl,
|
||||
};
|
||||
@ -1770,22 +1771,18 @@ static const struct inode_operations ceph_symlink_iops = {
|
||||
.get_link = simple_get_link,
|
||||
.setattr = ceph_setattr,
|
||||
.getattr = ceph_getattr,
|
||||
.setxattr = ceph_setxattr,
|
||||
.getxattr = ceph_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = ceph_listxattr,
|
||||
.removexattr = ceph_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
};
|
||||
|
||||
/*
|
||||
* setattr
|
||||
*/
|
||||
int ceph_setattr(struct dentry *dentry, struct iattr *attr)
|
||||
int __ceph_setattr(struct inode *inode, struct iattr *attr)
|
||||
{
|
||||
struct inode *inode = d_inode(dentry);
|
||||
struct ceph_inode_info *ci = ceph_inode(inode);
|
||||
const unsigned int ia_valid = attr->ia_valid;
|
||||
struct ceph_mds_request *req;
|
||||
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;
|
||||
int issued;
|
||||
int release = 0, dirtied = 0;
|
||||
@ -2009,6 +2006,14 @@ out_put:
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* setattr
|
||||
*/
|
||||
int ceph_setattr(struct dentry *dentry, struct iattr *attr)
|
||||
{
|
||||
return __ceph_setattr(d_inode(dentry), attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* Verify that we have a lease on the given mask. If not,
|
||||
* do a getattr against an mds.
|
||||
|
@ -785,19 +785,15 @@ static inline int ceph_do_getattr(struct inode *inode, int mask, bool force)
|
||||
return __ceph_do_getattr(inode, NULL, mask, force);
|
||||
}
|
||||
extern int ceph_permission(struct inode *inode, int mask);
|
||||
extern int __ceph_setattr(struct inode *inode, struct iattr *attr);
|
||||
extern int ceph_setattr(struct dentry *dentry, struct iattr *attr);
|
||||
extern int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
||||
struct kstat *stat);
|
||||
|
||||
/* xattr.c */
|
||||
extern int ceph_setxattr(struct dentry *, const char *, const void *,
|
||||
size_t, int);
|
||||
int __ceph_setxattr(struct dentry *, const char *, const void *, size_t, int);
|
||||
int __ceph_setxattr(struct inode *, const char *, const void *, size_t, int);
|
||||
ssize_t __ceph_getxattr(struct inode *, const char *, void *, size_t);
|
||||
int __ceph_removexattr(struct dentry *, const char *);
|
||||
extern ssize_t ceph_getxattr(struct dentry *, struct inode *, const char *, void *, size_t);
|
||||
extern ssize_t ceph_listxattr(struct dentry *, char *, size_t);
|
||||
extern int ceph_removexattr(struct dentry *, const char *);
|
||||
extern void __ceph_build_xattrs_blob(struct ceph_inode_info *ci);
|
||||
extern void __ceph_destroy_xattrs(struct ceph_inode_info *ci);
|
||||
extern void __init ceph_xattr_init(void);
|
||||
|
194
fs/ceph/xattr.c
194
fs/ceph/xattr.c
@ -16,6 +16,8 @@
|
||||
static int __remove_xattr(struct ceph_inode_info *ci,
|
||||
struct ceph_inode_xattr *xattr);
|
||||
|
||||
const struct xattr_handler ceph_other_xattr_handler;
|
||||
|
||||
/*
|
||||
* List of handlers for synthetic system.* attributes. Other
|
||||
* attributes are handled directly.
|
||||
@ -25,6 +27,7 @@ const struct xattr_handler *ceph_xattr_handlers[] = {
|
||||
&posix_acl_access_xattr_handler,
|
||||
&posix_acl_default_xattr_handler,
|
||||
#endif
|
||||
&ceph_other_xattr_handler,
|
||||
NULL,
|
||||
};
|
||||
|
||||
@ -33,7 +36,6 @@ static bool ceph_is_valid_xattr(const char *name)
|
||||
return !strncmp(name, XATTR_CEPH_PREFIX, XATTR_CEPH_PREFIX_LEN) ||
|
||||
!strncmp(name, XATTR_SECURITY_PREFIX,
|
||||
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_USER_PREFIX, XATTR_USER_PREFIX_LEN);
|
||||
}
|
||||
@ -496,19 +498,6 @@ static int __remove_xattr(struct ceph_inode_info *ci,
|
||||
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)
|
||||
{
|
||||
@ -740,9 +729,6 @@ ssize_t __ceph_getxattr(struct inode *inode, const char *name, void *value,
|
||||
int req_mask;
|
||||
int err;
|
||||
|
||||
if (!ceph_is_valid_xattr(name))
|
||||
return -ENODATA;
|
||||
|
||||
/* let's see if a virtual xattr was requested */
|
||||
vxattr = ceph_match_vxattr(inode, name);
|
||||
if (vxattr) {
|
||||
@ -804,15 +790,6 @@ out:
|
||||
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)
|
||||
{
|
||||
struct inode *inode = d_inode(dentry);
|
||||
@ -877,11 +854,10 @@ out:
|
||||
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)
|
||||
{
|
||||
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_mds_request *req;
|
||||
struct ceph_mds_client *mdsc = fsc->mdsc;
|
||||
@ -939,13 +915,12 @@ out:
|
||||
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)
|
||||
{
|
||||
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_mds_client *mdsc = ceph_sb_to_client(inode->i_sb)->mdsc;
|
||||
struct ceph_cap_flush *prealloc_cf = NULL;
|
||||
int issued;
|
||||
int err;
|
||||
@ -958,8 +933,8 @@ int __ceph_setxattr(struct dentry *dentry, const char *name,
|
||||
int required_blob_size;
|
||||
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);
|
||||
if (vxattr && vxattr->readonly)
|
||||
@ -1056,7 +1031,7 @@ do_sync_unlocked:
|
||||
"during filling trace\n", inode);
|
||||
err = -EBUSY;
|
||||
} else {
|
||||
err = ceph_sync_setxattr(dentry, name, value, size, flags);
|
||||
err = ceph_sync_setxattr(inode, name, value, size, flags);
|
||||
}
|
||||
out:
|
||||
ceph_free_cap_flush(prealloc_cf);
|
||||
@ -1066,147 +1041,30 @@ out:
|
||||
return err;
|
||||
}
|
||||
|
||||
int ceph_setxattr(struct dentry *dentry, const char *name,
|
||||
const void *value, size_t size, int flags)
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int __ceph_removexattr(struct dentry *dentry, const char *name)
|
||||
{
|
||||
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))
|
||||
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_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)
|
||||
{
|
||||
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);
|
||||
if (!ceph_is_valid_xattr(name))
|
||||
return -EOPNOTSUPP;
|
||||
return __ceph_setxattr(d_inode(dentry), name, value, size, flags);
|
||||
}
|
||||
|
||||
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
|
||||
bool ceph_security_xattr_wanted(struct inode *in)
|
||||
{
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "glock.h"
|
||||
#include "inode.h"
|
||||
#include "meta_io.h"
|
||||
#include "rgrp.h"
|
||||
#include "trans.h"
|
||||
#include "util.h"
|
||||
|
||||
@ -38,7 +39,7 @@ static const char *gfs2_acl_name(int type)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
|
||||
static struct posix_acl *__gfs2_get_acl(struct inode *inode, int type)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct posix_acl *acl;
|
||||
@ -50,29 +51,41 @@ struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
|
||||
return NULL;
|
||||
|
||||
name = gfs2_acl_name(type);
|
||||
if (name == NULL)
|
||||
return ERR_PTR(-EINVAL);
|
||||
|
||||
len = gfs2_xattr_acl_get(ip, name, &data);
|
||||
if (len < 0)
|
||||
if (len <= 0)
|
||||
return ERR_PTR(len);
|
||||
if (len == 0)
|
||||
return NULL;
|
||||
|
||||
acl = posix_acl_from_xattr(&init_user_ns, data, len);
|
||||
kfree(data);
|
||||
return acl;
|
||||
}
|
||||
|
||||
int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
struct posix_acl *gfs2_get_acl(struct inode *inode, int type)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
bool need_unlock = false;
|
||||
struct posix_acl *acl;
|
||||
|
||||
if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
|
||||
int ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED,
|
||||
LM_FLAG_ANY, &gh);
|
||||
if (ret)
|
||||
return ERR_PTR(ret);
|
||||
need_unlock = true;
|
||||
}
|
||||
acl = __gfs2_get_acl(inode, type);
|
||||
if (need_unlock)
|
||||
gfs2_glock_dq_uninit(&gh);
|
||||
return acl;
|
||||
}
|
||||
|
||||
int __gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
{
|
||||
int error;
|
||||
int len;
|
||||
char *data;
|
||||
const char *name = gfs2_acl_name(type);
|
||||
|
||||
BUG_ON(name == NULL);
|
||||
|
||||
if (acl && acl->a_count > GFS2_ACL_MAX_ENTRIES(GFS2_SB(inode)))
|
||||
return -E2BIG;
|
||||
|
||||
@ -115,3 +128,26 @@ out:
|
||||
kfree(data);
|
||||
return error;
|
||||
}
|
||||
|
||||
int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
bool need_unlock = false;
|
||||
int ret;
|
||||
|
||||
ret = gfs2_rsqa_alloc(ip);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
|
||||
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
|
||||
if (ret)
|
||||
return ret;
|
||||
need_unlock = true;
|
||||
}
|
||||
ret = __gfs2_set_acl(inode, acl, type);
|
||||
if (need_unlock)
|
||||
gfs2_glock_dq_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#define GFS2_ACL_MAX_ENTRIES(sdp) ((300 << (sdp)->sd_sb.sb_bsize_shift) >> 12)
|
||||
|
||||
extern struct posix_acl *gfs2_get_acl(struct inode *inode, int type);
|
||||
extern int __gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
|
||||
extern int gfs2_set_acl(struct inode *inode, struct posix_acl *acl, int type);
|
||||
|
||||
#endif /* __ACL_DOT_H__ */
|
||||
|
@ -692,12 +692,12 @@ static int gfs2_create_inode(struct inode *dir, struct dentry *dentry,
|
||||
considered free. Any failures need to undo
|
||||
the gfs2 structures. */
|
||||
if (default_acl) {
|
||||
error = gfs2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
|
||||
error = __gfs2_set_acl(inode, default_acl, ACL_TYPE_DEFAULT);
|
||||
posix_acl_release(default_acl);
|
||||
}
|
||||
if (acl) {
|
||||
if (!error)
|
||||
error = gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
|
||||
error = __gfs2_set_acl(inode, acl, ACL_TYPE_ACCESS);
|
||||
posix_acl_release(acl);
|
||||
}
|
||||
|
||||
@ -1948,66 +1948,6 @@ static int gfs2_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int gfs2_setxattr(struct dentry *dentry, const char *name,
|
||||
const void *data, size_t size, int flags)
|
||||
{
|
||||
struct inode *inode = d_inode(dentry);
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
int ret;
|
||||
|
||||
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
|
||||
ret = gfs2_glock_nq(&gh);
|
||||
if (ret == 0) {
|
||||
ret = gfs2_rsqa_alloc(ip);
|
||||
if (ret == 0)
|
||||
ret = generic_setxattr(dentry, name, data, size, flags);
|
||||
gfs2_glock_dq(&gh);
|
||||
}
|
||||
gfs2_holder_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t gfs2_getxattr(struct dentry *dentry, struct inode *inode,
|
||||
const char *name, void *data, size_t size)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
int ret;
|
||||
|
||||
/* For selinux during lookup */
|
||||
if (gfs2_glock_is_locked_by_me(ip->i_gl))
|
||||
return generic_getxattr(dentry, inode, name, data, size);
|
||||
|
||||
gfs2_holder_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
|
||||
ret = gfs2_glock_nq(&gh);
|
||||
if (ret == 0) {
|
||||
ret = generic_getxattr(dentry, inode, name, data, size);
|
||||
gfs2_glock_dq(&gh);
|
||||
}
|
||||
gfs2_holder_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int gfs2_removexattr(struct dentry *dentry, const char *name)
|
||||
{
|
||||
struct inode *inode = d_inode(dentry);
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
int ret;
|
||||
|
||||
gfs2_holder_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
|
||||
ret = gfs2_glock_nq(&gh);
|
||||
if (ret == 0) {
|
||||
ret = gfs2_rsqa_alloc(ip);
|
||||
if (ret == 0)
|
||||
ret = generic_removexattr(dentry, name);
|
||||
gfs2_glock_dq(&gh);
|
||||
}
|
||||
gfs2_holder_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int gfs2_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
|
||||
u64 start, u64 len)
|
||||
{
|
||||
@ -2054,10 +1994,10 @@ const struct inode_operations gfs2_file_iops = {
|
||||
.permission = gfs2_permission,
|
||||
.setattr = gfs2_setattr,
|
||||
.getattr = gfs2_getattr,
|
||||
.setxattr = gfs2_setxattr,
|
||||
.getxattr = gfs2_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = gfs2_listxattr,
|
||||
.removexattr = gfs2_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.fiemap = gfs2_fiemap,
|
||||
.get_acl = gfs2_get_acl,
|
||||
.set_acl = gfs2_set_acl,
|
||||
@ -2076,10 +2016,10 @@ const struct inode_operations gfs2_dir_iops = {
|
||||
.permission = gfs2_permission,
|
||||
.setattr = gfs2_setattr,
|
||||
.getattr = gfs2_getattr,
|
||||
.setxattr = gfs2_setxattr,
|
||||
.getxattr = gfs2_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = gfs2_listxattr,
|
||||
.removexattr = gfs2_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.fiemap = gfs2_fiemap,
|
||||
.get_acl = gfs2_get_acl,
|
||||
.set_acl = gfs2_set_acl,
|
||||
@ -2092,10 +2032,10 @@ const struct inode_operations gfs2_symlink_iops = {
|
||||
.permission = gfs2_permission,
|
||||
.setattr = gfs2_setattr,
|
||||
.getattr = gfs2_getattr,
|
||||
.setxattr = gfs2_setxattr,
|
||||
.getxattr = gfs2_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = gfs2_listxattr,
|
||||
.removexattr = gfs2_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.fiemap = gfs2_fiemap,
|
||||
};
|
||||
|
||||
|
@ -583,13 +583,11 @@ out:
|
||||
*
|
||||
* Returns: actual size of data on success, -errno on error
|
||||
*/
|
||||
static int gfs2_xattr_get(const struct xattr_handler *handler,
|
||||
struct dentry *unused, struct inode *inode,
|
||||
const char *name, void *buffer, size_t size)
|
||||
static int __gfs2_xattr_get(struct inode *inode, const char *name,
|
||||
void *buffer, size_t size, int type)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_ea_location el;
|
||||
int type = handler->flags;
|
||||
int error;
|
||||
|
||||
if (!ip->i_eattr)
|
||||
@ -611,6 +609,29 @@ static int gfs2_xattr_get(const struct xattr_handler *handler,
|
||||
return error;
|
||||
}
|
||||
|
||||
static int gfs2_xattr_get(const struct xattr_handler *handler,
|
||||
struct dentry *unused, struct inode *inode,
|
||||
const char *name, void *buffer, size_t size)
|
||||
{
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
bool need_unlock = false;
|
||||
int ret;
|
||||
|
||||
/* During lookup, SELinux calls this function with the glock locked. */
|
||||
|
||||
if (!gfs2_glock_is_locked_by_me(ip->i_gl)) {
|
||||
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, LM_FLAG_ANY, &gh);
|
||||
if (ret)
|
||||
return ret;
|
||||
need_unlock = true;
|
||||
}
|
||||
ret = __gfs2_xattr_get(inode, name, buffer, size, handler->flags);
|
||||
if (need_unlock)
|
||||
gfs2_glock_dq_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* ea_alloc_blk - allocates a new block for extended attributes.
|
||||
* @ip: A pointer to the inode that's getting extended attributes
|
||||
@ -1233,8 +1254,21 @@ static int gfs2_xattr_set(const struct xattr_handler *handler,
|
||||
struct dentry *dentry, const char *name,
|
||||
const void *value, size_t size, int flags)
|
||||
{
|
||||
return __gfs2_xattr_set(d_inode(dentry), name, value,
|
||||
size, flags, handler->flags);
|
||||
struct inode *inode = d_inode(dentry);
|
||||
struct gfs2_inode *ip = GFS2_I(inode);
|
||||
struct gfs2_holder gh;
|
||||
int ret;
|
||||
|
||||
ret = gfs2_rsqa_alloc(ip);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
|
||||
if (ret)
|
||||
return ret;
|
||||
ret = __gfs2_xattr_set(inode, name, value, size, flags, handler->flags);
|
||||
gfs2_glock_dq_uninit(&gh);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ea_dealloc_indirect(struct gfs2_inode *ip)
|
||||
|
@ -140,10 +140,10 @@ int jfs_setattr(struct dentry *dentry, struct iattr *iattr)
|
||||
}
|
||||
|
||||
const struct inode_operations jfs_file_inode_operations = {
|
||||
.setxattr = jfs_setxattr,
|
||||
.getxattr = jfs_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = jfs_listxattr,
|
||||
.removexattr = jfs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.setattr = jfs_setattr,
|
||||
#ifdef CONFIG_JFS_POSIX_ACL
|
||||
.get_acl = jfs_get_acl,
|
||||
|
@ -19,6 +19,8 @@
|
||||
#ifndef H_JFS_XATTR
|
||||
#define H_JFS_XATTR
|
||||
|
||||
#include <linux/xattr.h>
|
||||
|
||||
/*
|
||||
* jfs_ea_list describe the on-disk format of the extended attributes.
|
||||
* I know the null-terminator is redundant since namelen is stored, but
|
||||
@ -54,12 +56,8 @@ struct jfs_ea_list {
|
||||
|
||||
extern int __jfs_setxattr(tid_t, struct inode *, const char *, const void *,
|
||||
size_t, int);
|
||||
extern int jfs_setxattr(struct dentry *, const char *, const void *, size_t,
|
||||
int);
|
||||
extern ssize_t __jfs_getxattr(struct inode *, const char *, void *, size_t);
|
||||
extern ssize_t jfs_getxattr(struct dentry *, struct inode *, const char *, void *, size_t);
|
||||
extern ssize_t jfs_listxattr(struct dentry *, char *, size_t);
|
||||
extern int jfs_removexattr(struct dentry *, const char *);
|
||||
|
||||
extern const struct xattr_handler *jfs_xattr_handlers[];
|
||||
|
||||
|
@ -1537,10 +1537,10 @@ const struct inode_operations jfs_dir_inode_operations = {
|
||||
.rmdir = jfs_rmdir,
|
||||
.mknod = jfs_mknod,
|
||||
.rename = jfs_rename,
|
||||
.setxattr = jfs_setxattr,
|
||||
.getxattr = jfs_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = jfs_listxattr,
|
||||
.removexattr = jfs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
.setattr = jfs_setattr,
|
||||
#ifdef CONFIG_JFS_POSIX_ACL
|
||||
.get_acl = jfs_get_acl,
|
||||
|
@ -25,19 +25,19 @@ const struct inode_operations jfs_fast_symlink_inode_operations = {
|
||||
.readlink = generic_readlink,
|
||||
.get_link = simple_get_link,
|
||||
.setattr = jfs_setattr,
|
||||
.setxattr = jfs_setxattr,
|
||||
.getxattr = jfs_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = jfs_listxattr,
|
||||
.removexattr = jfs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
};
|
||||
|
||||
const struct inode_operations jfs_symlink_inode_operations = {
|
||||
.readlink = generic_readlink,
|
||||
.get_link = page_get_link,
|
||||
.setattr = jfs_setattr,
|
||||
.setxattr = jfs_setxattr,
|
||||
.getxattr = jfs_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = jfs_listxattr,
|
||||
.removexattr = jfs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
};
|
||||
|
||||
|
224
fs/jfs/xattr.c
224
fs/jfs/xattr.c
@ -86,6 +86,14 @@ struct ea_buffer {
|
||||
#define EA_MALLOC 0x0008
|
||||
|
||||
|
||||
/*
|
||||
* Mapping of on-disk attribute names: for on-disk attribute names with an
|
||||
* unknown prefix (not "system.", "user.", "security.", or "trusted."), the
|
||||
* prefix "os2." is prepended. On the way back to disk, "os2." prefixes are
|
||||
* stripped and we make sure that the remaining name does not start with one
|
||||
* of the know prefixes.
|
||||
*/
|
||||
|
||||
static int is_known_namespace(const char *name)
|
||||
{
|
||||
if (strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) &&
|
||||
@ -97,29 +105,19 @@ static int is_known_namespace(const char *name)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* These three routines are used to recognize on-disk extended attributes
|
||||
* that are in a recognized namespace. If the attribute is not recognized,
|
||||
* "os2." is prepended to the name
|
||||
*/
|
||||
static int is_os2_xattr(struct jfs_ea *ea)
|
||||
{
|
||||
return !is_known_namespace(ea->name);
|
||||
}
|
||||
|
||||
static inline int name_size(struct jfs_ea *ea)
|
||||
{
|
||||
if (is_os2_xattr(ea))
|
||||
return ea->namelen + XATTR_OS2_PREFIX_LEN;
|
||||
else
|
||||
if (is_known_namespace(ea->name))
|
||||
return ea->namelen;
|
||||
else
|
||||
return ea->namelen + XATTR_OS2_PREFIX_LEN;
|
||||
}
|
||||
|
||||
static inline int copy_name(char *buffer, struct jfs_ea *ea)
|
||||
{
|
||||
int len = ea->namelen;
|
||||
|
||||
if (is_os2_xattr(ea)) {
|
||||
if (!is_known_namespace(ea->name)) {
|
||||
memcpy(buffer, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN);
|
||||
buffer += XATTR_OS2_PREFIX_LEN;
|
||||
len += XATTR_OS2_PREFIX_LEN;
|
||||
@ -665,35 +663,6 @@ static int ea_put(tid_t tid, struct inode *inode, struct ea_buffer *ea_buf,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Most of the permission checking is done by xattr_permission in the vfs.
|
||||
* We also need to verify that this is a namespace that we recognize.
|
||||
*/
|
||||
static int can_set_xattr(struct inode *inode, const char *name,
|
||||
const void *value, size_t value_len)
|
||||
{
|
||||
if (!strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)) {
|
||||
/*
|
||||
* This makes sure that we aren't trying to set an
|
||||
* attribute in a different namespace by prefixing it
|
||||
* with "os2."
|
||||
*/
|
||||
if (is_known_namespace(name + XATTR_OS2_PREFIX_LEN))
|
||||
return -EOPNOTSUPP;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Don't allow setting an attribute in an unknown namespace.
|
||||
*/
|
||||
if (strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) &&
|
||||
strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) &&
|
||||
strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name,
|
||||
const void *value, size_t value_len, int flags)
|
||||
{
|
||||
@ -704,21 +673,10 @@ int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name,
|
||||
int xattr_size;
|
||||
int new_size;
|
||||
int namelen = strlen(name);
|
||||
char *os2name = NULL;
|
||||
int found = 0;
|
||||
int rc;
|
||||
int length;
|
||||
|
||||
if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
|
||||
os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1,
|
||||
GFP_KERNEL);
|
||||
if (!os2name)
|
||||
return -ENOMEM;
|
||||
strcpy(os2name, name + XATTR_OS2_PREFIX_LEN);
|
||||
name = os2name;
|
||||
namelen -= XATTR_OS2_PREFIX_LEN;
|
||||
}
|
||||
|
||||
down_write(&JFS_IP(inode)->xattr_sem);
|
||||
|
||||
xattr_size = ea_get(inode, &ea_buf, 0);
|
||||
@ -841,44 +799,6 @@ int __jfs_setxattr(tid_t tid, struct inode *inode, const char *name,
|
||||
out:
|
||||
up_write(&JFS_IP(inode)->xattr_sem);
|
||||
|
||||
kfree(os2name);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
int jfs_setxattr(struct dentry *dentry, const char *name, const void *value,
|
||||
size_t value_len, int flags)
|
||||
{
|
||||
struct inode *inode = d_inode(dentry);
|
||||
struct jfs_inode_info *ji = JFS_IP(inode);
|
||||
int rc;
|
||||
tid_t tid;
|
||||
|
||||
/*
|
||||
* If this is a request for a synthetic attribute in the system.*
|
||||
* namespace use the generic infrastructure to resolve a handler
|
||||
* for it via sb->s_xattr.
|
||||
*/
|
||||
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
||||
return generic_setxattr(dentry, name, value, value_len, flags);
|
||||
|
||||
if ((rc = can_set_xattr(inode, name, value, value_len)))
|
||||
return rc;
|
||||
|
||||
if (value == NULL) { /* empty EA, do not remove */
|
||||
value = "";
|
||||
value_len = 0;
|
||||
}
|
||||
|
||||
tid = txBegin(inode->i_sb, 0);
|
||||
mutex_lock(&ji->commit_mutex);
|
||||
rc = __jfs_setxattr(tid, d_inode(dentry), name, value, value_len,
|
||||
flags);
|
||||
if (!rc)
|
||||
rc = txCommit(tid, 1, &inode, 0);
|
||||
txEnd(tid);
|
||||
mutex_unlock(&ji->commit_mutex);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
@ -933,37 +853,6 @@ ssize_t __jfs_getxattr(struct inode *inode, const char *name, void *data,
|
||||
return size;
|
||||
}
|
||||
|
||||
ssize_t jfs_getxattr(struct dentry *dentry, struct inode *inode,
|
||||
const char *name, void *data, size_t buf_size)
|
||||
{
|
||||
int err;
|
||||
|
||||
/*
|
||||
* If this is a request for a synthetic attribute in the system.*
|
||||
* namespace use the generic infrastructure to resolve a handler
|
||||
* for it via sb->s_xattr.
|
||||
*/
|
||||
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
||||
return generic_getxattr(dentry, inode, name, data, buf_size);
|
||||
|
||||
if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) {
|
||||
/*
|
||||
* skip past "os2." prefix
|
||||
*/
|
||||
name += XATTR_OS2_PREFIX_LEN;
|
||||
/*
|
||||
* Don't allow retrieving properly prefixed attributes
|
||||
* by prepending them with "os2."
|
||||
*/
|
||||
if (is_known_namespace(name))
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
err = __jfs_getxattr(inode, name, data, buf_size);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* No special permissions are needed to list attributes except for trusted.*
|
||||
*/
|
||||
@ -1027,27 +916,16 @@ ssize_t jfs_listxattr(struct dentry * dentry, char *data, size_t buf_size)
|
||||
return size;
|
||||
}
|
||||
|
||||
int jfs_removexattr(struct dentry *dentry, const char *name)
|
||||
static int __jfs_xattr_set(struct inode *inode, const char *name,
|
||||
const void *value, size_t size, int flags)
|
||||
{
|
||||
struct inode *inode = d_inode(dentry);
|
||||
struct jfs_inode_info *ji = JFS_IP(inode);
|
||||
int rc;
|
||||
tid_t tid;
|
||||
|
||||
/*
|
||||
* If this is a request for a synthetic attribute in the system.*
|
||||
* namespace use the generic infrastructure to resolve a handler
|
||||
* for it via sb->s_xattr.
|
||||
*/
|
||||
if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN))
|
||||
return generic_removexattr(dentry, name);
|
||||
|
||||
if ((rc = can_set_xattr(inode, name, NULL, 0)))
|
||||
return rc;
|
||||
int rc;
|
||||
|
||||
tid = txBegin(inode->i_sb, 0);
|
||||
mutex_lock(&ji->commit_mutex);
|
||||
rc = __jfs_setxattr(tid, d_inode(dentry), name, NULL, 0, XATTR_REPLACE);
|
||||
rc = __jfs_setxattr(tid, inode, name, value, size, flags);
|
||||
if (!rc)
|
||||
rc = txCommit(tid, 1, &inode, 0);
|
||||
txEnd(tid);
|
||||
@ -1056,15 +934,77 @@ int jfs_removexattr(struct dentry *dentry, const char *name)
|
||||
return rc;
|
||||
}
|
||||
|
||||
/*
|
||||
* List of handlers for synthetic system.* attributes. All real ondisk
|
||||
* attributes are handled directly.
|
||||
*/
|
||||
static int jfs_xattr_get(const struct xattr_handler *handler,
|
||||
struct dentry *unused, struct inode *inode,
|
||||
const char *name, void *value, size_t size)
|
||||
{
|
||||
name = xattr_full_name(handler, name);
|
||||
return __jfs_getxattr(inode, name, value, size);
|
||||
}
|
||||
|
||||
static int jfs_xattr_set(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);
|
||||
|
||||
name = xattr_full_name(handler, name);
|
||||
return __jfs_xattr_set(inode, name, value, size, flags);
|
||||
}
|
||||
|
||||
static int jfs_xattr_get_os2(const struct xattr_handler *handler,
|
||||
struct dentry *unused, struct inode *inode,
|
||||
const char *name, void *value, size_t size)
|
||||
{
|
||||
if (is_known_namespace(name))
|
||||
return -EOPNOTSUPP;
|
||||
return __jfs_getxattr(inode, name, value, size);
|
||||
}
|
||||
|
||||
static int jfs_xattr_set_os2(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);
|
||||
|
||||
if (is_known_namespace(name))
|
||||
return -EOPNOTSUPP;
|
||||
return __jfs_xattr_set(inode, name, value, size, flags);
|
||||
}
|
||||
|
||||
static const struct xattr_handler jfs_user_xattr_handler = {
|
||||
.prefix = XATTR_USER_PREFIX,
|
||||
.get = jfs_xattr_get,
|
||||
.set = jfs_xattr_set,
|
||||
};
|
||||
|
||||
static const struct xattr_handler jfs_os2_xattr_handler = {
|
||||
.prefix = XATTR_OS2_PREFIX,
|
||||
.get = jfs_xattr_get_os2,
|
||||
.set = jfs_xattr_set_os2,
|
||||
};
|
||||
|
||||
static const struct xattr_handler jfs_security_xattr_handler = {
|
||||
.prefix = XATTR_SECURITY_PREFIX,
|
||||
.get = jfs_xattr_get,
|
||||
.set = jfs_xattr_set,
|
||||
};
|
||||
|
||||
static const struct xattr_handler jfs_trusted_xattr_handler = {
|
||||
.prefix = XATTR_TRUSTED_PREFIX,
|
||||
.get = jfs_xattr_get,
|
||||
.set = jfs_xattr_set,
|
||||
};
|
||||
|
||||
const struct xattr_handler *jfs_xattr_handlers[] = {
|
||||
#ifdef CONFIG_JFS_POSIX_ACL
|
||||
&posix_acl_access_xattr_handler,
|
||||
&posix_acl_default_xattr_handler,
|
||||
#endif
|
||||
&jfs_os2_xattr_handler,
|
||||
&jfs_user_xattr_handler,
|
||||
&jfs_security_xattr_handler,
|
||||
&jfs_trusted_xattr_handler,
|
||||
NULL,
|
||||
};
|
||||
|
||||
|
@ -1182,10 +1182,10 @@ const struct inode_operations ubifs_dir_inode_operations = {
|
||||
.rename = ubifs_rename,
|
||||
.setattr = ubifs_setattr,
|
||||
.getattr = ubifs_getattr,
|
||||
.setxattr = ubifs_setxattr,
|
||||
.getxattr = ubifs_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = ubifs_listxattr,
|
||||
.removexattr = ubifs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
#ifdef CONFIG_UBIFS_ATIME_SUPPORT
|
||||
.update_time = ubifs_update_time,
|
||||
#endif
|
||||
|
@ -1597,10 +1597,10 @@ const struct address_space_operations ubifs_file_address_operations = {
|
||||
const struct inode_operations ubifs_file_inode_operations = {
|
||||
.setattr = ubifs_setattr,
|
||||
.getattr = ubifs_getattr,
|
||||
.setxattr = ubifs_setxattr,
|
||||
.getxattr = ubifs_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = ubifs_listxattr,
|
||||
.removexattr = ubifs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
#ifdef CONFIG_UBIFS_ATIME_SUPPORT
|
||||
.update_time = ubifs_update_time,
|
||||
#endif
|
||||
@ -1611,10 +1611,10 @@ const struct inode_operations ubifs_symlink_inode_operations = {
|
||||
.get_link = simple_get_link,
|
||||
.setattr = ubifs_setattr,
|
||||
.getattr = ubifs_getattr,
|
||||
.setxattr = ubifs_setxattr,
|
||||
.getxattr = ubifs_getxattr,
|
||||
.setxattr = generic_setxattr,
|
||||
.getxattr = generic_getxattr,
|
||||
.listxattr = ubifs_listxattr,
|
||||
.removexattr = ubifs_removexattr,
|
||||
.removexattr = generic_removexattr,
|
||||
#ifdef CONFIG_UBIFS_ATIME_SUPPORT
|
||||
.update_time = ubifs_update_time,
|
||||
#endif
|
||||
|
@ -2040,6 +2040,7 @@ static int ubifs_fill_super(struct super_block *sb, void *data, int silent)
|
||||
if (c->max_inode_sz > MAX_LFS_FILESIZE)
|
||||
sb->s_maxbytes = c->max_inode_sz = MAX_LFS_FILESIZE;
|
||||
sb->s_op = &ubifs_super_operations;
|
||||
sb->s_xattr = ubifs_xattr_handlers;
|
||||
|
||||
mutex_lock(&c->umount_mutex);
|
||||
err = mount_ubifs(c);
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <linux/pagemap.h>
|
||||
#include <linux/backing-dev.h>
|
||||
#include <linux/security.h>
|
||||
#include <linux/xattr.h>
|
||||
#include "ubifs-media.h"
|
||||
|
||||
/* Version of this UBIFS implementation */
|
||||
@ -1732,12 +1733,8 @@ int ubifs_getattr(struct vfsmount *mnt, struct dentry *dentry,
|
||||
struct kstat *stat);
|
||||
|
||||
/* xattr.c */
|
||||
int ubifs_setxattr(struct dentry *dentry, const char *name,
|
||||
const void *value, size_t size, int flags);
|
||||
ssize_t ubifs_getxattr(struct dentry *dentry, struct inode *host,
|
||||
const char *name, void *buf, size_t size);
|
||||
extern const struct xattr_handler *ubifs_xattr_handlers[];
|
||||
ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size);
|
||||
int ubifs_removexattr(struct dentry *dentry, const char *name);
|
||||
int ubifs_init_security(struct inode *dentry, struct inode *inode,
|
||||
const struct qstr *qstr);
|
||||
|
||||
|
143
fs/ubifs/xattr.c
143
fs/ubifs/xattr.c
@ -249,42 +249,6 @@ out_free:
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* check_namespace - check extended attribute name-space.
|
||||
* @nm: extended attribute name
|
||||
*
|
||||
* This function makes sure the extended attribute name belongs to one of the
|
||||
* supported extended attribute name-spaces. Returns name-space index in case
|
||||
* of success and a negative error code in case of failure.
|
||||
*/
|
||||
static int check_namespace(const struct qstr *nm)
|
||||
{
|
||||
int type;
|
||||
|
||||
if (nm->len > UBIFS_MAX_NLEN)
|
||||
return -ENAMETOOLONG;
|
||||
|
||||
if (!strncmp(nm->name, XATTR_TRUSTED_PREFIX,
|
||||
XATTR_TRUSTED_PREFIX_LEN)) {
|
||||
if (nm->name[XATTR_TRUSTED_PREFIX_LEN] == '\0')
|
||||
return -EINVAL;
|
||||
type = TRUSTED_XATTR;
|
||||
} else if (!strncmp(nm->name, XATTR_USER_PREFIX,
|
||||
XATTR_USER_PREFIX_LEN)) {
|
||||
if (nm->name[XATTR_USER_PREFIX_LEN] == '\0')
|
||||
return -EINVAL;
|
||||
type = USER_XATTR;
|
||||
} else if (!strncmp(nm->name, XATTR_SECURITY_PREFIX,
|
||||
XATTR_SECURITY_PREFIX_LEN)) {
|
||||
if (nm->name[XATTR_SECURITY_PREFIX_LEN] == '\0')
|
||||
return -EINVAL;
|
||||
type = SECURITY_XATTR;
|
||||
} else
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
return type;
|
||||
}
|
||||
|
||||
static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum)
|
||||
{
|
||||
struct inode *inode;
|
||||
@ -302,24 +266,23 @@ static struct inode *iget_xattr(struct ubifs_info *c, ino_t inum)
|
||||
return ERR_PTR(-EINVAL);
|
||||
}
|
||||
|
||||
static int setxattr(struct inode *host, const char *name, const void *value,
|
||||
size_t size, int flags)
|
||||
static int __ubifs_setxattr(struct inode *host, const char *name,
|
||||
const void *value, size_t size, int flags)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct ubifs_info *c = host->i_sb->s_fs_info;
|
||||
struct qstr nm = QSTR_INIT(name, strlen(name));
|
||||
struct ubifs_dent_node *xent;
|
||||
union ubifs_key key;
|
||||
int err, type;
|
||||
int err;
|
||||
|
||||
ubifs_assert(inode_is_locked(host));
|
||||
|
||||
if (size > UBIFS_MAX_INO_DATA)
|
||||
return -ERANGE;
|
||||
|
||||
type = check_namespace(&nm);
|
||||
if (type < 0)
|
||||
return type;
|
||||
if (nm.len > UBIFS_MAX_NLEN)
|
||||
return -ENAMETOOLONG;
|
||||
|
||||
xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS);
|
||||
if (!xent)
|
||||
@ -363,17 +326,8 @@ out_free:
|
||||
return err;
|
||||
}
|
||||
|
||||
int ubifs_setxattr(struct dentry *dentry, const char *name,
|
||||
const void *value, size_t size, int flags)
|
||||
{
|
||||
dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd",
|
||||
name, d_inode(dentry)->i_ino, dentry, size);
|
||||
|
||||
return setxattr(d_inode(dentry), name, value, size, flags);
|
||||
}
|
||||
|
||||
ssize_t ubifs_getxattr(struct dentry *dentry, struct inode *host,
|
||||
const char *name, void *buf, size_t size)
|
||||
static ssize_t __ubifs_getxattr(struct inode *host, const char *name,
|
||||
void *buf, size_t size)
|
||||
{
|
||||
struct inode *inode;
|
||||
struct ubifs_info *c = host->i_sb->s_fs_info;
|
||||
@ -383,12 +337,8 @@ ssize_t ubifs_getxattr(struct dentry *dentry, struct inode *host,
|
||||
union ubifs_key key;
|
||||
int err;
|
||||
|
||||
dbg_gen("xattr '%s', ino %lu ('%pd'), buf size %zd", name,
|
||||
host->i_ino, dentry, size);
|
||||
|
||||
err = check_namespace(&nm);
|
||||
if (err < 0)
|
||||
return err;
|
||||
if (nm.len > UBIFS_MAX_NLEN)
|
||||
return -ENAMETOOLONG;
|
||||
|
||||
xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS);
|
||||
if (!xent)
|
||||
@ -460,8 +410,6 @@ ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
||||
|
||||
lowest_xent_key(c, &key, host->i_ino);
|
||||
while (1) {
|
||||
int type;
|
||||
|
||||
xent = ubifs_tnc_next_ent(c, &key, &nm);
|
||||
if (IS_ERR(xent)) {
|
||||
err = PTR_ERR(xent);
|
||||
@ -471,14 +419,10 @@ ssize_t ubifs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
||||
nm.name = xent->name;
|
||||
nm.len = le16_to_cpu(xent->nlen);
|
||||
|
||||
type = check_namespace(&nm);
|
||||
if (unlikely(type < 0)) {
|
||||
err = type;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Show trusted namespace only for "power" users */
|
||||
if (type != TRUSTED_XATTR || capable(CAP_SYS_ADMIN)) {
|
||||
if (strncmp(xent->name, XATTR_TRUSTED_PREFIX,
|
||||
XATTR_TRUSTED_PREFIX_LEN) ||
|
||||
capable(CAP_SYS_ADMIN)) {
|
||||
memcpy(buffer + written, nm.name, nm.len + 1);
|
||||
written += nm.len + 1;
|
||||
}
|
||||
@ -538,22 +482,19 @@ out_cancel:
|
||||
return err;
|
||||
}
|
||||
|
||||
int ubifs_removexattr(struct dentry *dentry, const char *name)
|
||||
static int __ubifs_removexattr(struct inode *host, const char *name)
|
||||
{
|
||||
struct inode *inode, *host = d_inode(dentry);
|
||||
struct inode *inode;
|
||||
struct ubifs_info *c = host->i_sb->s_fs_info;
|
||||
struct qstr nm = QSTR_INIT(name, strlen(name));
|
||||
struct ubifs_dent_node *xent;
|
||||
union ubifs_key key;
|
||||
int err;
|
||||
|
||||
dbg_gen("xattr '%s', ino %lu ('%pd')", name,
|
||||
host->i_ino, dentry);
|
||||
ubifs_assert(inode_is_locked(host));
|
||||
|
||||
err = check_namespace(&nm);
|
||||
if (err < 0)
|
||||
return err;
|
||||
if (nm.len > UBIFS_MAX_NLEN)
|
||||
return -ENAMETOOLONG;
|
||||
|
||||
xent = kmalloc(UBIFS_MAX_XENT_NODE_SZ, GFP_NOFS);
|
||||
if (!xent)
|
||||
@ -603,7 +544,7 @@ static int init_xattrs(struct inode *inode, const struct xattr *xattr_array,
|
||||
}
|
||||
strcpy(name, XATTR_SECURITY_PREFIX);
|
||||
strcpy(name + XATTR_SECURITY_PREFIX_LEN, xattr->name);
|
||||
err = setxattr(inode, name, xattr->value, xattr->value_len, 0);
|
||||
err = __ubifs_setxattr(inode, name, xattr->value, xattr->value_len, 0);
|
||||
kfree(name);
|
||||
if (err < 0)
|
||||
break;
|
||||
@ -626,3 +567,53 @@ int ubifs_init_security(struct inode *dentry, struct inode *inode,
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static int ubifs_xattr_get(const struct xattr_handler *handler,
|
||||
struct dentry *dentry, struct inode *inode,
|
||||
const char *name, void *buffer, size_t size)
|
||||
{
|
||||
dbg_gen("xattr '%s', ino %lu ('%pd'), buf size %zd", name,
|
||||
inode->i_ino, dentry, size);
|
||||
|
||||
return __ubifs_getxattr(inode, name, buffer, size);
|
||||
}
|
||||
|
||||
static int ubifs_xattr_set(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);
|
||||
|
||||
dbg_gen("xattr '%s', host ino %lu ('%pd'), size %zd",
|
||||
name, inode->i_ino, dentry, size);
|
||||
|
||||
if (value)
|
||||
return __ubifs_setxattr(inode, name, value, size, flags);
|
||||
else
|
||||
return __ubifs_removexattr(inode, name);
|
||||
}
|
||||
|
||||
const struct xattr_handler ubifs_user_xattr_handler = {
|
||||
.prefix = XATTR_USER_PREFIX,
|
||||
.get = ubifs_xattr_get,
|
||||
.set = ubifs_xattr_set,
|
||||
};
|
||||
|
||||
const struct xattr_handler ubifs_trusted_xattr_handler = {
|
||||
.prefix = XATTR_TRUSTED_PREFIX,
|
||||
.get = ubifs_xattr_get,
|
||||
.set = ubifs_xattr_set,
|
||||
};
|
||||
|
||||
const struct xattr_handler ubifs_security_xattr_handler = {
|
||||
.prefix = XATTR_SECURITY_PREFIX,
|
||||
.get = ubifs_xattr_get,
|
||||
.set = ubifs_xattr_set,
|
||||
};
|
||||
|
||||
const struct xattr_handler *ubifs_xattr_handlers[] = {
|
||||
&ubifs_user_xattr_handler,
|
||||
&ubifs_trusted_xattr_handler,
|
||||
&ubifs_security_xattr_handler,
|
||||
NULL
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user