From nobody Wed Nov 27 15:52:35 2024 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 154696999040943.59587922411026; Tue, 8 Jan 2019 09:53:10 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C9E9F13A68; Tue, 8 Jan 2019 17:53:07 +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 84C601057069; Tue, 8 Jan 2019 17:53:07 +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 1523F3F604; Tue, 8 Jan 2019 17:53:07 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x08HqZdC025813 for ; Tue, 8 Jan 2019 12:52:35 -0500 Received: by smtp.corp.redhat.com (Postfix) id BFA0B60C67; Tue, 8 Jan 2019 17:52:35 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-116-153.phx2.redhat.com [10.3.116.153]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A9A560E3F for ; Tue, 8 Jan 2019 17:52:35 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 8 Jan 2019 12:52:26 -0500 Message-Id: <20190108175226.32693-7-jferlan@redhat.com> In-Reply-To: <20190108175226.32693-1-jferlan@redhat.com> References: <20190108175226.32693-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 6/6] rbd: Utilize storage pool namespace to manage config options 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.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Tue, 08 Jan 2019 17:53:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Allow for adjustment of RBD configuration options via Storage Pool XML Namespace adjustments. Based off original patch/concept: https://www.redhat.com/archives/libvir-list/2014-May/msg00940.html Signed-off-by: John Ferlan --- docs/formatstorage.html.in | 45 +++++ docs/schemas/storagepool.rng | 23 +++ src/storage/storage_backend_rbd.c | 159 +++++++++++++++++- .../pool-rbd-configopts.xml | 17 ++ .../pool-rbd-configopts.xml | 20 +++ tests/storagepoolxml2xmltest.c | 1 + 6 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 tests/storagepoolxml2xmlin/pool-rbd-configopts.xml create mode 100644 tests/storagepoolxml2xmlout/pool-rbd-configopts.xml diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in index 308b94f5e5..4e0fe0a981 100644 --- a/docs/formatstorage.html.in +++ b/docs/formatstorage.html.in @@ -437,6 +437,51 @@ =20 Since 5.0.0. =20 +
rbd:config_opts
+
Provides an XML namespace mechanism to optionally utilize + specifically named options for the RBD configuration options + via the rados_conf_set API for the rbd type + storage pools. In order to designate that the Storage Pool + will be using the mechanism, the pool element + must be modified to provide the XML namespace attribute + syntax as follows: + +

+ xmlns:rbd=3D'http://libvirt.org/schemas/storagepool/source/rbd/1.0' +

+ +

+ The rbd:config_opts defines the configuration options + by specifying multiple rbd:option subelements with + the attribute name specifying the configuration option + to be added and value specifying the configuration + option value. The name and value for each option is only checked + to be not empty. The name and value provided are not checked since + it's possible options don't exist on all distributions. It is + expected that proper and valid options will be supplied for the + target host. +

+ + The following XML snippet shows the syntax required in order to + utilize +
+<pool type=3D"rbd" xmlns:rbd=3D'http://libvirt.org/schemas/storagepool/=
source/rbd/1.0'>
+  <name>myrbdpool</name>
+...
+  <source>
+    <name>rbdpool</name>
+    <host name=3D'1.2.3.4'/>
+    <host name=3D'my.ceph.monitor'/>
+    <host name=3D'third.ceph.monitor' port=3D'6789'/>
+    <rbd:config_opts>
+      <rbd:option name=3D'client_mount_timeout' value=3D'45'/>
+      <rbd:option name=3D'rados_mon_op_timeout' value=3D'20'/>
+      <rbd:option name=3D'rados_osd_op_timeout' value=3D'10'/>
+    </rbd:config_opts>
+  </source>
+...
+ + Since 5.0.0.
=20

Target elements

diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng index 20c7ae5744..54fa584828 100644 --- a/docs/schemas/storagepool.rng +++ b/docs/schemas/storagepool.rng @@ -647,6 +647,9 @@ + + + @@ -695,4 +698,24 @@ =20 + + + + + + + + + + + + + + + + + diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backen= d_rbd.c index 24dd1349ae..c419b12e2d 100644 --- a/src/storage/storage_backend_rbd.c +++ b/src/storage/storage_backend_rbd.c @@ -36,6 +36,7 @@ #include "rbd/librbd.h" #include "secret_util.h" #include "storage_util.h" +#include =20 #define VIR_FROM_THIS VIR_FROM_STORAGE =20 @@ -50,6 +51,138 @@ struct _virStorageBackendRBDState { typedef struct _virStorageBackendRBDState virStorageBackendRBDState; typedef virStorageBackendRBDState *virStorageBackendRBDStatePtr; =20 +/* NetFS Storage Pool Namespace options to share w/ storage_backend_fs.c a= nd + * the virStorageBackendFileSystemMountCmd method */ +typedef struct _virStoragePoolRBDMountOptionsDef virStoragePoolRBDMountOpt= ionsDef; +typedef virStoragePoolRBDMountOptionsDef *virStoragePoolRBDMountOptionsDef= Ptr; +struct _virStoragePoolRBDMountOptionsDef { + size_t noptions; + char **names; + char **values; +}; + +#define STORAGE_POOL_RBD_NAMESPACE_HREF "http://libvirt.org/schemas/storag= epool/source/rbd/1.0" + +static void +virStoragePoolDefRBDNamespaceFree(void *nsdata) +{ + virStoragePoolRBDMountOptionsDefPtr cmdopts =3D nsdata; + size_t i; + + if (!cmdopts) + return; + + for (i =3D 0; i < cmdopts->noptions; i++) { + VIR_FREE(cmdopts->names[i]); + VIR_FREE(cmdopts->values[i]); + } + + VIR_FREE(cmdopts); +} + + +static int +virStoragePoolDefRBDNamespaceParse(xmlXPathContextPtr ctxt, + void **data) +{ + virStoragePoolRBDMountOptionsDefPtr cmdopts =3D NULL; + xmlNodePtr *nodes =3D NULL; + int nnodes; + size_t i; + int ret =3D -1; + + if (xmlXPathRegisterNs(ctxt, BAD_CAST "rbd", + BAD_CAST STORAGE_POOL_RBD_NAMESPACE_HREF) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to register xml namespace '%s'"), + STORAGE_POOL_RBD_NAMESPACE_HREF); + return -1; + } + + nnodes =3D virXPathNodeSet("./rbd:config_opts/rbd:option", ctxt, &node= s); + if (nnodes < 0) + return -1; + + if (nnodes =3D=3D 0) + return 0; + + if (VIR_ALLOC(cmdopts) < 0) + goto cleanup; + + if (VIR_ALLOC_N(cmdopts->names, nnodes) < 0 || + VIR_ALLOC_N(cmdopts->values, nnodes) < 0) + goto cleanup; + + for (i =3D 0; i < nnodes; i++) { + if (!(cmdopts->names[cmdopts->noptions] =3D + virXMLPropString(nodes[i], "name"))) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("no rbd option name specified")); + goto cleanup; + } + if (*cmdopts->names[cmdopts->noptions] =3D=3D '\0') { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("empty rbd option name specified")); + goto cleanup; + } + if (!(cmdopts->values[cmdopts->noptions] =3D + virXMLPropString(nodes[i], "value"))) { + virReportError(VIR_ERR_XML_ERROR, + _("no rbd option value specified for name '%s'"= ), + cmdopts->names[cmdopts->noptions]); + goto cleanup; + } + if (*cmdopts->values[cmdopts->noptions] =3D=3D '\0') { + virReportError(VIR_ERR_XML_ERROR, + _("empty rbd option value specified for name '%= s'"), + cmdopts->names[cmdopts->noptions]); + goto cleanup; + } + cmdopts->noptions++; + } + + VIR_STEAL_PTR(*data, cmdopts); + ret =3D 0; + + cleanup: + VIR_FREE(nodes); + virStoragePoolDefRBDNamespaceFree(cmdopts); + return ret; +} + + +static int +virStoragePoolDefRBDNamespaceFormatXML(virBufferPtr buf, + void *nsdata) +{ + size_t i; + virStoragePoolRBDMountOptionsDefPtr def =3D nsdata; + + if (!def) + return 0; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + for (i =3D 0; i < def->noptions; i++) { + virBufferEscapeString(buf, "names[= i]); + virBufferEscapeString(buf, "value=3D'%s'/>\n", def->values[i]); + } + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + return 0; +} + + +static const char * +virStoragePoolDefRBDNamespaceHref(void) +{ + return "xmlns:rbd=3D'" STORAGE_POOL_RBD_NAMESPACE_HREF "'"; +} + + static int virStorageBackendRBDRADOSConfSet(rados_t cluster, const char *option, @@ -183,6 +316,17 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBD= StatePtr ptr, rbd_default_format) < 0) goto cleanup; =20 + if (source->namespaceData) { + virStoragePoolRBDMountOptionsDefPtr cmdopts =3D source->namespaceD= ata; + + for (i =3D 0; i < cmdopts->noptions; i++) { + if (virStorageBackendRBDRADOSConfSet(ptr->cluster, + cmdopts->names[i], + cmdopts->values[i]) < 0) + goto cleanup; + } + } + ptr->starttime =3D time(0); if ((r =3D rados_connect(ptr->cluster)) < 0) { virReportSystemError(-r, _("failed to connect to the RADOS monitor= on: %s"), @@ -1277,6 +1421,7 @@ virStorageBackendRBDVolWipe(virStoragePoolObjPtr pool, return ret; } =20 + virStorageBackend virStorageBackendRBD =3D { .type =3D VIR_STORAGE_POOL_RBD, =20 @@ -1291,8 +1436,20 @@ virStorageBackend virStorageBackendRBD =3D { }; =20 =20 +static virStoragePoolXMLNamespace virStoragePoolRBDXMLNamespace =3D { + .parse =3D virStoragePoolDefRBDNamespaceParse, + .free =3D virStoragePoolDefRBDNamespaceFree, + .format =3D virStoragePoolDefRBDNamespaceFormatXML, + .href =3D virStoragePoolDefRBDNamespaceHref, +}; + + int virStorageBackendRBDRegister(void) { - return virStorageBackendRegister(&virStorageBackendRBD); + if (virStorageBackendRegister(&virStorageBackendRBD) < 0) + return -1; + + return virStorageBackendNamespaceInit(VIR_STORAGE_POOL_RBD, + &virStoragePoolRBDXMLNamespace); } diff --git a/tests/storagepoolxml2xmlin/pool-rbd-configopts.xml b/tests/sto= ragepoolxml2xmlin/pool-rbd-configopts.xml new file mode 100644 index 0000000000..a23f559afb --- /dev/null +++ b/tests/storagepoolxml2xmlin/pool-rbd-configopts.xml @@ -0,0 +1,17 @@ + + ceph + 47c1faee-0207-e741-f5ae-d9b019b98fe2 + + rbd + + + + + + + + + + + + diff --git a/tests/storagepoolxml2xmlout/pool-rbd-configopts.xml b/tests/st= oragepoolxml2xmlout/pool-rbd-configopts.xml new file mode 100644 index 0000000000..121a69c0d7 --- /dev/null +++ b/tests/storagepoolxml2xmlout/pool-rbd-configopts.xml @@ -0,0 +1,20 @@ + + ceph + 47c1faee-0207-e741-f5ae-d9b019b98fe2 + 0 + 0 + 0 + + + + rbd + + + + + + + + + + diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index c08313d236..25f134fc23 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -105,6 +105,7 @@ mymain(void) DO_TEST("pool-zfs"); DO_TEST("pool-zfs-sourcedev"); DO_TEST("pool-rbd"); + DO_TEST("pool-rbd-configopts"); DO_TEST("pool-vstorage"); DO_TEST("pool-iscsi-direct-auth"); DO_TEST("pool-iscsi-direct"); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list