All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/14 v5]  xfsprogs: Partial OSX support
@ 2015-09-15  9:59 Jan Tulak
  2015-09-15  9:59 ` [PATCH 01/14] xfsprogs: Add a way to compile without blkid Jan Tulak
                   ` (13 more replies)
  0 siblings, 14 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

Hi all,

An updated version. This set is intended to put together the current
versions of the individual patches with the exception of a new patch 14,
and rebase it against the current master branch.

Patch 4 contains renaming required by Dave, however I'm not sure
if it is still needed with the changes in patches 2 and 3.

Patch 10 (adding timer) was mentioned that it "doesn't look to work",
but I didn't get a reasoning. The added code, when tested,
really run. For testing it in xfs_repair, I don't have how to
create a large enough FS where the timer would be noticable on OSX.
(Not enough of empty space.)

Cheers,
Jan

CHANGELOG:
v5:
- patch 2 was split into 3 patches, numbered 2, 3 and 4
- in patches 2-4, instead of just prefixing it all, a mixed
  approach was used.
- patch 9 renames the function directly instead of using #define
- patch 11 now adds a simple rename
- patch 12 uses mntinfo instead of dummy code
- in patch 13, make mremap build optional instead of dummy code
- new patch 14 with lstat64


v4:
- added #warning message (patch 1)
- use dummy blkid_get_topology instead of #ifdefs (patch 1)
- fix autoconf (wasn't passing -DENABLE_BLKID flag, lost during
  patch cleaning.) (patch 1)
- remove dependency on linux XATTR_ constants (patch 2)
- add autoconf detection for fsetxattr (patch 4)
- use uuid_t instead of unsigned char (patch 5)
- add a basic timer functionality (patch 8)
- mremap replacement now returns MAP_FAILED (patch 11)



Version 3:
- better commit messages (patch 1)
- formatting fixes (patch 2, 8)
- autoconf updates (patch 6, 7)
- changed default behaviour if BLKID is disabled such that mkfs -f
  is required (patch 11)

Jan Tulak (14):
  xfsprogs: Add a way to compile without blkid
  xfsprogs: Add XATTR_LIST_MAX to OS X headers
  xfsprogs: avoid dependency on Linux XATTR_SIZE_MAX
  xfsprogs: prefix XATTR_LIST_MAX with XFS_
  xfsprogs: Add includes required for OS X builds (delta)
  xfsprogs: Add autoconf check for fsetxattr call
  xfsprogs: uuid changes for OS X
  xfsprogs: Remove conflicting define for OS X
  xfsprogs: change nftw64 to nftw
  xfsprogs: Add a timer implementation for OS X
  xfsprogs: Add statvfs64 for osx
  xfsprogs: make fsr use mntinfo when there is no mntent
  xfsprogs: Make mremap conditional
  xfsprogs: rename lstat64 to lstat for OS X

 configure.ac             |  12 +++++-
 estimate/xfs_estimate.c  |   6 +--
 fsr/Makefile             |   8 ++++
 fsr/xfs_fsr.c            |  85 ++++++++++++++++++++++++++++++++-----
 include/builddefs.in     |  12 +++++-
 include/darwin.h         | 106 ++++++++++++++++++++++++++++++++++++++++-------
 include/xfs.h            |   2 +
 io/mmap.c                |   8 ++++
 libhandle/handle.c       |   4 +-
 libhandle/jdm.c          |   4 +-
 libxfs/xfs_attr_remote.c |   2 +-
 libxfs/xfs_format.h      |  10 ++++-
 m4/package_libcdev.m4    |  26 ++++++++++++
 mkfs/xfs_mkfs.c          |  37 ++++++++++++++++-
 repair/progress.c        |  16 ++++++-
 15 files changed, 298 insertions(+), 40 deletions(-)

-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 01/14] xfsprogs: Add a way to compile without blkid
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-15  9:59 ` [PATCH 02/14] xfsprogs: Add XATTR_LIST_MAX to OS X headers Jan Tulak
                   ` (12 subsequent siblings)
  13 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

Because not all platforms have up-to-date blkid with required
functions, allow at least partial functionality by adding
--enable-blkid=yes/no optional configure argument.

When blkid is disabled, signature detection and device geometry
detection doesn't work.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 configure.ac         | 10 +++++++++-
 include/builddefs.in |  5 +++++
 mkfs/xfs_mkfs.c      | 37 ++++++++++++++++++++++++++++++++++++-
 3 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 16f3f68..aa241cd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,6 +26,11 @@ AC_ARG_ENABLE(gettext,
 	enable_gettext=yes)
 AC_SUBST(enable_gettext)
 
+AC_ARG_ENABLE(blkid,
+[ --enable-blkid=[yes/no] Enable use of block device id library [default=yes]],,
+	enable_blkid=yes)
+AC_SUBST(enable_blkid)
+
 AC_ARG_ENABLE(readline,
 [ --enable-readline=[yes/no] Enable readline command editing [default=no]],
 	test $enable_readline = yes && libreadline="-lreadline",
@@ -117,9 +122,12 @@ AC_HAVE_PREADV
 AC_HAVE_SYNC_FILE_RANGE
 AC_HAVE_MNTENT
 AC_HAVE_FLS
-AC_HAVE_BLKID_TOPO
 AC_HAVE_READDIR
 
+if test "$enable_blkid" = yes; then
+AC_HAVE_BLKID_TOPO
+fi
+
 AC_CHECK_SIZEOF([long])
 AC_CHECK_SIZEOF([char *])
 AC_TYPE_UMODE_T
diff --git a/include/builddefs.in b/include/builddefs.in
index 8851956..6c16a65 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -89,6 +89,7 @@ ENABLE_SHARED	= @enable_shared@
 ENABLE_GETTEXT	= @enable_gettext@
 ENABLE_EDITLINE	= @enable_editline@
 ENABLE_READLINE	= @enable_readline@
+ENABLE_BLKID	= @enable_blkid@
 
 HAVE_ZIPPED_MANPAGES = @have_zipped_manpages@
 
@@ -138,6 +139,10 @@ endif
 ifeq ($(HAVE_MNTENT),yes)
 PCFLAGS+= -DHAVE_MNTENT
 endif
+ifeq ($(ENABLE_BLKID),yes)
+PCFLAGS+= -DENABLE_BLKID
+endif
+
 
 GCFLAGS = $(OPTIMIZER) $(DEBUG) \
 	  -DVERSION=\"$(PKG_VERSION)\" -DLOCALEDIR=\"$(PKG_LOCALE_DIR)\"  \
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index d993fc0..5964eaf 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -18,7 +18,9 @@
 
 #include "libxfs.h"
 #include <ctype.h>
-#include <blkid/blkid.h>
+#ifdef ENABLE_BLKID
+#  include <blkid/blkid.h>
+#endif /* ENABLE_BLKID */
 #include "xfs_mkfs.h"
 
 /*
@@ -298,6 +300,7 @@ calc_stripe_factors(
  *	 0 for nothing found
  *	-1 for internal error
  */
+#ifdef ENABLE_BLKID
 static int
 check_overwrite(
 	char		*device)
@@ -451,6 +454,38 @@ out_free_probe:
 		_("warning: unable to probe device topology for device %s\n"),
 		device);
 }
+#else /* ifdef ENABLE_BLKID */
+/*
+ * Without blkid, we can't do a good check for signatures.
+ * So instead of some messy attempts, just disable any checks
+ * and always return 'nothing found'.
+ */
+#  warning BLKID is disabled, so signature detection and block device\
+ access are not working!
+static int
+check_overwrite(
+	char		*device)
+{
+	return 1;
+}
+
+static void blkid_get_topology(
+	const char	*device,
+	int		*sunit,
+	int		*swidth,
+	int		*lsectorsize,
+	int		*psectorsize,
+	int		force_overwrite)
+{
+	/*
+	 * Shouldn't make any difference (no blkid = no block device access),
+	 * but make sure this dummy replacement returns with at least some
+	 * sanity.
+	 */
+	*lsectorsize = *psectorsize = 512;
+}
+
+#endif /* ENABLE_BLKID */
 
 static void get_topology(
 	libxfs_init_t		*xi,
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 02/14] xfsprogs: Add XATTR_LIST_MAX to OS X headers
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
  2015-09-15  9:59 ` [PATCH 01/14] xfsprogs: Add a way to compile without blkid Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-15  9:59 ` [PATCH 03/14] xfsprogs: avoid dependency on Linux XATTR_SIZE_MAX Jan Tulak
                   ` (11 subsequent siblings)
  13 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

OS X has no XATTR_LIST_MAX value. So add it to the platform header.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 include/darwin.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/darwin.h b/include/darwin.h
index b904898..4b7ba3a 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -39,6 +39,11 @@
 # ifndef SYS_fsctl
 #  define SYS_fsctl	242
 # endif
+
+#ifndef XATTR_LIST_MAX
+#define XATTR_LIST_MAX  65536
+#endif
+
 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
 {
 	return syscall(SYS_fsctl, path, cmd, p, 0);
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 03/14] xfsprogs: avoid dependency on Linux XATTR_SIZE_MAX
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
  2015-09-15  9:59 ` [PATCH 01/14] xfsprogs: Add a way to compile without blkid Jan Tulak
  2015-09-15  9:59 ` [PATCH 02/14] xfsprogs: Add XATTR_LIST_MAX to OS X headers Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-23  3:09   ` Dave Chinner
  2015-09-15  9:59 ` [PATCH 04/14] xfsprogs: prefix XATTR_LIST_MAX with XFS_ Jan Tulak
                   ` (10 subsequent siblings)
  13 siblings, 1 reply; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

Currently, we depends on Linux XATTR value for on disk
definitions. Which causes trouble on other platforms and
maybe also if this value was to change.

Fix it by creating a custom definition independent from
those in Linux (although with the same values), so it is OK
with the be16 fields used for holding these attributes.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 libxfs/xfs_attr_remote.c |  2 +-
 libxfs/xfs_format.h      | 10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/libxfs/xfs_attr_remote.c b/libxfs/xfs_attr_remote.c
index 3b3c24b..39ab350 100644
--- a/libxfs/xfs_attr_remote.c
+++ b/libxfs/xfs_attr_remote.c
@@ -102,7 +102,7 @@ xfs_attr3_rmt_verify(
 	if (be32_to_cpu(rmt->rm_bytes) > fsbsize - sizeof(*rmt))
 		return false;
 	if (be32_to_cpu(rmt->rm_offset) +
-				be32_to_cpu(rmt->rm_bytes) > XATTR_SIZE_MAX)
+				be32_to_cpu(rmt->rm_bytes) > XFS_XATTR_SIZE_MAX)
 		return false;
 	if (rmt->rm_owner == 0)
 		return false;
diff --git a/libxfs/xfs_format.h b/libxfs/xfs_format.h
index 3c98635..946bcd1 100644
--- a/libxfs/xfs_format.h
+++ b/libxfs/xfs_format.h
@@ -60,6 +60,14 @@ struct xfs_ifork;
 #define	XFS_SB_VERSION_MOREBITSBIT	0x8000
 
 /*
+ * The size of a single extended attribute on disk is limited by
+ * the size of index values within the attribute entries themselves.
+ * These are be16 fields, so we can only support attribute data
+ * sizes up to 2^16 bytes in length.
+ */
+#define XFS_XATTR_SIZE_MAX (1 << 16)
+
+/*
  * Supported feature bit list is just all bits in the versionnum field because
  * we've used them all up and understand them all. Except, of course, for the
  * shared superblock bit, which nobody knows what it does and so is unsupported.
@@ -1483,7 +1491,7 @@ struct xfs_acl {
  */
 #define XFS_ACL_MAX_ENTRIES(mp)	\
 	(xfs_sb_version_hascrc(&mp->m_sb) \
-		?  (XATTR_SIZE_MAX - sizeof(struct xfs_acl)) / \
+		?  (XFS_XATTR_SIZE_MAX - sizeof(struct xfs_acl)) / \
 						sizeof(struct xfs_acl_entry) \
 		: 25)
 
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 04/14] xfsprogs: prefix XATTR_LIST_MAX with XFS_
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (2 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 03/14] xfsprogs: avoid dependency on Linux XATTR_SIZE_MAX Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-23  3:15   ` Dave Chinner
  2015-10-07 11:17   ` [PATCH 04/14 v2] " Jan Tulak
  2015-09-15  9:59 ` [PATCH 05/14] xfsprogs: Add includes required for OS X builds (delta) Jan Tulak
                   ` (9 subsequent siblings)
  13 siblings, 2 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

WILL CHANGE THE COMMIT MESSAGE.

All right, I make the renaming with define - though I'm not sure
that with the ifdef for OS X and SIZE_MAX moved to a standalone patch
we need it - shouldn't be this change rather dropped?

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 include/xfs.h      | 2 ++
 libhandle/handle.c | 4 ++--
 libhandle/jdm.c    | 4 ++--
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/include/xfs.h b/include/xfs.h
index bc94068..8ee0106 100644
--- a/include/xfs.h
+++ b/include/xfs.h
@@ -53,6 +53,8 @@
 # define ASSERT(EX)	((void) 0)
 #endif
 
+#define XFS_XATTR_LIST_MAX XATTR_LIST_MAX
+
 /*
  * sparse kernel source annotations
  */
