From 30090f88aabc6dd2e1bc18b61857ef99a0ac5432 Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Mon, 16 Jun 2014 20:52:37 -0500 Subject: [PATCH] Fix aarch64 build problems w/ sys_getdents --- xfsdump-ancient-getdents-code.patch | 284 ++++++++++++++++++++++++++++ xfsdump-getdents-ifdef-hell.patch | 214 +++++++++++++++++++++ xfsdump.spec | 13 +- 3 files changed, 509 insertions(+), 2 deletions(-) create mode 100644 xfsdump-ancient-getdents-code.patch create mode 100644 xfsdump-getdents-ifdef-hell.patch diff --git a/xfsdump-ancient-getdents-code.patch b/xfsdump-ancient-getdents-code.patch new file mode 100644 index 0000000..cdbd7bc --- /dev/null +++ b/xfsdump-ancient-getdents-code.patch @@ -0,0 +1,284 @@ +commit b1d6979f1fae82acc79d27cf0add4d55da6d83cc +Author: Kyle McMartin +Date: Tue Apr 8 10:35:34 2014 +1000 + + remove ancient sys_getdents code paths + + Everything since 2.4.1 has supported getdents64... so let's remove all + the legacy code paths to handle it and just rely on getdents64 existing + everywhere. Also re-indent the function to not look entirely awful. + + Signed-off-by: Kyle McMartin + Reviewed-by: Christoph Hellwig + Signed-off-by: Dave Chinner + +diff --git a/common/getdents.c b/common/getdents.c +index 49d0d03..957bb5a 100644 +--- a/common/getdents.c ++++ b/common/getdents.c +@@ -35,47 +35,13 @@ + + #include + +-/* For Linux we need a special version of this file since the +- definition of `struct dirent' is not the same for the kernel and +- the libc. There is one additional field which might be introduced +- in the kernel structure in the future. +- +- Here is the kernel definition of `struct dirent' as of 2.1.20: */ +- +-struct kernel_dirent +- { +- long int d_ino; +- __kernel_off_t d_off; +- unsigned short int d_reclen; +- char d_name[256]; +- }; +- +-struct kernel_dirent64 +- { +- uint64_t d_ino; +- int64_t d_off; +- unsigned short int d_reclen; +- unsigned char d_type; +- char d_name[256]; +- }; +- +-#define DIRENT_SET_DP_INO(dp, value) (dp)->d_ino = (value) +- +-#define __set_errno(e) (errno = (e)) +- +-int __have_no_getdents64; +- +-#ifdef __NR_getdents64 +-# define __SYS_GETDENTS64(fd, buf, len) (syscall(SYS_getdents64, fd, buf, len)) +-#else +-# define __SYS_GETDENTS64(fd, buf, len) ({ __set_errno(ENOSYS); -1; }) +-#endif +- +-#ifdef __NR_getdents +-# define __SYS_GETDENTS(fd, buf, len) (syscall(SYS_getdents, fd, buf, len)) +-#else +-# define __SYS_GETDENTS(fd, buf, len) ({ __set_errno(ENOSYS); -1; }) +-#endif ++struct kernel_dirent64 { ++ uint64_t d_ino; ++ int64_t d_off; ++ unsigned short int d_reclen; ++ unsigned char d_type; ++ char d_name[256]; ++}; + + /* The problem here is that we cannot simply read the next NBYTES + bytes. We need to take the additional field into account. We use +@@ -85,148 +51,74 @@ int __have_no_getdents64; + reasonable number of bytes to read. If we should be wrong, we can + reset the file descriptor. In practice the kernel is limiting the + amount of data returned much more then the reduced buffer size. */ +-int +-getdents_wrap (int fd, char *buf, size_t nbytes) ++int getdents_wrap(int fd, char *buf, size_t nbytes) + { +- struct dirent *dp; +- off64_t last_offset = -1; +- ssize_t retval; +- +- if (!__have_no_getdents64) +- { +- int saved_errno = errno; +- char *kbuf = buf; +- size_t kbytes = nbytes; +- if (offsetof (struct dirent, d_name) +- < offsetof (struct kernel_dirent64, d_name) +- && nbytes <= sizeof (struct dirent)) +- { +- kbytes = nbytes + offsetof (struct kernel_dirent64, d_name) +- - offsetof (struct dirent, d_name); +- kbuf = alloca(kbytes); ++ struct dirent *dp; ++ struct kernel_dirent64 *kdp; ++ off64_t last_offset = -1; ++ ssize_t retval; ++ char *kbuf = buf; ++ size_t kbytes = nbytes; ++ const size_t size_diff = (offsetof(struct kernel_dirent64, d_name) ++ - offsetof(struct dirent, d_name)); ++ ++ if (offsetof(struct dirent, d_name) ++ < offsetof(struct kernel_dirent64, d_name) ++ && nbytes <= sizeof(struct dirent)) { ++ kbytes = nbytes + size_diff; ++ kbuf = alloca(kbytes); + } +- retval = __SYS_GETDENTS64(fd, kbuf, kbytes); +- if (retval != -1) +- { +- struct kernel_dirent64 *kdp; +- const size_t size_diff = (offsetof (struct kernel_dirent64, d_name) +- - offsetof (struct dirent, d_name)); +- +- /* If the structure returned by the kernel is identical to what we +- need, don't do any conversions. */ +- if (offsetof (struct dirent, d_name) +- == offsetof (struct kernel_dirent64, d_name) +- && sizeof (dp->d_ino) == sizeof (kdp->d_ino) +- && sizeof (dp->d_off) == sizeof (kdp->d_off)) +- return retval; +- +- dp = (struct dirent *)buf; +- kdp = (struct kernel_dirent64 *) kbuf; +- while ((char *) kdp < kbuf + retval) +- { +- const size_t alignment = __alignof__ (struct dirent); +- /* Since kdp->d_reclen is already aligned for the kernel +- structure this may compute a value that is bigger +- than necessary. */ +- size_t old_reclen = kdp->d_reclen; +- size_t new_reclen = ((old_reclen - size_diff + alignment - 1) +- & ~(alignment - 1)); +- uint64_t d_ino = kdp->d_ino; +- int64_t d_off = kdp->d_off; +- unsigned char d_type = kdp->d_type; + +- DIRENT_SET_DP_INO (dp, d_ino); +- dp->d_off = d_off; +- if ((sizeof (dp->d_ino) != sizeof (kdp->d_ino) +- && dp->d_ino != d_ino) +- || (sizeof (dp->d_off) != sizeof (kdp->d_off) +- && dp->d_off != d_off)) +- { +- /* Overflow. If there was at least one entry +- before this one, return them without error, +- otherwise signal overflow. */ +- if (last_offset != -1) +- { +- lseek64 (fd, last_offset, SEEK_SET); +- return (char *) dp - buf; +- } +- __set_errno (EOVERFLOW); +- return -1; ++ retval = syscall(SYS_getdents64, fd, kbuf, kbytes); ++ if (retval != -1) ++ return retval; ++ ++ /* If the structure returned by the kernel is identical to what we ++ need, don't do any conversions. */ ++ if (offsetof(struct dirent, d_name) ++ == offsetof(struct kernel_dirent64, d_name) ++ && sizeof(dp->d_ino) == sizeof(kdp->d_ino) ++ && sizeof(dp->d_off) == sizeof(kdp->d_off)) ++ return retval; ++ ++ dp = (struct dirent *)buf; ++ kdp = (struct kernel_dirent64 *)kbuf; ++ while ((char *)kdp < kbuf + retval) { ++ const size_t alignment = __alignof__(struct dirent); ++ /* Since kdp->d_reclen is already aligned for the kernel ++ structure this may compute a value that is bigger ++ than necessary. */ ++ size_t old_reclen = kdp->d_reclen; ++ size_t new_reclen = ((old_reclen - size_diff + alignment - 1) ++ & ~(alignment - 1)); ++ uint64_t d_ino = kdp->d_ino; ++ int64_t d_off = kdp->d_off; ++ unsigned char d_type = kdp->d_type; ++ ++ dp->d_ino = d_ino; ++ dp->d_off = d_off; ++ if ((sizeof(dp->d_ino) != sizeof(kdp->d_ino)) ++ || (sizeof(dp->d_off) != sizeof(kdp->d_off))) { ++ /* Overflow. If there was at least one entry ++ before this one, return them without error, ++ otherwise signal overflow. */ ++ if (last_offset != -1) { ++ lseek64(fd, last_offset, SEEK_SET); ++ return (char *)dp - buf; ++ } ++ errno = EOVERFLOW; ++ return -1; + } + +- last_offset = d_off; +- dp->d_reclen = new_reclen; +- dp->d_type = d_type; +- memmove (dp->d_name, kdp->d_name, +- old_reclen - offsetof (struct kernel_dirent64, d_name)); ++ last_offset = d_off; ++ dp->d_reclen = new_reclen; ++ dp->d_type = d_type; ++ memmove(dp->d_name, kdp->d_name, ++ old_reclen - offsetof(struct kernel_dirent64, d_name)); + +- dp = (struct dirent *) ((char *) dp + new_reclen); +- kdp = (struct kernel_dirent64 *) ((char *) kdp + old_reclen); +- } +- +- return (char *) dp - buf; ++ dp = (struct dirent *)((char *)dp + new_reclen); ++ kdp = (struct kernel_dirent64 *)((char *)kdp + old_reclen); + } + +- __set_errno (saved_errno); +- __have_no_getdents64 = 1; +- } +- +- /* fallback to getdents */ +- { +- size_t red_nbytes; +- struct kernel_dirent *skdp, *kdp; +- const size_t size_diff = (offsetof (struct dirent, d_name) +- - offsetof (struct kernel_dirent, d_name)); +- +- red_nbytes = MIN (nbytes +- - ((nbytes / (offsetof (struct dirent, d_name) + 14)) +- * size_diff), +- nbytes - size_diff); +- +- dp = (struct dirent *) buf; +- skdp = kdp = alloca (red_nbytes); +- +- retval = __SYS_GETDENTS(fd, kdp, red_nbytes); +- if (retval == -1) +- return -1; +- +- while ((char *) kdp < (char *) skdp + retval) +- { +- const size_t alignment = __alignof__ (struct dirent); +- /* Since kdp->d_reclen is already aligned for the kernel structure +- this may compute a value that is bigger than necessary. */ +- size_t new_reclen = ((kdp->d_reclen + size_diff + alignment - 1) +- & ~(alignment - 1)); +- if ((char *) dp + new_reclen > buf + nbytes) +- { +- /* Our heuristic failed. We read too many entries. Reset +- the stream. */ +- assert (last_offset != -1); +- lseek64 (fd, last_offset, SEEK_SET); +- +- if ((char *) dp == buf) +- { +- /* The buffer the user passed in is too small to hold even +- one entry. */ +- __set_errno (EINVAL); +- return -1; +- } +- +- break; +- } +- +- last_offset = kdp->d_off; +- DIRENT_SET_DP_INO(dp, kdp->d_ino); +- dp->d_off = kdp->d_off; +- dp->d_reclen = new_reclen; +- dp->d_type = DT_UNKNOWN; +- memcpy (dp->d_name, kdp->d_name, +- kdp->d_reclen - offsetof (struct kernel_dirent, d_name)); +- +- dp = (struct dirent *) ((char *) dp + new_reclen); +- kdp = (struct kernel_dirent *) (((char *) kdp) + kdp->d_reclen); +- } +- } +- +- return (char *) dp - buf; ++ return (char *)dp - buf; + } diff --git a/xfsdump-getdents-ifdef-hell.patch b/xfsdump-getdents-ifdef-hell.patch new file mode 100644 index 0000000..b6fe794 --- /dev/null +++ b/xfsdump-getdents-ifdef-hell.patch @@ -0,0 +1,214 @@ +commit 9ed517b63df35876681e8883388fbf154afda0c1 +Author: Kyle McMartin +Date: Tue Apr 8 10:33:57 2014 +1000 + + xfsdump: getdents.c: clean up ifdef-hell around sys_getdents + + Remove the ifdef-hell imported from glibc around getdents64. Everything + since 2.4.1 supports things properly and this seems like a sensible + clean up, so lets just assume it exists and handle it by falling back + if not. + + Additionally, if the old getdents syscall doesn't exist, just stub out + the actual syscall and return ENOSYS. + + Signed-off-by: Kyle McMartin + Reviewed-by: Christoph Hellwig + Signed-off-by: Dave Chinner + +diff --git a/common/getdents.c b/common/getdents.c +index e9ba25a..49d0d03 100644 +--- a/common/getdents.c ++++ b/common/getdents.c +@@ -35,44 +35,6 @@ + + #include + +-/* Copied from kernel-features.h for __ASSUME_GETDENTS64_SYSCALL */ +-#ifndef __LINUX_KERNEL_VERSION +-/* We assume the worst; all kernels should be supported. */ +-# define __LINUX_KERNEL_VERSION 0 +-#endif +-/* The getdents64 syscall was introduced in 2.4.0-test7. We test for +- 2.4.1 for the earliest version we know the syscall is available. */ +-#if __LINUX_KERNEL_VERSION >= 132097 +-# define __ASSUME_GETDENTS64_SYSCALL 1 +-#endif +-/* There are an infinite number of PA-RISC kernel versions numbered +- 2.4.0. But they've not really been released as such. We require +- and expect the final version here. */ +-#ifdef __hppa__ +-# define __ASSUME_GETDENTS64_SYSCALL 1 +-#endif +- +-#ifndef __set_errno +-#define __set_errno(e) (errno = (e)) +-#endif +- +- +-#ifdef __NR_getdents64 +-# ifndef __ASSUME_GETDENTS64_SYSCALL +-# ifndef __GETDENTS +-/* The variable is shared between all *getdents* calls. */ +-int __have_no_getdents64; +-# else +-extern int __have_no_getdents64; +-# endif +-# endif +-/* Earlier versions of glibc don't define SYS_getdents64 at all */ +-# ifndef SYS_getdents64 +-# define SYS_getdents64 __NR_getdents64 +-# endif +-#endif +- +- + /* For Linux we need a special version of this file since the + definition of `struct dirent' is not the same for the kernel and + the libc. There is one additional field which might be introduced +@@ -97,11 +59,22 @@ struct kernel_dirent64 + char d_name[256]; + }; + +-#ifndef DIRENT_TYPE +-# define DIRENT_TYPE struct dirent ++#define DIRENT_SET_DP_INO(dp, value) (dp)->d_ino = (value) ++ ++#define __set_errno(e) (errno = (e)) ++ ++int __have_no_getdents64; ++ ++#ifdef __NR_getdents64 ++# define __SYS_GETDENTS64(fd, buf, len) (syscall(SYS_getdents64, fd, buf, len)) ++#else ++# define __SYS_GETDENTS64(fd, buf, len) ({ __set_errno(ENOSYS); -1; }) + #endif +-#ifndef DIRENT_SET_DP_INO +-# define DIRENT_SET_DP_INO(dp, value) (dp)->d_ino = (value) ++ ++#ifdef __NR_getdents ++# define __SYS_GETDENTS(fd, buf, len) (syscall(SYS_getdents, fd, buf, len)) ++#else ++# define __SYS_GETDENTS(fd, buf, len) ({ __set_errno(ENOSYS); -1; }) + #endif + + /* The problem here is that we cannot simply read the next NBYTES +@@ -115,50 +88,43 @@ struct kernel_dirent64 + int + getdents_wrap (int fd, char *buf, size_t nbytes) + { +- DIRENT_TYPE *dp; ++ struct dirent *dp; + off64_t last_offset = -1; + ssize_t retval; + +-#ifdef __NR_getdents64 +-# ifndef __ASSUME_GETDENTS64_SYSCALL + if (!__have_no_getdents64) +-# endif + { +-# ifndef __ASSUME_GETDENTS64_SYSCALL + int saved_errno = errno; +-# endif + char *kbuf = buf; + size_t kbytes = nbytes; +- if (offsetof (DIRENT_TYPE, d_name) ++ if (offsetof (struct dirent, d_name) + < offsetof (struct kernel_dirent64, d_name) +- && nbytes <= sizeof (DIRENT_TYPE)) ++ && nbytes <= sizeof (struct dirent)) + { + kbytes = nbytes + offsetof (struct kernel_dirent64, d_name) +- - offsetof (DIRENT_TYPE, d_name); ++ - offsetof (struct dirent, d_name); + kbuf = alloca(kbytes); + } +- retval = syscall(SYS_getdents64, fd, kbuf, kbytes); +-# ifndef __ASSUME_GETDENTS64_SYSCALL +- if (retval != -1 && errno != -EINVAL) +-# endif ++ retval = __SYS_GETDENTS64(fd, kbuf, kbytes); ++ if (retval != -1) + { + struct kernel_dirent64 *kdp; + const size_t size_diff = (offsetof (struct kernel_dirent64, d_name) +- - offsetof (DIRENT_TYPE, d_name)); ++ - offsetof (struct dirent, d_name)); + + /* If the structure returned by the kernel is identical to what we + need, don't do any conversions. */ +- if (offsetof (DIRENT_TYPE, d_name) ++ if (offsetof (struct dirent, d_name) + == offsetof (struct kernel_dirent64, d_name) + && sizeof (dp->d_ino) == sizeof (kdp->d_ino) + && sizeof (dp->d_off) == sizeof (kdp->d_off)) + return retval; + +- dp = (DIRENT_TYPE *)buf; ++ dp = (struct dirent *)buf; + kdp = (struct kernel_dirent64 *) kbuf; + while ((char *) kdp < kbuf + retval) + { +- const size_t alignment = __alignof__ (DIRENT_TYPE); ++ const size_t alignment = __alignof__ (struct dirent); + /* Since kdp->d_reclen is already aligned for the kernel + structure this may compute a value that is bigger + than necessary. */ +@@ -194,41 +160,39 @@ getdents_wrap (int fd, char *buf, size_t nbytes) + memmove (dp->d_name, kdp->d_name, + old_reclen - offsetof (struct kernel_dirent64, d_name)); + +- dp = (DIRENT_TYPE *) ((char *) dp + new_reclen); ++ dp = (struct dirent *) ((char *) dp + new_reclen); + kdp = (struct kernel_dirent64 *) ((char *) kdp + old_reclen); + } + + return (char *) dp - buf; + } + +-# ifndef __ASSUME_GETDENTS64_SYSCALL + __set_errno (saved_errno); + __have_no_getdents64 = 1; +-# endif + } +-#endif ++ ++ /* fallback to getdents */ + { + size_t red_nbytes; + struct kernel_dirent *skdp, *kdp; +- const size_t size_diff = (offsetof (DIRENT_TYPE, d_name) ++ const size_t size_diff = (offsetof (struct dirent, d_name) + - offsetof (struct kernel_dirent, d_name)); + + red_nbytes = MIN (nbytes +- - ((nbytes / (offsetof (DIRENT_TYPE, d_name) + 14)) ++ - ((nbytes / (offsetof (struct dirent, d_name) + 14)) + * size_diff), + nbytes - size_diff); + +- dp = (DIRENT_TYPE *) buf; ++ dp = (struct dirent *) buf; + skdp = kdp = alloca (red_nbytes); + +- retval = syscall(SYS_getdents, fd, kdp, red_nbytes); +- ++ retval = __SYS_GETDENTS(fd, kdp, red_nbytes); + if (retval == -1) + return -1; + + while ((char *) kdp < (char *) skdp + retval) + { +- const size_t alignment = __alignof__ (DIRENT_TYPE); ++ const size_t alignment = __alignof__ (struct dirent); + /* Since kdp->d_reclen is already aligned for the kernel structure + this may compute a value that is bigger than necessary. */ + size_t new_reclen = ((kdp->d_reclen + size_diff + alignment - 1) +@@ -259,7 +223,7 @@ getdents_wrap (int fd, char *buf, size_t nbytes) + memcpy (dp->d_name, kdp->d_name, + kdp->d_reclen - offsetof (struct kernel_dirent, d_name)); + +- dp = (DIRENT_TYPE *) ((char *) dp + new_reclen); ++ dp = (struct dirent *) ((char *) dp + new_reclen); + kdp = (struct kernel_dirent *) (((char *) kdp) + kdp->d_reclen); + } + } diff --git a/xfsdump.spec b/xfsdump.spec index 4beb42b..bb1070d 100644 --- a/xfsdump.spec +++ b/xfsdump.spec @@ -1,7 +1,7 @@ Summary: Administrative utilities for the XFS filesystem Name: xfsdump Version: 3.1.3 -Release: 4%{?dist} +Release: 5%{?dist} # Licensing based on generic "GNU GENERAL PUBLIC LICENSE" # in source, with no mention of version. License: GPL+ @@ -13,6 +13,9 @@ BuildRequires: libtool, gettext, gawk BuildRequires: xfsprogs-devel, libuuid-devel, libattr-devel ncurses-devel Requires: xfsprogs >= 2.6.30, attr >= 2.0.0 +Patch0: xfsdump-getdents-ifdef-hell.patch +Patch1: xfsdump-ancient-getdents-code.patch + %description The xfsdump package contains xfsdump, xfsrestore and a number of other utilities for administering XFS filesystems. @@ -33,6 +36,9 @@ subtrees may be restored from full or partial backups. %prep %setup -q +%patch0 -p1 +%patch1 -p1 + %build %configure @@ -65,6 +71,9 @@ rm -rf $RPM_BUILD_ROOT %{_sharedstatedir}/xfsdump/inventory %changelog +* Mon Jun 16 2014 Eric Sandeen 3.1.3-5 +- Fix aarch64 build (#926800) + * Sun Jun 08 2014 Fedora Release Engineering - 3.1.3-4 - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_Mass_Rebuild @@ -166,4 +175,4 @@ rm -rf $RPM_BUILD_ROOT package the docs based in the version specfic directory * Wed Aug 9 2006 Russell Cattelan - 2.2.38-1 -- Add xfsdump to Fedorda +- Add xfsdump to Fedora