[stgt] [PATCH 3/3] WRITE_SAME: Add support for thin provisioning and unmapping blocks to WRITE_SAME10/16
FUJITA Tomonori
fujita.tomonori at lab.ntt.co.jp
Sun Apr 22 03:38:01 CEST 2012
On Wed, 18 Apr 2012 19:30:42 +1000
Ronnie Sahlberg <ronniesahlberg at gmail.com> wrote:
>
> Signed-off-by: Ronnie Sahlberg <ronniesahlberg at gmail.com>
> ---
> usr/bs_rdwr.c | 21 +++++++++++++++++++++
> usr/sbc.c | 14 ++++++++++++++
> usr/spc.c | 2 +-
> 3 files changed, 36 insertions(+), 1 deletions(-)
>
> diff --git a/usr/bs_rdwr.c b/usr/bs_rdwr.c
> index 09524a4..cdaab15 100644
> --- a/usr/bs_rdwr.c
> +++ b/usr/bs_rdwr.c
> @@ -112,6 +112,27 @@ static void bs_rdwr_request(struct scsi_cmd *cmd)
> break;
> case WRITE_SAME:
> case WRITE_SAME_16:
> + /* WRITE_SAME used to punch hole in file */
> + if (cmd->scb[1] & 0x08) {
> + uint64_t offset;
> + uint64_t len;
> +
> + offset = cmd->offset;
> + offset = offset << cmd->dev->blk_shift;
> +
> + len = cmd->tl;
> + len = len << cmd->dev->blk_shift;
> +
> + if (unmap_file_region(fd, offset, len) != 0) {
> + eprintf("Failed to punch hole for WRITE_SAME"
Can you do instead:
ret = unmap_file_region()
if (ret) {
...
> + " command\n");
> + result = SAM_STAT_CHECK_CONDITION;
> + key = HARDWARE_ERROR;
> + asc = ASC_INTERNAL_TGT_FAILURE;
> + break;
> + }
> + break;
> + }
> while (cmd->tl > 0) {
> blocksize = 1 << cmd->dev->blk_shift;
> tmpbuf = scsi_get_out_buffer(cmd);
> diff --git a/usr/sbc.c b/usr/sbc.c
> index de0a13b..2cfcd11 100644
> --- a/usr/sbc.c
> +++ b/usr/sbc.c
> @@ -230,6 +230,20 @@ static int sbc_rw(int host_no, struct scsi_cmd *cmd)
> break;
> case WRITE_SAME:
> case WRITE_SAME_16:
> + /* We dont support resource-provisioning so
> + * ANCHOR bit == 1 is an error.
> + */
> + if (cmd->scb[1] & 0x10) {
> + key = ILLEGAL_REQUEST;
> + asc = ASC_INVALID_FIELD_IN_CDB;
> + goto sense;
> + }
> + /* We only support unmap for thin provisioned LUNS */
> + if (cmd->scb[1] & 0x08 && !lu->attrs.thinprovisioning) {
> + key = ILLEGAL_REQUEST;
> + asc = ASC_INVALID_FIELD_IN_CDB;
> + goto sense;
> + }
> /* We only support protection information type 0 */
> if (cmd->scb[1] & 0xe0) {
> key = ILLEGAL_REQUEST;
> diff --git a/usr/spc.c b/usr/spc.c
> index b0a305f..eb435ae 100644
> --- a/usr/spc.c
> +++ b/usr/spc.c
> @@ -146,7 +146,7 @@ static void update_vpd_b2(struct scsi_lu *lu, void *id)
>
> if (lu->attrs.thinprovisioning) {
> data[0] = 0; /* threshold exponent */
> - data[1] = 0x84; /* LBPU LBPRZ */
> + data[1] = 0xe4; /* LBPU LBPWS(10) LBPRZ */
> data[2] = 0x02; /* provisioning type */
> data[3] = 0;
> } else {
> --
> 1.7.3.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe stgt" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
More information about the stgt
mailing list