Skip to content

Commit 3ce6cd1

Browse files
author
Alex Elder
committed
ceph: avoid repeatedly computing the size of constant vxattr names
All names defined in the directory and file virtual extended attribute tables are constant, and the size of each is known at compile time. So there's no need to compute their length every time any file's attribute is listed. Record the length of each string and use it when needed to determine the space need to represent them. In addition, compute the aggregate size of strings in each table just once at initialization time. Signed-off-by: Alex Elder <elder@dreamhost.com> Signed-off-by: Sage Weil <sage@newdream.net>
1 parent aa4066e commit 3ce6cd1

3 files changed

Lines changed: 56 additions & 5 deletions

File tree

‎fs/ceph/super.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -927,6 +927,7 @@ static int __init init_ceph(void)
927927
if (ret)
928928
goto out;
929929

930+
ceph_xattr_init();
930931
ret = register_filesystem(&ceph_fs_type);
931932
if (ret)
932933
goto out_icache;
@@ -936,6 +937,7 @@ static int __init init_ceph(void)
936937
return 0;
937938

938939
out_icache:
940+
ceph_xattr_exit();
939941
destroy_caches();
940942
out:
941943
return ret;
@@ -945,6 +947,7 @@ static void __exit exit_ceph(void)
945947
{
946948
dout("exit_ceph\n");
947949
unregister_filesystem(&ceph_fs_type);
950+
ceph_xattr_exit();
948951
destroy_caches();
949952
}
950953

‎fs/ceph/super.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,8 @@ extern ssize_t ceph_listxattr(struct dentry *, char *, size_t);
733733
extern int ceph_removexattr(struct dentry *, const char *);
734734
extern void __ceph_build_xattrs_blob(struct ceph_inode_info *ci);
735735
extern void __ceph_destroy_xattrs(struct ceph_inode_info *ci);
736+
extern void __init ceph_xattr_init(void);
737+
extern void ceph_xattr_exit(void);
736738

737739
/* caps.c */
738740
extern const char *ceph_cap_string(int c);

‎fs/ceph/xattr.c‎

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ static bool ceph_is_valid_xattr(const char *name)
2626
*/
2727
struct ceph_vxattr {
2828
char *name;
29+
size_t name_size; /* strlen(name) + 1 (for '\0') */
2930
size_t (*getxattr_cb)(struct ceph_inode_info *ci, char *val,
3031
size_t size);
3132
bool readonly;
@@ -87,6 +88,7 @@ static size_t ceph_vxattrcb_dir_rctime(struct ceph_inode_info *ci, char *val,
8788
#define XATTR_NAME_CEPH(_type, _name) \
8889
{ \
8990
.name = CEPH_XATTR_NAME(_type, _name), \
91+
.name_size = sizeof (CEPH_XATTR_NAME(_type, _name)), \
9092
.getxattr_cb = ceph_vxattrcb_ ## _type ## _ ## _name, \
9193
.readonly = true, \
9294
}
@@ -102,6 +104,7 @@ static struct ceph_vxattr ceph_dir_vxattrs[] = {
102104
XATTR_NAME_CEPH(dir, rctime),
103105
{ 0 } /* Required table terminator */
104106
};
107+
static size_t ceph_dir_vxattrs_name_size; /* total size of all names */
105108

106109
/* files */
107110

@@ -127,11 +130,13 @@ static struct ceph_vxattr ceph_file_vxattrs[] = {
127130
/* The following extended attribute name is deprecated */
128131
{
129132
.name = XATTR_CEPH_PREFIX "layout",
133+
.name_size = sizeof (XATTR_CEPH_PREFIX "layout"),
130134
.getxattr_cb = ceph_vxattrcb_file_layout,
131135
.readonly = true,
132136
},
133137
{ 0 } /* Required table terminator */
134138
};
139+
static size_t ceph_file_vxattrs_name_size; /* total size of all names */
135140

136141
static struct ceph_vxattr *ceph_inode_vxattrs(struct inode *inode)
137142
{
@@ -142,6 +147,46 @@ static struct ceph_vxattr *ceph_inode_vxattrs(struct inode *inode)
142147
return NULL;
143148
}
144149

150+
static size_t ceph_vxattrs_name_size(struct ceph_vxattr *vxattrs)
151+
{
152+
if (vxattrs == ceph_dir_vxattrs)
153+
return ceph_dir_vxattrs_name_size;
154+
if (vxattrs == ceph_file_vxattrs)
155+
return ceph_file_vxattrs_name_size;
156+
BUG();
157+
158+
return 0;
159+
}
160+
161+
/*
162+
* Compute the aggregate size (including terminating '\0') of all
163+
* virtual extended attribute names in the given vxattr table.
164+
*/
165+
static size_t __init vxattrs_name_size(struct ceph_vxattr *vxattrs)
166+
{
167+
struct ceph_vxattr *vxattr;
168+
size_t size = 0;
169+
170+
for (vxattr = vxattrs; vxattr->name; vxattr++)
171+
size += vxattr->name_size;
172+
173+
return size;
174+
}
175+
176+
/* Routines called at initialization and exit time */
177+
178+
void __init ceph_xattr_init(void)
179+
{
180+
ceph_dir_vxattrs_name_size = vxattrs_name_size(ceph_dir_vxattrs);
181+
ceph_file_vxattrs_name_size = vxattrs_name_size(ceph_file_vxattrs);
182+
}
183+
184+
void ceph_xattr_exit(void)
185+
{
186+
ceph_dir_vxattrs_name_size = 0;
187+
ceph_file_vxattrs_name_size = 0;
188+
}
189+
145190
static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,
146191
const char *name)
147192
{
@@ -615,11 +660,12 @@ ssize_t ceph_listxattr(struct dentry *dentry, char *names, size_t size)
615660
goto out;
616661

617662
list_xattr:
618-
vir_namelen = 0;
619-
/* include virtual dir xattrs */
620-
if (vxattrs)
621-
for (i = 0; vxattrs[i].name; i++)
622-
vir_namelen += strlen(vxattrs[i].name) + 1;
663+
/*
664+
* Start with virtual dir xattr names (if any) (including
665+
* terminating '\0' characters for each).
666+
*/
667+
vir_namelen = ceph_vxattrs_name_size(vxattrs);
668+
623669
/* adding 1 byte per each variable due to the null termination */
624670
namelen = vir_namelen + ci->i_xattrs.names_size + ci->i_xattrs.count;
625671
err = -ERANGE;

0 commit comments

Comments
 (0)