Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to power down HDD because of unreladed device still in use #1225

Open
calestyo opened this issue Nov 21, 2023 · 8 comments
Open

unable to power down HDD because of unreladed device still in use #1225

calestyo opened this issue Nov 21, 2023 · 8 comments
Milestone

Comments

@calestyo
Copy link

Hey.

This must have started with a recent upgrade of udisks or maybe one of its libs like libblockdev (unfortunately I don't know exactly which).

What I do is:

  • Have two HDDs connected via USB. Each has a dm-crypt LUKS container with some filesystem in it. The HDDs, LUKS and the filesystems are independent (no RAID or so).
  • Both filesystems are opened, I unmount one of them, stop the corresponding LUKS mapping and want to power off the device.

For example, if sda is the one where everything is stopped/unmounted:

# udisksctl power-off -b /dev/sda
Error powering off drive: The drive in use: Encrypted device /dev/sdb1 is unlocked (udisks-error-quark, 14)
# udisksctl power-off -b /dev/sdb
Error powering off drive: The drive in use: Encrypted device /dev/sdb1 is unlocked (udisks-error-quark, 14)

The latter makes sense, as the LUKS on sdb1 is actually still running, however, even when trying to power off sda, which has no business with sdb1, it complains about sdb1 still being unlocked.

Any ideas?

Thanks,
Chris.

@tbzatek
Copy link
Member

tbzatek commented Dec 14, 2023

Could you please provide udisksctl dump output? Looks like mismatched indexes somewhere.

Do you see a similar error by calling the D-Bus method directly? e.g.
gdbus call --system --dest org.freedesktop.UDisks2 --object-path /org/freedesktop/UDisks2/drives/VirtIO_Disk --method org.freedesktop.UDisks2.Drive.PowerOff '{}'
(remember to replace the object path with your drive object)

@calestyo
Copy link
Author

Hey.

Here's the dump:
udisksctl-dump.txt

And no, gives the same error.

# gdbus call --system --dest org.freedesktop.UDisks2 --object-path /org/freedesktop/UDisks2/drives/ST20000N_M007D_3DJ103_ABCDEFA74566 --method org.freedesktop.UDisks2.Drive.PowerOff '{}'
Error: GDBus.Error:org.freedesktop.UDisks2.Error.DeviceBusy: The drive in use: Encrypted device /dev/sda1 is unlocked

But I think I saw the problem now,... these are two identical drives, and udisks for some reason seems to identify them via ID, which are however the same for both devices:

# udisksctl info -b /dev/sda
/org/freedesktop/UDisks2/block_devices/sda:
  org.freedesktop.UDisks2.Block:
    Configuration:              []
    CryptoBackingDevice:        '/'
    Device:                     /dev/sda
    DeviceNumber:               2048
    Drive:                      '/org/freedesktop/UDisks2/drives/ST20000N_M007D_3DJ103_ABCDEFA74566'
    HintAuto:                   true
    HintIconName:               
    HintIgnore:                 false
    HintName:                   
    HintPartitionable:          true
    HintSymbolicIconName:       
    HintSystem:                 false
    Id:                         by-id-usb-ST20000N_M007D-3DJ103_ABCDEFA74566-0:0
    IdLabel:                    
    IdType:                     
    IdUUID:                     
    IdUsage:                    
    IdVersion:                  
    MDRaid:                     '/'
    MDRaidMember:               '/'
    PreferredDevice:            /dev/sda
    ReadOnly:                   false
    Size:                       20000588955648
    Symlinks:                   /dev/disk/by-diskseq/12
                                /dev/disk/by-id/usb-ST20000N_M007D-3DJ103_ABCDEFA74566-0:0
                                /dev/disk/by-path/pci-0000:00:14.0-usb-0:4.1:1.0-scsi-0:0:0:0
                                /dev/disk/by-path/pci-0000:00:14.0-usbv3-0:4.1:1.0-scsi-0:0:0:0
    UserspaceMountOptions:      
  org.freedesktop.UDisks2.PartitionTable:
    Partitions:         /org/freedesktop/UDisks2/block_devices/sda1
                        /org/freedesktop/UDisks2/block_devices/sda2
    Type:               gpt
# udisksctl info -b /dev/sdb
/org/freedesktop/UDisks2/block_devices/sdb:
  org.freedesktop.UDisks2.Block:
    Configuration:              []
    CryptoBackingDevice:        '/'
    Device:                     /dev/sdb
    DeviceNumber:               2064
    Drive:                      '/org/freedesktop/UDisks2/drives/ST20000N_M007D_3DJ103_ABCDEFA74566'
    HintAuto:                   true
    HintIconName:               
    HintIgnore:                 false
    HintName:                   
    HintPartitionable:          true
    HintSymbolicIconName:       
    HintSystem:                 false
    Id:                         by-id-usb-ST20000N_M007D-3DJ103_ABCDEFA74566-0:0
    IdLabel:                    
    IdType:                     
    IdUUID:                     
    IdUsage:                    
    IdVersion:                  
    MDRaid:                     '/'
    MDRaidMember:               '/'
    PreferredDevice:            /dev/sdb
    ReadOnly:                   false
    Size:                       20000588955648
    Symlinks:                   /dev/disk/by-diskseq/14
                                /dev/disk/by-id/usb-ST20000N_M007D-3DJ103_ABCDEFA74566-0:0
                                /dev/disk/by-path/pci-0000:00:14.0-usb-0:4.2:1.0-scsi-0:0:0:0
                                /dev/disk/by-path/pci-0000:00:14.0-usbv3-0:4.2:1.0-scsi-0:0:0:0
    UserspaceMountOptions:      
  org.freedesktop.UDisks2.PartitionTable:
    Partitions:         /org/freedesktop/UDisks2/block_devices/sdb1
                        /org/freedesktop/UDisks2/block_devices/sdb2
    Type:               gpt

Also in:

# ls -al /dev/disk/by-id/
...
lrwxrwxrwx 1 root root   9 Dec 22 05:07 usb-ST20000N_M007D-3DJ103_ABCDEFA74566-0:0 -> ../../sdb
lrwxrwxrwx 1 root root  10 Dec 22 05:07 usb-ST20000N_M007D-3DJ103_ABCDEFA74566-0:0-part1 -> ../../sdb1
lrwxrwxrwx 1 root root  10 Dec 22 05:07 usb-ST20000N_M007D-3DJ103_ABCDEFA74566-0:0-part2 -> ../../sdb2

there is only one symlink created.

There is however a sda, too... and I can mount it and it works.

Even worse, udisks seems to even fall for the duplicate when doing actions on the device:

# udisksctl power-off -b /dev/sdb 
# udisksctl power-off -b /dev/sda
Error looking up object for device /dev/sda
# udisksctl power-off -b /dev/sdb

The first call, actually powers sda off, which is why the 2nd fails, and only at the 3rd call, the real sdb is powered off.

Not sure which functionality udisks exports... but if you do offer things like formatting devices or so, I could easily imagine that this leads to using the wrong device and catastrophic data loss for people.

Cheers,
Chris.

@tbzatek
Copy link
Member

tbzatek commented Dec 27, 2023

Thanks, this explains a lot. The bogus ABCDEFA74566 serial number is a problem here - even for udev as you noted. The /dev/disk/by- symlinks actually suffer from a design deficiency and are randomly overwritten by udev rules.

Actually, your setup may be classified as a multipath scenario when multipath-aware tools are considered (do not install any as you may corrupt your data). While there's some basic support of multipath in UDisks, it's mostly harmless.

Anyway, may I ask you for udevadm info over /dev/sda and /dev/sdb? Looking for any unique identifier.

As a tentative proposed workaround, UDisks may want to ignore multipathing on devices connected over usb.

@calestyo
Copy link
Author

Well, but for udev, and most of the /dev/disk/by-* it's perfectly clear that one cannot rely on and files in there and that there will be collisions (I'd guess for any except by-path).

