diff options
author | mav <mav@FreeBSD.org> | 2015-10-05 09:13:30 +0000 |
---|---|---|
committer | mav <mav@FreeBSD.org> | 2015-10-05 09:13:30 +0000 |
commit | 240ba1ee1f0db11773bb61b99d2415ef0a6ec387 (patch) | |
tree | ae54f12dd3d9caf560c1dfa81e686b2a193abb42 /sys/cam | |
parent | 0e819dab72ea40a70f7dbcc2ba79f5dbda97a9e3 (diff) | |
download | FreeBSD-src-240ba1ee1f0db11773bb61b99d2415ef0a6ec387.zip FreeBSD-src-240ba1ee1f0db11773bb61b99d2415ef0a6ec387.tar.gz |
MFC r287760: Improve read-only support.
Diffstat (limited to 'sys/cam')
-rw-r--r-- | sys/cam/ctl/ctl.c | 4 | ||||
-rw-r--r-- | sys/cam/ctl/ctl_backend_block.c | 6 | ||||
-rw-r--r-- | sys/cam/ctl/ctl_cmd_table.c | 4 | ||||
-rw-r--r-- | sys/cam/ctl/ctl_error.c | 12 | ||||
-rw-r--r-- | sys/cam/ctl/ctl_error.h | 1 |
5 files changed, 22 insertions, 5 deletions
diff --git a/sys/cam/ctl/ctl.c b/sys/cam/ctl/ctl.c index 50cfeb2..3954d07 100644 --- a/sys/cam/ctl/ctl.c +++ b/sys/cam/ctl/ctl.c @@ -10848,9 +10848,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; } diff --git a/sys/cam/ctl/ctl_backend_block.c b/sys/cam/ctl/ctl_backend_block.c index 9941dee..48c5333 100644 --- a/sys/cam/ctl/ctl_backend_block.c +++ b/sys/cam/ctl/ctl_backend_block.c @@ -511,6 +511,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, @@ -723,6 +725,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); @@ -888,6 +892,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); diff --git a/sys/cam/ctl/ctl_cmd_table.c b/sys/cam/ctl/ctl_cmd_table.c index d19b0c1..f910201 100644 --- a/sys/cam/ctl/ctl_cmd_table.c +++ b/sys/cam/ctl/ctl_cmd_table.c @@ -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}}, diff --git a/sys/cam/ctl/ctl_error.c b/sys/cam/ctl/ctl_error.c index 2265a03..6aa6f45 100644 --- a/sys/cam/ctl/ctl_error.c +++ b/sys/cam/ctl/ctl_error.c @@ -848,6 +848,18 @@ ctl_set_task_aborted(struct ctl_scsiio *ctsio) } 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) { /* "Space allocation failed write protect" */ diff --git a/sys/cam/ctl/ctl_error.h b/sys/cam/ctl/ctl_error.h index 4fa8060..348ff70 100644 --- a/sys/cam/ctl/ctl_error.h +++ b/sys/cam/ctl/ctl_error.h @@ -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); |