From: Luis Chamberlain <mcgrof@kernel.org>
To: jack@suse.cz, hch@infradead.org,
James.Bottomley@HansenPartnership.com, david@fromorbit.com,
rafael@kernel.org, djwong@kernel.org, pavel@kernel.org,
song@kernel.org
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
gost.dev@samsung.com, Luis Chamberlain <mcgrof@kernel.org>
Subject: [RFC 1/6] fs: add frozen sb state helpers
Date: Wed, 26 Mar 2025 04:22:15 -0700 [thread overview]
Message-ID: <20250326112220.1988619-2-mcgrof@kernel.org> (raw)
In-Reply-To: <20250326112220.1988619-1-mcgrof@kernel.org>
Provide helpers so that we can check a superblock frozen state.
This will make subsequent changes easier to read. This makes
no functional changes.
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
fs/ext4/ext4_jbd2.c | 2 +-
fs/gfs2/sys.c | 2 +-
fs/quota/quota.c | 3 ++-
fs/super.c | 8 ++++----
fs/xfs/xfs_trans.c | 3 +--
include/linux/fs.h | 22 ++++++++++++++++++++++
6 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
index 135e278c832e..5f5c2121d2ad 100644
--- a/fs/ext4/ext4_jbd2.c
+++ b/fs/ext4/ext4_jbd2.c
@@ -75,7 +75,7 @@ static int ext4_journal_check_start(struct super_block *sb)
if (WARN_ON_ONCE(sb_rdonly(sb)))
return -EROFS;
- WARN_ON(sb->s_writers.frozen == SB_FREEZE_COMPLETE);
+ WARN_ON(sb_is_frozen(sb));
journal = EXT4_SB(sb)->s_journal;
/*
* Special case here: if the journal has aborted behind our
diff --git a/fs/gfs2/sys.c b/fs/gfs2/sys.c
index ecc699f8d9fc..08ec5904a208 100644
--- a/fs/gfs2/sys.c
+++ b/fs/gfs2/sys.c
@@ -156,7 +156,7 @@ static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf)
static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf)
{
struct super_block *sb = sdp->sd_vfs;
- int frozen = (sb->s_writers.frozen == SB_UNFROZEN) ? 0 : 1;
+ int frozen = sb_is_unfrozen(sb) ? 0 : 1;
return snprintf(buf, PAGE_SIZE, "%d\n", frozen);
}
diff --git a/fs/quota/quota.c b/fs/quota/quota.c
index 7c2b75a44485..9b4e0a80f386 100644
--- a/fs/quota/quota.c
+++ b/fs/quota/quota.c
@@ -890,11 +890,12 @@ static struct super_block *quotactl_block(const char __user *special, int cmd)
sb = user_get_super(dev, excl);
if (!sb)
return ERR_PTR(-ENODEV);
- if (thawed && sb->s_writers.frozen != SB_UNFROZEN) {
+ if (thawed && !sb_is_unfrozen(sb)) {
if (excl)
up_write(&sb->s_umount);
else
up_read(&sb->s_umount);
+
/* Wait for sb to unfreeze */
sb_start_write(sb);
sb_end_write(sb);
diff --git a/fs/super.c b/fs/super.c
index 97a17f9d9023..117bd1bfe09f 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -1029,7 +1029,7 @@ int reconfigure_super(struct fs_context *fc)
if (fc->sb_flags_mask & ~MS_RMT_MASK)
return -EINVAL;
- if (sb->s_writers.frozen != SB_UNFROZEN)
+ if (!(sb_is_unfrozen(sb)))
return -EBUSY;
retval = security_sb_remount(sb, fc->security);
@@ -1053,7 +1053,7 @@ int reconfigure_super(struct fs_context *fc)
__super_lock_excl(sb);
if (!sb->s_root)
return 0;
- if (sb->s_writers.frozen != SB_UNFROZEN)
+ if (!sb_is_unfrozen(sb))
return -EBUSY;
remount_ro = !sb_rdonly(sb);
}
@@ -2009,7 +2009,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who)
atomic_inc(&sb->s_active);
retry:
- if (sb->s_writers.frozen == SB_FREEZE_COMPLETE) {
+ if (sb_is_frozen(sb)) {
if (may_freeze(sb, who))
ret = !!WARN_ON_ONCE(freeze_inc(sb, who) == 1);
else
@@ -2019,7 +2019,7 @@ int freeze_super(struct super_block *sb, enum freeze_holder who)
return ret;
}
- if (sb->s_writers.frozen != SB_UNFROZEN) {
+ if (sb_is_unfrozen(sb)) {
ret = wait_for_partially_frozen(sb);
if (ret) {
deactivate_locked_super(sb);
diff --git a/fs/xfs/xfs_trans.c b/fs/xfs/xfs_trans.c
index c6657072361a..3a5088865064 100644
--- a/fs/xfs/xfs_trans.c
+++ b/fs/xfs/xfs_trans.c
@@ -269,8 +269,7 @@ xfs_trans_alloc(
* Zero-reservation ("empty") transactions can't modify anything, so
* they're allowed to run while we're frozen.
*/
- WARN_ON(resp->tr_logres > 0 &&
- mp->m_super->s_writers.frozen == SB_FREEZE_COMPLETE);
+ WARN_ON(resp->tr_logres > 0 && sb_is_frozen(mp->m_super));
ASSERT(!(flags & XFS_TRANS_RES_FDBLKS) ||
xfs_has_lazysbcount(mp));
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 016b0fe1536e..1d9a9c557e1a 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1971,6 +1971,28 @@ static inline bool sb_start_intwrite_trylock(struct super_block *sb)
return __sb_start_write_trylock(sb, SB_FREEZE_FS);
}
+/**
+ * sb_is_frozen - is superblock frozen
+ * @sb: the super to check
+ *
+ * Returns true if the super is frozen.
+ */
+static inline bool sb_is_frozen(struct super_block *sb)
+{
+ return sb->s_writers.frozen == SB_FREEZE_COMPLETE;
+}
+
+/**
+ * sb_is_unfrozen - is superblock unfrozen
+ * @sb: the super to check
+ *
+ * Returns true if the super is unfrozen.
+ */
+static inline bool sb_is_unfrozen(struct super_block *sb)
+{
+ return sb->s_writers.frozen == SB_UNFROZEN;
+}
+
bool inode_owner_or_capable(struct mnt_idmap *idmap,
const struct inode *inode);
--
2.47.2
next prev parent reply other threads:[~2025-03-26 11:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-26 11:22 [RFC 0/6] fs: automatic kernel fs freeze / thaw Luis Chamberlain
2025-03-26 11:22 ` Luis Chamberlain [this message]
2025-03-26 11:22 ` [RFC 2/6] fs: add iterate_supers_excl() and iterate_supers_reverse_excl() Luis Chamberlain
2025-03-26 13:17 ` Christian Brauner
2025-03-26 11:22 ` [RFC 3/6] fs: add automatic kernel fs freeze / thaw and remove kthread freezing Luis Chamberlain
2025-03-26 11:53 ` James Bottomley
2025-03-26 14:09 ` Christian Brauner
2025-03-26 14:37 ` James Bottomley
2025-03-26 11:22 ` [RFC 4/6] ext4: replace kthread freezing with auto fs freezing Luis Chamberlain
2025-03-26 17:57 ` Jan Kara
2025-03-26 11:22 ` [RFC 5/6] btrfs: " Luis Chamberlain
2025-03-26 11:22 ` [RFC 6/6] xfs: " Luis Chamberlain
2025-03-26 11:42 ` [RFC 0/6] fs: automatic kernel fs freeze / thaw Luis Chamberlain
2025-03-26 12:27 ` 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=20250326112220.1988619-2-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=James.Bottomley@HansenPartnership.com \
--cc=david@fromorbit.com \
--cc=djwong@kernel.org \
--cc=gost.dev@samsung.com \
--cc=hch@infradead.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pavel@kernel.org \
--cc=rafael@kernel.org \
--cc=song@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).