Re: [PATCH] sd: do not set changed flag on all unit attentionconditions

From: James Bottomley
Date: Mon Jul 16 2012 - 12:18:23 EST


On Mon, 2012-07-16 at 18:06 +0200, Paolo Bonzini wrote:
> Right now, I/O will fail as soon as a unit attention condition is
> detected on a unit with removable media. However, this is not
> always necessary. There are some cases (such as "Capacity data
> has changed") where no particular action is needed. On the
> other hand, all problematic cases have to report at least one
> of "No medium" and/or a "Medium may have changed", so restrict
> our attention to those.
>
> This patch fixes resizing a removable medium with virtio-scsi.
>
> Signed-off-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
> ---
> drivers/scsi/scsi_lib.c | 7 +++++--
> 1 files changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
> index b583277..6d8ca08 100644
> --- a/drivers/scsi/scsi_lib.c
> +++ b/drivers/scsi/scsi_lib.c
> @@ -843,8 +843,11 @@ void scsi_io_completion(struct scsi_cmnd *cmd, unsigned int good_bytes)
> } else if (sense_valid && !sense_deferred) {
> switch (sshdr.sense_key) {
> case UNIT_ATTENTION:
> - if (cmd->device->removable) {
> - /* Detected disc change. Set a bit
> + if (cmd->device->removable &&
> + (sshdr.asc == 0x3a ||
> + (sshdr.asc == 0x28 && sshdr.ascq == 0x00))) {
> + /* "No medium" or "Medium may have changed."
> + * This means a disc change. Set a bit

This type of change would likely cause a huge cascade of errors in real
removable media devices. Under the MMC standards, which a lot of the
older removable discs seem to follow, UNIT ATTENTION indicates either
medium change or device reset (which we check for and eat lower down);
we can't rely on them giving proper SBC-2 sense codes. If you want to
pretend to be removable media, you have to conform to its standards.

James


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/