]> xenbits.xensource.com Git - libvirt.git/commitdiff
fix multiple veth problem for OpenVZ
authorYuji NISHIDA <nishidy@nict.go.jp>
Fri, 19 Feb 2010 15:49:56 +0000 (16:49 +0100)
committerDaniel Veillard <veillard@redhat.com>
Fri, 19 Feb 2010 15:49:56 +0000 (16:49 +0100)
Fix multiple veth problem.
NETIF setting was overwritten after first CT because any CT could not be
found by name.
* src/openvz/openvz_conf.c src/openvz/openvz_conf.h: add the
  openvzGetVEID lookup function
* src/openvz/openvz_driver.c: use it in openvzDomainSetNetwork()

src/openvz/openvz_conf.c
src/openvz/openvz_conf.h
src/openvz/openvz_driver.c

index a4aab1ee4ad432f43208e91337e8e913c721fd6b..ce0c4d332c9021cfa843a2d06eff3c6a239ae06c 100644 (file)
@@ -953,3 +953,44 @@ static int openvzAssignUUIDs(void)
     VIR_FREE(conf_dir);
     return 0;
 }
+
+
+/*
+ * Return CTID from name
+ *
+ */
+
+int openvzGetVEID(const char *name) {
+    char *cmd;
+    int veid;
+    FILE *fp;
+
+    if (virAsprintf(&cmd, "%s %s -ovpsid -H", VZLIST, name) < 0) {
+        openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s",
+                    _("virAsprintf failed"));
+        return -1;
+    }
+
+    fp = popen(cmd, "r");
+    VIR_FREE(cmd);
+
+    if (fp == NULL) {
+        openvzError(NULL, VIR_ERR_INTERNAL_ERROR, "%s", _("popen failed"));
+        return -1;
+    }
+
+    if (fscanf(fp, "%d\n", &veid ) != 1) {
+        if (feof(fp))
+            return -1;
+
+        openvzError(NULL, VIR_ERR_INTERNAL_ERROR,
+                    "%s", _("Failed to parse vzlist output"));
+        goto cleanup;
+    }
+
+    return veid;
+
+ cleanup:
+    fclose(fp);
+    return -1;
+}
index 00e18b4325225cf95c3f106d3756fa58b2ce749a..c863a2a3f6961f82bf961e23650fefa9b259b7d6 100644 (file)
@@ -66,5 +66,6 @@ void openvzFreeDriver(struct openvz_driver *driver);
 int strtoI(const char *str);
 int openvzSetDefinedUUID(int vpsid, unsigned char *uuid);
 unsigned int openvzGetNodeCPUs(void);
+int openvzGetVEID(const char *name);
 
 #endif /* OPENVZ_CONF_H */
index 68d03980dbebef6cb0d3338aede50361e0a2e951..5057b81943a9ecfccd455a8c8350a1b4ccda3cfc 100644 (file)
@@ -667,7 +667,7 @@ openvzDomainSetNetwork(virConnectPtr conn, const char *vpsid,
     if (net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) {
         virBuffer buf = VIR_BUFFER_INITIALIZER;
         char *dev_name_ve;
-        int veid = strtoI(vpsid);
+        int veid = openvzGetVEID(vpsid);
 
         //--netif_add ifname[,mac,host_ifname,host_mac]
         ADD_ARG_LIT("--netif_add") ;