[libvirt] [PATCH 0/2] conf: do not steal pointers from the pool source

https://bugzilla.redhat.com/show_bug.cgi?id=1436400 Ján Tomko (2): schema: do not require name for certain pool types conf: do not steal pointers from the pool source docs/schemas/storagepool.rng | 27 +++++++++++++++++----- src/conf/storage_conf.c | 5 ++-- tests/storagepoolxml2xmlin/pool-logical-noname.xml | 18 +++++++++++++++ .../storagepoolxml2xmlout/pool-logical-noname.xml | 19 +++++++++++++++ tests/storagepoolxml2xmltest.c | 1 + 5 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 tests/storagepoolxml2xmlin/pool-logical-noname.xml create mode 100644 tests/storagepoolxml2xmlout/pool-logical-noname.xml -- 2.10.2

Pool types that have the VIR_STORAGE_POOL_SOURCE_NAME flag set allow omitting the <name> element and instead fill out the pool name from the <source><name> element. Relax the schema to make <name> optional for these pool. Expressing that at least one of these is required is out of scope of the schema.~ --- docs/schemas/storagepool.rng | 27 +++++++++++++++++----- tests/storagepoolxml2xmlin/pool-logical-noname.xml | 18 +++++++++++++++ 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 tests/storagepoolxml2xmlin/pool-logical-noname.xml diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng index 6219ce5..8386f29 100644 --- a/docs/schemas/storagepool.rng +++ b/docs/schemas/storagepool.rng @@ -70,7 +70,7 @@ <value>logical</value> </attribute> <interleave> - <ref name='commonmetadata'/> + <ref name='commonMetadataNameOptional'/> <ref name='sizing'/> <ref name='sourcelogical'/> <ref name='targetlogical'/> @@ -132,7 +132,7 @@ <value>rbd</value> </attribute> <interleave> - <ref name='commonmetadata'/> + <ref name='commonMetadataNameOptional'/> <ref name='sizing'/> <ref name='sourcerbd'/> </interleave> @@ -143,7 +143,7 @@ <value>sheepdog</value> </attribute> <interleave> - <ref name='commonmetadata'/> + <ref name='commonMetadataNameOptional'/> <ref name='sizing'/> <ref name='sourcesheepdog'/> </interleave> @@ -154,7 +154,7 @@ <value>gluster</value> </attribute> <interleave> - <ref name='commonmetadata'/> + <ref name='commonMetadataNameOptional'/> <ref name='sizing'/> <ref name='sourcegluster'/> </interleave> @@ -165,7 +165,7 @@ <value>zfs</value> </attribute> <interleave> - <ref name='commonmetadata'/> + <ref name='commonMetadataNameOptional'/> <ref name='sizing'/> <ref name='sourcezfs'/> <optional> @@ -179,7 +179,7 @@ <value>vstorage</value> </attribute> <interleave> - <ref name='commonmetadata'/> + <ref name='commonMetadataNameOptional'/> <ref name='sizing'/> <ref name='sourcevstorage'/> <ref name='target'/> @@ -205,6 +205,21 @@ </interleave> </define> + <define name='commonMetadataNameOptional'> + <interleave> + <optional> + <element name='name'> + <ref name='genericName'/> + </element> + </optional> + <optional> + <element name='uuid'> + <ref name='UUID'/> + </element> + </optional> + </interleave> + </define> + <define name='commonmetadata'> <interleave> <element name='name'> diff --git a/tests/storagepoolxml2xmlin/pool-logical-noname.xml b/tests/storagepoolxml2xmlin/pool-logical-noname.xml new file mode 100644 index 0000000..ad3f88d --- /dev/null +++ b/tests/storagepoolxml2xmlin/pool-logical-noname.xml @@ -0,0 +1,18 @@ +<pool type='logical'> + <uuid>1c13165a-d0f4-3aee-b447-30fb38789091</uuid> + <capacity>99891544064</capacity> + <allocation>99220455424</allocation> + <available>671088640</available> + <source> + <name>zily</name> + <format type='lvm2'/> + </source> + <target> + <path>/dev/zily</path> + <permissions> + <mode>0700</mode> + <owner>0</owner> + <group>0</group> + </permissions> + </target> +</pool> -- 2.10.2

