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