From nobody Tue Nov 4 15:31:25 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 153021874239697.55334968937757; Thu, 28 Jun 2018 13:45:42 -0700 (PDT) Received: from localhost ([::1]:38501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdnM-0007mr-Qg for importer@patchew.org; Thu, 28 Jun 2018 16:45:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38541) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdBG-0007x3-IQ for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:06:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYdBE-0001bu-Ml for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:06:14 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:50760) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYdBE-0001Yo-B3 for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:06:12 -0400 Received: by mail-wm0-x242.google.com with SMTP id e16-v6so10988863wmd.0 for ; Thu, 28 Jun 2018 13:06:12 -0700 (PDT) Received: from 640k.lan ([82.84.124.111]) by smtp.gmail.com with ESMTPSA id 127-v6sm6211110wmd.18.2018.06.28.13.06.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 13:06:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=GeeFo2ZE3Zs/DOHWbzlKZcK4Y0iSJ+znqfWdiRViv1c=; b=IrmmZFtwpWN+DADByRDm1QPANt8P11BUYeBWJ3t91p8ImILGROjD43M1A8jZ449/vc QgZt8nAOZcnYKASNsRgfSYvfVj9VEF+4C1ogtMsWKqo8mSP5eDsDkrsSpo6n4jUt2rvR QBen2eh/3tvi5bH30a22pC88d4xxbs3wiRxgE6Dv9kj8etqzyCgT6bnvKxWcZJII9IF8 h2dLGDG17QA7z7Or/4fa1/QNKJFrFJVthtXFF0U6J5hHcvcDQN+p3UPuSD4DnzvXfSSO puxQOhtuePDtfupyYkiii6kXUeup80zYkiOO6uYL9Gqy7RYmEYehuFnJuHPTCbRviHXj 37UQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=GeeFo2ZE3Zs/DOHWbzlKZcK4Y0iSJ+znqfWdiRViv1c=; b=WNcycMNV0xSQ9JJONfdw8flqoMdOMRgmZ4akMhs5epRy6ostUbYc4G4VtEV9l4eDsy FVuxGOfT/ZNsfaqmF6mz+3ZSm7OK5j0nsQrv9x1jM996TBkd0CMCIjiQHkgZnt6gD3lz MZurQzlHbwV2lS1CCLbQWOARrcu5/tNUUvfoaN7dIuZTf+Lpiq1tM6ftCgO5UkF8BD+6 FoF9Jpx9Fa8X5+dGi8m1VbBa4/El6eULeRzL/QNxjVolgC1M0HF6Z6CVGpGIXCm+R+VS fm0RG+EhjKN53tLT6dto3mBisoRxNJohCuMf8AL2AOr0biuou84rV2CN4+xHNbnjsuvz k8jg== X-Gm-Message-State: APt69E1dovUsxPZKHYMv5YlcFYbU2+l16FJr6kcbgYpapbD3kMvq8NVG J5X++FyJ9srotjMmtDmb8/2MdRor X-Google-Smtp-Source: AAOMgpfHNx+cGLVL9CVA7Dw6trNEuHAjI3h9vWQXfZoirkfARK9BjT6R6vB0WqmWkeZQVX16Q9nvww== X-Received: by 2002:a1c:8d8d:: with SMTP id p135-v6mr8861402wmd.34.1530216371075; Thu, 28 Jun 2018 13:06:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 22:05:08 +0200 Message-Id: <1530216310-52873-59-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> References: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PULL 58/60] hw/scsi: centralize SG_IO calls into single function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Daniel Henrique Barboza Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza For the VPD Block Limits emulation with SCSI passthrough, we'll issue an Inquiry request with EVPD set to retrieve the available VPD pages of the device. This would be done in a way similar of what scsi_generic_read_device_identification does: create a SCSI command and a reply buffer, fill in the sg_io_hdr_t structure, call blk_ioctl, check if an error occurred, process the response. This same process is done in other 2 functions, get_device_type and get_stream_blocksize. They differ in the command/reply buffer and post-processing, everything else is almost a copy/paste. Instead of adding a forth copy/pasted-ish code when adding the passthrough VPD BL emulation, this patch extirpates this repetition of those 3 functions and put it into a new one called scsi_SG_IO_FROM_DEV. Any future code that wants to execute an SG_DXFER_FROM_DEV to the device can use it, avoiding filling sg_io_hdr_t again and et cetera. Signed-off-by: Daniel Henrique Barboza Message-Id: <20180627172432.11120-3-danielhb413@gmail.com> Signed-off-by: Paolo Bonzini --- hw/scsi/scsi-disk.c | 18 +++------------ hw/scsi/scsi-generic.c | 61 +++++++++++++++++++++++++---------------------= ---- include/hw/scsi/scsi.h | 2 ++ 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 664d634..b0b39f1 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2578,8 +2578,6 @@ static int get_device_type(SCSIDiskState *s) { uint8_t cmd[16]; uint8_t buf[36]; - uint8_t sensebuf[8]; - sg_io_hdr_t io_header; int ret; =20 memset(cmd, 0, sizeof(cmd)); @@ -2587,19 +2585,9 @@ static int get_device_type(SCSIDiskState *s) cmd[0] =3D INQUIRY; cmd[4] =3D sizeof(buf); =20 - memset(&io_header, 0, sizeof(io_header)); - io_header.interface_id =3D 'S'; - io_header.dxfer_direction =3D SG_DXFER_FROM_DEV; - io_header.dxfer_len =3D sizeof(buf); - io_header.dxferp =3D buf; - io_header.cmdp =3D cmd; - io_header.cmd_len =3D sizeof(cmd); - io_header.mx_sb_len =3D sizeof(sensebuf); - io_header.sbp =3D sensebuf; - io_header.timeout =3D 6000; /* XXX */ - - ret =3D blk_ioctl(s->qdev.conf.blk, SG_IO, &io_header); - if (ret < 0 || io_header.driver_status || io_header.host_status) { + ret =3D scsi_SG_IO_FROM_DEV(s->qdev.conf.blk, cmd, sizeof(cmd), + buf, sizeof(buf)); + if (ret < 0) { return -1; } s->qdev.type =3D buf[0]; diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index a04a704..61abc27 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -409,35 +409,48 @@ static int read_naa_id(const uint8_t *p, uint64_t *p_= wwn) return -EINVAL; } =20 -void scsi_generic_read_device_identification(SCSIDevice *s) +int scsi_SG_IO_FROM_DEV(BlockBackend *blk, uint8_t *cmd, uint8_t cmd_size, + uint8_t *buf, uint8_t buf_size) { - uint8_t cmd[6]; - uint8_t buf[250]; - uint8_t sensebuf[8]; sg_io_hdr_t io_header; + uint8_t sensebuf[8]; int ret; - int i, len; - - memset(cmd, 0, sizeof(cmd)); - memset(buf, 0, sizeof(buf)); - cmd[0] =3D INQUIRY; - cmd[1] =3D 1; - cmd[2] =3D 0x83; - cmd[4] =3D sizeof(buf); =20 memset(&io_header, 0, sizeof(io_header)); io_header.interface_id =3D 'S'; io_header.dxfer_direction =3D SG_DXFER_FROM_DEV; - io_header.dxfer_len =3D sizeof(buf); + io_header.dxfer_len =3D buf_size; io_header.dxferp =3D buf; io_header.cmdp =3D cmd; - io_header.cmd_len =3D sizeof(cmd); + io_header.cmd_len =3D cmd_size; io_header.mx_sb_len =3D sizeof(sensebuf); io_header.sbp =3D sensebuf; io_header.timeout =3D 6000; /* XXX */ =20 - ret =3D blk_ioctl(s->conf.blk, SG_IO, &io_header); + ret =3D blk_ioctl(blk, SG_IO, &io_header); if (ret < 0 || io_header.driver_status || io_header.host_status) { + return -1; + } + return 0; +} + +void scsi_generic_read_device_identification(SCSIDevice *s) +{ + uint8_t cmd[6]; + uint8_t buf[250]; + int ret; + int i, len; + + memset(cmd, 0, sizeof(cmd)); + memset(buf, 0, sizeof(buf)); + cmd[0] =3D INQUIRY; + cmd[1] =3D 1; + cmd[2] =3D 0x83; + cmd[4] =3D sizeof(buf); + + ret =3D scsi_SG_IO_FROM_DEV(s->conf.blk, cmd, sizeof(cmd), + buf, sizeof(buf)); + if (ret < 0) { return; } =20 @@ -470,8 +483,6 @@ static int get_stream_blocksize(BlockBackend *blk) { uint8_t cmd[6]; uint8_t buf[12]; - uint8_t sensebuf[8]; - sg_io_hdr_t io_header; int ret; =20 memset(cmd, 0, sizeof(cmd)); @@ -479,21 +490,11 @@ static int get_stream_blocksize(BlockBackend *blk) cmd[0] =3D MODE_SENSE; cmd[4] =3D sizeof(buf); =20 - memset(&io_header, 0, sizeof(io_header)); - io_header.interface_id =3D 'S'; - io_header.dxfer_direction =3D SG_DXFER_FROM_DEV; - io_header.dxfer_len =3D sizeof(buf); - io_header.dxferp =3D buf; - io_header.cmdp =3D cmd; - io_header.cmd_len =3D sizeof(cmd); - io_header.mx_sb_len =3D sizeof(sensebuf); - io_header.sbp =3D sensebuf; - io_header.timeout =3D 6000; /* XXX */ - - ret =3D blk_ioctl(blk, SG_IO, &io_header); - if (ret < 0 || io_header.driver_status || io_header.host_status) { + ret =3D scsi_SG_IO_FROM_DEV(blk, cmd, sizeof(cmd), buf, sizeof(buf)); + if (ret < 0) { return -1; } + return (buf[9] << 16) | (buf[10] << 8) | buf[11]; } =20 diff --git a/include/hw/scsi/scsi.h b/include/hw/scsi/scsi.h index 138eb79..75eced3 100644 --- a/include/hw/scsi/scsi.h +++ b/include/hw/scsi/scsi.h @@ -187,6 +187,8 @@ void scsi_device_unit_attention_reported(SCSIDevice *de= v); void scsi_generic_read_device_identification(SCSIDevice *dev); int scsi_device_get_sense(SCSIDevice *dev, uint8_t *buf, int len, bool fix= ed); int scsi_disk_emulate_vpd_page(SCSIRequest *req, uint8_t *outbuf); +int scsi_SG_IO_FROM_DEV(BlockBackend *blk, uint8_t *cmd, uint8_t cmd_size, + uint8_t *buf, uint8_t buf_size); SCSIDevice *scsi_device_find(SCSIBus *bus, int channel, int target, int lu= n); =20 /* scsi-generic.c. */ --=20 1.8.3.1