[virt-tools-list] [virt-manager 8/8] filesystem: Add a checkbox for setting shared memory access for virtiofs

Lin Ma lma at suse.com
Wed Jun 30 12:11:06 UTC 2021


Signed-off-by: Lin Ma <lma at suse.com>
---
 ui/fsdetails.ui                 | 14 ++++++++++++++
 virtManager/addhardware.py      |  6 ++----
 virtManager/details/details.py  |  5 +----
 virtManager/device/fsdetails.py | 13 +++++++++++++
 4 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/ui/fsdetails.ui b/ui/fsdetails.ui
index e5311492..e662b181 100644
--- a/ui/fsdetails.ui
+++ b/ui/fsdetails.ui
@@ -40,6 +40,20 @@
         <property name="top-attach">7</property>
       </packing>
     </child>
+    <child>
+      <object class="GtkCheckButton" id="mem-sharedaccess">
+        <property name="label" translatable="yes">S_hared memory access</property>
+        <property name="visible">True</property>
+        <property name="can-focus">True</property>
+        <property name="receives-default">False</property>
+        <property name="use-underline">True</property>
+        <property name="draw-indicator">True</property>
+      </object>
+      <packing>
+        <property name="left-attach">1</property>
+        <property name="top-attach">8</property>
+      </packing>
+    </child>
     <child>
       <object class="GtkBox" id="fs-source-box">
         <property name="visible">True</property>
diff --git a/virtManager/addhardware.py b/virtManager/addhardware.py
index 463410ab..25709506 100644
--- a/virtManager/addhardware.py
+++ b/virtManager/addhardware.py
@@ -9,7 +9,7 @@ import traceback
 from gi.repository import Gtk
 
 from virtinst import (DeviceChannel, DeviceConsole,
-        DeviceController, DeviceDisk, DeviceHostdev, DeviceFilesystem,
+        DeviceController, DeviceDisk, DeviceHostdev,
         DeviceInput, DeviceInterface, DevicePanic, DeviceParallel,
         DeviceRedirdev, DeviceRng, DeviceSerial, DeviceSmartcard,
         DeviceSound, DeviceTpm, DeviceVideo, DeviceVsock, DeviceWatchdog)
@@ -1554,9 +1554,7 @@ class vmmAddHardware(vmmGObjectUI):
         return dev
 
     def _build_filesystem(self):
-        fsdriver = uiutil.get_list_selection(
-            self._fsdetails.widget("fs-driver-combo"))
-        if fsdriver == DeviceFilesystem.DRIVER_VIRTIOFS:
+        if self._fsdetails.force_mem_shared_access():
             guest = self.vm.xmlobj
             if guest.cpu.has_private_memAccess_cells():
                 kwargs = {}
diff --git a/virtManager/details/details.py b/virtManager/details/details.py
index 6c194d2f..289c9909 100644
--- a/virtManager/details/details.py
+++ b/virtManager/details/details.py
@@ -12,7 +12,6 @@ import libvirt
 
 import virtinst
 from virtinst import log
-from virtinst import DeviceFilesystem
 
 from ..lib import uiutil
 from ..addhardware import vmmAddHardware
@@ -1641,9 +1640,7 @@ class vmmDetails(vmmGObjectUI):
         kwargs = {}
 
         if self._edited(EDIT_FS):
-            fsdriver = uiutil.get_list_selection(
-                self.fsDetails.widget("fs-driver-combo"))
-            if fsdriver == DeviceFilesystem.DRIVER_VIRTIOFS:
+            if self.fsDetails.force_mem_shared_access():
                 guest = self.vm.xmlobj
                 if guest.cpu.has_private_memAccess_cells():
                     embeded_kwargs = {}
diff --git a/virtManager/device/fsdetails.py b/virtManager/device/fsdetails.py
index 1650e1b8..264db3bb 100644
--- a/virtManager/device/fsdetails.py
+++ b/virtManager/device/fsdetails.py
@@ -120,6 +120,9 @@ class vmmFSDetails(vmmGObjectUI):
                 self.conn.is_qemu() or
                 self.conn.is_test() or
                 self.conn.is_lxc())
+        self.widget("mem-sharedaccess").set_visible(
+                self.conn.is_qemu() or
+                self.conn.is_test())
 
 
     ##############
@@ -176,6 +179,7 @@ class vmmFSDetails(vmmGObjectUI):
         self.widget("fs-source").set_text("")
         self.widget("fs-target").set_text("")
         self.widget("fs-readonly").set_active(False)
+        self.widget("mem-sharedaccess").set_active(False)
         self._sync_ui()
         self._active_edits = []
 
@@ -298,13 +302,22 @@ class vmmFSDetails(vmmGObjectUI):
 
     def _fs_driver_cb(self, src):
         fsdriver = uiutil.get_list_selection(src)
+        self.widget("mem-sharedaccess").set_visible(False)
         if fsdriver == DeviceFilesystem.DRIVER_VIRTIOFS:
             uiutil.set_list_selection(
                 self.widget("fs-mode-combo"), DeviceFilesystem.MODE_PASSTHROUGH)
             self.widget("fs-mode-combo").set_sensitive(False)
             self.widget("fs-readonly").set_active(False)
             self.widget("fs-readonly").set_sensitive(False)
+            guest = self.vm.xmlobj
+            if (guest.cpu.has_private_memAccess_cells() or
+                (not guest.cpu.all_shared_memAccess_cells() and
+                 not guest.memoryBacking.is_access_shared())):
+                self.widget("mem-sharedaccess").set_visible(True)
         else:
             self.widget("fs-mode-combo").set_sensitive(True)
             self.widget("fs-readonly").set_sensitive(True)
         self._change_cb(_EDIT_FS_DRIVER)
+
+    def force_mem_shared_access(self):
+        return self.widget("mem-sharedaccess").get_active()
-- 
2.26.2





More information about the virt-tools-list mailing list