1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Feature #3782: Minor fixes to oned code

This commit is contained in:
Carlos Martín 2015-07-01 15:43:22 +02:00
parent e183a8c242
commit 143017e30d
9 changed files with 130 additions and 129 deletions

View File

@ -1566,8 +1566,8 @@ public:
* @param disk_id of the disk
* @param snap_id of the snapshot
*/
int get_snapshot_disk(string& ds_id, string& tm_mad, string& disk_id,
string& snap_id);
int get_snapshot_disk(int& ds_id, string& tm_mad, int& disk_id,
int& snap_id);
/**
* Unset the current disk being snapshotted (reverted...)
*/

View File

@ -1901,10 +1901,6 @@ int DispatchManager::disk_snapshot_delete(
default: break;
}
vmpool->update(vm);
vm->unlock();
return 0;
}

View File

@ -920,11 +920,6 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error)
return -1;
}
/* ---------------------------------------------------------------------- */
/* Check action consistency: */
/* state is READY */
/* snapshot can be deleted (not active, no childs, exists) */
/* ---------------------------------------------------------------------- */
Image * img = ipool->get(iid,true);
if ( img == 0 )
@ -933,21 +928,6 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error)
return -1;
}
if (img->get_state() != Image::READY)
{
error = "Cannot delete snapshot in state " + Image::state_to_str(img->get_state());
img->unlock();
return -1;
}
const Snapshots& snaps = img->get_snapshots();
if (!snaps.test_delete(sid, error))
{
img->unlock();
return -1;
}
/* ---------------------------------------------------------------------- */
/* Get DS data for driver */
/* ---------------------------------------------------------------------- */
@ -969,17 +949,37 @@ int ImageManager::delete_snapshot(int iid, int sid, string& error)
ds->unlock();
/* ---------------------------------------------------------------------- */
/* Check action consistency: */
/* state is READY */
/* snapshot can be deleted (not active, no childs, exists) */
/* ---------------------------------------------------------------------- */
img = ipool->get(iid,true);
/* ---------------------------------------------------------------------- */
/* Format message and send action to driver */
/* ---------------------------------------------------------------------- */
if ( img == 0 )
{
error = "Image does not exist";
return -1;
}
if (img->get_state() != Image::READY)
{
error = "Cannot delete snapshot in state " + Image::state_to_str(img->get_state());
img->unlock();
return -1;
}
const Snapshots& snaps = img->get_snapshots();
if (!snaps.test_delete(sid, error))
{
img->unlock();
return -1;
}
/* ---------------------------------------------------------------------- */
/* Format message and send action to driver */
/* ---------------------------------------------------------------------- */
img->set_target_snapshot(sid);
string img_tmpl;
@ -1013,14 +1013,42 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error)
return -1;
}
Image * img = ipool->get(iid,true);
if ( img == 0 )
{
error = "Image does not exist";
return -1;
}
/* ---------------------------------------------------------------------- */
/* Get DS data for driver */
/* ---------------------------------------------------------------------- */
int ds_id = img->get_ds_id();
img->unlock();
string ds_data;
Datastore * ds = dspool->get(ds_id, true);
if ( ds == 0 )
{
error = "Datastore no longer exists";
return -1;
}
ds->to_xml(ds_data);
ds->unlock();
/* ---------------------------------------------------------------------- */
/* Check action consistency: */
/* state is READY */
/* snapshot exists */
/* snapshot is not the active one */
/* ---------------------------------------------------------------------- */
Image * img = ipool->get(iid,true);
img = ipool->get(iid,true);
if ( img == 0 )
{
@ -1053,38 +1081,9 @@ int ImageManager::revert_snapshot(int iid, int sid, string& error)
return -1;
}
/* ---------------------------------------------------------------------- */
/* Get DS data for driver */
/* ---------------------------------------------------------------------- */
int ds_id = img->get_ds_id();
img->unlock();
string ds_data;
Datastore * ds = dspool->get(ds_id, true);
if ( ds == 0 )
{
error = "Datastore no longer exists";
return -1;
}
ds->to_xml(ds_data);
ds->unlock();
/* ---------------------------------------------------------------------- */
/* Format message and send action to driver */
/* ---------------------------------------------------------------------- */
img = ipool->get(iid,true);
if ( img == 0 )
{
error = "Image does not exist";
return -1;
}
img->set_target_snapshot(sid);
string img_tmpl;
@ -1118,12 +1117,6 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error)
return -1;
}
/* ---------------------------------------------------------------------- */
/* Check action consistency: */
/* state is READY */
/* snapshot exists */
/* ---------------------------------------------------------------------- */
Image * img = ipool->get(iid,true);
if ( img == 0 )
@ -1132,23 +1125,6 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error)
return -1;
}
if (img->get_state() != Image::READY)
{
error = "Cannot flatten snapshot in state " + Image::state_to_str(img->get_state());
img->unlock();
return -1;
}
const Snapshots& snaps = img->get_snapshots();
if (!snaps.exists(sid))
{
error = "Snapshot does not exist";
img->unlock();
return -1;
}
/* ---------------------------------------------------------------------- */
/* Get DS data for driver */
/* ---------------------------------------------------------------------- */
@ -1171,8 +1147,11 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error)
ds->unlock();
/* ---------------------------------------------------------------------- */
/* Format message and send action to driver */
/* Check action consistency: */
/* state is READY */
/* snapshot exists */
/* ---------------------------------------------------------------------- */
img = ipool->get(iid,true);
if ( img == 0 )
@ -1181,6 +1160,27 @@ int ImageManager::flatten_snapshot(int iid, int sid, string& error)
return -1;
}
if (img->get_state() != Image::READY)
{
error = "Cannot flatten snapshot in state " + Image::state_to_str(img->get_state());
img->unlock();
return -1;
}
const Snapshots& snaps = img->get_snapshots();
if (!snaps.exists(sid))
{
error = "Snapshot does not exist";
img->unlock();
return -1;
}
/* ---------------------------------------------------------------------- */
/* Format message and send action to driver */
/* ---------------------------------------------------------------------- */
img->set_target_snapshot(sid);
string img_tmpl;

