diff --git a/include/Datastore.h b/include/Datastore.h index 2b03953032..fe134af97e 100644 --- a/include/Datastore.h +++ b/include/Datastore.h @@ -29,6 +29,38 @@ class Datastore : public PoolObjectSQL, ObjectCollection, public Clusterable { public: + /** + * Type of Datastore + */ + enum DatastoreType + { + IMAGE_DS = 0, /** < Standard datastore for disk images */ + SYSTEM_DS = 1, /** < System datastore for disks of running VMs */ + FILE_DS = 2 /** < File datastore for context, kernel, initrd files */ + }; + + /** + * Return the string representation of an DatastoreType + * @param ob the type + * @return the string + */ + static string type_to_str(DatastoreType ob) + { + switch (ob) + { + case IMAGE_DS: return "IMAGE_DS" ; break; + case SYSTEM_DS: return "SYSTEM_DS" ; break; + case FILE_DS: return "FILE_DS" ; break; + default: return ""; + } + }; + + /** + * Return the string representation of an DatastoreType + * @param str_type string representing the DatastoreTypr + * @return the ImageType (defaults to IMAGE_DS) + */ + static DatastoreType str_to_type(string& str_type); /** * Function to print the Datastore object into a string in XML format @@ -93,12 +125,12 @@ public: }; /** - * Returns true if this is a system datastore - * @return true if this is a system datastore + * Returns the datastore type + * @return datastore type */ - bool is_system() const + DatastoreType get_type() const { - return system_ds == 1; + return type; }; /** @@ -145,9 +177,9 @@ private: string base_path; /** - * 1 if this is a system DS + * The datastore type */ - int system_ds; + DatastoreType type; /** * Disk types for the Images created in this datastore diff --git a/include/DatastorePool.h b/include/DatastorePool.h index 294af9512d..07d607a749 100644 --- a/include/DatastorePool.h +++ b/include/DatastorePool.h @@ -54,6 +54,16 @@ public: */ static const int DEFAULT_DS_ID; + /** + * Name for the file datastore + */ + static const string FILE_DS_NAME; + + /** + * Identifier for the file datastore + */ + static const int FILE_DS_ID; + /* ---------------------------------------------------------------------- */ /* Methods for DB management */ /* ---------------------------------------------------------------------- */ diff --git a/include/Image.h b/include/Image.h index 4206f48b93..48ee9c670a 100644 --- a/include/Image.h +++ b/include/Image.h @@ -37,7 +37,8 @@ public: { OS = 0, /** < Base OS image */ CDROM = 1, /** < An ISO9660 image */ - DATABLOCK = 2 /** < User persistent data device */ + DATABLOCK = 2, /** < User persistent data device */ + DATAFILE = 3 /** < Context, kernels and initrd files */ }; /** @@ -52,6 +53,7 @@ public: case OS: return "OS" ; break; case CDROM: return "CDROM" ; break; case DATABLOCK: return "DATABLOCK" ; break; + case DATAFILE: return "FILE" ; break; default: return ""; } }; diff --git a/include/ImagePool.h b/include/ImagePool.h index 1d9f171b1b..a2ef77a4e1 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 @@ -58,6 +59,7 @@ public: * @param ds_name the name of the datastore * @param ds_type disk type for the image * @param ds_data the datastore data + * @param ds_type the datastore type * @param source_img_id If the new Image is a clone, this must be the * source Image ID. Otherwise, it must be set to -1 * @param oid the id assigned to the Image @@ -67,18 +69,19 @@ public: * -2 in case of template parse failure */ int allocate ( - int uid, - int gid, - const string& uname, - const string& gname, - ImageTemplate * img_template, - int ds_id, - const string& ds_name, - Image::DiskType ds_type, - const string& ds_data, - int source_img_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 source_img_id, + int * oid, + string& error_str); /** ** Function to get a Image from the pool, if the object is not in memory @@ -177,6 +180,21 @@ public: return _default_dev_prefix; }; + /** + * Get the effective uid to get an image. Used in VM parsers + * @param disk a vector attribute with the image data + * @param uid default uid + * @return the uid to get the image; + */ + static int get_disk_uid(VectorAttribute * disk, int _uid); + + /** + * Get the disk id based on its string representation. Used in VM parsers + * @param id_s the string id + * @return the id in int form + */ + static int get_disk_id(const string& id_s); + private: //-------------------------------------------------------------------------- // Configuration Attributes for Images diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index b9a528ce8b..9b8ef879f8 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -220,6 +220,50 @@ public: etime = et; }; + /** + * Sets the KERNEL OS attribute (path to the kernel file). Used when + * the template is using a FILE Datastore for it + * @param path to the kernel (in the remote host) + */ + void set_kernel(const string& kernel) + { + vector os_attr; + VectorAttribute * os; + + int num = obj_template->get("OS", os_attr); + + if ( num == 0 ) + { + return; + } + + os = dynamic_cast(os_attr[0]); + + os->replace("KERNEL", kernel); + }; + + /** + * Sets the INITRD OS attribute (path to the initrd file). Used when + * the template is using a FILE Datastore for it + * @param path to the initrd (in the remote host) + */ + void set_initrd(const string& initrd) + { + vector os_attr; + VectorAttribute * os; + + int num = obj_template->get("OS", os_attr); + + if ( num == 0 ) + { + return; + } + + os = dynamic_cast(os_attr[0]); + + os->replace("INITRD", initrd); + }; + // ------------------------------------------------------------------------ // Access to VM locations // ------------------------------------------------------------------------ @@ -620,9 +664,24 @@ public: * template values: * @param attribute, the string to be parsed * @param parsed, the resulting parsed string + * @param error description in case of failure * @return 0 on success. */ - int parse_template_attribute(const string& attribute, string& parsed); + int parse_template_attribute(const string& attribute, + string& parsed, + string& error); + + /** + * Parse a file string variable (i.e. $FILE) using the FILE_DS datastores. + * It should be used for OS/DS_KERNEL, OS/DS_INITRD, CONTEXT/DS_FILES. + * @param attribute the string to be parsed + * @param img_ids ids of the FILE images in the attribute + * @param error description in case of failure + * @return 0 on success. + */ + int parse_file_attribute(string attribute, + vector& img_ids, + string& error); /** * Factory method for virtual machine templates @@ -1073,6 +1132,25 @@ private: */ static pthread_mutex_t lex_mutex; + /** + * Generates image attributes (DS_ID, TM_MAD, SOURCE...) for KERNEL and + * INITRD files. + * @param os attribute of the VM template + * @param base_name of the attribute "KERNEL", or "INITRD" + * @param error_str Returns the error reason, if any + * @return 0 on success + */ + int set_os_file(VectorAttribute * os, + const string& base_name, + string& error_str); + /** + * Parse the "OS" attribute of the template by substituting + * $FILE variables + * @param error_str Returns the error reason, if any + * @return 0 on success + */ + int parse_os(string& error_str); + /** * Parse the "CONTEXT" attribute of the template by substituting * $VARIABLE, $VARIABLE[ATTR] and $VARIABLE[ATTR, ATTR = VALUE] diff --git a/src/cli/etc/onedatastore.yaml b/src/cli/etc/onedatastore.yaml index 4a1e5b89f8..ee1fe3be79 100644 --- a/src/cli/etc/onedatastore.yaml +++ b/src/cli/etc/onedatastore.yaml @@ -1,23 +1,28 @@ ---- -:ID: +--- +:ID: :desc: ONE identifier for the Datastore :size: 4 -:NAME: +:NAME: :desc: Name of the Datastore :size: 25 :left: true -:CLUSTER: +:CLUSTER: :desc: Name of the Cluster :size: 15 :left: true -:IMAGES: +:IMAGES: :desc: Number of Images :size: 6 :TYPE: + :desc: Datastore type + :size: 4 + :left: true + +:DS: :desc: Datastore driver :size: 8 :left: true @@ -33,5 +38,6 @@ - :CLUSTER - :IMAGES - :TYPE +- :DS - :TM diff --git a/src/cli/one_helper/onedatastore_helper.rb b/src/cli/one_helper/onedatastore_helper.rb index d8495bfa71..3123cf18f0 100644 --- a/src/cli/one_helper/onedatastore_helper.rb +++ b/src/cli/one_helper/onedatastore_helper.rb @@ -60,7 +60,12 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper end end - column :TYPE, "Datastore driver", :left, :size=>8 do |d| + column :TYPE, "Datastore type", :left, :size=>4 do |d| + type = Datastore::DATASTORE_TYPES[d["TYPE"].to_i] + Datastore::SHORT_DATASTORE_TYPES[type] + end + + column :DS, "Datastore driver", :left, :size=>8 do |d| d["DS_MAD"] end @@ -68,7 +73,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper d["TM_MAD"] end - default :ID, :NAME, :CLUSTER, :IMAGES, :TYPE, :TM + default :ID, :NAME, :CLUSTER, :IMAGES, :TYPE, :DS, :TM end table @@ -101,6 +106,7 @@ class OneDatastoreHelper < OpenNebulaHelper::OneHelper puts str % ["GROUP", datastore['GNAME']] puts str % ["CLUSTER", OpenNebulaHelper.cluster_str(datastore['CLUSTER'])] + puts str % ["TYPE", datastore.type_str] puts str % ["DS_MAD", datastore['DS_MAD']] puts str % ["TM_MAD", datastore['TM_MAD']] puts str % ["BASE PATH",datastore['BASE_PATH']] diff --git a/src/cli/one_helper/oneimage_helper.rb b/src/cli/one_helper/oneimage_helper.rb index 44bc84c3b5..0fa428f12e 100644 --- a/src/cli/one_helper/oneimage_helper.rb +++ b/src/cli/one_helper/oneimage_helper.rb @@ -34,14 +34,14 @@ class OneImageHelper < OpenNebulaHelper::OneHelper :name => "type", :large => "--type type", :format => String, - :description => "Type of the new Image: OS, CDROM or DATABLOCK", + :description => "Type of the new Image: #{Image::IMAGE_TYPES.join(", ")}", :proc => lambda do |o, options| type=o.strip.upcase - if %w{OS CDROM DATABLOCK}.include? type + if Image::IMAGE_TYPES.include? type [0, type] else - [-1, "Type should be OS, CDROM or DATABLOCK"] + [-1, "Type should be: #{Image::IMAGE_TYPES.join(", ")}"] end end }, diff --git a/src/cli/oneimage b/src/cli/oneimage index c63ca447c8..8c5d8e16a3 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -150,6 +150,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do puts "ID: #{res}" else puts res.message + exit -1 end end end diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index bfed67afaa..6e93122920 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -50,7 +50,7 @@ Datastore::Datastore( ds_mad(""), tm_mad(""), base_path(""), - system_ds(0) + type(IMAGE_DS) { group_u = 1; @@ -92,6 +92,33 @@ int Datastore::disk_attribute(VectorAttribute * disk) /* Datastore :: Database Access Functions */ /* ************************************************************************ */ +Datastore::DatastoreType Datastore::str_to_type(string& str_type) +{ + Datastore::DatastoreType dst = IMAGE_DS; + + if (str_type.empty()) + { + return dst; + } + + TO_UPPER(str_type); + + if ( str_type == "IMAGE_DS" ) + { + dst = IMAGE_DS; + } + else if ( str_type == "SYSTEM_DS" ) + { + dst = SYSTEM_DS; + } + else if ( str_type == "FILE_DS" ) + { + dst = FILE_DS; + } + + return dst; +} + /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ @@ -100,25 +127,22 @@ int Datastore::insert(SqlDB *db, string& error_str) int rc; ostringstream oss; string s_disk_type; - string s_system_ds; + string s_ds_type; Nebula& nd = Nebula::instance(); - // --------------------------------------------------------------------- + // ------------------------------------------------------------------------- // Check default datastore attributes - // --------------------------------------------------------------------- + // ------------------------------------------------------------------------- - erase_template_attribute("NAME", name); - // NAME is checked in DatastorePool::allocate + erase_template_attribute("NAME", name);//DatastorePool::allocate checks NAME get_template_attribute("DS_MAD", ds_mad); - get_template_attribute("SYSTEM", s_system_ds); + get_template_attribute("TYPE", s_ds_type); - TO_UPPER(s_system_ds); + type = str_to_type(s_ds_type); - system_ds = (s_system_ds == "YES"); - - if ( system_ds == 1 ) + if ( type == SYSTEM_DS ) { if ( !ds_mad.empty() ) { @@ -143,19 +167,20 @@ int Datastore::insert(SqlDB *db, string& error_str) base_path = oss.str(); - get_template_attribute("DISK_TYPE", s_disk_type); + disk_type = Image::FILE; - if (s_disk_type == "BLOCK") + if ( type == IMAGE_DS ) { - disk_type = Image::BLOCK; - } - else if (s_disk_type == "CDROM") - { - disk_type = Image::CD_ROM; - } - else - { - disk_type = Image::FILE; + 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; + } } if ( tm_mad.empty() == true ) @@ -295,7 +320,7 @@ string& Datastore::to_xml(string& xml) const "" << ds_mad << "" << "" << tm_mad << "" << "" << base_path << "" << - "" << system_ds << "" << + "" << type << "" << "" << disk_type << "" << "" << cluster_id << "" << "" << cluster << "" << @@ -315,6 +340,7 @@ int Datastore::from_xml(const string& xml) { int rc = 0; int int_disk_type; + int int_ds_type; vector content; // Initialize the internal XML object @@ -330,7 +356,7 @@ int Datastore::from_xml(const string& xml) 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(system_ds, "/DATASTORE/SYSTEM", -1); + rc += xpath(int_ds_type, "/DATASTORE/TYPE", -1); rc += xpath(int_disk_type,"/DATASTORE/DISK_TYPE", -1); rc += xpath(cluster_id, "/DATASTORE/CLUSTER_ID", -1); @@ -340,6 +366,7 @@ int Datastore::from_xml(const string& xml) rc += perms_from_xml(); disk_type = static_cast(int_disk_type); + type = static_cast(int_ds_type); // Get associated classes ObjectXML::get_nodes("/DATASTORE/IMAGES", content); @@ -382,7 +409,7 @@ int Datastore::replace_template(const string& tmpl_str, string& error_str) { string new_ds_mad; string new_tm_mad; - string s_system_ds; + string s_ds_type; int rc; @@ -394,29 +421,23 @@ int Datastore::replace_template(const string& tmpl_str, string& error_str) } get_template_attribute("DS_MAD", new_ds_mad); - get_template_attribute("SYSTEM", s_system_ds); + get_template_attribute("TYPE", s_ds_type); if ( oid == DatastorePool::SYSTEM_DS_ID ) { - system_ds = 1; - } - else if ( !s_system_ds.empty() ) - { - TO_UPPER(s_system_ds); - - system_ds = (s_system_ds == "YES"); - } - - if ( system_ds == 1 ) - { - replace_template_attribute("SYSTEM", "YES"); - - new_ds_mad = "-"; + type = SYSTEM_DS; } else { - obj_template->erase("SYSTEM"); + type = str_to_type(s_ds_type); + + replace_template_attribute("TYPE", type_to_str(type)); + } + + if ( type == SYSTEM_DS ) + { + new_ds_mad = "-"; } if ( !new_ds_mad.empty() ) diff --git a/src/datastore/DatastorePool.cc b/src/datastore/DatastorePool.cc index c8639eca69..676e894357 100644 --- a/src/datastore/DatastorePool.cc +++ b/src/datastore/DatastorePool.cc @@ -32,6 +32,9 @@ const int DatastorePool::SYSTEM_DS_ID = 0; const string DatastorePool::DEFAULT_DS_NAME = "default"; const int DatastorePool::DEFAULT_DS_ID = 1; +const string DatastorePool::FILE_DS_NAME = "files"; +const int DatastorePool::FILE_DS_ID = 2; + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -49,12 +52,12 @@ DatastorePool::DatastorePool(SqlDB * db): int rc; // --------------------------------------------------------------------- - // Create the system datastore + // Create the system datastore // --------------------------------------------------------------------- - oss << "NAME = " << SYSTEM_DS_NAME << endl - << "SYSTEM = YES" << endl - << "TM_MAD = shared"; + oss << "NAME = " << SYSTEM_DS_NAME << endl + << "TYPE = SYSTEM_DS" << endl + << "TM_MAD = shared"; ds_tmpl = new DatastoreTemplate; rc = ds_tmpl->parse_str_or_xml(oss.str(), error_str); @@ -80,13 +83,59 @@ DatastorePool::DatastorePool(SqlDB * db): } // --------------------------------------------------------------------- - // Create the default datastore + // Create the default datastore // --------------------------------------------------------------------- oss.str(""); - oss << "NAME = " << DEFAULT_DS_NAME << endl - << "DS_MAD = fs" << endl - << "TM_MAD = shared"; + oss << "NAME = " << DEFAULT_DS_NAME << endl + << "TYPE = IMAGE_DS" << endl + << "DS_MAD = fs" << endl + << "TM_MAD = shared"; + + ds_tmpl = new DatastoreTemplate; + rc = ds_tmpl->parse_str_or_xml(oss.str(), error_str); + + if( rc < 0 ) + { + goto error_bootstrap; + } + + allocate(UserPool::ONEADMIN_ID, + GroupPool::ONEADMIN_ID, + UserPool::oneadmin_name, + GroupPool::ONEADMIN_NAME, + ds_tmpl, + &rc, + ClusterPool::NONE_CLUSTER_ID, + ClusterPool::NONE_CLUSTER_NAME, + error_str); + + if( rc < 0 ) + { + goto error_bootstrap; + } + + ds = get(rc, true); + + ds->set_permissions( + -1,-1,-1, + -1,-1,-1, + 1,-1,-1, + error_str); + + update(ds); + + ds->unlock(); + + // --------------------------------------------------------------------- + // Create the default file datastore + // --------------------------------------------------------------------- + oss.str(""); + + oss << "NAME = " << FILE_DS_NAME << endl + << "TYPE = FILE_DS" << endl + << "DS_MAD = fs" << endl + << "TM_MAD = ssh"; ds_tmpl = new DatastoreTemplate; rc = ds_tmpl->parse_str_or_xml(oss.str(), error_str); diff --git a/src/image/Image.cc b/src/image/Image.cc index 7b8e5cdbdf..4ab57a7cde 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -132,19 +132,33 @@ int Image::insert(SqlDB *db, string& error_str) erase_template_attribute("PERSISTENT", persistent_attr); - TO_UPPER(persistent_attr); + if ( type != DATAFILE ) + { + TO_UPPER(persistent_attr); - persistent_img = (persistent_attr == "YES"); + persistent_img = (persistent_attr == "YES"); + } + else // Files are always non-persistent + { + persistent_img = false; + } // ------------ PREFIX -------------------- - get_template_attribute("DEV_PREFIX", dev_prefix); - - if( dev_prefix.empty() ) + if ( type != DATAFILE ) { - SingleAttribute * dev_att = new SingleAttribute("DEV_PREFIX", - ImagePool::default_dev_prefix()); - obj_template->set(dev_att); + get_template_attribute("DEV_PREFIX", 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); } // ------------ SIZE -------------------- @@ -569,6 +583,10 @@ int Image::set_type(string& _type) { type = DATABLOCK; } + else if ( _type == "FILE" ) + { + type = DATAFILE; + } else { rc = -1; @@ -630,6 +648,10 @@ Image::ImageType Image::str_to_type(string& str_type) { it = DATABLOCK; } + else if ( str_type == "FILE" ) + { + it = DATAFILE; + } return it; } diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index 79b8578d7a..c50cd9267e 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -88,6 +88,17 @@ int ImageManager::acquire_image(int vm_id, Image *img, string& error) { int rc = 0; + if ( img->get_type() == Image::DATAFILE ) + { + ostringstream oss; + + oss << "Image " << img->get_oid() << " (" << img->get_name() << ") " + << "of type FILE cannot be used as DISK."; + error = oss.str(); + + return -1; + } + switch (img->get_state()) { case Image::READY: @@ -149,6 +160,14 @@ void ImageManager::release_image(int vm_id, int iid, bool failed) return; } + if ( img->get_type() == Image::DATAFILE ) + { + NebulaLog::log("ImM", Log::ERROR, "Trying to release a FILE image"); + + img->unlock(); + return; + } + switch (img->get_state()) { case Image::USED_PERS: @@ -238,6 +257,14 @@ void ImageManager::release_cloning_image(int iid, int clone_img_id) return; } + if ( img->get_type() == Image::DATAFILE ) + { + NebulaLog::log("ImM", Log::ERROR, "Trying to release a cloning FILE image"); + + img->unlock(); + return; + } + switch (img->get_state()) { case Image::USED: @@ -682,6 +709,7 @@ int ImageManager::stat_image(Template* img_tmpl, { case Image::OS: case Image::CDROM: + case Image::DATAFILE: img_tmpl->get("SOURCE", res); if (!res.empty()) @@ -720,6 +748,7 @@ int ImageManager::stat_image(Template* img_tmpl, { img_data << "" << res << ""; } + break; } add_request(&sr); diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index 653174f37e..04abb2c592 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,20 @@ 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_file; + } + + if ( ds_type == Datastore::IMAGE_DS && + img->str_to_type(type) == Image::DATAFILE ) + { + goto error_types_missmatch_image; + } + img_aux = get(name,uid,false); if( img_aux != 0 ) @@ -120,7 +136,6 @@ int ImagePool::allocate ( goto error_clone_state; } - img->set_cloning_id(cloning_id); } @@ -181,6 +196,14 @@ error_name_length: oss << "NAME is too long; max length is 128 chars."; goto error_common; +error_types_missmatch_file: + oss << "Only IMAGES of type FILE 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"; + goto error_common; + error_duplicated: oss << "NAME is already taken by IMAGE " << img_aux->get_oid() << "."; @@ -201,7 +224,7 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -static int get_disk_uid(VectorAttribute * disk, int _uid) +int ImagePool::get_disk_uid(VectorAttribute * disk, int _uid) { istringstream is; @@ -246,7 +269,7 @@ static int get_disk_uid(VectorAttribute * disk, int _uid) /* -------------------------------------------------------------------------- */ -static int get_disk_id(const string& id_s) +int ImagePool::get_disk_id(const string& id_s) { istringstream is; int id; diff --git a/src/oca/java/src/org/opennebula/client/datastore/Datastore.java b/src/oca/java/src/org/opennebula/client/datastore/Datastore.java index 7665af9853..f2bca4788c 100644 --- a/src/oca/java/src/org/opennebula/client/datastore/Datastore.java +++ b/src/oca/java/src/org/opennebula/client/datastore/Datastore.java @@ -36,6 +36,10 @@ public class Datastore extends PoolElement private static final String CHOWN = METHOD_PREFIX + "chown"; private static final String CHMOD = METHOD_PREFIX + "chmod"; + private static final String[] DATASTORE_TYPES = {"IMAGE", "SYSTEM", "FILE"}; + + private static final String[] SHORT_DATASTORE_TYPES = {"img", "sys", "fil"}; + /** * Creates a new Datastore representation. * @param id The datastore id. @@ -358,6 +362,38 @@ public class Datastore extends PoolElement // ================================= // Helpers // ================================= + /** + * Returns the type of the Datastore. + * + * @return The type of the Datastore. + */ + public int type() + { + String state = xpath("TYPE"); + return state != null ? Integer.parseInt( state ) : -1; + } + + /** + * Returns the type of the Datastore as a String. + * + * @return The type of the Datastore as a String. + */ + public String typeStr() + { + int type = type(); + return type != -1 ? DATASTORE_TYPES[type] : null; + } + + /** + * Returns the type of the Datastore as a short String. + * + * @return The type of the Datastore as a short String. + */ + public String shortTypeStr() + { + int type = type(); + return type != -1 ? SHORT_DATASTORE_TYPES[type] : null; + } /** * Returns whether or not the image is part of this datastore diff --git a/src/oca/java/src/org/opennebula/client/image/Image.java b/src/oca/java/src/org/opennebula/client/image/Image.java index 245da2a152..f6ebf9993f 100644 --- a/src/oca/java/src/org/opennebula/client/image/Image.java +++ b/src/oca/java/src/org/opennebula/client/image/Image.java @@ -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"}; + {"OS", "CDROM", "DATABLOCK", "FILE"}; private static final String[] SHORT_IMAGE_TYPES = - {"OS", "CD", "DB"}; + {"OS", "CD", "DB", "FL"}; /** * Creates a new Image representation. diff --git a/src/oca/ruby/OpenNebula/Datastore.rb b/src/oca/ruby/OpenNebula/Datastore.rb index 355d252c9a..fa1410203a 100644 --- a/src/oca/ruby/OpenNebula/Datastore.rb +++ b/src/oca/ruby/OpenNebula/Datastore.rb @@ -32,6 +32,14 @@ module OpenNebula :chmod => "datastore.chmod" } + DATASTORE_TYPES=%w{IMAGE SYSTEM FILE} + + SHORT_DATASTORE_TYPES = { + "IMAGE" => "img", + "SYSTEM"=> "sys", + "FILE" => "fil" + } + # Creates a Datastore description with just its identifier # this method should be used to create plain Datastore objects. # +id+ the id of the user @@ -57,6 +65,20 @@ module OpenNebula ####################################################################### # XML-RPC Methods for the Datastore Object ####################################################################### + # Returns the datastore type + def type + self['TYPE'].to_i + end + + # Returns the datastore type (string value) + def type_str + DATASTORE_TYPES[type] + end + + # Returns the datastore type (string value) + def short_type_str + SHORT_DATASTORE_TYPES[type_str] + end # Retrieves the information of the given Datastore. def info() diff --git a/src/oca/ruby/OpenNebula/Image.rb b/src/oca/ruby/OpenNebula/Image.rb index 75976036ca..6975a29f1e 100644 --- a/src/oca/ruby/OpenNebula/Image.rb +++ b/src/oca/ruby/OpenNebula/Image.rb @@ -52,12 +52,13 @@ module OpenNebula "USED_PERS" => "used" } - IMAGE_TYPES=%w{OS CDROM DATABLOCK} + IMAGE_TYPES=%w{OS CDROM DATABLOCK FILE} SHORT_IMAGE_TYPES={ - "OS" => "OS", - "CDROM" => "CD", - "DATABLOCK" => "DB" + "OS" => "OS", + "CDROM" => "CD", + "DATABLOCK" => "DB", + "FILE" => "FL" } # Creates an Image description with just its identifier diff --git a/src/rm/RequestManagerAllocate.cc b/src/rm/RequestManagerAllocate.cc index e376487176..84dcd007c0 100644 --- a/src/rm/RequestManagerAllocate.cc +++ b/src/rm/RequestManagerAllocate.cc @@ -232,9 +232,9 @@ void RequestManagerAllocate::request_execute(xmlrpc_c::paramList const& params, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachineAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, +int VirtualMachineAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, Template * tmpl, - int& id, + int& id, string& error_str, RequestAttributes& att) { @@ -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; @@ -301,7 +303,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, DatastorePool * dspool = nd.get_dspool(); ImagePool * ipool = static_cast(pool); ImageManager * imagem = nd.get_imagem(); - + ImageTemplate * tmpl = new ImageTemplate; Template img_usage; @@ -332,7 +334,9 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, return; } - if ( ds->is_system() ) + ds_type = ds->get_type(); + + if ( ds_type == Datastore::SYSTEM_DS ) { ostringstream oss; @@ -361,8 +365,8 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, if ( rc == -1 ) { - failure_response(INTERNAL, - request_error("Cannot determine Image SIZE", size_str), + failure_response(INTERNAL, + request_error("Cannot determine Image SIZE", size_str), att); delete tmpl; return; @@ -373,18 +377,18 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, if ( iss.fail() ) { - failure_response(INTERNAL, - request_error("Cannot parse SIZE", size_str), + failure_response(INTERNAL, + request_error("Cannot parse SIZE", size_str), att); delete tmpl; - return; + return; } tmpl->erase("SIZE"); tmpl->add("SIZE", size_str); // ------------- Set authorization request for non-oneadmin's -------------- - + img_usage.add("DATASTORE", ds_id); img_usage.add("SIZE", size_str); @@ -435,19 +439,20 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, if ( quota_authorization(&img_usage, Quotas::DATASTORE, att) == false ) { delete tmpl; - return; + return; } } - rc = ipool->allocate(att.uid, - att.gid, - att.uname, - att.gname, - tmpl, - ds_id, + rc = ipool->allocate(att.uid, + att.gid, + att.uname, + att.gname, + tmpl, + ds_id, ds_name, ds_disk_type, - ds_data, + ds_data, + ds_type, -1, &id, error_str); @@ -476,9 +481,9 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int TemplateAllocate::pool_allocate(xmlrpc_c::paramList const& _paramList, +int TemplateAllocate::pool_allocate(xmlrpc_c::paramList const& _paramList, Template * tmpl, - int& id, + int& id, string& error_str, RequestAttributes& att) { @@ -517,9 +522,9 @@ int HostAllocate::pool_allocate( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int UserAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, +int UserAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, Template * tmpl, - int& id, + int& id, string& error_str, RequestAttributes& att) { @@ -540,7 +545,7 @@ int UserAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, if (driver.empty()) { - driver = UserPool::CORE_AUTH; + driver = UserPool::CORE_AUTH; } return upool->allocate(&id,ugid,uname,ugname,passwd,driver,true,error_str); @@ -566,9 +571,9 @@ void UserAllocate::log_xmlrpc_param( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int GroupAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, +int GroupAllocate::pool_allocate(xmlrpc_c::paramList const& paramList, Template * tmpl, - int& id, + int& id, string& error_str, RequestAttributes& att) { diff --git a/src/rm/RequestManagerImage.cc b/src/rm/RequestManagerImage.cc index 668a0f11c1..b6caf756a3 100644 --- a/src/rm/RequestManagerImage.cc +++ b/src/rm/RequestManagerImage.cc @@ -44,11 +44,11 @@ void ImageEnable::request_execute(xmlrpc_c::paramList const& paramList, { if (enable_flag == true) { - err_msg = "Could not enable image"; + err_msg = "Could not enable image."; } else { - err_msg = "Could not disable image"; + err_msg = "Could not disable image."; } failure_response(INTERNAL, request_error(err_msg,""), att); @@ -87,6 +87,15 @@ void ImagePersistent::request_execute(xmlrpc_c::paramList const& paramList, return; } + if ( image->get_type() == Image::DATAFILE ) + { + failure_response(ACTION, + request_error("FILE images must be non-persistent",""), att); + + image->unlock(); + return; + } + rc = image->persistent(persistent_flag, err_msg); if ( rc != 0 ) @@ -142,6 +151,17 @@ 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); + + image->unlock(); + return; + } + rc = image->set_type(type); if ( rc != 0 ) @@ -182,7 +202,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 +220,19 @@ void ImageClone::request_execute( return; } + if ( img->get_type() == Image::DATAFILE ) + { + failure_response(ACTION, + allocate_error("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 +255,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 +276,7 @@ void ImageClone::request_execute( ds->unlock(); // ------------- Set authorization request --------------------------------- - + img_usage.add("DATASTORE", ds_id); img_usage.add("SIZE", size); @@ -265,21 +308,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 e7280cd27a..a30d61be8c 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -172,7 +172,7 @@ int RequestManagerVirtualMachine::get_host_information(int hid, return -1; } - if ( ds->is_system() == false ) + if ( ds->get_type() != Datastore::SYSTEM_DS ) { ostringstream oss; @@ -641,6 +641,14 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis return; } + if ( type == Image::DATAFILE ) + { + failure_response(INTERNAL, + request_error("Cannot save_as image of type FILE", ""), + att); + return; + } + // ------------------------------------------------------------------------- // Get the data of the DataStore for the new image // ------------------------------------------------------------------------- @@ -725,6 +733,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis ds_name, ds_disk_type, ds_data, + Datastore::IMAGE_DS, -1, &iid, error_str); diff --git a/src/template/template_syntax.cc b/src/template/template_syntax.cc index 641ef802b9..b8d43da3ae 100644 --- a/src/template/template_syntax.cc +++ b/src/template/template_syntax.cc @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.5. */ +/* A Bison parser, made by GNU Bison 2.6.5. */ /* Bison implementation for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. + 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 @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.5" +#define YYBISON_VERSION "2.6.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -58,8 +58,6 @@ /* Pull parsers. */ #define YYPULL 1 -/* Using locations. */ -#define YYLSP_NEEDED 1 /* Substitute the variable and function names. */ #define yyparse template__parse @@ -72,8 +70,7 @@ #define yylloc template__lloc /* Copy the first part of user declarations. */ - -/* Line 268 of yacc.c */ +/* Line 360 of yacc.c */ #line 17 "template_syntax.y" #include @@ -125,14 +122,16 @@ extern "C" } +/* Line 360 of yacc.c */ +#line 127 "template_syntax.cc" -/* Line 268 of yacc.c */ -#line 131 "template_syntax.cc" - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif +# ifndef YY_NULL +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULL nullptr +# else +# define YY_NULL 0 +# endif +# endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE @@ -142,11 +141,17 @@ extern "C" # define YYERROR_VERBOSE 0 #endif -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE 0 +/* In a future release of Bison, this section will be replaced + by #include "template_syntax.hh". */ +#ifndef YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED +# define YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int template__debug; #endif - /* Tokens. */ #ifndef YYTOKENTYPE @@ -165,21 +170,18 @@ extern "C" #endif - #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { - -/* Line 293 of yacc.c */ +/* Line 376 of yacc.c */ #line 74 "template_syntax.y" char * val_str; void * val_attr; - -/* Line 293 of yacc.c */ -#line 183 "template_syntax.cc" +/* Line 376 of yacc.c */ +#line 185 "template_syntax.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ @@ -200,11 +202,26 @@ typedef struct YYLTYPE #endif +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int template__parse (void *YYPARSE_PARAM); +#else +int template__parse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int template__parse (mem_collector * mc, Template * tmpl, char ** error_msg); +#else +int template__parse (); +#endif +#endif /* ! YYPARSE_PARAM */ + +#endif /* !YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED */ + /* Copy the second part of user declarations. */ - -/* Line 343 of yacc.c */ -#line 208 "template_syntax.cc" +/* Line 379 of yacc.c */ +#line 225 "template_syntax.cc" #ifdef short # undef short @@ -257,24 +274,24 @@ typedef short int yytype_int16; # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YYUSE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YYUSE(E) /* empty */ #endif /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint -# define YYID(n) (n) +# define YYID(N) (N) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) @@ -310,6 +327,7 @@ YYID (yyi) # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ # ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 # endif @@ -403,20 +421,20 @@ union yyalloc #endif #if defined YYCOPY_NEEDED && YYCOPY_NEEDED -/* Copy COUNT objects from FROM to TO. The source and destination do +/* Copy COUNT objects from SRC to DST. The source and destination do not overlap. */ # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) # else -# define YYCOPY(To, From, Count) \ - do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ while (YYID (0)) # endif # endif @@ -501,14 +519,14 @@ static const yytype_uint8 yyrline[] = }; #endif -#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE +#if YYDEBUG || YYERROR_VERBOSE || 0 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { "$end", "error", "$undefined", "EQUAL", "COMMA", "OBRACKET", "CBRACKET", "EQUAL_EMPTY", "STRING", "VARIABLE", "$accept", "template_file", - "template", "attribute", "array_val", 0 + "template", "attribute", "array_val", YY_NULL }; #endif @@ -575,10 +593,10 @@ static const yytype_uint8 yytable[] = 18, 16, 8, 17, 0, 0, 19 }; -#define yypact_value_is_default(yystate) \ - ((yystate) == (-9)) +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-9))) -#define yytable_value_is_error(yytable_value) \ +#define yytable_value_is_error(Yytable_value) \ YYID (0) static const yytype_int8 yycheck[] = @@ -622,23 +640,24 @@ static const yytype_uint8 yystos[] = #define YYRECOVERING() (!!yyerrstatus) -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - YYPOPSTACK (1); \ - goto yybackup; \ - } \ - else \ - { \ +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ yyerror (&yylloc, mc, tmpl, error_msg, YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) - +/* Error token number */ #define YYTERROR 1 #define YYERRCODE 256 @@ -647,27 +666,28 @@ while (YYID (0)) If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ -#define YYRHSLOC(Rhs, K) ((Rhs)[K]) #ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - do \ - if (YYID (N)) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ - else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ while (YYID (0)) #endif +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) + /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know @@ -675,10 +695,14 @@ while (YYID (0)) #ifndef YY_LOCATION_PRINT # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) +# define YY_LOCATION_PRINT(File, Loc) \ + do { \ + fprintf (File, "%d.%d", (Loc).first_line, (Loc).first_column); \ + if ((Loc).first_line < (Loc).last_line) \ + fprintf (File, "-%d.%d", (Loc).last_line, (Loc).last_column - 1); \ + else if ((Loc).first_column < (Loc).last_column - 1) \ + fprintf (File, "-%d", (Loc).last_column - 1); \ + } while (0) # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif @@ -686,7 +710,6 @@ while (YYID (0)) /* YYLEX -- calling `yylex' with the right arguments. */ - #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) #else @@ -740,6 +763,8 @@ yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, tmpl, error_ char ** error_msg; #endif { + FILE *yyo = yyoutput; + YYUSE (yyo); if (!yyvaluep) return; YYUSE (yylocationp); @@ -1005,12 +1030,12 @@ static int yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, yytype_int16 *yyssp, int yytoken) { - YYSIZE_T yysize0 = yytnamerr (0, yytname[yytoken]); + YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); YYSIZE_T yysize = yysize0; YYSIZE_T yysize1; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; /* Internationalized format string. */ - const char *yyformat = 0; + const char *yyformat = YY_NULL; /* Arguments of yyformat. */ char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; /* Number of reported tokens (one for the "unexpected", one per @@ -1070,7 +1095,7 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, break; } yyarg[yycount++] = yytname[yyx]; - yysize1 = yysize + yytnamerr (0, yytname[yyx]); + yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) return 2; @@ -1170,20 +1195,6 @@ yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, tmpl, error_msg) } -/* Prevent warnings from -Wmissing-prototypes. */ -#ifdef YYPARSE_PARAM -#if defined __STDC__ || defined __cplusplus -int yyparse (void *YYPARSE_PARAM); -#else -int yyparse (); -#endif -#else /* ! YYPARSE_PARAM */ -#if defined __STDC__ || defined __cplusplus -int yyparse (mem_collector * mc, Template * tmpl, char ** error_msg); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ /*----------. @@ -1217,11 +1228,39 @@ yyparse (mc, tmpl, error_msg) /* The lookahead symbol. */ int yychar; + +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +/* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ +static YYSTYPE yyval_default; +# define YY_INITIAL_VALUE(Value) = Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; +YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); /* Location data for the lookahead symbol. */ -YYLTYPE yylloc; +YYLTYPE yylloc +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + = { 1, 1, 1, 1 } +# endif +; + /* Number of syntax errors so far. */ int yynerrs; @@ -1235,7 +1274,7 @@ YYLTYPE yylloc; `yyvs': related to semantic values. `yyls': related to locations. - Refer to the stacks thru separate pointers, to allow yyoverflow + Refer to the stacks through separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ @@ -1261,7 +1300,7 @@ YYLTYPE yylloc; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken; + int yytoken = 0; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -1280,10 +1319,9 @@ YYLTYPE yylloc; Keep to zero when no symbol should be popped. */ int yylen = 0; - yytoken = 0; - yyss = yyssa; - yyvs = yyvsa; - yyls = yylsa; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yylsp = yyls = yylsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1292,21 +1330,7 @@ YYLTYPE yylloc; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - yyssp = yyss; - yyvsp = yyvs; - yylsp = yyls; - -#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL - /* Initialize the default location before parsing starts. */ - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = 1; -#endif - + yylsp[0] = yylloc; goto yysetstate; /*------------------------------------------------------------. @@ -1452,7 +1476,9 @@ yybackup: yychar = YYEMPTY; yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END *++yylsp = yylloc; goto yynewstate; @@ -1490,8 +1516,7 @@ yyreduce: switch (yyn) { case 6: - -/* Line 1806 of yacc.c */ +/* Line 1778 of yacc.c */ #line 103 "template_syntax.y" { Attribute * pattr; @@ -1505,8 +1530,7 @@ yyreduce: break; case 7: - -/* Line 1806 of yacc.c */ +/* Line 1778 of yacc.c */ #line 113 "template_syntax.y" { Attribute * pattr; @@ -1523,8 +1547,7 @@ yyreduce: break; case 8: - -/* Line 1806 of yacc.c */ +/* Line 1778 of yacc.c */ #line 126 "template_syntax.y" { Attribute * pattr; @@ -1538,8 +1561,7 @@ yyreduce: break; case 9: - -/* Line 1806 of yacc.c */ +/* Line 1778 of yacc.c */ #line 138 "template_syntax.y" { map* vattr; @@ -1556,8 +1578,7 @@ yyreduce: break; case 10: - -/* Line 1806 of yacc.c */ +/* Line 1778 of yacc.c */ #line 151 "template_syntax.y" { string name((yyvsp[(3) - (5)].val_str)); @@ -1574,9 +1595,8 @@ yyreduce: break; - -/* Line 1806 of yacc.c */ -#line 1580 "template_syntax.cc" +/* Line 1778 of yacc.c */ +#line 1600 "template_syntax.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1741,7 +1761,9 @@ yyerrlab1: YY_STACK_PRINT (yyss, yyssp); } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of @@ -1770,7 +1792,7 @@ yyabortlab: yyresult = 1; goto yyreturn; -#if !defined(yyoverflow) || YYERROR_VERBOSE +#if !defined yyoverflow || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ @@ -1812,8 +1834,7 @@ yyreturn: } - -/* Line 2067 of yacc.c */ +/* Line 2041 of yacc.c */ #line 164 "template_syntax.y" @@ -1853,4 +1874,3 @@ extern "C" void template__error( llocp->last_column); } } - diff --git a/src/template/template_syntax.h b/src/template/template_syntax.h index aa9ae6b64b..389697a95a 100644 --- a/src/template/template_syntax.h +++ b/src/template/template_syntax.h @@ -1,8 +1,8 @@ -/* A Bison parser, made by GNU Bison 2.5. */ +/* A Bison parser, made by GNU Bison 2.6.5. */ /* Bison interface for Yacc-like parsers in C - Copyright (C) 1984, 1989-1990, 2000-2011 Free Software Foundation, Inc. + 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 @@ -30,6 +30,15 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ +#ifndef YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED +# define YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int template__debug; +#endif /* Tokens. */ #ifndef YYTOKENTYPE @@ -48,29 +57,24 @@ #endif - #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { - -/* Line 2068 of yacc.c */ +/* Line 2042 of yacc.c */ #line 74 "template_syntax.y" char * val_str; void * val_attr; - -/* Line 2068 of yacc.c */ -#line 66 "template_syntax.hh" +/* Line 2042 of yacc.c */ +#line 72 "template_syntax.hh" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 #endif - - #if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED typedef struct YYLTYPE { @@ -84,5 +88,4 @@ typedef struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif - - +#endif /* !YY_TEMPLATE_TEMPLATE_SYNTAX_HH_INCLUDED */ diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 708a2093e0..78408eee6e 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -348,6 +348,55 @@ error_attributes: return -1; } +/* -------------------------------------------------------------------------- */ + +static string prolog_os_transfer_commands( + VirtualMachine * vm, + const VectorAttribute * os_attr, + const string& base, + string& opennebula_hostname, + ostream& xfr) +{ + string base_ds = base + "_DS"; + + string name_ds = os_attr->vector_value(base_ds.c_str()); + + if ( name_ds.empty() ) + { + return ""; + } + + string base_source = base + "_DS_SOURCE"; + string base_ds_id = base + "_DS_DSID"; + string base_tm = base + "_DS_TM"; + + string source = os_attr->vector_value(base_source.c_str()); + string ds_id = os_attr->vector_value(base_ds_id.c_str()); + string tm_mad = os_attr->vector_value(base_tm.c_str()); + + if ( source.empty() || ds_id.empty() || tm_mad.empty() ) + { + return ""; + } + + ostringstream base_dst; + string name = base; + + transform(name.begin(), name.end(), name.begin(), (int(*)(int))tolower); + + base_dst << vm->get_remote_system_dir() << "/" << name; + + xfr << "CLONE " << tm_mad << " " + << opennebula_hostname << ":" << source << " " + << vm->get_hostname() << ":" + << base_dst.str() << " " + << vm->get_oid() << " " + << ds_id + << endl; + + return base_dst.str(); +} + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -435,9 +484,46 @@ void TransferManager::prolog_action(int vid) } } + // ------------------------------------------------------------------------- + // Transfers for kernel and initrd files + // ------------------------------------------------------------------------- + attrs.clear(); + + num = vm->get_template_attribute("OS",attrs); + + if ( num > 0 ) + { + const VectorAttribute * os_attr; + + os_attr = dynamic_cast(attrs[0]); + + string kernel = prolog_os_transfer_commands(vm, + os_attr, + "KERNEL", + opennebula_hostname, + xfr); + if ( !kernel.empty() ) + { + vm->set_kernel(kernel); + vmpool->update(vm); + } + + string initrd = prolog_os_transfer_commands(vm, + os_attr, + "initrd", + opennebula_hostname, + xfr); + if ( !initrd.empty() ) + { + vm->set_initrd(initrd); + vmpool->update(vm); + } + } + // ------------------------------------------------------------------------- // Generate context file // ------------------------------------------------------------------------- + context_result = vm->generate_context(files, disk_id); if ( context_result == -1 ) diff --git a/src/vm/SConstruct b/src/vm/SConstruct index bc041d804e..58840389ca 100644 --- a/src/vm/SConstruct +++ b/src/vm/SConstruct @@ -33,12 +33,18 @@ if env['parsers']=='yes': ) env.NoClean(parser) + parser=env.Bison( + source='vm_file_var_syntax.y' + ) + env.NoClean(parser) + # Sources to generate the library source_files=[ 'History.cc', 'VirtualMachine.cc', 'vm_var_parser.c', 'vm_var_syntax.cc', + 'vm_file_var_syntax.cc', 'VirtualMachinePool.cc', 'VirtualMachineHook.cc', 'VirtualMachineTemplate.cc' diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 07f2cc7296..13a0ef0e71 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -31,7 +31,7 @@ #include "Nebula.h" - +#include "vm_file_var_syntax.h" #include "vm_var_syntax.h" /* ************************************************************************** */ @@ -269,6 +269,17 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) } } + // ------------------------------------------------------------------------ + // Check the OS attribute + // ------------------------------------------------------------------------ + + rc = parse_os(error_str); + + if ( rc != 0 ) + { + goto error_os; + } + // ------------------------------------------------------------------------ // Get network leases // ------------------------------------------------------------------------ @@ -349,6 +360,9 @@ error_leases_rollback: release_network_leases(); goto error_common; +error_os: + goto error_common; + error_cpu: error_str = "CPU attribute must be a positive float or integer value."; goto error_common; @@ -374,15 +388,150 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +int VirtualMachine::set_os_file(VectorAttribute * os, + const string& base_name, + string& error_str) +{ + vector img_ids; + Nebula& nd = Nebula::instance(); + + ImagePool * ipool = nd.get_ipool(); + Image * img = 0; + + DatastorePool * ds_pool = nd.get_dspool(); + Datastore * ds; + int ds_id; + + string attr; + string base_name_ds = base_name + "_DS"; + string base_name_id = base_name + "_DS_ID"; + string base_name_source = base_name + "_DS_SOURCE"; + string base_name_ds_id = base_name + "_DS_DSID"; + string base_name_tm = base_name + "_DS_TM"; + string base_name_cluster= base_name + "_DS_CLUSTER_ID"; + + attr = os->vector_value(base_name_ds.c_str()); + + if ( attr.empty() ) + { + return 0; + } + + if ( parse_file_attribute(attr, img_ids, error_str) != 0 ) + { + return -1; + } + + if ( img_ids.size() != 1 ) + { + error_str = "Only one FILE variable can be used in: " + attr; + return -1; + } + + img = ipool->get(img_ids.back(), true); + + if ( img == 0 ) + { + error_str = "Image no longer exists in attribute: " + attr; + return -1; + } + + ds_id = img->get_ds_id(); + + os->remove(base_name); + + os->replace(base_name_id, img->get_oid()); + os->replace(base_name_source, img->get_source()); + os->replace(base_name_ds_id, img->get_ds_id()); + + img->unlock(); + + ds = ds_pool->get(ds_id, true); + + if ( ds == 0 ) + { + error_str = "Associated datastore for image does not exist"; + return -1; + } + + os->replace(base_name_tm, ds->get_tm_mad()); + + if ( ds->get_cluster_id() != ClusterPool::NONE_CLUSTER_ID ) + { + os->replace(base_name_cluster, ds->get_cluster_id()); + } + + ds->unlock(); + + return 0; +} + +/* -------------------------------------------------------------------------- */ + +int VirtualMachine::parse_os(string& error_str) +{ + int num; + int rc; + + vector os_attr; + VectorAttribute * os; + + num = obj_template->get("OS", os_attr); + + if ( num == 0 ) + { + return 0; + } + else if ( num > 1 ) + { + error_str = "Only one OS attribute can be defined."; + return -1; + } + + os = dynamic_cast(os_attr[0]); + + if ( os == 0 ) + { + error_str = "Internal error parsing OS attribute."; + return -1; + } + + rc = set_os_file(os, "KERNEL", error_str); + + if ( rc != 0 ) + { + return -1; + } + + rc = set_os_file(os, "INITRD", error_str); + + if ( rc != 0 ) + { + return -1; + } + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + int VirtualMachine::parse_context(string& error_str) { int rc, num; vector array_context; VectorAttribute * context; + VectorAttribute * context_parsed; - string * str; - string parsed; + string * str; + string parsed; + string files_ds; + string files_ds_parsed; + + ostringstream oss_parsed; + + vector img_ids; num = obj_template->remove("CONTEXT", array_context); @@ -404,28 +553,33 @@ int VirtualMachine::parse_context(string& error_str) goto error_cleanup; } + //Backup datastore files to parse them later + + files_ds = context->vector_value("FILES_DS"); + + context->remove("FILES_DS"); + + // ------------------------------------------------------------------------- + // Parse CONTEXT variables & free vector attributes + // ------------------------------------------------------------------------- + str = context->marshall(" @^_^@ "); if (str == 0) { - NebulaLog::log("ONE",Log::ERROR, "Cannot marshall CONTEXT"); + error_str = "Cannot marshall CONTEXT"; goto error_cleanup; } - rc = parse_template_attribute(*str,parsed); + rc = parse_template_attribute(*str, parsed, error_str); - if ( rc == 0 ) + delete str; + + if (rc != 0) { - VectorAttribute * context_parsed; - - context_parsed = new VectorAttribute("CONTEXT"); - context_parsed->unmarshall(parsed," @^_^@ "); - - obj_template->set(context_parsed); + goto error_cleanup; } - /* --- Delete old context attributes --- */ - for (int i = 0; i < num ; i++) { if (array_context[i] != 0) @@ -434,6 +588,52 @@ int VirtualMachine::parse_context(string& error_str) } } + // ------------------------------------------------------------------------- + // Parse FILE_DS variables + // ------------------------------------------------------------------------- + + if (!files_ds.empty()) + { + if ( parse_file_attribute(files_ds, img_ids, error_str) != 0 ) + { + return -1; + } + + if ( img_ids.size() > 0 ) + { + vector::iterator it; + + Nebula& nd = Nebula::instance(); + + ImagePool * ipool = nd.get_ipool(); + Image * img = 0; + + for ( it=img_ids.begin() ; it < img_ids.end(); it++ ) + { + img = ipool->get(*it, true); + + if ( img != 0 ) + { + oss_parsed << img->get_source() << " "; + + img->unlock(); + } + } + } + } + + files_ds_parsed = oss_parsed.str(); + + context_parsed = new VectorAttribute("CONTEXT"); + context_parsed->unmarshall(parsed," @^_^@ "); + + if ( !files_ds_parsed.empty() ) + { + context_parsed->replace("FILES_DS", files_ds_parsed); + } + + obj_template->set(context_parsed); + return rc; error_cleanup: @@ -525,7 +725,7 @@ int VirtualMachine::parse_requirements(string& error_str) goto error_cleanup; } - rc = parse_template_attribute(reqs->value(),parsed); + rc = parse_template_attribute(reqs->value(), parsed, error_str); if ( rc == 0 ) { @@ -562,6 +762,31 @@ error_cleanup: /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ +static int check_and_set_cluster_id(const char * id_name, + VectorAttribute * vatt, + string& cluster_id) +{ + string vatt_cluster_id; + + vatt_cluster_id = vatt->vector_value(id_name); + + if ( !vatt_cluster_id.empty() ) + { + if ( cluster_id.empty() ) + { + cluster_id = vatt_cluster_id; + } + else if ( cluster_id != vatt_cluster_id ) + { + return -1; + } + } + + return 0; +} + +/* ------------------------------------------------------------------------ */ + int VirtualMachine::automatic_requirements(string& error_str) { int num_vatts; @@ -571,9 +796,11 @@ int VirtualMachine::automatic_requirements(string& error_str) ostringstream oss; string requirements; string cluster_id = ""; - string vatt_cluster_id; - // Get cluster id from all DISK vector attributes + int incomp_id; + int rc; + + // Get cluster id from all DISK vector attributes (IMAGE Datastore) num_vatts = obj_template->get("DISK",v_attributes); @@ -586,16 +813,39 @@ int VirtualMachine::automatic_requirements(string& error_str) continue; } - vatt_cluster_id = vatt->vector_value("CLUSTER_ID"); + rc = check_and_set_cluster_id("CLUSTER_ID", vatt, cluster_id); - if ( !vatt_cluster_id.empty() ) + if ( rc != 0 ) { - if ( !cluster_id.empty() && cluster_id != vatt_cluster_id ) + incomp_id = i; + goto error_disk; + } + } + + // Get cluster id from the KERNEL and INITRD (FILE Datastores) + + v_attributes.clear(); + num_vatts = obj_template->get("OS",v_attributes); + + if ( num_vatts > 0 ) + { + vatt = dynamic_cast(v_attributes[0]); + + if ( vatt != 0 ) + { + rc = check_and_set_cluster_id("KERNEL_CLUSTER_ID", vatt, cluster_id); + + if ( rc != 0 ) { - goto error; + goto error_kernel; } - cluster_id = vatt_cluster_id; + rc = check_and_set_cluster_id("INITRD_CLUSTER_ID", vatt, cluster_id); + + if ( rc != 0 ) + { + goto error_initrd; + } } } @@ -613,16 +863,12 @@ int VirtualMachine::automatic_requirements(string& error_str) continue; } - vatt_cluster_id = vatt->vector_value("CLUSTER_ID"); + rc = check_and_set_cluster_id("CLUSTER_ID", vatt, cluster_id); - if ( !vatt_cluster_id.empty() ) + if ( rc != 0 ) { - if ( !cluster_id.empty() && cluster_id != vatt_cluster_id ) - { - goto error; - } - - cluster_id = vatt_cluster_id; + incomp_id = i; + goto error_nic; } } @@ -643,59 +889,27 @@ int VirtualMachine::automatic_requirements(string& error_str) return 0; -error: +error_disk: + oss << "Incompatible clusters in DISKs. Datastore for DISK[" + << incomp_id <<"] should be in cluster " << cluster_id << "."; + goto error_common; - oss << "Incompatible cluster IDs."; +error_kernel: + oss << "Incompatible cluster in KERNEL datastore, it should be in cluster " + << cluster_id << "."; + goto error_common; - // Get cluster id from all DISK vector attributes +error_initrd: + oss << "Incompatible cluster in INITRD datastore, it should be in cluster " + << cluster_id << "."; + goto error_common; - v_attributes.clear(); - num_vatts = obj_template->get("DISK",v_attributes); - - for(int i=0; i(v_attributes[i]); - - if ( vatt == 0 ) - { - continue; - } - - vatt_cluster_id = vatt->vector_value("CLUSTER_ID"); - - if ( !vatt_cluster_id.empty() ) - { - oss << endl << "DISK [" << i << "]: IMAGE [" - << vatt->vector_value("IMAGE_ID") << "] from DATASTORE [" - << vatt->vector_value("DATASTORE_ID") << "] requires CLUSTER [" - << vatt_cluster_id << "]"; - } - } - - // Get cluster id from all NIC vector attributes - - v_attributes.clear(); - num_vatts = obj_template->get("NIC",v_attributes); - - for(int i=0; i(v_attributes[i]); - - if ( vatt == 0 ) - { - continue; - } - - vatt_cluster_id = vatt->vector_value("CLUSTER_ID"); - - if ( !vatt_cluster_id.empty() ) - { - oss << endl << "NIC [" << i << "]: NETWORK [" - << vatt->vector_value("NETWORK_ID") << "] requires CLUSTER [" - << vatt_cluster_id << "]"; - } - } +error_nic: + oss << "Incompatible clusters in NICs. Network for NIC[" << incomp_id <<"]" + << " should be in cluster " << cluster_id << "."; + goto error_common; +error_common: error_str = oss.str(); return -1; @@ -1575,6 +1789,7 @@ void VirtualMachine::release_network_leases() int VirtualMachine::generate_context(string &files, int &disk_id) { ofstream file; + string files_ds; vector attrs; const VectorAttribute * context; @@ -1613,6 +1828,14 @@ int VirtualMachine::generate_context(string &files, int &disk_id) files = context->vector_value("FILES"); + files_ds = context->vector_value("FILES_DS"); + + if (!files_ds.empty()) + { + files += " "; + files += files_ds; + } + const map values = context->value(); file << "# Context variables generated by OpenNebula\n"; @@ -1826,6 +2049,10 @@ extern "C" ostringstream * parsed, char ** errmsg); + int vm_file_var_parse (VirtualMachine * vm, + vector * img_ids, + char ** errmsg); + int vm_var_lex_destroy(); YY_BUFFER_STATE vm_var__scan_string(const char * str); @@ -1836,7 +2063,8 @@ extern "C" /* -------------------------------------------------------------------------- */ int VirtualMachine::parse_template_attribute(const string& attribute, - string& parsed) + string& parsed, + string& error_str) { YY_BUFFER_STATE str_buffer = 0; const char * str; @@ -1854,7 +2082,7 @@ int VirtualMachine::parse_template_attribute(const string& attribute, goto error_yy; } - rc = vm_var_parse(this,&oss_parsed,&error_msg); + rc = vm_var_parse(this, &oss_parsed, &error_msg); vm_var__delete_buffer(str_buffer); @@ -1867,7 +2095,9 @@ int VirtualMachine::parse_template_attribute(const string& attribute, ostringstream oss; oss << "Error parsing: " << attribute << ". " << error_msg; - log("VM",Log::ERROR,oss); + log("VM", Log::ERROR, oss); + + error_str = oss.str(); free(error_msg); } @@ -1882,6 +2112,71 @@ error_yy: return -1; } +/* -------------------------------------------------------------------------- */ + +int VirtualMachine::parse_file_attribute(string attribute, + vector& img_ids, + string& error) +{ + YY_BUFFER_STATE str_buffer = 0; + const char * str; + int rc; + ostringstream oss_parsed; + char * error_msg = 0; + + size_t non_blank_pos; + + //Removes leading blanks from attribute, these are not managed + //by the parser as it is common to the other VM varibales + non_blank_pos = attribute.find_first_not_of(" \t\n\v\f\r"); + + if ( non_blank_pos != string::npos ) + { + attribute.erase(0, non_blank_pos); + } + + pthread_mutex_lock(&lex_mutex); + + str = attribute.c_str(); + str_buffer = vm_var__scan_string(str); + + if (str_buffer == 0) + { + goto error_yy; + } + + rc = vm_file_var_parse(this, &img_ids, &error_msg); + + vm_var__delete_buffer(str_buffer); + + vm_var_lex_destroy(); + + pthread_mutex_unlock(&lex_mutex); + + if ( rc != 0 ) + { + ostringstream oss; + + if ( error_msg != 0 ) + { + oss << "Error parsing: " << attribute << ". " << error_msg; + free(error_msg); + } + else + { + oss << "Unknown error parsing: " << attribute << "."; + } + + error = oss.str(); + } + + return rc; + +error_yy: + log("VM",Log::ERROR,"Error setting scan buffer"); + pthread_mutex_unlock(&lex_mutex); + return -1; +} /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/vm/vm_file_var_syntax.cc b/src/vm/vm_file_var_syntax.cc new file mode 100644 index 0000000000..81b2869063 --- /dev/null +++ b/src/vm/vm_file_var_syntax.cc @@ -0,0 +1,1942 @@ +/* A Bison parser, made by GNU Bison 2.6.5. */ + +/* Bison implementation 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 . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + 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. */ + +/* C LALR(1) parser skeleton written by Richard Stallman, by + simplifying the original so-called "semantic" parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Bison version. */ +#define YYBISON_VERSION "2.6.5" + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 1 + +/* Push parsers. */ +#define YYPUSH 0 + +/* Pull parsers. */ +#define YYPULL 1 + + +/* Substitute the variable and function names. */ +#define yyparse vm_file_var__parse +#define yylex vm_file_var__lex +#define yyerror vm_file_var__error +#define yylval vm_file_var__lval +#define yychar vm_file_var__char +#define yydebug vm_file_var__debug +#define yynerrs vm_file_var__nerrs +#define yylloc vm_file_var__lloc + +/* Copy the first part of user declarations. */ +/* Line 360 of yacc.c */ +#line 17 "vm_file_var_syntax.y" + +#include +#include +#include +#include +#include + +#include +#include + +#include "vm_file_var_syntax.h" +#include "ImagePool.h" +#include "UserPool.h" +#include "VirtualMachine.h" +#include "Nebula.h" + +#define vm_file_var__lex vm_var_lex + +#define YYERROR_VERBOSE +#define VM_VAR_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \ +(int(*)(int))toupper) + +extern "C" +{ + #include "mem_collector.h" + + void vm_file_var__error( + YYLTYPE * llocp, + mem_collector * mc, + VirtualMachine * vm, + vector * img_ids, + char ** errmsg, + const char * str); + + int vm_file_var__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + + int vm_file_var__parse (mem_collector * mc, + VirtualMachine * vm, + vector * img_ids, + char ** errmsg); + + int vm_file_var_parse (VirtualMachine * vm, + vector * img_ids, + char ** errmsg) + { + mem_collector mc; + int rc; + + mem_collector_init(&mc); + + rc = vm_file_var__parse(&mc, vm, img_ids, errmsg); + + mem_collector_cleanup(&mc); + + return rc; + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int get_image_path(VirtualMachine * vm, + const string& var_name, + const string& var1, + const string& val1, + const string& var2, + const string& val2, + vector * img_ids, + string& error_str) +{ + Nebula& nd = Nebula::instance(); + + ImagePool * ipool = nd.get_ipool(); + Image * img = 0; + int iid = -1; + + PoolObjectAuth perm; + + if (var_name != "FILE" ) + { + error_str = "Must use FILE variable for attribute."; + return -1; + } + + if ( var1 == "IMAGE" ) + { + int uid = vm->get_uid(); + + if ( !var2.empty() ) + { + VectorAttribute * vfile; + map file_values; + + file_values.insert(make_pair(var1, val1)); + file_values.insert(make_pair(var2, val2)); + + vfile = new VectorAttribute("FILE", file_values); + uid = ImagePool::get_disk_uid(vfile, uid); + + delete vfile; + } + + img = ipool->get(val1, uid, true); + } + else if ( var1 == "IMAGE_ID" ) + { + iid = ImagePool::get_disk_id(val1); + + if ( iid != -1 ) + { + img = ipool->get(iid, true); + } + } + + if ( img == 0 ) + { + error_str = "Cannot get image (check name/ID or try IMAGE_UNAME or IMAGE_UID)."; + return -1; + } + + iid = img->get_oid(); + + 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()); + + ar.add_auth(AuthRequest::USE, perm); + + if (UserPool::authorize(ar) == -1) + { + error_str = "User not authorize to use image."; + return -1; + } + + img_ids->push_back(iid); + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + + +/* Line 360 of yacc.c */ +#line 230 "vm_file_var_syntax.cc" + +# ifndef YY_NULL +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULL nullptr +# else +# define YY_NULL 0 +# endif +# endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +/* In a future release of Bison, this section will be replaced + by #include "vm_file_var_syntax.hh". */ +#ifndef YY_VM_FILE_VAR_VM_FILE_VAR_SYNTAX_HH_INCLUDED +# define YY_VM_FILE_VAR_VM_FILE_VAR_SYNTAX_HH_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int vm_file_var__debug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + EQUAL = 258, + COMMA = 259, + OBRACKET = 260, + CBRACKET = 261, + EOA = 262, + STRING = 263, + VARIABLE = 264, + RSTRING = 265, + INTEGER = 266 + }; +#endif + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 376 of yacc.c */ +#line 178 "vm_file_var_syntax.y" + + char * val_str; + int val_int; + char val_char; + + +/* Line 376 of yacc.c */ +#line 291 "vm_file_var_syntax.cc" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + + +#ifdef YYPARSE_PARAM +#if defined __STDC__ || defined __cplusplus +int vm_file_var__parse (void *YYPARSE_PARAM); +#else +int vm_file_var__parse (); +#endif +#else /* ! YYPARSE_PARAM */ +#if defined __STDC__ || defined __cplusplus +int vm_file_var__parse (mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg); +#else +int vm_file_var__parse (); +#endif +#endif /* ! YYPARSE_PARAM */ + +#endif /* !YY_VM_FILE_VAR_VM_FILE_VAR_SYNTAX_HH_INCLUDED */ + +/* Copy the second part of user declarations. */ + +/* Line 379 of yacc.c */ +#line 331 "vm_file_var_syntax.cc" + +#ifdef short +# undef short +#endif + +#ifdef YYTYPE_UINT8 +typedef YYTYPE_UINT8 yytype_uint8; +#else +typedef unsigned char yytype_uint8; +#endif + +#ifdef YYTYPE_INT8 +typedef YYTYPE_INT8 yytype_int8; +#elif (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +typedef signed char yytype_int8; +#else +typedef short int yytype_int8; +#endif + +#ifdef YYTYPE_UINT16 +typedef YYTYPE_UINT16 yytype_uint16; +#else +typedef unsigned short int yytype_uint16; +#endif + +#ifdef YYTYPE_INT16 +typedef YYTYPE_INT16 yytype_int16; +#else +typedef short int yytype_int16; +#endif + +#ifndef YYSIZE_T +# ifdef __SIZE_TYPE__ +# define YYSIZE_T __SIZE_TYPE__ +# elif defined size_t +# define YYSIZE_T size_t +# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# else +# define YYSIZE_T unsigned int +# endif +#endif + +#define YYSIZE_MAXIMUM ((YYSIZE_T) -1) + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include /* INFRINGES ON USER NAME SPACE */ +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) +# endif +# endif +# ifndef YY_ +# define YY_(Msgid) Msgid +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(E) ((void) (E)) +#else +# define YYUSE(E) /* empty */ +#endif + +/* Identity function, used to suppress warnings about constant conditions. */ +#ifndef lint +# define YYID(N) (N) +#else +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static int +YYID (int yyi) +#else +static int +YYID (yyi) + int yyi; +#endif +{ + return yyi; +} +#endif + +#if ! defined yyoverflow || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# ifdef YYSTACK_USE_ALLOCA +# if YYSTACK_USE_ALLOCA +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# elif defined __BUILTIN_VA_ARG_INCR +# include /* INFRINGES ON USER NAME SPACE */ +# elif defined _AIX +# define YYSTACK_ALLOC __alloca +# elif defined _MSC_VER +# include /* INFRINGES ON USER NAME SPACE */ +# define alloca _alloca +# else +# define YYSTACK_ALLOC alloca +# if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +# include /* INFRINGES ON USER NAME SPACE */ + /* Use EXIT_SUCCESS as a witness for stdlib.h. */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) +# ifndef YYSTACK_ALLOC_MAXIMUM + /* The OS might guarantee only one guard page at the bottom of the stack, + and a page size can be as small as 4096 bytes. So we cannot safely + invoke alloca (N) if N exceeds 4096. Use a slightly smaller number + to allow for a few compiler-allocated temporary stack slots. */ +# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ +# endif +# else +# define YYSTACK_ALLOC YYMALLOC +# define YYSTACK_FREE YYFREE +# ifndef YYSTACK_ALLOC_MAXIMUM +# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM +# endif +# if (defined __cplusplus && ! defined EXIT_SUCCESS \ + && ! ((defined YYMALLOC || defined malloc) \ + && (defined YYFREE || defined free))) +# include /* INFRINGES ON USER NAME SPACE */ +# ifndef EXIT_SUCCESS +# define EXIT_SUCCESS 0 +# endif +# endif +# ifndef YYMALLOC +# define YYMALLOC malloc +# if ! defined malloc && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# ifndef YYFREE +# define YYFREE free +# if ! defined free && ! defined EXIT_SUCCESS && (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +void free (void *); /* INFRINGES ON USER NAME SPACE */ +# endif +# endif +# endif +#endif /* ! defined yyoverflow || YYERROR_VERBOSE */ + + +#if (! defined yyoverflow \ + && (! defined __cplusplus \ + || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ + && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + yytype_int16 yyss_alloc; + YYSTYPE yyvs_alloc; + YYLTYPE yyls_alloc; +}; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \ + + 2 * YYSTACK_GAP_MAXIMUM) + +# define YYCOPY_NEEDED 1 + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack_alloc, Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (YYID (0)) + +#endif + +#if defined YYCOPY_NEEDED && YYCOPY_NEEDED +/* Copy COUNT objects from SRC to DST. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if defined __GNUC__ && 1 < __GNUC__ +# define YYCOPY(Dst, Src, Count) \ + __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src))) +# else +# define YYCOPY(Dst, Src, Count) \ + do \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ + while (YYID (0)) +# endif +# endif +#endif /* !YYCOPY_NEEDED */ + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 5 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 16 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 12 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 3 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 5 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 18 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 266 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const yytype_uint8 yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 7, 8, 9, 10, 11 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const yytype_uint8 yyprhs[] = +{ + 0, 0, 3, 5, 8, 16 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yytype_int8 yyrhs[] = +{ + 13, 0, -1, 14, -1, 13, 14, -1, 9, 5, + 9, 3, 8, 6, 7, -1, 9, 5, 9, 3, + 8, 4, 9, 3, 8, 6, 7, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const yytype_uint8 yyrline[] = +{ + 0, 202, 202, 203, 207, 225 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE || 0 +/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "EQUAL", "COMMA", "OBRACKET", "CBRACKET", + "EOA", "STRING", "VARIABLE", "RSTRING", "INTEGER", "$accept", + "vm_string", "vm_variable", YY_NULL +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const yytype_uint16 yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, + 265, 266 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const yytype_uint8 yyr1[] = +{ + 0, 12, 13, 13, 14, 14 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const yytype_uint8 yyr2[] = +{ + 0, 2, 1, 2, 7, 11 +}; + +/* YYDEFACT[STATE-NAME] -- Default reduction number in state STATE-NUM. + Performed when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const yytype_uint8 yydefact[] = +{ + 0, 0, 0, 2, 0, 1, 3, 0, 0, 0, + 0, 0, 0, 4, 0, 0, 0, 5 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yytype_int8 yydefgoto[] = +{ + -1, 2, 3 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -8 +static const yytype_int8 yypact[] = +{ + -7, -1, 0, -8, -4, -8, -8, 3, 2, -3, + -2, 1, 8, -8, 4, 7, 9, -8 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yytype_int8 yypgoto[] = +{ + -8, -8, 12 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const yytype_uint8 yytable[] = +{ + 5, 10, 1, 11, 4, 7, 8, 12, 13, 1, + 9, 14, 15, 16, 6, 0, 17 +}; + +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-8))) + +#define yytable_value_is_error(Yytable_value) \ + YYID (0) + +static const yytype_int8 yycheck[] = +{ + 0, 4, 9, 6, 5, 9, 3, 9, 7, 9, + 8, 3, 8, 6, 2, -1, 7 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const yytype_uint8 yystos[] = +{ + 0, 9, 13, 14, 5, 0, 14, 9, 3, 8, + 4, 6, 9, 7, 3, 8, 6, 7 +}; + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. However, + YYFAIL appears to be in use. Nevertheless, it is formally deprecated + in Bison 2.4.2's NEWS entry, where a plan to phase it out is + discussed. */ + +#define YYFAIL goto yyerrlab +#if defined YYFAIL + /* This is here to suppress warnings from the GCC cpp's + -Wunused-macros. Normally we don't worry about that warning, but + some users do, and we want to make it easy for users to remove + YYFAIL uses, which will produce warnings from Bison 2.5. */ +#endif + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + YYPOPSTACK (yylen); \ + yystate = *yyssp; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror (&yylloc, mc, vm, img_ids, errmsg, YY_("syntax error: cannot back up")); \ + YYERROR; \ + } \ +while (YYID (0)) + +/* Error token number */ +#define YYTERROR 1 +#define YYERRCODE 256 + + +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (YYID (N)) \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ + else \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ + while (YYID (0)) +#endif + +#define YYRHSLOC(Rhs, K) ((Rhs)[K]) + + +/* YY_LOCATION_PRINT -- Print the location on the stream. + This macro was not mandated originally: define only if we know + we won't break user code: when these are the locations we know. */ + +#ifndef YY_LOCATION_PRINT +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL +# define YY_LOCATION_PRINT(File, Loc) \ + do { \ + fprintf (File, "%d.%d", (Loc).first_line, (Loc).first_column); \ + if ((Loc).first_line < (Loc).last_line) \ + fprintf (File, "-%d.%d", (Loc).last_line, (Loc).last_column - 1); \ + else if ((Loc).first_column < (Loc).last_column - 1) \ + fprintf (File, "-%d", (Loc).last_column - 1); \ + } while (0) +# else +# define YY_LOCATION_PRINT(File, Loc) ((void) 0) +# endif +#endif + + +/* YYLEX -- calling `yylex' with the right arguments. */ +#ifdef YYLEX_PARAM +# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) +#else +# define YYLEX yylex (&yylval, &yylloc, mc) +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (YYID (0)) + +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yy_symbol_print (stderr, \ + Type, Value, Location, mc, vm, img_ids, errmsg); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (YYID (0)) + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg) +#else +static void +yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, vm, img_ids, errmsg) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + YYLTYPE const * const yylocationp; + mem_collector * mc; + VirtualMachine * vm; + vector * img_ids; + char ** errmsg; +#endif +{ + FILE *yyo = yyoutput; + YYUSE (yyo); + if (!yyvaluep) + return; + YYUSE (yylocationp); + YYUSE (mc); + YYUSE (vm); + YYUSE (img_ids); + YYUSE (errmsg); +# ifdef YYPRINT + if (yytype < YYNTOKENS) + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# else + YYUSE (yyoutput); +# endif + switch (yytype) + { + default: + break; + } +} + + +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg) +#else +static void +yy_symbol_print (yyoutput, yytype, yyvaluep, yylocationp, mc, vm, img_ids, errmsg) + FILE *yyoutput; + int yytype; + YYSTYPE const * const yyvaluep; + YYLTYPE const * const yylocationp; + mem_collector * mc; + VirtualMachine * vm; + vector * img_ids; + char ** errmsg; +#endif +{ + if (yytype < YYNTOKENS) + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + YY_LOCATION_PRINT (yyoutput, *yylocationp); + YYFPRINTF (yyoutput, ": "); + yy_symbol_value_print (yyoutput, yytype, yyvaluep, yylocationp, mc, vm, img_ids, errmsg); + YYFPRINTF (yyoutput, ")"); +} + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (included). | +`------------------------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) +#else +static void +yy_stack_print (yybottom, yytop) + yytype_int16 *yybottom; + yytype_int16 *yytop; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (; yybottom <= yytop; yybottom++) + { + int yybot = *yybottom; + YYFPRINTF (stderr, " %d", yybot); + } + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (YYID (0)) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yy_reduce_print (YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg) +#else +static void +yy_reduce_print (yyvsp, yylsp, yyrule, mc, vm, img_ids, errmsg) + YYSTYPE *yyvsp; + YYLTYPE *yylsp; + int yyrule; + mem_collector * mc; + VirtualMachine * vm; + vector * img_ids; + char ** errmsg; +#endif +{ + int yynrhs = yyr2[yyrule]; + int yyi; + unsigned long int yylno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", + yyrule - 1, yylno); + /* The symbols being reduced. */ + for (yyi = 0; yyi < yynrhs; yyi++) + { + YYFPRINTF (stderr, " $%d = ", yyi + 1); + yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], + &(yyvsp[(yyi + 1) - (yynrhs)]) + , &(yylsp[(yyi + 1) - (yynrhs)]) , mc, vm, img_ids, errmsg); + YYFPRINTF (stderr, "\n"); + } +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (yyvsp, yylsp, Rule, mc, vm, img_ids, errmsg); \ +} while (YYID (0)) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined __GLIBC__ && defined _STRING_H +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static YYSIZE_T +yystrlen (const char *yystr) +#else +static YYSIZE_T +yystrlen (yystr) + const char *yystr; +#endif +{ + YYSIZE_T yylen; + for (yylen = 0; yystr[yylen]; yylen++) + continue; + return yylen; +} +# endif +# endif + +# ifndef yystpcpy +# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static char * +yystpcpy (char *yydest, const char *yysrc) +#else +static char * +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +#endif +{ + char *yyd = yydest; + const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +# ifndef yytnamerr +/* Copy to YYRES the contents of YYSTR after stripping away unnecessary + quotes and backslashes, so that it's suitable for yyerror. The + heuristic is that double-quoting is unnecessary unless the string + contains an apostrophe, a comma, or backslash (other than + backslash-backslash). YYSTR is taken from yytname. If YYRES is + null, do not copy; instead, return the length of what the result + would have been. */ +static YYSIZE_T +yytnamerr (char *yyres, const char *yystr) +{ + if (*yystr == '"') + { + YYSIZE_T yyn = 0; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } + do_not_strip_quotes: ; + } + + if (! yyres) + return yystrlen (yystr); + + return yystpcpy (yyres, yystr) - yyres; +} +# endif + +/* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message + about the unexpected token YYTOKEN for the state stack whose top is + YYSSP. + + Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is + not large enough to hold the message. In that case, also set + *YYMSG_ALLOC to the required number of bytes. Return 2 if the + required number of bytes is too large to store. */ +static int +yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, + yytype_int16 *yyssp, int yytoken) +{ + YYSIZE_T yysize0 = yytnamerr (YY_NULL, yytname[yytoken]); + YYSIZE_T yysize = yysize0; + YYSIZE_T yysize1; + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + /* Internationalized format string. */ + const char *yyformat = YY_NULL; + /* Arguments of yyformat. */ + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + /* Number of reported tokens (one for the "unexpected", one per + "expected"). */ + int yycount = 0; + + /* There are many possibilities here to consider: + - Assume YYFAIL is not used. It's too flawed to consider. See + + for details. YYERROR is fine as it does not invoke this + function. + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yychar) is if + this state is a consistent state with a default action. Thus, + detecting the absence of a lookahead is sufficient to determine + that there is no unexpected or expected token to report. In that + case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is a + consistent state with a default action. There might have been a + previous inconsistent state, consistent state with a non-default + action, or user semantic action that manipulated yychar. + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state merging + (from LALR or IELR) and default reductions corrupt the expected + token list. However, the list is correct for canonical LR with + one exception: it will still contain any token that will not be + accepted due to an error action in a later state. + */ + if (yytoken != YYEMPTY) + { + int yyn = yypact[*yyssp]; + yyarg[yycount++] = yytname[yytoken]; + if (!yypact_value_is_default (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + yysize1 = yysize + yytnamerr (YY_NULL, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } + + switch (yycount) + { +# define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +# undef YYCASE_ + } + + yysize1 = yysize + yystrlen (yyformat); + if (! (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + + if (*yymsg_alloc < yysize) + { + *yymsg_alloc = 2 * yysize; + if (! (yysize <= *yymsg_alloc + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + return 1; + } + + /* Avoid sprintf, as that infringes on the user's name space. + Don't have undefined behavior even if the translation + produced a string with the wrong number of "%s"s. */ + { + char *yyp = *yymsg; + int yyi = 0; + while ((*yyp = *yyformat) != '\0') + if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } + else + { + yyp++; + yyformat++; + } + } + return 0; +} +#endif /* YYERROR_VERBOSE */ + +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +/*ARGSUSED*/ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +static void +yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep, YYLTYPE *yylocationp, mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg) +#else +static void +yydestruct (yymsg, yytype, yyvaluep, yylocationp, mc, vm, img_ids, errmsg) + const char *yymsg; + int yytype; + YYSTYPE *yyvaluep; + YYLTYPE *yylocationp; + mem_collector * mc; + VirtualMachine * vm; + vector * img_ids; + char ** errmsg; +#endif +{ + YYUSE (yyvaluep); + YYUSE (yylocationp); + YYUSE (mc); + YYUSE (vm); + YYUSE (img_ids); + YYUSE (errmsg); + + if (!yymsg) + yymsg = "Deleting"; + YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); + + switch (yytype) + { + + default: + break; + } +} + + + + +/*----------. +| yyparse. | +`----------*/ + +#ifdef YYPARSE_PARAM +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (void *YYPARSE_PARAM) +#else +int +yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +#endif +#else /* ! YYPARSE_PARAM */ +#if (defined __STDC__ || defined __C99__FUNC__ \ + || defined __cplusplus || defined _MSC_VER) +int +yyparse (mem_collector * mc, VirtualMachine * vm, vector * img_ids, char ** errmsg) +#else +int +yyparse (mc, vm, img_ids, errmsg) + mem_collector * mc; + VirtualMachine * vm; + vector * img_ids; + char ** errmsg; +#endif +#endif +{ +/* The lookahead symbol. */ +int yychar; + + +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +/* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ +static YYSTYPE yyval_default; +# define YY_INITIAL_VALUE(Value) = Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); + +/* Location data for the lookahead symbol. */ +YYLTYPE yylloc +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + = { 1, 1, 1, 1 } +# endif +; + + + /* Number of syntax errors so far. */ + int yynerrs; + + int yystate; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + + /* The stacks and their tools: + `yyss': related to states. + `yyvs': related to semantic values. + `yyls': related to locations. + + Refer to the stacks through separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + yytype_int16 yyssa[YYINITDEPTH]; + yytype_int16 *yyss; + yytype_int16 *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs; + YYSTYPE *yyvsp; + + /* The location stack. */ + YYLTYPE yylsa[YYINITDEPTH]; + YYLTYPE *yyls; + YYLTYPE *yylsp; + + /* The locations where the error started and ended. */ + YYLTYPE yyerror_range[3]; + + YYSIZE_T yystacksize; + + int yyn; + int yyresult; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + YYLTYPE yyloc; + +#if YYERROR_VERBOSE + /* Buffer for error messages, and its allocated size. */ + char yymsgbuf[128]; + char *yymsg = yymsgbuf; + YYSIZE_T yymsg_alloc = sizeof yymsgbuf; +#endif + +#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N), yylsp -= (N)) + + /* The number of symbols on the RHS of the reduced rule. + Keep to zero when no symbol should be popped. */ + int yylen = 0; + + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yylsp = yyls = yylsa; + yystacksize = YYINITDEPTH; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + yylsp[0] = yylloc; + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. So pushing a state here evens the stacks. */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + YYLTYPE *yyls1 = yyls; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yyls1, yysize * sizeof (*yylsp), + &yystacksize); + + yyls = yyls1; + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyexhaustedlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyexhaustedlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); + YYSTACK_RELOCATE (yyls_alloc, yyls); +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + yylsp = yyls + yysize - 1; + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + if (yystate == YYFINAL) + YYACCEPT; + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + + /* Do appropriate processing given the current state. Read a + lookahead token if we need one and don't already have one. */ + + /* First try to decide what to do without reference to lookahead token. */ + yyn = yypact[yystate]; + if (yypact_value_is_default (yyn)) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yytable_value_is_error (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + /* Shift the lookahead token. */ + YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); + + /* Discard the shifted token. */ + yychar = YYEMPTY; + + yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + *++yylsp = yylloc; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + /* Default location. */ + YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen); + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 4: +/* Line 1778 of yacc.c */ +#line 208 "vm_file_var_syntax.y" + { + string file((yyvsp[(1) - (7)].val_str)); + string var1((yyvsp[(3) - (7)].val_str)); + string val1((yyvsp[(5) - (7)].val_str)); + + string result; + + VM_VAR_TO_UPPER(file); + VM_VAR_TO_UPPER(var1); + + if (get_image_path(vm, file, var1, val1, "", "", img_ids, result) == -1) + { + img_ids->clear(); + *errmsg = strdup(result.c_str()); + YYABORT; + } + } + break; + + case 5: +/* Line 1778 of yacc.c */ +#line 226 "vm_file_var_syntax.y" + { + string file((yyvsp[(1) - (11)].val_str)); + string var1((yyvsp[(3) - (11)].val_str)); + string val1((yyvsp[(5) - (11)].val_str)); + string var2((yyvsp[(7) - (11)].val_str)); + string val2((yyvsp[(9) - (11)].val_str)); + + string result; + + VM_VAR_TO_UPPER(file); + VM_VAR_TO_UPPER(var1); + VM_VAR_TO_UPPER(var2); + + if (get_image_path(vm, file, var1, val1, var2, val2, img_ids, result) == -1) + { + img_ids->clear(); + *errmsg = strdup(result.c_str()); + YYABORT; + } + } + break; + + +/* Line 1778 of yacc.c */ +#line 1677 "vm_file_var_syntax.cc" + default: break; + } + /* User semantic actions sometimes alter yychar, and that requires + that yytoken be updated with the new translation. We take the + approach of translating immediately before every use of yytoken. + One alternative is translating here after every semantic action, + but that translation would be missed if the semantic action invokes + YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or + if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an + incorrect destructor might then be invoked immediately. In the + case of YYERROR or YYBACKUP, subsequent parser actions might lead + to an incorrect destructor call or verbose syntax error message + before the lookahead is translated. */ + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); + + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + *++yylsp = yyloc; + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar); + + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if ! YYERROR_VERBOSE + yyerror (&yylloc, mc, vm, img_ids, errmsg, YY_("syntax error")); +#else +# define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ + yyssp, yytoken) + { + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (&yylloc, mc, vm, img_ids, errmsg, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; + } +# undef YYSYNTAX_ERROR +#endif + } + + yyerror_range[1] = yylloc; + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + if (yychar <= YYEOF) + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } + else + { + yydestruct ("Error: discarding", + yytoken, &yylval, &yylloc, mc, vm, img_ids, errmsg); + yychar = YYEMPTY; + } + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*---------------------------------------------------. +| yyerrorlab -- error raised explicitly by YYERROR. | +`---------------------------------------------------*/ +yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (/*CONSTCOND*/ 0) + goto yyerrorlab; + + yyerror_range[1] = yylsp[1-yylen]; + /* Do not reclaim the symbols of the rule which action triggered + this YYERROR. */ + YYPOPSTACK (yylen); + yylen = 0; + YY_STACK_PRINT (yyss, yyssp); + yystate = *yyssp; + goto yyerrlab1; + + +/*-------------------------------------------------------------. +| yyerrlab1 -- common code for both syntax error and YYERROR. | +`-------------------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (!yypact_value_is_default (yyn)) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + yyerror_range[1] = *yylsp; + yydestruct ("Error: popping", + yystos[yystate], yyvsp, yylsp, mc, vm, img_ids, errmsg); + YYPOPSTACK (1); + yystate = *yyssp; + YY_STACK_PRINT (yyss, yyssp); + } + + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN + *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END + + yyerror_range[2] = yylloc; + /* Using YYLLOC is tempting, but would change the location of + the lookahead. YYLOC is available though. */ + YYLLOC_DEFAULT (yyloc, yyerror_range, 2); + *++yylsp = yyloc; + + /* Shift the error token. */ + YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#if !defined yyoverflow || YYERROR_VERBOSE +/*-------------------------------------------------. +| yyexhaustedlab -- memory exhaustion comes here. | +`-------------------------------------------------*/ +yyexhaustedlab: + yyerror (&yylloc, mc, vm, img_ids, errmsg, YY_("memory exhausted")); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: + if (yychar != YYEMPTY) + { + /* Make sure we have latest lookahead translation. See comments at + user semantic actions for why this is necessary. */ + yytoken = YYTRANSLATE (yychar); + yydestruct ("Cleanup: discarding lookahead", + yytoken, &yylval, &yylloc, mc, vm, img_ids, errmsg); + } + /* Do not reclaim the symbols of the rule which action triggered + this YYABORT or YYACCEPT. */ + YYPOPSTACK (yylen); + YY_STACK_PRINT (yyss, yyssp); + while (yyssp != yyss) + { + yydestruct ("Cleanup: popping", + yystos[*yyssp], yyvsp, yylsp, mc, vm, img_ids, errmsg); + YYPOPSTACK (1); + } +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif +#if YYERROR_VERBOSE + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); +#endif + /* Make sure YYID is used. */ + return YYID (yyresult); +} + + +/* Line 2041 of yacc.c */ +#line 247 "vm_file_var_syntax.y" + + +extern "C" void vm_file_var__error( + YYLTYPE * llocp, + mem_collector * mc, + VirtualMachine * vm, + vector * img_ids, + char ** error_msg, + const char * str) +{ + int length; + + length = strlen(str)+ 64; + + *error_msg = (char *) malloc(sizeof(char)*length); + + if (*error_msg != 0) + { + snprintf(*error_msg, + length, + "%s at line %i, columns %i:%i", + str, + llocp->first_line, + llocp->first_column, + llocp->last_column); + } +} diff --git a/src/vm/vm_file_var_syntax.h b/src/vm/vm_file_var_syntax.h new file mode 100644 index 0000000000..b638e005f3 --- /dev/null +++ b/src/vm/vm_file_var_syntax.h @@ -0,0 +1,94 @@ +/* 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 . */ + +/* As a special exception, you may create a larger work that contains + part or all of the Bison parser skeleton and distribute that work + under terms of your choice, so long as that work isn't itself a + parser generator using the skeleton or a modified version thereof + as a parser skeleton. Alternatively, if you modify or redistribute + the parser skeleton itself, you may (at your option) remove this + 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. */ + +#ifndef YY_VM_FILE_VAR_VM_FILE_VAR_SYNTAX_HH_INCLUDED +# define YY_VM_FILE_VAR_VM_FILE_VAR_SYNTAX_HH_INCLUDED +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif +#if YYDEBUG +extern int vm_file_var__debug; +#endif + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + EQUAL = 258, + COMMA = 259, + OBRACKET = 260, + CBRACKET = 261, + EOA = 262, + STRING = 263, + VARIABLE = 264, + RSTRING = 265, + INTEGER = 266 + }; +#endif + + +#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED +typedef union YYSTYPE +{ +/* Line 2042 of yacc.c */ +#line 178 "vm_file_var_syntax.y" + + char * val_str; + int val_int; + char val_char; + + +/* Line 2042 of yacc.c */ +#line 75 "vm_file_var_syntax.hh" +} YYSTYPE; +# define YYSTYPE_IS_TRIVIAL 1 +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +#endif + +#if ! defined YYLTYPE && ! defined YYLTYPE_IS_DECLARED +typedef struct YYLTYPE +{ + int first_line; + int first_column; + int last_line; + int last_column; +} YYLTYPE; +# define yyltype YYLTYPE /* obsolescent; will be withdrawn */ +# define YYLTYPE_IS_DECLARED 1 +# define YYLTYPE_IS_TRIVIAL 1 +#endif + +#endif /* !YY_VM_FILE_VAR_VM_FILE_VAR_SYNTAX_HH_INCLUDED */ diff --git a/src/vm/vm_file_var_syntax.y b/src/vm/vm_file_var_syntax.y new file mode 100644 index 0000000000..4d9bd17a9d --- /dev/null +++ b/src/vm/vm_file_var_syntax.y @@ -0,0 +1,273 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ +/* not use this file except in compliance with the License. You may obtain */ +/* a copy of the License at */ +/* */ +/* http://www.apache.org/licenses/LICENSE-2.0 */ +/* */ +/* Unless required by applicable law or agreed to in writing, software */ +/* distributed under the License is distributed on an "AS IS" BASIS, */ +/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ +/* See the License for the specific language governing permissions and */ +/* limitations under the License. */ +/* -------------------------------------------------------------------------- */ + +%{ +#include +#include +#include +#include +#include + +#include +#include + +#include "vm_file_var_syntax.h" +#include "ImagePool.h" +#include "UserPool.h" +#include "VirtualMachine.h" +#include "Nebula.h" + +#define vm_file_var__lex vm_var_lex + +#define YYERROR_VERBOSE +#define VM_VAR_TO_UPPER(S) transform (S.begin(),S.end(),S.begin(), \ +(int(*)(int))toupper) + +extern "C" +{ + #include "mem_collector.h" + + void vm_file_var__error( + YYLTYPE * llocp, + mem_collector * mc, + VirtualMachine * vm, + vector * img_ids, + char ** errmsg, + const char * str); + + int vm_file_var__lex (YYSTYPE *lvalp, YYLTYPE *llocp, mem_collector * mc); + + int vm_file_var__parse (mem_collector * mc, + VirtualMachine * vm, + vector * img_ids, + char ** errmsg); + + int vm_file_var_parse (VirtualMachine * vm, + vector * img_ids, + char ** errmsg) + { + mem_collector mc; + int rc; + + mem_collector_init(&mc); + + rc = vm_file_var__parse(&mc, vm, img_ids, errmsg); + + mem_collector_cleanup(&mc); + + return rc; + } +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +int get_image_path(VirtualMachine * vm, + const string& var_name, + const string& var1, + const string& val1, + const string& var2, + const string& val2, + vector * img_ids, + string& error_str) +{ + Nebula& nd = Nebula::instance(); + + ImagePool * ipool = nd.get_ipool(); + Image * img = 0; + int iid = -1; + + PoolObjectAuth perm; + + if (var_name != "FILE" ) + { + error_str = "Must use FILE variable for attribute."; + return -1; + } + + if ( var1 == "IMAGE" ) + { + int uid = vm->get_uid(); + + if ( !var2.empty() ) + { + VectorAttribute * vfile; + map file_values; + + file_values.insert(make_pair(var1, val1)); + file_values.insert(make_pair(var2, val2)); + + vfile = new VectorAttribute("FILE", file_values); + uid = ImagePool::get_disk_uid(vfile, uid); + + delete vfile; + } + + img = ipool->get(val1, uid, true); + } + else if ( var1 == "IMAGE_ID" ) + { + iid = ImagePool::get_disk_id(val1); + + if ( iid != -1 ) + { + img = ipool->get(iid, true); + } + } + + if ( img == 0 ) + { + error_str = "Cannot get image (check name/ID or try IMAGE_UNAME or IMAGE_UID)."; + return -1; + } + + iid = img->get_oid(); + + 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()); + + ar.add_auth(AuthRequest::USE, perm); + + if (UserPool::authorize(ar) == -1) + { + error_str = "User not authorize to use image."; + return -1; + } + + img_ids->push_back(iid); + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +%} + +%parse-param {mem_collector * mc} +%parse-param {VirtualMachine * vm} +%parse-param {vector * img_ids} +%parse-param {char ** errmsg} + +%lex-param {mem_collector * mc} + +%union { + char * val_str; + int val_int; + char val_char; +}; + +%defines +%locations +%pure_parser +%name-prefix = "vm_file_var__" +%output = "vm_file_var_syntax.cc" + +%token EQUAL COMMA OBRACKET CBRACKET + +%token EOA +%token STRING +%token VARIABLE +%token RSTRING +%token INTEGER +%type vm_variable +%type vm_string + +%% + +vm_string: vm_variable + | vm_string vm_variable + ; + +vm_variable: + VARIABLE OBRACKET VARIABLE EQUAL STRING CBRACKET EOA + { + string file($1); + string var1($3); + string val1($5); + + string result; + + VM_VAR_TO_UPPER(file); + VM_VAR_TO_UPPER(var1); + + if (get_image_path(vm, file, var1, val1, "", "", img_ids, result) == -1) + { + img_ids->clear(); + *errmsg = strdup(result.c_str()); + YYABORT; + } + } + | VARIABLE OBRACKET VARIABLE EQUAL STRING COMMA VARIABLE EQUAL STRING CBRACKET EOA + { + string file($1); + string var1($3); + string val1($5); + string var2($7); + string val2($9); + + string result; + + VM_VAR_TO_UPPER(file); + VM_VAR_TO_UPPER(var1); + VM_VAR_TO_UPPER(var2); + + if (get_image_path(vm, file, var1, val1, var2, val2, img_ids, result) == -1) + { + img_ids->clear(); + *errmsg = strdup(result.c_str()); + YYABORT; + } + } + ; +%% + +extern "C" void vm_file_var__error( + YYLTYPE * llocp, + mem_collector * mc, + VirtualMachine * vm, + vector * img_ids, + char ** error_msg, + const char * str) +{ + int length; + + length = strlen(str)+ 64; + + *error_msg = (char *) malloc(sizeof(char)*length); + + if (*error_msg != 0) + { + snprintf(*error_msg, + length, + "%s at line %i, columns %i:%i", + str, + llocp->first_line, + llocp->first_column, + llocp->last_column); + } +} diff --git a/src/vm/vm_var_syntax.cc b/src/vm/vm_var_syntax.cc index 69020fac24..baa15c5c3c 100644 --- a/src/vm/vm_var_syntax.cc +++ b/src/vm/vm_var_syntax.cc @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.2. */ +/* A Bison parser, made by GNU Bison 2.6.5. */ /* Bison implementation for Yacc-like parsers in C @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.6.2" +#define YYBISON_VERSION "2.6.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -70,7 +70,7 @@ #define yylloc vm_var__lloc /* Copy the first part of user declarations. */ -/* Line 336 of yacc.c */ +/* Line 360 of yacc.c */ #line 17 "vm_var_syntax.y" #include @@ -463,7 +463,7 @@ void insert_vector(VirtualMachine * vm, /* -------------------------------------------------------------------------- */ -/* Line 336 of yacc.c */ +/* Line 360 of yacc.c */ #line 468 "vm_var_syntax.cc" # ifndef YY_NULL @@ -484,8 +484,8 @@ void insert_vector(VirtualMachine * vm, /* In a future release of Bison, this section will be replaced by #include "vm_var_syntax.hh". */ -#ifndef VM_VAR_VM_VAR_SYNTAX_HH -# define VM_VAR_VM_VAR_SYNTAX_HH +#ifndef YY_VM_VAR_VM_VAR_SYNTAX_HH_INCLUDED +# define YY_VM_VAR_VM_VAR_SYNTAX_HH_INCLUDED /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG 0 @@ -516,7 +516,7 @@ extern int vm_var__debug; #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { -/* Line 350 of yacc.c */ +/* Line 376 of yacc.c */ #line 416 "vm_var_syntax.y" char * val_str; @@ -524,7 +524,7 @@ typedef union YYSTYPE char val_char; -/* Line 350 of yacc.c */ +/* Line 376 of yacc.c */ #line 529 "vm_var_syntax.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 @@ -560,11 +560,11 @@ int vm_var__parse (); #endif #endif /* ! YYPARSE_PARAM */ -#endif /* !VM_VAR_VM_VAR_SYNTAX_HH */ +#endif /* !YY_VM_VAR_VM_VAR_SYNTAX_HH_INCLUDED */ /* Copy the second part of user declarations. */ -/* Line 353 of yacc.c */ +/* Line 379 of yacc.c */ #line 569 "vm_var_syntax.cc" #ifdef short @@ -618,24 +618,24 @@ typedef short int yytype_int16; # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YYUSE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YYUSE(E) /* empty */ #endif /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint -# define YYID(n) (n) +# define YYID(N) (N) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) @@ -933,10 +933,10 @@ static const yytype_uint8 yytable[] = 2, 12, 13, 14, 15, 16, 8, 0, 17 }; -#define yypact_value_is_default(yystate) \ - ((yystate) == (-5)) +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-5))) -#define yytable_value_is_error(yytable_value) \ +#define yytable_value_is_error(Yytable_value) \ YYID (0) static const yytype_int8 yycheck[] = @@ -997,10 +997,11 @@ do \ } \ while (YYID (0)) - +/* Error token number */ #define YYTERROR 1 #define YYERRCODE 256 + /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ @@ -1028,17 +1029,20 @@ while (YYID (0)) #define YYRHSLOC(Rhs, K) ((Rhs)[K]) - /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) +# define YY_LOCATION_PRINT(File, Loc) \ + do { \ + fprintf (File, "%d.%d", (Loc).first_line, (Loc).first_column); \ + if ((Loc).first_line < (Loc).last_line) \ + fprintf (File, "-%d.%d", (Loc).last_line, (Loc).last_column - 1); \ + else if ((Loc).first_column < (Loc).last_column - 1) \ + fprintf (File, "-%d", (Loc).last_column - 1); \ + } while (0) # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif @@ -1046,7 +1050,6 @@ while (YYID (0)) /* YYLEX -- calling `yylex' with the right arguments. */ - #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) #else @@ -1572,11 +1575,39 @@ yyparse (mc, vm, parsed, errmsg) /* The lookahead symbol. */ int yychar; + +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +/* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ +static YYSTYPE yyval_default; +# define YY_INITIAL_VALUE(Value) = Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; +YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); /* Location data for the lookahead symbol. */ -YYLTYPE yylloc; +YYLTYPE yylloc +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + = { 1, 1, 1, 1 } +# endif +; + /* Number of syntax errors so far. */ int yynerrs; @@ -1616,7 +1647,7 @@ YYLTYPE yylloc; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken; + int yytoken = 0; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -1635,10 +1666,9 @@ YYLTYPE yylloc; Keep to zero when no symbol should be popped. */ int yylen = 0; - yytoken = 0; - yyss = yyssa; - yyvs = yyvsa; - yyls = yylsa; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yylsp = yyls = yylsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1647,20 +1677,7 @@ YYLTYPE yylloc; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - yyssp = yyss; - yyvsp = yyvs; - yylsp = yyls; - -#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL - /* Initialize the default location before parsing starts. */ - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = 1; -#endif + yylsp[0] = yylloc; goto yysetstate; /*------------------------------------------------------------. @@ -1806,7 +1823,9 @@ yybackup: yychar = YYEMPTY; yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END *++yylsp = yylloc; goto yynewstate; @@ -1844,7 +1863,7 @@ yyreduce: switch (yyn) { case 4: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 445 "vm_var_syntax.y" { (*parsed) << (yyvsp[(1) - (1)].val_str); @@ -1852,7 +1871,7 @@ yyreduce: break; case 5: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 449 "vm_var_syntax.y" { string name((yyvsp[(1) - (2)].val_str)); @@ -1869,7 +1888,7 @@ yyreduce: break; case 6: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 462 "vm_var_syntax.y" { string name((yyvsp[(1) - (5)].val_str)); @@ -1888,7 +1907,7 @@ yyreduce: break; case 7: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 477 "vm_var_syntax.y" { string name((yyvsp[(1) - (9)].val_str)); @@ -1910,8 +1929,8 @@ yyreduce: break; -/* Line 1787 of yacc.c */ -#line 1915 "vm_var_syntax.cc" +/* Line 1778 of yacc.c */ +#line 1934 "vm_var_syntax.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -2076,7 +2095,9 @@ yyerrlab1: YY_STACK_PRINT (yyss, yyssp); } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of @@ -2147,7 +2168,7 @@ yyreturn: } -/* Line 2048 of yacc.c */ +/* Line 2041 of yacc.c */ #line 495 "vm_var_syntax.y" diff --git a/src/vm/vm_var_syntax.h b/src/vm/vm_var_syntax.h index a38408222f..0ea16d629e 100644 --- a/src/vm/vm_var_syntax.h +++ b/src/vm/vm_var_syntax.h @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.2. */ +/* A Bison parser, made by GNU Bison 2.6.5. */ /* Bison interface for Yacc-like parsers in C @@ -30,8 +30,8 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -#ifndef VM_VAR_VM_VAR_SYNTAX_HH -# define VM_VAR_VM_VAR_SYNTAX_HH +#ifndef YY_VM_VAR_VM_VAR_SYNTAX_HH_INCLUDED +# define YY_VM_VAR_VM_VAR_SYNTAX_HH_INCLUDED /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG 0 @@ -62,7 +62,7 @@ extern int vm_var__debug; #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { -/* Line 2049 of yacc.c */ +/* Line 2042 of yacc.c */ #line 416 "vm_var_syntax.y" char * val_str; @@ -70,7 +70,7 @@ typedef union YYSTYPE char val_char; -/* Line 2049 of yacc.c */ +/* Line 2042 of yacc.c */ #line 75 "vm_var_syntax.hh" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 @@ -91,4 +91,4 @@ typedef struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif -#endif /* !VM_VAR_VM_VAR_SYNTAX_HH */ +#endif /* !YY_VM_VAR_VM_VAR_SYNTAX_HH_INCLUDED */ diff --git a/src/xml/expr_arith.cc b/src/xml/expr_arith.cc index d41579103f..73bb7dfe23 100644 --- a/src/xml/expr_arith.cc +++ b/src/xml/expr_arith.cc @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.2. */ +/* A Bison parser, made by GNU Bison 2.6.5. */ /* Bison implementation for Yacc-like parsers in C @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.6.2" +#define YYBISON_VERSION "2.6.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -70,7 +70,7 @@ #define yylloc expr_arith__lloc /* Copy the first part of user declarations. */ -/* Line 336 of yacc.c */ +/* Line 360 of yacc.c */ #line 17 "expr_arith.y" #include @@ -125,7 +125,7 @@ extern "C" } -/* Line 336 of yacc.c */ +/* Line 360 of yacc.c */ #line 130 "expr_arith.cc" # ifndef YY_NULL @@ -146,8 +146,8 @@ extern "C" /* In a future release of Bison, this section will be replaced by #include "expr_arith.hh". */ -#ifndef EXPR_ARITH_EXPR_ARITH_HH -# define EXPR_ARITH_EXPR_ARITH_HH +#ifndef YY_EXPR_ARITH_EXPR_ARITH_HH_INCLUDED +# define YY_EXPR_ARITH_EXPR_ARITH_HH_INCLUDED /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG 0 @@ -172,7 +172,7 @@ extern int expr_arith__debug; #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { -/* Line 350 of yacc.c */ +/* Line 376 of yacc.c */ #line 78 "expr_arith.y" char * val_str; @@ -180,7 +180,7 @@ typedef union YYSTYPE float val_float; -/* Line 350 of yacc.c */ +/* Line 376 of yacc.c */ #line 185 "expr_arith.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 @@ -216,11 +216,11 @@ int expr_arith__parse (); #endif #endif /* ! YYPARSE_PARAM */ -#endif /* !EXPR_ARITH_EXPR_ARITH_HH */ +#endif /* !YY_EXPR_ARITH_EXPR_ARITH_HH_INCLUDED */ /* Copy the second part of user declarations. */ -/* Line 353 of yacc.c */ +/* Line 379 of yacc.c */ #line 225 "expr_arith.cc" #ifdef short @@ -274,24 +274,24 @@ typedef short int yytype_int16; # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YYUSE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YYUSE(E) /* empty */ #endif /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint -# define YYID(n) (n) +# define YYID(N) (N) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) @@ -594,10 +594,10 @@ static const yytype_uint8 yytable[] = 4, 5, 11, 12, 13, 14 }; -#define yypact_value_is_default(yystate) \ - ((yystate) == (-5)) +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-5))) -#define yytable_value_is_error(yytable_value) \ +#define yytable_value_is_error(Yytable_value) \ YYID (0) static const yytype_int8 yycheck[] = @@ -659,10 +659,11 @@ do \ } \ while (YYID (0)) - +/* Error token number */ #define YYTERROR 1 #define YYERRCODE 256 + /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ @@ -690,17 +691,20 @@ while (YYID (0)) #define YYRHSLOC(Rhs, K) ((Rhs)[K]) - /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) +# define YY_LOCATION_PRINT(File, Loc) \ + do { \ + fprintf (File, "%d.%d", (Loc).first_line, (Loc).first_column); \ + if ((Loc).first_line < (Loc).last_line) \ + fprintf (File, "-%d.%d", (Loc).last_line, (Loc).last_column - 1); \ + else if ((Loc).first_column < (Loc).last_column - 1) \ + fprintf (File, "-%d", (Loc).last_column - 1); \ + } while (0) # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif @@ -708,7 +712,6 @@ while (YYID (0)) /* YYLEX -- calling `yylex' with the right arguments. */ - #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) #else @@ -1234,11 +1237,39 @@ yyparse (mc, oxml, result, error_msg) /* The lookahead symbol. */ int yychar; + +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +/* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ +static YYSTYPE yyval_default; +# define YY_INITIAL_VALUE(Value) = Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; +YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); /* Location data for the lookahead symbol. */ -YYLTYPE yylloc; +YYLTYPE yylloc +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + = { 1, 1, 1, 1 } +# endif +; + /* Number of syntax errors so far. */ int yynerrs; @@ -1278,7 +1309,7 @@ YYLTYPE yylloc; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken; + int yytoken = 0; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -1297,10 +1328,9 @@ YYLTYPE yylloc; Keep to zero when no symbol should be popped. */ int yylen = 0; - yytoken = 0; - yyss = yyssa; - yyvs = yyvsa; - yyls = yylsa; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yylsp = yyls = yylsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1309,20 +1339,7 @@ YYLTYPE yylloc; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - yyssp = yyss; - yyvsp = yyvs; - yylsp = yyls; - -#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL - /* Initialize the default location before parsing starts. */ - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = 1; -#endif + yylsp[0] = yylloc; goto yysetstate; /*------------------------------------------------------------. @@ -1468,7 +1485,9 @@ yybackup: yychar = YYEMPTY; yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END *++yylsp = yylloc; goto yynewstate; @@ -1506,19 +1525,19 @@ yyreduce: switch (yyn) { case 2: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 100 "expr_arith.y" { result = static_cast((yyvsp[(1) - (1)].val_float));} break; case 3: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 101 "expr_arith.y" { result = 0; } break; case 4: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 104 "expr_arith.y" { float val = 0.0; @@ -1548,56 +1567,56 @@ yyreduce: break; case 5: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 129 "expr_arith.y" { (yyval.val_float) = (yyvsp[(1) - (1)].val_float); } break; case 6: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 130 "expr_arith.y" { (yyval.val_float) = static_cast((yyvsp[(1) - (1)].val_int)); } break; case 7: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 131 "expr_arith.y" { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) + (yyvsp[(3) - (3)].val_float);} break; case 8: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 132 "expr_arith.y" { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) - (yyvsp[(3) - (3)].val_float);} break; case 9: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 133 "expr_arith.y" { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) * (yyvsp[(3) - (3)].val_float);} break; case 10: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 134 "expr_arith.y" { (yyval.val_float) = (yyvsp[(1) - (3)].val_float) / (yyvsp[(3) - (3)].val_float);} break; case 11: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 135 "expr_arith.y" { (yyval.val_float) = - (yyvsp[(2) - (2)].val_float);} break; case 12: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 136 "expr_arith.y" { (yyval.val_float) = (yyvsp[(2) - (3)].val_float);} break; -/* Line 1787 of yacc.c */ -#line 1601 "expr_arith.cc" +/* Line 1778 of yacc.c */ +#line 1620 "expr_arith.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1762,7 +1781,9 @@ yyerrlab1: YY_STACK_PRINT (yyss, yyssp); } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of @@ -1833,7 +1854,7 @@ yyreturn: } -/* Line 2048 of yacc.c */ +/* Line 2041 of yacc.c */ #line 139 "expr_arith.y" diff --git a/src/xml/expr_arith.h b/src/xml/expr_arith.h index 4268fbef40..dca7a5d771 100644 --- a/src/xml/expr_arith.h +++ b/src/xml/expr_arith.h @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.2. */ +/* A Bison parser, made by GNU Bison 2.6.5. */ /* Bison interface for Yacc-like parsers in C @@ -30,8 +30,8 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -#ifndef EXPR_ARITH_EXPR_ARITH_HH -# define EXPR_ARITH_EXPR_ARITH_HH +#ifndef YY_EXPR_ARITH_EXPR_ARITH_HH_INCLUDED +# define YY_EXPR_ARITH_EXPR_ARITH_HH_INCLUDED /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG 0 @@ -56,7 +56,7 @@ extern int expr_arith__debug; #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { -/* Line 2049 of yacc.c */ +/* Line 2042 of yacc.c */ #line 78 "expr_arith.y" char * val_str; @@ -64,7 +64,7 @@ typedef union YYSTYPE float val_float; -/* Line 2049 of yacc.c */ +/* Line 2042 of yacc.c */ #line 69 "expr_arith.hh" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 @@ -85,4 +85,4 @@ typedef struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif -#endif /* !EXPR_ARITH_EXPR_ARITH_HH */ +#endif /* !YY_EXPR_ARITH_EXPR_ARITH_HH_INCLUDED */ diff --git a/src/xml/expr_bool.cc b/src/xml/expr_bool.cc index b5833d45fc..61dc13cef7 100644 --- a/src/xml/expr_bool.cc +++ b/src/xml/expr_bool.cc @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.2. */ +/* A Bison parser, made by GNU Bison 2.6.5. */ /* Bison implementation for Yacc-like parsers in C @@ -44,7 +44,7 @@ #define YYBISON 1 /* Bison version. */ -#define YYBISON_VERSION "2.6.2" +#define YYBISON_VERSION "2.6.5" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" @@ -70,7 +70,7 @@ #define yylloc expr_bool__lloc /* Copy the first part of user declarations. */ -/* Line 336 of yacc.c */ +/* Line 360 of yacc.c */ #line 17 "expr_bool.y" #include @@ -130,7 +130,7 @@ void get_xml_attribute(ObjectXML * oxml, const char* attr, float& val); void get_xml_attribute(ObjectXML * oxml, const char* attr, string& val); -/* Line 336 of yacc.c */ +/* Line 360 of yacc.c */ #line 135 "expr_bool.cc" # ifndef YY_NULL @@ -151,8 +151,8 @@ void get_xml_attribute(ObjectXML * oxml, const char* attr, string& val); /* In a future release of Bison, this section will be replaced by #include "expr_bool.hh". */ -#ifndef EXPR_BOOL_EXPR_BOOL_HH -# define EXPR_BOOL_EXPR_BOOL_HH +#ifndef YY_EXPR_BOOL_EXPR_BOOL_HH_INCLUDED +# define YY_EXPR_BOOL_EXPR_BOOL_HH_INCLUDED /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG 0 @@ -177,7 +177,7 @@ extern int expr_bool__debug; #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { -/* Line 350 of yacc.c */ +/* Line 376 of yacc.c */ #line 83 "expr_bool.y" char * val_str; @@ -185,7 +185,7 @@ typedef union YYSTYPE float val_float; -/* Line 350 of yacc.c */ +/* Line 376 of yacc.c */ #line 190 "expr_bool.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 @@ -221,11 +221,11 @@ int expr_bool__parse (); #endif #endif /* ! YYPARSE_PARAM */ -#endif /* !EXPR_BOOL_EXPR_BOOL_HH */ +#endif /* !YY_EXPR_BOOL_EXPR_BOOL_HH_INCLUDED */ /* Copy the second part of user declarations. */ -/* Line 353 of yacc.c */ +/* Line 379 of yacc.c */ #line 230 "expr_bool.cc" #ifdef short @@ -279,24 +279,24 @@ typedef short int yytype_int16; # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ -# define YY_(msgid) dgettext ("bison-runtime", msgid) +# define YY_(Msgid) dgettext ("bison-runtime", Msgid) # endif # endif # ifndef YY_ -# define YY_(msgid) msgid +# define YY_(Msgid) Msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ -# define YYUSE(e) ((void) (e)) +# define YYUSE(E) ((void) (E)) #else -# define YYUSE(e) /* empty */ +# define YYUSE(E) /* empty */ #endif /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint -# define YYID(n) (n) +# define YYID(N) (N) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) @@ -604,10 +604,10 @@ static const yytype_uint8 yytable[] = 16, 17, 18, 26, 27, 28, 19, 21, 20, 22 }; -#define yypact_value_is_default(yystate) \ - ((yystate) == (-6)) +#define yypact_value_is_default(Yystate) \ + (!!((Yystate) == (-6))) -#define yytable_value_is_error(yytable_value) \ +#define yytable_value_is_error(Yytable_value) \ YYID (0) static const yytype_int8 yycheck[] = @@ -670,10 +670,11 @@ do \ } \ while (YYID (0)) - +/* Error token number */ #define YYTERROR 1 #define YYERRCODE 256 + /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ @@ -701,17 +702,20 @@ while (YYID (0)) #define YYRHSLOC(Rhs, K) ((Rhs)[K]) - /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL -# define YY_LOCATION_PRINT(File, Loc) \ - fprintf (File, "%d.%d-%d.%d", \ - (Loc).first_line, (Loc).first_column, \ - (Loc).last_line, (Loc).last_column) +# define YY_LOCATION_PRINT(File, Loc) \ + do { \ + fprintf (File, "%d.%d", (Loc).first_line, (Loc).first_column); \ + if ((Loc).first_line < (Loc).last_line) \ + fprintf (File, "-%d.%d", (Loc).last_line, (Loc).last_column - 1); \ + else if ((Loc).first_column < (Loc).last_column - 1) \ + fprintf (File, "-%d", (Loc).last_column - 1); \ + } while (0) # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif @@ -719,7 +723,6 @@ while (YYID (0)) /* YYLEX -- calling `yylex' with the right arguments. */ - #ifdef YYLEX_PARAM # define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM) #else @@ -1245,11 +1248,39 @@ yyparse (mc, oxml, result, error_msg) /* The lookahead symbol. */ int yychar; + +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +/* Default value used for initialization, for pacifying older GCCs + or non-GCC compilers. */ +static YYSTYPE yyval_default; +# define YY_INITIAL_VALUE(Value) = Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + /* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; +YYSTYPE yylval YY_INITIAL_VALUE(yyval_default); /* Location data for the lookahead symbol. */ -YYLTYPE yylloc; +YYLTYPE yylloc +# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL + = { 1, 1, 1, 1 } +# endif +; + /* Number of syntax errors so far. */ int yynerrs; @@ -1289,7 +1320,7 @@ YYLTYPE yylloc; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ - int yytoken; + int yytoken = 0; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; @@ -1308,10 +1339,9 @@ YYLTYPE yylloc; Keep to zero when no symbol should be popped. */ int yylen = 0; - yytoken = 0; - yyss = yyssa; - yyvs = yyvsa; - yyls = yylsa; + yyssp = yyss = yyssa; + yyvsp = yyvs = yyvsa; + yylsp = yyls = yylsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); @@ -1320,20 +1350,7 @@ YYLTYPE yylloc; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ - - /* Initialize stack pointers. - Waste one element of value and location stack - so that they stay on the same level as the state stack. - The wasted elements are never initialized. */ - yyssp = yyss; - yyvsp = yyvs; - yylsp = yyls; - -#if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL - /* Initialize the default location before parsing starts. */ - yylloc.first_line = yylloc.last_line = 1; - yylloc.first_column = yylloc.last_column = 1; -#endif + yylsp[0] = yylloc; goto yysetstate; /*------------------------------------------------------------. @@ -1479,7 +1496,9 @@ yybackup: yychar = YYEMPTY; yystate = yyn; + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END *++yylsp = yylloc; goto yynewstate; @@ -1517,19 +1536,19 @@ yyreduce: switch (yyn) { case 2: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 103 "expr_bool.y" { result=(yyvsp[(1) - (1)].val_int); } break; case 3: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 104 "expr_bool.y" { result=true; } break; case 4: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 107 "expr_bool.y" { int val; @@ -1538,7 +1557,7 @@ yyreduce: break; case 5: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 112 "expr_bool.y" { int val; @@ -1547,7 +1566,7 @@ yyreduce: break; case 6: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 117 "expr_bool.y" { int val; @@ -1556,7 +1575,7 @@ yyreduce: break; case 7: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 122 "expr_bool.y" { int val; @@ -1565,7 +1584,7 @@ yyreduce: break; case 8: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 127 "expr_bool.y" { float val; @@ -1574,7 +1593,7 @@ yyreduce: break; case 9: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 132 "expr_bool.y" { float val; @@ -1583,7 +1602,7 @@ yyreduce: break; case 10: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 137 "expr_bool.y" { float val; @@ -1592,7 +1611,7 @@ yyreduce: break; case 11: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 142 "expr_bool.y" { float val; @@ -1601,7 +1620,7 @@ yyreduce: break; case 12: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 147 "expr_bool.y" { string val; @@ -1610,7 +1629,7 @@ yyreduce: break; case 13: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 152 "expr_bool.y" { string val; @@ -1619,32 +1638,32 @@ yyreduce: break; case 14: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 157 "expr_bool.y" { (yyval.val_int) = (yyvsp[(1) - (3)].val_int) && (yyvsp[(3) - (3)].val_int); } break; case 15: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 158 "expr_bool.y" { (yyval.val_int) = (yyvsp[(1) - (3)].val_int) || (yyvsp[(3) - (3)].val_int); } break; case 16: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 159 "expr_bool.y" { (yyval.val_int) = ! (yyvsp[(2) - (2)].val_int); } break; case 17: -/* Line 1787 of yacc.c */ +/* Line 1778 of yacc.c */ #line 160 "expr_bool.y" { (yyval.val_int) = (yyvsp[(2) - (3)].val_int); } break; -/* Line 1787 of yacc.c */ -#line 1648 "expr_bool.cc" +/* Line 1778 of yacc.c */ +#line 1667 "expr_bool.cc" default: break; } /* User semantic actions sometimes alter yychar, and that requires @@ -1809,7 +1828,9 @@ yyerrlab1: YY_STACK_PRINT (yyss, yyssp); } + YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN *++yyvsp = yylval; + YY_IGNORE_MAYBE_UNINITIALIZED_END yyerror_range[2] = yylloc; /* Using YYLLOC is tempting, but would change the location of @@ -1880,7 +1901,7 @@ yyreturn: } -/* Line 2048 of yacc.c */ +/* Line 2041 of yacc.c */ #line 163 "expr_bool.y" diff --git a/src/xml/expr_bool.h b/src/xml/expr_bool.h index 73a9d063b2..8d56fec616 100644 --- a/src/xml/expr_bool.h +++ b/src/xml/expr_bool.h @@ -1,4 +1,4 @@ -/* A Bison parser, made by GNU Bison 2.6.2. */ +/* A Bison parser, made by GNU Bison 2.6.5. */ /* Bison interface for Yacc-like parsers in C @@ -30,8 +30,8 @@ This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ -#ifndef EXPR_BOOL_EXPR_BOOL_HH -# define EXPR_BOOL_EXPR_BOOL_HH +#ifndef YY_EXPR_BOOL_EXPR_BOOL_HH_INCLUDED +# define YY_EXPR_BOOL_EXPR_BOOL_HH_INCLUDED /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG 0 @@ -56,7 +56,7 @@ extern int expr_bool__debug; #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { -/* Line 2049 of yacc.c */ +/* Line 2042 of yacc.c */ #line 83 "expr_bool.y" char * val_str; @@ -64,7 +64,7 @@ typedef union YYSTYPE float val_float; -/* Line 2049 of yacc.c */ +/* Line 2042 of yacc.c */ #line 69 "expr_bool.hh" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 @@ -85,4 +85,4 @@ typedef struct YYLTYPE # define YYLTYPE_IS_TRIVIAL 1 #endif -#endif /* !EXPR_BOOL_EXPR_BOOL_HH */ +#endif /* !YY_EXPR_BOOL_EXPR_BOOL_HH_INCLUDED */