From: "Benjamin Marzinski" <bmarzins@redhat.com>
To: device-mapper development <dm-devel@redhat.com>
Cc: Christophe Varoqui <christophe.varoqui@gmail.com>
Subject: [PATCH v2 15/18] multipath: check partitions unused before removing
Date: Thu, 7 Apr 2016 18:20:09 -0500 [thread overview]
Message-ID: <1460071212-21018-16-git-send-email-bmarzins@redhat.com> (raw)
In-Reply-To: <1460071212-21018-1-git-send-email-bmarzins@redhat.com>
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 <bmarzins@redhat.com>
---
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);
--
1.8.3.1
next prev parent reply other threads:[~2016-04-07 23:20 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-07 23:19 [PATCH v2 00/18] Multipath patch sync Benjamin Marzinski
2016-04-07 23:19 ` [PATCH v2 01/18] multipathd: use /run instead of /var/run Benjamin Marzinski
2016-04-07 23:19 ` [PATCH v2 02/18] retrigger uevents to try and get the uid through udev Benjamin Marzinski
2016-04-07 23:19 ` [PATCH v2 03/18] Fix issues with user_friendly_names initramfs bindings Benjamin Marzinski
2016-04-07 23:19 ` [PATCH v2 04/18] Add libmpathcmd library and use it internally Benjamin Marzinski
2016-04-07 23:19 ` [PATCH v2 05/18] libmultipath: add ignore_new_boot_devs option Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 06/18] libmultipath: fix PAD and PRINT macros Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 07/18] libmultipath: Cut down on alua prioritizer ioctls Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 08/18] multipathd: fail if pidfile can't be created Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 09/18] libmultipath: check correct function for define Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 10/18] multipathd: delay reloads during creation Benjamin Marzinski
2016-04-08 8:36 ` Zdenek Kabelac
2016-04-08 21:53 ` Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 11/18] multipath: Fix minor text issues Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 12/18] kpartx: verify partition devices Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 13/18] multipath: add exclusive_pref_bit for alua prio Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 14/18] multipathd: print "fail" when remove fails Benjamin Marzinski
2016-04-07 23:20 ` Benjamin Marzinski [this message]
2016-04-07 23:20 ` [PATCH v2 16/18] multipathd.service: remove blk-availability Requires Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 17/18] multipathd: use 64-bit int for command key Benjamin Marzinski
2016-04-07 23:20 ` [PATCH v2 18/18] multipath: add wwn keyword to weightedpath prio Benjamin Marzinski
2016-04-18 9:36 ` [PATCH v2 00/18] Multipath patch sync Christophe Varoqui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1460071212-21018-16-git-send-email-bmarzins@redhat.com \
--to=bmarzins@redhat.com \
--cc=christophe.varoqui@gmail.com \
--cc=dm-devel@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).