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

David Herrmann dh.herrmann at gmail.com
Thu Sep 18 04:56:52 PDT 2014


Hi again

On Thu, Sep 18, 2014 at 1:34 PM, David Herrmann <dh.herrmann at gmail.com> wrote:
> I'm putting Harald and Kay on CC, as they added O_EXCL to protect
> against parallel burning-sessions. Maybe they can tell you whether
> that is still needed today and whether we can drop it.

So my conception of O_EXCL was kinda wrong. O_EXCL on block devices
fails with EBUSY if, and only if, there's someone else also opening
the device with O_EXCL. You can still open it without O_EXCL. Now, the
kernel-internal mount helpers always keep O_EXCL for mounted block
devices. This way, user-space can open block devices via O_EXCL and be
sure no-one can mount it in parallel.

For your automounter, this means you should just drop the event on
EBUSY. If udev was the offender, you will get a follow-up event. If
fsck was the offender, you're screwed anyway as it takes ages to
complete (but fsck shouldn't be any problem for the automounter,
anyway). if anyone else is the offender, you have no idea what they
do, so you should just fail right away.

Regarding lazy-unmount: It'd require kernel support to notice such
usage in user-space. I don't plan on working on this (and nobody
really cares). But if there will be a kernel-interface, we'd gladly
accept patches to fix cdrom_id.

Thanks
David


More information about the systemd-devel mailing list