On Tue, Mar 28, 2017 at 03:22:07PM +0200, Ján Tomko wrote:
Pool types that have the VIR_STORAGE_POOL_SOURCE_NAME flag set allow omitting the <name> element and instead fill out the pool name from the <source><name> element.
Relax the schema to make <name> optional for these pool.
s/pool/pools/
Expressing that at least one of these is required is out of scope of the schema.~
s/~$// ACK and safe for freeze, obviously.

Since commit fcbbb28 we steal the pointer to the storage pool source name if there was no pool name specified. Properly duplicate the string to avoid freeing it twice. https://bugzilla.redhat.com/show_bug.cgi?id=1436400 --- src/conf/storage_conf.c | 5 +++-- tests/storagepoolxml2xmlout/pool-logical-noname.xml | 19 +++++++++++++++++++ tests/storagepoolxml2xmltest.c | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/storagepoolxml2xmlout/pool-logical-noname.xml diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 585ca71..fe0f0bc 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -710,8 +710,9 @@ virStoragePoolDefParseXML(xmlXPathContextPtr ctxt) ret->name = virXPathString("string(./name)", ctxt); if (ret->name == NULL && - options->flags & VIR_STORAGE_POOL_SOURCE_NAME) - ret->name = ret->source.name; + options->flags & VIR_STORAGE_POOL_SOURCE_NAME && + VIR_STRDUP(ret->name, ret->source.name) < 0) + goto error; if (ret->name == NULL) { virReportError(VIR_ERR_XML_ERROR, "%s", _("missing pool source name element")); diff --git a/tests/storagepoolxml2xmlout/pool-logical-noname.xml b/tests/storagepoolxml2xmlout/pool-logical-noname.xml new file mode 100644 index 0000000..a5e0ead --- /dev/null +++ b/tests/storagepoolxml2xmlout/pool-logical-noname.xml @@ -0,0 +1,19 @@ +<pool type='logical'> + <name>zily</name> + <uuid>1c13165a-d0f4-3aee-b447-30fb38789091</uuid> + <capacity unit='bytes'>0</capacity> + <allocation unit='bytes'>0</allocation> + <available unit='bytes'>0</available> + <source> + <name>zily</name> + <format type='lvm2'/> + </source> + <target> + <path>/dev/zily</path> + <permissions> + <mode>0700</mode> + <owner>0</owner> + <group>0</group> + </permissions> + </target> +</pool> diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c index 79bdc26..355871c 100644 --- a/tests/storagepoolxml2xmltest.c +++ b/tests/storagepoolxml2xmltest.c @@ -79,6 +79,7 @@ mymain(void) DO_TEST("pool-logical"); DO_TEST("pool-logical-nopath"); DO_TEST("pool-logical-create"); + DO_TEST("pool-logical-noname"); DO_TEST("pool-disk"); DO_TEST("pool-disk-device-nopartsep"); DO_TEST("pool-iscsi"); -- 2.10.2

On Tue, Mar 28, 2017 at 03:22:08PM +0200, Ján Tomko wrote:
Since commit fcbbb28 we steal the pointer to the storage pool source name if there was no pool name specified.
Properly duplicate the string to avoid freeing it twice.
https://bugzilla.redhat.com/show_bug.cgi?id=1436400 --- src/conf/storage_conf.c | 5 +++-- tests/storagepoolxml2xmlout/pool-logical-noname.xml | 19 +++++++++++++++++++ tests/storagepoolxml2xmltest.c | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/storagepoolxml2xmlout/pool-logical-noname.xml
The ACK from the previous one was meant for both patches, but I didn't mention it for some reason. So ACK to this one as well.
participants (2)
-
Ján Tomko
-
Martin Kletzander