diff --git a/src/conf/Makefile.inc.am b/src/conf/Makefile.inc.am
index 219ff350d77672e13841da375d34c958c0327abf..fb2ec0e785aa0097b16277710ea180bb8613750c 100644
--- a/src/conf/Makefile.inc.am
+++ b/src/conf/Makefile.inc.am
@@ -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 \
diff --git a/src/conf/storage_capabilities.c b/src/conf/storage_capabilities.c
new file mode 100644
index 0000000000000000000000000000000000000000..cf3ee488aca162b1a3a8e1a2648669332137509c
--- /dev/null
+++ b/src/conf/storage_capabilities.c
@@ -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
+ * .
+ */
+
+#include
+
+#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, "\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, "\n");
+ return 0;
+}
+
+
+char *
+virStoragePoolCapsFormat(virStoragePoolCapsPtr const caps)
+{
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ size_t i;
+
+ virBufferAddLit(&buf, "\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, "\n");
+
+ return virBufferContentAndReset(&buf);
+}
diff --git a/src/conf/storage_capabilities.h b/src/conf/storage_capabilities.h
new file mode 100644
index 0000000000000000000000000000000000000000..daeb4969097194e2c4bdc1e4e920f6ead846f65a
--- /dev/null
+++ b/src/conf/storage_capabilities.h
@@ -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
+ * .
+ */
+
+#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 */
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 7fea478a8888b9e7b74f8c0df1b9cc500f138ec0..751a00aaf0c006472f5779d34a9e4a01a7580982 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -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, "\n");
+ virBufferAdjustIndent(buf, 2);
+
+ if (poolOptions->formatToString) {
+ size_t i;
+
+ virBufferAsprintf(buf, "\n",
+ (poolOptions->formatToString)(poolOptions->defaultFormat));
+
+ virBufferAddLit(buf, "\n");
+ virBufferAdjustIndent(buf, 2);
+
+ for (i = 0; i < poolOptions->lastFormat; i++)
+ virBufferAsprintf(buf, "%s\n",
+ (poolOptions->formatToString)(i));
+
+ virBufferAdjustIndent(buf, -2);
+ virBufferAddLit(buf, "\n");
+ }
+
+ if (poolOptions->flags) {
+ virBufferAddLit(buf, "\n");
+ virBufferAdjustIndent(buf, 2);
+
+ if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_HOST)
+ virBufferAddLit(buf, "host\n");
+ if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_DEVICE)
+ virBufferAddLit(buf, "device\n");
+ if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_DIR)
+ virBufferAddLit(buf, "dir\n");
+ if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_ADAPTER)
+ virBufferAddLit(buf, "adapter\n");
+ if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_NAME)
+ virBufferAddLit(buf, "name\n");
+ if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_INITIATOR_IQN)
+ virBufferAddLit(buf, "initiator\n");
+ if (poolOptions->flags & VIR_STORAGE_POOL_SOURCE_NETWORK)
+ virBufferAddLit(buf, "network\n");
+
+ virBufferAdjustIndent(buf, -2);
+ virBufferAddLit(buf, "\n");
+ }
+
+ virBufferAdjustIndent(buf, -2);
+ virBufferAddLit(buf, "\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, "\n");
+ virBufferAdjustIndent(buf, 2);
+
+ virBufferAsprintf(buf, "\n",
+ (volOptions->formatToString)(volOptions->defaultFormat));
+
+ virBufferAddLit(buf, "\n");
+ virBufferAdjustIndent(buf, 2);
+
+ for (i = 0; i < volOptions->lastFormat; i++)
+ virBufferAsprintf(buf, "%s\n",
+ (volOptions->formatToString)(i));
+
+ virBufferAdjustIndent(buf, -2);
+ virBufferAddLit(buf, "\n");
+
+ virBufferAdjustIndent(buf, -2);
+ virBufferAddLit(buf, "\n");
+
+ return 0;
+}
+
+
void
virStorageVolDefFree(virStorageVolDefPtr def)
{
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index daf6f9b68c01b69af9444601f4ba18a0ac8d9b17..bfbebd15bd5e78f2434646ff5af381241c2c93f2 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -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
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6d78db2b942343d98e75146af06afdda122aeb42..3ae48ad33add2c63e2e42735f7529b53f11f7424 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -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;