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:

  <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>
This commit is contained in:
Roman Bogorodskiy 2020-10-07 20:07:04 +04:00
parent 7c878cf9a7
commit 7382a7c2be
17 changed files with 308 additions and 1 deletions

View 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;

View 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);

View 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;

View 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;
}

View File

@ -402,6 +402,7 @@ virDomainDiskSourceFormat;
virDomainDiskTranslateSourcePool;
virDomainFeatureTypeFromString;
virDomainFeatureTypeToString;
virDomainFSAccessModeTypeToString;
virDomainFSCacheModeTypeToString;
virDomainFSDefFree;
virDomainFSDefNew;

View File

@ -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

View File

@ -0,0 +1,3 @@
/usr/sbin/bhyveload \
-m 214 \
-d /tmp/freebsd.img bhyve

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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

View File

@ -0,0 +1,3 @@
/usr/sbin/bhyveload \
-m 214 \
-d /tmp/freebsd.img bhyve

View File

@ -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>

View 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");

View File

@ -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>

View 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");