diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2019-08-16 12:00:18 +0100 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2019-08-16 12:00:18 +0100 |
| commit | 27608c7c66bd923eb5e5faab80e795408cbe2b51 (patch) | |
| tree | ece1982460bc4a1f53833838337cb9fcb9fe5061 /migration/qemu-file.c | |
| parent | f8f2eac4e5de8ce8ef17591ee1b84904437be25b (diff) | |
| parent | 7dd59d01ddcc4a4ba0c44c2cc9e3b35c79aa7a29 (diff) | |
| download | focaccia-qemu-27608c7c66bd923eb5e5faab80e795408cbe2b51.tar.gz focaccia-qemu-27608c7c66bd923eb5e5faab80e795408cbe2b51.zip | |
Merge remote-tracking branch 'remotes/dgilbert/tags/pull-migration-20190814a' into staging
Migration pull 2019-08-15
Marcel's vmxnet3 live migraiton fix (that breaks vmxnet3 compatibility
but makes it work)
Error description improvements from Yury.
Multifd fixes from Ivan and Juan.
A load of small cleanups from Wei.
A small cleanup from Marc-André for a future patch.
# gpg: Signature made Wed 14 Aug 2019 19:00:39 BST
# gpg: using RSA key 45F5C71B4A0CB7FB977A9FA90516331EBC5BFDE7
# gpg: Good signature from "Dr. David Alan Gilbert (RH2) <dgilbert@redhat.com>" [full]
# Primary key fingerprint: 45F5 C71B 4A0C B7FB 977A 9FA9 0516 331E BC5B FDE7
* remotes/dgilbert/tags/pull-migration-20190814a: (33 commits)
migration: add some multifd traces
migration: Make global sem_sync semaphore by channel
migration: Add traces for multifd terminate threads
qemu-file: move qemu_{get,put}_counted_string() declarations
migration/postcopy: use mis->bh instead of allocating a QEMUBH
migration: rename migration_bitmap_sync_range to ramblock_sync_dirty_bitmap
migration: update ram_counters for multifd sync packet
migration: add speed limit for multifd migration
migration: add qemu_file_update_transfer interface
migration: always initialise ram_counters for a new migration
migration: remove unused field bytes_xfer
hmp: Remove migration capabilities from "info migrate"
migration/postcopy: use QEMU_IS_ALIGNED to replace host_offset
migration/postcopy: simplify calculation of run_start and fixup_start_addr
migration/postcopy: make PostcopyDiscardState a static variable
migration: extract ram_load_precopy
migration: return -EINVAL directly when version_id mismatch
migration: equation is more proper than and to check LOADVM_QUIT
migration: just pass RAMBlock is enough
migration: use migration_in_postcopy() to check POSTCOPY_ACTIVE
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'migration/qemu-file.c')
| -rw-r--r-- | migration/qemu-file.c | 68 |
1 files changed, 56 insertions, 12 deletions
diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 0431585502..e33c46764f 100644 --- a/migration/qemu-file.c +++ b/migration/qemu-file.c @@ -28,6 +28,7 @@ #include "migration.h" #include "qemu-file.h" #include "trace.h" +#include "qapi/error.h" #define IO_BUF_SIZE 32768 #define MAX_IOV_SIZE MIN(IOV_MAX, 64) @@ -51,6 +52,7 @@ struct QEMUFile { unsigned int iovcnt; int last_error; + Error *last_error_obj; }; /* @@ -62,7 +64,7 @@ int qemu_file_shutdown(QEMUFile *f) if (!f->ops->shut_down) { return -ENOSYS; } - return f->ops->shut_down(f->opaque, true, true); + return f->ops->shut_down(f->opaque, true, true, NULL); } /* @@ -107,24 +109,55 @@ void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks) } /* - * Get last error for stream f + * Get last error for stream f with optional Error* * * Return negative error value if there has been an error on previous * operations, return 0 if no error happened. + * Optional, it returns Error* in errp, but it may be NULL even if return value + * is not 0. * */ -int qemu_file_get_error(QEMUFile *f) +int qemu_file_get_error_obj(QEMUFile *f, Error **errp) { + if (errp) { + *errp = f->last_error_obj ? error_copy(f->last_error_obj) : NULL; + } return f->last_error; } -void qemu_file_set_error(QEMUFile *f, int ret) +/* + * Set the last error for stream f with optional Error* + */ +void qemu_file_set_error_obj(QEMUFile *f, int ret, Error *err) { - if (f->last_error == 0) { + if (f->last_error == 0 && ret) { f->last_error = ret; + error_propagate(&f->last_error_obj, err); + } else if (err) { + error_report_err(err); } } +/* + * Get last error for stream f + * + * Return negative error value if there has been an error on previous + * operations, return 0 if no error happened. + * + */ +int qemu_file_get_error(QEMUFile *f) +{ + return qemu_file_get_error_obj(f, NULL); +} + +/* + * Set the last error for stream f + */ +void qemu_file_set_error(QEMUFile *f, int ret) +{ + qemu_file_set_error_obj(f, ret, NULL); +} + bool qemu_file_is_writable(QEMUFile *f) { return f->ops->writev_buffer; @@ -176,6 +209,7 @@ void qemu_fflush(QEMUFile *f) { ssize_t ret = 0; ssize_t expect = 0; + Error *local_error = NULL; if (!qemu_file_is_writable(f)) { return; @@ -183,7 +217,8 @@ 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->pos, + &local_error); qemu_iovec_release_ram(f); } @@ -195,7 +230,7 @@ void qemu_fflush(QEMUFile *f) * data set we requested, so sanity check that. */ if (ret != expect) { - qemu_file_set_error(f, ret < 0 ? ret : -EIO); + qemu_file_set_error_obj(f, ret < 0 ? ret : -EIO, local_error); } f->buf_index = 0; f->iovcnt = 0; @@ -283,6 +318,7 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) { int len; int pending; + Error *local_error = NULL; assert(!qemu_file_is_writable(f)); @@ -294,14 +330,16 @@ static ssize_t qemu_fill_buffer(QEMUFile *f) f->buf_size = pending; len = f->ops->get_buffer(f->opaque, f->buf + pending, f->pos, - IO_BUF_SIZE - pending); + IO_BUF_SIZE - pending, &local_error); if (len > 0) { f->buf_size += len; f->pos += len; } else if (len == 0) { - qemu_file_set_error(f, -EIO); + qemu_file_set_error_obj(f, -EIO, local_error); } else if (len != -EAGAIN) { - qemu_file_set_error(f, len); + qemu_file_set_error_obj(f, len, local_error); + } else { + error_free(local_error); } return len; @@ -327,7 +365,7 @@ int qemu_fclose(QEMUFile *f) ret = qemu_file_get_error(f); if (f->ops->close) { - int ret2 = f->ops->close(f->opaque); + int ret2 = f->ops->close(f->opaque, NULL); if (ret >= 0) { ret = ret2; } @@ -338,6 +376,7 @@ int qemu_fclose(QEMUFile *f) if (f->last_error) { ret = f->last_error; } + error_free(f->last_error_obj); g_free(f); trace_qemu_file_fclose(); return ret; @@ -615,6 +654,11 @@ void qemu_file_reset_rate_limit(QEMUFile *f) f->bytes_xfer = 0; } +void qemu_file_update_transfer(QEMUFile *f, int64_t len) +{ + f->bytes_xfer += len; +} + void qemu_put_be16(QEMUFile *f, unsigned int v) { qemu_put_byte(f, v >> 8); @@ -783,6 +827,6 @@ 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); + f->ops->set_blocking(f->opaque, block, NULL); } } |