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 <host> output, we need
to filter that data.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
John Ferlan 2019-01-10 07:19:35 -05:00
parent 05fade52fe
commit 05fe03505a
3 changed files with 90 additions and 0 deletions

View File

@ -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, "<host>\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, "<pool>\n");
virBufferAdjustIndent(buf, 2);
virBufferAddLit(buf, "<enum name='type'>\n");
virBufferAdjustIndent(buf, 2);
for (i = 0; i < npools; i++)
virBufferAsprintf(buf, "<value>%s</value>\n",
virStoragePoolTypeToString(pools[i]->type));
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</enum>\n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</pool>\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, "</capabilities>\n");

View File

@ -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,

View File

@ -49,6 +49,7 @@ virCapabilitiesAddGuestFeature;
virCapabilitiesAddHostFeature;
virCapabilitiesAddHostMigrateTransport;
virCapabilitiesAddHostNUMACell;
virCapabilitiesAddStoragePool;
virCapabilitiesAllocMachines;
virCapabilitiesClearHostNUMACellCPUTopology;
virCapabilitiesDomainDataLookup;