0001-build-detect-where-struct-mount_attr-is-declared.patch 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. From c1115e1503bf955c97f4cf3b925a6a9f619764c3 Mon Sep 17 00:00:00 2001
  2. From: Christian Brauner <brauner@kernel.org>
  3. Date: Tue, 9 Aug 2022 16:14:25 +0200
  4. Subject: [PATCH] build: detect where struct mount_attr is declared
  5. Fixes: #4176
  6. Signed-off-by: Christian Brauner (Microsoft) <christian.brauner@ubuntu.com>
  7. [Retrieved from:
  8. https://github.com/lxc/lxc/commit/c1115e1503bf955c97f4cf3b925a6a9f619764c3]
  9. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  10. ---
  11. meson.build | 30 ++++++++++++++++++++++++++++--
  12. src/lxc/conf.c | 6 +++---
  13. src/lxc/conf.h | 2 +-
  14. src/lxc/mount_utils.c | 6 +++---
  15. src/lxc/syscall_wrappers.h | 12 ++++++++++--
  16. 5 files changed, 45 insertions(+), 11 deletions(-)
  17. diff --git a/meson.build b/meson.build
  18. index a145faf069..f679aabbc8 100644
  19. --- a/meson.build
  20. +++ b/meson.build
  21. @@ -590,7 +590,6 @@ decl_headers = '''
  22. foreach decl: [
  23. '__aligned_u64',
  24. 'struct clone_args',
  25. - 'struct mount_attr',
  26. 'struct open_how',
  27. 'struct rtnl_link_stats64',
  28. ]
  29. @@ -610,7 +609,6 @@ foreach tuple: [
  30. ['struct seccomp_notif_sizes'],
  31. ['struct clone_args'],
  32. ['__aligned_u64'],
  33. - ['struct mount_attr'],
  34. ['struct open_how'],
  35. ['struct rtnl_link_stats64'],
  36. ]
  37. @@ -630,6 +628,34 @@ foreach tuple: [
  38. endif
  39. endforeach
  40. +## Types.
  41. +decl_headers = '''
  42. +#include <sys/mount.h>
  43. +'''
  44. +
  45. +# We get -1 if the size cannot be determined
  46. +if cc.sizeof('struct mount_attr', prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
  47. + srcconf.set10('HAVE_' + 'struct mount_attr'.underscorify().to_upper(), true)
  48. + found_types += 'struct mount_attr (sys/mount.h)'
  49. +else
  50. + srcconf.set10('HAVE_' + 'struct mount_attr'.underscorify().to_upper(), false)
  51. + missing_types += 'struct mount_attr (sys/mount.h)'
  52. +endif
  53. +
  54. +## Types.
  55. +decl_headers = '''
  56. +#include <linux/mount.h>
  57. +'''
  58. +
  59. +# We get -1 if the size cannot be determined
  60. +if cc.sizeof('struct mount_attr', prefix: decl_headers, args: '-D_GNU_SOURCE') > 0
  61. + srcconf.set10('HAVE_UAPI_' + 'struct mount_attr'.underscorify().to_upper(), true)
  62. + found_types += 'struct mount_attr (linux/mount.h)'
  63. +else
  64. + srcconf.set10('HAVE_UAPI_' + 'struct mount_attr'.underscorify().to_upper(), false)
  65. + missing_types += 'struct mount_attr (linux/mount.h)'
  66. +endif
  67. +
  68. ## Headers.
  69. foreach ident: [
  70. ['bpf', '''#include <sys/syscall.h>
  71. diff --git a/src/lxc/conf.c b/src/lxc/conf.c
  72. index ffbe74c2f6..4193cd07f5 100644
  73. --- a/src/lxc/conf.c
  74. +++ b/src/lxc/conf.c
  75. @@ -2885,7 +2885,7 @@ static int __lxc_idmapped_mounts_child(struct lxc_handler *handler, FILE *f)
  76. struct lxc_mount_options opts = {};
  77. int dfd_from;
  78. const char *source_relative, *target_relative;
  79. - struct lxc_mount_attr attr = {};
  80. + struct mount_attr attr = {};
  81. ret = parse_lxc_mount_attrs(&opts, mntent.mnt_opts);
  82. if (ret < 0)
  83. @@ -3005,7 +3005,7 @@ static int __lxc_idmapped_mounts_child(struct lxc_handler *handler, FILE *f)
  84. /* Set propagation mount options. */
  85. if (opts.attr.propagation) {
  86. - attr = (struct lxc_mount_attr) {
  87. + attr = (struct mount_attr) {
  88. .propagation = opts.attr.propagation,
  89. };
  90. @@ -4109,7 +4109,7 @@ int lxc_idmapped_mounts_parent(struct lxc_handler *handler)
  91. for (;;) {
  92. __do_close int fd_from = -EBADF, fd_userns = -EBADF;
  93. - struct lxc_mount_attr attr = {};
  94. + struct mount_attr attr = {};
  95. struct lxc_mount_options opts = {};
  96. ssize_t ret;
  97. diff --git a/src/lxc/conf.h b/src/lxc/conf.h
  98. index 7dc2f15b60..772479f9e1 100644
  99. --- a/src/lxc/conf.h
  100. +++ b/src/lxc/conf.h
  101. @@ -223,7 +223,7 @@ struct lxc_mount_options {
  102. unsigned long mnt_flags;
  103. unsigned long prop_flags;
  104. char *data;
  105. - struct lxc_mount_attr attr;
  106. + struct mount_attr attr;
  107. char *raw_options;
  108. };
  109. diff --git a/src/lxc/mount_utils.c b/src/lxc/mount_utils.c
  110. index bba75f933c..88dd73ee36 100644
  111. --- a/src/lxc/mount_utils.c
  112. +++ b/src/lxc/mount_utils.c
  113. @@ -31,7 +31,7 @@ lxc_log_define(mount_utils, lxc);
  114. * setting in @attr_set, but must also specify MOUNT_ATTR__ATIME in the
  115. * @attr_clr field.
  116. */
  117. -static inline void set_atime(struct lxc_mount_attr *attr)
  118. +static inline void set_atime(struct mount_attr *attr)
  119. {
  120. switch (attr->attr_set & MOUNT_ATTR__ATIME) {
  121. case MOUNT_ATTR_RELATIME:
  122. @@ -272,7 +272,7 @@ int create_detached_idmapped_mount(const char *path, int userns_fd,
  123. {
  124. __do_close int fd_tree_from = -EBADF;
  125. unsigned int open_tree_flags = OPEN_TREE_CLONE | OPEN_TREE_CLOEXEC;
  126. - struct lxc_mount_attr attr = {
  127. + struct mount_attr attr = {
  128. .attr_set = MOUNT_ATTR_IDMAP | attr_set,
  129. .attr_clr = attr_clr,
  130. .userns_fd = userns_fd,
  131. @@ -335,7 +335,7 @@ int __fd_bind_mount(int dfd_from, const char *path_from, __u64 o_flags_from,
  132. __u64 attr_clr, __u64 propagation, int userns_fd,
  133. bool recursive)
  134. {
  135. - struct lxc_mount_attr attr = {
  136. + struct mount_attr attr = {
  137. .attr_set = attr_set,
  138. .attr_clr = attr_clr,
  139. .propagation = propagation,
  140. diff --git a/src/lxc/syscall_wrappers.h b/src/lxc/syscall_wrappers.h
  141. index a5e98b565c..c8a7d0c7b7 100644
  142. --- a/src/lxc/syscall_wrappers.h
  143. +++ b/src/lxc/syscall_wrappers.h
  144. @@ -18,6 +18,12 @@
  145. #include "macro.h"
  146. #include "syscall_numbers.h"
  147. +#if HAVE_STRUCT_MOUNT_ATTR
  148. +#include <sys/mount.h>
  149. +#elif HAVE_UAPI_STRUCT_MOUNT_ATTR
  150. +#include <linux/mount.h>
  151. +#endif
  152. +
  153. #ifdef HAVE_LINUX_MEMFD_H
  154. #include <linux/memfd.h>
  155. #endif
  156. @@ -210,16 +216,18 @@ extern int fsmount(int fs_fd, unsigned int flags, unsigned int attr_flags);
  157. /*
  158. * mount_setattr()
  159. */
  160. -struct lxc_mount_attr {
  161. +#if !HAVE_STRUCT_MOUNT_ATTR && !HAVE_UAPI_STRUCT_MOUNT_ATTR
  162. +struct mount_attr {
  163. __u64 attr_set;
  164. __u64 attr_clr;
  165. __u64 propagation;
  166. __u64 userns_fd;
  167. };
  168. +#endif
  169. #if !HAVE_MOUNT_SETATTR
  170. static inline int mount_setattr(int dfd, const char *path, unsigned int flags,
  171. - struct lxc_mount_attr *attr, size_t size)
  172. + struct mount_attr *attr, size_t size)
  173. {
  174. return syscall(__NR_mount_setattr, dfd, path, flags, attr, size);
  175. }