target_core_device.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155
  1. /*******************************************************************************
  2. * Filename: target_core_device.c (based on iscsi_target_device.c)
  3. *
  4. * This file contains the TCM Virtual Device and Disk Transport
  5. * agnostic related functions.
  6. *
  7. * (c) Copyright 2003-2013 Datera, Inc.
  8. *
  9. * Nicholas A. Bellinger <nab@kernel.org>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  24. *
  25. ******************************************************************************/
  26. #include <linux/net.h>
  27. #include <linux/string.h>
  28. #include <linux/delay.h>
  29. #include <linux/timer.h>
  30. #include <linux/slab.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/kthread.h>
  33. #include <linux/in.h>
  34. #include <linux/export.h>
  35. #include <linux/t10-pi.h>
  36. #include <asm/unaligned.h>
  37. #include <net/sock.h>
  38. #include <net/tcp.h>
  39. #include <scsi/scsi_common.h>
  40. #include <scsi/scsi_proto.h>
  41. #include <target/target_core_base.h>
  42. #include <target/target_core_backend.h>
  43. #include <target/target_core_fabric.h>
  44. #include "target_core_internal.h"
  45. #include "target_core_alua.h"
  46. #include "target_core_pr.h"
  47. #include "target_core_ua.h"
  48. DEFINE_MUTEX(g_device_mutex);
  49. LIST_HEAD(g_device_list);
  50. static struct se_hba *lun0_hba;
  51. /* not static, needed by tpg.c */
  52. struct se_device *g_lun0_dev;
  53. sense_reason_t
  54. transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
  55. {
  56. struct se_lun *se_lun = NULL;
  57. struct se_session *se_sess = se_cmd->se_sess;
  58. struct se_node_acl *nacl = se_sess->se_node_acl;
  59. struct se_dev_entry *deve;
  60. sense_reason_t ret = TCM_NO_SENSE;
  61. rcu_read_lock();
  62. deve = target_nacl_find_deve(nacl, unpacked_lun);
  63. if (deve) {
  64. atomic_long_inc(&deve->total_cmds);
  65. if (se_cmd->data_direction == DMA_TO_DEVICE)
  66. atomic_long_add(se_cmd->data_length,
  67. &deve->write_bytes);
  68. else if (se_cmd->data_direction == DMA_FROM_DEVICE)
  69. atomic_long_add(se_cmd->data_length,
  70. &deve->read_bytes);
  71. se_lun = rcu_dereference(deve->se_lun);
  72. if (!percpu_ref_tryget_live(&se_lun->lun_ref)) {
  73. se_lun = NULL;
  74. goto out_unlock;
  75. }
  76. se_cmd->se_lun = rcu_dereference(deve->se_lun);
  77. se_cmd->pr_res_key = deve->pr_res_key;
  78. se_cmd->orig_fe_lun = unpacked_lun;
  79. se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
  80. se_cmd->lun_ref_active = true;
  81. if ((se_cmd->data_direction == DMA_TO_DEVICE) &&
  82. deve->lun_access_ro) {
  83. pr_err("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN"
  84. " Access for 0x%08llx\n",
  85. se_cmd->se_tfo->get_fabric_name(),
  86. unpacked_lun);
  87. rcu_read_unlock();
  88. ret = TCM_WRITE_PROTECTED;
  89. goto ref_dev;
  90. }
  91. }
  92. out_unlock:
  93. rcu_read_unlock();
  94. if (!se_lun) {
  95. /*
  96. * Use the se_portal_group->tpg_virt_lun0 to allow for
  97. * REPORT_LUNS, et al to be returned when no active
  98. * MappedLUN=0 exists for this Initiator Port.
  99. */
  100. if (unpacked_lun != 0) {
  101. pr_err("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN"
  102. " Access for 0x%08llx\n",
  103. se_cmd->se_tfo->get_fabric_name(),
  104. unpacked_lun);
  105. return TCM_NON_EXISTENT_LUN;
  106. }
  107. se_lun = se_sess->se_tpg->tpg_virt_lun0;
  108. se_cmd->se_lun = se_sess->se_tpg->tpg_virt_lun0;
  109. se_cmd->orig_fe_lun = 0;
  110. se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
  111. percpu_ref_get(&se_lun->lun_ref);
  112. se_cmd->lun_ref_active = true;
  113. /*
  114. * Force WRITE PROTECT for virtual LUN 0
  115. */
  116. if ((se_cmd->data_direction != DMA_FROM_DEVICE) &&
  117. (se_cmd->data_direction != DMA_NONE)) {
  118. ret = TCM_WRITE_PROTECTED;
  119. goto ref_dev;
  120. }
  121. }
  122. /*
  123. * RCU reference protected by percpu se_lun->lun_ref taken above that
  124. * must drop to zero (including initial reference) before this se_lun
  125. * pointer can be kfree_rcu() by the final se_lun->lun_group put via
  126. * target_core_fabric_configfs.c:target_fabric_port_release
  127. */
  128. ref_dev:
  129. se_cmd->se_dev = rcu_dereference_raw(se_lun->lun_se_dev);
  130. atomic_long_inc(&se_cmd->se_dev->num_cmds);
  131. if (se_cmd->data_direction == DMA_TO_DEVICE)
  132. atomic_long_add(se_cmd->data_length,
  133. &se_cmd->se_dev->write_bytes);
  134. else if (se_cmd->data_direction == DMA_FROM_DEVICE)
  135. atomic_long_add(se_cmd->data_length,
  136. &se_cmd->se_dev->read_bytes);
  137. return ret;
  138. }
  139. EXPORT_SYMBOL(transport_lookup_cmd_lun);
  140. int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun)
  141. {
  142. struct se_dev_entry *deve;
  143. struct se_lun *se_lun = NULL;
  144. struct se_session *se_sess = se_cmd->se_sess;
  145. struct se_node_acl *nacl = se_sess->se_node_acl;
  146. struct se_tmr_req *se_tmr = se_cmd->se_tmr_req;
  147. unsigned long flags;
  148. rcu_read_lock();
  149. deve = target_nacl_find_deve(nacl, unpacked_lun);
  150. if (deve) {
  151. se_lun = rcu_dereference(deve->se_lun);
  152. if (!percpu_ref_tryget_live(&se_lun->lun_ref)) {
  153. se_lun = NULL;
  154. goto out_unlock;
  155. }
  156. se_cmd->se_lun = rcu_dereference(deve->se_lun);
  157. se_cmd->pr_res_key = deve->pr_res_key;
  158. se_cmd->orig_fe_lun = unpacked_lun;
  159. se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD;
  160. se_cmd->lun_ref_active = true;
  161. }
  162. out_unlock:
  163. rcu_read_unlock();
  164. if (!se_lun) {
  165. pr_debug("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN"
  166. " Access for 0x%08llx\n",
  167. se_cmd->se_tfo->get_fabric_name(),
  168. unpacked_lun);
  169. return -ENODEV;
  170. }
  171. se_cmd->se_dev = rcu_dereference_raw(se_lun->lun_se_dev);
  172. se_tmr->tmr_dev = rcu_dereference_raw(se_lun->lun_se_dev);
  173. spin_lock_irqsave(&se_tmr->tmr_dev->se_tmr_lock, flags);
  174. list_add_tail(&se_tmr->tmr_list, &se_tmr->tmr_dev->dev_tmr_list);
  175. spin_unlock_irqrestore(&se_tmr->tmr_dev->se_tmr_lock, flags);
  176. return 0;
  177. }
  178. EXPORT_SYMBOL(transport_lookup_tmr_lun);
  179. bool target_lun_is_rdonly(struct se_cmd *cmd)
  180. {
  181. struct se_session *se_sess = cmd->se_sess;
  182. struct se_dev_entry *deve;
  183. bool ret;
  184. rcu_read_lock();
  185. deve = target_nacl_find_deve(se_sess->se_node_acl, cmd->orig_fe_lun);
  186. ret = deve && deve->lun_access_ro;
  187. rcu_read_unlock();
  188. return ret;
  189. }
  190. EXPORT_SYMBOL(target_lun_is_rdonly);
  191. /*
  192. * This function is called from core_scsi3_emulate_pro_register_and_move()
  193. * and core_scsi3_decode_spec_i_port(), and will increment &deve->pr_kref
  194. * when a matching rtpi is found.
  195. */
  196. struct se_dev_entry *core_get_se_deve_from_rtpi(
  197. struct se_node_acl *nacl,
  198. u16 rtpi)
  199. {
  200. struct se_dev_entry *deve;
  201. struct se_lun *lun;
  202. struct se_portal_group *tpg = nacl->se_tpg;
  203. rcu_read_lock();
  204. hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) {
  205. lun = rcu_dereference(deve->se_lun);
  206. if (!lun) {
  207. pr_err("%s device entries device pointer is"
  208. " NULL, but Initiator has access.\n",
  209. tpg->se_tpg_tfo->get_fabric_name());
  210. continue;
  211. }
  212. if (lun->lun_rtpi != rtpi)
  213. continue;
  214. kref_get(&deve->pr_kref);
  215. rcu_read_unlock();
  216. return deve;
  217. }
  218. rcu_read_unlock();
  219. return NULL;
  220. }
  221. void core_free_device_list_for_node(
  222. struct se_node_acl *nacl,
  223. struct se_portal_group *tpg)
  224. {
  225. struct se_dev_entry *deve;
  226. mutex_lock(&nacl->lun_entry_mutex);
  227. hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) {
  228. struct se_lun *lun = rcu_dereference_check(deve->se_lun,
  229. lockdep_is_held(&nacl->lun_entry_mutex));
  230. core_disable_device_list_for_node(lun, deve, nacl, tpg);
  231. }
  232. mutex_unlock(&nacl->lun_entry_mutex);
  233. }
  234. void core_update_device_list_access(
  235. u64 mapped_lun,
  236. bool lun_access_ro,
  237. struct se_node_acl *nacl)
  238. {
  239. struct se_dev_entry *deve;
  240. mutex_lock(&nacl->lun_entry_mutex);
  241. deve = target_nacl_find_deve(nacl, mapped_lun);
  242. if (deve)
  243. deve->lun_access_ro = lun_access_ro;
  244. mutex_unlock(&nacl->lun_entry_mutex);
  245. }
  246. /*
  247. * Called with rcu_read_lock or nacl->device_list_lock held.
  248. */
  249. struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *nacl, u64 mapped_lun)
  250. {
  251. struct se_dev_entry *deve;
  252. hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link)
  253. if (deve->mapped_lun == mapped_lun)
  254. return deve;
  255. return NULL;
  256. }
  257. EXPORT_SYMBOL(target_nacl_find_deve);
  258. void target_pr_kref_release(struct kref *kref)
  259. {
  260. struct se_dev_entry *deve = container_of(kref, struct se_dev_entry,
  261. pr_kref);
  262. complete(&deve->pr_comp);
  263. }
  264. static void
  265. target_luns_data_has_changed(struct se_node_acl *nacl, struct se_dev_entry *new,
  266. bool skip_new)
  267. {
  268. struct se_dev_entry *tmp;
  269. rcu_read_lock();
  270. hlist_for_each_entry_rcu(tmp, &nacl->lun_entry_hlist, link) {
  271. if (skip_new && tmp == new)
  272. continue;
  273. core_scsi3_ua_allocate(tmp, 0x3F,
  274. ASCQ_3FH_REPORTED_LUNS_DATA_HAS_CHANGED);
  275. }
  276. rcu_read_unlock();
  277. }
  278. int core_enable_device_list_for_node(
  279. struct se_lun *lun,
  280. struct se_lun_acl *lun_acl,
  281. u64 mapped_lun,
  282. bool lun_access_ro,
  283. struct se_node_acl *nacl,
  284. struct se_portal_group *tpg)
  285. {
  286. struct se_dev_entry *orig, *new;
  287. new = kzalloc(sizeof(*new), GFP_KERNEL);
  288. if (!new) {
  289. pr_err("Unable to allocate se_dev_entry memory\n");
  290. return -ENOMEM;
  291. }
  292. atomic_set(&new->ua_count, 0);
  293. spin_lock_init(&new->ua_lock);
  294. INIT_LIST_HEAD(&new->ua_list);
  295. INIT_LIST_HEAD(&new->lun_link);
  296. new->mapped_lun = mapped_lun;
  297. kref_init(&new->pr_kref);
  298. init_completion(&new->pr_comp);
  299. new->lun_access_ro = lun_access_ro;
  300. new->creation_time = get_jiffies_64();
  301. new->attach_count++;
  302. mutex_lock(&nacl->lun_entry_mutex);
  303. orig = target_nacl_find_deve(nacl, mapped_lun);
  304. if (orig && orig->se_lun) {
  305. struct se_lun *orig_lun = rcu_dereference_check(orig->se_lun,
  306. lockdep_is_held(&nacl->lun_entry_mutex));
  307. if (orig_lun != lun) {
  308. pr_err("Existing orig->se_lun doesn't match new lun"
  309. " for dynamic -> explicit NodeACL conversion:"
  310. " %s\n", nacl->initiatorname);
  311. mutex_unlock(&nacl->lun_entry_mutex);
  312. kfree(new);
  313. return -EINVAL;
  314. }
  315. if (orig->se_lun_acl != NULL) {
  316. pr_warn_ratelimited("Detected existing explicit"
  317. " se_lun_acl->se_lun_group reference for %s"
  318. " mapped_lun: %llu, failing\n",
  319. nacl->initiatorname, mapped_lun);
  320. mutex_unlock(&nacl->lun_entry_mutex);
  321. kfree(new);
  322. return -EINVAL;
  323. }
  324. rcu_assign_pointer(new->se_lun, lun);
  325. rcu_assign_pointer(new->se_lun_acl, lun_acl);
  326. hlist_del_rcu(&orig->link);
  327. hlist_add_head_rcu(&new->link, &nacl->lun_entry_hlist);
  328. mutex_unlock(&nacl->lun_entry_mutex);
  329. spin_lock(&lun->lun_deve_lock);
  330. list_del(&orig->lun_link);
  331. list_add_tail(&new->lun_link, &lun->lun_deve_list);
  332. spin_unlock(&lun->lun_deve_lock);
  333. kref_put(&orig->pr_kref, target_pr_kref_release);
  334. wait_for_completion(&orig->pr_comp);
  335. target_luns_data_has_changed(nacl, new, true);
  336. kfree_rcu(orig, rcu_head);
  337. return 0;
  338. }
  339. rcu_assign_pointer(new->se_lun, lun);
  340. rcu_assign_pointer(new->se_lun_acl, lun_acl);
  341. hlist_add_head_rcu(&new->link, &nacl->lun_entry_hlist);
  342. mutex_unlock(&nacl->lun_entry_mutex);
  343. spin_lock(&lun->lun_deve_lock);
  344. list_add_tail(&new->lun_link, &lun->lun_deve_list);
  345. spin_unlock(&lun->lun_deve_lock);
  346. target_luns_data_has_changed(nacl, new, true);
  347. return 0;
  348. }
  349. /*
  350. * Called with se_node_acl->lun_entry_mutex held.
  351. */
  352. void core_disable_device_list_for_node(
  353. struct se_lun *lun,
  354. struct se_dev_entry *orig,
  355. struct se_node_acl *nacl,
  356. struct se_portal_group *tpg)
  357. {
  358. /*
  359. * rcu_dereference_raw protected by se_lun->lun_group symlink
  360. * reference to se_device->dev_group.
  361. */
  362. struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev);
  363. /*
  364. * If the MappedLUN entry is being disabled, the entry in
  365. * lun->lun_deve_list must be removed now before clearing the
  366. * struct se_dev_entry pointers below as logic in
  367. * core_alua_do_transition_tg_pt() depends on these being present.
  368. *
  369. * deve->se_lun_acl will be NULL for demo-mode created LUNs
  370. * that have not been explicitly converted to MappedLUNs ->
  371. * struct se_lun_acl, but we remove deve->lun_link from
  372. * lun->lun_deve_list. This also means that active UAs and
  373. * NodeACL context specific PR metadata for demo-mode
  374. * MappedLUN *deve will be released below..
  375. */
  376. spin_lock(&lun->lun_deve_lock);
  377. list_del(&orig->lun_link);
  378. spin_unlock(&lun->lun_deve_lock);
  379. /*
  380. * Disable struct se_dev_entry LUN ACL mapping
  381. */
  382. core_scsi3_ua_release_all(orig);
  383. hlist_del_rcu(&orig->link);
  384. clear_bit(DEF_PR_REG_ACTIVE, &orig->deve_flags);
  385. orig->lun_access_ro = false;
  386. orig->creation_time = 0;
  387. orig->attach_count--;
  388. /*
  389. * Before firing off RCU callback, wait for any in process SPEC_I_PT=1
  390. * or REGISTER_AND_MOVE PR operation to complete.
  391. */
  392. kref_put(&orig->pr_kref, target_pr_kref_release);
  393. wait_for_completion(&orig->pr_comp);
  394. rcu_assign_pointer(orig->se_lun, NULL);
  395. rcu_assign_pointer(orig->se_lun_acl, NULL);
  396. kfree_rcu(orig, rcu_head);
  397. core_scsi3_free_pr_reg_from_nacl(dev, nacl);
  398. target_luns_data_has_changed(nacl, NULL, false);
  399. }
  400. /* core_clear_lun_from_tpg():
  401. *
  402. *
  403. */
  404. void core_clear_lun_from_tpg(struct se_lun *lun, struct se_portal_group *tpg)
  405. {
  406. struct se_node_acl *nacl;
  407. struct se_dev_entry *deve;
  408. mutex_lock(&tpg->acl_node_mutex);
  409. list_for_each_entry(nacl, &tpg->acl_node_list, acl_list) {
  410. mutex_lock(&nacl->lun_entry_mutex);
  411. hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) {
  412. struct se_lun *tmp_lun = rcu_dereference_check(deve->se_lun,
  413. lockdep_is_held(&nacl->lun_entry_mutex));
  414. if (lun != tmp_lun)
  415. continue;
  416. core_disable_device_list_for_node(lun, deve, nacl, tpg);
  417. }
  418. mutex_unlock(&nacl->lun_entry_mutex);
  419. }
  420. mutex_unlock(&tpg->acl_node_mutex);
  421. }
  422. int core_alloc_rtpi(struct se_lun *lun, struct se_device *dev)
  423. {
  424. struct se_lun *tmp;
  425. spin_lock(&dev->se_port_lock);
  426. if (dev->export_count == 0x0000ffff) {
  427. pr_warn("Reached dev->dev_port_count =="
  428. " 0x0000ffff\n");
  429. spin_unlock(&dev->se_port_lock);
  430. return -ENOSPC;
  431. }
  432. again:
  433. /*
  434. * Allocate the next RELATIVE TARGET PORT IDENTIFIER for this struct se_device
  435. * Here is the table from spc4r17 section 7.7.3.8.
  436. *
  437. * Table 473 -- RELATIVE TARGET PORT IDENTIFIER field
  438. *
  439. * Code Description
  440. * 0h Reserved
  441. * 1h Relative port 1, historically known as port A
  442. * 2h Relative port 2, historically known as port B
  443. * 3h to FFFFh Relative port 3 through 65 535
  444. */
  445. lun->lun_rtpi = dev->dev_rpti_counter++;
  446. if (!lun->lun_rtpi)
  447. goto again;
  448. list_for_each_entry(tmp, &dev->dev_sep_list, lun_dev_link) {
  449. /*
  450. * Make sure RELATIVE TARGET PORT IDENTIFIER is unique
  451. * for 16-bit wrap..
  452. */
  453. if (lun->lun_rtpi == tmp->lun_rtpi)
  454. goto again;
  455. }
  456. spin_unlock(&dev->se_port_lock);
  457. return 0;
  458. }
  459. static void se_release_vpd_for_dev(struct se_device *dev)
  460. {
  461. struct t10_vpd *vpd, *vpd_tmp;
  462. spin_lock(&dev->t10_wwn.t10_vpd_lock);
  463. list_for_each_entry_safe(vpd, vpd_tmp,
  464. &dev->t10_wwn.t10_vpd_list, vpd_list) {
  465. list_del(&vpd->vpd_list);
  466. kfree(vpd);
  467. }
  468. spin_unlock(&dev->t10_wwn.t10_vpd_lock);
  469. }
  470. static u32 se_dev_align_max_sectors(u32 max_sectors, u32 block_size)
  471. {
  472. u32 aligned_max_sectors;
  473. u32 alignment;
  474. /*
  475. * Limit max_sectors to a PAGE_SIZE aligned value for modern
  476. * transport_allocate_data_tasks() operation.
  477. */
  478. alignment = max(1ul, PAGE_SIZE / block_size);
  479. aligned_max_sectors = rounddown(max_sectors, alignment);
  480. if (max_sectors != aligned_max_sectors)
  481. pr_info("Rounding down aligned max_sectors from %u to %u\n",
  482. max_sectors, aligned_max_sectors);
  483. return aligned_max_sectors;
  484. }
  485. int core_dev_add_lun(
  486. struct se_portal_group *tpg,
  487. struct se_device *dev,
  488. struct se_lun *lun)
  489. {
  490. int rc;
  491. rc = core_tpg_add_lun(tpg, lun, false, dev);
  492. if (rc < 0)
  493. return rc;
  494. pr_debug("%s_TPG[%u]_LUN[%llu] - Activated %s Logical Unit from"
  495. " CORE HBA: %u\n", tpg->se_tpg_tfo->get_fabric_name(),
  496. tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
  497. tpg->se_tpg_tfo->get_fabric_name(), dev->se_hba->hba_id);
  498. /*
  499. * Update LUN maps for dynamically added initiators when
  500. * generate_node_acl is enabled.
  501. */
  502. if (tpg->se_tpg_tfo->tpg_check_demo_mode(tpg)) {
  503. struct se_node_acl *acl;
  504. mutex_lock(&tpg->acl_node_mutex);
  505. list_for_each_entry(acl, &tpg->acl_node_list, acl_list) {
  506. if (acl->dynamic_node_acl &&
  507. (!tpg->se_tpg_tfo->tpg_check_demo_mode_login_only ||
  508. !tpg->se_tpg_tfo->tpg_check_demo_mode_login_only(tpg))) {
  509. core_tpg_add_node_to_devs(acl, tpg, lun);
  510. }
  511. }
  512. mutex_unlock(&tpg->acl_node_mutex);
  513. }
  514. return 0;
  515. }
  516. /* core_dev_del_lun():
  517. *
  518. *
  519. */
  520. void core_dev_del_lun(
  521. struct se_portal_group *tpg,
  522. struct se_lun *lun)
  523. {
  524. pr_debug("%s_TPG[%u]_LUN[%llu] - Deactivating %s Logical Unit from"
  525. " device object\n", tpg->se_tpg_tfo->get_fabric_name(),
  526. tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
  527. tpg->se_tpg_tfo->get_fabric_name());
  528. core_tpg_remove_lun(tpg, lun);
  529. }
  530. struct se_lun_acl *core_dev_init_initiator_node_lun_acl(
  531. struct se_portal_group *tpg,
  532. struct se_node_acl *nacl,
  533. u64 mapped_lun,
  534. int *ret)
  535. {
  536. struct se_lun_acl *lacl;
  537. if (strlen(nacl->initiatorname) >= TRANSPORT_IQN_LEN) {
  538. pr_err("%s InitiatorName exceeds maximum size.\n",
  539. tpg->se_tpg_tfo->get_fabric_name());
  540. *ret = -EOVERFLOW;
  541. return NULL;
  542. }
  543. lacl = kzalloc(sizeof(struct se_lun_acl), GFP_KERNEL);
  544. if (!lacl) {
  545. pr_err("Unable to allocate memory for struct se_lun_acl.\n");
  546. *ret = -ENOMEM;
  547. return NULL;
  548. }
  549. lacl->mapped_lun = mapped_lun;
  550. lacl->se_lun_nacl = nacl;
  551. return lacl;
  552. }
  553. int core_dev_add_initiator_node_lun_acl(
  554. struct se_portal_group *tpg,
  555. struct se_lun_acl *lacl,
  556. struct se_lun *lun,
  557. bool lun_access_ro)
  558. {
  559. struct se_node_acl *nacl = lacl->se_lun_nacl;
  560. /*
  561. * rcu_dereference_raw protected by se_lun->lun_group symlink
  562. * reference to se_device->dev_group.
  563. */
  564. struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev);
  565. if (!nacl)
  566. return -EINVAL;
  567. if (lun->lun_access_ro)
  568. lun_access_ro = true;
  569. lacl->se_lun = lun;
  570. if (core_enable_device_list_for_node(lun, lacl, lacl->mapped_lun,
  571. lun_access_ro, nacl, tpg) < 0)
  572. return -EINVAL;
  573. pr_debug("%s_TPG[%hu]_LUN[%llu->%llu] - Added %s ACL for "
  574. " InitiatorNode: %s\n", tpg->se_tpg_tfo->get_fabric_name(),
  575. tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun, lacl->mapped_lun,
  576. lun_access_ro ? "RO" : "RW",
  577. nacl->initiatorname);
  578. /*
  579. * Check to see if there are any existing persistent reservation APTPL
  580. * pre-registrations that need to be enabled for this LUN ACL..
  581. */
  582. core_scsi3_check_aptpl_registration(dev, tpg, lun, nacl,
  583. lacl->mapped_lun);
  584. return 0;
  585. }
  586. int core_dev_del_initiator_node_lun_acl(
  587. struct se_lun *lun,
  588. struct se_lun_acl *lacl)
  589. {
  590. struct se_portal_group *tpg = lun->lun_tpg;
  591. struct se_node_acl *nacl;
  592. struct se_dev_entry *deve;
  593. nacl = lacl->se_lun_nacl;
  594. if (!nacl)
  595. return -EINVAL;
  596. mutex_lock(&nacl->lun_entry_mutex);
  597. deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
  598. if (deve)
  599. core_disable_device_list_for_node(lun, deve, nacl, tpg);
  600. mutex_unlock(&nacl->lun_entry_mutex);
  601. pr_debug("%s_TPG[%hu]_LUN[%llu] - Removed ACL for"
  602. " InitiatorNode: %s Mapped LUN: %llu\n",
  603. tpg->se_tpg_tfo->get_fabric_name(),
  604. tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
  605. nacl->initiatorname, lacl->mapped_lun);
  606. return 0;
  607. }
  608. void core_dev_free_initiator_node_lun_acl(
  609. struct se_portal_group *tpg,
  610. struct se_lun_acl *lacl)
  611. {
  612. pr_debug("%s_TPG[%hu] - Freeing ACL for %s InitiatorNode: %s"
  613. " Mapped LUN: %llu\n", tpg->se_tpg_tfo->get_fabric_name(),
  614. tpg->se_tpg_tfo->tpg_get_tag(tpg),
  615. tpg->se_tpg_tfo->get_fabric_name(),
  616. lacl->se_lun_nacl->initiatorname, lacl->mapped_lun);
  617. kfree(lacl);
  618. }
  619. static void scsi_dump_inquiry(struct se_device *dev)
  620. {
  621. struct t10_wwn *wwn = &dev->t10_wwn;
  622. char buf[17];
  623. int i, device_type;
  624. /*
  625. * Print Linux/SCSI style INQUIRY formatting to the kernel ring buffer
  626. */
  627. for (i = 0; i < 8; i++)
  628. if (wwn->vendor[i] >= 0x20)
  629. buf[i] = wwn->vendor[i];
  630. else
  631. buf[i] = ' ';
  632. buf[i] = '\0';
  633. pr_debug(" Vendor: %s\n", buf);
  634. for (i = 0; i < 16; i++)
  635. if (wwn->model[i] >= 0x20)
  636. buf[i] = wwn->model[i];
  637. else
  638. buf[i] = ' ';
  639. buf[i] = '\0';
  640. pr_debug(" Model: %s\n", buf);
  641. for (i = 0; i < 4; i++)
  642. if (wwn->revision[i] >= 0x20)
  643. buf[i] = wwn->revision[i];
  644. else
  645. buf[i] = ' ';
  646. buf[i] = '\0';
  647. pr_debug(" Revision: %s\n", buf);
  648. device_type = dev->transport->get_device_type(dev);
  649. pr_debug(" Type: %s ", scsi_device_type(device_type));
  650. }
  651. struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
  652. {
  653. struct se_device *dev;
  654. struct se_lun *xcopy_lun;
  655. dev = hba->backend->ops->alloc_device(hba, name);
  656. if (!dev)
  657. return NULL;
  658. dev->se_hba = hba;
  659. dev->transport = hba->backend->ops;
  660. dev->prot_length = sizeof(struct t10_pi_tuple);
  661. dev->hba_index = hba->hba_index;
  662. INIT_LIST_HEAD(&dev->dev_sep_list);
  663. INIT_LIST_HEAD(&dev->dev_tmr_list);
  664. INIT_LIST_HEAD(&dev->delayed_cmd_list);
  665. INIT_LIST_HEAD(&dev->state_list);
  666. INIT_LIST_HEAD(&dev->qf_cmd_list);
  667. INIT_LIST_HEAD(&dev->g_dev_node);
  668. spin_lock_init(&dev->execute_task_lock);
  669. spin_lock_init(&dev->delayed_cmd_lock);
  670. spin_lock_init(&dev->dev_reservation_lock);
  671. spin_lock_init(&dev->se_port_lock);
  672. spin_lock_init(&dev->se_tmr_lock);
  673. spin_lock_init(&dev->qf_cmd_lock);
  674. sema_init(&dev->caw_sem, 1);
  675. INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
  676. spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
  677. INIT_LIST_HEAD(&dev->t10_pr.registration_list);
  678. INIT_LIST_HEAD(&dev->t10_pr.aptpl_reg_list);
  679. spin_lock_init(&dev->t10_pr.registration_lock);
  680. spin_lock_init(&dev->t10_pr.aptpl_reg_lock);
  681. INIT_LIST_HEAD(&dev->t10_alua.tg_pt_gps_list);
  682. spin_lock_init(&dev->t10_alua.tg_pt_gps_lock);
  683. INIT_LIST_HEAD(&dev->t10_alua.lba_map_list);
  684. spin_lock_init(&dev->t10_alua.lba_map_lock);
  685. dev->t10_wwn.t10_dev = dev;
  686. dev->t10_alua.t10_dev = dev;
  687. dev->dev_attrib.da_dev = dev;
  688. dev->dev_attrib.emulate_model_alias = DA_EMULATE_MODEL_ALIAS;
  689. dev->dev_attrib.emulate_dpo = 1;
  690. dev->dev_attrib.emulate_fua_write = 1;
  691. dev->dev_attrib.emulate_fua_read = 1;
  692. dev->dev_attrib.emulate_write_cache = DA_EMULATE_WRITE_CACHE;
  693. dev->dev_attrib.emulate_ua_intlck_ctrl = DA_EMULATE_UA_INTLLCK_CTRL;
  694. dev->dev_attrib.emulate_tas = DA_EMULATE_TAS;
  695. dev->dev_attrib.emulate_tpu = DA_EMULATE_TPU;
  696. dev->dev_attrib.emulate_tpws = DA_EMULATE_TPWS;
  697. dev->dev_attrib.emulate_caw = DA_EMULATE_CAW;
  698. dev->dev_attrib.emulate_3pc = DA_EMULATE_3PC;
  699. dev->dev_attrib.pi_prot_type = TARGET_DIF_TYPE0_PROT;
  700. dev->dev_attrib.enforce_pr_isids = DA_ENFORCE_PR_ISIDS;
  701. dev->dev_attrib.force_pr_aptpl = DA_FORCE_PR_APTPL;
  702. dev->dev_attrib.is_nonrot = DA_IS_NONROT;
  703. dev->dev_attrib.emulate_rest_reord = DA_EMULATE_REST_REORD;
  704. dev->dev_attrib.max_unmap_lba_count = DA_MAX_UNMAP_LBA_COUNT;
  705. dev->dev_attrib.max_unmap_block_desc_count =
  706. DA_MAX_UNMAP_BLOCK_DESC_COUNT;
  707. dev->dev_attrib.unmap_granularity = DA_UNMAP_GRANULARITY_DEFAULT;
  708. dev->dev_attrib.unmap_granularity_alignment =
  709. DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT;
  710. dev->dev_attrib.unmap_zeroes_data =
  711. DA_UNMAP_ZEROES_DATA_DEFAULT;
  712. dev->dev_attrib.max_write_same_len = DA_MAX_WRITE_SAME_LEN;
  713. xcopy_lun = &dev->xcopy_lun;
  714. rcu_assign_pointer(xcopy_lun->lun_se_dev, dev);
  715. init_completion(&xcopy_lun->lun_ref_comp);
  716. init_completion(&xcopy_lun->lun_shutdown_comp);
  717. INIT_LIST_HEAD(&xcopy_lun->lun_deve_list);
  718. INIT_LIST_HEAD(&xcopy_lun->lun_dev_link);
  719. mutex_init(&xcopy_lun->lun_tg_pt_md_mutex);
  720. xcopy_lun->lun_tpg = &xcopy_pt_tpg;
  721. return dev;
  722. }
  723. /*
  724. * Check if the underlying struct block_device request_queue supports
  725. * the QUEUE_FLAG_DISCARD bit for UNMAP/WRITE_SAME in SCSI + TRIM
  726. * in ATA and we need to set TPE=1
  727. */
  728. bool target_configure_unmap_from_queue(struct se_dev_attrib *attrib,
  729. struct request_queue *q)
  730. {
  731. int block_size = queue_logical_block_size(q);
  732. if (!blk_queue_discard(q))
  733. return false;
  734. attrib->max_unmap_lba_count =
  735. q->limits.max_discard_sectors >> (ilog2(block_size) - 9);
  736. /*
  737. * Currently hardcoded to 1 in Linux/SCSI code..
  738. */
  739. attrib->max_unmap_block_desc_count = 1;
  740. attrib->unmap_granularity = q->limits.discard_granularity / block_size;
  741. attrib->unmap_granularity_alignment = q->limits.discard_alignment /
  742. block_size;
  743. attrib->unmap_zeroes_data = (q->limits.max_write_zeroes_sectors);
  744. return true;
  745. }
  746. EXPORT_SYMBOL(target_configure_unmap_from_queue);
  747. /*
  748. * Convert from blocksize advertised to the initiator to the 512 byte
  749. * units unconditionally used by the Linux block layer.
  750. */
  751. sector_t target_to_linux_sector(struct se_device *dev, sector_t lb)
  752. {
  753. switch (dev->dev_attrib.block_size) {
  754. case 4096:
  755. return lb << 3;
  756. case 2048:
  757. return lb << 2;
  758. case 1024:
  759. return lb << 1;
  760. default:
  761. return lb;
  762. }
  763. }
  764. EXPORT_SYMBOL(target_to_linux_sector);
  765. int target_configure_device(struct se_device *dev)
  766. {
  767. struct se_hba *hba = dev->se_hba;
  768. int ret;
  769. if (dev->dev_flags & DF_CONFIGURED) {
  770. pr_err("se_dev->se_dev_ptr already set for storage"
  771. " object\n");
  772. return -EEXIST;
  773. }
  774. ret = dev->transport->configure_device(dev);
  775. if (ret)
  776. goto out;
  777. /*
  778. * XXX: there is not much point to have two different values here..
  779. */
  780. dev->dev_attrib.block_size = dev->dev_attrib.hw_block_size;
  781. dev->dev_attrib.queue_depth = dev->dev_attrib.hw_queue_depth;
  782. /*
  783. * Align max_hw_sectors down to PAGE_SIZE I/O transfers
  784. */
  785. dev->dev_attrib.hw_max_sectors =
  786. se_dev_align_max_sectors(dev->dev_attrib.hw_max_sectors,
  787. dev->dev_attrib.hw_block_size);
  788. dev->dev_attrib.optimal_sectors = dev->dev_attrib.hw_max_sectors;
  789. dev->dev_index = scsi_get_new_index(SCSI_DEVICE_INDEX);
  790. dev->creation_time = get_jiffies_64();
  791. ret = core_setup_alua(dev);
  792. if (ret)
  793. goto out;
  794. /*
  795. * Startup the struct se_device processing thread
  796. */
  797. dev->tmr_wq = alloc_workqueue("tmr-%s", WQ_MEM_RECLAIM | WQ_UNBOUND, 1,
  798. dev->transport->name);
  799. if (!dev->tmr_wq) {
  800. pr_err("Unable to create tmr workqueue for %s\n",
  801. dev->transport->name);
  802. ret = -ENOMEM;
  803. goto out_free_alua;
  804. }
  805. /*
  806. * Setup work_queue for QUEUE_FULL
  807. */
  808. INIT_WORK(&dev->qf_work_queue, target_qf_do_work);
  809. /*
  810. * Preload the initial INQUIRY const values if we are doing
  811. * anything virtual (IBLOCK, FILEIO, RAMDISK), but not for TCM/pSCSI
  812. * passthrough because this is being provided by the backend LLD.
  813. */
  814. if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)) {
  815. strncpy(&dev->t10_wwn.vendor[0], "LIO-ORG", 8);
  816. strncpy(&dev->t10_wwn.model[0],
  817. dev->transport->inquiry_prod, 16);
  818. strncpy(&dev->t10_wwn.revision[0],
  819. dev->transport->inquiry_rev, 4);
  820. }
  821. scsi_dump_inquiry(dev);
  822. spin_lock(&hba->device_lock);
  823. hba->dev_count++;
  824. spin_unlock(&hba->device_lock);
  825. mutex_lock(&g_device_mutex);
  826. list_add_tail(&dev->g_dev_node, &g_device_list);
  827. mutex_unlock(&g_device_mutex);
  828. dev->dev_flags |= DF_CONFIGURED;
  829. return 0;
  830. out_free_alua:
  831. core_alua_free_lu_gp_mem(dev);
  832. out:
  833. se_release_vpd_for_dev(dev);
  834. return ret;
  835. }
  836. void target_free_device(struct se_device *dev)
  837. {
  838. struct se_hba *hba = dev->se_hba;
  839. WARN_ON(!list_empty(&dev->dev_sep_list));
  840. if (dev->dev_flags & DF_CONFIGURED) {
  841. destroy_workqueue(dev->tmr_wq);
  842. dev->transport->destroy_device(dev);
  843. mutex_lock(&g_device_mutex);
  844. list_del(&dev->g_dev_node);
  845. mutex_unlock(&g_device_mutex);
  846. spin_lock(&hba->device_lock);
  847. hba->dev_count--;
  848. spin_unlock(&hba->device_lock);
  849. }
  850. core_alua_free_lu_gp_mem(dev);
  851. core_alua_set_lba_map(dev, NULL, 0, 0);
  852. core_scsi3_free_all_registrations(dev);
  853. se_release_vpd_for_dev(dev);
  854. if (dev->transport->free_prot)
  855. dev->transport->free_prot(dev);
  856. dev->transport->free_device(dev);
  857. }
  858. int core_dev_setup_virtual_lun0(void)
  859. {
  860. struct se_hba *hba;
  861. struct se_device *dev;
  862. char buf[] = "rd_pages=8,rd_nullio=1";
  863. int ret;
  864. hba = core_alloc_hba("rd_mcp", 0, HBA_FLAGS_INTERNAL_USE);
  865. if (IS_ERR(hba))
  866. return PTR_ERR(hba);
  867. dev = target_alloc_device(hba, "virt_lun0");
  868. if (!dev) {
  869. ret = -ENOMEM;
  870. goto out_free_hba;
  871. }
  872. hba->backend->ops->set_configfs_dev_params(dev, buf, sizeof(buf));
  873. ret = target_configure_device(dev);
  874. if (ret)
  875. goto out_free_se_dev;
  876. lun0_hba = hba;
  877. g_lun0_dev = dev;
  878. return 0;
  879. out_free_se_dev:
  880. target_free_device(dev);
  881. out_free_hba:
  882. core_delete_hba(hba);
  883. return ret;
  884. }
  885. void core_dev_release_virtual_lun0(void)
  886. {
  887. struct se_hba *hba = lun0_hba;
  888. if (!hba)
  889. return;
  890. if (g_lun0_dev)
  891. target_free_device(g_lun0_dev);
  892. core_delete_hba(hba);
  893. }
  894. /*
  895. * Common CDB parsing for kernel and user passthrough.
  896. */
  897. sense_reason_t
  898. passthrough_parse_cdb(struct se_cmd *cmd,
  899. sense_reason_t (*exec_cmd)(struct se_cmd *cmd))
  900. {
  901. unsigned char *cdb = cmd->t_task_cdb;
  902. struct se_device *dev = cmd->se_dev;
  903. unsigned int size;
  904. /*
  905. * Clear a lun set in the cdb if the initiator talking to use spoke
  906. * and old standards version, as we can't assume the underlying device
  907. * won't choke up on it.
  908. */
  909. switch (cdb[0]) {
  910. case READ_10: /* SBC - RDProtect */
  911. case READ_12: /* SBC - RDProtect */
  912. case READ_16: /* SBC - RDProtect */
  913. case SEND_DIAGNOSTIC: /* SPC - SELF-TEST Code */
  914. case VERIFY: /* SBC - VRProtect */
  915. case VERIFY_16: /* SBC - VRProtect */
  916. case WRITE_VERIFY: /* SBC - VRProtect */
  917. case WRITE_VERIFY_12: /* SBC - VRProtect */
  918. case MAINTENANCE_IN: /* SPC - Parameter Data Format for SA RTPG */
  919. break;
  920. default:
  921. cdb[1] &= 0x1f; /* clear logical unit number */
  922. break;
  923. }
  924. /*
  925. * For REPORT LUNS we always need to emulate the response, for everything
  926. * else, pass it up.
  927. */
  928. if (cdb[0] == REPORT_LUNS) {
  929. cmd->execute_cmd = spc_emulate_report_luns;
  930. return TCM_NO_SENSE;
  931. }
  932. /*
  933. * For PERSISTENT RESERVE IN/OUT, RELEASE, and RESERVE we need to
  934. * emulate the response, since tcmu does not have the information
  935. * required to process these commands.
  936. */
  937. if (!(dev->transport->transport_flags &
  938. TRANSPORT_FLAG_PASSTHROUGH_PGR)) {
  939. if (cdb[0] == PERSISTENT_RESERVE_IN) {
  940. cmd->execute_cmd = target_scsi3_emulate_pr_in;
  941. size = get_unaligned_be16(&cdb[7]);
  942. return target_cmd_size_check(cmd, size);
  943. }
  944. if (cdb[0] == PERSISTENT_RESERVE_OUT) {
  945. cmd->execute_cmd = target_scsi3_emulate_pr_out;
  946. size = get_unaligned_be16(&cdb[7]);
  947. return target_cmd_size_check(cmd, size);
  948. }
  949. if (cdb[0] == RELEASE || cdb[0] == RELEASE_10) {
  950. cmd->execute_cmd = target_scsi2_reservation_release;
  951. if (cdb[0] == RELEASE_10)
  952. size = get_unaligned_be16(&cdb[7]);
  953. else
  954. size = cmd->data_length;
  955. return target_cmd_size_check(cmd, size);
  956. }
  957. if (cdb[0] == RESERVE || cdb[0] == RESERVE_10) {
  958. cmd->execute_cmd = target_scsi2_reservation_reserve;
  959. if (cdb[0] == RESERVE_10)
  960. size = get_unaligned_be16(&cdb[7]);
  961. else
  962. size = cmd->data_length;
  963. return target_cmd_size_check(cmd, size);
  964. }
  965. }
  966. /* Set DATA_CDB flag for ops that should have it */
  967. switch (cdb[0]) {
  968. case READ_6:
  969. case READ_10:
  970. case READ_12:
  971. case READ_16:
  972. case WRITE_6:
  973. case WRITE_10:
  974. case WRITE_12:
  975. case WRITE_16:
  976. case WRITE_VERIFY:
  977. case WRITE_VERIFY_12:
  978. case WRITE_VERIFY_16:
  979. case COMPARE_AND_WRITE:
  980. case XDWRITEREAD_10:
  981. cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
  982. break;
  983. case VARIABLE_LENGTH_CMD:
  984. switch (get_unaligned_be16(&cdb[8])) {
  985. case READ_32:
  986. case WRITE_32:
  987. case 0x0c: /* WRITE_VERIFY_32 */
  988. case XDWRITEREAD_32:
  989. cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB;
  990. break;
  991. }
  992. }
  993. cmd->execute_cmd = exec_cmd;
  994. return TCM_NO_SENSE;
  995. }
  996. EXPORT_SYMBOL(passthrough_parse_cdb);