SBC: Add support for WRITESAME16 and add simple tests using it to unmap blocks from a thin provisioned lun

This commit is contained in:
Ronnie Sahlberg
2012-04-28 14:34:47 +10:00
parent d620cf4fd2
commit 568e4ddfcc
11 changed files with 397 additions and 1 deletions

View File

@@ -833,6 +833,51 @@ scsi_cdb_writesame10(int wrprotect, int anchor, int unmap, int pbdata, int lbdat
return task;
}
/*
* WRITE_SAME16
*/
struct scsi_task *
scsi_cdb_writesame16(int wrprotect, int anchor, int unmap, int pbdata, int lbdata, uint64_t lba, int group, uint32_t num_blocks)
{
struct scsi_task *task;
task = malloc(sizeof(struct scsi_task));
if (task == NULL) {
return NULL;
}
memset(task, 0, sizeof(struct scsi_task));
task->cdb[0] = SCSI_OPCODE_WRITE_SAME16;
if (wrprotect) {
task->cdb[1] |= ((wrprotect & 0x7) << 5);
}
if (anchor) {
task->cdb[1] |= 0x10;
}
if (unmap) {
task->cdb[1] |= 0x08;
}
if (pbdata) {
task->cdb[1] |= 0x04;
}
if (lbdata) {
task->cdb[1] |= 0x02;
}
*(uint32_t *)&task->cdb[2] = htonl(lba >> 32);
*(uint32_t *)&task->cdb[6] = htonl(lba & 0xffffffff);
*(uint32_t *)&task->cdb[10] = htonl(num_blocks);
if (group) {
task->cdb[14] |= (group & 0x1f);
}
task->cdb_size = 16;
task->xfer_dir = SCSI_XFER_WRITE;
task->expxferlen = 512;
return task;
}
/*
* MODESENSE6
*/