Skip to content

Commit e43eec8

Browse files
sweetteakdave
authored andcommitted
btrfs: use struct qstr instead of name and namelen pairs
Many functions throughout btrfs take name buffer and name length arguments. Most of these functions at the highest level are usually called with these arguments extracted from a supplied dentry's name. But the entire name can be passed instead, making each function a little more elegant. Each function whose arguments are currently the name and length extracted from a dentry is herein converted to instead take a pointer to the name in the dentry. The couple of calls to these calls without a struct dentry are converted to create an appropriate qstr to pass in. Additionally, every function which is only called with a name/len extracted directly from a qstr is also converted. This change has positive effect on stack consumption, frame of many functions is reduced but this will be used in the future for fscrypt related structures. Signed-off-by: Sweet Tea Dorminy <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 82c0efd commit e43eec8

File tree

12 files changed

+287
-335
lines changed

12 files changed

+287
-335
lines changed

fs/btrfs/ctree.h

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,11 +1516,11 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
15161516

15171517
/* root-item.c */
15181518
int btrfs_add_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
1519-
u64 ref_id, u64 dirid, u64 sequence, const char *name,
1520-
int name_len);
1519+
u64 ref_id, u64 dirid, u64 sequence,
1520+
const struct qstr *name);
15211521
int btrfs_del_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
1522-
u64 ref_id, u64 dirid, u64 *sequence, const char *name,
1523-
int name_len);
1522+
u64 ref_id, u64 dirid, u64 *sequence,
1523+
const struct qstr *name);
15241524
int btrfs_del_root(struct btrfs_trans_handle *trans,
15251525
const struct btrfs_key *key);
15261526
int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
@@ -1549,25 +1549,23 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info);
15491549

15501550
/* dir-item.c */
15511551
int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
1552-
const char *name, int name_len);
1553-
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
1554-
int name_len, struct btrfs_inode *dir,
1552+
const struct qstr *name);
1553+
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
1554+
const struct qstr *name, struct btrfs_inode *dir,
15551555
struct btrfs_key *location, u8 type, u64 index);
15561556
struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
15571557
struct btrfs_root *root,
15581558
struct btrfs_path *path, u64 dir,
1559-
const char *name, int name_len,
1560-
int mod);
1559+
const struct qstr *name, int mod);
15611560
struct btrfs_dir_item *
15621561
btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
15631562
struct btrfs_root *root,
15641563
struct btrfs_path *path, u64 dir,
1565-
u64 index, const char *name, int name_len,
1566-
int mod);
1564+
u64 index, const struct qstr *name, int mod);
15671565
struct btrfs_dir_item *
15681566
btrfs_search_dir_index_item(struct btrfs_root *root,
15691567
struct btrfs_path *path, u64 dirid,
1570-
const char *name, int name_len);
1568+
const struct qstr *name);
15711569
int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
15721570
struct btrfs_root *root,
15731571
struct btrfs_path *path,
@@ -1648,10 +1646,10 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry);
16481646
int btrfs_set_inode_index(struct btrfs_inode *dir, u64 *index);
16491647
int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
16501648
struct btrfs_inode *dir, struct btrfs_inode *inode,
1651-
const char *name, int name_len);
1649+
const struct qstr *name);
16521650
int btrfs_add_link(struct btrfs_trans_handle *trans,
16531651
struct btrfs_inode *parent_inode, struct btrfs_inode *inode,
1654-
const char *name, int name_len, int add_backref, u64 index);
1652+
const struct qstr *name, int add_backref, u64 index);
16551653
int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry);
16561654
int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len,
16571655
int front);

fs/btrfs/dir-item.c

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
105105
* to use for the second index (if one is created).
106106
* Will return 0 or -ENOMEM
107107
*/
108-
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
109-
int name_len, struct btrfs_inode *dir,
108+
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
109+
const struct qstr *name, struct btrfs_inode *dir,
110110
struct btrfs_key *location, u8 type, u64 index)
111111
{
112112
int ret = 0;
@@ -122,17 +122,17 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
122122

123123
key.objectid = btrfs_ino(dir);
124124
key.type = BTRFS_DIR_ITEM_KEY;
125-
key.offset = btrfs_name_hash(name, name_len);
125+
key.offset = btrfs_name_hash(name->name, name->len);
126126

127127
path = btrfs_alloc_path();
128128
if (!path)
129129
return -ENOMEM;
130130

131131
btrfs_cpu_key_to_disk(&disk_key, location);
132132

133-
data_size = sizeof(*dir_item) + name_len;
133+
data_size = sizeof(*dir_item) + name->len;
134134
dir_item = insert_with_overflow(trans, root, path, &key, data_size,
135-
name, name_len);
135+
name->name, name->len);
136136
if (IS_ERR(dir_item)) {
137137
ret = PTR_ERR(dir_item);
138138
if (ret == -EEXIST)
@@ -144,11 +144,11 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
144144
btrfs_set_dir_item_key(leaf, dir_item, &disk_key);
145145
btrfs_set_dir_type(leaf, dir_item, type);
146146
btrfs_set_dir_data_len(leaf, dir_item, 0);
147-
btrfs_set_dir_name_len(leaf, dir_item, name_len);
147+
btrfs_set_dir_name_len(leaf, dir_item, name->len);
148148
btrfs_set_dir_transid(leaf, dir_item, trans->transid);
149149
name_ptr = (unsigned long)(dir_item + 1);
150150

151-
write_extent_buffer(leaf, name, name_ptr, name_len);
151+
write_extent_buffer(leaf, name->name, name_ptr, name->len);
152152
btrfs_mark_buffer_dirty(leaf);
153153

154154
second_insert:
@@ -159,7 +159,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
159159
}
160160
btrfs_release_path(path);
161161

