Skip to contentSkip to conversation

libdevmapper's handling of devices with spaces in the name

linux-lvm Phillip Susi 4 participants 10 messages Feb 26, 2014 – Feb 27, 2014

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

So if I tell dmsetup to create a device named 'foo bar' it ends up actually naming it 'foo\x20bar'. If I run parted on 'foo\x20bar', it appears that libdevmapper helpfully tries to unescape the name, returning 'foo bar' from dm_task_get_name(). Unfortunately, such a dev node does not actually exist so this creates a problem trying to open it.

This seems like a bug in libdevmapper. I'd say the name of the actual dev node should not be escaped in the first place.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJTDh6oAAoJEI5FoCIzSKrwDQgH/ikb56o0nnptlD98L1dW9LNi pZQL7IixpwVCLHrI2DBIZvtGAQKgrN16lMLIkLnH7LzRXNaw9Lkw/QG9Jgs+Zibm fd5yYTgHlOCCsw8OEIOoXLT3YRWB6fjsWrGuFo9/SnJQpZVjxeLCGoopIkusNd6A aP8BnX4iWl/eJgs/4gOuFjbimckDui5jYnp4ZJ8ena7a+tv1H/rywPkboOlKrz2+ /dI9WMJYFyUYqaVgZCXstBStCQTF6156HZAkB+qqwAo2um9SP+yQlU7zqixieK9T h/Rd7MuDHPe+TObNVmLRRXJ1+c2yoEKa8ra8WH+C/G7u2V6qtzZf0CfSMzk0p+A= =wPZ8
-----END PGP SIGNATURE-----

#1 lore raw

Dne 26.2.2014 18:04, Phillip Susi napsal(a):

Quoted 10 lines

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

So if I tell dmsetup to create a device named 'foo bar' it ends up actually naming it 'foo\x20bar'. If I run parted on 'foo\x20bar', it appears that libdevmapper helpfully tries to unescape the name, returning 'foo bar' from dm_task_get_name(). Unfortunately, such a dev node does not actually exist so this creates a problem trying to open it.

Quoted 2 lines

This seems like a bug in libdevmapper. I'd say the name of the actual dev node should not be escaped in the first place.

This is no longer true for 'modern' systems with udev.

libdevmapper no longer creates any /dev nodes - it's all job for udev.

And udev has had in dark ages the idea to use 'space' as a separator
for device names in device list. Thus it 'invented' escaping/mangling names.
(There are more prohibited characters which used to be used for normal device names (see man dmsetup mangling))

If you have system without udev - you could disable name mangling on i.e. dmsetup cmdline.

There is also envvar DM_DEFAULT_NAME_MANGLING_MODE_ENV_VAR_NAME which could be used to set prefered behavior.

So there is no bug in libdm side - but I'll not comment on the rest...

I'll just note - it really means all tools now would need to be fixed to handle udev mangled names properly...

Regards

Zdenek

#2 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 5 lines · Zdenek Kabelac

This is no longer true for 'modern' systems with udev.

libdevmapper no longer creates any /dev nodes - it's all job for udev.

Quoted 8 lines

And udev has had in dark ages the idea to use 'space' as a separator for device names in device list. Thus it 'invented' escaping/mangling names. (There are more prohibited characters which used to be used for normal device names (see man dmsetup mangling))

If you have system without udev - you could disable name mangling on i.e. dmsetup cmdline.

So it is doing this to try and work around a bug in udev. Has this been fixed in modern udev and should be safe to disable? It doesn't seem to work for me when I do with udev 204: I end up with /dev/mapper/foo.

Quoted 5 lines

There is also envvar DM_DEFAULT_NAME_MANGLING_MODE_ENV_VAR_NAME which could be used to set prefered behavior.

So there is no bug in libdm side - but I'll not comment on the rest...

The bug in libdm is that it is lieing to the calling application about the name of the device, claiming it is not escaped, when in fact, it is. Or is dm_task_get_name() supposed to return a human readable string rather than the actual file name? If that is the case, how to get the actual file name instead?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJTDjRkAAoJEI5FoCIzSKrwpAcIAJz9UAGH5KRTZphdC5TBnfiH +5Hvpeep1gjO/W5mnsjNw7/Y1fP9W+vGKnJj2GUY4nlB0iVYoDxR6M8dTUkBKgZr M+4hkxUdco8I/oik9uFZrF8YhcHIEsFJrhpAD/RDgsq7YiLD+U6bxAnR9O+OdCyG hJh3GuKhEXf/A6D2sc89F06mg+7e2m44Yn/rjaYdQaYXISQ34++1lkrjZ8co8gDz UWkPnoTwSJPuMhhhNXhBvSKxwl7J0SYC9E53D3uBChnHc3zfWoR21h8MxZ9EdUgD sVA0HLZdxZrkbAiaw7p0YW8KZhEcT0Khsn+X/oagB/EqJBT5MXioHZIuAJk2nFw= =hzdN
-----END PGP SIGNATURE-----

