[virt-tools-list] [PATCH 2/2] details: Add support for disk detect zeroes option

Povilas Kanapickas povilas at radix.lt
Thu Aug 23 23:40:18 UTC 2018


---
 tests/xmlparse-xml/change-disk-out.xml |  2 +-
 tests/xmlparse.py                      |  1 +
 ui/addhardware.ui                      | 24 ++++++++++++++++++++
 ui/details.ui                          | 31 ++++++++++++++++++++++++++
 virtManager/addhardware.py             |  9 ++++++++
 virtManager/details.py                 | 15 ++++++++++++-
 virtManager/domain.py                  |  4 +++-
 virtinst/devices/disk.py               |  6 +++++
 8 files changed, 89 insertions(+), 3 deletions(-)

diff --git a/tests/xmlparse-xml/change-disk-out.xml b/tests/xmlparse-xml/change-disk-out.xml
index 0a7833eb..1fa26591 100644
--- a/tests/xmlparse-xml/change-disk-out.xml
+++ b/tests/xmlparse-xml/change-disk-out.xml
@@ -59,7 +59,7 @@
         <total_iops_sec>5</total_iops_sec>
         <total_bytes_sec>6</total_bytes_sec>
       </iotune>
-      <driver cache="writeback" discard="unmap" io="native"/>
+      <driver cache="writeback" discard="unmap" detect_zeroes="unmap" io="native"/>
       <source file="/dev/default-pool/default-vol" startupPolicy="optional"/>
       <shareable/>
     </disk>
diff --git a/tests/xmlparse.py b/tests/xmlparse.py
index 6fe9c9a7..05b1ce26 100644
--- a/tests/xmlparse.py
+++ b/tests/xmlparse.py
@@ -390,6 +390,7 @@ class XMLParseTest(unittest.TestCase):
         check("driver_io", None, "threads")
         check("driver_io", "threads", "native")
         check("driver_discard", None, "unmap")
+        check("driver_detect_zeroes", None, "unmap")
         check("iotune_ris", 1, 0)
         check("iotune_rbs", 2, 0)
         check("iotune_wis", 3, 0)
diff --git a/ui/addhardware.ui b/ui/addhardware.ui
index 92cbbeaa..33cb590c 100644
--- a/ui/addhardware.ui
+++ b/ui/addhardware.ui
@@ -279,6 +279,30 @@
                                         <property name="top_attach">1</property>
                                       </packing>
                                     </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label-storage-detect-zeroes">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="halign">start</property>
+                                        <property name="label" translatable="yes">Zero detection mode:</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="mnemonic_widget">storage-detect-zeroes</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">2</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkComboBox" id="storage-detect-zeroes">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">2</property>
+                                      </packing>
+                                    </child>
                                   </object>
                                 </child>
                                 <child type="label">
diff --git a/ui/details.ui b/ui/details.ui
index d4b23b8e..341e691d 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -3819,6 +3819,37 @@
                                                             <property name="top_attach">2</property>
                                                           </packing>
                                                         </child>
+                                                        <child>
+                                                          <object class="GtkLabel" id="label-disk-detect-zeroes">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="halign">end</property>
+                                                            <property name="label" translatable="yes">Zero detection mode:</property>
+                                                            <property name="use_underline">True</property>
+                                                            <property name="mnemonic_widget">detectzeroesmode-entry-box</property>
+                                                          </object>
+                                                          <packing>
+                                                            <property name="left_attach">0</property>
+                                                            <property name="top_attach">3</property>
+                                                          </packing>
+                                                        </child>
+                                                        <child>
+                                                          <object class="GtkComboBox" id="disk-detect-zeroes">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="has_entry">True</property>
+                                                            <signal name="changed" handler="on_disk_detect_zeroes_combo_changed" swapped="no"/>
+                                                            <child internal-child="entry">
+                                                            <object class="GtkEntry" id="detectzeroesmode-entry-box">
+                                                            <property name="can_focus">True</property>
+                                                            </object>
+                                                            </child>
+                                                          </object>
+                                                          <packing>
+                                                            <property name="left_attach">1</property>
+                                                            <property name="top_attach">3</property>
+                                                          </packing>
+                                                        </child>
                                                       </object>
                                                     </child>
                                                     <child type="label">
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 0196ea18..cf066ce0 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -194,6 +194,8 @@ class vmmAddHardware(vmmGObjectUI):
         self._build_disk_device_combo()
         self.build_disk_cache_combo(self.vm, self.widget("storage-cache"))
         self.build_disk_discard_combo(self.vm, self.widget("storage-discard"))
+        self.build_disk_detect_zeroes_combo(self.vm,
+            self.widget("storage-detect-zeroes"))
         self.build_network_model_combo(self.vm, self.widget("net-model"))
         self._build_input_combo()
         self.build_sound_combo(self.vm, self.widget("sound-model"))
@@ -458,6 +460,13 @@ class vmmAddHardware(vmmGObjectUI):
             values.append([m, m])
         _build_combo(combo, values, sort=False)
 
+    @staticmethod
+    def build_disk_detect_zeroes_combo(_vm, combo):
+        values = [[None, _("Hypervisor default")]]
+        for m in DeviceDisk.detect_zeroes_types:
+            values.append([m, m])
+        _build_combo(combo, values, sort=False)
+
     @staticmethod
     def build_disk_bus_combo(_vm, combo):
         _build_combo(combo, [])
