107d241fdSMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0 207d241fdSMauro Carvalho Chehab 307d241fdSMauro Carvalho Chehab======================================= 407d241fdSMauro Carvalho Chehabv9fs: Plan 9 Resource Sharing for Linux 507d241fdSMauro Carvalho Chehab======================================= 607d241fdSMauro Carvalho Chehab 707d241fdSMauro Carvalho ChehabAbout 807d241fdSMauro Carvalho Chehab===== 907d241fdSMauro Carvalho Chehab 1007d241fdSMauro Carvalho Chehabv9fs is a Unix implementation of the Plan 9 9p remote filesystem protocol. 1107d241fdSMauro Carvalho Chehab 1207d241fdSMauro Carvalho ChehabThis software was originally developed by Ron Minnich <rminnich@sandia.gov> 1307d241fdSMauro Carvalho Chehaband Maya Gokhale. Additional development by Greg Watson 1407d241fdSMauro Carvalho Chehab<gwatson@lanl.gov> and most recently Eric Van Hensbergen 1507d241fdSMauro Carvalho Chehab<ericvh@gmail.com>, Latchesar Ionkov <lucho@ionkov.net> and Russ Cox 1607d241fdSMauro Carvalho Chehab<rsc@swtch.com>. 1707d241fdSMauro Carvalho Chehab 1807d241fdSMauro Carvalho ChehabThe best detailed explanation of the Linux implementation and applications of 1907d241fdSMauro Carvalho Chehabthe 9p client is available in the form of a USENIX paper: 2007d241fdSMauro Carvalho Chehab 210f540b95SAlexander A. Klimov https://www.usenix.org/events/usenix05/tech/freenix/hensbergen.html 2207d241fdSMauro Carvalho Chehab 2307d241fdSMauro Carvalho ChehabOther applications are described in the following papers: 2407d241fdSMauro Carvalho Chehab 2507d241fdSMauro Carvalho Chehab * XCPU & Clustering 2607d241fdSMauro Carvalho Chehab http://xcpu.org/papers/xcpu-talk.pdf 2707d241fdSMauro Carvalho Chehab * KVMFS: control file system for KVM 2807d241fdSMauro Carvalho Chehab http://xcpu.org/papers/kvmfs.pdf 2907d241fdSMauro Carvalho Chehab * CellFS: A New Programming Model for the Cell BE 3007d241fdSMauro Carvalho Chehab http://xcpu.org/papers/cellfs-talk.pdf 3107d241fdSMauro Carvalho Chehab * PROSE I/O: Using 9p to enable Application Partitions 3207d241fdSMauro Carvalho Chehab http://plan9.escet.urjc.es/iwp9/cready/PROSE_iwp9_2006.pdf 3307d241fdSMauro Carvalho Chehab * VirtFS: A Virtualization Aware File System pass-through 34f92a24aeSDr. David Alan Gilbert https://kernel.org/doc/ols/2010/ols2010-pages-109-120.pdf 3507d241fdSMauro Carvalho Chehab 3607d241fdSMauro Carvalho ChehabUsage 3707d241fdSMauro Carvalho Chehab===== 3807d241fdSMauro Carvalho Chehab 3907d241fdSMauro Carvalho ChehabFor remote file server:: 4007d241fdSMauro Carvalho Chehab 4107d241fdSMauro Carvalho Chehab mount -t 9p 10.10.1.2 /mnt/9 4207d241fdSMauro Carvalho Chehab 4307d241fdSMauro Carvalho ChehabFor Plan 9 From User Space applications (http://swtch.com/plan9):: 4407d241fdSMauro Carvalho Chehab 4507d241fdSMauro Carvalho Chehab mount -t 9p `namespace`/acme /mnt/9 -o trans=unix,uname=$USER 4607d241fdSMauro Carvalho Chehab 4707d241fdSMauro Carvalho ChehabFor server running on QEMU host with virtio transport:: 4807d241fdSMauro Carvalho Chehab 4907d241fdSMauro Carvalho Chehab mount -t 9p -o trans=virtio <mount_tag> /mnt/9 5007d241fdSMauro Carvalho Chehab 51a3be076dSMichael Grzeschikwhere mount_tag is the tag generated by the server to each of the exported 5207d241fdSMauro Carvalho Chehabmount points. Each 9P export is seen by the client as a virtio device with an 5307d241fdSMauro Carvalho Chehabassociated "mount_tag" property. Available mount tags can be 5407d241fdSMauro Carvalho Chehabseen by reading /sys/bus/virtio/drivers/9pnet_virtio/virtio<n>/mount_tag files. 5507d241fdSMauro Carvalho Chehab 56a3be076dSMichael GrzeschikUSBG Usage 57a3be076dSMichael Grzeschik========== 58a3be076dSMichael Grzeschik 59a3be076dSMichael GrzeschikTo mount a 9p FS on a USB Host accessible via the gadget at runtime:: 60a3be076dSMichael Grzeschik 61a3be076dSMichael Grzeschik mount -t 9p -o trans=usbg,aname=/path/to/fs <device> /mnt/9 62a3be076dSMichael Grzeschik 63a3be076dSMichael GrzeschikTo mount a 9p FS on a USB Host accessible via the gadget as root filesystem:: 64a3be076dSMichael Grzeschik 65a3be076dSMichael Grzeschik root=<device> rootfstype=9p rootflags=trans=usbg,cache=loose,uname=root,access=0,dfltuid=0,dfltgid=0,aname=/path/to/rootfs 66a3be076dSMichael Grzeschik 67a3be076dSMichael Grzeschikwhere <device> is the tag associated by the usb gadget transport. 68a3be076dSMichael GrzeschikIt is defined by the configfs instance name. 69a3be076dSMichael Grzeschik 70673f0c3fSMichael GrzeschikUSBG Example 71673f0c3fSMichael Grzeschik============ 72673f0c3fSMichael Grzeschik 73673f0c3fSMichael GrzeschikThe USB host exports a filesystem, while the gadget on the USB device 74673f0c3fSMichael Grzeschikside makes it mountable. 75673f0c3fSMichael Grzeschik 76673f0c3fSMichael GrzeschikDiod (9pfs server) and the forwarder are on the development host, where 77673f0c3fSMichael Grzeschikthe root filesystem is actually stored. The gadget is initialized during 78673f0c3fSMichael Grzeschikboot (or later) on the embedded board. Then the forwarder will find it 79673f0c3fSMichael Grzeschikon the USB bus and start forwarding requests. 80673f0c3fSMichael Grzeschik 81673f0c3fSMichael GrzeschikIn this case the 9p requests come from the device and are handled by the 82673f0c3fSMichael Grzeschikhost. The reason is that USB device ports are normally not available on 83673f0c3fSMichael GrzeschikPCs, so a connection in the other direction would not work. 84673f0c3fSMichael Grzeschik 85673f0c3fSMichael GrzeschikWhen using the usbg transport, for now there is no native usb host 86673f0c3fSMichael Grzeschikservice capable to handle the requests from the gadget driver. For 87673f0c3fSMichael Grzeschikthis we have to use the extra python tool p9_fwd.py from tools/usb. 88673f0c3fSMichael Grzeschik 89*0088d758SBagas SanjayaJust start the 9pfs capable network server like diod/nfs-ganesha e.g.:: 90673f0c3fSMichael Grzeschik 91673f0c3fSMichael Grzeschik $ diod -f -n -d 0 -S -l 0.0.0.0:9999 -e $PWD 92673f0c3fSMichael Grzeschik 93*0088d758SBagas SanjayaOptionaly scan your bus if there are more then one usbg gadgets to find their path:: 94673f0c3fSMichael Grzeschik 95673f0c3fSMichael Grzeschik $ python $kernel_dir/tools/usb/p9_fwd.py list 96673f0c3fSMichael Grzeschik 97673f0c3fSMichael Grzeschik Bus | Addr | Manufacturer | Product | ID | Path 98673f0c3fSMichael Grzeschik --- | ---- | ---------------- | ---------------- | --------- | ---- 99673f0c3fSMichael Grzeschik 2 | 67 | unknown | unknown | 1d6b:0109 | 2-1.1.2 100673f0c3fSMichael Grzeschik 2 | 68 | unknown | unknown | 1d6b:0109 | 2-1.1.3 101673f0c3fSMichael Grzeschik 102*0088d758SBagas SanjayaThen start the python transport:: 103673f0c3fSMichael Grzeschik 104673f0c3fSMichael Grzeschik $ python $kernel_dir/tools/usb/p9_fwd.py --path 2-1.1.2 connect -p 9999 105673f0c3fSMichael Grzeschik 106673f0c3fSMichael GrzeschikAfter that the gadget driver can be used as described above. 107673f0c3fSMichael Grzeschik 108673f0c3fSMichael GrzeschikOne use-case is to use it as an alternative to NFS root booting during 109673f0c3fSMichael Grzeschikthe development of embedded Linux devices. 110673f0c3fSMichael Grzeschik 11107d241fdSMauro Carvalho ChehabOptions 11207d241fdSMauro Carvalho Chehab======= 11307d241fdSMauro Carvalho Chehab 11407d241fdSMauro Carvalho Chehab ============= =============================================================== 11507d241fdSMauro Carvalho Chehab trans=name select an alternative transport. Valid options are 11607d241fdSMauro Carvalho Chehab currently: 11707d241fdSMauro Carvalho Chehab 11807d241fdSMauro Carvalho Chehab ======== ============================================ 11907d241fdSMauro Carvalho Chehab unix specifying a named pipe mount point 12007d241fdSMauro Carvalho Chehab tcp specifying a normal TCP/IP connection 12107d241fdSMauro Carvalho Chehab fd used passed file descriptors for connection 12207d241fdSMauro Carvalho Chehab (see rfdno and wfdno) 12307d241fdSMauro Carvalho Chehab virtio connect to the next virtio channel available 12407d241fdSMauro Carvalho Chehab (from QEMU with trans_virtio module) 12507d241fdSMauro Carvalho Chehab rdma connect to a specified RDMA channel 126a3be076dSMichael Grzeschik usbg connect to a specified usb gadget channel 12707d241fdSMauro Carvalho Chehab ======== ============================================ 12807d241fdSMauro Carvalho Chehab 12907d241fdSMauro Carvalho Chehab uname=name user name to attempt mount as on the remote server. The 13007d241fdSMauro Carvalho Chehab server may override or ignore this value. Certain user 13107d241fdSMauro Carvalho Chehab names may require authentication. 13207d241fdSMauro Carvalho Chehab 13307d241fdSMauro Carvalho Chehab aname=name aname specifies the file tree to access when the server is 13407d241fdSMauro Carvalho Chehab offering several exported file systems. 13507d241fdSMauro Carvalho Chehab 13607d241fdSMauro Carvalho Chehab cache=mode specifies a caching policy. By default, no caches are used. 1374eb31178SEric Van Hensbergen The mode can be specified as a bitmask or by using one of the 138d56b699dSBjorn Helgaas preexisting common 'shortcuts'. 1394eb31178SEric Van Hensbergen The bitmask is described below: (unspecified bits are reserved) 14007d241fdSMauro Carvalho Chehab 1414eb31178SEric Van Hensbergen ========== ==================================================== 1424eb31178SEric Van Hensbergen 0b00000000 all caches disabled, mmap disabled 1434eb31178SEric Van Hensbergen 0b00000001 file caches enabled 1444eb31178SEric Van Hensbergen 0b00000010 meta-data caches enabled 1454eb31178SEric Van Hensbergen 0b00000100 writeback behavior (as opposed to writethrough) 1464eb31178SEric Van Hensbergen 0b00001000 loose caches (no explicit consistency with server) 1474eb31178SEric Van Hensbergen 0b10000000 fscache enabled for persistent caching 1484eb31178SEric Van Hensbergen ========== ==================================================== 1494eb31178SEric Van Hensbergen 1504eb31178SEric Van Hensbergen The current shortcuts and their associated bitmask are: 1514eb31178SEric Van Hensbergen 1524eb31178SEric Van Hensbergen ========= ==================================================== 1534eb31178SEric Van Hensbergen none 0b00000000 (no caching) 1544eb31178SEric Van Hensbergen readahead 0b00000001 (only read-ahead file caching) 1554eb31178SEric Van Hensbergen mmap 0b00000101 (read-ahead + writeback file cache) 1564eb31178SEric Van Hensbergen loose 0b00001111 (non-coherent file and meta-data caches) 1574eb31178SEric Van Hensbergen fscache 0b10001111 (persistent loose cache) 1584eb31178SEric Van Hensbergen ========= ==================================================== 1594eb31178SEric Van Hensbergen 1604eb31178SEric Van Hensbergen NOTE: only these shortcuts are tested modes of operation at the 1614eb31178SEric Van Hensbergen moment, so using other combinations of bit-patterns is not 1624eb31178SEric Van Hensbergen known to work. Work on better cache support is in progress. 1634eb31178SEric Van Hensbergen 1644eb31178SEric Van Hensbergen IMPORTANT: loose caches (and by extension at the moment fscache) 1654eb31178SEric Van Hensbergen do not necessarily validate cached values on the server. In other 1664eb31178SEric Van Hensbergen words changes on the server are not guaranteed to be reflected 1674eb31178SEric Van Hensbergen on the client system. Only use this mode of operation if you 1684eb31178SEric Van Hensbergen have an exclusive mount and the server will modify the filesystem 1694eb31178SEric Van Hensbergen underneath you. 17007d241fdSMauro Carvalho Chehab 17107d241fdSMauro Carvalho Chehab debug=n specifies debug level. The debug level is a bitmask. 17207d241fdSMauro Carvalho Chehab 17307d241fdSMauro Carvalho Chehab ===== ================================ 17407d241fdSMauro Carvalho Chehab 0x01 display verbose error messages 17507d241fdSMauro Carvalho Chehab 0x02 developer debug (DEBUG_CURRENT) 17607d241fdSMauro Carvalho Chehab 0x04 display 9p trace 17707d241fdSMauro Carvalho Chehab 0x08 display VFS trace 17807d241fdSMauro Carvalho Chehab 0x10 display Marshalling debug 17907d241fdSMauro Carvalho Chehab 0x20 display RPC debug 18007d241fdSMauro Carvalho Chehab 0x40 display transport debug 18107d241fdSMauro Carvalho Chehab 0x80 display allocation debug 18207d241fdSMauro Carvalho Chehab 0x100 display protocol message debug 18307d241fdSMauro Carvalho Chehab 0x200 display Fid debug 18407d241fdSMauro Carvalho Chehab 0x400 display packet debug 18507d241fdSMauro Carvalho Chehab 0x800 display fscache tracing debug 18607d241fdSMauro Carvalho Chehab ===== ================================ 18707d241fdSMauro Carvalho Chehab 18807d241fdSMauro Carvalho Chehab rfdno=n the file descriptor for reading with trans=fd 18907d241fdSMauro Carvalho Chehab 19007d241fdSMauro Carvalho Chehab wfdno=n the file descriptor for writing with trans=fd 19107d241fdSMauro Carvalho Chehab 19207d241fdSMauro Carvalho Chehab msize=n the number of bytes to use for 9p packet payload 19307d241fdSMauro Carvalho Chehab 19407d241fdSMauro Carvalho Chehab port=n port to connect to on the remote server 19507d241fdSMauro Carvalho Chehab 19607d241fdSMauro Carvalho Chehab noextend force legacy mode (no 9p2000.u or 9p2000.L semantics) 19707d241fdSMauro Carvalho Chehab 19807d241fdSMauro Carvalho Chehab version=name Select 9P protocol version. Valid options are: 19907d241fdSMauro Carvalho Chehab 20007d241fdSMauro Carvalho Chehab ======== ============================== 20107d241fdSMauro Carvalho Chehab 9p2000 Legacy mode (same as noextend) 20207d241fdSMauro Carvalho Chehab 9p2000.u Use 9P2000.u protocol 20307d241fdSMauro Carvalho Chehab 9p2000.L Use 9P2000.L protocol 20407d241fdSMauro Carvalho Chehab ======== ============================== 20507d241fdSMauro Carvalho Chehab 20607d241fdSMauro Carvalho Chehab dfltuid attempt to mount as a particular uid 20707d241fdSMauro Carvalho Chehab 20807d241fdSMauro Carvalho Chehab dfltgid attempt to mount with a particular gid 20907d241fdSMauro Carvalho Chehab 21007d241fdSMauro Carvalho Chehab afid security channel - used by Plan 9 authentication protocols 21107d241fdSMauro Carvalho Chehab 21207d241fdSMauro Carvalho Chehab nodevmap do not map special files - represent them as normal files. 21307d241fdSMauro Carvalho Chehab This can be used to share devices/named pipes/sockets between 21407d241fdSMauro Carvalho Chehab hosts. This functionality will be expanded in later versions. 21507d241fdSMauro Carvalho Chehab 2164eb31178SEric Van Hensbergen directio bypass page cache on all read/write operations 2174eb31178SEric Van Hensbergen 2184eb31178SEric Van Hensbergen ignoreqv ignore qid.version==0 as a marker to ignore cache 2194eb31178SEric Van Hensbergen 2208142db4fSEric Van Hensbergen noxattr do not offer xattr functions on this mount. 2218142db4fSEric Van Hensbergen 22207d241fdSMauro Carvalho Chehab access there are four access modes. 22307d241fdSMauro Carvalho Chehab user 22407d241fdSMauro Carvalho Chehab if a user tries to access a file on v9fs 22507d241fdSMauro Carvalho Chehab filesystem for the first time, v9fs sends an 22607d241fdSMauro Carvalho Chehab attach command (Tattach) for that user. 22707d241fdSMauro Carvalho Chehab This is the default mode. 22807d241fdSMauro Carvalho Chehab <uid> 22907d241fdSMauro Carvalho Chehab allows only user with uid=<uid> to access 23007d241fdSMauro Carvalho Chehab the files on the mounted filesystem 23107d241fdSMauro Carvalho Chehab any 23207d241fdSMauro Carvalho Chehab v9fs does single attach and performs all 23307d241fdSMauro Carvalho Chehab operations as one user 23407d241fdSMauro Carvalho Chehab clien 23507d241fdSMauro Carvalho Chehab ACL based access check on the 9p client 23607d241fdSMauro Carvalho Chehab side for access validation 23707d241fdSMauro Carvalho Chehab 23807d241fdSMauro Carvalho Chehab cachetag cache tag to use the specified persistent cache. 23907d241fdSMauro Carvalho Chehab cache tags for existing cache sessions can be listed at 24007d241fdSMauro Carvalho Chehab /sys/fs/9p/caches. (applies only to cache=fscache) 24107d241fdSMauro Carvalho Chehab ============= =============================================================== 24207d241fdSMauro Carvalho Chehab 2435d30bcacSLinus TorvaldsBehavior 2445d30bcacSLinus Torvalds======== 2455d30bcacSLinus Torvalds 2465d30bcacSLinus TorvaldsThis section aims at describing 9p 'quirks' that can be different 2475d30bcacSLinus Torvaldsfrom a local filesystem behaviors. 2485d30bcacSLinus Torvalds 2495d30bcacSLinus Torvalds - Setting O_NONBLOCK on a file will make client reads return as early 2505d30bcacSLinus Torvalds as the server returns some data instead of trying to fill the read 2515d30bcacSLinus Torvalds buffer with the requested amount of bytes or end of file is reached. 2525d30bcacSLinus Torvalds 25307d241fdSMauro Carvalho ChehabResources 25407d241fdSMauro Carvalho Chehab========= 25507d241fdSMauro Carvalho Chehab 25607d241fdSMauro Carvalho ChehabProtocol specifications are maintained on github: 25707d241fdSMauro Carvalho Chehabhttp://ericvh.github.com/9p-rfc/ 25807d241fdSMauro Carvalho Chehab 25907d241fdSMauro Carvalho Chehab9p client and server implementations are listed on 26007d241fdSMauro Carvalho Chehabhttp://9p.cat-v.org/implementations 26107d241fdSMauro Carvalho Chehab 26207d241fdSMauro Carvalho ChehabA 9p2000.L server is being developed by LLNL and can be found 26307d241fdSMauro Carvalho Chehabat http://code.google.com/p/diod/ 26407d241fdSMauro Carvalho Chehab 26507d241fdSMauro Carvalho ChehabThere are user and developer mailing lists available through the v9fs project 26607d241fdSMauro Carvalho Chehabon sourceforge (http://sourceforge.net/projects/v9fs). 26707d241fdSMauro Carvalho Chehab 26807d241fdSMauro Carvalho ChehabNews and other information is maintained on a Wiki. 26907d241fdSMauro Carvalho Chehab(http://sf.net/apps/mediawiki/v9fs/index.php). 27007d241fdSMauro Carvalho Chehab 27107d241fdSMauro Carvalho ChehabBug reports are best issued via the mailing list. 27207d241fdSMauro Carvalho Chehab 27307d241fdSMauro Carvalho ChehabFor more information on the Plan 9 Operating System check out 27407d241fdSMauro Carvalho Chehabhttp://plan9.bell-labs.com/plan9 27507d241fdSMauro Carvalho Chehab 27607d241fdSMauro Carvalho ChehabFor information on Plan 9 from User Space (Plan 9 applications and libraries 277b529c06fSJuan Manuel Méndez Reyported to Linux/BSD/OSX/etc) check out https://9fans.github.io/plan9port/ 278