0001-lib-fs-fix-issue-when-name-open-_to_handle_at-is-not.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. From c5b72cc56bf88160bbf477ec8565fed865e7a1c9 Mon Sep 17 00:00:00 2001
  2. From: Heiko Thiery <heiko.thiery@gmail.com>
  3. Date: Sat, 8 May 2021 08:49:26 +0200
  4. Subject: [PATCH] lib/fs: fix issue when {name,open}_to_handle_at() is not
  5. implemented
  6. With commit d5e6ee0dac64 the usage of functions name_to_handle_at() and
  7. open_by_handle_at() are introduced. But these function are not available
  8. e.g. in uclibc-ng < 1.0.35. To have a backward compatibility check for the
  9. availability in the configure script and in case of absence do a direct
  10. syscall.
  11. Fixes: d5e6ee0dac64 ("ss: introduce cgroup2 cache and helper functions")
  12. Cc: Dmitry Yakunin <zeil@yandex-team.ru>
  13. Cc: Petr Vorel <petr.vorel@gmail.com>
  14. Signed-off-by: Heiko Thiery <heiko.thiery@gmail.com>
  15. Reviewed-by: Petr Vorel <petr.vorel@gmail.com>
  16. Signed-off-by: David Ahern <dsahern@kernel.org>
  17. [ upstream-status: https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=c5b72cc56bf88160bbf477ec8565fed865e7a1c9 ]
  18. ---
  19. configure | 28 ++++++++++++++++++++++++++++
  20. lib/fs.c | 25 +++++++++++++++++++++++++
  21. 2 files changed, 53 insertions(+)
  22. diff --git a/configure b/configure
  23. index 2c363d3b..179eae08 100755
  24. --- a/configure
  25. +++ b/configure
  26. @@ -202,6 +202,31 @@ EOF
  27. rm -f $TMPDIR/setnstest.c $TMPDIR/setnstest
  28. }
  29. +check_name_to_handle_at()
  30. +{
  31. + cat >$TMPDIR/name_to_handle_at_test.c <<EOF
  32. +#define _GNU_SOURCE
  33. +#include <sys/types.h>
  34. +#include <sys/stat.h>
  35. +#include <fcntl.h>
  36. +int main(int argc, char **argv)
  37. +{
  38. + struct file_handle *fhp;
  39. + int mount_id, flags, dirfd;
  40. + char *pathname;
  41. + name_to_handle_at(dirfd, pathname, fhp, &mount_id, flags);
  42. + return 0;
  43. +}
  44. +EOF
  45. + if $CC -I$INCLUDE -o $TMPDIR/name_to_handle_at_test $TMPDIR/name_to_handle_at_test.c >/dev/null 2>&1; then
  46. + echo "yes"
  47. + echo "CFLAGS += -DHAVE_HANDLE_AT" >>$CONFIG
  48. + else
  49. + echo "no"
  50. + fi
  51. + rm -f $TMPDIR/name_to_handle_at_test.c $TMPDIR/name_to_handle_at_test
  52. +}
  53. +
  54. check_ipset()
  55. {
  56. cat >$TMPDIR/ipsettest.c <<EOF
  57. @@ -492,6 +517,9 @@ fi
  58. echo -n "libc has setns: "
  59. check_setns
  60. +echo -n "libc has name_to_handle_at: "
  61. +check_name_to_handle_at
  62. +
  63. echo -n "SELinux support: "
  64. check_selinux
  65. diff --git a/lib/fs.c b/lib/fs.c
  66. index f161d888..05697a7e 100644
  67. --- a/lib/fs.c
  68. +++ b/lib/fs.c
  69. @@ -25,11 +25,36 @@
  70. #include "utils.h"
  71. +#ifndef HAVE_HANDLE_AT
  72. +# include <sys/syscall.h>
  73. +#endif
  74. +
  75. #define CGROUP2_FS_NAME "cgroup2"
  76. /* if not already mounted cgroup2 is mounted here for iproute2's use */
  77. #define MNT_CGRP2_PATH "/var/run/cgroup2"
  78. +
  79. +#ifndef HAVE_HANDLE_AT
  80. +struct file_handle {
  81. + unsigned handle_bytes;
  82. + int handle_type;
  83. + unsigned char f_handle[];
  84. +};
  85. +
  86. +static int name_to_handle_at(int dirfd, const char *pathname,
  87. + struct file_handle *handle, int *mount_id, int flags)
  88. +{
  89. + return syscall(__NR_name_to_handle_at, dirfd, pathname, handle,
  90. + mount_id, flags);
  91. +}
  92. +
  93. +static int open_by_handle_at(int mount_fd, struct file_handle *handle, int flags)
  94. +{
  95. + return syscall(__NR_open_by_handle_at, mount_fd, handle, flags);
  96. +}
  97. +#endif
  98. +
  99. /* return mount path of first occurrence of given fstype */
  100. static char *find_fs_mount(const char *fs_to_find)
  101. {
  102. --
  103. 2.31.1