From patchwork Fri Jul 27 15:02:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 173699 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8E33F2C0089 for ; Sat, 28 Jul 2012 01:30:53 +1000 (EST) Received: from localhost ([::1]:50814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum6F-0000YF-5y for incoming@patchwork.ozlabs.org; Fri, 27 Jul 2012 11:05:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:51724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum5h-00088t-39 for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:04:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sum5Z-0007Vc-5I for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:04:33 -0400 Received: from mail-gh0-f173.google.com ([209.85.160.173]:42319) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sum5Z-0007JU-0o for qemu-devel@nongnu.org; Fri, 27 Jul 2012 11:04:25 -0400 Received: by mail-gh0-f173.google.com with SMTP id r14so3231906ghr.4 for ; Fri, 27 Jul 2012 08:04:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:subject:date:message-id:x-mailer:in-reply-to :references; bh=GHoAte+eF6wEvjbEOt0NR4KDcc7wJ/T96/lPgJnwWok=; b=AJC4eLHbpkkwcC/J481pEQSIvtWhZVk4b856uCc8rcuIKj9igg3IAT+4obgWr0IadQ pauCgC3E969nqtcRVYqsONVCDDc5NsXPzHroQfFo20Q5UlddIJxBHsbxKZ2H/ykXzt3L E04DqHwJHbkgerdWShV8Q1LhMi6BfFqQGcN9iK7k8H72bVHs+CGZGp40AiDl9DWI7eHD gbyr8F8bjZ615OIHzWLtOUora2RAyuJV3Xa+PrOx13uzxG+Gw2s/69fcpQPb3Uxk959o JhkanchT6oNwtq1WCXMiURKQj9YjI8X+CAZZaFIV228Jp9TJWUNoyWRZvj30rxEFi+mk k6lA== Received: by 10.66.73.133 with SMTP id l5mr6039322pav.74.1343401464642; Fri, 27 Jul 2012 08:04:24 -0700 (PDT) Received: from yakj.usersys.redhat.com (93-34-189-113.ip51.fastwebnet.it. [93.34.189.113]) by mx.google.com with ESMTPS id nk3sm2062530pbc.27.2012.07.27.08.04.21 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Jul 2012 08:04:23 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 27 Jul 2012 17:02:52 +0200 Message-Id: <1343401379-19495-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343401379-19495-1-git-send-email-pbonzini@redhat.com> References: <1343401379-19495-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.160.173 Subject: [Qemu-devel] [PATCH 25/32] scsi-disk: report resized disk via sense codes 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 Linux will not use these, but a very similar mechanism will be used to report the condition via virtio-scsi events. Signed-off-by: Paolo Bonzini --- hw/scsi-bus.c | 5 +++++ hw/scsi-disk.c | 24 ++++++++++++++++++++++-- hw/scsi.h | 2 ++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index c38c0ec..04262de 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -1161,6 +1161,11 @@ const struct SCSISense sense_code_LUN_FAILURE = { .key = ABORTED_COMMAND, .asc = 0x3e, .ascq = 0x01 }; +/* Unit attention, Capacity data has changed */ +const struct SCSISense sense_code_CAPACITY_CHANGED = { + .key = UNIT_ATTENTION, .asc = 0x2a, .ascq = 0x09 +}; + /* Unit attention, Power on, reset or bus device reset occurred */ const struct SCSISense sense_code_RESET = { .key = UNIT_ATTENTION, .asc = 0x29, .ascq = 0x00 diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c index 734fe13..9ba405f 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1860,6 +1860,18 @@ static void scsi_destroy(SCSIDevice *dev) blockdev_mark_auto_del(s->qdev.conf.bs); } +static void scsi_disk_resize_cb(void *opaque) +{ + SCSIDiskState *s = opaque; + + /* SPC lists this sense code as available only for + * direct-access devices. + */ + if (s->qdev.type == TYPE_DISK) { + scsi_device_set_ua(&s->qdev, SENSE_CODE(CAPACITY_CHANGED)); + } +} + static void scsi_cd_change_media_cb(void *opaque, bool load) { SCSIDiskState *s = opaque; @@ -1901,11 +1913,17 @@ static bool scsi_cd_is_medium_locked(void *opaque) return ((SCSIDiskState *)opaque)->tray_locked; } -static const BlockDevOps scsi_cd_block_ops = { +static const BlockDevOps scsi_disk_removable_block_ops = { .change_media_cb = scsi_cd_change_media_cb, .eject_request_cb = scsi_cd_eject_request_cb, .is_tray_open = scsi_cd_is_tray_open, .is_medium_locked = scsi_cd_is_medium_locked, + + .resize_cb = scsi_disk_resize_cb, +}; + +static const BlockDevOps scsi_disk_block_ops = { + .resize_cb = scsi_disk_resize_cb, }; static void scsi_disk_unit_attention_reported(SCSIDevice *dev) @@ -1950,7 +1968,9 @@ static int scsi_initfn(SCSIDevice *dev) } if (s->features & (1 << SCSI_DISK_F_REMOVABLE)) { - bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_cd_block_ops, s); + bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_removable_block_ops, s); + } else { + bdrv_set_dev_ops(s->qdev.conf.bs, &scsi_disk_block_ops, s); } bdrv_set_buffer_alignment(s->qdev.conf.bs, s->qdev.blocksize); diff --git a/hw/scsi.h b/hw/scsi.h index f920208..82a5fc8 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -200,6 +200,8 @@ extern const struct SCSISense sense_code_IO_ERROR; extern const struct SCSISense sense_code_I_T_NEXUS_LOSS; /* Command aborted, Logical Unit failure */ extern const struct SCSISense sense_code_LUN_FAILURE; +/* LUN not ready, Capacity data has changed */ +extern const struct SCSISense sense_code_CAPACITY_CHANGED; /* LUN not ready, Medium not present */ extern const struct SCSISense sense_code_UNIT_ATTENTION_NO_MEDIUM; /* Unit attention, Power on, reset or bus device reset occurred */