Skip to content

Commit

Permalink
[qemu] Update mount args when applying a snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
ricab committed Jul 4, 2023
1 parent 748c99a commit 1ca344e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
2 changes: 2 additions & 0 deletions src/platform/backends/qemu/qemu_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
34 changes: 17 additions & 17 deletions src/platform/backends/qemu/qemu_virtual_machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QJsonObject>& resume_metadata,
const mp::QemuVirtualMachine::MountArgs& mount_args, const QStringList& platform_args)
{
Expand Down Expand Up @@ -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<Snapshot> parent)
-> std::shared_ptr<Snapshot>
Expand Down
2 changes: 2 additions & 0 deletions src/platform/backends/qemu/qemu_virtual_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class QemuVirtualMachine : public QObject, public BaseVirtualMachine
std::unique_ptr<MountHandler> 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();
Expand Down

0 comments on commit 1ca344e

Please sign in to comment.