提交 3b1988f3 编写于 作者: J John Ferlan

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: NJohn Ferlan <jferlan@redhat.com>
ACKed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 5dded8c8
...@@ -96,6 +96,8 @@ NWFILTER_CONF_SOURCES = \ ...@@ -96,6 +96,8 @@ NWFILTER_CONF_SOURCES = \
STORAGE_CONF_SOURCES = \ STORAGE_CONF_SOURCES = \
conf/storage_adapter_conf.h \ conf/storage_adapter_conf.h \
conf/storage_adapter_conf.c \ conf/storage_adapter_conf.c \
conf/storage_capabilities.h \
conf/storage_capabilities.c \
conf/storage_conf.h \ conf/storage_conf.h \
conf/storage_conf.c \ conf/storage_conf.c \
conf/virstorageobj.h \ conf/virstorageobj.h \
......
/*
* 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);
}
/*
* 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; ...@@ -112,6 +112,7 @@ typedef struct _virStorageVolOptions virStorageVolOptions;
typedef virStorageVolOptions *virStorageVolOptionsPtr; typedef virStorageVolOptions *virStorageVolOptionsPtr;
struct _virStorageVolOptions { struct _virStorageVolOptions {
int defaultFormat; int defaultFormat;
int lastFormat;
virStorageVolFormatToString formatToString; virStorageVolFormatToString formatToString;
virStorageVolFormatFromString formatFromString; virStorageVolFormatFromString formatFromString;
}; };
...@@ -132,6 +133,7 @@ typedef virStoragePoolOptions *virStoragePoolOptionsPtr; ...@@ -132,6 +133,7 @@ typedef virStoragePoolOptions *virStoragePoolOptionsPtr;
struct _virStoragePoolOptions { struct _virStoragePoolOptions {
unsigned int flags; unsigned int flags;
int defaultFormat; int defaultFormat;
int lastFormat;
virStoragePoolXMLNamespace ns; virStoragePoolXMLNamespace ns;
...@@ -164,6 +166,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = { ...@@ -164,6 +166,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
.flags = (VIR_STORAGE_POOL_SOURCE_NAME | .flags = (VIR_STORAGE_POOL_SOURCE_NAME |
VIR_STORAGE_POOL_SOURCE_DEVICE), VIR_STORAGE_POOL_SOURCE_DEVICE),
.defaultFormat = VIR_STORAGE_POOL_LOGICAL_LVM2, .defaultFormat = VIR_STORAGE_POOL_LOGICAL_LVM2,
.lastFormat = VIR_STORAGE_POOL_LOGICAL_LAST,
.formatFromString = virStoragePoolFormatLogicalTypeFromString, .formatFromString = virStoragePoolFormatLogicalTypeFromString,
.formatToString = virStoragePoolFormatLogicalTypeToString, .formatToString = virStoragePoolFormatLogicalTypeToString,
}, },
...@@ -171,6 +174,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = { ...@@ -171,6 +174,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
{.poolType = VIR_STORAGE_POOL_DIR, {.poolType = VIR_STORAGE_POOL_DIR,
.volOptions = { .volOptions = {
.defaultFormat = VIR_STORAGE_FILE_RAW, .defaultFormat = VIR_STORAGE_FILE_RAW,
.lastFormat = VIR_STORAGE_FILE_LAST,
.formatFromString = virStorageVolumeFormatFromString, .formatFromString = virStorageVolumeFormatFromString,
.formatToString = virStorageFileFormatTypeToString, .formatToString = virStorageFileFormatTypeToString,
}, },
...@@ -179,11 +183,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] = { ...@@ -179,11 +183,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
.poolOptions = { .poolOptions = {
.flags = (VIR_STORAGE_POOL_SOURCE_DEVICE), .flags = (VIR_STORAGE_POOL_SOURCE_DEVICE),
.defaultFormat = VIR_STORAGE_POOL_FS_AUTO, .defaultFormat = VIR_STORAGE_POOL_FS_AUTO,
.lastFormat = VIR_STORAGE_POOL_FS_LAST,
.formatFromString = virStoragePoolFormatFileSystemTypeFromString, .formatFromString = virStoragePoolFormatFileSystemTypeFromString,
.formatToString = virStoragePoolFormatFileSystemTypeToString, .formatToString = virStoragePoolFormatFileSystemTypeToString,
}, },
.volOptions = { .volOptions = {
.defaultFormat = VIR_STORAGE_FILE_RAW, .defaultFormat = VIR_STORAGE_FILE_RAW,
.lastFormat = VIR_STORAGE_FILE_LAST,
.formatFromString = virStorageVolumeFormatFromString, .formatFromString = virStorageVolumeFormatFromString,
.formatToString = virStorageFileFormatTypeToString, .formatToString = virStorageFileFormatTypeToString,
}, },
...@@ -193,11 +199,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] = { ...@@ -193,11 +199,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
.flags = (VIR_STORAGE_POOL_SOURCE_HOST | .flags = (VIR_STORAGE_POOL_SOURCE_HOST |
VIR_STORAGE_POOL_SOURCE_DIR), VIR_STORAGE_POOL_SOURCE_DIR),
.defaultFormat = VIR_STORAGE_POOL_NETFS_AUTO, .defaultFormat = VIR_STORAGE_POOL_NETFS_AUTO,
.lastFormat = VIR_STORAGE_POOL_NETFS_LAST,
.formatFromString = virStoragePoolFormatFileSystemNetTypeFromString, .formatFromString = virStoragePoolFormatFileSystemNetTypeFromString,
.formatToString = virStoragePoolFormatFileSystemNetTypeToString, .formatToString = virStoragePoolFormatFileSystemNetTypeToString,
}, },
.volOptions = { .volOptions = {
.defaultFormat = VIR_STORAGE_FILE_RAW, .defaultFormat = VIR_STORAGE_FILE_RAW,
.lastFormat = VIR_STORAGE_FILE_LAST,
.formatFromString = virStorageVolumeFormatFromString, .formatFromString = virStorageVolumeFormatFromString,
.formatToString = virStorageFileFormatTypeToString, .formatToString = virStorageFileFormatTypeToString,
}, },
...@@ -245,6 +253,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = { ...@@ -245,6 +253,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
}, },
.volOptions = { .volOptions = {
.defaultFormat = VIR_STORAGE_FILE_RAW, .defaultFormat = VIR_STORAGE_FILE_RAW,
.lastFormat = VIR_STORAGE_FILE_LAST,
.formatToString = virStorageFileFormatTypeToString, .formatToString = virStorageFileFormatTypeToString,
.formatFromString = virStorageVolumeFormatFromString, .formatFromString = virStorageVolumeFormatFromString,
} }
...@@ -255,11 +264,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] = { ...@@ -255,11 +264,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
.poolOptions = { .poolOptions = {
.flags = (VIR_STORAGE_POOL_SOURCE_DEVICE), .flags = (VIR_STORAGE_POOL_SOURCE_DEVICE),
.defaultFormat = VIR_STORAGE_POOL_DISK_UNKNOWN, .defaultFormat = VIR_STORAGE_POOL_DISK_UNKNOWN,
.lastFormat = VIR_STORAGE_POOL_DISK_LAST,
.formatFromString = virStoragePoolFormatDiskTypeFromString, .formatFromString = virStoragePoolFormatDiskTypeFromString,
.formatToString = virStoragePoolFormatDiskTypeToString, .formatToString = virStoragePoolFormatDiskTypeToString,
}, },
.volOptions = { .volOptions = {
.defaultFormat = VIR_STORAGE_VOL_DISK_NONE, .defaultFormat = VIR_STORAGE_VOL_DISK_NONE,
.lastFormat = VIR_STORAGE_VOL_DISK_LAST,
.formatFromString = virStorageVolFormatDiskTypeFromString, .formatFromString = virStorageVolFormatDiskTypeFromString,
.formatToString = virStorageVolFormatDiskTypeToString, .formatToString = virStorageVolFormatDiskTypeToString,
}, },
...@@ -276,6 +287,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = { ...@@ -276,6 +287,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] = {
}, },
.volOptions = { .volOptions = {
.defaultFormat = VIR_STORAGE_FILE_RAW, .defaultFormat = VIR_STORAGE_FILE_RAW,
.lastFormat = VIR_STORAGE_FILE_LAST,
.formatFromString = virStorageVolumeFormatFromString, .formatFromString = virStorageVolumeFormatFromString,
.formatToString = virStorageFileFormatTypeToString, .formatToString = virStorageFileFormatTypeToString,
}, },
...@@ -345,6 +357,103 @@ virStorageVolOptionsForPoolType(int type) ...@@ -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 void
virStorageVolDefFree(virStorageVolDefPtr def) virStorageVolDefFree(virStorageVolDefPtr def)
{ {
......
...@@ -53,6 +53,13 @@ int ...@@ -53,6 +53,13 @@ int
virStoragePoolOptionsPoolTypeSetXMLNamespace(int type, virStoragePoolOptionsPoolTypeSetXMLNamespace(int type,
virStoragePoolXMLNamespacePtr ns); virStoragePoolXMLNamespacePtr ns);
int
virStoragePoolOptionsFormatPool(virBufferPtr buf,
int type);
int
virStoragePoolOptionsFormatVolume(virBufferPtr buf,
int type);
/* /*
* How the volume's data is stored on underlying * How the volume's data is stored on underlying
* physical devices - can potentially span many * physical devices - can potentially span many
......
...@@ -912,6 +912,11 @@ virStorageAdapterParseXML; ...@@ -912,6 +912,11 @@ virStorageAdapterParseXML;
virStorageAdapterValidate; virStorageAdapterValidate;
# conf/storage_capabilities.h
virStoragePoolCapsFormat;
virStoragePoolCapsNew;
# conf/storage_conf.h # conf/storage_conf.h
virStoragePartedFsTypeToString; virStoragePartedFsTypeToString;
virStoragePoolDefFormat; virStoragePoolDefFormat;
...@@ -925,6 +930,8 @@ virStoragePoolFormatDiskTypeToString; ...@@ -925,6 +930,8 @@ virStoragePoolFormatDiskTypeToString;
virStoragePoolFormatFileSystemNetTypeToString; virStoragePoolFormatFileSystemNetTypeToString;
virStoragePoolFormatFileSystemTypeToString; virStoragePoolFormatFileSystemTypeToString;
virStoragePoolFormatLogicalTypeToString; virStoragePoolFormatLogicalTypeToString;
virStoragePoolOptionsFormatPool;
virStoragePoolOptionsFormatVolume;
virStoragePoolOptionsPoolTypeSetXMLNamespace; virStoragePoolOptionsPoolTypeSetXMLNamespace;
virStoragePoolSaveConfig; virStoragePoolSaveConfig;
virStoragePoolSaveState; virStoragePoolSaveState;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册