From: yumkam@gmail.com (Yuriy M. Kaminskiy)
To: util-linux@vger.kernel.org
Subject: Re: [PATCH] libmount: if ENOMEDIUM and tray is open, close tray and retry
Date: Thu, 27 Jul 2017 11:58:36 +0300 [thread overview]
Message-ID: <m3wp6u5k8z.fsf@gmail.com> (raw)
In-Reply-To: db7a8eaa-3519-234c-72c9-428ca1b80ff0@suse.cz
On 07/21/17 21:44 , Stanislav Brabec wrote:
> In past, d50c5917 introduced an interesting behavior: If mount was called on a
> CDROM with open tray, the tray was closed and mount was retried. But the
> implementation caused 15 seconds delay, so ca55a451 reverted it.
>
> This is another attempt to implement that:
> If tray is closed: No delay, no retry, simply fail.
> If tray is open: Check, whether the drive can close tray.
> If yes, close tray and retry after 3 seconds.
> If not, no delay, no retry, simply fail.
>
> It can never cause delay more than time to close tray + 3 sec.
>
> Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
> ---
> libmount/src/context_mount.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c
> index 65f7dbfd0..ed0b84080 100644
> --- a/libmount/src/context_mount.c
> +++ b/libmount/src/context_mount.c
> @@ -18,11 +18,15 @@
>
> #include <sys/wait.h>
> #include <sys/mount.h>
> +#include <linux/cdrom.h>
>
> #include "linux_version.h"
> #include "mountP.h"
> #include "strutils.h"
>
> +/* open() retries when errno is ENOMEDIUM and tray is open */
> +#define CRDOM_TRAYOPEN_RETRIES 5
> +
> /*
> * Kernel supports only one MS_PROPAGATION flag change by one mount(2) syscall,
> * to bypass this restriction we call mount(2) per flag. It's really not a perfect
> @@ -1292,6 +1296,8 @@ int mnt_context_get_mount_excode(
> int syserr;
> struct stat st;
> unsigned long uflags = 0, mflags = 0;
> + int cdrom;
> + unsigned int retries = 0;
>
> int restricted = mnt_context_is_restricted(cxt);
> const char *tgt = mnt_context_get_target(cxt);
> @@ -1399,6 +1405,7 @@ int mnt_context_get_mount_excode(
> /*
> * mount(2) errors
> */
> +mount_retry:
> syserr = mnt_context_get_syscall_errno(cxt);
>
>
> @@ -1563,6 +1570,19 @@ int mnt_context_get_mount_excode(
> break;
>
> case ENOMEDIUM:
> + cdrom = open(mnt_context_get_source(cxt), O_RDONLY | O_NONBLOCK);
> + if (cdrom != -1) {
> + if (retries < CRDOM_TRAYOPEN_RETRIES &&
> + (ioctl(cdrom, CDROM_GET_CAPABILITY, NULL) & CDC_CLOSE_TRAY) &&
If ioctl is not supported, and ioctl() returns -1, (ioctl() & FOO) is
true.
I guess this should be something like
+ (rc = ioctl(cdrom, CDROM_GET_CAPABILITY, NULL)) != -1 &&
+ (rc & CDC_CLOSE_TRAY) &&
instead.
> + ioctl(cdrom, CDROM_DRIVE_STATUS, NULL) == CDS_TRAY_OPEN) {
> + ioctl(cdrom, CDROMCLOSETRAY);
Error check missing?
(And, I used cdrom a long time ago, but IIRC there were some driver
settings to automatically close tray on device open, so that this patch
should not be needed?)
> + close(cdrom);
> + sleep(3);
> + ++retries;
> + goto mount_retry;
> + } else
> + close(cdrom);
> + }
> if (uflags & MNT_MS_NOFAIL)
> return MNT_EX_SUCCESS;
> if (buf)
next prev parent reply other threads:[~2017-07-27 8:58 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-21 15:12 [PATCH] libmount: if ENOMEDIUM and tray is open, close tray and retry Stanislav Brabec
2017-07-21 18:42 ` Stanislav Brabec
2017-07-21 18:44 ` Stanislav Brabec
2017-07-27 8:58 ` Yuriy M. Kaminskiy [this message]
2017-07-28 15:26 ` Stanislav Brabec
2017-07-28 15:48 ` Stanislav Brabec
2017-10-02 13:00 ` Michal Suchánek
2017-10-02 13:06 ` Stanislav Brabec
2017-10-02 13:50 ` Michal Suchánek
2017-10-02 14:11 ` Stanislav Brabec
2017-10-02 14:24 ` Michal Suchánek
2017-10-02 14:36 ` Michal Suchánek
2017-11-02 18:20 ` Michal Suchánek
2017-08-01 12:16 ` Karel Zak
2017-09-05 11:04 ` Karel Zak
2017-09-05 12:53 ` Stanislav Brabec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3wp6u5k8z.fsf@gmail.com \
--to=yumkam@gmail.com \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.