From nobody Fri May 3 14:13:53 2024 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 Tested-by: Christian Ehrhardt --- 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 From nobody Fri May 3 14:13:53 2024 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-delivery-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=1597674504; cv=none; d=zohomail.com; s=zohoarc; b=kTGK/1XncmMGfBvVdmvnPRPf+v2OR4XYjAnrVgdJ0T5Ahh5IX/44wCh3RqMzNij77IS4XUSOG0phdjiBej9LYdcqD6tURwVZuyqvaQ7kOjZipNOld/vhCyPM1rS1S7JerSAA441IF8EN/rXPh9QR5fOUuTmpStYQoe1m2UQV0eE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597674504; 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=W2dXyAPbospXjWH5ZHjdba4r26SlvmJltz+ZIxE/PFk=; b=iw7l0Sm/I2q6o1LQOwgJisLEhv1EV7X7eX79aKtaT+yYQH2KftIYsY1S4ods2S3ncgf//mc4K2T9A6swCLyhWGmePFWt7B+DOIKF3Fc3mv1TMA8ZJPvgX/NK0mT9EtcYm0ppjho5wrD/pRYm6ye1goCzB+AVCZ8jbAx0iBmpv5k= 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-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1597674504618254.99649198377517; Mon, 17 Aug 2020 07:28:24 -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-216-qFO2p7V4MHKXInIJ6nlrNw-1; Mon, 17 Aug 2020 10:27:13 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C96EF81F005; Mon, 17 Aug 2020 14:27:07 +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 A8F875C644; Mon, 17 Aug 2020 14:27:07 +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 526E24EE20; Mon, 17 Aug 2020 14:27:07 +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 07HER54F025307 for ; Mon, 17 Aug 2020 10:27:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id D88C35D98D; Mon, 17 Aug 2020 14:27:05 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.99]) by smtp.corp.redhat.com (Postfix) with ESMTP id 58B385D9E2 for ; Mon, 17 Aug 2020 14:27:03 +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=W2dXyAPbospXjWH5ZHjdba4r26SlvmJltz+ZIxE/PFk=; b=cPAEGhnkyr8MivGh2GLyN8MXiGBaWDvEJpSG0z5LYm/JlB0hLJ30XGtzkih86vLxcWFpvg W8QFc1lXfBOpBstd4RPhsYCv+GK0T51Ef/VeK806bOL5GBtfzDeWSPW+mnLvtxa43yBmwQ Y2to9Y9Fb491WDhakC0rzUsHB5NfSRw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597674460; 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=W2dXyAPbospXjWH5ZHjdba4r26SlvmJltz+ZIxE/PFk=; b=XzZXXoVSNpAD/sUlozpvOCjz6nK9n25fQMdqT65M94V7duoq3+AzCFi3QNfEm4EK66REPw axRMY3fpnY/QLEytxWmU6zPH6QYmf16SJhPuPllmrG4B21COvF3dwbp5+alUuBzgVNPtBd jwZJZSPxH4AGWkEMXTxtJg57M2kKGd4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1597674503; 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=W2dXyAPbospXjWH5ZHjdba4r26SlvmJltz+ZIxE/PFk=; b=bLJBv6DcdTZssFuiNa35a3IfZ1pY8c33DL+ppmIoGxD7bLyQjNz9ix6osTedUeus1dPJ3J iUxLU6oetW3j8wIs2A1rQfoh9PRbc2KxoY4XycKdLmWsCES+k0Mti24EpZM8+xRIUNSrMe SUPvAlNJTzGpxQ9Ijarn1k29Jmg6d7c= X-MC-Unique: qFO2p7V4MHKXInIJ6nlrNw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] virdevmapper: Deal with unloading dm module Date: Mon, 17 Aug 2020 16:26:55 +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.79 on 10.5.11.16 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) (identity @redhat.com) (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The following situation can happen: we've initialized DM major successfully. But later, the devmapper module(s) was removed and thus kernel lost its ability to handle multipath devices. More importantly, the /dev/mapper/control file is removed and thus our attempt to open it will fail. Note, we will attempt to open it only after we've found devmapper major number successfully in one of the previous runs. Anyway, if it so happens that the module was unloaded then we have to reset the major number we remembered from one of the previous runs and not report error. Fixes: 22494556542c676d1b9e7f1c1f2ea13ac17e1e3e Reported-by: Andrea Bolognani Signed-off-by: Michal Privoznik Tested-by: Christian Ehrhardt --- src/util/virdevmapper.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index cc33d8211e..642f1d9bdb 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -143,8 +143,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", @@ -328,8 +333,17 @@ virDevMapperGetTargets(const char *path, return -1; } =20 - if ((controlFD =3D virDMOpen()) < 0) + if ((controlFD =3D virDMOpen()) < 0) { + if (controlFD =3D=3D -2) { + /* Devmapper was available but now it isn't. Somebody + * must have removed the module. Reset the major + * number we remember. */ + virDMMajor =3D 0; + return 0; + } + return -1; + } =20 return virDevMapperGetTargetsImpl(controlFD, path, devPaths, ttl); } --=20 2.26.2