qemu_file_new_impl() takes its own reference and qemu_fclose() drops exactly one, so the reference from qio_channel_savevm_async_new() was never released. The channel also holds a BlockBackend reference that only its finalizer drops, so both leaked on every snapshot.
Signed-off-by: Erik Fastermann <[email protected]> --- ...async-for-background-state-snapshots.patch | 15 ++++++++++----- ...add-optional-buffer-size-to-QEMUFile.patch | 19 +++++++++---------- ...se-migration-blocker-check-for-snaps.patch | 2 +- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/debian/patches/pve/0017-PVE-add-savevm-async-for-background-state-snapshots.patch b/debian/patches/pve/0017-PVE-add-savevm-async-for-background-state-snapshots.patch index ce9df5c..f252236 100644 --- a/debian/patches/pve/0017-PVE-add-savevm-async-for-background-state-snapshots.patch +++ b/debian/patches/pve/0017-PVE-add-savevm-async-for-background-state-snapshots.patch @@ -37,19 +37,21 @@ Signed-off-by: Stefan Reiter <[email protected]> add parameter to skip vm start to be used for hibernation rebase for 11.0.0] Signed-off-by: Fiona Ebner <[email protected]> +[EF: drop QIOChannel reference] +Signed-off-by: Erik Fastermann <[email protected]> --- hmp-commands-info.hx | 13 + hmp-commands.hx | 17 + include/migration/snapshot.h | 2 + include/monitor/hmp.h | 3 + migration/meson.build | 1 + - migration/savevm-async.c | 597 +++++++++++++++++++++++++++++++++++ + migration/savevm-async.c | 600 +++++++++++++++++++++++++++++++++++ monitor/hmp-cmds.c | 38 +++ qapi/migration.json | 34 ++ qapi/misc.json | 25 ++ qemu-options.hx | 12 + system/vl.c | 10 + - 11 files changed, 752 insertions(+) + 11 files changed, 755 insertions(+) create mode 100644 migration/savevm-async.c diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx @@ -147,10 +149,10 @@ index 0222d5ea6e..90d62d5723 100644 ), gnutls, zlib) diff --git a/migration/savevm-async.c b/migration/savevm-async.c new file mode 100644 -index 0000000000..2a860f11a1 +index 0000000000..cab08643ad --- /dev/null +++ b/migration/savevm-async.c -@@ -0,0 +1,597 @@ +@@ -0,0 +1,600 @@ +#include "qemu/osdep.h" +#include "migration/channel-savevm-async.h" +#include "migration/migration.h" @@ -572,6 +574,7 @@ index 0000000000..2a860f11a1 + QIOChannel *ioc = QIO_CHANNEL(qio_channel_savevm_async_new(snap_state.target, + &snap_state.bs_pos)); + snap_state.file = qemu_file_new_output(ioc); ++ object_unref(ioc); + + if (!snap_state.file) { + error_setg(errp, "failed to open '%s'", statefile); @@ -708,7 +711,9 @@ index 0000000000..2a860f11a1 + bdrv_op_block_all(bs, blocker); + + /* restore the VM state */ -+ f = qemu_file_new_input(QIO_CHANNEL(qio_channel_savevm_async_new(be, &bs_pos))); ++ QIOChannel *ioc = QIO_CHANNEL(qio_channel_savevm_async_new(be, &bs_pos)); ++ f = qemu_file_new_input(ioc); ++ object_unref(ioc); + if (!f) { + error_setg(errp, "Could not open VM state file"); + goto the_end; diff --git a/debian/patches/pve/0018-PVE-add-optional-buffer-size-to-QEMUFile.patch b/debian/patches/pve/0018-PVE-add-optional-buffer-size-to-QEMUFile.patch index b56dd34..39cacf7 100644 --- a/debian/patches/pve/0018-PVE-add-optional-buffer-size-to-QEMUFile.patch +++ b/debian/patches/pve/0018-PVE-add-optional-buffer-size-to-QEMUFile.patch @@ -17,8 +17,8 @@ Signed-off-by: Erik Fastermann <[email protected]> --- migration/qemu-file.c | 48 +++++++++++++++++++++++++++------------- migration/qemu-file.h | 2 ++ - migration/savevm-async.c | 5 +++-- - 3 files changed, 38 insertions(+), 17 deletions(-) + migration/savevm-async.c | 4 ++-- + 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/migration/qemu-file.c b/migration/qemu-file.c index 9cf7dc3bd5..b1b7aa453e 100644 @@ -186,7 +186,7 @@ index a390554208..eda093b16a 100644 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QEMUFile, qemu_fclose) diff --git a/migration/savevm-async.c b/migration/savevm-async.c -index 2a860f11a1..f5a4819e27 100644 +index cab08643ad..f9eaf3b8e6 100644 --- a/migration/savevm-async.c +++ b/migration/savevm-async.c @@ -418,7 +418,7 @@ void qmp_savevm_start(const char *statefile, bool has_skip_vm_start, @@ -195,16 +195,15 @@ index 2a860f11a1..f5a4819e27 100644 &snap_state.bs_pos)); - snap_state.file = qemu_file_new_output(ioc); + snap_state.file = qemu_file_new_output_sized(ioc, 4 * 1024 * 1024); + object_unref(ioc); if (!snap_state.file) { - error_setg(errp, "failed to open '%s'", statefile); -@@ -555,7 +555,8 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp) - bdrv_op_block_all(bs, blocker); +@@ -557,7 +557,7 @@ int load_snapshot_from_blockdev(const char *filename, Error **errp) /* restore the VM state */ -- f = qemu_file_new_input(QIO_CHANNEL(qio_channel_savevm_async_new(be, &bs_pos))); -+ f = qemu_file_new_input_sized(QIO_CHANNEL(qio_channel_savevm_async_new(be, &bs_pos)), -+ 4 * 1024 * 1024); + QIOChannel *ioc = QIO_CHANNEL(qio_channel_savevm_async_new(be, &bs_pos)); +- f = qemu_file_new_input(ioc); ++ f = qemu_file_new_input_sized(ioc, 4 * 1024 * 1024); + object_unref(ioc); if (!f) { error_setg(errp, "Could not open VM state file"); - goto the_end; diff --git a/debian/patches/pve/0046-savevm-async-reuse-migration-blocker-check-for-snaps.patch b/debian/patches/pve/0046-savevm-async-reuse-migration-blocker-check-for-snaps.patch index 25a06a6..5cc3893 100644 --- a/debian/patches/pve/0046-savevm-async-reuse-migration-blocker-check-for-snaps.patch +++ b/debian/patches/pve/0046-savevm-async-reuse-migration-blocker-check-for-snaps.patch @@ -136,7 +136,7 @@ index b6888daced..80eb0dcd1f 100644 bool migration_in_postcopy(void); bool migration_postcopy_is_alive(MigrationStatus state); diff --git a/migration/savevm-async.c b/migration/savevm-async.c -index f5a4819e27..41376406eb 100644 +index f9eaf3b8e6..51340c5dcd 100644 --- a/migration/savevm-async.c +++ b/migration/savevm-async.c @@ -384,7 +384,7 @@ void qmp_savevm_start(const char *statefile, bool has_skip_vm_start, -- 2.47.3
