From 4be5f86cf32c61d8d8c005aa39593e435007f090 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Sun, 21 Jan 2024 22:41:00 +0100 Subject: [PATCH] kvm : support des sockets de monitoring --- qemu/bin/diskpath | 13 +++++++++++++ qemu/bin/sockpath | 13 +++++++++++++ qemu/launchers/kvm | 11 ++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/qemu/bin/diskpath b/qemu/bin/diskpath index 2fec25b..85a74aa 100755 --- a/qemu/bin/diskpath +++ b/qemu/bin/diskpath @@ -1,3 +1,16 @@ #!/bin/sh -e + +# Invoked on termination if the last command failed +error() { >&2 echo "$(basename "$0"): failed"; } + +# Trap errors +trap error EXIT + +# Assert that the QEMUSH_NAME variable is not null [ -n "$QEMUSH_NAME" ] + +# Release the trap +trap - EXIT + +# Print the actual string printf %s/%s.qcow2\\n ~/disks "$QEMUSH_NAME" diff --git a/qemu/bin/sockpath b/qemu/bin/sockpath index 4569b33..a840abe 100755 --- a/qemu/bin/sockpath +++ b/qemu/bin/sockpath @@ -1,3 +1,16 @@ #!/bin/sh -e + +# Invoked on termination if the last command failed +error() { >&2 echo "$(basename "$0"): failed"; } + +# Trap errors +trap error EXIT + +# Assert that the QEMUSH_NAME variable is not null [ -n "$QEMUSH_NAME" ] + +# Release the trap +trap - EXIT + +# Print the actual string printf %s/%s ~/sockets "$QEMUSH_NAME" diff --git a/qemu/launchers/kvm b/qemu/launchers/kvm index 6ea6984..141a008 100755 --- a/qemu/launchers/kvm +++ b/qemu/launchers/kvm @@ -1,8 +1,16 @@ #!/usr/bin/env python3 -from os import environ + +# Retrieve the name of the monitor socket +from subprocess import check_output +from subprocess import CalledProcessError +try: + socket = 'unix:%s,server,nowait' % (check_output(["sockpath"], text=True)) +except CalledProcessError as e: + exit(e.returncode) # Set number of vCPUs to use to the environment variable QEMUSH_NPROC or # half of total vCPUs installed if it fails +from os import environ try: nproc = environ['QEMUSH_NPROC'] except KeyError: @@ -23,6 +31,7 @@ from sys import argv command = [ 'qemu-system-x86_64', '-enable-kvm', '-daemonize', + '-monitor', socket, '-M', 'q35', '-cpu', 'host', '-smp', nproc, '-m', ram,