Skip to contentSkip to conversation

Hacking linux-utils for swap label

DISCUSSION Loiseleur Michel 5 participants 9 messages Apr 13, 2006 VFS

lore
Share & tools
lore
#0 lore raw

Hello everyone,

It's my first time in hacking something so deep in linux, so please
don't be too hard on me. It concerns the code packaged in "linux-utils", I hope I have found the correct mailing list.

Here is the problem :
I need a way in shell script to get back the device name from the
label name, in order to restore (ie: format) it correctly in a recovery solution (mondorescue).
For instance, a call to "e2label" do the job for the ext2/3 kind of
partition.
But for swap partition, there is _no_ way to get it back. The name
didn't appear in /proc/swaps or /proc/partitions.

Here is my current hacking:
I have developped myself a small "addon" to swapon/swapoff program,
named _swaplabel_, which display the list of device, uuid and name of all the partitions. It was really easy, this code is old but so damn cool !

Here is the question :
1) Is this possible to enhance linux-utils in order to do the job ?
2) What's the better way to correct this :
2.1) a new program as my "swaplabel" ?
2.2) a new option to swapon ? (there is already a "-l" in it,
but it does not display the label)
2.3) a patch to the "-l" option ?
2.4) a patch to add a colum "label" in /proc/partitions ? 2.5) an other way I didn't think of ?

thanks for your help,
kind regards,

Signature · 1 line
Michel Loiseleur
#1 lore raw
Quoted 8 lines · Loiseleur Michel

Here is the problem :
I need a way in shell script to get back the device name from the
label name, in order to restore (ie: format) it correctly in a recovery solution (mondorescue).
For instance, a call to "e2label" do the job for the ext2/3 kind of
partition.
But for swap partition, there is _no_ way to get it back. The name
didn't appear in /proc/swaps or /proc/partitions.

That's because filesystem labels is a userland issue and not at all kernel related. It's also how mount label works: the userland program "mount" figures out which device contains the requested label and passes the correct device to the mount() syscall.

Quoted 9 lines

Here is my current hacking:
I have developped myself a small "addon" to swapon/swapoff program,
named _swaplabel_, which display the list of device, uuid and name of all the partitions. It was really easy, this code is old but so damn cool !

Here is the question :
1) Is this possible to enhance linux-utils in order to do the job ?
2) What's the better way to correct this :
2.1) a new program as my "swaplabel" ?

Yes, but rather name it something like dumpswap, just like dumpe2fs, etc.

Quoted 2 lines

2.2) a new option to swapon ? (there is already a "-l" in it,
but it does not display the label)

No, mount also doesn't display labels.

Quoted 2 lines

2.3) a patch to the "-l" option ?
2.4) a patch to add a colum "label" in /proc/partitions ?

No, cause labels are a userland issue.

Erik

Signature · 2 lines
+-- Erik Mouw -- www.harddisk-recovery.com -- +31 70 370 12 90 --
| Lab address: Delftechpark 26, 2628 XH, Delft, The Netherlands
#2 lore raw
Quoted 31 lines · Erik Mouw
Quoted 9 lines · Loiseleur Michel

Here is the problem :
I need a way in shell script to get back the device name from the
label name, in order to restore (ie: format) it correctly in a recovery solution (mondorescue).
For instance, a call to "e2label" do the job for the ext2/3 kind of
partition.
But for swap partition, there is _no_ way to get it back. The name
didn't appear in /proc/swaps or /proc/partitions.

That's because filesystem labels is a userland issue and not at all kernel related. It's also how mount label works: the userland program "mount" figures out which device contains the requested label and passes the correct device to the mount() syscall.

Quoted 10 lines

Here is my current hacking:
I have developped myself a small "addon" to swapon/swapoff program,
named _swaplabel_, which display the list of device, uuid and name of all the partitions. It was really easy, this code is old but so damn cool !

Here is the question :
1) Is this possible to enhance linux-utils in order to do the job ?
2) What's the better way to correct this :
2.1) a new program as my "swaplabel" ?

