qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert (git)" <dgilbert@redhat.com>
To: qemu-devel@nongnu.org, berrange@redhat.com,
	huangy81@chinatelecom.cn, quintela@redhat.com,
	leobras@redhat.com, peterx@redhat.com
Cc: jdenemar@redhat.com
Subject: [PULL 13/33] migration: introduce a QIOChannel impl for BlockDriverState VMState
Date: Thu, 23 Jun 2022 10:27:50 +0100	[thread overview]
Message-ID: <20220623092810.96234-14-dgilbert@redhat.com> (raw)
In-Reply-To: <20220623092810.96234-1-dgilbert@redhat.com>

From: Daniel P. Berrangé <berrange@redhat.com>

Introduce a QIOChannelBlock class that exposes the BlockDriverState
VMState region for I/O.

This is kept in the migration/ directory rather than io/, to avoid
a mutual dependancy between block/ <-> io/ directories. Also the
VMState should only be used by the migration code.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
  dgilbert: Fixed coding style in qio_channel_block_close
---
 migration/channel-block.c | 195 ++++++++++++++++++++++++++++++++++++++
 migration/channel-block.h |  59 ++++++++++++
 migration/meson.build     |   1 +
 3 files changed, 255 insertions(+)
 create mode 100644 migration/channel-block.c
 create mode 100644 migration/channel-block.h

