[libvirt] [PATCH 1/4] vol: Add new elements to _virStorageVolSource for thin lv

John Ferlan jferlan at redhat.com
Fri Feb 5 01:40:47 UTC 2016


A thin lv doesn't have any extents defined - rather it uses a concept of
a "thin-pool" in order to describe it's source. In order to allow that to
be displayed properly in a future patch, add a new 'thin_pool' name that
can be used by a future patch to store the name of the source thin_pool
name used by a thin logical volume. A thin_pool has a specific size, so
add a thin_capacity field to store that.

For now, these are "output only" fields. That is - if a thin lv is found
in a volume group, we can display the thinpool data.  The output will
appear in a vol-dumpxml (similar to how extents are handled) as:

  <source>
    <thinpool name='thinmints'>
      <capacity unit='bytes'>20971520</capacity>
    </thinpool>
  </source>

The new tests add the "bones" in order to at some point in a future patch
add the ability to parse the input XML with a <thinpool> and generate a
thinpool within the volume group.  Although the storagevolxml2xmltest
added valid input (so that storagevolschematest can validate the format),
the output will not be listed, thus the storagevolxml2xmlout does not
have the source data (similar to vol-logical.xml).

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 docs/schemas/storagevol.rng                     | 14 ++++++++++++++
 src/conf/storage_conf.c                         | 11 +++++++++++
 src/conf/storage_conf.h                         |  3 +++
 tests/storagevolxml2xmlin/vol-logical-thin.xml  | 20 ++++++++++++++++++++
 tests/storagevolxml2xmlout/vol-logical-thin.xml | 17 +++++++++++++++++
 tests/storagevolxml2xmltest.c                   |  1 +
 6 files changed, 66 insertions(+)
 create mode 100644 tests/storagevolxml2xmlin/vol-logical-thin.xml
 create mode 100644 tests/storagevolxml2xmlout/vol-logical-thin.xml

diff --git a/docs/schemas/storagevol.rng b/docs/schemas/storagevol.rng
index 7450547..25e2db7 100644
--- a/docs/schemas/storagevol.rng
+++ b/docs/schemas/storagevol.rng
@@ -144,6 +144,9 @@
       <zeroOrMore>
         <ref name='sourcedev'/>
       </zeroOrMore>
+      <optional>
+        <ref name='sourcethinpool'/>
+        </optional>
     </element>
   </define>
 
@@ -172,6 +175,17 @@
     </oneOrMore>
   </define>
 
+  <define name='sourcethinpool'>
+    <element name='thinpool'>
+      <attribute name='name'>
+        <text/>
+      </attribute>
+      <element name='capacity'>
+        <ref name='scaledInteger'/>
+      </element>
+    </element>
+  </define>
+
   <define name='formatdev'>
     <choice>
       <value>none</value>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 3657dfd..8eef399 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -322,6 +322,7 @@ virStorageVolDefFree(virStorageVolDefPtr def)
     for (i = 0; i < def->source.nextent; i++)
         VIR_FREE(def->source.extents[i].path);
     VIR_FREE(def->source.extents);
+    VIR_FREE(def->source.thin_pool);
 
     virStorageSourceClear(&def->target);
     VIR_FREE(def);
@@ -1655,6 +1656,16 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
             virBufferAddLit(&buf, "</device>\n");
     }
 
+    if (def->source.thin_pool) {
+        virBufferEscapeString(&buf, "<thinpool name='%s'>\n",
+                              def->source.thin_pool);
+        virBufferAdjustIndent(&buf, 2);
+        virBufferAsprintf(&buf, "<capacity unit='bytes'>%llu</capacity>\n",
+                          def->source.thin_capacity);
+        virBufferAdjustIndent(&buf, -2);
+        virBufferAddLit(&buf, "</thinpool>\n");
+    }
+
     virBufferAdjustIndent(&buf, -2);
     virBufferAddLit(&buf, "</source>\n");
 
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index 31b45be..f19cb59 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -55,6 +55,9 @@ struct _virStorageVolSource {
 
     int partType; /* virStorageVolTypeDisk, only used by disk
                    * backend for partition type creation */
+
+    char *thin_pool;   /* For a thin volume, the thin-pool and capacity */
+    unsigned long long thin_capacity; /* bytes */
 };
 
 
diff --git a/tests/storagevolxml2xmlin/vol-logical-thin.xml b/tests/storagevolxml2xmlin/vol-logical-thin.xml
new file mode 100644
index 0000000..7d97627
--- /dev/null
+++ b/tests/storagevolxml2xmlin/vol-logical-thin.xml
@@ -0,0 +1,20 @@
+<volume type='block'>
+  <name>thinmint1</name>
+  <key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
+  <source>
+    <thinpool name='thinmints'>
+      <capacity unit='bytes'>20971520</capacity>
+    </thinpool>
+  </source>
+  <capacity unit='bytes'>2080374784</capacity>
+  <allocation unit='bytes'>2080374784</allocation>
+  <target>
+    <path>/dev/HostVG/thinmints</path>
+    <permissions>
+      <mode>0660</mode>
+      <owner>0</owner>
+      <group>6</group>
+      <label>system_u:object_r:fixed_disk_device_t:s0</label>
+    </permissions>
+  </target>
+</volume>
diff --git a/tests/storagevolxml2xmlout/vol-logical-thin.xml b/tests/storagevolxml2xmlout/vol-logical-thin.xml
new file mode 100644
index 0000000..198d3ea
--- /dev/null
+++ b/tests/storagevolxml2xmlout/vol-logical-thin.xml
@@ -0,0 +1,17 @@
+<volume type='block'>
+  <name>thinmint1</name>
+  <key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
+  <source>
+  </source>
+  <capacity unit='bytes'>2080374784</capacity>
+  <allocation unit='bytes'>2080374784</allocation>
+  <target>
+    <path>/dev/HostVG/thinmints</path>
+    <permissions>
+      <mode>0660</mode>
+      <owner>0</owner>
+      <group>6</group>
+      <label>system_u:object_r:fixed_disk_device_t:s0</label>
+    </permissions>
+  </target>
+</volume>
diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c
index 148d1e6..197d308 100644
--- a/tests/storagevolxml2xmltest.c
+++ b/tests/storagevolxml2xmltest.c
@@ -107,6 +107,7 @@ mymain(void)
     DO_TEST("pool-dir", "vol-qcow2-nobacking");
     DO_TEST("pool-disk", "vol-partition");
     DO_TEST("pool-logical", "vol-logical");
+    DO_TEST("pool-logical", "vol-logical-thin");
     DO_TEST("pool-logical", "vol-logical-backing");
     DO_TEST("pool-sheepdog", "vol-sheepdog");
     DO_TEST("pool-gluster", "vol-gluster-dir");
-- 
2.5.0




More information about the libvir-list mailing list