All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/9] xfsprogs-4.17: geometry refactoring
@ 2018-04-18  2:45 Darrick J. Wong
  2018-04-18  2:45 ` [PATCH 1/9] libfrog: move platform specific runtime support code out of libxfs Darrick J. Wong
                   ` (8 more replies)
  0 siblings, 9 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-04-18  2:45 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

Hi all,

This series refactors geometry reporting in xfsprogs.  First we move the
platform support code to libfrog where it belongs.  Next we hoist the
fsgeometry generation function to libxfs, then add some libfrog
functions to print fsgeometry structures.  Next we add a command to
xfs_db to print the geometry information of the loaded filesystem.
Finally, we move online geometry reporting from growfs to spaceman and
refactor xfs_info to call spaceman or db depending on the passed in
command line argument.  This series is largely unchanged from the
previous posting for 4.16.

This probably won't eat your data, and the branch[2] should apply
against for-next.

--D

[1] https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=djwong-devel

^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH 1/9] libfrog: move platform specific runtime support code out of libxfs
  2018-04-18  2:45 [PATCH 0/9] xfsprogs-4.17: geometry refactoring Darrick J. Wong
@ 2018-04-18  2:45 ` Darrick J. Wong
  2018-05-03 18:23   ` Eric Sandeen
  2018-04-18  2:45 ` [PATCH 2/9] libfrog: refactor fs geometry printing function Darrick J. Wong
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 34+ messages in thread
From: Darrick J. Wong @ 2018-04-18  2:45 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Move the platform support code to libfrog, which should remove the final
dependency of libfrog on libxfs.  libfrog is the runtime support
library, and these files provide platform support.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libfrog/Makefile  |    4 +
 libfrog/darwin.c  |  148 ++++++++++++++++++++++++++++++
 libfrog/freebsd.c |  205 +++++++++++++++++++++++++++++++++++++++++
 libfrog/irix.c    |  115 +++++++++++++++++++++++
 libfrog/linux.c   |  265 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 libxfs/Makefile   |    3 -
 libxfs/darwin.c   |  148 ------------------------------
 libxfs/freebsd.c  |  205 -----------------------------------------
 libxfs/irix.c     |  115 -----------------------
 libxfs/linux.c    |  265 -----------------------------------------------------
 10 files changed, 737 insertions(+), 736 deletions(-)
 create mode 100644 libfrog/darwin.c
 create mode 100644 libfrog/freebsd.c
 create mode 100644 libfrog/irix.c
 create mode 100644 libfrog/linux.c
 delete mode 100644 libxfs/darwin.c
 delete mode 100644 libxfs/freebsd.c
 delete mode 100644 libxfs/irix.c
 delete mode 100644 libxfs/linux.c


diff --git a/libfrog/Makefile b/libfrog/Makefile
index 230b08f..21bb5b7 100644
--- a/libfrog/Makefile
+++ b/libfrog/Makefile
@@ -22,6 +22,10 @@ topology.c \
 util.c \
 workqueue.c
 
+CFILES += $(PKG_PLATFORM).c
+PCFILES = darwin.c freebsd.c irix.c linux.c
+LSRCFILES = $(shell echo $(PCFILES) | sed -e "s/$(PKG_PLATFORM).c//g")
+
 ifeq ($(HAVE_GETMNTENT),yes)
 LCFLAGS += -DHAVE_GETMNTENT
 endif
diff --git a/libfrog/darwin.c b/libfrog/darwin.c
new file mode 100644
index 0000000..396477e
--- /dev/null
+++ b/libfrog/darwin.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2003,2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <sys/disk.h>
+#include <sys/stat.h>
+#include <sys/mount.h>
+#include <sys/ioctl.h>
+#include <sys/sysctl.h>
+#include "libxfs.h"
+
+int platform_has_uuid = 1;
+extern char *progname;
+
+#warning "Darwin support is deprecated and planned for removal in July 2018"
+#warning "Contact linux-xfs@vger.kernel.org if you'd like to maintain this port"
+#error   "Remove this line if you'd like to continue the build"
+
+int
+platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
+{
+	return 0;
+}
+
+int
+platform_check_iswritable(char *name, char *block, struct stat *s)
+{
+	int	fd, writable;
+
+	if ((fd = open(block, O_RDONLY, 0)) < 0) {
+		fprintf(stderr, _("%s: "
+			"error opening the device special file \"%s\": %s\n"),
+			progname, block, strerror(errno));
+		exit(1);
+	}
+
+	if (ioctl(fd, DKIOCISWRITABLE, &writable) < 0) {
+		fprintf(stderr, _("%s: can't tell if \"%s\" is writable: %s\n"),
+			progname, block, strerror(errno));
+		exit(1);
+	}
+	close(fd);
+	return writable == 0;
+}
+
+int
+platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
+{
+	return fatal;
+}
+
+void
+platform_flush_device(int fd, dev_t device)
+{
+	ioctl(fd, DKIOCSYNCHRONIZECACHE, NULL);
+}
+
+void
+platform_findsizes(char *path, int fd, long long *sz, int *bsz)
+{
+	uint64_t	size;
+	struct stat	st;
+
+	if (fstat(fd, &st) < 0) {
+		fprintf(stderr,
+			_("%s: cannot stat the device file \"%s\": %s\n"),
+			progname, path, strerror(errno));
+		exit(1);
+	}
+	if ((st.st_mode & S_IFMT) == S_IFREG) {
+		*sz = (long long)(st.st_size >> 9);
+		*bsz = BBSIZE;
+		return;
+	}
+	if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size) < 0) {
+		fprintf(stderr, _("%s: can't determine device size: %s\n"),
+			progname, strerror(errno));
+		exit(1);
+	}
+	*sz = (long long)size;
+	*bsz = BBSIZE;
+}
+
+char *
+platform_findrawpath(char *path)
+{
+	return path;
+}
+
+char *
+platform_findblockpath(char *path)
+{
+	return path;
+}
+
+int
+platform_direct_blockdev(void)
+{
+	return 0;
+}
+
+int
+platform_align_blockdev(void)
+{
+	return sizeof(void *);
+}
+
+int
+platform_nproc(void)
+{
+	int		ncpu;
+	size_t		len = sizeof(ncpu);
+	static int	mib[2] = {CTL_HW, HW_NCPU};
+
+	if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0)
+		ncpu = 1;
+
+	return ncpu;
+}
+
+unsigned long
+platform_physmem(void)
+{
+	unsigned long	physmem;
+	size_t		len = sizeof(physmem);
+	static int	mib[2] = {CTL_HW, HW_PHYSMEM};
+
+	if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) {
+		fprintf(stderr, _("%s: can't determine memory size\n"),
+			progname);
+		exit(1);
+	}
+	return physmem >> 10;
+}
diff --git a/libfrog/freebsd.c b/libfrog/freebsd.c
new file mode 100644
index 0000000..d9fc837
--- /dev/null
+++ b/libfrog/freebsd.c
@@ -0,0 +1,205 @@
+/*
+ * Copyright (c) 2003,2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "libxfs.h"
+#include <sys/stat.h>
+#include <sys/disk.h>
+#include <sys/mount.h>
+#include <sys/ioctl.h>
+#include <sys/sysctl.h>
+
+int platform_has_uuid = 1;
+extern char *progname;
+
+#warning "FreeBSD support is deprecated and planned for removal in July 2018"
+#warning "Contact linux-xfs@vger.kernel.org if you'd like to maintain this port"
+#error   "Remove this line if you'd like to continue the build"
+
+int
+platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
+{
+	struct stat	st;
+        int cnt, i;
+        struct statfs *fsinfo;
+
+	if (!s) {
+		if (stat(block, &st) < 0)
+			return 0;
+		s = &st;
+	}
+
+	/* Remember, FreeBSD can now mount char devices! -- adrian */
+	if (((st.st_mode & S_IFMT) != S_IFBLK) &&
+	    ((st.st_mode & S_IFMT) != S_IFCHR))
+		return 0;
+
+	if ((cnt = getmntinfo(&fsinfo, MNT_NOWAIT)) == 0) {
+		fprintf(stderr,
+		    _("%s: %s possibly contains a mounted filesystem\n"),
+		    progname, name);
+		return 1;
+	}
+
+        for (i = 0; i < cnt; i++) {
+                if (strcmp (name, fsinfo[i].f_mntfromname) != 0)
+			continue;
+
+		if (verbose)
+			fprintf(stderr,
+			    _("%s: %s contains a mounted filesystem\n"),
+			    progname, name);
+		break;
+	}
+
+        return i < cnt;
+}
+
+int
+platform_check_iswritable(char *name, char *block, struct stat *s)
+{
+        int cnt, i;
+        struct statfs *fsinfo;
+
+        if ((cnt = getmntinfo(&fsinfo, MNT_NOWAIT)) == 0) {
+		fprintf(stderr, _("%s: %s contains a possibly writable, "
+				"mounted filesystem\n"), progname, name);
+			return 1;
+	}
+
+        for (i = 0; i < cnt; i++) {
+                if (strcmp (name, fsinfo[i].f_mntfromname) != 0)
+			continue;
+
+		if (fsinfo[i].f_flags &= MNT_RDONLY)
+			break;
+	}
+
+        if (i == cnt) {
+		fprintf(stderr, _("%s: %s contains a mounted and writable "
+				"filesystem\n"), progname, name);
+		return 1;
+	}
+	return 0;
+}
+
+int
+platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
+{
+	return fatal;
+}
+
+void
+platform_flush_device(int fd, dev_t device)
+{
+	return;
+}
+
+void
+platform_findsizes(char *path, int fd, long long *sz, int *bsz)
+{
+	struct stat	st;
+	int64_t		size;
+	uint		ssize;
+
+	if (fstat(fd, &st) < 0) {
+		fprintf(stderr, _("%s: "
+			"cannot stat the device file \"%s\": %s\n"),
+			progname, path, strerror(errno));
+		exit(1);
+	}
+
+	if ((st.st_mode & S_IFMT) == S_IFREG) {
+		*sz = (long long)(st.st_size >> 9);
+		*bsz = 512;
+		return;
+	}
+
+	if ((st.st_mode & S_IFMT) != S_IFCHR) {
+		fprintf(stderr, _("%s: Not a device or file: \"%s\"\n"),
+			progname, path);
+		exit(1);
+	}
+
+	if (ioctl(fd, DIOCGMEDIASIZE, &size) != 0) {
+		fprintf(stderr, _("%s: DIOCGMEDIASIZE failed on \"%s\": %s\n"),
+			progname, path, strerror(errno));
+		exit(1);
+	}
+
+	if (ioctl(fd, DIOCGSECTORSIZE, &ssize) != 0) {
+		fprintf(stderr, _("%s: "
+			"DIOCGSECTORSIZE failed on \"%s\": %s\n"),
+			progname, path, strerror(errno));
+		exit(1);
+	}
+
+	*sz = (long long) (size / ssize);
+	*bsz = (int)ssize;
+}
+
+char *
+platform_findrawpath(char *path)
+{
+	return path;
+}
+
+char *
+platform_findblockpath(char *path)
+{
+	return path;
+}
+
+int
+platform_direct_blockdev(void)
+{
+	return 0;
+}
+
+int
+platform_align_blockdev(void)
+{
+	return sizeof(void *);
+}
+
+int
+platform_nproc(void)
+{
+	int		ncpu;
+	size_t		len = sizeof(ncpu);
+	static int	mib[2] = {CTL_HW, HW_NCPU};
+
+	if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0)
+		ncpu = 1;
+
+	return ncpu;
+}
+
+unsigned long
+platform_physmem(void)
+{
+	unsigned long	physmem;
+	size_t		len = sizeof(physmem);
+	static int	mib[2] = {CTL_HW, HW_PHYSMEM};
+
+	if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) {
+		fprintf(stderr, _("%s: can't determine memory size\n"),
+			progname);
+		exit(1);
+	}
+	return physmem >> 10;
+}
diff --git a/libfrog/irix.c b/libfrog/irix.c
new file mode 100644
index 0000000..4ad68d5
--- /dev/null
+++ b/libfrog/irix.c
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "libxfs.h"
+#include <diskinfo.h>
+#include <sys/sysmp.h>
+
+int platform_has_uuid = 0;
+extern char *progname;
+extern int64_t findsize(char *);
+
+#warning "IRIX support is deprecated and planned for removal in July 2018"
+#warning "Contact linux-xfs@vger.kernel.org if you'd like to maintain this port"
+#error   "Remove this line if you'd like to continue the build"
+
+int
+platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
+{
+	return 0;
+}
+
+int
+platform_check_iswritable(char *name, char *block, struct stat *s)
+{
+	return 1;
+}
+
+int
+platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
+{
+	return fatal;
+}
+
+void
+platform_flush_device(int fd, dev_t device)
+{
+	return;
+}
+
+void
+platform_findsizes(char *path, int fd, long long *sz, int *bsz)
+{
+	struct stat		st;
+
+	if (fstat(fd, &st) < 0) {
+		fprintf(stderr,
+			_("%s: cannot stat the device file \"%s\": %s\n"),
+			progname, path, strerror(errno));
+		exit(1);
+	}
+	if ((st.st_mode & S_IFMT) == S_IFREG) {
+		*sz = (long long)(st.st_size >> 9);
+	} else {
+		*sz = findsize(path);
+	}
+	*bsz = BBSIZE;
+}
+
+char *
+platform_findrawpath(char *path)
+{
+	return findrawpath(path);
+}
+
+char *
+platform_findblockpath(char *path)
+{
+	return findblockpath(path);
+}
+
+int
+platform_direct_blockdev(void)
+{
+	return 0;
+}
+
+int
+platform_align_blockdev(void)
+{
+	return sizeof(void *);
+}
+
+int
+platform_nproc(void)
+{
+	return sysmp(MP_NPROCS);
+}
+
+unsigned long
+platform_physmem(void)
+{
+	struct rminfo ri;
+
+	if (sysmp(MP_SAGET, MPSA_RMINFO, &ri, sizeof(ri)) < 0)
+		fprintf(stderr, _("%s: can't determine memory size\n"),
+			progname);
+		exit(1);
+	}
+	return (ri.physmem >> 10) * getpagesize();	/* kilobytes */
+}
diff --git a/libfrog/linux.c b/libfrog/linux.c
new file mode 100644
index 0000000..0bace3e
--- /dev/null
+++ b/libfrog/linux.c
@@ -0,0 +1,265 @@
+/*
+ * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include <mntent.h>
+#include <sys/stat.h>
+#include <sys/mount.h>
+#include <sys/ioctl.h>
+#include <sys/sysinfo.h>
+
+#include "libxfs_priv.h"
+#include "xfs_fs.h"
+
+int platform_has_uuid = 1;
+extern char *progname;
+static int max_block_alignment;
+
+#ifndef BLKGETSIZE64
+# define BLKGETSIZE64	_IOR(0x12,114,size_t)
+#endif
+#ifndef BLKBSZSET
+# define BLKBSZSET	_IOW(0x12,113,size_t)
+#endif
+#ifndef BLKSSZGET
+# define BLKSSZGET	_IO(0x12,104)
+#endif
+
+#ifndef RAMDISK_MAJOR
+#define RAMDISK_MAJOR	1	/* ramdisk major number */
+#endif
+
+#define PROC_MOUNTED	"/proc/mounts"
+
+/*
+ * Check if the filesystem is mounted.  Be verbose if asked, and
+ * optionally restrict check to /writable/ mounts (i.e. RO is OK)
+ */
+#define	CHECK_MOUNT_VERBOSE	0x1
+#define	CHECK_MOUNT_WRITABLE	0x2
+
+static int
+platform_check_mount(char *name, char *block, struct stat *s, int flags)
+{
+	FILE		*f;
+	struct stat	st, mst;
+	struct mntent	*mnt;
+	char		mounts[MAXPATHLEN];
+
+	if (!s) {
+		/* If either fails we are not mounted */
+		if (stat(block, &st) < 0)
+			return 0;
+		if ((st.st_mode & S_IFMT) != S_IFBLK)
+			return 0;
+		s = &st;
+	}
+
+	strcpy(mounts, (!access(PROC_MOUNTED, R_OK)) ? PROC_MOUNTED : MOUNTED);
+	if ((f = setmntent(mounts, "r")) == NULL) {
+		/* Unexpected failure, warn unconditionally */
+		fprintf(stderr,
+		    _("%s: %s possibly contains a mounted filesystem\n"),
+		    progname, name);
+		return 1;
+	}
+	while ((mnt = getmntent(f)) != NULL) {
+		if (stat(mnt->mnt_dir, &mst) < 0)
+			continue;
+		if (mst.st_dev != s->st_rdev)
+			continue;
+		/* Found our device, is RO OK? */
+		if ((flags & CHECK_MOUNT_WRITABLE) && hasmntopt(mnt, MNTOPT_RO))
+			continue;
+		else
+			break;
+	}
+	endmntent(f);
+
+	/* No mounts contained the condition we were looking for */
+	if (mnt == NULL)
+		return 0;
+
+	if (flags & CHECK_MOUNT_VERBOSE) {
+		if (flags & CHECK_MOUNT_WRITABLE) {
+			fprintf(stderr,
+_("%s: %s contains a mounted and writable filesystem\n"),
+				progname, name);
+		} else {
+			fprintf(stderr,
+_("%s: %s contains a mounted filesystem\n"),
+				progname, name);
+		}
+	}
+	return 1;
+}
+
+int
+platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
+{
+	int flags;
+
+	flags = verbose ? CHECK_MOUNT_VERBOSE : 0;
+	return platform_check_mount(name, block, s, flags);
+}
+
+int
+platform_check_iswritable(char *name, char *block, struct stat *s)
+{
+	int flags;
+
+	/* Writable checks are always verbose */
+	flags = CHECK_MOUNT_WRITABLE | CHECK_MOUNT_VERBOSE;
+	return platform_check_mount(name, block, s, flags);
+}
+
+int
+platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int 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));
+		}
+	}
+	return error;
+}
+
+void
+platform_flush_device(int fd, dev_t device)
+{
+	struct stat	st;
+	if (major(device) == RAMDISK_MAJOR)
+		return;
+
+	if (fstat(fd, &st) < 0)
+		return;
+
+	if (S_ISREG(st.st_mode))
+		fsync(fd);
+	else
+		ioctl(fd, BLKFLSBUF, 0);
+}
+
+void
+platform_findsizes(char *path, int fd, long long *sz, int *bsz)
+{
+	struct stat	st;
+	uint64_t	size;
+	int		error;
+
+	if (fstat(fd, &st) < 0) {
+		fprintf(stderr, _("%s: "
+			"cannot stat the device file \"%s\": %s\n"),
+			progname, path, strerror(errno));
+		exit(1);
+	}
+
+	if ((st.st_mode & S_IFMT) == S_IFREG) {
+		struct dioattr	da;
+
+		*sz = (long long)(st.st_size >> 9);
+
+		if (ioctl(fd, XFS_IOC_DIOINFO, &da) < 0) {
+			/*
+			 * fall back to BBSIZE; mkfs might fail if there's a
+			 * size mismatch between the image & the host fs...
+			 */
+			*bsz = BBSIZE;
+		} else
+			*bsz = da.d_miniosz;
+
+		if (*bsz > max_block_alignment)
+			max_block_alignment = *bsz;
+		return;
+	}
+
+	error = ioctl(fd, BLKGETSIZE64, &size);
+	if (error >= 0) {
+		/* BLKGETSIZE64 returns size in bytes not 512-byte blocks */
+		*sz = (long long)(size >> 9);
+	} else {
+		/* If BLKGETSIZE64 fails, try BLKGETSIZE */
+		unsigned long tmpsize;
+
+		error = ioctl(fd, BLKGETSIZE, &tmpsize);
+		if (error < 0) {
+			fprintf(stderr, _("%s: can't determine device size\n"),
+				progname);
+			exit(1);
+		}
+		*sz = (long long)tmpsize;
+	}
+
+	if (ioctl(fd, BLKSSZGET, bsz) < 0) {
+		fprintf(stderr, _("%s: warning - cannot get sector size "
+				"from block device %s: %s\n"),
+			progname, path, strerror(errno));
+		*bsz = BBSIZE;
+	}
+	if (*bsz > max_block_alignment)
+		max_block_alignment = *bsz;
+}
+
+char *
+platform_findrawpath(char *path)
+{
+	return path;
+}
+
+char *
+platform_findblockpath(char *path)
+{
+	return path;
+}
+
+int
+platform_direct_blockdev(void)
+{
+	return 1;
+}
+
+int
+platform_align_blockdev(void)
+{
+	if (!max_block_alignment)
+		return getpagesize();
+	return max_block_alignment;
+}
+
+int
+platform_nproc(void)
+{
+	return sysconf(_SC_NPROCESSORS_ONLN);
+}
+
+unsigned long
+platform_physmem(void)
+{
+	struct sysinfo  si;
+
+	if (sysinfo(&si) < 0) {
+		fprintf(stderr, _("%s: can't determine memory size\n"),
+			progname);
+		exit(1);
+	}
+	return (si.totalram >> 10) * si.mem_unit;	/* kilobytes */
+}
diff --git a/libxfs/Makefile b/libxfs/Makefile
index 0470f5f..7cde18d 100644
--- a/libxfs/Makefile
+++ b/libxfs/Makefile
@@ -97,9 +97,6 @@ CFILES = cache.c \
 	xfs_symlink_remote.c \
 	xfs_trans_resv.c
 
-CFILES += $(PKG_PLATFORM).c
-PCFILES = darwin.c freebsd.c irix.c linux.c
-LSRCFILES = $(shell echo $(PCFILES) | sed -e "s/$(PKG_PLATFORM).c//g")
 LSRCFILES += gen_crc32table.c
 
 #
diff --git a/libxfs/darwin.c b/libxfs/darwin.c
deleted file mode 100644
index 396477e..0000000
--- a/libxfs/darwin.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Copyright (c) 2003,2005 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include <sys/disk.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-#include <sys/ioctl.h>
-#include <sys/sysctl.h>
-#include "libxfs.h"
-
-int platform_has_uuid = 1;
-extern char *progname;
-
-#warning "Darwin support is deprecated and planned for removal in July 2018"
-#warning "Contact linux-xfs@vger.kernel.org if you'd like to maintain this port"
-#error   "Remove this line if you'd like to continue the build"
-
-int
-platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
-{
-	return 0;
-}
-
-int
-platform_check_iswritable(char *name, char *block, struct stat *s)
-{
-	int	fd, writable;
-
-	if ((fd = open(block, O_RDONLY, 0)) < 0) {
-		fprintf(stderr, _("%s: "
-			"error opening the device special file \"%s\": %s\n"),
-			progname, block, strerror(errno));
-		exit(1);
-	}
-
-	if (ioctl(fd, DKIOCISWRITABLE, &writable) < 0) {
-		fprintf(stderr, _("%s: can't tell if \"%s\" is writable: %s\n"),
-			progname, block, strerror(errno));
-		exit(1);
-	}
-	close(fd);
-	return writable == 0;
-}
-
-int
-platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
-{
-	return fatal;
-}
-
-void
-platform_flush_device(int fd, dev_t device)
-{
-	ioctl(fd, DKIOCSYNCHRONIZECACHE, NULL);
-}
-
-void
-platform_findsizes(char *path, int fd, long long *sz, int *bsz)
-{
-	uint64_t	size;
-	struct stat	st;
-
-	if (fstat(fd, &st) < 0) {
-		fprintf(stderr,
-			_("%s: cannot stat the device file \"%s\": %s\n"),
-			progname, path, strerror(errno));
-		exit(1);
-	}
-	if ((st.st_mode & S_IFMT) == S_IFREG) {
-		*sz = (long long)(st.st_size >> 9);
-		*bsz = BBSIZE;
-		return;
-	}
-	if (ioctl(fd, DKIOCGETBLOCKCOUNT, &size) < 0) {
-		fprintf(stderr, _("%s: can't determine device size: %s\n"),
-			progname, strerror(errno));
-		exit(1);
-	}
-	*sz = (long long)size;
-	*bsz = BBSIZE;
-}
-
-char *
-platform_findrawpath(char *path)
-{
-	return path;
-}
-
-char *
-platform_findblockpath(char *path)
-{
-	return path;
-}
-
-int
-platform_direct_blockdev(void)
-{
-	return 0;
-}
-
-int
-platform_align_blockdev(void)
-{
-	return sizeof(void *);
-}
-
-int
-platform_nproc(void)
-{
-	int		ncpu;
-	size_t		len = sizeof(ncpu);
-	static int	mib[2] = {CTL_HW, HW_NCPU};
-
-	if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0)
-		ncpu = 1;
-
-	return ncpu;
-}
-
-unsigned long
-platform_physmem(void)
-{
-	unsigned long	physmem;
-	size_t		len = sizeof(physmem);
-	static int	mib[2] = {CTL_HW, HW_PHYSMEM};
-
-	if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) {
-		fprintf(stderr, _("%s: can't determine memory size\n"),
-			progname);
-		exit(1);
-	}
-	return physmem >> 10;
-}
diff --git a/libxfs/freebsd.c b/libxfs/freebsd.c
deleted file mode 100644
index d9fc837..0000000
--- a/libxfs/freebsd.c
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Copyright (c) 2003,2005 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "libxfs.h"
-#include <sys/stat.h>
-#include <sys/disk.h>
-#include <sys/mount.h>
-#include <sys/ioctl.h>
-#include <sys/sysctl.h>
-
-int platform_has_uuid = 1;
-extern char *progname;
-
-#warning "FreeBSD support is deprecated and planned for removal in July 2018"
-#warning "Contact linux-xfs@vger.kernel.org if you'd like to maintain this port"
-#error   "Remove this line if you'd like to continue the build"
-
-int
-platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
-{
-	struct stat	st;
-        int cnt, i;
-        struct statfs *fsinfo;
-
-	if (!s) {
-		if (stat(block, &st) < 0)
-			return 0;
-		s = &st;
-	}
-
-	/* Remember, FreeBSD can now mount char devices! -- adrian */
-	if (((st.st_mode & S_IFMT) != S_IFBLK) &&
-	    ((st.st_mode & S_IFMT) != S_IFCHR))
-		return 0;
-
-	if ((cnt = getmntinfo(&fsinfo, MNT_NOWAIT)) == 0) {
-		fprintf(stderr,
-		    _("%s: %s possibly contains a mounted filesystem\n"),
-		    progname, name);
-		return 1;
-	}
-
-        for (i = 0; i < cnt; i++) {
-                if (strcmp (name, fsinfo[i].f_mntfromname) != 0)
-			continue;
-
-		if (verbose)
-			fprintf(stderr,
-			    _("%s: %s contains a mounted filesystem\n"),
-			    progname, name);
-		break;
-	}
-
-        return i < cnt;
-}
-
-int
-platform_check_iswritable(char *name, char *block, struct stat *s)
-{
-        int cnt, i;
-        struct statfs *fsinfo;
-
-        if ((cnt = getmntinfo(&fsinfo, MNT_NOWAIT)) == 0) {
-		fprintf(stderr, _("%s: %s contains a possibly writable, "
-				"mounted filesystem\n"), progname, name);
-			return 1;
-	}
-
-        for (i = 0; i < cnt; i++) {
-                if (strcmp (name, fsinfo[i].f_mntfromname) != 0)
-			continue;
-
-		if (fsinfo[i].f_flags &= MNT_RDONLY)
-			break;
-	}
-
-        if (i == cnt) {
-		fprintf(stderr, _("%s: %s contains a mounted and writable "
-				"filesystem\n"), progname, name);
-		return 1;
-	}
-	return 0;
-}
-
-int
-platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
-{
-	return fatal;
-}
-
-void
-platform_flush_device(int fd, dev_t device)
-{
-	return;
-}
-
-void
-platform_findsizes(char *path, int fd, long long *sz, int *bsz)
-{
-	struct stat	st;
-	int64_t		size;
-	uint		ssize;
-
-	if (fstat(fd, &st) < 0) {
-		fprintf(stderr, _("%s: "
-			"cannot stat the device file \"%s\": %s\n"),
-			progname, path, strerror(errno));
-		exit(1);
-	}
-
-	if ((st.st_mode & S_IFMT) == S_IFREG) {
-		*sz = (long long)(st.st_size >> 9);
-		*bsz = 512;
-		return;
-	}
-
-	if ((st.st_mode & S_IFMT) != S_IFCHR) {
-		fprintf(stderr, _("%s: Not a device or file: \"%s\"\n"),
-			progname, path);
-		exit(1);
-	}
-
-	if (ioctl(fd, DIOCGMEDIASIZE, &size) != 0) {
-		fprintf(stderr, _("%s: DIOCGMEDIASIZE failed on \"%s\": %s\n"),
-			progname, path, strerror(errno));
-		exit(1);
-	}
-
-	if (ioctl(fd, DIOCGSECTORSIZE, &ssize) != 0) {
-		fprintf(stderr, _("%s: "
-			"DIOCGSECTORSIZE failed on \"%s\": %s\n"),
-			progname, path, strerror(errno));
-		exit(1);
-	}
-
-	*sz = (long long) (size / ssize);
-	*bsz = (int)ssize;
-}
-
-char *
-platform_findrawpath(char *path)
-{
-	return path;
-}
-
-char *
-platform_findblockpath(char *path)
-{
-	return path;
-}
-
-int
-platform_direct_blockdev(void)
-{
-	return 0;
-}
-
-int
-platform_align_blockdev(void)
-{
-	return sizeof(void *);
-}
-
-int
-platform_nproc(void)
-{
-	int		ncpu;
-	size_t		len = sizeof(ncpu);
-	static int	mib[2] = {CTL_HW, HW_NCPU};
-
-	if (sysctl(mib, 2, &ncpu, &len, NULL, 0) < 0)
-		ncpu = 1;
-
-	return ncpu;
-}
-
-unsigned long
-platform_physmem(void)
-{
-	unsigned long	physmem;
-	size_t		len = sizeof(physmem);
-	static int	mib[2] = {CTL_HW, HW_PHYSMEM};
-
-	if (sysctl(mib, 2, &physmem, &len, NULL, 0) < 0) {
-		fprintf(stderr, _("%s: can't determine memory size\n"),
-			progname);
-		exit(1);
-	}
-	return physmem >> 10;
-}
diff --git a/libxfs/irix.c b/libxfs/irix.c
deleted file mode 100644
index 4ad68d5..0000000
--- a/libxfs/irix.c
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "libxfs.h"
-#include <diskinfo.h>
-#include <sys/sysmp.h>
-
-int platform_has_uuid = 0;
-extern char *progname;
-extern int64_t findsize(char *);
-
-#warning "IRIX support is deprecated and planned for removal in July 2018"
-#warning "Contact linux-xfs@vger.kernel.org if you'd like to maintain this port"
-#error   "Remove this line if you'd like to continue the build"
-
-int
-platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
-{
-	return 0;
-}
-
-int
-platform_check_iswritable(char *name, char *block, struct stat *s)
-{
-	return 1;
-}
-
-int
-platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int fatal)
-{
-	return fatal;
-}
-
-void
-platform_flush_device(int fd, dev_t device)
-{
-	return;
-}
-
-void
-platform_findsizes(char *path, int fd, long long *sz, int *bsz)
-{
-	struct stat		st;
-
-	if (fstat(fd, &st) < 0) {
-		fprintf(stderr,
-			_("%s: cannot stat the device file \"%s\": %s\n"),
-			progname, path, strerror(errno));
-		exit(1);
-	}
-	if ((st.st_mode & S_IFMT) == S_IFREG) {
-		*sz = (long long)(st.st_size >> 9);
-	} else {
-		*sz = findsize(path);
-	}
-	*bsz = BBSIZE;
-}
-
-char *
-platform_findrawpath(char *path)
-{
-	return findrawpath(path);
-}
-
-char *
-platform_findblockpath(char *path)
-{
-	return findblockpath(path);
-}
-
-int
-platform_direct_blockdev(void)
-{
-	return 0;
-}
-
-int
-platform_align_blockdev(void)
-{
-	return sizeof(void *);
-}
-
-int
-platform_nproc(void)
-{
-	return sysmp(MP_NPROCS);
-}
-
-unsigned long
-platform_physmem(void)
-{
-	struct rminfo ri;
-
-	if (sysmp(MP_SAGET, MPSA_RMINFO, &ri, sizeof(ri)) < 0)
-		fprintf(stderr, _("%s: can't determine memory size\n"),
-			progname);
-		exit(1);
-	}
-	return (ri.physmem >> 10) * getpagesize();	/* kilobytes */
-}
diff --git a/libxfs/linux.c b/libxfs/linux.c
deleted file mode 100644
index 0bace3e..0000000
--- a/libxfs/linux.c
+++ /dev/null
@@ -1,265 +0,0 @@
-/*
- * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include <mntent.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-#include <sys/ioctl.h>
-#include <sys/sysinfo.h>
-
-#include "libxfs_priv.h"
-#include "xfs_fs.h"
-
-int platform_has_uuid = 1;
-extern char *progname;
-static int max_block_alignment;
-
-#ifndef BLKGETSIZE64
-# define BLKGETSIZE64	_IOR(0x12,114,size_t)
-#endif
-#ifndef BLKBSZSET
-# define BLKBSZSET	_IOW(0x12,113,size_t)
-#endif
-#ifndef BLKSSZGET
-# define BLKSSZGET	_IO(0x12,104)
-#endif
-
-#ifndef RAMDISK_MAJOR
-#define RAMDISK_MAJOR	1	/* ramdisk major number */
-#endif
-
-#define PROC_MOUNTED	"/proc/mounts"
-
-/*
- * Check if the filesystem is mounted.  Be verbose if asked, and
- * optionally restrict check to /writable/ mounts (i.e. RO is OK)
- */
-#define	CHECK_MOUNT_VERBOSE	0x1
-#define	CHECK_MOUNT_WRITABLE	0x2
-
-static int
-platform_check_mount(char *name, char *block, struct stat *s, int flags)
-{
-	FILE		*f;
-	struct stat	st, mst;
-	struct mntent	*mnt;
-	char		mounts[MAXPATHLEN];
-
-	if (!s) {
-		/* If either fails we are not mounted */
-		if (stat(block, &st) < 0)
-			return 0;
-		if ((st.st_mode & S_IFMT) != S_IFBLK)
-			return 0;
-		s = &st;
-	}
-
-	strcpy(mounts, (!access(PROC_MOUNTED, R_OK)) ? PROC_MOUNTED : MOUNTED);
-	if ((f = setmntent(mounts, "r")) == NULL) {
-		/* Unexpected failure, warn unconditionally */
-		fprintf(stderr,
-		    _("%s: %s possibly contains a mounted filesystem\n"),
-		    progname, name);
-		return 1;
-	}
-	while ((mnt = getmntent(f)) != NULL) {
-		if (stat(mnt->mnt_dir, &mst) < 0)
-			continue;
-		if (mst.st_dev != s->st_rdev)
-			continue;
-		/* Found our device, is RO OK? */
-		if ((flags & CHECK_MOUNT_WRITABLE) && hasmntopt(mnt, MNTOPT_RO))
-			continue;
-		else
-			break;
-	}
-	endmntent(f);
-
-	/* No mounts contained the condition we were looking for */
-	if (mnt == NULL)
-		return 0;
-
-	if (flags & CHECK_MOUNT_VERBOSE) {
-		if (flags & CHECK_MOUNT_WRITABLE) {
-			fprintf(stderr,
-_("%s: %s contains a mounted and writable filesystem\n"),
-				progname, name);
-		} else {
-			fprintf(stderr,
-_("%s: %s contains a mounted filesystem\n"),
-				progname, name);
-		}
-	}
-	return 1;
-}
-
-int
-platform_check_ismounted(char *name, char *block, struct stat *s, int verbose)
-{
-	int flags;
-
-	flags = verbose ? CHECK_MOUNT_VERBOSE : 0;
-	return platform_check_mount(name, block, s, flags);
-}
-
-int
-platform_check_iswritable(char *name, char *block, struct stat *s)
-{
-	int flags;
-
-	/* Writable checks are always verbose */
-	flags = CHECK_MOUNT_WRITABLE | CHECK_MOUNT_VERBOSE;
-	return platform_check_mount(name, block, s, flags);
-}
-
-int
-platform_set_blocksize(int fd, char *path, dev_t device, int blocksize, int 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));
-		}
-	}
-	return error;
-}
-
-void
-platform_flush_device(int fd, dev_t device)
-{
-	struct stat	st;
-	if (major(device) == RAMDISK_MAJOR)
-		return;
-
-	if (fstat(fd, &st) < 0)
-		return;
-
-	if (S_ISREG(st.st_mode))
-		fsync(fd);
-	else
-		ioctl(fd, BLKFLSBUF, 0);
-}
-
-void
-platform_findsizes(char *path, int fd, long long *sz, int *bsz)
-{
-	struct stat	st;
-	uint64_t	size;
-	int		error;
-
-	if (fstat(fd, &st) < 0) {
-		fprintf(stderr, _("%s: "
-			"cannot stat the device file \"%s\": %s\n"),
-			progname, path, strerror(errno));
-		exit(1);
-	}
-
-	if ((st.st_mode & S_IFMT) == S_IFREG) {
-		struct dioattr	da;
-
-		*sz = (long long)(st.st_size >> 9);
-
-		if (ioctl(fd, XFS_IOC_DIOINFO, &da) < 0) {
-			/*
-			 * fall back to BBSIZE; mkfs might fail if there's a
-			 * size mismatch between the image & the host fs...
-			 */
-			*bsz = BBSIZE;
-		} else
-			*bsz = da.d_miniosz;
-
-		if (*bsz > max_block_alignment)
-			max_block_alignment = *bsz;
-		return;
-	}
-
-	error = ioctl(fd, BLKGETSIZE64, &size);
-	if (error >= 0) {
-		/* BLKGETSIZE64 returns size in bytes not 512-byte blocks */
-		*sz = (long long)(size >> 9);
-	} else {
-		/* If BLKGETSIZE64 fails, try BLKGETSIZE */
-		unsigned long tmpsize;
-
-		error = ioctl(fd, BLKGETSIZE, &tmpsize);
-		if (error < 0) {
-			fprintf(stderr, _("%s: can't determine device size\n"),
-				progname);
-			exit(1);
-		}
-		*sz = (long long)tmpsize;
-	}
-
-	if (ioctl(fd, BLKSSZGET, bsz) < 0) {
-		fprintf(stderr, _("%s: warning - cannot get sector size "
-				"from block device %s: %s\n"),
-			progname, path, strerror(errno));
-		*bsz = BBSIZE;
-	}
-	if (*bsz > max_block_alignment)
-		max_block_alignment = *bsz;
-}
-
-char *
-platform_findrawpath(char *path)
-{
-	return path;
-}
-
-char *
-platform_findblockpath(char *path)
-{
-	return path;
-}
-
-int
-platform_direct_blockdev(void)
-{
-	return 1;
-}
-
-int
-platform_align_blockdev(void)
-{
-	if (!max_block_alignment)
-		return getpagesize();
-	return max_block_alignment;
-}
-
-int
-platform_nproc(void)
-{
-	return sysconf(_SC_NPROCESSORS_ONLN);
-}
-
-unsigned long
-platform_physmem(void)
-{
-	struct sysinfo  si;
-
-	if (sysinfo(&si) < 0) {
-		fprintf(stderr, _("%s: can't determine memory size\n"),
-			progname);
-		exit(1);
-	}
-	return (si.totalram >> 10) * si.mem_unit;	/* kilobytes */
-}


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 2/9] libfrog: refactor fs geometry printing function
  2018-04-18  2:45 [PATCH 0/9] xfsprogs-4.17: geometry refactoring Darrick J. Wong
  2018-04-18  2:45 ` [PATCH 1/9] libfrog: move platform specific runtime support code out of libxfs Darrick J. Wong
@ 2018-04-18  2:45 ` Darrick J. Wong
  2018-05-03 18:47   ` Eric Sandeen
  2018-05-03 21:27   ` Eric Sandeen
  2018-04-18  2:45 ` [PATCH 3/9] mkfs: use geometry generation / helper functions Darrick J. Wong
                   ` (6 subsequent siblings)
  8 siblings, 2 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-04-18  2:45 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Move the fs geometry printing function to libfrog so that mkfs and others
can share.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 include/fsgeom.h |   24 ++++++++++++++++
 libfrog/Makefile |    1 +
 libfrog/fsgeom.c |   82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 107 insertions(+)
 create mode 100644 include/fsgeom.h
 create mode 100644 libfrog/fsgeom.c


diff --git a/include/fsgeom.h b/include/fsgeom.h
new file mode 100644
index 0000000..acf11bf
--- /dev/null
+++ b/include/fsgeom.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2000-2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#ifndef _LIBFROG_FSGEOM_H_
+#define _LIBFROG_FSGEOM_H_
+
+void xfs_report_geom(struct xfs_fsop_geom *geo, const char *mntpoint,
+		const char *logname, const char *rtname);
+
+#endif /* _LIBFROG_FSGEOM_H_ */
diff --git a/libfrog/Makefile b/libfrog/Makefile
index 21bb5b7..f682829 100644
--- a/libfrog/Makefile
+++ b/libfrog/Makefile
@@ -13,6 +13,7 @@ LT_AGE = 0
 CFILES = \
 avl64.c \
 convert.c \
+fsgeom.c \
 list_sort.c \
 paths.c \
 projects.c \
diff --git a/libfrog/fsgeom.c b/libfrog/fsgeom.c
new file mode 100644
index 0000000..cbe847a
--- /dev/null
+++ b/libfrog/fsgeom.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2000-2005 Silicon Graphics, Inc.
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+#include "libxfs.h"
+#include "fsgeom.h"
+
+void
+xfs_report_geom(
+	struct xfs_fsop_geom	*geo,
+	const char		*mntpoint,
+	const char		*logname,
+	const char		*rtname)
+{
+	int			isint;
+	int			lazycount;
+	int			dirversion;
+	int			logversion;
+	int			attrversion;
+	int			projid32bit;
+	int			crcs_enabled;
+	int			cimode;
+	int			ftype_enabled;
+	int			finobt_enabled;
+	int			spinodes;
+	int			rmapbt_enabled;
+	int			reflink_enabled;
+
+	isint = geo->logstart > 0;
+	lazycount = geo->flags & XFS_FSOP_GEOM_FLAGS_LAZYSB ? 1 : 0;
+	dirversion = geo->flags & XFS_FSOP_GEOM_FLAGS_DIRV2 ? 2 : 1;
+	logversion = geo->flags & XFS_FSOP_GEOM_FLAGS_LOGV2 ? 2 : 1;
+	attrversion = geo->flags & XFS_FSOP_GEOM_FLAGS_ATTR2 ? 2 : \
+			(geo->flags & XFS_FSOP_GEOM_FLAGS_ATTR ? 1 : 0);
+	cimode = geo->flags & XFS_FSOP_GEOM_FLAGS_DIRV2CI ? 1 : 0;
+	projid32bit = geo->flags & XFS_FSOP_GEOM_FLAGS_PROJID32 ? 1 : 0;
+	crcs_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_V5SB ? 1 : 0;
+	ftype_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_FTYPE ? 1 : 0;
+	finobt_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_FINOBT ? 1 : 0;
+	spinodes = geo->flags & XFS_FSOP_GEOM_FLAGS_SPINODES ? 1 : 0;
+	rmapbt_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_RMAPBT ? 1 : 0;
+	reflink_enabled = geo->flags & XFS_FSOP_GEOM_FLAGS_REFLINK ? 1 : 0;
+
+	printf(_(
+"meta-data=%-22s isize=%-6d agcount=%u, agsize=%u blks\n"
+"         =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
+"         =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u\n"
+"         =%-22s reflink=%u\n"
+"data     =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
+"         =%-22s sunit=%-6u swidth=%u blks\n"
+"naming   =version %-14u bsize=%-6u ascii-ci=%d, ftype=%d\n"
+"log      =%-22s bsize=%-6d blocks=%u, version=%d\n"
+"         =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
+"realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),
+		mntpoint, geo->inodesize, geo->agcount, geo->agblocks,
+		"", geo->sectsize, attrversion, projid32bit,
+		"", crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled,
+		"", reflink_enabled,
+		"", geo->blocksize, (unsigned long long)geo->datablocks,
+			geo->imaxpct,
+		"", geo->sunit, geo->swidth,
+		dirversion, geo->dirblocksize, cimode, ftype_enabled,
+		isint ? _("internal log") : logname ? logname : _("external"),
+			geo->blocksize, geo->logblocks, logversion,
+		"", geo->logsectsize, geo->logsunit / geo->blocksize, lazycount,
+		!geo->rtblocks ? _("none") : rtname ? rtname : _("external"),
+		geo->rtextsize * geo->blocksize, (unsigned long long)geo->rtblocks,
+			(unsigned long long)geo->rtextents);
+}


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 3/9] mkfs: use geometry generation / helper functions
  2018-04-18  2:45 [PATCH 0/9] xfsprogs-4.17: geometry refactoring Darrick J. Wong
  2018-04-18  2:45 ` [PATCH 1/9] libfrog: move platform specific runtime support code out of libxfs Darrick J. Wong
  2018-04-18  2:45 ` [PATCH 2/9] libfrog: refactor fs geometry printing function Darrick J. Wong
@ 2018-04-18  2:45 ` Darrick J. Wong
  2018-05-03 18:52   ` Eric Sandeen
  2018-04-18  2:45 ` [PATCH 4/9] xfs_db: add a superblock info command Darrick J. Wong
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 34+ messages in thread
From: Darrick J. Wong @ 2018-04-18  2:45 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Since libxfs now has a function to fill out the geometry structure
and libfrog has a function to pretty-print the geometry, have mkfs
use the two helpers instead of open-coding it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 libxfs/libxfs_api_defs.h |    1 +
 mkfs/xfs_mkfs.c          |   54 ++++++++++++++--------------------------------
 2 files changed, 18 insertions(+), 37 deletions(-)


