From patchwork Mon Dec 11 16:37:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487640 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="MCNKme/c" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E1FC98 for ; Mon, 11 Dec 2023 08:37:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=d59nT4IHoHqgpRImVueFbui60aL9QlMykGN6BmiZgTU=; b=MCNKme/cmH6B81ktYd5yYrT6lg x6VhgqQC7SQ4/JrpPhS3UxieDsEejEWiXYtYe0Wt2mSqnRnCzLdpC8vimdCShwOPdriEI9+AmVTvn O41RteVw1BZg+dS80cpdWXcbmrf8fe+pnIown562BQHHLSkw6ob2Ms3e6jS6akfyOZLoXhF6qPs1j mUez0ZF4dceNv9aSSP/D0x2SP8bjRnH/cZq1tJFc0iDoJdHIRJzLXZqCA3rZ+LILkH9pV1nb766Z9 FYa1JFIb127WPwQD6u3pTYO6x7Oq+T7ndpvMfyVZDXo3ttSYqng1Hg5i9Zg4vcYf8e4jkWeDsHMcU gR1vfEHQ==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjHw-005sqq-2Z; Mon, 11 Dec 2023 16:37:49 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 01/23] libxfs: remove the unused icache_flags member from struct libxfs_xinit Date: Mon, 11 Dec 2023 17:37:20 +0100 Message-Id: <20231211163742.837427-2-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- include/libxfs.h | 1 - 1 file changed, 1 deletion(-) diff --git a/include/libxfs.h b/include/libxfs.h index b28781d19..9b0294cb8 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -124,7 +124,6 @@ typedef struct libxfs_xinit { int dfd; /* data subvolume file descriptor */ int logfd; /* log subvolume file descriptor */ int rtfd; /* realtime subvolume file descriptor */ - int icache_flags; /* cache init flags */ int bcache_flags; /* cache init flags */ } libxfs_init_t; From patchwork Mon Dec 11 16:37:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487641 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="gVBLDFwm" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C971C8E for ; Mon, 11 Dec 2023 08:37:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=t1kw9Z/CzAaj4e3nEA0OcWjpVg8bPg4M0PWQkg1kwxo=; b=gVBLDFwmTuHiRCyp5hW6qPGtre StHvYXzXPNd+1Z+SjApZtIFfBy1WMgOMO16vk7ilOwDTSRKUGvaGHnK4zDWWBTg59ArJ87Suhl1o2 5lgIxl2fH4Mdisyt82ZC9xdwTeYatK6GX9XO0oG9pCFBxGDxS+k5gOUa75WlXRqU6xiFamuL5akKB il2XV432gSOSg5mJRYff2Wj0oV6OAlFs25LL/TCzx6kOkOCpq/Qt8omvFVlWKhTHVttEjKnvZ2ObJ kr9cmR399dlU5hLDanmJWnJ8hiJ/V+pLrgwOfMWslIKCaL273m/Cx9PZjqYiIa6k6QHnq/VEwF9hq WLWE8ogA==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjHz-005ssK-37; Mon, 11 Dec 2023 16:37:52 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 02/23] libxfs: remove the dead {d,log,rt}path variables in libxfs_init Date: Mon, 11 Dec 2023 17:37:21 +0100 Message-Id: <20231211163742.837427-3-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html These variables are only initialized, and then unlink is called if they were changed from the initial value, which can't happen. Remove the variables and the conditional unlink calls. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- libxfs/init.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/libxfs/init.c b/libxfs/init.c index ce6e62cde..a8603e2fb 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -307,17 +307,13 @@ libxfs_init(libxfs_init_t *a) { char *blockfile; char *dname; - char dpath[25]; int fd; char *logname; - char logpath[25]; char *rawfile; char *rtname; - char rtpath[25]; int rval = 0; int flags; - dpath[0] = logpath[0] = rtpath[0] = '\0'; dname = a->dname; logname = a->logname; rtname = a->rtname; @@ -418,12 +414,6 @@ libxfs_init(libxfs_init_t *a) init_caches(); rval = 1; done: - if (dpath[0]) - unlink(dpath); - if (logpath[0]) - unlink(logpath); - if (rtpath[0]) - unlink(rtpath); if (fd >= 0) close(fd); if (!rval) { From patchwork Mon Dec 11 16:37:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487642 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="h/0+39pT" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7D338E for ; Mon, 11 Dec 2023 08:37:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=+L/DwvnuIBCgDCK0ttwLb4zY2PjwmhZBQ3ZSNM1sfIg=; b=h/0+39pT6xpKJVuad7iO+g4yra nyow5ssi3/yE0TN0rrgnGdcnAWNg5nLxhMQn0L8P0DjdP1plWR3Z0g7iKEnw4xm+px0kbb5aKvSjl jb5jg/mYmD60tQuCP30MTZoGaYjB8epz6BdHZqpuaQeHCmjSIlWCuSNOWyfe7//TyPyzSxIdyYdtl JpHP2fLNt7bHJRe0cgtiqF+M7YQz66/SzrfxcguziUVzV5g74jfSOuwYI1JgVBll3KV1KmUsvM7bM KC6aQ3HxCF/OANZpDsMS+tQS9bS5qv9mdCRpILGUWiDRwdSeX55hjv4d03/1db896bVdNyhC+hUbj zMngTZiw==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjI3-005sto-0T; Mon, 11 Dec 2023 16:37:55 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 03/23] libxfs/frog: remove latform_find{raw,block}path Date: Mon, 11 Dec 2023 17:37:22 +0100 Message-Id: <20231211163742.837427-4-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Stop pretending we try to distinguish between the legacy Unix raw and block devices nodes. Linux as the only currently support platform never had them, but other modern Unix variants like FreeBSD also got rid of this distinction years ago. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- libfrog/linux.c | 12 ------------ libfrog/platform.h | 2 -- libxfs/init.c | 42 ++++++++++++++---------------------------- 3 files changed, 14 insertions(+), 42 deletions(-) diff --git a/libfrog/linux.c b/libfrog/linux.c index 0d9bd355f..2e4fd316e 100644 --- a/libfrog/linux.c +++ b/libfrog/linux.c @@ -232,18 +232,6 @@ platform_findsizes(char *path, int fd, long long *sz, int *bsz) max_block_alignment = *bsz; } -char * -platform_findrawpath(char *path) -{ - return path; -} - -char * -platform_findblockpath(char *path) -{ - return path; -} - int platform_direct_blockdev(void) { diff --git a/libfrog/platform.h b/libfrog/platform.h index 0aef318a8..e3e6b7c71 100644 --- a/libfrog/platform.h +++ b/libfrog/platform.h @@ -13,8 +13,6 @@ int platform_check_iswritable(char *path, char *block, struct stat *sptr); int platform_set_blocksize(int fd, char *path, dev_t device, int bsz, int fatal); int platform_flush_device(int fd, dev_t device); -char *platform_findrawpath(char *path); -char *platform_findblockpath(char *path); int platform_direct_blockdev(void); int platform_align_blockdev(void); unsigned long platform_physmem(void); /* in kilobytes */ diff --git a/libxfs/init.c b/libxfs/init.c index a8603e2fb..9cfd20e3f 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -197,7 +197,7 @@ libxfs_device_close(dev_t dev) } static int -check_open(char *path, int flags, char **rawfile, char **blockfile) +check_open(char *path, int flags) { int readonly = (flags & LIBXFS_ISREADONLY); int inactive = (flags & LIBXFS_ISINACTIVE); @@ -208,22 +208,10 @@ check_open(char *path, int flags, char **rawfile, char **blockfile) perror(path); return 0; } - if (!(*rawfile = platform_findrawpath(path))) { - fprintf(stderr, _("%s: " - "can't find a character device matching %s\n"), - progname, path); - return 0; - } - if (!(*blockfile = platform_findblockpath(path))) { - fprintf(stderr, _("%s: " - "can't find a block device matching %s\n"), - progname, path); - return 0; - } - if (!readonly && !inactive && platform_check_ismounted(path, *blockfile, NULL, 1)) + if (!readonly && !inactive && platform_check_ismounted(path, path, NULL, 1)) return 0; - if (inactive && check_isactive(path, *blockfile, ((readonly|dangerously)?1:0))) + if (inactive && check_isactive(path, path, ((readonly|dangerously)?1:0))) return 0; return 1; @@ -305,11 +293,9 @@ libxfs_close_devices( int libxfs_init(libxfs_init_t *a) { - char *blockfile; char *dname; int fd; char *logname; - char *rawfile; char *rtname; int rval = 0; int flags; @@ -330,9 +316,9 @@ libxfs_init(libxfs_init_t *a) radix_tree_init(); if (a->volname) { - if(!check_open(a->volname,flags,&rawfile,&blockfile)) + if (!check_open(a->volname, flags)) goto done; - fd = open(rawfile, O_RDONLY); + fd = open(a->volname, O_RDONLY); dname = a->dname = a->volname; a->volname = NULL; } @@ -344,12 +330,12 @@ libxfs_init(libxfs_init_t *a) platform_findsizes(dname, a->dfd, &a->dsize, &a->dbsize); } else { - if (!check_open(dname, flags, &rawfile, &blockfile)) + if (!check_open(dname, flags)) goto done; - a->ddev = libxfs_device_open(rawfile, + a->ddev = libxfs_device_open(dname, a->dcreat, flags, a->setblksize); a->dfd = libxfs_device_to_fd(a->ddev); - platform_findsizes(rawfile, a->dfd, + platform_findsizes(dname, a->dfd, &a->dsize, &a->dbsize); } } else @@ -362,12 +348,12 @@ libxfs_init(libxfs_init_t *a) platform_findsizes(dname, a->logfd, &a->logBBsize, &a->lbsize); } else { - if (!check_open(logname, flags, &rawfile, &blockfile)) + if (!check_open(logname, flags)) goto done; - a->logdev = libxfs_device_open(rawfile, + a->logdev = libxfs_device_open(logname, a->lcreat, flags, a->setblksize); a->logfd = libxfs_device_to_fd(a->logdev); - platform_findsizes(rawfile, a->logfd, + platform_findsizes(logname, a->logfd, &a->logBBsize, &a->lbsize); } } else @@ -380,12 +366,12 @@ libxfs_init(libxfs_init_t *a) platform_findsizes(dname, a->rtfd, &a->rtsize, &a->rtbsize); } else { - if (!check_open(rtname, flags, &rawfile, &blockfile)) + if (!check_open(rtname, flags)) goto done; - a->rtdev = libxfs_device_open(rawfile, + a->rtdev = libxfs_device_open(rtname, a->rcreat, flags, a->setblksize); a->rtfd = libxfs_device_to_fd(a->rtdev); - platform_findsizes(rawfile, a->rtfd, + platform_findsizes(rtname, a->rtfd, &a->rtsize, &a->rtbsize); } } else From patchwork Mon Dec 11 16:37:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487643 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="L4NCEbov" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFD88BD for ; Mon, 11 Dec 2023 08:37:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=mu1ksTTE57Ss8gfAcKRmIc2AK4SWs4x4c/UjztWn9TY=; b=L4NCEbovdQHCTdusfiasRXRamI 2TZ8nFmA4YgdgFV8z/d53jNzKtBdtmIXKAG/alqTJ1JHPW3IIGclDC2NisBnRpODvTjrF/LydI4sw d5u65nrWX2yuJPC/t/y85WYQIbMb6LHbmiSjTqCz7XTV5G0WYF28gIuikc5hbpNCjJwta1ZUaUJql fYZ+ZxKQdbI9a2wRKbzBQqQnVd9xvzZTGmpgcS6CGEipnTEj1CvRTJxzZU1pnNgCU/s3R8Wa6x81h lkyG7nS2PIc1rE+aLslZGOIElPOQsEQXmJeJDuqpTpGk0UuLsS8a+Xi/2QwQHoZOJFwaFHhut90aZ VeoTKtWA==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjI6-005sva-0m; Mon, 11 Dec 2023 16:37:58 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 04/23] libxfs: remove the volname concept Date: Mon, 11 Dec 2023 17:37:23 +0100 Message-Id: <20231211163742.837427-5-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html IRIX has the concept of a volume that has data/log/rt subvolumes (that's where the subvolume name in Linux comes from), but in the current Linux-only xfsprogs version trying to pretend we do anything with that it is just utterly confusing. The volname is basically just a very obsfucated second way to pass the data device name, so get rid of it in the libxfs and progs internals. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- copy/xfs_copy.c | 7 ++---- db/info.c | 2 +- db/init.c | 13 +++------- db/init.h | 1 - db/output.c | 2 +- include/libxfs.h | 1 - libxfs/init.c | 24 ++++-------------- libxfs/topology.c | 10 ++++---- mkfs/xfs_mkfs.c | 63 ++++++++++------------------------------------- repair/init.c | 11 ++------- 10 files changed, 33 insertions(+), 101 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 79f659467..66728f199 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -718,11 +718,8 @@ main(int argc, char **argv) xargs.isdirect = LIBXFS_DIRECT; xargs.isreadonly = LIBXFS_ISREADONLY; - if (source_is_file) { - xargs.dname = source_name; - xargs.disfile = 1; - } else - xargs.volname = source_name; + xargs.dname = source_name; + xargs.disfile = source_is_file; if (!libxfs_init(&xargs)) { do_log(_("%s: couldn't initialize XFS library\n" diff --git a/db/info.c b/db/info.c index 0f6c29429..b30ada3aa 100644 --- a/db/info.c +++ b/db/info.c @@ -30,7 +30,7 @@ info_f( struct xfs_fsop_geom geo; libxfs_fs_geometry(mp, &geo, XFS_FS_GEOM_MAX_STRUCT_VER); - xfs_report_geom(&geo, fsdevice, x.logname, x.rtname); + xfs_report_geom(&geo, x.dname, x.logname, x.rtname); return 0; } diff --git a/db/init.c b/db/init.c index 4599cc00d..18d9dfdd9 100644 --- a/db/init.c +++ b/db/init.c @@ -19,7 +19,6 @@ static char **cmdline; static int ncmdline; -char *fsdevice; int blkbb; int exitcode; int expert_mode; @@ -91,11 +90,7 @@ init( if (optind + 1 != argc) usage(); - fsdevice = argv[optind]; - if (!x.disfile) - x.volname = fsdevice; - else - x.dname = fsdevice; + x.dname = argv[optind]; x.isdirect = LIBXFS_DIRECT; x.bcache_flags = CACHE_MISCOMPARE_PURGE; @@ -115,7 +110,7 @@ init( 1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &bp, NULL); if (error) { fprintf(stderr, _("%s: %s is invalid (cannot read first 512 " - "bytes)\n"), progname, fsdevice); + "bytes)\n"), progname, x.dname); exit(1); } @@ -126,7 +121,7 @@ init( sbp = &xmount.m_sb; if (sbp->sb_magicnum != XFS_SB_MAGIC) { fprintf(stderr, _("%s: %s is not a valid XFS filesystem (unexpected SB magic number 0x%08x)\n"), - progname, fsdevice, sbp->sb_magicnum); + progname, x.dname, sbp->sb_magicnum); if (!force) { fprintf(stderr, _("Use -F to force a read attempt.\n")); exit(EXIT_FAILURE); @@ -139,7 +134,7 @@ init( if (!mp) { fprintf(stderr, _("%s: device %s unusable (not an XFS filesystem?)\n"), - progname, fsdevice); + progname, x.dname); exit(1); } mp->m_log = &xlog; diff --git a/db/init.h b/db/init.h index 16dc13f2b..05e75c100 100644 --- a/db/init.h +++ b/db/init.h @@ -4,7 +4,6 @@ * All Rights Reserved. */ -extern char *fsdevice; extern int blkbb; extern int exitcode; extern int expert_mode; diff --git a/db/output.c b/db/output.c index 422148afa..30ae82ced 100644 --- a/db/output.c +++ b/db/output.c @@ -34,7 +34,7 @@ dbprintf(const char *fmt, ...) blockint(); i = 0; if (dbprefix) - i += printf("%s: ", fsdevice); + i += printf("%s: ", x.dname); i += vprintf(fmt, ap); unblockint(); va_end(ap); diff --git a/include/libxfs.h b/include/libxfs.h index 9b0294cb8..b35dc2184 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -94,7 +94,6 @@ struct iomap; */ typedef struct libxfs_xinit { /* input parameters */ - char *volname; /* pathname of volume */ char *dname; /* pathname of data "subvolume" */ char *logname; /* pathname of log "subvolume" */ char *rtname; /* pathname of realtime "subvolume" */ diff --git a/libxfs/init.c b/libxfs/init.c index 9cfd20e3f..894d84057 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -294,10 +294,8 @@ int libxfs_init(libxfs_init_t *a) { char *dname; - int fd; char *logname; char *rtname; - int rval = 0; int flags; dname = a->dname; @@ -308,20 +306,12 @@ libxfs_init(libxfs_init_t *a) a->dsize = a->lbsize = a->rtbsize = 0; a->dbsize = a->logBBsize = a->logBBstart = a->rtsize = 0; - fd = -1; flags = (a->isreadonly | a->isdirect); rcu_init(); rcu_register_thread(); radix_tree_init(); - if (a->volname) { - if (!check_open(a->volname, flags)) - goto done; - fd = open(a->volname, O_RDONLY); - dname = a->dname = a->volname; - a->volname = NULL; - } if (dname) { if (a->disfile) { a->ddev= libxfs_device_open(dname, a->dcreat, flags, @@ -398,16 +388,12 @@ libxfs_init(libxfs_init_t *a) use_xfs_buf_lock = a->usebuflock; xfs_dir_startup(); init_caches(); - rval = 1; -done: - if (fd >= 0) - close(fd); - if (!rval) { - libxfs_close_devices(a); - rcu_unregister_thread(); - } + return 1; - return rval; +done: + libxfs_close_devices(a); + rcu_unregister_thread(); + return 0; } diff --git a/libxfs/topology.c b/libxfs/topology.c index a17c19691..25f47beda 100644 --- a/libxfs/topology.c +++ b/libxfs/topology.c @@ -292,7 +292,6 @@ void get_topology( int force_overwrite) { struct stat statbuf; - char *dfile = xi->volname ? xi->volname : xi->dname; /* * If our target is a regular file, use platform_findsizes @@ -300,7 +299,7 @@ void get_topology( * for direct IO; we'll set our sector size to that if possible. */ if (xi->disfile || - (!stat(dfile, &statbuf) && S_ISREG(statbuf.st_mode))) { + (!stat(xi->dname, &statbuf) && S_ISREG(statbuf.st_mode))) { int fd; int flags = O_RDONLY; long long dummy; @@ -309,15 +308,16 @@ void get_topology( if (xi->disfile) flags |= O_CREAT; - fd = open(dfile, flags, 0666); + fd = open(xi->dname, flags, 0666); if (fd >= 0) { - platform_findsizes(dfile, fd, &dummy, &ft->lsectorsize); + platform_findsizes(xi->dname, fd, &dummy, + &ft->lsectorsize); close(fd); ft->psectorsize = ft->lsectorsize; } else ft->psectorsize = ft->lsectorsize = BBSIZE; } else { - blkid_get_topology(dfile, &ft->dsunit, &ft->dswidth, + blkid_get_topology(xi->dname, &ft->dsunit, &ft->dswidth, &ft->lsectorsize, &ft->psectorsize, force_overwrite); } diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index c522cb4df..19849ed21 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -1959,7 +1959,6 @@ validate_sectorsize( struct cli_params *cli, struct mkfs_default_params *dft, struct fs_topology *ft, - char *dfile, int dry_run, int force_overwrite) { @@ -1967,7 +1966,8 @@ validate_sectorsize( * Before anything else, verify that we are correctly operating on * files or block devices and set the control parameters correctly. */ - check_device_type(dfile, &cli->xi->disfile, !cli->dsize, !dfile, + check_device_type(cli->xi->dname, &cli->xi->disfile, + !cli->dsize, !cli->xi->dname, dry_run ? NULL : &cli->xi->dcreat, "d"); if (!cli->loginternal) check_device_type(cli->xi->logname, &cli->xi->lisfile, @@ -2929,36 +2929,17 @@ reported by the device (%u).\n"), } } -/* - * This is more complex than it needs to be because we still support volume - * based external logs. They are only discovered *after* the devices have been - * opened, hence the crazy "is this really an internal log" checks here. - */ static void validate_logdev( struct mkfs_params *cfg, - struct cli_params *cli, - char **devname) + struct cli_params *cli) { struct libxfs_xinit *xi = cli->xi; - *devname = NULL; - - /* check for volume log first */ - if (cli->loginternal && xi->volname && xi->logdev) { - *devname = _("volume log"); - cfg->loginternal = false; - } else - cfg->loginternal = cli->loginternal; + cfg->loginternal = cli->loginternal; /* now run device checks */ if (cfg->loginternal) { - if (xi->logdev) { - fprintf(stderr, -_("can't have both external and internal logs\n")); - usage(); - } - /* * if no sector size has been specified on the command line, * use what has been configured and validated for the data @@ -2980,14 +2961,11 @@ _("log size %lld too large for internal log\n"), (long long)cfg->logblocks); usage(); } - *devname = _("internal log"); return; } /* External/log subvolume checks */ - if (xi->logname) - *devname = xi->logname; - if (!*devname || !xi->logdev) { + if (!*xi->logname || !xi->logdev) { fprintf(stderr, _("no log subvolume or external log.\n")); usage(); } @@ -3018,13 +2996,10 @@ reported by the device (%u).\n"), static void validate_rtdev( struct mkfs_params *cfg, - struct cli_params *cli, - char **devname) + struct cli_params *cli) { struct libxfs_xinit *xi = cli->xi; - *devname = NULL; - if (!xi->rtdev) { if (cli->rtsize) { fprintf(stderr, @@ -3032,7 +3007,6 @@ _("size specified for non-existent rt subvolume\n")); usage(); } - *devname = _("none"); cfg->rtblocks = 0; cfg->rtextents = 0; cfg->rtbmblocks = 0; @@ -3043,12 +3017,6 @@ _("size specified for non-existent rt subvolume\n")); usage(); } - /* volume rtdev */ - if (xi->volname) - *devname = _("volume rt"); - else - *devname = xi->rtname; - if (cli->rtsize) { if (cfg->rtblocks > DTOBT(xi->rtsize, cfg->blocklog)) { fprintf(stderr, @@ -4080,9 +4048,6 @@ main( xfs_agnumber_t agno; struct xfs_buf *buf; int c; - char *dfile = NULL; - char *logfile = NULL; - char *rtfile = NULL; int dry_run = 0; int discard = 1; int force_overwrite = 0; @@ -4222,9 +4187,8 @@ main( fprintf(stderr, _("extra arguments\n")); usage(); } else if (argc - optind == 1) { - dfile = xi.volname = getstr(argv[optind], &dopts, D_NAME); - } else - dfile = xi.dname; + xi.dname = getstr(argv[optind], &dopts, D_NAME); + } /* * Now we have all the options parsed, we can read in the option file @@ -4241,8 +4205,7 @@ main( * before opening the libxfs devices. */ validate_blocksize(&cfg, &cli, &dft); - validate_sectorsize(&cfg, &cli, &dft, &ft, dfile, dry_run, - force_overwrite); + validate_sectorsize(&cfg, &cli, &dft, &ft, dry_run, force_overwrite); /* * XXX: we still need to set block size and sector size global variables @@ -4277,10 +4240,10 @@ main( * Open and validate the device configurations */ open_devices(&cfg, &xi); - validate_overwrite(dfile, force_overwrite); + validate_overwrite(xi.dname, force_overwrite); validate_datadev(&cfg, &cli); - validate_logdev(&cfg, &cli, &logfile); - validate_rtdev(&cfg, &cli, &rtfile); + validate_logdev(&cfg, &cli); + validate_rtdev(&cfg, &cli); calc_stripe_factors(&cfg, &cli, &ft); /* @@ -4321,7 +4284,7 @@ main( struct xfs_fsop_geom geo; libxfs_fs_geometry(mp, &geo, XFS_FS_GEOM_MAX_STRUCT_VER); - xfs_report_geom(&geo, dfile, logfile, rtfile); + xfs_report_geom(&geo, xi.dname, xi.logname, xi.rtname); if (dry_run) exit(0); } diff --git a/repair/init.c b/repair/init.c index 0d5bfabcf..6d019b393 100644 --- a/repair/init.c +++ b/repair/init.c @@ -54,15 +54,8 @@ xfs_init(libxfs_init_t *args) { memset(args, 0, sizeof(libxfs_init_t)); - if (isa_file) { - args->disfile = 1; - args->dname = fs_name; - args->volname = NULL; - } else { - args->disfile = 0; - args->volname = fs_name; - args->dname = NULL; - } + args->dname = fs_name; + args->disfile = isa_file; if (log_spec) { /* External log specified */ args->logname = log_name; From patchwork Mon Dec 11 16:37:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487644 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="RUe2wtvU" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 017AAC2 for ; Mon, 11 Dec 2023 08:38:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=kFRVmyseUjRZgsiWDUd88An0u1cuEV0SuqTwpagIn+s=; b=RUe2wtvUJYvSs4BXyfCDi1qH12 psEuxqY/e1bcf46mhPV0xLLLCn5fkJ4wxRA7kzzcHldIpyUgoOtZ75g6kfMyiHAzomByYzjNwtavD ORSkJ2d23WUjIIqsjAIOSfVZDkJjViSmkMqagcMd6WAWjbaAAZoWdpgifue9H5dUxB7YMIInPU4he 8lhP074yvy2Nr3ig8JkppqGpbz6j3rsWVP2biUrL8C6rPBGihJtynUXXM8GloyirO4sgNu1ciY7ai wvJhuXQ9+gwGhEhoJaDgS2JuFzjGCDNAcJVRS0RlsdTHO7HId5HVFchNrY5ZoikTCYLMqCAWGq75a 1bnGFbfQ==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjI9-005sxF-0v; Mon, 11 Dec 2023 16:38:01 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 05/23] xfs_logprint: move all code to set up the fake xlog into logstat() Date: Mon, 11 Dec 2023 17:37:24 +0100 Message-Id: <20231211163742.837427-6-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Isolate the code that sets up the fake xlog into the logstat() helper to prepare for upcoming changes. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- logprint/logprint.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/logprint/logprint.c b/logprint/logprint.c index 9a8811f46..7d51cdd91 100644 --- a/logprint/logprint.c +++ b/logprint/logprint.c @@ -52,7 +52,9 @@ Options:\n\ } static int -logstat(xfs_mount_t *mp) +logstat( + struct xfs_mount *mp, + struct xlog *log) { int fd; char buf[BBSIZE]; @@ -103,6 +105,11 @@ logstat(xfs_mount_t *mp) x.lbsize = BBSIZE; } + log->l_dev = mp->m_logdev_targp; + log->l_logBBstart = x.logBBstart; + log->l_logBBsize = x.logBBsize; + log->l_sectBBsize = BTOBB(x.lbsize); + log->l_mp = mp; if (x.logname && *x.logname) { /* External log */ if ((fd = open(x.logname, O_RDONLY)) == -1) { @@ -212,8 +219,8 @@ main(int argc, char **argv) if (!libxfs_init(&x)) exit(1); - logstat(&mount); libxfs_buftarg_init(&mount, x.ddev, x.logdev, x.rtdev); + logstat(&mount, &log); logfd = (x.logfd < 0) ? x.dfd : x.logfd; @@ -226,15 +233,9 @@ main(int argc, char **argv) } printf(_("daddr: %lld length: %lld\n\n"), - (long long)x.logBBstart, (long long)x.logBBsize); + (long long)log.l_logBBstart, (long long)log.l_logBBsize); - ASSERT(x.logBBsize <= INT_MAX); - - log.l_dev = mount.m_logdev_targp; - log.l_logBBstart = x.logBBstart; - log.l_logBBsize = x.logBBsize; - log.l_sectBBsize = BTOBB(x.lbsize); - log.l_mp = &mount; + ASSERT(log.l_logBBsize <= INT_MAX); switch (print_operation) { case OP_PRINT: From patchwork Mon Dec 11 16:37:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487645 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GqUFkB6k" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E83FC95 for ; Mon, 11 Dec 2023 08:38:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=BZ7hB4JDE8U95MW6mQ0Xj/9LuQAZT+9aat/HkrPyt0g=; b=GqUFkB6kVZsjvO95uwGitDjosy KJ0QlAgD4lGoTMl6o43V3hN1csinWngr/dapgNxkggJ6cohq5AmYAnkR47p3tSzQvsjdl+4wqYBs1 xkhhNsMsOX1tcItTN6X0o8EsHGMR7ImimK3UGeTgHjFeqAiFSO8J8c1HHtNYi8t6DRYDT4g1xFW2e nJIXSn825+zEOoiOfR0IaN08mg3j8LgV0pyPsITgNU39s4LrjA2mvnZwOnl2WzCyOck/epmUMYwkB NCr2ySMQl6Pi5Vv8n8ChrgD8IWYEb3ekznW26uRvc66OiZ7hO/mRuoGYHeK7oze9U4G94hDnRzoyu XuU8Q3fw==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIC-005syr-0c; Mon, 11 Dec 2023 16:38:04 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 06/23] libxlog: remove the verbose argument to xlog_is_dirty Date: Mon, 11 Dec 2023 17:37:25 +0100 Message-Id: <20231211163742.837427-7-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html No caller passes a non-zero verbose argument to xlog_is_dirty. Remove the argument the code keyed off by it. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- copy/xfs_copy.c | 2 +- db/metadump.c | 4 ++-- db/sb.c | 2 +- include/libxlog.h | 3 +-- libxlog/util.c | 8 +------- 5 files changed, 6 insertions(+), 13 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 66728f199..4bd473a04 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -784,7 +784,7 @@ main(int argc, char **argv) */ memset(&xlog, 0, sizeof(struct xlog)); mp->m_log = &xlog; - c = xlog_is_dirty(mp, mp->m_log, &xargs, 0); + c = xlog_is_dirty(mp, mp->m_log, &xargs); if (!duplicate) { if (c == 1) { do_log(_( diff --git a/db/metadump.c b/db/metadump.c index f9c82148e..e57b024cd 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -2615,7 +2615,7 @@ copy_log(void) if (!metadump.obfuscate && !metadump.zero_stale_data) goto done; - dirty = xlog_is_dirty(mp, &log, &x, 0); + dirty = xlog_is_dirty(mp, &log, &x); switch (dirty) { case 0: @@ -2945,7 +2945,7 @@ metadump_f( if (iocur_top->data) { /* best effort */ struct xlog log; - if (xlog_is_dirty(mp, &log, &x, 0)) + if (xlog_is_dirty(mp, &log, &x)) metadump.dirty_log = true; } pop_cur(); diff --git a/db/sb.c b/db/sb.c index 2d508c26a..a3a4a758f 100644 --- a/db/sb.c +++ b/db/sb.c @@ -235,7 +235,7 @@ sb_logcheck(void) libxfs_buftarg_init(mp, x.ddev, x.logdev, x.rtdev); - dirty = xlog_is_dirty(mp, mp->m_log, &x, 0); + dirty = xlog_is_dirty(mp, mp->m_log, &x); if (dirty == -1) { dbprintf(_("ERROR: cannot find log head/tail, run xfs_repair\n")); return 0; diff --git a/include/libxlog.h b/include/libxlog.h index 3ade7ffaf..a598a7b3c 100644 --- a/include/libxlog.h +++ b/include/libxlog.h @@ -71,9 +71,8 @@ extern int print_record_header; /* libxfs parameters */ extern libxfs_init_t x; +int xlog_is_dirty(struct xfs_mount *mp, struct xlog *log, libxfs_init_t *x); -extern int xlog_is_dirty(struct xfs_mount *, struct xlog *, libxfs_init_t *, - int); extern struct xfs_buf *xlog_get_bp(struct xlog *, int); extern int xlog_bread(struct xlog *log, xfs_daddr_t blk_no, int nbblks, struct xfs_buf *bp, char **offset); diff --git a/libxlog/util.c b/libxlog/util.c index ad60036f8..1022e3378 100644 --- a/libxlog/util.c +++ b/libxlog/util.c @@ -19,8 +19,7 @@ int xlog_is_dirty( struct xfs_mount *mp, struct xlog *log, - libxfs_init_t *x, - int verbose) + libxfs_init_t *x) { int error; xfs_daddr_t head_blk, tail_blk; @@ -58,11 +57,6 @@ xlog_is_dirty( return -1; } - if (verbose) - xlog_warn( - _("%s: head block %" PRId64 " tail block %" PRId64 "\n"), - __func__, head_blk, tail_blk); - if (head_blk != tail_blk) return 1; From patchwork Mon Dec 11 16:37:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487646 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="rScg+W/X" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE4E391 for ; Mon, 11 Dec 2023 08:38:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=FtVDf2BvTNsPIqBX1aCrgYsKN1KD/vMDX0iHsctNH6Q=; b=rScg+W/XfIiVy2ay6WbGqWV1kr rRMOVU3rQBccOt4LNIypmIJz/WaEdb/i/9hEFH9EQoAXjjdahddCfrin40UJ72Pd78Dd7lavxXAJW 4MuCHdOWoFpK57H/DiphoVG8GYVv1uigP0QEwD4KQHLW6lROUTOPBulJ6Hq7ACa757E81GJW1hYLO QxdyB/+qtvaDBkEH84dWibYgAhuqsydoB8TduYf/BuYb1UOe7WYXJepofsA7fSGwMmZ79DpTkANNP ltW41YvXd/zEc51saoUCDigx6Tmk7MqONeV+wzNrwiunJ8mCoPvzAMGFmt9UKglXHGZ5YFuph5Y42 uZ0HMxUA==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIE-005t0Y-3B; Mon, 11 Dec 2023 16:38:07 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 07/23] libxlog: add a helper to initialize a xlog without clobbering the x structure Date: Mon, 11 Dec 2023 17:37:26 +0100 Message-Id: <20231211163742.837427-8-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html xfsprogs has three copies of a code sequence to initialize an xlog structure from a libxfs_init structure. Factor the code into a helper. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- include/libxlog.h | 1 + libxlog/util.c | 25 +++++++++++++++++-------- logprint/logprint.c | 25 +++++++++---------------- repair/phase2.c | 23 +---------------------- 4 files changed, 28 insertions(+), 46 deletions(-) diff --git a/include/libxlog.h b/include/libxlog.h index a598a7b3c..657acfe42 100644 --- a/include/libxlog.h +++ b/include/libxlog.h @@ -71,6 +71,7 @@ extern int print_record_header; /* libxfs parameters */ extern libxfs_init_t x; +void xlog_init(struct xfs_mount *mp, struct xlog *log, libxfs_init_t *x); int xlog_is_dirty(struct xfs_mount *mp, struct xlog *log, libxfs_init_t *x); extern struct xfs_buf *xlog_get_bp(struct xlog *, int); diff --git a/libxlog/util.c b/libxlog/util.c index 1022e3378..bc4db478e 100644 --- a/libxlog/util.c +++ b/libxlog/util.c @@ -12,18 +12,12 @@ int print_skip_uuid; int print_record_header; libxfs_init_t x; -/* - * Return 1 for dirty, 0 for clean, -1 for errors - */ -int -xlog_is_dirty( +void +xlog_init( struct xfs_mount *mp, struct xlog *log, libxfs_init_t *x) { - int error; - xfs_daddr_t head_blk, tail_blk; - memset(log, 0, sizeof(*log)); /* We (re-)init members of libxfs_init_t here? really? */ @@ -48,6 +42,21 @@ xlog_is_dirty( ASSERT(mp->m_sb.sb_logsectlog >= BBSHIFT); } log->l_sectbb_mask = (1 << log->l_sectbb_log) - 1; +} + +/* + * Return 1 for dirty, 0 for clean, -1 for errors + */ +int +xlog_is_dirty( + struct xfs_mount *mp, + struct xlog *log, + libxfs_init_t *x) +{ + int error; + xfs_daddr_t head_blk, tail_blk; + + xlog_init(mp, log, x); error = xlog_find_tail(log, &head_blk, &tail_blk); if (error) { diff --git a/logprint/logprint.c b/logprint/logprint.c index 7d51cdd91..c78aeb2f8 100644 --- a/logprint/logprint.c +++ b/logprint/logprint.c @@ -58,7 +58,6 @@ logstat( { int fd; char buf[BBSIZE]; - xfs_sb_t *sb; /* On Linux we always read the superblock of the * filesystem. We need this to get the length of the @@ -77,19 +76,16 @@ logstat( close (fd); if (!x.disfile) { + struct xfs_sb *sb = &mp->m_sb; + /* * Conjure up a mount structure */ - sb = &mp->m_sb; libxfs_sb_from_disk(sb, (struct xfs_dsb *)buf); mp->m_features |= libxfs_sb_version_to_features(&mp->m_sb); mp->m_blkbb_log = sb->sb_blocklog - BBSHIFT; - x.logBBsize = XFS_FSB_TO_BB(mp, sb->sb_logblocks); - x.logBBstart = XFS_FSB_TO_DADDR(mp, sb->sb_logstart); - x.lbsize = BBSIZE; - if (xfs_has_sector(mp)) - x.lbsize <<= (sb->sb_logsectlog - BBSHIFT); + xlog_init(mp, log, &x); if (!x.logname && sb->sb_logstart == 0) { fprintf(stderr, _(" external log device not specified\n\n")); @@ -100,16 +96,13 @@ logstat( struct stat s; stat(x.dname, &s); - x.logBBsize = s.st_size >> 9; - x.logBBstart = 0; - x.lbsize = BBSIZE; - } - log->l_dev = mp->m_logdev_targp; - log->l_logBBstart = x.logBBstart; - log->l_logBBsize = x.logBBsize; - log->l_sectBBsize = BTOBB(x.lbsize); - log->l_mp = mp; + log->l_logBBsize = s.st_size >> 9; + log->l_logBBstart = 0; + log->l_sectBBsize = BTOBB(BBSIZE); + log->l_dev = mp->m_logdev_targp; + log->l_mp = mp; + } if (x.logname && *x.logname) { /* External log */ if ((fd = open(x.logname, O_RDONLY)) == -1) { diff --git a/repair/phase2.c b/repair/phase2.c index 2ada95aef..a9dd77be3 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -30,28 +30,7 @@ zero_log( xfs_daddr_t tail_blk; struct xlog *log = mp->m_log; - memset(log, 0, sizeof(struct xlog)); - x.logBBsize = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks); - x.logBBstart = XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart); - x.lbsize = BBSIZE; - if (xfs_has_sector(mp)) - x.lbsize <<= (mp->m_sb.sb_logsectlog - BBSHIFT); - - log->l_dev = mp->m_logdev_targp; - log->l_logBBsize = x.logBBsize; - log->l_logBBstart = x.logBBstart; - log->l_sectBBsize = BTOBB(x.lbsize); - log->l_mp = mp; - if (xfs_has_sector(mp)) { - log->l_sectbb_log = mp->m_sb.sb_logsectlog - BBSHIFT; - ASSERT(log->l_sectbb_log <= mp->m_sectbb_log); - /* for larger sector sizes, must have v2 or external log */ - ASSERT(log->l_sectbb_log == 0 || - log->l_logBBstart == 0 || - xfs_has_logv2(mp)); - ASSERT(mp->m_sb.sb_logsectlog >= BBSHIFT); - } - log->l_sectbb_mask = (1 << log->l_sectbb_log) - 1; + xlog_init(mp, mp->m_log, &x); /* * Find the log head and tail and alert the user to the situation if the From patchwork Mon Dec 11 16:37:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487647 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="u7UiT1N3" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 620CA8E for ; Mon, 11 Dec 2023 08:38:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=/gqTejgdpI0z2c8oe/kZNt7Wg4YOkgkoMqOtDFIlUCo=; b=u7UiT1N3ucYsDLhWBHblJ4psvm 5cqfeQDMPbrkVEoW9iQ+AjqT3XOx3iH8JLIGjZ13bt3ENGdsdeztIAAh+aidgm+ottVXVfYINfprC zJ3zYguWfTWC7LUayVZhQTUXudqJ8kQhqCYWeP33aobOFroaRLdJOu27tC2M2QFpLku/54qxn6S93 zBbvq/IYK4JnS8ORBATmqLRmtrhK1MW3B3K2g/0Zgky/puhB6Hi2hgvv7HSvsemv8kCzNySk5YVOt XBk2byWqJVLGOk0VtNRU/9hNwh3UqVKJQH7p4nuRu6q/maetnAKu7a8ZHBcfEnXvllzmbZLkop+9Z ThkUZHcg==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIH-005t2p-2s; Mon, 11 Dec 2023 16:38:10 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 08/23] libxlog: don't require a libxfs_xinit structure for xlog_init Date: Mon, 11 Dec 2023 17:37:27 +0100 Message-Id: <20231211163742.837427-9-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html xlog_init currently requires a libxfs_args structure to be passed in, and then clobbers various log-related arguments to it. There is no good reason for that as all the required information can be calculated without it. Remove the x argument to xlog_init and xlog_is_dirty and the now unused logBBstart member in struct libxfs_xinit. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- copy/xfs_copy.c | 2 +- db/metadump.c | 4 ++-- db/sb.c | 2 +- include/libxfs.h | 1 - include/libxlog.h | 4 ++-- libxfs/init.c | 2 +- libxlog/util.c | 25 ++++++++++--------------- logprint/logprint.c | 2 +- repair/phase2.c | 2 +- 9 files changed, 19 insertions(+), 25 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 4bd473a04..86187086d 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -784,7 +784,7 @@ main(int argc, char **argv) */ memset(&xlog, 0, sizeof(struct xlog)); mp->m_log = &xlog; - c = xlog_is_dirty(mp, mp->m_log, &xargs); + c = xlog_is_dirty(mp, mp->m_log); if (!duplicate) { if (c == 1) { do_log(_( diff --git a/db/metadump.c b/db/metadump.c index e57b024cd..bac35b9cc 100644 --- a/db/metadump.c +++ b/db/metadump.c @@ -2615,7 +2615,7 @@ copy_log(void) if (!metadump.obfuscate && !metadump.zero_stale_data) goto done; - dirty = xlog_is_dirty(mp, &log, &x); + dirty = xlog_is_dirty(mp, &log); switch (dirty) { case 0: @@ -2945,7 +2945,7 @@ metadump_f( if (iocur_top->data) { /* best effort */ struct xlog log; - if (xlog_is_dirty(mp, &log, &x)) + if (xlog_is_dirty(mp, &log)) metadump.dirty_log = true; } pop_cur(); diff --git a/db/sb.c b/db/sb.c index a3a4a758f..2f046c6aa 100644 --- a/db/sb.c +++ b/db/sb.c @@ -235,7 +235,7 @@ sb_logcheck(void) libxfs_buftarg_init(mp, x.ddev, x.logdev, x.rtdev); - dirty = xlog_is_dirty(mp, mp->m_log, &x); + dirty = xlog_is_dirty(mp, mp->m_log); if (dirty == -1) { dbprintf(_("ERROR: cannot find log head/tail, run xfs_repair\n")); return 0; diff --git a/include/libxfs.h b/include/libxfs.h index b35dc2184..270efb2c1 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -115,7 +115,6 @@ typedef struct libxfs_xinit { long long logBBsize; /* size of log subvolume (BBs) */ /* (blocks allocated for use as * log is stored in mount structure) */ - long long logBBstart; /* start block of log subvolume (BBs) */ long long rtsize; /* size of realtime subvolume (BBs) */ int dbsize; /* data subvolume device blksize */ int lbsize; /* log subvolume device blksize */ diff --git a/include/libxlog.h b/include/libxlog.h index 657acfe42..57f39e4e8 100644 --- a/include/libxlog.h +++ b/include/libxlog.h @@ -71,8 +71,8 @@ extern int print_record_header; /* libxfs parameters */ extern libxfs_init_t x; -void xlog_init(struct xfs_mount *mp, struct xlog *log, libxfs_init_t *x); -int xlog_is_dirty(struct xfs_mount *mp, struct xlog *log, libxfs_init_t *x); +void xlog_init(struct xfs_mount *mp, struct xlog *log); +int xlog_is_dirty(struct xfs_mount *mp, struct xlog *log); extern struct xfs_buf *xlog_get_bp(struct xlog *, int); extern int xlog_bread(struct xlog *log, xfs_daddr_t blk_no, int nbblks, diff --git a/libxfs/init.c b/libxfs/init.c index 894d84057..6482ba52b 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -304,7 +304,7 @@ libxfs_init(libxfs_init_t *a) a->dfd = a->logfd = a->rtfd = -1; a->ddev = a->logdev = a->rtdev = 0; a->dsize = a->lbsize = a->rtbsize = 0; - a->dbsize = a->logBBsize = a->logBBstart = a->rtsize = 0; + a->dbsize = a->logBBsize = a->rtsize = 0; flags = (a->isreadonly | a->isdirect); diff --git a/libxlog/util.c b/libxlog/util.c index bc4db478e..d1377c2e2 100644 --- a/libxlog/util.c +++ b/libxlog/util.c @@ -15,22 +15,18 @@ libxfs_init_t x; void xlog_init( struct xfs_mount *mp, - struct xlog *log, - libxfs_init_t *x) + struct xlog *log) { - memset(log, 0, sizeof(*log)); + unsigned int log_sect_size = BBSIZE; - /* We (re-)init members of libxfs_init_t here? really? */ - x->logBBsize = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks); - x->logBBstart = XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart); - x->lbsize = BBSIZE; - if (xfs_has_sector(mp)) - x->lbsize <<= (mp->m_sb.sb_logsectlog - BBSHIFT); + memset(log, 0, sizeof(*log)); log->l_dev = mp->m_logdev_targp; - log->l_logBBsize = x->logBBsize; - log->l_logBBstart = x->logBBstart; - log->l_sectBBsize = BTOBB(x->lbsize); + log->l_logBBsize = XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks); + log->l_logBBstart = XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart); + if (xfs_has_sector(mp)) + log_sect_size <<= (mp->m_sb.sb_logsectlog - BBSHIFT); + log->l_sectBBsize = BTOBB(log_sect_size); log->l_mp = mp; if (xfs_has_sector(mp)) { log->l_sectbb_log = mp->m_sb.sb_logsectlog - BBSHIFT; @@ -50,13 +46,12 @@ xlog_init( int xlog_is_dirty( struct xfs_mount *mp, - struct xlog *log, - libxfs_init_t *x) + struct xlog *log) { int error; xfs_daddr_t head_blk, tail_blk; - xlog_init(mp, log, x); + xlog_init(mp, log); error = xlog_find_tail(log, &head_blk, &tail_blk); if (error) { diff --git a/logprint/logprint.c b/logprint/logprint.c index c78aeb2f8..bcdb6b359 100644 --- a/logprint/logprint.c +++ b/logprint/logprint.c @@ -85,7 +85,7 @@ logstat( mp->m_features |= libxfs_sb_version_to_features(&mp->m_sb); mp->m_blkbb_log = sb->sb_blocklog - BBSHIFT; - xlog_init(mp, log, &x); + xlog_init(mp, log); if (!x.logname && sb->sb_logstart == 0) { fprintf(stderr, _(" external log device not specified\n\n")); diff --git a/repair/phase2.c b/repair/phase2.c index a9dd77be3..48263e161 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -30,7 +30,7 @@ zero_log( xfs_daddr_t tail_blk; struct xlog *log = mp->m_log; - xlog_init(mp, mp->m_log, &x); + xlog_init(mp, mp->m_log); /* * Find the log head and tail and alert the user to the situation if the From patchwork Mon Dec 11 16:37:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487648 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="pldpMi1P" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 008CF98 for ; Mon, 11 Dec 2023 08:38:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=nxrcCbQGpjtzcd0/TdGR8FeUFnPfJhNHIyoQhjRIp3s=; b=pldpMi1PCNA87xwS+W98I5Gfg4 y5VxldM6+4kD7NkTeJK3kkLdNK09LlRUq7kPNsBKp+5sJPeTYi5wFkBaQghm+iSPPiUIuqHaJRtiQ 7rs2yBJcGoTxhbzUzufYft4WwxSgmURrANMktyFUl4ymogZm53iRScQuFRkicIHyv5yIGp0+w4QI1 TAZDdeMKXItuwK3y7TSBDCjpF5lAGN0TgM30i29tEScAUjZCqCU3pn6frV7BOBurOXvFK8FIlOOFo +KQsK6YX2MXaIncB4ahIMA4i8C4p4yRdTQr55G8w9Ok4APou5MZrZjbDjD1t8p8eR5TjgMB7/ml1Q Ucfg7ZIQ==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIL-005t50-0n; Mon, 11 Dec 2023 16:38:13 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 09/23] libxlog: remove the global libxfs_xinit x structure Date: Mon, 11 Dec 2023 17:37:28 +0100 Message-Id: <20231211163742.837427-10-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html There is no need to export a libxfs_xinit with the somewhat unsuitable name x from libxlog. Move it into the tools linking against libxlog that actually need it. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- db/init.c | 1 + include/libxlog.h | 3 --- libxlog/util.c | 1 - logprint/logprint.c | 1 + repair/globals.h | 2 ++ repair/init.c | 2 ++ 6 files changed, 6 insertions(+), 4 deletions(-) diff --git a/db/init.c b/db/init.c index 18d9dfdd9..eceaf576c 100644 --- a/db/init.c +++ b/db/init.c @@ -27,6 +27,7 @@ static struct xfs_mount xmount; struct xfs_mount *mp; static struct xlog xlog; xfs_agnumber_t cur_agno = NULLAGNUMBER; +libxfs_init_t x; static void usage(void) diff --git a/include/libxlog.h b/include/libxlog.h index 57f39e4e8..3948c0b8d 100644 --- a/include/libxlog.h +++ b/include/libxlog.h @@ -68,9 +68,6 @@ extern int print_exit; extern int print_skip_uuid; extern int print_record_header; -/* libxfs parameters */ -extern libxfs_init_t x; - void xlog_init(struct xfs_mount *mp, struct xlog *log); int xlog_is_dirty(struct xfs_mount *mp, struct xlog *log); diff --git a/libxlog/util.c b/libxlog/util.c index d1377c2e2..6e21f1a89 100644 --- a/libxlog/util.c +++ b/libxlog/util.c @@ -10,7 +10,6 @@ int print_exit; int print_skip_uuid; int print_record_header; -libxfs_init_t x; void xlog_init( diff --git a/logprint/logprint.c b/logprint/logprint.c index bcdb6b359..1a096fa79 100644 --- a/logprint/logprint.c +++ b/logprint/logprint.c @@ -25,6 +25,7 @@ int print_overwrite; int print_no_data; int print_no_print; static int print_operation = OP_PRINT; +static struct libxfs_xinit x; static void usage(void) diff --git a/repair/globals.h b/repair/globals.h index b65e4a2d0..f2952d8b4 100644 --- a/repair/globals.h +++ b/repair/globals.h @@ -169,4 +169,6 @@ extern int thread_count; /* If nonzero, simulate failure after this phase. */ extern int fail_after_phase; +extern libxfs_init_t x; + #endif /* _XFS_REPAIR_GLOBAL_H */ diff --git a/repair/init.c b/repair/init.c index 6d019b393..6e3548b32 100644 --- a/repair/init.c +++ b/repair/init.c @@ -18,6 +18,8 @@ #include "libfrog/dahashselftest.h" #include +struct libxfs_xinit x; + static void ts_create(void) { From patchwork Mon Dec 11 16:37:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487649 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="czoNmMXX" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 826288E for ; Mon, 11 Dec 2023 08:38:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=MmAHyruwYLHy9Zb9UBz37Er/sH3hkxQytCwAjEybT7Y=; b=czoNmMXXnjxxkPCs0/8wjEYPJS pbVbbhZE+Sh/u6qYnPxFkufWbcVjUVtDKkIoTP9ceGn6JOaugelSWYTFl0BSA3Lpqcg1TCLMw0luA Qfdvb0cMSrjrMMP+2niu/OLD570CrLNR3kISRpRNGsVNAdycycEdDk/xgCJ8laoDkYSJHTPOQsQfJ vIoaFgbDZtWTi9HZq1QDQud8A5ZQeqzBm0BVfNX9LmU6CkMOccJBy8GKhSQJspLoZQdSxeBl+H2Yd JaObapMR4DeJcxdRKNdOCi/0EXWe750huvaIC7el2s0YlYVc6fYDeNlpUj3HW8ar55bysQ0CZnPtJ fPjBM5hQ==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIN-005t6o-35; Mon, 11 Dec 2023 16:38:16 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 10/23] libxfs: rename struct libxfs_xinit to libxfs_init Date: Mon, 11 Dec 2023 17:37:29 +0100 Message-Id: <20231211163742.837427-11-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Make the struct name more usual, and remove the libxfs_init_t typedef. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- copy/xfs_copy.c | 2 +- db/init.c | 2 +- db/init.h | 2 +- growfs/xfs_growfs.c | 2 +- include/libxfs.h | 10 ++++++---- libxfs/init.c | 6 +++--- libxfs/topology.c | 5 +++-- libxfs/topology.h | 4 ++-- logprint/logprint.c | 2 +- mkfs/xfs_mkfs.c | 18 +++++++++--------- repair/globals.h | 2 +- repair/init.c | 6 +++--- repair/protos.h | 2 +- repair/sb.c | 2 +- 14 files changed, 34 insertions(+), 31 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 86187086d..12ad81eb1 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -582,7 +582,7 @@ main(int argc, char **argv) xfs_alloc_rec_t *rec_ptr; extern char *optarg; extern int optind; - libxfs_init_t xargs; + struct libxfs_init xargs; thread_args *tcarg; struct stat statbuf; int error; diff --git a/db/init.c b/db/init.c index eceaf576c..36e2bb89d 100644 --- a/db/init.c +++ b/db/init.c @@ -27,7 +27,7 @@ static struct xfs_mount xmount; struct xfs_mount *mp; static struct xlog xlog; xfs_agnumber_t cur_agno = NULLAGNUMBER; -libxfs_init_t x; +struct libxfs_init x; static void usage(void) diff --git a/db/init.h b/db/init.h index 05e75c100..aa6d843d8 100644 --- a/db/init.h +++ b/db/init.h @@ -8,5 +8,5 @@ extern int blkbb; extern int exitcode; extern int expert_mode; extern xfs_mount_t *mp; -extern libxfs_init_t x; +extern struct libxfs_init x; extern xfs_agnumber_t cur_agno; diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c index 683961f6b..802e01154 100644 --- a/growfs/xfs_growfs.c +++ b/growfs/xfs_growfs.c @@ -61,7 +61,7 @@ main(int argc, char **argv) char *logdev; /* log device name */ char *rtdev; /* RT device name */ fs_path_t *fs; /* mount point information */ - libxfs_init_t xi; /* libxfs structure */ + struct libxfs_init xi; /* libxfs structure */ char rpath[PATH_MAX]; int ret; diff --git a/include/libxfs.h b/include/libxfs.h index 270efb2c1..6da8fd1c8 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -92,7 +92,7 @@ struct iomap; /* * Argument structure for libxfs_init(). */ -typedef struct libxfs_xinit { +struct libxfs_init { /* input parameters */ char *dname; /* pathname of data "subvolume" */ char *logname; /* pathname of log "subvolume" */ @@ -123,7 +123,7 @@ typedef struct libxfs_xinit { int logfd; /* log subvolume file descriptor */ int rtfd; /* realtime subvolume file descriptor */ int bcache_flags; /* cache init flags */ -} libxfs_init_t; +}; #define LIBXFS_ISREADONLY 0x0002 /* disallow all mounted filesystems */ #define LIBXFS_ISINACTIVE 0x0004 /* allow mounted only if mounted ro */ @@ -133,8 +133,10 @@ typedef struct libxfs_xinit { extern char *progname; extern xfs_lsn_t libxfs_max_lsn; -extern int libxfs_init (libxfs_init_t *); -void libxfs_destroy(struct libxfs_xinit *li); + +int libxfs_init(struct libxfs_init *); +void libxfs_destroy(struct libxfs_init *li); + extern int libxfs_device_to_fd (dev_t); extern dev_t libxfs_device_open (char *, int, int, int); extern void libxfs_device_close (dev_t); diff --git a/libxfs/init.c b/libxfs/init.c index 6482ba52b..cafd40b11 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -273,7 +273,7 @@ destroy_caches(void) static void libxfs_close_devices( - struct libxfs_xinit *li) + struct libxfs_init *li) { if (li->ddev) libxfs_device_close(li->ddev); @@ -291,7 +291,7 @@ libxfs_close_devices( * Caller gets a 0 on failure (and we print a message), 1 on success. */ int -libxfs_init(libxfs_init_t *a) +libxfs_init(struct libxfs_init *a) { char *dname; char *logname; @@ -1034,7 +1034,7 @@ libxfs_umount( */ void libxfs_destroy( - struct libxfs_xinit *li) + struct libxfs_init *li) { int leaked; diff --git a/libxfs/topology.c b/libxfs/topology.c index 25f47beda..d6791c0f6 100644 --- a/libxfs/topology.c +++ b/libxfs/topology.c @@ -286,8 +286,9 @@ static void blkid_get_topology( #endif /* ENABLE_BLKID */ -void get_topology( - libxfs_init_t *xi, +void +get_topology( + struct libxfs_init *xi, struct fs_topology *ft, int force_overwrite) { diff --git a/libxfs/topology.h b/libxfs/topology.h index 1a0fe24c0..1af5b0549 100644 --- a/libxfs/topology.h +++ b/libxfs/topology.h @@ -18,9 +18,9 @@ typedef struct fs_topology { int psectorsize; /* physical sector size */ } fs_topology_t; -extern void +void get_topology( - libxfs_init_t *xi, + struct libxfs_init *xi, struct fs_topology *ft, int force_overwrite); diff --git a/logprint/logprint.c b/logprint/logprint.c index 1a096fa79..c6e5051e8 100644 --- a/logprint/logprint.c +++ b/logprint/logprint.c @@ -25,7 +25,7 @@ int print_overwrite; int print_no_data; int print_no_print; static int print_operation = OP_PRINT; -static struct libxfs_xinit x; +static struct libxfs_init x; static void usage(void) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 19849ed21..346516e13 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -907,7 +907,7 @@ struct cli_params { struct fsxattr fsx; /* libxfs device setup */ - struct libxfs_xinit *xi; + struct libxfs_init *xi; }; /* @@ -1246,7 +1246,7 @@ validate_ag_geometry( static void zero_old_xfs_structures( - libxfs_init_t *xi, + struct libxfs_init *xi, xfs_sb_t *new_sb) { void *buf; @@ -2834,7 +2834,7 @@ _("log stripe unit (%d bytes) is too large (maximum is 256KiB)\n" static void open_devices( struct mkfs_params *cfg, - struct libxfs_xinit *xi) + struct libxfs_init *xi) { uint64_t sector_mask; @@ -2867,7 +2867,7 @@ open_devices( static void discard_devices( - struct libxfs_xinit *xi, + struct libxfs_init *xi, int quiet) { /* @@ -2887,7 +2887,7 @@ validate_datadev( struct mkfs_params *cfg, struct cli_params *cli) { - struct libxfs_xinit *xi = cli->xi; + struct libxfs_init *xi = cli->xi; if (!xi->dsize) { /* @@ -2934,7 +2934,7 @@ validate_logdev( struct mkfs_params *cfg, struct cli_params *cli) { - struct libxfs_xinit *xi = cli->xi; + struct libxfs_init *xi = cli->xi; cfg->loginternal = cli->loginternal; @@ -2998,7 +2998,7 @@ validate_rtdev( struct mkfs_params *cfg, struct cli_params *cli) { - struct libxfs_xinit *xi = cli->xi; + struct libxfs_init *xi = cli->xi; if (!xi->rtdev) { if (cli->rtsize) { @@ -3750,7 +3750,7 @@ alloc_write_buf( static void prepare_devices( struct mkfs_params *cfg, - struct libxfs_xinit *xi, + struct libxfs_init *xi, struct xfs_mount *mp, struct xfs_sb *sbp, bool clear_stale) @@ -4055,7 +4055,7 @@ main( char *protostring = NULL; int worst_freelist = 0; - struct libxfs_xinit xi = { + struct libxfs_init xi = { .isdirect = LIBXFS_DIRECT, .isreadonly = LIBXFS_EXCLUSIVELY, }; diff --git a/repair/globals.h b/repair/globals.h index f2952d8b4..89f1b0e07 100644 --- a/repair/globals.h +++ b/repair/globals.h @@ -169,6 +169,6 @@ extern int thread_count; /* If nonzero, simulate failure after this phase. */ extern int fail_after_phase; -extern libxfs_init_t x; +extern struct libxfs_init x; #endif /* _XFS_REPAIR_GLOBAL_H */ diff --git a/repair/init.c b/repair/init.c index 6e3548b32..1c562fb34 100644 --- a/repair/init.c +++ b/repair/init.c @@ -18,7 +18,7 @@ #include "libfrog/dahashselftest.h" #include -struct libxfs_xinit x; +struct libxfs_init x; static void ts_create(void) @@ -52,9 +52,9 @@ increase_rlimit(void) } void -xfs_init(libxfs_init_t *args) +xfs_init(struct libxfs_init *args) { - memset(args, 0, sizeof(libxfs_init_t)); + memset(args, 0, sizeof(*args)); args->dname = fs_name; args->disfile = isa_file; diff --git a/repair/protos.h b/repair/protos.h index 83e471ff2..e2f39f1d6 100644 --- a/repair/protos.h +++ b/repair/protos.h @@ -4,7 +4,7 @@ * All Rights Reserved. */ -void xfs_init(libxfs_init_t *args); +void xfs_init(struct libxfs_init *args); int verify_sb(char *sb_buf, xfs_sb_t *sb, diff --git a/repair/sb.c b/repair/sb.c index 7391cf043..b823ba3a9 100644 --- a/repair/sb.c +++ b/repair/sb.c @@ -176,7 +176,7 @@ static int guess_default_geometry( uint64_t *agsize, uint64_t *agcount, - libxfs_init_t *x) + struct libxfs_init *x) { struct fs_topology ft; int blocklog; From patchwork Mon Dec 11 16:37:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487650 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="fkA8u7ER" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54F2995 for ; Mon, 11 Dec 2023 08:38:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=7bxRRfD4JcVm+J5ZoL4OQ4+Xls2DJosTu0mHhuXo0eQ=; b=fkA8u7ERL77EMTJ4c96rFlJgLT ZB3t0d9C4KMxtLfKwgJ5F9KaeDAemAM6JtHldGkck3wwl7yhZM8Z4OusArBuQgV1TSCF2LpNeCYc0 Bs7FRY3eZlXeiXx9oTin1EbBI+qJm1etgh6E10JJvVtRRgQIQjVfd+JHsFC7LO5ceu2Vhdrfy2km5 pG+A4M1xEDZrZIjgXwc5bsiQNrvjIWKBY/OK/ZDtUfqckowm2qF40AP6YlCYhpQofe0C0z++no/UV U5wYn4lGtj6sVaPtvoqZnP+qiEX9mwAL92XUmz4zo6JEH0FSatNH64eAZksYyQeXLH5P7O9U6HyTH yHgO48/w==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIQ-005t88-1s; Mon, 11 Dec 2023 16:38:19 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 11/23] libxfs: pass a struct libxfs_init to libxfs_mount Date: Mon, 11 Dec 2023 17:37:30 +0100 Message-Id: <20231211163742.837427-12-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Pass a libxfs_init structure to libxfs_mount instead of three separate dev_t values. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- copy/xfs_copy.c | 2 +- db/init.c | 3 +-- include/xfs_mount.h | 3 ++- libxfs/init.c | 8 +++----- mkfs/xfs_mkfs.c | 5 +++-- repair/xfs_repair.c | 2 +- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 12ad81eb1..fbccd32a1 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -755,7 +755,7 @@ main(int argc, char **argv) } libxfs_buf_relse(sbp); - mp = libxfs_mount(&mbuf, sb, xargs.ddev, xargs.logdev, xargs.rtdev, 0); + mp = libxfs_mount(&mbuf, sb, &xargs, 0); if (mp == NULL) { do_log(_("%s: %s filesystem failed to initialize\n" "%s: Aborting.\n"), progname, source_name, progname); diff --git a/db/init.c b/db/init.c index 36e2bb89d..74c63e218 100644 --- a/db/init.c +++ b/db/init.c @@ -130,8 +130,7 @@ init( } agcount = sbp->sb_agcount; - mp = libxfs_mount(&xmount, sbp, x.ddev, x.logdev, x.rtdev, - LIBXFS_MOUNT_DEBUGGER); + mp = libxfs_mount(&xmount, sbp, &x, LIBXFS_MOUNT_DEBUGGER); if (!mp) { fprintf(stderr, _("%s: device %s unusable (not an XFS filesystem?)\n"), diff --git a/include/xfs_mount.h b/include/xfs_mount.h index 99d1d9ab1..9adc1f898 100644 --- a/include/xfs_mount.h +++ b/include/xfs_mount.h @@ -10,6 +10,7 @@ struct xfs_inode; struct xfs_buftarg; struct xfs_da_geometry; +struct libxfs_init; typedef void (*buf_writeback_fn)(struct xfs_buf *bp); @@ -272,7 +273,7 @@ __XFS_UNSUPP_OPSTATE(shutdown) void libxfs_compute_all_maxlevels(struct xfs_mount *mp); struct xfs_mount *libxfs_mount(struct xfs_mount *mp, struct xfs_sb *sb, - dev_t dev, dev_t logdev, dev_t rtdev, unsigned int flags); + struct libxfs_init *xi, unsigned int flags); int libxfs_flush_mount(struct xfs_mount *mp); int libxfs_umount(struct xfs_mount *mp); extern void libxfs_rtmount_destroy (xfs_mount_t *); diff --git a/libxfs/init.c b/libxfs/init.c index cafd40b11..1b7397819 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -744,9 +744,7 @@ struct xfs_mount * libxfs_mount( struct xfs_mount *mp, struct xfs_sb *sb, - dev_t dev, - dev_t logdev, - dev_t rtdev, + struct libxfs_init *xi, unsigned int flags) { struct xfs_buf *bp; @@ -759,7 +757,7 @@ libxfs_mount( xfs_set_debugger(mp); if (flags & LIBXFS_MOUNT_REPORT_CORRUPTION) xfs_set_reporting_corruption(mp); - libxfs_buftarg_init(mp, dev, logdev, rtdev); + libxfs_buftarg_init(mp, xi->ddev, xi->logdev, xi->rtdev); mp->m_finobt_nores = true; xfs_set_inode32(mp); @@ -825,7 +823,7 @@ libxfs_mount( /* Initialize the precomputed transaction reservations values */ xfs_trans_init(mp); - if (dev == 0) /* maxtrres, we have no device so leave now */ + if (xi->ddev == 0) /* maxtrres, we have no device so leave now */ return mp; /* device size checks must pass unless we're a debugger. */ diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 346516e13..5aadf0f94 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -3483,11 +3483,12 @@ calculate_log_size( int min_logblocks; /* absolute minimum */ int max_logblocks; /* absolute max for this AG */ struct xfs_mount mount; + struct libxfs_init dummy_init = { }; /* we need a temporary mount to calculate the minimum log size. */ memset(&mount, 0, sizeof(mount)); mount.m_sb = *sbp; - libxfs_mount(&mount, &mp->m_sb, 0, 0, 0, 0); + libxfs_mount(&mount, &mp->m_sb, &dummy_init, 0); min_logblocks = libxfs_log_calc_minimum_size(&mount); libxfs_umount(&mount); @@ -4320,7 +4321,7 @@ main( * mount. */ prepare_devices(&cfg, &xi, mp, sbp, force_overwrite); - mp = libxfs_mount(mp, sbp, xi.ddev, xi.logdev, xi.rtdev, 0); + mp = libxfs_mount(mp, sbp, &xi, 0); if (mp == NULL) { fprintf(stderr, _("%s: filesystem failed to initialize\n"), progname); diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index ff29bea97..8a6cf31b4 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -1034,7 +1034,7 @@ main(int argc, char **argv) * initialized in phase 2. */ memset(&xfs_m, 0, sizeof(xfs_mount_t)); - mp = libxfs_mount(&xfs_m, &psb, x.ddev, x.logdev, x.rtdev, 0); + mp = libxfs_mount(&xfs_m, &psb, &x, 0); if (!mp) { fprintf(stderr, From patchwork Mon Dec 11 16:37:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487651 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="lc2EDd8N" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0596798 for ; Mon, 11 Dec 2023 08:38:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=K/gs6ykSmZ6CWDRLECgKQB19vh0D42zwLgwGT2Xum64=; b=lc2EDd8Nev0hFIdkGKuJKoPS9m EsBxwc8bAXRof4rglr1fIOyEEjXGxC/ZZDLvaPwelEOo0CKCZ4rOtfUi7Uj33vfA7bu8V4t8rBXLV pg+Vvb03zJpaJEECSPRk/rRtwSVfArBOe7cCVGMLVbMirtPF0IeSjiVjW4EVWJ4rzvrDEwbTjuJ57 q7UzzKBSj2djON2F8Gq37NNHN47sCDQyBG7pK6haRQYJmIT5hF/ZUdllydJOl8L0actfmmhtoDZCm occY4AZamiuLZO5In5vJhy+AohQSD7OK+qa6N1SAn0YLu4FO2nSQnkSZpacyhsG1zIiYQYncpqvEp 4jPkSBDw==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIT-005t9k-19; Mon, 11 Dec 2023 16:38:21 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 12/23] libxfs: pass a struct libxfs_init to libxfs_alloc_buftarg Date: Mon, 11 Dec 2023 17:37:31 +0100 Message-Id: <20231211163742.837427-13-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Pass a libxfs_init structure to libxfs_alloc_buftarg instead of three separate dev_t values. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- copy/xfs_copy.c | 2 +- db/init.c | 2 +- db/sb.c | 2 +- libxfs/init.c | 26 +++++++++++++------------- libxfs/libxfs_io.h | 4 ++-- logprint/logprint.c | 2 +- mkfs/xfs_mkfs.c | 2 +- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index fbccd32a1..2f98ae8fb 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -730,7 +730,7 @@ main(int argc, char **argv) memset(&mbuf, 0, sizeof(xfs_mount_t)); /* We don't yet know the sector size, so read maximal size */ - libxfs_buftarg_init(&mbuf, xargs.ddev, xargs.logdev, xargs.rtdev); + libxfs_buftarg_init(&mbuf, &xargs); error = -libxfs_buf_read_uncached(mbuf.m_ddev_targp, XFS_SB_DADDR, 1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &sbp, NULL); if (error) { diff --git a/db/init.c b/db/init.c index 74c63e218..8bd8e83f6 100644 --- a/db/init.c +++ b/db/init.c @@ -106,7 +106,7 @@ init( * tool and so need to be able to mount busted filesystems. */ memset(&xmount, 0, sizeof(struct xfs_mount)); - libxfs_buftarg_init(&xmount, x.ddev, x.logdev, x.rtdev); + libxfs_buftarg_init(&xmount, &x); error = -libxfs_buf_read_uncached(xmount.m_ddev_targp, XFS_SB_DADDR, 1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &bp, NULL); if (error) { diff --git a/db/sb.c b/db/sb.c index 2f046c6aa..30709e84e 100644 --- a/db/sb.c +++ b/db/sb.c @@ -233,7 +233,7 @@ sb_logcheck(void) } } - libxfs_buftarg_init(mp, x.ddev, x.logdev, x.rtdev); + libxfs_buftarg_init(mp, &x); dirty = xlog_is_dirty(mp, mp->m_log); if (dirty == -1) { diff --git a/libxfs/init.c b/libxfs/init.c index 1b7397819..14962b9fa 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -607,9 +607,7 @@ static char *wf_opts[] = { void libxfs_buftarg_init( struct xfs_mount *mp, - dev_t dev, - dev_t logdev, - dev_t rtdev) + struct libxfs_init *xi) { char *p = getenv("LIBXFS_DEBUG_WRITE_CRASH"); unsigned long dfail = 0, lfail = 0, rfail = 0; @@ -653,29 +651,30 @@ libxfs_buftarg_init( if (mp->m_ddev_targp) { /* should already have all buftargs initialised */ - if (mp->m_ddev_targp->bt_bdev != dev || + if (mp->m_ddev_targp->bt_bdev != xi->ddev || mp->m_ddev_targp->bt_mount != mp) { fprintf(stderr, _("%s: bad buftarg reinit, ddev\n"), progname); exit(1); } - if (!logdev || logdev == dev) { + if (!xi->logdev || xi->logdev == xi->ddev) { 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 != logdev || + } else if (mp->m_logdev_targp->bt_bdev != xi->logdev || mp->m_logdev_targp->bt_mount != mp) { fprintf(stderr, _("%s: bad buftarg reinit, logdev\n"), progname); exit(1); } - if (rtdev && (mp->m_rtdev_targp->bt_bdev != rtdev || - mp->m_rtdev_targp->bt_mount != mp)) { + if (xi->rtdev && + (mp->m_rtdev_targp->bt_bdev != xi->rtdev || + mp->m_rtdev_targp->bt_mount != mp)) { fprintf(stderr, _("%s: bad buftarg reinit, rtdev\n"), progname); @@ -684,12 +683,13 @@ libxfs_buftarg_init( return; } - mp->m_ddev_targp = libxfs_buftarg_alloc(mp, dev, dfail); - if (!logdev || logdev == dev) + mp->m_ddev_targp = libxfs_buftarg_alloc(mp, xi->ddev, dfail); + if (!xi->logdev || xi->logdev == xi->ddev) mp->m_logdev_targp = mp->m_ddev_targp; else - mp->m_logdev_targp = libxfs_buftarg_alloc(mp, logdev, lfail); - mp->m_rtdev_targp = libxfs_buftarg_alloc(mp, rtdev, rfail); + mp->m_logdev_targp = libxfs_buftarg_alloc(mp, xi->logdev, + lfail); + mp->m_rtdev_targp = libxfs_buftarg_alloc(mp, xi->rtdev, rfail); } /* Compute maximum possible height for per-AG btree types for this fs. */ @@ -757,7 +757,7 @@ libxfs_mount( xfs_set_debugger(mp); if (flags & LIBXFS_MOUNT_REPORT_CORRUPTION) xfs_set_reporting_corruption(mp); - libxfs_buftarg_init(mp, xi->ddev, xi->logdev, xi->rtdev); + libxfs_buftarg_init(mp, xi); mp->m_finobt_nores = true; xfs_set_inode32(mp); diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h index fae864272..bf4d4ecd9 100644 --- a/libxfs/libxfs_io.h +++ b/libxfs/libxfs_io.h @@ -14,6 +14,7 @@ struct xfs_buf; struct xfs_mount; struct xfs_perag; +struct libxfs_init; /* * IO verifier callbacks need the xfs_mount pointer, so we have to behave @@ -50,8 +51,7 @@ xfs_buftarg_trip_write( pthread_mutex_unlock(&btp->lock); } -extern void libxfs_buftarg_init(struct xfs_mount *mp, dev_t ddev, - dev_t logdev, dev_t rtdev); +void libxfs_buftarg_init(struct xfs_mount *mp, struct libxfs_init *xi); int libxfs_blkdev_issue_flush(struct xfs_buftarg *btp); #define LIBXFS_BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT) diff --git a/logprint/logprint.c b/logprint/logprint.c index c6e5051e8..c2976333d 100644 --- a/logprint/logprint.c +++ b/logprint/logprint.c @@ -213,7 +213,7 @@ main(int argc, char **argv) if (!libxfs_init(&x)) exit(1); - libxfs_buftarg_init(&mount, x.ddev, x.logdev, x.rtdev); + libxfs_buftarg_init(&mount, &x); logstat(&mount, &log); logfd = (x.logfd < 0) ? x.dfd : x.logfd; diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 5aadf0f94..50b0a7e19 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -4313,7 +4313,7 @@ main( /* * we need the libxfs buffer cache from here on in. */ - libxfs_buftarg_init(mp, xi.ddev, xi.logdev, xi.rtdev); + libxfs_buftarg_init(mp, &xi); /* * Before we mount the filesystem we need to make sure the devices have From patchwork Mon Dec 11 16:37:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487652 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="dBMrGCBS" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 47EF198 for ; Mon, 11 Dec 2023 08:38:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=e0LJKvAjx68Z7E/xoPGzFQo3lH4YDO2zpAv/dspLq48=; b=dBMrGCBSM/u2xhSJ5VmcMVNfSr 7z3xfTwgtwBePuUu701JsLHcfl31G5NCUgqILfF/q+glmP70dhzwXk1DNw6JoQx1RDrE8m32dtJlR 7tFNcCrGT+Vhflb6JhLeQVXNcUojQSX7Fu2rWXDcFAU4mv2zaPWo1dMMAwLLNikj5fBkkN+lgvHbp RLK/423opCSeeJTFtz24ZxlAR/fmQTSif4NV70xeCpAQKyAea9xYBSS0v6JTj8W4Up4yz8J0IYLA+ /tBRXmtZDxWd40BFkw6wiAvQycShBUmHxddoTvR2vXK+0TeR0iPGIUGpGNztXMT6xPDQ+zpiJfgNp ExtX8KEA==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIW-005tBZ-08; Mon, 11 Dec 2023 16:38:24 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 13/23] libxfs: merge the file vs device cases in libxfs_init Date: Mon, 11 Dec 2023 17:37:32 +0100 Message-Id: <20231211163742.837427-14-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html The only special handling for an XFS device on a regular file is that we skip the checks in check_open. Simplify perform those conditionally instead of duplicating the entire sequence. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- libxfs/init.c | 74 ++++++++++++++++----------------------------------- 1 file changed, 23 insertions(+), 51 deletions(-) diff --git a/libxfs/init.c b/libxfs/init.c index 14962b9fa..86b810bfe 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -313,59 +313,31 @@ libxfs_init(struct libxfs_init *a) radix_tree_init(); if (dname) { - if (a->disfile) { - a->ddev= libxfs_device_open(dname, a->dcreat, flags, - a->setblksize); - a->dfd = libxfs_device_to_fd(a->ddev); - platform_findsizes(dname, a->dfd, &a->dsize, - &a->dbsize); - } else { - if (!check_open(dname, flags)) - goto done; - a->ddev = libxfs_device_open(dname, - a->dcreat, flags, a->setblksize); - a->dfd = libxfs_device_to_fd(a->ddev); - platform_findsizes(dname, a->dfd, - &a->dsize, &a->dbsize); - } - } else - a->dsize = 0; + if (!a->disfile && !check_open(dname, flags)) + goto done; + a->ddev = libxfs_device_open(dname, a->dcreat, flags, + a->setblksize); + a->dfd = libxfs_device_to_fd(a->ddev); + platform_findsizes(dname, a->dfd, &a->dsize, &a->dbsize); + } if (logname) { - if (a->lisfile) { - a->logdev = libxfs_device_open(logname, - a->lcreat, flags, a->setblksize); - a->logfd = libxfs_device_to_fd(a->logdev); - platform_findsizes(dname, a->logfd, &a->logBBsize, - &a->lbsize); - } else { - if (!check_open(logname, flags)) - goto done; - a->logdev = libxfs_device_open(logname, - a->lcreat, flags, a->setblksize); - a->logfd = libxfs_device_to_fd(a->logdev); - platform_findsizes(logname, a->logfd, - &a->logBBsize, &a->lbsize); - } - } else - a->logBBsize = 0; + if (!a->lisfile && !check_open(logname, flags)) + goto done; + a->logdev = libxfs_device_open(logname, a->lcreat, flags, + a->setblksize); + a->logfd = libxfs_device_to_fd(a->logdev); + platform_findsizes(logname, a->logfd, &a->logBBsize, + &a->lbsize); + } if (rtname) { - if (a->risfile) { - a->rtdev = libxfs_device_open(rtname, - a->rcreat, flags, a->setblksize); - a->rtfd = libxfs_device_to_fd(a->rtdev); - platform_findsizes(dname, a->rtfd, &a->rtsize, - &a->rtbsize); - } else { - if (!check_open(rtname, flags)) - goto done; - a->rtdev = libxfs_device_open(rtname, - a->rcreat, flags, a->setblksize); - a->rtfd = libxfs_device_to_fd(a->rtdev); - platform_findsizes(rtname, a->rtfd, - &a->rtsize, &a->rtbsize); - } - } else - a->rtsize = 0; + if (a->risfile && !check_open(rtname, flags)) + goto done; + a->rtdev = libxfs_device_open(rtname, a->rcreat, flags, + a->setblksize); + a->rtfd = libxfs_device_to_fd(a->rtdev); + platform_findsizes(dname, a->rtfd, &a->rtsize, &a->rtbsize); + } + if (a->dsize < 0) { fprintf(stderr, _("%s: can't get size for data subvolume\n"), progname); From patchwork Mon Dec 11 16:37:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487653 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QpPLt1bw" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A0CA8E for ; Mon, 11 Dec 2023 08:38:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=fDIvf/zhljpeH51Rpr21V2Rs6SiEf/AWtdIbMGOklv8=; b=QpPLt1bw8pPcuRCRUGftubc+sO jqixltL40wIH25VL8iBit19nNyRZiqNQMWIx/CbVJ++dDxiSyfbtEtI/izfDVK0rBznAPUaevROKM fAZ1k1nsZ+1M7+N3tW0ycP0OElgzr0ZFc/PRn5xdOj5TTNS75jRQnzpB6kwosp7caw7g/ygNxKCYD pKAjg91UV1VPCTdOK57HFWraVCioRIZdJH19vNi/NFyu36l+FaqhsioXy2v7GiwREr0hHtGXF0CH3 KIDUKq1gywAQuO235eHY0fT+9UHlC2GwfkOUIkbx7o3Z9cb9Th45KCXN6sdWLrLE5HgxbvkkPgDCT 5Bmswbvw==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIZ-005tE3-0h; Mon, 11 Dec 2023 16:38:27 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 14/23] libxfs: making passing flags to libxfs_init less confusing Date: Mon, 11 Dec 2023 17:37:33 +0100 Message-Id: <20231211163742.837427-15-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html The libxfs_xinit stucture has four different ways to pass flags to libxfs_init: - the isreadonly argument despite it's name contains various LIBXFS_ flags that go beyond just the readonly flag - the isdirect flag contains a single LIBXFS_ flag from the same name - the usebuflock is an integer used as bool - the bcache_flags member is used to pass flags directly to cache_init() for the buffer cache While there is good arguments for keeping the last one separate, all the others are rather confusing. Consolidate them into a single flags member using flags in the LIBXFS_* namespace. Reviewed-by: Carlos Maiolino Signed-off-by: Christoph Hellwig --- copy/xfs_copy.c | 4 +--- db/crc.c | 2 +- db/fuzz.c | 2 +- db/init.c | 6 +++--- db/sb.c | 6 +++--- db/write.c | 2 +- growfs/xfs_growfs.c | 2 +- include/libxfs.h | 26 ++++++++++++++++++-------- libxfs/init.c | 17 +++++++---------- logprint/logprint.c | 2 +- mkfs/xfs_mkfs.c | 5 ++--- repair/init.c | 15 ++++++++------- 12 files changed, 47 insertions(+), 42 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 2f98ae8fb..bd7c6d334 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -715,9 +715,7 @@ main(int argc, char **argv) /* prepare the libxfs_init structure */ memset(&xargs, 0, sizeof(xargs)); - xargs.isdirect = LIBXFS_DIRECT; - xargs.isreadonly = LIBXFS_ISREADONLY; - + xargs.flags = LIBXFS_ISREADONLY | LIBXFS_DIRECT; xargs.dname = source_name; xargs.disfile = source_is_file; diff --git a/db/crc.c b/db/crc.c index 1c73f9803..9043b3f48 100644 --- a/db/crc.c +++ b/db/crc.c @@ -98,7 +98,7 @@ crc_f( } if ((invalidate || recalculate) && - ((x.isreadonly & LIBXFS_ISREADONLY) || !expert_mode)) { + ((x.flags & LIBXFS_ISREADONLY) || !expert_mode)) { dbprintf(_("%s not in expert mode, writing disabled\n"), progname); return 0; diff --git a/db/fuzz.c b/db/fuzz.c index ba64bad7a..fafbca3e3 100644 --- a/db/fuzz.c +++ b/db/fuzz.c @@ -77,7 +77,7 @@ fuzz_f( struct xfs_buf_ops local_ops; const struct xfs_buf_ops *stashed_ops = NULL; - if (x.isreadonly & LIBXFS_ISREADONLY) { + if (x.flags & LIBXFS_ISREADONLY) { dbprintf(_("%s started in read only mode, fuzzing disabled\n"), progname); return 0; diff --git a/db/init.c b/db/init.c index 8bd8e83f6..f240d0f66 100644 --- a/db/init.c +++ b/db/init.c @@ -67,13 +67,13 @@ init( force = 1; break; case 'i': - x.isreadonly = (LIBXFS_ISREADONLY|LIBXFS_ISINACTIVE); + x.flags = LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE; break; case 'p': progname = optarg; break; case 'r': - x.isreadonly = LIBXFS_ISREADONLY; + x.flags = LIBXFS_ISREADONLY; break; case 'l': x.logname = optarg; @@ -92,7 +92,7 @@ init( usage(); x.dname = argv[optind]; - x.isdirect = LIBXFS_DIRECT; + x.flags |= LIBXFS_DIRECT; x.bcache_flags = CACHE_MISCOMPARE_PURGE; if (!libxfs_init(&x)) { diff --git a/db/sb.c b/db/sb.c index 30709e84e..b2aa4a626 100644 --- a/db/sb.c +++ b/db/sb.c @@ -374,7 +374,7 @@ uuid_f( if (argc == 2) { /* WRITE UUID */ - if ((x.isreadonly & LIBXFS_ISREADONLY) || !expert_mode) { + if ((x.flags & LIBXFS_ISREADONLY) || !expert_mode) { dbprintf(_("%s: not in expert mode, writing disabled\n"), progname); return 0; @@ -542,7 +542,7 @@ label_f( if (argc == 2) { /* WRITE LABEL */ - if ((x.isreadonly & LIBXFS_ISREADONLY) || !expert_mode) { + if ((x.flags & LIBXFS_ISREADONLY) || !expert_mode) { dbprintf(_("%s: not in expert mode, writing disabled\n"), progname); return 0; @@ -727,7 +727,7 @@ version_f( if (argc == 2) { /* WRITE VERSION */ - if ((x.isreadonly & LIBXFS_ISREADONLY) || !expert_mode) { + if ((x.flags & LIBXFS_ISREADONLY) || !expert_mode) { dbprintf(_("%s: not in expert mode, writing disabled\n"), progname); return 0; diff --git a/db/write.c b/db/write.c index 6c67e839a..96dea7051 100644 --- a/db/write.c +++ b/db/write.c @@ -88,7 +88,7 @@ write_f( struct xfs_buf_ops local_ops; const struct xfs_buf_ops *stashed_ops = NULL; - if (x.isreadonly & LIBXFS_ISREADONLY) { + if (x.flags & LIBXFS_ISREADONLY) { dbprintf(_("%s started in read only mode, writing disabled\n"), progname); return 0; diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c index 802e01154..05aea3496 100644 --- a/growfs/xfs_growfs.c +++ b/growfs/xfs_growfs.c @@ -186,7 +186,7 @@ main(int argc, char **argv) xi.dname = datadev; xi.logname = logdev; xi.rtname = rtdev; - xi.isreadonly = LIBXFS_ISREADONLY; + xi.flags = LIBXFS_ISREADONLY; if (!libxfs_init(&xi)) usage(); diff --git a/include/libxfs.h b/include/libxfs.h index 6da8fd1c8..9ee3dd979 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -97,8 +97,7 @@ struct libxfs_init { char *dname; /* pathname of data "subvolume" */ char *logname; /* pathname of log "subvolume" */ char *rtname; /* pathname of realtime "subvolume" */ - int isreadonly; /* filesystem is only read in applic */ - int isdirect; /* we can attempt to use direct I/O */ + unsigned flags; /* LIBXFS_* flags below */ int disfile; /* data "subvolume" is a regular file */ int dcreat; /* try to create data subvolume */ int lisfile; /* log "subvolume" is a regular file */ @@ -106,7 +105,6 @@ struct libxfs_init { int risfile; /* realtime "subvolume" is a reg file */ int rcreat; /* try to create realtime subvolume */ int setblksize; /* attempt to set device blksize */ - int usebuflock; /* lock xfs_buf's - for MT usage */ /* output results */ dev_t ddev; /* device for data subvolume */ dev_t logdev; /* device for log subvolume */ @@ -125,11 +123,23 @@ struct libxfs_init { int bcache_flags; /* cache init flags */ }; -#define LIBXFS_ISREADONLY 0x0002 /* disallow all mounted filesystems */ -#define LIBXFS_ISINACTIVE 0x0004 /* allow mounted only if mounted ro */ -#define LIBXFS_DANGEROUSLY 0x0008 /* repairing a device mounted ro */ -#define LIBXFS_EXCLUSIVELY 0x0010 /* disallow other accesses (O_EXCL) */ -#define LIBXFS_DIRECT 0x0020 /* can use direct I/O, not buffered */ +/* disallow all mounted filesystems: */ +#define LIBXFS_ISREADONLY (1U << 0) + +/* allow mounted only if mounted ro: */ +#define LIBXFS_ISINACTIVE (1U << 1) + +/* repairing a device mounted ro: */ +#define LIBXFS_DANGEROUSLY (1U << 2) + +/* disallow other accesses (O_EXCL): */ +#define LIBXFS_EXCLUSIVELY (1U << 3) + +/* can use direct I/O, not buffered: */ +#define LIBXFS_DIRECT (1U << 4) + +/* lock xfs_buf's - for MT usage */ +#define LIBXFS_USEBUFLOCK (1U << 5) extern char *progname; extern xfs_lsn_t libxfs_max_lsn; diff --git a/libxfs/init.c b/libxfs/init.c index 86b810bfe..de1e588f1 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -296,7 +296,6 @@ libxfs_init(struct libxfs_init *a) char *dname; char *logname; char *rtname; - int flags; dname = a->dname; logname = a->logname; @@ -306,33 +305,31 @@ libxfs_init(struct libxfs_init *a) a->dsize = a->lbsize = a->rtbsize = 0; a->dbsize = a->logBBsize = a->rtsize = 0; - flags = (a->isreadonly | a->isdirect); - rcu_init(); rcu_register_thread(); radix_tree_init(); if (dname) { - if (!a->disfile && !check_open(dname, flags)) + if (!a->disfile && !check_open(dname, a->flags)) goto done; - a->ddev = libxfs_device_open(dname, a->dcreat, flags, + a->ddev = libxfs_device_open(dname, a->dcreat, a->flags, a->setblksize); a->dfd = libxfs_device_to_fd(a->ddev); platform_findsizes(dname, a->dfd, &a->dsize, &a->dbsize); } if (logname) { - if (!a->lisfile && !check_open(logname, flags)) + if (!a->lisfile && !check_open(logname, a->flags)) goto done; - a->logdev = libxfs_device_open(logname, a->lcreat, flags, + a->logdev = libxfs_device_open(logname, a->lcreat, a->flags, a->setblksize); a->logfd = libxfs_device_to_fd(a->logdev); platform_findsizes(logname, a->logfd, &a->logBBsize, &a->lbsize); } if (rtname) { - if (a->risfile && !check_open(rtname, flags)) + if (a->risfile && !check_open(rtname, a->flags)) goto done; - a->rtdev = libxfs_device_open(rtname, a->rcreat, flags, + a->rtdev = libxfs_device_open(rtname, a->rcreat, a->flags, a->setblksize); a->rtfd = libxfs_device_to_fd(a->rtdev); platform_findsizes(dname, a->rtfd, &a->rtsize, &a->rtbsize); @@ -357,7 +354,7 @@ libxfs_init(struct libxfs_init *a) libxfs_bhash_size = LIBXFS_BHASHSIZE(sbp); libxfs_bcache = cache_init(a->bcache_flags, libxfs_bhash_size, &libxfs_bcache_operations); - use_xfs_buf_lock = a->usebuflock; + use_xfs_buf_lock = a->flags & LIBXFS_USEBUFLOCK; xfs_dir_startup(); init_caches(); return 1; diff --git a/logprint/logprint.c b/logprint/logprint.c index c2976333d..5349e7838 100644 --- a/logprint/logprint.c +++ b/logprint/logprint.c @@ -208,7 +208,7 @@ main(int argc, char **argv) if (x.dname == NULL) usage(); - x.isreadonly = LIBXFS_ISINACTIVE; + x.flags = LIBXFS_ISINACTIVE; printf(_("xfs_logprint:\n")); if (!libxfs_init(&x)) exit(1); diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 50b0a7e19..dd5f4c8b6 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -1984,7 +1984,7 @@ validate_sectorsize( * host filesystem. */ if (cli->xi->disfile || cli->xi->lisfile || cli->xi->risfile) - cli->xi->isdirect = 0; + cli->xi->flags &= ~LIBXFS_DIRECT; memset(ft, 0, sizeof(*ft)); get_topology(cli->xi, ft, force_overwrite); @@ -4057,8 +4057,7 @@ main( int worst_freelist = 0; struct libxfs_init xi = { - .isdirect = LIBXFS_DIRECT, - .isreadonly = LIBXFS_EXCLUSIVELY, + .flags = LIBXFS_EXCLUSIVELY | LIBXFS_DIRECT, }; struct xfs_mount mbuf = {}; struct xfs_mount *mp = &mbuf; diff --git a/repair/init.c b/repair/init.c index 1c562fb34..2dc439a22 100644 --- a/repair/init.c +++ b/repair/init.c @@ -72,21 +72,22 @@ xfs_init(struct libxfs_init *args) /* XXX assume data file also means rt file */ } - args->usebuflock = do_prefetch; args->setblksize = 0; - args->isdirect = LIBXFS_DIRECT; if (no_modify) - args->isreadonly = (LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE); + args->flags = LIBXFS_ISREADONLY | LIBXFS_ISINACTIVE; else if (dangerously) - args->isreadonly = (LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY); + args->flags = LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY; else - args->isreadonly = LIBXFS_EXCLUSIVELY; + args->flags = LIBXFS_EXCLUSIVELY; + args->flags |= LIBXFS_DIRECT; + if (do_prefetch) + args->flags |= LIBXFS_USEBUFLOCK; if (!libxfs_init(args)) { /* would -d be an option? */ if (!no_modify && !dangerously) { - args->isreadonly = (LIBXFS_ISINACTIVE | - LIBXFS_DANGEROUSLY); + args->flags &= ~LIBXFS_EXCLUSIVELY; + args->flags |= LIBXFS_ISINACTIVE | LIBXFS_DANGEROUSLY; if (libxfs_init(args)) fprintf(stderr, _("Unmount or use the dangerous (-d) option to repair a read-only mounted filesystem\n")); From patchwork Mon Dec 11 16:37:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487654 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="0rlMRxEc" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 90E0CD1 for ; Mon, 11 Dec 2023 08:38:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=Fs2pjrjhW1UMDIEnb7TwVY2M1OqT5gAG+jZ6jMUQtlo=; b=0rlMRxEclcyhoN2tPtbo6PQGgg 6aU6HCf4zcFIfNzsw2EFlwzVmXD2Zb05k7k4yCVPA9vWKifGnFCwMTcynhaDza3RR8XJY38JVFLUp FyVNXfhG5kYumDQ8PO0Dh6+ikMhw8V5JIufzc5awEsSzCKXyyxuxcZ/y3z3TOq2hGI3tFJdCLBmPD b2dCm/hh37AGg1hQAc+uHa26JLPYWAcOVYMY9JHFpS0Y9Ac5vaMRrhd6seDE5us11Ql2BXcwhEB2K gx65TP/3kNry2qYeFILe0T+xoiR0yw3sUOdh0Kcgwrdi8MJP41azVksrqvXvA5XEOY+GV017ZyfXD fi/16EHg==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIc-005tGV-0E; Mon, 11 Dec 2023 16:38:30 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 15/23] libxfs: remove the setblksize == 1 case in libxfs_device_open Date: Mon, 11 Dec 2023 17:37:34 +0100 Message-Id: <20231211163742.837427-16-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html All callers of libxfs_init always pass an actual sector size or zero in the setblksize member. Remove the unreachable setblksize == 1 case. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- libxfs/init.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libxfs/init.c b/libxfs/init.c index de1e588f1..6570c595a 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -125,10 +125,7 @@ retry: } if (!readonly && setblksize && (statb.st_mode & S_IFMT) == S_IFBLK) { - if (setblksize == 1) { - /* use the default blocksize */ - (void)platform_set_blocksize(fd, path, statb.st_rdev, XFS_MIN_SECTORSIZE, 0); - } else if (dio) { + if (dio) { /* try to use the given explicit blocksize */ (void)platform_set_blocksize(fd, path, statb.st_rdev, setblksize, 0); From patchwork Mon Dec 11 16:37:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487655 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Nwn4kOml" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3475AC2 for ; Mon, 11 Dec 2023 08:38:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=GQiM/lFhLocC+Xk976WUL6PtsBmA5w0/0C9cIn/eR+E=; b=Nwn4kOmldXuH5FfyBin4bQshH3 ddO3D6424ZV7Va/+5ixddenBu/7gyHEzXw96Tg5Kccp+jOJiIG/Xq3DXSWZT8dt6eJzBBChHguSos gJOWldkmp2KRYUNwr4xpnPWbbXyEyZw1RhEoEBor6wzIDfc2pteGnKsGNdO7wIOcocgihzZEw2n/F VaYE87NhZCaz01PMw/0T52jH0HC7+smXkDtHSURecTu7UHfezVV5iv+meiokncnT6sxqHtEd8rQUG ptBg7PG9nARAuY5a7ClEwha/1hvZ4pOJR9APLce7trn7IpNPc/qaGfdA2ufByp4fazE4kh+fiQvPN r+9qk6Pw==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIe-005tHk-1y; Mon, 11 Dec 2023 16:38:33 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 16/23] libfrog: make platform_set_blocksize exit on fatal failure Date: Mon, 11 Dec 2023 17:37:35 +0100 Message-Id: <20231211163742.837427-17-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html platform_set_blocksize has a fatal argument that is currently only used to change the printed message. Make it actually fatal similar to other libfrog platform helpers to simplify the caller. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- libfrog/linux.c | 27 +++++++++++++++------------ libfrog/platform.h | 4 ++-- libxfs/init.c | 15 ++++++--------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libfrog/linux.c b/libfrog/linux.c index 2e4fd316e..46a5ff39e 100644 --- a/libfrog/linux.c +++ b/libfrog/linux.c @@ -127,20 +127,23 @@ platform_check_iswritable(char *name, char *block, struct stat *s) return platform_check_mount(name, block, s, flags); } -int -platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal) +void +platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, + bool fatal) { - int error = 0; - - if (major(device) != RAMDISK_MAJOR) { - if ((error = ioctl(fd, BLKBSZSET, &blocksize)) < 0) { - fprintf(stderr, _("%s: %s - cannot set blocksize " - "%d on block device %s: %s\n"), - progname, fatal ? "error": "warning", - blocksize, path, strerror(errno)); - } + int error; + + if (major(device) == RAMDISK_MAJOR) + return; + error = ioctl(fd, BLKBSZSET, &blocksize); + if (error < 0) { + fprintf(stderr, _("%s: %s - cannot set blocksize " + "%d on block device %s: %s\n"), + progname, fatal ? "error": "warning", + blocksize, path, strerror(errno)); + if (fatal) + exit(1); } - return error; } /* diff --git a/libfrog/platform.h b/libfrog/platform.h index e3e6b7c71..20f9bdf5c 100644 --- a/libfrog/platform.h +++ b/libfrog/platform.h @@ -10,8 +10,8 @@ int platform_check_ismounted(char *path, char *block, struct stat *sptr, int verbose); int platform_check_iswritable(char *path, char *block, struct stat *sptr); -int platform_set_blocksize(int fd, char *path, dev_t device, int bsz, - int fatal); +void platform_set_blocksize(int fd, char *path, dev_t device, int bsz, + bool fatal); int platform_flush_device(int fd, dev_t device); int platform_direct_blockdev(void); int platform_align_blockdev(void); diff --git a/libxfs/init.c b/libxfs/init.c index 6570c595a..5be6f8cf1 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -125,15 +125,12 @@ retry: } if (!readonly && setblksize && (statb.st_mode & S_IFMT) == S_IFBLK) { - if (dio) { - /* try to use the given explicit blocksize */ - (void)platform_set_blocksize(fd, path, statb.st_rdev, - setblksize, 0); - } else { - /* given an explicit blocksize to use */ - if (platform_set_blocksize(fd, path, statb.st_rdev, setblksize, 1)) - exit(1); - } + /* + * Try to use the given explicit blocksize. Failure to set the + * block size is only fatal for direct I/O. + */ + platform_set_blocksize(fd, path, statb.st_rdev, setblksize, + dio); } /* From patchwork Mon Dec 11 16:37:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487656 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="BoBgNooh" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDC4FB4 for ; Mon, 11 Dec 2023 08:38:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=HRhz5/OA/u2+PLRXu/sMPsTt5ftcQ/uheBlsos48KeI=; b=BoBgNooh5Dafqobs30RyWxMEFs 0EPdIOnOUNZcx6xhyk2CjSOrdwTc1/9mq2exH+ast/fmDdKzUskEtPoBh21Rrn2Rvpvcn5cU8SOII A4i/DZs97u2SCCj9x3oieRMVkiUQGGoy8A7K1z31nf/BW70DIomXAsRP6dcD1wLqg9js6OAzCSpND 2TSFYgSFITJvdIMDDUysZVOZ57b/fjIKgV/tQfMAkmhFzRJhBGIXiXegLaJeXsMZhCGlUk42bQKCd MqtLxnqw8qprNkxS+bcUe/CKyHNLSwInkFtweozpluD+ajXuHHGfk6hMJxK8ijD3rIbyKefOal+i9 zA0s9hyw==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIh-005tJK-0Z; Mon, 11 Dec 2023 16:38:35 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 17/23] libxfs: remove dead size < 0 checks in libxfs_init Date: Mon, 11 Dec 2023 17:37:36 +0100 Message-Id: <20231211163742.837427-18-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html libxfs_init initializes the device size to 0 at the start of the function and libxfs_open_device never sets the size to a negativ value. Remove these checks as they are dead code. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- libxfs/init.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/libxfs/init.c b/libxfs/init.c index 5be6f8cf1..87193c3a6 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -329,21 +329,6 @@ libxfs_init(struct libxfs_init *a) platform_findsizes(dname, a->rtfd, &a->rtsize, &a->rtbsize); } - if (a->dsize < 0) { - fprintf(stderr, _("%s: can't get size for data subvolume\n"), - progname); - goto done; - } - if (a->logBBsize < 0) { - fprintf(stderr, _("%s: can't get size for log subvolume\n"), - progname); - goto done; - } - if (a->rtsize < 0) { - fprintf(stderr, _("%s: can't get size for realtime subvolume\n"), - progname); - goto done; - } if (!libxfs_bhash_size) libxfs_bhash_size = LIBXFS_BHASHSIZE(sbp); libxfs_bcache = cache_init(a->bcache_flags, libxfs_bhash_size, From patchwork Mon Dec 11 16:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487657 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="Db2aiJlc" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A0FBCF for ; Mon, 11 Dec 2023 08:38:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=5PVY1I2hotnkWKbUEL/b1azxlOVkSSqKyoz8RpZpaDg=; b=Db2aiJlc/GOo240yo8YYkXuZv+ T4LscxIRFEpgneI1uSwz0G9j+CtsYsjqDGSK7SzT26SGNnh03ETrgAt7ph8EWmlx28M9vzrThsDWB 3l1Pv4iHmpG+U4rOSSqeeEyrfNgZkrN40Tjc+78QYtoWfN0Mst31SnL+ssDNJNdgOHnLSxlBv9U6h F/nY4F3UIPwhBHPcF6ENPFnpNP0vW+WlP8sXXFiY6lttPzDyo97dHO7RpR5v3sTniJaoYdIPXVV5a YriCOTMG9eSKEx6S7VaF8Pwa+97CzqjAGbutCs8aS0aZtObLAMZ+J40Bka9/EH4TKpF0H5z/uYY8z ulLCpVrg==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIj-005tKf-2u; Mon, 11 Dec 2023 16:38:38 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 18/23] libxfs: mark libxfs_device_{open,close} static Date: Mon, 11 Dec 2023 17:37:37 +0100 Message-Id: <20231211163742.837427-19-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html libxfs_device_open and libxfs_device_close are only used in init.c. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- include/libxfs.h | 2 -- libxfs/init.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/libxfs.h b/include/libxfs.h index 9ee3dd979..68efe9caa 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -148,8 +148,6 @@ int libxfs_init(struct libxfs_init *); void libxfs_destroy(struct libxfs_init *li); extern int libxfs_device_to_fd (dev_t); -extern dev_t libxfs_device_open (char *, int, int, int); -extern void libxfs_device_close (dev_t); extern int libxfs_device_alignment (void); extern void libxfs_report(FILE *); diff --git a/libxfs/init.c b/libxfs/init.c index 87193c3a6..13ad7899c 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -92,7 +92,7 @@ libxfs_device_to_fd(dev_t device) /* libxfs_device_open: * open a device and return its device number */ -dev_t +static dev_t libxfs_device_open(char *path, int creat, int xflags, int setblksize) { dev_t dev; @@ -161,7 +161,7 @@ retry: /* NOTREACHED */ } -void +static void libxfs_device_close(dev_t dev) { int d; From patchwork Mon Dec 11 16:37:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487658 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="VzpvznPW" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC84595 for ; Mon, 11 Dec 2023 08:38:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=OZQTyqpNEYI4oQp6uQPEW/4EW3KEGPTdOqnlYfzKLi0=; b=VzpvznPW5yJ9JUy7SbMcYQPu45 gTGb1yklOFfGepPHcXH4o1K2wUq3h9RE2SRnOXTVQWQRv2jL8rqvS+9MefhVkbW80y0SEv6bEj1ji 30T7tMiCJJgf7qQu8RgzCL80VyjJ3v/lmUrrqjZaT9/mJnqWMSLvdEU4jieu/f+OAOo60ymGQYXPp ziJdRuONYn7rtFt88YA8WaIzZA171hnC2iN/dcJEkT6OJAjkCIqYZKtn1mTTNXIKgQ16W9G7ovTCe pVvUq/0LmOmosjSXeGrXpnbBScntJt3CSuB0YW0qLM5oCFIb7vtGH77p1jMrrY1K7/9nJVhejFk8y q6Z3g8vw==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIm-005tMF-1F; Mon, 11 Dec 2023 16:38:40 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 19/23] libxfs: return the opened fd from libxfs_device_open Date: Mon, 11 Dec 2023 17:37:38 +0100 Message-Id: <20231211163742.837427-20-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html So that the caller can stash it away without having to call xfs_device_to_fd. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- libxfs/init.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libxfs/init.c b/libxfs/init.c index 13ad7899c..866e5f425 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -93,7 +93,7 @@ libxfs_device_to_fd(dev_t device) * open a device and return its device number */ static dev_t -libxfs_device_open(char *path, int creat, int xflags, int setblksize) +libxfs_device_open(char *path, int creat, int xflags, int setblksize, int *fdp) { dev_t dev; int fd, d, flags; @@ -151,6 +151,7 @@ retry: if (!dev_map[d].dev) { dev_map[d].dev = dev; dev_map[d].fd = fd; + *fdp = fd; return dev; } @@ -307,16 +308,14 @@ libxfs_init(struct libxfs_init *a) if (!a->disfile && !check_open(dname, a->flags)) goto done; a->ddev = libxfs_device_open(dname, a->dcreat, a->flags, - a->setblksize); - a->dfd = libxfs_device_to_fd(a->ddev); + a->setblksize, &a->dfd); platform_findsizes(dname, a->dfd, &a->dsize, &a->dbsize); } if (logname) { if (!a->lisfile && !check_open(logname, a->flags)) goto done; a->logdev = libxfs_device_open(logname, a->lcreat, a->flags, - a->setblksize); - a->logfd = libxfs_device_to_fd(a->logdev); + a->setblksize, &a->logfd); platform_findsizes(logname, a->logfd, &a->logBBsize, &a->lbsize); } @@ -324,8 +323,7 @@ libxfs_init(struct libxfs_init *a) if (a->risfile && !check_open(rtname, a->flags)) goto done; a->rtdev = libxfs_device_open(rtname, a->rcreat, a->flags, - a->setblksize); - a->rtfd = libxfs_device_to_fd(a->rtdev); + a->setblksize, &a->rtfd); platform_findsizes(dname, a->rtfd, &a->rtsize, &a->rtbsize); } From patchwork Mon Dec 11 16:37:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487659 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="2DXywiAa" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EE798E for ; Mon, 11 Dec 2023 08:38:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=xfYS5IAAb5Z9BjR80UWwcw5amyUIpbEXaDiP826X58c=; b=2DXywiAajXRrxwpvYGXQZxbsQA NPBT7zAZIjd50Txddn6JA0YBVStv85OReofKs10ukXvVXk4qTiNl2zV4KUGv96/Ae+34HERNPuhbV fYHOaVj27p4pPHSAGPtPV7CIJj+hvEP68JZlH2Ap1v27L0BkgoQ2f/kXV86XxqYV/xdLP3fmg8ltF 58dIak1O+oceoTVhzeZrA+cui/0XBLIKpKH+CJEKpJApj7JFAkazl5dK5S+e92y2i/+aUyltQow45 DDS3wWxXac6y5w7A6JQvtYgfAiOsqNngXDqld+CDsiOFhyBHXrX0ZNT3t88hQAzWTqXoLw8DrudF1 MCaBmxrw==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIo-005tO0-2p; Mon, 11 Dec 2023 16:38:43 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 20/23] libxfs: pass the device fd to discard_blocks Date: Mon, 11 Dec 2023 17:37:39 +0100 Message-Id: <20231211163742.837427-21-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html No need to do a dev_t to fd lookup when the caller already has the fd. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- mkfs/xfs_mkfs.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index dd5f4c8b6..01c6ce33b 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -1325,19 +1325,15 @@ done: } static void -discard_blocks(dev_t dev, uint64_t nsectors, int quiet) +discard_blocks(int fd, uint64_t nsectors, int quiet) { - int fd; uint64_t offset = 0; /* Discard the device 2G at a time */ const uint64_t step = 2ULL << 30; const uint64_t count = BBTOB(nsectors); - fd = libxfs_device_to_fd(dev); - if (fd <= 0) - return; - - /* The block discarding happens in smaller batches so it can be + /* + * The block discarding happens in smaller batches so it can be * interrupted prematurely */ while (offset < count) { @@ -2875,11 +2871,11 @@ discard_devices( */ if (!xi->disfile) - discard_blocks(xi->ddev, xi->dsize, quiet); + discard_blocks(xi->dfd, xi->dsize, quiet); if (xi->rtdev && !xi->risfile) - discard_blocks(xi->rtdev, xi->rtsize, quiet); + discard_blocks(xi->rtfd, xi->rtsize, quiet); if (xi->logdev && xi->logdev != xi->ddev && !xi->lisfile) - discard_blocks(xi->logdev, xi->logBBsize, quiet); + discard_blocks(xi->logfd, xi->logBBsize, quiet); } static void From patchwork Mon Dec 11 16:37:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487660 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="zRviP7FD" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D55A28E for ; Mon, 11 Dec 2023 08:38:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=xNH5gDpy1OsXzX1OsQe1uFSC9CH6BfZVQdCD3xNioiQ=; b=zRviP7FDcp+ksZ/5JusqLw5eD+ 6PBT13pSHGrmu+j/HoZei6Qhp+JM0lYU88sUvCpxgAxAxp1f8922tckKHVN0NFjODXxQcoFdeuoNW hOa9ZVxOZAdgkPPKG8RehKKlzaIo50n/fiVhwowi70v7xbN8IHJ1fO8Ad8uBb+ycEaUiye4Pira8h PzByRsSyNddQ1gIfZ9qSMh+ZlfkmNvtg2jjmlXY9iksEvoO2Q/K+lkX86/fBN6+k66xxdtDm297Rl BpAz822+7B4EHyZ61/lDMwO8oat2aRGGA+k/PCRUteWjHWAnNBB9A1aHSo1sy6AJFyPyfODwdsebD E4rYPwng==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIr-005tPi-19; Mon, 11 Dec 2023 16:38:45 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 21/23] xfs_repair: remove various libxfs_device_to_fd calls Date: Mon, 11 Dec 2023 17:37:40 +0100 Message-Id: <20231211163742.837427-22-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html A few places in xfs_repair call libxfs_device_to_fd to get the data device fd from the data device dev_t stored in the libxfs_init structure. Just use the file descriptor stored right there directly. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- repair/xfs_repair.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index 8a6cf31b4..cdbdbe855 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -724,13 +724,11 @@ static void check_fs_vs_host_sectsize( struct xfs_sb *sb) { - int fd, ret; + int ret; long old_flags; struct xfs_fsop_geom geom = { 0 }; - fd = libxfs_device_to_fd(x.ddev); - - ret = -xfrog_geometry(fd, &geom); + ret = -xfrog_geometry(x.dfd, &geom); if (ret) { do_log(_("Cannot get host filesystem geometry.\n" "Repair may fail if there is a sector size mismatch between\n" @@ -739,8 +737,8 @@ check_fs_vs_host_sectsize( } if (sb->sb_sectsize < geom.sectsize) { - old_flags = fcntl(fd, F_GETFL, 0); - if (fcntl(fd, F_SETFL, old_flags & ~O_DIRECT) < 0) { + old_flags = fcntl(x.dfd, F_GETFL, 0); + if (fcntl(x.dfd, F_SETFL, old_flags & ~O_DIRECT) < 0) { do_warn(_( "Sector size on host filesystem larger than image sector size.\n" "Cannot turn off direct IO, so exiting.\n")); @@ -986,10 +984,9 @@ main(int argc, char **argv) /* -f forces this, but let's be nice and autodetect it, as well. */ if (!isa_file) { - int fd = libxfs_device_to_fd(x.ddev); struct stat statbuf; - if (fstat(fd, &statbuf) < 0) + if (fstat(x.dfd, &statbuf) < 0) do_warn(_("%s: couldn't stat \"%s\"\n"), progname, fs_name); else if (S_ISREG(statbuf.st_mode)) From patchwork Mon Dec 11 16:37:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487661 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QjohJZUr" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63CDD8E for ; Mon, 11 Dec 2023 08:38:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=b1/+QwHrxVG+nufyYIwOPNTS/emBQ64Rl6YGmW3orlc=; b=QjohJZUr9O5S1OoCskCsVl8NWU 8ejFyeDUtSN5YvegcZh7baOluQp0CD1naBhXTIsIGwx2HfL8xWwwBkj+n1yiFCeJYglfJYSQ7NWOB OPvKY7X2P+Or+Lkj1MhqZzP/ctd5OffXZQFev/hHuSg4AIHs8+artY8MvcRCarexsgqWQqxAADkjW r4EMNSLU7ZuTR/+PmMCdNkKr0hyo72lChclKU41P+iXiJUs2O8VQ/hbyHO7yokW7h3FBvUSn/H/6I 3KrvzGnDsT7N68RZmZED5ZFik4etx2cyRHa7A3Vz4s3xu30lPAlVOk/PFoI8Yp0qk4ZT9TwItUlGo NOjE3pNQ==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIt-005tRn-2r; Mon, 11 Dec 2023 16:38:48 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 22/23] libxfs: stash away the device fd in struct xfs_buftarg Date: Mon, 11 Dec 2023 17:37:41 +0100 Message-Id: <20231211163742.837427-23-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Cache the open file descriptor for each device in the buftarg structure and remove the now unused dev_map infrastructure. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- include/libxfs.h | 1 - libxfs/init.c | 108 +++++++++++---------------------------------- libxfs/libxfs_io.h | 1 + libxfs/rdwr.c | 16 +++---- repair/prefetch.c | 2 +- 5 files changed, 34 insertions(+), 94 deletions(-) diff --git a/include/libxfs.h b/include/libxfs.h index 68efe9caa..058217c2a 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -147,7 +147,6 @@ extern xfs_lsn_t libxfs_max_lsn; int libxfs_init(struct libxfs_init *); void libxfs_destroy(struct libxfs_init *li); -extern int libxfs_device_to_fd (dev_t); extern int libxfs_device_alignment (void); extern void libxfs_report(FILE *); diff --git a/libxfs/init.c b/libxfs/init.c index 866e5f425..320e4d63f 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -36,15 +36,7 @@ int libxfs_bhash_size; /* #buckets in bcache */ int use_xfs_buf_lock; /* global flag: use xfs_buf locks for MT */ -/* - * dev_map - map open devices to fd. - */ -#define MAX_DEVS 10 /* arbitary maximum */ static int nextfakedev = -1; /* device number to give to next fake device */ -static struct dev_to_fd { - dev_t dev; - int fd; -} dev_map[MAX_DEVS]={{0}}; /* * Checks whether a given device has a mounted, writable @@ -70,33 +62,13 @@ check_isactive(char *name, char *block, int fatal) return 0; } -/* libxfs_device_to_fd: - * lookup a device number in the device map - * return the associated fd - */ -int -libxfs_device_to_fd(dev_t device) -{ - int d; - - for (d = 0; d < MAX_DEVS; d++) - if (dev_map[d].dev == device) - return dev_map[d].fd; - - fprintf(stderr, _("%s: %s: device %lld is not open\n"), - progname, __FUNCTION__, (long long)device); - exit(1); - /* NOTREACHED */ -} - /* libxfs_device_open: * open a device and return its device number */ static dev_t libxfs_device_open(char *path, int creat, int xflags, int setblksize, int *fdp) { - dev_t dev; - int fd, d, flags; + int fd, flags; int readonly, dio, excl; struct stat statb; @@ -134,61 +106,28 @@ retry: } /* - * Get the device number from the stat buf - unless - * we're not opening a real device, in which case - * choose a new fake device number. + * Get the device number from the stat buf - unless we're not opening a + * real device, in which case choose a new fake device number. */ - dev = (statb.st_rdev) ? (statb.st_rdev) : (nextfakedev--); - - for (d = 0; d < MAX_DEVS; d++) - if (dev_map[d].dev == dev) { - fprintf(stderr, _("%s: device %lld is already open\n"), - progname, (long long)dev); - exit(1); - } - - for (d = 0; d < MAX_DEVS; d++) - if (!dev_map[d].dev) { - dev_map[d].dev = dev; - dev_map[d].fd = fd; - *fdp = fd; - - return dev; - } - - fprintf(stderr, _("%s: %s: too many open devices\n"), - progname, __FUNCTION__); - exit(1); - /* NOTREACHED */ + *fdp = fd; + if (statb.st_rdev) + return statb.st_rdev; + return nextfakedev--; } static void -libxfs_device_close(dev_t dev) +libxfs_device_close(int fd, dev_t dev) { - int d; + int ret; - for (d = 0; d < MAX_DEVS; d++) - if (dev_map[d].dev == dev) { - int fd, ret; - - fd = dev_map[d].fd; - dev_map[d].dev = dev_map[d].fd = 0; - - ret = platform_flush_device(fd, dev); - if (ret) { - ret = -errno; - fprintf(stderr, + ret = platform_flush_device(fd, dev); + if (ret) { + ret = -errno; + fprintf(stderr, _("%s: flush of device %lld failed, err=%d"), - progname, (long long)dev, ret); - } - close(fd); - - return; - } - - fprintf(stderr, _("%s: %s: device %lld is not open\n"), - progname, __FUNCTION__, (long long)dev); - exit(1); + progname, (long long)dev, ret); + } + close(fd); } static int @@ -271,11 +210,11 @@ libxfs_close_devices( struct libxfs_init *li) { if (li->ddev) - libxfs_device_close(li->ddev); + libxfs_device_close(li->dfd, li->ddev); if (li->logdev && li->logdev != li->ddev) - libxfs_device_close(li->logdev); + libxfs_device_close(li->logfd, li->logdev); if (li->rtdev) - libxfs_device_close(li->rtdev); + libxfs_device_close(li->rtfd, li->rtdev); li->ddev = li->logdev = li->rtdev = 0; li->dfd = li->logfd = li->rtfd = -1; @@ -514,6 +453,7 @@ static struct xfs_buftarg * libxfs_buftarg_alloc( struct xfs_mount *mp, dev_t dev, + int fd, unsigned long write_fails) { struct xfs_buftarg *btp; @@ -526,6 +466,7 @@ libxfs_buftarg_alloc( } btp->bt_mount = mp; btp->bt_bdev = dev; + btp->bt_bdev_fd = fd; btp->flags = 0; if (write_fails) { btp->writes_left = write_fails; @@ -629,13 +570,14 @@ libxfs_buftarg_init( return; } - mp->m_ddev_targp = libxfs_buftarg_alloc(mp, xi->ddev, dfail); + mp->m_ddev_targp = libxfs_buftarg_alloc(mp, xi->ddev, xi->dfd, dfail); if (!xi->logdev || xi->logdev == xi->ddev) mp->m_logdev_targp = mp->m_ddev_targp; else mp->m_logdev_targp = libxfs_buftarg_alloc(mp, xi->logdev, - lfail); - mp->m_rtdev_targp = libxfs_buftarg_alloc(mp, xi->rtdev, rfail); + xi->logfd, lfail); + mp->m_rtdev_targp = libxfs_buftarg_alloc(mp, xi->rtdev, xi->rtfd, + rfail); } /* Compute maximum possible height for per-AG btree types for this fs. */ diff --git a/libxfs/libxfs_io.h b/libxfs/libxfs_io.h index bf4d4ecd9..267ea9796 100644 --- a/libxfs/libxfs_io.h +++ b/libxfs/libxfs_io.h @@ -26,6 +26,7 @@ struct xfs_buftarg { pthread_mutex_t lock; unsigned long writes_left; dev_t bt_bdev; + int bt_bdev_fd; unsigned int flags; }; diff --git a/libxfs/rdwr.c b/libxfs/rdwr.c index ccd1501ab..0e332110b 100644 --- a/libxfs/rdwr.c +++ b/libxfs/rdwr.c @@ -62,13 +62,13 @@ static void libxfs_brelse(struct cache_node *node); int libxfs_device_zero(struct xfs_buftarg *btp, xfs_daddr_t start, uint len) { + int fd = btp->bt_bdev_fd; xfs_off_t start_offset, end_offset, offset; ssize_t zsize, bytes; size_t len_bytes; char *z; - int error, fd; + int error; - fd = libxfs_device_to_fd(btp->bt_bdev); start_offset = LIBXFS_BBTOOFF64(start); /* try to use special zeroing methods, fall back to writes if needed */ @@ -598,7 +598,7 @@ int libxfs_readbufr(struct xfs_buftarg *btp, xfs_daddr_t blkno, struct xfs_buf *bp, int len, int flags) { - int fd = libxfs_device_to_fd(btp->bt_bdev); + int fd = btp->bt_bdev_fd; int bytes = BBTOB(len); int error; @@ -631,12 +631,11 @@ libxfs_readbuf_verify( int libxfs_readbufr_map(struct xfs_buftarg *btp, struct xfs_buf *bp, int flags) { - int fd; + int fd = btp->bt_bdev_fd; int error = 0; void *buf; int i; - fd = libxfs_device_to_fd(btp->bt_bdev); buf = bp->b_addr; for (i = 0; i < bp->b_nmaps; i++) { off64_t offset = LIBXFS_BBTOOFF64(bp->b_maps[i].bm_bn); @@ -820,7 +819,7 @@ int libxfs_bwrite( struct xfs_buf *bp) { - int fd = libxfs_device_to_fd(bp->b_target->bt_bdev); + int fd = bp->b_target->bt_bdev_fd; /* * we never write buffers that are marked stale. This indicates they @@ -1171,13 +1170,12 @@ int libxfs_blkdev_issue_flush( struct xfs_buftarg *btp) { - int fd, ret; + int ret; if (btp->bt_bdev == 0) return 0; - fd = libxfs_device_to_fd(btp->bt_bdev); - ret = platform_flush_device(fd, btp->bt_bdev); + ret = platform_flush_device(btp->bt_bdev_fd, btp->bt_bdev); return ret ? -errno : 0; } diff --git a/repair/prefetch.c b/repair/prefetch.c index 017750e9a..78c1e3974 100644 --- a/repair/prefetch.c +++ b/repair/prefetch.c @@ -876,7 +876,7 @@ init_prefetch( xfs_mount_t *pmp) { mp = pmp; - mp_fd = libxfs_device_to_fd(mp->m_ddev_targp->bt_bdev); + mp_fd = mp->m_ddev_targp->bt_bdev_fd;; pf_max_bytes = sysconf(_SC_PAGE_SIZE) << 7; pf_max_bbs = pf_max_bytes >> BBSHIFT; pf_max_fsbs = pf_max_bytes >> mp->m_sb.sb_blocklog; From patchwork Mon Dec 11 16:37:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 13487662 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="QB7qTili" Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 299BB98 for ; Mon, 11 Dec 2023 08:38:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc: To:From:Sender:Reply-To:Content-ID:Content-Description; bh=2QTHK7Cmht+8grEGowicDb4HwWzaooquNeJmlMvn9XQ=; b=QB7qTilimmEQ4h5yL0og4whF0d 3Y2Bik51/e8Ppsgxf9XPuWUpvG2SbG4HQhad5xomm6D84ZDqgC6nLkq6O4srVmFsJrBAVY3vkB3tv ZK1/7B/lKu5Hfn9dP/42UT6htDT0K4vP0tJplcnIakckV2wVv9P11DMNrY2vuJRvl1j0nTrx5FHzL /O09AwM63ucwRY1eLjzyNNjs0BQKzCrGNtuoD3E6MNPBFhvI626VxDRE/otcQaYIZ0TnkFUAhygBk RYGrA5qn2fzzt+rPDGJuhYnhfcoPLk41oyTDB/lcgrjd6nAjyhVPwrxvYaUk/TtiQaxkQ5Og4WYjs cMiKRjug==; Received: from [2001:4bb8:19a:a621:c70:4a89:bc61:3] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.96 #2 (Red Hat Linux)) id 1rCjIw-005tSv-1H; Mon, 11 Dec 2023 16:38:51 +0000 From: Christoph Hellwig To: Carlos Maiolino Cc: linux-xfs@vger.kernel.org Subject: [PATCH 23/23] libxfs: split out a libxfs_dev structure from struct libxfs_init Date: Mon, 11 Dec 2023 17:37:42 +0100 Message-Id: <20231211163742.837427-24-hch@lst.de> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231211163742.837427-1-hch@lst.de> References: <20231211163742.837427-1-hch@lst.de> Precedence: bulk X-Mailing-List: linux-xfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Most of the content of libxfs_init is members duplicated for each of the data, log and RT devices. Split those members into a separate libxfs_dev structure. Signed-off-by: Christoph Hellwig Reviewed-by: Carlos Maiolino --- copy/xfs_copy.c | 4 +- db/info.c | 2 +- db/init.c | 12 +-- db/output.c | 2 +- db/sb.c | 8 +- growfs/xfs_growfs.c | 20 ++--- include/libxfs.h | 45 ++++------ libxfs/init.c | 210 +++++++++++++++++++++----------------------- libxfs/topology.c | 16 ++-- logprint/logprint.c | 40 ++++----- mkfs/xfs_mkfs.c | 158 ++++++++++++++++----------------- repair/init.c | 12 +-- repair/phase2.c | 4 +- repair/sb.c | 16 ++-- repair/xfs_repair.c | 8 +- 15 files changed, 265 insertions(+), 292 deletions(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index bd7c6d334..6e692e4f7 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -716,8 +716,8 @@ main(int argc, char **argv) memset(&xargs, 0, sizeof(xargs)); xargs.flags = LIBXFS_ISREADONLY | LIBXFS_DIRECT; - xargs.dname = source_name; - xargs.disfile = source_is_file; + xargs.data.name = source_name; + xargs.data.isfile = source_is_file; if (!libxfs_init(&xargs)) { do_log(_("%s: couldn't initialize XFS library\n" diff --git a/db/info.c b/db/info.c index b30ada3aa..9c6203f02 100644 --- a/db/info.c +++ b/db/info.c @@ -30,7 +30,7 @@ info_f( struct xfs_fsop_geom geo; libxfs_fs_geometry(mp, &geo, XFS_FS_GEOM_MAX_STRUCT_VER); - xfs_report_geom(&geo, x.dname, x.logname, x.rtname); + xfs_report_geom(&geo, x.data.name, x.log.name, x.rt.name); return 0; } diff --git a/db/init.c b/db/init.c index f240d0f66..cea25ae52 100644 --- a/db/init.c +++ b/db/init.c @@ -61,7 +61,7 @@ init( cmdline[ncmdline++] = optarg; break; case 'f': - x.disfile = 1; + x.data.isfile = 1; break; case 'F': force = 1; @@ -76,7 +76,7 @@ init( x.flags = LIBXFS_ISREADONLY; break; case 'l': - x.logname = optarg; + x.log.name = optarg; break; case 'x': expert_mode = 1; @@ -91,7 +91,7 @@ init( if (optind + 1 != argc) usage(); - x.dname = argv[optind]; + x.data.name = argv[optind]; x.flags |= LIBXFS_DIRECT; x.bcache_flags = CACHE_MISCOMPARE_PURGE; @@ -111,7 +111,7 @@ init( 1 << (XFS_MAX_SECTORSIZE_LOG - BBSHIFT), 0, &bp, NULL); if (error) { fprintf(stderr, _("%s: %s is invalid (cannot read first 512 " - "bytes)\n"), progname, x.dname); + "bytes)\n"), progname, x.data.name); exit(1); } @@ -122,7 +122,7 @@ init( sbp = &xmount.m_sb; if (sbp->sb_magicnum != XFS_SB_MAGIC) { fprintf(stderr, _("%s: %s is not a valid XFS filesystem (unexpected SB magic number 0x%08x)\n"), - progname, x.dname, sbp->sb_magicnum); + progname, x.data.name, sbp->sb_magicnum); if (!force) { fprintf(stderr, _("Use -F to force a read attempt.\n")); exit(EXIT_FAILURE); @@ -134,7 +134,7 @@ init( if (!mp) { fprintf(stderr, _("%s: device %s unusable (not an XFS filesystem?)\n"), - progname, x.dname); + progname, x.data.name); exit(1); } mp->m_log = &xlog; diff --git a/db/output.c b/db/output.c index 30ae82ced..d12266c42 100644 --- a/db/output.c +++ b/db/output.c @@ -34,7 +34,7 @@ dbprintf(const char *fmt, ...) blockint(); i = 0; if (dbprefix) - i += printf("%s: ", x.dname); + i += printf("%s: ", x.data.name); i += vprintf(fmt, ap); unblockint(); va_end(ap); diff --git a/db/sb.c b/db/sb.c index b2aa4a626..b48767f47 100644 --- a/db/sb.c +++ b/db/sb.c @@ -220,13 +220,13 @@ sb_logcheck(void) int dirty; if (mp->m_sb.sb_logstart) { - if (x.logdev && x.logdev != x.ddev) { + if (x.log.dev && x.log.dev != x.data.dev) { dbprintf(_("aborting - external log specified for FS " "with an internal log\n")); return 0; } } else { - if (!x.logdev || (x.logdev == x.ddev)) { + if (!x.log.dev || (x.log.dev == x.data.dev)) { dbprintf(_("aborting - no external log specified for FS " "with an external log\n")); return 0; @@ -452,10 +452,10 @@ uuid_f( } } if (mp->m_sb.sb_logstart) { - if (x.logdev && x.logdev != x.ddev) + if (x.log.dev && x.log.dev != x.data.dev) dbprintf(_("warning - external log specified " "for FS with an internal log\n")); - } else if (!x.logdev || (x.logdev == x.ddev)) { + } else if (!x.log.dev || (x.log.dev == x.data.dev)) { dbprintf(_("warning - no external log specified " "for FS with an external log\n")); } diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c index 05aea3496..4b941403e 100644 --- a/growfs/xfs_growfs.c +++ b/growfs/xfs_growfs.c @@ -183,26 +183,26 @@ main(int argc, char **argv) */ memset(&xi, 0, sizeof(xi)); - xi.dname = datadev; - xi.logname = logdev; - xi.rtname = rtdev; + xi.data.name = datadev; + xi.log.name = logdev; + xi.rt.name = rtdev; xi.flags = LIBXFS_ISREADONLY; if (!libxfs_init(&xi)) usage(); /* check we got the info for all the sections we are trying to modify */ - if (!xi.ddev) { + if (!xi.data.dev) { fprintf(stderr, _("%s: failed to access data device for %s\n"), progname, fname); exit(1); } - if (lflag && !isint && !xi.logdev) { + if (lflag && !isint && !xi.log.dev) { fprintf(stderr, _("%s: failed to access external log for %s\n"), progname, fname); exit(1); } - if (rflag && !xi.rtdev) { + if (rflag && !xi.rt.dev) { fprintf(stderr, _("%s: failed to access realtime device for %s\n"), progname, fname); @@ -211,10 +211,10 @@ main(int argc, char **argv) xfs_report_geom(&geo, datadev, logdev, rtdev); - ddsize = xi.dsize; - dlsize = ( xi.logBBsize? xi.logBBsize : + ddsize = xi.data.size; + dlsize = (xi.log.size ? xi.log.size : geo.logblocks * (geo.blocksize / BBSIZE) ); - drsize = xi.rtsize; + drsize = xi.rt.size; /* * Ok, Linux only has a 1024-byte resolution on device _size_, @@ -328,7 +328,7 @@ _("[EXPERIMENTAL] try to shrink unused space %lld, old size is %lld\n"), else if (xflag) in.isint = 0; else - in.isint = xi.logBBsize == 0; + in.isint = xi.log.size == 0; if (lsize == geo.logblocks && (in.isint == isint)) { if (lflag) fprintf(stderr, diff --git a/include/libxfs.h b/include/libxfs.h index 058217c2a..eb3f9ac22 100644 --- a/include/libxfs.h +++ b/include/libxfs.h @@ -89,38 +89,31 @@ struct iomap; #define xfs_isset(a,i) ((a)[(i)/(sizeof(*(a))*NBBY)] & (1ULL<<((i)%(sizeof(*(a))*NBBY)))) +struct libxfs_dev { + /* input parameters */ + char *name; /* pathname of the device */ + bool isfile; /* is the device a file? */ + bool create; /* create file if it doesn't exist */ + + /* output parameters */ + dev_t dev; /* device name for the device */ + long long size; /* size of subvolume (BBs) */ + int bsize; /* device blksize */ + int fd; /* file descriptor */ +}; + /* * Argument structure for libxfs_init(). */ struct libxfs_init { - /* input parameters */ - char *dname; /* pathname of data "subvolume" */ - char *logname; /* pathname of log "subvolume" */ - char *rtname; /* pathname of realtime "subvolume" */ + struct libxfs_dev data; + struct libxfs_dev log; + struct libxfs_dev rt; + + /* input parameters */ unsigned flags; /* LIBXFS_* flags below */ - int disfile; /* data "subvolume" is a regular file */ - int dcreat; /* try to create data subvolume */ - int lisfile; /* log "subvolume" is a regular file */ - int lcreat; /* try to create log subvolume */ - int risfile; /* realtime "subvolume" is a reg file */ - int rcreat; /* try to create realtime subvolume */ - int setblksize; /* attempt to set device blksize */ - /* output results */ - dev_t ddev; /* device for data subvolume */ - dev_t logdev; /* device for log subvolume */ - dev_t rtdev; /* device for realtime subvolume */ - long long dsize; /* size of data subvolume (BBs) */ - long long logBBsize; /* size of log subvolume (BBs) */ - /* (blocks allocated for use as - * log is stored in mount structure) */ - long long rtsize; /* size of realtime subvolume (BBs) */ - int dbsize; /* data subvolume device blksize */ - int lbsize; /* log subvolume device blksize */ - int rtbsize; /* realtime subvolume device blksize */ - int dfd; /* data subvolume file descriptor */ - int logfd; /* log subvolume file descriptor */ - int rtfd; /* realtime subvolume file descriptor */ int bcache_flags; /* cache init flags */ + int setblksize; /* value to set device blksizes to */ }; /* disallow all mounted filesystems: */ diff --git a/libxfs/init.c b/libxfs/init.c index 320e4d63f..63c506a69 100644 --- a/libxfs/init.c +++ b/libxfs/init.c @@ -62,93 +62,117 @@ check_isactive(char *name, char *block, int fatal) return 0; } -/* libxfs_device_open: - * open a device and return its device number - */ -static dev_t -libxfs_device_open(char *path, int creat, int xflags, int setblksize, int *fdp) +static int +check_open( + struct libxfs_init *xi, + struct libxfs_dev *dev) { - int fd, flags; - int readonly, dio, excl; - struct stat statb; + struct stat stbuf; - readonly = (xflags & LIBXFS_ISREADONLY); - excl = (xflags & LIBXFS_EXCLUSIVELY) && !creat; - dio = (xflags & LIBXFS_DIRECT) && !creat && platform_direct_blockdev(); + if (stat(dev->name, &stbuf) < 0) { + perror(dev->name); + return 0; + } + if (!(xi->flags & LIBXFS_ISREADONLY) && + !(xi->flags & LIBXFS_ISINACTIVE) && + platform_check_ismounted(dev->name, dev->name, NULL, 1)) + return 0; -retry: - flags = (readonly ? O_RDONLY : O_RDWR) | \ - (creat ? (O_CREAT|O_TRUNC) : 0) | \ - (dio ? O_DIRECT : 0) | \ - (excl ? O_EXCL : 0); + if ((xi->flags & LIBXFS_ISINACTIVE) && + check_isactive(dev->name, dev->name, !!(xi->flags & + (LIBXFS_ISREADONLY | LIBXFS_DANGEROUSLY)))) + return 0; + + return 1; +} + +static bool +libxfs_device_open( + struct libxfs_init *xi, + struct libxfs_dev *dev) +{ + struct stat statb; + int flags; + + dev->fd = -1; + + if (!dev->name) + return true; + if (!dev->isfile && !check_open(xi, dev)) + return false; + + if (xi->flags & LIBXFS_ISREADONLY) + flags = O_RDONLY; + else + flags = O_RDWR; - if ((fd = open(path, flags, 0666)) < 0) { - if (errno == EINVAL && --dio == 0) + if (dev->create) { + flags |= O_CREAT | O_TRUNC; + } else { + if (xi->flags & LIBXFS_EXCLUSIVELY) + flags |= O_EXCL; + if ((xi->flags & LIBXFS_DIRECT) && platform_direct_blockdev()) + flags |= O_DIRECT; + } + +retry: + dev->fd = open(dev->name, flags, 0666); + if (dev->fd < 0) { + if (errno == EINVAL && (flags & O_DIRECT)) { + flags &= ~O_DIRECT; goto retry; + } fprintf(stderr, _("%s: cannot open %s: %s\n"), - progname, path, strerror(errno)); + progname, dev->name, strerror(errno)); exit(1); } - if (fstat(fd, &statb) < 0) { + if (fstat(dev->fd, &statb) < 0) { fprintf(stderr, _("%s: cannot stat %s: %s\n"), - progname, path, strerror(errno)); + progname, dev->name, strerror(errno)); exit(1); } - if (!readonly && setblksize && (statb.st_mode & S_IFMT) == S_IFBLK) { + if (!(xi->flags & LIBXFS_ISREADONLY) && + xi->setblksize && + (statb.st_mode & S_IFMT) == S_IFBLK) { /* * Try to use the given explicit blocksize. Failure to set the * block size is only fatal for direct I/O. */ - platform_set_blocksize(fd, path, statb.st_rdev, setblksize, - dio); + platform_set_blocksize(dev->fd, dev->name, statb.st_rdev, + xi->setblksize, flags & O_DIRECT); } /* * Get the device number from the stat buf - unless we're not opening a * real device, in which case choose a new fake device number. */ - *fdp = fd; if (statb.st_rdev) - return statb.st_rdev; - return nextfakedev--; + dev->dev = statb.st_rdev; + else + dev->dev = nextfakedev--; + platform_findsizes(dev->name, dev->fd, &dev->size, &dev->bsize); + return true; } static void -libxfs_device_close(int fd, dev_t dev) +libxfs_device_close( + struct libxfs_dev *dev) { - int ret; + int ret; - ret = platform_flush_device(fd, dev); + ret = platform_flush_device(dev->fd, dev->dev); if (ret) { ret = -errno; fprintf(stderr, _("%s: flush of device %lld failed, err=%d"), progname, (long long)dev, ret); } - close(fd); -} + close(dev->fd); -static int -check_open(char *path, int flags) -{ - int readonly = (flags & LIBXFS_ISREADONLY); - int inactive = (flags & LIBXFS_ISINACTIVE); - int dangerously = (flags & LIBXFS_DANGEROUSLY); - struct stat stbuf; - - if (stat(path, &stbuf) < 0) { - perror(path); - return 0; - } - if (!readonly && !inactive && platform_check_ismounted(path, path, NULL, 1)) - return 0; - - if (inactive && check_isactive(path, path, ((readonly|dangerously)?1:0))) - return 0; - - return 1; + dev->fd = -1; + dev->dev = 0; } /* @@ -209,15 +233,12 @@ static void libxfs_close_devices( struct libxfs_init *li) { - if (li->ddev) - libxfs_device_close(li->dfd, li->ddev); - if (li->logdev && li->logdev != li->ddev) - libxfs_device_close(li->logfd, li->logdev); - if (li->rtdev) - libxfs_device_close(li->rtfd, li->rtdev); - - li->ddev = li->logdev = li->rtdev = 0; - li->dfd = li->logfd = li->rtfd = -1; + if (li->data.dev) + libxfs_device_close(&li->data); + if (li->log.dev && li->log.dev != li->data.dev) + libxfs_device_close(&li->log); + if (li->rt.dev) + libxfs_device_close(&li->rt); } /* @@ -227,44 +248,16 @@ libxfs_close_devices( int libxfs_init(struct libxfs_init *a) { - char *dname; - char *logname; - char *rtname; - - dname = a->dname; - logname = a->logname; - rtname = a->rtname; - a->dfd = a->logfd = a->rtfd = -1; - a->ddev = a->logdev = a->rtdev = 0; - a->dsize = a->lbsize = a->rtbsize = 0; - a->dbsize = a->logBBsize = a->rtsize = 0; - rcu_init(); rcu_register_thread(); radix_tree_init(); - if (dname) { - if (!a->disfile && !check_open(dname, a->flags)) - goto done; - a->ddev = libxfs_device_open(dname, a->dcreat, a->flags, - a->setblksize, &a->dfd); - platform_findsizes(dname, a->dfd, &a->dsize, &a->dbsize); - } - if (logname) { - if (!a->lisfile && !check_open(logname, a->flags)) - goto done; - a->logdev = libxfs_device_open(logname, a->lcreat, a->flags, - a->setblksize, &a->logfd); - platform_findsizes(logname, a->logfd, &a->logBBsize, - &a->lbsize); - } - if (rtname) { - if (a->risfile && !check_open(rtname, a->flags)) - goto done; - a->rtdev = libxfs_device_open(rtname, a->rcreat, a->flags, - a->setblksize, &a->rtfd); - platform_findsizes(dname, a->rtfd, &a->rtsize, &a->rtbsize); - } + if (!libxfs_device_open(a, &a->data)) + goto done; + if (!libxfs_device_open(a, &a->log)) + goto done; + if (!libxfs_device_open(a, &a->rt)) + goto done; if (!libxfs_bhash_size) libxfs_bhash_size = LIBXFS_BHASHSIZE(sbp); @@ -452,8 +445,7 @@ xfs_set_inode_alloc( static struct xfs_buftarg * libxfs_buftarg_alloc( struct xfs_mount *mp, - dev_t dev, - int fd, + struct libxfs_dev *dev, unsigned long write_fails) { struct xfs_buftarg *btp; @@ -465,8 +457,8 @@ libxfs_buftarg_alloc( exit(1); } btp->bt_mount = mp; - btp->bt_bdev = dev; - btp->bt_bdev_fd = fd; + btp->bt_bdev = dev->dev; + btp->bt_bdev_fd = dev->fd; btp->flags = 0; if (write_fails) { btp->writes_left = write_fails; @@ -538,29 +530,29 @@ libxfs_buftarg_init( if (mp->m_ddev_targp) { /* should already have all buftargs initialised */ - if (mp->m_ddev_targp->bt_bdev != xi->ddev || + 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->logdev || xi->logdev == xi->ddev) { + 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->logdev || + } 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->rtdev && - (mp->m_rtdev_targp->bt_bdev != xi->rtdev || + if (xi->rt.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"), @@ -570,14 +562,12 @@ libxfs_buftarg_init( return; } - mp->m_ddev_targp = libxfs_buftarg_alloc(mp, xi->ddev, xi->dfd, dfail); - if (!xi->logdev || xi->logdev == xi->ddev) + mp->m_ddev_targp = libxfs_buftarg_alloc(mp, &xi->data, dfail); + if (!xi->log.dev || xi->log.dev == xi->data.dev) mp->m_logdev_targp = mp->m_ddev_targp; else - mp->m_logdev_targp = libxfs_buftarg_alloc(mp, xi->logdev, - xi->logfd, lfail); - mp->m_rtdev_targp = libxfs_buftarg_alloc(mp, xi->rtdev, xi->rtfd, - rfail); + mp->m_logdev_targp = libxfs_buftarg_alloc(mp, &xi->log, lfail); + mp->m_rtdev_targp = libxfs_buftarg_alloc(mp, &xi->rt, rfail); } /* Compute maximum possible height for per-AG btree types for this fs. */ @@ -711,7 +701,7 @@ libxfs_mount( /* Initialize the precomputed transaction reservations values */ xfs_trans_init(mp); - if (xi->ddev == 0) /* maxtrres, we have no device so leave now */ + if (xi->data.dev == 0) /* maxtrres, we have no device so leave now */ return mp; /* device size checks must pass unless we're a debugger. */ diff --git a/libxfs/topology.c b/libxfs/topology.c index d6791c0f6..06013d429 100644 --- a/libxfs/topology.c +++ b/libxfs/topology.c @@ -299,34 +299,34 @@ get_topology( * to try to obtain the underlying filesystem's requirements * for direct IO; we'll set our sector size to that if possible. */ - if (xi->disfile || - (!stat(xi->dname, &statbuf) && S_ISREG(statbuf.st_mode))) { + if (xi->data.isfile || + (!stat(xi->data.name, &statbuf) && S_ISREG(statbuf.st_mode))) { int fd; int flags = O_RDONLY; long long dummy; /* with xi->disfile we may not have the file yet! */ - if (xi->disfile) + if (xi->data.isfile) flags |= O_CREAT; - fd = open(xi->dname, flags, 0666); + fd = open(xi->data.name, flags, 0666); if (fd >= 0) { - platform_findsizes(xi->dname, fd, &dummy, + platform_findsizes(xi->data.name, fd, &dummy, &ft->lsectorsize); close(fd); ft->psectorsize = ft->lsectorsize; } else ft->psectorsize = ft->lsectorsize = BBSIZE; } else { - blkid_get_topology(xi->dname, &ft->dsunit, &ft->dswidth, + blkid_get_topology(xi->data.name, &ft->dsunit, &ft->dswidth, &ft->lsectorsize, &ft->psectorsize, force_overwrite); } - if (xi->rtname && !xi->risfile) { + if (xi->rt.name && !xi->rt.isfile) { int sunit, lsectorsize, psectorsize; - blkid_get_topology(xi->rtname, &sunit, &ft->rtswidth, + blkid_get_topology(xi->rt.name, &sunit, &ft->rtswidth, &lsectorsize, &psectorsize, force_overwrite); } } diff --git a/logprint/logprint.c b/logprint/logprint.c index 5349e7838..7c69cdcc7 100644 --- a/logprint/logprint.c +++ b/logprint/logprint.c @@ -64,9 +64,9 @@ logstat( * filesystem. We need this to get the length of the * log. Otherwise we end up seeking forever. -- mkp */ - if ((fd = open(x.dname, O_RDONLY)) == -1) { + if ((fd = open(x.data.name, O_RDONLY)) == -1) { fprintf(stderr, _(" Can't open device %s: %s\n"), - x.dname, strerror(errno)); + x.data.name, strerror(errno)); exit(1); } lseek(fd, 0, SEEK_SET); @@ -76,7 +76,7 @@ logstat( } close (fd); - if (!x.disfile) { + if (!x.data.isfile) { struct xfs_sb *sb = &mp->m_sb; /* @@ -88,7 +88,7 @@ logstat( xlog_init(mp, log); - if (!x.logname && sb->sb_logstart == 0) { + if (!x.log.name && sb->sb_logstart == 0) { fprintf(stderr, _(" external log device not specified\n\n")); usage(); /*NOTREACHED*/ @@ -96,7 +96,7 @@ logstat( } else { struct stat s; - stat(x.dname, &s); + stat(x.data.name, &s); log->l_logBBsize = s.st_size >> 9; log->l_logBBstart = 0; @@ -105,15 +105,15 @@ logstat( log->l_mp = mp; } - if (x.logname && *x.logname) { /* External log */ - if ((fd = open(x.logname, O_RDONLY)) == -1) { + if (x.log.name && *x.log.name) { /* External log */ + if ((fd = open(x.log.name, O_RDONLY)) == -1) { fprintf(stderr, _("Can't open file %s: %s\n"), - x.logname, strerror(errno)); + x.log.name, strerror(errno)); exit(1); } close(fd); } else { /* Internal log */ - x.logdev = x.ddev; + x.log.dev = x.data.dev; } return 0; @@ -165,11 +165,11 @@ main(int argc, char **argv) break; case 'f': print_skip_uuid++; - x.disfile = 1; + x.data.isfile = 1; break; case 'l': - x.logname = optarg; - x.lisfile = 1; + x.log.name = optarg; + x.log.isfile = 1; break; case 'i': print_inode++; @@ -203,9 +203,9 @@ main(int argc, char **argv) if (argc - optind != 1) usage(); - x.dname = argv[optind]; + x.data.name = argv[optind]; - if (x.dname == NULL) + if (x.data.name == NULL) usage(); x.flags = LIBXFS_ISINACTIVE; @@ -216,20 +216,20 @@ main(int argc, char **argv) libxfs_buftarg_init(&mount, &x); logstat(&mount, &log); - logfd = (x.logfd < 0) ? x.dfd : x.logfd; + logfd = (x.log.fd < 0) ? x.data.fd : x.log.fd; - printf(_(" data device: 0x%llx\n"), (unsigned long long)x.ddev); + printf(_(" data device: 0x%llx\n"), (unsigned long long)x.data.dev); - if (x.logname) { - printf(_(" log file: \"%s\" "), x.logname); + if (x.log.name) { + printf(_(" log file: \"%s\" "), x.log.name); } else { - printf(_(" log device: 0x%llx "), (unsigned long long)x.logdev); + printf(_(" log device: 0x%llx "), (unsigned long long)x.log.dev); } printf(_("daddr: %lld length: %lld\n\n"), (long long)log.l_logBBstart, (long long)log.l_logBBsize); - ASSERT(log.l_logBBsize <= INT_MAX); + ASSERT(x.log.size <= INT_MAX); switch (print_operation) { case OP_PRINT: diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index 01c6ce33b..fcbf54132 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -1092,37 +1092,35 @@ invalid_cfgfile_opt( static void check_device_type( - const char *name, - int *isfile, - bool no_size, - bool no_name, - int *create, - const char *optname) + struct libxfs_dev *dev, + bool no_size, + bool dry_run, + const char *optname) { struct stat statbuf; - if (*isfile && (no_size || no_name)) { + if (dev->isfile && (no_size || !dev->name)) { fprintf(stderr, _("if -%s file then -%s name and -%s size are required\n"), optname, optname, optname); usage(); } - if (!name) { + if (!dev->name) { fprintf(stderr, _("No device name specified\n")); usage(); } - if (stat(name, &statbuf)) { - if (errno == ENOENT && *isfile) { - if (create) - *create = 1; + if (stat(dev->name, &statbuf)) { + if (errno == ENOENT && dev->isfile) { + if (!dry_run) + dev->create = 1; return; } fprintf(stderr, _("Error accessing specified device %s: %s\n"), - name, strerror(errno)); + dev->name, strerror(errno)); usage(); return; } @@ -1133,18 +1131,18 @@ check_device_type( * this case to trigger that behaviour. */ if (S_ISREG(statbuf.st_mode)) { - if (!*isfile) - *isfile = 1; - else if (create) - *create = 1; + if (!dev->isfile) + dev->isfile = 1; + else if (!dry_run) + dev->create = 1; return; } if (S_ISBLK(statbuf.st_mode)) { - if (*isfile) { + if (dev->isfile) { fprintf(stderr, _("specified \"-%s file\" on a block device %s\n"), - optname, name); + optname, dev->name); usage(); } return; @@ -1152,7 +1150,7 @@ check_device_type( fprintf(stderr, _("specified device %s not a file or block device\n"), - name); + dev->name); usage(); } @@ -1258,7 +1256,7 @@ zero_old_xfs_structures( /* * We open regular files with O_TRUNC|O_CREAT. Nothing to do here... */ - if (xi->disfile && xi->dcreat) + if (xi->data.isfile && xi->data.create) return; /* @@ -1279,9 +1277,9 @@ zero_old_xfs_structures( * return zero bytes. It's not a failure we need to warn about in this * case. */ - off = pread(xi->dfd, buf, new_sb->sb_sectsize, 0); + off = pread(xi->data.fd, buf, new_sb->sb_sectsize, 0); if (off != new_sb->sb_sectsize) { - if (!xi->disfile) + if (!xi->data.isfile) fprintf(stderr, _("error reading existing superblock: %s\n"), strerror(errno)); @@ -1316,7 +1314,7 @@ zero_old_xfs_structures( off = 0; for (i = 1; i < sb.sb_agcount; i++) { off += sb.sb_agblocks; - if (pwrite(xi->dfd, buf, new_sb->sb_sectsize, + if (pwrite(xi->data.fd, buf, new_sb->sb_sectsize, off << sb.sb_blocklog) == -1) break; } @@ -1561,10 +1559,10 @@ data_opts_parser( cli->agsize = getstr(value, opts, subopt); break; case D_FILE: - cli->xi->disfile = getnum(value, opts, subopt); + cli->xi->data.isfile = getnum(value, opts, subopt); break; case D_NAME: - cli->xi->dname = getstr(value, opts, subopt); + cli->xi->data.name = getstr(value, opts, subopt); break; case D_SIZE: cli->dsize = getstr(value, opts, subopt); @@ -1673,7 +1671,7 @@ log_opts_parser( cli->logagno = getnum(value, opts, subopt); break; case L_FILE: - cli->xi->lisfile = getnum(value, opts, subopt); + cli->xi->log.isfile = getnum(value, opts, subopt); break; case L_INTERNAL: cli->loginternal = getnum(value, opts, subopt); @@ -1686,7 +1684,7 @@ log_opts_parser( break; case L_NAME: case L_DEV: - cli->xi->logname = getstr(value, opts, subopt); + cli->xi->log.name = getstr(value, opts, subopt); cli->loginternal = 0; break; case L_VERSION: @@ -1819,11 +1817,11 @@ rtdev_opts_parser( cli->rtextsize = getstr(value, opts, subopt); break; case R_FILE: - cli->xi->risfile = getnum(value, opts, subopt); + cli->xi->rt.isfile = getnum(value, opts, subopt); break; case R_NAME: case R_DEV: - cli->xi->rtname = getstr(value, opts, subopt); + cli->xi->rt.name = getstr(value, opts, subopt); break; case R_SIZE: cli->rtsize = getstr(value, opts, subopt); @@ -1962,24 +1960,18 @@ validate_sectorsize( * Before anything else, verify that we are correctly operating on * files or block devices and set the control parameters correctly. */ - check_device_type(cli->xi->dname, &cli->xi->disfile, - !cli->dsize, !cli->xi->dname, - dry_run ? NULL : &cli->xi->dcreat, "d"); + check_device_type(&cli->xi->data, !cli->dsize, dry_run, "d"); if (!cli->loginternal) - check_device_type(cli->xi->logname, &cli->xi->lisfile, - !cli->logsize, !cli->xi->logname, - dry_run ? NULL : &cli->xi->lcreat, "l"); - if (cli->xi->rtname) - check_device_type(cli->xi->rtname, &cli->xi->risfile, - !cli->rtsize, !cli->xi->rtname, - dry_run ? NULL : &cli->xi->rcreat, "r"); + check_device_type(&cli->xi->log, !cli->logsize, dry_run, "l"); + if (cli->xi->rt.name) + check_device_type(&cli->xi->rt, !cli->rtsize, dry_run, "r"); /* * Explicitly disable direct IO for image files so we don't error out on * sector size mismatches between the new filesystem and the underlying * host filesystem. */ - if (cli->xi->disfile || cli->xi->lisfile || cli->xi->risfile) + if (cli->xi->data.isfile || cli->xi->log.isfile || cli->xi->rt.isfile) cli->xi->flags &= ~LIBXFS_DIRECT; memset(ft, 0, sizeof(*ft)); @@ -2294,7 +2286,7 @@ _("inode btree counters not supported without finobt support\n")); cli->sb_feat.inobtcnt = false; } - if (cli->xi->rtname) { + if (cli->xi->rt.name) { if (cli->sb_feat.reflink && cli_opt_set(&mopts, M_REFLINK)) { fprintf(stderr, _("reflink not supported with realtime devices\n")); @@ -2461,8 +2453,8 @@ validate_rtextsize( */ uint64_t rswidth; - if (!cfg->sb_feat.nortalign && !cli->xi->risfile && - !(!cli->rtsize && cli->xi->disfile)) + if (!cfg->sb_feat.nortalign && !cli->xi->rt.isfile && + !(!cli->rtsize && cli->xi->data.isfile)) rswidth = ft->rtswidth; else rswidth = 0; @@ -2840,7 +2832,7 @@ open_devices( xi->setblksize = cfg->sectorsize; if (!libxfs_init(xi)) usage(); - if (!xi->ddev) { + if (!xi->data.dev) { fprintf(stderr, _("no device name given in argument list\n")); usage(); } @@ -2856,9 +2848,9 @@ open_devices( * multiple of the sector size, or 1024, whichever is larger. */ sector_mask = (uint64_t)-1 << (max(cfg->sectorlog, 10) - BBSHIFT); - xi->dsize &= sector_mask; - xi->rtsize &= sector_mask; - xi->logBBsize &= (uint64_t)-1 << (max(cfg->lsectorlog, 10) - BBSHIFT); + xi->data.size &= sector_mask; + xi->rt.size &= sector_mask; + xi->log.size &= (uint64_t)-1 << (max(cfg->lsectorlog, 10) - BBSHIFT); } static void @@ -2870,12 +2862,12 @@ discard_devices( * This function has to be called after libxfs has been initialized. */ - if (!xi->disfile) - discard_blocks(xi->dfd, xi->dsize, quiet); - if (xi->rtdev && !xi->risfile) - discard_blocks(xi->rtfd, xi->rtsize, quiet); - if (xi->logdev && xi->logdev != xi->ddev && !xi->lisfile) - discard_blocks(xi->logfd, xi->logBBsize, quiet); + if (!xi->data.isfile) + discard_blocks(xi->data.fd, xi->data.size, quiet); + if (xi->rt.dev && !xi->rt.isfile) + discard_blocks(xi->rt.fd, xi->rt.size, quiet); + if (xi->log.dev && xi->log.dev != xi->data.dev && !xi->log.isfile) + discard_blocks(xi->log.fd, xi->log.size, quiet); } static void @@ -2885,29 +2877,29 @@ validate_datadev( { struct libxfs_init *xi = cli->xi; - if (!xi->dsize) { + if (!xi->data.size) { /* * if the device is a file, we can't validate the size here. * Instead, the file will be truncated to the correct length * later on. if it's not a file, we've got a dud device. */ - if (!xi->disfile) { + if (!xi->data.isfile) { fprintf(stderr, _("can't get size of data subvolume\n")); usage(); } ASSERT(cfg->dblocks); } else if (cfg->dblocks) { /* check the size fits into the underlying device */ - if (cfg->dblocks > DTOBT(xi->dsize, cfg->blocklog)) { + if (cfg->dblocks > DTOBT(xi->data.size, cfg->blocklog)) { fprintf(stderr, _("size %s specified for data subvolume is too large, maximum is %lld blocks\n"), cli->dsize, - (long long)DTOBT(xi->dsize, cfg->blocklog)); + (long long)DTOBT(xi->data.size, cfg->blocklog)); usage(); } } else { /* no user size, so use the full block device */ - cfg->dblocks = DTOBT(xi->dsize, cfg->blocklog); + cfg->dblocks = DTOBT(xi->data.size, cfg->blocklog); } if (cfg->dblocks < XFS_MIN_DATA_BLOCKS(cfg)) { @@ -2917,11 +2909,11 @@ _("size %lld of data subvolume is too small, minimum %lld blocks\n"), usage(); } - if (xi->dbsize > cfg->sectorsize) { + if (xi->data.bsize > cfg->sectorsize) { fprintf(stderr, _( "Warning: the data subvolume sector size %u is less than the sector size \n\ reported by the device (%u).\n"), - cfg->sectorsize, xi->dbsize); + cfg->sectorsize, xi->data.bsize); } } @@ -2961,31 +2953,31 @@ _("log size %lld too large for internal log\n"), } /* External/log subvolume checks */ - if (!*xi->logname || !xi->logdev) { + if (!*xi->log.name || !xi->log.dev) { fprintf(stderr, _("no log subvolume or external log.\n")); usage(); } if (!cfg->logblocks) { - if (xi->logBBsize == 0) { + if (xi->log.size == 0) { fprintf(stderr, _("unable to get size of the log subvolume.\n")); usage(); } - cfg->logblocks = DTOBT(xi->logBBsize, cfg->blocklog); - } else if (cfg->logblocks > DTOBT(xi->logBBsize, cfg->blocklog)) { + cfg->logblocks = DTOBT(xi->log.size, cfg->blocklog); + } else if (cfg->logblocks > DTOBT(xi->log.size, cfg->blocklog)) { fprintf(stderr, _("size %s specified for log subvolume is too large, maximum is %lld blocks\n"), cli->logsize, - (long long)DTOBT(xi->logBBsize, cfg->blocklog)); + (long long)DTOBT(xi->log.size, cfg->blocklog)); usage(); } - if (xi->lbsize > cfg->lsectorsize) { + if (xi->log.bsize > cfg->lsectorsize) { fprintf(stderr, _( "Warning: the log subvolume sector size %u is less than the sector size\n\ reported by the device (%u).\n"), - cfg->lsectorsize, xi->lbsize); + cfg->lsectorsize, xi->log.bsize); } } @@ -2996,7 +2988,7 @@ validate_rtdev( { struct libxfs_init *xi = cli->xi; - if (!xi->rtdev) { + if (!xi->rt.dev) { if (cli->rtsize) { fprintf(stderr, _("size specified for non-existent rt subvolume\n")); @@ -3008,28 +3000,28 @@ _("size specified for non-existent rt subvolume\n")); cfg->rtbmblocks = 0; return; } - if (!xi->rtsize) { + if (!xi->rt.size) { fprintf(stderr, _("Invalid zero length rt subvolume found\n")); usage(); } if (cli->rtsize) { - if (cfg->rtblocks > DTOBT(xi->rtsize, cfg->blocklog)) { + if (cfg->rtblocks > DTOBT(xi->rt.size, cfg->blocklog)) { fprintf(stderr, _("size %s specified for rt subvolume is too large, maxi->um is %lld blocks\n"), cli->rtsize, - (long long)DTOBT(xi->rtsize, cfg->blocklog)); + (long long)DTOBT(xi->rt.size, cfg->blocklog)); usage(); } - if (xi->rtbsize > cfg->sectorsize) { + if (xi->rt.bsize > cfg->sectorsize) { fprintf(stderr, _( "Warning: the realtime subvolume sector size %u is less than the sector size\n\ reported by the device (%u).\n"), - cfg->sectorsize, xi->rtbsize); + cfg->sectorsize, xi->rt.bsize); } } else { /* grab volume size */ - cfg->rtblocks = DTOBT(xi->rtsize, cfg->blocklog); + cfg->rtblocks = DTOBT(xi->rt.size, cfg->blocklog); } cfg->rtextents = cfg->rtblocks / cfg->rtextblocks; @@ -3770,9 +3762,9 @@ prepare_devices( * needed so that the reads for the end of the device in the mount code * will succeed. */ - if (xi->disfile && - xi->dsize * xi->dbsize < cfg->dblocks * cfg->blocksize) { - if (ftruncate(xi->dfd, cfg->dblocks * cfg->blocksize) < 0) { + if (xi->data.isfile && + xi->data.size * xi->data.bsize < cfg->dblocks * cfg->blocksize) { + if (ftruncate(xi->data.fd, cfg->dblocks * cfg->blocksize) < 0) { fprintf(stderr, _("%s: Growing the data section failed\n"), progname); @@ -3780,7 +3772,7 @@ prepare_devices( } /* update size to be able to whack blocks correctly */ - xi->dsize = BTOBB(cfg->dblocks * cfg->blocksize); + xi->data.size = BTOBB(cfg->dblocks * cfg->blocksize); } /* @@ -3788,7 +3780,7 @@ prepare_devices( * the end of the device. (MD sb is ~64k from the end, take out a wider * swath to be sure) */ - buf = alloc_write_buf(mp->m_ddev_targp, (xi->dsize - whack_blks), + buf = alloc_write_buf(mp->m_ddev_targp, (xi->data.size - whack_blks), whack_blks); memset(buf->b_addr, 0, WHACK_SIZE); libxfs_buf_mark_dirty(buf); @@ -4183,7 +4175,7 @@ main( fprintf(stderr, _("extra arguments\n")); usage(); } else if (argc - optind == 1) { - xi.dname = getstr(argv[optind], &dopts, D_NAME); + xi.data.name = getstr(argv[optind], &dopts, D_NAME); } /* @@ -4236,7 +4228,7 @@ main( * Open and validate the device configurations */ open_devices(&cfg, &xi); - validate_overwrite(xi.dname, force_overwrite); + validate_overwrite(xi.data.name, force_overwrite); validate_datadev(&cfg, &cli); validate_logdev(&cfg, &cli); validate_rtdev(&cfg, &cli); @@ -4280,7 +4272,7 @@ main( struct xfs_fsop_geom geo; libxfs_fs_geometry(mp, &geo, XFS_FS_GEOM_MAX_STRUCT_VER); - xfs_report_geom(&geo, xi.dname, xi.logname, xi.rtname); + xfs_report_geom(&geo, xi.data.name, xi.log.name, xi.rt.name); if (dry_run) exit(0); } diff --git a/repair/init.c b/repair/init.c index 2dc439a22..3788d00f2 100644 --- a/repair/init.c +++ b/repair/init.c @@ -56,19 +56,19 @@ xfs_init(struct libxfs_init *args) { memset(args, 0, sizeof(*args)); - args->dname = fs_name; - args->disfile = isa_file; + args->data.name = fs_name; + args->data.isfile = isa_file; if (log_spec) { /* External log specified */ - args->logname = log_name; - args->lisfile = (isa_file?1:0); + args->log.name = log_name; + args->log.isfile = isa_file; /* XXX assume data file also means log file */ /* REVISIT: Need to do fs sanity / log validity checking */ } if (rt_spec) { /* RT device specified */ - args->rtname = rt_name; - args->risfile = (isa_file?1:0); + args->rt.name = rt_name; + args->rt.isfile = isa_file; /* XXX assume data file also means rt file */ } diff --git a/repair/phase2.c b/repair/phase2.c index 48263e161..063748179 100644 --- a/repair/phase2.c +++ b/repair/phase2.c @@ -341,11 +341,11 @@ phase2( /* Check whether this fs has internal or external log */ if (mp->m_sb.sb_logstart == 0) { - if (!x.logname) + if (!x.log.name) do_error(_("This filesystem has an external log. " "Specify log device with the -l option.\n")); - do_log(_("Phase 2 - using external log on %s\n"), x.logname); + do_log(_("Phase 2 - using external log on %s\n"), x.log.name); } else do_log(_("Phase 2 - using internal log\n")); diff --git a/repair/sb.c b/repair/sb.c index b823ba3a9..dedac53af 100644 --- a/repair/sb.c +++ b/repair/sb.c @@ -125,13 +125,11 @@ __find_secondary_sb( /* * read disk 1 MByte at a time. */ - if (lseek(x.dfd, off, SEEK_SET) != off) { + if (lseek(x.data.fd, off, SEEK_SET) != off) done = 1; - } - if (!done && (bsize = read(x.dfd, sb, BSIZE)) <= 0) { + if (!done && (bsize = read(x.data.fd, sb, BSIZE)) <= 0) done = 1; - } do_warn("."); @@ -192,7 +190,7 @@ guess_default_geometry( */ blocklog = 12; multidisk = ft.dswidth | ft.dsunit; - dblocks = x->dsize >> (blocklog - BBSHIFT); + dblocks = x->data.size >> (blocklog - BBSHIFT); calc_default_ag_geometry(blocklog, dblocks, multidisk, agsize, agcount); @@ -533,7 +531,7 @@ write_primary_sb(xfs_sb_t *sbp, int size) } memset(buf, 0, size); - if (lseek(x.dfd, 0LL, SEEK_SET) != 0LL) { + if (lseek(x.data.fd, 0LL, SEEK_SET) != 0LL) { free(buf); do_error(_("couldn't seek to offset 0 in filesystem\n")); } @@ -543,7 +541,7 @@ write_primary_sb(xfs_sb_t *sbp, int size) if (xfs_sb_version_hascrc(sbp)) xfs_update_cksum((char *)buf, size, XFS_SB_CRC_OFF); - if (write(x.dfd, buf, size) != size) { + if (write(x.data.fd, buf, size) != size) { free(buf); do_error(_("primary superblock write failed!\n")); } @@ -572,7 +570,7 @@ get_sb(xfs_sb_t *sbp, xfs_off_t off, int size, xfs_agnumber_t agno) /* try and read it first */ - if (lseek(x.dfd, off, SEEK_SET) != off) { + if (lseek(x.data.fd, off, SEEK_SET) != off) { do_warn( _("error reading superblock %u -- seek to offset %" PRId64 " failed\n"), agno, off); @@ -580,7 +578,7 @@ get_sb(xfs_sb_t *sbp, xfs_off_t off, int size, xfs_agnumber_t agno) return(XR_EOF); } - if ((rval = read(x.dfd, buf, size)) != size) { + if ((rval = read(x.data.fd, buf, size)) != size) { error = errno; do_warn( _("superblock read failed, offset %" PRId64 ", size %d, ag %u, rval %d\n"), diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c index cdbdbe855..ba9d28330 100644 --- a/repair/xfs_repair.c +++ b/repair/xfs_repair.c @@ -728,7 +728,7 @@ check_fs_vs_host_sectsize( long old_flags; struct xfs_fsop_geom geom = { 0 }; - ret = -xfrog_geometry(x.dfd, &geom); + ret = -xfrog_geometry(x.data.fd, &geom); if (ret) { do_log(_("Cannot get host filesystem geometry.\n" "Repair may fail if there is a sector size mismatch between\n" @@ -737,8 +737,8 @@ check_fs_vs_host_sectsize( } if (sb->sb_sectsize < geom.sectsize) { - old_flags = fcntl(x.dfd, F_GETFL, 0); - if (fcntl(x.dfd, F_SETFL, old_flags & ~O_DIRECT) < 0) { + old_flags = fcntl(x.data.fd, F_GETFL, 0); + if (fcntl(x.data.fd, F_SETFL, old_flags & ~O_DIRECT) < 0) { do_warn(_( "Sector size on host filesystem larger than image sector size.\n" "Cannot turn off direct IO, so exiting.\n")); @@ -986,7 +986,7 @@ main(int argc, char **argv) if (!isa_file) { struct stat statbuf; - if (fstat(x.dfd, &statbuf) < 0) + if (fstat(x.data.fd, &statbuf) < 0) do_warn(_("%s: couldn't stat \"%s\"\n"), progname, fs_name); else if (S_ISREG(statbuf.st_mode))