From 12a6d66366a976f2ddc7700d996d51c1ff6a4ed5 Mon Sep 17 00:00:00 2001 From: Ricardo Abreu Date: Thu, 14 Dec 2023 11:49:12 +0000 Subject: [PATCH] [daemon] Add snapshot settings only if supported --- src/daemon/daemon.cpp | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 1ec668f4c9..af7d443d57 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -1209,10 +1209,21 @@ mp::SettingsHandler* register_instance_mod(std::unordered_map& operative_instances, const std::unordered_map& deleted_instances, - const std::unordered_set& preparing_instances) + const std::unordered_set& preparing_instances, + const mp::VirtualMachineFactory& vm_factory) { - return MP_SETTINGS.register_handler( - std::make_unique(operative_instances, deleted_instances, preparing_instances)); + try + { + vm_factory.require_snapshots_support(); + return MP_SETTINGS.register_handler( + std::make_unique(operative_instances, deleted_instances, preparing_instances)); + } + catch (const mp::NotImplementedOnThisBackendException& e) + { + assert(std::string{e.what()}.find("snapshots") != std::string::npos); + } + + return nullptr; } // Erase any outdated mount handlers for a given VM @@ -1330,7 +1341,8 @@ mp::Daemon::Daemon(std::unique_ptr the_config) deleted_instances, preparing_instances, [this] { persist_instances(); })}, - snapshot_mod_handler{register_snapshot_mod(operative_instances, deleted_instances, preparing_instances)} + snapshot_mod_handler{ + register_snapshot_mod(operative_instances, deleted_instances, preparing_instances, *config->factory)} { connect_rpc(daemon_rpc, *this); std::vector invalid_specs;