diff --git a/include/AclManager.h b/include/AclManager.h index c5c0ede2a1..eb665666e9 100644 --- a/include/AclManager.h +++ b/include/AclManager.h @@ -106,11 +106,11 @@ public: * -2 if the rule is malformed, * -3 if the DB insert failed */ - virtual int add_rule(long long user, - long long resource, - long long rights, - long long zone, - std::string& error_str); + int add_rule(long long user, + long long resource, + long long rights, + long long zone, + std::string& error_str); /** * Deletes a rule from the ACL rule set * @@ -118,7 +118,7 @@ public: * @param error_str Returns the error reason, if any * @return 0 on success */ - virtual int del_rule(int oid, std::string& error_str); + int del_rule(int oid, std::string& error_str); /** * Deletes a new rule from the ACL rule set @@ -131,11 +131,11 @@ public: * @param error_str Returns the error reason, if any * @return 0 on success */ - virtual int del_rule(long long user, - long long resource, - long long rights, - long long zone, - std::string& error_str); + int del_rule(long long user, + long long resource, + long long rights, + long long zone, + std::string& error_str); /** * Deletes rules that apply to this user id @@ -212,7 +212,7 @@ public: * @param oss The output stream to dump the rule set contents * @return 0 on success */ - virtual int dump(std::ostringstream& oss); + int dump(std::ostringstream& oss); protected: /** diff --git a/include/AddressRange.h b/include/AddressRange.h index cc1340e970..93ca8d89ce 100644 --- a/include/AddressRange.h +++ b/include/AddressRange.h @@ -769,7 +769,7 @@ private: /** * The type of addresses defined in the range */ - AddressType type; + AddressType type = NONE; /** * ID for this range, unique within the Virtual Network @@ -779,12 +779,12 @@ private: /** * Number of addresses in the range */ - unsigned long int size; + unsigned long int size = 0; /** * First IP4 in the range */ - unsigned int ip; + unsigned int ip = 0; /** * First MAC in the range @@ -825,7 +825,7 @@ private: * The Address Range attributes as a Template VectorAttribute. This is * used to generate XML or a template representation of the AR. */ - VectorAttribute * attr; + VectorAttribute * attr = nullptr; /* ---------------------------------------------------------------------- */ /* Restricted Attributes */ diff --git a/include/AuthManager.h b/include/AuthManager.h index 5e2613f05b..86b8b3311d 100644 --- a/include/AuthManager.h +++ b/include/AuthManager.h @@ -36,10 +36,11 @@ public: AuthManager( time_t timer, - const std::string& mads_location): - DriverManager(mads_location), - Listener("Authorization Manager"), - timer_thread(timer, [this](){timer_action();}) + const std::string& mads_location) + : DriverManager(mads_location) + , Listener("Authorization Manager") + , timer_thread(timer, [this](){timer_action();}) + , authz_enabled(false) { } diff --git a/include/Datastore.h b/include/Datastore.h index 1f8d689c62..37a56782ad 100644 --- a/include/Datastore.h +++ b/include/Datastore.h @@ -424,13 +424,13 @@ private: * related to the DS defined in DS_MAD_CONF specified in the Datastore * template */ - int set_ds_mad(std::string &ds_mad, std::string &error_str); + int set_ds_mad(const std::string &ds_mad, std::string &error_str); /** * Verify the proper definition of the TM_MAD by checking the attributes * related to the TM defined in TM_MAD_CONF */ - int set_tm_mad(std::string &tm_mad, std::string &error_str); + int set_tm_mad(const std::string &tm_mad, std::string &error_str); /** * Child classes can process the new template set with replace_template or diff --git a/include/Driver.h b/include/Driver.h index 84c8b99459..d14960fda7 100644 --- a/include/Driver.h +++ b/include/Driver.h @@ -49,7 +49,6 @@ public: : cmd(c) , arg(a) , concurrency(ct) - , pid(-1) {} ~Driver() @@ -129,12 +128,12 @@ private: /** * Communication pipe file descriptor (daemon <- driver) */ - int from_drv; + int from_drv = -1; /** * Communication pipe file descriptor (daemon -> driver) */ - int to_drv; + int to_drv = -1; /** * Driver configuration: path and arguments @@ -143,12 +142,12 @@ private: std::string arg; - int concurrency; + int concurrency = 0; /** * Process ID of the driver */ - pid_t pid; + pid_t pid = -1; /** * Class to read lines from the stream diff --git a/include/HostShareNUMA.h b/include/HostShareNUMA.h index 8e650a4c6a..db6dcc3f9a 100644 --- a/include/HostShareNUMA.h +++ b/include/HostShareNUMA.h @@ -50,14 +50,19 @@ class HostShareNode : public Template { public: - HostShareNode() : Template(false, '=', "NODE"){}; + HostShareNode() + : Template(false, '=', "NODE") + , node_id(std::numeric_limits::max()) + {} - HostShareNode(unsigned int i) : Template(false, '=', "NODE"), node_id(i) + HostShareNode(unsigned int i) + : Template(false, '=', "NODE") + , node_id(i) { replace("NODE_ID", i); - }; + } - virtual ~HostShareNode(){}; + virtual ~HostShareNode() = default; /** * Builds the node from its XML representation. This function is used when diff --git a/include/HostSharePCI.h b/include/HostSharePCI.h index ddbd572cfc..35c5a6c1b9 100644 --- a/include/HostSharePCI.h +++ b/include/HostSharePCI.h @@ -53,7 +53,7 @@ public: virtual ~HostSharePCI() { - clear(); + HostSharePCI::clear(); }; /** diff --git a/include/IPAMRequest.h b/include/IPAMRequest.h index 32bf29b481..a9ac1a60d6 100644 --- a/include/IPAMRequest.h +++ b/include/IPAMRequest.h @@ -127,6 +127,8 @@ public: if ( new_ar == 0 ) { error = "AR not found in IPAM driver response"; + + return -1; } vattr->replace(new_ar->value()); @@ -148,6 +150,8 @@ public: if ( addr == 0 ) { error = "ADDRESS not found in IPAM driver response"; + + return -1; } ip = addr->vector_value("IP"); diff --git a/include/Nebula.h b/include/Nebula.h index 1181085935..bc55cd1477 100644 --- a/include/Nebula.h +++ b/include/Nebula.h @@ -597,30 +597,36 @@ public: //Constructors and = are private to only access the class through instance // ----------------------------------------------------------------------- - Nebula():nebula_configuration(0), - default_user_quota( "DEFAULT_USER_QUOTAS", - "/DEFAULT_USER_QUOTAS/DATASTORE_QUOTA", - "/DEFAULT_USER_QUOTAS/NETWORK_QUOTA", - "/DEFAULT_USER_QUOTAS/IMAGE_QUOTA", - "/DEFAULT_USER_QUOTAS/VM_QUOTA"), - default_group_quota("DEFAULT_GROUP_QUOTAS", - "/DEFAULT_GROUP_QUOTAS/DATASTORE_QUOTA", - "/DEFAULT_GROUP_QUOTAS/NETWORK_QUOTA", - "/DEFAULT_GROUP_QUOTAS/IMAGE_QUOTA", - "/DEFAULT_GROUP_QUOTAS/VM_QUOTA"), - system_db(0), db_backend_type("sqlite"), logdb(0), fed_logdb(0), - vmpool(0), hpool(0), vnpool(0), upool(0), ipool(0), gpool(0), tpool(0), - dspool(0), clpool(0), docpool(0), zonepool(0), secgrouppool(0), - vdcpool(0), vrouterpool(0), marketpool(0), apppool(0), vmgrouppool(0), - vntpool(0), hkpool(0), lcm(0), vmm(0), im(0), tm(0), dm(0), rm(0), hm(0), - hl(0), authm(0), aclm(0), imagem(0), marketm(0), ipamm(0), raftm(0), frm(0) + Nebula() + : nebula_configuration(0) + , federation_enabled(false) + , federation_master(false) + , cache(false) + , zone_id(0) + , server_id(-1) + , default_user_quota( "DEFAULT_USER_QUOTAS", + "/DEFAULT_USER_QUOTAS/DATASTORE_QUOTA", + "/DEFAULT_USER_QUOTAS/NETWORK_QUOTA", + "/DEFAULT_USER_QUOTAS/IMAGE_QUOTA", + "/DEFAULT_USER_QUOTAS/VM_QUOTA") + , default_group_quota("DEFAULT_GROUP_QUOTAS", + "/DEFAULT_GROUP_QUOTAS/DATASTORE_QUOTA", + "/DEFAULT_GROUP_QUOTAS/NETWORK_QUOTA", + "/DEFAULT_GROUP_QUOTAS/IMAGE_QUOTA", + "/DEFAULT_GROUP_QUOTAS/VM_QUOTA") + , system_db(0), db_backend_type("sqlite"), logdb(0), fed_logdb(0) + , vmpool(0), hpool(0), vnpool(0), upool(0), ipool(0), gpool(0), tpool(0) + , dspool(0), clpool(0), docpool(0), zonepool(0), secgrouppool(0) + , vdcpool(0), vrouterpool(0), marketpool(0), apppool(0), vmgrouppool(0) + , vntpool(0), hkpool(0), lcm(0), vmm(0), im(0), tm(0), dm(0), rm(0), hm(0) + , hl(0), authm(0), aclm(0), imagem(0), marketm(0), ipamm(0), raftm(0), frm(0) { }; ~Nebula(); private: - Nebula& operator=(Nebula const&){return *this;}; + Nebula& operator=(Nebula const&) = delete; // --------------------------------------------------------------- // Environment variables diff --git a/include/ObjectXML.h b/include/ObjectXML.h index 02e202cc52..3272800847 100644 --- a/include/ObjectXML.h +++ b/include/ObjectXML.h @@ -37,7 +37,12 @@ public: // ---------------------- Constructors ------------------------------------ - ObjectXML():xml(0), ctx(0) {} + ObjectXML() + : paths(nullptr) + , num_paths(0) + , xml(nullptr) + , ctx(nullptr) + {} /** * Constructs an object using a XML document diff --git a/include/PoolObjectAuth.h b/include/PoolObjectAuth.h index e8e5648e33..5947631a17 100644 --- a/include/PoolObjectAuth.h +++ b/include/PoolObjectAuth.h @@ -30,23 +30,25 @@ class PoolObjectAuth public: /* ------------------- Constructor and Methods -------------------------- */ - PoolObjectAuth(): - oid(-1), - uid(-1), - gid(-1), - owner_u(1), - owner_m(1), - owner_a(0), - group_u(0), - group_m(0), - group_a(0), - other_u(0), - other_m(0), - other_a(0), - disable_all_acl(false), - disable_cluster_acl(false), - disable_group_acl(false), - locked(0) {}; + PoolObjectAuth() + : obj_type(PoolObjectSQL::NONE) + , oid(-1) + , uid(-1) + , gid(-1) + , owner_u(1) + , owner_m(1) + , owner_a(0) + , group_u(0) + , group_m(0) + , group_a(0) + , other_u(0) + , other_m(0) + , other_a(0) + , disable_all_acl(false) + , disable_cluster_acl(false) + , disable_group_acl(false) + , locked(0) + {} void get_acl_rules(AclRule& owner_rule, AclRule& group_rule, diff --git a/include/Request.h b/include/Request.h index c9827e7463..afcc60690b 100644 --- a/include/Request.h +++ b/include/Request.h @@ -63,10 +63,16 @@ public: bool success; /**< True if the call was successfull false otherwise */ RequestAttributes(AuthRequest::Operation api_auth_op) - : resp_obj(PoolObjectSQL::NONE) + : uid(-1) + , gid(-1) + , req_id(-1) + , umask(0) + , retval(nullptr) + , resp_obj(PoolObjectSQL::NONE) , resp_id(-1) , replication_idx(UINT64_MAX) , auth_op(api_auth_op) + , success(false) {} RequestAttributes(const RequestAttributes& ra) = default; @@ -89,6 +95,7 @@ public: , resp_msg() , replication_idx(UINT64_MAX) , auth_op(ra.auth_op) + , success(ra.success) {} bool is_admin() const @@ -257,7 +264,7 @@ protected: // Configuration for authentication level of the API call PoolObjectSQL::ObjectType auth_object = PoolObjectSQL::ObjectType::NONE; - AuthRequest::Operation auth_op; + AuthRequest::Operation auth_op = AuthRequest::NONE; VMActions::Action vm_action; diff --git a/include/StreamManager.h b/include/StreamManager.h index fa476abc7d..3b7d82afb0 100644 --- a/include/StreamManager.h +++ b/include/StreamManager.h @@ -113,7 +113,7 @@ private: std::condition_variable _cond; - int _concurrency; + int _concurrency = 0; std::map actions; diff --git a/include/ZoneServer.h b/include/ZoneServer.h index 2dd5ba157b..f5b64a83f3 100644 --- a/include/ZoneServer.h +++ b/include/ZoneServer.h @@ -81,7 +81,9 @@ public: * attributes * @param tmpl template with SERVER */ - ZoneServers(Template * tmpl):ExtendedAttributeSet(false), next_id(-1) + ZoneServers(Template * tmpl) + : ExtendedAttributeSet(false) + , next_id(-1) { std::vector vas; @@ -109,9 +111,12 @@ public: /** * Creates an empty zone server set */ - ZoneServers():ExtendedAttributeSet(false){}; + ZoneServers() + : ExtendedAttributeSet(false) + , next_id(-1) + {} - virtual ~ZoneServers(){}; + virtual ~ZoneServers() = default; /* ---------------------------------------------------------------------- */ /* Iterators */ diff --git a/share/smoke_tests/config/cppcheck-suppressions.xml b/share/smoke_tests/config/cppcheck-suppressions.xml index 82837cd7b4..762b50d549 100644 --- a/share/smoke_tests/config/cppcheck-suppressions.xml +++ b/share/smoke_tests/config/cppcheck-suppressions.xml @@ -1,9 +1,60 @@ - variableScope * + + noExplicitConstructor + * + + + missingInclude + * + + + danglingLifetime + * + + + shadowFunction + * + + + + containerOutOfBounds + src/hm/HookLog.cc + query_output + + + ctuuninitvar + src/sql/LogDB.cc + + + knownConditionTrueFalse + src/raft/ReplicaThread.cc + + + knownConditionTrueFalse + src/vmm/LibVirtDriverKVM.cc + + + knownConditionTrueFalse + src/sql/LogDB.cc + + + knownConditionTrueFalse + src/monitor/src/data_model/VMRPCPool.cc + + + nullPointer + src/scheduler/include/Scheduler.h + + + uninitMemberVar + include/Callbackable.h + + unusedVariable * @@ -12,10 +63,6 @@ noConstructor * - - noExplicitConstructor - * - constVariable * @@ -32,23 +79,13 @@ unreadVariable * ---> - missingInclude + constParameter * - danglingLifetime + useStlAlgorithm * - - containerOutOfBounds - src/hm/HookLog.cc - query_output - - - ctuuninitvar - src/sql/LogDB.cc - diff --git a/share/smoke_tests/tests/04-cppcheck.sh b/share/smoke_tests/tests/04-cppcheck.sh index de83d6f66c..403b6e4ce1 100755 --- a/share/smoke_tests/tests/04-cppcheck.sh +++ b/share/smoke_tests/tests/04-cppcheck.sh @@ -14,10 +14,10 @@ # To disable specific error messages use cppcheck-suppressions.xml file SOURCES="src" -INCLUDES="-I include" +INCLUDES="-I include -I src/monitor/include -I src/scheduler/include" DEFINES="-DSQLITE_DB -DMYSQL_DB -DPOSTGRESQL_DB -DSYSTEMD" -ENABLE="--enable=performance,information" -IGNORE="-i .xmlrpc_test/ -i src/sunstone/ -i src/svncterm_server/ -i src/fireedge" +ENABLE="--enable=performance,information,warning,portability,style" +IGNORE="-i .xmlrpc_test/ -i src/sunstone/ -i src/svncterm_server/ -i src/fireedge -i src/parsers" SUPRESS="--suppress-xml=share/smoke_tests/config/cppcheck-suppressions.xml" OTHERS="--std=c++14 --error-exitcode=2 -q" diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 2feb833d0e..b1a3b29cbd 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -316,7 +316,7 @@ static int check_tm_target_type(string& tm_tt) /* -------------------------------------------------------------------------- */ -int Datastore::set_ds_mad(std::string &mad, std::string &error_str) +int Datastore::set_ds_mad(const std::string &mad, std::string &error_str) { const VectorAttribute* vatt; std::vector vrequired_attrs; @@ -375,7 +375,7 @@ error_common: /* -------------------------------------------------------------------------- */ -int Datastore::set_tm_mad(string &tm_mad, string &error_str) +int Datastore::set_tm_mad(const string &tm_mad, string &error_str) { const VectorAttribute* vatt; @@ -447,35 +447,35 @@ int Datastore::set_tm_mad(string &tm_mad, string &error_str) for (const auto &mode : modes) { - string tm_mad = one_util::trim(mode); - one_util::toupper(tm_mad); + string tm = one_util::trim(mode); + one_util::toupper(tm); - st = vatt->vector_value("LN_TARGET_" + tm_mad); + st = vatt->vector_value("LN_TARGET_" + tm); if (check_tm_target_type(st) == -1) { goto error; } - replace_template_attribute("LN_TARGET_" + tm_mad, st); + replace_template_attribute("LN_TARGET_" + tm, st); - st = vatt->vector_value("CLONE_TARGET_" + tm_mad); + st = vatt->vector_value("CLONE_TARGET_" + tm); if (check_tm_target_type(st) == -1) { goto error; } - replace_template_attribute("CLONE_TARGET_" + tm_mad, st); + replace_template_attribute("CLONE_TARGET_" + tm, st); - st = vatt->vector_value("DISK_TYPE_" + tm_mad); + st = vatt->vector_value("DISK_TYPE_" + tm); if (st.empty()) { goto error; } - replace_template_attribute("DISK_TYPE_" + tm_mad, st); + replace_template_attribute("DISK_TYPE_" + tm, st); } } diff --git a/src/hm/ExecuteHook.cc b/src/hm/ExecuteHook.cc index c217908dc7..072a1808dd 100644 --- a/src/hm/ExecuteHook.cc +++ b/src/hm/ExecuteHook.cc @@ -50,7 +50,7 @@ ExecuteHook::ExecuteHook(const std::string& _name, const std::string& _cmd, c_args[i] = nullptr; } - for (int i=1; iss >> args[i] && i < EXECUTE_HOOK_MAX_ARG - 1; ++i) + for (int i=1; i < EXECUTE_HOOK_MAX_ARG && iss >> args[i]; ++i) { c_args[i] = args[i].c_str(); } diff --git a/src/host/Host.cc b/src/host/Host.cc index cec87f29c0..78035d4fbd 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -578,7 +578,7 @@ int Host::post_update_template(string& error) im_mad_name = new_im_mad; } - if (!new_im_mad.empty()) + if (!new_vm_mad.empty()) { vmm_mad_name = new_vm_mad; } diff --git a/src/host/HostShare.cc b/src/host/HostShare.cc index 8a857f9ab0..79bc31f03f 100644 --- a/src/host/HostShare.cc +++ b/src/host/HostShare.cc @@ -246,7 +246,7 @@ void HostShare::update_capacity(Template& ht, string& rcpu, string& rmem) if ( ht.get("VMS_THREAD", vthread) ) { - if ( vthread <= 0 ) + if ( vthread == 0 ) { vthread = 1; diff --git a/src/monitor/src/data_model/VirtualMachineBase.cc b/src/monitor/src/data_model/VirtualMachineBase.cc index c684457798..10f976a914 100644 --- a/src/monitor/src/data_model/VirtualMachineBase.cc +++ b/src/monitor/src/data_model/VirtualMachineBase.cc @@ -104,7 +104,7 @@ int VirtualMachineBase::init_attributes() } else { - vm_template = 0; + vm_template = nullptr; } nodes.clear(); @@ -116,21 +116,21 @@ int VirtualMachineBase::init_attributes() user_template->from_xml_node(nodes[0]); free_nodes(nodes); + + public_cloud = (user_template->get("PUBLIC_CLOUD", attrs) > 0); + + if (public_cloud == false) + { + attrs.clear(); + public_cloud = (user_template->get("EC2", attrs) > 0); + } } else { - user_template = 0; + user_template = nullptr; } - public_cloud = (user_template->get("PUBLIC_CLOUD", attrs) > 0); - - if (public_cloud == false) - { - attrs.clear(); - public_cloud = (user_template->get("EC2", attrs) > 0); - } - - if (vm_template != 0) + if (vm_template != nullptr) { init_storage_usage(); } @@ -200,10 +200,7 @@ void VirtualMachineBase::init_storage_usage() continue; } - if (ds_usage.count(ds_id) == 0) - { - ds_usage[ds_id] = 0; - } + ds_usage.emplace(ds_id, 0); // no-op if element already exists if (disk->vector_value("CLONE", clone) != 0) { diff --git a/src/monitor/src/monitor/HostMonitorManager.cc b/src/monitor/src/monitor/HostMonitorManager.cc index 62f980d274..a28d2b8462 100644 --- a/src/monitor/src/monitor/HostMonitorManager.cc +++ b/src/monitor/src/monitor/HostMonitorManager.cc @@ -45,7 +45,10 @@ HostMonitorManager::HostMonitorManager( const std::string& driver_path, int timer_period, int monitor_interval_host) - : hpool(hp) + : driver_manager(make_unique(driver_path)) + , udp_driver(make_unique(addr, port)) + , tcp_driver(make_unique(addr, port)) + , hpool(hp) , vmpool(vmp) , threads(_threads) , timer_period(timer_period) @@ -53,10 +56,7 @@ HostMonitorManager::HostMonitorManager( , is_leader(false) { oned_driver = make_unique(this); - udp_driver = make_unique(addr, port); - tcp_driver = make_unique(addr, port); - driver_manager = make_unique(driver_path); -}; +} /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 3c2f5791bb..970309966f 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -284,18 +284,15 @@ void Nebula::start(bool bootstrap_only) // ----------------------------------------------------------- const VectorAttribute * vatt = nebula_configuration->get("FEDERATION"); - federation_enabled = false; - federation_master = false; - cache = false; - zone_id = 0; - server_id = -1; - master_oned = vatt->vector_value("MASTER_ONED"); - string mode = vatt->vector_value("MODE"); - - one_util::toupper(mode); + string mode = "STANDALONE"; if (vatt != 0) { + master_oned = vatt->vector_value("MASTER_ONED"); + mode = vatt->vector_value("MODE"); + + one_util::toupper(mode); + if (mode == "STANDALONE") { federation_enabled = false; diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index ad1ca0fb2f..444afbb916 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -175,7 +175,6 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params, int rc, id; - int cluster_id = ClusterPool::NONE_CLUSTER_ID; string cluster_name = ClusterPool::NONE_CLUSTER_NAME; PoolObjectAuth cluster_perms; @@ -195,7 +194,7 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params, } } - cluster_id = get_cluster_id(params); + int cluster_id = get_cluster_id(params); if ( cluster_id != ClusterPool::NONE_CLUSTER_ID ) { diff --git a/src/rm/RequestManagerDelete.cc b/src/rm/RequestManagerDelete.cc index 21c2595d22..bb3476aaf8 100644 --- a/src/rm/RequestManagerDelete.cc +++ b/src/rm/RequestManagerDelete.cc @@ -872,11 +872,12 @@ int MarketPlaceDelete::drop(std::unique_ptr object, bool r, Reque { unique_ptr mp(static_cast(object.release())); - bool can_del = mp->is_public() || apps.empty(); apps = mp->get_marketapp_ids(); mp_id = mp->get_oid(); + bool can_del = mp->is_public() || apps.empty(); + if (!can_del) { std::ostringstream oss; diff --git a/src/rm/RequestManagerGroup.cc b/src/rm/RequestManagerGroup.cc index 582e3a31a8..71a70e7e8a 100644 --- a/src/rm/RequestManagerGroup.cc +++ b/src/rm/RequestManagerGroup.cc @@ -57,7 +57,7 @@ void GroupSetQuota:: return; } - group->quota.set("a_tmpl, att.resp_msg); + rc = group->quota.set("a_tmpl, att.resp_msg); static_cast(pool)->update_quotas(group.get()); diff --git a/src/scheduler/include/AclXML.h b/src/scheduler/include/AclXML.h index d7ab79c029..555e9ad849 100644 --- a/src/scheduler/include/AclXML.h +++ b/src/scheduler/include/AclXML.h @@ -39,30 +39,18 @@ public: private: /* ---------------------------------------------------------------------- */ - /* Re-implement DB public functions not used in scheduler */ + /* Disable public methods not used in scheduler */ /* ---------------------------------------------------------------------- */ - int start() - { - return -1; - } + int start() = delete; int add_rule(long long user, long long resource, long long rights, - std::string& error_str) - { - return -1; - }; + std::string& error_str) = delete; - int del_rule(int oid, std::string& error_str) - { - return -1; - }; + int del_rule(int oid, std::string& error_str) = delete; - int dump(std::ostringstream& oss) - { - return -1; - }; + int dump(std::ostringstream& oss) = delete; Client * client; diff --git a/src/scheduler/include/HostXML.h b/src/scheduler/include/HostXML.h index 9a04763433..4aaa268547 100644 --- a/src/scheduler/include/HostXML.h +++ b/src/scheduler/include/HostXML.h @@ -84,10 +84,7 @@ public: */ bool test_ds_capacity(int dsid, long long vm_disk_mb) { - if (ds_free_disk.count(dsid) == 0) - { - ds_free_disk[dsid] = free_disk; - } + ds_free_disk.emplace(dsid, free_disk); return (vm_disk_mb < ds_free_disk[dsid]); } @@ -100,10 +97,7 @@ public: */ void add_ds_capacity(int dsid, long long vm_disk_mb) { - if (ds_free_disk.count(dsid) == 0) - { - ds_free_disk[dsid] = free_disk; - } + ds_free_disk.emplace(dsid, free_disk); ds_free_disk[dsid] -= vm_disk_mb; } @@ -117,19 +111,19 @@ private: friend class HostXML; // Host computing capacity and usage - long long mem_usage; - long long cpu_usage; + long long mem_usage = 0; + long long cpu_usage = 0; - long long max_mem; - long long max_cpu; + long long max_mem = 0; + long long max_cpu = 0; - long long running_vms; + long long running_vms = 0; // PCI devices HostSharePCI pci; // System datastore - long long free_disk; + long long free_disk = 0; std::map ds_free_disk; //Numa Nodes diff --git a/src/scheduler/include/PoolXML.h b/src/scheduler/include/PoolXML.h index 33fb5ffa17..6aa36a0c73 100644 --- a/src/scheduler/include/PoolXML.h +++ b/src/scheduler/include/PoolXML.h @@ -90,7 +90,7 @@ public: get_suitable_nodes(nodes); for (unsigned int i=0 ; - i < nodes.size() && ( pool_limit <= 0 || i < pool_limit ) ; + i < nodes.size() && ( pool_limit == 0 || i < pool_limit ) ; i++) { add_object(nodes[i]); diff --git a/src/scheduler/include/Scheduler.h b/src/scheduler/include/Scheduler.h index 07d945b6ec..a85e76ecfc 100644 --- a/src/scheduler/include/Scheduler.h +++ b/src/scheduler/include/Scheduler.h @@ -78,6 +78,7 @@ protected: machines_limit(0), dispatch_limit(0), host_dispatch_limit(0), + zone_id(0), mem_ds_scale(0), diff_vnets(false) { diff --git a/src/scheduler/include/SchedulerPolicy.h b/src/scheduler/include/SchedulerPolicy.h index 6e31edb923..472802df07 100644 --- a/src/scheduler/include/SchedulerPolicy.h +++ b/src/scheduler/include/SchedulerPolicy.h @@ -115,7 +115,7 @@ private: float weight; - float max; + float max = 0; } sw; }; diff --git a/src/scheduler/include/VirtualMachinePoolXML.h b/src/scheduler/include/VirtualMachinePoolXML.h index 110f51d7a5..79726345e2 100644 --- a/src/scheduler/include/VirtualMachinePoolXML.h +++ b/src/scheduler/include/VirtualMachinePoolXML.h @@ -222,7 +222,7 @@ protected: oss << "/VM_POOL/VM[TEMPLATE/VMGROUP/ROLE]"; - return get_nodes(oss.str().c_str(), content); + return get_nodes(oss.str(), content); } }; #endif /* VM_POOL_XML_H_ */ diff --git a/src/scheduler/src/pool/VirtualMachineXML.cc b/src/scheduler/src/pool/VirtualMachineXML.cc index 10a4840389..daf58a5d69 100644 --- a/src/scheduler/src/pool/VirtualMachineXML.cc +++ b/src/scheduler/src/pool/VirtualMachineXML.cc @@ -228,20 +228,20 @@ void VirtualMachineXML::init_attributes() user_template->from_xml_node(nodes[0]); free_nodes(nodes); + + public_cloud = (user_template->get("PUBLIC_CLOUD", attrs) > 0); + + if (public_cloud == false) + { + attrs.clear(); + public_cloud = (user_template->get("EC2", attrs) > 0); + } } else { user_template = 0; } - public_cloud = (user_template->get("PUBLIC_CLOUD", attrs) > 0); - - if (public_cloud == false) - { - attrs.clear(); - public_cloud = (user_template->get("EC2", attrs) > 0); - } - only_public_cloud = false; if (vm_template != 0) @@ -313,10 +313,7 @@ void VirtualMachineXML::init_storage_usage() continue; } - if (ds_usage.count(ds_id) == 0) - { - ds_usage[ds_id] = 0; - } + ds_usage.emplace(ds_id, 0); if (disk->vector_value("CLONE", clone) != 0) { @@ -455,7 +452,7 @@ bool VirtualMachineXML::test_image_datastore_capacity( { ostringstream oss; - oss << "Image Datastore " << ds->get_oid() + oss << "Image Datastore " << ds_it->first << " does not have enough capacity"; error_msg = oss.str(); diff --git a/src/scheduler/src/sched/Scheduler.cc b/src/scheduler/src/sched/Scheduler.cc index f748c604be..68000dfba6 100644 --- a/src/scheduler/src/sched/Scheduler.cc +++ b/src/scheduler/src/sched/Scheduler.cc @@ -1331,7 +1331,7 @@ void Scheduler::dispatch() // Dispatch each VM till we reach the dispatch limit //-------------------------------------------------------------------------- for (k = vm_rs.rbegin(); k != vm_rs.rend() && - ( dispatch_limit <= 0 || dispatched_vms < dispatch_limit ); ++k) + ( dispatch_limit == 0 || dispatched_vms < dispatch_limit ); ++k) { dispatched = false; diff --git a/src/template/Template.cc b/src/template/Template.cc index 9d4cce0c53..d9f1f86c00 100644 --- a/src/template/Template.cc +++ b/src/template/Template.cc @@ -531,7 +531,7 @@ Attribute * Template::vector_xml_att(const xmlNode * node) attr = new VectorAttribute( reinterpret_cast(node->name)); - for(child = child; child != 0; child = child->next) + for( ; child != 0; child = child->next) { grandchild = child->children; diff --git a/src/um/UserPool.cc b/src/um/UserPool.cc index 04ab1bdabb..ed10ff7c38 100644 --- a/src/um/UserPool.cc +++ b/src/um/UserPool.cc @@ -402,9 +402,9 @@ int UserPool::allocate( user = new User(-1, gid, uname, gname, upass, auth_driver, enabled); // Add the primary and secondary groups to the collection - for (auto gid : gids) + for (auto group_id : gids) { - user->add_group(gid); + user->add_group(group_id); } // Set a password for the OneGate tokens @@ -419,9 +419,9 @@ int UserPool::allocate( } // Add the user to the main and secondary groups - for (auto gid : gids) + for (auto group_id : gids) { - auto group = gpool->get(gid); + auto group = gpool->get(group_id); if (!group) //Secondary group no longer exists { @@ -443,9 +443,9 @@ int UserPool::allocate( if ( driver_managed_group_admin ) { // Set the user group admin - for (auto gid : agids) + for (auto group_id : agids) { - auto group = gpool->get(gid); + auto group = gpool->get(group_id); if (!group) //Secondary group no longer exists { @@ -486,9 +486,9 @@ error_group: // Remove from all the groups, just in case the user id was added to a any // of them before a non-existing group was found - for (auto gid : gids) + for (auto group_id : gids) { - if ( auto group = gpool->get(gid) ) + if ( auto group = gpool->get(group_id) ) { group->del_user(*oid); diff --git a/src/vdc/Vdc.cc b/src/vdc/Vdc.cc index 66b8cc3de6..47236281b8 100644 --- a/src/vdc/Vdc.cc +++ b/src/vdc/Vdc.cc @@ -534,9 +534,9 @@ int ResourceSet::add(const set& groups, int zone_id, int id, } } - for (auto id : del_ids) + for (auto del_id : del_ids) { - this->del(groups, zone_id, id, error_aux); + this->del(groups, zone_id, del_id, error_aux); } } diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index fde3d189f9..1aa4b879bf 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -2779,12 +2779,6 @@ int VirtualMachine::replace_template( auto new_tmpl = make_unique(false,'=',"USER_TEMPLATE"); - if ( new_tmpl == 0 ) - { - error = "Cannot allocate a new template"; - return -1; - } - if ( new_tmpl->parse_str_or_xml(tmpl_str, error) != 0 ) { return -1; @@ -2838,12 +2832,6 @@ int VirtualMachine::append_template( make_unique(false,'=',"USER_TEMPLATE"); string rname; - if ( new_tmpl == 0 ) - { - error = "Cannot allocate a new template"; - return -1; - } - if ( new_tmpl->parse_str_or_xml(tmpl_str, error) != 0 ) { return -1; @@ -2852,31 +2840,18 @@ int VirtualMachine::append_template( /* ---------------------------------------------------------------------- */ /* Append new_tmpl to the current user_template */ /* ---------------------------------------------------------------------- */ + // Create a copy of actual user template auto old_user_tmpl = make_unique(*user_obj_template); - if (user_obj_template != 0) + if (keep_restricted && + new_tmpl->check_restricted(rname, user_obj_template.get())) { - if (keep_restricted && - new_tmpl->check_restricted(rname, user_obj_template.get())) - { - error ="User Template includes a restricted attribute " + rname; + error ="User Template includes a restricted attribute " + rname; - return -1; - } - - user_obj_template->merge(new_tmpl.get()); + return -1; } - else - { - if (keep_restricted && new_tmpl->check_restricted(rname)) - { - error ="User Template includes a restricted attribute " + rname; - return -1; - } - - user_obj_template = move(new_tmpl); - } + user_obj_template->merge(new_tmpl.get()); if (post_update_template(error) == -1) { @@ -3470,15 +3445,25 @@ int VirtualMachine::get_auto_network_leases(VirtualMachineTemplate * tmpl, VirtualMachineNic * nic = get_nic(nic_id); + if (!nic) + { + std::ostringstream oss; + + oss << "NIC_ID " << nic_id << " not found"; + estr = oss.str(); + + return -1; + } + net_mode = nic->vector_value("NETWORK_MODE"); string network_id = nic->vector_value("NETWORK_ID"); - if (nic == 0 || !one_util::icasecmp(net_mode, "AUTO") || !network_id.empty()) + if (!one_util::icasecmp(net_mode, "AUTO") || !network_id.empty()) { std::ostringstream oss; - oss << "NIC_ID "<< nic_id << " not found or not AUTO"; + oss << "NIC_ID " << nic_id << " not AUTO"; estr = oss.str(); return -1; diff --git a/src/vm/VirtualMachineParser.cc b/src/vm/VirtualMachineParser.cc index 81116984e1..43df2dbdfa 100644 --- a/src/vm/VirtualMachineParser.cc +++ b/src/vm/VirtualMachineParser.cc @@ -951,7 +951,7 @@ int VirtualMachine::parse_topology(Template * tmpl, std::string &error) (*it)->vector_value("TOTAL_CPUS", ncpu); (*it)->vector_value("MEMORY", nmem); - if ( ncpu <= 0 || nmem <= 0) + if ( ncpu == 0 || nmem <= 0) { break; } @@ -970,7 +970,7 @@ int VirtualMachine::parse_topology(Template * tmpl, std::string &error) tmpl->erase("NUMA_NODE"); if (node_cpu != vcpu || node_mem != memory || - ncpu <= 0 || nmem <= 0) + ncpu == 0 || nmem <= 0) { for (auto it = new_nodes.begin(); it != new_nodes.end(); ++it) { @@ -978,7 +978,7 @@ int VirtualMachine::parse_topology(Template * tmpl, std::string &error) } } - if (ncpu <= 0) + if (ncpu == 0) { error = "A NUMA_NODE must have TOTAL_CPUS greater than 0"; return -1; diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 1c413864fc..1e174fa870 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -707,7 +707,7 @@ int VirtualMachinePool::calculate_showback( std::string acct_str; - rc = dump_acct(acct_str, start_time, end_time, start_index, chunk_size); + dump_acct(acct_str, start_time, end_time, start_index, chunk_size); start_index += chunk_size; ObjectXML xml(acct_str); @@ -717,7 +717,7 @@ int VirtualMachinePool::calculate_showback( //-------------------------------------------------------------------------- nodes.clear(); - rc = xml.get_nodes("/HISTORY_RECORDS/HISTORY", nodes); + xml.get_nodes("/HISTORY_RECORDS/HISTORY", nodes); for ( auto node : nodes ) { @@ -775,10 +775,7 @@ int VirtualMachinePool::calculate_showback( if( (et > t || et == 0) && (st != 0 && st <= t_next) ) { - time_t stime = t; - if(st != 0){ - stime = max(t, st); - } + time_t stime = max(t, st); time_t etime = t_next; if(et != 0){ diff --git a/src/xml/ObjectXML.cc b/src/xml/ObjectXML.cc index 81912c2777..6fa820526d 100644 --- a/src/xml/ObjectXML.cc +++ b/src/xml/ObjectXML.cc @@ -31,7 +31,11 @@ using namespace std; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -ObjectXML::ObjectXML(const std::string &xml_doc):paths(0),num_paths(0),xml(0),ctx(0) +ObjectXML::ObjectXML(const std::string &xml_doc) + : paths(nullptr) + , num_paths(0) + , xml(nullptr) + , ctx(nullptr) { try {