From a57cbb79879a3e285e8e8d166a730e71717cf532 Mon Sep 17 00:00:00 2001 From: Rom Walton <rwalton@ssl.berkeley.edu> Date: Mon, 7 Jul 2014 16:03:46 -0400 Subject: [PATCH] Add implementation for an extra cache disk This commit adds two extra options: - enable_cache_disk - cache_disk_filename This allows to attach a cache disk image to extend the storage needs initially provided by the OS image. In context-based systems such as uCernVM, this image can be used to store the local cache of artifacs coming from CVMFS. Note this image is attached without further checking on the content and is entirely up to the main OS to make good use of it. Signed-off-by: Carlos Aguado Sanchez <carlos.aguado@epfl.ch> --- samples/vboxwrapper/vbox.cpp | 53 ++++++++++++++++++++++++++--- samples/vboxwrapper/vbox.h | 6 ++++ samples/vboxwrapper/vboxwrapper.cpp | 9 +++++ samples/vboxwrapper/vboxwrapper.h | 2 ++ 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/samples/vboxwrapper/vbox.cpp b/samples/vboxwrapper/vbox.cpp index 60653661df..c0a36d8171 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 e86f5239f9..fdb34607fc 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 65f2d4621c..fdb87a9363 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 7362de6264..4f6d2474a3 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" -- GitLab