vmfsfilelockinfo is inbuilt tool on ESX server to check which host is holding the lock on VM files. To prevent concurrent changes to virtual machine files, ESXi host establish locks on virtual machine files. Once we vmotion virtual machine from ESX host A to ESX host B, then that host B holds the lock of virtual machine. It can be verified by running vmfsfilelockinfo command.
How to run this command. ?
First we have to ssh into ESXi host using root. We can run this command by running command “vmfsfilelockinfo -p /vmfs/volumes/<location of vm files>/<vmname.vmx”.
Please note with this command, it will only look for ESX hosts in the same cluster as ESX host on which you are running this command from. If we want to search all the ESX hosts in vcenter which are holding the locks , then we need to run “vmfsfilelockinfo -p /vmfs/volumes/<location of vm files>/<vmname.vmx -v <vcenter name or IP> -u <local administrator username of vcenter>”
Why we need to know which ESX is holding the lock?
In some rare situations, VM is on ESX host A but we find out by running the command above that ESX host B is holding the locks. In that scenario, we will likely not be able to power on VM if it is power off. Now question is why this happened? In our case this happened because we took some storage level snapshot on storage LUN on which VM files were residing. At that time, VM was on ESX host B which means ESX host B was holding the lock that time. After some time, DRS move the VM from host B to Host A which means host A should technically be holding VM files lock. Now for some reason we had to shut down the VM and restore the VM from storage snapshot. After restore, though VM was running on Host A now but VM files lock was found to be holding by host B ( as per time of storage snapshot) . We can verify that by running the above command. To overcome this situation, we can either a ) reboot ESX host B so that it releases the lock or b) unregister VM from vcenter and using ‘.vmx’ file register VM again , this time on Host B which was still holding the lock on virtual machine files.
This KB article provides much more information on same topic.
https://kb.vmware.com/s/article/10051