]> xenbits.xensource.com Git - libvirt.git/commitdiff
Make state driver device hotplug/update actually transient
authorCole Robinson <crobinso@redhat.com>
Fri, 19 Nov 2010 18:36:29 +0000 (13:36 -0500)
committerCole Robinson <crobinso@redhat.com>
Tue, 23 Nov 2010 13:42:45 +0000 (08:42 -0500)
The current semantics of non-persistent hotplug/update are confusing: the
changes will persist as long as the in memory domain definition isn't
overwritten. This means hotplug changes stay around until the domain is
redefined or libvirtd is restarted.

Call virDomainObjSetDefTransient at VM startup, so that we properly discard
hotplug changes when the VM is shutdown.

src/lxc/lxc_driver.c
src/qemu/qemu_driver.c
src/test/test_driver.c
src/uml/uml_driver.c

index f5014cbd2c3b46be3c4d8d5dfde37d0a43ad2a22..f6ba137277e662861c7ec0b587d2e6437bc82205 100644 (file)
@@ -1532,6 +1532,9 @@ static int lxcVmStart(virConnectPtr conn,
     if (virDomainSaveConfig(driver->stateDir, vm->def) < 0)
         goto cleanup;
 
+    if (virDomainObjSetDefTransient(driver->caps, vm) < 0)
+        goto cleanup;
+
     rc = 0;
 
 cleanup:
index ed1ea6b71526deaa27145517d462e6ca0395cbc1..18b3f16764eea72560be3234acea06ec1284ceef 100644 (file)
@@ -4235,6 +4235,11 @@ static int qemudStartVMDaemon(virConnectPtr conn,
     if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
         goto cleanup;
 
+    /* Do this last, since it depends on domain being active */
+    DEBUG0("Setting running domain def as transient");
+    if (virDomainObjSetDefTransient(driver->caps, vm) < 0)
+        goto cleanup;
+
     VIR_FORCE_CLOSE(logfile);
 
     return 0;
index 5693d7adba402e4297239aa04c75935ddce6f3aa..5e737e86757800ae315e653d869bd8dfd12499f7 100644 (file)
@@ -457,6 +457,22 @@ cleanup:
     return ret;
 }
 
+static void
+testDomainShutdownState(virDomainPtr domain,
+                        virDomainObjPtr privdom)
+{
+    if (privdom->newDef) {
+        virDomainDefFree(privdom->def);
+        privdom->def = privdom->newDef;
+        privdom->newDef = NULL;
+    }
+
+    privdom->state = VIR_DOMAIN_SHUTOFF;
+    privdom->def->id = -1;
+    if (domain)
+        domain->id = -1;
+}
+
 /* Set up domain runtime state */
 static int
 testDomainStartState(virConnectPtr conn,
@@ -468,30 +484,20 @@ testDomainStartState(virConnectPtr conn,
     if (testDomainUpdateVCPUs(conn, dom, dom->def->vcpus, 1) < 0)
         goto cleanup;
 
-    /* Set typical run state */
     dom->state = VIR_DOMAIN_RUNNING;
     dom->def->id = privconn->nextDomID++;
 
+    if (virDomainObjSetDefTransient(privconn->caps, dom) < 0) {
+        goto cleanup;
+    }
+
     ret = 0;
 cleanup:
+    if (ret < 0)
+        testDomainShutdownState(NULL, dom);
     return ret;
 }
 
-static void
-testDomainShutdownState(virDomainPtr domain,
-                        virDomainObjPtr privdom)
-{
-    if (privdom->newDef) {
-        virDomainDefFree(privdom->def);
-        privdom->def = privdom->newDef;
-        privdom->newDef = NULL;
-    }
-
-    privdom->state = VIR_DOMAIN_SHUTOFF;
-    privdom->def->id = -1;
-    domain->id = -1;
-}
-
 static int testOpenDefault(virConnectPtr conn) {
     int u;
     struct timeval tv;
@@ -558,12 +564,12 @@ static int testOpenDefault(virConnectPtr conn) {
         goto error;
     domdef = NULL;
 
+    domobj->persistent = 1;
     if (testDomainStartState(conn, domobj) < 0) {
         virDomainObjUnlock(domobj);
         goto error;
     }
 
-    domobj->persistent = 1;
     virDomainObjUnlock(domobj);
 
     if (!(netdef = virNetworkDefParseString(defaultNetworkXML)))
@@ -918,12 +924,12 @@ static int testOpenFromFile(virConnectPtr conn,
             goto error;
         }
 
+        dom->persistent = 1;
         if (testDomainStartState(conn, dom) < 0) {
             virDomainObjUnlock(dom);
             goto error;
         }
 
-        dom->persistent = 1;
         virDomainObjUnlock(dom);
     }
     VIR_FREE(domains);
index ca4e7be695a2cf573bb9bed76bb633ce0807cee6..eaa3509b5d13c33468a7eb0dda81b6667943d5e9 100644 (file)
@@ -916,7 +916,11 @@ static int umlStartVMDaemon(virConnectPtr conn,
                            VIR_EXEC_CLEAR_CAPS,
                            NULL, NULL, NULL);
     VIR_FORCE_CLOSE(logfd);
+    if (ret < 0)
+        goto cleanup;
 
+    ret = virDomainObjSetDefTransient(driver->caps, vm);
+cleanup:
     /*
      * At the moment, the only thing that populates keepfd is
      * umlBuildCommandLineChr. We want to close every fd it opens.
@@ -940,7 +944,6 @@ static int umlStartVMDaemon(virConnectPtr conn,
         umlCleanupTapDevices(conn, vm);
     }
 
-
     /* NB we don't mark it running here - we do that async
        with inotify */
     /* XXX what if someone else tries to start it again