diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index e94222fa68..ffa57e778e 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -734,28 +734,33 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis return; } - int rc = vm->set_saveas_state(); + if ( vm->set_saveas_state() != 0 ) + { + vm->unlock(); + + failure_response(INTERNAL, + request_error("VM has to be RUNNING, POWEROFF or" + " SUSPENDED to saveas disks.",""), att); + return; + } + int iid_orig = vm->get_image_from_disk(disk_id, is_hot, error_str); - vmpool->update(vm); - - vm->unlock(); - if ( iid_orig == -1 ) { + vm->clear_saveas_state(); + + vm->unlock(); + failure_response(INTERNAL, request_error("Cannot use selected DISK", error_str), att); return; } - if ( rc != 0 ) - { - failure_response(INTERNAL, - request_error("VM has to be RUNNING, POWEROFF or" - " SUSPENDED to saveas disks.",""), att); - return; - } + vmpool->update(vm); + + vm->unlock(); // ------------------------------------------------------------------------- // Get the data of the Image to be saved @@ -909,20 +914,20 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis // ------------------------------------------------------------------------- // Create the image // ------------------------------------------------------------------------- - rc = ipool->allocate(att.uid, - att.gid, - att.uname, - att.gname, - umask, - itemplate, - ds_id, - ds_name, - ds_disk_type, - ds_data, - Datastore::IMAGE_DS, - -1, - &iid, - error_str); + int rc = ipool->allocate(att.uid, + att.gid, + att.uname, + att.gname, + umask, + itemplate, + ds_id, + ds_name, + ds_disk_type, + ds_data, + Datastore::IMAGE_DS, + -1, + &iid, + error_str); if (rc < 0) { quota_rollback(&img_usage, Quotas::DATASTORE, att);