Skip to contentSkip to conversation

Extract libclone from testcases/kernel/containers

PATCH In review Andrea Cervesato 4 participants 6 messages Feb 1, 2022 – Feb 3, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Extract libclone from testcases/kernel/containers

libclone has been added to the libs folder and updated with the new LTP API. This library will be used by containers tests, which will be updated to the new LTP API as well.

---
 include/libclone.h          |  61 ++++++++++++++
 libs/libltpclone/Makefile   |  12 +++
 libs/libltpclone/libclone.c | 155 ++++++++++++++++++++++++++++++++++++
 3 files changed, 228 insertions(+)
 create mode 100644 include/libclone.h
 create mode 100644 libs/libltpclone/Makefile
 create mode 100644 libs/libltpclone/libclone.c
include/libclone.h new file +61 -0
new file mode 100644
index 000000000..9ffa35165
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
+ */
+
+#ifndef __LIBCLONE_H
+#define __LIBCLONE_H
+
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/namespaces_constants.h"
+
+#define T_UNSHARE 0
+#define T_CLONE 1
+#define T_NONE 2
+
+#ifndef SYS_unshare
+#ifdef __NR_unshare
+#define SYS_unshare __NR_unshare
+#elif __i386__
+#define SYS_unshare 310
+#elif __ia64__
+#define SYS_unshare 1296
+#elif __x86_64__
+#define SYS_unshare 272
+#elif __s390x__ || __s390__
+#define SYS_unshare 303
+#elif __powerpc__
+#define SYS_unshare 282
+#else
+#error "unshare not supported on this architecure."
+#endif
+#endif
+
+#ifndef __NR_unshare
+#define __NR_unshare SYS_unshare
+#endif
+
+/*
+ * Run fn1 in a unshared environmnent, and fn2 in the original context
+ * Fn2 may be NULL.
+ */
+
+int tst_clone_tests(unsigned long clone_flags, int (*fn1)(void *arg),
+		    void *arg1, int (*fn2)(void *arg), void *arg2);
+
+int tst_unshare_tests(unsigned long clone_flags, int (*fn1)(void *arg),
+		      void *arg1, int (*fn2)(void *arg), void *arg2);
+
+int tst_fork_tests(int (*fn1)(void *arg), void *arg1, int (*fn2)(void *arg),
+		   void *arg2);
+
+int tst_clone_unshare_test(int use_clone, unsigned long clone_flags,
+			   int (*fn1)(void *arg), void *arg1);
+
+int tst_clone_unshare_tests(int use_clone, unsigned long clone_flags,
+			    int (*fn1)(void *arg), void *arg1,
+			    int (*fn2)(void *arg), void *arg2);
+
+#endif
libs/libltpclone/Makefile new file +12 -0
new file mode 100644
index 000000000..c869f6cf8
@@ -0,0 +1,12 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2007
+# Copyright (C) 2021 SUSE LLC Andrea Cervesato <[email protected]>
+
+top_srcdir		?= ../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INTERNAL_LIB		= libltpclone.a
+
+include $(top_srcdir)/include/mk/lib.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
libs/libltpclone/libclone.c new file +155 -0

155 lines not on this page · raw message

Signature · 5 lines
2.34.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Andrea,

[ Cc Richie, Li ]
https://lore.kernel.org/ltp/[email protected]/

Quoted 3 lines

libclone has been added to the libs folder and updated with the new LTP API. This library will be used by containers tests, which will be updated to the new LTP API as well.

I suppose you want to use it for containers (still use legacy API), which already use it. I remember Richie not considering libclone.h as a good source and suggesting to use SAFE_CLONE() for simple cases.

https://lore.kernel.org/ltp/[email protected]/

We probably need some wrapper for containers, but we should recheck, whether we want to take a different approach. Code in the functions is really a bit weird.

...

Quoted 7 lines
include/libclone.h new file +7 -0
+#ifndef SYS_unshare
+#ifdef __NR_unshare
+#define SYS_unshare __NR_unshare
+#elif __i386__
+#define SYS_unshare 310
+#elif __ia64__
+#define SYS_unshare 1296

include/libclone.h line 34

Quoted 10 lines
include/libclone.h new file +10 -0
+#elif __x86_64__
+#define SYS_unshare 272
+#elif __s390x__ || __s390__
+#define SYS_unshare 303
+#elif __powerpc__
+#define SYS_unshare 282
+#else
+#error "unshare not supported on this architecure."
+#endif
+#endif

nit: we usually put space before define for a readability.

