[systemd-devel] cdrom_id opens device with O_EXCL, why?

Hoyer, Marko (ADITG/SW2) mhoyer at de.adit-jv.com
Thu Sep 18 00:32:43 PDT 2014


> -----Original Message-----
> From: Hoyer, Marko (ADITG/SW2)
> Sent: Thursday, September 18, 2014 8:22 AM
> To: systemd-devel at lists.freedesktop.org
> Subject: cdrom_id opens device with O_EXCL, why?
> 
> Hello together,
> 
> I recently stumbled over cdrom_id opening the device with the O_EXCL flag set,
> if it is not currently mounted:
> 
> "fd = open(node, O_RDONLY|O_NONBLOCK|(is_mounted(node) ? 0 : O_EXCL));"
> 
> The effect of this is that automatically mounting a cdrom sometimes results in
> "resource busy", if "change" uevents of the devices are processed by udevd
> while the automounter (udisks or something different in my case) is currently
> trying to mount the device triggered by a previous "add" or "change" uevent.
> 
> I've to questions to this issue. Maybe someone of you can help me:
> 
> 1. Is there any particular reason why cdrom_id should open the device
> exclusively (especially since it is not opened exclusively when it is already
> mounted)?
> 
> 2. If there is any good reason to keep this behavior: How is the best way for
> an automounter to deal with this? Retry? Something different?
> 
> 
> Thx in advance for valuable input.
> 

There is one additional more general issue with the behavior of cdrom_id.

- Insert a cdrom and mount it.
- "cd" into the mounted subtree of the cdrom
- do an lazy unmount (umount -l /dev/sr0)

>From now on, cdrom_id will fail completely due to the following reasons:
- the bash which "cd"ed into the mounted sub tree creates busy i-nodes
- this keeps the kernel from releasing the /dev/sr0 node
- the lazy umount appears to the userspace as if nothing is mounted any more (no entry in /proc/self/mountinfo, which is evaluated by cdrom_id)
- due to this, cdrom_id tries to open the device exclusively, which fails
- after 20 retries, cdrom_id finally fails

The kernel itself is able to deal with this issue. Even though we have this busy i-nodes hanging around in the back, it allows mounting the cd drive again at a different position. So the only blocker seems to me is cdrom_id, failing opening the device exclusively.

Any comments?

Best regards

Marko Hoyer
Software Group II (ADITG/SW2)

Tel. +49 5121 49 6948



More information about the systemd-devel mailing list