https://bugzilla.redhat.com/show_bug.cgi?id=1265694
Add the capability to recognize and parse named/documented flags for
the storage pool. Chose to make rng flags just text rather than having
flags be some list of "expected" values (such as in nwfilter.rng) mostly
to make future expansion easier. The flags are expect to be a comma
separated list which can be parsed by existing virStringSplit API.
The flag will be used by the disk pool that's using device mapper
mulitpath device to expose partitions. The flag will follow the logic
of the /etc/multipath.conf feature 'user_friendly_names'.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
docs/formatstorage.html.in | 33 ++++++++++++++++++++
docs/schemas/storagepool.rng | 9 ++++++
src/conf/storage_conf.c | 41 +++++++++++++++++++++++++
src/storage/parthelper.c | 2 +-
tests/storagepoolxml2xmlin/pool-disk-flags.xml | 15 +++++++++
tests/storagepoolxml2xmlout/pool-disk-flags.xml | 15 +++++++++
tests/storagepoolxml2xmltest.c | 1 +
7 files changed, 115 insertions(+), 1 deletion(-)
create mode 100644 tests/storagepoolxml2xmlin/pool-disk-flags.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-disk-flags.xml
diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index a60e05e..9912a2b 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -90,6 +90,15 @@
<pre>
...
<source>
+ <device path='/dev/mapper/mpatha'/>
+ <format type='gpt'/>
+ <flags>user_friendly_names</flags>
+ </source>
+ ...</pre>
+
+ <pre>
+ ...
+ <source>
<adapter type='scsi_host' name='scsi_host1'/>
</source>
...</pre>
@@ -353,6 +362,30 @@
<dd>Provides an optional product name of the storage device.
This contains a single attribute <code>name</code> whose value
is backend specific. <span class="since">Since
0.8.4</span></dd>
+
+ <dt><code>flags</code></dt>
+ <dd>Provides an optional way to pass a flag via the storage pool
+ configuration for the storage backing drivers to utilize some
+ feature or request usage of a specific algorithm by the backend
+ driver in order find storage targets. The following is a list
+ of support flags for specific backends.
+ <span class="since">Since 1.3.1</span>
+ <dl>
+ <dt><code>user_friendly_names</code></dt>
+ <dd>Used by the storage pool <code>type</code> 'disk'
which
+ is using a multipath <code>device path</code> in order to
+ manage the partitions for the pool. The feature mimics the
+ same named feature for device mapper multipath (dm-multipath)
+ within its /etc/multipath.conf. The result is names libvirt
+ generates for partitions will not have the "p" separator
+ unless the <code>device path</code> ends with a number.
+ Thus "/dev/mapper/mpatha" will create "mpatha1",
"mpatha2",
+ etc. instead of "mpathap1", "mpathap2", etc. names for
the
+ partitions.
+ <span class="since">Since 1.3.1</span>
+ </dd>
+ </dl>
+ </dd>
</dl>
<h3><a name="StoragePoolTarget">Target
elements</a></h3>
diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
index 3a61f04..edfc924 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -532,6 +532,9 @@
<optional>
<ref name='sourceinfovendor'/>
</optional>
+ <optional>
+ <ref name='sourceflags'/>
+ </optional>
</interleave>
</element>
</define>
@@ -610,4 +613,10 @@
</data>
</define>
+ <define name='sourceflags'>
+ <element name="flags">
+ <text/>
+ </element>
+ </define>
+
</grammar>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 9b8abea..049bc9e 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -459,6 +459,8 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
char *port = NULL;
char *adapter_type = NULL;
char *managed = NULL;
+ char *flagstr = NULL;
+ char **flags = NULL;
int n;
relnode = ctxt->node;
@@ -663,6 +665,26 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
source->vendor = virXPathString("string(./vendor/@name)", ctxt);
source->product = virXPathString("string(./product/@name)", ctxt);
+ /* Find and parse a comma separated list of flags by name and
+ * associate with the virStoragePoolSourceFlags
+ */
+ flagstr = virXPathString("string(./flags)", ctxt);
+ if (flagstr) {
+ if (!(flags = virStringSplit(flagstr, ",", 0)))
+ goto cleanup;
+
+ for (i = 0; flags[i] != NULL; i++) {
+ if (STREQ(flags[i], "user_friendly_names")) {
+ source->flags |= VIR_STORAGE_POOL_SOURCE_USER_FRIENDLY_NAMES;
+ } else {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("unrecognized storage pool flag
'%s'"),
+ flags[i]);
+ goto cleanup;
+ }
+ }
+ }
+
ret = 0;
cleanup:
ctxt->node = relnode;
@@ -671,6 +693,8 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
VIR_FREE(nodeset);
VIR_FREE(adapter_type);
VIR_FREE(managed);
+ VIR_FREE(flagstr);
+ virStringFreeList(flags);
virStorageAuthDefFree(authdef);
return ret;
}
@@ -1128,6 +1152,23 @@ virStoragePoolSourceFormat(virBufferPtr buf,
virBufferEscapeString(buf, "<vendor name='%s'/>\n",
src->vendor);
virBufferEscapeString(buf, "<product name='%s'/>\n",
src->product);
+ if (src->flags) {
+ unsigned int flags = src->flags;
+ int c = 0;
+
+ virBufferAddLit(buf, "<flags>");
+ while (flags) {
+ if (c > 0)
+ virBufferAddLit(buf, ",");
+ if (flags & VIR_STORAGE_POOL_SOURCE_USER_FRIENDLY_NAMES) {
+ virBufferAddLit(buf, "user_friendly_names");
+ flags ^= VIR_STORAGE_POOL_SOURCE_USER_FRIENDLY_NAMES;
+ c++;
+ }
+ }
+ virBufferAddLit(buf, "</flags>\n");
+ }
+
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</source>\n");
return 0;
diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c
index 7a658ae..046c3ca 100644
--- a/src/storage/parthelper.c
+++ b/src/storage/parthelper.c
@@ -94,7 +94,7 @@ int main(int argc, char **argv)
* onto the name unless the 'path' ends in a number
*/
if (c_isdigit(path[strlen(path)-1]) || !user_friendly_names)
- partsep ="p";
+ partsep = "p";
else
partsep = "";
if (VIR_STRDUP_QUIET(canonical_path, path) < 0)
diff --git a/tests/storagepoolxml2xmlin/pool-disk-flags.xml
b/tests/storagepoolxml2xmlin/pool-disk-flags.xml
new file mode 100644
index 0000000..9e867f4
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-disk-flags.xml
@@ -0,0 +1,15 @@
+<pool type='disk'>
+ <name>multipath</name>
+ <uuid>70a7eb15-6c34-ee9c-bf57-69e8e5ff3fb2</uuid>
+ <capacity unit='bytes'>0</capacity>
+ <allocation unit='bytes'>0</allocation>
+ <available unit='bytes'>0</available>
+ <source>
+ <device path='/dev/mapper/mpatha'/>
+ <format type='gpt'/>
+ <flags>user_friendly_names</flags>
+ </source>
+ <target>
+ <path>/dev</path>
+ </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-disk-flags.xml
b/tests/storagepoolxml2xmlout/pool-disk-flags.xml
new file mode 100644
index 0000000..9e867f4
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-disk-flags.xml
@@ -0,0 +1,15 @@
+<pool type='disk'>
+ <name>multipath</name>
+ <uuid>70a7eb15-6c34-ee9c-bf57-69e8e5ff3fb2</uuid>
+ <capacity unit='bytes'>0</capacity>
+ <allocation unit='bytes'>0</allocation>
+ <available unit='bytes'>0</available>
+ <source>
+ <device path='/dev/mapper/mpatha'/>
+ <format type='gpt'/>
+ <flags>user_friendly_names</flags>
+ </source>
+ <target>
+ <path>/dev</path>
+ </target>
+</pool>
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index b03c4b0..1f8655e 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -80,6 +80,7 @@ mymain(void)
DO_TEST("pool-logical-nopath");
DO_TEST("pool-logical-create");
DO_TEST("pool-disk");
+ DO_TEST("pool-disk-flags");
DO_TEST("pool-iscsi");
DO_TEST("pool-iscsi-auth");
DO_TEST("pool-netfs");
--
2.5.0