Open Nebula : After attaching a disk to a VM, getting "failed to lock the file" When I am starting the machine

Hi Sanal!
I’ve been reviewing the code and I’ve reproduced the issue, so thanks for the info you’ve provided me.

I think I’ve found a fix, so if you could try it, here it is and the instructions to test it follows.

Instructions:

  1. First create a backup of your vcenter_driver.rb file, that file is located in /usr/lib/one/ruby/vcenter_driver.rb
  2. The line numbers I provide may be different from yours so check that you’re changing the right lines with the info I give you.
  3. Edit the vcenter_driver.rb file and locate the self.reconfigure_vm function, it should be near 2467 line.
  4. Inside that function go to lines 2636 -2637, you should see:
if !newvm
       vm.config.hardware.device.select {

Now replace the lines between if !newvm and end (lines 2636 to 2647) with the code I’ve linked you in a gist from GitHub. It should look like this after the change:

       # If the VM is not new, avoid reading DISKS
        if !newvm
            vm.config.hardware.device.select { |d|
                if is_disk?(d)
                   disks.each{|disk|
                      if d.backing.respond_to?(:fileName) &&
                         ("[#{disk.elements["DATASTORE"].text}] #{disk.elements["SOURCE"].text}" == d.backing.fileName ||
                          disk.elements["SOURCE"].text == d.backing.fileName)
                         disks.delete(disk)
                      end
                   }
                end
            }
        end

Finally, stop OpenNebula’s daemon and restart it again so the new code is used, and before trying to resume the affect VM again, you should remove the duplicated disks as you mentioned before so the file is not locked.

Try it and let’s see if it solves your issue!

Cheers!