From 3a399ea0f586e46bd3001cd53434bcc2706c497b Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Fri, 27 Mar 2015 16:34:09 -0400 Subject: [PATCH] VBOX: If polling for the current VM state fails for any reason, like vboxsvc crashing, do a temp exit for 24 hours. Before COM, polling for the current state wasn't as critical. If the poll operation failed, we would try again in one second anyway. After COM, it is used as a test to see if the communication channel between the wrapper and VirtualBox is still operational. If not, temp exit and hope things work the next attempt. --- samples/vboxwrapper/vbox_common.h | 2 +- samples/vboxwrapper/vbox_mscom_impl.cpp | 8 ++++++-- samples/vboxwrapper/vbox_mscom_impl.h | 2 +- samples/vboxwrapper/vbox_vboxmanage.cpp | 7 ++++++- samples/vboxwrapper/vbox_vboxmanage.h | 2 +- samples/vboxwrapper/vboxwrapper.cpp | 8 +++++++- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/samples/vboxwrapper/vbox_common.h b/samples/vboxwrapper/vbox_common.h index a591c7ce9a..373283b88c 100644 --- a/samples/vboxwrapper/vbox_common.h +++ b/samples/vboxwrapper/vbox_common.h @@ -168,7 +168,7 @@ public: virtual int register_vm() = 0; virtual int deregister_vm(bool delete_media) = 0; virtual int deregister_stale_vm() = 0; - virtual void poll(bool log_state = true) = 0; + virtual int poll(bool log_state = true) = 0; virtual int start() = 0; virtual int stop() = 0; virtual int poweroff() = 0; diff --git a/samples/vboxwrapper/vbox_mscom_impl.cpp b/samples/vboxwrapper/vbox_mscom_impl.cpp index 6fb6b136da..a782516ee5 100644 --- a/samples/vboxwrapper/vbox_mscom_impl.cpp +++ b/samples/vboxwrapper/vbox_mscom_impl.cpp @@ -1155,7 +1155,8 @@ int VBOX_VM::deregister_stale_vm() { return 0; } -void VBOX_VM::poll(bool log_state) { +int VBOX_VM::poll(bool log_state) { + int retval = ERR_EXEC; APP_INIT_DATA aid; HRESULT rc; CComPtr pMachine; @@ -1181,7 +1182,6 @@ void VBOX_VM::poll(bool log_state) { if (SUCCEEDED(rc) && pMachine) { rc = pMachine->get_State(&vmstate); if (SUCCEEDED(rc)) { - // VirtualBox Documentation suggests that that a VM is running when its // machine state is between MachineState_FirstOnline and MachineState_LastOnline // which as of this writing is 5 and 17. @@ -1289,6 +1289,8 @@ void VBOX_VM::poll(bool log_state) { ); vmstate_old = vmstate; } + + retval = BOINC_SUCCESS; } } @@ -1304,6 +1306,8 @@ void VBOX_VM::poll(bool log_state) { // Dump any new VM Guest Log entries // dump_vmguestlog_entries(); + + return retval; } int VBOX_VM::start() { diff --git a/samples/vboxwrapper/vbox_mscom_impl.h b/samples/vboxwrapper/vbox_mscom_impl.h index c0e7a23189..de2d8e3130 100644 --- a/samples/vboxwrapper/vbox_mscom_impl.h +++ b/samples/vboxwrapper/vbox_mscom_impl.h @@ -27,7 +27,7 @@ public: int register_vm(); int deregister_vm(bool delete_media); int deregister_stale_vm(); - void poll(bool log_state = true); + int poll(bool log_state = true); int start(); int stop(); int poweroff(); diff --git a/samples/vboxwrapper/vbox_vboxmanage.cpp b/samples/vboxwrapper/vbox_vboxmanage.cpp index 44805be255..4b60982a93 100644 --- a/samples/vboxwrapper/vbox_vboxmanage.cpp +++ b/samples/vboxwrapper/vbox_vboxmanage.cpp @@ -824,7 +824,8 @@ int VBOX_VM::deregister_stale_vm() { return 0; } -void VBOX_VM::poll(bool log_state) { +int VBOX_VM::poll(bool log_state) { + int retval = ERR_EXEC; APP_INIT_DATA aid; string command; string output; @@ -955,6 +956,8 @@ void VBOX_VM::poll(bool log_state) { vboxlog_msg("VM state change detected. (old = '%s', new = '%s')", vmstate_old.c_str(), vmstate.c_str()); vmstate_old = vmstate; } + + retval = BOINC_SUCCESS; } } @@ -970,6 +973,8 @@ void VBOX_VM::poll(bool log_state) { // Dump any new VM Guest Log entries // dump_vmguestlog_entries(); + + return retval; } int VBOX_VM::start() { diff --git a/samples/vboxwrapper/vbox_vboxmanage.h b/samples/vboxwrapper/vbox_vboxmanage.h index 330feb5bda..fcd170792e 100644 --- a/samples/vboxwrapper/vbox_vboxmanage.h +++ b/samples/vboxwrapper/vbox_vboxmanage.h @@ -33,7 +33,7 @@ namespace vboxmanage { int register_vm(); int deregister_vm(bool delete_media); int deregister_stale_vm(); - void poll(bool log_state = true); + int poll(bool log_state = true); int start(); int stop(); int poweroff(); diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp index 9dd1032f93..e937e53cdc 100644 --- a/samples/vboxwrapper/vboxwrapper.cpp +++ b/samples/vboxwrapper/vboxwrapper.cpp @@ -867,7 +867,13 @@ int main(int argc, char** argv) { loop_iteration += 1; // Discover the VM's current state - pVM->poll(); + retval = pVM->poll(); + if (retval) { + vboxlog_msg("ERROR: Vboxwrapper lost communication with VirtualBox, rescheduling task for a later time."); + pVM->reset_vm_process_priority(); + pVM->poweroff(); + boinc_temporary_exit(86400, "VM job unmanageable, restarting later."); + } // Write updates for the graphics application's use if (pVM->enable_graphics_support) {