Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add guest-agent socket; make use of it to request guest shutdown along with ACPI request #26

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions qemu.confd
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@
# Path of the QEMU monitor socket for this VM.
#monitor_socket="/run/qemu/${VM_NAME}/monitor.sock"

# Path of the QEMU Guest Agent socket for this VM.
#qemu_ga_socket="/run/qemu/${VM_NAME}/qemu_ga.sock"

##
# Network interfaces
Expand Down
20 changes: 15 additions & 5 deletions qemu.initd
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ VM_NAME="${RC_SVCNAME#qemu.}"
: ${vnc_listen:=0.0.0.0}
: ${hugepages_path:=/dev/hugepages}
: ${monitor_socket:=/run/qemu/${VM_NAME}/monitor.sock}
: ${qemu_ga_socket:=/run/qemu/${VM_NAME}/qemu-ga.sock}
: ${extra_args:=}

name="VM $VM_NAME"
Expand Down Expand Up @@ -54,7 +55,10 @@ command_args="
-vga $vga
-device virtio-rng-pci
-device virtio-scsi-pci,id=scsi
-monitor unix:$monitor_socket,server,nowait"
-monitor unix:$monitor_socket,server,nowait
-chardev socket,path=$qemu_ga_socket,server,nowait,id=qga0
-device virtio-serial
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0"
command_background='yes'
command_user="$user"
command_group="$group"
Expand Down Expand Up @@ -102,7 +106,7 @@ start_pre() {
einfo "Command: $command $(printf '%s ' $command_args)"
fi

local path; for path in "$pidfile" "$monitor_socket" "$logfile"; do
local path; for path in "$pidfile" "$monitor_socket" "$qemu_ga_socket" "$logfile"; do
# checkpath doesn't create intermediate directories
mkdir -p "$(dirname "$path")"
checkpath -d -m 0750 -o $user:$group "$(dirname "$path")"
Expand All @@ -112,8 +116,8 @@ start_pre() {
}

start_post() {
ewaitfile 5 "$monitor_socket" || {
eerror 'Monitor socket has not been created!'; return 1
ewaitfile 5 "$monitor_socket" "$qemu_ga_socket" || {
eerror 'Monitor socket or guest agent socket have not been created!'; return 1
}
if [ -n "$vnc_password" ]; then
qemush "set_password vnc $vnc_password" || eerror 'Failed to set VNC password!'
Expand All @@ -126,7 +130,7 @@ stop() {

ebegin "Stopping $name"

if is_running && qemush 'system_powerdown'; then
if is_running && guestcmd '{"execute":"guest-shutdown"}' && qemush 'system_powerdown'; then
count="$shutdown_timeout"

printf " Waiting $count seconds for VM shutdown "
Expand All @@ -152,6 +156,7 @@ stop() {

stop_post() {
[ -S "$monitor_socket" ] && rm -f "$monitor_socket"
[ -S "$qemu_ga_socket" ] && rm -f "$qemu_ga_socket"
[ -f "$pidfile" ] && rm -f "$pidfile"
return 0
}
Expand Down Expand Up @@ -290,6 +295,11 @@ qemush_show() {
printf "%b\n" "$*" | socat - "UNIX-CONNECT:${monitor_socket}" | tail -n +3 | head -n -1
}

guestcmd() {
local IFS=$'\n'
printf "%b\n" "$*" | socat - "UNIX-CONNECT:${qemu_ga_socket}" 1>/dev/null
}

gen_macaddr() {
printf "$1" | md5sum | sed -E 's/^(..)(..)(..)(..).*$/52:54:\1:\2:\3:\4/'
}
Expand Down