diff mbox series

[3/7] qemu: conf: add virQEMUDriverGetDomainCapabilities

Message ID 5b90f49b349c1d9379544a8a091a9d3a0618fc04.1554419814.git.crobinso@redhat.com
State Accepted
Commit d05bdff79b9bf4e6e49fbaf09cc0b776d127ac7e
Headers show
Series qemu: use domCaps for validation | expand

Commit Message

Cole Robinson April 4, 2019, 11:37 p.m. UTC
For now it's just a helper for building a qemu virDomainCapsPtr.
It will be used in upcoming patches

Signed-off-by: Cole Robinson <crobinso@redhat.com>

---
 src/qemu/qemu_conf.c   | 39 +++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_conf.h   |  7 +++++++
 src/qemu/qemu_driver.c | 18 +++---------------
 3 files changed, 49 insertions(+), 15 deletions(-)

-- 
2.21.0

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

Comments

Daniel Henrique Barboza April 26, 2019, 8:43 p.m. UTC | #1
On 4/4/19 8:37 PM, Cole Robinson wrote:
> For now it's just a helper for building a qemu virDomainCapsPtr.

> It will be used in upcoming patches


It is already being used at qemuConnectGetDomainCapabilities,
making the flow easier to read. Perhaps something worth mentioning
in the commit msg.


Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>



>

> Signed-off-by: Cole Robinson <crobinso@redhat.com>

> ---

>   src/qemu/qemu_conf.c   | 39 +++++++++++++++++++++++++++++++++++++++

>   src/qemu/qemu_conf.h   |  7 +++++++

>   src/qemu/qemu_driver.c | 18 +++---------------

>   3 files changed, 49 insertions(+), 15 deletions(-)

>

> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c

> index 41ce0a978d..635fdcc5a4 100644

> --- a/src/qemu/qemu_conf.c

> +++ b/src/qemu/qemu_conf.c

> @@ -1357,6 +1357,45 @@ virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,

>       return ret;

>   }

>   

> +

> +/**

> + * virQEMUDriverGetDomainCapabilities:

> + *

> + * Build a virDomainCapsPtr instance for the passed data.

> + *

> + * Returns: a reference to a virDomainCapsPtr instance or NULL

> + */

> +virDomainCapsPtr

> +virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,

> +                                   virQEMUCapsPtr qemuCaps,

> +                                   const char *machine,

> +                                   virArch arch,

> +                                   virDomainVirtType virttype)

> +{

> +    virDomainCapsPtr ret = NULL, domCaps = NULL;

> +    virCapsPtr caps = NULL;

> +    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);

> +

> +    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))

> +        goto cleanup;

> +

> +    if (!(domCaps = virDomainCapsNew(virQEMUCapsGetBinary(qemuCaps), machine,

> +                                     arch, virttype)))

> +        goto cleanup;

> +

> +    if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,

> +                                  cfg->firmwares, cfg->nfirmwares) < 0)

> +        goto cleanup;

> +

> +    VIR_STEAL_PTR(ret, domCaps);

> + cleanup:

> +    virObjectUnref(domCaps);

> +    virObjectUnref(cfg);

> +    virObjectUnref(caps);

> +    return ret;

> +}

> +

> +

>   struct _qemuSharedDeviceEntry {

>       size_t ref;

>       char **domains; /* array of domain names */

> diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h

> index 14c9d15a72..ddf5ea4b8f 100644

> --- a/src/qemu/qemu_conf.h

> +++ b/src/qemu/qemu_conf.h

> @@ -331,6 +331,13 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver);

>   virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,

>                                           bool refresh);

>   

> +virDomainCapsPtr

> +virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,

> +                                   virQEMUCapsPtr qemuCaps,

> +                                   const char *machine,

> +                                   virArch arch,

> +                                   virDomainVirtType virttype);

> +

>   typedef struct _qemuSharedDeviceEntry qemuSharedDeviceEntry;

>   typedef qemuSharedDeviceEntry *qemuSharedDeviceEntryPtr;

>   

> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c

> index 7e5bbc3cc9..3e8ae8a4dc 100644

> --- a/src/qemu/qemu_driver.c

> +++ b/src/qemu/qemu_driver.c

> @@ -19829,19 +19829,12 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,

>       virArch arch;

>       virDomainVirtType virttype;

>       virDomainCapsPtr domCaps = NULL;

> -    virQEMUDriverConfigPtr cfg = NULL;

> -    virCapsPtr caps = NULL;

>   

>       virCheckFlags(0, ret);

>   

>       if (virConnectGetDomainCapabilitiesEnsureACL(conn) < 0)

>           return ret;

>   

> -    cfg = virQEMUDriverGetConfig(driver);

> -

> -    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))

> -        goto cleanup;

> -

>       qemuCaps = virQEMUCapsCacheLookupDefault(driver->qemuCapsCache,

>                                                emulatorbin,

>                                                arch_str,

> @@ -19851,18 +19844,13 @@ qemuConnectGetDomainCapabilities(virConnectPtr conn,

>       if (!qemuCaps)

>           goto cleanup;

>   

> -    if (!(domCaps = virDomainCapsNew(virQEMUCapsGetBinary(qemuCaps), machine,

> -                                     arch, virttype)))

> -        goto cleanup;

> -

> -    if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,

> -                                  cfg->firmwares, cfg->nfirmwares) < 0)

> +    if (!(domCaps = virQEMUDriverGetDomainCapabilities(driver,

> +                                                       qemuCaps, machine,

> +                                                       arch, virttype)))

>           goto cleanup;

>   

>       ret = virDomainCapsFormat(domCaps);

>    cleanup:

> -    virObjectUnref(cfg);

> -    virObjectUnref(caps);

>       virObjectUnref(domCaps);

>       virObjectUnref(qemuCaps);

>       return ret;


--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Michal Prívozník April 29, 2019, 12:35 p.m. UTC | #2
On 4/5/19 1:37 AM, Cole Robinson wrote:
> For now it's just a helper for building a qemu virDomainCapsPtr.

> It will be used in upcoming patches

> 

> Signed-off-by: Cole Robinson <crobinso@redhat.com>

> ---

>   src/qemu/qemu_conf.c   | 39 +++++++++++++++++++++++++++++++++++++++

>   src/qemu/qemu_conf.h   |  7 +++++++

>   src/qemu/qemu_driver.c | 18 +++---------------

>   3 files changed, 49 insertions(+), 15 deletions(-)

> 

> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c

> index 41ce0a978d..635fdcc5a4 100644

> --- a/src/qemu/qemu_conf.c

> +++ b/src/qemu/qemu_conf.c

> @@ -1357,6 +1357,45 @@ virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,

>       return ret;

>   }

>   

> +

> +/**

> + * virQEMUDriverGetDomainCapabilities:

> + *

> + * Build a virDomainCapsPtr instance for the passed data.

> + *

> + * Returns: a reference to a virDomainCapsPtr instance or NULL

> + */

> +virDomainCapsPtr

> +virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,

> +                                   virQEMUCapsPtr qemuCaps,

> +                                   const char *machine,

> +                                   virArch arch,

> +                                   virDomainVirtType virttype)

> +{

> +    virDomainCapsPtr ret = NULL, domCaps = NULL;

> +    virCapsPtr caps = NULL;

> +    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);

> +

> +    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))

> +        goto cleanup;

> +

> +    if (!(domCaps = virDomainCapsNew(virQEMUCapsGetBinary(qemuCaps), machine,

> +                                     arch, virttype)))

> +        goto cleanup;

> +

> +    if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,

> +                                  cfg->firmwares, cfg->nfirmwares) < 0)


You'll need to rebase this because after 5b9819eedc7 there's @privileged 
argument.

> +        goto cleanup;

> +

> +    VIR_STEAL_PTR(ret, domCaps);

> + cleanup:

> +    virObjectUnref(domCaps);

