Skip to content

Commit eb78808

Browse files
author
Alex Elder
committed
ceph: use macros to normalize vxattr table definitions
Entries in the ceph virtual extended attribute tables all follow a distinct pattern in their definition. Enforce this pattern through the use of a macro. Also, a null name field signals the end of the table, so make that be the first field in the ceph_vxattr_cb structure. Signed-off-by: Alex Elder <elder@dreamhost.com> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent 2289190 commit eb78808

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

‎fs/ceph/xattr.c‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ static bool ceph_is_valid_xattr(const char *name)
2525
* statistics and layout metadata.
2626
*/
2727
struct ceph_vxattr_cb {
28-
bool readonly;
2928
char *name;
3029
size_t (*getxattr_cb)(struct ceph_inode_info *ci, char *val,
3130
size_t size);
31+
bool readonly;
3232
};
3333

3434
/* directories */
@@ -82,16 +82,25 @@ static size_t ceph_vxattrcb_rctime(struct ceph_inode_info *ci, char *val,
8282
(long)ci->i_rctime.tv_nsec);
8383
}
8484

85+
#define CEPH_XATTR_NAME(_type, _name) XATTR_CEPH_PREFIX #_type "." #_name
86+
87+
#define XATTR_NAME_CEPH(_type, _name) \
88+
{ \
89+
.name = CEPH_XATTR_NAME(_type, _name), \
90+
.getxattr_cb = ceph_vxattrcb_ ## _name, \
91+
.readonly = true, \
92+
}
93+
8594
static struct ceph_vxattr_cb ceph_dir_vxattrs[] = {
86-
{ true, XATTR_CEPH_PREFIX "dir.entries", ceph_vxattrcb_entries},
87-
{ true, XATTR_CEPH_PREFIX "dir.files", ceph_vxattrcb_files},
88-
{ true, XATTR_CEPH_PREFIX "dir.subdirs", ceph_vxattrcb_subdirs},
89-
{ true, XATTR_CEPH_PREFIX "dir.rentries", ceph_vxattrcb_rentries},
90-
{ true, XATTR_CEPH_PREFIX "dir.rfiles", ceph_vxattrcb_rfiles},
91-
{ true, XATTR_CEPH_PREFIX "dir.rsubdirs", ceph_vxattrcb_rsubdirs},
92-
{ true, XATTR_CEPH_PREFIX "dir.rbytes", ceph_vxattrcb_rbytes},
93-
{ true, XATTR_CEPH_PREFIX "dir.rctime", ceph_vxattrcb_rctime},
94-
{ true, NULL, NULL }
95+
XATTR_NAME_CEPH(dir, entries),
96+
XATTR_NAME_CEPH(dir, files),
97+
XATTR_NAME_CEPH(dir, subdirs),
98+
XATTR_NAME_CEPH(dir, rentries),
99+
XATTR_NAME_CEPH(dir, rfiles),
100+
XATTR_NAME_CEPH(dir, rsubdirs),
101+
XATTR_NAME_CEPH(dir, rbytes),
102+
XATTR_NAME_CEPH(dir, rctime),
103+
{ 0 } /* Required table terminator */
95104
};
96105

97106
/* files */
@@ -114,10 +123,14 @@ static size_t ceph_vxattrcb_layout(struct ceph_inode_info *ci, char *val,
114123
}
115124

116125
static struct ceph_vxattr_cb ceph_file_vxattrs[] = {
117-
{ true, XATTR_CEPH_PREFIX "file.layout", ceph_vxattrcb_layout},
126+
XATTR_NAME_CEPH(file, layout),
118127
/* The following extended attribute name is deprecated */
119-
{ true, XATTR_CEPH_PREFIX "layout", ceph_vxattrcb_layout},
120-
{ true, NULL, NULL }
128+
{
129+
.name = XATTR_CEPH_PREFIX "layout",
130+
.getxattr_cb = ceph_vxattrcb_layout,
131+
.readonly = true,
132+
},
133+
{ 0 } /* Required table terminator */
121134
};
122135

123136
static struct ceph_vxattr_cb *ceph_inode_vxattrs(struct inode *inode)

0 commit comments

Comments
 (0)