diff --git a/migration/channel-block.c b/migration/channel-block.c
new file mode 100644
index 0000000000..c55c8c93ce
--- /dev/null
+++ b/migration/channel-block.c
@@ -0,0 +1,195 @@
+/*
+ * QEMU I/O channels block driver
+ *
+ * Copyright (c) 2022 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.1 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 "qemu/osdep.h"
+#include "migration/channel-block.h"
+#include "qapi/error.h"
+#include "block/block.h"
+#include "trace.h"
+
+QIOChannelBlock *
+qio_channel_block_new(BlockDriverState *bs)
+{
+    QIOChannelBlock *ioc;
+
+    ioc = QIO_CHANNEL_BLOCK(object_new(TYPE_QIO_CHANNEL_BLOCK));
+
+    bdrv_ref(bs);
+    ioc->bs = bs;
+
+    return ioc;
+}
+
+
+static void
+qio_channel_block_finalize(Object *obj)
+{
+    QIOChannelBlock *ioc = QIO_CHANNEL_BLOCK(obj);
+
+    g_clear_pointer(&ioc->bs, bdrv_unref);
+}
+
+
+static ssize_t
+qio_channel_block_readv(QIOChannel *ioc,
+                        const struct iovec *iov,
+                        size_t niov,
+                        int **fds,
+                        size_t *nfds,
+                        Error **errp)
+{
+    QIOChannelBlock *bioc = QIO_CHANNEL_BLOCK(ioc);
+    QEMUIOVector qiov;
+    int ret;
+
+    qemu_iovec_init_external(&qiov, (struct iovec *)iov, niov);
+    ret = bdrv_readv_vmstate(bioc->bs, &qiov, bioc->offset);
+    if (ret < 0) {
+        return ret;
+    }
+
+    bioc->offset += qiov.size;
+    return qiov.size;
+}
+
+
+static ssize_t
+qio_channel_block_writev(QIOChannel *ioc,
+                         const struct iovec *iov,
+                         size_t niov,
+                         int *fds,
+                         size_t nfds,
+                         int flags,
+                         Error **errp)
+{
+    QIOChannelBlock *bioc = QIO_CHANNEL_BLOCK(ioc);
+    QEMUIOVector qiov;
+    int ret;
+
+    qemu_iovec_init_external(&qiov, (struct iovec *)iov, niov);
+    ret = bdrv_writev_vmstate(bioc->bs, &qiov, bioc->offset);
+    if (ret < 0) {
+        return ret;
+    }
+
+    bioc->offset += qiov.size;
+    return qiov.size;
+}
+
+
+static int
+qio_channel_block_set_blocking(QIOChannel *ioc,
+                               bool enabled,
+                               Error **errp)
+{
+    if (!enabled) {
+        error_setg(errp, "Non-blocking mode not supported for block devices");
+        return -1;
+    }
+    return 0;
+}
+
+
+static off_t
+qio_channel_block_seek(QIOChannel *ioc,
+                       off_t offset,
+                       int whence,
+                       Error **errp)
+{
+    QIOChannelBlock *bioc = QIO_CHANNEL_BLOCK(ioc);
+
+    switch (whence) {
+    case SEEK_SET:
+        bioc->offset = offset;
+        break;
+    case SEEK_CUR:
+        bioc->offset += whence;
+        break;
+    case SEEK_END:
+        error_setg(errp, "Size of VMstate region is unknown");
+        return (off_t)-1;
+    default:
+        g_assert_not_reached();
+    }
+
+    return bioc->offset;
+}
+
+
+static int
+qio_channel_block_close(QIOChannel *ioc,
+                        Error **errp)
+{
+    QIOChannelBlock *bioc = QIO_CHANNEL_BLOCK(ioc);
+    int rv = bdrv_flush(bioc->bs);
+
+    if (rv < 0) {
+        error_setg_errno(errp, -rv,
+                         "Unable to flush VMState");
+        return -1;
+    }
+
+    g_clear_pointer(&bioc->bs, bdrv_unref);
+    bioc->offset = 0;
+
+    return 0;
+}
+
+
+static void
+qio_channel_block_set_aio_fd_handler(QIOChannel *ioc,
+                                     AioContext *ctx,
+                                     IOHandler *io_read,
+                                     IOHandler *io_write,
+                                     void *opaque)
+{
+    /* XXX anything we can do here ? */
+}
+
+
+static void
+qio_channel_block_class_init(ObjectClass *klass,
+                             void *class_data G_GNUC_UNUSED)
+{
+    QIOChannelClass *ioc_klass = QIO_CHANNEL_CLASS(klass);
+
+    ioc_klass->io_writev = qio_channel_block_writev;
+    ioc_klass->io_readv = qio_channel_block_readv;
+    ioc_klass->io_set_blocking = qio_channel_block_set_blocking;
+    ioc_klass->io_seek = qio_channel_block_seek;
+    ioc_klass->io_close = qio_channel_block_close;
+    ioc_klass->io_set_aio_fd_handler = qio_channel_block_set_aio_fd_handler;
+}
+
+static const TypeInfo qio_channel_block_info = {
+    .parent = TYPE_QIO_CHANNEL,
+    .name = TYPE_QIO_CHANNEL_BLOCK,
+    .instance_size = sizeof(QIOChannelBlock),
+    .instance_finalize = qio_channel_block_finalize,
+    .class_init = qio_channel_block_class_init,
+};
+
+static void
+qio_channel_block_register_types(void)
+{
+    type_register_static(&qio_channel_block_info);
+}
+
+type_init(qio_channel_block_register_types);
diff --git a/migration/channel-block.h b/migration/channel-block.h
new file mode 100644
index 0000000000..31673824e6
--- /dev/null
+++ b/migration/channel-block.h
@@ -0,0 +1,59 @@
+/*
+ * QEMU I/O channels block driver
+ *
+ * Copyright (c) 2022 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.1 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_BLOCK_H
+#define QIO_CHANNEL_BLOCK_H
+
+#include "io/channel.h"
+#include "qom/object.h"
+
+#define TYPE_QIO_CHANNEL_BLOCK "qio-channel-block"
+OBJECT_DECLARE_SIMPLE_TYPE(QIOChannelBlock, QIO_CHANNEL_BLOCK)
+
+
+/**
+ * QIOChannelBlock:
+ *
+ * The QIOChannelBlock object provides a channel implementation
+ * that is able to perform I/O on the BlockDriverState objects
+ * to the VMState region.
+ */
+
+struct QIOChannelBlock {
+    QIOChannel parent;
+    BlockDriverState *bs;
+    off_t offset;
+};
+
+
+/**
+ * qio_channel_block_new:
+ * @bs: the block driver state
+ *
+ * Create a new IO channel object that can perform
+ * I/O on a BlockDriverState object to the VMState
+ * region
+ *
+ * Returns: the new channel object
+ */
+QIOChannelBlock *
+qio_channel_block_new(BlockDriverState *bs);
+
+#endif /* QIO_CHANNEL_BLOCK_H */
diff --git a/migration/meson.build b/migration/meson.build
index 6880b61b10..8d309f5849 100644
--- a/migration/meson.build
+++ b/migration/meson.build
@@ -13,6 +13,7 @@ softmmu_ss.add(migration_files)
 softmmu_ss.add(files(
   'block-dirty-bitmap.c',
   'channel.c',
+  'channel-block.c',
   'colo-failover.c',
   'colo.c',
   'exec.c',
-- 
2.36.1



  parent reply	other threads:[~2022-06-23 10:01 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23  9:27 [PULL 00/33] migration queue Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 01/33] migration: Remove RDMA_UNREGISTRATION_EXAMPLE Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 02/33] QIOChannelSocket: Introduce assert and reduce ifdefs to improve readability Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 03/33] QIOChannelSocket: Fix zero-copy send so socket flush works Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 04/33] migration: Change zero_copy_send from migration parameter to migration capability Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 05/33] io: add a QIOChannelNull equivalent to /dev/null Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 06/33] migration: switch to use QIOChannelNull for dummy channel Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 07/33] migration: remove unreachble RDMA code in save_hook impl Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 08/33] migration: rename rate limiting fields in QEMUFile Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 09/33] migration: rename 'pos' field in QEMUFile to 'bytes_processed' Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 10/33] migration: rename qemu_ftell to qemu_file_total_transferred Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 11/33] migration: rename qemu_update_position to qemu_file_credit_transfer Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 12/33] migration: rename qemu_file_update_transfer to qemu_file_acct_rate_limit Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` Dr. David Alan Gilbert (git) [this message]
2022-06-23  9:27 ` [PULL 14/33] migration: convert savevm to use QIOChannelBlock for VMState Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 15/33] migration: stop passing 'opaque' parameter to QEMUFile hooks Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 16/33] migration: hardcode assumption that QEMUFile is backed with QIOChannel Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 17/33] migration: introduce new constructors for QEMUFile Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 18/33] migration: remove unused QEMUFileGetFD typedef / qemu_get_fd method Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 19/33] migration: remove the QEMUFileOps 'shut_down' callback Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 20/33] migration: remove the QEMUFileOps 'set_blocking' callback Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 21/33] migration: remove the QEMUFileOps 'close' callback Dr. David Alan Gilbert (git)
2022-06-23  9:27 ` [PULL 22/33] migration: remove the QEMUFileOps 'get_buffer' callback Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 23/33] migration: remove the QEMUFileOps 'writev_buffer' callback Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 24/33] migration: remove the QEMUFileOps 'get_return_path' callback Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 25/33] migration: remove the QEMUFileOps abstraction Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 26/33] accel/kvm/kvm-all: Refactor per-vcpu dirty ring reaping Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 27/33] cpus: Introduce cpu_list_generation_id Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 28/33] migration/dirtyrate: Refactor dirty page rate calculation Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 29/33] softmmu/dirtylimit: Implement vCPU dirtyrate calculation periodically Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 30/33] accel/kvm/kvm-all: Introduce kvm_dirty_ring_size function Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 31/33] softmmu/dirtylimit: Implement virtual CPU throttle Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 32/33] softmmu/dirtylimit: Implement dirty page rate limit Dr. David Alan Gilbert (git)
2022-06-23  9:28 ` [PULL 33/33] tests: Add dirty page rate limit test Dr. David Alan Gilbert (git)
2022-06-23 14:26 ` [PULL 00/33] migration queue Richard Henderson
2022-06-23 16:37   ` Dr. David Alan Gilbert
  -- strict thread matches above, loose matches on Subject: below --
2022-06-22 18:38 Dr. David Alan Gilbert (git)
2022-06-22 18:38 ` [PULL 13/33] migration: introduce a QIOChannel impl for BlockDriverState VMState Dr. David Alan Gilbert (git)

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=20220623092810.96234-14-dgilbert@redhat.com \
    --to=dgilbert@redhat.com \
    --cc=berrange@redhat.com \
    --cc=huangy81@chinatelecom.cn \
    --cc=jdenemar@redhat.com \
    --cc=leobras@redhat.com \
    --cc=peterx@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).