From patchwork Wed Nov 21 10:18:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Wilck X-Patchwork-Id: 10692339 X-Patchwork-Delegate: christophe.varoqui@free.fr Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27E341709 for ; Wed, 21 Nov 2018 10:20:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14CDD2B4FD for ; Wed, 21 Nov 2018 10:20:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0923E2B89F; Wed, 21 Nov 2018 10:20:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4C8A02B4FD for ; Wed, 21 Nov 2018 10:20:03 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D180181F12; Wed, 21 Nov 2018 10:20:01 +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 766E1271A3; Wed, 21 Nov 2018 10:20:01 +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 1C774181B9EB; Wed, 21 Nov 2018 10:20:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id wALAJmeW014922 for ; Wed, 21 Nov 2018 05:19:48 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0563C7058A; Wed, 21 Nov 2018 10:19:48 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx18.extmail.prod.ext.phx2.redhat.com [10.5.110.47]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EE85570584; Wed, 21 Nov 2018 10:19:47 +0000 (UTC) Received: from smtp2.provo.novell.com (smtp2.provo.novell.com [137.65.250.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BA6E9307B960; Wed, 21 Nov 2018 10:19:46 +0000 (UTC) Received: from apollon.suse.de.de (prv-ext-foundry1int.gns.novell.com [137.65.251.240]) by smtp2.provo.novell.com with ESMTP (TLS encrypted); Wed, 21 Nov 2018 03:19:41 -0700 From: Martin Wilck To: Christophe Varoqui Date: Wed, 21 Nov 2018 11:18:36 +0100 Message-Id: <20181121101839.30784-17-mwilck@suse.com> In-Reply-To: <20181121101839.30784-1-mwilck@suse.com> References: <20181121101839.30784-1-mwilck@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 21 Nov 2018 10:19:47 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 21 Nov 2018 10:19:47 +0000 (UTC) for IP:'137.65.250.81' DOMAIN:'smtp2.provo.novell.com' HELO:'smtp2.provo.novell.com' FROM:'mwilck@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.301 (RCVD_IN_DNSWL_MED, SPF_PASS) 137.65.250.81 smtp2.provo.novell.com 137.65.250.81 smtp2.provo.novell.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.47 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, Martin Wilck Subject: [dm-devel] [PATCH 16/19] libmultipath: coalesce_paths: fix size mismatch handling X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 21 Nov 2018 10:20:03 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP When there are paths with the same WWID but different sizes, and coalesce_paths() walks the pathvec, it checks paths _after_ the current one for size mismatch and sets ACT_REJECT. However, these paths will be reached in the main loop later, and this time the already handled paths will not be checked for size mismatch; thus a map could be created, possibly even with mismatching devices. Fix that by tracking which paths were already discarded, and skipping them in the main loop later. Signed-off-by: Martin Wilck --- libmultipath/configure.c | 33 +++++++++++++++++++++++++-------- libmultipath/util.h | 16 ++++++++++++++++ 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/libmultipath/configure.c b/libmultipath/configure.c index 406cd4c9..4ed3cc23 100644 --- a/libmultipath/configure.c +++ b/libmultipath/configure.c @@ -1009,6 +1009,7 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid, vector pathvec = vecs->pathvec; struct config *conf; int allow_queueing; + uint64_t *size_mismatch_seen; /* ignore refwwid if it's empty */ if (refwwid && !strlen(refwwid)) @@ -1019,6 +1020,14 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid, pp1->mpp = NULL; } } + + if (VECTOR_SIZE(pathvec) == 0) + return 0; + size_mismatch_seen = calloc((VECTOR_SIZE(pathvec) - 1) / 64 + 1, + sizeof(uint64_t)); + if (size_mismatch_seen == NULL) + return 1; + vector_foreach_slot (pathvec, pp1, k) { int invalid; /* skip this path for some reason */ @@ -1038,8 +1047,8 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid, continue; } - /* 2. if path already coalesced */ - if (pp1->mpp) + /* 2. if path already coalesced, or seen and discarded */ + if (pp1->mpp || is_bit_set_in_array(k, size_mismatch_seen)) continue; /* 3. if path has disappeared */ @@ -1088,9 +1097,10 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid, * ouch, avoid feeding that to the DM */ condlog(0, "%s: size %llu, expected %llu. " - "Discard", pp2->dev_t, pp2->size, + "Discard", pp2->dev, pp2->size, mpp->size); mpp->action = ACT_REJECT; + set_bit_in_array(i, size_mismatch_seen); } } verify_paths(mpp, vecs); @@ -1119,8 +1129,10 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid, "ignoring" : "removing"); remove_map(mpp, vecs, 0); continue; - } else /* if (r == DOMAP_RETRY) */ - return r; + } else /* if (r == DOMAP_RETRY) */ { + r = 1; + goto out; + } } if (r == DOMAP_DRY) continue; @@ -1161,8 +1173,10 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid, if (newmp) { if (mpp->action != ACT_REJECT) { - if (!vector_alloc_slot(newmp)) - return 1; + if (!vector_alloc_slot(newmp)) { + r = 1; + goto out; + } vector_set_slot(newmp, mpp); } else @@ -1193,7 +1207,10 @@ int coalesce_paths (struct vectors * vecs, vector newmp, char * refwwid, condlog(2, "%s: remove (dead)", alias); } } - return 0; + r = 0; +out: + free(size_mismatch_seen); + return r; } struct udev_device *get_udev_device(const char *dev, enum devtypes dev_type) diff --git a/libmultipath/util.h b/libmultipath/util.h index a818e29a..1f13c913 100644 --- a/libmultipath/util.h +++ b/libmultipath/util.h @@ -3,6 +3,7 @@ #include #include +#include size_t strchop(char *); int basenamecpy (const char *src, char *dst, size_t size); @@ -39,4 +40,19 @@ struct scandir_result { }; void free_scandir_result(struct scandir_result *); +static inline bool is_bit_set_in_array(unsigned int bit, const uint64_t *arr) +{ + return arr[bit / 64] & (1ULL << (bit % 64)) ? 1 : 0; +} + +static inline void set_bit_in_array(unsigned int bit, uint64_t *arr) +{ + arr[bit / 64] |= (1ULL << (bit % 64)); +} + +static inline void clear_bit_in_array(unsigned int bit, uint64_t *arr) +{ + arr[bit / 64] &= ~(1ULL << (bit % 64)); +} + #endif /* _UTIL_H */