virtio_blk.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. //#define DEBUG
  2. #include <linux/spinlock.h>
  3. #include <linux/slab.h>
  4. #include <linux/blkdev.h>
  5. #include <linux/hdreg.h>
  6. #include <linux/module.h>
  7. #include <linux/mutex.h>
  8. #include <linux/virtio.h>
  9. #include <linux/virtio_blk.h>
  10. #include <linux/scatterlist.h>
  11. #include <linux/string_helpers.h>
  12. #include <scsi/scsi_cmnd.h>
  13. #include <linux/idr.h>
  14. #define PART_BITS 4
  15. static int major;
  16. static DEFINE_IDA(vd_index_ida);
  17. struct workqueue_struct *virtblk_wq;
  18. struct virtio_blk
  19. {
  20. spinlock_t lock;
  21. struct virtio_device *vdev;
  22. struct virtqueue *vq;
  23. /* The disk structure for the kernel. */
  24. struct gendisk *disk;
  25. /* Request tracking. */
  26. struct list_head reqs;
  27. mempool_t *pool;
  28. /* Process context for config space updates */
  29. struct work_struct config_work;
  30. /* Lock for config space updates */
  31. struct mutex config_lock;
  32. /* enable config space updates */
  33. bool config_enable;
  34. /* What host tells us, plus 2 for header & tailer. */
  35. unsigned int sg_elems;
  36. /* Ida index - used to track minor number allocations. */
  37. int index;
  38. /* Scatterlist: can be too big for stack. */
  39. struct scatterlist sg[/*sg_elems*/];
  40. };
  41. struct virtblk_req
  42. {
  43. struct list_head list;
  44. struct request *req;
  45. struct virtio_blk_outhdr out_hdr;
  46. struct virtio_scsi_inhdr in_hdr;
  47. u8 status;
  48. };
  49. static void blk_done(struct virtqueue *vq)
  50. {
  51. struct virtio_blk *vblk = vq->vdev->priv;
  52. struct virtblk_req *vbr;
  53. unsigned int len;
  54. unsigned long flags;
  55. spin_lock_irqsave(&vblk->lock, flags);
  56. while ((vbr = virtqueue_get_buf(vblk->vq, &len)) != NULL) {
  57. int error;
  58. switch (vbr->status) {
  59. case VIRTIO_BLK_S_OK:
  60. error = 0;
  61. break;
  62. case VIRTIO_BLK_S_UNSUPP:
  63. error = -ENOTTY;
  64. break;
  65. default:
  66. error = -EIO;
  67. break;
  68. }
  69. switch (vbr->req->cmd_type) {
  70. case REQ_TYPE_BLOCK_PC:
  71. vbr->req->resid_len = vbr->in_hdr.residual;
  72. vbr->req->sense_len = vbr->in_hdr.sense_len;
  73. vbr->req->errors = vbr->in_hdr.errors;
  74. break;
  75. case REQ_TYPE_SPECIAL:
  76. vbr->req->errors = (error != 0);
  77. break;
  78. default:
  79. break;
  80. }
  81. __blk_end_request_all(vbr->req, error);
  82. list_del(&vbr->list);
  83. mempool_free(vbr, vblk->pool);
  84. }
  85. /* In case queue is stopped waiting for more buffers. */
  86. blk_start_queue(vblk->disk->queue);
  87. spin_unlock_irqrestore(&vblk->lock, flags);
  88. }
  89. static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
  90. struct request *req)
  91. {
  92. unsigned long num, out = 0, in = 0;
  93. struct virtblk_req *vbr;
  94. vbr = mempool_alloc(vblk->pool, GFP_ATOMIC);
  95. if (!vbr)
  96. /* When another request finishes we'll try again. */
  97. return false;
  98. vbr->req = req;
  99. if (req->cmd_flags & REQ_FLUSH) {
  100. vbr->out_hdr.type = VIRTIO_BLK_T_FLUSH;
  101. vbr->out_hdr.sector = 0;
  102. vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
  103. } else {
  104. switch (req->cmd_type) {
  105. case REQ_TYPE_FS:
  106. vbr->out_hdr.type = 0;
  107. vbr->out_hdr.sector = blk_rq_pos(vbr->req);
  108. vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
  109. break;
  110. case REQ_TYPE_BLOCK_PC:
  111. vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD;
  112. vbr->out_hdr.sector = 0;
  113. vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
  114. break;
  115. case REQ_TYPE_SPECIAL:
  116. vbr->out_hdr.type = VIRTIO_BLK_T_GET_ID;
  117. vbr->out_hdr.sector = 0;
  118. vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
  119. break;
  120. default:
  121. /* We don't put anything else in the queue. */
  122. BUG();
  123. }
  124. }
  125. sg_set_buf(&vblk->sg[out++], &vbr->out_hdr, sizeof(vbr->out_hdr));
  126. /*
  127. * If this is a packet command we need a couple of additional headers.
  128. * Behind the normal outhdr we put a segment with the scsi command
  129. * block, and before the normal inhdr we put the sense data and the
  130. * inhdr with additional status information before the normal inhdr.
  131. */
  132. if (vbr->req->cmd_type == REQ_TYPE_BLOCK_PC)
  133. sg_set_buf(&vblk->sg[out++], vbr->req->cmd, vbr->req->cmd_len);
  134. num = blk_rq_map_sg(q, vbr->req, vblk->sg + out);
  135. if (vbr->req->cmd_type == REQ_TYPE_BLOCK_PC) {
  136. sg_set_buf(&vblk->sg[num + out + in++], vbr->req->sense, SCSI_SENSE_BUFFERSIZE);
  137. sg_set_buf(&vblk->sg[num + out + in++], &vbr->in_hdr,
  138. sizeof(vbr->in_hdr));
  139. }
  140. sg_set_buf(&vblk->sg[num + out + in++], &vbr->status,
  141. sizeof(vbr->status));
  142. if (num) {
  143. if (rq_data_dir(vbr->req) == WRITE) {
  144. vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
  145. out += num;
  146. } else {
  147. vbr->out_hdr.type |= VIRTIO_BLK_T_IN;
  148. in += num;
  149. }
  150. }
  151. if (virtqueue_add_buf(vblk->vq, vblk->sg, out, in, vbr, GFP_ATOMIC)<0) {
  152. mempool_free(vbr, vblk->pool);
  153. return false;
  154. }
  155. list_add_tail(&vbr->list, &vblk->reqs);
  156. return true;
  157. }
  158. static void do_virtblk_request(struct request_queue *q)
  159. {
  160. struct virtio_blk *vblk = q->queuedata;
  161. struct request *req;
  162. unsigned int issued = 0;
  163. while ((req = blk_peek_request(q)) != NULL) {
  164. BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
  165. /* If this request fails, stop queue and wait for something to
  166. finish to restart it. */
  167. if (!do_req(q, vblk, req)) {
  168. blk_stop_queue(q);
  169. break;
  170. }
  171. blk_start_request(req);
  172. issued++;
  173. }
  174. if (issued)
  175. virtqueue_kick(vblk->vq);
  176. }
  177. /* return id (s/n) string for *disk to *id_str
  178. */
  179. static int virtblk_get_id(struct gendisk *disk, char *id_str)
  180. {
  181. struct virtio_blk *vblk = disk->private_data;
  182. struct request *req;
  183. struct bio *bio;
  184. int err;
  185. bio = bio_map_kern(vblk->disk->queue, id_str, VIRTIO_BLK_ID_BYTES,
  186. GFP_KERNEL);
  187. if (IS_ERR(bio))
  188. return PTR_ERR(bio);
  189. req = blk_make_request(vblk->disk->queue, bio, GFP_KERNEL);
  190. if (IS_ERR(req)) {
  191. bio_put(bio);
  192. return PTR_ERR(req);
  193. }
  194. req->cmd_type = REQ_TYPE_SPECIAL;
  195. err = blk_execute_rq(vblk->disk->queue, vblk->disk, req, false);
  196. blk_put_request(req);
  197. return err;
  198. }
  199. static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
  200. unsigned int cmd, unsigned long data)
  201. {
  202. struct gendisk *disk = bdev->bd_disk;
  203. struct virtio_blk *vblk = disk->private_data;
  204. /*
  205. * Only allow the generic SCSI ioctls if the host can support it.
  206. */
  207. if (!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_SCSI))
  208. return -ENOTTY;
  209. return scsi_cmd_ioctl(disk->queue, disk, mode, cmd,
  210. (void __user *)data);
  211. }
  212. /* We provide getgeo only to please some old bootloader/partitioning tools */
  213. static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
  214. {
  215. struct virtio_blk *vblk = bd->bd_disk->private_data;
  216. struct virtio_blk_geometry vgeo;
  217. int err;
  218. /* see if the host passed in geometry config */
  219. err = virtio_config_val(vblk->vdev, VIRTIO_BLK_F_GEOMETRY,
  220. offsetof(struct virtio_blk_config, geometry),
  221. &vgeo);
  222. if (!err) {
  223. geo->heads = vgeo.heads;
  224. geo->sectors = vgeo.sectors;
  225. geo->cylinders = vgeo.cylinders;
  226. } else {
  227. /* some standard values, similar to sd */
  228. geo->heads = 1 << 6;
  229. geo->sectors = 1 << 5;
  230. geo->cylinders = get_capacity(bd->bd_disk) >> 11;
  231. }
  232. return 0;
  233. }
  234. static const struct block_device_operations virtblk_fops = {
  235. .ioctl = virtblk_ioctl,
  236. .owner = THIS_MODULE,
  237. .getgeo = virtblk_getgeo,
  238. };
  239. static int index_to_minor(int index)
  240. {
  241. return index << PART_BITS;
  242. }
  243. static int minor_to_index(int minor)
  244. {
  245. return minor >> PART_BITS;
  246. }
  247. static ssize_t virtblk_serial_show(struct device *dev,
  248. struct device_attribute *attr, char *buf)
  249. {
  250. struct gendisk *disk = dev_to_disk(dev);
  251. int err;
  252. /* sysfs gives us a PAGE_SIZE buffer */
  253. BUILD_BUG_ON(PAGE_SIZE < VIRTIO_BLK_ID_BYTES);
  254. buf[VIRTIO_BLK_ID_BYTES] = '\0';
  255. err = virtblk_get_id(disk, buf);
  256. if (!err)
  257. return strlen(buf);
  258. if (err == -EIO) /* Unsupported? Make it empty. */
  259. return 0;
  260. return err;
  261. }
  262. DEVICE_ATTR(serial, S_IRUGO, virtblk_serial_show, NULL);
  263. static void virtblk_config_changed_work(struct work_struct *work)
  264. {
  265. struct virtio_blk *vblk =
  266. container_of(work, struct virtio_blk, config_work);
  267. struct virtio_device *vdev = vblk->vdev;
  268. struct request_queue *q = vblk->disk->queue;
  269. char cap_str_2[10], cap_str_10[10];
  270. u64 capacity, size;
  271. mutex_lock(&vblk->config_lock);
  272. if (!vblk->config_enable)
  273. goto done;
  274. /* Host must always specify the capacity. */
  275. vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity),
  276. &capacity, sizeof(capacity));
  277. /* If capacity is too big, truncate with warning. */
  278. if ((sector_t)capacity != capacity) {
  279. dev_warn(&vdev->dev, "Capacity %llu too large: truncating\n",
  280. (unsigned long long)capacity);
  281. capacity = (sector_t)-1;
  282. }
  283. size = capacity * queue_logical_block_size(q);
  284. string_get_size(size, STRING_UNITS_2, cap_str_2, sizeof(cap_str_2));
  285. string_get_size(size, STRING_UNITS_10, cap_str_10, sizeof(cap_str_10));
  286. dev_notice(&vdev->dev,
  287. "new size: %llu %d-byte logical blocks (%s/%s)\n",
  288. (unsigned long long)capacity,
  289. queue_logical_block_size(q),
  290. cap_str_10, cap_str_2);
  291. set_capacity(vblk->disk, capacity);
  292. done:
  293. mutex_unlock(&vblk->config_lock);
  294. }
  295. static void virtblk_config_changed(struct virtio_device *vdev)
  296. {
  297. struct virtio_blk *vblk = vdev->priv;
  298. queue_work(virtblk_wq, &vblk->config_work);
  299. }
  300. static int __devinit virtblk_probe(struct virtio_device *vdev)
  301. {
  302. struct virtio_blk *vblk;
  303. struct request_queue *q;
  304. int err, index;
  305. u64 cap;
  306. u32 v, blk_size, sg_elems, opt_io_size;
  307. u16 min_io_size;
  308. u8 physical_block_exp, alignment_offset;
  309. err = ida_simple_get(&vd_index_ida, 0, minor_to_index(1 << MINORBITS),
  310. GFP_KERNEL);
  311. if (err < 0)
  312. goto out;
  313. index = err;
  314. /* We need to know how many segments before we allocate. */
  315. err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX,
  316. offsetof(struct virtio_blk_config, seg_max),
  317. &sg_elems);
  318. /* We need at least one SG element, whatever they say. */
  319. if (err || !sg_elems)
  320. sg_elems = 1;
  321. /* We need an extra sg elements at head and tail. */
  322. sg_elems += 2;
  323. vdev->priv = vblk = kmalloc(sizeof(*vblk) +
  324. sizeof(vblk->sg[0]) * sg_elems, GFP_KERNEL);
  325. if (!vblk) {
  326. err = -ENOMEM;
  327. goto out_free_index;
  328. }
  329. INIT_LIST_HEAD(&vblk->reqs);
  330. spin_lock_init(&vblk->lock);
  331. vblk->vdev = vdev;
  332. vblk->sg_elems = sg_elems;
  333. sg_init_table(vblk->sg, vblk->sg_elems);
  334. mutex_init(&vblk->config_lock);
  335. INIT_WORK(&vblk->config_work, virtblk_config_changed_work);
  336. vblk->config_enable = true;
  337. /* We expect one virtqueue, for output. */
  338. vblk->vq = virtio_find_single_vq(vdev, blk_done, "requests");
  339. if (IS_ERR(vblk->vq)) {
  340. err = PTR_ERR(vblk->vq);
  341. goto out_free_vblk;
  342. }
  343. vblk->pool = mempool_create_kmalloc_pool(1,sizeof(struct virtblk_req));
  344. if (!vblk->pool) {
  345. err = -ENOMEM;
  346. goto out_free_vq;
  347. }
  348. /* FIXME: How many partitions? How long is a piece of string? */
  349. vblk->disk = alloc_disk(1 << PART_BITS);
  350. if (!vblk->disk) {
  351. err = -ENOMEM;
  352. goto out_mempool;
  353. }
  354. q = vblk->disk->queue = blk_init_queue(do_virtblk_request, &vblk->lock);
  355. if (!q) {
  356. err = -ENOMEM;
  357. goto out_put_disk;
  358. }
  359. q->queuedata = vblk;
  360. if (index < 26) {
  361. sprintf(vblk->disk->disk_name, "vd%c", 'a' + index % 26);
  362. } else if (index < (26 + 1) * 26) {
  363. sprintf(vblk->disk->disk_name, "vd%c%c",
  364. 'a' + index / 26 - 1, 'a' + index % 26);
  365. } else {
  366. const unsigned int m1 = (index / 26 - 1) / 26 - 1;
  367. const unsigned int m2 = (index / 26 - 1) % 26;
  368. const unsigned int m3 = index % 26;
  369. sprintf(vblk->disk->disk_name, "vd%c%c%c",
  370. 'a' + m1, 'a' + m2, 'a' + m3);
  371. }
  372. vblk->disk->major = major;
  373. vblk->disk->first_minor = index_to_minor(index);
  374. vblk->disk->private_data = vblk;
  375. vblk->disk->fops = &virtblk_fops;
  376. vblk->disk->driverfs_dev = &vdev->dev;
  377. vblk->index = index;
  378. /* configure queue flush support */
  379. if (virtio_has_feature(vdev, VIRTIO_BLK_F_FLUSH))
  380. blk_queue_flush(q, REQ_FLUSH);
  381. /* If disk is read-only in the host, the guest should obey */
  382. if (virtio_has_feature(vdev, VIRTIO_BLK_F_RO))
  383. set_disk_ro(vblk->disk, 1);
  384. /* Host must always specify the capacity. */
  385. vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity),
  386. &cap, sizeof(cap));
  387. /* If capacity is too big, truncate with warning. */
  388. if ((sector_t)cap != cap) {
  389. dev_warn(&vdev->dev, "Capacity %llu too large: truncating\n",
  390. (unsigned long long)cap);
  391. cap = (sector_t)-1;
  392. }
  393. set_capacity(vblk->disk, cap);
  394. /* We can handle whatever the host told us to handle. */
  395. blk_queue_max_segments(q, vblk->sg_elems-2);
  396. /* No need to bounce any requests */
  397. blk_queue_bounce_limit(q, BLK_BOUNCE_ANY);
  398. /* No real sector limit. */
  399. blk_queue_max_hw_sectors(q, -1U);
  400. /* Host can optionally specify maximum segment size and number of
  401. * segments. */
  402. err = virtio_config_val(vdev, VIRTIO_BLK_F_SIZE_MAX,
  403. offsetof(struct virtio_blk_config, size_max),
  404. &v);
  405. if (!err)
  406. blk_queue_max_segment_size(q, v);
  407. else
  408. blk_queue_max_segment_size(q, -1U);
  409. /* Host can optionally specify the block size of the device */
  410. err = virtio_config_val(vdev, VIRTIO_BLK_F_BLK_SIZE,
  411. offsetof(struct virtio_blk_config, blk_size),
  412. &blk_size);
  413. if (!err)
  414. blk_queue_logical_block_size(q, blk_size);
  415. else
  416. blk_size = queue_logical_block_size(q);
  417. /* Use topology information if available */
  418. err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
  419. offsetof(struct virtio_blk_config, physical_block_exp),
  420. &physical_block_exp);
  421. if (!err && physical_block_exp)
  422. blk_queue_physical_block_size(q,
  423. blk_size * (1 << physical_block_exp));
  424. err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
  425. offsetof(struct virtio_blk_config, alignment_offset),
  426. &alignment_offset);
  427. if (!err && alignment_offset)
  428. blk_queue_alignment_offset(q, blk_size * alignment_offset);
  429. err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
  430. offsetof(struct virtio_blk_config, min_io_size),
  431. &min_io_size);
  432. if (!err && min_io_size)
  433. blk_queue_io_min(q, blk_size * min_io_size);
  434. err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
  435. offsetof(struct virtio_blk_config, opt_io_size),
  436. &opt_io_size);
  437. if (!err && opt_io_size)
  438. blk_queue_io_opt(q, blk_size * opt_io_size);
  439. add_disk(vblk->disk);
  440. err = device_create_file(disk_to_dev(vblk->disk), &dev_attr_serial);
  441. if (err)
  442. goto out_del_disk;
  443. return 0;
  444. out_del_disk:
  445. del_gendisk(vblk->disk);
  446. blk_cleanup_queue(vblk->disk->queue);
  447. out_put_disk:
  448. put_disk(vblk->disk);
  449. out_mempool:
  450. mempool_destroy(vblk->pool);
  451. out_free_vq:
  452. vdev->config->del_vqs(vdev);
  453. out_free_vblk:
  454. kfree(vblk);
  455. out_free_index:
  456. ida_simple_remove(&vd_index_ida, index);
  457. out:
  458. return err;
  459. }
  460. static void __devexit virtblk_remove(struct virtio_device *vdev)
  461. {
  462. struct virtio_blk *vblk = vdev->priv;
  463. int index = vblk->index;
  464. /* Prevent config work handler from accessing the device. */
  465. mutex_lock(&vblk->config_lock);
  466. vblk->config_enable = false;
  467. mutex_unlock(&vblk->config_lock);
  468. /* Nothing should be pending. */
  469. BUG_ON(!list_empty(&vblk->reqs));
  470. /* Stop all the virtqueues. */
  471. vdev->config->reset(vdev);
  472. flush_work(&vblk->config_work);
  473. del_gendisk(vblk->disk);
  474. blk_cleanup_queue(vblk->disk->queue);
  475. put_disk(vblk->disk);
  476. mempool_destroy(vblk->pool);
  477. vdev->config->del_vqs(vdev);
  478. kfree(vblk);
  479. ida_simple_remove(&vd_index_ida, index);
  480. }
  481. static const struct virtio_device_id id_table[] = {
  482. { VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID },
  483. { 0 },
  484. };
  485. static unsigned int features[] = {
  486. VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_GEOMETRY,
  487. VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE, VIRTIO_BLK_F_SCSI,
  488. VIRTIO_BLK_F_FLUSH, VIRTIO_BLK_F_TOPOLOGY
  489. };
  490. /*
  491. * virtio_blk causes spurious section mismatch warning by
  492. * simultaneously referring to a __devinit and a __devexit function.
  493. * Use __refdata to avoid this warning.
  494. */
  495. static struct virtio_driver __refdata virtio_blk = {
  496. .feature_table = features,
  497. .feature_table_size = ARRAY_SIZE(features),
  498. .driver.name = KBUILD_MODNAME,
  499. .driver.owner = THIS_MODULE,
  500. .id_table = id_table,
  501. .probe = virtblk_probe,
  502. .remove = __devexit_p(virtblk_remove),
  503. .config_changed = virtblk_config_changed,
  504. };
  505. static int __init init(void)
  506. {
  507. int error;
  508. virtblk_wq = alloc_workqueue("virtio-blk", 0, 0);
  509. if (!virtblk_wq)
  510. return -ENOMEM;
  511. major = register_blkdev(0, "virtblk");
  512. if (major < 0) {
  513. error = major;
  514. goto out_destroy_workqueue;
  515. }
  516. error = register_virtio_driver(&virtio_blk);
  517. if (error)
  518. goto out_unregister_blkdev;
  519. return 0;
  520. out_unregister_blkdev:
  521. unregister_blkdev(major, "virtblk");
  522. out_destroy_workqueue:
  523. destroy_workqueue(virtblk_wq);
  524. return error;
  525. }
  526. static void __exit fini(void)
  527. {
  528. unregister_blkdev(major, "virtblk");
  529. unregister_virtio_driver(&virtio_blk);
  530. destroy_workqueue(virtblk_wq);
  531. }
  532. module_init(init);
  533. module_exit(fini);
  534. MODULE_DEVICE_TABLE(virtio, id_table);
  535. MODULE_DESCRIPTION("Virtio block driver");
  536. MODULE_LICENSE("GPL");