[PATCHv3] Trivially support DomainHasManagedSaveImage

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

 



Return 0 instead of ERR_NO_SUPPORT in each driver
where we don't support managed save or -1 if
the domain does not exist.

This avoids spamming daemon logs when 'virsh dominfo' is run.

https://bugzilla.redhat.com/show_bug.cgi?id=1095637
---
 src/bhyve/bhyve_driver.c         | 25 +++++++++++++-
 src/esx/esx_driver.c             | 39 ++++++++++++++++++++-
 src/lxc/lxc_driver.c             | 26 +++++++++++++-
 src/openvz/openvz_driver.c       | 28 ++++++++++++++-
 src/parallels/parallels_driver.c | 20 ++++++++++-
 src/phyp/phyp_driver.c           | 29 +++++++++++++++-
 src/uml/uml_driver.c             | 33 +++++++++++++++++-
 src/vbox/vbox_common.c           | 73 +++++++++++++++++++++++++++++++++++++++-
 src/vmware/vmware_driver.c       | 27 ++++++++++++++-
 src/xenapi/xenapi_driver.c       | 27 ++++++++++++++-
 10 files changed, 317 insertions(+), 10 deletions(-)

v2: implement the function in all drivers, not just LXC
v3: also check if the domain exists

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 56cc8ab..ae39917 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -2,7 +2,7 @@
  * bhyve_driver.c: core driver methods for managing bhyve guests
  *
  * Copyright (C) 2014 Roman Bogorodskiy
- * Copyright (C) 2014 Red Hat, Inc.
+ * Copyright (C) 2014-2015 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -1430,6 +1430,28 @@ bhyveConnectDomainEventDeregisterAny(virConnectPtr conn,
     return 0;
 }
 
+static int
+bhyveDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags)
+{
+    virDomainObjPtr vm = NULL;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = bhyveDomObjFromDomain(domain)))
+        goto cleanup;
+
+    if (virDomainHasManagedSaveImageEnsureACL(domain->conn, vm->def) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    if (vm)
+        virObjectUnlock(vm);
+    return ret;
+}
+
 static virHypervisorDriver bhyveHypervisorDriver = {
     .name = "bhyve",
     .connectOpen = bhyveConnectOpen, /* 1.2.2 */
@@ -1476,6 +1498,7 @@ static virHypervisorDriver bhyveHypervisorDriver = {
     .connectCompareCPU = bhyveConnectCompareCPU, /* 1.2.4 */
     .connectDomainEventRegisterAny = bhyveConnectDomainEventRegisterAny, /* 1.2.5 */
     .connectDomainEventDeregisterAny = bhyveConnectDomainEventDeregisterAny, /* 1.2.5 */
+    .domainHasManagedSaveImage = bhyveDomainHasManagedSaveImage, /* 1.2.13 */
 };
 
 
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index 6b9965f..179f44c 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -1,7 +1,7 @@
 /*
  * esx_driver.c: core driver functions for managing VMware ESX hosts
  *
- * Copyright (C) 2010-2014 Red Hat, Inc.
+ * Copyright (C) 2010-2015 Red Hat, Inc.
  * Copyright (C) 2009-2014 Matthias Bolte <matthias.bolte@xxxxxxxxxxxxxx>
  * Copyright (C) 2009 Maximilian Wilhelm <max@xxxxxxxxxxx>
  *
@@ -5147,6 +5147,42 @@ esxConnectListAllDomains(virConnectPtr conn,
 }
 #undef MATCH
 
+static int
+esxDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags)
+{
+    int result = -1;
+    esxPrivate *priv = domain->conn->privateData;
+    esxVI_ManagedObjectReference *managedObjectReference = NULL;
+    char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
+
+    virCheckFlags(0, -1);
+
+    if (esxVI_EnsureSession(priv->primary) < 0)
+        return -1;
+
+    virUUIDFormat(domain->uuid, uuid_string);
+
+    if (esxVI_FindByUuid(priv->primary, priv->primary->datacenter->_reference,
+                         uuid_string, esxVI_Boolean_True,
+                         esxVI_Boolean_Undefined,
+                         &managedObjectReference) < 0) {
+        return -1;
+    }
+
+    if (!managedObjectReference) {
+        virReportError(VIR_ERR_NO_DOMAIN,
+                       _("Could not find domain with UUID '%s'"),
+                       uuid_string);
+        goto cleanup;
+    }
+
+    result = 0;
+
+ cleanup:
+    esxVI_ManagedObjectReference_Free(&managedObjectReference);
+    return result;
+}
+
 
 static virHypervisorDriver esxHypervisorDriver = {
     .name = "ESX",
@@ -5226,6 +5262,7 @@ static virHypervisorDriver esxHypervisorDriver = {
     .domainSnapshotHasMetadata = esxDomainSnapshotHasMetadata, /* 0.9.13 */
     .domainSnapshotDelete = esxDomainSnapshotDelete, /* 0.8.0 */
     .connectIsAlive = esxConnectIsAlive, /* 0.9.8 */
+    .domainHasManagedSaveImage = esxDomainHasManagedSaveImage, /* 1.2.13 */
 };
 
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 487e2a2..3adb21d 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 Red Hat, Inc.
+ * Copyright (C) 2010-2015 Red Hat, Inc.
  * Copyright IBM Corp. 2008
  *
  * lxc_driver.c: linux container driver functions
