Skip to contentSkip to conversation

ext2: return -ENODATA for NULL i_file_acl in ext2_xattr_list

PATCH In review Wang Sheng-Hui 2 participants 3 messages Jul 13, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ext2: return -ENODATA for NULL i_file_acl in ext2_xattr_list

Hi,

In ext2_xattr_list, if (!EXT2_I(inode)->i_file_acl) is true, we should return -ENODATA instead of 0. Following patch is against 2.6.35-rc5. Please check it.

---
fs/ext2/xattr.c | 2 +-

1 files changed, 1 insertions(+), 1 deletions(-)
fs/ext2/xattr.c +0 -0
index 7c39157..5ecbbd8 100644
@@ -263,7 +263,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer,

size_t buffer_size)
buffer, (long)buffer_size);

down_read(&EXT2_I(inode)->xattr_sem);
- error = 0;
+ error = -ENODATA;
if (!EXT2_I(inode)->i_file_acl)
goto cleanup;
ea_idebug(inode, "reading block %d", EXT2_I(inode)->i_file_acl);

Signature · 7 lines
1.7.1.1



-- 
Thanks and Regards,
shenghui
#1 lore raw

Review ext2_xattr_list(struct dentry *dentry, char *buffer, · line 269

Quoted 12 lines · Wang Sheng-Hui

In ext2_xattr_list, if (!EXT2_I(inode)->i_file_acl) is true, we should return -ENODATA instead of 0.

(quoted diff) +1 -1
@@ -263,7 +263,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer,
         size_t buffer_size)
 
         down_read(&EXT2_I(inode)->xattr_sem);
-        error = 0;
+        error = -ENODATA;
         if (!EXT2_I(inode)->i_file_acl)
                 goto cleanup;
         ea_idebug(inode, "reading block %d", EXT2_I(inode)->i_file_acl);

The "error" value gets overwritten almost immediately with -EIO, and then at the end of the function if there is an xattr block but it doesn't contain any attributes (I'm not sure if this could happen, but it seems possible) it will return "error = buffer_size - rest; /* total size */", so 0 if "rest" was not changed from its initial value of buffer_size.

The question is why this return value should be changed to -ENODATA in the first place? This isn't true for ext3_xattr_list() or ext4_xattr_list(). I tend to think it is not an error to get back an empty list, and applications shouldn't treat it as such. Most applications will check "if (rc < 0)" and treat it as an error. This is different than e.g. requesting a specific value by name (which does return -ENODATA) because it would otherwise be ambiguous whether the xattr existed but had zero size or didn't exist at all.

Cheers, Andreas

author
#2 lore raw

2010/7/14 Andreas Dilger <[email protected]>:

Quoted 4 lines

The "error" value gets overwritten almost immediately with -EIO, and then at the end of the function if there is an xattr block but it doesn't contain any attributes (I'm not sure if this could happen, but it seems possible) it will return "error = buffer_size - rest;  /* total size */", so 0 if "rest" was not changed from its initial value of buffer_size.

The question is why this return value should be changed to -ENODATA in the first place?  This isn't true for ext3_xattr_list() or ext4_xattr_list().  I tend to think it is not an error to get back an empty list, and applications shouldn't treat it as such.  Most applications will check "if (rc < 0)" and treat it as an error.  This is different than e.g. requesting a specific value by name (which does return -ENODATA) because it would otherwise be ambiguous whether the xattr existed but had zero size or didn't exist at all.

Thanks for your explanation!

Signature · 2 lines
Thanks and Best Regards,
shenghui