From nobody Sun Feb 8 15:54:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1585671892; cv=none; d=zohomail.com; s=zohoarc; b=hxUwZFpbqMUGDvHdWNHGceklsTJENueYJIr+kWXiHF6cVFx09Tuo42gVGVgfFuW9LFdVQKCZMEfhGlXBwTrJ/aqXctyy8EFYuMscAEg/L1bjS9c6CC2oEhz2RIPB/UrccBoCUk9/NXywGFWs76WANAujqn+USq10+xL9nOipIOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585671892; 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=gWqQbr9/Tn709OXZklT27PsuXavr75JQ1k+NcqHPDKk=; b=KSUV13TT7fnwIi5wP7fNZX+7TYUd8mIs033wzhe+RyCCVTlJpHCrPnkZY5ANQ0QdFCg0sm7KafScUJAXbFu5Js245Yu7bE2u5iCTs4dsOQ94IebPG4MHsdf+NT4tpXyRrM5L/FeUqknQEzIR0+S6SogFcGNaLYEXvVhkCO93zCQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1585671892940142.1263442853301; Tue, 31 Mar 2020 09:24:52 -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-28-AXYGxw6oN4uan51-Q4pmTw-1; Tue, 31 Mar 2020 12:24:49 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BE01C477; Tue, 31 Mar 2020 16:24:43 +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 8DDEE19C58; Tue, 31 Mar 2020 16:24:43 +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 29A8018089C8; Tue, 31 Mar 2020 16:24:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02VGOfva023077 for ; Tue, 31 Mar 2020 12:24:41 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1D37F5D9E2; Tue, 31 Mar 2020 16:24:41 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.155]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8DBF85D9C5 for ; Tue, 31 Mar 2020 16:24:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585671891; 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=gWqQbr9/Tn709OXZklT27PsuXavr75JQ1k+NcqHPDKk=; b=YJWQrZNdzVNDxR6dyZlboT1snxr9RFrX0YcgHDks8ELGrljmpE4Fz5Sl27ysdG7SWAZduq zASZn9pMyJkxVr/ZFz2jzpOyGzLcUFWWpH7JWhxyddaUHFHkjSRWy/wY8gq0srV6N81z+s XNHcB+H+jQRCPvUE0a2ncJv6TqPagt0= X-MC-Unique: AXYGxw6oN4uan51-Q4pmTw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v3 05/10] virDomainDriverGenerateMachineName: Factor out embed path hashing Date: Tue, 31 Mar 2020 18:24:17 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 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.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The code that generates "qemu-embed-$hash" is going to be useful in more places. Separate it out into a function. Signed-off-by: Michal Privoznik Reviewed-by: Andrea Bolognani Reviewed-by: Daniel Henrique Barboza Reviewed-by: Daniel P. Berrang=C3=A9 --- src/hypervisor/domain_driver.c | 42 ++++++++++++++++++++++------------ src/hypervisor/domain_driver.h | 4 ++++ src/libvirt_private.syms | 1 + 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 7bf0fb3f98..31821fc712 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -28,6 +28,22 @@ =20 #define VIR_FROM_THIS VIR_FROM_DOMAIN =20 +char * +virDomainDriverGenerateRootHash(const char *drivername, + const char *root) +{ + g_autofree char *hash =3D NULL; + + if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, root, &hash) < 0) + return NULL; + + /* When two embed drivers start two domains with the same @name and @id + * we would generate a non-unique name. Include parts of hashed @root + * which guarantees uniqueness. The first 8 characters of SHA256 ought + * to be enough for anybody. */ + return g_strdup_printf("%s-embed-%.8s", drivername, hash); +} + =20 #define HOSTNAME_CHARS \ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-" @@ -72,26 +88,24 @@ virDomainDriverGenerateMachineName(const char *driverna= me, { virBuffer buf =3D VIR_BUFFER_INITIALIZER; =20 - virBufferAsprintf(&buf, "%s-", drivername); - if (root) { g_autofree char *hash =3D NULL; =20 - /* When two embed drivers start two domains with the same @name an= d @id - * we would generate a non-unique name. Include parts of hashed @r= oot - * which guarantees uniqueness. The first 8 characters of SHA256 o= ught - * to be enough for anybody. */ - if (virCryptoHashString(VIR_CRYPTO_HASH_SHA256, root, &hash) < 0) + if (!(hash =3D virDomainDriverGenerateRootHash(drivername, root))) return NULL; =20 - virBufferAsprintf(&buf, "embed-%.8s-", hash); - } else if (!privileged) { - g_autofree char *username =3D NULL; - if (!(username =3D virGetUserName(geteuid()))) { - virBufferFreeAndReset(&buf); - return NULL; + virBufferAsprintf(&buf, "%s-", hash); + } else { + virBufferAsprintf(&buf, "%s-", drivername); + if (!privileged) { + + g_autofree char *username =3D NULL; + if (!(username =3D virGetUserName(geteuid()))) { + virBufferFreeAndReset(&buf); + return NULL; + } + virBufferAsprintf(&buf, "%s-", username); } - virBufferAsprintf(&buf, "%s-", username); } =20 virBufferAsprintf(&buf, "%d-", id); diff --git a/src/hypervisor/domain_driver.h b/src/hypervisor/domain_driver.h index c52e37f038..b66ae2d421 100644 --- a/src/hypervisor/domain_driver.h +++ b/src/hypervisor/domain_driver.h @@ -22,6 +22,10 @@ =20 #include "domain_conf.h" =20 +char * +virDomainDriverGenerateRootHash(const char *drivername, + const char *root); + char * virDomainDriverGenerateMachineName(const char *drivername, const char *root, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b02b6380ed..ec367653d5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1403,6 +1403,7 @@ virDomainCgroupSetupMemtune; =20 # hypervisor/domain_driver.h virDomainDriverGenerateMachineName; +virDomainDriverGenerateRootHash; virDomainDriverMergeBlkioDevice; virDomainDriverParseBlkioDeviceStr; virDomainDriverSetupPersistentDefBlkioParams; --=20 2.24.1