diff --git a/include/DatastorePool.h b/include/DatastorePool.h index 58adca22e5..711236c37b 100644 --- a/include/DatastorePool.h +++ b/include/DatastorePool.h @@ -26,7 +26,7 @@ using namespace std; class DatastorePool : public PoolSQL { public: - DatastorePool(SqlDB * db); + DatastorePool(SqlDB * db, const vector& _inherit_attrs); ~DatastorePool(){}; @@ -189,7 +189,20 @@ public: return PoolSQL::list(oids, Datastore::table); } + /** + * Adds to the disk the datastore inherit attributes and conf values + * @param ds_id of the datastore to use + * @para disk vector attribute for the disk + * + * @return -1 if the DS does not exists + */ + int disk_attribute(int ds_id, VectorAttribute * disk); + private: + /** + * Datastore attributes to be inherited into the VM disk + */ + vector inherit_attrs; /** * Factory method to produce objects diff --git a/include/ImagePool.h b/include/ImagePool.h index 82ec16709a..7e5b676342 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -48,8 +48,7 @@ public: vector& restricted_attrs, vector hook_mads, const string& remotes_location, - const vector& _inherit_image_attrs, - const vector& _inherit_datastore_attrs); + const vector& _inherit_image_attrs); ~ImagePool(){}; @@ -248,12 +247,7 @@ private: /** * Image attributes to be inherited into the VM disk */ - vector inherit_image_attrs; - - /** - * Datastore attributes to be inherited into the VM disk - */ - vector inherit_datastore_attrs; + vector inherit_attrs; //-------------------------------------------------------------------------- // Pool Attributes diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc index 04eefa6456..affd7d1f30 100644 --- a/src/datastore/DatastorePool.cc +++ b/src/datastore/DatastorePool.cc @@ -38,12 +38,24 @@ const int DatastorePool::FILE_DS_ID = 2; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -DatastorePool::DatastorePool(SqlDB * db): - PoolSQL(db, Datastore::table, true, true) +DatastorePool::DatastorePool( + SqlDB * db, + const vector& _inherit_attrs) : + PoolSQL(db, Datastore::table, true, true) + { ostringstream oss; string error_str; + vector::const_iterator it; + + for (it = _inherit_attrs.begin(); it != _inherit_attrs.end(); it++) + { + const SingleAttribute* sattr = static_cast(*it); + + inherit_attrs.push_back(sattr->value()); + } + if (get_lastOID() == -1) //lastOID is set in PoolSQL::init_cb { DatastoreTemplate * ds_tmpl; @@ -261,3 +273,20 @@ int DatastorePool::drop(PoolObjectSQL * objsql, string& error_msg) return rc; } + +int DatastorePool::disk_attribute(int ds_id, VectorAttribute * disk) +{ + Datastore * ds = get(ds_id, true); + + if (ds == 0) + { + return -1; + } + + ds->disk_attribute(disk, inherit_attrs); + + ds->unlock(); + + return 0; +} + diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 3e9281fde5..e550155a3f 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -41,8 +41,7 @@ ImagePool::ImagePool( vector& restricted_attrs, vector hook_mads, const string& remotes_location, - const vector& _inherit_image_attrs, - const vector& _inherit_datastore_attrs) + const vector& _inherit_attrs) :PoolSQL(db, Image::table, true, true) { // Init static defaults @@ -54,18 +53,11 @@ ImagePool::ImagePool( // Init inherit attributes vector::const_iterator it; - for (it = _inherit_image_attrs.begin(); it != _inherit_image_attrs.end(); it++) + for (it = _inherit_attrs.begin(); it != _inherit_attrs.end(); it++) { const SingleAttribute* sattr = static_cast(*it); - inherit_image_attrs.push_back(sattr->value()); - } - - for (it = _inherit_datastore_attrs.begin(); it != _inherit_datastore_attrs.end(); it++) - { - const SingleAttribute* sattr = static_cast(*it); - - inherit_datastore_attrs.push_back(sattr->value()); + inherit_attrs.push_back(sattr->value()); } // Set default type @@ -408,7 +400,6 @@ int ImagePool::acquire_disk(int vm_id, if ( img != 0 ) { DatastorePool * ds_pool = nd.get_dspool(); - Datastore * ds; long long size = 0; bool has_size = (disk->vector_value("SIZE", size) == 0); @@ -440,7 +431,7 @@ int ImagePool::acquire_disk(int vm_id, } iid = img->get_oid(); - img->disk_attribute(disk, img_type, dev_prefix, inherit_image_attrs); + img->disk_attribute(disk, img_type, dev_prefix, inherit_attrs); image_id = img->get_oid(); datastore_id = img->get_ds_id(); @@ -453,9 +444,7 @@ int ImagePool::acquire_disk(int vm_id, img->unlock(); - ds = ds_pool->get(datastore_id, true); - - if ( ds == 0 ) + if ( ds_pool->disk_attribute(datastore_id, disk) == -1 ) { imagem->release_image(vm_id, iid, false); error_str = "Associated datastore for the image does not exist"; @@ -465,10 +454,6 @@ int ImagePool::acquire_disk(int vm_id, return -1; } - - ds->disk_attribute(disk, inherit_datastore_attrs); - - ds->unlock(); } disk->replace("DISK_ID", disk_id); @@ -495,7 +480,6 @@ void ImagePool::disk_attribute( Nebula& nd = Nebula::instance(); DatastorePool * ds_pool = nd.get_dspool(); - Datastore * ds; if (!(source = disk->vector_value("IMAGE")).empty()) { @@ -518,20 +502,13 @@ void ImagePool::disk_attribute( if ( img != 0 ) { - img->disk_attribute(disk, img_type, dev_prefix, inherit_image_attrs); + img->disk_attribute(disk, img_type, dev_prefix, inherit_attrs); datastore_id = img->get_ds_id(); img->unlock(); - ds = ds_pool->get(datastore_id, true); - - if ( ds != 0 ) - { - ds->disk_attribute(disk, inherit_datastore_attrs); - - ds->unlock(); - } + ds_pool->disk_attribute(datastore_id, disk); } disk->replace("DISK_ID", disk_id); diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 95af52bbbb..c0d1fab0e5 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -594,12 +594,11 @@ void Nebula::start(bool bootstrap_only) img_restricted_attrs, image_hooks, remotes_location, - inherit_image_attrs, - inherit_datastore_attrs); + inherit_image_attrs); tpool = new VMTemplatePool(db); - dspool = new DatastorePool(db); + dspool = new DatastorePool(db, inherit_datastore_attrs); default_user_quota.select(); default_group_quota.select();