From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:57265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QorI8-0001j1-3R for qemu-devel@nongnu.org; Thu, 04 Aug 2011 02:20:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QorI6-0007sc-OT for qemu-devel@nongnu.org; Thu, 04 Aug 2011 02:20:24 -0400 Received: from cantor2.suse.de ([195.135.220.15]:45428 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QorI6-0007sP-Gb for qemu-devel@nongnu.org; Thu, 04 Aug 2011 02:20:22 -0400 Message-ID: <4E3A3A25.7040006@suse.de> Date: Thu, 04 Aug 2011 08:20:21 +0200 From: Hannes Reinecke MIME-Version: 1.0 References: <1312376904-16115-1-git-send-email-armbru@redhat.com> <1312376904-16115-24-git-send-email-armbru@redhat.com> In-Reply-To: <1312376904-16115-24-git-send-email-armbru@redhat.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 23/45] scsi-disk: Fix START_STOP to fail when it can't eject List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: kwolf@redhat.com, quintela@redhat.com, stefano.stabellini@eu.citrix.com, qemu-devel@nongnu.org, lcapitulino@redhat.com, amit.shah@redhat.com, hch@lst.de On 08/03/2011 03:08 PM, Markus Armbruster wrote: > Don't fail when tray is already open. > > Signed-off-by: Markus Armbruster > --- > hw/scsi-bus.c | 10 ++++++++++ > hw/scsi-disk.c | 15 +++++++++++---- > hw/scsi.h | 4 ++++ > 3 files changed, 25 insertions(+), 4 deletions(-) > > diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c > index 0b0344c..1c5fe7f 100644 > --- a/hw/scsi-bus.c > +++ b/hw/scsi-bus.c > @@ -441,6 +441,11 @@ const struct SCSISense sense_code_NO_MEDIUM =3D { > .key =3D NOT_READY, .asc =3D 0x3a, .ascq =3D 0x00 > }; > > +/* LUN not ready, medium removal prevented */ > +const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR =3D { > + .key =3D NOT_READY, .asc =3D 0x53, .ascq =3D 0x00 > +}; > + I would prefer to have the naming reversed, eg NOT_READY_REMOVAL_PREVENTED > /* Hardware error, internal target failure */ > const struct SCSISense sense_code_TARGET_FAILURE =3D { > .key =3D HARDWARE_ERROR, .asc =3D 0x44, .ascq =3D 0x00 > @@ -466,6 +471,11 @@ const struct SCSISense sense_code_LUN_NOT_SUPPORTE= D =3D { > .key =3D ILLEGAL_REQUEST, .asc =3D 0x25, .ascq =3D 0x00 > }; > > +/* Illegal request, medium removal prevented */ > +const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_ILL =3D { > + .key =3D ILLEGAL_REQUEST, .asc =3D 0x53, .ascq =3D 0x00 > +}; > + Same here: ILLEGAL_REQ_REMOVAL_PREVENTED > /* Command aborted, I/O process terminated */ > const struct SCSISense sense_code_IO_ERROR =3D { > .key =3D ABORTED_COMMAND, .asc =3D 0x00, .ascq =3D 0x06 > diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c > index 79d7737..19a1843 100644 > --- a/hw/scsi-disk.c > +++ b/hw/scsi-disk.c > @@ -828,7 +828,7 @@ static int scsi_disk_emulate_read_toc(SCSIRequest *= req, uint8_t *outbuf) > return toclen; > } > > -static void scsi_disk_emulate_start_stop(SCSIDiskReq *r) > +static int scsi_disk_emulate_start_stop(SCSIDiskReq *r) > { > SCSIRequest *req =3D&r->req; > SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, req->dev); > @@ -836,12 +836,17 @@ static void scsi_disk_emulate_start_stop(SCSIDisk= Req *r) > bool loej =3D req->cmd.buf[4]& 2; > > if (s->qdev.type =3D=3D TYPE_ROM&& loej) { > - if (!start&& s->tray_locked) { > - return; > + if (!start&& !s->tray_open&& s->tray_locked) { > + scsi_command_complete(r, CHECK_CONDITION, > + bdrv_is_inserted(s->bs) > + ? SENSE_CODE(MEDIUM_REMOVAL_PREVENTE= D_ILL) > + : SENSE_CODE(MEDIUM_REMOVAL_PREVENTE= D_NR)); > + return -1; > } > bdrv_eject(s->bs, !start); > s->tray_open =3D !start; > } > + return 0; > } > > static int scsi_disk_emulate_command(SCSIDiskReq *r, uint8_t *outbuf) > @@ -897,7 +902,9 @@ static int scsi_disk_emulate_command(SCSIDiskReq *r= , uint8_t *outbuf) > goto illegal_request; > break; > case START_STOP: > - scsi_disk_emulate_start_stop(r); > + if (scsi_disk_emulate_start_stop(r)< 0) { > + return -1; > + } > break; > case ALLOW_MEDIUM_REMOVAL: > s->tray_locked =3D req->cmd.buf[4]& 1; > diff --git a/hw/scsi.h b/hw/scsi.h > index 6b15bbc..63442c6 100644 > --- a/hw/scsi.h > +++ b/hw/scsi.h > @@ -118,6 +118,8 @@ extern const struct SCSISense sense_code_NO_SENSE; > extern const struct SCSISense sense_code_LUN_NOT_READY; > /* LUN not ready, Medium not present */ > extern const struct SCSISense sense_code_NO_MEDIUM; > +/* LUN not readt, medium removal prevented */ > +extern const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_NR; LUN not ready. Naming see above. > /* Hardware error, internal target failure */ > extern const struct SCSISense sense_code_TARGET_FAILURE; > /* Illegal request, invalid command operation code */ > @@ -128,6 +130,8 @@ extern const struct SCSISense sense_code_LBA_OUT_OF= _RANGE; > extern const struct SCSISense sense_code_INVALID_FIELD; > /* Illegal request, LUN not supported */ > extern const struct SCSISense sense_code_LUN_NOT_SUPPORTED; > +/* Illegal request, medium removal prevented */ > +extern const struct SCSISense sense_code_MEDIUM_REMOVAL_PREVENTED_ILL; See above. > /* Command aborted, I/O process terminated */ > extern const struct SCSISense sense_code_IO_ERROR; > /* Command aborted, I_T Nexus loss occurred */ Other than that it's okay. Cheers, Hannes --=20 Dr. Hannes Reinecke zSeries & Storage hare@suse.de +49 911 74053 688 SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 N=FCrnberg GF: J. Hawn, J. Guild, F. Imend=F6rffer, HRB 16746 (AG N=FCrnberg)