162-
ret2 = btrfs_insert_delayed_dir_index(trans, name, name_len, dir,
162+
ret2 = btrfs_insert_delayed_dir_index(trans, name->name, name->len, dir,
163163
&disk_key, type, index);
164164
out_free:
165165
btrfs_free_path(path);
@@ -208,25 +208,26 @@ static struct btrfs_dir_item *btrfs_lookup_match_dir(
208208
struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
209209
struct btrfs_root *root,
210210
struct btrfs_path *path, u64 dir,
211-
const char *name, int name_len,
211+
const struct qstr *name,
212212
int mod)
213213
{
214214
struct btrfs_key key;
215215
struct btrfs_dir_item *di;
216216

217217
key.objectid = dir;
218218
key.type = BTRFS_DIR_ITEM_KEY;
219-
key.offset = btrfs_name_hash(name, name_len);
219+
key.offset = btrfs_name_hash(name->name, name->len);
220220

221-
di = btrfs_lookup_match_dir(trans, root, path, &key, name, name_len, mod);
221+
di = btrfs_lookup_match_dir(trans, root, path, &key, name->name,
222+
name->len, mod);
222223
if (IS_ERR(di) && PTR_ERR(di) == -ENOENT)
223224
return NULL;
224225

225226
return di;
226227
}
227228

228229
int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
229-
const char *name, int name_len)
230+
const struct qstr *name)
230231
{
231232
int ret;
232233
struct btrfs_key key;
@@ -242,9 +243,10 @@ int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
242243

243244
key.objectid = dir;
244245
key.type = BTRFS_DIR_ITEM_KEY;
245-
key.offset = btrfs_name_hash(name, name_len);
246+
key.offset = btrfs_name_hash(name->name, name->len);
246247

247-
di = btrfs_lookup_match_dir(NULL, root, path, &key, name, name_len, 0);
248+
di = btrfs_lookup_match_dir(NULL, root, path, &key, name->name,
249+
name->len, 0);
248250
if (IS_ERR(di)) {
249251
ret = PTR_ERR(di);
250252
/* Nothing found, we're safe */
@@ -264,11 +266,8 @@ int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
264266
goto out;
265267
}
266268

267-
/*
268-
* see if there is room in the item to insert this
269-
* name
270-
*/
271-
data_size = sizeof(*di) + name_len;
269+
/* See if there is room in the item to insert this name. */
270+
data_size = sizeof(*di) + name->len;
272271
leaf = path->nodes[0];
273272
slot = path->slots[0];
274273
if (data_size + btrfs_item_size(leaf, slot) +
@@ -305,8 +304,7 @@ struct btrfs_dir_item *
305304
btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
306305
struct btrfs_root *root,
307306
struct btrfs_path *path, u64 dir,
308-
u64 index, const char *name, int name_len,
309-
int mod)
307+
u64 index, const struct qstr *name, int mod)
310308
{
311309
struct btrfs_dir_item *di;
312310
struct btrfs_key key;
@@ -315,17 +313,17 @@ btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
315313
key.type = BTRFS_DIR_INDEX_KEY;
316314
key.offset = index;
317315

318-
di = btrfs_lookup_match_dir(trans, root, path, &key, name, name_len, mod);
316+
di = btrfs_lookup_match_dir(trans, root, path, &key, name->name,
317+
name->len, mod);
319318
if (di == ERR_PTR(-ENOENT))
320319
return NULL;
321320

322321
return di;
323322
}
324323

325324
struct btrfs_dir_item *
326-
btrfs_search_dir_index_item(struct btrfs_root *root,
327-
struct btrfs_path *path, u64 dirid,
328-
const char *name, int name_len)
325+
btrfs_search_dir_index_item(struct btrfs_root *root, struct btrfs_path *path,
326+
u64 dirid, const struct qstr *name)
329327
{
330328
struct btrfs_dir_item *di;
331329
struct btrfs_key key;
@@ -340,7 +338,7 @@ btrfs_search_dir_index_item(struct btrfs_root *root,
340338
break;
341339

342340
di = btrfs_match_dir_item_name(root->fs_info, path,
343-
name, name_len);
341+
name->name, name->len);
344342
if (di)
345343
return di;
346344
}

0 commit comments

Comments
 (0)