Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 13 Sep 2015 16:49:42 +0000 (UTC)
From:      Alexander Motin <mav@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r287760 - head/sys/cam/ctl
Message-ID:  <201509131649.t8DGngAZ058248@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Sun Sep 13 16:49:41 2015
New Revision: 287760
URL: https://svnweb.freebsd.org/changeset/base/287760

Log:
  Improve read-only support.

Modified:
  head/sys/cam/ctl/ctl.c
  head/sys/cam/ctl/ctl_backend_block.c
  head/sys/cam/ctl/ctl_cmd_table.c
  head/sys/cam/ctl/ctl_error.c
  head/sys/cam/ctl/ctl_error.h

Modified: head/sys/cam/ctl/ctl.c
==============================================================================
--- head/sys/cam/ctl/ctl.c	Sun Sep 13 15:50:55 2015	(r287759)
+++ head/sys/cam/ctl/ctl.c	Sun Sep 13 16:49:41 2015	(r287760)
@@ -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;
 		}

Modified: head/sys/cam/ctl/ctl_backend_block.c
==============================================================================
--- head/sys/cam/ctl/ctl_backend_block.c	Sun Sep 13 15:50:55 2015	(r287759)
+++ head/sys/cam/ctl/ctl_backend_block.c	Sun Sep 13 16:49:41 2015	(r287760)
@@ -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
 		       (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
 	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);

Modified: head/sys/cam/ctl/ctl_cmd_table.c
==============================================================================
--- head/sys/cam/ctl/ctl_cmd_table.c	Sun Sep 13 15:50:55 2015	(r287759)
+++ head/sys/cam/ctl/ctl_cmd_table.c	Sun Sep 13 16:49:41 2015	(r287760)
@@ -768,7 +768,7 @@ const struct ctl_cmd_entry ctl_cmd_table
 /* 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
 /* 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}},
 

Modified: head/sys/cam/ctl/ctl_error.c
==============================================================================
--- head/sys/cam/ctl/ctl_error.c	Sun Sep 13 15:50:55 2015	(r287759)
+++ head/sys/cam/ctl/ctl_error.c	Sun Sep 13 16:49:41 2015	(r287760)
@@ -848,6 +848,18 @@ ctl_set_task_aborted(struct ctl_scsiio *
 }
 
 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" */

Modified: head/sys/cam/ctl/ctl_error.h
==============================================================================
--- head/sys/cam/ctl/ctl_error.h	Sun Sep 13 15:50:55 2015	(r287759)
+++ head/sys/cam/ctl/ctl_error.h	Sun Sep 13 16:49:41 2015	(r287760)
@@ -85,6 +85,7 @@ void ctl_set_reservation_conflict(struct
 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);
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201509131649.t8DGngAZ058248>