[CRIU] [PATCH cr 7/9] cr-dump: lock network before dump and unlock in case of errors

Andrey Vagin avagin at openvz.org
Mon Sep 17 03:50:12 EDT 2012


Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c     |    6 +++++-
 include/net.h |    3 +++
 net.c         |   26 ++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 1 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index a41fab1..58f76c7 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -48,6 +48,7 @@
 #include "pstree.h"
 #include "mount.h"
 #include "tty.h"
+#include "net.h"
 
 #include "protobuf.h"
 #include "protobuf/fdinfo.pb-c.h"
@@ -1585,6 +1586,9 @@ int cr_dump_tasks(pid_t pid, const struct cr_options *opts)
 	pr_info("Dumping processes (pid: %d)\n", pid);
 	pr_info("========================================\n");
 
+	if (network_lock())
+		goto err;
+
 	if (write_img_inventory())
 		goto err;
 
@@ -1642,7 +1646,7 @@ err:
 	 * don't, just close them silently.
 	 */
 	if (ret)
-		tcp_unlock_all();
+		network_unlock();
 	pstree_switch_state(root_item,
 			ret ? TASK_ALIVE : opts->final_state);
 	free_pstree(root_item);
diff --git a/include/net.h b/include/net.h
index b210679..fb55e07 100644
--- a/include/net.h
+++ b/include/net.h
@@ -16,4 +16,7 @@ struct veth_pair {
 	char *inside;
 	char *outside;
 };
+
+extern int network_lock(void);
+extern void network_unlock(void);
 #endif
diff --git a/net.c b/net.c
index 5988159..96fb2ca 100644
--- a/net.c
+++ b/net.c
@@ -11,6 +11,7 @@
 #include "net.h"
 #include "libnetlink.h"
 #include "crtools.h"
+#include "sk-inet.h"
 
 #include "protobuf.h"
 #include "protobuf/netdev.pb-c.h"
@@ -405,3 +406,28 @@ int netns_pre_create(void)
 	pr_info("Saved netns fd for links restore\n");
 	return 0;
 }
+
+int network_lock(void)
+{
+	pr_info("Lock network\n");
+
+	/* Each connection will be locked on dump */
+	if  (!(opts.namespaces_flags & CLONE_NEWNET))
+		return 0;
+
+	return run_scripts("network-lock");
+}
+
+void network_unlock(void)
+{
+	pr_info("Unlock network\n");
+
+	if  (!(opts.namespaces_flags & CLONE_NEWNET)) {
+		tcp_unlock_all();
+
+		return;
+	}
+
+	run_scripts("network-unlock");
+}
+
-- 
1.7.1



More information about the CRIU mailing list