vendredi 28 novembre 2014

How do I figure out what is preventing a bind mount from unmounting?


I have a problem with a mountpoint being too busy to unmount. Normally, lsof or fuser would tell me what process is using it, but this is a bind mount, so lsof and fuser show what is using both the original mountpoint, and the bind mountpoint.


Ex:


Mount the filesystems:



$ sudo mkdir /mnt/mount /mnt/bind
$ sudo mount /dev/sdb1 /mnt/mount
$ sudo mount -o bind /mnt/mount /mnt/bind


Start a process that keeps /mnt/mount too busy to unmount



$ sudo dd if=/dev/zero of=/mnt/mount/testfile bs=1 oflag=dsync


Check what fuser says



$ sudo fuser -m /mnt/mount
/mnt/mount: 4022
$ sudo fuser -m /mnt/bind
/mnt/bind: 4022


Check what lsof says



$ sudo lsof +D /mnt/mount
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
dd 4022 root 1w REG 8,17 28545 12 /mnt/mount/testfile

$ sudo lsof +D /mnt/bind
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
dd 4022 root 1w REG 8,17 40682 12 /mnt/bind/testfile


Try to unmount both



$ sudo umount -v *
umount: /mnt/bind (/mnt/mount) unmounted
umount: /mnt/mount: target is busy


If you follow the same steps, but tell dd to write the file to /mnt/bind/testfile instead, unmounting /mnt/mount will be successful, but unmounting /mnt/bind will fail.


Clearly it makes a difference which mountpoint the process (dd in this case) is using, but lsof and fuser do not differentiate. Is there something that does?



Aucun commentaire:

Enregistrer un commentaire