[07/12] kdat: Config for nsids

Submitted by Pavel Emelianov on April 24, 2017, 8:08 p.m.

Details

Message ID 58FE5B2D.2000109@virtuozzo.com
State New
Series "Speed up kdat checks"
Headers show

Commit Message

Pavel Emelianov April 24, 2017, 8:08 p.m.
Whether or not kernel support nsids can be found out compile time.

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/cr-check.c    |  7 +++++--
 criu/include/net.h |  2 +-
 criu/kerndat.c     | 25 +++++++++++++++++++++++--
 3 files changed, 29 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/cr-check.c b/criu/cr-check.c
index 503ff2f..78386d4 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -1242,10 +1242,13 @@  static int check_tun(void)
 
 static int check_nsid(void)
 {
-	if (kerndat_nsid() < 0)
+	int ret;
+
+	ret = kernel_has_nsid();
+	if (ret < 0)
 		return -1;
 
-	if (!kdat.has_nsid) {
+	if (!ret) {
 		pr_warn("NSID isn't supported\n");
 		return -1;
 	}
diff --git a/criu/include/net.h b/criu/include/net.h
index 796dcc4..b90577d 100644
--- a/criu/include/net.h
+++ b/criu/include/net.h
@@ -47,6 +47,6 @@  extern int move_veth_to_bridge(void);
 
 extern int kerndat_link_nsid(void);
 extern int net_get_nsid(int rtsk, int fd, int *nsid);
-extern int kerndat_nsid(void);
+extern int kernel_has_nsid(void);
 
 #endif /* __CR_NET_H__ */
diff --git a/criu/kerndat.c b/criu/kerndat.c
index a904e84..837ddee 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -596,7 +596,7 @@  static int kerndat_tcp_repair(void)
 }
 #endif
 
-int kerndat_nsid(void)
+int kernel_has_nsid(void)
 {
 	int nsid, sk;
 
@@ -609,13 +609,34 @@  int kerndat_nsid(void)
 	if (net_get_nsid(sk, getpid(), &nsid) < 0) {
 		pr_err("NSID is not supported\n");
 		close(sk);
-		return -1;
+		return 0;
 	}
 
 	kdat.has_nsid = true;
 	close(sk);
+	return 1;
+}
+
+#ifdef CONFIG_KERNEL_NSID
+static inline int kerndat_nsid(void)
+{
+	kdat.has_nsid = CONFIG_KERNEL_NSID;
 	return 0;
 }
+#else
+static int kerndat_nsid(void)
+{
+	int ret;
+
+	ret = kernel_has_nsid();
+	if (ret > 0) {
+		kdat.has_nsid = true;
+		ret = 0;
+	}
+
+	return 0;
+}
+#endif
 
 static int kerndat_compat_restore(void)
 {