@@ -5726,6 +5726,29 @@ lxcNodeAllocPages(virConnectPtr conn,
 }
 
 
+static int
+lxcDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
+{
+    virDomainObjPtr vm = NULL;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = lxcDomObjFromDomain(dom)))
+        return ret;
+
+    if (virDomainHasManagedSaveImageEnsureACL(dom->conn, vm->def) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    if (vm)
+        virObjectUnlock(vm);
+    return ret;
+}
+
+
 /* Function Tables */
 static virHypervisorDriver lxcHypervisorDriver = {
     .name = LXC_DRIVER_NAME,
@@ -5818,6 +5841,7 @@ static virHypervisorDriver lxcHypervisorDriver = {
     .domainLxcOpenNamespace = lxcDomainLxcOpenNamespace, /* 1.0.2 */
     .nodeGetFreePages = lxcNodeGetFreePages, /* 1.2.6 */
     .nodeAllocPages = lxcNodeAllocPages, /* 1.2.9 */
+    .domainHasManagedSaveImage = lxcDomainHasManagedSaveImage, /* 1.2.13 */
 };
 
 static virConnectDriver lxcConnectDriver = {
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 556f626..5a5cd8d 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -1,7 +1,7 @@
 /*
  * openvz_driver.c: core driver methods for managing OpenVZ VEs
  *
- * Copyright (C) 2010-2014 Red Hat, Inc.
+ * Copyright (C) 2010-2015 Red Hat, Inc.
  * Copyright (C) 2006, 2007 Binary Karma
  * Copyright (C) 2006 Shuveb Hussain
  * Copyright (C) 2007 Anoop Joe Cyriac
@@ -2567,6 +2567,31 @@ openvzDomainMigrateConfirm3Params(virDomainPtr domain,
     return ret;
 }
 
+static int
+openvzDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
+{
+    struct openvz_driver *driver = dom->conn->privateData;
+    virDomainObjPtr obj;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    openvzDriverLock(driver);
+    obj = virDomainObjListFindByUUID(driver->domains, dom->uuid);
+    openvzDriverUnlock(driver);
+    if (!obj) {
+        virReportError(VIR_ERR_NO_DOMAIN, NULL);
+        goto cleanup;
+    }
+    ret = 0;
+
+ cleanup:
+    if (obj)
+        virObjectUnlock(obj);
+    return ret;
+}
+
+
 
 static virHypervisorDriver openvzHypervisorDriver = {
     .name = "OPENVZ",
@@ -2632,6 +2657,7 @@ static virHypervisorDriver openvzHypervisorDriver = {
     .domainMigratePerform3Params = openvzDomainMigratePerform3Params, /* 1.2.8 */
     .domainMigrateFinish3Params = openvzDomainMigrateFinish3Params, /* 1.2.8 */
     .domainMigrateConfirm3Params = openvzDomainMigrateConfirm3Params, /* 1.2.8 */
+    .domainHasManagedSaveImage = openvzDomainHasManagedSaveImage, /* 1.2.13 */
 };
 
 static virConnectDriver openvzConnectDriver = {
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index b569160..c9338b5 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -2,7 +2,7 @@
  * parallels_driver.c: core driver functions for managing
  * Parallels Cloud Server hosts
  *
- * Copyright (C) 2014 Red Hat, Inc.
+ * Copyright (C) 2014-2015 Red Hat, Inc.
  * Copyright (C) 2012 Parallels, Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -956,6 +956,23 @@ parallelsDomainUndefine(virDomainPtr domain)
     return parallelsDomainUndefineFlags(domain, 0);
 }
 
+static int
+parallelsDomainHasManagedSaveImage(virDomainPtr domain, unsigned int flags)
+{
+    parallelsConnPtr privconn = domain->conn->privateData;
+    virDomainObjPtr dom = NULL;
+
+    virCheckFlags(0, -1);
+
+    dom = virDomainObjListFindByUUID(privconn->domains, domain->uuid);
+    if (dom == NULL) {
+        parallelsDomNotFoundError(domain);
+        return -1;
+    }
+
+    return 0;
+}
+
 static virHypervisorDriver parallelsDriver = {
     .name = "Parallels",
     .connectOpen = parallelsConnectOpen,            /* 0.10.0 */
@@ -997,6 +1014,7 @@ static virHypervisorDriver parallelsDriver = {
     .connectIsEncrypted = parallelsConnectIsEncrypted, /* 1.2.5 */
     .connectIsSecure = parallelsConnectIsSecure, /* 1.2.5 */
     .connectIsAlive = parallelsConnectIsAlive, /* 1.2.5 */
+    .domainHasManagedSaveImage = parallelsDomainHasManagedSaveImage, /* 1.2.13 */
 };
 
 static virConnectDriver parallelsConnectDriver = {
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index 6c5a91e..d05f897 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2010-2014 Red Hat, Inc.
+ * Copyright (C) 2010-2015 Red Hat, Inc.
  * Copyright IBM Corp. 2009
  *
  * phyp_driver.c: ssh layer to access Power Hypervisors
@@ -3669,6 +3669,32 @@ phypDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
     return phypDomainSetVcpusFlags(dom, nvcpus, VIR_DOMAIN_VCPU_LIVE);
 }
 
+static int
+phypDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
+{
+
+    phyp_driverPtr phyp_driver = dom->conn->privateData;
+    LIBSSH2_SESSION *session = phyp_driver->session;
+    char *managed_system = phyp_driver->managed_system;
+    char *lpar_name = NULL;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    lpar_name = phypGetLparNAME(session, managed_system, dom->id, dom->conn);
+
+    if (lpar_name == NULL) {
+        VIR_ERROR(_("Unable to determine domain's name."));
+        goto cleanup;
+    }
+
+    ret = 0;
+
+ cleanup:
+    VIR_FREE(lpar_name);
+    return ret;
+}
+
 static virHypervisorDriver phypHypervisorDriver = {
     .name = "PHYP",
     .connectOpen = phypConnectOpen, /* 0.7.0 */
@@ -3698,6 +3724,7 @@ static virHypervisorDriver phypHypervisorDriver = {
     .connectIsSecure = phypConnectIsSecure, /* 0.7.3 */
     .domainIsUpdated = phypDomainIsUpdated, /* 0.8.6 */
     .connectIsAlive = phypConnectIsAlive, /* 0.9.8 */
+    .domainHasManagedSaveImage = phypDomainHasManagedSaveImage, /* 1.2.13 */
 };
 
 static virStorageDriver phypStorageDriver = {
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 6ca038a..68efd18 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1,7 +1,7 @@
 /*
  * uml_driver.c: core driver methods for managing UML guests
  *
- * Copyright (C) 2006-2014 Red Hat, Inc.
+ * Copyright (C) 2006-2015 Red Hat, Inc.
  * Copyright (C) 2006-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -2943,6 +2943,36 @@ umlNodeAllocPages(virConnectPtr conn,
 }
 
 
+static int
+umlDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
+{
+    struct uml_driver *driver = dom->conn->privateData;
+    int ret = -1;
+    virDomainObjPtr vm;
+
+    virCheckFlags(0, -1);
+
+    umlDriverLock(driver);
+    vm = virDomainObjListFindByUUID(driver->domains, dom->uuid);
+    umlDriverUnlock(driver);
+
+    if (!vm) {
+        virReportError(VIR_ERR_NO_DOMAIN, NULL);
+        goto cleanup;
+    }
+
+    if (virDomainHasManagedSaveImageEnsureACL(dom->conn, vm->def) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    if (vm)
+        virObjectUnlock(vm);
+    return ret;
+}
+
+
 static virHypervisorDriver umlHypervisorDriver = {
     .name = "UML",
     .connectOpen = umlConnectOpen, /* 0.5.0 */
@@ -3006,6 +3036,7 @@ static virHypervisorDriver umlHypervisorDriver = {
     .nodeSetMemoryParameters = umlNodeSetMemoryParameters, /* 0.10.2 */
     .nodeGetFreePages = umlNodeGetFreePages, /* 1.2.6 */
     .nodeAllocPages = umlNodeAllocPages, /* 1.2.9 */
+    .domainHasManagedSaveImage = umlDomainHasManagedSaveImage, /* 1.2.13 */
 };
 
 static virConnectDriver umlConnectDriver = {
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index bd3f50c..deca490 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2014, Taowei Luo (uaedante@xxxxxxxxx)
- * Copyright (C) 2010-2014 Red Hat, Inc.
+ * Copyright (C) 2010-2015 Red Hat, Inc.
  * Copyright (C) 2008-2009 Sun Microsystems, Inc.
  *
  * This library is free software; you can redistribute it and/or
@@ -7588,6 +7588,76 @@ vboxNodeAllocPages(virConnectPtr conn ATTRIBUTE_UNUSED,
                           startCell, cellCount, add);
 }
 
+static int
+vboxDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
+{
+    vboxGlobalData *data = dom->conn->privateData;
+    vboxArray machines = VBOX_ARRAY_INITIALIZER;
+    vboxIIDUnion iid;
+    char *machineNameUtf8  = NULL;
+    PRUnichar *machineNameUtf16 = NULL;
+    unsigned char uuid[VIR_UUID_BUFLEN];
+    size_t i;
+    bool matched = false;
+    nsresult rc;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!data->vboxObj)
+        return ret;
+
+    VBOX_IID_INITIALIZE(&iid);
+    rc = gVBoxAPI.UArray.vboxArrayGet(&machines, data->vboxObj, ARRAY_GET_MACHINES);
+    if (NS_FAILED(rc)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Could not get list of machines, rc=%08x"), (unsigned)rc);
+        return ret;
+    }
+
+    for (i = 0; i < machines.count; ++i) {
+        IMachine *machine = machines.items[i];
+        PRBool isAccessible = PR_FALSE;
+
+        if (!machine)
+            continue;
+
+        gVBoxAPI.UIMachine.GetAccessible(machine, &isAccessible);
+        if (!isAccessible)
+            continue;
+
+        gVBoxAPI.UIMachine.GetId(machine, &iid);
+        if (NS_FAILED(rc))
+            continue;
+        vboxIIDToUUID(&iid, uuid);
+        vboxIIDUnalloc(&iid);
+
+        if (memcmp(dom->uuid, uuid, VIR_UUID_BUFLEN) == 0) {
+
+            PRUint32 state;
+
+            matched = true;
+
+            gVBoxAPI.UIMachine.GetName(machine, &machineNameUtf16);
+            VBOX_UTF16_TO_UTF8(machineNameUtf16, &machineNameUtf8);
+
+            gVBoxAPI.UIMachine.GetState(machine, &state);
+
+            ret = 0;
+        }
+
+        if (matched)
+            break;
+    }
+
+    /* Do the cleanup and take care you dont leak any memory */
+    VBOX_UTF8_FREE(machineNameUtf8);
+    VBOX_COM_UNALLOC_MEM(machineNameUtf16);
+    gVBoxAPI.UArray.vboxArrayRelease(&machines);
+
+    return ret;
+}
+
 
 /**
  * Function Tables
@@ -7661,6 +7731,7 @@ virHypervisorDriver vboxCommonDriver = {
     .connectIsAlive = vboxConnectIsAlive, /* 0.9.8 */
     .nodeGetFreePages = vboxNodeGetFreePages, /* 1.2.6 */
     .nodeAllocPages = vboxNodeAllocPages, /* 1.2.9 */
+    .domainHasManagedSaveImage = vboxDomainHasManagedSaveImage, /* 1.2.13 */
 };
 
 static void updateDriver(void)
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index 2d7ba04..fb7fa5b 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -1,6 +1,6 @@
 /*---------------------------------------------------------------------------*/
 /*
- * Copyright (C) 2011-2012 Red Hat, Inc.
+ * Copyright (C) 2011-2015 Red Hat, Inc.
  * Copyright 2010, diateam (www.diateam.net)
  * Copyright (C) 2013. Doug Goldstein <cardoe@xxxxxxxxxx>
  *
@@ -1195,6 +1195,30 @@ vmwareConnectListAllDomains(virConnectPtr conn,
     return ret;
 }
 
+static int
+vmwareDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
+{
+    struct vmware_driver *driver = dom->conn->privateData;
+    virDomainObjPtr obj;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    vmwareDriverLock(driver);
+    obj = virDomainObjListFindByUUID(driver->domains, dom->uuid);
+    vmwareDriverUnlock(driver);
+    if (!obj) {
+        virReportError(VIR_ERR_NO_DOMAIN, NULL);
+        goto cleanup;
+    }
+    ret = 0;
+
+ cleanup:
+    if (obj)
+        virObjectUnlock(obj);
+    return ret;
+}
+
 
 
 static virHypervisorDriver vmwareHypervisorDriver = {
@@ -1233,6 +1257,7 @@ static virHypervisorDriver vmwareHypervisorDriver = {
     .domainIsActive = vmwareDomainIsActive, /* 0.8.7 */
     .domainIsPersistent = vmwareDomainIsPersistent, /* 0.8.7 */
     .connectIsAlive = vmwareConnectIsAlive, /* 0.9.8 */
+    .domainHasManagedSaveImage = vmwareDomainHasManagedSaveImage, /* 1.2.13 */
 };
 
 static virConnectDriver vmwareConnectDriver = {
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 0902f9a..afb6d6c 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -1,6 +1,6 @@
 /*
  * xenapi_driver.c: Xen API driver.
- * Copyright (C) 2011-2014 Red Hat, Inc.
+ * Copyright (C) 2011-2015 Red Hat, Inc.
  * Copyright (C) 2009, 2010 Citrix Ltd.
  *
  * This library is free software; you can redistribute it and/or
@@ -1977,6 +1977,30 @@ xenapiConnectIsAlive(virConnectPtr conn)
         return 0;
 }
 
+static int
+xenapiDomainHasManagedSaveImage(virDomainPtr dom, unsigned int flags)
+{
+    struct xen_vm_set *vms;
+    xen_session *session = ((struct _xenapiPrivate *)(dom->conn->privateData))->session;
+
+    virCheckFlags(0, -1);
+
+    if (xen_vm_get_by_name_label(session, &vms, dom->name) && vms->size > 0) {
+        if (vms->size != 1) {
+            xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR,
+                                      _("Domain name is not unique"));
+            xen_vm_set_free(vms);
+            return -1;
+        }
+        xen_vm_set_free(vms);
+        return 0;
+    }
+    if (vms)
+        xen_vm_set_free(vms);
+    xenapiSessionErrorHandler(dom->conn, VIR_ERR_NO_DOMAIN, NULL);
+    return -1;
+}
+
 /* The interface which we export upwards to libvirt.c. */
 static virHypervisorDriver xenapiHypervisorDriver = {
     .name = "XenAPI",
@@ -2029,6 +2053,7 @@ static virHypervisorDriver xenapiHypervisorDriver = {
     .nodeGetFreeMemory = xenapiNodeGetFreeMemory, /* 0.8.0 */
     .domainIsUpdated = xenapiDomainIsUpdated, /* 0.8.6 */
     .connectIsAlive = xenapiConnectIsAlive, /* 0.9.8 */
+    .domainHasManagedSaveImage = xenapiDomainHasManagedSaveImage, /* 1.2.13 */
 };
 
 
-- 
2.0.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]