diff --git a/libxfs/libxfs_api_defs.h b/libxfs/libxfs_api_defs.h
index 78daca0..09f1428 100644
--- a/libxfs/libxfs_api_defs.h
+++ b/libxfs/libxfs_api_defs.h
@@ -152,5 +152,6 @@
 #define xfs_rmap_compare		libxfs_rmap_compare
 #define xfs_dir_get_ops			libxfs_dir_get_ops
 #define xfs_default_ifork_ops		libxfs_default_ifork_ops
+#define xfs_fs_geometry			libxfs_fs_geometry
 
 #endif /* __LIBXFS_API_DEFS_H__ */
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 78d0ce5..81f2123 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -20,7 +20,7 @@
 #include <ctype.h>
 #include "xfs_multidisk.h"
 #include "libxcmd.h"
-
+#include "fsgeom.h"
 
 
 #define TERABYTES(count, blog)	((uint64_t)(count) << (40 - (blog)))
@@ -3172,40 +3172,6 @@ initialise_mount(
 	mp->m_sectbb_log = sbp->sb_sectlog - BBSHIFT;
 }
 
-static void
-print_mkfs_cfg(
-	struct mkfs_params	*cfg,
-	char			*dfile,
-	char			*logfile,
-	char			*rtfile)
-{
-	struct sb_feat_args	*fp = &cfg->sb_feat;
-
-	printf(_(
-"meta-data=%-22s isize=%-6d agcount=%lld, agsize=%lld blks\n"
-"         =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
-"         =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u, reflink=%u\n"
-"data     =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
-"         =%-22s sunit=%-6u swidth=%u blks\n"
-"naming   =version %-14u bsize=%-6u ascii-ci=%d ftype=%d\n"
-"log      =%-22s bsize=%-6d blocks=%lld, version=%d\n"
-"         =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
-"realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),
-		dfile, cfg->inodesize, (long long)cfg->agcount,
-			(long long)cfg->agsize,
-		"", cfg->sectorsize, fp->attr_version, fp->projid32bit,
-		"", fp->crcs_enabled, fp->finobt, fp->spinodes, fp->rmapbt,
-			fp->reflink,
-		"", cfg->blocksize, (long long)cfg->dblocks, cfg->imaxpct,
-		"", cfg->dsunit, cfg->dswidth,
-		fp->dir_version, cfg->dirblocksize, fp->nci, fp->dirftype,
-		logfile, cfg->blocksize, (long long)cfg->logblocks,
-			fp->log_version,
-		"", cfg->lsectorsize, cfg->lsunit, fp->lazy_sb_counters,
-		rtfile, (int)cfg->rtextblocks << cfg->blocklog,
-			(long long)cfg->rtblocks, (long long)cfg->rtextents);
-}
-
 /*
  * Format everything from the generated config into the superblock that
  * will be used to initialise the on-disk superblock. This is the in-memory
@@ -3967,12 +3933,26 @@ main(
 	 */
 	calculate_log_size(&cfg, &cli, mp);
 
+	finish_superblock_setup(&cfg, mp, sbp);
+
+	/* Print the intended geometry of the fs. */
 	if (!quiet || dry_run) {
-		print_mkfs_cfg(&cfg, dfile, logfile, rtfile);
+		struct xfs_fsop_geom	geo;
+		int			error;
+
+		error = -libxfs_fs_geometry(sbp, &geo,
+				XFS_FS_GEOM_MAX_STRUCT_VER);
+		if (error) {
+			fprintf(stderr,
+	_("%s: failed to generate filesystem geometry\n"),
+				progname);
+			exit(1);
+		}
+
+		xfs_report_geom(&geo, dfile, logfile, rtfile);
 		if (dry_run)
 			exit(0);
 	}
-	finish_superblock_setup(&cfg, mp, sbp);
 
 	/*
 	 * we need the libxfs buffer cache from here on in.


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 4/9] xfs_db: add a superblock info command
  2018-04-18  2:45 [PATCH 0/9] xfsprogs-4.17: geometry refactoring Darrick J. Wong
                   ` (2 preceding siblings ...)
  2018-04-18  2:45 ` [PATCH 3/9] mkfs: use geometry generation / helper functions Darrick J. Wong
@ 2018-04-18  2:45 ` Darrick J. Wong
  2018-05-03 20:53   ` Eric Sandeen
  2018-05-23  3:30   ` [PATCH v2 " Darrick J. Wong
  2018-04-18  2:46 ` [PATCH 5/9] xfs_spaceman: print a nicer message when the file path isn't on an xfs Darrick J. Wong
                   ` (4 subsequent siblings)
  8 siblings, 2 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-04-18  2:45 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Add an 'info' command to pretty-print the superblock geometry.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/Makefile       |    2 +
 db/command.c      |    1 +
 db/command.h      |    1 +
 db/info.c         |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/man8/xfs_db.8 |    6 ++++
 5 files changed, 83 insertions(+), 1 deletion(-)
 create mode 100644 db/info.c


diff --git a/db/Makefile b/db/Makefile
index 6caa634..c73d7f2 100644
--- a/db/Makefile
+++ b/db/Makefile
@@ -14,7 +14,7 @@ HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
 	io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \
 	sig.h strvec.h text.h type.h write.h attrset.h symlink.h fsmap.h \
 	fuzz.h
-CFILES = $(HFILES:.h=.c) btdump.c
+CFILES = $(HFILES:.h=.c) btdump.c info.c
 LSRCFILES = xfs_admin.sh xfs_ncheck.sh xfs_metadump.sh
 
 LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
diff --git a/db/command.c b/db/command.c
index 12ae5b7..087955e 100644
--- a/db/command.c
+++ b/db/command.c
@@ -136,6 +136,7 @@ init_commands(void)
 	fsmap_init();
 	help_init();
 	hash_init();
+	info_init();
 	inode_init();
 	input_init();
 	logres_init();
diff --git a/db/command.h b/db/command.h
index 9b4ed2d..84cd0b1 100644
--- a/db/command.h
+++ b/db/command.h
@@ -41,3 +41,4 @@ extern const cmdinfo_t	*find_command(const char *cmd);
 extern void		init_commands(void);
 
 extern void		btdump_init(void);
+extern void		info_init(void);
diff --git a/db/info.c b/db/info.c
new file mode 100644
index 0000000..7e7e4db
--- /dev/null
+++ b/db/info.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2018 Oracle.  All Rights Reserved.
+ *
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#include "libxfs.h"
+#include "command.h"
+#include "init.h"
+#include "output.h"
+#include "fsgeom.h"
+
+static void
+info_help(void)
+{
+	dbprintf(_(
+"\n"
+" Pretty-prints the filesystem geometry as derived from the superblock.\n"
+" The output has the same format as mkfs.\n"
+"\n"
+));
+
+}
+
+static int
+info_f(
+	int			argc,
+	char			**argv)
+{
+	struct xfs_fsop_geom	geo;
+	int			error;
+
+	error = -libxfs_fs_geometry(&mp->m_sb, &geo,
+			XFS_FS_GEOM_MAX_STRUCT_VER);
+	if (error) {
+		dbprintf(_("could not obtain geometry\n"));
+		exitcode = 1;
+		return 0;
+	}
+
+	xfs_report_geom(&geo, fsdevice, x.logname, x.rtname);
+	return 0;
+}
+
+static const struct cmdinfo info_cmd = {
+	.name =		"info",
+	.altname =	"i",
+	.cfunc =	info_f,
+	.argmin =	0,
+	.argmax =	0,
+	.canpush =	0,
+	.args =		NULL,
+	.oneline =	N_("dump superblock info"),
+	.help =		info_help,
+};
+
+void
+info_init(void)
+{
+	add_command(&info_cmd);
+}
diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8
index 524b1ef..e29821e 100644
--- a/man/man8/xfs_db.8
+++ b/man/man8/xfs_db.8
@@ -670,6 +670,12 @@ using the hash function of the XFS directory and attribute implementation.
 .BI "help [" command ]
 Print help for one or all commands.
 .TP
+.B info
+Displays selected geometry information about the filesystem.
+The output will have the same format that
+.BR "mkfs.xfs" "(8)"
+prints when creating a filesystem.
+.TP
 .BI "inode [" inode# ]
 Set the current inode number. If no
 .I inode#


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 5/9] xfs_spaceman: print a nicer message when the file path isn't on an xfs
  2018-04-18  2:45 [PATCH 0/9] xfsprogs-4.17: geometry refactoring Darrick J. Wong
                   ` (3 preceding siblings ...)
  2018-04-18  2:45 ` [PATCH 4/9] xfs_db: add a superblock info command Darrick J. Wong
@ 2018-04-18  2:46 ` Darrick J. Wong
  2018-05-03 20:57   ` Eric Sandeen
  2018-05-23  3:31   ` [PATCH v2 " Darrick J. Wong
  2018-04-18  2:46 ` [PATCH 6/9] xfs_spaceman: add a superblock info command Darrick J. Wong
                   ` (3 subsequent siblings)
  8 siblings, 2 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-04-18  2:46 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

If the file path passed in is not something on an xfs filesystem, print
a nice message about that instead of yelling about ioctls.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 spaceman/file.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


diff --git a/spaceman/file.c b/spaceman/file.c
index 4c13b4a..4f9f66c 100644
--- a/spaceman/file.c
+++ b/spaceman/file.c
@@ -69,7 +69,8 @@ openfile(
 	}
 
 	if (ioctl(fd, XFS_IOC_FSGEOMETRY, geom) < 0) {
-		perror("XFS_IOC_FSGEOMETRY");
+		fprintf(stderr, _("%s: Not on a mounted XFS filesystem.\n"),
+				path);
 		close(fd);
 		return -1;
 	}


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 6/9] xfs_spaceman: add a superblock info command
  2018-04-18  2:45 [PATCH 0/9] xfsprogs-4.17: geometry refactoring Darrick J. Wong
                   ` (4 preceding siblings ...)
  2018-04-18  2:46 ` [PATCH 5/9] xfs_spaceman: print a nicer message when the file path isn't on an xfs Darrick J. Wong
@ 2018-04-18  2:46 ` Darrick J. Wong
  2018-05-03 21:09   ` Eric Sandeen
  2018-05-23  3:32   ` [PATCH v2 " Darrick J. Wong
  2018-04-18  2:46 ` [PATCH 7/9] xfs_info: move to xfs_spaceman Darrick J. Wong
                   ` (2 subsequent siblings)
  8 siblings, 2 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-04-18  2:46 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Add an 'info' command to pretty-print the superblock geometry.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 man/man8/xfs_spaceman.8 |    7 +++
 spaceman/Makefile       |    2 -
 spaceman/file.c         |    2 +
 spaceman/info.c         |   96 +++++++++++++++++++++++++++++++++++++++++++++++
 spaceman/init.c         |    1 
 spaceman/space.h        |    1 
 6 files changed, 108 insertions(+), 1 deletion(-)
 create mode 100644 spaceman/info.c


diff --git a/man/man8/xfs_spaceman.8 b/man/man8/xfs_spaceman.8
index e4a9137..12dd04e 100644
--- a/man/man8/xfs_spaceman.8
+++ b/man/man8/xfs_spaceman.8
@@ -84,6 +84,13 @@ Display a summary of the free space information found.
 .PD
 .RE
 .TP
+.B info
+Displays selected geometry information about the filesystem.
+The opened file must be a mount point of a XFS filesystem.
+The output will have the same format that
+.BR "xfs_info" "(8)"
+prints when querying a filesystem.
+.TP
 .BR "help [ " command " ]"
 Display a brief description of one or all commands.
 .TP
diff --git a/spaceman/Makefile b/spaceman/Makefile
index 8b31030..c1d903b 100644
--- a/spaceman/Makefile
+++ b/spaceman/Makefile
@@ -7,7 +7,7 @@ include $(TOPDIR)/include/builddefs
 
 LTCOMMAND = xfs_spaceman
 HFILES = init.h space.h
-CFILES = init.c file.c prealloc.c trim.c
+CFILES = info.c init.c file.c prealloc.c trim.c
 
 LLDLIBS = $(LIBXCMD) $(LIBFROG)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBFROG)
diff --git a/spaceman/file.c b/spaceman/file.c
index 4f9f66c..6adb4f5 100644
--- a/spaceman/file.c
+++ b/spaceman/file.c
@@ -84,6 +84,8 @@ openfile(
 			return -1;
 		}
 		memcpy(fs_path, fsp, sizeof(struct fs_path));
+	} else {
+		memset(fs_path, 0, sizeof(struct fs_path));
 	}
 	return fd;
 }
diff --git a/spaceman/info.c b/spaceman/info.c
new file mode 100644
index 0000000..b8b8133
--- /dev/null
+++ b/spaceman/info.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2018 Oracle.  All Rights Reserved.
+ *
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#include "libxfs.h"
+#include "command.h"
+#include "init.h"
+#include "path.h"
+#include "space.h"
+#include "fsgeom.h"
+
+static void
+info_help(void)
+{
+	printf(_(
+"\n"
+" Pretty-prints the filesystem geometry as derived from the superblock.\n"
+" The output has the same format as mkfs.  The opened file must be a XFS\n"
+" mount point.\n"
+"\n"
+));
+
+}
+
+static int
+info_f(
+	int			argc,
+	char			**argv)
+{
+	struct xfs_fsop_geom	geo;
+	int			error;
+
+	if (fs_table_lookup_mount(file->name) == NULL) {
+		fprintf(stderr, _("%s: Not a XFS mount point.\n"), file->name);
+		return 1;
+	}
+
+	/* 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;
+		}
+	}
+
+	xfs_report_geom(&geo, file->fs_path.fs_name, file->fs_path.fs_log,
+			file->fs_path.fs_rt);
+	return 0;
+}
+
+static const struct cmdinfo info_cmd = {
+	.name =		"info",
+	.altname =	"i",
+	.cfunc =	info_f,
+	.argmin =	0,
+	.argmax =	0,
+	.canpush =	0,
+	.args =		NULL,
+	.flags =	CMD_FLAG_ONESHOT,
+	.oneline =	N_("dump superblock info"),
+	.help =		info_help,
+};
+
+void
+info_init(void)
+{
+	add_command(&info_cmd);
+}
diff --git a/spaceman/init.c b/spaceman/init.c
index b3eface..895504f 100644
--- a/spaceman/init.c
+++ b/spaceman/init.c
@@ -40,6 +40,7 @@ init_commands(void)
 {
 	print_init();
 	help_init();
+	info_init();
 	prealloc_init();
 	quit_init();
 	trim_init();
diff --git a/spaceman/space.h b/spaceman/space.h
index 5f4a8a0..d2a2543 100644
--- a/spaceman/space.h
+++ b/spaceman/space.h
@@ -42,5 +42,6 @@ extern void	freesp_init(void);
 #else
 # define freesp_init()	do { } while (0)
 #endif
+extern void	info_init(void);
 
 #endif /* XFS_SPACEMAN_SPACE_H_ */


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 7/9] xfs_info: move to xfs_spaceman
  2018-04-18  2:45 [PATCH 0/9] xfsprogs-4.17: geometry refactoring Darrick J. Wong
                   ` (5 preceding siblings ...)
  2018-04-18  2:46 ` [PATCH 6/9] xfs_spaceman: add a superblock info command Darrick J. Wong
@ 2018-04-18  2:46 ` Darrick J. Wong
  2018-05-03 21:17   ` Eric Sandeen
  2018-04-18  2:46 ` [PATCH 8/9] xfs_info: call xfs_db for offline filesystems Darrick J. Wong
  2018-04-18  2:46 ` [PATCH 9/9] xfs_growfs: refactor geometry reporting Darrick J. Wong
  8 siblings, 1 reply; 34+ messages in thread
From: Darrick J. Wong @ 2018-04-18  2:46 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Move xfs_info to be under spaceman so that we can remove growfs -N.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 growfs/Makefile      |    2 --
 growfs/xfs_info.sh   |   32 --------------------------------
 spaceman/Makefile    |    2 ++
 spaceman/init.c      |    5 ++++-
 spaceman/xfs_info.sh |   32 ++++++++++++++++++++++++++++++++
 5 files changed, 38 insertions(+), 35 deletions(-)
 delete mode 100755 growfs/xfs_info.sh
 create mode 100755 spaceman/xfs_info.sh


diff --git a/growfs/Makefile b/growfs/Makefile
index f0190e4..adcd84b 100644
--- a/growfs/Makefile
+++ b/growfs/Makefile
@@ -20,7 +20,6 @@ endif
 
 LTDEPENDENCIES = $(LIBXFS) $(LIBXCMD) $(LIBFROG)
 LLDFLAGS = -static-libtool-libs
-LSRCFILES = xfs_info.sh
 
 default: depend $(LTCOMMAND)
 
@@ -29,7 +28,6 @@ include $(BUILDRULES)
 install: default
 	$(INSTALL) -m 755 -d $(PKG_SBIN_DIR)
 	$(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR)
-	$(INSTALL) -m 755 xfs_info.sh $(PKG_SBIN_DIR)/xfs_info
 install-dev:
 
 -include .dep
diff --git a/growfs/xfs_info.sh b/growfs/xfs_info.sh
deleted file mode 100755
index b85f120..0000000
--- a/growfs/xfs_info.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/sh -f
-#
-# Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
-#
-
-OPTS=""
-USAGE="Usage: xfs_info [-V] [-t mtab] mountpoint"
-
-while getopts "t:V" c
-do
-	case $c in
-	t)	OPTS="-t $OPTARG" ;;
-	V)	xfs_growfs -p xfs_info -V
-		status=$?
-		exit $status
-		;;
-	*)	echo $USAGE 1>&2
-		exit 2
-		;;
-	esac
-done
-set -- extra "$@"
-shift $OPTIND
-case $# in
-	1)	xfs_growfs -p xfs_info -n $OPTS "$1"
-		status=$?
-		;;
-	*)	echo $USAGE 1>&2
-		exit 2
-		;;
-esac
-exit $status
diff --git a/spaceman/Makefile b/spaceman/Makefile
index c1d903b..0d5ae2d 100644
--- a/spaceman/Makefile
+++ b/spaceman/Makefile
@@ -8,6 +8,7 @@ include $(TOPDIR)/include/builddefs
 LTCOMMAND = xfs_spaceman
 HFILES = init.h space.h
 CFILES = info.c init.c file.c prealloc.c trim.c
+LSRCFILES = xfs_info.sh
 
 LLDLIBS = $(LIBXCMD) $(LIBFROG)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBFROG)
@@ -35,6 +36,7 @@ include $(BUILDRULES)
 install: default
 	$(INSTALL) -m 755 -d $(PKG_SBIN_DIR)
 	$(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR)
+	$(INSTALL) -m 755 xfs_info.sh $(PKG_SBIN_DIR)/xfs_info
 install-dev:
 
 -include .dep
diff --git a/spaceman/init.c b/spaceman/init.c
index 895504f..91c773f 100644
--- a/spaceman/init.c
+++ b/spaceman/init.c
@@ -81,11 +81,14 @@ init(
 	textdomain(PACKAGE);
 
 	fs_table_initialise(0, NULL, 0, NULL);
-	while ((c = getopt(argc, argv, "c:V")) != EOF) {
+	while ((c = getopt(argc, argv, "c:p:V")) != EOF) {
 		switch (c) {
 		case 'c':
 			add_user_command(optarg);
 			break;
+		case 'p':
+			progname = optarg;
+			break;
 		case 'V':
 			printf(_("%s version %s\n"), progname, VERSION);
 			exit(0);
diff --git a/spaceman/xfs_info.sh b/spaceman/xfs_info.sh
new file mode 100755
index 0000000..5df0a26
--- /dev/null
+++ b/spaceman/xfs_info.sh
@@ -0,0 +1,32 @@
+#!/bin/sh -f
+#
+# Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
+#
+
+OPTS=""
+USAGE="Usage: xfs_info [-V] [-t mtab] mountpoint"
+
+while getopts "t:V" c
+do
+	case $c in
+	t)	OPTS="-t $OPTARG" ;;
+	V)	xfs_spaceman -p xfs_info -V
+		status=$?
+		exit $status
+		;;
+	*)	echo $USAGE 1>&2
+		exit 2
+		;;
+	esac
+done
+set -- extra "$@"
+shift $OPTIND
+case $# in
+	1)	xfs_spaceman -p xfs_info -c "info" $OPTS "$1"
+		status=$?
+		;;
+	*)	echo $USAGE 1>&2
+		exit 2
+		;;
+esac
+exit $status


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 8/9] xfs_info: call xfs_db for offline filesystems
  2018-04-18  2:45 [PATCH 0/9] xfsprogs-4.17: geometry refactoring Darrick J. Wong
                   ` (6 preceding siblings ...)
  2018-04-18  2:46 ` [PATCH 7/9] xfs_info: move to xfs_spaceman Darrick J. Wong
@ 2018-04-18  2:46 ` Darrick J. Wong
  2018-05-03 21:22   ` Eric Sandeen
  2018-05-23  3:33   ` [PATCH v2 " Darrick J. Wong
  2018-04-18  2:46 ` [PATCH 9/9] xfs_growfs: refactor geometry reporting Darrick J. Wong
  8 siblings, 2 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-04-18  2:46 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

If the online filesystem geometry query doesn't work, try using xfs_db
to see if we can grab the information offline.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 man/man8/xfs_growfs.8 |   47 +-----------------------
 man/man8/xfs_info.8   |   95 +++++++++++++++++++++++++++++++++++++++++++++++++
 spaceman/xfs_info.sh  |   12 +++++-
 3 files changed, 106 insertions(+), 48 deletions(-)
 create mode 100644 man/man8/xfs_info.8


diff --git a/man/man8/xfs_growfs.8 b/man/man8/xfs_growfs.8
index e23d30e..7e6a387 100644
--- a/man/man8/xfs_growfs.8
+++ b/man/man8/xfs_growfs.8
@@ -11,7 +11,7 @@
 
 .TH xfs_growfs 8
 .SH NAME
