From patchwork Thu Apr 7 23:20:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Marzinski X-Patchwork-Id: 8777961 X-Patchwork-Delegate: christophe.varoqui@free.fr 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 EE920C0553 for ; Thu, 7 Apr 2016 23:23:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0BC692025B for ; Thu, 7 Apr 2016 23:23:30 +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 EA6FC2020F for ; Thu, 7 Apr 2016 23:23:27 +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 u37NL2Vq030874; Thu, 7 Apr 2016 19:21:02 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id u37NKdfk028007 for ; Thu, 7 Apr 2016 19:20:39 -0400 Received: from redhat.com (octiron.msp.redhat.com [10.15.80.209]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u37NKbl3006993; Thu, 7 Apr 2016 19:20:38 -0400 Received: by redhat.com (sSMTP sendmail emulation); Thu, 07 Apr 2016 18:20:38 -0500 From: "Benjamin Marzinski" To: device-mapper development Date: Thu, 7 Apr 2016 18:20:09 -0500 Message-Id: <1460071212-21018-16-git-send-email-bmarzins@redhat.com> In-Reply-To: <1460071212-21018-1-git-send-email-bmarzins@redhat.com> References: <1460071212-21018-1-git-send-email-bmarzins@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-loop: dm-devel@redhat.com Cc: Christophe Varoqui Subject: [dm-devel] [PATCH v2 15/18] 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);