Signed-off-by: Han Han <hhan(a)redhat.com>
---
docs/formatdomain.rst | 16 ++++++++++++++
src/conf/domain_conf.c | 47 ++++++++++++++++++++++++++++++++++++++----
2 files changed, 59 insertions(+), 4 deletions(-)
diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst
index df5ac28028..181afc8574 100644
--- a/docs/formatdomain.rst
+++ b/docs/formatdomain.rst
@@ -2409,6 +2409,16 @@ paravirtualized driver is specified via the ``disk`` element.
</source>
<target dev='vde' bus='virtio'/>
</disk>
+ <disk type='network'>
+ <driver name="qemu" type="raw"/>
+ <source protocol="rbd" name="pool/namespace/image">
+ <host name="hostname" port="7000"/>
+ <auth username='myuser'>
+ <secret type='ceph' usage='mypassid'/>
+ </auth>
+ </source>
+ <target dev="vdf" bus="virtio"/>
+ </disk>
</devices>
...
@@ -2500,6 +2510,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`` ( :since:`Since 6.9.0 and QEMU 5.0` ).
+ The pool name, namespace and image are separated by slash.
+
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 51efeb0e42..7877ef3ff5 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -9550,6 +9550,7 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node,
g_autofree char *tlsCfg = NULL;
g_autofree char *sslverifystr = NULL;
xmlNodePtr tmpnode;
+ char **tmp_split_paths;
if (!(protocol = virXMLPropString(node, "protocol"))) {
virReportError(VIR_ERR_XML_ERROR, "%s",
@@ -9591,8 +9592,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) {
@@ -9609,6 +9609,41 @@ 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 &&
+ (tmp_split_paths = virStringSplit(src->path, "/", 3))) {
+ if (virStringIsEmpty(tmp_split_paths[0]) ||
+ !tmp_split_paths[1] ||
+ STREQ_NULLABLE(tmp_split_paths[2], "") ||
+ (virStringIsEmpty(tmp_split_paths[1]) &&
+ !tmp_split_paths[2])) {
+ virStringListFreeCount(tmp_split_paths, 3);
+ virReportError(VIR_ERR_XML_ERROR,
+ _("can't split path '%s' into pool name, pool
"
+ "namespace, image name OR pool name, image
name"),
+ src->path);
+ return -1;
+ }
+
+ VIR_FREE(src->path);
+ src->volume = g_strdup(tmp_split_paths[0]);
+ /* the format of <pool>/<image> */
+ if (!tmp_split_paths[2])
+ src->path = g_strdup(tmp_split_paths[1]);
+
+ if (tmp_split_paths[2]) {
+ /* the format of <pool>/<ns>/<image> */
+ if (STRNEQ_NULLABLE(tmp_split_paths[1], ""))
+ src->ns = g_strdup(tmp_split_paths[1]);
+
+ /* the format of <pool>//<image> */
+ src->path = g_strdup(tmp_split_paths[2]);
+ }
+
+ virStringListFreeCount(tmp_split_paths, 3);
+ }
+
/* snapshot currently works only for remote disks */
src->snapshot = virXPathString("string(./snapshot/@name)", ctxt);
@@ -25282,8 +25317,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);
+ }
virBufferEscapeString(attrBuf, " name='%s'", path ? path :
src->path);
virBufferEscapeString(attrBuf, " query='%s'", src->query);
--
2.26.2