From nobody Tue Dec 16 08:58:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 152204145606839.85958543122638; Sun, 25 Mar 2018 22:17:36 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id CB87BC057F92; Mon, 26 Mar 2018 05:17:34 +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 98DBD18B26; Mon, 26 Mar 2018 05:17:34 +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 6364D4CA9D; Mon, 26 Mar 2018 05:17:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2Q5H93S027623 for ; Mon, 26 Mar 2018 01:17:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1CA19200BC7C; Mon, 26 Mar 2018 05:17:09 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-33.brq.redhat.com [10.40.204.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id A4467200BC87 for ; Mon, 26 Mar 2018 05:17:08 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 26 Mar 2018 07:16:43 +0200 Message-Id: <89296884c9f600f3f4c925163b3faa40a4a57a7d.1522041162.git.mprivozn@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] utils: Introduce virFileGetMPathTargets 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 26 Mar 2018 05:17:35 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This helper fetches targets for multipath devices. Signed-off-by: Michal Privoznik --- src/libvirt_private.syms | 1 + src/util/virfile.c | 90 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virfile.h | 4 +++ 3 files changed, 95 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 03fe3b315f..1bbff72263 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1773,6 +1773,7 @@ virFileGetACLs; virFileGetHugepageSize; virFileGetMountReverseSubtree; virFileGetMountSubtree; +virFileGetMPathTargets; virFileHasSuffix; virFileInData; virFileIsAbsPath; diff --git a/src/util/virfile.c b/src/util/virfile.c index 5e9bd2007a..f89e4bd823 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -64,6 +64,10 @@ # include #endif =20 +#ifdef WITH_DEVMAPPER +# include +#endif + #include "configmake.h" #include "intprops.h" #include "viralloc.h" @@ -4227,3 +4231,89 @@ virFileWaitForExists(const char *path, =20 return 0; } + + +#ifdef WITH_DEVMAPPER +/** + * virFileGetMPathTargets: + * @path: multipath device + * @devs: returned array of st_rdevs of @path targets + * @ndevs: size of @devs and @devNames + * + * For given @path figure out its targets, and store them in + * @devs. Items from @devs are meant to be used in + * minor() and major() to receive device MAJ:MIN pairs. + * + * If @path is not a multipath device, @ndevs is set to 0 and + * success is returned. + * + * If we don't have permissions to talk to kernel, -1 is returned + * and errno is set to EBADF. + * + * Returns 0 on success, -1 otherwise. + */ +int +virFileGetMPathTargets(const char *path, + unsigned long long **devs, + size_t *ndevs) +{ + struct dm_deps *deps; + struct dm_task *dmt; + struct dm_info info; + size_t i; + int ret =3D -1; + + *ndevs =3D 0; + + if (!(dmt =3D dm_task_create(DM_DEVICE_DEPS))) + goto cleanup; + + if (!dm_task_set_name(dmt, path)) { + if (errno =3D=3D ENOENT) { + /* It's okay, @path is not managed by devmapper =3D> + * not a multipath device. */ + ret =3D 0; + } + goto cleanup; + } + + dm_task_no_open_count(dmt); + + if (!dm_task_run(dmt)) + goto cleanup; + + if (!dm_task_get_info(dmt, &info)) + goto cleanup; + + if (!info.exists) { + ret =3D 0; + goto cleanup; + } + + if (!(deps =3D dm_task_get_deps(dmt))) + goto cleanup; + + if (VIR_ALLOC_N(*devs, deps->count) < 0) + goto cleanup; + *ndevs =3D deps->count; + + for (i =3D 0; i < deps->count; i++) + (*devs)[i] =3D deps->device[i]; + + ret =3D 0; + cleanup: + dm_task_destroy(dmt); + return ret; +} + +#else /* ! WITH_DEVMAPPER */ + +int +virFileGetMPathTargets(const char *path ATTRIBUTE_UNUSED, + unsigned long long **devs ATTRIBUTE_UNUSED, + size_t *ndevs ATTRIBUTE_UNUSED) +{ + errno =3D ENOSYS; + return -1; +} +#endif /* ! WITH_DEVMAPPER */ diff --git a/src/util/virfile.h b/src/util/virfile.h index cd2a3867c2..0db8bf0b99 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -358,4 +358,8 @@ int virFileInData(int fd, int *inData, long long *length); =20 +int virFileGetMPathTargets(const char *path, + unsigned long long **devs, + size_t *ndevs); + #endif /* __VIR_FILE_H */ --=20 2.16.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list