diff --git a/libhandle/handle.c b/libhandle/handle.c
index b1c0c10..7207186 100644
--- a/libhandle/handle.c
+++ b/libhandle/handle.c
@@ -397,8 +397,8 @@ attr_list_by_handle(
 	alhreq.buffer = buf;
 	alhreq.buflen = bufsize;
 	/* prevent needless EINVAL from the kernel */
-	if (alhreq.buflen > XATTR_LIST_MAX)
-		alhreq.buflen = XATTR_LIST_MAX;
+	if (alhreq.buflen > XFS_XATTR_LIST_MAX)
+		alhreq.buflen = XFS_XATTR_LIST_MAX;
 
 	error = xfsctl(path, fd, XFS_IOC_ATTRLIST_BY_HANDLE, &alhreq);
 
diff --git a/libhandle/jdm.c b/libhandle/jdm.c
index d804423..e52f5d8 100644
--- a/libhandle/jdm.c
+++ b/libhandle/jdm.c
@@ -168,8 +168,8 @@ jdm_attr_list(	jdm_fshandle_t *fshp,
 	int rval;
 
 	/* prevent needless EINVAL from the kernel */
-	if (bufsz > XATTR_LIST_MAX)
-		bufsz = XATTR_LIST_MAX;
+	if (bufsz > XFS_XATTR_LIST_MAX)
+		bufsz = XFS_XATTR_LIST_MAX;
 
 	jdm_fill_filehandle( &filehandle, fshandlep, statp );
 	rval = attr_list_by_handle (( void * )&filehandle,
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 05/14] xfsprogs: Add includes required for OS X builds (delta)
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (3 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 04/14] xfsprogs: prefix XATTR_LIST_MAX with XFS_ Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-15  9:59 ` [PATCH 06/14] xfsprogs: Add autoconf check for fsetxattr call Jan Tulak
                   ` (8 subsequent siblings)
  13 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

Delta patch, an older version missing 3 includes was merged
into 4.2.0-rc2.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 include/darwin.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/darwin.h b/include/darwin.h
index 4b7ba3a..fe489a6 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -18,6 +18,9 @@
 #ifndef __XFS_DARWIN_H__
 #define __XFS_DARWIN_H__
 
+#include <unistd.h>
+#include <sys/types.h>
+#include <string.h>
 #include <uuid/uuid.h>
 #include <libgen.h>
 #include <sys/vm.h>
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 06/14] xfsprogs: Add autoconf check for fsetxattr call
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (4 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 05/14] xfsprogs: Add includes required for OS X builds (delta) Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-15  9:59 ` [PATCH 07/14] xfsprogs: uuid changes for OS X Jan Tulak
                   ` (7 subsequent siblings)
  13 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

OS X has fsetxattr() in another header and with different arguments.
For now, check for the Linux variant and if not available, skip
the code using the call.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 configure.ac          |  1 +
 fsr/xfs_fsr.c         |  2 ++
 include/builddefs.in  |  4 ++++
 m4/package_libcdev.m4 | 13 +++++++++++++
 4 files changed, 20 insertions(+)

diff --git a/configure.ac b/configure.ac
index aa241cd..5d8486e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -123,6 +123,7 @@ AC_HAVE_SYNC_FILE_RANGE
 AC_HAVE_MNTENT
 AC_HAVE_FLS
 AC_HAVE_READDIR
+AC_HAVE_FSETXATTR
 
 if test "$enable_blkid" = yes; then
 AC_HAVE_BLKID_TOPO
diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index b673761..e1b7bd6 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -1025,6 +1025,7 @@ fsr_setup_attr_fork(
 	int		tfd,
 	xfs_bstat_t	*bstatp)
 {
+#ifdef HAVE_FSETXATTR
 	struct stat64	tstatbuf;
 	int		i;
 	int		diff = 0;
@@ -1199,6 +1200,7 @@ out:
 	if (dflag && diff)
 		fsrprintf(_("failed to match fork offset\n"));;
 
+#endif /* HAVE_FSETXATTR */
 	return 0;
 }
 
diff --git a/include/builddefs.in b/include/builddefs.in
index 6c16a65..25b8816 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -106,6 +106,7 @@ HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
 HAVE_READDIR = @have_readdir@
 HAVE_MNTENT = @have_mntent@
 HAVE_FLS = @have_fls@
+HAVE_FSETXATTR = @have_fsetxattr@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
 #	   -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
@@ -139,6 +140,9 @@ endif
 ifeq ($(HAVE_MNTENT),yes)
 PCFLAGS+= -DHAVE_MNTENT
 endif
+ifeq ($(HAVE_FSETXATTR),yes)
+PCFLAGS+= -DHAVE_FSETXATTR
+endif
 ifeq ($(ENABLE_BLKID),yes)
 PCFLAGS+= -DENABLE_BLKID
 endif
diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4
index 4a96374..5e900ab 100644
--- a/m4/package_libcdev.m4
+++ b/m4/package_libcdev.m4
@@ -215,6 +215,19 @@ AC_DEFUN([AC_HAVE_FLS],
   ])
 
 #
+# Check if we have a fsetxattr call (Mac OS X)
+#
+AC_DEFUN([AC_HAVE_FSETXATTR],
+  [ AC_CHECK_DECL([fsetxattr],
+       have_fsetxattr=yes,
+       [],
+       [#include <sys/types.h>
+        #include <attr/xattr.h>]
+       )
+    AC_SUBST(have_fsetxattr)
+  ])
+
+#
 # Check if there is mntent.h
 #
 AC_DEFUN([AC_HAVE_MNTENT],
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 07/14] xfsprogs: uuid changes for OS X
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (5 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 06/14] xfsprogs: Add autoconf check for fsetxattr call Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-15  9:59 ` [PATCH 08/14] xfsprogs: Remove conflicting define " Jan Tulak
                   ` (6 subsequent siblings)
  13 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

UUID API changed in OS X in last few years, so fix the platform_ calls.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 include/darwin.h | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/include/darwin.h b/include/darwin.h
index fe489a6..78f7df3 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -81,45 +81,37 @@ static __inline__ void platform_getoptreset(void)
 
 static __inline__ int platform_uuid_compare(uuid_t *uu1, uuid_t *uu2)
 {
-	return uuid_compare(uu1, uu2, NULL);
+	return uuid_compare(*uu1, *uu2);
 }
 
 static __inline__ void platform_uuid_unparse(uuid_t *uu, char *buffer)
 {
-	uint32_t status;
-	char *s;
-	uuid_to_string(uu, &s, &status);
-	if (status == uuid_s_ok)
-		strcpy(buffer, s);
-	else buffer[0] = '\0';
-	free(s);
+	uuid_unparse(*uu, buffer);
 }
 
 static __inline__ int platform_uuid_parse(char *buffer, uuid_t *uu)
 {
-	uint32_t status;
-	uuid_from_string(buffer, uu, &status);
-	return (status == uuid_s_ok);
+	return uuid_parse(buffer, *uu);
 }
 
 static __inline__ int platform_uuid_is_null(uuid_t *uu)
 {
-	return uuid_is_nil(uu, NULL);
+	return uuid_is_null(*uu);
 }
 
 static __inline__ void platform_uuid_generate(uuid_t *uu)
 {
-	uuid_create(uu, NULL);
+	uuid_generate(*uu);
 }
 
 static __inline__ void platform_uuid_clear(uuid_t *uu)
 {
-	uuid_create_nil(uu, NULL);
+	uuid_clear(*uu);
 }
 
 static __inline__ void platform_uuid_copy(uuid_t *dst, uuid_t *src)
 {
-	memcpy(dst, src, sizeof(uuid_t));
+	uuid_copy(*dst, *src);
 }
 
 typedef unsigned char		__u8;
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 08/14] xfsprogs: Remove conflicting define for OS X
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (6 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 07/14] xfsprogs: uuid changes for OS X Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-15  9:59 ` [PATCH 09/14] xfsprogs: change nftw64 to nftw Jan Tulak
                   ` (5 subsequent siblings)
  13 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

ENOATTR already exists in OS X.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 include/darwin.h | 1 -
 1 file changed, 1 deletion(-)

diff --git a/include/darwin.h b/include/darwin.h
index 78f7df3..1409c91 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -156,7 +156,6 @@ typedef int64_t		xfs_daddr_t;
 #define O_SYNC          0
 #endif
 