Quoted 4 lines

Yes, but rather name it something like dumpswap, just like dumpe2fs, etc.

This is not exactly what I need. I don't know how to dress the full map of a swap file/partition, and I don't need it. I just need to retrieve the link between 'device' and 'label' put in /etc/fstab. After reading the code in linux-utils package (mount/swapon.c & mount/get_label_uuid.c), I figured out how to implement it in C. But I need it in shell script >_<. The program I want to add is nearer of e2label program (ext2/3 equivalent). That's why I suggested the name "swaplabel", which would be functionally equivalent to e2label.

Quoted 10 lines
Quoted 6 lines

2.2) a new option to swapon ? (there is already a "-l" in it,
but it does not display the label)

No, mount also doesn't display labels.

ok

Quoted 10 lines
Quoted 6 lines

2.3) a patch to the "-l" option ?
2.4) a patch to add a colum "label" in /proc/partitions ?

No, cause labels are a userland issue.

Yes, you're right. I wanted to join linux-utils developers, and it's the mailing list which seems the good one for me.

Thanks for your advice, erik.

Signature · 6 lines
Michel Loiseleur

-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
In reply to Loiseleur Michel
Quoted 31 lines · Loiseleur Michel

Hello everyone,

It's my first time in hacking something so deep in linux, so please
don't be too hard on me. It concerns the code packaged in "linux-utils", I hope I have found the correct mailing list.

Here is the problem :
I need a way in shell script to get back the device name from the
label name, in order to restore (ie: format) it correctly in a recovery solution (mondorescue).
For instance, a call to "e2label" do the job for the ext2/3 kind of
partition.
But for swap partition, there is _no_ way to get it back. The name
didn't appear in /proc/swaps or /proc/partitions.

Here is my current hacking:
I have developped myself a small "addon" to swapon/swapoff program,
named _swaplabel_, which display the list of device, uuid and name of all the partitions. It was really easy, this code is old but so damn cool !

Here is the question :
1) Is this possible to enhance linux-utils in order to do the job ?
2) What's the better way to correct this :
2.1) a new program as my "swaplabel" ?
2.2) a new option to swapon ? (there is already a "-l" in it,
but it does not display the label)
2.3) a patch to the "-l" option ?
2.4) a patch to add a colum "label" in /proc/partitions ? 2.5) an other way I didn't think of ?

Quoted 3 lines

thanks for your help,
kind regards,

May be I don't understand something, but there is
http://e2fsprogs.sourceforge.net/
and it contains blkid utility and which used for handle LABEL= in /etc/fstab,
in spite of name it handles many types of file systems and swap partitions also.

Signature · 1 line
/Evgeniy
#4 lore raw
Quoted 36 lines · Evgeniy Dushistov
Quoted 28 lines · Loiseleur Michel

Hello everyone,

It's my first time in hacking something so deep in linux, so please
don't be too hard on me. It concerns the code packaged in "linux-utils", I hope I have found the correct mailing list.

Here is the problem :
I need a way in shell script to get back the device name from the
label name, in order to restore (ie: format) it correctly in a recovery solution (mondorescue).
For instance, a call to "e2label" do the job for the ext2/3 kind of
partition.
But for swap partition, there is _no_ way to get it back. The name
didn't appear in /proc/swaps or /proc/partitions.

Here is my current hacking:
I have developped myself a small "addon" to swapon/swapoff program,
named _swaplabel_, which display the list of device, uuid and name of all the partitions. It was really easy, this code is old but so damn cool !

Here is the question :
1) Is this possible to enhance linux-utils in order to do the job ?
2) What's the better way to correct this :
2.1) a new program as my "swaplabel" ?
2.2) a new option to swapon ? (there is already a "-l" in it,
but it does not display the label)
2.3) a patch to the "-l" option ?
2.4) a patch to add a colum "label" in /proc/partitions ? 2.5) an other way I didn't think of ?

Quoted 5 lines

thanks for your help,
kind regards,

Quoted 8 lines

