Skip to contentSkip to conversation

idmap: override btrfs_ioctl_vol_args_v2 if system header doesn't have subvolid

PATCH In review Darrick J. Wong 4 participants 4 messages Aug 23, 2021 – Aug 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 idmap: override btrfs_ioctl_vol_args_v2 if system header doesn't have subvolid

From: Darrick J. Wong <[email protected]>

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.

---
 configure.ac                          |    2 +-
 src/idmapped-mounts/idmapped-mounts.c |    6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
configure.ac +1 -1
index 4117a302..36960910 100644
@@ -79,7 +79,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])
src/idmapped-mounts/idmapped-mounts.c +5 -1
index 78b7cc09..40eb2cc6 100644
@@ -23,7 +23,11 @@
 #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
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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;
| ^

Quoted 6 lines

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.

---

Looks good! Thank you for taking the time to fix this!

Reviewed-by on v1 1/1
#2 lore raw
In reply to Darrick J. Wong
Quoted 11 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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;
| ^

Quoted 6 lines

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.

---

Thanks, I just hit it[1] too. This patch works on my old and new systems, so good and helpful to me. I'd like to see it can be merged ASAP.

[1]
[CC] idmapped-mounts
[CC] mount-idmapped
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'

  args.subvolid = subvolid;
      ^

gmake[3]: *** [Makefile:30: idmapped-mounts] Error 1 gmake[2]: *** [../include/buildrules:30: idmapped-mounts] Error 2 gmake[1]: *** [include/buildrules:30: src] Error 2

Quoted 43 lines
 configure.ac                          |    2 +-
 src/idmapped-mounts/idmapped-mounts.c |    6 +++++-
 2 files changed, 6 insertions(+), 2 deletions(-)
configure.ac +1 -1
index 4117a302..36960910 100644
@@ -79,7 +79,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])
src/idmapped-mounts/idmapped-mounts.c +5 -1
index 78b7cc09..40eb2cc6 100644
@@ -23,7 +23,11 @@
 #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
Reviewed-by on v1 1/1
#3 lore raw
In reply to Darrick J. Wong
Quoted 11 lines · Darrick J. Wong

From: Darrick J. Wong <[email protected]>

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;
| ^

Quoted 6 lines

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.

---

LGTM. Thanks for fixing this issue. I too hit this issue in my system and

this patch helped me.