diff --git a/include/ImageManager.h b/include/ImageManager.h index b205c3d59d..6016ea4f63 100644 --- a/include/ImageManager.h +++ b/include/ImageManager.h @@ -261,6 +261,12 @@ public: */ void set_image_snapshots(int iid, const Snapshots& s); + /** + * Clear the snapshots of an image by setting an empty set. + * @param iid id of image + */ + void clear_image_snapshots(int iid); + /** * Set the size for the given image. The image MUST be persistent * and of type OS or DATABLOCK. diff --git a/include/Snapshots.h b/include/Snapshots.h index d895bc70ff..72284a104b 100644 --- a/include/Snapshots.h +++ b/include/Snapshots.h @@ -157,6 +157,14 @@ public: return snapshot_pool.size(); }; + /** + * @return true if snapshot_pool is empty + */ + bool empty() const + { + return snapshot_pool.empty(); + }; + /** * Check if snapshot exists * @param snap_id of the snapshot diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index 3439cad2d8..1f71e873f0 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -1027,7 +1027,14 @@ void ImageManager::set_image_snapshots(int iid, const Snapshots& s) return; } - img->set_snapshots(s); + if (s.empty()) + { + img->clear_snapshots(); + } + else + { + img->set_snapshots(s); + } ipool->update(img); @@ -1037,6 +1044,16 @@ void ImageManager::set_image_snapshots(int iid, const Snapshots& s) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void ImageManager::clear_image_snapshots(int iid) +{ + Snapshots _snaps(-1, false); + + set_image_snapshots(iid, _snaps); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void ImageManager::set_image_size(int iid, long long size) { Image * img = ipool->get(iid); diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index b3888512f6..905bd96f39 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -1871,7 +1871,6 @@ void LifeCycleManager::disk_snapshot_success(int vid) const VirtualMachineDisk * disk; Snapshots snaps(-1, false); const Snapshots* tmp_snaps; - bool has_snaps = false; string error_str; VirtualMachine * vm = vmpool->get(vid); @@ -1925,10 +1924,8 @@ void LifeCycleManager::disk_snapshot_success(int vid) vm->clear_snapshot_disk(); tmp_snaps = vm->get_disk_snapshots(disk_id, error_str); - - if(tmp_snaps != 0) + if (tmp_snaps != 0) { - has_snaps = true; snaps = *tmp_snaps; } @@ -1976,7 +1973,7 @@ void LifeCycleManager::disk_snapshot_success(int vid) } // Update image if it is persistent and ln mode does not clone it - if ( img_id != -1 && is_persistent && has_snaps && target == "NONE" ) + if ( img_id != -1 && is_persistent && target == "NONE" ) { imagem->set_image_snapshots(img_id, snaps); } @@ -2017,7 +2014,6 @@ void LifeCycleManager::disk_snapshot_failure(int vid) const VirtualMachineDisk* disk; Snapshots snaps(-1, false); const Snapshots* tmp_snaps; - bool has_snaps = false; string error_str; bool img_owner, vm_owner; @@ -2072,10 +2068,8 @@ void LifeCycleManager::disk_snapshot_failure(int vid) vm->clear_snapshot_disk(); tmp_snaps = vm->get_disk_snapshots(disk_id, error_str); - - if(tmp_snaps != 0) + if (tmp_snaps != 0) { - has_snaps = true; snaps = *tmp_snaps; } @@ -2123,7 +2117,7 @@ void LifeCycleManager::disk_snapshot_failure(int vid) } // Update image if it is persistent and ln mode does not clone it - if ( img_id != -1 && is_persistent && has_snaps && target != "SYSTEM" ) + if ( img_id != -1 && is_persistent && target != "SYSTEM" ) { imagem->set_image_snapshots(img_id, snaps); } diff --git a/src/vm/VirtualMachineDisk.cc b/src/vm/VirtualMachineDisk.cc index fe655eed6b..3beb746a4c 100644 --- a/src/vm/VirtualMachineDisk.cc +++ b/src/vm/VirtualMachineDisk.cc @@ -911,9 +911,15 @@ void VirtualMachineDisks::release_images(int vmid, bool image_error, } /* ------- Update snapshots on source image if needed ----------- */ - if ( (*it)->has_snapshots() ) + const Snapshots * snaps = (*it)->get_snapshots(); + + if (snaps != 0) { - imagem->set_image_snapshots(iid, *(*it)->get_snapshots()); + imagem->set_image_snapshots(iid, *snaps); + } + else + { + imagem->clear_image_snapshots(iid); } /* --------- Compute space to free on image datastore ----------- */ diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 4dd9e74b56..f8140a7750 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -1072,9 +1072,15 @@ void VirtualMachinePool::delete_attach_disk(int vid) Quotas::quota_del(Quotas::VM, uid, gid, &tmpl); } - if ( disk->has_snapshots() ) + const Snapshots * snaps = disk->get_snapshots(); + + if (snaps != 0) { - imagem->set_image_snapshots(image_id, *disk->get_snapshots()); + imagem->set_image_snapshots(image_id, *snaps); + } + else + { + imagem->clear_image_snapshots(image_id); } imagem->release_image(oid, image_id, false);