[Devel] [PATCH 2/3] vzctl: add ability to skip creation of veth devices

Andrey Vagin avagin at openvz.org
Mon May 27 13:24:14 PDT 2013


It will be used for resuming CT with help CRIU.
CRIU restores veth devices and configures them inside CT,
so vzctl should configures them on the host side.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 include/types.h              |  2 ++
 scripts/vps-netns_dev_add.in |  5 ++++-
 src/lib/hooks_ct.c           | 10 ++++++++--
 src/lib/veth.c               |  8 +++++---
 4 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/include/types.h b/include/types.h
index a715a5a..63919b9 100644
--- a/include/types.h
+++ b/include/types.h
@@ -49,6 +49,7 @@ typedef unsigned envid_t;
 #define YES		1
 #define NO		2
 
+#define CFG		2
 #define ADD		0
 #define DEL		1
 
@@ -99,6 +100,7 @@ typedef enum {
 	SKIP_ACTION_SCRIPT =	(1<<2),
 	SKIP_UMOUNT =		(1<<3),
 	SKIP_REMOUNT =		(1<<4),
+	SKIP_VETH_CREATE =	(1<<5),
 } skipFlags;
 
 /** CT handler.
diff --git a/scripts/vps-netns_dev_add.in b/scripts/vps-netns_dev_add.in
index 60461e4..12e0eaa 100755
--- a/scripts/vps-netns_dev_add.in
+++ b/scripts/vps-netns_dev_add.in
@@ -40,11 +40,14 @@
 vzcheckvar VEID
 vzcheckvar VNAME
 vzcheckvar HNAME
+vzcheckvar ACTION
 
 if [ "x$HNAME" = "x$VNAME" ]; then
 	vzmoveif
 else
-	vzcreatepair
+	if [ "$ACTION" = "add" ]; then
+		vzcreatepair
+	fi
 	vzadjustmacs
 	vzconfbridge
 fi
diff --git a/src/lib/hooks_ct.c b/src/lib/hooks_ct.c
index d8909b1..21e6823 100644
--- a/src/lib/hooks_ct.c
+++ b/src/lib/hooks_ct.c
@@ -815,7 +815,7 @@ static int ct_ip_ctl(vps_handler *h, envid_t veid, int op, const char *ipstr)
 static int ct_veth_ctl(vps_handler *h, envid_t veid, int op, veth_dev *dev)
 {
 	int ret = -1;
-	char *envp[10];
+	char *envp[11];
 	char buf[STR_SIZE];
 	int i = 0;
 
@@ -847,6 +847,12 @@ static int ct_veth_ctl(vps_handler *h, envid_t veid, int op, veth_dev *dev)
 		envp[i++] = strdup(buf);
 	}
 
+	if (op == ADD)
+		snprintf(buf, sizeof(buf), "ACTION=add");
+	else
+		snprintf(buf, sizeof(buf), "ACTION=cfg");
+	envp[i++] = strdup(buf);
+
 	envp[i] = NULL;
 
 	if (op == ADD) {
@@ -970,7 +976,7 @@ static int ct_restore(vps_handler *h, envid_t veid, vps_param *vps_p, int cmd,
 	cpt_param *param, skipFlags skip)
 {
 	return vps_start_custom(h, veid, vps_p,
-			SKIP_CONFIGURE | SKIP_ACTION_SCRIPT | skip,
+			SKIP_CONFIGURE | SKIP_ACTION_SCRIPT | SKIP_VETH_CREATE | skip,
 			NULL, ct_restore_fn, param);
 }
 
diff --git a/src/lib/veth.c b/src/lib/veth.c
index 2b63774..b1956fa 100644
--- a/src/lib/veth.c
+++ b/src/lib/veth.c
@@ -111,9 +111,9 @@ static int veth_ctl(vps_handler *h, envid_t veid, int op, veth_param *list,
 			break;
 	}
 	logger(0, 0, "%s veth devices: %s",
-		op == ADD ? "Configure" : "Deleting", buf);
+		(op == ADD || op == CFG) ? "Configure" : "Deleting", buf);
 	list_for_each(tmp, dev_h, list) {
-		if (op == ADD) {
+		if (op == ADD || op == CFG) {
 			if ((ret = h->veth_ctl(h, veid, ADD, tmp)))
 				break;
 			if ((ret = run_vznetcfg(veid, tmp)))
@@ -407,8 +407,10 @@ int vps_setup_veth(vps_handler *h, envid_t veid, dist_actions *actions,
 		veth_ctl(h, veid, DEL, veth_del, 0);
 	}
 	if (!list_empty(&veth_add->dev)) {
+		int op = (skip & SKIP_VETH_CREATE) ? CFG : ADD;
+
 		fill_veth_dev_name(&veth_old, veth_add);
-		ret = veth_ctl(h, veid, ADD, veth_add, 1);
+		ret = veth_ctl(h, veid, op, veth_add, 1);
 	}
 	if (!list_empty(&veth_old.dev))
 		free_veth_param(&veth_old);
-- 
1.8.2




More information about the Devel mailing list