Give choice between COM and VboxManage interface

This commit is contained in:
nikolasgianna 2017-04-10 10:50:42 +02:00
parent 6e8c453460
commit 2420c31902
3 changed files with 107 additions and 66 deletions

View File

@ -149,6 +149,7 @@ int VBOX_BASE::run(bool do_restore_snapshot) {
retval = is_registered();
if (ERR_TIMEOUT == retval) {
vboxlog_msg("Error: Timeout");
return VBOXWRAPPER_ERR_RECOVERABLE;
@ -156,17 +157,26 @@ int VBOX_BASE::run(bool do_restore_snapshot) {
if (is_vm_machine_configuration_available()) {
retval = register_vm();
if (retval) return retval;
if (retval){
vboxlog_msg("Could not register");
return retval;
}
} else {
if (is_disk_image_registered()) {
// Handle the case where a previous instance of the same projects VM
// was already initialized for the current slot directory but aborted
// while the task was suspended and unloaded from memory.
retval = deregister_stale_vm();
if (retval) return retval;
if (retval){
vboxlog_msg("Could not deregister stale VM");
return retval;
}
}
retval = create_vm();
if (retval) return retval;
if (retval){
vboxlog_msg("Could not create VM");
return retval;
}
}
}
@ -183,15 +193,22 @@ int VBOX_BASE::run(bool do_restore_snapshot) {
// Check to see if the VM is already in a running state, if so, poweroff.
poll(false);
if (online) {
vboxlog_msg("VM was running");
retval = poweroff();
if (retval) return ERR_NOT_EXITED;
if (retval){
vboxlog_msg("Could not stop running VM");
return ERR_NOT_EXITED;
}
}
// If our last checkpoint time is greater than 0, restore from the previously
// saved snapshot
if (do_restore_snapshot) {
retval = restore_snapshot();
if (retval) return retval;
if (retval){
vboxlog_msg("Could not restore from snapshot");
return retval;
}
}
// Has BOINC signaled that we should quit?
@ -205,7 +222,10 @@ int VBOX_BASE::run(bool do_restore_snapshot) {
// Start the VM
retval = start();
if (retval) return retval;
if (retval){
vboxlog_msg("Could not start ");
return retval;
}
return 0;
}
@ -267,41 +287,37 @@ void VBOX_BASE::dump_hypervisor_logs(bool include_error_logs) {
void VBOX_BASE::dump_vmguestlog_entries() {
string local_vm_log;
string line;
size_t eol_pos;
size_t eol_prev_pos;
size_t line_pos;
VBOX_TIMESTAMP current_timestamp;
string msg;
string virtualbox_vm_log;
virtualbox_vm_log = vm_master_name + "/Logs/VBox.log";
get_vm_log(local_vm_log, true, 16*1024);
if (boinc_file_exists(virtualbox_vm_log.c_str())) {
eol_prev_pos = 0;
eol_pos = local_vm_log.find("\n");
while (eol_pos != string::npos) {
line = local_vm_log.substr(eol_prev_pos, eol_pos - eol_prev_pos);
std::ifstream src(virtualbox_vm_log.c_str(), std::ios::binary);
while (std::getline(src, line))
{
line_pos = line.find("Guest Log:");
if (line_pos != string::npos) {
sscanf(
line.c_str(),
"%d:%d:%d.%d",
&current_timestamp.hours, &current_timestamp.minutes,
&current_timestamp.seconds, &current_timestamp.milliseconds
);
line_pos = line.find("Guest Log:");
if (line_pos != string::npos) {
sscanf(
line.c_str(),
"%d:%d:%d.%d",
&current_timestamp.hours, &current_timestamp.minutes,
&current_timestamp.seconds, &current_timestamp.milliseconds
);
if (is_timestamp_newer(current_timestamp, vm_log_timestamp)) {
vm_log_timestamp = current_timestamp;
msg = line.substr(line_pos, line.size() - line_pos);
if (is_timestamp_newer(current_timestamp, vm_log_timestamp)) {
vm_log_timestamp = current_timestamp;
msg = line.substr(line_pos, line.size() - line_pos);
sanitize_format(msg);
sanitize_format(msg);
vboxlog_msg(msg.c_str());
}
}
eol_prev_pos = eol_pos + 1;
eol_pos = local_vm_log.find("\n", eol_prev_pos);
}
vboxlog_msg(msg.c_str());
}
}
}
}
}
int VBOX_BASE::dump_screenshot() {
@ -1273,3 +1289,4 @@ VBOX_VM::VBOX_VM() {
VBOX_VM::~VBOX_VM() {
}

View File

@ -153,11 +153,13 @@ int VBOX_VM::initialize() {
}
#ifdef _WIN32
#ifndef COM_OFF
// Launch vboxsvc manually so that the DCOM subsystem won't be able too. Our version
// will have permission and direction to write its state information to the BOINC
// data directory.
//
launch_vboxsvc();
#endif
#endif
rc = get_version_information(virtualbox_version_raw, virtualbox_version_display);
@ -793,7 +795,7 @@ int VBOX_VM::deregister_stale_vm() {
// In use by VMs: test2 (UUID: 000ab2be-1254-4c6a-9fdc-1536a478f601)
// Location: C:\Users\romw\VirtualBox VMs\test2\test2.vdi
//
if (enable_isocontextualization) {
if (enable_isocontextualization && enable_isocontextualization) {
command = "showhdinfo \"" + virtual_machine_slot_directory + "/" + cache_disk_filename + "\" ";
retval = vbm_popen(command, output, "get HDD info");
if (retval) return retval;
@ -1005,7 +1007,7 @@ int VBOX_VM::start() {
boinc_get_init_data_p(&aid);
vboxlog_msg("Starting VM. (%s, slot#%d)", vm_name.c_str(), aid.slot);
vboxlog_msg("Starting VM using VboxManage interface. (%s, slot#%d)", vm_name.c_str(), aid.slot);
command = "startvm \"" + vm_name + "\"";
@ -1721,41 +1723,48 @@ int VBOX_VM::get_vm_network_bytes_received(double& received) {
}
int VBOX_VM::get_vm_process_id() {
string output;
string pid;
size_t pid_start;
size_t pid_end;
string virtualbox_vm_log;
string::iterator iter;
int retval = BOINC_SUCCESS;
string line;
string comp = "Process ID";
string pid;
size_t pid_start;
size_t pid_end;
std::size_t found;
get_vm_log(output, false);
// Output should look like this:
// VirtualBox 4.1.0 r73009 win.amd64 (Jul 19 2011 13:05:53) release log
// 00:00:06.008 Log opened 2011-09-01T23:00:59.829170900Z
// 00:00:06.008 OS Product: Windows 7
// 00:00:06.009 OS Release: 6.1.7601
// 00:00:06.009 OS Service Pack: 1
// 00:00:06.015 Host RAM: 4094MB RAM, available: 876MB
// 00:00:06.015 Executable: C:\Program Files\Oracle\VirtualBox\VirtualBox.exe
// 00:00:06.015 Process ID: 6128
// 00:00:06.015 Package type: WINDOWS_64BITS_GENERIC
// 00:00:06.015 Installed Extension Packs:
// 00:00:06.015 None installed!
//
pid_start = output.find("Process ID: ");
if (pid_start == string::npos) {
return ERR_NOT_FOUND;
}
pid_start += strlen("Process ID: ");
pid_end = output.find("\n", pid_start);
pid = output.substr(pid_start, pid_end - pid_start);
strip_whitespace(pid);
if (pid.size() <= 0) {
return ERR_NOT_FOUND;
}
virtualbox_vm_log = vm_master_name + "/Logs/VBox.log";
vm_pid = atol(pid.c_str());
if (boinc_file_exists(virtualbox_vm_log.c_str())) {
return 0;
std::ifstream src(virtualbox_vm_log.c_str(), std::ios::binary);
while (std::getline(src, line))
{
found = line.find(comp);
if (found != string::npos){
pid_start = line.find("Process ID: ");
if (pid_start == string::npos) {
vboxlog_msg("Something wrong with the process ID finding\n %s ", line.c_str());
return ERR_NOT_FOUND;
}
pid_start += strlen("Process ID: ");
pid_end = line.find("\n", pid_start);
pid = line.substr(pid_start, pid_end - pid_start);
strip_whitespace(pid);
if (pid.size() <= 0) {
return ERR_NOT_FOUND;
}
vm_pid = atol(pid.c_str());
break;
}
}
}
return retval;
}
int VBOX_VM::get_vm_exit_code(unsigned long& exit_code) {
@ -1914,3 +1923,4 @@ void VBOX_VM::reset_vm_process_priority() {
}
}

View File

@ -80,12 +80,18 @@
#include "vboxcheckpoint.h"
#include "vboxwrapper.h"
#include "vbox_common.h"
//Use of COM_OFF to choose between COM
//and VboxManage interfaces
//
//Default is COM
#ifdef _WIN32
#ifndef COM_OFF
#include "vbox_mscom42.h"
#include "vbox_mscom43.h"
#include "vbox_mscom50.h"
#include "vbox_mscom51.h"
#endif
#endif
#include "vbox_vboxmanage.h"
@ -423,7 +429,9 @@ int main(int argc, char** argv) {
// Initialize system services
//
#ifdef _WIN32
#ifndef COM_OFF
CoInitialize(NULL);
#endif
#ifdef USE_WINSOCK
WSADATA wsdata;
retval = WSAStartup( MAKEWORD( 1, 1 ), &wsdata);
@ -439,7 +447,9 @@ int main(int argc, char** argv) {
boinc_parse_init_data_file();
boinc_get_init_data(aid);
//Use COM_OFF to choose how we initialize() the VM
#ifdef _WIN32
#ifndef COM_OFF
// Determine what version of VirtualBox we are using via the registry. Use a
// namespace specific version of the function because VirtualBox has been known
// to change the registry location from time to time.
@ -481,6 +491,7 @@ int main(int argc, char** argv) {
}
}
}
#endif
#endif
// Initialize VM Hypervisor
//
@ -1383,7 +1394,9 @@ int main(int argc, char** argv) {
}
#ifdef _WIN32
#ifndef COM_OFF
CoUninitialize();
#endif
#ifdef USE_WINSOCK
WSACleanup();
#endif
@ -1391,3 +1404,4 @@ int main(int argc, char** argv) {
return 0;
}