unable to power-on snapshot, or...?

Feb 2, 2010 at 2:05 PM
Edited Feb 2, 2010 at 2:06 PM
dB,

  I have found your vmwaretasks library a great springboard and
no significant issues that I couldn't figure out, until now.
My current program is usually using the current state of my VM.
There is a certain circumstance where I need the VM to revert to a pre-configured "Baseline" snapshot before continuing.

I use the following snip, taken mostly from the initial example in your documentation:

virtualMachine.PowerOff();
// find the snapshot
VMWareSnapshot snapshot = virtualMachine.Snapshots.GetNamedSnapshot("Baseline");
// revert to the Baseline snapshot
snapshot.RevertToSnapshot();


When the last line is executed, the program receives an exception which expands to "The file is already in use".
Could you please advise me on what I'm missing or doing incorrectly?

Thanks


-bC
Coordinator
Feb 2, 2010 at 3:14 PM

This usually means that another process (or another thread in your own process) is doing something to the virtual machine, so it can't revert to a snapshot while that operation is in progress (eg. another revert to a snapshot operation). Does this code fail in a simple command-line program? If it does, write it and post it here.

Feb 2, 2010 at 3:41 PM

I will try and figure out how to do a command-line only program in C#.  Thus far, only using the VisualStudio IDE to setup a project for me using windows and such.  Hopefully won't be too tough for me.

BTW #1: I have an existing DOS-command batch script that accomplishes all this using VMRUN commands.... so I feel that the VM and sequence of events is hopefully sound.

BTW #2: I forgot to mention initially that this current C# project is manipulating a VM within VMware Workstation 6.5.2, in case information that makes any difference in the steps that I should use.

 

 

 

Feb 2, 2010 at 7:24 PM

Below is a simple console version of the essentials.  It is also giving me the "file-in-use" message.  BTW, the VM is left in a suspended state and seems to have switched back to the snapshot; just not resumed.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vestris.VMWareLib;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            // declare a virtual host
            VMWareVirtualHost virtualHost = new VMWareVirtualHost();
            // connect to a local (VMWare Workstation) virtual machine
            virtualHost.ConnectToVMWareWorkstation();
            // open an existing virtual machine
            VMWareVirtualMachine virtualMachine = virtualHost.Open("C:\\Documents and Settings\\Ardbeg\\My Documents\\Expo2\\VM\\VM.vmx");
            // power on this virtual machine
            virtualMachine.PowerOn();

            // wait for tools to launch
            virtualMachine.WaitForToolsInGuest();
            virtualMachine.PowerOff();
            VMWareSnapshot snapshot = virtualMachine.Snapshots.GetNamedSnapshot("Baseline");
            // revert to the "Baseline" snapshot
            snapshot.RevertToSnapshot();

            virtualHost.Disconnect();

        }
    }
}

Feb 4, 2010 at 12:15 PM

dB,

  Need more info?  Any ideas?

 

thanks

 

-bC

 

Coordinator
Feb 8, 2010 at 1:03 PM

Yes, I have more questions.

  1. What state is the snapshot in? Was it snapshot powered-down, suspended, etc.?
  2. Which line actually throws this error? A call stack would be nice.

I doubt that the VMWareTasks library has anything to do with this problem. You should bring this up in the VixCOM forum too.

Thanks,
dB.

Feb 9, 2010 at 7:09 PM
Edited Feb 9, 2010 at 7:10 PM

dB ,

   The snapshot was made while the VM was powered-on and running; not suspended or powered-down.

Here's the call stack info:

>    ConsoleApplication1.exe!ConsoleApplication1.Program.Main(string[] args = {string[0]}) Line 27    C#
     [External Code]    

Here's the exception details:


Vestris.VMWareLib.VMWareException was unhandled
  Message="The file is already in use"
  Source="Vestris.VMWareLib"
  ErrorCode=15
  StackTrace:
       at Vestris.VMWareLib.VMWareInterop.Check(UInt64 errCode)
       at Vestris.VMWareLib.VMWareJob.Wait(Int32 timeoutInSeconds)
       at Vestris.VMWareLib.VMWareSnapshot.RevertToSnapshot(Int32 powerOnOptions, Int32 timeoutInSeconds)
       at Vestris.VMWareLib.VMWareSnapshot.RevertToSnapshot(Int32 timeoutInSeconds)
       at Vestris.VMWareLib.VMWareSnapshot.RevertToSnapshot()
       at ConsoleApplication1.Program.Main(String[] args) in C:\Documents and Settings\Barry\Local Settings\Application Data\Temporary Projects\ConsoleApplication1\Program.cs:line 27
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException:

 

Feb 11, 2010 at 8:11 PM

I have the same problem trying to restore snapshots as well.  Mine are in the powered on state as well that might be a common factor.

I Use the following code to work around the issue.

VMWareSnapshot snapshot = virtualMachine.Snapshots.GetNamedSnapshot("Ocular");
try {
    snapshot.RevertToSnapshot();
} catch {
    virtualMachine.PowerOn();
}

Craig 

Coordinator
Feb 11, 2010 at 9:57 PM

Are you on Workstation as well?

Feb 11, 2010 at 11:46 PM
Edited Feb 12, 2010 at 1:50 AM

Craig,

  Thanks for the idea on the work-around.  I'll be sure to try that.

a little later....     Yes, works for me too.

 

Any ideas db?

 

 

Feb 12, 2010 at 3:44 PM

Yes I'm running WMWare Workstation Ver 6.5.3  I tried it on 7.1.0 as well both fail in same mannor.

Craig

Coordinator
Feb 13, 2010 at 12:06 AM

Sorry for the late reply. I figured it out.

RevertToSnapshot will fail with "file already in use" on VMWare workstation (both 6.x and 7.x) when you pass VIX_VMPOWEROP_NORMAL and try to revert a Live (powered on) snapshot. I think VIX_VMPOWEROP_NORMAL is meant to figure out what kind of power-on state to bring the snapshot to, so looks like a bug to me. The workaround is to use any other flag, both VIX_VMPOWEROP_LAUNCH_GUI and VIX_VMPOWEROP_SUPPRESS_SNAPSHOT_POWERON produce expected results.

This worked for me:

VMWareSnapshot snapshot = virtualMachine.Snapshots.GetNamedSnapshot("Live");
snapshot.RevertToSnapshot(Interop.VixCOM.Constants.VIX_VMPOWEROP_SUPPRESS_SNAPSHOT_POWERON, VMWareInterop.Timeouts.RevertToSnapshotTimeout);
virtualMachine.PowerOn();

Posted to VixCOM forum here, maybe it's a bug.

Feb 15, 2010 at 12:24 PM

Thanks dB!