mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
Updates image when acquired/released
This commit is contained in:
parent
fa96d8a7e2
commit
6e3d697d9e
@ -140,16 +140,17 @@ public:
|
||||
|
||||
/**
|
||||
* Get an image to be used in a VM, and updates its state.
|
||||
* @param overwrite true if the image is going to be overwritten
|
||||
* @return 0 if success
|
||||
* @param overwrite true if the image is going to be overwritten
|
||||
* @return 0 if success
|
||||
*/
|
||||
int acquire_image(bool overwrite);
|
||||
|
||||
|
||||
/**
|
||||
* Releases an image being used by a VM
|
||||
* @return true if the image needs to be updated
|
||||
*/
|
||||
void release_image();
|
||||
bool release_image();
|
||||
|
||||
/**
|
||||
* Enables the image
|
||||
|
@ -522,8 +522,10 @@ int Image::acquire_image(bool overwrite)
|
||||
/* ------------------------------------------------------------------------ */
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
void Image::release_image()
|
||||
bool Image::release_image()
|
||||
{
|
||||
bool dirty = false;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case USED:
|
||||
@ -534,6 +536,8 @@ void Image::release_image()
|
||||
{
|
||||
state = READY;
|
||||
}
|
||||
|
||||
dirty = true;
|
||||
break;
|
||||
|
||||
case DISABLED:
|
||||
@ -541,6 +545,8 @@ void Image::release_image()
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return dirty;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
@ -550,22 +556,14 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
int * index,
|
||||
ImageType& img_type)
|
||||
{
|
||||
string overwrite;
|
||||
string saveas;
|
||||
string bus;
|
||||
|
||||
ostringstream iid;
|
||||
|
||||
img_type = type;
|
||||
|
||||
overwrite = disk->vector_value("OVERWRITE");
|
||||
saveas = disk->vector_value("SAVE_AS");
|
||||
bus = disk->vector_value("BUS");
|
||||
bus = disk->vector_value("BUS");
|
||||
iid << oid;
|
||||
|
||||
transform(overwrite.begin(), overwrite.end(), overwrite.begin(),
|
||||
(int(*)(int))toupper);
|
||||
|
||||
string template_bus;
|
||||
string prefix;
|
||||
|
||||
@ -576,7 +574,7 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
// Acquire the image
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
if ( acquire_image(overwrite == "YES") != 0 )
|
||||
if ( acquire_image(true) != 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -591,16 +589,6 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
new_disk.insert(make_pair("IMAGE_ID", iid.str()));
|
||||
new_disk.insert(make_pair("SOURCE", source));
|
||||
|
||||
if (!overwrite.empty())
|
||||
{
|
||||
new_disk.insert(make_pair("OVERWRITE",overwrite));
|
||||
}
|
||||
|
||||
if (!saveas.empty())
|
||||
{
|
||||
new_disk.insert(make_pair("SAVE_AS",saveas));
|
||||
}
|
||||
|
||||
if (bus.empty())
|
||||
{
|
||||
if (!template_bus.empty())
|
||||
@ -624,17 +612,17 @@ int Image::disk_attribute( VectorAttribute * disk,
|
||||
new_disk.insert(make_pair("TYPE","DISK"));
|
||||
new_disk.insert(make_pair("READONLY","NO"));
|
||||
|
||||
if (overwrite == "YES")
|
||||
// if (overwrite == "YES")
|
||||
{
|
||||
new_disk.insert(make_pair("CLONE","NO"));
|
||||
new_disk.insert(make_pair("SAVE","YES"));
|
||||
}
|
||||
else if (!saveas.empty())
|
||||
// else if (!saveas.empty())
|
||||
{
|
||||
new_disk.insert(make_pair("CLONE","YES"));
|
||||
new_disk.insert(make_pair("SAVE","YES"));
|
||||
}
|
||||
else
|
||||
// else
|
||||
{
|
||||
new_disk.insert(make_pair("CLONE","YES"));
|
||||
new_disk.insert(make_pair("SAVE","NO"));
|
||||
|
@ -206,6 +206,11 @@ int ImagePool::disk_attribute( VectorAttribute * disk,
|
||||
|
||||
int rc = img->disk_attribute(disk,index, img_type);
|
||||
|
||||
if ( rc == 0 )
|
||||
{
|
||||
update(img);
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
|
||||
return rc;
|
||||
|
@ -967,7 +967,10 @@ void VirtualMachine::release_disk_images()
|
||||
continue;
|
||||
}
|
||||
|
||||
img->release_image();
|
||||
if (img->release_image() == true)
|
||||
{
|
||||
ipool->update(img);
|
||||
}
|
||||
|
||||
img->unlock();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user