fbe740
From 2fce649fb569ab21c224f387456c996428f8a251 Mon Sep 17 00:00:00 2001
fbe740
Message-Id: <2fce649fb569ab21c224f387456c996428f8a251@dist-git>
fbe740
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
fbe740
Date: Wed, 4 Mar 2020 12:42:41 +0100
fbe740
Subject: [PATCH] conf: qemu: add virtiofs fsdriver type
fbe740
MIME-Version: 1.0
fbe740
Content-Type: text/plain; charset=UTF-8
fbe740
Content-Transfer-Encoding: 8bit
fbe740
fbe740
Introduce a new 'virtiofs' driver type for filesystem.
fbe740
fbe740
<filesystem type='mount' accessmode='passthrough'>
fbe740
  <driver type='virtiofs'/>
fbe740
  <source dir='/path'/>
fbe740
  <target dir='mount_tag'>
fbe740
  <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
fbe740
</filesystem>
fbe740
fbe740
Signed-off-by: Ján Tomko <jtomko@redhat.com>
fbe740
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
fbe740
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
fbe740
Tested-by: Andrea Bolognani <abologna@redhat.com>
fbe740
(cherry picked from commit ecc6ad6b90ad674a903c95d2a637f8b1b5833be2)
fbe740
Signed-off-by: Ján Tomko <jtomko@redhat.com>
fbe740
https://bugzilla.redhat.com/show_bug.cgi?id=1694166
fbe740
Message-Id: <abe26807f06ed14b2be3cbd098461afc307e88e3.1583322090.git.jtomko@redhat.com>
fbe740
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
fbe740
---
fbe740
 docs/formatdomain.html.in                     | 12 ++-
fbe740
 docs/schemas/domaincommon.rng                 |  6 ++
fbe740
 src/conf/domain_conf.c                        |  1 +
fbe740
 src/conf/domain_conf.h                        |  1 +
fbe740
 src/qemu/qemu_command.c                       |  4 +
fbe740
 src/qemu/qemu_domain.c                        |  4 +
fbe740
 src/qemu/qemu_domain_address.c                |  4 +
fbe740
 .../vhost-user-fs-fd-memory.xml               | 39 ++++++++++
fbe740
 .../vhost-user-fs-hugepages.xml               | 74 +++++++++++++++++++
fbe740
 .../vhost-user-fs-fd-memory.x86_64-latest.xml |  1 +
fbe740
 .../vhost-user-fs-hugepages.x86_64-latest.xml |  1 +
fbe740
 tests/qemuxml2xmltest.c                       |  3 +
fbe740
 12 files changed, 149 insertions(+), 1 deletion(-)
fbe740
 create mode 100644 tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
fbe740
 create mode 100644 tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
fbe740
 create mode 120000 tests/qemuxml2xmloutdata/vhost-user-fs-fd-memory.x86_64-latest.xml
fbe740
 create mode 120000 tests/qemuxml2xmloutdata/vhost-user-fs-hugepages.x86_64-latest.xml
fbe740
fbe740
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
fbe740
index 50914a5207..337ab01316 100644
fbe740
--- a/docs/formatdomain.html.in
fbe740
+++ b/docs/formatdomain.html.in
fbe740
@@ -3935,6 +3935,11 @@
fbe740
     <target dir='/import/from/host'/>
fbe740
     <readonly/>
fbe740
   </filesystem>
fbe740
+  <filesystem type='mount' accessmode='passthrough'>
fbe740
+      <driver type='virtiofs'/>
fbe740
+      <source dir='/path'/>
fbe740
+      <target dir='mount_tag'/>
fbe740
+  </filesystem>
fbe740
   ...
fbe740
 </devices>
fbe740
 ...
fbe740
@@ -3963,6 +3968,9 @@
fbe740
         while the value immediate means that a host writeback
fbe740
         is immediately triggered for all pages touched during a guest file
fbe740
         write operation (since 0.9.10).
fbe740
+        Since 6.2.0, type='virtiofs'
fbe740
+        is also supported. Using virtiofs requires setting up shared memory,
fbe740
+        see the guide: Virtio-FS
fbe740
         
fbe740
         
template
fbe740
         
fbe740
@@ -3998,7 +4006,9 @@
fbe740
       The filesystem element has an optional attribute accessmode
fbe740
       which specifies the security mode for accessing the source
fbe740
       (since 0.8.5). Currently this only works
