qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Juan Quintela <quintela@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org,  qemu-block@nongnu.org,
	 "Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	 Stefan Hajnoczi <stefanha@redhat.com>,
	 Hailiang Zhang <zhang.zhanghailiang@huawei.com>,
	 Fam Zheng <fam@euphon.net>,
	Hailiang Zhang <zhanghailiang@xfusion.com>
Subject: Re: [PATCH v2 09/21] migration: introduce a QIOChannel impl for BlockDriverState VMState
Date: Tue, 21 Jun 2022 17:40:19 +0200	[thread overview]
Message-ID: <871qvivxcs.fsf@secure.mitica> (raw)
In-Reply-To: <20220620110205.1357829-10-berrange@redhat.com> ("Daniel P. Berrangé"'s message of "Mon, 20 Jun 2022 12:01:53 +0100")

Daniel P. Berrangé <berrange@redhat.com> wrote:
> 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.
>
> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>

I will maggically charge this to a:

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

O:-)

> ---
>  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..ad52342c10
> --- /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;
> +
> +    if ((rv = bdrv_flush(bioc->bs)) < 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',



  parent reply	other threads:[~2022-06-21 15:42 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 11:01 [PATCH v2 00/21] migration: remove QEMUFileOps concept and assume use of QIOChannel Daniel P. Berrangé
2022-06-20 11:01 ` [PATCH v2 01/21] io: add a QIOChannelNull equivalent to /dev/null Daniel P. Berrangé
2022-06-20 12:44   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 02/21] migration: switch to use QIOChannelNull for dummy channel Daniel P. Berrangé
2022-06-20 12:45   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 03/21] migration: remove unreachble RDMA code in save_hook impl Daniel P. Berrangé
2022-06-20 15:11   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 04/21] migration: rename rate limiting fields in QEMUFile Daniel P. Berrangé
2022-06-20 15:11   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 05/21] migration: rename 'pos' field in QEMUFile to 'bytes_processed' Daniel P. Berrangé
2022-06-20 15:12   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 06/21] migration: rename qemu_ftell to qemu_file_total_transferred Daniel P. Berrangé
2022-06-20 15:13   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 07/21] migration: rename qemu_update_position to qemu_file_credit_transfer Daniel P. Berrangé
2022-06-20 15:14   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 08/21] migration: rename qemu_file_update_transfer to qemu_file_acct_rate_limit Daniel P. Berrangé
2022-06-20 14:36   ` Dr. David Alan Gilbert
2022-06-20 15:15   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 09/21] migration: introduce a QIOChannel impl for BlockDriverState VMState Daniel P. Berrangé
2022-06-20 15:17   ` Juan Quintela
2022-06-21 15:40   ` Juan Quintela [this message]
2022-06-21 15:42     ` Daniel P. Berrangé
2022-06-20 11:01 ` [PATCH v2 10/21] migration: convert savevm to use QIOChannelBlock for VMState Daniel P. Berrangé
2022-06-20 15:19   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 11/21] migration: stop passing 'opaque' parameter to QEMUFile hooks Daniel P. Berrangé
2022-06-20 15:20   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 12/21] migration: hardcode assumption that QEMUFile is backed with QIOChannel Daniel P. Berrangé
2022-06-20 15:21   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 13/21] migration: introduce new constructors for QEMUFile Daniel P. Berrangé
2022-06-20 15:27   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 14/21] migration: remove unused QEMUFileGetFD typedef / qemu_get_fd method Daniel P. Berrangé
2022-06-20 15:28   ` Juan Quintela
2022-06-20 11:01 ` [PATCH v2 15/21] migration: remove the QEMUFileOps 'shut_down' callback Daniel P. Berrangé
2022-06-20 15:36   ` Juan Quintela
2022-06-20 11:02 ` [PATCH v2 16/21] migration: remove the QEMUFileOps 'set_blocking' callback Daniel P. Berrangé
2022-06-20 15:39   ` Juan Quintela
2022-06-20 11:02 ` [PATCH v2 17/21] migration: remove the QEMUFileOps 'close' callback Daniel P. Berrangé
2022-06-20 15:40   ` Juan Quintela
2022-06-20 11:02 ` [PATCH v2 18/21] migration: remove the QEMUFileOps 'get_buffer' callback Daniel P. Berrangé
2022-06-20 15:40   ` Juan Quintela
2022-06-27 12:04   ` Dr. David Alan Gilbert
2022-06-20 11:02 ` [PATCH v2 19/21] migration: remove the QEMUFileOps 'writev_buffer' callback Daniel P. Berrangé
2022-06-20 15:43   ` Juan Quintela
2022-06-20 11:02 ` [PATCH v2 20/21] migration: remove the QEMUFileOps 'get_return_path' callback Daniel P. Berrangé
2022-06-20 15:45   ` Juan Quintela
2022-06-20 11:02 ` [PATCH v2 21/21] migration: remove the QEMUFileOps abstraction Daniel P. Berrangé
2022-06-20 15:47   ` Juan Quintela

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=871qvivxcs.fsf@secure.mitica \
    --to=quintela@redhat.com \
    --cc=berrange@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=fam@euphon.net \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=zhang.zhanghailiang@huawei.com \
    --cc=zhanghailiang@xfusion.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).