Bug 242684

Summary: sysutils/vm-bhyve: service vm stop
Product: Ports & Packages Reporter: Bernhard Berger <bernhard>
Component: Individual Port(s)Assignee: freebsd-ports-bugs (Nobody) <ports-bugs>
Status: Open ---    
Severity: Affects Only Me CC: 0mp, churchers, kwiat3k, sascha.folie
Priority: --- Flags: bugzilla: maintainer-feedback? (churchers)
Version: Latest   
Hardware: amd64   
OS: Any   

Description Bernhard Berger 2019-12-17 11:55:18 UTC
I found a problem with VM-BHYVE.

VM-BHYVE provides a service vm which starts /stop the VM's on system startup and on system stop. 

The problem is with shutdown of the host system. The script in /usr/local/etc/rc.d/vm uses "vm stopall" to terminate the VM's. 
vm stopall sends the VM's the signal to shut down the system. if "vm stopall" is done, the script "/usr/local/etc/rc.d/vm" is done, too, so that the shutdown process of the host is continued and this is the problem, because "vm stopall" does not wait until the VM's are really finished and the shutdown processes of the host are continued, the VM's which are not finished with the schutdown will be aborted. This leads to broken file systems in the VM's -> fatal

they can easily verify that. Start a VM in a shell a: vm -f start test and now stop the VM: vm stop test in another shell b and you will see that the command in shell b is finished faster and the VM in shell a is still in the shutdown process.  

My suggestion:
In the script:
in the function core::stopall() or core::stop()

to add a check function that waits with the continuation until the VM's are actually finished. so the task: bhyve <vm-name> has disappeared.

This way you can make sure that when the host system is stopped, all VM's are really stopped.
Comment 1 Mateusz Piotrowski freebsd_committer 2019-12-17 13:24:12 UTC
(In reply to Bernhard Berger from comment #0)
Thanks for the report!

I guess this could be discussed upstream so that a fix for this problem could be included in the next release of vm-bhyve: https://github.com/churchers/vm-bhyve

Comment 2 Bernhard Berger 2020-01-05 08:17:41 UTC
This information might be helpful to know!
I found out that when using "reboot" the function "stop" in the service vm is not executed because reboot obviously does not execute the script /etc/rc.shutdown (see ticket 243094)