Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for host-shared folders using virtio-9p #97

Closed
wants to merge 14 commits into from
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "lib9p"]
path = lib9p
url = https://github.com/jceel/lib9p.git
21 changes: 19 additions & 2 deletions Makefile
Expand Up @@ -49,6 +49,7 @@ XHYVE_SRC := \
src/pci_irq.c \
src/pci_lpc.c \
src/pci_uart.c \
src/pci_virtio_9p.c \
src/pci_virtio_block.c \
src/pci_virtio_net_tap.c \
src/pci_virtio_net_vmnet.c \
Expand All @@ -67,14 +68,24 @@ FIRMWARE_SRC := \
src/firmware/kexec.c \
src/firmware/fbsd.c

LIB9P_SRC := \
lib9p/connection.c \
lib9p/hashtable.c \
lib9p/log.c \
lib9p/pack.c \
lib9p/request.c \
lib9p/utils.c \
lib9p/sbuf/sbuf.c \
lib9p/backend/fs.c

SRC := \
$(VMM_SRC) \
$(XHYVE_SRC) \
$(FIRMWARE_SRC)

OBJ := $(SRC:src/%.c=build/%.o)
OBJ := $(SRC:src/%.c=build/%.o) $(LIB9P_SRC:lib9p/%.c=build/lib9p/%.o)
DEP := $(OBJ:%.o=%.d)
INC := -Iinclude
INC := -Iinclude -Ilib9p

CFLAGS += -DVERSION=\"$(GIT_VERSION)\"

Expand All @@ -95,6 +106,11 @@ build/%.o: src/%.c
@mkdir -p $(dir $@)
$(VERBOSE) $(ENV) $(CC) $(CFLAGS) $(INC) $(DEF) -MMD -MT $@ -MF build/$*.d -o $@ -c $<

build/lib9p/%.o: lib9p/%.c
@echo cc $<
@mkdir -p $(dir $@)
$(VERBOSE) $(ENV) $(CC) $(CFLAGS) $(CFLAGS_LIB9P) $(INC) $(DEF) -MMD -MT $@ -MF build/lib9p/$*.d -o $@ -c $<

$(TARGET).sym: $(OBJ)
@echo ld $(notdir $@)
$(VERBOSE) $(ENV) $(LD) $(LDFLAGS) -Xlinker $(TARGET).lto.o -o $@ $(OBJ)
Expand All @@ -107,3 +123,4 @@ $(TARGET): $(TARGET).sym

clean:
@rm -rf build

23 changes: 20 additions & 3 deletions README.md
Expand Up @@ -28,11 +28,11 @@ If you have homebrew, then simply:

The `--HEAD` in the brew command ensures that you always get the latest changes, even if the homebrew database is not yet updated. If for any reason you don't want that simply do `brew install xhyve` .

if not then:
if not then:

Building
--------
$ git clone https://github.com/mist64/xhyve
$ git clone --recursive https://github.com/mist64/xhyve
$ cd xhyve
$ make

Expand Down Expand Up @@ -66,6 +66,7 @@ It exposes the following peripherals to virtual machines:
- VirtIO block device
- VirtIO networking
- VirtIO RNG
- VirtIO filesystem sharing

Notably absent are sound, USB, HID and any kind of graphics support. With a focus on server virtualization this is not strictly a requirement. bhyve may gain desktop virtualization capabilities in the future but this doesn't seem to be a priority.

Expand Down Expand Up @@ -152,7 +153,7 @@ xhyve architecture
------------------------------┼------------------------------
|syscall xnu kernel
V

VMX host
VMX nested paging

Expand Down Expand Up @@ -181,6 +182,22 @@ instead of:

Where *X* is your tap device, i.e. */dev/tapX*.

File Sharing
------
You can setup shared folders between OS X and your guest by using the `virtio-9p` device.
9P / VirtFS is a shared FS protocol introduced by Bell's Plan 9 OS.
More information is available in the [KVM wiki](http://www.linux-kvm.org/page/9p_virtio).

Adding a VirtFS device to your VM:

$ xhyve -s 5,virtio-9p,hostshare=/Users/example/shared,ro ...

Inside the Linux VM:

$ mount -t 9p -o trans=virtio,version=9p2000.L hostshare /tmp/host_files

The `hostshare` identifier can be changed to support multiple mounts.

Issues
------
If you are, or were, running any version of VirtualBox, prior to 4.3.30 or 5.0,
Expand Down
5 changes: 5 additions & 0 deletions config.mk
Expand Up @@ -47,6 +47,11 @@ CFLAGS_DIAG := \
CFLAGS_DBG := \
-g

CFLAGS_LIB9P := \
-Wno-padded \
-Wno-gnu-zero-variadic-macro-arguments \
-Wno-format-nonliteral

CFLAGS := \
-arch x86_64 \
-x c \
Expand Down
1 change: 1 addition & 0 deletions include/xhyve/virtio.h
Expand Up @@ -217,6 +217,7 @@ struct vring_used {
#define VIRTIO_DEV_NET 0x1000
#define VIRTIO_DEV_BLOCK 0x1001
#define VIRTIO_DEV_RANDOM 0x1002
#define VIRTIO_DEV_9P 0x1009

/*
* PCI config space constants.
Expand Down
1 change: 1 addition & 0 deletions lib9p
Submodule lib9p added at ddfdba