Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/puffs/mount_9p mount_9p: enable to communicate with...



details:   https://anonhg.NetBSD.org/src/rev/83b71b8ba40c
branches:  trunk
changeset: 460559:83b71b8ba40c
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Mon Oct 28 02:59:25 2019 +0000

description:
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.

diffstat:

 usr.sbin/puffs/mount_9p/mount_9p.8  |  30 ++++++++++++++++++++++--
 usr.sbin/puffs/mount_9p/ninebuf.c   |   6 ++--
 usr.sbin/puffs/mount_9p/ninepuffs.c |  45 ++++++++++++++++++++++++++++++++----
 usr.sbin/puffs/mount_9p/ninepuffs.h |   5 +++-
 4 files changed, 73 insertions(+), 13 deletions(-)

diffs (236 lines):

diff -r 177410207355 -r 83b71b8ba40c usr.sbin/puffs/mount_9p/mount_9p.8
--- a/usr.sbin/puffs/mount_9p/mount_9p.8        Mon Oct 28 02:56:40 2019 +0000
+++ b/usr.sbin/puffs/mount_9p/mount_9p.8        Mon Oct 28 02:59:25 2019 +0000
@@ -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 @@
 .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 @@
 .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 @@
 .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 -r 177410207355 -r 83b71b8ba40c usr.sbin/puffs/mount_9p/ninebuf.c
--- a/usr.sbin/puffs/mount_9p/ninebuf.c Mon Oct 28 02:56:40 2019 +0000
+++ b/usr.sbin/puffs/mount_9p/ninebuf.c Mon Oct 28 02:59:25 2019 +0000
@@ -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 @@
                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 -r 177410207355 -r 83b71b8ba40c usr.sbin/puffs/mount_9p/ninepuffs.c
--- a/usr.sbin/puffs/mount_9p/ninepuffs.c       Mon Oct 28 02:56:40 2019 +0000
+++ b/usr.sbin/puffs/mount_9p/ninepuffs.c       Mon Oct 28 02:59:25 2019 +0000
@@ -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 @@
 
        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 @@
 {
        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 @@
        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 @@
        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 @@
        unsigned short port;
        int mntflags, pflags, ch;
        int detach;
-       int protover = P9PROTO_VERSION;
+       int protover;
+       int server;
 
        setprogname(argv[0]);
 
@@ -118,9 +137,14 @@
        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 @@
                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 @@
 
        if (puffs_mainloop(pu) == -1)
                err(1, "mainloop");
+       close(p9p.servsock);
+       puffs_exit(pu, 1);
 
        return 0;
 }
diff -r 177410207355 -r 83b71b8ba40c usr.sbin/puffs/mount_9p/ninepuffs.h
--- a/usr.sbin/puffs/mount_9p/ninepuffs.h       Mon Oct 28 02:56:40 2019 +0000
+++ b/usr.sbin/puffs/mount_9p/ninepuffs.h       Mon Oct 28 02:59:25 2019 +0000
@@ -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 @@
        size_t maxreq;          /* negotiated with server */
 
        int protover;
+       int server;
+#define P9P_SERVER_TCP         0
+#define P9P_SERVER_CDEV                1
 };
 
 struct dirfid {



Home | Main Index | Thread Index | Old Index