[stgt] [PATCH 1/3] add support for PRE-FETCH10/16 call posix_fadvise() to tell indicate to the host that we will soon need to accesas this data

Ronnie Sahlberg ronniesahlberg at gmail.com
Wed Jan 25 07:37:26 CET 2012


Signed-off-by: Ronnie Sahlberg <ronniesahlberg at gmail.com>
---
 usr/bs_rdwr.c   |   10 +++++++++-
 usr/sbc.c       |    7 +++++--
 usr/scsi.c      |    4 ++++
 usr/scsi.h      |    3 ++-
 usr/scsi_cmnd.h |    1 +
 5 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/usr/bs_rdwr.c b/usr/bs_rdwr.c
index 03b869d..acee73c 100644
--- a/usr/bs_rdwr.c
+++ b/usr/bs_rdwr.c
@@ -19,7 +19,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA
  */
-#define _XOPEN_SOURCE 500
+#define _XOPEN_SOURCE 600
 
 #include <errno.h>
 #include <fcntl.h>
@@ -113,6 +113,14 @@ static void bs_rdwr_request(struct scsi_cmd *cmd)
 		if (ret != length)
 			set_medium_error(&result, &key, &asc);
 		break;
+	case PRE_FETCH_10:
+	case PRE_FETCH_16:
+		ret = posix_fadvise(fd, cmd->offset, cmd->tl,
+				POSIX_FADV_WILLNEED);
+
+		if (ret != 0)
+			set_medium_error(&result, &key, &asc);
+		break;
 	default:
 		break;
 	}
diff --git a/usr/sbc.c b/usr/sbc.c
index 9666801..b5843af 100644
--- a/usr/sbc.c
+++ b/usr/sbc.c
@@ -130,6 +130,8 @@ static int sbc_rw(int host_no, struct scsi_cmd *cmd)
 		case WRITE_10:
 		case WRITE_12:
 		case WRITE_16:
+		case PRE_FETCH_10:
+		case PRE_FETCH_16:
 			key = DATA_PROTECT;
 			asc = ASC_WRITE_PROTECT;
 			goto sense;
@@ -149,6 +151,7 @@ static int sbc_rw(int host_no, struct scsi_cmd *cmd)
 	}
 
 	cmd->offset = lba;
+	cmd->tl     = tl;
 
 	ret = cmd->dev->bst->bs_cmd_submit(cmd);
 	if (ret) {
@@ -407,7 +410,7 @@ static struct device_type_template sbc_template = {
 		{spc_illegal_op,},
 		{spc_illegal_op,},
 		{spc_illegal_op,},
-		{spc_illegal_op,},
+		{sbc_rw, NULL, PR_EA_FA|PR_EA_FN}, /*PRE_FETCH_10 */
 		{sbc_sync_cache, NULL, PR_WE_FA|PR_EA_FA|PR_WE_FN|PR_EA_FN},
 		{spc_illegal_op,},
 		{spc_illegal_op,},
@@ -464,7 +467,7 @@ static struct device_type_template sbc_template = {
 		{spc_illegal_op,},
 
 		/* 0x90 */
-		{spc_illegal_op,},
+		{sbc_rw, NULL, PR_EA_FA|PR_EA_FN}, /*PRE_FETCH_16 */
 		{sbc_sync_cache, NULL, PR_WE_FA|PR_EA_FA|PR_WE_FN|PR_EA_FN},
 		{spc_illegal_op,},
 		{spc_illegal_op,},
diff --git a/usr/scsi.c b/usr/scsi.c
index 8db2b88..5f78bfd 100644
--- a/usr/scsi.c
+++ b/usr/scsi.c
@@ -115,6 +115,7 @@ uint64_t scsi_rw_offset(uint8_t *scb)
 		off = ((scb[1] & 0x1f) << 16) + (scb[2] << 8) + scb[3];
 		break;
 	case READ_10:
+	case PRE_FETCH_10:
 	case WRITE_10:
 	case VERIFY:
 	case WRITE_VERIFY:
@@ -127,6 +128,7 @@ uint64_t scsi_rw_offset(uint8_t *scb)
 			(uint32_t)scb[4] << 8 | (uint32_t)scb[5];
 		break;
 	case READ_16:
+	case PRE_FETCH_16:
 	case WRITE_16:
 	case VERIFY_16:
 	case WRITE_VERIFY_16:
@@ -156,6 +158,7 @@ uint32_t scsi_rw_count(uint8_t *scb)
 			cnt = 256;
 		break;
 	case READ_10:
+	case PRE_FETCH_10:
 	case WRITE_10:
 	case VERIFY:
 	case WRITE_VERIFY:
@@ -170,6 +173,7 @@ uint32_t scsi_rw_count(uint8_t *scb)
 			(uint32_t)scb[8] << 8 | (uint32_t)scb[9];
 		break;
 	case READ_16:
+	case PRE_FETCH_16:
 	case WRITE_16:
 	case VERIFY_16:
 	case WRITE_VERIFY_16:
diff --git a/usr/scsi.h b/usr/scsi.h
index f4d8c11..0d33e32 100644
--- a/usr/scsi.h
+++ b/usr/scsi.h
@@ -45,7 +45,7 @@
 #define SEARCH_EQUAL          0x31
 #define SEARCH_LOW            0x32
 #define SET_LIMITS            0x33
-#define PRE_FETCH             0x34
+#define PRE_FETCH_10          0x34
 #define READ_POSITION         0x34
 #define SYNCHRONIZE_CACHE     0x35
 #define LOCK_UNLOCK_CACHE     0x36
@@ -74,6 +74,7 @@
 #define WRITE_16              0x8a
 #define WRITE_VERIFY_16       0x8e
 #define VERIFY_16	      0x8f
+#define PRE_FETCH_16          0x90
 #define SYNCHRONIZE_CACHE_16  0x91
 #define SERVICE_ACTION_IN     0x9e
 #define	SAI_READ_CAPACITY_16  0x10
diff --git a/usr/scsi_cmnd.h b/usr/scsi_cmnd.h
index 6e3c6e2..83d733c 100644
--- a/usr/scsi_cmnd.h
+++ b/usr/scsi_cmnd.h
@@ -34,6 +34,7 @@ struct scsi_cmd {
 
 	uint64_t cmd_itn_id;
 	uint64_t offset;
+	uint32_t tl;
 	uint8_t *scb;
 	int scb_len;
 	uint8_t lun[8];
-- 
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



More information about the stgt mailing list