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

Povilas Kanapickas povilas at radix.lt
Thu Aug 23 23:38:07 UTC 2018


---
 ui/addhardware.ui          | 24 ++++++++++++++++++++++++
 ui/details.ui              | 31 +++++++++++++++++++++++++++++++
 virtManager/addhardware.py |  8 ++++++++
 virtManager/details.py     | 14 +++++++++++++-
 virtManager/domain.py      |  5 ++++-
 5 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/ui/addhardware.ui b/ui/addhardware.ui
index 4c266826..92cbbeaa 100644
--- a/ui/addhardware.ui
+++ b/ui/addhardware.ui
@@ -255,6 +255,30 @@
                                         <property name="top_attach">0</property>
                                       </packing>
                                     </child>
+                                    <child>
+                                      <object class="GtkLabel" id="label-storage-discard">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="halign">start</property>
+                                        <property name="label" translatable="yes">Discard mode:</property>
+                                        <property name="use_underline">True</property>
+                                        <property name="mnemonic_widget">storage-discard</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">0</property>
+                                        <property name="top_attach">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
+                                      <object class="GtkComboBox" id="storage-discard">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                      </object>
+                                      <packing>
+                                        <property name="left_attach">1</property>
+                                        <property name="top_attach">1</property>
+                                      </packing>
+                                    </child>
                                   </object>
                                 </child>
                                 <child type="label">
diff --git a/ui/details.ui b/ui/details.ui
index 5a35a156..d4b23b8e 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -3788,6 +3788,37 @@
                                                             <property name="top_attach">1</property>
                                                           </packing>
                                                         </child>
+                                                        <child>
+                                                          <object class="GtkLabel" id="label-disk-discard">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="halign">end</property>
+                                                            <property name="label" translatable="yes">Discard mode:</property>
+                                                            <property name="use_underline">True</property>
+                                                            <property name="mnemonic_widget">discardmode-entry-box</property>
+                                                          </object>
+                                                          <packing>
+                                                            <property name="left_attach">0</property>
+                                                            <property name="top_attach">2</property>
+                                                          </packing>
+                                                        </child>
+                                                        <child>
+                                                          <object class="GtkComboBox" id="disk-discard">
+                                                            <property name="visible">True</property>
+                                                            <property name="can_focus">False</property>
+                                                            <property name="has_entry">True</property>
+                                                            <signal name="changed" handler="on_disk_discard_combo_changed" swapped="no"/>
+                                                            <child internal-child="entry">
+                                                            <object class="GtkEntry" id="discardmode-entry-box">
+                                                            <property name="can_focus">True</property>
+                                                            </object>
+                                                            </child>
+                                                          </object>
+                                                          <packing>
+                                                            <property name="left_attach">1</property>
+                                                            <property name="top_attach">2</property>
+                                                          </packing>
+                                                        </child>
                                                       </object>
                                                     </child>
                                                     <child type="label">
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index e6619d66..0196ea18 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -193,6 +193,7 @@ class vmmAddHardware(vmmGObjectUI):
         self.build_disk_bus_combo(self.vm, self.widget("storage-bustype"))
         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_network_model_combo(self.vm, self.widget("net-model"))
         self._build_input_combo()
         self.build_sound_combo(self.vm, self.widget("sound-model"))
@@ -450,6 +451,13 @@ class vmmAddHardware(vmmGObjectUI):
             values.append([m, m])
         _build_combo(combo, values, sort=False)
 
+    @staticmethod
+    def build_disk_discard_combo(_vm, combo):
+        values = [[None, _("Hypervisor default")]]
+        for m in DeviceDisk.discard_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 e670d21f..d355ccd3 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -56,6 +56,7 @@ from .graphwidgets import Sparkline
  EDIT_DISK_REMOVABLE,
  EDIT_DISK_CACHE,
  EDIT_DISK_IO,
+ EDIT_DISK_DISCARD,
  EDIT_DISK_BUS,
  EDIT_DISK_SERIAL,
  EDIT_DISK_FORMAT,
@@ -94,7 +95,7 @@ from .graphwidgets import Sparkline
 
  EDIT_FS,
 
- EDIT_HOSTDEV_ROMBAR) = range(1, 51)
+ EDIT_HOSTDEV_ROMBAR) = range(1, 52)
 
 
 # Columns in hw list model
@@ -538,6 +539,7 @@ class vmmDetails(vmmGObjectUI):
             "on_disk_removable_changed": lambda *x: self.enable_apply(x, EDIT_DISK_REMOVABLE),
             "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_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),
@@ -1016,6 +1018,10 @@ class vmmDetails(vmmGObjectUI):
             model.append([m, m])
         combo.set_active(0)
 
+        # Discard combo
+        combo = self.widget("disk-discard")
+        vmmAddHardware.build_disk_discard_combo(self.vm, combo)
+
         # Disk bus combo
         disk_bus = self.widget("disk-bus")
         vmmAddHardware.build_disk_bus_combo(self.vm, disk_bus)
@@ -2113,6 +2119,10 @@ class vmmDetails(vmmGObjectUI):
         if self.edited(EDIT_DISK_IO):
             kwargs["io"] = uiutil.get_list_selection(self.widget("disk-io"))
 
+        if self.edited(EDIT_DISK_DISCARD):
+            kwargs["discard"] = uiutil.get_list_selection(
+                self.widget("disk-discard"))
+
         if self.edited(EDIT_DISK_FORMAT):
             kwargs["driver_type"] = self.widget("disk-format").get_text()
 
@@ -2647,6 +2657,7 @@ class vmmDetails(vmmGObjectUI):
         removable = disk.removable
         cache = disk.driver_cache
         io = disk.driver_io
+        discard = disk.driver_discard
         driver_type = disk.driver_type or ""
         serial = disk.serial
 
@@ -2689,6 +2700,7 @@ class vmmDetails(vmmGObjectUI):
         self.widget("disk-size").set_text(size)
         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)
 
         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 5af6ee01..16266b2c 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -687,7 +687,8 @@ class vmmDomain(vmmLibvirtObject):
     def define_disk(self, devobj, do_hotplug,
             path=_SENTINEL, readonly=_SENTINEL, serial=_SENTINEL,
             shareable=_SENTINEL, removable=_SENTINEL, cache=_SENTINEL,
-            io=_SENTINEL, driver_type=_SENTINEL, bus=_SENTINEL, addrstr=_SENTINEL,
+            io=_SENTINEL, discard=_SENTINEL,
+            driver_type=_SENTINEL, bus=_SENTINEL, addrstr=_SENTINEL,
             sgio=_SENTINEL):
         xmlobj = self._make_xmlobj_to_define()
         editdev = self._lookup_device_to_define(xmlobj, devobj, do_hotplug)
@@ -736,6 +737,8 @@ class vmmDomain(vmmLibvirtObject):
             editdev.driver_cache = cache or None
         if io != _SENTINEL:
             editdev.driver_io = io or None
+        if discard != _SENTINEL:
+            editdev.driver_discard = discard or None
         if driver_type != _SENTINEL:
             editdev.driver_type = driver_type or None
         if serial != _SENTINEL:
-- 
2.17.1




More information about the virt-tools-list mailing list