Module Name: src Committed By: ozaki-r Date: Mon Oct 28 02:59:25 UTC 2019
Modified Files: src/usr.sbin/puffs/mount_9p: mount_9p.8 ninebuf.c ninepuffs.c ninepuffs.h Log Message: mount_9p: enable to communicate with vio9p via its character device file With this feature, we can mount an exported filesystem by a VM host via virtio-9p. To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/puffs/mount_9p/mount_9p.8 cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/puffs/mount_9p/ninebuf.c cvs rdiff -u -r1.26 -r1.27 src/usr.sbin/puffs/mount_9p/ninepuffs.c cvs rdiff -u -r1.14 -r1.15 src/usr.sbin/puffs/mount_9p/ninepuffs.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/puffs/mount_9p/mount_9p.8 diff -u src/usr.sbin/puffs/mount_9p/mount_9p.8:1.10 src/usr.sbin/puffs/mount_9p/mount_9p.8:1.11 --- src/usr.sbin/puffs/mount_9p/mount_9p.8:1.10 Fri Jun 7 05:34:34 2019 +++ src/usr.sbin/puffs/mount_9p/mount_9p.8 Mon Oct 28 02:59:25 2019 @@ -1,4 +1,4 @@ -.\" $NetBSD: mount_9p.8,v 1.10 2019/06/07 05:34:34 ozaki-r Exp $ +.\" $NetBSD: mount_9p.8,v 1.11 2019/10/28 02:59:25 ozaki-r Exp $ .\" .\" Copyright (c) 2007 Antti Kantee. All rights reserved. .\" @@ -23,7 +23,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd June 7, 2019 +.Dd October 24, 2019 .Dt MOUNT_9P 8 .Os .Sh NAME @@ -36,6 +36,12 @@ .Op Fl p Ar port .Ar [user@]host[:path] .Ar mount_point +.Nm +.Fl c +.Op Fl su +.Op Fl o Ar mntopts +.Ar devfile +.Ar mount_point .Sh DESCRIPTION The .Nm @@ -52,6 +58,18 @@ is supplied, it is used as the mount roo .Ar path must be an absolute path. .Pp +The +.Fl c +opiton enables to mount a filesystem exported by a VM host through +a character device file +.Ar devfile +backed by the +.Xr vio9p 4 +driver. +See +.Xr vio9p 4 +for more information. +.Pp By default .Nm runs in the background with @@ -74,7 +92,8 @@ environments. .Sh SEE ALSO .Xr puffs 3 , .Xr puffs 4 , -.Xr mount 8 +.Xr mount 8 , +.Xr vio9p 4 .Rs .%T RFC and standards documents relating the 9P protocol .%U http://ericvh.github.io/9p-rfc/ @@ -87,6 +106,11 @@ utility first appeared in .Pp Experimental 9P2000.u support appeared in .Nx 9.0 . +.Pp +The +.Fl c +option appeared in +.Nx 10.0 . .Sh CAVEATS Permissions are not handled well. .Pp Index: src/usr.sbin/puffs/mount_9p/ninebuf.c diff -u src/usr.sbin/puffs/mount_9p/ninebuf.c:1.8 src/usr.sbin/puffs/mount_9p/ninebuf.c:1.9 --- src/usr.sbin/puffs/mount_9p/ninebuf.c:1.8 Sun Nov 4 22:38:19 2012 +++ src/usr.sbin/puffs/mount_9p/ninebuf.c Mon Oct 28 02:59:25 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ninebuf.c,v 1.8 2012/11/04 22:38:19 christos Exp $ */ +/* $NetBSD: ninebuf.c,v 1.9 2019/10/28 02:59:25 ozaki-r Exp $ */ /* * Copyright (c) 2006, 2007 Antti Kantee. All Rights Reserved. @@ -27,7 +27,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: ninebuf.c,v 1.8 2012/11/04 22:38:19 christos Exp $"); +__RCSID("$NetBSD: ninebuf.c,v 1.9 2019/10/28 02:59:25 ozaki-r Exp $"); #endif /* !lint */ #include <sys/types.h> @@ -138,7 +138,7 @@ p9pbuf_write(struct puffs_usermount *pu, winlen = howmuch; if (puffs_framebuf_getwindow(pb, CUROFF(pb), &win, &winlen)==-1) return errno; - n = send(fd, win, winlen, MSG_NOSIGNAL); + n = write(fd, win, winlen); switch (n) { case 0: return ECONNRESET; Index: src/usr.sbin/puffs/mount_9p/ninepuffs.c diff -u src/usr.sbin/puffs/mount_9p/ninepuffs.c:1.26 src/usr.sbin/puffs/mount_9p/ninepuffs.c:1.27 --- src/usr.sbin/puffs/mount_9p/ninepuffs.c:1.26 Mon May 20 08:55:31 2019 +++ src/usr.sbin/puffs/mount_9p/ninepuffs.c Mon Oct 28 02:59:25 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ninepuffs.c,v 1.26 2019/05/20 08:55:31 ozaki-r Exp $ */ +/* $NetBSD: ninepuffs.c,v 1.27 2019/10/28 02:59:25 ozaki-r Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: ninepuffs.c,v 1.26 2019/05/20 08:55:31 ozaki-r Exp $"); +__RCSID("$NetBSD: ninepuffs.c,v 1.27 2019/10/28 02:59:25 ozaki-r Exp $"); #endif /* !lint */ #include <sys/types.h> @@ -60,6 +60,8 @@ usage(void) fprintf(stderr, "usage: %s [-su] [-o mntopts] [-p port] " "[user@]server[:path] mountpoint\n", getprogname()); + fprintf(stderr, " %s -c [-su] [-o mntopts] devfile mountpoint\n", + getprogname()); exit(1); } @@ -72,7 +74,7 @@ serverconnect(const char *addr, unsigned { struct sockaddr_in mysin; struct hostent *he; - int s; + int s, ret, opt; he = gethostbyname2(addr, AF_INET); if (he == NULL) { @@ -84,6 +86,11 @@ serverconnect(const char *addr, unsigned if (s == -1) err(1, "socket"); + opt = 1; + ret = setsockopt(s, SOL_SOCKET, SO_NOSIGPIPE, &opt, sizeof(opt)); + if (ret == -1) + err(1, "setsockopt(SO_NOSIGPIPE)"); + memset(&mysin, 0, sizeof(struct sockaddr_in)); mysin.sin_family = AF_INET; mysin.sin_port = htons(port); @@ -95,6 +102,17 @@ serverconnect(const char *addr, unsigned return s; } +static int +open_cdev(const char *path) +{ + int s; + + s = open(path, O_RDWR, 0); + if (s == -1) + err(1, "%s", path); + return s; +} + int main(int argc, char *argv[]) { @@ -108,7 +126,8 @@ main(int argc, char *argv[]) unsigned short port; int mntflags, pflags, ch; int detach; - int protover = P9PROTO_VERSION; + int protover; + int server; setprogname(argv[0]); @@ -118,9 +137,14 @@ main(int argc, char *argv[]) mntflags = pflags = 0; detach = 1; port = DEFPORT_9P; + protover = P9PROTO_VERSION; + server = P9P_SERVER_TCP; - while ((ch = getopt(argc, argv, "o:p:su")) != -1) { + while ((ch = getopt(argc, argv, "co:p:su")) != -1) { switch (ch) { + case 'c': + server = P9P_SERVER_CDEV; + break; case 'o': mp = getmntopts(optarg, puffsmopts, &mntflags, &pflags); if (mp == NULL) @@ -209,8 +233,15 @@ main(int argc, char *argv[]) srvpath = "/"; } - p9p.servsock = serverconnect(srvhost, port); + if (server == P9P_SERVER_TCP) { + p9p.servsock = serverconnect(srvhost, port); + } else { + /* path to a viop9fs chardev file, e.g., /dev/viop9fs0 */ + p9p.servsock = open_cdev(argv[0]); + } + if ((pn_root = p9p_handshake(pu, user, srvpath)) == NULL) { + close(p9p.servsock); puffs_exit(pu, 1); exit(1); } @@ -232,6 +263,8 @@ main(int argc, char *argv[]) if (puffs_mainloop(pu) == -1) err(1, "mainloop"); + close(p9p.servsock); + puffs_exit(pu, 1); return 0; } Index: src/usr.sbin/puffs/mount_9p/ninepuffs.h diff -u src/usr.sbin/puffs/mount_9p/ninepuffs.h:1.14 src/usr.sbin/puffs/mount_9p/ninepuffs.h:1.15 --- src/usr.sbin/puffs/mount_9p/ninepuffs.h:1.14 Fri Jun 7 05:34:34 2019 +++ src/usr.sbin/puffs/mount_9p/ninepuffs.h Mon Oct 28 02:59:25 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: ninepuffs.h,v 1.14 2019/06/07 05:34:34 ozaki-r Exp $ */ +/* $NetBSD: ninepuffs.h,v 1.15 2019/10/28 02:59:25 ozaki-r Exp $ */ /* * Copyright (c) 2007 Antti Kantee. All Rights Reserved. @@ -105,6 +105,9 @@ struct puffs9p { size_t maxreq; /* negotiated with server */ int protover; + int server; +#define P9P_SERVER_TCP 0 +#define P9P_SERVER_CDEV 1 }; struct dirfid {