From nobody Tue Apr 23 18:45:56 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 1552684214239620.1977375683755; Fri, 15 Mar 2019 14:10:14 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5BFA6308795D; Fri, 15 Mar 2019 21:10:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2823F17AD4; Fri, 15 Mar 2019 21:10:12 +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 C4EDA181A13C; Fri, 15 Mar 2019 21:10:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2FL75RM032147 for ; Fri, 15 Mar 2019 17:07:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9BE671973E; Fri, 15 Mar 2019 21:07:05 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9225D19C57; Fri, 15 Mar 2019 21:07:05 +0000 (UTC) Received: from mail-qt1-f196.google.com (mail-qt1-f196.google.com [209.85.160.196]) (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 1CE9530018D8; Fri, 15 Mar 2019 21:07:04 +0000 (UTC) Received: by mail-qt1-f196.google.com with SMTP id h39so11736250qte.2; Fri, 15 Mar 2019 14:07:04 -0700 (PDT) Received: from rekt.ibmmodules.com ([2804:431:f701:aef2:4320:3acd:b307:d018]) by smtp.gmail.com with ESMTPSA id 17sm2470220qtt.18.2019.03.15.14.07.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 15 Mar 2019 14:07:02 -0700 (PDT) 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=4vBtHlk5bMILn7UHqm848hMfD8YMRO0DnS375lcnh1I=; b=dJieJ/BRtpG8TBEO0RTrzt1Yi1oaTwkpq/mv4ciI+rHFXKMqmY/j7CTUlhza4aIRZU PXlvandaQ4gVLaQ35QgGGbuPsK+085QrFRdNMXmxqPpPIf56uO4BzvxFE8eihaEHBZTV A3FfvauSmhrtkhFuF3sM4EexY3HzXMkDWy5DPAInbyO/At5dLQ8oph+C81JXY8+s7xEb 1IF0A3sQqAUNRsmUnVdEjWLPYsmPCqf2TETMQeTU3hNpi7TSw0mZNypy1AIBCwh7SFji CAfcwC/KW54bwECUZgoJtIpThVZo7a40Me1P/Cfu9P9XuFjtS1GJ2/8G03ZvCk+gcn7Q 2WSg== 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=4vBtHlk5bMILn7UHqm848hMfD8YMRO0DnS375lcnh1I=; b=DsJyWTclIL/Z0xkG5ufju8G+UEW/VqC/SZiK866cnh6MUQC0+VrF0UAgX5M8HM29cB SCmagiFed+T/uE9e4wvqAwZHwmw5359cDs5Nma/gwQw46mk2OiedDy8lLtJ/fBBiDZcw HHUS6dFylGwFICrYDkys+6JQh436ox49Mz+8BX50UqcVlYdgSuf1Nd4SeFPZW+TUWTrA CKdF9Go3eAIiTk7WvGtz0gqFrZjVNUlcBdNu56DzsAeZlov7Y1EskLqSN420EWj5U8He eH/HtE4P9eIg5QNx2EEpN1c9+45IW1d15fP0Onouul2HuwWeA1M65EV5H3WMNCUVIQQQ ZzJQ== X-Gm-Message-State: APjAAAVOZo2W5Ps9yLNHFbL63T2PSdl62vhV69dSV/7uUDqxbkNHXcg2 8q/+JpVgcB4uJCn81kz9xZMpM35k X-Google-Smtp-Source: APXvYqzA9aYNlhI3G0h6im/E+WGbUCpEv3Z05yYKuuuCFhHfHVPYpFRRPbRcG4TqrgM+bITtUqMBVA== X-Received: by 2002:ac8:2269:: with SMTP id p38mr4524721qtp.340.1552684023236; Fri, 15 Mar 2019 14:07:03 -0700 (PDT) From: Daniel Henrique Barboza To: libvir-list@redhat.com Date: Fri, 15 Mar 2019 18:06:45 -0300 Message-Id: <20190315210645.10229-2-danielhb413@gmail.com> In-Reply-To: <20190315210645.10229-1-danielhb413@gmail.com> References: <20190315210645.10229-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.46]); Fri, 15 Mar 2019 21:07:04 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 15 Mar 2019 21:07:04 +0000 (UTC) for IP:'209.85.160.196' DOMAIN:'mail-qt1-f196.google.com' HELO:'mail-qt1-f196.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.196 mail-qt1-f196.google.com 209.85.160.196 mail-qt1-f196.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: pkrempa@redhat.com, Srikanth Aithal , Daniel Henrique Barboza Subject: [libvirt] [PATCH v3 1/1] domain_conf: check device address before attach 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 15 Mar 2019 21:10:13 +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 ub1810 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 patch adds an address verification for all attached devices, avoid calling the driver attach() function using a device with duplicated address. The change is done in virDomainDefCompatibleDevice when @action is equal to VIR_DOMAIN_DEVICE_ACTION_ATTACH. The affected callers are: - qemuDomainAttachDeviceLiveAndConfig, both LIVE and CONFIG cases; - lxcDomainAttachDeviceFlags, both LIVE and CONFIG. The check is done using the virDomainDefHasDeviceAddress, a generic function that can check address duplicates for all supported device types, not limiting just to DeviceDisk type. After this patch, this is the result of the previous attach-device call: $ ./run tools/virsh attach-device ub1810 hp-disk-dup.xml error: Failed to attach device from hp-disk-dup.xml error: Requested operation is not valid: Domain already contains a device w= ith the same address Reported-by: Srikanth Aithal Signed-off-by: Daniel Henrique Barboza --- As mentioned above, this code impacts LXC too. Although I believe this change isn't harmful, tt would be good to have an ACK of someone familiar with the LXC driver to be safe. src/conf/domain_conf.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 504c24b545..d3d33ef78d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -28628,6 +28628,14 @@ virDomainDefCompatibleDevice(virDomainDefPtr def, if (oldDev) data.oldInfo =3D virDomainDeviceGetInfo(oldDev); =20 + if (action =3D=3D VIR_DOMAIN_DEVICE_ACTION_ATTACH && + virDomainDefHasDeviceAddress(def, data.newInfo)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("Domain already contains a device with the same " + "address")); + return -1; + } + if (action =3D=3D VIR_DOMAIN_DEVICE_ACTION_UPDATE && live && (data.newInfo && data.oldInfo && --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list