]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
qemu-file: qemu_file_get_fd(): improve interface
authorVladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Wed, 14 Jan 2026 06:47:10 +0000 (09:47 +0300)
committerFabiano Rosas <farosas@suse.de>
Fri, 23 Jan 2026 14:24:18 +0000 (11:24 -0300)
Make it symmetrical with qemu_file_put_fd() and simplify callers.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/qemu-devel/20260114064710.176268-6-vsementsov@yandex-team.ru
Signed-off-by: Fabiano Rosas <farosas@suse.de>
migration/qemu-file.c
migration/qemu-file.h
migration/vmstate-types.c

index 8fdb6c87ea1bdee866cda4e5fb0f88e4064aa764..9cf7dc3bd5c4677b50f8da6f85b4c78f94092919 100644 (file)
@@ -385,9 +385,8 @@ int qemu_file_put_fd(QEMUFile *f, int fd)
     return ret;
 }
 
-int qemu_file_get_fd(QEMUFile *f)
+int qemu_file_get_fd(QEMUFile *f, int *fd)
 {
-    int fd = -1;
     FdEntry *fde;
     Error *err = NULL;
     int service_byte;
@@ -410,12 +409,12 @@ int qemu_file_get_fd(QEMUFile *f)
         goto fail;
     }
 
-    fd = fde->fd;
+    *fd = fde->fd;
     QTAILQ_REMOVE(&f->fds, fde, entry);
     g_free(fde);
 
-    trace_qemu_file_get_fd(f->ioc->name, fd);
-    return fd;
+    trace_qemu_file_get_fd(f->ioc->name, *fd);
+    return 0;
 
 fail:
     error_report_err(error_copy(err));
index c13c96716702cef0d7c7754194e19637cb2b7a70..a8e9bb2ccb016b23b218e9a001b8a25762b0e088 100644 (file)
@@ -82,6 +82,6 @@ size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen,
 
 QIOChannel *qemu_file_get_ioc(QEMUFile *file);
 int qemu_file_put_fd(QEMUFile *f, int fd);
-int qemu_file_get_fd(QEMUFile *f);
+int qemu_file_get_fd(QEMUFile *f, int *fd);
 
 #endif
index e34bf4486ed5f2a27c45611e9e4ba474cc792228..89cb21147217ebf86c1e52a9410528266ec7f753 100644 (file)
@@ -321,7 +321,6 @@ const VMStateInfo vmstate_info_uint64 = {
 static int get_fd(QEMUFile *f, void *pv, size_t size,
                   const VMStateField *field)
 {
-    int fd;
     int32_t *v = pv;
 
     if (migrate_mode() == MIG_MODE_CPR_EXEC) {
@@ -329,14 +328,7 @@ static int get_fd(QEMUFile *f, void *pv, size_t size,
         return 0;
     }
 
-    fd = qemu_file_get_fd(f);
-    if (fd < 0) {
-        return -1;
-    }
-
-    *v = fd;
-
-    return 0;
+    return qemu_file_get_fd(f, v);
 }
 
 static int put_fd(QEMUFile *f, void *pv, size_t size,