[PATCH v2 0/5] qemu: Support rbd namespace attribute

Change from v1: - Add rbd namespace member to aarch64 capability replies. Add rbd namespace capability test for aarch64. - Provide more details in news xml v1: https://www.redhat.com/archives/libvir-list/2020-April/msg00388.html git repo: https://github.com/qiankehan/libvirt/tree/rbd-namespace-v2 Han Han (5): qemu_capabilities: Add QEMU_CAPS_RBD_NAMESPACE conf: Support to parse rbd namespace attribute qemu: Implement rbd namespace attribute doc: rng schemas and html doc for rbd namespace attribute news: qemu: Support rbd namespace docs/formatdomain.html.in | 5 +++ docs/news.xml | 10 +++++ docs/schemas/domaincommon.rng | 3 ++ src/conf/domain_conf.c | 4 ++ src/qemu/qemu_block.c | 1 + src/qemu/qemu_capabilities.c | 2 + src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 14 ++++++- src/util/virstoragefile.h | 1 + .../caps_5.0.0.aarch64.replies | 5 +++ .../caps_5.0.0.aarch64.xml | 1 + .../qemucapabilitiesdata/caps_5.0.0.ppc64.xml | 1 + .../caps_5.0.0.x86_64.xml | 1 + ...k-network-rbd-namespace.x86_64-latest.args | 41 +++++++++++++++++++ .../disk-network-rbd-namespace.xml | 33 +++++++++++++++ tests/qemuxml2argvtest.c | 1 + ...sk-network-rbd-namespace.x86_64-latest.xml | 41 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 18 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/disk-network-rbd-namespace.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-network-rbd-namespace.xml create mode 100644 tests/qemuxml2xmloutdata/disk-network-rbd-namespace.x86_64-latest.xml -- 2.25.0

