[virt-tools-list] [ [PATCH 2/3] details: Add disk pr.managed and pr.path options to support SCSI PR

Lin Ma lma at suse.com
Tue Sep 25 09:12:49 UTC 2018


It's a common requirement for VMs to send SCSI PR commands in VM cluster
environment. This patch adds the configuration support in details page.

To make the usage simpler, the pr.type and pr.mode are invisible for user.
Currently, the pr.type and the pr.mode are hardcoded in case of user select
unmanaged PR, user only needs to provide the value of pr.path in this case.

Signed-off-by: Lin Ma <lma at suse.com>
---
 ui/details.ui              | 57 ++++++++++++++++++++++++++++++++++++++
 virtManager/addhardware.py |  7 +++++
 virtManager/details.py     | 47 ++++++++++++++++++++++++++++++-
 virtManager/domain.py      | 15 +++++++++-
 virtinst/devices/disk.py   |  4 +++
 5 files changed, 128 insertions(+), 2 deletions(-)

diff --git a/ui/details.ui b/ui/details.ui
index 48464546..acc4b1c5 100644
--- a/ui/details.ui
+++ b/ui/details.ui
@@ -3676,6 +3676,63 @@
                                                         <property name="top_attach">2</property>
                                                       </packing>
                                                     </child>
+                                                    <child>
+                                                      <object class="GtkLabel" id="disk-pr-label">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="halign">end</property>
+                                                        <property name="label" translatable="yes">_Managed SCSI PR:</property>
+                                                        <property name="use_underline">True</property>
+                                                        <property name="mnemonic_widget">disk-pr-entry</property>
+                                                      </object>
+                                                      <packing>
+                                                        <property name="left_attach">0</property>
+                                                        <property name="top_attach">4</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <object class="GtkComboBox" id="disk-pr">
+                                                        <property name="visible">True</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="has_entry">True</property>
+                                                        <child internal-child="entry">
+                                                          <object class="GtkEntry" id="disk-pr-entry">
+                                                            <property name="can_focus">True</property>
+                                                            <signal name="changed" handler="on_disk_pr_combo_changed" swapped="no"/>
+                                                          </object>
+                                                        </child>
+                                                      </object>
+                                                      <packing>
+                                                        <property name="left_attach">1</property>
+                                                        <property name="top_attach">4</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <object class="GtkLabel" id="disk-pr-path-label">
+                                                        <property name="visible">False</property>
+                                                        <property name="can_focus">False</property>
+                                                        <property name="halign">end</property>
+                                                        <property name="label" translatable="yes">PR source path:</property>
+                                                        <property name="use_underline">True</property>
+                                                        <property name="mnemonic_widget">disk-pr-path-entry</property>
+                                                      </object>
+                                                      <packing>
+                                                        <property name="left_attach">0</property>
+                                                        <property name="top_attach">5</property>
+                                                      </packing>
+                                                    </child>
+                                                    <child>
+                                                      <object class="GtkEntry" id="disk-pr-path-entry">
+                                                        <property name="visible">False</property>
+                                                        <property name="can_focus">True</property>
+                                                        <property name="hexpand">False</property>
+                                                        <signal name="changed" handler="on_disk_pr_path_entry_changed" swapped="no"/>
+                                                      </object>
+                                                        <packing>
+                                                          <property name="left_attach">1</property>
+                                                          <property name="top_attach">5</property>
+                                                        </packing>
+                                                    </child>
                                                   </object>
                                                   <packing>
                                                     <property name="expand">False</property>
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index cb45b194..e1fe699c 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -463,6 +463,13 @@ class vmmAddHardware(vmmGObjectUI):
             values.append([m, m])
         _build_combo(combo, values, sort=False)
 
+    @staticmethod
+    def build_disk_pr_managed_combo(_vm, combo):
+        values = [[None, _("Hypervisor default")]]
+        for m in DeviceDisk.PR_MANAGED_MODES:
+            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 f8976fdb..2edfe46d 100644
--- a/virtManager/details.py
+++ b/virtManager/details.py
@@ -61,6 +61,8 @@ from .graphwidgets import Sparkline
  EDIT_DISK_SERIAL,
  EDIT_DISK_FORMAT,
  EDIT_DISK_SGIO,
+ EDIT_DISK_PR_MANAGED,
+ EDIT_DISK_PR_PATH,
 
  EDIT_SOUND_MODEL,
 
@@ -95,7 +97,7 @@ from .graphwidgets import Sparkline
 
  EDIT_FS,
 
- EDIT_HOSTDEV_ROMBAR) = range(1, 53)
+ EDIT_HOSTDEV_ROMBAR) = range(1, 55)
 
 
 # Columns in hw list model
