[libvirt] [PATCH] build: avoid compile failure on linux kernels older than 2.6.19

This is required for any kernel prior to 2.6.19, since <linux/magic.h> didn't exist back then. Now that file is provided by the kernel-headers package.
From d14ef1669968ffeb65076b007e318934ed99aa61 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 17 May 2010 16:17:08 +0200 Subject: [PATCH] build: avoid compile failure on linux kernels older than 2.6.19
* configure.ac: Check for <linux/magic.h>. * src/util/storage_file.c: Include <linux/magic.h> only if present. Linux kernels prior to 2.6.19 lacked it. [__linux__] (NFS_SUPER_MAGIC): Define if not already defined. --- configure.ac | 2 +- src/util/storage_file.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index c187420..ebd2082 100644 --- a/configure.ac +++ b/configure.ac @@ -108,7 +108,7 @@ LIBS=$old_libs dnl Availability of various common headers (non-fatal if missing). AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h \ - termios.h sys/poll.h syslog.h mntent.h net/ethernet.h]) + termios.h sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h]) dnl Where are the XDR functions? dnl If portablexdr is installed, prefer that. diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 5f15a64..a07bedc 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -27,7 +27,9 @@ #include <unistd.h> #include <fcntl.h> #ifdef __linux__ -# include <linux/magic.h> +# if HAVE_LINUX_MAGIC_H +# include <linux/magic.h> +# endif # include <sys/statfs.h> #endif #include "dirname.h" @@ -416,6 +418,9 @@ virStorageFileGetMetadata(const char *path, #ifdef __linux__ +# ifndef NFS_SUPER_MAGIC +# define NFS_SUPER_MAGIC 0x6969 +# endif # ifndef OCFS2_SUPER_MAGIC # define OCFS2_SUPER_MAGIC 0x7461636f # endif -- 1.7.1.250.g7d1e8

On 05/17/2010 10:25 AM, Jim Meyering wrote:
This is required for any kernel prior to 2.6.19, since <linux/magic.h> didn't exist back then. Now that file is provided by the kernel-headers package.
From d14ef1669968ffeb65076b007e318934ed99aa61 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 17 May 2010 16:17:08 +0200 Subject: [PATCH] build: avoid compile failure on linux kernels older than 2.6.19
* configure.ac: Check for <linux/magic.h>. * src/util/storage_file.c: Include <linux/magic.h> only if present. Linux kernels prior to 2.6.19 lacked it. [__linux__] (NFS_SUPER_MAGIC): Define if not already defined.
Yeah, this caused compile failure over the weekend for me. There's a similar #define in the qemu_driver.c sources; we should think about combining these at some point, but this fixes the immediate problem. ACK -- Chris Lalancette

Chris Lalancette wrote:
On 05/17/2010 10:25 AM, Jim Meyering wrote:
This is required for any kernel prior to 2.6.19, since <linux/magic.h> didn't exist back then. Now that file is provided by the kernel-headers package.
From d14ef1669968ffeb65076b007e318934ed99aa61 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 17 May 2010 16:17:08 +0200 Subject: [PATCH] build: avoid compile failure on linux kernels older than 2.6.19
* configure.ac: Check for <linux/magic.h>. * src/util/storage_file.c: Include <linux/magic.h> only if present. Linux kernels prior to 2.6.19 lacked it. [__linux__] (NFS_SUPER_MAGIC): Define if not already defined.
Yeah, this caused compile failure over the weekend for me. There's a similar #define in the qemu_driver.c sources; we should think about combining these at some point, but this fixes the immediate problem.
ACK
Thanks. Will push shortly. And I'll take care of the clean-up, too.

