* [PATCH 1/6] libfrog: refactor online geometry queries
2019-06-07 19:28 [PATCH v2 0/6] xfsprogs-5.1: fix various problems Darrick J. Wong
@ 2019-06-07 19:28 ` Darrick J. Wong
2019-06-07 19:28 ` [PATCH 2/6] libxfs: refactor open-coded bulkstat calls Darrick J. Wong
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2019-06-07 19:28 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
Refactor all the open-coded XFS_IOC_FSGEOMETRY queries into a single
helper that we can use to standardize behaviors across mixed xfslibs
versions. This is the prelude to introducing a new FSGEOMETRY version
in 5.2 and needing to fix the (relatively few) client programs.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
Makefile | 1 +
fsr/xfs_fsr.c | 26 ++++----------------------
growfs/xfs_growfs.c | 25 +++++++++----------------
include/xfrog.h | 22 ++++++++++++++++++++++
io/bmap.c | 3 ++-
io/fsmap.c | 3 ++-
io/open.c | 3 ++-
io/stat.c | 5 +++--
libfrog/fsgeom.c | 18 ++++++++++++++++++
quota/free.c | 6 +++---
repair/xfs_repair.c | 5 +++--
rtcp/Makefile | 3 +++
rtcp/xfs_rtcp.c | 7 ++++---
scrub/phase1.c | 3 ++-
spaceman/file.c | 3 ++-
spaceman/info.c | 25 ++++++++-----------------
16 files changed, 88 insertions(+), 70 deletions(-)
create mode 100644 include/xfrog.h
diff --git a/Makefile b/Makefile
index 9204bed8..0edc2700 100644
--- a/Makefile
+++ b/Makefile
@@ -107,6 +107,7 @@ copy: libxlog
mkfs: libxcmd
spaceman: libxcmd
scrub: libhandle libxcmd
+rtcp: libfrog
ifeq ($(HAVE_BUILDDEFS), yes)
include $(BUILDRULES)
diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index fef6262c..0bfecf37 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -11,6 +11,7 @@
#include "xfs_bmap_btree.h"
#include "xfs_attr_sf.h"
#include "path.h"
+#include "xfrog.h"
#include <fcntl.h>
#include <errno.h>
@@ -83,9 +84,8 @@ int cmp(const void *, const void *);
static void tmp_init(char *mnt);
static char * tmp_next(char *mnt);
static void tmp_close(char *mnt);
-int xfs_getgeom(int , xfs_fsop_geom_v1_t * );
-static xfs_fsop_geom_v1_t fsgeom; /* geometry of active mounted system */
+static struct xfs_fsop_geom fsgeom; /* geometry of active mounted system */
#define NMOUNT 64
static int numfs;
@@ -102,12 +102,6 @@ static int nfrags = 0; /* Debug option: Coerse into specific number
* of extents */
static int openopts = O_CREAT|O_EXCL|O_RDWR|O_DIRECT;
-static int
-xfs_fsgeometry(int fd, xfs_fsop_geom_v1_t *geom)
-{
- return ioctl(fd, XFS_IOC_FSGEOMETRY_V1, geom);
-}
-
static int
xfs_bulkstat_single(int fd, xfs_ino_t *lastip, xfs_bstat_t *ubuffer)
{
@@ -630,7 +624,7 @@ fsrfs(char *mntdir, xfs_ino_t startino, int targetrange)
return -1;
}
- if (xfs_getgeom(fsfd, &fsgeom) < 0 ) {
+ if (xfrog_geometry(fsfd, &fsgeom) < 0 ) {
fsrprintf(_("Skipping %s: could not get XFS geometry\n"),
mntdir);
close(fsfd);
@@ -772,7 +766,7 @@ fsrfile(char *fname, xfs_ino_t ino)
}
/* Get the fs geometry */
- if (xfs_getgeom(fsfd, &fsgeom) < 0 ) {
+ if (xfrog_geometry(fsfd, &fsgeom) < 0 ) {
fsrprintf(_("Unable to get geom on fs for: %s\n"), fname);
goto out;
}
@@ -1612,18 +1606,6 @@ getnextents(int fd)
return(nextents);
}
-/*
- * Get the fs geometry
- */
-int
-xfs_getgeom(int fd, xfs_fsop_geom_v1_t * fsgeom)
-{
- if (xfs_fsgeometry(fd, fsgeom) < 0) {
- return -1;
- }
- return 0;
-}
-
/*
* Get xfs realtime space information
*/
diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c
index 20089d2b..28dd6d84 100644
--- a/growfs/xfs_growfs.c
+++ b/growfs/xfs_growfs.c
@@ -7,6 +7,7 @@
#include "libxfs.h"
#include "path.h"
#include "fsgeom.h"
+#include "xfrog.h"
static void
usage(void)
@@ -165,22 +166,14 @@ main(int argc, char **argv)
}
/* get the current filesystem size & geometry */
- if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY, &geo) < 0) {
- /*
- * OK, new xfsctl barfed - back off and try earlier version
- * as we're probably running an older kernel version.
- * Only field added in the v2 geometry xfsctl is "logsunit"
- * so we'll zero that out for later display (as zero).
- */
- geo.logsunit = 0;
- if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY_V1, &geo) < 0) {
- fprintf(stderr, _(
- "%s: cannot determine geometry of filesystem"
- " mounted at %s: %s\n"),
- progname, fname, strerror(errno));
- exit(1);
- }
+ if (xfrog_geometry(ffd, &geo)) {
+ fprintf(stderr, _(
+ "%s: cannot determine geometry of filesystem"
+ " mounted at %s: %s\n"),
+ progname, fname, strerror(errno));
+ exit(1);
}
+
isint = geo.logstart > 0;
/*
@@ -359,7 +352,7 @@ main(int argc, char **argv)
}
}
- if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY_V1, &ngeo) < 0) {
+ if (xfrog_geometry(ffd, &ngeo)) {
fprintf(stderr, _("%s: XFS_IOC_FSGEOMETRY xfsctl failed: %s\n"),
progname, strerror(errno));
exit(1);
diff --git a/include/xfrog.h b/include/xfrog.h
new file mode 100644
index 00000000..b683cf63
--- /dev/null
+++ b/include/xfrog.h
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2000-2002 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ */
+#ifndef __XFROG_H__
+#define __XFROG_H__
+
+/*
+ * XFS Filesystem Runtime Online Gluecode
+ * ======================================
+ *
+ * These support functions wrap the more complex xfs ioctls so that xfs
+ * utilities can take advantage of them without having to deal with graceful
+ * degradation in the face of new ioctls. They will also provide higher level
+ * abstractions when possible.
+ */
+
+struct xfs_fsop_geom;
+int xfrog_geometry(int fd, struct xfs_fsop_geom *fsgeo);
+
+#endif /* __XFROG_H__ */
diff --git a/io/bmap.c b/io/bmap.c
index d408826a..5f0d12ca 100644
--- a/io/bmap.c
+++ b/io/bmap.c
@@ -9,6 +9,7 @@
#include "input.h"
#include "init.h"
#include "io.h"
+#include "xfrog.h"
static cmdinfo_t bmap_cmd;
@@ -105,7 +106,7 @@ bmap_f(
bmv_iflags &= ~(BMV_IF_PREALLOC|BMV_IF_NO_DMAPI_READ);
if (vflag) {
- c = xfsctl(file->name, file->fd, XFS_IOC_FSGEOMETRY_V1, &fsgeo);
+ c = xfrog_geometry(file->fd, &fsgeo);
if (c < 0) {
fprintf(stderr,
_("%s: can't get geometry [\"%s\"]: %s\n"),
diff --git a/io/fsmap.c b/io/fsmap.c
index 477c36fc..d3ff7dea 100644
--- a/io/fsmap.c
+++ b/io/fsmap.c
@@ -9,6 +9,7 @@
#include "path.h"
#include "io.h"
#include "input.h"
+#include "xfrog.h"
static cmdinfo_t fsmap_cmd;
static dev_t xfs_data_dev;
@@ -447,7 +448,7 @@ fsmap_f(
}
if (vflag) {
- c = ioctl(file->fd, XFS_IOC_FSGEOMETRY, &fsgeo);
+ c = xfrog_geometry(file->fd, &fsgeo);
if (c < 0) {
fprintf(stderr,
_("%s: can't get geometry [\"%s\"]: %s\n"),
diff --git a/io/open.c b/io/open.c
index c7f5248a..997df119 100644
--- a/io/open.c
+++ b/io/open.c
@@ -9,6 +9,7 @@
#include "init.h"
#include "io.h"
#include "libxfs.h"
+#include "xfrog.h"
#ifndef __O_TMPFILE
#if defined __alpha__
@@ -118,7 +119,7 @@ openfile(
if (flags & IO_PATH) {
/* Can't call ioctl() on O_PATH fds */
memset(geom, 0, sizeof(*geom));
- } else if (xfsctl(path, fd, XFS_IOC_FSGEOMETRY, geom) < 0) {
+ } else if (xfrog_geometry(fd, geom)) {
perror("XFS_IOC_FSGEOMETRY");
close(fd);
return -1;
diff --git a/io/stat.c b/io/stat.c
index 37c0b2e8..26b4eb68 100644
--- a/io/stat.c
+++ b/io/stat.c
@@ -12,6 +12,7 @@
#include "io.h"
#include "statx.h"
#include "libxfs.h"
+#include "xfrog.h"
#include <fcntl.h>
@@ -194,8 +195,8 @@ statfs_f(
}
if (file->flags & IO_FOREIGN)
return 0;
- if ((xfsctl(file->name, file->fd, XFS_IOC_FSGEOMETRY_V1, &fsgeo)) < 0) {
- perror("XFS_IOC_FSGEOMETRY_V1");
+ if (xfrog_geometry(file->fd, &fsgeo)) {
+ perror("XFS_IOC_FSGEOMETRY");
} else {
printf(_("geom.bsize = %u\n"), fsgeo.blocksize);
printf(_("geom.agcount = %u\n"), fsgeo.agcount);
diff --git a/libfrog/fsgeom.c b/libfrog/fsgeom.c
index 8879d161..a6dab3a8 100644
--- a/libfrog/fsgeom.c
+++ b/libfrog/fsgeom.c
@@ -4,6 +4,7 @@
*/
#include "libxfs.h"
#include "fsgeom.h"
+#include "xfrog.h"
void
xfs_report_geom(
@@ -67,3 +68,20 @@ xfs_report_geom(
geo->rtextsize * geo->blocksize, (unsigned long long)geo->rtblocks,
(unsigned long long)geo->rtextents);
}
+
+/* Try to obtain the xfs geometry. */
+int
+xfrog_geometry(
+ int fd,
+ struct xfs_fsop_geom *fsgeo)
+{
+ int ret;
+
+ memset(fsgeo, 0, sizeof(*fsgeo));
+
+ ret = ioctl(fd, XFS_IOC_FSGEOMETRY, fsgeo);
+ if (!ret)
+ return 0;
+
+ return ioctl(fd, XFS_IOC_FSGEOMETRY_V1, fsgeo);
+}
diff --git a/quota/free.c b/quota/free.c
index 1d13006e..f47001bf 100644
--- a/quota/free.c
+++ b/quota/free.c
@@ -8,6 +8,7 @@
#include "command.h"
#include "init.h"
#include "quota.h"
+#include "xfrog.h"
static cmdinfo_t free_cmd;
@@ -67,9 +68,8 @@ mount_free_space_data(
}
if (!(mount->fs_flags & FS_FOREIGN)) {
- if ((xfsctl(mount->fs_dir, fd, XFS_IOC_FSGEOMETRY_V1,
- &fsgeo)) < 0) {
- perror("XFS_IOC_FSGEOMETRY_V1");
+ if (xfrog_geometry(fd, &fsgeo)) {
+ perror("XFS_IOC_FSGEOMETRY");
close(fd);
return 0;
}
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index 9657503f..e6717d3c 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -22,6 +22,7 @@
#include "dinode.h"
#include "slab.h"
#include "rmap.h"
+#include "xfrog.h"
/*
* option tables for getsubopt calls
@@ -636,11 +637,11 @@ check_fs_vs_host_sectsize(
{
int fd;
long old_flags;
- struct xfs_fsop_geom_v1 geom = { 0 };
+ struct xfs_fsop_geom geom = { 0 };
fd = libxfs_device_to_fd(x.ddev);
- if (ioctl(fd, XFS_IOC_FSGEOMETRY_V1, &geom) < 0) {
+ if (xfrog_geometry(fd, &geom)) {
do_log(_("Cannot get host filesystem geometry.\n"
"Repair may fail if there is a sector size mismatch between\n"
"the image and the host filesystem.\n"));
diff --git a/rtcp/Makefile b/rtcp/Makefile
index 808b5378..264b4f27 100644
--- a/rtcp/Makefile
+++ b/rtcp/Makefile
@@ -9,6 +9,9 @@ LTCOMMAND = xfs_rtcp
CFILES = xfs_rtcp.c
LLDFLAGS = -static
+LLDLIBS = $(LIBFROG)
+LTDEPENDENCIES = $(LIBFROG)
+
default: depend $(LTCOMMAND)
include $(BUILDRULES)
diff --git a/rtcp/xfs_rtcp.c b/rtcp/xfs_rtcp.c
index f928a86a..0b37ee89 100644
--- a/rtcp/xfs_rtcp.c
+++ b/rtcp/xfs_rtcp.c
@@ -5,6 +5,7 @@
*/
#include "libxfs.h"
+#include "xfrog.h"
int rtcp(char *, char *, int);
int xfsrtextsize(char *path);
@@ -368,8 +369,8 @@ rtcp( char *source, char *target, int fextsize)
int
xfsrtextsize( char *path)
{
- int fd, rval, rtextsize;
- xfs_fsop_geom_v1_t geo;
+ struct xfs_fsop_geom geo;
+ int fd, rval, rtextsize;
fd = open( path, O_RDONLY );
if ( fd < 0 ) {
@@ -377,7 +378,7 @@ xfsrtextsize( char *path)
progname, path, strerror(errno));
return -1;
}
- rval = xfsctl( path, fd, XFS_IOC_FSGEOMETRY_V1, &geo );
+ rval = xfrog_geometry(fd, &geo);
close(fd);
if ( rval < 0 )
return -1;
diff --git a/scrub/phase1.c b/scrub/phase1.c
index 04a5f4a9..5ab2a4fe 100644
--- a/scrub/phase1.c
+++ b/scrub/phase1.c
@@ -26,6 +26,7 @@
#include "disk.h"
#include "scrub.h"
#include "repair.h"
+#include "xfrog.h"
/* Phase 1: Find filesystem geometry (and clean up after) */
@@ -129,7 +130,7 @@ _("Does not appear to be an XFS filesystem!"));
}
/* Retrieve XFS geometry. */
- error = ioctl(ctx->mnt_fd, XFS_IOC_FSGEOMETRY, &ctx->geo);
+ error = xfrog_geometry(ctx->mnt_fd, &ctx->geo);
if (error) {
str_errno(ctx, ctx->mntpoint);
return false;
diff --git a/spaceman/file.c b/spaceman/file.c
index 7e33e07e..690dd760 100644
--- a/spaceman/file.c
+++ b/spaceman/file.c
@@ -12,6 +12,7 @@
#include "init.h"
#include "path.h"
#include "space.h"
+#include "xfrog.h"
static cmdinfo_t print_cmd;
@@ -56,7 +57,7 @@ openfile(
return -1;
}
- if (ioctl(fd, XFS_IOC_FSGEOMETRY, geom) < 0) {
+ if (xfrog_geometry(fd, geom)) {
if (errno == ENOTTY)
fprintf(stderr,
_("%s: Not on a mounted XFS filesystem.\n"),
diff --git a/spaceman/info.c b/spaceman/info.c
index 01d0744a..714d715c 100644
--- a/spaceman/info.c
+++ b/spaceman/info.c
@@ -9,6 +9,7 @@
#include "path.h"
#include "space.h"
#include "fsgeom.h"
+#include "xfrog.h"
static void
info_help(void)
@@ -37,24 +38,14 @@ info_f(
}
/* get the current filesystem size & geometry */
- error = ioctl(file->fd, XFS_IOC_FSGEOMETRY, &geo);
+ error = xfrog_geometry(file->fd, &geo);
if (error) {
- /*
- * OK, new xfsctl barfed - back off and try earlier version
- * as we're probably running an older kernel version.
- * Only field added in the v2 geometry xfsctl is "logsunit"
- * so we'll zero that out for later display (as zero).
- */
- geo.logsunit = 0;
- error = ioctl(file->fd, XFS_IOC_FSGEOMETRY_V1, &geo);
- if (error) {
- fprintf(stderr, _(
- "%s: cannot determine geometry of filesystem"
- " mounted at %s: %s\n"),
- progname, file->name, strerror(errno));
- exitcode = 1;
- return 0;
- }
+ fprintf(stderr, _(
+ "%s: cannot determine geometry of filesystem"
+ " mounted at %s: %s\n"),
+ progname, file->name, strerror(errno));
+ exitcode = 1;
+ return 0;
}
xfs_report_geom(&geo, file->fs_path.fs_name, file->fs_path.fs_log,
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/6] libxfs: refactor open-coded bulkstat calls
2019-06-07 19:28 [PATCH v2 0/6] xfsprogs-5.1: fix various problems Darrick J. Wong
2019-06-07 19:28 ` [PATCH 1/6] libfrog: refactor online geometry queries Darrick J. Wong
@ 2019-06-07 19:28 ` Darrick J. Wong
2019-06-07 19:28 ` [PATCH 3/6] libxfs: refactor open-coded INUMBERS calls Darrick J. Wong
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2019-06-07 19:28 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
Refactor the BULKSTAT_SINGLE and BULKSTAT ioctl callsites into helper
functions.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
fsr/xfs_fsr.c | 37 ++++-------------------------
include/xfrog.h | 5 ++++
io/open.c | 66 ++++++++++++++++++++++++----------------------------
io/swapext.c | 18 ++------------
libfrog/Makefile | 1 +
libfrog/bulkstat.c | 43 ++++++++++++++++++++++++++++++++++
quota/quot.c | 17 +++++--------
scrub/inodes.c | 28 ++++++----------------
8 files changed, 101 insertions(+), 114 deletions(-)
create mode 100644 libfrog/bulkstat.c
diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index 0bfecf37..f35ead90 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -102,31 +102,6 @@ static int nfrags = 0; /* Debug option: Coerse into specific number
* of extents */
static int openopts = O_CREAT|O_EXCL|O_RDWR|O_DIRECT;
-static int
-xfs_bulkstat_single(int fd, xfs_ino_t *lastip, xfs_bstat_t *ubuffer)
-{
- xfs_fsop_bulkreq_t bulkreq;
-
- bulkreq.lastip = (__u64 *)lastip;
- bulkreq.icount = 1;
- bulkreq.ubuffer = ubuffer;
- bulkreq.ocount = NULL;
- return ioctl(fd, XFS_IOC_FSBULKSTAT_SINGLE, &bulkreq);
-}
-
-static int
-xfs_bulkstat(int fd, xfs_ino_t *lastip, int icount,
- xfs_bstat_t *ubuffer, __s32 *ocount)
-{
- xfs_fsop_bulkreq_t bulkreq;
-
- bulkreq.lastip = (__u64 *)lastip;
- bulkreq.icount = icount;
- bulkreq.ubuffer = ubuffer;
- bulkreq.ocount = ocount;
- return ioctl(fd, XFS_IOC_FSBULKSTAT, &bulkreq);
-}
-
static int
xfs_swapext(int fd, xfs_swapext_t *sx)
{
@@ -600,7 +575,7 @@ fsrfs(char *mntdir, xfs_ino_t startino, int targetrange)
int fsfd, fd;
int count = 0;
int ret;
- __s32 buflenout;
+ uint32_t buflenout;
xfs_bstat_t buf[GRABSZ];
char fname[64];
char *tname;
@@ -634,7 +609,7 @@ fsrfs(char *mntdir, xfs_ino_t startino, int targetrange)
tmp_init(mntdir);
- while ((ret = xfs_bulkstat(fsfd,
+ while ((ret = xfrog_bulkstat(fsfd,
&lastino, GRABSZ, &buf[0], &buflenout)) == 0) {
xfs_bstat_t *p;
xfs_bstat_t *endp;
@@ -690,7 +665,7 @@ fsrfs(char *mntdir, xfs_ino_t startino, int targetrange)
}
}
if (ret < 0)
- fsrprintf(_("%s: xfs_bulkstat: %s\n"), progname, strerror(errno));
+ fsrprintf(_("%s: xfrog_bulkstat: %s\n"), progname, strerror(errno));
out0:
tmp_close(mntdir);
close(fsfd);
@@ -752,7 +727,7 @@ fsrfile(char *fname, xfs_ino_t ino)
goto out;
}
- if ((xfs_bulkstat_single(fsfd, &ino, &statbuf)) < 0) {
+ if ((xfrog_bulkstat_single(fsfd, ino, &statbuf)) < 0) {
fsrprintf(_("unable to get bstat on %s: %s\n"),
fname, strerror(errno));
goto out;
@@ -981,7 +956,6 @@ fsr_setup_attr_fork(
i = 0;
do {
xfs_bstat_t tbstat;
- xfs_ino_t ino;
char name[64];
/*
@@ -989,8 +963,7 @@ fsr_setup_attr_fork(
* this to compare against the target and determine what we
* need to do.
*/
- ino = tstatbuf.st_ino;
- if ((xfs_bulkstat_single(tfd, &ino, &tbstat)) < 0) {
+ if ((xfrog_bulkstat_single(tfd, tstatbuf.st_ino, &tbstat)) < 0) {
fsrprintf(_("unable to get bstat on temp file: %s\n"),
strerror(errno));
return -1;
diff --git a/include/xfrog.h b/include/xfrog.h
index b683cf63..4b4e0adc 100644
--- a/include/xfrog.h
+++ b/include/xfrog.h
@@ -19,4 +19,9 @@
struct xfs_fsop_geom;
int xfrog_geometry(int fd, struct xfs_fsop_geom *fsgeo);
+struct xfs_bstat;
+int xfrog_bulkstat_single(int fd, uint64_t ino, struct xfs_bstat *ubuffer);
+int xfrog_bulkstat(int fd, uint64_t *lastino, uint32_t icount,
+ struct xfs_bstat *ubuffer, uint32_t *ocount);
+
#endif /* __XFROG_H__ */
diff --git a/io/open.c b/io/open.c
index 997df119..d97903e9 100644
--- a/io/open.c
+++ b/io/open.c
@@ -713,19 +713,18 @@ get_last_inode(void)
static int
inode_f(
- int argc,
- char **argv)
+ int argc,
+ char **argv)
{
- __s32 count = 0;
- __u64 result_ino = 0;
- __u64 userino = NULLFSINO;
+ struct xfs_bstat bstat;
+ uint32_t count = 0;
+ uint64_t result_ino = 0;
+ uint64_t userino = NULLFSINO;
char *p;
int c;
int verbose = 0;
int ret_next = 0;
- int cmd = 0;
- struct xfs_fsop_bulkreq bulkreq;
- struct xfs_bstat bstat;
+ int ret;
while ((c = getopt(argc, argv, "nv")) != EOF) {
switch (c) {
@@ -767,35 +766,32 @@ inode_f(
exitcode = 1;
return 0;
}
+ } else if (ret_next) {
+ /* get next inode */
+ ret = xfrog_bulkstat(file->fd, &userino, 1, &bstat, &count);
+ if (ret) {
+ perror("xfsctl");
+ exitcode = 1;
+ return 0;
+ }
+
+ /* The next inode in use, or 0 if none */
+ if (count)
+ result_ino = bstat.bs_ino;
+ else
+ result_ino = 0;
} else {
- if (ret_next) /* get next inode */
- cmd = XFS_IOC_FSBULKSTAT;
- else /* get this inode */
- cmd = XFS_IOC_FSBULKSTAT_SINGLE;
-
- bulkreq.lastip = &userino;
- bulkreq.icount = 1;
- bulkreq.ubuffer = &bstat;
- bulkreq.ocount = &count;
-
- if (xfsctl(file->name, file->fd, cmd, &bulkreq)) {
- if (!ret_next && errno == EINVAL) {
- /* Not in use */
- result_ino = 0;
- } else {
- perror("xfsctl");
- exitcode = 1;
- return 0;
- }
- } else if (ret_next) {
- /* The next inode in use, or 0 if none */
- if (*bulkreq.ocount)
- result_ino = bstat.bs_ino;
- else
- result_ino = 0;
+ /* get this inode */
+ ret = xfrog_bulkstat_single(file->fd, userino, &bstat);
+ if (ret && errno == EINVAL) {
+ /* Not in use */
+ result_ino = 0;
+ } else if (ret) {
+ perror("bulkstat_single");
+ exitcode = 1;
+ return 0;
} else {
- /* The inode we asked about */
- result_ino = userino;
+ result_ino = bstat.bs_ino;
}
}
diff --git a/io/swapext.c b/io/swapext.c
index d360c221..f5e6532f 100644
--- a/io/swapext.c
+++ b/io/swapext.c
@@ -8,6 +8,7 @@
#include "input.h"
#include "init.h"
#include "io.h"
+#include "xfrog.h"
static cmdinfo_t swapext_cmd;
@@ -20,21 +21,6 @@ swapext_help(void)
"\n"));
}
-static int
-xfs_bulkstat_single(
- int fd,
- xfs_ino_t *lastip,
- struct xfs_bstat *ubuffer)
-{
- struct xfs_fsop_bulkreq bulkreq;
-
- bulkreq.lastip = (__u64 *)lastip;
- bulkreq.icount = 1;
- bulkreq.ubuffer = ubuffer;
- bulkreq.ocount = NULL;
- return ioctl(fd, XFS_IOC_FSBULKSTAT_SINGLE, &bulkreq);
-}
-
static int
swapext_f(
int argc,
@@ -60,7 +46,7 @@ swapext_f(
goto out;
}
- error = xfs_bulkstat_single(file->fd, &stat.st_ino, &sx.sx_stat);
+ error = xfrog_bulkstat_single(file->fd, stat.st_ino, &sx.sx_stat);
if (error) {
perror("bulkstat");
goto out;
diff --git a/libfrog/Makefile b/libfrog/Makefile
index f5a0539b..05c6f701 100644
--- a/libfrog/Makefile
+++ b/libfrog/Makefile
@@ -13,6 +13,7 @@ LT_AGE = 0
CFILES = \
avl64.c \
bitmap.c \
+bulkstat.c \
convert.c \
crc32.c \
fsgeom.c \
diff --git a/libfrog/bulkstat.c b/libfrog/bulkstat.c
new file mode 100644
index 00000000..c0d3b627
--- /dev/null
+++ b/libfrog/bulkstat.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Oracle. All Rights Reserved.
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ */
+#include "xfs.h"
+
+/* Bulkstat a single inode. */
+int
+xfrog_bulkstat_single(
+ int fd,
+ uint64_t ino,
+ struct xfs_bstat *ubuffer)
+{
+ __u64 i = ino;
+ struct xfs_fsop_bulkreq bulkreq = {
+ .lastip = &i,
+ .icount = 1,
+ .ubuffer = ubuffer,
+ .ocount = NULL,
+ };
+
+ return ioctl(fd, XFS_IOC_FSBULKSTAT_SINGLE, &bulkreq);
+}
+
+/* Bulkstat a bunch of inodes. */
+int
+xfrog_bulkstat(
+ int fd,
+ uint64_t *lastino,
+ uint32_t icount,
+ struct xfs_bstat *ubuffer,
+ uint32_t *ocount)
+{
+ struct xfs_fsop_bulkreq bulkreq = {
+ .lastip = (__u64 *)lastino,
+ .icount = icount,
+ .ubuffer = ubuffer,
+ .ocount = (__s32 *)ocount,
+ };
+
+ return ioctl(fd, XFS_IOC_FSBULKSTAT, &bulkreq);
+}
diff --git a/quota/quot.c b/quota/quot.c
index d60cf4a8..4639dc5d 100644
--- a/quota/quot.c
+++ b/quota/quot.c
@@ -11,6 +11,7 @@
#include <grp.h>
#include "init.h"
#include "quota.h"
+#include "xfrog.h"
typedef struct du {
struct du *next;
@@ -124,12 +125,11 @@ quot_bulkstat_add(
static void
quot_bulkstat_mount(
char *fsdir,
- uint flags)
+ unsigned int flags)
{
- xfs_fsop_bulkreq_t bulkreq;
- xfs_bstat_t *buf;
- __u64 last = 0;
- __s32 count;
+ struct xfs_bstat *buf;
+ uint64_t last = 0;
+ uint32_t count;
int i, sts, fsfd;
du_t **dp;
@@ -158,12 +158,7 @@ quot_bulkstat_mount(
return;
}
- bulkreq.lastip = &last;
- bulkreq.icount = NBSTAT;
- bulkreq.ubuffer = buf;
- bulkreq.ocount = &count;
-
- while ((sts = xfsctl(fsdir, fsfd, XFS_IOC_FSBULKSTAT, &bulkreq)) == 0) {
+ while ((sts = xfrog_bulkstat(fsfd, &last, NBSTAT, buf, &count)) == 0) {
if (count == 0)
break;
for (i = 0; i < count; i++)
diff --git a/scrub/inodes.c b/scrub/inodes.c
index 442a5978..7950208d 100644
--- a/scrub/inodes.c
+++ b/scrub/inodes.c
@@ -17,6 +17,7 @@
#include "xfs_scrub.h"
#include "common.h"
#include "inodes.h"
+#include "xfrog.h"
/*
* Iterate a range of inodes.
@@ -50,17 +51,10 @@ xfs_iterate_inodes_range_check(
struct xfs_inogrp *inogrp,
struct xfs_bstat *bstat)
{
- struct xfs_fsop_bulkreq onereq = {NULL};
struct xfs_bstat *bs;
- __u64 oneino;
- __s32 onelen = 0;
int i;
int error;
- onereq.lastip = &oneino;
- onereq.icount = 1;
- onereq.ocount = &onelen;
-
for (i = 0, bs = bstat; i < XFS_INODES_PER_CHUNK; i++) {
if (!(inogrp->xi_allocmask & (1ULL << i)))
continue;
@@ -70,10 +64,8 @@ xfs_iterate_inodes_range_check(
}
/* Load the one inode. */
- oneino = inogrp->xi_startino + i;
- onereq.ubuffer = bs;
- error = ioctl(ctx->mnt_fd, XFS_IOC_FSBULKSTAT_SINGLE,
- &onereq);
+ error = xfrog_bulkstat_single(ctx->mnt_fd,
+ inogrp->xi_startino + i, bs);
if (error || bs->bs_ino != inogrp->xi_startino + i) {
memset(bs, 0, sizeof(struct xfs_bstat));
bs->bs_ino = inogrp->xi_startino + i;
@@ -99,7 +91,6 @@ xfs_iterate_inodes_range(
void *arg)
{
struct xfs_fsop_bulkreq igrpreq = {NULL};
- struct xfs_fsop_bulkreq bulkreq = {NULL};
struct xfs_handle handle;
struct xfs_inogrp inogrp;
struct xfs_bstat bstat[XFS_INODES_PER_CHUNK];
@@ -107,8 +98,8 @@ xfs_iterate_inodes_range(
char buf[DESCR_BUFSZ];
struct xfs_bstat *bs;
__u64 igrp_ino;
- __u64 ino;
- __s32 bulklen = 0;
+ uint64_t ino;
+ uint32_t bulklen = 0;
__s32 igrplen = 0;
bool moveon = true;
int i;
@@ -117,10 +108,6 @@ xfs_iterate_inodes_range(
memset(bstat, 0, XFS_INODES_PER_CHUNK * sizeof(struct xfs_bstat));
- bulkreq.lastip = &ino;
- bulkreq.icount = XFS_INODES_PER_CHUNK;
- bulkreq.ubuffer = &bstat;
- bulkreq.ocount = &bulklen;
igrpreq.lastip = &igrp_ino;
igrpreq.icount = 1;
@@ -138,14 +125,15 @@ xfs_iterate_inodes_range(
while (!error && igrplen) {
/* Load the inodes. */
ino = inogrp.xi_startino - 1;
- bulkreq.icount = inogrp.xi_alloccount;
+
/*
* We can have totally empty inode chunks on filesystems where
* there are more than 64 inodes per block. Skip these.
*/
if (inogrp.xi_alloccount == 0)
goto igrp_retry;
- error = ioctl(ctx->mnt_fd, XFS_IOC_FSBULKSTAT, &bulkreq);
+ error = xfrog_bulkstat(ctx->mnt_fd, &ino, inogrp.xi_alloccount,
+ bstat, &bulklen);
if (error)
str_info(ctx, descr, "%s", strerror_r(errno,
buf, DESCR_BUFSZ));
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/6] libxfs: refactor open-coded INUMBERS calls
2019-06-07 19:28 [PATCH v2 0/6] xfsprogs-5.1: fix various problems Darrick J. Wong
2019-06-07 19:28 ` [PATCH 1/6] libfrog: refactor online geometry queries Darrick J. Wong
2019-06-07 19:28 ` [PATCH 2/6] libxfs: refactor open-coded bulkstat calls Darrick J. Wong
@ 2019-06-07 19:28 ` Darrick J. Wong
2019-06-07 19:28 ` [PATCH 4/6] mkfs: validate start and end of aligned logs Darrick J. Wong
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2019-06-07 19:28 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
Refactor all the INUMBERS ioctl callsites into helper functions.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
include/xfrog.h | 4 ++++
io/imap.c | 31 ++++++++++++++-----------------
io/open.c | 19 +++++++------------
libfrog/bulkstat.c | 19 +++++++++++++++++++
scrub/fscounters.c | 18 +++++++-----------
scrub/inodes.c | 21 +++++++--------------
6 files changed, 58 insertions(+), 54 deletions(-)
diff --git a/include/xfrog.h b/include/xfrog.h
index 4b4e0adc..8456d55e 100644
--- a/include/xfrog.h
+++ b/include/xfrog.h
@@ -24,4 +24,8 @@ int xfrog_bulkstat_single(int fd, uint64_t ino, struct xfs_bstat *ubuffer);
int xfrog_bulkstat(int fd, uint64_t *lastino, uint32_t icount,
struct xfs_bstat *ubuffer, uint32_t *ocount);
+struct xfs_inogrp;
+int xfrog_inumbers(int fd, uint64_t *lastino, uint32_t icount,
+ struct xfs_inogrp *ubuffer, uint32_t *ocount);
+
#endif /* __XFROG_H__ */
diff --git a/io/imap.c b/io/imap.c
index fbc8e9e1..69027693 100644
--- a/io/imap.c
+++ b/io/imap.c
@@ -8,18 +8,19 @@
#include "input.h"
#include "init.h"
#include "io.h"
+#include "xfrog.h"
static cmdinfo_t imap_cmd;
static int
imap_f(int argc, char **argv)
{
- int count;
- int nent;
- int i;
- __u64 last = 0;
- xfs_inogrp_t *t;
- xfs_fsop_bulkreq_t bulkreq;
+ struct xfs_inogrp *t;
+ uint64_t last = 0;
+ uint32_t count;
+ uint32_t nent;
+ int i;
+ int error;
if (argc != 2)
nent = 1;
@@ -30,14 +31,8 @@ imap_f(int argc, char **argv)
if (!t)
return 0;
- bulkreq.lastip = &last;
- bulkreq.icount = nent;
- bulkreq.ubuffer = (void *)t;
- bulkreq.ocount = &count;
-
- while (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS, &bulkreq) == 0) {
- if (count == 0)
- goto out_free;
+ while ((error = xfrog_inumbers(file->fd, &last, nent, t, &count)) == 0 &&
+ count > 0) {
for (i = 0; i < count; i++) {
printf(_("ino %10llu count %2d mask %016llx\n"),
(unsigned long long)t[i].xi_startino,
@@ -45,9 +40,11 @@ imap_f(int argc, char **argv)
(unsigned long long)t[i].xi_allocmask);
}
}
- perror("xfsctl(XFS_IOC_FSINUMBERS)");
- exitcode = 1;
-out_free:
+
+ if (error) {
+ perror("xfsctl(XFS_IOC_FSINUMBERS)");
+ exitcode = 1;
+ }
free(t);
return 0;
}
diff --git a/io/open.c b/io/open.c
index d97903e9..7bc5a2f3 100644
--- a/io/open.c
+++ b/io/open.c
@@ -669,24 +669,19 @@ inode_help(void)
"\n"));
}
+#define IGROUP_NR (1024)
static __u64
get_last_inode(void)
{
- __u64 lastip = 0;
- __u64 lastgrp = 0;
- __s32 ocount = 0;
+ uint64_t lastip = 0;
+ uint32_t lastgrp = 0;
+ uint32_t ocount = 0;
__u64 last_ino;
- struct xfs_inogrp igroup[1024];
- struct xfs_fsop_bulkreq bulkreq;
-
- bulkreq.lastip = &lastip;
- bulkreq.ubuffer = &igroup;
- bulkreq.icount = sizeof(igroup) / sizeof(struct xfs_inogrp);
- bulkreq.ocount = &ocount;
+ struct xfs_inogrp igroup[IGROUP_NR];
for (;;) {
- if (xfsctl(file->name, file->fd, XFS_IOC_FSINUMBERS,
- &bulkreq)) {
+ if (xfrog_inumbers(file->fd, &lastip, IGROUP_NR, igroup,
+ &ocount)) {
perror("XFS_IOC_FSINUMBERS");
return 0;
}
diff --git a/libfrog/bulkstat.c b/libfrog/bulkstat.c
index c0d3b627..1b08bbbd 100644
--- a/libfrog/bulkstat.c
+++ b/libfrog/bulkstat.c
@@ -41,3 +41,22 @@ xfrog_bulkstat(
return ioctl(fd, XFS_IOC_FSBULKSTAT, &bulkreq);
}
+
+/* Query inode allocation bitmask information. */
+int
+xfrog_inumbers(
+ int fd,
+ uint64_t *lastino,
+ uint32_t icount,
+ struct xfs_inogrp *ubuffer,
+ uint32_t *ocount)
+{
+ struct xfs_fsop_bulkreq bulkreq = {
+ .lastip = (__u64 *)lastino,
+ .icount = icount,
+ .ubuffer = ubuffer,
+ .ocount = (__s32 *)ocount,
+ };
+
+ return ioctl(fd, XFS_IOC_FSINUMBERS, &bulkreq);
+}
diff --git a/scrub/fscounters.c b/scrub/fscounters.c
index 9e93e2a6..492a06c7 100644
--- a/scrub/fscounters.c
+++ b/scrub/fscounters.c
@@ -15,6 +15,7 @@
#include "xfs_scrub.h"
#include "common.h"
#include "fscounters.h"
+#include "xfrog.h"
/*
* Filesystem counter collection routines. We can count the number of
@@ -41,26 +42,21 @@ xfs_count_inodes_range(
uint64_t last_ino,
uint64_t *count)
{
- struct xfs_fsop_bulkreq igrpreq = {NULL};
struct xfs_inogrp inogrp;
- __u64 igrp_ino;
+ uint64_t igrp_ino;
uint64_t nr = 0;
- __s32 igrplen = 0;
+ uint32_t igrplen = 0;
int error;
ASSERT(!(first_ino & (XFS_INODES_PER_CHUNK - 1)));
ASSERT((last_ino & (XFS_INODES_PER_CHUNK - 1)));
- igrpreq.lastip = &igrp_ino;
- igrpreq.icount = 1;
- igrpreq.ubuffer = &inogrp;
- igrpreq.ocount = &igrplen;
-
igrp_ino = first_ino;
- error = ioctl(ctx->mnt_fd, XFS_IOC_FSINUMBERS, &igrpreq);
- while (!error && igrplen && inogrp.xi_startino < last_ino) {
+ while ((error = xfrog_inumbers(ctx->mnt_fd, &igrp_ino, 1, &inogrp,
+ &igrplen)) == 0 &&
+ igrplen > 0 &&
+ inogrp.xi_startino < last_ino) {
nr += inogrp.xi_alloccount;
- error = ioctl(ctx->mnt_fd, XFS_IOC_FSINUMBERS, &igrpreq);
}
if (error) {
diff --git a/scrub/inodes.c b/scrub/inodes.c
index 7950208d..0db16916 100644
--- a/scrub/inodes.c
+++ b/scrub/inodes.c
@@ -90,17 +90,16 @@ xfs_iterate_inodes_range(
xfs_inode_iter_fn fn,
void *arg)
{
- struct xfs_fsop_bulkreq igrpreq = {NULL};
struct xfs_handle handle;
struct xfs_inogrp inogrp;
struct xfs_bstat bstat[XFS_INODES_PER_CHUNK];
char idescr[DESCR_BUFSZ];
char buf[DESCR_BUFSZ];
struct xfs_bstat *bs;
- __u64 igrp_ino;
+ uint64_t igrp_ino;
uint64_t ino;
uint32_t bulklen = 0;
- __s32 igrplen = 0;
+ uint32_t igrplen = 0;
bool moveon = true;
int i;
int error;
@@ -109,11 +108,6 @@ xfs_iterate_inodes_range(
memset(bstat, 0, XFS_INODES_PER_CHUNK * sizeof(struct xfs_bstat));
- igrpreq.lastip = &igrp_ino;
- igrpreq.icount = 1;
- igrpreq.ubuffer = &inogrp;
- igrpreq.ocount = &igrplen;
-
memcpy(&handle.ha_fsid, fshandle, sizeof(handle.ha_fsid));
handle.ha_fid.fid_len = sizeof(xfs_fid_t) -
sizeof(handle.ha_fid.fid_len);
@@ -121,8 +115,9 @@ xfs_iterate_inodes_range(
/* Find the inode chunk & alloc mask */
igrp_ino = first_ino;
- error = ioctl(ctx->mnt_fd, XFS_IOC_FSINUMBERS, &igrpreq);
- while (!error && igrplen) {
+ while ((error = xfrog_inumbers(ctx->mnt_fd, &igrp_ino, 1, &inogrp,
+ &igrplen)) == 0 &&
+ igrplen > 0) {
/* Load the inodes. */
ino = inogrp.xi_startino - 1;
@@ -131,7 +126,7 @@ xfs_iterate_inodes_range(
* there are more than 64 inodes per block. Skip these.
*/
if (inogrp.xi_alloccount == 0)
- goto igrp_retry;
+ continue;
error = xfrog_bulkstat(ctx->mnt_fd, &ino, inogrp.xi_alloccount,
bstat, &bulklen);
if (error)
@@ -155,7 +150,7 @@ xfs_iterate_inodes_range(
stale_count++;
if (stale_count < 30) {
igrp_ino = inogrp.xi_startino;
- goto igrp_retry;
+ continue;
}
snprintf(idescr, DESCR_BUFSZ, "inode %"PRIu64,
(uint64_t)bs->bs_ino);
@@ -177,8 +172,6 @@ _("Changed too many times during scan; giving up."));
}
stale_count = 0;
-igrp_retry:
- error = ioctl(ctx->mnt_fd, XFS_IOC_FSINUMBERS, &igrpreq);
}
err:
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/6] mkfs: validate start and end of aligned logs
2019-06-07 19:28 [PATCH v2 0/6] xfsprogs-5.1: fix various problems Darrick J. Wong
` (2 preceding siblings ...)
2019-06-07 19:28 ` [PATCH 3/6] libxfs: refactor open-coded INUMBERS calls Darrick J. Wong
@ 2019-06-07 19:28 ` Darrick J. Wong
2019-06-07 19:28 ` [PATCH 5/6] xfs_io: repair_f should use its own name Darrick J. Wong
2019-06-07 19:28 ` [PATCH 6/6] libxfs-diff: try harder to find the kernel equivalent libxfs files Darrick J. Wong
5 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2019-06-07 19:28 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
Validate that the start and end of the log stay within a single AG if
we adjust either end to align to stripe units.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
mkfs/xfs_mkfs.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index ddb25ecc..468b8fde 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -3033,15 +3033,28 @@ align_internal_log(
struct xfs_mount *mp,
int sunit)
{
+ uint64_t logend;
+
/* round up log start if necessary */
if ((cfg->logstart % sunit) != 0)
cfg->logstart = ((cfg->logstart + (sunit - 1)) / sunit) * sunit;
+ /* If our log start overlaps the next AG's metadata, fail. */
+ if (!xfs_verify_fsbno(mp, cfg->logstart)) {
+ fprintf(stderr,
+_("Due to stripe alignment, the internal log start (%lld) cannot be aligned\n"
+ "within an allocation group.\n"),
+ (long long) cfg->logstart);
+ usage();
+ }
+
/* round up/down the log size now */
align_log_size(cfg, sunit);
/* check the aligned log still fits in an AG. */
- if (cfg->logblocks > cfg->agsize - XFS_FSB_TO_AGBNO(mp, cfg->logstart)) {
+ logend = cfg->logstart + cfg->logblocks - 1;
+ if (XFS_FSB_TO_AGNO(mp, cfg->logstart) != XFS_FSB_TO_AGNO(mp, logend) ||
+ !xfs_verify_fsbno(mp, logend)) {
fprintf(stderr,
_("Due to stripe alignment, the internal log size (%lld) is too large.\n"
"Must fit within an allocation group.\n"),
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/6] xfs_io: repair_f should use its own name
2019-06-07 19:28 [PATCH v2 0/6] xfsprogs-5.1: fix various problems Darrick J. Wong
` (3 preceding siblings ...)
2019-06-07 19:28 ` [PATCH 4/6] mkfs: validate start and end of aligned logs Darrick J. Wong
@ 2019-06-07 19:28 ` Darrick J. Wong
2019-06-07 19:28 ` [PATCH 6/6] libxfs-diff: try harder to find the kernel equivalent libxfs files Darrick J. Wong
5 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2019-06-07 19:28 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
If the repair command fails, it should tag the error message with its
own name ("repair").
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
io/scrub.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/io/scrub.c b/io/scrub.c
index 2ff1a6af..052497be 100644
--- a/io/scrub.c
+++ b/io/scrub.c
@@ -293,7 +293,7 @@ repair_ioctl(
error = ioctl(fd, XFS_IOC_SCRUB_METADATA, &meta);
if (error)
- perror("scrub");
+ perror("repair");
if (meta.sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
printf(_("Corruption remains.\n"));
if (meta.sm_flags & XFS_SCRUB_OFLAG_PREEN)
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/6] libxfs-diff: try harder to find the kernel equivalent libxfs files
2019-06-07 19:28 [PATCH v2 0/6] xfsprogs-5.1: fix various problems Darrick J. Wong
` (4 preceding siblings ...)
2019-06-07 19:28 ` [PATCH 5/6] xfs_io: repair_f should use its own name Darrick J. Wong
@ 2019-06-07 19:28 ` Darrick J. Wong
5 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2019-06-07 19:28 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
Now that we're syncing userspace libxfs/ files with kernel fs/xfs/
files, teach the diff tool to try fs/xfs/xfs_foo.c if
fs/xfs/libxfs/xfs_foo.c doesn't exist.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
tools/libxfs-diff | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/libxfs-diff b/tools/libxfs-diff
index fa57c004..c18ad487 100755
--- a/tools/libxfs-diff
+++ b/tools/libxfs-diff
@@ -22,5 +22,6 @@ dir="$(readlink -m "${dir}/..")"
for i in libxfs/xfs*.[ch]; do
kfile="${dir}/$i"
+ test -f "${kfile}" || kfile="$(echo "${kfile}" | sed -e 's|libxfs/||g')"
diff -Naurpw --label "$i" <(sed -e '/#include/d' "$i") --label "${kfile}" <(sed -e '/#include/d' "${kfile}")
done
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 1/6] libfrog: refactor online geometry queries
2019-08-20 20:30 [PATCH 0/6] libxfrog: wrap version ioctl calls Darrick J. Wong
@ 2019-08-20 20:30 ` Darrick J. Wong
2019-08-27 6:30 ` Dave Chinner
0 siblings, 1 reply; 10+ messages in thread
From: Darrick J. Wong @ 2019-08-20 20:30 UTC (permalink / raw)
To: sandeen, darrick.wong; +Cc: linux-xfs
From: Darrick J. Wong <darrick.wong@oracle.com>
Refactor all the open-coded XFS_IOC_FSGEOMETRY queries into a single
helper that we can use to standardize behaviors across mixed xfslibs
versions. This is the prelude to introducing a new FSGEOMETRY version
in 5.2 and needing to fix the (relatively few) client programs.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
Makefile | 1 +
fsr/xfs_fsr.c | 26 ++++----------------------
growfs/xfs_growfs.c | 25 +++++++++----------------
include/xfrog.h | 22 ++++++++++++++++++++++
io/bmap.c | 3 ++-
io/fsmap.c | 3 ++-
io/open.c | 3 ++-
io/stat.c | 5 +++--
libfrog/fsgeom.c | 18 ++++++++++++++++++
quota/free.c | 6 +++---
repair/xfs_repair.c | 5 +++--
rtcp/Makefile | 3 +++
rtcp/xfs_rtcp.c | 7 ++++---
scrub/phase1.c | 5 +++--
spaceman/file.c | 3 ++-
spaceman/info.c | 27 +++++++++------------------
16 files changed, 90 insertions(+), 72 deletions(-)
create mode 100644 include/xfrog.h
diff --git a/Makefile b/Makefile
index 9204bed8..0edc2700 100644
--- a/Makefile
+++ b/Makefile
@@ -107,6 +107,7 @@ copy: libxlog
mkfs: libxcmd
spaceman: libxcmd
scrub: libhandle libxcmd
+rtcp: libfrog
ifeq ($(HAVE_BUILDDEFS), yes)
include $(BUILDRULES)
diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index 1963a05e..1541917e 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -11,6 +11,7 @@
#include "xfs_bmap_btree.h"
#include "xfs_attr_sf.h"
#include "path.h"
+#include "xfrog.h"
#include <fcntl.h>
#include <errno.h>
@@ -83,9 +84,8 @@ int cmp(const void *, const void *);
static void tmp_init(char *mnt);
static char * tmp_next(char *mnt);
static void tmp_close(char *mnt);
-int xfs_getgeom(int , struct xfs_fsop_geom_v1 * );
-static struct xfs_fsop_geom_v1 fsgeom; /* geometry of active mounted system */
+static struct xfs_fsop_geom fsgeom; /* geometry of active mounted system */
#define NMOUNT 64
static int numfs;
@@ -102,12 +102,6 @@ static int nfrags = 0; /* Debug option: Coerse into specific number
* of extents */
static int openopts = O_CREAT|O_EXCL|O_RDWR|O_DIRECT;
-static int
-xfs_fsgeometry(int fd, struct xfs_fsop_geom_v1 *geom)
-{
- return ioctl(fd, XFS_IOC_FSGEOMETRY_V1, geom);
-}
-
static int
xfs_bulkstat_single(int fd, xfs_ino_t *lastip, struct xfs_bstat *ubuffer)
{
@@ -630,7 +624,7 @@ fsrfs(char *mntdir, xfs_ino_t startino, int targetrange)
return -1;
}
- if (xfs_getgeom(fsfd, &fsgeom) < 0 ) {
+ if (xfrog_geometry(fsfd, &fsgeom) < 0 ) {
fsrprintf(_("Skipping %s: could not get XFS geometry\n"),
mntdir);
close(fsfd);
@@ -772,7 +766,7 @@ fsrfile(char *fname, xfs_ino_t ino)
}
/* Get the fs geometry */
- if (xfs_getgeom(fsfd, &fsgeom) < 0 ) {
+ if (xfrog_geometry(fsfd, &fsgeom) < 0 ) {
fsrprintf(_("Unable to get geom on fs for: %s\n"), fname);
goto out;
}
@@ -1612,18 +1606,6 @@ getnextents(int fd)
return(nextents);
}
-/*
- * Get the fs geometry
- */
-int
-xfs_getgeom(int fd, struct xfs_fsop_geom_v1 *fsgeom)
-{
- if (xfs_fsgeometry(fd, fsgeom) < 0) {
- return -1;
- }
- return 0;
-}
-
/*
* Get xfs realtime space information
*/
diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c
index 20089d2b..86b1d542 100644
--- a/growfs/xfs_growfs.c
+++ b/growfs/xfs_growfs.c
@@ -7,6 +7,7 @@
#include "libxfs.h"
#include "path.h"
#include "fsgeom.h"
+#include "xfrog.h"
static void
usage(void)
@@ -165,22 +166,14 @@ main(int argc, char **argv)
}
/* get the current filesystem size & geometry */
- if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY, &geo) < 0) {
- /*
- * OK, new xfsctl barfed - back off and try earlier version
- * as we're probably running an older kernel version.
- * Only field added in the v2 geometry xfsctl is "logsunit"
- * so we'll zero that out for later display (as zero).
- */
- geo.logsunit = 0;
- if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY_V1, &geo) < 0) {
- fprintf(stderr, _(
- "%s: cannot determine geometry of filesystem"
- " mounted at %s: %s\n"),
- progname, fname, strerror(errno));
- exit(1);
- }
+ if (xfrog_geometry(ffd, &geo) < 0) {
+ fprintf(stderr, _(
+ "%s: cannot determine geometry of filesystem"
+ " mounted at %s: %s\n"),
+ progname, fname, strerror(errno));
+ exit(1);
}
+
isint = geo.logstart > 0;
/*
@@ -359,7 +352,7 @@ main(int argc, char **argv)
}
}
- if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY_V1, &ngeo) < 0) {
+ if (xfrog_geometry(ffd, &ngeo) < 0) {
fprintf(stderr, _("%s: XFS_IOC_FSGEOMETRY xfsctl failed: %s\n"),
progname, strerror(errno));
exit(1);
diff --git a/include/xfrog.h b/include/xfrog.h
new file mode 100644
index 00000000..5420b47c
--- /dev/null
+++ b/include/xfrog.h
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2000-2002 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ */
+#ifndef __XFROG_H__
+#define __XFROG_H__
+
+/*
+ * XFS Filesystem Random Online Gluecode
+ * =====================================
+ *
+ * These support functions wrap the more complex xfs ioctls so that xfs
+ * utilities can take advantage of them without having to deal with graceful
+ * degradation in the face of new ioctls. They will also provide higher level
+ * abstractions when possible.
+ */
+
+struct xfs_fsop_geom;
+int xfrog_geometry(int fd, struct xfs_fsop_geom *fsgeo);
+
+#endif /* __XFROG_H__ */
diff --git a/io/bmap.c b/io/bmap.c
index d408826a..5f0d12ca 100644
--- a/io/bmap.c
+++ b/io/bmap.c
@@ -9,6 +9,7 @@
#include "input.h"
#include "init.h"
#include "io.h"
+#include "xfrog.h"
static cmdinfo_t bmap_cmd;
@@ -105,7 +106,7 @@ bmap_f(
bmv_iflags &= ~(BMV_IF_PREALLOC|BMV_IF_NO_DMAPI_READ);
if (vflag) {
- c = xfsctl(file->name, file->fd, XFS_IOC_FSGEOMETRY_V1, &fsgeo);
+ c = xfrog_geometry(file->fd, &fsgeo);
if (c < 0) {
fprintf(stderr,
_("%s: can't get geometry [\"%s\"]: %s\n"),
diff --git a/io/fsmap.c b/io/fsmap.c
index 477c36fc..d3ff7dea 100644
--- a/io/fsmap.c
+++ b/io/fsmap.c
@@ -9,6 +9,7 @@
#include "path.h"
#include "io.h"
#include "input.h"
+#include "xfrog.h"
static cmdinfo_t fsmap_cmd;
static dev_t xfs_data_dev;
@@ -447,7 +448,7 @@ fsmap_f(
}
if (vflag) {
- c = ioctl(file->fd, XFS_IOC_FSGEOMETRY, &fsgeo);
+ c = xfrog_geometry(file->fd, &fsgeo);
if (c < 0) {
fprintf(stderr,
_("%s: can't get geometry [\"%s\"]: %s\n"),
diff --git a/io/open.c b/io/open.c
index c7f5248a..e70c8cb0 100644
--- a/io/open.c
+++ b/io/open.c
@@ -9,6 +9,7 @@
#include "init.h"
#include "io.h"
#include "libxfs.h"
+#include "xfrog.h"
#ifndef __O_TMPFILE
#if defined __alpha__
@@ -118,7 +119,7 @@ openfile(
if (flags & IO_PATH) {
/* Can't call ioctl() on O_PATH fds */
memset(geom, 0, sizeof(*geom));
- } else if (xfsctl(path, fd, XFS_IOC_FSGEOMETRY, geom) < 0) {
+ } else if (xfrog_geometry(fd, geom) < 0) {
perror("XFS_IOC_FSGEOMETRY");
close(fd);
return -1;
diff --git a/io/stat.c b/io/stat.c
index 37c0b2e8..f7bbe08b 100644
--- a/io/stat.c
+++ b/io/stat.c
@@ -12,6 +12,7 @@
#include "io.h"
#include "statx.h"
#include "libxfs.h"
+#include "xfrog.h"
#include <fcntl.h>
@@ -194,8 +195,8 @@ statfs_f(
}
if (file->flags & IO_FOREIGN)
return 0;
- if ((xfsctl(file->name, file->fd, XFS_IOC_FSGEOMETRY_V1, &fsgeo)) < 0) {
- perror("XFS_IOC_FSGEOMETRY_V1");
+ if (xfrog_geometry(file->fd, &fsgeo) < 0) {
+ perror("XFS_IOC_FSGEOMETRY");
} else {
printf(_("geom.bsize = %u\n"), fsgeo.blocksize);
printf(_("geom.agcount = %u\n"), fsgeo.agcount);
diff --git a/libfrog/fsgeom.c b/libfrog/fsgeom.c
index 8879d161..a6dab3a8 100644
--- a/libfrog/fsgeom.c
+++ b/libfrog/fsgeom.c
@@ -4,6 +4,7 @@
*/
#include "libxfs.h"
#include "fsgeom.h"
+#include "xfrog.h"
void
xfs_report_geom(
@@ -67,3 +68,20 @@ xfs_report_geom(
geo->rtextsize * geo->blocksize, (unsigned long long)geo->rtblocks,
(unsigned long long)geo->rtextents);
}
+
+/* Try to obtain the xfs geometry. */
+int
+xfrog_geometry(
+ int fd,
+ struct xfs_fsop_geom *fsgeo)
+{
+ int ret;
+
+ memset(fsgeo, 0, sizeof(*fsgeo));
+
+ ret = ioctl(fd, XFS_IOC_FSGEOMETRY, fsgeo);
+ if (!ret)
+ return 0;
+
+ return ioctl(fd, XFS_IOC_FSGEOMETRY_V1, fsgeo);
+}
diff --git a/quota/free.c b/quota/free.c
index 1d13006e..5432b6a8 100644
--- a/quota/free.c
+++ b/quota/free.c
@@ -8,6 +8,7 @@
#include "command.h"
#include "init.h"
#include "quota.h"
+#include "xfrog.h"
static cmdinfo_t free_cmd;
@@ -67,9 +68,8 @@ mount_free_space_data(
}
if (!(mount->fs_flags & FS_FOREIGN)) {
- if ((xfsctl(mount->fs_dir, fd, XFS_IOC_FSGEOMETRY_V1,
- &fsgeo)) < 0) {
- perror("XFS_IOC_FSGEOMETRY_V1");
+ if (xfrog_geometry(fd, &fsgeo) < 0) {
+ perror("XFS_IOC_FSGEOMETRY");
close(fd);
return 0;
}
diff --git a/repair/xfs_repair.c b/repair/xfs_repair.c
index ce70e2de..9f4f2611 100644
--- a/repair/xfs_repair.c
+++ b/repair/xfs_repair.c
@@ -22,6 +22,7 @@
#include "dinode.h"
#include "slab.h"
#include "rmap.h"
+#include "xfrog.h"
/*
* option tables for getsubopt calls
@@ -636,11 +637,11 @@ check_fs_vs_host_sectsize(
{
int fd;
long old_flags;
- struct xfs_fsop_geom_v1 geom = { 0 };
+ struct xfs_fsop_geom geom = { 0 };
fd = libxfs_device_to_fd(x.ddev);
- if (ioctl(fd, XFS_IOC_FSGEOMETRY_V1, &geom) < 0) {
+ if (xfrog_geometry(fd, &geom) < 0) {
do_log(_("Cannot get host filesystem geometry.\n"
"Repair may fail if there is a sector size mismatch between\n"
"the image and the host filesystem.\n"));
diff --git a/rtcp/Makefile b/rtcp/Makefile
index 808b5378..264b4f27 100644
--- a/rtcp/Makefile
+++ b/rtcp/Makefile
@@ -9,6 +9,9 @@ LTCOMMAND = xfs_rtcp
CFILES = xfs_rtcp.c
LLDFLAGS = -static
+LLDLIBS = $(LIBFROG)
+LTDEPENDENCIES = $(LIBFROG)
+
default: depend $(LTCOMMAND)
include $(BUILDRULES)
diff --git a/rtcp/xfs_rtcp.c b/rtcp/xfs_rtcp.c
index 1027c913..0b37ee89 100644
--- a/rtcp/xfs_rtcp.c
+++ b/rtcp/xfs_rtcp.c
@@ -5,6 +5,7 @@
*/
#include "libxfs.h"
+#include "xfrog.h"
int rtcp(char *, char *, int);
int xfsrtextsize(char *path);
@@ -368,8 +369,8 @@ rtcp( char *source, char *target, int fextsize)
int
xfsrtextsize( char *path)
{
- int fd, rval, rtextsize;
- struct xfs_fsop_geom_v1 geo;
+ struct xfs_fsop_geom geo;
+ int fd, rval, rtextsize;
fd = open( path, O_RDONLY );
if ( fd < 0 ) {
@@ -377,7 +378,7 @@ xfsrtextsize( char *path)
progname, path, strerror(errno));
return -1;
}
- rval = xfsctl( path, fd, XFS_IOC_FSGEOMETRY_V1, &geo );
+ rval = xfrog_geometry(fd, &geo);
close(fd);
if ( rval < 0 )
return -1;
diff --git a/scrub/phase1.c b/scrub/phase1.c
index 04a5f4a9..bd7c9fee 100644
--- a/scrub/phase1.c
+++ b/scrub/phase1.c
@@ -26,6 +26,7 @@
#include "disk.h"
#include "scrub.h"
#include "repair.h"
+#include "xfrog.h"
/* Phase 1: Find filesystem geometry (and clean up after) */
@@ -129,8 +130,8 @@ _("Does not appear to be an XFS filesystem!"));
}
/* Retrieve XFS geometry. */
- error = ioctl(ctx->mnt_fd, XFS_IOC_FSGEOMETRY, &ctx->geo);
- if (error) {
+ error = xfrog_geometry(ctx->mnt_fd, &ctx->geo);
+ if (error < 0) {
str_errno(ctx, ctx->mntpoint);
return false;
}
diff --git a/spaceman/file.c b/spaceman/file.c
index 7e33e07e..ef627fdb 100644
--- a/spaceman/file.c
+++ b/spaceman/file.c
@@ -6,6 +6,7 @@
*/
#include "libxfs.h"
+#include "xfrog.h"
#include <sys/mman.h>
#include "command.h"
#include "input.h"
@@ -56,7 +57,7 @@ openfile(
return -1;
}
- if (ioctl(fd, XFS_IOC_FSGEOMETRY, geom) < 0) {
+ if (xfrog_geometry(fd, geom) < 0) {
if (errno == ENOTTY)
fprintf(stderr,
_("%s: Not on a mounted XFS filesystem.\n"),
diff --git a/spaceman/info.c b/spaceman/info.c
index 01d0744a..5357b430 100644
--- a/spaceman/info.c
+++ b/spaceman/info.c
@@ -4,6 +4,7 @@
* Author: Darrick J. Wong <darrick.wong@oracle.com>
*/
#include "libxfs.h"
+#include "xfrog.h"
#include "command.h"
#include "init.h"
#include "path.h"
@@ -37,24 +38,14 @@ info_f(
}
/* get the current filesystem size & geometry */
- error = ioctl(file->fd, XFS_IOC_FSGEOMETRY, &geo);
- if (error) {
- /*
- * OK, new xfsctl barfed - back off and try earlier version
- * as we're probably running an older kernel version.
- * Only field added in the v2 geometry xfsctl is "logsunit"
- * so we'll zero that out for later display (as zero).
- */
- geo.logsunit = 0;
- error = ioctl(file->fd, XFS_IOC_FSGEOMETRY_V1, &geo);
- if (error) {
- fprintf(stderr, _(
- "%s: cannot determine geometry of filesystem"
- " mounted at %s: %s\n"),
- progname, file->name, strerror(errno));
- exitcode = 1;
- return 0;
- }
+ error = xfrog_geometry(file->fd, &geo);
+ if (error < 0) {
+ fprintf(stderr, _(
+ "%s: cannot determine geometry of filesystem"
+ " mounted at %s: %s\n"),
+ progname, file->name, strerror(errno));
+ exitcode = 1;
+ return 0;
}
xfs_report_geom(&geo, file->fs_path.fs_name, file->fs_path.fs_log,
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/6] libfrog: refactor online geometry queries
2019-08-20 20:30 ` [PATCH 1/6] libfrog: refactor online geometry queries Darrick J. Wong
@ 2019-08-27 6:30 ` Dave Chinner
2019-08-28 17:08 ` Darrick J. Wong
0 siblings, 1 reply; 10+ messages in thread
From: Dave Chinner @ 2019-08-27 6:30 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: sandeen, linux-xfs
On Tue, Aug 20, 2019 at 01:30:38PM -0700, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
>
> Refactor all the open-coded XFS_IOC_FSGEOMETRY queries into a single
> helper that we can use to standardize behaviors across mixed xfslibs
> versions. This is the prelude to introducing a new FSGEOMETRY version
> in 5.2 and needing to fix the (relatively few) client programs.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
> Makefile | 1 +
> fsr/xfs_fsr.c | 26 ++++----------------------
Ok.
> growfs/xfs_growfs.c | 25 +++++++++----------------
Nit.
> include/xfrog.h | 22 ++++++++++++++++++++++
Copyright issue.
> io/bmap.c | 3 ++-
> io/fsmap.c | 3 ++-
> io/open.c | 3 ++-
> io/stat.c | 5 +++--
ok.
> libfrog/fsgeom.c | 18 ++++++++++++++++++
fallback question.
> quota/free.c | 6 +++---
> repair/xfs_repair.c | 5 +++--
> rtcp/Makefile | 3 +++
Linker question
> rtcp/xfs_rtcp.c | 7 ++++---
> scrub/phase1.c | 5 +++--
> spaceman/file.c | 3 ++-
> spaceman/info.c | 27 +++++++++------------------
OK.
> diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c
> index 20089d2b..86b1d542 100644
> --- a/growfs/xfs_growfs.c
> +++ b/growfs/xfs_growfs.c
> @@ -7,6 +7,7 @@
> #include "libxfs.h"
> #include "path.h"
> #include "fsgeom.h"
> +#include "xfrog.h"
>
> static void
> usage(void)
> @@ -165,22 +166,14 @@ main(int argc, char **argv)
> }
>
> /* get the current filesystem size & geometry */
> - if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY, &geo) < 0) {
> - /*
> - * OK, new xfsctl barfed - back off and try earlier version
> - * as we're probably running an older kernel version.
> - * Only field added in the v2 geometry xfsctl is "logsunit"
> - * so we'll zero that out for later display (as zero).
> - */
> - geo.logsunit = 0;
> - if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY_V1, &geo) < 0) {
> - fprintf(stderr, _(
> - "%s: cannot determine geometry of filesystem"
> - " mounted at %s: %s\n"),
> - progname, fname, strerror(errno));
> - exit(1);
> - }
> + if (xfrog_geometry(ffd, &geo) < 0) {
> + fprintf(stderr, _(
> + "%s: cannot determine geometry of filesystem"
> + " mounted at %s: %s\n"),
> + progname, fname, strerror(errno));
> + exit(1);
Can you run the format string into a single line?
> diff --git a/include/xfrog.h b/include/xfrog.h
> new file mode 100644
> index 00000000..5420b47c
> --- /dev/null
> +++ b/include/xfrog.h
> @@ -0,0 +1,22 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2000-2002 Silicon Graphics, Inc.
> + * All Rights Reserved.
> + */
I don't think that copyright is valid/appropriate for a new header
file with new contents.
...
> @@ -67,3 +68,20 @@ xfs_report_geom(
> geo->rtextsize * geo->blocksize, (unsigned long long)geo->rtblocks,
> (unsigned long long)geo->rtextents);
> }
> +
> +/* Try to obtain the xfs geometry. */
> +int
> +xfrog_geometry(
> + int fd,
> + struct xfs_fsop_geom *fsgeo)
> +{
> + int ret;
> +
> + memset(fsgeo, 0, sizeof(*fsgeo));
> +
> + ret = ioctl(fd, XFS_IOC_FSGEOMETRY, fsgeo);
> + if (!ret)
> + return 0;
> +
> + return ioctl(fd, XFS_IOC_FSGEOMETRY_V1, fsgeo);
> +}
Should this fall back to XFS_IOC_FSGEOMETRY_V4, then V1 if that
fails (which it shouldn't on any supported kernel)?
> diff --git a/rtcp/Makefile b/rtcp/Makefile
> index 808b5378..264b4f27 100644
> --- a/rtcp/Makefile
> +++ b/rtcp/Makefile
> @@ -9,6 +9,9 @@ LTCOMMAND = xfs_rtcp
> CFILES = xfs_rtcp.c
> LLDFLAGS = -static
>
> +LLDLIBS = $(LIBFROG)
> +LTDEPENDENCIES = $(LIBFROG)
Does this work correctly given LLDFLAGS sets -static and not
-libtools-static-libs?
Cheers,
Dave.
--
Dave Chinner
david@fromorbit.com
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/6] libfrog: refactor online geometry queries
2019-08-27 6:30 ` Dave Chinner
@ 2019-08-28 17:08 ` Darrick J. Wong
0 siblings, 0 replies; 10+ messages in thread
From: Darrick J. Wong @ 2019-08-28 17:08 UTC (permalink / raw)
To: Dave Chinner; +Cc: sandeen, linux-xfs
On Tue, Aug 27, 2019 at 04:30:54PM +1000, Dave Chinner wrote:
> On Tue, Aug 20, 2019 at 01:30:38PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> >
> > Refactor all the open-coded XFS_IOC_FSGEOMETRY queries into a single
> > helper that we can use to standardize behaviors across mixed xfslibs
> > versions. This is the prelude to introducing a new FSGEOMETRY version
> > in 5.2 and needing to fix the (relatively few) client programs.
> >
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > Makefile | 1 +
> > fsr/xfs_fsr.c | 26 ++++----------------------
>
> Ok.
>
> > growfs/xfs_growfs.c | 25 +++++++++----------------
>
> Nit.
>
> > include/xfrog.h | 22 ++++++++++++++++++++++
>
> Copyright issue.
>
> > io/bmap.c | 3 ++-
> > io/fsmap.c | 3 ++-
> > io/open.c | 3 ++-
> > io/stat.c | 5 +++--
>
> ok.
>
> > libfrog/fsgeom.c | 18 ++++++++++++++++++
>
> fallback question.
>
> > quota/free.c | 6 +++---
> > repair/xfs_repair.c | 5 +++--
> > rtcp/Makefile | 3 +++
>
> Linker question
>
> > rtcp/xfs_rtcp.c | 7 ++++---
> > scrub/phase1.c | 5 +++--
> > spaceman/file.c | 3 ++-
> > spaceman/info.c | 27 +++++++++------------------
>
> OK.
>
>
> > diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c
> > index 20089d2b..86b1d542 100644
> > --- a/growfs/xfs_growfs.c
> > +++ b/growfs/xfs_growfs.c
> > @@ -7,6 +7,7 @@
> > #include "libxfs.h"
> > #include "path.h"
> > #include "fsgeom.h"
> > +#include "xfrog.h"
> >
> > static void
> > usage(void)
> > @@ -165,22 +166,14 @@ main(int argc, char **argv)
> > }
> >
> > /* get the current filesystem size & geometry */
> > - if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY, &geo) < 0) {
> > - /*
> > - * OK, new xfsctl barfed - back off and try earlier version
> > - * as we're probably running an older kernel version.
> > - * Only field added in the v2 geometry xfsctl is "logsunit"
> > - * so we'll zero that out for later display (as zero).
> > - */
> > - geo.logsunit = 0;
> > - if (xfsctl(fname, ffd, XFS_IOC_FSGEOMETRY_V1, &geo) < 0) {
> > - fprintf(stderr, _(
> > - "%s: cannot determine geometry of filesystem"
> > - " mounted at %s: %s\n"),
> > - progname, fname, strerror(errno));
> > - exit(1);
> > - }
> > + if (xfrog_geometry(ffd, &geo) < 0) {
> > + fprintf(stderr, _(
> > + "%s: cannot determine geometry of filesystem"
> > + " mounted at %s: %s\n"),
> > + progname, fname, strerror(errno));
> > + exit(1);
>
> Can you run the format string into a single line?
ok.
> > diff --git a/include/xfrog.h b/include/xfrog.h
> > new file mode 100644
> > index 00000000..5420b47c
> > --- /dev/null
> > +++ b/include/xfrog.h
> > @@ -0,0 +1,22 @@
> > +// SPDX-License-Identifier: GPL-2.0
> > +/*
> > + * Copyright (c) 2000-2002 Silicon Graphics, Inc.
> > + * All Rights Reserved.
> > + */
>
> I don't think that copyright is valid/appropriate for a new header
> file with new contents.
Hrmmm ok I'll uhh fix it.
> ...
>
> > @@ -67,3 +68,20 @@ xfs_report_geom(
> > geo->rtextsize * geo->blocksize, (unsigned long long)geo->rtblocks,
> > (unsigned long long)geo->rtextents);
> > }
> > +
> > +/* Try to obtain the xfs geometry. */
> > +int
> > +xfrog_geometry(
> > + int fd,
> > + struct xfs_fsop_geom *fsgeo)
> > +{
> > + int ret;
> > +
> > + memset(fsgeo, 0, sizeof(*fsgeo));
> > +
> > + ret = ioctl(fd, XFS_IOC_FSGEOMETRY, fsgeo);
> > + if (!ret)
> > + return 0;
> > +
> > + return ioctl(fd, XFS_IOC_FSGEOMETRY_V1, fsgeo);
> > +}
>
> Should this fall back to XFS_IOC_FSGEOMETRY_V4, then V1 if that
> fails (which it shouldn't on any supported kernel)?
It should; there's a patch in the next series to do that, but I might as
well merge them (this series was originally targeting 5.1).
>
> > diff --git a/rtcp/Makefile b/rtcp/Makefile
> > index 808b5378..264b4f27 100644
> > --- a/rtcp/Makefile
> > +++ b/rtcp/Makefile
> > @@ -9,6 +9,9 @@ LTCOMMAND = xfs_rtcp
> > CFILES = xfs_rtcp.c
> > LLDFLAGS = -static
> >
> > +LLDLIBS = $(LIBFROG)
> > +LTDEPENDENCIES = $(LIBFROG)
>
> Does this work correctly given LLDFLAGS sets -static and not
> -libtools-static-libs?
It seems to, at least on Ubuntu 18.04.
--D
>
> Cheers,
>
> Dave.
> --
> Dave Chinner
> david@fromorbit.com
^ permalink raw reply [flat|nested] 10+ messages in thread