Skip to contentSkip to conversation

xfsprogs: OS X partial support

PATCH In review Jan Tulak 3 participants 36 messages Aug 3, 2015 – Aug 17, 2015 Kbuild

lore
Share & tools
lore

Jan Tulak

author
#0 lore raw

v3 cover xfsprogs: OS X partial support

Hi folks.

All right, this is a third iteration of fixing the out-of-date OS X code in xfsprogs (4 years since the last touch).

Against v2, I made these changes:

- Patch 4/4 was broken to 8 smaller patches
- Issues in that patch were addressed
- Greatly enhanced commit message about LIST_ macros renaming

The last point is still open and may change, so I moved it into the last commit. First two commits were already reviewed, but I include them to keep their trace in this new numbering of the patchset.

Cheers,
Jan

Jan Tulak (11):
xfsprogs: Don't Make .po files with gettext disabled
xfsprogs: Use glibtoolize on osx
xfsprogs: undefined variable fix
xfsprogs: Add ifdef dirent checks where it was missing
xfsprogs: Change OS X-specific CFLAGS/LDFLAGS
xfsprogs: Add includes required for OS X builds
xfsprogs: missing and dummy calls for OS X support
xfsprogs: Add fls check into autoconf
xfsprogs: Add mntent.h check into autoconf
xfsprogs: replace obsolete memalign with posix_memalign
xfsprogs: Prefix LIST_... macros to XFS_LIST_...

 Makefile              |  19 +++++-
 configure.ac          |   2 +
 copy/xfs_copy.c       |   2 +-
 db/attrset.c          |   2 +-
 fsr/xfs_fsr.c         |  17 ++++--
 include/bitops.h      |   2 +
 include/builddefs.in  |  10 +++-
 include/darwin.h      | 159 ++++++++++++++++++++++++++++++++++++++++++++------
 include/freebsd.h     |   1 -
 include/gnukfreebsd.h |   1 -
 include/linux.h       |   1 -
 include/list.h        |   6 +-
 io/pread.c            |   4 +-
 io/readdir.c          |   4 ++
 libdisk/fstype.c      |   1 +
 libhandle/Makefile    |   4 ++
 libxcmd/paths.c       |   2 +-
 libxfs/rdwr.c         |  19 ++++--
 m4/package_libcdev.m4 |  26 +++++++++
 mkfs/xfs_mkfs.c       |   6 +-
 repair/incore.c       |   2 +-
 repair/incore_ino.c   |  13 ++++-
 repair/phase1.c       |   2 +-
 repair/phase6.c       |   2 +-
 repair/prefetch.c     |   7 +--
 repair/sb.c           |  10 ++--
 rtcp/xfs_rtcp.c       |   7 ++-
 27 files changed, 274 insertions(+), 57 deletions(-)
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#1 lore raw

PATCH v2 1/11 xfsprogs: Don't Make .po files with gettext disabled

(Already reviewed by Chris, but resubmiting
as the patchset itself was partially reworked.)

"po" target is added only if gettext binary is found. Without this patch, Make tried to build the target even with --enable-gettext=no configure option, which led to a failing build.

---
 Makefile | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
Makefile +5 -1
index 6d6803b..3da4d5d 100644
@@ -46,7 +46,11 @@ HDR_SUBDIRS = include libxfs
 DLIB_SUBDIRS = libxlog libxcmd libhandle libdisk
 LIB_SUBDIRS = libxfs $(DLIB_SUBDIRS)
 TOOL_SUBDIRS = copy db estimate fsck fsr growfs io logprint mkfs quota \
-		mdrestore repair rtcp m4 man doc po debian
+		mdrestore repair rtcp m4 man doc debian
+
+ifneq ("$(XGETTEXT)","")
+TOOL_SUBDIRS += po
+endif
 
 # include is listed last so it is processed last in clean rules.
 SUBDIRS = $(LIB_SUBDIRS) $(TOOL_SUBDIRS) include
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#2 lore raw

PATCH v3 3/11 xfsprogs: undefined variable fix

In reply to Jan Tulak

Typo fix, which wasn't catch earlier due to #ifdef branching. The 'rmnttomname' does not exists anywhere and looks like a hybrid between rmntfromname and rmntonname. And because the previous if has has 'fromname' on both arguments of realpath, I choose the same approach when fixing it.

---
 libxcmd/paths.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libxcmd/paths.c +1 -1
