idmap: override btrfs_ioctl_vol_args_v2 if system header doesn't have subvolid
authorDarrick J. Wong <djwong@kernel.org>
Mon, 23 Aug 2021 18:21:38 +0000 (11:21 -0700)
committerEryu Guan <guaneryu@gmail.com>
Sun, 29 Aug 2021 13:05:45 +0000 (21:05 +0800)
The struct btrfs_ioctl_vol_args_v2 in /usr/include/linux/btrfs.h on
my system predates the inclusion of the "subvolid" field.  This
causes the following build failure:

idmapped-mounts.c: In function 'btrfs_delete_subvolume_id':
idmapped-mounts.c:9730:6: error: 'struct btrfs_ioctl_vol_args_v2' has no member named 'subvolid'
 9730 |  args.subvolid = subvolid;
      |      ^

Since this source file contains its own more uptodate copy of that
structure, add some more autoconf/cpp magic so that we can override
the struct definition if the system header doesn't have the desired
field.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
Reviewed-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Anju T Sudhakar<anju@linux.vnet.ibm.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
configure.ac
src/idmapped-mounts/idmapped-mounts.c

index 4f9f672ae691a00a64ab7b09e517f380c6af5fbd..78e9d9459a72f57164b97bb6a7d461373dd60744 100644 (file)
@@ -77,7 +77,7 @@ AC_CHECK_TYPES([struct btrfs_ioctl_ino_lookup_args], [], [], [[#include <linux/b
 AC_CHECK_TYPES([struct btrfs_ioctl_ino_lookup_user_args], [], [], [[#include <linux/btrfs.h>]])
 AC_CHECK_TYPES([struct btrfs_ioctl_get_subvol_rootref_args], [], [], [[#include <linux/btrfs.h>]])
 AC_CHECK_HEADERS([linux/btrfs.h linux/btrfs_tree.h])
-
+AC_CHECK_MEMBERS([struct btrfs_ioctl_vol_args_v2.subvolid], [], [], [[#include <linux/btrfs.h>]])
 
 AC_CONFIG_HEADER(include/config.h)
 AC_CONFIG_FILES([include/builddefs])
index 78b7cc094772a5d337c9364d676cb241c114e6a5..40eb2cc6dc00ea5002bbc8a00a1f5cd204f08feb 100644 (file)
 #include <unistd.h>
 
 #ifdef HAVE_LINUX_BTRFS_H
+# ifndef HAVE_STRUCT_BTRFS_IOCTL_VOL_ARGS_V2_SUBVOLID
+#  define btrfs_ioctl_vol_args_v2 override_btrfs_ioctl_vol_args_v2
+# endif
 #include <linux/btrfs.h>
+# undef btrfs_ioctl_vol_args_v2
 #endif
 
 #ifdef HAVE_LINUX_BTRFS_TREE_H
@@ -9570,7 +9574,7 @@ struct btrfs_qgroup_inherit {
 };
 #endif
 
-#ifndef HAVE_STRUCT_BTRFS_IOCTL_VOL_ARGS_V2
+#if !defined(HAVE_STRUCT_BTRFS_IOCTL_VOL_ARGS_V2) || !defined(HAVE_STRUCT_BTRFS_IOCTL_VOL_ARGS_V2_SUBVOLID)
 
 #ifndef BTRFS_SUBVOL_NAME_MAX
 #define BTRFS_SUBVOL_NAME_MAX 4039