1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Bug: Add support for BLOCK disk types. Datastore supports a new attribute DISK_TYPE that is inherited by

the IMAGE and subsequent DISKs in VM templates. By default the FILE type is used
This commit is contained in:
Ruben S. Montero 2012-04-19 11:44:19 +02:00
parent ef459eac2b
commit 62a9ebe555
8 changed files with 123 additions and 31 deletions

View File

@ -21,6 +21,7 @@
#include "ObjectCollection.h"
#include "DatastoreTemplate.h"
#include "Clusterable.h"
#include "Image.h"
/**
* The Datastore class.
@ -82,6 +83,14 @@ public:
return base_path;
};
/**
* Retrieves the disk type
* @return disk type
*/
Image::DiskType get_disk_type() const
{
return disk_type;
};
/**
* Modifies the given VM disk attribute adding the relevant datastore
* attributes
@ -125,6 +134,11 @@ private:
*/
string base_path;
/**
* Disk types for the Images created in this datastore
*/
Image::DiskType disk_type;
// *************************************************************************
// Constructor
// *************************************************************************

View File

@ -55,6 +55,33 @@ public:
}
};
/**
* Type of Disks (used by the VMM_MAD). Values: BLOCK, CDROM or
* FILE
*/
enum DiskType
{
FILE = 0, /** < File-based disk */
CD_ROM = 1, /** < An ISO9660 disk */
BLOCK = 2 /** < Block-device disk */
};
/**
* Return the string representation of a DiskType
* @param ob the type
* @return the string
*/
static string disk_type_to_str(DiskType ob)
{
switch (ob)
{
case FILE: return "FILE" ; break;
case CD_ROM: return "CDROM" ; break;
case BLOCK: return "BLOCK" ; break;
default: return "";
}
};
/**
* Image State
*/
@ -356,6 +383,11 @@ private:
*/
ImageType type;
/**
* Type for the Disk
*/
DiskType disk_type;
/**
* Persistency of the Image
*/

View File

@ -54,6 +54,7 @@ public:
* @param img_template template associated with the image
* @param ds_id the id of the datastore
* @param ds_name the name of the datastore
* @param ds_type disk type for the image
* @param ds_data the datastore data
* @param oid the id assigned to the Image
* @param error_str Returns the error reason, if any
@ -69,6 +70,7 @@ public:
ImageTemplate * img_template,
int ds_id,
const string& ds_name,
Image::DiskType ds_type,
const string& ds_data,
int * oid,
string& error_str);

View File

