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

Bug #1316: Clean files when a stopped VM is deleted. Previous commit:dbefe6f only worked with shared DS

This commit is contained in:
Carlos Martín 2012-06-27 18:50:19 +02:00
parent 8c792cc0ff
commit 9d8ccd61c8
4 changed files with 112 additions and 41 deletions

View File

@ -302,6 +302,13 @@ private:
const string & action,
void * arg);
/**
* Called from finalize(). Releases the images and networks acquired by this
* vm, and unlocks it.
* @param vm the VM
*/
void finalize_cleanup(VirtualMachine * vm);
//--------------------------------------------------------------------------
// DM Actions associated with a VM state transition
//--------------------------------------------------------------------------

View File

@ -53,6 +53,7 @@ public:
EPILOG_STOP,
EPILOG_DELETE,
EPILOG_DELETE_PREVIOUS,
EPILOG_DELETE_STOP,
CHECKPOINT,
DRIVER_CANCEL,
FINALIZE
@ -239,7 +240,23 @@ private:
/**
* This function starts the epilog_delete sequence
*/
void epilog_delete_action(int vid);
void epilog_delete_action(int vid)
{
epilog_delete_action(false, vid);
}
/**
* This function starts the epilog_delete_stop sequence on the local host
*/
void epilog_delete_stop_action(int vid)
{
epilog_delete_action(true, vid);
}
/**
* This function starts the epilog_delete sequence
*/
void epilog_delete_action(bool local, int vid);
/**
* This function starts the epilog_delete sequence on the previous host

View File

@ -680,15 +680,43 @@ error:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void DispatchManager::finalize_cleanup(VirtualMachine * vm)
{
Template * tmpl;
int uid;
int gid;
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->log("DiM", Log::INFO, "New VM state is DONE.");
uid = vm->get_uid();
gid = vm->get_gid();
tmpl = vm->clone_template();
vm->unlock();
Quotas::vm_del(uid, gid, tmpl);
delete tmpl;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int DispatchManager::finalize(
int vid)
{
VirtualMachine * vm;
ostringstream oss;
Template * tmpl;
int uid;
int gid;
VirtualMachine::VmState state;
@ -711,33 +739,20 @@ int DispatchManager::finalize(
switch (state)
{
case VirtualMachine::SUSPENDED:
case VirtualMachine::STOPPED:
case VirtualMachine::FAILED:
tm->trigger(TransferManager::EPILOG_DELETE,vid);
finalize_cleanup(vm);
break;
case VirtualMachine::STOPPED:
tm->trigger(TransferManager::EPILOG_DELETE_STOP,vid);
finalize_cleanup(vm);
break;
case VirtualMachine::INIT:
case VirtualMachine::PENDING:
case VirtualMachine::HOLD:
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->log("DiM", Log::INFO, "New VM state is DONE.");
uid = vm->get_uid();
gid = vm->get_gid();
tmpl = vm->clone_template();
vm->unlock();
Quotas::vm_del(uid, gid, tmpl);
delete tmpl;
finalize_cleanup(vm);
break;
case VirtualMachine::ACTIVE:

View File

@ -107,6 +107,10 @@ void TransferManager::trigger(Actions action, int _vid)
aname = "EPILOG_DELETE";
break;
case EPILOG_DELETE_STOP:
aname = "EPILOG_DELETE_STOP";
break;
case EPILOG_DELETE_PREVIOUS:
aname = "EPILOG_DELETE_PREVIOUS";
break;
@ -171,6 +175,10 @@ void TransferManager::do_action(const string &action, void * arg)
{
epilog_delete_action(vid);
}
else if (action == "EPILOG_DELETE_STOP")
{
epilog_delete_stop_action(vid);
}
else if (action == "EPILOG_DELETE_PREVIOUS")
{
epilog_delete_previous_action(vid);
@ -1033,11 +1041,10 @@ error_common:
return;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void TransferManager::epilog_delete_action(int vid)
void TransferManager::epilog_delete_action(bool local, int vid)
{
ofstream xfr;
ostringstream os;
@ -1113,21 +1120,46 @@ void TransferManager::epilog_delete_action(int vid)
continue;
}
//DELETE tm_mad host:remote_system_dir/disk.i vmid dsid
xfr << "DELETE "
<< tm_mad << " "
<< vm->get_hostname() << ":"
<< vm->get_remote_system_dir() << "/disk." << disk_id << " "
<< vm->get_oid() << " "
<< ds_id << endl;
if ( local )
{
//DELETE tm_mad fe:system_dir/disk.i vmid dsid
xfr << "DELETE "
<< tm_mad << " "
<< nd.get_nebula_hostname() << ":"
<< vm->get_system_dir() << "/disk." << disk_id << " "
<< vm->get_oid() << " "
<< ds_id << endl;
}
else
{
//DELETE tm_mad host:remote_system_dir/disk.i vmid dsid
xfr << "DELETE "
<< tm_mad << " "
<< vm->get_hostname() << ":"
<< vm->get_remote_system_dir() << "/disk." << disk_id << " "
<< vm->get_oid() << " "
<< ds_id << endl;
}
}
//DELETE system_tm_mad hostname:remote_system_dir vmid dsid(=0)
xfr << "DELETE "
<< system_tm_mad << " "
<< vm->get_hostname() <<":"<< vm->get_remote_system_dir() << " "
<< vm->get_oid() << " "
<< "0";
if ( local )
{
//DELETE system_tm_mad fe:system_dir vmid dsid(=0)
xfr << "DELETE "
<< system_tm_mad << " "
<< nd.get_nebula_hostname() <<":"<< vm->get_system_dir() << " "
<< vm->get_oid() << " "
<< "0";
}
else
{
//DELETE system_tm_mad hostname:remote_system_dir vmid dsid(=0)
xfr << "DELETE "
<< system_tm_mad << " "
<< vm->get_hostname() <<":"<< vm->get_remote_system_dir() << " "
<< vm->get_oid() << " "
<< "0";
}
xfr.close();