From 05fe03505afac2583bc2d81373b967cd8031a48e Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Thu, 10 Jan 2019 07:19:35 -0500 Subject: [PATCH] conf: Introduce storage pool functions into capabilities Introduce the bare bones functions to processing capability data for the storage driver. Since there will be no need for the output, we need to filter that data. Signed-off-by: John Ferlan ACKed-by: Michal Privoznik --- src/conf/capabilities.c | 74 ++++++++++++++++++++++++++++++++++++++++ src/conf/capabilities.h | 15 ++++++++ src/libvirt_private.syms | 1 + 3 files changed, 90 insertions(+) diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 716ac6e2e7..47308700bb 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -28,6 +28,7 @@ #include "cpu_conf.h" #include "domain_conf.h" #include "physmem.h" +#include "storage_conf.h" #include "viralloc.h" #include "virarch.h" #include "virbuffer.h" @@ -181,6 +182,17 @@ virCapabilitiesFreeGuest(virCapsGuestPtr guest) VIR_FREE(guest); } + +static void +virCapabilitiesFreeStoragePool(virCapsStoragePoolPtr pool) +{ + if (!pool) + return; + + VIR_FREE(pool); +} + + void virCapabilitiesFreeNUMAInfo(virCapsPtr caps) { @@ -222,6 +234,10 @@ virCapsDispose(void *object) virCapsPtr caps = object; size_t i; + for (i = 0; i < caps->npools; i++) + virCapabilitiesFreeStoragePool(caps->pools[i]); + VIR_FREE(caps->pools); + for (i = 0; i < caps->nguests; i++) virCapabilitiesFreeGuest(caps->guests[i]); VIR_FREE(caps->guests); @@ -793,6 +809,30 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps, emulator, machinetype); } + +int +virCapabilitiesAddStoragePool(virCapsPtr caps, + int poolType) +{ + virCapsStoragePoolPtr pool; + + if (VIR_ALLOC(pool) < 0) + goto error; + + pool->type = poolType; + + if (VIR_RESIZE_N(caps->pools, caps->npools_max, caps->npools, 1) < 0) + goto error; + caps->pools[caps->npools++] = pool; + + return 0; + + error: + virCapabilitiesFreeStoragePool(pool); + return -1; +} + + static int virCapabilitiesFormatNUMATopology(virBufferPtr buf, size_t ncells, @@ -1065,6 +1105,12 @@ virCapabilitiesFormatHostXML(virCapsHostPtr host, size_t i, j; char host_uuid[VIR_UUID_STRING_BUFLEN]; + /* The lack of some data means we have nothing + * minimally to format, so just return. */ + if (!virUUIDIsValid(host->host_uuid) && + !host->arch && !host->powerMgmt && !host->iommu) + return 0; + virBufferAddLit(buf, "\n"); virBufferAdjustIndent(buf, 2); if (virUUIDIsValid(host->host_uuid)) { @@ -1277,6 +1323,32 @@ virCapabilitiesFormatGuestXML(virCapsGuestPtr *guests, } +static void +virCapabilitiesFormatStoragePoolXML(virCapsStoragePoolPtr *pools, + size_t npools, + virBufferPtr buf) +{ + size_t i; + + if (npools == 0) + return; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (i = 0; i < npools; i++) + virBufferAsprintf(buf, "%s\n", + virStoragePoolTypeToString(pools[i]->type)); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n\n"); +} + + /** * virCapabilitiesFormatXML: * @caps: capabilities to format @@ -1298,6 +1370,8 @@ virCapabilitiesFormatXML(virCapsPtr caps) virCapabilitiesFormatGuestXML(caps->guests, caps->nguests, &buf); + virCapabilitiesFormatStoragePoolXML(caps->pools, caps->npools, &buf); + virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h index 31c2a07a9b..cca1a20949 100644 --- a/src/conf/capabilities.h +++ b/src/conf/capabilities.h @@ -211,6 +211,13 @@ struct _virCapsHost { bool iommu; }; +typedef struct _virCapsStoragePool virCapsStoragePool; +typedef virCapsStoragePool *virCapsStoragePoolPtr; +struct _virCapsStoragePool { + int type; +}; + + typedef int (*virDomainDefNamespaceParse)(xmlDocPtr, xmlNodePtr, xmlXPathContextPtr, void **); typedef void (*virDomainDefNamespaceFree)(void *); @@ -235,6 +242,10 @@ struct _virCaps { size_t nguests; size_t nguests_max; virCapsGuestPtr *guests; + + size_t npools; + size_t npools_max; + virCapsStoragePoolPtr *pools; }; typedef struct _virCapsDomainData virCapsDomainData; @@ -318,6 +329,10 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest, bool defaultOn, bool toggle); +int +virCapabilitiesAddStoragePool(virCapsPtr caps, + int poolType); + int virCapabilitiesHostSecModelAddBaseLabel(virCapsHostSecModelPtr secmodel, const char *type, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 69643732e0..6d78db2b94 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -49,6 +49,7 @@ virCapabilitiesAddGuestFeature; virCapabilitiesAddHostFeature; virCapabilitiesAddHostMigrateTransport; virCapabilitiesAddHostNUMACell; +virCapabilitiesAddStoragePool; virCapabilitiesAllocMachines; virCapabilitiesClearHostNUMACellCPUTopology; virCapabilitiesDomainDataLookup; -- GitLab