Received: from eggs.gnu.org ([2001:4830:134:3::10]:49159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VykFZ-0002LZ-Q2 for qemu-devel@nongnu.org; Thu, 02 Jan 2014 10:32:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VykFT-0007c4-KU for qemu-devel@nongnu.org; Thu, 02 Jan 2014 10:31:57 -0500 Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 7.1 \(1827\)) From: Alexander Graf In-Reply-To: <1382099622-87967-1-git-send-email-nwhitehorn@freebsd.org> Date: Thu, 2 Jan 2014 16:31:46 +0100 Content-Transfer-Encoding: quoted-printable Message-Id: References: <1382099622-87967-1-git-send-email-nwhitehorn@freebsd.org> Subject: Re: [Qemu-devel] [PATCH] spapr_vscsi: Fix REPORT_LUNS handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Nathan Whitehorn Cc: Paolo Bonzini , qemu-ppc , QEMU Developers On 18.10.2013, at 14:33, Nathan Whitehorn = wrote: > Intercept REPORT_LUNS commands addressed either to SRP LUN 0 or the = well-known > LUN for REPORT_LUNS commands. This is required to implement the SAM = and SPC > specifications. >=20 > Since SRP implements only a single SCSI target port per connection, = the SRP > target is required to report all available LUNs in response to a = REPORT_LUNS > command addressed either to LUN 0 or the well-known LUN. Instead, QEMU = was > forwarding such requests to the first QEMU SCSI target, with the = result that > initiators that relied on this feature would only see LUNs on the = first QEMU > SCSI target. >=20 > Behavior for REPORT_LUNS commands addressed to any other LUN is not = specified > by the standard and so is left unchanged. This preserves behavior = under Linux > and SLOF, which enumerate possible LUNs by hand and so address no = commands > either to LUN 0 or the well-known REPORT_LUNS LUN. >=20 > Signed-off-by: Nathan Whitehorn This patch fails on checkpatch.pl. Please fix those warnings up :). WARNING: braces {} are necessary for all arms of this statement #65: FILE: hw/scsi/spapr_vscsi.c:738: + if (dev->channel =3D=3D 0 && dev->id =3D=3D 0 && dev->lun =3D=3D = 0) [...] WARNING: braces {} are necessary for all arms of this statement #81: FILE: hw/scsi/spapr_vscsi.c:754: + if (dev->id =3D=3D 0 && dev->channel =3D=3D 0) [...] + else [...] WARNING: line over 80 characters #108: FILE: hw/scsi/spapr_vscsi.c:781: + if ((srp->cmd.lun =3D=3D 0 || be64_to_cpu(srp->cmd.lun) =3D=3D = SRP_REPORT_LUNS_WLUN) && srp->cmd.cdb[0] =3D=3D REPORT_LUNS) { total: 0 errors, 3 warnings, 75 lines checked Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS. > --- > hw/scsi/spapr_vscsi.c | 57 = +++++++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 57 insertions(+) >=20 > diff --git a/hw/scsi/spapr_vscsi.c b/hw/scsi/spapr_vscsi.c > index 2a26042..87e0fb3 100644 > --- a/hw/scsi/spapr_vscsi.c > +++ b/hw/scsi/spapr_vscsi.c > @@ -63,6 +63,8 @@ > #define SCSI_SENSE_BUF_SIZE 96 > #define SRP_RSP_SENSE_DATA_LEN 18 >=20 > +#define SRP_REPORT_LUNS_WLUN 0xc10100000000000 > + > typedef union vscsi_crq { > struct viosrp_crq s; > uint8_t raw[16]; > @@ -720,12 +722,67 @@ static void vscsi_inquiry_no_target(VSCSIState = *s, vscsi_req *req) > } > } >=20 > +static void vscsi_report_luns(VSCSIState *s, vscsi_req *req) > +{ > + BusChild *kid; > + int i, len, n, rc; > + uint8_t *resp_data; > + bool found_lun0; > + > + n =3D 0; > + found_lun0 =3D false; > + QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) { > + SCSIDevice *dev =3D SCSI_DEVICE(kid->child); > + > + n +=3D 8; > + if (dev->channel =3D=3D 0 && dev->id =3D=3D 0 && dev->lun =3D=3D= 0) > + found_lun0 =3D true; > + } > + if (!found_lun0) { > + n +=3D 8; > + } > + len =3D n+8; Let me try to grasp what you're doing here. You're trying to figure out = how many devices there are attached to the bus. For every device you = reserve a buffer block. Lun0 is mandatory, all others are optional. First off, I think the code would be easier to grasp if you'd count = "number of entries" rather than "number of bytes". That way we don't = have to mentally deal with the 8 byte block granularity. Then IIUC you're jumping through a lot of hoops to count lun0 if it's = there, but keep it reserved when it's not there. Why don't you just = always reserve entry 0 for lun0? In the loop where you're actually = filling in data you just skip lun0. Or is lun0 a terminator and always = has to come last? > + > + resp_data =3D malloc(len); g_malloc0 > + memset(resp_data, 0, len); > + stl_be_p(resp_data, n); > + i =3D found_lun0 ? 8 : 16; > + QTAILQ_FOREACH(kid, &s->bus.qbus.children, sibling) { > + DeviceState *qdev =3D kid->child; > + SCSIDevice *dev =3D SCSI_DEVICE(qdev); > + > + if (dev->id =3D=3D 0 && dev->channel =3D=3D 0) > + resp_data[i] =3D 0; > + else > + resp_data[i] =3D (2 << 6); > + resp_data[i] |=3D dev->id; > + resp_data[i+1] =3D (dev->channel << 5); > + resp_data[i+1] |=3D dev->lun; > + i +=3D 8; > + } > + > + vscsi_preprocess_desc(req); > + rc =3D vscsi_srp_transfer_data(s, req, 0, resp_data, len); > + free(resp_data); g_free Alex > + if (rc < 0) { > + vscsi_makeup_sense(s, req, HARDWARE_ERROR, 0, 0); > + vscsi_send_rsp(s, req, CHECK_CONDITION, 0, 0); > + } else { > + vscsi_send_rsp(s, req, 0, len - rc, 0); > + } > +} > + > static int vscsi_queue_cmd(VSCSIState *s, vscsi_req *req) > { > union srp_iu *srp =3D &req->iu.srp; > SCSIDevice *sdev; > int n, lun; >=20 > + if ((srp->cmd.lun =3D=3D 0 || be64_to_cpu(srp->cmd.lun) =3D=3D = SRP_REPORT_LUNS_WLUN) && srp->cmd.cdb[0] =3D=3D REPORT_LUNS) { > + vscsi_report_luns(s, req); > + return 0; > + } > + > sdev =3D vscsi_device_find(&s->bus, be64_to_cpu(srp->cmd.lun), = &lun); > if (!sdev) { > DPRINTF("VSCSI: Command for lun %08" PRIx64 " with no = drive\n", > --=20 > 1.8.4 >=20 >=20