mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
conf: Add storage pool capability formatting
Add support to format the storage pool capabilities using the virStoragePoolTypeInfoPtr to determine what capabilities exist for the various pools and the driver capabilities to determine whether the pool is compiled in and supported. Signed-off-by: John Ferlan <jferlan@redhat.com> ACKed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
5dded8c806
commit
3b1988f3e3
@ -96,6 +96,8 @@ NWFILTER_CONF_SOURCES = \
|
||||
STORAGE_CONF_SOURCES = \
|
||||
conf/storage_adapter_conf.h \
|
||||
conf/storage_adapter_conf.c \
|
||||
conf/storage_capabilities.h \
|
||||
conf/storage_capabilities.c \
|
||||
conf/storage_conf.h \
|
||||
conf/storage_conf.c \
|
||||
conf/virstorageobj.h \
|
||||
|
135
src/conf/storage_capabilities.c
Normal file
135
src/conf/storage_capabilities.c
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* storage_capabilities.c: storage pool capabilities XML processing
|
||||
*
|
||||
* Copyright (C) 2019 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "virerror.h"
|
||||
#include "datatypes.h"
|
||||
#include "capabilities.h"
|
||||
#include "storage_capabilities.h"
|
||||
#include "storage_conf.h"
|
||||
#include "virlog.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_CAPABILITIES
|
||||
|
||||
VIR_LOG_INIT("conf.storage_capabilities");
|
||||
|
||||
static virClassPtr virStoragePoolCapsClass;
|
||||
|
||||
|
||||
static void
|
||||
virStoragePoolCapsDispose(void *obj)
|
||||
{
|
||||
virStoragePoolCapsPtr caps = obj;
|
||||
VIR_DEBUG("obj=%p", caps);
|
||||
|
||||
virObjectUnref(caps->driverCaps);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virStoragePoolCapsOnceInit(void)
|
||||
{
|
||||
if (!VIR_CLASS_NEW(virStoragePoolCaps, virClassForObjectLockable()))
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
VIR_ONCE_GLOBAL_INIT(virStoragePoolCaps);
|
||||
|
||||
|
||||
virStoragePoolCapsPtr
|
||||
virStoragePoolCapsNew(virCapsPtr driverCaps)
|
||||
{
|
||||
virStoragePoolCapsPtr caps = NULL;
|
||||
|
||||
if (virStoragePoolCapsInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(caps = virObjectLockableNew(virStoragePoolCapsClass)))
|
||||
return NULL;
|
||||
|
||||
caps->driverCaps = virObjectRef(driverCaps);
|
||||
|
||||
return caps;
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
virStoragePoolCapsIsLoaded(virCapsPtr driverCaps,
|
||||
int poolType)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!driverCaps)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < driverCaps->npools; i++) {
|
||||
if (driverCaps->pools[i]->type == poolType)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
virStoragePoolCapsFormatPool(virBufferPtr buf,
|
||||
int poolType,
|
||||
virStoragePoolCapsPtr const caps)
|
||||
{
|
||||
bool isLoaded = virStoragePoolCapsIsLoaded(caps->driverCaps, poolType);
|
||||
|
||||
virBufferAsprintf(buf, "<pool type='%s' supported='%s'>\n",
|
||||
virStoragePoolTypeToString(poolType),
|
||||
isLoaded ? "yes" : "no");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
if (virStoragePoolOptionsFormatPool(buf, poolType) < 0)
|
||||
return -1;
|
||||
|
||||
if (virStoragePoolOptionsFormatVolume(buf, poolType) < 0)
|
||||
return -1;
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</pool>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
char *
|
||||
virStoragePoolCapsFormat(virStoragePoolCapsPtr const caps)
|
||||
{
|
||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
||||
size_t i;
|
||||
|
||||
virBufferAddLit(&buf, "<storagepoolCapabilities>\n");
|
||||
virBufferAdjustIndent(&buf, 2);
|
||||
for (i = 0; i < VIR_STORAGE_POOL_LAST; i++) {
|
||||
if (virStoragePoolCapsFormatPool(&buf, i, caps) < 0) {
|
||||
virBufferFreeAndReset(&buf);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
virBufferAdjustIndent(&buf, -2);
|
||||
virBufferAddLit(&buf, "</storagepoolCapabilities>\n");
|
||||
|
||||
return virBufferContentAndReset(&buf);
|
||||
}
|
41
src/conf/storage_capabilities.h
Normal file
41
src/conf/storage_capabilities.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* storage_capabilities.h: storage pool capabilities XML processing
|
||||
*
|
||||
* Copyright (C) 2019 Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef LIBVIRT_STORAGE_CAPABILITIES_H
|
||||
# define LIBVIRT_STORAGE_CAPABILITIES_H
|
||||
|
||||
# include "internal.h"
|
||||
|
||||
typedef struct _virStoragePoolCaps virStoragePoolCaps;
|
||||
typedef virStoragePoolCaps *virStoragePoolCapsPtr;
|
||||
struct _virStoragePoolCaps {
|
||||
virObjectLockable parent;
|
||||
|
||||
virCapsPtr driverCaps;
|
||||
};
|
||||
|
||||
virStoragePoolCapsPtr
|
||||
virStoragePoolCapsNew(virCapsPtr driverCaps);
|
||||
|
||||
char *
|
||||
virStoragePoolCapsFormat(virStoragePoolCapsPtr const caps);
|
||||
|
||||
|
||||
#endif /* LIBVIRT_STORAGE_CAPABILITIES_H */
|
@ -112,6 +112,7 @@ typedef struct _virStorageVolOptions virStorageVolOptions;
|
||||
typedef virStorageVolOptions *virStorageVolOptionsPtr;
|
||||
struct _virStorageVolOptions {
|
||||
int defaultFormat;
|
||||
int lastFormat;
|
||||
virStorageVolFormatToString formatToString;
|
||||
virStorageVolFormatFromString formatFromString;
|
||||
};
|
||||
@ -132,6 +133,7 @@ typedef virStoragePoolOptions *virStoragePoolOptionsPtr;
|
||||
struct _virStoragePoolOptions {
|
||||
unsigned int flags;
|
||||
int defaultFormat;
|
||||
int lastFormat;
|
||||
|
||||
virStoragePoolXMLNamespace ns;
|
||||
|
||||
@ -164,6 +166,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
|
||||
.flags = (VIR_STORAGE_POOL_SOURCE_NAME |
|
||||
VIR_STORAGE_POOL_SOURCE_DEVICE),
|
||||
.defaultFormat = VIR_STORAGE_POOL_LOGICAL_LVM2,
|
||||
.lastFormat = VIR_STORAGE_POOL_LOGICAL_LAST,
|
||||
.formatFromString = virStoragePoolFormatLogicalTypeFromString,
|
||||
.formatToString = virStoragePoolFormatLogicalTypeToString,
|
||||
},
|
||||
@ -171,6 +174,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
|
||||
{.poolType = VIR_STORAGE_POOL_DIR,
|
||||
.volOptions = {
|
||||
.defaultFormat = VIR_STORAGE_FILE_RAW,
|
||||
.lastFormat = VIR_STORAGE_FILE_LAST,
|
||||
.formatFromString = virStorageVolumeFormatFromString,
|
||||
.formatToString = virStorageFileFormatTypeToString,
|
||||
},
|
||||
@ -179,11 +183,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
|
||||
.poolOptions = {
|
||||
.flags = (VIR_STORAGE_POOL_SOURCE_DEVICE),
|
||||
.defaultFormat = VIR_STORAGE_POOL_FS_AUTO,
|
||||
.lastFormat = VIR_STORAGE_POOL_FS_LAST,
|
||||
.formatFromString = virStoragePoolFormatFileSystemTypeFromString,
|
||||
.formatToString = virStoragePoolFormatFileSystemTypeToString,
|
||||
},
|
||||
.volOptions = {
|
||||
.defaultFormat = VIR_STORAGE_FILE_RAW,
|
||||
.lastFormat = VIR_STORAGE_FILE_LAST,
|
||||
.formatFromString = virStorageVolumeFormatFromString,
|
||||
.formatToString = virStorageFileFormatTypeToString,
|
||||
},
|
||||
@ -193,11 +199,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
|
||||
.flags = (VIR_STORAGE_POOL_SOURCE_HOST |
|
||||
VIR_STORAGE_POOL_SOURCE_DIR),
|
||||
.defaultFormat = VIR_STORAGE_POOL_NETFS_AUTO,
|
||||
.lastFormat = VIR_STORAGE_POOL_NETFS_LAST,
|
||||
.formatFromString = virStoragePoolFormatFileSystemNetTypeFromString,
|
||||
.formatToString = virStoragePoolFormatFileSystemNetTypeToString,
|
||||
},
|
||||
.volOptions = {
|
||||
.defaultFormat = VIR_STORAGE_FILE_RAW,
|
||||
.lastFormat = VIR_STORAGE_FILE_LAST,
|
||||
.formatFromString = virStorageVolumeFormatFromString,
|
||||
.formatToString = virStorageFileFormatTypeToString,
|
||||
},
|
||||
@ -245,6 +253,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
|
||||
},
|
||||
.volOptions = {
|
||||
.defaultFormat = VIR_STORAGE_FILE_RAW,
|
||||
.lastFormat = VIR_STORAGE_FILE_LAST,
|
||||
.formatToString = virStorageFileFormatTypeToString,
|
||||
.formatFromString = virStorageVolumeFormatFromString,
|
||||
}
|
||||
@ -255,11 +264,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
|
||||
.poolOptions = {
|
||||
.flags = (VIR_STORAGE_POOL_SOURCE_DEVICE),
|
||||
.defaultFormat = VIR_STORAGE_POOL_DISK_UNKNOWN,
|
||||
.lastFormat = VIR_STORAGE_POOL_DISK_LAST,
|
||||
.formatFromString = virStoragePoolFormatDiskTypeFromString,
|
||||
.formatToString = virStoragePoolFormatDiskTypeToString,
|
||||
},
|
||||
.volOptions = {
|
||||
.defaultFormat = VIR_STORAGE_VOL_DISK_NONE,
|
||||
.lastFormat = VIR_STORAGE_VOL_DISK_LAST,
|
||||
.formatFromString = virStorageVolFormatDiskTypeFromString,
|
||||
.formatToString = virStorageVolFormatDiskTypeToString,
|
||||
},
|
||||
@ -276,6 +287,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
|
||||
},
|
||||
.volOptions = {
|
||||
.defaultFormat = VIR_STORAGE_FILE_RAW,
|
||||
.lastFormat = VIR_STORAGE_FILE_LAST,
|
||||
.formatFromString = virStorageVolumeFormatFromString,
|
||||
.formatToString = virStorageFileFormatTypeToString,
|
||||
},
|
||||
@ -345,6 +357,103 @@ virStorageVolOptionsForPoolType(int type)
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virStoragePoolOptionsFormatPool(virBufferPtr buf,
|
||||
int type)
|
||||
{
|
||||
virStoragePoolOptionsPtr poolOptions;
|
||||
|
||||
if (!(poolOptions = virStoragePoolOptionsForPoolType(type)))
|
||||
return -1;
|
||||
|
||||
if (!poolOptions->formatToString && !poolOptions->flags)
|
||||
return 0;
|
||||
|
||||
virBufferAddLit(buf, "<poolOptions>\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
if (poolOptions->formatToString) {
|
||||
size_t i;
|
||||
|
||||
virBufferAsprintf(buf, "<defaultFormat type='%s'/>\n",
|
||||
(poolOptions->formatToString)(poolOptions->defaultFormat));
|
||||
|
||||
virBufferAddLit(buf, "<enum name='sourceFormatType'>\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
for (i = 0; i < poolOptions->lastFormat; i++)
|
||||
virBufferAsprintf(buf, "<value>%s</value>\n",
|
||||
(poolOptions->formatToString)(i));
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</enum>\n");
|
||||
}
|
||||
|
||||
if (poolOptions->flags) {
|
||||
virBufferAddLit(buf, "<enum name='requiredSourceElements'>\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_HOST)
|
||||
virBufferAddLit(buf, "<value>host</value>\n");
|
||||
if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_DEVICE)
|
||||
virBufferAddLit(buf, "<value>device</value>\n");
|
||||
if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_DIR)
|
||||
virBufferAddLit(buf, "<value>dir</value>\n");
|
||||
if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER)
|
||||
virBufferAddLit(buf, "<value>adapter</value>\n");
|
||||
if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_NAME)
|
||||
virBufferAddLit(buf, "<value>name</value>\n");
|
||||
if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_INITIATOR_IQN)
|
||||
virBufferAddLit(buf, "<value>initiator</value>\n");
|
||||
if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)
|
||||
virBufferAddLit(buf, "<value>network</value>\n");
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</enum>\n");
|
||||
}
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</poolOptions>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virStoragePoolOptionsFormatVolume(virBufferPtr buf,
|
||||
int type)
|
||||
{
|
||||
size_t i;
|
||||
virStorageVolOptionsPtr volOptions;
|
||||
|
||||
if (!(volOptions = virStorageVolOptionsForPoolType(type)))
|
||||
return -1;
|
||||
|
||||
if (!volOptions->formatToString)
|
||||
return 0;
|
||||
|
||||
virBufferAddLit(buf, "<volOptions>\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
virBufferAsprintf(buf, "<defaultFormat type='%s'/>\n",
|
||||
(volOptions->formatToString)(volOptions->defaultFormat));
|
||||
|
||||
virBufferAddLit(buf, "<enum name='targetFormatType'>\n");
|
||||
virBufferAdjustIndent(buf, 2);
|
||||
|
||||
for (i = 0; i < volOptions->lastFormat; i++)
|
||||
virBufferAsprintf(buf, "<value>%s</value>\n",
|
||||
(volOptions->formatToString)(i));
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</enum>\n");
|
||||
|
||||
virBufferAdjustIndent(buf, -2);
|
||||
virBufferAddLit(buf, "</volOptions>\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
virStorageVolDefFree(virStorageVolDefPtr def)
|
||||
{
|
||||
|
@ -53,6 +53,13 @@ int
|
||||
virStoragePoolOptionsPoolTypeSetXMLNamespace(int type,
|
||||
virStoragePoolXMLNamespacePtr ns);
|
||||
|
||||
int
|
||||
virStoragePoolOptionsFormatPool(virBufferPtr buf,
|
||||
int type);
|
||||
|
||||
int
|
||||
virStoragePoolOptionsFormatVolume(virBufferPtr buf,
|
||||
int type);
|
||||
/*
|
||||
* How the volume's data is stored on underlying
|
||||
* physical devices - can potentially span many
|
||||
|
@ -912,6 +912,11 @@ virStorageAdapterParseXML;
|
||||
virStorageAdapterValidate;
|
||||
|
||||
|
||||
# conf/storage_capabilities.h
|
||||
virStoragePoolCapsFormat;
|
||||
virStoragePoolCapsNew;
|
||||
|
||||
|
||||
# conf/storage_conf.h
|
||||
virStoragePartedFsTypeToString;
|
||||
virStoragePoolDefFormat;
|
||||
@ -925,6 +930,8 @@ virStoragePoolFormatDiskTypeToString;
|
||||
virStoragePoolFormatFileSystemNetTypeToString;
|
||||
virStoragePoolFormatFileSystemTypeToString;
|
||||
virStoragePoolFormatLogicalTypeToString;
|
||||
virStoragePoolOptionsFormatPool;
|
||||
virStoragePoolOptionsFormatVolume;
|
||||
virStoragePoolOptionsPoolTypeSetXMLNamespace;
|
||||
virStoragePoolSaveConfig;
|
||||
virStoragePoolSaveState;
|
||||
|
Loading…
Reference in New Issue
Block a user