On Mon, May 17, 2010 at 04:25:43PM +0200, Jim Meyering wrote:
This is required for any kernel prior to 2.6.19, since <linux/magic.h> didn't exist back then. Now that file is provided by the kernel-headers package.
From d14ef1669968ffeb65076b007e318934ed99aa61 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 17 May 2010 16:17:08 +0200 Subject: [PATCH] build: avoid compile failure on linux kernels older than 2.6.19
* configure.ac: Check for <linux/magic.h>. * src/util/storage_file.c: Include <linux/magic.h> only if present. Linux kernels prior to 2.6.19 lacked it. [__linux__] (NFS_SUPER_MAGIC): Define if not already defined. --- configure.ac | 2 +- src/util/storage_file.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac index c187420..ebd2082 100644 --- a/configure.ac +++ b/configure.ac @@ -108,7 +108,7 @@ LIBS=$old_libs
dnl Availability of various common headers (non-fatal if missing). AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h \ - termios.h sys/poll.h syslog.h mntent.h net/ethernet.h]) + termios.h sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h])
dnl Where are the XDR functions? dnl If portablexdr is installed, prefer that. diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 5f15a64..a07bedc 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -27,7 +27,9 @@ #include <unistd.h> #include <fcntl.h> #ifdef __linux__ -# include <linux/magic.h> +# if HAVE_LINUX_MAGIC_H +# include <linux/magic.h> +# endif
Don't bother with this - just kill this include off completely. It is a waste of time using it if we can't rely on it existing & have to re-define everything ourselves.
# include <sys/statfs.h> #endif #include "dirname.h" @@ -416,6 +418,9 @@ virStorageFileGetMetadata(const char *path,
#ifdef __linux__
+# ifndef NFS_SUPER_MAGIC +# define NFS_SUPER_MAGIC 0x6969 +# endif # ifndef OCFS2_SUPER_MAGIC # define OCFS2_SUPER_MAGIC 0x7461636f # endif
Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Daniel P. Berrange wrote:
On Mon, May 17, 2010 at 04:25:43PM +0200, Jim Meyering wrote:
This is required for any kernel prior to 2.6.19, since <linux/magic.h> didn't exist back then. Now that file is provided by the kernel-headers package.
From d14ef1669968ffeb65076b007e318934ed99aa61 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 17 May 2010 16:17:08 +0200 Subject: [PATCH] build: avoid compile failure on linux kernels older than 2.6.19
* configure.ac: Check for <linux/magic.h>. * src/util/storage_file.c: Include <linux/magic.h> only if present. Linux kernels prior to 2.6.19 lacked it. [__linux__] (NFS_SUPER_MAGIC): Define if not already defined. --- configure.ac | 2 +- src/util/storage_file.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac index c187420..ebd2082 100644 --- a/configure.ac +++ b/configure.ac @@ -108,7 +108,7 @@ LIBS=$old_libs
dnl Availability of various common headers (non-fatal if missing). AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h \ - termios.h sys/poll.h syslog.h mntent.h net/ethernet.h]) + termios.h sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h])
dnl Where are the XDR functions? dnl If portablexdr is installed, prefer that. diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 5f15a64..a07bedc 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -27,7 +27,9 @@ #include <unistd.h> #include <fcntl.h> #ifdef __linux__ -# include <linux/magic.h> +# if HAVE_LINUX_MAGIC_H +# include <linux/magic.h> +# endif
Don't bother with this - just kill this include off completely. It is a waste of time using it if we can't rely on it existing & have to re-define everything ourselves.
I admit that those numbers will probably never change, but I see including the recommended/modern header as the preferred approach. Then, eventually when the old systems are no longer relevant (yeah, in a long time) we'll be able to remove our hackish define-if-required code.

