From nobody Mon Sep 16 19:23:29 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 1721997628406251.96687440510175; Fri, 26 Jul 2024 05:40:28 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 441F61214; Fri, 26 Jul 2024 08:40:27 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 541C811C5; Fri, 26 Jul 2024 08:39:57 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id BE455E78; Fri, 26 Jul 2024 08:39:54 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.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 15D81996 for ; Fri, 26 Jul 2024 08:39:54 -0400 (EDT) Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-468-XXrFwlYIPLucoCEtMGUeSg-1; Fri, 26 Jul 2024 08:39:52 -0400 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BB645195609E for ; Fri, 26 Jul 2024 12:39:51 +0000 (UTC) Received: from ajulis-thinkpadt14gen4.remote.csb (unknown [10.43.2.246]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B725A1955D42 for ; Fri, 26 Jul 2024 12:39:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,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=1721997593; 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=uh3dpob3R2VlAatEHuXGbR8FOf7l65+dtu+9uOEupVM=; b=H2X2xPDk4COIIlFHucHKlpxE1kp/PHyxJt+FNqaZoMONTMy9QvKZ+nckinqwep5xZiLFjF zR7yzuX4xpKpe/1a9/KenoPNv04wclLk7G44aj1fS4e0S9GXDueO/csmQmMWY4b7z4FSBb 2MhgPgmx+BLCjc64cFbJ/fhf3R0lQsI= X-MC-Unique: XXrFwlYIPLucoCEtMGUeSg-1 From: Adam Julis To: devel@lists.libvirt.org Subject: [PATCH v2] vmx: Ensure unique disk targets when parsing Date: Fri, 26 Jul 2024 14:39:46 +0200 Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 6T2ULGBJO4MQURRUQO6LUBG5ZNQGQWAA X-Message-ID-Hash: 6T2ULGBJO4MQURRUQO6LUBG5ZNQGQWAA X-MailFrom: ajulis@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: 1721997630470116600 Content-Type: text/plain; charset="utf-8"; x-default="true" Disk targets are generated in virVMXParseConfig() with virVMXGenerateDiskTarget(). It works on combination of controller, fix offset, unit and prefix. While SCSI and SATA have same prefix "sd", function virVMXGenerateDiskTarget() could returned in some cases same targets. In this patch, after loaded SCSI and SATA disks to the def, indexes are regenerated, now simply from position of the disk in array of disks (def). With this, required uniqueness is guaranteed. Because assigned addresses of disks are generated from their indexes, for every changed SATA disk is called virDomainDiskDefAssignAddress() with the updated value. The corresponding tests have been modified to match the index changes. Signed-off-by: Adam Julis --- Since previous version in mailing list was complicated for trying to preserve the indexes of SCSI and previous tests, this one going to straightforward, although it changes all (SCSI and SATA) indexes. It's not a bug, since we cannot guarantee the same naming inside the guest anyway. src/vmx/vmx.c | 19 +++++++++++++++++++ tests/vmx2xmldata/esx-in-the-wild-11.xml | 4 ++-- tests/vmx2xmldata/esx-in-the-wild-12.xml | 4 ++-- tests/vmx2xmldata/esx-in-the-wild-2.xml | 4 ++-- tests/vmx2xmldata/esx-in-the-wild-8.xml | 4 ++-- tests/vmx2xmldata/scsi-driver.xml | 12 ++++++------ 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index 227744d062..22e59726c8 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1400,6 +1400,7 @@ virVMXParseConfig(virVMXContext *ctx, virCPUDef *cpu =3D NULL; char *firmware =3D NULL; size_t saved_ndisks =3D 0; + size_t i; =20 if (ctx->parseFileName =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1805,6 +1806,24 @@ virVMXParseConfig(virVMXContext *ctx, } } =20 + /* now disks contain only SCSI and SATA, SATA could have same name (ds= t) as SCSI + * so replace all their names with new ones to guarantee their uniquen= ess + * finally, regenerate correct addresses, while it depends on the inde= x */ + + for (i =3D 0; i < def->ndisks; i++) { + virDomainDiskDef *disk =3D def->disks[i]; + + VIR_FREE(disk->dst); + disk->dst =3D virIndexToDiskName(i, "sd"); + + if (virDomainDiskDefAssignAddress(NULL, disk, def) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not assign address to disk '%1$s'"), + virDomainDiskGetSource(disk)); + goto cleanup; + } + } + /* def:disks (ide) */ for (bus =3D 0; bus < 2; ++bus) { for (unit =3D 0; unit < 2; ++unit) { diff --git a/tests/vmx2xmldata/esx-in-the-wild-11.xml b/tests/vmx2xmldata/e= sx-in-the-wild-11.xml index 8807a057d7..d9522c1be2 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-11.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-11.xml @@ -22,8 +22,8 @@ - -
+ +
diff --git a/tests/vmx2xmldata/esx-in-the-wild-12.xml b/tests/vmx2xmldata/e= sx-in-the-wild-12.xml index 42184501d0..a7730845ee 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-12.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-12.xml @@ -21,9 +21,9 @@
- + -
+
diff --git a/tests/vmx2xmldata/esx-in-the-wild-2.xml b/tests/vmx2xmldata/es= x-in-the-wild-2.xml index 59071b5d3a..1a66f5e9c7 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-2.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-2.xml @@ -20,9 +20,9 @@ - + -
+
diff --git a/tests/vmx2xmldata/esx-in-the-wild-8.xml b/tests/vmx2xmldata/es= x-in-the-wild-8.xml index 47d22ced2a..d5356bda34 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-8.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-8.xml @@ -36,9 +36,9 @@ - + -
+
diff --git a/tests/vmx2xmldata/scsi-driver.xml b/tests/vmx2xmldata/scsi-dri= ver.xml index e5b73420c3..42b6fffe24 100644 --- a/tests/vmx2xmldata/scsi-driver.xml +++ b/tests/vmx2xmldata/scsi-driver.xml @@ -19,18 +19,18 @@ - -
+ +
- -
+ +
- -
+ +
--=20 2.45.2