VBOX: Convert cleanup_snapshots() and various bug fixes

This commit is contained in:
Rom Walton 2014-11-15 23:14:11 -05:00
parent 56aeda1233
commit 59152902b0
8 changed files with 839 additions and 848 deletions

View File

@ -118,6 +118,60 @@ VBOX_BASE::~VBOX_BASE() {
}
}
int VBOX_BASE::initialize() {
return ERR_EXEC;
}
int VBOX_BASE::create_vm() {
return ERR_EXEC;
}
int VBOX_BASE::register_vm() {
return ERR_EXEC;
}
int VBOX_BASE::deregister_vm(bool delete_media) {
return ERR_EXEC;
}
int VBOX_BASE::deregister_stale_vm() {
return ERR_EXEC;
}
void VBOX_BASE::poll(bool /*log_state*/) {
}
int VBOX_BASE::start() {
return ERR_EXEC;
}
int VBOX_BASE::stop() {
return ERR_EXEC;
}
int VBOX_BASE::poweroff() {
return ERR_EXEC;
}
int VBOX_BASE::pause() {
return ERR_EXEC;
}
int VBOX_BASE::resume() {
return ERR_EXEC;
}
int VBOX_BASE::create_snapshot(double elapsed_time) {
return ERR_EXEC;
}
int VBOX_BASE::cleanup_snapshots(bool delete_active) {
return ERR_EXEC;
}
int VBOX_BASE::restore_snapshot() {
return ERR_EXEC;
}
int VBOX_BASE::run(bool do_restore_snapshot) {
int retval;
@ -230,6 +284,9 @@ void VBOX_BASE::dump_hypervisor_logs(bool include_error_logs) {
}
}
void VBOX_BASE::dump_hypervisor_status_reports() {
}
// t1 > t2
static bool is_timestamp_newer(VBOX_TIMESTAMP& t1, VBOX_TIMESTAMP& t2) {
if (t1.hours > t2.hours) return true;
@ -288,6 +345,14 @@ void VBOX_BASE::dump_vmguestlog_entries() {
}
}
int VBOX_BASE::is_registered() {
return ERR_NOT_FOUND;
}
bool VBOX_BASE::is_system_ready(std::string& message) {
return false;
}
bool VBOX_BASE::is_vm_machine_configuration_available() {
string virtual_machine_slot_directory;
string vm_machine_configuration_file;
@ -303,6 +368,14 @@ bool VBOX_BASE::is_vm_machine_configuration_available() {
return false;
}
bool VBOX_BASE::is_hdd_registered() {
return false;
}
bool VBOX_BASE::is_extpack_installed() {
return false;
}
bool VBOX_BASE::is_logged_failure_vm_extensions_disabled() {
if (vm_log.find("VERR_VMX_MSR_LOCKED_OR_DISABLED") != string::npos) return true;
if (vm_log.find("VERR_SVM_DISABLED") != string::npos) return true;
@ -337,20 +410,6 @@ bool VBOX_BASE::is_logged_failure_guest_job_out_of_memory() {
return false;
}
bool VBOX_BASE::is_logged_completion_file_exists() {
char path[MAXPATHLEN];
sprintf(path, "shared/%s", completion_trigger_file.c_str());
if (boinc_file_exists(path)) return true;
return false;
}
bool VBOX_BASE::is_logged_temporary_exit_file_exists() {
char path[MAXPATHLEN];
sprintf(path, "shared/%s", temporary_exit_trigger_file.c_str());
if (boinc_file_exists(path)) return true;
return false;
}
bool VBOX_BASE::is_virtualbox_version_newer(int maj, int min, int rel) {
int vbox_major = 0, vbox_minor = 0, vbox_release = 0;
if (3 == sscanf(virtualbox_version.c_str(), "%d.%d.%d", &vbox_major, &vbox_minor, &vbox_release)) {
@ -363,10 +422,16 @@ bool VBOX_BASE::is_virtualbox_version_newer(int maj, int min, int rel) {
return false;
}
bool VBOX_BASE::is_virtualbox_error_recoverable(int retval) {
// See comments for VBOX_BASE::vbm_popen about session lock issues.
if (VBOX_E_INVALID_OBJECT_STATE == (unsigned int)retval) return true;
return false;
int VBOX_BASE::get_install_directory(std::string& dir) {
return ERR_EXEC;
}
int VBOX_BASE::get_version_information(std::string& version) {
return ERR_EXEC;
}
int VBOX_BASE::get_guest_additions(std::string& dir) {
return ERR_EXEC;
}
// Returns the current directory in which the executable resides.
@ -383,18 +448,28 @@ int VBOX_BASE::get_slot_directory(string& dir) {
return 0;
}
void VBOX_BASE::sanitize_output(std::string& output) {
#ifdef _WIN32
// Remove \r from the log spew
string::iterator iter = output.begin();
while (iter != output.end()) {
if (*iter == '\r') {
iter = output.erase(iter);
} else {
++iter;
}
}
#endif
int VBOX_BASE::get_default_network_interface(std::string& iface) {
return ERR_EXEC;
}
int VBOX_BASE::get_vm_network_bytes_sent(double& sent) {
return ERR_EXEC;
}
int VBOX_BASE::get_vm_network_bytes_received(double& received) {
return ERR_EXEC;
}
int VBOX_BASE::get_vm_process_id() {
return 0;
}
int VBOX_BASE::get_vm_exit_code(unsigned long& exit_code) {
return ERR_EXEC;
}
double VBOX_BASE::get_vm_cpu_time() {
return 0.0;
}
int VBOX_BASE::get_system_log(string& log, bool tail_only, unsigned int buffer_size) {
@ -565,6 +640,18 @@ int VBOX_BASE::get_trace_log(string& log, bool tail_only, unsigned int buffer_si
return retval;
}
int VBOX_BASE::set_network_access(bool enabled) {
return ERR_EXEC;
}
int VBOX_BASE::set_cpu_usage(int percentage) {
return ERR_EXEC;
}
int VBOX_BASE::set_network_usage(int kilobytes) {
return ERR_EXEC;
}
int VBOX_BASE::read_floppy(std::string& data) {
if (enable_floppyio && pFloppy) {
data = pFloppy->receive();
@ -580,3 +667,23 @@ int VBOX_BASE::write_floppy(std::string& data) {
}
return 1;
}
void VBOX_BASE::lower_vm_process_priority() {
}
void VBOX_BASE::reset_vm_process_priority() {
}
void VBOX_BASE::sanitize_output(std::string& output) {
#ifdef _WIN32
// Remove \r from the log spew
string::iterator iter = output.begin();
while (iter != output.end()) {
if (*iter == '\r') {
iter = output.erase(iter);
} else {
++iter;
}
}
#endif
}

View File

@ -21,18 +21,6 @@
#ifndef _VBOX_H_
#define _VBOX_H_
// Known VirtualBox/COM error codes
//
#ifndef CO_E_SERVER_EXEC_FAILURE
#define CO_E_SERVER_EXEC_FAILURE 0x80080005
#endif
#ifndef RPC_S_SERVER_UNAVAILABLE
#define RPC_S_SERVER_UNAVAILABLE 0x800706ba
#endif
#ifndef VBOX_E_INVALID_OBJECT_STATE
#define VBOX_E_INVALID_OBJECT_STATE 0x80bb0007
#endif
// Vboxwrapper errors
//
#define VBOXWRAPPER_ERR_RECOVERABLE -1000
@ -213,72 +201,53 @@ public:
virtual int cleanup_snapshots(bool delete_active);
virtual int restore_snapshot();
int run(bool do_restore_snapshot);
void cleanup();
virtual int run(bool do_restore_snapshot);
virtual void cleanup();
void dump_hypervisor_logs(bool include_error_logs);
void dump_hypervisor_status_reports();
void dump_vmguestlog_entries();
void check_trickle_triggers();
void check_intermediate_uploads();
void delete_temporary_exit_trigger_file();
virtual void dump_hypervisor_logs(bool include_error_logs);
virtual void dump_hypervisor_status_reports();
virtual void dump_vmguestlog_entries();
int is_registered();
bool is_system_ready(std::string& message);
bool is_vm_machine_configuration_available();
bool is_hdd_registered();
bool is_extpack_installed();
bool is_logged_failure_vm_extensions_disabled();
bool is_logged_failure_vm_extensions_in_use();
bool is_logged_failure_vm_extensions_not_supported();
bool is_logged_failure_host_out_of_memory();
bool is_logged_failure_guest_job_out_of_memory();
bool is_logged_completion_file_exists();
bool is_logged_temporary_exit_file_exists();
bool is_virtualbox_version_newer(int maj, int min, int rel);
bool is_virtualbox_error_recoverable(int retval);
virtual int is_registered();
virtual bool is_system_ready(std::string& message);
virtual bool is_vm_machine_configuration_available();
virtual bool is_hdd_registered();
virtual bool is_extpack_installed();
virtual bool is_logged_failure_vm_extensions_disabled();
virtual bool is_logged_failure_vm_extensions_in_use();
virtual bool is_logged_failure_vm_extensions_not_supported();
virtual bool is_logged_failure_host_out_of_memory();
virtual bool is_logged_failure_guest_job_out_of_memory();
virtual bool is_virtualbox_version_newer(int maj, int min, int rel);
int get_install_directory(std::string& dir);
int get_version_information(std::string& version);
int get_guest_additions(std::string& dir);
int get_slot_directory(std::string& dir);
int get_default_network_interface(std::string& iface);
int get_vm_network_bytes_sent(double& sent);
int get_vm_network_bytes_received(double& received);
int get_vm_process_id();
int get_vm_exit_code(unsigned long& exit_code);
double get_vm_cpu_time();
virtual int get_install_directory(std::string& dir);
virtual int get_version_information(std::string& version);
virtual int get_guest_additions(std::string& dir);
virtual int get_slot_directory(std::string& dir);
virtual int get_default_network_interface(std::string& iface);
virtual int get_vm_network_bytes_sent(double& sent);
virtual int get_vm_network_bytes_received(double& received);
virtual int get_vm_process_id();
virtual int get_vm_exit_code(unsigned long& exit_code);
virtual double get_vm_cpu_time();
int get_system_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
int get_vm_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
int get_trace_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
virtual int get_system_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
virtual int get_vm_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
virtual int get_trace_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
int set_network_access(bool enabled);
int set_cpu_usage(int percentage);
int set_network_usage(int kilobytes);
virtual int set_network_access(bool enabled);
virtual int set_cpu_usage(int percentage);
virtual int set_network_usage(int kilobytes);
int read_floppy(std::string& data);
int write_floppy(std::string& data);
virtual int read_floppy(std::string& data);
virtual int write_floppy(std::string& data);
void lower_vm_process_priority();
void reset_vm_process_priority();
virtual void lower_vm_process_priority();
virtual void reset_vm_process_priority();
virtual void sanitize_output(std::string& output);
void sanitize_output(std::string& output);
#ifndef _WIN32
int vbm_popen(
std::string& command, std::string& output, const char* item, bool log_error = true, bool retry_failures = true, unsigned int timeout = 45, bool log_trace = true
);
int vbm_popen_raw(
std::string& command, std::string& output, unsigned int timeout
);
void vbm_replay(
std::string& command
);
void vbm_trace(
std::string& command, std::string& ouput, int retval
);
#endif
};
#endif

View File

@ -34,11 +34,6 @@
using std::string;
#if defined(_MSC_VER)
#define getcwd _getcwd
#define stricmp _stricmp
#endif
#include "diagnostics.h"
#include "filesys.h"
#include "parse.h"
@ -109,8 +104,7 @@ int VBOX_VM::initialize() {
rc = get_version_information(virtualbox_version);
if (rc) return rc;
rc = get_guest_additions(virtualbox_guest_additions);
if (rc) return rc;
get_guest_additions(virtualbox_guest_additions);
return 0;
}
@ -1805,6 +1799,14 @@ int VBOX_VM::get_vm_exit_code(unsigned long& exit_code) {
return 0;
}
double VBOX_VM::get_vm_cpu_time() {
double x = process_tree_cpu_time(vm_pid);
if (x > current_cpu_time) {
current_cpu_time = x;
}
return current_cpu_time;
}
// Enable the network adapter if a network connection is required.
// NOTE: Network access should never be allowed if the code running in a
// shared directory or the VM image itself is NOT signed. Doing so

View File

@ -18,8 +18,8 @@
// Provide cross-platform interfaces for making changes to VirtualBox
#ifndef _VBOX_H_
#define _VBOX_H_
#ifndef _VBOX_UNIX_H_
#define _VBOX_UNIX_H_
// Known VirtualBox/COM error codes
//
@ -33,224 +33,40 @@
#define VBOX_E_INVALID_OBJECT_STATE 0x80bb0007
#endif
// Vboxwrapper errors
//
#define VBOXWRAPPER_ERR_RECOVERABLE -1000
// Vboxwrapper diagnostics
//
#define REPLAYLOG_FILENAME "vbox_replay.txt"
#define TRACELOG_FILENAME "vbox_trace.txt"
// raw floppy drive device
class FloppyIO;
// represents a VirtualBox Guest Log Timestamp
struct VBOX_TIMESTAMP {
int hours;
int minutes;
int seconds;
int milliseconds;
};
// represents the state of a intermediate upload
struct INTERMEDIATE_UPLOAD {
std::string file;
bool reported;
bool ignore;
INTERMEDIATE_UPLOAD() {
clear();
}
void clear() {
file = "";
reported = false;
ignore = false;
}
};
struct PORT_FORWARD {
int host_port; // 0 means assign dynamically
int guest_port;
bool is_remote;
PORT_FORWARD() {
host_port = 0;
guest_port = 0;
is_remote = false;
}
int get_host_port(); // assign host port
};
// represents a VirtualBox VM
class VBOX_VM {
class VBOX_VM : public VBOX_BASE {
public:
VBOX_VM();
~VBOX_VM();
std::string virtualbox_home_directory;
std::string virtualbox_install_directory;
std::string virtualbox_guest_additions;
std::string virtualbox_version;
FloppyIO* pFloppy;
std::string vm_log;
// last polled copy of the log file
VBOX_TIMESTAMP vm_log_timestamp;
// last VM guest log entry detected
std::string vm_master_name;
// unique name for the VM
std::string vm_master_description;
// unique description for the VM
std::string vm_name;
// unique name for the VM or UUID of a stale VM if deregistering it
std::string vm_cpu_count;
// required CPU core count
std::string vm_memory_size_mb;
// required size of the memory allocation for the VM, in megabytes
std::string image_filename;
// name of the virtual machine disk image file
std::string iso_image_filename;
// name of the virtual machine iso9660 disk image file
std::string cache_disk_filename;
// name of the virtual machine cache disk image file
std::string floppy_image_filename;
// name of the virtual machine floppy disk image file
double current_cpu_time;
// amount of CPU time consumed by the VM (note: use get_vm_cpu_time())
bool suspended;
// is the VM suspended?
bool network_suspended;
// is network access temporarily suspended?
bool online;
// is VM even online?
bool saving;
// Is VM saving from checkpoint?
bool restoring;
// Is VM restoring from checkpoint?
bool crashed;
// Has the VM crashed?
bool register_only;
// whether we were instructed to only register the VM.
// useful for debugging VMs.
int rd_host_port;
// for optional remote desktop; dynamically assigned
bool headless;
/////////// THE FOLLOWING SPECIFIED IN VBOX_JOB.XML //////////////
// some of these don't really belong in this class
std::string os_name;
// name of the OS the VM runs
std::string vm_disk_controller_type;
// the type of disk controller to emulate
std::string vm_disk_controller_model;
// the disk controller model to emulate
double memory_size_mb;
// size of the memory allocation for the VM, in megabytes
bool enable_cern_dataformat;
// whether to use CERN specific data structures
bool enable_isocontextualization;
// whether to use an iso9660 image to implement VM contextualization (e.g. uCernVM)
bool enable_cache_disk;
// whether to add an extra cache disk for systems like uCernVM
bool enable_network;
// whether to allow network access
bool network_bridged_mode;
// use bridged mode for network
bool enable_shared_directory;
// whether to use shared directory infrastructure
bool enable_floppyio;
// whether to use floppy io infrastructure
bool enable_remotedesktop;
// whether to enable remote desktop functionality
double job_duration;
// maximum amount of wall-clock time this VM is allowed to run before
// considering itself done.
std::string fraction_done_filename;
// name of file where app will write its fraction done
int pf_guest_port; // if nonzero, do port forwarding for Web GUI
int pf_host_port; // AFAIK this isn't needed
std::vector<PORT_FORWARD> port_forwards;
double minimum_checkpoint_interval;
// minimum time between checkpoints
std::vector<std::string> copy_to_shared;
// list of files to copy from slot dir to shared/
std::vector<std::string> trickle_trigger_files;
// if find file of this name in shared/, send trickle-up message
// with variety = filename, contents = file contents
std::vector<INTERMEDIATE_UPLOAD> intermediate_upload_files;
// if find file of this name in shared/, send specified file
std::string completion_trigger_file;
// if find this file in shared/, task is over.
// File can optionally contain exit code (first line)
// and stderr text (subsequent lines).
// Addresses a problem where VM doesn't shut down properly
/////////// END VBOX_JOB.XML ITEMS //////////////
// the pid to the process for the VM/VboxSvc
int vm_pid;
int vboxsvc_pid;
#ifdef _WIN32
// the handle to the process for the VM
// NOTE: we get a handle to the pid right after we parse it from the
// log files so we can adjust the process priority and retrieve the process
// exit code in case it crashed or was terminated. Without an outstanding
// handle to the process, the OS is free to reuse the pid for some other
// executable.
HANDLE vm_pid_handle;
// the handle to the vboxsvc process created by us in the sandbox'ed environment
HANDLE vboxsvc_pid_handle;
#endif
int initialize();
int parse_port_forward(XML_PARSER&);
void set_web_graphics_url();
void poll(bool log_state = true);
int create_vm();
int register_vm();
int deregister_vm(bool delete_media);
int deregister_stale_vm();
int run(bool do_restore_snapshot);
void cleanup();
void poll(bool log_state = true);
int start();
int stop();
int poweroff();
int pause();
int resume();
void check_trickle_triggers();
void check_intermediate_uploads();
int create_snapshot(double elapsed_time);
int cleanup_snapshots(bool delete_active);
int restore_snapshot();
void dump_hypervisor_logs(bool include_error_logs);
void dump_hypervisor_status_reports();
void dump_vmguestlog_entries();
int is_registered();
bool is_system_ready(std::string& message);
bool is_vm_machine_configuration_available();
bool is_hdd_registered();
bool is_extpack_installed();
bool is_logged_failure_vm_extensions_disabled();
bool is_logged_failure_vm_extensions_in_use();
bool is_logged_failure_vm_extensions_not_supported();
bool is_logged_failure_host_out_of_memory();
bool is_logged_failure_guest_job_out_of_memory();
bool is_logged_completion_file_exists();
bool is_virtualbox_version_newer(int maj, int min, int rel);
bool is_virtualbox_error_recoverable(int retval);
int get_install_directory(std::string& dir);
int get_version_information(std::string& version);
int get_guest_additions(std::string& dir);
int get_slot_directory(std::string& dir);
int get_default_network_interface(std::string& iface);
int get_vm_network_bytes_sent(double& sent);
int get_vm_network_bytes_received(double& received);
@ -258,26 +74,13 @@ public:
int get_vm_exit_code(unsigned long& exit_code);
double get_vm_cpu_time();
int get_system_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
int get_vm_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
int get_trace_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
int set_network_access(bool enabled);
int set_cpu_usage(int percentage);
int set_network_usage(int kilobytes);
int read_floppy(std::string& data);
int write_floppy(std::string& data);
void lower_vm_process_priority();
void reset_vm_process_priority();
int launch_vboxsvc();
int launch_vboxvm();
void sanitize_output(std::string& output);
#ifndef _WIN32
int vbm_popen(
std::string& command, std::string& output, const char* item, bool log_error = true, bool retry_failures = true, unsigned int timeout = 45, bool log_trace = true
);
@ -290,7 +93,7 @@ public:
void vbm_trace(
std::string& command, std::string& ouput, int retval
);
#endif
};
#endif

File diff suppressed because it is too large Load Diff

View File

@ -19,13 +19,13 @@
#ifndef _VBOX_WIN_H_
#define _VBOX_WIN_H_
#include "mscom/VirtualBox.h"
class VBOX_VM : public VBOX_BASE {
public:
VBOX_VM();
~VBOX_VM();
CComPtr<IVirtualBox> m_pVirtualBox;
CComPtr<ISession> m_pSession;
CComPtr<IMachine> m_pMachine;
@ -36,46 +36,31 @@ public:
int vboxsvc_pid;
HANDLE vboxsvc_pid_handle;
int initialize();
int create_vm();
int register_vm();
int deregister_vm(bool delete_media);
int deregister_stale_vm();
void poll(bool log_state = true);
int start();
int stop();
int poweroff();
int pause();
int resume();
int create_snapshot(double elapsed_time);
int cleanup_snapshots(bool delete_active);
int restore_snapshot();
virtual int initialize();
virtual int create_vm();
virtual int register_vm();
virtual int deregister_vm(bool delete_media);
virtual int deregister_stale_vm();
virtual void poll(bool log_state = true);
virtual int start();
virtual int stop();
virtual int poweroff();
virtual int pause();
virtual int resume();
virtual int create_snapshot(double elapsed_time);
virtual int cleanup_snapshots(bool delete_active);
virtual int restore_snapshot();
void dump_hypervisor_logs(bool include_error_logs);
void dump_hypervisor_status_reports();
void dump_vmguestlog_entries();
void check_trickle_triggers();
void check_intermediate_uploads();
int is_registered();
bool is_system_ready(std::string& message);
bool is_vm_machine_configuration_available();
bool is_hdd_registered();
bool is_extpack_installed();
bool is_logged_failure_vm_extensions_disabled();
bool is_logged_failure_vm_extensions_in_use();
bool is_logged_failure_vm_extensions_not_supported();
bool is_logged_failure_host_out_of_memory();
bool is_logged_failure_guest_job_out_of_memory();
bool is_logged_completion_file_exists();
bool is_virtualbox_version_newer(int maj, int min, int rel);
bool is_virtualbox_error_recoverable(int retval);
int get_install_directory(std::string& dir);
int get_version_information(std::string& version);
int get_guest_additions(std::string& dir);
int get_slot_directory(std::string& dir);
int get_default_network_interface(std::string& iface);
int get_vm_network_bytes_sent(double& sent);
int get_vm_network_bytes_received(double& received);
@ -83,25 +68,16 @@ public:
int get_vm_exit_code(unsigned long& exit_code);
double get_vm_cpu_time();
int get_system_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
int get_vm_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
int get_trace_log(std::string& log, bool tail_only = true, unsigned int buffer_size = 8192);
int set_network_access(bool enabled);
int set_cpu_usage(int percentage);
int set_network_usage(int kilobytes);
int read_floppy(std::string& data);
int write_floppy(std::string& data);
void lower_vm_process_priority();
void reset_vm_process_priority();
int launch_vboxsvc();
int launch_vboxvm();
void sanitize_output(std::string& output);
};
#endif

View File

@ -24,7 +24,7 @@
// (use this for credit granting if your app does its
// own job management, like CernVM).
// --nthreads N create a VM with N threads.
// --vmimage file Use "file" as the VM image.
// --vmimage N Use "vm_image_N" as the VM image.
// This lets you create an app version with several images,
// and the app_plan function can decide which one to use
// for the particular host.
@ -50,7 +50,6 @@
#include "win_util.h"
#include "atlcomcli.h"
#include "atlstr.h"
#include "mscom/VirtualBox.h"
#else
#include <vector>
#include <sys/wait.h>
@ -75,7 +74,6 @@
#include "procinfo.h"
#include "vboxwrapper.h"
#include "vbox.h"
#ifdef _WIN32
#include "vbox_win.h"
#else
@ -319,6 +317,13 @@ void read_fraction_done(double& frac_done, VBOX_VM& vm) {
frac_done = frac;
}
bool completion_file_exists(VBOX_VM& vm) {
char path[MAXPATHLEN];
sprintf(path, "shared/%s", vm.completion_trigger_file.c_str());
if (boinc_file_exists(path)) return true;
return false;
}
void read_completion_file_info(unsigned long& exit_code, bool& is_notice, string& message, VBOX_VM& vm) {
char path[MAXPATHLEN];
char buf[1024];
@ -342,6 +347,13 @@ void read_completion_file_info(unsigned long& exit_code, bool& is_notice, string
}
}
bool temporary_exit_file_exists(VBOX_VM& vm) {
char path[MAXPATHLEN];
sprintf(path, "shared/%s", vm.temporary_exit_trigger_file.c_str());
if (boinc_file_exists(path)) return true;
return false;
}
void read_temporary_exit_file_info(int& temp_delay, bool& is_notice, string& message, VBOX_VM& vm) {
char path[MAXPATHLEN];
char buf[1024];
@ -365,6 +377,12 @@ void read_temporary_exit_file_info(int& temp_delay, bool& is_notice, string& mes
}
}
void delete_temporary_exit_trigger_file(VBOX_VM& vm) {
char path[MAXPATHLEN];
sprintf(path, "shared/%s", vm.temporary_exit_trigger_file.c_str());
boinc_delete_file(path);
}
// set CPU and network throttling if needed
//
void set_throttles(APP_INIT_DATA& aid, VBOX_VM& vm) {
@ -494,10 +512,10 @@ void set_remote_desktop_info(APP_INIT_DATA& /* aid */, VBOX_VM& vm) {
// check for trickle trigger files, and send trickles if find them.
//
void VBOX_VM::check_trickle_triggers() {
void check_trickle_triggers(VBOX_VM& vm) {
char filename[256], path[MAXPATHLEN], buf[256];
for (unsigned int i=0; i<trickle_trigger_files.size(); i++) {
strcpy(filename, trickle_trigger_files[i].c_str());
for (unsigned int i=0; i<vm.trickle_trigger_files.size(); i++) {
strcpy(filename, vm.trickle_trigger_files[i].c_str());
sprintf(path, "shared/%s", filename);
if (!boinc_file_exists(path)) continue;
string text;
@ -529,38 +547,38 @@ void VBOX_VM::check_trickle_triggers() {
// check for intermediate upload files, and send them if found.
//
void VBOX_VM::check_intermediate_uploads() {
void check_intermediate_uploads(VBOX_VM& vm) {
int retval;
char filename[256], path[MAXPATHLEN], buf[256];
for (unsigned int i=0; i<intermediate_upload_files.size(); i++) {
strcpy(filename, intermediate_upload_files[i].file.c_str());
for (unsigned int i=0; i<vm.intermediate_upload_files.size(); i++) {
strcpy(filename, vm.intermediate_upload_files[i].file.c_str());
sprintf(path, "shared/%s", filename);
if (!boinc_file_exists(path)) continue;
if (!intermediate_upload_files[i].reported && !intermediate_upload_files[i].ignore) {
if (!vm.intermediate_upload_files[i].reported && !vm.intermediate_upload_files[i].ignore) {
fprintf(stderr,
"%s Reporting an intermediate file. (%s)\n",
vboxwrapper_msg_prefix(buf, sizeof(buf)),
intermediate_upload_files[i].file.c_str()
vm.intermediate_upload_files[i].file.c_str()
);
retval = boinc_upload_file(intermediate_upload_files[i].file);
retval = boinc_upload_file(vm.intermediate_upload_files[i].file);
if (retval) {
fprintf(stderr,
"%s boinc_upload_file() failed: %s\n",
vboxwrapper_msg_prefix(buf, sizeof(buf)), boincerror(retval)
);
intermediate_upload_files[i].ignore = true;
vm.intermediate_upload_files[i].ignore = true;
} else {
intermediate_upload_files[i].reported = true;
vm.intermediate_upload_files[i].reported = true;
}
} else if (intermediate_upload_files[i].reported && !intermediate_upload_files[i].ignore) {
retval = boinc_upload_status(intermediate_upload_files[i].file);
} else if (vm.intermediate_upload_files[i].reported && !vm.intermediate_upload_files[i].ignore) {
retval = boinc_upload_status(vm.intermediate_upload_files[i].file);
if (!retval) {
fprintf(stderr,
"%s Intermediate file uploaded. (%s)\n",
vboxwrapper_msg_prefix(buf, sizeof(buf)),
intermediate_upload_files[i].file.c_str()
vm.intermediate_upload_files[i].file.c_str()
);
intermediate_upload_files[i].ignore = true;
vm.intermediate_upload_files[i].ignore = true;
}
}
}
@ -994,6 +1012,13 @@ int main(int argc, char** argv) {
" operation and this job cannot be recovered.\n";
skip_cleanup = true;
retval = ERR_EXEC;
} else if (retval == (int)VBOX_E_INVALID_OBJECT_STATE) {
error_reason =
" NOTE: VM session lock error encountered.\n"
" BOINC will be notified that it needs to clean up the environment.\n"
" This might be a temporary problem and so this job will be rescheduled for another time.\n";
unrecoverable_error = false;
temp_reason = "VM environment needed to be cleaned up.";
} else if (vm.is_logged_failure_vm_extensions_disabled()) {
error_reason =
" NOTE: BOINC has detected that your computer's processor supports hardware acceleration for\n"
@ -1023,13 +1048,6 @@ int main(int argc, char** argv) {
" This might be a temporary problem and so this job will be rescheduled for another time.\n";
unrecoverable_error = false;
temp_reason = "VM Hypervisor was unable to allocate enough memory to start VM.";
} else if (vm.is_virtualbox_error_recoverable(retval)) {
error_reason =
" NOTE: VM session lock error encountered.\n"
" BOINC will be notified that it needs to clean up the environment.\n"
" This might be a temporary problem and so this job will be rescheduled for another time.\n";
unrecoverable_error = false;
temp_reason = "VM environment needed to be cleaned up.";
} else {
do_dump_hypervisor_logs = true;
}
@ -1146,7 +1164,6 @@ int main(int argc, char** argv) {
}
set_floppy_image(aid, vm);
//set_port_forwarding_info(aid, vm);
set_web_graphics_url(vm);
set_remote_desktop_info(aid, vm);
write_checkpoint(elapsed_time, current_cpu_time, vm);
@ -1173,9 +1190,7 @@ int main(int argc, char** argv) {
vm.dump_hypervisor_logs(true);
boinc_finish(EXIT_ABORTED_BY_CLIENT);
}
if (vm.is_logged_completion_file_exists()) {
vm.reset_vm_process_priority();
vm.cleanup();
if (completion_file_exists(vm)) {
fprintf(
stderr,
"%s VM Completion File Detected.\n",
@ -1190,15 +1205,15 @@ int main(int argc, char** argv) {
message.c_str()
);
}
vm.reset_vm_process_priority();
vm.cleanup();
if (is_notice) {
boinc_finish_message(vm_exit_code, message.c_str(), is_notice);
} else {
boinc_finish(vm_exit_code);
}
}
if (vm.is_logged_temporary_exit_file_exists()) {
vm.reset_vm_process_priority();
vm.stop();
if (temporary_exit_file_exists(vm)) {
fprintf(
stderr,
"%s VM Temporary Exit File Detected.\n",
@ -1213,7 +1228,9 @@ int main(int argc, char** argv) {
message.c_str()
);
}
vm.delete_temporary_exit_trigger_file();
delete_temporary_exit_trigger_file(vm);
vm.reset_vm_process_priority();
vm.stop();
if (is_notice) {
boinc_temporary_exit(temp_delay, message.c_str(), is_notice);
} else {
@ -1277,7 +1294,7 @@ int main(int argc, char** argv) {
if (boinc_status.suspended) {
if (!vm.suspended) {
retval = vm.pause();
if (retval && vm.is_virtualbox_error_recoverable(retval)) {
if (retval && (VBOX_E_INVALID_OBJECT_STATE == retval)) {
fprintf(
stderr,
"%s ERROR: VM task failed to pause, rescheduling task for a later time.\n",
@ -1290,7 +1307,7 @@ int main(int argc, char** argv) {
} else {
if (vm.suspended) {
retval = vm.resume();
if (retval && vm.is_virtualbox_error_recoverable(retval)) {
if (retval && (VBOX_E_INVALID_OBJECT_STATE == retval)) {
fprintf(
stderr,
"%s ERROR: VM task failed to resume, rescheduling task for a later time.\n",
@ -1305,8 +1322,8 @@ int main(int argc, char** argv) {
//
if ((loop_iteration % 10) == 0) {
current_cpu_time = starting_cpu_time + vm.get_vm_cpu_time();
vm.check_trickle_triggers();
vm.check_intermediate_uploads();
check_trickle_triggers(vm);
check_intermediate_uploads(vm);
}
if (vm.job_duration) {

View File

@ -93,6 +93,10 @@
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">vboxwrapper_26108_windows_x86_64</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|x64'">vboxwrapper_26108_windows_x86_64</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">vboxwrapper_26108_windows_intelx86</TargetName>
<TargetName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">vboxwrapper_26108_windows_intelx86</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Midl>
@ -133,12 +137,12 @@
</ResourceCompile>
<Link>
<AdditionalDependencies>libcmt.lib;libcpmt.lib;atls.lib;kernel32.lib;user32.lib;gdi32.lib;ole32.lib;wsock32.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26108_windows_intelx86.exe</OutputFile>
<OutputFile>$(TargetDir)\$(TargetFileName)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26108_windows_intelx86.pdb</ProgramDatabaseFile>
<ProgramDatabaseFile>$(TargetDir)\$(TargetName).pdb</ProgramDatabaseFile>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
@ -183,12 +187,12 @@
</ResourceCompile>
<Link>
<AdditionalDependencies>libcmt.lib;libcpmt.lib;atls.lib;kernel32.lib;user32.lib;gdi32.lib;ole32.lib;wsock32.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26108_windows_x86_64.exe</OutputFile>
<OutputFile>$(TargetDir)\$(TargetFileName)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26108_windows_x86_64.pdb</ProgramDatabaseFile>
<ProgramDatabaseFile>$(TargetDir)\$(TargetName).pdb</ProgramDatabaseFile>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX64</TargetMachine>
</Link>
@ -229,12 +233,12 @@
</ResourceCompile>
<Link>
<AdditionalDependencies>libcmtd.lib;libcpmtd.lib;atlsd.lib;kernel32.lib;user32.lib;gdi32.lib;ole32.lib;psapi.lib;wsock32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_6.1_windows_intelx86.exe</OutputFile>
<OutputFile>$(TargetDir)\$(TargetFileName)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_6.1_windows_intelx86.pdb</ProgramDatabaseFile>
<ProgramDatabaseFile>$(TargetDir)\$(TargetName).pdb</ProgramDatabaseFile>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX86</TargetMachine>
</Link>
@ -275,26 +279,24 @@
</ResourceCompile>
<Link>
<AdditionalDependencies>libcmtd.lib;libcpmtd.lib;atlsd.lib;kernel32.lib;user32.lib;gdi32.lib;ole32.lib;wsock32.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<OutputFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26063_windows_x86_64.exe</OutputFile>
<OutputFile>$(TargetDir)\$(TargetFileName)</OutputFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
<DelayLoadDLLs>%(DelayLoadDLLs)</DelayLoadDLLs>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ProgramDatabaseFile>.\Build\$(Platform)\$(Configuration)\vboxwrapper_26063_windows_x86_64.pdb</ProgramDatabaseFile>
<ProgramDatabaseFile>$(TargetDir)\$(TargetName).pdb</ProgramDatabaseFile>
<SubSystem>Windows</SubSystem>
<TargetMachine>MachineX64</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\samples\vboxwrapper\floppyio.cpp" />
<ClCompile Include="..\samples\vboxwrapper\mscom\VirtualBox_i.c" />
<ClCompile Include="..\samples\vboxwrapper\vbox.cpp" />
<ClCompile Include="..\samples\vboxwrapper\vboxwrapper.cpp" />
<ClCompile Include="..\samples\vboxwrapper\vbox_win.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\samples\vboxwrapper\floppyio.h" />
<ClInclude Include="..\samples\vboxwrapper\mscom\VirtualBox.h" />
<ClInclude Include="..\samples\vboxwrapper\vbox.h" />
<ClInclude Include="..\samples\vboxwrapper\vboxwrapper.h" />
<ClInclude Include="..\samples\vboxwrapper\vboxwrapper_win.h" />