erofs: code cleanup by removing ifdef macro surrounding
PATCH 1/1 erofs: code cleanup by removing ifdef macro surrounding
Define erofs_listxattr and erofs_xattr_handlers to NULL when CONFIG_EROFS_FS_XATTR is not enabled, then we can remove many ugly ifdef macros in the code.
---
Only compile tested.
fs/erofs/inode.c | 6 ------ fs/erofs/namei.c | 2 -- fs/erofs/super.c | 4 +--- fs/erofs/xattr.h | 7 ++----- 4 files changed, 3 insertions(+), 16 deletions(-)
fs/erofs/inode.c +0 -6
@@ -311,27 +311,21 @@ int erofs_getattr(const struct path *path, struct kstat *stat,const struct inode_operations erofs_generic_iops = { .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endif .get_acl = erofs_get_acl, };const struct inode_operations erofs_symlink_iops = { .get_link = page_get_link, .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endif .get_acl = erofs_get_acl, };const struct inode_operations erofs_fast_symlink_iops = { .get_link = simple_get_link, .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endif .get_acl = erofs_get_acl, };
fs/erofs/namei.c +0 -2
@@ -244,9 +244,7 @@ static struct dentry *erofs_lookup(struct inode *dir,const struct inode_operations erofs_dir_iops = { .lookup = erofs_lookup, .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endif .get_acl = erofs_get_acl, };
fs/erofs/super.c +1 -3
@@ -408,10 +408,8 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent) sb->s_time_gran =1 ; sb->s_op = &erofs_sops; - -#ifdef CONFIG_EROFS_FS_XATTR sb->s_xattr = erofs_xattr_handlers; -#endif +/* set erofs default mount options */ erofs_default_options (sbi);
fs/erofs/xattr.h +2 -5
@@ -76,11 +76,8 @@ static inline int erofs_getxattr(struct inode *inode, int index, return -EOPNOTSUPP; } -static inline ssize_t erofs_listxattr (struct dentry *dentry, -char *buffer,size_t buffer_size) -{ -return -EOPNOTSUPP ; -} +#define erofs_listxattr (NULL) +#define erofs_xattr_handlers (NULL)#endif /* !CONFIG_EROFS_FS_XATTR */ #ifdef CONFIG_EROFS_FS_POSIX_ACL
Signature · 1 line
2.20.1
Hi Chengguang,
Quoted 19 lines · Chengguang Xu
Define
erofs_listxattranderofs_xattr_handlersto NULL whenCONFIG_EROFS_FS_XATTRis not enabled, then we can remove many ugly ifdef macros in the code.Signed-off-by Chengguang Xu <[email protected]>---
Only compile tested.fs/erofs/inode.c | 6 ------ fs/erofs/namei.c | 2 -- fs/erofs/super.c | 4 +--- fs/erofs/xattr.h | 7 ++----- 4 files changed, 3 insertions(+), 16 deletions(-)fs/erofs/inode.c +0
-0
fs/erofs/inode.c int erofs_getattr(const struct path *path, struct kstat *stat, · line 316
Quoted 6 lines
fs/erofs/inode.c +0
-2@@ -311,27 +311,21 @@ int erofs_getattr(const struct path *path, struct kstat *stat,const struct inode_operations erofs_generic_iops = { .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endif
It seems equivalent. And it seems ext2 and f2fs behave in the same way... But I'm not sure whether we'd return 0 (if I didn't see fs/xattr.c by mistake) or -EOPNOTSUPP here... Some thoughts about this?
Anyway, I'm fine with that if return 0 is okay here, but I'd like to know your and Chao's thoughts about this... I will play with it later as well.
Thanks,
Gao Xiang
Quoted 73 lines
fs/erofs/inode.c +0
-4.get_acl = erofs_get_acl, };const struct inode_operations erofs_symlink_iops = { .get_link = page_get_link, .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endif .get_acl = erofs_get_acl, };const struct inode_operations erofs_fast_symlink_iops = { .get_link = simple_get_link, .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endif .get_acl = erofs_get_acl, };fs/erofs/namei.c +0
-2@@ -244,9 +244,7 @@ static struct dentry *erofs_lookup(struct inode *dir,const struct inode_operations erofs_dir_iops = { .lookup = erofs_lookup, .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endif .get_acl = erofs_get_acl, };fs/erofs/super.c +1
-3@@ -408,10 +408,8 @@ static int erofs_fill_super(struct super_block *sb, void *data, int silent) sb->s_time_gran =1 ; sb->s_op = &erofs_sops; - -#ifdef CONFIG_EROFS_FS_XATTR sb->s_xattr = erofs_xattr_handlers; -#endif +/* set erofs default mount options */ erofs_default_options (sbi);fs/erofs/xattr.h +2
-5@@ -76,11 +76,8 @@ static inline int erofs_getxattr(struct inode *inode, int index, return -EOPNOTSUPP; } -static inline ssize_t erofs_listxattr (struct dentry *dentry, -char *buffer,size_t buffer_size) -{ -return -EOPNOTSUPP ; -} +#define erofs_listxattr (NULL) +#define erofs_xattr_handlers (NULL)#endif /* !CONFIG_EROFS_FS_XATTR */ #ifdef CONFIG_EROFS_FS_POSIX_ACL Signature · 1 line
2.20.1
Quoted 23 lines · Gao Xiang
Hi Chengguang,
Quoted 20 lines · Chengguang Xu
Define
erofs_listxattranderofs_xattr_handlersto NULL whenCONFIG_EROFS_FS_XATTRis not enabled, then we can remove many ugly ifdef macros in the code.Signed-off-by Chengguang Xu <[email protected]>---
Only compile tested.fs/erofs/inode.c | 6 ------ fs/erofs/namei.c | 2 -- fs/erofs/super.c | 4 +--- fs/erofs/xattr.h | 7 ++----- 4 files changed, 3 insertions(+), 16 deletions(-)fs/erofs/inode.c +0
-0@@ -311,27 +311,21 @@ int erofs_getattr(const struct path *path, struct kstat *stat,
Quoted 7 lines
fs/erofs/inode.c int erofs_getattr(const struct path *path, struct kstat *stat, · line 316
Quoted 5 lines
fs/erofs/inode.c +0
-2const struct inode_operations erofs_generic_iops = { .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endifIt seems equivalent. And it seems ext2 and f2fs behave in the same way...
I posted similar patch for ext2 and Jack merged to his tree the other day, though that series also included a real bugfix. I also posted similar patch to f2fs, so if erofs and f2fs merge these patches then all three will behave in the same way, ;-)
You may refer below link for the detail.
https://lore.kernel.org/linux-ext4/[email protected]/
Quoted 4 lines
But I'm not sure whether we'd return 0 (if I didn't see
fs/xattr.cby mistake) or-EOPNOTSUPPhere... Some thoughts about this? >
Anyway, I'm fine with that if return 0 is okay here, but I'd like to know your and Chao's thoughts about this... I will play with it later as well.
Originally, we set erofs_listxattr to ->listxattr only when the config macro CONFIG_EROFS_FS_XATTR is enabled, it means that erofs_listxattr() never returns -EOPNOTSUPP in any case, so actually there is no logic change here, right?
Thanks,
cgxu
Quoted 37 lines · cgxu
Quoted 17 lines · Gao Xiang
Hi Chengguang,
Quoted 14 lines · Chengguang Xu
Define
erofs_listxattranderofs_xattr_handlersto NULL whenCONFIG_EROFS_FS_XATTRis not enabled, then we can remove many ugly ifdef macros in the code.Signed-off-by Chengguang Xu <[email protected]>---
Only compile tested.fs/erofs/inode.c | 6 ------ fs/erofs/namei.c | 2 -- fs/erofs/super.c | 4 +--- fs/erofs/xattr.h | 7 ++----- 4 files changed, 3 insertions(+), 16 deletions(-)Quoted 12 lines
fs/erofs/inode.c int erofs_getattr(const struct path *path, struct kstat *stat, · line 315
Quoted 10 lines
fs/erofs/inode.c +0
-2@@ -311,27 +311,21 @@ int erofs_getattr(const struct path *path, struct kstat *stat,const struct inode_operations erofs_generic_iops = { .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endifIt seems equivalent. And it seems ext2 and f2fs behave in the same way...
I posted similar patch for ext2 and Jack merged to his tree the other day, though that series also included a real bugfix. I also posted similar patch to f2fs, so if erofs and f2fs merge these patches then all three will behave in the same way, ;-)
Quoted 3 lines
You may refer below link for the detail.
Thanks for your link...
Quoted 7 lines
Quoted 6 lines
But I'm not sure whether we'd return 0 (if I didn't see
fs/xattr.cby mistake) or-EOPNOTSUPPhere... Some thoughts about this? >
Anyway, I'm fine with that if return 0 is okay here, but I'd like to know your and Chao's thoughts about this... I will play with it later as well.
Quoted 5 lines
Originally, we set
erofs_listxattrto ->listxattr only when the config macroCONFIG_EROFS_FS_XATTRis enabled, it means thaterofs_listxattr()never returns-EOPNOTSUPPin any case, so actually there is no logic change here, right?
Yeah, I agree there is no logic change, so I'm fine with the patch. But I'm little worry about if return 0 is actually wrong here...
see the return value at:
http://man7.org/linux/man-pages/man2/listxattr.2.html
Thanks,
Gao Xiang
Quoted 5 lines
Thanks,
cgxu
Chao Yu
Reviewed-byQuoted 38 lines · Gao Xiang
Quoted 37 lines · cgxu
Quoted 17 lines · Gao Xiang
Hi Chengguang,
Quoted 14 lines · Chengguang Xu
Define
erofs_listxattranderofs_xattr_handlersto NULL whenCONFIG_EROFS_FS_XATTRis not enabled, then we can remove many ugly ifdef macros in the code.Signed-off-by Chengguang Xu <[email protected]>---
Only compile tested.fs/erofs/inode.c | 6 ------ fs/erofs/namei.c | 2 -- fs/erofs/super.c | 4 +--- fs/erofs/xattr.h | 7 ++----- 4 files changed, 3 insertions(+), 16 deletions(-)Quoted 12 lines
fs/erofs/inode.c int erofs_getattr(const struct path *path, struct kstat *stat, · line 315
Quoted 10 lines
fs/erofs/inode.c +0
-2@@ -311,27 +311,21 @@ int erofs_getattr(const struct path *path, struct kstat *stat,const struct inode_operations erofs_generic_iops = { .getattr = erofs_getattr, -#ifdef CONFIG_EROFS_FS_XATTR .listxattr = erofs_listxattr, -#endifIt seems equivalent. And it seems ext2 and f2fs behave in the same way...
I posted similar patch for ext2 and Jack merged to his tree the other day, though that series also included a real bugfix. I also posted similar patch to f2fs, so if erofs and f2fs merge these patches then all three will behave in the same way, ;-)
Quoted 12 lines
Quoted 3 lines
You may refer below link for the detail.
Thanks for your link...
Quoted 6 lines
Quoted 6 lines
But I'm not sure whether we'd return 0 (if I didn't see
fs/xattr.cby mistake) or-EOPNOTSUPPhere... Some thoughts about this? >
Anyway, I'm fine with that if return 0 is okay here, but I'd like to know your and Chao's thoughts about this... I will play with it later as well.
I'm okay with this change, please feel free to add:
Quoted 7 lines
Quoted 6 lines
Originally, we set
erofs_listxattrto ->listxattr only when the config macroCONFIG_EROFS_FS_XATTRis enabled, it means thaterofs_listxattr()never returns-EOPNOTSUPPin any case, so actually there is no logic change here, right?
Quoted 5 lines
Yeah, I agree there is no logic change, so I'm fine with the patch. But I'm little worry about if return 0 is actually wrong here...
see the return value at:
http://man7.org/linux/man-pages/man2/listxattr.2.html
Yeah, I guess vfs should check that whether lower filesystem has set .listxattr callback function to decide to return that value, something like:
static ssize_tecryptfs_listxattr(struct dentry *dentry, char *list, size_t size) {
...
if (!d_inode(lower_dentry)->i_op->listxattr) {
rc = -EOPNOTSUPP;
goto out;
}
...
rc = d_inode(lower_dentry)->i_op->listxattr(lower_dentry, list, size);...
}
Quoted 12 lines
Thanks,
Gao XiangQuoted 5 lines
Thanks,
cgxu.
On Wed, May 27, 2020 at 09:55:17AM +0800, Chao Yu wrote:
...
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Originally, we set
erofs_listxattrto ->listxattr only when the config macroCONFIG_EROFS_FS_XATTRis enabled, it means thaterofs_listxattr()never returns-EOPNOTSUPPin any case, so actually there is no logic change here, right?Quoted 5 lines
Yeah, I agree there is no logic change, so I'm fine with the patch. But I'm little worry about if return 0 is actually wrong here...
see the return value at:
http://man7.org/linux/man-pages/man2/listxattr.2.htmlYeah, I guess vfs should check that whether lower filesystem has set .listxattr callback function to decide to return that value, something like:
static
ssize_tecryptfs_listxattr(struct dentry *dentry, char *list, size_t size){
...
Quoted 8 lines
if (!d_inode(lower_dentry)->i_op->listxattr) { rc = -EOPNOTSUPP; goto out; } ... rc = d_inode(lower_dentry)->i_op->listxattr(lower_dentry, list, size);...
}
This approach seems better. ;) Let me recheck all of this. Maybe we could submit a patch to fsdevel for some further advice...
Thanks,
Gao Xiang
Quoted 15 lines
Quoted 14 lines
Thanks,
Gao XiangQuoted 5 lines
Thanks,
cgxu.
Quoted 33 lines · Gao Xiang
On Wed, May 27, 2020 at 09:55:17AM +0800, Chao Yu wrote:
...
Quoted 20 lines
Quoted 7 lines
Quoted 6 lines
Originally, we set
erofs_listxattrto ->listxattr only when the config macroCONFIG_EROFS_FS_XATTRis enabled, it means thaterofs_listxattr()never returns-EOPNOTSUPPin any case, so actually there is no logic change here, right?Quoted 5 lines
Yeah, I agree there is no logic change, so I'm fine with the patch. But I'm little worry about if return 0 is actually wrong here...
see the return value at:
http://man7.org/linux/man-pages/man2/listxattr.2.htmlYeah, I guess vfs should check that whether lower filesystem has set .listxattr callback function to decide to return that value, something like:
static
ssize_tecryptfs_listxattr(struct dentry *dentry, char *list, size_t size){
...Quoted 8 lines
if (!d_inode(lower_dentry)->i_op->listxattr) { rc = -EOPNOTSUPP; goto out; } ... rc = d_inode(lower_dentry)->i_op->listxattr(lower_dentry, list, size);...
}
Quoted 3 lines
This approach seems better. ;) Let me recheck all of this. Maybe we could submit a patch to fsdevel for some further advice...
I agree that doing the check in vfs layer looks tidy and unified. However, we should be aware this change may break user space tools.
Thanks,
cgxu
Quoted 34 lines · cgxu
Quoted 33 lines · Gao Xiang
On Wed, May 27, 2020 at 09:55:17AM +0800, Chao Yu wrote:
...
Quoted 28 lines
Quoted 7 lines
Quoted 6 lines
Originally, we set
erofs_listxattrto ->listxattr only when the config macroCONFIG_EROFS_FS_XATTRis enabled, it means thaterofs_listxattr()never returns-EOPNOTSUPPin any case, so actually there is no logic change here, right?Quoted 5 lines
Yeah, I agree there is no logic change, so I'm fine with the patch. But I'm little worry about if return 0 is actually wrong here...
see the return value at:
http://man7.org/linux/man-pages/man2/listxattr.2.htmlYeah, I guess vfs should check that whether lower filesystem has set .listxattr callback function to decide to return that value, something like:
static
ssize_tecryptfs_listxattr(struct dentry *dentry, char *list, size_t size){
...if (!d_inode(lower_dentry)->i_op->listxattr) { rc = -EOPNOTSUPP; goto out; } ... rc = d_inode(lower_dentry)->i_op->listxattr(lower_dentry, list, size);...
}
Quoted 6 lines
Quoted 3 lines
This approach seems better. ;) Let me recheck all of this. Maybe we could submit a patch to fsdevel for some further advice...
I agree that doing the check in vfs layer looks tidy and unified. However, we should be aware this change may break user space tools.
I think I already sorted out the reason, it actually seems a regression due to multiple commits, let me try to submit a patch for some advice...
Thanks,
Gao Xiang
Quoted 5 lines
Thanks,
cgxu