[PATCH 1/5] conf: Add support for discard granularity

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Lin Ma <lma@xxxxxxxx>
---
 docs/formatdomain.html.in     |  6 +++++-
 docs/schemas/domaincommon.rng |  5 +++++
 src/conf/domain_conf.c        | 19 ++++++++++++++++++-
 src/conf/domain_conf.h        |  1 +
 src/qemu/qemu_domain.c        |  2 ++
 5 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index 20c28a47e3..59ee50225a 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3019,7 +3019,7 @@
     &lt;driver name='qemu' type='raw'/&gt;
     &lt;source dev='/dev/sda'/&gt;
     &lt;geometry cyls='16383' heads='16' secs='63' trans='lba'/&gt;
-    &lt;blockio logical_block_size='512' physical_block_size='4096'/&gt;
+    &lt;blockio logical_block_size='512' physical_block_size='4096' discard_granularity='4096'/&gt;
     &lt;target dev='hdj' bus='ide'/&gt;
   &lt;/disk&gt;
   &lt;disk type='volume' device='disk'&gt;
@@ -4067,6 +4067,10 @@
             BLKPBSZGET ioctl and describes the disk's hardware sector
             size which can be relevant for the alignment of disk data.
           </dd>
+          <dt><code>discard_granularity</code></dt>
+          <dd>Its value impacts the Optimal Unmap Granularity field in
+            the block limits VPD page. <span class="since">Since 6.5.0</span>
+          </dd>
         </dl>
       </dd>
     </dl>
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index e3bf7f5d55..5206c4e246 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -2177,6 +2177,11 @@
           <data type="integer"/>
         </attribute>
       </optional>
+      <optional>
+        <attribute name="discard_granularity">
+          <data type="integer"/>
+        </attribute>
+      </optional>
     </element>
   </define>
   <!--
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index e9336fd72d..7a6a124ffd 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10425,6 +10425,7 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
     g_autofree char *vendor = NULL;
     g_autofree char *product = NULL;
     g_autofree char *domain_name = NULL;
+    g_autofree char *discard_granularity = NULL;
 
     if (!(def = virDomainDiskDefNew(xmlopt)))
         return NULL;
@@ -10522,6 +10523,16 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt,
                                physical_block_size);
                 goto error;
             }
+            discard_granularity =
+                virXMLPropString(cur, "discard_granularity");
+            if (discard_granularity &&
+                virStrToLong_ui(discard_granularity, NULL, 0,
+                                &def->blockio.discard_granularity) < 0) {
+                virReportError(VIR_ERR_INTERNAL_ERROR,
+                               _("invalid granularity size '%s'"),
+                               discard_granularity);
+                goto error;
+            }
         } else if (!virDomainDiskGetDriver(def) &&
                    virXMLNodeNameEqual(cur, "driver")) {
             if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0)
@@ -24958,7 +24969,8 @@ virDomainDiskBlockIoDefFormat(virBufferPtr buf,
                               virDomainDiskDefPtr def)
 {
     if (def->blockio.logical_block_size > 0 ||
-        def->blockio.physical_block_size > 0) {
+        def->blockio.physical_block_size > 0 ||
+        def->blockio.discard_granularity > 0) {
         virBufferAddLit(buf, "<blockio");
         if (def->blockio.logical_block_size > 0) {
             virBufferAsprintf(buf,
@@ -24970,6 +24982,11 @@ virDomainDiskBlockIoDefFormat(virBufferPtr buf,
                               " physical_block_size='%u'",
                               def->blockio.physical_block_size);
         }
+        if (def->blockio.discard_granularity > 0) {
+            virBufferAsprintf(buf,
+                              " discard_granularity='%u'",
+                              def->blockio.discard_granularity);
+        }
         virBufferAddLit(buf, "/>\n");
     }
 }
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index bda8fb6bce..9056e5e9b6 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -549,6 +549,7 @@ struct _virDomainDiskDef {
     struct {
         unsigned int logical_block_size;
         unsigned int physical_block_size;
+        unsigned int discard_granularity;
     } blockio;
 
     virDomainBlockIoTuneInfo blkdeviotune;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2dad823a86..c582550def 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -8743,6 +8743,8 @@ qemuDomainDiskChangeSupported(virDomainDiskDefPtr disk,
              "blockio logical_block_size", false);
     CHECK_EQ(blockio.physical_block_size,
              "blockio physical_block_size", false);
+    CHECK_EQ(blockio.discard_granularity,
+             "blockio discard_granularity", false);
 
     CHECK_EQ(blkdeviotune.total_bytes_sec,
              "blkdeviotune total_bytes_sec",
-- 
2.26.0





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux