[libvirt] [PATCH v4 3/7] qemu: Implement qemuDomainManagedSaveGetXMLDesc

Kothapally Madhu Pavan posted 7 patches 7 years, 9 months ago
[libvirt] [PATCH v4 3/7] qemu: Implement qemuDomainManagedSaveGetXMLDesc
Posted by Kothapally Madhu Pavan 7 years, 9 months ago
This commit adds qemu driver implementation to get xml description
for managed save state domain.

Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
---
 src/qemu/qemu_driver.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b3f65f4..ec73dc1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6797,6 +6797,51 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, const char *path,
     return ret;
 }
 
+static char *
+qemuDomainManagedSaveGetXMLDesc(virDomainPtr dom, unsigned int flags)
+{
+    virQEMUDriverPtr driver = dom->conn->privateData;
+    virDomainObjPtr vm;
+    char *path = NULL;
+    char *ret = NULL;
+    virDomainDefPtr def = NULL;
+    int fd = -1;
+    virQEMUSaveDataPtr data = NULL;
+
+    /* We only take subset of virDomainDefFormat flags.  */
+    virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL);
+
+    if (!(vm = qemuDomObjFromDomain(dom)))
+        return ret;
+
+    path = qemuDomainManagedSavePath(driver, vm);
+
+    if (!path)
+        goto cleanup;
+
+    if (!virFileExists(path)) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s",_("domain does not have managed save image"));
+        goto cleanup;
+    }
+
+    fd = qemuDomainSaveImageOpen(driver, path, &def, &data,
+                                 false, NULL, false, false);
+    if (fd < 0)
+        goto cleanup;
+    if (virDomainManagedSaveGetXMLDescEnsureACL(dom->conn, def, flags) < 0)
+        goto cleanup;
+    ret = qemuDomainDefFormatXML(driver, def, flags);
+
+ cleanup:
+    virQEMUSaveDataFree(data);
+    virDomainDefFree(def);
+    VIR_FORCE_CLOSE(fd);
+    virDomainObjEndAPI(&vm);
+    VIR_FREE(path);
+    return ret;
+}
+
 /* Return 0 on success, 1 if incomplete saved image was silently unlinked,
  * and -1 on failure with error raised.  */
 static int
@@ -20839,6 +20884,7 @@ static virHypervisorDriver qemuHypervisorDriver = {
     .domainManagedSave = qemuDomainManagedSave, /* 0.8.0 */
     .domainHasManagedSaveImage = qemuDomainHasManagedSaveImage, /* 0.8.0 */
     .domainManagedSaveRemove = qemuDomainManagedSaveRemove, /* 0.8.0 */
+    .domainManagedSaveGetXMLDesc = qemuDomainManagedSaveGetXMLDesc, /* 3.7.0 */
     .domainSnapshotCreateXML = qemuDomainSnapshotCreateXML, /* 0.8.0 */
     .domainSnapshotGetXMLDesc = qemuDomainSnapshotGetXMLDesc, /* 0.8.0 */
     .domainSnapshotNum = qemuDomainSnapshotNum, /* 0.8.0 */
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 3/7] qemu: Implement qemuDomainManagedSaveGetXMLDesc
Posted by Peter Krempa 7 years, 8 months ago
On Tue, Aug 08, 2017 at 13:32:51 +0530, Kothapally Madhu Pavan wrote:
> This commit adds qemu driver implementation to get xml description
> for managed save state domain.
> 
> Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
> ---
>  src/qemu/qemu_driver.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index b3f65f4..ec73dc1 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -6797,6 +6797,51 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, const char *path,
>      return ret;
>  }
>  
> +static char *
> +qemuDomainManagedSaveGetXMLDesc(virDomainPtr dom, unsigned int flags)
> +{
> +    virQEMUDriverPtr driver = dom->conn->privateData;
> +    virDomainObjPtr vm;
> +    char *path = NULL;
> +    char *ret = NULL;
> +    virDomainDefPtr def = NULL;
> +    int fd = -1;
> +    virQEMUSaveDataPtr data = NULL;
> +
> +    /* We only take subset of virDomainDefFormat flags.  */
> +    virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL);
> +
> +    if (!(vm = qemuDomObjFromDomain(dom)))
> +        return ret;
> +
> +    path = qemuDomainManagedSavePath(driver, vm);
> +
> +    if (!path)
> +        goto cleanup;
> +
> +    if (!virFileExists(path)) {
> +        virReportError(VIR_ERR_OPERATION_INVALID,
> +                       "%s",_("domain does not have managed save image"));

You did not run syntax-check on this patch:

Invalid character after comma:
src/qemu/qemu_driver.c:6824:                        "%s",_("domain does not have managed save image"));

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v4 3/7] qemu: Implement qemuDomainManagedSaveGetXMLDesc
Posted by Peter Krempa 7 years, 8 months ago
On Tue, Aug 08, 2017 at 13:32:51 +0530, Kothapally Madhu Pavan wrote:
> This commit adds qemu driver implementation to get xml description
> for managed save state domain.
> 
> Signed-off-by: Kothapally Madhu Pavan <kmp@linux.vnet.ibm.com>
> ---
>  src/qemu/qemu_driver.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 46 insertions(+)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index b3f65f4..ec73dc1 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -6797,6 +6797,51 @@ qemuDomainSaveImageDefineXML(virConnectPtr conn, const char *path,
>      return ret;
>  }
>  
> +static char *
> +qemuDomainManagedSaveGetXMLDesc(virDomainPtr dom, unsigned int flags)
> +{
> +    virQEMUDriverPtr driver = dom->conn->privateData;
> +    virDomainObjPtr vm;
> +    char *path = NULL;
> +    char *ret = NULL;
> +    virDomainDefPtr def = NULL;
> +    int fd = -1;
> +    virQEMUSaveDataPtr data = NULL;
> +
> +    /* We only take subset of virDomainDefFormat flags.  */
> +    virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL);
> +
> +    if (!(vm = qemuDomObjFromDomain(dom)))
> +        return ret;
> +
> +    path = qemuDomainManagedSavePath(driver, vm);
> +
> +    if (!path)
> +        goto cleanup;
> +
> +    if (!virFileExists(path)) {
> +        virReportError(VIR_ERR_OPERATION_INVALID,
> +                       "%s",_("domain does not have managed save image"));
> +        goto cleanup;
> +    }
> +
> +    fd = qemuDomainSaveImageOpen(driver, path, &def, &data,
> +                                 false, NULL, false, false);
> +    if (fd < 0)
> +        goto cleanup;
> +    if (virDomainManagedSaveGetXMLDescEnsureACL(dom->conn, def, flags) < 0)
> +        goto cleanup;

Since you have the 'vm' object at the beginning, I think the ACL check
should be done right away with vm->def in this case. The ACL check
should only need the name and UUID from the definition and thus can be
run earlier.

This will mitigate a possible side channel, where we'd return 'domain
does not have managed save image' instead of the "access denied"
message.

I'll do this adjustment locally along with others pointed out. I might
finish this until the freeze tomorrow.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list