From nobody Sun Feb 8 16:30:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1549985339365205.22117676593996; Tue, 12 Feb 2019 07:28:59 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 064BF7F3E7; Tue, 12 Feb 2019 15:28:57 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BDDB4A33A4; Tue, 12 Feb 2019 15:28:56 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7CCB93F605; Tue, 12 Feb 2019 15:28:56 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x1CFSsXa024151 for ; Tue, 12 Feb 2019 10:28:54 -0500 Received: by smtp.corp.redhat.com (Postfix) id 9D8EC17ADC; Tue, 12 Feb 2019 15:28:54 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-117-20.phx2.redhat.com [10.3.117.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5165517A66 for ; Tue, 12 Feb 2019 15:28:52 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 12 Feb 2019 10:28:10 -0500 Message-Id: <20190212152816.3454-12-jferlan@redhat.com> In-Reply-To: <20190212152816.3454-1-jferlan@redhat.com> References: <20190212152816.3454-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 11/17] conf: Add storage pool capability formatting X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Tue, 12 Feb 2019 15:28:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" 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 --- src/conf/Makefile.inc.am | 2 + src/conf/storage_capabilities.c | 135 ++++++++++++++++++++++++++++++++ src/conf/storage_capabilities.h | 41 ++++++++++ src/conf/storage_conf.c | 109 ++++++++++++++++++++++++++ src/conf/storage_conf.h | 7 ++ src/libvirt_private.syms | 7 ++ 6 files changed, 301 insertions(+) create mode 100644 src/conf/storage_capabilities.c create mode 100644 src/conf/storage_capabilities.h diff --git a/src/conf/Makefile.inc.am b/src/conf/Makefile.inc.am index 219ff350d7..fb2ec0e785 100644 --- a/src/conf/Makefile.inc.am +++ b/src/conf/Makefile.inc.am @@ -96,6 +96,8 @@ NWFILTER_CONF_SOURCES =3D \ STORAGE_CONF_SOURCES =3D \ 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_capabilitie= s.c new file mode 100644 index 0000000000..cf3ee488ac --- /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 =3D obj; + VIR_DEBUG("obj=3D%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 =3D NULL; + + if (virStoragePoolCapsInitialize() < 0) + return NULL; + + if (!(caps =3D virObjectLockableNew(virStoragePoolCapsClass))) + return NULL; + + caps->driverCaps =3D virObjectRef(driverCaps); + + return caps; +} + + +static bool +virStoragePoolCapsIsLoaded(virCapsPtr driverCaps, + int poolType) +{ + size_t i; + + if (!driverCaps) + return false; + + for (i =3D 0; i < driverCaps->npools; i++) { + if (driverCaps->pools[i]->type =3D=3D poolType) + return true; + } + + return false; +} + + +static int +virStoragePoolCapsFormatPool(virBufferPtr buf, + int poolType, + virStoragePoolCapsPtr const caps) +{ + bool isLoaded =3D virStoragePoolCapsIsLoaded(caps->driverCaps, poolTyp= e); + + 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 =3D VIR_BUFFER_INITIALIZER; + size_t i; + + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + for (i =3D 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_capabilitie= s.h new file mode 100644 index 0000000000..daeb496909 --- /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 be64c09d37..37c84d73ae 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -112,6 +112,7 @@ typedef struct _virStorageVolOptions virStorageVolOptio= ns; 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; =20 virStoragePoolXMLNamespace ns; =20 @@ -164,6 +166,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] =3D { .flags =3D (VIR_STORAGE_POOL_SOURCE_NAME | VIR_STORAGE_POOL_SOURCE_DEVICE), .defaultFormat =3D VIR_STORAGE_POOL_LOGICAL_LVM2, + .lastFormat =3D VIR_STORAGE_POOL_LOGICAL_LAST, .formatFromString =3D virStoragePoolFormatLogicalTypeFromString, .formatToString =3D virStoragePoolFormatLogicalTypeToString, }, @@ -171,6 +174,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] =3D { {.poolType =3D VIR_STORAGE_POOL_DIR, .volOptions =3D { .defaultFormat =3D VIR_STORAGE_FILE_RAW, + .lastFormat =3D VIR_STORAGE_FILE_LAST, .formatFromString =3D virStorageVolumeFormatFromString, .formatToString =3D virStorageFileFormatTypeToString, }, @@ -179,11 +183,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] =3D { .poolOptions =3D { .flags =3D (VIR_STORAGE_POOL_SOURCE_DEVICE), .defaultFormat =3D VIR_STORAGE_POOL_FS_AUTO, + .lastFormat =3D VIR_STORAGE_POOL_FS_LAST, .formatFromString =3D virStoragePoolFormatFileSystemTypeFromStrin= g, .formatToString =3D virStoragePoolFormatFileSystemTypeToString, }, .volOptions =3D { .defaultFormat =3D VIR_STORAGE_FILE_RAW, + .lastFormat =3D VIR_STORAGE_FILE_LAST, .formatFromString =3D virStorageVolumeFormatFromString, .formatToString =3D virStorageFileFormatTypeToString, }, @@ -193,11 +199,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] =3D { .flags =3D (VIR_STORAGE_POOL_SOURCE_HOST | VIR_STORAGE_POOL_SOURCE_DIR), .defaultFormat =3D VIR_STORAGE_POOL_NETFS_AUTO, + .lastFormat =3D VIR_STORAGE_POOL_NETFS_LAST, .formatFromString =3D virStoragePoolFormatFileSystemNetTypeFromSt= ring, .formatToString =3D virStoragePoolFormatFileSystemNetTypeToString, }, .volOptions =3D { .defaultFormat =3D VIR_STORAGE_FILE_RAW, + .lastFormat =3D VIR_STORAGE_FILE_LAST, .formatFromString =3D virStorageVolumeFormatFromString, .formatToString =3D virStorageFileFormatTypeToString, }, @@ -245,6 +253,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] =3D { }, .volOptions =3D { .defaultFormat =3D VIR_STORAGE_FILE_RAW, + .lastFormat =3D VIR_STORAGE_FILE_LAST, .formatToString =3D virStorageFileFormatTypeToString, .formatFromString =3D virStorageVolumeFormatFromString, } @@ -255,11 +264,13 @@ static virStoragePoolTypeInfo poolTypeInfo[] =3D { .poolOptions =3D { .flags =3D (VIR_STORAGE_POOL_SOURCE_DEVICE), .defaultFormat =3D VIR_STORAGE_POOL_DISK_UNKNOWN, + .lastFormat =3D VIR_STORAGE_POOL_DISK_LAST, .formatFromString =3D virStoragePoolFormatDiskTypeFromString, .formatToString =3D virStoragePoolFormatDiskTypeToString, }, .volOptions =3D { .defaultFormat =3D VIR_STORAGE_VOL_DISK_NONE, + .lastFormat =3D VIR_STORAGE_VOL_DISK_LAST, .formatFromString =3D virStorageVolFormatDiskTypeFromString, .formatToString =3D virStorageVolFormatDiskTypeToString, }, @@ -276,6 +287,7 @@ static virStoragePoolTypeInfo poolTypeInfo[] =3D { }, .volOptions =3D { .defaultFormat =3D VIR_STORAGE_FILE_RAW, + .lastFormat =3D VIR_STORAGE_FILE_LAST, .formatFromString =3D virStorageVolumeFormatFromString, .formatToString =3D virStorageFileFormatTypeToString, }, @@ -345,6 +357,103 @@ virStorageVolOptionsForPoolType(int type) } =20 =20 +int +virStoragePoolOptionsFormatPool(virBufferPtr buf, + int type) +{ + virStoragePoolOptionsPtr poolOptions; + + if (!(poolOptions =3D 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->defau= ltFormat)); + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + for (i =3D 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 =3D virStorageVolOptionsForPoolType(type))) + return -1; + + if (!volOptions->formatToString) + return 0; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + virBufferAsprintf(buf, "\n", + (volOptions->formatToString)(volOptions->defaultForm= at)); + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + for (i =3D 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 daf6f9b68c..bfbebd15bd 100644 --- a/src/conf/storage_conf.h +++ b/src/conf/storage_conf.h @@ -53,6 +53,13 @@ int virStoragePoolOptionsPoolTypeSetXMLNamespace(int type, virStoragePoolXMLNamespacePtr= ns); =20 +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 62e37f442d..0d8291411d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -909,6 +909,11 @@ virStorageAdapterParseXML; virStorageAdapterValidate; =20 =20 +# conf/storage_capabilities.h +virStoragePoolCapsFormat; +virStoragePoolCapsNew; + + # conf/storage_conf.h virStoragePartedFsTypeToString; virStoragePoolDefFormat; @@ -922,6 +927,8 @@ virStoragePoolFormatDiskTypeToString; virStoragePoolFormatFileSystemNetTypeToString; virStoragePoolFormatFileSystemTypeToString; virStoragePoolFormatLogicalTypeToString; +virStoragePoolOptionsFormatPool; +virStoragePoolOptionsFormatVolume; virStoragePoolOptionsPoolTypeSetXMLNamespace; virStoragePoolSaveConfig; virStoragePoolSaveState; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list