target_core_iblock.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*******************************************************************************
  2. * Filename: target_core_iblock.c
  3. *
  4. * This file contains the Storage Engine <-> Linux BlockIO transport
  5. * specific functions.
  6. *
  7. * Copyright (c) 2003, 2004, 2005 PyX Technologies, Inc.
  8. * Copyright (c) 2005, 2006, 2007 SBE, Inc.
  9. * Copyright (c) 2007-2010 Rising Tide Systems
  10. * Copyright (c) 2008-2010 Linux-iSCSI.org
  11. *
  12. * Nicholas A. Bellinger <nab@kernel.org>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27. *
  28. ******************************************************************************/
  29. #include <linux/string.h>
  30. #include <linux/parser.h>
  31. #include <linux/timer.h>
  32. #include <linux/fs.h>
  33. #include <linux/blkdev.h>
  34. #include <linux/slab.h>
  35. #include <linux/spinlock.h>
  36. #include <linux/bio.h>
  37. #include <linux/genhd.h>
  38. #include <linux/file.h>
  39. #include <linux/module.h>
  40. #include <scsi/scsi.h>
  41. #include <scsi/scsi_host.h>
  42. #include <target/target_core_base.h>
  43. #include <target/target_core_backend.h>
  44. #include "target_core_iblock.h"
  45. static struct se_subsystem_api iblock_template;
  46. static void iblock_bio_done(struct bio *, int);
  47. /* iblock_attach_hba(): (Part of se_subsystem_api_t template)
  48. *
  49. *
  50. */
  51. static int iblock_attach_hba(struct se_hba *hba, u32 host_id)
  52. {
  53. pr_debug("CORE_HBA[%d] - TCM iBlock HBA Driver %s on"
  54. " Generic Target Core Stack %s\n", hba->hba_id,
  55. IBLOCK_VERSION, TARGET_CORE_MOD_VERSION);
  56. return 0;
  57. }
  58. static void iblock_detach_hba(struct se_hba *hba)
  59. {
  60. }
  61. static void *iblock_allocate_virtdevice(struct se_hba *hba, const char *name)
  62. {
  63. struct iblock_dev *ib_dev = NULL;
  64. ib_dev = kzalloc(sizeof(struct iblock_dev), GFP_KERNEL);
  65. if (!ib_dev) {
  66. pr_err("Unable to allocate struct iblock_dev\n");
  67. return NULL;
  68. }
  69. pr_debug( "IBLOCK: Allocated ib_dev for %s\n", name);
  70. return ib_dev;
  71. }
  72. static struct se_device *iblock_create_virtdevice(
  73. struct se_hba *hba,
  74. struct se_subsystem_dev *se_dev,
  75. void *p)
  76. {
  77. struct iblock_dev *ib_dev = p;
  78. struct se_device *dev;
  79. struct se_dev_limits dev_limits;
  80. struct block_device *bd = NULL;
  81. struct request_queue *q;
  82. struct queue_limits *limits;
  83. u32 dev_flags = 0;
  84. int ret = -EINVAL;
  85. if (!ib_dev) {
  86. pr_err("Unable to locate struct iblock_dev parameter\n");
  87. return ERR_PTR(ret);
  88. }
  89. memset(&dev_limits, 0, sizeof(struct se_dev_limits));
  90. /*
  91. * These settings need to be made tunable..
  92. */
  93. ib_dev->ibd_bio_set = bioset_create(32, 0);
  94. if (!ib_dev->ibd_bio_set) {
  95. pr_err("IBLOCK: Unable to create bioset()\n");
  96. return ERR_PTR(-ENOMEM);
  97. }
  98. pr_debug("IBLOCK: Created bio_set()\n");
  99. /*
  100. * iblock_check_configfs_dev_params() ensures that ib_dev->ibd_udev_path
  101. * must already have been set in order for echo 1 > $HBA/$DEV/enable to run.
  102. */
  103. pr_debug( "IBLOCK: Claiming struct block_device: %s\n",
  104. ib_dev->ibd_udev_path);
  105. bd = blkdev_get_by_path(ib_dev->ibd_udev_path,
  106. FMODE_WRITE|FMODE_READ|FMODE_EXCL, ib_dev);
  107. if (IS_ERR(bd)) {
  108. ret = PTR_ERR(bd);
  109. goto failed;
  110. }
  111. /*
  112. * Setup the local scope queue_limits from struct request_queue->limits
  113. * to pass into transport_add_device_to_core_hba() as struct se_dev_limits.
  114. */
  115. q = bdev_get_queue(bd);
  116. limits = &dev_limits.limits;
  117. limits->logical_block_size = bdev_logical_block_size(bd);
  118. limits->max_hw_sectors = queue_max_hw_sectors(q);
  119. limits->max_sectors = queue_max_sectors(q);
  120. dev_limits.hw_queue_depth = q->nr_requests;
  121. dev_limits.queue_depth = q->nr_requests;
  122. ib_dev->ibd_bd = bd;
  123. dev = transport_add_device_to_core_hba(hba,
  124. &iblock_template, se_dev, dev_flags, ib_dev,
  125. &dev_limits, "IBLOCK", IBLOCK_VERSION);
  126. if (!dev)
  127. goto failed;
  128. /*
  129. * Check if the underlying struct block_device request_queue supports
  130. * the QUEUE_FLAG_DISCARD bit for UNMAP/WRITE_SAME in SCSI + TRIM
  131. * in ATA and we need to set TPE=1
  132. */
  133. if (blk_queue_discard(q)) {
  134. dev->se_sub_dev->se_dev_attrib.max_unmap_lba_count =
  135. q->limits.max_discard_sectors;
  136. /*
  137. * Currently hardcoded to 1 in Linux/SCSI code..
  138. */
  139. dev->se_sub_dev->se_dev_attrib.max_unmap_block_desc_count = 1;
  140. dev->se_sub_dev->se_dev_attrib.unmap_granularity =
  141. q->limits.discard_granularity >> 9;
  142. dev->se_sub_dev->se_dev_attrib.unmap_granularity_alignment =
  143. q->limits.discard_alignment;
  144. pr_debug("IBLOCK: BLOCK Discard support available,"
  145. " disabled by default\n");
  146. }
  147. if (blk_queue_nonrot(q))
  148. dev->se_sub_dev->se_dev_attrib.is_nonrot = 1;
  149. return dev;
  150. failed:
  151. if (ib_dev->ibd_bio_set) {
  152. bioset_free(ib_dev->ibd_bio_set);
  153. ib_dev->ibd_bio_set = NULL;
  154. }
  155. ib_dev->ibd_bd = NULL;
  156. return ERR_PTR(ret);
  157. }
  158. static void iblock_free_device(void *p)
  159. {
  160. struct iblock_dev *ib_dev = p;
  161. if (ib_dev->ibd_bd != NULL)
  162. blkdev_put(ib_dev->ibd_bd, FMODE_WRITE|FMODE_READ|FMODE_EXCL);
  163. if (ib_dev->ibd_bio_set != NULL)
  164. bioset_free(ib_dev->ibd_bio_set);
  165. kfree(ib_dev);
  166. }
  167. static inline struct iblock_req *IBLOCK_REQ(struct se_task *task)
  168. {
  169. return container_of(task, struct iblock_req, ib_task);
  170. }
  171. static struct se_task *
  172. iblock_alloc_task(unsigned char *cdb)
  173. {
  174. struct iblock_req *ib_req;
  175. ib_req = kzalloc(sizeof(struct iblock_req), GFP_KERNEL);
  176. if (!ib_req) {
  177. pr_err("Unable to allocate memory for struct iblock_req\n");
  178. return NULL;
  179. }
  180. atomic_set(&ib_req->ib_bio_cnt, 0);
  181. return &ib_req->ib_task;
  182. }
  183. static unsigned long long iblock_emulate_read_cap_with_block_size(
  184. struct se_device *dev,
  185. struct block_device *bd,
  186. struct request_queue *q)
  187. {
  188. unsigned long long blocks_long = (div_u64(i_size_read(bd->bd_inode),
  189. bdev_logical_block_size(bd)) - 1);
  190. u32 block_size = bdev_logical_block_size(bd);
  191. if (block_size == dev->se_sub_dev->se_dev_attrib.block_size)
  192. return blocks_long;
  193. switch (block_size) {
  194. case 4096:
  195. switch (dev->se_sub_dev->se_dev_attrib.block_size) {
  196. case 2048:
  197. blocks_long <<= 1;
  198. break;
  199. case 1024:
  200. blocks_long <<= 2;
  201. break;
  202. case 512:
  203. blocks_long <<= 3;
  204. default:
  205. break;
  206. }
  207. break;
  208. case 2048:
  209. switch (dev->se_sub_dev->se_dev_attrib.block_size) {
  210. case 4096:
  211. blocks_long >>= 1;
  212. break;
  213. case 1024:
  214. blocks_long <<= 1;
  215. break;
  216. case 512:
  217. blocks_long <<= 2;
  218. break;
  219. default:
  220. break;
  221. }
  222. break;
  223. case 1024:
  224. switch (dev->se_sub_dev->se_dev_attrib.block_size) {
  225. case 4096:
  226. blocks_long >>= 2;
  227. break;
  228. case 2048:
  229. blocks_long >>= 1;
  230. break;
  231. case 512:
  232. blocks_long <<= 1;
  233. break;
  234. default:
  235. break;
  236. }
  237. break;
  238. case 512:
  239. switch (dev->se_sub_dev->se_dev_attrib.block_size) {
  240. case 4096:
  241. blocks_long >>= 3;
  242. break;
  243. case 2048:
  244. blocks_long >>= 2;
  245. break;
  246. case 1024:
  247. blocks_long >>= 1;
  248. break;
  249. default:
  250. break;
  251. }
  252. break;
  253. default:
  254. break;
  255. }
  256. return blocks_long;
  257. }
  258. static void iblock_end_io_flush(struct bio *bio, int err)
  259. {
  260. struct se_cmd *cmd = bio->bi_private;
  261. if (err)
  262. pr_err("IBLOCK: cache flush failed: %d\n", err);
  263. if (cmd)
  264. transport_complete_sync_cache(cmd, err == 0);
  265. bio_put(bio);
  266. }
  267. /*
  268. * Implement SYCHRONIZE CACHE. Note that we can't handle lba ranges and must
  269. * always flush the whole cache.
  270. */
  271. static void iblock_emulate_sync_cache(struct se_task *task)
  272. {
  273. struct se_cmd *cmd = task->task_se_cmd;
  274. struct iblock_dev *ib_dev = cmd->se_dev->dev_ptr;
  275. int immed = (cmd->t_task_cdb[1] & 0x2);
  276. struct bio *bio;
  277. /*
  278. * If the Immediate bit is set, queue up the GOOD response
  279. * for this SYNCHRONIZE_CACHE op.
  280. */
  281. if (immed)
  282. transport_complete_sync_cache(cmd, 1);
  283. bio = bio_alloc(GFP_KERNEL, 0);
  284. bio->bi_end_io = iblock_end_io_flush;
  285. bio->bi_bdev = ib_dev->ibd_bd;
  286. if (!immed)
  287. bio->bi_private = cmd;
  288. submit_bio(WRITE_FLUSH, bio);
  289. }
  290. static int iblock_do_discard(struct se_device *dev, sector_t lba, u32 range)
  291. {
  292. struct iblock_dev *ibd = dev->dev_ptr;
  293. struct block_device *bd = ibd->ibd_bd;
  294. int barrier = 0;
  295. return blkdev_issue_discard(bd, lba, range, GFP_KERNEL, barrier);
  296. }
  297. static void iblock_free_task(struct se_task *task)
  298. {
  299. kfree(IBLOCK_REQ(task));
  300. }
  301. enum {
  302. Opt_udev_path, Opt_force, Opt_err
  303. };
  304. static match_table_t tokens = {
  305. {Opt_udev_path, "udev_path=%s"},
  306. {Opt_force, "force=%d"},
  307. {Opt_err, NULL}
  308. };
  309. static ssize_t iblock_set_configfs_dev_params(struct se_hba *hba,
  310. struct se_subsystem_dev *se_dev,
  311. const char *page, ssize_t count)
  312. {
  313. struct iblock_dev *ib_dev = se_dev->se_dev_su_ptr;
  314. char *orig, *ptr, *arg_p, *opts;
  315. substring_t args[MAX_OPT_ARGS];
  316. int ret = 0, token;
  317. opts = kstrdup(page, GFP_KERNEL);
  318. if (!opts)
  319. return -ENOMEM;
  320. orig = opts;
  321. while ((ptr = strsep(&opts, ",\n")) != NULL) {
  322. if (!*ptr)
  323. continue;
  324. token = match_token(ptr, tokens, args);
  325. switch (token) {
  326. case Opt_udev_path:
  327. if (ib_dev->ibd_bd) {
  328. pr_err("Unable to set udev_path= while"
  329. " ib_dev->ibd_bd exists\n");
  330. ret = -EEXIST;
  331. goto out;
  332. }
  333. arg_p = match_strdup(&args[0]);
  334. if (!arg_p) {
  335. ret = -ENOMEM;
  336. break;
  337. }
  338. snprintf(ib_dev->ibd_udev_path, SE_UDEV_PATH_LEN,
  339. "%s", arg_p);
  340. kfree(arg_p);
  341. pr_debug("IBLOCK: Referencing UDEV path: %s\n",
  342. ib_dev->ibd_udev_path);
  343. ib_dev->ibd_flags |= IBDF_HAS_UDEV_PATH;
  344. break;
  345. case Opt_force:
  346. break;
  347. default:
  348. break;
  349. }
  350. }
  351. out:
  352. kfree(orig);
  353. return (!ret) ? count : ret;
  354. }
  355. static ssize_t iblock_check_configfs_dev_params(
  356. struct se_hba *hba,
  357. struct se_subsystem_dev *se_dev)
  358. {
  359. struct iblock_dev *ibd = se_dev->se_dev_su_ptr;
  360. if (!(ibd->ibd_flags & IBDF_HAS_UDEV_PATH)) {
  361. pr_err("Missing udev_path= parameters for IBLOCK\n");
  362. return -EINVAL;
  363. }
  364. return 0;
  365. }
  366. static ssize_t iblock_show_configfs_dev_params(
  367. struct se_hba *hba,
  368. struct se_subsystem_dev *se_dev,
  369. char *b)
  370. {
  371. struct iblock_dev *ibd = se_dev->se_dev_su_ptr;
  372. struct block_device *bd = ibd->ibd_bd;
  373. char buf[BDEVNAME_SIZE];
  374. ssize_t bl = 0;
  375. if (bd)
  376. bl += sprintf(b + bl, "iBlock device: %s",
  377. bdevname(bd, buf));
  378. if (ibd->ibd_flags & IBDF_HAS_UDEV_PATH) {
  379. bl += sprintf(b + bl, " UDEV PATH: %s\n",
  380. ibd->ibd_udev_path);
  381. } else
  382. bl += sprintf(b + bl, "\n");
  383. bl += sprintf(b + bl, " ");
  384. if (bd) {
  385. bl += sprintf(b + bl, "Major: %d Minor: %d %s\n",
  386. MAJOR(bd->bd_dev), MINOR(bd->bd_dev), (!bd->bd_contains) ?
  387. "" : (bd->bd_holder == ibd) ?
  388. "CLAIMED: IBLOCK" : "CLAIMED: OS");
  389. } else {
  390. bl += sprintf(b + bl, "Major: 0 Minor: 0\n");
  391. }
  392. return bl;
  393. }
  394. static void iblock_bio_destructor(struct bio *bio)
  395. {
  396. struct se_task *task = bio->bi_private;
  397. struct iblock_dev *ib_dev = task->task_se_cmd->se_dev->dev_ptr;
  398. bio_free(bio, ib_dev->ibd_bio_set);
  399. }
  400. static struct bio *
  401. iblock_get_bio(struct se_task *task, sector_t lba, u32 sg_num)
  402. {
  403. struct iblock_dev *ib_dev = task->task_se_cmd->se_dev->dev_ptr;
  404. struct iblock_req *ib_req = IBLOCK_REQ(task);
  405. struct bio *bio;
  406. /*
  407. * Only allocate as many vector entries as the bio code allows us to,
  408. * we'll loop later on until we have handled the whole request.
  409. */
  410. if (sg_num > BIO_MAX_PAGES)
  411. sg_num = BIO_MAX_PAGES;
  412. bio = bio_alloc_bioset(GFP_NOIO, sg_num, ib_dev->ibd_bio_set);
  413. if (!bio) {
  414. pr_err("Unable to allocate memory for bio\n");
  415. return NULL;
  416. }
  417. pr_debug("Allocated bio: %p task_sg_nents: %u using ibd_bio_set:"
  418. " %p\n", bio, task->task_sg_nents, ib_dev->ibd_bio_set);
  419. pr_debug("Allocated bio: %p task_size: %u\n", bio, task->task_size);
  420. bio->bi_bdev = ib_dev->ibd_bd;
  421. bio->bi_private = task;
  422. bio->bi_destructor = iblock_bio_destructor;
  423. bio->bi_end_io = &iblock_bio_done;
  424. bio->bi_sector = lba;
  425. atomic_inc(&ib_req->ib_bio_cnt);
  426. pr_debug("Set bio->bi_sector: %llu\n", (unsigned long long)bio->bi_sector);
  427. pr_debug("Set ib_req->ib_bio_cnt: %d\n",
  428. atomic_read(&ib_req->ib_bio_cnt));
  429. return bio;
  430. }
  431. static int iblock_do_task(struct se_task *task)
  432. {
  433. struct se_cmd *cmd = task->task_se_cmd;
  434. struct se_device *dev = cmd->se_dev;
  435. struct bio *bio;
  436. struct bio_list list;
  437. struct scatterlist *sg;
  438. u32 i, sg_num = task->task_sg_nents;
  439. sector_t block_lba;
  440. struct blk_plug plug;
  441. int rw;
  442. if (task->task_data_direction == DMA_TO_DEVICE) {
  443. /*
  444. * Force data to disk if we pretend to not have a volatile
  445. * write cache, or the initiator set the Force Unit Access bit.
  446. */
  447. if (dev->se_sub_dev->se_dev_attrib.emulate_write_cache == 0 ||
  448. (dev->se_sub_dev->se_dev_attrib.emulate_fua_write > 0 &&
  449. (cmd->se_cmd_flags & SCF_FUA)))
  450. rw = WRITE_FUA;
  451. else
  452. rw = WRITE;
  453. } else {
  454. rw = READ;
  455. }
  456. /*
  457. * Do starting conversion up from non 512-byte blocksize with
  458. * struct se_task SCSI blocksize into Linux/Block 512 units for BIO.
  459. */
  460. if (dev->se_sub_dev->se_dev_attrib.block_size == 4096)
  461. block_lba = (task->task_lba << 3);
  462. else if (dev->se_sub_dev->se_dev_attrib.block_size == 2048)
  463. block_lba = (task->task_lba << 2);
  464. else if (dev->se_sub_dev->se_dev_attrib.block_size == 1024)
  465. block_lba = (task->task_lba << 1);
  466. else if (dev->se_sub_dev->se_dev_attrib.block_size == 512)
  467. block_lba = task->task_lba;
  468. else {
  469. pr_err("Unsupported SCSI -> BLOCK LBA conversion:"
  470. " %u\n", dev->se_sub_dev->se_dev_attrib.block_size);
  471. cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  472. return -ENOSYS;
  473. }
  474. bio = iblock_get_bio(task, block_lba, sg_num);
  475. if (!bio) {
  476. cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  477. return -ENOMEM;
  478. }
  479. bio_list_init(&list);
  480. bio_list_add(&list, bio);
  481. for_each_sg(task->task_sg, sg, task->task_sg_nents, i) {
  482. /*
  483. * XXX: if the length the device accepts is shorter than the
  484. * length of the S/G list entry this will cause and
  485. * endless loop. Better hope no driver uses huge pages.
  486. */
  487. while (bio_add_page(bio, sg_page(sg), sg->length, sg->offset)
  488. != sg->length) {
  489. bio = iblock_get_bio(task, block_lba, sg_num);
  490. if (!bio)
  491. goto fail;
  492. bio_list_add(&list, bio);
  493. }
  494. /* Always in 512 byte units for Linux/Block */
  495. block_lba += sg->length >> IBLOCK_LBA_SHIFT;
  496. sg_num--;
  497. }
  498. blk_start_plug(&plug);
  499. while ((bio = bio_list_pop(&list)))
  500. submit_bio(rw, bio);
  501. blk_finish_plug(&plug);
  502. return 0;
  503. fail:
  504. while ((bio = bio_list_pop(&list)))
  505. bio_put(bio);
  506. cmd->scsi_sense_reason = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
  507. return -ENOMEM;
  508. }
  509. static u32 iblock_get_device_rev(struct se_device *dev)
  510. {
  511. return SCSI_SPC_2; /* Returns SPC-3 in Initiator Data */
  512. }
  513. static u32 iblock_get_device_type(struct se_device *dev)
  514. {
  515. return TYPE_DISK;
  516. }
  517. static sector_t iblock_get_blocks(struct se_device *dev)
  518. {
  519. struct iblock_dev *ibd = dev->dev_ptr;
  520. struct block_device *bd = ibd->ibd_bd;
  521. struct request_queue *q = bdev_get_queue(bd);
  522. return iblock_emulate_read_cap_with_block_size(dev, bd, q);
  523. }
  524. static void iblock_bio_done(struct bio *bio, int err)
  525. {
  526. struct se_task *task = bio->bi_private;
  527. struct iblock_req *ibr = IBLOCK_REQ(task);
  528. /*
  529. * Set -EIO if !BIO_UPTODATE and the passed is still err=0
  530. */
  531. if (!test_bit(BIO_UPTODATE, &bio->bi_flags) && !err)
  532. err = -EIO;
  533. if (err != 0) {
  534. pr_err("test_bit(BIO_UPTODATE) failed for bio: %p,"
  535. " err: %d\n", bio, err);
  536. /*
  537. * Bump the ib_bio_err_cnt and release bio.
  538. */
  539. atomic_inc(&ibr->ib_bio_err_cnt);
  540. smp_mb__after_atomic_inc();
  541. }
  542. bio_put(bio);
  543. if (!atomic_dec_and_test(&ibr->ib_bio_cnt))
  544. return;
  545. pr_debug("done[%p] bio: %p task_lba: %llu bio_lba: %llu err=%d\n",
  546. task, bio, task->task_lba,
  547. (unsigned long long)bio->bi_sector, err);
  548. transport_complete_task(task, !atomic_read(&ibr->ib_bio_err_cnt));
  549. }
  550. static struct se_subsystem_api iblock_template = {
  551. .name = "iblock",
  552. .owner = THIS_MODULE,
  553. .transport_type = TRANSPORT_PLUGIN_VHBA_PDEV,
  554. .write_cache_emulated = 1,
  555. .fua_write_emulated = 1,
  556. .attach_hba = iblock_attach_hba,
  557. .detach_hba = iblock_detach_hba,
  558. .allocate_virtdevice = iblock_allocate_virtdevice,
  559. .create_virtdevice = iblock_create_virtdevice,
  560. .free_device = iblock_free_device,
  561. .alloc_task = iblock_alloc_task,
  562. .do_task = iblock_do_task,
  563. .do_discard = iblock_do_discard,
  564. .do_sync_cache = iblock_emulate_sync_cache,
  565. .free_task = iblock_free_task,
  566. .check_configfs_dev_params = iblock_check_configfs_dev_params,
  567. .set_configfs_dev_params = iblock_set_configfs_dev_params,
  568. .show_configfs_dev_params = iblock_show_configfs_dev_params,
  569. .get_device_rev = iblock_get_device_rev,
  570. .get_device_type = iblock_get_device_type,
  571. .get_blocks = iblock_get_blocks,
  572. };
  573. static int __init iblock_module_init(void)
  574. {
  575. return transport_subsystem_register(&iblock_template);
  576. }
  577. static void iblock_module_exit(void)
  578. {
  579. transport_subsystem_release(&iblock_template);
  580. }
  581. MODULE_DESCRIPTION("TCM IBLOCK subsystem plugin");
  582. MODULE_AUTHOR("nab@Linux-iSCSI.org");
  583. MODULE_LICENSE("GPL");
  584. module_init(iblock_module_init);
  585. module_exit(iblock_module_exit);