From nobody Tue Dec 3 17:39:42 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; 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=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1731418554700951.6339361037875; Tue, 12 Nov 2024 05:35:54 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 99D4A17A8; Tue, 12 Nov 2024 08:35:53 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8FFA717F4; Tue, 12 Nov 2024 08:35:35 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id D1E991788; Tue, 12 Nov 2024 08:35:32 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 4FDD8142E for ; Tue, 12 Nov 2024 08:35:32 -0500 (EST) Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591-CIP8ctitN5evzyh64CRqcA-1; Tue, 12 Nov 2024 08:35:30 -0500 Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-539e7dc83ecso3589028e87.2 for ; Tue, 12 Nov 2024 05:35:30 -0800 (PST) Received: from wheatley.localdomain (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-381ed987d95sm15606050f8f.44.2024.11.12.05.35.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Nov 2024 05:35:26 -0800 (PST) Received: from wheatley.brq.redhat.com (wheatley.k8r.cz [127.0.0.1]) by wheatley.localdomain (Postfix) with ESMTP id 94D633C1624E for ; Tue, 12 Nov 2024 14:35:26 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,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=1731418532; 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; bh=ha24Dlg//MShHq0gNnswL+yR5/YkmhDf+rGO7eg4Psw=; b=WGQLK/HzAHhpmEbtvPp05s0l91mVqbJA2nnCVhsSejQyEwmu1j+6PIHNmUKu7LA23hi3pW BmlPtxUis/Mm2MLUzywz0F5oxZcq7RJwoyoO1rdK+wioGPv/93P1kCxTxzvGWsFgOWfjDN zHL6sd9EIVlyTJb4EpwDh0K3bp9jO6M= X-MC-Unique: CIP8ctitN5evzyh64CRqcA-1 X-Mimecast-MFC-AGG-ID: CIP8ctitN5evzyh64CRqcA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731418529; x=1732023329; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ha24Dlg//MShHq0gNnswL+yR5/YkmhDf+rGO7eg4Psw=; b=cGisokcUJCJE9ux56zxx8xQPeXDTOPnp8FBZwTiZ6cfYd1dQiOp4YxAakW5iesTzzD Na2pL1ILFc5xEUAjbCF8LhN8OGjbcs7xHIEAmJilbVBoy/3BpImKMNGPdA3DqT2eGulV mS6c5Vo3a4woD2fb+eJ9odKKREAElAVAnz92MOIX5DiBe8qNuvJDPPhDKX3yxKSUfrrt y81Vig7EAOZlf9aG0YquV/isjKkF0Z3XkocaEjbQbjwLwUrgFpDpCOkBqJbX/Z4GWAvd B/geV5siMteD/M+RsxFQCt4VFzsXs8/VgXzVtS2pou/QcDmtVGYr+VuQI/Y9WCQlUdvn Ef6g== X-Gm-Message-State: AOJu0YzJ5T298AWldPuL7fRfKlUnzHSY7igRWHv/rJdXDvmfXZfnM9Va 6YJPl/fGDTywnWbsVzOC2DMAg+l5LumwbVEsNW4S9TSI3peeQJIMiEDWbq45XVMRWAn9+zokzhg 16TXkQrkU/xCNStMHnnqe1SMO8Q+iJtZjXCMclbfRwnXd1lQkEex1UycTOmI9B0NPXBU26uxPJw MVot767jkxTf344xeWf+O0tUlfm+DmjQRpJRCGIgs= X-Received: by 2002:a05:6512:128a:b0:539:f886:31d6 with SMTP id 2adb3069b0e04-53d862bd946mr7627766e87.2.1731418529220; Tue, 12 Nov 2024 05:35:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTHXhAP2948RCfXGzAKNbNIdsOLAEs46nEjYJJ8HbOWwIs2+W3e6NCY+0eU0cY32DIxKnTqA== X-Received: by 2002:a05:6512:128a:b0:539:f886:31d6 with SMTP id 2adb3069b0e04-53d862bd946mr7627708e87.2.1731418527221; Tue, 12 Nov 2024 05:35:27 -0800 (PST) From: Martin Kletzander To: devel@lists.libvirt.org Subject: [PATCH v3] qemu_hotplug: Do not report unknown error when hot-unplugging non-existing device Date: Tue, 12 Nov 2024 14:33:29 +0100 Message-ID: <2e036107744bbf952eeb6fc5a61a4ea54eda0f1f.1731418409.git.mkletzan@redhat.com> X-Mailer: git-send-email 2.47.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: xq_LENN5a_HlJmzmMlCOF3PhO1RLVAH2R3gx3f4ACrU_1731418529 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: YJQYHR77TMDUAADU2BEQFYCXLVPKLCI3 X-Message-ID-Hash: YJQYHR77TMDUAADU2BEQFYCXLVPKLCI3 X-MailFrom: mkletzan@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: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1731418556446116600 Content-Type: text/plain; charset="utf-8"; x-default="true" When qemuDomainDeleteDevice() gets "DeviceNotFound" error it is a special case as we're trying to remove a device which does not exists any more. Such occasion is indicated by the return value -2. Callers of the aforementioned function ought to base their behaviour on the return value. However not all callers take as much care for the return value as one could realistically anticipate. Follow the usual direction of removing possible backend object (in case of character devices), remove the device from its XML without waiting for the device removal from QEMU (since it is already not there) and basically follow the same algorithm as there is when the device was removed, skipping over the wait for the device removal. The overall return value also needs to be adjusted since qemuDomainDeleteDevice() does not set an error on the -2 return value and would otherwise trigger an unknown error being reported to the user or management application. Signed-off-by: Martin Kletzander Reviewed-by: J=C3=A1n Tomko --- v3: - Skip qemuDomainWaitForDeviceRemoval() when the vCPU does not exist, as written in the commit message - Do all the other necessary things when the vCPU is missing v2: - Adjust for -2 return value in callers src/qemu/qemu_hotplug.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 8361d3d9c1b7..bddd553c88a5 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -6090,8 +6090,12 @@ qemuDomainDetachDeviceChr(virQEMUDriver *driver, if (rc < 0) goto cleanup; } else { - if (qemuDomainDeleteDevice(vm, tmpChr->info.alias) < 0) + ret =3D qemuDomainDeleteDevice(vm, tmpChr->info.alias); + if (ret < 0) { + if (ret =3D=3D -2) + ret =3D qemuDomainRemoveChrDevice(driver, vm, tmpChr, true= ); goto cleanup; + } } =20 if (guestfwd) { @@ -6595,18 +6599,20 @@ qemuDomainHotplugDelVcpu(virQEMUDriver *driver, =20 qemuDomainMarkDeviceAliasForRemoval(vm, vcpupriv->alias); =20 - if (qemuDomainDeleteDevice(vm, vcpupriv->alias) < 0) { - if (virDomainObjIsActive(vm)) - virDomainAuditVcpu(vm, oldvcpus, oldvcpus - nvcpus, "update", = false); - goto cleanup; - } - - if ((rc =3D qemuDomainWaitForDeviceRemoval(vm)) <=3D 0) { - if (rc =3D=3D 0) - virReportError(VIR_ERR_OPERATION_TIMEOUT, "%s", - _("vcpu unplug request timed out. Unplug result= must be manually inspected in the domain")); - - goto cleanup; + rc =3D qemuDomainDeleteDevice(vm, vcpupriv->alias); + if (rc < 0) { + if (rc !=3D -2) { + if (virDomainObjIsActive(vm)) + virDomainAuditVcpu(vm, oldvcpus, oldvcpus - nvcpus, "updat= e", false); + goto cleanup; + } + } else { + if ((rc =3D qemuDomainWaitForDeviceRemoval(vm)) <=3D 0) { + if (rc =3D=3D 0) + virReportError(VIR_ERR_OPERATION_TIMEOUT, "%s", + _("vcpu unplug request timed out. Unplug re= sult must be manually inspected in the domain")); + goto cleanup; + } } =20 if (qemuDomainRemoveVcpu(vm, vcpu) < 0) --=20 2.47.0