1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

Bug #1232: Bring back part of commit:e401b49 : Only allow Datastore & volatile disks.

This commit is contained in:
Carlos Martín 2012-04-25 17:12:16 +02:00
parent f0c1641fdc
commit 7da6c9883e
3 changed files with 33 additions and 24 deletions

View File

@ -441,12 +441,12 @@ int Image::disk_attribute( VectorAttribute * disk,
int * index,
ImageType* img_type)
{
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");
@ -459,7 +459,7 @@ int Image::disk_attribute( VectorAttribute * disk,
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);
@ -473,7 +473,6 @@ int Image::disk_attribute( VectorAttribute * disk,
//---------------------------------------------------------------------------
// BASE DISK ATTRIBUTES
//---------------------------------------------------------------------------
disk->replace("IMAGE", name);
disk->replace("IMAGE_ID", iid.str());
disk->replace("SOURCE", source);
@ -491,7 +490,6 @@ int Image::disk_attribute( VectorAttribute * disk,
//---------------------------------------------------------------------------
// TYPE, READONLY, CLONE, and SAVE attributes
//---------------------------------------------------------------------------
if ( persistent_img )
{
disk->replace("CLONE","NO");
@ -518,7 +516,6 @@ int Image::disk_attribute( VectorAttribute * disk,
break;
}
disk->replace("TYPE",disk_attr_type);
//---------------------------------------------------------------------------

View File

@ -191,6 +191,7 @@ void ImageManager::release_image(int iid, bool failed)
img->unlock();
break;
case Image::DISABLED:
case Image::READY:
case Image::ERROR:

View File

@ -226,6 +226,7 @@ int ImagePool::disk_attribute(VectorAttribute * disk,
Image * img = 0;
int rc = 0;
int datastore_id;
int iid;
ostringstream oss;
@ -248,10 +249,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 +269,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 +297,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, index, img_type);
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;
}