Actually, your setup may be classified as a multipath scenario when multipath-aware tools are considered (do not install any as you may corrupt your data).

Well these are two distinct devices, and I'd consider any software severely broken, that relies on e.g. UUID, label, serial numbers or the likes and not the true device major/minor numbers or something that's guaranteed to be unique.

Anyway, may I ask you for udevadm info over /dev/sda and /dev/sdb? Looking for any unique identifier.

Will take a while, because I'm not at home.

But anyway, I don't think there's anything except the canonical device file path (like /dev/sda/), device major/minor numbers and perhaps (but not 100% sure) /dev/disk/by-path/* links in a safe way.

Everything what a drive reports, model numbers, serial numbers, etc. pp. can all be faked by a rogue device (or by accident, like in this case).

by-id, will never be guaranteed to be safe either, simply use the canonical device file /dev/sdb or so as means for identification.

And as I've said before... depending on what udisks offers in terms of exported functionality (like wiping filesystems, creating new ones, etc. pp.), using anything that is not guaranteed - from the kernel side - to be unique, may easily lead to catastrophic data loss.

I also doubt that just applying a workaround for USB will be a proper solution. While these USB-SATA bridges are often cheap devices and they're therefore likely to do such stuff... there's no guaranteed that something like this may not also happen on SATA controller connected by other means (or just for any other block device, connected somehow).

@Galdanwing
Copy link

Galdanwing commented Mar 20, 2024

Hi, I personally also ran into this issue and am spotting something weird.

My Drive value seems to be the same for two different drives.

udisksctl info -b /dev/sdc

/org/freedesktop/UDisks2/block_devices/sdc:
  org.freedesktop.UDisks2.Block:
    Configuration:              []
    CryptoBackingDevice:        '/'
    Device:                     /dev/sdc
    DeviceNumber:               2080
    Drive:                      '/org/freedesktop/UDisks2/drives/Samsung_PSSD_T7_Shield_K533101X0JNZ67S'
    HintAuto:                   true
    HintIconName:               
    HintIgnore:                 false
    HintName:                   
    HintPartitionable:          true
    HintSymbolicIconName:       
    HintSystem:                 false
    Id:                         by-id-scsi-35000000000000001
    IdLabel:                    
    IdType:                     
    IdUUID:                     
    IdUsage:                    
    IdVersion:                  
    MDRaid:                     '/'
    MDRaidMember:               '/'
    PreferredDevice:            /dev/sdc
    ReadOnly:                   false
    Size:                       4000787030016
    Symlinks:                   /dev/disk/by-id/scsi-35000000000000001
                                /dev/disk/by-id/scsi-SSamsung_PSSD_T7_Shield_J282101X0JNZ67S
                                /dev/disk/by-id/wwn-0x5000000000000001
                                /dev/disk/by-path/pci-0000:61:00.0-usb-0:4:1.0-scsi-0:0:0:0
    UserspaceMountOptions:      
  org.freedesktop.UDisks2.PartitionTable:
    Partitions:         /org/freedesktop/UDisks2/block_devices/sdc2
                        /org/freedesktop/UDisks2/block_devices/sdc1
    Type:               gpt
udisksctl info -b /dev/sdd
/org/freedesktop/UDisks2/block_devices/sdd:
  org.freedesktop.UDisks2.Block:
    Configuration:              []
    CryptoBackingDevice:        '/'
    Device:                     /dev/sdd
    DeviceNumber:               2096
    Drive:                      '/org/freedesktop/UDisks2/drives/Samsung_PSSD_T7_Shield_K533101X0JNZ67S'
    HintAuto:                   true
    HintIconName:               
    HintIgnore:                 false
    HintName:                   
    HintPartitionable:          true
    HintSymbolicIconName:       
    HintSystem:                 false
    Id:                         by-id-scsi-35000000000000001
    IdLabel:                    
    IdType:                     
    IdUUID:                     
    IdUsage:                    
    IdVersion:                  
    MDRaid:                     '/'
    MDRaidMember:               '/'
    PreferredDevice:            /dev/sdd
    ReadOnly:                   false
    Size:                       4000787030016
    Symlinks:                   /dev/disk/by-id/scsi-35000000000000001
                                /dev/disk/by-id/scsi-SSamsung_PSSD_T7_Shield_K493101X0JNZ67S
                                /dev/disk/by-id/wwn-0x5000000000000001
                                /dev/disk/by-path/pci-0000:00:14.0-usb-0:5:1.0-scsi-0:0:0:0
    UserspaceMountOptions:      
  org.freedesktop.UDisks2.PartitionTable:
    Partitions:         /org/freedesktop/UDisks2/block_devices/sdd2
                        /org/freedesktop/UDisks2/block_devices/sdd1
    Type:               gpt

This value Samsung_PSSD_T7_Shield_K533101X0JNZ67S seems to be based off of the serial number of one drive.

 lsblk -o SERIAL,NAME
SERIAL            NAME
                  loop0
                  loop1
                  loop2
                  loop3
                  loop4
                  loop5
                  loop6
                  loop7
PWXKV0CRHEM076    sda
                  ├─sda1
                  ├─sda2
                  └─sda3
                    └─ubuntu--vg-ubuntu--lv
K533101X0JNZ67S   sdb
                  ├─sdb1
                  └─sdb2
J282101X0JNZ67S   sdc
                  ├─sdc1
                  └─sdc2
K493101X0JNZ67S   sdd
                  ├─sdd1
                  └─sdd2

I hope this helps in finding the potential issue, but to me it looks like there's some problems with not working well when two of the same drives are connected..

This is on version 2.9.4 If that helps

@tbzatek
Copy link
Member

tbzatek commented May 2, 2024

@Galdanwing can you provide udevadm info for both devices please? This may be a different issue.

@Galdanwing
Copy link

Sure, I'm now on v2.10.1 and still facing it:

 udisksctl power-off -b /dev/sdd
Error powering off drive: The drive in use: Device /dev/sdh2 is mounted (udisks-error-quark, 14)

udevadm /dev/sdd:

udevadm info /dev/sdd
P: /devices/pci0000:60/0000:60:00.0/0000:61:00.0/usb7/7-3/7-3:1.0/host4/target4:0:0/4:0:0:0/block/sdd
M: sdd
U: block
T: disk
D: b 8:48
N: sdd
L: 0
S: disk/by-id/usb-Samsung_PSSD_T7_Shield_S76ZNS0WB04073D-0:0
S: disk/by-id/wwn-0x5000000000000001
S: disk/by-id/scsi-SSamsung_PSSD_T7_Shield_D37040BW0SNZ67S
S: disk/by-id/scsi-35000000000000001
S: disk/by-path/pci-0000:61:00.0-usb-0:3:1.0-scsi-0:0:0:0
S: disk/by-diskseq/34
Q: 34
E: DEVPATH=/devices/pci0000:60/0000:60:00.0/0000:61:00.0/usb7/7-3/7-3:1.0/host4/target4:0:0/4:0:0:0/block/sdd
E: DEVNAME=/dev/sdd
E: DEVTYPE=disk
E: DISKSEQ=34
E: MAJOR=8
E: MINOR=48
E: SUBSYSTEM=block
E: USEC_INITIALIZED=7754501246
E: SCSI_TPGS=0
E: SCSI_TYPE=disk
E: SCSI_VENDOR=Samsung
E: SCSI_VENDOR_ENC=Samsung\x20
E: SCSI_MODEL=PSSD_T7_Shield
E: SCSI_MODEL_ENC=PSSD\x20T7\x20Shield\x20\x20
E: SCSI_REVISION=0
E: ID_SCSI=1
E: ID_SCSI_INQUIRY=1
E: SCSI_IDENT_SERIAL=D37040BW0SNZ67S
E: SCSI_IDENT_LUN_NAA_REG=5000000000000001
E: ID_VENDOR=Samsung
E: ID_VENDOR_ENC=Samsung\x20
E: ID_MODEL=PSSD_T7_Shield
E: ID_MODEL_ENC=PSSD\x20T7\x20Shield\x20\x20
E: ID_REVISION=0
E: ID_TYPE=disk
E: ID_WWN_WITH_EXTENSION=0x5000000000000001
E: ID_WWN=0x5000000000000001
E: ID_BUS=scsi
E: ID_SERIAL=35000000000000001
E: ID_SERIAL_SHORT=5000000000000001
E: ID_SCSI_SERIAL=D37040BW0SNZ67S
E: MPATH_SBIN_PATH=/sbin
E: DM_MULTIPATH_DEVICE_PATH=0
E: ID_USB_MODEL=PSSD_T7_Shield
E: ID_USB_MODEL_ENC=PSSD\x20T7\x20Shield\x20\x20
E: ID_USB_MODEL_ID=61fb
E: ID_USB_SERIAL=Samsung_PSSD_T7_Shield_S76ZNS0WB04073D-0:0
E: ID_USB_SERIAL_SHORT=S76ZNS0WB04073D
E: ID_USB_VENDOR=Samsung
E: ID_USB_VENDOR_ENC=Samsung\x20
E: ID_USB_VENDOR_ID=04e8
E: ID_USB_REVISION=0
E: ID_USB_TYPE=disk
E: ID_USB_INSTANCE=0:0
E: ID_USB_INTERFACES=:080650:080662:
E: ID_USB_INTERFACE_NUM=00
E: ID_USB_DRIVER=uas
E: ID_PATH=pci-0000:61:00.0-usb-0:3:1.0-scsi-0:0:0:0
E: ID_PATH_TAG=pci-0000_61_00_0-usb-0_3_1_0-scsi-0_0_0_0
E: ID_PART_TABLE_UUID=b7c689e1-42da-48a9-9c8e-9a61203c7183
E: ID_PART_TABLE_TYPE=gpt
E: DEVLINKS=/dev/disk/by-id/usb-Samsung_PSSD_T7_Shield_S76ZNS0WB04073D-0:0 /dev/disk/by-id/wwn-0x5000000000000001 /dev/disk/by-id/scsi-SSamsung_PSSD_T7_Shield_D37040BW0SNZ67S /dev/disk/by-id/scsi-35000000000000001 /dev/disk/by-path/pci>
E: TAGS=:systemd:
E: CURRENT_TAGS=:systemd:

and of sdh:

udevadm info /dev/sdh
P: /devices/pci0000:10/0000:10:00.0/0000:11:00.0/usb5/5-3/5-3:1.0/host8/target8:0:0/8:0:0:0/block/sdh
M: sdh
U: block
T: disk
D: b 8:112
N: sdh
L: 0
S: disk/by-id/usb-Samsung_PSSD_T7_Shield_S76ZNS0X205846Y-0:0
S: disk/by-id/wwn-0x5000000000000001
S: disk/by-id/scsi-SSamsung_PSSD_T7_Shield_Y648502X0SNZ67S
S: disk/by-path/pci-0000:11:00.0-usb-0:3:1.0-scsi-0:0:0:0
S: disk/by-diskseq/38
S: disk/by-id/scsi-35000000000000001
Q: 38
E: DEVPATH=/devices/pci0000:10/0000:10:00.0/0000:11:00.0/usb5/5-3/5-3:1.0/host8/target8:0:0/8:0:0:0/block/sdh
E: DEVNAME=/dev/sdh
E: DEVTYPE=disk
E: DISKSEQ=38
E: MAJOR=8
E: MINOR=112
E: SUBSYSTEM=block
E: USEC_INITIALIZED=80595512555
E: SCSI_TPGS=0
E: SCSI_TYPE=disk
E: SCSI_VENDOR=Samsung
E: SCSI_VENDOR_ENC=Samsung\x20
E: SCSI_MODEL=PSSD_T7_Shield
E: SCSI_MODEL_ENC=PSSD\x20T7\x20Shield\x20\x20
E: SCSI_REVISION=0
E: ID_SCSI=1
E: ID_SCSI_INQUIRY=1
E: SCSI_IDENT_SERIAL=Y648502X0SNZ67S
E: SCSI_IDENT_LUN_NAA_REG=5000000000000001
E: ID_VENDOR=Samsung
E: ID_VENDOR_ENC=Samsung\x20
E: ID_MODEL=PSSD_T7_Shield
E: ID_MODEL_ENC=PSSD\x20T7\x20Shield\x20\x20
E: ID_REVISION=0
E: ID_TYPE=disk
E: ID_WWN_WITH_EXTENSION=0x5000000000000001
E: ID_WWN=0x5000000000000001
E: ID_BUS=scsi
E: ID_SERIAL=35000000000000001
E: ID_SERIAL_SHORT=5000000000000001
E: ID_SCSI_SERIAL=Y648502X0SNZ67S
E: MPATH_SBIN_PATH=/sbin
E: DM_MULTIPATH_DEVICE_PATH=0
E: ID_USB_MODEL=PSSD_T7_Shield
E: ID_USB_MODEL_ENC=PSSD\x20T7\x20Shield\x20\x20
E: ID_USB_MODEL_ID=61fb
E: ID_USB_SERIAL=Samsung_PSSD_T7_Shield_S76ZNS0X205846Y-0:0
E: ID_USB_SERIAL_SHORT=S76ZNS0X205846Y
E: ID_USB_VENDOR=Samsung
E: ID_USB_VENDOR_ENC=Samsung\x20
E: ID_USB_VENDOR_ID=04e8
E: ID_USB_REVISION=0
E: ID_USB_TYPE=disk
E: ID_USB_INSTANCE=0:0
E: ID_USB_INTERFACES=:080650:080662:
E: ID_USB_INTERFACE_NUM=00
E: ID_USB_DRIVER=uas
E: ID_PATH=pci-0000:11:00.0-usb-0:3:1.0-scsi-0:0:0:0
E: ID_PATH_TAG=pci-0000_11_00_0-usb-0_3_1_0-scsi-0_0_0_0
E: ID_PART_TABLE_UUID=5ea38d5c-bccf-41ec-9e0f-5e5bd7d1ec1f
E: ID_PART_TABLE_TYPE=gpt
E: DEVLINKS=/dev/disk/by-id/usb-Samsung_PSSD_T7_Shield_S76ZNS0X205846Y-0:0 /dev/disk/by-id/wwn-0x5000000000000001 /dev/disk/by-id/scsi-SSamsung_PSSD_T7_Shield_Y648502X0SNZ67S /dev/disk/by-path/pci-0000:11:00.0-usb-0:3:1.0-scsi-0:0:0:0 >
E: TAGS=:systemd:
E: CURRENT_TAGS=:systemd:

@tbzatek tbzatek added this to the udisks-2.11.0 milestone May 15, 2024
@Galdanwing
Copy link

I have now also tried to do it via any of the other /dev/disk/ links, but they all fail. Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants