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

Feature #3907: Improve the FSTYPE heuristic

This commit is contained in:
Jaime Melis 2016-05-06 15:03:22 +02:00
parent 6306af2059
commit 14c318b7b9
6 changed files with 66 additions and 19 deletions

View File

@ -86,6 +86,8 @@ public:
Image::DiskType disk_type,
const string& ds_data,
Datastore::DatastoreType ds_type,
const string& ds_mad,
const string& tm_mad,
const string& extra_data,
int source_img_id,
int * oid,

View File

@ -187,25 +187,11 @@ int Image::insert(SqlDB *db, string& error_str)
erase_template_attribute("PATH", path);
erase_template_attribute("SOURCE", source);
if (!is_saving()) //Not a saving image
if (!is_saving())
{
if ( source.empty() && path.empty() )
if ( source.empty() && path.empty() && type != DATABLOCK )
{
if (type != DATABLOCK)
{
goto error_no_path;
}
get_template_attribute("DRIVER", driver);
if (driver == "qcow2")
{
fs_type = "qcow2";
}
else
{
fs_type = "raw";
}
goto error_no_path;
}
else if ( !source.empty() && !path.empty() )
{
@ -228,7 +214,7 @@ int Image::insert(SqlDB *db, string& error_str)
return rc;
error_no_path:
error_str = "No PATH in template.";
error_str = "No PATH nor SOURCE in template.";
goto error_common;
error_path_and_source:

View File

@ -87,6 +87,8 @@ int ImagePool::allocate (
Image::DiskType disk_type,
const string& ds_data,
Datastore::DatastoreType ds_type,
const string& ds_mad,
const string& tm_mad,
const string& extra_data,
int cloning_id,
int * oid,
@ -99,6 +101,8 @@ int ImagePool::allocate (
Image * img_aux = 0;
string name;
string type;
string fs_type;
string driver;
ostringstream oss;
int rc;
@ -161,6 +165,45 @@ int ImagePool::allocate (
img->set_cloning_id(cloning_id);
}
// ---------------------------------------------------------------------
// Get FSTYPE
// ---------------------------------------------------------------------
img->get_template_attribute("FSTYPE", fs_type);
if (!fs_type.empty())
{
img->fs_type = fs_type;
}
else
{
img->get_template_attribute("DRIVER", driver);
if (!driver.empty())
{
// infer fs_type from driver
one_util::tolower(driver);
if (driver == "qcow2")
{
img->fs_type = "qcow2";
}
else
{
img->fs_type = "raw";
}
} else {
// no driver, infer ds_type from tm_mad
if (tm_mad == "qcow2")
{
img->fs_type = "qcow2";
}
else
{
img->fs_type = "raw";
}
}
}
// ---------------------------------------------------------------------
// Insert the Object in the pool & Register the image in the repository
// ---------------------------------------------------------------------

View File

@ -298,6 +298,8 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
string ds_name;
string ds_data;
string ds_mad;
string tm_mad;
bool ds_persistent_only;
@ -382,6 +384,8 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
ds_disk_type = ds->get_disk_type();
ds_check = ds->get_avail_mb(avail);
ds_persistent_only = ds->is_persistent_only();
ds_mad = ds->get_ds_mad();
tm_mad = ds->get_tm_mad();
ds->to_xml(ds_data);
@ -543,6 +547,8 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
ds_disk_type,
ds_data,
ds_type,
ds_mad,
tm_mad,
extra_data,
-1,
&id,

View File

@ -317,7 +317,7 @@ Request::ErrorCode ImageClone::request_execute(
{
long long avail, size;
int rc, ds_id_orig;
string ds_name, ds_data, ds_mad;
string ds_name, ds_data, ds_mad, tm_mad;
bool ds_check;
Image::DiskType disk_type;
@ -414,6 +414,7 @@ Request::ErrorCode ImageClone::request_execute(
ds_check = ds->get_avail_mb(avail);
ds_name = ds->get_name();
ds_mad = ds->get_ds_mad();
tm_mad = ds->get_tm_mad();
ds->unlock();
@ -520,6 +521,8 @@ Request::ErrorCode ImageClone::request_execute(
disk_type,
ds_data,
Datastore::IMAGE_DS,
ds_mad,
tm_mad,
"",
clone_id,
&new_id,

View File

@ -1333,6 +1333,9 @@ void VirtualMachineDiskSaveas::request_execute(
long long avail;
bool ds_check;
string ds_mad;
string tm_mad;
string driver;
string target;
string dev_prefix;
@ -1427,6 +1430,8 @@ void VirtualMachineDiskSaveas::request_execute(
ds_check = ds->get_avail_mb(avail);
ds_disk_type = ds->get_disk_type();
ds_mad = ds->get_ds_mad();
ds_mad = ds->get_tm_mad();
ds->unlock();
@ -1504,6 +1509,8 @@ void VirtualMachineDiskSaveas::request_execute(
ds_disk_type,
ds_data,
Datastore::IMAGE_DS,
ds_mad,
tm_mad,
"",
-1,
&iid,