diff --git a/include/ImagePool.h b/include/ImagePool.h index 833a47e839..f834edd20e 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -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, diff --git a/src/image/Image.cc b/src/image/Image.cc index 31634aafee..27c43b5eab 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -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: diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index c84d3a4bf9..3ad57af60d 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -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 // --------------------------------------------------------------------- diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index f0e708801d..e081ffd061 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -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, diff --git a/src/rm/RequestManagerImage.cc b/src/rm/RequestManagerImage.cc index cc546d468f..baef45b6b8 100644 --- a/src/rm/RequestManagerImage.cc +++ b/src/rm/RequestManagerImage.cc @@ -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, diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index dda254281d..6c3523b9d8 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -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,