sys-apps/qemu-openrc: initial import

Signed-off-by: Aisha Tammy <gentoo@aisha.cc>
This commit is contained in:
Aisha Tammy
2022-05-15 15:52:52 +00:00
parent ab80a9cc27
commit 5c1c154ef9
5 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1 @@
DIST qemu-openrc-0.10.0.tar.gz 8367 BLAKE2B 34447e04c1a81fa13bddf2f4a742059beea6eeb0025ec32219ef3718a0ff62b98a3d0c39083068f52362eb6fe3eb105338febdd36ea696f144a6b2ce583b3441 SHA512 cdcf51dc59dbca96102c1b73032a726a44cb62c0c93a42adb9b6806609a0fa24bf8dde4814ed5010de63d54fde75f661bb9f5245d85e28de08cdba08d538c959

View File

@@ -0,0 +1,87 @@
From 6928925968faf8c8c07e6e955b6864e11f614f77 Mon Sep 17 00:00:00 2001
From: Aisha Tammy <floss@bsd.ac>
Date: Mon, 24 Jan 2022 13:50:37 +0000
Subject: [PATCH] allow shutdown via guest agent socket
This allows shutdown events to be sent
via qemu guest agent, which works for
BSD agents which don't handle ACPI events
correctly.
Tested with OpenBSD 7.0.
Signed-off-by: Aisha Tammy <floss@bsd.ac>
---
qemu.initd | 31 +++++++++++++++++++++++++++----
1 file changed, 27 insertions(+), 4 deletions(-)
diff --git a/qemu.initd b/qemu.initd
index a80d291..8756080 100644
--- a/qemu.initd
+++ b/qemu.initd
@@ -25,6 +25,7 @@ VM_NAME="${RC_SVCNAME#qemu.}"
: ${vnc_listen:=0.0.0.0}
: ${hugepages_path:=/dev/hugepages}
: ${monitor_socket:=/run/qemu/${VM_NAME}/monitor.sock}
+: ${guest_agent_socket:=/run/qemu/${VM_NAME}/ga.sock}
: ${extra_args:=}
name="VM $VM_NAME"
@@ -53,7 +54,9 @@ 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=$guest_agent_socket,server,nowait,id=qga0
+ -device isa-serial,chardev=qga0"
command_background='yes'
start_stop_daemon_args="
@@ -125,10 +128,22 @@ stop() {
ebegin "Stopping $name"
+ if is_running && qemush "${guest_agent_socket}" "{'execute': 'guest-exec', 'arguments': {'path': '/sbin/halt', 'arg': ['-p']}}"; then
+ count="$shutdown_timeout"
+
+ printf " Waiting $count seconds for VM shutdown via guest agent "
+ while is_running && [ $count -gt 0 ]; do
+ sleep 1
+ printf '.'
+ count=$(( count - 1 ))
+ done
+ printf '\n'
+ fi
+
if is_running && qemush 'system_powerdown'; then
count="$shutdown_timeout"
- printf " Waiting $count seconds for VM shutdown "
+ printf " Waiting $count seconds for VM shutdown via ACPI"
while is_running && [ $count -gt 0 ]; do
sleep 1
printf '.'
@@ -281,12 +296,20 @@ check_bridge() {
qemush() {
local IFS=$'\n'
- printf "%b\n" "$*" | socat - "UNIX-CONNECT:${monitor_socket}" 1>/dev/null
+ socket_path="${monitor_socket}"
+ case "$1" in
+ /*) socket_path="$1"; shift;
+ esac
+ printf "%b\n" "$*" | socat - "UNIX-CONNECT:${socket_path}" 1>/dev/null
}
qemush_show() {
local IFS=$'\n'
- printf "%b\n" "$*" | socat - "UNIX-CONNECT:${monitor_socket}" | tail -n +3 | head -n -1
+ socket_path="${monitor_socket}"
+ case "$1" in
+ /*) socket_path="$1"; shift;
+ esac
+ printf "%b\n" "$*" | socat - "UNIX-CONNECT:${socket_path}" | tail -n +3 | head -n -1
}
gen_macaddr() {

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<maintainer type="person">
<email>gentoo@aisha.cc</email>
<name>Aisha Tammy</name>
</maintainer>
</pkgmetadata>

View File

@@ -0,0 +1,32 @@
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
DESCRIPTION="OpenRC init script for QEMU/KVM"
HOMEPAGE="https://github.com/jirutka/qemu-openrc"
if [[ ${PV} == 9999 ]]; then
inherit git-r3
EGIT_REPO_URI="https://github.com/jirutka/qemu-openrc"
else
SRC_URI="https://github.com/jirutka/qemu-openrc/archive/v${PV}.tar.gz -> ${P}.tar.gz"
KEYWORDS="~amd64"
fi
LICENSE="MIT"
SLOT="0"
RDEPEND="net-misc/socat"
PATCHES=( "${FILESDIR}/qemu-openrc-0.10.0-guest-agent.patch")
src_compile() {
:
}
src_install() {
newinitd qemu.initd qemu
newconfd qemu.confd qemu
dobin qemush
}

View File

@@ -0,0 +1,32 @@
# Copyright 2022 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=8
DESCRIPTION="OpenRC init script for QEMU/KVM"
HOMEPAGE="https://github.com/jirutka/qemu-openrc"
if [[ ${PV} == 9999 ]]; then
inherit git-r3
EGIT_REPO_URI="https://github.com/jirutka/qemu-openrc"
else
SRC_URI="https://github.com/jirutka/qemu-openrc/archive/v${PV}.tar.gz -> ${P}.tar.gz"
KEYWORDS="~amd64"
fi
LICENSE="MIT"
SLOT="0"
RDEPEND="net-misc/socat"
PATCHES=( "${FILESDIR}/qemu-openrc-0.10.0-guest-agent.patch")
src_compile() {
:
}
src_install() {
newinitd qemu.initd qemu
newconfd qemu.confd qemu
dobin qemush
}