-xfs_growfs, xfs_info \- expand an XFS filesystem
+xfs_growfs \- expand an XFS filesystem
 .SH SYNOPSIS
 .B xfs_growfs
 [
@@ -38,16 +38,6 @@ xfs_growfs, xfs_info \- expand an XFS filesystem
 .I mount-point
 .br
 .B xfs_growfs \-V
-.PP
-.br
-.B xfs_info
-[
-.B \-t
-.I mtab
-]
-.I mount-point
-.br
-.B xfs_info \-V
 .SH DESCRIPTION
 .B xfs_growfs
 expands an existing XFS filesystem (see
@@ -59,13 +49,6 @@ is mounted. The filesystem must be mounted to be grown (see
 .BR mount (8)).
 The existing contents of the filesystem are undisturbed, and the added space
 becomes available for additional file storage.
-.PP
-.B xfs_info
-is equivalent to invoking
-.B xfs_growfs
-with the
-.B \-n
-option (see discussion below).
 .SH OPTIONS
 .TP
 .BI "\-d | \-D " size
@@ -169,35 +152,9 @@ reside. In order to grow a filesystem, it is necessary to provide added
 space for it to occupy. Therefore there must be at least one spare new
 disk partition available. Adding the space is often done through the use
 of a logical volume manager.
-.SH "EXAMPLES"
-
-Understanding xfs_info output.
-.PP
-Suppose one has the following "xfs_info /dev/sda" output:
-.PP
-.RS 2
-.Vb
-\&meta-data=/dev/sda      isize=256    agcount=32, agsize=16777184 blks
-\&         =              sectsz=512   attr=2
-\&data     =              bsize=4096   blocks=536869888, imaxpct=5
-\&         =              sunit=32     swidth=128 blks
-\&naming   =version 2     bsize=4096
-\&log      =internal      bsize=4096   blocks=32768, version=2
-\&         =              sectsz=512   sunit=32 blks, lazy-count=1
-\&realtime =none          extsz=524288 blocks=0, rtextents=0
-.Ve
-.RE
-.PP
-
-Here, the data section of the output indicates "bsize=4096",
-meaning the data block size for this filesystem is 4096 bytes.
-This section also shows "sunit=32 swidth=128 blks", which means
-the stripe unit is 32*4096 bytes = 128 kibibytes and the stripe
-width is 128*4096 bytes = 512 kibibytes.
-A single stripe of this filesystem therefore consists
-of four stripe units (128 blocks / 32 blocks per unit).
 .SH SEE ALSO
 .BR mkfs.xfs (8),
+.BR xfs_info (8),
 .BR md (4),
 .BR lvm (8),
 .BR mount (8).
diff --git a/man/man8/xfs_info.8 b/man/man8/xfs_info.8
new file mode 100644
index 0000000..c4c470d
--- /dev/null
+++ b/man/man8/xfs_info.8
@@ -0,0 +1,95 @@
+.\" Verbatim blocks taken from openssl req manpage content
+.de Vb \" Begin verbatim text
+.ft CW
+.nf
+.ne \\$1
+..
+.de Ve \" End verbatim text
+.ft R
+.fi
+..
+
+.TH xfs_info 8
+.SH NAME
+xfs_info, \- display XFS filesystem geometry information
+.SH SYNOPSIS
+.B xfs_info
+[
+.B \-t
+.I mtab
+]
+[
+.I mount-point
+|
+.I block-device
+|
+.I file-image
+]
+.br
+.B xfs_info \-V
+.SH DESCRIPTION
+.B xfs_info
+displays geometry information about an existing XFS filesystem.
+The
+.I mount-point
+argument is the pathname of a directory where the filesystem
+is mounted.
+The
+.I block-device
+or
+.I file-image
+contain a raw XFS filesystem.
+The existing contents of the filesystem are undisturbed.
+.SH OPTIONS
+.TP
+.B \-t
+Specifies an alternate mount table file (default is
+.I /proc/mounts
+if it exists, else
+.IR /etc/mtab ).
+This is used when working with filesystems mounted without writing to
+.I /etc/mtab
+file - refer to
+.BR mount (8)
+for further details.
+This option has no effect with the
+.IR block-device " or " file-image
+parameters.
+.TP
+.B \-V
+Prints the version number and exits. The
+.I mount-point
+argument is not required with
+.BR \-V .
+.SH "EXAMPLES"
+
+Understanding xfs_info output.
+.PP
+Suppose one has the following "xfs_info /dev/sda" output:
+.PP
+.RS 2
+.Vb
+\&meta-data=/dev/sda      isize=256    agcount=32, agsize=16777184 blks
+\&         =              sectsz=512   attr=2
+\&data     =              bsize=4096   blocks=536869888, imaxpct=5
+\&         =              sunit=32     swidth=128 blks
+\&naming   =version 2     bsize=4096
+\&log      =internal log  bsize=4096   blocks=32768, version=2
+\&         =              sectsz=512   sunit=32 blks, lazy-count=1
+\&realtime =none          extsz=524288 blocks=0, rtextents=0
+.Ve
+.RE
+.PP
+
+Here, the data section of the output indicates "bsize=4096",
+meaning the data block size for this filesystem is 4096 bytes.
+This section also shows "sunit=32 swidth=128 blks", which means
+the stripe unit is 32*4096 bytes = 128 kibibytes and the stripe
+width is 128*4096 bytes = 512 kibibytes.
+A single stripe of this filesystem therefore consists
+of four stripe units (128 blocks / 32 blocks per unit).
+.SH SEE ALSO
+.BR mkfs.xfs (8),
+.BR md (4),
+.BR lvm (8),
+.BR mount (8).
diff --git a/spaceman/xfs_info.sh b/spaceman/xfs_info.sh
index 5df0a26..2e17fd9 100755
--- a/spaceman/xfs_info.sh
+++ b/spaceman/xfs_info.sh
@@ -4,7 +4,7 @@
 #
 
 OPTS=""
-USAGE="Usage: xfs_info [-V] [-t mtab] mountpoint"
+USAGE="Usage: xfs_info [-V] [-t mtab] [mountpoint|device|file]"
 
 while getopts "t:V" c
 do
@@ -22,8 +22,14 @@ done
 set -- extra "$@"
 shift $OPTIND
 case $# in
-	1)	xfs_spaceman -p xfs_info -c "info" $OPTS "$1"
-		status=$?
+	1)
+		if [ -b "$1" ] || [ -f "$1" ]; then
+			xfs_db -p xfs_info -c "info" $OPTS "$1"
+			status=$?
+		else
+			xfs_spaceman -p xfs_info -c "info" $OPTS "$1"
+			status=$?
+		fi
 		;;
 	*)	echo $USAGE 1>&2
 		exit 2


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH 9/9] xfs_growfs: refactor geometry reporting
  2018-04-18  2:45 [PATCH 0/9] xfsprogs-4.17: geometry refactoring Darrick J. Wong
                   ` (7 preceding siblings ...)
  2018-04-18  2:46 ` [PATCH 8/9] xfs_info: call xfs_db for offline filesystems Darrick J. Wong
@ 2018-04-18  2:46 ` Darrick J. Wong
  2018-05-03 21:25   ` Eric Sandeen
  8 siblings, 1 reply; 34+ messages in thread
From: Darrick J. Wong @ 2018-04-18  2:46 UTC (permalink / raw)
  To: sandeen, darrick.wong; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Use the new geometry pretty-printing function.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 growfs/xfs_growfs.c |   88 +--------------------------------------------------
 1 file changed, 2 insertions(+), 86 deletions(-)


diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c
index 366176b..8ec445a 100644
--- a/growfs/xfs_growfs.c
+++ b/growfs/xfs_growfs.c
@@ -18,6 +18,7 @@
 
 #include "libxfs.h"
 #include "path.h"
+#include "fsgeom.h"
 
 static void
 usage(void)
@@ -42,54 +43,6 @@ Options:\n\
 	exit(2);
 }
 
-void
-report_info(
-	xfs_fsop_geom_t	geo,
-	char		*mntpoint,
-	int		isint,
-	char		*logname,
-	char		*rtname,
-	int		lazycount,
-	int		dirversion,
-	int		logversion,
-	int		attrversion,
-	int		projid32bit,
-	int		crcs_enabled,
-	int		cimode,
-	int		ftype_enabled,
-	int		finobt_enabled,
-	int		spinodes,
-	int		rmapbt_enabled,
-	int		reflink_enabled)
-{
-	printf(_(
-	    "meta-data=%-22s isize=%-6u agcount=%u, agsize=%u blks\n"
-	    "         =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
-	    "         =%-22s crc=%-8u finobt=%u spinodes=%u rmapbt=%u\n"
-	    "         =%-22s reflink=%u\n"
-	    "data     =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
-	    "         =%-22s sunit=%-6u swidth=%u blks\n"
-	    "naming   =version %-14u bsize=%-6u ascii-ci=%d ftype=%d\n"
-	    "log      =%-22s bsize=%-6u blocks=%u, version=%u\n"
-	    "         =%-22s sectsz=%-5u sunit=%u blks, lazy-count=%u\n"
-	    "realtime =%-22s extsz=%-6u blocks=%llu, rtextents=%llu\n"),
-
-		mntpoint, geo.inodesize, geo.agcount, geo.agblocks,
-		"", geo.sectsize, attrversion, projid32bit,
-		"", crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled,
-		"", reflink_enabled,
-		"", geo.blocksize, (unsigned long long)geo.datablocks,
-			geo.imaxpct,
-		"", geo.sunit, geo.swidth,
-  		dirversion, geo.dirblocksize, cimode, ftype_enabled,
-		isint ? _("internal") : logname ? logname : _("external"),
-			geo.blocksize, geo.logblocks, logversion,
-		"", geo.logsectsize, geo.logsunit / geo.blocksize, lazycount,
-		!geo.rtblocks ? _("none") : rtname ? rtname : _("external"),
-		geo.rtextsize * geo.blocksize, (unsigned long long)geo.rtblocks,
-			(unsigned long long)geo.rtextents);
-}
-
 int
 main(int argc, char **argv)
 {
@@ -97,9 +50,6 @@ main(int argc, char **argv)
 	int			c;	/* current option character */
 	long long		ddsize;	/* device size in 512-byte blocks */
 	int			dflag;	/* -d flag */
-	int			attrversion;/* attribute version number */
-	int			dirversion; /* directory version number */
-	int			logversion; /* log version number */
 	long long		dlsize;	/* device size in 512-byte blocks */
 	long long		drsize;	/* device size in 512-byte blocks */
 	long long		dsize;	/* new data size in fs blocks */
@@ -117,8 +67,6 @@ main(int argc, char **argv)
 	xfs_fsop_geom_t		ngeo;	/* new fs geometry */
 	int			rflag;	/* -r flag */
 	long long		rsize;	/* new rt size in fs blocks */
-	int			ci;	/* ASCII case-insensitive fs */
-	int			lazycount; /* lazy superblock counters */
 	int			xflag;	/* -x flag */
 	char			*fname;	/* mount point name */
 	char			*datadev; /* data device name */
@@ -126,13 +74,6 @@ main(int argc, char **argv)
 	char			*rtdev;	/*   RT device name */
 	fs_path_t		*fs;	/* mount point information */
 	libxfs_init_t		xi;	/* libxfs structure */
-	int			projid32bit;
-	int			crcs_enabled;
-	int			ftype_enabled = 0;
-	int			finobt_enabled;	/* free inode btree */
-	int			spinodes;
-	int			rmapbt_enabled;
-	int			reflink_enabled;
 	char			rpath[PATH_MAX];
 
 	progname = basename(argv[0]);
@@ -253,27 +194,6 @@ main(int argc, char **argv)
 		}
 	}
 	isint = geo.logstart > 0;
-	lazycount = geo.flags & XFS_FSOP_GEOM_FLAGS_LAZYSB ? 1 : 0;
-	dirversion = geo.flags & XFS_FSOP_GEOM_FLAGS_DIRV2 ? 2 : 1;
-	logversion = geo.flags & XFS_FSOP_GEOM_FLAGS_LOGV2 ? 2 : 1;
-	attrversion = geo.flags & XFS_FSOP_GEOM_FLAGS_ATTR2 ? 2 : \
-			(geo.flags & XFS_FSOP_GEOM_FLAGS_ATTR ? 1 : 0);
-	ci = geo.flags & XFS_FSOP_GEOM_FLAGS_DIRV2CI ? 1 : 0;
-	projid32bit = geo.flags & XFS_FSOP_GEOM_FLAGS_PROJID32 ? 1 : 0;
-	crcs_enabled = geo.flags & XFS_FSOP_GEOM_FLAGS_V5SB ? 1 : 0;
-	ftype_enabled = geo.flags & XFS_FSOP_GEOM_FLAGS_FTYPE ? 1 : 0;
-	finobt_enabled = geo.flags & XFS_FSOP_GEOM_FLAGS_FINOBT ? 1 : 0;
-	spinodes = geo.flags & XFS_FSOP_GEOM_FLAGS_SPINODES ? 1 : 0;
-	rmapbt_enabled = geo.flags & XFS_FSOP_GEOM_FLAGS_RMAPBT ? 1 : 0;
-	reflink_enabled = geo.flags & XFS_FSOP_GEOM_FLAGS_REFLINK ? 1 : 0;
-	if (nflag) {
-		report_info(geo, datadev, isint, logdev, rtdev,
-				lazycount, dirversion, logversion,
-				attrversion, projid32bit, crcs_enabled, ci,
-				ftype_enabled, finobt_enabled, spinodes,
-				rmapbt_enabled, reflink_enabled);
-		exit(0);
-	}
 
 	/*
 	 * Need root access from here on (using raw devices)...
@@ -306,11 +226,7 @@ main(int argc, char **argv)
 		exit(1);
 	}
 
-	report_info(geo, datadev, isint, logdev, rtdev,
-			lazycount, dirversion, logversion,
-			attrversion, projid32bit, crcs_enabled, ci, ftype_enabled,
-			finobt_enabled, spinodes, rmapbt_enabled,
-			reflink_enabled);
+	xfs_report_geom(&geo, datadev, logdev, rtdev);
 
 	ddsize = xi.dsize;
 	dlsize = ( xi.logBBsize? xi.logBBsize :


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [PATCH 1/9] libfrog: move platform specific runtime support code out of libxfs
  2018-04-18  2:45 ` [PATCH 1/9] libfrog: move platform specific runtime support code out of libxfs Darrick J. Wong
@ 2018-05-03 18:23   ` Eric Sandeen
  0 siblings, 0 replies; 34+ messages in thread
From: Eric Sandeen @ 2018-05-03 18:23 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/17/18 9:45 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Move the platform support code to libfrog, which should remove the final
> dependency of libfrog on libxfs.  libfrog is the runtime support
> library, and these files provide platform support.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Reviewed-by: Eric Sandeen <sandeen@redhat.com>


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 2/9] libfrog: refactor fs geometry printing function
  2018-04-18  2:45 ` [PATCH 2/9] libfrog: refactor fs geometry printing function Darrick J. Wong
@ 2018-05-03 18:47   ` Eric Sandeen
  2018-05-03 21:27   ` Eric Sandeen
  1 sibling, 0 replies; 34+ messages in thread
From: Eric Sandeen @ 2018-05-03 18:47 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/17/18 9:45 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Move the fs geometry printing function to libfrog so that mkfs and others
> can share.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 3/9] mkfs: use geometry generation / helper functions
  2018-04-18  2:45 ` [PATCH 3/9] mkfs: use geometry generation / helper functions Darrick J. Wong
@ 2018-05-03 18:52   ` Eric Sandeen
  0 siblings, 0 replies; 34+ messages in thread
From: Eric Sandeen @ 2018-05-03 18:52 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/17/18 9:45 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Since libxfs now has a function to fill out the geometry structure
> and libfrog has a function to pretty-print the geometry, have mkfs
> use the two helpers instead of open-coding it.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

We should make (lib)xfs_fs_geometry a void and get rid of the pointless
error handling, but that's a patch for another day.

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 4/9] xfs_db: add a superblock info command
  2018-04-18  2:45 ` [PATCH 4/9] xfs_db: add a superblock info command Darrick J. Wong
@ 2018-05-03 20:53   ` Eric Sandeen
  2018-05-03 21:44     ` Darrick J. Wong
  2018-05-23  3:30   ` [PATCH v2 " Darrick J. Wong
  1 sibling, 1 reply; 34+ messages in thread
From: Eric Sandeen @ 2018-05-03 20:53 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/17/18 9:45 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Add an 'info' command to pretty-print the superblock geometry.

This seems ... fine, it's a bit out of xfs_db's charter but ...
I see where you're going with this ... ;)

A little nitpicky below though.

> +static void
> +info_help(void)
> +{
> +	dbprintf(_(
> +"\n"
> +" Pretty-prints the filesystem geometry as derived from the superblock.\n"
> +" The output has the same format as mkfs.\n"

mkfs.xfs, xfs_info, and other utilities. ?

> +"\n"
> +));
> +
> +}
> +
> +static int
> +info_f(
> +	int			argc,
> +	char			**argv)
> +{
> +	struct xfs_fsop_geom	geo;
> +	int			error;
> +
> +	error = -libxfs_fs_geometry(&mp->m_sb, &geo,
> +			XFS_FS_GEOM_MAX_STRUCT_VER);
> +	if (error) {
> +		dbprintf(_("could not obtain geometry\n"));
> +		exitcode = 1;
> +		return 0;
> +	}
> +
> +	xfs_report_geom(&geo, fsdevice, x.logname, x.rtname);
> +	return 0;
> +}
> +
> +static const struct cmdinfo info_cmd = {
> +	.name =		"info",
> +	.altname =	"i",
> +	.cfunc =	info_f,
> +	.argmin =	0,
> +	.argmax =	0,
> +	.canpush =	0,
> +	.args =		NULL,
> +	.oneline =	N_("dump superblock info"),

"pretty-print superblock geometry info"  ?

> +	.help =		info_help,
> +};
> +
> +void
> +info_init(void)
> +{
> +	add_command(&info_cmd);
> +}
> diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8
> index 524b1ef..e29821e 100644
> --- a/man/man8/xfs_db.8
> +++ b/man/man8/xfs_db.8
> @@ -670,6 +670,12 @@ using the hash function of the XFS directory and attribute implementation.
>  .BI "help [" command ]
>  Print help for one or all commands.
>  .TP
> +.B info
> +Displays selected geometry information about the filesystem.
> +The output will have the same format that
> +.BR "mkfs.xfs" "(8)"
> +prints when creating a filesystem.

Again adding xfs_info here might be nice too?

Just seems a little odd to single out one utility, not a huge deal tho.

I could just add these if you agree.  Or drop it if not ;)

> +.TP
>  .BI "inode [" inode# ]
>  Set the current inode number. If no
>  .I inode#


^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 5/9] xfs_spaceman: print a nicer message when the file path isn't on an xfs
  2018-04-18  2:46 ` [PATCH 5/9] xfs_spaceman: print a nicer message when the file path isn't on an xfs Darrick J. Wong
@ 2018-05-03 20:57   ` Eric Sandeen
  2018-05-23  3:31   ` [PATCH v2 " Darrick J. Wong
  1 sibling, 0 replies; 34+ messages in thread
From: Eric Sandeen @ 2018-05-03 20:57 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/17/18 9:46 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> If the file path passed in is not something on an xfs filesystem, print
> a nice message about that instead of yelling about ioctls.

Assumes that -ENOTTY is the only possible error though...

Maybe:

if (errno == ENOTTY)
	printf("nice thing")
else
	perror("XFS_IOC_FSGEOMETRY");

?

Not a lot else that should go wrong today (EFAULT?) but assuming only
one thing could go wrong seems wrong.

> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  spaceman/file.c |    3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> 
> diff --git a/spaceman/file.c b/spaceman/file.c
> index 4c13b4a..4f9f66c 100644
> --- a/spaceman/file.c
> +++ b/spaceman/file.c
> @@ -69,7 +69,8 @@ openfile(
>  	}
>  
>  	if (ioctl(fd, XFS_IOC_FSGEOMETRY, geom) < 0) {
> -		perror("XFS_IOC_FSGEOMETRY");
> +		fprintf(stderr, _("%s: Not on a mounted XFS filesystem.\n"),
> +				path);
>  		close(fd);
>  		return -1;
>  	}
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 6/9] xfs_spaceman: add a superblock info command
  2018-04-18  2:46 ` [PATCH 6/9] xfs_spaceman: add a superblock info command Darrick J. Wong
@ 2018-05-03 21:09   ` Eric Sandeen
  2018-05-03 21:39     ` Darrick J. Wong
  2018-05-23  3:32   ` [PATCH v2 " Darrick J. Wong
  1 sibling, 1 reply; 34+ messages in thread
From: Eric Sandeen @ 2018-05-03 21:09 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/17/18 9:46 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Add an 'info' command to pretty-print the superblock geometry.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---



> diff --git a/spaceman/file.c b/spaceman/file.c
> index 4f9f66c..6adb4f5 100644
> --- a/spaceman/file.c
> +++ b/spaceman/file.c
> @@ -84,6 +84,8 @@ openfile(

        char            *path,
        xfs_fsop_geom_t *geom,
        struct fs_path  *fs_path)
{
..

        if (fs_path) {
...
>  			return -1;
>  		}
>  		memcpy(fs_path, fsp, sizeof(struct fs_path));
> +	} else {
> +		memset(fs_path, 0, sizeof(struct fs_path));
>  	}

so if fs_path == NULL memset(NULL, 0) ?

Not sure what's going on here.

(or maybe I've forgotten how C works)

>  	return fd;
>  }
> diff --git a/spaceman/info.c b/spaceman/info.c
> new file mode 100644
> index 0000000..b8b8133
> --- /dev/null
> +++ b/spaceman/info.c
> @@ -0,0 +1,96 @@
> +/*
> + * Copyright (C) 2018 Oracle.  All Rights Reserved.
> + *
> + * Author: Darrick J. Wong <darrick.wong@oracle.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software Foundation,
> + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
> + */
> +#include "libxfs.h"
> +#include "command.h"
> +#include "init.h"
> +#include "path.h"
> +#include "space.h"
> +#include "fsgeom.h"
> +
> +static void
> +info_help(void)
> +{
> +	printf(_(
> +"\n"
> +" Pretty-prints the filesystem geometry as derived from the superblock.\n"
> +" The output has the same format as mkfs.  The opened file must be a XFS\n"

"an XFS?"

> +" mount point.\n"
> +"\n"
> +));
> +
> +}
> +
> +static int
> +info_f(
> +	int			argc,
> +	char			**argv)
> +{
> +	struct xfs_fsop_geom	geo;
> +	int			error;
> +
> +	if (fs_table_lookup_mount(file->name) == NULL) {
> +		fprintf(stderr, _("%s: Not a XFS mount point.\n"), file->name);
> +		return 1;
> +	}
> +
> +	/* 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);

We're certain that it won't fill in logsunit with junk, right?
Would it be any safer to set logsunit after or is that presupposing too
much about the interface?  I guess it's fine.

> +		if (error) {
> +			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,
> +			file->fs_path.fs_rt);
> +	return 0;
> +}
> +
> +static const struct cmdinfo info_cmd = {
> +	.name =		"info",
> +	.altname =	"i",
> +	.cfunc =	info_f,
> +	.argmin =	0,
> +	.argmax =	0,
> +	.canpush =	0,
> +	.args =		NULL,
> +	.flags =	CMD_FLAG_ONESHOT,
> +	.oneline =	N_("dump superblock info"),

"print geometry superblock info"

> +	.help =		info_help,
> +};
> +
> +void
> +info_init(void)
> +{
> +	add_command(&info_cmd);
> +}
> diff --git a/spaceman/init.c b/spaceman/init.c
> index b3eface..895504f 100644
> --- a/spaceman/init.c
> +++ b/spaceman/init.c
> @@ -40,6 +40,7 @@ init_commands(void)
>  {
>  	print_init();
>  	help_init();
> +	info_init();
>  	prealloc_init();
>  	quit_init();
>  	trim_init();
> diff --git a/spaceman/space.h b/spaceman/space.h
> index 5f4a8a0..d2a2543 100644
> --- a/spaceman/space.h
> +++ b/spaceman/space.h
> @@ -42,5 +42,6 @@ extern void	freesp_init(void);
>  #else
>  # define freesp_init()	do { } while (0)
>  #endif
> +extern void	info_init(void);
>  
>  #endif /* XFS_SPACEMAN_SPACE_H_ */
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 7/9] xfs_info: move to xfs_spaceman
  2018-04-18  2:46 ` [PATCH 7/9] xfs_info: move to xfs_spaceman Darrick J. Wong
@ 2018-05-03 21:17   ` Eric Sandeen
  2018-05-03 21:48     ` Darrick J. Wong
  0 siblings, 1 reply; 34+ messages in thread
From: Eric Sandeen @ 2018-05-03 21:17 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/17/18 9:46 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Move xfs_info to be under spaceman so that we can remove growfs -N.

Seems ok in general, though how will this work with Dave's upcoming
special subvol-files-no-they're-devices-no-they're-files?

Do we worry about all that later?  I guess?

(I guess we don't document -p as it's for internal use)

Modulo that concern,

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

-Eric


> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  growfs/Makefile      |    2 --
>  growfs/xfs_info.sh   |   32 --------------------------------
>  spaceman/Makefile    |    2 ++
>  spaceman/init.c      |    5 ++++-
>  spaceman/xfs_info.sh |   32 ++++++++++++++++++++++++++++++++
>  5 files changed, 38 insertions(+), 35 deletions(-)
>  delete mode 100755 growfs/xfs_info.sh
>  create mode 100755 spaceman/xfs_info.sh
> 
> 
> diff --git a/growfs/Makefile b/growfs/Makefile
> index f0190e4..adcd84b 100644
> --- a/growfs/Makefile
> +++ b/growfs/Makefile
> @@ -20,7 +20,6 @@ endif
>  
>  LTDEPENDENCIES = $(LIBXFS) $(LIBXCMD) $(LIBFROG)
>  LLDFLAGS = -static-libtool-libs
> -LSRCFILES = xfs_info.sh
>  
>  default: depend $(LTCOMMAND)
>  
> @@ -29,7 +28,6 @@ include $(BUILDRULES)
>  install: default
>  	$(INSTALL) -m 755 -d $(PKG_SBIN_DIR)
>  	$(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR)
> -	$(INSTALL) -m 755 xfs_info.sh $(PKG_SBIN_DIR)/xfs_info
>  install-dev:
>  
>  -include .dep
> diff --git a/growfs/xfs_info.sh b/growfs/xfs_info.sh
> deleted file mode 100755
> index b85f120..0000000
> --- a/growfs/xfs_info.sh
> +++ /dev/null
> @@ -1,32 +0,0 @@
> -#!/bin/sh -f
> -#
> -# Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
> -#
> -
> -OPTS=""
> -USAGE="Usage: xfs_info [-V] [-t mtab] mountpoint"
> -
> -while getopts "t:V" c
> -do
> -	case $c in
> -	t)	OPTS="-t $OPTARG" ;;
> -	V)	xfs_growfs -p xfs_info -V
> -		status=$?
> -		exit $status
> -		;;
> -	*)	echo $USAGE 1>&2
> -		exit 2
> -		;;
> -	esac
> -done
> -set -- extra "$@"
> -shift $OPTIND
> -case $# in
> -	1)	xfs_growfs -p xfs_info -n $OPTS "$1"
> -		status=$?
> -		;;
> -	*)	echo $USAGE 1>&2
> -		exit 2
> -		;;
> -esac
> -exit $status
> diff --git a/spaceman/Makefile b/spaceman/Makefile
> index c1d903b..0d5ae2d 100644
> --- a/spaceman/Makefile
> +++ b/spaceman/Makefile
> @@ -8,6 +8,7 @@ include $(TOPDIR)/include/builddefs
>  LTCOMMAND = xfs_spaceman
>  HFILES = init.h space.h
>  CFILES = info.c init.c file.c prealloc.c trim.c
> +LSRCFILES = xfs_info.sh
>  
>  LLDLIBS = $(LIBXCMD) $(LIBFROG)
>  LTDEPENDENCIES = $(LIBXCMD) $(LIBFROG)
> @@ -35,6 +36,7 @@ include $(BUILDRULES)
>  install: default
>  	$(INSTALL) -m 755 -d $(PKG_SBIN_DIR)
>  	$(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR)
> +	$(INSTALL) -m 755 xfs_info.sh $(PKG_SBIN_DIR)/xfs_info
>  install-dev:
>  
>  -include .dep
> diff --git a/spaceman/init.c b/spaceman/init.c
> index 895504f..91c773f 100644
> --- a/spaceman/init.c
> +++ b/spaceman/init.c
> @@ -81,11 +81,14 @@ init(
>  	textdomain(PACKAGE);
>  
>  	fs_table_initialise(0, NULL, 0, NULL);
> -	while ((c = getopt(argc, argv, "c:V")) != EOF) {
> +	while ((c = getopt(argc, argv, "c:p:V")) != EOF) {
>  		switch (c) {
>  		case 'c':
>  			add_user_command(optarg);
>  			break;
> +		case 'p':
> +			progname = optarg;
> +			break;
>  		case 'V':
>  			printf(_("%s version %s\n"), progname, VERSION);
>  			exit(0);
> diff --git a/spaceman/xfs_info.sh b/spaceman/xfs_info.sh
> new file mode 100755
> index 0000000..5df0a26
> --- /dev/null
> +++ b/spaceman/xfs_info.sh
> @@ -0,0 +1,32 @@
> +#!/bin/sh -f
> +#
> +# Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
> +#
> +
> +OPTS=""
> +USAGE="Usage: xfs_info [-V] [-t mtab] mountpoint"
> +
> +while getopts "t:V" c
> +do
> +	case $c in
> +	t)	OPTS="-t $OPTARG" ;;
> +	V)	xfs_spaceman -p xfs_info -V
> +		status=$?
> +		exit $status
> +		;;
> +	*)	echo $USAGE 1>&2
> +		exit 2
> +		;;
> +	esac
> +done
> +set -- extra "$@"
> +shift $OPTIND
> +case $# in
> +	1)	xfs_spaceman -p xfs_info -c "info" $OPTS "$1"
> +		status=$?
> +		;;
> +	*)	echo $USAGE 1>&2
> +		exit 2
> +		;;
> +esac
> +exit $status
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 8/9] xfs_info: call xfs_db for offline filesystems
  2018-04-18  2:46 ` [PATCH 8/9] xfs_info: call xfs_db for offline filesystems Darrick J. Wong
