After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 673930 - Reboot doesn't work when guest in grub/syslinux
Reboot doesn't work when guest in grub/syslinux
Status: RESOLVED FIXED
Product: gnome-boxes
Classification: Applications
Component: general
unspecified
Other Linux
: Normal normal
: --
Assigned To: GNOME Boxes maintainer(s)
GNOME Boxes maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2012-04-11 18:03 UTC by Ray Strode [halfline]
Modified: 2016-03-31 13:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
libvirt-machine: Stop if guest ignores shutdown request (1.81 KB, patch)
2012-10-16 20:10 UTC, Zeeshan Ali
none Details | Review
libvirt-machine: Set status after stopping, not before (1023 bytes, patch)
2012-10-31 23:08 UTC, Zeeshan Ali
none Details | Review
libvirt-machine: Stop if guest ignores shutdown request (2.68 KB, patch)
2012-10-31 23:08 UTC, Zeeshan Ali
needs-work Details | Review
libvirt-machine: Stop if guest ignores shutdown request (2.29 KB, patch)
2012-11-01 21:41 UTC, Zeeshan Ali
none Details | Review
libvirt-machine: Stop if guest ignores shutdown request (2.93 KB, patch)
2012-11-02 14:26 UTC, Zeeshan Ali
none Details | Review
libvirt-machine: Set status after stopping, not before (1.09 KB, patch)
2012-11-02 14:34 UTC, Zeeshan Ali
none Details | Review
libvirt-machine: Set forced state from domain state change handler (2.13 KB, patch)
2012-11-06 09:21 UTC, Zeeshan Ali
committed Details | Review
notificationbar: Allow tweaking of timeout (2.69 KB, patch)
2012-11-06 09:21 UTC, Zeeshan Ali
committed Details | Review
notificationbar: Provide users with Gd.Notification instance (3.32 KB, patch)
2012-11-06 09:21 UTC, Zeeshan Ali
committed Details | Review
libvirt-machine: Stop if guest ignores shutdown request (3.52 KB, patch)
2012-11-06 09:23 UTC, Zeeshan Ali
committed Details | Review

Description Ray Strode [halfline] 2012-04-11 18:03:07 UTC
I recently tried to do an OS install that requires 768mb or ram, so the defaul 512 wasn't going to work.

I went into the System settings thing, slide the slider to 1gb and clicked the Restart button in the popup dialog thing.

At this point it didn't reboot, but just sat there.

