From patchwork Mon Jul 16 14:25:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 1201001 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id F0F54E0038 for ; Mon, 16 Jul 2012 14:26:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753465Ab2GPO0O (ORCPT ); Mon, 16 Jul 2012 10:26:14 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:59203 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753325Ab2GPO0N (ORCPT ); Mon, 16 Jul 2012 10:26:13 -0400 Received: by mail-pb0-f46.google.com with SMTP id rp8so10129290pbb.19 for ; Mon, 16 Jul 2012 07:26:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=lwbTbTnhEzOSJknosUIZtu9HELz3KXfnLHgF3cdVET0=; b=foamklqTVBYY3/NsLHCkDYZFi19vQoTPL6pAdHoT8XNr6pAF1h6dgWQh6O27XPthmo /NV3HLWArpy4GdRNyEusjXnebqfKKyKUh402ffxY5nrPPQAxwAQk3p8Sn2tVIwM6T7MA puSVTgn1pNCxXQ+frbXLDYWdIvz/JOzpOc2hFss660+CJdv6+ViatqBUhXA0rSmpWnd9 xMkXBefIZ/jOYx6RNn/qHlMdll4CqsDmfur/pLgNTIooxt941VUSQfPsSdkZfRg9gWVh a8QoPGSuyWwcHjeN+THkUCrJL2RuRWgHGbrIKzwX4IPhKEtHWa57VOiL3Dr7umnQPxHm WWdQ== Received: by 10.68.225.201 with SMTP id rm9mr27424528pbc.71.1342448772846; Mon, 16 Jul 2012 07:26:12 -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 qa5sm11997476pbb.19.2012.07.16.07.26.10 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 16 Jul 2012 07:26:11 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org Subject: [PATCH 2/5] scsi-disk: report resized disk via sense codes Date: Mon, 16 Jul 2012 16:25:53 +0200 Message-Id: <1342448756-7582-3-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1342448756-7582-1-git-send-email-pbonzini@redhat.com> References: <1342448756-7582-1-git-send-email-pbonzini@redhat.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.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 | 15 +++++++++++---- hw/scsi.h | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c index 8b961f2..2547c50 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 42bae3b..0905446 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1863,6 +1863,13 @@ 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; + + scsi_device_set_ua(&s->qdev, SENSE_CODE(CAPACITY_CHANGED)); +} + static void scsi_cd_change_media_cb(void *opaque, bool load) { SCSIDiskState *s = opaque; @@ -1904,11 +1911,13 @@ 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_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 void scsi_disk_unit_attention_reported(SCSIDevice *dev) @@ -1956,9 +1965,7 @@ static int scsi_initfn(SCSIDevice *dev) return -1; } - 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_block_ops, s); bdrv_set_buffer_alignment(s->qdev.conf.bs, s->qdev.blocksize); bdrv_iostatus_enable(s->qdev.conf.bs); diff --git a/hw/scsi.h b/hw/scsi.h index 47c3b9c..e901350 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -198,6 +198,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 */