* [PATCH 1/2] staging: erofs: support statx
@ 2019-05-28 2:31 Gao Xiang
2019-05-28 2:31 ` [PATCH 2/2] staging: erofs: fix i_blocks calculation Gao Xiang
2019-05-28 2:44 ` [PATCH " Chao Yu
0 siblings, 2 replies; 14+ messages in thread
From: Gao Xiang @ 2019-05-28 2:31 UTC (permalink / raw)
To: Chao Yu, Greg Kroah-Hartman, devel
Cc: LKML, linux-erofs, Chao Yu, Miao Xie, weidu.du, Fang Wei, Gao Xiang
statx() has already been supported in commit a528d35e8bfc
("statx: Add a system call to make enhanced file info available"),
user programs can get more useful attributes.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
drivers/staging/erofs/inode.c | 18 ++++++++++++++++++
drivers/staging/erofs/internal.h | 2 ++
drivers/staging/erofs/namei.c | 1 +
3 files changed, 21 insertions(+)
diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index c7d3b815a798..8da144943ed6 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -285,7 +285,23 @@ struct inode *erofs_iget(struct super_block *sb,
return inode;
}
+int erofs_getattr(const struct path *path, struct kstat *stat,
+ u32 request_mask, unsigned int query_flags)
+{
+ struct inode *const inode = d_inode(path->dentry);
+ struct erofs_vnode *const vi = EROFS_V(inode);
+
+ if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
+ stat->attributes |= STATX_ATTR_COMPRESSED;
+
+ stat->attributes |= STATX_ATTR_IMMUTABLE;
+
+ generic_fillattr(inode, stat);
+ return 0;
+}
+
const struct inode_operations erofs_generic_iops = {
+ .getattr = erofs_getattr,
#ifdef CONFIG_EROFS_FS_XATTR
.listxattr = erofs_listxattr,
#endif
@@ -294,6 +310,7 @@ const struct inode_operations erofs_generic_iops = {
const struct inode_operations erofs_symlink_iops = {
.get_link = page_get_link,
+ .getattr = erofs_getattr,
#ifdef CONFIG_EROFS_FS_XATTR
.listxattr = erofs_listxattr,
#endif
@@ -302,6 +319,7 @@ const struct inode_operations erofs_symlink_iops = {
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
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index c47778b3fabd..911333cdeef4 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -556,6 +556,8 @@ static inline bool is_inode_fast_symlink(struct inode *inode)
}
struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir);
+int erofs_getattr(const struct path *path, struct kstat *stat,
+ u32 request_mask, unsigned int query_flags);
/* namei.c */
extern const struct inode_operations erofs_dir_iops;
diff --git a/drivers/staging/erofs/namei.c b/drivers/staging/erofs/namei.c
index d8d9dc9dab43..fd3ae78d0ba5 100644
--- a/drivers/staging/erofs/namei.c
+++ b/drivers/staging/erofs/namei.c
@@ -247,6 +247,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
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/2] staging: erofs: fix i_blocks calculation
2019-05-28 2:31 [PATCH 1/2] staging: erofs: support statx Gao Xiang
@ 2019-05-28 2:31 ` Gao Xiang
2019-05-28 2:36 ` [PATCH v2 " Gao Xiang
2019-05-28 3:19 ` [PATCH v3 1/2] staging: erofs: support statx Gao Xiang
2019-05-28 2:44 ` [PATCH " Chao Yu
1 sibling, 2 replies; 14+ messages in thread
From: Gao Xiang @ 2019-05-28 2:31 UTC (permalink / raw)
To: Chao Yu, Greg Kroah-Hartman, devel
Cc: LKML, linux-erofs, Chao Yu, Miao Xie, weidu.du, Fang Wei, Gao Xiang
For compressed files, i_blocks should not be calculated
by using i_size. i_u.compressed_blocks is used instead.
In addition, i_blocks is miscalculated for non-compressed
files previously, fix it as well.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
drivers/staging/erofs/inode.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index 8da144943ed6..b1b790767089 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -20,6 +20,7 @@ static int read_inode(struct inode *inode, void *data)
struct erofs_vnode *vi = EROFS_V(inode);
struct erofs_inode_v1 *v1 = data;
const unsigned int advise = le16_to_cpu(v1->i_advise);
+ erofs_blk_t nblks = 0;
vi->data_mapping_mode = __inode_data_mapping(advise);
@@ -60,6 +61,10 @@ static int read_inode(struct inode *inode, void *data)
le32_to_cpu(v2->i_ctime_nsec);
inode->i_size = le64_to_cpu(v2->i_size);
+
+ /* total blocks for compressed files */
+ if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
+ nblks = v2->i_u.compressed_blocks;
} else if (__inode_version(advise) == EROFS_INODE_LAYOUT_V1) {
struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
@@ -90,6 +95,8 @@ static int read_inode(struct inode *inode, void *data)
sbi->build_time_nsec;
inode->i_size = le32_to_cpu(v1->i_size);
+ if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
+ nblks = v1->i_u.compressed_blocks;
} else {
errln("unsupported on-disk inode version %u of nid %llu",
__inode_version(advise), vi->nid);
@@ -97,8 +104,11 @@ static int read_inode(struct inode *inode, void *data)
return -EIO;
}
- /* measure inode.i_blocks as the generic filesystem */
- inode->i_blocks = ((inode->i_size - 1) >> 9) + 1;
+ if (!nblks)
+ /* measure inode.i_blocks as generic filesystems */
+ inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
+ else
+ inode->i_blocks = nblks >> LOG_SECTORS_PER_BLOCK;
return 0;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v2 2/2] staging: erofs: fix i_blocks calculation
2019-05-28 2:31 ` [PATCH 2/2] staging: erofs: fix i_blocks calculation Gao Xiang
@ 2019-05-28 2:36 ` Gao Xiang
2019-05-28 3:02 ` Chao Yu
2019-05-28 3:19 ` [PATCH v3 1/2] staging: erofs: support statx Gao Xiang
1 sibling, 1 reply; 14+ messages in thread
From: Gao Xiang @ 2019-05-28 2:36 UTC (permalink / raw)
To: Chao Yu, Greg Kroah-Hartman, devel
Cc: LKML, linux-erofs, Chao Yu, Miao Xie, weidu.du, Fang Wei, Gao Xiang
For compressed files, i_blocks should not be calculated
by using i_size. i_u.compressed_blocks is used instead.
In addition, i_blocks was miscalculated for non-compressed
files previously, fix it as well.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
change log v2:
- fix description in commit message
- fix to 'inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK'
Thanks,
Gao Xiang
drivers/staging/erofs/inode.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index 8da144943ed6..6e67e018784e 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -20,6 +20,7 @@ static int read_inode(struct inode *inode, void *data)
struct erofs_vnode *vi = EROFS_V(inode);
struct erofs_inode_v1 *v1 = data;
const unsigned int advise = le16_to_cpu(v1->i_advise);
+ erofs_blk_t nblks = 0;
vi->data_mapping_mode = __inode_data_mapping(advise);
@@ -60,6 +61,10 @@ static int read_inode(struct inode *inode, void *data)
le32_to_cpu(v2->i_ctime_nsec);
inode->i_size = le64_to_cpu(v2->i_size);
+
+ /* total blocks for compressed files */
+ if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
+ nblks = v2->i_u.compressed_blocks;
} else if (__inode_version(advise) == EROFS_INODE_LAYOUT_V1) {
struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
@@ -90,6 +95,8 @@ static int read_inode(struct inode *inode, void *data)
sbi->build_time_nsec;
inode->i_size = le32_to_cpu(v1->i_size);
+ if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
+ nblks = v1->i_u.compressed_blocks;
} else {
errln("unsupported on-disk inode version %u of nid %llu",
__inode_version(advise), vi->nid);
@@ -97,8 +104,11 @@ static int read_inode(struct inode *inode, void *data)
return -EIO;
}
- /* measure inode.i_blocks as the generic filesystem */
- inode->i_blocks = ((inode->i_size - 1) >> 9) + 1;
+ if (!nblks)
+ /* measure inode.i_blocks as generic filesystems */
+ inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
+ else
+ inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK;
return 0;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 1/2] staging: erofs: support statx
2019-05-28 2:31 [PATCH 1/2] staging: erofs: support statx Gao Xiang
2019-05-28 2:31 ` [PATCH 2/2] staging: erofs: fix i_blocks calculation Gao Xiang
@ 2019-05-28 2:44 ` Chao Yu
2019-05-28 2:49 ` Gao Xiang
1 sibling, 1 reply; 14+ messages in thread
From: Chao Yu @ 2019-05-28 2:44 UTC (permalink / raw)
To: Gao Xiang, Greg Kroah-Hartman, devel
Cc: LKML, linux-erofs, Chao Yu, Miao Xie, weidu.du, Fang Wei
On 2019/5/28 10:31, Gao Xiang wrote:
> statx() has already been supported in commit a528d35e8bfc
> ("statx: Add a system call to make enhanced file info available"),
> user programs can get more useful attributes.
>
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> ---
> drivers/staging/erofs/inode.c | 18 ++++++++++++++++++
> drivers/staging/erofs/internal.h | 2 ++
> drivers/staging/erofs/namei.c | 1 +
> 3 files changed, 21 insertions(+)
>
> diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
> index c7d3b815a798..8da144943ed6 100644
> --- a/drivers/staging/erofs/inode.c
> +++ b/drivers/staging/erofs/inode.c
> @@ -285,7 +285,23 @@ struct inode *erofs_iget(struct super_block *sb,
> return inode;
> }
>
> +int erofs_getattr(const struct path *path, struct kstat *stat,
> + u32 request_mask, unsigned int query_flags)
> +{
> + struct inode *const inode = d_inode(path->dentry);
> + struct erofs_vnode *const vi = EROFS_V(inode);
> +
> + if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
> + stat->attributes |= STATX_ATTR_COMPRESSED;
> +
> + stat->attributes |= STATX_ATTR_IMMUTABLE;
Xiang,
Should update stat->attributes_mask as well to indicate all erofs supported
attributes bits.
Thanks,
> +
> + generic_fillattr(inode, stat);
> + return 0;
> +}
> +
> const struct inode_operations erofs_generic_iops = {
> + .getattr = erofs_getattr,
> #ifdef CONFIG_EROFS_FS_XATTR
> .listxattr = erofs_listxattr,
> #endif
> @@ -294,6 +310,7 @@ const struct inode_operations erofs_generic_iops = {
>
> const struct inode_operations erofs_symlink_iops = {
> .get_link = page_get_link,
> + .getattr = erofs_getattr,
> #ifdef CONFIG_EROFS_FS_XATTR
> .listxattr = erofs_listxattr,
> #endif
> @@ -302,6 +319,7 @@ const struct inode_operations erofs_symlink_iops = {
>
> 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
> diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
> index c47778b3fabd..911333cdeef4 100644
> --- a/drivers/staging/erofs/internal.h
> +++ b/drivers/staging/erofs/internal.h
> @@ -556,6 +556,8 @@ static inline bool is_inode_fast_symlink(struct inode *inode)
> }
>
> struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir);
> +int erofs_getattr(const struct path *path, struct kstat *stat,
> + u32 request_mask, unsigned int query_flags);
>
> /* namei.c */
> extern const struct inode_operations erofs_dir_iops;
> diff --git a/drivers/staging/erofs/namei.c b/drivers/staging/erofs/namei.c
> index d8d9dc9dab43..fd3ae78d0ba5 100644
> --- a/drivers/staging/erofs/namei.c
> +++ b/drivers/staging/erofs/namei.c
> @@ -247,6 +247,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
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/2] staging: erofs: support statx
2019-05-28 2:44 ` [PATCH " Chao Yu
@ 2019-05-28 2:49 ` Gao Xiang
0 siblings, 0 replies; 14+ messages in thread
From: Gao Xiang @ 2019-05-28 2:49 UTC (permalink / raw)
To: Chao Yu
Cc: Greg Kroah-Hartman, devel, LKML, linux-erofs, Chao Yu, Miao Xie,
weidu.du, Fang Wei
Hi Chao,
On 2019/5/28 10:44, Chao Yu wrote:
> On 2019/5/28 10:31, Gao Xiang wrote:
>> statx() has already been supported in commit a528d35e8bfc
>> ("statx: Add a system call to make enhanced file info available"),
>> user programs can get more useful attributes.
>>
>> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
>> ---
>> drivers/staging/erofs/inode.c | 18 ++++++++++++++++++
>> drivers/staging/erofs/internal.h | 2 ++
>> drivers/staging/erofs/namei.c | 1 +
>> 3 files changed, 21 insertions(+)
>>
>> diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
>> index c7d3b815a798..8da144943ed6 100644
>> --- a/drivers/staging/erofs/inode.c
>> +++ b/drivers/staging/erofs/inode.c
>> @@ -285,7 +285,23 @@ struct inode *erofs_iget(struct super_block *sb,
>> return inode;
>> }
>>
>> +int erofs_getattr(const struct path *path, struct kstat *stat,
>> + u32 request_mask, unsigned int query_flags)
>> +{
>> + struct inode *const inode = d_inode(path->dentry);
>> + struct erofs_vnode *const vi = EROFS_V(inode);
>> +
>> + if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
>> + stat->attributes |= STATX_ATTR_COMPRESSED;
>> +
>> + stat->attributes |= STATX_ATTR_IMMUTABLE;
>
> Xiang,
>
> Should update stat->attributes_mask as well to indicate all erofs supported
> attributes bits.
opps, my fault... I just verified these patches stability.
Will do in the next version.
Thanks,
Gao Xiang
>
> Thanks,
>
>> +
>> + generic_fillattr(inode, stat);
>> + return 0;
>> +}
>> +
>> const struct inode_operations erofs_generic_iops = {
>> + .getattr = erofs_getattr,
>> #ifdef CONFIG_EROFS_FS_XATTR
>> .listxattr = erofs_listxattr,
>> #endif
>> @@ -294,6 +310,7 @@ const struct inode_operations erofs_generic_iops = {
>>
>> const struct inode_operations erofs_symlink_iops = {
>> .get_link = page_get_link,
>> + .getattr = erofs_getattr,
>> #ifdef CONFIG_EROFS_FS_XATTR
>> .listxattr = erofs_listxattr,
>> #endif
>> @@ -302,6 +319,7 @@ const struct inode_operations erofs_symlink_iops = {
>>
>> 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
>> diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
>> index c47778b3fabd..911333cdeef4 100644
>> --- a/drivers/staging/erofs/internal.h
>> +++ b/drivers/staging/erofs/internal.h
>> @@ -556,6 +556,8 @@ static inline bool is_inode_fast_symlink(struct inode *inode)
>> }
>>
>> struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir);
>> +int erofs_getattr(const struct path *path, struct kstat *stat,
>> + u32 request_mask, unsigned int query_flags);
>>
>> /* namei.c */
>> extern const struct inode_operations erofs_dir_iops;
>> diff --git a/drivers/staging/erofs/namei.c b/drivers/staging/erofs/namei.c
>> index d8d9dc9dab43..fd3ae78d0ba5 100644
>> --- a/drivers/staging/erofs/namei.c
>> +++ b/drivers/staging/erofs/namei.c
>> @@ -247,6 +247,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
>>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/2] staging: erofs: fix i_blocks calculation
2019-05-28 2:36 ` [PATCH v2 " Gao Xiang
@ 2019-05-28 3:02 ` Chao Yu
2019-05-28 3:23 ` Gao Xiang
2019-05-28 6:57 ` Dan Carpenter
0 siblings, 2 replies; 14+ messages in thread
From: Chao Yu @ 2019-05-28 3:02 UTC (permalink / raw)
To: Gao Xiang, Greg Kroah-Hartman, devel
Cc: LKML, linux-erofs, Chao Yu, Miao Xie, weidu.du, Fang Wei
On 2019/5/28 10:36, Gao Xiang wrote:
> For compressed files, i_blocks should not be calculated
> by using i_size. i_u.compressed_blocks is used instead.
>
> In addition, i_blocks was miscalculated for non-compressed
> files previously, fix it as well.
>
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> ---
> change log v2:
> - fix description in commit message
> - fix to 'inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK'
>
> Thanks,
> Gao Xiang
>
> drivers/staging/erofs/inode.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
> index 8da144943ed6..6e67e018784e 100644
> --- a/drivers/staging/erofs/inode.c
> +++ b/drivers/staging/erofs/inode.c
> @@ -20,6 +20,7 @@ static int read_inode(struct inode *inode, void *data)
> struct erofs_vnode *vi = EROFS_V(inode);
> struct erofs_inode_v1 *v1 = data;
> const unsigned int advise = le16_to_cpu(v1->i_advise);
> + erofs_blk_t nblks = 0;
>
> vi->data_mapping_mode = __inode_data_mapping(advise);
>
> @@ -60,6 +61,10 @@ static int read_inode(struct inode *inode, void *data)
> le32_to_cpu(v2->i_ctime_nsec);
>
> inode->i_size = le64_to_cpu(v2->i_size);
> +
> + /* total blocks for compressed files */
> + if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
> + nblks = v2->i_u.compressed_blocks;
Xiang,
It needs to use le32_to_cpu(). ;)
> } else if (__inode_version(advise) == EROFS_INODE_LAYOUT_V1) {
> struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
>
> @@ -90,6 +95,8 @@ static int read_inode(struct inode *inode, void *data)
> sbi->build_time_nsec;
>
> inode->i_size = le32_to_cpu(v1->i_size);
> + if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
> + nblks = v1->i_u.compressed_blocks;
Ditto.
Thanks,
> } else {
> errln("unsupported on-disk inode version %u of nid %llu",
> __inode_version(advise), vi->nid);
> @@ -97,8 +104,11 @@ static int read_inode(struct inode *inode, void *data)
> return -EIO;
> }
>
> - /* measure inode.i_blocks as the generic filesystem */
> - inode->i_blocks = ((inode->i_size - 1) >> 9) + 1;
> + if (!nblks)
> + /* measure inode.i_blocks as generic filesystems */
> + inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
> + else
> + inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK;
> return 0;
> }
>
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v3 1/2] staging: erofs: support statx
2019-05-28 2:31 ` [PATCH 2/2] staging: erofs: fix i_blocks calculation Gao Xiang
2019-05-28 2:36 ` [PATCH v2 " Gao Xiang
@ 2019-05-28 3:19 ` Gao Xiang
2019-05-28 3:19 ` [PATCH v3 2/2] staging: erofs: fix i_blocks calculation Gao Xiang
2019-05-28 3:28 ` [PATCH v3 1/2] staging: erofs: support statx Chao Yu
1 sibling, 2 replies; 14+ messages in thread
From: Gao Xiang @ 2019-05-28 3:19 UTC (permalink / raw)
To: Chao Yu, Greg Kroah-Hartman, devel
Cc: LKML, linux-erofs, Chao Yu, Miao Xie, weidu.du, Fang Wei, Gao Xiang
statx() has already been supported in commit a528d35e8bfc
("statx: Add a system call to make enhanced file info available"),
user programs can get more useful attributes.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
change log v3:
- update attributes_mask to indicate bits which erofs support
as Chao pointed out;
- already tested with samples/vfs/test-statx.c;
Thanks,
Gao Xiang
drivers/staging/erofs/inode.c | 20 ++++++++++++++++++++
drivers/staging/erofs/internal.h | 2 ++
drivers/staging/erofs/namei.c | 1 +
3 files changed, 23 insertions(+)
diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index c7d3b815a798..1c220900e1a0 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -285,7 +285,25 @@ struct inode *erofs_iget(struct super_block *sb,
return inode;
}
+int erofs_getattr(const struct path *path, struct kstat *stat,
+ u32 request_mask, unsigned int query_flags)
+{
+ struct inode *const inode = d_inode(path->dentry);
+ struct erofs_vnode *const vi = EROFS_V(inode);
+
+ if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
+ stat->attributes |= STATX_ATTR_COMPRESSED;
+
+ stat->attributes |= STATX_ATTR_IMMUTABLE;
+ stat->attributes_mask |= (STATX_ATTR_COMPRESSED |
+ STATX_ATTR_IMMUTABLE);
+
+ generic_fillattr(inode, stat);
+ return 0;
+}
+
const struct inode_operations erofs_generic_iops = {
+ .getattr = erofs_getattr,
#ifdef CONFIG_EROFS_FS_XATTR
.listxattr = erofs_listxattr,
#endif
@@ -294,6 +312,7 @@ const struct inode_operations erofs_generic_iops = {
const struct inode_operations erofs_symlink_iops = {
.get_link = page_get_link,
+ .getattr = erofs_getattr,
#ifdef CONFIG_EROFS_FS_XATTR
.listxattr = erofs_listxattr,
#endif
@@ -302,6 +321,7 @@ const struct inode_operations erofs_symlink_iops = {
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
diff --git a/drivers/staging/erofs/internal.h b/drivers/staging/erofs/internal.h
index c47778b3fabd..911333cdeef4 100644
--- a/drivers/staging/erofs/internal.h
+++ b/drivers/staging/erofs/internal.h
@@ -556,6 +556,8 @@ static inline bool is_inode_fast_symlink(struct inode *inode)
}
struct inode *erofs_iget(struct super_block *sb, erofs_nid_t nid, bool dir);
+int erofs_getattr(const struct path *path, struct kstat *stat,
+ u32 request_mask, unsigned int query_flags);
/* namei.c */
extern const struct inode_operations erofs_dir_iops;
diff --git a/drivers/staging/erofs/namei.c b/drivers/staging/erofs/namei.c
index d8d9dc9dab43..fd3ae78d0ba5 100644
--- a/drivers/staging/erofs/namei.c
+++ b/drivers/staging/erofs/namei.c
@@ -247,6 +247,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
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v3 2/2] staging: erofs: fix i_blocks calculation
2019-05-28 3:19 ` [PATCH v3 1/2] staging: erofs: support statx Gao Xiang
@ 2019-05-28 3:19 ` Gao Xiang
2019-05-28 3:28 ` Chao Yu
2019-05-28 3:28 ` [PATCH v3 1/2] staging: erofs: support statx Chao Yu
1 sibling, 1 reply; 14+ messages in thread
From: Gao Xiang @ 2019-05-28 3:19 UTC (permalink / raw)
To: Chao Yu, Greg Kroah-Hartman, devel
Cc: LKML, linux-erofs, Chao Yu, Miao Xie, weidu.du, Fang Wei, Gao Xiang
For compressed files, i_blocks should not be calculated
by using i_size. use i_u.compressed_blocks instead.
In addition, i_blocks was miscalculated for non-compressed
files previously, fix it as well.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
---
change log v3:
- wrap i.u.compressed_blocks with le32_to_cpu() as Chao pointed out;
change log v2:
- fix description in commit message;
- fix to 'inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK'.
Thanks,
Gao Xiang
drivers/staging/erofs/inode.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
index 1c220900e1a0..9520419f746c 100644
--- a/drivers/staging/erofs/inode.c
+++ b/drivers/staging/erofs/inode.c
@@ -20,6 +20,7 @@ static int read_inode(struct inode *inode, void *data)
struct erofs_vnode *vi = EROFS_V(inode);
struct erofs_inode_v1 *v1 = data;
const unsigned int advise = le16_to_cpu(v1->i_advise);
+ erofs_blk_t nblks = 0;
vi->data_mapping_mode = __inode_data_mapping(advise);
@@ -60,6 +61,10 @@ static int read_inode(struct inode *inode, void *data)
le32_to_cpu(v2->i_ctime_nsec);
inode->i_size = le64_to_cpu(v2->i_size);
+
+ /* total blocks for compressed files */
+ if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
+ nblks = le32_to_cpu(v2->i_u.compressed_blocks);
} else if (__inode_version(advise) == EROFS_INODE_LAYOUT_V1) {
struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
@@ -90,6 +95,8 @@ static int read_inode(struct inode *inode, void *data)
sbi->build_time_nsec;
inode->i_size = le32_to_cpu(v1->i_size);
+ if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
+ nblks = le32_to_cpu(v1->i_u.compressed_blocks);
} else {
errln("unsupported on-disk inode version %u of nid %llu",
__inode_version(advise), vi->nid);
@@ -97,8 +104,11 @@ static int read_inode(struct inode *inode, void *data)
return -EIO;
}
- /* measure inode.i_blocks as the generic filesystem */
- inode->i_blocks = ((inode->i_size - 1) >> 9) + 1;
+ if (!nblks)
+ /* measure inode.i_blocks as generic filesystems */
+ inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
+ else
+ inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK;
return 0;
}
--
2.17.1
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/2] staging: erofs: fix i_blocks calculation
2019-05-28 3:02 ` Chao Yu
@ 2019-05-28 3:23 ` Gao Xiang
2019-05-28 6:57 ` Dan Carpenter
1 sibling, 0 replies; 14+ messages in thread
From: Gao Xiang @ 2019-05-28 3:23 UTC (permalink / raw)
To: Chao Yu
Cc: Greg Kroah-Hartman, devel, LKML, linux-erofs, Chao Yu, Miao Xie,
weidu.du, Fang Wei
On 2019/5/28 11:02, Chao Yu wrote:
> On 2019/5/28 10:36, Gao Xiang wrote:
>> For compressed files, i_blocks should not be calculated
>> by using i_size. i_u.compressed_blocks is used instead.
>>
>> In addition, i_blocks was miscalculated for non-compressed
>> files previously, fix it as well.
>>
>> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
>> ---
>> change log v2:
>> - fix description in commit message
>> - fix to 'inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK'
>>
>> Thanks,
>> Gao Xiang
>>
>> drivers/staging/erofs/inode.c | 14 ++++++++++++--
>> 1 file changed, 12 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
>> index 8da144943ed6..6e67e018784e 100644
>> --- a/drivers/staging/erofs/inode.c
>> +++ b/drivers/staging/erofs/inode.c
>> @@ -20,6 +20,7 @@ static int read_inode(struct inode *inode, void *data)
>> struct erofs_vnode *vi = EROFS_V(inode);
>> struct erofs_inode_v1 *v1 = data;
>> const unsigned int advise = le16_to_cpu(v1->i_advise);
>> + erofs_blk_t nblks = 0;
>>
>> vi->data_mapping_mode = __inode_data_mapping(advise);
>>
>> @@ -60,6 +61,10 @@ static int read_inode(struct inode *inode, void *data)
>> le32_to_cpu(v2->i_ctime_nsec);
>>
>> inode->i_size = le64_to_cpu(v2->i_size);
>> +
>> + /* total blocks for compressed files */
>> + if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
>> + nblks = v2->i_u.compressed_blocks;
>
> Xiang,
>
> It needs to use le32_to_cpu(). ;)
Already fixed in v3... Sorry about that...
Thanks,
Gao Xiang
>
>> } else if (__inode_version(advise) == EROFS_INODE_LAYOUT_V1) {
>> struct erofs_sb_info *sbi = EROFS_SB(inode->i_sb);
>>
>> @@ -90,6 +95,8 @@ static int read_inode(struct inode *inode, void *data)
>> sbi->build_time_nsec;
>>
>> inode->i_size = le32_to_cpu(v1->i_size);
>> + if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
>> + nblks = v1->i_u.compressed_blocks;
>
> Ditto.
>
> Thanks,
>
>> } else {
>> errln("unsupported on-disk inode version %u of nid %llu",
>> __inode_version(advise), vi->nid);
>> @@ -97,8 +104,11 @@ static int read_inode(struct inode *inode, void *data)
>> return -EIO;
>> }
>>
>> - /* measure inode.i_blocks as the generic filesystem */
>> - inode->i_blocks = ((inode->i_size - 1) >> 9) + 1;
>> + if (!nblks)
>> + /* measure inode.i_blocks as generic filesystems */
>> + inode->i_blocks = roundup(inode->i_size, EROFS_BLKSIZ) >> 9;
>> + else
>> + inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK;
>> return 0;
>> }
>>
>>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 1/2] staging: erofs: support statx
2019-05-28 3:19 ` [PATCH v3 1/2] staging: erofs: support statx Gao Xiang
2019-05-28 3:19 ` [PATCH v3 2/2] staging: erofs: fix i_blocks calculation Gao Xiang
@ 2019-05-28 3:28 ` Chao Yu
1 sibling, 0 replies; 14+ messages in thread
From: Chao Yu @ 2019-05-28 3:28 UTC (permalink / raw)
To: Gao Xiang, Greg Kroah-Hartman, devel
Cc: LKML, linux-erofs, Chao Yu, Miao Xie, weidu.du, Fang Wei
On 2019/5/28 11:19, Gao Xiang wrote:
> statx() has already been supported in commit a528d35e8bfc
> ("statx: Add a system call to make enhanced file info available"),
> user programs can get more useful attributes.
>
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Thanks,
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v3 2/2] staging: erofs: fix i_blocks calculation
2019-05-28 3:19 ` [PATCH v3 2/2] staging: erofs: fix i_blocks calculation Gao Xiang
@ 2019-05-28 3:28 ` Chao Yu
0 siblings, 0 replies; 14+ messages in thread
From: Chao Yu @ 2019-05-28 3:28 UTC (permalink / raw)
To: Gao Xiang, Greg Kroah-Hartman, devel
Cc: LKML, linux-erofs, Chao Yu, Miao Xie, weidu.du, Fang Wei
On 2019/5/28 11:19, Gao Xiang wrote:
> For compressed files, i_blocks should not be calculated
> by using i_size. use i_u.compressed_blocks instead.
>
> In addition, i_blocks was miscalculated for non-compressed
> files previously, fix it as well.
>
> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Thanks,
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/2] staging: erofs: fix i_blocks calculation
2019-05-28 3:02 ` Chao Yu
2019-05-28 3:23 ` Gao Xiang
@ 2019-05-28 6:57 ` Dan Carpenter
2019-05-28 7:16 ` Gao Xiang
2019-05-28 9:45 ` Chao Yu
1 sibling, 2 replies; 14+ messages in thread
From: Dan Carpenter @ 2019-05-28 6:57 UTC (permalink / raw)
To: Chao Yu
Cc: Gao Xiang, Greg Kroah-Hartman, devel, linux-erofs, Chao Yu, LKML,
weidu.du, Fang Wei, Miao Xie
On Tue, May 28, 2019 at 11:02:12AM +0800, Chao Yu wrote:
> On 2019/5/28 10:36, Gao Xiang wrote:
> > For compressed files, i_blocks should not be calculated
> > by using i_size. i_u.compressed_blocks is used instead.
> >
> > In addition, i_blocks was miscalculated for non-compressed
> > files previously, fix it as well.
> >
> > Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
> > ---
> > change log v2:
> > - fix description in commit message
> > - fix to 'inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK'
> >
> > Thanks,
> > Gao Xiang
> >
> > drivers/staging/erofs/inode.c | 14 ++++++++++++--
> > 1 file changed, 12 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
> > index 8da144943ed6..6e67e018784e 100644
> > --- a/drivers/staging/erofs/inode.c
> > +++ b/drivers/staging/erofs/inode.c
> > @@ -20,6 +20,7 @@ static int read_inode(struct inode *inode, void *data)
> > struct erofs_vnode *vi = EROFS_V(inode);
> > struct erofs_inode_v1 *v1 = data;
> > const unsigned int advise = le16_to_cpu(v1->i_advise);
> > + erofs_blk_t nblks = 0;
> >
> > vi->data_mapping_mode = __inode_data_mapping(advise);
> >
> > @@ -60,6 +61,10 @@ static int read_inode(struct inode *inode, void *data)
> > le32_to_cpu(v2->i_ctime_nsec);
> >
> > inode->i_size = le64_to_cpu(v2->i_size);
> > +
> > + /* total blocks for compressed files */
> > + if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
> > + nblks = v2->i_u.compressed_blocks;
>
> Xiang,
>
> It needs to use le32_to_cpu(). ;)
>
I wonder it the kbuild bot is going to send an email about that...
Hopefully these sorts of bugs get detected with Sparse CF=-D__CHECK_ENDIAN__
regards,
dan carpenter
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/2] staging: erofs: fix i_blocks calculation
2019-05-28 6:57 ` Dan Carpenter
@ 2019-05-28 7:16 ` Gao Xiang
2019-05-28 9:45 ` Chao Yu
1 sibling, 0 replies; 14+ messages in thread
From: Gao Xiang @ 2019-05-28 7:16 UTC (permalink / raw)
To: Dan Carpenter
Cc: Chao Yu, Greg Kroah-Hartman, devel, linux-erofs, Chao Yu, LKML,
weidu.du, Fang Wei, Miao Xie
Hi Dan,
On 2019/5/28 14:57, Dan Carpenter wrote:
> On Tue, May 28, 2019 at 11:02:12AM +0800, Chao Yu wrote:
>> On 2019/5/28 10:36, Gao Xiang wrote:
>>> For compressed files, i_blocks should not be calculated
>>> by using i_size. i_u.compressed_blocks is used instead.
>>>
>>> In addition, i_blocks was miscalculated for non-compressed
>>> files previously, fix it as well.
>>>
>>> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
>>> ---
>>> change log v2:
>>> - fix description in commit message
>>> - fix to 'inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK'
>>>
>>> Thanks,
>>> Gao Xiang
>>>
>>> drivers/staging/erofs/inode.c | 14 ++++++++++++--
>>> 1 file changed, 12 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
>>> index 8da144943ed6..6e67e018784e 100644
>>> --- a/drivers/staging/erofs/inode.c
>>> +++ b/drivers/staging/erofs/inode.c
>>> @@ -20,6 +20,7 @@ static int read_inode(struct inode *inode, void *data)
>>> struct erofs_vnode *vi = EROFS_V(inode);
>>> struct erofs_inode_v1 *v1 = data;
>>> const unsigned int advise = le16_to_cpu(v1->i_advise);
>>> + erofs_blk_t nblks = 0;
>>>
>>> vi->data_mapping_mode = __inode_data_mapping(advise);
>>>
>>> @@ -60,6 +61,10 @@ static int read_inode(struct inode *inode, void *data)
>>> le32_to_cpu(v2->i_ctime_nsec);
>>>
>>> inode->i_size = le64_to_cpu(v2->i_size);
>>> +
>>> + /* total blocks for compressed files */
>>> + if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
>>> + nblks = v2->i_u.compressed_blocks;
>>
>> Xiang,
>>
>> It needs to use le32_to_cpu(). ;)
>>
>
> I wonder it the kbuild bot is going to send an email about that...
Not yet, and v3 fixes it. I have no idea whether kbuild checks all version
or just the latest version...
> Hopefully these sorts of bugs get detected with Sparse CF=-D__CHECK_ENDIAN__
Yes, I missed this case by mistake.
These two patches are small, I didn't do too many static checking expect for checkpatch.pl.
v3 seems fine and I will take care later, Thanks for kindly suggestion. :)
Thanks,
Gao Xiang
>
> regards,
> dan carpenter
>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 2/2] staging: erofs: fix i_blocks calculation
2019-05-28 6:57 ` Dan Carpenter
2019-05-28 7:16 ` Gao Xiang
@ 2019-05-28 9:45 ` Chao Yu
1 sibling, 0 replies; 14+ messages in thread
From: Chao Yu @ 2019-05-28 9:45 UTC (permalink / raw)
To: Dan Carpenter
Cc: Gao Xiang, Greg Kroah-Hartman, devel, linux-erofs, Chao Yu, LKML,
weidu.du, Fang Wei, Miao Xie
On 2019/5/28 14:57, Dan Carpenter wrote:
> On Tue, May 28, 2019 at 11:02:12AM +0800, Chao Yu wrote:
>> On 2019/5/28 10:36, Gao Xiang wrote:
>>> For compressed files, i_blocks should not be calculated
>>> by using i_size. i_u.compressed_blocks is used instead.
>>>
>>> In addition, i_blocks was miscalculated for non-compressed
>>> files previously, fix it as well.
>>>
>>> Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
>>> ---
>>> change log v2:
>>> - fix description in commit message
>>> - fix to 'inode->i_blocks = nblks << LOG_SECTORS_PER_BLOCK'
>>>
>>> Thanks,
>>> Gao Xiang
>>>
>>> drivers/staging/erofs/inode.c | 14 ++++++++++++--
>>> 1 file changed, 12 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/staging/erofs/inode.c b/drivers/staging/erofs/inode.c
>>> index 8da144943ed6..6e67e018784e 100644
>>> --- a/drivers/staging/erofs/inode.c
>>> +++ b/drivers/staging/erofs/inode.c
>>> @@ -20,6 +20,7 @@ static int read_inode(struct inode *inode, void *data)
>>> struct erofs_vnode *vi = EROFS_V(inode);
>>> struct erofs_inode_v1 *v1 = data;
>>> const unsigned int advise = le16_to_cpu(v1->i_advise);
>>> + erofs_blk_t nblks = 0;
>>>
>>> vi->data_mapping_mode = __inode_data_mapping(advise);
>>>
>>> @@ -60,6 +61,10 @@ static int read_inode(struct inode *inode, void *data)
>>> le32_to_cpu(v2->i_ctime_nsec);
>>>
>>> inode->i_size = le64_to_cpu(v2->i_size);
>>> +
>>> + /* total blocks for compressed files */
>>> + if (vi->data_mapping_mode == EROFS_INODE_LAYOUT_COMPRESSION)
>>> + nblks = v2->i_u.compressed_blocks;
>>
>> Xiang,
>>
>> It needs to use le32_to_cpu(). ;)
>>
>
> I wonder it the kbuild bot is going to send an email about that...
0-day may do this a little later.
> Hopefully these sorts of bugs get detected with Sparse CF=-D__CHECK_ENDIAN__
Thanks, Dan, let's use this sparse flag more frequently to avoid such issue.
Thanks,
>
> regards,
> dan carpenter
>
> .
>
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2019-05-28 9:45 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-28 2:31 [PATCH 1/2] staging: erofs: support statx Gao Xiang
2019-05-28 2:31 ` [PATCH 2/2] staging: erofs: fix i_blocks calculation Gao Xiang
2019-05-28 2:36 ` [PATCH v2 " Gao Xiang
2019-05-28 3:02 ` Chao Yu
2019-05-28 3:23 ` Gao Xiang
2019-05-28 6:57 ` Dan Carpenter
2019-05-28 7:16 ` Gao Xiang
2019-05-28 9:45 ` Chao Yu
2019-05-28 3:19 ` [PATCH v3 1/2] staging: erofs: support statx Gao Xiang
2019-05-28 3:19 ` [PATCH v3 2/2] staging: erofs: fix i_blocks calculation Gao Xiang
2019-05-28 3:28 ` Chao Yu
2019-05-28 3:28 ` [PATCH v3 1/2] staging: erofs: support statx Chao Yu
2019-05-28 2:44 ` [PATCH " Chao Yu
2019-05-28 2:49 ` Gao Xiang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).