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