# v9fs: Plan 9 Resource Sharing for Linux

_Peios Kernel / Internals / Filesystems_

> v9fs is a Unix implementation of the Plan 9 9p remote filesystem protocol.

<a id="rst-v9fs-plan-9-resource-sharing-for-linux"></a>

<!-- SPDX-License-Identifier: GPL-2.0 -->

<a id="rst-about"></a>

## About

v9fs is a Unix implementation of the Plan 9 9p remote filesystem protocol.

This software was originally developed by Ron Minnich &lt;[rminnich@sandia.gov](<mailto:rminnich@sandia.gov>)&gt; and Maya Gokhale.  Additional development by Greg Watson &lt;[gwatson@lanl.gov](<mailto:gwatson@lanl.gov>)&gt; and most recently Eric Van Hensbergen &lt;[ericvh@gmail.com](<mailto:ericvh@gmail.com>)&gt;, Latchesar Ionkov &lt;[lucho@ionkov.net](<mailto:lucho@ionkov.net>)&gt; and Russ Cox &lt;[rsc@swtch.com](<mailto:rsc@swtch.com>)&gt;.

The best detailed explanation of the Linux implementation and applications of the 9p client is available in the form of a USENIX paper:

> [https://www.usenix.org/events/usenix05/tech/freenix/hensbergen.html](<https://www.usenix.org/events/usenix05/tech/freenix/hensbergen.html>)

Other applications are described in the following papers:

> - XCPU &amp; Clustering [http://xcpu.org/papers/xcpu-talk.pdf](<http://xcpu.org/papers/xcpu-talk.pdf>)
>
> - KVMFS: control file system for KVM [http://xcpu.org/papers/kvmfs.pdf](<http://xcpu.org/papers/kvmfs.pdf>)
>
> - CellFS: A New Programming Model for the Cell BE [http://xcpu.org/papers/cellfs-talk.pdf](<http://xcpu.org/papers/cellfs-talk.pdf>)
>
> - PROSE I/O: Using 9p to enable Application Partitions [http://plan9.escet.urjc.es/iwp9/cready/PROSE_iwp9_2006.pdf](<http://plan9.escet.urjc.es/iwp9/cready/PROSE_iwp9_2006.pdf>)
>
> - VirtFS: A Virtualization Aware File System pass-through [https://kernel.org/doc/ols/2010/ols2010-pages-109-120.pdf](<https://kernel.org/doc/ols/2010/ols2010-pages-109-120.pdf>)

<a id="rst-usage"></a>

## Usage

For remote file server:



```text
mount -t 9p 10.10.1.2 /mnt/9
```

For Plan 9 From User Space applications ([https://9fans.github.io/plan9port/](<https://9fans.github.io/plan9port/>)):



```text
mount -t 9p `namespace`/acme /mnt/9 -o trans=unix,uname=$USER
```

For server running on QEMU host with virtio transport:



```text
mount -t 9p -o trans=virtio <mount_tag> /mnt/9
```

where mount_tag is the tag generated by the server to each of the exported mount points. Each 9P export is seen by the client as a virtio device with an associated "mount_tag" property. Available mount tags can be seen by reading /sys/bus/virtio/drivers/9pnet_virtio/virtio&lt;n&gt;/mount_tag files.

<a id="rst-usbg-usage"></a>

## USBG Usage

To mount a 9p FS on a USB Host accessible via the gadget at runtime:



```text
mount -t 9p -o trans=usbg,aname=/path/to/fs <device> /mnt/9
```

To mount a 9p FS on a USB Host accessible via the gadget as root filesystem:



```text
root=<device> rootfstype=9p rootflags=trans=usbg,cache=loose,uname=root,access=0,dfltuid=0,dfltgid=0,aname=/path/to/rootfs
```

where &lt;device&gt; is the tag associated by the usb gadget transport. It is defined by the configfs instance name.

<a id="rst-usbg-example"></a>

## USBG Example

The USB host exports a filesystem, while the gadget on the USB device side makes it mountable.

Diod (9pfs server) and the forwarder are on the development host, where the root filesystem is actually stored. The gadget is initialized during boot (or later) on the embedded board. Then the forwarder will find it on the USB bus and start forwarding requests.

In this case the 9p requests come from the device and are handled by the host. The reason is that USB device ports are normally not available on PCs, so a connection in the other direction would not work.

When using the usbg transport, for now there is no native usb host service capable to handle the requests from the gadget driver. For this we have to use the extra python tool p9_fwd.py from tools/usb.

Just start the 9pfs capable network server like diod/nfs-ganesha e.g.:



```text
$ diod -f -n -d 0 -S -l 0.0.0.0:9999 -e $PWD
```

Optionally scan your bus if there are more then one usbg gadgets to find their path:



```text
$ python $kernel_dir/tools/usb/p9_fwd.py list

Bus | Addr | Manufacturer     | Product          | ID        | Path
--- | ---- | ---------------- | ---------------- | --------- | ----
  2 |   67 | unknown          | unknown          | 1d6b:0109 | 2-1.1.2
  2 |   68 | unknown          | unknown          | 1d6b:0109 | 2-1.1.3
```

Then start the python transport:



```text
$ python $kernel_dir/tools/usb/p9_fwd.py --path 2-1.1.2 connect -p 9999
```

After that the gadget driver can be used as described above.

One use-case is to use it as an alternative to NFS root booting during the development of embedded Linux devices.

<a id="rst-options"></a>

## Options

>
> <table>
> <tbody>
> <tr>
> <td>
>
>
> trans=name
>
> </td>
> <td>
>
>
> select an alternative transport.  Valid options are currently:
>
> >
> > <table>
> > <tbody>
> > <tr>
> > <td>
> >
> >
> > unix
> >
> > </td>
> > <td>
> >
> >
> > specifying a named pipe mount point
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > tcp
> >
> > </td>
> > <td>
> >
> >
> > specifying a normal TCP/IP connection
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > fd
> >
> > </td>
> > <td>
> >
> >
> > used passed file descriptors for connection (see rfdno and wfdno)
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > virtio
> >
> > </td>
> > <td>
> >
> >
> > connect to the next virtio channel available (from QEMU with trans_virtio module)
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > rdma
> >
> > </td>
> > <td>
> >
> >
> > connect to a specified RDMA channel
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > usbg
> >
> > </td>
> > <td>
> >
> >
> > connect to a specified usb gadget channel
> >
> > </td>
> > </tr>
> > </tbody>
> > </table>
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> uname=name
>
> </td>
> <td>
>
>
> user name to attempt mount as on the remote server.  The server may override or ignore this value.  Certain user names may require authentication.
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> aname=name
>
> </td>
> <td>
>
>
> aname specifies the file tree to access when the server is offering several exported file systems.
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> cache=mode
>
> </td>
> <td>
>
>
> specifies a caching policy.  By default, no caches are used. The mode can be specified as a bitmask or by using one of the preexisting common 'shortcuts'. The bitmask is described below: (unspecified bits are reserved)
>
> >
> > <table>
> > <tbody>
> > <tr>
> > <td>
> >
> >
> > 0b00000000
> >
> > </td>
> > <td>
> >
> >
> > all caches disabled, mmap disabled
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0b00000001
> >
> > </td>
> > <td>
> >
> >
> > file caches enabled
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0b00000010
> >
> > </td>
> > <td>
> >
> >
> > meta-data caches enabled
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0b00000100
> >
> > </td>
> > <td>
> >
> >
> > writeback behavior (as opposed to writethrough)
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0b00001000
> >
> > </td>
> > <td>
> >
> >
> > loose caches (no explicit consistency with server)
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0b10000000
> >
> > </td>
> > <td>
> >
> >
> > fscache enabled for persistent caching
> >
> > </td>
> > </tr>
> > </tbody>
> > </table>
>
> The current shortcuts and their associated bitmask are:
>
> >
> > <table>
> > <tbody>
> > <tr>
> > <td>
> >
> >
> > none
> >
> > </td>
> > <td>
> >
> >
> > 0b00000000 (no caching)
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > readahead
> >
> > </td>
> > <td>
> >
> >
> > 0b00000001 (only read-ahead file caching)
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > mmap
> >
> > </td>
> > <td>
> >
> >
> > 0b00000101 (read-ahead + writeback file cache)
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > loose
> >
> > </td>
> > <td>
> >
> >
> > 0b00001111 (non-coherent file and meta-data caches)
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > fscache
> >
> > </td>
> > <td>
> >
> >
> > 0b10001111 (persistent loose cache)
> >
> > </td>
> > </tr>
> > </tbody>
> > </table>
>
> NOTE: only these shortcuts are tested modes of operation at the moment, so using other combinations of bit-patterns is not known to work.  Work on better cache support is in progress.
>
> IMPORTANT: loose caches (and by extension at the moment fscache) do not necessarily validate cached values on the server.  In other words changes on the server are not guaranteed to be reflected on the client system.  Only use this mode of operation if you have an exclusive mount and the server will not modify the filesystem underneath you.
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> debug=n
>
> </td>
> <td>
>
>
> specifies debug level.  The debug level is a bitmask.
>
> >
> > <table>
> > <tbody>
> > <tr>
> > <td>
> >
> >
> > 0x01
> >
> > </td>
> > <td>
> >
> >
> > display verbose error messages
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x02
> >
> > </td>
> > <td>
> >
> >
> > developer debug (DEBUG_CURRENT)
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x04
> >
> > </td>
> > <td>
> >
> >
> > display 9p trace
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x08
> >
> > </td>
> > <td>
> >
> >
> > display VFS trace
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x10
> >
> > </td>
> > <td>
> >
> >
> > display Marshalling debug
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x20
> >
> > </td>
> > <td>
> >
> >
> > display RPC debug
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x40
> >
> > </td>
> > <td>
> >
> >
> > display transport debug
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x80
> >
> > </td>
> > <td>
> >
> >
> > display allocation debug
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x100
> >
> > </td>
> > <td>
> >
> >
> > display protocol message debug
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x200
> >
> > </td>
> > <td>
> >
> >
> > display Fid debug
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x400
> >
> > </td>
> > <td>
> >
> >
> > display packet debug
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 0x800
> >
> > </td>
> > <td>
> >
> >
> > display fscache tracing debug
> >
> > </td>
> > </tr>
> > </tbody>
> > </table>
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> rfdno=n
>
> </td>
> <td>
>
>
> the file descriptor for reading with trans=fd
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> wfdno=n
>
> </td>
> <td>
>
>
> the file descriptor for writing with trans=fd
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> msize=n
>
> </td>
> <td>
>
>
> the number of bytes to use for 9p packet payload
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> port=n
>
> </td>
> <td>
>
>
> port to connect to on the remote server
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> noextend
>
> </td>
> <td>
>
>
> force legacy mode (no 9p2000.u or 9p2000.L semantics)
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> version=name
>
> </td>
> <td>
>
>
> Select 9P protocol version. Valid options are:
>
> >
> > <table>
> > <tbody>
> > <tr>
> > <td>
> >
> >
> > 9p2000
> >
> > </td>
> > <td>
> >
> >
> > Legacy mode (same as noextend)
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 9p2000.u
> >
> > </td>
> > <td>
> >
> >
> > Use 9P2000.u protocol
> >
> > </td>
> > </tr>
> > <tr>
> > <td>
> >
> >
> > 9p2000.L
> >
> > </td>
> > <td>
> >
> >
> > Use 9P2000.L protocol
> >
> > </td>
> > </tr>
> > </tbody>
> > </table>
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> dfltuid
>
> </td>
> <td>
>
>
> attempt to mount as a particular uid
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> dfltgid
>
> </td>
> <td>
>
>
> attempt to mount with a particular gid
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> afid
>
> </td>
> <td>
>
>
> security channel - used by Plan 9 authentication protocols
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> nodevmap
>
> </td>
> <td>
>
>
> do not map special files - represent them as normal files. This can be used to share devices/named pipes/sockets between hosts.  This functionality will be expanded in later versions.
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> directio
>
> </td>
> <td>
>
>
> bypass page cache on all read/write operations
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> ignoreqv
>
> </td>
> <td>
>
>
> ignore qid.version==0 as a marker to ignore cache
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> noxattr
>
> </td>
> <td>
>
>
> do not offer xattr functions on this mount.
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> access
>
> </td>
> <td>
>
>
> - **there are four access modes.**
>
>   - **user**
>
>     if a user tries to access a file on v9fs filesystem for the first time, v9fs sends an attach command (Tattach) for that user. This is the default mode.
>
>   - **&lt;uid&gt;**
>
>     allows only user with uid=&lt;uid&gt; to access the files on the mounted filesystem
>
>   - **any**
>
>     v9fs does single attach and performs all operations as one user
>
>   - **clien**
>
>     ACL based access check on the 9p client side for access validation
>
> </td>
> </tr>
> <tr>
> <td>
>
>
> cachetag
>
> </td>
> <td>
>
>
> cache tag to use the specified persistent cache. cache tags for existing cache sessions can be listed at /sys/fs/9p/caches. (applies only to cache=fscache)
>
> </td>
> </tr>
> </tbody>
> </table>

<a id="rst-behavior"></a>

## Behavior

This section aims at describing 9p 'quirks' that can be different from a local filesystem behaviors.

> - Setting O_NONBLOCK on a file will make client reads return as early as the server returns some data instead of trying to fill the read buffer with the requested amount of bytes or end of file is reached.

<a id="rst-resources"></a>

## Resources

Protocol specifications are maintained on github: [http://ericvh.github.com/9p-rfc/](<http://ericvh.github.com/9p-rfc/>)

9p client and server implementations are listed on [http://9p.cat-v.org/implementations](<http://9p.cat-v.org/implementations>)

A 9p2000.L server is being developed by LLNL and can be found at [http://code.google.com/p/diod/](<http://code.google.com/p/diod/>)

There are user and developer mailing lists available through the v9fs project on sourceforge ([http://sourceforge.net/projects/v9fs](<http://sourceforge.net/projects/v9fs>)).

News and other information is maintained on a Wiki. ([http://sf.net/apps/mediawiki/v9fs/index.php](<http://sf.net/apps/mediawiki/v9fs/index.php>)).

Bug reports are best issued via the mailing list.

For more information on the Plan 9 Operating System check out [http://plan9.bell-labs.com/plan9](<http://plan9.bell-labs.com/plan9>)

For information on Plan 9 from User Space (Plan 9 applications and libraries ported to Linux/BSD/OSX/etc) check out [https://9fans.github.io/plan9port/](<https://9fans.github.io/plan9port/>)
