<div dir="ltr">Applied,<div>thanks.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jan 20, 2016 at 2:52 PM, Mauricio Faria de Oliveira <span dir="ltr"><<a href="mailto:mauricfo@linux.vnet.ibm.com" target="_blank">mauricfo@linux.vnet.ibm.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Device names with spaces fail to be added to device-mapper tables<br>
because spaces are field separators. In order to support it, use<br>
device major:minor numbers, instead. While still there, make the<br>
verbose output of container- and contained-slices consistent.<br>
<br>
This is useful on some scenarios with arbitrary loop device names,<br>
and non-user_friendly_names multipath WWIDs with spaces (eg, QEMU<br>
emulated hard drives, and some IBM devices) on some distros.<br>
<br>
Changelog:<br>
- V2: Use major()/minor() instead of MAJOR()/MINOR() (build errors).<br>
Update test-case verification output.<br>
Thanks: Christophe Varoqui<br>
<br>
Test-case:<br>
<br>
# img="/tmp/my.img"<br>
# spacename="/dev/my space name"<br>
<br>
# truncate --size=1G "$img"<br>
# lodev=$(sudo losetup --find --show "$img")<br>
# ln -sf "$lodev" "$spacename"<br>
<br>
# ls -l $lodev "$spacename"<br>
brw-rw----. 1 root disk 7, 0 Jan 20 11:15 /dev/loop0<br>
lrwxrwxrwx. 1 root root 10 Jan 20 11:16 /dev/my space name -> /dev/loop0<br>
<br>
# fdisk $lodev<br>
<...><br>
<br>
# fdisk -l $lodev<br>
<...><br>
Device Boot Start End Blocks Id System<br>
/dev/loop0p1 2048 264191 131072 83 Linux<br>
/dev/loop0p2 264192 788479 262144 83 Linux<br>
/dev/loop0p3 788480 2097151 654336 5 Extended<br>
/dev/loop0p5 790528 856063 32768 83 Linux<br>
/dev/loop0p6 858112 989183 65536 83 Linux<br>
/dev/loop0p7 991232 1515519 262144 83 Linux<br>
<br>
Without patch:<br>
<br>
# ./kpartx/kpartx -av "$spacename"<br>
device-mapper: reload ioctl on my\x20space\x20name1 failed: Invalid argument<br>
create/reload failed on my space name1<br>
add map my space name1 (0:0): 0 262144 linear /dev/my space name 2048<br>
<br>
device-mapper: reload ioctl on my\x20space\x20name2 failed: Invalid argument<br>
create/reload failed on my space name2<br>
add map my space name2 (0:0): 0 524288 linear /dev/my space name 264192<br>
<br>
device-mapper: reload ioctl on my\x20space\x20name3 failed: Invalid argument<br>
create/reload failed on my space name3<br>
add map my space name3 (0:0): 0 2 linear /dev/my space name 788480<br>
<br>
device-mapper: reload ioctl on my\x20space\x20name5 failed: Invalid argument<br>
add map my space name5 : 0 65536 linear /dev/my space name 790528<br>
<br>
device-mapper: reload ioctl on my\x20space\x20name6 failed: Invalid argument<br>
add map my space name6 : 0 131072 linear /dev/my space name 858112<br>
<br>
device-mapper: reload ioctl on my\x20space\x20name7 failed: Invalid argument<br>
add map my space name7 : 0 524288 linear /dev/my space name 991232<br>
<br>
(note: line breaks added for clarity)<br>
<br>
With patch:<br>
<br>
# ./kpartx/kpartx -av "$spacename"<br>
add map my space name1 (253:3): 0 262144 linear 7:0 2048<br>
add map my space name2 (253:4): 0 524288 linear 7:0 264192<br>
add map my space name3 (253:5): 0 2 linear 7:0 788480<br>
add map my space name5 (253:6): 0 65536 linear 7:0 790528<br>
add map my space name6 (253:7): 0 131072 linear 7:0 858112<br>
add map my space name7 (253:8): 0 524288 linear 7:0 991232<br>
<br>
# dmsetup table | sort<br>
my space name1: 0 262144 linear 7:0 2048<br>
my space name2: 0 524288 linear 7:0 264192<br>
my space name3: 0 2 linear 7:0 788480<br>
my space name5: 0 65536 linear 7:0 790528<br>
my space name6: 0 131072 linear 7:0 858112<br>
my space name7: 0 524288 linear 7:0 991232<br>
<br>
# ls -l /dev/mapper/<br>
total 0<br>
crw-------. 1 root root 10, 236 Jan 11 16:29 control<br>
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name1 -> ../dm-3<br>
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name2 -> ../dm-4<br>
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name3 -> ../dm-5<br>
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name5 -> ../dm-6<br>
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name6 -> ../dm-7<br>
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name7 -> ../dm-8<br>
<br>
Thanks: Scott Moser (pointers to the error and test-case).<br>
<br>
Signed-off-by: Mauricio Faria de Oliveira <<a href="mailto:mauricfo@linux.vnet.ibm.com">mauricfo@linux.vnet.ibm.com</a>><br>
---<br>
kpartx/kpartx.c | 12 ++++++------<br>
1 file changed, 6 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c<br>
index a9d4c98..ee7c38a 100644<br>
--- a/kpartx/kpartx.c<br>
+++ b/kpartx/kpartx.c<br>
@@ -477,8 +477,8 @@ main(int argc, char **argv){<br>
}<br>
strip_slash(partname);<br>
<br>
- if (safe_sprintf(params, "%s %" PRIu64 ,<br>
- device, slices[j].start)) {<br>
+ if (safe_sprintf(params, "%d:%d %" PRIu64 ,<br>
+ major(buf.st_rdev), minor(buf.st_rdev), slices[j].start)) {<br>
fprintf(stderr, "params too small\n");<br>
exit(1);<br>
}<br>
@@ -540,8 +540,8 @@ main(int argc, char **argv){<br>
}<br>
strip_slash(partname);<br>
<br>
- if (safe_sprintf(params, "%s %" PRIu64,<br>
- device,<br>
+ if (safe_sprintf(params, "%d:%d %" PRIu64,<br>
+ major(buf.st_rdev), minor(buf.st_rdev),<br>
slices[j].start)) {<br>
fprintf(stderr, "params too small\n");<br>
exit(1);<br>
@@ -563,8 +563,8 @@ main(int argc, char **argv){<br>
&slices[j].minor);<br>
<br>
if (verbose)<br>
- printf("add map %s : 0 %" PRIu64 " %s %s\n",<br>
- partname, slices[j].size,<br>
+ printf("add map %s (%d:%d): 0 %" PRIu64 " %s %s\n",<br>
+ partname, slices[j].major, slices[j].minor, slices[j].size,<br>
DM_TARGET, params);<br>
c--;<br>
}<br>
<span class="HOEnZb"><font color="#888888">--<br>
1.8.3.1<br>
<br>
</font></span></blockquote></div><br></div>