@ 2018-05-03 21:22   ` Eric Sandeen
  2018-05-03 21:55     ` Darrick J. Wong
  2018-05-23  3:33   ` [PATCH v2 " Darrick J. Wong
  1 sibling, 1 reply; 34+ messages in thread
From: Eric Sandeen @ 2018-05-03 21:22 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/17/18 9:46 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> If the online filesystem geometry query doesn't work, try using xfs_db
> to see if we can grab the information offline.
> 

I'm slightly concerned that having all-singing, all-dancing tools
that operate on mounted, unmounted, devices, mountpoints, and images
will further encourage people to think that operations on mounted
block devices are Just Fine(tm).

But ... I suppose the convenience is worth it.

...

> diff --git a/man/man8/xfs_info.8 b/man/man8/xfs_info.8
> new file mode 100644
> index 0000000..c4c470d
> --- /dev/null
> +++ b/man/man8/xfs_info.8
> @@ -0,0 +1,95 @@
> +.\" Verbatim blocks taken from openssl req manpage content
> +.de Vb \" Begin verbatim text
> +.ft CW
> +.nf
> +.ne \\$1
> +..
> +.de Ve \" End verbatim text
> +.ft R
> +.fi
> +..
> +
> +.TH xfs_info 8
> +.SH NAME
> +xfs_info, \- display XFS filesystem geometry information

drop the comma pls, or I can do this.

...

> +.BR \-V .
> +.SH "EXAMPLES"
> +
> +Understanding xfs_info output.
> +.PP
> +Suppose one has the following "xfs_info /dev/sda" output:
> +.PP
> +.RS 2
> +.Vb
> +\&meta-data=/dev/sda      isize=256    agcount=32, agsize=16777184 blks
> +\&         =              sectsz=512   attr=2
> +\&data     =              bsize=4096   blocks=536869888, imaxpct=5
> +\&         =              sunit=32     swidth=128 blks
> +\&naming   =version 2     bsize=4096
> +\&log      =internal log  bsize=4096   blocks=32768, version=2
> +\&         =              sectsz=512   sunit=32 blks, lazy-count=1
> +\&realtime =none          extsz=524288 blocks=0, rtextents=0
> +.Ve

Should we update this to a more modern version?  *shrug*




^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 9/9] xfs_growfs: refactor geometry reporting
  2018-04-18  2:46 ` [PATCH 9/9] xfs_growfs: refactor geometry reporting Darrick J. Wong
@ 2018-05-03 21:25   ` Eric Sandeen
  0 siblings, 0 replies; 34+ messages in thread
From: Eric Sandeen @ 2018-05-03 21:25 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/17/18 9:46 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Use the new geometry pretty-printing function.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>

Reviewed-by: Eric Sandeen <sandeen@redhat.com>

> ---
>  growfs/xfs_growfs.c |   88 +--------------------------------------------------
>  1 file changed, 2 insertions(+), 86 deletions(-)
> 
> 
> diff --git a/growfs/xfs_growfs.c b/growfs/xfs_growfs.c
> index 366176b..8ec445a 100644
> --- a/growfs/xfs_growfs.c
> +++ b/growfs/xfs_growfs.c
> @@ -18,6 +18,7 @@
>  
>  #include "libxfs.h"
>  #include "path.h"
> +#include "fsgeom.h"
>  
>  static void
>  usage(void)
> @@ -42,54 +43,6 @@ Options:\n\
>  	exit(2);
>  }
>  
> -void
> -report_info(
> -	xfs_fsop_geom_t	geo,
> -	char		*mntpoint,
> -	int		isint,
> -	char		*logname,
> -	char		*rtname,
> -	int		lazycount,
> -	int		dirversion,
> -	int		logversion,
> -	int		attrversion,
> -	int		projid32bit,
> -	int		crcs_enabled,
> -	int		cimode,
> -	int		ftype_enabled,
> -	int		finobt_enabled,
> -	int		spinodes,
> -	int		rmapbt_enabled,
> -	int		reflink_enabled)
> -{
> -	printf(_(
> -	    "meta-data=%-22s isize=%-6u agcount=%u, agsize=%u blks\n"
> -	    "         =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
> -	    "         =%-22s crc=%-8u finobt=%u spinodes=%u rmapbt=%u\n"
> -	    "         =%-22s reflink=%u\n"
> -	    "data     =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
> -	    "         =%-22s sunit=%-6u swidth=%u blks\n"
> -	    "naming   =version %-14u bsize=%-6u ascii-ci=%d ftype=%d\n"
> -	    "log      =%-22s bsize=%-6u blocks=%u, version=%u\n"
> -	    "         =%-22s sectsz=%-5u sunit=%u blks, lazy-count=%u\n"
> -	    "realtime =%-22s extsz=%-6u blocks=%llu, rtextents=%llu\n"),
> -
> -		mntpoint, geo.inodesize, geo.agcount, geo.agblocks,
> -		"", geo.sectsize, attrversion, projid32bit,
> -		"", crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled,
> -		"", reflink_enabled,
> -		"", geo.blocksize, (unsigned long long)geo.datablocks,
> -			geo.imaxpct,
> -		"", geo.sunit, geo.swidth,
> -  		dirversion, geo.dirblocksize, cimode, ftype_enabled,
> -		isint ? _("internal") : logname ? logname : _("external"),
> -			geo.blocksize, geo.logblocks, logversion,
> -		"", geo.logsectsize, geo.logsunit / geo.blocksize, lazycount,
> -		!geo.rtblocks ? _("none") : rtname ? rtname : _("external"),
> -		geo.rtextsize * geo.blocksize, (unsigned long long)geo.rtblocks,
> -			(unsigned long long)geo.rtextents);
> -}
> -
>  int
>  main(int argc, char **argv)
>  {
> @@ -97,9 +50,6 @@ main(int argc, char **argv)
>  	int			c;	/* current option character */
>  	long long		ddsize;	/* device size in 512-byte blocks */
>  	int			dflag;	/* -d flag */
> -	int			attrversion;/* attribute version number */
> -	int			dirversion; /* directory version number */
> -	int			logversion; /* log version number */
>  	long long		dlsize;	/* device size in 512-byte blocks */
>  	long long		drsize;	/* device size in 512-byte blocks */
>  	long long		dsize;	/* new data size in fs blocks */
> @@ -117,8 +67,6 @@ main(int argc, char **argv)
>  	xfs_fsop_geom_t		ngeo;	/* new fs geometry */
>  	int			rflag;	/* -r flag */
>  	long long		rsize;	/* new rt size in fs blocks */
> -	int			ci;	/* ASCII case-insensitive fs */
> -	int			lazycount; /* lazy superblock counters */
>  	int			xflag;	/* -x flag */
>  	char			*fname;	/* mount point name */
>  	char			*datadev; /* data device name */
> @@ -126,13 +74,6 @@ main(int argc, char **argv)
>  	char			*rtdev;	/*   RT device name */
>  	fs_path_t		*fs;	/* mount point information */
>  	libxfs_init_t		xi;	/* libxfs structure */
> -	int			projid32bit;
> -	int			crcs_enabled;
> -	int			ftype_enabled = 0;
> -	int			finobt_enabled;	/* free inode btree */
> -	int			spinodes;
> -	int			rmapbt_enabled;
> -	int			reflink_enabled;
>  	char			rpath[PATH_MAX];
>  
>  	progname = basename(argv[0]);
> @@ -253,27 +194,6 @@ main(int argc, char **argv)
>  		}
>  	}
>  	isint = geo.logstart > 0;
> -	lazycount = geo.flags & XFS_FSOP_GEOM_FLAGS_LAZYSB ? 1 : 0;
> -	dirversion = geo.flags & XFS_FSOP_GEOM_FLAGS_DIRV2 ? 2 : 1;
> -	logversion = geo.flags & XFS_FSOP_GEOM_FLAGS_LOGV2 ? 2 : 1;
> -	attrversion = geo.flags & XFS_FSOP_GEOM_FLAGS_ATTR2 ? 2 : \
> -			(geo.flags & XFS_FSOP_GEOM_FLAGS_ATTR ? 1 : 0);
> -	ci = geo.flags & XFS_FSOP_GEOM_FLAGS_DIRV2CI ? 1 : 0;
> -	projid32bit = geo.flags & XFS_FSOP_GEOM_FLAGS_PROJID32 ? 1 : 0;
> -	crcs_enabled = geo.flags & XFS_FSOP_GEOM_FLAGS_V5SB ? 1 : 0;
> -	ftype_enabled = geo.flags & XFS_FSOP_GEOM_FLAGS_FTYPE ? 1 : 0;
> -	finobt_enabled = geo.flags & XFS_FSOP_GEOM_FLAGS_FINOBT ? 1 : 0;
> -	spinodes = geo.flags & XFS_FSOP_GEOM_FLAGS_SPINODES ? 1 : 0;
> -	rmapbt_enabled = geo.flags & XFS_FSOP_GEOM_FLAGS_RMAPBT ? 1 : 0;
> -	reflink_enabled = geo.flags & XFS_FSOP_GEOM_FLAGS_REFLINK ? 1 : 0;
> -	if (nflag) {
> -		report_info(geo, datadev, isint, logdev, rtdev,
> -				lazycount, dirversion, logversion,
> -				attrversion, projid32bit, crcs_enabled, ci,
> -				ftype_enabled, finobt_enabled, spinodes,
> -				rmapbt_enabled, reflink_enabled);
> -		exit(0);
> -	}
>  
>  	/*
>  	 * Need root access from here on (using raw devices)...
> @@ -306,11 +226,7 @@ main(int argc, char **argv)
>  		exit(1);
>  	}
>  
> -	report_info(geo, datadev, isint, logdev, rtdev,
> -			lazycount, dirversion, logversion,
> -			attrversion, projid32bit, crcs_enabled, ci, ftype_enabled,
> -			finobt_enabled, spinodes, rmapbt_enabled,
> -			reflink_enabled);
> +	xfs_report_geom(&geo, datadev, logdev, rtdev);
>  
>  	ddsize = xi.dsize;
>  	dlsize = ( xi.logBBsize? xi.logBBsize :
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 2/9] libfrog: refactor fs geometry printing function
  2018-04-18  2:45 ` [PATCH 2/9] libfrog: refactor fs geometry printing function Darrick J. Wong
  2018-05-03 18:47   ` Eric Sandeen
@ 2018-05-03 21:27   ` Eric Sandeen
  2018-05-03 21:35     ` Darrick J. Wong
  1 sibling, 1 reply; 34+ messages in thread
From: Eric Sandeen @ 2018-05-03 21:27 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

On 4/17/18 9:45 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Move the fs geometry printing function to libfrog so that mkfs and others
> can share.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>


> +	printf(_(
> +"meta-data=%-22s isize=%-6d agcount=%u, agsize=%u blks\n"
> +"         =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
> +"         =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u\n"
> +"         =%-22s reflink=%u\n"
> +"data     =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
> +"         =%-22s sunit=%-6u swidth=%u blks\n"
> +"naming   =version %-14u bsize=%-6u ascii-ci=%d, ftype=%d\n"
> +"log      =%-22s bsize=%-6d blocks=%u, version=%d\n"
> +"         =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
> +"realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),

Actually, I'd like to put a whitespace break here as there was in old code,
as this is a giant, dense blob of code that's pretty hard to grok visually.

Any objection? :)

-Eric

> +		mntpoint, geo->inodesize, geo->agcount, geo->agblocks,
> +		"", geo->sectsize, attrversion, projid32bit,
> +		"", crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled,
> +		"", reflink_enabled,
> +		"", geo->blocksize, (unsigned long long)geo->datablocks,
> +			geo->imaxpct,
> +		"", geo->sunit, geo->swidth,
> +		dirversion, geo->dirblocksize, cimode, ftype_enabled,
> +		isint ? _("internal log") : logname ? logname : _("external"),
> +			geo->blocksize, geo->logblocks, logversion,
> +		"", geo->logsectsize, geo->logsunit / geo->blocksize, lazycount,
> +		!geo->rtblocks ? _("none") : rtname ? rtname : _("external"),
> +		geo->rtextsize * geo->blocksize, (unsigned long long)geo->rtblocks,
> +			(unsigned long long)geo->rtextents);
> +}
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 2/9] libfrog: refactor fs geometry printing function
  2018-05-03 21:27   ` Eric Sandeen
@ 2018-05-03 21:35     ` Darrick J. Wong
  0 siblings, 0 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-05-03 21:35 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Thu, May 03, 2018 at 04:27:28PM -0500, Eric Sandeen wrote:
> On 4/17/18 9:45 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Move the fs geometry printing function to libfrog so that mkfs and others
> > can share.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> 
> 
> > +	printf(_(
> > +"meta-data=%-22s isize=%-6d agcount=%u, agsize=%u blks\n"
> > +"         =%-22s sectsz=%-5u attr=%u, projid32bit=%u\n"
> > +"         =%-22s crc=%-8u finobt=%u, sparse=%u, rmapbt=%u\n"
> > +"         =%-22s reflink=%u\n"
> > +"data     =%-22s bsize=%-6u blocks=%llu, imaxpct=%u\n"
> > +"         =%-22s sunit=%-6u swidth=%u blks\n"
> > +"naming   =version %-14u bsize=%-6u ascii-ci=%d, ftype=%d\n"
> > +"log      =%-22s bsize=%-6d blocks=%u, version=%d\n"
> > +"         =%-22s sectsz=%-5u sunit=%d blks, lazy-count=%d\n"
> > +"realtime =%-22s extsz=%-6d blocks=%lld, rtextents=%lld\n"),
> 
> Actually, I'd like to put a whitespace break here as there was in old code,
> as this is a giant, dense blob of code that's pretty hard to grok visually.
> 
> Any objection? :)

None here.

--D

> -Eric
> 
> > +		mntpoint, geo->inodesize, geo->agcount, geo->agblocks,
> > +		"", geo->sectsize, attrversion, projid32bit,
> > +		"", crcs_enabled, finobt_enabled, spinodes, rmapbt_enabled,
> > +		"", reflink_enabled,
> > +		"", geo->blocksize, (unsigned long long)geo->datablocks,
> > +			geo->imaxpct,
> > +		"", geo->sunit, geo->swidth,
> > +		dirversion, geo->dirblocksize, cimode, ftype_enabled,
> > +		isint ? _("internal log") : logname ? logname : _("external"),
> > +			geo->blocksize, geo->logblocks, logversion,
> > +		"", geo->logsectsize, geo->logsunit / geo->blocksize, lazycount,
> > +		!geo->rtblocks ? _("none") : rtname ? rtname : _("external"),
> > +		geo->rtextsize * geo->blocksize, (unsigned long long)geo->rtblocks,
> > +			(unsigned long long)geo->rtextents);
> > +}
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 6/9] xfs_spaceman: add a superblock info command
  2018-05-03 21:09   ` Eric Sandeen
