From: Yun Zhou <yun.zhou@windriver.com>
To: <cem@kernel.org>
Cc: <linux-xfs@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<yun.zhou@windriver.com>
Subject: [PATCH] xfs: move xfs_sync_sb_buf() out of libxfs into xfs_ioctl.c
Date: Wed, 16 Sep 2026 08:43:35 +0800 [thread overview]
Message-ID: <20260916004335.228753-1-yun.zhou@windriver.com> (raw)
xfs_sync_sb_buf() dereferences mp->m_sb_bp and mp->m_rtsb_bp, which
only exist in the kernel's struct xfs_mount, not in xfsprogs' libxfs.
Keeping it in libxfs is a porting hazard.
Its only caller, xfs_ioc_setlabel(), is kernel-only, so move it there
and make it static.
Fixes: c1351fb48eee ("xfs: don't hold buffer locks across sync transaction commit in xfs_sync_sb_buf")
Suggested-by: Darrick J. Wong <djwong@kernel.org>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Yun Zhou <yun.zhou@windriver.com>
---
fs/xfs/libxfs/xfs_sb.c | 40 ----------------------------------------
fs/xfs/libxfs/xfs_sb.h | 1 -
fs/xfs/xfs_ioctl.c | 40 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 40 insertions(+), 41 deletions(-)
diff --git a/fs/xfs/libxfs/xfs_sb.c b/fs/xfs/libxfs/xfs_sb.c
index 2664728f2d8f..2c976b9d343d 100644
--- a/fs/xfs/libxfs/xfs_sb.c
+++ b/fs/xfs/libxfs/xfs_sb.c
@@ -1460,46 +1460,6 @@ xfs_update_secondary_sbs(
return saved_error ? saved_error : error;
}
-/*
- * Same behavior as xfs_sync_sb, except that it is always synchronous and it
- * also writes the superblock buffer to disk sector 0 immediately.
- */
-int
-xfs_sync_sb_buf(
- struct xfs_mount *mp,
- bool update_rtsb)
-{
- struct xfs_trans *tp;
- int error;
-
- error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp);
- if (error)
- return error;
-
- xfs_log_sb(tp);
- if (update_rtsb)
- xfs_log_rtsb(tp, xfs_trans_getsb(tp));
- xfs_trans_set_sync(tp);
- error = xfs_trans_commit(tp);
- if (error)
- return error;
-
- /* Re-acquire and write the sb and rtsb to disk. */
- xfs_buf_lock(mp->m_sb_bp);
- error = xfs_bwrite(mp->m_sb_bp);
- xfs_buf_unlock(mp->m_sb_bp);
- if (error)
- return error;
-
- if (update_rtsb && mp->m_rtsb_bp) {
- xfs_buf_lock(mp->m_rtsb_bp);
- error = xfs_bwrite(mp->m_rtsb_bp);
- xfs_buf_unlock(mp->m_rtsb_bp);
- }
-
- return error;
-}
-
void
xfs_fs_geometry(
struct xfs_mount *mp,
diff --git a/fs/xfs/libxfs/xfs_sb.h b/fs/xfs/libxfs/xfs_sb.h
index 34d0dd374e9b..77de65922213 100644
--- a/fs/xfs/libxfs/xfs_sb.h
+++ b/fs/xfs/libxfs/xfs_sb.h
@@ -15,7 +15,6 @@ struct xfs_perag;
extern void xfs_log_sb(struct xfs_trans *tp);
extern int xfs_sync_sb(struct xfs_mount *mp, bool wait);
-extern int xfs_sync_sb_buf(struct xfs_mount *mp, bool update_rtsb);
extern void xfs_sb_mount_common(struct xfs_mount *mp, struct xfs_sb *sbp);
void xfs_sb_mount_rextsize(struct xfs_mount *mp, struct xfs_sb *sbp);
void xfs_mount_sb_set_rextsize(struct xfs_mount *mp,
diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
index 1b53701bebea..fc8c59d2879c 100644
--- a/fs/xfs/xfs_ioctl.c
+++ b/fs/xfs/xfs_ioctl.c
@@ -1035,6 +1035,46 @@ xfs_ioc_getlabel(
return 0;
}
+/*
+ * Same behavior as xfs_sync_sb, except that it is always synchronous and it
+ * also writes the superblock buffer to disk sector 0 immediately.
+ */
+static int
+xfs_sync_sb_buf(
+ struct xfs_mount *mp,
+ bool update_rtsb)
+{
+ struct xfs_trans *tp;
+ int error;
+
+ error = xfs_trans_alloc(mp, &M_RES(mp)->tr_sb, 0, 0, 0, &tp);
+ if (error)
+ return error;
+
+ xfs_log_sb(tp);
+ if (update_rtsb)
+ xfs_log_rtsb(tp, xfs_trans_getsb(tp));
+ xfs_trans_set_sync(tp);
+ error = xfs_trans_commit(tp);
+ if (error)
+ return error;
+
+ /* Re-acquire and write the sb and rtsb to disk. */
+ xfs_buf_lock(mp->m_sb_bp);
+ error = xfs_bwrite(mp->m_sb_bp);
+ xfs_buf_unlock(mp->m_sb_bp);
+ if (error)
+ return error;
+
+ if (update_rtsb && mp->m_rtsb_bp) {
+ xfs_buf_lock(mp->m_rtsb_bp);
+ error = xfs_bwrite(mp->m_rtsb_bp);
+ xfs_buf_unlock(mp->m_rtsb_bp);
+ }
+
+ return error;
+}
+
static int
xfs_ioc_setlabel(
struct file *filp,
--
2.43.0
reply other threads:[~2026-09-16 0:43 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260916004335.228753-1-yun.zhou@windriver.com \
--to=yun.zhou@windriver.com \
--cc=cem@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.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
all inboxes | Powered by JetHome®