svn commit: r321413 - stable/11/usr.sbin/bhyve
Alexander Motin
mav at FreeBSD.org
Mon Jul 24 06:19:06 UTC 2017
Author: mav
Date: Mon Jul 24 06:19:04 2017
New Revision: 321413
URL: https://svnweb.freebsd.org/changeset/base/321413
Log:
MFC r305898, r309120, r309121 (by jceel):
Add virtio-console support to bhyve.
Adds virtio-console device support to bhyve, allowing to create
bidirectional character streams between host and guest.
Syntax:
-s <slotnum>,virtio-console,port1=/path/to/port1.sock,anotherport=...
Maximum of 16 ports per device can be created. Every port is named
and corresponds to an Unix domain socket created by bhyve. bhyve
accepts at most one connection per port at a time.
Limitations:
- due to lack of destructors of in bhyve, sockets on the filesystem
must be cleaned up manually after bhyve exits
- there's no way to use "console port" feature, nor the console port
resize as of now
- emergency write is advertised, but no-op as of now
Added:
stable/11/usr.sbin/bhyve/pci_virtio_console.c
- copied, changed from r305898, head/usr.sbin/bhyve/pci_virtio_console.c
Modified:
stable/11/usr.sbin/bhyve/Makefile
stable/11/usr.sbin/bhyve/virtio.h
Directory Properties:
stable/11/ (props changed)
Modified: stable/11/usr.sbin/bhyve/Makefile
==============================================================================
--- stable/11/usr.sbin/bhyve/Makefile Mon Jul 24 06:07:44 2017 (r321412)
+++ stable/11/usr.sbin/bhyve/Makefile Mon Jul 24 06:19:04 2017 (r321413)
@@ -38,6 +38,7 @@ SRCS= \
pci_lpc.c \
pci_passthru.c \
pci_virtio_block.c \
+ pci_virtio_console.c \
pci_virtio_net.c \
pci_virtio_rnd.c \
pci_uart.c \
Copied and modified: stable/11/usr.sbin/bhyve/pci_virtio_console.c (from r305898, head/usr.sbin/bhyve/pci_virtio_console.c)
==============================================================================
--- head/usr.sbin/bhyve/pci_virtio_console.c Sat Sep 17 13:48:01 2016 (r305898, copy source)
+++ stable/11/usr.sbin/bhyve/pci_virtio_console.c Mon Jul 24 06:19:04 2017 (r321413)
@@ -53,6 +53,7 @@ __FBSDID("$FreeBSD$");
#include "pci_emul.h"
#include "virtio.h"
#include "mevent.h"
+#include "sockstream.h"
#define VTCON_RINGSZ 64
#define VTCON_MAXPORTS 16
@@ -90,6 +91,7 @@ struct pci_vtcon_port {
bool vsp_enabled;
bool vsp_console;
bool vsp_rx_ready;
+ bool vsp_open;
int vsp_rxq;
int vsp_txq;
void * vsp_arg;
@@ -116,6 +118,7 @@ struct pci_vtcon_softc {
char * vsc_rootdir;
int vsc_kq;
int vsc_nports;
+ bool vsc_ready;
struct pci_vtcon_port vsc_control_port;
struct pci_vtcon_port vsc_ports[VTCON_MAXPORTS];
struct pci_vtcon_config *vsc_config;
@@ -349,6 +352,7 @@ pci_vtcon_sock_accept(int fd __unused, enum ev_type t
sock->vss_open = true;
sock->vss_conn_fd = s;
sock->vss_conn_evp = mevent_add(s, EVF_READ, pci_vtcon_sock_rx, sock);
+
pci_vtcon_open_port(sock->vss_port, true);
}
@@ -412,16 +416,21 @@ pci_vtcon_sock_tx(struct pci_vtcon_port *port, void *a
int niov)
{
struct pci_vtcon_sock *sock;
- int ret;
+ int i, ret;
sock = (struct pci_vtcon_sock *)arg;
if (sock->vss_conn_fd == -1)
return;
- ret = writev(sock->vss_conn_fd, iov, niov);
+ for (i = 0; i < niov; i++) {
+ ret = stream_write(sock->vss_conn_fd, iov[i].iov_base,
+ iov[i].iov_len);
+ if (ret <= 0)
+ break;
+ }
- if (ret < 0 && errno != EWOULDBLOCK) {
+ if (ret <= 0) {
mevent_delete_close(sock->vss_conn_evp);
sock->vss_conn_fd = -1;
sock->vss_open = false;
@@ -444,11 +453,15 @@ pci_vtcon_control_tx(struct pci_vtcon_port *port, void
switch (ctrl->event) {
case VTCON_DEVICE_READY:
+ sc->vsc_ready = true;
/* set port ready events for registered ports */
for (i = 0; i < VTCON_MAXPORTS; i++) {
tmp = &sc->vsc_ports[i];
if (tmp->vsp_enabled)
pci_vtcon_announce_port(tmp);
+
+ if (tmp->vsp_open)
+ pci_vtcon_open_port(tmp, true);
}
break;
@@ -489,6 +502,11 @@ static void
pci_vtcon_open_port(struct pci_vtcon_port *port, bool open)
{
struct pci_vtcon_control event;
+
+ if (!port->vsp_sc->vsc_ready) {
+ port->vsp_open = true;
+ return;
+ }
event.id = port->vsp_id;
event.event = VTCON_PORT_OPEN;
Modified: stable/11/usr.sbin/bhyve/virtio.h
==============================================================================
--- stable/11/usr.sbin/bhyve/virtio.h Mon Jul 24 06:07:44 2017 (r321412)
+++ stable/11/usr.sbin/bhyve/virtio.h Mon Jul 24 06:19:04 2017 (r321413)
@@ -210,6 +210,7 @@ struct vring_used {
#define VIRTIO_DEV_NET 0x1000
#define VIRTIO_DEV_BLOCK 0x1001
#define VIRTIO_DEV_RANDOM 0x1005
+#define VIRTIO_DEV_CONSOLE 0x1003
/*
* PCI config space constants.
More information about the svn-src-all
mailing list