@ 2018-05-03 21:39     ` Darrick J. Wong
  2018-05-08 15:24       ` Darrick J. Wong
  0 siblings, 1 reply; 34+ messages in thread
From: Darrick J. Wong @ 2018-05-03 21:39 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Thu, May 03, 2018 at 04:09:36PM -0500, Eric Sandeen wrote:
> On 4/17/18 9:46 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Add an 'info' command to pretty-print the superblock geometry.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> 
> 
> 
> > diff --git a/spaceman/file.c b/spaceman/file.c
> > index 4f9f66c..6adb4f5 100644
> > --- a/spaceman/file.c
> > +++ b/spaceman/file.c
> > @@ -84,6 +84,8 @@ openfile(
> 
>         char            *path,
>         xfs_fsop_geom_t *geom,
>         struct fs_path  *fs_path)
> {
> ..
> 
>         if (fs_path) {
> ...
> >  			return -1;
> >  		}
> >  		memcpy(fs_path, fsp, sizeof(struct fs_path));
> > +	} else {
> > +		memset(fs_path, 0, sizeof(struct fs_path));
> >  	}
> 
> so if fs_path == NULL memset(NULL, 0) ?
> 
> Not sure what's going on here.
> 
> (or maybe I've forgotten how C works)

Not sure either.  The only caller of openfile() always passes in fs_path
so the else clause can go away.  Bad xfs_io copy pasta, sorry. :(

--D

> >  	return fd;
> >  }
> > diff --git a/spaceman/info.c b/spaceman/info.c
> > new file mode 100644
> > index 0000000..b8b8133
> > --- /dev/null
> > +++ b/spaceman/info.c
> > @@ -0,0 +1,96 @@
> > +/*
> > + * Copyright (C) 2018 Oracle.  All Rights Reserved.
> > + *
> > + * Author: Darrick J. Wong <darrick.wong@oracle.com>
> > + *
> > + * This program is free software; you can redistribute it and/or
> > + * modify it under the terms of the GNU General Public License
> > + * as published by the Free Software Foundation; either version 2
> > + * of the License, or (at your option) any later version.
> > + *
> > + * This program is distributed in the hope that it would be useful,
> > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > + * GNU General Public License for more details.
> > + *
> > + * You should have received a copy of the GNU General Public License
> > + * along with this program; if not, write the Free Software Foundation,
> > + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
> > + */
> > +#include "libxfs.h"
> > +#include "command.h"
> > +#include "init.h"
> > +#include "path.h"
> > +#include "space.h"
> > +#include "fsgeom.h"
> > +
> > +static void
> > +info_help(void)
> > +{
> > +	printf(_(
> > +"\n"
> > +" Pretty-prints the filesystem geometry as derived from the superblock.\n"
> > +" The output has the same format as mkfs.  The opened file must be a XFS\n"
> 
> "an XFS?"
> 
> > +" mount point.\n"
> > +"\n"
> > +));
> > +
> > +}
> > +
> > +static int
> > +info_f(
> > +	int			argc,
> > +	char			**argv)
> > +{
> > +	struct xfs_fsop_geom	geo;
> > +	int			error;
> > +
> > +	if (fs_table_lookup_mount(file->name) == NULL) {
> > +		fprintf(stderr, _("%s: Not a XFS mount point.\n"), file->name);
> > +		return 1;
> > +	}
> > +
> > +	/* 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);
> 
> We're certain that it won't fill in logsunit with junk, right?
> Would it be any safer to set logsunit after or is that presupposing too
> much about the interface?  I guess it's fine.
> 
> > +		if (error) {
> > +			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,
> > +			file->fs_path.fs_rt);
> > +	return 0;
> > +}
> > +
> > +static const struct cmdinfo info_cmd = {
> > +	.name =		"info",
> > +	.altname =	"i",
> > +	.cfunc =	info_f,
> > +	.argmin =	0,
> > +	.argmax =	0,
> > +	.canpush =	0,
> > +	.args =		NULL,
> > +	.flags =	CMD_FLAG_ONESHOT,
> > +	.oneline =	N_("dump superblock info"),
> 
> "print geometry superblock info"
> 
> > +	.help =		info_help,
> > +};
> > +
> > +void
> > +info_init(void)
> > +{
> > +	add_command(&info_cmd);
> > +}
> > diff --git a/spaceman/init.c b/spaceman/init.c
> > index b3eface..895504f 100644
> > --- a/spaceman/init.c
> > +++ b/spaceman/init.c
> > @@ -40,6 +40,7 @@ init_commands(void)
> >  {
> >  	print_init();
> >  	help_init();
> > +	info_init();
> >  	prealloc_init();
> >  	quit_init();
> >  	trim_init();
> > diff --git a/spaceman/space.h b/spaceman/space.h
> > index 5f4a8a0..d2a2543 100644
> > --- a/spaceman/space.h
> > +++ b/spaceman/space.h
> > @@ -42,5 +42,6 @@ extern void	freesp_init(void);
> >  #else
> >  # define freesp_init()	do { } while (0)
> >  #endif
> > +extern void	info_init(void);
> >  
> >  #endif /* XFS_SPACEMAN_SPACE_H_ */
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 4/9] xfs_db: add a superblock info command
  2018-05-03 20:53   ` Eric Sandeen
@ 2018-05-03 21:44     ` Darrick J. Wong
  0 siblings, 0 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-05-03 21:44 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Thu, May 03, 2018 at 03:53:30PM -0500, Eric Sandeen wrote:
> On 4/17/18 9:45 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Add an 'info' command to pretty-print the superblock geometry.
> 
> This seems ... fine, it's a bit out of xfs_db's charter but ...
> I see where you're going with this ... ;)
> 
> A little nitpicky below though.
> 
> > +static void
> > +info_help(void)
> > +{
> > +	dbprintf(_(
> > +"\n"
> > +" Pretty-prints the filesystem geometry as derived from the superblock.\n"
> > +" The output has the same format as mkfs.\n"
> 
> mkfs.xfs, xfs_info, and other utilities. ?

Ok.  It seems a little ouroborousy for one of the (future) xfs_info
backends to say that it behaves like xfs_info but eh that's fine. :)

> > +"\n"
> > +));
> > +
> > +}
> > +
> > +static int
> > +info_f(
> > +	int			argc,
> > +	char			**argv)
> > +{
> > +	struct xfs_fsop_geom	geo;
> > +	int			error;
> > +
> > +	error = -libxfs_fs_geometry(&mp->m_sb, &geo,
> > +			XFS_FS_GEOM_MAX_STRUCT_VER);
> > +	if (error) {
> > +		dbprintf(_("could not obtain geometry\n"));
> > +		exitcode = 1;
> > +		return 0;
> > +	}
> > +
> > +	xfs_report_geom(&geo, fsdevice, x.logname, x.rtname);
> > +	return 0;
> > +}
> > +
> > +static const struct cmdinfo info_cmd = {
> > +	.name =		"info",
> > +	.altname =	"i",
> > +	.cfunc =	info_f,
> > +	.argmin =	0,
> > +	.argmax =	0,
> > +	.canpush =	0,
> > +	.args =		NULL,
> > +	.oneline =	N_("dump superblock info"),
> 
> "pretty-print superblock geometry info"  ?

Ok.

> > +	.help =		info_help,
> > +};
> > +
> > +void
> > +info_init(void)
> > +{
> > +	add_command(&info_cmd);
> > +}
> > diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8
> > index 524b1ef..e29821e 100644
> > --- a/man/man8/xfs_db.8
> > +++ b/man/man8/xfs_db.8
> > @@ -670,6 +670,12 @@ using the hash function of the XFS directory and attribute implementation.
> >  .BI "help [" command ]
> >  Print help for one or all commands.
> >  .TP
> > +.B info
> > +Displays selected geometry information about the filesystem.
> > +The output will have the same format that
> > +.BR "mkfs.xfs" "(8)"
> > +prints when creating a filesystem.
> 
> Again adding xfs_info here might be nice too?
> 
> Just seems a little odd to single out one utility, not a huge deal tho.
> 
> I could just add these if you agree.  Or drop it if not ;)

Sure, it's fine by me.

--D

> > +.TP
> >  .BI "inode [" inode# ]
> >  Set the current inode number. If no
> >  .I inode#
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 7/9] xfs_info: move to xfs_spaceman
  2018-05-03 21:17   ` Eric Sandeen
@ 2018-05-03 21:48     ` Darrick J. Wong
  0 siblings, 0 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-05-03 21:48 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Thu, May 03, 2018 at 04:17:00PM -0500, Eric Sandeen wrote:
> On 4/17/18 9:46 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Move xfs_info to be under spaceman so that we can remove growfs -N.
> 
> Seems ok in general, though how will this work with Dave's upcoming
> special subvol-files-no-they're-devices-no-they're-files?
> 
> Do we worry about all that later?  I guess?

I think we can worry about that later seeing as Dave hasn't posted
patches recently. :)

> (I guess we don't document -p as it's for internal use)
> 
> Modulo that concern,

FWIW this patch just moves xfs_info to use spaceman instead of growfs,
so I'll go blather about xfs_db/xfs_spaceman switcheroo in that patch.

--D

> Reviewed-by: Eric Sandeen <sandeen@redhat.com>
> 
> -Eric
> 
> 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> >  growfs/Makefile      |    2 --
> >  growfs/xfs_info.sh   |   32 --------------------------------
> >  spaceman/Makefile    |    2 ++
> >  spaceman/init.c      |    5 ++++-
> >  spaceman/xfs_info.sh |   32 ++++++++++++++++++++++++++++++++
> >  5 files changed, 38 insertions(+), 35 deletions(-)
> >  delete mode 100755 growfs/xfs_info.sh
> >  create mode 100755 spaceman/xfs_info.sh
> > 
> > 
> > diff --git a/growfs/Makefile b/growfs/Makefile
> > index f0190e4..adcd84b 100644
> > --- a/growfs/Makefile
> > +++ b/growfs/Makefile
> > @@ -20,7 +20,6 @@ endif
> >  
> >  LTDEPENDENCIES = $(LIBXFS) $(LIBXCMD) $(LIBFROG)
> >  LLDFLAGS = -static-libtool-libs
> > -LSRCFILES = xfs_info.sh
> >  
> >  default: depend $(LTCOMMAND)
> >  
> > @@ -29,7 +28,6 @@ include $(BUILDRULES)
> >  install: default
> >  	$(INSTALL) -m 755 -d $(PKG_SBIN_DIR)
> >  	$(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR)
> > -	$(INSTALL) -m 755 xfs_info.sh $(PKG_SBIN_DIR)/xfs_info
> >  install-dev:
> >  
> >  -include .dep
> > diff --git a/growfs/xfs_info.sh b/growfs/xfs_info.sh
> > deleted file mode 100755
> > index b85f120..0000000
> > --- a/growfs/xfs_info.sh
> > +++ /dev/null
> > @@ -1,32 +0,0 @@
> > -#!/bin/sh -f
> > -#
> > -# Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
> > -#
> > -
> > -OPTS=""
> > -USAGE="Usage: xfs_info [-V] [-t mtab] mountpoint"
> > -
> > -while getopts "t:V" c
> > -do
> > -	case $c in
> > -	t)	OPTS="-t $OPTARG" ;;
> > -	V)	xfs_growfs -p xfs_info -V
> > -		status=$?
> > -		exit $status
> > -		;;
> > -	*)	echo $USAGE 1>&2
> > -		exit 2
> > -		;;
> > -	esac
> > -done
> > -set -- extra "$@"
> > -shift $OPTIND
> > -case $# in
> > -	1)	xfs_growfs -p xfs_info -n $OPTS "$1"
> > -		status=$?
> > -		;;
> > -	*)	echo $USAGE 1>&2
> > -		exit 2
> > -		;;
> > -esac
> > -exit $status
> > diff --git a/spaceman/Makefile b/spaceman/Makefile
> > index c1d903b..0d5ae2d 100644
> > --- a/spaceman/Makefile
> > +++ b/spaceman/Makefile
> > @@ -8,6 +8,7 @@ include $(TOPDIR)/include/builddefs
> >  LTCOMMAND = xfs_spaceman
> >  HFILES = init.h space.h
> >  CFILES = info.c init.c file.c prealloc.c trim.c
> > +LSRCFILES = xfs_info.sh
> >  
> >  LLDLIBS = $(LIBXCMD) $(LIBFROG)
> >  LTDEPENDENCIES = $(LIBXCMD) $(LIBFROG)
> > @@ -35,6 +36,7 @@ include $(BUILDRULES)
> >  install: default
> >  	$(INSTALL) -m 755 -d $(PKG_SBIN_DIR)
> >  	$(LTINSTALL) -m 755 $(LTCOMMAND) $(PKG_SBIN_DIR)
> > +	$(INSTALL) -m 755 xfs_info.sh $(PKG_SBIN_DIR)/xfs_info
> >  install-dev:
> >  
> >  -include .dep
> > diff --git a/spaceman/init.c b/spaceman/init.c
> > index 895504f..91c773f 100644
> > --- a/spaceman/init.c
> > +++ b/spaceman/init.c
> > @@ -81,11 +81,14 @@ init(
> >  	textdomain(PACKAGE);
> >  
> >  	fs_table_initialise(0, NULL, 0, NULL);
> > -	while ((c = getopt(argc, argv, "c:V")) != EOF) {
> > +	while ((c = getopt(argc, argv, "c:p:V")) != EOF) {
> >  		switch (c) {
> >  		case 'c':
> >  			add_user_command(optarg);
> >  			break;
> > +		case 'p':
> > +			progname = optarg;
> > +			break;
> >  		case 'V':
> >  			printf(_("%s version %s\n"), progname, VERSION);
> >  			exit(0);
> > diff --git a/spaceman/xfs_info.sh b/spaceman/xfs_info.sh
> > new file mode 100755
> > index 0000000..5df0a26
> > --- /dev/null
> > +++ b/spaceman/xfs_info.sh
> > @@ -0,0 +1,32 @@
> > +#!/bin/sh -f
> > +#
> > +# Copyright (c) 2000-2001 Silicon Graphics, Inc.  All Rights Reserved.
> > +#
> > +
> > +OPTS=""
> > +USAGE="Usage: xfs_info [-V] [-t mtab] mountpoint"
> > +
> > +while getopts "t:V" c
> > +do
> > +	case $c in
> > +	t)	OPTS="-t $OPTARG" ;;
> > +	V)	xfs_spaceman -p xfs_info -V
> > +		status=$?
> > +		exit $status
> > +		;;
> > +	*)	echo $USAGE 1>&2
> > +		exit 2
> > +		;;
> > +	esac
> > +done
> > +set -- extra "$@"
> > +shift $OPTIND
> > +case $# in
> > +	1)	xfs_spaceman -p xfs_info -c "info" $OPTS "$1"
> > +		status=$?
> > +		;;
> > +	*)	echo $USAGE 1>&2
> > +		exit 2
> > +		;;
> > +esac
> > +exit $status
> > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 8/9] xfs_info: call xfs_db for offline filesystems
  2018-05-03 21:22   ` Eric Sandeen
@ 2018-05-03 21:55     ` Darrick J. Wong
  0 siblings, 0 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-05-03 21:55 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Thu, May 03, 2018 at 04:22:24PM -0500, Eric Sandeen wrote:
> On 4/17/18 9:46 PM, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > If the online filesystem geometry query doesn't work, try using xfs_db
> > to see if we can grab the information offline.
> > 
> 
> I'm slightly concerned that having all-singing, all-dancing tools
> that operate on mounted, unmounted, devices, mountpoints, and images
> will further encourage people to think that operations on mounted
> block devices are Just Fine(tm).

<nod> The current semantics of xfs_info are that one has to feed it a
mountpoint, which means the arg is a direct... oh dangit.

# touch mugga
# mount /bin/true mugga --bind
# xfs_info ./mugga 
meta-data=/dev/mapper/system-root isize=512    agcount=4, agsize=1953024 blks

Uh, ok, so the new behavior of xfs_info is that if you pass it a block
device or a file it'll try to call xfs_db (assuming it's a fs, fs image
file, or I guess future-dchinner subvolume); and if it's any other kind
of fs object it'll try spaceman (which requires a mountpoint arg).

Hopefully that's ok with Dave's subvol plans?

> But ... I suppose the convenience is worth it.
> 
> ...
> 
> > diff --git a/man/man8/xfs_info.8 b/man/man8/xfs_info.8
> > new file mode 100644
> > index 0000000..c4c470d
> > --- /dev/null
> > +++ b/man/man8/xfs_info.8
> > @@ -0,0 +1,95 @@
> > +.\" Verbatim blocks taken from openssl req manpage content
> > +.de Vb \" Begin verbatim text
> > +.ft CW
> > +.nf
> > +.ne \\$1
> > +..
> > +.de Ve \" End verbatim text
> > +.ft R
> > +.fi
> > +..
> > +
> > +.TH xfs_info 8
> > +.SH NAME
> > +xfs_info, \- display XFS filesystem geometry information
> 
> drop the comma pls, or I can do this.

I'll drop it in my patches, though if you don't find any serious
problems that warrant a reissue then you should do it.

> ...
> 
> > +.BR \-V .
> > +.SH "EXAMPLES"
> > +
> > +Understanding xfs_info output.
> > +.PP
> > +Suppose one has the following "xfs_info /dev/sda" output:
> > +.PP
> > +.RS 2
> > +.Vb
> > +\&meta-data=/dev/sda      isize=256    agcount=32, agsize=16777184 blks
> > +\&         =              sectsz=512   attr=2
> > +\&data     =              bsize=4096   blocks=536869888, imaxpct=5
> > +\&         =              sunit=32     swidth=128 blks
> > +\&naming   =version 2     bsize=4096
> > +\&log      =internal log  bsize=4096   blocks=32768, version=2
> > +\&         =              sectsz=512   sunit=32 blks, lazy-count=1
> > +\&realtime =none          extsz=524288 blocks=0, rtextents=0
> > +.Ve
> 
> Should we update this to a more modern version?  *shrug*

Yeah probably.

--D

> 
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH 6/9] xfs_spaceman: add a superblock info command
  2018-05-03 21:39     ` Darrick J. Wong
@ 2018-05-08 15:24       ` Darrick J. Wong
  0 siblings, 0 replies; 34+ messages in thread
From: Darrick J. Wong @ 2018-05-08 15:24 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: sandeen, linux-xfs

