From nobody Mon Feb 9 15:10:32 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 63.128.21.124 is neither permitted nor denied by domain of redhat.com) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=none (zohomail.com: 63.128.21.124 is neither permitted nor denied by domain of redhat.com) 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=1597743044; cv=none; d=zohomail.com; s=zohoarc; b=fULT8EnOWpVVXw8yU+22z6H5VA+EkcplqMntCrGm+AI4mzH1aOXL+k44fU3XwwrcOYkvHmvhm9eQBI425tHVJpU2YR/QEpczd7W7qXc0aYeudrOeehXs6Df9vd6MZ80jr1pKUzS+jGQQGs0zivHFZdGkKng/dDYp9uaNiK4HnHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597743044; 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=HR02A9C5kjy6Q/+JjoopLm0zJv8EIUvklcMfyM9wBuo=; b=HbH2DPSS3XtySn63Fz+X3MNsajSX7Iqn9EKCO3V/dzlXu4FULgP0drYVpBzKXPboRpQtuK72DzZdUl92/fetQvmBWA5Qj2hJ+zseSyyzG/gJ0n2n9XL9Ifw8nZM+ehnH3wF7IZMXfUUpcWrKDqbprUpeXY2eWASJkjcd7n+BQ9o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=none (zohomail.com: 63.128.21.124 is neither permitted nor denied by domain of redhat.com) 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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1597743044553382.7355233762895; Tue, 18 Aug 2020 02:30:44 -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-464-cvVYgsVsOW6PHXnAxeQOtQ-1; Tue, 18 Aug 2020 05:30:41 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3FA5D1005E64; Tue, 18 Aug 2020 09:30:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E36F3756B0; Tue, 18 Aug 2020 09:30:35 +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 B00F660361; Tue, 18 Aug 2020 09:30:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 07I9UXSK002101 for ; Tue, 18 Aug 2020 05:30:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id A2C2E7A1F3; Tue, 18 Aug 2020 09:30:33 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 209557A1E6 for ; Tue, 18 Aug 2020 09:30:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597743043; 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=HR02A9C5kjy6Q/+JjoopLm0zJv8EIUvklcMfyM9wBuo=; b=CA0s9+XwCllvnGuQddSsMYvDXk+SVeIagR0V7WmMKKIC1Qqz2anosYNy4obb87mCWiRYti IbQv9omMJhLasmmNmMw4FkXq1jJATUW7dKm6ihBXwg8RRoYVIXWQSdjGw4sqy0iSQgnl3a haU6zfPSlou8BtfTjZZZDO1gGD/SN0Y= X-MC-Unique: cvVYgsVsOW6PHXnAxeQOtQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 1/2] virdevmapper: Don't cache device-mapper major Date: Tue, 18 Aug 2020 11:30:24 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0.001 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 device mapper major is needed in virIsDevMapperDevice() which determines whether given device is managed by device-mapper. This number is obtained by parsing /proc/devices and then stored in a global variable so that the file doesn't have to be parsed again. However, as it turns out this logic is flawed - the major number is not static and can change as it can be specified as a parameter when loading the dm-mod module. Unfortunately, I was not able to come up with a good solution and thus the /proc/devices file is being parsed every time we need the device mapper major. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa --- src/util/virdevmapper.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index fe7f611496..b24d9377f8 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -46,11 +46,9 @@ =20 G_STATIC_ASSERT(BUF_SIZE > sizeof(struct dm_ioctl)); =20 -static unsigned int virDMMajor; - =20 static int -virDevMapperOnceInit(void) +virDevMapperGetMajor(unsigned int *major) { g_autofree char *buf =3D NULL; VIR_AUTOSTRINGLIST lines =3D NULL; @@ -69,7 +67,7 @@ virDevMapperOnceInit(void) =20 if (sscanf(lines[i], "%u %ms\n", &maj, &dev) =3D=3D 2 && STREQ(dev, DM_NAME)) { - virDMMajor =3D maj; + *major =3D maj; break; } } @@ -85,9 +83,6 @@ virDevMapperOnceInit(void) } =20 =20 -VIR_ONCE_GLOBAL_INIT(virDevMapper); - - static void * virDMIoctl(int controlFD, int cmd, struct dm_ioctl *dm, char **buf) { @@ -304,9 +299,6 @@ virDevMapperGetTargets(const char *path, * consist of devices or yet another targets. If that's the * case, we have to stop recursion somewhere. */ =20 - if (virDevMapperInitialize() < 0) - return -1; - if ((controlFD =3D virDMOpen()) < 0) return -1; =20 @@ -318,13 +310,14 @@ bool virIsDevMapperDevice(const char *dev_name) { struct stat buf; + unsigned int major; =20 - if (virDevMapperInitialize() < 0) + if (virDevMapperGetMajor(&major) < 0) return false; =20 if (!stat(dev_name, &buf) && S_ISBLK(buf.st_mode) && - major(buf.st_rdev) =3D=3D virDMMajor) + major(buf.st_rdev) =3D=3D major) return true; =20 return false; --=20 2.26.2