@@ -545,6 +547,8 @@ class vmmDetails(vmmGObjectUI):
             "on_disk_format_changed": self.disk_format_changed,
             "on_disk_serial_changed": lambda *x: self.enable_apply(x, EDIT_DISK_SERIAL),
             "on_disk_sgio_entry_changed": lambda *x: self.enable_apply(x, EDIT_DISK_SGIO),
+            "on_disk_pr_combo_changed": self.disk_pr_combo_changed,
+            "on_disk_pr_path_entry_changed": lambda *x: self.enable_apply(x, EDIT_DISK_PR_PATH),
 
             "on_network_model_combo_changed": lambda *x: self.enable_apply(x, EDIT_NET_MODEL),
             "on_network_mac_entry_changed": lambda *x: self.enable_apply(x,
@@ -1020,6 +1024,10 @@ class vmmDetails(vmmGObjectUI):
         combo = self.widget("disk-detect-zeroes")
         vmmAddHardware.build_disk_detect_zeroes_combo(self.vm, combo)
 
+        # Managed SCSI PR combo
+        combo = self.widget("disk-pr")
+        vmmAddHardware.build_disk_pr_managed_combo(self.vm, combo)
+
         # Disk bus combo
         disk_bus = self.widget("disk-bus")
         vmmAddHardware.build_disk_bus_combo(self.vm, disk_bus)
@@ -1867,6 +1875,18 @@ class vmmDetails(vmmGObjectUI):
         self._set_network_ip_details(net)
 
 
+    # SCSI persistent reservation
+    def disk_pr_combo_changed(self, src_ignore):
+        self.enable_apply(EDIT_DISK_PR_MANAGED)
+        disk_pr = self.widget("disk-pr")
+        not_managed = (uiutil.get_list_selection(disk_pr) == "no")
+        uiutil.set_grid_row_visible(self.widget("disk-pr-path-label"),
+                                    not_managed)
+        uiutil.set_grid_row_visible(self.widget("disk-pr-path-entry"),
+                                    not_managed)
+        if not_managed and self.widget("disk-pr-path-entry").get_text() == "":
+            self.disable_apply()
+
     ##################################################
     # Details/Hardware config changes (apply button) #
     ##################################################
@@ -2130,6 +2150,18 @@ class vmmDetails(vmmGObjectUI):
             sgio = uiutil.get_list_selection(self.widget("disk-sgio"))
             kwargs["sgio"] = sgio
 
+        if self.edited(EDIT_DISK_PR_MANAGED):
+            pr_managed = uiutil.get_list_selection(self.widget("disk-pr"))
+            kwargs["pr_managed"] = pr_managed
+            if pr_managed == "no":
+                pr_path = self.widget("disk-pr-path-entry").get_text()
+                kwargs["pr_path"] = pr_path
+
+        if self.edited(EDIT_DISK_PR_PATH):
+            pr_path = self.widget("disk-pr-path-entry").get_text().strip()
+            kwargs["pr_managed"] = "no"
+            kwargs["pr_path"] = pr_path
+
         if self.edited(EDIT_DISK_BUS):
             bus = uiutil.get_list_selection(self.widget("disk-bus"))
             addr = None
@@ -2686,9 +2718,22 @@ class vmmDetails(vmmGObjectUI):
 
         is_lun = disk.device == virtinst.DeviceDisk.DEVICE_LUN
         uiutil.set_grid_row_visible(self.widget("disk-sgio"), is_lun)
+        uiutil.set_grid_row_visible(self.widget("disk-pr"), is_lun)
+        disk_pr_path_label = self.widget("disk-pr-path-label")
+        disk_pr_path_entry = self.widget("disk-pr-path-entry")
+        uiutil.set_grid_row_visible(disk_pr_path_label, False)
+        uiutil.set_grid_row_visible(disk_pr_path_entry, False)
         if is_lun:
             self.build_disk_sgio(self.vm, self.widget("disk-sgio"))
             uiutil.set_list_selection(self.widget("disk-sgio"), disk.sgio)
+            disk_pr = self.widget("disk-pr")
+            vmmAddHardware.build_disk_pr_managed_combo(self.vm, disk_pr)
+            uiutil.set_list_selection(disk_pr, disk.pr_managed)
+            not_managed = (disk.pr_managed == "no")
+            uiutil.set_grid_row_visible(disk_pr_path_label, not_managed)
+            uiutil.set_grid_row_visible(disk_pr_path_entry, not_managed)
+            if uiutil.get_list_selection(disk_pr) == "no":
+                disk_pr_path_entry.set_text(disk.pr_path)
 
         self.widget("disk-size").set_text(size)
         uiutil.set_list_selection(self.widget("disk-cache"), cache)
diff --git a/virtManager/domain.py b/virtManager/domain.py
index 0f7410ff..19c4a924 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -673,7 +673,7 @@ class vmmDomain(vmmLibvirtObject):
             shareable=_SENTINEL, removable=_SENTINEL, cache=_SENTINEL,
             io=_SENTINEL, discard=_SENTINEL, detect_zeroes=_SENTINEL,
             driver_type=_SENTINEL, bus=_SENTINEL, addrstr=_SENTINEL,
-            sgio=_SENTINEL):
+            sgio=_SENTINEL, pr_managed=_SENTINEL, pr_path=_SENTINEL):
         xmlobj = self._make_xmlobj_to_define()
         editdev = self._lookup_device_to_define(xmlobj, devobj, do_hotplug)
         if not editdev:
