Add WRITE10 support to dbench/iscsi
authorRonnie sahlberg <ronniesahlberg@gmail.com>
Tue, 18 May 2010 23:18:46 +0000 (09:18 +1000)
committerRonnie sahlberg <ronniesahlberg@gmail.com>
Tue, 18 May 2010 23:18:46 +0000 (09:18 +1000)
To use writes you must specify --allow-scsi-writes on the
commandline

iscsi.c
loadfiles/iscsi.txt

diff --git a/iscsi.c b/iscsi.c
index 8db6d70634519f533a92fae73ae03c5ef1f0bcd1..327317e777e275049ca90a204eb15d20db6548e9 100644 (file)
--- a/iscsi.c
+++ b/iscsi.c
@@ -508,6 +508,63 @@ static void iscsi_read10(struct dbench_op *op)
 }
 
 
+static void iscsi_write10(struct dbench_op *op)
+{
+       struct iscsi_device *sd=op->child->private;
+       unsigned char cdb[]={0x2a,0,0,0,0,0,0,0,0,0};
+       int res;
+       uint32_t lba = op->params[0];
+       uint32_t xferlen = op->params[1];
+       int fua = op->params[2];
+       int grp = op->params[3];
+       unsigned int data_size=1024*1024;
+       char data[data_size];
+       unsigned char sc;
+
+       if (!options.allow_scsi_writes) {
+               printf("WRITE10 command in loadfile but --allow-scsi-writes not specified. Aborting.\n");
+               failed(op->child);
+       }
+
+       lba = (lba / xferlen) * xferlen;
+
+       /* make sure we wrap properly instead of failing if the loadfile
+          is bigger than our device
+       */
+       if (sd->blocks <= lba) {
+               lba = lba%sd->blocks;
+       }
+       if (sd->blocks <= lba+xferlen) {
+               xferlen=1;
+       }
+
+       cdb[1] = fua;
+
+       cdb[2] = (lba>>24)&0xff;
+       cdb[3] = (lba>>16)&0xff;
+       cdb[4] = (lba>> 8)&0xff;
+       cdb[5] = (lba    )&0xff;
+
+       cdb[6] = grp&0x1f;
+
+       cdb[7] = (xferlen>>8)&0xff;
+       cdb[8] = xferlen&0xff;
+       data_size = xferlen*512;
+
+       res=do_iscsi_io(sd, cdb, sizeof(cdb), SG_DXFER_TO_DEV, &data_size, data, &sc);
+       if(res){
+               printf("SCSI_IO failed\n");
+               failed(op->child);
+       }
+       if (!check_sense(sc, op->status)) {
+               printf("[%d] READ10 \"%s\" failed (0x%02x) - expected %s\n", 
+                      op->child->line, op->fname, sc, op->status);
+               failed(op->child);
+       }
+
+       op->child->bytes += xferlen*512;
+}
+
 
 static void local_iscsi_readcapacity10(struct dbench_op *op, uint64_t *blocks)
 {
@@ -554,7 +611,7 @@ static void iscsi_prout(struct dbench_op *op)
        struct iscsi_device *sd;
        unsigned char sc;
        unsigned char cdb[10];
-       unsigned char parameters[PARAMETERS_SIZE];
+       char parameters[PARAMETERS_SIZE];
        int i;
        unsigned int data_size = PARAMETERS_SIZE;
        u_int64_t sa, type, key, sakey;
@@ -736,6 +793,7 @@ static struct backend_op ops[] = {
        { "READ10",           iscsi_read10 },
        { "READCAPACITY10",   iscsi_readcapacity10 },
        { "PROUT",            iscsi_prout },
+       { "WRITE10",          iscsi_write10 },
        { NULL, NULL}
 };
 
index 49a9e95c5d4a020bd6b0e5dcd35e505c9579e23f..9940388644373d6febe8e34f6c434f95fc8e6152 100644 (file)
@@ -1,6 +1,24 @@
 # timestamp TESTUNITREADY sense
 0.000 TESTUNITREADY 0x00
 #
+# READ10/WRITE10 take an LBA and a XFERLEN arguments.
+# These can be absolute numbers,
+# but also as a simple expression for generation of random I/O
+#
+# These are strings starting with a '*' followed by one or more
+# qualifiers :
+# '*'    : Random 64 bit integer
+# '/yyy' : align the number to yyy. This is the same as x = (x/y)*y
+# '%yyy' : modulo yyy. This is the same as x = x%y
+# '+yyy' : Add y
+#
+# Examples :
+# '*'           A random value between 0 and 2**64-1
+# '*/8'         A random value aligned to a page boundary (8blocks)
+# '*/8%5000000' A random value between 0 and 500000 aligned by 8.
+#
+# '*%100+25'    A random value between 25 and 124
+#
 #
 # timestamp READ10 lba #xferlen rd grp sense
 #   if lba is * this means to use a random lba
 0.000 READ10    6 2 0 0 0x00
 0.000 READ10    * 2 0 0 0x00
 #
+#
+# timestamp WRITE10 lba #xferlen FUAbits grp sense
+# WRITES are ignored by default and must be activated using --allow-scsi-writes
+#
+#   FUAbits are cdb byte#1 in SBC:
+#     a value of 0x06 will force the data to be written to the medium
+#     a value of 0x00 allow the device to only write to nv-ram and not medium
+0.000 WRITE10 5000 1 0x06 0 0x00
+#
+#
 # timestamp READCAPACITY10 lba pmi(0/1) sense
 0.000 READCAPACITY10 0 0 0x00