Skip to contentSkip to conversation

Introduce I/O channels framework

PATCH Superseded Daniel P. Berrange 7 participants 45 messages Oct 12, 2015 – Nov 2, 2015

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Introduce I/O channels framework

This series of patches is a followup submission for review of another chunk of my large series supporting TLS across chardevs, VNC and migration, previously shown here:

RFC: https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00829.html
v1: https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg04853.html

In this series, I have provided only the general I/O channels framework, which will ultimately be used by VNC, chardev and migration code, whicih currently work as follows:

- VNC: uses raw sockets APIs directly, layering in TLS, SASL and websockets where needed. This has resulted in what should be fairly generic code for TLS and websockets being entangled with the rest of the VNC server code.

- Chardevs: uses GLib's GIOChannel framework. This only provides implementations for sockets and files. Its API lacks support for using struct iovec for read/writes, file descriptor passing, misc sockets ioctls/fcntls. While you can work around these problems by accessing the underling file descriptor directly, this breaks the encapsulation, requiring callers to know about specific implementations. It also does not have integration with QEMU Error reporting framework. So while the GIOChannel is extensible, extending it would result in throwing away pretty much the entire of the existing implementations

- Migration: uses QEMUFile framework. The provides an abstract interface for I/O channels used during migration. It has impls for sockets, files, memory buffers & commands. While it has struct iovec support for writes, it does not have the same for reads. It also doesn't support file descriptor passing or control of the sockets ioctls/fcntls. It also does not have any explicit event loop integration, expecting the callers to directly access the underling file desctriptor and setup events on that. This limits its utility in cases where you need channels which are not backed by file descriptors. It has no integration with QEMU Error object for error reporting, has fixed semantics wrt writes ie must always do a full write, no partial writes, and most strangely forces either input or output mode, but refuses to allow both, so no bi-directional channels!

Out of all of these, the migration code is probably closest to what is needed, but is still a good way off from being a generic framework that be can reused outside of the migration code.

There is also the GLib GIO library which provides a generic framework, but we can't depend on that due to the minimum GLib requirement. It also has various missing pieces such as file descriptor passing, and no support for struct iovec either.

Hence, this series was born, which tries to take the best of the designs for the GIOChannel, QIO and QEMUFile code to provide QIOChannel. Right from the start this new framework is explicitly isolated from any other QEMU subsystem, so its implementation will not get mixed up with specific use cases.

The QIOChannel abstract base class defines the overall API contract

- qio_channel_{write,writev,write_full} for writing data. The underling impl always uses struct iovec, but non-iov APIs are provided as simple wrappers for convenience

- qio_channel_{read,readv,read_full} for reading data. The underling impl always uses struct iovec, but non-iov APIs are provided as simple wrappers for convenience

- qio_channel_has_feature to determine which optional features the channel supports - eg file descriptor passing, nagle, etc

- qio_channel_set_{blocking,delay,cork} for various fcntl and ioctl controls

- qio_channel_{close,shutdown} for closing the I/O stream or individual channels

- qio_channel_seek for random access channels

- qio_channel_{add,create}_watch for integration into the main loop for event notifications

- qio_channel_wait for blocking of execution pending an event notification

- qio_channel_yield for switching coroutine until an event notification

All the APIs support Error ** object arguments where needed. The object is built using QOM, in order to get reference counting and sub-classing with type checking. They are *not* user creatable/visible objects though - these are internal infrastructure, so we will be free to adapt APIs/objects at will over time.

In this series there are a variety of implementations. Some of them provide an actual base layer data transport, while others provide a data translation layer:

In this series there are a variety of implementations. Some of them provide an actual base layer data transport, while others provide a data translation layer:

- QIOChannelSocket - for socket based I/O, IPv4, IPV6 & UNIX, both stream and datagram.
- QIOChannelFile - any non-socket file, plain file, char dev, fifo, pipe, etc
- QIOChannelTLS - data translation layer to apply TLS protocol
- QIOChannelWebsock - data translation layer to apply the websockets server protocol
- QIOChannelCommand - spawn & communicate with a command via pipes
- QIOChannelBuffer - a simple in-memory buffer

These 6 implementations are sufficient to support the current needs of the VNC server, chardev network backends, and all the various migration protocols, except RDMA (which is part of the larger RFC series I've posted previously).

The sockets implementation in particular solves a long standing limitation of the qemu-sockets.c API by providing a truely asynchronous API for establishing listener sockets / connections. The current code is only async for the socket establishment, but still blocks the caller for DNS resolution.

I have not attempted to make the socket implementation support multiple listener sockets in a single object. I looked at this but it would significantly complicate the QIOChannelSocket implementation. I intend to suggest an alternative approach for that problem at a later date, whereby we define a QIONetworkService object, which provides the infrastructure for managing multiple QIOChannelSocket listeners, and clients, which was resuable for any QEMU network service.

There are unit tests for the socket, file, tls, and command channel implementations. I didn't create unit test for the websock impl, as it needs a websock client to usefully test it which doesn't exist in QEMU yet. The memory buffer impl also lacks unit tests for now, simply due to not getting around to it yet.

This series merely introduces all the new framework. To keep it an acceptable length for review, it doesn't include any of the patches which actually use the new APIs. If reviewers want to see real world usage of these APIs, they can refer to my previous RFC series.

https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00829.html

In particular

- VNC conversion to QIOChannelSocket

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00851.html

- VNC conversion to QIOChannelTLS

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00845.html

- VNC conversion to QIOChannelWebsock

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00842.html

- Chardev conversion to QIOChannelSocket

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00849.html

- Chardev addition of TLS support

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00848.html

- All the migration ones, but most interesting addition of TLS

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00871.html

Finally I've listed myself as maintainer for the new io/ and include/io/ directory prefixes.

Changed in v2:

- Put the Buffer APIs extracted from VNC code into util/ instead of io/ directories (Paolo)

- Added Kevin & Stefan to MAINTAINERS for coroutine code (Paolo)

- Remove feature checks for TCP_NODELAY and TCP_CORK and treat them as hints which cannot fail (Paolo)

- Push feature checking for FD passing up into QIOChannel base class (Paolo)

- Use more constants in websockets code instead of magic values (David Gilbert)

Daniel P. Berrange (16):
sockets: add helpers for creating SocketAddress from a socket
sockets: move qapi_copy_SocketAddress into qemu-sockets.c
sockets: allow port to be NULL when listening on IP address
ui: convert VNC startup code to use SocketAddress
osdep: add qemu_fork() wrapper for safely handling signals
coroutine: move into libqemuutil.a library
util: pull Buffer code out of VNC module
io: add abstract QIOChannel classes
io: add helper module for creating watches on FDs
io: add QIOTask class for async operations
io: add QIOChannelSocket class
io: add QIOChannelFile class
io: add QIOChannelTLS class
io: add QIOChannelWebsock class
io: add QIOChannelCommand class
io: add QIOChannelBuffer class

 MAINTAINERS                                        |  20 +
 Makefile                                           |   2 +
 Makefile.objs                                      |   9 +-
 Makefile.target                                    |   2 +
 block.c                                            |   2 +-
 block/qcow2.h                                      |   2 +-
 block/vdi.c                                        |   2 +-
 block/write-threshold.c                            |   2 +-
 blockjob.c                                         |   2 +-
 configure                                          |  11 +
 hw/9pfs/codir.c                                    |   2 +-
 hw/9pfs/cofile.c                                   |   2 +-
 hw/9pfs/cofs.c                                     |   2 +-
 hw/9pfs/coxattr.c                                  |   2 +-
 hw/9pfs/virtio-9p-coth.c                           |   2 +-
 hw/9pfs/virtio-9p-coth.h                           |   2 +-
 hw/9pfs/virtio-9p.h                                |   2 +-
 include/block/block.h                              |   2 +-
 include/block/block_int.h                          |   2 +-
 include/io/channel-buffer.h                        |  59 ++
 include/io/channel-command.h                       |  91 ++
 include/io/channel-file.h                          |  93 ++
 include/io/channel-socket.h                        | 244 ++++++
 include/io/channel-tls.h                           | 142 +++
 include/io/channel-watch.h                         |  72 ++
 include/io/channel-websock.h                       | 108 +++
 include/io/channel.h                               | 506 +++++++++++
 include/io/task.h                                  | 256 ++++++
 include/qemu/buffer.h                              | 118 +++
 include/{block => qemu}/coroutine.h                |   0
 include/{block => qemu}/coroutine_int.h            |   2 +-
 include/qemu/osdep.h                               |  16 +
 include/qemu/sockets.h                             |  34 +
 io/Makefile.objs                                   |   9 +
 io/channel-buffer.c                                | 255 ++++++
 io/channel-command.c                               | 369 ++++++++
 io/channel-file.c                                  | 237 +++++
 io/channel-socket.c                                | 737 ++++++++++++++++
 io/channel-tls.c                                   | 405 +++++++++
 io/channel-watch.c                                 | 200 +++++
 io/channel-websock.c                               | 975 +++++++++++++++++++++
 io/channel.c                                       | 283 ++++++
 io/task.c                                          | 159 ++++
 migration/qemu-file-buf.c                          |   2 +-
 migration/qemu-file-stdio.c                        |   2 +-
 migration/qemu-file-unix.c                         |   2 +-
 migration/qemu-file.c                              |   2 +-
 migration/rdma.c                                   |   2 +-
 nbd.c                                              |   2 +-
 qemu-char.c                                        |  25 -
 scripts/create_config                              |   9 +
 tests/.gitignore                                   |   7 +
 tests/Makefile                                     |  16 +
 tests/io-channel-helpers.c                         | 247 ++++++
 tests/io-channel-helpers.h                         |  33 +
 tests/test-coroutine.c                             |   4 +-
 tests/test-io-channel-command.c                    | 122 +++
 tests/test-io-channel-file.c                       |  91 ++
 tests/test-io-channel-socket.c                     | 367 ++++++++
 tests/test-io-channel-tls.c                        | 335 +++++++
 tests/test-io-task.c                               | 276 ++++++
 tests/test-vmstate.c                               |   2 +-
 thread-pool.c                                      |   2 +-
 trace-events                                       |  56 ++
 ui/vnc.c                                           | 204 ++---
 ui/vnc.h                                           |  16 +-
 util/Makefile.objs                                 |   4 +
 util/buffer.c                                      |  65 ++
 coroutine-gthread.c => util/coroutine-gthread.c    |   2 +-
 .../coroutine-sigaltstack.c                        |   2 +-
 coroutine-ucontext.c => util/coroutine-ucontext.c  |   2 +-
 coroutine-win32.c => util/coroutine-win32.c        |   2 +-
 util/oslib-posix.c                                 |  71 ++
 util/oslib-win32.c                                 |   9 +
 qemu-coroutine-io.c => util/qemu-coroutine-io.c    |   2 +-
 .../qemu-coroutine-lock.c                          |   4 +-
 .../qemu-coroutine-sleep.c                         |   2 +-
 qemu-coroutine.c => util/qemu-coroutine.c          |   4 +-
 util/qemu-sockets.c                                | 158 +++-
 79 files changed, 7396 insertions(+), 197 deletions(-)
 create mode 100644 include/io/channel-buffer.h
 create mode 100644 include/io/channel-command.h
 create mode 100644 include/io/channel-file.h
 create mode 100644 include/io/channel-socket.h
 create mode 100644 include/io/channel-tls.h
 create mode 100644 include/io/channel-watch.h
 create mode 100644 include/io/channel-websock.h
 create mode 100644 include/io/channel.h
 create mode 100644 include/io/task.h
 create mode 100644 include/qemu/buffer.h
 rename include/{block => qemu}/coroutine.h (100%)
 rename include/{block => qemu}/coroutine_int.h (98%)
 create mode 100644 io/Makefile.objs
 create mode 100644 io/channel-buffer.c
 create mode 100644 io/channel-command.c
 create mode 100644 io/channel-file.c
 create mode 100644 io/channel-socket.c
 create mode 100644 io/channel-tls.c
 create mode 100644 io/channel-watch.c
 create mode 100644 io/channel-websock.c
 create mode 100644 io/channel.c
 create mode 100644 io/task.c
 create mode 100644 tests/io-channel-helpers.c
 create mode 100644 tests/io-channel-helpers.h
 create mode 100644 tests/test-io-channel-command.c
 create mode 100644 tests/test-io-channel-file.c
 create mode 100644 tests/test-io-channel-socket.c
 create mode 100644 tests/test-io-channel-tls.c
 create mode 100644 tests/test-io-task.c
 create mode 100644 util/buffer.c
 rename coroutine-gthread.c => util/coroutine-gthread.c (99%)
 rename coroutine-sigaltstack.c => util/coroutine-sigaltstack.c (99%)
 rename coroutine-ucontext.c => util/coroutine-ucontext.c (99%)
 rename coroutine-win32.c => util/coroutine-win32.c (98%)
 rename qemu-coroutine-io.c => util/qemu-coroutine-io.c (99%)
 rename qemu-coroutine-lock.c => util/qemu-coroutine-lock.c (98%)
 rename qemu-coroutine-sleep.c => util/qemu-coroutine-sleep.c (96%)
 rename qemu-coroutine.c => util/qemu-coroutine.c (98%)
Signature · 1 line
2.4.3
#1 lore raw

PATCH v2 1/16 sockets: add helpers for creating SocketAddress from a socket

Add two helper methods that, given a socket file descriptor, can return a populated SocketAddress struct containing either the local or remote address information.

---
 include/qemu/sockets.h |  30 ++++++++++++++
 util/qemu-sockets.c    | 110 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+)
include/qemu/sockets.h +30 -0
index c174b5c..3ea7cc9 100644
@@ -88,4 +88,34 @@ int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp);
 int parse_host_port(struct sockaddr_in *saddr, const char *str);
 int socket_init(void);
 
+/**
+ * socket_local_address:
+ * @fd: the socket file handle
+ * @errp: pointer to uninitialized error object
+ *
+ * Get the string representation of the local socket
+ * address. A pointer to the allocated address information
+ * struct will be returned, which the caller is required to
+ * release with a call qapi_free_SocketAddress when no
+ * longer required.
+ *
+ * Returns: the socket address struct, or NULL on error
+ */
+SocketAddress *socket_local_address(int fd, Error **errp);
+
+/**
+ * socket_remote_address:
+ * @fd: the socket file handle
+ * @errp: pointer to uninitialized error object
+ *
+ * Get the string representation of the remote socket
+ * address. A pointer to the allocated address information
+ * struct will be returned, which the caller is required to
+ * release with a call qapi_free_SocketAddress when no
+ * longer required.
+ *
+ * Returns: the socket address struct, or NULL on error
+ */
+SocketAddress *socket_remote_address(int fd, Error **errp);
+
 #endif /* QEMU_SOCKET_H */
util/qemu-sockets.c +110 -0

113 lines not on this page · raw message

Signature · 1 line
2.4.3
#2 lore raw

Re: [Qemu-devel] [PATCH v2 01/16] sockets: add helpers for creating SocketAddress from a socket

Quoted 18 lines · Daniel P. Berrange

Add two helper methods that, given a socket file descriptor, can return a populated SocketAddress struct containing either the local or remote address information.

---
 include/qemu/sockets.h |  30 ++++++++++++++
 util/qemu-sockets.c    | 110 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+)
util/qemu-sockets.c +7 -0
+static SocketAddress *
+socket_sockaddr_to_address_inet(struct sockaddr_storage *sa,
+                                socklen_t salen,
+                                Error **errp)
+{
+    char host[NI_MAXHOST];
+    char serv[NI_MAXSERV];

util/qemu-sockets.c int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) · line 1036

Quoted 10 lines
util/qemu-sockets.c +10 -0
+    SocketAddress *addr;
+    int ret;
+
+    ret = getnameinfo((struct sockaddr *)sa, salen,
+                      host, sizeof(host),
+                      serv, sizeof(serv),
+                      NI_NUMERICHOST | NI_NUMERICSERV);
+    if (ret != 0) {
+        error_setg(errp, "Cannot format numeric socket address: %s\n",
+                   gai_strerror(ret));

No trailing \n with error_setg(), please.

util/qemu-sockets.c int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) · line 1041

Quoted 5 lines
util/qemu-sockets.c +5 -0
+        return NULL;
+    }
+
+    addr = g_new0(SocketAddress, 1);
+    addr->kind = SOCKET_ADDRESS_KIND_INET;

I've got pending qapi patches that rename this to addr->type,

Quoted 1 line

+ addr->inet = g_new0(InetSocketAddress, 1);

and this to addr->u.inet. Whoever merges first gets to watch the other guy rebase :)

util/qemu-sockets.c int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) · line 1049

Quoted 7 lines
util/qemu-sockets.c +7 -0
+    addr->inet->host = g_strdup(host);
+    addr->inet->port = g_strdup(serv);
+    if (sa->ss_family == AF_INET) {
+        addr->inet->ipv4 = true;
+    } else {
+        addr->inet->ipv6 = true;
+    }

Don't we also need to set has_ipv4 and has_ipv6 appropriately?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

Re: [Qemu-devel] [PATCH v2 01/16] sockets: add helpers for creating SocketAddress from a socket

Quoted 53 lines · Eric Blake
Quoted 18 lines · Daniel P. Berrange

Add two helper methods that, given a socket file descriptor, can return a populated SocketAddress struct containing either the local or remote address information.

---
 include/qemu/sockets.h |  30 ++++++++++++++
 util/qemu-sockets.c    | 110 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 140 insertions(+)
util/qemu-sockets.c +7 -0
+static SocketAddress *
+socket_sockaddr_to_address_inet(struct sockaddr_storage *sa,
+                                socklen_t salen,
+                                Error **errp)
+{
+    char host[NI_MAXHOST];
+    char serv[NI_MAXSERV];

util/qemu-sockets.c int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) · line 1036

Quoted 10 lines
util/qemu-sockets.c +10 -0
+    SocketAddress *addr;
+    int ret;
+
+    ret = getnameinfo((struct sockaddr *)sa, salen,
+                      host, sizeof(host),
+                      serv, sizeof(serv),
+                      NI_NUMERICHOST | NI_NUMERICSERV);
+    if (ret != 0) {
+        error_setg(errp, "Cannot format numeric socket address: %s\n",
+                   gai_strerror(ret));

No trailing \n with error_setg(), please.

util/qemu-sockets.c int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) · line 1041

Quoted 5 lines
util/qemu-sockets.c +5 -0
+        return NULL;
+    }
+
+    addr = g_new0(SocketAddress, 1);
+    addr->kind = SOCKET_ADDRESS_KIND_INET;

I've got pending qapi patches that rename this to addr->type,

Quoted 1 line

+ addr->inet = g_new0(InetSocketAddress, 1);

and this to addr->u.inet. Whoever merges first gets to watch the other guy rebase :)

util/qemu-sockets.c int socket_dgram(SocketAddress *remote, SocketAddress *local, Error **errp) · line 1049

Quoted 7 lines
util/qemu-sockets.c +7 -0
+    addr->inet->host = g_strdup(host);
+    addr->inet->port = g_strdup(serv);
+    if (sa->ss_family == AF_INET) {
+        addr->inet->ipv4 = true;
+    } else {
+        addr->inet->ipv6 = true;
+    }
Quoted 1 line

Don't we also need to set has_ipv4 and has_ipv6 appropriately?

Yes, we do.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#4 lore raw

PATCH v2 2/16 sockets: move qapi_copy_SocketAddress into qemu-sockets.c

In reply to Daniel P. Berrange

The qapi_copy_SocketAddress method is going to be useful in more places than just qemu-char.c, so move it into the qemu-sockets.c file to allow its reuse.

---
 include/qemu/sockets.h |  4 ++++
 qemu-char.c            | 25 -------------------------
 util/qemu-sockets.c    | 30 ++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 25 deletions(-)
include/qemu/sockets.h +4 -0
index 3ea7cc9..5a183c5 100644
@@ -118,4 +118,8 @@ SocketAddress *socket_local_address(int fd, Error **errp);
  */
 SocketAddress *socket_remote_address(int fd, Error **errp);
 
+
+void qapi_copy_SocketAddress(SocketAddress **p_dest,
+                             SocketAddress *src);
+
 #endif /* QEMU_SOCKET_H */
qemu-char.c +0 -25
index 653ea10..50ea4f7 100644
@@ -92,31 +92,6 @@
 
 /***********************************************************/
 /* Socket address helpers */
-static void qapi_copy_SocketAddress(SocketAddress **p_dest,
-                                    SocketAddress *src)
-{
-    QmpOutputVisitor *qov;
-    QmpInputVisitor *qiv;
-    Visitor *ov, *iv;
-    QObject *obj;
-
-    *p_dest = NULL;
-
-    qov = qmp_output_visitor_new();
-    ov = qmp_output_get_visitor(qov);
-    visit_type_SocketAddress(ov, &src, NULL, &error_abort);
-    obj = qmp_output_get_qobject(qov);
-    qmp_output_visitor_cleanup(qov);
-    if (!obj) {
-        return;
-    }
-
-    qiv = qmp_input_visitor_new(obj);
-    iv = qmp_input_get_visitor(qiv);
-    visit_type_SocketAddress(iv, p_dest, NULL, &error_abort);
-    qmp_input_visitor_cleanup(qiv);
-    qobject_decref(obj);
-}
 
 static int SocketAddress_to_str(char *dest, int max_len,
                                 const char *prefix, SocketAddress *addr,
util/qemu-sockets.c +30 -0
index 2bdfacf..9cc5bee 100644
@@ -25,6 +25,9 @@
 #include "monitor/monitor.h"
 #include "qemu/sockets.h"
 #include "qemu/main-loop.h"
+#include "qapi/qmp-input-visitor.h"
+#include "qapi/qmp-output-visitor.h"
+#include "qapi-visit.h"
 
 #ifndef AI_ADDRCONFIG
 # define AI_ADDRCONFIG 0
@@ -1125,3 +1128,30 @@ SocketAddress *socket_remote_address(int fd, Error **errp)
 
     return socket_sockaddr_to_address(&ss, sslen, errp);
 }
