From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
mcgrof@kernel.org, jack@suse.cz, hch@infradead.org,
david@fromorbit.com, rafael@kernel.org, djwong@kernel.org,
pavel@kernel.org, peterz@infradead.org, mingo@redhat.com,
will@kernel.org, boqun.feng@gmail.com
Subject: Re: [RFC PATCH 4/4] vfs: add filesystem freeze/thaw callbacks for power management
Date: Fri, 28 Mar 2025 10:14:22 -0400 [thread overview]
Message-ID: <cd5c3d8aab9c5fb37fa018cb3302ecf7d2bdb140.camel@HansenPartnership.com> (raw)
In-Reply-To: <20250328-luxus-zinspolitik-835cc75fbad5@brauner>
On Fri, 2025-03-28 at 11:08 +0100, Christian Brauner wrote:
> On Thu, Mar 27, 2025 at 10:06:13AM -0400, James Bottomley wrote:
[...]
> > +
> > +static void filesystems_freeze_callback(struct super_block *sb)
> > +{
> > + /* errors don't fail suspend so ignore them */
> > + if (sb->s_op->freeze_super)
> > + sb->s_op->freeze_super(sb, FREEZE_MAY_NEST
> > + | FREEZE_HOLDER_KERNEL
> > + | freeze_flags);
> > + else if (sb->s_bdev)
> > + freeze_super(sb, FREEZE_MAY_NEST |
> > FREEZE_HOLDER_KERNEL
> > + | freeze_flags);
> > + else {
> > + pr_info("Ignoring filesystem %s\n", sb->s_type-
> > >name);
> > + return;
> > + }
> > +
> > + pr_info("frozen %s, now syncing block ...", sb->s_type-
> > >name);
> > + sync_blockdev(sb->s_bdev);
> > + pr_info("done.");
> > +}
> > +
> > +/**
> > + * filesystems_freeze - freeze callback for power management
> > + *
> > + * Freeze all active filesystems (in reverse superblock order)
> > + */
> > +void filesystems_freeze(bool for_hibernate)
> > +{
> > + freeze_flags = for_hibernate ? FREEZE_FOR_HIBERNATE : 0;
> > + __iterate_supers_rev(filesystems_freeze_callback);
> > +}
> > +
> > +static void filesystems_thaw_callback(struct super_block *sb)
> > +{
> > + if (sb->s_op->thaw_super)
> > + sb->s_op->thaw_super(sb, FREEZE_MAY_NEST
> > + | FREEZE_HOLDER_KERNEL
> > + | freeze_flags);
> > + else if (sb->s_bdev)
> > + thaw_super(sb, FREEZE_MAY_NEST |
> > FREEZE_HOLDER_KERNEL
> > + | freeze_flags);
> > +}
> > +
> > +/**
> > + * filesystems_thaw - thaw callback for power management
> > + *
> > + * Thaw all active filesystems (in forward superblock order)
> > + */
> > +void filesystems_thaw(bool for_hibernate)
> > +{
> > + freeze_flags = for_hibernate ? FREEZE_FOR_HIBERNATE : 0;
> > + __iterate_supers(filesystems_thaw_callback);
>
> This doesn't work and I've explained in my reply to Luis how this
> doesn't work and what the alternative are:
>
> A concurrent umount() can wipe the filesystem behind your back. So
> you either need an active superblock reference or you need to
> communicate that the superblock is locked through the new flag I
> proposed (naming irrelevant for now).
Since this is a hybrid thread between power management and VFS, could I
just summarize what I think the various superblock locks are before
discussing the actual problem (important because the previous threads
always gave the impression of petering out for fear of vfs locking).
s_count: outermost of the superblock locks refcounting the superblock
structure itself, making no guarantee that any of the underlying
filesystem superblock structures are attached (i.e. kill_sb() may have
been called). Taken by incrementing under the global sb_lock and
decremented using a put_super() variant.
s_active: an atomic reference counting the underlying filesystem
specific superblock structures. if you hold s_active, kill_sb cannot
be called. Acquired by atomic_inc_not_zero() with a possible failure
if it is zero and released by deactivate_super() and its variants.
s_umount: rwsem and innermost of the superblock locks. Used to protect
various operations from races. Taken exclusively with down_write and
shared with down_read. Private functions internal to super.c wrap this
with grab_super and super_lock_shared/excl() wrappers.
The explicit freeze/thaw_super() functions require the s_umount rwsem
in down_write or exclusive mode and take it as the first step in their
operation. Looking at the locking in fs_bdev_freeze/thaw() implies
that the super_operations freeze_super/thaw_super *don't* need this
taken (presumably they handle it internally).
Regards,
James
next prev parent reply other threads:[~2025-03-28 14:14 UTC|newest]
Thread overview: 121+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-27 14:06 [RFC PATCH 0/4] vfs freeze/thaw on suspend/resume James Bottomley
2025-03-27 14:06 ` [RFC PATCH 1/4] locking/percpu-rwsem: add freezable alternative to down_read James Bottomley
2025-03-31 19:51 ` James Bottomley
2025-03-31 23:32 ` Christian Brauner
2025-04-01 1:13 ` James Bottomley
2025-04-01 11:20 ` Jan Kara
2025-04-01 12:50 ` Christian Brauner
2025-04-01 12:52 ` James Bottomley
2025-04-02 11:47 ` Jan Kara
2025-03-27 14:06 ` [RFC PATCH 2/4] vfs: make sb_start_write freezable James Bottomley
2025-03-27 17:36 ` Jan Kara
2025-03-27 14:06 ` [RFC PATCH 3/4] fs/super.c: introduce reverse superblock iterator and use it in emergency remount James Bottomley
2025-03-28 11:56 ` Christian Brauner
2025-03-28 12:38 ` James Bottomley
2025-03-28 16:15 ` [PATCH 0/6] Extend freeze support to suspend and hibernate Christian Brauner
2025-03-28 16:15 ` [PATCH 1/6] super: remove pointless s_root checks Christian Brauner
2025-03-28 16:15 ` [PATCH 2/6] super: simplify user_get_super() Christian Brauner
2025-03-28 16:15 ` [PATCH 3/6] super: skip dying superblocks early Christian Brauner
2025-03-28 16:15 ` [PATCH 4/6] super: use a common iterator (Part 1) Christian Brauner
2025-03-28 16:15 ` [PATCH 5/6] super: use common iterator (Part 2) Christian Brauner
2025-03-28 18:58 ` James Bottomley
2025-03-29 7:34 ` Christian Brauner
2025-03-28 16:15 ` [PATCH 6/6] super: add filesystem freezing helpers for suspend and hibernate Christian Brauner
2025-03-29 8:42 ` [PATCH v2 0/6] Extend freeze support to " Christian Brauner
2025-03-29 8:42 ` [PATCH v2 1/6] super: remove pointless s_root checks Christian Brauner
2025-03-31 9:57 ` Jan Kara
2025-06-11 16:26 ` Darrick J. Wong
2025-06-12 12:20 ` Christian Brauner
2025-03-29 8:42 ` [PATCH v2 2/6] super: simplify user_get_super() Christian Brauner
2025-03-31 9:58 ` Jan Kara
2025-03-29 8:42 ` [PATCH v2 3/6] super: skip dying superblocks early Christian Brauner
2025-03-31 10:00 ` Jan Kara
2025-03-29 8:42 ` [PATCH v2 4/6] super: use a common iterator (Part 1) Christian Brauner
2025-03-31 10:01 ` Jan Kara
2025-03-29 8:42 ` [PATCH v2 5/6] super: use common iterator (Part 2) Christian Brauner
2025-03-31 10:07 ` Jan Kara
2025-03-31 10:15 ` Christian Brauner
2025-03-29 8:42 ` [PATCH v2 6/6] super: add filesystem freezing helpers for suspend and hibernate Christian Brauner
2025-03-29 8:46 ` Christian Brauner
2025-03-29 11:30 ` kernel test robot
2025-03-31 10:23 ` Jan Kara
2025-03-31 10:25 ` Christian Brauner
2025-03-29 14:04 ` [PATCH v2 0/6] Extend freeze support to " James Bottomley
2025-03-29 17:02 ` James Bottomley
2025-03-30 8:33 ` Christian Brauner
2025-03-30 11:53 ` Christian Brauner
2025-03-30 14:00 ` James Bottomley
2025-03-31 9:13 ` Christian Brauner
2025-03-31 10:36 ` Jan Kara
2025-03-31 14:49 ` James Bottomley
2025-03-31 23:33 ` Christian Brauner
2025-03-31 12:42 ` [PATCH 0/2] efivarfs: support freeze/thaw Christian Brauner
2025-03-31 12:42 ` [PATCH 1/2] libfs: export find_next_child() Christian Brauner
2025-03-31 12:42 ` [PATCH 2/2] efivarfs: support freeze/thaw Christian Brauner
2025-03-31 14:46 ` James Bottomley
2025-03-31 15:03 ` Christian Brauner
2025-04-01 19:31 ` James Bottomley
2025-04-02 7:44 ` Christian Brauner
2025-03-31 14:05 ` [PATCH 0/2] " Ard Biesheuvel
2025-04-01 0:32 ` [PATCH 0/6] power: wire-up filesystem freeze/thaw with suspend/resume Christian Brauner
2025-04-01 0:32 ` [PATCH 1/6] ext4: replace kthread freezing with auto fs freezing Christian Brauner
2025-04-01 9:16 ` Jan Kara
2025-04-01 9:35 ` Christian Brauner
2025-04-01 10:08 ` Jan Kara
2025-04-01 0:32 ` [PATCH 2/6] btrfs: " Christian Brauner
2025-04-01 0:32 ` [PATCH 3/6] xfs: " Christian Brauner
2025-04-01 1:11 ` Dave Chinner
2025-04-01 7:17 ` Christian Brauner
2025-04-01 11:35 ` Dave Chinner
2025-04-01 12:45 ` Christian Brauner
2025-04-01 0:32 ` [PATCH 4/6] fs: add owner of freeze/thaw Christian Brauner
2025-04-01 0:32 ` [PATCH 5/6] fs: allow pagefault based writers to be frozen Christian Brauner
2025-04-01 0:32 ` [PATCH 6/6] power: freeze filesystems during suspend/resume Christian Brauner
2025-04-01 8:16 ` [PATCH 0/6] power: wire-up filesystem freeze/thaw with suspend/resume Christian Brauner
2025-04-01 9:32 ` Jan Kara
2025-04-01 13:03 ` Christian Brauner
2025-04-01 16:57 ` Jan Kara
2025-04-02 14:07 ` [PATCH v2 0/4] " Christian Brauner
2025-04-02 14:07 ` [PATCH v2 1/4] fs: add owner of freeze/thaw Christian Brauner
2025-04-03 14:56 ` Jan Kara
2025-04-03 19:33 ` Christian Brauner
2025-04-04 10:24 ` [PATCH] fs: allow nesting with FREEZE_EXCL Christian Brauner
2025-04-07 9:08 ` Christoph Hellwig
2025-05-07 11:18 ` Jan Kara
2025-05-09 10:38 ` Christian Brauner
2025-04-02 14:07 ` [PATCH v2 2/4] fs: allow all writers to be frozen Christian Brauner
2025-04-02 15:32 ` Christian Brauner
2025-04-02 16:03 ` James Bottomley
2025-04-02 16:13 ` Christian Brauner
2025-04-03 14:59 ` Jan Kara
2025-04-02 14:07 ` [PATCH v2 3/4] power: freeze filesystems during suspend/resume Christian Brauner
2025-04-03 16:29 ` Jan Kara
2025-04-02 14:07 ` [PATCH v2 4/4] kernfs: add warning about implementing freeze/thaw Christian Brauner
2025-04-03 15:00 ` Jan Kara
2025-07-20 19:23 ` [PATCH v2 0/4] power: wire-up filesystem freeze/thaw with suspend/resume Askar Safin
2025-07-21 12:09 ` Jan Kara
2025-08-04 5:31 ` Miklos Szeredi
2025-08-04 6:02 ` Askar Safin
2025-08-04 6:51 ` Sergey Senozhatsky
2025-04-01 14:14 ` [PATCH 0/6] " Peter Zijlstra
2025-04-01 14:40 ` Christian Brauner
2025-04-01 14:59 ` Peter Zijlstra
2025-04-01 17:02 ` James Bottomley
2025-04-02 7:46 ` Christian Brauner
2025-04-08 15:43 ` James Bottomley
2025-04-08 17:09 ` Luis Chamberlain
2025-04-08 17:20 ` Luis Chamberlain
2025-04-08 17:26 ` James Bottomley
2025-04-08 17:24 ` James Bottomley
2025-04-09 7:17 ` Christian Brauner
2025-03-27 14:06 ` [RFC PATCH 4/4] vfs: add filesystem freeze/thaw callbacks for power management James Bottomley
2025-03-27 18:20 ` Jan Kara
2025-03-28 14:21 ` James Bottomley
2025-03-28 14:36 ` James Bottomley
2025-03-28 10:08 ` Christian Brauner
2025-03-28 14:14 ` James Bottomley [this message]
2025-03-28 15:52 ` Christian Brauner
2025-03-28 16:15 ` James Bottomley
2025-03-29 8:23 ` Christian Brauner
2025-03-28 12:01 ` Christian Brauner
2025-03-28 14:40 ` James Bottomley
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=cd5c3d8aab9c5fb37fa018cb3302ecf7d2bdb140.camel@HansenPartnership.com \
--to=james.bottomley@hansenpartnership.com \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mcgrof@kernel.org \
--cc=mingo@redhat.com \
--cc=pavel@kernel.org \
--cc=peterz@infradead.org \
--cc=rafael@kernel.org \
--cc=will@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.