#ifndef SYS_unshare
#ifdef __NR_unshare

# define SYS_unshare __NR_unshare
#elif __i386__
# define SYS_unshare 310
#elif __ia64__
# define SYS_unshare 1296
...

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Hello,

Quoted 8 lines · Petr Vorel

Hi Andrea,

[ Cc Richie, Li ]
https://lore.kernel.org/ltp/[email protected]/

Quoted 3 lines

libclone has been added to the libs folder and updated with the new LTP API. This library will be used by containers tests, which will be updated to the new LTP API as well.

Quoted 9 lines

I suppose you want to use it for containers (still use legacy API), which already use it. I remember Richie not considering libclone.h as a good source and suggesting to use SAFE_CLONE() for simple cases.

https://lore.kernel.org/ltp/[email protected]/

We probably need some wrapper for containers, but we should recheck, whether we want to take a different approach. Code in the functions is really a bit weird.

Yeah tst_clone.{c,h} is the new library which uses clone3 + a compatability layer if clone3 is not available. This avoids reinventing a cloning API to some extent because the clone3 interface is nice IMO.

Also IMO tests should be rewritten to use tst_clone, I just haven't had chance to do that.

BTW we need to test cloning into a CGroup, so I'll probably add that soon.

Signature · 5 lines
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Hi!

Quoted 21 lines · Richard Palethorpe

Hello,

Quoted 8 lines · Petr Vorel

Hi Andrea,

[ Cc Richie, Li ]
https://lore.kernel.org/ltp/[email protected]/

Quoted 3 lines

libclone has been added to the libs folder and updated with the new LTP API. This library will be used by containers tests, which will be updated to the new LTP API as well.

Quoted 9 lines

I suppose you want to use it for containers (still use legacy API), which already use it. I remember Richie not considering libclone.h as a good source and suggesting to use SAFE_CLONE() for simple cases.

https://lore.kernel.org/ltp/[email protected]/

We probably need some wrapper for containers, but we should recheck, whether we want to take a different approach. Code in the functions is really a bit weird.

Quoted 6 lines

Yeah tst_clone.{c,h} is the new library which uses clone3 + a compatability layer if clone3 is not available. This avoids reinventing a cloning API to some extent because the clone3 interface is nice IMO.

Also IMO tests should be rewritten to use tst_clone, I just haven't had chance to do that.

libclone does also a several other things, such as executing a process under unshared namespace and that is used by mountns testcases. So maybe we can just call it in an another way or find a way to recycle the libclone code.

Quoted 3 lines

BTW we need to test cloning into a CGroup, so I'll probably add that soon.

Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Hi,

an update about the last comments: the unshared clone is only used by mountns tests suite, so we can add that to the common utilities and get back to tst_clone for the other testing suites. I'm going to do that.

Andrea

Quoted 35 lines · Andrea Cervesato

Hi!

Quoted 21 lines · Richard Palethorpe

Hello,

Quoted 8 lines · Petr Vorel

Hi Andrea,

[ Cc Richie, Li ]
https://lore.kernel.org/ltp/[email protected]/

Quoted 3 lines

libclone has been added to the libs folder and updated with the new LTP API. This library will be used by containers tests, which will be updated to the new LTP API as well.

Quoted 9 lines

I suppose you want to use it for containers (still use legacy API), which already use it. I remember Richie not considering libclone.h as a good source and suggesting to use SAFE_CLONE() for simple cases.

https://lore.kernel.org/ltp/[email protected]/

We probably need some wrapper for containers, but we should recheck, whether we want to take a different approach. Code in the functions is really a bit weird.

Quoted 6 lines

Yeah tst_clone.{c,h} is the new library which uses clone3 + a compatability layer if clone3 is not available. This avoids reinventing a cloning API to some extent because the clone3 interface is nice IMO.

Also IMO tests should be rewritten to use tst_clone, I just haven't had chance to do that.

libclone does also a several other things, such as executing a process under unshared namespace and that is used by mountns testcases. So maybe we can just call it in an another way or find a way to recycle the libclone code.

Quoted 3 lines

BTW we need to test cloning into a CGroup, so I'll probably add that soon.

Signature · 2 lines
-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw
Quoted 5 lines

Hi,

an update about the last comments: the unshared clone is only used by mountns tests suite, so we can add that to the common utilities and get back to tst_clone for the other testing suites. I'm going to do that.

Thanks! Thus setting this as rejected.

Kind regards,
Petr

Quoted 1 line

Andrea

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp