From 7382a7c2bef9d0f74a364a13b8b4ec8c08ffd1e5 Mon Sep 17 00:00:00 2001 From: Roman Bogorodskiy Date: Wed, 7 Oct 2020 20:07:04 +0400 Subject: [PATCH] bhyve: implement virtio-9p support 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: Optional 'readonly' sub-element enables read-only mode. Signed-off-by: Roman Bogorodskiy Reviewed-by: Michal Privoznik --- src/bhyve/bhyve_capabilities.c | 14 ++++ src/bhyve/bhyve_capabilities.h | 1 + src/bhyve/bhyve_command.c | 72 +++++++++++++++++++ src/bhyve/bhyve_device.c | 10 +++ src/libvirt_private.syms | 1 + .../bhyvexml2argv-fs-9p-readonly.args | 10 +++ .../bhyvexml2argv-fs-9p-readonly.ldargs | 3 + .../bhyvexml2argv-fs-9p-readonly.xml | 28 ++++++++ ...exml2argv-fs-9p-unsupported-accessmode.xml | 27 +++++++ ...bhyvexml2argv-fs-9p-unsupported-driver.xml | 28 ++++++++ .../bhyvexml2argv-fs-9p-unsupported-type.xml | 27 +++++++ .../bhyvexml2argv-fs-9p.args | 10 +++ .../bhyvexml2argv-fs-9p.ldargs | 3 + .../bhyvexml2argvdata/bhyvexml2argv-fs-9p.xml | 27 +++++++ tests/bhyvexml2argvtest.c | 9 ++- .../bhyvexml2xmlout-fs-9p.xml | 38 ++++++++++ tests/bhyvexml2xmltest.c | 1 + 17 files changed, 308 insertions(+), 1 deletion(-) create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.args create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.ldargs create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-accessmode.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-driver.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-type.xml create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.args create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.ldargs create mode 100644 tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.xml create mode 100644 tests/bhyvexml2xmloutdata/bhyvexml2xmlout-fs-9p.xml diff --git a/src/bhyve/bhyve_capabilities.c b/src/bhyve/bhyve_capabilities.c index 96cfe8357a..8a9acf52b0 100644 --- a/src/bhyve/bhyve_capabilities.c +++ b/src/bhyve/bhyve_capabilities.c @@ -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; diff --git a/src/bhyve/bhyve_capabilities.h b/src/bhyve/bhyve_capabilities.h index b2a16b0189..1b25c000b5 100644 --- a/src/bhyve/bhyve_capabilities.h +++ b/src/bhyve/bhyve_capabilities.h @@ -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); diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 7526f10fb1..7606840f45 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -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(¶ms, ",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(¶ms)); + + 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; diff --git a/src/bhyve/bhyve_device.c b/src/bhyve/bhyve_device.c index e2e1efd97e..f8c7522d26 100644 --- a/src/bhyve/bhyve_device.c +++ b/src/bhyve/bhyve_device.c @@ -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; } diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 152083d220..d773aee571 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -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 index 0000000000..193895574d --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.args @@ -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 index 0000000000..32538b558e --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.ldargs @@ -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 index 0000000000..6341236654 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-readonly.xml @@ -0,0 +1,28 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + + + + + + +
+ + + + + +
+ + + + + + + + diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-accessmode.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-accessmode.xml new file mode 100644 index 0000000000..f7d8ce5712 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-accessmode.xml @@ -0,0 +1,27 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + + + + + + +
+ + + + + +
+ + + + + + + diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-driver.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-driver.xml new file mode 100644 index 0000000000..3072e6a687 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-driver.xml @@ -0,0 +1,28 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + + + + + + +
+ + + + + +
+ + + + + + + + diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-type.xml b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-type.xml new file mode 100644 index 0000000000..24d7d129fc --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-type.xml @@ -0,0 +1,27 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + + + + + + +
+ + + + + +
+ + + + + + + diff --git a/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.args b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.args new file mode 100644 index 0000000000..0d27954432 --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.args @@ -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 index 0000000000..32538b558e --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.ldargs @@ -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 index 0000000000..22b8edc69f --- /dev/null +++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p.xml @@ -0,0 +1,27 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 1 + + hvm + + + + + + +
+ + + + + +
+ + + + + + + diff --git a/tests/bhyvexml2argvtest.c b/tests/bhyvexml2argvtest.c index def2acc15c..be816e554f 100644 --- a/tests/bhyvexml2argvtest.c +++ b/tests/bhyvexml2argvtest.c @@ -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 index 0000000000..db3faf29ef --- /dev/null +++ b/tests/bhyvexml2xmloutdata/bhyvexml2xmlout-fs-9p.xml @@ -0,0 +1,38 @@ + + bhyve + df3be7e7-a104-11e3-aeb0-50e5492bd3dc + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + + + + +
+ + + +
+ + + + +
+ + + + + +
+ + + diff --git a/tests/bhyvexml2xmltest.c b/tests/bhyvexml2xmltest.c index 8808d5a8fa..eb9b108704 100644 --- a/tests/bhyvexml2xmltest.c +++ b/tests/bhyvexml2xmltest.c @@ -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");