From nobody Mon Apr 29 09:29:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 154783803413971.1163723725814; Fri, 18 Jan 2019 11:00:34 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AD677C00293F; Fri, 18 Jan 2019 19:00:31 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7148560C55; Fri, 18 Jan 2019 19:00:31 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 0BF603F7CD; Fri, 18 Jan 2019 19:00:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0IIxhJJ006160 for ; Fri, 18 Jan 2019 13:59:43 -0500 Received: by smtp.corp.redhat.com (Postfix) id AF64D5C57C; Fri, 18 Jan 2019 18:59:43 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 62B6F5E1C8; Fri, 18 Jan 2019 18:59:41 +0000 (UTC) Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5D35A36883; Fri, 18 Jan 2019 18:59:40 +0000 (UTC) Received: by mail-qt1-f195.google.com with SMTP id k12so16349996qtf.7; Fri, 18 Jan 2019 10:59:40 -0800 (PST) Received: from localhost.localdomain ([2804:431:f701:d7e2:f3c3:7fc9:2def:debc]) by smtp.gmail.com with ESMTPSA id p47sm75831709qta.36.2019.01.18.10.59.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jan 2019 10:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e3D6pAxwNaYl9dE4/4p18L86LFSObjF0P2teLSC74cE=; b=vgWyyJUJxzWGVuTbZkLwQORrYFyjl+o52I/IggrKNOQhMZ7OfS1Rxsar1Ju4ZJhLva 1LaQ4Zx3qV9B1/UTXNnwjszrnhz1hTmIXf4kR1GkAhQ4yah0k7RhUPZNRoPdFvaBs1Tx lWcZ6x7BjHcpdsbzKHG2nUUP2BD5n/cq2lAz/O7Hs/vpRBGwP52kENSHgsRrD/UIdurc gdkDoEz3rwTHcP6YfC4R672BMH83hCXuTGXUrlJ7HbeUKOtQWXfpMvBr5wU5Y+NSkxjw zSRzCtcvK3sN1ai8lePmdeSmvEzr/81ChRleA42Eg3OTjwPYfp4DBHZhFAJT6krZlz8B pQqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e3D6pAxwNaYl9dE4/4p18L86LFSObjF0P2teLSC74cE=; b=W8RUAUBPmPuZgYqIgaOtqyFgFNPtfnmklbTGJVJ1c8iCwqnj+pQh8A9iaL8gHDrYAz oiBCxKfJeXWX8rZH9Oqb+iTxUQ/PNXjgQESpAmhSOXxkeBMt4etRL6spCzYDDibdHpc5 usbbs36U/kHCHpoNjzty8cjAQCpppQpBMSCa9cEEajOIhvkNfjH24FhxJahn/8sYp8po 4ZCODpRkCCdfBNyqfeJnmfmAoyx+goz0STmfhQzwpMTCyPmjluwDVYP8Ean8Kq8cNJpQ cNzsbtSWGIrH7F+VwyrCU+fw1gsRjlrzTIE5Ii50EUU1G8bHcIc1ZOsukT7xe/JBljOL x9eQ== X-Gm-Message-State: AJcUukewXcpNuoalTs5kdZfP+WT7jYjKPAg7hhwtI0mIJbAWxB31QGaP DA4aFRtEs2WFAGLsrhLZnhTMXKw6zDI= X-Google-Smtp-Source: ALg8bN6ZcIz43MjtnporjuOmdJxmQ7eJVbZNl85HiGPDegycy6XX4RK2CBQpKFXdKZhwe8W7dMWw7Q== X-Received: by 2002:a0c:8ae3:: with SMTP id 32mr16787936qvw.27.1547837979496; Fri, 18 Jan 2019 10:59:39 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Fri, 18 Jan 2019 16:59:20 -0200 Message-Id: <20190118185920.25750-2-danielhb413@gmail.com> In-Reply-To: <20190118185920.25750-1-danielhb413@gmail.com> References: <20190118185920.25750-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 18 Jan 2019 18:59:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 18 Jan 2019 18:59:40 +0000 (UTC) for IP:'209.85.160.195' DOMAIN:'mail-qt1-f195.google.com' HELO:'mail-qt1-f195.google.com' FROM:'danielhb413@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.142 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.160.195 mail-qt1-f195.google.com 209.85.160.195 mail-qt1-f195.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Cc: pkrempa@redhat.com, Srikanth Aithal , Daniel Henrique Barboza Subject: [libvirt] [PATCH v2 1/1] qemu_hotplug.c: check disk address before hotplug X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 18 Jan 2019 19:00:32 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" In a case where we want to hotplug the following disk: (...)
In a QEMU guest that has a single OS disk, as follows: (...)
What happens is that the existing guest disk will receive the ID 'scsi0-0-0-0' due to how Libvirt calculate the alias based on the address in qemu_alias.c, qemuAssignDeviceDiskAlias. When hotplugging a disk that happens to have the same address, Libvirt will calculate the same ID to it and attempt to device_add. QEMU will refuse it: $ virsh attach-device dhb hp-disk-dup.xml error: Failed to attach device from hp-disk-dup.xml error: internal error: unable to execute QEMU command 'device_add': Duplica= te ID 'scsi0-0-0-0' for device And Libvirt follows it up with a cleanup code in qemuDomainAttachDiskGeneric that ends up removing what supposedly is a faulty hotplugged disk but, in this case, ends up being the original guest disk. This happens because Libv= irt doesn't differentiate the error received by QMP device_add. An argument can be made for how QMP device_add should provide a different error code for this scenario. A quicker way to solve the problem is presented in this patch: let us check the address of disk to be attached and see if there is already a disk with the same address in the VM definition. In this case, error out without calling device_add. After this patch, this is the result of the previous attach-device call: $ ./run tools/virsh attach-device dhb ~/hp-disk-dup.xml error: Failed to attach device from /home/danielhb/hp-disk-dup.xml error: operation failed: attached disk address conflicts with existing disk= 'scsi0-0-0-0' Reported-by: Srikanth Aithal Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_hotplug.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index a1c3ca999b..4e6703f0b8 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -875,6 +875,36 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, } =20 =20 +/** + * qemuDomainFindDiskByAddress: + * + * Returns an existing disk in the VM definition that matches a given + * bus/controller/unit/target set, NULL in no match was found. */ +static virDomainDiskDefPtr +qemuDomainFindDiskByAddress(virDomainDefPtr def, + virDomainDeviceInfo info) +{ + virDomainDeviceInfo vm_info; + int idx; + + for (idx =3D 0; idx < def->ndisks; idx++) { + vm_info =3D def->disks[idx]->info; + if ((vm_info.addr.drive.bus =3D=3D info.addr.drive.bus) && + (vm_info.addr.drive.controller =3D=3D info.addr.drive.controll= er) && + (vm_info.addr.drive.unit =3D=3D info.addr.drive.unit)) { + /* Address does not have target to compare. We have + * a match. */ + if (!info.addr.drive.target) + return def->disks[idx]; + else if (vm_info.addr.drive.target && + vm_info.addr.drive.target =3D=3D info.addr.drive.= target) + return def->disks[idx]; + } + } + return NULL; +} + + /** * qemuDomainAttachDiskGeneric: * @@ -888,12 +918,21 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver, int ret =3D -1; qemuDomainObjPrivatePtr priv =3D vm->privateData; qemuHotplugDiskSourceDataPtr diskdata =3D NULL; + virDomainDiskDefPtr vm_disk =3D NULL; char *devstr =3D NULL; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); =20 if (qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, false) < 0) goto cleanup; =20 + if ((disk->info.type =3D=3D VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) && + (vm_disk =3D qemuDomainFindDiskByAddress(vm->def, disk->info))) { + virReportError(VIR_ERR_OPERATION_FAILED, + _("attached disk address conflicts with existing " + "disk '%s'"), vm_disk->info.alias); + goto error; + } + if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0) goto error; =20 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list