Skip to contentSkip to conversation

Fix return code of info callbacks.

PATCH New Milan Broz 1 participant 6 messages Jan 23, 2010

lore
Share & tools
lore

Milan Broz

author
#0 lore raw

PATCH 1/6 Fix return code of info callbacks.

In dev_manager_info 0 means error and 1 info is returned, not that device exist (that value is part of info struct).

Fix query by uuid only (no name) which returns 0 when device do not exist.

---
 lib/activate/dev_manager.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
lib/activate/dev_manager.c +7 -5
index 25b7a10..6023574 100644
@@ -209,14 +209,16 @@ static int _info(const char *name, const char *dlid, int mknodes,
 		 int with_open_count, int with_read_ahead,
 		 struct dm_info *info, uint32_t *read_ahead)
 {
+	int r = 0;
+
 	if (!mknodes && dlid && *dlid) {
-		if (_info_run(NULL, dlid, info, read_ahead, 0, with_open_count,
-			      with_read_ahead, 0, 0) &&
+		if ((r = _info_run(NULL, dlid, info, read_ahead, 0, with_open_count,
+			      with_read_ahead, 0, 0)) &&
 	    	    info->exists)
 			return 1;
-		else if (_info_run(NULL, dlid + sizeof(UUID_PREFIX) - 1, info,
+		else if ((r = _info_run(NULL, dlid + sizeof(UUID_PREFIX) - 1, info,
 				   read_ahead, 0, with_open_count,
-				   with_read_ahead, 0, 0) &&
+				   with_read_ahead, 0, 0)) &&
 			 info->exists)
 			return 1;
 	}
@@ -225,7 +227,7 @@ static int _info(const char *name, const char *dlid, int mknodes,
 		return _info_run(name, NULL, info, read_ahead, mknodes,
 				 with_open_count, with_read_ahead, 0, 0);
 
-	return 0;
+	return r;
 }
 
 static int _info_by_dev(uint32_t major, uint32_t minor, struct dm_info *info)
Signature · 1 line
1.6.6
author
#1 lore raw

PATCH 2/6 Always query device by using uuid only and not name.

Otherwise confusion with the device of the same name (but different UUID, e.g. non-lvm device) can happen.

---
 lib/activate/activate.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
lib/activate/activate.c +1 -1
index f18ecf9..433c8cc 100644
@@ -492,7 +492,7 @@ int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
 	if (!(lv = lv_from_lvid(cmd, lvid_s, 0)))
 		return 0;
 
-	r = _lv_info(cmd, lv, 0, info, with_open_count, with_read_ahead, 0);
+	r = _lv_info(cmd, lv, 0, info, with_open_count, with_read_ahead, 1);
 	vg_release(lv->vg);
 
 	return r;
Signature · 1 line
1.6.6
author
#2 lore raw

PATCH 3/6 Unlock shared lock if activation calls failed.

In reply to Milan Broz

Clvmd should unlock new lock if activation in device-mapper fails.

---
 daemons/clvmd/lvm-functions.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
daemons/clvmd/lvm-functions.c +8 -3
index 74c660e..02d401b 100644
@@ -373,17 +373,22 @@ static int do_activate_lv(char *resource, unsigned char lock_flags, int mode)
 
 	/* If it's suspended then resume it */
 	if (!lv_info_by_lvid(cmd, resource, &lvi, 0, 0))
-		return EIO;
+		goto error;
 
 	if (lvi.suspended)
 		if (!lv_resume(cmd, resource))
-			return EIO;
+			goto error;
 
 	/* Now activate it */
 	if (!lv_activate(cmd, resource, exclusive))
-		return EIO;
+		goto error;
 
 	return 0;
+
+error:
+	if (oldmode == -1 || oldmode != mode)
+		(void)hold_unlock(resource);
+	return EIO;
 }
 
 /* Resume the LV if it was active */
Signature · 1 line
1.6.6
author
#3 lore raw

RFC PATCH 4/6 Always query device by uuid only in activation calls.

In reply to Milan Broz

lvm2 devices have always UUID set even if imported from lvm1 metadata.

Why not use query by UUID only always?

---
 lib/activate/activate.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
lib/activate/activate.c +2 -2
index 433c8cc..83d363a 100644
@@ -453,7 +453,7 @@ static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, in
 	    !(name = build_dm_name(cmd->mem, lv->vg->name, lv->name, NULL)))
 		return_0;
 
-	log_debug("Getting device info for %s", name);
+	log_debug("Getting device info for %s/%s", lv->vg->name, lv->name);
 	if (!dev_manager_info(lv->vg->cmd->mem, name, lv, with_mknodes,
 			      with_open_count, with_read_ahead, &dminfo,
 			      &info->read_ahead)) {
@@ -480,7 +480,7 @@ static int _lv_info(struct cmd_context *cmd, const struct logical_volume *lv, in
 int lv_info(struct cmd_context *cmd, const struct logical_volume *lv, struct lvinfo *info,
 	    int with_open_count, int with_read_ahead)
 {
-	return _lv_info(cmd, lv, 0, info, with_open_count, with_read_ahead, 0);
+	return _lv_info(cmd, lv, 0, info, with_open_count, with_read_ahead, 1);
 }
 
 int lv_info_by_lvid(struct cmd_context *cmd, const char *lvid_s,
Signature · 1 line
1.6.6
author
#4 lore raw

PATCH 5/6 Add some missing vg_revrts calls when pvmove aborts.

In reply to Milan Broz
---
 tools/pvmove.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
tools/pvmove.c +4 -1
index 47982e6..a286db1 100644
@@ -303,8 +303,10 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
 	}
 
 	/* Suspend lvs_changed */
-	if (!suspend_lvs(cmd, lvs_changed))
+	if (!suspend_lvs(cmd, lvs_changed)) {
+		vg_revert(vg);
 		goto_out;
+	}
 
 	/* Suspend mirrors on subsequent calls */
 	if (!first_time) {
@@ -324,6 +326,7 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
 				stack;
 		if (!resume_lvs(cmd, lvs_changed))
 			stack;
+		vg_revert(vg);
 		goto out;
 	}
 
Signature · 1 line
1.6.6
author
#5 lore raw

PATCH 6/6 Fix pvmove abort when temporary mirror fails to be cluster-aware.

In reply to Milan Broz

When activation of pvmove mirror fails on cluster, some nodes still possibly succeeded in activation.

- Explicitly deactivate that mirror to be sure
- properly pair suspend/resume calls to not cause memory lock problems in clvmd

Code cannot simply call _finish_pvmove on cluster in this situation, because changed LVs are suspended twice (causing memory inbalance) and also temporary mirror is activated when it is not expected (and we know that it failed already).

Patch prepares special fucntion which remove temporary mirror references from metadata and then resumes changed LVs.

---
 tools/pvmove.c |   51 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 35 insertions(+), 16 deletions(-)
tools/pvmove.c +35 -16
index a286db1..7ff94ff 100644
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2003-2004 Sistina Software, Inc. All rights reserved.
- * Copyright (C) 2004-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2004-2010 Red Hat, Inc. All rights reserved.
  *
  * This file is part of LVM2.
  *
@@ -284,9 +284,26 @@ static int _activate_lv(struct cmd_context *cmd, struct logical_volume *lv_mirr,
 	return r;
 }
 
-static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg,
-			  struct logical_volume *lv_mirr,
-			  struct dm_list *lvs_changed);
+static int _detach_pvmove_mirror(struct cmd_context *cmd,
+				 struct logical_volume *lv_mirr)
+{
+	struct dm_list lvs_completed;
+	struct lv_list *lvl;
+
+	/* Update metadata to remove mirror segments and break dependencies */
+	dm_list_init(&lvs_completed);
+	if (!lv_remove_mirrors(cmd, lv_mirr, 1, 0, NULL, PVMOVE) ||
+	    !remove_layers_for_segments_all(cmd, lv_mirr, PVMOVE,
+					    &lvs_completed)) {
+		return 0;
+	}
+
+	dm_list_iterate_items(lvl, &lvs_completed)
+		/* FIXME Assumes only one pvmove at a time! */
+		lvl->lv->status &= ~LOCKED;
+
+	return 1;
+}
 
 static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
 			    struct logical_volume *lv_mirr,
@@ -344,9 +361,21 @@ static int _update_metadata(struct cmd_context *cmd, struct volume_group *vg,
 			 * Nothing changed yet, try to revert pvmove.
 			 */
 			log_error("Temporary pvmove mirror activation failed.");
-			if (!_finish_pvmove(cmd, vg, lv_mirr, lvs_changed))
+
+			/* Ensure that temporary mrror is deactivate even on other nodes. */
+			(void)deactivate_lv(cmd, lv_mirr);
+
+			/* Revert metadata */
+			if (!_detach_pvmove_mirror(cmd, lv_mirr) ||
+			    !lv_remove(lv_mirr) ||
+			    !vg_write(vg) || !vg_commit(vg))
 				log_error("ABORTING: Restoring original configuration "
 					  "before pvmove failed. Run pvmove --abort.");
+
+			/* Unsuspend LVs */
+			if(!resume_lvs(cmd, lvs_changed))
+				stack;
+
 			goto out;
 		}
 	} else if (!resume_lv(cmd, lv_mirr)) {
@@ -487,22 +516,12 @@ static int _finish_pvmove(struct cmd_context *cmd, struct volume_group *vg,
 			  struct dm_list *lvs_changed)
 {
 	int r = 1;
-	struct dm_list lvs_completed;
-	struct lv_list *lvl;
 
-	/* Update metadata to remove mirror segments and break dependencies */
-	dm_list_init(&lvs_completed);
-	if (!lv_remove_mirrors(cmd, lv_mirr, 1, 0, NULL, PVMOVE) ||
-	    !remove_layers_for_segments_all(cmd, lv_mirr, PVMOVE,
-					    &lvs_completed)) {
+	if (!_detach_pvmove_mirror(cmd, lv_mirr)) {
 		log_error("ABORTING: Removal of temporary mirror failed");
 		return 0;
 	}
 
-	dm_list_iterate_items(lvl, &lvs_completed)
-		/* FIXME Assumes only one pvmove at a time! */
-		lvl->lv->status &= ~LOCKED;
-
 	/* Store metadata without dependencies on mirror segments */
 	if (!vg_write(vg)) {
 		log_error("ABORTING: Failed to write new data locations "
Signature · 1 line
1.6.6