From nobody Mon Feb 9 23:57:46 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1616777342; cv=none; d=zohomail.com; s=zohoarc; b=Ljcz5u/OCW4FcvJQFDcRuWDNCb/Cyic5qqOw0+Nw5OPNCK3eDMSDdDu5MRwpJ1u6077PrPbZJ/6mr9yd6LE4BW36z//yXFl6ysraQlgiCaHmQlVdJjtekJjS5ATDLK5f0/ZXeMMszHFegVq2HcYcNyoaDYuRl/HoP8j5LG8+zfo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777342; h=Content-Type:Content-Transfer-Encoding:Cc: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=GU/L9q497qHERTdfR2670srKRKEDww4l3NTie2h49wI=; b=A/45lmky2raqlhGkYbhjXuwOgK6ixkSOQCFuPKjmyYA6zxeaEWDXXAykXKMegRFYURfwkFVGwFU0QAzV25pGG8waDxrjRA98C52APFLYK2q+V3Xb2g1BTPloa5JG/142fJmuQTQXwjfcWXctoJ33uXHgMhBgrm+HhsWC7eorhMU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 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-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 161677734285426.724995262888456; Fri, 26 Mar 2021 09:49:02 -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-365-QZ-I8BAsM3-BzeX_l4D0BA-1; Fri, 26 Mar 2021 12:48:58 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AB132107B7C9; Fri, 26 Mar 2021 16:48:51 +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 8790B5D6DC; Fri, 26 Mar 2021 16:48:51 +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 48594180213C; Fri, 26 Mar 2021 16:48:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12QGmZ9h002945 for ; Fri, 26 Mar 2021 12:48:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E0785D72E; Fri, 26 Mar 2021 16:48:35 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-51.phx2.redhat.com [10.3.113.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 56C0E5D6DC; Fri, 26 Mar 2021 16:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777341; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=GU/L9q497qHERTdfR2670srKRKEDww4l3NTie2h49wI=; b=SwJwqssO9w+QB8ISLfoTOglGlS25TqoGd+tnKomc9+qKmbbhf6zjc7KJUXAsAlHQb/eosn vVF5/7gd1O7M7lD9RfITFI+IfD+fvGABJcgc6vdHVi0FbM7A+tRBsNyldgi4uyvs8BTKvJ UxtxJtLSYnUqhU9TV03jeQjLDzrvbkw= X-MC-Unique: QZ-I8BAsM3-BzeX_l4D0BA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 06/30] nodedev: expose internal helper for naming devices Date: Fri, 26 Mar 2021 11:48:02 -0500 Message-Id: <20210326164826.1720062-7-jjongsma@redhat.com> In-Reply-To: <20210326164826.1720062-1-jjongsma@redhat.com> References: <20210326164826.1720062-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: eskultet@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.15 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) Content-Type: text/plain; charset="utf-8" Expose a helper function that can be used by udev and mdevctl to generate device names for node devices. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 25 +++++++++++++++++++++++++ src/node_device/node_device_driver.h | 6 ++++++ src/node_device/node_device_udev.c | 19 +++---------------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 920fd815f2..bada5bbf00 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -978,3 +978,28 @@ nodedevRegister(void) return udevNodeRegister(); #endif } + + +void +nodeDeviceGenerateName(virNodeDeviceDef *def, + const char *subsystem, + const char *sysname, + const char *s) +{ + size_t i; + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + + virBufferAsprintf(&buf, "%s_%s", + subsystem, + sysname); + + if (s !=3D NULL) + virBufferAsprintf(&buf, "_%s", s); + + def->name =3D virBufferContentAndReset(&buf); + + for (i =3D 0; i < strlen(def->name); i++) { + if (!(g_ascii_isalnum(*(def->name + i)))) + *(def->name + i) =3D '_'; + } +} diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index 4a40aa51f6..76a40c05ad 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -120,3 +120,9 @@ nodeDeviceGetMdevctlStartCommand(virNodeDeviceDefPtr de= f, virCommandPtr nodeDeviceGetMdevctlStopCommand(const char *uuid, char **errmsg); + +void +nodeDeviceGenerateName(virNodeDeviceDef *def, + const char *subsystem, + const char *sysname, + const char *s); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 373f36c41f..eae301cc95 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -311,22 +311,9 @@ udevGenerateDeviceName(struct udev_device *device, virNodeDeviceDefPtr def, const char *s) { - size_t i; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - - virBufferAsprintf(&buf, "%s_%s", - udev_device_get_subsystem(device), - udev_device_get_sysname(device)); - - if (s !=3D NULL) - virBufferAsprintf(&buf, "_%s", s); - - def->name =3D virBufferContentAndReset(&buf); - - for (i =3D 0; i < strlen(def->name); i++) { - if (!(g_ascii_isalnum(*(def->name + i)))) - *(def->name + i) =3D '_'; - } + nodeDeviceGenerateName(def, + udev_device_get_subsystem(device), + udev_device_get_sysname(device), s); =20 return 0; } --=20 2.26.3