aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/target
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2012-04-23 11:35:33 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2012-05-06 18:11:14 -0400
commit6bb35e009b656b36f7985057822c5fbf53ea75b7 (patch)
tree31384150dbd2828ee72a0802efb23692511f032f /drivers/target
parentbd31377878868a47b2d2e6f570fb0cace828555b (diff)
target: replace ->execute_task with ->execute_cmd
Make CDB emulation work on commands instead of tasks again as a preparation of removing tasks completely. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r--drivers/target/target_core_alua.c12
-rw-r--r--drivers/target/target_core_alua.h4
-rw-r--r--drivers/target/target_core_cdb.c64
-rw-r--r--drivers/target/target_core_device.c6
-rw-r--r--drivers/target/target_core_file.c3
-rw-r--r--drivers/target/target_core_iblock.c3
-rw-r--r--drivers/target/target_core_internal.h20
-rw-r--r--drivers/target/target_core_pr.c36
-rw-r--r--drivers/target/target_core_pr.h8
-rw-r--r--drivers/target/target_core_transport.c54
10 files changed, 90 insertions, 120 deletions
diff --git a/drivers/target/target_core_alua.c b/drivers/target/target_core_alua.c
index c7746a3339d4..c39ae7cd9895 100644
--- a/drivers/target/target_core_alua.c
+++ b/drivers/target/target_core_alua.c
@@ -59,9 +59,8 @@ struct t10_alua_lu_gp *default_lu_gp;
59 * 59 *
60 * See spc4r17 section 6.27 60 * See spc4r17 section 6.27
61 */ 61 */
62int target_emulate_report_target_port_groups(struct se_task *task) 62int target_emulate_report_target_port_groups(struct se_cmd *cmd)
63{ 63{
64 struct se_cmd *cmd = task->task_se_cmd;
65 struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev; 64 struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev;
66 struct se_port *port; 65 struct se_port *port;
67 struct t10_alua_tg_pt_gp *tg_pt_gp; 66 struct t10_alua_tg_pt_gp *tg_pt_gp;
@@ -166,8 +165,7 @@ int target_emulate_report_target_port_groups(struct se_task *task)
166 165
167 transport_kunmap_data_sg(cmd); 166 transport_kunmap_data_sg(cmd);
168 167
169 task->task_scsi_status = GOOD; 168 target_complete_cmd(cmd, GOOD);
170 transport_complete_task(task, 1);
171 return 0; 169 return 0;
172} 170}
173 171
@@ -176,9 +174,8 @@ int target_emulate_report_target_port_groups(struct se_task *task)
176 * 174 *
177 * See spc4r17 section 6.35 175 * See spc4r17 section 6.35
178 */ 176 */
179int target_emulate_set_target_port_groups(struct se_task *task) 177int target_emulate_set_target_port_groups(struct se_cmd *cmd)
180{ 178{
181 struct se_cmd *cmd = task->task_se_cmd;
182 struct se_device *dev = cmd->se_dev; 179 struct se_device *dev = cmd->se_dev;
183 struct se_subsystem_dev *su_dev = dev->se_sub_dev; 180 struct se_subsystem_dev *su_dev = dev->se_sub_dev;
184 struct se_port *port, *l_port = cmd->se_lun->lun_sep; 181 struct se_port *port, *l_port = cmd->se_lun->lun_sep;
@@ -351,8 +348,7 @@ int target_emulate_set_target_port_groups(struct se_task *task)
351 348
352out: 349out:
353 transport_kunmap_data_sg(cmd); 350 transport_kunmap_data_sg(cmd);
354 task->task_scsi_status = GOOD; 351 target_complete_cmd(cmd, GOOD);
355 transport_complete_task(task, 1);
356 return 0; 352 return 0;
357} 353}
358 354
diff --git a/drivers/target/target_core_alua.h b/drivers/target/target_core_alua.h
index c5b4ecd3e745..e26454324752 100644
--- a/drivers/target/target_core_alua.h
+++ b/drivers/target/target_core_alua.h
@@ -66,8 +66,8 @@ extern struct kmem_cache *t10_alua_lu_gp_mem_cache;
66extern struct kmem_cache *t10_alua_tg_pt_gp_cache; 66extern struct kmem_cache *t10_alua_tg_pt_gp_cache;
67extern struct kmem_cache *t10_alua_tg_pt_gp_mem_cache; 67extern struct kmem_cache *t10_alua_tg_pt_gp_mem_cache;
68 68
69extern int target_emulate_report_target_port_groups(struct se_task *); 69extern int target_emulate_report_target_port_groups(struct se_cmd *);
70extern int target_emulate_set_target_port_groups(struct se_task *); 70extern int target_emulate_set_target_port_groups(struct se_cmd *);
71extern int core_alua_check_nonop_delay(struct se_cmd *); 71extern int core_alua_check_nonop_delay(struct se_cmd *);
72extern int core_alua_do_port_transition(struct t10_alua_tg_pt_gp *, 72extern int core_alua_do_port_transition(struct t10_alua_tg_pt_gp *,
73 struct se_device *, struct se_port *, 73 struct se_device *, struct se_port *,
diff --git a/drivers/target/target_core_cdb.c b/drivers/target/target_core_cdb.c
index 8e6b91d0380d..22cf44cf43ac 100644
--- a/drivers/target/target_core_cdb.c
+++ b/drivers/target/target_core_cdb.c
@@ -601,9 +601,8 @@ target_emulate_evpd_00(struct se_cmd *cmd, unsigned char *buf)
601 return 0; 601 return 0;
602} 602}
603 603
604int target_emulate_inquiry(struct se_task *task) 604int target_emulate_inquiry(struct se_cmd *cmd)
605{ 605{
606 struct se_cmd *cmd = task->task_se_cmd;
607 struct se_device *dev = cmd->se_dev; 606 struct se_device *dev = cmd->se_dev;
608 struct se_portal_group *tpg = cmd->se_lun->lun_sep->sep_tpg; 607 struct se_portal_group *tpg = cmd->se_lun->lun_sep->sep_tpg;
609 unsigned char *buf, *map_buf; 608 unsigned char *buf, *map_buf;
@@ -667,16 +666,13 @@ out:
667 } 666 }
668 transport_kunmap_data_sg(cmd); 667 transport_kunmap_data_sg(cmd);
669 668
670 if (!ret) { 669 if (!ret)
671 task->task_scsi_status = GOOD; 670 target_complete_cmd(cmd, GOOD);
672 transport_complete_task(task, 1);
673 }
674 return ret; 671 return ret;
675} 672}
676 673
677int target_emulate_readcapacity(struct se_task *task) 674int target_emulate_readcapacity(struct se_cmd *cmd)
678{ 675{
679 struct se_cmd *cmd = task->task_se_cmd;
680 struct se_device *dev = cmd->se_dev; 676 struct se_device *dev = cmd->se_dev;
681 unsigned char *buf; 677 unsigned char *buf;
682 unsigned long long blocks_long = dev->transport->get_blocks(dev); 678 unsigned long long blocks_long = dev->transport->get_blocks(dev);
@@ -700,14 +696,12 @@ int target_emulate_readcapacity(struct se_task *task)
700 696
701 transport_kunmap_data_sg(cmd); 697 transport_kunmap_data_sg(cmd);
702 698
703 task->task_scsi_status = GOOD; 699 target_complete_cmd(cmd, GOOD);
704 transport_complete_task(task, 1);
705 return 0; 700 return 0;
706} 701}
707 702
708int target_emulate_readcapacity_16(struct se_task *task) 703int target_emulate_readcapacity_16(struct se_cmd *cmd)
709{ 704{
710 struct se_cmd *cmd = task->task_se_cmd;
711 struct se_device *dev = cmd->se_dev; 705 struct se_device *dev = cmd->se_dev;
712 unsigned char *buf; 706 unsigned char *buf;
713 unsigned long long blocks = dev->transport->get_blocks(dev); 707 unsigned long long blocks = dev->transport->get_blocks(dev);
@@ -735,8 +729,7 @@ int target_emulate_readcapacity_16(struct se_task *task)
735 729
736 transport_kunmap_data_sg(cmd); 730 transport_kunmap_data_sg(cmd);
737 731
738 task->task_scsi_status = GOOD; 732 target_complete_cmd(cmd, GOOD);
739 transport_complete_task(task, 1);
740 return 0; 733 return 0;
741} 734}
742 735
@@ -875,9 +868,8 @@ target_modesense_dpofua(unsigned char *buf, int type)
875 } 868 }
876} 869}
877 870
878int target_emulate_modesense(struct se_task *task) 871int target_emulate_modesense(struct se_cmd *cmd)
879{ 872{
880 struct se_cmd *cmd = task->task_se_cmd;
881 struct se_device *dev = cmd->se_dev; 873 struct se_device *dev = cmd->se_dev;
882 char *cdb = cmd->t_task_cdb; 874 char *cdb = cmd->t_task_cdb;
883 unsigned char *rbuf; 875 unsigned char *rbuf;
@@ -950,14 +942,12 @@ int target_emulate_modesense(struct se_task *task)
950 memcpy(rbuf, buf, offset); 942 memcpy(rbuf, buf, offset);
951 transport_kunmap_data_sg(cmd); 943 transport_kunmap_data_sg(cmd);
952 944
953 task->task_scsi_status = GOOD; 945 target_complete_cmd(cmd, GOOD);
954 transport_complete_task(task, 1);
955 return 0; 946 return 0;
956} 947}
957 948
958int target_emulate_request_sense(struct se_task *task) 949int target_emulate_request_sense(struct se_cmd *cmd)
959{ 950{
960 struct se_cmd *cmd = task->task_se_cmd;
961 unsigned char *cdb = cmd->t_task_cdb; 951 unsigned char *cdb = cmd->t_task_cdb;
962 unsigned char *buf; 952 unsigned char *buf;
963 u8 ua_asc = 0, ua_ascq = 0; 953 u8 ua_asc = 0, ua_ascq = 0;
@@ -1011,8 +1001,7 @@ int target_emulate_request_sense(struct se_task *task)
1011 1001
1012end: 1002end:
1013 transport_kunmap_data_sg(cmd); 1003 transport_kunmap_data_sg(cmd);
1014 task->task_scsi_status = GOOD; 1004 target_complete_cmd(cmd, GOOD);
1015 transport_complete_task(task, 1);
1016 return 0; 1005 return 0;
1017} 1006}
1018 1007
@@ -1020,9 +1009,8 @@ end:
1020 * Used for TCM/IBLOCK and TCM/FILEIO for block/blk-lib.c level discard support. 1009 * Used for TCM/IBLOCK and TCM/FILEIO for block/blk-lib.c level discard support.
1021 * Note this is not used for TCM/pSCSI passthrough 1010 * Note this is not used for TCM/pSCSI passthrough
1022 */ 1011 */
1023int target_emulate_unmap(struct se_task *task) 1012int target_emulate_unmap(struct se_cmd *cmd)
1024{ 1013{
1025 struct se_cmd *cmd = task->task_se_cmd;
1026 struct se_device *dev = cmd->se_dev; 1014 struct se_device *dev = cmd->se_dev;
1027 unsigned char *buf, *ptr = NULL; 1015 unsigned char *buf, *ptr = NULL;
1028 unsigned char *cdb = &cmd->t_task_cdb[0]; 1016 unsigned char *cdb = &cmd->t_task_cdb[0];
@@ -1069,10 +1057,8 @@ int target_emulate_unmap(struct se_task *task)
1069 1057
1070err: 1058err:
1071 transport_kunmap_data_sg(cmd); 1059 transport_kunmap_data_sg(cmd);
1072 if (!ret) { 1060 if (!ret)
1073 task->task_scsi_status = GOOD; 1061 target_complete_cmd(cmd, GOOD);
1074 transport_complete_task(task, 1);
1075 }
1076 return ret; 1062 return ret;
1077} 1063}
1078 1064
@@ -1080,9 +1066,8 @@ err:
1080 * Used for TCM/IBLOCK and TCM/FILEIO for block/blk-lib.c level discard support. 1066 * Used for TCM/IBLOCK and TCM/FILEIO for block/blk-lib.c level discard support.
1081 * Note this is not used for TCM/pSCSI passthrough 1067 * Note this is not used for TCM/pSCSI passthrough
1082 */ 1068 */
1083int target_emulate_write_same(struct se_task *task) 1069int target_emulate_write_same(struct se_cmd *cmd)
1084{ 1070{
1085 struct se_cmd *cmd = task->task_se_cmd;
1086 struct se_device *dev = cmd->se_dev; 1071 struct se_device *dev = cmd->se_dev;
1087 sector_t range; 1072 sector_t range;
1088 sector_t lba = cmd->t_task_lba; 1073 sector_t lba = cmd->t_task_lba;
@@ -1121,30 +1106,25 @@ int target_emulate_write_same(struct se_task *task)
1121 return ret; 1106 return ret;
1122 } 1107 }
1123 1108
1124 task->task_scsi_status = GOOD; 1109 target_complete_cmd(cmd, GOOD);
1125 transport_complete_task(task, 1);
1126 return 0; 1110 return 0;
1127} 1111}
1128 1112
1129int target_emulate_synchronize_cache(struct se_task *task) 1113int target_emulate_synchronize_cache(struct se_cmd *cmd)
1130{ 1114{
1131 struct se_device *dev = task->task_se_cmd->se_dev; 1115 if (!cmd->se_dev->transport->do_sync_cache) {
1132 struct se_cmd *cmd = task->task_se_cmd;
1133
1134 if (!dev->transport->do_sync_cache) {
1135 pr_err("SYNCHRONIZE_CACHE emulation not supported" 1116 pr_err("SYNCHRONIZE_CACHE emulation not supported"
1136 " for: %s\n", dev->transport->name); 1117 " for: %s\n", cmd->se_dev->transport->name);
1137 cmd->scsi_sense_reason = TCM_UNSUPPORTED_SCSI_OPCODE; 1118 cmd->scsi_sense_reason = TCM_UNSUPPORTED_SCSI_OPCODE;
1138 return -ENOSYS; 1119 return -ENOSYS;
1139 } 1120 }
1140 1121
1141 dev->transport->do_sync_cache(task); 1122 cmd->se_dev->transport->do_sync_cache(cmd);
1142 return 0; 1123 return 0;
1143} 1124}
1144 1125
1145int target_emulate_noop(struct se_task *task) 1126int target_emulate_noop(struct se_cmd *cmd)
1146{ 1127{
1147 task->task_scsi_status = GOOD; 1128 target_complete_cmd(cmd, GOOD);
1148 transport_complete_task(task, 1);
1149 return 0; 1129 return 0;
1150} 1130}
diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index d175ee260a06..e621350feebc 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -643,9 +643,8 @@ void core_dev_unexport(
643 lun->lun_se_dev = NULL; 643 lun->lun_se_dev = NULL;
644} 644}
645 645
646int target_report_luns(struct se_task *se_task) 646int target_report_luns(struct se_cmd *se_cmd)
647{ 647{
648 struct se_cmd *se_cmd = se_task->task_se_cmd;
649 struct se_dev_entry *deve; 648 struct se_dev_entry *deve;
650 struct se_session *se_sess = se_cmd->se_sess; 649 struct se_session *se_sess = se_cmd->se_sess;
651 unsigned char *buf; 650 unsigned char *buf;
@@ -696,8 +695,7 @@ done:
696 buf[3] = (lun_count & 0xff); 695 buf[3] = (lun_count & 0xff);
697 transport_kunmap_data_sg(se_cmd); 696 transport_kunmap_data_sg(se_cmd);
698 697
699 se_task->task_scsi_status = GOOD; 698 target_complete_cmd(se_cmd, GOOD);
700 transport_complete_task(se_task, 1);
701 return 0; 699 return 0;
702} 700}
703 701
diff --git a/drivers/target/target_core_file.c b/drivers/target/target_core_file.c
index 6667039250c0..a984964ab70a 100644
--- a/drivers/target/target_core_file.c
+++ b/drivers/target/target_core_file.c
@@ -356,9 +356,8 @@ static int fd_do_writev(struct se_task *task)
356 return 1; 356 return 1;
357} 357}
358 358
359static void fd_emulate_sync_cache(struct se_task *task) 359static void fd_emulate_sync_cache(struct se_cmd *cmd)
360{ 360{
361 struct se_cmd *cmd = task->task_se_cmd;
362 struct se_device *dev = cmd->se_dev; 361 struct se_device *dev = cmd->se_dev;
363 struct fd_dev *fd_dev = dev->dev_ptr; 362 struct fd_dev *fd_dev = dev->dev_ptr;
364 int immed = (cmd->t_task_cdb[1] & 0x2); 363 int immed = (cmd->t_task_cdb[1] & 0x2);
diff --git a/drivers/target/target_core_iblock.c b/drivers/target/target_core_iblock.c
index 873440bf65f3..82ec0d3fa9dd 100644
--- a/drivers/target/target_core_iblock.c
+++ b/drivers/target/target_core_iblock.c
@@ -304,9 +304,8 @@ static void iblock_end_io_flush(struct bio *bio, int err)
304 * Implement SYCHRONIZE CACHE. Note that we can't handle lba ranges and must 304 * Implement SYCHRONIZE CACHE. Note that we can't handle lba ranges and must
305 * always flush the whole cache. 305 * always flush the whole cache.
306 */ 306 */
307static void iblock_emulate_sync_cache(struct se_task *task) 307static void iblock_emulate_sync_cache(struct se_cmd *cmd)
308{ 308{
309 struct se_cmd *cmd = task->task_se_cmd;
310 struct iblock_dev *ib_dev = cmd->se_dev->dev_ptr; 309 struct iblock_dev *ib_dev = cmd->se_dev->dev_ptr;
311 int immed = (cmd->t_task_cdb[1] & 0x2); 310 int immed = (cmd->t_task_cdb[1] & 0x2);
312 struct bio *bio; 311 struct bio *bio;
diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h
index 21c05638f158..1675be4e308c 100644
--- a/drivers/target/target_core_internal.h
+++ b/drivers/target/target_core_internal.h
@@ -5,15 +5,15 @@
5extern struct t10_alua_lu_gp *default_lu_gp; 5extern struct t10_alua_lu_gp *default_lu_gp;
6 6
7/* target_core_cdb.c */ 7/* target_core_cdb.c */
8int target_emulate_inquiry(struct se_task *task); 8int target_emulate_inquiry(struct se_cmd *cmd);
9int target_emulate_readcapacity(struct se_task *task); 9int target_emulate_readcapacity(struct se_cmd *cmd);
10int target_emulate_readcapacity_16(struct se_task *task); 10int target_emulate_readcapacity_16(struct se_cmd *cmd);
11int target_emulate_modesense(struct se_task *task); 11int target_emulate_modesense(struct se_cmd *cmd);
12int target_emulate_request_sense(struct se_task *task); 12int target_emulate_request_sense(struct se_cmd *cmd);
13int target_emulate_unmap(struct se_task *task); 13int target_emulate_unmap(struct se_cmd *cmd);
14int target_emulate_write_same(struct se_task *task); 14int target_emulate_write_same(struct se_cmd *cmd);
15int target_emulate_synchronize_cache(struct se_task *task); 15int target_emulate_synchronize_cache(struct se_cmd *cmd);
16int target_emulate_noop(struct se_task *task); 16int target_emulate_noop(struct se_cmd *cmd);
17 17
18/* target_core_device.c */ 18/* target_core_device.c */
19struct se_dev_entry *core_get_se_deve_from_rtpi(struct se_node_acl *, u16); 19struct se_dev_entry *core_get_se_deve_from_rtpi(struct se_node_acl *, u16);
@@ -28,7 +28,7 @@ int core_dev_export(struct se_device *, struct se_portal_group *,
28 struct se_lun *); 28 struct se_lun *);
29void core_dev_unexport(struct se_device *, struct se_portal_group *, 29void core_dev_unexport(struct se_device *, struct se_portal_group *,
30 struct se_lun *); 30 struct se_lun *);
31int target_report_luns(struct se_task *); 31int target_report_luns(struct se_cmd *);
32void se_release_device_for_hba(struct se_device *); 32void se_release_device_for_hba(struct se_device *);
33void se_release_vpd_for_dev(struct se_device *); 33void se_release_vpd_for_dev(struct se_device *);
34int se_free_virtual_device(struct se_device *, struct se_hba *); 34int se_free_virtual_device(struct se_device *, struct se_hba *);
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index 9754819b6042..f5ba98693796 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -193,9 +193,8 @@ static int target_check_scsi2_reservation_conflict(struct se_cmd *cmd)
193 return 0; 193 return 0;
194} 194}
195 195
196int target_scsi2_reservation_release(struct se_task *task) 196int target_scsi2_reservation_release(struct se_cmd *cmd)
197{ 197{
198 struct se_cmd *cmd = task->task_se_cmd;
199 struct se_device *dev = cmd->se_dev; 198 struct se_device *dev = cmd->se_dev;
200 struct se_session *sess = cmd->se_sess; 199 struct se_session *sess = cmd->se_sess;
201 struct se_portal_group *tpg = sess->se_tpg; 200 struct se_portal_group *tpg = sess->se_tpg;
@@ -234,16 +233,13 @@ int target_scsi2_reservation_release(struct se_task *task)
234out_unlock: 233out_unlock:
235 spin_unlock(&dev->dev_reservation_lock); 234 spin_unlock(&dev->dev_reservation_lock);
236out: 235out:
237 if (!ret) { 236 if (!ret)
238 task->task_scsi_status = GOOD; 237 target_complete_cmd(cmd, GOOD);
239 transport_complete_task(task, 1);
240 }
241 return ret; 238 return ret;
242} 239}
243 240
244int target_scsi2_reservation_reserve(struct se_task *task) 241int target_scsi2_reservation_reserve(struct se_cmd *cmd)
245{ 242{
246 struct se_cmd *cmd = task->task_se_cmd;
247 struct se_device *dev = cmd->se_dev; 243 struct se_device *dev = cmd->se_dev;
248 struct se_session *sess = cmd->se_sess; 244 struct se_session *sess = cmd->se_sess;
249 struct se_portal_group *tpg = sess->se_tpg; 245 struct se_portal_group *tpg = sess->se_tpg;
@@ -304,10 +300,8 @@ int target_scsi2_reservation_reserve(struct se_task *task)
304out_unlock: 300out_unlock:
305 spin_unlock(&dev->dev_reservation_lock); 301 spin_unlock(&dev->dev_reservation_lock);
306out: 302out:
307 if (!ret) { 303 if (!ret)
308 task->task_scsi_status = GOOD; 304 target_complete_cmd(cmd, GOOD);
309 transport_complete_task(task, 1);
310 }
311 return ret; 305 return ret;
312} 306}
313 307
@@ -3798,9 +3792,8 @@ static unsigned long long core_scsi3_extract_reservation_key(unsigned char *cdb)
3798/* 3792/*
3799 * See spc4r17 section 6.14 Table 170 3793 * See spc4r17 section 6.14 Table 170
3800 */ 3794 */
3801int target_scsi3_emulate_pr_out(struct se_task *task) 3795int target_scsi3_emulate_pr_out(struct se_cmd *cmd)
3802{ 3796{
3803 struct se_cmd *cmd = task->task_se_cmd;
3804 unsigned char *cdb = &cmd->t_task_cdb[0]; 3797 unsigned char *cdb = &cmd->t_task_cdb[0];
3805 unsigned char *buf; 3798 unsigned char *buf;
3806 u64 res_key, sa_res_key; 3799 u64 res_key, sa_res_key;
@@ -3940,10 +3933,8 @@ int target_scsi3_emulate_pr_out(struct se_task *task)
3940 } 3933 }
3941 3934
3942out: 3935out:
3943 if (!ret) { 3936 if (!ret)
3944 task->task_scsi_status = GOOD; 3937 target_complete_cmd(cmd, GOOD);
3945 transport_complete_task(task, 1);
3946 }
3947 return ret; 3938 return ret;
3948} 3939}
3949 3940
@@ -4298,9 +4289,8 @@ static int core_scsi3_pri_read_full_status(struct se_cmd *cmd)
4298 return 0; 4289 return 0;
4299} 4290}
4300 4291
4301int target_scsi3_emulate_pr_in(struct se_task *task) 4292int target_scsi3_emulate_pr_in(struct se_cmd *cmd)
4302{ 4293{
4303 struct se_cmd *cmd = task->task_se_cmd;
4304 int ret; 4294 int ret;
4305 4295
4306 /* 4296 /*
@@ -4341,10 +4331,8 @@ int target_scsi3_emulate_pr_in(struct se_task *task)
4341 break; 4331 break;
4342 } 4332 }
4343 4333
4344 if (!ret) { 4334 if (!ret)
4345 task->task_scsi_status = GOOD; 4335 target_complete_cmd(cmd, GOOD);
4346 transport_complete_task(task, 1);
4347 }
4348 return ret; 4336 return ret;
4349} 4337}
4350 4338
diff --git a/drivers/target/target_core_pr.h b/drivers/target/target_core_pr.h
index 7a233feb7e99..af6c460d886d 100644
--- a/drivers/target/target_core_pr.h
+++ b/drivers/target/target_core_pr.h
@@ -47,8 +47,8 @@ extern struct kmem_cache *t10_pr_reg_cache;
47 47
48extern int core_pr_dump_initiator_port(struct t10_pr_registration *, 48extern int core_pr_dump_initiator_port(struct t10_pr_registration *,
49 char *, u32); 49 char *, u32);
50extern int target_scsi2_reservation_release(struct se_task *task); 50extern int target_scsi2_reservation_release(struct se_cmd *);
51extern int target_scsi2_reservation_reserve(struct se_task *task); 51extern int target_scsi2_reservation_reserve(struct se_cmd *);
52extern int core_scsi3_alloc_aptpl_registration( 52extern int core_scsi3_alloc_aptpl_registration(
53 struct t10_reservation *, u64, 53 struct t10_reservation *, u64,
54 unsigned char *, unsigned char *, u32, 54 unsigned char *, unsigned char *, u32,
@@ -61,8 +61,8 @@ extern void core_scsi3_free_pr_reg_from_nacl(struct se_device *,
61extern void core_scsi3_free_all_registrations(struct se_device *); 61extern void core_scsi3_free_all_registrations(struct se_device *);
62extern unsigned char *core_scsi3_pr_dump_type(int); 62extern unsigned char *core_scsi3_pr_dump_type(int);
63 63
64extern int target_scsi3_emulate_pr_in(struct se_task *task); 64extern int target_scsi3_emulate_pr_in(struct se_cmd *);
65extern int target_scsi3_emulate_pr_out(struct se_task *task); 65extern int target_scsi3_emulate_pr_out(struct se_cmd *);
66extern int core_setup_reservations(struct se_device *, int); 66extern int core_setup_reservations(struct se_device *, int);
67 67
68#endif /* TARGET_CORE_PR_H */ 68#endif /* TARGET_CORE_PR_H */
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index be580ab7afac..087bbea46cdc 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -772,6 +772,16 @@ void transport_complete_task(struct se_task *task, int success)
772} 772}
773EXPORT_SYMBOL(transport_complete_task); 773EXPORT_SYMBOL(transport_complete_task);
774 774
775void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status)
776{
777 struct se_task *task = list_entry(cmd->t_task_list.next,
778 struct se_task, t_list);
779
780 task->task_scsi_status = scsi_status;
781 transport_complete_task(task, scsi_status == GOOD);
782}
783EXPORT_SYMBOL(target_complete_cmd);
784
775/* 785/*
776 * Called by transport_add_tasks_from_cmd() once a struct se_cmd's 786 * Called by transport_add_tasks_from_cmd() once a struct se_cmd's
777 * struct se_task list are ready to be added to the active execution list 787 * struct se_task list are ready to be added to the active execution list
@@ -2233,8 +2243,8 @@ check_depth:
2233 2243
2234 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2244 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2235 2245
2236 if (cmd->execute_task) 2246 if (cmd->execute_cmd)
2237 error = cmd->execute_task(task); 2247 error = cmd->execute_cmd(cmd);
2238 else 2248 else
2239 error = dev->transport->do_task(task); 2249 error = dev->transport->do_task(task);
2240 if (error != 0) { 2250 if (error != 0) {
@@ -2804,7 +2814,7 @@ static int transport_generic_cmd_sequencer(
2804 if (target_check_write_same_discard(&cdb[10], dev) < 0) 2814 if (target_check_write_same_discard(&cdb[10], dev) < 0)
2805 goto out_unsupported_cdb; 2815 goto out_unsupported_cdb;
2806 if (!passthrough) 2816 if (!passthrough)
2807 cmd->execute_task = target_emulate_write_same; 2817 cmd->execute_cmd = target_emulate_write_same;
2808 break; 2818 break;
2809 default: 2819 default:
2810 pr_err("VARIABLE_LENGTH_CMD service action" 2820 pr_err("VARIABLE_LENGTH_CMD service action"
@@ -2820,7 +2830,7 @@ static int transport_generic_cmd_sequencer(
2820 */ 2830 */
2821 if (cdb[1] == MI_REPORT_TARGET_PGS && 2831 if (cdb[1] == MI_REPORT_TARGET_PGS &&
2822 su_dev->t10_alua.alua_type == SPC3_ALUA_EMULATED) { 2832 su_dev->t10_alua.alua_type == SPC3_ALUA_EMULATED) {
2823 cmd->execute_task = 2833 cmd->execute_cmd =
2824 target_emulate_report_target_port_groups; 2834 target_emulate_report_target_port_groups;
2825 } 2835 }
2826 size = (cdb[6] << 24) | (cdb[7] << 16) | 2836 size = (cdb[6] << 24) | (cdb[7] << 16) |
@@ -2843,13 +2853,13 @@ static int transport_generic_cmd_sequencer(
2843 size = cdb[4]; 2853 size = cdb[4];
2844 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2854 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2845 if (!passthrough) 2855 if (!passthrough)
2846 cmd->execute_task = target_emulate_modesense; 2856 cmd->execute_cmd = target_emulate_modesense;
2847 break; 2857 break;
2848 case MODE_SENSE_10: 2858 case MODE_SENSE_10:
2849 size = (cdb[7] << 8) + cdb[8]; 2859 size = (cdb[7] << 8) + cdb[8];
2850 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2860 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2851 if (!passthrough) 2861 if (!passthrough)
2852 cmd->execute_task = target_emulate_modesense; 2862 cmd->execute_cmd = target_emulate_modesense;
2853 break; 2863 break;
2854 case GPCMD_READ_BUFFER_CAPACITY: 2864 case GPCMD_READ_BUFFER_CAPACITY:
2855 case GPCMD_SEND_OPC: 2865 case GPCMD_SEND_OPC:
@@ -2871,13 +2881,13 @@ static int transport_generic_cmd_sequencer(
2871 break; 2881 break;
2872 case PERSISTENT_RESERVE_IN: 2882 case PERSISTENT_RESERVE_IN:
2873 if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS) 2883 if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
2874 cmd->execute_task = target_scsi3_emulate_pr_in; 2884 cmd->execute_cmd = target_scsi3_emulate_pr_in;
2875 size = (cdb[7] << 8) + cdb[8]; 2885 size = (cdb[7] << 8) + cdb[8];
2876 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2886 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2877 break; 2887 break;
2878 case PERSISTENT_RESERVE_OUT: 2888 case PERSISTENT_RESERVE_OUT:
2879 if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS) 2889 if (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS)
2880 cmd->execute_task = target_scsi3_emulate_pr_out; 2890 cmd->execute_cmd = target_scsi3_emulate_pr_out;
2881 size = (cdb[7] << 8) + cdb[8]; 2891 size = (cdb[7] << 8) + cdb[8];
2882 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2892 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2883 break; 2893 break;
@@ -2898,7 +2908,7 @@ static int transport_generic_cmd_sequencer(
2898 */ 2908 */
2899 if (cdb[1] == MO_SET_TARGET_PGS && 2909 if (cdb[1] == MO_SET_TARGET_PGS &&
2900 su_dev->t10_alua.alua_type == SPC3_ALUA_EMULATED) { 2910 su_dev->t10_alua.alua_type == SPC3_ALUA_EMULATED) {
2901 cmd->execute_task = 2911 cmd->execute_cmd =
2902 target_emulate_set_target_port_groups; 2912 target_emulate_set_target_port_groups;
2903 } 2913 }
2904 2914
@@ -2920,7 +2930,7 @@ static int transport_generic_cmd_sequencer(
2920 cmd->sam_task_attr = MSG_HEAD_TAG; 2930 cmd->sam_task_attr = MSG_HEAD_TAG;
2921 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2931 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2922 if (!passthrough) 2932 if (!passthrough)
2923 cmd->execute_task = target_emulate_inquiry; 2933 cmd->execute_cmd = target_emulate_inquiry;
2924 break; 2934 break;
2925 case READ_BUFFER: 2935 case READ_BUFFER:
2926 size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8]; 2936 size = (cdb[6] << 16) + (cdb[7] << 8) + cdb[8];
@@ -2930,7 +2940,7 @@ static int transport_generic_cmd_sequencer(
2930 size = READ_CAP_LEN; 2940 size = READ_CAP_LEN;
2931 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2941 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2932 if (!passthrough) 2942 if (!passthrough)
2933 cmd->execute_task = target_emulate_readcapacity; 2943 cmd->execute_cmd = target_emulate_readcapacity;
2934 break; 2944 break;
2935 case READ_MEDIA_SERIAL_NUMBER: 2945 case READ_MEDIA_SERIAL_NUMBER:
2936 case SECURITY_PROTOCOL_IN: 2946 case SECURITY_PROTOCOL_IN:
@@ -2942,7 +2952,7 @@ static int transport_generic_cmd_sequencer(
2942 switch (cmd->t_task_cdb[1] & 0x1f) { 2952 switch (cmd->t_task_cdb[1] & 0x1f) {
2943 case SAI_READ_CAPACITY_16: 2953 case SAI_READ_CAPACITY_16:
2944 if (!passthrough) 2954 if (!passthrough)
2945 cmd->execute_task = 2955 cmd->execute_cmd =
2946 target_emulate_readcapacity_16; 2956 target_emulate_readcapacity_16;
2947 break; 2957 break;
2948 default: 2958 default:
@@ -2985,7 +2995,7 @@ static int transport_generic_cmd_sequencer(
2985 size = cdb[4]; 2995 size = cdb[4];
2986 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 2996 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
2987 if (!passthrough) 2997 if (!passthrough)
2988 cmd->execute_task = target_emulate_request_sense; 2998 cmd->execute_cmd = target_emulate_request_sense;
2989 break; 2999 break;
2990 case READ_ELEMENT_STATUS: 3000 case READ_ELEMENT_STATUS:
2991 size = 65536 * cdb[7] + 256 * cdb[8] + cdb[9]; 3001 size = 65536 * cdb[7] + 256 * cdb[8] + cdb[9];
@@ -3014,7 +3024,7 @@ static int transport_generic_cmd_sequencer(
3014 * emulation disabled. 3024 * emulation disabled.
3015 */ 3025 */
3016 if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH) 3026 if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH)
3017 cmd->execute_task = target_scsi2_reservation_reserve; 3027 cmd->execute_cmd = target_scsi2_reservation_reserve;
3018 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB; 3028 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
3019 break; 3029 break;
3020 case RELEASE: 3030 case RELEASE:
@@ -3029,7 +3039,7 @@ static int transport_generic_cmd_sequencer(
3029 size = cmd->data_length; 3039 size = cmd->data_length;
3030 3040
3031 if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH) 3041 if (su_dev->t10_pr.res_type != SPC_PASSTHROUGH)
3032 cmd->execute_task = target_scsi2_reservation_release; 3042 cmd->execute_cmd = target_scsi2_reservation_release;
3033 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB; 3043 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
3034 break; 3044 break;
3035 case SYNCHRONIZE_CACHE: 3045 case SYNCHRONIZE_CACHE:
@@ -3061,13 +3071,13 @@ static int transport_generic_cmd_sequencer(
3061 if (transport_cmd_get_valid_sectors(cmd) < 0) 3071 if (transport_cmd_get_valid_sectors(cmd) < 0)
3062 goto out_invalid_cdb_field; 3072 goto out_invalid_cdb_field;
3063 } 3073 }
3064 cmd->execute_task = target_emulate_synchronize_cache; 3074 cmd->execute_cmd = target_emulate_synchronize_cache;
3065 break; 3075 break;
3066 case UNMAP: 3076 case UNMAP:
3067 size = get_unaligned_be16(&cdb[7]); 3077 size = get_unaligned_be16(&cdb[7]);
3068 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB; 3078 cmd->se_cmd_flags |= SCF_SCSI_CONTROL_SG_IO_CDB;
3069 if (!passthrough) 3079 if (!passthrough)
3070 cmd->execute_task = target_emulate_unmap; 3080 cmd->execute_cmd = target_emulate_unmap;
3071 break; 3081 break;
3072 case WRITE_SAME_16: 3082 case WRITE_SAME_16:
3073 sectors = transport_get_sectors_16(cdb, cmd, &sector_ret); 3083 sectors = transport_get_sectors_16(cdb, cmd, &sector_ret);
@@ -3087,7 +3097,7 @@ static int transport_generic_cmd_sequencer(
3087 if (target_check_write_same_discard(&cdb[1], dev) < 0) 3097 if (target_check_write_same_discard(&cdb[1], dev) < 0)
3088 goto out_unsupported_cdb; 3098 goto out_unsupported_cdb;
3089 if (!passthrough) 3099 if (!passthrough)
3090 cmd->execute_task = target_emulate_write_same; 3100 cmd->execute_cmd = target_emulate_write_same;
3091 break; 3101 break;
3092 case WRITE_SAME: 3102 case WRITE_SAME:
3093 sectors = transport_get_sectors_10(cdb, cmd, &sector_ret); 3103 sectors = transport_get_sectors_10(cdb, cmd, &sector_ret);
@@ -3110,7 +3120,7 @@ static int transport_generic_cmd_sequencer(
3110 if (target_check_write_same_discard(&cdb[1], dev) < 0) 3120 if (target_check_write_same_discard(&cdb[1], dev) < 0)
3111 goto out_unsupported_cdb; 3121 goto out_unsupported_cdb;
3112 if (!passthrough) 3122 if (!passthrough)
3113 cmd->execute_task = target_emulate_write_same; 3123 cmd->execute_cmd = target_emulate_write_same;
3114 break; 3124 break;
3115 case ALLOW_MEDIUM_REMOVAL: 3125 case ALLOW_MEDIUM_REMOVAL:
3116 case ERASE: 3126 case ERASE:
@@ -3123,7 +3133,7 @@ static int transport_generic_cmd_sequencer(
3123 case WRITE_FILEMARKS: 3133 case WRITE_FILEMARKS:
3124 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB; 3134 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
3125 if (!passthrough) 3135 if (!passthrough)
3126 cmd->execute_task = target_emulate_noop; 3136 cmd->execute_cmd = target_emulate_noop;
3127 break; 3137 break;
3128 case GPCMD_CLOSE_TRACK: 3138 case GPCMD_CLOSE_TRACK:
3129 case INITIALIZE_ELEMENT_STATUS: 3139 case INITIALIZE_ELEMENT_STATUS:
@@ -3133,7 +3143,7 @@ static int transport_generic_cmd_sequencer(
3133 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB; 3143 cmd->se_cmd_flags |= SCF_SCSI_NON_DATA_CDB;
3134 break; 3144 break;
3135 case REPORT_LUNS: 3145 case REPORT_LUNS:
3136 cmd->execute_task = target_report_luns; 3146 cmd->execute_cmd = target_report_luns;
3137 size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9]; 3147 size = (cdb[6] << 24) | (cdb[7] << 16) | (cdb[8] << 8) | cdb[9];
3138 /* 3148 /*
3139 * Do implict HEAD_OF_QUEUE processing for REPORT_LUNS 3149 * Do implict HEAD_OF_QUEUE processing for REPORT_LUNS
@@ -3201,7 +3211,7 @@ static int transport_generic_cmd_sequencer(
3201 } 3211 }
3202 3212
3203 /* reject any command that we don't have a handler for */ 3213 /* reject any command that we don't have a handler for */
3204 if (!(passthrough || cmd->execute_task || 3214 if (!(passthrough || cmd->execute_cmd ||
3205 (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB))) 3215 (cmd->se_cmd_flags & SCF_SCSI_DATA_SG_IO_CDB)))
3206 goto out_unsupported_cdb; 3216 goto out_unsupported_cdb;
3207 3217