From: "Austin S. Hemmelgarn" <ahferroin7@gmail.com>
To: Joerg Schilling <Joerg.Schilling@fokus.fraunhofer.de>, antonio@gnu.org
Cc: linux-btrfs@vger.kernel.org, bug-tar@gnu.org, adilger@dilger.ca
Subject: Re: [Bug-tar] stat() on btrfs reports the st_blocks with delay (data loss in archivers)
Date: Wed, 6 Jul 2016 11:12:24 -0400 [thread overview]
Message-ID: <12d68c4e-5918-4ed0-9172-be7bd166c020@gmail.com> (raw)
In-Reply-To: <577d1b65.pxyPJIXK4jVojlar%Joerg.Schilling@fokus.fraunhofer.de>
On 2016-07-06 10:53, Joerg Schilling wrote:
> Antonio Diaz Diaz <antonio@gnu.org> wrote:
>
>> Joerg Schilling wrote:
>>> POSIX requires st_blocks to be != 0 in case that the file contains data.
>>
>> Please, could you provide a reference? I can't find such requirement at
>> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_stat.h.html
>
> blkcnt_t st_blocks Number of blocks allocated for this object.
>
> It should be obvious that a file that offers content also has allocated blocks.
What you mean then is that POSIX _implies_ that this is the case, but
does not say whether or not it is required. There are all kinds of
counterexamples to this too, procfs is a POSIX compliant filesystem
(every POSIX certified system has it), yet does not display the behavior
that you expect, every single file in /proc for example reports 0 for
both st_blocks and st_size, and yet all of them very obviously have content.
>
> Blocks are "allocated" when the OS decides whether the new data will fit on the
> medium. The fact that some filesystems may have data in a cache but not yet on
> the medium does not matter here. This is how UNIX worked since st_block has
> been introduced nearly 40 years ago.
Tradition is the corpse of wisdom. Backwards comparability is a problem
just as much as a good thing.
In all seriousness though, this started out because stuff wasn't cached
to anywhere near the degree it is today, and there was no such thing as
delayed allocation. When you said to write, the filesystem allocated
the blocks, regardless of when it actually wrote the data. IOW, the
behavior that GNU tar is relying on is an implementation detail, not an
API. Just like df, this breaks under modern designs, not because they
chose to break it, but because it wasn't designed for use with such
implementations.
In the case of tar and similar things though, I'd argue that it's not
sensible to special case files that are 'sparse', it should store any
long enough run of zeroes as a sparse region, then provide an option to
say to not make those files sparse when restored.
>
> A new filesystem cannot introduce new rules just because people believe it would
> save time.
Saying the file has no blocks when there are no blocks allocated for it
is not to 'save time', it's absolutely accurate. Suppose SVR4 UFS had a
way to pack file data into the inode if it was small enough. In that
case, it woulod be perfectly reasonable to return 0 for st_blocks
because the inode table in UFS is a fixed pre-allocated structure, and
therefore nothing is allocated to the file itself except the inode. The
same applies in the case of a file packed into it's own metadata block
on BTRFS, nothing is allocated to that file beyond the metadata block it
has to have to store the inode. In the case of delayed allocation where
the file hasn't been flushed, there is nothing allocated, so st_blocks
based on a strict interpretation of it's description in POSIX _should_
be 0, because nothing is allocated yet.
next prev parent reply other threads:[~2016-07-06 15:12 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-02 7:18 stat() on btrfs reports the st_blocks with delay (data loss in archivers) Pavel Raiskup
2016-07-04 19:35 ` [Bug-tar] " Andreas Dilger
2016-07-05 9:28 ` Joerg Schilling
2016-07-06 11:37 ` Austin S. Hemmelgarn
2016-07-06 11:49 ` Joerg Schilling
2016-07-06 14:43 ` Antonio Diaz Diaz
2016-07-06 14:53 ` Joerg Schilling
2016-07-06 15:01 ` Paul Eggert
2016-07-06 15:09 ` Joerg Schilling
2016-07-06 15:11 ` Paul Eggert
2016-07-06 15:12 ` Austin S. Hemmelgarn [this message]
2016-07-06 15:22 ` Joerg Schilling
2016-07-06 16:05 ` Austin S. Hemmelgarn
2016-07-06 16:11 ` Austin S. Hemmelgarn
2016-07-06 16:33 ` Joerg Schilling
2016-07-06 17:35 ` Andreas Dilger
2016-07-07 8:08 ` Pavel Raiskup
2016-07-11 14:41 ` David Sterba
2016-07-11 15:00 ` Chris Mason
2016-07-11 15:16 ` David Sterba
2016-07-11 17:30 ` Chris Mason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=12d68c4e-5918-4ed0-9172-be7bd166c020@gmail.com \
--to=ahferroin7@gmail.com \
--cc=Joerg.Schilling@fokus.fraunhofer.de \
--cc=adilger@dilger.ca \
--cc=antonio@gnu.org \
--cc=bug-tar@gnu.org \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).