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>
18 module_param(use_bio, bool, S_IRUGO);
21 static DEFINE_IDA(vd_index_ida);
23 struct workqueue_struct *virtblk_wq;
27 struct virtio_device *vdev;
29 wait_queue_head_t queue_wait;
31 /* The disk structure for the kernel. */
36 /* Process context for config space updates */
37 struct work_struct config_work;
39 /* Lock for config space updates */
40 struct mutex config_lock;
42 /* enable config space updates */
45 /* What host tells us, plus 2 for header & tailer. */
46 unsigned int sg_elems;
48 /* Ida index - used to track minor number allocations. */
51 /* Scatterlist: can be too big for stack. */
52 struct scatterlist sg[/*sg_elems*/];
59 struct virtio_blk_outhdr out_hdr;
60 struct virtio_scsi_inhdr in_hdr;
62 struct scatterlist sg[];
65 static inline int virtblk_result(struct virtblk_req *vbr)
67 switch (vbr->status) {
70 case VIRTIO_BLK_S_UNSUPP:
77 static inline void virtblk_request_done(struct virtio_blk *vblk,
78 struct virtblk_req *vbr)
80 struct request *req = vbr->req;
81 int error = virtblk_result(vbr);
83 if (req->cmd_type == REQ_TYPE_BLOCK_PC) {
84 req->resid_len = vbr->in_hdr.residual;
85 req->sense_len = vbr->in_hdr.sense_len;
86 req->errors = vbr->in_hdr.errors;
87 } else if (req->cmd_type == REQ_TYPE_SPECIAL) {
88 req->errors = (error != 0);
91 __blk_end_request_all(req, error);
92 mempool_free(vbr, vblk->pool);
95 static inline void virtblk_bio_done(struct virtio_blk *vblk,
96 struct virtblk_req *vbr)
98 bio_endio(vbr->bio, virtblk_result(vbr));
99 mempool_free(vbr, vblk->pool);
102 static void virtblk_done(struct virtqueue *vq)
104 struct virtio_blk *vblk = vq->vdev->priv;
105 unsigned long bio_done = 0, req_done = 0;
106 struct virtblk_req *vbr;
110 spin_lock_irqsave(vblk->disk->queue->queue_lock, flags);
111 while ((vbr = virtqueue_get_buf(vblk->vq, &len)) != NULL) {
113 virtblk_bio_done(vblk, vbr);
116 virtblk_request_done(vblk, vbr);
120 /* In case queue is stopped waiting for more buffers. */
122 blk_start_queue(vblk->disk->queue);
123 spin_unlock_irqrestore(vblk->disk->queue->queue_lock, flags);
126 wake_up(&vblk->queue_wait);
129 static inline struct virtblk_req *virtblk_alloc_req(struct virtio_blk *vblk,
132 struct virtblk_req *vbr;
134 vbr = mempool_alloc(vblk->pool, gfp_mask);
136 sg_init_table(vbr->sg, vblk->sg_elems);
141 static bool do_req(struct request_queue *q, struct virtio_blk *vblk,
144 unsigned long num, out = 0, in = 0;
145 struct virtblk_req *vbr;
147 vbr = virtblk_alloc_req(vblk, GFP_ATOMIC);
149 /* When another request finishes we'll try again. */
154 if (req->cmd_flags & REQ_FLUSH) {
155 vbr->out_hdr.type = VIRTIO_BLK_T_FLUSH;
156 vbr->out_hdr.sector = 0;
157 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
159 switch (req->cmd_type) {
161 vbr->out_hdr.type = 0;
162 vbr->out_hdr.sector = blk_rq_pos(vbr->req);
163 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
165 case REQ_TYPE_BLOCK_PC:
166 vbr->out_hdr.type = VIRTIO_BLK_T_SCSI_CMD;
167 vbr->out_hdr.sector = 0;
168 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
170 case REQ_TYPE_SPECIAL:
171 vbr->out_hdr.type = VIRTIO_BLK_T_GET_ID;
172 vbr->out_hdr.sector = 0;
173 vbr->out_hdr.ioprio = req_get_ioprio(vbr->req);
176 /* We don't put anything else in the queue. */
181 sg_set_buf(&vblk->sg[out++], &vbr->out_hdr, sizeof(vbr->out_hdr));
184 * If this is a packet command we need a couple of additional headers.
185 * Behind the normal outhdr we put a segment with the scsi command
186 * block, and before the normal inhdr we put the sense data and the
187 * inhdr with additional status information before the normal inhdr.
189 if (vbr->req->cmd_type == REQ_TYPE_BLOCK_PC)
190 sg_set_buf(&vblk->sg[out++], vbr->req->cmd, vbr->req->cmd_len);
192 num = blk_rq_map_sg(q, vbr->req, vblk->sg + out);
194 if (vbr->req->cmd_type == REQ_TYPE_BLOCK_PC) {
195 sg_set_buf(&vblk->sg[num + out + in++], vbr->req->sense, SCSI_SENSE_BUFFERSIZE);
196 sg_set_buf(&vblk->sg[num + out + in++], &vbr->in_hdr,
197 sizeof(vbr->in_hdr));
200 sg_set_buf(&vblk->sg[num + out + in++], &vbr->status,
201 sizeof(vbr->status));
204 if (rq_data_dir(vbr->req) == WRITE) {
205 vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
208 vbr->out_hdr.type |= VIRTIO_BLK_T_IN;
213 if (virtqueue_add_buf(vblk->vq, vblk->sg, out, in, vbr,
215 mempool_free(vbr, vblk->pool);
222 static void virtblk_request(struct request_queue *q)
224 struct virtio_blk *vblk = q->queuedata;
226 unsigned int issued = 0;
228 while ((req = blk_peek_request(q)) != NULL) {
229 BUG_ON(req->nr_phys_segments + 2 > vblk->sg_elems);
231 /* If this request fails, stop queue and wait for something to
232 finish to restart it. */
233 if (!do_req(q, vblk, req)) {
237 blk_start_request(req);
242 virtqueue_kick(vblk->vq);
245 static void virtblk_add_buf_wait(struct virtio_blk *vblk,
246 struct virtblk_req *vbr,
253 prepare_to_wait_exclusive(&vblk->queue_wait, &wait,
254 TASK_UNINTERRUPTIBLE);
256 spin_lock_irq(vblk->disk->queue->queue_lock);
257 if (virtqueue_add_buf(vblk->vq, vbr->sg, out, in, vbr,
259 spin_unlock_irq(vblk->disk->queue->queue_lock);
262 virtqueue_kick(vblk->vq);
263 spin_unlock_irq(vblk->disk->queue->queue_lock);
269 finish_wait(&vblk->queue_wait, &wait);
272 static void virtblk_make_request(struct request_queue *q, struct bio *bio)
274 struct virtio_blk *vblk = q->queuedata;
275 unsigned int num, out = 0, in = 0;
276 struct virtblk_req *vbr;
278 BUG_ON(bio->bi_phys_segments + 2 > vblk->sg_elems);
279 BUG_ON(bio->bi_rw & (REQ_FLUSH | REQ_FUA));
281 vbr = virtblk_alloc_req(vblk, GFP_NOIO);
283 bio_endio(bio, -ENOMEM);
289 vbr->out_hdr.type = 0;
290 vbr->out_hdr.sector = bio->bi_sector;
291 vbr->out_hdr.ioprio = bio_prio(bio);
293 sg_set_buf(&vbr->sg[out++], &vbr->out_hdr, sizeof(vbr->out_hdr));
295 num = blk_bio_map_sg(q, bio, vbr->sg + out);
297 sg_set_buf(&vbr->sg[num + out + in++], &vbr->status,
298 sizeof(vbr->status));
301 if (bio->bi_rw & REQ_WRITE) {
302 vbr->out_hdr.type |= VIRTIO_BLK_T_OUT;
305 vbr->out_hdr.type |= VIRTIO_BLK_T_IN;
310 spin_lock_irq(vblk->disk->queue->queue_lock);
311 if (unlikely(virtqueue_add_buf(vblk->vq, vbr->sg, out, in, vbr,
313 spin_unlock_irq(vblk->disk->queue->queue_lock);
314 virtblk_add_buf_wait(vblk, vbr, out, in);
317 virtqueue_kick(vblk->vq);
318 spin_unlock_irq(vblk->disk->queue->queue_lock);
321 /* return id (s/n) string for *disk to *id_str
323 static int virtblk_get_id(struct gendisk *disk, char *id_str)
325 struct virtio_blk *vblk = disk->private_data;
330 bio = bio_map_kern(vblk->disk->queue, id_str, VIRTIO_BLK_ID_BYTES,
335 req = blk_make_request(vblk->disk->queue, bio, GFP_KERNEL);
341 req->cmd_type = REQ_TYPE_SPECIAL;
342 err = blk_execute_rq(vblk->disk->queue, vblk->disk, req, false);
343 blk_put_request(req);
348 static int virtblk_ioctl(struct block_device *bdev, fmode_t mode,
349 unsigned int cmd, unsigned long data)
351 struct gendisk *disk = bdev->bd_disk;
352 struct virtio_blk *vblk = disk->private_data;
355 * Only allow the generic SCSI ioctls if the host can support it.
357 if (!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_SCSI))
360 return scsi_cmd_blk_ioctl(bdev, mode, cmd,
361 (void __user *)data);
364 /* We provide getgeo only to please some old bootloader/partitioning tools */
365 static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo)
367 struct virtio_blk *vblk = bd->bd_disk->private_data;
368 struct virtio_blk_geometry vgeo;
371 /* see if the host passed in geometry config */
372 err = virtio_config_val(vblk->vdev, VIRTIO_BLK_F_GEOMETRY,
373 offsetof(struct virtio_blk_config, geometry),
377 geo->heads = vgeo.heads;
378 geo->sectors = vgeo.sectors;
379 geo->cylinders = vgeo.cylinders;
381 /* some standard values, similar to sd */
383 geo->sectors = 1 << 5;
384 geo->cylinders = get_capacity(bd->bd_disk) >> 11;
389 static const struct block_device_operations virtblk_fops = {
390 .ioctl = virtblk_ioctl,
391 .owner = THIS_MODULE,
392 .getgeo = virtblk_getgeo,
395 static int index_to_minor(int index)
397 return index << PART_BITS;
400 static int minor_to_index(int minor)
402 return minor >> PART_BITS;
405 static ssize_t virtblk_serial_show(struct device *dev,
406 struct device_attribute *attr, char *buf)
408 struct gendisk *disk = dev_to_disk(dev);
411 /* sysfs gives us a PAGE_SIZE buffer */
412 BUILD_BUG_ON(PAGE_SIZE < VIRTIO_BLK_ID_BYTES);
414 buf[VIRTIO_BLK_ID_BYTES] = '\0';
415 err = virtblk_get_id(disk, buf);
419 if (err == -EIO) /* Unsupported? Make it empty. */
424 DEVICE_ATTR(serial, S_IRUGO, virtblk_serial_show, NULL);
426 static void virtblk_config_changed_work(struct work_struct *work)
428 struct virtio_blk *vblk =
429 container_of(work, struct virtio_blk, config_work);
430 struct virtio_device *vdev = vblk->vdev;
431 struct request_queue *q = vblk->disk->queue;
432 char cap_str_2[10], cap_str_10[10];
435 mutex_lock(&vblk->config_lock);
436 if (!vblk->config_enable)
439 /* Host must always specify the capacity. */
440 vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity),
441 &capacity, sizeof(capacity));
443 /* If capacity is too big, truncate with warning. */
444 if ((sector_t)capacity != capacity) {
445 dev_warn(&vdev->dev, "Capacity %llu too large: truncating\n",
446 (unsigned long long)capacity);
447 capacity = (sector_t)-1;
450 size = capacity * queue_logical_block_size(q);
451 string_get_size(size, STRING_UNITS_2, cap_str_2, sizeof(cap_str_2));
452 string_get_size(size, STRING_UNITS_10, cap_str_10, sizeof(cap_str_10));
454 dev_notice(&vdev->dev,
455 "new size: %llu %d-byte logical blocks (%s/%s)\n",
456 (unsigned long long)capacity,
457 queue_logical_block_size(q),
458 cap_str_10, cap_str_2);
460 set_capacity(vblk->disk, capacity);
461 revalidate_disk(vblk->disk);
463 mutex_unlock(&vblk->config_lock);
466 static void virtblk_config_changed(struct virtio_device *vdev)
468 struct virtio_blk *vblk = vdev->priv;
470 queue_work(virtblk_wq, &vblk->config_work);
473 static int init_vq(struct virtio_blk *vblk)
477 /* We expect one virtqueue, for output. */
478 vblk->vq = virtio_find_single_vq(vblk->vdev, virtblk_done, "requests");
479 if (IS_ERR(vblk->vq))
480 err = PTR_ERR(vblk->vq);
486 * Legacy naming scheme used for virtio devices. We are stuck with it for
487 * virtio blk but don't ever use it for any new driver.
489 static int virtblk_name_format(char *prefix, int index, char *buf, int buflen)
491 const int base = 'z' - 'a' + 1;
492 char *begin = buf + strlen(prefix);
493 char *end = buf + buflen;
503 *--p = 'a' + (index % unit);
504 index = (index / unit) - 1;
505 } while (index >= 0);
507 memmove(begin, p, end - p);
508 memcpy(buf, prefix, strlen(prefix));
513 static int virtblk_get_cache_mode(struct virtio_device *vdev)
518 err = virtio_config_val(vdev, VIRTIO_BLK_F_CONFIG_WCE,
519 offsetof(struct virtio_blk_config, wce),
522 writeback = virtio_has_feature(vdev, VIRTIO_BLK_F_WCE);
527 static void virtblk_update_cache_mode(struct virtio_device *vdev)
529 u8 writeback = virtblk_get_cache_mode(vdev);
530 struct virtio_blk *vblk = vdev->priv;
532 if (writeback && !use_bio)
533 blk_queue_flush(vblk->disk->queue, REQ_FLUSH);
535 blk_queue_flush(vblk->disk->queue, 0);
537 revalidate_disk(vblk->disk);
540 static const char *const virtblk_cache_types[] = {
541 "write through", "write back"
545 virtblk_cache_type_store(struct device *dev, struct device_attribute *attr,
546 const char *buf, size_t count)
548 struct gendisk *disk = dev_to_disk(dev);
549 struct virtio_blk *vblk = disk->private_data;
550 struct virtio_device *vdev = vblk->vdev;
554 BUG_ON(!virtio_has_feature(vblk->vdev, VIRTIO_BLK_F_CONFIG_WCE));
555 for (i = ARRAY_SIZE(virtblk_cache_types); --i >= 0; )
556 if (sysfs_streq(buf, virtblk_cache_types[i]))
563 vdev->config->set(vdev,
564 offsetof(struct virtio_blk_config, wce),
565 &writeback, sizeof(writeback));
567 virtblk_update_cache_mode(vdev);
572 virtblk_cache_type_show(struct device *dev, struct device_attribute *attr,
575 struct gendisk *disk = dev_to_disk(dev);
576 struct virtio_blk *vblk = disk->private_data;
577 u8 writeback = virtblk_get_cache_mode(vblk->vdev);
579 BUG_ON(writeback >= ARRAY_SIZE(virtblk_cache_types));
580 return snprintf(buf, 40, "%s\n", virtblk_cache_types[writeback]);
583 static const struct device_attribute dev_attr_cache_type_ro =
584 __ATTR(cache_type, S_IRUGO,
585 virtblk_cache_type_show, NULL);
586 static const struct device_attribute dev_attr_cache_type_rw =
587 __ATTR(cache_type, S_IRUGO|S_IWUSR,
588 virtblk_cache_type_show, virtblk_cache_type_store);
590 static int __devinit virtblk_probe(struct virtio_device *vdev)
592 struct virtio_blk *vblk;
593 struct request_queue *q;
598 u32 v, blk_size, sg_elems, opt_io_size;
600 u8 physical_block_exp, alignment_offset;
602 err = ida_simple_get(&vd_index_ida, 0, minor_to_index(1 << MINORBITS),
608 /* We need to know how many segments before we allocate. */
609 err = virtio_config_val(vdev, VIRTIO_BLK_F_SEG_MAX,
610 offsetof(struct virtio_blk_config, seg_max),
613 /* We need at least one SG element, whatever they say. */
614 if (err || !sg_elems)
617 /* We need an extra sg elements at head and tail. */
619 vdev->priv = vblk = kmalloc(sizeof(*vblk) +
620 sizeof(vblk->sg[0]) * sg_elems, GFP_KERNEL);
626 init_waitqueue_head(&vblk->queue_wait);
628 vblk->sg_elems = sg_elems;
629 sg_init_table(vblk->sg, vblk->sg_elems);
630 mutex_init(&vblk->config_lock);
632 INIT_WORK(&vblk->config_work, virtblk_config_changed_work);
633 vblk->config_enable = true;
639 pool_size = sizeof(struct virtblk_req);
641 pool_size += sizeof(struct scatterlist) * sg_elems;
642 vblk->pool = mempool_create_kmalloc_pool(1, pool_size);
648 /* FIXME: How many partitions? How long is a piece of string? */
649 vblk->disk = alloc_disk(1 << PART_BITS);
655 q = vblk->disk->queue = blk_init_queue(virtblk_request, NULL);
662 blk_queue_make_request(q, virtblk_make_request);
665 virtblk_name_format("vd", index, vblk->disk->disk_name, DISK_NAME_LEN);
667 vblk->disk->major = major;
668 vblk->disk->first_minor = index_to_minor(index);
669 vblk->disk->private_data = vblk;
670 vblk->disk->fops = &virtblk_fops;
671 vblk->disk->driverfs_dev = &vdev->dev;
674 /* configure queue flush support */
675 virtblk_update_cache_mode(vdev);
677 /* If disk is read-only in the host, the guest should obey */
678 if (virtio_has_feature(vdev, VIRTIO_BLK_F_RO))
679 set_disk_ro(vblk->disk, 1);
681 /* Host must always specify the capacity. */
682 vdev->config->get(vdev, offsetof(struct virtio_blk_config, capacity),
685 /* If capacity is too big, truncate with warning. */
686 if ((sector_t)cap != cap) {
687 dev_warn(&vdev->dev, "Capacity %llu too large: truncating\n",
688 (unsigned long long)cap);
691 set_capacity(vblk->disk, cap);
693 /* We can handle whatever the host told us to handle. */
694 blk_queue_max_segments(q, vblk->sg_elems-2);
696 /* No need to bounce any requests */
697 blk_queue_bounce_limit(q, BLK_BOUNCE_ANY);
699 /* No real sector limit. */
700 blk_queue_max_hw_sectors(q, -1U);
702 /* Host can optionally specify maximum segment size and number of
704 err = virtio_config_val(vdev, VIRTIO_BLK_F_SIZE_MAX,
705 offsetof(struct virtio_blk_config, size_max),
708 blk_queue_max_segment_size(q, v);
710 blk_queue_max_segment_size(q, -1U);
712 /* Host can optionally specify the block size of the device */
713 err = virtio_config_val(vdev, VIRTIO_BLK_F_BLK_SIZE,
714 offsetof(struct virtio_blk_config, blk_size),
717 blk_queue_logical_block_size(q, blk_size);
719 blk_size = queue_logical_block_size(q);
721 /* Use topology information if available */
722 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
723 offsetof(struct virtio_blk_config, physical_block_exp),
724 &physical_block_exp);
725 if (!err && physical_block_exp)
726 blk_queue_physical_block_size(q,
727 blk_size * (1 << physical_block_exp));
729 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
730 offsetof(struct virtio_blk_config, alignment_offset),
732 if (!err && alignment_offset)
733 blk_queue_alignment_offset(q, blk_size * alignment_offset);
735 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
736 offsetof(struct virtio_blk_config, min_io_size),
738 if (!err && min_io_size)
739 blk_queue_io_min(q, blk_size * min_io_size);
741 err = virtio_config_val(vdev, VIRTIO_BLK_F_TOPOLOGY,
742 offsetof(struct virtio_blk_config, opt_io_size),
744 if (!err && opt_io_size)
745 blk_queue_io_opt(q, blk_size * opt_io_size);
747 add_disk(vblk->disk);
748 err = device_create_file(disk_to_dev(vblk->disk), &dev_attr_serial);
752 if (virtio_has_feature(vdev, VIRTIO_BLK_F_CONFIG_WCE))
753 err = device_create_file(disk_to_dev(vblk->disk),
754 &dev_attr_cache_type_rw);
756 err = device_create_file(disk_to_dev(vblk->disk),
757 &dev_attr_cache_type_ro);
763 del_gendisk(vblk->disk);
764 blk_cleanup_queue(vblk->disk->queue);
766 put_disk(vblk->disk);
768 mempool_destroy(vblk->pool);
770 vdev->config->del_vqs(vdev);
774 ida_simple_remove(&vd_index_ida, index);
779 static void __devexit virtblk_remove(struct virtio_device *vdev)
781 struct virtio_blk *vblk = vdev->priv;
782 int index = vblk->index;
784 /* Prevent config work handler from accessing the device. */
785 mutex_lock(&vblk->config_lock);
786 vblk->config_enable = false;
787 mutex_unlock(&vblk->config_lock);
789 del_gendisk(vblk->disk);
790 blk_cleanup_queue(vblk->disk->queue);
792 /* Stop all the virtqueues. */
793 vdev->config->reset(vdev);
795 flush_work(&vblk->config_work);
797 put_disk(vblk->disk);
798 mempool_destroy(vblk->pool);
799 vdev->config->del_vqs(vdev);
801 ida_simple_remove(&vd_index_ida, index);
805 static int virtblk_freeze(struct virtio_device *vdev)
807 struct virtio_blk *vblk = vdev->priv;
809 /* Ensure we don't receive any more interrupts */
810 vdev->config->reset(vdev);
812 /* Prevent config work handler from accessing the device. */
813 mutex_lock(&vblk->config_lock);
814 vblk->config_enable = false;
815 mutex_unlock(&vblk->config_lock);
817 flush_work(&vblk->config_work);
819 spin_lock_irq(vblk->disk->queue->queue_lock);
820 blk_stop_queue(vblk->disk->queue);
821 spin_unlock_irq(vblk->disk->queue->queue_lock);
822 blk_sync_queue(vblk->disk->queue);
824 vdev->config->del_vqs(vdev);
828 static int virtblk_restore(struct virtio_device *vdev)
830 struct virtio_blk *vblk = vdev->priv;
833 vblk->config_enable = true;
834 ret = init_vq(vdev->priv);
836 spin_lock_irq(vblk->disk->queue->queue_lock);
837 blk_start_queue(vblk->disk->queue);
838 spin_unlock_irq(vblk->disk->queue->queue_lock);
844 static const struct virtio_device_id id_table[] = {
845 { VIRTIO_ID_BLOCK, VIRTIO_DEV_ANY_ID },
849 static unsigned int features[] = {
850 VIRTIO_BLK_F_SEG_MAX, VIRTIO_BLK_F_SIZE_MAX, VIRTIO_BLK_F_GEOMETRY,
851 VIRTIO_BLK_F_RO, VIRTIO_BLK_F_BLK_SIZE, VIRTIO_BLK_F_SCSI,
852 VIRTIO_BLK_F_WCE, VIRTIO_BLK_F_TOPOLOGY, VIRTIO_BLK_F_CONFIG_WCE
856 * virtio_blk causes spurious section mismatch warning by
857 * simultaneously referring to a __devinit and a __devexit function.
858 * Use __refdata to avoid this warning.
860 static struct virtio_driver __refdata virtio_blk = {
861 .feature_table = features,
862 .feature_table_size = ARRAY_SIZE(features),
863 .driver.name = KBUILD_MODNAME,
864 .driver.owner = THIS_MODULE,
865 .id_table = id_table,
866 .probe = virtblk_probe,
867 .remove = __devexit_p(virtblk_remove),
868 .config_changed = virtblk_config_changed,
870 .freeze = virtblk_freeze,
871 .restore = virtblk_restore,
875 static int __init init(void)
879 virtblk_wq = alloc_workqueue("virtio-blk", 0, 0);
883 major = register_blkdev(0, "virtblk");
886 goto out_destroy_workqueue;
889 error = register_virtio_driver(&virtio_blk);
891 goto out_unregister_blkdev;
894 out_unregister_blkdev:
895 unregister_blkdev(major, "virtblk");
896 out_destroy_workqueue:
897 destroy_workqueue(virtblk_wq);
901 static void __exit fini(void)
903 unregister_blkdev(major, "virtblk");
904 unregister_virtio_driver(&virtio_blk);
905 destroy_workqueue(virtblk_wq);
910 MODULE_DEVICE_TABLE(virtio, id_table);
911 MODULE_DESCRIPTION("Virtio block driver");
912 MODULE_LICENSE("GPL");