From 1ca344e4f160f71d21be9d02145184c2d5edd35e Mon Sep 17 00:00:00 2001 From: Ricardo Abreu Date: Thu, 22 Jun 2023 12:27:18 +0100 Subject: [PATCH] [qemu] Update mount args when applying a snapshot --- src/platform/backends/qemu/qemu_snapshot.cpp | 2 ++ .../backends/qemu/qemu_virtual_machine.cpp | 34 +++++++++---------- .../backends/qemu/qemu_virtual_machine.h | 2 ++ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/platform/backends/qemu/qemu_snapshot.cpp b/src/platform/backends/qemu/qemu_snapshot.cpp index b4c7b6a7546..592dce48a18 100644 --- a/src/platform/backends/qemu/qemu_snapshot.cpp +++ b/src/platform/backends/qemu/qemu_snapshot.cpp @@ -104,6 +104,8 @@ void mp::QemuSnapshot::apply_impl() desc.mem_size = get_mem_size(); desc.disk_space = get_disk_space(); + mount_args = QemuVirtualMachine::mount_args_from_json(BaseSnapshot::get_metadata()); + checked_exec_qemu_img(make_restore_spec(derive_tag(), image_path)); rollback.dismiss(); } diff --git a/src/platform/backends/qemu/qemu_virtual_machine.cpp b/src/platform/backends/qemu/qemu_virtual_machine.cpp index 8b9d130a510..6523dc7d546 100644 --- a/src/platform/backends/qemu/qemu_virtual_machine.cpp +++ b/src/platform/backends/qemu/qemu_virtual_machine.cpp @@ -88,23 +88,6 @@ QStringList get_arguments(const QJsonObject& metadata) return args; } -auto mount_args_from_json(const QJsonObject& object) -{ - mp::QemuVirtualMachine::MountArgs mount_args; - auto mount_data_map = object[mount_data_key].toObject(); - for (const auto& tag : mount_data_map.keys()) - { - const auto mount_data = mount_data_map[tag].toObject(); - const auto source = mount_data[mount_source_key]; - const auto args = mount_data[mount_arguments_key].toArray(); - if (!source.isString() || !std::all_of(args.begin(), args.end(), std::mem_fn(&QJsonValue::isString))) - continue; - mount_args[tag.toStdString()] = {source.toString().toStdString(), - QVariant{args.toVariantList()}.toStringList()}; - } - return mount_args; -} - auto make_qemu_process(const mp::VirtualMachineDescription& desc, const std::optional& resume_metadata, const mp::QemuVirtualMachine::MountArgs& mount_args, const QStringList& platform_args) { @@ -613,6 +596,23 @@ mp::QemuVirtualMachine::MountArgs& mp::QemuVirtualMachine::modifiable_mount_args return mount_args; } +auto mp::QemuVirtualMachine::mount_args_from_json(const QJsonObject& object) -> MountArgs +{ + mp::QemuVirtualMachine::MountArgs mount_args; + auto mount_data_map = object[mount_data_key].toObject(); + for (const auto& tag : mount_data_map.keys()) + { + const auto mount_data = mount_data_map[tag].toObject(); + const auto source = mount_data[mount_source_key]; + const auto args = mount_data[mount_arguments_key].toArray(); + if (!source.isString() || !std::all_of(args.begin(), args.end(), std::mem_fn(&QJsonValue::isString))) + continue; + mount_args[tag.toStdString()] = {source.toString().toStdString(), + QVariant{args.toVariantList()}.toStringList()}; + } + return mount_args; +} + auto mp::QemuVirtualMachine::make_specific_snapshot(const std::string& name, const std::string& comment, const VMSpecs& specs, std::shared_ptr parent) -> std::shared_ptr diff --git a/src/platform/backends/qemu/qemu_virtual_machine.h b/src/platform/backends/qemu/qemu_virtual_machine.h index de1086c5eae..25d94d042cb 100644 --- a/src/platform/backends/qemu/qemu_virtual_machine.h +++ b/src/platform/backends/qemu/qemu_virtual_machine.h @@ -64,6 +64,8 @@ class QemuVirtualMachine : public QObject, public BaseVirtualMachine std::unique_ptr make_native_mount_handler(const SSHKeyProvider* ssh_key_provider, const std::string& target, const VMMount& mount) override; + static MountArgs mount_args_from_json(const QJsonObject& metadata); + signals: void on_delete_memory_snapshot(); void on_reset_network();