From patchwork Mon Jun 6 16:04:14 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 98956 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F3BE9B6FA3 for ; Tue, 7 Jun 2011 02:59:19 +1000 (EST) Received: from localhost ([::1]:35810 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTd90-0002os-Iv for incoming@patchwork.ozlabs.org; Mon, 06 Jun 2011 12:59:14 -0400 Received: from eggs.gnu.org ([140.186.70.92]:54668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTcIb-0005uM-Aa for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QTcIY-0000HR-Ky for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:04 -0400 Received: from mail-pw0-f45.google.com ([209.85.160.45]:36212) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QTcIX-0000HG-PH for qemu-devel@nongnu.org; Mon, 06 Jun 2011 12:05:02 -0400 Received: by pwi6 with SMTP id 6so2335439pwi.4 for ; Mon, 06 Jun 2011 09:05:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:sender:from:to:subject:date:message-id:x-mailer :in-reply-to:references; bh=w4EXHGciiJKPDP1BA5K1voBVlhTzz29i1wIZ9UPvPYo=; b=aZ9HMG3818GtmNMt+/dmwc92P6OxvD+v0BiVZoZ1QAnpCtkdAXL1WyNewg/6V1C2sd QPEzUoiiIq5lFlJ0HfV+zkG71+3RcuW9gHR1xPgMf7If0ui4aC/6lT3drO6pIehTCuIC iz8FIFbSy8spsnTb/lI3N/d7fEOVV7SDbgvWU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; b=CErP3Uej2JlTdlOtuCcRbYl2XhiP8O/hHvyF4xCUOcog5mArbXpfNJEcUgRGLRadZP 5pTghaHwFgS1bCTq5Iy3CVvNgR3z/aseu6eGDfvJU4Ezp/djz7n4/ATXP3rXfd/bd1jV urEwP4DgupJ0T8f3lLhb+evtAFxoRqWWF5cNc= Received: by 10.68.12.132 with SMTP id y4mr2112980pbb.296.1307376300908; Mon, 06 Jun 2011 09:05:00 -0700 (PDT) Received: from localhost.localdomain (93-34-184-88.ip51.fastwebnet.it [93.34.184.88]) by mx.google.com with ESMTPS id c3sm3770633pbk.77.2011.06.06.09.04.58 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 06 Jun 2011 09:04:59 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 6 Jun 2011 18:04:14 +0200 Message-Id: <1307376262-1255-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1307376262-1255-1-git-send-email-pbonzini@redhat.com> References: <1307376262-1255-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.160.45 Subject: [Qemu-devel] [RFC PATCH v2 05/13] scsi: let the bus pick a LUN for the child device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The scsi-id may be a LUN value or a target id. The bus knows, so add a callback to that end. The default value in case there is no implementation is to always returns zero. Signed-off-by: Paolo Bonzini --- hw/scsi-bus.c | 3 +++ hw/scsi-disk.c | 6 +++--- hw/scsi.h | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index b44f308..b64ed68 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -54,6 +54,9 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base) } bus->devs[dev->id] = dev; + if (bus->ops->get_child_lun) { + dev->lun = bus->ops->get_child_lun(dev); + } dev->info = info; QTAILQ_INIT(&dev->requests); rc = dev->info->init(dev); diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 87e5ac8..b2c8d6e 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -518,7 +518,7 @@ static int scsi_disk_emulate_inquiry(SCSIRequest *req, uint8_t *outbuf) memset(outbuf, 0, buflen); - if (req->lun) { + if (req->lun != s->qdev.lun) { outbuf[0] = 0x7f; /* LUN not supported */ return buflen; } @@ -1024,8 +1024,8 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf) } #endif - if (req->lun) { - /* Only LUN 0 supported. */ + if (req->lun != s->qdev.lun) { + /* Only one LUN supported. */ DPRINTF("Unimplemented LUN %d\n", req->lun); if (command != REQUEST_SENSE && command != INQUIRY) { scsi_command_complete(r, CHECK_CONDITION, diff --git a/hw/scsi.h b/hw/scsi.h index 8d5737b..67d18cc 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -57,6 +57,7 @@ struct SCSIDevice { DeviceState qdev; uint32_t id; + uint32_t lun; BlockConf conf; SCSIDeviceInfo *info; SCSIBus *children; @@ -90,6 +91,7 @@ struct SCSIBusOps { void (*transfer_data)(SCSIRequest *req, uint32_t arg); void (*complete)(SCSIRequest *req, uint32_t arg); void (*cancel)(SCSIRequest *req); + int (*get_child_lun)(SCSIDevice *dev); }; struct SCSIBus {