[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH] Save uuid when define/create domain



Hi,

There was bug.
UUID defined in XML or generated during define/create was not saved to config. Then it was regenerated in virDrvStateInitialize.

Attached patch fix bug.
Index: src/openvz_conf.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_conf.c,v
retrieving revision 1.32
diff -u -p -r1.32 openvz_conf.c
--- src/openvz_conf.c	29 Jul 2008 08:42:56 -0000	1.32
+++ src/openvz_conf.c	5 Aug 2008 09:51:49 -0000
@@ -736,13 +736,14 @@ openvzGetVPSUUID(int vpsid, char *uuidst
 /* Do actual checking for UUID presence in conf file,
  * assign if not present.
  */
-
-static int
-openvzSetUUID(int vpsid)
+int
+openvzSetDefinedUUID(int vpsid, unsigned char *uuid)
 {
     char conf_file[PATH_MAX];
     char uuidstr[VIR_UUID_STRING_BUFLEN];
-    unsigned char uuid[VIR_UUID_BUFLEN];
+
+    if (uuid == NULL)
+        return -1;
 
    if (openvzLocateConfFile(vpsid, conf_file, PATH_MAX)<0)
        return -1;
@@ -755,7 +756,6 @@ openvzSetUUID(int vpsid)
         if (fp == NULL)
           return -1;
 
-        virUUIDGenerate(uuid);
         virUUIDFormat(uuid, uuidstr);
 
         /* Record failure if fprintf or fclose fails,
@@ -768,6 +768,15 @@ openvzSetUUID(int vpsid)
     return 0;
 }
 
+static int
+openvzSetUUID(int vpsid){
+    unsigned char uuid[VIR_UUID_BUFLEN];
+
+    virUUIDGenerate(uuid);
+
+    return openvzSetDefinedUUID(vpsid, uuid);
+}
+
 /*
  * Scan VPS config files and see if they have a UUID.
  * If not, assign one. Just append one to the config
Index: src/openvz_conf.h
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_conf.h,v
retrieving revision 1.10
diff -u -p -r1.10 openvz_conf.h
--- src/openvz_conf.h	28 Jul 2008 14:06:54 -0000	1.10
+++ src/openvz_conf.h	5 Aug 2008 09:51:49 -0000
@@ -119,5 +119,6 @@ void openvzFreeVMDef(struct openvz_vm_de
 int strtoI(const char *str);
 int openvzCheckEmptyMac(const unsigned char *mac);
 char *openvzMacToString(const unsigned char *mac);
+int openvzSetDefinedUUID(int vpsid, unsigned char *uuid);
 
 #endif /* OPENVZ_CONF_H */
Index: src/openvz_driver.c
===================================================================
RCS file: /data/cvs/libvirt/src/openvz_driver.c,v
retrieving revision 1.36
diff -u -p -r1.36 openvz_driver.c
--- src/openvz_driver.c	28 Jul 2008 14:06:54 -0000	1.36
+++ src/openvz_driver.c	5 Aug 2008 09:51:49 -0000
@@ -459,6 +459,12 @@ openvzDomainDefineXML(virConnectPtr conn
         goto exit;
     }
 
+    if (openvzSetDefinedUUID(strtoI(vmdef->name), vmdef->uuid) < 0) {
+        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
+               _("Could not set UUID"));
+        goto exit;
+    }
+
     dom = virGetDomain(conn, vm->vmdef->name, vm->vmdef->uuid);
     if (dom)
         dom->id = vm->vpsid;
@@ -514,6 +520,12 @@ openvzDomainCreateLinux(virConnectPtr co
         goto exit;
     }
 
+    if (openvzSetDefinedUUID(strtoI(vmdef->name), vmdef->uuid) < 0) {
+        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
+               _("Could not set UUID"));
+        goto exit;
+    }
+
     if (openvzDomainSetNetwork(conn, vmdef->name, vmdef->net) < 0) {
        openvzError(conn, VIR_ERR_INTERNAL_ERROR,
                   _("Could not configure network"));

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]