Bug 511409 - Cannot remount encrypted USB disk after unclean ejection.
Cannot remount encrypted USB disk after unclean ejection.
Status: CLOSED UPSTREAM
Product: Fedora
Classification: Fedora
Component: DeviceKit-disks (Show other bugs)
rawhide
All Linux
low Severity medium
: ---
: ---
Assigned To: David Zeuthen
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2009-07-14 21:09 EDT by Saikat Guha
Modified: 2009-10-02 13:56 EDT (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-10-02 13:17:00 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Saikat Guha 2009-07-14 21:09:55 EDT
Description of problem:
Error message after entering password when plugging in a USB disk after it fell off:
Unable to mount 363 GB Encrypted

Error unlocking device: cryptsetup exited with exit code 239: Command failed: Device devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 already exists.

Version-Release number of selected component (if applicable):
cryptsetup-luks-1.0.7-0.1.fc12.x86_64

How reproducible:
Always

Steps to Reproduce:
1.Uncleanly unplug USB device with mounted encrypted partition.
2.Plug in same device. Wait for gnome password prompt. Enter password.
  
Actual results:
Error

Expected results:
Device is mounted.

Additional info:
Comment 1 Saikat Guha 2009-09-04 16:54:05 EDT
Remounting encrypted disk after unclean dismount requires reboot.

Error unlocking device: cryptsetup exited with exit code 239: Command failed: Device devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 already exists.

[root@dent ~]# ls -l /dev/mapper/devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 
brw-rw---- 1 root disk 253, 3 2009-09-04 02:43 /dev/mapper/devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500

[root@dent root]# lsof /dev/mapper/devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 
[root@dent ~]#

[root@dent ~]# cryptsetup luksClose /dev/mapper/devkit-disks-luks-uuid-e0aaaf5e-2818-4ac2-8d75-b8bd1a13c1a3-uid500 
Command failed: Device busy
Comment 2 David Zeuthen 2009-10-02 13:17:00 EDT
Handling devices in use suddenly disappearing is very difficult and it should probably be done in the kernel instead of trying to piece things together in user space. 

I've opened a bug at

 https://bugs.freedesktop.org/show_bug.cgi?id=24279

to discuss this. Ideally we'd fix the kernel to do this. So I'm closing this as UPSTREAM.

For now, the answer to this bug report is "Don't do it", e.g. you need to properly unmount the device before removing it. It is not a very satisfying answer but that's how things work right now.
Comment 3 Milan Broz 2009-10-02 13:56:18 EDT
Command failed: Device busy
error means, that device is open (mounted fs). Someone must umount the fs first.

If the underlying device disappears, cryptsetup luksClose should remove it without problems - just it must have open_count == 0 (see dmsetup info).

If the device is reinserted, new disk is probably allocated (like sdb->sdc) so it cannot work with the original mapping pointing to sdb.

Maybe there should be some handler reacting to usb remove event, which force umount and remove encrypted fs and disc. The same problem exist without crypto - just disconect disk with mounted fs.

So what fails/missing here is probably force umount fs on disk which dissappeared. Hardly to imagine that this can be done in kernel space.

See:
(removed usb disk)

# cryptsetup luksClose bad
Command failed: Device busy
# umount -f /mnt/tst
# cryptsetup luksClose bad
ok

(if you reinsert disk between these steps, new device appears. but because of name and uuid conflict for existing crypt it cannot be created)

Note You need to log in before you can comment on or make changes to this bug.