Skip to contentSkip to conversation

libxl: support domainReset

PATCH Jim Fehlig 1 participant 1 message Jun 26, 2015 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

Jim Fehlig

author
#1 lore raw
Quoted 15 lines · Jim Fehlig

Currently, libxl does not provide a reset function, but domainReset can be implemented in the libxl driver by forcibly destroying the domain and starting it again.

---

This is essentially a V2 of a patch submitted quite some time ago

https://www.redhat.com/archives/libvir-list/2014-August/msg00077.html

The idea of implmenting domainReset in the libxl driver by forcibly destroying the domain and starting it again was ACK'ed in principle by Ian Campbell

Quoted 6 lines

https://www.redhat.com/archives/libvir-list/2014-August/msg00109.html

I never pushed the patch since it was not ACK'ed by a libvirt maintainer and stumbled across it while cleaning up some of my old branches. The only change here is rebase against current libvirt.git master.

Any comments on this, beyond my self-comment below?

Quoted 74 lines
  src/libxl/libxl_driver.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 59 insertions(+)
src/libxl/libxl_driver.c +58 -0
index 12be816..671d336 100644
@@ -1237,6 +1237,64 @@ libxlDomainReboot(virDomainPtr dom, unsigned int flags)
  }
 
  static int
+libxlDomainReset(virDomainPtr dom, unsigned int flags)
+{
+    libxlDriverPrivatePtr driver = dom->conn->privateData;
+    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
+    virDomainObjPtr vm;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = libxlDomObjFromDomain(dom)))
+        goto cleanup;
+
+    if (virDomainResetEnsureACL(dom->conn, vm->def) < 0)
+        goto cleanup;
+
+    if (libxlDomainObjBeginJob(driver, vm, LIBXL_JOB_MODIFY) < 0)
+        goto cleanup;
+
+    if (!virDomainObjIsActive(vm)) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("Domain is not running"));
+        goto endjob;
+    }
+
+    /*
+     * The semantics of reset can be achieved by forcibly destroying
+     * the domain and starting it again.
+     */
+    if (libxl_domain_destroy(cfg->ctx, vm->def->id, NULL) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to destroy domain '%d' before reset"),
+                       vm->def->id);
+        goto endjob;
+    }
+
+    libxlDomainCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_DESTROYED);
+
+    if (libxlDomainStart(driver, vm, false, -1) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Failed to start domain '%d' after reset"),
+                       vm->def->id);
+        goto endjob;
+    }
+
+    ret = 0;
+
+ endjob:
+    if (!libxlDomainObjEndJob(driver, vm))
+        vm = NULL;
+
+ cleanup:
+    if (vm)
+        virObjectUnlock(vm);
+    virObjectUnref(cfg);
+    return ret;
+}
+
+static int
  libxlDomainDestroyFlags(virDomainPtr dom,
                          unsigned int flags)
  {

src/libxl/libxl_driver.c static virHypervisorDriver libxlHypervisorDriver = { · line 5127

Quoted 4 lines
src/libxl/libxl_driver.c +1 -0
@@ -5066,6 +5124,7 @@ static virHypervisorDriver libxlHypervisorDriver = {
      .domainShutdown = libxlDomainShutdown, /* 0.9.0 */
      .domainShutdownFlags = libxlDomainShutdownFlags, /* 0.9.10 */
      .domainReboot = libxlDomainReboot, /* 0.9.0 */
+    .domainReset = libxlDomainReset, /* 1.2.8 */

Needs to be updated to 1.2.17? 1.3.0? (I'm behind on my libvirt mail and not sure about the outcome of the version discussion.)

Regards,
Jim