From: Filipe Manana <fdmanana@kernel.org>
To: Chris Murphy <lists@colorremedies.com>
Cc: Btrfs BTRFS <linux-btrfs@vger.kernel.org>,
Josef Bacik <josef@toxicpanda.com>
Subject: Re: [bug] GNOME loses all settings following failure to resume from suspend
Date: Wed, 5 Jan 2022 18:32:54 +0000 [thread overview]
Message-ID: <YdXkVnh+QLbZI5oI@debian9.Home> (raw)
In-Reply-To: <YdXdtrHb9nTYgFo7@debian9.Home>
On Wed, Jan 05, 2022 at 06:04:38PM +0000, Filipe Manana wrote:
> On Wed, Jan 05, 2022 at 10:34:10AM -0700, Chris Murphy wrote:
> > https://gitlab.gnome.org/GNOME/dconf/-/issues/73
> >
> > Following a crash, instead of either the old or new dconf database
> > file being present, a corrupt one is present.
> >
> > dconf uses g_file_set_contents() to atomically update the database
> > file, which effectively inhibits (one or more?) fsync's, yet somehow
> > in the crash/powerfail case this is resulting in a corrupt dconf
> > database. I don't know if by "corrupt" this is a 0 length file or some
> > other effect.
>
> Looking at the issue, Sebastian Keller posted a patch to disable one
> optimization in glib, that should fix it.
>
> Looking at the code before that patch, it explicitly skips fsync after
> a rename pointing out to:
>
> https://btrfs.wiki.kernel.org/index.php/FAQ#What_are_the_crash_guarantees_of_overwrite-by-rename.3F
>
> I'm afraid that information is wrong, perhaps it might have been true in
> some very distant past, but certainly not for many years.
After some digging in git history:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=8d875f95da43c6a8f18f77869f2ef26e9594fecc
So that guarantee existed until August 2014.
Not anymore, and no one should rely on it (except when using "-o flushoncommit").
>
> The wiki says, doing something like this:
>
> echo "oldcontent" > file
>
> # make sure oldcontent is on disk
> sync
>
> echo "newcontent" > file.tmp
> mv -f file.tmp file
>
> # *crash*
>
> Will give either:
>
> file contains "newcontent"; file.tmp does not exist
> file contains "oldcontent"; file.tmp may contain "newcontent", be zero-length or not exists at all.
>
> However that's not true, there's a chance 'file' will be empty.
>
> During a rename with overwrite we trigger writeback (via filemap_flush())
> of the file being renamed but never wait for it to complete before
> returning to user space. So what can happen is:
>
> 1) We trigger writeback;
>
> 2) We join the current transaction and do the rename;
>
> 3) We return from rename to user space with success (0);
>
> 4) Writeback didn't finish yet, or it has finished but the
> ordered extent is not yet complete - i.e. btrfs_finish_ordered_io()
> did not complete yet;
>
> 5) The transaction used by the rename is committed;
> A transaction commit does not wait for any writeback or in flight
> ordered extents to complete - except if the fs is mounted with
> "-o flushoncommit";
>
> 6) Crash
>
> After mounting the fs again 'file' is empty and 'file.tmp' does not exists.
>
> The only for that to guarantee 'file' is not empty and has the expected
> data ("newcontent"), would be to mount with -o flushoncommit.
>
> I don't think I have a wiki account enabled, but I'll see if I get that
> updated soon.
>
> Thanks.
>
> >
> > Thanks,
> >
> > --
> > Chris Murphy
next prev parent reply other threads:[~2022-01-05 18:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-05 17:34 [bug] GNOME loses all settings following failure to resume from suspend Chris Murphy
2022-01-05 18:04 ` Filipe Manana
2022-01-05 18:32 ` Filipe Manana [this message]
2022-01-05 18:34 ` Hugo Mills
2022-01-05 20:38 ` Filipe Manana
2022-01-05 21:31 ` Hugo Mills
2022-01-05 21:39 ` Hugo Mills
2022-01-05 21:53 ` Hugo Mills
2022-01-06 9:51 ` Filipe Manana
2022-01-06 10:20 ` Hugo Mills
2022-01-06 10:27 ` Filipe Manana
2022-01-06 20:02 ` Chris Murphy
2022-01-06 20:06 ` Chris Murphy
2022-01-06 20:23 ` Hugo Mills
2022-01-06 21:07 ` Adam Borowski
2022-01-05 18:40 ` Chris Murphy
2022-01-05 20:32 ` Filipe Manana
2022-01-09 17:04 ` Remi Gauvin
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=YdXkVnh+QLbZI5oI@debian9.Home \
--to=fdmanana@kernel.org \
--cc=josef@toxicpanda.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=lists@colorremedies.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;
as well as URLs for NNTP newsgroup(s).