Skip to contentSkip to conversation

Fix pvcreate device check.

PATCH New Milan Broz 2 participants 3 messages Mar 15, 2010 – Mar 16, 2010

lore
Share & tools
lore

Milan Broz

author
#0 lore raw

PATCH 1/1 Fix pvcreate device check.

If user try to vgcreate or vgextend non-existent VG, these messages appears:

# vgcreate xxx /dev/xxx
  Internal error: Volume Group xxx was not unlocked
  Device /dev/xxx not found (or ignored by filtering).
  Unable to add physical volume '/dev/xxx' to volume group 'xxx'.
  Internal error: Attempt to unlock unlocked VG xxx.

(the same with existing VG and non-existing PV & vgextend)

# vgextend vg_test /dev/xxx
...

It is caused because code tries to "refresh" cache if md filter is switched on using cache destroy.

But we can change filters and rescan even without this machinery now, just use refresh_filters
(and reset md filter afterwards).

(Patch also discovers cache alias bug in vgsplit test, fix it by using better filter line.)

---
 lib/metadata/metadata.c   |   12 ++----------
 test/t-vgsplit-stacked.sh |    2 +-
 2 files changed, 3 insertions(+), 11 deletions(-)
lib/metadata/metadata.c +2 -10
index f1b90a7..f079554 100644
@@ -1294,17 +1294,9 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
 
 	/* Is there an md superblock here? */
 	if (!dev && md_filtering()) {
-		unlock_vg(cmd, VG_ORPHANS);
-
-		persistent_filter_wipe(cmd->filter);
-		lvmcache_destroy(cmd, 1);
-
+		refresh_filters(cmd);
 		init_md_filtering(0);
-		if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
-			log_error("Can't get lock for orphan PVs");
-			init_md_filtering(1);
-			return 0;
-		}
+		lvmcache_label_scan(cmd, 0);
 		dev = dev_cache_get(name, cmd->filter);
 		init_md_filtering(1);
 	}
test/t-vgsplit-stacked.sh +1 -1
index 46cb105..fb4e659 100644
@@ -1,6 +1,6 @@
 . ./test-utils.sh
 
-prepare_lvmconf '[ "a/dev\/mirror/", "a/dev\/mapper\/.*$/", "r/.*/" ]'
+prepare_lvmconf '[ "a/dev\/mirror/", "a/dev\/mapper\/.*$/", "a/dev\/LVMTEST/", "r/.*/" ]'
 aux prepare_devs 3
 
 pvcreate $devs
Signature · 1 line
1.7.0
author
#1 lore raw

PATCH 1/1 Fix pvcreate device check.

Quoted 9 lines · Milan Broz
lib/metadata/metadata.c +0 -5
@@ -1294,17 +1294,9 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
 
 	/* Is there an md superblock here? */
 	if (!dev && md_filtering()) {
-		unlock_vg(cmd, VG_ORPHANS);
-
-		persistent_filter_wipe(cmd->filter);
-		lvmcache_destroy(cmd, 1);
-

lib/metadata/metadata.c static int pvcreate_check(struct cmd_context *cmd, const char *name, · line 1301

Quoted 10 lines
lib/metadata/metadata.c +2 -5
+		refresh_filters(cmd);
 		init_md_filtering(0);
-		if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
-			log_error("Can't get lock for orphan PVs");
-			init_md_filtering(1);
-			return 0;
-		}
 
 
+		lvmcache_label_scan(cmd, 0);

even this rescan line is not needed, device must be in cache already, just it is filtered out by MD filter.

Milan

#2 lore raw

PATCH 1/1 Fix pvcreate device check.

Quoted 19 lines · Milan Broz
Quoted 16 lines · Milan Broz
lib/metadata/metadata.c +1 -10
@@ -1294,17 +1294,9 @@ static int pvcreate_check(struct cmd_context *cmd, const char *name,
 
 	/* Is there an md superblock here? */
 	if (!dev && md_filtering()) {
-		unlock_vg(cmd, VG_ORPHANS);
-
-		persistent_filter_wipe(cmd->filter);
-		lvmcache_destroy(cmd, 1);
-
+		refresh_filters(cmd);
 		init_md_filtering(0);
-		if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
-			log_error("Can't get lock for orphan PVs");
-			init_md_filtering(1);
-			return 0;
-		}
Quoted 7 lines

lib/metadata/metadata.c static int pvcreate_check(struct cmd_context *cmd, const char *name, · line 1299

Quoted 1 line
lib/metadata/metadata.c +1 -0
+		lvmcache_label_scan(cmd, 0);

even this rescan line is not needed, device must be in cache already, just it is filtered out by MD filter.

Milan

Ack. Thanks for cleaning up this code wart Milan!