-#define ENOATTR		989     /* Attribute not found */
 #define EFSCORRUPTED	990	/* Filesystem is corrupted */
 #define EFSBADCRC	991	/* Bad CRC detected */
 #define constpp		char * const *
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 09/14] xfsprogs: change nftw64 to nftw
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (7 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 08/14] xfsprogs: Remove conflicting define " Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-15  9:59 ` [PATCH 10/14] xfsprogs: Add a timer implementation for OS X Jan Tulak
                   ` (4 subsequent siblings)
  13 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

There is only one usage of nftw64 in entire xfsprogs, but
multiple usages of nftw. It seems the 64 variant has no reason,
and causes difficulties with some other platforms which has
only nftw call.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 estimate/xfs_estimate.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/estimate/xfs_estimate.c b/estimate/xfs_estimate.c
index 65b7168..323137c 100644
--- a/estimate/xfs_estimate.c
+++ b/estimate/xfs_estimate.c
@@ -45,7 +45,7 @@ cvtnum(char *s)
 	return 0LL;
 }
 
-int ffn(const char *, const struct stat64 *, int, struct FTW *);
+int ffn(const char *, const struct stat *, int, struct FTW *);
 
 #define BLOCKSIZE	4096
 #define INODESIZE	256
@@ -168,7 +168,7 @@ main(int argc, char **argv)
 		ndirs=0LL;		/* number of directories */
 		nspecial=0LL;		/* number of special files */
 
-		nftw64(argv[optind], ffn, 40, FTW_PHYS | FTW_MOUNT);
+		nftw(argv[optind], ffn, 40, FTW_PHYS | FTW_MOUNT);
 
 		if (__debug) {
 			printf(_("dirsize=%llu\n"), dirsize);
@@ -214,7 +214,7 @@ main(int argc, char **argv)
 }
 
 int
-ffn(const char *path, const struct stat64 *stb, int flags, struct FTW *f)
+ffn(const char *path, const struct stat *stb, int flags, struct FTW *f)
 {
 	/* cases are in most-encountered to least-encountered order */
 	dirsize+=PERDIRENTRY+strlen(path);
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 10/14] xfsprogs: Add a timer implementation for OS X
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (8 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 09/14] xfsprogs: change nftw64 to nftw Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-23  3:25   ` Dave Chinner
  2015-09-30  8:23   ` [PATCH 10/14 v2] " Jan Tulak
  2015-09-15  9:59 ` [PATCH 11/14] xfsprogs: Add statvfs64 for osx Jan Tulak
                   ` (3 subsequent siblings)
  13 siblings, 2 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

OS X does not have the timer used in xfs_repair.
Add a simple implementation providing the required
capabilities.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 include/darwin.h  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 repair/progress.c | 16 ++++++++++++++--
 2 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/include/darwin.h b/include/darwin.h
index 1409c91..0d2f175 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -28,6 +28,7 @@
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 #include <sys/types.h>
+#include <sys/time.h>
 #include <ftw.h>
 #include <mach/mach_time.h>
 #include <inttypes.h>
@@ -168,4 +169,51 @@ platform_discard_blocks(int fd, uint64_t start, uint64_t len)
 	return 0;
 }
 
+/*
+ * POSIX timer replacement.
+ * It really just do the minimum we need for xfs_repair.
+ * Also, as setitimer can't create multiple timers,
+ * the timerid things are useless - we have only one ITIMER_REAL
+ * timer.
+ */
+#define CLOCK_REALTIME ITIMER_REAL
+#define itimerspec itimerval
+typedef uint64_t timer_t;
+typedef double   timer_c;
+typedef clock_id_t clockid_t;
+
+
+static inline int timer_create (clockid_t __clock_id,
+                         struct sigevent *__restrict __evp,
+                         timer_t *__restrict timer)
+{
+	// set something, to initialize the variable, just in case
+	*timer = 0;
+	return 0;
+}
+
+static inline int timer_settime (timer_t timerid, int flags,
+                          const struct itimerspec *__restrict timerspec,
+                          struct itimerspec *__restrict ovalue)
+{
+	return setitimer(ITIMER_REAL, timerspec, ovalue);
+}
+
+static inline int timer_delete (timer_t timerid)
+{
+	struct itimerspec timespec;
+
+	timespec.it_interval.tv_sec=0;
+	timespec.it_interval.tv_usec=0;
+	timespec.it_value.tv_sec=0;
+	timespec.it_value.tv_usec=0;
+
+	return setitimer(ITIMER_REAL, &timespec, NULL);
+}
+
+static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
+{
+	return getitimer(ITIMER_REAL, value);
+}
+
 #endif	/* __XFS_DARWIN_H__ */
diff --git a/repair/progress.c b/repair/progress.c
index 27cbaef..0fee7dc 100644
--- a/repair/progress.c
+++ b/repair/progress.c
@@ -184,10 +184,22 @@ progress_rpt_thread (void *p)
 	 */
 
 	timespec.it_value.tv_sec = msgp->interval;
-	timespec.it_value.tv_nsec = 0;
 	timespec.it_interval.tv_sec = msgp->interval;
+	/*
+	 * On some platforms (like OS X), timers and time things are slightly
+	 * different: itimerspec is replaced with itimerval and timeval struct
+	 * has no tv_nsec, but just tv_usec member.
+	 * For compatibility, itimerspec is a macro defined to the existing
+	 * itimerval on these platforms, and in such case, use usec instead
+	 * of nsec.
+	 */
+#ifndef itimerspec
+	timespec.it_value.tv_nsec = 0;
 	timespec.it_interval.tv_nsec = 0;
-
+#else
+	timespec.it_value.tv_usec = 0;
+	timespec.it_interval.tv_usec = 0;
+#endif
 	if (timer_create (CLOCK_REALTIME, NULL, &timerid))
 		do_error(_("progress_rpt: cannot create timer\n"));
 
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 11/14] xfsprogs: Add statvfs64 for osx
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (9 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 10/14] xfsprogs: Add a timer implementation for OS X Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-23  3:32   ` Dave Chinner
  2015-09-30  8:21   ` [PATCH 11/14 v2] " Jan Tulak
  2015-09-15  9:59 ` [PATCH 12/14] xfsprogs: make fsr use mntinfo when there is no mntent Jan Tulak
                   ` (2 subsequent siblings)
  13 siblings, 2 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

Simply rename statvfs64 to statfs with a #define.
OSX version of statvfs is missing some members, so if the renaming
is in effect (stavfs64 is defined), don't try to use them and go
directly for the other member value.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 fsr/xfs_fsr.c        | 14 ++++++++++++++
 include/builddefs.in |  2 +-
 include/darwin.h     |  5 +++++
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index e1b7bd6..5f95cdc 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -36,6 +36,12 @@
 #  include <mntent.h>
 #endif
 
+#ifdef __APPLE__
+//#  define statvfs64 statfs;
+#  include <sys/param.h>
+#  include <sys/mount.h>
+#endif
+
 #ifndef XFS_XFLAG_NODEFRAG
 #define XFS_XFLAG_NODEFRAG 0x00002000 /* src dependancy, remove later */
 #endif
@@ -948,7 +954,11 @@ fsrfile_common(
 			fname, strerror(errno));
 		return -1;
 	}
+#ifndef statvfs64
 	bsize = vfss.f_frsize ? vfss.f_frsize : vfss.f_bsize;
+#else
+	bsize = vfss.f_bsize;
+#endif
 	if (statp->bs_blksize * statp->bs_blocks >
 	    vfss.f_bfree * bsize - minimumfree) {
 		fsrprintf(_("insufficient freespace for: %s: "
@@ -1728,7 +1738,11 @@ xfs_getrt(int fd, struct statvfs64 *sfbp)
 		close(fd);
 		return -1;
 	}
+#ifndef statvfs64
 	bsize = (sfbp->f_frsize ? sfbp->f_frsize : sfbp->f_bsize);
+#else
+	bsize = sfbp->f_bsize;
+#endif
 	factor = fsgeom.blocksize / bsize;         /* currently this is == 1 */
 	sfbp->f_bfree = (cnt.freertx * fsgeom.rtextsize) * factor;
 	return 0;
diff --git a/include/builddefs.in b/include/builddefs.in
index 25b8816..31e21ba 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -123,7 +123,7 @@ PCFLAGS = -D_GNU_SOURCE $(GCCFLAGS)
 endif
 ifeq ($(PKG_PLATFORM),darwin)
 PCFLAGS = $(GCCFLAGS)
-DEPENDFLAGS = -D__APPLE__
+DEPENDFLAGS = -D__APPLE__ -D_DARWIN_FEATURE_64_BIT_INODE
 endif
 ifeq ($(PKG_PLATFORM),irix)
 PLDLIBS = -ldisk -lgen
diff --git a/include/darwin.h b/include/darwin.h
index 0d2f175..288ad1f 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -216,4 +216,9 @@ static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
 	return getitimer(ITIMER_REAL, value);
 }
 
+/* FSR */
+
+#define statvfs64 statfs
+#define		_PATH_MOUNTED   "/etc/mtab"
+
 #endif	/* __XFS_DARWIN_H__ */
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 12/14] xfsprogs: make fsr use mntinfo when there is no mntent
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (10 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 11/14] xfsprogs: Add statvfs64 for osx Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-09-23  3:36   ` Dave Chinner
  2015-09-29 16:04   ` [PATCH 12/14 v2] " Jan Tulak
  2015-09-15  9:59 ` [PATCH 13/14] xfsprogs: Make mremap conditional Jan Tulak
  2015-09-15  9:59 ` [PATCH 14/14] xfsprogs: rename lstat64 to lstat for OS X Jan Tulak
  13 siblings, 2 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

For what fsr needs, mntinfo can be used instead of mntent.
Custom mntent struct is used to avoid too big ifdefs:
We only change few lines and the rest of the code can still
use mntent as before.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 fsr/Makefile     |  8 +++++++
 fsr/xfs_fsr.c    | 69 ++++++++++++++++++++++++++++++++++++++++++++++++--------
 include/darwin.h | 20 ++++++++++++++++
 3 files changed, 87 insertions(+), 10 deletions(-)

diff --git a/fsr/Makefile b/fsr/Makefile
index a9d1bf6..d3521b2 100644
--- a/fsr/Makefile
+++ b/fsr/Makefile
@@ -9,6 +9,14 @@ LTCOMMAND = xfs_fsr
 CFILES = xfs_fsr.c
 LLDLIBS = $(LIBHANDLE)
 
+ifeq ($(HAVE_GETMNTENT),yes)
+LCFLAGS += -DHAVE_GETMNTENT
+endif
+
+ifeq ($(HAVE_GETMNTINFO),yes)
+LCFLAGS += -DHAVE_GETMNTINFO
+endif
+
 default: depend $(LTCOMMAND)
 
 include $(BUILDRULES)
diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index 5f95cdc..ff791d3 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -32,8 +32,10 @@
 #include <sys/statvfs.h>
 #include <sys/xattr.h>
 
-#ifdef HAVE_MNTENT
+#if defined(HAVE_GETMNTENT)
 #  include <mntent.h>
+#elif defined(HAVE_GETMNTINFO)
+#  include <sys/mount.h>
 #endif
 
 #ifdef __APPLE__
@@ -191,9 +193,10 @@ find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
 {
 	struct mntent *t;
 	struct stat64 ms;
-	FILE *mtabp;
 	char *mntp = NULL;
 
+#if defined(HAVE_GETMNTENT)
+	FILE *mtabp;
 	mtabp = setmntent(mtab, "r");
 	if (!mtabp) {
 		fprintf(stderr, _("%s: cannot read %s\n"),
@@ -202,6 +205,27 @@ find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
 	}
 
 	while ((t = getmntent(mtabp))) {
+#elif defined(HAVE_GETMNTINFO)
+	struct statfs	*stats;
+	int error, i, count;
+	// because "t" is a pointer, but we don't need to use
+	// malloc for this usage
+	struct mntent t_tmp;
+	t = &t_tmp;
+
+		
+	error = 0;
+	if ((count = getmntinfo(&stats, 0)) < 0) {
+		fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
+				progname, strerror(errno));
+		return 0;
+	}
+
+	for (i = 0; i < count; i++) {
+		mntinfo2mntent(&stats[i], t);
+#else
+# error "How do I extract info about mounted filesystems on this platform?"
+#endif
 		if (S_ISDIR(sb->st_mode)) {		/* mount point */
 			if (stat64(t->mnt_dir, &ms) < 0)
 				continue;
@@ -233,10 +257,11 @@ find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
 		break;
 	}
 
+#if defined(HAVE_GETMNTENT)
 	endmntent(mtabp);
+#endif
 	return mntp;
 }
-
 int
 main(int argc, char **argv)
 {
@@ -411,18 +436,11 @@ usage(int ret)
 static void
 initallfs(char *mtab)
 {
-	FILE *fp;
 	struct mntent *mp;
 	int mi;
 	char *cp;
 	struct stat64 sb;
 
-	fp = setmntent(mtab, "r");
-	if (fp == NULL) {
-		fsrprintf(_("could not open mtab file: %s\n"), mtab);
-		exit(1);
-	}
-
 	/* malloc a number of descriptors, increased later if needed */
 	if (!(fsbase = (fsdesc_t *)malloc(fsbufsize * sizeof(fsdesc_t)))) {
 		fsrprintf(_("out of memory: %s\n"), strerror(errno));
@@ -433,7 +451,36 @@ initallfs(char *mtab)
 	/* find all rw xfs file systems */
 	mi = 0;
 	fs = fsbase;
+
+#if defined(HAVE_GETMNTENT)
+	FILE *fp;
+	fp = setmntent(mtab, "r");
+	if (fp == NULL) {
+		fsrprintf(_("could not open mtab file: %s\n"), mtab);
+		exit(1);
+	}
+
 	while ((mp = getmntent(fp))) {
+#elif defined(HAVE_GETMNTINFO)
+	struct statfs	*stats;
+	int error, i, count;
+	// because "t" is a pointer, but we don't need to use
+	// malloc for this usage
+	struct mntent mp_tmp;
+	mp = &mp_tmp;
+	error = 0;
+	if ((count = getmntinfo(&stats, 0)) < 0) {
+		fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
+				progname, strerror(errno));
+		exit(1);
+	}
+
+	for (i = 0; i < count; i++) {
+		mntinfo2mntent(&stats[i], mp);
+#else
+# error "How do I extract info about mounted filesystems on this platform?"
+#endif
+
 		int rw = 0;
 
 		if (strcmp(mp->mnt_type, MNTTYPE_XFS ) != 0 ||
@@ -485,7 +532,9 @@ initallfs(char *mtab)
 	}
 	numfs = mi;
 	fsend = (fsbase + numfs);
+#if defined(HAVE_GETMNTENT)
 	endmntent(fp);
+#endif
 	if (numfs == 0) {
 		fsrprintf(_("no rw xfs file systems in mtab: %s\n"), mtab);
 		exit(0);
diff --git a/include/darwin.h b/include/darwin.h
index 288ad1f..0313f46 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -218,7 +218,27 @@ static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
 
 /* FSR */
 
+#  include <sys/mount.h>
+#  include <sys/param.h>
+#include <sys/ucred.h>
+#include <errno.h>
 #define statvfs64 statfs
 #define		_PATH_MOUNTED   "/etc/mtab"
 
+struct mntent
+{
+	char *mnt_fsname;
+	char *mnt_dir;
+	char *mnt_type;
+	char *mnt_opts;
+	int mnt_freq;
+	int mnt_passno;
+};
+
+static inline void mntinfo2mntent (struct statfs * stats, struct mntent * mnt) {
+	mnt->mnt_fsname = stats->f_mntfromname;
+	mnt->mnt_dir = stats->f_mntonname;
+	mnt->mnt_type = stats->f_fstypename;
+}
+
 #endif	/* __XFS_DARWIN_H__ */
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 13/14] xfsprogs: Make mremap conditional
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (11 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 12/14] xfsprogs: make fsr use mntinfo when there is no mntent Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  2015-10-13  4:42   ` Dave Chinner
  2015-09-15  9:59 ` [PATCH 14/14] xfsprogs: rename lstat64 to lstat for OS X Jan Tulak
  13 siblings, 1 reply; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

Don't build mremap (in xfs_io) on platforms where it has no support.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 configure.ac          |  1 +
 include/builddefs.in  |  1 +
 include/darwin.h      |  1 +
 io/mmap.c             |  8 ++++++++
 m4/package_libcdev.m4 | 13 +++++++++++++
 5 files changed, 24 insertions(+)

diff --git a/configure.ac b/configure.ac
index 5d8486e..7cb87bc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -124,6 +124,7 @@ AC_HAVE_MNTENT
 AC_HAVE_FLS
 AC_HAVE_READDIR
 AC_HAVE_FSETXATTR
+AC_HAVE_MREMAP
 
 if test "$enable_blkid" = yes; then
 AC_HAVE_BLKID_TOPO
diff --git a/include/builddefs.in b/include/builddefs.in
index 31e21ba..c1797fd 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -107,6 +107,7 @@ HAVE_READDIR = @have_readdir@
 HAVE_MNTENT = @have_mntent@
 HAVE_FLS = @have_fls@
 HAVE_FSETXATTR = @have_fsetxattr@
+HAVE_MREMAP = @have_mremap@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
 #	   -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
diff --git a/include/darwin.h b/include/darwin.h
index 0313f46..16ead12 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -33,6 +33,7 @@
 #include <mach/mach_time.h>
 #include <inttypes.h>
 #include <stdio.h>
+#include <sys/mman.h>
 
 #include <machine/endian.h>
 #define __BYTE_ORDER	BYTE_ORDER
diff --git a/io/mmap.c b/io/mmap.c
index f26276e..7093650 100644
--- a/io/mmap.c
+++ b/io/mmap.c
@@ -28,7 +28,9 @@ static cmdinfo_t mread_cmd;
 static cmdinfo_t msync_cmd;
 static cmdinfo_t munmap_cmd;
 static cmdinfo_t mwrite_cmd;
+#ifdef HAVE_MREMAP
 static cmdinfo_t mremap_cmd;
+#endif /* HAVE_MREMAP */
 
 mmap_region_t	*maptable;
 int		mapcount;
@@ -574,6 +576,7 @@ mwrite_f(
 	return 0;
 }
 
+#ifdef HAVE_MREMAP
 static void
 mremap_help(void)
 {
@@ -633,6 +636,7 @@ mremap_f(
 
 	return 0;
 }
+#endif /* HAVE_MREMAP */
 
 void
 mmap_init(void)
@@ -688,6 +692,7 @@ mmap_init(void)
 		_("writes data into a region in the current memory mapping");
 	mwrite_cmd.help = mwrite_help;
 
+#ifdef HAVE_MREMAP
 	mremap_cmd.name = "mremap";
 	mremap_cmd.altname = "mrm";
 	mremap_cmd.cfunc = mremap_f;
@@ -698,11 +703,14 @@ mmap_init(void)
 	mremap_cmd.oneline =
 		_("alters the size of the current memory mapping");
 	mremap_cmd.help = mremap_help;
+#endif /* HAVE_MREMAP */
 
 	add_command(&mmap_cmd);
 	add_command(&mread_cmd);
 	add_command(&msync_cmd);
 	add_command(&munmap_cmd);
 	add_command(&mwrite_cmd);
+#ifdef HAVE_MREMAP
 	add_command(&mremap_cmd);
+#endif /* HAVE_MREMAP */
 }
diff --git a/m4/package_libcdev.m4 b/m4/package_libcdev.m4
index 5e900ab..b6a7a54 100644
--- a/m4/package_libcdev.m4
+++ b/m4/package_libcdev.m4
@@ -235,3 +235,16 @@ AC_DEFUN([AC_HAVE_MNTENT],
     have_mntent=yes)
     AC_SUBST(have_mntent)
   ])
+
+#
+# Check if we have a mremap call (not on Mac OS X)
+#
+AC_DEFUN([AC_HAVE_MREMAP],
+  [ AC_CHECK_DECL([mremap],
+       have_mremap=yes,
+       [],
+       [#define _GNU_SOURCE
+        #include <sys/mman.h>]
+       )
+    AC_SUBST(have_mremap)
+  ])
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 14/14] xfsprogs: rename lstat64 to lstat for OS X
  2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
                   ` (12 preceding siblings ...)
  2015-09-15  9:59 ` [PATCH 13/14] xfsprogs: Make mremap conditional Jan Tulak
@ 2015-09-15  9:59 ` Jan Tulak
  13 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-15  9:59 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

OS X has a different means to distinguish between
a 32 and 64bit calls - using xxx64 is deprecated.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 include/darwin.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/darwin.h b/include/darwin.h
index 16ead12..4ad2de1 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -224,6 +224,7 @@ static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
 #include <sys/ucred.h>
 #include <errno.h>
 #define statvfs64 statfs
+#define lstat64 lstat
 #define		_PATH_MOUNTED   "/etc/mtab"
 
 struct mntent
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 03/14] xfsprogs: avoid dependency on Linux XATTR_SIZE_MAX
  2015-09-15  9:59 ` [PATCH 03/14] xfsprogs: avoid dependency on Linux XATTR_SIZE_MAX Jan Tulak
@ 2015-09-23  3:09   ` Dave Chinner
  0 siblings, 0 replies; 35+ messages in thread
From: Dave Chinner @ 2015-09-23  3:09 UTC (permalink / raw)
  To: Jan Tulak; +Cc: xfs

On Tue, Sep 15, 2015 at 11:59:13AM +0200, Jan Tulak wrote:
> Currently, we depends on Linux XATTR value for on disk
> definitions. Which causes trouble on other platforms and
> maybe also if this value was to change.
> 
> Fix it by creating a custom definition independent from
> those in Linux (although with the same values), so it is OK
> with the be16 fields used for holding these attributes.
> 
> Signed-off-by: Jan Tulak <jtulak@redhat.com>

Looks good. We'll need a kernel version of this patch, too.

Reviewed-by: Dave Chinner <dchinner@redhat.com>

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 04/14] xfsprogs: prefix XATTR_LIST_MAX with XFS_
  2015-09-15  9:59 ` [PATCH 04/14] xfsprogs: prefix XATTR_LIST_MAX with XFS_ Jan Tulak
@ 2015-09-23  3:15   ` Dave Chinner
  2015-09-24  8:28     ` Jan Tulak
  2015-10-07 11:17   ` [PATCH 04/14 v2] " Jan Tulak
  1 sibling, 1 reply; 35+ messages in thread
From: Dave Chinner @ 2015-09-23  3:15 UTC (permalink / raw)
  To: Jan Tulak; +Cc: xfs

On Tue, Sep 15, 2015 at 11:59:14AM +0200, Jan Tulak wrote:
> WILL CHANGE THE COMMIT MESSAGE.

OK?

> All right, I make the renaming with define - though I'm not sure
> that with the ifdef for OS X and SIZE_MAX moved to a standalone patch
> we need it - shouldn't be this change rather dropped?
> 
> Signed-off-by: Jan Tulak <jtulak@redhat.com>
> ---
>  include/xfs.h      | 2 ++
>  libhandle/handle.c | 4 ++--
>  libhandle/jdm.c    | 4 ++--
>  3 files changed, 6 insertions(+), 4 deletions(-)
> 
> diff --git a/include/xfs.h b/include/xfs.h
> index bc94068..8ee0106 100644
> --- a/include/xfs.h
> +++ b/include/xfs.h
> @@ -53,6 +53,8 @@
>  # define ASSERT(EX)	((void) 0)
>  #endif
>  
> +#define XFS_XATTR_LIST_MAX XATTR_LIST_MAX
> +

This does not belong here - it is a limit that applies to the ioctl
API and so must be the same in userspace and the kernel. Such
definitions belong in libxfs/xfs_fs.h, and should respect local OS
limits if defined. e.g. something like:

#ifdef XATTR_LIST_MAX
#define XFS_XATTR_LIST_MAX XATTR_LIST_MAX
#else
#define XFS_XATTR_LIST_MAX 65536
#endif

Will work on both the kernel and userspace side. This will also need
a kernel side patch...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 10/14] xfsprogs: Add a timer implementation for OS X
  2015-09-15  9:59 ` [PATCH 10/14] xfsprogs: Add a timer implementation for OS X Jan Tulak
@ 2015-09-23  3:25   ` Dave Chinner
  2015-09-24  9:26     ` Jan Tulak
  2015-09-30  8:23   ` [PATCH 10/14 v2] " Jan Tulak
  1 sibling, 1 reply; 35+ messages in thread
From: Dave Chinner @ 2015-09-23  3:25 UTC (permalink / raw)
  To: Jan Tulak; +Cc: xfs

On Tue, Sep 15, 2015 at 11:59:20AM +0200, Jan Tulak wrote:
> OS X does not have the timer used in xfs_repair.
> Add a simple implementation providing the required
> capabilities.
....
>  #endif	/* __XFS_DARWIN_H__ */
> diff --git a/repair/progress.c b/repair/progress.c
> index 27cbaef..0fee7dc 100644
> --- a/repair/progress.c
> +++ b/repair/progress.c
> @@ -184,10 +184,22 @@ progress_rpt_thread (void *p)
>  	 */
>  
>  	timespec.it_value.tv_sec = msgp->interval;
> -	timespec.it_value.tv_nsec = 0;
>  	timespec.it_interval.tv_sec = msgp->interval;
> +	/*
> +	 * On some platforms (like OS X), timers and time things are slightly
> +	 * different: itimerspec is replaced with itimerval and timeval struct
> +	 * has no tv_nsec, but just tv_usec member.
> +	 * For compatibility, itimerspec is a macro defined to the existing
> +	 * itimerval on these platforms, and in such case, use usec instead
> +	 * of nsec.
> +	 */
> +#ifndef itimerspec
> +	timespec.it_value.tv_nsec = 0;
>  	timespec.it_interval.tv_nsec = 0;
> -
> +#else
> +	timespec.it_value.tv_usec = 0;
> +	timespec.it_interval.tv_usec = 0;
> +#endif

That's pretty nasty. How about this:

	memset(&timespec, 0, sizeof(timespec));
	timespec.it_value.tv_sec = msgp->interval;
	timespec.it_interval.tv_sec = msgp->interval;

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 11/14] xfsprogs: Add statvfs64 for osx
  2015-09-15  9:59 ` [PATCH 11/14] xfsprogs: Add statvfs64 for osx Jan Tulak
@ 2015-09-23  3:32   ` Dave Chinner
  2015-09-24  9:33     ` Jan Tulak
  2015-09-30  8:21   ` [PATCH 11/14 v2] " Jan Tulak
  1 sibling, 1 reply; 35+ messages in thread
From: Dave Chinner @ 2015-09-23  3:32 UTC (permalink / raw)
  To: Jan Tulak; +Cc: xfs

On Tue, Sep 15, 2015 at 11:59:21AM +0200, Jan Tulak wrote:
> Simply rename statvfs64 to statfs with a #define.
> OSX version of statvfs is missing some members, so if the renaming
> is in effect (stavfs64 is defined), don't try to use them and go
> directly for the other member value.
> 
> Signed-off-by: Jan Tulak <jtulak@redhat.com>
> ---
>  fsr/xfs_fsr.c        | 14 ++++++++++++++
>  include/builddefs.in |  2 +-
>  include/darwin.h     |  5 +++++
>  3 files changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
> index e1b7bd6..5f95cdc 100644
> --- a/fsr/xfs_fsr.c
> +++ b/fsr/xfs_fsr.c
> @@ -36,6 +36,12 @@
>  #  include <mntent.h>
>  #endif
>  
> +#ifdef __APPLE__
> +//#  define statvfs64 statfs;
> +#  include <sys/param.h>
> +#  include <sys/mount.h>
> +#endif

Why is this here? We've included libxfs.h in this file, so we've
got access to the platform specific includes already, and later in
the patch you put the commented out define there...

> +
>  #ifndef XFS_XFLAG_NODEFRAG
>  #define XFS_XFLAG_NODEFRAG 0x00002000 /* src dependancy, remove later */
>  #endif
> @@ -948,7 +954,11 @@ fsrfile_common(
>  			fname, strerror(errno));
>  		return -1;
>  	}
> +#ifndef statvfs64
>  	bsize = vfss.f_frsize ? vfss.f_frsize : vfss.f_bsize;
> +#else
> +	bsize = vfss.f_bsize;
> +#endif

	bsize = platform_statvfs_bsize(&vfss);

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 12/14] xfsprogs: make fsr use mntinfo when there is no mntent
  2015-09-15  9:59 ` [PATCH 12/14] xfsprogs: make fsr use mntinfo when there is no mntent Jan Tulak
@ 2015-09-23  3:36   ` Dave Chinner
  2015-09-24 14:38     ` Jan Tulak
  2015-09-29 16:04   ` [PATCH 12/14 v2] " Jan Tulak
  1 sibling, 1 reply; 35+ messages in thread
From: Dave Chinner @ 2015-09-23  3:36 UTC (permalink / raw)
  To: Jan Tulak; +Cc: xfs

On Tue, Sep 15, 2015 at 11:59:22AM +0200, Jan Tulak wrote:
> For what fsr needs, mntinfo can be used instead of mntent.
> Custom mntent struct is used to avoid too big ifdefs:
> We only change few lines and the rest of the code can still
> use mntent as before.
> 
> Signed-off-by: Jan Tulak <jtulak@redhat.com>
> ---
>  fsr/Makefile     |  8 +++++++
>  fsr/xfs_fsr.c    | 69 ++++++++++++++++++++++++++++++++++++++++++++++++--------
>  include/darwin.h | 20 ++++++++++++++++
>  3 files changed, 87 insertions(+), 10 deletions(-)
> 
> diff --git a/fsr/Makefile b/fsr/Makefile
> index a9d1bf6..d3521b2 100644
> --- a/fsr/Makefile
> +++ b/fsr/Makefile
> @@ -9,6 +9,14 @@ LTCOMMAND = xfs_fsr
>  CFILES = xfs_fsr.c
>  LLDLIBS = $(LIBHANDLE)
>  
> +ifeq ($(HAVE_GETMNTENT),yes)
> +LCFLAGS += -DHAVE_GETMNTENT
> +endif
> +
> +ifeq ($(HAVE_GETMNTINFO),yes)
> +LCFLAGS += -DHAVE_GETMNTINFO
> +endif
> +
>  default: depend $(LTCOMMAND)
>  
>  include $(BUILDRULES)
> diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
> index 5f95cdc..ff791d3 100644
> --- a/fsr/xfs_fsr.c
> +++ b/fsr/xfs_fsr.c
> @@ -32,8 +32,10 @@
>  #include <sys/statvfs.h>
>  #include <sys/xattr.h>
>  
> -#ifdef HAVE_MNTENT
> +#if defined(HAVE_GETMNTENT)
>  #  include <mntent.h>
> +#elif defined(HAVE_GETMNTINFO)
> +#  include <sys/mount.h>
>  #endif
>  
>  #ifdef __APPLE__
> @@ -191,9 +193,10 @@ find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
>  {
>  	struct mntent *t;
>  	struct stat64 ms;
> -	FILE *mtabp;
>  	char *mntp = NULL;
>  
> +#if defined(HAVE_GETMNTENT)
> +	FILE *mtabp;
>  	mtabp = setmntent(mtab, "r");
>  	if (!mtabp) {
>  		fprintf(stderr, _("%s: cannot read %s\n"),
> @@ -202,6 +205,27 @@ find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
>  	}
>  
>  	while ((t = getmntent(mtabp))) {
> +#elif defined(HAVE_GETMNTINFO)
> +	struct statfs	*stats;
> +	int error, i, count;
> +	// because "t" is a pointer, but we don't need to use
> +	// malloc for this usage
> +	struct mntent t_tmp;
> +	t = &t_tmp;
> +
> +		
> +	error = 0;
> +	if ((count = getmntinfo(&stats, 0)) < 0) {
> +		fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
> +				progname, strerror(errno));
> +		return 0;
> +	}
> +
> +	for (i = 0; i < count; i++) {
> +		mntinfo2mntent(&stats[i], t);
> +#else
> +# error "How do I extract info about mounted filesystems on this platform?"
> +#endif

No, please don't do that. Having a loop iterator split across two
separate defines is unmaintainable. Write two separate functions
with the different loop iterators, then factor the common bit out
of them into a single function.

>  	/* find all rw xfs file systems */
>  	mi = 0;
>  	fs = fsbase;
> +
> +#if defined(HAVE_GETMNTENT)
> +	FILE *fp;
> +	fp = setmntent(mtab, "r");
> +	if (fp == NULL) {
> +		fsrprintf(_("could not open mtab file: %s\n"), mtab);
> +		exit(1);
> +	}
> +
>  	while ((mp = getmntent(fp))) {
> +#elif defined(HAVE_GETMNTINFO)
> +	struct statfs	*stats;
> +	int error, i, count;
> +	// because "t" is a pointer, but we don't need to use
> +	// malloc for this usage
> +	struct mntent mp_tmp;
> +	mp = &mp_tmp;
> +	error = 0;
> +	if ((count = getmntinfo(&stats, 0)) < 0) {
> +		fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
> +				progname, strerror(errno));
> +		exit(1);
> +	}
> +
> +	for (i = 0; i < count; i++) {
> +		mntinfo2mntent(&stats[i], mp);
> +#else
> +# error "How do I extract info about mounted filesystems on this platform?"
> +#endif
> +

Same again here.


-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 04/14] xfsprogs: prefix XATTR_LIST_MAX with XFS_
  2015-09-23  3:15   ` Dave Chinner
@ 2015-09-24  8:28     ` Jan Tulak
  2015-09-24 22:41       ` Dave Chinner
  0 siblings, 1 reply; 35+ messages in thread
From: Jan Tulak @ 2015-09-24  8:28 UTC (permalink / raw)
  To: Dave Chinner; +Cc: xfs-oss


[-- Attachment #1.1: Type: text/plain, Size: 1928 bytes --]

On Wed, Sep 23, 2015 at 5:15 AM, Dave Chinner <david@fromorbit.com> wrote:

> On Tue, Sep 15, 2015 at 11:59:14AM +0200, Jan Tulak wrote:
> > WILL CHANGE THE COMMIT MESSAGE.
>
> OK?

> All right, I make the renaming with define - though I'm not sure
> > that with the ifdef for OS X and SIZE_MAX moved to a standalone patch
> > we need it - shouldn't be this change rather dropped?
> >
> > Signed-off-by: Jan Tulak <jtulak@redhat.com>
> > ---
> >  include/xfs.h      | 2 ++
> >  libhandle/handle.c | 4 ++--
> >  libhandle/jdm.c    | 4 ++--
> >  3 files changed, 6 insertions(+), 4 deletions(-)
> >
> > diff --git a/include/xfs.h b/include/xfs.h
> > index bc94068..8ee0106 100644
> > --- a/include/xfs.h
> > +++ b/include/xfs.h
> > @@ -53,6 +53,8 @@
> >  # define ASSERT(EX)  ((void) 0)
> >  #endif
> >
> > +#define XFS_XATTR_LIST_MAX XATTR_LIST_MAX
> > +
>
> This does not belong here - it is a limit that applies to the ioctl
> API and so must be the same in userspace and the kernel. Such
> definitions belong in libxfs/xfs_fs.h, and should respect local OS
> limits if defined. e.g. something like:
>
> #ifdef XATTR_LIST_MAX
> #define XFS_XATTR_LIST_MAX XATTR_LIST_MAX
> #else
> #define XFS_XATTR_LIST_MAX 65536
> #endif
>
>
​OK, ​that makes sense.



> Will work on both the kernel and userspace side. This will also need
> a kernel side patch...


​Now, this is something where I may need a bit help/confirmation, I guess.​
What I suppose I should do is:

1) Clone linux-xfs (git://
git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs.git)
2) Edit linux-xfs/fs/xfs/libxfs/xfs_fs.h and add the same change there
3) Send it to this mailing list as usual, with "[PATCH] xfs: ..."

(The same goes for the other patch with the kernel need too.)

Is it all right? Correct repository URL? :-)

Thanks,
Jan

-- 
Jan Tulak
jtulak@redhat.com / jan@tulak.me

[-- Attachment #1.2: Type: text/html, Size: 4615 bytes --]

[-- Attachment #2: Type: text/plain, Size: 121 bytes --]

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 10/14] xfsprogs: Add a timer implementation for OS X
  2015-09-23  3:25   ` Dave Chinner
@ 2015-09-24  9:26     ` Jan Tulak
  0 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-24  9:26 UTC (permalink / raw)
  To: Dave Chinner; +Cc: xfs-oss


[-- Attachment #1.1: Type: text/plain, Size: 1699 bytes --]

On Wed, Sep 23, 2015 at 5:25 AM, Dave Chinner <david@fromorbit.com> wrote:

> On Tue, Sep 15, 2015 at 11:59:20AM +0200, Jan Tulak wrote:
> > OS X does not have the timer used in xfs_repair.
> > Add a simple implementation providing the required
> > capabilities.
> ....
> >  #endif       /* __XFS_DARWIN_H__ */
> > diff --git a/repair/progress.c b/repair/progress.c
> > index 27cbaef..0fee7dc 100644
> > --- a/repair/progress.c
> > +++ b/repair/progress.c
> > @@ -184,10 +184,22 @@ progress_rpt_thread (void *p)
> >        */
> >
> >       timespec.it_value.tv_sec = msgp->interval;
> > -     timespec.it_value.tv_nsec = 0;
> >       timespec.it_interval.tv_sec = msgp->interval;
> > +     /*
> > +      * On some platforms (like OS X), timers and time things are
> slightly
> > +      * different: itimerspec is replaced with itimerval and timeval
> struct
> > +      * has no tv_nsec, but just tv_usec member.
> > +      * For compatibility, itimerspec is a macro defined to the existing
> > +      * itimerval on these platforms, and in such case, use usec instead
> > +      * of nsec.
> > +      */
> > +#ifndef itimerspec
> > +     timespec.it_value.tv_nsec = 0;
> >       timespec.it_interval.tv_nsec = 0;
> > -
> > +#else
> > +     timespec.it_value.tv_usec = 0;
> > +     timespec.it_interval.tv_usec = 0;
> > +#endif
>
> That's pretty nasty. How about this:
>
>         memset(&timespec, 0, sizeof(timespec));
>         timespec.it_value.tv_sec = msgp->interval;
>         timespec.it_interval.tv_sec = msgp->interval;
>

​This is much better and elegant ​solution. :-)

Cheers,
Jan


-- 
Jan Tulak
jtulak@redhat.com / jan@tulak.me

[-- Attachment #1.2: Type: text/html, Size: 3043 bytes --]

[-- Attachment #2: Type: text/plain, Size: 121 bytes --]

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 11/14] xfsprogs: Add statvfs64 for osx
  2015-09-23  3:32   ` Dave Chinner
@ 2015-09-24  9:33     ` Jan Tulak
  0 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-24  9:33 UTC (permalink / raw)
  To: Dave Chinner; +Cc: xfs-oss


[-- Attachment #1.1: Type: text/plain, Size: 1417 bytes --]

On Wed, Sep 23, 2015 at 5:32 AM, Dave Chinner <david@fromorbit.com> wrote:

> On Tue, Sep 15, 2015 at 11:59:21AM +0200, Jan Tulak wrote:
> > Simply rename statvfs64 to statfs with a #define.
> > OSX version of statvfs is missing some members, so if the renaming
> > is in effect (stavfs64 is defined), don't try to use them and go
> > directly for the other member value.
> >
> > Signed-off-by: Jan Tulak <jtulak@redhat.com>
> > ---
> >  fsr/xfs_fsr.c        | 14 ++++++++++++++
> >  include/builddefs.in |  2 +-
> >  include/darwin.h     |  5 +++++
> >  3 files changed, 20 insertions(+), 1 deletion(-)
> >
> > diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
> > index e1b7bd6..5f95cdc 100644
> > --- a/fsr/xfs_fsr.c
> > +++ b/fsr/xfs_fsr.c
> > @@ -36,6 +36,12 @@
> >  #  include <mntent.h>
> >  #endif
> >
> > +#ifdef __APPLE__
> > +//#  define statvfs64 statfs;
> > +#  include <sys/param.h>
> > +#  include <sys/mount.h>
> > +#endif
>
> Why is this here? We've included libxfs.h in this file, so we've
> got access to the platform specific includes already, and later in
> the patch you put the commented out define there...
>

​Most likely because I messed it in a rebase during some conflict. I try to
check for these things, but apparently this one escaped. Removing it
again​..

Thanks for catching it.

Cheers,
Jan

-- 
Jan Tulak
jtulak@redhat.com / jan@tulak.me

[-- Attachment #1.2: Type: text/html, Size: 2995 bytes --]

[-- Attachment #2: Type: text/plain, Size: 121 bytes --]

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 12/14] xfsprogs: make fsr use mntinfo when there is no mntent
  2015-09-23  3:36   ` Dave Chinner
@ 2015-09-24 14:38     ` Jan Tulak
  2015-09-24 22:53       ` Dave Chinner
  0 siblings, 1 reply; 35+ messages in thread
From: Jan Tulak @ 2015-09-24 14:38 UTC (permalink / raw)
  To: Dave Chinner; +Cc: xfs-oss


[-- Attachment #1.1: Type: text/plain, Size: 1917 bytes --]

On Wed, Sep 23, 2015 at 5:36 AM, Dave Chinner <david@fromorbit.com> wrote:

> On Tue, Sep 15, 2015 at 11:59:22AM +0200, Jan Tulak wrote:
> > @@ -202,6 +205,27 @@ find_mountpoint(char *mtab, char *argname, struct
> stat64 *sb)
> >       }
> >
> >       while ((t = getmntent(mtabp))) {
> > +#elif defined(HAVE_GETMNTINFO)
> > +     struct statfs   *stats;
> > +     int error, i, count;
> > +     // because "t" is a pointer, but we don't need to use
> > +     // malloc for this usage
> > +     struct mntent t_tmp;
> > +     t = &t_tmp;
> > +
> > +
> > +     error = 0;
> > +     if ((count = getmntinfo(&stats, 0)) < 0) {
> > +             fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
> > +                             progname, strerror(errno));
> > +             return 0;
> > +     }
> > +
> > +     for (i = 0; i < count; i++) {
> > +             mntinfo2mntent(&stats[i], t);
> > +#else
> > +# error "How do I extract info about mounted filesystems on this
> platform?"
> > +#endif
>
> No, please don't do that. Having a loop iterator split across two
> separate defines is unmaintainable. Write two separate functions
> with the different loop iterators, then factor the common bit out
> of them into a single function.
>
>
I did a little refactoring to solve it. What I would like to ask ab​out is
this:
When I can put ifdef just inside of a function like fnc(void) { #ifdef...
#else ... #endif }, with little to no code outside of the ifdef, is it
better to put the ifdef outside, or keep it inside?

I suppose the outside placement allows for easier changes for one of the
branches when there would be a new function just for a specific branch. But
on the other side, it makes it easier to forget the second function in
another branch when making some change later.

​Cheers,
Jan​

--
​-​

Jan Tulak
jtulak@redhat.com / jan@tulak.me

[-- Attachment #1.2: Type: text/html, Size: 3567 bytes --]

[-- Attachment #2: Type: text/plain, Size: 121 bytes --]

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 04/14] xfsprogs: prefix XATTR_LIST_MAX with XFS_
  2015-09-24  8:28     ` Jan Tulak
@ 2015-09-24 22:41       ` Dave Chinner
  0 siblings, 0 replies; 35+ messages in thread
From: Dave Chinner @ 2015-09-24 22:41 UTC (permalink / raw)
  To: Jan Tulak; +Cc: xfs-oss

On Thu, Sep 24, 2015 at 10:28:05AM +0200, Jan Tulak wrote:
> On Wed, Sep 23, 2015 at 5:15 AM, Dave Chinner <david@fromorbit.com> wrote:
> > Will work on both the kernel and userspace side. This will also need
> > a kernel side patch...
> 
> 
> ​Now, this is something where I may need a bit help/confirmation, I guess.​
> What I suppose I should do is:
> 
> 1) Clone linux-xfs (git://
> git.kernel.org/pub/scm/linux/kernel/git/dgc/linux-xfs.git)
> 2) Edit linux-xfs/fs/xfs/libxfs/xfs_fs.h and add the same change there

and to the files in fs/xfs that directly use XATTR_LIST_MAX.

2.5) compile, install kernel, run xfstests.

> 3) Send it to this mailing list as usual, with "[PATCH] xfs: ..."
>
> (The same goes for the other patch with the kernel need too.)
> 
> Is it all right? Correct repository URL? :-)

Yup.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 12/14] xfsprogs: make fsr use mntinfo when there is no mntent
  2015-09-24 14:38     ` Jan Tulak
@ 2015-09-24 22:53       ` Dave Chinner
  2015-09-29 16:07         ` Jan Tulak
  0 siblings, 1 reply; 35+ messages in thread
From: Dave Chinner @ 2015-09-24 22:53 UTC (permalink / raw)
  To: Jan Tulak; +Cc: xfs-oss

On Thu, Sep 24, 2015 at 04:38:49PM +0200, Jan Tulak wrote:
> On Wed, Sep 23, 2015 at 5:36 AM, Dave Chinner <david@fromorbit.com> wrote:
> 
> > On Tue, Sep 15, 2015 at 11:59:22AM +0200, Jan Tulak wrote:
> > > @@ -202,6 +205,27 @@ find_mountpoint(char *mtab, char *argname, struct
> > stat64 *sb)
> > >       }
> > >
> > >       while ((t = getmntent(mtabp))) {
> > > +#elif defined(HAVE_GETMNTINFO)
> > > +     struct statfs   *stats;
> > > +     int error, i, count;
> > > +     // because "t" is a pointer, but we don't need to use
> > > +     // malloc for this usage
> > > +     struct mntent t_tmp;
> > > +     t = &t_tmp;
> > > +
> > > +
> > > +     error = 0;
> > > +     if ((count = getmntinfo(&stats, 0)) < 0) {
> > > +             fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
> > > +                             progname, strerror(errno));
> > > +             return 0;
> > > +     }
> > > +
> > > +     for (i = 0; i < count; i++) {
> > > +             mntinfo2mntent(&stats[i], t);
> > > +#else
> > > +# error "How do I extract info about mounted filesystems on this
> > platform?"
> > > +#endif
> >
> > No, please don't do that. Having a loop iterator split across two
> > separate defines is unmaintainable. Write two separate functions
> > with the different loop iterators, then factor the common bit out
> > of them into a single function.
> >
> >
> I did a little refactoring to solve it. What I would like to ask ab​out is
> this:
> When I can put ifdef just inside of a function like fnc(void) { #ifdef...
> #else ... #endif }, with little to no code outside of the ifdef, is it
> better to put the ifdef outside, or keep it inside?

The idea is that the "little differences" are put in functions that
end up in include/<platform>.h or libxfs/<platform>.c, so there are
no ifdefs in any of the application or library code. The build will
automatically include the correct function on the given platform,
and so the application code does not need such ifdefs at all.

e.g. you could implement these functions to abstract the differences
away from xfs_fsr and any other code that iterates the mount table:

struct mntent_cursor {
	/* variables needed to track iteration of the mtab */
};

platform_first_mntent()
platform_next_mntent()
platform_end_mntent()

and so the code would look like:

	struct mntent_cursor	cursor;

	mntent = platform_first_mntent(&cursor)

	do {
		/* process mntent */
	} while (mntent = platform_next_mntent(&cursor, mntent));

	platform_end_mntent(&cursor);

This completely abstracts the differences related to the the mount
table traversal, and allows the aplication level code to be written
in a clean, easily maintainable fashion...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 12/14 v2] xfsprogs: make fsr use mntinfo when there is no mntent
  2015-09-15  9:59 ` [PATCH 12/14] xfsprogs: make fsr use mntinfo when there is no mntent Jan Tulak
  2015-09-23  3:36   ` Dave Chinner
@ 2015-09-29 16:04   ` Jan Tulak
  2015-10-13  4:54     ` Dave Chinner
  2015-10-13  9:56     ` [PATCH 12/14 v3] " Jan Tulak
  1 sibling, 2 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-29 16:04 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

UPDATE:
- refactor ifdefs to platform_ functions

For what fsr needs, mntinfo can be used instead of mntent on some
platforms. Exctract the platform-specific code to platform headers.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 fsr/Makefile          |   8 ++++
 fsr/xfs_fsr.c         | 127 +++++++++++++++++++++++++++++++-------------------
 include/darwin.h      |  64 +++++++++++++++++++++++++
 include/freebsd.h     |  32 +++++++++++++
 include/gnukfreebsd.h |  31 ++++++++++++
 include/irix.h        |  32 +++++++++++++
 include/linux.h       |  31 ++++++++++++
 7 files changed, 276 insertions(+), 49 deletions(-)

diff --git a/fsr/Makefile b/fsr/Makefile
index a9d1bf6..d3521b2 100644
--- a/fsr/Makefile
+++ b/fsr/Makefile
@@ -9,6 +9,14 @@ LTCOMMAND = xfs_fsr
 CFILES = xfs_fsr.c
 LLDLIBS = $(LIBHANDLE)
 
+ifeq ($(HAVE_GETMNTENT),yes)
+LCFLAGS += -DHAVE_GETMNTENT
+endif
+
+ifeq ($(HAVE_GETMNTINFO),yes)
+LCFLAGS += -DHAVE_GETMNTINFO
+endif
+
 default: depend $(LTCOMMAND)
 
 include $(BUILDRULES)
diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index c8ef18f..d7087d4 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -32,10 +32,6 @@
 #include <sys/statvfs.h>
 #include <sys/xattr.h>
 
-#ifdef HAVE_MNTENT
-#  include <mntent.h>
-#endif
-
 #ifndef XFS_XFLAG_NODEFRAG
 #define XFS_XFLAG_NODEFRAG 0x00002000 /* src dependancy, remove later */
 #endif
@@ -174,60 +170,69 @@ aborter(int unused)
 	exit(1);
 }
 
+
+
 /*
  * Check if the argument is either the device name or mountpoint of an XFS
  * filesystem.  Note that we do not care about bind mounted regular files
  * here - the code that handles defragmentation of invidual files takes care
  * of that.
  */
+
 static char *
