* [PATCH] ext4: return non-zero st_blocks for inline data
@ 2013-11-06 10:42 Andreas Dilger
2013-11-08 3:45 ` Theodore Ts'o
2013-11-12 3:44 ` Theodore Ts'o
0 siblings, 2 replies; 4+ messages in thread
From: Andreas Dilger @ 2013-11-06 10:42 UTC (permalink / raw)
To: tytso; +Cc: linux-ext4, Andreas Dilger
Return a non-zero st_blocks to userspace for statfs() and friends.
Some versions of tar will assume that files with st_blocks == 0
do not contain any data and will skip reading them entirely.
Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
---
fs/ext4/inode.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index cbfe13b..e832a6a 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -4532,6 +4532,15 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
generic_fillattr(inode, stat);
/*
+ * If there is inline data in the inode, the inode will normally not
+ * have data blocks allocated (it may have an external xattr block).
+ * Report at least one sector for such files, so tools like tar, rsync,
+ * others doen't incorrectly think the file is completely sparse.
+ */
+ if (unlikely(ext4_has_inline_data(inode)))
+ stat->blocks += (stat->size + 511) >> 9;
+
+ /*
* We can't update i_blocks if the block allocation is delayed
* otherwise in the case of system crash before the real block
* allocation is done, we will have i_blocks inconsistent with
@@ -4542,9 +4551,9 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
* blocks for this file.
*/
delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb),
- EXT4_I(inode)->i_reserved_data_blocks);
+ EXT4_I(inode)->i_reserved_data_blocks);
+ stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits - 9);
- stat->blocks += (delalloc_blocks << inode->i_sb->s_blocksize_bits)>>9;
return 0;
}
--
1.7.3.4
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: return non-zero st_blocks for inline data
2013-11-06 10:42 [PATCH] ext4: return non-zero st_blocks for inline data Andreas Dilger
@ 2013-11-08 3:45 ` Theodore Ts'o
2013-11-08 12:25 ` Dilger, Andreas
2013-11-12 3:44 ` Theodore Ts'o
1 sibling, 1 reply; 4+ messages in thread
From: Theodore Ts'o @ 2013-11-08 3:45 UTC (permalink / raw)
To: Andreas Dilger; +Cc: linux-ext4
On Wed, Nov 06, 2013 at 03:42:32AM -0700, Andreas Dilger wrote:
> @@ -4542,9 +4551,9 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
> * blocks for this file.
> */
> delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb),
> - EXT4_I(inode)->i_reserved_data_blocks);
> + EXT4_I(inode)->i_reserved_data_blocks);
> + stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits - 9);
>
> - stat->blocks += (delalloc_blocks << inode->i_sb->s_blocksize_bits)>>9;
Why this change to the calculation to stat->blocks?
- Ted
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: return non-zero st_blocks for inline data
2013-11-08 3:45 ` Theodore Ts'o
@ 2013-11-08 12:25 ` Dilger, Andreas
0 siblings, 0 replies; 4+ messages in thread
From: Dilger, Andreas @ 2013-11-08 12:25 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: linux-ext4@vger.kernel.org
On 2013/11/07 8:45 PM, "Theodore Ts'o" <tytso@mit.edu> wrote:
>On Wed, Nov 06, 2013 at 03:42:32AM -0700, Andreas Dilger wrote:
>> @@ -4542,9 +4551,9 @@ int ext4_getattr(struct vfsmount *mnt, struct
>>dentry *dentry,
>> * blocks for this file.
>> */
>> delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb),
>> - EXT4_I(inode)->i_reserved_data_blocks);
>> + EXT4_I(inode)->i_reserved_data_blocks);
>> + stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits -
>>9);
>>
>> - stat->blocks += (delalloc_blocks << inode->i_sb->s_blocksize_bits)>>9;
>
>Why this change to the calculation to stat->blocks?
Just code cleanup. The lack of spaces around ">>9" irked me.
The calculation is the same (s_blocksize_bits can never be less than 10
for ext* filesystems), but avoids doing two separate shifts that the
compiler cannot optimize together due to parenthesis and potential side
effects (e.g. this kind of operation could be used to mask off the top
bits, but isn't doing so here).
Cheers, Andreas
--
Andreas Dilger
Lustre Software Architect
Intel High Performance Data Division
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] ext4: return non-zero st_blocks for inline data
2013-11-06 10:42 [PATCH] ext4: return non-zero st_blocks for inline data Andreas Dilger
2013-11-08 3:45 ` Theodore Ts'o
@ 2013-11-12 3:44 ` Theodore Ts'o
1 sibling, 0 replies; 4+ messages in thread
From: Theodore Ts'o @ 2013-11-12 3:44 UTC (permalink / raw)
To: Andreas Dilger; +Cc: linux-ext4
On Wed, Nov 06, 2013 at 03:42:32AM -0700, Andreas Dilger wrote:
> Return a non-zero st_blocks to userspace for statfs() and friends.
> Some versions of tar will assume that files with st_blocks == 0
> do not contain any data and will skip reading them entirely.
>
> Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Applied, thanks.
- Ted
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-11-12 12:43 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-06 10:42 [PATCH] ext4: return non-zero st_blocks for inline data Andreas Dilger
2013-11-08 3:45 ` Theodore Ts'o
2013-11-08 12:25 ` Dilger, Andreas
2013-11-12 3:44 ` Theodore Ts'o
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).