index c0b1ddb..b360617 100644
@@ -364,7 +364,7 @@ fs_table_initialise_mounts(
 			continue;
 		if (!realpath(stats[i].f_mntfromname, rmntfromname))
 			continue;
-		if (!realpath(stats[i].f_mntonname, rmnttomname)))
+		if (!realpath(stats[i].f_mntonname, rmntonname))
 			continue;
 
 		if (path &&
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#4 lore raw

PATCH v2 2/11 xfsprogs: Use glibtoolize on osx

In reply to Jan Tulak

(Already reviewed by Chris, but resubmiting
as the patchset itself was partially reworked.)

OS X doesn't have libtoolize binary by default, and the available$ ports are named "glibtoolize". Autodetect this issue.

---
 Makefile | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
Makefile +11 -2
index 3da4d5d..4abaaac 100644
@@ -52,6 +52,14 @@ ifneq ("$(XGETTEXT)","")
 TOOL_SUBDIRS += po
 endif
 
+# If we are on OS X, use glibtoolize from MacPorts, as OS X doesn't have
+# libtoolize binary itself.
+LIBTOOLIZE_TEST=$(shell libtoolize --version >/dev/null 2>&1 && echo found)
+LIBTOOLIZE_BIN=libtoolize
+ifneq ("$(LIBTOOLIZE_TEST)","found")
+LIBTOOLIZE_BIN=glibtoolize
+endif
+
 # include is listed last so it is processed last in clean rules.
 SUBDIRS = $(LIB_SUBDIRS) $(TOOL_SUBDIRS) include
 
@@ -85,13 +93,14 @@ else
 clean:	# if configure hasn't run, nothing to clean
 endif
 
+
 # Recent versions of libtool require the -i option for copying auxiliary
 # files (config.sub, config.guess, install-sh, ltmain.sh), while older
 # versions will copy those files anyway, and don't understand -i.
-LIBTOOLIZE_INSTALL = `libtoolize -n -i >/dev/null 2>/dev/null && echo -i`
+LIBTOOLIZE_INSTALL = `$(LIBTOOLIZE_BIN) -n -i >/dev/null 2>/dev/null && echo -i`
 
 configure:
-	libtoolize -c $(LIBTOOLIZE_INSTALL) -f
+	$(LIBTOOLIZE_BIN) -c $(LIBTOOLIZE_INSTALL) -f
 	cp include/install-sh .
 	aclocal -I m4
 	autoconf
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#5 lore raw

PATCH v3 4/11 xfsprogs: Add ifdef dirent checks where it was missing

In reply to Jan Tulak

Add check for _DIRENT_HAVED_RECLEN/_OFF to read_directory(). In dump_dirent() these checks already are used, but they were missing in read_directory.

---
 io/readdir.c | 4 ++++
 1 file changed, 4 insertions(+)
io/readdir.c +4 -0
index 20b8898..ed8f04d 100644
@@ -104,12 +104,16 @@ read_directory(
 		if (!dirent)
 			break;
 
+#ifdef _DIRENT_HAVE_D_RECLEN
 		*total += dirent->d_reclen;
+#endif
 		count++;
 
 		if (dump) {
 			dump_dirent(offset, dirent);
+#ifdef _DIRENT_HAVE_D_OFF
 			offset = dirent->d_off;
+#endif
 		}
 	}
 
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#6 lore raw

Re: [PATCH v3 04/11] xfsprogs: Add ifdef dirent checks where it was missing

io/readdir.c read_directory( · line 109

Quoted 11 lines
io/readdir.c +2 -0
index 20b8898..ed8f04d 100644
@@ -104,12 +104,16 @@ read_directory(
 		if (!dirent)
 			break;
 
+#ifdef _DIRENT_HAVE_D_RECLEN
 		*total += dirent->d_reclen;
+#endif

You probably want to use d_namen + sizeof(*dirent) to approimate the value if d_reclen doesn't exist.

io/readdir.c read_directory( · line 116

Quoted 7 lines
io/readdir.c +2 -0
 		count++;
 
 		if (dump) {
 			dump_dirent(offset, dirent);
+#ifdef _DIRENT_HAVE_D_OFF
 			offset = dirent->d_off;
+#endif

We're only using the offset for dumping the value, maybe setting it to 0 and adding a comment explaining it should go into the else branch here?

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#7 lore raw

Re: [PATCH v3 04/11] xfsprogs: Add ifdef dirent checks where it was missing

----- Original Message -----

Quoted 23 lines

From: "Christoph Hellwig" <[email protected]>
To: "Jan Tulak" <[email protected]>
Cc: [email protected], [email protected]
Sent: Tuesday, August 4, 2015 10:46:25 AM
Subject: Re: [PATCH v3 04/11] xfsprogs: Add ifdef dirent checks where it was missing

io/readdir.c read_directory( · line 109

Quoted 11 lines
io/readdir.c +2 -0
index 20b8898..ed8f04d 100644
@@ -104,12 +104,16 @@ read_directory(
 		if (!dirent)
 			break;
 
+#ifdef _DIRENT_HAVE_D_RECLEN
 		*total += dirent->d_reclen;
+#endif

You probably want to use d_namen + sizeof(*dirent) to approimate the value if d_reclen doesn't exist.

Quoted 2 lines
io/readdir.c +0 -0
 		count++;
 
Quoted 10 lines

io/readdir.c read_directory( · line 116

Quoted 5 lines
io/readdir.c +2 -0
 		if (dump) {
 			dump_dirent(offset, dirent);
+#ifdef _DIRENT_HAVE_D_OFF
 			offset = dirent->d_off;
+#endif

We're only using the offset for dumping the value, maybe setting it to 0 and adding a comment explaining it should go into the else branch here?

That sounds reasonable, sending an updated patch.

Thanks. :-)

Jan

Signature · 7 lines
Jan Tulak
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#8 lore raw

PATCH v4 4/11 xfsprogs: Add ifdef dirent checks where it was missing

In reply to Jan Tulak

Add check for _DIRENT_HAVED_RECLEN/_OFF to read_directory(). In dump_dirent() these checks already are used, but they were missing in read_directory.

---
 io/readdir.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
io/readdir.c +12 -0
index 20b8898..ddd62c9 100644
@@ -104,12 +104,24 @@ read_directory(
 		if (!dirent)
 			break;
 
+#ifdef _DIRENT_HAVE_D_RECLEN
 		*total += dirent->d_reclen;
+#else
+		*total += dirent->d_namlen + sizeof(*dirent);
+#endif
 		count++;
 
 		if (dump) {
 			dump_dirent(offset, dirent);
+#ifdef _DIRENT_HAVE_D_OFF
 			offset = dirent->d_off;
+#else
+			/* Some platforms don't have dirent->d_off, but because it is
+			 * used only for dumping the value, it should be safe to only
+			 * set it to zero in such case.
+			 */
+			offset = 0;
+#endif
 		}
 	}
 
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
Reviewed-by on v4 4/11
#9 lore raw

Re: [PATCH v4 04/11] xfsprogs: Add ifdef dirent checks where it was missing

Quoted 3 lines · Jan Tulak

Add check for _DIRENT_HAVED_RECLEN/_OFF to read_directory(). In dump_dirent() these checks already are used, but they were missing in read_directory.

Needs to be fixed to avoid > 80 char lines.

Otherwise looks good:

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#10 lore raw

Re: [PATCH v4 04/11] xfsprogs: Add ifdef dirent checks where it was missing

----- Original Message -----

Quoted 4 lines

From: "Christoph Hellwig" <[email protected]>

Needs to be fixed to avoid > 80 char lines.

I don't see any >80 char line in this patch. O_o The longest line is 73 in the code and 62 in commit message. Though... maybe it can be a tab width issue? I use four spaces for a tab...

Cheers,
Jan

Signature · 7 lines
Jan Tulak
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#11 lore raw

Re: [PATCH v4 04/11] xfsprogs: Add ifdef dirent checks where it was missing

Quoted 10 lines · Jan Tulak

----- Original Message -----

Quoted 4 lines

From: "Christoph Hellwig" <[email protected]>

Needs to be fixed to avoid > 80 char lines.

I don't see any >80 char line in this patch. O_o The longest line is 73 in the code and 62 in commit message. Though... maybe it can be a tab width issue? I use four spaces for a tab...

8 spaces to a tab, please. Same coding style rules as for writing kernel code. ;)

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#12 lore raw

Re: [PATCH v4 04/11] xfsprogs: Add ifdef dirent checks where it was missing

----- Original Message -----

Quoted 13 lines

From: "Dave Chinner" <[email protected]>
To: "Jan Tulak" <[email protected]>
Cc: "Christoph Hellwig" <[email protected]>, [email protected]
Sent: Wednesday, August 5, 2015 1:00:00 AM
Subject: Re: [PATCH v4 04/11] xfsprogs: Add ifdef dirent checks where it was missing

Quoted 6 lines · Jan Tulak

----- Original Message -----

Quoted 4 lines

From: "Christoph Hellwig" <[email protected]>

Needs to be fixed to avoid > 80 char lines.

Quoted 7 lines
Quoted 4 lines

I don't see any >80 char line in this patch. O_o The longest line is 73 in the code and 62 in commit message. Though... maybe it can be a tab width issue? I use four spaces for a tab...

8 spaces to a tab, please. Same coding style rules as for writing kernel code. ;)

All right, fixed patch sent. :-)

Cheers,
Jan

Signature · 7 lines
Jan Tulak
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#13 lore raw

PATCH v5 4/11 xfsprogs: Add ifdef dirent checks where it was missing

In reply to Jan Tulak

CHANGED: text width fix

Add check for _DIRENT_HAVED_RECLEN/_OFF to read_directory(). In dump_dirent() these checks already are used, but they were missing in read_directory.

---
 io/readdir.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
io/readdir.c +12 -0
index 7b0edbc..151b72e 100644
@@ -103,12 +103,24 @@ read_directory(
 		if (!dirent)
 			break;
 
+#ifdef _DIRENT_HAVE_D_RECLEN
 		*total += dirent->d_reclen;
+#else
+		*total += dirent->d_namlen + sizeof(*dirent);
+#endif
 		count++;
 
 		if (dump) {
 			dump_dirent(offset, dirent);
+#ifdef _DIRENT_HAVE_D_OFF
 			offset = dirent->d_off;
+#else
+			/* Some platforms don't have dirent->d_off, but because
+			 * it is used only for dumping the value, it should be
+			 * safe to only set it to zero in such case.
+			 */
+			offset = 0;
+#endif
 		}
 	}
 
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#14 lore raw

PATCH v3 5/11 xfsprogs: Change OS X-specific CFLAGS/LDFLAGS

In reply to Jan Tulak

OS X uses clang as a default compiler.
So remove incompatible options.

---
 include/builddefs.in | 2 +-
 libhandle/Makefile   | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)
include/builddefs.in +1 -1
index 7e9f53d..7f939f6 100644
@@ -119,7 +119,7 @@ ifeq ($(PKG_PLATFORM),gnukfreebsd)
 PCFLAGS = -D_GNU_SOURCE $(GCCFLAGS)
 endif
 ifeq ($(PKG_PLATFORM),darwin)
-PCFLAGS = -traditional-cpp $(GCCFLAGS)
+PCFLAGS = $(GCCFLAGS)
 DEPENDFLAGS = -D__APPLE__
 endif
 ifeq ($(PKG_PLATFORM),irix)
libhandle/Makefile +4 -0
index 865ca22..0b5e1ad 100644
@@ -10,7 +10,11 @@ LT_CURRENT = 1
 LT_REVISION = 3
 LT_AGE = 0
 
+ifeq ($(PKG_PLATFORM),darwin)
+LTLDFLAGS += -Wl,libhandle.sym
+else
 LTLDFLAGS += -Wl,--version-script,libhandle.sym
+endif
 
 CFILES = handle.c jdm.c
 LSRCFILES = libhandle.sym
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#16 lore raw

PATCH v3 6/11 xfsprogs: Add includes required for OS X builds

In reply to Jan Tulak
---
 include/darwin.h | 5 +++++
 libdisk/fstype.c | 1 +
 2 files changed, 6 insertions(+)
include/darwin.h +5 -0
index 30f0052..2b470b4 100644
@@ -24,6 +24,11 @@
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
+#include <sys/types.h>
+#include <ftw.h>
+#include <mach/mach_time.h>
+#include <inttypes.h>
+#include <stdio.h>
 
 #include <machine/endian.h>
 #define __BYTE_ORDER	BYTE_ORDER
libdisk/fstype.c +1 -0
index 548f297..c8bde34 100644
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include "fstype.h"
 
 /*
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#18 lore raw

PATCH v3 6/11 xfsprogs: Add includes required for OS X builds

UPDATE: updated for libdisk gone

---
 include/darwin.h | 8 ++++++++
 1 file changed, 8 insertions(+)
include/darwin.h +8 -0
index abdf4e3..8b5a661 100644
@@ -18,12 +18,20 @@
 #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>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
+#include <sys/types.h>
+#include <ftw.h>
+#include <mach/mach_time.h>
+#include <inttypes.h>
+#include <stdio.h>
 
 #include <machine/endian.h>
 #define __BYTE_ORDER	BYTE_ORDER
Signature · 6 lines
2.4.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#19 lore raw

PATCH v3 7/11 xfsprogs: missing and dummy calls for OS X support

In reply to Jan Tulak

Add and update various API, macros and types where is some change in OS X or xfsprogs. Most changes are in darwin.h.

Add dummy implementations where native support is nonexistent and the tools are not expected to work anyway, so all tools can be at least compiled.

---
 fsr/xfs_fsr.c    |   8 +++
 include/darwin.h | 153 +++++++++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 145 insertions(+), 16 deletions(-)
fsr/xfs_fsr.c +8 -0
index efc17a8..d8a4ece 100644
@@ -43,6 +43,14 @@
 #define _PATH_FSRLAST		"/var/tmp/.fsrlast_xfs"
 #define _PATH_PROC_MOUNTS	"/proc/mounts"
 
+#ifdef USE_DUMMY_XATTR
+	/* OS X has fsetxattr with different number of arguments.
+	 * Because it won't work anyway (no fstab/mtab and so on),
+	 * hijack the call to a dummy function so it can at least
+	 * compile.
+	 */
+#  define fsetxattr(a,b,c,d,e) dummy_fsetxattr(a,b,c,d,e)
+#endif
 
 char *progname;
 
include/darwin.h +137 -16

197 lines not on this page · raw message

Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#20 lore raw

PATCH v3 8/11 xfsprogs: Add fls check into autoconf

In reply to Jan Tulak

Add a check for fls call, and a replacement call
for platforms without fls.

---
 configure.ac          |  1 +
 include/bitops.h      |  2 ++
 include/builddefs.in  |  4 ++++
 m4/package_libcdev.m4 | 14 ++++++++++++++
 4 files changed, 21 insertions(+)
configure.ac +1 -0
index fe991cc..8f966a6 100644
@@ -113,6 +113,7 @@ AC_HAVE_PREADV
 AC_HAVE_SYNC_FILE_RANGE
 AC_HAVE_BLKID_TOPO($enable_blkid)
 AC_HAVE_READDIR
+AC_HAVE_FLS
 
 AC_CHECK_SIZEOF([long])
 AC_CHECK_SIZEOF([char *])
include/bitops.h +2 -0
index 930f64a..44599a7 100644
@@ -5,6 +5,7 @@
  * fls: find last bit set.
  */
 
+#ifndef HAVE_FLS
 static inline int fls(int x)
 {
 	int r = 32;
@@ -32,6 +33,7 @@ static inline int fls(int x)
 	}
 	return r;
 }
+#endif /* HAVE_FLS */
 
 static inline int fls64(__u64 x)
 {
include/builddefs.in +4 -0
index 7f939f6..9feb096 100644
@@ -104,6 +104,7 @@ HAVE_FIEMAP = @have_fiemap@
 HAVE_PREADV = @have_preadv@
 HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
 HAVE_READDIR = @have_readdir@
+HAVE_FLS = @have_fls@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
 #	   -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
@@ -131,6 +132,9 @@ PLDLIBS = -L/usr/local/lib -lintl
 PCFLAGS = -I/usr/local/include $(GCCFLAGS)
 DEPENDFLAGS = -D__FreeBSD__
 endif
+ifeq ($(HAVE_FLS),yes)
+LCFLAGS+= -DHAVE_FLS
+endif
 
 GCFLAGS = $(OPTIMIZER) $(DEBUG) \
 	  -DVERSION=\"$(PKG_VERSION)\" -DLOCALEDIR=\"$(PKG_LOCALE_DIR)\"  \
m4/package_libcdev.m4 +14 -0
index 919ae0a..d7f37ca 100644
@@ -202,3 +202,17 @@ AC_DEFUN([AC_HAVE_READDIR],
     AC_SUBST(have_readdir)
   ])
 
+#
+# Check if we have a flc call (Mac OS X)
+#
+AC_DEFUN([AC_HAVE_FLS],
+  [ AC_MSG_CHECKING([for fls])
+    AC_TRY_LINK([
+#include <string.h>
+    ], [
+         fls(0);
+    ], have_fls=yes
+       AC_MSG_RESULT(yes),
+       AC_MSG_RESULT(no))
+    AC_SUBST(have_fls)
+  ])
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#22 lore raw

Re: [PATCH v3 08/11] xfsprogs: Add fls check into autoconf

----- Original Message -----

Quoted 6 lines

From: "Christoph Hellwig" <[email protected]>
To: "Jan Tulak" <[email protected]>
Cc: [email protected], [email protected]
Sent: Tuesday, August 4, 2015 1:21:03 PM
Subject: Re: [PATCH v3 08/11] xfsprogs: Add fls check into autoconf

Quoted 8 lines

Can't you just use something like:

AC_CHECK_DECL([fls],

        [AC_DEFINE([HAVE_FLS_PROTOTYPE], [1],
	 [Define to 1 if have fls prototype])],
	 [],
	 [#include <string.h>])

You mean to replace the entire autoconf part of the patch with this? I will try it. Autoconf is still a bit of a black magic for me, so I used the already existing checks. :-)

Cheers,
Jan

Signature · 7 lines
Jan Tulak
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#23 lore raw

Re: [PATCH v3 08/11] xfsprogs: Add fls check into autoconf

Quoted 18 lines · Jan Tulak

----- Original Message -----

Quoted 6 lines

From: "Christoph Hellwig" <[email protected]>
To: "Jan Tulak" <[email protected]>
Cc: [email protected], [email protected]
Sent: Tuesday, August 4, 2015 1:21:03 PM
Subject: Re: [PATCH v3 08/11] xfsprogs: Add fls check into autoconf

Quoted 8 lines

Can't you just use something like:

AC_CHECK_DECL([fls],

        [AC_DEFINE([HAVE_FLS_PROTOTYPE], [1],
       [Define to 1 if have fls prototype])],
       [],
       [#include <string.h>])
Quoted 4 lines

You mean to replace the entire autoconf part of the patch with this? I will try it. Autoconf is still a bit of a black magic for me, so I used the already existing checks. :-)

Hi Chris,
did you want the result to be this? (I didn't get any clarification of what you mean, so I'm asking again. :-) )

#
# Check if we have a flc call (Mac OS X)
#
AC_DEFUN([AC_HAVE_FLS],
[ AC_CHECK_DECL([fls],

       have_fls=yes,
       [],
       [#include <string.h>]
       )
    AC_SUBST(have_fls)

])

Cheers,
Jan

Signature · 2 lines
Jan Tulak
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#24 lore raw

PATCH v4 3/11 xfsprogs: Add fls check into autoconf

In reply to Jan Tulak

UPDATE: Autoconf change. Hopefully this is what Chris meant.

---
 configure.ac          |  1 +
 include/bitops.h      |  2 ++
 include/builddefs.in  |  4 ++++
 m4/package_libcdev.m4 | 12 ++++++++++++
 4 files changed, 19 insertions(+)
configure.ac +1 -0
index 0aba90c..abb7904 100644
@@ -116,6 +116,7 @@ AC_HAVE_FIEMAP
 AC_HAVE_PREADV
 AC_HAVE_SYNC_FILE_RANGE
 AC_HAVE_MNTENT
+AC_HAVE_FLS
 AC_HAVE_BLKID_TOPO
 AC_HAVE_READDIR
 
include/bitops.h +2 -0
index 930f64a..44599a7 100644
@@ -5,6 +5,7 @@
  * fls: find last bit set.
  */
 
+#ifndef HAVE_FLS
 static inline int fls(int x)
 {
 	int r = 32;
@@ -32,6 +33,7 @@ static inline int fls(int x)
 	}
 	return r;
 }
+#endif /* HAVE_FLS */
 
 static inline int fls64(__u64 x)
 {
include/builddefs.in +4 -0
index e522243..8851956 100644
@@ -104,6 +104,7 @@ HAVE_PREADV = @have_preadv@
 HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
 HAVE_READDIR = @have_readdir@
 HAVE_MNTENT = @have_mntent@
+HAVE_FLS = @have_fls@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
 #	   -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
@@ -131,6 +132,9 @@ PLDLIBS = -L/usr/local/lib -lintl
 PCFLAGS = -I/usr/local/include $(GCCFLAGS)
 DEPENDFLAGS = -D__FreeBSD__
 endif
+ifeq ($(HAVE_FLS),yes)
+LCFLAGS+= -DHAVE_FLS
+endif
 ifeq ($(HAVE_MNTENT),yes)
 PCFLAGS+= -DHAVE_MNTENT
 endif
m4/package_libcdev.m4 +12 -0
index 75aa61e..4a96374 100644
@@ -203,6 +203,18 @@ AC_DEFUN([AC_HAVE_READDIR],
   ])
 
 #
+# Check if we have a flc call (Mac OS X)
+#
+AC_DEFUN([AC_HAVE_FLS],
+  [ AC_CHECK_DECL([fls],
+       have_fls=yes,
+       [],
+       [#include <string.h>]
+       )
+    AC_SUBST(have_fls)
+  ])
+
+#
 # Check if there is mntent.h
 #
 AC_DEFUN([AC_HAVE_MNTENT],
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#25 lore raw

PATCH v3 9/11 xfsprogs: Add mntent.h check into autoconf

In reply to Jan Tulak
---
 configure.ac          |  1 +
 fsr/xfs_fsr.c         |  6 +++---
 include/builddefs.in  |  4 ++++
 m4/package_libcdev.m4 | 12 ++++++++++++
 4 files changed, 20 insertions(+), 3 deletions(-)
configure.ac +1 -0
index 8f966a6..e2d395b 100644
@@ -113,6 +113,7 @@ AC_HAVE_PREADV
 AC_HAVE_SYNC_FILE_RANGE
 AC_HAVE_BLKID_TOPO($enable_blkid)
 AC_HAVE_READDIR
+AC_HAVE_MNTENT
 AC_HAVE_FLS
 
 AC_CHECK_SIZEOF([long])
fsr/xfs_fsr.c +3 -3
index d8a4ece..12eb172 100644
@@ -25,16 +25,16 @@
 
 #include <fcntl.h>
 #include <errno.h>
-#include <malloc.h>
-#include <mntent.h>
 #include <syslog.h>
 #include <signal.h>
 #include <sys/ioctl.h>
 #include <sys/wait.h>
-#include <sys/vfs.h>
 #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 */
include/builddefs.in +4 -0
index 9feb096..1132f26 100644
@@ -104,6 +104,7 @@ HAVE_FIEMAP = @have_fiemap@
 HAVE_PREADV = @have_preadv@
 HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
 HAVE_READDIR = @have_readdir@
+HAVE_MNTENT = @have_mntent@
 HAVE_FLS = @have_fls@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
@@ -135,6 +136,9 @@ endif
 ifeq ($(HAVE_FLS),yes)
 LCFLAGS+= -DHAVE_FLS
 endif
+ifeq ($(HAVE_MNTENT),yes)
+PCFLAGS+= -DHAVE_MNTENT
+endif
 
 GCFLAGS = $(OPTIMIZER) $(DEBUG) \
 	  -DVERSION=\"$(PKG_VERSION)\" -DLOCALEDIR=\"$(PKG_LOCALE_DIR)\"  \
m4/package_libcdev.m4 +12 -0
index d7f37ca..bb7bcdb 100644
@@ -216,3 +216,15 @@ AC_DEFUN([AC_HAVE_FLS],
        AC_MSG_RESULT(no))
     AC_SUBST(have_fls)
   ])
+
+#
+# Check if there is mntent.h
+#
+AC_DEFUN([AC_HAVE_MNTENT],
+  [ AC_MSG_CHECKING([for mntent])
+    AC_CHECK_HEADERS(mntent.h,
+    have_mntent=yes
+    AC_MSG_RESULT(yes),
+    AC_MSG_RESULT(no))
+    AC_SUBST(have_mntent)
+  ])
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#27 lore raw

PATCH v4 9/11 xfsprogs: Add mntent.h check into autoconf

UPDATE: Autoconf change. Hopefully this is what Chris meant.

---
 configure.ac          | 1 +
 fsr/xfs_fsr.c         | 6 +++---
 include/builddefs.in  | 4 ++++
 m4/package_libcdev.m4 | 8 ++++++++
 4 files changed, 16 insertions(+), 3 deletions(-)
configure.ac +1 -0
index 530650b..0aba90c 100644
@@ -115,6 +115,7 @@ AC_HAVE_FALLOCATE
 AC_HAVE_FIEMAP
 AC_HAVE_PREADV
 AC_HAVE_SYNC_FILE_RANGE
+AC_HAVE_MNTENT
 AC_HAVE_BLKID_TOPO
 AC_HAVE_READDIR
 
fsr/xfs_fsr.c +3 -3
index b4ff136..4912b73 100644
@@ -25,16 +25,16 @@
 
 #include <fcntl.h>
 #include <errno.h>
-#include <malloc.h>
-#include <mntent.h>
 #include <syslog.h>
 #include <signal.h>
 #include <sys/ioctl.h>
 #include <sys/wait.h>
-#include <sys/vfs.h>
 #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 */
include/builddefs.in +4 -0
index c644a17..e522243 100644
@@ -103,6 +103,7 @@ HAVE_FIEMAP = @have_fiemap@
 HAVE_PREADV = @have_preadv@
 HAVE_SYNC_FILE_RANGE = @have_sync_file_range@
 HAVE_READDIR = @have_readdir@
+HAVE_MNTENT = @have_mntent@
 
 GCCFLAGS = -funsigned-char -fno-strict-aliasing -Wall 
 #	   -Wbitwise -Wno-transparent-union -Wno-old-initializer -Wno-decl
@@ -130,6 +131,9 @@ PLDLIBS = -L/usr/local/lib -lintl
 PCFLAGS = -I/usr/local/include $(GCCFLAGS)
 DEPENDFLAGS = -D__FreeBSD__
 endif
+ifeq ($(HAVE_MNTENT),yes)
+PCFLAGS+= -DHAVE_MNTENT
+endif
 
 GCFLAGS = $(OPTIMIZER) $(DEBUG) \
 	  -DVERSION=\"$(PKG_VERSION)\" -DLOCALEDIR=\"$(PKG_LOCALE_DIR)\"  \
m4/package_libcdev.m4 +8 -0
index 919ae0a..75aa61e 100644
@@ -202,3 +202,11 @@ AC_DEFUN([AC_HAVE_READDIR],
     AC_SUBST(have_readdir)
   ])
 
+#
+# Check if there is mntent.h
+#
+AC_DEFUN([AC_HAVE_MNTENT],
+  [ AC_CHECK_HEADERS(mntent.h,
+    have_mntent=yes)
+    AC_SUBST(have_mntent)
+  ])
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#28 lore raw

Re: [PATCH v4 09/11] xfsprogs: Add mntent.h check into autoconf

This looks mostly fine. I think you could just add the AC_CHECK_HEADERS directly to configure.ac, but otherwise it's exactly what I though.

Can you please resend all your pending patches in a single series, and move the UPDATES: lines and other internal changelogs to the cover letter instead of the patch descriptions?

Thanks for doing this work!

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#29 lore raw

Re: [PATCH v4 09/11] xfsprogs: Add mntent.h check into autoconf

Quoted 4 lines · Christoph Hellwig

This looks mostly fine. I think you could just add the AC_CHECK_HEADERS directly to configure.ac, but otherwise it's exactly what I though.

In configure.ac, there are no direct checks for headers, just calls of all the various
AC_HAVE_*. I'm not sure it is a good idea to mix now. Unless you think that all
the functions should be moved into configure.ac from the m4/ directory.

Quoted 6 lines

Can you please resend all your pending patches in a single series, and move the UPDATES: lines and other internal changelogs to the cover letter instead of the patch descriptions?

Thanks for doing this work!

Sure, I'll send it again as a whole. And np. :-)

Signature · 2 lines
Jan Tulak
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs

author
#30 lore raw

PATCH v3 10/11 xfsprogs: replace obsolete memalign with posix_memalign

In reply to Jan Tulak

Memalign from <malloc.h> was marked obsolete in favor of a posix variant from <stdlib.h>. So replace all calls and remove <malloc.h> includes. This also enhances support on other posix platforms, which doesn't have <malloc.h>.

Because posix_memalign returns any error as a return code, not in errno, change relevant checks in code (and add a missing one).

---
 copy/xfs_copy.c       |  2 +-
 db/attrset.c          |  2 +-
 fsr/xfs_fsr.c         |  3 ++-
 include/darwin.h      |  1 -
 include/freebsd.h     |  1 -
 include/gnukfreebsd.h |  1 -
 include/linux.h       |  1 -
 io/pread.c            |  4 ++--
 libxfs/rdwr.c         | 19 +++++++++++++++----
 mkfs/xfs_mkfs.c       |  6 +++++-
 repair/incore.c       |  2 +-
 repair/incore_ino.c   | 13 ++++++++++---
 repair/phase1.c       |  2 +-
 repair/prefetch.c     |  7 +++----
 repair/sb.c           | 10 +++++-----
 rtcp/xfs_rtcp.c       |  7 ++++++-
 16 files changed, 52 insertions(+), 29 deletions(-)
copy/xfs_copy.c +1 -1
index 44a32e8..5badd74 100644
@@ -332,7 +332,7 @@ wbuf *
 wbuf_init(wbuf *buf, int data_size, int data_align, int min_io_size, int id)
 {
 	ASSERT(data_size % BBSIZE == 0);
-	while ((buf->data = memalign(data_align, data_size)) == NULL) {
+	while (posix_memalign((void**)&(buf->data), data_align, data_size)) {
 		data_size >>= 1;
 		if (data_size < min_io_size)
 			return NULL;
db/attrset.c +1 -1
index 1afadd2..3e293be 100644
@@ -141,7 +141,7 @@ attr_set_f(
 	name = argv[optind];
 
 	if (valuelen) {
-		value = (char *)memalign(getpagesize(), valuelen);
+		posix_memalign((void**)&value, getpagesize(), valuelen);
 		if (!value) {
 			dbprintf(_("cannot allocate buffer (%d)\n"), valuelen);
 			goto out;
fsr/xfs_fsr.c +2 -1
index 12eb172..44626ba 100644
@@ -1306,7 +1306,8 @@ packfile(char *fname, char *tname, int fd,
 			dio.d_maxiosz, pagesize);
 	}
 
-	if (!(fbuf = (char *)memalign(dio.d_mem, blksz_dio))) {
+	posix_memalign((void **)&fbuf, dio.d_mem, blksz_dio);
+	if (!fbuf) {
 		fsrprintf(_("could not allocate buf: %s\n"), tname);
 		goto out;
 	}
include/darwin.h +0 -1
index caec897..34264f9 100644
@@ -129,7 +129,6 @@ typedef int64_t		xfs_daddr_t;
 #define pwrite64	pwrite
 #define ftruncate64	ftruncate
 #define fdatasync	fsync
-#define memalign(a,sz)	valloc(sz)
 
 #define O_LARGEFILE     0
 #ifndef O_DIRECT
include/freebsd.h +0 -1
index e59b1e8..b4051ea 100644
@@ -40,7 +40,6 @@
 #define pwrite64	pwrite
 #define pread64		pread
 #define fdatasync	fsync
-#define memalign(a,sz)	valloc(sz)
 
 #define constpp	char * const *
 
include/gnukfreebsd.h +0 -1
index f2e1bf5..f9c0c15 100644
@@ -22,7 +22,6 @@
 #include <sys/vfs.h>
 #include <sys/ioctl.h>
 #include <sys/sysmacros.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <endian.h>
 #include <sys/stat.h>
include/linux.h +0 -1
index 31c077a..2abda79 100644
@@ -24,7 +24,6 @@
 #include <sys/sysmacros.h>
 #include <sys/stat.h>
 #include <inttypes.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <endian.h>
 #include <stdbool.h>
io/pread.c +2 -2
index 280cc9d..2dd5b7a 100644
@@ -78,7 +78,7 @@ alloc_iovec(
 
 	buffersize = 0;
 	for (i = 0; i < vectors; i++) {
-		iov[i].iov_base = memalign(pagesize, bsize);
+		posix_memalign((void**)&(iov[i].iov_base), pagesize, bsize);
 		if (!iov[i].iov_base) {
 			perror("memalign");
 			goto unwind;
@@ -109,7 +109,7 @@ alloc_buffer(
 	if (bsize > highwater) {
 		if (buffer)
 			free(buffer);
-		buffer = memalign(pagesize, bsize);
+		posix_memalign((void**)&buffer, pagesize, bsize);
 		if (!buffer) {
 			perror("memalign");
 			highwater = buffersize = 0;
libxfs/rdwr.c +15 -4
index 4e0c75b..d75bf1c 100644
@@ -74,12 +74,18 @@ libxfs_device_zero(struct xfs_buftarg *btp, xfs_daddr_t start, uint len)
 	ssize_t		zsize, bytes;
 	char		*z;
 	int		fd;
+	int ret;
 
 	zsize = min(BDSTRAT_SIZE, BBTOB(len));
-	if ((z = memalign(libxfs_device_alignment(), zsize)) == NULL) {
+	ret = posix_memalign(
+						(void **)&z,
+						libxfs_device_alignment(),
+						zsize
+					);
+	if (!z) {
 		fprintf(stderr,
 			_("%s: %s can't memalign %d bytes: %s\n"),
-			progname, __FUNCTION__, (int)zsize, strerror(errno));
+			progname, __FUNCTION__, (int)zsize, strerror(ret));
 		exit(1);
 	}
 	memset(z, 0, zsize);
@@ -409,6 +415,7 @@ static void
 __initbuf(xfs_buf_t *bp, struct xfs_buftarg *btp, xfs_daddr_t bno,
 		unsigned int bytes)
 {
+	int ret;
 	bp->b_flags = 0;
 	bp->b_bn = bno;
 	bp->b_bcount = bytes;
@@ -416,12 +423,16 @@ __initbuf(xfs_buf_t *bp, struct xfs_buftarg *btp, xfs_daddr_t bno,
 	bp->b_target = btp;
 	bp->b_error = 0;
 	if (!bp->b_addr)
-		bp->b_addr = memalign(libxfs_device_alignment(), bytes);
+		ret = posix_memalign(
+							(void**)&(bp->b_addr),
+							libxfs_device_alignment(),
+							bytes
+						);
 	if (!bp->b_addr) {
 		fprintf(stderr,
 			_("%s: %s can't memalign %u bytes: %s\n"),
 			progname, __FUNCTION__, bytes,
-			strerror(errno));
+			strerror(ret));
 		exit(1);
 	}
 	memset(bp->b_addr, 0, bytes);
mkfs/xfs_mkfs.c +5 -1
index 11e9f4b..a0273f7 100644
@@ -856,7 +856,11 @@ zero_old_xfs_structures(
 	 * read in existing filesystem superblock, use its geometry
 	 * settings and zero the existing secondary superblocks.
 	 */
-	buf = memalign(libxfs_device_alignment(), new_sb->sb_sectsize);
+	posix_memalign(
+				(void**)&buf,
+				libxfs_device_alignment(),
+				new_sb->sb_sectsize
+			);
 	if (!buf) {
 		fprintf(stderr,
 	_("error reading existing superblock -- failed to memalign buffer\n"));
repair/incore.c +1 -1
index d5ecfd6..57cbeb6 100644
@@ -224,7 +224,7 @@ init_rt_bmap(
 	rt_bmap_size = roundup(mp->m_sb.sb_rextents / (NBBY / XR_BB),
 			       sizeof(__uint64_t));
 
-	rt_bmap = memalign(sizeof(__uint64_t), rt_bmap_size);
+	posix_memalign((void**)&rt_bmap, sizeof(__uint64_t), rt_bmap_size);
 	if (!rt_bmap) {
 		do_error(
 	_("couldn't allocate realtime block map, size = %" PRIu64 "\n"),
repair/incore_ino.c +10 -3
index 7e19657..71d6d4c 100644
@@ -626,8 +626,11 @@ set_inode_parent(
 			irec->ino_un.plist = ptbl;
 
 		ptbl->pmask = 1LL << offset;
-		ptbl->pentries = (xfs_ino_t*)memalign(sizeof(xfs_ino_t),
-							sizeof(xfs_ino_t));
+		posix_memalign(
+					(void**)&(ptbl->pentries),
+					sizeof(xfs_ino_t),
+					sizeof(xfs_ino_t)
+				);
 		if (!ptbl->pentries)
 			do_error(_("couldn't memalign pentries table\n"));
 #ifdef DEBUG
@@ -673,7 +676,11 @@ set_inode_parent(
 #endif
 	ASSERT(cnt >= target);
 
-	tmp = (xfs_ino_t*)memalign(sizeof(xfs_ino_t), (cnt + 1) * sizeof(xfs_ino_t));
+	posix_memalign(
+				(void**)&tmp,
+				sizeof(xfs_ino_t), 
+				(cnt + 1) * sizeof(xfs_ino_t)
+			);
 	if (!tmp)
 		do_error(_("couldn't memalign pentries table\n"));
 
repair/phase1.c +1 -1
index bd9adcb..20d7b24 100644
@@ -35,7 +35,7 @@ alloc_ag_buf(int size)
 {
 	char	*bp;
 
-	bp = (char *)memalign(libxfs_device_alignment(), size);
+	posix_memalign((void**)&bp, libxfs_device_alignment(), size);
 	if (!bp)
 		do_error(_("could not allocate ag header buffer (%d bytes)\n"),
 			size);
repair/prefetch.c +3 -4
index 08c0394..2843042 100644
@@ -631,10 +631,9 @@ pf_io_worker(
 	void			*param)
 {
 	prefetch_args_t		*args = param;
-	void			*buf = memalign(libxfs_device_alignment(),
-						pf_max_bytes);
-
-	if (buf == NULL)
+	void			*buf;
+	posix_memalign((void**)&buf, libxfs_device_alignment(), pf_max_bytes);
+	if (!buf)
 		return NULL;
 
 	pthread_mutex_lock(&args->lock);
repair/sb.c +5 -5
index f6a1f15..f2e32aa 100644
@@ -102,7 +102,7 @@ find_secondary_sb(xfs_sb_t *rsb)
 
 	do_warn(_("\nattempting to find secondary superblock...\n"));
 
-	sb = (xfs_sb_t *)memalign(libxfs_device_alignment(), BSIZE);
+	posix_memalign((void**)&sb, libxfs_device_alignment(), BSIZE);
 	if (!sb) {
 		do_error(
 	_("error finding secondary superblock -- failed to memalign buffer\n"));
@@ -438,8 +438,8 @@ write_primary_sb(xfs_sb_t *sbp, int size)
 	if (no_modify)
 		return;
 
-	buf = memalign(libxfs_device_alignment(), size);
-	if (buf == NULL) {
+	posix_memalign((void**)&buf, libxfs_device_alignment(), size);
+	if (!buf) {
 		do_error(_("failed to memalign superblock buffer\n"));
 		return;
 	}
@@ -472,8 +472,8 @@ get_sb(xfs_sb_t *sbp, xfs_off_t off, int size, xfs_agnumber_t agno)
 	int error, rval;
 	xfs_dsb_t *buf;
 
-	buf = memalign(libxfs_device_alignment(), size);
-	if (buf == NULL) {
+	posix_memalign((void**)&buf, libxfs_device_alignment(), size);
+	if (!buf) {
 		do_error(
 	_("error reading superblock %u -- failed to memalign buffer\n"),
 			agno);
rtcp/xfs_rtcp.c +6 -1
index 7f48060..417b066 100644
@@ -327,7 +327,12 @@ rtcp( char *source, char *target, int fextsize)
 	}
 
 	iosz =  dioattr.d_miniosz;
-	fbuf = memalign( dioattr.d_mem, iosz);
+	posix_memalign((void**)&fbuf, dioattr.d_mem, iosz);
+	if (!fbuf) {
+		perror(
+	_("error finding secondary superblock -- failed to memalign buffer\n"));
+		exit(1);
+	}
 	memset(fbuf, 0, iosz);
 
 	/*
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
#31 lore raw

Re: [PATCH v3 10/11] xfsprogs: replace obsolete memalign with posix_memalign

Quoted 7 lines · Jan Tulak

Memalign from <malloc.h> was marked obsolete in favor of a posix variant from <stdlib.h>. So replace all calls and remove <malloc.h> includes. This also enhances support on other posix platforms, which doesn't have <malloc.h>.

Because posix_memalign returns any error as a return code, not in errno, change relevant checks in code (and add a missing one).

....

libxfs/rdwr.c libxfs_device_zero(struct xfs_buftarg *btp, xfs_daddr_t start, uint len) · line 84

Quoted 13 lines
libxfs/rdwr.c +6 -1
@@ -74,12 +74,18 @@ libxfs_device_zero(struct xfs_buftarg *btp, xfs_daddr_t start, uint len)
 	ssize_t		zsize, bytes;
 	char		*z;
 	int		fd;
+	int ret;
 
 	zsize = min(BDSTRAT_SIZE, BBTOB(len));
-	if ((z = memalign(libxfs_device_alignment(), zsize)) == NULL) {
+	ret = posix_memalign(
+						(void **)&z,
+						libxfs_device_alignment(),
+						zsize
+					);

Unusual function call formatting. Please use the form the rest of the code uses. i.e:

	ret = posix_memalign((void **)&z, libxfs_device_alignment(), zsize);

(same for the rest of the patch).

Cheers,

Dave.

Signature · 7 lines
Dave Chinner
[email protected]

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#32 lore raw

PATCH v3 10/11 xfsprogs: replace obsolete memalign with posix_memalign

UPDATE: code format

Memalign from <malloc.h> was marked obsolete in favor of a posix variant from <stdlib.h>. So replace all calls and remove <malloc.h> includes. This also enhances support on other posix platforms, which doesn't have <malloc.h>.

Because posix_memalign returns any error as a return code, not in errno, change relevant checks in code (and add a missing one).

---
 copy/xfs_copy.c       |  2 +-
 db/attrset.c          |  2 +-
 fsr/xfs_fsr.c         |  3 ++-
 include/darwin.h      |  1 -
 include/freebsd.h     |  1 -
 include/gnukfreebsd.h |  1 -
 include/linux.h       |  1 -
 io/pread.c            |  4 ++--
 libxfs/rdwr.c         | 12 ++++++++----
 mkfs/xfs_mkfs.c       |  3 ++-
 repair/incore.c       |  2 +-
 repair/incore_ino.c   |  7 ++++---
 repair/phase1.c       |  2 +-
 repair/prefetch.c     |  7 +++----
 repair/sb.c           | 10 +++++-----
 rtcp/xfs_rtcp.c       |  7 ++++++-
 16 files changed, 36 insertions(+), 29 deletions(-)
copy/xfs_copy.c +1 -1
index e13f468..8109ac5 100644
@@ -333,7 +333,7 @@ wbuf *
 wbuf_init(wbuf *buf, int data_size, int data_align, int min_io_size, int id)
 {
 	ASSERT(data_size % BBSIZE == 0);
-	while ((buf->data = memalign(data_align, data_size)) == NULL) {
+	while (posix_memalign((void**)&(buf->data), data_align, data_size)) {
 		data_size >>= 1;
 		if (data_size < min_io_size)
 			return NULL;
db/attrset.c +1 -1
index ec9da5a..539765f 100644
@@ -141,7 +141,7 @@ attr_set_f(
 	name = argv[optind];
 
 	if (valuelen) {
-		value = (char *)memalign(getpagesize(), valuelen);
+		posix_memalign((void**)&value, getpagesize(), valuelen);
 		if (!value) {
 			dbprintf(_("cannot allocate buffer (%d)\n"), valuelen);
 			goto out;
fsr/xfs_fsr.c +2 -1
index 4912b73..ad52990 100644
@@ -1306,7 +1306,8 @@ packfile(char *fname, char *tname, int fd,
 			dio.d_maxiosz, pagesize);
 	}
 
-	if (!(fbuf = (char *)memalign(dio.d_mem, blksz_dio))) {
+	posix_memalign((void **)&fbuf, dio.d_mem, blksz_dio);
+	if (!fbuf) {
 		fsrprintf(_("could not allocate buf: %s\n"), tname);
 		goto out;
 	}
include/darwin.h +0 -1
index 775dfc8..e3ec863 100644
@@ -141,7 +141,6 @@ typedef int64_t		xfs_daddr_t;
 #define pwrite64	pwrite
 #define ftruncate64	ftruncate
 #define fdatasync	fsync
-#define memalign(a,sz)	valloc(sz)
 
 #define O_LARGEFILE     0
 #ifndef O_DIRECT
include/freebsd.h +0 -1
index 902b940..7289159 100644
@@ -40,7 +40,6 @@
 #define pwrite64	pwrite
 #define pread64		pread
 #define fdatasync	fsync
-#define memalign(a,sz)	valloc(sz)
 
 #define constpp	char * const *
 
include/gnukfreebsd.h +0 -1
index 95c4c13..4605234 100644
@@ -22,7 +22,6 @@
 #include <sys/vfs.h>
 #include <sys/ioctl.h>
 #include <sys/sysmacros.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <endian.h>
 #include <sys/stat.h>
include/linux.h +0 -1
index 8804c2d..7493b76 100644
@@ -24,7 +24,6 @@
 #include <sys/sysmacros.h>
 #include <sys/stat.h>
 #include <inttypes.h>
-#include <malloc.h>
 #include <getopt.h>
 #include <errno.h>
 #include <endian.h>
io/pread.c +2 -2
index 1c77c41..74ba47e 100644
@@ -77,7 +77,7 @@ alloc_iovec(
 
 	buffersize = 0;
 	for (i = 0; i < vectors; i++) {
-		iov[i].iov_base = memalign(pagesize, bsize);
+		posix_memalign((void**)&(iov[i].iov_base), pagesize, bsize);
 		if (!iov[i].iov_base) {
 			perror("memalign");
 			goto unwind;
@@ -108,7 +108,7 @@ alloc_buffer(
 	if (bsize > highwater) {
 		if (buffer)
 			free(buffer);
-		buffer = memalign(pagesize, bsize);
+		posix_memalign((void**)&buffer, pagesize, bsize);
 		if (!buffer) {
 			perror("memalign");
 			highwater = buffersize = 0;
libxfs/rdwr.c +8 -4
index 4f8212f..7884cf8 100644
@@ -74,12 +74,14 @@ libxfs_device_zero(struct xfs_buftarg *btp, xfs_daddr_t start, uint len)
 	ssize_t		zsize, bytes;
 	char		*z;
 	int		fd;
+	int ret;
 
 	zsize = min(BDSTRAT_SIZE, BBTOB(len));
-	if ((z = memalign(libxfs_device_alignment(), zsize)) == NULL) {
+	ret = posix_memalign((void **)&z, libxfs_device_alignment(), zsize);
+	if (!z) {
 		fprintf(stderr,
 			_("%s: %s can't memalign %d bytes: %s\n"),
-			progname, __FUNCTION__, (int)zsize, strerror(errno));
+			progname, __FUNCTION__, (int)zsize, strerror(ret));
 		exit(1);
 	}
 	memset(z, 0, zsize);
@@ -409,6 +411,7 @@ static void
 __initbuf(xfs_buf_t *bp, struct xfs_buftarg *btp, xfs_daddr_t bno,
 		unsigned int bytes)
 {
+	int ret;
 	bp->b_flags = 0;
 	bp->b_bn = bno;
 	bp->b_bcount = bytes;
@@ -416,12 +419,13 @@ __initbuf(xfs_buf_t *bp, struct xfs_buftarg *btp, xfs_daddr_t bno,
 	bp->b_target = btp;
 	bp->b_error = 0;
 	if (!bp->b_addr)
-		bp->b_addr = memalign(libxfs_device_alignment(), bytes);
+		ret = posix_memalign((void**)&(bp->b_addr),
+					libxfs_device_alignment(), bytes);
 	if (!bp->b_addr) {
 		fprintf(stderr,
 			_("%s: %s can't memalign %u bytes: %s\n"),
 			progname, __FUNCTION__, bytes,
-			strerror(errno));
+			strerror(ret));
 		exit(1);
 	}
 	memset(bp->b_addr, 0, bytes);
mkfs/xfs_mkfs.c +2 -1
index 69d61c7..d349b4f 100644
@@ -770,7 +770,8 @@ zero_old_xfs_structures(
 	 * read in existing filesystem superblock, use its geometry
 	 * settings and zero the existing secondary superblocks.
 	 */
-	buf = memalign(libxfs_device_alignment(), new_sb->sb_sectsize);
+	posix_memalign((void**)&buf, libxfs_device_alignment(),
+		       new_sb->sb_sectsize);
 	if (!buf) {
 		fprintf(stderr,
 	_("error reading existing superblock -- failed to memalign buffer\n"));
repair/incore.c +1 -1
index cb57316..81d3b8c 100644
@@ -224,7 +224,7 @@ init_rt_bmap(
 	rt_bmap_size = roundup(mp->m_sb.sb_rextents / (NBBY / XR_BB),
 			       sizeof(__uint64_t));
 
-	rt_bmap = memalign(sizeof(__uint64_t), rt_bmap_size);
+	posix_memalign((void**)&rt_bmap, sizeof(__uint64_t), rt_bmap_size);
 	if (!rt_bmap) {
 		do_error(
 	_("couldn't allocate realtime block map, size = %" PRIu64 "\n"),
repair/incore_ino.c +4 -3
index 32d7678..dd95996 100644
@@ -626,8 +626,8 @@ set_inode_parent(
 			irec->ino_un.plist = ptbl;
 
 		ptbl->pmask = 1LL << offset;
-		ptbl->pentries = (xfs_ino_t*)memalign(sizeof(xfs_ino_t),
-							sizeof(xfs_ino_t));
+		posix_memalign((void**)&(ptbl->pentries),sizeof(xfs_ino_t),
+				sizeof(xfs_ino_t));
 		if (!ptbl->pentries)
 			do_error(_("couldn't memalign pentries table\n"));
 #ifdef DEBUG
@@ -673,7 +673,8 @@ set_inode_parent(
 #endif
 	ASSERT(cnt >= target);
 
-	tmp = (xfs_ino_t*)memalign(sizeof(xfs_ino_t), (cnt + 1) * sizeof(xfs_ino_t));
+	posix_memalign((void**)&tmp, sizeof(xfs_ino_t),
+		       (cnt + 1) * sizeof(xfs_ino_t));
 	if (!tmp)
 		do_error(_("couldn't memalign pentries table\n"));
 
repair/phase1.c +1 -1
index 126d0b3..7a1fc7d 100644
@@ -35,7 +35,7 @@ alloc_ag_buf(int size)
 {
 	char	*bp;
 
-	bp = (char *)memalign(libxfs_device_alignment(), size);
+	posix_memalign((void**)&bp, libxfs_device_alignment(), size);
 	if (!bp)
 		do_error(_("could not allocate ag header buffer (%d bytes)\n"),
 			size);
repair/prefetch.c +3 -4
index 8b261ae..c6c9450 100644
@@ -631,10 +631,9 @@ pf_io_worker(
 	void			*param)
 {
 	prefetch_args_t		*args = param;
-	void			*buf = memalign(libxfs_device_alignment(),
-						pf_max_bytes);
-
-	if (buf == NULL)
+	void			*buf;
+	posix_memalign((void**)&buf, libxfs_device_alignment(), pf_max_bytes);
+	if (!buf)
 		return NULL;
 
 	pthread_mutex_lock(&args->lock);
repair/sb.c +5 -5
index 4eef14a..cf1ea8b 100644
@@ -102,7 +102,7 @@ find_secondary_sb(xfs_sb_t *rsb)
 
 	do_warn(_("\nattempting to find secondary superblock...\n"));
 
-	sb = (xfs_sb_t *)memalign(libxfs_device_alignment(), BSIZE);
+	posix_memalign((void**)&sb, libxfs_device_alignment(), BSIZE);
 	if (!sb) {
 		do_error(
 	_("error finding secondary superblock -- failed to memalign buffer\n"));
@@ -438,8 +438,8 @@ write_primary_sb(xfs_sb_t *sbp, int size)
 	if (no_modify)
 		return;
 
-	buf = memalign(libxfs_device_alignment(), size);
-	if (buf == NULL) {
+	posix_memalign((void**)&buf, libxfs_device_alignment(), size);
+	if (!buf) {
 		do_error(_("failed to memalign superblock buffer\n"));
 		return;
 	}
@@ -472,8 +472,8 @@ get_sb(xfs_sb_t *sbp, xfs_off_t off, int size, xfs_agnumber_t agno)
 	int error, rval;
 	xfs_dsb_t *buf;
 
-	buf = memalign(libxfs_device_alignment(), size);
-	if (buf == NULL) {
+	posix_memalign((void**)&buf, libxfs_device_alignment(), size);
+	if (!buf) {
 		do_error(
 	_("error reading superblock %u -- failed to memalign buffer\n"),
 			agno);
rtcp/xfs_rtcp.c +6 -1
index f604b46..e2e3ece 100644
@@ -327,7 +327,12 @@ rtcp( char *source, char *target, int fextsize)
 	}
 
 	iosz =  dioattr.d_miniosz;
-	fbuf = memalign( dioattr.d_mem, iosz);
+	posix_memalign((void**)&fbuf, dioattr.d_mem, iosz);
+	if (!fbuf) {
+		perror(
+	_("error finding secondary superblock -- failed to memalign buffer\n"));
+		exit(1);
+	}
 	memset(fbuf, 0, iosz);
 
 	/*
Signature · 6 lines
2.4.5

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#33 lore raw

PATCH v2 11/11 xfsprogs: Prefix LIST_... macros to XFS_LIST_...

In reply to Jan Tulak

OS X has two conflicting LIST_ macros:
- LIST_HEAD
- LIST_HEAD_INIT

These results in tons of warnings like:

In file included from init.c:22:
In file included from ./libxfs_priv.h:63:
../include/xfs/list.h:32:9: warning: 'LIST_HEAD' macro redefined [-Wmacro-redefined]
\#define LIST_HEAD(name) \

These macros are included from sys/queue.h through sys/mount.h and possibly through more system libraries. So far, I didn't found a way how to prevent the inclusion.

Attempted solution was to avoid including with -D_SYS_QUEUE_H_ for the compiler, but this resulted in another error:

In file included from crc32.c:36:
In file included from ../include/xfs/platform_defs.h:79:
In file included from ../include/xfs/darwin.h:26:
In file included from /usr/include/sys/mount.h:76:
In file included from /usr/include/sys/attr.h:42:
/usr/include/sys/ucred.h:90:2: error: type name requires a specifier or qualifier
TAILQ_ENTRY(ucred) cr_link; /* never modify this without KAUTH_CRE...

I tried renaming. This works, but it doesn't look like a good solution. So this patch is still not final.

---
 include/list.h  | 6 +++---
 repair/phase6.c | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
include/list.h +3 -3
index 3f087a4..7e9f748 100644
@@ -27,10 +27,10 @@ struct list_head {
 	struct list_head *prev;
 };
 
-#define LIST_HEAD_INIT(name) { &(name), &(name) }
+#define XFS_LIST_HEAD_INIT(name) { &(name), &(name) }
 
-#define LIST_HEAD(name) \
-		struct list_head name = LIST_HEAD_INIT(name)
+#define XFS_LIST_HEAD(name) \
+		struct list_head name = XFS_LIST_HEAD_INIT(name)
 
 #define INIT_LIST_HEAD(list) list_head_init(list)
 static inline void list_head_init(struct list_head *list)
repair/phase6.c +1 -1
index 9a5cba7..87732e1 100644
@@ -49,7 +49,7 @@ typedef struct dotdot_update {
 	int			ino_offset;
 } dotdot_update_t;
 
-static LIST_HEAD(dotdot_update_list);
+static XFS_LIST_HEAD(dotdot_update_list);
 static int			dotdot_update;
 
 static void
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs
author
#34 lore raw

PATCH v4 11/11 xfsprogs: prevent LIST_ macros conflicts

BSD 4.4 added some LIST_ macros into system header files, which causes "macro redefined" warnings. To ensure we use our own macros, undefine the system ones at first.

The conflicting macros are LIST_HEAD and LIST_HEAD_INIT

---
 include/list.h | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
include/list.h +14 -0
index 3f087a4..f92faed 100644
@@ -19,6 +19,20 @@
 #define __LIST_H__
 
 /*
+ * This undef is here because BSD 4.4 added some LIST_ macros into system
+ * header file sys/queue.h. This header is included in many other system
+ * headers and thus causes "macro redefined" warnings.
+ *
+ * As OS X is kind of a derivate of BSD, this affects OS X too.
+ *
+ * To use our own LIST_ macros (copied from kernel code), we have to
+ * at first undefine the conflicting system macros.
+ *
+ */
+#undef LIST_HEAD
+#undef LIST_HEAD_INIT
+
+/*
  * Simple, generic doubly-linked list implementation.
  */
 
Signature · 6 lines
2.4.3

_______________________________________________
xfs mailing list
[email protected]
http://oss.sgi.com/mailman/listinfo/xfs