Add rbd namespace in aarch64 capability replies. The capability flag will be used for rbd namespace option. The rbd namespace is introduced since ceph Nautilus and qemu v5.0.0. Signed-off-by: Han Han <hhan@redhat.com> --- src/qemu/qemu_capabilities.c | 2 ++ src/qemu/qemu_capabilities.h | 1 + tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies | 5 +++++ tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml | 1 + tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml | 1 + tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml | 1 + 6 files changed, 11 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 994f1fd1..f4344464 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -571,6 +571,7 @@ VIR_ENUM_IMPL(virQEMUCaps, /* 360 */ "fsdev.multidevs", + "rbd.namespace", ); @@ -1450,6 +1451,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsQMPSchemaQueries[] = { { "blockdev-add/arg-type/+nvme", QEMU_CAPS_DRIVE_NVME }, { "query-named-block-nodes/arg-type/flat", QEMU_CAPS_QMP_QUERY_NAMED_BLOCK_NODES_FLAT }, { "blockdev-snapshot/$allow-write-only-overlay", QEMU_CAPS_BLOCKDEV_SNAPSHOT_ALLOW_WRITE_ONLY }, + { "blockdev-add/arg-type/+rbd/namespace", QEMU_CAPS_RBD_NAMESPACE }, }; typedef struct _virQEMUCapsObjectTypeProps virQEMUCapsObjectTypeProps; diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index d247e197..1aed6af3 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -552,6 +552,7 @@ typedef enum { /* virQEMUCapsFlags grouping marker for syntax-check */ /* 360 */ QEMU_CAPS_FSDEV_MULTIDEVS, /* fsdev.multidevs */ + QEMU_CAPS_RBD_NAMESPACE, /* -blockdev '{"driver":"rbd",...,"namespace":str}' */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies index a3136a09..cacdee67 100644 --- a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies +++ b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.replies @@ -16940,6 +16940,11 @@ "name": "pool", "type": "str" }, + { + "name": "namespace", + "default": null, + "type": "str" + }, { "name": "image", "type": "str" diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml index 30664c62..79ef10b3 100644 --- a/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml +++ b/tests/qemucapabilitiesdata/caps_5.0.0.aarch64.xml @@ -183,6 +183,7 @@ <flag name='vhost-user-fs'/> <flag name='storage.werror'/> <flag name='fsdev.multidevs'/> + <flag name='rbd.namespace'/> <version>4002050</version> <kvmVersion>0</kvmVersion> <microcodeVersion>61700241</microcodeVersion> diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml b/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml index a6800482..e420c8ff 100644 --- a/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml +++ b/tests/qemucapabilitiesdata/caps_5.0.0.ppc64.xml @@ -191,6 +191,7 @@ <flag name='blockdev-snapshot.allow-write-only-overlay'/> <flag name='storage.werror'/> <flag name='fsdev.multidevs'/> + <flag name='rbd.namespace'/> <version>4002050</version> <kvmVersion>0</kvmVersion> <microcodeVersion>42900241</microcodeVersion> diff --git a/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml b/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml index df3557d1..5db56b75 100644 --- a/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_5.0.0.x86_64.xml @@ -228,6 +228,7 @@ <flag name='blockdev-snapshot.allow-write-only-overlay'/> <flag name='storage.werror'/> <flag name='fsdev.multidevs'/> + <flag name='rbd.namespace'/> <version>4002091</version> <kvmVersion>0</kvmVersion> <microcodeVersion>43100241</microcodeVersion> -- 2.25.0

Signed-off-by: Han Han <hhan@redhat.com> --- src/conf/domain_conf.c | 4 ++++ src/util/virstoragefile.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6ad7552b..a4ee2e1e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9488,6 +9488,7 @@ virDomainDiskSourceNetworkParse(xmlNodePtr node, /* config file currently only works with remote disks */ src->configFile = virXPathString("string(./config/@file)", ctxt); + src->namespace = virXPathString("string(./@namespace)", ctxt); if (src->protocol == VIR_STORAGE_NET_PROTOCOL_HTTP || src->protocol == VIR_STORAGE_NET_PROTOCOL_HTTPS) @@ -24614,6 +24615,9 @@ virDomainDiskSourceFormatNetwork(virBufferPtr attrBuf, path = g_strdup_printf("%s/%s", src->volume, src->path); virBufferEscapeString(attrBuf, " name='%s'", path ? path : src->path); + if (src->namespace) + virBufferEscapeString(attrBuf, " namespace='%s'", src->namespace); + virBufferEscapeString(attrBuf, " query='%s'", src->query); if (src->haveTLS != VIR_TRISTATE_BOOL_ABSENT && diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h index 7939c09c..8b683b7e 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 *namespace; /* for the storage systems supporting namespace */ char *query; /* query string for HTTP based protocols */ size_t nhosts; virStorageNetHostDefPtr hosts; -- 2.25.0

Ceph Nautilus supports separate image namespaces within a pool for tenant isolation and QEMU added it as a rbd blockdev options from 5.0.0. This optional attribute is used to access a image with namespace. Add unit tests for this attribute. https://bugzilla.redhat.com/show_bug.cgi?id=1816909 Signed-off-by: Han Han <hhan@redhat.com> --- src/qemu/qemu_block.c | 1 + src/qemu/qemu_command.c | 14 ++++++- ...k-network-rbd-namespace.x86_64-latest.args | 41 +++++++++++++++++++ .../disk-network-rbd-namespace.xml | 33 +++++++++++++++ tests/qemuxml2argvtest.c | 1 + ...sk-network-rbd-namespace.x86_64-latest.xml | 41 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 7 files changed, 131 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/disk-network-rbd-namespace.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-network-rbd-namespace.xml create mode 100644 tests/qemuxml2xmloutdata/disk-network-rbd-namespace.x86_64-latest.xml diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index d32277d7..8cc007ac 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -872,6 +872,7 @@ qemuBlockStorageSourceGetRBDProps(virStorageSourcePtr src, "s:pool", src->volume, "s:image", src->path, "S:snapshot", src->snapshot, + "S:namespace", src->namespace, "S:conf", src->configFile, "A:server", &servers, "S:user", username, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 988d38e4..32b6bb4d 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1047,7 +1047,12 @@ qemuBuildNetworkDriveStr(virStorageSourcePtr src, return NULL; } - virBufferStrcat(&buf, "rbd:", src->volume, "/", src->path, NULL); + virBufferStrcat(&buf, "rbd:", src->volume, "/", NULL); + /* The filename of image with namespace: rbd:POOL/NAMESPACE/IMAGE... */ + if (src->namespace) + virBufferStrcat(&buf, src->namespace, "/", NULL); + + virBufferStrcat(&buf, src->path, NULL); if (src->snapshot) virBufferEscape(&buf, '\\', ":", "@%s", src->snapshot); @@ -1425,6 +1430,13 @@ qemuCheckDiskConfig(virDomainDiskDefPtr disk, _("detect_zeroes is not supported by this QEMU binary")); return -1; } + + if (disk->src->namespace && + !virQEMUCapsGet(qemuCaps, QEMU_CAPS_RBD_NAMESPACE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("rbd namespace is not supported by this QEMU binary")); + return -1; + } } if (disk->serial && diff --git a/tests/qemuxml2argvdata/disk-network-rbd-namespace.x86_64-latest.args b/tests/qemuxml2argvdata/disk-network-rbd-namespace.x86_64-latest.args new file mode 100644 index 00000000..138b7538 --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-rbd-namespace.x86_64-latest.args @@ -0,0 +1,41 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-QEMUGuest1 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-x86_64 \ +-name guest=QEMUGuest1,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \ +-machine pc,accel=tcg,usb=off,dump-guest-core=off \ +-cpu qemu64 \ +-m 214 \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ +-blockdev '{"driver":"rbd","pool":"pool","image":"image","namespace":"ns",\ +"server":[{"host":"mon1.example.org","port":"6321"},{"host":"mon2.example.org",\ +"port":"6322"},{"host":"mon3.example.org","port":"6322"}],\ +"node-name":"libvirt-1-storage","auto-read-only":true,"discard":"unmap"}' \ +-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"raw",\ +"file":"libvirt-1-storage"}' \ +-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x2,drive=libvirt-1-format,\ +id=virtio-disk0,bootindex=1 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/disk-network-rbd-namespace.xml b/tests/qemuxml2argvdata/disk-network-rbd-namespace.xml new file mode 100644 index 00000000..8b526c4a --- /dev/null +++ b/tests/qemuxml2argvdata/disk-network-rbd-namespace.xml @@ -0,0 +1,33 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <disk type='network' device='disk'> + <driver name='qemu' type='raw'/> + <source protocol='rbd' name='pool/image' namespace='ns'> + <host name='mon1.example.org' port='6321'/> + <host name='mon2.example.org' port='6322'/> + <host name='mon3.example.org' port='6322'/> + </source> + <target dev='vda' bus='virtio'/> + </disk> + <controller type='usb' index='0'/> + <controller type='ide' index='0'/> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index fdeb3c2e..aaa32da6 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1081,6 +1081,7 @@ mymain(void) DO_TEST_CAPS_VER("disk-network-rbd", "2.5.0"); DO_TEST_CAPS_VER("disk-network-rbd", "2.12.0"); DO_TEST_CAPS_LATEST("disk-network-rbd"); + DO_TEST_CAPS_LATEST("disk-network-rbd-namespace"); DO_TEST_FAILURE("disk-network-rbd-no-colon", NONE); DO_TEST("disk-network-sheepdog", NONE); DO_TEST_CAPS_VER("disk-network-sheepdog", "2.12.0"); diff --git a/tests/qemuxml2xmloutdata/disk-network-rbd-namespace.x86_64-latest.xml b/tests/qemuxml2xmloutdata/disk-network-rbd-namespace.x86_64-latest.xml new file mode 100644 index 00000000..2166696c --- /dev/null +++ b/tests/qemuxml2xmloutdata/disk-network-rbd-namespace.x86_64-latest.xml @@ -0,0 +1,41 @@ +<domain type='qemu'> + <name>QEMUGuest1</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='custom' match='exact' check='none'> + <model fallback='forbid'>qemu64</model> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <disk type='network' device='disk'> + <driver name='qemu' type='raw'/> + <source protocol='rbd' name='pool/image' namespace='ns'> + <host name='mon1.example.org' port='6321'/> + <host name='mon2.example.org' port='6322'/> + <host name='mon3.example.org' port='6322'/> + </source> + <target dev='vda' bus='virtio'/> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </disk> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='ide' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='none'/> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index b4c83fcc..6e8a8196 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -333,6 +333,7 @@ mymain(void) DO_TEST("disk-network-iscsi", QEMU_CAPS_VIRTIO_SCSI); DO_TEST("disk-network-gluster", NONE); DO_TEST("disk-network-rbd", NONE); + DO_TEST_CAPS_LATEST("disk-network-rbd-namespace"); DO_TEST("disk-network-source-auth", NONE); DO_TEST("disk-network-sheepdog", NONE); DO_TEST("disk-network-vxhs", NONE); -- 2.25.0

Signed-off-by: Han Han <hhan@redhat.com> --- docs/formatdomain.html.in | 5 +++++ docs/schemas/domaincommon.rng | 3 +++ 2 files changed, 8 insertions(+) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index d56600dc..06e1a7ee 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -3118,6 +3118,11 @@ (<span class="since">Since 6.2.0</span>) </p> + <p>For protocol <code>rbd</code>, an optional attribute + <code>namespace</code> specifies the namespace of a rbd pool. + (<span class="since">Since 6.3.0 and QEMU 5.0.0</span>) + </p> + <p>For "iscsi" (<span class="since">since 1.0.4</span>), the <code>name</code> attribute may include a logical unit number, separated from the target's name by a slash (e.g., diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index dcf2e09d..294ade34 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -1762,6 +1762,9 @@ <optional> <attribute name="name"/> </optional> + <optional> + <attribute name="namespace"/> + </optional> <zeroOrMore> <ref name="diskSourceNetworkHost"/> </zeroOrMore> -- 2.25.0

Signed-off-by: Han Han <hhan@redhat.com> --- docs/news.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/news.xml b/docs/news.xml index 0d3f3386..14ebc15f 100644 --- a/docs/news.xml +++ b/docs/news.xml @@ -44,6 +44,16 @@ <libvirt> <release version="v6.3.0" date="unreleased"> <section title="New features"> + <change> + <summary> + qemu: Support rbd namespace attribute + </summary> + <description> + The namespaces is for the tenant isolation within a rbd pool, + introduced from Ceph Nautilus, supported since QEMU 5.0.0. In libvirt + use it by namespace attribute in the source element of rbd. + </description> + </change> </section> <section title="Improvements"> </section> -- 2.25.0

ping On Tue, Apr 21, 2020 at 8:11 PM Han Han <hhan@redhat.com> wrote:
Change from v1: - Add rbd namespace member to aarch64 capability replies. Add rbd namespace capability test for aarch64. - Provide more details in news xml
v1: https://www.redhat.com/archives/libvir-list/2020-April/msg00388.html git repo: https://github.com/qiankehan/libvirt/tree/rbd-namespace-v2
Han Han (5): qemu_capabilities: Add QEMU_CAPS_RBD_NAMESPACE conf: Support to parse rbd namespace attribute qemu: Implement rbd namespace attribute doc: rng schemas and html doc for rbd namespace attribute news: qemu: Support rbd namespace
docs/formatdomain.html.in | 5 +++ docs/news.xml | 10 +++++ docs/schemas/domaincommon.rng | 3 ++ src/conf/domain_conf.c | 4 ++ src/qemu/qemu_block.c | 1 + src/qemu/qemu_capabilities.c | 2 + src/qemu/qemu_capabilities.h | 1 + src/qemu/qemu_command.c | 14 ++++++- src/util/virstoragefile.h | 1 + .../caps_5.0.0.aarch64.replies | 5 +++ .../caps_5.0.0.aarch64.xml | 1 + .../qemucapabilitiesdata/caps_5.0.0.ppc64.xml | 1 + .../caps_5.0.0.x86_64.xml | 1 + ...k-network-rbd-namespace.x86_64-latest.args | 41 +++++++++++++++++++ .../disk-network-rbd-namespace.xml | 33 +++++++++++++++ tests/qemuxml2argvtest.c | 1 + ...sk-network-rbd-namespace.x86_64-latest.xml | 41 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 18 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/disk-network-rbd-namespace.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/disk-network-rbd-namespace.xml create mode 100644 tests/qemuxml2xmloutdata/disk-network-rbd-namespace.x86_64-latest.xml
-- 2.25.0
-- Best regards, ----------------------------------- Han Han Quality Engineer Redhat. Email: hhan@redhat.com Phone: +861065339333
participants (1)
-
Han Han