[libvirt] [PATCH v3 05/12] qemu: Store pr runtime data in status XML

Michal Privoznik posted 12 patches 7 years, 2 months ago
There is a newer version of this series
[libvirt] [PATCH v3 05/12] qemu: Store pr runtime data in status XML
Posted by Michal Privoznik 7 years, 2 months ago
Now that we generate pr-manager alias and socket path store them
in status XML so that they are preserved across daemon restarts.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---
 src/qemu/qemu_domain.c | 108 +++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 86 insertions(+), 22 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c17e40dc8..d673ddbb2 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -1961,28 +1961,6 @@ qemuDomainObjPrivateFree(void *data)
 }
 
 
-static int
-qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
-                                  virStorageSourcePtr src)
-{
-    if (virStorageSourcePrivateDataParseRelPath(ctxt, src) < 0)
-        return -1;
-
-    return 0;
-}
-
-
-static int
-qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src,
-                                   virBufferPtr buf)
-{
-    if (virStorageSourcePrivateDataFormatRelPath(src, buf) < 0)
-        return -1;
-
-    return 0;
-}
-
-
 static void
 qemuDomainObjPrivateXMLFormatVcpus(virBufferPtr buf,
                                    virDomainDefPtr def)
@@ -2590,6 +2568,92 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
 }
 
 
+static int
+qemuStorageSourcePrivateDataParsePR(xmlXPathContextPtr ctxt,
+                                    virStorageSourcePtr src)
+{
+    qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
+    qemuDomainDiskPRDPtr prd = NULL;
+    int rc;
+    int ret = -1;
+
+    if ((rc = virXPathBoolean("boolean(./prd)", ctxt)) == 0) {
+        return 0;
+    } else if (rc < 0) {
+        return ret;
+    }
+
+    if (VIR_ALLOC(prd) < 0)
+        return ret;
+
+    if (!(prd->alias = virXPathString("string(./prd/alias)", ctxt)) ||
+        !(prd->path = virXPathString("string(./prd/path)", ctxt))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("malformed <prd/>"));
+        goto cleanup;
+    }
+
+    VIR_STEAL_PTR(srcPriv->prd, prd);
+    ret = 0;
+ cleanup:
+    qemuDomainDiskPRDFree(prd);
+    return ret;
+}
+
+
+static int
+qemuStorageSourcePrivateDataFormatPR(virStorageSourcePtr src,
+                                     virBufferPtr buf)
+{
+    qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
+    qemuDomainDiskPRDPtr prd;
+
+    if (!srcPriv || !srcPriv->prd)
+        return 0;
+
+    prd = srcPriv->prd;
+
+    virBufferAddLit(buf, "<prd>\n");
+    virBufferAdjustIndent(buf, 2);
+    virBufferAsprintf(buf, "<alias>%s</alias>\n", prd->alias);
+    virBufferAsprintf(buf, "<path>%s</path>\n", prd->path);
+    virBufferAdjustIndent(buf, -2);
+    virBufferAddLit(buf, "</prd>\n");
+    return 0;
+}
+
+
+static int
+qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
+                                  virStorageSourcePtr src)
+{
+    if (!(src->privateData = qemuDomainStorageSourcePrivateNew()))
+        return -1;
+
+    if (virStorageSourcePrivateDataParseRelPath(ctxt, src) < 0)
+        return -1;
+
+    if (qemuStorageSourcePrivateDataParsePR(ctxt, src) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+static int
+qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src,
+                                   virBufferPtr buf)
+{
+    if (virStorageSourcePrivateDataFormatRelPath(src, buf) < 0)
+        return -1;
+
+    if (qemuStorageSourcePrivateDataFormatPR(src, buf) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 virDomainXMLPrivateDataCallbacks virQEMUDriverPrivateDataCallbacks = {
     .alloc = qemuDomainObjPrivateAlloc,
     .free = qemuDomainObjPrivateFree,
-- 
2.16.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3 05/12] qemu: Store pr runtime data in status XML
Posted by Peter Krempa 7 years, 2 months ago
On Wed, Mar 14, 2018 at 17:05:34 +0100, Michal Privoznik wrote:
> Now that we generate pr-manager alias and socket path store them
> in status XML so that they are preserved across daemon restarts.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_domain.c | 108 +++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 86 insertions(+), 22 deletions(-)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index c17e40dc8..d673ddbb2 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -1961,28 +1961,6 @@ qemuDomainObjPrivateFree(void *data)
>  }
>  
>  
> -static int
> -qemuStorageSourcePrivateDataParse(xmlXPathContextPtr ctxt,
> -                                  virStorageSourcePtr src)
> -{
> -    if (virStorageSourcePrivateDataParseRelPath(ctxt, src) < 0)
> -        return -1;
> -
> -    return 0;
> -}
> -
> -
> -static int
> -qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src,
> -                                   virBufferPtr buf)
> -{
> -    if (virStorageSourcePrivateDataFormatRelPath(src, buf) < 0)
> -        return -1;
> -
> -    return 0;
> -}

Please don't move these out of here. I've specifically placed them here
since I'll need them way earlier than your patch puts them.
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3 05/12] qemu: Store pr runtime data in status XML
Posted by Peter Krempa 7 years, 2 months ago
On Wed, Mar 14, 2018 at 17:05:34 +0100, Michal Privoznik wrote:
> Now that we generate pr-manager alias and socket path store them
> in status XML so that they are preserved across daemon restarts.
> 
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
>  src/qemu/qemu_domain.c | 108 +++++++++++++++++++++++++++++++++++++++----------
>  1 file changed, 86 insertions(+), 22 deletions(-)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index c17e40dc8..d673ddbb2 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c

[...]

> +static int
> +qemuStorageSourcePrivateDataFormatPR(virStorageSourcePtr src,
> +                                     virBufferPtr buf)
> +{
> +    qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
> +    qemuDomainDiskPRDPtr prd;
> +
> +    if (!srcPriv || !srcPriv->prd)
> +        return 0;
> +
> +    prd = srcPriv->prd;
> +
> +    virBufferAddLit(buf, "<prd>\n");
> +    virBufferAdjustIndent(buf, 2);
> +    virBufferAsprintf(buf, "<alias>%s</alias>\n", prd->alias);
> +    virBufferAsprintf(buf, "<path>%s</path>\n", prd->path);

'path' is user-controlled, so you need to use the 'virBufferEscape'
function.

> +    virBufferAdjustIndent(buf, -2);
> +    virBufferAddLit(buf, "</prd>\n");
> +    return 0;
> +}
> +
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list