linux/drivers/target
Nicholas Bellinger 68ff9b9b27 target: Add support for COMPARE_AND_WRITE emulation
This patch adds support for COMPARE_AND_WRITE emulation on a per block
basis.  This logic is used as an atomic test and set primative currently
used by VMWare ESX VAAI for performing array side locking of individual
VMFS extent ownership.

This includes the COMPARE_AND_WRITE CDB parsing within sbc_parse_cdb(),
and does the majority of the work within the compare_and_write_callback()
to perform the verify instance user data comparision, and subsequent
write instance user data I/O submission upon a successfull comparision.

The synchronization is enforced by se_device->caw_sem, that is obtained
before the initial READ I/O submission in sbc_compare_and_write().  The
mutex is then released upon MISCOMPARE in compare_and_write_callback(),
or upon WRITE instance user-data completion in compare_and_write_post().

The implementation currently assumes a single logical block (NoLB=1).

v4 changes:
 - Explicitly clear cmd->transport_complete_callback for two failure
   cases in sbc_compare_and_write() in order to avoid double unlock
   of ->caw_sem in compare_and_write_callback() (Dan Carpenter)

v3 changes:
 - Convert se_device->caw_mutex to ->caw_sem

v2 changes:
 - Set SCF_COMPARE_AND_WRITE and cmd->execute_cmd() to
   sbc_compare_and_write() during setup in sbc_parse_cdb()
 - Use sbc_compare_and_write() for initial READ submission with
   DMA_FROM_DEVICE
 - Reset cmd->execute_cmd() to sbc_execute_rw() for write instance
   user-data in compare_and_write_callback()
 - Drop SCF_BIDI command flag usage
 - Set TRANSPORT_PROCESSING + transport_state flags before write
   instance submission, and convert to __target_execute_cmd()
 - Prevent sbc_get_size() from being being called twice to
   generate incorrect size in sbc_parse_cdb()
 - Enforce se_device->caw_mutex synchronization between initial
   READ I/O submission, and final WRITE I/O completion.

Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.de>
Cc: Martin Petersen <martin.petersen@oracle.com>
Cc: Chris Mason <chris.mason@fusionio.com>
Cc: James Bottomley <JBottomley@Parallels.com>
Cc: Nicholas Bellinger <nab@linux-iscsi.org>
Signed-off-by: Nicholas Bellinger <nab@daterainc.com>
2013-09-10 16:41:59 -07:00
..
iscsi iscsi-target: Convert to per-cpu ida_alloc + ida_free command map 2013-09-09 14:29:22 -07:00
loopback target: make queue_tm_rsp() return void 2013-07-07 18:36:53 -07:00
sbp target: make queue_tm_rsp() return void 2013-07-07 18:36:53 -07:00
tcm_fc target: replace strict_strto*() with kstrto*() 2013-08-12 20:31:44 -07:00
Kconfig sbp-target: Initial merge of firewire/ieee-1394 target mode support 2012-05-09 15:25:17 -07:00
Makefile target: move code for CDB emulation 2012-07-16 17:27:45 -07:00
target_core_alua.c target: replace strict_strto*() with kstrto*() 2013-08-12 20:31:44 -07:00
target_core_alua.h target: pass sense_reason as a return value 2012-11-06 20:55:46 -08:00
target_core_configfs.c target: Add MAXIMUM COMPARE AND WRITE LENGTH in Block Limits VPD 2013-09-09 14:29:35 -07:00
target_core_device.c target: Add support for COMPARE_AND_WRITE emulation 2013-09-10 16:41:59 -07:00
target_core_fabric_configfs.c target: replace strict_strto*() with kstrto*() 2013-08-12 20:31:44 -07:00
target_core_fabric_lib.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_file.c target: Allow sbc_ops->execute_rw() to accept SGLs + data_direction 2013-09-09 14:29:28 -07:00
target_core_file.h target/file: Bump FD_MAX_SECTORS to 2048 to handle 1M sized I/Os 2013-03-19 17:24:28 -07:00
target_core_hba.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_iblock.c target: Allow sbc_ops->execute_rw() to accept SGLs + data_direction 2013-09-09 14:29:28 -07:00
target_core_iblock.h target: kill struct se_subsystem_dev 2012-11-06 20:55:43 -08:00
target_core_internal.h target: Add MAXIMUM COMPARE AND WRITE LENGTH in Block Limits VPD 2013-09-09 14:29:35 -07:00
target_core_pr.c target: Make core_scsi3_update_and_write_aptpl return sense_reason_t 2013-07-03 19:44:33 -07:00
target_core_pr.h target: Alter core_pr_dump_initiator_port for ease of use 2013-06-14 00:04:31 -07:00
target_core_pscsi.c target/pscsi: remove an unneeded check 2013-09-09 14:29:23 -07:00
target_core_pscsi.h target: kill struct se_subsystem_dev 2012-11-06 20:55:43 -08:00
target_core_rd.c target: Allow sbc_ops->execute_rw() to accept SGLs + data_direction 2013-09-09 14:29:28 -07:00
target_core_rd.h target/rd: Add ramdisk bit for NULLIO operation 2013-05-11 16:22:39 -07:00
target_core_sbc.c target: Add support for COMPARE_AND_WRITE emulation 2013-09-10 16:41:59 -07:00
target_core_spc.c target: Add MAXIMUM COMPARE AND WRITE LENGTH in Block Limits VPD 2013-09-09 14:29:35 -07:00
target_core_stat.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_tmr.c target: Remove legacy t_fe_count + avoid t_state_lock access in transport_put_cmd 2013-06-20 14:10:41 -07:00
target_core_tpg.c target: fix possible memory leak in core_tpg_register() 2013-03-18 12:45:52 -07:00
target_core_transport.c target: Make __target_execute_cmd() available as extern 2013-09-09 14:29:34 -07:00
target_core_ua.c target: Update copyright information to 2012 2012-11-27 22:47:02 -08:00
target_core_ua.h target: pass sense_reason as a return value 2012-11-06 20:55:46 -08:00