On Mon, May 17, 2010 at 04:59:51PM +0200, Jim Meyering wrote:
Daniel P. Berrange wrote:
On Mon, May 17, 2010 at 04:25:43PM +0200, Jim Meyering wrote:
This is required for any kernel prior to 2.6.19, since <linux/magic.h> didn't exist back then. Now that file is provided by the kernel-headers package.
From d14ef1669968ffeb65076b007e318934ed99aa61 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 17 May 2010 16:17:08 +0200 Subject: [PATCH] build: avoid compile failure on linux kernels older than 2.6.19
* configure.ac: Check for <linux/magic.h>. * src/util/storage_file.c: Include <linux/magic.h> only if present. Linux kernels prior to 2.6.19 lacked it. [__linux__] (NFS_SUPER_MAGIC): Define if not already defined. --- configure.ac | 2 +- src/util/storage_file.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac index c187420..ebd2082 100644 --- a/configure.ac +++ b/configure.ac @@ -108,7 +108,7 @@ LIBS=$old_libs
dnl Availability of various common headers (non-fatal if missing). AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h \ - termios.h sys/poll.h syslog.h mntent.h net/ethernet.h]) + termios.h sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h])
dnl Where are the XDR functions? dnl If portablexdr is installed, prefer that. diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 5f15a64..a07bedc 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -27,7 +27,9 @@ #include <unistd.h> #include <fcntl.h> #ifdef __linux__ -# include <linux/magic.h> +# if HAVE_LINUX_MAGIC_H +# include <linux/magic.h> +# endif
Don't bother with this - just kill this include off completely. It is a waste of time using it if we can't rely on it existing & have to re-define everything ourselves.
I admit that those numbers will probably never change, but I see including the recommended/modern header as the preferred approach. Then, eventually when the old systems are no longer relevant (yeah, in a long time) we'll be able to remove our hackish define-if-required code.
If we're going to plan todo that then we need to open a bug report against the current linux/magic.h because it is still missing many filesystems that exist today. Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

Daniel P. Berrange wrote:
On Mon, May 17, 2010 at 04:59:51PM +0200, Jim Meyering wrote:
Daniel P. Berrange wrote:
On Mon, May 17, 2010 at 04:25:43PM +0200, Jim Meyering wrote:
This is required for any kernel prior to 2.6.19, since <linux/magic.h> didn't exist back then. Now that file is provided by the kernel-headers package.
From d14ef1669968ffeb65076b007e318934ed99aa61 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Mon, 17 May 2010 16:17:08 +0200 Subject: [PATCH] build: avoid compile failure on linux kernels older than 2.6.19
* configure.ac: Check for <linux/magic.h>. * src/util/storage_file.c: Include <linux/magic.h> only if present. Linux kernels prior to 2.6.19 lacked it. [__linux__] (NFS_SUPER_MAGIC): Define if not already defined. --- configure.ac | 2 +- src/util/storage_file.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac index c187420..ebd2082 100644 --- a/configure.ac +++ b/configure.ac @@ -108,7 +108,7 @@ LIBS=$old_libs
dnl Availability of various common headers (non-fatal if missing). AC_CHECK_HEADERS([pwd.h paths.h regex.h sys/syslimits.h \ - termios.h sys/poll.h syslog.h mntent.h net/ethernet.h]) + termios.h sys/poll.h syslog.h mntent.h net/ethernet.h linux/magic.h])
dnl Where are the XDR functions? dnl If portablexdr is installed, prefer that. diff --git a/src/util/storage_file.c b/src/util/storage_file.c index 5f15a64..a07bedc 100644 --- a/src/util/storage_file.c +++ b/src/util/storage_file.c @@ -27,7 +27,9 @@ #include <unistd.h> #include <fcntl.h> #ifdef __linux__ -# include <linux/magic.h> +# if HAVE_LINUX_MAGIC_H +# include <linux/magic.h> +# endif
Don't bother with this - just kill this include off completely. It is a waste of time using it if we can't rely on it existing & have to re-define everything ourselves.
I admit that those numbers will probably never change, but I see including the recommended/modern header as the preferred approach. Then, eventually when the old systems are no longer relevant (yeah, in a long time) we'll be able to remove our hackish define-if-required code.
If we're going to plan todo that then we need to open a bug report against the current linux/magic.h because it is still missing many filesystems that exist today.
An alternative is to use something like the hard-coded list in coreutils' src/stat.c (from which src/fs.h is generated). http://git.savannah.gnu.org/cgit/coreutils.git/tree/src/stat.c#n219 It is a list of all known (to me) FS magic numbers, and src/Makefile.am includes a couple of checks that give us a chance of spotting new additions.
participants (3)
-
Chris Lalancette
-
Daniel P. Berrange
-
Jim Meyering