@ -96,6 +96,7 @@ int Datastore::insert(SqlDB *db, string& error_str)
{
int rc;
ostringstream oss;
string s_disk_type;
Nebula& nd = Nebula::instance();
@ -124,6 +125,25 @@ int Datastore::insert(SqlDB *db, string& error_str)
base_path = oss.str();
get_template_attribute("DISK_TYPE", s_disk_type);
if (s_disk_type == "BLOCK")
{
disk_type = Image::BLOCK;
}
else if (s_disk_type == "CDROM")
{
disk_type = Image::CD_ROM;
}
else
{
disk_type = Image::FILE;
}
if ( tm_mad.empty() == true )
{
goto error_tm;
}
//--------------------------------------------------------------------------
// Insert the Datastore
//--------------------------------------------------------------------------
@ -253,6 +273,7 @@ string& Datastore::to_xml(string& xml) const
"<DS_MAD>" << ds_mad << "</DS_MAD>" <<
"<TM_MAD>" << tm_mad << "</TM_MAD>" <<
"<BASE_PATH>" << base_path << "</BASE_PATH>" <<
"<DISK_TYPE>" << disk_type << "</DISK_TYPE>" <<
"<CLUSTER_ID>" << cluster_id << "</CLUSTER_ID>" <<
"<CLUSTER>" << cluster << "</CLUSTER>" <<
collection_xml <<
@ -270,21 +291,23 @@ string& Datastore::to_xml(string& xml) const
int Datastore::from_xml(const string& xml)
{
int rc = 0;
int int_disk_type;
vector<xmlNodePtr> content;
// Initialize the internal XML object
update_from_str(xml);
// Get class base attributes
rc += xpath(oid, "/DATASTORE/ID", -1);
rc += xpath(uid, "/DATASTORE/UID", -1);
rc += xpath(gid, "/DATASTORE/GID", -1);
rc += xpath(uname, "/DATASTORE/UNAME", "not_found");
rc += xpath(gname, "/DATASTORE/GNAME", "not_found");
rc += xpath(name, "/DATASTORE/NAME", "not_found");
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(oid, "/DATASTORE/ID", -1);
rc += xpath(uid, "/DATASTORE/UID", -1);
rc += xpath(gid, "/DATASTORE/GID", -1);
rc += xpath(uname, "/DATASTORE/UNAME", "not_found");
rc += xpath(gname, "/DATASTORE/GNAME", "not_found");
rc += xpath(name, "/DATASTORE/NAME", "not_found");
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(int_disk_type,"/DATASTORE/DISK_TYPE", -1);
rc += xpath(cluster_id, "/DATASTORE/CLUSTER_ID", -1);
rc += xpath(cluster, "/DATASTORE/CLUSTER", "not_found");
@ -292,6 +315,8 @@ int Datastore::from_xml(const string& xml)
// Permissions
rc += perms_from_xml();
disk_type = static_cast<Image::DiskType>(int_disk_type);
// Get associated classes
ObjectXML::get_nodes("/DATASTORE/IMAGES", content);

View File

@ -41,6 +41,7 @@ Image::Image(int _uid,
ImageTemplate * _image_template):
PoolObjectSQL(-1,IMAGE,"",_uid,_gid,_uname,_gname,table),
type(OS),
disk_type(FILE),
regtime(time(0)),
source(""),
path(""),
@ -345,6 +346,7 @@ string& Image::to_xml(string& xml) const
"<NAME>" << name << "</NAME>" <<
perms_to_xml(perms_xml) <<
"<TYPE>" << type << "</TYPE>" <<
"<DISK_TYPE>" << disk_type << "</DISK_TYPE>" <<
"<PERSISTENT>" << persistent_img << "</PERSISTENT>" <<
"<REGTIME>" << regtime << "</REGTIME>" <<
"<SOURCE>" << source << "</SOURCE>" <<
@ -371,6 +373,7 @@ int Image::from_xml(const string& xml)
vector<xmlNodePtr> content;
int int_state;
int int_type;
int int_disk_type;
int rc = 0;
@ -388,6 +391,7 @@ int Image::from_xml(const string& xml)
rc += xpath(name, "/IMAGE/NAME", "not_found");
rc += xpath(int_type, "/IMAGE/TYPE", 0);
rc += xpath(int_disk_type, "/IMAGE/DISK_TYPE", 0);
rc += xpath(persistent_img, "/IMAGE/PERSISTENT", 0);
rc += xpath(regtime, "/IMAGE/REGTIME", 0);
@ -406,8 +410,9 @@ int Image::from_xml(const string& xml)
xpath(path,"/IMAGE/PATH", "");
xpath(fs_type,"/IMAGE/FSTYPE","");
type = static_cast<ImageType>(int_type);
state = static_cast<ImageState>(int_state);
type = static_cast<ImageType>(int_type);
disk_type = static_cast<DiskType>(int_disk_type);
state = static_cast<ImageState>(int_state);
// Get associated classes
ObjectXML::get_nodes("/IMAGE/TEMPLATE", content);
@ -439,6 +444,7 @@ int Image::disk_attribute( VectorAttribute * disk,
string bus;
string target;
string driver;
string disk_attr_type;
ostringstream iid;
@ -501,17 +507,20 @@ int Image::disk_attribute( VectorAttribute * disk,
switch(type)
{
case OS:
case DATABLOCK:
disk->replace("TYPE","DISK");
case DATABLOCK: //Type is FILE or BLOCK as inherited from the DS
disk_attr_type = disk_type_to_str(disk_type);
disk->replace("READONLY","NO");
break;
case CDROM:
disk->replace("TYPE","CDROM");
case CDROM: //Always use CDROM type for these ones
disk_attr_type = "CDROM"
disk->replace("READONLY","YES");
break;
}
disk->replace("TYPE",disk_attr_type);
//---------------------------------------------------------------------------
// TARGET attribute
//---------------------------------------------------------------------------

View File

@ -60,16 +60,17 @@ ImagePool::ImagePool(SqlDB * db,
/* -------------------------------------------------------------------------- */
int ImagePool::allocate (
int uid,
int gid,
const string& uname,
const string& gname,
ImageTemplate* img_template,
int ds_id,
const string& ds_name,
const string& ds_data,
int * oid,
string& error_str)
int uid,
int gid,
const string& uname,
const string& gname,
ImageTemplate* img_template,
int ds_id,
const string& ds_name,
Image::DiskType disk_type,
const string& ds_data,
int * oid,
string& error_str)
{
Image * img;
Image * img_aux = 0;
@ -102,6 +103,8 @@ int ImagePool::allocate (
img->ds_name = ds_name;
img->ds_id = ds_id;
img->disk_type = disk_type;
// ---------------------------------------------------------------------
// Insert the Object in the pool & Register the image in the repository

View File

@ -313,6 +313,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
ImageTemplate * tmpl = new ImageTemplate;
Datastore * ds;
Image::DiskType ds_disk_type;
// ------------------------- Parse image template --------------------------
@ -351,7 +352,8 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
ds->get_permissions(ds_perms);
ds_name = ds->get_name();
ds_name = ds->get_name();
ds_disk_type = ds->get_disk_type();
ds->to_xml(ds_data);
@ -387,7 +389,8 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
att.gname,
tmpl,
ds_id,
ds_name,
ds_name,
ds_disk_type,
ds_data,
&id,
error_str);

View File

@ -417,6 +417,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
Image * img;
Datastore * ds;
Image::DiskType ds_disk_type;
int rc;
string error_str;
@ -485,6 +486,8 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
ds->get_permissions(ds_perms);
ds->to_xml(ds_data);
ds_disk_type = ds->get_disk_type();
ds->unlock();
@ -535,10 +538,11 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
att.uname,
att.gname,
itemplate,
ds_id,
ds_name,
ds_data,
&iid,
ds_id,
ds_name,
ds_disk_type,
ds_data,
&iid,
error_str);
if (rc < 0)
{