From 7f3fbd6a4ae863ef6e50f56b3332add18f57408a Mon Sep 17 00:00:00 2001 Message-Id: <7f3fbd6a4ae863ef6e50f56b3332add18f57408a.1350309834.git.minovotn@redhat.com> In-Reply-To: <14b740b7e3fbafdbfe2e6a302f51d6aa4fa96bf7.1350309834.git.minovotn@redhat.com> References: <14b740b7e3fbafdbfe2e6a302f51d6aa4fa96bf7.1350309834.git.minovotn@redhat.com> From: Paolo Bonzini Date: Fri, 12 Oct 2012 16:22:40 +0200 Subject: [PATCH 08/17] scsi-disk: report resized disk via sense codes RH-Author: Paolo Bonzini Message-id: <1350058967-27351-4-git-send-email-pbonzini@redhat.com> Patchwork-id: 43059 O-Subject: [RHEL 6.4 qemu-kvm PATCH v2 03/10] scsi-disk: report resized disk via sense codes Bugzilla: 808660 RH-Acked-by: Markus Armbruster RH-Acked-by: Laszlo Ersek RH-Acked-by: Orit Wasserman Bugzilla: 808660 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 (cherry picked from commit aaebacef0a55a7113335ae3f998031d3c538a477) Conflicts: hw/scsi-disk.c --- hw/scsi-bus.c | 5 +++++ hw/scsi-disk.c | 24 ++++++++++++++++++++++-- hw/scsi.h | 2 ++ 3 file modificati, 29 inserzioni(+), 2 rimozioni(-) Signed-off-by: Michal Novotny --- 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 ff2dd2b..57b5ac8 100644 --- a/hw/scsi-bus.c +++ b/hw/scsi-bus.c @@ -1068,6 +1068,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 97bb0e5..2ff63d8 100644 --- a/hw/scsi-disk.c +++ b/hw/scsi-disk.c @@ -1617,6 +1617,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; @@ -1658,11 +1670,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) @@ -1707,7 +1725,9 @@ static int scsi_initfn(SCSIDevice *dev) } if (s->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); } s->qdev.conf.bs->buffer_alignment = s->qdev.blocksize; diff --git a/hw/scsi.h b/hw/scsi.h index ec90005..493461f 100644 --- a/hw/scsi.h +++ b/hw/scsi.h @@ -188,6 +188,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 */ -- 1.7.11.7