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(a)gmail.com>
---
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.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 +
16 files changed, 281 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.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 7cf8bea962..ae82172b90 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 @@
+<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
index 0000000000..f7d8ce5712
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-accessmode.xml
@@ -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
index 0000000000..3072e6a687
--- /dev/null
+++ b/tests/bhyvexml2argvdata/bhyvexml2argv-fs-9p-unsupported-driver.xml
@@ -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.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 @@
+<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>
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 @@
+<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>
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");
--
2.28.0