commit 37b42f3db0685561c7fcc12d6c9feca6df11b2f4 Author: Ryota Ozaki Date: Mon Aug 19 16:34:30 2019 +0900 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. diff --git a/usr.sbin/puffs/mount_9p/mount_9p.8 b/usr.sbin/puffs/mount_9p/mount_9p.8 index 6a7c15bfaa9..20f63627b43 100644 --- a/usr.sbin/puffs/mount_9p/mount_9p.8 +++ b/usr.sbin/puffs/mount_9p/mount_9p.8 @@ -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 rootpath on the remote host. .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 diff --git a/usr.sbin/puffs/mount_9p/ninebuf.c b/usr.sbin/puffs/mount_9p/ninebuf.c index a9fe6879cf3..7b0ba3f9084 100644 --- a/usr.sbin/puffs/mount_9p/ninebuf.c +++ b/usr.sbin/puffs/mount_9p/ninebuf.c @@ -138,7 +138,7 @@ p9pbuf_write(struct puffs_usermount *pu, struct puffs_framebuf *pb, 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; diff --git a/usr.sbin/puffs/mount_9p/ninepuffs.c b/usr.sbin/puffs/mount_9p/ninepuffs.c index e9a0550a5c1..49d2b21e780 100644 --- a/usr.sbin/puffs/mount_9p/ninepuffs.c +++ b/usr.sbin/puffs/mount_9p/ninepuffs.c @@ -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 short port) { 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 short port) 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 short port) return s; } +static int +open_cdev(const char *path) +{ + int s; + + s = open(path, O_RDWR, 0); + if (s == -1) + err(1, "open(%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; } diff --git a/usr.sbin/puffs/mount_9p/ninepuffs.h b/usr.sbin/puffs/mount_9p/ninepuffs.h index d8974d9a725..13dbd269312 100644 --- a/usr.sbin/puffs/mount_9p/ninepuffs.h +++ b/usr.sbin/puffs/mount_9p/ninepuffs.h @@ -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 {