Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Implement a front-end driver of virtio-9p called vio9p
details: https://anonhg.NetBSD.org/src/rev/177410207355
branches: trunk
changeset: 460558:177410207355
user: ozaki-r <ozaki-r%NetBSD.org@localhost>
date: Mon Oct 28 02:56:40 2019 +0000
description:
Implement a front-end driver of virtio-9p called vio9p
In conjunction with mount_9p, it enables a NetBSD system running as a VM guest
to mount an exported filesystem by the host via virtio-9p. It exports a 9p
end-point of virtio-9p via a character device file for mount_9p.
Reviewed by yamaguchi@
diffstat:
distrib/sets/lists/man/mi | 5 +-
share/man/man4/Makefile | 8 +-
share/man/man4/vio9p.4 | 70 ++++
sys/conf/majors | 3 +-
sys/dev/pci/files.virtio | 5 +-
sys/dev/pci/vio9p.c | 643 +++++++++++++++++++++++++++++++++++++++++
sys/modules/Makefile | 3 +-
sys/modules/vio9p/Makefile | 12 +
sys/modules/vio9p/vio9p.ioconf | 10 +
9 files changed, 751 insertions(+), 8 deletions(-)
diffs (truncated from 853 to 300 lines):
diff -r 4a8fb76dcb62 -r 177410207355 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Mon Oct 28 02:53:29 2019 +0000
+++ b/distrib/sets/lists/man/mi Mon Oct 28 02:56:40 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1658 2019/10/25 17:39:56 martin Exp $
+# $NetBSD: mi,v 1.1659 2019/10/28 02:56:40 ozaki-r Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -1990,6 +1990,7 @@
./usr/share/man/cat4/viapm.0 man-obsolete obsolete
./usr/share/man/cat4/video.0 man-sys-catman .cat
./usr/share/man/cat4/vinum.0 man-obsolete obsolete
+./usr/share/man/cat4/vio9p.0 man-sys-catman .cat
./usr/share/man/cat4/vioif.0 man-sys-catman .cat
./usr/share/man/cat4/viomb.0 man-sys-catman .cat
./usr/share/man/cat4/viornd.0 man-sys-catman .cat
@@ -5085,6 +5086,7 @@
./usr/share/man/html4/viaenv.html man-sys-htmlman html
./usr/share/man/html4/viaide.html man-sys-htmlman html
./usr/share/man/html4/video.html man-sys-htmlman html
+./usr/share/man/html4/vio9p.html man-sys-htmlman html
./usr/share/man/html4/vioif.html man-sys-htmlman html
./usr/share/man/html4/viomb.html man-sys-htmlman html
./usr/share/man/html4/viornd.html man-sys-htmlman html
@@ -8112,6 +8114,7 @@
./usr/share/man/man4/viapm.4 man-obsolete obsolete
./usr/share/man/man4/video.4 man-sys-man .man
./usr/share/man/man4/vinum.4 man-obsolete obsolete
+./usr/share/man/man4/vio9p.4 man-sys-man .man
./usr/share/man/man4/vioif.4 man-sys-man .man
./usr/share/man/man4/viomb.4 man-sys-man .man
./usr/share/man/man4/viornd.4 man-sys-man .man
diff -r 4a8fb76dcb62 -r 177410207355 share/man/man4/Makefile
--- a/share/man/man4/Makefile Mon Oct 28 02:53:29 2019 +0000
+++ b/share/man/man4/Makefile Mon Oct 28 02:56:40 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.685 2019/10/25 17:39:57 martin Exp $
+# $NetBSD: Makefile,v 1.686 2019/10/28 02:56:40 ozaki-r Exp $
# @(#)Makefile 8.1 (Berkeley) 6/18/93
MAN= aac.4 ac97.4 acardide.4 aceride.4 acphy.4 \
@@ -66,9 +66,9 @@
trm.4 tsllux.4 tty.4 tun.4 tqphy.4 twa.4 twe.4 txp.4 \
uark.4 ubsec.4 udp.4 uep.4 ug.4 uha.4 uk.4 ukphy.4 umb.4 \
unix.4 userconf.4 \
- vald.4 valz.4 veriexec.4 vga.4 vge.4 viaide.4 video.4 vioif.4 viomb.4 \
- viornd.4 vioscsi.4 virt.4 \
- virtio.4 vlan.4 vmmon.4 vmnet.4 vnd.4 voodoofb.4 vr.4 vte.4 \
+ vald.4 valz.4 veriexec.4 vga.4 vge.4 viaide.4 video.4 \
+ vio9p.4 vioif.4 viomb.4 viornd.4 vioscsi.4 virt.4 virtio.4 \
+ vlan.4 vmmon.4 vmnet.4 vnd.4 voodoofb.4 vr.4 vte.4 \
wapbl.4 wb.4 wbsio.4 wd.4 wdc.4 wi.4 wm.4 wpi.4 \
wsbell.4 wscons.4 wsdisplay.4 wsfont.4 wskbd.4 wsmouse.4 wsmux.4 \
xbox.4 xge.4 \
diff -r 4a8fb76dcb62 -r 177410207355 share/man/man4/vio9p.4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/share/man/man4/vio9p.4 Mon Oct 28 02:56:40 2019 +0000
@@ -0,0 +1,70 @@
+.\" $NetBSD: vio9p.4,v 1.1 2019/10/28 02:56:40 ozaki-r Exp $
+.\"
+.\" Copyright (c) 2019 Internet Initiative Japan, Inc.
+.\" All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+.\" POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd October 24, 2019
+.Dt VIO9P 4
+.Os
+.Sh NAME
+.Nm vio9p
+.Nd VirtIO 9p front-end driver
+.Sh SYNOPSIS
+.Cd "vio9p* at virtio?"
+.Sh DESCRIPTION
+In conjunction with
+.Xr mount_9p 8 , the
+.Nm
+driver enables a NetBSD system running as a VM guest to mount an exported filesystem
+by the host via virtio-9p.
+It exports a 9p end-point of virtio-9p via a character device file for
+.Xr mount_9p 8 .
+.Pp
+Each exported filesystem is assigned a character device and accesible via
+.Pa /dev/vio9p0 ,
+.Pa /dev/vio9p1
+and so on, respectively in exporting order by the host.
+.Sh FILES
+.Bl -tag -width XdevXvio9pX -compact
+.It Pa /dev/vio9p?
+.El
+.Sh EXAMPLES
+The following command mounts a first exported filesystem by the host at
+.Pa /mnt/9p :
+.Bd -literal -offset indent
+# mount_9p -cu /dev/vio9p0 /mnt/9p
+.Ed
+.Sh SEE ALSO
+.Xr mount_9p 8 ,
+.Xr virtio 4
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Nx 10.0 .
+.Sh AUTHORS
+The
+.Nm
+driver was written by
+.An Ryota Ozaki Aq Mt ozaki-r%iij.ad.jp@localhost .
diff -r 4a8fb76dcb62 -r 177410207355 sys/conf/majors
--- a/sys/conf/majors Mon Oct 28 02:53:29 2019 +0000
+++ b/sys/conf/majors Mon Oct 28 02:56:40 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: majors,v 1.89 2019/09/15 11:45:47 maxv Exp $
+# $NetBSD: majors,v 1.90 2019/10/28 02:56:40 ozaki-r Exp $
#
# Device majors for Machine-Independent drivers.
#
@@ -87,3 +87,4 @@
# Major 353 is reserved for external/cddl/osnet/dev/sdt/sdt.c
device-major ipmi char 354 ipmi
device-major vhci char 355 vhci
+device-major vio9p char 356 vio9p
diff -r 4a8fb76dcb62 -r 177410207355 sys/dev/pci/files.virtio
--- a/sys/dev/pci/files.virtio Mon Oct 28 02:53:29 2019 +0000
+++ b/sys/dev/pci/files.virtio Mon Oct 28 02:56:40 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.virtio,v 1.1 2017/08/02 08:39:14 cherry Exp $
+# $NetBSD: files.virtio,v 1.2 2019/10/28 02:56:40 ozaki-r Exp $
# VirtIO
device virtio {}
@@ -23,3 +23,6 @@
attach vioscsi at virtio
file dev/pci/vioscsi.c vioscsi
+device vio9p
+attach vio9p at virtio
+file dev/pci/vio9p.c vio9p
diff -r 4a8fb76dcb62 -r 177410207355 sys/dev/pci/vio9p.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/vio9p.c Mon Oct 28 02:56:40 2019 +0000
@@ -0,0 +1,643 @@
+/* $NetBSD: vio9p.c,v 1.1 2019/10/28 02:56:40 ozaki-r Exp $ */
+
+/*
+ * Copyright (c) 2019 Internet Initiative Japan, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: vio9p.c,v 1.1 2019/10/28 02:56:40 ozaki-r Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+#include <sys/conf.h>
+#include <sys/condvar.h>
+#include <sys/device.h>
+#include <sys/mutex.h>
+#include <sys/sysctl.h>
+#include <sys/module.h>
+#include <sys/syslog.h>
+#include <sys/select.h>
+#include <sys/kmem.h>
+
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/uio.h>
+
+#include <dev/pci/virtioreg.h>
+#include <dev/pci/virtiovar.h>
+
+#include "ioconf.h"
+
+//#define VIO9P_DEBUG 1
+//#define VIO9P_DUMP 1
+#ifdef VIO9P_DEBUG
+#define DLOG(fmt, args...) \
+ do { log(LOG_DEBUG, "%s: " fmt "\n", __func__, ##args); } while (0)
+#else
+#define DLOG(fmt, args...) __nothing
+#endif
+
+/* Configuration registers */
+#define VIO9P_CONFIG_TAG_LEN 0 /* 16bit */
+#define VIO9P_CONFIG_TAG 2
+
+#define VIO9P_FLAG_BITS VIRTIO_COMMON_FLAG_BITS
+
+// Must be the same as P9P_DEFREQLEN of usr.sbin/puffs/mount_9p/ninepuffs.h
+#define VIO9P_MAX_REQLEN (16 * 1024)
+#define VIO9P_SEGSIZE PAGE_SIZE
+#define VIO9P_N_SEGMENTS (VIO9P_MAX_REQLEN / VIO9P_SEGSIZE)
+
+#define P9_MAX_TAG_LEN 16
+
+CTASSERT((PAGE_SIZE) == (VIRTIO_PAGE_SIZE)); /* XXX */
+
+struct vio9p_softc {
+ device_t sc_dev;
+
+ struct virtio_softc *sc_virtio;
+ struct virtqueue sc_vq[1];
+
+ uint16_t sc_taglen;
+ uint8_t sc_tag[P9_MAX_TAG_LEN + 1];
+
+ int sc_flags;
+#define VIO9P_INUSE __BIT(0)
+
+ int sc_state;
+#define VIO9P_S_INIT 0
+#define VIO9P_S_REQUESTING 1
+#define VIO9P_S_REPLIED 2
+#define VIO9P_S_CONSUMING 3
+ kcondvar_t sc_wait;
+ struct selinfo sc_sel;
+ kmutex_t sc_lock;
+
+ bus_dmamap_t sc_dmamap_tx;
+ bus_dmamap_t sc_dmamap_rx;
+ char *sc_buf_tx;
+ char *sc_buf_rx;
+ size_t sc_buf_rx_len;
+ off_t sc_buf_rx_offset;
+};
+
+/*
+ * Locking notes:
+ * - sc_state, sc_wait and sc_sel are protected by sc_lock
+ *
+ * The state machine (sc_state):
+ * - INIT =(write from client)=> REQUESTING
+ * - REQUESTING =(reply from host)=> REPLIED
+ * - REPLIED =(read from client)=> CONSUMING
+ * - CONSUMING =(read completed(*))=> INIT
+ *
+ * (*) read may not finish by one read(2) request, then
+ * the state remains CONSUMING.
+ */
+
+static int vio9p_match(device_t, cfdata_t, void *);
+static void vio9p_attach(device_t, device_t, void *);
+static void vio9p_read_config(struct vio9p_softc *);
+static int vio9p_request_done(struct virtqueue *);
+
+static int vio9p_read(struct file *, off_t *, struct uio *, kauth_cred_t,
+ int);
+static int vio9p_write(struct file *, off_t *, struct uio *,
+ kauth_cred_t, int);
+static int vio9p_ioctl(struct file *, u_long, void *);
+static int vio9p_close(struct file *);
+static int vio9p_kqfilter(struct file *, struct knote *);
+
+static const struct fileops vio9p_fileops = {
+ .fo_name = "vio9p",
+ .fo_read = vio9p_read,
+ .fo_write = vio9p_write,
Home |
Main Index |
Thread Index |
Old Index