1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-22 22:03:39 +03:00

Feature #1678: Make all disk related variables long long

This commit is contained in:
Carlos Martín 2013-10-17 12:35:19 +02:00 committed by Javi Fontan
parent e68e95035e
commit 5f8af5cf39
23 changed files with 208 additions and 66 deletions

View File

@ -265,6 +265,16 @@ public:
*/
int vector_value(const char *name, int& value) const;
/**
* Returns the long long value
*
* @param name Name of the attribute
* @param value Long long value
*
* @return 0 on success, -1 otherwise
*/
int vector_value(const char *name, long long& value) const;
/**
* Returns the float value
*
@ -347,6 +357,18 @@ public:
replace(name, oss.str());
}
/**
* Replace the value of the given vector attribute
*/
void replace(const string& name, long long value)
{
ostringstream oss;
oss << value;
replace(name, oss.str());
}
/**
* Replace the value of the given vector attribute
*/

View File

@ -163,7 +163,7 @@ public:
* @param free_mb
* @param used_mb
*/
void update_monitor(unsigned int total, unsigned int free, unsigned int used)
void update_monitor(long long total, long long free, long long used)
{
total_mb = total;
free_mb = free;
@ -176,7 +176,7 @@ public:
* @return true if the datastore is configured to enforce capacity
* checkings
*/
bool get_avail_mb(unsigned int &avail);
bool get_avail_mb(long long &avail);
private:
@ -218,17 +218,17 @@ private:
/**
* Total datastore capacity in MB
*/
unsigned int total_mb;
long long total_mb;
/**
* Available datastore capacity in MB
*/
unsigned int free_mb;
long long free_mb;
/**
* Used datastore capacity in MB
*/
unsigned int used_mb;
long long used_mb;
// *************************************************************************
// Constructor

View File

@ -204,9 +204,9 @@ public:
/**
* Returns the size of the image
* @return size in mb
* @return size in MB
*/
int get_size() const
long long get_size() const
{
return size_mb;
}
@ -222,7 +222,7 @@ public:
/**
* Sets the size for the image
*/
void set_size(unsigned int _size_mb)
void set_size(long long _size_mb)
{
size_mb = _size_mb;
}
@ -563,7 +563,7 @@ private:
/**
* Size of the image in MB
*/
unsigned int size_mb;
long long size_mb;
/**
* Image state

View File

@ -382,6 +382,22 @@ public:
return obj_template->get(name,value);
}
/**
* Gets a long long based attribute (single)
* @param name of the attribute
* @param value of the attribute (long long), will be 0 if not defined or
* not a single attribute
*
* @return True if the Single attribute was found and is a valid integer
* value
*/
bool get_template_attribute(
const char * name,
long long& value) const
{
return obj_template->get(name,value);
}
/**
* Gets a float based attribute (single)
* @param name of the attribute

View File

@ -159,6 +159,22 @@ public:
return replace(name, oss.str());
}
/**
* Adds a new attribute to the template (replacing it if
* already defined)
* @param name of the new attribute
* @param value of the new attribute
* @return 0 on success
*/
int replace(const string& name, long long value)
{
ostringstream oss;
oss << value;
return replace(name, oss.str());
}
/*
* Adds a new single attribute to the template. It will replace an existing
* one if replace_mode was set to true
@ -184,6 +200,20 @@ public:
set(new SingleAttribute(name, oss.str()));
}
/**
* Adds a new single attribute to the template.
* @param name of the attribute
* @param value of the attribute
*/
void add(const string& name, long long value)
{
ostringstream oss;
oss << value;
set(new SingleAttribute(name, oss.str()));
}
/**
* Adds a new single attribute to the template.
* @param name of the attribute
@ -266,6 +296,19 @@ public:
const string& name,
int& value) const;
/**
* Gets the value of a Single attributes (long long) with the given name.
* @param name the attribute name.
* @param value the attribute value, a long long, 0 if the attribute is not
* defined or not Single
*
* @return True if the Single attribute was found and is a valid integer
* value
*/
virtual bool get(
const string& name,
long long& value) const;
/**
* Gets the value of a Single attributes (float) with the given name.
* @param name the attribute name.

View File

@ -1081,7 +1081,7 @@ public:
/**
* Return the total SIZE of volatile disks
*/
static float get_volatile_disk_size(Template * tmpl);
static long long get_volatile_disk_size(Template * tmpl);
// ------------------------------------------------------------------------
// Context related functions

View File

@ -281,6 +281,36 @@ int VectorAttribute::vector_value(const char *name, int & value) const
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VectorAttribute::vector_value(const char *name, long long& value) const
{
map<string,string>::const_iterator it;
it = attribute_value.find(name);
if ( it == attribute_value.end() )
{
return -1;
}
if ( it->second.empty() )
{
return -1;
}
istringstream iss(it->second);
iss >> value;
if (iss.fail() || !iss.eof())
{
return -1;
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VectorAttribute::vector_value(const char *name, float & value) const
{
map<string,string>::const_iterator it;

View File

@ -587,16 +587,16 @@ int Datastore::replace_template(const string& tmpl_str, string& error_str)
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
bool Datastore::get_avail_mb(unsigned int &avail)
bool Datastore::get_avail_mb(long long &avail)
{
float max_used_size;
bool check;
long long max_used_size;
bool check;
avail = free_mb;
if (get_template_attribute("MAX_USED_SIZE", max_used_size))
{
if (used_mb >= (unsigned int) max_used_size)
if (used_mb >= max_used_size)
{
avail = 0;
}

View File

@ -516,9 +516,7 @@ int Image::disk_attribute( VectorAttribute * disk,
disk->replace("IMAGE", name);
disk->replace("IMAGE_ID", iid.str());
disk->replace("SOURCE", source);
// TODO: move all size values (image, volatile disk, quotas) to long long
disk->replace("SIZE", (int)size_mb);
disk->replace("SIZE", size_mb);
if (driver.empty() && !template_driver.empty())//DRIVER in Image,not in DISK
{

View File

@ -398,7 +398,7 @@ int ImageManager::delete_image(int iid, const string& ds_data, string& error_str
string img_tmpl;
string * drv_msg;
int size;
long long size;
int ds_id;
int uid;

View File

@ -637,8 +637,8 @@ static void monitor_action(istringstream& is,
delete dsinfo;
float total, free, used;
string ds_name;
long long total, free, used;
string ds_name;
monitor_data.get("TOTAL_MB", total);
monitor_data.get("FREE_MB", free);

View File

@ -313,7 +313,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
string error_str;
string size_str;
int size_mb;
long long size_mb;
istringstream iss;
string ds_name;
@ -342,7 +342,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
Datastore * ds;
Image::DiskType ds_disk_type;
unsigned int avail;
long long avail;
int umask;
bool ds_check;
@ -441,7 +441,7 @@ void ImageAllocate::request_execute(xmlrpc_c::paramList const& params,
return;
}
if (ds_check && ((unsigned int) size_mb > avail))
if (ds_check && (size_mb > avail))
{
failure_response(ACTION, "Not enough space in datastore", att);

View File

@ -229,8 +229,8 @@ void ImageClone::request_execute(
int clone_id = xmlrpc_c::value_int(paramList.getInt(1));
string name = xmlrpc_c::value_string(paramList.getString(2));
unsigned int avail;
int rc, new_id, ds_id, size, umask;
long long avail, size;
int rc, new_id, ds_id, umask;
string error_str, ds_name, ds_data;
bool ds_check;
@ -347,7 +347,7 @@ void ImageClone::request_execute(
img_usage.add("DATASTORE", ds_id);
img_usage.add("SIZE", size);
if (ds_check && ((unsigned int) size > avail))
if (ds_check && (size > avail))
{
failure_response(ACTION, "Not enough space in datastore", att);

View File

@ -1097,9 +1097,9 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
return;
}
int ds_id = img->get_ds_id();
string ds_name = img->get_ds_name();
int size = img->get_size();
int ds_id = img->get_ds_id();
string ds_name = img->get_ds_name();
long long size = img->get_size();
Image::ImageType type = img->get_type();
@ -1147,7 +1147,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
string ds_data;
PoolObjectAuth ds_perms;
unsigned int avail;
long long avail;
bool ds_check;
ds->get_permissions(ds_perms);
@ -1162,7 +1162,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
// -------------------------------------------------------------------------
// Check Datastore Capacity
// -------------------------------------------------------------------------
if (ds_check && ((unsigned int) size > avail))
if (ds_check && (size > avail))
{
failure_response(ACTION, "Not enough space in datastore", att);

View File

@ -40,7 +40,7 @@ public:
* @param vm_disk_mb capacity needed by the VM
* @return true if the datastore can host the VM
*/
bool test_capacity(unsigned int vm_disk_mb) const
bool test_capacity(long long vm_disk_mb) const
{
return (vm_disk_mb < free_mb);
};
@ -50,7 +50,7 @@ public:
* @param vm_disk_mb capacity needed by the VM
* @return 0 on success
*/
void add_capacity(unsigned int vm_disk_mb)
void add_capacity(long long vm_disk_mb)
{
free_mb += vm_disk_mb;
};
@ -70,7 +70,7 @@ private:
int oid;
int cluster_id;
unsigned int free_mb; /**< Free disk for VMs (in Mb). */
long long free_mb; /**< Free disk for VMs (in MB). */
static const char *ds_paths[]; /**< paths for search function */

View File

@ -109,9 +109,9 @@ public:
return ds_requirements;
}
void get_requirements (int& cpu, int& memory, int& disk);
void get_requirements (int& cpu, int& memory, long long& disk);
map<int,float> get_storage_usage();
map<int,long long> get_storage_usage();
//--------------------------------------------------------------------------
// Matched Resources Interface
@ -274,11 +274,11 @@ protected:
int resched;
int memory;
float cpu;
float system_ds_usage;
int memory;
float cpu;
long long system_ds_usage;
map<int,float> ds_usage;
map<int,long long> ds_usage;
string rank;
string requirements;

View File

@ -35,9 +35,7 @@ void DatastoreXML::init_attributes()
{
oid = atoi(((*this)["/DATASTORE/ID"] )[0].c_str() );
cluster_id = atoi(((*this)["/DATASTORE/CLUSTER_ID"] )[0].c_str() );
free_mb = static_cast<unsigned int>(
atol(((*this)["/DATASTORE/FREE_MB"])[0].c_str()));
free_mb = atoll(((*this)["/DATASTORE/FREE_MB"])[0].c_str());
ObjectXML::paths = ds_paths;
ObjectXML::num_paths = ds_num_paths;

View File

@ -49,14 +49,15 @@ int VirtualMachinePoolXML::set_up()
oss << "Storage usage:" << endl;
int tmp, disk;
int tmp;
long long disk;
for (it=objects.begin();it!=objects.end();it++)
{
VirtualMachineXML * vm = static_cast<VirtualMachineXML *>(it->second);
map<int,float> ds_usage = vm->get_storage_usage();
map<int,float>::iterator ds_it;
map<int,long long> ds_usage = vm->get_storage_usage();
map<int,long long>::const_iterator ds_it;
oss << "VM " << vm->get_oid() << ": ";

View File

@ -250,7 +250,7 @@ ostream& operator<<(ostream& os, VirtualMachineXML& vm)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineXML::get_requirements (int& cpu, int& memory, int& disk)
void VirtualMachineXML::get_requirements (int& cpu, int& memory, long long& disk)
{
if (this->memory == 0 || this->cpu == 0)
{
@ -279,7 +279,7 @@ bool isVolatile(const VectorAttribute * disk)
return ( type == "SWAP" || type == "FS");
}
map<int,float> VirtualMachineXML::get_storage_usage()
map<int,long long> VirtualMachineXML::get_storage_usage()
{
return ds_usage;
}
@ -289,10 +289,10 @@ void VirtualMachineXML::init_storage_usage()
vector<Attribute *> disks;
vector<Attribute*>::iterator it;
float size;
string st;
int ds_id;
bool clone;
long long size;
string st;
int ds_id;
bool clone;
system_ds_usage = 0;

View File

@ -385,7 +385,7 @@ void Scheduler::match_schedule()
int vm_memory;
int vm_cpu;
int vm_disk;
long long vm_disk;
int oid;
int uid;
@ -409,7 +409,7 @@ void Scheduler::match_schedule()
map<int, ObjectXML*>::const_iterator vm_it;
map<int, ObjectXML*>::const_iterator h_it;
map<int, ObjectXML*>::const_iterator ds_it;
map<int,float>::const_iterator ds_usage_it;
map<int,long long>::const_iterator ds_usage_it;
vector<SchedulerPolicy *>::iterator it;
@ -435,7 +435,7 @@ void Scheduler::match_schedule()
n_auth = 0;
n_error = 0;
map<int,float> ds_usage = vm->get_storage_usage();
map<int,long long> ds_usage = vm->get_storage_usage();
for (ds_usage_it = ds_usage.begin(); ds_usage_it != ds_usage.end(); ds_usage_it++)
{
@ -449,7 +449,7 @@ void Scheduler::match_schedule()
ds = static_cast<DatastoreXML *>( ds_it->second );
if (!ds->test_capacity((unsigned int) ds_usage_it->second))
if (!ds->test_capacity(ds_usage_it->second))
{
ostringstream oss;
@ -777,7 +777,8 @@ void Scheduler::dispatch()
ostringstream oss;
int cpu, mem, dsk;
int cpu, mem;
long long dsk;
int hid, dsid, cid;
unsigned int dispatched_vms = 0;

View File

@ -450,6 +450,36 @@ bool Template::get(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool Template::get(
const string& name,
long long& value) const
{
string sval;
get(name, sval);
if ( sval == "" )
{
value = 0;
return false;
}
istringstream iss(sval);
iss >> value;
if (iss.fail() || !iss.eof())
{
value = 0;
return false;
}
return true;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
bool Template::get(
const string& name,
float& value) const

View File

@ -57,8 +57,9 @@ bool QuotaVirtualMachine::check(Template * tmpl,
{
map<string, float> vm_request;
int memory;
float cpu, size;
int memory;
float cpu;
long long size;
if ( tmpl->get("MEMORY", memory) == false || memory <= 0 )
{
@ -89,8 +90,9 @@ void QuotaVirtualMachine::del(Template * tmpl)
{
map<string, float> vm_request;
int memory, vms;
float cpu, size;
int memory, vms;
float cpu;
long long size;
if ( tmpl->get("MEMORY", memory) == false )
{
@ -137,8 +139,9 @@ bool QuotaVirtualMachine::update(Template * tmpl,
{
map<string, float> vm_request;
int delta_memory;
float delta_cpu, delta_size;
int delta_memory;
float delta_cpu;
long long delta_size;
if ( tmpl->get("MEMORY", delta_memory) == true )
{

View File

@ -2060,9 +2060,9 @@ bool VirtualMachine::isVolatile(const Template * tmpl)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
float VirtualMachine::get_volatile_disk_size(Template * tmpl)
long long VirtualMachine::get_volatile_disk_size(Template * tmpl)
{
float size = 0;
long long size = 0;
vector<const Attribute*> disks;
int num_disks = tmpl->get("DISK", disks);
@ -2074,7 +2074,7 @@ float VirtualMachine::get_volatile_disk_size(Template * tmpl)
for (int i = 0 ; i < num_disks ; i++)
{
float disk_size;
long long disk_size;
const VectorAttribute * disk = dynamic_cast<const VectorAttribute*>(disks[i]);
if (disk == 0)