From 146ca09e08040b789dc753013e61b35fdf58e890 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 1 Mar 2013 19:04:56 +0100 Subject: [PATCH 01/14] feature #1791: new saveas hot functionality in the core --- include/Image.h | 12 +++ include/ImageTemplate.h | 20 ++++ include/LifeCycleManager.h | 6 ++ include/RequestManagerVirtualMachine.h | 2 +- include/TransferManager.h | 7 ++ include/VirtualMachine.h | 15 ++- src/image/ImageManagerDriver.cc | 53 ++++++++-- src/image/ImageTemplate.cc | 3 +- src/lcm/LifeCycleManager.cc | 16 +++ src/lcm/LifeCycleStates.cc | 36 +++++++ src/rm/RequestManagerVirtualMachine.cc | 11 +++ src/tm/TransferManager.cc | 131 +++++++++++++++++++++++++ src/tm/TransferManagerDriver.cc | 8 ++ src/vm/VirtualMachine.cc | 61 ++++++++++++ 14 files changed, 370 insertions(+), 11 deletions(-) diff --git a/include/Image.h b/include/Image.h index 08949f6c72..29284b9d3b 100644 --- a/include/Image.h +++ b/include/Image.h @@ -348,6 +348,18 @@ public: return it->is_saving(); } + /** + * Check if the image is a hot snapshot + * @return true if image is a hot snapshot + */ + bool isHot() + { + ImageTemplate * it = static_cast(obj_template); + + return it->is_hot(); + } + + /** * Set permissions for the Image. Extends the PoolSQLObject method * by checking the persistent state of the image. diff --git a/include/ImageTemplate.h b/include/ImageTemplate.h index 7f7b0b2a43..6cddd2eda7 100644 --- a/include/ImageTemplate.h +++ b/include/ImageTemplate.h @@ -52,6 +52,15 @@ public: return (saving.empty() == false); } + bool is_hot() + { + string snapshot_hot; + + get(snapshot_hot_attribute, snapshot_hot); + + return (snapshot_hot.empty() == false); + } + void set_saving() { SingleAttribute * attr= new SingleAttribute(saving_attribute, "YES"); @@ -61,6 +70,16 @@ public: set(attr); } + void set_snapshot_hot() + { + SingleAttribute * attr = new SingleAttribute( + snapshot_hot_attribute, "YES"); + + erase(snapshot_hot_attribute); + + set(attr); + } + void unset_saving() { erase(saving_attribute); @@ -72,6 +91,7 @@ private: static vector restricted_attributes; static string saving_attribute; + static string snapshot_hot_attribute; /** * Stores the attributes as restricted, these attributes will be used in diff --git a/include/LifeCycleManager.h b/include/LifeCycleManager.h index 34d7eece7c..5702178dd6 100644 --- a/include/LifeCycleManager.h +++ b/include/LifeCycleManager.h @@ -64,6 +64,8 @@ public: DETACH_FAILURE, /**< Sent by the VMM when a detach action fails */ CLEANUP_SUCCESS, /**< Sent by the VMM when a cleanup action succeeds */ CLEANUP_FAILURE, /**< Sent by the VMM when a cleanup action fails */ + HOTPLUG_SAVEAS_SUCCESS, /**< Sent by the VMM when hot saveas succeeds */ + HOTPLUG_SAVEAS_FAILURE, /**< Sent by the VMM when hot saveas fails */ DEPLOY, /**< Sent by the DM to deploy a VM on a host */ SUSPEND, /**< Sent by the DM to suspend an running VM */ RESTORE, /**< Sent by the DM to restore a suspended VM */ @@ -187,6 +189,10 @@ private: void detach_failure_action(int vid); + void hotplug_saveas_success_action(int vid); + + void hotplug_saveas_failure_action(int vid); + void cleanup_callback_action(int vid); void deploy_action(int vid); diff --git a/include/RequestManagerVirtualMachine.h b/include/RequestManagerVirtualMachine.h index b4bf5a9852..63f22fe44a 100644 --- a/include/RequestManagerVirtualMachine.h +++ b/include/RequestManagerVirtualMachine.h @@ -152,7 +152,7 @@ public: VirtualMachineSaveDisk(): RequestManagerVirtualMachine("VirtualMachineSaveDisk", "Saves a disk from virtual machine as a new image", - "A:siiss"){}; + "A:siissb"){}; ~VirtualMachineSaveDisk(){}; diff --git a/include/TransferManager.h b/include/TransferManager.h index a31a8484bb..085eeeedbe 100644 --- a/include/TransferManager.h +++ b/include/TransferManager.h @@ -153,6 +153,13 @@ public: ostream& xfr, bool local, bool previous); + + + /** + * This function starts the hot saveas of an image + */ + void saveas_hot_transfer_command(int vid, int disk_id, string& save_source); + private: /** * Thread id for the Transfer Manager diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index be43d917ca..4bb9c61d44 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -89,7 +89,8 @@ public: BOOT_POWEROFF = 20, BOOT_SUSPENDED = 21, BOOT_STOPPED = 22, - CLEANUP_DELETE = 23 + CLEANUP_DELETE = 23, + HOTPLUG_SAVEAS = 24 }; // ------------------------------------------------------------------------- @@ -953,6 +954,18 @@ public: */ int detach_failure(); + /** + * Sets the hotplug_saveas attribute to the given disk + * @param disk_id of the DISK + * @return 0 if the disk_id was found -1 otherwise + */ + int set_hotplug_saveas(int disk_id); + + /** + * Cleans the HOTPLUG_SAVEAS = YES attribute from the disks + */ + void clear_hotplug_saveas(); + private: // ------------------------------------------------------------------------- diff --git a/src/image/ImageManagerDriver.cc b/src/image/ImageManagerDriver.cc index a252e219ae..64196c7a9e 100644 --- a/src/image/ImageManagerDriver.cc +++ b/src/image/ImageManagerDriver.cc @@ -319,6 +319,7 @@ static void mkfs_action(istringstream& is, string source; Image * image; bool is_saving; + bool is_hot; string disk_id; string vm_id; @@ -373,6 +374,8 @@ static void mkfs_action(istringstream& is, is_saving = image->isSaving(); + is_hot = image->isHot(); + image->set_source(source); if (is_saving) @@ -396,8 +399,6 @@ static void mkfs_action(istringstream& is, return; } - /* ---------------- Set up information for the Saved Image -------------- */ - vm = vmpool->get(vm_id, true); if ( vm == 0 ) @@ -405,14 +406,50 @@ static void mkfs_action(istringstream& is, goto error_save_get; } - rc = vm->save_disk(disk_id, source, id); - - if ( rc == -1 ) + if ( is_hot ) { - goto error_save_state; - } + istringstream iss; + int vm_oid; + int disk_oid; - vmpool->update(vm); + /* change state */ + + iss.str(vm_id); + iss >> vm_oid; + + iss.clear(); + + iss.str(disk_id); + iss >> disk_oid; + + vm->set_state(VirtualMachine::HOTPLUG_SAVEAS); + vm->set_hotplug_saveas(disk_oid); + + vm->set_resched(false); + + vmpool->update(vm); + + vm->log("LCM", Log::INFO, "New VM state is HOTPLUG_SAVEAS"); + + /* call tm */ + + TransferManager * tm = nd.get_tm(); + + vm->unlock(); + tm->saveas_hot_transfer_command(vm_oid, disk_oid, source); + } + else + { + /* -------------- Set up information for the Saved Image ------------ */ + rc = vm->save_disk(disk_id, source, id); + + if ( rc == -1 ) + { + goto error_save_state; + } + + vmpool->update(vm); + } vm->unlock(); diff --git a/src/image/ImageTemplate.cc b/src/image/ImageTemplate.cc index 802569bfc0..543491a7ec 100644 --- a/src/image/ImageTemplate.cc +++ b/src/image/ImageTemplate.cc @@ -21,7 +21,8 @@ vector ImageTemplate::restricted_attributes; -string ImageTemplate::saving_attribute = "SAVE_AS"; +string ImageTemplate::saving_attribute = "SAVE_AS"; +string ImageTemplate::snapshot_hot_attribute = "SNAPSHOT_HOT"; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/lcm/LifeCycleManager.cc b/src/lcm/LifeCycleManager.cc index 326da9c36f..7ae2a9ea28 100644 --- a/src/lcm/LifeCycleManager.cc +++ b/src/lcm/LifeCycleManager.cc @@ -145,6 +145,14 @@ void LifeCycleManager::trigger(Actions action, int _vid) aname = "DETACH_FAILURE"; break; + case HOTPLUG_SAVEAS_SUCCESS: + aname = "HOTPLUG_SAVEAS_SUCCESS"; + break; + + case HOTPLUG_SAVEAS_FAILURE: + aname = "HOTPLUG_SAVEAS_FAILURE"; + break; + case CLEANUP_SUCCESS: aname = "CLEANUP_SUCCESS"; break; @@ -306,6 +314,14 @@ void LifeCycleManager::do_action(const string &action, void * arg) { detach_failure_action(vid); } + else if (action == "HOTPLUG_SAVEAS_SUCCESS") + { + hotplug_saveas_success_action(vid); + } + else if (action == "HOTPLUG_SAVEAS_FAILURE") + { + hotplug_saveas_failure_action(vid); + } else if (action == "CLEANUP_SUCCESS") { cleanup_callback_action(vid); diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 8c17bcd206..5e19917dcb 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -1197,3 +1197,39 @@ void LifeCycleManager::detach_failure_action(int vid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ + +void LifeCycleManager::hotplug_saveas_success_action(int vid) +{ + VirtualMachine * vm; + + vm = vmpool->get(vid,true); + + if ( vm == 0 ) + { + return; + } + + if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS) + { + vm->clear_attach_disk(); + + vm->set_state(VirtualMachine::RUNNING); + + vmpool->update(vm); + } + else + { + vm->log("LCM",Log::ERROR,"hotplug_saveas_success_action," + " VM in a wrong state"); + } + + vm->unlock(); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void LifeCycleManager::hotplug_saveas_failure_action(int vid) +{ + hotplug_saveas_success_action(vid); +} diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 51bf57b1b7..180a9e5395 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -690,6 +690,12 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis int disk_id = xmlrpc_c::value_int(paramList.getInt(2)); string img_name = xmlrpc_c::value_string(paramList.getString(3)); string img_type = xmlrpc_c::value_string(paramList.getString(4)); + bool is_hot = false; //Optional XML-RPC argument + + if ( paramList.size() > 5 ) + { + is_hot = xmlrpc_c::value_boolean(paramList.getBoolean(5)); + } VirtualMachine * vm; int iid; @@ -829,6 +835,11 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis itemplate->add("SAVED_DISK_ID",disk_id); itemplate->add("SAVED_VM_ID", id); + if ( is_hot ) + { + itemplate->set_snapshot_hot(); + } + if ( img_type.empty() ) { itemplate->add("TYPE", Image::type_to_str(type)); diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 73393a8456..63ddd30039 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -1625,6 +1625,137 @@ void TransferManager::checkpoint_action(int vid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void TransferManager::saveas_hot_transfer_command(int vid, + int disk_id, + string& save_source) +{ + string save; + string tm_mad; + string ds_id; + + int num; + int disk_id_iter; + + ostringstream os; + + ofstream xfr; + string xfr_name; + + string source; + + const VectorAttribute * disk; + vector attrs; + + VirtualMachine * vm; + Nebula& nd = Nebula::instance(); + + const TransferManagerDriver * tm_md; + + // ------------------------------------------------------------------------ + // Setup & Transfer script + // ------------------------------------------------------------------------ + vm = vmpool->get(vid,true); + + if (vm == 0) + { + vm->log("TM", Log::ERROR, "Could not obtain the VM");; + goto error_common; + } + + if (!vm->hasHistory()) + { + vm->log("TM", Log::ERROR, "The VM has no history");; + goto error_common; + } + + tm_md = get(); + + if (tm_md == 0) + { + goto error_driver; + } + + num = vm->get_template_attribute("DISK",attrs); + + for (int i=0 ; i < num ; i++) + { + disk = dynamic_cast(attrs[i]); + + if ( disk == 0 ) + { + continue; + } + + disk->vector_value("DISK_ID", disk_id_iter); + + if (disk_id == disk_id_iter) + { + tm_mad = disk->vector_value("TM_MAD"); + ds_id = disk->vector_value("DATASTORE_ID"); + + break; + } + } + + if ( ds_id.empty() || tm_mad.empty() ) + { + vm->log("TM", Log::ERROR, "No DS_ID or TM_MAD to save disk image"); + goto error_common; + } + + if (save_source.empty()) + { + vm->log("TM", Log::ERROR, "No SOURCE to save disk image"); + goto error_common; + } + + xfr_name = vm->get_transfer_file() + ".saveas_hot"; + xfr.open(xfr_name.c_str(),ios::out | ios::trunc); + + if (xfr.fail() == true) + { + goto error_file; + } + + //MVDS tm_mad hostname:remote_system_dir/disk.0 vmid dsid + xfr << "CPDS " + << tm_mad << " " + << vm->get_hostname() << ":" + << vm->get_remote_system_dir() << "/disk." << disk_id << " " + << save_source << " " + << vm->get_oid() << " " + << ds_id + << endl; + + xfr.close(); + + tm_md->transfer(vid, xfr_name); + + vm->unlock(); + + return; + +error_driver: + os << "saveas_hot_transfer, error getting TM driver."; + goto error_common; + +error_file: + os << "saveas_hot_transfer, could not open file: " << xfr_name; + os << ". You may need to manually clean hosts (previous & current)"; + goto error_common; + +error_common: + vm->log("TM", Log::ERROR, os); + + (nd.get_lcm())->trigger(LifeCycleManager::HOTPLUG_SAVEAS_FAILURE, vid); + + vm->unlock(); + return; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void TransferManager::migrate_transfer_command( VirtualMachine * vm, ostream& xfr) diff --git a/src/tm/TransferManagerDriver.cc b/src/tm/TransferManagerDriver.cc index 7f5e85cc79..416d44091f 100644 --- a/src/tm/TransferManagerDriver.cc +++ b/src/tm/TransferManagerDriver.cc @@ -131,6 +131,10 @@ void TransferManagerDriver::protocol( lcm_action = LifeCycleManager::EPILOG_SUCCESS; break; + case VirtualMachine::HOTPLUG_SAVEAS: + lcm_action = LifeCycleManager::HOTPLUG_SAVEAS_SUCCESS; + break; + default: goto error_state; } @@ -168,6 +172,10 @@ void TransferManagerDriver::protocol( lcm_action = LifeCycleManager::EPILOG_FAILURE; break; + case VirtualMachine::HOTPLUG_SAVEAS: + lcm_action = LifeCycleManager::HOTPLUG_SAVEAS_FAILURE; + break; + default: goto error_state; } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 7ea7d9576c..94bfec379d 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1854,6 +1854,67 @@ VectorAttribute * VirtualMachine::delete_attach_disk() return 0; } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualMachine::set_hotplug_saveas(int disk_id) +{ + + int num_disks; + int d_id; + + vector disks; + VectorAttribute * disk; + + num_disks = obj_template->get("DISK", disks); + + for(int i=0; i(disks[i]); + + if ( disk == 0 ) + { + continue; + } + + disk->vector_value("DISK_ID", d_id); + + if ( d_id == disk_id ) + { + disk->replace("HOTPLUG_SAVEAS", "YES"); + return 0; + } + } + + return -1; +} +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void VirtualMachine::clear_hotplug_saveas() +{ + int num_disks; + vector disks; + VectorAttribute * disk; + + num_disks = obj_template->get("DISK", disks); + + for(int i=0; i(disks[i]); + + if ( disk == 0 ) + { + continue; + } + + if ( disk->vector_value("HOTPLUG_SAVEAS") == "YES" ) + { + disk->remove("HOTPLUG_SAVEAS"); + return; + } + } +} /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ From 3816c614ef42645389f7feadc28e5fd6cf657c7c Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Wed, 6 Mar 2013 16:09:11 +0100 Subject: [PATCH 02/14] feature #1791: manage the image lifecycle during the saveas hot operation --- include/VirtualMachine.h | 11 ++++- src/image/ImageManagerDriver.cc | 7 ++- src/lcm/LifeCycleStates.cc | 77 ++++++++++++++++++++++++++++++++- src/vm/VirtualMachine.cc | 47 +++++++++++++++++++- 4 files changed, 136 insertions(+), 6 deletions(-) diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 4bb9c61d44..6ec148b6f1 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -954,12 +954,21 @@ public: */ int detach_failure(); + /** + * Get the IMAGE_ID of the image that's being saved as hot + * @param disk_id of the DISK + * @param image_id id of the image being saved + * @return IMAGE_ID on success, -1 otherwise + */ + int get_hotplug_saveas_image_id(); + /** * Sets the hotplug_saveas attribute to the given disk * @param disk_id of the DISK + * @param image_id id of the image being saved * @return 0 if the disk_id was found -1 otherwise */ - int set_hotplug_saveas(int disk_id); + int set_hotplug_saveas(int disk_id, int image_id); /** * Cleans the HOTPLUG_SAVEAS = YES attribute from the disks diff --git a/src/image/ImageManagerDriver.cc b/src/image/ImageManagerDriver.cc index 64196c7a9e..fa09841d88 100644 --- a/src/image/ImageManagerDriver.cc +++ b/src/image/ImageManagerDriver.cc @@ -385,7 +385,10 @@ static void mkfs_action(istringstream& is, } else { - image->set_state(Image::READY); + if ( !is_hot ) + { + image->set_state(Image::READY); + } NebulaLog::log("ImM", Log::INFO, "Image created and ready to use"); } @@ -423,7 +426,7 @@ static void mkfs_action(istringstream& is, iss >> disk_oid; vm->set_state(VirtualMachine::HOTPLUG_SAVEAS); - vm->set_hotplug_saveas(disk_oid); + vm->set_hotplug_saveas(disk_oid, id); vm->set_resched(false); diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 5e19917dcb..36169d6d80 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -1200,7 +1200,14 @@ void LifeCycleManager::detach_failure_action(int vid) void LifeCycleManager::hotplug_saveas_success_action(int vid) { + Nebula& nd = Nebula::instance(); + + ImagePool * ipool = nd.get_ipool(); + VirtualMachine * vm; + Image * image; + + int image_id; vm = vmpool->get(vid,true); @@ -1211,7 +1218,9 @@ void LifeCycleManager::hotplug_saveas_success_action(int vid) if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS) { - vm->clear_attach_disk(); + image_id = vm->get_hotplug_saveas_image_id(); + + vm->clear_hotplug_saveas(); vm->set_state(VirtualMachine::RUNNING); @@ -1224,6 +1233,22 @@ void LifeCycleManager::hotplug_saveas_success_action(int vid) } vm->unlock(); + + + ostringstream oss; + + image = ipool->get(image_id, true); + + if ( image == 0 ) + { + return; + } + + image->set_state(Image::READY); + + ipool->update(image); + + image->unlock(); } /* -------------------------------------------------------------------------- */ @@ -1231,5 +1256,53 @@ void LifeCycleManager::hotplug_saveas_success_action(int vid) void LifeCycleManager::hotplug_saveas_failure_action(int vid) { - hotplug_saveas_success_action(vid); + Nebula& nd = Nebula::instance(); + + ImagePool * ipool = nd.get_ipool(); + + VirtualMachine * vm; + Image * image; + + int image_id; + + vm = vmpool->get(vid,true); + + if ( vm == 0 ) + { + return; + } + + if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS) + { + image_id = vm->get_hotplug_saveas_image_id(); + + vm->clear_hotplug_saveas(); + + vm->set_state(VirtualMachine::RUNNING); + + vmpool->update(vm); + } + else + { + vm->log("LCM",Log::ERROR,"hotplug_saveas_success_action," + " VM in a wrong state"); + } + + vm->unlock(); + + + ostringstream oss; + + image = ipool->get(image_id, true); + + if ( image == 0 ) + { + return; + } + + image->set_state(Image::ERROR); + + ipool->update(image); + + image->unlock(); } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 94bfec379d..020fb8f54e 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1854,10 +1854,51 @@ VectorAttribute * VirtualMachine::delete_attach_disk() return 0; } + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachine::set_hotplug_saveas(int disk_id) +int VirtualMachine::get_hotplug_saveas_image_id() +{ + int num_disks; + vector disks; + VectorAttribute * disk; + + istringstream iss; + string image_id_str; + int image_id; + + num_disks = obj_template->get("DISK", disks); + + for(int i=0; i(disks[i]); + + if ( disk == 0 ) + { + continue; + } + + if ( !disk->vector_value("HOTPLUG_SAVEAS_IMAGE_ID").empty() ) + { + image_id_str = disk->vector_value("HOTPLUG_SAVEAS_IMAGE_ID"); + iss.str(image_id_str); + + iss >> image_id; + + if ( !iss.fail() ) + { + return image_id; + } + } + } + return -1; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualMachine::set_hotplug_saveas(int disk_id, int img_id) { int num_disks; @@ -1882,12 +1923,15 @@ int VirtualMachine::set_hotplug_saveas(int disk_id) if ( d_id == disk_id ) { disk->replace("HOTPLUG_SAVEAS", "YES"); + disk->replace("HOTPLUG_SAVEAS_IMAGE_ID", img_id); + return 0; } } return -1; } + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -1911,6 +1955,7 @@ void VirtualMachine::clear_hotplug_saveas() if ( disk->vector_value("HOTPLUG_SAVEAS") == "YES" ) { disk->remove("HOTPLUG_SAVEAS"); + disk->remove("HOTPLUG_SAVEAS_IMAGE_ID"); return; } } From d74c51e7a4f0ea61e758f94464542c29b8343229 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 7 Mar 2013 13:09:57 +0100 Subject: [PATCH 03/14] feature #1791: set the hotplug_saveas state at the beginning of the action. Allow for suspended and poweroff to be saveas-hot valid states. --- include/VirtualMachine.h | 52 +++++++++-------- src/image/ImageManagerDriver.cc | 79 +++++++++++++------------- src/lcm/LifeCycleStates.cc | 46 ++++++++++++++- src/rm/RequestManagerVirtualMachine.cc | 64 +++++++++++++++++++++ src/tm/TransferManagerDriver.cc | 4 ++ 5 files changed, 177 insertions(+), 68 deletions(-) diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 6ec148b6f1..60dcdaf597 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -66,31 +66,33 @@ public: */ enum LcmState { - LCM_INIT = 0, - PROLOG = 1, - BOOT = 2, - RUNNING = 3, - MIGRATE = 4, - SAVE_STOP = 5, - SAVE_SUSPEND = 6, - SAVE_MIGRATE = 7, - PROLOG_MIGRATE = 8, - PROLOG_RESUME = 9, - EPILOG_STOP = 10, - EPILOG = 11, - SHUTDOWN = 12, - CANCEL = 13, - FAILURE = 14, - CLEANUP_RESUBMIT = 15, - UNKNOWN = 16, - HOTPLUG = 17, - SHUTDOWN_POWEROFF = 18, - BOOT_UNKNOWN = 19, - BOOT_POWEROFF = 20, - BOOT_SUSPENDED = 21, - BOOT_STOPPED = 22, - CLEANUP_DELETE = 23, - HOTPLUG_SAVEAS = 24 + LCM_INIT = 0, + PROLOG = 1, + BOOT = 2, + RUNNING = 3, + MIGRATE = 4, + SAVE_STOP = 5, + SAVE_SUSPEND = 6, + SAVE_MIGRATE = 7, + PROLOG_MIGRATE = 8, + PROLOG_RESUME = 9, + EPILOG_STOP = 10, + EPILOG = 11, + SHUTDOWN = 12, + CANCEL = 13, + FAILURE = 14, + CLEANUP_RESUBMIT = 15, + UNKNOWN = 16, + HOTPLUG = 17, + SHUTDOWN_POWEROFF = 18, + BOOT_UNKNOWN = 19, + BOOT_POWEROFF = 20, + BOOT_SUSPENDED = 21, + BOOT_STOPPED = 22, + CLEANUP_DELETE = 23, + HOTPLUG_SAVEAS = 24, + HOTPLUG_SAVEAS_POWEROFF = 25, + HOTPLUG_SAVEAS_SUSPENDED = 26 }; // ------------------------------------------------------------------------- diff --git a/src/image/ImageManagerDriver.cc b/src/image/ImageManagerDriver.cc index fa09841d88..ff054a6dc4 100644 --- a/src/image/ImageManagerDriver.cc +++ b/src/image/ImageManagerDriver.cc @@ -326,6 +326,10 @@ static void mkfs_action(istringstream& is, string info; int rc; + istringstream iss; + int vm_oid; + int disk_oid; + VirtualMachine * vm; ostringstream oss; @@ -357,9 +361,35 @@ static void mkfs_action(istringstream& is, return; } + is_saving = image->isSaving(); + is_hot = image->isHot(); + + if ( is_saving ) + { + image->get_template_attribute("SAVED_DISK_ID", disk_id); + image->get_template_attribute("SAVED_VM_ID", vm_id); + + iss.str(vm_id); + iss >> vm_oid; + + iss.clear(); + + iss.str(disk_id); + iss >> disk_oid; + } + if ( result == "FAILURE" ) { - goto error_img; + if ( is_hot ) + { + LifeCycleManager * lcm = nd.get_lcm(); + lcm->trigger(LifeCycleManager::HOTPLUG_SAVEAS_FAILURE, vm_oid); + goto error_img_hot; + } + else + { + goto error_img; + } } if ( is.good() ) @@ -372,32 +402,20 @@ static void mkfs_action(istringstream& is, goto error_img; } - is_saving = image->isSaving(); - - is_hot = image->isHot(); - image->set_source(source); - if (is_saving) + if ( !is_saving && !is_hot ) { - image->get_template_attribute("SAVED_DISK_ID", disk_id); - image->get_template_attribute("SAVED_VM_ID", vm_id); + image->set_state(Image::READY); } - else - { - if ( !is_hot ) - { - image->set_state(Image::READY); - } - NebulaLog::log("ImM", Log::INFO, "Image created and ready to use"); - } + NebulaLog::log("ImM", Log::INFO, "Image created and ready to use"); ipool->update(image); image->unlock(); - if ( ! is_saving ) + if ( !is_saving ) { return; } @@ -411,34 +429,12 @@ static void mkfs_action(istringstream& is, if ( is_hot ) { - istringstream iss; - int vm_oid; - int disk_oid; - - /* change state */ - - iss.str(vm_id); - iss >> vm_oid; - - iss.clear(); - - iss.str(disk_id); - iss >> disk_oid; - - vm->set_state(VirtualMachine::HOTPLUG_SAVEAS); vm->set_hotplug_saveas(disk_oid, id); - vm->set_resched(false); - - vmpool->update(vm); - - vm->log("LCM", Log::INFO, "New VM state is HOTPLUG_SAVEAS"); - - /* call tm */ - - TransferManager * tm = nd.get_tm(); + TransferManager * tm = nd.get_tm(); vm->unlock(); + tm->saveas_hot_transfer_command(vm_oid, disk_oid, source); } else @@ -458,6 +454,7 @@ static void mkfs_action(istringstream& is, return; +error_img_hot: error_img: oss << "Error creating datablock"; goto error; diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 36169d6d80..8c324399d6 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -1226,6 +1226,28 @@ void LifeCycleManager::hotplug_saveas_success_action(int vid) vmpool->update(vm); } + else if (vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS_POWEROFF) + { + image_id = vm->get_hotplug_saveas_image_id(); + + vm->clear_hotplug_saveas(); + + vm->set_state(VirtualMachine::POWEROFF); + vm->set_state(VirtualMachine::LCM_INIT); + + vmpool->update(vm); + } + else if (vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED) + { + image_id = vm->get_hotplug_saveas_image_id(); + + vm->clear_hotplug_saveas(); + + vm->set_state(VirtualMachine::SUSPENDED); + vm->set_state(VirtualMachine::LCM_INIT); + + vmpool->update(vm); + } else { vm->log("LCM",Log::ERROR,"hotplug_saveas_success_action," @@ -1234,7 +1256,6 @@ void LifeCycleManager::hotplug_saveas_success_action(int vid) vm->unlock(); - ostringstream oss; image = ipool->get(image_id, true); @@ -1282,6 +1303,28 @@ void LifeCycleManager::hotplug_saveas_failure_action(int vid) vmpool->update(vm); } + else if (vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS_POWEROFF) + { + image_id = vm->get_hotplug_saveas_image_id(); + + vm->clear_hotplug_saveas(); + + vm->set_state(VirtualMachine::POWEROFF); + vm->set_state(VirtualMachine::LCM_INIT); + + vmpool->update(vm); + } + else if (vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED) + { + image_id = vm->get_hotplug_saveas_image_id(); + + vm->clear_hotplug_saveas(); + + vm->set_state(VirtualMachine::SUSPENDED); + vm->set_state(VirtualMachine::LCM_INIT); + + vmpool->update(vm); + } else { vm->log("LCM",Log::ERROR,"hotplug_saveas_success_action," @@ -1290,7 +1333,6 @@ void LifeCycleManager::hotplug_saveas_failure_action(int vid) vm->unlock(); - ostringstream oss; image = ipool->get(image_id, true); diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 180a9e5395..43bd98b9d7 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -697,6 +697,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis is_hot = xmlrpc_c::value_boolean(paramList.getBoolean(5)); } + VirtualMachinePool * vmpool = static_cast(pool); VirtualMachine * vm; int iid; int iid_orig; @@ -726,8 +727,22 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis return; } + if (!( (vm->get_state() == VirtualMachine::POWEROFF) || + (vm->get_state() == VirtualMachine::SUSPENDED) || + (vm->get_state() == VirtualMachine::ACTIVE && + vm->get_lcm_state() == VirtualMachine::RUNNING))) + { + failure_response(ACTION, + request_error("Wrong state to perform action",""), + att); + + vm->unlock(); + return; + } + iid_orig = vm->get_image_from_disk(disk_id, error_str); + // TODO: remove this update? pool->update(vm); vm->unlock(); @@ -809,6 +824,55 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis return; } + // ------------------------------------------------------------------------- + // Change to one of the HOTPLUG_SAVEAS states if it's a hot saveas + // ------------------------------------------------------------------------- + + if ( is_hot ) + { + vm = vmpool->get(id,true); + + if ( vm == 0 ) + { + failure_response(NO_EXISTS, + get_error(object_name(PoolObjectSQL::VM), id), + att); + return; + } + + if ( vm->get_state() == VirtualMachine::ACTIVE && + vm->get_lcm_state() == VirtualMachine::RUNNING) + { + vm->set_state(VirtualMachine::HOTPLUG_SAVEAS); + } + else if (vm->get_state() == VirtualMachine::POWEROFF) + { + vm->set_state(VirtualMachine::ACTIVE); + vm->set_state(VirtualMachine::HOTPLUG_SAVEAS_POWEROFF); + } + else if (vm->get_state() == VirtualMachine::SUSPENDED) + { + vm->set_state(VirtualMachine::ACTIVE); + vm->set_state(VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED); + } + else + { + failure_response(ACTION, + request_error("Wrong state to perform action",""), + att); + + vm->unlock(); + return; + } + + vm->log("RM", Log::INFO, "New VM state is HOTPLUG_SAVEAS"); + + vm->set_resched(false); + vmpool->update(vm); + + vm->unlock(); + } + // ------------------------------------------------------------------------- // Get the data of the DataStore for the new image // ------------------------------------------------------------------------- diff --git a/src/tm/TransferManagerDriver.cc b/src/tm/TransferManagerDriver.cc index 416d44091f..8be69538f7 100644 --- a/src/tm/TransferManagerDriver.cc +++ b/src/tm/TransferManagerDriver.cc @@ -132,6 +132,8 @@ void TransferManagerDriver::protocol( break; case VirtualMachine::HOTPLUG_SAVEAS: + case VirtualMachine::HOTPLUG_SAVEAS_POWEROFF: + case VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED: lcm_action = LifeCycleManager::HOTPLUG_SAVEAS_SUCCESS; break; @@ -173,6 +175,8 @@ void TransferManagerDriver::protocol( break; case VirtualMachine::HOTPLUG_SAVEAS: + case VirtualMachine::HOTPLUG_SAVEAS_POWEROFF: + case VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED: lcm_action = LifeCycleManager::HOTPLUG_SAVEAS_FAILURE; break; From a425458a8a7a06717f3ef1d8819a919b9d4c787c Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 7 Mar 2013 22:44:18 +0100 Subject: [PATCH 04/14] feature #1791: Use HOTPLUG state to prevent saving twice an image. Rename functions and variables to saveas_hot. Use events to triggers save as --- include/Image.h | 3 +- include/ImageTemplate.h | 19 +- include/LifeCycleManager.h | 8 +- include/TransferManager.h | 13 +- include/VirtualMachine.h | 75 ++++--- src/image/ImageManagerDriver.cc | 143 ++++++------ src/image/ImageTemplate.cc | 4 +- src/lcm/LifeCycleActions.cc | 2 - src/lcm/LifeCycleManager.cc | 16 +- src/lcm/LifeCycleStates.cc | 104 +++------ src/rm/RequestManagerVirtualMachine.cc | 183 ++++++--------- src/tm/TransferManager.cc | 28 ++- src/tm/TransferManagerDriver.cc | 4 +- src/vm/VirtualMachine.cc | 299 +++++++++++++++---------- 14 files changed, 458 insertions(+), 443 deletions(-) diff --git a/include/Image.h b/include/Image.h index 29284b9d3b..500e26eb76 100644 --- a/include/Image.h +++ b/include/Image.h @@ -356,10 +356,9 @@ public: { ImageTemplate * it = static_cast(obj_template); - return it->is_hot(); + return it->is_saving_hot(); } - /** * Set permissions for the Image. Extends the PoolSQLObject method * by checking the persistent state of the image. diff --git a/include/ImageTemplate.h b/include/ImageTemplate.h index 6cddd2eda7..21f2b5aca1 100644 --- a/include/ImageTemplate.h +++ b/include/ImageTemplate.h @@ -52,13 +52,13 @@ public: return (saving.empty() == false); } - bool is_hot() + bool is_saving_hot() { - string snapshot_hot; + string save_as_hot; - get(snapshot_hot_attribute, snapshot_hot); + get(saving_hot_attribute, save_as_hot); - return (snapshot_hot.empty() == false); + return (save_as_hot.empty() == false); } void set_saving() @@ -70,12 +70,11 @@ public: set(attr); } - void set_snapshot_hot() + void set_saving_hot() { - SingleAttribute * attr = new SingleAttribute( - snapshot_hot_attribute, "YES"); + SingleAttribute * attr = new SingleAttribute(saving_hot_attribute,"YES"); - erase(snapshot_hot_attribute); + erase(saving_hot_attribute); set(attr); } @@ -91,7 +90,7 @@ private: static vector restricted_attributes; static string saving_attribute; - static string snapshot_hot_attribute; + static string saving_hot_attribute; /** * Stores the attributes as restricted, these attributes will be used in @@ -103,7 +102,7 @@ private: Template::set_restricted_attributes(rattrs, restricted_attributes); }; }; - + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/include/LifeCycleManager.h b/include/LifeCycleManager.h index 5702178dd6..4f9f6aa1f9 100644 --- a/include/LifeCycleManager.h +++ b/include/LifeCycleManager.h @@ -64,8 +64,8 @@ public: DETACH_FAILURE, /**< Sent by the VMM when a detach action fails */ CLEANUP_SUCCESS, /**< Sent by the VMM when a cleanup action succeeds */ CLEANUP_FAILURE, /**< Sent by the VMM when a cleanup action fails */ - HOTPLUG_SAVEAS_SUCCESS, /**< Sent by the VMM when hot saveas succeeds */ - HOTPLUG_SAVEAS_FAILURE, /**< Sent by the VMM when hot saveas fails */ + SAVEAS_HOT_SUCCESS,/**< Sent by the VMM when hot saveas succeeds */ + SAVEAS_HOT_FAILURE,/**< Sent by the VMM when hot saveas fails */ DEPLOY, /**< Sent by the DM to deploy a VM on a host */ SUSPEND, /**< Sent by the DM to suspend an running VM */ RESTORE, /**< Sent by the DM to restore a suspended VM */ @@ -189,9 +189,9 @@ private: void detach_failure_action(int vid); - void hotplug_saveas_success_action(int vid); + void saveas_hot_success_action(int vid); - void hotplug_saveas_failure_action(int vid); + void saveas_hot_failure_action(int vid); void cleanup_callback_action(int vid); diff --git a/include/TransferManager.h b/include/TransferManager.h index 085eeeedbe..7ec8945e86 100644 --- a/include/TransferManager.h +++ b/include/TransferManager.h @@ -57,6 +57,7 @@ public: EPILOG_DELETE_BOTH, CHECKPOINT, DRIVER_CANCEL, + SAVEAS_HOT, FINALIZE }; @@ -153,13 +154,6 @@ public: ostream& xfr, bool local, bool previous); - - - /** - * This function starts the hot saveas of an image - */ - void saveas_hot_transfer_command(int vid, int disk_id, string& save_source); - private: /** * Thread id for the Transfer Manager @@ -314,6 +308,11 @@ private: * This function cancels the operation being performed by the driver */ void driver_cancel_action(int vid); + + /** + * This function starts the saveas of the given disk + */ + void saveas_hot_action(int vid); }; #endif /*TRANSFER_MANAGER_H*/ diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 60dcdaf597..1e8d882f6c 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -836,20 +836,49 @@ public: */ int generate_context(string &files, int &disk_id); - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- // Datastore related functions - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- + /** + * Gest the associated image to the given disk_id + * @param disk_id of the VM + * @param hot is this a save_as hot operation + * @param err_str describing the error + * @return -1 if the image cannot saveas + */ + int get_image_from_disk(int disk_id, bool hot, string& err_str); + + /** + * Sets the corresponding SAVE_AS state. + * @return 0 if the VM can be saved as + */ + int set_saveas_state(); + + /** + * Clears the SAVE_AS state, moving the VM to the original state. + * @return 0 if the VM was in a SAVE_AS state + */ + int clear_saveas_state(); + /** * Set the SAVE_AS attribute for the "disk_id"th disk. * @param disk_id Index of the disk to save * @param source to save the disk (SAVE_AS_SOURCE) * @param img_id ID of the image this disk will be saved to (SAVE_AS). - * @return 0 if success */ int save_disk(const string& disk_id, const string& source, int img_id); + /** + * Set the SAVE_AS attribute for the "disk_id"th disk. + * @param disk_id Index of the disk to save + * @param source to save the disk (SAVE_AS_SOURCE) + * @param img_id ID of the image this disk will be saved to (SAVE_AS). + */ + int save_disk_hot(const string& disk_id, + const string& source, + int img_id); /** * Get the original image id of the disk. It also checks that the disk can * be saved_as. @@ -857,7 +886,12 @@ public: * @param error_str describes the error * @return -1 if failure */ - int get_image_from_disk(int disk_id, string& error_str); + int get_saveas_disk_hot(int& disk_id, string& source, int& image_id); + + /** + * Cleans the HOTPLUG_SAVEAS = YES attribute from the disks + */ + void clear_saveas_disk_hot(); // ------------------------------------------------------------------------ // Authorization related functions @@ -873,9 +907,9 @@ public: AuthRequest& ar, VirtualMachineTemplate *tmpl); - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- // Hotplug related functions - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- /** * Collects information about VM DISKS @@ -884,6 +918,14 @@ public: */ void get_disk_info(int& max_disk_id, set& used_targets); + /** + * Get the IMAGE_ID of the image that's being saved as hot + * @param disk_id of the DISK + * @param image_id id of the image being saved + * @return IMAGE_ID on success, -1 otherwise + */ + int get_disk_hot_info(int& image_id, int& disk_id, string& source); + /** * Generate a DISK attributed to be attached to the VM. * @param tmpl Template containing a single DISK vector attribute. @@ -956,27 +998,6 @@ public: */ int detach_failure(); - /** - * Get the IMAGE_ID of the image that's being saved as hot - * @param disk_id of the DISK - * @param image_id id of the image being saved - * @return IMAGE_ID on success, -1 otherwise - */ - int get_hotplug_saveas_image_id(); - - /** - * Sets the hotplug_saveas attribute to the given disk - * @param disk_id of the DISK - * @param image_id id of the image being saved - * @return 0 if the disk_id was found -1 otherwise - */ - int set_hotplug_saveas(int disk_id, int image_id); - - /** - * Cleans the HOTPLUG_SAVEAS = YES attribute from the disks - */ - void clear_hotplug_saveas(); - private: // ------------------------------------------------------------------------- diff --git a/src/image/ImageManagerDriver.cc b/src/image/ImageManagerDriver.cc index ff054a6dc4..469a9659d5 100644 --- a/src/image/ImageManagerDriver.cc +++ b/src/image/ImageManagerDriver.cc @@ -26,7 +26,7 @@ /* Driver ASCII Protocol Implementation */ /* ************************************************************************** */ -void ImageManagerDriver::cp(int oid, +void ImageManagerDriver::cp(int oid, const string& drv_msg) const { ostringstream os; @@ -38,7 +38,7 @@ void ImageManagerDriver::cp(int oid, /* -------------------------------------------------------------------------- */ -void ImageManagerDriver::clone(int oid, +void ImageManagerDriver::clone(int oid, const string& drv_msg) const { ostringstream os; @@ -49,7 +49,7 @@ void ImageManagerDriver::clone(int oid, } /* -------------------------------------------------------------------------- */ -void ImageManagerDriver::stat(int oid, +void ImageManagerDriver::stat(int oid, const string& drv_msg) const { ostringstream os; @@ -61,13 +61,13 @@ void ImageManagerDriver::stat(int oid, /* -------------------------------------------------------------------------- */ -void ImageManagerDriver::mkfs(int oid, +void ImageManagerDriver::mkfs(int oid, const string& drv_msg) const { ostringstream os; os << "MKFS " << oid << " " << drv_msg << endl; - + write(os); } @@ -121,9 +121,9 @@ static void stat_action(istringstream& is, int id, const string& result) /* -------------------------------------------------------------------------- */ -static void cp_action(istringstream& is, - ImagePool* ipool, - int id, +static void cp_action(istringstream& is, + ImagePool* ipool, + int id, const string& result) { string source; @@ -143,7 +143,7 @@ static void cp_action(istringstream& is, if ( is.good()) { - is >> source >> ws; + is >> source >> ws; } if (!source.empty()) @@ -151,7 +151,7 @@ static void cp_action(istringstream& is, oss << "CP operation succeeded but image no longer exists." << " Source image: " << source << ", may be left in datastore"; - NebulaLog::log("ImM", Log::ERROR, oss); + NebulaLog::log("ImM", Log::ERROR, oss); } } @@ -160,7 +160,7 @@ static void cp_action(istringstream& is, if ( result == "FAILURE" ) { - goto error; + goto error; } if ( is.good() ) @@ -172,7 +172,7 @@ static void cp_action(istringstream& is, { goto error; } - + image->set_source(source); image->set_state(Image::READY); @@ -194,7 +194,7 @@ error: { oss << ": " << info; } - + NebulaLog::log("ImM", Log::ERROR, oss); image->set_template_error_message(oss.str()); @@ -209,9 +209,9 @@ error: /* -------------------------------------------------------------------------- */ -static void clone_action(istringstream& is, - ImagePool* ipool, - int id, +static void clone_action(istringstream& is, + ImagePool* ipool, + int id, const string& result) { int cloning_id; @@ -235,7 +235,7 @@ static void clone_action(istringstream& is, if ( is.good()) { - is >> source >> ws; + is >> source >> ws; } if (!source.empty()) @@ -243,7 +243,7 @@ static void clone_action(istringstream& is, oss << "CLONE operation succeeded but image no longer exists." << " Source image: " << source << ", may be left in datastore"; - NebulaLog::log("ImM", Log::ERROR, oss); + NebulaLog::log("ImM", Log::ERROR, oss); } } @@ -254,7 +254,7 @@ static void clone_action(istringstream& is, if ( result == "FAILURE" ) { - goto error; + goto error; } if ( is.good() ) @@ -266,7 +266,7 @@ static void clone_action(istringstream& is, { goto error; } - + image->set_source(source); image->set_state(Image::READY); @@ -292,7 +292,7 @@ error: { oss << ": " << info; } - + NebulaLog::log("ImM", Log::ERROR, oss); image->set_template_error_message(oss.str()); @@ -311,30 +311,28 @@ error: /* -------------------------------------------------------------------------- */ -static void mkfs_action(istringstream& is, - ImagePool* ipool, - int id, +static void mkfs_action(istringstream& is, + ImagePool* ipool, + int id, const string& result) { string source; Image * image; - bool is_saving; - bool is_hot; + bool is_saving = false; + bool is_hot = false; - string disk_id; - string vm_id; string info; int rc; - istringstream iss; - int vm_oid; - int disk_oid; + int vm_id = -1; + string disk_id; VirtualMachine * vm; ostringstream oss; Nebula& nd = Nebula::instance(); VirtualMachinePool * vmpool = nd.get_vmpool(); + TransferManager * tm = nd.get_tm(); image = ipool->get(id, true); @@ -346,7 +344,7 @@ static void mkfs_action(istringstream& is, if ( is.good()) { - is >> source >> ws; + is >> source >> ws; } if (!source.empty()) @@ -354,42 +352,25 @@ static void mkfs_action(istringstream& is, oss << "MkFS operation succeeded but image no longer exists." << " Source image: " << source << ", may be left in datastore"; - NebulaLog::log("ImM", Log::ERROR, oss); + NebulaLog::log("ImM", Log::ERROR, oss); } } - + return; } is_saving = image->isSaving(); - is_hot = image->isHot(); + is_hot = image->isHot(); if ( is_saving ) { - image->get_template_attribute("SAVED_DISK_ID", disk_id); image->get_template_attribute("SAVED_VM_ID", vm_id); - - iss.str(vm_id); - iss >> vm_oid; - - iss.clear(); - - iss.str(disk_id); - iss >> disk_oid; + image->get_template_attribute("SAVED_DISK_ID", disk_id); } if ( result == "FAILURE" ) { - if ( is_hot ) - { - LifeCycleManager * lcm = nd.get_lcm(); - lcm->trigger(LifeCycleManager::HOTPLUG_SAVEAS_FAILURE, vm_oid); - goto error_img_hot; - } - else - { - goto error_img; - } + goto error_img; } if ( is.good() ) @@ -404,7 +385,7 @@ static void mkfs_action(istringstream& is, image->set_source(source); - if ( !is_saving && !is_hot ) + if (!is_saving) { image->set_state(Image::READY); } @@ -427,19 +408,19 @@ static void mkfs_action(istringstream& is, goto error_save_get; } - if ( is_hot ) + if ( is_hot ) //Saveas hot, trigger disk copy { - vm->set_hotplug_saveas(disk_oid, id); + rc = vm->save_disk_hot(disk_id, source, id); - TransferManager * tm = nd.get_tm(); + if ( rc == -1 ) + { + goto error_save_state; + } - vm->unlock(); - - tm->saveas_hot_transfer_command(vm_oid, disk_oid, source); + tm->trigger(TransferManager::SAVEAS_HOT, vm_id); } - else + else //setup disk information { - /* -------------- Set up information for the Saved Image ------------ */ rc = vm->save_disk(disk_id, source, id); if ( rc == -1 ) @@ -447,14 +428,15 @@ static void mkfs_action(istringstream& is, goto error_save_state; } - vmpool->update(vm); + vm->clear_saveas_state(); } + vmpool->update(vm); + vm->unlock(); return; -error_img_hot: error_img: oss << "Error creating datablock"; goto error; @@ -483,7 +465,7 @@ error: { oss << ": " << info; } - + NebulaLog::log("ImM", Log::ERROR, oss); image->set_template_error_message(oss.str()); @@ -493,14 +475,25 @@ error: image->unlock(); + if (is_saving && vm_id != -1) + { + if ((vm = vmpool->get(vm_id, true)) != 0) + { + vm->clear_saveas_state(); + vmpool->update(vm); + + vm->unlock(); + } + } + return ; } /* -------------------------------------------------------------------------- */ -static void rm_action(istringstream& is, - ImagePool* ipool, - int id, +static void rm_action(istringstream& is, + ImagePool* ipool, + int id, const string& result) { int rc; @@ -526,7 +519,7 @@ static void rm_action(istringstream& is, if ( result == "FAILURE" ) { - goto error; + goto error; } else if ( rc < 0 ) { @@ -538,7 +531,7 @@ static void rm_action(istringstream& is, return; error_drop: - oss << "Error removing image from DB: " << tmp_error + oss << "Error removing image from DB: " << tmp_error << ". Remove image source " << source << " to completely delete image."; NebulaLog::log("ImM", Log::ERROR, oss); @@ -554,7 +547,7 @@ error: { oss << ": " << info; } - + NebulaLog::log("ImM", Log::ERROR, oss); return; @@ -572,9 +565,9 @@ void ImageManagerDriver::protocol( string action; string result; string source; - string info; + string info; int id; - + oss << "Message received: " << message; NebulaLog::log("ImG", Log::DEBUG, oss); @@ -621,7 +614,7 @@ void ImageManagerDriver::protocol( else if ( action == "CLONE" ) { clone_action(is, ipool, id, result); - } + } else if ( action == "MKFS" ) { mkfs_action(is, ipool, id, result); diff --git a/src/image/ImageTemplate.cc b/src/image/ImageTemplate.cc index 543491a7ec..c10713fb02 100644 --- a/src/image/ImageTemplate.cc +++ b/src/image/ImageTemplate.cc @@ -21,8 +21,8 @@ vector ImageTemplate::restricted_attributes; -string ImageTemplate::saving_attribute = "SAVE_AS"; -string ImageTemplate::snapshot_hot_attribute = "SNAPSHOT_HOT"; +string ImageTemplate::saving_attribute = "SAVE_AS"; +string ImageTemplate::saving_hot_attribute = "SAVE_AS_HOT"; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index d0827f8491..1f1491253f 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -550,8 +550,6 @@ void LifeCycleManager::restart_action(int vid) vm->log("LCM", Log::INFO, "New VM state is BOOT_POWEROFF"); } - //---------------------------------------------------- - vmm->trigger(VirtualMachineManager::DEPLOY,vid); } else diff --git a/src/lcm/LifeCycleManager.cc b/src/lcm/LifeCycleManager.cc index 7ae2a9ea28..540c9353c0 100644 --- a/src/lcm/LifeCycleManager.cc +++ b/src/lcm/LifeCycleManager.cc @@ -145,12 +145,12 @@ void LifeCycleManager::trigger(Actions action, int _vid) aname = "DETACH_FAILURE"; break; - case HOTPLUG_SAVEAS_SUCCESS: - aname = "HOTPLUG_SAVEAS_SUCCESS"; + case SAVEAS_HOT_SUCCESS: + aname = "SAVEAS_HOT_SUCCESS"; break; - case HOTPLUG_SAVEAS_FAILURE: - aname = "HOTPLUG_SAVEAS_FAILURE"; + case SAVEAS_HOT_FAILURE: + aname = "SAVEAS_HOT_FAILURE"; break; case CLEANUP_SUCCESS: @@ -314,13 +314,13 @@ void LifeCycleManager::do_action(const string &action, void * arg) { detach_failure_action(vid); } - else if (action == "HOTPLUG_SAVEAS_SUCCESS") + else if (action == "SAVEAS_HOT_SUCCESS") { - hotplug_saveas_success_action(vid); + saveas_hot_success_action(vid); } - else if (action == "HOTPLUG_SAVEAS_FAILURE") + else if (action == "SAVEAS_HOT_FAILURE") { - hotplug_saveas_failure_action(vid); + saveas_hot_failure_action(vid); } else if (action == "CLEANUP_SUCCESS") { diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 8c324399d6..abef5d29e7 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -1198,16 +1198,17 @@ void LifeCycleManager::detach_failure_action(int vid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void LifeCycleManager::hotplug_saveas_success_action(int vid) +void LifeCycleManager::saveas_hot_success_action(int vid) { - Nebula& nd = Nebula::instance(); - + Nebula& nd = Nebula::instance(); ImagePool * ipool = nd.get_ipool(); - VirtualMachine * vm; + VirtualMachine * vm; Image * image; int image_id; + int disk_id; + string source; vm = vmpool->get(vid,true); @@ -1216,47 +1217,26 @@ void LifeCycleManager::hotplug_saveas_success_action(int vid) return; } - if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS) + if (vm->clear_saveas_state() == -1) { - image_id = vm->get_hotplug_saveas_image_id(); + vm->log("LCM", Log::ERROR, "saveas_hot_success_action, VM in a wrong state"); + vm->unlock(); - vm->clear_hotplug_saveas(); - - vm->set_state(VirtualMachine::RUNNING); - - vmpool->update(vm); + return; } - else if (vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS_POWEROFF) - { - image_id = vm->get_hotplug_saveas_image_id(); - vm->clear_hotplug_saveas(); + int rc = vm->get_saveas_disk_hot(disk_id, source, image_id); - vm->set_state(VirtualMachine::POWEROFF); - vm->set_state(VirtualMachine::LCM_INIT); + vm->clear_saveas_disk_hot(); - vmpool->update(vm); - } - else if (vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED) - { - image_id = vm->get_hotplug_saveas_image_id(); - - vm->clear_hotplug_saveas(); - - vm->set_state(VirtualMachine::SUSPENDED); - vm->set_state(VirtualMachine::LCM_INIT); - - vmpool->update(vm); - } - else - { - vm->log("LCM",Log::ERROR,"hotplug_saveas_success_action," - " VM in a wrong state"); - } + vmpool->update(vm); vm->unlock(); - ostringstream oss; + if ( rc != 0 ) + { + return; + } image = ipool->get(image_id, true); @@ -1275,16 +1255,17 @@ void LifeCycleManager::hotplug_saveas_success_action(int vid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void LifeCycleManager::hotplug_saveas_failure_action(int vid) +void LifeCycleManager::saveas_hot_failure_action(int vid) { - Nebula& nd = Nebula::instance(); - + Nebula& nd = Nebula::instance(); ImagePool * ipool = nd.get_ipool(); - VirtualMachine * vm; + VirtualMachine * vm; Image * image; int image_id; + int disk_id; + string source; vm = vmpool->get(vid,true); @@ -1293,47 +1274,26 @@ void LifeCycleManager::hotplug_saveas_failure_action(int vid) return; } - if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS) + if (vm->clear_saveas_state() == -1) { - image_id = vm->get_hotplug_saveas_image_id(); + vm->log("LCM", Log::ERROR, "saveas_hot_success_action, VM in a wrong state"); + vm->unlock(); - vm->clear_hotplug_saveas(); - - vm->set_state(VirtualMachine::RUNNING); - - vmpool->update(vm); + return; } - else if (vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS_POWEROFF) - { - image_id = vm->get_hotplug_saveas_image_id(); - vm->clear_hotplug_saveas(); + int rc = vm->get_saveas_disk_hot(disk_id, source, image_id); - vm->set_state(VirtualMachine::POWEROFF); - vm->set_state(VirtualMachine::LCM_INIT); + vm->clear_saveas_disk_hot(); - vmpool->update(vm); - } - else if (vm->get_lcm_state() == VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED) - { - image_id = vm->get_hotplug_saveas_image_id(); - - vm->clear_hotplug_saveas(); - - vm->set_state(VirtualMachine::SUSPENDED); - vm->set_state(VirtualMachine::LCM_INIT); - - vmpool->update(vm); - } - else - { - vm->log("LCM",Log::ERROR,"hotplug_saveas_success_action," - " VM in a wrong state"); - } + vmpool->update(vm); vm->unlock(); - ostringstream oss; + if ( rc != 0 ) + { + return; + } image = ipool->get(image_id, true); diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 43bd98b9d7..4dc228d1b0 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -682,9 +682,9 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis { Nebula& nd = Nebula::instance(); - ImagePool * ipool = nd.get_ipool(); - DatastorePool * dspool = nd.get_dspool(); - UserPool * upool = nd.get_upool(); + ImagePool * ipool = nd.get_ipool(); + DatastorePool * dspool = nd.get_dspool(); + UserPool * upool = nd.get_upool(); int id = xmlrpc_c::value_int(paramList.getInt(1)); int disk_id = xmlrpc_c::value_int(paramList.getInt(2)); @@ -699,51 +699,45 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis VirtualMachinePool * vmpool = static_cast(pool); VirtualMachine * vm; + Datastore * ds; int iid; - int iid_orig; - Image * img; - Datastore * ds; - User * user; - Image::DiskType ds_disk_type; - - int umask; - int rc; - string error_str; + string error_str; string driver; string target; string dev_prefix; // ------------------------------------------------------------------------- - // Prepare and check the VM/DISK to be saved_as + // Get user's umask // ------------------------------------------------------------------------- + User * user = upool->get(att.uid, true); - if ( (vm = get_vm(id, att)) == 0 ) + if ( user == 0 ) { failure_response(NO_EXISTS, - get_error(object_name(PoolObjectSQL::VM), id), - att); - return; - } - - if (!( (vm->get_state() == VirtualMachine::POWEROFF) || - (vm->get_state() == VirtualMachine::SUSPENDED) || - (vm->get_state() == VirtualMachine::ACTIVE && - vm->get_lcm_state() == VirtualMachine::RUNNING))) - { - failure_response(ACTION, - request_error("Wrong state to perform action",""), + get_error(object_name(PoolObjectSQL::USER), att.uid), att); - vm->unlock(); return; } - iid_orig = vm->get_image_from_disk(disk_id, error_str); + int umask = user->get_umask(); - // TODO: remove this update? - pool->update(vm); + user->unlock(); + + // ------------------------------------------------------------------------- + // Prepare and check the VM/DISK to be saved_as + // ------------------------------------------------------------------------- + if ((vm = get_vm(id, att)) == 0) + { + return; + } + + int rc = vm->set_saveas_state(); + int iid_orig = vm->get_image_from_disk(disk_id, is_hot, error_str); + + vmpool->update(vm); vm->unlock(); @@ -755,36 +749,32 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis return; } - // ------------------------------------------------------------------------- - // Get user's umask - // ------------------------------------------------------------------------- - - user = upool->get(att.uid, true); - - if ( user == 0 ) + if ( rc != 0 ) { - failure_response(NO_EXISTS, - get_error(object_name(PoolObjectSQL::USER), att.uid), - att); - + failure_response(INTERNAL, + request_error("VM has to be RUNNING, POWEROFF or" + " SUSPENDED to saveas disks.",""), att); return; } - umask = user->get_umask(); - - user->unlock(); - // ------------------------------------------------------------------------- // Get the data of the Image to be saved // ------------------------------------------------------------------------- - - img = ipool->get(iid_orig, true); + Image * img = ipool->get(iid_orig, true); if ( img == 0 ) { failure_response(NO_EXISTS, get_error(object_name(PoolObjectSQL::IMAGE), iid_orig), att); + + if ((vm = vmpool->get(id, true)) != 0) + { + vm->clear_saveas_state(); + vmpool->update(vm); + vm->unlock(); + } + return; } @@ -800,11 +790,22 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis img->unlock(); + // ------------------------------------------------------------------------- + // Get the data of the DataStore for the new image + // ------------------------------------------------------------------------- if ((ds = dspool->get(ds_id, true)) == 0 ) { failure_response(NO_EXISTS, get_error(object_name(PoolObjectSQL::DATASTORE), ds_id), att); + + if ((vm = vmpool->get(id, true)) != 0) + { + vm->clear_saveas_state(); + vmpool->update(vm); + vm->unlock(); + } + return; } @@ -819,70 +820,18 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis case Image::RAMDISK: case Image::CONTEXT: failure_response(INTERNAL, - request_error("Cannot save_as image of type " + Image::type_to_str(type), ""), - att); + request_error("Cannot save_as image of type " + + Image::type_to_str(type), ""), att); return; } - // ------------------------------------------------------------------------- - // Change to one of the HOTPLUG_SAVEAS states if it's a hot saveas - // ------------------------------------------------------------------------- - - if ( is_hot ) - { - vm = vmpool->get(id,true); - - if ( vm == 0 ) - { - failure_response(NO_EXISTS, - get_error(object_name(PoolObjectSQL::VM), id), - att); - return; - } - - if ( vm->get_state() == VirtualMachine::ACTIVE && - vm->get_lcm_state() == VirtualMachine::RUNNING) - { - vm->set_state(VirtualMachine::HOTPLUG_SAVEAS); - } - else if (vm->get_state() == VirtualMachine::POWEROFF) - { - vm->set_state(VirtualMachine::ACTIVE); - vm->set_state(VirtualMachine::HOTPLUG_SAVEAS_POWEROFF); - } - else if (vm->get_state() == VirtualMachine::SUSPENDED) - { - vm->set_state(VirtualMachine::ACTIVE); - vm->set_state(VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED); - } - else - { - failure_response(ACTION, - request_error("Wrong state to perform action",""), - att); - - vm->unlock(); - return; - } - - vm->log("RM", Log::INFO, "New VM state is HOTPLUG_SAVEAS"); - - vm->set_resched(false); - vmpool->update(vm); - - vm->unlock(); - } - - // ------------------------------------------------------------------------- - // Get the data of the DataStore for the new image - // ------------------------------------------------------------------------- string ds_data; PoolObjectAuth ds_perms; ds->get_permissions(ds_perms); ds->to_xml(ds_data); - ds_disk_type = ds->get_disk_type(); + Image::DiskType ds_disk_type = ds->get_disk_type(); ds->unlock(); @@ -899,9 +848,11 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis itemplate->add("SAVED_DISK_ID",disk_id); itemplate->add("SAVED_VM_ID", id); + itemplate->set_saving(); + if ( is_hot ) { - itemplate->set_snapshot_hot(); + itemplate->set_saving_hot(); } if ( img_type.empty() ) @@ -928,31 +879,36 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis itemplate->add("DEV_PREFIX", dev_prefix); } - itemplate->set_saving(); - img_usage.add("SIZE", size); img_usage.add("DATASTORE", ds_id); // ------------------------------------------------------------------------- // Authorize the operation & check quotas // ------------------------------------------------------------------------- + bool rc_auth = vm_authorization(id, itemplate, 0, att, 0,&ds_perms,auth_op); - if ( vm_authorization(id, itemplate, 0, att, 0, &ds_perms, auth_op) == false ) + if ( rc_auth == true ) { - delete itemplate; - return; + rc_auth = quota_authorization(&img_usage, Quotas::DATASTORE, att); } - if ( quota_authorization(&img_usage, Quotas::DATASTORE, att) == false ) + if ( rc_auth == false) { delete itemplate; + + if ((vm = vmpool->get(id, true)) != 0) + { + vm->clear_saveas_state(); + vmpool->update(vm); + vm->unlock(); + } + return; } // ------------------------------------------------------------------------- // Create the image // ------------------------------------------------------------------------- - rc = ipool->allocate(att.uid, att.gid, att.uname, @@ -971,6 +927,13 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis { quota_rollback(&img_usage, Quotas::DATASTORE, att); + if ((vm = vmpool->get(id, true)) != 0) + { + vm->clear_saveas_state(); + vmpool->update(vm); + vm->unlock(); + } + failure_response(INTERNAL, allocate_error(PoolObjectSQL::IMAGE, error_str), att); return; diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 63ddd30039..a7365b1903 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -123,6 +123,10 @@ void TransferManager::trigger(Actions action, int _vid) aname = "CHECKPOINT"; break; + case SAVEAS_HOT: + aname = "DRIVER_CANCEL"; + break; + case DRIVER_CANCEL: aname = "DRIVER_CANCEL"; break; @@ -195,6 +199,10 @@ void TransferManager::do_action(const string &action, void * arg) { checkpoint_action(vid); } + else if (action == "SAVEAS_HOT") + { + saveas_hot_action(vid); + } else if (action == "DRIVER_CANCEL") { driver_cancel_action(vid); @@ -1625,10 +1633,12 @@ void TransferManager::checkpoint_action(int vid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void TransferManager::saveas_hot_transfer_command(int vid, - int disk_id, - string& save_source) +void TransferManager::saveas_hot_action(int vid) { + int disk_id; + int image_id; + string save_source; + string save; string tm_mad; string ds_id; @@ -1658,13 +1668,19 @@ void TransferManager::saveas_hot_transfer_command(int vid, if (vm == 0) { - vm->log("TM", Log::ERROR, "Could not obtain the VM");; + vm->log("TM", Log::ERROR, "Could not obtain the VM"); goto error_common; } if (!vm->hasHistory()) { - vm->log("TM", Log::ERROR, "The VM has no history");; + vm->log("TM", Log::ERROR, "The VM has no history"); + goto error_common; + } + + if (vm->get_saveas_disk_hot(disk_id, save_source, image_id) == -1) + { + vm->log("TM", Log::ERROR, "Could not get disk information to saveas it"); goto error_common; } @@ -1747,7 +1763,7 @@ error_file: error_common: vm->log("TM", Log::ERROR, os); - (nd.get_lcm())->trigger(LifeCycleManager::HOTPLUG_SAVEAS_FAILURE, vid); + (nd.get_lcm())->trigger(LifeCycleManager::SAVEAS_HOT_FAILURE, vid); vm->unlock(); return; diff --git a/src/tm/TransferManagerDriver.cc b/src/tm/TransferManagerDriver.cc index 8be69538f7..44027fb044 100644 --- a/src/tm/TransferManagerDriver.cc +++ b/src/tm/TransferManagerDriver.cc @@ -134,7 +134,7 @@ void TransferManagerDriver::protocol( case VirtualMachine::HOTPLUG_SAVEAS: case VirtualMachine::HOTPLUG_SAVEAS_POWEROFF: case VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED: - lcm_action = LifeCycleManager::HOTPLUG_SAVEAS_SUCCESS; + lcm_action = LifeCycleManager::SAVEAS_HOT_SUCCESS; break; default: @@ -177,7 +177,7 @@ void TransferManagerDriver::protocol( case VirtualMachine::HOTPLUG_SAVEAS: case VirtualMachine::HOTPLUG_SAVEAS_POWEROFF: case VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED: - lcm_action = LifeCycleManager::HOTPLUG_SAVEAS_FAILURE; + lcm_action = LifeCycleManager::SAVEAS_HOT_FAILURE; break; default: diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 020fb8f54e..4b1367d5d3 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -1858,112 +1858,6 @@ VectorAttribute * VirtualMachine::delete_attach_disk() /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachine::get_hotplug_saveas_image_id() -{ - int num_disks; - vector disks; - VectorAttribute * disk; - - istringstream iss; - string image_id_str; - int image_id; - - num_disks = obj_template->get("DISK", disks); - - for(int i=0; i(disks[i]); - - if ( disk == 0 ) - { - continue; - } - - if ( !disk->vector_value("HOTPLUG_SAVEAS_IMAGE_ID").empty() ) - { - image_id_str = disk->vector_value("HOTPLUG_SAVEAS_IMAGE_ID"); - iss.str(image_id_str); - - iss >> image_id; - - if ( !iss.fail() ) - { - return image_id; - } - } - } - return -1; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -int VirtualMachine::set_hotplug_saveas(int disk_id, int img_id) -{ - - int num_disks; - int d_id; - - vector disks; - VectorAttribute * disk; - - num_disks = obj_template->get("DISK", disks); - - for(int i=0; i(disks[i]); - - if ( disk == 0 ) - { - continue; - } - - disk->vector_value("DISK_ID", d_id); - - if ( d_id == disk_id ) - { - disk->replace("HOTPLUG_SAVEAS", "YES"); - disk->replace("HOTPLUG_SAVEAS_IMAGE_ID", img_id); - - return 0; - } - } - - return -1; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -void VirtualMachine::clear_hotplug_saveas() -{ - int num_disks; - vector disks; - VectorAttribute * disk; - - num_disks = obj_template->get("DISK", disks); - - for(int i=0; i(disks[i]); - - if ( disk == 0 ) - { - continue; - } - - if ( disk->vector_value("HOTPLUG_SAVEAS") == "YES" ) - { - disk->remove("HOTPLUG_SAVEAS"); - disk->remove("HOTPLUG_SAVEAS_IMAGE_ID"); - return; - } - } -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - void VirtualMachine::release_disk_images() { int iid; @@ -2177,7 +2071,7 @@ int VirtualMachine::generate_context(string &files, int &disk_id) /* -------------------------------------------------------------------------- */ -int VirtualMachine::get_image_from_disk(int disk_id, string& error_str) +int VirtualMachine::get_image_from_disk(int disk_id, bool hot, string& err_str) { int num_disks; int tid; @@ -2219,7 +2113,7 @@ int VirtualMachine::get_image_from_disk(int disk_id, string& error_str) goto error_saved; } - if(!((disk->vector_value("PERSISTENT")).empty())) + if(!(disk->vector_value("PERSISTENT").empty()) && !hot) { goto error_persistent; } @@ -2257,7 +2151,7 @@ error_not_found: oss << "The DISK " << disk_id << " does not exist for VM " << oid << "."; error_common: - error_str = oss.str(); + err_str = oss.str(); return -1; } @@ -2265,6 +2159,65 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int VirtualMachine::set_saveas_state() +{ + switch (state) + { + case ACTIVE: + switch (lcm_state) + { + case RUNNING: + lcm_state = HOTPLUG_SAVEAS; + return 0; + default: + return -1; + } + break; + + case POWEROFF: + state = ACTIVE; + lcm_state = HOTPLUG_SAVEAS_POWEROFF; + return 0; + + case SUSPENDED: + state = ACTIVE; + lcm_state = HOTPLUG_SAVEAS_SUSPENDED; + return 0; + + default: + return -1; + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualMachine::clear_saveas_state() + { + switch (lcm_state) + { + case HOTPLUG_SAVEAS: + lcm_state = RUNNING; + return 0; + + case HOTPLUG_SAVEAS_POWEROFF: + state = POWEROFF; + lcm_state = LCM_INIT; + return 0; + + case HOTPLUG_SAVEAS_SUSPENDED: + state = SUSPENDED; + lcm_state = LCM_INIT; + return 0; + + default: + return -1; + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + int VirtualMachine::save_disk(const string& disk_id, const string& source, int img_id) @@ -2272,18 +2225,16 @@ int VirtualMachine::save_disk(const string& disk_id, vector disks; VectorAttribute * disk; - int num_disks; string tdisk_id; - ostringstream oss; + int num_disks = obj_template->get("DISK",disks); - if ( state == DONE || state == FAILED ) + if (lcm_state != HOTPLUG_SAVEAS || lcm_state != HOTPLUG_SAVEAS_SUSPENDED + || lcm_state != HOTPLUG_SAVEAS_POWEROFF ) { return -1; } - num_disks = obj_template->get("DISK",disks); - for(int i=0; i(disks[i]); @@ -2299,8 +2250,7 @@ int VirtualMachine::save_disk(const string& disk_id, { disk->replace("SAVE_AS_SOURCE", source); - oss << (img_id); - disk->replace("SAVE_AS", oss.str()); + disk->replace("SAVE_AS", img_id); disk->replace("SAVE", "YES"); @@ -2314,6 +2264,123 @@ int VirtualMachine::save_disk(const string& disk_id, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int VirtualMachine::save_disk_hot(const string& disk_id, + const string& source, + int img_id) +{ + int num_disks; + string tdisk_id; + + vector disks; + VectorAttribute * disk; + + num_disks = obj_template->get("DISK", disks); + + if (lcm_state != HOTPLUG_SAVEAS || lcm_state != HOTPLUG_SAVEAS_SUSPENDED + || lcm_state != HOTPLUG_SAVEAS_POWEROFF ) + { + return -1; + } + + for(int i=0; i(disks[i]); + + if ( disk == 0 ) + { + continue; + } + + tdisk_id = disk->vector_value("DISK_ID"); + + if ( tdisk_id == disk_id ) + { + disk->replace("HOTPLUG_SAVEAS", "YES"); + disk->replace("HOTPLUG_SAVEAS_IMAGE_ID", img_id); + disk->replace("HOTPLUG_SAVEAS_SOURCE", source); + break; + } + } + + return 0; +} + + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int VirtualMachine::get_saveas_disk_hot(int& disk_id, string& source, int& image_id) +{ + vector disks; + VectorAttribute * disk; + + int rc; + int num_disks; + + num_disks = obj_template->get("DISK", disks); + + for(int i=0; i(disks[i]); + + if ( disk == 0 ) + { + continue; + } + + if ( disk->vector_value("HOTPLUG_SAVEAS") == "YES" ) + { + source = disk->vector_value("HOTPLUG_SAVEAS_SOURCE"); + + rc = disk->vector_value("HOTPLUG_SAVEAS_IMAGE_ID", image_id); + rc += disk->vector_value("DISK_ID", disk_id); + + if ( rc != 0 || source.empty() ) + { + return -1; + } + + return 0; + } + } + + return -1; +} + + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void VirtualMachine::clear_saveas_disk_hot() +{ + int num_disks; + vector disks; + VectorAttribute * disk; + + num_disks = obj_template->get("DISK", disks); + + for(int i=0; i(disks[i]); + + if ( disk == 0 ) + { + continue; + } + + if ( disk->vector_value("HOTPLUG_SAVEAS") == "YES" ) + { + disk->remove("HOTPLUG_SAVEAS"); + disk->remove("HOTPLUG_SAVEAS_IMAGE_ID"); + disk->remove("HOTPLUG_SAVEAS_SOURCE"); + return; + } + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void VirtualMachine::set_auth_request(int uid, AuthRequest& ar, VirtualMachineTemplate *tmpl) From eb5ce07c97a673ec3ab51d6fd49b2f5e057f1df9 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 7 Mar 2013 22:46:55 +0100 Subject: [PATCH 05/14] feature #1791:HOTPLUG states in delete action --- src/lcm/LifeCycleActions.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index 1f1491253f..10dea559e5 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -733,6 +733,9 @@ void LifeCycleManager::clean_up_vm(VirtualMachine * vm, bool dispose) case VirtualMachine::SHUTDOWN_POWEROFF: case VirtualMachine::CANCEL: case VirtualMachine::HOTPLUG: + case VirtualMachine::HOTPLUG_SAVEAS: + case VirtualMachine::HOTPLUG_SAVEAS_POWEROFF: + case VirtualMachine::HOTPLUG_SAVEAS_SUSPENDED: vm->set_running_etime(the_time); vmpool->update_history(vm); From 6c21529a391346c76d6d53010095d7daf9cb2d11 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Thu, 7 Mar 2013 16:48:23 +0100 Subject: [PATCH 06/14] feature #1791: Add all cpds actions --- install.sh | 16 ++++++-- src/tm_mad/ceph/cpds | 70 ++++++++++++++++++++++++++++++++ src/tm_mad/dummy/cpds | 1 + src/tm_mad/iscsi/cpds | 92 ++++++++++++++++++++++++++++++++++++++++++ src/tm_mad/lvm/cpds | 70 ++++++++++++++++++++++++++++++++ src/tm_mad/qcow2/cpds | 75 ++++++++++++++++++++++++++++++++++ src/tm_mad/shared/cpds | 83 +++++++++++++++++++++++++++++++++++++ src/tm_mad/ssh/cpds | 47 +++++++++++++++++++++ src/tm_mad/vmfs/cpds | 1 + 9 files changed, 451 insertions(+), 4 deletions(-) create mode 100755 src/tm_mad/ceph/cpds create mode 120000 src/tm_mad/dummy/cpds create mode 100755 src/tm_mad/iscsi/cpds create mode 100755 src/tm_mad/lvm/cpds create mode 100755 src/tm_mad/qcow2/cpds create mode 100755 src/tm_mad/shared/cpds create mode 100755 src/tm_mad/ssh/cpds create mode 120000 src/tm_mad/vmfs/cpds diff --git a/install.sh b/install.sh index cfb3ab6e81..aa40a89f07 100755 --- a/install.sh +++ b/install.sh @@ -935,7 +935,8 @@ TM_SHARED_FILES="src/tm_mad/shared/clone \ src/tm_mad/shared/context \ src/tm_mad/shared/premigrate \ src/tm_mad/shared/postmigrate \ - src/tm_mad/shared/mvds" + src/tm_mad/shared/mvds \ + src/tm_mad/shared/cpds" TM_QCOW2_FILES="src/tm_mad/qcow2/clone \ src/tm_mad/qcow2/delete \ @@ -946,7 +947,8 @@ TM_QCOW2_FILES="src/tm_mad/qcow2/clone \ src/tm_mad/qcow2/context \ src/tm_mad/qcow2/premigrate \ src/tm_mad/qcow2/postmigrate \ - src/tm_mad/qcow2/mvds" + src/tm_mad/qcow2/mvds \ + src/tm_mad/qcow2/cpds" TM_SSH_FILES="src/tm_mad/ssh/clone \ src/tm_mad/ssh/delete \ @@ -957,7 +959,8 @@ TM_SSH_FILES="src/tm_mad/ssh/clone \ src/tm_mad/ssh/context \ src/tm_mad/ssh/premigrate \ src/tm_mad/ssh/postmigrate \ - src/tm_mad/ssh/mvds" + src/tm_mad/ssh/mvds \ + src/tm_mad/ssh/cpds" TM_DUMMY_FILES="src/tm_mad/dummy/clone \ src/tm_mad/dummy/delete \ @@ -968,7 +971,8 @@ TM_DUMMY_FILES="src/tm_mad/dummy/clone \ src/tm_mad/dummy/context \ src/tm_mad/dummy/premigrate \ src/tm_mad/dummy/postmigrate \ - src/tm_mad/dummy/mvds" + src/tm_mad/dummy/mvds \ + src/tm_mad/dummy/cpds" TM_VMFS_FILES="src/tm_mad/vmfs/clone \ src/tm_mad/vmfs/delete @@ -978,6 +982,7 @@ TM_VMFS_FILES="src/tm_mad/vmfs/clone \ src/tm_mad/vmfs/mv \ src/tm_mad/vmfs/context \ src/tm_mad/vmfs/mvds \ + src/tm_mad/vmfs/cpds \ src/tm_mad/vmfs/postmigrate \ src/tm_mad/vmfs/premigrate" @@ -985,6 +990,7 @@ TM_ISCSI_FILES="src/tm_mad/iscsi/clone \ src/tm_mad/iscsi/ln \ src/tm_mad/iscsi/mv \ src/tm_mad/iscsi/mvds \ + src/tm_mad/iscsi/cpds \ src/tm_mad/iscsi/premigrate \ src/tm_mad/iscsi/postmigrate \ src/tm_mad/iscsi/delete" @@ -993,6 +999,7 @@ TM_LVM_FILES="src/tm_mad/lvm/clone \ src/tm_mad/lvm/ln \ src/tm_mad/lvm/mv \ src/tm_mad/lvm/mvds \ + src/tm_mad/lvm/cpds \ src/tm_mad/lvm/premigrate \ src/tm_mad/lvm/postmigrate \ src/tm_mad/lvm/delete" @@ -1001,6 +1008,7 @@ TM_CEPH_FILES="src/tm_mad/ceph/clone \ src/tm_mad/ceph/ln \ src/tm_mad/ceph/mv \ src/tm_mad/ceph/mvds \ + src/tm_mad/ceph/cpds \ src/tm_mad/ceph/premigrate \ src/tm_mad/ceph/postmigrate \ src/tm_mad/ceph/delete" diff --git a/src/tm_mad/ceph/cpds b/src/tm_mad/ceph/cpds new file mode 100755 index 0000000000..64e47842a8 --- /dev/null +++ b/src/tm_mad/ceph/cpds @@ -0,0 +1,70 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +# mvds host:remote_system_ds/disk.i fe:SOURCE +# - fe is the front-end hostname +# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host + +SRC=$1 +DST=$2 +VM_ID=$3 +DS_ID=$4 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +DRIVER_PATH=$(dirname $0) + +source $TMCOMMON +source ${DRIVER_PATH}/../../datastore/ceph/ceph.conf + +#------------------------------------------------------------------------------- +# Set dst path and dir +#------------------------------------------------------------------------------- + +SRC_HOST=`arg_host $SRC` +SRC_PATH=`arg_path $SRC` + +#------------------------------------------------------------------------------- +# Get Image information +#------------------------------------------------------------------------------- + +DISK_ID=$(echo "$SRC_PATH" | $AWK -F. '{print $NF}') + +XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" + +unset i j XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <(onevm show -x $VM_ID| $XPATH \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT) + +RBD_SRC="${XPATH_ELEMENTS[j++]}" +PERSISTENT="${XPATH_ELEMENTS[j++]}" + +ssh_exec_and_log "$DST_HOST" "$RBD copy $RBD_DST $DST" \ + "Error cloning $RBD_DST to $DST in $DST_HOST" + +exit 0 diff --git a/src/tm_mad/dummy/cpds b/src/tm_mad/dummy/cpds new file mode 120000 index 0000000000..300563f2ad --- /dev/null +++ b/src/tm_mad/dummy/cpds @@ -0,0 +1 @@ +../common/dummy.sh \ No newline at end of file diff --git a/src/tm_mad/iscsi/cpds b/src/tm_mad/iscsi/cpds new file mode 100755 index 0000000000..15706507a1 --- /dev/null +++ b/src/tm_mad/iscsi/cpds @@ -0,0 +1,92 @@ +#!/bin/bash + +# -------------------------------------------------------------------------- # +# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs # +# # +# Licensed under the Apache License, Version 2.0 (the "License"); you may # +# not use this file except in compliance with the License. You may obtain # +# a copy of the License at # +# # +# http://www.apache.org/licenses/LICENSE-2.0 # +# # +# Unless required by applicable law or agreed to in writing, software # +# distributed under the License is distributed on an "AS IS" BASIS, # +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # +# See the License for the specific language governing permissions and # +# limitations under the License. # +#--------------------------------------------------------------------------- # + +# mvds host:remote_system_ds/disk.i fe:SOURCE +# - fe is the front-end hostname +# - SOURCE is the path of the disk image in the form DS_BASE_PATH/disk +# - host is the target host to deploy the VM +# - remote_system_ds is the path for the system datastore in the host +# - vmid is the id of the VM +# - dsid is the target datastore (0 is the system datastore) + +SRC=$1 +DST=$2 + +VMID=$3 +DSID=$4 + +if [ -z "${ONE_LOCATION}" ]; then + TMCOMMON=/var/lib/one/remotes/tm/tm_common.sh +else + TMCOMMON=$ONE_LOCATION/var/remotes/tm/tm_common.sh +fi + +DRIVER_PATH=$(dirname $0) + +. $TMCOMMON + +source ${DRIVER_PATH}/../../datastore/iscsi/iscsi.conf + +SRC_HOST=`arg_host $SRC` +NEW_IQN="$DST" + +DISK_ID=$(echo $SRC|awk -F. '{print $NF}') + +#------------------------------------------------------------------------------- +# Get image information +#------------------------------------------------------------------------------- + +XPATH="${DRIVER_PATH}/../../datastore/xpath.rb --stdin" + +unset i XPATH_ELEMENTS + +while IFS= read -r -d '' element; do + XPATH_ELEMENTS[i++]="$element" +done < <(onevm show -x $VMID| $XPATH \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SOURCE \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/SAVE_AS \ + /VM/TEMPLATE/DISK[DISK_ID=$DISK_ID]/PERSISTENT) + +IQN="${XPATH_ELEMENTS[0]}" +SAVE_AS="${XPATH_ELEMENTS[1]}" +PERSISTENT="${XPATH_ELEMENTS[2]}" + +if [ -z "$PERSISTENT" ]; then + IQN=$IQN-$VMID +fi + +#------------------------------------------------------------------------------- +# IQN and TARGETs +#------------------------------------------------------------------------------- + +LV_NAME=`echo $IQN|$AWK -F. '{print $(NF)}'` +VG_NAME=`echo $IQN|$AWK -F. '{print $(NF-1)}'` +SOURCE_DEV="/dev/$VG_NAME/$LV_NAME" + +TARGET=`arg_path $IQN` +TARGET_LV_NAME=`echo $NEW_IQN|$AWK -F. '{print $(NF)}'` +TARGET_DEV="/dev/$VG_NAME/$TARGET_LV_NAME" +TARGET_HOST="${TARGET%.$VG_NAME.$LV_NAME}" + +CLONE_CMD=$(cat < Date: Fri, 8 Mar 2013 11:27:07 +0100 Subject: [PATCH 07/14] feature #1791: Add onevm saveas --hot to CLI and Ruby OCA --- src/cli/one_helper/onevm_helper.rb | 6 ++++++ src/cli/onevm | 11 +++++++++-- src/oca/ruby/opennebula/virtual_machine.rb | 13 +++++++++---- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index b04380d99e..332ce83a57 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -82,6 +82,12 @@ class OneVMHelper < OpenNebulaHelper::OneHelper :description => "Show all template data" } + HOT = { + :name =>"hot", + :large => "--hot", + :description => "The Image will be saved immediately" + } + def self.rname "VM" end diff --git a/src/cli/onevm b/src/cli/onevm index e8792192ab..9684bb6619 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -261,12 +261,19 @@ cmd=CommandParser::CmdParser.new(ARGV) do created immediately, but the contents are saved only if the VM is shut down gracefully (i.e., using 'onevm shutdown' and not 'onevm delete') + Sets the specified VM disk to be saved in a new Image. + + The Image is created immediately, but the contents are saved only if the + VM is shut down gracefully (i.e., using 'onevm shutdown' and not 'onevm + delete') + + If '--hot' is specified, the Image will be saved immediately. States: ANY EOT command :saveas, saveas_desc, :vmid, :diskid, :img_name, - :options=>[TYPE] do + :options=>[TYPE, OneVMHelper::HOT] do disk_id = args[1].to_i image_name = args[2] image_type = options[:type] || "" @@ -275,7 +282,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do "the image #{image_name}" helper.perform_action(args[0],options,verbose) do |vm| - res = vm.save_as(disk_id, image_name, image_type) + res = vm.save_as(disk_id, image_name, image_type, options[:hot]) if !OpenNebula.is_error?(res) puts "Image ID: #{res}" diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb index a338e97ecb..2c10a9b0b2 100644 --- a/src/oca/ruby/opennebula/virtual_machine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -52,7 +52,8 @@ module OpenNebula SAVE_MIGRATE PROLOG_MIGRATE PROLOG_RESUME EPILOG_STOP EPILOG SHUTDOWN CANCEL FAILURE CLEANUP_RESUBMIT UNKNOWN HOTPLUG SHUTDOWN_POWEROFF BOOT_UNKNOWN BOOT_POWEROFF BOOT_SUSPENDED BOOT_STOPPED CLEANUP_DELETE - HOTPLUG_SNAPSHOT HOTPLUG_NIC} + HOTPLUG_SNAPSHOT HOTPLUG_NIC HOTPLUG_SAVEAS HOTPLUG_SAVEAS_POWEROFF + HOTPLUG_SAVEAS_SUSPENDED} SHORT_VM_STATES={ "INIT" => "init", @@ -91,7 +92,10 @@ module OpenNebula "BOOT_STOPPED" => "boot", "CLEANUP_DELETE" => "clea", "HOTPLUG_SNAPSHOT" => "snap", - "HOTPLUG_NIC" => "hotp" + "HOTPLUG_NIC" => "hotp", + "HOTPLUG_SAVEAS" => "hotp", + "HOTPLUG_SAVEAS_POWEROFF" => "hotp", + "HOTPLUG_SAVEAS_SUSPENDED" => "hotp" } MIGRATE_REASON=%w{NONE ERROR STOP_RESUME USER CANCEL} @@ -350,14 +354,15 @@ module OpenNebula # # @return [Integer, OpenNebula::Error] the new Image ID in case of # success, error otherwise - def save_as(disk_id, image_name, image_type="") + def save_as(disk_id, image_name, image_type="", hot=false) return Error.new('ID not defined') if !@pe_id rc = @client.call(VM_METHODS[:savedisk], @pe_id, disk_id, image_name, - image_type) + image_type, + hot) return rc end From efa655a2b0ccc1f3e9f05c8b6a7c1f315b9a7b13 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 8 Mar 2013 12:27:00 +0100 Subject: [PATCH 08/14] feature #1791: minor typos --- src/image/ImageManagerDriver.cc | 5 ++--- src/tm/TransferManager.cc | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/image/ImageManagerDriver.cc b/src/image/ImageManagerDriver.cc index 469a9659d5..cf19508544 100644 --- a/src/image/ImageManagerDriver.cc +++ b/src/image/ImageManagerDriver.cc @@ -373,12 +373,11 @@ static void mkfs_action(istringstream& is, goto error_img; } - if ( is.good() ) + if ( is.fail() ) { is >> source >> ws; } - - if ( is.fail() ) + else { goto error_img; } diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index a7365b1903..2dcff9158d 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -124,7 +124,7 @@ void TransferManager::trigger(Actions action, int _vid) break; case SAVEAS_HOT: - aname = "DRIVER_CANCEL"; + aname = "SAVEAS_HOT"; break; case DRIVER_CANCEL: From f3d1b8d8a9678948dbcef0218e5648a55784acea Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 8 Mar 2013 12:29:05 +0100 Subject: [PATCH 09/14] feature #1791: more minor typos --- src/image/ImageManagerDriver.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/image/ImageManagerDriver.cc b/src/image/ImageManagerDriver.cc index cf19508544..6e9b38ec0e 100644 --- a/src/image/ImageManagerDriver.cc +++ b/src/image/ImageManagerDriver.cc @@ -373,7 +373,7 @@ static void mkfs_action(istringstream& is, goto error_img; } - if ( is.fail() ) + if ( !is.fail() ) { is >> source >> ws; } From 482ae7d22848e3cfb5a94c199e73ec80bb348442 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 8 Mar 2013 12:42:42 +0100 Subject: [PATCH 10/14] feature #1791: proper state checking --- src/vm/VirtualMachine.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index b63aeb4d30..2381c36f23 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -2636,8 +2636,8 @@ int VirtualMachine::save_disk_hot(const string& disk_id, num_disks = obj_template->get("DISK", disks); - if (lcm_state != HOTPLUG_SAVEAS || lcm_state != HOTPLUG_SAVEAS_SUSPENDED - || lcm_state != HOTPLUG_SAVEAS_POWEROFF ) + if (lcm_state != HOTPLUG_SAVEAS && lcm_state != HOTPLUG_SAVEAS_SUSPENDED + && lcm_state != HOTPLUG_SAVEAS_POWEROFF ) { return -1; } From 4167c140662062d193e95ccffb792e6fe8d461d4 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 8 Mar 2013 12:47:53 +0100 Subject: [PATCH 11/14] feature #1791: proper state checking for simple save action as well --- src/vm/VirtualMachine.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 2381c36f23..6761e464f8 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -2589,8 +2589,8 @@ int VirtualMachine::save_disk(const string& disk_id, int num_disks = obj_template->get("DISK",disks); - if (lcm_state != HOTPLUG_SAVEAS || lcm_state != HOTPLUG_SAVEAS_SUSPENDED - || lcm_state != HOTPLUG_SAVEAS_POWEROFF ) + if (lcm_state != HOTPLUG_SAVEAS && lcm_state != HOTPLUG_SAVEAS_SUSPENDED + && lcm_state != HOTPLUG_SAVEAS_POWEROFF ) { return -1; } From ea8afc435b5dd32e65e1d677976f91af40f48b07 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 8 Mar 2013 14:26:03 +0100 Subject: [PATCH 12/14] feature #1791: Add new states to JAVA bindings, and Sunstone --- share/doc/xsd/acct.xsd | 5 ++++- share/doc/xsd/vm.xsd | 5 ++++- .../opennebula/client/vm/VirtualMachine.java | 21 +++++++++++++------ src/ozones/Server/public/js/ozones.js | 5 ++++- src/sunstone/public/js/opennebula.js | 5 ++++- src/sunstone/public/js/plugins/vms-tab.js | 3 +-- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/share/doc/xsd/acct.xsd b/share/doc/xsd/acct.xsd index 7234640862..f7c7d29381 100644 --- a/share/doc/xsd/acct.xsd +++ b/share/doc/xsd/acct.xsd @@ -108,7 +108,10 @@ BOOT_STOPPED = 22, CLEANUP_DELETE = 23, HOTPLUG_SNAPSHOT = 24, - HOTPLUG_NIC = 25 + HOTPLUG_NIC = 25, + HOTPLUG_SAVEAS = 26, + HOTPLUG_SAVEAS_POWEROFF = 27, + HOTPLUG_SAVEAS_SUSPENDED = 28 --> diff --git a/share/doc/xsd/vm.xsd b/share/doc/xsd/vm.xsd index 08a73a8f44..fa5babf322 100644 --- a/share/doc/xsd/vm.xsd +++ b/share/doc/xsd/vm.xsd @@ -70,7 +70,10 @@ BOOT_STOPPED = 22, CLEANUP_DELETE = 23, HOTPLUG_SNAPSHOT = 24, - HOTPLUG_NIC = 25 + HOTPLUG_NIC = 25, + HOTPLUG_SAVEAS = 26, + HOTPLUG_SAVEAS_POWEROFF = 27, + HOTPLUG_SAVEAS_SUSPENDED = 28 --> diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index 7a9949e525..c8322af13b 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -96,7 +96,10 @@ public class VirtualMachine extends PoolElement{ "BOOT_STOPPED", "CLEANUP_DELETE", "HOTPLUG_SNAPSHOT", - "HOTPLUG_NIC" }; + "HOTPLUG_NIC", + "HOTPLUG_SAVEAS", + "HOTPLUG_SAVEAS_POWEROFF", + "HOTPLUG_SAVEAS_SUSPENDED" }; private static final String[] SHORT_LCM_STATES = { @@ -124,7 +127,11 @@ public class VirtualMachine extends PoolElement{ "boot", "boot", "clea", - "snap" }; + "snap", + "hotp", + "hotp", + "hotp", + "hotp" }; /** * Creates a new VM representation. @@ -468,9 +475,9 @@ public class VirtualMachine extends PoolElement{ * @param imageName Name of the new Image that will be created. * @return If an error occurs the error message contains the reason. */ - public OneResponse savedisk(int diskId, String imageName) + public OneResponse savedisk(int diskId, String imageName, boolean hot = false) { - return savedisk(diskId, imageName, ""); + return savedisk(diskId, imageName, "", hot); } /** @@ -481,11 +488,13 @@ public class VirtualMachine extends PoolElement{ * @param imageName Name of the new Image that will be created. * @param imageType Type of the new image. Set to empty string to use * the default type + * @param hot do not defer saveas operation * @return If an error occurs the error message contains the reason. */ - public OneResponse savedisk(int diskId, String imageName, String imageType) + public OneResponse savedisk(int diskId, String imageName, String imageType, + boolean hot) { - return client.call(SAVEDISK, id ,diskId, imageName, imageType); + return client.call(SAVEDISK, id ,diskId, imageName, imageType, hot); } /** diff --git a/src/ozones/Server/public/js/ozones.js b/src/ozones/Server/public/js/ozones.js index ab47b88fc4..e8661caccd 100644 --- a/src/ozones/Server/public/js/ozones.js +++ b/src/ozones/Server/public/js/ozones.js @@ -104,7 +104,10 @@ var oZones = { "BOOT_STOPPED", "CLEANUP_DELETE", "HOTPLUG_SNAPSHOT", - "HOTPLUG_NIC"][value]); + "HOTPLUG_NIC", + "HOTPLUG_SAVEAS", + "HOTPLUG_SAVEAS_POWEROFF", + "HOTPLUG_SAVEAS_SUSPENDED"][value]); break; case "IMAGE": case "image": diff --git a/src/sunstone/public/js/opennebula.js b/src/sunstone/public/js/opennebula.js index 4008cee7a1..a512a2bf32 100644 --- a/src/sunstone/public/js/opennebula.js +++ b/src/sunstone/public/js/opennebula.js @@ -112,7 +112,10 @@ var OpenNebula = { "BOOT_STOPPED", "CLEANUP_DELETE", "HOTPLUG_SNAPSHOT", - "HOTPLUG_NIC"][value]); + "HOTPLUG_NIC", + "HOTPLUG_SAVEAS", + "HOTPLUG_SAVEAS_POWEROFF", + "HOTPLUG_SAVEAS_SUSPENDED"][value]); break; case "IMAGE": case "image": diff --git a/src/sunstone/public/js/plugins/vms-tab.js b/src/sunstone/public/js/plugins/vms-tab.js index a2654070cc..0aa73874ab 100644 --- a/src/sunstone/public/js/plugins/vms-tab.js +++ b/src/sunstone/public/js/plugins/vms-tab.js @@ -49,8 +49,7 @@ var vm_graphs = [ } ]; - -var VNCstates=["RUNNING","SHUTDOWN","SHUTDOWN_POWEROFF","UNKNOWN","HOTPLUG","CANCEL","MIGRATE", "HOTPLUG_SNAPSHOT", "HOTPLUG_NIC"]; +var VNCstates=["RUNNING","SHUTDOWN","SHUTDOWN_POWEROFF","UNKNOWN","HOTPLUG","CANCEL","MIGRATE", "HOTPLUG_SNAPSHOT", "HOTPLUG_NIC", "HOTPLUG_SAVEAS", "HOTPLUG_SAVEAS_POWEROFF", "HOTPLUG_SAVEAS_SUSPENDED"]; //Permanent storage for last value of aggregated network usage //Used to calculate bandwidth From 8f3fdaf943d1093622a421ffafacb9cee2790d71 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Fri, 8 Mar 2013 14:37:03 +0100 Subject: [PATCH 13/14] bug #1799: Remove NAME from template in VMTemplate and Document classes --- src/document/Document.cc | 6 +++--- src/vm_template/VMTemplate.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/document/Document.cc b/src/document/Document.cc index b6481e9010..4343d694e5 100644 --- a/src/document/Document.cc +++ b/src/document/Document.cc @@ -79,7 +79,7 @@ int Document::insert(SqlDB *db, string& error_str) // Check default attributes // --------------------------------------------------------------------- - get_template_attribute("NAME", name); + erase_template_attribute("NAME", name); if ( name.empty() == true ) { @@ -199,8 +199,8 @@ string& Document::to_xml(string& xml) const << "" << oid << "" << "" << uid << "" << "" << gid << "" - << "" << uname << "" - << "" << gname << "" + << "" << uname << "" + << "" << gname << "" << "" << name << "" << "" << type << "" << perms_to_xml(perm_str) diff --git a/src/vm_template/VMTemplate.cc b/src/vm_template/VMTemplate.cc index af638437fd..822885c0ad 100644 --- a/src/vm_template/VMTemplate.cc +++ b/src/vm_template/VMTemplate.cc @@ -81,7 +81,7 @@ int VMTemplate::insert(SqlDB *db, string& error_str) // Check default attributes // --------------------------------------------------------------------- - get_template_attribute("NAME", name); + erase_template_attribute("NAME", name); if ( name.empty() == true ) { From f522e120848657ef2f19dc736797d6101a492c59 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Fri, 8 Mar 2013 16:03:31 +0100 Subject: [PATCH 14/14] feature #1791: fix the ceph cpds script --- src/tm_mad/ceph/cpds | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/tm_mad/ceph/cpds b/src/tm_mad/ceph/cpds index 64e47842a8..bd729f2e7a 100755 --- a/src/tm_mad/ceph/cpds +++ b/src/tm_mad/ceph/cpds @@ -64,7 +64,13 @@ done < <(onevm show -x $VM_ID| $XPATH \ RBD_SRC="${XPATH_ELEMENTS[j++]}" PERSISTENT="${XPATH_ELEMENTS[j++]}" -ssh_exec_and_log "$DST_HOST" "$RBD copy $RBD_DST $DST" \ +if [ "$PERSISTENT" = "YES" ]; then + RBD_DST="${RBD_SRC}" +else + RBD_DST="${RBD_SRC}-${VM_ID}-${DISK_ID}" +fi + +ssh_exec_and_log "$SRC_HOST" "$RBD copy $RBD_DST $DST" \ "Error cloning $RBD_DST to $DST in $DST_HOST" exit 0