+
+
+void qapi_copy_SocketAddress(SocketAddress **p_dest,
+                             SocketAddress *src)
+{
+    QmpOutputVisitor *qov;
+    QmpInputVisitor *qiv;
+    Visitor *ov, *iv;
+    QObject *obj;
+
+    *p_dest = NULL;
+
+    qov = qmp_output_visitor_new();
+    ov = qmp_output_get_visitor(qov);
+    visit_type_SocketAddress(ov, &src, NULL, &error_abort);
+    obj = qmp_output_get_qobject(qov);
+    qmp_output_visitor_cleanup(qov);
+    if (!obj) {
+        return;
+    }
+
+    qiv = qmp_input_visitor_new(obj);
+    iv = qmp_input_get_visitor(qiv);
+    visit_type_SocketAddress(iv, p_dest, NULL, &error_abort);
+    qmp_input_visitor_cleanup(qiv);
+    qobject_decref(obj);
+}
Signature · 1 line
2.4.3
Reviewed-by on v2 2/16
#5 lore raw

Re: [Qemu-devel] [PATCH v2 02/16] sockets: move qapi_copy_SocketAddress into qemu-sockets.c

Quoted 31 lines · Daniel P. Berrange

The qapi_copy_SocketAddress method is going to be useful in more places than just qemu-char.c, so move it into the qemu-sockets.c file to allow its reuse.

---
 include/qemu/sockets.h |  4 ++++
 qemu-char.c            | 25 -------------------------
 util/qemu-sockets.c    | 30 ++++++++++++++++++++++++++++++
 3 files changed, 34 insertions(+), 25 deletions(-)

+++ b/qemu-char.c

qemu-char.c +0 -14
@@ -92,31 +92,6 @@
 
 /***********************************************************/
 /* Socket address helpers */
-static void qapi_copy_SocketAddress(SocketAddress **p_dest,
-                                    SocketAddress *src)
-{
-    QmpOutputVisitor *qov;
-    QmpInputVisitor *qiv;
-    Visitor *ov, *iv;
-    QObject *obj;
-
-    *p_dest = NULL;
-
-    qov = qmp_output_visitor_new();
-    ov = qmp_output_get_visitor(qov);
-    visit_type_SocketAddress(ov, &src, NULL, &error_abort);
-    obj = qmp_output_get_qobject(qov);

qemu-char.c line 118

Quoted 10 lines
qemu-char.c +0 -10
-    qmp_output_visitor_cleanup(qov);
-    if (!obj) {
-        return;
-    }
-
-    qiv = qmp_input_visitor_new(obj);
-    iv = qmp_input_get_visitor(qiv);
-    visit_type_SocketAddress(iv, p_dest, NULL, &error_abort);
-    qmp_input_visitor_cleanup(qiv);
-    qobject_decref(obj);

Interesting approach - it means that this copy will work no matter what further extensions we add into the qapi type. But rather heavyweight compared to just doing a memberwise copy, no? At any rate, this commit is straight code motion, so you did it correctly, but we may want to simplify things in a later commit.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#6 lore raw

Re: [Qemu-devel] [PATCH v2 02/16] sockets: move qapi_copy_SocketAddress into qemu-sockets.c

Quoted 10 lines · Eric Blake

qemu-char.c line 118

Quoted 5 lines
qemu-char.c +0 -5
-    qiv = qmp_input_visitor_new(obj);
-    iv = qmp_input_get_visitor(qiv);
-    visit_type_SocketAddress(iv, p_dest, NULL, &error_abort);
-    qmp_input_visitor_cleanup(qiv);
-    qobject_decref(obj);

Interesting approach - it means that this copy will work no matter what further extensions we add into the qapi type. But rather heavyweight compared to just doing a memberwise copy, no? At any rate, this commit is straight code motion, so you did it correctly, but we may want to simplify things in a later commit.

A memberwise copy requires you to allocate embedded objects (I'm not sure whether your boxing changes can simplify this).

Paolo

#7 lore raw

Re: [Qemu-devel] [PATCH v2 02/16] sockets: move qapi_copy_SocketAddress into qemu-sockets.c

Quoted 8 lines · Paolo Bonzini
Quoted 5 lines · Eric Blake
Quoted 5 lines
qemu-char.c +0 -5
-    qiv = qmp_input_visitor_new(obj);
-    iv = qmp_input_get_visitor(qiv);
-    visit_type_SocketAddress(iv, p_dest, NULL, &error_abort);
-    qmp_input_visitor_cleanup(qiv);
-    qobject_decref(obj);
Quoted 8 lines
Quoted 5 lines

Interesting approach - it means that this copy will work no matter what further extensions we add into the qapi type. But rather heavyweight compared to just doing a memberwise copy, no? At any rate, this commit is straight code motion, so you did it correctly, but we may want to simplify things in a later commit.

A memberwise copy requires you to allocate embedded objects (I'm not sure whether your boxing changes can simplify this).

It would probably be a nice idea if the QAPI code generator could emit an efficient copy func. So if someone wants an coding exercise....

In the mean time, this socket kaddress copy func is not called in any performance critical code paths, so the inefficiency doesn't particularly matter for now.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#8 lore raw

PATCH v2 3/16 sockets: allow port to be NULL when listening on IP address

In reply to Daniel P. Berrange

If the port in the SocketAddress struct is NULL, it can allow the kernel to automatically select a free port. This is useful in particular in unit tests to avoid a race trying to find a free port to run a test case on.

---
 util/qemu-sockets.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
util/qemu-sockets.c +13 -5
index 9cc5bee..f9d2f6e 100644
@@ -128,12 +128,15 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
     ai.ai_family = PF_UNSPEC;
     ai.ai_socktype = SOCK_STREAM;
 
-    if ((qemu_opt_get(opts, "host") == NULL) ||
-        (qemu_opt_get(opts, "port") == NULL)) {
-        error_setg(errp, "host and/or port not specified");
+    if ((qemu_opt_get(opts, "host") == NULL)) {
+        error_setg(errp, "host not specified");
         return -1;
     }
-    pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
+    if (qemu_opt_get(opts, "port") != NULL) {
+        pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
+    } else {
+        port[0] = '\0';
+    }
     addr = qemu_opt_get(opts, "host");
 
     to = qemu_opt_get_number(opts, "to", 0);
@@ -145,6 +148,10 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
     /* lookup */
     if (port_offset) {
         unsigned long long baseport;
+        if (strlen(port) == 0) {
+            error_setg(errp, "port not specified");
+            return -1;
+        }
         if (parse_uint_full(port, &baseport, 10) < 0) {
             error_setg(errp, "can't convert to a number: %s", port);
             return -1;
@@ -156,7 +163,8 @@ int inet_listen_opts(QemuOpts *opts, int port_offset, Error **errp)
         }
         snprintf(port, sizeof(port), "%d", (int)baseport + port_offset);
     }
-    rc = getaddrinfo(strlen(addr) ? addr : NULL, port, &ai, &res);
+    rc = getaddrinfo(strlen(addr) ? addr : NULL,
+                     strlen(port) ? port : NULL, &ai, &res);
     if (rc != 0) {
         error_setg(errp, "address resolution failed for %s:%s: %s", addr, port,
                    gai_strerror(rc));
Signature · 1 line
2.4.3
#9 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

Quoted 10 lines · Daniel P. Berrange

If the port in the SocketAddress struct is NULL, it can allow the kernel to automatically select a free port. This is useful in particular in unit tests to avoid a race trying to find a free port to run a test case on.

---
 util/qemu-sockets.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

Right now, the qapi documents InetSocketAddress.port as mandatory. Should we relax it to be optional, rather than special-casing the empty string "" to mean no port?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#10 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

Quoted 12 lines · Eric Blake
Quoted 10 lines · Daniel P. Berrange

If the port in the SocketAddress struct is NULL, it can allow the kernel to automatically select a free port. This is useful in particular in unit tests to avoid a race trying to find a free port to run a test case on.

---
 util/qemu-sockets.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
Quoted 3 lines

Right now, the qapi documents InetSocketAddress.port as mandatory. Should we relax it to be optional, rather than special-casing the empty string "" to mean no port?

Yep, I can change qapi-schema.json to mark it optional.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#11 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

In reply to Daniel P. Berrange
Quoted 4 lines · Daniel P. Berrange

If the port in the SocketAddress struct is NULL, it can allow the kernel to automatically select a free port. This is useful in particular in unit tests to avoid a race trying to find a free port to run a test case on.

This patch seems to do a bit more than it claims ;-)

I just noticed that after a rebase a few minutes ago, all options I have that uses this type of port syntax:

-serial telnet:ip:port
-serial tcp:ip:port
-qmp ip:port

started to ignore the port argument and instead provide a dynamic port. Rebasing without this patch fixes the issue,

Thanks,
Knut

Quoted 56 lines
---
 util/qemu-sockets.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
util/qemu-sockets.c +7 -4
index 9cc5bee..f9d2f6e 100644
@@ -128,12 +128,15 @@ int inet_listen_opts(QemuOpts *opts, int
 port_offset, Error **errp)
     ai.ai_family = PF_UNSPEC;
     ai.ai_socktype = SOCK_STREAM;
 
-    if ((qemu_opt_get(opts, "host") == NULL) ||
-        (qemu_opt_get(opts, "port") == NULL)) {
-        error_setg(errp, "host and/or port not specified");
+    if ((qemu_opt_get(opts, "host") == NULL)) {
+        error_setg(errp, "host not specified");
         return -1;
     }
-    pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
+    if (qemu_opt_get(opts, "port") != NULL) {
+        pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
+    } else {
+        port[0] = '\0';
+    }
     addr = qemu_opt_get(opts, "host");
 
     to = qemu_opt_get_number(opts, "to", 0);
util/qemu-sockets.c +4 -0
@@ -145,6 +148,10 @@ int inet_listen_opts(QemuOpts *opts, int
 port_offset, Error **errp)
     /* lookup */
     if (port_offset) {
         unsigned long long baseport;
+        if (strlen(port) == 0) {
+            error_setg(errp, "port not specified");
+            return -1;
+        }
         if (parse_uint_full(port, &baseport, 10) < 0) {
             error_setg(errp, "can't convert to a number: %s", port);
             return -1;
util/qemu-sockets.c +2 -1
@@ -156,7 +163,8 @@ int inet_listen_opts(QemuOpts *opts, int
 port_offset, Error **errp)
         }
         snprintf(port, sizeof(port), "%d", (int)baseport +
 port_offset);
     }
-    rc = getaddrinfo(strlen(addr) ? addr : NULL, port, &ai, &res);
+    rc = getaddrinfo(strlen(addr) ? addr : NULL,
+                     strlen(port) ? port : NULL, &ai, &res);
     if (rc != 0) {

error_setg(errp, "address resolution failed for %s:%s: %s",
addr, port,

                    gai_strerror(rc));
#12 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

Quoted 15 lines · Knut Omang
Quoted 4 lines · Daniel P. Berrange

If the port in the SocketAddress struct is NULL, it can allow the kernel to automatically select a free port. This is useful in particular in unit tests to avoid a race trying to find a free port to run a test case on.

This patch seems to do a bit more than it claims ;-)

I just noticed that after a rebase a few minutes ago, all options I have that uses this type of port syntax:

(quoted diff) +0 -3
-serial telnet:ip:port
-serial tcp:ip:port
-qmp ip:port
Quoted 2 lines

started to ignore the port argument and instead provide a dynamic port. Rebasing without this patch fixes the issue,

It is the change to qapi-schema.json that causes this. When 'port' is marked as optional in the schema for InetSocketAddress, then even if the 'port' field is set to a non-NULL string, the qapi_copy_SocketAddress function will not copy that field, so the valid port setting gets discarded.

For reasons I don't understand, it appears that even string fields which are marked as optional get a 'has_XXX' flag, to distinguish betweeen a NULL string and an unset string. I struggle to imagine why we need this. It makes sense for integer/boolean types, but I would have thought just checking for NULL was sufficient for string types.

Auditing the code to add in 'has_port = true' everywhere that we set 'port = <a non-NULL string>' is a bit of work, so simplest is probably to revert the change which marks port as optional in qapi-schema.json by doing

qapi-schema.json +1 -3
index f60be29..c613dfd 100644
@@ -2615,8 +2615,6 @@
 # @host: host part of the address
 #
 # @port: port part of the address, or lowest port if @to is present.
-#        Kernel selects a free port if omitted for listener addresses.
-#        #optional
 #
 # @to: highest port to try
 #
@@ -2631,7 +2629,7 @@
 { 'struct': 'InetSocketAddress',
   'data': {
     'host': 'str',
-    '*port': 'str',
+    'port': 'str',
     '*to': 'uint16',
     '*ipv4': 'bool',
     '*ipv6': 'bool' } }

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#13 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

Quoted 6 lines · Daniel P. Berrange

For reasons I don't understand, it appears that even string fields which are marked as optional get a 'has_XXX' flag, to distinguish betweeen a NULL string and an unset string. I struggle to imagine why we need this. It makes sense for integer/boolean types, but I would have thought just checking for NULL was sufficient for string types.

I think the argument here is pure consistency. *Every* optional field should be implemented as has_fieldname (bool) plus fieldname (actual value). Special casing string types because we happen to have a special value we can use to indicate 'no string' seems to me like it would cause more confusion than it would be worth.

thanks
-- PMM

#14 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

Quoted 8 lines · Peter Maydell
Quoted 6 lines · Daniel P. Berrange

For reasons I don't understand, it appears that even string fields which are marked as optional get a 'has_XXX' flag, to distinguish betweeen a NULL string and an unset string. I struggle to imagine why we need this. It makes sense for integer/boolean types, but I would have thought just checking for NULL was sufficient for string types.

Quoted 6 lines

I think the argument here is pure consistency. *Every* optional field should be implemented as has_fieldname (bool) plus fieldname (actual value). Special casing string types because we happen to have a special value we can use to indicate 'no string' seems to me like it would cause more confusion than it would be worth.

Having a has_FOO for pointer-valued FOOs also causes confusion, because it begs questions like "does has_FOO imply FOO != NULL?" and "if !has_FOO, do I have to worry about freeing FOO?".

I believe we have these has_FOOs not because someone tried to minimize confusion, but due to laziness: it was simpler to blindly generate the has_FOO for every FOO.

Since I don't think distinguishing "pointer argument omitted" from "pointer argument is null" makes sense, I want the has_FOO killed for pointer FOOs. Perhaps it's even in the QAPI review queue already, which Eric keeps filling faster than I can drain it :)

#15 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

Quoted 21 lines · Markus Armbruster
Quoted 8 lines · Peter Maydell
Quoted 6 lines · Daniel P. Berrange

For reasons I don't understand, it appears that even string fields which are marked as optional get a 'has_XXX' flag, to distinguish betweeen a NULL string and an unset string. I struggle to imagine why we need this. It makes sense for integer/boolean types, but I would have thought just checking for NULL was sufficient for string types.

Quoted 6 lines

I think the argument here is pure consistency. *Every* optional field should be implemented as has_fieldname (bool) plus fieldname (actual value). Special casing string types because we happen to have a special value we can use to indicate 'no string' seems to me like it would cause more confusion than it would be worth.

Having a has_FOO for pointer-valued FOOs also causes confusion, because it begs questions like "does has_FOO imply FOO != NULL?" and "if !has_FOO, do I have to worry about freeing FOO?".

Quoted 8 lines

I believe we have these has_FOOs not because someone tried to minimize confusion, but due to laziness: it was simpler to blindly generate the has_FOO for every FOO.

Since I don't think distinguishing "pointer argument omitted" from "pointer argument is null" makes sense, I want the has_FOO killed for pointer FOOs. Perhaps it's even in the QAPI review queue already, which Eric keeps filling faster than I can drain it :)

Yep, Eric just replied to my patch for this to the effect that he's planning to fix this for 2.6. So we can just do this trivial revert for 2.5 and fix it properly in 2.6

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#16 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster

I believe we have these has_FOOs not because someone tried to minimize confusion, but due to laziness: it was simpler to blindly generate the has_FOO for every FOO.

Since I don't think distinguishing "pointer argument omitted" from "pointer argument is null" makes sense, I want the has_FOO killed for pointer FOOs. Perhaps it's even in the QAPI review queue already, which Eric keeps filling faster than I can drain it :)

It's not there yet (so it's missed 2.5), but it IS on my plate for 2.6, to add a per-struct attribute on whether the struct prefers has_FOO vs FOO==NULL for marking optional strings/objects (has_FOO will remain mandatory for optional numbers). Per-struct attribute, because there are too many structs to change in one patch, although if I scrub the entire tree, we may remove the attribute at the end of the conversion.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#17 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

In reply to Knut Omang
Quoted 12 lines · Knut Omang
Quoted 4 lines · Daniel P. Berrange

If the port in the SocketAddress struct is NULL, it can allow the kernel to automatically select a free port. This is useful in particular in unit tests to avoid a race trying to find a free port to run a test case on.

This patch seems to do a bit more than it claims ;-)

I just noticed that after a rebase a few minutes ago, all options I have that uses this type of port syntax:

Review

Quoted 3 lines
(quoted diff) +0 -3
-serial telnet:ip:port
-serial tcp:ip:port
-qmp ip:port

And -monitor telnet::4444,server,nowait makes QEMU exit.

So do we decide how to fix this?

Quoted 65 lines

started to ignore the port argument and instead provide a dynamic port. Rebasing without this patch fixes the issue,

Thanks,
Knut

Quoted 56 lines
---
 util/qemu-sockets.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)
util/qemu-sockets.c +7 -4
index 9cc5bee..f9d2f6e 100644
@@ -128,12 +128,15 @@ int inet_listen_opts(QemuOpts *opts, int
 port_offset, Error **errp)
     ai.ai_family = PF_UNSPEC;
     ai.ai_socktype = SOCK_STREAM;
 
