1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-26 09:57:23 +03:00

feature #1617: New image types: KERNEL, RAMDISK and CONTEXT to store plain files for different uses.

This commit is contained in:
Ruben S. Montero 2012-12-04 23:19:08 +01:00
parent 332b6bf0ff
commit ff926f17d5
14 changed files with 239 additions and 117 deletions

View File

@ -38,7 +38,9 @@ public:
OS = 0, /** < Base OS image */
CDROM = 1, /** < An ISO9660 image */
DATABLOCK = 2, /** < User persistent data device */
DATAFILE = 3 /** < Context, kernels and initrd files */
KERNEL = 3, /** < Context, kernels and initrd files */
RAMDISK = 4, /** < Context, kernels and initrd files */
CONTEXT = 5 /** < Context, kernels and initrd files */
};
/**
@ -53,7 +55,9 @@ public:
case OS: return "OS" ; break;
case CDROM: return "CDROM" ; break;
case DATABLOCK: return "DATABLOCK" ; break;
case DATAFILE: return "FILE" ; break;
case KERNEL: return "KERNEL" ; break;
case RAMDISK: return "RAMDISK" ; break;
case CONTEXT: return "CONTEXT" ; break;
default: return "";
}
};

View File

@ -20,6 +20,7 @@
#include "VirtualMachineTemplate.h"
#include "PoolSQL.h"
#include "History.h"
#include "Image.h"
#include "Log.h"
#include "NebulaLog.h"
@ -1137,11 +1138,13 @@ private:
* INITRD files.
* @param os attribute of the VM template
* @param base_name of the attribute "KERNEL", or "INITRD"
* @param base_type of the image attribute KERNEL, RAMDISK
* @param error_str Returns the error reason, if any
* @return 0 on success
*/
int set_os_file(VectorAttribute * os,
const string& base_name,
Image::ImageType base_type,
string& error_str);
/**
* Parse the "OS" attribute of the template by substituting

View File

@ -76,12 +76,12 @@ cmd=CommandParser::CmdParser.new(ARGV) do
helper.filterflag_to_i(arg)
end
format(:type, 'Image type: OS, DATABLOCK or CDROM') do |arg|
format(:type, "Image type: #{Image::IMAGE_TYPES.join(", ")}") do |arg|
type=arg.strip.upcase
if %w{OS DATABLOCK CDROM}.include? type
if Image::IMAGE_TYPES.include? type
[0, type]
else
[1, "Image type not supported. Must be OS, DATABLOCK or CDROM."]
[1, "Image type not supported. Must be #{Image::IMAGE_TYPES.join(", ")}."]
end
end

View File

@ -128,37 +128,34 @@ int Image::insert(SqlDB *db, string& error_str)
goto error_type;
}
// ------------ PERSISTENT --------------------
// ------------ PERSISTENT & PREFIX --------------------
erase_template_attribute("PERSISTENT", persistent_attr);
if ( type != DATAFILE )
switch (type)
{
TO_UPPER(persistent_attr);
case OS:
case DATABLOCK:
case CDROM:
TO_UPPER(persistent_attr);
persistent_img = (persistent_attr == "YES");
persistent_img = (persistent_attr == "YES");
}
else // Files are always non-persistent
{
persistent_img = false;
}
get_template_attribute("DEV_PREFIX", dev_prefix);
// ------------ PREFIX --------------------
if ( type != DATAFILE )
{
get_template_attribute("DEV_PREFIX", dev_prefix);
if( dev_prefix.empty() )
{
SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX",
if( dev_prefix.empty() )
{
SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX",
ImagePool::default_dev_prefix());
obj_template->set(dev_att);
}
}
else // Do not set dev_prefix for files
{
erase_template_attribute("DEV_PREFIX", dev_prefix);
obj_template->set(dev_att);
}
break;
case KERNEL: // Files are always non-persistent with no dev_prefix
case RAMDISK:
case CONTEXT:
persistent_img = false;
erase_template_attribute("DEV_PREFIX", dev_prefix);
break;
}
// ------------ SIZE --------------------
@ -586,9 +583,17 @@ int Image::set_type(string& _type)
{
type = DATABLOCK;
}
else if ( _type == "FILE" )
else if ( _type == "KERNEL" )
{
type = DATAFILE;
type = KERNEL;
}
else if ( _type == "RAMDISK" )
{
type = RAMDISK;
}
else if ( _type == "CONTEXT" )
{
type = CONTEXT;
}
else
{
@ -651,9 +656,17 @@ Image::ImageType Image::str_to_type(string& str_type)
{
it = DATABLOCK;
}
else if ( str_type == "FILE" )
else if ( str_type == "KERNEL" )
{
it = DATAFILE;
it = KERNEL;
}
else if ( str_type == "RAMDISK" )
{
it = RAMDISK;
}
else if ( str_type == "CONTEXT" )
{
it = CONTEXT;
}
return it;

View File

@ -88,15 +88,24 @@ int ImageManager::acquire_image(int vm_id, Image *img, string& error)
{
int rc = 0;
if ( img->get_type() == Image::DATAFILE )
switch(img->get_type())
{
ostringstream oss;
case Image::OS:
case Image::DATABLOCK:
case Image::CDROM:
break;
oss << "Image " << img->get_oid() << " (" << img->get_name() << ") "
<< "of type FILE cannot be used as DISK.";
error = oss.str();
case Image::KERNEL:
case Image::RAMDISK:
case Image::CONTEXT:
ostringstream oss;
return -1;
oss << "Image " << img->get_oid() << " (" << img->get_name() << ") "
<< "of type " << Image::type_to_str(img->get_type())
<< " cannot be used as DISK.";
error = oss.str();
return -1;
}
switch (img->get_state())
@ -160,12 +169,20 @@ void ImageManager::release_image(int vm_id, int iid, bool failed)
return;
}
if ( img->get_type() == Image::DATAFILE )
switch(img->get_type())
{
NebulaLog::log("ImM", Log::ERROR, "Trying to release a FILE image");
case Image::OS:
case Image::DATABLOCK:
case Image::CDROM:
break;
img->unlock();
return;
case Image::KERNEL:
case Image::RAMDISK:
case Image::CONTEXT:
NebulaLog::log("ImM", Log::ERROR, "Trying to release a KERNEL, "
"RAMDISK or CONTEXT image");
img->unlock();
return;
}
switch (img->get_state())
@ -257,12 +274,20 @@ void ImageManager::release_cloning_image(int iid, int clone_img_id)
return;
}
if ( img->get_type() == Image::DATAFILE )
switch(img->get_type())
{
NebulaLog::log("ImM", Log::ERROR, "Trying to release a cloning FILE image");
case Image::OS:
case Image::DATABLOCK:
case Image::CDROM:
break;
img->unlock();
return;
case Image::KERNEL:
case Image::RAMDISK:
case Image::CONTEXT:
NebulaLog::log("ImM", Log::ERROR, "Trying to release a cloning "
"KERNEL, RAMDISK or CONTEXT image");
img->unlock();
return;
}
switch (img->get_state())
@ -709,7 +734,9 @@ int ImageManager::stat_image(Template* img_tmpl,
{
case Image::OS:
case Image::CDROM:
case Image::DATAFILE:
case Image::KERNEL:
case Image::RAMDISK:
case Image::CONTEXT:
img_tmpl->get("SOURCE", res);
if (!res.empty())

View File

@ -105,16 +105,25 @@ int ImagePool::allocate (
img->get_template_attribute("TYPE", type);
if ( ds_type == Datastore::FILE_DS &&
img->str_to_type(type) != Image::DATAFILE )
switch (img->str_to_type(type))
{
goto error_types_missmatch_file;
}
case Image::OS:
case Image::DATABLOCK:
case Image::CDROM:
if ( ds_type != Datastore::IMAGE_DS )
{
goto error_types_missmatch_file;
}
break;
if ( ds_type == Datastore::IMAGE_DS &&
img->str_to_type(type) == Image::DATAFILE )
{
goto error_types_missmatch_image;
case Image::KERNEL:
case Image::RAMDISK:
case Image::CONTEXT:
if ( ds_type != Datastore::FILE_DS )
{
goto error_types_missmatch_image;
}
break;
}
img_aux = get(name,uid,false);
@ -197,11 +206,13 @@ error_name_length:
goto error_common;
error_types_missmatch_file:
oss << "Only IMAGES of type FILE can be registered in a FILE_DS datastore";
oss << "Only IMAGES of type KERNEL, RAMDISK and CONTEXT can be registered"
" in a FILE_DS datastore";
goto error_common;
error_types_missmatch_image:
oss << "IMAGES of type FILE cannot be registered in a IMAGE_DS datastore";
oss << "IMAGES of type KERNEL, RAMDISK and CONTEXT cannot be registered"
" in a IMAGE_DS datastore";
goto error_common;
error_duplicated:

View File

@ -47,10 +47,10 @@ public class Image extends PoolElement
{"init", "rdy", "used", "disa", "lock", "err", "clon", "dele", "used"};
private static final String[] IMAGE_TYPES =
{"OS", "CDROM", "DATABLOCK", "FILE"};
{"OS", "CDROM", "DATABLOCK", "KERNEL", "RAMDISK", "CONTEXT"};
private static final String[] SHORT_IMAGE_TYPES =
{"OS", "CD", "DB", "FL"};
{"OS", "CD", "DB", "KL", "RD", "CX"};
/**
* Creates a new Image representation.

View File

@ -52,13 +52,15 @@ module OpenNebula
"USED_PERS" => "used"
}
IMAGE_TYPES=%w{OS CDROM DATABLOCK FILE}
IMAGE_TYPES=%w{OS CDROM DATABLOCK KERNEL RAMDISK CONTEXT}
SHORT_IMAGE_TYPES={
"OS" => "OS",
"CDROM" => "CD",
"DATABLOCK" => "DB",
"FILE" => "FL"
"KERNEL" => "KL",
"RAMDISK" => "RD",
"CONTEXT" => "CX"
}
# Creates an Image description with just its identifier

View File

@ -87,12 +87,20 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
if ( image->get_type() == Image::DATAFILE )
switch (image->get_type())
{
failure_response(ACTION,
request_error("FILE images must be non-persistent",""), att);
case Image::OS:
case Image::DATABLOCK:
case Image::CDROM:
break;
image->unlock();
case Image::KERNEL:
case Image::RAMDISK:
case Image::CONTEXT:
failure_response(ACTION,
request_error("KERNEL, RAMDISK and CONTEXT files must be "
"non-persistent",""), att);
image->unlock();
return;
}
@ -132,6 +140,8 @@ void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList,
string type = xmlrpc_c::value_string(paramList.getString(2));
int rc;
Image::ImageType itype;
Image * image;
string err_msg;
@ -151,15 +161,43 @@ void ImageChangeType::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
if ( image->get_type() == Image::DATAFILE )
{
failure_response(ACTION,
request_error("Only FILE images can be stored in a FILE_DS"
" datastore.",""),
att);
itype = Image::str_to_type(type);
image->unlock();
return;
switch (image->get_type())
{
case Image::OS:
case Image::DATABLOCK:
case Image::CDROM:
if ((itype != Image::OS) &&
(itype != Image::DATABLOCK)&&
(itype != Image::CDROM) )
{
failure_response(ACTION,
request_error("Cannot change image type to an incompatible"
" type for the current datastore.",""),
att);
image->unlock();
return;
}
break;
case Image::KERNEL:
case Image::RAMDISK:
case Image::CONTEXT:
if ((itype != Image::KERNEL) &&
(itype != Image::RAMDISK)&&
(itype != Image::CONTEXT) )
{
failure_response(ACTION,
request_error("Cannot change image type to an incompatible"
" type for the current datastore.",""),
att);
image->unlock();
return;
}
break;
}
rc = image->set_type(type);
@ -220,14 +258,20 @@ void ImageClone::request_execute(
return;
}
if ( img->get_type() == Image::DATAFILE )
switch (img->get_type())
{
failure_response(ACTION,
allocate_error("Image of type FILE cannot be clonned"),
att);
img->unlock();
case Image::OS:
case Image::DATABLOCK:
case Image::CDROM:
break;
case Image::KERNEL:
case Image::RAMDISK:
case Image::CONTEXT:
failure_response(ACTION,
allocate_error("KERNEL, RAMDISK and CONTEXT files cannot be "
"clonned."), att);
img->unlock();
return;
}

View File

@ -641,11 +641,19 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
return;
}
if ( type == Image::DATAFILE )
switch (type)
{
failure_response(INTERNAL,
request_error("Cannot save_as image of type FILE", ""),
att);
case Image::OS:
case Image::DATABLOCK:
case Image::CDROM:
break;
case Image::KERNEL:
case Image::RAMDISK:
case Image::CONTEXT:
failure_response(INTERNAL,
request_error("Cannot save_as image of type FILE", ""),
att);
return;
}

View File

@ -390,6 +390,7 @@ error_common:
int VirtualMachine::set_os_file(VectorAttribute * os,
const string& base_name,
Image::ImageType base_type,
string& error_str)
{
vector<int> img_ids;
@ -398,6 +399,8 @@ int VirtualMachine::set_os_file(VectorAttribute * os,
ImagePool * ipool = nd.get_ipool();
Image * img = 0;
Image::ImageType type;
DatastorePool * ds_pool = nd.get_dspool();
Datastore * ds;
int ds_id;
@ -437,6 +440,7 @@ int VirtualMachine::set_os_file(VectorAttribute * os,
}
ds_id = img->get_ds_id();
type = img->get_type();
os->remove(base_name);
@ -446,6 +450,18 @@ int VirtualMachine::set_os_file(VectorAttribute * os,
img->unlock();
if ( type != base_type )
{
ostringstream oss;
oss << base_name << " needs an image of type "
<< Image::type_to_str(base_type) << " and not "
<< Image::type_to_str(type);
error_str = oss.str();
return -1;
}
ds = ds_pool->get(ds_id, true);
if ( ds == 0 )
@ -496,14 +512,14 @@ int VirtualMachine::parse_os(string& error_str)
return -1;
}
rc = set_os_file(os, "KERNEL", error_str);
rc = set_os_file(os, "KERNEL", Image::KERNEL, error_str);
if ( rc != 0 )
{
return -1;
}
rc = set_os_file(os, "INITRD", error_str);
rc = set_os_file(os, "INITRD", Image::RAMDISK, error_str);
if ( rc != 0 )
{
@ -608,6 +624,8 @@ int VirtualMachine::parse_context(string& error_str)
ImagePool * ipool = nd.get_ipool();
Image * img = 0;
Image::ImageType type;
for ( it=img_ids.begin() ; it < img_ids.end(); it++ )
{
img = ipool->get(*it, true);
@ -615,8 +633,16 @@ int VirtualMachine::parse_context(string& error_str)
if ( img != 0 )
{
oss_parsed << img->get_source() << " ";
type = img->get_type();
img->unlock();
if (type != Image::CONTEXT)
{
error_str = "Only images of type CONTEXT can be used in"
" FILE_DS attribute.";
return -1;
}
}
}
}

View File

@ -196,14 +196,6 @@ int get_image_path(VirtualMachine * vm,
img->get_permissions(perm);
if ( img->get_type() != Image::DATAFILE )
{
error_str = "FILE variables must use images of type FILE.";
img->unlock();
return -1;
}
img->unlock();
AuthRequest ar(vm->get_uid(), vm->get_gid());
@ -226,7 +218,7 @@ int get_image_path(VirtualMachine * vm,
/* Line 360 of yacc.c */
#line 230 "vm_file_var_syntax.cc"
#line 222 "vm_file_var_syntax.cc"
# ifndef YY_NULL
# if defined __cplusplus && 201103L <= __cplusplus
@ -279,7 +271,7 @@ extern int vm_file_var__debug;
typedef union YYSTYPE
{
/* Line 376 of yacc.c */
#line 178 "vm_file_var_syntax.y"
#line 170 "vm_file_var_syntax.y"
char * val_str;
int val_int;
@ -287,7 +279,7 @@ typedef union YYSTYPE
/* Line 376 of yacc.c */
#line 291 "vm_file_var_syntax.cc"
#line 283 "vm_file_var_syntax.cc"
} YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
@ -327,7 +319,7 @@ int vm_file_var__parse ();
/* Copy the second part of user declarations. */
/* Line 379 of yacc.c */
#line 331 "vm_file_var_syntax.cc"
#line 323 "vm_file_var_syntax.cc"
#ifdef short
# undef short
@ -618,7 +610,7 @@ static const yytype_int8 yyrhs[] =
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
static const yytype_uint8 yyrline[] =
{
0, 202, 202, 203, 207, 225
0, 194, 194, 195, 199, 217
};
#endif
@ -1626,7 +1618,7 @@ yyreduce:
{
case 4:
/* Line 1778 of yacc.c */
#line 208 "vm_file_var_syntax.y"
#line 200 "vm_file_var_syntax.y"
{
string file((yyvsp[(1) - (7)].val_str));
string var1((yyvsp[(3) - (7)].val_str));
@ -1648,7 +1640,7 @@ yyreduce:
case 5:
/* Line 1778 of yacc.c */
#line 226 "vm_file_var_syntax.y"
#line 218 "vm_file_var_syntax.y"
{
string file((yyvsp[(1) - (11)].val_str));
string var1((yyvsp[(3) - (11)].val_str));
@ -1673,7 +1665,7 @@ yyreduce:
/* Line 1778 of yacc.c */
#line 1677 "vm_file_var_syntax.cc"
#line 1669 "vm_file_var_syntax.cc"
default: break;
}
/* User semantic actions sometimes alter yychar, and that requires
@ -1912,7 +1904,7 @@ yyreturn:
/* Line 2041 of yacc.c */
#line 247 "vm_file_var_syntax.y"
#line 239 "vm_file_var_syntax.y"
extern "C" void vm_file_var__error(

View File

@ -1,19 +1,19 @@
/* A Bison parser, made by GNU Bison 2.6.5. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2012 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
@ -26,7 +26,7 @@
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
@ -63,7 +63,7 @@ extern int vm_file_var__debug;
typedef union YYSTYPE
{
/* Line 2042 of yacc.c */
#line 178 "vm_file_var_syntax.y"
#line 170 "vm_file_var_syntax.y"
char * val_str;
int val_int;

View File

@ -138,14 +138,6 @@ int get_image_path(VirtualMachine * vm,
img->get_permissions(perm);
if ( img->get_type() != Image::DATAFILE )
{
error_str = "FILE variables must use images of type FILE.";
img->unlock();
return -1;
}
img->unlock();
AuthRequest ar(vm->get_uid(), vm->get_gid());