- VBOX: Write the firewall rules once, after creation. If the job was suspended

and restarted it would null out the host port information.
    - VBOX: Try to make the CERN compatible datatype for FloppyIO more JSON friendly
        by following the advice of issue:
          https://github.com/stig/json-framework/issues/48
    - VBOX: Support both the old style and new style of determining assigned threads
        of execution (aka core counts).  6.12 and the early versions of 7.x support
        the old style.
        
    samples/vboxwrapper/
        vbox.cpp, .h
        vboxwrapper.cpp, .h

svn path=/trunk/boinc/; revision=24876
This commit is contained in:
Rom Walton 2011-12-23 17:24:28 +00:00
parent 7419d3a7e1
commit 68568b400a
5 changed files with 87 additions and 35 deletions

View File

@ -9324,3 +9324,17 @@ Rom 22 Dec 2011
samples/vboxwrapper/
vboxwrapper.cpp
Rom 23 Dec 2011
- VBOX: Write the firewall rules once, after creation. If the job was suspended
and restarted it would null out the host port information.
- VBOX: Try to make the CERN compatible datatype for FloppyIO more JSON friendly
by following the advice of issue:
https://github.com/stig/json-framework/issues/48
- VBOX: Support both the old style and new style of determining assigned threads
of execution (aka core counts). 6.12 and the early versions of 7.x support
the old style.
samples/vboxwrapper/
vbox.cpp, .h
vboxwrapper.cpp, .h

View File

@ -49,6 +49,7 @@ using std::string;
#include "network.h"
#include "boinc_api.h"
#include "floppyio.h"
#include "vboxwrapper.h"
#include "vbox.h"
VBOX_VM::VBOX_VM() {
@ -759,6 +760,27 @@ int VBOX_VM::register_vm_firewall_rules() {
boinc_msg_prefix(buf, sizeof(buf)), pf_assigned_host_port
);
// Write firewall rule to disk
//
MIOFILE mf;
FILE* f = boinc_fopen(PORTFORWARD_FILENAME, "w");
mf.init_file(f);
mf.printf(
"<vbox_firewall>\n"
" <rule>\n"
" <name>vboxwrapper</name>\n"
" <host_port>%d</host_port>\n"
" <guest_port>%d</guest_port>\n"
" </rule>\n"
"</vbox_firewall>\n",
pf_assigned_host_port,
pf_desired_guest_port
);
fclose(f);
return 0;
}

View File

@ -69,16 +69,11 @@
#include "util.h"
#include "error_numbers.h"
#include "procinfo.h"
#include "vboxwrapper.h"
#include "vbox.h"
using std::vector;
#define IMAGE_FILENAME "vm_image.vdi"
#define JOB_FILENAME "vbox_job.xml"
#define CHECKPOINT_FILENAME "vbox_checkpoint.txt"
#define PORTFORWARD_FILENAME "vbox_firewall.txt"
#define POLL_PERIOD 1.0
int parse_job_file(VBOX_VM& vm) {
MIOFILE mf;
char buf[1024], buf2[256];
@ -192,12 +187,16 @@ void set_floppy_image(APP_INIT_DATA& aid, VBOX_VM& vm) {
);
}
} else {
// Per: https://github.com/stig/json-framework/issues/48
//
// Use %.17g to represent doubles
//
scratch = "BOINC_USERNAME=" + std::string(aid.user_name) + "\n";
sprintf(buf, "%f", aid.user_total_credit);
sprintf(buf, "%.17g", aid.user_total_credit);
scratch += "BOINC_USER_TOTAL_CREDIT=" + std::string(buf) + "\n";
sprintf(buf, "%f", aid.host_total_credit);
sprintf(buf, "%.17g", aid.host_total_credit);
scratch += "BOINC_HOST_TOTAL_CREDIT=" + std::string(buf) + "\n";
scratch += "BOINC_AUTHENTICATOR=" + std::string(aid.authenticator) + "\n";
@ -206,30 +205,6 @@ void set_floppy_image(APP_INIT_DATA& aid, VBOX_VM& vm) {
}
}
// If a project has decided it wants to use port forwarding, write the port
// information to a file so that a graphics application or some other
// application knows what port number has been assigned to the VM.
//
void write_firewall_rules(VBOX_VM& vm) {
MIOFILE mf;
FILE* f = boinc_fopen(PORTFORWARD_FILENAME, "w");
mf.init_file(f);
mf.printf(
"<vbox_firewall>\n"
" <rule>\n"
" <name>vboxwrapper</name>\n"
" <host_port>%d</host_port>\n"
" <guest_port>%d</guest_port>\n"
" </rule>\n"
"</vbox_firewall>\n",
vm.pf_assigned_host_port,
vm.pf_desired_guest_port
);
fclose(f);
}
int main(int argc, char** argv) {
int retval;
BOINC_OPTIONS boinc_options;
@ -245,6 +220,7 @@ int main(int argc, char** argv) {
double bytes_sent=0, bytes_received=0;
bool report_net_usage = false;
int vm_pid=0;
int vm_max_cpus=0;
char buf[256];
memset(&boinc_options, 0, sizeof(boinc_options));
@ -257,6 +233,9 @@ int main(int argc, char** argv) {
if (!strcmp(argv[i], "--trickle")) {
trickle_period = atof(argv[++i]);
}
if (!strcmp(argv[i], "--nthreads")) {
vm_max_cpus = atoi(argv[++i]);
}
if (!strcmp(argv[i], "--register_only")) {
vm.register_only = true;
}
@ -327,8 +306,12 @@ int main(int argc, char** argv) {
vm.image_filename = buf;
boinc_rename(IMAGE_FILENAME, buf);
}
if (aid.ncpus > 1.0) {
sprintf(buf, "%d", (int)aid.ncpus);
if (aid.ncpus > 1.0 || vm_max_cpus > 1) {
if (vm_max_cpus) {
sprintf(buf, "%d", vm_max_cpus);
} else {
sprintf(buf, "%d", (int)aid.ncpus);
}
vm.vm_cpu_count = buf;
} else {
vm.vm_cpu_count = "1";
@ -344,7 +327,6 @@ int main(int argc, char** argv) {
boinc_finish(retval);
}
write_firewall_rules(vm);
set_floppy_image(aid, vm);
set_throttles(aid, vm);

View File

@ -0,0 +1,30 @@
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2010 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
// Provide cross-platform interfaces for making changes to VirtualBox
#ifndef _VBOXWRAPPER_H_
#define _VBOXWRAPPER_H_
#define IMAGE_FILENAME "vm_image.vdi"
#define JOB_FILENAME "vbox_job.xml"
#define CHECKPOINT_FILENAME "vbox_checkpoint.txt"
#define PORTFORWARD_FILENAME "vbox_firewall.txt"
#define POLL_PERIOD 1.0
#endif

View File

@ -449,6 +449,10 @@
RelativePath="..\samples\vboxwrapper\vbox.h"
>
</File>
<File
RelativePath="..\samples\vboxwrapper\vboxwrapper.h"
>
</File>
</Filter>
</Files>
<Globals>