[CRIU] [PATCH 06/12] kdat: Config for socket netns
Pavel Emelyanov
xemul at virtuozzo.com
Mon Apr 24 13:08:00 PDT 2017
Whether or not kernel support ioctl to get socket ns
can be defined compile time.
Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
criu/cr-check.c | 10 +++-------
criu/include/sockets.h | 2 +-
criu/kerndat.c | 21 +++++++++++++++++++++
criu/net.c | 7 ++-----
4 files changed, 27 insertions(+), 13 deletions(-)
diff --git a/criu/cr-check.c b/criu/cr-check.c
index fbd566e..503ff2f 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -1101,13 +1101,9 @@ static int check_uffd(void)
static int check_sk_netns(void)
{
- if (kerndat_socket_netns() < 0)
- return -1;
-
- if (!kdat.sk_ns)
- return -1;
-
- return 0;
+ int ret;
+ ret = socket_has_netns();
+ return ret > 0 ? 0 : -1;
}
static int (*chk_feature)(void);
diff --git a/criu/include/sockets.h b/criu/include/sockets.h
index 93f9ca3..afd3c6c 100644
--- a/criu/include/sockets.h
+++ b/criu/include/sockets.h
@@ -88,6 +88,6 @@ extern int set_netns(uint32_t ns_id);
#define SIOCGSKNS 0x894C /* get socket network namespace */
#endif
-extern int kerndat_socket_netns(void);
+extern int socket_has_netns(void);
#endif /* __CR_SOCKETS_H__ */
diff --git a/criu/kerndat.c b/criu/kerndat.c
index 46b9bd7..a904e84 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -665,6 +665,27 @@ int kerndat_uffd(bool need_uffd)
return 0;
}
+#ifdef CONFIG_KERNEL_SOCK_NETNS
+static inline int kerndat_socket_netns(void)
+{
+ kdat.sk_ns = CONFIG_KERNEL_SOCK_NETNS;
+ return 0;
+}
+#else
+static int kerndat_socket_netns(void)
+{
+ int ret;
+
+ ret = socket_has_netns();
+ if (ret > 0) {
+ kdat.sk_ns = true;
+ ret = 0;
+ }
+
+ return ret;
+}
+#endif
+
int kerndat_init(void)
{
int ret;
diff --git a/criu/net.c b/criu/net.c
index b423000..9876ef4 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -2483,7 +2483,7 @@ struct ns_id *get_socket_ns(int lfd)
return ns;
}
-int kerndat_socket_netns(void)
+int socket_has_netns(void)
{
int sk, ns_fd;
@@ -2495,16 +2495,13 @@ int kerndat_socket_netns(void)
ns_fd = ioctl(sk, SIOCGSKNS);
if (ns_fd < 0) {
pr_warn("Unable to get a socket network namespace\n");
- kdat.sk_ns = false;
close(sk);
return 0;
}
close(sk);
close(ns_fd);
- kdat.sk_ns = true;
-
- return 0;
+ return 1;
}
static int move_to_bridge(struct external *ext, void *arg)
--
2.5.5
More information about the CRIU
mailing list