Linux XFS filesystem development
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Andrey Albershteyn <aalbersh@kernel.org>
Cc: "Darrick J . Wong" <djwong@kernel.org>, linux-xfs@vger.kernel.org
Subject: [PATCH 01/10] libxfs: refactor the reinit case in libxfs_buftarg_init
Date: Fri, 25 Sep 2026 07:12:47 +0200	[thread overview]
Message-ID: <20260925051336.2997014-2-hch@lst.de> (raw)
In-Reply-To: <20260925051336.2997014-1-hch@lst.de>

I had to wade through this to understand what is going on here.  Factor
the reinit code into a well-name helper and dump the rationale for it
into a comment to make it easier for the next person to understand the
logic.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 libxfs/init.c | 75 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 45 insertions(+), 30 deletions(-)

diff --git a/libxfs/init.c b/libxfs/init.c
index b89c9fe360d4..63015badc24e 100644
--- a/libxfs/init.c
+++ b/libxfs/init.c
@@ -487,6 +487,43 @@ static char *wf_opts[] = {
 	[WF_MAX_OPTS]		= NULL,
 };
 
+static void
+libxfs_buftarg_reinit(
+	struct xfs_mount	*mp,
+	struct libxfs_init	*xi)
+{
+	if (mp->m_ddev_targp->bt_bdev != xi->data.dev ||
+	    mp->m_ddev_targp->bt_mount != mp) {
+		fprintf(stderr,
+			_("%s: bad buftarg reinit, ddev\n"),
+			progname);
+		exit(1);
+	}
+
+	if (!xi->log.dev || xi->log.dev == xi->data.dev) {
+		if (mp->m_logdev_targp != mp->m_ddev_targp) {
+			fprintf(stderr,
+			_("%s: bad buftarg reinit, ldev mismatch\n"),
+				progname);
+			exit(1);
+		}
+	} else if (mp->m_logdev_targp->bt_bdev != xi->log.dev ||
+		   mp->m_logdev_targp->bt_mount != mp) {
+		fprintf(stderr,
+			_("%s: bad buftarg reinit, logdev\n"),
+			progname);
+		exit(1);
+	}
+	if ((xi->rt.dev || xi->rt.dev == xi->data.dev) &&
+	    (mp->m_rtdev_targp->bt_bdev != xi->rt.dev ||
+	     mp->m_rtdev_targp->bt_mount != mp)) {
+		fprintf(stderr,
+			_("%s: bad buftarg reinit, rtdev\n"),
+			progname);
+		exit(1);
+	}
+}
+
 void
 libxfs_buftarg_init(
 	struct xfs_mount	*mp,
@@ -532,37 +569,15 @@ libxfs_buftarg_init(
 		}
 	}
 
+	/*
+	 * This can happen if the utility called libxfs_buftarg_init manually
+	 * before libxfs_mount, which calls us again.
+	 *
+	 * In this case all buftargs should be initialized already, and we just
+	 * ensure the values are sane and match the current mount.
+	 */
 	if (mp->m_ddev_targp) {
-		/* should already have all buftargs initialised */
-		if (mp->m_ddev_targp->bt_bdev != xi->data.dev ||
-		    mp->m_ddev_targp->bt_mount != mp) {
-			fprintf(stderr,
-				_("%s: bad buftarg reinit, ddev\n"),
-				progname);
-			exit(1);
-		}
-		if (!xi->log.dev || xi->log.dev == xi->data.dev) {
-			if (mp->m_logdev_targp != mp->m_ddev_targp) {
-				fprintf(stderr,
-				_("%s: bad buftarg reinit, ldev mismatch\n"),
-					progname);
-				exit(1);
-			}
-		} else if (mp->m_logdev_targp->bt_bdev != xi->log.dev ||
-			   mp->m_logdev_targp->bt_mount != mp) {
-			fprintf(stderr,
-				_("%s: bad buftarg reinit, logdev\n"),
-				progname);
-			exit(1);
-		}
-		if ((xi->rt.dev || xi->rt.dev == xi->data.dev) &&
-		    (mp->m_rtdev_targp->bt_bdev != xi->rt.dev ||
-		     mp->m_rtdev_targp->bt_mount != mp)) {
-			fprintf(stderr,
-				_("%s: bad buftarg reinit, rtdev\n"),
-				progname);
-			exit(1);
-		}
+		libxfs_buftarg_reinit(mp, xi);
 		return;
 	}
 
-- 
2.53.0


  reply	other threads:[~2026-09-25  5:13 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-25  5:12 fix missing RT detection in libxfs v2 Christoph Hellwig
2026-09-25  5:12 ` Christoph Hellwig [this message]
2026-09-25 22:32   ` [PATCH 01/10] libxfs: refactor the reinit case in libxfs_buftarg_init Darrick J. Wong
2026-09-25  5:12 ` [PATCH 02/10] libxfs: split error injection option parsing out of libxfs_buftarg_init Christoph Hellwig
2026-09-25 22:33   ` Darrick J. Wong
2026-09-25  5:12 ` [PATCH 03/10] libxfs: remove buftarg member aliases Christoph Hellwig
2026-09-25  5:12 ` [PATCH 04/10] libxfs: unify buftarg handling with the kernel Christoph Hellwig
2026-09-25 22:37   ` Darrick J. Wong
2026-09-26  5:59     ` Christoph Hellwig
2026-09-27 15:18       ` Darrick J. Wong
2026-09-25  5:12 ` [PATCH 05/10] libxfs: make the size check in rtmount_init internal RT device aware Christoph Hellwig
2026-09-25 22:38   ` Darrick J. Wong
2026-09-25  5:12 ` [PATCH 06/10] libxfs: don't clear ->dev in libxfs_device_close Christoph Hellwig
2026-09-25 22:39   ` Darrick J. Wong
2026-09-25  5:12 ` [PATCH 07/10] libxfs: fix buftarg initialization for the RT device Christoph Hellwig
2026-09-25 22:42   ` Darrick J. Wong
2026-09-25  5:12 ` [PATCH 08/10] libxfs: rename bt_bdev* Christoph Hellwig
2026-09-25 22:43   ` Darrick J. Wong
2026-09-25  5:12 ` [PATCH 09/10] libfrog: improve ramdisk handling in platform_flush_device Christoph Hellwig
2026-09-25 22:47   ` Darrick J. Wong
2026-09-26  6:02     ` Christoph Hellwig
2026-09-27 15:22       ` Darrick J. Wong
2026-09-25  5:12 ` [PATCH 10/10] xfs_db: remove a double-whitespace in rdump_regfile_data Christoph Hellwig
2026-09-25 22:47   ` Darrick J. Wong

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=20260925051336.2997014-2-hch@lst.de \
    --to=hch@lst.de \
    --cc=aalbersh@kernel.org \
    --cc=djwong@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