1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-25 02:50:08 +03:00

Feature #1112: Fix save_as image state update when VMs in failed state are deleted

This commit is contained in:
Carlos Martín 2012-03-06 18:44:22 +01:00
parent c9cc70dc81
commit ea70484edc
6 changed files with 81 additions and 66 deletions

View File

@ -243,6 +243,16 @@ public:
*/
string vector_value(const char *name) const;
/**
* Returns the integer value
*
* @param name Name of the attribute
* @param value Integer value
*
* @return 0 on success, -1 otherwise
*/
int vector_value(const char *name, int & value) const;
/**
* Marshall the attribute in a single string. The string MUST be freed
* by the calling function. The string is in the form:

View File

@ -96,22 +96,6 @@ public:
*/
Image * acquire_image(const string& name, int uid, string& error);
/**
* Releases an image and triggers any needed operations in the repo
* @param iid image id of the image to be released
* @param failed the associated VM releasing the images is FAILED
*/
void release_image(const string& iid, bool failed)
{
int image_id;
istringstream iss;
iss.str(iid);
iss >> image_id;
release_image(image_id, failed);
};
/**
* Releases an image and triggers any needed operations in the repo
* @param iid image id of the image to be released

View File

@ -201,3 +201,27 @@ string VectorAttribute::vector_value(const char *name) const
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VectorAttribute::vector_value(const char *name, int & 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;
return 0;
}

View File

@ -616,16 +616,15 @@ int DispatchManager::finalize(
case VirtualMachine::PENDING:
case VirtualMachine::HOLD:
case VirtualMachine::STOPPED:
vm->release_network_leases();
vm->release_disk_images();
vm->set_exit_time(time(0));
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_state(VirtualMachine::DONE);
vmpool->update(vm);
vm->release_network_leases();
vm->release_disk_images();
vm->log("DiM", Log::INFO, "New VM state is DONE.");
break;

View File

@ -158,34 +158,39 @@ void ImageManager::release_image(int iid, bool failed)
{
img->set_state(Image::READY);
}
ipool->update(img);
}
else if ( rvms == 0 )
{
img->set_state(Image::READY);
ipool->update(img);
}
img->unlock();
break;
case Image::LOCKED: //SAVE_AS images are LOCKED till released
if (failed == true)
{
img->set_state(Image::ERROR);
}
else
{
img->set_state(Image::READY);
}
ipool->update(img);
img->unlock();
break;
break;
case Image::LOCKED: //SAVE_AS images are LOCKED till released
if ( img->isSaving() )
{
if (failed == true)
{
img->set_state(Image::ERROR);
}
else
{
img->set_state(Image::READY);
}
ipool->update(img);
}
else
{
NebulaLog::log("ImM",Log::ERROR,
"Trying to release image in wrong state.");
}
img->unlock();
break;
case Image::DISABLED:
case Image::READY:
case Image::ERROR:

View File

@ -949,8 +949,9 @@ error_common:
void VirtualMachine::release_disk_images()
{
string iid;
string saveas;
int iid;
int save_as_id;
int rc;
int num_disks;
vector<Attribute const * > disks;
@ -973,12 +974,19 @@ void VirtualMachine::release_disk_images()
continue;
}
iid = disk->vector_value("IMAGE_ID");
rc = disk->vector_value("IMAGE_ID", iid);
if ( !iid.empty() )
if ( rc == 0 )
{
imagem->release_image(iid, (state == FAILED));
}
rc = disk->vector_value("SAVE_AS", save_as_id);
if ( rc == 0 )
{
imagem->release_image(save_as_id, (state == FAILED));
}
}
}
@ -1131,27 +1139,6 @@ int VirtualMachine::generate_context(string &files)
return 1;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static int id_from_attr (VectorAttribute * attr, const char *name)
{
int id;
string id_str;
id_str = attr->vector_value(name);
if (id_str.empty())
{
return -1;
}
istringstream iss(id_str);
iss >> id;
return id;
}
/* -------------------------------------------------------------------------- */
int VirtualMachine::get_image_from_disk(int disk_id, string& error_str)
@ -1159,6 +1146,7 @@ int VirtualMachine::get_image_from_disk(int disk_id, string& error_str)
int num_disks;
int tid;
int iid = -1;
int rc;
vector<Attribute * > disks;
VectorAttribute * disk;
@ -1181,7 +1169,12 @@ int VirtualMachine::get_image_from_disk(int disk_id, string& error_str)
continue;
}
tid = id_from_attr(disk,"DISK_ID");
rc = disk->vector_value("DISK_ID", tid);
if ( rc != 0 )
{
continue;
}
if ( disk_id == tid )
{
@ -1195,9 +1188,9 @@ int VirtualMachine::get_image_from_disk(int disk_id, string& error_str)
goto error_persistent;
}
iid = id_from_attr(disk, "IMAGE_ID");
rc = disk->vector_value("IMAGE_ID", iid);
if (iid == -1)
if ( rc != 0 )
{
goto error_image_id;
}