migration: remove QEMUFileOps concept and assume use of QIOChannel
PATCH 3/20 migration: remove unreachble RDMA code in save_hook impl
In reply to Daniel P. BerrangéThe QEMUFile 'save_hook' callback has a 'size_t size' parameter.
The RDMA impl of this has logic that takes different actions depending on whether the value is zero or non-zero. It has commented out logic that would have taken further actions if the value was negative.
The only place where the 'save_hook' callback is invoked is the ram_control_save_page() method, which passes 'size' through from its caller. The only caller of this method is in turn control_save_page(). This method unconditionally passes the 'TARGET_PAGE_SIZE' constant for the 'size' parameter.
IOW, the only scenario for 'size' that can execute in the qemu_rdma_save_page method is 'size > 0'. The remaining code has been unreachable since RDMA support was first introduced 9 years ago.
--- migration/rdma.c | 120 +++++++++-------------------------------------- 1 file changed, 21 insertions(+), 99 deletions(-)
migration/rdma.c +21 -99
@@ -1486,34 +1486,6 @@ static uint64_t qemu_rdma_make_wrid(uint64_t wr_id, uint64_t index,return result; } -/* -* Set bit for unregistration in the next iteration. -* We cannot transmit right here, but will unpin later. -*/ -static void qemu_rdma_signal_unregister (RDMAContext *rdma,uint64_t index, -uint64_t chunk,uint64_t wr_id) -{ -if (rdma->unregistrations[rdma->unregister_next] !=0 ) { -error_report ("rdma migration: queue is full" ); - }else { -RDMALocalBlock *block = &(rdma->local_ram_blocks.block[index]); - -if (!test_and_set_bit (chunk, block->unregister_bitmap)) { -trace_qemu_rdma_signal_unregister_append (chunk, - rdma->unregister_next); - - rdma->unregistrations[rdma->unregister_next++] = -qemu_rdma_make_wrid (wr_id, index, chunk); - -if (rdma->unregister_next ==RDMA_SIGNALED_SEND_MAX ) { - rdma->unregister_next =0 ; - } - }else { -trace_qemu_rdma_signal_unregister_already (chunk); - } - } -} -/* * Consult the connection manager to see a work request * (of any kind) has completed.
@@ -3278,23 +3250,7 @@ qio_channel_rdma_shutdown(QIOChannel *ioc,* Offset is an offset to be added to block_offset and used * to also lookup the corresponding RAMBlock. * -* @size > 0 : -* Initiate an transfer this size. -* -* @size == 0 : -* A 'hint' or 'advice' that means that we wish to speculatively -* and asynchronously unregister this memory. In this case, there is no -* guarantee that the unregister will actually happen, for example, -* if the memory is being actively transmitted. Additionally, the memory -* may be re-registered at any future time if a write within the same -* chunk was requested again, even if you attempted to unregister it -* here. -* -* @size < 0 : TODO, not yet supported -* Unregister the memory NOW. This means that the caller does not -* expect there to be any future RDMA transfers and we just want to clean -* things up. This is used in case the upper layer owns the memory and -* cannot wait for qemu_fclose() to occur. +* @size : Number of bytes to transfer * * @bytes_sent : User-specificed pointer to indicate how many bytes were * sent. Usually, this will not be more than a few bytes of
@@ -3323,61 +3279,27 @@ static size_t qemu_rdma_save_page(QEMUFile *f, void *opaque,qemu_fflush (f); -if (size >0 ) { -/* -* Add this page to the current 'chunk'. If the chunk -* is full, or the page doesn't belong to the current chunk, -* an actual RDMA write will occur and a new chunk will be formed. -*/ - ret =qemu_rdma_write (f, rdma, block_offset, offset, size); -if (ret <0 ) { -error_report ("rdma migration: write error! %d" , ret); - goto err; - } - -/* -* We always return 1 bytes because the RDMA -* protocol is completely asynchronous. We do not yet know -* whether an identified chunk is zero or not because we're -* waiting for other pages to potentially be merged with -* the current chunk. So, we have to call qemu_update_position() -* later on when the actual write occurs. -*/ -if (bytes_sent) { - *bytes_sent =1 ; - } - }else { -uint64_t index, chunk; - -/* TODO: Change QEMUFileOps prototype to be signed: size_t => long -if (size < 0) { -ret = qemu_rdma_drain_cq(f, rdma); -if (ret < 0) { -fprintf(stderr, "rdma: failed to synchronously drain" -" completion queue before unregistration.\n"); -goto err; -} -} -*/ - - ret =qemu_rdma_search_ram_block (rdma, block_offset, - offset, size, &index, &chunk); - -if (ret) { -error_report ("ram block search failed" ); - goto err; - } - -qemu_rdma_signal_unregister (rdma, index, chunk,0 ); +/* +* Add this page to the current 'chunk'. If the chunk +* is full, or the page doesn't belong to the current chunk, +* an actual RDMA write will occur and a new chunk will be formed. +*/ + ret =qemu_rdma_write (f, rdma, block_offset, offset, size); +if (ret <0 ) { +error_report ("rdma migration: write error! %d" , ret); + goto err; + } -/* -* TODO: Synchronous, guaranteed unregistration (should not occur during -* fast-path). Otherwise, unregisters will process on the next call to -* qemu_rdma_drain_cq() -if (size < 0) { -qemu_rdma_unregister_waiting(rdma); -} -*/ +/* +* We always return 1 bytes because the RDMA +* protocol is completely asynchronous. We do not yet know +* whether an identified chunk is zero or not because we're +* waiting for other pages to potentially be merged with +* the current chunk. So, we have to call qemu_update_position() +* later on when the actual write occurs. +*/ +if (bytes_sent) { + *bytes_sent =1 ; }/*
Signature · 1 line
2.36.1
PATCH 12/20 migration: introduce new constructors for QEMUFile
In reply to Daniel P. BerrangéPrepare for the elimination of QEMUFileOps by introducing a pair of new constructors. This lets us distinguish between an input and output file object explicitly rather than via the existance of specific callbacks.
--- migration/qemu-file-channel.c | 4 ++-- migration/qemu-file.c | 18 ++++++++++++++++-- migration/qemu-file.h | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-)
migration/qemu-file-channel.c +2 -2
@@ -184,11 +184,11 @@ static const QEMUFileOps channel_output_ops = {QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc) {object_ref (OBJECT (ioc)); -return qemu_fopen_ops (ioc, &channel_input_ops); +return qemu_file_new_input (ioc, &channel_input_ops); }QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc) {object_ref (OBJECT (ioc)); -return qemu_fopen_ops (ioc, &channel_output_ops); +return qemu_file_new_output (ioc, &channel_output_ops); }
migration/qemu-file.c +16 -2
@@ -38,6 +38,7 @@ struct QEMUFile {const QEMUFileOps *ops;const QEMUFileHooks *hooks;QIOChannel *ioc; +bool is_writable;/* * Maximum amount of data in bytes to transfer during one
@@ -111,7 +112,9 @@ bool qemu_file_mode_is_not_valid(const char *mode)return false; } -QEMUFile *qemu_fopen_ops (QIOChannel *ioc,const QEMUFileOps *ops) +static QEMUFile *qemu_file_new_impl (QIOChannel *ioc, +const QEMUFileOps *ops, +bool is_writable) {QEMUFile *f;
@@ -119,10 +122,21 @@ QEMUFile *qemu_fopen_ops(QIOChannel *ioc, const QEMUFileOps *ops) f->ioc = ioc; f->ops = ops; + f->is_writable = is_writable;return f; } +QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops) +{ +return qemu_file_new_impl (ioc, ops, true); +} + +QEMUFile *qemu_file_new_input (QIOChannel *ioc,const QEMUFileOps *ops) +{ +return qemu_file_new_impl (ioc, ops, false); +} +void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks) {
@@ -181,7 +195,7 @@ void qemu_file_set_error(QEMUFile *f, int ret)bool qemu_file_is_writable (QEMUFile *f) { -return f->ops->writev_buffer; +return f->is_writable; }static void qemu_iovec_release_ram (QEMUFile *f)
migration/qemu-file.h +2 -1
@@ -118,7 +118,8 @@ typedef struct QEMUFileHooks {QEMURamSaveFunc *save_page; } QEMUFileHooks; -QEMUFile *qemu_fopen_ops (QIOChannel *ioc,const QEMUFileOps *ops); +QEMUFile *qemu_file_new_input (QIOChannel *ioc,const QEMUFileOps *ops); +QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks);int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);
Signature · 1 line
2.36.1
PATCH 6/20 migration: rename qemu_ftell to qemu_file_total_transferred
In reply to Daniel P. BerrangéThe name 'ftell' gives the misleading impression that the QEMUFile objects are seekable. This is not the case, as in general we just have an opaque stream. The users of this method are only interested in the total bytes processed. This switches to a new name that reflects the intended usage.
--- migration/block.c | 10 +++++----- migration/migration.c | 2 +- migration/qemu-file.c | 4 ++-- migration/qemu-file.h | 40 ++++++++++++++++++++++++++++++++++++++-- migration/savevm.c | 6 +++--- migration/vmstate.c | 4 ++-- 6 files changed, 51 insertions(+), 15 deletions(-)
migration/block.c +5 -5
@@ -756,8 +756,8 @@ static int block_save_setup(QEMUFile *f, void *opaque)static int block_save_iterate (QEMUFile *f,void *opaque) {int ret; -int64_t last_ftell =qemu_ftell (f); -int64_t delta_ftell; +int64_t last_bytes =qemu_file_total_transferred (f); +int64_t delta_bytes;trace_migration_block_save ("iterate" , block_mig_state.submitted, block_mig_state.transferred);
@@ -809,10 +809,10 @@ static int block_save_iterate(QEMUFile *f, void *opaque) }qemu_put_be64 (f,BLK_MIG_FLAG_EOS ); - delta_ftell =qemu_ftell (f) - last_ftell; -if (delta_ftell >0 ) { + delta_bytes =qemu_file_total_transferred (f) - last_bytes; +if (delta_bytes >0 ) {return 1 ; - }else if (delta_ftell <0 ) { + }else if (delta_bytes <0 ) {return -1 ; }else {return 0 ;
migration/migration.c +1 -1
@@ -3544,7 +3544,7 @@ static MigThrError migration_detect_error(MigrationState *s)/* How many bytes have we transferred since the beginning of the migration */ static uint64_t migration_total_bytes (MigrationState *s) { -return qemu_ftell (s->to_dst_file) + ram_counters.multifd_bytes; +return qemu_file_total_transferred (s->to_dst_file) + ram_counters.multifd_bytes; }static void migration_calculate_complete (MigrationState *s)
migration/qemu-file.c +2 -2
@@ -657,7 +657,7 @@ int qemu_get_byte(QEMUFile *f)return result; } -int64_t qemu_ftell_fast (QEMUFile *f) +int64_t qemu_file_total_transferred_fast (QEMUFile *f) {int64_t ret = f->total_transferred;int i;
@@ -669,7 +669,7 @@ int64_t qemu_ftell_fast(QEMUFile *f)return ret; } -int64_t qemu_ftell (QEMUFile *f) +int64_t qemu_file_total_transferred (QEMUFile *f) {qemu_fflush (f);return f->total_transferred;
migration/qemu-file.h +38 -2
@@ -124,8 +124,44 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks);int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f); -int64_t qemu_ftell (QEMUFile *f); -int64_t qemu_ftell_fast (QEMUFile *f); + +/* +* qemu_file_total_transferred: +* +* Report the total number of bytes transferred with +* this file. +* +* For writable files, any pending buffers will be +* flushed, so the reported value will be equal to +* the number of bytes transferred on the wire. +* +* For readable files, the reported value will be +* equal to the number of bytes transferred on the +* wire. +* +* Returns: the total bytes transferred +*/ +int64_t qemu_file_total_transferred (QEMUFile *f); + +/* +* qemu_file_total_transferred_fast: +* +* Report the total number of bytes transferred with +* this file. +* +* For writable files, no pending buffers will be +* flushed, but the reported value will include the +* size of any queued buffers, on top of the amount +* actually transferred. +* +* For readable files, the reported value will be +* equal to the number of bytes transferred on the +* wire. +* +* Returns: the total bytes transferred and queued +*/ +int64_t qemu_file_total_transferred_fast (QEMUFile *f); +/* * put_buffer without copying the buffer. * The buffer should be available till it is sent asynchronously.
migration/savevm.c +3 -3
@@ -916,9 +916,9 @@ static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, {int64_t old_offset, size; - old_offset =qemu_ftell_fast (f); + old_offset =qemu_file_total_transferred_fast (f); se->ops->save_state (f, se->opaque); - size =qemu_ftell_fast (f) - old_offset; + size =qemu_file_total_transferred_fast (f) - old_offset;if (vmdesc) {json_writer_int64 (vmdesc,"size" , size);
@@ -2887,7 +2887,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate, goto the_end; } ret =qemu_savevm_state (f, errp); - vm_state_size =qemu_ftell (f); + vm_state_size =qemu_file_total_transferred (f); ret2 =qemu_fclose (f);if (ret <0 ) { goto the_end;
migration/vmstate.c +2 -2
@@ -360,7 +360,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,void *curr_elem = first_elem + size * i;vmsd_desc_field_start (vmsd, vmdesc_loop, field, i, n_elems); - old_offset =qemu_ftell_fast (f); + old_offset =qemu_file_total_transferred_fast (f);if (field->flags &VMS_ARRAY_OF_POINTER ) {assert (curr_elem); curr_elem = *(void **)curr_elem;
@@ -390,7 +390,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,return ret; } - written_bytes =qemu_ftell_fast (f) - old_offset; + written_bytes =qemu_file_total_transferred_fast (f) - old_offset;vmsd_desc_field_end (vmsd, vmdesc_loop, field, written_bytes, i);/* Compressed arrays only care about the first element */
Signature · 1 line
2.36.1
PATCH 2/20 migration: switch to use QIOChannelNull for dummy channel
In reply to Daniel P. BerrangéThis removes one further custom impl of QEMUFile, in favour of a QIOChannel based impl.
--- migration/ram.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
migration/ram.c +4 -3
@@ -32,11 +32,13 @@#include "qemu/bitmap.h" #include "qemu/madvise.h" #include "qemu/main-loop.h" +#include "io/channel-null.h" #include "xbzrle.h" #include "ram.h" #include "migration.h" #include "migration/register.h" #include "migration/misc.h" +#include "migration/qemu-file-channel.h" #include "qemu-file.h" #include "postcopy-ram.h" #include "page_cache.h"
@@ -457,8 +459,6 @@ static QemuThread *compress_threads;*/ static QemuMutex comp_done_lock;static QemuCond comp_done_cond; -/* The empty QEMUFileOps will be used by file in CompressParam */ -static const QEMUFileOps empty_ops = { };static QEMUFile *decomp_file;static DecompressParam *decomp_param;
@@ -569,7 +569,8 @@ static int compress_threads_save_setup(void)/* comp_param[i].file is just used as a dummy buffer to save data, * set its ops to empty. */ - comp_param[i].file =qemu_fopen_ops (NULL , &empty_ops, false); + comp_param[i].file =qemu_fopen_channel_output ( +QIO_CHANNEL (qio_channel_null_new ())); comp_param[i].done = true; comp_param[i].quit = false;qemu_mutex_init (&comp_param[i].mutex);
Signature · 1 line
2.36.1
PATCH 15/20 migration: remove the QEMUFileOps 'set_blocking' callback
In reply to Daniel P. BerrangéThis directly implements the set_blocking logic using QIOChannel APIs.
--- migration/qemu-file-channel.c | 14 -------------- migration/qemu-file.c | 4 +--- migration/qemu-file.h | 5 ----- 3 files changed, 1 insertion(+), 22 deletions(-)
migration/qemu-file-channel.c +0 -14
@@ -112,18 +112,6 @@ static int channel_close(void *opaque, Error **errp) } -static int channel_set_blocking (void *opaque, -bool enabled, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); - -if (qio_channel_set_blocking (ioc, enabled, errp) <0 ) { -return -1 ; - } -return 0 ; -} -static QEMUFile *channel_get_input_return_path (void *opaque) {QIOChannel *ioc =QIO_CHANNEL (opaque);
@@ -141,7 +129,6 @@ static QEMUFile *channel_get_output_return_path(void *opaque)static const QEMUFileOps channel_input_ops = { .get_buffer = channel_get_buffer, .close = channel_close, - .set_blocking = channel_set_blocking, .get_return_path = channel_get_input_return_path, };
@@ -149,7 +136,6 @@ static const QEMUFileOps channel_input_ops = {static const QEMUFileOps channel_output_ops = { .writev_buffer = channel_writev_buffer, .close = channel_close, - .set_blocking = channel_set_blocking, .get_return_path = channel_get_output_return_path, };
migration/qemu-file.c +1 -3
@@ -876,9 +876,7 @@ void qemu_put_counted_string(QEMUFile *f, const char *str)*/ void qemu_file_set_blocking (QEMUFile *f,bool block) { -if (f->ops->set_blocking) { - f->ops->set_blocking (f->ioc, block,NULL ); - } +qio_channel_set_blocking (f->ioc, block,NULL ); }/*
migration/qemu-file.h +0 -5
@@ -46,10 +46,6 @@ typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,*/ typedef int (QEMUFileCloseFunc )(void *opaque,Error **errp); -/* Called to change the blocking mode of the file -*/ -typedef int (QEMUFileSetBlocking )(void *opaque,bool enabled,Error **errp); -/* * This function writes an iovec to file. The handler must write all * of the data or return a negative errno value.
@@ -92,7 +88,6 @@ typedef QEMUFile *(QEMURetPathFunc)(void *opaque);typedef struct QEMUFileOps {QEMUFileGetBufferFunc *get_buffer;QEMUFileCloseFunc *close; -QEMUFileSetBlocking *set_blocking;QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path; }QEMUFileOps ;
Signature · 1 line
2.36.1
PATCH 1/20 io: add a QIOChannelNull equivalent to /dev/null
In reply to Daniel P. BerrangéThis is for code which needs a portable equivalent to a QIOChannelFile connected to /dev/null.
--- include/io/channel-null.h | 55 +++++++ io/channel-null.c | 237 ++++++++++++++++++++++++++++++ io/meson.build | 1 + io/trace-events | 3 + tests/unit/meson.build | 1 + tests/unit/test-io-channel-null.c | 95 ++++++++++++ 6 files changed, 392 insertions(+) create mode 100644 include/io/channel-null.h create mode 100644 io/channel-null.c create mode 100644 tests/unit/test-io-channel-null.c
include/io/channel-null.h new file +55 -0
@@ -0,0 +1,55 @@ +/* +* QEMU I/O channels null 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_FILE_H +#define QIO_CHANNEL_FILE_H + +#include "io/channel.h" +#include "qom/object.h" + +#define TYPE_QIO_CHANNEL_NULL "qio-channel-null" +OBJECT_DECLARE_SIMPLE_TYPE (QIOChannelNull,QIO_CHANNEL_NULL ) + + +/** +* QIOChannelNull: +* +* The QIOChannelNull object provides a channel implementation +* that discards all writes and returns zero bytes for all reads. + */ + +struct QIOChannelNull { +QIOChannel parent; +bool closed; +}; + + +/** +* qio_channel_null_new: +* +* Create a new IO channel object that discards all writes +* and returns zero bytes for all reads. +* +* Returns: the new channel object +*/ +QIOChannelNull * +qio_channel_null_new (void ); + +#endif /* QIO_CHANNEL_NULL_H */
io/channel-null.c new file +237 -0
237 lines not on this page · raw message
io/meson.build +1 -0
@@ -3,6 +3,7 @@ io_ss.add(files( 'channel-buffer.c', 'channel-command.c', 'channel-file.c', + 'channel-null.c', 'channel-socket.c', 'channel-tls.c', 'channel-util.c',
io/trace-events +3 -0
@@ -10,6 +10,9 @@ qio_task_thread_result(void *task) "Task thread result task=%p" qio_task_thread_source_attach(void *task, void *source) "Task thread source attach task=%p source=%p" qio_task_thread_source_cancel(void *task, void *source) "Task thread source cancel task=%p source=%p" +# channel-null.c +qio_channel_null_new(void *ioc) "Null new ioc=%p" + # 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"
tests/unit/meson.build +1 -0
@@ -86,6 +86,7 @@ if have_block 'test-io-channel-file': ['io-channel-helpers.c', io], 'test-io-channel-command': ['io-channel-helpers.c', io], 'test-io-channel-buffer': ['io-channel-helpers.c', io], + 'test-io-channel-null': [io], 'test-crypto-ivgen': [io], 'test-crypto-afsplit': [io], 'test-crypto-block': [io],
tests/unit/test-io-channel-null.c new file +95 -0
95 lines not on this page · raw message
Signature · 1 line
2.36.1
PATCH 5/20 migration: rename 'pos' field in QEMUFile to 'bytes_processed'
In reply to Daniel P. BerrangéThis makes the field name align with the newly introduced method names in the previous commit.
--- migration/qemu-file.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)
migration/qemu-file.c +10 -9
@@ -50,8 +50,9 @@ struct QEMUFile {*/ int64_t rate_limit_used; -int64_t pos;/* start of buffer when writing, end of buffer -when reading */ +/* The sum of bytes transferred on the wire */ +int64_t total_transferred; +int buf_index;int buf_size;/* 0 when writing */ uint8_t buf[IO_BUF_SIZE ];
@@ -241,14 +242,14 @@ void qemu_fflush(QEMUFile *f) }if (f->iovcnt >0 ) { expect =iov_size (f->iov, f->iovcnt); - ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->pos, + ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->total_transferred, &local_error);qemu_iovec_release_ram (f); }if (ret >=0 ) { - f->pos += ret; + f->total_transferred += ret; }/* We expect the QEMUFile write impl to send the full * data set we requested, so sanity check that.
@@ -357,11 +358,11 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return 0 ; } - len = f->ops->get_buffer (f->opaque, f->buf + pending, f->pos, + len = f->ops->get_buffer (f->opaque, f->buf + pending, f->total_transferred,IO_BUF_SIZE - pending, &local_error);if (len >0 ) { f->buf_size += len; - f->pos += len; + f->total_transferred += len; }else if (len ==0 ) {qemu_file_set_error_obj (f, -EIO , local_error); }else if (len != -EAGAIN ) {
@@ -375,7 +376,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)void qemu_update_position (QEMUFile *f,size_t size) { - f->pos += size; + f->total_transferred += size; }/** Closes the file
@@ -658,7 +659,7 @@ int qemu_get_byte(QEMUFile *f)int64_t qemu_ftell_fast (QEMUFile *f) { -int64_t ret = f->pos; +int64_t ret = f->total_transferred;int i;for (i =0 ; i < f->iovcnt; i++) {
@@ -671,7 +672,7 @@ int64_t qemu_ftell_fast(QEMUFile *f)int64_t qemu_ftell (QEMUFile *f) {qemu_fflush (f); -return f->pos; +return f->total_transferred; }int qemu_file_rate_limit (QEMUFile *f)
Signature · 1 line
2.36.1
PATCH 17/20 migration: remove the QEMUFileOps 'get_buffer' callback
In reply to Daniel P. BerrangéThis directly implements the get_buffer logic using QIOChannel APIs.
--- migration/qemu-file-channel.c | 29 ----------------------------- migration/qemu-file.c | 18 ++++++++++++++++-- migration/qemu-file.h | 9 --------- 3 files changed, 16 insertions(+), 40 deletions(-)
migration/qemu-file-channel.c +0 -29
@@ -74,34 +74,6 @@ static ssize_t channel_writev_buffer(void *opaque, } -static ssize_t channel_get_buffer (void *opaque, -uint8_t *buf, -int64_t pos, -size_t size, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); -ssize_t ret; - -do { - ret =qio_channel_read (ioc, (char *)buf, size, errp); -if (ret <0 ) { -if (ret ==QIO_CHANNEL_ERR_BLOCK ) { -if (qemu_in_coroutine ()) { -qio_channel_yield (ioc,G_IO_IN ); - }else { -qio_channel_wait (ioc,G_IO_IN ); - } - }else { -return -EIO ; - } - } - }while (ret ==QIO_CHANNEL_ERR_BLOCK ); - -return ret; -} - -static QEMUFile *channel_get_input_return_path (void *opaque) {QIOChannel *ioc =QIO_CHANNEL (opaque);
@@ -117,7 +89,6 @@ static QEMUFile *channel_get_output_return_path(void *opaque) }static const QEMUFileOps channel_input_ops = { - .get_buffer = channel_get_buffer, .get_return_path = channel_get_input_return_path, };
migration/qemu-file.c +16 -2
@@ -374,8 +374,22 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return 0 ; } - len = f->ops->get_buffer (f->ioc, f->buf + pending, f->total_transferred, -IO_BUF_SIZE - pending, &local_error); +do { + len =qio_channel_read (f->ioc, + (char *)f->buf + pending, +IO_BUF_SIZE - pending, + &local_error); +if (len ==QIO_CHANNEL_ERR_BLOCK ) { +if (qemu_in_coroutine ()) { +qio_channel_yield (f->ioc,G_IO_IN ); + }else { +qio_channel_wait (f->ioc,G_IO_IN ); + } + }else if (len <0 ) { + len =EIO ; + } + }while (len ==QIO_CHANNEL_ERR_BLOCK ); +if (len >0 ) { f->buf_size += len; f->total_transferred += len;
migration/qemu-file.h +0 -9
@@ -29,14 +29,6 @@#include "exec/cpu-common.h" #include "io/channel.h" -/* Read a chunk of data from a file at the given position. The pos argument -* can be ignored if the file is only be used for streaming. The number of -* bytes actually read should be returned. -*/ -typedef ssize_t (QEMUFileGetBufferFunc )(void *opaque,uint8_t *buf, -int64_t pos,size_t size, -Error **errp); -/* * This function writes an iovec to file. The handler must write all * of the data or return a negative errno value.
@@ -77,7 +69,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,typedef QEMUFile *(QEMURetPathFunc )(void *opaque);typedef struct QEMUFileOps { -QEMUFileGetBufferFunc *get_buffer;QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path; }QEMUFileOps ;
Signature · 1 line
2.36.1
PATCH 7/20 migration: rename qemu_update_position to qemu_file_credit_transfer
In reply to Daniel P. BerrangéThe qemu_update_position method name gives the misleading impression that it is changing the current file offset. Most of the files are just streams, however, so there's no concept of a file offset in the general case.
What this method is actually used for is to report on the number of bytes that have been transferred out of band from the main I/O methods. This new name better reflects this purpose.
--- migration/qemu-file.c | 4 ++-- migration/qemu-file.h | 8 +++++++- migration/ram.c | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-)
migration/qemu-file.c +2 -2
@@ -319,7 +319,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,if (ret !=RAM_SAVE_CONTROL_DELAYED && ret !=RAM_SAVE_CONTROL_NOT_SUPP ) {if (bytes_sent && *bytes_sent >0 ) { -qemu_update_position (f, *bytes_sent); +qemu_file_credit_transfer (f, *bytes_sent); }else if (ret <0 ) {qemu_file_set_error (f, ret); }
@@ -374,7 +374,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return len; } -void qemu_update_position (QEMUFile *f,size_t size) +void qemu_file_credit_transfer (QEMUFile *f,size_t size) { f->total_transferred += size; }
migration/qemu-file.h +7 -1
@@ -186,7 +186,13 @@ int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src);*/ int qemu_peek_byte (QEMUFile *f,int offset);void qemu_file_skip (QEMUFile *f,int size); -void qemu_update_position (QEMUFile *f,size_t size); +/* +* qemu_file_credit_transfer: +* +* Report on a number of bytes that have been transferred +* out of band from the main file object I/O methods. +*/ +void qemu_file_credit_transfer (QEMUFile *f,size_t size);void qemu_file_reset_rate_limit (QEMUFile *f);void qemu_file_update_transfer (QEMUFile *f,int64_t len);void qemu_file_set_rate_limit (QEMUFile *f,int64_t new_rate);
migration/ram.c +1 -1
@@ -2301,7 +2301,7 @@ void acct_update_position(QEMUFile *f, size_t size, bool zero) }else { ram_counters.normal += pages;ram_transferred_add (size); -qemu_update_position (f, size); +qemu_file_credit_transfer (f, size); } }
Signature · 1 line
2.36.1
PATCH 4/20 migration: rename rate limiting fields in QEMUFile
In reply to Daniel P. BerrangéThis renames the following QEMUFile fields
* bytes_xfer -> rate_limit_used
* xfer_limit -> rate_limit_max
The intent is to make it clear that 'bytes_xfer' is specifically related to rate limiting of data and applies to data queued, which need not have been transferred on the wire yet if a flush hasn't taken place.
--- migration/qemu-file.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)
migration/qemu-file.c +19 -11
@@ -39,8 +39,16 @@ struct QEMUFile {const QEMUFileHooks *hooks;void *opaque; -int64_t bytes_xfer; -int64_t xfer_limit; +/* +* Maximum amount of data in bytes to transfer during one +* rate limiting time window +*/ +int64_t rate_limit_max; +/* +* Total amount of data in bytes queued for transfer +* during this rate limiting time window +*/ +int64_t rate_limit_used;int64_t pos;/* start of buffer when writing, end of buffer when reading */
@@ -304,7 +312,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,int ret = f->hooks->save_page (f, f->opaque, block_offset, offset, size, bytes_sent);if (ret !=RAM_SAVE_CONTROL_NOT_SUPP ) { - f->bytes_xfer += size; + f->rate_limit_used += size; } if (ret != RAM_SAVE_CONTROL_DELAYED &&
@@ -457,7 +465,7 @@ void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size,return ; } - f->bytes_xfer += size; + f->rate_limit_used += size;add_to_iovec (f, buf, size, may_free); }
@@ -475,7 +483,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size) l = size; }memcpy (f->buf + f->buf_index, buf, l); - f->bytes_xfer += l; + f->rate_limit_used += l;add_buf_to_iovec (f, l);if (qemu_file_get_error (f)) {break ;
@@ -492,7 +500,7 @@ void qemu_put_byte(QEMUFile *f, int v) } f->buf[f->buf_index] = v; - f->bytes_xfer++; + f->rate_limit_used++;add_buf_to_iovec (f,1 ); }
@@ -674,7 +682,7 @@ int qemu_file_rate_limit(QEMUFile *f)if (qemu_file_get_error (f)) {return 1 ; } -if (f->xfer_limit >0 && f->bytes_xfer > f->xfer_limit) { +if (f->rate_limit_max >0 && f->rate_limit_used > f->rate_limit_max) {return 1 ; }return 0 ;
@@ -682,22 +690,22 @@ int qemu_file_rate_limit(QEMUFile *f)int64_t qemu_file_get_rate_limit (QEMUFile *f) { -return f->xfer_limit; +return f->rate_limit_max; }void qemu_file_set_rate_limit (QEMUFile *f,int64_t limit) { - f->xfer_limit = limit; + f->rate_limit_max = limit; }void qemu_file_reset_rate_limit (QEMUFile *f) { - f->bytes_xfer =0 ; + f->rate_limit_used =0 ; }void qemu_file_update_transfer (QEMUFile *f,int64_t len) { - f->bytes_xfer += len; + f->rate_limit_used += len; }void qemu_put_be16 (QEMUFile *f,unsigned int v)
Signature · 1 line
2.36.1
PATCH 19/20 migration: remove the QEMUFileOps 'get_return_path' callback
In reply to Daniel P. BerrangéThis directly implements the get_return_path logic using QIOChannel APIs.
--- migration/qemu-file-channel.c | 16 ---------------- migration/qemu-file.c | 22 ++++++++++------------ migration/qemu-file.h | 6 ------ 3 files changed, 10 insertions(+), 34 deletions(-)
migration/qemu-file-channel.c +0 -16
@@ -32,27 +32,11 @@#include "yank_functions.h" -static QEMUFile *channel_get_input_return_path (void *opaque) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); - -return qemu_fopen_channel_output (ioc); -} - -static QEMUFile *channel_get_output_return_path (void *opaque) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); - -return qemu_fopen_channel_input (ioc); -} -static const QEMUFileOps channel_input_ops = { - .get_return_path = channel_get_input_return_path, };static const QEMUFileOps channel_output_ops = { - .get_return_path = channel_get_output_return_path, };
migration/qemu-file.c +10 -12
@@ -92,18 +92,6 @@ int qemu_file_shutdown(QEMUFile *f)return ret; } -/* -* Result: QEMUFile* for a 'return path' for comms in the opposite direction -* NULL if not available -*/ -QEMUFile *qemu_file_get_return_path (QEMUFile *f) -{ -if (!f->ops->get_return_path) { -return NULL ; - } -return f->ops->get_return_path (f->ioc); -} -bool qemu_file_mode_is_not_valid (const char *mode) { if (mode == NULL ||
@@ -131,6 +119,16 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc,return f; } +/* +* Result: QEMUFile* for a 'return path' for comms in the opposite direction +* NULL if not available +*/ +QEMUFile *qemu_file_get_return_path (QEMUFile *f) +{ +object_ref (f->ioc); +return qemu_file_new_impl (f->ioc, f->ops, !f->is_writable); +} +QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops) {return qemu_file_new_impl (ioc, ops, true);
migration/qemu-file.h +0 -6
@@ -55,13 +55,7 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,size_t size, uint64_t *bytes_sent); -/* -* Return a QEMUFile for comms in the opposite direction -*/ -typedef QEMUFile *(QEMURetPathFunc )(void *opaque); -typedef struct QEMUFileOps { -QEMURetPathFunc *get_return_path; }QEMUFileOps ; typedef struct QEMUFileHooks {
Signature · 1 line
2.36.1
PATCH 10/20 migration: stop passing 'opaque' parameter to QEMUFile hooks
In reply to Daniel P. BerrangéThe only user of the hooks is RDMA which provides a QIOChannel backed impl of QEMUFile. It can thus use the qemu_file_get_ioc() method.
--- migration/qemu-file.c | 8 ++++---- migration/qemu-file.h | 14 ++++++-------- migration/rdma.c | 19 ++++++++++--------- 3 files changed, 20 insertions(+), 21 deletions(-)
migration/qemu-file.c +4 -4
@@ -266,7 +266,7 @@ void ram_control_before_iterate(QEMUFile *f, uint64_t flags)int ret =0 ;if (f->hooks && f->hooks->before_ram_iterate) { - ret = f->hooks->before_ram_iterate (f, f->opaque, flags,NULL ); + ret = f->hooks->before_ram_iterate (f, flags,NULL );if (ret <0 ) {qemu_file_set_error (f, ret); }
@@ -278,7 +278,7 @@ void ram_control_after_iterate(QEMUFile *f, uint64_t flags)int ret =0 ;if (f->hooks && f->hooks->after_ram_iterate) { - ret = f->hooks->after_ram_iterate (f, f->opaque, flags,NULL ); + ret = f->hooks->after_ram_iterate (f, flags,NULL );if (ret <0 ) {qemu_file_set_error (f, ret); }
@@ -290,7 +290,7 @@ void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data)int ret = -EINVAL ;if (f->hooks && f->hooks->hook_ram_load) { - ret = f->hooks->hook_ram_load (f, f->opaque, flags, data); + ret = f->hooks->hook_ram_load (f, flags, data);if (ret <0 ) {qemu_file_set_error (f, ret); }
@@ -310,7 +310,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, uint64_t *bytes_sent) {if (f->hooks && f->hooks->save_page) { -int ret = f->hooks->save_page (f, f->opaque, block_offset, +int ret = f->hooks->save_page (f, block_offset, offset, size, bytes_sent);if (ret !=RAM_SAVE_CONTROL_NOT_SUPP ) { f->rate_limit_used += size;
migration/qemu-file.h +6 -8
@@ -65,11 +65,9 @@ typedef ssize_t (QEMUFileWritevBufferFunc)(void *opaque, struct iovec *iov,/* * This function provides hooks around different * stages of RAM migration. -* 'opaque' is the backend specific data in QEMUFile * 'data' is call specific data associated with the 'flags' value */ -typedef int (QEMURamHookFunc )(QEMUFile *f,void *opaque,uint64_t flags, -void *data); +typedef int (QEMURamHookFunc )(QEMUFile *f,uint64_t flags,void *data);/* * Constants used by ram_control_* hooks
@@ -84,11 +82,11 @@ typedef int (QEMURamHookFunc)(QEMUFile *f, void *opaque, uint64_t flags,* This function allows override of where the RAM page * is saved (such as RDMA, for example.) */ -typedef size_t (QEMURamSaveFunc )(QEMUFile *f,void *opaque, -ram_addr_t block_offset, -ram_addr_t offset, -size_t size, -uint64_t *bytes_sent); +typedef size_t (QEMURamSaveFunc )(QEMUFile *f, +ram_addr_t block_offset, +ram_addr_t offset, +size_t size, +uint64_t *bytes_sent);/* * Return a QEMUFile for comms in the opposite direction
migration/rdma.c +10 -9
@@ -3256,11 +3256,11 @@ qio_channel_rdma_shutdown(QIOChannel *ioc,* sent. Usually, this will not be more than a few bytes of * the protocol because most transfers are sent asynchronously. */ -static size_t qemu_rdma_save_page (QEMUFile *f,void *opaque, +static size_t qemu_rdma_save_page (QEMUFile *f,ram_addr_t block_offset,ram_addr_t offset,size_t size,uint64_t *bytes_sent) { -QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (opaque); +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (qemu_file_get_ioc (f));RDMAContext *rdma;int ret;
@@ -3872,14 +3872,15 @@ rdma_block_notification_handle(QIOChannelRDMA *rioc, const char *name)return 0 ; } -static int rdma_load_hook (QEMUFile *f,void *opaque,uint64_t flags,void *data) +static int rdma_load_hook (QEMUFile *f,uint64_t flags,void *data) { +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (qemu_file_get_ioc (f));switch (flags) {case RAM_CONTROL_BLOCK_REG : -return rdma_block_notification_handle (opaque, data); +return rdma_block_notification_handle (rioc, data);case RAM_CONTROL_HOOK : -return qemu_rdma_registration_handle (f, opaque); +return qemu_rdma_registration_handle (f, rioc);default :/* Shouldn't be called with any other values */
@@ -3887,10 +3888,10 @@ static int rdma_load_hook(QEMUFile *f, void *opaque, uint64_t flags, void *data) } } -static int qemu_rdma_registration_start (QEMUFile *f,void *opaque, +static int qemu_rdma_registration_start (QEMUFile *f,uint64_t flags,void *data) { -QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (opaque); +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (qemu_file_get_ioc (f));RDMAContext *rdma;RCU_READ_LOCK_GUARD ();
@@ -3916,10 +3917,10 @@ static int qemu_rdma_registration_start(QEMUFile *f, void *opaque,* Inform dest that dynamic registrations are done for now. * First, flush writes, if any. */ -static int qemu_rdma_registration_stop (QEMUFile *f,void *opaque, +static int qemu_rdma_registration_stop (QEMUFile *f,uint64_t flags,void *data) { -QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (opaque); +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (qemu_file_get_ioc (f));RDMAContext *rdma;RDMAControlHeader head = { .len =0 , .repeat =1 };int ret =0 ;
Signature · 1 line
2.36.1
PATCH 11/20 migration: hardcode assumption that QEMUFile is backed with QIOChannel
In reply to Daniel P. BerrangéThe only callers of qemu_fopen_ops pass 'true' for the 'has_ioc' parameter, so hardcode this assumption in QEMUFile, by passing in the QIOChannel object as a non-opaque parameter.
--- migration/qemu-file-channel.c | 4 ++-- migration/qemu-file.c | 35 +++++++++++++++++------------------ migration/qemu-file.h | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-)
migration/qemu-file-channel.c +2 -2
@@ -184,11 +184,11 @@ static const QEMUFileOps channel_output_ops = {QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc) {object_ref (OBJECT (ioc)); -return qemu_fopen_ops (ioc, &channel_input_ops, true); +return qemu_fopen_ops (ioc, &channel_input_ops); }QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc) {object_ref (OBJECT (ioc)); -return qemu_fopen_ops (ioc, &channel_output_ops, true); +return qemu_fopen_ops (ioc, &channel_output_ops); }
migration/qemu-file.c +17 -18
@@ -37,7 +37,7 @@struct QEMUFile {const QEMUFileOps *ops;const QEMUFileHooks *hooks; -void *opaque; +QIOChannel *ioc;/* * Maximum amount of data in bytes to transfer during one
@@ -65,8 +65,6 @@ struct QEMUFile {Error *last_error_obj;/* has the file has been shutdown */ bool shutdown; -/* Whether opaque points to a QIOChannel */ -bool has_ioc; };/*
@@ -81,7 +79,7 @@ int qemu_file_shutdown(QEMUFile *f)if (!f->ops->shut_down) {return -ENOSYS ; } - ret = f->ops->shut_down (f->opaque, true, true,NULL ); + ret = f->ops->shut_down (f->ioc, true, true,NULL );if (!f->last_error) {qemu_file_set_error (f, -EIO );
@@ -98,7 +96,7 @@ QEMUFile *qemu_file_get_return_path(QEMUFile *f)if (!f->ops->get_return_path) {return NULL ; } -return f->ops->get_return_path (f->opaque); +return f->ops->get_return_path (f->ioc); }bool qemu_file_mode_is_not_valid (const char *mode)
@@ -113,15 +111,15 @@ bool qemu_file_mode_is_not_valid(const char *mode)return false; } -QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops,bool has_ioc) +QEMUFile *qemu_fopen_ops (QIOChannel *ioc,const QEMUFileOps *ops) {QEMUFile *f; f =g_new0 (QEMUFile,1 ); - f->opaque = opaque; + f->ioc = ioc; f->ops = ops; - f->has_ioc = has_ioc; +return f; }
@@ -242,7 +240,7 @@ void qemu_fflush(QEMUFile *f) }if (f->iovcnt >0 ) { expect =iov_size (f->iov, f->iovcnt); - ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->total_transferred, + ret = f->ops->writev_buffer (f->ioc, f->iov, f->iovcnt, f->total_transferred, &local_error);qemu_iovec_release_ram (f);
@@ -358,7 +356,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return 0 ; } - len = f->ops->get_buffer (f->opaque, f->buf + pending, f->total_transferred, + len = f->ops->get_buffer (f->ioc, f->buf + pending, f->total_transferred,IO_BUF_SIZE - pending, &local_error);if (len >0 ) { f->buf_size += len;
@@ -394,7 +392,7 @@ int qemu_fclose(QEMUFile *f) ret =qemu_file_get_error (f);if (f->ops->close) { -int ret2 = f->ops->close (f->opaque,NULL ); +int ret2 = f->ops->close (f->ioc,NULL );if (ret >=0 ) { ret = ret2; }
@@ -861,18 +859,19 @@ void qemu_put_counted_string(QEMUFile *f, const char *str)void qemu_file_set_blocking (QEMUFile *f,bool block) {if (f->ops->set_blocking) { - f->ops->set_blocking (f->opaque, block,NULL ); + f->ops->set_blocking (f->ioc, block,NULL ); } }/* -* Return the ioc object if it's a migration channel. Note: it can return NULL -* for callers passing in a non-migration qemufile. E.g. see qemu_fopen_bdrv() -* and its usage in e.g. load_snapshot(). So we need to check against NULL -* before using it. If without the check, migration_incoming_state_destroy() -* could fail for load_snapshot(). +* qemu_file_get_ioc: +* +* Get the ioc object for the file, without incrementing +* the reference count. +* +* Returns: the ioc object */ QIOChannel *qemu_file_get_ioc (QEMUFile *file) { -return file->has_ioc ?QIO_CHANNEL (file->opaque) :NULL ; +return file->ioc; }
migration/qemu-file.h +1 -1
@@ -118,7 +118,7 @@ typedef struct QEMUFileHooks {QEMURamSaveFunc *save_page; } QEMUFileHooks; -QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops,bool has_ioc); +QEMUFile *qemu_fopen_ops (QIOChannel *ioc,const QEMUFileOps *ops);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks);int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);
Signature · 1 line
2.36.1
cover migration: remove QEMUFileOps concept and assume use of QIOChannel
Quite a while ago now, the majority of QEMUFile implementations were switched over to use QIOChannel APIs, but a couple remained.
The newish multifd code is directly using QIOChannel, only calling in to QEMUFile for the VMState transfer and for rate limiting purposes.
This series finishes the job of converting QEMUFile to always have a QIOChannel as its backend, enabling a removal of QEMUFileOps.
Most callers still need to use the QEMUFile APIs though, as that performs buffering of reads/writes.
As a followup to this series, however, it would be practical to introduce a QIOChannelCache that layers on top of another QIOChannel to add buffering equivalent to what QEMUFile does, possibly with the rate limiting too.
At that point QEMUFile would not really be doing much at all and could possibly go away entirely, leaving just the MigrationState object for global state tracking, managing one or more QIOChannel objects for the data transfer. I think this could simplify future evolution of migration code.
I'm not likely to have time in the immediate future to work on such a followup though.
Daniel P. Berrangé (20):
io: add a QIOChannelNull equivalent to /dev/null
migration: switch to use QIOChannelNull for dummy channel
migration: remove unreachble RDMA code in save_hook impl
migration: rename rate limiting fields in QEMUFile
migration: rename 'pos' field in QEMUFile to 'bytes_processed'
migration: rename qemu_ftell to qemu_file_total_transferred
migration: rename qemu_update_position to qemu_file_credit_transfer
migration: introduce a QIOChannel impl for BlockDriverState VMState
migration: convert savevm to use QIOChannelBlock for VMState
migration: stop passing 'opaque' parameter to QEMUFile hooks
migration: hardcode assumption that QEMUFile is backed with QIOChannel
migration: introduce new constructors for QEMUFile
migration: remove unused QEMUFileGetFD typedef
migration: remove the QEMUFileOps 'shut_down' callback
migration: remove the QEMUFileOps 'set_blocking' callback
migration: remove the QEMUFileOps 'close' callback
migration: remove the QEMUFileOps 'get_buffer' callback
migration: remove the QEMUFileOps 'writev_buffer' callback
migration: remove the QEMUFileOps 'get_return_path' callback
migration: remove the QEMUFileOps abstraction
include/io/channel-null.h | 55 +++++++ io/channel-null.c | 237 ++++++++++++++++++++++++++++++ io/meson.build | 1 + io/trace-events | 3 + migration/block.c | 10 +- migration/channel-block.c | 195 ++++++++++++++++++++++++ migration/channel-block.h | 59 ++++++++ migration/channel.c | 4 +- migration/colo.c | 5 +- migration/meson.build | 2 +- migration/migration.c | 9 +- migration/qemu-file-channel.c | 194 ------------------------ migration/qemu-file-channel.h | 32 ---- migration/qemu-file.c | 188 +++++++++++++----------- migration/qemu-file.h | 122 +++++++-------- migration/ram.c | 8 +- migration/rdma.c | 144 +++++------------- migration/savevm.c | 55 ++----- migration/vmstate.c | 4 +- tests/unit/meson.build | 1 + tests/unit/test-io-channel-null.c | 95 ++++++++++++ tests/unit/test-vmstate.c | 5 +- 22 files changed, 870 insertions(+), 558 deletions(-) create mode 100644 include/io/channel-null.h create mode 100644 io/channel-null.c create mode 100644 migration/channel-block.c create mode 100644 migration/channel-block.h delete mode 100644 migration/qemu-file-channel.c delete mode 100644 migration/qemu-file-channel.h create mode 100644 tests/unit/test-io-channel-null.c
Signature · 1 line
2.36.1
PATCH 20/20 migration: remove the QEMUFileOps abstraction
Now that all QEMUFile callbacks are removed, the entire concept can be deleted.
--- migration/channel.c | 4 +-- migration/colo.c | 5 ++-- migration/meson.build | 1 - migration/migration.c | 7 ++--- migration/qemu-file-channel.c | 53 ----------------------------------- migration/qemu-file-channel.h | 32 --------------------- migration/qemu-file.c | 20 ++++++------- migration/qemu-file.h | 8 ++---- migration/ram.c | 3 +- migration/rdma.c | 5 ++-- migration/savevm.c | 11 ++++---- tests/unit/test-vmstate.c | 5 ++-- 12 files changed, 27 insertions(+), 127 deletions(-) delete mode 100644 migration/qemu-file-channel.c delete mode 100644 migration/qemu-file-channel.h
migration/channel.c +2 -2
@@ -14,7 +14,7 @@#include "channel.h" #include "tls.h" #include "migration.h" -#include "qemu-file-channel.h" +#include "qemu-file.h" #include "trace.h" #include "qapi/error.h" #include "io/channel-tls.h"
@@ -85,7 +85,7 @@ void migration_channel_connect(MigrationState *s,return ; } }else { -QEMUFile *f =qemu_fopen_channel_output (ioc); +QEMUFile *f =qemu_file_new_output (ioc);migration_ioc_register_yank (ioc);
migration/colo.c +2 -3
@@ -14,7 +14,6 @@#include "sysemu/sysemu.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" -#include "qemu-file-channel.h" #include "migration.h" #include "qemu-file.h" #include "savevm.h"
@@ -559,7 +558,7 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } bioc =qio_channel_buffer_new (COLO_BUFFER_BASE_SIZE ); - fb =qemu_fopen_channel_output (QIO_CHANNEL (bioc)); + fb =qemu_file_new_output (QIO_CHANNEL (bioc));object_unref (OBJECT (bioc));qemu_mutex_lock_iothread ();
@@ -873,7 +872,7 @@ void *colo_process_incoming_thread(void *opaque)colo_incoming_start_dirty_log (); bioc =qio_channel_buffer_new (COLO_BUFFER_BASE_SIZE ); - fb =qemu_fopen_channel_input (QIO_CHANNEL (bioc)); + fb =qemu_file_new_input (QIO_CHANNEL (bioc));object_unref (OBJECT (bioc));qemu_mutex_lock_iothread ();
migration/meson.build +0 -1
@@ -4,7 +4,6 @@ migration_files = files( 'xbzrle.c', 'vmstate-types.c', 'vmstate.c', - 'qemu-file-channel.c', 'qemu-file.c', 'yank_functions.c', )
migration/migration.c +3 -4
@@ -30,7 +30,6 @@#include "migration/misc.h" #include "migration.h" #include "savevm.h" -#include "qemu-file-channel.h" #include "qemu-file.h" #include "migration/vmstate.h" #include "block/block.h"
@@ -722,7 +721,7 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp)if (!mis->from_src_file) {/* The first connection (multifd may have multiple) */ -QEMUFile *f =qemu_fopen_channel_input (ioc); +QEMUFile *f =qemu_file_new_input (ioc);if (!migration_incoming_setup (f, errp)) {return ;
@@ -3081,7 +3080,7 @@ static int postcopy_start(MigrationState *ms)*/ bioc =qio_channel_buffer_new (4096 );qio_channel_set_name (QIO_CHANNEL (bioc),"migration-postcopy-buffer" ); - fb =qemu_fopen_channel_output (QIO_CHANNEL (bioc)); + fb =qemu_file_new_output (QIO_CHANNEL (bioc));object_unref (OBJECT (bioc));/*
@@ -3970,7 +3969,7 @@ static void *bg_migration_thread(void *opaque)*/ s->bioc =qio_channel_buffer_new (512 *1024 );qio_channel_set_name (QIO_CHANNEL (s->bioc),"vmstate-buffer" ); - fb =qemu_fopen_channel_output (QIO_CHANNEL (s->bioc)); + fb =qemu_file_new_output (QIO_CHANNEL (s->bioc));object_unref (OBJECT (s->bioc));update_iteration_initial_status (s);
migration/qemu-file-channel.c deleted +0 -53
53 lines not on this page · raw message
migration/qemu-file-channel.h deleted +0 -32
@@ -1,32 +0,0 @@ -/* -* QEMUFile backend for QIOChannel objects -* -* Copyright (c) 2015-2016 Red Hat, Inc -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#ifndef QEMU_FILE_CHANNEL_H -#define QEMU_FILE_CHANNEL_H - -#include "io/channel.h" - -QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc); -QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc); -#endif
migration/qemu-file.c +8 -12
@@ -35,7 +35,6 @@#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)struct QEMUFile { -const QEMUFileOps *ops;const QEMUFileHooks *hooks;QIOChannel *ioc;bool is_writable;
@@ -104,16 +103,14 @@ bool qemu_file_mode_is_not_valid(const char *mode)return false; } -static QEMUFile *qemu_file_new_impl (QIOChannel *ioc, -const QEMUFileOps *ops, -bool is_writable) +static QEMUFile *qemu_file_new_impl (QIOChannel *ioc,bool is_writable) {QEMUFile *f; f =g_new0 (QEMUFile,1 ); +object_ref (ioc); f->ioc = ioc; - f->ops = ops; f->is_writable = is_writable;return f;
@@ -125,21 +122,19 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc,*/ QEMUFile *qemu_file_get_return_path (QEMUFile *f) { -object_ref (f->ioc); -return qemu_file_new_impl (f->ioc, f->ops, !f->is_writable); +return qemu_file_new_impl (f->ioc, !f->is_writable); } -QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops) +QEMUFile *qemu_file_new_output (QIOChannel *ioc) { -return qemu_file_new_impl (ioc, ops, true); +return qemu_file_new_impl (ioc, true); } -QEMUFile *qemu_file_new_input (QIOChannel *ioc,const QEMUFileOps *ops) +QEMUFile *qemu_file_new_input (QIOChannel *ioc) { -return qemu_file_new_impl (ioc, ops, false); +return qemu_file_new_impl (ioc, false); } -void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks) { f->hooks = hooks;
@@ -235,6 +230,7 @@ static void qemu_iovec_release_ram(QEMUFile *f)memset (f->may_free,0 ,sizeof (f->may_free)); } +/** * Flushes QEMUFile buffer *
migration/qemu-file.h +2 -6
@@ -55,9 +55,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,size_t size, uint64_t *bytes_sent); -typedef struct QEMUFileOps { -}QEMUFileOps ; - typedef struct QEMUFileHooks { QEMURamHookFunc *before_ram_iterate; QEMURamHookFunc *after_ram_iterate;
@@ -65,10 +62,9 @@ typedef struct QEMUFileHooks {QEMURamSaveFunc *save_page; } QEMUFileHooks; -QEMUFile *qemu_file_new_input (QIOChannel *ioc,const QEMUFileOps *ops); -QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops); +QEMUFile *qemu_file_new_input (QIOChannel *ioc); +QEMUFile *qemu_file_new_output (QIOChannel *ioc);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks); -int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);/*
migration/ram.c +1 -2
@@ -38,7 +38,6 @@#include "migration.h" #include "migration/register.h" #include "migration/misc.h" -#include "migration/qemu-file-channel.h" #include "qemu-file.h" #include "postcopy-ram.h" #include "page_cache.h"
@@ -569,7 +568,7 @@ static int compress_threads_save_setup(void)/* comp_param[i].file is just used as a dummy buffer to save data, * set its ops to empty. */ - comp_param[i].file =qemu_fopen_channel_output ( + comp_param[i].file =qemu_file_new_output (QIO_CHANNEL (qio_channel_null_new ())); comp_param[i].done = true; comp_param[i].quit = false;
migration/rdma.c +2 -3
@@ -21,7 +21,6 @@#include "migration.h" #include "qemu-file.h" #include "ram.h" -#include "qemu-file-channel.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/module.h"
@@ -4093,12 +4092,12 @@ static QEMUFile *qemu_fopen_rdma(RDMAContext *rdma, const char *mode) rioc =QIO_CHANNEL_RDMA (object_new (TYPE_QIO_CHANNEL_RDMA ));if (mode[0 ] =='w' ) { - rioc->file =qemu_fopen_channel_output (QIO_CHANNEL (rioc)); + rioc->file =qemu_file_new_output (QIO_CHANNEL (rioc)); rioc->rdmaout = rdma; rioc->rdmain = rdma->return_path;qemu_file_set_hooks (rioc->file, &rdma_write_hooks); }else { - rioc->file =qemu_fopen_channel_input (QIO_CHANNEL (rioc)); + rioc->file =qemu_file_new_input (QIO_CHANNEL (rioc)); rioc->rdmain = rdma; rioc->rdmaout = rdma->return_path;qemu_file_set_hooks (rioc->file, &rdma_read_hooks);
migration/savevm.c +5 -6
@@ -37,7 +37,6 @@#include "migration/global_state.h" #include "migration/channel-block.h" #include "ram.h" -#include "qemu-file-channel.h" #include "qemu-file.h" #include "savevm.h" #include "postcopy-ram.h"
@@ -134,9 +133,9 @@ static struct mig_cmd_args {static QEMUFile *qemu_fopen_bdrv (BlockDriverState *bs,int is_writable) {if (is_writable) { -return qemu_fopen_channel_output (QIO_CHANNEL (qio_channel_block_new (bs))); +return qemu_file_new_output (QIO_CHANNEL (qio_channel_block_new (bs))); }else { -return qemu_fopen_channel_input (QIO_CHANNEL (qio_channel_block_new (bs))); +return qemu_file_new_input (QIO_CHANNEL (qio_channel_block_new (bs))); } }
@@ -2159,7 +2158,7 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis) bioc->usage += length;trace_loadvm_handle_cmd_packaged_received (ret); -QEMUFile *packf =qemu_fopen_channel_input (QIO_CHANNEL (bioc)); +QEMUFile *packf =qemu_file_new_input (QIO_CHANNEL (bioc)); ret =qemu_loadvm_state_main (packf, mis);trace_loadvm_handle_cmd_packaged_main (ret);
@@ -2917,7 +2916,7 @@ void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live, goto the_end; }qio_channel_set_name (QIO_CHANNEL (ioc),"migration-xen-save-state" ); - f =qemu_fopen_channel_output (QIO_CHANNEL (ioc)); + f =qemu_file_new_output (QIO_CHANNEL (ioc));object_unref (OBJECT (ioc)); ret =qemu_save_device_state (f);if (ret <0 ||qemu_fclose (f) <0 ) {
@@ -2964,7 +2963,7 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp)return ; }qio_channel_set_name (QIO_CHANNEL (ioc),"migration-xen-load-state" ); - f =qemu_fopen_channel_input (QIO_CHANNEL (ioc)); + f =qemu_file_new_input (QIO_CHANNEL (ioc));object_unref (OBJECT (ioc)); ret =qemu_loadvm_state (f);
tests/unit/test-vmstate.c +2 -3
@@ -28,7 +28,6 @@#include "migration/vmstate.h" #include "migration/qemu-file-types.h" #include "../migration/qemu-file.h" -#include "../migration/qemu-file-channel.h" #include "../migration/savevm.h" #include "qemu/coroutine.h" #include "qemu/module.h"
@@ -52,9 +51,9 @@ static QEMUFile *open_test_file(bool write) } ioc =QIO_CHANNEL (qio_channel_file_new_fd (fd));if (write) { - f =qemu_fopen_channel_output (ioc); + f =qemu_file_new_output (ioc); }else { - f =qemu_fopen_channel_input (ioc); + f =qemu_file_new_input (ioc); }object_unref (OBJECT (ioc));return f;
Signature · 1 line
2.36.1
PATCH 13/20 migration: remove unused QEMUFileGetFD typedef
In reply to Daniel P. Berrangé--- migration/qemu-file.h | 4 ---- 1 file changed, 4 deletions(-)
migration/qemu-file.h +0 -4
@@ -46,10 +46,6 @@ typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,*/ typedef int (QEMUFileCloseFunc )(void *opaque,Error **errp); -/* Called to return the OS file descriptor associated to the QEMUFile. -*/ -typedef int (QEMUFileGetFD )(void *opaque); -/* Called to change the blocking mode of the file */ typedef int (QEMUFileSetBlocking )(void *opaque,bool enabled,Error **errp);
Signature · 1 line
2.36.1
PATCH 8/20 migration: introduce a QIOChannel impl for BlockDriverState VMState
In reply to Daniel P. Berrangé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.
--- 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
migration/channel-block.c new file +195 -0
@@ -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);
migration/channel-block.h new file +59 -0
59 lines not on this page · raw message
migration/meson.build +1 -0
@@ -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',
Signature · 1 line
2.36.1
PATCH 14/20 migration: remove the QEMUFileOps 'shut_down' callback
In reply to Daniel P. BerrangéThis directly implements the shutdown logic using QIOChannel APIs.
--- migration/qemu-file-channel.c | 27 --------------------------- migration/qemu-file.c | 10 +++++++--- migration/qemu-file.h | 10 ---------- 3 files changed, 7 insertions(+), 40 deletions(-)
migration/qemu-file-channel.c +0 -27
@@ -112,31 +112,6 @@ static int channel_close(void *opaque, Error **errp) } -static int channel_shutdown (void *opaque, -bool rd, -bool wr, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); - -if (qio_channel_has_feature (ioc, -QIO_CHANNEL_FEATURE_SHUTDOWN )) { -QIOChannelShutdown mode; -if (rd && wr) { - mode =QIO_CHANNEL_SHUTDOWN_BOTH ; - }else if (rd) { - mode =QIO_CHANNEL_SHUTDOWN_READ ; - }else { - mode =QIO_CHANNEL_SHUTDOWN_WRITE ; - } -if (qio_channel_shutdown (ioc, mode, errp) <0 ) { -return -EIO ; - } - } -return 0 ; -} - -static int channel_set_blocking (void *opaque,bool enabled,Error **errp)
@@ -166,7 +141,6 @@ static QEMUFile *channel_get_output_return_path(void *opaque)static const QEMUFileOps channel_input_ops = { .get_buffer = channel_get_buffer, .close = channel_close, - .shut_down = channel_shutdown, .set_blocking = channel_set_blocking, .get_return_path = channel_get_input_return_path, };
@@ -175,7 +149,6 @@ static const QEMUFileOps channel_input_ops = {static const QEMUFileOps channel_output_ops = { .writev_buffer = channel_writev_buffer, .close = channel_close, - .shut_down = channel_shutdown, .set_blocking = channel_set_blocking, .get_return_path = channel_get_output_return_path, };
migration/qemu-file.c +7 -3
@@ -74,13 +74,17 @@ struct QEMUFile {*/ int qemu_file_shutdown (QEMUFile *f) { -int ret; +int ret =0 ; f->shutdown = true; -if (!f->ops->shut_down) { +if (!qio_channel_has_feature (f->ioc, +QIO_CHANNEL_FEATURE_SHUTDOWN )) {return -ENOSYS ; } - ret = f->ops->shut_down (f->ioc, true, true,NULL ); + +if (qio_channel_shutdown (f->ioc,QIO_CHANNEL_SHUTDOWN_BOTH ,NULL ) <0 ) { + ret = -EIO ; + }if (!f->last_error) {qemu_file_set_error (f, -EIO );
migration/qemu-file.h +0 -10
@@ -89,22 +89,12 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,*/ typedef QEMUFile *(QEMURetPathFunc )(void *opaque); -/* -* Stop any read or write (depending on flags) on the underlying -* transport on the QEMUFile. -* Existing blocking reads/writes must be woken -* Returns 0 on success, -err on error -*/ -typedef int (QEMUFileShutdownFunc )(void *opaque,bool rd,bool wr, -Error **errp); -typedef struct QEMUFileOps {QEMUFileGetBufferFunc *get_buffer;QEMUFileCloseFunc *close;QEMUFileSetBlocking *set_blocking;QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path; -QEMUFileShutdownFunc *shut_down; }QEMUFileOps ; typedef struct QEMUFileHooks {
Signature · 1 line
2.36.1
PATCH 9/20 migration: convert savevm to use QIOChannelBlock for VMState
In reply to Daniel P. BerrangéWith this change, all QEMUFile usage is backed by QIOChannel at last.
--- migration/savevm.c | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-)
migration/savevm.c +4 -38
@@ -35,6 +35,7 @@#include "migration/misc.h" #include "migration/register.h" #include "migration/global_state.h" +#include "migration/channel-block.h" #include "ram.h" #include "qemu-file-channel.h" #include "qemu-file.h"
@@ -130,48 +131,13 @@ static struct mig_cmd_args {/***********************************************************/ /* savevm/loadvm support */ -static ssize_t block_writev_buffer (void *opaque,struct iovec *iov,int iovcnt, -int64_t pos,Error **errp) -{ -int ret; -QEMUIOVector qiov; - -qemu_iovec_init_external (&qiov, iov, iovcnt); - ret =bdrv_writev_vmstate (opaque, &qiov, pos); -if (ret <0 ) { -return ret; - } - -return qiov.size; -} - -static ssize_t block_get_buffer (void *opaque,uint8_t *buf,int64_t pos, -size_t size,Error **errp) -{ -return bdrv_load_vmstate (opaque, buf, pos, size); -} - -static int bdrv_fclose (void *opaque,Error **errp) -{ -return bdrv_flush (opaque); -} - -static const QEMUFileOps bdrv_read_ops = { - .get_buffer = block_get_buffer, - .close = bdrv_fclose -}; - -static const QEMUFileOps bdrv_write_ops = { - .writev_buffer = block_writev_buffer, - .close = bdrv_fclose -}; -static QEMUFile *qemu_fopen_bdrv (BlockDriverState *bs,int is_writable) {if (is_writable) { -return qemu_fopen_ops (bs, &bdrv_write_ops, false); +return qemu_fopen_channel_output (QIO_CHANNEL (qio_channel_block_new (bs))); + }else { +return qemu_fopen_channel_input (QIO_CHANNEL (qio_channel_block_new (bs))); } -return qemu_fopen_ops (bs, &bdrv_read_ops, false); }
Signature · 1 line
2.36.1
PATCH 16/20 migration: remove the QEMUFileOps 'close' callback
In reply to Daniel P. BerrangéThis directly implements the close logic using QIOChannel APIs.
--- migration/qemu-file-channel.c | 12 ------------ migration/qemu-file.c | 12 ++++++------ migration/qemu-file.h | 10 ---------- 3 files changed, 6 insertions(+), 28 deletions(-)
migration/qemu-file-channel.c +0 -12
@@ -102,16 +102,6 @@ static ssize_t channel_get_buffer(void *opaque, } -static int channel_close (void *opaque,Error **errp) -{ -int ret; -QIOChannel *ioc =QIO_CHANNEL (opaque); - ret =qio_channel_close (ioc, errp); -object_unref (OBJECT (ioc)); -return ret; -} - -static QEMUFile *channel_get_input_return_path (void *opaque) {QIOChannel *ioc =QIO_CHANNEL (opaque);
@@ -128,14 +118,12 @@ static QEMUFile *channel_get_output_return_path(void *opaque)static const QEMUFileOps channel_input_ops = { .get_buffer = channel_get_buffer, - .close = channel_close, .get_return_path = channel_get_input_return_path, };static const QEMUFileOps channel_output_ops = { .writev_buffer = channel_writev_buffer, - .close = channel_close, .get_return_path = channel_get_output_return_path, };
migration/qemu-file.c +6 -6
@@ -405,16 +405,16 @@ void qemu_file_credit_transfer(QEMUFile *f, size_t size)*/ int qemu_fclose (QEMUFile *f) { -int ret; +int ret, ret2;qemu_fflush (f); ret =qemu_file_get_error (f); -if (f->ops->close) { -int ret2 = f->ops->close (f->ioc,NULL ); -if (ret >=0 ) { - ret = ret2; - } + ret2 =qio_channel_close (f->ioc,NULL ); +if (ret >=0 ) { + ret = ret2; } +g_clear_pointer (&f->ioc, object_unref); +/* If any error was spotted before closing, we should report it * instead of the close() return value. */
migration/qemu-file.h +0 -10
@@ -37,15 +37,6 @@ typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf, int64_t pos, size_t size, Error **errp); -/* Close a file -* -* Return negative error number on error, 0 or positive value on success. -* -* The meaning of return value on success depends on the specific back-end being -* used. -*/ -typedef int (QEMUFileCloseFunc )(void *opaque,Error **errp); -/* * This function writes an iovec to file. The handler must write all * of the data or return a negative errno value.
@@ -87,7 +78,6 @@ typedef QEMUFile *(QEMURetPathFunc)(void *opaque);typedef struct QEMUFileOps {QEMUFileGetBufferFunc *get_buffer; -QEMUFileCloseFunc *close;QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path; }QEMUFileOps ;
Signature · 1 line
2.36.1
PATCH 18/20 migration: remove the QEMUFileOps 'writev_buffer' callback
In reply to Daniel P. BerrangéThis directly implements the writev_buffer logic using QIOChannel APIs.
--- migration/qemu-file-channel.c | 43 ----------------------------------- migration/qemu-file.c | 24 +++++++------------ migration/qemu-file.h | 9 -------- 3 files changed, 8 insertions(+), 68 deletions(-)
migration/qemu-file-channel.c +0 -43
@@ -32,48 +32,6 @@#include "yank_functions.h" -static ssize_t channel_writev_buffer (void *opaque, -struct iovec *iov, -int iovcnt, -int64_t pos, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); -ssize_t done =0 ; - struct iovec *local_iov = g_new(struct iovec, iovcnt); -struct iovec *local_iov_head = local_iov; -unsigned int nlocal_iov = iovcnt; - - nlocal_iov =iov_copy (local_iov, nlocal_iov, - iov, iovcnt, -0 ,iov_size (iov, iovcnt)); - -while (nlocal_iov >0 ) { -ssize_t len; - len =qio_channel_writev (ioc, local_iov, nlocal_iov, errp); -if (len ==QIO_CHANNEL_ERR_BLOCK ) { -if (qemu_in_coroutine ()) { -qio_channel_yield (ioc,G_IO_OUT ); - }else { -qio_channel_wait (ioc,G_IO_OUT ); - } -continue ; - } -if (len <0 ) { - done = -EIO ; - goto cleanup; - } - -iov_discard_front (&local_iov, &nlocal_iov, len); - done += len; - } - - cleanup: -g_free (local_iov_head); -return done; -} - -static QEMUFile *channel_get_input_return_path (void *opaque) {QIOChannel *ioc =QIO_CHANNEL (opaque);
@@ -94,7 +52,6 @@ static const QEMUFileOps channel_input_ops = {static const QEMUFileOps channel_output_ops = { - .writev_buffer = channel_writev_buffer, .get_return_path = channel_get_output_return_path, };
migration/qemu-file.c +8 -16
@@ -245,10 +245,6 @@ static void qemu_iovec_release_ram(QEMUFile *f)*/ void qemu_fflush (QEMUFile *f) { -ssize_t ret =0 ; -ssize_t expect =0 ; -Error *local_error =NULL ; -if (!qemu_file_is_writable (f)) {return ; }
@@ -257,22 +253,18 @@ void qemu_fflush(QEMUFile *f)return ; }if (f->iovcnt >0 ) { - expect =iov_size (f->iov, f->iovcnt); - ret = f->ops->writev_buffer (f->ioc, f->iov, f->iovcnt, f->total_transferred, - &local_error); +Error *local_error =NULL ; +if (qio_channel_writev_all (f->ioc, + f->iov, f->iovcnt, + &local_error) <0 ) { +qemu_file_set_error_obj (f, -EIO , local_error); + }else { + f->total_transferred +=iov_size (f->iov, f->iovcnt); + }qemu_iovec_release_ram (f); } -if (ret >=0 ) { - f->total_transferred += ret; - } -/* We expect the QEMUFile write impl to send the full -* data set we requested, so sanity check that. -*/ -if (ret != expect) { -qemu_file_set_error_obj (f, ret <0 ? ret : -EIO , local_error); - } f->buf_index =0 ; f->iovcnt =0 ; }
migration/qemu-file.h +0 -9
@@ -29,14 +29,6 @@#include "exec/cpu-common.h" #include "io/channel.h" -/* -* This function writes an iovec to file. The handler must write all -* of the data or return a negative errno value. -*/ -typedef ssize_t (QEMUFileWritevBufferFunc )(void *opaque,struct iovec *iov, -int iovcnt,int64_t pos, -Error **errp); -/* * This function provides hooks around different * stages of RAM migration.
@@ -69,7 +61,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,typedef QEMUFile *(QEMURetPathFunc )(void *opaque);typedef struct QEMUFileOps { -QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path; }QEMUFileOps ;
Signature · 1 line
2.36.1
Re: [PATCH 01/20] io: add a QIOChannelNull equivalent to /dev/null
In reply to Daniel P. BerrangéQuoted 16 lines · Daniel P. Berrangé
This is for code which needs a portable equivalent to a QIOChannelFile connected to
/dev/null.Signed-off-by Daniel P. Berrangé <[email protected]>--- include/io/channel-null.h | 55 +++++++ io/channel-null.c | 237 ++++++++++++++++++++++++++++++ io/meson.build | 1 + io/trace-events | 3 + tests/unit/meson.build | 1 + tests/unit/test-io-channel-null.c | 95 ++++++++++++ 6 files changed, 392 insertions(+) create mode 100644 include/io/channel-null.h create mode 100644 io/channel-null.c create mode 100644 tests/unit/test-io-channel-null.c
Quoted 5 lines
+/**
+ * QIOChannelNull:
+ *
+ * The QIOChannelNull object provides a channel implementation
+ * that discards all writes and returns zero bytes for all reads.
That describes the behavior of /dev/zero, not /dev/null, where reads always fail with EOF.
Quoted 19 lines
+ */
include/io/channel-null.h new file +6
-0+ +struct QIOChannelNull { +QIOChannel parent; +bool closed; +}; +io/channel-null.c +9
-0+ +static ssize_t +qio_channel_null_readv (QIOChannel *ioc, +const struct iovec *iov, +size_t niov, + int **fds G_GNUC_UNUSED, + size_t *nfds G_GNUC_UNUSED, +Error **errp) +{
io/channel-null.c line 74
Quoted 10 lines
io/channel-null.c +10
-0+QIOChannelNull *nioc =QIO_CHANNEL_NULL (ioc); + +if (nioc->closed) { +error_setg_errno (errp,EINVAL , +"Channel is closed" ); +return -1 ; + } + +return 0 ; +}
But this behavior is returning early EOF instead of using iov_memset() to read all zeroes the way /dev/zero would.
io/channel-null.c
Quoted 12 lines
+++
b/tests/unit/test-io-channel-null.cio/channel-null.c +10
-0+static void test_io_channel_null_io (void ) +{ +g_autoptr (QIOChannelNull) null =qio_channel_null_new (); +char buf[1024 ]; +GIOCondition gotcond =0 ; +Error *local_err =NULL ; + +g_assert (qio_channel_write (QIO_CHANNEL (null), +"Hello World" ,11 , + &error_abort) ==11 );
I still cringe seeing tests inside g_assert(), but this is not the first instance of it.
io/channel-null.c
Quoted 4 lines
io/channel-null.c +4
-0+ +g_assert (qio_channel_read (QIO_CHANNEL (null), + buf,sizeof (buf), + &error_abort) ==0 );
Okay, you're testing for /dev/null behavior of early EOF.
Other than misleading comments, this looks reasonable. But those comments are core enough as to what this channel does that I don't feel comfortable giving R-b yet.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH 02/20] migration: switch to use QIOChannelNull for dummy channel
In reply to Daniel P. BerrangéQuoted 8 lines · Daniel P. Berrangé
This removes one further custom impl of QEMUFile, in favour of a QIOChannel based impl.
Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/ram.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH 03/20] migration: remove unreachble RDMA code in save_hook impl
In reply to Daniel P. BerrangéQuoted 18 lines · Daniel P. Berrangé
The QEMUFile '
save_hook' callback has a 'size_tsize' parameter.The RDMA impl of this has logic that takes different actions depending on whether the value is zero or non-zero. It has commented out logic that would have taken further actions if the value was negative.
The only place where the '
save_hook' callback is invoked is theram_control_save_page()method, which passes 'size' through from its caller. The only caller of this method is in turncontrol_save_page(). This method unconditionally passes the 'TARGET_PAGE_SIZE' constant for the 'size' parameter.IOW, the only scenario for 'size' that can execute in the
qemu_rdma_save_pagemethod is 'size > 0'. The remaining code has been unreachable since RDMA support was first introduced 9 years ago.
Quoted 5 lines
Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/rdma.c | 120 +++++++++-------------------------------------- 1 file changed, 21 insertions(+), 99 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [PATCH 03/20] migration: remove unreachble RDMA code in save_hook impl
In reply to Daniel P. BerrangéQuoted 13 lines · * Daniel P. Berrangé ([email protected]) wrote:
The QEMUFile '
save_hook' callback has a 'size_tsize' parameter.The RDMA impl of this has logic that takes different actions depending on whether the value is zero or non-zero. It has commented out logic that would have taken further actions if the value was negative.
The only place where the '
save_hook' callback is invoked is theram_control_save_page()method, which passes 'size' through from its caller. The only caller of this method is in turncontrol_save_page(). This method unconditionally passes the 'TARGET_PAGE_SIZE' constant for the 'size' parameter.
Quoted 6 lines
IOW, the only scenario for 'size' that can execute in the
qemu_rdma_save_pagemethod is 'size > 0'. The remaining code has been unreachable since RDMA support was first introduced 9 years ago.Signed-off-by Daniel P. Berrangé <[email protected]>
Ah good; less rdma code!
Quoted 153 lines
--- migration/rdma.c | 120 +++++++++-------------------------------------- 1 file changed, 21 insertions(+), 99 deletions(-)migration/rdma.c +21
-99@@ -1486,34 +1486,6 @@ static uint64_t qemu_rdma_make_wrid(uint64_t wr_id, uint64_t index,return result; } -/* -* Set bit for unregistration in the next iteration. -* We cannot transmit right here, but will unpin later. -*/ -static void qemu_rdma_signal_unregister (RDMAContext *rdma,uint64_t index, -uint64_t chunk,uint64_t wr_id) -{ -if (rdma->unregistrations[rdma->unregister_next] !=0 ) { -error_report ("rdma migration: queue is full" ); - }else { -RDMALocalBlock *block = &(rdma->local_ram_blocks.block[index]); - -if (!test_and_set_bit (chunk, block->unregister_bitmap)) { -trace_qemu_rdma_signal_unregister_append (chunk, - rdma->unregister_next); - - rdma->unregistrations[rdma->unregister_next++] = -qemu_rdma_make_wrid (wr_id, index, chunk); - -if (rdma->unregister_next ==RDMA_SIGNALED_SEND_MAX ) { - rdma->unregister_next =0 ; - } - }else { -trace_qemu_rdma_signal_unregister_already (chunk); - } - } -} -/* * Consult the connection manager to see a work request * (of any kind) has completed. @@ -3278,23 +3250,7 @@ qio_channel_rdma_shutdown(QIOChannel *ioc,* Offset is an offset to be added to block_offset and used * to also lookup the corresponding RAMBlock. * -* @size > 0 : -* Initiate an transfer this size. -* -* @size == 0 : -* A 'hint' or 'advice' that means that we wish to speculatively -* and asynchronously unregister this memory. In this case, there is no -* guarantee that the unregister will actually happen, for example, -* if the memory is being actively transmitted. Additionally, the memory -* may be re-registered at any future time if a write within the same -* chunk was requested again, even if you attempted to unregister it -* here. -* -* @size < 0 : TODO, not yet supported -* Unregister the memory NOW. This means that the caller does not -* expect there to be any future RDMA transfers and we just want to clean -* things up. This is used in case the upper layer owns the memory and -* cannot wait for qemu_fclose() to occur. +* @size : Number of bytes to transfer * * @bytes_sent : User-specificed pointer to indicate how many bytes were * sent. Usually, this will not be more than a few bytes of @@ -3323,61 +3279,27 @@ static size_t qemu_rdma_save_page(QEMUFile *f, void *opaque,qemu_fflush (f); -if (size >0 ) { -/* -* Add this page to the current 'chunk'. If the chunk -* is full, or the page doesn't belong to the current chunk, -* an actual RDMA write will occur and a new chunk will be formed. -*/ - ret =qemu_rdma_write (f, rdma, block_offset, offset, size); -if (ret <0 ) { -error_report ("rdma migration: write error! %d" , ret); - goto err; - } - -/* -* We always return 1 bytes because the RDMA -* protocol is completely asynchronous. We do not yet know -* whether an identified chunk is zero or not because we're -* waiting for other pages to potentially be merged with -* the current chunk. So, we have to call qemu_update_position() -* later on when the actual write occurs. -*/ -if (bytes_sent) { - *bytes_sent =1 ; - } - }else { -uint64_t index, chunk; - -/* TODO: Change QEMUFileOps prototype to be signed: size_t => long -if (size < 0) { -ret = qemu_rdma_drain_cq(f, rdma); -if (ret < 0) { -fprintf(stderr, "rdma: failed to synchronously drain" -" completion queue before unregistration.\n"); -goto err; -} -} -*/ - - ret =qemu_rdma_search_ram_block (rdma, block_offset, - offset, size, &index, &chunk); - -if (ret) { -error_report ("ram block search failed" ); - goto err; - } - -qemu_rdma_signal_unregister (rdma, index, chunk,0 ); +/* +* Add this page to the current 'chunk'. If the chunk +* is full, or the page doesn't belong to the current chunk, +* an actual RDMA write will occur and a new chunk will be formed. +*/ + ret =qemu_rdma_write (f, rdma, block_offset, offset, size); +if (ret <0 ) { +error_report ("rdma migration: write error! %d" , ret); + goto err; + } -/* -* TODO: Synchronous, guaranteed unregistration (should not occur during -* fast-path). Otherwise, unregisters will process on the next call to -* qemu_rdma_drain_cq() -if (size < 0) { -qemu_rdma_unregister_waiting(rdma); -} -*/ +/* +* We always return 1 bytes because the RDMA +* protocol is completely asynchronous. We do not yet know +* whether an identified chunk is zero or not because we're +* waiting for other pages to potentially be merged with +* the current chunk. So, we have to call qemu_update_position() +* later on when the actual write occurs. +*/ +if (bytes_sent) { + *bytes_sent =1 ; }/* Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 04/20] migration: rename rate limiting fields in QEMUFile
In reply to Daniel P. BerrangéQuoted 10 lines · * Daniel P. Berrangé ([email protected]) wrote:
This renames the following QEMUFile fields
*
bytes_xfer->rate_limit_used
*xfer_limit->rate_limit_maxThe intent is to make it clear that '
bytes_xfer' is specifically related to rate limiting of data and applies to data queued, which need not have been transferred on the wire yet if a flush hasn't taken place.Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 102 lines
--- migration/qemu-file.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-)migration/qemu-file.c +19
-11@@ -39,8 +39,16 @@ struct QEMUFile {const QEMUFileHooks *hooks;void *opaque; -int64_t bytes_xfer; -int64_t xfer_limit; +/* +* Maximum amount of data in bytes to transfer during one +* rate limiting time window +*/ +int64_t rate_limit_max; +/* +* Total amount of data in bytes queued for transfer +* during this rate limiting time window +*/ +int64_t rate_limit_used;int64_t pos;/* start of buffer when writing, end of buffer when reading */ @@ -304,7 +312,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,int ret = f->hooks->save_page (f, f->opaque, block_offset, offset, size, bytes_sent);if (ret !=RAM_SAVE_CONTROL_NOT_SUPP ) { - f->bytes_xfer += size; + f->rate_limit_used += size; } if (ret != RAM_SAVE_CONTROL_DELAYED &&@@ -457,7 +465,7 @@ void qemu_put_buffer_async(QEMUFile *f, const uint8_t *buf, size_t size,return ; } - f->bytes_xfer += size; + f->rate_limit_used += size;add_to_iovec (f, buf, size, may_free); }@@ -475,7 +483,7 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size) l = size; }memcpy (f->buf + f->buf_index, buf, l); - f->bytes_xfer += l; + f->rate_limit_used += l;add_buf_to_iovec (f, l);if (qemu_file_get_error (f)) {break ;@@ -492,7 +500,7 @@ void qemu_put_byte(QEMUFile *f, int v) } f->buf[f->buf_index] = v; - f->bytes_xfer++; + f->rate_limit_used++;add_buf_to_iovec (f,1 ); }@@ -674,7 +682,7 @@ int qemu_file_rate_limit(QEMUFile *f)if (qemu_file_get_error (f)) {return 1 ; } -if (f->xfer_limit >0 && f->bytes_xfer > f->xfer_limit) { +if (f->rate_limit_max >0 && f->rate_limit_used > f->rate_limit_max) {return 1 ; }return 0 ;@@ -682,22 +690,22 @@ int qemu_file_rate_limit(QEMUFile *f)int64_t qemu_file_get_rate_limit (QEMUFile *f) { -return f->xfer_limit; +return f->rate_limit_max; }void qemu_file_set_rate_limit (QEMUFile *f,int64_t limit) { - f->xfer_limit = limit; + f->rate_limit_max = limit; }void qemu_file_reset_rate_limit (QEMUFile *f) { - f->bytes_xfer =0 ; + f->rate_limit_used =0 ; }void qemu_file_update_transfer (QEMUFile *f,int64_t len) { - f->bytes_xfer += len; + f->rate_limit_used += len; }void qemu_put_be16 (QEMUFile *f,unsigned int v)Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 05/20] migration: rename 'pos' field in QEMUFile to 'bytes_processed'
In reply to Daniel P. BerrangéQuoted 2 lines · * Daniel P. Berrangé ([email protected]) wrote:
This makes the field name align with the newly introduced method names in the previous commit.
I think that's the method in the following commits?
tbh I'm not sure about this; 'pos' is still passed to writev_buffer and get_buffer to say where the data is - and that makes it a 'pos' still rather than a simple stats counter.
Dave
Quoted 82 lines
Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/qemu-file.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)migration/qemu-file.c +10
-9@@ -50,8 +50,9 @@ struct QEMUFile {*/ int64_t rate_limit_used; -int64_t pos;/* start of buffer when writing, end of buffer -when reading */ +/* The sum of bytes transferred on the wire */ +int64_t total_transferred; +int buf_index;int buf_size;/* 0 when writing */ uint8_t buf[IO_BUF_SIZE ];@@ -241,14 +242,14 @@ void qemu_fflush(QEMUFile *f) }if (f->iovcnt >0 ) { expect =iov_size (f->iov, f->iovcnt); - ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->pos, + ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->total_transferred, &local_error);qemu_iovec_release_ram (f); }if (ret >=0 ) { - f->pos += ret; + f->total_transferred += ret; }/* We expect the QEMUFile write impl to send the full * data set we requested, so sanity check that. @@ -357,11 +358,11 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return 0 ; } - len = f->ops->get_buffer (f->opaque, f->buf + pending, f->pos, + len = f->ops->get_buffer (f->opaque, f->buf + pending, f->total_transferred,IO_BUF_SIZE - pending, &local_error);if (len >0 ) { f->buf_size += len; - f->pos += len; + f->total_transferred += len; }else if (len ==0 ) {qemu_file_set_error_obj (f, -EIO , local_error); }else if (len != -EAGAIN ) {@@ -375,7 +376,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)void qemu_update_position (QEMUFile *f,size_t size) { - f->pos += size; + f->total_transferred += size; }/** Closes the file @@ -658,7 +659,7 @@ int qemu_get_byte(QEMUFile *f)int64_t qemu_ftell_fast (QEMUFile *f) { -int64_t ret = f->pos; +int64_t ret = f->total_transferred;int i;for (i =0 ; i < f->iovcnt; i++) {@@ -671,7 +672,7 @@ int64_t qemu_ftell_fast(QEMUFile *f)int64_t qemu_ftell (QEMUFile *f) {qemu_fflush (f); -return f->pos; +return f->total_transferred; }int qemu_file_rate_limit (QEMUFile *f)Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Dr. David Alan Gilbert
Reviewed-byRe: [PATCH 05/20] migration: rename 'pos' field in QEMUFile to 'bytes_processed'
In reply to Daniel P. BerrangéQuoted 17 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 5 lines · Dr. David Alan Gilbert
Quoted 2 lines · * Daniel P. Berrangé ([email protected]) wrote:
This makes the field name align with the newly introduced method names in the previous commit.
I think that's the method in the following commits?
Opps, yeah, I did re-arrange this series a few times to get the most attractive diffs.
Quoted 3 lines
tbh I'm not sure about this; 'pos' is still passed to
writev_bufferandget_bufferto say where the data is - and that makes it a 'pos' still rather than a simple stats counter.Note every QIOChannel backed impl of QEMUFile is ignoring the 'pos' field.
Quoted 6 lines
The only QEMUFile impl using 'pos' is the one during I/O is the block device vmstate. A later patch is introducing a QIOChannel impl for the vmstate, and to handle this it is tracking a file offset itself internally to the QIOChannel impl. So when we eliminate the QEMUFileOps callbacks later, this 'pos' goes away.
Ah! Put that description in the commit message and:
Quoted 96 lines
So I guess my description here is a little ahead of itself.
Quoted 78 lines
Quoted 78 lines
Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/qemu-file.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)migration/qemu-file.c +10
-9@@ -50,8 +50,9 @@ struct QEMUFile {*/ int64_t rate_limit_used; -int64_t pos;/* start of buffer when writing, end of buffer -when reading */ +/* The sum of bytes transferred on the wire */ +int64_t total_transferred; +int buf_index;int buf_size;/* 0 when writing */ uint8_t buf[IO_BUF_SIZE ];@@ -241,14 +242,14 @@ void qemu_fflush(QEMUFile *f) }if (f->iovcnt >0 ) { expect =iov_size (f->iov, f->iovcnt); - ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->pos, + ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->total_transferred, &local_error);qemu_iovec_release_ram (f); }if (ret >=0 ) { - f->pos += ret; + f->total_transferred += ret; }/* We expect the QEMUFile write impl to send the full * data set we requested, so sanity check that. @@ -357,11 +358,11 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return 0 ; } - len = f->ops->get_buffer (f->opaque, f->buf + pending, f->pos, + len = f->ops->get_buffer (f->opaque, f->buf + pending, f->total_transferred,IO_BUF_SIZE - pending, &local_error);if (len >0 ) { f->buf_size += len; - f->pos += len; + f->total_transferred += len; }else if (len ==0 ) {qemu_file_set_error_obj (f, -EIO , local_error); }else if (len != -EAGAIN ) {@@ -375,7 +376,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)void qemu_update_position (QEMUFile *f,size_t size) { - f->pos += size; + f->total_transferred += size; }/** Closes the file @@ -658,7 +659,7 @@ int qemu_get_byte(QEMUFile *f)int64_t qemu_ftell_fast (QEMUFile *f) { -int64_t ret = f->pos; +int64_t ret = f->total_transferred;int i;for (i =0 ; i < f->iovcnt; i++) {@@ -671,7 +672,7 @@ int64_t qemu_ftell_fast(QEMUFile *f)int64_t qemu_ftell (QEMUFile *f) {qemu_fflush (f); -return f->pos; +return f->total_transferred; }Quoted 7 lines
Quoted 4 lines
migration/qemu-file.c +0
-0int qemu_file_rate_limit (QEMUFile *f)Signature · 1 line
2.36.1Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UKWith regards,
DanielSignature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 05/20] migration: rename 'pos' field in QEMUFile to 'bytes_processed'
In reply to Dr. David Alan GilbertQuoted 5 lines · Dr. David Alan Gilbert
Quoted 2 lines · * Daniel P. Berrangé ([email protected]) wrote:
This makes the field name align with the newly introduced method names in the previous commit.
I think that's the method in the following commits?
Opps, yeah, I did re-arrange this series a few times to get the most attractive diffs.
Quoted 3 lines
tbh I'm not sure about this; 'pos' is still passed to
writev_bufferandget_bufferto say where the data is - and that makes it a 'pos' still rather than a simple stats counter.
Note every QIOChannel backed impl of QEMUFile is ignoring the 'pos' field.
The only QEMUFile impl using 'pos' is the one during I/O is the block device vmstate. A later patch is introducing a QIOChannel impl for the vmstate, and to handle this it is tracking a file offset itself internally to the QIOChannel impl. So when we eliminate the QEMUFileOps callbacks later, this 'pos' goes away.
So I guess my description here is a little ahead of itself.
Quoted 78 lines
Quoted 78 lines
Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/qemu-file.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-)migration/qemu-file.c +10
-9@@ -50,8 +50,9 @@ struct QEMUFile {*/ int64_t rate_limit_used; -int64_t pos;/* start of buffer when writing, end of buffer -when reading */ +/* The sum of bytes transferred on the wire */ +int64_t total_transferred; +int buf_index;int buf_size;/* 0 when writing */ uint8_t buf[IO_BUF_SIZE ];@@ -241,14 +242,14 @@ void qemu_fflush(QEMUFile *f) }if (f->iovcnt >0 ) { expect =iov_size (f->iov, f->iovcnt); - ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->pos, + ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->total_transferred, &local_error);qemu_iovec_release_ram (f); }if (ret >=0 ) { - f->pos += ret; + f->total_transferred += ret; }/* We expect the QEMUFile write impl to send the full * data set we requested, so sanity check that. @@ -357,11 +358,11 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return 0 ; } - len = f->ops->get_buffer (f->opaque, f->buf + pending, f->pos, + len = f->ops->get_buffer (f->opaque, f->buf + pending, f->total_transferred,IO_BUF_SIZE - pending, &local_error);if (len >0 ) { f->buf_size += len; - f->pos += len; + f->total_transferred += len; }else if (len ==0 ) {qemu_file_set_error_obj (f, -EIO , local_error); }else if (len != -EAGAIN ) {@@ -375,7 +376,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)void qemu_update_position (QEMUFile *f,size_t size) { - f->pos += size; + f->total_transferred += size; }/** Closes the file @@ -658,7 +659,7 @@ int qemu_get_byte(QEMUFile *f)int64_t qemu_ftell_fast (QEMUFile *f) { -int64_t ret = f->pos; +int64_t ret = f->total_transferred;int i;for (i =0 ; i < f->iovcnt; i++) {@@ -671,7 +672,7 @@ int64_t qemu_ftell_fast(QEMUFile *f)int64_t qemu_ftell (QEMUFile *f) {qemu_fflush (f); -return f->pos; +return f->total_transferred; }
Quoted 7 lines
Quoted 4 lines
migration/qemu-file.c +0
-0int qemu_file_rate_limit (QEMUFile *f)Signature · 1 line
2.36.1Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 06/20] migration: rename qemu_ftell to qemu_file_total_transferred
In reply to Daniel P. BerrangéQuoted 7 lines · * Daniel P. Berrangé ([email protected]) wrote:
The name 'ftell' gives the misleading impression that the QEMUFile objects are seekable. This is not the case, as in general we just have an opaque stream. The users of this method are only interested in the total bytes processed. This switches to a new name that reflects the intended usage.
Signed-off-by Daniel P. Berrangé <[email protected]>
Mostly,
Two nits below:
Quoted 43 lines
--- migration/block.c | 10 +++++----- migration/migration.c | 2 +- migration/qemu-file.c | 4 ++-- migration/qemu-file.h | 40 ++++++++++++++++++++++++++++++++++++++-- migration/savevm.c | 6 +++--- migration/vmstate.c | 4 ++-- 6 files changed, 51 insertions(+), 15 deletions(-)migration/block.c +5
-5@@ -756,8 +756,8 @@ static int block_save_setup(QEMUFile *f, void *opaque)static int block_save_iterate (QEMUFile *f,void *opaque) {int ret; -int64_t last_ftell =qemu_ftell (f); -int64_t delta_ftell; +int64_t last_bytes =qemu_file_total_transferred (f); +int64_t delta_bytes;trace_migration_block_save ("iterate" , block_mig_state.submitted, block_mig_state.transferred);@@ -809,10 +809,10 @@ static int block_save_iterate(QEMUFile *f, void *opaque) }qemu_put_be64 (f,BLK_MIG_FLAG_EOS ); - delta_ftell =qemu_ftell (f) - last_ftell; -if (delta_ftell >0 ) { + delta_bytes =qemu_file_total_transferred (f) - last_bytes; +if (delta_bytes >0 ) {return 1 ; - }else if (delta_ftell <0 ) { + }else if (delta_bytes <0 ) {return -1 ; }else {return 0 ;migration/migration.c +0
-0
migration/migration.c static MigThrError migration_detect_error(MigrationState *s) · line 3547
Quoted 5 lines
migration/migration.c +1
-1@@ -3544,7 +3544,7 @@ static MigThrError migration_detect_error(MigrationState *s)/* How many bytes have we transferred since the beginning of the migration */ static uint64_t migration_total_bytes (MigrationState *s) { -return qemu_ftell (s->to_dst_file) + ram_counters.multifd_bytes; +return qemu_file_total_transferred (s->to_dst_file) + ram_counters.multifd_bytes;
I think that's hit line length limits.
Quoted 60 lines
migration/migration.c +0
-0}static void migration_calculate_complete (MigrationState *s)migration/qemu-file.c +2
-2@@ -657,7 +657,7 @@ int qemu_get_byte(QEMUFile *f)return result; } -int64_t qemu_ftell_fast (QEMUFile *f) +int64_t qemu_file_total_transferred_fast (QEMUFile *f) {int64_t ret = f->total_transferred;int i;@@ -669,7 +669,7 @@ int64_t qemu_ftell_fast(QEMUFile *f)return ret; } -int64_t qemu_ftell (QEMUFile *f) +int64_t qemu_file_total_transferred (QEMUFile *f) {qemu_fflush (f);return f->total_transferred;migration/qemu-file.h +25
-2@@ -124,8 +124,44 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks);int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f); -int64_t qemu_ftell (QEMUFile *f); -int64_t qemu_ftell_fast (QEMUFile *f); + +/* +* qemu_file_total_transferred: +* +* Report the total number of bytes transferred with +* this file. +* +* For writable files, any pending buffers will be +* flushed, so the reported value will be equal to +* the number of bytes transferred on the wire. +* +* For readable files, the reported value will be +* equal to the number of bytes transferred on the +* wire. +* +* Returns: the total bytes transferred +*/ +int64_t qemu_file_total_transferred (QEMUFile *f); + +/* +* qemu_file_total_transferred_fast: +* +* Report the total number of bytes transferred with +* this file. +*
migration/qemu-file.h QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc); · line 161
Quoted 10 lines
migration/qemu-file.h +10
-0+* For writable files, no pending buffers will be +* flushed, but the reported value will include the +* size of any queued buffers, on top of the amount +* actually transferred. +* +* For readable files, the reported value will be +* equal to the number of bytes transferred on the +* wire. +* +* Returns: the total bytes transferred and queued
I think this would be clearer if it just said:
* qemu_file_total_transferred_fast:
As qemu_file_total_transferred except for writable files, where no flush is performed and the reported amount will include the size of any queued buffers, on top of the amount actually transferred.
Otherwise you're left eyeballing the two to try and spot the difference.
Dave
Quoted 56 lines
migration/qemu-file.h +3
-0+*/ +int64_t qemu_file_total_transferred_fast (QEMUFile *f); +/* * put_buffer without copying the buffer. * The buffer should be available till it is sent asynchronously. migration/savevm.c +3
-3@@ -916,9 +916,9 @@ static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se, {int64_t old_offset, size; - old_offset =qemu_ftell_fast (f); + old_offset =qemu_file_total_transferred_fast (f); se->ops->save_state (f, se->opaque); - size =qemu_ftell_fast (f) - old_offset; + size =qemu_file_total_transferred_fast (f) - old_offset;if (vmdesc) {json_writer_int64 (vmdesc,"size" , size);@@ -2887,7 +2887,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate, goto the_end; } ret =qemu_savevm_state (f, errp); - vm_state_size =qemu_ftell (f); + vm_state_size =qemu_file_total_transferred (f); ret2 =qemu_fclose (f);if (ret <0 ) { goto the_end;migration/vmstate.c +2
-2@@ -360,7 +360,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,void *curr_elem = first_elem + size * i;vmsd_desc_field_start (vmsd, vmdesc_loop, field, i, n_elems); - old_offset =qemu_ftell_fast (f); + old_offset =qemu_file_total_transferred_fast (f);if (field->flags &VMS_ARRAY_OF_POINTER ) {assert (curr_elem); curr_elem = *(void **)curr_elem;@@ -390,7 +390,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,return ret; } - written_bytes =qemu_ftell_fast (f) - old_offset; + written_bytes =qemu_file_total_transferred_fast (f) - old_offset;vmsd_desc_field_end (vmsd, vmdesc_loop, field, written_bytes, i);/* Compressed arrays only care about the first element */ Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 07/20] migration: rename qemu_update_position to qemu_file_credit_transfer
In reply to Daniel P. BerrangéQuoted 10 lines · * Daniel P. Berrangé ([email protected]) wrote:
The
qemu_update_positionmethod name gives the misleading impression that it is changing the current file offset. Most of the files are just streams, however, so there's no concept of a file offset in the general case.What this method is actually used for is to report on the number of bytes that have been transferred out of band from the main I/O methods. This new name better reflects this purpose.
Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 63 lines
--- migration/qemu-file.c | 4 ++-- migration/qemu-file.h | 8 +++++++- migration/ram.c | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-)migration/qemu-file.c +2
-2@@ -319,7 +319,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,if (ret !=RAM_SAVE_CONTROL_DELAYED && ret !=RAM_SAVE_CONTROL_NOT_SUPP ) {if (bytes_sent && *bytes_sent >0 ) { -qemu_update_position (f, *bytes_sent); +qemu_file_credit_transfer (f, *bytes_sent); }else if (ret <0 ) {qemu_file_set_error (f, ret); }@@ -374,7 +374,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return len; } -void qemu_update_position (QEMUFile *f,size_t size) +void qemu_file_credit_transfer (QEMUFile *f,size_t size) { f->total_transferred += size; }migration/qemu-file.h +7
-1@@ -186,7 +186,13 @@ int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src);*/ int qemu_peek_byte (QEMUFile *f,int offset);void qemu_file_skip (QEMUFile *f,int size); -void qemu_update_position (QEMUFile *f,size_t size); +/* +* qemu_file_credit_transfer: +* +* Report on a number of bytes that have been transferred +* out of band from the main file object I/O methods. +*/ +void qemu_file_credit_transfer (QEMUFile *f,size_t size);void qemu_file_reset_rate_limit (QEMUFile *f);void qemu_file_update_transfer (QEMUFile *f,int64_t len);void qemu_file_set_rate_limit (QEMUFile *f,int64_t new_rate);migration/ram.c +1
-1@@ -2301,7 +2301,7 @@ void acct_update_position(QEMUFile *f, size_t size, bool zero) }else { ram_counters.normal += pages;ram_transferred_add (size); -qemu_update_position (f, size); +qemu_file_credit_transfer (f, size); } }Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 07/20] migration: rename qemu_update_position to qemu_file_credit_transfer
In reply to Peter MaydellQuoted 22 lines · Peter Maydell
Quoted 21 lines · Daniel P. Berrangé
The
qemu_update_positionmethod name gives the misleading impression that it is changing the current file offset. Most of the files are just streams, however, so there's no concept of a file offset in the general case.What this method is actually used for is to report on the number of bytes that have been transferred out of band from the main I/O methods. This new name better reflects this purpose.
Signed-off-by Daniel P. Berrangé <[email protected]>int
qemu_peek_byte(QEMUFile *f, int offset);
voidqemu_file_skip(QEMUFile *f, int size);migration/qemu-file.h +6
-1-void qemu_update_position (QEMUFile *f,size_t size); +/* +* qemu_file_credit_transfer: +* +* Report on a number of bytes that have been transferred +* out of band from the main file object I/O methods. +*/
Quoted 8 lines
Quoted 4 lines
+void
qemu_file_credit_transfer(QEMUFile *f, size_t size);
voidqemu_file_reset_rate_limit(QEMUFile *f);
voidqemu_file_update_transfer(QEMUFile *f, int64_t len); voidqemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);What's the difference between "credit transfer" and "update transfer" ? The latter also seems to just be adding a number to a count of bytes-transferred...
The other method is merely related to the rate limiting, and so probably ought to have 'rate_limit' included in its name too.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 07/20] migration: rename qemu_update_position to qemu_file_credit_transfer
In reply to Daniel P. BerrangéQuoted 15 lines · Daniel P. Berrangé
The
qemu_update_positionmethod name gives the misleading impression that it is changing the current file offset. Most of the files are just streams, however, so there's no concept of a file offset in the general case.What this method is actually used for is to report on the number of bytes that have been transferred out of band from the main I/O methods. This new name better reflects this purpose.
Signed-off-by Daniel P. Berrangé <[email protected]>int
qemu_peek_byte(QEMUFile *f, int offset);
voidqemu_file_skip(QEMUFile *f, int size);migration/qemu-file.h +0
-1-void qemu_update_position (QEMUFile *f,size_t size);
migration/qemu-file.h int qemu_put_qemu_file(QEMUFile *f_des, QEMUFile *f_src); · line 198
Quoted 10 lines
migration/qemu-file.h +7
-0+/* +* qemu_file_credit_transfer: +* +* Report on a number of bytes that have been transferred +* out of band from the main file object I/O methods. +*/ +void qemu_file_credit_transfer (QEMUFile *f,size_t size);void qemu_file_reset_rate_limit (QEMUFile *f);void qemu_file_update_transfer (QEMUFile *f,int64_t len);void qemu_file_set_rate_limit (QEMUFile *f,int64_t new_rate);
What's the difference between "credit transfer" and "update transfer" ? The latter also seems to just be adding a number to a count of bytes-transferred...
-- PMM
Re: [PATCH 07/20] migration: rename qemu_update_position to qemu_file_credit_transfer
In reply to Daniel P. BerrangéQuoted 32 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 22 lines · Peter Maydell
Quoted 21 lines · Daniel P. Berrangé
The
qemu_update_positionmethod name gives the misleading impression that it is changing the current file offset. Most of the files are just streams, however, so there's no concept of a file offset in the general case.What this method is actually used for is to report on the number of bytes that have been transferred out of band from the main I/O methods. This new name better reflects this purpose.
Signed-off-by Daniel P. Berrangé <[email protected]>int
qemu_peek_byte(QEMUFile *f, int offset);
voidqemu_file_skip(QEMUFile *f, int size);migration/qemu-file.h +6
-1-void qemu_update_position (QEMUFile *f,size_t size); +/* +* qemu_file_credit_transfer: +* +* Report on a number of bytes that have been transferred +* out of band from the main file object I/O methods. +*/ Quoted 8 lines
Quoted 4 lines
+void
qemu_file_credit_transfer(QEMUFile *f, size_t size);
voidqemu_file_reset_rate_limit(QEMUFile *f);
voidqemu_file_update_transfer(QEMUFile *f, int64_t len); voidqemu_file_set_rate_limit(QEMUFile *f, int64_t new_rate);What's the difference between "credit transfer" and "update transfer" ? The latter also seems to just be adding a number to a count of bytes-transferred...
Quoted 2 lines
The other method is merely related to the rate limiting, and so probably ought to have '
rate_limit' included in its name too.
Bleh that's messy; I see update_transfer is used in the multifd case as well, so makes sense for stats only and not a position in a stream that only makes sense for a single fd.
(But now doesn't make any sense any more with these changes either)
Dave
Quoted 7 lines
With regards,
DanielSignature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 09/20] migration: convert savevm to use QIOChannelBlock for VMState
In reply to Daniel P. BerrangéQuoted 4 lines · * Daniel P. Berrangé ([email protected]) wrote:
With this change, all QEMUFile usage is backed by QIOChannel at last.
Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 71 lines
--- migration/savevm.c | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-)migration/savevm.c +4
-38@@ -35,6 +35,7 @@#include "migration/misc.h" #include "migration/register.h" #include "migration/global_state.h" +#include "migration/channel-block.h" #include "ram.h" #include "qemu-file-channel.h" #include "qemu-file.h" @@ -130,48 +131,13 @@ static struct mig_cmd_args {/***********************************************************/ /* savevm/loadvm support */ -static ssize_t block_writev_buffer (void *opaque,struct iovec *iov,int iovcnt, -int64_t pos,Error **errp) -{ -int ret; -QEMUIOVector qiov; - -qemu_iovec_init_external (&qiov, iov, iovcnt); - ret =bdrv_writev_vmstate (opaque, &qiov, pos); -if (ret <0 ) { -return ret; - } - -return qiov.size; -} - -static ssize_t block_get_buffer (void *opaque,uint8_t *buf,int64_t pos, -size_t size,Error **errp) -{ -return bdrv_load_vmstate (opaque, buf, pos, size); -} - -static int bdrv_fclose (void *opaque,Error **errp) -{ -return bdrv_flush (opaque); -} - -static const QEMUFileOps bdrv_read_ops = { - .get_buffer = block_get_buffer, - .close = bdrv_fclose -}; - -static const QEMUFileOps bdrv_write_ops = { - .writev_buffer = block_writev_buffer, - .close = bdrv_fclose -}; -static QEMUFile *qemu_fopen_bdrv (BlockDriverState *bs,int is_writable) {if (is_writable) { -return qemu_fopen_ops (bs, &bdrv_write_ops, false); +return qemu_fopen_channel_output (QIO_CHANNEL (qio_channel_block_new (bs))); + }else { +return qemu_fopen_channel_input (QIO_CHANNEL (qio_channel_block_new (bs))); } -return qemu_fopen_ops (bs, &bdrv_read_ops, false); }Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 10/20] migration: stop passing 'opaque' parameter to QEMUFile hooks
In reply to Daniel P. BerrangéQuoted 4 lines · * Daniel P. Berrangé ([email protected]) wrote:
The only user of the hooks is RDMA which provides a QIOChannel backed impl of QEMUFile. It can thus use the
qemu_file_get_ioc()method.Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 146 lines
--- migration/qemu-file.c | 8 ++++---- migration/qemu-file.h | 14 ++++++-------- migration/rdma.c | 19 ++++++++++--------- 3 files changed, 20 insertions(+), 21 deletions(-)migration/qemu-file.c +4
-4@@ -266,7 +266,7 @@ void ram_control_before_iterate(QEMUFile *f, uint64_t flags)int ret =0 ;if (f->hooks && f->hooks->before_ram_iterate) { - ret = f->hooks->before_ram_iterate (f, f->opaque, flags,NULL ); + ret = f->hooks->before_ram_iterate (f, flags,NULL );if (ret <0 ) {qemu_file_set_error (f, ret); }@@ -278,7 +278,7 @@ void ram_control_after_iterate(QEMUFile *f, uint64_t flags)int ret =0 ;if (f->hooks && f->hooks->after_ram_iterate) { - ret = f->hooks->after_ram_iterate (f, f->opaque, flags,NULL ); + ret = f->hooks->after_ram_iterate (f, flags,NULL );if (ret <0 ) {qemu_file_set_error (f, ret); }@@ -290,7 +290,7 @@ void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data)int ret = -EINVAL ;if (f->hooks && f->hooks->hook_ram_load) { - ret = f->hooks->hook_ram_load (f, f->opaque, flags, data); + ret = f->hooks->hook_ram_load (f, flags, data);if (ret <0 ) {qemu_file_set_error (f, ret); }@@ -310,7 +310,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset, uint64_t *bytes_sent) {if (f->hooks && f->hooks->save_page) { -int ret = f->hooks->save_page (f, f->opaque, block_offset, +int ret = f->hooks->save_page (f, block_offset, offset, size, bytes_sent);if (ret !=RAM_SAVE_CONTROL_NOT_SUPP ) { f->rate_limit_used += size;migration/qemu-file.h +6
-8@@ -65,11 +65,9 @@ typedef ssize_t (QEMUFileWritevBufferFunc)(void *opaque, struct iovec *iov,/* * This function provides hooks around different * stages of RAM migration. -* 'opaque' is the backend specific data in QEMUFile * 'data' is call specific data associated with the 'flags' value */ -typedef int (QEMURamHookFunc )(QEMUFile *f,void *opaque,uint64_t flags, -void *data); +typedef int (QEMURamHookFunc )(QEMUFile *f,uint64_t flags,void *data);/* * Constants used by ram_control_* hooks @@ -84,11 +82,11 @@ typedef int (QEMURamHookFunc)(QEMUFile *f, void *opaque, uint64_t flags,* This function allows override of where the RAM page * is saved (such as RDMA, for example.) */ -typedef size_t (QEMURamSaveFunc )(QEMUFile *f,void *opaque, -ram_addr_t block_offset, -ram_addr_t offset, -size_t size, -uint64_t *bytes_sent); +typedef size_t (QEMURamSaveFunc )(QEMUFile *f, +ram_addr_t block_offset, +ram_addr_t offset, +size_t size, +uint64_t *bytes_sent);/* * Return a QEMUFile for comms in the opposite direction migration/rdma.c +10
-9@@ -3256,11 +3256,11 @@ qio_channel_rdma_shutdown(QIOChannel *ioc,* sent. Usually, this will not be more than a few bytes of * the protocol because most transfers are sent asynchronously. */ -static size_t qemu_rdma_save_page (QEMUFile *f,void *opaque, +static size_t qemu_rdma_save_page (QEMUFile *f,ram_addr_t block_offset,ram_addr_t offset,size_t size,uint64_t *bytes_sent) { -QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (opaque); +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (qemu_file_get_ioc (f));RDMAContext *rdma;int ret;@@ -3872,14 +3872,15 @@ rdma_block_notification_handle(QIOChannelRDMA *rioc, const char *name)return 0 ; } -static int rdma_load_hook (QEMUFile *f,void *opaque,uint64_t flags,void *data) +static int rdma_load_hook (QEMUFile *f,uint64_t flags,void *data) { +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (qemu_file_get_ioc (f));switch (flags) {case RAM_CONTROL_BLOCK_REG : -return rdma_block_notification_handle (opaque, data); +return rdma_block_notification_handle (rioc, data);case RAM_CONTROL_HOOK : -return qemu_rdma_registration_handle (f, opaque); +return qemu_rdma_registration_handle (f, rioc);default :/* Shouldn't be called with any other values */ @@ -3887,10 +3888,10 @@ static int rdma_load_hook(QEMUFile *f, void *opaque, uint64_t flags, void *data) } } -static int qemu_rdma_registration_start (QEMUFile *f,void *opaque, +static int qemu_rdma_registration_start (QEMUFile *f,uint64_t flags,void *data) { -QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (opaque); +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (qemu_file_get_ioc (f));RDMAContext *rdma;RCU_READ_LOCK_GUARD ();@@ -3916,10 +3917,10 @@ static int qemu_rdma_registration_start(QEMUFile *f, void *opaque,* Inform dest that dynamic registrations are done for now. * First, flush writes, if any. */ -static int qemu_rdma_registration_stop (QEMUFile *f,void *opaque, +static int qemu_rdma_registration_stop (QEMUFile *f,uint64_t flags,void *data) { -QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (opaque); +QIOChannelRDMA *rioc =QIO_CHANNEL_RDMA (qemu_file_get_ioc (f));RDMAContext *rdma;RDMAControlHeader head = { .len =0 , .repeat =1 };int ret =0 ;Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 11/20] migration: hardcode assumption that QEMUFile is backed with QIOChannel
In reply to Daniel P. BerrangéQuoted 5 lines · * Daniel P. Berrangé ([email protected]) wrote:
The only callers of
qemu_fopen_opspass 'true' for the 'has_ioc' parameter, so hardcode this assumption in QEMUFile, by passing in the QIOChannel object as a non-opaque parameter.Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 153 lines
--- migration/qemu-file-channel.c | 4 ++-- migration/qemu-file.c | 35 +++++++++++++++++------------------ migration/qemu-file.h | 2 +- 3 files changed, 20 insertions(+), 21 deletions(-)migration/qemu-file-channel.c +2
-2@@ -184,11 +184,11 @@ static const QEMUFileOps channel_output_ops = {QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc) {object_ref (OBJECT (ioc)); -return qemu_fopen_ops (ioc, &channel_input_ops, true); +return qemu_fopen_ops (ioc, &channel_input_ops); }QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc) {object_ref (OBJECT (ioc)); -return qemu_fopen_ops (ioc, &channel_output_ops, true); +return qemu_fopen_ops (ioc, &channel_output_ops); }migration/qemu-file.c +17
-18@@ -37,7 +37,7 @@struct QEMUFile {const QEMUFileOps *ops;const QEMUFileHooks *hooks; -void *opaque; +QIOChannel *ioc;/* * Maximum amount of data in bytes to transfer during one @@ -65,8 +65,6 @@ struct QEMUFile {Error *last_error_obj;/* has the file has been shutdown */ bool shutdown; -/* Whether opaque points to a QIOChannel */ -bool has_ioc; };/* @@ -81,7 +79,7 @@ int qemu_file_shutdown(QEMUFile *f)if (!f->ops->shut_down) {return -ENOSYS ; } - ret = f->ops->shut_down (f->opaque, true, true,NULL ); + ret = f->ops->shut_down (f->ioc, true, true,NULL );if (!f->last_error) {qemu_file_set_error (f, -EIO );@@ -98,7 +96,7 @@ QEMUFile *qemu_file_get_return_path(QEMUFile *f)if (!f->ops->get_return_path) {return NULL ; } -return f->ops->get_return_path (f->opaque); +return f->ops->get_return_path (f->ioc); }bool qemu_file_mode_is_not_valid (const char *mode)@@ -113,15 +111,15 @@ bool qemu_file_mode_is_not_valid(const char *mode)return false; } -QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops,bool has_ioc) +QEMUFile *qemu_fopen_ops (QIOChannel *ioc,const QEMUFileOps *ops) {QEMUFile *f; f =g_new0 (QEMUFile,1 ); - f->opaque = opaque; + f->ioc = ioc; f->ops = ops; - f->has_ioc = has_ioc; +return f; }@@ -242,7 +240,7 @@ void qemu_fflush(QEMUFile *f) }if (f->iovcnt >0 ) { expect =iov_size (f->iov, f->iovcnt); - ret = f->ops->writev_buffer (f->opaque, f->iov, f->iovcnt, f->total_transferred, + ret = f->ops->writev_buffer (f->ioc, f->iov, f->iovcnt, f->total_transferred, &local_error);qemu_iovec_release_ram (f);@@ -358,7 +356,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return 0 ; } - len = f->ops->get_buffer (f->opaque, f->buf + pending, f->total_transferred, + len = f->ops->get_buffer (f->ioc, f->buf + pending, f->total_transferred,IO_BUF_SIZE - pending, &local_error);if (len >0 ) { f->buf_size += len;@@ -394,7 +392,7 @@ int qemu_fclose(QEMUFile *f) ret =qemu_file_get_error (f);if (f->ops->close) { -int ret2 = f->ops->close (f->opaque,NULL ); +int ret2 = f->ops->close (f->ioc,NULL );if (ret >=0 ) { ret = ret2; }@@ -861,18 +859,19 @@ void qemu_put_counted_string(QEMUFile *f, const char *str)void qemu_file_set_blocking (QEMUFile *f,bool block) {if (f->ops->set_blocking) { - f->ops->set_blocking (f->opaque, block,NULL ); + f->ops->set_blocking (f->ioc, block,NULL ); } }/* -* Return the ioc object if it's a migration channel. Note: it can return NULL -* for callers passing in a non-migration qemufile. E.g. see qemu_fopen_bdrv() -* and its usage in e.g. load_snapshot(). So we need to check against NULL -* before using it. If without the check, migration_incoming_state_destroy() -* could fail for load_snapshot(). +* qemu_file_get_ioc: +* +* Get the ioc object for the file, without incrementing +* the reference count. +* +* Returns: the ioc object */ QIOChannel *qemu_file_get_ioc (QEMUFile *file) { -return file->has_ioc ?QIO_CHANNEL (file->opaque) :NULL ; +return file->ioc; }migration/qemu-file.h +1
-1@@ -118,7 +118,7 @@ typedef struct QEMUFileHooks {QEMURamSaveFunc *save_page; } QEMUFileHooks; -QEMUFile *qemu_fopen_ops (void *opaque,const QEMUFileOps *ops,bool has_ioc); +QEMUFile *qemu_fopen_ops (QIOChannel *ioc,const QEMUFileOps *ops);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks);int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 14/20] migration: remove the QEMUFileOps 'shut_down' callback
In reply to Daniel P. BerrangéQuoted 73 lines · * Daniel P. Berrangé ([email protected]) wrote:
This directly implements the shutdown logic using QIOChannel APIs.
Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/qemu-file-channel.c | 27 --------------------------- migration/qemu-file.c | 10 +++++++--- migration/qemu-file.h | 10 ---------- 3 files changed, 7 insertions(+), 40 deletions(-)migration/qemu-file-channel.c +0
-27@@ -112,31 +112,6 @@ static int channel_close(void *opaque, Error **errp) } -static int channel_shutdown (void *opaque, -bool rd, -bool wr, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); - -if (qio_channel_has_feature (ioc, -QIO_CHANNEL_FEATURE_SHUTDOWN )) { -QIOChannelShutdown mode; -if (rd && wr) { - mode =QIO_CHANNEL_SHUTDOWN_BOTH ; - }else if (rd) { - mode =QIO_CHANNEL_SHUTDOWN_READ ; - }else { - mode =QIO_CHANNEL_SHUTDOWN_WRITE ; - } -if (qio_channel_shutdown (ioc, mode, errp) <0 ) { -return -EIO ; - } - } -return 0 ; -} - -static int channel_set_blocking (void *opaque,bool enabled,Error **errp)@@ -166,7 +141,6 @@ static QEMUFile *channel_get_output_return_path(void *opaque)static const QEMUFileOps channel_input_ops = { .get_buffer = channel_get_buffer, .close = channel_close, - .shut_down = channel_shutdown, .set_blocking = channel_set_blocking, .get_return_path = channel_get_input_return_path, };@@ -175,7 +149,6 @@ static const QEMUFileOps channel_input_ops = {static const QEMUFileOps channel_output_ops = { .writev_buffer = channel_writev_buffer, .close = channel_close, - .shut_down = channel_shutdown, .set_blocking = channel_set_blocking, .get_return_path = channel_get_output_return_path, };migration/qemu-file.c +1
-1@@ -74,13 +74,17 @@ struct QEMUFile {*/ int qemu_file_shutdown (QEMUFile *f) { -int ret; +int ret =0 ; f->shutdown = true;
migration/qemu-file.c struct QEMUFile { · line 87
Quoted 10 lines
migration/qemu-file.c +6
-2-if (!f->ops->shut_down) { +if (!qio_channel_has_feature (f->ioc, +QIO_CHANNEL_FEATURE_SHUTDOWN )) {return -ENOSYS ; } - ret = f->ops->shut_down (f->ioc, true, true,NULL ); + +if (qio_channel_shutdown (f->ioc,QIO_CHANNEL_SHUTDOWN_BOTH ,NULL ) <0 ) { + ret = -EIO ; + }
OK, so this is following the code you're flattening; so:
I wonder if there's any reason it doesn't just pass the return value through to ret rather
than flattening it to -EIO?
Quoted 32 lines
migration/qemu-file.c +0
-0if (!f->last_error) {qemu_file_set_error (f, -EIO );migration/qemu-file.h +0
-10@@ -89,22 +89,12 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,*/ typedef QEMUFile *(QEMURetPathFunc )(void *opaque); -/* -* Stop any read or write (depending on flags) on the underlying -* transport on the QEMUFile. -* Existing blocking reads/writes must be woken -* Returns 0 on success, -err on error -*/ -typedef int (QEMUFileShutdownFunc )(void *opaque,bool rd,bool wr, -Error **errp); -typedef struct QEMUFileOps {QEMUFileGetBufferFunc *get_buffer;QEMUFileCloseFunc *close;QEMUFileSetBlocking *set_blocking;QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path; -QEMUFileShutdownFunc *shut_down; }QEMUFileOps ; typedef struct QEMUFileHooks {Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 12/20] migration: introduce new constructors for QEMUFile
In reply to Daniel P. BerrangéQuoted 5 lines · * Daniel P. Berrangé ([email protected]) wrote:
Prepare for the elimination of QEMUFileOps by introducing a pair of new constructors. This lets us distinguish between an input and output file object explicitly rather than via the existance of specific callbacks.
Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 95 lines
--- migration/qemu-file-channel.c | 4 ++-- migration/qemu-file.c | 18 ++++++++++++++++-- migration/qemu-file.h | 3 ++- 3 files changed, 20 insertions(+), 5 deletions(-)migration/qemu-file-channel.c +2
-2@@ -184,11 +184,11 @@ static const QEMUFileOps channel_output_ops = {QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc) {object_ref (OBJECT (ioc)); -return qemu_fopen_ops (ioc, &channel_input_ops); +return qemu_file_new_input (ioc, &channel_input_ops); }QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc) {object_ref (OBJECT (ioc)); -return qemu_fopen_ops (ioc, &channel_output_ops); +return qemu_file_new_output (ioc, &channel_output_ops); }migration/qemu-file.c +16
-2@@ -38,6 +38,7 @@ struct QEMUFile {const QEMUFileOps *ops;const QEMUFileHooks *hooks;QIOChannel *ioc; +bool is_writable;/* * Maximum amount of data in bytes to transfer during one @@ -111,7 +112,9 @@ bool qemu_file_mode_is_not_valid(const char *mode)return false; } -QEMUFile *qemu_fopen_ops (QIOChannel *ioc,const QEMUFileOps *ops) +static QEMUFile *qemu_file_new_impl (QIOChannel *ioc, +const QEMUFileOps *ops, +bool is_writable) {QEMUFile *f;@@ -119,10 +122,21 @@ QEMUFile *qemu_fopen_ops(QIOChannel *ioc, const QEMUFileOps *ops) f->ioc = ioc; f->ops = ops; + f->is_writable = is_writable;return f; } +QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops) +{ +return qemu_file_new_impl (ioc, ops, true); +} + +QEMUFile *qemu_file_new_input (QIOChannel *ioc,const QEMUFileOps *ops) +{ +return qemu_file_new_impl (ioc, ops, false); +} +void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks) {@@ -181,7 +195,7 @@ void qemu_file_set_error(QEMUFile *f, int ret)bool qemu_file_is_writable (QEMUFile *f) { -return f->ops->writev_buffer; +return f->is_writable; }static void qemu_iovec_release_ram (QEMUFile *f)migration/qemu-file.h +2
-1@@ -118,7 +118,8 @@ typedef struct QEMUFileHooks {QEMURamSaveFunc *save_page; } QEMUFileHooks; -QEMUFile *qemu_fopen_ops (QIOChannel *ioc,const QEMUFileOps *ops); +QEMUFile *qemu_file_new_input (QIOChannel *ioc,const QEMUFileOps *ops); +QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks);int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 15/20] migration: remove the QEMUFileOps 'set_blocking' callback
In reply to Daniel P. BerrangéQuoted 3 lines · * Daniel P. Berrangé ([email protected]) wrote:
This directly implements the
set_blockinglogic using QIOChannel APIs.Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 86 lines
--- migration/qemu-file-channel.c | 14 -------------- migration/qemu-file.c | 4 +--- migration/qemu-file.h | 5 ----- 3 files changed, 1 insertion(+), 22 deletions(-)migration/qemu-file-channel.c +0
-14@@ -112,18 +112,6 @@ static int channel_close(void *opaque, Error **errp) } -static int channel_set_blocking (void *opaque, -bool enabled, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); - -if (qio_channel_set_blocking (ioc, enabled, errp) <0 ) { -return -1 ; - } -return 0 ; -} -static QEMUFile *channel_get_input_return_path (void *opaque) {QIOChannel *ioc =QIO_CHANNEL (opaque);@@ -141,7 +129,6 @@ static QEMUFile *channel_get_output_return_path(void *opaque)static const QEMUFileOps channel_input_ops = { .get_buffer = channel_get_buffer, .close = channel_close, - .set_blocking = channel_set_blocking, .get_return_path = channel_get_input_return_path, };@@ -149,7 +136,6 @@ static const QEMUFileOps channel_input_ops = {static const QEMUFileOps channel_output_ops = { .writev_buffer = channel_writev_buffer, .close = channel_close, - .set_blocking = channel_set_blocking, .get_return_path = channel_get_output_return_path, };migration/qemu-file.c +1
-3@@ -876,9 +876,7 @@ void qemu_put_counted_string(QEMUFile *f, const char *str)*/ void qemu_file_set_blocking (QEMUFile *f,bool block) { -if (f->ops->set_blocking) { - f->ops->set_blocking (f->ioc, block,NULL ); - } +qio_channel_set_blocking (f->ioc, block,NULL ); }/* migration/qemu-file.h +0
-5@@ -46,10 +46,6 @@ typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,*/ typedef int (QEMUFileCloseFunc )(void *opaque,Error **errp); -/* Called to change the blocking mode of the file -*/ -typedef int (QEMUFileSetBlocking )(void *opaque,bool enabled,Error **errp); -/* * This function writes an iovec to file. The handler must write all * of the data or return a negative errno value. @@ -92,7 +88,6 @@ typedef QEMUFile *(QEMURetPathFunc)(void *opaque);typedef struct QEMUFileOps {QEMUFileGetBufferFunc *get_buffer;QEMUFileCloseFunc *close; -QEMUFileSetBlocking *set_blocking;QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path; }QEMUFileOps ;Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 19/20] migration: remove the QEMUFileOps 'get_return_path' callback
In reply to Daniel P. BerrangéQuoted 3 lines · * Daniel P. Berrangé ([email protected]) wrote:
This directly implements the
get_return_pathlogic using QIOChannel APIs.Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 99 lines
--- migration/qemu-file-channel.c | 16 ---------------- migration/qemu-file.c | 22 ++++++++++------------ migration/qemu-file.h | 6 ------ 3 files changed, 10 insertions(+), 34 deletions(-)migration/qemu-file-channel.c +0
-16@@ -32,27 +32,11 @@#include "yank_functions.h" -static QEMUFile *channel_get_input_return_path (void *opaque) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); - -return qemu_fopen_channel_output (ioc); -} - -static QEMUFile *channel_get_output_return_path (void *opaque) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); - -return qemu_fopen_channel_input (ioc); -} -static const QEMUFileOps channel_input_ops = { - .get_return_path = channel_get_input_return_path, };static const QEMUFileOps channel_output_ops = { - .get_return_path = channel_get_output_return_path, };migration/qemu-file.c +10
-12@@ -92,18 +92,6 @@ int qemu_file_shutdown(QEMUFile *f)return ret; } -/* -* Result: QEMUFile* for a 'return path' for comms in the opposite direction -* NULL if not available -*/ -QEMUFile *qemu_file_get_return_path (QEMUFile *f) -{ -if (!f->ops->get_return_path) { -return NULL ; - } -return f->ops->get_return_path (f->ioc); -} -bool qemu_file_mode_is_not_valid (const char *mode) { if (mode == NULL ||@@ -131,6 +119,16 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc,return f; } +/* +* Result: QEMUFile* for a 'return path' for comms in the opposite direction +* NULL if not available +*/ +QEMUFile *qemu_file_get_return_path (QEMUFile *f) +{ +object_ref (f->ioc); +return qemu_file_new_impl (f->ioc, f->ops, !f->is_writable); +} +QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops) {return qemu_file_new_impl (ioc, ops, true);migration/qemu-file.h +0
-6@@ -55,13 +55,7 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,size_t size, uint64_t *bytes_sent); -/* -* Return a QEMUFile for comms in the opposite direction -*/ -typedef QEMUFile *(QEMURetPathFunc )(void *opaque); -typedef struct QEMUFileOps { -QEMURetPathFunc *get_return_path; }QEMUFileOps ; typedef struct QEMUFileHooks {Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 20/20] migration: remove the QEMUFileOps abstraction
In reply to Dr. David Alan GilbertQuoted 8 lines · Dr. David Alan Gilbert
Quoted 4 lines · * Daniel P. Berrangé ([email protected]) wrote:
Now that all QEMUFile callbacks are removed, the entire concept can be deleted.
Signed-off-by Daniel P. Berrangé <[email protected]>I think that's OK, there's one nit - you remove
qemu_get_fdfrom one of the headers; I think that probably belongs in an earlier patch.
Oh should probably be squashed back into patch 13, which removes the corresponding unused callback typedef.
Quoted 434 lines
Other than that,
Reviewed-by Dr. David Alan Gilbert <[email protected]>Quoted 428 lines
--- migration/channel.c | 4 +-- migration/colo.c | 5 ++-- migration/meson.build | 1 - migration/migration.c | 7 ++--- migration/qemu-file-channel.c | 53 ----------------------------------- migration/qemu-file-channel.h | 32 --------------------- migration/qemu-file.c | 20 ++++++------- migration/qemu-file.h | 8 ++---- migration/ram.c | 3 +- migration/rdma.c | 5 ++-- migration/savevm.c | 11 ++++---- tests/unit/test-vmstate.c | 5 ++-- 12 files changed, 27 insertions(+), 127 deletions(-) delete mode 100644 migration/qemu-file-channel.c delete mode 100644 migration/qemu-file-channel.hmigration/channel.c +2
-2@@ -14,7 +14,7 @@#include "channel.h" #include "tls.h" #include "migration.h" -#include "qemu-file-channel.h" +#include "qemu-file.h" #include "trace.h" #include "qapi/error.h" #include "io/channel-tls.h" @@ -85,7 +85,7 @@ void migration_channel_connect(MigrationState *s,return ; } }else { -QEMUFile *f =qemu_fopen_channel_output (ioc); +QEMUFile *f =qemu_file_new_output (ioc);migration_ioc_register_yank (ioc);migration/colo.c +2
-3@@ -14,7 +14,6 @@#include "sysemu/sysemu.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" -#include "qemu-file-channel.h" #include "migration.h" #include "qemu-file.h" #include "savevm.h" @@ -559,7 +558,7 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } bioc =qio_channel_buffer_new (COLO_BUFFER_BASE_SIZE ); - fb =qemu_fopen_channel_output (QIO_CHANNEL (bioc)); + fb =qemu_file_new_output (QIO_CHANNEL (bioc));object_unref (OBJECT (bioc));qemu_mutex_lock_iothread ();@@ -873,7 +872,7 @@ void *colo_process_incoming_thread(void *opaque)colo_incoming_start_dirty_log (); bioc =qio_channel_buffer_new (COLO_BUFFER_BASE_SIZE ); - fb =qemu_fopen_channel_input (QIO_CHANNEL (bioc)); + fb =qemu_file_new_input (QIO_CHANNEL (bioc));object_unref (OBJECT (bioc));qemu_mutex_lock_iothread ();migration/meson.build +0
-1@@ -4,7 +4,6 @@ migration_files = files( 'xbzrle.c', 'vmstate-types.c', 'vmstate.c', - 'qemu-file-channel.c', 'qemu-file.c', 'yank_functions.c', )migration/migration.c +3
-4@@ -30,7 +30,6 @@#include "migration/misc.h" #include "migration.h" #include "savevm.h" -#include "qemu-file-channel.h" #include "qemu-file.h" #include "migration/vmstate.h" #include "block/block.h" @@ -722,7 +721,7 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp)if (!mis->from_src_file) {/* The first connection (multifd may have multiple) */ -QEMUFile *f =qemu_fopen_channel_input (ioc); +QEMUFile *f =qemu_file_new_input (ioc);if (!migration_incoming_setup (f, errp)) {return ;@@ -3081,7 +3080,7 @@ static int postcopy_start(MigrationState *ms)*/ bioc =qio_channel_buffer_new (4096 );qio_channel_set_name (QIO_CHANNEL (bioc),"migration-postcopy-buffer" ); - fb =qemu_fopen_channel_output (QIO_CHANNEL (bioc)); + fb =qemu_file_new_output (QIO_CHANNEL (bioc));object_unref (OBJECT (bioc));/* @@ -3970,7 +3969,7 @@ static void *bg_migration_thread(void *opaque)*/ s->bioc =qio_channel_buffer_new (512 *1024 );qio_channel_set_name (QIO_CHANNEL (s->bioc),"vmstate-buffer" ); - fb =qemu_fopen_channel_output (QIO_CHANNEL (s->bioc)); + fb =qemu_file_new_output (QIO_CHANNEL (s->bioc));object_unref (OBJECT (s->bioc));update_iteration_initial_status (s);migration/qemu-file-channel.c deleted +0
-53@@ -1,53 +0,0 @@ -/* -* QEMUFile backend for QIOChannel objects -* -* Copyright (c) 2015-2016 Red Hat, Inc -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#include "qemu/osdep.h" -#include "qemu-file-channel.h" -#include "qemu-file.h" -#include "io/channel-socket.h" -#include "io/channel-tls.h" -#include "qemu/iov.h" -#include "qemu/yank.h" -#include "yank_functions.h" - - -static const QEMUFileOps channel_input_ops = { -}; - - -static const QEMUFileOps channel_output_ops = { -}; - - -QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc) -{ -object_ref (OBJECT (ioc)); -return qemu_file_new_input (ioc, &channel_input_ops); -} - -QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc) -{ -object_ref (OBJECT (ioc)); -return qemu_file_new_output (ioc, &channel_output_ops); -}migration/qemu-file-channel.h deleted +0
-32@@ -1,32 +0,0 @@ -/* -* QEMUFile backend for QIOChannel objects -* -* Copyright (c) 2015-2016 Red Hat, Inc -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#ifndef QEMU_FILE_CHANNEL_H -#define QEMU_FILE_CHANNEL_H - -#include "io/channel.h" - -QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc); -QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc); -#endif migration/qemu-file.c +8
-12@@ -35,7 +35,6 @@#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)struct QEMUFile { -const QEMUFileOps *ops;const QEMUFileHooks *hooks;QIOChannel *ioc;bool is_writable;@@ -104,16 +103,14 @@ bool qemu_file_mode_is_not_valid(const char *mode)return false; } -static QEMUFile *qemu_file_new_impl (QIOChannel *ioc, -const QEMUFileOps *ops, -bool is_writable) +static QEMUFile *qemu_file_new_impl (QIOChannel *ioc,bool is_writable) {QEMUFile *f; f =g_new0 (QEMUFile,1 ); +object_ref (ioc); f->ioc = ioc; - f->ops = ops; f->is_writable = is_writable;return f;@@ -125,21 +122,19 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc,*/ QEMUFile *qemu_file_get_return_path (QEMUFile *f) { -object_ref (f->ioc); -return qemu_file_new_impl (f->ioc, f->ops, !f->is_writable); +return qemu_file_new_impl (f->ioc, !f->is_writable); } -QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops) +QEMUFile *qemu_file_new_output (QIOChannel *ioc) { -return qemu_file_new_impl (ioc, ops, true); +return qemu_file_new_impl (ioc, true); } -QEMUFile *qemu_file_new_input (QIOChannel *ioc,const QEMUFileOps *ops) +QEMUFile *qemu_file_new_input (QIOChannel *ioc) { -return qemu_file_new_impl (ioc, ops, false); +return qemu_file_new_impl (ioc, false); } -void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks) { f->hooks = hooks;@@ -235,6 +230,7 @@ static void qemu_iovec_release_ram(QEMUFile *f)memset (f->may_free,0 ,sizeof (f->may_free)); } +/** * Flushes QEMUFile buffer * migration/qemu-file.h +2
-6@@ -55,9 +55,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,size_t size, uint64_t *bytes_sent); -typedef struct QEMUFileOps { -}QEMUFileOps ; - typedef struct QEMUFileHooks { QEMURamHookFunc *before_ram_iterate; QEMURamHookFunc *after_ram_iterate;@@ -65,10 +62,9 @@ typedef struct QEMUFileHooks {QEMURamSaveFunc *save_page; } QEMUFileHooks; -QEMUFile *qemu_file_new_input (QIOChannel *ioc,const QEMUFileOps *ops); -QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops); +QEMUFile *qemu_file_new_input (QIOChannel *ioc); +QEMUFile *qemu_file_new_output (QIOChannel *ioc);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks); -int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);/* migration/ram.c +1
-2@@ -38,7 +38,6 @@#include "migration.h" #include "migration/register.h" #include "migration/misc.h" -#include "migration/qemu-file-channel.h" #include "qemu-file.h" #include "postcopy-ram.h" #include "page_cache.h" @@ -569,7 +568,7 @@ static int compress_threads_save_setup(void)/* comp_param[i].file is just used as a dummy buffer to save data, * set its ops to empty. */ - comp_param[i].file =qemu_fopen_channel_output ( + comp_param[i].file =qemu_file_new_output (QIO_CHANNEL (qio_channel_null_new ())); comp_param[i].done = true; comp_param[i].quit = false;migration/rdma.c +2
-3@@ -21,7 +21,6 @@#include "migration.h" #include "qemu-file.h" #include "ram.h" -#include "qemu-file-channel.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/module.h" @@ -4093,12 +4092,12 @@ static QEMUFile *qemu_fopen_rdma(RDMAContext *rdma, const char *mode) rioc =QIO_CHANNEL_RDMA (object_new (TYPE_QIO_CHANNEL_RDMA ));if (mode[0 ] =='w' ) { - rioc->file =qemu_fopen_channel_output (QIO_CHANNEL (rioc)); + rioc->file =qemu_file_new_output (QIO_CHANNEL (rioc)); rioc->rdmaout = rdma; rioc->rdmain = rdma->return_path;qemu_file_set_hooks (rioc->file, &rdma_write_hooks); }else { - rioc->file =qemu_fopen_channel_input (QIO_CHANNEL (rioc)); + rioc->file =qemu_file_new_input (QIO_CHANNEL (rioc)); rioc->rdmain = rdma; rioc->rdmaout = rdma->return_path;qemu_file_set_hooks (rioc->file, &rdma_read_hooks);migration/savevm.c +5
-6@@ -37,7 +37,6 @@#include "migration/global_state.h" #include "migration/channel-block.h" #include "ram.h" -#include "qemu-file-channel.h" #include "qemu-file.h" #include "savevm.h" #include "postcopy-ram.h" @@ -134,9 +133,9 @@ static struct mig_cmd_args {static QEMUFile *qemu_fopen_bdrv (BlockDriverState *bs,int is_writable) {if (is_writable) { -return qemu_fopen_channel_output (QIO_CHANNEL (qio_channel_block_new (bs))); +return qemu_file_new_output (QIO_CHANNEL (qio_channel_block_new (bs))); }else { -return qemu_fopen_channel_input (QIO_CHANNEL (qio_channel_block_new (bs))); +return qemu_file_new_input (QIO_CHANNEL (qio_channel_block_new (bs))); } }@@ -2159,7 +2158,7 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis) bioc->usage += length;trace_loadvm_handle_cmd_packaged_received (ret); -QEMUFile *packf =qemu_fopen_channel_input (QIO_CHANNEL (bioc)); +QEMUFile *packf =qemu_file_new_input (QIO_CHANNEL (bioc)); ret =qemu_loadvm_state_main (packf, mis);trace_loadvm_handle_cmd_packaged_main (ret);@@ -2917,7 +2916,7 @@ void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live, goto the_end; }qio_channel_set_name (QIO_CHANNEL (ioc),"migration-xen-save-state" ); - f =qemu_fopen_channel_output (QIO_CHANNEL (ioc)); + f =qemu_file_new_output (QIO_CHANNEL (ioc));object_unref (OBJECT (ioc)); ret =qemu_save_device_state (f);if (ret <0 ||qemu_fclose (f) <0 ) {@@ -2964,7 +2963,7 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp)return ; }qio_channel_set_name (QIO_CHANNEL (ioc),"migration-xen-load-state" ); - f =qemu_fopen_channel_input (QIO_CHANNEL (ioc)); + f =qemu_file_new_input (QIO_CHANNEL (ioc));object_unref (OBJECT (ioc)); ret =qemu_loadvm_state (f);tests/unit/test-vmstate.c +1
-2@@ -28,7 +28,6 @@#include "migration/vmstate.h" #include "migration/qemu-file-types.h" #include "../migration/qemu-file.h" -#include "../migration/qemu-file-channel.h" #include "../migration/savevm.h" #include "qemu/coroutine.h" #include "qemu/module.h" @@ -52,9 +51,9 @@ static QEMUFile *open_test_file(bool write) } ioc =QIO_CHANNEL (qio_channel_file_new_fd (fd));if (write) { - f =qemu_fopen_channel_output (ioc); + f =qemu_file_new_output (ioc); }else {
Quoted 11 lines
Quoted 8 lines
tests/unit/test-vmstate.c +1
-1- f =qemu_fopen_channel_input (ioc); + f =qemu_file_new_input (ioc); }object_unref (OBJECT (ioc));return f;Signature · 1 line
2.36.1Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 13/20] migration: remove unused QEMUFileGetFD typedef
In reply to Daniel P. BerrangéQuoted 1 line · * Daniel P. Berrangé ([email protected]) wrote:
Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 22 lines
--- migration/qemu-file.h | 4 ---- 1 file changed, 4 deletions(-)migration/qemu-file.h +0
-4@@ -46,10 +46,6 @@ typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf,*/ typedef int (QEMUFileCloseFunc )(void *opaque,Error **errp); -/* Called to return the OS file descriptor associated to the QEMUFile. -*/ -typedef int (QEMUFileGetFD )(void *opaque); -/* Called to change the blocking mode of the file */ typedef int (QEMUFileSetBlocking )(void *opaque,bool enabled,Error **errp);Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 16/20] migration: remove the QEMUFileOps 'close' callback
In reply to Daniel P. BerrangéQuoted 3 lines · * Daniel P. Berrangé ([email protected]) wrote:
This directly implements the close logic using QIOChannel APIs.
Signed-off-by Daniel P. Berrangé <[email protected]>
Quoted 100 lines
--- migration/qemu-file-channel.c | 12 ------------ migration/qemu-file.c | 12 ++++++------ migration/qemu-file.h | 10 ---------- 3 files changed, 6 insertions(+), 28 deletions(-)migration/qemu-file-channel.c +0
-12@@ -102,16 +102,6 @@ static ssize_t channel_get_buffer(void *opaque, } -static int channel_close (void *opaque,Error **errp) -{ -int ret; -QIOChannel *ioc =QIO_CHANNEL (opaque); - ret =qio_channel_close (ioc, errp); -object_unref (OBJECT (ioc)); -return ret; -} - -static QEMUFile *channel_get_input_return_path (void *opaque) {QIOChannel *ioc =QIO_CHANNEL (opaque);@@ -128,14 +118,12 @@ static QEMUFile *channel_get_output_return_path(void *opaque)static const QEMUFileOps channel_input_ops = { .get_buffer = channel_get_buffer, - .close = channel_close, .get_return_path = channel_get_input_return_path, };static const QEMUFileOps channel_output_ops = { .writev_buffer = channel_writev_buffer, - .close = channel_close, .get_return_path = channel_get_output_return_path, };migration/qemu-file.c +6
-6@@ -405,16 +405,16 @@ void qemu_file_credit_transfer(QEMUFile *f, size_t size)*/ int qemu_fclose (QEMUFile *f) { -int ret; +int ret, ret2;qemu_fflush (f); ret =qemu_file_get_error (f); -if (f->ops->close) { -int ret2 = f->ops->close (f->ioc,NULL ); -if (ret >=0 ) { - ret = ret2; - } + ret2 =qio_channel_close (f->ioc,NULL ); +if (ret >=0 ) { + ret = ret2; } +g_clear_pointer (&f->ioc, object_unref); +/* If any error was spotted before closing, we should report it * instead of the close() return value. */ migration/qemu-file.h +0
-10@@ -37,15 +37,6 @@ typedef ssize_t (QEMUFileGetBufferFunc)(void *opaque, uint8_t *buf, int64_t pos, size_t size, Error **errp); -/* Close a file -* -* Return negative error number on error, 0 or positive value on success. -* -* The meaning of return value on success depends on the specific back-end being -* used. -*/ -typedef int (QEMUFileCloseFunc )(void *opaque,Error **errp); -/* * This function writes an iovec to file. The handler must write all * of the data or return a negative errno value. @@ -87,7 +78,6 @@ typedef QEMUFile *(QEMURetPathFunc)(void *opaque);typedef struct QEMUFileOps {QEMUFileGetBufferFunc *get_buffer; -QEMUFileCloseFunc *close;QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path; }QEMUFileOps ;Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 14/20] migration: remove the QEMUFileOps 'shut_down' callback
In reply to Dr. David Alan GilbertQuoted 87 lines · Dr. David Alan Gilbert
Quoted 73 lines · * Daniel P. Berrangé ([email protected]) wrote:
This directly implements the shutdown logic using QIOChannel APIs.
Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/qemu-file-channel.c | 27 --------------------------- migration/qemu-file.c | 10 +++++++--- migration/qemu-file.h | 10 ---------- 3 files changed, 7 insertions(+), 40 deletions(-)migration/qemu-file-channel.c +0
-27@@ -112,31 +112,6 @@ static int channel_close(void *opaque, Error **errp) } -static int channel_shutdown (void *opaque, -bool rd, -bool wr, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); - -if (qio_channel_has_feature (ioc, -QIO_CHANNEL_FEATURE_SHUTDOWN )) { -QIOChannelShutdown mode; -if (rd && wr) { - mode =QIO_CHANNEL_SHUTDOWN_BOTH ; - }else if (rd) { - mode =QIO_CHANNEL_SHUTDOWN_READ ; - }else { - mode =QIO_CHANNEL_SHUTDOWN_WRITE ; - } -if (qio_channel_shutdown (ioc, mode, errp) <0 ) { -return -EIO ; - } - } -return 0 ; -} - -static int channel_set_blocking (void *opaque,bool enabled,Error **errp)@@ -166,7 +141,6 @@ static QEMUFile *channel_get_output_return_path(void *opaque)static const QEMUFileOps channel_input_ops = { .get_buffer = channel_get_buffer, .close = channel_close, - .shut_down = channel_shutdown, .set_blocking = channel_set_blocking, .get_return_path = channel_get_input_return_path, };@@ -175,7 +149,6 @@ static const QEMUFileOps channel_input_ops = {static const QEMUFileOps channel_output_ops = { .writev_buffer = channel_writev_buffer, .close = channel_close, - .shut_down = channel_shutdown, .set_blocking = channel_set_blocking, .get_return_path = channel_get_output_return_path, };migration/qemu-file.c +1
-1@@ -74,13 +74,17 @@ struct QEMUFile {*/ int qemu_file_shutdown (QEMUFile *f) { -int ret; +int ret =0 ; f->shutdown = true;migration/qemu-file.c struct QEMUFile { · line 87
Quoted 10 lines
migration/qemu-file.c +6
-2-if (!f->ops->shut_down) { +if (!qio_channel_has_feature (f->ioc, +QIO_CHANNEL_FEATURE_SHUTDOWN )) {return -ENOSYS ; } - ret = f->ops->shut_down (f->ioc, true, true,NULL ); + +if (qio_channel_shutdown (f->ioc,QIO_CHANNEL_SHUTDOWN_BOTH ,NULL ) <0 ) { + ret = -EIO ; + }OK, so this is following the code you're flattening; so:
Quoted 4 lines
Reviewed-by Dr. David Alan Gilbert <[email protected]>I wonder if there's any reason it doesn't just pass the return value through to ret rather
than flattening it to-EIO?
qio methods never return errno values just positive integer or -1.
Since qemu_file_shutdown seems to want an errno, I picked EIO
Better would be for qemu_file_shutdown to have an Error **errp param instead but that could come later.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 14/20] migration: remove the QEMUFileOps 'shut_down' callback
Quoted 93 lines · * Daniel P. Berrangé ([email protected]) wrote:
Quoted 87 lines · Dr. David Alan Gilbert
Quoted 73 lines · * Daniel P. Berrangé ([email protected]) wrote:
This directly implements the shutdown logic using QIOChannel APIs.
Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/qemu-file-channel.c | 27 --------------------------- migration/qemu-file.c | 10 +++++++--- migration/qemu-file.h | 10 ---------- 3 files changed, 7 insertions(+), 40 deletions(-)migration/qemu-file-channel.c +0
-27@@ -112,31 +112,6 @@ static int channel_close(void *opaque, Error **errp) } -static int channel_shutdown (void *opaque, -bool rd, -bool wr, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); - -if (qio_channel_has_feature (ioc, -QIO_CHANNEL_FEATURE_SHUTDOWN )) { -QIOChannelShutdown mode; -if (rd && wr) { - mode =QIO_CHANNEL_SHUTDOWN_BOTH ; - }else if (rd) { - mode =QIO_CHANNEL_SHUTDOWN_READ ; - }else { - mode =QIO_CHANNEL_SHUTDOWN_WRITE ; - } -if (qio_channel_shutdown (ioc, mode, errp) <0 ) { -return -EIO ; - } - } -return 0 ; -} - -static int channel_set_blocking (void *opaque,bool enabled,Error **errp)@@ -166,7 +141,6 @@ static QEMUFile *channel_get_output_return_path(void *opaque)static const QEMUFileOps channel_input_ops = { .get_buffer = channel_get_buffer, .close = channel_close, - .shut_down = channel_shutdown, .set_blocking = channel_set_blocking, .get_return_path = channel_get_input_return_path, };@@ -175,7 +149,6 @@ static const QEMUFileOps channel_input_ops = {static const QEMUFileOps channel_output_ops = { .writev_buffer = channel_writev_buffer, .close = channel_close, - .shut_down = channel_shutdown, .set_blocking = channel_set_blocking, .get_return_path = channel_get_output_return_path, };migration/qemu-file.c +1
-1@@ -74,13 +74,17 @@ struct QEMUFile {*/ int qemu_file_shutdown (QEMUFile *f) { -int ret; +int ret =0 ; f->shutdown = true;migration/qemu-file.c struct QEMUFile { · line 87
Quoted 10 lines
migration/qemu-file.c +6
-2-if (!f->ops->shut_down) { +if (!qio_channel_has_feature (f->ioc, +QIO_CHANNEL_FEATURE_SHUTDOWN )) {return -ENOSYS ; } - ret = f->ops->shut_down (f->ioc, true, true,NULL ); + +if (qio_channel_shutdown (f->ioc,QIO_CHANNEL_SHUTDOWN_BOTH ,NULL ) <0 ) { + ret = -EIO ; + }OK, so this is following the code you're flattening; so:
Quoted 4 lines
Reviewed-by Dr. David Alan Gilbert <[email protected]>I wonder if there's any reason it doesn't just pass the return value through to ret rather
than flattening it to-EIO?
Quoted 6 lines
qio methods never return errno values just positive integer or -1.
Since
qemu_file_shutdownseems to want an errno, I picked EIOBetter would be for
qemu_file_shutdownto have an Error **errp param instead but that could come later.
Ah OK.
Dave
Quoted 8 lines
With regards,
DanielSignature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 17/20] migration: remove the QEMUFileOps 'get_buffer' callback
In reply to Daniel P. BerrangéQuoted 61 lines · * Daniel P. Berrangé ([email protected]) wrote:
This directly implements the
get_bufferlogic using QIOChannel APIs.Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/qemu-file-channel.c | 29 ----------------------------- migration/qemu-file.c | 18 ++++++++++++++++-- migration/qemu-file.h | 9 --------- 3 files changed, 16 insertions(+), 40 deletions(-)migration/qemu-file-channel.c +0
-29@@ -74,34 +74,6 @@ static ssize_t channel_writev_buffer(void *opaque, } -static ssize_t channel_get_buffer (void *opaque, -uint8_t *buf, -int64_t pos, -size_t size, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); -ssize_t ret; - -do { - ret =qio_channel_read (ioc, (char *)buf, size, errp); -if (ret <0 ) { -if (ret ==QIO_CHANNEL_ERR_BLOCK ) { -if (qemu_in_coroutine ()) { -qio_channel_yield (ioc,G_IO_IN ); - }else { -qio_channel_wait (ioc,G_IO_IN ); - } - }else { -return -EIO ; - } - } - }while (ret ==QIO_CHANNEL_ERR_BLOCK ); - -return ret; -} - -static QEMUFile *channel_get_input_return_path (void *opaque) {QIOChannel *ioc =QIO_CHANNEL (opaque);@@ -117,7 +89,6 @@ static QEMUFile *channel_get_output_return_path(void *opaque) }static const QEMUFileOps channel_input_ops = { - .get_buffer = channel_get_buffer, .get_return_path = channel_get_input_return_path, };migration/qemu-file.c +0
-0
migration/qemu-file.c static ssize_t qemu_fill_buffer(QEMUFile *f) · line 378
Quoted 7 lines
migration/qemu-file.c +2
-2@@ -374,8 +374,22 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return 0 ; } - len = f->ops->get_buffer (f->ioc, f->buf + pending, f->total_transferred, -IO_BUF_SIZE - pending, &local_error); + do { + len = qio_channel_read(f->ioc,
Yes, I think that's OK - not that 'len' is an int where 'ret' was a ssize_t; but I think our buffers are guranteed to be 'small'.
Quoted 47 lines
migration/qemu-file.c +14
-0+ (char *)f->buf + pending, +IO_BUF_SIZE - pending, + &local_error); +if (len ==QIO_CHANNEL_ERR_BLOCK ) { +if (qemu_in_coroutine ()) { +qio_channel_yield (f->ioc,G_IO_IN ); + }else { +qio_channel_wait (f->ioc,G_IO_IN ); + } + }else if (len <0 ) { + len =EIO ; + } + }while (len ==QIO_CHANNEL_ERR_BLOCK ); +if (len >0 ) { f->buf_size += len; f->total_transferred += len;migration/qemu-file.h +0
-9@@ -29,14 +29,6 @@#include "exec/cpu-common.h" #include "io/channel.h" -/* Read a chunk of data from a file at the given position. The pos argument -* can be ignored if the file is only be used for streaming. The number of -* bytes actually read should be returned. -*/ -typedef ssize_t (QEMUFileGetBufferFunc )(void *opaque,uint8_t *buf, -int64_t pos,size_t size, -Error **errp); -/* * This function writes an iovec to file. The handler must write all * of the data or return a negative errno value. @@ -77,7 +69,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,typedef QEMUFile *(QEMURetPathFunc )(void *opaque);typedef struct QEMUFileOps { -QEMUFileGetBufferFunc *get_buffer;QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path; }QEMUFileOps ;Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 18/20] migration: remove the QEMUFileOps 'writev_buffer' callback
In reply to Daniel P. BerrangéQuoted 33 lines · * Daniel P. Berrangé ([email protected]) wrote:
This directly implements the
writev_bufferlogic using QIOChannel APIs.Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/qemu-file-channel.c | 43 ----------------------------------- migration/qemu-file.c | 24 +++++++------------ migration/qemu-file.h | 9 -------- 3 files changed, 8 insertions(+), 68 deletions(-)migration/qemu-file-channel.c +0
-16@@ -32,48 +32,6 @@#include "yank_functions.h" -static ssize_t channel_writev_buffer (void *opaque, -struct iovec *iov, -int iovcnt, -int64_t pos, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); -ssize_t done =0 ; - struct iovec *local_iov = g_new(struct iovec, iovcnt); -struct iovec *local_iov_head = local_iov; -unsigned int nlocal_iov = iovcnt; - - nlocal_iov =iov_copy (local_iov, nlocal_iov, - iov, iovcnt, -0 ,iov_size (iov, iovcnt)); -
migration/qemu-file-channel.c line 60
Quoted 10 lines
migration/qemu-file-channel.c +0
-10-while (nlocal_iov >0 ) { -ssize_t len; - len =qio_channel_writev (ioc, local_iov, nlocal_iov, errp); -if (len ==QIO_CHANNEL_ERR_BLOCK ) { -if (qemu_in_coroutine ()) { -qio_channel_yield (ioc,G_IO_OUT ); - }else { -qio_channel_wait (ioc,G_IO_OUT ); - } -continue ;
I wondered where that code went, but it turns out it's already copied into qio_channel_writev_full_all, so:
Quoted 103 lines
migration/qemu-file-channel.c +0
-17- } -if (len <0 ) { - done = -EIO ; - goto cleanup; - } - -iov_discard_front (&local_iov, &nlocal_iov, len); - done += len; - } - - cleanup: -g_free (local_iov_head); -return done; -} - -static QEMUFile *channel_get_input_return_path (void *opaque) {QIOChannel *ioc =QIO_CHANNEL (opaque);@@ -94,7 +52,6 @@ static const QEMUFileOps channel_input_ops = {static const QEMUFileOps channel_output_ops = { - .writev_buffer = channel_writev_buffer, .get_return_path = channel_get_output_return_path, };migration/qemu-file.c +8
-16@@ -245,10 +245,6 @@ static void qemu_iovec_release_ram(QEMUFile *f)*/ void qemu_fflush (QEMUFile *f) { -ssize_t ret =0 ; -ssize_t expect =0 ; -Error *local_error =NULL ; -if (!qemu_file_is_writable (f)) {return ; }@@ -257,22 +253,18 @@ void qemu_fflush(QEMUFile *f)return ; }if (f->iovcnt >0 ) { - expect =iov_size (f->iov, f->iovcnt); - ret = f->ops->writev_buffer (f->ioc, f->iov, f->iovcnt, f->total_transferred, - &local_error); +Error *local_error =NULL ; +if (qio_channel_writev_all (f->ioc, + f->iov, f->iovcnt, + &local_error) <0 ) { +qemu_file_set_error_obj (f, -EIO , local_error); + }else { + f->total_transferred +=iov_size (f->iov, f->iovcnt); + }qemu_iovec_release_ram (f); } -if (ret >=0 ) { - f->total_transferred += ret; - } -/* We expect the QEMUFile write impl to send the full -* data set we requested, so sanity check that. -*/ -if (ret != expect) { -qemu_file_set_error_obj (f, ret <0 ? ret : -EIO , local_error); - } f->buf_index =0 ; f->iovcnt =0 ; }migration/qemu-file.h +0
-9@@ -29,14 +29,6 @@#include "exec/cpu-common.h" #include "io/channel.h" -/* -* This function writes an iovec to file. The handler must write all -* of the data or return a negative errno value. -*/ -typedef ssize_t (QEMUFileWritevBufferFunc )(void *opaque,struct iovec *iov, -int iovcnt,int64_t pos, -Error **errp); -/* * This function provides hooks around different * stages of RAM migration. @@ -69,7 +61,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,typedef QEMUFile *(QEMURetPathFunc )(void *opaque);typedef struct QEMUFileOps { -QEMUFileWritevBufferFunc *writev_buffer;QEMURetPathFunc *get_return_path; }QEMUFileOps ;Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 20/20] migration: remove the QEMUFileOps abstraction
In reply to Daniel P. BerrangéQuoted 4 lines · * Daniel P. Berrangé ([email protected]) wrote:
Now that all QEMUFile callbacks are removed, the entire concept can be deleted.
Signed-off-by Daniel P. Berrangé <[email protected]>
I think that's OK, there's one nit - you remove qemu_get_fd from one of the headers; I think that probably belongs in an earlier patch.
Other than that,
Quoted 436 lines
--- migration/channel.c | 4 +-- migration/colo.c | 5 ++-- migration/meson.build | 1 - migration/migration.c | 7 ++--- migration/qemu-file-channel.c | 53 ----------------------------------- migration/qemu-file-channel.h | 32 --------------------- migration/qemu-file.c | 20 ++++++------- migration/qemu-file.h | 8 ++---- migration/ram.c | 3 +- migration/rdma.c | 5 ++-- migration/savevm.c | 11 ++++---- tests/unit/test-vmstate.c | 5 ++-- 12 files changed, 27 insertions(+), 127 deletions(-) delete mode 100644 migration/qemu-file-channel.c delete mode 100644 migration/qemu-file-channel.hmigration/channel.c +2
-2@@ -14,7 +14,7 @@#include "channel.h" #include "tls.h" #include "migration.h" -#include "qemu-file-channel.h" +#include "qemu-file.h" #include "trace.h" #include "qapi/error.h" #include "io/channel-tls.h" @@ -85,7 +85,7 @@ void migration_channel_connect(MigrationState *s,return ; } }else { -QEMUFile *f =qemu_fopen_channel_output (ioc); +QEMUFile *f =qemu_file_new_output (ioc);migration_ioc_register_yank (ioc);migration/colo.c +2
-3@@ -14,7 +14,6 @@#include "sysemu/sysemu.h" #include "qapi/error.h" #include "qapi/qapi-commands-migration.h" -#include "qemu-file-channel.h" #include "migration.h" #include "qemu-file.h" #include "savevm.h" @@ -559,7 +558,7 @@ static void colo_process_checkpoint(MigrationState *s) goto out; } bioc =qio_channel_buffer_new (COLO_BUFFER_BASE_SIZE ); - fb =qemu_fopen_channel_output (QIO_CHANNEL (bioc)); + fb =qemu_file_new_output (QIO_CHANNEL (bioc));object_unref (OBJECT (bioc));qemu_mutex_lock_iothread ();@@ -873,7 +872,7 @@ void *colo_process_incoming_thread(void *opaque)colo_incoming_start_dirty_log (); bioc =qio_channel_buffer_new (COLO_BUFFER_BASE_SIZE ); - fb =qemu_fopen_channel_input (QIO_CHANNEL (bioc)); + fb =qemu_file_new_input (QIO_CHANNEL (bioc));object_unref (OBJECT (bioc));qemu_mutex_lock_iothread ();migration/meson.build +0
-1@@ -4,7 +4,6 @@ migration_files = files( 'xbzrle.c', 'vmstate-types.c', 'vmstate.c', - 'qemu-file-channel.c', 'qemu-file.c', 'yank_functions.c', )migration/migration.c +3
-4@@ -30,7 +30,6 @@#include "migration/misc.h" #include "migration.h" #include "savevm.h" -#include "qemu-file-channel.h" #include "qemu-file.h" #include "migration/vmstate.h" #include "block/block.h" @@ -722,7 +721,7 @@ void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp)if (!mis->from_src_file) {/* The first connection (multifd may have multiple) */ -QEMUFile *f =qemu_fopen_channel_input (ioc); +QEMUFile *f =qemu_file_new_input (ioc);if (!migration_incoming_setup (f, errp)) {return ;@@ -3081,7 +3080,7 @@ static int postcopy_start(MigrationState *ms)*/ bioc =qio_channel_buffer_new (4096 );qio_channel_set_name (QIO_CHANNEL (bioc),"migration-postcopy-buffer" ); - fb =qemu_fopen_channel_output (QIO_CHANNEL (bioc)); + fb =qemu_file_new_output (QIO_CHANNEL (bioc));object_unref (OBJECT (bioc));/* @@ -3970,7 +3969,7 @@ static void *bg_migration_thread(void *opaque)*/ s->bioc =qio_channel_buffer_new (512 *1024 );qio_channel_set_name (QIO_CHANNEL (s->bioc),"vmstate-buffer" ); - fb =qemu_fopen_channel_output (QIO_CHANNEL (s->bioc)); + fb =qemu_file_new_output (QIO_CHANNEL (s->bioc));object_unref (OBJECT (s->bioc));update_iteration_initial_status (s);migration/qemu-file-channel.c deleted +0
-53@@ -1,53 +0,0 @@ -/* -* QEMUFile backend for QIOChannel objects -* -* Copyright (c) 2015-2016 Red Hat, Inc -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#include "qemu/osdep.h" -#include "qemu-file-channel.h" -#include "qemu-file.h" -#include "io/channel-socket.h" -#include "io/channel-tls.h" -#include "qemu/iov.h" -#include "qemu/yank.h" -#include "yank_functions.h" - - -static const QEMUFileOps channel_input_ops = { -}; - - -static const QEMUFileOps channel_output_ops = { -}; - - -QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc) -{ -object_ref (OBJECT (ioc)); -return qemu_file_new_input (ioc, &channel_input_ops); -} - -QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc) -{ -object_ref (OBJECT (ioc)); -return qemu_file_new_output (ioc, &channel_output_ops); -}migration/qemu-file-channel.h deleted +0
-32@@ -1,32 +0,0 @@ -/* -* QEMUFile backend for QIOChannel objects -* -* Copyright (c) 2015-2016 Red Hat, Inc -* -* Permission is hereby granted, free of charge, to any person obtaining a copy -* of this software and associated documentation files (the "Software"), to deal -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ - -#ifndef QEMU_FILE_CHANNEL_H -#define QEMU_FILE_CHANNEL_H - -#include "io/channel.h" - -QEMUFile *qemu_fopen_channel_input (QIOChannel *ioc); -QEMUFile *qemu_fopen_channel_output (QIOChannel *ioc); -#endif migration/qemu-file.c +8
-12@@ -35,7 +35,6 @@#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)struct QEMUFile { -const QEMUFileOps *ops;const QEMUFileHooks *hooks;QIOChannel *ioc;bool is_writable;@@ -104,16 +103,14 @@ bool qemu_file_mode_is_not_valid(const char *mode)return false; } -static QEMUFile *qemu_file_new_impl (QIOChannel *ioc, -const QEMUFileOps *ops, -bool is_writable) +static QEMUFile *qemu_file_new_impl (QIOChannel *ioc,bool is_writable) {QEMUFile *f; f =g_new0 (QEMUFile,1 ); +object_ref (ioc); f->ioc = ioc; - f->ops = ops; f->is_writable = is_writable;return f;@@ -125,21 +122,19 @@ static QEMUFile *qemu_file_new_impl(QIOChannel *ioc,*/ QEMUFile *qemu_file_get_return_path (QEMUFile *f) { -object_ref (f->ioc); -return qemu_file_new_impl (f->ioc, f->ops, !f->is_writable); +return qemu_file_new_impl (f->ioc, !f->is_writable); } -QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops) +QEMUFile *qemu_file_new_output (QIOChannel *ioc) { -return qemu_file_new_impl (ioc, ops, true); +return qemu_file_new_impl (ioc, true); } -QEMUFile *qemu_file_new_input (QIOChannel *ioc,const QEMUFileOps *ops) +QEMUFile *qemu_file_new_input (QIOChannel *ioc) { -return qemu_file_new_impl (ioc, ops, false); +return qemu_file_new_impl (ioc, false); } -void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks) { f->hooks = hooks;@@ -235,6 +230,7 @@ static void qemu_iovec_release_ram(QEMUFile *f)memset (f->may_free,0 ,sizeof (f->may_free)); } +/** * Flushes QEMUFile buffer * migration/qemu-file.h +2
-6@@ -55,9 +55,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,size_t size, uint64_t *bytes_sent); -typedef struct QEMUFileOps { -}QEMUFileOps ; - typedef struct QEMUFileHooks { QEMURamHookFunc *before_ram_iterate; QEMURamHookFunc *after_ram_iterate;@@ -65,10 +62,9 @@ typedef struct QEMUFileHooks {QEMURamSaveFunc *save_page; } QEMUFileHooks; -QEMUFile *qemu_file_new_input (QIOChannel *ioc,const QEMUFileOps *ops); -QEMUFile *qemu_file_new_output (QIOChannel *ioc,const QEMUFileOps *ops); +QEMUFile *qemu_file_new_input (QIOChannel *ioc); +QEMUFile *qemu_file_new_output (QIOChannel *ioc);void qemu_file_set_hooks (QEMUFile *f,const QEMUFileHooks *hooks); -int qemu_get_fd (QEMUFile *f);int qemu_fclose (QEMUFile *f);/* migration/ram.c +1
-2@@ -38,7 +38,6 @@#include "migration.h" #include "migration/register.h" #include "migration/misc.h" -#include "migration/qemu-file-channel.h" #include "qemu-file.h" #include "postcopy-ram.h" #include "page_cache.h" @@ -569,7 +568,7 @@ static int compress_threads_save_setup(void)/* comp_param[i].file is just used as a dummy buffer to save data, * set its ops to empty. */ - comp_param[i].file =qemu_fopen_channel_output ( + comp_param[i].file =qemu_file_new_output (QIO_CHANNEL (qio_channel_null_new ())); comp_param[i].done = true; comp_param[i].quit = false;migration/rdma.c +2
-3@@ -21,7 +21,6 @@#include "migration.h" #include "qemu-file.h" #include "ram.h" -#include "qemu-file-channel.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" #include "qemu/module.h" @@ -4093,12 +4092,12 @@ static QEMUFile *qemu_fopen_rdma(RDMAContext *rdma, const char *mode) rioc =QIO_CHANNEL_RDMA (object_new (TYPE_QIO_CHANNEL_RDMA ));if (mode[0 ] =='w' ) { - rioc->file =qemu_fopen_channel_output (QIO_CHANNEL (rioc)); + rioc->file =qemu_file_new_output (QIO_CHANNEL (rioc)); rioc->rdmaout = rdma; rioc->rdmain = rdma->return_path;qemu_file_set_hooks (rioc->file, &rdma_write_hooks); }else { - rioc->file =qemu_fopen_channel_input (QIO_CHANNEL (rioc)); + rioc->file =qemu_file_new_input (QIO_CHANNEL (rioc)); rioc->rdmain = rdma; rioc->rdmaout = rdma->return_path;qemu_file_set_hooks (rioc->file, &rdma_read_hooks);migration/savevm.c +5
-6@@ -37,7 +37,6 @@#include "migration/global_state.h" #include "migration/channel-block.h" #include "ram.h" -#include "qemu-file-channel.h" #include "qemu-file.h" #include "savevm.h" #include "postcopy-ram.h" @@ -134,9 +133,9 @@ static struct mig_cmd_args {static QEMUFile *qemu_fopen_bdrv (BlockDriverState *bs,int is_writable) {if (is_writable) { -return qemu_fopen_channel_output (QIO_CHANNEL (qio_channel_block_new (bs))); +return qemu_file_new_output (QIO_CHANNEL (qio_channel_block_new (bs))); }else { -return qemu_fopen_channel_input (QIO_CHANNEL (qio_channel_block_new (bs))); +return qemu_file_new_input (QIO_CHANNEL (qio_channel_block_new (bs))); } }@@ -2159,7 +2158,7 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis) bioc->usage += length;trace_loadvm_handle_cmd_packaged_received (ret); -QEMUFile *packf =qemu_fopen_channel_input (QIO_CHANNEL (bioc)); +QEMUFile *packf =qemu_file_new_input (QIO_CHANNEL (bioc)); ret =qemu_loadvm_state_main (packf, mis);trace_loadvm_handle_cmd_packaged_main (ret);@@ -2917,7 +2916,7 @@ void qmp_xen_save_devices_state(const char *filename, bool has_live, bool live, goto the_end; }qio_channel_set_name (QIO_CHANNEL (ioc),"migration-xen-save-state" ); - f =qemu_fopen_channel_output (QIO_CHANNEL (ioc)); + f =qemu_file_new_output (QIO_CHANNEL (ioc));object_unref (OBJECT (ioc)); ret =qemu_save_device_state (f);if (ret <0 ||qemu_fclose (f) <0 ) {@@ -2964,7 +2963,7 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp)return ; }qio_channel_set_name (QIO_CHANNEL (ioc),"migration-xen-load-state" ); - f =qemu_fopen_channel_input (QIO_CHANNEL (ioc)); + f =qemu_file_new_input (QIO_CHANNEL (ioc));object_unref (OBJECT (ioc)); ret =qemu_loadvm_state (f);tests/unit/test-vmstate.c +2
-3@@ -28,7 +28,6 @@#include "migration/vmstate.h" #include "migration/qemu-file-types.h" #include "../migration/qemu-file.h" -#include "../migration/qemu-file-channel.h" #include "../migration/savevm.h" #include "qemu/coroutine.h" #include "qemu/module.h" @@ -52,9 +51,9 @@ static QEMUFile *open_test_file(bool write) } ioc =QIO_CHANNEL (qio_channel_file_new_fd (fd));if (write) { - f =qemu_fopen_channel_output (ioc); + f =qemu_file_new_output (ioc); }else { - f =qemu_fopen_channel_input (ioc); + f =qemu_file_new_input (ioc); }object_unref (OBJECT (ioc));return f;Signature · 1 line
2.36.1
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
Re: [PATCH 17/20] migration: remove the QEMUFileOps 'get_buffer' callback
In reply to Dr. David Alan GilbertQuoted 65 lines · Dr. David Alan Gilbert
Quoted 64 lines · * Daniel P. Berrangé ([email protected]) wrote:
This directly implements the
get_bufferlogic using QIOChannel APIs.Signed-off-by Daniel P. Berrangé <[email protected]>--- migration/qemu-file-channel.c | 29 ----------------------------- migration/qemu-file.c | 18 ++++++++++++++++-- migration/qemu-file.h | 9 --------- 3 files changed, 16 insertions(+), 40 deletions(-)migration/qemu-file-channel.c +0
-29@@ -74,34 +74,6 @@ static ssize_t channel_writev_buffer(void *opaque, } -static ssize_t channel_get_buffer (void *opaque, -uint8_t *buf, -int64_t pos, -size_t size, -Error **errp) -{ -QIOChannel *ioc =QIO_CHANNEL (opaque); -ssize_t ret; - -do { - ret =qio_channel_read (ioc, (char *)buf, size, errp); -if (ret <0 ) { -if (ret ==QIO_CHANNEL_ERR_BLOCK ) { -if (qemu_in_coroutine ()) { -qio_channel_yield (ioc,G_IO_IN ); - }else { -qio_channel_wait (ioc,G_IO_IN ); - } - }else { -return -EIO ; - } - } - }while (ret ==QIO_CHANNEL_ERR_BLOCK ); - -return ret; -} - -static QEMUFile *channel_get_input_return_path (void *opaque) {QIOChannel *ioc =QIO_CHANNEL (opaque);@@ -117,7 +89,6 @@ static QEMUFile *channel_get_output_return_path(void *opaque) }static const QEMUFileOps channel_input_ops = { - .get_buffer = channel_get_buffer, .get_return_path = channel_get_input_return_path, };migration/qemu-file.c +0
-0@@ -374,8 +374,22 @@ static ssize_t qemu_fill_buffer(QEMUFile *f)return 0 ; }
Quoted 7 lines
migration/qemu-file.c static ssize_t qemu_fill_buffer(QEMUFile *f) · line 378
Quoted 4 lines
migration/qemu-file.c +2
-2- len = f->ops->get_buffer (f->ioc, f->buf + pending, f->total_transferred, -IO_BUF_SIZE - pending, &local_error); + do { + len = qio_channel_read(f->ioc,Yes, I think that's OK - not that 'len' is an int where 'ret' was a
ssize_t; but I think our buffers are guranteed to be 'small'.
There are a few places in qemu-file.c where we're fast & loose with int rather than size_t, that are probably worth cleaning.
Quoted 1 line
Reviewed-by Dr. David Alan Gilbert <[email protected]>
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH 01/20] io: add a QIOChannelNull equivalent to /dev/null
In reply to Eric BlakeQuoted 17 lines · Eric Blake
Quoted 15 lines · Daniel P. Berrangé
This is for code which needs a portable equivalent to a QIOChannelFile connected to
/dev/null.Signed-off-by Daniel P. Berrangé <[email protected]>--- include/io/channel-null.h | 55 +++++++ io/channel-null.c | 237 ++++++++++++++++++++++++++++++ io/meson.build | 1 + io/trace-events | 3 + tests/unit/meson.build | 1 + tests/unit/test-io-channel-null.c | 95 ++++++++++++ 6 files changed, 392 insertions(+) create mode 100644 include/io/channel-null.h create mode 100644 io/channel-null.c create mode 100644 tests/unit/test-io-channel-null.c
Quoted 8 lines
Quoted 5 lines
+/**
+ * QIOChannelNull:
+ *
+ * The QIOChannelNull object provides a channel implementation
+ * that discards all writes and returns zero bytes for all reads.That describes the behavior of
/dev/zero, not/dev/null, where reads always fail with EOF.
Nb, I wrote 'zero bytes' (as in "byte count equal to zero") not 'zeroed bytes' (as in "set all bytes to the value zero").
I'll reword it to make it less confusing though.
Quoted 55 lines
Quoted 20 lines
+ */
include/io/channel-null.h new file +6
-0+ +struct QIOChannelNull { +QIOChannel parent; +bool closed; +}; +io/channel-null.c +9
-0+ +static ssize_t +qio_channel_null_readv (QIOChannel *ioc, +const struct iovec *iov, +size_t niov, + int **fds G_GNUC_UNUSED, + size_t *nfds G_GNUC_UNUSED, +Error **errp) +{io/channel-null.c line 74
Quoted 10 lines
io/channel-null.c +10
-0+QIOChannelNull *nioc =QIO_CHANNEL_NULL (ioc); + +if (nioc->closed) { +error_setg_errno (errp,EINVAL , +"Channel is closed" ); +return -1 ; + } + +return 0 ; +}But this behavior is returning early EOF instead of using
iov_memset()to read all zeroes the way/dev/zerowould.io/channel-null.c
Quoted 12 lines
+++
b/tests/unit/test-io-channel-null.cio/channel-null.c +10
-0+static void test_io_channel_null_io (void ) +{ +g_autoptr (QIOChannelNull) null =qio_channel_null_new (); +char buf[1024 ]; +GIOCondition gotcond =0 ; +Error *local_err =NULL ; + +g_assert (qio_channel_write (QIO_CHANNEL (null), +"Hello World" ,11 , + &error_abort) ==11 );I still cringe seeing tests inside
g_assert(), but this is not the first instance of it.io/channel-null.c
Quoted 4 lines
io/channel-null.c +4
-0+ +g_assert (qio_channel_read (QIO_CHANNEL (null), + buf,sizeof (buf), + &error_abort) ==0 );
Quoted 11 lines
Okay, you're testing for
/dev/nullbehavior of early EOF.Other than misleading comments, this looks reasonable. But those comments are core enough as to what this channel does that I don't feel comfortable giving R-b yet.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|