diff --git a/include/Image.h b/include/Image.h index bdee93831a..871046a443 100644 --- a/include/Image.h +++ b/include/Image.h @@ -329,18 +329,13 @@ public: * Modifies the given disk attribute adding the following attributes: * * SOURCE: the file-path. * * BUS: will only be set if the Image's definition includes it. - * * TARGET: the value set depends on: - * - OS images will be mounted at prefix + a: hda, sda. - * - Prefix + b is reserved for the contex cdrom. - * - CDROM images will be at prefix + c: hdc, sdc. - * - Several DATABLOCK images can be mounted, they will be set to - * prefix + (d + index) : hdd, hde, hdf... + * * TARGET: if not set uses that in the image template * @param disk attribute for the VM template - * @param index number of datablock images used by the same VM. Will be - * automatically increased. - * @param img_type will be set to the used image's type + * + * @return -1 if there is no TARGET in the disk nor in the template, 0 + * otherwise */ - int disk_attribute(VectorAttribute * disk, int* index, ImageType* img_type); + int disk_attribute(VectorAttribute * disk); /** * Factory method for image templates diff --git a/include/ImagePool.h b/include/ImagePool.h index 4fc8038f9b..e4792b6677 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -40,7 +40,6 @@ public: ImagePool(SqlDB * db, const string& _default_type, - const string& _default_dev_prefix, vector& restricted_attrs); ~ImagePool(){}; @@ -136,9 +135,6 @@ public: * Generates a DISK attribute for VM templates using the Image metadata * @param disk the disk to be generated * @param disk_id the id for this disk - * @param index number of datablock images used by the same VM. Will be - * automatically increased. - * @param img_type will be set to the used image's type * @param uid of VM owner (to look for the image id within its images) * @param image_id on success returns the acquired image id * @param error_str string describing the error @@ -148,8 +144,6 @@ public: */ int disk_attribute(VectorAttribute * disk, int disk_id, - int * index, - Image::ImageType * img_type, int uid, int& image_id, string& error_str); @@ -166,11 +160,6 @@ public: return _default_type; }; - static const string& default_dev_prefix() - { - return _default_dev_prefix; - }; - private: //-------------------------------------------------------------------------- // Configuration Attributes for Images @@ -181,11 +170,6 @@ private: **/ static string _default_type; - /** - * Default device prefix - **/ - static string _default_dev_prefix; - //-------------------------------------------------------------------------- // Pool Attributes // ------------------------------------------------------------------------- diff --git a/include/test/NebulaTest.h b/include/test/NebulaTest.h index bd73d4f201..754289367c 100644 --- a/include/test/NebulaTest.h +++ b/include/test/NebulaTest.h @@ -104,8 +104,7 @@ public: virtual UserPool* create_upool(SqlDB* db); - virtual ImagePool* create_ipool( SqlDB* db, - string default_image_type, + virtual ImagePool* create_ipool(SqlDB* db, string default_device_prefix); virtual VMTemplatePool* create_tpool(SqlDB* db); diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 0bf1cd0492..c49a503ecd 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -88,19 +88,11 @@ MAC_PREFIX = "02:00" # DEFAULT_IMAGE_TYPE: This can take values # OS Image file holding an operating system # CDROM Image file holding a CDROM -# DATABLOCK Image file holding a datablock, -# always created as an empty block -# DEFAULT_DEVICE_PREFIX: This can be set to -# hd IDE prefix -# sd SCSI -# xvd XEN Virtual Disk -# vd KVM virtual disk +# DATABLOCK Image file holding a datablock, created as an empty block #******************************************************************************* #DATASTORE_LOCATION = /var/lib/one/datastores - -DEFAULT_IMAGE_TYPE = "OS" -DEFAULT_DEVICE_PREFIX = "hd" +DEFAULT_IMAGE_TYPE = "OS" #******************************************************************************* # Information Driver Configuration diff --git a/src/image/Image.cc b/src/image/Image.cc index adcb40d64c..389b7ef0fd 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -130,17 +130,6 @@ int Image::insert(SqlDB *db, string& error_str) persistent_img = (persistent_attr == "YES"); - // ------------ PREFIX -------------------- - - get_template_attribute("DEV_PREFIX", dev_prefix); - - if( dev_prefix.empty() ) - { - SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX", - ImagePool::default_dev_prefix()); - obj_template->set(dev_att); - } - // ------------ PATH & SOURCE -------------------- erase_template_attribute("PATH", path); @@ -437,18 +426,15 @@ int Image::from_xml(const string& xml) /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ -int Image::disk_attribute( VectorAttribute * disk, - int * index, - ImageType* img_type) +int Image::disk_attribute(VectorAttribute * disk) { - string bus; - string target; - string driver; - string disk_attr_type; + string bus; + string target; + string driver; + string disk_attr_type; - ostringstream iid; + ostringstream iid; - *img_type = type; bus = disk->vector_value("BUS"); target = disk->vector_value("TARGET"); driver = disk->vector_value("DRIVER"); @@ -456,24 +442,30 @@ int Image::disk_attribute( VectorAttribute * disk, string template_bus; string template_target; - string prefix; string template_driver; - get_template_attribute("BUS", template_bus); + get_template_attribute("BUS", template_bus); get_template_attribute("TARGET", template_target); get_template_attribute("DRIVER", template_driver); - get_template_attribute("DEV_PREFIX", prefix); - - if (prefix.empty())//Removed from image template, get it again from defaults + //--------------------------------------------------------------------------- + // TARGET attribute + //--------------------------------------------------------------------------- + if (target.empty()) { - prefix = ImagePool::default_dev_prefix(); + if (!template_target.empty()) + { + disk->replace("TARGET", template_target); + } + else //No TARGET in DISK nor in Image (ERROR!) + { + return -1; + } } //--------------------------------------------------------------------------- // BASE DISK ATTRIBUTES //--------------------------------------------------------------------------- - disk->replace("IMAGE", name); disk->replace("IMAGE_ID", iid.str()); disk->replace("SOURCE", source); @@ -491,7 +483,6 @@ int Image::disk_attribute( VectorAttribute * disk, //--------------------------------------------------------------------------- // TYPE, READONLY, CLONE, and SAVE attributes //--------------------------------------------------------------------------- - if ( persistent_img ) { disk->replace("CLONE","NO"); @@ -518,42 +509,8 @@ int Image::disk_attribute( VectorAttribute * disk, break; } - disk->replace("TYPE",disk_attr_type); - - //--------------------------------------------------------------------------- - // TARGET attribute - //--------------------------------------------------------------------------- - - if (target.empty()) //No TARGET in DISK attribute - { - if (!template_target.empty()) - { - disk->replace("TARGET", template_target); - } - else - { - switch(type) - { - case OS: - prefix += "a"; - break; - - case CDROM: - prefix += "c"; // b is for context - break; - - case DATABLOCK: - prefix += static_cast(('e'+ *index)); - *index = *index + 1; - break; - - } - - disk->replace("TARGET", prefix); - } - } - + return 0; } diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index 58f41d3d33..17f63c3f62 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -191,6 +191,7 @@ void ImageManager::release_image(int iid, bool failed) img->unlock(); break; + case Image::DISABLED: case Image::READY: case Image::ERROR: diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 3fde07920c..48ad8be838 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -26,14 +26,12 @@ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ string ImagePool::_default_type; -string ImagePool::_default_dev_prefix; /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -ImagePool::ImagePool(SqlDB * db, - const string& __default_type, - const string& __default_dev_prefix, +ImagePool::ImagePool(SqlDB * db, + const string& __default_type, vector& restricted_attrs): PoolSQL(db, Image::table, true) { @@ -41,7 +39,6 @@ ImagePool::ImagePool(SqlDB * db, // Init static defaults _default_type = __default_type; - _default_dev_prefix = __default_dev_prefix; // Set default type if (_default_type != "OS" && @@ -216,8 +213,6 @@ static int get_disk_id(const string& id_s) int ImagePool::disk_attribute(VectorAttribute * disk, int disk_id, - int * index, - Image::ImageType * img_type, int uid, int& image_id, string& error_str) @@ -226,6 +221,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk, Image * img = 0; int rc = 0; int datastore_id; + int iid; ostringstream oss; @@ -248,10 +244,12 @@ int ImagePool::disk_attribute(VectorAttribute * disk, { return -1; } + + iid = img->get_oid(); } else if (!(source = disk->vector_value("IMAGE_ID")).empty()) { - int iid = get_disk_id(source); + iid = get_disk_id(source); if ( iid == -1) { @@ -266,28 +264,27 @@ int ImagePool::disk_attribute(VectorAttribute * disk, return -1; } } - else //Not using the image repository + else //Not using the image repository (volatile DISK) { - string type; - - rc = -2; - type = disk->vector_value("TYPE"); + string type = disk->vector_value("TYPE"); transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper); - if( type == "SWAP" ) + if ( type == "SWAP" || type == "FS" ) { string target = disk->vector_value("TARGET"); if ( target.empty() ) { - string dev_prefix = _default_dev_prefix; - - dev_prefix += "d"; - - disk->replace("TARGET", dev_prefix); + error_str = "Missing target for disk of type " + type; + return -1; } } + else + { + error_str = "Unknown disk type " + type; + return -1; + } } if ( img != 0 ) @@ -295,20 +292,29 @@ int ImagePool::disk_attribute(VectorAttribute * disk, DatastorePool * ds_pool = nd.get_dspool(); Datastore * ds; - img->disk_attribute(disk, index, img_type); + iid = img->get_oid(); + rc = img->disk_attribute(disk); image_id = img->get_oid(); datastore_id = img->get_ds_id(); - update(img); - img->unlock(); + if (rc == -1) + { + imagem->release_image(iid, false); + error_str = "Missing TARGET in disk"; + + return -1; + } + ds = ds_pool->get(datastore_id, true); if ( ds == 0 ) { + imagem->release_image(iid, false); error_str = "Associated datastore for the image does not exist"; + return -1; } diff --git a/src/image/test/ImagePoolTest.cc b/src/image/test/ImagePoolTest.cc index 11f1d82003..ab63e93cf5 100644 --- a/src/image/test/ImagePoolTest.cc +++ b/src/image/test/ImagePoolTest.cc @@ -90,12 +90,10 @@ class ImagePoolFriend : public ImagePool public: ImagePoolFriend(SqlDB * db, const string& _default_type, - const string& _default_dev_prefix, vector _restricted_attrs): ImagePool( db, _default_type, - _default_dev_prefix, _restricted_attrs){}; @@ -115,7 +113,7 @@ public: string gname = gnames[uid]; return ImagePool::allocate(uid, 1, uname, gname, - img_template, 0,"none", "", oid, err); + img_template, 0, "none", "", oid, err); } else { @@ -145,7 +143,6 @@ class ImagePoolTest : public PoolTest CPPUNIT_TEST ( duplicates ); CPPUNIT_TEST ( extra_attributes ); CPPUNIT_TEST ( wrong_templates ); - CPPUNIT_TEST ( target_generation ); CPPUNIT_TEST ( bus_source_assignment ); CPPUNIT_TEST ( persistence ); CPPUNIT_TEST ( imagepool_disk_attribute ); @@ -256,7 +253,7 @@ public: // Create a new pool, using the same DB. This new pool should read the // allocated images. vector restricted_attrs; - imp = new ImagePool(db,"OS", "hd", restricted_attrs); + imp = new ImagePool(db,"OS", restricted_attrs); img = imp->get(0, false); CPPUNIT_ASSERT( img != 0 ); @@ -427,107 +424,6 @@ public: } } -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - - void target_generation() - { - ImagePoolFriend * imp = static_cast(pool); - Image * img; - - VectorAttribute * disk; - int oid; - string value; - int index=0; - Image::ImageType img_type; - - disk = new VectorAttribute("DISK"); - - // Allocate an OS type image - oid = allocate(0); - img = imp->get(oid, false); - - CPPUNIT_ASSERT( img != 0 ); - CPPUNIT_ASSERT( oid == 0 ); - - img->set_state(Image::READY); - img->disk_attribute(disk, &index, &img_type); - - value = disk->vector_value("TARGET"); - - CPPUNIT_ASSERT( value == "hda" ); - CPPUNIT_ASSERT( img_type == Image::OS ); - - // clean up - delete disk; - value = ""; - - disk = new VectorAttribute("DISK"); - - // Allocate a CDROM type image - string templ = "NAME = \"name A\" TYPE = CDROM PATH = /tmp"; - imp->allocate(0, templ, &oid); - - CPPUNIT_ASSERT(oid >= 0); - - img = imp->get(oid, false); - CPPUNIT_ASSERT( img != 0 ); - - img->set_state(Image::READY); - img->disk_attribute(disk, &index, &img_type); - - value = disk->vector_value("TARGET"); - CPPUNIT_ASSERT(value == "hdc"); - CPPUNIT_ASSERT( img_type == Image::CDROM ); - - // clean up - delete disk; - value = ""; - - disk = new VectorAttribute("DISK"); - - // Allocate a DATABLOCK type image - templ = "NAME = \"name B\" TYPE = DATABLOCK PATH=\"/dev/null\""; - imp->allocate(0, templ, &oid); - - CPPUNIT_ASSERT(oid >= 0); - - img = imp->get(oid, false); - CPPUNIT_ASSERT( img != 0 ); - - img->set_state(Image::READY); - img->disk_attribute(disk, &index, &img_type); - - value = disk->vector_value("TARGET"); - CPPUNIT_ASSERT(value == "hde"); - CPPUNIT_ASSERT( img_type == Image::DATABLOCK ); - - // clean up - delete disk; - value = ""; - - disk = new VectorAttribute("DISK"); - - // Allocate a DATABLOCK type image - templ = "NAME = \"name C\" TYPE = DATABLOCK DEV_PREFIX = \"sd\"" - " SIZE=4 FSTYPE=ext3"; - imp->allocate(0, templ, &oid); - - CPPUNIT_ASSERT(oid >= 0); - - img = imp->get(oid, false); - CPPUNIT_ASSERT( img != 0 ); - - img->set_state(Image::READY); - img->disk_attribute(disk, &index, &img_type); - - value = disk->vector_value("TARGET"); - CPPUNIT_ASSERT(value == "sdf"); - - // clean up - delete disk; - } - /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -604,11 +500,10 @@ public: // Allocate 2 images, with different dev_prefix string template_0 = "NAME = \"Image 0\"\n" - "DEV_PREFIX = \"hd\"\n" + "TARGET = \"hdx\"\n" "PATH = /dev/null\n"; string template_1 = "NAME = \"Image 1\"\n" - "DEV_PREFIX = \"sd\"\n" "PATH = /dev/null\n"; @@ -632,29 +527,25 @@ public: disk = new VectorAttribute("DISK"); disk->replace("IMAGE_ID", "0"); - ((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type,0, img_id,error); + ((ImagePool*)imp)->disk_attribute(disk, 0, 0, img_id,error); value = ""; value = disk->vector_value("TARGET"); - CPPUNIT_ASSERT( value == "hda" ); + CPPUNIT_ASSERT( value == "hdx" ); + value = ""; + value = disk->vector_value("IMAGE"); + CPPUNIT_ASSERT( value == "Image 0" ); delete disk; - // Disk using image 1 index disk = new VectorAttribute("DISK"); disk->replace("IMAGE_ID", "1"); - ((ImagePool*)imp)->disk_attribute(disk, 0, &index, &img_type,0, img_id,error); + int rc = ((ImagePool*)imp)->disk_attribute(disk, 0, 0, img_id,error); - value = ""; - value = disk->vector_value("TARGET"); - CPPUNIT_ASSERT( value == "sda" ); - - value = ""; - value = disk->vector_value("IMAGE"); - CPPUNIT_ASSERT( value == "Image 1" ); + CPPUNIT_ASSERT( rc == -1 ); delete disk; } diff --git a/src/nebula/Nebula.cc b/src/nebula/Nebula.cc index 7ccb90c74b..d2cef5f284 100644 --- a/src/nebula/Nebula.cc +++ b/src/nebula/Nebula.cc @@ -299,16 +299,9 @@ void Nebula::start() upool = new UserPool(db, expiration_time); nebula_configuration->get("DEFAULT_IMAGE_TYPE", default_image_type); - nebula_configuration->get("DEFAULT_DEVICE_PREFIX", - default_device_prefix); - - ipool = new ImagePool(db, - default_image_type, - default_device_prefix, - img_restricted_attrs); - + + ipool = new ImagePool(db, default_image_type, img_restricted_attrs); tpool = new VMTemplatePool(db); - dspool = new DatastorePool(db); } catch (exception&) diff --git a/src/nebula/NebulaTemplate.cc b/src/nebula/NebulaTemplate.cc index db998d2a17..4e216a105d 100644 --- a/src/nebula/NebulaTemplate.cc +++ b/src/nebula/NebulaTemplate.cc @@ -179,7 +179,6 @@ void OpenNebulaTemplate::set_conf_default() #******************************************************************************* # DATASTORE_LOCATION # DEFAULT_IMAGE_TYPE -# DEFAULT_DEVICE_PREFIX #******************************************************************************* */ //DATASTORE_LOCATION @@ -193,11 +192,6 @@ void OpenNebulaTemplate::set_conf_default() attribute = new SingleAttribute("DEFAULT_IMAGE_TYPE",value); conf_default.insert(make_pair(attribute->name(),attribute)); - //DEFAULT_DEVICE_PREFIX - value = "hd"; - - attribute = new SingleAttribute("DEFAULT_DEVICE_PREFIX",value); - conf_default.insert(make_pair(attribute->name(),attribute)); /* #******************************************************************************* # Auth Manager Configuration diff --git a/src/test/Nebula.cc b/src/test/Nebula.cc index 14684ebe4e..bd9a202997 100644 --- a/src/test/Nebula.cc +++ b/src/test/Nebula.cc @@ -243,9 +243,7 @@ void Nebula::start() if (tester->need_image_pool) { - ipool = tester->create_ipool(db, - default_image_type, - default_device_prefix); + ipool = tester->create_ipool(db, default_image_type); } if (tester->need_template_pool) diff --git a/src/test/NebulaTest.cc b/src/test/NebulaTest.cc index 1527e57982..0c1c9f04ae 100644 --- a/src/test/NebulaTest.cc +++ b/src/test/NebulaTest.cc @@ -44,12 +44,11 @@ UserPool* NebulaTest::create_upool(SqlDB* db) } ImagePool* NebulaTest::create_ipool( SqlDB* db, - string default_image_type, - string default_device_prefix) + string default_image_type) { vector restricted_attrs; - return new ImagePool(db, default_image_type, default_device_prefix, restricted_attrs); + return new ImagePool(db, default_image_type, restricted_attrs); } VMTemplatePool* NebulaTest::create_tpool(SqlDB* db) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 6b530500b2..d2bae041c9 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -376,13 +376,8 @@ int VirtualMachine::parse_context(string& error_str) if ( target.empty() ) { - Nebula& nd = Nebula::instance(); - string dev_prefix; - - nd.get_configuration_attribute("DEFAULT_DEVICE_PREFIX",dev_prefix); - dev_prefix += "b"; - - context_parsed->replace("TARGET", dev_prefix); + error_str = "Missing TARGET attribute in CONTEXT."; + return -1; } obj_template->set(context_parsed); @@ -860,21 +855,15 @@ int VirtualMachine::get_disk_images(string& error_str) VectorAttribute * disk; vector acquired_images; - int n_os = 0; // Number of OS images - int n_cd = 0; // Number of CDROMS - int n_db = 0; // Number of DATABLOCKS - string type; - int image_id; - - ostringstream oss; - Image::ImageType img_type; + int image_id; + ostringstream oss; Nebula& nd = Nebula::instance(); ipool = nd.get_ipool(); num_disks = obj_template->get("DISK",disks); - for(int i=0, index=0; i(disks[i]); @@ -883,48 +872,13 @@ int VirtualMachine::get_disk_images(string& error_str) continue; } - rc = ipool->disk_attribute(disk, - i, - &index, - &img_type, - uid, - image_id, - error_str); + rc = ipool->disk_attribute(disk, i, uid, image_id, error_str); + if (rc == 0 ) { acquired_images.push_back(image_id); - - switch(img_type) - { - case Image::OS: - n_os++; - break; - case Image::CDROM: - n_cd++; - break; - case Image::DATABLOCK: - n_db++; - break; - default: - break; - } - - if( n_os > 1 ) // Max. number of OS images is 1 - { - goto error_max_os; - } - - if( n_cd > 1 ) // Max. number of CDROM images is 1 - { - goto error_max_cd; - } - - if( n_db > 10 ) // Max. number of DATABLOCK images is 10 - { - goto error_max_db; - } } - else if ( rc == -1 ) + else { goto error_common; } @@ -932,18 +886,6 @@ int VirtualMachine::get_disk_images(string& error_str) return 0; -error_max_os: - error_str = "VM cannot use more than one OS image."; - goto error_common; - -error_max_cd: - error_str = "VM cannot use more than one CDROM image."; - goto error_common; - -error_max_db: - error_str = "VM cannot use more than 10 DATABLOCK images."; - goto error_common; - error_common: ImageManager * imagem = nd.get_imagem();