[CentOS] kpartx can not detach

Sat Mar 10 22:33:51 UTC 2018
Leon Fauster <leonfauster at googlemail.com>

Am 07.03.2018 um 19:35 schrieb Jim Perrin <jperrin at centos.org>:
> On 03/07/2018 04:48 AM, Leon Fauster wrote:
>> OS: EL6 - sometimes I use 
>> kpartx -a /mnt/.../lvdisk.img 
>> to map the partitions and mount them via 
>> /dev/mapper/loop0pX
>> After using the disk (unmounting it) I noticed that 
>> detaching such mapping via kpartx -d does not result 
>> in freeing up the loop devices. Results: System reboots 
>> shows that the filesystem where lvdisk.img is located 
>> can't be unmounted. 
>> lsof, fuser, ps does not show any usage. Even removing the 
>> device node via 
>> dmsetup remove /dev/mapper/loop0pX
>> does not help. Trying to unmount the underlying filesystem 
>> still shows /mnt: device is busy.
>> Any other suggestions would be greatly appreciated!
> Do you have an open shell/terminal session hanging out in the /mnt
> directory you used?

With some heuristic I got following results (briefly): 

Jumping into the image/file directory and adding the partition map (kpartx -a) and removing it (kpartx -d) works!

So the output of losetup between this two activities shows:

losetup -a
/dev/loop0: [0821]:130822 (kvm-system-centos6_x86_64-devel-lv_vm_intern_spare.img)

but when adding the partition map with an absolut _long_ path detaching/deleting the map doesn't work.

losetup -a
/dev/loop0: [0821]:130822 (/mnt/pool/VirtLibrary/3-live/kvm-system-centos6_x86_64-devel-l*)

shortening the path and adding the partition map with an absolut path and removing it works again.

losetup -a
/dev/loop0: [0821]:130822 (/mnt/kvm-system-centos6_x86_64-devel-lv_vm_intern_spare.img)

So, is kpartx or the underlying loop handle limited to a 64 character long file pointer?

Anyway, at least I can work around it ...