diff --git a/include/ImagePool.h b/include/ImagePool.h index 1d9f171b1b..dfab3ed669 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -20,6 +20,7 @@ #include "PoolSQL.h" #include "Image.h" #include "NebulaLog.h" +#include "Datastore.h" #include #include @@ -74,8 +75,9 @@ public: ImageTemplate * img_template, int ds_id, const string& ds_name, - Image::DiskType ds_type, + Image::DiskType disk_type, const string& ds_data, + Datastore::DatastoreType ds_type, int source_img_id, int * oid, string& error_str); diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 653174f37e..2122f4152b 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -63,18 +63,19 @@ 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, - Image::DiskType disk_type, - const string& ds_data, - int cloning_id, - 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, + Datastore::DatastoreType ds_type, + int cloning_id, + int * oid, + string& error_str) { Nebula& nd = Nebula::instance(); ImageManager * imagem = nd.get_imagem(); @@ -82,6 +83,7 @@ int ImagePool::allocate ( Image * img; Image * img_aux = 0; string name; + string type; ostringstream oss; img = new Image(uid, gid, uname, gname, img_template); @@ -101,6 +103,14 @@ int ImagePool::allocate ( goto error_name_length; } + img->get_template_attribute("TYPE", type); + + if ( ds_type == Datastore::FILE_DS && + img->str_to_type(type) != Image::DATAFILE ) + { + goto error_types_missmatch; + } + img_aux = get(name,uid,false); if( img_aux != 0 ) @@ -181,6 +191,10 @@ error_name_length: oss << "NAME is too long; max length is 128 chars."; goto error_common; +error_types_missmatch: + oss << "Only IMAGES of type FILE can be registered in FILE_DS Datastore"; + goto error_common; + error_duplicated: oss << "NAME is already taken by IMAGE " << img_aux->get_oid() << "."; diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index 2f590fb7b2..84dcd007c0 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -289,6 +289,8 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, string ds_name; string ds_data; + Datastore::DatastoreType ds_type; + int rc, id; PoolObjectAuth ds_perms; @@ -332,7 +334,9 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, return; } - if ( ds->get_type() == Datastore::SYSTEM_DS ) + ds_type = ds->get_type(); + + if ( ds_type == Datastore::SYSTEM_DS ) { ostringstream oss; @@ -448,6 +452,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, ds_name, ds_disk_type, ds_data, + ds_type, -1, &id, error_str); diff --git a/src/rm/RequestManagerImage.cc b/src/rm/RequestManagerImage.cc index 668a0f11c1..f6eb514dfc 100644 --- a/src/rm/RequestManagerImage.cc +++ b/src/rm/RequestManagerImage.cc @@ -182,7 +182,7 @@ void ImageClone::request_execute( Image * img; Datastore * ds; - Nebula& nd = Nebula::instance(); + Nebula& nd = Nebula::instance(); DatastorePool * dspool = nd.get_dspool(); ImagePool * ipool = static_cast(pool); @@ -200,8 +200,19 @@ void ImageClone::request_execute( return; } + if ( img->get_type() == Image::DATAFILE ) + { + failure_response(ACTION, + "Image of type FILE cannot be clonned", + att); + + img->unlock(); + + return; + } + tmpl = img->clone_template(name); - + img->get_permissions(perms); ds_id = img->get_ds_id(); @@ -224,6 +235,18 @@ void ImageClone::request_execute( return; } + if ( ds->get_type() == Datastore::FILE_DS ) + { + failure_response(ACTION, "Clone not supported for FILE_DS Datastores", + att); + + delete tmpl; + + ds->unlock(); + + return; + } + ds->get_permissions(ds_perms); disk_type = ds->get_disk_type(); @@ -233,7 +256,7 @@ void ImageClone::request_execute( ds->unlock(); // ------------- Set authorization request --------------------------------- - + img_usage.add("DATASTORE", ds_id); img_usage.add("SIZE", size); @@ -265,21 +288,22 @@ void ImageClone::request_execute( if ( quota_authorization(&img_usage, Quotas::DATASTORE, att) == false ) { delete tmpl; - return; - } + return; + } } - rc = ipool->allocate(att.uid, - att.gid, - att.uname, + rc = ipool->allocate(att.uid, + att.gid, + att.uname, att.gname, - tmpl, - ds_id, - ds_name, + tmpl, + ds_id, + ds_name, disk_type, - ds_data, - clone_id, - &new_id, + ds_data, + Datastore::IMAGE_DS, + clone_id, + &new_id, error_str); if ( rc < 0 ) { diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index d0265e8356..84408d0c24 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -725,6 +725,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis ds_name, ds_disk_type, ds_data, + Datastore::IMAGE_DS, -1, &iid, error_str);