From nobody Tue Sep 9 03:20:47 2025 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; 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1749111275; cv=none; d=zohomail.com; s=zohoarc; b=FwalNPFyAksVsG+6xQiXGcSgh7CfF4OkdZYQhhBc5InB2MhwlZ+Ev8i2rV0ePTfe7d22O0IESDCUETYWRDZ+rKFkFAQu6DTyj8IB4//SDPRUk9+EujauKQycW/YUtsUedYQXQRZBJncC8T85xx5K1Po2iAw9BWtQOtx9PE/xqf8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1749111275; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=NikEUfKV4XmFxAmW+/khSrLLNeCXMXFJ2Pr2us0vgSI=; b=IBtRHcnFt8g/99I4aVIdKiVoXdEnUFeqhSGNHbnR30yAS6iPs6dHphxxgibxlPf3gUvlxIL3/rvEgLriY4R+YpIMsAKAi/z0oFbIQcv73VbrzXLuHrm8cEgs0yWSOLvUQ/hpFlSRnwqaUr221/toegcGcv7xF9novEig3NULImo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1749111275540274.9842077757494; Thu, 5 Jun 2025 01:14:35 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7E81611BF; Thu, 5 Jun 2025 04:14:34 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 598D114C1; Thu, 5 Jun 2025 04:11:24 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6739E11A8; Thu, 5 Jun 2025 04:11:18 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 A8C7E13A0 for ; Thu, 5 Jun 2025 04:11:01 -0400 (EDT) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-256-8A_p7kboPSyRVL6ZQbGZiQ-1; Thu, 05 Jun 2025 04:10:59 -0400 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1144018003FC for ; Thu, 5 Jun 2025 08:10:59 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.44.22.3]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 3D4E218003FC for ; Thu, 5 Jun 2025 08:10:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1749111061; h=from:from: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; bh=4P9OIWswAIrNNT9ah0xMlKx7cp2YAd1P0ZeHaVi+Coo=; b=O5tKupG4/E6Dv82k49GxHPzTCzpfRiaANCUjGj8tJB9j6S1/3YJFutAGOKYlYUoC7q65Tw NzN7hChjPQE+1bjUI+Rq/9YrE6Uk0Qwxs/wK70JX0+ibrrhpm2sNrYwF1MdXHiKHrSYxyj 6ZcgtP0FuekW59iKNFCBUiEFLLlk2Kw= X-MC-Unique: 8A_p7kboPSyRVL6ZQbGZiQ-1 X-Mimecast-MFC-AGG-ID: 8A_p7kboPSyRVL6ZQbGZiQ_1749111059 To: devel@lists.libvirt.org Subject: [PATCH 7/7] virsh: await: Introduce 'guest-agent-available' condition Date: Thu, 5 Jun 2025 10:10:47 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: s25JJTtczqOKSAZMZC-JQLumIA5FR36T-kJvYJfqZIw_1749111059 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: OZEHSVE2GOJY7CJRUNFI7D7SJBBJX4DN X-Message-ID-Hash: OZEHSVE2GOJY7CJRUNFI7D7SJBBJX4DN X-MailFrom: pkrempa@redhat.com 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; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header 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: From: Peter Krempa via Devel Reply-To: Peter Krempa X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1749111277365116600 Content-Type: text/plain; charset="utf-8" From: Peter Krempa The new condition allows waiting for the guest agent to show up, which usually means that the guest has booted enough to respond to external stimuli. Signed-off-by: Peter Krempa --- docs/manpages/virsh.rst | 5 +++++ tools/virsh-domain-event.c | 42 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index 1515f84063..0259c21065 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -3080,6 +3080,11 @@ Supported conditions: domain is or becomes inactive + *guest-agent-available* + + the guest agent inside the guest connects and becomes available for co= mmands + (usually means that the guest has booted) + If *--timeout* is specified, the command gives up waiting for the conditio= n to satisfy after *seconds* have elapsed. If SIGINT is delivered to virsh (usually via ``Ctrl-C``) the wait is given up immediately. In non-interact= ive diff --git a/tools/virsh-domain-event.c b/tools/virsh-domain-event.c index 2cd52933c7..de33ed9d74 100644 --- a/tools/virsh-domain-event.c +++ b/tools/virsh-domain-event.c @@ -24,6 +24,7 @@ #include "virenum.h" #include "virtime.h" #include "virtypedparam.h" +#include "virxml.h" /* * "event" command @@ -1109,6 +1110,20 @@ virshDomainEventAwaitCallbackLifecycle(virConnectPtr= conn G_GNUC_UNUSED, } +static void +virshDomainEventAwaitAgentLifecycle(virConnectPtr conn G_GNUC_UNUSED, + virDomainPtr dom G_GNUC_UNUSED, + int state G_GNUC_UNUSED, + int reason G_GNUC_UNUSED, + void *opaque G_GNUC_UNUSED) +{ + struct virshDomEventAwaitConditionData *data =3D opaque; + + if (data->cond->handler(data) < 1) + vshEventDone(data->ctl); +} + + struct virshDomainEventAwaitCallbackTuple { int event; virConnectDomainEventGenericCallback eventCB; @@ -1120,6 +1135,9 @@ static const struct virshDomainEventAwaitCallbackTupl= e callbacks[] =3D { .event =3D VIR_DOMAIN_EVENT_ID_LIFECYCLE, .eventCB =3D VIR_DOMAIN_EVENT_CALLBACK(virshDomainEventAwaitCallback= Lifecycle), }, + { .event =3D VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE, + .eventCB =3D VIR_DOMAIN_EVENT_CALLBACK(virshDomainEventAwaitAgentLif= ecycle), + }, }; @@ -1152,11 +1170,35 @@ virshDomainEventAwaitConditionDomainInactive(struct= virshDomEventAwaitConditionD } +static int +virshDomainEventAwaitConditionGuestAgentAvailable(struct virshDomEventAwai= tConditionData *data) +{ + g_autoptr(xmlDoc) xml =3D NULL; + g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autofree char *state =3D NULL; + + if (virshDomainGetXMLFromDom(data->ctl, data->dom, 0, &xml, &ctxt) < 0) + return -1; + + if ((state =3D virXPathString("string(//devices/channel/target[@name = =3D 'org.qemu.guest_agent.0']/@state)", + ctxt))) { + if (STREQ(state, "connected")) + return 0; + } + + return 1; +} + + static const struct virshDomainEventAwaitCondition conditions[] =3D { { .name =3D "domain-inactive", .event =3D VIR_DOMAIN_EVENT_ID_LIFECYCLE, .handler =3D virshDomainEventAwaitConditionDomainInactive, }, + { .name =3D "guest-agent-available", + .event =3D VIR_DOMAIN_EVENT_ID_AGENT_LIFECYCLE, + .handler =3D virshDomainEventAwaitConditionGuestAgentAvailable, + }, }; --=20 2.49.0