fbe740
-      with type='mount' for the QEMU/KVM driver. The possible
fbe740
+      with type='mount' for the QEMU/KVM driver.
fbe740
+      For driver type virtiofs, only passthrough is
fbe740
+      supported. For other driver types, the possible
fbe740
       values are:
fbe740
 
fbe740
         
fbe740
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
fbe740
index bfd8786ea8..5a9291b443 100644
fbe740
--- a/docs/schemas/domaincommon.rng
fbe740
+++ b/docs/schemas/domaincommon.rng
fbe740
@@ -2645,6 +2645,12 @@
fbe740
           </optional>
fbe740
           <ref name='virtioOptions'/>
fbe740
         </group>
fbe740
+        <group>
fbe740
+          <attribute name="type">
fbe740
+            <value>virtiofs</value>
fbe740
+          </attribute>
fbe740
+          <ref name='virtioOptions'/>
fbe740
+        </group>
fbe740
         <empty/>
fbe740
       </choice>
fbe740
     </element>
fbe740
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
fbe740
index 990c5bcc1e..31d4828802 100644
fbe740
--- a/src/conf/domain_conf.c
fbe740
+++ b/src/conf/domain_conf.c
fbe740
@@ -476,6 +476,7 @@ VIR_ENUM_IMPL(virDomainFSDriver,
fbe740
               "loop",
fbe740
               "nbd",
fbe740
               "ploop",
fbe740
+              "virtiofs",
fbe740
 );
fbe740
 
