From: Hugo Mills <hugo@carfax.org.uk>
To: Chris Murphy <lists@colorremedies.com>
Cc: Filipe Manana <fdmanana@kernel.org>,
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: Thu, 6 Jan 2022 20:23:14 +0000 [thread overview]
Message-ID: <20220106202314.GA1698@savella.carfax.org.uk> (raw)
In-Reply-To: <CAJCQCtTyUk_TC=W+2o+Cy_W_mfX-0_sTXGBLf1S9AdQiHkDiMA@mail.gmail.com>
On Thu, Jan 06, 2022 at 01:06:40PM -0700, Chris Murphy wrote:
> On Thu, Jan 6, 2022 at 1:02 PM Chris Murphy <lists@colorremedies.com> wrote:
> >
> > On Thu, Jan 6, 2022 at 3:28 AM Filipe Manana <fdmanana@kernel.org> wrote:
> > >
> > > On Thu, Jan 6, 2022 at 10:21 AM Hugo Mills <hugo@carfax.org.uk> wrote:
> > > >
> > > > > Yep, that's correct Hugo.
> > > > >
> > > > > Starting with 3.17, the example on the wiki needs an fsync on
> > > > > "file.tmp" after writing to it and before renaming it over "file".
> > > > > I.e. the full example should be:
> > > > >
> > > > > ****
> > > > > echo "oldcontent" > file
> > > > >
> > > > > # make sure oldcontent is on disk
> > > > > sync
> > > > >
> > > > > echo "newcontent" > file.tmp
> > > > > fsync 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.
> > > > > ****
> > > >
> > > > Since I can't find an "fsync" command line tool, I've rewritten the
> > > > example in more general terms, rather than tying it to a specific
> > > > implementation (such as a sequence of shell commands). I note that
> > > > we've got a near-duplicate entry in the FAQ, two items down ("What are
> > > > the crash guarantees of rename?"), that should probably be removed.
> > > >
> > > > Updated entry: https://btrfs.wiki.kernel.org/index.php/FAQ#What_are_the_crash_guarantees_of_overwrite-by-rename.3F
> > > > Candidate for deletion: https://btrfs.wiki.kernel.org/index.php/FAQ#What_are_the_crash_guarantees_of_rename.3F
> > >
> > > There's the xfs_io command from xfsprogs that can be used to trigger
> > > an fsync like this: xfs_io -c fsync /path/to/file
> > > But it's probably not well known for non-developers.
> > >
> > > Anyway, as it is, it looks perfect to me, thanks!
> >
> >
> > I think it's OK to use pseudo-code. Folks will figure it out. So you
> > can just write it as fsync() and even if you're not using the exact
> > correct syntax it'll be understood.
>
> Topical xxample:
> https://lore.kernel.org/linux-xfs/6A65F394-C1BA-4339-AC9B-051885D12F65@corp.ovh.com/
I did wonder whether to write it as C-ish code, but I felt that the
prose description was sufficient, and didn't presuppose any particular
implementation.
> Reminds me to ask Filipe if the example Hugo is writing up also needs
> an fsync() on the enclosing directory *after* the rename?
As I understand it, as long as the data is fsynced properly before
the move, the semantics are safe and atomic (if you don't get the new
data afterwards, you get the old data, regardless of where the crash
is). Syncing the directory and waiting for that to complete gives you
the guarantee that you'll get the new data from that point on of the
system crashes afterwards.
Hugo.
--
Hugo Mills | I hate housework. You make the beds, you wash the
hugo@... carfax.org.uk | dishes, and six months later you have to start all
http://carfax.org.uk/ | over again.
PGP: E2AB1DE4 | Joan Rivers
next prev parent reply other threads:[~2022-01-06 20:23 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
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 [this message]
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=20220106202314.GA1698@savella.carfax.org.uk \
--to=hugo@carfax.org.uk \
--cc=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).