[CRIU] [PATCH 4/8] net: Add ability to dump external links with plugins

Pavel Emelyanov xemul at parallels.com
Thu Dec 26 05:00:05 PST 2013


If we meet a link we cannot dump we call plugin to check
whether it's the link, that should be treated as external.

Note, that on restore we don't call any plugins, but
consider the setup-namespace script to move the respective
link into the namespace. Links are not hierarchical and
can be moved between namespaces easily, so it's OK to
delegate the link creation to the script.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 include/criu-plugin.h |  2 ++
 include/plugin.h      |  2 ++
 net.c                 | 12 ++++++++++--
 plugin.c              |  9 +++++++++
 4 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/include/criu-plugin.h b/include/criu-plugin.h
index 9391055..3e0fd41 100644
--- a/include/criu-plugin.h
+++ b/include/criu-plugin.h
@@ -35,6 +35,8 @@ typedef int (cr_plugin_restore_file_t)(int id);
 typedef int (cr_plugin_dump_ext_mount_t)(char *mountpoint, int id);
 typedef int (cr_plugin_restore_ext_mount_t)(int id, char *mountpoint, char *old_root, int *is_file);
 
+typedef int (cr_plugin_dump_ext_link_t)(int index, int type, char *kind);
+
 /* Public API */
 extern int criu_get_image_dir(void);
 
diff --git a/include/plugin.h b/include/plugin.h
index 6b8e323..3c53e30 100644
--- a/include/plugin.h
+++ b/include/plugin.h
@@ -17,4 +17,6 @@ int cr_plugin_restore_file(int id);
 int cr_plugin_dump_ext_mount(char *mountpoint, int id);
 int cr_plugin_restore_ext_mount(int id, char *mountpoint, char *old_root, int *is_file);
 
+int cr_plugin_dump_ext_link(int index, int type, char *kind);
+
 #endif
diff --git a/net.c b/net.c
index 1815941..bceeb4d 100644
--- a/net.c
+++ b/net.c
@@ -17,6 +17,7 @@
 #include "sk-inet.h"
 #include "tun.h"
 #include "util-pie.h"
+#include "plugin.h"
 
 #include "protobuf.h"
 #include "protobuf/netdev.pb-c.h"
@@ -103,8 +104,15 @@ static char *link_kind(struct ifinfomsg *ifi, struct rtattr **tb)
 static int dump_unknown_device(struct ifinfomsg *ifi, char *kind,
 		struct rtattr **tb, struct cr_fdset *fds)
 {
-	pr_err("Unsupported link %d (type %d kind %s)\n",
-			ifi->ifi_index, ifi->ifi_type, kind);
+	int ret;
+
+	ret = cr_plugin_dump_ext_link(ifi->ifi_index, ifi->ifi_type, kind);
+	if (ret == 0)
+		return dump_one_netdev(ND_TYPE__EXTLINK, ifi, tb, fds, NULL);
+
+	if (ret == -ENOTSUP)
+		pr_err("Unsupported link %d (type %d kind %s)\n",
+				ifi->ifi_index, ifi->ifi_type, kind);
 	return -1;
 }
 
diff --git a/plugin.c b/plugin.c
index d575323..b0db97e 100644
--- a/plugin.c
+++ b/plugin.c
@@ -21,6 +21,7 @@ struct cr_plugin_entry {
 		cr_plugin_restore_file_t *cr_plugin_restore_file;
 		cr_plugin_dump_ext_mount_t *cr_plugin_dump_ext_mount;
 		cr_plugin_restore_ext_mount_t *cr_plugin_restore_ext_mount;
+		cr_plugin_dump_ext_link_t *cr_plugin_dump_ext_link;
 	};
 
 	struct cr_plugin_entry *next;
@@ -35,6 +36,7 @@ struct cr_plugins {
 	struct cr_plugin_entry *cr_plugin_restore_file;
 	struct cr_plugin_entry *cr_plugin_dump_ext_mount;
 	struct cr_plugin_entry *cr_plugin_restore_ext_mount;
+	struct cr_plugin_entry *cr_plugin_dump_ext_link;
 };
 
 struct cr_plugins cr_plugins;
@@ -101,6 +103,11 @@ int cr_plugin_restore_ext_mount(int id, char *mountpoint, char *old_root, int *i
 	return run_plugin_funcs(cr_plugin_restore_ext_mount, id, mountpoint, old_root, is_file);
 }
 
+int cr_plugin_dump_ext_link(int index, int type, char *kind)
+{
+	return run_plugin_funcs(cr_plugin_dump_ext_link, index, type, kind);
+}
+
 static int cr_lib_load(char *path)
 {
 	struct cr_plugin_entry *ce;
@@ -123,6 +130,8 @@ static int cr_lib_load(char *path)
 	add_plugin_func(cr_plugin_dump_ext_mount);
 	add_plugin_func(cr_plugin_restore_ext_mount);
 
+	add_plugin_func(cr_plugin_dump_ext_link);
+
 	ce = NULL;
 	f_fini = dlsym(h, "cr_plugin_fini");
 	if (f_fini) {
-- 
1.8.3.1


More information about the CRIU mailing list