* [PATCH V2] kpartx: support device names with spaces
@ 2016-01-20 13:52 Mauricio Faria de Oliveira
2016-01-20 14:53 ` Christophe Varoqui
0 siblings, 1 reply; 5+ messages in thread
From: Mauricio Faria de Oliveira @ 2016-01-20 13:52 UTC (permalink / raw)
To: dm-devel
Device names with spaces fail to be added to device-mapper tables
because spaces are field separators. In order to support it, use
device major:minor numbers, instead. While still there, make the
verbose output of container- and contained-slices consistent.
This is useful on some scenarios with arbitrary loop device names,
and non-user_friendly_names multipath WWIDs with spaces (eg, QEMU
emulated hard drives, and some IBM devices) on some distros.
Changelog:
- V2: Use major()/minor() instead of MAJOR()/MINOR() (build errors).
Update test-case verification output.
Thanks: Christophe Varoqui
Test-case:
# img="/tmp/my.img"
# spacename="/dev/my space name"
# truncate --size=1G "$img"
# lodev=$(sudo losetup --find --show "$img")
# ln -sf "$lodev" "$spacename"
# ls -l $lodev "$spacename"
brw-rw----. 1 root disk 7, 0 Jan 20 11:15 /dev/loop0
lrwxrwxrwx. 1 root root 10 Jan 20 11:16 /dev/my space name -> /dev/loop0
# fdisk $lodev
<...>
# fdisk -l $lodev
<...>
Device Boot Start End Blocks Id System
/dev/loop0p1 2048 264191 131072 83 Linux
/dev/loop0p2 264192 788479 262144 83 Linux
/dev/loop0p3 788480 2097151 654336 5 Extended
/dev/loop0p5 790528 856063 32768 83 Linux
/dev/loop0p6 858112 989183 65536 83 Linux
/dev/loop0p7 991232 1515519 262144 83 Linux
Without patch:
# ./kpartx/kpartx -av "$spacename"
device-mapper: reload ioctl on my\x20space\x20name1 failed: Invalid argument
create/reload failed on my space name1
add map my space name1 (0:0): 0 262144 linear /dev/my space name 2048
device-mapper: reload ioctl on my\x20space\x20name2 failed: Invalid argument
create/reload failed on my space name2
add map my space name2 (0:0): 0 524288 linear /dev/my space name 264192
device-mapper: reload ioctl on my\x20space\x20name3 failed: Invalid argument
create/reload failed on my space name3
add map my space name3 (0:0): 0 2 linear /dev/my space name 788480
device-mapper: reload ioctl on my\x20space\x20name5 failed: Invalid argument
add map my space name5 : 0 65536 linear /dev/my space name 790528
device-mapper: reload ioctl on my\x20space\x20name6 failed: Invalid argument
add map my space name6 : 0 131072 linear /dev/my space name 858112
device-mapper: reload ioctl on my\x20space\x20name7 failed: Invalid argument
add map my space name7 : 0 524288 linear /dev/my space name 991232
(note: line breaks added for clarity)
With patch:
# ./kpartx/kpartx -av "$spacename"
add map my space name1 (253:3): 0 262144 linear 7:0 2048
add map my space name2 (253:4): 0 524288 linear 7:0 264192
add map my space name3 (253:5): 0 2 linear 7:0 788480
add map my space name5 (253:6): 0 65536 linear 7:0 790528
add map my space name6 (253:7): 0 131072 linear 7:0 858112
add map my space name7 (253:8): 0 524288 linear 7:0 991232
# dmsetup table | sort
my space name1: 0 262144 linear 7:0 2048
my space name2: 0 524288 linear 7:0 264192
my space name3: 0 2 linear 7:0 788480
my space name5: 0 65536 linear 7:0 790528
my space name6: 0 131072 linear 7:0 858112
my space name7: 0 524288 linear 7:0 991232
# ls -l /dev/mapper/
total 0
crw-------. 1 root root 10, 236 Jan 11 16:29 control
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name1 -> ../dm-3
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name2 -> ../dm-4
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name3 -> ../dm-5
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name5 -> ../dm-6
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name6 -> ../dm-7
lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name7 -> ../dm-8
Thanks: Scott Moser (pointers to the error and test-case).
Signed-off-by: Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>
---
kpartx/kpartx.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
index a9d4c98..ee7c38a 100644
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -477,8 +477,8 @@ main(int argc, char **argv){
}
strip_slash(partname);
- if (safe_sprintf(params, "%s %" PRIu64 ,
- device, slices[j].start)) {
+ if (safe_sprintf(params, "%d:%d %" PRIu64 ,
+ major(buf.st_rdev), minor(buf.st_rdev), slices[j].start)) {
fprintf(stderr, "params too small\n");
exit(1);
}
@@ -540,8 +540,8 @@ main(int argc, char **argv){
}
strip_slash(partname);
- if (safe_sprintf(params, "%s %" PRIu64,
- device,
+ if (safe_sprintf(params, "%d:%d %" PRIu64,
+ major(buf.st_rdev), minor(buf.st_rdev),
slices[j].start)) {
fprintf(stderr, "params too small\n");
exit(1);
@@ -563,8 +563,8 @@ main(int argc, char **argv){
&slices[j].minor);
if (verbose)
- printf("add map %s : 0 %" PRIu64 " %s %s\n",
- partname, slices[j].size,
+ printf("add map %s (%d:%d): 0 %" PRIu64 " %s %s\n",
+ partname, slices[j].major, slices[j].minor, slices[j].size,
DM_TARGET, params);
c--;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH V2] kpartx: support device names with spaces
2016-01-20 13:52 [PATCH V2] kpartx: support device names with spaces Mauricio Faria de Oliveira
@ 2016-01-20 14:53 ` Christophe Varoqui
2016-01-20 17:35 ` Mauricio Faria de Oliveira
2016-02-02 21:37 ` [PATCH] Fix loopback file with kpartx -av Mathieu Trudel-Lapierre
0 siblings, 2 replies; 5+ messages in thread
From: Christophe Varoqui @ 2016-01-20 14:53 UTC (permalink / raw)
To: Mauricio Faria de Oliveira; +Cc: device-mapper development
[-- Attachment #1.1: Type: text/plain, Size: 6995 bytes --]
Applied,
thanks.
On Wed, Jan 20, 2016 at 2:52 PM, Mauricio Faria de Oliveira <
mauricfo@linux.vnet.ibm.com> wrote:
> Device names with spaces fail to be added to device-mapper tables
> because spaces are field separators. In order to support it, use
> device major:minor numbers, instead. While still there, make the
> verbose output of container- and contained-slices consistent.
>
> This is useful on some scenarios with arbitrary loop device names,
> and non-user_friendly_names multipath WWIDs with spaces (eg, QEMU
> emulated hard drives, and some IBM devices) on some distros.
>
> Changelog:
> - V2: Use major()/minor() instead of MAJOR()/MINOR() (build errors).
> Update test-case verification output.
> Thanks: Christophe Varoqui
>
> Test-case:
>
> # img="/tmp/my.img"
> # spacename="/dev/my space name"
>
> # truncate --size=1G "$img"
> # lodev=$(sudo losetup --find --show "$img")
> # ln -sf "$lodev" "$spacename"
>
> # ls -l $lodev "$spacename"
> brw-rw----. 1 root disk 7, 0 Jan 20 11:15 /dev/loop0
> lrwxrwxrwx. 1 root root 10 Jan 20 11:16 /dev/my space name ->
> /dev/loop0
>
> # fdisk $lodev
> <...>
>
> # fdisk -l $lodev
> <...>
> Device Boot Start End Blocks Id System
> /dev/loop0p1 2048 264191 131072 83 Linux
> /dev/loop0p2 264192 788479 262144 83 Linux
> /dev/loop0p3 788480 2097151 654336 5 Extended
> /dev/loop0p5 790528 856063 32768 83 Linux
> /dev/loop0p6 858112 989183 65536 83 Linux
> /dev/loop0p7 991232 1515519 262144 83 Linux
>
> Without patch:
>
> # ./kpartx/kpartx -av "$spacename"
> device-mapper: reload ioctl on my\x20space\x20name1 failed:
> Invalid argument
> create/reload failed on my space name1
> add map my space name1 (0:0): 0 262144 linear /dev/my space name
> 2048
>
> device-mapper: reload ioctl on my\x20space\x20name2 failed:
> Invalid argument
> create/reload failed on my space name2
> add map my space name2 (0:0): 0 524288 linear /dev/my space name
> 264192
>
> device-mapper: reload ioctl on my\x20space\x20name3 failed:
> Invalid argument
> create/reload failed on my space name3
> add map my space name3 (0:0): 0 2 linear /dev/my space name 788480
>
> device-mapper: reload ioctl on my\x20space\x20name5 failed:
> Invalid argument
> add map my space name5 : 0 65536 linear /dev/my space name 790528
>
> device-mapper: reload ioctl on my\x20space\x20name6 failed:
> Invalid argument
> add map my space name6 : 0 131072 linear /dev/my space name 858112
>
> device-mapper: reload ioctl on my\x20space\x20name7 failed:
> Invalid argument
> add map my space name7 : 0 524288 linear /dev/my space name 991232
>
> (note: line breaks added for clarity)
>
> With patch:
>
> # ./kpartx/kpartx -av "$spacename"
> add map my space name1 (253:3): 0 262144 linear 7:0 2048
> add map my space name2 (253:4): 0 524288 linear 7:0 264192
> add map my space name3 (253:5): 0 2 linear 7:0 788480
> add map my space name5 (253:6): 0 65536 linear 7:0 790528
> add map my space name6 (253:7): 0 131072 linear 7:0 858112
> add map my space name7 (253:8): 0 524288 linear 7:0 991232
>
> # dmsetup table | sort
> my space name1: 0 262144 linear 7:0 2048
> my space name2: 0 524288 linear 7:0 264192
> my space name3: 0 2 linear 7:0 788480
> my space name5: 0 65536 linear 7:0 790528
> my space name6: 0 131072 linear 7:0 858112
> my space name7: 0 524288 linear 7:0 991232
>
> # ls -l /dev/mapper/
> total 0
> crw-------. 1 root root 10, 236 Jan 11 16:29 control
> lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name1
> -> ../dm-3
> lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name2
> -> ../dm-4
> lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name3
> -> ../dm-5
> lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name5
> -> ../dm-6
> lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name6
> -> ../dm-7
> lrwxrwxrwx. 1 root root 7 Jan 20 11:19 my\x20space\x20name7
> -> ../dm-8
>
> Thanks: Scott Moser (pointers to the error and test-case).
>
> Signed-off-by: Mauricio Faria de Oliveira <mauricfo@linux.vnet.ibm.com>
> ---
> kpartx/kpartx.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/kpartx/kpartx.c b/kpartx/kpartx.c
> index a9d4c98..ee7c38a 100644
> --- a/kpartx/kpartx.c
> +++ b/kpartx/kpartx.c
> @@ -477,8 +477,8 @@ main(int argc, char **argv){
> }
> strip_slash(partname);
>
> - if (safe_sprintf(params, "%s %" PRIu64 ,
> - device, slices[j].start))
> {
> + if (safe_sprintf(params, "%d:%d %" PRIu64 ,
> + major(buf.st_rdev),
> minor(buf.st_rdev), slices[j].start)) {
> fprintf(stderr, "params too
> small\n");
> exit(1);
> }
> @@ -540,8 +540,8 @@ main(int argc, char **argv){
> }
> strip_slash(partname);
>
> - if (safe_sprintf(params, "%s %"
> PRIu64,
> - device,
> + if (safe_sprintf(params, "%d:%d %"
> PRIu64,
> +
> major(buf.st_rdev), minor(buf.st_rdev),
> slices[j].start))
> {
> fprintf(stderr, "params
> too small\n");
> exit(1);
> @@ -563,8 +563,8 @@ main(int argc, char **argv){
> &slices[j].minor);
>
> if (verbose)
> - printf("add map %s : 0 %"
> PRIu64 " %s %s\n",
> - partname,
> slices[j].size,
> + printf("add map %s
> (%d:%d): 0 %" PRIu64 " %s %s\n",
> + partname,
> slices[j].major, slices[j].minor, slices[j].size,
> DM_TARGET, params);
> c--;
> }
> --
> 1.8.3.1
>
>
[-- Attachment #1.2: Type: text/html, Size: 9061 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH V2] kpartx: support device names with spaces
2016-01-20 14:53 ` Christophe Varoqui
@ 2016-01-20 17:35 ` Mauricio Faria de Oliveira
2016-02-02 21:37 ` [PATCH] Fix loopback file with kpartx -av Mathieu Trudel-Lapierre
1 sibling, 0 replies; 5+ messages in thread
From: Mauricio Faria de Oliveira @ 2016-01-20 17:35 UTC (permalink / raw)
To: Christophe Varoqui; +Cc: device-mapper development
On 01/20/2016 12:53 PM, Christophe Varoqui wrote:
> Applied,
> thanks.
Thank you.
--
Mauricio Faria de Oliveira
IBM Linux Technology Center
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH] Fix loopback file with kpartx -av
2016-01-20 14:53 ` Christophe Varoqui
2016-01-20 17:35 ` Mauricio Faria de Oliveira
@ 2016-02-02 21:37 ` Mathieu Trudel-Lapierre
2016-02-03 8:27 ` Christophe Varoqui
1 sibling, 1 reply; 5+ messages in thread
From: Mathieu Trudel-Lapierre @ 2016-02-02 21:37 UTC (permalink / raw)
To: dm-devel
[-- Attachment #1.1: Type: text/plain, Size: 1158 bytes --]
Le 2016-01-20 09:53, Christophe Varoqui a écrit :
> Applied,
> thanks.
>
This patch apparently breaks the use of loopback-mounted files if you
try to use them directly with kpartx -av.
For instance:
qemu-img create foo.img 20M
sgdisk -n 1 foo.img
kpartx -av foo.img
Fails with the following error:
device-mapper: reload ioctl on loop0p1 failed: No such device
create/reload failed on loop0p1
add map loop0p1 (0:0): 0 4192256 linear 0:0 2048
This can be fixed by stat()'ing the loop device again after picking it:
--- a/kpartx/kpartx.c
+++ b/kpartx/kpartx.c
@@ -322,6 +322,11 @@ main(int argc, char **argv){
loopcreated = 1;
}
device = loopdev;
+
+ if (stat(device, &buf)) {
+ printf("failed to stat() %s\n", device);
+ exit (1);
+ }
}
off = find_devname_offset(device);
--
Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
Freenode: cyphermox, Jabber: mathieu.tl@gmail.com
4096R/65B58DA1 818A D123 0992 275B 23C2 CF89 C67B B4D6 65B5 8DA1
[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 801 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] Fix loopback file with kpartx -av
2016-02-02 21:37 ` [PATCH] Fix loopback file with kpartx -av Mathieu Trudel-Lapierre
@ 2016-02-03 8:27 ` Christophe Varoqui
0 siblings, 0 replies; 5+ messages in thread
From: Christophe Varoqui @ 2016-02-03 8:27 UTC (permalink / raw)
To: Mathieu Trudel-Lapierre; +Cc: device-mapper development
[-- Attachment #1.1: Type: text/plain, Size: 1476 bytes --]
Commited,
Thanks.
On Tue, Feb 2, 2016 at 10:37 PM, Mathieu Trudel-Lapierre <
mathieu.trudel-lapierre@canonical.com> wrote:
> Le 2016-01-20 09:53, Christophe Varoqui a écrit :
> > Applied,
> > thanks.
> >
>
> This patch apparently breaks the use of loopback-mounted files if you
> try to use them directly with kpartx -av.
>
> For instance:
> qemu-img create foo.img 20M
> sgdisk -n 1 foo.img
> kpartx -av foo.img
>
>
> Fails with the following error:
> device-mapper: reload ioctl on loop0p1 failed: No such device
> create/reload failed on loop0p1
> add map loop0p1 (0:0): 0 4192256 linear 0:0 2048
>
>
> This can be fixed by stat()'ing the loop device again after picking it:
>
> --- a/kpartx/kpartx.c
> +++ b/kpartx/kpartx.c
> @@ -322,6 +322,11 @@ main(int argc, char **argv){
> loopcreated = 1;
> }
> device = loopdev;
> +
> + if (stat(device, &buf)) {
> + printf("failed to stat() %s\n", device);
> + exit (1);
> + }
> }
>
> off = find_devname_offset(device);
>
>
>
>
> --
> Mathieu Trudel-Lapierre <mathieu.trudel-lapierre@canonical.com>
> Freenode: cyphermox, Jabber: mathieu.tl@gmail.com
> 4096R/65B58DA1 818A D123 0992 275B 23C2 CF89 C67B B4D6 65B5 8DA1
>
>
> --
> dm-devel mailing list
> dm-devel@redhat.com
> https://www.redhat.com/mailman/listinfo/dm-devel
>
[-- Attachment #1.2: Type: text/html, Size: 2303 bytes --]
[-- Attachment #2: Type: text/plain, Size: 0 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-02-03 8:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-20 13:52 [PATCH V2] kpartx: support device names with spaces Mauricio Faria de Oliveira
2016-01-20 14:53 ` Christophe Varoqui
2016-01-20 17:35 ` Mauricio Faria de Oliveira
2016-02-02 21:37 ` [PATCH] Fix loopback file with kpartx -av Mathieu Trudel-Lapierre
2016-02-03 8:27 ` Christophe Varoqui
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.