May be I don't understand something, but there is
http://e2fsprogs.sourceforge.net/
and it contains blkid utility and which used for handle LABEL= in /etc/fstab,
in spite of name it handles many types of file systems and swap partitions also.

Thanks a lot to you. It was ... hum ... not obvious. I can do the job with it. No needs to patch anything ! I can parse in shell script the output of "blkid".

kind regards,

Signature · 6 lines
Michel

-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#5 lore raw
In reply to Evgeniy Dushistov
Quoted 6 lines · Evgeniy Dushistov

May be I don't understand something, but there is
http://e2fsprogs.sourceforge.net/
and it contains blkid utility and which used for handle LABEL= in /etc/fstab,
in spite of name it handles many types of file systems and swap partitions also.

vol_id in the udev package is much better than blkid, as it handles more file system types, and is easier to intregrate into other programs and scripts (it's also availble as a library.) I would recommend it instead.

thanks,

greg k-h

#6 lore raw
Quoted 4 lines · Greg KH

vol_id in the udev package is much better than blkid, as it handles more file system types, and is easier to intregrate into other programs and scripts (it's also availble as a library.) I would recommend it instead.

For the record, blkid is also available as a library, and it is what is used by mount and fsck to support. Blkid also has the advantage that it doesn't require a modern 2.6 kernel to function (since it isn't dependent on udev) in order to find the device where a particular filesystem with a particular label or UUID. Blkid is available on pretty much all distributions since it's been part of e2fsprogs since 2002 or so; udev is used available on all reasonably modern distro's using a 2.6 kernel.

Finally, the number of filesystem types handled by the two really aren't all that different; certainly all of the major filesystem types are covered by both libraries/programs.

Regards,

- Ted

#7 lore raw
Quoted 4 lines · Theodore Ts'o

Blkid also has the advantage that it doesn't require a modern 2.6 kernel to function (since it isn't dependent on udev) in order to find the device where a particular filesystem with a particular label or UUID.

I don't see that requirement anywhere in the vol_id code. It's a stand-alone binary that should work with just about any kernel version, as it just talks to the block device directly. No udev requirement at all (it just happens to live in the udev source tree for now, I think that's changing as HAL and some other utilities are starting to rely on it.)

Anyway, I don't have any objection to blkid, just trying to point out another solution, instead of having the original poster try to reinvent the wheel again :)

thanks,

greg k-h

#8 lore raw
Quoted 6 lines · Greg KH

I don't see that requirement anywhere in the vol_id code. It's a stand-alone binary that should work with just about any kernel version, as it just talks to the block device directly. No udev requirement at all (it just happens to live in the udev source tree for now, I think that's changing as HAL and some other utilities are starting to rely on it.)

The blkid library/program does many things, beyond just simply identifying the filesystem type, label, and uuid given a particular device. In particular, the blkid library uses a cache (so you don't have to scan all of the attached block devices, which in the case of a system with a truly vast number of san attached storage devices, could take very long time), so that an application can find a block device given a particular label or uuid as a search parameter.

That was what was originally requested, and that is something which vol_id can not do unassisted (but which blkid can do, either from the command-line or from the C library interface).

Udev can provide this functionality, if you are running on a modern distribution that uses udev, and it does so by scanning all block devices at hotplug/coldplug time. I'm not entirely convinced that is the right approach if there are several hundred thousand potential devices available via a SAN fabric, or via iSCSI --- and to be fair, blkid probably won't be enough in that environment, either. But it provides a nice abstraction interface so that in the future, blkid could optionally call out to some directory service to find the location of the iSCSI device. In contrast, the udev solution to the find-the-device-given-a-uuid assumes that a symlink has been created, which makes it more difficult to trap the request to look for a particular UUID/label.

Quoted 3 lines

Anyway, I don't have any objection to blkid, just trying to point out another solution, instead of having the original poster try to reinvent the wheel again :)

And I don't have an objection to udev, although I'm not convineced it's proposed solution for finding block devices given a UUID or label is the best one....

- Ted