From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: "Daniel P. Berrange" <berrange@redhat.com>
Cc: Amit Shah <amit.shah@redhat.com>,
qemu-devel@nongnu.org, Juan Quintela <quintela@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v3 16/27] migration: convert RDMA to use QIOChannel interface
Date: Thu, 10 Mar 2016 17:00:20 +0000 [thread overview]
Message-ID: <20160310170019.GI10196@work-vm> (raw)
In-Reply-To: <1456499430-8558-17-git-send-email-berrange@redhat.com>
* Daniel P. Berrange (berrange@redhat.com) wrote:
> This converts the RDMA code to provide a subclass of
> QIOChannel that uses RDMA for the data transport.
>
> This implementation of RDMA does not correctly
> handle non-blocking mode. Reads might block
> if there was not already some pending data
> and writes will block until all data is sent.
> This flawed behaviour was already present in
> the existing impl, so appears to not be a
> critical problem at this time. It should be
> on the list of things to fix in the future
> though.
>
> The RDMA code would be much better off it it could
> be split up in a generic RDMA layer, a QIOChannel
> impl based on RMDA, and then the RMDA migration
> glue. This is left as a future exercise for the brave.
>
> Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
(I don't know that much about the GSource stuff, but it looks
consistent)
> +static gboolean
> +qio_channel_rdma_source_prepare(GSource *source,
> + gint *timeout)
> +{
> + QIOChannelRDMASource *rsource = (QIOChannelRDMASource *)source;
> + RDMAContext *rdma = rsource->rioc->rdma;
> + GIOCondition cond = 0;
> + *timeout = -1;
> +
> + if (rdma->wr_data[0].control_len) {
> + cond |= G_IO_IN;
> + }
> + cond |= G_IO_OUT;
> +
> + return cond & rsource->condition;
> +}
I guess you could make that:
*timeout = -1;
return qio_channel_rdma_source_check(source);
Dave
> +static gboolean
> +qio_channel_rdma_source_check(GSource *source)
> +{
> + QIOChannelRDMASource *rsource = (QIOChannelRDMASource *)source;
> + RDMAContext *rdma = rsource->rioc->rdma;
> + GIOCondition cond = 0;
> +
> + if (rdma->wr_data[0].control_len) {
> + cond |= G_IO_IN;
> + }
> + cond |= G_IO_OUT;
> +
> + return cond & rsource->condition;
> +}
> +
> +static gboolean
> +qio_channel_rdma_source_dispatch(GSource *source,
> + GSourceFunc callback,
> + gpointer user_data)
> +{
> + QIOChannelFunc func = (QIOChannelFunc)callback;
> + QIOChannelRDMASource *rsource = (QIOChannelRDMASource *)source;
> + RDMAContext *rdma = rsource->rioc->rdma;
> + GIOCondition cond = 0;
> +
> + if (rdma->wr_data[0].control_len) {
> + cond |= G_IO_IN;
> + }
> + cond |= G_IO_OUT;
> +
> + return (*func)(QIO_CHANNEL(rsource->rioc),
> + (cond & rsource->condition),
> + user_data);
> +}
> +
> +static void
> +qio_channel_rdma_source_finalize(GSource *source)
> +{
> + QIOChannelRDMASource *ssource = (QIOChannelRDMASource *)source;
> +
> + object_unref(OBJECT(ssource->rioc));
> +}
> +
> +GSourceFuncs qio_channel_rdma_source_funcs = {
> + qio_channel_rdma_source_prepare,
> + qio_channel_rdma_source_check,
> + qio_channel_rdma_source_dispatch,
> + qio_channel_rdma_source_finalize
> +};
> +
> +static GSource *qio_channel_rdma_create_watch(QIOChannel *ioc,
> + GIOCondition condition)
> {
> + QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(ioc);
> + QIOChannelRDMASource *ssource;
> + GSource *source;
> +
> + source = g_source_new(&qio_channel_rdma_source_funcs,
> + sizeof(QIOChannelRDMASource));
> + ssource = (QIOChannelRDMASource *)source;
> +
> + ssource->rioc = rioc;
> + object_ref(OBJECT(rioc));
> +
> + ssource->condition = condition;
> +
> + return source;
> +}
> +
> +
> +static int qio_channel_rdma_close(QIOChannel *ioc,
> + Error **errp)
> +{
> + QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(ioc);
> trace_qemu_rdma_close();
> - QEMUFileRDMA *r = opaque;
> - if (r->rdma) {
> - qemu_rdma_cleanup(r->rdma);
> - g_free(r->rdma);
> + if (rioc->rdma) {
> + qemu_rdma_cleanup(rioc->rdma);
> + g_free(rioc->rdma);
> + rioc->rdma = NULL;
> }
> - g_free(r);
> return 0;
> }
>
> @@ -2694,8 +2850,8 @@ static size_t qemu_rdma_save_page(QEMUFile *f, void *opaque,
> ram_addr_t block_offset, ram_addr_t offset,
> size_t size, uint64_t *bytes_sent)
> {
> - QEMUFileRDMA *rfile = opaque;
> - RDMAContext *rdma = rfile->rdma;
> + QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(opaque);
> + RDMAContext *rdma = rioc->rdma;
> int ret;
>
> CHECK_ERROR_STATE();
> @@ -2949,8 +3105,8 @@ static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque)
> };
> RDMAControlHeader blocks = { .type = RDMA_CONTROL_RAM_BLOCKS_RESULT,
> .repeat = 1 };
> - QEMUFileRDMA *rfile = opaque;
> - RDMAContext *rdma = rfile->rdma;
> + QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(opaque);
> + RDMAContext *rdma = rioc->rdma;
> RDMALocalBlocks *local = &rdma->local_ram_blocks;
> RDMAControlHeader head;
> RDMARegister *reg, *registers;
> @@ -3205,9 +3361,10 @@ out:
> * We've already built our local RAMBlock list, but not yet sent the list to
> * the source.
> */
> -static int rdma_block_notification_handle(QEMUFileRDMA *rfile, const char *name)
> +static int
> +rdma_block_notification_handle(QIOChannelRDMA *rioc, const char *name)
> {
> - RDMAContext *rdma = rfile->rdma;
> + RDMAContext *rdma = rioc->rdma;
> int curr;
> int found = -1;
>
> @@ -3249,8 +3406,8 @@ static int rdma_load_hook(QEMUFile *f, void *opaque, uint64_t flags, void *data)
> static int qemu_rdma_registration_start(QEMUFile *f, void *opaque,
> uint64_t flags, void *data)
> {
> - QEMUFileRDMA *rfile = opaque;
> - RDMAContext *rdma = rfile->rdma;
> + QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(opaque);
> + RDMAContext *rdma = rioc->rdma;
>
> CHECK_ERROR_STATE();
>
> @@ -3269,8 +3426,8 @@ static int qemu_rdma_registration_stop(QEMUFile *f, void *opaque,
> uint64_t flags, void *data)
> {
> Error *local_err = NULL, **errp = &local_err;
> - QEMUFileRDMA *rfile = opaque;
> - RDMAContext *rdma = rfile->rdma;
> + QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(opaque);
> + RDMAContext *rdma = rioc->rdma;
> RDMAControlHeader head = { .len = 0, .repeat = 1 };
> int ret = 0;
>
> @@ -3366,55 +3523,74 @@ err:
> return ret;
> }
>
> -static int qemu_rdma_get_fd(void *opaque)
> -{
> - QEMUFileRDMA *rfile = opaque;
> - RDMAContext *rdma = rfile->rdma;
> -
> - return rdma->comp_channel->fd;
> -}
> -
> -static const QEMUFileOps rdma_read_ops = {
> - .get_buffer = qemu_rdma_get_buffer,
> - .get_fd = qemu_rdma_get_fd,
> - .close = qemu_rdma_close,
> -};
> -
> static const QEMUFileHooks rdma_read_hooks = {
> .hook_ram_load = rdma_load_hook,
> };
>
> -static const QEMUFileOps rdma_write_ops = {
> - .put_buffer = qemu_rdma_put_buffer,
> - .close = qemu_rdma_close,
> -};
> -
> static const QEMUFileHooks rdma_write_hooks = {
> .before_ram_iterate = qemu_rdma_registration_start,
> .after_ram_iterate = qemu_rdma_registration_stop,
> .save_page = qemu_rdma_save_page,
> };
>
> -static void *qemu_fopen_rdma(RDMAContext *rdma, const char *mode)
> +
> +static void qio_channel_rdma_finalize(Object *obj)
> +{
> + QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(obj);
> + if (rioc->rdma) {
> + qemu_rdma_cleanup(rioc->rdma);
> + g_free(rioc->rdma);
> + rioc->rdma = NULL;
> + }
> +}
> +
> +static void qio_channel_rdma_class_init(ObjectClass *klass,
> + void *class_data G_GNUC_UNUSED)
> +{
> + QIOChannelClass *ioc_klass = QIO_CHANNEL_CLASS(klass);
> +
> + ioc_klass->io_writev = qio_channel_rdma_writev;
> + ioc_klass->io_readv = qio_channel_rdma_readv;
> + ioc_klass->io_set_blocking = qio_channel_rdma_set_blocking;
> + ioc_klass->io_close = qio_channel_rdma_close;
> + ioc_klass->io_create_watch = qio_channel_rdma_create_watch;
> +}
> +
> +static const TypeInfo qio_channel_rdma_info = {
> + .parent = TYPE_QIO_CHANNEL,
> + .name = TYPE_QIO_CHANNEL_RDMA,
> + .instance_size = sizeof(QIOChannelRDMA),
> + .instance_finalize = qio_channel_rdma_finalize,
> + .class_init = qio_channel_rdma_class_init,
> +};
> +
> +static void qio_channel_rdma_register_types(void)
> +{
> + type_register_static(&qio_channel_rdma_info);
> +}
> +
> +type_init(qio_channel_rdma_register_types);
> +
> +static QEMUFile *qemu_fopen_rdma(RDMAContext *rdma, const char *mode)
> {
> - QEMUFileRDMA *r;
> + QIOChannelRDMA *rioc;
>
> if (qemu_file_mode_is_not_valid(mode)) {
> return NULL;
> }
>
> - r = g_new0(QEMUFileRDMA, 1);
> - r->rdma = rdma;
> + rioc = QIO_CHANNEL_RDMA(object_new(TYPE_QIO_CHANNEL_RDMA));
> + rioc->rdma = rdma;
>
> if (mode[0] == 'w') {
> - r->file = qemu_fopen_ops(r, &rdma_write_ops);
> - qemu_file_set_hooks(r->file, &rdma_write_hooks);
> + rioc->file = qemu_fopen_channel_output(QIO_CHANNEL(rioc));
> + qemu_file_set_hooks(rioc->file, &rdma_write_hooks);
> } else {
> - r->file = qemu_fopen_ops(r, &rdma_read_ops);
> - qemu_file_set_hooks(r->file, &rdma_read_hooks);
> + rioc->file = qemu_fopen_channel_input(QIO_CHANNEL(rioc));
> + qemu_file_set_hooks(rioc->file, &rdma_read_hooks);
> }
>
> - return r->file;
> + return rioc->file;
> }
>
> static void rdma_accept_incoming_migration(void *opaque)
> --
> 2.5.0
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
next prev parent reply other threads:[~2016-03-10 17:00 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-26 15:10 [Qemu-devel] [PATCH v3 00/27] Convert migration to QIOChannel & support TLS Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 01/27] s390: use FILE instead of QEMUFile for creating text file Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 02/27] migration: remove use of qemu_bufopen from vmstate tests Daniel P. Berrange
2016-03-03 8:43 ` Amit Shah
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 03/27] migration: ensure qemu_fflush() always writes full data amount Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 04/27] migration: split migration hooks out of QEMUFileOps Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 05/27] migration: introduce set_blocking function in QEMUFileOps Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 06/27] migration: force QEMUFile to blocking mode for outgoing migration Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 07/27] migration: introduce a new QEMUFile impl based on QIOChannel Daniel P. Berrange
2016-03-10 14:44 ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 08/27] migration: add helpers for creating QEMUFile from a QIOChannel Daniel P. Berrange
2016-03-10 14:52 ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 09/27] migration: add reporting of errors for outgoing migration Daniel P. Berrange
2016-03-04 9:49 ` Markus Armbruster
2016-03-04 10:49 ` Daniel P. Berrange
2016-03-10 15:13 ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 10/27] migration: convert post-copy to use QIOChannelBuffer Daniel P. Berrange
2016-03-10 15:25 ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 11/27] migration: convert unix socket protocol to use QIOChannel Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 12/27] migration: rename unix.c to socket.c Daniel P. Berrange
2016-03-10 15:35 ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 13/27] migration: convert tcp socket protocol to use QIOChannel Daniel P. Berrange
2016-03-10 15:38 ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 14/27] migration: convert fd " Daniel P. Berrange
2016-03-10 15:46 ` Dr. David Alan Gilbert
2016-03-10 15:56 ` Daniel P. Berrange
2016-03-10 17:27 ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 15/27] migration: convert exec " Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 16/27] migration: convert RDMA to use QIOChannel interface Daniel P. Berrange
2016-03-10 17:00 ` Dr. David Alan Gilbert [this message]
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 17/27] migration: convert savevm to use QIOChannel for writing to files Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 18/27] migration: delete QEMUFile buffer implementation Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 19/27] migration: delete QEMUSizedBuffer struct Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 20/27] migration: delete QEMUFile sockets implementation Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 21/27] migration: delete QEMUFile stdio implementation Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 22/27] migration: move definition of struct QEMUFile back into qemu-file.c Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 23/27] migration: don't use an array for storing migrate parameters Daniel P. Berrange
2016-03-10 17:25 ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 24/27] migration: define 'tls-creds' and 'tls-hostname' migration parameters Daniel P. Berrange
2016-03-10 17:42 ` Dr. David Alan Gilbert
2016-03-10 17:50 ` Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 25/27] migration: add support for encrypting data with TLS Daniel P. Berrange
2016-03-10 18:25 ` Dr. David Alan Gilbert
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 26/27] migration: remove support for non-iovec based write handlers Daniel P. Berrange
2016-02-26 15:10 ` [Qemu-devel] [PATCH v3 27/27] migration: remove qemu_get_fd method from QEMUFile Daniel P. Berrange
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=20160310170019.GI10196@work-vm \
--to=dgilbert@redhat.com \
--cc=amit.shah@redhat.com \
--cc=berrange@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/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.