-find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
+find_mountpoint_check(struct stat64 *sb, struct mntent *t, struct stat64 ms)
 {
-	struct mntent *t;
-	struct stat64 ms;
-	FILE *mtabp;
-	char *mntp = NULL;
+	if (S_ISDIR(sb->st_mode)) {		/* mount point */
+		if (stat64(t->mnt_dir, &ms) < 0)
+			return NULL;
+		if (sb->st_ino != ms.st_ino)
+			return NULL;
+		if (sb->st_dev != ms.st_dev)
+			return NULL;
+		if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
+			return NULL;
+	} else {				/* device */
+		struct stat64 sb2;
+
+		if (stat64(t->mnt_fsname, &ms) < 0)
+			return NULL;
+		if (sb->st_rdev != ms.st_rdev)
+			return NULL;
+		if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
+			return NULL;
 
-	mtabp = setmntent(mtab, "r");
-	if (!mtabp) {
-		fprintf(stderr, _("%s: cannot read %s\n"),
-			progname, mtab);
-		exit(1);
+		/*
+			* Make sure the mountpoint given by mtab is accessible
+			* before using it.
+			*/
+		if (stat64(t->mnt_dir, &sb2) < 0)
+			return NULL;
 	}
 
-	while ((t = getmntent(mtabp))) {
-		if (S_ISDIR(sb->st_mode)) {		/* mount point */
-			if (stat64(t->mnt_dir, &ms) < 0)
-				continue;
-			if (sb->st_ino != ms.st_ino)
-				continue;
-			if (sb->st_dev != ms.st_dev)
-				continue;
-			if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
-				continue;
-		} else {				/* device */
-			struct stat64 sb2;
+	return t->mnt_dir;
 
-			if (stat64(t->mnt_fsname, &ms) < 0)
-				continue;
-			if (sb->st_rdev != ms.st_rdev)
-				continue;
-			if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
-				continue;
+}
 
-			/*
-			 * Make sure the mountpoint given by mtab is accessible
-			 * before using it.
-			 */
-			if (stat64(t->mnt_dir, &sb2) < 0)
-				continue;
-		}
+static char *
+find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
+{
+	struct mntent_cursor cursor;
+	struct stat64 ms;
+	struct mntent t = {};
+	char *mntp = NULL;
 
-		mntp = t->mnt_dir;
+	if (platform_mntent_open(&cursor, mtab) != 0){
+		fprintf(stderr, "Error: can't get mntent entries.\n");
+		exit(1);
+	}
+		
+	while (platform_mntent_next(&cursor, &t) == 0) {
+		mntp = find_mountpoint_check(sb, &t, ms);
+		if (mntp == NULL)
+			continue;
 		break;
 	}
-
-	endmntent(mtabp);
+	platform_mntent_close(&cursor);
 	return mntp;
 }
 
@@ -405,18 +410,11 @@ usage(int ret)
 static void
 initallfs(char *mtab)
 {
-	FILE *fp;
 	struct mntent *mp;
 	int mi;
 	char *cp;
 	struct stat64 sb;
 
-	fp = setmntent(mtab, "r");
-	if (fp == NULL) {
-		fsrprintf(_("could not open mtab file: %s\n"), mtab);
-		exit(1);
-	}
-
 	/* malloc a number of descriptors, increased later if needed */
 	if (!(fsbase = (fsdesc_t *)malloc(fsbufsize * sizeof(fsdesc_t)))) {
 		fsrprintf(_("out of memory: %s\n"), strerror(errno));
@@ -427,7 +425,36 @@ initallfs(char *mtab)
 	/* find all rw xfs file systems */
 	mi = 0;
 	fs = fsbase;
+
+#if defined(HAVE_GETMNTENT)
+	FILE *fp;
+	fp = setmntent(mtab, "r");
+	if (fp == NULL) {
+		fsrprintf(_("could not open mtab file: %s\n"), mtab);
+		exit(1);
+	}
+
 	while ((mp = getmntent(fp))) {
+#elif defined(HAVE_GETMNTINFO)
+	struct statfs	*stats;
+	int error, i, count;
+	// because "t" is a pointer, but we don't need to use
+	// malloc for this usage
+	struct mntent mp_tmp;
+	mp = &mp_tmp;
+	error = 0;
+	if ((count = getmntinfo(&stats, 0)) < 0) {
+		fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
+				progname, strerror(errno));
+		exit(1);
+	}
+
+	for (i = 0; i < count; i++) {
+		mntinfo2mntent(&stats[i], mp);
+#else
+# error "How do I extract info about mounted filesystems on this platform?"
+#endif
+
 		int rw = 0;
 
 		if (strcmp(mp->mnt_type, MNTTYPE_XFS ) != 0 ||
@@ -479,7 +506,9 @@ initallfs(char *mtab)
 	}
 	numfs = mi;
 	fsend = (fsbase + numfs);
+#if defined(HAVE_GETMNTENT)
 	endmntent(fp);
+#endif
 	if (numfs == 0) {
 		fsrprintf(_("no rw xfs file systems in mtab: %s\n"), mtab);
 		exit(0);
diff --git a/include/darwin.h b/include/darwin.h
index 288ad1f..fd9384d 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -33,6 +33,8 @@
 #include <mach/mach_time.h>
 #include <inttypes.h>
 #include <stdio.h>
+#include <sys/mman.h>
+#include <sys/mount.h>
 
 #include <machine/endian.h>
 #define __BYTE_ORDER	BYTE_ORDER
@@ -218,7 +220,69 @@ static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
 
 /* FSR */
 
+#  include <sys/mount.h>
+#  include <sys/param.h>
+#include <sys/ucred.h>
+#include <errno.h>
 #define statvfs64 statfs
 #define		_PATH_MOUNTED   "/etc/mtab"
 
+struct mntent
+{
+	char *mnt_fsname;
+	char *mnt_dir;
+	char *mnt_type;
+	char *mnt_opts;
+	int mnt_freq;
+	int mnt_passno;
+};
+
+static inline void mntinfo2mntent (struct statfs * stats, struct mntent * mnt) {
+	mnt->mnt_fsname = stats->f_mntfromname;
+	mnt->mnt_dir = stats->f_mntonname;
+	mnt->mnt_type = stats->f_fstypename;
+}
+
+
+
+/**
+ * Abstraction of mountpoints.
+ */
+struct mntent_cursor {
+	FILE *mtabp;
+	struct statfs *stats;
+	int count;
+	int i;
+};
+
+/**
+ * OS X uses getmntinfo, which doesn't use a mtab file. So we just ignore it.
+ */
+static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
+{	
+	if ((cursor->count = getmntinfo(&cursor->stats, 0)) < 0) {
+		fprintf(stderr, "Error: getmntinfo() failed: %s\n", strerror(errno));
+		return 1;
+	}
+	cursor->i = 0;
+	return 0;
+}
+
+static inline int platform_mntent_next(struct mntent_cursor * cursor, struct mntent * t)
+{
+	if (cursor->i >= cursor->count){
+		return 1;
+	}
+	mntinfo2mntent(&cursor->stats[cursor->i], t);
+	cursor->i++;
+	return 0;
+
+}
+
+static inline void platform_mntent_close(struct mntent_cursor * cursor)
+{
+	cursor->count = 0;
+	cursor->i = 0;
+}
+
 #endif	/* __XFS_DARWIN_H__ */
diff --git a/include/freebsd.h b/include/freebsd.h
index 902b940..6bc9e61 100644
--- a/include/freebsd.h
+++ b/include/freebsd.h
@@ -26,6 +26,7 @@
 #include <libgen.h>
 #include <paths.h>
 #include <uuid.h>
+#include <mntent.h>
 
 #include <sys/endian.h>
 #define __BYTE_ORDER	BYTE_ORDER
@@ -147,4 +148,35 @@ platform_discard_blocks(int fd, uint64_t start, uint64_t len)
 	return 0;
 }
 
+/**
+ * Abstraction of mountpoints.
+ */
+struct mntent_cursor {
+	FILE *mtabp;
+};
+
+static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
+{
+	cursor->mtabp = setmntent(mtab, "r");
+	if (!cursor->mtabp) {
+		fprintf(stderr, "Error: cannot read %s\n", mtab);
+		return 1;
+	}
+	return 0;
+}
+
+static inline int platform_mntent_next(struct mntent_cursor * cursor, struct mntent * t)
+{
+	t = getmntent(cursor->mtabp);
+	if (t == NULL)
+		return 1;
+	return 0;
+}
+
+static inline void platform_mntent_close(struct mntent_cursor * cursor)
+{
+	endmntent(cursor->mtabp);
+}
+
+
 #endif	/* __XFS_FREEBSD_H__ */
diff --git a/include/gnukfreebsd.h b/include/gnukfreebsd.h
index 95c4c13..2740cae 100644
--- a/include/gnukfreebsd.h
+++ b/include/gnukfreebsd.h
@@ -31,6 +31,7 @@
 #include <ctype.h>
 #include <libgen.h>
 #include <paths.h>
+#include <mntent.h>
 
 #define constpp	char * const *
 
@@ -126,4 +127,34 @@ platform_discard_blocks(int fd, uint64_t start, uint64_t len)
 	return 0;
 }
 
+/**
+ * Abstraction of mountpoints.
+ */
+struct mntent_cursor {
+	FILE *mtabp;
+};
+
+static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
+{
+	cursor->mtabp = setmntent(mtab, "r");
+	if (!cursor->mtabp) {
+		fprintf(stderr, "Error: cannot read %s\n", mtab);
+		return 1;
+	}
+	return 0;
+}
+
+static inline int platform_mntent_next(struct mntent_cursor * cursor, struct mntent * t)
+{
+	t = getmntent(cursor->mtabp);
+	if (t == NULL)
+		return 1;
+	return 0;
+}
+
+static inline void platform_mntent_close(struct mntent_cursor * cursor)
+{
+	endmntent(cursor->mtabp);
+}
+
 #endif	/* __XFS_KFREEBSD_H__ */
diff --git a/include/irix.h b/include/irix.h
index 28564c8..cb9cce0 100644
--- a/include/irix.h
+++ b/include/irix.h
@@ -37,6 +37,7 @@
 #include <sys/sysmacros.h>
 #include <sys/fs/xfs_fsops.h>
 #include <sys/fs/xfs_itable.h>
+#include <mntent.h>
 
 #define __int8_t	char
 #define __int16_t	short
@@ -423,4 +424,35 @@ static __inline__ char * strsep(char **s, const char *ct)
 
 #define	XFS_XFLAG_NODEFRAG		0x00002000
 
+/**
+ * Abstraction of mountpoints.
+ */
+struct mntent_cursor {
+	FILE *mtabp;
+};
+
+static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
+{
+	cursor->mtabp = setmntent(mtab, "r");
+	if (!cursor->mtabp) {
+		fprintf(stderr, "Error: cannot read %s\n", mtab);
+		return 1;
+	}
+	return 0;
+}
+
+static inline int platform_mntent_next(struct mntent_cursor * cursor, struct mntent * t)
+{
+	t = getmntent(cursor->mtabp);
+	if (t == NULL)
+		return 1;
+	return 0;
+}
+
+static inline void platform_mntent_close(struct mntent_cursor * cursor)
+{
+	endmntent(cursor->mtabp);
+}
+
+
 #endif	/* __XFS_IRIX_H__ */
diff --git a/include/linux.h b/include/linux.h
index 8804c2d..437970b 100644
--- a/include/linux.h
+++ b/include/linux.h
@@ -30,6 +30,7 @@
 #include <endian.h>
 #include <stdbool.h>
 #include <asm/types.h>
+#include <mntent.h>
 
 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
 {
@@ -145,4 +146,34 @@ typedef __uint64_t	xfs_ino_t;
 typedef __uint32_t	xfs_dev_t;
 typedef __int64_t	xfs_daddr_t;
 
+/**
+ * Abstraction of mountpoints.
+ */
+struct mntent_cursor {
+	FILE *mtabp;
+};
+
+static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
+{
+	cursor->mtabp = setmntent(mtab, "r");
+	if (!cursor->mtabp) {
+		fprintf(stderr, "Error: cannot read %s\n", mtab);
+		return 1;
+	}
+	return 0;
+}
+
+static inline int platform_mntent_next(struct mntent_cursor * cursor, struct mntent * t)
+{
+	t = getmntent(cursor->mtabp);
+	if (t == NULL)
+		return 1;
+	return 0;
+}
+
+static inline void platform_mntent_close(struct mntent_cursor * cursor)
+{
+	endmntent(cursor->mtabp);
+}
+
 #endif	/* __XFS_LINUX_H__ */
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 12/14] xfsprogs: make fsr use mntinfo when there is no mntent
  2015-09-24 22:53       ` Dave Chinner
@ 2015-09-29 16:07         ` Jan Tulak
  0 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-29 16:07 UTC (permalink / raw)
  To: Dave Chinner; +Cc: xfs-oss


[-- Attachment #1.1: Type: text/plain, Size: 3403 bytes --]

On Fri, Sep 25, 2015 at 12:53 AM, Dave Chinner <david@fromorbit.com> wrote:

> On Thu, Sep 24, 2015 at 04:38:49PM +0200, Jan Tulak wrote:
> > On Wed, Sep 23, 2015 at 5:36 AM, Dave Chinner <david@fromorbit.com>
> wrote:
> >
> > > On Tue, Sep 15, 2015 at 11:59:22AM +0200, Jan Tulak wrote:
> > > > @@ -202,6 +205,27 @@ find_mountpoint(char *mtab, char *argname,
> struct
> > > stat64 *sb)
> > > >       }
> > > >
> > > >       while ((t = getmntent(mtabp))) {
> > > > +#elif defined(HAVE_GETMNTINFO)
> > > > +     struct statfs   *stats;
> > > > +     int error, i, count;
> > > > +     // because "t" is a pointer, but we don't need to use
> > > > +     // malloc for this usage
> > > > +     struct mntent t_tmp;
> > > > +     t = &t_tmp;
> > > > +
> > > > +
> > > > +     error = 0;
> > > > +     if ((count = getmntinfo(&stats, 0)) < 0) {
> > > > +             fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
> > > > +                             progname, strerror(errno));
> > > > +             return 0;
> > > > +     }
> > > > +
> > > > +     for (i = 0; i < count; i++) {
> > > > +             mntinfo2mntent(&stats[i], t);
> > > > +#else
> > > > +# error "How do I extract info about mounted filesystems on this
> > > platform?"
> > > > +#endif
> > >
> > > No, please don't do that. Having a loop iterator split across two
> > > separate defines is unmaintainable. Write two separate functions
> > > with the different loop iterators, then factor the common bit out
> > > of them into a single function.
> > >
> > >
> > I did a little refactoring to solve it. What I would like to ask ab​out
> is
> > this:
> > When I can put ifdef just inside of a function like fnc(void) { #ifdef...
> > #else ... #endif }, with little to no code outside of the ifdef, is it
> > better to put the ifdef outside, or keep it inside?
>
> The idea is that the "little differences" are put in functions that
> end up in include/<platform>.h or libxfs/<platform>.c, so there are
> no ifdefs in any of the application or library code. The build will
> automatically include the correct function on the given platform,
> and so the application code does not need such ifdefs at all.
>
> e.g. you could implement these functions to abstract the differences
> away from xfs_fsr and any other code that iterates the mount table:
>
> struct mntent_cursor {
>         /* variables needed to track iteration of the mtab */
> };
>
> platform_first_mntent()
> platform_next_mntent()
> platform_end_mntent()
>
> and so the code would look like:
>
>         struct mntent_cursor    cursor;
>
>         mntent = platform_first_mntent(&cursor)
>
>         do {
>                 /* process mntent */
>         } while (mntent = platform_next_mntent(&cursor, mntent));
>
>         platform_end_mntent(&cursor);
>
> This completely abstracts the differences related to the the mount
> table traversal, and allows the aplication level code to be written
> in a clean, easily maintainable fashion...
>

​So something like what I just posted? I added the same code that works for
Linux into other platforms other than OS X. ​

​Because as it was there before,  it either works on them, ​or no one care.
And I really don't have an idea how to test it on Irix... :-)

Cheers,
Jan

-- 
Jan Tulak
jtulak@redhat.com / jan@tulak.me

[-- Attachment #1.2: Type: text/html, Size: 5406 bytes --]

[-- Attachment #2: Type: text/plain, Size: 121 bytes --]

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 11/14 v2] xfsprogs: Add statvfs64 for osx
  2015-09-15  9:59 ` [PATCH 11/14] xfsprogs: Add statvfs64 for osx Jan Tulak
  2015-09-23  3:32   ` Dave Chinner
@ 2015-09-30  8:21   ` Jan Tulak
  1 sibling, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-30  8:21 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

UPDATE:
- removing unnecessary include lines (again)

Simply rename statvfs64 to statfs with a #define.
OSX version of statvfs is missing some members, so if the renaming
is in effect (stavfs64 is defined), don't try to use them and go
directly for the other member value.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 fsr/xfs_fsr.c        | 8 ++++++++
 include/builddefs.in | 2 +-
 include/darwin.h     | 5 +++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index e1b7bd6..c8ef18f 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -948,7 +948,11 @@ fsrfile_common(
 			fname, strerror(errno));
 		return -1;
 	}
+#ifndef statvfs64
 	bsize = vfss.f_frsize ? vfss.f_frsize : vfss.f_bsize;
+#else
+	bsize = vfss.f_bsize;
+#endif
 	if (statp->bs_blksize * statp->bs_blocks >
 	    vfss.f_bfree * bsize - minimumfree) {
 		fsrprintf(_("insufficient freespace for: %s: "
@@ -1728,7 +1732,11 @@ xfs_getrt(int fd, struct statvfs64 *sfbp)
 		close(fd);
 		return -1;
 	}
+#ifndef statvfs64
 	bsize = (sfbp->f_frsize ? sfbp->f_frsize : sfbp->f_bsize);
+#else
+	bsize = sfbp->f_bsize;
+#endif
 	factor = fsgeom.blocksize / bsize;         /* currently this is == 1 */
 	sfbp->f_bfree = (cnt.freertx * fsgeom.rtextsize) * factor;
 	return 0;
diff --git a/include/builddefs.in b/include/builddefs.in
index 25b8816..31e21ba 100644
--- a/include/builddefs.in
+++ b/include/builddefs.in
@@ -123,7 +123,7 @@ PCFLAGS = -D_GNU_SOURCE $(GCCFLAGS)
 endif
 ifeq ($(PKG_PLATFORM),darwin)
 PCFLAGS = $(GCCFLAGS)
-DEPENDFLAGS = -D__APPLE__
+DEPENDFLAGS = -D__APPLE__ -D_DARWIN_FEATURE_64_BIT_INODE
 endif
 ifeq ($(PKG_PLATFORM),irix)
 PLDLIBS = -ldisk -lgen
diff --git a/include/darwin.h b/include/darwin.h
index 0d2f175..288ad1f 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -216,4 +216,9 @@ static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
 	return getitimer(ITIMER_REAL, value);
 }
 
+/* FSR */
+
+#define statvfs64 statfs
+#define		_PATH_MOUNTED   "/etc/mtab"
+
 #endif	/* __XFS_DARWIN_H__ */
-- 
2.5.1

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 10/14 v2] xfsprogs: Add a timer implementation for OS X
  2015-09-15  9:59 ` [PATCH 10/14] xfsprogs: Add a timer implementation for OS X Jan Tulak
  2015-09-23  3:25   ` Dave Chinner
@ 2015-09-30  8:23   ` Jan Tulak
  1 sibling, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-09-30  8:23 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

UPDATE:
- Instead of ifndef just call memset to zero the structure universally.

OS X does not have the timer used in xfs_repair.
Add a simple implementation providing the required
capabilities.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 include/darwin.h  | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 repair/progress.c |  3 +--
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/include/darwin.h b/include/darwin.h
index 1409c91..0d2f175 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -28,6 +28,7 @@
 #include <sys/ioctl.h>
 #include <sys/mount.h>
 #include <sys/types.h>
+#include <sys/time.h>
 #include <ftw.h>
 #include <mach/mach_time.h>
 #include <inttypes.h>
@@ -168,4 +169,51 @@ platform_discard_blocks(int fd, uint64_t start, uint64_t len)
 	return 0;
 }
 
+/*
+ * POSIX timer replacement.
+ * It really just do the minimum we need for xfs_repair.
+ * Also, as setitimer can't create multiple timers,
+ * the timerid things are useless - we have only one ITIMER_REAL
+ * timer.
+ */
+#define CLOCK_REALTIME ITIMER_REAL
+#define itimerspec itimerval
+typedef uint64_t timer_t;
+typedef double   timer_c;
+typedef clock_id_t clockid_t;
+
+
+static inline int timer_create (clockid_t __clock_id,
+                         struct sigevent *__restrict __evp,
+                         timer_t *__restrict timer)
+{
+	// set something, to initialize the variable, just in case
+	*timer = 0;
+	return 0;
+}
+
+static inline int timer_settime (timer_t timerid, int flags,
+                          const struct itimerspec *__restrict timerspec,
+                          struct itimerspec *__restrict ovalue)
+{
+	return setitimer(ITIMER_REAL, timerspec, ovalue);
+}
+
+static inline int timer_delete (timer_t timerid)
+{
+	struct itimerspec timespec;
+
+	timespec.it_interval.tv_sec=0;
+	timespec.it_interval.tv_usec=0;
+	timespec.it_value.tv_sec=0;
+	timespec.it_value.tv_usec=0;
+
+	return setitimer(ITIMER_REAL, &timespec, NULL);
+}
+
+static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
+{
+	return getitimer(ITIMER_REAL, value);
+}
+
 #endif	/* __XFS_DARWIN_H__ */
diff --git a/repair/progress.c b/repair/progress.c
index 27cbaef..418b803 100644
--- a/repair/progress.c
+++ b/repair/progress.c
@@ -183,10 +183,9 @@ progress_rpt_thread (void *p)
 	 * Specify a repeating timer that fires each MSG_INTERVAL seconds.
 	 */
 
+	memset(&timespec, 0, sizeof(timespec));
 	timespec.it_value.tv_sec = msgp->interval;
-	timespec.it_value.tv_nsec = 0;
 	timespec.it_interval.tv_sec = msgp->interval;
-	timespec.it_interval.tv_nsec = 0;
 
 	if (timer_create (CLOCK_REALTIME, NULL, &timerid))
 		do_error(_("progress_rpt: cannot create timer\n"));
-- 
2.5.1

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 04/14 v2] xfsprogs: prefix XATTR_LIST_MAX with XFS_
  2015-09-15  9:59 ` [PATCH 04/14] xfsprogs: prefix XATTR_LIST_MAX with XFS_ Jan Tulak
  2015-09-23  3:15   ` Dave Chinner
@ 2015-10-07 11:17   ` Jan Tulak
  1 sibling, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-10-07 11:17 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

UPDATE:
- moved define from include/xfs.h to libxfs/xfs_fs.h

As we depends on XATTR_ value that is available only on some
platforms, prefix it with XFS_ and allow for an alternative value
in future.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 libhandle/handle.c | 4 ++--
 libhandle/jdm.c    | 4 ++--
 libxfs/xfs_fs.h    | 9 +++++++++
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/libhandle/handle.c b/libhandle/handle.c
index b1c0c10..7207186 100644
--- a/libhandle/handle.c
+++ b/libhandle/handle.c
@@ -397,8 +397,8 @@ attr_list_by_handle(
 	alhreq.buffer = buf;
 	alhreq.buflen = bufsize;
 	/* prevent needless EINVAL from the kernel */
-	if (alhreq.buflen > XATTR_LIST_MAX)
-		alhreq.buflen = XATTR_LIST_MAX;
+	if (alhreq.buflen > XFS_XATTR_LIST_MAX)
+		alhreq.buflen = XFS_XATTR_LIST_MAX;
 
 	error = xfsctl(path, fd, XFS_IOC_ATTRLIST_BY_HANDLE, &alhreq);
 
diff --git a/libhandle/jdm.c b/libhandle/jdm.c
index d804423..e52f5d8 100644
--- a/libhandle/jdm.c
+++ b/libhandle/jdm.c
@@ -168,8 +168,8 @@ jdm_attr_list(	jdm_fshandle_t *fshp,
 	int rval;
 
 	/* prevent needless EINVAL from the kernel */
-	if (bufsz > XATTR_LIST_MAX)
-		bufsz = XATTR_LIST_MAX;
+	if (bufsz > XFS_XATTR_LIST_MAX)
+		bufsz = XFS_XATTR_LIST_MAX;
 
 	jdm_fill_filehandle( &filehandle, fshandlep, statp );
 	rval = attr_list_by_handle (( void * )&filehandle,
diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h
index 89689c6..3a86d7d 100644
--- a/libxfs/xfs_fs.h
+++ b/libxfs/xfs_fs.h
@@ -490,6 +490,15 @@ typedef struct xfs_swapext
 #define XFS_FSOP_GOING_FLAGS_NOLOGFLUSH		0x2	/* don't flush log nor data */
 
 /*
+ * ioctl limits
+ */
+#ifdef XATTR_LIST_MAX
+#  define XFS_XATTR_LIST_MAX XATTR_LIST_MAX
+#else
+#  define XFS_XATTR_LIST_MAX 65536
+#endif
+
+/*
  * ioctl commands that are used by Linux filesystems
  */
 #define XFS_IOC_GETXFLAGS	FS_IOC_GETFLAGS
-- 
2.4.3

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 13/14] xfsprogs: Make mremap conditional
  2015-09-15  9:59 ` [PATCH 13/14] xfsprogs: Make mremap conditional Jan Tulak
@ 2015-10-13  4:42   ` Dave Chinner
  0 siblings, 0 replies; 35+ messages in thread
From: Dave Chinner @ 2015-10-13  4:42 UTC (permalink / raw)
  To: Jan Tulak; +Cc: xfs

On Tue, Sep 15, 2015 at 11:59:23AM +0200, Jan Tulak wrote:
> Don't build mremap (in xfs_io) on platforms where it has no support.
> 
> Signed-off-by: Jan Tulak <jtulak@redhat.com>

This doesn't define HAVE_REMAP as a build define in io/Makefile,
so always fails to build in mremap support. this leads to:

generic/030 2s ... [not run] xfs_io mremap support is missing

I've fixed this on commit.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 12/14 v2] xfsprogs: make fsr use mntinfo when there is no mntent
  2015-09-29 16:04   ` [PATCH 12/14 v2] " Jan Tulak
@ 2015-10-13  4:54     ` Dave Chinner
  2015-10-13  8:45       ` Jan Tulak
  2015-10-13  9:56     ` [PATCH 12/14 v3] " Jan Tulak
  1 sibling, 1 reply; 35+ messages in thread
From: Dave Chinner @ 2015-10-13  4:54 UTC (permalink / raw)
  To: Jan Tulak; +Cc: xfs

On Tue, Sep 29, 2015 at 06:04:13PM +0200, Jan Tulak wrote:
> UPDATE:
> - refactor ifdefs to platform_ functions
> 
> For what fsr needs, mntinfo can be used instead of mntent on some
> platforms. Exctract the platform-specific code to platform headers.
> 
> Signed-off-by: Jan Tulak <jtulak@redhat.com>

I haven't commited this patch - I think it still needs some work
to clean up....

>  static void
>  initallfs(char *mtab)
>  {
> -	FILE *fp;
>  	struct mntent *mp;
>  	int mi;
>  	char *cp;
>  	struct stat64 sb;
>  
> -	fp = setmntent(mtab, "r");
> -	if (fp == NULL) {
> -		fsrprintf(_("could not open mtab file: %s\n"), mtab);
> -		exit(1);
> -	}
> -
>  	/* malloc a number of descriptors, increased later if needed */
>  	if (!(fsbase = (fsdesc_t *)malloc(fsbufsize * sizeof(fsdesc_t)))) {
>  		fsrprintf(_("out of memory: %s\n"), strerror(errno));
> @@ -427,7 +425,36 @@ initallfs(char *mtab)
>  	/* find all rw xfs file systems */
>  	mi = 0;
>  	fs = fsbase;
> +
> +#if defined(HAVE_GETMNTENT)
> +	FILE *fp;
> +	fp = setmntent(mtab, "r");
> +	if (fp == NULL) {
> +		fsrprintf(_("could not open mtab file: %s\n"), mtab);
> +		exit(1);
> +	}
> +
>  	while ((mp = getmntent(fp))) {
> +#elif defined(HAVE_GETMNTINFO)
> +	struct statfs	*stats;
> +	int error, i, count;
> +	// because "t" is a pointer, but we don't need to use
> +	// malloc for this usage
> +	struct mntent mp_tmp;
> +	mp = &mp_tmp;
> +	error = 0;
> +	if ((count = getmntinfo(&stats, 0)) < 0) {
> +		fprintf(stderr, _("%s: getmntinfo() failed: %s\n"),
> +				progname, strerror(errno));
> +		exit(1);
> +	}
> +
> +	for (i = 0; i < count; i++) {
> +		mntinfo2mntent(&stats[i], mp);
> +#else
> +# error "How do I extract info about mounted filesystems on this platform?"
> +#endif

this stuff here. This iteration should be able to be done via the
cursor abstraction, such as by keeping the iteration information
within the cursor...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* Re: [PATCH 12/14 v2] xfsprogs: make fsr use mntinfo when there is no mntent
  2015-10-13  4:54     ` Dave Chinner
@ 2015-10-13  8:45       ` Jan Tulak
  0 siblings, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-10-13  8:45 UTC (permalink / raw)
  To: Dave Chinner; +Cc: xfs-oss


[-- Attachment #1.1: Type: text/plain, Size: 398 bytes --]

On Tue, Oct 13, 2015 at 6:54 AM, Dave Chinner <david@fromorbit.com> wrote:
>
> this stuff here. This iteration should be able to be done via the
> cursor abstraction, such as by keeping the iteration information
> within the cursor...
>
> ​Ah, sorry! I forgot to change the other #if...

​Fixing it right now.

Cheers,
Jan​



-- 
Jan Tulak
jtulak@redhat.com / jan@tulak.me

[-- Attachment #1.2: Type: text/html, Size: 1571 bytes --]

[-- Attachment #2: Type: text/plain, Size: 121 bytes --]

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

* [PATCH 12/14 v3] xfsprogs: make fsr use mntinfo when there is no mntent
  2015-09-29 16:04   ` [PATCH 12/14 v2] " Jan Tulak
  2015-10-13  4:54     ` Dave Chinner
@ 2015-10-13  9:56     ` Jan Tulak
  1 sibling, 0 replies; 35+ messages in thread
From: Jan Tulak @ 2015-10-13  9:56 UTC (permalink / raw)
  To: xfs; +Cc: Jan Tulak

UPDATE:
- refactor ifdefs to platform_ functions
- refactor also the other ifdef which I forgot to change before

For what fsr needs, mntinfo can be used instead of mntent on some
platforms. Exctract the platform-specific code to platform headers.

Signed-off-by: Jan Tulak <jtulak@redhat.com>
---
 fsr/Makefile          |   8 ++++
 fsr/xfs_fsr.c         | 111 +++++++++++++++++++++++++++-----------------------
 include/darwin.h      |  64 +++++++++++++++++++++++++++++
 include/freebsd.h     |  32 +++++++++++++++
 include/gnukfreebsd.h |  31 ++++++++++++++
 include/irix.h        |  32 +++++++++++++++
 include/linux.h       |  31 ++++++++++++++
 7 files changed, 259 insertions(+), 50 deletions(-)

diff --git a/fsr/Makefile b/fsr/Makefile
index a9d1bf6..d3521b2 100644
--- a/fsr/Makefile
+++ b/fsr/Makefile
@@ -9,6 +9,14 @@ LTCOMMAND = xfs_fsr
 CFILES = xfs_fsr.c
 LLDLIBS = $(LIBHANDLE)
 
+ifeq ($(HAVE_GETMNTENT),yes)
+LCFLAGS += -DHAVE_GETMNTENT
+endif
+
+ifeq ($(HAVE_GETMNTINFO),yes)
+LCFLAGS += -DHAVE_GETMNTINFO
+endif
+
 default: depend $(LTCOMMAND)
 
 include $(BUILDRULES)
diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c
index c8ef18f..fa7f8cf 100644
--- a/fsr/xfs_fsr.c
+++ b/fsr/xfs_fsr.c
@@ -32,10 +32,6 @@
 #include <sys/statvfs.h>
 #include <sys/xattr.h>
 
-#ifdef HAVE_MNTENT
-#  include <mntent.h>
-#endif
-
 #ifndef XFS_XFLAG_NODEFRAG
 #define XFS_XFLAG_NODEFRAG 0x00002000 /* src dependancy, remove later */
 #endif
@@ -180,54 +176,61 @@ aborter(int unused)
  * here - the code that handles defragmentation of invidual files takes care
  * of that.
  */
+
+static char *
+find_mountpoint_check(struct stat64 *sb, struct mntent *t, struct stat64 *ms)
+{
+	if (S_ISDIR(sb->st_mode)) {		/* mount point */
+		if (stat64(t->mnt_dir, &ms) < 0)
+			return NULL;
+		if (sb->st_ino != ms->st_ino)
+			return NULL;
+		if (sb->st_dev != ms->st_dev)
+			return NULL;
+		if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
+			return NULL;
+	} else {				/* device */
+		struct stat64 sb2;
+
+		if (stat64(t->mnt_fsname, &ms) < 0)
+			return NULL;
+		if (sb->st_rdev != ms->st_rdev)
+			return NULL;
+		if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
+			return NULL;
+
+		/*
+			* Make sure the mountpoint given by mtab is accessible
+			* before using it.
+			*/
+		if (stat64(t->mnt_dir, &sb2) < 0)
+			return NULL;
+	}
+
+	return t->mnt_dir;
+
+}
+
 static char *
 find_mountpoint(char *mtab, char *argname, struct stat64 *sb)
 {
-	struct mntent *t;
+	struct mntent_cursor cursor;
 	struct stat64 ms;
-	FILE *mtabp;
+	struct mntent t = {};
 	char *mntp = NULL;
 
-	mtabp = setmntent(mtab, "r");
-	if (!mtabp) {
-		fprintf(stderr, _("%s: cannot read %s\n"),
-			progname, mtab);
+	if (platform_mntent_open(&cursor, mtab) != 0){
+		fprintf(stderr, "Error: can't get mntent entries.\n");
 		exit(1);
 	}
 
-	while ((t = getmntent(mtabp))) {
-		if (S_ISDIR(sb->st_mode)) {		/* mount point */
-			if (stat64(t->mnt_dir, &ms) < 0)
-				continue;
-			if (sb->st_ino != ms.st_ino)
-				continue;
-			if (sb->st_dev != ms.st_dev)
-				continue;
-			if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
-				continue;
-		} else {				/* device */
-			struct stat64 sb2;
-
-			if (stat64(t->mnt_fsname, &ms) < 0)
-				continue;
-			if (sb->st_rdev != ms.st_rdev)
-				continue;
-			if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0)
-				continue;
-
-			/*
-			 * Make sure the mountpoint given by mtab is accessible
-			 * before using it.
-			 */
-			if (stat64(t->mnt_dir, &sb2) < 0)
-				continue;
-		}
-
-		mntp = t->mnt_dir;
+	while (platform_mntent_next(&cursor, &t) == 0) {
+		mntp = find_mountpoint_check(sb, &t, &ms);
+		if (mntp == NULL)
+			continue;
 		break;
 	}
-
-	endmntent(mtabp);
+	platform_mntent_close(&cursor);
 	return mntp;
 }
 
@@ -405,17 +408,13 @@ usage(int ret)
 static void
 initallfs(char *mtab)
 {
-	FILE *fp;
+	struct mntent_cursor cursor;
+	char *mntp = NULL;
 	struct mntent *mp;
 	int mi;
 	char *cp;
 	struct stat64 sb;
-
-	fp = setmntent(mtab, "r");
-	if (fp == NULL) {
-		fsrprintf(_("could not open mtab file: %s\n"), mtab);
-		exit(1);
-	}
+	struct stat64 ms;
 
 	/* malloc a number of descriptors, increased later if needed */
 	if (!(fsbase = (fsdesc_t *)malloc(fsbufsize * sizeof(fsdesc_t)))) {
@@ -427,7 +426,18 @@ initallfs(char *mtab)
 	/* find all rw xfs file systems */
 	mi = 0;
 	fs = fsbase;
-	while ((mp = getmntent(fp))) {
+
+	if (platform_mntent_open(&cursor, mtab) != 0){
+		fprintf(stderr, "Error: can't get mntent entries.\n");
+		exit(1);
+	}
+
+	while (platform_mntent_next(&cursor, &mp) == 0) {
+		mntp = find_mountpoint_check(&sb, &mp, &ms);
+		if (mntp == NULL)
+			continue;
+		break;
+
 		int rw = 0;
 
 		if (strcmp(mp->mnt_type, MNTTYPE_XFS ) != 0 ||
@@ -477,9 +487,10 @@ initallfs(char *mtab)
 		mi++;
 		fs++;
 	}
+	platform_mntent_close(&cursor);
+
 	numfs = mi;
 	fsend = (fsbase + numfs);
-	endmntent(fp);
 	if (numfs == 0) {
 		fsrprintf(_("no rw xfs file systems in mtab: %s\n"), mtab);
 		exit(0);
diff --git a/include/darwin.h b/include/darwin.h
index 288ad1f..fd9384d 100644
--- a/include/darwin.h
+++ b/include/darwin.h
@@ -33,6 +33,8 @@
 #include <mach/mach_time.h>
 #include <inttypes.h>
 #include <stdio.h>
+#include <sys/mman.h>
+#include <sys/mount.h>
 
 #include <machine/endian.h>
 #define __BYTE_ORDER	BYTE_ORDER
@@ -218,7 +220,69 @@ static inline int timer_gettime (timer_t timerid, struct itimerspec *value)
 
 /* FSR */
 
+#  include <sys/mount.h>
+#  include <sys/param.h>
+#include <sys/ucred.h>
+#include <errno.h>
 #define statvfs64 statfs
 #define		_PATH_MOUNTED   "/etc/mtab"
 
+struct mntent
+{
+	char *mnt_fsname;
+	char *mnt_dir;
+	char *mnt_type;
+	char *mnt_opts;
+	int mnt_freq;
+	int mnt_passno;
+};
+
+static inline void mntinfo2mntent (struct statfs * stats, struct mntent * mnt) {
+	mnt->mnt_fsname = stats->f_mntfromname;
+	mnt->mnt_dir = stats->f_mntonname;
+	mnt->mnt_type = stats->f_fstypename;
+}
+
+
+
+/**
+ * Abstraction of mountpoints.
+ */
+struct mntent_cursor {
+	FILE *mtabp;
+	struct statfs *stats;
+	int count;
+	int i;
+};
+
+/**
+ * OS X uses getmntinfo, which doesn't use a mtab file. So we just ignore it.
+ */
+static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
+{
+	if ((cursor->count = getmntinfo(&cursor->stats, 0)) < 0) {
+		fprintf(stderr, "Error: getmntinfo() failed: %s\n", strerror(errno));
+		return 1;
+	}
+	cursor->i = 0;
+	return 0;
+}
+
+static inline int platform_mntent_next(struct mntent_cursor * cursor, struct mntent * t)
+{
+	if (cursor->i >= cursor->count){
+		return 1;
+	}
+	mntinfo2mntent(&cursor->stats[cursor->i], t);
+	cursor->i++;
+	return 0;
+
+}
+
+static inline void platform_mntent_close(struct mntent_cursor * cursor)
+{
+	cursor->count = 0;
+	cursor->i = 0;
+}
+
 #endif	/* __XFS_DARWIN_H__ */
diff --git a/include/freebsd.h b/include/freebsd.h
index 902b940..6bc9e61 100644
--- a/include/freebsd.h
+++ b/include/freebsd.h
@@ -26,6 +26,7 @@
 #include <libgen.h>
 #include <paths.h>
 #include <uuid.h>
+#include <mntent.h>
 
 #include <sys/endian.h>
 #define __BYTE_ORDER	BYTE_ORDER
@@ -147,4 +148,35 @@ platform_discard_blocks(int fd, uint64_t start, uint64_t len)
 	return 0;
 }
 
+/**
+ * Abstraction of mountpoints.
+ */
+struct mntent_cursor {
+	FILE *mtabp;
+};
+
+static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
+{
+	cursor->mtabp = setmntent(mtab, "r");
+	if (!cursor->mtabp) {
+		fprintf(stderr, "Error: cannot read %s\n", mtab);
+		return 1;
+	}
+	return 0;
+}
+
+static inline int platform_mntent_next(struct mntent_cursor * cursor, struct mntent * t)
+{
+	t = getmntent(cursor->mtabp);
+	if (t == NULL)
+		return 1;
+	return 0;
+}
+
+static inline void platform_mntent_close(struct mntent_cursor * cursor)
+{
+	endmntent(cursor->mtabp);
+}
+
+
 #endif	/* __XFS_FREEBSD_H__ */
diff --git a/include/gnukfreebsd.h b/include/gnukfreebsd.h
index 95c4c13..2740cae 100644
--- a/include/gnukfreebsd.h
+++ b/include/gnukfreebsd.h
@@ -31,6 +31,7 @@
 #include <ctype.h>
 #include <libgen.h>
 #include <paths.h>
+#include <mntent.h>
 
 #define constpp	char * const *
 
@@ -126,4 +127,34 @@ platform_discard_blocks(int fd, uint64_t start, uint64_t len)
 	return 0;
 }
 
+/**
+ * Abstraction of mountpoints.
+ */
+struct mntent_cursor {
+	FILE *mtabp;
+};
+
+static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
+{
+	cursor->mtabp = setmntent(mtab, "r");
+	if (!cursor->mtabp) {
+		fprintf(stderr, "Error: cannot read %s\n", mtab);
+		return 1;
+	}
+	return 0;
+}
+
+static inline int platform_mntent_next(struct mntent_cursor * cursor, struct mntent * t)
+{
+	t = getmntent(cursor->mtabp);
+	if (t == NULL)
+		return 1;
+	return 0;
+}
+
+static inline void platform_mntent_close(struct mntent_cursor * cursor)
+{
+	endmntent(cursor->mtabp);
+}
+
 #endif	/* __XFS_KFREEBSD_H__ */
diff --git a/include/irix.h b/include/irix.h
index 28564c8..cb9cce0 100644
--- a/include/irix.h
+++ b/include/irix.h
@@ -37,6 +37,7 @@
 #include <sys/sysmacros.h>
 #include <sys/fs/xfs_fsops.h>
 #include <sys/fs/xfs_itable.h>
+#include <mntent.h>
 
 #define __int8_t	char
 #define __int16_t	short
@@ -423,4 +424,35 @@ static __inline__ char * strsep(char **s, const char *ct)
 
 #define	XFS_XFLAG_NODEFRAG		0x00002000
 
+/**
+ * Abstraction of mountpoints.
+ */
+struct mntent_cursor {
+	FILE *mtabp;
+};
+
+static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
+{
+	cursor->mtabp = setmntent(mtab, "r");
+	if (!cursor->mtabp) {
+		fprintf(stderr, "Error: cannot read %s\n", mtab);
+		return 1;
+	}
+	return 0;
+}
+
+static inline int platform_mntent_next(struct mntent_cursor * cursor, struct mntent * t)
+{
+	t = getmntent(cursor->mtabp);
+	if (t == NULL)
+		return 1;
+	return 0;
+}
+
+static inline void platform_mntent_close(struct mntent_cursor * cursor)
+{
+	endmntent(cursor->mtabp);
+}
+
+
 #endif	/* __XFS_IRIX_H__ */
diff --git a/include/linux.h b/include/linux.h
index 8804c2d..437970b 100644
--- a/include/linux.h
+++ b/include/linux.h
@@ -30,6 +30,7 @@
 #include <endian.h>
 #include <stdbool.h>
 #include <asm/types.h>
+#include <mntent.h>
 
 static __inline__ int xfsctl(const char *path, int fd, int cmd, void *p)
 {
@@ -145,4 +146,34 @@ typedef __uint64_t	xfs_ino_t;
 typedef __uint32_t	xfs_dev_t;
 typedef __int64_t	xfs_daddr_t;
 
+/**
+ * Abstraction of mountpoints.
+ */
+struct mntent_cursor {
+	FILE *mtabp;
+};
+
+static inline int platform_mntent_open(struct mntent_cursor * cursor, char *mtab)
+{
+	cursor->mtabp = setmntent(mtab, "r");
+	if (!cursor->mtabp) {
+		fprintf(stderr, "Error: cannot read %s\n", mtab);
+		return 1;
+	}
+	return 0;
+}
+
+static inline int platform_mntent_next(struct mntent_cursor * cursor, struct mntent * t)
+{
+	t = getmntent(cursor->mtabp);
+	if (t == NULL)
+		return 1;
+	return 0;
+}
+
+static inline void platform_mntent_close(struct mntent_cursor * cursor)
+{
+	endmntent(cursor->mtabp);
+}
+
 #endif	/* __XFS_LINUX_H__ */
-- 
2.6.0

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

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

end of thread, other threads:[~2015-10-13  9:56 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-15  9:59 [PATCH 00/14 v5] xfsprogs: Partial OSX support Jan Tulak
2015-09-15  9:59 ` [PATCH 01/14] xfsprogs: Add a way to compile without blkid Jan Tulak
2015-09-15  9:59 ` [PATCH 02/14] xfsprogs: Add XATTR_LIST_MAX to OS X headers Jan Tulak
2015-09-15  9:59 ` [PATCH 03/14] xfsprogs: avoid dependency on Linux XATTR_SIZE_MAX Jan Tulak
2015-09-23  3:09   ` Dave Chinner
2015-09-15  9:59 ` [PATCH 04/14] xfsprogs: prefix XATTR_LIST_MAX with XFS_ Jan Tulak
2015-09-23  3:15   ` Dave Chinner
2015-09-24  8:28     ` Jan Tulak
2015-09-24 22:41       ` Dave Chinner
2015-10-07 11:17   ` [PATCH 04/14 v2] " Jan Tulak
2015-09-15  9:59 ` [PATCH 05/14] xfsprogs: Add includes required for OS X builds (delta) Jan Tulak
2015-09-15  9:59 ` [PATCH 06/14] xfsprogs: Add autoconf check for fsetxattr call Jan Tulak
2015-09-15  9:59 ` [PATCH 07/14] xfsprogs: uuid changes for OS X Jan Tulak
2015-09-15  9:59 ` [PATCH 08/14] xfsprogs: Remove conflicting define " Jan Tulak
2015-09-15  9:59 ` [PATCH 09/14] xfsprogs: change nftw64 to nftw Jan Tulak
2015-09-15  9:59 ` [PATCH 10/14] xfsprogs: Add a timer implementation for OS X Jan Tulak
2015-09-23  3:25   ` Dave Chinner
2015-09-24  9:26     ` Jan Tulak
2015-09-30  8:23   ` [PATCH 10/14 v2] " Jan Tulak
2015-09-15  9:59 ` [PATCH 11/14] xfsprogs: Add statvfs64 for osx Jan Tulak
2015-09-23  3:32   ` Dave Chinner
2015-09-24  9:33     ` Jan Tulak
2015-09-30  8:21   ` [PATCH 11/14 v2] " Jan Tulak
2015-09-15  9:59 ` [PATCH 12/14] xfsprogs: make fsr use mntinfo when there is no mntent Jan Tulak
2015-09-23  3:36   ` Dave Chinner
2015-09-24 14:38     ` Jan Tulak
2015-09-24 22:53       ` Dave Chinner
2015-09-29 16:07         ` Jan Tulak
2015-09-29 16:04   ` [PATCH 12/14 v2] " Jan Tulak
2015-10-13  4:54     ` Dave Chinner
2015-10-13  8:45       ` Jan Tulak
2015-10-13  9:56     ` [PATCH 12/14 v3] " Jan Tulak
2015-09-15  9:59 ` [PATCH 13/14] xfsprogs: Make mremap conditional Jan Tulak
2015-10-13  4:42   ` Dave Chinner
2015-09-15  9:59 ` [PATCH 14/14] xfsprogs: rename lstat64 to lstat for OS X Jan Tulak

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.