ceph: Get rid of d_find_alias in ceph_set_acl
PATCH 1/3 ceph: Get rid of d_find_alias in ceph_set_acl
From: Andreas Gruenbacher <[email protected]>
Create a variant of ceph_setattr that takes an inode instead of a dentry. Change __ceph_setxattr (and also __ceph_removexattr) to take an inode instead of a dentry. Use those in ceph_set_acl so that we no longer need a dentry there.
--- fs/ceph/acl.c | 14 +++++--------- fs/ceph/inode.c | 16 ++++++++++------ fs/ceph/super.h | 4 ++-- fs/ceph/xattr.c | 28 ++++++++++++---------------- 4 files changed, 29 insertions(+), 33 deletions(-)
fs/ceph/acl.c +5 -9
@@ -88,7 +88,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 :
@@ -126,29 +125,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:
fs/ceph/inode.c +10 -6
@@ -1792,16 +1792,12 @@ static const struct inode_operations ceph_symlink_iops = { .removexattr = ceph_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 ;
@@ -2026,6 +2022,14 @@ out_put: }/* +* 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. */
fs/ceph/super.h +2 -2
@@ -786,6 +786,7 @@ 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);
@@ -793,9 +794,8 @@ extern int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry,/* 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 *,const char *,void *,size_t );extern ssize_t ceph_listxattr (struct dentry *,char *,size_t );extern int ceph_removexattr (struct dentry *,const char *);
fs/ceph/xattr.c +12 -16
@@ -898,11 +898,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;
@@ -960,13 +959,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;
@@ -1077,7 +1075,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);
@@ -1099,14 +1097,13 @@ int ceph_setxattr(struct dentry *dentry, const char *name,if (size ==0 ) value ="" ;/* empty EA, do not remove */ -return __ceph_setxattr (dentry, name, value, size, flags); +return __ceph_setxattr (d_inode (dentry), name, value, size, flags); } -static int ceph_send_removexattr (struct dentry *dentry,const char *name) +static int ceph_send_removexattr (struct inode *inode,const char *name) { -struct ceph_fs_client *fsc =ceph_sb_to_client (dentry->d_sb); +struct ceph_fs_client *fsc =ceph_sb_to_client (inode->i_sb);struct ceph_mds_client *mdsc = fsc->mdsc; -struct inode *inode =d_inode (dentry);struct ceph_mds_request *req;int err;
@@ -1127,12 +1124,11 @@ static int ceph_send_removexattr(struct dentry *dentry, const char *name)return err; } -int __ceph_removexattr (struct dentry *dentry,const char *name) +static int __ceph_removexattr (struct inode *inode,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_mds_client *mdsc =ceph_sb_to_client (inode->i_sb)->mdsc;struct ceph_cap_flush *prealloc_cf =NULL ;int issued;int err;
@@ -1213,7 +1209,7 @@ do_sync_unlocked:if (lock_snap_rwsem)up_read (&mdsc->snap_rwsem);ceph_free_cap_flush (prealloc_cf); - err =ceph_send_removexattr (dentry, name); + err =ceph_send_removexattr (inode, name);return err; }
@@ -1225,7 +1221,7 @@ int ceph_removexattr(struct dentry *dentry, const char *name)if (!strncmp (name,XATTR_SYSTEM_PREFIX ,XATTR_SYSTEM_PREFIX_LEN ))return generic_removexattr (dentry, name); -return __ceph_removexattr (dentry, name); +return __ceph_removexattr (d_inode (dentry), name); }#ifdef CONFIG_SECURITY
Signature · 1 line
2.5.0
PATCH 2/3 ceph: Switch to generic xattr handlers
From: Andreas Gruenbacher <[email protected]>
Add a catch-all xattr handler at the end of ceph_xattr_handlers. Check for valid attribute names there, and remove those checks from __ceph_{get,set,remove}xattr instead. No "system.*" xattrs need to be handled by the catch-all handler anymore.
The set xattr handler is called with a NULL value to indicate that the attribute should be removed, so call __ceph_removexattr instead of __ceph_setxattr in that case.
Move the check for snapshots from ceph_{set,remove}xattr into __ceph_{set,remove}xattr. With that, ceph_{get,set,remove}xattr can be replaced with the generic iops.
--- fs/ceph/dir.c | 7 +++--- fs/ceph/inode.c | 13 ++++++------ fs/ceph/super.h | 4 ---- fs/ceph/xattr.c | 66 +++++++++++++++++++++++---------------------------------- 4 files changed, 38 insertions(+), 52 deletions(-)
fs/ceph/dir.c +4 -3
@@ -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,
fs/ceph/inode.c +7 -6
@@ -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, };
@@ -1786,10 +1787,10 @@ 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, };int __ceph_setattr (struct inode *inode,struct iattr *attr)
fs/ceph/super.h +0 -4
@@ -792,13 +792,9 @@ 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 inode *,const char *,const void *,size_t ,int );ssize_t __ceph_getxattr (struct inode *,const char *,void *,size_t ); -extern ssize_t ceph_getxattr (struct dentry *,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 );
fs/ceph/xattr.c +27 -39
124 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH 3/3 ceph: kill __ceph_removexattr()
In reply to Yan, Zhengwhen removing a xattr, generic_removexattr() calls __ceph_setxattr() with NULL value and XATTR_REPLACE flag. __ceph_removexattr() is not used any more.
--- fs/ceph/xattr.c | 126 -------------------------------------------------------- 1 file changed, 126 deletions(-)
fs/ceph/xattr.c +0 -126
@@ -519,19 +519,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) {
@@ -1075,119 +1062,6 @@ out:return err; } -static int ceph_send_removexattr (struct inode *inode,const char *name) -{ -struct ceph_fs_client *fsc =ceph_sb_to_client (inode->i_sb); -struct ceph_mds_client *mdsc = fsc->mdsc; -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; -} - -static int __ceph_removexattr (struct inode *inode,const char *name) -{ -struct ceph_vxattr *vxattr; -struct ceph_inode_info *ci =ceph_inode (inode); -struct ceph_mds_client *mdsc =ceph_sb_to_client (inode->i_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_snap (inode) !=CEPH_NOSNAP ) -return -EROFS ; - - 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 (inode, name); -return err; -} -static int ceph_get_xattr_handler (const struct xattr_handler *handler,struct dentry *dentry,const char *name,void *value,size_t size)
Signature · 1 line
2.5.0
Re: [PATCH 3/3] ceph: kill __ceph_removexattr()
Yan,
Quoted 3 lines · Zheng
when removing a xattr,
generic_removexattr()calls__ceph_setxattr()with NULL value andXATTR_REPLACEflag.__ceph_removexattr()is not used any more.
thanks for this, and for reviewing/testing the previous two patches.
Andreas