Filesystems in userspace? we're officially a microkernel!

9 views
Skip to first unread message

Barret Rhoden

unread,
Jun 14, 2019, 6:12:19 PM6/14/19
to akaros-list
Hi -

I've sorted out how to run a filesystem server in userspace, using a
VM. The short version is that a Linux VM is just a process, and it has
the code to mount a disk with e.g. ext4 on it. The VM guest runs a 9p
server, and Akaros can connect to it using virtio-net and NAT. And of
course Akaros can mount a 9p server.

For bonus points, I did it as a shell script. For even more points, my
Linux VMs boot relatively quickly. O(100ms) (much of which is
unpacking an unduly large initramfs). More on that in the next week or
so.

Here's the quick demo:

/ $ ./temp.sh
Usage: ./temp.sh /full/path/to/disk/data PART_ID /full/path/to/mnt

/ $ ls /mnt

(Nothing there)

/ $ ./temp.sh /dev/sdE0/data 1 /mnt/ &

/ $ ls /mnt/
bb data home proc tmp
bin dev lib root user
boot etc lost+found sbin usr
chroots export mnt sys var

(That's the contents of the ext4 filesystem. Note I passed it a disk
from Akaros/Plan 9. This is using Plan 9's disk driver and
virtio-block to Linux).

/ $ ps
1 bash WAITING 0
1342 /bin/sh WAITING 46
1348 vmrunkernel WAITING 1342
31 /bin/cs WAITING 0
34 /bin/dropbear WAITING 1
35 /bin/bash WAITING 1
45 /bin/dropbear WAITING 34
46 -sh WAITING 45
/ $ kill 1342

(Note I'm killing the shell script, not vmrunkernel. Our ps doesn't
know the scripts name...)

/ $ ls /mnt/

(and it's gone. It should have synced too.)

/ $ ps
1 bash WAITING 0
31 /bin/cs WAITING 0
34 /bin/dropbear WAITING 1
35 /bin/bash WAITING 1
45 /bin/dropbear WAITING 34
46 -sh WAITING 45

(VMRK and the shell script are gone).

The hard parts were getting it to clean up - getting the shell to
intercept the kill signal, sending a message to the tiny app in the VM
to kill the 9p file server, unmount the disk, and issue a vmcall to
shutdown.

One cool thing is that vmrunkernel (VMRK) expects to take a bunch of
text files. I didn't want to litter the namespace with them, so I used
#tmpfs. Just cd into it! You get a per-instance tmpfs that cleans
itself up when you leave the directory; i.e. when the shell exits.

I use virtio-cons for the control plane of the shutdown message, and the
guest's cmdline for telling Linux which partition to mount and which
port to have UFS listen on.

The script roughly does this:
- cd \#tmpfs (private, will be thrown away)
- bind \#pipe pipe-dir (gives us named pipes in the tmpfs)
- create cmdline and network control files for VMRK
- run VMRK, redirecting in pipe-dir/data1
- trap signals: sync; unmount; echo SHUTDOWN > pipe-dir/data

It'd actually be 'better' as a C program, due to some of the FD
management, and maybe the /full/path stuff, but the shell script works.
And it exposed a bunch of bugs / missing features. =)

There's a bunch of hokeyness I still need to sort through - various
minor bugs, cleanups of my linux 'distro' etc. More to come next week.

Barret

Gan Shun

unread,
Jun 15, 2019, 12:44:40 PM6/15/19
to Barret Rhoden, Akaros
Fantastic! This finally works!

--
You received this message because you are subscribed to the Google Groups "Akaros" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akaros+un...@googlegroups.com.
To post to this group, send email to aka...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/akaros/20190614181213.7f041101%40gnomeregan.cam.corp.google.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages