mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-07 14:32:23 +00:00
btrfs: use btrfs_for_each_slot in btrfs_listxattr
This function can be simplified by refactoring to use the new iterator macro. No functional changes. Signed-off-by: Marcos Paulo de Souza <mpdesouza@suse.com> Signed-off-by: Gabriel Niebler <gniebler@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
43cb1478de
commit
184b3d1900
@ -272,10 +272,12 @@ int btrfs_setxattr_trans(struct inode *inode, const char *name,
|
|||||||
|
|
||||||
ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
||||||
{
|
{
|
||||||
|
struct btrfs_key found_key;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct inode *inode = d_inode(dentry);
|
struct inode *inode = d_inode(dentry);
|
||||||
struct btrfs_root *root = BTRFS_I(inode)->root;
|
struct btrfs_root *root = BTRFS_I(inode)->root;
|
||||||
struct btrfs_path *path;
|
struct btrfs_path *path;
|
||||||
|
int iter_ret = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t total_size = 0, size_left = size;
|
size_t total_size = 0, size_left = size;
|
||||||
|
|
||||||
@ -294,44 +296,23 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
|||||||
path->reada = READA_FORWARD;
|
path->reada = READA_FORWARD;
|
||||||
|
|
||||||
/* search for our xattrs */
|
/* search for our xattrs */
|
||||||
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
|
btrfs_for_each_slot(root, &key, &found_key, path, iter_ret) {
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
int slot;
|
int slot;
|
||||||
struct btrfs_dir_item *di;
|
struct btrfs_dir_item *di;
|
||||||
struct btrfs_key found_key;
|
|
||||||
u32 item_size;
|
u32 item_size;
|
||||||
u32 cur;
|
u32 cur;
|
||||||
|
|
||||||
leaf = path->nodes[0];
|
leaf = path->nodes[0];
|
||||||
slot = path->slots[0];
|
slot = path->slots[0];
|
||||||
|
|
||||||
/* this is where we start walking through the path */
|
|
||||||
if (slot >= btrfs_header_nritems(leaf)) {
|
|
||||||
/*
|
|
||||||
* if we've reached the last slot in this leaf we need
|
|
||||||
* to go to the next leaf and reset everything
|
|
||||||
*/
|
|
||||||
ret = btrfs_next_leaf(root, path);
|
|
||||||
if (ret < 0)
|
|
||||||
goto err;
|
|
||||||
else if (ret > 0)
|
|
||||||
break;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
btrfs_item_key_to_cpu(leaf, &found_key, slot);
|
|
||||||
|
|
||||||
/* check to make sure this item is what we want */
|
/* check to make sure this item is what we want */
|
||||||
if (found_key.objectid != key.objectid)
|
if (found_key.objectid != key.objectid)
|
||||||
break;
|
break;
|
||||||
if (found_key.type > BTRFS_XATTR_ITEM_KEY)
|
if (found_key.type > BTRFS_XATTR_ITEM_KEY)
|
||||||
break;
|
break;
|
||||||
if (found_key.type < BTRFS_XATTR_ITEM_KEY)
|
if (found_key.type < BTRFS_XATTR_ITEM_KEY)
|
||||||
goto next_item;
|
continue;
|
||||||
|
|
||||||
di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
|
di = btrfs_item_ptr(leaf, slot, struct btrfs_dir_item);
|
||||||
item_size = btrfs_item_size(leaf, slot);
|
item_size = btrfs_item_size(leaf, slot);
|
||||||
@ -351,8 +332,8 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
|||||||
goto next;
|
goto next;
|
||||||
|
|
||||||
if (!buffer || (name_len + 1) > size_left) {
|
if (!buffer || (name_len + 1) > size_left) {
|
||||||
ret = -ERANGE;
|
iter_ret = -ERANGE;
|
||||||
goto err;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
read_extent_buffer(leaf, buffer, name_ptr, name_len);
|
read_extent_buffer(leaf, buffer, name_ptr, name_len);
|
||||||
@ -364,12 +345,13 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
|||||||
cur += this_len;
|
cur += this_len;
|
||||||
di = (struct btrfs_dir_item *)((char *)di + this_len);
|
di = (struct btrfs_dir_item *)((char *)di + this_len);
|
||||||
}
|
}
|
||||||
next_item:
|
|
||||||
path->slots[0]++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (iter_ret < 0)
|
||||||
|
ret = iter_ret;
|
||||||
|
else
|
||||||
ret = total_size;
|
ret = total_size;
|
||||||
|
|
||||||
err:
|
|
||||||
btrfs_free_path(path);
|
btrfs_free_path(path);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
Reference in New Issue
Block a user