Btrfs: A few small bug fixes
cover Btrfs: A few small bug fixes
Hi Chris,
Those bugs are small, and the fixes are simple and straitforward.
You can pull from:
git://repo.or.cz/linux-btrfs-devel.git for-chris
Li Zefan (2):
Btrfs: Check if btrfs_next_leaf() returns error in btrfs_listxattr()
Btrfs: Check if btrfs_next_leaf() returns error in btrfs_real_readdir()
Miao Xie (2):
Btrfs: Fix incorrect inode nlink in btrfs_link()
Btrfs: Check validity before setting an acl
--- fs/btrfs/acl.c | 9 +++++---- fs/btrfs/inode.c | 34 +++++++++++++--------------------- fs/btrfs/xattr.c | 33 ++++++++++++--------------------- 3 files changed, 30 insertions(+), 46 deletions(-)
PATCH 1/4 Btrfs: Check if btrfs_next_leaf() returns error in btrfs_listxattr()
btrfs_next_leaf() can return -errno, and we should propagate it to userspace.
This also simplifies how we walk the btree path.
--- fs/btrfs/xattr.c | 33 ++++++++++++--------------------- 1 files changed, 12 insertions(+), 21 deletions(-)
fs/btrfs/xattr.c +12 -21
@@ -180,11 +180,10 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)struct btrfs_path *path;struct extent_buffer *leaf;struct btrfs_dir_item *di; -int ret =0 , slot, advance; +int ret =0 , slot;size_t total_size =0 , size_left = size;unsigned long name_ptr;size_t name_len; -u32 nritems;/* * ok we want all objects associated with this id.
@@ -204,34 +203,24 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size) ret =btrfs_search_slot (NULL , root, &key, path,0 ,0 );if (ret <0 ) goto err; - advance =0 ; +while (1 ) { leaf = path->nodes[0 ]; - nritems =btrfs_header_nritems (leaf); slot = path->slots[0 ];/* this is where we start walking through the path */ -if (advance || slot >= nritems) { +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 */ -if (slot >= nritems-1 ) { - ret =btrfs_next_leaf (root, path); -if (ret) -break ; - leaf = path->nodes[0 ]; - nritems =btrfs_header_nritems (leaf); - slot = path->slots[0 ]; - }else { -/* -* just walking through the slots on this leaf -*/ - slot++; - path->slots[0 ]++; - } + ret =btrfs_next_leaf (root, path); +if (ret <0 ) + goto err; +else if (ret >0 ) +break ; +continue ; } - advance =1 ;btrfs_item_key_to_cpu (leaf, &found_key, slot);
@@ -250,7 +239,7 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)/* we are just looking for how big our buffer needs to be */ if (!size) -continue ; + goto next;if (!buffer || (name_len +1 ) > size_left) { ret = -ERANGE ;
@@ -263,6 +252,8 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size) size_left -= name_len +1 ; buffer += name_len +1 ; +next: + path->slots[0 ]++; } ret = total_size;
Signature · 1 line
1.7.3.1
PATCH 2/4 Btrfs: Check if btrfs_next_leaf() returns error in btrfs_real_readdir()
In reply to Li Zefanbtrfs_next_leaf() can return -errno, and we should propagate it to userspace.
This also simplifies how we walk the btree path.
--- fs/btrfs/inode.c | 28 ++++++++++------------------ 1 files changed, 10 insertions(+), 18 deletions(-)
fs/btrfs/inode.c +10 -18
@@ -4221,10 +4221,8 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,struct btrfs_key found_key;struct btrfs_path *path;int ret; -u32 nritems;struct extent_buffer *leaf;int slot; -int advance;unsigned char d_type;int over =0 ;u32 di_cur;
@@ -4267,27 +4265,19 @@ static int btrfs_real_readdir(struct file *filp, void *dirent, ret =btrfs_search_slot (NULL , root, &key, path,0 ,0 );if (ret <0 ) goto err; - advance =0 ;while (1 ) { leaf = path->nodes[0 ]; - nritems =btrfs_header_nritems (leaf); slot = path->slots[0 ]; -if (advance || slot >= nritems) { -if (slot >= nritems -1 ) { - ret =btrfs_next_leaf (root, path); -if (ret) -break ; - leaf = path->nodes[0 ]; - nritems =btrfs_header_nritems (leaf); - slot = path->slots[0 ]; - }else { - slot++; - path->slots[0 ]++; - } +if (slot >=btrfs_header_nritems (leaf)) { + ret =btrfs_next_leaf (root, path); +if (ret <0 ) + goto err; +else if (ret >0 ) +break ; +continue ; } - advance =1 ; item =btrfs_item_nr (leaf, slot);btrfs_item_key_to_cpu (leaf, &found_key, slot);
@@ -4296,7 +4286,7 @@ static int btrfs_real_readdir(struct file *filp, void *dirent,if (btrfs_key_type (&found_key) != key_type)break ;if (found_key.offset < filp->f_pos) -continue ; + goto next; filp->f_pos = found_key.offset;
@@ -4349,6 +4339,8 @@ skip: di_cur += di_len; di = (struct btrfs_dir_item *)((char *)di + di_len); } +next: + path->slots[0 ]++; }/* Reached end of directory/root. Bump pos past the last item. */
Signature · 1 line
1.7.3.1
PATCH 3/4 Btrfs: Fix incorrect inode nlink in btrfs_link()
In reply to Li ZefanFrom: Miao Xie <[email protected]>
Link count of the inode is not decreased if btrfs_set_inode_index() fails.
--- fs/btrfs/inode.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/inode.c +3 -3
@@ -4846,9 +4846,6 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir,if (inode->i_nlink == ~0U )return -EMLINK ; -btrfs_inc_nlink (inode); - inode->i_ctime =CURRENT_TIME ; - err =btrfs_set_inode_index (dir, &index);if (err) goto fail;
@@ -4864,6 +4861,9 @@ static int btrfs_link(struct dentry *old_dentry, struct inode *dir, goto fail; } +btrfs_inc_nlink (inode); + inode->i_ctime =CURRENT_TIME ; +btrfs_set_trans_block_group (trans, dir);ihold (inode);
Signature · 1 line
1.7.3.1
PATCH 4/4 Btrfs: Check validity before setting an acl
In reply to Li ZefanFrom: Miao Xie <[email protected]>
Call posix_acl_valid() to check if an acl is valid or not.
--- fs/btrfs/acl.c | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/acl.c +5 -4
@@ -178,16 +178,17 @@ static int btrfs_xattr_acl_set(struct dentry *dentry, const char *name,if (value) { acl =posix_acl_from_xattr (value, size); -if (acl ==NULL ) { - value =NULL ; - size =0 ; +if (acl) { + ret =posix_acl_valid (acl); +if (ret) + goto out; }else if (IS_ERR (acl)) {return PTR_ERR (acl); } } ret =btrfs_set_acl (NULL , dentry->d_inode, acl, type); - +out:posix_acl_release (acl);return ret;
Signature · 1 line
1.7.3.1
Excerpts from Li Zefan's message of 2011-04-13 03:42:01 -0400:
Quoted 7 lines
Hi Chris,
Those bugs are small, and the fixes are simple and straitforward.
You can pull from:
git://repo.or.cz/linux-btrfs-devel.gitfor-chris
Thanks these are now in my master branch.
-chris