From ab619a50f4cfb4663f3a6e551ce6b9c8a175ccbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 21 Nov 2013 18:28:49 +0100 Subject: [PATCH] Bug #2487: RM forces the system DS for stopped/undeployed VMs --- include/VirtualMachine.h | 22 +++++++++- src/rm/RequestManagerVirtualMachine.cc | 61 +++++++++++++++++++++----- src/tm/TransferManager.cc | 20 ++++----- src/vmm/LibVirtDriverVMware.cc | 8 ++-- 4 files changed, 84 insertions(+), 27 deletions(-) diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 6a8d8ccec6..c137fd75a6 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -496,7 +496,7 @@ public: * function MUST be called before this one. * @return the ds id */ - string get_ds_id() const + string get_ds_id_st() const { ostringstream oss; @@ -505,6 +505,16 @@ public: return oss.str(); }; + /** + * Returns the datastore ID of the system DS for the host. The hasHistory() + * function MUST be called before this one. + * @return the ds id + */ + int get_ds_id() const + { + return history->ds_id; + }; + /** * Returns the datastore ID of the system DS for the previous host. * The hasPreviousHistory() function MUST be called before this one. @@ -653,6 +663,16 @@ public: return previous_history->reason; }; + /** + * Returns the action that closed the current history record. The hasHistory() + * function MUST be called before this one. + * @return the action that closed the current history record + */ + const History::VMAction get_action() const + { + return history->action; + }; + /** * Returns the action that closed the history record in the previous host * @return the action that closed the history record in the previous host diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 347d46cb48..12a3153f61 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -660,6 +660,50 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, return; } + // ------------------------------------------------------------------------ + // Authorize request + // ------------------------------------------------------------------------ + + auth = vm_authorization(id, 0, 0, att, &host_perms, 0, auth_op); + + if (auth == false) + { + return; + } + + if ((vm = get_vm(id, att)) == 0) + { + return; + } + + if (vm->hasHistory() && + (vm->get_action() == History::STOP_ACTION || + vm->get_action() == History::UNDEPLOY_ACTION || + vm->get_action() == History::UNDEPLOY_HARD_ACTION)) + { + int c_ds_id = vm->get_ds_id(); + + if (ds_id == -1) + { + ds_id = c_ds_id; + } + else if (ds_id != c_ds_id) + { + ostringstream oss; + + oss << "VM can only be resumed in System Datastore " + << "[" << c_ds_id << "]"; + + failure_response(ACTION, request_error(oss.str(),""), att); + + vm->unlock(); + + return; + } + } + + vm->unlock(); + // ------------------------------------------------------------------------ // Get information about the system DS to use (tm_mad) // ------------------------------------------------------------------------ @@ -694,17 +738,6 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, } } - // ------------------------------------------------------------------------ - // Authorize request - // ------------------------------------------------------------------------ - - auth = vm_authorization(id, 0, 0, att, &host_perms, 0, auth_op); - - if (auth == false) - { - return; - } - // ------------------------------------------------------------------------ // Check request consistency: // - VM States are right @@ -748,6 +781,10 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, } } + + + + // ------------------------------------------------------------------------ // Add a new history record and deploy the VM // ------------------------------------------------------------------------ @@ -882,7 +919,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList // Get System DS information from current History record - istringstream iss(vm->get_ds_id()); + istringstream iss(vm->get_ds_id_st()); iss >> c_ds_id; diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index a83f01a7e2..d45c6907db 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -384,7 +384,7 @@ int TransferManager::prolog_transfer_command( int disk_id; - vm_ds_id = vm->get_ds_id(); + vm_ds_id = vm->get_ds_id_st(); disk->vector_value("DISK_ID", disk_id); @@ -747,7 +747,7 @@ void TransferManager::prolog_action(int vid) xfr << vm->get_hostname() << ":" << vm->get_remote_system_dir() << "/disk." << disk_id << " " << vm->get_oid() << " " - << vm->get_ds_id() + << vm->get_ds_id_st() << endl; } @@ -829,7 +829,7 @@ void TransferManager::prolog_migr_action(int vid) } vm_tm_mad = vm->get_tm_mad(); - vm_ds_id = vm->get_ds_id(); + vm_ds_id = vm->get_ds_id_st(); tm_md = get(); if ( tm_md == 0 || vm_tm_mad.empty() || vm_ds_id.empty()) @@ -969,7 +969,7 @@ void TransferManager::prolog_resume_action(int vid) } vm_tm_mad = vm->get_tm_mad(); - vm_ds_id = vm->get_ds_id(); + vm_ds_id = vm->get_ds_id_st(); tm_md = get(); if ( tm_md == 0 || vm_tm_mad.empty() || vm_ds_id.empty()) @@ -1128,7 +1128,7 @@ void TransferManager::epilog_transfer_command( if ( VirtualMachine::isVolatile(disk) == true ) { tm_mad = vm->get_tm_mad(); - ds_id = vm->get_ds_id(); + ds_id = vm->get_ds_id_st(); } else { @@ -1188,7 +1188,7 @@ void TransferManager::epilog_action(int vid) } vm_tm_mad = vm->get_tm_mad(); - vm_ds_id = vm->get_ds_id(); + vm_ds_id = vm->get_ds_id_st(); tm_md = get(); if ( tm_md == 0 || vm_tm_mad.empty() || vm_ds_id.empty()) @@ -1299,7 +1299,7 @@ void TransferManager::epilog_stop_action(int vid) } vm_tm_mad = vm->get_tm_mad(); - vm_ds_id = vm->get_ds_id(); + vm_ds_id = vm->get_ds_id_st(); tm_md = get(); if ( tm_md == 0 || vm_tm_mad.empty() || vm_ds_id.empty()) @@ -1438,7 +1438,7 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm, system_dir = vm->get_system_dir(); vm_tm_mad = vm->get_tm_mad(); - vm_ds_id = vm->get_ds_id(); + vm_ds_id = vm->get_ds_id_st(); } else if (previous) { @@ -1459,7 +1459,7 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm, system_dir = vm->get_remote_system_dir(); vm_tm_mad = vm->get_tm_mad(); - vm_ds_id = vm->get_ds_id(); + vm_ds_id = vm->get_ds_id_st(); } if ( vm_tm_mad.empty() || vm_ds_id.empty()) @@ -1956,7 +1956,7 @@ void TransferManager::migrate_transfer_command( << vm->get_hostname() << " " << vm->get_remote_system_dir() << " " << vm->get_oid() << " " - << vm->get_ds_id() + << vm->get_ds_id_st() << endl; } diff --git a/src/vmm/LibVirtDriverVMware.cc b/src/vmm/LibVirtDriverVMware.cc index cc2135d866..9554361a0c 100644 --- a/src/vmm/LibVirtDriverVMware.cc +++ b/src/vmm/LibVirtDriverVMware.cc @@ -276,19 +276,19 @@ int LibVirtDriver::deployment_description_vmware( if ( type == "BLOCK" ) { file << "\t\t" << endl; - file << "\t\t\tget_ds_id_st() << "] " << vm->get_oid() << "/disk." << disk_id << "'/>" << endl; } else if ( type == "CDROM" ) { file << "\t\t" << endl; - file << "\t\t\tget_ds_id_st() << "] " << vm->get_oid() << "/disk." << disk_id << ".iso'/>" << endl; } else { file << "\t\t" << endl - << "\t\t\tget_ds_id_st() <<"] " << vm->get_oid() << "/disk." << disk_id << "/disk.vmdk'/>" << endl; } @@ -337,7 +337,7 @@ int LibVirtDriver::deployment_description_vmware( if ( !target.empty() ) { file << "\t\t" << endl; - file << "\t\t\tget_ds_id_st() <<"] " << vm->get_oid() << "/disk." << disk_id << ".iso'/>" << endl; file << "\t\t\t" << endl; file << "\t\t\t" << endl;