[PATCH v5 2/4] conf: Support to parse rbd namespace from source name
Peter Krempa
pkrempa at redhat.com
Tue Sep 8 13:31:58 UTC 2020
On Wed, Sep 02, 2020 at 16:05:19 +0800, Han Han wrote:
> Signed-off-by: Han Han <hhan at redhat.com>
> ---
> docs/formatdomain.rst | 12 +++++++++---
> src/conf/domain_conf.c | 35 +++++++++++++++++++++++++++++++----
> src/util/virstoragefile.c | 1 +
> src/util/virstoragefile.h | 1 +
> 4 files changed, 42 insertions(+), 7 deletions(-)
>
> diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
> index 1979dfb8d3..4d730a4446 100644
> --- a/docs/formatdomain.rst
> +++ b/docs/formatdomain.rst
> @@ -2256,7 +2256,7 @@ paravirtualized driver is specified via the ``disk`` element.
> </disk>
> <disk type='network'>
> <driver name="qemu" type="raw"/>
> - <source protocol="rbd" name="image_name2">
> + <source protocol="rbd" name="pool/namespace/image">
Please add another example rather than modifying this one.
> <host name="hostname" port="7000"/>
> <snapshot name="snapname"/>
> <config file="/path/to/file"/>
> @@ -2485,8 +2485,8 @@ paravirtualized driver is specified via the ``disk`` element.
> requested image. Possible values are "nbd", "iscsi", "rbd", "sheepdog",
> "gluster", "vxhs", "http", "https", "ftp", ftps", or "tftp".
>
> - For any ``protocol`` other than ``nbd`` an additional attribute ``name``
> - is mandatory to specify which volume/image will be used.
> + For any ``protocol`` other than ``nbd`` or ``rbd`` an additional attribute
> + ``name`` is mandatory to specify which volume/image will be used.
You made the sentence misleading. 'name' is still mandatory for 'rbd'.
>
> For "nbd", the ``name`` attribute is optional. TLS transport for NBD can
> be enabled by setting the ``tls`` attribute to ``yes``. For the QEMU
> @@ -2494,6 +2494,12 @@ paravirtualized driver is specified via the ``disk`` element.
> the host by the ``nbd_tls`` and ``nbd_tls_x509_cert_dir`` in
> /etc/libvirt/qemu.conf. ('tls' :since:`Since 4.5.0` )
>
> + For "rbd", the ``name`` attribute could be two formats: the format of
> + ``pool_name/image_name`` includes the rbd pool name and image name with
> + default rbd pool namespace; for the customized namespace, the format is
> + ``pool_name/namespace/image_name``. The pool name, namespace and image are
> + separated by slash.
Missing since tag.
> +
> For protocols ``http`` and ``https`` an optional attribute ``query``
> specifies the query string. ( :since:`Since 6.2.0` )
>
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 72ac4f4191..5ece5f515d 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -9624,8 +9624,7 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
> /* for historical reasons we store the volume and image name in one XML
> * element although it complicates thing when attempting to access them. */
> if (src->path &&
> - (src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER ||
> - src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD)) {
> + src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER) {
> char *tmp;
> if (!(tmp = strchr(src->path, '/')) ||
> tmp == src->path) {
> @@ -9642,6 +9641,30 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
> tmp[0] = '\0';
> }
>
> + /* the name of rbd could be <pool>/<image> or <pool>/<namespace>/<image> */
> + if (src->path &&
> + src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD) {
The following algorithm became very ugly and unobvious. Please
reimplement this using virStringSplit.
> + char *first_slash = strchr(src->path, '/');
> + char *last_slash = strrchr(src->path, '/');
> + if (!first_slash ||
> + first_slash == src->path ||
> + !last_slash ||
> + last_slash[1] == '\0') {
> + virReportError(VIR_ERR_XML_ERROR,
> + _("can't split path '%s' into pool name, pool "
> + "namespace and image name"), src->path);
> + return -1;
> + }
> +
> + src->volume = src->path;
> + src->path = g_strdup(last_slash + 1);
> + src->ns = NULL;
> + first_slash[0] = '\0';
> + last_slash[0] = '\0';
> + if (first_slash != last_slash)
> + src->ns = g_strdup(first_slash + 1);
> + }
> +
> /* snapshot currently works only for remote disks */
> src->snapshot = virXPathString("string(./snapshot/@name)", ctxt);
>
> @@ -25211,8 +25234,12 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attrBuf,
> virBufferAsprintf(attrBuf, " protocol='%s'",
> virStorageNetProtocolTypeToString(src->protocol));
>
> - if (src->volume)
> - path = g_strdup_printf("%s/%s", src->volume, src->path);
> + if (src->volume) {
> + if (src->ns)
> + path = g_strdup_printf("%s/%s/%s", src->volume, src->ns, src->path);
> + else
> + path = g_strdup_printf("%s/%s", src->volume, src->path);
> + }
[...]
> diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
> index f73b3ee005..f027989462 100644
> --- a/src/util/virstoragefile.h
> +++ b/src/util/virstoragefile.h
> @@ -284,6 +284,7 @@ struct _virStorageSource {
> char *snapshot; /* for storage systems supporting internal snapshots */
> char *configFile; /* some storage systems use config file as part of
> the source definition */
> + char *ns; /* for the storage systems supporting namespace */
struct virStorageSource has a deep copy function which must be updated
with any addition to it.
> char *query; /* query string for HTTP based protocols */
> size_t nhosts;
> virStorageNetHostDefPtr hosts;
> --
> 2.28.0
>
More information about the libvir-list
mailing list