> +    virObjectUnref(cfg);

> +    virObjectUnref(caps);

> +    return ret;

> +}

> +

> +


Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
diff mbox series

Patch

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 41ce0a978d..635fdcc5a4 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1357,6 +1357,45 @@  virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
     return ret;
 }
 
+
+/**
+ * virQEMUDriverGetDomainCapabilities:
+ *
+ * Build a virDomainCapsPtr instance for the passed data.
+ *
+ * Returns: a reference to a virDomainCapsPtr instance or NULL
+ */
+virDomainCapsPtr
+virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,
+                                   virQEMUCapsPtr qemuCaps,
+                                   const char *machine,
+                                   virArch arch,
+                                   virDomainVirtType virttype)
+{
+    virDomainCapsPtr ret = NULL, domCaps = NULL;
+    virCapsPtr caps = NULL;
+    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
+
+    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
+        goto cleanup;
+
+    if (!(domCaps = virDomainCapsNew(virQEMUCapsGetBinary(qemuCaps), machine,
+                                     arch, virttype)))
+        goto cleanup;
+
+    if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,
+                                  cfg->firmwares, cfg->nfirmwares) < 0)
+        goto cleanup;
+
+    VIR_STEAL_PTR(ret, domCaps);
+ cleanup:
+    virObjectUnref(domCaps);
+    virObjectUnref(cfg);
+    virObjectUnref(caps);
+    return ret;
+}
+
+
 struct _qemuSharedDeviceEntry {
     size_t ref;
     char **domains; /* array of domain names */
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 14c9d15a72..ddf5ea4b8f 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -331,6 +331,13 @@  virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver);
 virCapsPtr virQEMUDriverGetCapabilities(virQEMUDriverPtr driver,
                                         bool refresh);
 
+virDomainCapsPtr
+virQEMUDriverGetDomainCapabilities(virQEMUDriverPtr driver,
+                                   virQEMUCapsPtr qemuCaps,
+                                   const char *machine,
+                                   virArch arch,
+                                   virDomainVirtType virttype);
+
 typedef struct _qemuSharedDeviceEntry qemuSharedDeviceEntry;
 typedef qemuSharedDeviceEntry *qemuSharedDeviceEntryPtr;
 
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7e5bbc3cc9..3e8ae8a4dc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -19829,19 +19829,12 @@  qemuConnectGetDomainCapabilities(virConnectPtr conn,
     virArch arch;
     virDomainVirtType virttype;
     virDomainCapsPtr domCaps = NULL;
-    virQEMUDriverConfigPtr cfg = NULL;
-    virCapsPtr caps = NULL;
 
     virCheckFlags(0, ret);
 
     if (virConnectGetDomainCapabilitiesEnsureACL(conn) < 0)
         return ret;
 
-    cfg = virQEMUDriverGetConfig(driver);
-
-    if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
-        goto cleanup;
-
     qemuCaps = virQEMUCapsCacheLookupDefault(driver->qemuCapsCache,
                                              emulatorbin,
                                              arch_str,
@@ -19851,18 +19844,13 @@  qemuConnectGetDomainCapabilities(virConnectPtr conn,
     if (!qemuCaps)
         goto cleanup;
 
-    if (!(domCaps = virDomainCapsNew(virQEMUCapsGetBinary(qemuCaps), machine,
-                                     arch, virttype)))
-        goto cleanup;
-
-    if (virQEMUCapsFillDomainCaps(caps, domCaps, qemuCaps,
-                                  cfg->firmwares, cfg->nfirmwares) < 0)
+    if (!(domCaps = virQEMUDriverGetDomainCapabilities(driver,
+                                                       qemuCaps, machine,
+                                                       arch, virttype)))
         goto cleanup;
 
     ret = virDomainCapsFormat(domCaps);
  cleanup:
-    virObjectUnref(cfg);
-    virObjectUnref(caps);
     virObjectUnref(domCaps);
     virObjectUnref(qemuCaps);
     return ret;