From nobody Tue May 7 00:16:51 2024 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: Christian Ehrhardt Reviewed-by: Peter Krempa Tested-by: Christian Ehrhardt --- 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 From nobody Tue May 7 00:16:51 2024 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.com: 207.211.31.120 is neither permitted nor denied by domain of redhat.com) client-ip=207.211.31.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=none (zohomail.com: 207.211.31.120 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=1597743050; cv=none; d=zohomail.com; s=zohoarc; b=HrVRq0UQJqkwNqp+G0+l6oVnFZesBnNayZcs/yBZkQsysZChUDQs6PvLl4VNKvw2dNjyGkpBnpnvJijYdoNUxh6Hv6vFVZZz3x+/8syoOBe2NSQrNOwMvUxykLalkUwE/YRT34s5y2OBTPnX3EavPbyM3hXwOGI70K26MkIpk+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597743050; 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=ZR3o/oWfhX29irznkQ9QNyyFHHhmQx0pxIbEyrSW9N4=; b=dWd5mWhturzo4QnFSL8hAv1uaVobl0DKjNynmPsll4Nwn4mFHFSNJvxTLuo1COFo8sjhX8k/OT7vuGEvT+aPsn5ekrg6nKWUejMpXtwbRFWv6p03dIKAjtRJaDXpNdCkdjjS8CF+3iXLEjS2rC50DQkTsSPxGkGYSjS2Iwgr7KI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=none (zohomail.com: 207.211.31.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1597743050185981.385886881039; Tue, 18 Aug 2020 02:30:50 -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-319-MWKBnke0M6Cl5i4UcRrDrw-1; Tue, 18 Aug 2020 05:30:46 -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 C58891005E5F; Tue, 18 Aug 2020 09:30:40 +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 A222D19C4F; Tue, 18 Aug 2020 09:30:40 +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 3FBDA181A06E; Tue, 18 Aug 2020 09:30:40 +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 07I9UYnW002106 for ; Tue, 18 Aug 2020 05:30:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 854A27A1E6; Tue, 18 Aug 2020 09:30:34 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.2]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02A027849A for ; Tue, 18 Aug 2020 09:30:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597743049; 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=ZR3o/oWfhX29irznkQ9QNyyFHHhmQx0pxIbEyrSW9N4=; b=EKdH9yVxJpNoJRAzWBkKbJQiDoew3OJv0aCK+zwA95jMD4fiSjWXyW3Bb9UrZbp/RFxtWQ 0pBc/IFrjhkFn8wcH3rE7QZCv0iG5qxquilBzVRW9xSfyQmlx3qN/cTd/Z28jzw6FZNN5q pa6xMAzV0fCl3ofvKZxU0wLrM4vSnsU= X-MC-Unique: MWKBnke0M6Cl5i4UcRrDrw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 2/2] virdevmapper: Handle kernel without device-mapper support Date: Tue, 18 Aug 2020 11:30:25 +0200 Message-Id: <0c2805af80a131d364fdab81d63da45b30c6cc29.1597742945.git.mprivozn@redhat.com> 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.84 on 10.5.11.23 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" In one of my latest patch (v6.6.0~30) I was trying to remove libdevmapper use in favor of our own implementation. However, the code did not take into account that device mapper can be not compiled into the kernel (e.g. be a separate module that's not loaded) in which case /proc/devices won't have the device-mapper major number and thus virDevMapperGetTargets() and/or virIsDevMapperDevice() fails. Fixes: 22494556542c676d1b9e7f1c1f2ea13ac17e1e3e Reported-by: Andrea Bolognani Reported-by: Christian Ehrhardt Signed-off-by: Michal Privoznik Reviewed-by: Christian Ehrhardt Reviewed-by: Peter Krempa Tested-by: Christian Ehrhardt --- src/util/virdevmapper.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index b24d9377f8..3cc399f382 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -54,6 +54,9 @@ virDevMapperGetMajor(unsigned int *major) VIR_AUTOSTRINGLIST lines =3D NULL; size_t i; =20 + if (!virFileExists(CONTROL_PATH)) + return -2; + if (virFileReadAll(PROC_DEVICES, BUF_SIZE, &buf) < 0) return -1; =20 @@ -126,8 +129,13 @@ virDMOpen(void) =20 memset(&dm, 0, sizeof(dm)); =20 - if ((controlFD =3D open(CONTROL_PATH, O_RDWR)) < 0) + if ((controlFD =3D open(CONTROL_PATH, O_RDWR)) < 0) { + if (errno =3D=3D ENOENT) + return -2; + + virReportSystemError(errno, _("Unable to open %s"), CONTROL_PATH); return -1; + } =20 if (!virDMIoctl(controlFD, DM_VERSION, &dm, &tmp)) { virReportSystemError(errno, "%s", @@ -299,8 +307,16 @@ virDevMapperGetTargets(const char *path, * consist of devices or yet another targets. If that's the * case, we have to stop recursion somewhere. */ =20 - if ((controlFD =3D virDMOpen()) < 0) + if ((controlFD =3D virDMOpen()) < 0) { + if (controlFD =3D=3D -2) { + /* The CONTROL_PATH doesn't exist. Probably the + * module isn't loaded, yet. Don't error out, just + * exit. */ + return 0; + } + return -1; + } =20 return virDevMapperGetTargetsImpl(controlFD, path, devPaths, ttl); } --=20 2.26.2