fbe740
 VIR_ENUM_IMPL(virDomainFSAccessMode,
fbe740
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
fbe740
index ef2c1b80f7..921cc42a57 100644
fbe740
--- a/src/conf/domain_conf.h
fbe740
+++ b/src/conf/domain_conf.h
fbe740
@@ -771,6 +771,7 @@ typedef enum {
fbe740
     VIR_DOMAIN_FS_DRIVER_TYPE_LOOP,
fbe740
     VIR_DOMAIN_FS_DRIVER_TYPE_NBD,
fbe740
     VIR_DOMAIN_FS_DRIVER_TYPE_PLOOP,
fbe740
+    VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS,
fbe740
 
fbe740
     VIR_DOMAIN_FS_DRIVER_TYPE_LAST
fbe740
 } virDomainFSDriverType;
fbe740
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
fbe740
index 252809a8d7..7fdf58f067 100644
fbe740
--- a/src/qemu/qemu_command.c
fbe740
+++ b/src/qemu/qemu_command.c
fbe740
@@ -2695,6 +2695,10 @@ qemuBuildFilesystemCommandLine(virCommandPtr cmd,
fbe740
                 return -1;
fbe740
             break;
fbe740
 
fbe740
+        case VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS:
fbe740
+            /* TODO: vhost-user-fs-pci */
fbe740
+            break;
fbe740
+
fbe740
         case VIR_DOMAIN_FS_DRIVER_TYPE_LOOP:
fbe740
         case VIR_DOMAIN_FS_DRIVER_TYPE_NBD:
fbe740
         case VIR_DOMAIN_FS_DRIVER_TYPE_PLOOP:
fbe740
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
fbe740
index ed35260712..402b079b09 100644
fbe740
--- a/src/qemu/qemu_domain.c
fbe740
+++ b/src/qemu/qemu_domain.c
fbe740
@@ -8361,6 +8361,10 @@ qemuDomainDeviceDefValidateFS(virDomainFSDefPtr fs,
fbe740
                        _("Filesystem driver type not supported"));
fbe740
         return -1;
fbe740
 
fbe740
+    case VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS:
fbe740
+        /* TODO: vhost-user-fs-pci */
fbe740
+        return 0;
fbe740
+
fbe740
     case VIR_DOMAIN_FS_DRIVER_TYPE_LAST:
fbe740
     default:
fbe740
         virReportEnumRangeError(virDomainFSDriverType, fs->fsdriver);
fbe740
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
fbe740
index 9e3bcc434d..3c6ac62ff5 100644
fbe740
--- a/src/qemu/qemu_domain_address.c
fbe740
+++ b/src/qemu/qemu_domain_address.c
fbe740
@@ -690,6 +690,10 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
fbe740
             }
fbe740
             break;
fbe740
 
fbe740
+        case VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS:
fbe740
+            /* vhost-user-fs-pci */
fbe740
+            return virtioFlags;
fbe740
+
fbe740
         case VIR_DOMAIN_FS_DRIVER_TYPE_LOOP:
fbe740
         case VIR_DOMAIN_FS_DRIVER_TYPE_NBD:
fbe740
         case VIR_DOMAIN_FS_DRIVER_TYPE_PLOOP:
fbe740
diff --git a/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
fbe740
new file mode 100644
fbe740
index 0000000000..a6b6279fb8
fbe740
--- /dev/null
fbe740
+++ b/tests/qemuxml2argvdata/vhost-user-fs-fd-memory.xml
fbe740
@@ -0,0 +1,39 @@
fbe740
+<domain type='kvm'>
fbe740
+  <name>guest</name>
fbe740
+  <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid>
fbe740
+  <memory unit='KiB'>14680064</memory>
fbe740
+  <currentMemory unit='KiB'>14680064</currentMemory>
fbe740
+  <memoryBacking>
fbe740
+    <source type='file'/>
fbe740
+    <access mode='shared'/>
fbe740
+  </memoryBacking>
fbe740
+  <vcpu placement='static'>2</vcpu>
fbe740
+  <os>
fbe740
+    <type arch='x86_64' machine='pc'>hvm</type>
fbe740
+    <boot dev='hd'/>
fbe740
+  </os>
fbe740
+  <cpu mode='custom' match='exact' check='none'>
fbe740
+    <model fallback='forbid'>qemu64</model>
fbe740
+    <numa>
fbe740
+      <cell id='0' cpus='0-1' memory='14680064' unit='KiB' memAccess='shared'/>
fbe740
+    </numa>
fbe740
+  </cpu>
fbe740
+  <clock offset='utc'/>
fbe740
+  <on_poweroff>destroy</on_poweroff>
fbe740
+  <on_reboot>restart</on_reboot>
fbe740
+  <on_crash>destroy</on_crash>
fbe740
+  <devices>
fbe740
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
fbe740
+    <controller type='usb' index='0' model='none'/>
fbe740
+    <controller type='pci' index='0' model='pci-root'/>
fbe740
+    <filesystem type='mount' accessmode='passthrough'>
fbe740
+      <driver type='virtiofs'/>
fbe740
+      <source dir='/path'/>
fbe740
+      <target dir='mount_tag'/>
fbe740
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
fbe740
+    </filesystem>
fbe740
+    <input type='mouse' bus='ps2'/>
fbe740
+    <input type='keyboard' bus='ps2'/>
fbe740
+    <memballoon model='none'/>
fbe740
+  </devices>
fbe740
+</domain>
fbe740
diff --git a/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml b/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
fbe740
new file mode 100644
fbe740
index 0000000000..70df7b890d
fbe740
--- /dev/null
fbe740
+++ b/tests/qemuxml2argvdata/vhost-user-fs-hugepages.xml
fbe740
@@ -0,0 +1,74 @@
fbe740
+<domain type='qemu'>
fbe740
+  <name>guest</name>
fbe740
+  <uuid>1ccfd97d-5eb4-478a-bbe6-88d254c16db7</uuid>
fbe740
+  <memory unit='KiB'>4194304</memory>
fbe740
+  <currentMemory unit='KiB'>4194304</currentMemory>
fbe740
+  <memoryBacking>
fbe740
+    <hugepages>
fbe740
+      <page size='2048' unit='KiB'/>
fbe740
+    </hugepages>
fbe740
+    <access mode='shared'/>
fbe740
+  </memoryBacking>
fbe740
+  <vcpu placement='static'>2</vcpu>
fbe740
+  <os>
fbe740
+    <type arch='x86_64' machine='q35'>hvm</type>
fbe740
+    <boot dev='hd'/>
fbe740
+  </os>
fbe740
+  <features>
fbe740
+    <acpi/>
fbe740
+    <apic/>
fbe740
+  </features>
fbe740
+  <cpu mode='custom' match='exact' check='none'>
fbe740
+    <model fallback='forbid'>qemu64</model>
fbe740
+    <numa>
fbe740
+      <cell id='0' cpus='0-1' memory='2097152' unit='KiB' memAccess='shared'/>
fbe740
+    </numa>
fbe740
+  </cpu>
fbe740
+  <clock offset='utc'/>
fbe740
+  <on_poweroff>destroy</on_poweroff>
fbe740
+  <on_reboot>restart</on_reboot>
fbe740
+  <on_crash>destroy</on_crash>
fbe740
+  <devices>
fbe740
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
fbe740
+    <disk type='file' device='disk'>
fbe740
+      <driver name='qemu' type='qcow2'/>
fbe740
+      <source file='/var/lib/libvirt/images/guest.qcow2'/>
fbe740
+      <target dev='vda' bus='virtio'/>
fbe740
+      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
fbe740
+    </disk>
fbe740
+    <controller type='usb' index='0' model='none'/>
fbe740
+    <controller type='sata' index='0'>
fbe740
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
fbe740
+    </controller>
fbe740
+    <controller type='pci' index='0' model='pcie-root'/>
fbe740
+    <controller type='pci' index='1' model='pcie-root-port'>
fbe740
+      <model name='pcie-root-port'/>
fbe740
+      <target chassis='1' port='0x8'/>
fbe740
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0' multifunction='on'/>
fbe740
+    </controller>
fbe740
+    <controller type='pci' index='2' model='pcie-root-port'>
fbe740
+      <model name='pcie-root-port'/>
fbe740
+      <target chassis='2' port='0x9'/>
fbe740
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
fbe740
+    </controller>
fbe740
+    <controller type='pci' index='3' model='pcie-root-port'>
fbe740
+      <model name='pcie-root-port'/>
fbe740
+      <target chassis='3' port='0xa'/>
fbe740
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
fbe740
+    </controller>
fbe740
+    <controller type='pci' index='4' model='pcie-root-port'>
fbe740
+      <model name='pcie-root-port'/>
fbe740
+      <target chassis='4' port='0xb'/>
fbe740
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x3'/>
fbe740
+    </controller>
fbe740
+    <filesystem type='mount' accessmode='passthrough'>
fbe740
+      <driver type='virtiofs'/>
fbe740
+      <source dir='/path'/>
fbe740
+      <target dir='mount_tag'/>
fbe740
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
fbe740
+    </filesystem>
fbe740
+    <input type='mouse' bus='ps2'/>
fbe740
+    <input type='keyboard' bus='ps2'/>
fbe740
+    <memballoon model='none'/>
fbe740
+  </devices>
fbe740
+</domain>
fbe740
diff --git a/tests/qemuxml2xmloutdata/vhost-user-fs-fd-memory.x86_64-latest.xml b/tests/qemuxml2xmloutdata/vhost-user-fs-fd-memory.x86_64-latest.xml
fbe740
new file mode 120000
fbe740
index 0000000000..fbc552ef94
fbe740
--- /dev/null
fbe740
+++ b/tests/qemuxml2xmloutdata/vhost-user-fs-fd-memory.x86_64-latest.xml
fbe740
@@ -0,0 +1 @@
fbe740
+../qemuxml2argvdata/vhost-user-fs-fd-memory.xml
fbe740
\ No newline at end of file
fbe740
diff --git a/tests/qemuxml2xmloutdata/vhost-user-fs-hugepages.x86_64-latest.xml b/tests/qemuxml2xmloutdata/vhost-user-fs-hugepages.x86_64-latest.xml
fbe740
new file mode 120000
fbe740
index 0000000000..0c0f05b254
fbe740
--- /dev/null
fbe740
+++ b/tests/qemuxml2xmloutdata/vhost-user-fs-hugepages.x86_64-latest.xml
fbe740
@@ -0,0 +1 @@
fbe740
+../qemuxml2argvdata/vhost-user-fs-hugepages.xml
fbe740
\ No newline at end of file
fbe740
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
fbe740
index d58259587b..f77f59fa3c 100644
fbe740
--- a/tests/qemuxml2xmltest.c
fbe740
+++ b/tests/qemuxml2xmltest.c
fbe740
@@ -1428,6 +1428,9 @@ mymain(void)
fbe740
     DO_TEST("vhost-vsock-ccw-auto", QEMU_CAPS_DEVICE_VHOST_VSOCK,
fbe740
             QEMU_CAPS_CCW);
fbe740
 
fbe740
+    DO_TEST_CAPS_LATEST("vhost-user-fs-fd-memory");
fbe740
+    DO_TEST_CAPS_LATEST("vhost-user-fs-hugepages");
fbe740
+
fbe740
     DO_TEST("riscv64-virt",
fbe740
             QEMU_CAPS_DEVICE_VIRTIO_MMIO);
fbe740
     DO_TEST("riscv64-virt-pci",
fbe740
-- 
fbe740
2.25.1
fbe740