From nobody Mon Apr 29 09:50:42 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=1591875933; cv=none; d=zohomail.com; s=zohoarc; b=cCW/c/BqMJLFSlCJ1brc0dO0vo9YfiutFz2Leu0FqyPqPBRFfQMzcoGkfRB0RNG5+J7iIeuxTMnTSzlytUKh2tkiwQaUfv2nSFIpaaTbt2dSxm3PQ6F2SpaN+faHk/JApS4nvF/SXhKVVXNTPkvl5povsG+CuDDIQynUZIh2syA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591875933; 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=u3hAT6q9BJkDKHxtp+jNZGrjCnIm6ZvA0tjAZxF5S84=; b=SRUl01NeDK/zqbdIl8ITmNXKsEGO93qBiAzENIADswtw/JlxAWOsAPG08HnkHnt17hdMLusJ7eiy/djsH6kkVUpCSJncvBZOI598YESXdAyVi+zfdfBg6n/5cVzxKmWUUXfPChsTBB4KFk7f1ajO6tSq4XQzDranrFHWZhX2kzA= 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 1591875933023626.5069646043099; Thu, 11 Jun 2020 04:45:33 -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-254-YlhzOlj8PV-jCgTuWy31bw-1; Thu, 11 Jun 2020 07:45:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1584F8018AD; Thu, 11 Jun 2020 11:45:23 +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 9CA57891E2; Thu, 11 Jun 2020 11:45:22 +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 839A0104809; Thu, 11 Jun 2020 11:45:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05BBjH3s013558 for ; Thu, 11 Jun 2020 07:45:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1C1419CA0; Thu, 11 Jun 2020 11:45:17 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 917847F4FE for ; Thu, 11 Jun 2020 11:45:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591875931; 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=u3hAT6q9BJkDKHxtp+jNZGrjCnIm6ZvA0tjAZxF5S84=; b=QeSNXuSZ9EkybFK7uU4D62fvjkR0+dodbR+XqcwyNtYZPUnqgDWZdvDJ20kRmU6cOX0dbu 1NecOuccbIZU/W1vzOVl2wXmhsaDD90LQhdAR7b0GIuUvKU7C0rH+xH/nm27vkdg5YPoOb F7InucJg7RQyML+NsPC5+ElhuTLJ9Lw= X-MC-Unique: YlhzOlj8PV-jCgTuWy31bw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/2] util: Move virIsDevMapperDevice() to virdevmapper.c Date: Thu, 11 Jun 2020 13:44:47 +0200 Message-Id: <13f611fdc0f1d1d4bc4505001149babc369d7c53.1591875846.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.13 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" When introducing virdevmapper.c (in v4.3.0-rc1~427) I didn't realize there is a function that calls in devmapper. The function is called virIsDevMapperDevice() and lives in virutil.c. Now that we have a special file for handling devmapper move it there. Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- src/libvirt_private.syms | 2 +- src/storage/parthelper.c | 2 +- src/storage/storage_backend_disk.c | 1 + src/util/virdevmapper.c | 24 ++++++++++++++++++++++++ src/util/virdevmapper.h | 3 +++ src/util/virutil.c | 24 ------------------------ src/util/virutil.h | 2 -- 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index a6af44fe1c..247d7f4741 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1943,6 +1943,7 @@ virDBusSetSharedBus; =20 # util/virdevmapper.h virDevMapperGetTargets; +virIsDevMapperDevice; =20 =20 # util/virdnsmasq.h @@ -3432,7 +3433,6 @@ virGetUserShell; virHostGetDRMRenderNode; virHostHasIOMMU; virIndexToDiskName; -virIsDevMapperDevice; virMemoryLimitIsSet; virMemoryLimitTruncate; virMemoryMaxValue; diff --git a/src/storage/parthelper.c b/src/storage/parthelper.c index 761a7f93fc..812e90d3cb 100644 --- a/src/storage/parthelper.c +++ b/src/storage/parthelper.c @@ -36,10 +36,10 @@ #include #include =20 -#include "virutil.h" #include "virfile.h" #include "virstring.h" #include "virgettext.h" +#include "virdevmapper.h" =20 /* we don't need to include the full internal.h just for this */ #define STREQ(a, b) (strcmp(a, b) =3D=3D 0) diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backe= nd_disk.c index 35b07abbfe..eae23ec24a 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -32,6 +32,7 @@ #include "virutil.h" #include "configmake.h" #include "virstring.h" +#include "virdevmapper.h" =20 #define VIR_FROM_THIS VIR_FROM_STORAGE =20 diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 79dbc3d02a..600e1f6322 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -212,3 +212,27 @@ virDevMapperGetTargets(const char *path G_GNUC_UNUSED, return -1; } #endif /* ! WITH_DEVMAPPER */ + + +#if WITH_DEVMAPPER +bool +virIsDevMapperDevice(const char *dev_name) +{ + struct stat buf; + + if (!stat(dev_name, &buf) && + S_ISBLK(buf.st_mode) && + dm_is_dm_major(major(buf.st_rdev))) + return true; + + return false; +} + +#else /* ! WITH_DEVMAPPER */ + +bool +virIsDevMapperDevice(const char *dev_name G_GNUC_UNUSED) +{ + return false; +} +#endif /* ! WITH_DEVMAPPER */ diff --git a/src/util/virdevmapper.h b/src/util/virdevmapper.h index 87bbc63cfd..834900692e 100644 --- a/src/util/virdevmapper.h +++ b/src/util/virdevmapper.h @@ -25,3 +25,6 @@ int virDevMapperGetTargets(const char *path, char ***devPaths) G_GNUC_NO_INLINE; + +bool +virIsDevMapperDevice(const char *dev_name) ATTRIBUTE_NONNULL(1); diff --git a/src/util/virutil.c b/src/util/virutil.c index fb46501142..929afb82d0 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -37,10 +37,6 @@ =20 #include =20 -#if WITH_DEVMAPPER -# include -#endif - #ifdef HAVE_GETPWUID_R # include # include @@ -1340,26 +1336,6 @@ void virWaitForDevices(void) ignore_value(virCommandRun(cmd, &exitstatus)); } =20 -#if WITH_DEVMAPPER -bool -virIsDevMapperDevice(const char *dev_name) -{ - struct stat buf; - - if (!stat(dev_name, &buf) && - S_ISBLK(buf.st_mode) && - dm_is_dm_major(major(buf.st_rdev))) - return true; - - return false; -} -#else -bool virIsDevMapperDevice(const char *dev_name G_GNUC_UNUSED) -{ - return false; -} -#endif - bool virValidateWWN(const char *wwn) { diff --git a/src/util/virutil.h b/src/util/virutil.h index 49b4bf440f..ef01fd9e36 100644 --- a/src/util/virutil.h +++ b/src/util/virutil.h @@ -114,8 +114,6 @@ bool virDoesUserExist(const char *name); bool virDoesGroupExist(const char *name); =20 =20 -bool virIsDevMapperDevice(const char *dev_name) ATTRIBUTE_NONNULL(1); - bool virValidateWWN(const char *wwn); =20 int virGetDeviceID(const char *path, --=20 2.26.2 From nobody Mon Apr 29 09:50:42 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.120 as permitted sender) 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=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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=1591875948; cv=none; d=zohomail.com; s=zohoarc; b=dZ9p/sAd0HJxVfnzpm8+Zrc8Z0Q18yP6SOcMLlfnWn2g+WAEThszIXwmLaLIvakvbpTDp+W2l3vhFl96rDgls+BJpZMUqq58cwt9QQPb9MiVutE9pxd84V1UqQCl4d7oer2DYek77FMk6qkSJcNVa8xYelnqGQlCo5+5CGlXgbY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591875948; 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=mQe+81cbSBkPKW6HILFGeGw1GXJZbyK7KNKP0d5MNHs=; b=PHlNVfTqg3eSSzvU0vUrAKOcx+2DBrKFCwvXmYRadavwh0yfZIjGIZid6kC2LnzPdWhIfUhOWB/sLHGInvNW4RtRx0p8ZDgrekm6rmkqkfA5yPaNf6OVqJJLQgradimVxDDyRgFbN8t8Nq+V5/IDI8i5GaWhJdFB8VN0rBt/F04= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.120 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-delivery-1.mimecast.com [207.211.31.120]) by mx.zohomail.com with SMTPS id 1591875948321311.9401597595205; Thu, 11 Jun 2020 04:45:48 -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-9-h5NmMgAzOqK-vd8Mrdr6Uw-1; Thu, 11 Jun 2020 07:45:44 -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 644E9193F561; Thu, 11 Jun 2020 11:45:39 +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 4214F60BF4; Thu, 11 Jun 2020 11:45:39 +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 1241F10480C; Thu, 11 Jun 2020 11:45:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 05BBjH4X013564 for ; Thu, 11 Jun 2020 07:45:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id EDD0A512FE; Thu, 11 Jun 2020 11:45:17 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.193.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EFDC9CA0 for ; Thu, 11 Jun 2020 11:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591875947; 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=mQe+81cbSBkPKW6HILFGeGw1GXJZbyK7KNKP0d5MNHs=; b=SYBfIADiViqXYherZfFw81dfzOLS6DJ+eKchGBn2wk/b8aWTQHZ+gE+FK8apat3ShVYU89 sV7STYPf/nM/K3MrIehIYrG9XZ4XGEMGbN+O63+y0rTH3Ug/lSy4Ki8RThkUiCojJiuzD8 abMSkew5B+3IBDnMzaeb7lle14SquKk= X-MC-Unique: h5NmMgAzOqK-vd8Mrdr6Uw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/2] virDevMapperGetTargetsImpl: Check for dm major properly Date: Thu, 11 Jun 2020 13:44:48 +0200 Message-Id: <73faec9f055848df4b370d31ca97b63ef831e610.1591875846.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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 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" In v6.4.0-rc1~143 I've introduced a check that is supposed to return from the function early, if given path is not a dm target. While the idea is still valid, the implementation had a flaw. It calls stat() over given path and the uses major(sb.st_dev) to learn the major of the device. This is then passed to dm_is_dm_major() which returns true or false depending whether the device is under devmapper's control or not. The problem with this approach is in how the major of the device is obtained - paths managed by devmapper are special files and thus we want to be using st_rdev instead of st_dev to obtain the major number. Well, that's what virIsDevMapperDevice() does already so might as well us that. Fixes: 01626c668ecfbe465d18799ac4628e6127ea1d47 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=3D1839992 Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- src/util/virdevmapper.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c index 600e1f6322..40a82285f9 100644 --- a/src/util/virdevmapper.c +++ b/src/util/virdevmapper.c @@ -64,7 +64,6 @@ virDevMapperGetTargetsImpl(const char *path, char ***devPaths_ret, unsigned int ttl) { - struct stat sb; struct dm_task *dmt =3D NULL; struct dm_deps *deps; struct dm_info info; @@ -83,13 +82,7 @@ virDevMapperGetTargetsImpl(const char *path, return ret; } =20 - if (stat(path, &sb) < 0) { - if (errno =3D=3D ENOENT) - return 0; - return -1; - } - - if (!dm_is_dm_major(major(sb.st_dev))) + if (!virIsDevMapperDevice(path)) return 0; =20 if (!(dmt =3D dm_task_create(DM_DEVICE_DEPS))) { --=20 2.26.2