Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 22 Sep 2014 09:22:58 +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: r271949 - head/sys/cam/ctl
Message-ID:  <201409220922.s8M9MwkS061425@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mav
Date: Mon Sep 22 09:22:58 2014
New Revision: 271949
URL: http://svnweb.freebsd.org/changeset/base/271949

Log:
  Fix UNMAP stuck if the last block descriptor in the list is empty.
  
  MFC after:	3 days

Modified:
  head/sys/cam/ctl/ctl.c

Modified: head/sys/cam/ctl/ctl.c
==============================================================================
--- head/sys/cam/ctl/ctl.c	Mon Sep 22 08:41:50 2014	(r271948)
+++ head/sys/cam/ctl/ctl.c	Mon Sep 22 09:22:58 2014	(r271949)
@@ -6059,7 +6059,7 @@ ctl_unmap(struct ctl_scsiio *ctsio)
 	struct scsi_unmap *cdb;
 	struct ctl_ptr_len_flags *ptrlen;
 	struct scsi_unmap_header *hdr;
-	struct scsi_unmap_desc *buf, *end, *range;
+	struct scsi_unmap_desc *buf, *end, *endnz, *range;
 	uint64_t lba;
 	uint32_t num_blocks;
 	int len, retval;
@@ -6112,6 +6112,7 @@ ctl_unmap(struct ctl_scsiio *ctsio)
 	buf = (struct scsi_unmap_desc *)(hdr + 1);
 	end = buf + len / sizeof(*buf);
 
+	endnz = buf;
 	for (range = buf; range < end; range++) {
 		lba = scsi_8btou64(range->lba);
 		num_blocks = scsi_4btoul(range->length);
@@ -6121,6 +6122,19 @@ ctl_unmap(struct ctl_scsiio *ctsio)
 			ctl_done((union ctl_io *)ctsio);
 			return (CTL_RETVAL_COMPLETE);
 		}
+		if (num_blocks != 0)
+			endnz = range + 1;
+	}
+
+	/*
+	 * Block backend can not handle zero last range.
+	 * Filter it out and return if there is nothing left.
+	 */
+	len = (uint8_t *)endnz - (uint8_t *)buf;
+	if (len == 0) {
+		ctl_set_success(ctsio);
+		ctl_done((union ctl_io *)ctsio);
+		return (CTL_RETVAL_COMPLETE);
 	}
 
 	mtx_lock(&lun->lun_lock);



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