* [PATCH v1 1/4] src/idmapped-mounts: Fix an error for the loop initialization declaration
@ 2021-09-01 12:43 Yang Xu
2021-09-01 12:43 ` [PATCH v1 2/4] configure.ac: Fix uncorrect detection because of linux/btrfs.h Yang Xu
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Yang Xu @ 2021-09-01 12:43 UTC (permalink / raw)
To: fstests; +Cc: Yang Xu
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
src/idmapped-mounts/idmapped-mounts.c | 30 +++++++++++++--------------
src/idmapped-mounts/utils.c | 3 ++-
2 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/src/idmapped-mounts/idmapped-mounts.c b/src/idmapped-mounts/idmapped-mounts.c
index 40eb2cc6..e83f8b04 100644
--- a/src/idmapped-mounts/idmapped-mounts.c
+++ b/src/idmapped-mounts/idmapped-mounts.c
@@ -8838,6 +8838,7 @@ static int nested_userns(void)
int fret = -1;
int ret;
pid_t pid;
+ unsigned int id;
struct list *it, *next;
struct userns_hierarchy hierarchy[] = {
{ .level = 1, .fd_userns = -EBADF, },
@@ -8979,7 +8980,7 @@ static int nested_userns(void)
goto out;
}
- for (unsigned int id = 0; id <= id_file_range; id++) {
+ for (id = 0; id <= id_file_range; id++) {
char file[256];
snprintf(file, sizeof(file), DIR1 "/" FILE1 "_%u", id);
@@ -9067,7 +9068,7 @@ static int nested_userns(void)
}
/* Verify that ownership looks correct for callers in the init userns. */
- for (unsigned int id = 0; id <= id_file_range; id++) {
+ for (id = 0; id <= id_file_range; id++) {
bool bret;
unsigned int id_level1, id_level2, id_level3;
char file[256];
@@ -9117,7 +9118,7 @@ static int nested_userns(void)
if (!switch_userns(attr_level1.userns_fd, 0, 0, false))
die("failure: switch_userns");
- for (unsigned int id = 0; id <= id_file_range; id++) {
+ for (id = 0; id <= id_file_range; id++) {
bool bret;
unsigned int id_level1, id_level2, id_level3;
char file[256];
@@ -9164,7 +9165,7 @@ static int nested_userns(void)
if (!switch_userns(attr_level2.userns_fd, 0, 0, false))
die("failure: switch_userns");
- for (unsigned int id = 0; id <= id_file_range; id++) {
+ for (id = 0; id <= id_file_range; id++) {
bool bret;
unsigned int id_level2, id_level3;
char file[256];
@@ -9210,7 +9211,7 @@ static int nested_userns(void)
if (!switch_userns(attr_level3.userns_fd, 0, 0, false))
die("failure: switch_userns");
- for (unsigned int id = 0; id <= id_file_range; id++) {
+ for (id = 0; id <= id_file_range; id++) {
bool bret;
unsigned int id_level2, id_level3;
char file[256];
@@ -9267,7 +9268,7 @@ static int nested_userns(void)
if (setns(attr_level4.userns_fd, CLONE_NEWUSER))
die("failure: switch_userns");
- for (unsigned int id = 0; id <= id_file_range; id++) {
+ for (id = 0; id <= id_file_range; id++) {
char file[256];
snprintf(file, sizeof(file), FILE1 "_%u", id);
@@ -9300,7 +9301,7 @@ static int nested_userns(void)
if (!switch_userns(attr_level1.userns_fd, 0, 0, false))
die("failure: switch_userns");
- for (unsigned int id = 0; id <= id_file_range; id++) {
+ for (id = 0; id <= id_file_range; id++) {
bool bret;
unsigned int id_level1, id_level2, id_level3, id_new;
char file[256];
@@ -9355,7 +9356,7 @@ static int nested_userns(void)
if (!switch_userns(attr_level2.userns_fd, 0, 0, false))
die("failure: switch_userns");
- for (unsigned int id = 0; id <= id_file_range; id++) {
+ for (id = 0; id <= id_file_range; id++) {
bool bret;
unsigned int id_level2, id_level3, id_new;
char file[256];
@@ -9409,7 +9410,7 @@ static int nested_userns(void)
if (!switch_userns(attr_level3.userns_fd, 0, 0, false))
die("failure: switch_userns");
- for (unsigned int id = 0; id <= id_file_range; id++) {
+ for (id = 0; id <= id_file_range; id++) {
unsigned int id_new;
char file[256];
@@ -9479,7 +9480,7 @@ static int nested_userns(void)
if (setns(attr_level4.userns_fd, CLONE_NEWUSER))
die("failure: switch_userns");
- for (unsigned int id = 0; id <= id_file_range; id++) {
+ for (id = 0; id <= id_file_range; id++) {
char file[256];
unsigned long id_new;
@@ -9909,7 +9910,6 @@ static int append_stack(struct btrfs_iter *iter, uint64_t tree_id, size_t path_l
if (iter->stack_len >= iter->stack_capacity) {
size_t new_capacity = iter->stack_capacity * 2;
struct btrfs_stack *new_search_stack;
-
new_search_stack = reallocarray(iter->search_stack, new_capacity,
sizeof(*iter->search_stack));
if (!new_search_stack)
@@ -12932,7 +12932,7 @@ out:
*/
static int btrfs_subvolume_lookup_user(void)
{
- int fret = -1;
+ int fret = -1, i;
int dir1_fd = -EBADF, dir2_fd = -EBADF, mnt_fd = -EBADF,
open_tree_fd = -EBADF, tree_fd = -EBADF, userns_fd = -EBADF;
int subvolume_fds[BTRFS_SUBVOLUME_SUBVOL4_ID + 1];
@@ -12947,10 +12947,10 @@ static int btrfs_subvolume_lookup_user(void)
if (!caps_supported())
return 0;
- for (int i = 0; i < ARRAY_SIZE(subvolume_fds); i++)
+ for (i = 0; i < ARRAY_SIZE(subvolume_fds); i++)
subvolume_fds[i] = -EBADF;
- for (int i = 0; i < ARRAY_SIZE(subvolume_ids); i++)
+ for (i = 0; i < ARRAY_SIZE(subvolume_ids); i++)
subvolume_ids[i] = -EINVAL;
if (btrfs_create_subvolume(t_mnt_scratch_fd, BTRFS_SUBVOLUME_SUBVOL1)) {
@@ -13312,7 +13312,7 @@ out:
safe_close(open_tree_fd);
safe_close(tree_fd);
safe_close(userns_fd);
- for (int i = 0; i < ARRAY_SIZE(subvolume_fds); i++)
+ for (i = 0; i < ARRAY_SIZE(subvolume_fds); i++)
safe_close(subvolume_fds[i]);
snprintf(t_buf, sizeof(t_buf), "%s/%s", t_mountpoint, BTRFS_SUBVOLUME_MNT);
sys_umount2(t_buf, MNT_DETACH);
diff --git a/src/idmapped-mounts/utils.c b/src/idmapped-mounts/utils.c
index 6ffd6a23..c2afa8dc 100644
--- a/src/idmapped-mounts/utils.c
+++ b/src/idmapped-mounts/utils.c
@@ -140,11 +140,12 @@ static int map_ids_from_idmap(struct list *idmap, pid_t pid)
int fill, left;
char mapbuf[4096] = {};
bool had_entry = false;
+ idmap_type_t map_type, u_or_g;
if (list_empty(idmap))
return 0;
- for (idmap_type_t map_type = ID_TYPE_UID, u_or_g = 'u';
+ for (map_type = ID_TYPE_UID, u_or_g = 'u';
map_type <= ID_TYPE_GID; map_type++, u_or_g = 'g') {
char *pos = mapbuf;
int ret;
--
2.23.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v1 2/4] configure.ac: Fix uncorrect detection because of linux/btrfs.h
2021-09-01 12:43 [PATCH v1 1/4] src/idmapped-mounts: Fix an error for the loop initialization declaration Yang Xu
@ 2021-09-01 12:43 ` Yang Xu
2021-09-01 12:43 ` [PATCH v1 3/4] src/idmapped-mounts/idmapped-mounts.c: Use renameat instead of renameat2 Yang Xu
2021-09-01 12:43 ` [PATCH v1 4/4] src/idmapped-mounts/idmapped-mounts.c: Fix build error because of undefined reallocarray Yang Xu
2 siblings, 0 replies; 4+ messages in thread
From: Yang Xu @ 2021-09-01 12:43 UTC (permalink / raw)
To: fstests; +Cc: Yang Xu
On old distros, we can't detect some btrfs structs because of undeclared 'NULL' in
btrfs_err_str function. This function has been removed after kernel
commit 68598d2ea8863 ("btrfs: remove btrfs_err_str function from uapi/linux/btrfs.h").
Fix this bug in xfstests layer by adding stddef.h because NULL is defined in stddef.h(it is
in /usr/lib/gcc*/ directory).
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
configure.ac | 40 ++++++++++++++++++++++++++++++++--------
1 file changed, 32 insertions(+), 8 deletions(-)
diff --git a/configure.ac b/configure.ac
index 78e9d945..0b55455a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -69,15 +69,39 @@ AC_PACKAGE_WANT_LIBBTRFSUTIL
AC_HAVE_COPY_FILE_RANGE
AC_CHECK_FUNCS([renameat2])
AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]])
-AC_CHECK_TYPES([struct btrfs_qgroup_limit], [], [], [[#include <linux/btrfs.h>]])
-AC_CHECK_TYPES([struct btrfs_qgroup_inherit], [], [], [[#include <linux/btrfs.h>]])
-AC_CHECK_TYPES([struct btrfs_ioctl_vol_args], [], [], [[#include <linux/btrfs.h>]])
-AC_CHECK_TYPES([struct btrfs_ioctl_vol_args_v2], [], [], [[#include <linux/btrfs.h>]])
-AC_CHECK_TYPES([struct btrfs_ioctl_ino_lookup_args], [], [], [[#include <linux/btrfs.h>]])
-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_TYPES([struct btrfs_qgroup_limit], [], [], [[
+#include <stddef.h>
+#include <linux/btrfs.h>
+]])
+AC_CHECK_TYPES([struct btrfs_qgroup_inherit], [], [], [[
+#include <stddef.h>
+#include <linux/btrfs.h>
+]])
+AC_CHECK_TYPES([struct btrfs_ioctl_vol_args], [], [], [[
+#include <stddef.h>
+#include <linux/btrfs.h>
+]])
+AC_CHECK_TYPES([struct btrfs_ioctl_vol_args_v2], [], [], [[
+#include <stddef.h>
+#include <linux/btrfs.h>
+]])
+AC_CHECK_TYPES([struct btrfs_ioctl_ino_lookup_args], [], [], [[
+#include <stddef.h>
+#include <linux/btrfs.h>
+]])
+AC_CHECK_TYPES([struct btrfs_ioctl_ino_lookup_user_args], [], [], [[
+#include <stddef.h>
+#include <linux/btrfs.h>
+]])
+AC_CHECK_TYPES([struct btrfs_ioctl_get_subvol_rootref_args], [], [], [[
+#include <stddef.h>
+#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_CHECK_MEMBERS([struct btrfs_ioctl_vol_args_v2.subvolid], [], [], [[
+#include <stddef.h>
+#include <linux/btrfs.h>
+]])
AC_CONFIG_HEADER(include/config.h)
AC_CONFIG_FILES([include/builddefs])
--
2.23.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v1 3/4] src/idmapped-mounts/idmapped-mounts.c: Use renameat instead of renameat2
2021-09-01 12:43 [PATCH v1 1/4] src/idmapped-mounts: Fix an error for the loop initialization declaration Yang Xu
2021-09-01 12:43 ` [PATCH v1 2/4] configure.ac: Fix uncorrect detection because of linux/btrfs.h Yang Xu
@ 2021-09-01 12:43 ` Yang Xu
2021-09-01 12:43 ` [PATCH v1 4/4] src/idmapped-mounts/idmapped-mounts.c: Fix build error because of undefined reallocarray Yang Xu
2 siblings, 0 replies; 4+ messages in thread
From: Yang Xu @ 2021-09-01 12:43 UTC (permalink / raw)
To: fstests; +Cc: Yang Xu
We don't add fallback for renameat2, so it build failed on old
kernel. So use renameat instead.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
src/idmapped-mounts/idmapped-mounts.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/idmapped-mounts/idmapped-mounts.c b/src/idmapped-mounts/idmapped-mounts.c
index e83f8b04..4230cb48 100644
--- a/src/idmapped-mounts/idmapped-mounts.c
+++ b/src/idmapped-mounts/idmapped-mounts.c
@@ -10433,9 +10433,9 @@ static int btrfs_subvolumes_fsids_unmapped(void)
}
/* try to rename a subvolume */
- if (!renameat2(open_tree_fd, BTRFS_SUBVOLUME1, open_tree_fd,
- BTRFS_SUBVOLUME1_RENAME, 0)) {
- log_stderr("failure: renameat2");
+ if (!renameat(open_tree_fd, BTRFS_SUBVOLUME1, open_tree_fd,
+ BTRFS_SUBVOLUME1_RENAME)) {
+ log_stderr("failure: renameat");
goto out;
}
if (errno != EOVERFLOW) {
@@ -10552,9 +10552,9 @@ static int btrfs_subvolumes_fsids_unmapped_userns(void)
die("failure: errno");
/* try to rename a subvolume */
- if (!renameat2(open_tree_fd, BTRFS_SUBVOLUME1, open_tree_fd,
- BTRFS_SUBVOLUME1_RENAME, 0))
- die("failure: renameat2");
+ if (!renameat(open_tree_fd, BTRFS_SUBVOLUME1, open_tree_fd,
+ BTRFS_SUBVOLUME1_RENAME))
+ die("failure: renameat");
if (errno != EOVERFLOW)
die("failure: errno");
@@ -10993,9 +10993,9 @@ static int btrfs_snapshots_fsids_unmapped(void)
die("failure: errno");
/* try to rename a directory */
- if (!renameat2(open_tree_fd, BTRFS_SUBVOLUME1, open_tree_fd,
- BTRFS_SUBVOLUME1_RENAME, 0))
- die("failure: renameat2");
+ if (!renameat(open_tree_fd, BTRFS_SUBVOLUME1, open_tree_fd,
+ BTRFS_SUBVOLUME1_RENAME))
+ die("failure: renameat");
if (errno != EOVERFLOW)
die("failure: errno");
@@ -11174,9 +11174,9 @@ static int btrfs_snapshots_fsids_unmapped_userns(void)
die("failure: errno");
/* try to rename a directory */
- if (!renameat2(open_tree_fd, BTRFS_SUBVOLUME1, open_tree_fd,
- BTRFS_SUBVOLUME1_RENAME, 0))
- die("failure: renameat2");
+ if (!renameat(open_tree_fd, BTRFS_SUBVOLUME1, open_tree_fd,
+ BTRFS_SUBVOLUME1_RENAME))
+ die("failure: renameat");
if (errno != EOVERFLOW)
die("failure: errno");
--
2.23.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v1 4/4] src/idmapped-mounts/idmapped-mounts.c: Fix build error because of undefined reallocarray
2021-09-01 12:43 [PATCH v1 1/4] src/idmapped-mounts: Fix an error for the loop initialization declaration Yang Xu
2021-09-01 12:43 ` [PATCH v1 2/4] configure.ac: Fix uncorrect detection because of linux/btrfs.h Yang Xu
2021-09-01 12:43 ` [PATCH v1 3/4] src/idmapped-mounts/idmapped-mounts.c: Use renameat instead of renameat2 Yang Xu
@ 2021-09-01 12:43 ` Yang Xu
2 siblings, 0 replies; 4+ messages in thread
From: Yang Xu @ 2021-09-01 12:43 UTC (permalink / raw)
To: fstests; +Cc: Yang Xu
On old glibc, reallocarray was not introduced, so this case compiles failed.
We should use reallocarray if glibc supports and use realloc if glibcs doesn't
support reallocarray.
Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
configure.ac | 1 +
src/idmapped-mounts/idmapped-mounts.c | 4 ++++
2 files changed, 5 insertions(+)
diff --git a/configure.ac b/configure.ac
index 0b55455a..6e5ab397 100644
--- a/configure.ac
+++ b/configure.ac
@@ -68,6 +68,7 @@ AC_PACKAGE_WANT_LIBBTRFSUTIL
AC_HAVE_COPY_FILE_RANGE
AC_CHECK_FUNCS([renameat2])
+AC_CHECK_FUNCS([reallocarray])
AC_CHECK_TYPES([struct mount_attr], [], [], [[#include <linux/mount.h>]])
AC_CHECK_TYPES([struct btrfs_qgroup_limit], [], [], [[
#include <stddef.h>
diff --git a/src/idmapped-mounts/idmapped-mounts.c b/src/idmapped-mounts/idmapped-mounts.c
index 4230cb48..83b7c89a 100644
--- a/src/idmapped-mounts/idmapped-mounts.c
+++ b/src/idmapped-mounts/idmapped-mounts.c
@@ -9910,8 +9910,12 @@ static int append_stack(struct btrfs_iter *iter, uint64_t tree_id, size_t path_l
if (iter->stack_len >= iter->stack_capacity) {
size_t new_capacity = iter->stack_capacity * 2;
struct btrfs_stack *new_search_stack;
+#ifdef HAVE_REALLOCARRAY
new_search_stack = reallocarray(iter->search_stack, new_capacity,
sizeof(*iter->search_stack));
+#else
+ new_search_stack = realloc(iter->search_stack, new_capacity * sizeof(*iter->search_stack));
+#endif
if (!new_search_stack)
return -ENOMEM;
--
2.23.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-01 12:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-01 12:43 [PATCH v1 1/4] src/idmapped-mounts: Fix an error for the loop initialization declaration Yang Xu
2021-09-01 12:43 ` [PATCH v1 2/4] configure.ac: Fix uncorrect detection because of linux/btrfs.h Yang Xu
2021-09-01 12:43 ` [PATCH v1 3/4] src/idmapped-mounts/idmapped-mounts.c: Use renameat instead of renameat2 Yang Xu
2021-09-01 12:43 ` [PATCH v1 4/4] src/idmapped-mounts/idmapped-mounts.c: Fix build error because of undefined reallocarray Yang Xu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).