From nobody Sun Feb 8 19:59:38 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; 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.61 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=1597674438; cv=none; d=zohomail.com; s=zohoarc; b=CLiYpJ92DIsI6Y0TeI4U5Q86IGYo9vDUbTmYxh1kpA8lIPJjXAc273+l/pQqT2dh1tmUyfkPvKqF5oMliuw8TGqYax0kGqMFEnfLTEZzIsLnRmneSNj+fGUNzcOVbMp8LuV1feIHtOm8aNXzyXVyMNcEB4RdM2Br8MM8P3LeoWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597674438; 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=iO5uZi1fgWFo9Y96LYuApSZ+9dTB2QSiGXZmm4XRt1M=; b=SJR4XaQGGMaDh2LBe1p1watWwpBad3FDPp+s9kaDG2yzUhew28mLt3NX9a6mGQILr97tBaEEbPAtGUjtBOKsARFKt5OMJsR1dUKRAH7aExdHOlDBKW7Wo1tiSplB/2PaYyXt+ucLTxEzYXlvSh90AOQ+KQBuvbK7Gsv82Cfq2kw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1597674438178223.92463061639796; Mon, 17 Aug 2020 07:27:18 -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-8-mqlx7N1aM16V_P6NLel2cw-1; Mon, 17 Aug 2020 10:27:12 -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 F1C6C807338; Mon, 17 Aug 2020 14:27:06 +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 D11E75D6C4; Mon, 17 Aug 2020 14:27:06 +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 7268E181A06B; Mon, 17 Aug 2020 14:27:05 +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 07HER3P9025291 for ; Mon, 17 Aug 2020 10:27:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0E60E5D98D; Mon, 17 Aug 2020 14:27:03 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82FB45D9E2 for ; Mon, 17 Aug 2020 14:27:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597674435; 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=iO5uZi1fgWFo9Y96LYuApSZ+9dTB2QSiGXZmm4XRt1M=; b=R8Ocm78qgkG84U8IUMiW7iCF9o3jJDxyHXWrhnJg7BONKcoKpdOhTeZScjIX6dGWO9nuKu afm599VCNb69+fL+7I6VS2UzdpEnzpJWCU+xq1FXe6oUJIqYypQXggcSp9sTKs9tMVvd0d 1N8JFpD+X7JHv4EmP/WBNcprjFBZL3w= X-MC-Unique: mqlx7N1aM16V_P6NLel2cw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] virdevmapper: Don't error on kernels without DM support Date: Mon, 17 Aug 2020 16:26:54 +0200 Message-Id: <8ea97d64d41f7eed6309b26e9291554cd114a614.1597674163.git.mprivozn@redhat.com> 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.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.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 Signed-off-by: Michal Privoznik --- src/util/virdevmapper.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index fe7f611496..cc33d8211e 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -47,10 +47,11 @@ G_STATIC_ASSERT(BUF_SIZE > sizeof(struct dm_ioctl)); =20 static unsigned int virDMMajor; +static virMutex virDevMapperInitMutex =3D VIR_MUTEX_INITIALIZER; =20 =20 static int -virDevMapperOnceInit(void) +virDevMapperGetMajor(unsigned int *dmmaj) { g_autofree char *buf =3D NULL; VIR_AUTOSTRINGLIST lines =3D NULL; @@ -69,23 +70,34 @@ virDevMapperOnceInit(void) =20 if (sscanf(lines[i], "%u %ms\n", &maj, &dev) =3D=3D 2 && STREQ(dev, DM_NAME)) { - virDMMajor =3D maj; + *dmmaj =3D maj; break; } } =20 if (!lines[i]) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Unable to find major for %s"), - DM_NAME); - return -1; + /* Don't error here. Maybe the kernel was built without + * devmapper. Let the caller decide. */ + return -2; } =20 return 0; } =20 =20 -VIR_ONCE_GLOBAL_INIT(virDevMapper); +static int +virDevMapperInit(void) +{ + int rc =3D 0; + + virMutexLock(&virDevMapperInitMutex); + + if (virDMMajor =3D=3D 0) + rc =3D virDevMapperGetMajor(&virDMMajor); + + virMutexUnlock(&virDevMapperInitMutex); + return rc; +} =20 =20 static void * @@ -220,7 +232,6 @@ virDevMapperGetTargetsImpl(int controlFD, size_t i; =20 memset(&dm, 0, sizeof(dm)); - *devPaths_ret =3D NULL; =20 if (ttl =3D=3D 0) { errno =3D ELOOP; @@ -298,14 +309,24 @@ virDevMapperGetTargets(const char *path, char ***devPaths) { VIR_AUTOCLOSE controlFD =3D -1; + int rc; const unsigned int ttl =3D 32; =20 /* Arbitrary limit on recursion level. A devmapper target can * consist of devices or yet another targets. If that's the * case, we have to stop recursion somewhere. */ =20 - if (virDevMapperInitialize() < 0) + *devPaths =3D NULL; + + if ((rc =3D virDevMapperInit()) < 0) { + if (rc =3D=3D -2) { + /* Devmapper is not available. Yet. Maybe the module + * will be loaded later, but do not error out for now. */ + return 0; + } + return -1; + } =20 if ((controlFD =3D virDMOpen()) < 0) return -1; @@ -319,7 +340,7 @@ virIsDevMapperDevice(const char *dev_name) { struct stat buf; =20 - if (virDevMapperInitialize() < 0) + if (virDevMapperInit() < 0) return false; =20 if (!stat(dev_name, &buf) && --=20 2.26.2