[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH v1 09/26] migration/qemu-file: add utility methods for workin
From: |
Fabiano Rosas |
Subject: |
[RFC PATCH v1 09/26] migration/qemu-file: add utility methods for working with seekable channels |
Date: |
Thu, 30 Mar 2023 15:03:19 -0300 |
From: Nikolay Borisov <nborisov@suse.com>
Add utility methods that will be needed when implementing 'fixed-ram'
migration capability.
qemu_file_is_seekable
qemu_put_buffer_at
qemu_get_buffer_at
qemu_set_offset
qemu_get_offset
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
fixed total_transferred accounting
restructured to use qio_channel_file_preadv instead of the _full
variant
---
include/migration/qemu-file-types.h | 2 +
migration/qemu-file.c | 80 +++++++++++++++++++++++++++++
migration/qemu-file.h | 4 ++
3 files changed, 86 insertions(+)
diff --git a/include/migration/qemu-file-types.h
b/include/migration/qemu-file-types.h
index 2867e3da84..eb0325ee86 100644
--- a/include/migration/qemu-file-types.h
+++ b/include/migration/qemu-file-types.h
@@ -50,6 +50,8 @@ unsigned int qemu_get_be16(QEMUFile *f);
unsigned int qemu_get_be32(QEMUFile *f);
uint64_t qemu_get_be64(QEMUFile *f);
+bool qemu_file_is_seekable(QEMUFile *f);
+
static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
{
qemu_put_be64(f, *pv);
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 102ab3b439..a1f7dbb3d9 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -30,6 +30,7 @@
#include "qemu-file.h"
#include "trace.h"
#include "qapi/error.h"
+#include "io/channel-file.h"
#define IO_BUF_SIZE 32768
#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)
@@ -281,6 +282,10 @@ static void qemu_iovec_release_ram(QEMUFile *f)
memset(f->may_free, 0, sizeof(f->may_free));
}
+bool qemu_file_is_seekable(QEMUFile *f)
+{
+ return qio_channel_has_feature(f->ioc, QIO_CHANNEL_FEATURE_SEEKABLE);
+}
/**
* Flushes QEMUFile buffer
@@ -559,6 +564,81 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf,
size_t size)
}
}
+void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, off_t
pos)
+{
+ Error *err = NULL;
+
+ if (f->last_error) {
+ return;
+ }
+
+ qemu_fflush(f);
+ qio_channel_pwritev(f->ioc, (char *)buf, buflen, pos, &err);
+
+ if (err) {
+ qemu_file_set_error_obj(f, -EIO, err);
+ } else {
+ f->total_transferred += buflen;
+ }
+
+ return;
+}
+
+
+size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
off_t pos)
+{
+ Error *err = NULL;
+ ssize_t ret;
+
+ if (f->last_error) {
+ return 0;
+ }
+
+ ret = qio_channel_preadv(f->ioc, (char *)buf, buflen, pos, &err);
+ if (ret == -1 || err) {
+ goto error;
+ }
+
+ return (size_t)ret;
+
+ error:
+ qemu_file_set_error_obj(f, -EIO, err);
+ return 0;
+}
+
+void qemu_set_offset(QEMUFile *f, off_t off, int whence)
+{
+ Error *err = NULL;
+ off_t ret;
+
+ qemu_fflush(f);
+
+ if (!qemu_file_is_writable(f)) {
+ f->buf_index = 0;
+ f->buf_size = 0;
+ }
+
+ ret = qio_channel_io_seek(f->ioc, off, whence, &err);
+ if (ret == (off_t)-1) {
+ qemu_file_set_error_obj(f, -EIO, err);
+ }
+}
+
+off_t qemu_get_offset(QEMUFile *f)
+{
+ Error *err = NULL;
+ off_t ret;
+
+ qemu_fflush(f);
+
+ ret = qio_channel_io_seek(f->ioc, 0, SEEK_CUR, &err);
+ if (ret == (off_t)-1) {
+ qemu_file_set_error_obj(f, -EIO, err);
+ }
+ return ret;
+}
+
+
void qemu_put_byte(QEMUFile *f, int v)
{
if (f->last_error) {
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index 9d0155a2a1..350273b441 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -149,6 +149,10 @@ QEMUFile *qemu_file_get_return_path(QEMUFile *f);
void qemu_fflush(QEMUFile *f);
void qemu_file_set_blocking(QEMUFile *f, bool block);
int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
+void qemu_set_offset(QEMUFile *f, off_t off, int whence);
+off_t qemu_get_offset(QEMUFile *f);
+void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, off_t
pos);
+size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
off_t pos);
void ram_control_before_iterate(QEMUFile *f, uint64_t flags);
void ram_control_after_iterate(QEMUFile *f, uint64_t flags);
--
2.35.3
- [RFC PATCH v1 00/26] migration: File based migration with multifd and fixed-ram, Fabiano Rosas, 2023/03/30
- [RFC PATCH v1 02/26] migration: Add support for 'file:' uri for incoming migration, Fabiano Rosas, 2023/03/30
- [RFC PATCH v1 04/26] tests/qtest: migration-test: Add tests for file-based migration, Fabiano Rosas, 2023/03/30
- [RFC PATCH v1 01/26] migration: Add support for 'file:' uri for source migration, Fabiano Rosas, 2023/03/30
- [RFC PATCH v1 03/26] tests/qtest: migration: Add migrate_incoming_qmp helper, Fabiano Rosas, 2023/03/30
- [RFC PATCH v1 05/26] migration: Initial support of fixed-ram feature for analyze-migration.py, Fabiano Rosas, 2023/03/30
- [RFC PATCH v1 06/26] io: add and implement QIO_CHANNEL_FEATURE_SEEKABLE for channel file, Fabiano Rosas, 2023/03/30
- [RFC PATCH v1 08/26] io: implement io_pwritev/preadv for QIOChannelFile, Fabiano Rosas, 2023/03/30
- [RFC PATCH v1 07/26] io: Add generic pwritev/preadv interface, Fabiano Rosas, 2023/03/30
- [RFC PATCH v1 09/26] migration/qemu-file: add utility methods for working with seekable channels,
Fabiano Rosas <=
- [RFC PATCH v1 10/26] migration/ram: Introduce 'fixed-ram' migration stream capability, Fabiano Rosas, 2023/03/30
- Re: [RFC PATCH v1 10/26] migration/ram: Introduce 'fixed-ram' migration stream capability, Fabiano Rosas, 2023/03/31
Re: [RFC PATCH v1 10/26] migration/ram: Introduce 'fixed-ram' migration stream capability, Markus Armbruster, 2023/03/31
[RFC PATCH v1 11/26] migration: Refactor precopy ram loading code, Fabiano Rosas, 2023/03/30
[RFC PATCH v1 12/26] migration: Add support for 'fixed-ram' migration restore, Fabiano Rosas, 2023/03/30