diff --git a/include/Cluster.h b/include/Cluster.h index 002328bd05..9c4641b7c2 100644 --- a/include/Cluster.h +++ b/include/Cluster.h @@ -31,6 +31,23 @@ class Cluster : public PoolObjectSQL { public: + /** + * Returns the SYSTEM_DS attribute, or the system DS id if it is not defined + * + * @return the SYSTEM_DS attribute, or the system DS id if it is not defined + */ + int get_ds_id() + { + int ds_id; + + if ( obj_template->get("SYSTEM_DS", ds_id) == false ) + { + ds_id = DatastorePool::SYSTEM_DS_ID; + } + + return ds_id; + } + // ************************************************************************* // Object Collections (Public) // ************************************************************************* diff --git a/include/Datastore.h b/include/Datastore.h index ceaf552fde..1941b02342 100644 --- a/include/Datastore.h +++ b/include/Datastore.h @@ -134,6 +134,11 @@ private: */ string base_path; + /** + * 1 if this is a system DS + */ + int system_ds; + /** * Disk types for the Images created in this datastore */ diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 8b40ddc925..96908e63cb 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -19,6 +19,8 @@ #include "NebulaLog.h" #include "Nebula.h" +#define TO_UPPER(S) transform(S.begin(),S.end(),S.begin(),(int(*)(int))toupper) + const char * Datastore::table = "datastore_pool"; const char * Datastore::db_names = @@ -97,6 +99,7 @@ int Datastore::insert(SqlDB *db, string& error_str) int rc; ostringstream oss; string s_disk_type; + string s_system_ds; Nebula& nd = Nebula::instance(); @@ -108,8 +111,22 @@ int Datastore::insert(SqlDB *db, string& error_str) // NAME is checked in DatastorePool::allocate get_template_attribute("DS_MAD", ds_mad); + get_template_attribute("SYSTEM", s_system_ds); - if ( ds_mad.empty() == true ) + TO_UPPER(s_system_ds); + + system_ds = (s_system_ds == "YES"); + + if ( system_ds == 1 ) + { + if ( !ds_mad.empty() ) + { + goto error_exclusive; + } + + ds_mad = "-"; + } + else if ( ds_mad.empty() == true ) { goto error_ds; } @@ -152,6 +169,10 @@ int Datastore::insert(SqlDB *db, string& error_str) return rc; +error_exclusive: + error_str = "SYSTEM datastores cannot have DS_MAD defined."; + goto error_common; + error_ds: error_str = "No DS_MAD in template."; goto error_common; @@ -273,6 +294,7 @@ string& Datastore::to_xml(string& xml) const "" << ds_mad << "" << "" << tm_mad << "" << "" << base_path << "" << + "" << system_ds << "" << "" << disk_type << "" << "" << cluster_id << "" << "" << cluster << "" << @@ -307,6 +329,7 @@ int Datastore::from_xml(const string& xml) rc += xpath(ds_mad, "/DATASTORE/DS_MAD", "not_found"); rc += xpath(tm_mad, "/DATASTORE/TM_MAD", "not_found"); rc += xpath(base_path, "/DATASTORE/BASE_PATH", "not_found"); + rc += xpath(system_ds, "/DATASTORE/SYSTEM", -1); rc += xpath(int_disk_type,"/DATASTORE/DISK_TYPE", -1); rc += xpath(cluster_id, "/DATASTORE/CLUSTER_ID", -1); @@ -354,14 +377,15 @@ int Datastore::from_xml(const string& xml) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int Datastore::replace_template(const string& tmpl_str, string& error) +int Datastore::replace_template(const string& tmpl_str, string& error_str) { string new_ds_mad; string new_tm_mad; + string s_system_ds; int rc; - rc = PoolObjectSQL::replace_template(tmpl_str, error); + rc = PoolObjectSQL::replace_template(tmpl_str, error_str); if ( rc != 0 ) { @@ -369,15 +393,32 @@ int Datastore::replace_template(const string& tmpl_str, string& error) } get_template_attribute("DS_MAD", new_ds_mad); + get_template_attribute("SYSTEM", s_system_ds); + + TO_UPPER(s_system_ds); + + if ( !s_system_ds.empty() ) + { + system_ds = (s_system_ds == "YES"); + } + + if ( system_ds == 1 ) + { + replace_template_attribute("SYSTEM", "YES"); + + new_ds_mad = "-"; + } + else + { + obj_template->erase("SYSTEM"); + } if ( !new_ds_mad.empty() ) { ds_mad = new_ds_mad; } - else - { - replace_template_attribute("DS_MAD", ds_mad); - } + + replace_template_attribute("DS_MAD", ds_mad); get_template_attribute("TM_MAD", new_tm_mad); diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc index b38318fc04..c8639eca69 100644 --- a/src/datastore/DatastorePool.cc +++ b/src/datastore/DatastorePool.cc @@ -53,7 +53,7 @@ DatastorePool::DatastorePool(SqlDB * db): // --------------------------------------------------------------------- oss << "NAME = " << SYSTEM_DS_NAME << endl - << "DS_MAD = -" << endl + << "SYSTEM = YES" << endl << "TM_MAD = shared"; ds_tmpl = new DatastoreTemplate; diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 90ec095ced..cad51340ce 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -145,8 +145,7 @@ int RequestManagerVirtualMachine::get_host_information(int hid, return -1; } - // TODO: ds_id = cluster->get_datastore() - ds_id = DatastorePool::SYSTEM_DS_ID; + ds_id = cluster->get_ds_id(); cluster->unlock();