From owner-svn-src-head@freebsd.org Sun Sep 13 16:49:43 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id D68F0A0301C; Sun, 13 Sep 2015 16:49:43 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id C7DA912B7; Sun, 13 Sep 2015 16:49:43 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t8DGnhrO058254; Sun, 13 Sep 2015 16:49:43 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t8DGngAZ058248; Sun, 13 Sep 2015 16:49:42 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201509131649.t8DGngAZ058248@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Sun, 13 Sep 2015 16:49:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r287760 - head/sys/cam/ctl X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Sep 2015 16:49:43 -0000 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);