4 * XenLinux virtual block device driver.
6 * Copyright (c) 2003-2004, Keir Fraser & Steve Hand
7 * Modifications by Mark A. Williamson are (c) Intel Research Cambridge
8 * Copyright (c) 2004, Christian Limpach
9 * Copyright (c) 2004, Andrew Warfield
10 * Copyright (c) 2005, Christopher Clark
11 * Copyright (c) 2005, XenSource Ltd
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License version 2
15 * as published by the Free Software Foundation; or, when distributed
16 * separately from the Linux kernel or incorporated into other
17 * software packages, subject to the following license:
19 * Permission is hereby granted, free of charge, to any person obtaining a copy
20 * of this source file (the "Software"), to deal in the Software without
21 * restriction, including without limitation the rights to use, copy, modify,
22 * merge, publish, distribute, sublicense, and/or sell copies of the Software,
23 * and to permit persons to whom the Software is furnished to do so, subject to
24 * the following conditions:
26 * The above copyright notice and this permission notice shall be included in
27 * all copies or substantial portions of the Software.
29 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
38 #include <linux/interrupt.h>
39 #include <linux/blkdev.h>
40 #include <linux/blk-mq.h>
41 #include <linux/hdreg.h>
42 #include <linux/cdrom.h>
43 #include <linux/module.h>
44 #include <linux/slab.h>
45 #include <linux/mutex.h>
46 #include <linux/scatterlist.h>
47 #include <linux/bitmap.h>
48 #include <linux/list.h>
51 #include <xen/xenbus.h>
52 #include <xen/grant_table.h>
53 #include <xen/events.h>
55 #include <xen/platform_pci.h>
57 #include <xen/interface/grant_table.h>
58 #include <xen/interface/io/blkif.h>
59 #include <xen/interface/io/protocols.h>
61 #include <asm/xen/hypervisor.h>
64 BLKIF_STATE_DISCONNECTED
,
65 BLKIF_STATE_CONNECTED
,
66 BLKIF_STATE_SUSPENDED
,
72 struct list_head node
;
76 struct blkif_request req
;
77 struct request
*request
;
78 struct grant
**grants_used
;
79 struct grant
**indirect_grants
;
80 struct scatterlist
*sg
;
88 static DEFINE_MUTEX(blkfront_mutex
);
89 static const struct block_device_operations xlvbd_block_fops
;
92 * Maximum number of segments in indirect requests, the actual value used by
93 * the frontend driver is the minimum of this value and the value provided
94 * by the backend driver.
97 static unsigned int xen_blkif_max_segments
= 32;
98 module_param_named(max
, xen_blkif_max_segments
, int, S_IRUGO
);
99 MODULE_PARM_DESC(max
, "Maximum amount of segments in indirect requests (default is 32)");
102 * Maximum order of pages to be used for the shared ring between front and
103 * backend, 4KB page granularity is used.
105 static unsigned int xen_blkif_max_ring_order
;
106 module_param_named(max_ring_page_order
, xen_blkif_max_ring_order
, int, S_IRUGO
);
107 MODULE_PARM_DESC(max_ring_page_order
, "Maximum order of pages to be used for the shared ring");
109 #define BLK_RING_SIZE(info) __CONST_RING_SIZE(blkif, PAGE_SIZE * (info)->nr_ring_pages)
110 #define BLK_MAX_RING_SIZE __CONST_RING_SIZE(blkif, PAGE_SIZE * XENBUS_MAX_RING_PAGES)
112 * ring-ref%i i=(-1UL) would take 11 characters + 'ring-ref' is 8, so 19
113 * characters are enough. Define to 20 to keep consist with backend.
115 #define RINGREF_NAME_LEN (20)
118 * We have one of these per vbd, whether ide, scsi or 'other'. They
119 * hang in private_data off the gendisk structure. We may end up
120 * putting all kinds of interesting stuff here :-)
126 struct xenbus_device
*xbdev
;
130 enum blkif_state connected
;
131 int ring_ref
[XENBUS_MAX_RING_PAGES
];
132 unsigned int nr_ring_pages
;
133 struct blkif_front_ring ring
;
134 unsigned int evtchn
, irq
;
135 struct request_queue
*rq
;
136 struct work_struct work
;
137 struct gnttab_free_callback callback
;
138 struct blk_shadow shadow
[BLK_MAX_RING_SIZE
];
139 struct list_head grants
;
140 struct list_head indirect_pages
;
141 unsigned int persistent_gnts_c
;
142 unsigned long shadow_free
;
143 unsigned int feature_flush
;
144 unsigned int feature_discard
:1;
145 unsigned int feature_secdiscard
:1;
146 unsigned int discard_granularity
;
147 unsigned int discard_alignment
;
148 unsigned int feature_persistent
:1;
149 unsigned int max_indirect_segments
;
151 struct blk_mq_tag_set tag_set
;
154 static unsigned int nr_minors
;
155 static unsigned long *minors
;
156 static DEFINE_SPINLOCK(minor_lock
);
158 #define GRANT_INVALID_REF 0
160 #define PARTS_PER_DISK 16
161 #define PARTS_PER_EXT_DISK 256
163 #define BLKIF_MAJOR(dev) ((dev)>>8)
164 #define BLKIF_MINOR(dev) ((dev) & 0xff)
167 #define EXTENDED (1<<EXT_SHIFT)
168 #define VDEV_IS_EXTENDED(dev) ((dev)&(EXTENDED))
169 #define BLKIF_MINOR_EXT(dev) ((dev)&(~EXTENDED))
170 #define EMULATED_HD_DISK_MINOR_OFFSET (0)
171 #define EMULATED_HD_DISK_NAME_OFFSET (EMULATED_HD_DISK_MINOR_OFFSET / 256)
172 #define EMULATED_SD_DISK_MINOR_OFFSET (0)
173 #define EMULATED_SD_DISK_NAME_OFFSET (EMULATED_SD_DISK_MINOR_OFFSET / 256)
175 #define DEV_NAME "xvd" /* name in /dev */
177 #define SEGS_PER_INDIRECT_FRAME \
178 (PAGE_SIZE/sizeof(struct blkif_request_segment))
179 #define INDIRECT_GREFS(_segs) \
180 ((_segs + SEGS_PER_INDIRECT_FRAME - 1)/SEGS_PER_INDIRECT_FRAME)
182 static int blkfront_setup_indirect(struct blkfront_info
*info
);
183 static int blkfront_gather_backend_features(struct blkfront_info
*info
);
185 static int get_id_from_freelist(struct blkfront_info
*info
)
187 unsigned long free
= info
->shadow_free
;
188 BUG_ON(free
>= BLK_RING_SIZE(info
));
189 info
->shadow_free
= info
->shadow
[free
].req
.u
.rw
.id
;
190 info
->shadow
[free
].req
.u
.rw
.id
= 0x0fffffee; /* debug */
194 static int add_id_to_freelist(struct blkfront_info
*info
,
197 if (info
->shadow
[id
].req
.u
.rw
.id
!= id
)
199 if (info
->shadow
[id
].request
== NULL
)
201 info
->shadow
[id
].req
.u
.rw
.id
= info
->shadow_free
;
202 info
->shadow
[id
].request
= NULL
;
203 info
->shadow_free
= id
;
207 static int fill_grant_buffer(struct blkfront_info
*info
, int num
)
209 struct page
*granted_page
;
210 struct grant
*gnt_list_entry
, *n
;
214 gnt_list_entry
= kzalloc(sizeof(struct grant
), GFP_NOIO
);
218 if (info
->feature_persistent
) {
219 granted_page
= alloc_page(GFP_NOIO
);
221 kfree(gnt_list_entry
);
224 gnt_list_entry
->page
= granted_page
;
227 gnt_list_entry
->gref
= GRANT_INVALID_REF
;
228 list_add(&gnt_list_entry
->node
, &info
->grants
);
235 list_for_each_entry_safe(gnt_list_entry
, n
,
236 &info
->grants
, node
) {
237 list_del(&gnt_list_entry
->node
);
238 if (info
->feature_persistent
)
239 __free_page(gnt_list_entry
->page
);
240 kfree(gnt_list_entry
);
247 static struct grant
*get_free_grant(struct blkfront_info
*info
)
249 struct grant
*gnt_list_entry
;
251 BUG_ON(list_empty(&info
->grants
));
252 gnt_list_entry
= list_first_entry(&info
->grants
, struct grant
,
254 list_del(&gnt_list_entry
->node
);
256 if (gnt_list_entry
->gref
!= GRANT_INVALID_REF
)
257 info
->persistent_gnts_c
--;
259 return gnt_list_entry
;
262 static inline void grant_foreign_access(const struct grant
*gnt_list_entry
,
263 const struct blkfront_info
*info
)
265 gnttab_page_grant_foreign_access_ref_one(gnt_list_entry
->gref
,
266 info
->xbdev
->otherend_id
,
267 gnt_list_entry
->page
,
271 static struct grant
*get_grant(grant_ref_t
*gref_head
,
273 struct blkfront_info
*info
)
275 struct grant
*gnt_list_entry
= get_free_grant(info
);
277 if (gnt_list_entry
->gref
!= GRANT_INVALID_REF
)
278 return gnt_list_entry
;
280 /* Assign a gref to this page */
281 gnt_list_entry
->gref
= gnttab_claim_grant_reference(gref_head
);
282 BUG_ON(gnt_list_entry
->gref
== -ENOSPC
);
283 if (info
->feature_persistent
)
284 grant_foreign_access(gnt_list_entry
, info
);
286 /* Grant access to the GFN passed by the caller */
287 gnttab_grant_foreign_access_ref(gnt_list_entry
->gref
,
288 info
->xbdev
->otherend_id
,
292 return gnt_list_entry
;
295 static struct grant
*get_indirect_grant(grant_ref_t
*gref_head
,
296 struct blkfront_info
*info
)
298 struct grant
*gnt_list_entry
= get_free_grant(info
);
300 if (gnt_list_entry
->gref
!= GRANT_INVALID_REF
)
301 return gnt_list_entry
;
303 /* Assign a gref to this page */
304 gnt_list_entry
->gref
= gnttab_claim_grant_reference(gref_head
);
305 BUG_ON(gnt_list_entry
->gref
== -ENOSPC
);
306 if (!info
->feature_persistent
) {
307 struct page
*indirect_page
;
309 /* Fetch a pre-allocated page to use for indirect grefs */
310 BUG_ON(list_empty(&info
->indirect_pages
));
311 indirect_page
= list_first_entry(&info
->indirect_pages
,
313 list_del(&indirect_page
->lru
);
314 gnt_list_entry
->page
= indirect_page
;
316 grant_foreign_access(gnt_list_entry
, info
);
318 return gnt_list_entry
;
321 static const char *op_name(int op
)
323 static const char *const names
[] = {
324 [BLKIF_OP_READ
] = "read",
325 [BLKIF_OP_WRITE
] = "write",
326 [BLKIF_OP_WRITE_BARRIER
] = "barrier",
327 [BLKIF_OP_FLUSH_DISKCACHE
] = "flush",
328 [BLKIF_OP_DISCARD
] = "discard" };
330 if (op
< 0 || op
>= ARRAY_SIZE(names
))
338 static int xlbd_reserve_minors(unsigned int minor
, unsigned int nr
)
340 unsigned int end
= minor
+ nr
;
343 if (end
> nr_minors
) {
344 unsigned long *bitmap
, *old
;
346 bitmap
= kcalloc(BITS_TO_LONGS(end
), sizeof(*bitmap
),
351 spin_lock(&minor_lock
);
352 if (end
> nr_minors
) {
354 memcpy(bitmap
, minors
,
355 BITS_TO_LONGS(nr_minors
) * sizeof(*bitmap
));
357 nr_minors
= BITS_TO_LONGS(end
) * BITS_PER_LONG
;
360 spin_unlock(&minor_lock
);
364 spin_lock(&minor_lock
);
365 if (find_next_bit(minors
, end
, minor
) >= end
) {
366 bitmap_set(minors
, minor
, nr
);
370 spin_unlock(&minor_lock
);
375 static void xlbd_release_minors(unsigned int minor
, unsigned int nr
)
377 unsigned int end
= minor
+ nr
;
379 BUG_ON(end
> nr_minors
);
380 spin_lock(&minor_lock
);
381 bitmap_clear(minors
, minor
, nr
);
382 spin_unlock(&minor_lock
);
385 static void blkif_restart_queue_callback(void *arg
)
387 struct blkfront_info
*info
= (struct blkfront_info
*)arg
;
388 schedule_work(&info
->work
);
391 static int blkif_getgeo(struct block_device
*bd
, struct hd_geometry
*hg
)
393 /* We don't have real geometry info, but let's at least return
394 values consistent with the size of the device */
395 sector_t nsect
= get_capacity(bd
->bd_disk
);
396 sector_t cylinders
= nsect
;
400 sector_div(cylinders
, hg
->heads
* hg
->sectors
);
401 hg
->cylinders
= cylinders
;
402 if ((sector_t
)(hg
->cylinders
+ 1) * hg
->heads
* hg
->sectors
< nsect
)
403 hg
->cylinders
= 0xffff;
407 static int blkif_ioctl(struct block_device
*bdev
, fmode_t mode
,
408 unsigned command
, unsigned long argument
)
410 struct blkfront_info
*info
= bdev
->bd_disk
->private_data
;
413 dev_dbg(&info
->xbdev
->dev
, "command: 0x%x, argument: 0x%lx\n",
414 command
, (long)argument
);
417 case CDROMMULTISESSION
:
418 dev_dbg(&info
->xbdev
->dev
, "FIXME: support multisession CDs later\n");
419 for (i
= 0; i
< sizeof(struct cdrom_multisession
); i
++)
420 if (put_user(0, (char __user
*)(argument
+ i
)))
424 case CDROM_GET_CAPABILITY
: {
425 struct gendisk
*gd
= info
->gd
;
426 if (gd
->flags
& GENHD_FL_CD
)
432 /*printk(KERN_ALERT "ioctl %08x not supported by Xen blkdev\n",
434 return -EINVAL
; /* same return as native Linux */
440 static int blkif_queue_discard_req(struct request
*req
)
442 struct blkfront_info
*info
= req
->rq_disk
->private_data
;
443 struct blkif_request
*ring_req
;
446 /* Fill out a communications ring structure. */
447 ring_req
= RING_GET_REQUEST(&info
->ring
, info
->ring
.req_prod_pvt
);
448 id
= get_id_from_freelist(info
);
449 info
->shadow
[id
].request
= req
;
451 ring_req
->operation
= BLKIF_OP_DISCARD
;
452 ring_req
->u
.discard
.nr_sectors
= blk_rq_sectors(req
);
453 ring_req
->u
.discard
.id
= id
;
454 ring_req
->u
.discard
.sector_number
= (blkif_sector_t
)blk_rq_pos(req
);
455 if ((req
->cmd_flags
& REQ_SECURE
) && info
->feature_secdiscard
)
456 ring_req
->u
.discard
.flag
= BLKIF_DISCARD_SECURE
;
458 ring_req
->u
.discard
.flag
= 0;
460 info
->ring
.req_prod_pvt
++;
462 /* Keep a private copy so we can reissue requests when recovering. */
463 info
->shadow
[id
].req
= *ring_req
;
468 static int blkif_queue_rw_req(struct request
*req
)
470 struct blkfront_info
*info
= req
->rq_disk
->private_data
;
471 struct blkif_request
*ring_req
;
473 unsigned int fsect
, lsect
;
475 struct blkif_request_segment
*segments
= NULL
;
478 * Used to store if we are able to queue the request by just using
479 * existing persistent grants, or if we have to get new grants,
480 * as there are not sufficiently many free.
482 bool new_persistent_gnts
;
483 grant_ref_t gref_head
;
484 struct grant
*gnt_list_entry
= NULL
;
485 struct scatterlist
*sg
;
488 max_grefs
= req
->nr_phys_segments
;
489 if (max_grefs
> BLKIF_MAX_SEGMENTS_PER_REQUEST
)
491 * If we are using indirect segments we need to account
492 * for the indirect grefs used in the request.
494 max_grefs
+= INDIRECT_GREFS(req
->nr_phys_segments
);
496 /* Check if we have enough grants to allocate a requests */
497 if (info
->persistent_gnts_c
< max_grefs
) {
498 new_persistent_gnts
= 1;
499 if (gnttab_alloc_grant_references(
500 max_grefs
- info
->persistent_gnts_c
,
502 gnttab_request_free_callback(
504 blkif_restart_queue_callback
,
510 new_persistent_gnts
= 0;
512 /* Fill out a communications ring structure. */
513 ring_req
= RING_GET_REQUEST(&info
->ring
, info
->ring
.req_prod_pvt
);
514 id
= get_id_from_freelist(info
);
515 info
->shadow
[id
].request
= req
;
517 BUG_ON(info
->max_indirect_segments
== 0 &&
518 req
->nr_phys_segments
> BLKIF_MAX_SEGMENTS_PER_REQUEST
);
519 BUG_ON(info
->max_indirect_segments
&&
520 req
->nr_phys_segments
> info
->max_indirect_segments
);
521 nseg
= blk_rq_map_sg(req
->q
, req
, info
->shadow
[id
].sg
);
522 ring_req
->u
.rw
.id
= id
;
523 if (nseg
> BLKIF_MAX_SEGMENTS_PER_REQUEST
) {
525 * The indirect operation can only be a BLKIF_OP_READ or
528 BUG_ON(req
->cmd_flags
& (REQ_FLUSH
| REQ_FUA
));
529 ring_req
->operation
= BLKIF_OP_INDIRECT
;
530 ring_req
->u
.indirect
.indirect_op
= rq_data_dir(req
) ?
531 BLKIF_OP_WRITE
: BLKIF_OP_READ
;
532 ring_req
->u
.indirect
.sector_number
= (blkif_sector_t
)blk_rq_pos(req
);
533 ring_req
->u
.indirect
.handle
= info
->handle
;
534 ring_req
->u
.indirect
.nr_segments
= nseg
;
536 ring_req
->u
.rw
.sector_number
= (blkif_sector_t
)blk_rq_pos(req
);
537 ring_req
->u
.rw
.handle
= info
->handle
;
538 ring_req
->operation
= rq_data_dir(req
) ?
539 BLKIF_OP_WRITE
: BLKIF_OP_READ
;
540 if (req
->cmd_flags
& (REQ_FLUSH
| REQ_FUA
)) {
542 * Ideally we can do an unordered flush-to-disk.
543 * In case the backend onlysupports barriers, use that.
544 * A barrier request a superset of FUA, so we can
545 * implement it the same way. (It's also a FLUSH+FUA,
546 * since it is guaranteed ordered WRT previous writes.)
548 switch (info
->feature_flush
&
549 ((REQ_FLUSH
|REQ_FUA
))) {
550 case REQ_FLUSH
|REQ_FUA
:
551 ring_req
->operation
=
552 BLKIF_OP_WRITE_BARRIER
;
555 ring_req
->operation
=
556 BLKIF_OP_FLUSH_DISKCACHE
;
559 ring_req
->operation
= 0;
562 ring_req
->u
.rw
.nr_segments
= nseg
;
564 for_each_sg(info
->shadow
[id
].sg
, sg
, nseg
, i
) {
565 fsect
= sg
->offset
>> 9;
566 lsect
= fsect
+ (sg
->length
>> 9) - 1;
568 if ((ring_req
->operation
== BLKIF_OP_INDIRECT
) &&
569 (i
% SEGS_PER_INDIRECT_FRAME
== 0)) {
571 kunmap_atomic(segments
);
573 n
= i
/ SEGS_PER_INDIRECT_FRAME
;
574 gnt_list_entry
= get_indirect_grant(&gref_head
, info
);
575 info
->shadow
[id
].indirect_grants
[n
] = gnt_list_entry
;
576 segments
= kmap_atomic(gnt_list_entry
->page
);
577 ring_req
->u
.indirect
.indirect_grefs
[n
] = gnt_list_entry
->gref
;
580 gnt_list_entry
= get_grant(&gref_head
,
581 xen_page_to_gfn(sg_page(sg
)),
583 ref
= gnt_list_entry
->gref
;
585 info
->shadow
[id
].grants_used
[i
] = gnt_list_entry
;
587 if (rq_data_dir(req
) && info
->feature_persistent
) {
591 BUG_ON(sg
->offset
+ sg
->length
> PAGE_SIZE
);
593 shared_data
= kmap_atomic(gnt_list_entry
->page
);
594 bvec_data
= kmap_atomic(sg_page(sg
));
597 * this does not wipe data stored outside the
598 * range sg->offset..sg->offset+sg->length.
599 * Therefore, blkback *could* see data from
600 * previous requests. This is OK as long as
601 * persistent grants are shared with just one
602 * domain. It may need refactoring if this
605 memcpy(shared_data
+ sg
->offset
,
606 bvec_data
+ sg
->offset
,
609 kunmap_atomic(bvec_data
);
610 kunmap_atomic(shared_data
);
612 if (ring_req
->operation
!= BLKIF_OP_INDIRECT
) {
613 ring_req
->u
.rw
.seg
[i
] =
614 (struct blkif_request_segment
) {
617 .last_sect
= lsect
};
619 n
= i
% SEGS_PER_INDIRECT_FRAME
;
621 (struct blkif_request_segment
) {
624 .last_sect
= lsect
};
628 kunmap_atomic(segments
);
630 info
->ring
.req_prod_pvt
++;
632 /* Keep a private copy so we can reissue requests when recovering. */
633 info
->shadow
[id
].req
= *ring_req
;
635 if (new_persistent_gnts
)
636 gnttab_free_grant_references(gref_head
);
642 * Generate a Xen blkfront IO request from a blk layer request. Reads
643 * and writes are handled as expected.
645 * @req: a request struct
647 static int blkif_queue_request(struct request
*req
)
649 struct blkfront_info
*info
= req
->rq_disk
->private_data
;
651 if (unlikely(info
->connected
!= BLKIF_STATE_CONNECTED
))
654 if (unlikely(req
->cmd_flags
& (REQ_DISCARD
| REQ_SECURE
)))
655 return blkif_queue_discard_req(req
);
657 return blkif_queue_rw_req(req
);
660 static inline void flush_requests(struct blkfront_info
*info
)
664 RING_PUSH_REQUESTS_AND_CHECK_NOTIFY(&info
->ring
, notify
);
667 notify_remote_via_irq(info
->irq
);
670 static inline bool blkif_request_flush_invalid(struct request
*req
,
671 struct blkfront_info
*info
)
673 return ((req
->cmd_type
!= REQ_TYPE_FS
) ||
674 ((req
->cmd_flags
& REQ_FLUSH
) &&
675 !(info
->feature_flush
& REQ_FLUSH
)) ||
676 ((req
->cmd_flags
& REQ_FUA
) &&
677 !(info
->feature_flush
& REQ_FUA
)));
680 static int blkif_queue_rq(struct blk_mq_hw_ctx
*hctx
,
681 const struct blk_mq_queue_data
*qd
)
683 struct blkfront_info
*info
= qd
->rq
->rq_disk
->private_data
;
685 blk_mq_start_request(qd
->rq
);
686 spin_lock_irq(&info
->io_lock
);
687 if (RING_FULL(&info
->ring
))
690 if (blkif_request_flush_invalid(qd
->rq
, info
))
693 if (blkif_queue_request(qd
->rq
))
696 flush_requests(info
);
697 spin_unlock_irq(&info
->io_lock
);
698 return BLK_MQ_RQ_QUEUE_OK
;
701 spin_unlock_irq(&info
->io_lock
);
702 return BLK_MQ_RQ_QUEUE_ERROR
;
705 spin_unlock_irq(&info
->io_lock
);
706 blk_mq_stop_hw_queue(hctx
);
707 return BLK_MQ_RQ_QUEUE_BUSY
;
710 static struct blk_mq_ops blkfront_mq_ops
= {
711 .queue_rq
= blkif_queue_rq
,
712 .map_queue
= blk_mq_map_queue
,
715 static int xlvbd_init_blk_queue(struct gendisk
*gd
, u16 sector_size
,
716 unsigned int physical_sector_size
,
717 unsigned int segments
)
719 struct request_queue
*rq
;
720 struct blkfront_info
*info
= gd
->private_data
;
722 memset(&info
->tag_set
, 0, sizeof(info
->tag_set
));
723 info
->tag_set
.ops
= &blkfront_mq_ops
;
724 info
->tag_set
.nr_hw_queues
= 1;
725 info
->tag_set
.queue_depth
= BLK_RING_SIZE(info
);
726 info
->tag_set
.numa_node
= NUMA_NO_NODE
;
727 info
->tag_set
.flags
= BLK_MQ_F_SHOULD_MERGE
| BLK_MQ_F_SG_MERGE
;
728 info
->tag_set
.cmd_size
= 0;
729 info
->tag_set
.driver_data
= info
;
731 if (blk_mq_alloc_tag_set(&info
->tag_set
))
733 rq
= blk_mq_init_queue(&info
->tag_set
);
735 blk_mq_free_tag_set(&info
->tag_set
);
739 queue_flag_set_unlocked(QUEUE_FLAG_VIRT
, rq
);
741 if (info
->feature_discard
) {
742 queue_flag_set_unlocked(QUEUE_FLAG_DISCARD
, rq
);
743 blk_queue_max_discard_sectors(rq
, get_capacity(gd
));
744 rq
->limits
.discard_granularity
= info
->discard_granularity
;
745 rq
->limits
.discard_alignment
= info
->discard_alignment
;
746 if (info
->feature_secdiscard
)
747 queue_flag_set_unlocked(QUEUE_FLAG_SECDISCARD
, rq
);
750 /* Hard sector size and max sectors impersonate the equiv. hardware. */
751 blk_queue_logical_block_size(rq
, sector_size
);
752 blk_queue_physical_block_size(rq
, physical_sector_size
);
753 blk_queue_max_hw_sectors(rq
, (segments
* PAGE_SIZE
) / 512);
755 /* Each segment in a request is up to an aligned page in size. */
756 blk_queue_segment_boundary(rq
, PAGE_SIZE
- 1);
757 blk_queue_max_segment_size(rq
, PAGE_SIZE
);
759 /* Ensure a merged request will fit in a single I/O ring slot. */
760 blk_queue_max_segments(rq
, segments
);
762 /* Make sure buffer addresses are sector-aligned. */
763 blk_queue_dma_alignment(rq
, 511);
765 /* Make sure we don't use bounce buffers. */
766 blk_queue_bounce_limit(rq
, BLK_BOUNCE_ANY
);
773 static const char *flush_info(unsigned int feature_flush
)
775 switch (feature_flush
& ((REQ_FLUSH
| REQ_FUA
))) {
776 case REQ_FLUSH
|REQ_FUA
:
777 return "barrier: enabled;";
779 return "flush diskcache: enabled;";
781 return "barrier or flush: disabled;";
785 static void xlvbd_flush(struct blkfront_info
*info
)
787 blk_queue_flush(info
->rq
, info
->feature_flush
);
788 pr_info("blkfront: %s: %s %s %s %s %s\n",
789 info
->gd
->disk_name
, flush_info(info
->feature_flush
),
790 "persistent grants:", info
->feature_persistent
?
791 "enabled;" : "disabled;", "indirect descriptors:",
792 info
->max_indirect_segments
? "enabled;" : "disabled;");
795 static int xen_translate_vdev(int vdevice
, int *minor
, unsigned int *offset
)
798 major
= BLKIF_MAJOR(vdevice
);
799 *minor
= BLKIF_MINOR(vdevice
);
802 *offset
= (*minor
/ 64) + EMULATED_HD_DISK_NAME_OFFSET
;
803 *minor
= ((*minor
/ 64) * PARTS_PER_DISK
) +
804 EMULATED_HD_DISK_MINOR_OFFSET
;
807 *offset
= (*minor
/ 64) + 2 + EMULATED_HD_DISK_NAME_OFFSET
;
808 *minor
= (((*minor
/ 64) + 2) * PARTS_PER_DISK
) +
809 EMULATED_HD_DISK_MINOR_OFFSET
;
811 case XEN_SCSI_DISK0_MAJOR
:
812 *offset
= (*minor
/ PARTS_PER_DISK
) + EMULATED_SD_DISK_NAME_OFFSET
;
813 *minor
= *minor
+ EMULATED_SD_DISK_MINOR_OFFSET
;
815 case XEN_SCSI_DISK1_MAJOR
:
816 case XEN_SCSI_DISK2_MAJOR
:
817 case XEN_SCSI_DISK3_MAJOR
:
818 case XEN_SCSI_DISK4_MAJOR
:
819 case XEN_SCSI_DISK5_MAJOR
:
820 case XEN_SCSI_DISK6_MAJOR
:
821 case XEN_SCSI_DISK7_MAJOR
:
822 *offset
= (*minor
/ PARTS_PER_DISK
) +
823 ((major
- XEN_SCSI_DISK1_MAJOR
+ 1) * 16) +
824 EMULATED_SD_DISK_NAME_OFFSET
;
826 ((major
- XEN_SCSI_DISK1_MAJOR
+ 1) * 16 * PARTS_PER_DISK
) +
827 EMULATED_SD_DISK_MINOR_OFFSET
;
829 case XEN_SCSI_DISK8_MAJOR
:
830 case XEN_SCSI_DISK9_MAJOR
:
831 case XEN_SCSI_DISK10_MAJOR
:
832 case XEN_SCSI_DISK11_MAJOR
:
833 case XEN_SCSI_DISK12_MAJOR
:
834 case XEN_SCSI_DISK13_MAJOR
:
835 case XEN_SCSI_DISK14_MAJOR
:
836 case XEN_SCSI_DISK15_MAJOR
:
837 *offset
= (*minor
/ PARTS_PER_DISK
) +
838 ((major
- XEN_SCSI_DISK8_MAJOR
+ 8) * 16) +
839 EMULATED_SD_DISK_NAME_OFFSET
;
841 ((major
- XEN_SCSI_DISK8_MAJOR
+ 8) * 16 * PARTS_PER_DISK
) +
842 EMULATED_SD_DISK_MINOR_OFFSET
;
845 *offset
= *minor
/ PARTS_PER_DISK
;
848 printk(KERN_WARNING
"blkfront: your disk configuration is "
849 "incorrect, please use an xvd device instead\n");
855 static char *encode_disk_name(char *ptr
, unsigned int n
)
858 ptr
= encode_disk_name(ptr
, n
/ 26 - 1);
863 static int xlvbd_alloc_gendisk(blkif_sector_t capacity
,
864 struct blkfront_info
*info
,
865 u16 vdisk_info
, u16 sector_size
,
866 unsigned int physical_sector_size
)
876 BUG_ON(info
->gd
!= NULL
);
877 BUG_ON(info
->rq
!= NULL
);
879 if ((info
->vdevice
>>EXT_SHIFT
) > 1) {
880 /* this is above the extended range; something is wrong */
881 printk(KERN_WARNING
"blkfront: vdevice 0x%x is above the extended range; ignoring\n", info
->vdevice
);
885 if (!VDEV_IS_EXTENDED(info
->vdevice
)) {
886 err
= xen_translate_vdev(info
->vdevice
, &minor
, &offset
);
889 nr_parts
= PARTS_PER_DISK
;
891 minor
= BLKIF_MINOR_EXT(info
->vdevice
);
892 nr_parts
= PARTS_PER_EXT_DISK
;
893 offset
= minor
/ nr_parts
;
894 if (xen_hvm_domain() && offset
< EMULATED_HD_DISK_NAME_OFFSET
+ 4)
895 printk(KERN_WARNING
"blkfront: vdevice 0x%x might conflict with "
896 "emulated IDE disks,\n\t choose an xvd device name"
897 "from xvde on\n", info
->vdevice
);
899 if (minor
>> MINORBITS
) {
900 pr_warn("blkfront: %#x's minor (%#x) out of range; ignoring\n",
901 info
->vdevice
, minor
);
905 if ((minor
% nr_parts
) == 0)
906 nr_minors
= nr_parts
;
908 err
= xlbd_reserve_minors(minor
, nr_minors
);
913 gd
= alloc_disk(nr_minors
);
917 strcpy(gd
->disk_name
, DEV_NAME
);
918 ptr
= encode_disk_name(gd
->disk_name
+ sizeof(DEV_NAME
) - 1, offset
);
919 BUG_ON(ptr
>= gd
->disk_name
+ DISK_NAME_LEN
);
923 snprintf(ptr
, gd
->disk_name
+ DISK_NAME_LEN
- ptr
,
924 "%d", minor
& (nr_parts
- 1));
926 gd
->major
= XENVBD_MAJOR
;
927 gd
->first_minor
= minor
;
928 gd
->fops
= &xlvbd_block_fops
;
929 gd
->private_data
= info
;
930 gd
->driverfs_dev
= &(info
->xbdev
->dev
);
931 set_capacity(gd
, capacity
);
933 if (xlvbd_init_blk_queue(gd
, sector_size
, physical_sector_size
,
934 info
->max_indirect_segments
? :
935 BLKIF_MAX_SEGMENTS_PER_REQUEST
)) {
940 info
->rq
= gd
->queue
;
945 if (vdisk_info
& VDISK_READONLY
)
948 if (vdisk_info
& VDISK_REMOVABLE
)
949 gd
->flags
|= GENHD_FL_REMOVABLE
;
951 if (vdisk_info
& VDISK_CDROM
)
952 gd
->flags
|= GENHD_FL_CD
;
957 xlbd_release_minors(minor
, nr_minors
);
962 static void xlvbd_release_gendisk(struct blkfront_info
*info
)
964 unsigned int minor
, nr_minors
;
966 if (info
->rq
== NULL
)
969 /* No more blkif_request(). */
970 blk_mq_stop_hw_queues(info
->rq
);
972 /* No more gnttab callback work. */
973 gnttab_cancel_free_callback(&info
->callback
);
975 /* Flush gnttab callback work. Must be done with no locks held. */
976 flush_work(&info
->work
);
978 del_gendisk(info
->gd
);
980 minor
= info
->gd
->first_minor
;
981 nr_minors
= info
->gd
->minors
;
982 xlbd_release_minors(minor
, nr_minors
);
984 blk_cleanup_queue(info
->rq
);
985 blk_mq_free_tag_set(&info
->tag_set
);
992 /* Must be called with io_lock holded */
993 static void kick_pending_request_queues(struct blkfront_info
*info
)
995 if (!RING_FULL(&info
->ring
))
996 blk_mq_start_stopped_hw_queues(info
->rq
, true);
999 static void blkif_restart_queue(struct work_struct
*work
)
1001 struct blkfront_info
*info
= container_of(work
, struct blkfront_info
, work
);
1003 spin_lock_irq(&info
->io_lock
);
1004 if (info
->connected
== BLKIF_STATE_CONNECTED
)
1005 kick_pending_request_queues(info
);
1006 spin_unlock_irq(&info
->io_lock
);
1009 static void blkif_free(struct blkfront_info
*info
, int suspend
)
1011 struct grant
*persistent_gnt
;
1015 /* Prevent new requests being issued until we fix things up. */
1016 spin_lock_irq(&info
->io_lock
);
1017 info
->connected
= suspend
?
1018 BLKIF_STATE_SUSPENDED
: BLKIF_STATE_DISCONNECTED
;
1019 /* No more blkif_request(). */
1021 blk_mq_stop_hw_queues(info
->rq
);
1023 /* Remove all persistent grants */
1024 if (!list_empty(&info
->grants
)) {
1025 list_for_each_entry_safe(persistent_gnt
, n
,
1026 &info
->grants
, node
) {
1027 list_del(&persistent_gnt
->node
);
1028 if (persistent_gnt
->gref
!= GRANT_INVALID_REF
) {
1029 gnttab_end_foreign_access(persistent_gnt
->gref
,
1031 info
->persistent_gnts_c
--;
1033 if (info
->feature_persistent
)
1034 __free_page(persistent_gnt
->page
);
1035 kfree(persistent_gnt
);
1038 BUG_ON(info
->persistent_gnts_c
!= 0);
1041 * Remove indirect pages, this only happens when using indirect
1042 * descriptors but not persistent grants
1044 if (!list_empty(&info
->indirect_pages
)) {
1045 struct page
*indirect_page
, *n
;
1047 BUG_ON(info
->feature_persistent
);
1048 list_for_each_entry_safe(indirect_page
, n
, &info
->indirect_pages
, lru
) {
1049 list_del(&indirect_page
->lru
);
1050 __free_page(indirect_page
);
1054 for (i
= 0; i
< BLK_RING_SIZE(info
); i
++) {
1056 * Clear persistent grants present in requests already
1057 * on the shared ring
1059 if (!info
->shadow
[i
].request
)
1062 segs
= info
->shadow
[i
].req
.operation
== BLKIF_OP_INDIRECT
?
1063 info
->shadow
[i
].req
.u
.indirect
.nr_segments
:
1064 info
->shadow
[i
].req
.u
.rw
.nr_segments
;
1065 for (j
= 0; j
< segs
; j
++) {
1066 persistent_gnt
= info
->shadow
[i
].grants_used
[j
];
1067 gnttab_end_foreign_access(persistent_gnt
->gref
, 0, 0UL);
1068 if (info
->feature_persistent
)
1069 __free_page(persistent_gnt
->page
);
1070 kfree(persistent_gnt
);
1073 if (info
->shadow
[i
].req
.operation
!= BLKIF_OP_INDIRECT
)
1075 * If this is not an indirect operation don't try to
1076 * free indirect segments
1080 for (j
= 0; j
< INDIRECT_GREFS(segs
); j
++) {
1081 persistent_gnt
= info
->shadow
[i
].indirect_grants
[j
];
1082 gnttab_end_foreign_access(persistent_gnt
->gref
, 0, 0UL);
1083 __free_page(persistent_gnt
->page
);
1084 kfree(persistent_gnt
);
1088 kfree(info
->shadow
[i
].grants_used
);
1089 info
->shadow
[i
].grants_used
= NULL
;
1090 kfree(info
->shadow
[i
].indirect_grants
);
1091 info
->shadow
[i
].indirect_grants
= NULL
;
1092 kfree(info
->shadow
[i
].sg
);
1093 info
->shadow
[i
].sg
= NULL
;
1096 /* No more gnttab callback work. */
1097 gnttab_cancel_free_callback(&info
->callback
);
1098 spin_unlock_irq(&info
->io_lock
);
1100 /* Flush gnttab callback work. Must be done with no locks held. */
1101 flush_work(&info
->work
);
1103 /* Free resources associated with old device channel. */
1104 for (i
= 0; i
< info
->nr_ring_pages
; i
++) {
1105 if (info
->ring_ref
[i
] != GRANT_INVALID_REF
) {
1106 gnttab_end_foreign_access(info
->ring_ref
[i
], 0, 0);
1107 info
->ring_ref
[i
] = GRANT_INVALID_REF
;
1110 free_pages((unsigned long)info
->ring
.sring
, get_order(info
->nr_ring_pages
* PAGE_SIZE
));
1111 info
->ring
.sring
= NULL
;
1114 unbind_from_irqhandler(info
->irq
, info
);
1115 info
->evtchn
= info
->irq
= 0;
1119 static void blkif_completion(struct blk_shadow
*s
, struct blkfront_info
*info
,
1120 struct blkif_response
*bret
)
1123 struct scatterlist
*sg
;
1128 nseg
= s
->req
.operation
== BLKIF_OP_INDIRECT
?
1129 s
->req
.u
.indirect
.nr_segments
: s
->req
.u
.rw
.nr_segments
;
1131 if (bret
->operation
== BLKIF_OP_READ
&& info
->feature_persistent
) {
1132 for_each_sg(s
->sg
, sg
, nseg
, i
) {
1133 BUG_ON(sg
->offset
+ sg
->length
> PAGE_SIZE
);
1134 shared_data
= kmap_atomic(s
->grants_used
[i
]->page
);
1135 bvec_data
= kmap_atomic(sg_page(sg
));
1136 memcpy(bvec_data
+ sg
->offset
,
1137 shared_data
+ sg
->offset
,
1139 kunmap_atomic(bvec_data
);
1140 kunmap_atomic(shared_data
);
1143 /* Add the persistent grant into the list of free grants */
1144 for (i
= 0; i
< nseg
; i
++) {
1145 if (gnttab_query_foreign_access(s
->grants_used
[i
]->gref
)) {
1147 * If the grant is still mapped by the backend (the
1148 * backend has chosen to make this grant persistent)
1149 * we add it at the head of the list, so it will be
1152 if (!info
->feature_persistent
)
1153 pr_alert_ratelimited("backed has not unmapped grant: %u\n",
1154 s
->grants_used
[i
]->gref
);
1155 list_add(&s
->grants_used
[i
]->node
, &info
->grants
);
1156 info
->persistent_gnts_c
++;
1159 * If the grant is not mapped by the backend we end the
1160 * foreign access and add it to the tail of the list,
1161 * so it will not be picked again unless we run out of
1162 * persistent grants.
1164 gnttab_end_foreign_access(s
->grants_used
[i
]->gref
, 0, 0UL);
1165 s
->grants_used
[i
]->gref
= GRANT_INVALID_REF
;
1166 list_add_tail(&s
->grants_used
[i
]->node
, &info
->grants
);
1169 if (s
->req
.operation
== BLKIF_OP_INDIRECT
) {
1170 for (i
= 0; i
< INDIRECT_GREFS(nseg
); i
++) {
1171 if (gnttab_query_foreign_access(s
->indirect_grants
[i
]->gref
)) {
1172 if (!info
->feature_persistent
)
1173 pr_alert_ratelimited("backed has not unmapped grant: %u\n",
1174 s
->indirect_grants
[i
]->gref
);
1175 list_add(&s
->indirect_grants
[i
]->node
, &info
->grants
);
1176 info
->persistent_gnts_c
++;
1178 struct page
*indirect_page
;
1180 gnttab_end_foreign_access(s
->indirect_grants
[i
]->gref
, 0, 0UL);
1182 * Add the used indirect page back to the list of
1183 * available pages for indirect grefs.
1185 if (!info
->feature_persistent
) {
1186 indirect_page
= s
->indirect_grants
[i
]->page
;
1187 list_add(&indirect_page
->lru
, &info
->indirect_pages
);
1189 s
->indirect_grants
[i
]->gref
= GRANT_INVALID_REF
;
1190 list_add_tail(&s
->indirect_grants
[i
]->node
, &info
->grants
);
1196 static irqreturn_t
blkif_interrupt(int irq
, void *dev_id
)
1198 struct request
*req
;
1199 struct blkif_response
*bret
;
1201 unsigned long flags
;
1202 struct blkfront_info
*info
= (struct blkfront_info
*)dev_id
;
1205 spin_lock_irqsave(&info
->io_lock
, flags
);
1207 if (unlikely(info
->connected
!= BLKIF_STATE_CONNECTED
)) {
1208 spin_unlock_irqrestore(&info
->io_lock
, flags
);
1213 rp
= info
->ring
.sring
->rsp_prod
;
1214 rmb(); /* Ensure we see queued responses up to 'rp'. */
1216 for (i
= info
->ring
.rsp_cons
; i
!= rp
; i
++) {
1219 bret
= RING_GET_RESPONSE(&info
->ring
, i
);
1222 * The backend has messed up and given us an id that we would
1223 * never have given to it (we stamp it up to BLK_RING_SIZE -
1224 * look in get_id_from_freelist.
1226 if (id
>= BLK_RING_SIZE(info
)) {
1227 WARN(1, "%s: response to %s has incorrect id (%ld)\n",
1228 info
->gd
->disk_name
, op_name(bret
->operation
), id
);
1229 /* We can't safely get the 'struct request' as
1230 * the id is busted. */
1233 req
= info
->shadow
[id
].request
;
1235 if (bret
->operation
!= BLKIF_OP_DISCARD
)
1236 blkif_completion(&info
->shadow
[id
], info
, bret
);
1238 if (add_id_to_freelist(info
, id
)) {
1239 WARN(1, "%s: response to %s (id %ld) couldn't be recycled!\n",
1240 info
->gd
->disk_name
, op_name(bret
->operation
), id
);
1244 error
= (bret
->status
== BLKIF_RSP_OKAY
) ? 0 : -EIO
;
1245 switch (bret
->operation
) {
1246 case BLKIF_OP_DISCARD
:
1247 if (unlikely(bret
->status
== BLKIF_RSP_EOPNOTSUPP
)) {
1248 struct request_queue
*rq
= info
->rq
;
1249 printk(KERN_WARNING
"blkfront: %s: %s op failed\n",
1250 info
->gd
->disk_name
, op_name(bret
->operation
));
1251 error
= -EOPNOTSUPP
;
1252 info
->feature_discard
= 0;
1253 info
->feature_secdiscard
= 0;
1254 queue_flag_clear(QUEUE_FLAG_DISCARD
, rq
);
1255 queue_flag_clear(QUEUE_FLAG_SECDISCARD
, rq
);
1257 blk_mq_complete_request(req
, error
);
1259 case BLKIF_OP_FLUSH_DISKCACHE
:
1260 case BLKIF_OP_WRITE_BARRIER
:
1261 if (unlikely(bret
->status
== BLKIF_RSP_EOPNOTSUPP
)) {
1262 printk(KERN_WARNING
"blkfront: %s: %s op failed\n",
1263 info
->gd
->disk_name
, op_name(bret
->operation
));
1264 error
= -EOPNOTSUPP
;
1266 if (unlikely(bret
->status
== BLKIF_RSP_ERROR
&&
1267 info
->shadow
[id
].req
.u
.rw
.nr_segments
== 0)) {
1268 printk(KERN_WARNING
"blkfront: %s: empty %s op failed\n",
1269 info
->gd
->disk_name
, op_name(bret
->operation
));
1270 error
= -EOPNOTSUPP
;
1272 if (unlikely(error
)) {
1273 if (error
== -EOPNOTSUPP
)
1275 info
->feature_flush
= 0;
1280 case BLKIF_OP_WRITE
:
1281 if (unlikely(bret
->status
!= BLKIF_RSP_OKAY
))
1282 dev_dbg(&info
->xbdev
->dev
, "Bad return from blkdev data "
1283 "request: %x\n", bret
->status
);
1285 blk_mq_complete_request(req
, error
);
1292 info
->ring
.rsp_cons
= i
;
1294 if (i
!= info
->ring
.req_prod_pvt
) {
1296 RING_FINAL_CHECK_FOR_RESPONSES(&info
->ring
, more_to_do
);
1300 info
->ring
.sring
->rsp_event
= i
+ 1;
1302 kick_pending_request_queues(info
);
1304 spin_unlock_irqrestore(&info
->io_lock
, flags
);
1310 static int setup_blkring(struct xenbus_device
*dev
,
1311 struct blkfront_info
*info
)
1313 struct blkif_sring
*sring
;
1315 unsigned long ring_size
= info
->nr_ring_pages
* PAGE_SIZE
;
1316 grant_ref_t gref
[XENBUS_MAX_RING_PAGES
];
1318 for (i
= 0; i
< info
->nr_ring_pages
; i
++)
1319 info
->ring_ref
[i
] = GRANT_INVALID_REF
;
1321 sring
= (struct blkif_sring
*)__get_free_pages(GFP_NOIO
| __GFP_HIGH
,
1322 get_order(ring_size
));
1324 xenbus_dev_fatal(dev
, -ENOMEM
, "allocating shared ring");
1327 SHARED_RING_INIT(sring
);
1328 FRONT_RING_INIT(&info
->ring
, sring
, ring_size
);
1330 err
= xenbus_grant_ring(dev
, info
->ring
.sring
, info
->nr_ring_pages
, gref
);
1332 free_pages((unsigned long)sring
, get_order(ring_size
));
1333 info
->ring
.sring
= NULL
;
1336 for (i
= 0; i
< info
->nr_ring_pages
; i
++)
1337 info
->ring_ref
[i
] = gref
[i
];
1339 err
= xenbus_alloc_evtchn(dev
, &info
->evtchn
);
1343 err
= bind_evtchn_to_irqhandler(info
->evtchn
, blkif_interrupt
, 0,
1346 xenbus_dev_fatal(dev
, err
,
1347 "bind_evtchn_to_irqhandler failed");
1354 blkif_free(info
, 0);
1359 /* Common code used when first setting up, and when resuming. */
1360 static int talk_to_blkback(struct xenbus_device
*dev
,
1361 struct blkfront_info
*info
)
1363 const char *message
= NULL
;
1364 struct xenbus_transaction xbt
;
1366 unsigned int max_page_order
= 0;
1367 unsigned int ring_page_order
= 0;
1369 err
= xenbus_scanf(XBT_NIL
, info
->xbdev
->otherend
,
1370 "max-ring-page-order", "%u", &max_page_order
);
1372 info
->nr_ring_pages
= 1;
1374 ring_page_order
= min(xen_blkif_max_ring_order
, max_page_order
);
1375 info
->nr_ring_pages
= 1 << ring_page_order
;
1378 /* Create shared ring, alloc event channel. */
1379 err
= setup_blkring(dev
, info
);
1384 err
= xenbus_transaction_start(&xbt
);
1386 xenbus_dev_fatal(dev
, err
, "starting transaction");
1387 goto destroy_blkring
;
1390 if (info
->nr_ring_pages
== 1) {
1391 err
= xenbus_printf(xbt
, dev
->nodename
,
1392 "ring-ref", "%u", info
->ring_ref
[0]);
1394 message
= "writing ring-ref";
1395 goto abort_transaction
;
1398 err
= xenbus_printf(xbt
, dev
->nodename
,
1399 "ring-page-order", "%u", ring_page_order
);
1401 message
= "writing ring-page-order";
1402 goto abort_transaction
;
1405 for (i
= 0; i
< info
->nr_ring_pages
; i
++) {
1406 char ring_ref_name
[RINGREF_NAME_LEN
];
1408 snprintf(ring_ref_name
, RINGREF_NAME_LEN
, "ring-ref%u", i
);
1409 err
= xenbus_printf(xbt
, dev
->nodename
, ring_ref_name
,
1410 "%u", info
->ring_ref
[i
]);
1412 message
= "writing ring-ref";
1413 goto abort_transaction
;
1417 err
= xenbus_printf(xbt
, dev
->nodename
,
1418 "event-channel", "%u", info
->evtchn
);
1420 message
= "writing event-channel";
1421 goto abort_transaction
;
1423 err
= xenbus_printf(xbt
, dev
->nodename
, "protocol", "%s",
1424 XEN_IO_PROTO_ABI_NATIVE
);
1426 message
= "writing protocol";
1427 goto abort_transaction
;
1429 err
= xenbus_printf(xbt
, dev
->nodename
,
1430 "feature-persistent", "%u", 1);
1433 "writing persistent grants feature to xenbus");
1435 err
= xenbus_transaction_end(xbt
, 0);
1439 xenbus_dev_fatal(dev
, err
, "completing transaction");
1440 goto destroy_blkring
;
1443 for (i
= 0; i
< BLK_RING_SIZE(info
); i
++)
1444 info
->shadow
[i
].req
.u
.rw
.id
= i
+1;
1445 info
->shadow
[BLK_RING_SIZE(info
)-1].req
.u
.rw
.id
= 0x0fffffff;
1446 xenbus_switch_state(dev
, XenbusStateInitialised
);
1451 xenbus_transaction_end(xbt
, 1);
1453 xenbus_dev_fatal(dev
, err
, "%s", message
);
1455 blkif_free(info
, 0);
1461 * Entry point to this code when a new device is created. Allocate the basic
1462 * structures and the ring buffer for communication with the backend, and
1463 * inform the backend of the appropriate details for those. Switch to
1464 * Initialised state.
1466 static int blkfront_probe(struct xenbus_device
*dev
,
1467 const struct xenbus_device_id
*id
)
1470 struct blkfront_info
*info
;
1472 /* FIXME: Use dynamic device id if this is not set. */
1473 err
= xenbus_scanf(XBT_NIL
, dev
->nodename
,
1474 "virtual-device", "%i", &vdevice
);
1476 /* go looking in the extended area instead */
1477 err
= xenbus_scanf(XBT_NIL
, dev
->nodename
, "virtual-device-ext",
1480 xenbus_dev_fatal(dev
, err
, "reading virtual-device");
1485 if (xen_hvm_domain()) {
1488 /* no unplug has been done: do not hook devices != xen vbds */
1489 if (xen_has_pv_and_legacy_disk_devices()) {
1492 if (!VDEV_IS_EXTENDED(vdevice
))
1493 major
= BLKIF_MAJOR(vdevice
);
1495 major
= XENVBD_MAJOR
;
1497 if (major
!= XENVBD_MAJOR
) {
1499 "%s: HVM does not support vbd %d as xen block device\n",
1504 /* do not create a PV cdrom device if we are an HVM guest */
1505 type
= xenbus_read(XBT_NIL
, dev
->nodename
, "device-type", &len
);
1508 if (strncmp(type
, "cdrom", 5) == 0) {
1514 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
1516 xenbus_dev_fatal(dev
, -ENOMEM
, "allocating info structure");
1520 mutex_init(&info
->mutex
);
1521 spin_lock_init(&info
->io_lock
);
1523 info
->vdevice
= vdevice
;
1524 INIT_LIST_HEAD(&info
->grants
);
1525 INIT_LIST_HEAD(&info
->indirect_pages
);
1526 info
->persistent_gnts_c
= 0;
1527 info
->connected
= BLKIF_STATE_DISCONNECTED
;
1528 INIT_WORK(&info
->work
, blkif_restart_queue
);
1530 /* Front end dir is a number, which is used as the id. */
1531 info
->handle
= simple_strtoul(strrchr(dev
->nodename
, '/')+1, NULL
, 0);
1532 dev_set_drvdata(&dev
->dev
, info
);
1537 static void split_bio_end(struct bio
*bio
)
1539 struct split_bio
*split_bio
= bio
->bi_private
;
1541 if (atomic_dec_and_test(&split_bio
->pending
)) {
1542 split_bio
->bio
->bi_phys_segments
= 0;
1543 split_bio
->bio
->bi_error
= bio
->bi_error
;
1544 bio_endio(split_bio
->bio
);
1550 static int blkif_recover(struct blkfront_info
*info
)
1553 struct request
*req
, *n
;
1554 struct blk_shadow
*copy
;
1556 struct bio
*bio
, *cloned_bio
;
1557 struct bio_list bio_list
, merge_bio
;
1558 unsigned int segs
, offset
;
1560 struct split_bio
*split_bio
;
1561 struct list_head requests
;
1563 /* Stage 1: Make a safe copy of the shadow state. */
1564 copy
= kmemdup(info
->shadow
, sizeof(info
->shadow
),
1565 GFP_NOIO
| __GFP_REPEAT
| __GFP_HIGH
);
1569 /* Stage 2: Set up free list. */
1570 memset(&info
->shadow
, 0, sizeof(info
->shadow
));
1571 for (i
= 0; i
< BLK_RING_SIZE(info
); i
++)
1572 info
->shadow
[i
].req
.u
.rw
.id
= i
+1;
1573 info
->shadow_free
= info
->ring
.req_prod_pvt
;
1574 info
->shadow
[BLK_RING_SIZE(info
)-1].req
.u
.rw
.id
= 0x0fffffff;
1576 rc
= blkfront_gather_backend_features(info
);
1582 segs
= info
->max_indirect_segments
? : BLKIF_MAX_SEGMENTS_PER_REQUEST
;
1583 blk_queue_max_segments(info
->rq
, segs
);
1584 bio_list_init(&bio_list
);
1585 INIT_LIST_HEAD(&requests
);
1586 for (i
= 0; i
< BLK_RING_SIZE(info
); i
++) {
1588 if (!copy
[i
].request
)
1592 * Get the bios in the request so we can re-queue them.
1594 if (copy
[i
].request
->cmd_flags
&
1595 (REQ_FLUSH
| REQ_FUA
| REQ_DISCARD
| REQ_SECURE
)) {
1597 * Flush operations don't contain bios, so
1598 * we need to requeue the whole request
1600 list_add(©
[i
].request
->queuelist
, &requests
);
1603 merge_bio
.head
= copy
[i
].request
->bio
;
1604 merge_bio
.tail
= copy
[i
].request
->biotail
;
1605 bio_list_merge(&bio_list
, &merge_bio
);
1606 copy
[i
].request
->bio
= NULL
;
1607 blk_end_request_all(copy
[i
].request
, 0);
1612 xenbus_switch_state(info
->xbdev
, XenbusStateConnected
);
1614 spin_lock_irq(&info
->io_lock
);
1616 /* Now safe for us to use the shared ring */
1617 info
->connected
= BLKIF_STATE_CONNECTED
;
1619 /* Kick any other new requests queued since we resumed */
1620 kick_pending_request_queues(info
);
1622 list_for_each_entry_safe(req
, n
, &requests
, queuelist
) {
1623 /* Requeue pending requests (flush or discard) */
1624 list_del_init(&req
->queuelist
);
1625 BUG_ON(req
->nr_phys_segments
> segs
);
1626 blk_mq_requeue_request(req
);
1628 spin_unlock_irq(&info
->io_lock
);
1629 blk_mq_kick_requeue_list(info
->rq
);
1631 while ((bio
= bio_list_pop(&bio_list
)) != NULL
) {
1632 /* Traverse the list of pending bios and re-queue them */
1633 if (bio_segments(bio
) > segs
) {
1635 * This bio has more segments than what we can
1636 * handle, we have to split it.
1638 pending
= (bio_segments(bio
) + segs
- 1) / segs
;
1639 split_bio
= kzalloc(sizeof(*split_bio
), GFP_NOIO
);
1640 BUG_ON(split_bio
== NULL
);
1641 atomic_set(&split_bio
->pending
, pending
);
1642 split_bio
->bio
= bio
;
1643 for (i
= 0; i
< pending
; i
++) {
1644 offset
= (i
* segs
* PAGE_SIZE
) >> 9;
1645 size
= min((unsigned int)(segs
* PAGE_SIZE
) >> 9,
1646 (unsigned int)bio_sectors(bio
) - offset
);
1647 cloned_bio
= bio_clone(bio
, GFP_NOIO
);
1648 BUG_ON(cloned_bio
== NULL
);
1649 bio_trim(cloned_bio
, offset
, size
);
1650 cloned_bio
->bi_private
= split_bio
;
1651 cloned_bio
->bi_end_io
= split_bio_end
;
1652 submit_bio(cloned_bio
->bi_rw
, cloned_bio
);
1655 * Now we have to wait for all those smaller bios to
1656 * end, so we can also end the "parent" bio.
1660 /* We don't need to split this bio */
1661 submit_bio(bio
->bi_rw
, bio
);
1668 * We are reconnecting to the backend, due to a suspend/resume, or a backend
1669 * driver restart. We tear down our blkif structure and recreate it, but
1670 * leave the device-layer structures intact so that this is transparent to the
1671 * rest of the kernel.
1673 static int blkfront_resume(struct xenbus_device
*dev
)
1675 struct blkfront_info
*info
= dev_get_drvdata(&dev
->dev
);
1678 dev_dbg(&dev
->dev
, "blkfront_resume: %s\n", dev
->nodename
);
1680 blkif_free(info
, info
->connected
== BLKIF_STATE_CONNECTED
);
1682 err
= talk_to_blkback(dev
, info
);
1685 * We have to wait for the backend to switch to
1686 * connected state, since we want to read which
1687 * features it supports.
1694 blkfront_closing(struct blkfront_info
*info
)
1696 struct xenbus_device
*xbdev
= info
->xbdev
;
1697 struct block_device
*bdev
= NULL
;
1699 mutex_lock(&info
->mutex
);
1701 if (xbdev
->state
== XenbusStateClosing
) {
1702 mutex_unlock(&info
->mutex
);
1707 bdev
= bdget_disk(info
->gd
, 0);
1709 mutex_unlock(&info
->mutex
);
1712 xenbus_frontend_closed(xbdev
);
1716 mutex_lock(&bdev
->bd_mutex
);
1718 if (bdev
->bd_openers
) {
1719 xenbus_dev_error(xbdev
, -EBUSY
,
1720 "Device in use; refusing to close");
1721 xenbus_switch_state(xbdev
, XenbusStateClosing
);
1723 xlvbd_release_gendisk(info
);
1724 xenbus_frontend_closed(xbdev
);
1727 mutex_unlock(&bdev
->bd_mutex
);
1731 static void blkfront_setup_discard(struct blkfront_info
*info
)
1734 unsigned int discard_granularity
;
1735 unsigned int discard_alignment
;
1736 unsigned int discard_secure
;
1738 info
->feature_discard
= 1;
1739 err
= xenbus_gather(XBT_NIL
, info
->xbdev
->otherend
,
1740 "discard-granularity", "%u", &discard_granularity
,
1741 "discard-alignment", "%u", &discard_alignment
,
1744 info
->discard_granularity
= discard_granularity
;
1745 info
->discard_alignment
= discard_alignment
;
1747 err
= xenbus_gather(XBT_NIL
, info
->xbdev
->otherend
,
1748 "discard-secure", "%d", &discard_secure
,
1751 info
->feature_secdiscard
= !!discard_secure
;
1754 static int blkfront_setup_indirect(struct blkfront_info
*info
)
1759 if (info
->max_indirect_segments
== 0)
1760 segs
= BLKIF_MAX_SEGMENTS_PER_REQUEST
;
1762 segs
= info
->max_indirect_segments
;
1764 err
= fill_grant_buffer(info
, (segs
+ INDIRECT_GREFS(segs
)) * BLK_RING_SIZE(info
));
1768 if (!info
->feature_persistent
&& info
->max_indirect_segments
) {
1770 * We are using indirect descriptors but not persistent
1771 * grants, we need to allocate a set of pages that can be
1772 * used for mapping indirect grefs
1774 int num
= INDIRECT_GREFS(segs
) * BLK_RING_SIZE(info
);
1776 BUG_ON(!list_empty(&info
->indirect_pages
));
1777 for (i
= 0; i
< num
; i
++) {
1778 struct page
*indirect_page
= alloc_page(GFP_NOIO
);
1781 list_add(&indirect_page
->lru
, &info
->indirect_pages
);
1785 for (i
= 0; i
< BLK_RING_SIZE(info
); i
++) {
1786 info
->shadow
[i
].grants_used
= kzalloc(
1787 sizeof(info
->shadow
[i
].grants_used
[0]) * segs
,
1789 info
->shadow
[i
].sg
= kzalloc(sizeof(info
->shadow
[i
].sg
[0]) * segs
, GFP_NOIO
);
1790 if (info
->max_indirect_segments
)
1791 info
->shadow
[i
].indirect_grants
= kzalloc(
1792 sizeof(info
->shadow
[i
].indirect_grants
[0]) *
1793 INDIRECT_GREFS(segs
),
1795 if ((info
->shadow
[i
].grants_used
== NULL
) ||
1796 (info
->shadow
[i
].sg
== NULL
) ||
1797 (info
->max_indirect_segments
&&
1798 (info
->shadow
[i
].indirect_grants
== NULL
)))
1800 sg_init_table(info
->shadow
[i
].sg
, segs
);
1807 for (i
= 0; i
< BLK_RING_SIZE(info
); i
++) {
1808 kfree(info
->shadow
[i
].grants_used
);
1809 info
->shadow
[i
].grants_used
= NULL
;
1810 kfree(info
->shadow
[i
].sg
);
1811 info
->shadow
[i
].sg
= NULL
;
1812 kfree(info
->shadow
[i
].indirect_grants
);
1813 info
->shadow
[i
].indirect_grants
= NULL
;
1815 if (!list_empty(&info
->indirect_pages
)) {
1816 struct page
*indirect_page
, *n
;
1817 list_for_each_entry_safe(indirect_page
, n
, &info
->indirect_pages
, lru
) {
1818 list_del(&indirect_page
->lru
);
1819 __free_page(indirect_page
);
1826 * Gather all backend feature-*
1828 static int blkfront_gather_backend_features(struct blkfront_info
*info
)
1831 int barrier
, flush
, discard
, persistent
;
1832 unsigned int indirect_segments
;
1834 info
->feature_flush
= 0;
1836 err
= xenbus_gather(XBT_NIL
, info
->xbdev
->otherend
,
1837 "feature-barrier", "%d", &barrier
,
1841 * If there's no "feature-barrier" defined, then it means
1842 * we're dealing with a very old backend which writes
1843 * synchronously; nothing to do.
1845 * If there are barriers, then we use flush.
1847 if (!err
&& barrier
)
1848 info
->feature_flush
= REQ_FLUSH
| REQ_FUA
;
1850 * And if there is "feature-flush-cache" use that above
1853 err
= xenbus_gather(XBT_NIL
, info
->xbdev
->otherend
,
1854 "feature-flush-cache", "%d", &flush
,
1858 info
->feature_flush
= REQ_FLUSH
;
1860 err
= xenbus_gather(XBT_NIL
, info
->xbdev
->otherend
,
1861 "feature-discard", "%d", &discard
,
1864 if (!err
&& discard
)
1865 blkfront_setup_discard(info
);
1867 err
= xenbus_gather(XBT_NIL
, info
->xbdev
->otherend
,
1868 "feature-persistent", "%u", &persistent
,
1871 info
->feature_persistent
= 0;
1873 info
->feature_persistent
= persistent
;
1875 err
= xenbus_gather(XBT_NIL
, info
->xbdev
->otherend
,
1876 "feature-max-indirect-segments", "%u", &indirect_segments
,
1879 info
->max_indirect_segments
= 0;
1881 info
->max_indirect_segments
= min(indirect_segments
,
1882 xen_blkif_max_segments
);
1884 return blkfront_setup_indirect(info
);
1888 * Invoked when the backend is finally 'ready' (and has told produced
1889 * the details about the physical device - #sectors, size, etc).
1891 static void blkfront_connect(struct blkfront_info
*info
)
1893 unsigned long long sectors
;
1894 unsigned long sector_size
;
1895 unsigned int physical_sector_size
;
1899 switch (info
->connected
) {
1900 case BLKIF_STATE_CONNECTED
:
1902 * Potentially, the back-end may be signalling
1903 * a capacity change; update the capacity.
1905 err
= xenbus_scanf(XBT_NIL
, info
->xbdev
->otherend
,
1906 "sectors", "%Lu", §ors
);
1907 if (XENBUS_EXIST_ERR(err
))
1909 printk(KERN_INFO
"Setting capacity to %Lu\n",
1911 set_capacity(info
->gd
, sectors
);
1912 revalidate_disk(info
->gd
);
1915 case BLKIF_STATE_SUSPENDED
:
1917 * If we are recovering from suspension, we need to wait
1918 * for the backend to announce it's features before
1919 * reconnecting, at least we need to know if the backend
1920 * supports indirect descriptors, and how many.
1922 blkif_recover(info
);
1929 dev_dbg(&info
->xbdev
->dev
, "%s:%s.\n",
1930 __func__
, info
->xbdev
->otherend
);
1932 err
= xenbus_gather(XBT_NIL
, info
->xbdev
->otherend
,
1933 "sectors", "%llu", §ors
,
1934 "info", "%u", &binfo
,
1935 "sector-size", "%lu", §or_size
,
1938 xenbus_dev_fatal(info
->xbdev
, err
,
1939 "reading backend fields at %s",
1940 info
->xbdev
->otherend
);
1945 * physcial-sector-size is a newer field, so old backends may not
1946 * provide this. Assume physical sector size to be the same as
1947 * sector_size in that case.
1949 err
= xenbus_scanf(XBT_NIL
, info
->xbdev
->otherend
,
1950 "physical-sector-size", "%u", &physical_sector_size
);
1952 physical_sector_size
= sector_size
;
1954 err
= blkfront_gather_backend_features(info
);
1956 xenbus_dev_fatal(info
->xbdev
, err
, "setup_indirect at %s",
1957 info
->xbdev
->otherend
);
1961 err
= xlvbd_alloc_gendisk(sectors
, info
, binfo
, sector_size
,
1962 physical_sector_size
);
1964 xenbus_dev_fatal(info
->xbdev
, err
, "xlvbd_add at %s",
1965 info
->xbdev
->otherend
);
1969 xenbus_switch_state(info
->xbdev
, XenbusStateConnected
);
1971 /* Kick pending requests. */
1972 spin_lock_irq(&info
->io_lock
);
1973 info
->connected
= BLKIF_STATE_CONNECTED
;
1974 kick_pending_request_queues(info
);
1975 spin_unlock_irq(&info
->io_lock
);
1983 * Callback received when the backend's state changes.
1985 static void blkback_changed(struct xenbus_device
*dev
,
1986 enum xenbus_state backend_state
)
1988 struct blkfront_info
*info
= dev_get_drvdata(&dev
->dev
);
1990 dev_dbg(&dev
->dev
, "blkfront:blkback_changed to state %d.\n", backend_state
);
1992 switch (backend_state
) {
1993 case XenbusStateInitWait
:
1994 if (dev
->state
!= XenbusStateInitialising
)
1996 if (talk_to_blkback(dev
, info
)) {
1998 dev_set_drvdata(&dev
->dev
, NULL
);
2001 case XenbusStateInitialising
:
2002 case XenbusStateInitialised
:
2003 case XenbusStateReconfiguring
:
2004 case XenbusStateReconfigured
:
2005 case XenbusStateUnknown
:
2008 case XenbusStateConnected
:
2009 blkfront_connect(info
);
2012 case XenbusStateClosed
:
2013 if (dev
->state
== XenbusStateClosed
)
2015 /* Missed the backend's Closing state -- fallthrough */
2016 case XenbusStateClosing
:
2017 blkfront_closing(info
);
2022 static int blkfront_remove(struct xenbus_device
*xbdev
)
2024 struct blkfront_info
*info
= dev_get_drvdata(&xbdev
->dev
);
2025 struct block_device
*bdev
= NULL
;
2026 struct gendisk
*disk
;
2028 dev_dbg(&xbdev
->dev
, "%s removed", xbdev
->nodename
);
2030 blkif_free(info
, 0);
2032 mutex_lock(&info
->mutex
);
2036 bdev
= bdget_disk(disk
, 0);
2039 mutex_unlock(&info
->mutex
);
2047 * The xbdev was removed before we reached the Closed
2048 * state. See if it's safe to remove the disk. If the bdev
2049 * isn't closed yet, we let release take care of it.
2052 mutex_lock(&bdev
->bd_mutex
);
2053 info
= disk
->private_data
;
2055 dev_warn(disk_to_dev(disk
),
2056 "%s was hot-unplugged, %d stale handles\n",
2057 xbdev
->nodename
, bdev
->bd_openers
);
2059 if (info
&& !bdev
->bd_openers
) {
2060 xlvbd_release_gendisk(info
);
2061 disk
->private_data
= NULL
;
2065 mutex_unlock(&bdev
->bd_mutex
);
2071 static int blkfront_is_ready(struct xenbus_device
*dev
)
2073 struct blkfront_info
*info
= dev_get_drvdata(&dev
->dev
);
2075 return info
->is_ready
&& info
->xbdev
;
2078 static int blkif_open(struct block_device
*bdev
, fmode_t mode
)
2080 struct gendisk
*disk
= bdev
->bd_disk
;
2081 struct blkfront_info
*info
;
2084 mutex_lock(&blkfront_mutex
);
2086 info
= disk
->private_data
;
2093 mutex_lock(&info
->mutex
);
2096 /* xbdev is closed */
2099 mutex_unlock(&info
->mutex
);
2102 mutex_unlock(&blkfront_mutex
);
2106 static void blkif_release(struct gendisk
*disk
, fmode_t mode
)
2108 struct blkfront_info
*info
= disk
->private_data
;
2109 struct block_device
*bdev
;
2110 struct xenbus_device
*xbdev
;
2112 mutex_lock(&blkfront_mutex
);
2114 bdev
= bdget_disk(disk
, 0);
2117 WARN(1, "Block device %s yanked out from us!\n", disk
->disk_name
);
2120 if (bdev
->bd_openers
)
2124 * Check if we have been instructed to close. We will have
2125 * deferred this request, because the bdev was still open.
2128 mutex_lock(&info
->mutex
);
2129 xbdev
= info
->xbdev
;
2131 if (xbdev
&& xbdev
->state
== XenbusStateClosing
) {
2132 /* pending switch to state closed */
2133 dev_info(disk_to_dev(bdev
->bd_disk
), "releasing disk\n");
2134 xlvbd_release_gendisk(info
);
2135 xenbus_frontend_closed(info
->xbdev
);
2138 mutex_unlock(&info
->mutex
);
2141 /* sudden device removal */
2142 dev_info(disk_to_dev(bdev
->bd_disk
), "releasing disk\n");
2143 xlvbd_release_gendisk(info
);
2144 disk
->private_data
= NULL
;
2151 mutex_unlock(&blkfront_mutex
);
2154 static const struct block_device_operations xlvbd_block_fops
=
2156 .owner
= THIS_MODULE
,
2158 .release
= blkif_release
,
2159 .getgeo
= blkif_getgeo
,
2160 .ioctl
= blkif_ioctl
,
2164 static const struct xenbus_device_id blkfront_ids
[] = {
2169 static struct xenbus_driver blkfront_driver
= {
2170 .ids
= blkfront_ids
,
2171 .probe
= blkfront_probe
,
2172 .remove
= blkfront_remove
,
2173 .resume
= blkfront_resume
,
2174 .otherend_changed
= blkback_changed
,
2175 .is_ready
= blkfront_is_ready
,
2178 static int __init
xlblk_init(void)
2185 if (xen_blkif_max_ring_order
> XENBUS_MAX_RING_PAGE_ORDER
) {
2186 pr_info("Invalid max_ring_order (%d), will use default max: %d.\n",
2187 xen_blkif_max_ring_order
, XENBUS_MAX_RING_PAGE_ORDER
);
2188 xen_blkif_max_ring_order
= 0;
2191 if (!xen_has_pv_disk_devices())
2194 if (register_blkdev(XENVBD_MAJOR
, DEV_NAME
)) {
2195 printk(KERN_WARNING
"xen_blk: can't get major %d with name %s\n",
2196 XENVBD_MAJOR
, DEV_NAME
);
2200 ret
= xenbus_register_frontend(&blkfront_driver
);
2202 unregister_blkdev(XENVBD_MAJOR
, DEV_NAME
);
2208 module_init(xlblk_init
);
2211 static void __exit
xlblk_exit(void)
2213 xenbus_unregister_driver(&blkfront_driver
);
2214 unregister_blkdev(XENVBD_MAJOR
, DEV_NAME
);
2217 module_exit(xlblk_exit
);
2219 MODULE_DESCRIPTION("Xen virtual block device frontend");
2220 MODULE_LICENSE("GPL");
2221 MODULE_ALIAS_BLOCKDEV_MAJOR(XENVBD_MAJOR
);
2222 MODULE_ALIAS("xen:vbd");
2223 MODULE_ALIAS("xenblk");