diff --git a/SConstruct b/SConstruct index 6b87af6dae..bf5273d1e6 100755 --- a/SConstruct +++ b/SConstruct @@ -118,7 +118,7 @@ main_env.Append(LIBPATH=[ main_env.Append(CPPFLAGS=[ "-g", "-Wall", - "-std=c++14" + "-std=c++17" ]) # Linking flags & common libraries @@ -129,6 +129,26 @@ main_env.Append(LIBS=['z']) # EXTRA CONFIGURATION # ####################### +# Generate help text +vars = Variables('custom.py') +vars.Add('sqlite_dir', 'Path to sqlite directory', '') +vars.Add('sqlite', 'Build with SQLite support', 'yes') +vars.Add('mysql', 'Build with MySQL support', 'no') +vars.Add('postgresql', 'Build with PostgreSQL support', 'no') +vars.Add('parsers', 'Obsolete. Rebuild flex/bison files', 'no') +vars.Add('xmlrpc', 'Path to xmlrpc directory', '') +vars.Add('new_xmlrpc', 'Use xmlrpc-c version >=1.31', 'no') +vars.Add('sunstone', 'Build Sunstone', 'no') +vars.Add('fireedge', 'Build FireEdge', 'no') +vars.Add('systemd', 'Build with systemd support', 'no') +vars.Add('docker_machine', 'Build Docker machine driver', 'no') +vars.Add('rubygems', 'Generate Ruby gems', 'no') +vars.Add('svncterm', 'Build VNC support for LXD drivers', 'yes') +vars.Add('context', 'Download guest contextualization packages', 'no') +vars.Add('strict', 'Strict C++ compiler, more warnings, treat warnings as errors', 'no') +env = Environment(variables = vars) +Help(vars.GenerateHelpText(env)) + # SQLITE sqlite_dir = ARGUMENTS.get('sqlite_dir', "none") if sqlite_dir != 'none': @@ -192,6 +212,18 @@ if build_parsers == 'yes': else: main_env.Append(parsers='no') +# strict: Add more warnings add treat warnings as errors +strict = ARGUMENTS.get('strict', 'no') +if strict == 'yes': + main_env.Append(CPPFLAGS=[ + "-Wextra", + "-Werror", + "-Wno-error=deprecated-declarations", + "-Wno-unused-parameter", + "-Wno-unused-result" + ]) + + # Rubygem generation main_env.Append(rubygems=ARGUMENTS.get('rubygems', 'no')) diff --git a/include/Attribute.h b/include/Attribute.h index 0eb0c699ad..80e2109403 100644 --- a/include/Attribute.h +++ b/include/Attribute.h @@ -32,13 +32,10 @@ class Attribute { public: - Attribute(const std::string& aname):attribute_name(aname) + Attribute(const std::string& aname) + : attribute_name(aname) { - transform ( - attribute_name.begin(), - attribute_name.end(), - attribute_name.begin(), - (int(*)(int))toupper); + one_util::toupper(attribute_name); // FIX Attribute name if it does not conform XML element // naming conventions @@ -117,6 +114,8 @@ protected: * The attribute name. */ std::string attribute_name; + + static const std::string EMPTY_ATTRIBUTE; }; /* -------------------------------------------------------------------------- */ @@ -267,16 +266,15 @@ public: , attribute_value(value) {} - VectorAttribute(const VectorAttribute& va) - : Attribute(va.attribute_name) - , attribute_value(va.attribute_value) - {} + VectorAttribute(const VectorAttribute& va) = default; VectorAttribute(const VectorAttribute* va) : Attribute(va->attribute_name) , attribute_value(va->attribute_value) {} + VectorAttribute& operator=(const VectorAttribute& va) = default; + ~VectorAttribute(){}; /** @@ -291,9 +289,23 @@ public: * Returns the string value * @param name of the attribute * - * @return the value of the attribute if found, empty otherwise + * @return copy of the value of the attribute if found, empty otherwise + * + * @note Non const version must return copy, as subsequent call to replace or remove + * may change the value */ - std::string vector_value(const std::string& name) const; + std::string vector_value(const std::string& name); + + /** + * Returns the string value + * @param name of the attribute + * + * @return reference of the value of the attribute if found, empty otherwise + * + * @note It's safe to return reference here, as we are using + * the const object, which can't change the value + */ + const std::string& vector_value(const std::string& name) const; /** * Returns the value of the given element of the VectorAttribute @@ -371,18 +383,18 @@ public: * @return the value in string form on success, "" otherwise */ template - std::string vector_value_str(const std::string& name, T& value) const + const std::string& vector_value_str(const std::string& name, T& value) const { auto it = attribute_value.find(name); if ( it == attribute_value.end() ) { - return ""; + return EMPTY_ATTRIBUTE; } if ( it->second.empty() ) { - return ""; + return EMPTY_ATTRIBUTE; } std::istringstream iss(it->second); @@ -390,7 +402,7 @@ public: if (iss.fail() || !iss.eof()) { - return ""; + return EMPTY_ATTRIBUTE; } return it->second; @@ -445,7 +457,7 @@ public: * Replace the value of the given vector attribute */ template - void replace(const std::string& name, T value) + void replace(const std::string& name, const T& value) { std::ostringstream oss; diff --git a/include/DriverManager.h b/include/DriverManager.h index dd18401bec..00aa4d0d8d 100644 --- a/include/DriverManager.h +++ b/include/DriverManager.h @@ -110,9 +110,9 @@ private: template int DriverManager::load_driver(const VectorAttribute* mad_config) { - auto name = mad_config->vector_value("NAME"); + const auto& name = mad_config->vector_value("NAME"); auto exec = mad_config->vector_value("EXECUTABLE"); - auto args = mad_config->vector_value("ARGUMENTS"); + const auto& args = mad_config->vector_value("ARGUMENTS"); int threads; mad_config->vector_value("THREADS", threads, 0); diff --git a/include/ExtendedAttribute.h b/include/ExtendedAttribute.h index e0fe67593e..0a3f1e0e39 100644 --- a/include/ExtendedAttribute.h +++ b/include/ExtendedAttribute.h @@ -48,13 +48,18 @@ public: return va->vector_value(name, value); } - std::string vector_value(const std::string& name) const + std::string vector_value(const std::string& name) { return va->vector_value(name); } + const std::string& vector_value(const std::string& name) const + { + return const_cast(va)->vector_value(name); + } + template - void replace(const std::string& name, T value) + void replace(const std::string& name, const T& value) { va->replace(name, value); } diff --git a/include/LifeCycleManager.h b/include/LifeCycleManager.h index c5eeebed8c..0a033f71b8 100644 --- a/include/LifeCycleManager.h +++ b/include/LifeCycleManager.h @@ -152,7 +152,6 @@ public: void trigger_suspend(int vid, const RequestAttributes& ra); void trigger_restore(int vid, const RequestAttributes& ra); void trigger_stop(int vid, const RequestAttributes& ra); - void trigger_checkpoint(int vid); void trigger_migrate(int vid, const RequestAttributes& ra, VMActions::Action vm_action); void trigger_migrate(int vid, const RequestAttributes& ra) diff --git a/include/Quota.h b/include/Quota.h index cdfdb9ab49..8e3f5634f1 100644 --- a/include/Quota.h +++ b/include/Quota.h @@ -301,7 +301,7 @@ private: * * @return a new attribute representing the quota, 0 on error */ - VectorAttribute * new_quota(VectorAttribute* va); + VectorAttribute * new_quota(const VectorAttribute* va); /** * Adds a new quota, it also updates an internal index for fast accessing diff --git a/include/TransferManager.h b/include/TransferManager.h index aee33b36e5..09373c4c81 100644 --- a/include/TransferManager.h +++ b/include/TransferManager.h @@ -148,7 +148,7 @@ public: * * @return 0 on success */ - int snapshot_transfer_command(VirtualMachine * vm, + int snapshot_transfer_command(const VirtualMachine * vm, const char * snap_action, std::ostream& xfr); @@ -292,11 +292,6 @@ public: */ void trigger_epilog_detach(VirtualMachine * vm); - /** - * This function starts the epilog sequence - */ - void trigger_checkpoint(int vid); - /** * This function cancels the operation being performed by the driver */ diff --git a/include/VMGroupRole.h b/include/VMGroupRole.h index a9ad0541fa..bbfacef587 100644 --- a/include/VMGroupRole.h +++ b/include/VMGroupRole.h @@ -75,7 +75,7 @@ public: */ VMGroupPolicy policy(); - std::string policy_s() + std::string policy_s() const { return va->vector_value("POLICY"); }; diff --git a/include/VirtualMachineDisk.h b/include/VirtualMachineDisk.h index 8c307fa270..1706aeaaf9 100644 --- a/include/VirtualMachineDisk.h +++ b/include/VirtualMachineDisk.h @@ -603,7 +603,7 @@ public: */ VirtualMachineDisk * set_up_attach(int vmid, int uid, int cluster_id, VectorAttribute * vdisk, const std::string& tsys, - VectorAttribute * vcontext, std::string& error); + const VectorAttribute * vcontext, std::string& error); /* ---------------------------------------------------------------------- */ /* Save as Interface */ diff --git a/include/VirtualMachineTemplate.h b/include/VirtualMachineTemplate.h index 944aee9201..0f79e41279 100644 --- a/include/VirtualMachineTemplate.h +++ b/include/VirtualMachineTemplate.h @@ -40,6 +40,8 @@ public: VirtualMachineTemplate(const Template& vmt):Template(vmt){}; + VirtualMachineTemplate(const VirtualMachineTemplate& t) = default; + VirtualMachineTemplate& operator=(const VirtualMachineTemplate& t) { if (this != &t) diff --git a/src/common/Attribute.cc b/src/common/Attribute.cc index cb1977df1b..11235336c2 100644 --- a/src/common/Attribute.cc +++ b/src/common/Attribute.cc @@ -25,6 +25,7 @@ using namespace std; const char * VectorAttribute::magic_sep = "@^_^@"; const int VectorAttribute::magic_sep_size = 5; +const string Attribute::EMPTY_ATTRIBUTE = ""; string VectorAttribute::marshall(const char * _sep) const { @@ -252,13 +253,30 @@ void VectorAttribute::remove(const string& name) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -string VectorAttribute::vector_value(const string& name) const +string VectorAttribute::vector_value(const string& name) { auto it = attribute_value.find(name); if ( it == attribute_value.end() ) { - return ""; + return EMPTY_ATTRIBUTE; + } + else + { + return it->second; + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +const string& VectorAttribute::vector_value(const string& name) const +{ + auto it = attribute_value.find(name); + + if ( it == attribute_value.end() ) + { + return EMPTY_ATTRIBUTE; } else { diff --git a/src/common/NebulaService.cc b/src/common/NebulaService.cc index 5763a5cdb0..35a091bf22 100644 --- a/src/common/NebulaService.cc +++ b/src/common/NebulaService.cc @@ -29,7 +29,7 @@ Log::MessageType NebulaService::get_debug_level(Log::MessageType default_) const if (log != 0) { - string value = log->vector_value("DEBUG_LEVEL"); + const string& value = log->vector_value("DEBUG_LEVEL"); log_level_int = std::atoi(value.c_str()); diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index 878327934a..1621d1d988 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -465,7 +465,7 @@ int DispatchManager::terminate(int vid, bool hard, const RequestAttributes& ra, break; } // else fallthrough to default - + [[fallthrough]]; default: oss.str(""); oss << "Could not terminate VM " << vid @@ -1220,6 +1220,8 @@ int DispatchManager::delete_recreate(unique_ptr vm, do_quotas = true; + [[fallthrough]]; + case VirtualMachine::HOLD: if (vm->hasHistory()) { @@ -1294,6 +1296,8 @@ int DispatchManager::delete_vm_db(unique_ptr vm, hpool->del_capacity(vm->get_hid(), sr); + [[fallthrough]]; + case VirtualMachine::STOPPED: case VirtualMachine::UNDEPLOYED: case VirtualMachine::INIT: diff --git a/src/host/HostSharePCI.cc b/src/host/HostSharePCI.cc index 508ad2a1b9..9e492352db 100644 --- a/src/host/HostSharePCI.cc +++ b/src/host/HostSharePCI.cc @@ -340,7 +340,7 @@ void HostSharePCI::clear() int HostSharePCI::get_pci_value(const char * name, const VectorAttribute * pci_device, unsigned int &pci_value) { - string temp = pci_device->vector_value(name); + const string& temp = pci_device->vector_value(name); if (temp.empty()) { diff --git a/src/lcm/LifeCycleActions.cc b/src/lcm/LifeCycleActions.cc index d009add5ff..bd087239af 100644 --- a/src/lcm/LifeCycleActions.cc +++ b/src/lcm/LifeCycleActions.cc @@ -862,6 +862,8 @@ void LifeCycleManager::trigger_delete(int vid, const RequestAttributes& ra) vm->set_state(VirtualMachine::CLEANUP_DELETE); vmpool->update(vm.get()); + [[fallthrough]]; + case VirtualMachine::CLEANUP_DELETE: dm->trigger_done(vid); break; diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index eae1ecae61..e96365e902 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -1941,6 +1941,7 @@ void LifeCycleManager::trigger_disk_snapshot_success(int vid) { case VirtualMachine::DISK_SNAPSHOT: vm->set_state(VirtualMachine::RUNNING); + [[fallthrough]]; case VirtualMachine::DISK_SNAPSHOT_POWEROFF: case VirtualMachine::DISK_SNAPSHOT_SUSPENDED: vm->log("LCM", Log::INFO, "VM disk snapshot operation completed."); @@ -1955,6 +1956,7 @@ void LifeCycleManager::trigger_disk_snapshot_success(int vid) case VirtualMachine::DISK_SNAPSHOT_DELETE: vm->set_state(VirtualMachine::RUNNING); + [[fallthrough]]; case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF: case VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED: vm->log("LCM", Log::INFO, "VM disk snapshot deleted."); @@ -2089,6 +2091,7 @@ void LifeCycleManager::trigger_disk_snapshot_failure(int vid) { case VirtualMachine::DISK_SNAPSHOT: vm->set_state(VirtualMachine::RUNNING); + [[fallthrough]]; case VirtualMachine::DISK_SNAPSHOT_POWEROFF: case VirtualMachine::DISK_SNAPSHOT_SUSPENDED: vm->log("LCM", Log::ERROR, "Could not take disk snapshot."); @@ -2098,6 +2101,7 @@ void LifeCycleManager::trigger_disk_snapshot_failure(int vid) case VirtualMachine::DISK_SNAPSHOT_DELETE: vm->set_state(VirtualMachine::RUNNING); + [[fallthrough]]; case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF: case VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF: case VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED: @@ -2312,6 +2316,7 @@ void LifeCycleManager::trigger_disk_resize_success(int vid) { case VirtualMachine::DISK_RESIZE: vm->set_state(VirtualMachine::RUNNING); + [[fallthrough]]; case VirtualMachine::DISK_RESIZE_POWEROFF: case VirtualMachine::DISK_RESIZE_UNDEPLOYED: @@ -2390,7 +2395,7 @@ void LifeCycleManager::trigger_disk_resize_failure(int vid) { case VirtualMachine::DISK_RESIZE: vm->set_state(VirtualMachine::RUNNING); - + [[fallthrough]]; case VirtualMachine::DISK_RESIZE_POWEROFF: case VirtualMachine::DISK_RESIZE_UNDEPLOYED: vm->log("LCM", Log::INFO, "VM disk resize operation completed."); diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 76ad18ab4d..292f803880 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -1296,20 +1296,14 @@ int Nebula::get_conf_attribute( const VectorAttribute* &value) const { std::vector values; - std::string template_name; - std::string name_upper = name; - - one_util::toupper(name_upper); nebula_configuration->get(key, values); for (auto vattr : values) { - template_name = vattr->vector_value("NAME"); + const string& template_name = vattr->vector_value("NAME"); - one_util::toupper(template_name); - - if ( template_name == name_upper ) + if ( one_util::icasecmp(name, template_name) ) { value = vattr; return 0; diff --git a/src/raft/RaftManager.cc b/src/raft/RaftManager.cc index 6417554462..021a3d2b06 100644 --- a/src/raft/RaftManager.cc +++ b/src/raft/RaftManager.cc @@ -67,7 +67,7 @@ RaftManager::RaftManager(int id, const VectorAttribute * leader_hook_mad, Nebula& nd = Nebula::instance(); LogDB * logdb = nd.get_logdb(); - std::string raft_xml, cmd, arg; + std::string raft_xml; // ------------------------------------------------------------------------- // Initialize Raft variables: @@ -138,8 +138,8 @@ RaftManager::RaftManager(int id, const VectorAttribute * leader_hook_mad, if ( leader_hook_mad != 0 ) { - cmd = leader_hook_mad->vector_value("COMMAND"); - arg = leader_hook_mad->vector_value("ARGUMENTS"); + const string& cmd = leader_hook_mad->vector_value("COMMAND"); + const string& arg = leader_hook_mad->vector_value("ARGUMENTS"); if ( cmd.empty() ) { @@ -159,8 +159,8 @@ RaftManager::RaftManager(int id, const VectorAttribute * leader_hook_mad, if ( follower_hook_mad != 0 ) { - cmd = follower_hook_mad->vector_value("COMMAND"); - arg = follower_hook_mad->vector_value("ARGUMENTS"); + const string& cmd = follower_hook_mad->vector_value("COMMAND"); + const string& arg = follower_hook_mad->vector_value("ARGUMENTS"); if ( cmd.empty() ) { diff --git a/src/scheduler/include/VirtualMachineXML.h b/src/scheduler/include/VirtualMachineXML.h index d3d803418d..a3d2d28ea9 100644 --- a/src/scheduler/include/VirtualMachineXML.h +++ b/src/scheduler/include/VirtualMachineXML.h @@ -414,7 +414,7 @@ public: * * @param action sched action to update */ - bool update_sched_action(SchedAction* action); + bool update_sched_action(const SchedAction* action); /** * Sets an attribute in the VM Template, it must be allocated in the heap diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index 8772f92075..ce0bff4cd2 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -677,13 +677,13 @@ int VirtualMachineXML::parse_action_name(string& action_st) // Updates to oned //****************************************************************************** -bool VirtualMachineXML::update_sched_action(SchedAction* action) +bool VirtualMachineXML::update_sched_action(const SchedAction* action) { xmlrpc_c::value result; try { - string action_id_str = action->vector_value("ID"); + const string& action_id_str = action->vector_value("ID"); int action_id = std::stoi(action_id_str); ostringstream oss; diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index b3a5434fce..82f82a7631 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -71,14 +71,8 @@ int TransferManager::prolog_transfer_command( ostream& xfr, ostringstream& os) { - string source; string type; - string clon; - string size; - string format; - string tm_mad; string tm_mad_system; - string ds_id; int disk_id = disk->get_disk_id(); @@ -91,7 +85,7 @@ int TransferManager::prolog_transfer_command( // ----------------------------------------------------------------- // Generate a swap disk image // ----------------------------------------------------------------- - size = disk->vector_value("SIZE"); + const string& size = disk->vector_value("SIZE"); if ( size.empty() ) { @@ -115,8 +109,8 @@ int TransferManager::prolog_transfer_command( // ----------------------------------------------------------------- // Create a clean file system disk image // ----------------------------------------------------------------- - size = disk->vector_value("SIZE"); - format = disk->vector_value("FORMAT"); + const string& size = disk->vector_value("SIZE"); + const string& format = disk->vector_value("FORMAT"); if ( size.empty() || format.empty() ) { @@ -141,10 +135,10 @@ int TransferManager::prolog_transfer_command( // ----------------------------------------------------------------- // Get transfer attributes & check errors // ----------------------------------------------------------------- - tm_mad = disk->vector_value("TM_MAD"); - ds_id = disk->vector_value("DATASTORE_ID"); - source = disk->vector_value("SOURCE"); - clon = disk->vector_value("CLONE"); + const string& tm_mad = disk->vector_value("TM_MAD"); + const string& ds_id = disk->vector_value("DATASTORE_ID"); + const string& source = disk->vector_value("SOURCE"); + const string& clon = disk->vector_value("CLONE"); if ( source.empty() || tm_mad.empty() || @@ -213,7 +207,7 @@ static string prolog_os_transfer_commands( { string base_ds = base + "_DS"; - string name_ds = os_attr->vector_value(base_ds); + const string& name_ds = os_attr->vector_value(base_ds); if ( name_ds.empty() ) { @@ -224,9 +218,9 @@ static string prolog_os_transfer_commands( string base_ds_id = base + "_DS_DSID"; string base_tm = base + "_DS_TM"; - string source = os_attr->vector_value(base_source); - string ds_id = os_attr->vector_value(base_ds_id); - string tm_mad = os_attr->vector_value(base_tm); + const string& source = os_attr->vector_value(base_source); + const string& ds_id = os_attr->vector_value(base_ds_id); + const string& tm_mad = os_attr->vector_value(base_tm); if ( source.empty() || ds_id.empty() || tm_mad.empty() ) { @@ -236,7 +230,7 @@ static string prolog_os_transfer_commands( ostringstream base_dst; string name = base; - transform(name.begin(), name.end(), name.begin(), (int(*)(int))tolower); + one_util::tolower(name); base_dst << vm->get_system_dir() << "/" << name; @@ -943,9 +937,9 @@ void TransferManager::epilog_transfer_command( if ( one_util::toupper(save) == "YES" ) { - string source = disk->vector_value("SOURCE"); - string tm_mad = disk->vector_value("TM_MAD"); - string ds_id = disk->vector_value("DATASTORE_ID"); + const string& source = disk->vector_value("SOURCE"); + const string& tm_mad = disk->vector_value("TM_MAD"); + const string& ds_id = disk->vector_value("DATASTORE_ID"); if ( ds_id.empty() || tm_mad.empty() ) { @@ -959,7 +953,7 @@ void TransferManager::epilog_transfer_command( return; } - string tsys = disk->vector_value("TM_MAD_SYSTEM"); + const string& tsys = disk->vector_value("TM_MAD_SYSTEM"); if (!tsys.empty()) { tm_mad_system = "." + tsys; @@ -992,7 +986,7 @@ void TransferManager::epilog_transfer_command( vv_rc = disk->vector_value("DATASTORE_ID", ds_id_i); } - string tsys = disk->vector_value("TM_MAD_SYSTEM"); + const string& tsys = disk->vector_value("TM_MAD_SYSTEM"); if (!tsys.empty()) { tm_mad_system = "." + tsys; @@ -1220,7 +1214,7 @@ void TransferManager::trigger_epilog_stop(VirtualMachine * vm) } } - string tsys = disk->vector_value("TM_MAD_SYSTEM"); + const string& tsys = disk->vector_value("TM_MAD_SYSTEM"); if (!tsys.empty()) { tm_mad_system = "." + tsys; @@ -1350,7 +1344,7 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm, // ------------------------------------------------------------------------- // Delete disk images and the remote system Directory // ------------------------------------------------------------------------- - for (auto disk : disks) + for (const auto* disk : disks) { disk_id = disk->get_disk_id(); @@ -1370,7 +1364,7 @@ int TransferManager::epilog_delete_commands(VirtualMachine *vm, } } - string tsys = disk->vector_value("TM_MAD_SYSTEM"); + const string& tsys = disk->vector_value("TM_MAD_SYSTEM"); if (!tsys.empty()) { tm_mad_system = "." + tsys; @@ -1816,14 +1810,6 @@ void TransferManager::trigger_driver_cancel(int vid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void TransferManager::trigger_checkpoint(int vid) -{ - -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - void TransferManager::trigger_saveas_hot(int vid) { trigger([this, vid] { @@ -1833,7 +1819,6 @@ void TransferManager::trigger_saveas_hot(int vid) string snap_id; string tm_mad; string ds_id; - string tsys; string tm_mad_system; string hostname; @@ -1843,7 +1828,7 @@ void TransferManager::trigger_saveas_hot(int vid) string xfr_name; const Driver * tm_md; - VirtualMachineDisk * disk; + const VirtualMachineDisk * disk; Nebula& nd = Nebula::instance(); @@ -1886,7 +1871,7 @@ void TransferManager::trigger_saveas_hot(int vid) if (disk != nullptr) { - tsys = disk->vector_value("TM_MAD_SYSTEM"); + const string& tsys = disk->vector_value("TM_MAD_SYSTEM"); if (!tsys.empty()) { tm_mad_system = "." + tsys; @@ -1974,15 +1959,14 @@ void TransferManager::migrate_transfer_command( /* -------------------------------------------------------------------------- */ int TransferManager::snapshot_transfer_command( - VirtualMachine * vm, const char * snap_action, ostream& xfr) + const VirtualMachine * vm, const char * snap_action, ostream& xfr) { string tm_mad; - string tsys; string tm_mad_system; int ds_id; int disk_id; int snap_id; - VirtualMachineDisk * disk; + const VirtualMachineDisk * disk; if (vm->get_snapshot_disk(ds_id, tm_mad, disk_id, snap_id) == -1) { @@ -1995,7 +1979,7 @@ int TransferManager::snapshot_transfer_command( if (disk != nullptr) { - tsys = disk->vector_value("TM_MAD_SYSTEM"); + const string& tsys = disk->vector_value("TM_MAD_SYSTEM"); if (!tsys.empty()) { tm_mad_system = "." + tsys; @@ -2146,7 +2130,7 @@ void TransferManager::resize_command(VirtualMachine * vm, ds_id = disk->vector_value("DATASTORE_ID"); } - string tsys = disk->vector_value("TM_MAD_SYSTEM"); + const string& tsys = disk->vector_value("TM_MAD_SYSTEM"); if (!tsys.empty()) { tm_mad_system = "." + tsys; diff --git a/src/um/Quota.cc b/src/um/Quota.cc index 005aafb557..1c4ed5093d 100644 --- a/src/um/Quota.cc +++ b/src/um/Quota.cc @@ -363,14 +363,13 @@ int Quota::update_limits( VectorAttribute * quota, const VectorAttribute * va) { - string limit; float limit_f; for (int i=0; i < num_metrics; i++) { - limit = va->vector_value_str(metrics[i], limit_f); + const string& limit = va->vector_value_str(metrics[i], limit_f); - if (limit == "") + if (limit.empty()) { if ( is_default ) { @@ -401,11 +400,10 @@ int Quota::update_limits( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -VectorAttribute * Quota::new_quota(VectorAttribute * va) +VectorAttribute * Quota::new_quota(const VectorAttribute * va) { map limits; - string limit; float limit_f; for (int i=0; i < num_metrics; i++) @@ -414,9 +412,9 @@ VectorAttribute * Quota::new_quota(VectorAttribute * va) metrics_used += "_USED"; - limit = va->vector_value_str(metrics[i], limit_f); + const string& limit = va->vector_value_str(metrics[i], limit_f); - if (limit == "") + if (limit.empty()) { if ( is_default ) { @@ -441,7 +439,7 @@ VectorAttribute * Quota::new_quota(VectorAttribute * va) limits.insert(make_pair(metrics_used, "0")); } - string id = va->vector_value("ID"); + const string& id = va->vector_value("ID"); if ( !id.empty() ) { diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 2528aefa54..66476e89dc 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -2721,9 +2721,9 @@ void VirtualMachine::get_public_clouds(const string& pname, set &clouds) clouds.insert("ec2"); } - for (auto vattr : attrs) + for (const auto* vattr : attrs) { - string type = vattr->vector_value("TYPE"); + const string& type = vattr->vector_value("TYPE"); if (!type.empty()) { diff --git a/src/vm/VirtualMachineContext.cc b/src/vm/VirtualMachineContext.cc index 3c277e689e..ee6e556c4d 100644 --- a/src/vm/VirtualMachineContext.cc +++ b/src/vm/VirtualMachineContext.cc @@ -417,9 +417,9 @@ int VirtualMachine::generate_network_context(VectorAttribute* context, /* -------------------------------------------------------------------------- */ static void parse_pci_context_network(const std::vector& cvars, - VectorAttribute * context, VectorAttribute * nic) + VectorAttribute * context, const VectorAttribute * nic) { - string pci_id = nic->vector_value("PCI_ID"); + const string& pci_id = nic->vector_value("PCI_ID"); for (const auto& con : cvars) { diff --git a/src/vm/VirtualMachineDisk.cc b/src/vm/VirtualMachineDisk.cc index 9b839e256a..143dfc0a63 100644 --- a/src/vm/VirtualMachineDisk.cc +++ b/src/vm/VirtualMachineDisk.cc @@ -174,14 +174,7 @@ int VirtualMachineDisk::get_image_id(int &id, int uid) const string VirtualMachineDisk::get_tm_mad_system() const { - std::string tm_mad_system; - - if (vector_value("TM_MAD_SYSTEM", tm_mad_system) != 0) - { - return ""; - } - - return tm_mad_system; + return vector_value("TM_MAD_SYSTEM"); } /* -------------------------------------------------------------------------- */ @@ -1085,7 +1078,8 @@ int VirtualMachineDisks::set_attach(int id) /* -------------------------------------------------------------------------- */ VirtualMachineDisk * VirtualMachineDisks::set_up_attach(int vmid, int uid, - int cluster_id, VectorAttribute * vdisk, const std::string& tsys, VectorAttribute * vcontext, + int cluster_id, VectorAttribute * vdisk, const std::string& tsys, + const VectorAttribute * vcontext, string& error) { set used_targets; @@ -1113,7 +1107,7 @@ VirtualMachineDisk * VirtualMachineDisks::set_up_attach(int vmid, int uid, if ( vcontext != 0 ) { - string target = vcontext->vector_value("TARGET"); + const string& target = vcontext->vector_value("TARGET"); if ( !target.empty() ) { diff --git a/src/vm/VirtualMachineNic.cc b/src/vm/VirtualMachineNic.cc index 8de7a7b55d..81c7b7aca1 100644 --- a/src/vm/VirtualMachineNic.cc +++ b/src/vm/VirtualMachineNic.cc @@ -154,9 +154,7 @@ void VirtualMachineNic::authorize(PoolObjectSQL::ObjectType ot, int uid, set sgroups; - string net_mode = ""; - - net_mode = this->vector_value("NETWORK_MODE"); + string net_mode = this->vector_value("NETWORK_MODE"); if ( one_util::icasecmp(net_mode, "AUTO") ) { @@ -195,17 +193,17 @@ void VirtualMachineNic::authorize(PoolObjectSQL::ObjectType ot, int uid, void VirtualMachineNic::to_xml_short(std::ostringstream& oss) const { - std::string ip = vector_value("IP"); - std::string ip6 = vector_value("IP6"); - std::string ip6_ula = vector_value("IP6_ULA"); + const string& ip = vector_value("IP"); + const string& ip6 = vector_value("IP6"); + const string& ip6_ula = vector_value("IP6_ULA"); - std::string ip6_link = vector_value("IP6_LINK"); - std::string ip6_global = vector_value("IP6_GLOBAL"); - std::string ip_external = vector_value("EXTERNAL_IP"); /* PROVISION AWS_IPAM */ + const string& ip6_link = vector_value("IP6_LINK"); + const string& ip6_global = vector_value("IP6_GLOBAL"); + const string& ip_external = vector_value("EXTERNAL_IP"); /* PROVISION AWS_IPAM */ - std::string reqs = vector_value("SCHED_REQUIREMENTS"); - std::string rank = vector_value("SCHED_RANK"); - std::string mode = vector_value("NETWORK_MODE"); + const string& reqs = vector_value("SCHED_REQUIREMENTS"); + const string& rank = vector_value("SCHED_RANK"); + const string& mode = vector_value("NETWORK_MODE"); oss << ""; diff --git a/src/vm/VirtualMachineTemplate.cc b/src/vm/VirtualMachineTemplate.cc index 449a137a45..75ed7aae55 100644 --- a/src/vm/VirtualMachineTemplate.cc +++ b/src/vm/VirtualMachineTemplate.cc @@ -263,7 +263,7 @@ static void copy_vector_values(const Template *old_tmpl, Template *new_tmpl, for (const auto& vname : vnames) { - std::string vval = old_attr->vector_value(vname); + const string& vval = old_attr->vector_value(vname); if (!vval.empty()) { diff --git a/src/vm_group/VMGroupPool.cc b/src/vm_group/VMGroupPool.cc index d5e772265a..241bb604ba 100644 --- a/src/vm_group/VMGroupPool.cc +++ b/src/vm_group/VMGroupPool.cc @@ -69,7 +69,7 @@ std::unique_ptr VMGroupPool::get_from_attribute( { std::unique_ptr vmgroup; - string vmg_name = va->vector_value("VMGROUP_NAME"); + const string& vmg_name = va->vector_value("VMGROUP_NAME"); int vmg_id; if ( !vmg_name.empty() ) @@ -140,7 +140,7 @@ void VMGroupPool::del_vm(const VectorAttribute * va, int vid) return; } - string vmg_role = va->vector_value("ROLE"); + const string& vmg_role = va->vector_value("ROLE"); if ( vmg_role.empty() ) { diff --git a/src/vmm/LibVirtDriverKVM.cc b/src/vmm/LibVirtDriverKVM.cc index b3e73e4320..34d784066d 100644 --- a/src/vmm/LibVirtDriverKVM.cc +++ b/src/vmm/LibVirtDriverKVM.cc @@ -189,7 +189,7 @@ static void pin_cpu(ofstream& file, const VectorAttribute * topology, unsigned int nv = 0; std::vector cpus_a; - std::string cpus = (*it)->vector_value("CPUS"); + const string& cpus = (*it)->vector_value("CPUS"); (*it)->vector_value("TOTAL_CPUS", nv); @@ -281,8 +281,8 @@ static void vtopol(ofstream& file, const VectorAttribute * topology, { unsigned int ncpu = 0; - std::string mem = (*it)->vector_value("MEMORY"); - std::string mem_id = (*it)->vector_value("MEMORY_NODE_ID"); + const string& mem = (*it)->vector_value("MEMORY"); + const string& mem_id = (*it)->vector_value("MEMORY_NODE_ID"); (*it)->vector_value("TOTAL_CPUS", ncpu); @@ -671,7 +671,7 @@ int LibVirtDriver::deployment_description_kvm( auto os = vm->get_template_attribute("OS"); if (os) { - auto uuid = os->vector_value("UUID"); + const string& uuid = os->vector_value("UUID"); if (!uuid.empty()) { file << "\t" << uuid << "" << endl; diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 0c08c10e75..fd8adee8c4 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -2430,7 +2430,7 @@ int VirtualMachineManager::load_drivers(const vector& _m ostringstream oss; VirtualMachineManagerDriver * vmm_driver = nullptr; - string name = vattr->vector_value("NAME"); + const string& name = vattr->vector_value("NAME"); string type = vattr->vector_value("TYPE"); one_util::toupper(type); diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 6b91a1d958..24d2d3b42a 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -1116,9 +1116,9 @@ int VirtualNetwork::hold_leases(VirtualNetworkTemplate * leases_template, unsigned int ar_id; - string ip = lease->vector_value("IP"); - string ip6 = lease->vector_value("IP6"); - string mac = lease->vector_value("MAC"); + const string& ip = lease->vector_value("IP"); + const string& ip6 = lease->vector_value("IP6"); + const string& mac = lease->vector_value("MAC"); int ip_ne = ip.empty() ? 0 : 1; int ip6_ne = ip6.empty() ? 0 : 1; @@ -1192,9 +1192,9 @@ int VirtualNetwork::free_leases(VirtualNetworkTemplate * leases_template, unsigned int ar_id; - string ip = lease->vector_value("IP"); - string ip6 = lease->vector_value("IP6"); - string mac = lease->vector_value("MAC"); + const string& ip = lease->vector_value("IP"); + const string& ip6 = lease->vector_value("IP6"); + const string& mac = lease->vector_value("MAC"); int ip_ne = ip.empty() ? 0 : 1; int ip6_ne = ip6.empty() ? 0 : 1; diff --git a/src/vrouter/VirtualRouter.cc b/src/vrouter/VirtualRouter.cc index a41467908b..6be7edd1b9 100644 --- a/src/vrouter/VirtualRouter.cc +++ b/src/vrouter/VirtualRouter.cc @@ -417,7 +417,6 @@ int VirtualRouter::release_network_leases(const VectorAttribute * nic) int vnid; int ar_id; - string mac; if (nic == nullptr) { @@ -429,7 +428,7 @@ int VirtualRouter::release_network_leases(const VectorAttribute * nic) return -1; } - mac = nic->vector_value("VROUTER_MAC"); + const string& mac = nic->vector_value("VROUTER_MAC"); auto vn = vnpool->get(vnid);