From 68568b400a061d0efc922f84243884668d6f631a Mon Sep 17 00:00:00 2001 From: Rom Walton Date: Fri, 23 Dec 2011 17:24:28 +0000 Subject: [PATCH] - 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 --- checkin_notes | 14 ++++++++ samples/vboxwrapper/vbox.cpp | 22 ++++++++++++ samples/vboxwrapper/vboxwrapper.cpp | 52 ++++++++++------------------- samples/vboxwrapper/vboxwrapper.h | 30 +++++++++++++++++ win_build/vboxwrapper.vcproj | 4 +++ 5 files changed, 87 insertions(+), 35 deletions(-) create mode 100644 samples/vboxwrapper/vboxwrapper.h diff --git a/checkin_notes b/checkin_notes index b83c4e505a..f29b0df24c 100644 --- a/checkin_notes +++ b/checkin_notes @@ -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 diff --git a/samples/vboxwrapper/vbox.cpp b/samples/vboxwrapper/vbox.cpp index 82598a371e..cdc32ee885 100644 --- a/samples/vboxwrapper/vbox.cpp +++ b/samples/vboxwrapper/vbox.cpp @@ -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( + "\n" + " \n" + " vboxwrapper\n" + " %d\n" + " %d\n" + " \n" + "\n", + pf_assigned_host_port, + pf_desired_guest_port + ); + + fclose(f); + return 0; } diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp index 6f7219d33f..3497038f71 100644 --- a/samples/vboxwrapper/vboxwrapper.cpp +++ b/samples/vboxwrapper/vboxwrapper.cpp @@ -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( - "\n" - " \n" - " vboxwrapper\n" - " %d\n" - " %d\n" - " \n" - "\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); diff --git a/samples/vboxwrapper/vboxwrapper.h b/samples/vboxwrapper/vboxwrapper.h new file mode 100644 index 0000000000..bf3a10542b --- /dev/null +++ b/samples/vboxwrapper/vboxwrapper.h @@ -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 . + + +// 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 diff --git a/win_build/vboxwrapper.vcproj b/win_build/vboxwrapper.vcproj index 7aeff2fbc1..f082456484 100644 --- a/win_build/vboxwrapper.vcproj +++ b/win_build/vboxwrapper.vcproj @@ -449,6 +449,10 @@ RelativePath="..\samples\vboxwrapper\vbox.h" > + +