-    if ((qemu_opt_get(opts, "host") == NULL) ||
-        (qemu_opt_get(opts, "port") == NULL)) {
-        error_setg(errp, "host and/or port not specified");
+    if ((qemu_opt_get(opts, "host") == NULL)) {
+        error_setg(errp, "host not specified");
         return -1;
     }
-    pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
+    if (qemu_opt_get(opts, "port") != NULL) {
+        pstrcpy(port, sizeof(port), qemu_opt_get(opts, "port"));
+    } else {
+        port[0] = '\0';
+    }
     addr = qemu_opt_get(opts, "host");
 
     to = qemu_opt_get_number(opts, "to", 0);
util/qemu-sockets.c +4 -0
@@ -145,6 +148,10 @@ int inet_listen_opts(QemuOpts *opts, int
 port_offset, Error **errp)
     /* lookup */
     if (port_offset) {
         unsigned long long baseport;
+        if (strlen(port) == 0) {
+            error_setg(errp, "port not specified");
+            return -1;
+        }
         if (parse_uint_full(port, &baseport, 10) < 0) {
             error_setg(errp, "can't convert to a number: %s", port);
             return -1;
util/qemu-sockets.c +2 -1
@@ -156,7 +163,8 @@ int inet_listen_opts(QemuOpts *opts, int
 port_offset, Error **errp)
         }
         snprintf(port, sizeof(port), "%d", (int)baseport +
 port_offset);
     }
-    rc = getaddrinfo(strlen(addr) ? addr : NULL, port, &ai, &res);
+    rc = getaddrinfo(strlen(addr) ? addr : NULL,
+                     strlen(port) ? port : NULL, &ai, &res);
     if (rc != 0) {

error_setg(errp, "address resolution failed for %s:%s: %s",
addr, port,

                    gai_strerror(rc));
Signature · 1 line
Shannon
#18 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

Quoted 11 lines · Shannon Zhao

Review

Quoted 7 lines · Knut Omang

I just noticed that after a rebase a few minutes ago, all options I have that uses this type of port syntax:

(quoted diff) +0 -3
-serial telnet:ip:port
-serial tcp:ip:port
-qmp ip:port

And -monitor telnet::4444,server,nowait makes QEMU exit.

So do we decide how to fix this?

It should be fixed by the patch "qapi-schema: mark InetSocketAddress as mandatory again". This was in Markus' latest QAPI pullreq, but that failed compile testing due to a different patch in the series. I expect Markus will resend a fixed pull early next week.

thanks
-- PMM

#19 lore raw

Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address

Quoted 11 lines · Peter Maydell
Quoted 10 lines · Shannon Zhao

Review

Quoted 7 lines · Knut Omang

I just noticed that after a rebase a few minutes ago, all options I have that uses this type of port syntax:

(quoted diff) +0 -3
-serial telnet:ip:port
-serial tcp:ip:port
-qmp ip:port

And -monitor telnet::4444,server,nowait makes QEMU exit.

Quoted 6 lines
Quoted 1 line

So do we decide how to fix this?

It should be fixed by the patch "qapi-schema: mark InetSocketAddress as mandatory again". This was in Markus' latest QAPI pullreq, but that failed compile testing due to a different patch in the series. I expect Markus will resend a fixed pull early next week.

Just sent.

#20 lore raw

PATCH v2 4/16 ui: convert VNC startup code to use SocketAddress

In reply to Daniel P. Berrange

The VNC code is currently using QemuOpts to configure the sockets connections / listeners it needs. Convert it to use SocketAddress to bring it in line with modern QAPI based code elsewhere in QEMU.

---
 ui/vnc.c | 161 ++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 91 insertions(+), 70 deletions(-)
ui/vnc.c +91 -70
index d73966a..952e551 100644
@@ -3506,18 +3506,14 @@ void vnc_display_open(const char *id, Error **errp)
 {
     VncDisplay *vs = vnc_display_find(id);
     QemuOpts *opts = qemu_opts_find(&qemu_vnc_opts, id);
-    QemuOpts *sopts, *wsopts;
+    SocketAddress *saddr = NULL, *wsaddr = NULL;
     const char *share, *device_id;
     QemuConsole *con;
     bool password = false;
     bool reverse = false;
     const char *vnc;
-    const char *has_to;
     char *h;
-    bool has_ipv4 = false;
-    bool has_ipv6 = false;
     const char *credid;
-    const char *websocket;
     bool sasl = false;
 #ifdef CONFIG_VNC_SASL
     int saslErr;
@@ -3539,44 +3535,83 @@ void vnc_display_open(const char *id, Error **errp)
         return;
     }
 
-    sopts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
-    wsopts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
-
     h = strrchr(vnc, ':');
     if (h) {
-        char *host;
         size_t hlen = h - vnc;
 
-        if (vnc[0] == '[' && vnc[hlen - 1] == ']') {
-            host = g_strndup(vnc + 1, hlen - 2);
+        const char *websocket = qemu_opt_get(opts, "websocket");
+        int to = qemu_opt_get_number(opts, "to", 0);
+        bool has_ipv4 = qemu_opt_get_bool(opts, "ipv4", false);
+        bool has_ipv6 = qemu_opt_get_bool(opts, "ipv6", false);
+
+        saddr = g_new0(SocketAddress, 1);
+        if (websocket) {
+            if (!qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA1)) {
+                error_setg(errp,
+                           "SHA1 hash support is required for websockets");
+                goto fail;
+            }
+
+            wsaddr = g_new0(SocketAddress, 1);
+            vs->ws_enabled = true;
+        }
+
+        if (strncmp(vnc, "unix:", 5) == 0) {
+            saddr->kind = SOCKET_ADDRESS_KIND_UNIX;
+            saddr->q_unix = g_new0(UnixSocketAddress, 1);
+            saddr->q_unix->path = g_strdup(vnc + 5);
+
+            if (vs->ws_enabled) {
+                error_setg(errp, "UNIX sockets not supported with websock");
+                goto fail;
+            }
         } else {
-            host = g_strndup(vnc, hlen);
+            unsigned long long baseport;
+            saddr->kind = SOCKET_ADDRESS_KIND_INET;
+            saddr->inet = g_new0(InetSocketAddress, 1);
+            if (vnc[0] == '[' && vnc[hlen - 1] == ']') {
+                saddr->inet->host = g_strndup(vnc + 1, hlen - 2);
+            } else {
+                saddr->inet->host = g_strndup(vnc, hlen);
+            }
+            if (parse_uint_full(h + 1, &baseport, 10) < 0) {
+                error_setg(errp, "can't convert to a number: %s", h + 1);
+                goto fail;
+            }
+            if (baseport > 65535 ||
+                baseport + 5900 > 65535) {
+                error_setg(errp, "port %s out of range", h + 1);
+                goto fail;
+            }
+            saddr->inet->port = g_strdup_printf(
+                "%d", (int)baseport + 5900);
+
+            if (to) {
+                saddr->inet->has_to = true;
+                saddr->inet->to = to;
+            }
+            saddr->inet->ipv4 = saddr->inet->has_ipv4 = has_ipv4;
+            saddr->inet->ipv6 = saddr->inet->has_ipv6 = has_ipv6;
+
+            if (vs->ws_enabled) {
+                wsaddr->kind = SOCKET_ADDRESS_KIND_INET;
+                wsaddr->inet = g_new0(InetSocketAddress, 1);
+                wsaddr->inet->host = g_strdup(saddr->inet->host);
+                wsaddr->inet->port = g_strdup(websocket);
+
+                if (to) {
+                    wsaddr->inet->has_to = true;
+                    wsaddr->inet->to = to;
+                }
+                wsaddr->inet->ipv4 = wsaddr->inet->has_ipv4 = has_ipv4;
+                wsaddr->inet->ipv6 = wsaddr->inet->has_ipv6 = has_ipv6;
+            }
         }
-        qemu_opt_set(sopts, "host", host, &error_abort);
-        qemu_opt_set(wsopts, "host", host, &error_abort);
-        qemu_opt_set(sopts, "port", h+1, &error_abort);
-        g_free(host);
     } else {
         error_setg(errp, "no vnc port specified");
         goto fail;
     }
 
-    has_to = qemu_opt_get(opts, "to");
-    has_ipv4 = qemu_opt_get_bool(opts, "ipv4", false);
-    has_ipv6 = qemu_opt_get_bool(opts, "ipv6", false);
-    if (has_to) {
-        qemu_opt_set(sopts, "to", has_to, &error_abort);
-        qemu_opt_set(wsopts, "to", has_to, &error_abort);
-    }
-    if (has_ipv4) {
-        qemu_opt_set(sopts, "ipv4", "on", &error_abort);
-        qemu_opt_set(wsopts, "ipv4", "on", &error_abort);
-    }
-    if (has_ipv6) {
-        qemu_opt_set(sopts, "ipv6", "on", &error_abort);
-        qemu_opt_set(wsopts, "ipv6", "on", &error_abort);
-    }
-
     password = qemu_opt_get_bool(opts, "password", false);
     if (password) {
         if (fips_get_state()) {
@@ -3682,16 +3717,6 @@ void vnc_display_open(const char *id, Error **errp)
     }
     vs->connections_limit = qemu_opt_get_number(opts, "connections", 32);
 
-    websocket = qemu_opt_get(opts, "websocket");
-    if (websocket) {
-        vs->ws_enabled = true;
-        qemu_opt_set(wsopts, "port", websocket, &error_abort);
-        if (!qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA1)) {
-            error_setg(errp, "SHA1 hash support is required for websockets");
-            goto fail;
-        }
-    }
-
 #ifdef CONFIG_VNC_JPEG
     vs->lossy = qemu_opt_get_bool(opts, "lossy", false);
 #endif
@@ -3725,7 +3750,7 @@ void vnc_display_open(const char *id, Error **errp)
     }
 #endif
 
-    if (vnc_display_setup_auth(vs, password, sasl, websocket, errp) < 0) {
+    if (vnc_display_setup_auth(vs, password, sasl, vs->ws_enabled, errp) < 0) {
         goto fail;
     }
 
@@ -3770,37 +3795,32 @@ void vnc_display_open(const char *id, Error **errp)
         int csock;
         vs->lsock = -1;
         vs->lwebsock = -1;
-        if (strncmp(vnc, "unix:", 5) == 0) {
-            csock = unix_connect(vnc+5, errp);
-        } else {
-            csock = inet_connect(vnc, errp);
+        if (vs->ws_enabled) {
+            error_setg(errp, "Cannot use websockets in reverse mode");
+            goto fail;
         }
+        csock = socket_connect(saddr, errp,
+                               NULL, NULL);
         if (csock < 0) {
             goto fail;
         }
+        vs->is_unix = saddr->kind == SOCKET_ADDRESS_KIND_UNIX;
         vnc_connect(vs, csock, false, false);
     } else {
         /* listen for connects */
-        if (strncmp(vnc, "unix:", 5) == 0) {
-            vs->lsock = unix_listen(vnc+5, NULL, 0, errp);
-            if (vs->lsock < 0) {
-                goto fail;
-            }
-            vs->is_unix = true;
-        } else {
-            vs->lsock = inet_listen_opts(sopts, 5900, errp);
-            if (vs->lsock < 0) {
-                goto fail;
-            }
-            if (vs->ws_enabled) {
-                vs->lwebsock = inet_listen_opts(wsopts, 0, errp);
-                if (vs->lwebsock < 0) {
-                    if (vs->lsock != -1) {
-                        close(vs->lsock);
-                        vs->lsock = -1;
-                    }
-                    goto fail;
+        vs->lsock = socket_listen(saddr, errp);
+        if (vs->lsock < 0) {
+            goto fail;
+        }
+        vs->is_unix = saddr->kind == SOCKET_ADDRESS_KIND_UNIX;
+        if (vs->ws_enabled) {
+            vs->lwebsock = socket_listen(wsaddr, errp);
+            if (vs->lwebsock < 0) {
+                if (vs->lsock != -1) {
+                    close(vs->lsock);
+                    vs->lsock = -1;
                 }
+                goto fail;
             }
         }
         vs->enabled = true;
@@ -3810,13 +3830,14 @@ void vnc_display_open(const char *id, Error **errp)
                                 NULL, vs);
         }
     }
-    qemu_opts_del(sopts);
-    qemu_opts_del(wsopts);
+
+    qapi_free_SocketAddress(saddr);
+    qapi_free_SocketAddress(wsaddr);
     return;
 
 fail:
-    qemu_opts_del(sopts);
-    qemu_opts_del(wsopts);
+    qapi_free_SocketAddress(saddr);
+    qapi_free_SocketAddress(wsaddr);
     vs->enabled = false;
     vs->ws_enabled = false;
 }
Signature · 1 line
2.4.3
Reviewed-by on v2 4/16
#21 lore raw

Re: [Qemu-devel] [PATCH v2 04/16] ui: convert VNC startup code to use SocketAddress

Quoted 16 lines · Daniel P. Berrange

The VNC code is currently using QemuOpts to configure the sockets connections / listeners it needs. Convert it to use SocketAddress to bring it in line with modern QAPI based code elsewhere in QEMU.

---
 ui/vnc.c | 161 ++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 91 insertions(+), 70 deletions(-)
ui/vnc.c +0 -2
@@ -3539,44 +3535,83 @@ void vnc_display_open(const char *id, Error **errp)
         return;
     }
 
-    sopts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
-    wsopts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3543

Quoted 10 lines
ui/vnc.c +2 -4
-
     h = strrchr(vnc, ':');
     if (h) {
-        char *host;
         size_t hlen = h - vnc;
 
-        if (vnc[0] == '[' && vnc[hlen - 1] == ']') {
-            host = g_strndup(vnc + 1, hlen - 2);
+        const char *websocket = qemu_opt_get(opts, "websocket");
+        int to = qemu_opt_get_number(opts, "to", 0);

We really ought to improve the qapi notion of InetSocketAddress to allow { 'alternate':'StrOrInt', 'data': { 'i':'int', 's':'str' } } rather than only 'str' for port. But that's a project for another day. I guess things get a bit weird if "to" is present but doesn't parse as a number, but I don't think your patch is making things any worse.

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3561

Quoted 4 lines
ui/vnc.c +4 -0
+
+        if (strncmp(vnc, "unix:", 5) == 0) {
+            saddr->kind = SOCKET_ADDRESS_KIND_UNIX;
+            saddr->q_unix = g_new0(UnixSocketAddress, 1);

More clashes with my pending qapi patches; rebase fun for one of us :)

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3594

Quoted 6 lines
ui/vnc.c +6 -0
+            if (to) {
+                saddr->inet->has_to = true;
+                saddr->inet->to = to;
+            }
+            saddr->inet->ipv4 = saddr->inet->has_ipv4 = has_ipv4;
+            saddr->inet->ipv6 = saddr->inet->has_ipv6 = has_ipv6;

Do we want to specify has_ipvX as true even when setting inet->ipvX to false?

Quoted 4 lines
ui/vnc.c +0 -0
@@ -3770,37 +3795,32 @@ void vnc_display_open(const char *id, Error **errp)
         int csock;
         vs->lsock = -1;
         vs->lwebsock = -1;

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3803

Quoted 10 lines
ui/vnc.c +5 -4
-        if (strncmp(vnc, "unix:", 5) == 0) {
-            csock = unix_connect(vnc+5, errp);
-        } else {
-            csock = inet_connect(vnc, errp);
+        if (vs->ws_enabled) {
+            error_setg(errp, "Cannot use websockets in reverse mode");
+            goto fail;
         }
+        csock = socket_connect(saddr, errp,
+                               NULL, NULL);

Looks like the line-wrapping isn't needed here.

Overall, looks like a sane conversion.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#22 lore raw

Re: [Qemu-devel] [PATCH v2 04/16] ui: convert VNC startup code to use SocketAddress

Quoted 49 lines · Eric Blake
Quoted 16 lines · Daniel P. Berrange

The VNC code is currently using QemuOpts to configure the sockets connections / listeners it needs. Convert it to use SocketAddress to bring it in line with modern QAPI based code elsewhere in QEMU.

---
 ui/vnc.c | 161 ++++++++++++++++++++++++++++++++++++---------------------------
 1 file changed, 91 insertions(+), 70 deletions(-)
ui/vnc.c +0 -2
@@ -3539,44 +3535,83 @@ void vnc_display_open(const char *id, Error **errp)
         return;
     }
 
-    sopts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);
-    wsopts = qemu_opts_create(&socket_optslist, NULL, 0, &error_abort);

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3543

Quoted 10 lines
ui/vnc.c +2 -4
-
     h = strrchr(vnc, ':');
     if (h) {
-        char *host;
         size_t hlen = h - vnc;
 
-        if (vnc[0] == '[' && vnc[hlen - 1] == ']') {
-            host = g_strndup(vnc + 1, hlen - 2);
+        const char *websocket = qemu_opt_get(opts, "websocket");
+        int to = qemu_opt_get_number(opts, "to", 0);

We really ought to improve the qapi notion of InetSocketAddress to allow { 'alternate':'StrOrInt', 'data': { 'i':'int', 's':'str' } } rather than only 'str' for port. But that's a project for another day. I guess things get a bit weird if "to" is present but doesn't parse as a number, but I don't think your patch is making things any worse.

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3561

Quoted 4 lines
ui/vnc.c +4 -0
+
+        if (strncmp(vnc, "unix:", 5) == 0) {
+            saddr->kind = SOCKET_ADDRESS_KIND_UNIX;
+            saddr->q_unix = g_new0(UnixSocketAddress, 1);

More clashes with my pending qapi patches; rebase fun for one of us :)

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3594

Quoted 6 lines
ui/vnc.c +6 -0
+            if (to) {
+                saddr->inet->has_to = true;
+                saddr->inet->to = to;
+            }
+            saddr->inet->ipv4 = saddr->inet->has_ipv4 = has_ipv4;
+            saddr->inet->ipv6 = saddr->inet->has_ipv6 = has_ipv6;
Quoted 2 lines

Do we want to specify has_ipvX as true even when setting inet->ipvX to false?

This saddr instance is passed into 'socket_connect' which then converts it back into a QemuOpts object using

    bool ipv4 = addr->has_ipv4 && addr->ipv4;

So, we don't need to set has_ipvX to true, when ipvX is false.

I'll be so happy to finally kill QemuOpts from the sockets code and use SocketAddress everywhere....

Quoted 19 lines
Quoted 6 lines
ui/vnc.c +0 -0
@@ -3770,37 +3795,32 @@ void vnc_display_open(const char *id, Error **errp)
         int csock;
         vs->lsock = -1;
         vs->lwebsock = -1;

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3803

Quoted 10 lines
ui/vnc.c +5 -4
-        if (strncmp(vnc, "unix:", 5) == 0) {
-            csock = unix_connect(vnc+5, errp);
-        } else {
-            csock = inet_connect(vnc, errp);
+        if (vs->ws_enabled) {
+            error_setg(errp, "Cannot use websockets in reverse mode");
+            goto fail;
         }
+        csock = socket_connect(saddr, errp,
+                               NULL, NULL);

Looks like the line-wrapping isn't needed here.

Quoted 3 lines

Overall, looks like a sane conversion.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#23 lore raw

Re: [Qemu-devel] [PATCH v2 04/16] ui: convert VNC startup code to use SocketAddress

Quoted 18 lines · Daniel P. Berrange
Quoted 14 lines · Eric Blake

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3594

Quoted 12 lines · Daniel P. Berrange

The VNC code is currently using QemuOpts to configure the sockets connections / listeners it needs. Convert it to use SocketAddress to bring it in line with modern QAPI based code elsewhere in QEMU.

ui/vnc.c +6 -0
+            if (to) {
+                saddr->inet->has_to = true;
+                saddr->inet->to = to;
+            }
+            saddr->inet->ipv4 = saddr->inet->has_ipv4 = has_ipv4;
+            saddr->inet->ipv6 = saddr->inet->has_ipv6 = has_ipv6;
Quoted 2 lines

Do we want to specify has_ipvX as true even when setting inet->ipvX to false?

Quoted 6 lines

This saddr instance is passed into 'socket_connect' which then converts it back into a QemuOpts object using

    bool ipv4 = addr->has_ipv4 && addr->ipv4;

So, we don't need to set has_ipvX to true, when ipvX is false.

That is not the *only* thing that inet_addr_to_opts does with the has_* flags... this kind of thing can be the difference between "force ipv4" and "use ipv4 or ipv6".

-- PMM

#24 lore raw

Re: [Qemu-devel] [PATCH v2 04/16] ui: convert VNC startup code to use SocketAddress

Quoted 22 lines · Peter Maydell
Quoted 21 lines · Daniel P. Berrange
Quoted 14 lines · Eric Blake

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3594

Quoted 12 lines · Daniel P. Berrange

The VNC code is currently using QemuOpts to configure the sockets connections / listeners it needs. Convert it to use SocketAddress to bring it in line with modern QAPI based code elsewhere in QEMU.

ui/vnc.c +6 -0
+            if (to) {
+                saddr->inet->has_to = true;
+                saddr->inet->to = to;
+            }
+            saddr->inet->ipv4 = saddr->inet->has_ipv4 = has_ipv4;
+            saddr->inet->ipv6 = saddr->inet->has_ipv6 = has_ipv6;
Quoted 2 lines

Do we want to specify has_ipvX as true even when setting inet->ipvX to false?

This saddr instance is passed into 'socket_connect' which then converts it back into a QemuOpts object using

Quoted 7 lines
Quoted 3 lines
    bool ipv4 = addr->has_ipv4 && addr->ipv4;

So, we don't need to set has_ipvX to true, when ipvX is false.

That is not the *only* thing that inet_addr_to_opts does with the has_* flags... this kind of thing can be the difference between "force ipv4" and "use ipv4 or ipv6".

The original code which used QemuOpts directly had this logic:

inet_listen_opts / inet_connect_opts use this logic:

    ai.ai_family = PF_UNSPEC;
    ....
    if (qemu_opt_get_bool(opts, "ipv4", 0))
        ai.ai_family = PF_INET;
    if (qemu_opt_get_bool(opts, "ipv6", 0))
        ai.ai_family = PF_INET6;

IOW, these methods treat ipv4 being omitted, as equivalent to ipv4=off.

Thus the existing VNC -> qemu-sockets code has this logic:

VNC | qemu-sockets
QemuOpts | ai_family
----------------------------
ipv4 ipv6 |
----------------------------

  -      -    |  PF_UNSPEC
  -      off  |  PF_UNSPEC
  -      on   |  PF_INET6
  off    -    |  PF_UNSPEC
  off    off  |  PF_UNSPEC
  off    on   |  PF_INET6
  on     -    |  PF_INET
  on     off  |  PF_INET
  on     on   |  PF_INET6

My patch, which also does not distinguish ipv4=off from ipv4 omitted has the following logic, at various stages of conversion between QemuOpts & QAPI SocketAddress:

     VNC      |          VNC                 | qemu-sockets | qemu-sockets
   QemuOpts   |      QAPI  SocketAddress     |  QemuOpts    |  ai_family
 -------------------------------------------------------------------------
  ipv4   ipv6 |  has_ipv4 ipv4 has_ipv6 ipv6 |   ipv4 ipv6  |
 -------------------------------------------------------------------------
  -      -    |  f        f    f        f    |  -     -     | PF_UNSPEC
  -      off  |  f        f    f        f    |  -     -     | PF_UNSPEC
  -      on   |  f        f    t        t    |  off   on    | PF_INET6
  off    -    |  f        f    f        f    |  -     -     | PF_UNSPEC
  off    off  |  f        f    f        f    |  -     -     | PF_UNSPEC
  off    on   |  f        f    t        t    |  off   on    | PF_INET6
  on     -    |  t        t    f        f    |  on    off   | PF_INET
  on     off  |  t        t    f        f    |  on    off   | PF_INET
  on     on   |  t        t    t        t    |  on    on    | PF_INET6

So, unless I've missed something, the final ai_family is set the same way before & after my patch, for all combinations of VNC ipv4/ipv6 CLI options.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#25 lore raw

Re: [Qemu-devel] [PATCH v2 04/16] ui: convert VNC startup code to use SocketAddress

Quoted 82 lines · Daniel P. Berrange
Quoted 22 lines · Peter Maydell
Quoted 21 lines · Daniel P. Berrange
Quoted 14 lines · Eric Blake

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3594

Quoted 12 lines · Daniel P. Berrange

The VNC code is currently using QemuOpts to configure the sockets connections / listeners it needs. Convert it to use SocketAddress to bring it in line with modern QAPI based code elsewhere in QEMU.

ui/vnc.c +6 -0
+            if (to) {
+                saddr->inet->has_to = true;
+                saddr->inet->to = to;
+            }
+            saddr->inet->ipv4 = saddr->inet->has_ipv4 = has_ipv4;
+            saddr->inet->ipv6 = saddr->inet->has_ipv6 = has_ipv6;
Quoted 2 lines

Do we want to specify has_ipvX as true even when setting inet->ipvX to false?

This saddr instance is passed into 'socket_connect' which then converts it back into a QemuOpts object using

Quoted 7 lines
Quoted 3 lines
    bool ipv4 = addr->has_ipv4 && addr->ipv4;

So, we don't need to set has_ipvX to true, when ipvX is false.

That is not the *only* thing that inet_addr_to_opts does with the has_* flags... this kind of thing can be the difference between "force ipv4" and "use ipv4 or ipv6".

The original code which used QemuOpts directly had this logic:

inet_listen_opts / inet_connect_opts use this logic:

    ai.ai_family = PF_UNSPEC;
    ....
    if (qemu_opt_get_bool(opts, "ipv4", 0))
        ai.ai_family = PF_INET;
    if (qemu_opt_get_bool(opts, "ipv6", 0))
        ai.ai_family = PF_INET6;

IOW, these methods treat ipv4 being omitted, as equivalent to ipv4=off.

Thus the existing VNC -> qemu-sockets code has this logic:

VNC | qemu-sockets
QemuOpts | ai_family
----------------------------
ipv4 ipv6 |
----------------------------

  -      -    |  PF_UNSPEC
  -      off  |  PF_UNSPEC
  -      on   |  PF_INET6
  off    -    |  PF_UNSPEC
  off    off  |  PF_UNSPEC
  off    on   |  PF_INET6
  on     -    |  PF_INET
  on     off  |  PF_INET
  on     on   |  PF_INET6

My patch, which also does not distinguish ipv4=off from ipv4 omitted has the following logic, at various stages of conversion between QemuOpts & QAPI SocketAddress:

     VNC      |          VNC                 | qemu-sockets | qemu-sockets
   QemuOpts   |      QAPI  SocketAddress     |  QemuOpts    |  ai_family
 -------------------------------------------------------------------------
  ipv4   ipv6 |  has_ipv4 ipv4 has_ipv6 ipv6 |   ipv4 ipv6  |
 -------------------------------------------------------------------------
  -      -    |  f        f    f        f    |  -     -     | PF_UNSPEC
  -      off  |  f        f    f        f    |  -     -     | PF_UNSPEC
  -      on   |  f        f    t        t    |  off   on    | PF_INET6
  off    -    |  f        f    f        f    |  -     -     | PF_UNSPEC
  off    off  |  f        f    f        f    |  -     -     | PF_UNSPEC
  off    on   |  f        f    t        t    |  off   on    | PF_INET6
  on     -    |  t        t    f        f    |  on    off   | PF_INET
  on     off  |  t        t    f        f    |  on    off   | PF_INET
  on     on   |  t        t    t        t    |  on    on    | PF_INET6
Quoted 3 lines

So, unless I've missed something, the final ai_family is set the same way before & after my patch, for all combinations of VNC ipv4/ipv6 CLI options.

I think you're right that this patch doesn't change anything, but doesn't it mean that vnc still has one of the bugs we fixed in commit b77e7c8e99f9a: if you say 'ipv6=off' it will give you a PF_UNSPEC rather than an PF_INET socket? (In particular on Windows PF_UNSPEC will get you ipv6, which is exactly what the user asked not to get...)

Since that's a pre-existing bug I guess we can fix it in a subsequent patch.

thanks
-- PMM

#26 lore raw

Re: [Qemu-devel] [PATCH v2 04/16] ui: convert VNC startup code to use SocketAddress

Quoted 94 lines · Peter Maydell
Quoted 82 lines · Daniel P. Berrange
Quoted 22 lines · Peter Maydell
Quoted 21 lines · Daniel P. Berrange
Quoted 14 lines · Eric Blake

ui/vnc.c void vnc_display_open(const char *id, Error **errp) · line 3594

Quoted 12 lines · Daniel P. Berrange

The VNC code is currently using QemuOpts to configure the sockets connections / listeners it needs. Convert it to use SocketAddress to bring it in line with modern QAPI based code elsewhere in QEMU.

ui/vnc.c +6 -0
+            if (to) {
+                saddr->inet->has_to = true;
+                saddr->inet->to = to;
+            }
+            saddr->inet->ipv4 = saddr->inet->has_ipv4 = has_ipv4;
+            saddr->inet->ipv6 = saddr->inet->has_ipv6 = has_ipv6;
Quoted 2 lines

Do we want to specify has_ipvX as true even when setting inet->ipvX to false?

This saddr instance is passed into 'socket_connect' which then converts it back into a QemuOpts object using

Quoted 7 lines
Quoted 3 lines
    bool ipv4 = addr->has_ipv4 && addr->ipv4;

So, we don't need to set has_ipvX to true, when ipvX is false.

That is not the *only* thing that inet_addr_to_opts does with the has_* flags... this kind of thing can be the difference between "force ipv4" and "use ipv4 or ipv6".

The original code which used QemuOpts directly had this logic:

inet_listen_opts / inet_connect_opts use this logic:

    ai.ai_family = PF_UNSPEC;
    ....
    if (qemu_opt_get_bool(opts, "ipv4", 0))
        ai.ai_family = PF_INET;
    if (qemu_opt_get_bool(opts, "ipv6", 0))
        ai.ai_family = PF_INET6;

IOW, these methods treat ipv4 being omitted, as equivalent to ipv4=off.

Thus the existing VNC -> qemu-sockets code has this logic:

VNC | qemu-sockets
QemuOpts | ai_family
----------------------------
ipv4 ipv6 |
----------------------------

  -      -    |  PF_UNSPEC
  -      off  |  PF_UNSPEC
  -      on   |  PF_INET6
  off    -    |  PF_UNSPEC
  off    off  |  PF_UNSPEC
  off    on   |  PF_INET6
  on     -    |  PF_INET
  on     off  |  PF_INET
  on     on   |  PF_INET6

My patch, which also does not distinguish ipv4=off from ipv4 omitted has the following logic, at various stages of conversion between QemuOpts & QAPI SocketAddress:

     VNC      |          VNC                 | qemu-sockets | qemu-sockets
   QemuOpts   |      QAPI  SocketAddress     |  QemuOpts    |  ai_family
 -------------------------------------------------------------------------
  ipv4   ipv6 |  has_ipv4 ipv4 has_ipv6 ipv6 |   ipv4 ipv6  |
 -------------------------------------------------------------------------
  -      -    |  f        f    f        f    |  -     -     | PF_UNSPEC
  -      off  |  f        f    f        f    |  -     -     | PF_UNSPEC
  -      on   |  f        f    t        t    |  off   on    | PF_INET6
  off    -    |  f        f    f        f    |  -     -     | PF_UNSPEC
  off    off  |  f        f    f        f    |  -     -     | PF_UNSPEC
  off    on   |  f        f    t        t    |  off   on    | PF_INET6
  on     -    |  t        t    f        f    |  on    off   | PF_INET
  on     off  |  t        t    f        f    |  on    off   | PF_INET
  on     on   |  t        t    t        t    |  on    on    | PF_INET6
Quoted 3 lines

So, unless I've missed something, the final ai_family is set the same way before & after my patch, for all combinations of VNC ipv4/ipv6 CLI options.

I think you're right that this patch doesn't change anything, but doesn't it mean that vnc still has one of the bugs we fixed in commit b77e7c8e99f9a: if you say 'ipv6=off' it will give you a PF_UNSPEC rather than an PF_INET socket? (In particular on Windows PF_UNSPEC will get you ipv6, which is exactly what the user asked not to get...)

Quoted 2 lines

Since that's a pre-existing bug I guess we can fix it in a subsequent patch.

Hmm, yes, you are correct in that - I can certainly look at creating a further patch to fix that bug.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#27 lore raw

PATCH v2 5/16 osdep: add qemu_fork() wrapper for safely handling signals

In reply to Daniel P. Berrange

When using regular fork() the child process of course inherits all the parents' signal handlers. If the child then proceeds to close() any open file descriptors, it may break some of those registered signal handlers. The child generally does not want to ever run any of the signal handlers tha parent may have installed in the short time before it exec's. The parent may also have blocked various signals which the child process will want enabled.

This introduces a wrapper qemu_fork() that takes care to sanitize signal handling across fork. Before forking it blocks all signals in the parent thread. After fork returns, the parent unblocks the signals and carries on as usual. The child, however, resets all the signal handlers back to their defaults before it unblocks signals. The child process can now exec the binary in a "clean" signal environment.

---
 include/qemu/osdep.h | 16 ++++++++++++
 util/oslib-posix.c   | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 util/oslib-win32.c   |  9 +++++++
 3 files changed, 96 insertions(+)
include/qemu/osdep.h +16 -0
index ef21efb..b568424 100644
@@ -69,6 +69,8 @@
 #include "sysemu/os-posix.h"
 #endif
 
+#include "qapi/error.h"
+
 #if defined(CONFIG_SOLARIS) && CONFIG_SOLARIS_VERSION < 10
 /* [u]int_fast*_t not in <sys/int_types.h> */
 typedef unsigned char           uint_fast8_t;
@@ -286,4 +288,18 @@ void os_mem_prealloc(int fd, char *area, size_t sz);
 
 int qemu_read_password(char *buf, int buf_size);
 
+/**
+ * qemu_fork:
+ *
+ * A version of fork that avoids signal handler race
+ * conditions that can lead to child process getting
+ * signals that are otherwise only expected by the
+ * parent. It also resets all signal handlers to the
+ * default settings.
+ *
+ * Returns 0 to child process, pid number to parent
+ * or -1 on failure.
+ */
+pid_t qemu_fork(Error **errp);
+
 #endif
util/oslib-posix.c +71 -0

74 lines not on this page · raw message

util/oslib-win32.c +9 -0
index 08f5a9c..09f9e98 100644
@@ -496,3 +496,12 @@ int qemu_read_password(char *buf, int buf_size)
     buf[i] = '\0';
     return 0;
 }
+
+
+pid_t qemu_fork(Error **errp)
+{
+    errno = ENOSYS;
+    error_setg_errno(errp, errno,
+                     "cannot fork child process");
+    return -1;
+}
Signature · 1 line
2.4.3
Reviewed-by on v2 5/16
#28 lore raw

Re: [Qemu-devel] [PATCH v2 05/16] osdep: add qemu_fork() wrapper for safely handling signals

Quoted 5 lines · Daniel P. Berrange

When using regular fork() the child process of course inherits all the parents' signal handlers. If the child then proceeds to close() any open file descriptors, it may break some of those registered signal handlers. The child generally does not want to ever run any of the signal handlers tha parent may have installed

s/tha/that the/

Quoted 11 lines

in the short time before it exec's. The parent may also have blocked various signals which the child process will want enabled.

This introduces a wrapper qemu_fork() that takes care to sanitize signal handling across fork. Before forking it blocks all signals in the parent thread. After fork returns, the parent unblocks the signals and carries on as usual. The child, however, resets all the signal handlers back to their defaults before it unblocks signals. The child process can now exec the binary in a "clean" signal environment.

Quoted 6 lines
---
 include/qemu/osdep.h | 16 ++++++++++++
 util/oslib-posix.c   | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 util/oslib-win32.c   |  9 +++++++
 3 files changed, 96 insertions(+)

Looks very similar to libvirt's fork() wrapper :)

util/oslib-posix.c int qemu_read_password(char *buf, int buf_size) · line 548

Quoted 6 lines
util/oslib-posix.c +6 -0
+        for (i = 1; i < NSIG; i++) {
+            /* Only possible errors are EFAULT or EINVAL The former
+             * won't happen, the latter we expect, so no need to check
+             * return value */
+            (void)sigaction(i, &sig_action, NULL);
+        }

Libvirt gets to rely on gnulib for a guaranteed definition of NSIG. But POSIX doesn't document it, and I'm not sure whether it is present on all platforms qemu targets. I guess we'll find out soon enough.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#29 lore raw

PATCH v2 6/16 coroutine: move into libqemuutil.a library

In reply to Daniel P. Berrange

The coroutine files are currently referenced by the block-obj-y variable. The coroutine functionality though is already used by more than just the block code. eg migration code uses coroutine yield. In the future the I/O channel code will also use the coroutine yield functionality. Since the coroutine code is nicely self-contained it can be easily built as part of the libqemuutil.a library, making it widely available.

The headers are also moved into include/qemu, instead of the include/block directory, since they are now part of the util codebase, and the impl was never in the block/ directory either.

---
 MAINTAINERS                                             | 7 +++++++
 Makefile.objs                                           | 4 ----
 block.c                                                 | 2 +-
 block/qcow2.h                                           | 2 +-
 block/vdi.c                                             | 2 +-
 block/write-threshold.c                                 | 2 +-
 blockjob.c                                              | 2 +-
 hw/9pfs/codir.c                                         | 2 +-
 hw/9pfs/cofile.c                                        | 2 +-
 hw/9pfs/cofs.c                                          | 2 +-
 hw/9pfs/coxattr.c                                       | 2 +-
 hw/9pfs/virtio-9p-coth.c                                | 2 +-
 hw/9pfs/virtio-9p-coth.h                                | 2 +-
 hw/9pfs/virtio-9p.h                                     | 2 +-
 include/block/block.h                                   | 2 +-
 include/block/block_int.h                               | 2 +-
 include/{block => qemu}/coroutine.h                     | 0
 include/{block => qemu}/coroutine_int.h                 | 2 +-
 migration/qemu-file-buf.c                               | 2 +-
 migration/qemu-file-stdio.c                             | 2 +-
 migration/qemu-file-unix.c                              | 2 +-
 migration/qemu-file.c                                   | 2 +-
 migration/rdma.c                                        | 2 +-
 nbd.c                                                   | 2 +-
 tests/test-coroutine.c                                  | 4 ++--
 tests/test-vmstate.c                                    | 2 +-
 thread-pool.c                                           | 2 +-
 util/Makefile.objs                                      | 3 +++
 coroutine-gthread.c => util/coroutine-gthread.c         | 2 +-
 coroutine-sigaltstack.c => util/coroutine-sigaltstack.c | 2 +-
 coroutine-ucontext.c => util/coroutine-ucontext.c       | 2 +-
 coroutine-win32.c => util/coroutine-win32.c             | 2 +-
 qemu-coroutine-io.c => util/qemu-coroutine-io.c         | 2 +-
 qemu-coroutine-lock.c => util/qemu-coroutine-lock.c     | 4 ++--
 qemu-coroutine-sleep.c => util/qemu-coroutine-sleep.c   | 2 +-
 qemu-coroutine.c => util/qemu-coroutine.c               | 4 ++--
 36 files changed, 45 insertions(+), 39 deletions(-)
 rename include/{block => qemu}/coroutine.h (100%)
 rename include/{block => qemu}/coroutine_int.h (98%)
 rename coroutine-gthread.c => util/coroutine-gthread.c (99%)
 rename coroutine-sigaltstack.c => util/coroutine-sigaltstack.c (99%)
 rename coroutine-ucontext.c => util/coroutine-ucontext.c (99%)
 rename coroutine-win32.c => util/coroutine-win32.c (98%)
 rename qemu-coroutine-io.c => util/qemu-coroutine-io.c (99%)
 rename qemu-coroutine-lock.c => util/qemu-coroutine-lock.c (98%)
 rename qemu-coroutine-sleep.c => util/qemu-coroutine-sleep.c (96%)
 rename qemu-coroutine.c => util/qemu-coroutine.c (98%)
MAINTAINERS +7 -0
index 9bde832..426d0ba 100644
@@ -1141,6 +1141,13 @@ F: crypto/
 F: include/crypto/
 F: tests/test-crypto-*
 
+Coroutines
+M: Stefan Hajnoczi <[email protected]>
+M: Kevin Wolf <[email protected]>
+F: util/*coroutine*
+F: include/qemu/coroutine*
+F: tests/test-coroutine.c
+
 Usermode Emulation
 ------------------
 Overall
Makefile.objs +0 -4
index bc43e5c..ecfe03c 100644
@@ -15,10 +15,6 @@ block-obj-$(CONFIG_WIN32) += aio-win32.o
 block-obj-y += block/
 block-obj-y += qemu-io-cmds.o
 
-block-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
-block-obj-y += qemu-coroutine-sleep.o
-block-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o
-
 block-obj-m = block/
 
 #######################################################################
block.c +1 -1
index 1f90b47..dfbee19 100644
@@ -33,7 +33,7 @@
 #include "sysemu/block-backend.h"
 #include "sysemu/sysemu.h"
 #include "qemu/notify.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "block/qapi.h"
 #include "qmp-commands.h"
 #include "qemu/timer.h"
block/qcow2.h +1 -1
index d700bf1..27b919c 100644
@@ -26,7 +26,7 @@
 #define BLOCK_QCOW2_H
 
 #include "crypto/cipher.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 
 //#define DEBUG_ALLOC
 //#define DEBUG_ALLOC2
block/vdi.c +1 -1
index 062a654..d662f41 100644
@@ -53,7 +53,7 @@
 #include "block/block_int.h"
 #include "qemu/module.h"
 #include "migration/migration.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 
 #if defined(CONFIG_UUID)
 #include <uuid/uuid.h>
block/write-threshold.c +1 -1
index a53c1f5..0fe3891 100644
@@ -11,7 +11,7 @@
  */
 
 #include "block/block_int.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "block/write-threshold.h"
 #include "qemu/notify.h"
 #include "qapi-event.h"
blockjob.c +1 -1
index 62bb906..dc42d15 100644
@@ -31,7 +31,7 @@
 #include "block/block_int.h"
 #include "qapi/qmp/qerror.h"
 #include "qapi/qmp/qjson.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "qmp-commands.h"
 #include "qemu/timer.h"
 #include "qapi-event.h"
hw/9pfs/codir.c +1 -1
index 65ad329..ec9cc7f 100644
@@ -14,7 +14,7 @@
 
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "virtio-9p-coth.h"
 
 int v9fs_co_readdir_r(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent *dent,
hw/9pfs/cofile.c +1 -1
index 2efebf3..7cb55ee 100644
@@ -14,7 +14,7 @@
 
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "virtio-9p-coth.h"
 
 int v9fs_co_st_gen(V9fsPDU *pdu, V9fsPath *path, mode_t st_mode,
hw/9pfs/cofs.c +1 -1
index 42ee614..e1953a9 100644
@@ -14,7 +14,7 @@
 
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "virtio-9p-coth.h"
 
 static ssize_t __readlink(V9fsState *s, V9fsPath *path, V9fsString *buf)
hw/9pfs/coxattr.c +1 -1
index 18ee08d..55c0d23 100644
@@ -14,7 +14,7 @@
 
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "virtio-9p-coth.h"
 
 int v9fs_co_llistxattr(V9fsPDU *pdu, V9fsPath *path, void *value, size_t size)
hw/9pfs/virtio-9p-coth.c +1 -1
index 8185c53..5057f8d 100644
@@ -15,7 +15,7 @@
 #include "fsdev/qemu-fsdev.h"
 #include "qemu/thread.h"
 #include "qemu/event_notifier.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "virtio-9p-coth.h"
 
 /* v9fs glib thread pool */
hw/9pfs/virtio-9p-coth.h +1 -1
index 4f51b25..0fbe49a 100644
@@ -16,7 +16,7 @@
 #define _QEMU_VIRTIO_9P_COTH_H
 
 #include "qemu/thread.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "virtio-9p.h"
 #include <glib.h>
 
hw/9pfs/virtio-9p.h +1 -1
index 2e7d488..d7a4dc1 100644
@@ -13,7 +13,7 @@
 #include "fsdev/file-op-9p.h"
 #include "fsdev/virtio-9p-marshal.h"
 #include "qemu/thread.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 
 enum {
     P9_TLERROR = 6,
include/block/block.h +1 -1
index 2dd6630..623fed3 100644
@@ -4,7 +4,7 @@
 #include "block/aio.h"
 #include "qemu-common.h"
 #include "qemu/option.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "block/accounting.h"
 #include "qapi/qmp/qobject.h"
 #include "qapi-types.h"
include/block/block_int.h +1 -1
index 14ad4c3..c37ed77 100644
@@ -28,7 +28,7 @@
 #include "block/block.h"
 #include "qemu/option.h"
 #include "qemu/queue.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "qemu/timer.h"
 #include "qapi-types.h"
 #include "qemu/hbitmap.h"
include/qemu/coroutine.h renamed from include/block/coroutine.h +0 -0
similarity index 100%
rename from include/block/coroutine.h
rename to include/qemu/coroutine.h
include/qemu/coroutine_int.h renamed from include/block/coroutine_int.h +1 -1
similarity index 98%
rename from include/block/coroutine_int.h
rename to include/qemu/coroutine_int.h
index 9aa1aae..42d6838 100644
@@ -26,7 +26,7 @@
 #define QEMU_COROUTINE_INT_H
 
 #include "qemu/queue.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 
 typedef enum {
     COROUTINE_YIELD = 1,
migration/qemu-file-buf.c +1 -1
index e3fd085..49516b8 100644
@@ -29,7 +29,7 @@
 #include "qemu/error-report.h"
 #include "qemu/iov.h"
 #include "qemu/sockets.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "migration/migration.h"
 #include "migration/qemu-file.h"
 #include "migration/qemu-file-internal.h"
migration/qemu-file-stdio.c +1 -1
index 889ffb3..9bde9db 100644
@@ -22,7 +22,7 @@
  * THE SOFTWARE.
  */
 #include "qemu-common.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "migration/qemu-file.h"
 
 typedef struct QEMUFileStdio {
migration/qemu-file-unix.c +1 -1
index bf7a0e4..809bf07 100644
@@ -24,7 +24,7 @@
 #include "qemu-common.h"
 #include "qemu/iov.h"
 #include "qemu/sockets.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "migration/qemu-file.h"
 #include "migration/qemu-file-internal.h"
 
migration/qemu-file.c +1 -1
index 49addf6..df49023 100644
@@ -26,7 +26,7 @@
 #include "qemu/error-report.h"
 #include "qemu/iov.h"
 #include "qemu/sockets.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "migration/migration.h"
 #include "migration/qemu-file.h"
 #include "migration/qemu-file-internal.h"
migration/rdma.c +1 -1
index 7a7176f..553fbd7 100644
@@ -19,7 +19,7 @@
 #include "qemu/main-loop.h"
 #include "qemu/sockets.h"
 #include "qemu/bitmap.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/socket.h>
nbd.c +1 -1
index 07240bd..1724a1f 100644
@@ -19,7 +19,7 @@
 #include "block/nbd.h"
 #include "sysemu/block-backend.h"
 
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 
 #include <errno.h>
 #include <string.h>
tests/test-coroutine.c +2 -2
index b552d9f..f5951cb 100644
@@ -12,8 +12,8 @@
  */
 
 #include <glib.h>
-#include "block/coroutine.h"
-#include "block/coroutine_int.h"
+#include "qemu/coroutine.h"
+#include "qemu/coroutine_int.h"
 
 /*
  * Check that qemu_in_coroutine() works
tests/test-vmstate.c +1 -1
index 1d620e0..4d13bd0 100644
@@ -27,7 +27,7 @@
 #include "qemu-common.h"
 #include "migration/migration.h"
 #include "migration/vmstate.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 
 static char temp_file[] = "/tmp/vmst.test.XXXXXX";
 static int temp_fd;
thread-pool.c +1 -1
index ac909f4..402c778 100644
@@ -18,7 +18,7 @@
 #include "qemu/queue.h"
 #include "qemu/thread.h"
 #include "qemu/osdep.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "trace.h"
 #include "block/thread-pool.h"
 #include "qemu/main-loop.h"
util/Makefile.objs +3 -0
index 114d657..d8d7e7a 100644
@@ -18,3 +18,6 @@ util-obj-y += getauxval.o
 util-obj-y += readline.o
 util-obj-y += rfifolock.o
 util-obj-y += rcu.o
+util-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
+util-obj-y += qemu-coroutine-sleep.o
+util-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o
util/coroutine-gthread.c renamed from coroutine-gthread.c +1 -1
similarity index 99%
rename from coroutine-gthread.c
rename to util/coroutine-gthread.c
index 6bd6d6b..0bcd778 100644
@@ -20,7 +20,7 @@
 
 #include <glib.h>
 #include "qemu-common.h"
-#include "block/coroutine_int.h"
+#include "qemu/coroutine_int.h"
 
 typedef struct {
     Coroutine base;
util/coroutine-sigaltstack.c renamed from coroutine-sigaltstack.c +1 -1
similarity index 99%
rename from coroutine-sigaltstack.c
rename to util/coroutine-sigaltstack.c
index 63519ff..39842a4 100644
@@ -31,7 +31,7 @@
 #include <pthread.h>
 #include <signal.h>
 #include "qemu-common.h"
-#include "block/coroutine_int.h"
+#include "qemu/coroutine_int.h"
 
 typedef struct {
     Coroutine base;
util/coroutine-ucontext.c renamed from coroutine-ucontext.c +1 -1
similarity index 99%
rename from coroutine-ucontext.c
rename to util/coroutine-ucontext.c
index 259fcb4..26cbebb 100644
@@ -27,7 +27,7 @@
 #include <stdint.h>
 #include <ucontext.h>
 #include "qemu-common.h"
-#include "block/coroutine_int.h"
+#include "qemu/coroutine_int.h"
 
 #ifdef CONFIG_VALGRIND_H
 #include <valgrind/valgrind.h>
util/coroutine-win32.c renamed from coroutine-win32.c +1 -1
similarity index 98%
rename from coroutine-win32.c
rename to util/coroutine-win32.c
index 17ace37..4f922c5 100644
@@ -23,7 +23,7 @@
  */
 
 #include "qemu-common.h"
-#include "block/coroutine_int.h"
+#include "qemu/coroutine_int.h"
 
 typedef struct
 {
util/qemu-coroutine-io.c renamed from qemu-coroutine-io.c +1 -1
similarity index 99%
rename from qemu-coroutine-io.c
rename to util/qemu-coroutine-io.c
index 28dc735..e1eae73 100644
@@ -24,7 +24,7 @@
  */
 #include "qemu-common.h"
 #include "qemu/sockets.h"
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "qemu/iov.h"
 #include "qemu/main-loop.h"
 
util/qemu-coroutine-lock.c renamed from qemu-coroutine-lock.c +2 -2
similarity index 98%
rename from qemu-coroutine-lock.c
rename to util/qemu-coroutine-lock.c
index 6b49033..130ee19 100644
@@ -23,8 +23,8 @@
  */
 
 #include "qemu-common.h"
-#include "block/coroutine.h"
-#include "block/coroutine_int.h"
+#include "qemu/coroutine.h"
+#include "qemu/coroutine_int.h"
 #include "qemu/queue.h"
 #include "trace.h"
 
util/qemu-coroutine-sleep.c renamed from qemu-coroutine-sleep.c +1 -1
similarity index 96%
rename from qemu-coroutine-sleep.c
rename to util/qemu-coroutine-sleep.c
index 9abb7fd..b35db56 100644
@@ -11,7 +11,7 @@
  *
  */
 
-#include "block/coroutine.h"
+#include "qemu/coroutine.h"
 #include "qemu/timer.h"
 #include "block/aio.h"
 
util/qemu-coroutine.c renamed from qemu-coroutine.c +2 -2
similarity index 98%
rename from qemu-coroutine.c
rename to util/qemu-coroutine.c
index c17a92b..8953560 100644
@@ -16,8 +16,8 @@
 #include "qemu-common.h"
 #include "qemu/thread.h"
 #include "qemu/atomic.h"
-#include "block/coroutine.h"
-#include "block/coroutine_int.h"
+#include "qemu/coroutine.h"
+#include "qemu/coroutine_int.h"
 
 enum {
     POOL_BATCH_SIZE = 64,
Signature · 1 line
2.4.3
#30 lore raw

PATCH v2 7/16 util: pull Buffer code out of VNC module

In reply to Daniel P. Berrange

The Buffer code in the VNC server is useful for the IO channel code, so pull it out into a shared module, QIOBuffer.

---
 MAINTAINERS           |   6 +++
 include/qemu/buffer.h | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/vnc.c              |  43 ------------------
 ui/vnc.h              |  16 +------
 util/Makefile.objs    |   1 +
 util/buffer.c         |  65 +++++++++++++++++++++++++++
 6 files changed, 191 insertions(+), 58 deletions(-)
 create mode 100644 include/qemu/buffer.h
 create mode 100644 util/buffer.c
MAINTAINERS +6 -0
index 426d0ba..0bcf85b 100644
@@ -1148,6 +1148,12 @@ F: util/*coroutine*
 F: include/qemu/coroutine*
 F: tests/test-coroutine.c
 
+Buffers
+M: Daniel P. Berrange <[email protected]>
+S: Odd fixes
+F: util/buffer.c
+F: include/qemu/buffer.h
+
 Usermode Emulation
 ------------------
 Overall
include/qemu/buffer.h new file +118 -0

118 lines not on this page · raw message

ui/vnc.c +0 -43

49 lines not on this page · raw message

ui/vnc.h +1 -15
index 4dd769c..2863f58 100644
@@ -34,6 +34,7 @@
 #include "audio/audio.h"
 #include "qemu/bitmap.h"
 #include "crypto/tlssession.h"
+#include "qemu/buffer.h"
 #include <zlib.h>
 #include <stdbool.h>
 
@@ -56,13 +57,6 @@
  *
  *****************************************************************************/
 
-typedef struct Buffer
-{
-    size_t capacity;
-    size_t offset;
-    uint8_t *buffer;
-} Buffer;
-
 typedef struct VncState VncState;
 typedef struct VncJob VncJob;
 typedef struct VncRect VncRect;
@@ -535,14 +529,6 @@ ssize_t vnc_client_io_error(VncState *vs, ssize_t ret, int last_errno);
 void start_client_init(VncState *vs);
 void start_auth_vnc(VncState *vs);
 
-/* Buffer management */
-void buffer_reserve(Buffer *buffer, size_t len);
-void buffer_reset(Buffer *buffer);
-void buffer_free(Buffer *buffer);
-void buffer_append(Buffer *buffer, const void *data, size_t len);
-void buffer_advance(Buffer *buf, size_t len);
-uint8_t *buffer_end(Buffer *buffer);
-
 
 /* Misc helpers */
 
util/Makefile.objs +1 -0
index d8d7e7a..1363d1f 100644
@@ -21,3 +21,4 @@ util-obj-y += rcu.o
 util-obj-y += qemu-coroutine.o qemu-coroutine-lock.o qemu-coroutine-io.o
 util-obj-y += qemu-coroutine-sleep.o
 util-obj-y += coroutine-$(CONFIG_COROUTINE_BACKEND).o
+util-obj-y += buffer.o
util/buffer.c new file +65 -0

65 lines not on this page · raw message

Signature · 1 line
2.4.3
#31 lore raw

PATCH v2 8/16 io: add abstract QIOChannel classes

In reply to Daniel P. Berrange

Start the new generic I/O channel framework by defining a QIOChannel abstract base class. This is designed to feel similar to GLib's GIOChannel, but with the addition of support for using iovecs, qemu error reporting, file descriptor passing, coroutine integration and use of the QOM framework for easier sub-classing.

The intention is that anywhere in QEMU that almost anywhere that deals with sockets will use this new I/O infrastructure, so that it becomes trivial to then layer in support for TLS encryption. This will at least include the VNC server, char device backend and migration code.

---
 MAINTAINERS          |   7 +
 Makefile             |   2 +
 Makefile.objs        |   5 +
 Makefile.target      |   2 +
 include/io/channel.h | 506 +++++++++++++++++++++++++++++++++++++++++++++++++++
 io/Makefile.objs     |   1 +
 io/channel.c         | 283 ++++++++++++++++++++++++++++
 7 files changed, 806 insertions(+)
 create mode 100644 include/io/channel.h
 create mode 100644 io/Makefile.objs
 create mode 100644 io/channel.c
MAINTAINERS +7 -0
index 0bcf85b..6327263 100644
@@ -1154,6 +1154,13 @@ S: Odd fixes
 F: util/buffer.c
 F: include/qemu/buffer.h
 
+I/O Channels
+M: Daniel P. Berrange <[email protected]>
+S: Maintained
+F: io/
+F: include/io/
+F: tests/test-io-*
+
 Usermode Emulation
 ------------------
 Overall
Makefile +2 -0
index e370876..288e198 100644
@@ -157,6 +157,7 @@ dummy := $(call unnest-vars,, \
                 crypto-obj-y \
                 crypto-aes-obj-y \
                 qom-obj-y \
+                io-obj-y \
                 common-obj-y \
                 common-obj-m)
 
@@ -176,6 +177,7 @@ SOFTMMU_SUBDIR_RULES=$(filter %-softmmu,$(SUBDIR_RULES))
 
 $(SOFTMMU_SUBDIR_RULES): $(block-obj-y)
 $(SOFTMMU_SUBDIR_RULES): $(crypto-obj-y)
+$(SOFTMMU_SUBDIR_RULES): $(io-obj-y)
 $(SOFTMMU_SUBDIR_RULES): config-all-devices.mak
 
 subdir-%:
Makefile.objs +5 -0
index ecfe03c..ffe8684 100644
@@ -28,6 +28,11 @@ crypto-aes-obj-y = crypto/
 
 qom-obj-y = qom/
 
+#######################################################################
+# io-obj-y is code used by both qemu system emulation and qemu-img
+
+io-obj-y = io/
+
 ######################################################################
 # Target independent part of system emulation. The long term path is to
 # suppress *all* target specific code in case of system emulation, i.e. a
Makefile.target +2 -0
index 962d004..34ddb7e 100644
@@ -176,6 +176,7 @@ dummy := $(call unnest-vars,.., \
                crypto-obj-y \
                crypto-aes-obj-y \
                qom-obj-y \
+               io-obj-y \
                common-obj-y \
                common-obj-m)
 target-obj-y := $(target-obj-y-save)
@@ -185,6 +186,7 @@ all-obj-y += $(qom-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y)
 all-obj-$(CONFIG_USER_ONLY) += $(crypto-aes-obj-y)
 all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
+all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)
 
 $(QEMU_PROG_BUILD): config-devices.mak
 
include/io/channel.h new file +506 -0

506 lines not on this page · raw message

io/Makefile.objs new file +1 -0
new file mode 100644
index 0000000..a6ed361
@@ -0,0 +1 @@
+io-obj-y = channel.o
io/channel.c new file +283 -0

283 lines not on this page · raw message

Signature · 1 line
2.4.3
#32 lore raw

Re: [Qemu-devel] [PATCH v2 08/16] io: add abstract QIOChannel classes

Quoted 30 lines · Daniel P. Berrange

Start the new generic I/O channel framework by defining a QIOChannel abstract base class. This is designed to feel similar to GLib's GIOChannel, but with the addition of support for using iovecs, qemu error reporting, file descriptor passing, coroutine integration and use of the QOM framework for easier sub-classing.

The intention is that anywhere in QEMU that almost anywhere that deals with sockets will use this new I/O infrastructure, so that it becomes trivial to then layer in support for TLS encryption. This will at least include the VNC server, char device backend and migration code.

---
 MAINTAINERS          |   7 +
 Makefile             |   2 +
 Makefile.objs        |   5 +
 Makefile.target      |   2 +
 include/io/channel.h | 506 +++++++++++++++++++++++++++++++++++++++++++++++++++
 io/Makefile.objs     |   1 +
 io/channel.c         | 283 ++++++++++++++++++++++++++++
 7 files changed, 806 insertions(+)
 create mode 100644 include/io/channel.h
 create mode 100644 io/Makefile.objs
 create mode 100644 io/channel.c

+++ b/include/io/channel.h

include/io/channel.h line 82

Quoted 4 lines
include/io/channel.h new file +3 -0
@@ -0,0 +1,506 @@
 
+struct QIOChannel {
+    Object parent;
+    int features; /* bitmask of QIOChannelFeatures */

Would an unsigned type make bit manipulations any less likely to avoid clang sanitizer warnings under future extensions of new bits?

include/io/channel.h line 91

Quoted 9 lines
include/io/channel.h new file +9 -0
+};
+
+/**
+ * QIOChannelClass:
+ *
+ * This class defines the contract that all subclasses
+ * must follow to provide specific channel implementations.
+ * All the callbacks are mandatory with the exception of
+ * io_has_feature, which defaults to returning false.

And yet...

Quoted 8 lines

+ *
+ * Consult the corresponding public API docs for a description
+ * of the semantics of each callback
+ */

include/io/channel.h new file +4 -0
+struct QIOChannelClass {
+    ObjectClass parent;
+
+    /* Mandatory callbacks */

...

include/io/channel.h line 131

Quoted 13 lines
include/io/channel.h new file +13 -0
+
+    /* Optional callbacks */
+    int (*io_shutdown)(QIOChannel *ioc,
+                       QIOChannelShutdown how,
+                       Error **errp);
+    void (*io_set_cork)(QIOChannel *ioc,
+                        bool enabled);
+    void (*io_set_delay)(QIOChannel *ioc,
+                         bool enabled);
+    off64_t (*io_seek)(QIOChannel *ioc,
+                       off64_t offset,
+                       int whence,
+                       Error **errp);

...there are four optional callbacks listed, and no mention of a callback named io_has_feature. Sounds like docs need an update.

include/io/channel.h line 147

Quoted 13 lines
include/io/channel.h new file +13 -0
+
+/**
+ * qio_channel_has_feature:
+ * @ioc: the channel object
+ * @feature: the feature to check support of
+ *
+ * Determine whether the channel implementation supports
+ * the optional feature named in @feature.
+ *
+ * Returns: true if supported, false otherwise.
+ */
+bool qio_channel_has_feature(QIOChannel *ioc,
+                             QIOChannelFeature feature);

Can this be used to check multiple features at once, or are we content that checking two features requires two calls?

Quoted 5 lines

+/**
+ * qio_channel_seek:
+ * @ioc: the channel object
+ * @offset: the position to seek to, relative to @whence
+ * @whence: one of the POSIX SEEK_* constants

Including SEEK_HOLE/SEEK_DATA?

Quoted 7 lines

+ * @errp: pointer to an uninitialized error object
+ *
+ * Moves the current I/O position within the channel
+ * @ioc, to be @offset. The value of @offset is
+ * interpreted relative to @whence:
+ *
+ * SEEK_SET - the position is set to @offset bytes

Quoted 8 lines

+ * SEEK_CUR - the position is moved by @offset bytes
+ * SEEK_END - the position is set to end of the file plus @offset bytes
+ *
+ * Not all implementations will support this facility,
+ * so may report an error. To avoid errors, the
+ * caller may check for the feature flag
+ * QIO_CHANNEL_FEATURE_SEEKABLE prior to calling
+ * this method.

I don't see that constant defined; stale docs?

Quoted 8 lines

+++ b/io/channel.c

io/channel.c new file +5 -0
@@ -0,0 +1,283 @@
 
+ssize_t qio_channel_readv_full(QIOChannel *ioc,
+                               const struct iovec *iov,
+                               size_t niov,
+                               int **fds,
+                               size_t *nfds,

io/channel.c line 45

Quoted 10 lines
io/channel.c new file +10 -0
+                               Error **errp)
+{
+    QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc);
+
+    if ((fds || nfds) &&
+        !(ioc->features & (1 << QIO_CHANNEL_FEATURE_FD_PASS))) {
+        error_setg_errno(errp, EINVAL,
+                         "Channel does not support file descriptor passing");
+        return -1;
+    }

Why pre-filter fds here...

Quoted 4 lines
io/channel.c new file +4 -0
+
+    return klass->io_readv(ioc, iov, niov, fds, nfds, errp);
+}
+

io/channel.c line 59

Quoted 10 lines
io/channel.c new file +10 -0
+
+ssize_t qio_channel_writev_full(QIOChannel *ioc,
+                                const struct iovec *iov,
+                                size_t niov,
+                                int *fds,
+                                size_t nfds,
+                                Error **errp)
+{
+    QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc);
+    return klass->io_writev(ioc, iov, niov, fds, nfds, errp);

...but rely on the callbacks to filter fds here?

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#33 lore raw

Re: [Qemu-devel] [PATCH v2 08/16] io: add abstract QIOChannel classes

Quoted 32 lines · Eric Blake
Quoted 30 lines · Daniel P. Berrange

Start the new generic I/O channel framework by defining a QIOChannel abstract base class. This is designed to feel similar to GLib's GIOChannel, but with the addition of support for using iovecs, qemu error reporting, file descriptor passing, coroutine integration and use of the QOM framework for easier sub-classing.

The intention is that anywhere in QEMU that almost anywhere that deals with sockets will use this new I/O infrastructure, so that it becomes trivial to then layer in support for TLS encryption. This will at least include the VNC server, char device backend and migration code.

---
 MAINTAINERS          |   7 +
 Makefile             |   2 +
 Makefile.objs        |   5 +
 Makefile.target      |   2 +
 include/io/channel.h | 506 +++++++++++++++++++++++++++++++++++++++++++++++++++
 io/Makefile.objs     |   1 +
 io/channel.c         | 283 ++++++++++++++++++++++++++++
 7 files changed, 806 insertions(+)
 create mode 100644 include/io/channel.h
 create mode 100644 io/Makefile.objs
 create mode 100644 io/channel.c

+++ b/include/io/channel.h

(quoted diff) +0 -0
@@ -0,0 +1,506 @@
Quoted 6 lines

include/io/channel.h line 82

Quoted 3 lines
include/io/channel.h new file +3 -0
+struct QIOChannel {
+    Object parent;
+    int features; /* bitmask of QIOChannelFeatures */

Would an unsigned type make bit manipulations any less likely to avoid clang sanitizer warnings under future extensions of new bits?

Yes, makes sense.

Quoted 30 lines

include/io/channel.h line 91

Quoted 4 lines
include/io/channel.h new file +4 -0
+ * This class defines the contract that all subclasses
+ * must follow to provide specific channel implementations.
+ * All the callbacks are mandatory with the exception of
+ * io_has_feature, which defaults to returning false.

And yet...

Quoted 8 lines
include/io/channel.h new file +8 -0
+ *
+ * Consult the corresponding public API docs for a description
+ * of the semantics of each callback
+ */
+struct QIOChannelClass {
+    ObjectClass parent;
+
+    /* Mandatory callbacks */

...

include/io/channel.h line 131

Quoted 13 lines
include/io/channel.h new file +13 -0
+
+    /* Optional callbacks */
+    int (*io_shutdown)(QIOChannel *ioc,
+                       QIOChannelShutdown how,
+                       Error **errp);
+    void (*io_set_cork)(QIOChannel *ioc,
+                        bool enabled);
+    void (*io_set_delay)(QIOChannel *ioc,
+                         bool enabled);
+    off64_t (*io_seek)(QIOChannel *ioc,
+                       off64_t offset,
+                       int whence,
+                       Error **errp);
Quoted 2 lines

...there are four optional callbacks listed, and no mention of a callback named io_has_feature. Sounds like docs need an update.

Opps, yes, I removed io_has_feature after last round of review feedback.

Quoted 8 lines
Quoted 8 lines
include/io/channel.h new file +8 -0
+
+/**
+ * qio_channel_has_feature:
+ * @ioc: the channel object
+ * @feature: the feature to check support of
+ *
+ * Determine whether the channel implementation supports
+ * the optional feature named in @feature.
Quoted 8 lines

include/io/channel.h line 147

Quoted 5 lines

+ *
+ * Returns: true if supported, false otherwise.
+ */

include/io/channel.h new file +2 -0
+bool qio_channel_has_feature(QIOChannel *ioc,
+                             QIOChannelFeature feature);

Can this be used to check multiple features at once, or are we content that checking two features requires two calls?

The expected usage of this is such that I don't really expect callers to need to check multiple features at once.

Quoted 7 lines
Quoted 5 lines

+/**
+ * qio_channel_seek:
+ * @ioc: the channel object
+ * @offset: the position to seek to, relative to @whence
+ * @whence: one of the POSIX SEEK_* constants

Including SEEK_HOLE/SEEK_DATA?

Are those actually POSIX, or Linux extensions ? In any case, only SEEK_SET, SEEK_CUR and SEEK_END are intended for use. I'll clarify the docs.

Quoted 17 lines
Quoted 16 lines

+ * @errp: pointer to an uninitialized error object
+ *
+ * Moves the current I/O position within the channel
+ * @ioc, to be @offset. The value of @offset is
+ * interpreted relative to @whence:
+ *
+ * SEEK_SET - the position is set to @offset bytes
+ * SEEK_CUR - the position is moved by @offset bytes
+ * SEEK_END - the position is set to end of the file plus @offset bytes
+ *
+ * Not all implementations will support this facility,
+ * so may report an error. To avoid errors, the
+ * caller may check for the feature flag
+ * QIO_CHANNEL_FEATURE_SEEKABLE prior to calling
+ * this method.

Quoted 1 line

I don't see that constant defined; stale docs?

Hmm, yes, its not defined - I can't remember now if i decided it was not needed after all, or if i just forgot about it... Will investigate & fix one way or the other.

Quoted 22 lines
Quoted 9 lines

+++ b/io/channel.c

io/channel.c new file +5 -0
@@ -0,0 +1,283 @@
 
+ssize_t qio_channel_readv_full(QIOChannel *ioc,
+                               const struct iovec *iov,
+                               size_t niov,
+                               int **fds,
+                               size_t *nfds,

io/channel.c line 45

Quoted 10 lines
io/channel.c new file +10 -0
+                               Error **errp)
+{
+    QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc);
+
+    if ((fds || nfds) &&
+        !(ioc->features & (1 << QIO_CHANNEL_FEATURE_FD_PASS))) {
+        error_setg_errno(errp, EINVAL,
+                         "Channel does not support file descriptor passing");
+        return -1;
+    }

Why pre-filter fds here...

Quoted 16 lines
Quoted 4 lines
io/channel.c new file +4 -0
+
+    return klass->io_readv(ioc, iov, niov, fds, nfds, errp);
+}
+

io/channel.c line 59

Quoted 10 lines
io/channel.c new file +10 -0
+
+ssize_t qio_channel_writev_full(QIOChannel *ioc,
+                                const struct iovec *iov,
+                                size_t niov,
+                                int *fds,
+                                size_t nfds,
+                                Error **errp)
+{
+    QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc);
+    return klass->io_writev(ioc, iov, niov, fds, nfds, errp);

...but rely on the callbacks to filter fds here?

That's an oversight.

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#34 lore raw

Re: [Qemu-devel] [PATCH v2 08/16] io: add abstract QIOChannel classes

Quoted 7 lines · Daniel P. Berrange
Quoted 7 lines
Quoted 6 lines

+/**
+ * qio_channel_seek:
+ * @ioc: the channel object
+ * @offset: the position to seek to, relative to @whence
+ * @whence: one of the POSIX SEEK_* constants

Quoted 5 lines
Quoted 1 line

Including SEEK_HOLE/SEEK_DATA?

Are those actually POSIX, or Linux extensions ? In any case, only SEEK_SET, SEEK_CUR and SEEK_END are intended for use. I'll clarify the docs.

SEEK_HOLE/DATA are not quite POSIX yet, although the next version of POSIX (Issue 8) will have them [1]. But they are definitely more than just Linux extensions (Solaris implemented them first, after all).

[1] http://austingroupbugs.net/view.php?id=415

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#35 lore raw

PATCH v2 9/16 io: add helper module for creating watches on FDs

In reply to Daniel P. Berrange

A number of the channel implementations will require the ability to create watches on file descriptors / sockets. To avoid duplicating this code in each channel, provide a helper API for dealing with file descriptor watches.

There are two watch implementations provided. The first is useful for bi-directional file descriptors such as sockets, regular files, character devices, etc. The second works with a pair of unidirectional file descriptors such as pipes.

---
 include/io/channel-watch.h |  72 ++++++++++++++++
 io/Makefile.objs           |   1 +
 io/channel-watch.c         | 200 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 273 insertions(+)
 create mode 100644 include/io/channel-watch.h
 create mode 100644 io/channel-watch.c
include/io/channel-watch.h new file +72 -0
new file mode 100644
index 0000000..656358a
@@ -0,0 +1,72 @@
+/*
+ * QEMU I/O channels watch helper APIs
+ *
+ * Copyright (c) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef QIO_CHANNEL_WATCH_H__
+#define QIO_CHANNEL_WATCH_H__
+
+#include "io/channel.h"
+
+/*
+ * This module provides helper functions that will be needed by
+ * the various QIOChannel implementations, for creating watches
+ * on file descriptors / sockets
+ */
+
+/**
+ * qio_channel_create_fd_watch:
+ * @ioc: the channel object
+ * @fd: the file descriptor
+ * @condition: the I/O condition
+ *
+ * Create a new main loop source that is able to
+ * monitor the file descriptor @fd for the
+ * I/O conditions in @condition. This is able
+ * monitor block devices, character devices,
+ * sockets, pipes but not plain files.
+ *
+ * Returns: the new main loop source
+ */
+GSource *qio_channel_create_fd_watch(QIOChannel *ioc,
+                                     int fd,
+                                     GIOCondition condition);
+
+/**
+ * qio_channel_create_fd_pair_watch:
+ * @ioc: the channel object
+ * @fdread: the file descriptor for reading
+ * @fdwrite: the file descriptor for writing
+ * @condition: the I/O condition
+ *
+ * Create a new main loop source that is able to
+ * monitor the pair of file descriptors @fdread
+ * and @fdwrite for the I/O conditions in @condition.
+ * This is intended for monitoring unidirectional
+ * file descriptors such as pipes, where a pair
+ * of descriptors is required for bidirectional
+ * I/O
+ *
+ * Returns: the new main loop source
+ */
+GSource *qio_channel_create_fd_pair_watch(QIOChannel *ioc,
+                                          int fdread,
+                                          int fdwrite,
+                                          GIOCondition condition);
+
+#endif /* QIO_CHANNEL_WATCH_H__ */
io/Makefile.objs +1 -0
index a6ed361..b02ea90 100644
@@ -1 +1,2 @@
 io-obj-y = channel.o
+io-obj-y += channel-watch.o
io/channel-watch.c new file +200 -0

200 lines not on this page · raw message

Signature · 1 line
2.4.3
#36 lore raw

PATCH v2 10/16 io: add QIOTask class for async operations

In reply to Daniel P. Berrange

A number of I/O operations need to be performed asynchronously to avoid blocking the main loop. The caller of such APIs need to provide a callback to be invoked on completion/error and need access to the error, if any. The small QIOTask provides a simple framework for dealing with such probes. The API docs inline provide an outline of how this is to be used.

Some functions don't have the ability to run asynchronously (eg getaddrinfo always blocks), so to facilitate their use, the task class provides a mechanism to run a blocking function in a thread, while triggering the completion callback in the main event loop thread. This easily allows any synchronous function to be made asynchronous, albeit at the cost of spawning a thread.

In this series, the QIOTask class will be used for things like the TLS handshake, the websockets handshake and TCP connect() progress.

The concept of QIOTask is inspired by the GAsyncResult interface / GTask class in the GIO libraries. The min version requirements on glib don't allow those to be used from QEMU, so QIOTask provides a facsimilie which can be easily switched to GTask in the future if the min version is increased.

---
 include/io/task.h    | 256 +++++++++++++++++++++++++++++++++++++++++++++++
 io/Makefile.objs     |   1 +
 io/task.c            | 159 +++++++++++++++++++++++++++++
 tests/.gitignore     |   1 +
 tests/Makefile       |   3 +
 tests/test-io-task.c | 276 +++++++++++++++++++++++++++++++++++++++++++++++++++
 trace-events         |   9 ++
 7 files changed, 705 insertions(+)
 create mode 100644 include/io/task.h
 create mode 100644 io/task.c
 create mode 100644 tests/test-io-task.c
include/io/task.h new file +256 -0
new file mode 100644
index 0000000..2418714
@@ -0,0 +1,256 @@
+/*
+ * QEMU I/O task
+ *
+ * Copyright (c) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef QIO_TASK_H__
+#define QIO_TASK_H__
+
+#include "qemu-common.h"
+#include "qapi/error.h"
+#include "qom/object.h"
+
+typedef struct QIOTask QIOTask;
+
+typedef void (*QIOTaskFunc)(Object *source,
+                            Error *err,
+                            gpointer opaque);
+
+typedef int (*QIOTaskWorker)(QIOTask *task,
+                             Error **errp,
+                             gpointer opaque);
+
+/**
+ * QIOTask:
+ *
+ * The QIOTask object provides a simple mechanism for reporting
+ * success / failure of long running background operations.
+ *
+ * A object on which the operation is to be performed could have
+ * a public API which accepts a task callback:
+ *
+ * <example>
+ *   <title>Task callback function signature</title>
+ *   <programlisting>
+ *  void myobject_operation(QMyObject *obj,
+ *                          QIOTaskFunc *func,
+ *                          gpointer opaque,
+ *                          GDestroyNotify *notify);
+ *   </programlisting>
+ * </example>
+ *
+ * The 'func' parameter is the callback to be invoked, and 'opaque'
+ * is data to pass to it. The optional 'notify' function is used
+ * to free 'opaque' when no longer needed.
+ *
+ * Now, lets say the implementation of this method wants to set
+ * a timer to run once a second checking for completion of some
+ * activity. It would do something like
+ *
+ * <example>
+ *   <title>Task callback function implementation</title>
+ *   <programlisting>
+ *    void myobject_operation(QMyObject *obj,
+ *                            QIOTaskFunc *func,
+ *                            gpointer opaque,
+ *                            GDestroyNotify *notify)
+ *    {
+ *      QIOTask *task;
+ *
+ *      task = qio_task_new(OBJECT(obj), func, opaque, notify);
+ *
+ *      g_timeout_add_full(G_PRIORITY_DEFAULT,
+ *                         1000,
+ *                         myobject_operation_timer,
+ *                         task,
+ *                         NULL);
+ *    }
+ *   </programlisting>
+ * </example>
+ *
+ * It could equally have setup a watch on a file descriptor or
+ * created a background thread, or something else entirely.
+ * Notice that the source object is passed to the task, and
+ * QIOTask will hold a reference on that. This ensure that
+ * the QMyObject instance cannot be garbage collected while
+ * the async task is still in progress.
+ *
+ * In this case, myobject_operation_timer will fire after
+ * 3 secs and do
+ *
+ * <example>
+ *   <title>Task timer function</title>
+ *   <programlisting>
+ *   gboolean myobject_operation_timer(gpointer opaque)
+ *   {
+ *      QIOTask *task = QIO_TASK(opaque);
+ *      Error *err;*
+ *
+ *      ...check something important...
+ *       if (err) {
+ *           qio_task_abort(task, err);
+ *           error_free(task);
+ *           return FALSE;
+ *       } else if (...work is completed ...) {
+ *           qio_task_complete(task);
+ *           return FALSE;
+ *       }
+ *       ...carry on polling ...
+ *       return TRUE;
+ *   }
+ *   </programlisting>
+ * </example>
+ *
+ * Once this function returns false, object_unref will be called
+ * automatically on the task causing it to be released and the
+ * ref on QMyObject dropped too.
+ *
+ * The QIOTask module can also be used to perform operations
+ * in a background thread context, while still reporting the
+ * results in the main event thread. This allows code which
+ * cannot easily be rewritten to be asychronous (such as DNS
+ * lookups) to be easily run non-blocking. Reporting the
+ * results in the main thread context means that the caller
+ * typically does not need to be concerned about thread
+ * safety wrt the QEMU global mutex.
+ *
+ * For example, the socket_listen() method will block the caller
+ * while DNS lookups take place if given a name, instead of IP
+ * address. The C library often do not provide a practical async
+ * DNS API, so the to get non-blocking DNS lookups in a portable
+ * manner requires use of a thread. So achieve a non-blocking
+ * socket listen using QIOTask would require:
+ *
+ * <example>
+ *    static int myobject_listen_worker(QIOTask *task,
+ *                                      Error **errp,
+ *                                      gpointer opaque)
+ *    {
+ *       QMyObject obj = QMY_OBJECT(qio_task_get_source(task));
+ *       SocketAddress *addr = opaque;
+ *
+ *       obj->fd = socket_listen(addr, errp);
+ *       if (obj->fd < 0) {
+ *          return -1;
+ *       }
+ *       return 0;
+ *    }
+ *
+ *    void myobject_listen_async(QMyObject *obj,
+ *                               SocketAddress *addr,
+ *                               QIOTaskFunc *func,
+ *                               gpointer opaque,
+ *                               GDestroyNotify *notify)
+ *    {
+ *      QIOTask *task;
+ *      SocketAddress *addrCopy;
+ *
+ *      qapi_copy_SocketAddress(&addrCopy, addr);
+ *      task = qio_task_new(OBJECT(obj), func, opaque, notify);
+ *
+ *      qio_task_run_in_thread(task, myobject_listen_worker,
+ *                             addrCopy,
+ *                             qapi_free_SocketAddress);
+ *    }
+ * </example>
+ *
+ * NB, The 'func' callback passed into myobject_listen_async
+ * will be invoked from the main event thread, despite the
+ * actual operation being performed in a different thread.
+ */
+
+/**
+ * qio_task_new:
+ * @source: the object on which the operation is invoked
+ * @func: the callback to invoke when the task completes
+ * @opaque: opaque data to pass to @func when invoked
+ * @destroy: optional callback to free @opaque
+ *
+ * Creates a new task struct to track completion of a
+ * background operation running on the object @source.
+ * When the operation completes or fails, the callback
+ * @func will be invoked. The callback can access the
+ * 'err' attribute in the task object to determine if
+ * the operation was successful or not.
+ *
+ * The returned task will be released when one of
+ * qio_task_abort() or qio_task_complete() are invoked.
+ *
+ * Returns: the task struct
+ */
+QIOTask *qio_task_new(Object *source,
+                      QIOTaskFunc func,
+                      gpointer opaque,
+                      GDestroyNotify destroy);
+
+/**
+ * qio_task_run_in_thread:
+ * @task: the task struct
+ * @worker: the function to invoke in a thread
+ * @opaque: opaque data to pass to @worker
+ * @destroy: function to free @opaque
+ *
+ * Run a task in a background thread. If @worker
+ * returns 0 it will call qio_task_complete() in
+ * the main event thread context. If @worker
+ * returns -1 it will call qio_task_abort() in
+ * the main event thread context.
+ */
+void qio_task_run_in_thread(QIOTask *task,
+                            QIOTaskWorker worker,
+                            gpointer opaque,
+                            GDestroyNotify destroy);
+
+/**
+ * qio_task_complete:
+ * @task: the task struct
+ *
+ * Mark the operation as succesfully completed
+ * and free the memory for @task.
+ */
+void qio_task_complete(QIOTask *task);
+
+/**
+ * qio_task_abort:
+ * @task: the task struct
+ * @err: the error to record for the operation
+ *
+ * Mark the operation as failed, with @err providing
+ * details about the failure. The @err may be freed
+ * afer the function returns, as the notification
+ * callback is invoked synchronously. The @task will
+ * be freed when this call completes.
+ */
+void qio_task_abort(QIOTask *task,
+                    Error *err);
+
+
+/**
+ * qio_task_get_source:
+ * @task: the task struct
+ *
+ * Get the source object associated with the background
+ * task. This returns a new reference to the object,
+ * which the caller must released with object_unref()
+ * when no longer required.
+ *
+ * Returns: the source object
+ */
+Object *qio_task_get_source(QIOTask *task);
+
+#endif /* QIO_TASK_H__ */
io/Makefile.objs +1 -0
index b02ea90..503b95c 100644
@@ -1,2 +1,3 @@
 io-obj-y = channel.o
 io-obj-y += channel-watch.o
+io-obj-y += task.o
io/task.c new file +159 -0

159 lines not on this page · raw message

tests/.gitignore +1 -0
index a607bdd..baea5af 100644
@@ -23,6 +23,7 @@ test-cutils
 test-hbitmap
 test-int128
 test-iov
+test-io-task
 test-mul64
 test-opts-visitor
 test-qapi-event.[ch]
tests/Makefile +3 -0
index e6474ba..563e775 100644
@@ -80,6 +80,7 @@ check-unit-$(CONFIG_GNUTLS_HASH) += tests/test-crypto-hash$(EXESUF)
 check-unit-y += tests/test-crypto-cipher$(EXESUF)
 check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlscredsx509$(EXESUF)
 check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlssession$(EXESUF)
+check-unit-y += tests/test-io-task$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -296,6 +297,7 @@ test-qapi-obj-y = tests/test-qapi-visit.o tests/test-qapi-types.o \
 	$(test-qom-obj-y)
 test-crypto-obj-y = $(crypto-obj-y) $(test-qom-obj-y)
 test-block-obj-y = $(block-obj-y) $(test-crypto-obj-y)
+test-io-obj-y = $(io-obj-y) $(test-crypto-obj-y)
 
 tests/check-qint$(EXESUF): tests/check-qint.o $(test-util-obj-y)
 tests/check-qstring$(EXESUF): tests/check-qstring.o $(test-util-obj-y)
@@ -373,6 +375,7 @@ tests/test-crypto-tlscredsx509$(EXESUF): tests/test-crypto-tlscredsx509.o \
 	tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o $(test-crypto-obj-y)
 tests/test-crypto-tlssession$(EXESUF): tests/test-crypto-tlssession.o \
 	tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o $(test-crypto-obj-y)
+tests/test-io-task$(EXESUF): tests/test-io-task.o $(test-io-obj-y)
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
 libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
tests/test-io-task.c new file +276 -0

276 lines not on this page · raw message

trace-events +9 -0
index a0ddc6b..af5e6e8 100644
@@ -1705,3 +1705,12 @@ qcrypto_tls_creds_x509_load_cert_list(void *creds, const char *file) "TLS creds
 
 # crypto/tlssession.c
 qcrypto_tls_session_new(void *session, void *creds, const char *hostname, const char *aclname, int endpoint) "TLS session new session=%p creds=%p hostname=%s aclname=%s endpoint=%d"
+
+# io/task.c
+qio_task_new(void *task, void *source, void *func, void *opaque) "Task new task=%p source=%p func=%p opaque=%p"
+qio_task_complete(void *task) "Task complete task=%p"
+qio_task_abort(void *task) "Task abort task=%p"
+qio_task_thread_start(void *task, void *worker, void *opaque) "Task thread start task=%p worker=%p opaque=%p"
+qio_task_thread_run(void *task) "Task thread run task=%p"
+qio_task_thread_exit(void *task) "Task thread exit task=%p"
+qio_task_thread_result(void *task) "Task thread result task=%p"
Signature · 1 line
2.4.3
#37 lore raw

PATCH v2 11/16 io: add QIOChannelSocket class

In reply to Daniel P. Berrange

Implement a QIOChannel subclass that supports sockets I/O. The implementation is able to manage a single socket file descriptor, whether a TCP/UNIX listener, TCP/UNIX connection, or a UDP datagram. It provides APIs which can listen and connect either asynchronously or synchronously. Since there is no asynchronous DNS lookup API available, it uses the QIOTask helper for spawning a background thread to ensure non-blocking operation.

---
 configure                      |  11 +
 include/io/channel-socket.h    | 244 ++++++++++++++
 io/Makefile.objs               |   1 +
 io/channel-socket.c            | 737 +++++++++++++++++++++++++++++++++++++++++
 scripts/create_config          |   9 +
 tests/.gitignore               |   1 +
 tests/Makefile                 |   3 +
 tests/io-channel-helpers.c     | 222 +++++++++++++
 tests/io-channel-helpers.h     |  30 ++
 tests/test-io-channel-socket.c | 367 ++++++++++++++++++++
 trace-events                   |  19 ++
 11 files changed, 1644 insertions(+)
 create mode 100644 include/io/channel-socket.h
 create mode 100644 io/channel-socket.c
 create mode 100644 tests/io-channel-helpers.c
 create mode 100644 tests/io-channel-helpers.h
 create mode 100644 tests/test-io-channel-socket.c
configure +11 -0
index f08327e..a7d6df0 100755
@@ -2299,6 +2299,14 @@ fi
 
 
 ##########################################
+# getifaddrs (for tests/test-io-channel-socket )
+
+have_ifaddrs_h=yes
+if ! check_include "ifaddrs.h" ; then
+  have_ifaddrs_h=no
+fi
+
+##########################################
 # VTE probe
 
 if test "$vte" != "no"; then
@@ -4986,6 +4994,9 @@ fi
 if test "$tasn1" = "yes" ; then
   echo "CONFIG_TASN1=y" >> $config_host_mak
 fi
+if test "$have_ifaddrs_h" = "yes" ; then
+    echo "HAVE_IFADDRS_H=y" >> $config_host_mak
+fi
 if test "$vte" = "yes" ; then
   echo "CONFIG_VTE=y" >> $config_host_mak
   echo "VTE_CFLAGS=$vte_cflags" >> $config_host_mak
include/io/channel-socket.h new file +244 -0

244 lines not on this page · raw message

io/Makefile.objs +1 -0
index 503b95c..e9d77aa 100644
@@ -1,3 +1,4 @@
 io-obj-y = channel.o
+io-obj-y += channel-socket.o
 io-obj-y += channel-watch.o
 io-obj-y += task.o
io/channel-socket.c new file +737 -0

737 lines not on this page · raw message

scripts/create_config +9 -0
index 546f889..9cb176f 100755
@@ -61,6 +61,15 @@ case $line in
     value=${line#*=}
     echo "#define $name $value"
     ;;
+ HAVE_*=y) # configuration
+    name=${line%=*}
+    echo "#define $name 1"
+    ;;
+ HAVE_*=*) # configuration
+    name=${line%=*}
+    value=${line#*=}
+    echo "#define $name $value"
+    ;;
  ARCH=*) # configuration
     arch=${line#*=}
     arch_name=`echo $arch | LC_ALL=C tr '[a-z]' '[A-Z]'`
tests/.gitignore +1 -0
index baea5af..8f6b7f6 100644
@@ -23,6 +23,7 @@ test-cutils
 test-hbitmap
 test-int128
 test-iov
+test-io-channel-socket
 test-io-task
 test-mul64
 test-opts-visitor
tests/Makefile +3 -0
index 563e775..b97f1ac 100644
@@ -81,6 +81,7 @@ check-unit-y += tests/test-crypto-cipher$(EXESUF)
 check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlscredsx509$(EXESUF)
 check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlssession$(EXESUF)
 check-unit-y += tests/test-io-task$(EXESUF)
+check-unit-y += tests/test-io-channel-socket$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -376,6 +377,8 @@ tests/test-crypto-tlscredsx509$(EXESUF): tests/test-crypto-tlscredsx509.o \
 tests/test-crypto-tlssession$(EXESUF): tests/test-crypto-tlssession.o \
 	tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o $(test-crypto-obj-y)
 tests/test-io-task$(EXESUF): tests/test-io-task.o $(test-io-obj-y)
+tests/test-io-channel-socket$(EXESUF): tests/test-io-channel-socket.o \
+        tests/io-channel-helpers.o $(test-io-obj-y)
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
 libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
tests/io-channel-helpers.c new file +222 -0

222 lines not on this page · raw message

tests/io-channel-helpers.h new file +30 -0
new file mode 100644
index 0000000..d0085a2
@@ -0,0 +1,30 @@
+/*
+ * QEMU I/O channel test helpers
+ *
+ * Copyright (c) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "io/channel.h"
+
+#ifndef TEST_IO_CHANNEL_HELPERS
+#define TEST_IO_CHANNEL_HELPERS
+
+void test_io_channel_comms(bool blocking,
+                           QIOChannel *src,
+                           QIOChannel *dst);
+
+#endif /* TEST_IO_CHANNEL_HELPERS */
tests/test-io-channel-socket.c new file +367 -0

367 lines not on this page · raw message

trace-events +19 -0
index af5e6e8..2d06918 100644
@@ -1714,3 +1714,22 @@ qio_task_thread_start(void *task, void *worker, void *opaque) "Task thread start
 qio_task_thread_run(void *task) "Task thread run task=%p"
 qio_task_thread_exit(void *task) "Task thread exit task=%p"
 qio_task_thread_result(void *task) "Task thread result task=%p"
+
+# io/channel-socket.c
+qio_channel_socket_new(void *ioc) "Socket new ioc=%p"
+qio_channel_socket_new_fd(void *ioc, int fd) "Socket new ioc=%p fd=%d"
+qio_channel_socket_connect_sync(void *ioc, void *addr) "Socket connect sync ioc=%p addr=%p"
+qio_channel_socket_connect_async(void *ioc, void *addr) "Socket connect async ioc=%p addr=%p"
+qio_channel_socket_connect_fail(void *ioc) "Socket connect fail ioc=%p"
+qio_channel_socket_connect_complete(void *ioc, int fd) "Socket connect complete ioc=%p fd=%d"
+qio_channel_socket_listen_sync(void *ioc, void *addr) "Socket listen sync ioc=%p addr=%p"
+qio_channel_socket_listen_async(void *ioc, void *addr) "Socket listen async ioc=%p addr=%p"
+qio_channel_socket_listen_fail(void *ioc) "Socket listen fail ioc=%p"
+qio_channel_socket_listen_complete(void *ioc, int fd) "Socket listen complete ioc=%p fd=%d"
+qio_channel_socket_dgram_sync(void *ioc, void *localAddr, void *remoteAddr) "Socket dgram sync ioc=%p localAddr=%p remoteAddr=%p"
+qio_channel_socket_dgram_async(void *ioc, void *localAddr, void *remoteAddr) "Socket dgram async ioc=%p localAddr=%p remoteAddr=%p"
+qio_channel_socket_dgram_fail(void *ioc) "Socket dgram fail ioc=%p"
+qio_channel_socket_dgram_complete(void *ioc, int fd) "Socket dgram complete ioc=%p fd=%d"
+qio_channel_socket_accept(void *ioc) "Socket accept start ioc=%p"
+qio_channel_socket_accept_fail(void *ioc) "Socket accept fail ioc=%p"
+qio_channel_socket_accept_complete(void *ioc, void *cioc, int fd) "Socket accept complete ioc=%p cioc=%p fd=%d"
Signature · 1 line
2.4.3
#38 lore raw

PATCH v2 12/16 io: add QIOChannelFile class

In reply to Daniel P. Berrange

Add a QIOChannel subclass that is capable of operating on things that are files, such as plain files, pipes, character/block devices, but notably not sockets.

---
 include/io/channel-file.h    |  93 +++++++++++++++++
 io/Makefile.objs             |   1 +
 io/channel-file.c            | 237 +++++++++++++++++++++++++++++++++++++++++++
 tests/.gitignore             |   2 +
 tests/Makefile               |   3 +
 tests/io-channel-helpers.c   |  25 +++++
 tests/io-channel-helpers.h   |   3 +
 tests/test-io-channel-file.c |  91 +++++++++++++++++
 trace-events                 |   4 +
 9 files changed, 459 insertions(+)
 create mode 100644 include/io/channel-file.h
 create mode 100644 io/channel-file.c
 create mode 100644 tests/test-io-channel-file.c
include/io/channel-file.h new file +93 -0
new file mode 100644
index 0000000..308e6d4
@@ -0,0 +1,93 @@
+/*
+ * QEMU I/O channels files driver
+ *
+ * Copyright (c) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef QIO_CHANNEL_FILE_H__
+#define QIO_CHANNEL_FILE_H__
+
+#include "io/channel.h"
+
+#define TYPE_QIO_CHANNEL_FILE "qio-channel-file"
+#define QIO_CHANNEL_FILE(obj)                                     \
+    OBJECT_CHECK(QIOChannelFile, (obj), TYPE_QIO_CHANNEL_FILE)
+
+typedef struct QIOChannelFile QIOChannelFile;
+
+/**
+ * QIOChannelFile:
+ *
+ * The QIOChannelFile object provides a channel implementation
+ * that is able to perform I/O on block devices, character
+ * devices, FIFOs, pipes and plain files. While it is technically
+ * able to work on sockets too on the UNIX platform, this is not
+ * portable to Windows and lacks some extra sockets specific
+ * functionality. So the QIOChannelSocket object is recommended
+ * for that use case.
+ *
+ */
+
+struct QIOChannelFile {
+    QIOChannel parent;
+    int fd;
+};
+
+
+/**
+ * qio_channel_file_new_fd:
+ * @fd: the file descriptor
+ *
+ * Create a new IO channel object for a file represented
+ * by the @fd parameter. @fd can be associated with a
+ * block device, character device, fifo, pipe, or a
+ * regular file. For sockets, the QIOChannelSocket class
+ * should be used instead, as this provides greater
+ * functionality and cross platform portability.
+ *
+ * The channel will own the passed in file descriptor
+ * and will take responsibility for closing it, so the
+ * caller must not close it. If appropriate the caller
+ * should dup() its FD before opening the channel.
+ *
+ * Returns: the new channel object
+ */
+QIOChannelFile *
+qio_channel_file_new_fd(int fd);
+
+/**
+ * qio_channel_file_new_path:
+ * @fd: the file descriptor
+ * @flags: the open flags (O_RDONLY|O_WRONLY|O_RDWR, etc)
+ * @mode: the file creation mode if O_WRONLY is set in @flags
+ * @errp: pointer to initialized error object
+ *
+ * Create a new IO channel object for a file represented
+ * by the @path parameter. @path can point to any
+ * type of file on which sequential I/O can be
+ * performed, whether it be a plain file, character
+ * device or block device.
+ *
+ * Returns: the new channel object
+ */
+QIOChannelFile *
+qio_channel_file_new_path(const char *path,
+                          int flags,
+                          mode_t mode,
+                          Error **errp);
+
+#endif /* QIO_CHANNEL_FILE_H__ */
io/Makefile.objs +1 -0
index e9d77aa..3d2f232 100644
@@ -1,4 +1,5 @@
 io-obj-y = channel.o
+io-obj-y += channel-file.o
 io-obj-y += channel-socket.o
 io-obj-y += channel-watch.o
 io-obj-y += task.o
io/channel-file.c new file +237 -0

237 lines not on this page · raw message

tests/.gitignore +2 -0
index 8f6b7f6..9a1fc33 100644
@@ -23,6 +23,8 @@ test-cutils
 test-hbitmap
 test-int128
 test-iov
+test-io-channel-file
+test-io-channel-file.txt
 test-io-channel-socket
 test-io-task
 test-mul64
tests/Makefile +3 -0
index b97f1ac..3498762 100644
@@ -82,6 +82,7 @@ check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlscredsx509$(EXESUF)
 check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlssession$(EXESUF)
 check-unit-y += tests/test-io-task$(EXESUF)
 check-unit-y += tests/test-io-channel-socket$(EXESUF)
+check-unit-y += tests/test-io-channel-file$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -379,6 +380,8 @@ tests/test-crypto-tlssession$(EXESUF): tests/test-crypto-tlssession.o \
 tests/test-io-task$(EXESUF): tests/test-io-task.o $(test-io-obj-y)
 tests/test-io-channel-socket$(EXESUF): tests/test-io-channel-socket.o \
         tests/io-channel-helpers.o $(test-io-obj-y)
+tests/test-io-channel-file$(EXESUF): tests/test-io-channel-file.o \
+        tests/io-channel-helpers.o $(test-io-obj-y)
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
 libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
tests/io-channel-helpers.c +25 -0
index c84b99f..91c44b4 100644
@@ -220,3 +220,28 @@ void test_io_channel_comms(bool blocking,
     g_free(data->output);
     g_free(data);
 }
+
+
+void test_io_channel_comms_serial(QIOChannel *src,
+                                  QIOChannel *dst)
+{
+    struct TestIOData *data;
+
+    data = test_load_io_data("libqemuutil.a");
+    data->src = src;
+    data->dst = dst;
+    data->blocking = true;
+
+    test_io_thread_writer(data);
+    test_io_thread_reader(data);
+
+    g_assert_cmpint(memcmp(data->input,
+                           data->output,
+                           data->len), ==, 0);
+    g_assert(data->readerr == NULL);
+    g_assert(data->writeerr == NULL);
+
+    g_free(data->input);
+    g_free(data->output);
+    g_free(data);
+}
tests/io-channel-helpers.h +3 -0
index d0085a2..7edbaad 100644
@@ -27,4 +27,7 @@ void test_io_channel_comms(bool blocking,
                            QIOChannel *src,
                            QIOChannel *dst);
 
+void test_io_channel_comms_serial(QIOChannel *src,
+                                  QIOChannel *dst);
+
 #endif /* TEST_IO_CHANNEL_HELPERS */
tests/test-io-channel-file.c new file +91 -0

91 lines not on this page · raw message

trace-events +4 -0
index 2d06918..26f6766 100644
@@ -1733,3 +1733,7 @@ qio_channel_socket_dgram_complete(void *ioc, int fd) "Socket dgram complete ioc=
 qio_channel_socket_accept(void *ioc) "Socket accept start ioc=%p"
 qio_channel_socket_accept_fail(void *ioc) "Socket accept fail ioc=%p"
 qio_channel_socket_accept_complete(void *ioc, void *cioc, int fd) "Socket accept complete ioc=%p cioc=%p fd=%d"
+
+# io/channel-file.c
+qio_channel_file_new_fd(void *ioc, int fd) "File new fd ioc=%p fd=%d"
+qio_channel_file_new_path(void *ioc, const char *path, int flags, int mode, int fd) "File new fd ioc=%p path=%s flags=%d mode=%d fd=%d"
Signature · 1 line
2.4.3
#39 lore raw

PATCH v2 13/16 io: add QIOChannelTLS class

In reply to Daniel P. Berrange

Add a QIOChannel subclass that can run the TLS protocol over the top of another QIOChannel instance. The object provides a simplified API to perform the handshake when starting the TLS session. The layering of TLS over the underlying channel does not have to be setup immediately. It is possible to take an existing QIOChannel that has done some handshake and then swap in the QIOChannelTLS layer. This allows for use with protocols which start TLS right away, and those which start plain text and then negotiate TLS.

---
 include/io/channel-tls.h    | 142 ++++++++++++++++
 io/Makefile.objs            |   1 +
 io/channel-tls.c            | 405 ++++++++++++++++++++++++++++++++++++++++++++
 tests/.gitignore            |   1 +
 tests/Makefile              |   4 +
 tests/test-io-channel-tls.c | 335 ++++++++++++++++++++++++++++++++++++
 trace-events                |  10 ++
 7 files changed, 898 insertions(+)
 create mode 100644 include/io/channel-tls.h
 create mode 100644 io/channel-tls.c
 create mode 100644 tests/test-io-channel-tls.c
include/io/channel-tls.h new file +142 -0
new file mode 100644
index 0000000..0298b17
@@ -0,0 +1,142 @@
+/*
+ * QEMU I/O channels TLS driver
+ *
+ * Copyright (c) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef QIO_CHANNEL_TLS_H__
+#define QIO_CHANNEL_TLS_H__
+
+#include "io/channel.h"
+#include "io/task.h"
+#include "crypto/tlssession.h"
+
+#define TYPE_QIO_CHANNEL_TLS "qio-channel-tls"
+#define QIO_CHANNEL_TLS(obj)                                     \
+    OBJECT_CHECK(QIOChannelTLS, (obj), TYPE_QIO_CHANNEL_TLS)
+
+typedef struct QIOChannelTLS QIOChannelTLS;
+
+/**
+ * QIOChannelTLS
+ *
+ * The QIOChannelTLS class provides a channel wrapper which
+ * can transparently run the TLS encryption protocol. It is
+ * usually used over a TCP socket, but there is actually no
+ * technical restriction on which type of master channel is
+ * used as the transport.
+ *
+ * This channel object is capable of running as either a
+ * TLS server or TLS client.
+ */
+
+struct QIOChannelTLS {
+    QIOChannel parent;
+    QIOChannel *master;
+    QCryptoTLSSession *session;
+};
+
+/**
+ * qio_channel_tls_new_server:
+ * @master: the underlying channel object
+ * @creds: the credentials to use for TLS handshake
+ * @aclname: the access control list for validating clients
+ * @errp: pointer to an uninitialized error object
+ *
+ * Create a new TLS channel that runs the server side of
+ * a TLS session. The TLS session handshake will use the
+ * credentials provided in @creds. If the @aclname parameter
+ * is non-NULL, then the client will have to provide
+ * credentials (ie a x509 client certificate) which will
+ * then be validated against the ACL.
+ *
+ * After creating the channel, it is mandatory to call
+ * the qio_channel_tls_handshake() method before attempting
+ * todo any I/O on the channel.
+ *
+ * Once the handshake has completed, all I/O should be done
+ * via the new TLS channel object and not the original
+ * master channel
+ *
+ * Returns: the new TLS channel object, or NULL
+ */
+QIOChannelTLS *
+qio_channel_tls_new_server(QIOChannel *master,
+                           QCryptoTLSCreds *creds,
+                           const char *aclname,
+                           Error **errp);
+
+/**
+ * qio_channel_tls_new_client:
+ * @master: the underlying channel object
+ * @creds: the credentials to use for TLS handshake
+ * @hostname: the user specified server hostname
+ * @errp: pointer to an uninitialized error object
+ *
+ * Create a new TLS channel that runs the client side of
+ * a TLS session. The TLS session handshake will use the
+ * credentials provided in @creds. The @hostname parameter
+ * should provide the user specified hostname of the server
+ * and will be validated against the server's credentials
+ * (ie CommonName of the x509 certificate)
+ *
+ * After creating the channel, it is mandatory to call
+ * the qio_channel_tls_handshake() method before attempting
+ * todo any I/O on the channel.
+ *
+ * Once the handshake has completed, all I/O should be done
+ * via the new TLS channel object and not the original
+ * master channel
+ *
+ * Returns: the new TLS channel object, or NULL
+ */
+QIOChannelTLS *
+qio_channel_tls_new_client(QIOChannel *master,
+                           QCryptoTLSCreds *creds,
+                           const char *hostname,
+                           Error **errp);
+
+/**
+ * qio_channel_tls_handshake:
+ * @ioc: the TLS channel object
+ * @func: the callback to invoke when completed
+ * @opaque: opaque data to pass to @func
+ * @destroy: optional callback to free @opaque
+ *
+ * Perform the TLS session handshake. This method
+ * will return immediately and the handshake will
+ * continue in the background, provided the main
+ * loop is running. When the handshake is complete,
+ * or fails, the @func callback will be invoked.
+ */
+void qio_channel_tls_handshake(QIOChannelTLS *ioc,
+                               QIOTaskFunc func,
+                               gpointer opaque,
+                               GDestroyNotify destroy);
+
+/**
+ * qio_channel_tls_get_session:
+ * @ioc: the TLS channel object
+ *
+ * Get the TLS session used by the channel.
+ *
+ * Returns: the TLS session
+ */
+QCryptoTLSSession *
+qio_channel_tls_get_session(QIOChannelTLS *ioc);
+
+#endif /* QIO_CHANNEL_TLS_H__ */
io/Makefile.objs +1 -0
index 3d2f232..a48011b 100644
@@ -1,5 +1,6 @@
 io-obj-y = channel.o
 io-obj-y += channel-file.o
 io-obj-y += channel-socket.o
+io-obj-y += channel-tls.o
 io-obj-y += channel-watch.o
 io-obj-y += task.o
io/channel-tls.c new file +405 -0

405 lines not on this page · raw message

tests/.gitignore +1 -0
index 9a1fc33..d92694e 100644
@@ -26,6 +26,7 @@ test-iov
 test-io-channel-file
 test-io-channel-file.txt
 test-io-channel-socket
+test-io-channel-tls
 test-io-task
 test-mul64
 test-opts-visitor
tests/Makefile +4 -0
index 3498762..e96f18c 100644
@@ -83,6 +83,7 @@ check-unit-$(CONFIG_GNUTLS) += tests/test-crypto-tlssession$(EXESUF)
 check-unit-y += tests/test-io-task$(EXESUF)
 check-unit-y += tests/test-io-channel-socket$(EXESUF)
 check-unit-y += tests/test-io-channel-file$(EXESUF)
+check-unit-$(CONFIG_GNUTLS) += tests/test-io-channel-tls$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -382,6 +383,9 @@ tests/test-io-channel-socket$(EXESUF): tests/test-io-channel-socket.o \
         tests/io-channel-helpers.o $(test-io-obj-y)
 tests/test-io-channel-file$(EXESUF): tests/test-io-channel-file.o \
         tests/io-channel-helpers.o $(test-io-obj-y)
+tests/test-io-channel-tls$(EXESUF): tests/test-io-channel-tls.o \
+	tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o \
+	tests/io-channel-helpers.o $(test-io-obj-y)
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
 libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
tests/test-io-channel-tls.c new file +335 -0

335 lines not on this page · raw message

trace-events +10 -0
index 26f6766..16b131c 100644
@@ -1737,3 +1737,13 @@ qio_channel_socket_accept_complete(void *ioc, void *cioc, int fd) "Socket accept
 # io/channel-file.c
 qio_channel_file_new_fd(void *ioc, int fd) "File new fd ioc=%p fd=%d"
 qio_channel_file_new_path(void *ioc, const char *path, int flags, int mode, int fd) "File new fd ioc=%p path=%s flags=%d mode=%d fd=%d"
+
+# io/channel-tls.c
+qio_channel_tls_new_client(void *ioc, void *master, void *creds, const char *hostname) "TLS new client ioc=%p master=%p creds=%p hostname=%s"
+qio_channel_tls_new_server(void *ioc, void *master, void *creds, const char *aclname) "TLS new client ioc=%p master=%p creds=%p acltname=%s"
+qio_channel_tls_handshake_start(void *ioc) "TLS handshake start ioc=%p"
+qio_channel_tls_handshake_pending(void *ioc, int status) "TLS handshake pending ioc=%p status=%d"
+qio_channel_tls_handshake_fail(void *ioc) "TLS handshake fail ioc=%p"
+qio_channel_tls_handshake_complete(void *ioc) "TLS handshake complete ioc=%p"
+qio_channel_tls_credentials_allow(void *ioc) "TLS credentials allow ioc=%p"
+qio_channel_tls_credentials_deny(void *ioc) "TLS credentials deny ioc=%p"
Signature · 1 line
2.4.3
#40 lore raw

PATCH v2 14/16 io: add QIOChannelWebsock class

In reply to Daniel P. Berrange

Add a QIOChannel subclass that can run the websocket protocol over the top of another QIOChannel instance. This initial implementation is only capable of acting as a websockets server. There is no support for acting as a websockets client yet.

---
 include/io/channel-websock.h | 108 +++++
 io/Makefile.objs             |   1 +
 io/channel-websock.c         | 975 +++++++++++++++++++++++++++++++++++++++++++
 trace-events                 |   8 +
 4 files changed, 1092 insertions(+)
 create mode 100644 include/io/channel-websock.h
 create mode 100644 io/channel-websock.c
include/io/channel-websock.h new file +108 -0
new file mode 100644
index 0000000..0dc21cc
@@ -0,0 +1,108 @@
+/*
+ * QEMU I/O channels driver websockets
+ *
+ * Copyright (c) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef QIO_CHANNEL_WEBSOCK_H__
+#define QIO_CHANNEL_WEBSOCK_H__
+
+#include "io/channel.h"
+#include "qemu/buffer.h"
+#include "io/task.h"
+
+#define TYPE_QIO_CHANNEL_WEBSOCK "qio-channel-websock"
+#define QIO_CHANNEL_WEBSOCK(obj)                                     \
+    OBJECT_CHECK(QIOChannelWebsock, (obj), TYPE_QIO_CHANNEL_WEBSOCK)
+
+typedef struct QIOChannelWebsock QIOChannelWebsock;
+typedef union QIOChannelWebsockMask QIOChannelWebsockMask;
+
+union QIOChannelWebsockMask {
+    char c[4];
+    uint32_t u;
+};
+
+/**
+ * QIOChannelWebsock
+ *
+ * The QIOChannelWebsock class provides a channel wrapper which
+ * can transparently run the HTTP websockets protocol. This is
+ * usually used over a TCP socket, but there is actually no
+ * technical restriction on which type of master channel is
+ * used as the transport.
+ *
+ * This channel object is currently only capable of running as
+ * a websocket server and is a pretty crude implementation
+ * of it, not supporting the full websockets protocol feature
+ * set. It is sufficient to use with a simple websockets
+ * client for encapsulating VNC for noVNC in-browser client.
+ */
+
+struct QIOChannelWebsock {
+    QIOChannel parent;
+    QIOChannel *master;
+    Buffer encinput;
+    Buffer encoutput;
+    Buffer rawinput;
+    Buffer rawoutput;
+    size_t payload_remain;
+    QIOChannelWebsockMask mask;
+    guint io_tag;
+    Error *io_err;
+    gboolean io_eof;
+};
+
+/**
+ * qio_channel_websock_new_server:
+ * @master: the underlying channel object
+ *
+ * Create a new websockets channel that runs the server
+ * side of the protocol.
+ *
+ * After creating the channel, it is mandatory to call
+ * the qio_channel_websock_handshake() method before attempting
+ * todo any I/O on the channel.
+ *
+ * Once the handshake has completed, all I/O should be done
+ * via the new websocket channel object and not the original
+ * master channel
+ *
+ * Returns: the new websockets channel object
+ */
+QIOChannelWebsock *
+qio_channel_websock_new_server(QIOChannel *master);
+
+/**
+ * qio_channel_websock_handshake:
+ * @ioc: the websocket channel object
+ * @func: the callback to invoke when completed
+ * @opaque: opaque data to pass to @func
+ * @destroy: optional callback to free @opaque
+ *
+ * Perform the websocket handshake. This method
+ * will return immediately and the handshake will
+ * continue in the background, provided the main
+ * loop is running. When the handshake is complete,
+ * or fails, the @func callback will be invoked.
+ */
+void qio_channel_websock_handshake(QIOChannelWebsock *ioc,
+                                   QIOTaskFunc func,
+                                   gpointer opaque,
+                                   GDestroyNotify destroy);
+
+#endif /* QIO_CHANNEL_WEBSOCK_H__ */
io/Makefile.objs +1 -0
index a48011b..e3771b1 100644
@@ -3,4 +3,5 @@ io-obj-y += channel-file.o
 io-obj-y += channel-socket.o
 io-obj-y += channel-tls.o
 io-obj-y += channel-watch.o
+io-obj-y += channel-websock.o
 io-obj-y += task.o
io/channel-websock.c new file +975 -0

975 lines not on this page · raw message

trace-events +8 -0
index 16b131c..57c90f9 100644
@@ -1747,3 +1747,11 @@ qio_channel_tls_handshake_fail(void *ioc) "TLS handshake fail ioc=%p"
 qio_channel_tls_handshake_complete(void *ioc) "TLS handshake complete ioc=%p"
 qio_channel_tls_credentials_allow(void *ioc) "TLS credentials allow ioc=%p"
 qio_channel_tls_credentials_deny(void *ioc) "TLS credentials deny ioc=%p"
+
+# io/channel-websock.c
+qio_channel_websock_new_server(void *ioc, void *master) "Websock new client ioc=%p master=%p"
+qio_channel_websock_handshake_start(void *ioc) "Websock handshake start ioc=%p"
+qio_channel_websock_handshake_pending(void *ioc, int status) "Websock handshake pending ioc=%p status=%d"
+qio_channel_websock_handshake_reply(void *ioc) "Websock handshake reply ioc=%p"
+qio_channel_websock_handshake_fail(void *ioc) "Websock handshake fail ioc=%p"
+qio_channel_websock_handshake_complete(void *ioc) "Websock handshake complete ioc=%p"
Signature · 1 line
2.4.3
#41 lore raw

PATCH v2 15/16 io: add QIOChannelCommand class

In reply to Daniel P. Berrange

Add a QIOChannel subclass that is capable of performing I/O to/from a separate process, via a pair of pipes. The command can be used for unidirectional or bi-directional I/O.

---
 include/io/channel-command.h    |  91 ++++++++++
 io/Makefile.objs                |   1 +
 io/channel-command.c            | 369 ++++++++++++++++++++++++++++++++++++++++
 tests/.gitignore                |   2 +
 tests/Makefile                  |   3 +
 tests/test-io-channel-command.c | 122 +++++++++++++
 trace-events                    |   6 +
 7 files changed, 594 insertions(+)
 create mode 100644 include/io/channel-command.h
 create mode 100644 io/channel-command.c
 create mode 100644 tests/test-io-channel-command.c
include/io/channel-command.h new file +91 -0
new file mode 100644
index 0000000..bd3c599
@@ -0,0 +1,91 @@
+/*
+ * QEMU I/O channels external command driver
+ *
+ * Copyright (c) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef QIO_CHANNEL_COMMAND_H__
+#define QIO_CHANNEL_COMMAND_H__
+
+#include "io/channel.h"
+
+#define TYPE_QIO_CHANNEL_COMMAND "qio-channel-command"
+#define QIO_CHANNEL_COMMAND(obj)                                     \
+    OBJECT_CHECK(QIOChannelCommand, (obj), TYPE_QIO_CHANNEL_COMMAND)
+
+typedef struct QIOChannelCommand QIOChannelCommand;
+
+
+/**
+ * QIOChannelCommand:
+ *
+ * The QIOChannelCommand class provides a channel implementation
+ * that can transport data with an externally running command
+ * via its stdio streams.
+ */
+
+struct QIOChannelCommand {
+    QIOChannel parent;
+    int writefd;
+    int readfd;
+    pid_t pid;
+};
+
+
+/**
+ * qio_channel_command_new_pid:
+ * @writefd: the FD connected to the command's stdin
+ * @readfd: the FD connected to the command's stdout
+ * @pid: the PID of the running child command
+ * @errp: pointer to an uninitialized error object
+ *
+ * Create a channel for performing I/O with the
+ * previously spawned command identified by @pid.
+ * The two file descriptors provide the connection
+ * to command's stdio streams, either one or which
+ * may be -1 to indicate that stream is not open.
+ *
+ * The channel will take ownership of the process
+ * @pid and will kill it when closing the channel.
+ * Similarly it will take responsibility for
+ * closing the file descriptors @writefd and @readfd.
+ *
+ * Returns: the command channel object, or NULL on error
+ */
+QIOChannelCommand *
+qio_channel_command_new_pid(int writefd,
+                            int readfd,
+                            pid_t pid);
+
+/**
+ * qio_channel_command_new_spawn:
+ * @argv: the NULL terminated list of command arguments
+ * @flags: the I/O mode, one of O_RDONLY, O_WRONLY, O_RDWR
+ * @errp: pointer to an uninitialized error object
+ *
+ * Create a channel for performing I/O with the
+ * command to be spawned with arguments @argv.
+ *
+ * Returns: the command channel object, or NULL on error
+ */
+QIOChannelCommand *
+qio_channel_command_new_spawn(const char *const argv[],
+                              int flags,
+                              Error **errp);
+
+
+#endif /* QIO_CHANNEL_COMMAND_H__ */
io/Makefile.objs +1 -0
index e3771b1..1a58ccb 100644
@@ -1,4 +1,5 @@
 io-obj-y = channel.o
+io-obj-y += channel-command.o
 io-obj-y += channel-file.o
 io-obj-y += channel-socket.o
 io-obj-y += channel-tls.o
io/channel-command.c new file +369 -0

369 lines not on this page · raw message

tests/.gitignore +2 -0
index d92694e..e761c17 100644
@@ -23,6 +23,8 @@ test-cutils
 test-hbitmap
 test-int128
 test-iov
+test-io-channel-command
+test-io-channel-command.fifo
 test-io-channel-file
 test-io-channel-file.txt
 test-io-channel-socket
tests/Makefile +3 -0
index e96f18c..d41b36f 100644
@@ -84,6 +84,7 @@ check-unit-y += tests/test-io-task$(EXESUF)
 check-unit-y += tests/test-io-channel-socket$(EXESUF)
 check-unit-y += tests/test-io-channel-file$(EXESUF)
 check-unit-$(CONFIG_GNUTLS) += tests/test-io-channel-tls$(EXESUF)
+check-unit-y += tests/test-io-channel-command$(EXESUF)
 
 check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
 
@@ -386,6 +387,8 @@ tests/test-io-channel-file$(EXESUF): tests/test-io-channel-file.o \
 tests/test-io-channel-tls$(EXESUF): tests/test-io-channel-tls.o \
 	tests/crypto-tls-x509-helpers.o tests/pkix_asn1_tab.o \
 	tests/io-channel-helpers.o $(test-io-obj-y)
+tests/test-io-channel-command$(EXESUF): tests/test-io-channel-command.o \
+        tests/io-channel-helpers.o $(test-io-obj-y)
 
 libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
 libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
tests/test-io-channel-command.c new file +122 -0

122 lines not on this page · raw message

trace-events +6 -0
index 57c90f9..9c4ef4a 100644
@@ -1755,3 +1755,9 @@ qio_channel_websock_handshake_pending(void *ioc, int status) "Websock handshake
 qio_channel_websock_handshake_reply(void *ioc) "Websock handshake reply ioc=%p"
 qio_channel_websock_handshake_fail(void *ioc) "Websock handshake fail ioc=%p"
 qio_channel_websock_handshake_complete(void *ioc) "Websock handshake complete ioc=%p"
+
+# io/channel-command.c
+qio_channel_command_new_pid(void *ioc, int writefd, int readfd, int pid) "Command new pid ioc=%p writefd=%d readfd=%d pid=%d"
+qio_channel_command_new_spawn(void *ioc, const char *binary, int flags) "Command new spawn ioc=%p binary=%s flags=%d"
+qio_channel_command_abort(void *ioc, int pid) "Command abort ioc=%p pid=%d"
+qio_channel_command_wait(void *ioc, int pid, int ret, int status) "Command abort ioc=%p pid=%d ret=%d status=%d"
Signature · 1 line
2.4.3
#42 lore raw

PATCH v2 16/16 io: add QIOChannelBuffer class

In reply to Daniel P. Berrange

Add a QIOChannel subclass that is capable of performing I/O to/from a memory buffer. This implementation does not attempt to support concurrent readers & writers. It is designed for serialized access where by a single thread at a time may write data, seek and then read data back out.

---
 include/io/channel-buffer.h |  59 ++++++++++
 io/Makefile.objs            |   1 +
 io/channel-buffer.c         | 255 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 315 insertions(+)
 create mode 100644 include/io/channel-buffer.h
 create mode 100644 io/channel-buffer.c
include/io/channel-buffer.h new file +59 -0
new file mode 100644
index 0000000..1e0f6c2
@@ -0,0 +1,59 @@
+/*
+ * QEMU I/O channels memory buffer driver
+ *
+ * Copyright (c) 2015 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef QIO_CHANNEL_BUFFER_H__
+#define QIO_CHANNEL_BUFFER_H__
+
+#include "io/channel.h"
+
+#define TYPE_QIO_CHANNEL_BUFFER "qio-channel-buffer"
+#define QIO_CHANNEL_BUFFER(obj)                                     \
+    OBJECT_CHECK(QIOChannelBuffer, (obj), TYPE_QIO_CHANNEL_BUFFER)
+
+typedef struct QIOChannelBuffer QIOChannelBuffer;
+
+/**
+ * QIOChannelBuffer:
+ *
+ * The QIOChannelBuffer object provides a channel implementation
+ * that is able to perform I/O to/from a memory buffer.
+ *
+ */
+
+struct QIOChannelBuffer {
+    QIOChannel parent;
+    size_t capacity; /* Total allocated memory */
+    size_t usage;    /* Current size of data */
+    size_t offset;   /* Offset for future I/O ops */
+    char *data;
+};
+
+
+/**
+ * qio_channel_buffer_new:
+ *
+ * Allocate a new buffer which is initially empty
+ *
+ * Returns: the new channel object
+ */
+QIOChannelBuffer *
+qio_channel_buffer_new(void);
+
+#endif /* QIO_CHANNEL_BUFFER_H__ */
io/Makefile.objs +1 -0
index 1a58ccb..0e3de31 100644
@@ -1,4 +1,5 @@
 io-obj-y = channel.o
+io-obj-y += channel-buffer.o
 io-obj-y += channel-command.o
 io-obj-y += channel-file.o
 io-obj-y += channel-socket.o
io/channel-buffer.c new file +255 -0

255 lines not on this page · raw message

Signature · 1 line
2.4.3
#43 lore raw
In reply to Daniel P. Berrange

Ping, does anyone feel like doing a review of this series, if not I'll just do a pull request as-is...

Daniel

Quoted 321 lines · Daniel P. Berrange

This series of patches is a followup submission for review of another chunk of my large series supporting TLS across chardevs, VNC and migration, previously shown here:

RFC: https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00829.html
v1: https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg04853.html

In this series, I have provided only the general I/O channels framework, which will ultimately be used by VNC, chardev and migration code, whicih currently work as follows:

- VNC: uses raw sockets APIs directly, layering in TLS, SASL and websockets where needed. This has resulted in what should be fairly generic code for TLS and websockets being entangled with the rest of the VNC server code.

- Chardevs: uses GLib's GIOChannel framework. This only provides implementations for sockets and files. Its API lacks support for using struct iovec for read/writes, file descriptor passing, misc sockets ioctls/fcntls. While you can work around these problems by accessing the underling file descriptor directly, this breaks the encapsulation, requiring callers to know about specific implementations. It also does not have integration with QEMU Error reporting framework. So while the GIOChannel is extensible, extending it would result in throwing away pretty much the entire of the existing implementations

- Migration: uses QEMUFile framework. The provides an abstract interface for I/O channels used during migration. It has impls for sockets, files, memory buffers & commands. While it has struct iovec support for writes, it does not have the same for reads. It also doesn't support file descriptor passing or control of the sockets ioctls/fcntls. It also does not have any explicit event loop integration, expecting the callers to directly access the underling file desctriptor and setup events on that. This limits its utility in cases where you need channels which are not backed by file descriptors. It has no integration with QEMU Error object for error reporting, has fixed semantics wrt writes ie must always do a full write, no partial writes, and most strangely forces either input or output mode, but refuses to allow both, so no bi-directional channels!

Out of all of these, the migration code is probably closest to what is needed, but is still a good way off from being a generic framework that be can reused outside of the migration code.

There is also the GLib GIO library which provides a generic framework, but we can't depend on that due to the minimum GLib requirement. It also has various missing pieces such as file descriptor passing, and no support for struct iovec either.

Hence, this series was born, which tries to take the best of the designs for the GIOChannel, QIO and QEMUFile code to provide QIOChannel. Right from the start this new framework is explicitly isolated from any other QEMU subsystem, so its implementation will not get mixed up with specific use cases.

The QIOChannel abstract base class defines the overall API contract

- qio_channel_{write,writev,write_full} for writing data. The underling impl always uses struct iovec, but non-iov APIs are provided as simple wrappers for convenience

- qio_channel_{read,readv,read_full} for reading data. The underling impl always uses struct iovec, but non-iov APIs are provided as simple wrappers for convenience

- qio_channel_has_feature to determine which optional features the channel supports - eg file descriptor passing, nagle, etc

- qio_channel_set_{blocking,delay,cork} for various fcntl and ioctl controls

- qio_channel_{close,shutdown} for closing the I/O stream or individual channels

- qio_channel_seek for random access channels

- qio_channel_{add,create}_watch for integration into the main loop for event notifications

- qio_channel_wait for blocking of execution pending an event notification

- qio_channel_yield for switching coroutine until an event notification

All the APIs support Error ** object arguments where needed. The object is built using QOM, in order to get reference counting and sub-classing with type checking. They are *not* user creatable/visible objects though - these are internal infrastructure, so we will be free to adapt APIs/objects at will over time.

In this series there are a variety of implementations. Some of them provide an actual base layer data transport, while others provide a data translation layer:

In this series there are a variety of implementations. Some of them provide an actual base layer data transport, while others provide a data translation layer:

- QIOChannelSocket - for socket based I/O, IPv4, IPV6 & UNIX, both stream and datagram.
- QIOChannelFile - any non-socket file, plain file, char dev, fifo, pipe, etc
- QIOChannelTLS - data translation layer to apply TLS protocol
- QIOChannelWebsock - data translation layer to apply the websockets server protocol
- QIOChannelCommand - spawn & communicate with a command via pipes
- QIOChannelBuffer - a simple in-memory buffer

These 6 implementations are sufficient to support the current needs of the VNC server, chardev network backends, and all the various migration protocols, except RDMA (which is part of the larger RFC series I've posted previously).

The sockets implementation in particular solves a long standing limitation of the qemu-sockets.c API by providing a truely asynchronous API for establishing listener sockets / connections. The current code is only async for the socket establishment, but still blocks the caller for DNS resolution.

I have not attempted to make the socket implementation support multiple listener sockets in a single object. I looked at this but it would significantly complicate the QIOChannelSocket implementation. I intend to suggest an alternative approach for that problem at a later date, whereby we define a QIONetworkService object, which provides the infrastructure for managing multiple QIOChannelSocket listeners, and clients, which was resuable for any QEMU network service.

There are unit tests for the socket, file, tls, and command channel implementations. I didn't create unit test for the websock impl, as it needs a websock client to usefully test it which doesn't exist in QEMU yet. The memory buffer impl also lacks unit tests for now, simply due to not getting around to it yet.

This series merely introduces all the new framework. To keep it an acceptable length for review, it doesn't include any of the patches which actually use the new APIs. If reviewers want to see real world usage of these APIs, they can refer to my previous RFC series.

https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00829.html

In particular

- VNC conversion to QIOChannelSocket

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00851.html

- VNC conversion to QIOChannelTLS

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00845.html

- VNC conversion to QIOChannelWebsock

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00842.html

- Chardev conversion to QIOChannelSocket

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00849.html

- Chardev addition of TLS support

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00848.html

- All the migration ones, but most interesting addition of TLS

     https://lists.gnu.org/archive/html/qemu-devel/2015-09/msg00871.html

Finally I've listed myself as maintainer for the new io/ and include/io/ directory prefixes.

Changed in v2:

- Put the Buffer APIs extracted from VNC code into util/ instead of io/ directories (Paolo)

- Added Kevin & Stefan to MAINTAINERS for coroutine code (Paolo)

- Remove feature checks for TCP_NODELAY and TCP_CORK and treat them as hints which cannot fail (Paolo)

- Push feature checking for FD passing up into QIOChannel base class (Paolo)

- Use more constants in websockets code instead of magic values (David Gilbert)

Daniel P. Berrange (16):
sockets: add helpers for creating SocketAddress from a socket
sockets: move qapi_copy_SocketAddress into qemu-sockets.c
sockets: allow port to be NULL when listening on IP address
ui: convert VNC startup code to use SocketAddress
osdep: add qemu_fork() wrapper for safely handling signals
coroutine: move into libqemuutil.a library
util: pull Buffer code out of VNC module
io: add abstract QIOChannel classes
io: add helper module for creating watches on FDs
io: add QIOTask class for async operations
io: add QIOChannelSocket class
io: add QIOChannelFile class
io: add QIOChannelTLS class
io: add QIOChannelWebsock class
io: add QIOChannelCommand class
io: add QIOChannelBuffer class

 MAINTAINERS                                        |  20 +
 Makefile                                           |   2 +
 Makefile.objs                                      |   9 +-
 Makefile.target                                    |   2 +
 block.c                                            |   2 +-
 block/qcow2.h                                      |   2 +-
 block/vdi.c                                        |   2 +-
 block/write-threshold.c                            |   2 +-
 blockjob.c                                         |   2 +-
 configure                                          |  11 +
 hw/9pfs/codir.c                                    |   2 +-
 hw/9pfs/cofile.c                                   |   2 +-
 hw/9pfs/cofs.c                                     |   2 +-
 hw/9pfs/coxattr.c                                  |   2 +-
 hw/9pfs/virtio-9p-coth.c                           |   2 +-
 hw/9pfs/virtio-9p-coth.h                           |   2 +-
 hw/9pfs/virtio-9p.h                                |   2 +-
 include/block/block.h                              |   2 +-
 include/block/block_int.h                          |   2 +-
 include/io/channel-buffer.h                        |  59 ++
 include/io/channel-command.h                       |  91 ++
 include/io/channel-file.h                          |  93 ++
 include/io/channel-socket.h                        | 244 ++++++
 include/io/channel-tls.h                           | 142 +++
 include/io/channel-watch.h                         |  72 ++
 include/io/channel-websock.h                       | 108 +++
 include/io/channel.h                               | 506 +++++++++++
 include/io/task.h                                  | 256 ++++++
 include/qemu/buffer.h                              | 118 +++
 include/{block => qemu}/coroutine.h                |   0
 include/{block => qemu}/coroutine_int.h            |   2 +-
 include/qemu/osdep.h                               |  16 +
 include/qemu/sockets.h                             |  34 +
 io/Makefile.objs                                   |   9 +
 io/channel-buffer.c                                | 255 ++++++
 io/channel-command.c                               | 369 ++++++++
 io/channel-file.c                                  | 237 +++++
 io/channel-socket.c                                | 737 ++++++++++++++++
 io/channel-tls.c                                   | 405 +++++++++
 io/channel-watch.c                                 | 200 +++++
 io/channel-websock.c                               | 975 +++++++++++++++++++++
 io/channel.c                                       | 283 ++++++
 io/task.c                                          | 159 ++++
 migration/qemu-file-buf.c                          |   2 +-
 migration/qemu-file-stdio.c                        |   2 +-
 migration/qemu-file-unix.c                         |   2 +-
 migration/qemu-file.c                              |   2 +-
 migration/rdma.c                                   |   2 +-
 nbd.c                                              |   2 +-
 qemu-char.c                                        |  25 -
 scripts/create_config                              |   9 +
 tests/.gitignore                                   |   7 +
 tests/Makefile                                     |  16 +
 tests/io-channel-helpers.c                         | 247 ++++++
 tests/io-channel-helpers.h                         |  33 +
 tests/test-coroutine.c                             |   4 +-
 tests/test-io-channel-command.c                    | 122 +++
 tests/test-io-channel-file.c                       |  91 ++
 tests/test-io-channel-socket.c                     | 367 ++++++++
 tests/test-io-channel-tls.c                        | 335 +++++++
 tests/test-io-task.c                               | 276 ++++++
 tests/test-vmstate.c                               |   2 +-
 thread-pool.c                                      |   2 +-
 trace-events                                       |  56 ++
 ui/vnc.c                                           | 204 ++---
 ui/vnc.h                                           |  16 +-
 util/Makefile.objs                                 |   4 +
 util/buffer.c                                      |  65 ++
 coroutine-gthread.c => util/coroutine-gthread.c    |   2 +-
 .../coroutine-sigaltstack.c                        |   2 +-
 coroutine-ucontext.c => util/coroutine-ucontext.c  |   2 +-
 coroutine-win32.c => util/coroutine-win32.c        |   2 +-
 util/oslib-posix.c                                 |  71 ++
 util/oslib-win32.c                                 |   9 +
 qemu-coroutine-io.c => util/qemu-coroutine-io.c    |   2 +-
 .../qemu-coroutine-lock.c                          |   4 +-
 .../qemu-coroutine-sleep.c                         |   2 +-
 qemu-coroutine.c => util/qemu-coroutine.c          |   4 +-
 util/qemu-sockets.c                                | 158 +++-
 79 files changed, 7396 insertions(+), 197 deletions(-)
 create mode 100644 include/io/channel-buffer.h
 create mode 100644 include/io/channel-command.h
 create mode 100644 include/io/channel-file.h
 create mode 100644 include/io/channel-socket.h
 create mode 100644 include/io/channel-tls.h
 create mode 100644 include/io/channel-watch.h
 create mode 100644 include/io/channel-websock.h
 create mode 100644 include/io/channel.h
 create mode 100644 include/io/task.h
 create mode 100644 include/qemu/buffer.h
 rename include/{block => qemu}/coroutine.h (100%)
 rename include/{block => qemu}/coroutine_int.h (98%)
 create mode 100644 io/Makefile.objs
 create mode 100644 io/channel-buffer.c
 create mode 100644 io/channel-command.c
 create mode 100644 io/channel-file.c
 create mode 100644 io/channel-socket.c
 create mode 100644 io/channel-tls.c
 create mode 100644 io/channel-watch.c
 create mode 100644 io/channel-websock.c
 create mode 100644 io/channel.c
 create mode 100644 io/task.c
 create mode 100644 tests/io-channel-helpers.c
 create mode 100644 tests/io-channel-helpers.h
 create mode 100644 tests/test-io-channel-command.c
 create mode 100644 tests/test-io-channel-file.c
 create mode 100644 tests/test-io-channel-socket.c
 create mode 100644 tests/test-io-channel-tls.c
 create mode 100644 tests/test-io-task.c
 create mode 100644 util/buffer.c
Quoted 12 lines
 rename coroutine-gthread.c => util/coroutine-gthread.c (99%)
 rename coroutine-sigaltstack.c => util/coroutine-sigaltstack.c (99%)
 rename coroutine-ucontext.c => util/coroutine-ucontext.c (99%)
 rename coroutine-win32.c => util/coroutine-win32.c (98%)
 rename qemu-coroutine-io.c => util/qemu-coroutine-io.c (99%)
 rename qemu-coroutine-lock.c => util/qemu-coroutine-lock.c (98%)
 rename qemu-coroutine-sleep.c => util/qemu-coroutine-sleep.c (96%)
 rename qemu-coroutine.c => util/qemu-coroutine.c (98%)
Signature · 1 line
2.4.3

Regards,
Daniel

Signature · 4 lines
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|
#44 lore raw
Quoted 2 lines · Daniel P. Berrange

Ping, does anyone feel like doing a review of this series, if not I'll just do a pull request as-is...

You can certainly do a pull request of patches 1-7. For 8-16, I haven't reviewed it because I'm not sure how much it makes sense to commit QIOChannel without a user.

Thanks,

Paolo