#3 lore raw

Dne 26.2.2014 19:37, Phillip Susi napsal(a):

Quoted 15 lines

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 11 lines · Zdenek Kabelac

This is no longer true for 'modern' systems with udev.

libdevmapper no longer creates any /dev nodes - it's all job for udev.

And udev has had in dark ages the idea to use 'space' as a separator for device names in device list. Thus it 'invented' escaping/mangling names. (There are more prohibited characters which used to be used for normal device names (see man dmsetup mangling))

Quoted 5 lines
Quoted 2 lines

If you have system without udev - you could disable name mangling on i.e. dmsetup cmdline.

So it is doing this to try and work around a bug in udev. Has this been fixed in modern udev and should be safe to disable? It doesn't

Unfortunately this is seen as a 'feature' of udev - so there is no plan to fix it in udev - since too many other things depends on the current naming logic (i.e all udev rules scripts written in bash would need major fixes to work with characters which are nontrivil to work with) All surrounding Gnome above it as well - you would be really amazed if you would check this deeply...

Quoted 6 lines

seem to work for me when I do with udev 204: I end up with /dev/mapper/foo.

Quoted 3 lines

There is also envvar DM_DEFAULT_NAME_MANGLING_MODE_ENV_VAR_NAME which could be used to set prefered behavior.

Quoted 8 lines
Quoted 2 lines

So there is no bug in libdm side - but I'll not comment on the rest...

The bug in libdm is that it is lieing to the calling application about the name of the device, claiming it is not escaped, when in fact, it is. Or is dm_task_get_name() supposed to return a human readable string rather than the actual file name? If that is the case, how to get the actual file name instead?

As said - there is no bug in libdm - libdm expects udev to create nodes.
You can reconfigure libdm to do this job instead of udev - but then nothing else will work with it - so it's basically dead-road...

The best you can do is to not use names which needs mangling - that's my best suggestions (and lvm team already spend countless hours on some usable workarounds and solutions...)

For mangling see 'dmsetup mangle' help - how to obtain device names...

Zdenek

#4 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 4 lines · Zdenek Kabelac

As said - there is no bug in libdm - libdm expects udev to create nodes. You can reconfigure libdm to do this job instead of udev - but then nothing else will work with it - so it's basically dead-road...

It doesn't matter who creates it, what matters is that when parted asks what the correct name is, that it be told the name that actually is created.

Quoted 3 lines

The best you can do is to not use names which needs mangling - that's my best suggestions (and lvm team already spend countless hours on some usable workarounds and solutions...)

Unfortunately, it seems that a number of hardware vendors ship preconfigured fakeraid setups with a space in the name of the volume.

Quoted 2 lines

For mangling see 'dmsetup mangle' help - how to obtain device names...

Is there a libdevmapper call to do this?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJTDlQcAAoJEI5FoCIzSKrw3Z8H/3pS3uLG9vcQOrVba4KMxjN6 PY1uPGCWIUyqiGUYxzyleyAXp7TVyNpvomPEuevToSaEQBjL60jBUW1NNSiqPmsz Dk9DDGzF7ecmQ3p4w6jPn0+RBKNvLU1jZygxCsMW3A9c2iqhuICkKD+MMDzjj2bw Af/M6fT8aJBUWCeLeT+egKY2vVHP59j0AyNwj2ei4pBZ+Y2gOoecJTB+kZB7VgJ+ MoY8VdQaQGhMKQLtmmkD5kIDbe7x8f1mYj4y1BUhzvnemu4vpFn7s5wOE41+9cTk F5J0GWE6OgNQ3oXLktpkt50hQH72rAOOrnlzEpx/SobH6l1oEtB0XpJdyVuiIAc= =kiNS
-----END PGP SIGNATURE-----

#5 lore raw

Dne 26.2.2014 21:52, Phillip Susi napsal(a):

Quoted 4 lines

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2/26/2014 2:12 PM, Zdenek Kabelac wrote:

Quoted 9 lines
Quoted 4 lines

As said - there is no bug in libdm - libdm expects udev to create nodes. You can reconfigure libdm to do this job instead of udev - but then nothing else will work with it - so it's basically dead-road...

It doesn't matter who creates it, what matters is that when parted asks what the correct name is, that it be told the name that actually is created.

