Skip to content

Commit 66ec4a7

Browse files
committed
xenmgr: Push ACPI power button multiple times
Sometimes the shutdown command does not work. It seems like the longer the VM is up, the more likely it is to not shutdown. This is based on Windows 10 without PV drivers. The button press is seen by the VM to some extent because a DPMS off (black) screen will turn back on, but shutdown is not initiated. A second press will trigger it - that was the intent to the xl trigger power line added in commit 1cfb6aa "xenmgr: Add xl trigger power to HVM shutdown". Re-work the code so a background thread is started that will push the power buttons* 3 times each with a 1 second delay. This will hopefully let the VM recognize the button press without going on for too long. *HVMs have two power and two sleep buttons. One is Xen emulating buttons for HVMs, and the second is from QEMU's acpi-pm-features.patch and ACPI changes. xl trigger power is pushing the Xen one and the xenstore hvm-shutdown write is triggering the QEMU one. With forkIO, the `xl shutdown -F -ww` runs before the `xl trigger power` commands. xl shutdown first tries PV shutdown and then (-F) fallback to ACPI. So this would push the Xen ACPI button before the QEMU one in pushPowerButton. Signed-off-by: Jason Andryuk <[email protected]>
1 parent 6419e6a commit 66ec4a7

File tree

1 file changed

+18
-3
lines changed
  • xenmgr/XenMgr/Connect

1 file changed

+18
-3
lines changed

xenmgr/XenMgr/Connect/Xl.hs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ domainXsPath uuid = do
158158
"" -> return $ "/local/domain/unknown"
159159
_ -> return $ "/local/domain/" ++ domid
160160

161+
pushPowerButton :: Uuid -> Int -> IO ()
162+
pushPowerButton uuid count = do
163+
domid <- getDomainId uuid
164+
stubdomid <- getStubDomainID uuid
165+
let xs_path = "/local/domain/" ++ stubdomid ++ "/device-model/" ++ domid
166+
_pushPowerButton uuid domid xs_path 1 count
167+
where
168+
_pushPowerButton :: Uuid -> String -> String -> Int -> Int -> IO ()
169+
_pushPowerButton uuid domid xs_path i max = do
170+
debug $ "push power button " ++ show uuid ++ " " ++ show i ++ " of " ++ show max
171+
xsWrite (xs_path ++ "/hvm-shutdown") "poweroff"
172+
system_ ("xl trigger " ++ domid ++ " power")
173+
if i < max
174+
then do threadDelay $ 10^6
175+
_pushPowerButton uuid domid xs_path ( i + 1 ) max
176+
else return ()
161177

162178
--The following functions are all domain lifecycle operations, and self-explanatory
163179

@@ -172,9 +188,8 @@ shutdown uuid =
172188
Just g -> do exitCode <- system ("xl shutdown -w " ++ domid)
173189
case exitCode of
174190
ExitSuccess -> return ()
175-
_ -> do xsWrite (xs_path ++ "/hvm-shutdown") "poweroff"
176-
_ <- system ("xl trigger " ++ domid ++ " power")
177-
_ <- system ("xl shutdown -F -w " ++ domid)
191+
_ -> do forkIO $ pushPowerButton uuid 3
192+
_ <- system_ ("xl shutdown -F -w " ++ domid)
178193
return ()
179194
Nothing -> do system ("xl shutdown -c -w " ++ domid)
180195
return ()

0 commit comments

Comments
 (0)