From nobody Wed Dec 4 19:08:40 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@intel.com; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=intel.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1716532634942939.511408723554; Thu, 23 May 2024 23:37:14 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C331A1B64; Fri, 24 May 2024 02:37:13 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id C78121C29; Fri, 24 May 2024 02:27:07 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3CB1B1ADD; Fri, 24 May 2024 02:26:53 -0400 (EDT) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 9EBBC19E6 for ; Fri, 24 May 2024 02:25:58 -0400 (EDT) Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 23:24:56 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2024 23:24:54 -0700 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716531959; x=1748067959; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yDu+nFa3UOeA3Xza1IF75dkhnt5X++iXKkXl3s36q5A=; b=cGNK77MBfX4khX+HVZACZzDxzOp3itXYXsJhv58DoVdYLxwayVEmmfZz Vz+bdEB52/aecRNmMUx846ZMYf6PFKMHvasx6Og316gf+nheM6mwsmMA2 FRqUHAkca6TnPnft/gscPY4LIDgDbucY+TSA9g7rkPcBQ9mMUFhGdJwuS x9OY/YOipckst4+mltXz3sVse9Z3O7xQ1mw0T+fgPyBlEKEDox5D4NwbL g6hungHlVH2l+85AMxgvDVUx9kSipQQXTitr8WlmZszpjrTwjRGHhA68J hQUGZ/6FrnNp1OS1TLKRFXP36wSa7SUrewFrqKr7FA+R3OShYLYx3xfWb g==; X-CSE-ConnectionGUID: FA30AUS4QnSMibNpnDbVZw== X-CSE-MsgGUID: YgH/SNSeT4CMQIlxf2sGlw== X-IronPort-AV: E=McAfee;i="6600,9927,11081"; a="13081283" X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="13081283" X-CSE-ConnectionGUID: /rABkUVeSEyOVabjKfXNRg== X-CSE-MsgGUID: z5y4UBM0SvWNOOXQGzWrYA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,184,1712646000"; d="scan'208";a="34034035" From: Zhenzhong Duan To: devel@lists.libvirt.org Subject: [PATCH rfcv4 10/13] qemu: Support reboot command in guest Date: Fri, 24 May 2024 14:21:25 +0800 Message-Id: <20240524062128.523820-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240524062128.523820-1-zhenzhong.duan@intel.com> References: <20240524062128.523820-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: AX73JCG7S4WTCUR6GFOSOY2S3ZRWSV2W X-Message-ID-Hash: AX73JCG7S4WTCUR6GFOSOY2S3ZRWSV2W X-MailFrom: zhenzhong.duan@intel.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: phrdina@redhat.com, pkrempa@redhat.com, jjongsma@redhat.com, jsuchane@redhat.com, chenyi.qiang@intel.com, isaku.yamahata@intel.com, xiaoyao.li@intel.com, chao.p.peng@intel.com, Zhenzhong Duan X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1716532635420100001 Content-Type: text/plain; charset="utf-8" We can reboot a TDX guest with 'virsh reboot' or 'virsh shutdown' if action for onPoweroff is 'restart'. But running reboot command in guest shell will always lead to shutdown. This behavior is not consistent with normal guest, fix it by checking shutdown reason and action configuration to trigger FakeReboot. Signed-off-by: Zhenzhong Duan Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_monitor.c | 18 +++++++++++++++++- src/qemu/qemu_monitor.h | 2 +- src/qemu/qemu_monitor_json.c | 6 +++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 34e2ccab97..7f7053054f 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1062,10 +1062,26 @@ qemuMonitorEmitEvent(qemuMonitor *mon, const char *= event, =20 =20 void -qemuMonitorEmitShutdown(qemuMonitor *mon, virTristateBool guest) +qemuMonitorEmitShutdown(qemuMonitor *mon, virTristateBool guest, + const char *reason) { + virDomainObj *vm =3D mon->vm; + VIR_DEBUG("mon=3D%p guest=3D%u", mon, guest); =20 + /* This isn't best place to set FakeReboot but we need to access + * mon->vm which is defined in this file. Reboot command in guest + * will trigger SHUTDOWN event for TDX guest, so we has to deal + * with it here. */ + if (vm->def->sec && + vm->def->sec->sectype =3D=3D VIR_DOMAIN_LAUNCH_SECURITY_TDX) { + if ((STREQ_NULLABLE(reason, "guest-shutdown") && + vm->def->onPoweroff =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_RESTAR= T) || + (STREQ_NULLABLE(reason, "guest-reset") && + vm->def->onReboot =3D=3D VIR_DOMAIN_LIFECYCLE_ACTION_RESTART)) + qemuDomainSetFakeReboot(vm, true); + } + QEMU_MONITOR_CALLBACK(mon, domainShutdown, mon->vm, guest); } =20 diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 6e81945201..226bd672ea 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -443,7 +443,7 @@ int qemuMonitorUpdateVideoVram64Size(qemuMonitor *mon, void qemuMonitorEmitEvent(qemuMonitor *mon, const char *event, long long seconds, unsigned int micros, const char *details); -void qemuMonitorEmitShutdown(qemuMonitor *mon, virTristateBool guest); +void qemuMonitorEmitShutdown(qemuMonitor *mon, virTristateBool guest, cons= t char *reason); void qemuMonitorEmitReset(qemuMonitor *mon); void qemuMonitorEmitStop(qemuMonitor *mon); void qemuMonitorEmitResume(qemuMonitor *mon); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index eb84a3d938..bcddabffa0 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -546,12 +546,16 @@ qemuMonitorJSONMakeCommand(const char *cmdname, static void qemuMonitorJSONHandleShutdown(qemuMonitor *mon, virJSONValue *= data) { bool guest =3D false; + const char *reason =3D NULL; virTristateBool guest_initiated =3D VIR_TRISTATE_BOOL_ABSENT; =20 if (data && virJSONValueObjectGetBoolean(data, "guest", &guest) =3D=3D= 0) guest_initiated =3D virTristateBoolFromBool(guest); =20 - qemuMonitorEmitShutdown(mon, guest_initiated); + if (data) + reason =3D virJSONValueObjectGetString(data, "reason"); + + qemuMonitorEmitShutdown(mon, guest_initiated, reason); } =20 static void qemuMonitorJSONHandleReset(qemuMonitor *mon, virJSONValue *dat= a G_GNUC_UNUSED) --=20 2.34.1