Util-Linux package development
 help / color / mirror / Atom feed
From: Karel Zak <kzak@redhat.com>
To: Stanislav Brabec <sbrabec@suse.cz>
Cc: util-linux@vger.kernel.org
Subject: Re: [PATCH] libmount: if ENOMEDIUM and tray is open, close tray and retry
Date: Tue, 5 Sep 2017 13:04:13 +0200	[thread overview]
Message-ID: <20170905110413.jy24jrfd2pr7ts4k@ws> (raw)
In-Reply-To: <20170801121615.nxqolue5qv3rwlrh@ws.net.home>

On Tue, Aug 01, 2017 at 02:16:15PM +0200, Karel Zak wrote:
> On Fri, Jul 21, 2017 at 08:44:03PM +0200, Stanislav Brabec wrote:
> > @@ -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) &&
> > +			    ioctl(cdrom, CDROM_DRIVE_STATUS, NULL) == CDS_TRAY_OPEN) {
> > +				ioctl(cdrom, CDROMCLOSETRAY);
> > +				close(cdrom);
> > +				sleep(3);
> > +				++retries;
> > +				goto mount_retry;
> > +			} else
> > +				close(cdrom);
> > +		}
> 
> This cannot work.

Stanislav, do you want to update the patch before the next release?

    Karel

> 
> It seem you have tested the tray-close only, but I guess your goal is
> also *mount* the device. The "goto mount_retry" does not call any
> mount(2) stuff :-)
> 
> The function mnt_context_get_mount_excode() is wrong place. This
> optional function is there to generate error message and exit code.
> Nothing else.
> 
> The right place for your code is mnt_context_mount() where we already
> have the same logic ("try mount again") for read-only devices. You
> need something like:
> 
>  if (mnt_context_syscall_called(cxt) &&
>      mnt_context_get_syscall_errno(cxt) == ENOMEDIUM) {
> 
>     ... your open() and ioctls ...
> 
>     goto again;
>  }
> 
> 
> Use findmnt(8) to be sure that CDROM is really mounted.
> 
>     Karel
> 
> -- 
>  Karel Zak  <kzak@redhat.com>
>  http://karelzak.blogspot.com

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

  reply	other threads:[~2017-09-05 11:04 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
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 [this message]
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=20170905110413.jy24jrfd2pr7ts4k@ws \
    --to=kzak@redhat.com \
    --cc=sbrabec@suse.cz \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox