From nobody Sun May 19 12:01:00 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=1632902535; cv=none; d=zohomail.com; s=zohoarc; b=h+XwVBxg3OHnW3Rqw8ugZoHEF9M9j3HYk5CZ4kWt23pfsxFghXqPUkYNhStJwlsfPwMxnpQ5x7sXSqyouKxkulrngm6E5M1Q7m08E8vcG79Ruks8JebdgFIhG8M/F1IySq8oHIGE5FIG8VHYtFH+l3kMtvoXOXUFl9iSYTVyg84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632902535; 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=kchsx/H46cmhNNtJb7PitLub+t+q2UG9tOPEOPrzGSU=; b=mnOzQG6trsXV0prRvQaSQuJQnbV0ztExbPmzbFKR/jTFguIKpJvHbjhKiIEI45YgCkppCu+JtJsLcVdOn5qQh41nPywI6pq/zk33FoxK6S16xzRXBuEKf/D/Dykje3rA1ocx43btEz49iL+lw22erNHi1YSSzlstbBP3zaaiUOI= 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 1632902535467974.4872244839978; Wed, 29 Sep 2021 01:02:15 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-386-khLSgHtdNv6pFthTiEl4jQ-1; Wed, 29 Sep 2021 04:02:12 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8F999801E72; Wed, 29 Sep 2021 08:02:07 +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 3148460936; Wed, 29 Sep 2021 08:02:07 +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 564B01800B9C; Wed, 29 Sep 2021 08:02:05 +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 18T8221g026804 for ; Wed, 29 Sep 2021 04:02:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id AD73319739; Wed, 29 Sep 2021 08:02:02 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 10CFD19C79; Wed, 29 Sep 2021 08:02:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632902534; 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=kchsx/H46cmhNNtJb7PitLub+t+q2UG9tOPEOPrzGSU=; b=DoHi0k1e9xXqXWHa0zj5rKwNIOXfSOM9c1oH8p03reUziiMC045rJdCh9Mpy9Sc/Eo9m5w gU+bL9p44dTIiJufvqkqMzyeQg6dwJy7MB3pemke67qQwZJ6DccvMGJ0IwXe1ubI175NOA npI0ZiS0Ew/WL47IMuHV7qY06D9hY4E= X-MC-Unique: khLSgHtdNv6pFthTiEl4jQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/1] vmx: Fix mapping Date: Wed, 29 Sep 2021 10:01:56 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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: 1632902536736100001 Content-Type: text/plain; charset="utf-8" Not a long ago I've introduced parsing of vmx.genid and vmx.genidX properties. They map onto our element. The implementation was quite straightforward: the UUID which is 128 bits long is split into two equally long parts which I then put next to each other and used virUUIDParse() to fill the UUID buffer. However, as it turns out it is not that simple - VMX apparently does swap some byte pairs in both Hi and Lo parts. Do the reverse so that the UUID is true to its original value. Mind you, this algorithm is heavily inspired by virt-v2v code: https://github.com/libguestfs/virt-v2v/blob/981e0c6b2d2ae0093e3f31829a8d00b= 552898552/input/parse_domain_from_vmx.ml#L364 Fixes: 7d661d6e20fe82e5472d5ab6dcd97ed76291f256 Reported-by: Richard W.M. Jones Signed-off-by: Michal Privoznik --- src/vmx/vmx.c | 16 ++++++++++++---- tests/vmx2xmldata/esx-in-the-wild-10.xml | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index d3540acd84..f0c30e60b6 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -1347,6 +1347,9 @@ virVMXParseGenID(virConf *conf, { long long vmid[2] =3D { 0 }; g_autofree char *uuidstr =3D NULL; + size_t i; + /* This mapping comes from virt-v2v sources. */ + const int uuidmap[] =3D {8, 10, 12, 14, 4, 6, 0, 2, 30, 28, 26, 24, 22= , 20, 18, 16}; =20 if (virVMXGetConfigLong(conf, "vm.genid", &vmid[0], 0, true) < 0 || virVMXGetConfigLong(conf, "vm.genidX", &vmid[1], 0, true) < 0) @@ -1356,10 +1359,15 @@ virVMXParseGenID(virConf *conf, return 0; =20 uuidstr =3D g_strdup_printf("%.16llx%.16llx", vmid[0], vmid[1]); - if (virUUIDParse(uuidstr, def->genid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Could not parse UUID from string '%s'"), uuidstr= ); - return -1; + /* Ideally we would just call virUUIDParse() and be done, but it's not= that + * simple. Some bytes in genid and genidX are swapped and we need to s= wap + * them back. This matches what virt-v2v does. */ + for (i =3D 0; i < G_N_ELEMENTS(uuidmap); i++) { + int idx =3D uuidmap[i]; + int val_hi =3D g_ascii_xdigit_value(uuidstr[idx]); + int val_lo =3D g_ascii_xdigit_value(uuidstr[idx + 1]); + + def->genid[i] =3D 16 * val_hi + val_lo; } def->genidRequested =3D true; =20 diff --git a/tests/vmx2xmldata/esx-in-the-wild-10.xml b/tests/vmx2xmldata/e= sx-in-the-wild-10.xml index 47ed637920..59cdc68bf3 100644 --- a/tests/vmx2xmldata/esx-in-the-wild-10.xml +++ b/tests/vmx2xmldata/esx-in-the-wild-10.xml @@ -1,7 +1,7 @@ w2019biosvmware 421a6177-5aa9-abb7-5924-fc376c18a1b4 - 13c67c91-9f47-526f-b0d6-e4dd2e4bb4f9 + 9f47526f-7c91-13c6-f9b4-4b2edde4d6b0 4194304 4194304 2 --=20 2.32.0