From nobody Fri Dec 19 21:50:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1629816340; cv=none; d=zohomail.com; s=zohoarc; b=KUbiphRGqZru5G5nQKnbdcJFKmrVWdxSvEhIQi46EA/JSiFfQP5BSzd9TewyOtz6NqNNotyvUpXQCnTxLsD/W0DwxSkd6nDoBp4GntJsm7lrIblVS6Rvd4G79hsUnzBHVTHn9Txl+Z5erUp9kocp0W8UUbco28hFAAhds82YP5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629816340; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ssaqTO+bfKi9IItJqTOJa1v5LoqzJkOxDUnHdTM5/Xc=; b=dB3Sbg3HQYUn9gWOh1x9K5sKN6UFvWBS9m/wA9pO2B9G+4+KIRSYakMMlLOwFtDV3IozE3VzE9hTx7MhkEdxjIE5FrlAqmooTwsHOEfKHMs0HGqQq5JH99IY1hLFT0bsfHxGmUDzK2cTybGyJTlbDWNVg2IRpA7gMVXXnAVXqmw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1629816340808616.3146578996591; Tue, 24 Aug 2021 07:45:40 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-307-Sc2GsLhvMnmFQr7nOISTQg-1; Tue, 24 Aug 2021 10:45:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8EE6087D563; Tue, 24 Aug 2021 14:45:32 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6F41E60C0F; Tue, 24 Aug 2021 14:45:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3BBC9181A2AA; Tue, 24 Aug 2021 14:45:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 17OEjTsx005683 for ; Tue, 24 Aug 2021 10:45:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id E5BE61ABD7; Tue, 24 Aug 2021 14:45:29 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 427DB17D4E for ; Tue, 24 Aug 2021 14:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629816339; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ssaqTO+bfKi9IItJqTOJa1v5LoqzJkOxDUnHdTM5/Xc=; b=b29kJYauj+EPj0npNpB54MHfYrAo8ncj2uarQnCYCbw2qGRdwdp+Mu0Inddqg7ROmtW9hL +iNmGeI/jOiA/6sV+8RhCw9KPUEqwkHVw7qIgkef2IxiQKKuOExLlIhsd756g1ZucZFFm1 qIzq8mwvtS/9fr3XuOxATmxARmIwq+g= X-MC-Unique: Sc2GsLhvMnmFQr7nOISTQg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 10/22] qemu: monitor: Implement monitor code for 'set-action' command Date: Tue, 24 Aug 2021 16:44:31 +0200 Message-Id: <145ae9b53d815024c28ffd2e767cf862590e645f.1629816141.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1629816341406100004 Content-Type: text/plain; charset="utf-8" Signed-off-by: Peter Krempa --- src/qemu/qemu_monitor.c | 16 ++++++++ src/qemu/qemu_monitor.h | 49 ++++++++++++++++++++++ src/qemu/qemu_monitor_json.c | 79 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 7 ++++ tests/qemumonitorjsontest.c | 6 +++ 5 files changed, 157 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 14fb605e92..42846349c4 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4609,3 +4609,19 @@ qemuMonitorQueryDirtyRate(qemuMonitor *mon, return qemuMonitorJSONQueryDirtyRate(mon, info); } + + +int +qemuMonitorSetAction(qemuMonitor *mon, + qemuMonitorActionShutdown shutdown, + qemuMonitorActionReboot reboot, + qemuMonitorActionWatchdog watchdog, + qemuMonitorActionPanic panic) +{ + VIR_DEBUG("shutdown=3D%u, reboot=3D%u, watchdog=3D%u panic=3D%u", + shutdown, reboot, watchdog, panic); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONSetAction(mon, shutdown, reboot, watchdog, panic= ); +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 8af271dc96..2f08357c0c 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -101,6 +101,48 @@ struct _qemuMonitorRdmaGidStatus { }; +typedef enum { + QEMU_MONITOR_ACTION_SHUTDOWN_KEEP, /* do not change the current settin= g */ + QEMU_MONITOR_ACTION_SHUTDOWN_POWEROFF, + QEMU_MONITOR_ACTION_SHUTDOWN_PAUSE, + + QEMU_MONITOR_ACTION_SHUTDOWN_LAST +} qemuMonitorActionShutdown; + + +typedef enum { + QEMU_MONITOR_ACTION_REBOOT_KEEP, /* do not change the current setting = */ + QEMU_MONITOR_ACTION_REBOOT_RESET, + QEMU_MONITOR_ACTION_REBOOT_SHUTDOWN, + + QEMU_MONITOR_ACTION_REBOOT_LAST +} qemuMonitorActionReboot; + + +typedef enum { + QEMU_MONITOR_ACTION_WATCHDOG_KEEP, /* do not change the current settin= g */ + QEMU_MONITOR_ACTION_WATCHDOG_RESET, + QEMU_MONITOR_ACTION_WATCHDOG_SHUTDOWN, + QEMU_MONITOR_ACTION_WATCHDOG_POWEROFF, + QEMU_MONITOR_ACTION_WATCHDOG_PAUSE, + QEMU_MONITOR_ACTION_WATCHDOG_DEBUG, + QEMU_MONITOR_ACTION_WATCHDOG_NONE, + QEMU_MONITOR_ACTION_WATCHDOG_INJECT_NMI, + + QEMU_MONITOR_ACTION_WATCHDOG_LAST +} qemuMonitorActionWatchdog; + + +typedef enum { + QEMU_MONITOR_ACTION_PANIC_KEEP, /* do not change the current setting */ + QEMU_MONITOR_ACTION_PANIC_PAUSE, + QEMU_MONITOR_ACTION_PANIC_SHUTDOWN, + QEMU_MONITOR_ACTION_PANIC_NONE, + + QEMU_MONITOR_ACTION_PANIC_LAST +} qemuMonitorActionPanic; + + typedef enum { QEMU_MONITOR_JOB_TYPE_UNKNOWN, /* internal value, not exposed by qemu = */ QEMU_MONITOR_JOB_TYPE_COMMIT, @@ -1488,3 +1530,10 @@ struct _qemuMonitorDirtyRateInfo { int qemuMonitorQueryDirtyRate(qemuMonitor *mon, qemuMonitorDirtyRateInfo *info); + +int +qemuMonitorSetAction(qemuMonitor *mon, + qemuMonitorActionShutdown shutdown, + qemuMonitorActionReboot reboot, + qemuMonitorActionWatchdog watchdog, + qemuMonitorActionPanic panic); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 8fb2bf4dc3..8d3c4031a6 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -9325,3 +9325,82 @@ qemuMonitorJSONQueryDirtyRate(qemuMonitor *mon, return qemuMonitorJSONExtractDirtyRateInfo(data, info); } + + +VIR_ENUM_DECL(qemuMonitorActionShutdown); +VIR_ENUM_IMPL(qemuMonitorActionShutdown, + QEMU_MONITOR_ACTION_SHUTDOWN_LAST, + "", + "poweroff", + "pause"); + +VIR_ENUM_DECL(qemuMonitorActionReboot); +VIR_ENUM_IMPL(qemuMonitorActionReboot, + QEMU_MONITOR_ACTION_REBOOT_LAST, + "", + "reset", + "shutdown"); + +VIR_ENUM_DECL(qemuMonitorActionWatchdog); +VIR_ENUM_IMPL(qemuMonitorActionWatchdog, + QEMU_MONITOR_ACTION_WATCHDOG_LAST, + "", + "reset", + "shutdown", + "poweroff", + "pause", + "debug", + "none", + "inject-nmi"); + +VIR_ENUM_DECL(qemuMonitorActionPanic); +VIR_ENUM_IMPL(qemuMonitorActionPanic, + QEMU_MONITOR_ACTION_PANIC_LAST, + "", + "pause", + "shutdown", + "none"); + + +int +qemuMonitorJSONSetAction(qemuMonitor *mon, + qemuMonitorActionShutdown shutdown, + qemuMonitorActionReboot reboot, + qemuMonitorActionWatchdog watchdog, + qemuMonitorActionPanic panic) +{ + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; + const char *actionShutdown =3D NULL; + const char *actionReboot =3D NULL; + const char *actionWatchdog =3D NULL; + const char *actionPanic =3D NULL; + + if (shutdown !=3D QEMU_MONITOR_ACTION_SHUTDOWN_KEEP) + actionShutdown =3D qemuMonitorActionShutdownTypeToString(shutdown); + + if (reboot !=3D QEMU_MONITOR_ACTION_REBOOT_KEEP) + actionReboot =3D qemuMonitorActionRebootTypeToString(reboot); + + if (watchdog !=3D QEMU_MONITOR_ACTION_WATCHDOG_KEEP) + actionWatchdog =3D qemuMonitorActionWatchdogTypeToString(watchdog); + + if (panic !=3D QEMU_MONITOR_ACTION_PANIC_KEEP) + actionPanic =3D qemuMonitorActionPanicTypeToString(panic); + + if (!(cmd =3D qemuMonitorJSONMakeCommand("set-action", + "S:shutdown", actionShutdown, + "S:reboot", actionReboot, + "S:watchdog", actionWatchdog, + "S:panic", actionPanic, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return -1; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + return -1; + + return 0; +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index fbeab2bf6d..c8cf734a1c 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -703,3 +703,10 @@ qemuMonitorJSONStartDirtyRateCalc(qemuMonitor *mon, int qemuMonitorJSONQueryDirtyRate(qemuMonitor *mon, qemuMonitorDirtyRateInfo *info); + +int +qemuMonitorJSONSetAction(qemuMonitor *mon, + qemuMonitorActionShutdown shutdown, + qemuMonitorActionReboot reboot, + qemuMonitorActionWatchdog watchdog, + qemuMonitorActionPanic panic); diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 6d7ecb0ab1..9ec5f06981 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1204,6 +1204,11 @@ GEN_TEST_FUNC(qemuMonitorJSONBitmapRemove, "foodev",= "newnode") GEN_TEST_FUNC(qemuMonitorJSONJobDismiss, "jobname") GEN_TEST_FUNC(qemuMonitorJSONJobComplete, "jobname") GEN_TEST_FUNC(qemuMonitorJSONBlockJobCancel, "jobname", true) +GEN_TEST_FUNC(qemuMonitorJSONSetAction, + QEMU_MONITOR_ACTION_SHUTDOWN_PAUSE, + QEMU_MONITOR_ACTION_REBOOT_RESET, + QEMU_MONITOR_ACTION_WATCHDOG_SHUTDOWN, + QEMU_MONITOR_ACTION_PANIC_SHUTDOWN) static int testQemuMonitorJSONqemuMonitorJSONNBDServerStart(const void *opaque) @@ -3067,6 +3072,7 @@ mymain(void) DO_TEST_GEN(qemuMonitorJSONJobDismiss); DO_TEST_GEN(qemuMonitorJSONJobComplete); DO_TEST_GEN(qemuMonitorJSONBlockJobCancel); + DO_TEST_GEN(qemuMonitorJSONSetAction); DO_TEST(qemuMonitorJSONGetBalloonInfo); DO_TEST(qemuMonitorJSONGetBlockInfo); DO_TEST(qemuMonitorJSONGetAllBlockStatsInfo); --=20 2.31.1