diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 5a2b24934a..9f8c7915ae 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -67,7 +67,8 @@ public: SNAPSHOT_CREATE, SNAPSHOT_REVERT, SNAPSHOT_DELETE, - DISK_SNAPSHOT_CREATE + DISK_SNAPSHOT_CREATE, + DISK_RESIZE }; /** @@ -409,13 +410,20 @@ private: void detach_nic_action( int vid); + /** + * This function cancels the current driver operation + */ + void driver_cancel_action( + int vid); + /** * Creates a new system snapshot. The VM must have a snapshot with the * attribute ACTIVE = YES * * @param vid the id of the VM. */ - void snapshot_create_action(int vid); + void snapshot_create_action( + int vid); /** * Reverts to a snapshot. The VM must have a snapshot with the @@ -423,7 +431,8 @@ private: * * @param vid the id of the VM. */ - void snapshot_revert_action(int vid); + void snapshot_revert_action( + int vid); /** * Deletes a snapshot. The VM must have a snapshot with the @@ -431,19 +440,23 @@ private: * * @param vid the id of the VM. */ - void snapshot_delete_action(int vid); + void snapshot_delete_action( + int vid); /** * Creates a new disk system snapshot. * * @param vid the id of the VM. */ - void disk_snapshot_create_action(int vid); + void disk_snapshot_create_action( + int vid); /** - * This function cancels the current driver operation + * Resize a VM disk + * + * @param vid the id of the VM. */ - void driver_cancel_action( + void disk_resize_action( int vid); }; diff --git a/include/VirtualMachineManagerDriver.h b/include/VirtualMachineManagerDriver.h index c18e9adc68..1523bc7fc7 100644 --- a/include/VirtualMachineManagerDriver.h +++ b/include/VirtualMachineManagerDriver.h @@ -401,6 +401,19 @@ private: write_drv("DISKSNAPSHOTCREATE", oid, drv_msg); } + /** + * Sends a disk resize request to the MAD: + * "RESIZE ID XML_DRV_MSG" + * @param oid the virtual machine id. + * @param drv_msg xml data for the mad operation + */ + void disk_resize ( + const int oid, + const string& drv_msg) const + { + write_drv("RESIZEDISK", oid, drv_msg); + } + /** * Sends a request to update the VM security groups: * "UPDATESG ID XML_DRV_MSG" diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index 1cf3a24bae..2dea25aead 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -2176,7 +2176,7 @@ int DispatchManager::disk_resize( vmpool->update_history(vm); -// vmm->trigger(VirtualMachineManager::DISK_SNAPSHOT_CREATE, vid); + vmm->trigger(VirtualMachineManager::DISK_RESIZE, vid); break; default: break; diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 170bfecbb5..aa3637ab32 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -203,6 +203,10 @@ void VirtualMachineManager::trigger(Actions action, int _vid) aname = "DISK_SNAPSHOT_CREATE"; break; + case DISK_RESIZE: + aname = "DISK_RESIZE"; + break; + default: delete vid; return; @@ -322,6 +326,10 @@ void VirtualMachineManager::do_action(const string &action, void * arg) { disk_snapshot_create_action(vid); } + else if (action == "DISK_RESIZE") + { + disk_resize_action(vid); + } else if (action == ACTION_TIMER) { timer_action(); @@ -2298,6 +2306,117 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void VirtualMachineManager::disk_resize_action(int vid) +{ + VirtualMachine * vm; + const VirtualMachineManagerDriver * vmd; + + VirtualMachineDisk * disk; + + ostringstream os; + + string vm_tmpl; + string* drv_msg; + + string resize_cmd; + string disk_path; + + Nebula& nd = Nebula::instance(); + TransferManager * tm = nd.get_tm(); + + vm = vmpool->get(vid,true); + + if (vm == 0) + { + return; + } + + if (!vm->hasHistory()) + { + goto error_history; + } + + vmd = get(vm->get_vmm_mad()); + + if ( vmd == 0 ) + { + goto error_driver; + } + + disk = vm->get_resize_disk(); + + if ( disk == 0 ) + { + goto error_disk; + } + + tm->resize_command(vm, disk, os); + + resize_cmd = os.str(); + + os.str(""); + + if ( resize_cmd.empty() ) + { + goto error_no_tm_command; + } + + os << vm->get_system_dir() << "/disk." << disk->get_disk_id(); + + disk_path = os.str(); + + // Invoke driver method + drv_msg = format_message( + vm->get_hostname(), + "", + vm->get_deploy_id(), + "", + "", + "", + resize_cmd, + "", + disk_path, + vm->to_xml(vm_tmpl), + vm->get_ds_id(), + -1); + + vmd->disk_resize(vid, *drv_msg); + + vm->unlock(); + + delete drv_msg; + + return; + +error_disk: + os << "disk_snapshot_create, could not find disk to take snapshot"; + goto error_common; + +error_history: + os << "disk_snapshot_create, VM has no history"; + goto error_common; + +error_driver: + os << "disk_snapshot_create, error getting driver " << vm->get_vmm_mad(); + goto error_common; + +error_no_tm_command: + os << "Cannot set disk for snapshot."; + goto error_common; + +error_common: + Nebula &ne = Nebula::instance(); + LifeCycleManager * lcm = ne.get_lcm(); + + lcm->trigger(LifeCycleManager::DISK_SNAPSHOT_FAILURE, vid); + + vm->log("VMM", Log::ERROR, os); + vm->unlock(); + return; +} +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + void VirtualMachineManager::attach_nic_action( int vid) { diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index 1ffcaa7d48..4440b3bd15 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -622,6 +622,22 @@ void VirtualMachineManagerDriver::protocol(const string& message) const lcm->trigger(LifeCycleManager::DISK_SNAPSHOT_FAILURE, id); } } + else if ( action == "RESIZEDISK" ) + { + if ( result == "SUCCESS" ) + { + vm->log("VMM", Log::INFO, "VM disk successfully resized"); + + lcm->trigger(LifeCycleManager::DISK_RESIZE_SUCCESS, id); + } + else + { + log_error(vm, os, is, "Error resizing disk"); + vmpool->update(vm); + + lcm->trigger(LifeCycleManager::DISK_RESIZE_FAILURE, id); + } + } else if ( action == "CLEANUP" ) { if ( result == "SUCCESS" ) diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index 909ada6d5b..f5f7e98029 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -789,13 +789,16 @@ class ExecDriver < VirtualMachineDriver tm_command = ensure_xpath(xml_data, id, action, 'TM_COMMAND') || return - size = xml_data.elements['SIZE'].text.strip - disk_id = xml_data.elements['DISK_ID'].text.strip + size_xpath = "VM/TEMPLATE/DISK[RESIZE='YES']/SIZE" + size = ensure_xpath(xml_data, id, action, size_xpath) || return + + disk_id_xpath = "VM/TEMPLATE/DISK[RESIZE='YES']/DISK_ID" + disk_id = ensure_xpath(xml_data, id, action, disk_id_xpath) || return action = VmmAction.new(self, id, :resize_disk, drv_message) steps = [ - # Perform a PROLOG on the disk + # Perform the resize command { :driver => :tm, :action => :tm_resize, diff --git a/src/vmm_mad/remotes/kvm/resize_disk b/src/vmm_mad/remotes/kvm/resize_disk index 7ecfbf49dc..b256091f67 100755 --- a/src/vmm_mad/remotes/kvm/resize_disk +++ b/src/vmm_mad/remotes/kvm/resize_disk @@ -1,4 +1,4 @@ -#!/bin/bash -x +#!/bin/bash # -------------------------------------------------------------------------- # # Copyright 2002-2016, OpenNebula Project, OpenNebula Systems #