5 Replies Latest reply on Oct 13, 2009 4:26 AM by WhiteKnight

    Improvement Suggestion: Suspend VMs Automatically On Host Log-off/Shut-down

    WhiteKnight Hot Shot

      When logging off or shutting down the host OS (Windows), VMware Workstation should automatically suspend all running VMs (incl. VMs running in the background) immediately.

       

      Currently on Windows 7 Workstation just hangs when a user is logging off at the host OS. At the same time VMs running in the background are simply abruptly shut off. Even though NTFS is a transactional file system, simply cutting off power is something that's never to be regarded a good idea.

       

      Hence, I'd like to suggest to implement a graceful shutdown behaviour of Workstation.

       

      .

      (for a previous discussion on this see here)

        • 1. Re: Improvement Suggestion: Suspend VMs Automatically On Host Log-off/Shut-down
          mdford Enthusiast

           

          I'll second that!

           

           

          In addition to suspending upon logoff/shutdown of the host, I'd like to add that all machines should be suspended when the host is put to sleep.  This currently sometimes works, but usually the VMs are locked up when the host resumes.

           

           

           

           

           

          • 2. Re: Improvement Suggestion: Suspend VMs Automatically On Host Log-off/Shut-down
            ksc Expert
            VMware Employees
            WhiteKnight wrote:

            When logging off or shutting down the host OS (Windows), VMware Workstation should automatically suspend all running VMs (incl. VMs running in the background) immediately.

             

            We have actually tried that ... Windows (Vista and later, I believe) has this "feature" where if an app does not succeed in shutting down in some short time interval, it simply kills the app.  Suffice it to say that suspending a guest is expensive enough that we really cannot fit in the time interval, we get killed halfway through suspend and end up in the worst of all worlds.

             

            Currently on Windows 7 Workstation just hangs when a user is logging off at the host OS. At the same time VMs running in the background are simply abruptly shut off. Even though NTFS is a transactional file system, simply cutting off power is something that's never to be regarded a good idea.

             

            Background VMs are killed because they run in the user's session (and not in the system service session).  We do this because we want to run the VMs with the user's reduced privileges, instead of system privileges (like, um, attaching to other user's .vmdk files).

             

            Nonetheless, it's a possibility.  Noted.

            • 3. Re: Improvement Suggestion: Suspend VMs Automatically On Host Log-off/Shut-down
              WhiteKnight Hot Shot

              Thanks for replying!

              And sorry for my late reply. I just couldn't remember the appropriate Windows system message for the problem you've had described anymore...

               

              But now I remember it: . It's WM_QUERYENDSESSION.

               

              -


               

              So I'd like to suggest the following workflow to use when the user tries to end his current session (either by logging off or shutting down):

               

              If VMware Workstation receives a WM_QUERYENDSESSION message while any VM is running,

                1. Workstation displays a message box requiring the user to confirm session end.
                  (Further steps described imply that user confirms session end ...)

                  .

                2. Workstation returns zero in order to stop standard user session end process.
                  .

                3. Workstation sends a WM_QUERYENDSESSION message to all other running applications to find out if other applications don't want the user session to end.
                  .

                4. If no other application keeps the session from ending, VMware Workstation suspends all running VMs.
                  .

                5. Workstation initiates an End Session itself using either of the two following commands (or any similar, appropriate means).

               

              -


               

              Ending a session can either be performed by using

              RunDll32.EXE User,ExitWindows

               

              or (starting with Vista)

              C:\WINDOWS\system32\shutdown.exe -r -t 0

               

               

              The WM_QUERYENDSESSION message parameters tell Workstation which options to use with these commands.

               

              .

              What do you think?

              • 4. Re: Improvement Suggestion: Suspend VMs Automatically On Host Log-off/Shut-down
                ksc Expert
                VMware Employees
                WhiteKnight wrote:

                Thanks for replying!

                And sorry for my late reply. I just couldn't remember the appropriate Windows system message for the problem you've had described anymore...

                 

                But now I remember it: . It's WM_QUERYENDSESSION.

                 

                It has been investigated.  The virtual machine's binary ... doesn't actually have an HWND to receive window messages, nor does it have a classic Win32 message loop.  We can (and do) receive thread messages, but not window messages.  That binary is more of a console app than a Win32 UI app.

                 

                One of the nastier corner cases is, what happens if there is a failure suspending the VM?  Do we decide the user really wanted to log off and forcibly kill the VM, or do we veto the log-off and go back to the user for input (which, if you are using a laptop, means closing the lid leaves the VM running and kills the battery)?  What if the VM process crashes during this - who initiates the log-off then?  What if the VM is busy doing something expensive (like disk consolidation) and cannot suspend?  Getting involved in the log-off path is, realistically, just a mess of bugs.

                 

                Now, the UI window can receive window messages, but that goes directly into a privilege problem.  The UI doesn't run with Administrator rights - so the UI isn't really able to initiate that shutdown.  (Yes, we could get around around it, but any workarounds start getting messy with synchronization / privilege escalation worries and in the long run the behavior is just a mess).

                • 5. Re: Improvement Suggestion: Suspend VMs Automatically On Host Log-off/Shut-down
                  WhiteKnight Hot Shot

                  I see.. Yeah, that's making things hard. But not insurmountable...

                   

                  .

                  For the failure cases you've mentioned:

                   

                  • You might want to leave the decision whether to continue or stop shut-down at failure to the customer by providing an option in the VM settings dialog. The error should be logged into the Windows Application event log (or a dedicated Workstation event log).

                   

                  • If the user has chosen to continue log-off/shut down, then when re-starting Workstation, a message box should inform the user that an error occured and point him to the event log for details.

                   

                  .

                  Suggestion:

                   

                  • Have Workstation run as a service instead of a program. Running Workstation as a service you'd get all the control you need and you'd get the same environment you have right now.

                   

                  • I've seen Hyper-V putting its VMs to sleep gracefully while shutting down, taking all the time it needs. That's because it's running as a service.

                   

                  • The Workstation Console program could connect to the VMs as easy if Workstation itself were run as a service. (Workstation: Service; Console window: program)

                   

                  • Each VM would run in a separate process, impersonating the current user (or run as the SERVICE user). VMs impersonating users would only be manageable by the corresponding user, VMs running under the SERVICE account would be manageable by members of some Active Directory "VMWare Virtual Machine Manager" group.

                   

                  • Running Workstation as a service would even get rid of the question what should happen when the user closes the Workstation Console window. The VMs would just continue to run. The System Tray icon would be sufficient to stop a VM and to launch a new Workstation Console window to manage a VM. There might also be an option added to automatically restart VMs being automatically suspended at shut down/log-off.

                   

                  • If Workstation VMs would run in the context of a service, why suspending VMs at log-off at all? They could continue to run in the background until shut down of the host, being visible/manageable only to the corresponding user or a member of the above mentioned "VMWare Virtual Machine Manager" Active Directory group