View File

@ -1720,7 +1720,8 @@ void LifeCycleManager::saveas_failure_action(int vid)
void LifeCycleManager::disk_snapshot_success(int vid)
{
string disk_id, tm_mad, ds_id, snap_id;
string tm_mad;
int disk_id, ds_id, snap_id;
Quotas::QuotaType qt;
Template *quotas = 0;
@ -1741,9 +1742,6 @@ void LifeCycleManager::disk_snapshot_success(int vid)
return;
}
int isnap_id = strtol(snap_id.c_str(),NULL,0);
int idisk_id = strtol(disk_id.c_str(),NULL,0);
int uid = vm->get_uid();
int gid = vm->get_gid();
@ -1759,7 +1757,7 @@ void LifeCycleManager::disk_snapshot_success(int vid)
case VirtualMachine::DISK_SNAPSHOT_REVERT_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_REVERT_SUSPENDED:
vm->log("LCM", Log::INFO, "VM disk snapshot operation completed.");
vm->revert_disk_snapshot(idisk_id, isnap_id);
vm->revert_disk_snapshot(disk_id, snap_id);
break;
case VirtualMachine::DISK_SNAPSHOT_DELETE:
@ -1767,7 +1765,7 @@ void LifeCycleManager::disk_snapshot_success(int vid)
case VirtualMachine::DISK_SNAPSHOT_DELETE_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_DELETE_SUSPENDED:
vm->log("LCM", Log::INFO, "VM disk snapshot deleted.");
vm->delete_disk_snapshot(idisk_id, isnap_id, qt, &quotas);
vm->delete_disk_snapshot(disk_id, snap_id, qt, &quotas);
break;
default:
@ -1815,7 +1813,8 @@ void LifeCycleManager::disk_snapshot_success(int vid)
void LifeCycleManager::disk_snapshot_failure(int vid)
{
string disk_id, tm_mad, ds_id, snap_id;
string tm_mad;
int disk_id, ds_id, snap_id;
Quotas::QuotaType qt;
Template *quotas = 0;
@ -1836,9 +1835,6 @@ void LifeCycleManager::disk_snapshot_failure(int vid)
return;
}
int isnap_id = strtol(snap_id.c_str(),NULL,0);
int idisk_id = strtol(disk_id.c_str(),NULL,0);
int uid = vm->get_uid();
int gid = vm->get_gid();
@ -1851,7 +1847,7 @@ void LifeCycleManager::disk_snapshot_failure(int vid)
case VirtualMachine::DISK_SNAPSHOT_POWEROFF:
case VirtualMachine::DISK_SNAPSHOT_SUSPENDED:
vm->log("LCM", Log::ERROR, "Could not take disk snapshot.");
vm->delete_disk_snapshot(idisk_id, isnap_id, qt, &quotas);
vm->delete_disk_snapshot(disk_id, snap_id, qt, &quotas);
break;
case VirtualMachine::DISK_SNAPSHOT_REVERT:

