Improve read-only support.

This commit is contained in:
Alexander Motin 2015-09-13 16:49:41 +00:00
parent 5d06879adb
commit 6187d4722a
5 changed files with 22 additions and 5 deletions

View File

@ -10846,9 +10846,7 @@ ctl_scsiio_lun_check(struct ctl_lun *lun,
if (entry->pattern & CTL_LUN_PAT_WRITE) {
if (lun->be_lun &&
lun->be_lun->flags & CTL_LUN_FLAG_READONLY) {
ctl_set_sense(ctsio, /*current_error*/ 1,
/*sense_key*/ SSD_KEY_DATA_PROTECT,
/*asc*/ 0x27, /*ascq*/ 0x01, SSD_ELEM_NONE);
ctl_set_hw_write_protected(ctsio);
retval = 1;
goto bailout;
}

View File

@ -508,6 +508,8 @@ ctl_be_block_biodone(struct bio *bio)
ctl_set_invalid_opcode(&io->scsiio);
} else if (error == ENOSPC || error == EDQUOT) {
ctl_set_space_alloc_fail(&io->scsiio);
} else if (error == EROFS || error == EACCES) {
ctl_set_hw_write_protected(&io->scsiio);
} else if (beio->bio_cmd == BIO_FLUSH) {
/* XXX KDM is there is a better error here? */
ctl_set_internal_failure(&io->scsiio,
@ -720,6 +722,8 @@ ctl_be_block_dispatch_file(struct ctl_be_block_lun *be_lun,
(beio->bio_cmd == BIO_READ) ? "READ" : "WRITE", error);
if (error == ENOSPC || error == EDQUOT) {
ctl_set_space_alloc_fail(&io->scsiio);
} else if (error == EROFS || error == EACCES) {
ctl_set_hw_write_protected(&io->scsiio);
} else
ctl_set_medium_error(&io->scsiio);
ctl_complete_beio(beio);
@ -885,6 +889,8 @@ ctl_be_block_dispatch_zvol(struct ctl_be_block_lun *be_lun,
if (error != 0) {
if (error == ENOSPC || error == EDQUOT) {
ctl_set_space_alloc_fail(&io->scsiio);
} else if (error == EROFS || error == EACCES) {
ctl_set_hw_write_protected(&io->scsiio);
} else
ctl_set_medium_error(&io->scsiio);
ctl_complete_beio(beio);

View File

@ -768,7 +768,7 @@ const struct ctl_cmd_entry ctl_cmd_table[256] =
/* 35 SYNCHRONIZE CACHE(10) */
{ctl_sync_cache, CTL_SERIDX_SYNC, CTL_CMD_FLAG_OK_ON_SLUN |
CTL_FLAG_DATA_NONE,
CTL_LUN_PAT_NONE,
CTL_LUN_PAT_WRITE,
10, {0x02, 0xff, 0xff, 0xff, 0xff, 0, 0xff, 0xff, 0x07}},
/* 36 LOCK UNLOCK CACHE(10) */
@ -1117,7 +1117,7 @@ const struct ctl_cmd_entry ctl_cmd_table[256] =
/* 91 SYNCHRONIZE CACHE(16) */
{ctl_sync_cache, CTL_SERIDX_SYNC, CTL_CMD_FLAG_OK_ON_SLUN |
CTL_FLAG_DATA_NONE,
CTL_LUN_PAT_NONE,
CTL_LUN_PAT_WRITE,
16, {0x02, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0, 0x07}},

View File

@ -847,6 +847,18 @@ ctl_set_task_aborted(struct ctl_scsiio *ctsio)
ctsio->io_hdr.status = CTL_CMD_ABORTED;
}
void
ctl_set_hw_write_protected(struct ctl_scsiio *ctsio)
{
/* "Hardware write protected" */
ctl_set_sense(ctsio,
/*current_error*/ 1,
/*sense_key*/ SSD_KEY_DATA_PROTECT,
/*asc*/ 0x27,
/*ascq*/ 0x01,
SSD_ELEM_NONE);
}
void
ctl_set_space_alloc_fail(struct ctl_scsiio *ctsio)
{

View File

@ -85,6 +85,7 @@ void ctl_set_reservation_conflict(struct ctl_scsiio *ctsio);
void ctl_set_queue_full(struct ctl_scsiio *ctsio);
void ctl_set_busy(struct ctl_scsiio *ctsio);
void ctl_set_task_aborted(struct ctl_scsiio *ctsio);
void ctl_set_hw_write_protected(struct ctl_scsiio *ctsio);
void ctl_set_space_alloc_fail(struct ctl_scsiio *ctsio);
void ctl_set_success(struct ctl_scsiio *ctsio);