On Thu, May 03, 2018 at 02:39:04PM -0700, Darrick J. Wong wrote:
> On Thu, May 03, 2018 at 04:09:36PM -0500, Eric Sandeen wrote:
> > On 4/17/18 9:46 PM, Darrick J. Wong wrote:
> > > From: Darrick J. Wong <darrick.wong@oracle.com>
> > > 
> > > Add an 'info' command to pretty-print the superblock geometry.
> > > 
> > > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > > ---
> > 
> > 
> > 
> > > diff --git a/spaceman/file.c b/spaceman/file.c
> > > index 4f9f66c..6adb4f5 100644
> > > --- a/spaceman/file.c
> > > +++ b/spaceman/file.c
> > > @@ -84,6 +84,8 @@ openfile(
> > 
> >         char            *path,
> >         xfs_fsop_geom_t *geom,
> >         struct fs_path  *fs_path)
> > {
> > ..
> > 
> >         if (fs_path) {
> > ...
> > >  			return -1;
> > >  		}
> > >  		memcpy(fs_path, fsp, sizeof(struct fs_path));
> > > +	} else {
> > > +		memset(fs_path, 0, sizeof(struct fs_path));
> > >  	}
> > 
> > so if fs_path == NULL memset(NULL, 0) ?
> > 
> > Not sure what's going on here.
> > 
> > (or maybe I've forgotten how C works)
> 
> Not sure either.  The only caller of openfile() always passes in fs_path
> so the else clause can go away.  Bad xfs_io copy pasta, sorry. :(
> 
> --D

Dangit, I missed some comments.

> > >  	return fd;
> > >  }
> > > diff --git a/spaceman/info.c b/spaceman/info.c
> > > new file mode 100644
> > > index 0000000..b8b8133
> > > --- /dev/null
> > > +++ b/spaceman/info.c
> > > @@ -0,0 +1,96 @@
> > > +/*
> > > + * Copyright (C) 2018 Oracle.  All Rights Reserved.
> > > + *
> > > + * Author: Darrick J. Wong <darrick.wong@oracle.com>
> > > + *
> > > + * This program is free software; you can redistribute it and/or
> > > + * modify it under the terms of the GNU General Public License
> > > + * as published by the Free Software Foundation; either version 2
> > > + * of the License, or (at your option) any later version.
> > > + *
> > > + * This program is distributed in the hope that it would be useful,
> > > + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> > > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > > + * GNU General Public License for more details.
> > > + *
> > > + * You should have received a copy of the GNU General Public License
> > > + * along with this program; if not, write the Free Software Foundation,
> > > + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
> > > + */
> > > +#include "libxfs.h"
> > > +#include "command.h"
> > > +#include "init.h"
> > > +#include "path.h"
> > > +#include "space.h"
> > > +#include "fsgeom.h"
> > > +
> > > +static void
> > > +info_help(void)
> > > +{
> > > +	printf(_(
> > > +"\n"
> > > +" Pretty-prints the filesystem geometry as derived from the superblock.\n"
> > > +" The output has the same format as mkfs.  The opened file must be a XFS\n"
> > 
> > "an XFS?"

Sure.

> > > +" mount point.\n"
> > > +"\n"
> > > +));
> > > +
> > > +}
> > > +
> > > +static int
> > > +info_f(
> > > +	int			argc,
> > > +	char			**argv)
> > > +{
> > > +	struct xfs_fsop_geom	geo;
> > > +	int			error;
> > > +
> > > +	if (fs_table_lookup_mount(file->name) == NULL) {
> > > +		fprintf(stderr, _("%s: Not a XFS mount point.\n"), file->name);
> > > +		return 1;
> > > +	}
> > > +
> > > +	/* 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);
> > 
> > We're certain that it won't fill in logsunit with junk, right?
> > Would it be any safer to set logsunit after or is that presupposing too
> > much about the interface?  I guess it's fine.

The kernel had better not fill logsunit with anything, since it copies
the v1 structure back to userspace and the v1 structure isn't long
enough to overlay logsunit.

> > > +		if (error) {
> > > +			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,
> > > +			file->fs_path.fs_rt);
> > > +	return 0;
> > > +}
> > > +
> > > +static const struct cmdinfo info_cmd = {
> > > +	.name =		"info",
> > > +	.altname =	"i",
> > > +	.cfunc =	info_f,
> > > +	.argmin =	0,
> > > +	.argmax =	0,
> > > +	.canpush =	0,
> > > +	.args =		NULL,
> > > +	.flags =	CMD_FLAG_ONESHOT,
> > > +	.oneline =	N_("dump superblock info"),
> > 
> > "print geometry superblock info"

"pretty-print superblock geometry info" ?

--D

> > > +	.help =		info_help,
> > > +};
> > > +
> > > +void
> > > +info_init(void)
> > > +{
> > > +	add_command(&info_cmd);
> > > +}
> > > diff --git a/spaceman/init.c b/spaceman/init.c
> > > index b3eface..895504f 100644
> > > --- a/spaceman/init.c
> > > +++ b/spaceman/init.c
> > > @@ -40,6 +40,7 @@ init_commands(void)
> > >  {
> > >  	print_init();
> > >  	help_init();
> > > +	info_init();
> > >  	prealloc_init();
> > >  	quit_init();
> > >  	trim_init();
> > > diff --git a/spaceman/space.h b/spaceman/space.h
> > > index 5f4a8a0..d2a2543 100644
> > > --- a/spaceman/space.h
> > > +++ b/spaceman/space.h
> > > @@ -42,5 +42,6 @@ extern void	freesp_init(void);
> > >  #else
> > >  # define freesp_init()	do { } while (0)
> > >  #endif
> > > +extern void	info_init(void);
> > >  
> > >  #endif /* XFS_SPACEMAN_SPACE_H_ */
> > > 
> > > --
> > > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > > the body of a message to majordomo@vger.kernel.org
> > > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> > > 
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 34+ messages in thread

* [PATCH v2 4/9] xfs_db: add a superblock info command
  2018-04-18  2:45 ` [PATCH 4/9] xfs_db: add a superblock info command Darrick J. Wong
  2018-05-03 20:53   ` Eric Sandeen
@ 2018-05-23  3:30   ` Darrick J. Wong
  2018-05-23  3:57     ` Allison Henderson
  1 sibling, 1 reply; 34+ messages in thread
From: Darrick J. Wong @ 2018-05-23  3:30 UTC (permalink / raw)
  To: sandeen; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Add an 'info' command to pretty-print the superblock geometry.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 db/Makefile       |    2 +
 db/command.c      |    1 +
 db/command.h      |    1 +
 db/info.c         |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/man8/xfs_db.8 |    8 ++++++
 5 files changed, 85 insertions(+), 1 deletion(-)
 create mode 100644 db/info.c

diff --git a/db/Makefile b/db/Makefile
index 6caa6348..c73d7f25 100644
--- a/db/Makefile
+++ b/db/Makefile
@@ -14,7 +14,7 @@ HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
 	io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \
 	sig.h strvec.h text.h type.h write.h attrset.h symlink.h fsmap.h \
 	fuzz.h
-CFILES = $(HFILES:.h=.c) btdump.c
+CFILES = $(HFILES:.h=.c) btdump.c info.c
 LSRCFILES = xfs_admin.sh xfs_ncheck.sh xfs_metadump.sh
 
 LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
diff --git a/db/command.c b/db/command.c
index 12ae5b78..087955e0 100644
--- a/db/command.c
+++ b/db/command.c
@@ -136,6 +136,7 @@ init_commands(void)
 	fsmap_init();
 	help_init();
 	hash_init();
+	info_init();
 	inode_init();
 	input_init();
 	logres_init();
diff --git a/db/command.h b/db/command.h
index 9b4ed2d7..84cd0b10 100644
--- a/db/command.h
+++ b/db/command.h
@@ -41,3 +41,4 @@ extern const cmdinfo_t	*find_command(const char *cmd);
 extern void		init_commands(void);
 
 extern void		btdump_init(void);
+extern void		info_init(void);
diff --git a/db/info.c b/db/info.c
new file mode 100644
index 00000000..05b3c1f0
--- /dev/null
+++ b/db/info.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2018 Oracle.  All Rights Reserved.
+ *
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#include "libxfs.h"
+#include "command.h"
+#include "init.h"
+#include "output.h"
+#include "fsgeom.h"
+
+static void
+info_help(void)
+{
+	dbprintf(_(
+"\n"
+" Pretty-prints the filesystem geometry as derived from the superblock.\n"
+" The output has the same format as mkfs.xfs, xfs_info, and other utilities.\n"
+"\n"
+));
+
+}
+
+static int
+info_f(
+	int			argc,
+	char			**argv)
+{
+	struct xfs_fsop_geom	geo;
+	int			error;
+
+	error = -libxfs_fs_geometry(&mp->m_sb, &geo,
+			XFS_FS_GEOM_MAX_STRUCT_VER);
+	if (error) {
+		dbprintf(_("could not obtain geometry\n"));
+		exitcode = 1;
+		return 0;
+	}
+
+	xfs_report_geom(&geo, fsdevice, x.logname, x.rtname);
+	return 0;
+}
+
+static const struct cmdinfo info_cmd = {
+	.name =		"info",
+	.altname =	"i",
+	.cfunc =	info_f,
+	.argmin =	0,
+	.argmax =	0,
+	.canpush =	0,
+	.args =		NULL,
+	.oneline =	N_("pretty-print superblock info"),
+	.help =		info_help,
+};
+
+void
+info_init(void)
+{
+	add_command(&info_cmd);
+}
diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8
index 524b1ef6..10f2beb9 100644
--- a/man/man8/xfs_db.8
+++ b/man/man8/xfs_db.8
@@ -670,6 +670,14 @@ using the hash function of the XFS directory and attribute implementation.
 .BI "help [" command ]
 Print help for one or all commands.
 .TP
+.B info
+Displays selected geometry information about the filesystem.
+The output will have the same format that
+.BR "mkfs.xfs" "(8)"
+prints when creating a filesystem or
+.BR "xfs_info" "(8)"
+prints when querying a filesystem.
+.TP
 .BI "inode [" inode# ]
 Set the current inode number. If no
 .I inode#

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 5/9] xfs_spaceman: print a nicer message when the file path isn't on an xfs
  2018-04-18  2:46 ` [PATCH 5/9] xfs_spaceman: print a nicer message when the file path isn't on an xfs Darrick J. Wong
  2018-05-03 20:57   ` Eric Sandeen
@ 2018-05-23  3:31   ` Darrick J. Wong
  2018-05-23  3:58     ` Allison Henderson
  1 sibling, 1 reply; 34+ messages in thread
From: Darrick J. Wong @ 2018-05-23  3:31 UTC (permalink / raw)
  To: sandeen; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

If the file path passed in is not something on an xfs filesystem, print
a nice message about that instead of yelling about ioctls.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 spaceman/file.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/spaceman/file.c b/spaceman/file.c
index 4c13b4a8..23f8be1c 100644
--- a/spaceman/file.c
+++ b/spaceman/file.c
@@ -69,7 +69,12 @@ openfile(
 	}
 
 	if (ioctl(fd, XFS_IOC_FSGEOMETRY, geom) < 0) {
-		perror("XFS_IOC_FSGEOMETRY");
+		if (errno == ENOTTY)
+			fprintf(stderr,
+_("%s: Not on a mounted XFS filesystem.\n"),
+					path);
+		else
+			perror("XFS_IOC_FSGEOMETRY");
 		close(fd);
 		return -1;
 	}

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 6/9] xfs_spaceman: add a superblock info command
  2018-04-18  2:46 ` [PATCH 6/9] xfs_spaceman: add a superblock info command Darrick J. Wong
  2018-05-03 21:09   ` Eric Sandeen
@ 2018-05-23  3:32   ` Darrick J. Wong
  2018-05-23  4:08     ` Allison Henderson
  1 sibling, 1 reply; 34+ messages in thread
From: Darrick J. Wong @ 2018-05-23  3:32 UTC (permalink / raw)
  To: sandeen; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

Add an 'info' command to pretty-print the superblock geometry.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 man/man8/xfs_spaceman.8 |    7 +++
 spaceman/Makefile       |    2 -
 spaceman/info.c         |   96 +++++++++++++++++++++++++++++++++++++++++++++++
 spaceman/init.c         |    1 
 spaceman/space.h        |    1 
 6 files changed, 111 insertions(+), 6 deletions(-)
 create mode 100644 spaceman/info.c

diff --git a/man/man8/xfs_spaceman.8 b/man/man8/xfs_spaceman.8
index e4a9137f..12dd04e4 100644
--- a/man/man8/xfs_spaceman.8
+++ b/man/man8/xfs_spaceman.8
@@ -84,6 +84,13 @@ Display a summary of the free space information found.
 .PD
 .RE
 .TP
+.B info
+Displays selected geometry information about the filesystem.
+The opened file must be a mount point of a XFS filesystem.
+The output will have the same format that
+.BR "xfs_info" "(8)"
+prints when querying a filesystem.
+.TP
 .BR "help [ " command " ]"
 Display a brief description of one or all commands.
 .TP
diff --git a/spaceman/Makefile b/spaceman/Makefile
index 8b310309..c1d903ba 100644
--- a/spaceman/Makefile
+++ b/spaceman/Makefile
@@ -7,7 +7,7 @@ include $(TOPDIR)/include/builddefs
 
 LTCOMMAND = xfs_spaceman
 HFILES = init.h space.h
-CFILES = init.c file.c prealloc.c trim.c
+CFILES = info.c init.c file.c prealloc.c trim.c
 
 LLDLIBS = $(LIBXCMD) $(LIBFROG)
 LTDEPENDENCIES = $(LIBXCMD) $(LIBFROG)
diff --git a/spaceman/info.c b/spaceman/info.c
new file mode 100644
index 00000000..8889346b
--- /dev/null
+++ b/spaceman/info.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2018 Oracle.  All Rights Reserved.
+ *
+ * Author: Darrick J. Wong <darrick.wong@oracle.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it would be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write the Free Software Foundation,
+ * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+#include "libxfs.h"
+#include "command.h"
+#include "init.h"
+#include "path.h"
+#include "space.h"
+#include "fsgeom.h"
+
+static void
+info_help(void)
+{
+	printf(_(
+"\n"
+" Pretty-prints the filesystem geometry as derived from the superblock.\n"
+" The output has the same format as mkfs.xfs, xfs_info, and other utilities.\n"
+" The opened file must be an XFS mount point.\n"
+"\n"
+));
+
+}
+
+static int
+info_f(
+	int			argc,
+	char			**argv)
+{
+	struct xfs_fsop_geom	geo;
+	int			error;
+
+	if (fs_table_lookup_mount(file->name) == NULL) {
+		fprintf(stderr, _("%s: Not a XFS mount point.\n"), file->name);
+		return 1;
+	}
+
+	/* 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;
+		}
+	}
+
+	xfs_report_geom(&geo, file->fs_path.fs_name, file->fs_path.fs_log,
+			file->fs_path.fs_rt);
+	return 0;
+}
+
+static const struct cmdinfo info_cmd = {
+	.name =		"info",
+	.altname =	"i",
+	.cfunc =	info_f,
+	.argmin =	0,
+	.argmax =	0,
+	.canpush =	0,
+	.args =		NULL,
+	.flags =	CMD_FLAG_ONESHOT,
+	.oneline =	N_("pretty-print superblock geometry info"),
+	.help =		info_help,
+};
+
+void
+info_init(void)
+{
+	add_command(&info_cmd);
+}
diff --git a/spaceman/init.c b/spaceman/init.c
index b3efacef..895504f3 100644
--- a/spaceman/init.c
+++ b/spaceman/init.c
@@ -40,6 +40,7 @@ init_commands(void)
 {
 	print_init();
 	help_init();
+	info_init();
 	prealloc_init();
 	quit_init();
 	trim_init();
diff --git a/spaceman/space.h b/spaceman/space.h
index 5f4a8a0b..d2a25432 100644
--- a/spaceman/space.h
+++ b/spaceman/space.h
@@ -42,5 +42,6 @@ extern void	freesp_init(void);
 #else
 # define freesp_init()	do { } while (0)
 #endif
+extern void	info_init(void);
 
 #endif /* XFS_SPACEMAN_SPACE_H_ */

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [PATCH v2 8/9] xfs_info: call xfs_db for offline filesystems
  2018-04-18  2:46 ` [PATCH 8/9] xfs_info: call xfs_db for offline filesystems Darrick J. Wong
  2018-05-03 21:22   ` Eric Sandeen
@ 2018-05-23  3:33   ` Darrick J. Wong
  2018-05-23  4:36     ` Allison Henderson
  1 sibling, 1 reply; 34+ messages in thread
From: Darrick J. Wong @ 2018-05-23  3:33 UTC (permalink / raw)
  To: sandeen; +Cc: linux-xfs

From: Darrick J. Wong <darrick.wong@oracle.com>

If the online filesystem geometry query doesn't work, try using xfs_db
to see if we can grab the information offline.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 man/man8/xfs_growfs.8 |   47 +-----------------------
 man/man8/xfs_info.8   |   97 +++++++++++++++++++++++++++++++++++++++++++++++++
 spaceman/xfs_info.sh  |   12 +++++-
 3 files changed, 108 insertions(+), 48 deletions(-)
 create mode 100644 man/man8/xfs_info.8

diff --git a/man/man8/xfs_growfs.8 b/man/man8/xfs_growfs.8
index e23d30e2..7e6a387c 100644
--- a/man/man8/xfs_growfs.8
+++ b/man/man8/xfs_growfs.8
@@ -11,7 +11,7 @@
 
 .TH xfs_growfs 8
 .SH NAME
-xfs_growfs, xfs_info \- expand an XFS filesystem
+xfs_growfs \- expand an XFS filesystem
 .SH SYNOPSIS
 .B xfs_growfs
 [
@@ -38,16 +38,6 @@ xfs_growfs, xfs_info \- expand an XFS filesystem
 .I mount-point
 .br
 .B xfs_growfs \-V
-.PP
-.br
-.B xfs_info
-[
-.B \-t
-.I mtab
-]
-.I mount-point
-.br
-.B xfs_info \-V
 .SH DESCRIPTION
 .B xfs_growfs
 expands an existing XFS filesystem (see
@@ -59,13 +49,6 @@ is mounted. The filesystem must be mounted to be grown (see
 .BR mount (8)).
 The existing contents of the filesystem are undisturbed, and the added space
 becomes available for additional file storage.
-.PP
-.B xfs_info
-is equivalent to invoking
-.B xfs_growfs
-with the
-.B \-n
-option (see discussion below).
 .SH OPTIONS
 .TP
 .BI "\-d | \-D " size
@@ -169,35 +152,9 @@ reside. In order to grow a filesystem, it is necessary to provide added
 space for it to occupy. Therefore there must be at least one spare new
 disk partition available. Adding the space is often done through the use
 of a logical volume manager.
-.SH "EXAMPLES"
-
-Understanding xfs_info output.
-.PP
-Suppose one has the following "xfs_info /dev/sda" output:
-.PP
-.RS 2
-.Vb
-\&meta-data=/dev/sda      isize=256    agcount=32, agsize=16777184 blks
-\&         =              sectsz=512   attr=2
-\&data     =              bsize=4096   blocks=536869888, imaxpct=5
-\&         =              sunit=32     swidth=128 blks
-\&naming   =version 2     bsize=4096
-\&log      =internal      bsize=4096   blocks=32768, version=2
-\&         =              sectsz=512   sunit=32 blks, lazy-count=1
-\&realtime =none          extsz=524288 blocks=0, rtextents=0
-.Ve
-.RE
-.PP
-
-Here, the data section of the output indicates "bsize=4096",
-meaning the data block size for this filesystem is 4096 bytes.
-This section also shows "sunit=32 swidth=128 blks", which means
-the stripe unit is 32*4096 bytes = 128 kibibytes and the stripe
-width is 128*4096 bytes = 512 kibibytes.
-A single stripe of this filesystem therefore consists
-of four stripe units (128 blocks / 32 blocks per unit).
 .SH SEE ALSO
 .BR mkfs.xfs (8),
+.BR xfs_info (8),
 .BR md (4),
 .BR lvm (8),
 .BR mount (8).
diff --git a/man/man8/xfs_info.8 b/man/man8/xfs_info.8
new file mode 100644
index 00000000..429356a8
--- /dev/null
+++ b/man/man8/xfs_info.8
@@ -0,0 +1,97 @@
+.\" Verbatim blocks taken from openssl req manpage content
+.de Vb \" Begin verbatim text
+.ft CW
+.nf
+.ne \\$1
+..
+.de Ve \" End verbatim text
+.ft R
+.fi
+..
+
+.TH xfs_info 8
+.SH NAME
+xfs_info \- display XFS filesystem geometry information
+.SH SYNOPSIS
+.B xfs_info
+[
+.B \-t
+.I mtab
+]
+[
+.I mount-point
+|
+.I block-device
+|
+.I file-image
+]
+.br
+.B xfs_info \-V
+.SH DESCRIPTION
+.B xfs_info
+displays geometry information about an existing XFS filesystem.
+The
+.I mount-point
+argument is the pathname of a directory where the filesystem
+is mounted.
+The
+.I block-device
+or
+.I file-image
+contain a raw XFS filesystem.
+The existing contents of the filesystem are undisturbed.
+.SH OPTIONS
+.TP
+.B \-t
+Specifies an alternate mount table file (default is
+.I /proc/mounts
+if it exists, else
+.IR /etc/mtab ).
+This is used when working with filesystems mounted without writing to
+.I /etc/mtab
+file - refer to
+.BR mount (8)
+for further details.
+This option has no effect with the
+.IR block-device " or " file-image
+parameters.
+.TP
+.B \-V
+Prints the version number and exits. The
+.I mount-point
+argument is not required with
+.BR \-V .
+.SH "EXAMPLES"
+
+Understanding xfs_info output.
+.PP
+Suppose one has the following "xfs_info /dev/sda" output:
+.PP
+.RS 2
+.Vb
+\&meta-data=/dev/pmem0             isize=512    agcount=8, agsize=5974144 blks
+\&         =                       sectsz=512   attr=2, projid32bit=1
+\&         =                       crc=1        finobt=1, sparse=1, rmapbt=1
+\&         =                       reflink=1
+\&data     =                       bsize=4096   blocks=47793152, imaxpct=25
+\&         =                       sunit=32     swidth=128 blks
+\&naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
+\&log      =internal log           bsize=4096   blocks=23336, version=2
+\&         =                       sectsz=512   sunit=0 blks, lazy-count=1
+\&realtime =none                   extsz=4096   blocks=0, rtextents=0
+.Ve
+.RE
+.PP
+
+Here, the data section of the output indicates "bsize=4096",
+meaning the data block size for this filesystem is 4096 bytes.
+This section also shows "sunit=32 swidth=128 blks", which means
+the stripe unit is 32*4096 bytes = 128 kibibytes and the stripe
+width is 128*4096 bytes = 512 kibibytes.
+A single stripe of this filesystem therefore consists
+of four stripe units (128 blocks / 32 blocks per unit).
+.SH SEE ALSO
+.BR mkfs.xfs (8),
+.BR md (4),
+.BR lvm (8),
+.BR mount (8).
diff --git a/spaceman/xfs_info.sh b/spaceman/xfs_info.sh
index 5df0a265..2e17fd91 100755
--- a/spaceman/xfs_info.sh
+++ b/spaceman/xfs_info.sh
@@ -4,7 +4,7 @@
 #
 
 OPTS=""
-USAGE="Usage: xfs_info [-V] [-t mtab] mountpoint"
+USAGE="Usage: xfs_info [-V] [-t mtab] [mountpoint|device|file]"
 
 while getopts "t:V" c
 do
@@ -22,8 +22,14 @@ done
 set -- extra "$@"
 shift $OPTIND
 case $# in
-	1)	xfs_spaceman -p xfs_info -c "info" $OPTS "$1"
-		status=$?
+	1)
+		if [ -b "$1" ] || [ -f "$1" ]; then
+			xfs_db -p xfs_info -c "info" $OPTS "$1"
+			status=$?
+		else
+			xfs_spaceman -p xfs_info -c "info" $OPTS "$1"
+			status=$?
+		fi
 		;;
 	*)	echo $USAGE 1>&2
 		exit 2

^ permalink raw reply related	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 4/9] xfs_db: add a superblock info command
  2018-05-23  3:30   ` [PATCH v2 " Darrick J. Wong
@ 2018-05-23  3:57     ` Allison Henderson
  0 siblings, 0 replies; 34+ messages in thread
From: Allison Henderson @ 2018-05-23  3:57 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

Alrighty, looks ok.

Reviewed by: Allison Henderson <allison.henderson@oracle.com>

