mirror of
https://github.com/OpenNebula/one.git
synced 2025-02-27 13:57:23 +03:00
B #1412: Fix missing condition when image was locked
This commit is contained in:
parent
5399f21a8e
commit
3cd612540f
@ -94,20 +94,20 @@ public:
|
||||
* Try to acquire an image from the repository for a VM.
|
||||
* @param image_id id of image
|
||||
* @param error string describing the error
|
||||
* @param attach indicates that are trying to make an attachment of the image
|
||||
* @param attach true if attaching the image to a VM
|
||||
* @return pointer to the image or 0 if could not be acquired
|
||||
*/
|
||||
Image * acquire_image(int vm_id, int image_id, string& error, bool attach);
|
||||
Image * acquire_image(int vm_id, int image_id, bool attach, string& error);
|
||||
|
||||
/**
|
||||
* Try to acquire an image from the repository for a VM.
|
||||
* @param name of the image
|
||||
* @param id of owner
|
||||
* @param error string describing the error
|
||||
* @param attach indicates that are trying to make an attachment of the image
|
||||
* @param attach true if attaching the image to a VM
|
||||
* @return pointer to the image or 0 if could not be acquired
|
||||
*/
|
||||
Image * acquire_image(int vm_id, const string& name, int uid, string& error, bool attach);
|
||||
Image * acquire_image(int vm_id, const string& name, int uid, bool attach, string& error);
|
||||
|
||||
/**
|
||||
* Releases an image and triggers any needed operations in the repo
|
||||
@ -360,10 +360,10 @@ private:
|
||||
/**
|
||||
* Acquires an image updating its state.
|
||||
* @param image pointer to image, it should be locked
|
||||
* @param attach indicates that are trying to make an attachment of the image
|
||||
* @param attach true if attaching the image to a VM
|
||||
* @return 0 on success
|
||||
*/
|
||||
int acquire_image(int vm_id, Image *img, string& error, bool attach);
|
||||
int acquire_image(int vm_id, Image *img, bool attach, string& error);
|
||||
|
||||
/**
|
||||
* Moves a file to an image in the repository
|
||||
|
@ -154,6 +154,7 @@ public:
|
||||
* @param uid of VM owner (to look for the image id within its images)
|
||||
* @param image_id on success returns the acquired image id
|
||||
* @param snaps list of snapshots associated to this image
|
||||
* @param attach true if attaching the image to a VM
|
||||
* @param error_str string describing the error
|
||||
*
|
||||
* @return 0 on success, -1 otherwise
|
||||
@ -166,8 +167,8 @@ public:
|
||||
int uid,
|
||||
int& image_id,
|
||||
Snapshots ** snaps,
|
||||
string& error_str,
|
||||
bool attach);
|
||||
bool attach,
|
||||
string& error_str);
|
||||
/**
|
||||
* Generates a DISK attribute for VM templates using the Image metadata
|
||||
*
|
||||
|
@ -25,7 +25,8 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Image * ImageManager::acquire_image(int vm_id, int image_id, string& error, bool attach)
|
||||
Image * ImageManager::acquire_image(int vm_id, int image_id, bool attach,
|
||||
string& error)
|
||||
{
|
||||
Image * img;
|
||||
int rc;
|
||||
@ -41,7 +42,7 @@ Image * ImageManager::acquire_image(int vm_id, int image_id, string& error, bool
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = acquire_image(vm_id, img, error, attach);
|
||||
rc = acquire_image(vm_id, img, attach, error);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -54,7 +55,8 @@ Image * ImageManager::acquire_image(int vm_id, int image_id, string& error, bool
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
Image * ImageManager::acquire_image(int vm_id, const string& name, int uid, string& error, bool attach)
|
||||
Image * ImageManager::acquire_image(int vm_id, const string& name, int uid,
|
||||
bool attach, string& error)
|
||||
{
|
||||
Image * img;
|
||||
int rc;
|
||||
@ -71,7 +73,7 @@ Image * ImageManager::acquire_image(int vm_id, const string& name, int uid, stri
|
||||
return 0;
|
||||
}
|
||||
|
||||
rc = acquire_image(vm_id, img, error, attach);
|
||||
rc = acquire_image(vm_id, img, attach, error);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
@ -84,7 +86,7 @@ Image * ImageManager::acquire_image(int vm_id, const string& name, int uid, stri
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int ImageManager::acquire_image(int vm_id, Image *img, string& error, bool attach)
|
||||
int ImageManager::acquire_image(int vm_id, Image *img, bool attach, string& error)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
@ -129,24 +131,26 @@ int ImageManager::acquire_image(int vm_id, Image *img, string& error, bool attac
|
||||
if (attach)
|
||||
{
|
||||
oss << "Cannot acquire image " << img->get_oid()
|
||||
<< ", it is locked";
|
||||
<< ", it is locked";
|
||||
|
||||
error = oss.str();
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
img->inc_running(vm_id);
|
||||
|
||||
if ( img->is_persistent() )
|
||||
{
|
||||
img->set_state(Image::LOCKED_USED_PERS);
|
||||
}
|
||||
else
|
||||
{
|
||||
img->set_state(Image::LOCKED_USED);
|
||||
}
|
||||
img->inc_running(vm_id);
|
||||
|
||||
ipool->update(img);
|
||||
if ( img->is_persistent() )
|
||||
{
|
||||
img->set_state(Image::LOCKED_USED_PERS);
|
||||
}
|
||||
else
|
||||
{
|
||||
img->set_state(Image::LOCKED_USED);
|
||||
}
|
||||
|
||||
ipool->update(img);
|
||||
}
|
||||
break;
|
||||
|
||||
case Image::USED_PERS:
|
||||
@ -162,18 +166,21 @@ int ImageManager::acquire_image(int vm_id, Image *img, string& error, bool attac
|
||||
img->inc_running(vm_id);
|
||||
ipool->update(img);
|
||||
break;
|
||||
|
||||
case Image::LOCKED_USED:
|
||||
if (attach)
|
||||
{
|
||||
oss << "Cannot acquire image " << img->get_oid()
|
||||
<< ", it is locked";
|
||||
<< ", it is locked";
|
||||
|
||||
error = oss.str();
|
||||
rc = -1;
|
||||
}
|
||||
|
||||
img->inc_running(vm_id);
|
||||
ipool->update(img);
|
||||
else
|
||||
{
|
||||
img->inc_running(vm_id);
|
||||
ipool->update(img);
|
||||
}
|
||||
break;
|
||||
|
||||
case Image::INIT:
|
||||
|
@ -297,8 +297,8 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
int uid,
|
||||
int& image_id,
|
||||
Snapshots ** snap,
|
||||
string& error_str,
|
||||
bool attach)
|
||||
bool attach,
|
||||
string& error_str)
|
||||
{
|
||||
string source;
|
||||
Image * img = 0;
|
||||
@ -315,7 +315,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
|
||||
if ( disk->vector_value("IMAGE_ID", iid) == 0 )
|
||||
{
|
||||
img = imagem->acquire_image(vm_id, iid, error_str, attach);
|
||||
img = imagem->acquire_image(vm_id, iid, attach, error_str);
|
||||
|
||||
if ( img == 0 )
|
||||
{
|
||||
@ -337,7 +337,7 @@ int ImagePool::acquire_disk(int vm_id,
|
||||
return -1;
|
||||
}
|
||||
|
||||
img = imagem->acquire_image(vm_id, source, uiid, error_str, attach);
|
||||
img = imagem->acquire_image(vm_id, source, uiid, attach, error_str);
|
||||
|
||||
if ( img == 0 )
|
||||
{
|
||||
|
@ -751,7 +751,7 @@ int VirtualMachineDisks::get_images(int vm_id, int uid, const std::string& tsys,
|
||||
}
|
||||
|
||||
if ( ipool->acquire_disk(vm_id, disk, disk_id, image_type, dev_prefix,
|
||||
uid, image_id, &snapshots, error_str, false) != 0 )
|
||||
uid, image_id, &snapshots, false, error_str) != 0 )
|
||||
{
|
||||
oss << "DISK " << disk_id << ": " << error_str;
|
||||
error_str = oss.str();
|
||||
@ -1076,7 +1076,7 @@ VirtualMachineDisk * VirtualMachineDisks::set_up_attach(int vmid, int uid,
|
||||
VirtualMachineDisk * disk = new VirtualMachineDisk(vdisk, max_disk_id + 1);
|
||||
|
||||
int rc = ipool->acquire_disk(vmid, disk, max_disk_id + 1, img_type,
|
||||
dev_prefix, uid, image_id, &snap, error, true);
|
||||
dev_prefix, uid, image_id, &snap, true, error);
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user