Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public underpinings for Hyper-V snapshots - take 2 #3214

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions src/platform/backends/qemu/qemu_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ namespace mpp = mp::platform;

namespace
{
const auto snapshot_template = QStringLiteral("@%1"); /* avoid colliding with suspension snapshots; prefix with a char
that can't be part of the name, to avoid confusion */

std::unique_ptr<mp::QemuImgProcessSpec> make_capture_spec(const QString& tag, const mp::Path& image_path)
{
return std::make_unique<mp::QemuImgProcessSpec>(QStringList{"snapshot", "-c", tag, image_path},
Expand Down Expand Up @@ -80,7 +77,7 @@ mp::QemuSnapshot::QemuSnapshot(const QJsonObject& json, QemuVirtualMachine& vm,

void mp::QemuSnapshot::capture_impl()
{
auto tag = derive_tag();
auto tag = derive_id();

// Avoid creating more than one snapshot with the same tag (creation would succeed, but we'd then be unable to
// identify the snapshot by tag)
Expand All @@ -93,7 +90,7 @@ void mp::QemuSnapshot::capture_impl()

void mp::QemuSnapshot::erase_impl()
{
checked_exec_qemu_img(make_delete_spec(derive_tag(), image_path));
checked_exec_qemu_img(make_delete_spec(derive_id(), image_path));
}

void mp::QemuSnapshot::apply_impl()
Expand All @@ -105,11 +102,6 @@ void mp::QemuSnapshot::apply_impl()
desc.mem_size = get_mem_size();
desc.disk_space = get_disk_space();

checked_exec_qemu_img(make_restore_spec(derive_tag(), image_path));
checked_exec_qemu_img(make_restore_spec(derive_id(), image_path));
rollback.dismiss();
}

QString mp::QemuSnapshot::derive_tag() const
{
return snapshot_template.arg(get_name().c_str());
}
3 changes: 0 additions & 3 deletions src/platform/backends/qemu/qemu_snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class QemuSnapshot : public BaseSnapshot
void erase_impl() override;
void apply_impl() override;

private:
QString derive_tag() const;

private:
VirtualMachineDescription& desc;
const Path& image_path;
Expand Down
8 changes: 8 additions & 0 deletions src/platform/backends/shared/base_snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ namespace mp = multipass;

namespace
{
const auto snapshot_template = QStringLiteral("@%1"); /* avoid colliding with suspension snapshots; prefix with a char
that can't be part of the name, to avoid confusion */

std::unordered_map<std::string, mp::VMMount> load_mounts(const QJsonArray& json)
{
std::unordered_map<std::string, mp::VMMount> mounts;
Expand Down Expand Up @@ -197,3 +200,8 @@ QJsonObject multipass::BaseSnapshot::serialize() const

return ret;
}

QString multipass::BaseSnapshot::derive_id() const
{
return snapshot_template.arg(get_name().c_str());
}
2 changes: 2 additions & 0 deletions src/platform/backends/shared/base_snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class BaseSnapshot : public Snapshot
virtual void erase_impl() = 0;
virtual void apply_impl() = 0;

QString derive_id() const;

private:
struct InnerJsonTag
{
Expand Down