Skip to contentSkip to conversation

kpartx to accept device map name

PATCH In review Jun'ichi Nomura 2 participants 3 messages May 16, 2005 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kpartx to accept device map name

Hello Christophe,

Attached patch adds '-m' option which makes kpartx to accept device map name.

Using with the cvs version of libdevmapper or with the patch suggested by Kiyoshi Ueda today, we don't need to depend on asynchronous nature of hotplug when it's not necessary.

For example, we can do this for initialization:
multipath
dmsetup info -c --noheadings -o name | xargs -l1 kpartx -a -m
otherwise we had to insert adhoc length of sleep to wait for the completion of hotplug events.

Please consider to apply.

Thanks,
Jun'ichi Nomura

kpartx/kpartx.c (mode:100644) +22 -2
Index: kpartx/kpartx.c
===================================================================
@@ -70,7 +70,7 @@
 	addpts("unixware", read_unixware_pt);
 }
 
-static char short_opts[] = "ladgvnp:t:";
+static char short_opts[] = "ladgvnp:t:m";
 
 /* Used in gpt.c */
 int force_gpt=0;
@@ -183,6 +183,7 @@
 	char * delim = NULL;
 	int loopro = 0;
 	int hotplug = 0;
+	int use_mapname = 0;
 	struct stat buf;
 
 	initpts();
@@ -245,12 +246,16 @@
 		case 'd':
 			what = DELETE;
 			break;
+		case 'm':
+			use_mapname = 1;
+			break;
 		default:
 			usage();
 			exit(1);
 	}
 
-	if (dm_prereq(DM_TARGET, 0, 0, 0) && (what == ADD || what == DELETE)) {
+	if (dm_prereq(DM_TARGET, 0, 0, 0)
+	    && (what == ADD || what == DELETE || use_mapname)) {
 		fprintf(stderr, "device mapper prerequisites not met\n"); 
 		exit(1);
 	}
@@ -267,6 +272,21 @@
 		exit(1);
 	}
 
+	if (use_mapname) {
+		int len;
+		char *realdev, *dmdir;
+
+		dmdir = dm_dir();
+		len = strlen(dmdir) + strlen(device) + 2;
+		realdev = malloc(sizeof(char) * len);
+		if (!realdev) {
+			printf("failed to alloc memory\n");
+			exit(1);
+		}
+		snprintf(realdev, len, "%s/%s", dmdir, device);
+		diskdevice = device = realdev;
+	}
+
 	if (stat(device, &buf)) {
 		printf("failed to stat() %s\n", device);
 		exit (1);
#1 lore raw

I applied Kiyoshi"s patch.

Can you elaborate on the problems you see with the asynchronous hotplug model ?

I would like to express my reluctance to add a devmap special case to kpartx.

Regards,
cvaroqui

Quoted 25 lines · Jun'ichi Nomura

Hello Christophe,

Attached patch adds '-m' option which makes kpartx to accept device map name.

Using with the cvs version of libdevmapper or with the patch suggested by Kiyoshi Ueda today, we don't need to depend on asynchronous nature of hotplug when it's not necessary.

For example, we can do this for initialization:
multipath
dmsetup info -c --noheadings -o name | xargs -l1 kpartx -a -m
otherwise we had to insert adhoc length of sleep to wait for the completion of hotplug events.

Please consider to apply.

Thanks,
Jun'ichi Nomura

--
dm-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/dm-devel

Signature · 1 line
christophe varoqui <[email protected]>
#2 lore raw

Hi,

Excuse me for the misleading message.

The problem I saw was that when executing kpartx just after multipath (in shell script), kpartx was invoked too early and couldn't see the device node. I could avoid it by inserting "sleep 5" after multipath execution but I can't tell whether it's enough.
Kiyoshi's patch should fix it and the device node will be created on the location which libdevmapper knows. (/dev/mapper)

'-m' option provides a way to avoid dependency to hidden knowledge about the location (/dev or /dev/mapper or anywhere else). Without this, we have to synchronize udev rules, hotplug shell scripts and initscripts to see the same device node for dm devices. This is why I thought it's better to give kpartx an option like this.

..However, in the really latest CVS, dmsetup has a new function to execute external command with device node name.
So we can do the same thing with dmsetup now.
Given that you are reluctant to add kpartx more relationship with libdevmapper, dmsetup is the best place.

Thanks,
Jun'ichi Nomura

Quoted 9 lines · christophe varoqui

Can you elaborate on the problems you see with the asynchronous hotplug model ?

I would like to express my reluctance to add a devmap special case to kpartx.

Quoted 2 lines · Jun'ichi Nomura

Attached patch adds '-m' option which makes kpartx to accept device map name.