From nobody Sat Nov 23 06:58:31 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1681919066; cv=none; d=zohomail.com; s=zohoarc; b=YHiEDDZXJEfYz6B+0w3DFobDnJLgU62UweQDbLJIYGNDAic4Y0yTx1rlLNmr99+Kq82FhkXnyCGosfWYWjExb6hqyHEJNaMclvRLEIDrS5atPbCqRSM3XT5U2Kv5hVB9fct9vmesMGtV2SGAC8bSy48L7lpjc6K/pYr354Fbyxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681919066; 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=RutNdIsdj8Hc3xurJdIKpmQd07jyhe4iJpBwroHgBNk=; b=N7pRvdWWr5n1TxENacOO5g/3Db7D0mu7Y3JNDJBT0ID4qaHe2DMPG7f3sKvJyRjACW5tvb13NApNOFBZwm83Ss/y9FBFZ4AnniTYm/xm3iZLEknsAt97uFtmpNRz/puiRk83QOep+T2GmnAe7PCkF2A22H9feDepULEhUQJ11BU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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 [170.10.129.124]) by mx.zohomail.com with SMTPS id 168191906668127.150640554326515; Wed, 19 Apr 2023 08:44:26 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-247-Z72LDRFOPvGD6Wou5EUc0w-1; Wed, 19 Apr 2023 11:44:19 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 911588996F3; Wed, 19 Apr 2023 15:44:16 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D8A85AB7A; Wed, 19 Apr 2023 15:44:16 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 39E0E19465BC; Wed, 19 Apr 2023 15:44:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id C694B19465A0 for ; Wed, 19 Apr 2023 15:44:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 9CE9F40C201F; Wed, 19 Apr 2023 15:44:07 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23FF040C2064 for ; Wed, 19 Apr 2023 15:44:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681919065; 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=RutNdIsdj8Hc3xurJdIKpmQd07jyhe4iJpBwroHgBNk=; b=iasE7xzgfm0Cjg5aAea0Y6mwhclvon3GUV+nwBIHePbGJujVmhMRbsO3enMAInxDOogIwV 7oVL1aO9L0mfHrQ/F1xZL/ePKIQeNvYZSWHwH219KbDUtUxivLgYolxqK6b1yBv/QMWGng MOQhueIQFfcHt9MI8Bn5LFx4qc+moKI= X-MC-Unique: Z72LDRFOPvGD6Wou5EUc0w-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/3] qemuProcessRefreshDisks: Properly compare tray status Date: Wed, 19 Apr 2023 17:44:03 +0200 Message-Id: <05f2849f60391bf207de473649deb6ce2f9ac85a.1681919007.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: 1681919067719100001 Content-Type: text/plain; charset="utf-8" The code compares the 'tray_open' boolean from 'struct qemuDomainDiskInfo' directly against 'disk->tray_status' which is declared as virDomainDiskTray (enum). Now the logic works correctly because the _OPEN enum has value '1'. Separate the event emission code from the update code and remember the old tray state in a separate variable rather than having the sneaky logic we have today. Signed-off-by: Peter Krempa --- src/qemu/qemu_process.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index b9e9a7d320..0dc49b87d8 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8695,6 +8695,7 @@ qemuProcessRefreshDisks(virDomainObj *vm, qemuDomainDiskPrivate *diskpriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); struct qemuDomainDiskInfo *info; const char *entryname =3D disk->info.alias; + virDomainDiskTray old_tray_status =3D disk->tray_status; if (diskpriv->qomName) entryname =3D diskpriv->qomName; @@ -8703,31 +8704,32 @@ qemuProcessRefreshDisks(virDomainObj *vm, continue; if (info->removable) { - bool emitEvent =3D info->tray_open !=3D disk->tray_status; - int reason; - if (info->empty) virDomainDiskEmptySource(disk); if (info->tray) { - if (info->tray_open) { - reason =3D VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN; + if (info->tray_open) disk->tray_status =3D VIR_DOMAIN_DISK_TRAY_OPEN; - } else { - reason =3D VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE; + else disk->tray_status =3D VIR_DOMAIN_DISK_TRAY_CLOSED; - } - - if (emitEvent) { - virObjectEvent *event =3D virDomainEventTrayChangeNewF= romObj(vm, disk->info.alias, reason); - virObjectEventStateQueue(driver->domainEventState, eve= nt); - } } } /* fill in additional data */ diskpriv->removable =3D info->removable; diskpriv->tray =3D info->tray; + + if (diskpriv->tray && + old_tray_status !=3D disk->tray_status) { + virDomainEventTrayChangeReason reason =3D VIR_DOMAIN_EVENT_TRA= Y_CHANGE_OPEN; + virObjectEvent *event; + + if (disk->tray_status =3D=3D VIR_DOMAIN_DISK_TRAY_CLOSED) + reason =3D VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE; + + event =3D virDomainEventTrayChangeNewFromObj(vm, disk->info.al= ias, reason); + virObjectEventStateQueue(driver->domainEventState, event); + } } return 0; --=20 2.39.2