Bug 1575952 - DVD can be ejected even though it is mounted
Summary: DVD can be ejected even though it is mounted
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: systemd
Version: 7.5
Hardware: Unspecified
OS: Unspecified
Target Milestone: rc
: ---
Assignee: systemd-maint
QA Contact: qe-baseos-daemons
Depends On:
TreeView+ depends on / blocked
Reported: 2018-05-08 11:42 UTC by Renaud Métrich
Modified: 2020-02-18 17:49 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Last Closed: 2020-02-18 17:49:58 UTC
Target Upstream Version:

Attachments (Terms of Use)

System ID Private Priority Status Summary Last Updated
Red Hat Knowledge Base (Solution) 3442081 0 None None None 2018-05-14 09:12:47 UTC

Description Renaud Métrich 2018-05-08 11:42:42 UTC
Description of problem:

On RHEL6, when the DVD is mounted, it is not possible to eject it, because the kernel locks it.

On RHEL7, whatever the DVD state is, it is always possible to eject it through pushing the Eject button of the DVD tray.
This leads to the mount point to get a I/O error upon access.

Is this expected? If so, why the behaviour has been changed?

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:
1. Mount a DVD
2. Push the eject button
3. Access the mountpoint

Actual results:

I/O error is returned

Expected results:

DVD not ejected and no I/O error

Additional info:

Digging into the code, we can see that in RHEL7, the DVD is handled by the following udev rule:

-------- 8< ---------------- 8< ---------------- 8< --------
# cat /lib/udev/rules.d/60-cdrom_id.rules
# media eject button pressed
ENV{DISK_EJECT_REQUEST}=="?*", RUN+="cdrom_id --eject-media $devnode", GOTO="cdrom_end"

# import device and media properties and lock tray to
# enable the receiving of media eject button events
IMPORT{program}="cdrom_id --lock-media $devnode"
-------- 8< ---------------- 8< ---------------- 8< --------

The "cdrom_id" utility is responsible for locking the media, unlocking it and ejecting.

Upon pushing the Eject button, a "DISK_EJECT_REQUEST=1" event is sent by the kernel, causing "cdrom_id --eject-media $devnode" to be executed.
This code does unlock the media, then ejects the tray.

This explains the new behaviour: unlocking the media always works for some reason (likely because the DVD is mounted read-only), hence eject works afterwards, even if the DVD remains mounted, leading to some I/O error upon access, as shown in the scenario below:

-------- 8< ---------------- 8< ---------------- 8< --------
# mount /dev/sr1 /mnt
mount: /dev/sr1 is write-protected, mounting read-only

--> push Eject button

# ls /mnt
ls: reading directory /mnt: Input/output error
-------- 8< ---------------- 8< ---------------- 8< --------

Comment 2 Renaud Métrich 2018-05-08 11:44:09 UTC
A workaround is to subsume the standard udev rule by creating the following script in /usr/local/bin:

-------- 8< ---------------- 8< ---------------- 8< --------
# cat /usr/local/bin/eject_cdrom.sh
# Script locking the CD when mounted.
# For demo purposes only, not supported by Red Hat in any way!!!


if ! awk "\$1 == \"$DEVICE\" { exit 1 }" /proc/mounts; then
	logger -t "$(basename $0)" "There is a CDROM, ignoring EJECT request."
	/usr/lib/udev/cdrom_id --eject-media $DEVICE

# chmod +x /usr/local/bin/eject_cdrom.sh
-------- 8< ---------------- 8< ---------------- 8< --------

Then, copy the /lib/udev/rules.d/60-cdrom_id.rules file into /etc/udev/rules.d so that udev uses the latter as an overload (it will disable the original rules in /lib/udev/rules.d/60-cdrom_id.rules):

-------- 8< ---------------- 8< ---------------- 8< --------
# cp /lib/udev/rules.d/60-cdrom_id.rules /etc/udev/rules.d/
-------- 8< ---------------- 8< ---------------- 8< --------

Finally, edit the /etc/udev/rules.d/60-cdrom_id.rules file to use the /usr/local/bin/eject_cdrom.sh command instead of the original "cdrom_id" command on the DISK_EJECT_REQUEST line:

-------- 8< ---------------- 8< ---------------- 8< --------
ENV{DISK_EJECT_REQUEST}=="?*", RUN+="/usr/local/bin/eject_cdrom.sh $devnode", GOTO="cdrom_end"
-------- 8< ---------------- 8< ---------------- 8< --------

You may now try to monitor the system logs.
If you have a mounted DVD and press the Eject button, nothing will happen, except the log message shown below:

-------- 8< ---------------- 8< ---------------- 8< --------
eject_cdrom.sh[13512]: There is a CDROM, ignoring EJECT request.
-------- 8< ---------------- 8< ---------------- 8< --------

If you have an unmounted DVD and press the Eject button, the button should work.

Comment 3 Lukáš Nykrýn 2018-05-09 07:50:28 UTC
Yep, this change was intentional. Users quite often think that the button on cd-rom is more hardware-ish and were wondering why they can't open it in some cases. So I would even say that the new behaviour matches the behaviour of floppy driver or usb flash drives :-).

Anyway, unless there is a strong push to change this I would like to keep the current state and create a KB article with your workaround as an official suggestion for those that want the opposite.

Comment 6 Kyle Walker 2020-02-18 17:49:58 UTC
Based on the feedback in comment 3, I am closing this as NOTABUG.

Please utilize the guidance in the following article should the alternative described behaviour be needed:

    [RHEL7] How to lock the DVD tray when a DVD is mounted - Red Hat Customer Portal

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