From 24a50d61889827437d52de0cb57da4b769d828fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 20 Oct 2014 16:13:50 +0200 Subject: [PATCH] Bug #3168: Rollback in Datastore::post_update_template --- src/datastore/Datastore.cc | 64 +++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 29 deletions(-) diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 7a8ed8f665..9a46e24afe 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -594,12 +594,15 @@ int Datastore::post_update_template(string& error_str) Image::DiskType new_disk_type; + DatastoreType old_ds_type; DatastoreType new_ds_type; /* ---------------------------------------------------------------------- */ /* Set the TYPE of the Datastore (class & template) */ /* ---------------------------------------------------------------------- */ + old_ds_type = type; + get_template_attribute("TYPE", s_ds_type); if (!s_ds_type.empty()) @@ -626,6 +629,36 @@ int Datastore::post_update_template(string& error_str) replace_template_attribute("TYPE", type_to_str(type)); + /* ---------------------------------------------------------------------- */ + /* Set the TM_MAD of the Datastore (class & template) */ + /* ---------------------------------------------------------------------- */ + + get_template_attribute("TM_MAD", new_tm_mad); + + if ( !new_tm_mad.empty() ) + { + // System DS are monitored by the TM mad, reset information + if ( type == SYSTEM_DS && new_tm_mad != tm_mad ) + { + update_monitor(0, 0, 0); + } + + if (set_tm_mad(new_tm_mad, error_str) != 0) + { + replace_template_attribute("TM_MAD", tm_mad); + + type = old_ds_type; + + return -1; + } + + tm_mad = new_tm_mad; + } + else + { + replace_template_attribute("TM_MAD", tm_mad); + } + /* ---------------------------------------------------------------------- */ /* Set the DISK_TYPE (class & template) */ /* ---------------------------------------------------------------------- */ @@ -651,13 +684,12 @@ int Datastore::post_update_template(string& error_str) disk_type = Image::FILE; } - get_template_attribute("DS_MAD", new_ds_mad); - get_template_attribute("TM_MAD", new_tm_mad); - /* ---------------------------------------------------------------------- */ /* Set the DS_MAD of the Datastore (class & template) */ /* ---------------------------------------------------------------------- */ + get_template_attribute("DS_MAD", new_ds_mad); + if ( type == SYSTEM_DS ) { ds_mad = "-"; @@ -679,32 +711,6 @@ int Datastore::post_update_template(string& error_str) } } - /* ---------------------------------------------------------------------- */ - /* Set the TM_MAD of the Datastore (class & template) */ - /* ---------------------------------------------------------------------- */ - - if ( !new_tm_mad.empty() ) - { - // System DS are monitored by the TM mad, reset information - if ( type == SYSTEM_DS && new_tm_mad != tm_mad ) - { - update_monitor(0, 0, 0); - } - - if (set_tm_mad(new_tm_mad, error_str) != 0) - { - replace_template_attribute("TM_MAD", tm_mad); - - return -1; - } - - tm_mad = new_tm_mad; - } - else - { - replace_template_attribute("TM_MAD", tm_mad); - } - /* ---------------------------------------------------------------------- */ /* Set the BASE_PATH of the Datastore (class & template) */ /* ---------------------------------------------------------------------- */