Skip to content

Commit 06476a6

Browse files
author
Alex Elder
committed
ceph: pass inode rather than table to ceph_match_vxattr()
All callers of ceph_match_vxattr() determine what to pass as the first argument by calling ceph_inode_vxattrs(inode). Just do that inside ceph_match_vxattr() itself, changing it to take an inode rather than the vxattr pointer as its first argument. Also ensure the function works correctly for an empty table (i.e., containing only a terminating null entry). Signed-off-by: Alex Elder <elder@dreamhost.com> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent b829c19 commit 06476a6

1 file changed

Lines changed: 20 additions & 23 deletions

File tree

‎fs/ceph/xattr.c‎

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,19 @@ static struct ceph_vxattr_cb *ceph_inode_vxattrs(struct inode *inode)
126126
return NULL;
127127
}
128128

129-
static struct ceph_vxattr_cb *ceph_match_vxattr(struct ceph_vxattr_cb *vxattr,
129+
static struct ceph_vxattr_cb *ceph_match_vxattr(struct inode *inode,
130130
const char *name)
131131
{
132-
do {
133-
if (strcmp(vxattr->name, name) == 0)
134-
return vxattr;
135-
vxattr++;
136-
} while (vxattr->name);
132+
struct ceph_vxattr_cb *vxattr = ceph_inode_vxattrs(inode);
133+
134+
if (vxattr) {
135+
while (vxattr->name) {
136+
if (!strcmp(vxattr->name, name))
137+
return vxattr;
138+
vxattr++;
139+
}
140+
}
141+
137142
return NULL;
138143
}
139144

@@ -502,7 +507,6 @@ ssize_t ceph_getxattr(struct dentry *dentry, const char *name, void *value,
502507
{
503508
struct inode *inode = dentry->d_inode;
504509
struct ceph_inode_info *ci = ceph_inode(inode);
505-
struct ceph_vxattr_cb *vxattrs = ceph_inode_vxattrs(inode);
506510
int err;
507511
struct ceph_inode_xattr *xattr;
508512
struct ceph_vxattr_cb *vxattr = NULL;
@@ -511,8 +515,7 @@ ssize_t ceph_getxattr(struct dentry *dentry, const char *name, void *value,
511515
return -ENODATA;
512516

513517
/* let's see if a virtual xattr was requested */
514-
if (vxattrs)
515-
vxattr = ceph_match_vxattr(vxattrs, name);
518+
vxattr = ceph_match_vxattr(inode, name);
516519

517520
spin_lock(&ci->i_ceph_lock);
518521
dout("getxattr %p ver=%lld index_ver=%lld\n", inode,
@@ -698,8 +701,8 @@ int ceph_setxattr(struct dentry *dentry, const char *name,
698701
const void *value, size_t size, int flags)
699702
{
700703
struct inode *inode = dentry->d_inode;
704+
struct ceph_vxattr_cb *vxattr;
701705
struct ceph_inode_info *ci = ceph_inode(inode);
702-
struct ceph_vxattr_cb *vxattrs = ceph_inode_vxattrs(inode);
703706
int err;
704707
int name_len = strlen(name);
705708
int val_len = size;
@@ -716,12 +719,9 @@ int ceph_setxattr(struct dentry *dentry, const char *name,
716719
if (!ceph_is_valid_xattr(name))
717720
return -EOPNOTSUPP;
718721

719-
if (vxattrs) {
720-
struct ceph_vxattr_cb *vxattr =
721-
ceph_match_vxattr(vxattrs, name);
722-
if (vxattr && vxattr->readonly)
723-
return -EOPNOTSUPP;
724-
}
722+
vxattr = ceph_match_vxattr(inode, name);
723+
if (vxattr && vxattr->readonly)
724+
return -EOPNOTSUPP;
725725

726726
/* preallocate memory for xattr name, value, index node */
727727
err = -ENOMEM;
@@ -814,8 +814,8 @@ static int ceph_send_removexattr(struct dentry *dentry, const char *name)
814814
int ceph_removexattr(struct dentry *dentry, const char *name)
815815
{
816816
struct inode *inode = dentry->d_inode;
817+
struct ceph_vxattr_cb *vxattr;
817818
struct ceph_inode_info *ci = ceph_inode(inode);
818-
struct ceph_vxattr_cb *vxattrs = ceph_inode_vxattrs(inode);
819819
int issued;
820820
int err;
821821
int required_blob_size;
@@ -827,12 +827,9 @@ int ceph_removexattr(struct dentry *dentry, const char *name)
827827
if (!ceph_is_valid_xattr(name))
828828
return -EOPNOTSUPP;
829829

830-
if (vxattrs) {
831-
struct ceph_vxattr_cb *vxattr =
832-
ceph_match_vxattr(vxattrs, name);
833-
if (vxattr && vxattr->readonly)
834-
return -EOPNOTSUPP;
835-
}
830+
vxattr = ceph_match_vxattr(inode, name);
831+
if (vxattr && vxattr->readonly)
832+
return -EOPNOTSUPP;
836833

837834
err = -ENOMEM;
838835
spin_lock(&ci->i_ceph_lock);

0 commit comments

Comments
 (0)