]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
bhyve: implement virtio-9p support
authorRoman Bogorodskiy <bogorodskiy@gmail.com>
Wed, 7 Oct 2020 16:07:04 +0000 (20:07 +0400)
committerRoman Bogorodskiy <bogorodskiy@gmail.com>
Fri, 9 Oct 2020 14:46:04 +0000 (18:46 +0400)
Recently virtio-9p support was added to bhyve.

On the host side it looks this way:

  bhyve .... -s 25:0,virtio-9p,sharename=/path/to/shared/dir

It could also have ",ro" suffix to make share read-only.

In the Linux guest, this share is mounted with:

  mount -t 9p sharename /mnt/sharename

In the guest user will see the same permissions and ownership
information for this directory as on the host. No uid/gid remapping is
supported, so those could resolve to wrong user or group names.

The same applies to the other side: chowning/chmodding in the guest will
set specified ownership and permissions on the host.

In libvirt domain XML it's modeled using the 'filesystem' element:

  <filesystem type='mount'>
    <source dir='/path/to/shared/dir'/>
    <target dir='sharename'/>
  </filesystem>

Optional 'readonly' sub-element enables read-only mode.

Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
17 files changed:
src/bhyve/bhyve_capabilities.c
src/bhyve/bhyve_capabilities.h
src/bhyve/bhyve_command.c
src/bhyve/bhyve_device.c
src/libvirt_private.syms
tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.args [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.ldargs [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.xml [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-accessmode.xml [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-driver.xml [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-type.xml [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.args [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.ldargs [new file with mode: 0644]
tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.xml [new file with mode: 0644]
tests/bhyvexml2argvtest.c
tests/bhyvexml2xmloutdata/bhyvexml2xmlout-fs-9p.xml [new file with mode: 0644]
tests/bhyvexml2xmltest.c

index 96cfe8357a195d160f8c94c8ca9056f13ac87437..8a9acf52b01a0696962e7f38c0e5323eecf7e82d 100644 (file)
@@ -344,6 +344,17 @@ bhyveProbeCapsVNCPassword(unsigned int *caps, char *binary)
 }
 
 
+static int
+bhyveProbeCapsVirtio9p(unsigned int *caps, char *binary)
+{
+    return bhyveProbeCapsDeviceHelper(caps, binary,
+                                      "-s",
+                                      "0,virtio-9p",
+                                      "pci slot 0:0: unknown device \"hda\"",
+                                      BHYVE_CAP_VIRTIO_9P);
+}
+
+
 int
 virBhyveProbeCaps(unsigned int *caps)
 {
@@ -378,6 +389,9 @@ virBhyveProbeCaps(unsigned int *caps)
     if ((ret = bhyveProbeCapsVNCPassword(caps, binary)))
         goto out;
 
+    if ((ret = bhyveProbeCapsVirtio9p(caps, binary)))
+        goto out;
+
  out:
     VIR_FREE(binary);
     return ret;
index b2a16b0189af2be9d3e06a31e3d015148a3c5e53..1b25c000b525042c45591113eff7dd808fa84a99 100644 (file)
@@ -51,6 +51,7 @@ typedef enum {
     BHYVE_CAP_CPUTOPOLOGY = 1 << 6,
     BHYVE_CAP_SOUND_HDA = 1 << 7,
     BHYVE_CAP_VNC_PASSWORD = 1 << 8,
+    BHYVE_CAP_VIRTIO_9P = 1 << 9,
 } virBhyveCapsFlags;
 
 int virBhyveProbeGrubCaps(virBhyveGrubCapsFlags *caps);
index 7526f10fb15e0249d1bf6c9e06d653e64783bcc6..7606840f45f87d4ce8ac129775f8447e2902ef66 100644 (file)
@@ -547,6 +547,73 @@ bhyveBuildSoundArgStr(const virDomainDef *def G_GNUC_UNUSED,
     return 0;
 }
 
+static int
+bhyveBuildFSArgStr(const virDomainDef *def G_GNUC_UNUSED,
+                   virDomainFSDefPtr fs,
+                   virCommandPtr cmd)
+{
+    g_auto(virBuffer) params = VIR_BUFFER_INITIALIZER;
+
+    switch ((virDomainFSType) fs->type) {
+    case VIR_DOMAIN_FS_TYPE_MOUNT:
+        break;
+    case VIR_DOMAIN_FS_TYPE_BLOCK:
+    case VIR_DOMAIN_FS_TYPE_FILE:
+    case VIR_DOMAIN_FS_TYPE_TEMPLATE:
+    case VIR_DOMAIN_FS_TYPE_RAM:
+    case VIR_DOMAIN_FS_TYPE_BIND:
+    case VIR_DOMAIN_FS_TYPE_VOLUME:
+    case VIR_DOMAIN_FS_TYPE_LAST:
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unsupported filesystem type '%s'"),
+                       virDomainFSTypeToString(fs->type));
+        return -1;
+    }
+
+    switch (fs->fsdriver) {
+    case VIR_DOMAIN_FS_DRIVER_TYPE_DEFAULT:
+        /* The only supported driver by bhyve currently */
+        break;
+    case VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS:
+    case VIR_DOMAIN_FS_DRIVER_TYPE_PATH:
+    case VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE:
+    case VIR_DOMAIN_FS_DRIVER_TYPE_LOOP:
+    case VIR_DOMAIN_FS_DRIVER_TYPE_NBD:
+    case VIR_DOMAIN_FS_DRIVER_TYPE_PLOOP:
+    case VIR_DOMAIN_FS_DRIVER_TYPE_LAST:
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unsupported filesystem driver '%s'"),
+                       virDomainFSDriverTypeToString(fs->fsdriver));
+        return -1;
+    }
+
+    switch (fs->accessmode) {
+    case VIR_DOMAIN_FS_ACCESSMODE_PASSTHROUGH:
+        /* This is the only supported mode for now, does not need specific configuration */
+        break;
+    case VIR_DOMAIN_FS_ACCESSMODE_MAPPED:
+    case VIR_DOMAIN_FS_ACCESSMODE_SQUASH:
+    case VIR_DOMAIN_FS_ACCESSMODE_LAST:
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unsupported filesystem accessmode '%s'"),
+                       virDomainFSAccessModeTypeToString(fs->accessmode));
+        return -1;
+    }
+
+    if (fs->readonly)
+        virBufferAddLit(&params, ",ro");
+
+    virCommandAddArg(cmd, "-s");
+    virCommandAddArgFormat(cmd, "%d:%d,virtio-9p,%s=%s%s",
+                           fs->info.addr.pci.slot,
+                           fs->info.addr.pci.function,
+                           fs->src->path,
+                           fs->dst,
+                           virBufferCurrentContent(&params));
+
+    return 0;
+}
+
 virCommandPtr
 virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, virDomainDefPtr def,
                              bool dryRun)
@@ -699,6 +766,11 @@ virBhyveProcessBuildBhyveCmd(bhyveConnPtr driver, virDomainDefPtr def,
             goto error;
     }
 
+    for (i = 0; i < def->nfss; i++) {
+        if (bhyveBuildFSArgStr(def, def->fss[i], cmd) < 0)
+            goto error;
+    }
+
     if (bhyveBuildConsoleArgStr(def, cmd) < 0)
         goto error;
 
index e2e1efd97ebf2b9484644a64270922a90428ca37..f8c7522d2661391af398159e09508531c1f15607 100644 (file)
@@ -175,6 +175,16 @@ bhyveAssignDevicePCISlots(virDomainDefPtr def,
             return -1;
     }
 
+    for (i = 0; i < def->nfss; i++) {
+        if (!virDeviceInfoPCIAddressIsWanted(&def->fss[i]->info))
+            continue;
+        if (virDomainPCIAddressReserveNextAddr(addrs,
+                                               &def->fss[i]->info,
+                                               VIR_PCI_CONNECT_TYPE_PCI_DEVICE,
+                                               -1) < 0)
+            return -1;
+    }
+
     return 0;
 }
 
index 152083d2202547f51aadecb6798d05ed0ea0f355..d773aee5713e6e99482c8d324ae7ba348841fd01 100644 (file)
@@ -402,6 +402,7 @@ virDomainDiskSourceFormat;
 virDomainDiskTranslateSourcePool;
 virDomainFeatureTypeFromString;
 virDomainFeatureTypeToString;
+virDomainFSAccessModeTypeToString;
 virDomainFSCacheModeTypeToString;
 virDomainFSDefFree;
 virDomainFSDefNew;
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.args b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.args
new file mode 100644 (file)
index 0000000..1938955
--- /dev/null
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 2:0,ahci,hd:/tmp/freebsd.img \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
+-s 4:0,virtio-9p,/shared/dir=shared_dir,ro bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.ldargs
new file mode 100644 (file)
index 0000000..32538b5
--- /dev/null
@@ -0,0 +1,3 @@
+/usr/sbin/bhyveload \
+-m 214 \
+-d /tmp/freebsd.img bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.xml
new file mode 100644 (file)
index 0000000..6341236
--- /dev/null
@@ -0,0 +1,28 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='52:54:00:b9:94:02'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+    <filesystem>
+      <source dir='/shared/dir'/>
+      <target dir='shared_dir'/>
+      <readonly/>
+    </filesystem>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-accessmode.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-accessmode.xml
new file mode 100644 (file)
index 0000000..f7d8ce5
--- /dev/null
@@ -0,0 +1,27 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='52:54:00:b9:94:02'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+    <filesystem accessmode='mapped'>
+      <source dir='/shared/dir'/>
+      <target dir='shared_dir'/>
+    </filesystem>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-driver.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-driver.xml
new file mode 100644 (file)
index 0000000..3072e6a
--- /dev/null
@@ -0,0 +1,28 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='52:54:00:b9:94:02'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+    <filesystem>
+      <driver type='loop'/>
+      <source dir='/shared/dir'/>
+      <target dir='shared_dir'/>
+    </filesystem>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-type.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-type.xml
new file mode 100644 (file)
index 0000000..24d7d12
--- /dev/null
@@ -0,0 +1,27 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='52:54:00:b9:94:02'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+    <filesystem type='bind'>
+      <source dir='/shared/dir'/>
+      <target dir='shared_dir'/>
+    </filesystem>
+  </devices>
+</domain>
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.args b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.args
new file mode 100644 (file)
index 0000000..0d27954
--- /dev/null
@@ -0,0 +1,10 @@
+/usr/sbin/bhyve \
+-c 1 \
+-m 214 \
+-u \
+-H \
+-P \
+-s 0:0,hostbridge \
+-s 2:0,ahci,hd:/tmp/freebsd.img \
+-s 3:0,virtio-net,faketapdev,mac=52:54:00:b9:94:02 \
+-s 4:0,virtio-9p,/shared/dir=shared_dir bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.ldargs b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.ldargs
new file mode 100644 (file)
index 0000000..32538b5
--- /dev/null
@@ -0,0 +1,3 @@
+/usr/sbin/bhyveload \
+-m 214 \
+-d /tmp/freebsd.img bhyve
diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.xml
new file mode 100644 (file)
index 0000000..22b8edc
--- /dev/null
@@ -0,0 +1,27 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory>219136</memory>
+  <vcpu>1</vcpu>
+  <os>
+    <type>hvm</type>
+  </os>
+  <devices>
+    <disk type='file'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+    </disk>
+    <interface type='bridge'>
+      <mac address='52:54:00:b9:94:02'/>
+      <model type='virtio'/>
+      <source bridge="virbr0"/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+    <filesystem>
+      <source dir='/shared/dir'/>
+      <target dir='shared_dir'/>
+    </filesystem>
+  </devices>
+</domain>
index def2acc15c345f3bc2e8a03e942b995acae08f7c..be816e554fd444401ff602e3fe2fe9584063222f 100644 (file)
@@ -167,7 +167,7 @@ mymain(void)
                        BHYVE_CAP_NET_E1000 | BHYVE_CAP_LPC_BOOTROM | \
                        BHYVE_CAP_FBUF | BHYVE_CAP_XHCI | \
                        BHYVE_CAP_CPUTOPOLOGY | BHYVE_CAP_SOUND_HDA | \
-                       BHYVE_CAP_VNC_PASSWORD;
+                       BHYVE_CAP_VNC_PASSWORD | BHYVE_CAP_VIRTIO_9P;
 
     DO_TEST("base");
     DO_TEST("wired");
@@ -208,6 +208,13 @@ mymain(void)
     DO_TEST("sound");
     DO_TEST("isa-controller");
     DO_TEST_FAILURE("isa-multiple-controllers");
+    DO_TEST("fs-9p");
+    DO_TEST("fs-9p-readonly");
+    DO_TEST_FAILURE("fs-9p-unsupported-type");
+    DO_TEST_FAILURE("fs-9p-unsupported-driver");
+    DO_TEST_FAILURE("fs-9p-unsupported-accessmode");
+    driver.bhyvecaps &= ~BHYVE_CAP_VIRTIO_9P;
+    DO_TEST_FAILURE("fs-9p");
 
     /* Address allocation tests */
     DO_TEST("addr-single-sata-disk");
diff --git a/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-fs-9p.xml b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-fs-9p.xml
new file mode 100644 (file)
index 0000000..db3faf2
--- /dev/null
@@ -0,0 +1,38 @@
+<domain type='bhyve'>
+  <name>bhyve</name>
+  <uuid>df3be7e7-a104-11e3-aeb0-50e5492bd3dc</uuid>
+  <memory unit='KiB'>219136</memory>
+  <currentMemory unit='KiB'>219136</currentMemory>
+  <vcpu placement='static'>1</vcpu>
+  <os>
+    <type arch='x86_64'>hvm</type>
+    <boot dev='hd'/>
+  </os>
+  <clock offset='utc'/>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <devices>
+    <disk type='file' device='disk'>
+      <driver name='file' type='raw'/>
+      <source file='/tmp/freebsd.img'/>
+      <target dev='hda' bus='sata'/>
+      <address type='drive' controller='0' bus='0' target='2' unit='0'/>
+    </disk>
+    <controller type='pci' index='0' model='pci-root'/>
+    <controller type='sata' index='0'>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+    </controller>
+    <filesystem type='mount' accessmode='passthrough'>
+      <source dir='/shared/dir'/>
+      <target dir='shared_dir'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
+    </filesystem>
+    <interface type='bridge'>
+      <mac address='52:54:00:b9:94:02'/>
+      <source bridge='virbr0'/>
+      <model type='virtio'/>
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+    </interface>
+  </devices>
+</domain>
index 8808d5a8fa30885dcd8401e8e07168cb3f9fc1b3..eb9b108704662c4d23b3cb6e3b1dca1e45d539ac 100644 (file)
@@ -112,6 +112,7 @@ mymain(void)
     DO_TEST_DIFFERENT("msrs");
     DO_TEST_DIFFERENT("sound");
     DO_TEST_DIFFERENT("isa-controller");
+    DO_TEST_DIFFERENT("fs-9p");
 
     /* Address allocation tests */
     DO_TEST_DIFFERENT("addr-single-sata-disk");