From: Ben Myers <bpm@sgi.com>
To: Robert Widmer <robertwidmer@gmail.com>
Cc: xfs@oss.sgi.com
Subject: Re: Power loss and zero-length files
Date: Fri, 23 Aug 2013 10:20:58 -0500 [thread overview]
Message-ID: <20130823152058.GR5262@sgi.com> (raw)
In-Reply-To: <CAGwuE-p8=UwpGUhgpqkWn4U4jU-KnfC3C19Kqqv7uYLJvubxgQ@mail.gmail.com>
Hey Robert,
On Fri, Aug 23, 2013 at 10:59:50AM -0400, Robert Widmer wrote:
> I had a script that updated several files on an XFS filesystem using "sed
> -i", and someone decided to power cycle the box without a sync after
> running the script, and found that all the files that were updated were now
> zero-length.
How did they power cycle the box? With a 'shutdown -h now' you shouldn't have
this behavior, but resetting or unplugging the machine is a different matter.
> Curious, I ran the following script to try and isolate the behavior:
>
>
> #!/usr/bin/perl
>
> my $dir = "/home/$ENV{USER}/XFSTest";
> mkdir $dir;
> chdir $dir;
>
> my $filecount = 100;
> my $tmpfile = 'file.tmp';
>
> while (1) {
> for (my $i=0; $i<$filecount; $i++) {
> my $filename = "file.$i";
> open(OUT, ">", $tmpfile);
> print OUT "Time:".localtime."\n";
> close OUT;
> rename $tmpfile, $filename;
> }
> }
>
>
> On the following release/kernels in a VM:
>
> Fedora 16 w/kernel 3.1.0-7.fc16.x86_64
> Fedora 16 w/kernel 3.6.11-4.fc16.x86_64
> Fedora 19 w/kernel 3.10-7.200.fc19.x86_64
> Ubuntu 13.04 w/kernel 3.8.0-19-generic
>
>
> And after a power cycle, all the files are zero-length with no extents.
>
> (CentOS 6.4 w/kernel 2.6.32-358.14.1.el6.centos.plus.x86_64 has the binary
> NULLS)
>
> Barriers are not disabled and drive cache:
> [ 2.145011] sd 2:0:0:0: [sda] Cache data unavailable
> [ 2.145013] sd 2:0:0:0: [sda] Assuming drive cache: write through
>
>
> The closest thing I can find in the documentation is the XFS FAQ which
> mentions "you are looking at an inode which was flushed out, but whose data
> was not", which seems to indicate that the inode writes and data writes are
> not done in order, but nothing explicitly documents this.
You have it correct. The inode writes are a separate from the data writes.
> Is this expected behavior?
>
> I've added a sync to the end of my script to try and ensure this does not
> happen again, and losing some amount of data after a power loss is
> expected, but it seems counter-intuitive that the inode/data writes are not
> done in order and that rapid file changes can result in such a large number
> of files being zero-length.
For a reset or hard power cycle this is the expected behavior. The inode will
have been logged when it was created and is likely to be written out before the
data. Unless you issue an fsync, the data will be sitting around in cache
until the kernel decides to write the pages out, and only then is the size
updated. Adding the fsync is the right thing to do. ;)
Regards,
Ben
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2013-08-23 15:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-23 14:59 Power loss and zero-length files Robert Widmer
2013-08-23 15:20 ` Ben Myers [this message]
2013-08-23 15:27 ` Robert Widmer
2013-08-23 15:45 ` Ben Myers
2013-08-23 22:32 ` Stan Hoeppner
2013-08-23 22:50 ` Ben Myers
2013-08-24 2:35 ` Stan Hoeppner
2013-08-24 11:15 ` Christoph Hellwig
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=20130823152058.GR5262@sgi.com \
--to=bpm@sgi.com \
--cc=robertwidmer@gmail.com \
--cc=xfs@oss.sgi.com \
/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