I was able to get the os installed by using virsh, editing the xml manually and running virsh create.
Comment 1 Zeeshan Ali 2012-04-11 18:25:13 UTC
The ability to (cleanly) restart requires cooperation from the guest OS. Wonder if we should just restart forcibly (pull the plug out and back in) if clean restart fails. One thing to keep in mind is that there is no error when guest doesn't cooperate but I guess we can detect the failure by waiting for 'restarted' signal from the domain for a specific amount of seconds.
Comment 2 Zeeshan Ali 2012-04-11 18:26:50 UTC
(In reply to comment #0)
>
> I was able to get the os installed by using virsh, editing the xml manually and
> running virsh create.

Bug#672554
Comment 3 Ray Strode [halfline] 2012-04-11 18:56:35 UTC
in this case i was sitting at the grub screen, so i think forceful restart is the only way that could work?
Comment 4 Ray Strode [halfline] 2012-04-11 18:57:40 UTC
s/grub/syslinux/
Comment 5 Ray Strode [halfline] 2012-04-11 19:43:51 UTC
tangentially related libvirt bug I filed many moons ago: 

https://bugzilla.redhat.com/show_bug.cgi?id=560678
Comment 6 Christophe Fergeau 2012-09-11 11:33:45 UTC
Fwiw, memory setting can now be edited before VM creation, and it's also possible to fore VM restarts, so this bug is much easier to workaround now.
Comment 7 Zeeshan Ali 2012-10-16 20:10:49 UTC
Created attachment 226587 [details] [review]
libvirt-machine: Stop if guest ignores shutdown request

It is not guaranteed that guest will honor the ACPI shutdown (e.g GRUB).
Force shutdown the guest if VM fails to shutdown in 5 seconds.
Comment 8 Ray Strode [halfline] 2012-10-16 20:19:26 UTC
so in theory shutdown could be slower than 5 seconds.  Maybe it should slide down a little infobar thing asking the user what to do after 5 seconds have elapsed?

Still, attachment 226587 [details] [review] should handle the lion's share of cases alright i think.
Comment 9 Zeeshan Ali 2012-10-23 21:26:12 UTC
So whats the verdict on the attached patch?
Comment 10 Christophe Fergeau 2012-10-24 08:55:36 UTC
Forcing shutdown this way can cause data loss so we need to warn the user about what's going on and let him cancel the force shutdown
Comment 11 Zeeshan Ali 2012-10-24 18:13:41 UTC
(In reply to comment #10)
> Forcing shutdown this way can cause data loss so we need to warn the user about
> what's going on and let him cancel the force shutdown

I'm not so sure about that. Here we are only doing it because guest is not responding to ACPI event. AFAIK that means that its hung, has crashed or its in a state where force shutdown can't cause any harm (e.g at boot loader). In all these cases, user doesn't really have any choice but to force shutdown so cancelling would be just postponing the inevitable. 

Perhaps we should instead figure how long should we wait to be sure ACPI shutdown failed?
Comment 12 Ray Strode [halfline] 2012-10-24 20:58:47 UTC
I think teuf's point was some machines may have perfectly ordered shut down that takes 10 seconds to complete.  If we pull the cord for these guests at the 5 second mark, there may be data loss.

Are you saying there's some sort of feedback provided by the guest os that it got the shutdown request, that the host is privvy to? And the patch, just waits 5 seconds for the feedback, not 5 seconds for the machine to finish the shutdown?
Comment 13 Zeeshan Ali 2012-10-24 21:35:47 UTC
(In reply to comment #12)
> I think teuf's point was some machines may have perfectly ordered shut down
> that takes 10 seconds to complete.  If we pull the cord for these guests at the
> 5 second mark, there may be data loss.

I understood his point and don't exactly disagree with it. I was just wonder it might be better (in terms of user experience) to wait longer before doing force shutdown rather than giving users a choice that is most probably going to be a fake one.

> Are you saying there's some sort of feedback provided by the guest os that it
> got the shutdown request, that the host is privvy to?

No, if only that was true. :)
Comment 14 Christophe Fergeau 2012-10-25 08:30:42 UTC
Actually I was thinking of OSes not supporting ACPI, or ignoring ACPI shutdown requests (I think that's doable?), but it's true that shutdown taking too long will also trigger this. With win7 applying updates on shutdown, the time it takes to actually shutdown can be arbitrarily long.
Comment 15 Zeeshan Ali 2012-10-31 23:08:17 UTC
Created attachment 227763 [details] [review]
libvirt-machine: Set status after stopping, not before

Otherwise _FORCE_STOPPED state gets overridden by our domain state event
handlers.
Comment 16 Zeeshan Ali 2012-10-31 23:08:44 UTC
Created attachment 227764 [details] [review]
libvirt-machine: Stop if guest ignores shutdown request

v2: Ask user first.
Comment 17 Alexander Larsson 2012-11-01 16:34:14 UTC
Review of attachment 227763 [details] [review]:

I don't understand this. The domain state handlers do:
        domain.stopped.connect (() => {
            if (state == MachineState.FORCE_STOPPED)
                return; // State already set by us when machine is forced to shutdown

So, it should not be overridden, should it?

Also, this will make us set the state to STOPPED first, and then FORCE_STOPPED. Maybe
you can set some local state instead that we handle inside the domain.stopped handler to pick FORCE_STOPPED rather than STOPPED state.
Comment 18 Alexander Larsson 2012-11-01 16:38:35 UTC
Review of attachment 227764 [details] [review]:

::: src/libvirt-machine.vala
@@ +629,3 @@
+                                                    Gtk.ButtonsType.YES_NO,
+                                                    msg);
+                var response = dialog.run ();

I don't think we want to run the dialog synchronously here. mainloop recursion like that is a risky business.
Comment 19 Zeeshan Ali 2012-11-01 17:21:26 UTC
Review of attachment 227763 [details] [review]:

Yeah, it shouldn't. I misread the code..
Comment 20 Zeeshan Ali 2012-11-01 17:22:19 UTC
Review of attachment 227764 [details] [review]:

::: src/libvirt-machine.vala
@@ +629,3 @@
+                                                    Gtk.ButtonsType.YES_NO,
+                                                    msg);
+                var response = dialog.run ();

How should it be done then? run_in_thread?
Comment 21 Alexander Larsson 2012-11-01 17:46:23 UTC
Review of attachment 227764 [details] [review]:

::: src/libvirt-machine.vala
@@ +629,3 @@
+                                                    Gtk.ButtonsType.YES_NO,
+                                                    msg);
+                var response = dialog.run ();

Just show the dialog and connect to the response signal.
Comment 22 Ray Strode [halfline] 2012-11-01 17:54:16 UTC
So right now when I move the slider, it puts this little floating info bar that says:

Changes require restart of 'blah'.  Attempt restart? [Yes] [X]

(at least for this case) maybe instead of a dialog, the same little floating info bar should come down and say:

"Restart operation is taking longer than expected.  Force immediate restart? [Yes] [X]"

?
Comment 23 Zeeshan Ali 2012-11-01 20:39:02 UTC
(In reply to comment #22)
> So right now when I move the slider, it puts this little floating info bar that
> says:
> 
> Changes require restart of 'blah'.  Attempt restart? [Yes] [X]
> 
> (at least for this case) maybe instead of a dialog, the same little floating
> info bar should come down and say:
> 
> "Restart operation is taking longer than expected.  Force immediate restart?
> [Yes] [X]"
> 
> ?

Good thought, I think that would be more consistent. I'll think a bit more about it and provide another patch in either case.
Comment 24 Zeeshan Ali 2012-11-01 21:41:33 UTC
Created attachment 227842 [details] [review]
libvirt-machine: Stop if guest ignores shutdown request

This version uses notificationbar rather than dialog.
Comment 25 Alexander Larsson 2012-11-02 09:32:24 UTC
Review of attachment 227842 [details] [review]:

This makes more sense to me than the dialog.

::: src/libvirt-machine.vala
@@ +630,3 @@
+                shutdown_timeout = 0;
+
+                return false;

Does this timeout get a ref to "this". Its not clear from the code. If it doesn't we need to ensure that we also remove the timeout on finalize.
Comment 26 Zeeshan Ali 2012-11-02 14:26:28 UTC
Created attachment 227892 [details] [review]
libvirt-machine: Stop if guest ignores shutdown request

This version keeps shutdown timeout id in the object and removes timeout on deletion of machine.
Comment 27 Zeeshan Ali 2012-11-02 14:29:50 UTC
Comment on attachment 227763 [details] [review]
libvirt-machine: Set status after stopping, not before

Actually, this one is needed. Not because of the reason I mentioned but because the state change handler in the other patch gets called when you set the state. The handler try to start the domain and that fails because the domain state is in reality still running..

I'll update the commit log.
Comment 28 Zeeshan Ali 2012-11-02 14:34:15 UTC
Created attachment 227893 [details] [review]
libvirt-machine: Set status after stopping, not before

Setting the state property will synchronously trigger all notifies on it
and they'll have a wrong idea about the actual state of the machine if
state has not actually changed.
Comment 29 Alexander Larsson 2012-11-05 07:56:16 UTC
Review of attachment 227892 [details] [review]:

::: src/libvirt-machine.vala
@@ +637,3 @@
+                shutdown_timeout = 0;
+
+                return false;

One issue with using a notification here is that by default that will time out after 6 seconds, but you might want to wait longer to see if  it will reboot correctly, or you might miss the notification and not want it to reboot.

So, i think we need to add some flag to the notification code to make it not have a timeout, requiring the user to nack or ack. We also want to get some kind of reference to the notification so we can remove it if the VM actually shuts down.
Comment 30 Alexander Larsson 2012-11-05 07:59:10 UTC
Review of attachment 227893 [details] [review]:

::: src/libvirt-machine.vala
@@ +473,2 @@
             domain.stop (0);
+            state = MachineState.FORCE_STOPPED;

I don't like how this seems potentially racy wrt the event handler setting state to STOPPED first. I Realize this is a sync call, so that won't happen, but this still seems kinda risky when things change later on.

It seems more reasonable to *only* change the state when we get an event from libvirt saying its state is changed, rather than having two divergent states.

So, can you just set some local boolean that we requested a force shutdown, and then when we get the STOPPED event we set it to FORCE_STOPPED if that boolean was set.
Comment 31 Zeeshan Ali 2012-11-06 09:21:22 UTC
Created attachment 228220 [details] [review]
libvirt-machine: Set forced state from domain state change handler

We should set the state only from the handler of underlying domain's
state change to avoid any race-conditions.
Comment 32 Zeeshan Ali 2012-11-06 09:21:32 UTC
Created attachment 228221 [details] [review]
notificationbar: Allow tweaking of timeout

Currently we just assume that 6 seconds timeout is enough for everyone.
This patch makes it possible to set or even unset the timeout on the
notifications.
Comment 33 Zeeshan Ali 2012-11-06 09:21:39 UTC
Created attachment 228222 [details] [review]
notificationbar: Provide users with Gd.Notification instance

The notification displaying methods now returns the underlying
Gd.Notification instance so that users of this API can do things like
dismissing the displayed notification.
Comment 34 Zeeshan Ali 2012-11-06 09:23:05 UTC
Created attachment 228224 [details] [review]
libvirt-machine: Stop if guest ignores shutdown request

New in this version:

* "Force shutdown" notification does not timeout.
* "Force shutdown" notification is dismissed automatically if shutdown happens before user hits a button.
Comment 35 Alexander Larsson 2012-11-08 13:27:31 UTC
Looks all good to me!
Comment 36 Zeeshan Ali 2012-11-08 15:29:08 UTC
Attachment 228220 [details] pushed as b43ad37 - libvirt-machine: Set forced state from domain state change handler
Attachment 228221 [details] pushed as 496f477 - notificationbar: Allow tweaking of timeout
Attachment 228222 [details] pushed as c7f9207 - notificationbar: Provide users with Gd.Notification instance
Attachment 228224 [details] pushed as 581b43c - libvirt-machine: Stop if guest ignores shutdown request
Comment 37 Ray Strode [halfline] 2012-11-08 15:34:50 UTC
thanks for all the work on this, you really went the extra mile.