From patchwork Thu Oct 8 19:44:51 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 7355171 X-Patchwork-Delegate: bmarzins@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2F93FBEEA4 for ; Thu, 8 Oct 2015 19:48:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 38E56207BC for ; Thu, 8 Oct 2015 19:48:10 +0000 (UTC) Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2F550207B9 for ; Thu, 8 Oct 2015 19:48:09 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t98JjXf3002063; Thu, 8 Oct 2015 15:45:33 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id t98JjSH7005915 for ; Thu, 8 Oct 2015 15:45:28 -0400 Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t98JjQrN010887; Thu, 8 Oct 2015 15:45:27 -0400 Received: by redhat.com (sSMTP sendmail emulation); Thu, 08 Oct 2015 14:45:26 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Thu, 8 Oct 2015 14:44:51 -0500 Message-Id: <1444333491-16265-19-git-send-email-bmarzins@redhat.com> In-Reply-To: <1444333491-16265-1-git-send-email-bmarzins@redhat.com> References: <1444333491-16265-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH 18/18] Make multipath ignore devices without mpath prefix X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Multpathd currently assumes that it controls all devices of "multipath" type. In order to allow people to create multipath type devices outside of the multipath-tools, this patch makes multipathd only modify devices if they have a uuid that starts with "mpath-". This was a suggestion from Hannes a couple of months ago. Signed-off-by: Benjamin Marzinski Reviewed-by: Hannes Reinecke --- libmpathpersist/mpath_persist.c | 4 +-- libmultipath/devmapper.c | 67 ++++++++++++++++++++++++++++++----------- libmultipath/devmapper.h | 1 + multipathd/main.c | 2 +- 4 files changed, 53 insertions(+), 21 deletions(-) diff --git a/libmpathpersist/mpath_persist.c b/libmpathpersist/mpath_persist.c index eba26a2..113cf7f 100644 --- a/libmpathpersist/mpath_persist.c +++ b/libmpathpersist/mpath_persist.c @@ -168,7 +168,7 @@ int mpath_persistent_reserve_in (int fd, int rq_servact, condlog(3, "alias = %s", alias); map_present = dm_map_present(alias); - if (map_present && dm_type(alias, TGT_MPATH) <= 0){ + if (map_present && !dm_is_mpath(alias)){ condlog( 0, "%s: not a multipath device.", alias); ret = MPATH_PR_DMMP_ERROR; goto out; @@ -258,7 +258,7 @@ int mpath_persistent_reserve_out ( int fd, int rq_servact, int rq_scope, condlog(3, "alias = %s", alias); map_present = dm_map_present(alias); - if (map_present && dm_type(alias, TGT_MPATH) <= 0){ + if (map_present && !dm_is_mpath(alias)){ condlog(3, "%s: not a multipath device.", alias); ret = MPATH_PR_DMMP_ERROR; goto out; diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index 560d418..cef8522 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -581,6 +581,48 @@ out: return r; } +extern int +dm_is_mpath(const char * name) +{ + int r = 0; + struct dm_task *dmt; + struct dm_info info; + uint64_t start, length; + char *target_type = NULL; + char *params; + const char *uuid; + + if (!(dmt = dm_task_create(DM_DEVICE_TABLE))) + return 0; + + if (!dm_task_set_name(dmt, name)) + goto out; + + dm_task_no_open_count(dmt); + + if (!dm_task_run(dmt)) + goto out; + + if (!dm_task_get_info(dmt, &info) || !info.exists) + goto out; + + uuid = dm_task_get_uuid(dmt); + + if (!uuid || strncmp(uuid, UUID_PREFIX, UUID_PREFIX_LEN) != 0) + goto out; + + /* Fetch 1st target */ + dm_get_next_target(dmt, NULL, &start, &length, &target_type, ¶ms); + + if (!target_type || strcmp(target_type, TGT_MPATH) != 0) + goto out; + + r = 1; +out: + dm_task_destroy(dmt); + return r; +} + static int dm_dev_t (const char * mapname, char * dev_t, int len) { @@ -698,10 +740,7 @@ _dm_flush_map (const char * mapname, int need_sync, int deferred_remove) { int r; - if (!dm_map_present(mapname)) - return 0; - - if (dm_type(mapname, TGT_MPATH) <= 0) + if (!dm_is_mpath(mapname)) return 0; /* nothing to do */ if (dm_remove_partmaps(mapname, need_sync, deferred_remove)) @@ -751,10 +790,7 @@ dm_suspend_and_flush_map (const char * mapname) unsigned long long mapsize; char params[PARAMS_SIZE] = {0}; - if (!dm_map_present(mapname)) - return 0; - - if (dm_type(mapname, TGT_MPATH) <= 0) + if (!dm_is_mpath(mapname)) return 0; /* nothing to do */ if (!dm_get_map(mapname, &mapsize, params)) { @@ -915,7 +951,6 @@ dm_get_maps (vector mp) { struct multipath * mpp; int r = 1; - int info; struct dm_task *dmt; struct dm_names *names; unsigned next = 0; @@ -940,9 +975,7 @@ dm_get_maps (vector mp) } do { - info = dm_type(names->name, TGT_MPATH); - - if (info <= 0) + if (!dm_is_mpath(names->name)) goto next; mpp = alloc_multipath(); @@ -955,13 +988,11 @@ dm_get_maps (vector mp) if (!mpp->alias) goto out1; - if (info > 0) { - if (dm_get_map(names->name, &mpp->size, NULL)) - goto out1; + if (dm_get_map(names->name, &mpp->size, NULL)) + goto out1; - dm_get_uuid(names->name, mpp->wwid); - dm_get_info(names->name, &mpp->dmi); - } + dm_get_uuid(names->name, mpp->wwid); + dm_get_info(names->name, &mpp->dmi); if (!vector_alloc_slot(mp)) goto out1; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 2613503..1752045 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -23,6 +23,7 @@ int dm_map_present (const char *); int dm_get_map(const char *, unsigned long long *, char *); int dm_get_status(char *, char *); int dm_type(const char *, char *); +int dm_is_mpath(const char *); int _dm_flush_map (const char *, int, int); int dm_flush_map_nopaths(const char * mapname, int deferred_remove); #define dm_flush_map(mapname) _dm_flush_map(mapname, 1, 0) diff --git a/multipathd/main.c b/multipathd/main.c index 6c315ad..14afe0c 100644 --- a/multipathd/main.c +++ b/multipathd/main.c @@ -295,7 +295,7 @@ ev_add_map (char * dev, char * alias, struct vectors * vecs) map_present = dm_map_present(alias); - if (map_present && dm_type(alias, TGT_MPATH) <= 0) { + if (map_present && !dm_is_mpath(alias)) { condlog(4, "%s: not a multipath map", alias); return 0; }