@@ -733,6 +733,19 @@ class vmmDomain(vmmLibvirtObject):
         if sgio != _SENTINEL:
             editdev.sgio = sgio or None
 
+        if pr_managed != _SENTINEL:
+            editdev.pr_managed = pr_managed or None
+            if pr_managed != "no":
+                editdev.pr_type = None
+                editdev.pr_path = None
+                editdev.pr_mode = None
+
+        if pr_path != _SENTINEL:
+            editdev.pr_path = pr_path or None
+            # Hardcode the vales of the type and the mode
+            editdev.pr_type = "unix"
+            editdev.pr_mode = "client"
+
         if bus != _SENTINEL:
             _change_bus()
 
diff --git a/virtinst/devices/disk.py b/virtinst/devices/disk.py
index 8b125e16..345bad54 100644
--- a/virtinst/devices/disk.py
+++ b/virtinst/devices/disk.py
@@ -123,6 +123,10 @@ class DeviceDisk(Device):
     DETECT_ZEROES_MODES = [DETECT_ZEROES_MODE_OFF, DETECT_ZEROES_MODE_ON,
                            DETECT_ZEROES_MODE_UNMAP]
 
+    PR_MANAGED_YES = "yes"
+    PR_MANAGED_NO = "no"
+    PR_MANAGED_MODES = [PR_MANAGED_YES, PR_MANAGED_NO]
+
     DEVICE_DISK = "disk"
     DEVICE_LUN = "lun"
     DEVICE_CDROM = "cdrom"
-- 
2.19.0




More information about the virt-tools-list mailing list