Hi,
I am trying to implement restore functionality in my application as described in the Designing vSphere Backup Solutions documentations. The application connects to a VM on a remote vCenter using VixDiskLib_ConnectEx, opens a virtual disk for writing and writes data on the disk.
I need to handle this scenario: if a netork failure occurs during writing data on disk then the application waits for the network to become available again and resumes writing data. The way I see it, the right thing to do is close the disk, re-open it and keep writing on it. Problem is, the disk cannot be closed. Logs show that the close comand could not be sent and so the disk remains locked. This is the full sequence of actions that replicate this:
- make a VM snapshot using the vSphere client
- open connection to the VM disks using default transport and snapshot's reference ID
- open a disk for writing in mode = unbuffered; the disk belongs to the snapshot
- write data in the first sector
- simulate a network failure: disable the network adapter and enable it
- wait for the network to become available; keep pinging the vCenter until it can be reached
- close the disk
- close the connection
- open a new connection
- open disk on the new connection
- write data in the first sector
The error occurs when opening the disk on the new connection: file already locked. I also attached the full code; connection settings are hardcoded in Main.
Any idea how to make this work?