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

Is NFS/Samba the only way to share files between host and guest? #70

Open
jgonera opened this issue Sep 30, 2015 · 23 comments
Open

Is NFS/Samba the only way to share files between host and guest? #70

jgonera opened this issue Sep 30, 2015 · 23 comments

Comments

@jgonera
Copy link

jgonera commented Sep 30, 2015

I was wondering if I am missing something. Can I somehow mount the disk image both on guest and host? I suspect that this would cause concurrency issues even if it is possible.

@xez
Copy link
Contributor

xez commented Oct 2, 2015

Network based solutions are probably the only options right now. I suggested virtio-9p as means of guest <-> host file sharing. But thats quite a bit of work.

@geoff-nixon
Copy link

@jgonera osxfuse + fuse-ext2 should allow you to mount R/W concurrently, though I can't vouch for it personally. Myself I use Paragon's commercial ExtFS for Mac, which is quite fast and the write locks are good enough I've never seen a race condition or corruption.

@geoff-nixon
Copy link

@johanneswuerbach Good point... osxfuse requires root and a codesigned kext. So I'll venture a different "no" answer — there's also afp (netatalk/avahi), http/webdav, ftp, scp, netcat... 😉 :neckbeard:.

@galaxy001
Copy link

It should be possible to mimic the Parallel Desktop's solution that installs a driver to the guest and export filesystem to host.

If we export it to host under fuse, no other kext needed except for osxfuse itself.

Well, I just read about VirtFS. Seems enough.


@geoff-codes mentioned mount R/W for a disk image with write locks, I wonder whether the "write locks" means it can make both the virtual machine and host to write on same disk image ?

@jceel
Copy link

jceel commented Feb 1, 2016

Hi guys,

I'm working on virtio-9p (so-called VirtFS) support for bhyve/xhyve. Right now I have almost complete 9p2000.u protocol support (except atime/mtime modification in Twstat).

You can check it out here: https://github.com/jceel/xhyve

Here's how to use it:

  1. add -s <n>,virtio-9p,sharename=/host/path to your xhyve arguments
  2. boot Linux
  3. mount -t 9p -o trans=virtio -o version=9p2000.u sharename /mnt/guest/path

Using 9p as root filesystem should work too.

This code is of course totally experimental and untested - I'm looking forward to your feeback!

@xez
Copy link
Contributor

xez commented Feb 2, 2016

@jceel Awesome, great work!!!

@ailispaw
Copy link
Contributor

ailispaw commented Feb 2, 2016

Hi @jceel great work!!
I tried to use virtfs with your xhyve and it works, but I have one problem here.
When the owner of a file and a user in a VM have different uid, the user (except root) can't modify the file from the VM.
Is there any configuration for ACL mapping like -mapall option for NFS?

@jceel
Copy link

jceel commented Feb 2, 2016

@ailispaw: You can try the following mount options: access=any (and optionally dfltuid=<n> if going to attach as non-root). That should make Linux do single attach as root/dfltuid.

Here's mount -t 9p options reference: https://www.kernel.org/doc/Documentation/filesystems/9p.txt

@ailispaw
Copy link
Contributor

ailispaw commented Feb 2, 2016

@jceel Thank you for the reply.
Yes. I have added access=any to it, but I can read files but write.
I will try dfltuid=<n>. Should <n> be a uid on host, shouldn't it?

@jceel
Copy link

jceel commented Feb 2, 2016

@ailispaw: yes, it should refer to the host UID.

@ailispaw
Copy link
Contributor

ailispaw commented Feb 2, 2016

Kernel version: 4.4.1 with

CONFIG_NET_9P=y
CONFIG_NET_9P_VIRTIO=y
CONFIG_9P_FS=y
CONFIG_9P_FS_POSIX_ACL=y

501 is my uid in OSX 10.10.5 host.

$ sudo mkdir -p /mnt/host
$ sudo mount -t 9p -o trans=virtio -o version=9p2000.u -o access=any -o dfltuid=501 host /mnt/host
$ touch /mnt/host/aaa
touch: /mnt/host/aaa: Permission denied

Something missing?

-s 5,virtio-9p,host=/Users/ailispaw/Desktop/test in my xhyverun.sh

@jceel
Copy link

jceel commented Feb 2, 2016

Ah, I see what you're trying to do. There's no UID/GID translation mechanism (yet) and it turns out dfltuid works a bit differently than I thought:

  • it's effective only when using legacy 9P2000 protocol (because original 9P2000 doesn't have concept of numeric uids/gids)
  • it's a client uid

So, a very poor man's solution would be to use 9P2000 and map everything to uid specified by dfltuid. For example:

