aboutsummaryrefslogtreecommitdiff
path: root/migration/qemu-file.c
diff options
context:
space:
mode:
Diffstat (limited to 'migration/qemu-file.c')
-rw-r--r--migration/qemu-file.c63
1 files changed, 51 insertions, 12 deletions
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 0431585502..c04a7a891b 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;
@@ -783,6 +822,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);
}
}