View File

@ -2377,7 +2377,7 @@ void VirtualMachineDiskSnapshotCreate::request_execute(
if (disk == 0)
{
failure_response(ACTION, request_error("VM disk does not exists", ""), att);
failure_response(ACTION, request_error("VM disk does not exist", ""), att);
vm->unlock();
@ -2387,6 +2387,7 @@ void VirtualMachineDiskSnapshotCreate::request_execute(
string disk_size = disk->vector_value("SIZE");
string ds_id = disk->vector_value("DATASTORE_ID");
bool persistent = VirtualMachine::is_persistent(disk);
bool is_volatile = VirtualMachine::is_volatile(disk);
vm->get_permissions(vm_perms);
@ -2394,7 +2395,7 @@ void VirtualMachineDiskSnapshotCreate::request_execute(
RequestAttributes att_quota(vm_perms.uid, vm_perms.gid, att);
if (VirtualMachine::is_volatile(disk))
if (is_volatile)
{
failure_response(ACTION, request_error("Cannot make snapshots on "
"volatile disks",""), att);
@ -2484,7 +2485,7 @@ void VirtualMachineDiskSnapshotRevert::request_execute(
}
else
{
success_response(snap_id, att);
success_response(id, att);
}
return;
@ -2493,7 +2494,6 @@ void VirtualMachineDiskSnapshotRevert::request_execute(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineDiskSnapshotDelete::request_execute(
xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
@ -2523,7 +2523,7 @@ void VirtualMachineDiskSnapshotDelete::request_execute(
}
else
{
success_response(snap_id, att);
success_response(id, att);
}
return;

View File

@ -2075,20 +2075,17 @@ void TransferManager::saveas_hot_action(int vid)
if (vm == 0)
{
vm->log("TM", Log::ERROR, "Could not obtain the VM");
goto error_common;
return;
}
if (!vm->hasHistory())
{
vm->log("TM", Log::ERROR, "The VM has no history");
goto error_common;
goto error_history;
}
if (vm->get_saveas_disk(disk_id, src, image_id, snap_id, tm_mad, ds_id)!= 0)
{
vm->log("TM", Log::ERROR,"Could not get disk information to export it");
goto error_common;
goto error_disk;
}
tm_md = get();
@ -2125,6 +2122,14 @@ void TransferManager::saveas_hot_action(int vid)
return;
error_history:
os << "saveas_hot_transfer, the VM has no history";
goto error_common;
error_disk:
os << "saveas_hot_transfer, could not get disk information to export it";
goto error_common;
error_driver:
os << "saveas_hot_transfer, error getting TM driver.";
goto error_common;
@ -2169,13 +2174,13 @@ int TransferManager::snapshot_transfer_command(
VirtualMachine * vm, const char * snap_action, ostream& xfr)
{
string tm_mad;
string ds_id;
string disk_id;
string snap_id;
int ds_id;
int disk_id;
int snap_id;
if (vm->get_snapshot_disk(ds_id, tm_mad, disk_id, snap_id) == -1)
{
vm->log("TM", Log::ERROR, "Could not get disk information to"
vm->log("TM", Log::ERROR, "Could not get disk information to "
"take snapshot");
return -1;
}
@ -2221,14 +2226,12 @@ void TransferManager::do_snapshot_action(int vid, const char * snap_action)
if (vm == 0)
{
vm->log("TM", Log::ERROR, "Could not obtain the VM");
goto error_common;
return;
}
if (!vm->hasHistory())
{
vm->log("TM", Log::ERROR, "The VM has no history");
goto error_common;
goto error_history;
}
xfr_name = vm->get_transfer_file() + ".disk_snapshot";
@ -2258,6 +2261,10 @@ error_driver:
os << "disk_snapshot, error getting TM driver.";
goto error_common;
error_history:
os << "disk_snapshot, the VM has no history";
goto error_common;
error_file:
os << "disk_snapshot, could not open file: " << xfr_name;
goto error_common;

View File

@ -311,7 +311,7 @@ bool Snapshots::test_delete(unsigned int id, string& error) const
if (snapshot == 0)
{
error = "Snapshot does not exists";
error = "Snapshot does not exist";
return false;
}

View File

@ -4153,8 +4153,8 @@ void VirtualMachine::clear_snapshot_disk()
/* -------------------------------------------------------------------------- */
int VirtualMachine::get_snapshot_disk(string& ds_id, string& tm_mad,
string& disk_id, string& snap_id)
int VirtualMachine::get_snapshot_disk(int& ds_id, string& tm_mad,
int& disk_id, int& snap_id)
{
vector<Attribute *> disks;
VectorAttribute * disk;
@ -4175,7 +4175,7 @@ int VirtualMachine::get_snapshot_disk(string& ds_id, string& tm_mad,
if ( disk->vector_value("DISK_SNAPSHOT_ACTIVE") == "YES" )
{
map<int, Snapshots *>::iterator it;
int did;
int did, rc;
if (disk->vector_value("DISK_ID", did) == -1)
{
@ -4190,11 +4190,11 @@ int VirtualMachine::get_snapshot_disk(string& ds_id, string& tm_mad,
}
tm_mad = disk->vector_value("TM_MAD");
ds_id = disk->vector_value("DATASTORE_ID");
disk_id = disk->vector_value("DISK_ID");
snap_id = disk->vector_value("DISK_SNAPSHOT_ID");
rc = disk->vector_value("DATASTORE_ID", ds_id);
rc += disk->vector_value("DISK_ID", disk_id);
rc += disk->vector_value("DISK_SNAPSHOT_ID", snap_id);
if (snap_id.empty()||tm_mad.empty()||ds_id.empty()||disk_id.empty())
if (tm_mad.empty() || rc != 0)
{
return -1;
}
@ -4221,7 +4221,7 @@ int VirtualMachine::new_disk_snapshot(int did, const string& tag, string& error)
if ( disk == 0 )
{
error = "VM disk does not exists";
error = "VM disk does not exist";
return -1;
}
@ -4280,7 +4280,7 @@ const Snapshots * VirtualMachine::get_disk_snapshots(int did, string& error) con
if ( disk == 0 )
{
error = "VM disk does not exists";
error = "VM disk does not exist";
return 0;
}
@ -4288,7 +4288,7 @@ const Snapshots * VirtualMachine::get_disk_snapshots(int did, string& error) con
if (it == snapshots.end())
{
error = "Snapshot does not exists";
error = "Snapshot does not exist";
return 0;
}

View File

@ -2121,7 +2121,8 @@ void VirtualMachineManager::disk_snapshot_create_action(int vid)
string snap_cmd, snap_cmd_rollback;
string disk_path;
string ds_id, tm_mad, disk_id, snap_id;
string tm_mad;
int ds_id, disk_id, snap_id;
int rc;
@ -2240,7 +2241,8 @@ void VirtualMachineManager::disk_snapshot_revert_action(int vid)
string snap_cmd;
string disk_path;
string ds_id, tm_mad, disk_id, snap_id;
string tm_mad;
int ds_id, disk_id, snap_id;
int rc;