diff --git a/samples/vboxwrapper/vbox.cpp b/samples/vboxwrapper/vbox.cpp index 60653661df7a2466fb579c108e93085b115319a9..c0a36d81718bb92095a218fed32082d107ef0e1a 100644 --- a/samples/vboxwrapper/vbox.cpp +++ b/samples/vboxwrapper/vbox.cpp @@ -80,6 +80,7 @@ VBOX_VM::VBOX_VM() { memory_size_mb.clear(); image_filename.clear(); iso_image_filename.clear(); + cache_disk_filename.clear(); floppy_image_filename.clear(); job_duration = 0.0; current_cpu_time = 0.0; @@ -94,6 +95,7 @@ VBOX_VM::VBOX_VM() { enable_cern_dataformat = false; enable_shared_directory = false; enable_floppyio = false; + enable_cache_disk = false; enable_isocontextualization = false; enable_remotedesktop = false; register_only = false; @@ -723,13 +725,34 @@ int VBOX_VM::create_vm() { ); command = "storageattach \"" + vm_name + "\" "; command += "--storagectl \"Hard Disk Controller\" "; - command += "--port 0 "; + command += "--port 1 "; command += "--device 0 "; command += "--type dvddrive "; command += "--medium \"" + virtual_machine_slot_directory + "/" + iso_image_filename + "\" "; - retval = vbm_popen(command, output, "storage attach (iso9660 image)"); + retval = vbm_popen(command, output, "storage attach (ISO 9660 image)"); if (retval) return retval; + + // Add a virtual cache disk drive to VM + // + if (enable_cache_disk){ + fprintf( + stderr, + "%s Adding virtual cache disk drive to VM. (%s)\n", + vboxwrapper_msg_prefix(buf, sizeof(buf)), + image_filename.c_str() + ); + command = "storageattach \"" + vm_name + "\" "; + command += "--storagectl \"Hard Disk Controller\" "; + command += "--port 0 "; + command += "--device 0 "; + command += "--type hdd "; + command += "--setuuid \"\" "; + command += "--medium \"" + virtual_machine_slot_directory + "/" + cache_disk_filename + "\" "; + + retval = vbm_popen(command, output, "storage attach (cached disk)"); + if (retval) return retval; + } } else { // Adding virtual hard drive to VM // @@ -1004,7 +1027,21 @@ int VBOX_VM::deregister_vm(bool delete_media) { if (delete_media) { command += "--delete "; } - vbm_popen(command, output, "remove virtual ido9660 disk", false, false); + vbm_popen(command, output, "remove virtual ISO 9660 disk", false, false); + + if (enable_cache_disk) { + fprintf( + stderr, + "%s Removing virtual cache disk from VirtualBox.\n", + vboxwrapper_msg_prefix(buf, sizeof(buf)) + ); + command = "closemedium disk \"" + virtual_machine_slot_directory + "/" + cache_disk_filename + "\" "; + if (delete_media) { + command += "--delete "; + } + + vbm_popen(command, output, "remove virtual cache disk", false, false); + } } else { fprintf( stderr, @@ -1082,7 +1119,15 @@ int VBOX_VM::deregister_stale_vm() { command = "closemedium floppy \"" + virtual_machine_slot_directory + "/" + floppy_image_filename + "\" "; vbm_popen(command, output, "remove virtual floppy disk", false, false); } - } + if (enable_isocontextualization) { + command = "closemedium dvd \"" + virtual_machine_slot_directory + "/" + iso_image_filename + "\" "; + vbm_popen(command, output, "remove virtual ISO 9660 disk", false); + + if (enable_cache_disk) { + command = "closemedium disk \"" + virtual_machine_slot_directory + "/" + cache_disk_filename + "\" "; + vbm_popen(command, output, "remove virtual cache disk", false); + } + } return 0; } diff --git a/samples/vboxwrapper/vbox.h b/samples/vboxwrapper/vbox.h index e86f5239f98098d291d14903e28c8b10f1903d4c..fdb34607fc253fecc0ec5891bebcc008e73a7dff 100644 --- a/samples/vboxwrapper/vbox.h +++ b/samples/vboxwrapper/vbox.h @@ -89,6 +89,10 @@ public: std::string image_filename; // name of the virtual machine iso9660 disk image file std::string iso_image_filename; + // name of the virtual machine cache disk image file + std::string cache_disk_filename; + // name of the virtual machine floppy disk image file + std::string floppy_image_filename; // name of the virtual machine floppy disk image file std::string floppy_image_filename; // amount of CPU time consumed by the VM (note: use get_vm_cpu_time()) @@ -125,6 +129,8 @@ public: // the disk controller model to emulate 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 enable_shared_directory; diff --git a/samples/vboxwrapper/vboxwrapper.cpp b/samples/vboxwrapper/vboxwrapper.cpp index 65f2d4621cd288b7bda61a4cd2e27bfadbb54097..fdb87a9363ba83e8b4d106c3a438781040f56c90 100644 --- a/samples/vboxwrapper/vboxwrapper.cpp +++ b/samples/vboxwrapper/vboxwrapper.cpp @@ -167,6 +167,7 @@ int parse_job_file(VBOX_VM& vm) { else if (xp.parse_bool("enable_network", vm.enable_network)) continue; else if (xp.parse_bool("enable_shared_directory", vm.enable_shared_directory)) continue; else if (xp.parse_bool("enable_floppyio", vm.enable_floppyio)) continue; + else if (xp.parse_bool("enable_cache_disk", vm.enable_cache_disk)) continue; else if (xp.parse_bool("enable_isocontextualization", vm.enable_isocontextualization)) continue; else if (xp.parse_bool("enable_remotedesktop", vm.enable_remotedesktop)) continue; else if (xp.parse_int("pf_guest_port", vm.pf_guest_port)) continue; @@ -775,6 +776,10 @@ int main(int argc, char** argv) { ); vm.floppy_image_filename = buf; } + if (vm.enable_cache_disk) { + sprintf(buf, "%s.%s", CACHE_DISK_FILENAME, CACHE_DISK_FILENAME_EXTENSION); + vm.cache_disk_filename = buf; + } if (vm.enable_isocontextualization) { sprintf(buf, "%s.%s", ISO_IMAGE_FILENAME, ISO_IMAGE_FILENAME_EXTENSION); vm.iso_image_filename = buf; @@ -795,6 +800,10 @@ int main(int argc, char** argv) { ); vm.floppy_image_filename = buf; } + if (vm.enable_cache_disk) { + sprintf(buf, "%s_%d.%s", CACHE_DISK_FILENAME, aid.slot, CACHE_DISK_FILENAME_EXTENSION); + vm.cache_disk_filename = buf; + } if (vm.enable_isocontextualization) { sprintf(buf, "%s_%d.%s", ISO_IMAGE_FILENAME, aid.slot, ISO_IMAGE_FILENAME_EXTENSION); vm.iso_image_filename = buf; diff --git a/samples/vboxwrapper/vboxwrapper.h b/samples/vboxwrapper/vboxwrapper.h index 7362de6264a417886f07ccf47dc86d1dd73b87ae..4f6d2474a34c84a447206e27291f03a2fbd3ad68 100644 --- a/samples/vboxwrapper/vboxwrapper.h +++ b/samples/vboxwrapper/vboxwrapper.h @@ -26,6 +26,8 @@ #define IMAGE_FILENAME_EXTENSION "vdi" #define FLOPPY_IMAGE_FILENAME "vm_floppy" #define FLOPPY_IMAGE_FILENAME_EXTENSION "img" +#define CACHE_DISK_FILENAME "vm_cache" +#define CACHE_DISK_FILENAME_EXTENSION "vdi" #define ISO_IMAGE_FILENAME "vm_isocontext" #define ISO_IMAGE_FILENAME_EXTENSION "iso" #define JOB_FILENAME "vbox_job.xml"