All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v2 08/16] io: add abstract QIOChannel classes
Date: Tue, 20 Oct 2015 11:48:03 -0600	[thread overview]
Message-ID: <56267E53.1050708@redhat.com> (raw)
In-Reply-To: <1444648509-29179-9-git-send-email-berrange@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 5566 bytes --]

On 10/12/2015 05:15 AM, Daniel P. Berrange wrote:
> 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.
> 
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
> ---
>  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
> @@ -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?

> +};
> +
> +/**
> + * 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...

> + *
> + * Consult the corresponding public API docs for a description
> + * of the semantics of each callback
> + */
> +struct QIOChannelClass {
> +    ObjectClass parent;
> +
> +    /* Mandatory callbacks */
...
> +
> +    /* 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.


> +
> +/**
> + * 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?


> +/**
> + * 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?

> + * @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.

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

> +++ b/io/channel.c
> @@ -0,0 +1,283 @@

> +ssize_t qio_channel_readv_full(QIOChannel *ioc,
> +                               const struct iovec *iov,
> +                               size_t niov,
> +                               int **fds,
> +                               size_t *nfds,
> +                               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...

> +
> +    return klass->io_readv(ioc, iov, niov, fds, nfds, errp);
> +}
> +
> +
> +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?

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-10-20 17:48 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-12 11:14 [Qemu-devel] [PATCH v2 00/16] Introduce I/O channels framework Daniel P. Berrange
2015-10-12 11:14 ` [Qemu-devel] [PATCH v2 01/16] sockets: add helpers for creating SocketAddress from a socket Daniel P. Berrange
2015-10-19 21:43   ` Eric Blake
2015-10-20 13:20     ` Daniel P. Berrange
2015-10-12 11:14 ` [Qemu-devel] [PATCH v2 02/16] sockets: move qapi_copy_SocketAddress into qemu-sockets.c Daniel P. Berrange
2015-10-19 22:05   ` Eric Blake
2015-10-20 12:08     ` Paolo Bonzini
2015-10-20 12:27       ` Daniel P. Berrange
2015-10-12 11:14 ` [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address Daniel P. Berrange
2015-10-19 22:12   ` Eric Blake
2015-10-20 13:19     ` Daniel P. Berrange
2015-10-21 17:52   ` Knut Omang
2015-10-22  9:43     ` Daniel P. Berrange
2015-10-22 10:02       ` Peter Maydell
2015-10-22 12:10         ` Markus Armbruster
2015-10-22 12:43           ` Daniel P. Berrange
2015-10-22 13:59           ` Eric Blake
2015-10-31  8:51     ` Shannon Zhao
2015-10-31 10:40       ` Peter Maydell
2015-11-02  9:14         ` Markus Armbruster
2015-10-12 11:14 ` [Qemu-devel] [PATCH v2 04/16] ui: convert VNC startup code to use SocketAddress Daniel P. Berrange
2015-10-19 22:20   ` Eric Blake
2015-10-20 13:39     ` Daniel P. Berrange
2015-10-20 17:01       ` Peter Maydell
2015-10-20 18:50         ` Daniel P. Berrange
2015-10-20 20:36           ` Peter Maydell
2015-10-21  9:01             ` Daniel P. Berrange
2015-10-12 11:14 ` [Qemu-devel] [PATCH v2 05/16] osdep: add qemu_fork() wrapper for safely handling signals Daniel P. Berrange
2015-10-19 22:24   ` Eric Blake
2015-10-12 11:14 ` [Qemu-devel] [PATCH v2 06/16] coroutine: move into libqemuutil.a library Daniel P. Berrange
2015-10-12 11:15 ` [Qemu-devel] [PATCH v2 07/16] util: pull Buffer code out of VNC module Daniel P. Berrange
2015-10-12 11:15 ` [Qemu-devel] [PATCH v2 08/16] io: add abstract QIOChannel classes Daniel P. Berrange
2015-10-20 17:48   ` Eric Blake [this message]
2015-10-21 17:32     ` Daniel P. Berrange
2015-10-21 18:20       ` Eric Blake
2015-10-12 11:15 ` [Qemu-devel] [PATCH v2 09/16] io: add helper module for creating watches on FDs Daniel P. Berrange
2015-10-12 11:15 ` [Qemu-devel] [PATCH v2 10/16] io: add QIOTask class for async operations Daniel P. Berrange
2015-10-12 11:15 ` [Qemu-devel] [PATCH v2 11/16] io: add QIOChannelSocket class Daniel P. Berrange
2015-10-12 11:15 ` [Qemu-devel] [PATCH v2 12/16] io: add QIOChannelFile class Daniel P. Berrange
2015-10-12 11:15 ` [Qemu-devel] [PATCH v2 13/16] io: add QIOChannelTLS class Daniel P. Berrange
2015-10-12 11:15 ` [Qemu-devel] [PATCH v2 14/16] io: add QIOChannelWebsock class Daniel P. Berrange
2015-10-12 11:15 ` [Qemu-devel] [PATCH v2 15/16] io: add QIOChannelCommand class Daniel P. Berrange
2015-10-12 11:15 ` [Qemu-devel] [PATCH v2 16/16] io: add QIOChannelBuffer class Daniel P. Berrange
2015-10-19 13:47 ` [Qemu-devel] [PATCH v2 00/16] Introduce I/O channels framework Daniel P. Berrange
2015-10-19 14:11   ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56267E53.1050708@redhat.com \
    --to=eblake@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.