diff --git a/virtManager/details.py b/virtManager/details.py
index d355ccd3..9aa7dc9d 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -57,6 +57,7 @@ from .graphwidgets import Sparkline
  EDIT_DISK_CACHE,
  EDIT_DISK_IO,
  EDIT_DISK_DISCARD,
+ EDIT_DISK_DETECT_ZEROES,
  EDIT_DISK_BUS,
  EDIT_DISK_SERIAL,
  EDIT_DISK_FORMAT,
@@ -95,7 +96,7 @@ from .graphwidgets import Sparkline
 
  EDIT_FS,
 
- EDIT_HOSTDEV_ROMBAR) = range(1, 52)
+ EDIT_HOSTDEV_ROMBAR) = range(1, 53)
 
 
 # Columns in hw list model
@@ -540,6 +541,7 @@ class vmmDetails(vmmGObjectUI):
             "on_disk_cache_combo_changed": lambda *x: self.enable_apply(x, EDIT_DISK_CACHE),
             "on_disk_io_combo_changed": lambda *x: self.enable_apply(x, EDIT_DISK_IO),
             "on_disk_discard_combo_changed": lambda *x: self.enable_apply(x, EDIT_DISK_DISCARD),
+            "on_disk_detect_zeroes_combo_changed": lambda *x: self.enable_apply(x, EDIT_DISK_DETECT_ZEROES),
             "on_disk_bus_combo_changed": lambda *x: self.enable_apply(x, EDIT_DISK_BUS),
             "on_disk_format_changed": self.disk_format_changed,
             "on_disk_serial_changed": lambda *x: self.enable_apply(x, EDIT_DISK_SERIAL),
@@ -1022,6 +1024,10 @@ class vmmDetails(vmmGObjectUI):
         combo = self.widget("disk-discard")
         vmmAddHardware.build_disk_discard_combo(self.vm, combo)
 
+        # Detect zeroes combo
+        combo = self.widget("disk-detect-zeroes")
+        vmmAddHardware.build_disk_detect_zeroes_combo(self.vm, combo)
+
         # Disk bus combo
         disk_bus = self.widget("disk-bus")
         vmmAddHardware.build_disk_bus_combo(self.vm, disk_bus)
@@ -2123,6 +2129,10 @@ class vmmDetails(vmmGObjectUI):
             kwargs["discard"] = uiutil.get_list_selection(
                 self.widget("disk-discard"))
 
+        if self.edited(EDIT_DISK_DETECT_ZEROES):
+            kwargs["detect_zeroes"] = uiutil.get_list_selection(
+                self.widget("disk-detect-zeroes"))
+
         if self.edited(EDIT_DISK_FORMAT):
             kwargs["driver_type"] = self.widget("disk-format").get_text()
 
@@ -2658,6 +2668,7 @@ class vmmDetails(vmmGObjectUI):
         cache = disk.driver_cache
         io = disk.driver_io
         discard = disk.driver_discard
+        detect_zeroes = disk.driver_detect_zeroes
         driver_type = disk.driver_type or ""
         serial = disk.serial
 
@@ -2701,6 +2712,8 @@ class vmmDetails(vmmGObjectUI):
         uiutil.set_list_selection(self.widget("disk-cache"), cache)
         uiutil.set_list_selection(self.widget("disk-io"), io)
         uiutil.set_list_selection(self.widget("disk-discard"), discard)
+        uiutil.set_list_selection(self.widget("disk-detect-zeroes"),
+                                  detect_zeroes)
 
         self.widget("disk-format").set_text(driver_type)
         self.widget("disk-format-warn").hide()
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 16266b2c..3226af9e 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -687,7 +687,7 @@ class vmmDomain(vmmLibvirtObject):
     def define_disk(self, devobj, do_hotplug,
             path=_SENTINEL, readonly=_SENTINEL, serial=_SENTINEL,
             shareable=_SENTINEL, removable=_SENTINEL, cache=_SENTINEL,
-            io=_SENTINEL, discard=_SENTINEL,
+            io=_SENTINEL, discard=_SENTINEL, detect_zeroes=_SENTINEL,
             driver_type=_SENTINEL, bus=_SENTINEL, addrstr=_SENTINEL,
             sgio=_SENTINEL):
         xmlobj = self._make_xmlobj_to_define()
@@ -739,6 +739,8 @@ class vmmDomain(vmmLibvirtObject):
             editdev.driver_io = io or None
         if discard != _SENTINEL:
             editdev.driver_discard = discard or None
+        if detect_zeroes != _SENTINEL:
+            editdev.driver_detect_zeroes = detect_zeroes or None
         if driver_type != _SENTINEL:
             editdev.driver_type = driver_type or None
         if serial != _SENTINEL:
diff --git a/virtinst/devices/disk.py b/virtinst/devices/disk.py
index 4e5afce4..16adae8b 100644
--- a/virtinst/devices/disk.py
+++ b/virtinst/devices/disk.py
@@ -117,6 +117,12 @@ class DeviceDisk(Device):
     DISCARD_MODE_UNMAP = "unmap"
     discard_types = [DISCARD_MODE_IGNORE, DISCARD_MODE_UNMAP]
 
+    DETECT_ZEROES_OFF = "off"
+    DETECT_ZEROES_ON = "on"
+    DETECT_ZEROES_UNMAP = "unmap"
+    detect_zeroes_types = [DETECT_ZEROES_OFF, DETECT_ZEROES_ON,
+                           DETECT_ZEROES_UNMAP]
+
     DEVICE_DISK = "disk"
     DEVICE_LUN = "lun"
     DEVICE_CDROM = "cdrom"
-- 
2.17.1





More information about the virt-tools-list mailing list