Skip to content
This repository has been archived by the owner on Oct 31, 2024. It is now read-only.

Commit

Permalink
btrfs: use struct qstr instead of name and namelen pairs
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
sweettea authored and kdave committed Dec 5, 2022
1 parent 82c0efd commit e43eec8
Show file tree
Hide file tree
Showing 12 changed files with 287 additions and 335 deletions.
26 changes: 12 additions & 14 deletions fs/btrfs/ctree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1516,11 +1516,11 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,

/* root-item.c */
int btrfs_add_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
u64 ref_id, u64 dirid, u64 sequence, const char *name,
int name_len);
u64 ref_id, u64 dirid, u64 sequence,
const struct qstr *name);
int btrfs_del_root_ref(struct btrfs_trans_handle *trans, u64 root_id,
u64 ref_id, u64 dirid, u64 *sequence, const char *name,
int name_len);
u64 ref_id, u64 dirid, u64 *sequence,
const struct qstr *name);
int btrfs_del_root(struct btrfs_trans_handle *trans,
const struct btrfs_key *key);
int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
Expand Down Expand Up @@ -1549,25 +1549,23 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info);

/* dir-item.c */
int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
const char *name, int name_len);
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
int name_len, struct btrfs_inode *dir,
const struct qstr *name);
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
const struct qstr *name, struct btrfs_inode *dir,
struct btrfs_key *location, u8 type, u64 index);
struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path, u64 dir,
const char *name, int name_len,
int mod);
const struct qstr *name, int mod);
struct btrfs_dir_item *
btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path, u64 dir,
u64 index, const char *name, int name_len,
int mod);
u64 index, const struct qstr *name, int mod);
struct btrfs_dir_item *
btrfs_search_dir_index_item(struct btrfs_root *root,
struct btrfs_path *path, u64 dirid,
const char *name, int name_len);
const struct qstr *name);
int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path,
Expand Down Expand Up @@ -1648,10 +1646,10 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry);
int btrfs_set_inode_index(struct btrfs_inode *dir, u64 *index);
int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
struct btrfs_inode *dir, struct btrfs_inode *inode,
const char *name, int name_len);
const struct qstr *name);
int btrfs_add_link(struct btrfs_trans_handle *trans,
struct btrfs_inode *parent_inode, struct btrfs_inode *inode,
const char *name, int name_len, int add_backref, u64 index);
const struct qstr *name, int add_backref, u64 index);
int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry);
int btrfs_truncate_block(struct btrfs_inode *inode, loff_t from, loff_t len,
int front);
Expand Down
50 changes: 24 additions & 26 deletions fs/btrfs/dir-item.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
* to use for the second index (if one is created).
* Will return 0 or -ENOMEM
*/
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
int name_len, struct btrfs_inode *dir,
int btrfs_insert_dir_item(struct btrfs_trans_handle *trans,
const struct qstr *name, struct btrfs_inode *dir,
struct btrfs_key *location, u8 type, u64 index)
{
int ret = 0;
Expand All @@ -122,17 +122,17 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,

key.objectid = btrfs_ino(dir);
key.type = BTRFS_DIR_ITEM_KEY;
key.offset = btrfs_name_hash(name, name_len);
key.offset = btrfs_name_hash(name->name, name->len);

path = btrfs_alloc_path();
if (!path)
return -ENOMEM;

btrfs_cpu_key_to_disk(&disk_key, location);

data_size = sizeof(*dir_item) + name_len;
data_size = sizeof(*dir_item) + name->len;
dir_item = insert_with_overflow(trans, root, path, &key, data_size,
name, name_len);
name->name, name->len);
if (IS_ERR(dir_item)) {
ret = PTR_ERR(dir_item);
if (ret == -EEXIST)
Expand All @@ -144,11 +144,11 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
btrfs_set_dir_item_key(leaf, dir_item, &disk_key);
btrfs_set_dir_type(leaf, dir_item, type);
btrfs_set_dir_data_len(leaf, dir_item, 0);
btrfs_set_dir_name_len(leaf, dir_item, name_len);
btrfs_set_dir_name_len(leaf, dir_item, name->len);
btrfs_set_dir_transid(leaf, dir_item, trans->transid);
name_ptr = (unsigned long)(dir_item + 1);

write_extent_buffer(leaf, name, name_ptr, name_len);
write_extent_buffer(leaf, name->name, name_ptr, name->len);
btrfs_mark_buffer_dirty(leaf);

second_insert:
Expand All @@ -159,7 +159,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, const char *name,
}
btrfs_release_path(path);

ret2 = btrfs_insert_delayed_dir_index(trans, name, name_len, dir,
ret2 = btrfs_insert_delayed_dir_index(trans, name->name, name->len, dir,
&disk_key, type, index);
out_free:
btrfs_free_path(path);
Expand Down Expand Up @@ -208,25 +208,26 @@ static struct btrfs_dir_item *btrfs_lookup_match_dir(
struct btrfs_dir_item *btrfs_lookup_dir_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path, u64 dir,
const char *name, int name_len,
const struct qstr *name,
int mod)
{
struct btrfs_key key;
struct btrfs_dir_item *di;

key.objectid = dir;
key.type = BTRFS_DIR_ITEM_KEY;
key.offset = btrfs_name_hash(name, name_len);
key.offset = btrfs_name_hash(name->name, name->len);

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

return di;
}

int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,
const char *name, int name_len)
const struct qstr *name)
{
int ret;
struct btrfs_key key;
Expand All @@ -242,9 +243,10 @@ int btrfs_check_dir_item_collision(struct btrfs_root *root, u64 dir,

key.objectid = dir;
key.type = BTRFS_DIR_ITEM_KEY;
key.offset = btrfs_name_hash(name, name_len);
key.offset = btrfs_name_hash(name->name, name->len);

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

/*
* see if there is room in the item to insert this
* name
*/
data_size = sizeof(*di) + name_len;
/* See if there is room in the item to insert this name. */
data_size = sizeof(*di) + name->len;
leaf = path->nodes[0];
slot = path->slots[0];
if (data_size + btrfs_item_size(leaf, slot) +
Expand Down Expand Up @@ -305,8 +304,7 @@ struct btrfs_dir_item *
btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path, u64 dir,
u64 index, const char *name, int name_len,
int mod)
u64 index, const struct qstr *name, int mod)
{
struct btrfs_dir_item *di;
struct btrfs_key key;
Expand All @@ -315,17 +313,17 @@ btrfs_lookup_dir_index_item(struct btrfs_trans_handle *trans,
key.type = BTRFS_DIR_INDEX_KEY;
key.offset = index;

di = btrfs_lookup_match_dir(trans, root, path, &key, name, name_len, mod);
di = btrfs_lookup_match_dir(trans, root, path, &key, name->name,
name->len, mod);
if (di == ERR_PTR(-ENOENT))
return NULL;

return di;
}

struct btrfs_dir_item *
btrfs_search_dir_index_item(struct btrfs_root *root,
struct btrfs_path *path, u64 dirid,
const char *name, int name_len)
btrfs_search_dir_index_item(struct btrfs_root *root, struct btrfs_path *path,
u64 dirid, const struct qstr *name)
{
struct btrfs_dir_item *di;
struct btrfs_key key;
Expand All @@ -340,7 +338,7 @@ btrfs_search_dir_index_item(struct btrfs_root *root,
break;

di = btrfs_match_dir_item_name(root->fs_info, path,
name, name_len);
name->name, name->len);
if (di)
return di;
}
Expand Down
Loading

0 comments on commit e43eec8

Please sign in to comment.