mount -t 9p -o version=9p2000 -o trans=virtio -o access=any -o uname=root -o dftlduid=1000

but with that approach, you'll lose ability to create symlinks/pipes/devices and ability see/modify file ownerships - basically everything in shared filesystem will be shown as owned by UID 1000. on the host side, newly created files and directories will be owned by root.

(to use -o uname option you need to update your sources, I've checked in support for it few minutes ago)

It seems to me that there are two ultimate solutions:

  • stick to "align your UIDs, sir" policy forever
  • implement an UID translation mechanism on the xhyve side (eg. make it read uid1=uid2 pairs from a text file specified on the command line)

@ailispaw
Copy link
Contributor

ailispaw commented Feb 2, 2016

@jceel Thank you so much for the explanation.
I thought security_mode=mapped on the virtfs server side was for that purpose.

@ailispaw
Copy link
Contributor

ailispaw commented Feb 2, 2016

@jceel I would like to let you know the result of 9p2000 case.
I tried mount -t 9p -o version=9p2000 -o trans=virtio -o access=any -o uname=root -o dfltuid=1000 host /mnt/host, but I got a xhyve panic as below.

$ sudo mkdir -p /mnt/host
$ sudo mount -t 9p -o version=9p2000 -o trans=virtio -o access=any -o uname=root -o dfltuid=1000 host /mnt/host
xhyve(5451,0x14468d000) malloc: *** error for object 0x7ffbd07006b0: pointer being freed was not allocated
     *** set a breakpoint in malloc_error_break to debug
                                                        ./xhyverun.sh: line 68:  5451 Abort trap: 6

@ailispaw
Copy link
Contributor

ailispaw commented Feb 2, 2016

@jceel Oh, I'm sorry I didn't update xhyve. I will test it again.

@ailispaw
Copy link
Contributor

ailispaw commented Feb 2, 2016

@jceel
That solution works for me!!

$ sudo mount -t 9p -o version=9p2000 -o trans=virtio -o access=any -o uname=ailispaw -o dfltuid=1000 -o dfltgid=1000 host /mnt/host

Thanks. :)

@stv0g
Copy link

stv0g commented Mar 31, 2016

Do you plan to push those changes to @mist64's repo?

@galaxy001
Copy link

I tried jceel/xhyve with sysresccd which provides fs/9p/9p.ko. However, when I try tomount -t 9p -o trans=virtio,version=9p2000.L hostshare /mnt/ after modprobe 9p, it says:

mount: special device hostshare does not exist

And find /dev/ |grep hostshare is empty.

My lsmod is:

% lsmod|grep -P '9p|virtio'
9p                     41056  0
fscache                47757  1 9p
9pnet_virtio           12537  0
9pnet                  58902  2 9p,9pnet_virtio
virtio_pci             12487  0
virtio_ring            14405  2 virtio_pci,9pnet_virtio
virtio                 13313  2 virtio_pci,9pnet_virtio

@jceel
Copy link

jceel commented May 11, 2016

9p2000.L is not supported yet - try 9p2000.u.

@galaxy001
Copy link

galaxy001 commented May 11, 2016

I keep get this in dmesg each time run mount:

9pnet_virtio: no channels available

I googled to https://bugs.launchpad.net/qemu/+bug/648128 and find 2 patch for trans_virtio.c and mount.c.

How can I check whether xhyve works ?

My lspci do shows a Virtio filesystem, but I do not know how to dump its tagname.

% lspci
00:00.0 Host bridge: Network Appliance Corporation Device 1275
00:02.0 Ethernet controller: Red Hat, Inc Virtio network device
00:03.0 SATA controller: Intel Corporation 82801HR/HO/HH (ICH8R/DO/DH) 6 port SATA Controller [AHCI mode]
00:05.0 SCSI storage controller: Red Hat, Inc Virtio filesystem
00:1f.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]

@jceel
Copy link

jceel commented May 11, 2016

What did you pass to xhyve command line?

@galaxy001
Copy link

build/xhyve -A -m 1G -s 0:0,hostbridge -s 31,lpc -l com1,stdio -s 2:0,virtio-net -s 3,ahci-cd,/Users/Galaxy/Downloads/systemrescuecd-x86-4.7.2.iso -s 5,virtio-9p,hostshare=/Users/Galaxy/git/xhyve/t,ro -f kexec,systemrescuecd/rescue64,systemrescuecd/initram.igz,earlyprintk=serial console=ttyS0

@galaxy001
Copy link

@jceel Would you update a kernel binary in your repo for testing ?

If my CLI was correct, it should due to the systemrescuecd kernel cannot support even after modprobe 9p.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants