Skip to content
Commit 253c4d64 authored by Mike Fleetwood's avatar Mike Fleetwood Committed by Curtis Gedak
Browse files

Fix BlockSpecial comparison (#771670)

Found that in some cases usage of active encrypted swap was not working,
but only for the first encrypted swap partition.  This only failed on
the first Device Mapper device, dm-0:

    # ls -l /dev/mapper/ /dev/dm-*
    brw-rw---- 1 root disk 254, 0 Oct  4 20:58 /dev/dm-0
    brw-rw---- 1 root disk 254, 1 Oct  4 20:58 /dev/dm-1

    /dev/mapper/:
    total 0
    crw------- 1 root root 10,236 Oct  4 19:48 control
    lrwxrwxrwx 1 root root      7 Oct  4 20:58 sdb1_crypt -> ../dm-0
    lrwxrwxrwx 1 root root      7 Oct  4 20:58 sdb2_crypt -> ../dm-1

    # cat /proc/swaps
    Filename                        Type        Size    Used    Priority
    /dev/sda1                       partition   1524732 92356   -1
    /dev/dm-0                       partition   1046524 0       -2
    /dev/dm-1                       partition   1046524 0       -3

Was failing because the minor number of dm-0 was 0, causing BlockSpecial
operator==() to fall back to name comparison rather than major, minor
number, and GParted name /dev/mapper/sdb1_crypt doesn't match /dev/dm-0.

Found on openSUSE and Ubuntu which don't use LVM by default and don't
already have dm-0 used as an LVM Logical Volume which GParted doesn't
support.

The LINUX ALLOCATED DEVICES document [1] says block special device 0, 0
(major, minor) is not used "reserved as null device number".   (Not to
be confused with 1, 3 /dev/null the Null device).  All other
non-negative pairs are valid block special device numbers.  Therefore
update BlockSpecial operator==() accordingly; compare by major, minor
number when either is greater than 0 falling back to string compare
otherwise.  This still fits in with the BlockSpecial() constructor using
major, minor numbers 0, 0 to represent plain files.

[1] LINUX ALLOCATED DEVICES
    https://www.kernel.org/doc/Documentation/devices.txt

Bug 771670 - Usage of active encrypted swap is not shown
parent 3966cc3e
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment