John Haxby
2015-Nov-24 21:07 UTC
[Ocfs2-devel] [PATCH 0/1] ocfs2: return non-zero st_blocks for inline data [resend2]
Hello All,
[Really sorry about this and I hope you're not getting fed up of
multiple copies of this message but the list on oss.oracle.com really
doesn't like me.]
Some programs, and programmers, assume that if a file is occupying
zero blocks (st_blocks == 0) then it contains no data and there's no
point in reading it. Posix doesn't actually say anything about this,
but it seems to be something a lot of people expect. Indeed, ext4,
btrfs and ntfs-3d all seem to behave this way so that no one[1] has
any unpleasant surprises.
This patch is almost exactly the same as commit 9206c561554c ("ext4:
return non-zero st_blocks for inline data") although I couldn't bring
myself to include the typo in the comment :)
jch
[resend because rejected by list the first time.]
[1] tar, I'm looking at you, but you're not the only one.
John Haxby (1):
ocfs2: return non-zero st_blocks for inline data
fs/ocfs2/file.c | 8 ++++++++
1 file changed, 8 insertions(+)
--
2.5.0
John Haxby
2015-Nov-24 21:07 UTC
[Ocfs2-devel] [PATCH 1/1] ocfs2: return non-zero st_blocks for inline data
Some versions of tar assume that files with st_blocks == 0 do not
contain any data and will skip reading them entirely. See also
commit 9206c561554c ("ext4: return non-zero st_blocks for inline
data").
Signed-off-by: John Haxby <john.haxby at oracle.com>
---
fs/ocfs2/file.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/fs/ocfs2/file.c b/fs/ocfs2/file.c
index 0e5b451..d631279 100644
--- a/fs/ocfs2/file.c
+++ b/fs/ocfs2/file.c
@@ -1302,6 +1302,14 @@ int ocfs2_getattr(struct vfsmount *mnt,
}
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 don't incorrectly think the file is completely sparse.
+ */
+ if (unlikely(OCFS2_I(inode)->ip_dyn_features & OCFS2_INLINE_DATA_FL))
+ stat->blocks += (stat->size + 511)>>9;
/* We set the blksize from the cluster size for performance */
stat->blksize = osb->s_clustersize;
--
2.5.0