From nobody Sat Nov 23 02:22:33 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 Reviewed-by: J=C3=A1n Tomko --- 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 From nobody Sat Nov 23 02:22:33 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=1681919056; cv=none; d=zohomail.com; s=zohoarc; b=YTR1tysWuHeRLK87vtfihdpUTZFReithjn5sIEmahcgZefb6y3NBODTuRGLfDllHJaHeQb71zKUyt5nm1B1NQlRJBNN4TuSezVpPMxkAZaRh75eyu/HnjFCZCMdKgJc5b5QdRwG8tbfKujvPOrcUfuUtFmaSSGkZX11nXuwU+ks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681919056; 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=oRJtRxooOBYnOoeaEouqYYfSCfkNVY6KYmTlceBDv7k=; b=StHkQVXAl39W0L/yBeM1xn7BBdJSaVEbIZWS7D/aAuDUdSdbtRELohklUBXZViBd/6R2+MSH6ADvhPvbSH0kRqqMQMzkc6BiTZ5sb2yUC94QSuBsWnG/wY05zju2Pha0scwyH2ojnifU7pwINxm3eJIdJXCpo4nmWnCXsjvA7bM= 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 1681919056667598.2949523868654; Wed, 19 Apr 2023 08:44:16 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-527-2SURwSpAN32zzknTlI6Qew-1; Wed, 19 Apr 2023 11:44:13 -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 752061C0E248; Wed, 19 Apr 2023 15:44:10 +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 5F2282958; Wed, 19 Apr 2023 15:44:10 +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 31CFB19465B1; Wed, 19 Apr 2023 15:44:10 +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 9181619465B2 for ; Wed, 19 Apr 2023 15:44:08 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 776CF40C2021; Wed, 19 Apr 2023 15:44:08 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA04040C2064 for ; Wed, 19 Apr 2023 15:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681919055; 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=oRJtRxooOBYnOoeaEouqYYfSCfkNVY6KYmTlceBDv7k=; b=R9nhnL/SxFww2H89CuHpXpCW3wxhqmX7PtC+xm0Y05ED9yBbyPc1FI44pqytM6zEslhlCk ID00wePRwkbTVVX16b7oa6Cwkmk54Vj/sYL25oh2P3kQru6lPtAtNM1+Hi1V+vGfdSu3ui HwWx8CsDijVCjsE6n77ouqo7aBEUndU= X-MC-Unique: 2SURwSpAN32zzknTlI6Qew-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/3] qemuProcessRefreshDisks: Extract update of a single disk Date: Wed, 19 Apr 2023 17:44:04 +0200 Message-Id: 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: 1681919057815100001 Content-Type: text/plain; charset="utf-8" Extract the logic to update one single disk (without emitting any events) so that it can be reused when updating the state after a disk hotplug. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_process.c | 39 ++++++++++++++++++++++++--------------- src/qemu/qemu_process.h | 3 +++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 0dc49b87d8..7e7178ecec 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -8673,6 +8673,29 @@ qemuProcessAutoDestroy(virDomainObj *dom, } +void +qemuProcessRefreshDiskProps(virDomainDiskDef *disk, + struct qemuDomainDiskInfo *info) +{ + qemuDomainDiskPrivate *diskpriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); + + if (info->removable) { + if (info->empty) + virDomainDiskEmptySource(disk); + + if (info->tray) { + if (info->tray_open) + disk->tray_status =3D VIR_DOMAIN_DISK_TRAY_OPEN; + else + disk->tray_status =3D VIR_DOMAIN_DISK_TRAY_CLOSED; + } + } + + diskpriv->removable =3D info->removable; + diskpriv->tray =3D info->tray; +} + + int qemuProcessRefreshDisks(virDomainObj *vm, virDomainAsyncJob asyncJob) @@ -8703,21 +8726,7 @@ qemuProcessRefreshDisks(virDomainObj *vm, if (!(info =3D virHashLookup(table, entryname))) continue; - if (info->removable) { - if (info->empty) - virDomainDiskEmptySource(disk); - - if (info->tray) { - if (info->tray_open) - disk->tray_status =3D VIR_DOMAIN_DISK_TRAY_OPEN; - else - disk->tray_status =3D VIR_DOMAIN_DISK_TRAY_CLOSED; - } - } - - /* fill in additional data */ - diskpriv->removable =3D info->removable; - diskpriv->tray =3D info->tray; + qemuProcessRefreshDiskProps(disk, info); if (diskpriv->tray && old_tray_status !=3D disk->tray_status) { diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index b171f0464c..f5c06c2915 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -235,3 +235,6 @@ bool qemuProcessRebootAllowed(const virDomainDef *def); void qemuProcessCleanupMigrationJob(virQEMUDriver *driver, virDomainObj *vm); + +void qemuProcessRefreshDiskProps(virDomainDiskDef *disk, + struct qemuDomainDiskInfo *info); --=20 2.39.2 From nobody Sat Nov 23 02:22:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1681919057; cv=none; d=zohomail.com; s=zohoarc; b=S1oI1JZNG0eMdWWG/N7jWlmkOIX3N2jaMxpaZjbk9oD0S8m1XVbIqF7u0TXPTvSSF3LvXRim+8PeMoh6VST55oKH+Vp08v5xiFoHdoKHwk3ce+DAAwSEaEc/O52yj2fIzirgZ6KQlbgu/raj5sszQgy2RJxXpvsa3iFwQ863AA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1681919057; 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=wn7WPXJeACphzK7HiVi+m04mg7o5ueGV+JxDV7wGgMY=; b=SHWfHnogXPCUTsVYLVIF0mcwJwoUlmULH5SJYQt0pbhN0iEIS3WEfMK4Wa3+Hmu5qu1SVur2CJA82PbuembdU6H7xYBOW6vQVXFKQPWuMPSibY9IaMJIH80hzDgg2x/w89CLlSnKcgS0vc2kjTRc81jTW5T1k2BIlGuLTARMDbE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1681919057671547.7887497952191; Wed, 19 Apr 2023 08:44:17 -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-636-gOph3kw8MrOore3k7xIEeQ-1; Wed, 19 Apr 2023 11:44:14 -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 2219E887405; Wed, 19 Apr 2023 15:44:11 +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 0EE772958; Wed, 19 Apr 2023 15:44:11 +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 E8DF919465B1; Wed, 19 Apr 2023 15:44:10 +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 5F6A619465A0 for ; Wed, 19 Apr 2023 15:44:09 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 45B0F40CF8EF; Wed, 19 Apr 2023 15:44:09 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id C25F040C2021 for ; Wed, 19 Apr 2023 15:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1681919056; 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=wn7WPXJeACphzK7HiVi+m04mg7o5ueGV+JxDV7wGgMY=; b=etnyVa9Gy3VO801VBZU9pl04ynlv2hBx1SQIM8g6ZHMxNcMPDLJuchsBxCS1vHM3ZTIZ42 Hz2YFd0mC1VKMlnvwAewTsOdh3OEYVGMGSuAgY5kt4cNaf4xvEHYFshHz0wcRco/qGY4qg nOQybKRRPtzK4iw8WVr6OSAWl+yMTBg= X-MC-Unique: gOph3kw8MrOore3k7xIEeQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/3] qemu: hotplug: Update disk private data after hotplug Date: Wed, 19 Apr 2023 17:44:05 +0200 Message-Id: <2413a7ea62caa49ca37d2f590b00744fcf043e8e.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: 1681919058876100003 Content-Type: text/plain; charset="utf-8" The disk private data contain information about the tray and removability of the disk. Until recently we didn't support hotplug of removable disks thus it wasn't a problem but now when you can hotplug a CDROM you would not be able to open its tray. Fix it by updating the hotplugged disk the same way we do at startup. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D2160435 Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_hotplug.c | 21 ++++++++++++++++----- tests/qemuhotplugtest.c | 40 +++++++++++++++++++++++++++------------- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3f45a48393..611fd97eb8 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -724,12 +724,23 @@ qemuDomainAttachDiskGeneric(virDomainObj *vm, * As there isn't anything sane to do if this fails, let's just return * success. */ - if (rc =3D=3D 0 && - qemuDiskConfigBlkdeviotuneEnabled(disk)) { + if (rc =3D=3D 0) { qemuDomainDiskPrivate *diskPriv =3D QEMU_DOMAIN_DISK_PRIVATE(disk); - if (qemuMonitorSetBlockIoThrottle(priv->mon, NULL, diskPriv->qomNa= me, - &disk->blkdeviotune) < 0) - VIR_WARN("failed to set blkdeviotune for '%s' of '%s'", disk->= dst, vm->def->name); + g_autoptr(GHashTable) blockinfo =3D NULL; + + if (qemuDiskConfigBlkdeviotuneEnabled(disk)) { + if (qemuMonitorSetBlockIoThrottle(priv->mon, NULL, diskPriv->q= omName, + &disk->blkdeviotune) < 0) + VIR_WARN("failed to set blkdeviotune for '%s' of '%s'", di= sk->dst, vm->def->name); + } + + if ((blockinfo =3D qemuMonitorGetBlockInfo(priv->mon))) { + struct qemuDomainDiskInfo *diskinfo; + + if ((diskinfo =3D virHashLookup(blockinfo, diskPriv->qomName))= ) { + qemuProcessRefreshDiskProps(disk, diskinfo); + } + } } qemuDomainObjExitMonitor(vm); diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c index 63a6833cfd..4a8a4c1538 100644 --- a/tests/qemuhotplugtest.c +++ b/tests/qemuhotplugtest.c @@ -709,6 +709,7 @@ mymain(void) #define QMP_OK "{\"return\": {}}" +#define QMP_EMPTY_ARRAY "{\"return\": []}" #define QMP_DEVICE_DELETED(dev) \ "{" \ @@ -747,7 +748,8 @@ mymain(void) DO_TEST_ATTACH("x86_64", "base-live", "disk-virtio", false, true, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("x86_64", "base-live", "disk-virtio", true, true, "device_del", QMP_OK); DO_TEST_DETACH("x86_64", "base-live", "disk-virtio", false, false, @@ -758,7 +760,8 @@ mymain(void) DO_TEST_ATTACH("x86_64", "base-live", "disk-usb", false, true, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("x86_64", "base-live", "disk-usb", true, true, "device_del", QMP_OK); DO_TEST_DETACH("x86_64", "base-live", "disk-usb", false, false, @@ -769,7 +772,8 @@ mymain(void) DO_TEST_ATTACH("x86_64", "base-live", "disk-scsi", false, true, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("x86_64", "base-live", "disk-scsi", true, true, "device_del", QMP_OK); DO_TEST_DETACH("x86_64", "base-live", "disk-scsi", false, false, @@ -785,7 +789,8 @@ mymain(void) "device_add", QMP_OK, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("x86_64", "base-with-scsi-controller-live", "disk-scsi-= 2", true, true, "device_del", QMP_OK); DO_TEST_DETACH("x86_64", "base-with-scsi-controller-live", "disk-scsi-= 2", false, false, @@ -797,7 +802,8 @@ mymain(void) "object-add", QMP_OK, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("x86_64", "base-live", "disk-scsi-multipath", true, tru= e, "device_del", QMP_OK); DO_TEST_DETACH("x86_64", "base-live", "disk-scsi-multipath", false, fa= lse, @@ -817,7 +823,8 @@ mymain(void) DO_TEST_ATTACH("s390x", "base-ccw-live", "ccw-virtio", false, true, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("s390x", "base-ccw-live", "ccw-virtio", false, false, "device_del", QMP_DEVICE_DELETED("virtio-disk4") QMP_OK, "blockdev-del", QMP_OK, @@ -826,7 +833,8 @@ mymain(void) DO_TEST_ATTACH("s390x", "base-ccw-live-with-ccw-virtio", "ccw-virtio-2= ", false, true, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("s390x", "base-ccw-live-with-ccw-virtio", "ccw-virtio-2= ", false, false, "device_del", QMP_DEVICE_DELETED("virtio-disk0") QMP_OK, @@ -836,7 +844,8 @@ mymain(void) DO_TEST_ATTACH("s390x", "base-ccw-live-with-ccw-virtio", "ccw-virtio-2= -explicit", false, true, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("s390x", "base-ccw-live-with-ccw-virtio", "ccw-virtio-2= -explicit", false, false, "device_del", QMP_DEVICE_DELETED("virtio-disk0") QMP_OK, @@ -847,7 +856,8 @@ mymain(void) DO_TEST_ATTACH("s390x", "base-ccw-live-with-ccw-virtio", "ccw-virtio-2= -explicit", false, true, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("s390x", "base-ccw-live-with-2-ccw-virtio", "ccw-virtio= -1-explicit", false, true, "device_del", QMP_DEVICE_DELETED("virtio-disk4") QMP_OK= ); @@ -855,7 +865,8 @@ mymain(void) DO_TEST_ATTACH("s390x", "base-ccw-live-with-2-ccw-virtio", "ccw-virtio= -1-reverse", false, false, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_ATTACH("x86_64", "base-live", "ivshmem-plain", false, true, "object-add", QMP_OK, @@ -873,7 +884,8 @@ mymain(void) "disk-scsi-duplicate-wwn", false, false, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_ATTACH("x86_64", "base-live", "hostdev-pci", false, true, "device_add", QMP_OK); @@ -918,7 +930,8 @@ mymain(void) DO_TEST_ATTACH("x86_64", "base-live", "cdrom-usb", false, true, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("x86_64", "base-live", "cdrom-usb", true, true, "device_del", QMP_OK); DO_TEST_DETACH("x86_64", "base-live", "cdrom-usb", false, false, @@ -929,7 +942,8 @@ mymain(void) DO_TEST_ATTACH("x86_64", "base-live", "cdrom-scsi", false, true, "blockdev-add", QMP_OK, "blockdev-add", QMP_OK, - "device_add", QMP_OK); + "device_add", QMP_OK, + "query-block", QMP_EMPTY_ARRAY); DO_TEST_DETACH("x86_64", "base-live", "cdrom-scsi", true, true, "device_del", QMP_OK); DO_TEST_DETACH("x86_64", "base-live", "cdrom-scsi", false, false, --=20 2.39.2