I assume you will need to learn why it does matter - it's the crucial part of this puzzle - but it's surely not a topic for lvm-devel list.

And as I've also already said - yes it really does mean that many userspace tools need be adapted to handle things in more user friendly way.

Quoted 6 lines
Quoted 3 lines

The best you can do is to not use names which needs mangling - that's my best suggestions (and lvm team already spend countless hours on some usable workarounds and solutions...)

Unfortunately, it seems that a number of hardware vendors ship preconfigured fakeraid setups with a space in the name of the volume.

It have to be dealt with them properly on user level part. User level needs to use some different names for such devices.

It's currently highly discouraged to create devices with 'prohibited' characters in them - since the rest will fail to process them properly.

You really can't expect udev will start to support spaces in names.... So tools like 'mount' will need to know how to translate...

Quoted 6 lines
Quoted 3 lines

For mangling see 'dmsetup mangle' help - how to obtain device names...

Is there a libdevmapper call to do this?

https://git.fedorahosted.org/cgit/lvm2.git/tree/libdm/libdevmapper.h

Look for 'mangle' in function names.

For 'howto' look at dmsetup.c source code:

https://git.fedorahosted.org/cgit/lvm2.git/tree/tools/dmsetup.c

There is not much better doc for these function unfortunately. I'd strongly advise to stay on 'dmsetup' level of usage.

It would also probably help to describe what kind of app which uses libdevmapper you are trying to develop...

Regards

Zdenek

#6 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 2 lines · Zdenek Kabelac

It would also probably help to describe what kind of app which uses libdevmapper you are trying to develop...

I'm trying to fix parted to not fail on such devices. As I said originally it fails because it calls dm_task_get_name() to find out the true /dev/mapper/ name of the device, so that it can add the partition number to it and be able to open the partition. Now that I look at the comment in the headers, it sounds like perhaps it just should be using dm_task_get_name_mangled() instead.

I'm also still wondering why udev can't simply handle quoted names with spaces in them. People have been dealing with this sort of thing in shell for years...

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJTDmfpAAoJEI5FoCIzSKrw+0YH/3i/a7dihHXuM1nGxkL16E+e Er2X7PoVnowBKVW7kk9bHXKOO5vZeSAArcYflmgcernBXTjBhyXFi8wtwuxtWIRc nesNV26dQz5I7Qh9l9tVt9kCuCwGs/UT/V4vnyPAIf+O5pnwFyy32d2CjnMVztTa QBRmS9CoeurQkj5s+BFGI+vyM3Uul5SA3Ymaf/qIWC8xQXMNUisro5ytwzXT5tJ5 jT5yK754wxw8V6bgFOTBssOaLKOetMklMHSgfW2+XWuhFduGNAOdeM5dbqJlW1Wr RSxEaTu4EvvuBcnYe/APuuOW6JUwG+Uf4Ut/gyMoWc8dRKXsPb2UMm694FRy8Rk= =6ZPG
-----END PGP SIGNATURE-----

#7 lore raw
Quoted 3 lines · Phillip Susi

I'm also still wondering why udev can't simply handle quoted names with spaces in them. People have been dealing with this sort of thing in shell for years...

Once you've had exposure to udev you soon learn that "wondering why" gets you nowhere:) However bizarre, your only option is to conform. Name mangling in lvm2/device-mapper was designed both to conform and to still allow for all possibilities in as transparent a way as we could.

The primary new limitation is a reduction in the effective maximum length of a device name due to the quoting. If this becomes a problem we will have to extend the kernal API to support longer names.

Alasdair

#8 lore raw
In reply to Phillip Susi
Quoted 3 lines · Phillip Susi

I'm also still wondering why udev can't simply handle quoted names with spaces in them. People have been dealing with this sort of thing in shell for years...

We tried that: https://bugzilla.redhat.com/show_bug.cgi?id=736486#c12

And this was not the only request from us to fix something in udev. But based on previous experience, we concluded that it was just useless to try spending time with persuading the other side.

If you have enough nerves to argue with them, I'm really and sincerely wishing you good luck.

Signature · 1 line
Peter
#9 lore raw
In reply to Phillip Susi
Quoted 6 lines · Phillip Susi

I'm trying to fix parted to not fail on such devices. As I said originally it fails because it calls dm_task_get_name() to find out the true /dev/mapper/ name of the device, so that it can add the partition number to it and be able to open the partition. Now that I look at the comment in the headers, it sounds like perhaps it just should be using dm_task_get_name_mangled() instead.

Yes, you can call that fn to get the name in its actual "mangled" form as it appears in /dev/mapper.

Signature · 1 line
Peter