scsi_tgt_lib.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. /*
  2. * SCSI target lib functions
  3. *
  4. * Copyright (C) 2005 Mike Christie <michaelc@cs.wisc.edu>
  5. * Copyright (C) 2005 FUJITA Tomonori <tomof@acm.org>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of the
  10. * License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20. * 02110-1301 USA
  21. */
  22. #include <linux/blkdev.h>
  23. #include <linux/hash.h>
  24. #include <linux/module.h>
  25. #include <linux/pagemap.h>
  26. #include <scsi/scsi.h>
  27. #include <scsi/scsi_cmnd.h>
  28. #include <scsi/scsi_device.h>
  29. #include <scsi/scsi_host.h>
  30. #include <scsi/scsi_transport.h>
  31. #include <scsi/scsi_tgt.h>
  32. #include "scsi_tgt_priv.h"
  33. static struct workqueue_struct *scsi_tgtd;
  34. static struct kmem_cache *scsi_tgt_cmd_cache;
  35. /*
  36. * TODO: this struct will be killed when the block layer supports large bios
  37. * and James's work struct code is in
  38. */
  39. struct scsi_tgt_cmd {
  40. /* TODO replace work with James b's code */
  41. struct work_struct work;
  42. /* TODO fix limits of some drivers */
  43. struct bio *bio;
  44. struct list_head hash_list;
  45. struct request *rq;
  46. u64 itn_id;
  47. u64 tag;
  48. };
  49. #define TGT_HASH_ORDER 4
  50. #define cmd_hashfn(tag) hash_long((unsigned long) (tag), TGT_HASH_ORDER)
  51. struct scsi_tgt_queuedata {
  52. struct Scsi_Host *shost;
  53. struct list_head cmd_hash[1 << TGT_HASH_ORDER];
  54. spinlock_t cmd_hash_lock;
  55. };
  56. /*
  57. * Function: scsi_host_get_command()
  58. *
  59. * Purpose: Allocate and setup a scsi command block and blk request
  60. *
  61. * Arguments: shost - scsi host
  62. * data_dir - dma data dir
  63. * gfp_mask- allocator flags
  64. *
  65. * Returns: The allocated scsi command structure.
  66. *
  67. * This should be called by target LLDs to get a command.
  68. */
  69. struct scsi_cmnd *scsi_host_get_command(struct Scsi_Host *shost,
  70. enum dma_data_direction data_dir,
  71. gfp_t gfp_mask)
  72. {
  73. int write = (data_dir == DMA_TO_DEVICE);
  74. struct request *rq;
  75. struct scsi_cmnd *cmd;
  76. struct scsi_tgt_cmd *tcmd;
  77. /* Bail if we can't get a reference to the device */
  78. if (!get_device(&shost->shost_gendev))
  79. return NULL;
  80. tcmd = kmem_cache_alloc(scsi_tgt_cmd_cache, GFP_ATOMIC);
  81. if (!tcmd)
  82. goto put_dev;
  83. /*
  84. * The blk helpers are used to the READ/WRITE requests
  85. * transfering data from a initiator point of view. Since
  86. * we are in target mode we want the opposite.
  87. */
  88. rq = blk_get_request(shost->uspace_req_q, !write, gfp_mask);
  89. if (!rq)
  90. goto free_tcmd;
  91. cmd = __scsi_get_command(shost, gfp_mask);
  92. if (!cmd)
  93. goto release_rq;
  94. cmd->sc_data_direction = data_dir;
  95. cmd->jiffies_at_alloc = jiffies;
  96. cmd->request = rq;
  97. rq->special = cmd;
  98. rq->cmd_type = REQ_TYPE_SPECIAL;
  99. rq->cmd_flags |= REQ_TYPE_BLOCK_PC;
  100. rq->end_io_data = tcmd;
  101. tcmd->rq = rq;
  102. return cmd;
  103. release_rq:
  104. blk_put_request(rq);
  105. free_tcmd:
  106. kmem_cache_free(scsi_tgt_cmd_cache, tcmd);
  107. put_dev:
  108. put_device(&shost->shost_gendev);
  109. return NULL;
  110. }
  111. EXPORT_SYMBOL_GPL(scsi_host_get_command);
  112. /*
  113. * Function: scsi_host_put_command()
  114. *
  115. * Purpose: Free a scsi command block
  116. *
  117. * Arguments: shost - scsi host
  118. * cmd - command block to free
  119. *
  120. * Returns: Nothing.
  121. *
  122. * Notes: The command must not belong to any lists.
  123. */
  124. void scsi_host_put_command(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
  125. {
  126. struct request_queue *q = shost->uspace_req_q;
  127. struct request *rq = cmd->request;
  128. struct scsi_tgt_cmd *tcmd = rq->end_io_data;
  129. unsigned long flags;
  130. kmem_cache_free(scsi_tgt_cmd_cache, tcmd);
  131. spin_lock_irqsave(q->queue_lock, flags);
  132. __blk_put_request(q, rq);
  133. spin_unlock_irqrestore(q->queue_lock, flags);
  134. __scsi_put_command(shost, cmd, &shost->shost_gendev);
  135. }
  136. EXPORT_SYMBOL_GPL(scsi_host_put_command);
  137. static void cmd_hashlist_del(struct scsi_cmnd *cmd)
  138. {
  139. struct request_queue *q = cmd->request->q;
  140. struct scsi_tgt_queuedata *qdata = q->queuedata;
  141. unsigned long flags;
  142. struct scsi_tgt_cmd *tcmd = cmd->request->end_io_data;
  143. spin_lock_irqsave(&qdata->cmd_hash_lock, flags);
  144. list_del(&tcmd->hash_list);
  145. spin_unlock_irqrestore(&qdata->cmd_hash_lock, flags);
  146. }
  147. static void scsi_unmap_user_pages(struct scsi_tgt_cmd *tcmd)
  148. {
  149. blk_rq_unmap_user(tcmd->bio);
  150. }
  151. static void scsi_tgt_cmd_destroy(struct work_struct *work)
  152. {
  153. struct scsi_tgt_cmd *tcmd =
  154. container_of(work, struct scsi_tgt_cmd, work);
  155. struct scsi_cmnd *cmd = tcmd->rq->special;
  156. dprintk("cmd %p %d %u\n", cmd, cmd->sc_data_direction,
  157. rq_data_dir(cmd->request));
  158. scsi_unmap_user_pages(tcmd);
  159. scsi_host_put_command(scsi_tgt_cmd_to_host(cmd), cmd);
  160. }
  161. static void init_scsi_tgt_cmd(struct request *rq, struct scsi_tgt_cmd *tcmd,
  162. u64 itn_id, u64 tag)
  163. {
  164. struct scsi_tgt_queuedata *qdata = rq->q->queuedata;
  165. unsigned long flags;
  166. struct list_head *head;
  167. tcmd->itn_id = itn_id;
  168. tcmd->tag = tag;
  169. tcmd->bio = NULL;
  170. INIT_WORK(&tcmd->work, scsi_tgt_cmd_destroy);
  171. spin_lock_irqsave(&qdata->cmd_hash_lock, flags);
  172. head = &qdata->cmd_hash[cmd_hashfn(tag)];
  173. list_add(&tcmd->hash_list, head);
  174. spin_unlock_irqrestore(&qdata->cmd_hash_lock, flags);
  175. }
  176. /*
  177. * scsi_tgt_alloc_queue - setup queue used for message passing
  178. * shost: scsi host
  179. *
  180. * This should be called by the LLD after host allocation.
  181. * And will be released when the host is released.
  182. */
  183. int scsi_tgt_alloc_queue(struct Scsi_Host *shost)
  184. {
  185. struct scsi_tgt_queuedata *queuedata;
  186. struct request_queue *q;
  187. int err, i;
  188. /*
  189. * Do we need to send a netlink event or should uspace
  190. * just respond to the hotplug event?
  191. */
  192. q = __scsi_alloc_queue(shost, NULL);
  193. if (!q)
  194. return -ENOMEM;
  195. queuedata = kzalloc(sizeof(*queuedata), GFP_KERNEL);
  196. if (!queuedata) {
  197. err = -ENOMEM;
  198. goto cleanup_queue;
  199. }
  200. queuedata->shost = shost;
  201. q->queuedata = queuedata;
  202. /*
  203. * this is a silly hack. We should probably just queue as many
  204. * command as is recvd to userspace. uspace can then make
  205. * sure we do not overload the HBA
  206. */
  207. q->nr_requests = shost->can_queue;
  208. /*
  209. * We currently only support software LLDs so this does
  210. * not matter for now. Do we need this for the cards we support?
  211. * If so we should make it a host template value.
  212. */
  213. blk_queue_dma_alignment(q, 0);
  214. shost->uspace_req_q = q;
  215. for (i = 0; i < ARRAY_SIZE(queuedata->cmd_hash); i++)
  216. INIT_LIST_HEAD(&queuedata->cmd_hash[i]);
  217. spin_lock_init(&queuedata->cmd_hash_lock);
  218. return 0;
  219. cleanup_queue:
  220. blk_cleanup_queue(q);
  221. return err;
  222. }
  223. EXPORT_SYMBOL_GPL(scsi_tgt_alloc_queue);
  224. void scsi_tgt_free_queue(struct Scsi_Host *shost)
  225. {
  226. int i;
  227. unsigned long flags;
  228. struct request_queue *q = shost->uspace_req_q;
  229. struct scsi_cmnd *cmd;
  230. struct scsi_tgt_queuedata *qdata = q->queuedata;
  231. struct scsi_tgt_cmd *tcmd, *n;
  232. LIST_HEAD(cmds);
  233. spin_lock_irqsave(&qdata->cmd_hash_lock, flags);
  234. for (i = 0; i < ARRAY_SIZE(qdata->cmd_hash); i++) {
  235. list_for_each_entry_safe(tcmd, n, &qdata->cmd_hash[i],
  236. hash_list) {
  237. list_del(&tcmd->hash_list);
  238. list_add(&tcmd->hash_list, &cmds);
  239. }
  240. }
  241. spin_unlock_irqrestore(&qdata->cmd_hash_lock, flags);
  242. while (!list_empty(&cmds)) {
  243. tcmd = list_entry(cmds.next, struct scsi_tgt_cmd, hash_list);
  244. list_del(&tcmd->hash_list);
  245. cmd = tcmd->rq->special;
  246. shost->hostt->eh_abort_handler(cmd);
  247. scsi_tgt_cmd_destroy(&tcmd->work);
  248. }
  249. }
  250. EXPORT_SYMBOL_GPL(scsi_tgt_free_queue);
  251. struct Scsi_Host *scsi_tgt_cmd_to_host(struct scsi_cmnd *cmd)
  252. {
  253. struct scsi_tgt_queuedata *queue = cmd->request->q->queuedata;
  254. return queue->shost;
  255. }
  256. EXPORT_SYMBOL_GPL(scsi_tgt_cmd_to_host);
  257. /*
  258. * scsi_tgt_queue_command - queue command for userspace processing
  259. * @cmd: scsi command
  260. * @scsilun: scsi lun
  261. * @tag: unique value to identify this command for tmf
  262. */
  263. int scsi_tgt_queue_command(struct scsi_cmnd *cmd, u64 itn_id,
  264. struct scsi_lun *scsilun, u64 tag)
  265. {
  266. struct scsi_tgt_cmd *tcmd = cmd->request->end_io_data;
  267. int err;
  268. init_scsi_tgt_cmd(cmd->request, tcmd, itn_id, tag);
  269. err = scsi_tgt_uspace_send_cmd(cmd, itn_id, scsilun, tag);
  270. if (err)
  271. cmd_hashlist_del(cmd);
  272. return err;
  273. }
  274. EXPORT_SYMBOL_GPL(scsi_tgt_queue_command);
  275. /*
  276. * This is run from a interrupt handler normally and the unmap
  277. * needs process context so we must queue
  278. */
  279. static void scsi_tgt_cmd_done(struct scsi_cmnd *cmd)
  280. {
  281. struct scsi_tgt_cmd *tcmd = cmd->request->end_io_data;
  282. dprintk("cmd %p %u\n", cmd, rq_data_dir(cmd->request));
  283. scsi_tgt_uspace_send_status(cmd, tcmd->itn_id, tcmd->tag);
  284. scsi_release_buffers(cmd);
  285. queue_work(scsi_tgtd, &tcmd->work);
  286. }
  287. static int scsi_tgt_transfer_response(struct scsi_cmnd *cmd)
  288. {
  289. struct Scsi_Host *shost = scsi_tgt_cmd_to_host(cmd);
  290. int err;
  291. dprintk("cmd %p %u\n", cmd, rq_data_dir(cmd->request));
  292. err = shost->hostt->transfer_response(cmd, scsi_tgt_cmd_done);
  293. switch (err) {
  294. case SCSI_MLQUEUE_HOST_BUSY:
  295. case SCSI_MLQUEUE_DEVICE_BUSY:
  296. return -EAGAIN;
  297. }
  298. return 0;
  299. }
  300. /* TODO: test this crap and replace bio_map_user with new interface maybe */
  301. static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
  302. unsigned long uaddr, unsigned int len, int rw)
  303. {
  304. struct request_queue *q = cmd->request->q;
  305. struct request *rq = cmd->request;
  306. int err;
  307. dprintk("%lx %u\n", uaddr, len);
  308. err = blk_rq_map_user(q, rq, (void *)uaddr, len);
  309. if (err) {
  310. /*
  311. * TODO: need to fixup sg_tablesize, max_segment_size,
  312. * max_sectors, etc for modern HW and software drivers
  313. * where this value is bogus.
  314. *
  315. * TODO2: we can alloc a reserve buffer of max size
  316. * we can handle and do the slow copy path for really large
  317. * IO.
  318. */
  319. eprintk("Could not handle request of size %u.\n", len);
  320. return err;
  321. }
  322. tcmd->bio = rq->bio;
  323. err = scsi_init_io(cmd, GFP_KERNEL);
  324. if (err) {
  325. scsi_release_buffers(cmd);
  326. goto unmap_rq;
  327. }
  328. return 0;
  329. unmap_rq:
  330. scsi_unmap_user_pages(tcmd);
  331. return err;
  332. }
  333. static int scsi_tgt_copy_sense(struct scsi_cmnd *cmd, unsigned long uaddr,
  334. unsigned len)
  335. {
  336. char __user *p = (char __user *) uaddr;
  337. if (copy_from_user(cmd->sense_buffer, p,
  338. min_t(unsigned, SCSI_SENSE_BUFFERSIZE, len))) {
  339. printk(KERN_ERR "Could not copy the sense buffer\n");
  340. return -EIO;
  341. }
  342. return 0;
  343. }
  344. static int scsi_tgt_abort_cmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd)
  345. {
  346. struct scsi_tgt_cmd *tcmd;
  347. int err;
  348. err = shost->hostt->eh_abort_handler(cmd);
  349. if (err)
  350. eprintk("fail to abort %p\n", cmd);
  351. tcmd = cmd->request->end_io_data;
  352. scsi_tgt_cmd_destroy(&tcmd->work);
  353. return err;
  354. }
  355. static struct request *tgt_cmd_hash_lookup(struct request_queue *q, u64 tag)
  356. {
  357. struct scsi_tgt_queuedata *qdata = q->queuedata;
  358. struct request *rq = NULL;
  359. struct list_head *head;
  360. struct scsi_tgt_cmd *tcmd;
  361. unsigned long flags;
  362. head = &qdata->cmd_hash[cmd_hashfn(tag)];
  363. spin_lock_irqsave(&qdata->cmd_hash_lock, flags);
  364. list_for_each_entry(tcmd, head, hash_list) {
  365. if (tcmd->tag == tag) {
  366. rq = tcmd->rq;
  367. list_del(&tcmd->hash_list);
  368. break;
  369. }
  370. }
  371. spin_unlock_irqrestore(&qdata->cmd_hash_lock, flags);
  372. return rq;
  373. }
  374. int scsi_tgt_kspace_exec(int host_no, u64 itn_id, int result, u64 tag,
  375. unsigned long uaddr, u32 len, unsigned long sense_uaddr,
  376. u32 sense_len, u8 rw)
  377. {
  378. struct Scsi_Host *shost;
  379. struct scsi_cmnd *cmd;
  380. struct request *rq;
  381. struct scsi_tgt_cmd *tcmd;
  382. int err = 0;
  383. dprintk("%d %llu %d %u %lx %u\n", host_no, (unsigned long long) tag,
  384. result, len, uaddr, rw);
  385. /* TODO: replace with a O(1) alg */
  386. shost = scsi_host_lookup(host_no);
  387. if (IS_ERR(shost)) {
  388. printk(KERN_ERR "Could not find host no %d\n", host_no);
  389. return -EINVAL;
  390. }
  391. if (!shost->uspace_req_q) {
  392. printk(KERN_ERR "Not target scsi host %d\n", host_no);
  393. goto done;
  394. }
  395. rq = tgt_cmd_hash_lookup(shost->uspace_req_q, tag);
  396. if (!rq) {
  397. printk(KERN_ERR "Could not find tag %llu\n",
  398. (unsigned long long) tag);
  399. err = -EINVAL;
  400. goto done;
  401. }
  402. cmd = rq->special;
  403. dprintk("cmd %p scb %x result %d len %d bufflen %u %u %x\n",
  404. cmd, cmd->cmnd[0], result, len, scsi_bufflen(cmd),
  405. rq_data_dir(rq), cmd->cmnd[0]);
  406. if (result == TASK_ABORTED) {
  407. scsi_tgt_abort_cmd(shost, cmd);
  408. goto done;
  409. }
  410. /*
  411. * store the userspace values here, the working values are
  412. * in the request_* values
  413. */
  414. tcmd = cmd->request->end_io_data;
  415. cmd->result = result;
  416. if (cmd->result == SAM_STAT_CHECK_CONDITION)
  417. scsi_tgt_copy_sense(cmd, sense_uaddr, sense_len);
  418. if (len) {
  419. err = scsi_map_user_pages(rq->end_io_data, cmd, uaddr, len, rw);
  420. if (err) {
  421. /*
  422. * user-space daemon bugs or OOM
  423. * TODO: we can do better for OOM.
  424. */
  425. struct scsi_tgt_queuedata *qdata;
  426. struct list_head *head;
  427. unsigned long flags;
  428. eprintk("cmd %p ret %d uaddr %lx len %d rw %d\n",
  429. cmd, err, uaddr, len, rw);
  430. qdata = shost->uspace_req_q->queuedata;
  431. head = &qdata->cmd_hash[cmd_hashfn(tcmd->tag)];
  432. spin_lock_irqsave(&qdata->cmd_hash_lock, flags);
  433. list_add(&tcmd->hash_list, head);
  434. spin_unlock_irqrestore(&qdata->cmd_hash_lock, flags);
  435. goto done;
  436. }
  437. }
  438. err = scsi_tgt_transfer_response(cmd);
  439. done:
  440. scsi_host_put(shost);
  441. return err;
  442. }
  443. int scsi_tgt_tsk_mgmt_request(struct Scsi_Host *shost, u64 itn_id,
  444. int function, u64 tag, struct scsi_lun *scsilun,
  445. void *data)
  446. {
  447. int err;
  448. /* TODO: need to retry if this fails. */
  449. err = scsi_tgt_uspace_send_tsk_mgmt(shost->host_no, itn_id,
  450. function, tag, scsilun, data);
  451. if (err < 0)
  452. eprintk("The task management request lost!\n");
  453. return err;
  454. }
  455. EXPORT_SYMBOL_GPL(scsi_tgt_tsk_mgmt_request);
  456. int scsi_tgt_kspace_tsk_mgmt(int host_no, u64 itn_id, u64 mid, int result)
  457. {
  458. struct Scsi_Host *shost;
  459. int err = -EINVAL;
  460. dprintk("%d %d %llx\n", host_no, result, (unsigned long long) mid);
  461. shost = scsi_host_lookup(host_no);
  462. if (IS_ERR(shost)) {
  463. printk(KERN_ERR "Could not find host no %d\n", host_no);
  464. return err;
  465. }
  466. if (!shost->uspace_req_q) {
  467. printk(KERN_ERR "Not target scsi host %d\n", host_no);
  468. goto done;
  469. }
  470. err = shost->transportt->tsk_mgmt_response(shost, itn_id, mid, result);
  471. done:
  472. scsi_host_put(shost);
  473. return err;
  474. }
  475. int scsi_tgt_it_nexus_create(struct Scsi_Host *shost, u64 itn_id,
  476. char *initiator)
  477. {
  478. int err;
  479. /* TODO: need to retry if this fails. */
  480. err = scsi_tgt_uspace_send_it_nexus_request(shost->host_no, itn_id, 0,
  481. initiator);
  482. if (err < 0)
  483. eprintk("The i_t_neuxs request lost, %d %llx!\n",
  484. shost->host_no, (unsigned long long)itn_id);
  485. return err;
  486. }
  487. EXPORT_SYMBOL_GPL(scsi_tgt_it_nexus_create);
  488. int scsi_tgt_it_nexus_destroy(struct Scsi_Host *shost, u64 itn_id)
  489. {
  490. int err;
  491. /* TODO: need to retry if this fails. */
  492. err = scsi_tgt_uspace_send_it_nexus_request(shost->host_no,
  493. itn_id, 1, NULL);
  494. if (err < 0)
  495. eprintk("The i_t_neuxs request lost, %d %llx!\n",
  496. shost->host_no, (unsigned long long)itn_id);
  497. return err;
  498. }
  499. EXPORT_SYMBOL_GPL(scsi_tgt_it_nexus_destroy);
  500. int scsi_tgt_kspace_it_nexus_rsp(int host_no, u64 itn_id, int result)
  501. {
  502. struct Scsi_Host *shost;
  503. int err = -EINVAL;
  504. dprintk("%d %d%llx\n", host_no, result, (unsigned long long)itn_id);
  505. shost = scsi_host_lookup(host_no);
  506. if (IS_ERR(shost)) {
  507. printk(KERN_ERR "Could not find host no %d\n", host_no);
  508. return err;
  509. }
  510. if (!shost->uspace_req_q) {
  511. printk(KERN_ERR "Not target scsi host %d\n", host_no);
  512. goto done;
  513. }
  514. err = shost->transportt->it_nexus_response(shost, itn_id, result);
  515. done:
  516. scsi_host_put(shost);
  517. return err;
  518. }
  519. static int __init scsi_tgt_init(void)
  520. {
  521. int err;
  522. scsi_tgt_cmd_cache = kmem_cache_create("scsi_tgt_cmd",
  523. sizeof(struct scsi_tgt_cmd),
  524. 0, 0, NULL);
  525. if (!scsi_tgt_cmd_cache)
  526. return -ENOMEM;
  527. scsi_tgtd = create_workqueue("scsi_tgtd");
  528. if (!scsi_tgtd) {
  529. err = -ENOMEM;
  530. goto free_kmemcache;
  531. }
  532. err = scsi_tgt_if_init();
  533. if (err)
  534. goto destroy_wq;
  535. return 0;
  536. destroy_wq:
  537. destroy_workqueue(scsi_tgtd);
  538. free_kmemcache:
  539. kmem_cache_destroy(scsi_tgt_cmd_cache);
  540. return err;
  541. }
  542. static void __exit scsi_tgt_exit(void)
  543. {
  544. destroy_workqueue(scsi_tgtd);
  545. scsi_tgt_if_exit();
  546. kmem_cache_destroy(scsi_tgt_cmd_cache);
  547. }
  548. module_init(scsi_tgt_init);
  549. module_exit(scsi_tgt_exit);
  550. MODULE_DESCRIPTION("SCSI target core");
  551. MODULE_LICENSE("GPL");