On 05/22/2018 08:30 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Add an 'info' command to pretty-print the superblock geometry.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>   db/Makefile       |    2 +
>   db/command.c      |    1 +
>   db/command.h      |    1 +
>   db/info.c         |   74 +++++++++++++++++++++++++++++++++++++++++++++++++++++
>   man/man8/xfs_db.8 |    8 ++++++
>   5 files changed, 85 insertions(+), 1 deletion(-)
>   create mode 100644 db/info.c
> 
> diff --git a/db/Makefile b/db/Makefile
> index 6caa6348..c73d7f25 100644
> --- a/db/Makefile
> +++ b/db/Makefile
> @@ -14,7 +14,7 @@ HFILES = addr.h agf.h agfl.h agi.h attr.h attrshort.h bit.h block.h bmap.h \
>   	io.h logformat.h malloc.h metadump.h output.h print.h quit.h sb.h \
>   	sig.h strvec.h text.h type.h write.h attrset.h symlink.h fsmap.h \
>   	fuzz.h
> -CFILES = $(HFILES:.h=.c) btdump.c
> +CFILES = $(HFILES:.h=.c) btdump.c info.c
>   LSRCFILES = xfs_admin.sh xfs_ncheck.sh xfs_metadump.sh
>   
>   LLDLIBS	= $(LIBXFS) $(LIBXLOG) $(LIBFROG) $(LIBUUID) $(LIBRT) $(LIBPTHREAD)
> diff --git a/db/command.c b/db/command.c
> index 12ae5b78..087955e0 100644
> --- a/db/command.c
> +++ b/db/command.c
> @@ -136,6 +136,7 @@ init_commands(void)
>   	fsmap_init();
>   	help_init();
>   	hash_init();
> +	info_init();
>   	inode_init();
>   	input_init();
>   	logres_init();
> diff --git a/db/command.h b/db/command.h
> index 9b4ed2d7..84cd0b10 100644
> --- a/db/command.h
> +++ b/db/command.h
> @@ -41,3 +41,4 @@ extern const cmdinfo_t	*find_command(const char *cmd);
>   extern void		init_commands(void);
>   
>   extern void		btdump_init(void);
> +extern void		info_init(void);
> diff --git a/db/info.c b/db/info.c
> new file mode 100644
> index 00000000..05b3c1f0
> --- /dev/null
> +++ b/db/info.c
> @@ -0,0 +1,74 @@
> +/*
> + * Copyright (C) 2018 Oracle.  All Rights Reserved.
> + *
> + * Author: Darrick J. Wong <darrick.wong@oracle.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software Foundation,
> + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
> + */
> +#include "libxfs.h"
> +#include "command.h"
> +#include "init.h"
> +#include "output.h"
> +#include "fsgeom.h"
> +
> +static void
> +info_help(void)
> +{
> +	dbprintf(_(
> +"\n"
> +" Pretty-prints the filesystem geometry as derived from the superblock.\n"
> +" The output has the same format as mkfs.xfs, xfs_info, and other utilities.\n"
> +"\n"
> +));
> +
> +}
> +
> +static int
> +info_f(
> +	int			argc,
> +	char			**argv)
> +{
> +	struct xfs_fsop_geom	geo;
> +	int			error;
> +
> +	error = -libxfs_fs_geometry(&mp->m_sb, &geo,
> +			XFS_FS_GEOM_MAX_STRUCT_VER);
> +	if (error) {
> +		dbprintf(_("could not obtain geometry\n"));
> +		exitcode = 1;
> +		return 0;
> +	}
> +
> +	xfs_report_geom(&geo, fsdevice, x.logname, x.rtname);
> +	return 0;
> +}
> +
> +static const struct cmdinfo info_cmd = {
> +	.name =		"info",
> +	.altname =	"i",
> +	.cfunc =	info_f,
> +	.argmin =	0,
> +	.argmax =	0,
> +	.canpush =	0,
> +	.args =		NULL,
> +	.oneline =	N_("pretty-print superblock info"),
> +	.help =		info_help,
> +};
> +
> +void
> +info_init(void)
> +{
> +	add_command(&info_cmd);
> +}
> diff --git a/man/man8/xfs_db.8 b/man/man8/xfs_db.8
> index 524b1ef6..10f2beb9 100644
> --- a/man/man8/xfs_db.8
> +++ b/man/man8/xfs_db.8
> @@ -670,6 +670,14 @@ using the hash function of the XFS directory and attribute implementation.
>   .BI "help [" command ]
>   Print help for one or all commands.
>   .TP
> +.B info
> +Displays selected geometry information about the filesystem.
> +The output will have the same format that
> +.BR "mkfs.xfs" "(8)"
> +prints when creating a filesystem or
> +.BR "xfs_info" "(8)"
> +prints when querying a filesystem.
> +.TP
>   .BI "inode [" inode# ]
>   Set the current inode number. If no
>   .I inode#
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  https://urldefense.proofpoint.com/v2/url?u=http-3A__vger.kernel.org_majordomo-2Dinfo.html&d=DwIBAg&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=LHZQ8fHvy6wDKXGTWcm97burZH5sQKHRDMaY1UthQxc&m=C4CGnxIhMfo-ZhlFRisC8dnLAsedNv4JxrtRdRDlaZ4&s=-VqBB1V3hpBVGR47wcYi0laLhS-aFZIqDbn6xsx5IUM&e=
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 5/9] xfs_spaceman: print a nicer message when the file path isn't on an xfs
  2018-05-23  3:31   ` [PATCH v2 " Darrick J. Wong
@ 2018-05-23  3:58     ` Allison Henderson
  0 siblings, 0 replies; 34+ messages in thread
From: Allison Henderson @ 2018-05-23  3:58 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

Ok, looks good.  Thx!

Reviewed by: Allison Henderson <allison.henderson@oracle.com>

On 05/22/2018 08:31 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> If the file path passed in is not something on an xfs filesystem, print
> a nice message about that instead of yelling about ioctls.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>   spaceman/file.c |    7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/spaceman/file.c b/spaceman/file.c
> index 4c13b4a8..23f8be1c 100644
> --- a/spaceman/file.c
> +++ b/spaceman/file.c
> @@ -69,7 +69,12 @@ openfile(
>   	}
>   
>   	if (ioctl(fd, XFS_IOC_FSGEOMETRY, geom) < 0) {
> -		perror("XFS_IOC_FSGEOMETRY");
> +		if (errno == ENOTTY)
> +			fprintf(stderr,
> +_("%s: Not on a mounted XFS filesystem.\n"),
> +					path);
> +		else
> +			perror("XFS_IOC_FSGEOMETRY");
>   		close(fd);
>   		return -1;
>   	}
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  https://urldefense.proofpoint.com/v2/url?u=http-3A__vger.kernel.org_majordomo-2Dinfo.html&d=DwIBAg&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=LHZQ8fHvy6wDKXGTWcm97burZH5sQKHRDMaY1UthQxc&m=c2CCB3K_iIfSsLpTfhw0rxFL87ZYlPnPvGWzEfJ_t2E&s=KTX7FsHojy6HKAINeB5zGTNlqQlJ037Cw09OFK9tBhY&e=
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 6/9] xfs_spaceman: add a superblock info command
  2018-05-23  3:32   ` [PATCH v2 " Darrick J. Wong
@ 2018-05-23  4:08     ` Allison Henderson
  0 siblings, 0 replies; 34+ messages in thread
From: Allison Henderson @ 2018-05-23  4:08 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

OK, you can add my review:
Reviewed by: Allison Henderson <allison.henderson@oracle.com>

On 05/22/2018 08:32 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Add an 'info' command to pretty-print the superblock geometry.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>   man/man8/xfs_spaceman.8 |    7 +++
>   spaceman/Makefile       |    2 -
>   spaceman/info.c         |   96 +++++++++++++++++++++++++++++++++++++++++++++++
>   spaceman/init.c         |    1
>   spaceman/space.h        |    1
>   6 files changed, 111 insertions(+), 6 deletions(-)
>   create mode 100644 spaceman/info.c
> 
> diff --git a/man/man8/xfs_spaceman.8 b/man/man8/xfs_spaceman.8
> index e4a9137f..12dd04e4 100644
> --- a/man/man8/xfs_spaceman.8
> +++ b/man/man8/xfs_spaceman.8
> @@ -84,6 +84,13 @@ Display a summary of the free space information found.
>   .PD
>   .RE
>   .TP
> +.B info
> +Displays selected geometry information about the filesystem.
> +The opened file must be a mount point of a XFS filesystem.
> +The output will have the same format that
> +.BR "xfs_info" "(8)"
> +prints when querying a filesystem.
> +.TP
>   .BR "help [ " command " ]"
>   Display a brief description of one or all commands.
>   .TP
> diff --git a/spaceman/Makefile b/spaceman/Makefile
> index 8b310309..c1d903ba 100644
> --- a/spaceman/Makefile
> +++ b/spaceman/Makefile
> @@ -7,7 +7,7 @@ include $(TOPDIR)/include/builddefs
>   
>   LTCOMMAND = xfs_spaceman
>   HFILES = init.h space.h
> -CFILES = init.c file.c prealloc.c trim.c
> +CFILES = info.c init.c file.c prealloc.c trim.c
>   
>   LLDLIBS = $(LIBXCMD) $(LIBFROG)
>   LTDEPENDENCIES = $(LIBXCMD) $(LIBFROG)
> diff --git a/spaceman/info.c b/spaceman/info.c
> new file mode 100644
> index 00000000..8889346b
> --- /dev/null
> +++ b/spaceman/info.c
> @@ -0,0 +1,96 @@
> +/*
> + * Copyright (C) 2018 Oracle.  All Rights Reserved.
> + *
> + * Author: Darrick J. Wong <darrick.wong@oracle.com>
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License
> + * as published by the Free Software Foundation; either version 2
> + * of the License, or (at your option) any later version.
> + *
> + * This program is distributed in the hope that it would be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write the Free Software Foundation,
> + * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
> + */
> +#include "libxfs.h"
> +#include "command.h"
> +#include "init.h"
> +#include "path.h"
> +#include "space.h"
> +#include "fsgeom.h"
> +
> +static void
> +info_help(void)
> +{
> +	printf(_(
> +"\n"
> +" Pretty-prints the filesystem geometry as derived from the superblock.\n"
> +" The output has the same format as mkfs.xfs, xfs_info, and other utilities.\n"
> +" The opened file must be an XFS mount point.\n"
> +"\n"
> +));
> +
> +}
> +
> +static int
> +info_f(
> +	int			argc,
> +	char			**argv)
> +{
> +	struct xfs_fsop_geom	geo;
> +	int			error;
> +
> +	if (fs_table_lookup_mount(file->name) == NULL) {
> +		fprintf(stderr, _("%s: Not a XFS mount point.\n"), file->name);
> +		return 1;
> +	}
> +
> +	/* 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;
> +		}
> +	}
> +
> +	xfs_report_geom(&geo, file->fs_path.fs_name, file->fs_path.fs_log,
> +			file->fs_path.fs_rt);
> +	return 0;
> +}
> +
> +static const struct cmdinfo info_cmd = {
> +	.name =		"info",
> +	.altname =	"i",
> +	.cfunc =	info_f,
> +	.argmin =	0,
> +	.argmax =	0,
> +	.canpush =	0,
> +	.args =		NULL,
> +	.flags =	CMD_FLAG_ONESHOT,
> +	.oneline =	N_("pretty-print superblock geometry info"),
> +	.help =		info_help,
> +};
> +
> +void
> +info_init(void)
> +{
> +	add_command(&info_cmd);
> +}
> diff --git a/spaceman/init.c b/spaceman/init.c
> index b3efacef..895504f3 100644
> --- a/spaceman/init.c
> +++ b/spaceman/init.c
> @@ -40,6 +40,7 @@ init_commands(void)
>   {
>   	print_init();
>   	help_init();
> +	info_init();
>   	prealloc_init();
>   	quit_init();
>   	trim_init();
> diff --git a/spaceman/space.h b/spaceman/space.h
> index 5f4a8a0b..d2a25432 100644
> --- a/spaceman/space.h
> +++ b/spaceman/space.h
> @@ -42,5 +42,6 @@ extern void	freesp_init(void);
>   #else
>   # define freesp_init()	do { } while (0)
>   #endif
> +extern void	info_init(void);
>   
>   #endif /* XFS_SPACEMAN_SPACE_H_ */
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  https://urldefense.proofpoint.com/v2/url?u=http-3A__vger.kernel.org_majordomo-2Dinfo.html&d=DwIBAg&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=LHZQ8fHvy6wDKXGTWcm97burZH5sQKHRDMaY1UthQxc&m=lKIJYVcivj2fVCdM5vPO_yQc-0radDye1heAQzr95K0&s=1Qksl8JMsIe6vJnzGPFX_G2ewgIRy-CwoaWCBQSHH2o&e=
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

* Re: [PATCH v2 8/9] xfs_info: call xfs_db for offline filesystems
  2018-05-23  3:33   ` [PATCH v2 " Darrick J. Wong
@ 2018-05-23  4:36     ` Allison Henderson
  0 siblings, 0 replies; 34+ messages in thread
From: Allison Henderson @ 2018-05-23  4:36 UTC (permalink / raw)
  To: Darrick J. Wong, sandeen; +Cc: linux-xfs

Ok, you can add my review:
Reviewed by: Allison Henderson <allison.henderson@oracle.com>

On 05/22/2018 08:33 PM, Darrick J. Wong wrote:
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> If the online filesystem geometry query doesn't work, try using xfs_db
> to see if we can grab the information offline.
> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>   man/man8/xfs_growfs.8 |   47 +-----------------------
>   man/man8/xfs_info.8   |   97 +++++++++++++++++++++++++++++++++++++++++++++++++
>   spaceman/xfs_info.sh  |   12 +++++-
>   3 files changed, 108 insertions(+), 48 deletions(-)
>   create mode 100644 man/man8/xfs_info.8
> 
> diff --git a/man/man8/xfs_growfs.8 b/man/man8/xfs_growfs.8
> index e23d30e2..7e6a387c 100644
> --- a/man/man8/xfs_growfs.8
> +++ b/man/man8/xfs_growfs.8
> @@ -11,7 +11,7 @@
>   
>   .TH xfs_growfs 8
>   .SH NAME
> -xfs_growfs, xfs_info \- expand an XFS filesystem
> +xfs_growfs \- expand an XFS filesystem
>   .SH SYNOPSIS
>   .B xfs_growfs
>   [
> @@ -38,16 +38,6 @@ xfs_growfs, xfs_info \- expand an XFS filesystem
>   .I mount-point
>   .br
>   .B xfs_growfs \-V
> -.PP
> -.br
> -.B xfs_info
> -[
> -.B \-t
> -.I mtab
> -]
> -.I mount-point
> -.br
> -.B xfs_info \-V
>   .SH DESCRIPTION
>   .B xfs_growfs
>   expands an existing XFS filesystem (see
> @@ -59,13 +49,6 @@ is mounted. The filesystem must be mounted to be grown (see
>   .BR mount (8)).
>   The existing contents of the filesystem are undisturbed, and the added space
>   becomes available for additional file storage.
> -.PP
> -.B xfs_info
> -is equivalent to invoking
> -.B xfs_growfs
> -with the
> -.B \-n
> -option (see discussion below).
>   .SH OPTIONS
>   .TP
>   .BI "\-d | \-D " size
> @@ -169,35 +152,9 @@ reside. In order to grow a filesystem, it is necessary to provide added
>   space for it to occupy. Therefore there must be at least one spare new
>   disk partition available. Adding the space is often done through the use
>   of a logical volume manager.
> -.SH "EXAMPLES"
> -
> -Understanding xfs_info output.
> -.PP
> -Suppose one has the following "xfs_info /dev/sda" output:
> -.PP
> -.RS 2
> -.Vb
> -\&meta-data=/dev/sda      isize=256    agcount=32, agsize=16777184 blks
> -\&         =              sectsz=512   attr=2
> -\&data     =              bsize=4096   blocks=536869888, imaxpct=5
> -\&         =              sunit=32     swidth=128 blks
> -\&naming   =version 2     bsize=4096
> -\&log      =internal      bsize=4096   blocks=32768, version=2
> -\&         =              sectsz=512   sunit=32 blks, lazy-count=1
> -\&realtime =none          extsz=524288 blocks=0, rtextents=0
> -.Ve
> -.RE
> -.PP
> -
> -Here, the data section of the output indicates "bsize=4096",
> -meaning the data block size for this filesystem is 4096 bytes.
> -This section also shows "sunit=32 swidth=128 blks", which means
> -the stripe unit is 32*4096 bytes = 128 kibibytes and the stripe
> -width is 128*4096 bytes = 512 kibibytes.
> -A single stripe of this filesystem therefore consists
> -of four stripe units (128 blocks / 32 blocks per unit).
>   .SH SEE ALSO
>   .BR mkfs.xfs (8),
> +.BR xfs_info (8),
>   .BR md (4),
>   .BR lvm (8),
>   .BR mount (8).
> diff --git a/man/man8/xfs_info.8 b/man/man8/xfs_info.8
> new file mode 100644
> index 00000000..429356a8
> --- /dev/null
> +++ b/man/man8/xfs_info.8
> @@ -0,0 +1,97 @@
> +.\" Verbatim blocks taken from openssl req manpage content
> +.de Vb \" Begin verbatim text
> +.ft CW
> +.nf
> +.ne \\$1
> +..
> +.de Ve \" End verbatim text
> +.ft R
> +.fi
> +..
> +
> +.TH xfs_info 8
> +.SH NAME
> +xfs_info \- display XFS filesystem geometry information
> +.SH SYNOPSIS
> +.B xfs_info
> +[
> +.B \-t
> +.I mtab
> +]
> +[
> +.I mount-point
> +|
> +.I block-device
> +|
> +.I file-image
> +]
> +.br
> +.B xfs_info \-V
> +.SH DESCRIPTION
> +.B xfs_info
> +displays geometry information about an existing XFS filesystem.
> +The
> +.I mount-point
> +argument is the pathname of a directory where the filesystem
> +is mounted.
> +The
> +.I block-device
> +or
> +.I file-image
> +contain a raw XFS filesystem.
> +The existing contents of the filesystem are undisturbed.
> +.SH OPTIONS
> +.TP
> +.B \-t
> +Specifies an alternate mount table file (default is
> +.I /proc/mounts
> +if it exists, else
> +.IR /etc/mtab ).
> +This is used when working with filesystems mounted without writing to
> +.I /etc/mtab
> +file - refer to
> +.BR mount (8)
> +for further details.
> +This option has no effect with the
> +.IR block-device " or " file-image
> +parameters.
> +.TP
> +.B \-V
> +Prints the version number and exits. The
> +.I mount-point
> +argument is not required with
> +.BR \-V .
> +.SH "EXAMPLES"
> +
> +Understanding xfs_info output.
> +.PP
> +Suppose one has the following "xfs_info /dev/sda" output:
> +.PP
> +.RS 2
> +.Vb
> +\&meta-data=/dev/pmem0             isize=512    agcount=8, agsize=5974144 blks
> +\&         =                       sectsz=512   attr=2, projid32bit=1
> +\&         =                       crc=1        finobt=1, sparse=1, rmapbt=1
> +\&         =                       reflink=1
> +\&data     =                       bsize=4096   blocks=47793152, imaxpct=25
> +\&         =                       sunit=32     swidth=128 blks
> +\&naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
> +\&log      =internal log           bsize=4096   blocks=23336, version=2
> +\&         =                       sectsz=512   sunit=0 blks, lazy-count=1
> +\&realtime =none                   extsz=4096   blocks=0, rtextents=0
> +.Ve
> +.RE
> +.PP
> +
> +Here, the data section of the output indicates "bsize=4096",
> +meaning the data block size for this filesystem is 4096 bytes.
> +This section also shows "sunit=32 swidth=128 blks", which means
> +the stripe unit is 32*4096 bytes = 128 kibibytes and the stripe
> +width is 128*4096 bytes = 512 kibibytes.
> +A single stripe of this filesystem therefore consists
> +of four stripe units (128 blocks / 32 blocks per unit).
> +.SH SEE ALSO
> +.BR mkfs.xfs (8),
> +.BR md (4),
> +.BR lvm (8),
> +.BR mount (8).
> diff --git a/spaceman/xfs_info.sh b/spaceman/xfs_info.sh
> index 5df0a265..2e17fd91 100755
> --- a/spaceman/xfs_info.sh
> +++ b/spaceman/xfs_info.sh
> @@ -4,7 +4,7 @@
>   #
>   
>   OPTS=""
> -USAGE="Usage: xfs_info [-V] [-t mtab] mountpoint"
> +USAGE="Usage: xfs_info [-V] [-t mtab] [mountpoint|device|file]"
>   
>   while getopts "t:V" c
>   do
> @@ -22,8 +22,14 @@ done
>   set -- extra "$@"
>   shift $OPTIND
>   case $# in
> -	1)	xfs_spaceman -p xfs_info -c "info" $OPTS "$1"
> -		status=$?
> +	1)
> +		if [ -b "$1" ] || [ -f "$1" ]; then
> +			xfs_db -p xfs_info -c "info" $OPTS "$1"
> +			status=$?
> +		else
> +			xfs_spaceman -p xfs_info -c "info" $OPTS "$1"
> +			status=$?
> +		fi
>   		;;
>   	*)	echo $USAGE 1>&2
>   		exit 2
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  https://urldefense.proofpoint.com/v2/url?u=http-3A__vger.kernel.org_majordomo-2Dinfo.html&d=DwIBAg&c=RoP1YumCXCgaWHvlZYR8PZh8Bv7qIrMUB65eapI_JnE&r=LHZQ8fHvy6wDKXGTWcm97burZH5sQKHRDMaY1UthQxc&m=uRT-Nkq5vtStwvh7rxxmiMIK1XkFKJjNdYWIowr_5RE&s=KrEravyvnIfkZJLlnByf7D3rwq_HRTTeL8E4BGwiaoc&e=
> 

^ permalink raw reply	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2018-05-23  4:36 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-18  2:45 [PATCH 0/9] xfsprogs-4.17: geometry refactoring Darrick J. Wong
2018-04-18  2:45 ` [PATCH 1/9] libfrog: move platform specific runtime support code out of libxfs Darrick J. Wong
2018-05-03 18:23   ` Eric Sandeen
2018-04-18  2:45 ` [PATCH 2/9] libfrog: refactor fs geometry printing function Darrick J. Wong
2018-05-03 18:47   ` Eric Sandeen
2018-05-03 21:27   ` Eric Sandeen
2018-05-03 21:35     ` Darrick J. Wong
2018-04-18  2:45 ` [PATCH 3/9] mkfs: use geometry generation / helper functions Darrick J. Wong
2018-05-03 18:52   ` Eric Sandeen
2018-04-18  2:45 ` [PATCH 4/9] xfs_db: add a superblock info command Darrick J. Wong
2018-05-03 20:53   ` Eric Sandeen
2018-05-03 21:44     ` Darrick J. Wong
2018-05-23  3:30   ` [PATCH v2 " Darrick J. Wong
2018-05-23  3:57     ` Allison Henderson
2018-04-18  2:46 ` [PATCH 5/9] xfs_spaceman: print a nicer message when the file path isn't on an xfs Darrick J. Wong
2018-05-03 20:57   ` Eric Sandeen
2018-05-23  3:31   ` [PATCH v2 " Darrick J. Wong
2018-05-23  3:58     ` Allison Henderson
2018-04-18  2:46 ` [PATCH 6/9] xfs_spaceman: add a superblock info command Darrick J. Wong
2018-05-03 21:09   ` Eric Sandeen
2018-05-03 21:39     ` Darrick J. Wong
2018-05-08 15:24       ` Darrick J. Wong
2018-05-23  3:32   ` [PATCH v2 " Darrick J. Wong
2018-05-23  4:08     ` Allison Henderson
2018-04-18  2:46 ` [PATCH 7/9] xfs_info: move to xfs_spaceman Darrick J. Wong
2018-05-03 21:17   ` Eric Sandeen
2018-05-03 21:48     ` Darrick J. Wong
2018-04-18  2:46 ` [PATCH 8/9] xfs_info: call xfs_db for offline filesystems Darrick J. Wong
2018-05-03 21:22   ` Eric Sandeen
2018-05-03 21:55     ` Darrick J. Wong
2018-05-23  3:33   ` [PATCH v2 " Darrick J. Wong
2018-05-23  4:36     ` Allison Henderson
2018-04-18  2:46 ` [PATCH 9/9] xfs_growfs: refactor geometry reporting Darrick J. Wong
2018-05-03 21:25   ` Eric Sandeen

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.