From patchwork Tue Mar 29 03:13:12 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 8681741 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 930299F44D for ; Tue, 29 Mar 2016 03:18:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B603820145 for ; Tue, 29 Mar 2016 03:18:14 +0000 (UTC) Received: from mx6-phx2.redhat.com (mx6-phx2.redhat.com [209.132.183.39]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A972E20142 for ; Tue, 29 Mar 2016 03:18:13 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2T3FnpT004856; Mon, 28 Mar 2016 23:15:49 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u2T3DfYK014427 for ; Mon, 28 Mar 2016 23:13:41 -0400 Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u2T3DdDF002280; Mon, 28 Mar 2016 23:13:40 -0400 Received: by redhat.com (sSMTP sendmail emulation); Mon, 28 Mar 2016 22:13:39 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Mon, 28 Mar 2016 22:13:12 -0500 Message-Id: <1459221194-23222-16-git-send-email-bmarzins@redhat.com> In-Reply-To: <1459221194-23222-1-git-send-email-bmarzins@redhat.com> References: <1459221194-23222-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH 15/17] multipath: check partitions unused before removing 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: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, 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 If kpartx partition devices are in-use, multipath will not be able to perform a non-deferred remove of the multipath device. So, before starting the remove, multipath should verify that none of the partition devices are currently in-use. Signed-off-by: Benjamin Marzinski --- libmultipath/devmapper.c | 46 ++++++++++++++++++++++++++++++++++++++-------- libmultipath/devmapper.h | 2 +- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/libmultipath/devmapper.c b/libmultipath/devmapper.c index cef8522..36c1a20 100644 --- a/libmultipath/devmapper.c +++ b/libmultipath/devmapper.c @@ -36,6 +36,10 @@ static int dm_cancel_remove_partmaps(const char * mapname); #endif +static int do_foreach_partmaps(const char * mapname, + int (*partmap_func)(const char *, void *), + void *data); + #ifndef LIBDM_API_COOKIE static inline int dm_task_set_cookie(struct dm_task *dmt, uint32_t *c, int a) { @@ -735,6 +739,26 @@ out: return r; } +static int +partmap_in_use(const char *name, void *data) +{ + int part_count, *ret_count = (int *)data; + int open_count = dm_get_opencount(name); + + if (ret_count) + (*ret_count)++; + part_count = 0; + if (open_count) { + if (do_foreach_partmaps(name, partmap_in_use, &part_count)) + return 1; + if (open_count != part_count) { + condlog(2, "%s: map in use", name); + return 1; + } + } + return 0; +} + extern int _dm_flush_map (const char * mapname, int need_sync, int deferred_remove) { @@ -743,6 +767,11 @@ _dm_flush_map (const char * mapname, int need_sync, int deferred_remove) if (!dm_is_mpath(mapname)) return 0; /* nothing to do */ + /* If you aren't doing a deferred remove, make sure that no + * devices are in use */ + if (!do_deferred(deferred_remove) && partmap_in_use(mapname, NULL)) + return 1; + if (dm_remove_partmaps(mapname, need_sync, deferred_remove)) return 1; @@ -851,7 +880,7 @@ dm_flush_maps (void) } int -dm_message(char * mapname, char * message) +dm_message(const char * mapname, char * message) { int r = 1; struct dm_task *dmt; @@ -1092,7 +1121,8 @@ bad: } static int -do_foreach_partmaps (const char * mapname, int (*partmap_func)(char *, void *), +do_foreach_partmaps (const char * mapname, + int (*partmap_func)(const char *, void *), void *data) { struct dm_task *dmt; @@ -1165,7 +1195,7 @@ struct remove_data { }; static int -remove_partmap(char *name, void *data) +remove_partmap(const char *name, void *data) { struct remove_data *rd = (struct remove_data *)data; @@ -1192,7 +1222,7 @@ dm_remove_partmaps (const char * mapname, int need_sync, int deferred_remove) #ifdef LIBDM_API_DEFERRED static int -cancel_remove_partmap (char *name, void *unused) +cancel_remove_partmap (const char *name, void *unused) { if (dm_get_opencount(name)) dm_cancel_remove_partmaps(name); @@ -1312,13 +1342,13 @@ out: } struct rename_data { - char *old; + const char *old; char *new; char *delim; }; static int -rename_partmap (char *name, void *data) +rename_partmap (const char *name, void *data) { char buff[PARAMS_SIZE]; int offset; @@ -1335,7 +1365,7 @@ rename_partmap (char *name, void *data) } int -dm_rename_partmaps (char * old, char * new) +dm_rename_partmaps (const char * old, char * new) { struct rename_data rd; @@ -1352,7 +1382,7 @@ dm_rename_partmaps (char * old, char * new) } int -dm_rename (char * old, char * new) +dm_rename (const char * old, char * new) { int r = 0; struct dm_task *dmt; diff --git a/libmultipath/devmapper.h b/libmultipath/devmapper.h index 1752045..0d27723 100644 --- a/libmultipath/devmapper.h +++ b/libmultipath/devmapper.h @@ -46,7 +46,7 @@ int dm_remove_partmaps (const char * mapname, int need_sync, int deferred_remove); int dm_get_uuid(char *name, char *uuid); int dm_get_info (char * mapname, struct dm_info ** dmi); -int dm_rename (char * old, char * new); +int dm_rename (const char * old, char * new); int dm_reassign(const char * mapname); int dm_reassign_table(const char *name, char *old, char *new); int dm_setgeometry(struct multipath *mpp);