2 * xen paravirt block device backend
4 * (c) Gerd Hoffmann <kraxel@redhat.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; under version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, see <http://www.gnu.org/licenses/>.
29 #include <sys/ioctl.h>
30 #include <sys/types.h>
37 #include <xen/io/xenbus.h>
40 #include "block_int.h"
41 #include "qemu-char.h"
42 #include "xen_blkif.h"
43 #include "xen_backend.h"
46 /* ------------------------------------------------------------- */
48 static int syncwrite
= 0;
49 static int batch_maps
= 0;
51 static int max_requests
= 32;
52 static int use_aio
= 1;
54 /* ------------------------------------------------------------- */
56 #define BLOCK_SIZE 512
57 #define IOCB_COUNT (BLKIF_MAX_SEGMENTS_PER_REQUEST + 2)
70 uint32_t domids
[BLKIF_MAX_SEGMENTS_PER_REQUEST
];
71 uint32_t refs
[BLKIF_MAX_SEGMENTS_PER_REQUEST
];
73 void *page
[BLKIF_MAX_SEGMENTS_PER_REQUEST
];
80 struct XenBlkDev
*blkdev
;
81 QLIST_ENTRY(ioreq
) list
;
85 struct XenDevice xendev
; /* must be first */
91 const char *fileproto
;
98 blkif_back_rings_t rings
;
103 QLIST_HEAD(inflight_head
, ioreq
) inflight
;
104 QLIST_HEAD(finished_head
, ioreq
) finished
;
105 QLIST_HEAD(freelist_head
, ioreq
) freelist
;
107 int requests_inflight
;
108 int requests_finished
;
110 /* qemu block driver */
112 BlockDriverState
*bs
;
116 /* ------------------------------------------------------------- */
118 static struct ioreq
*ioreq_start(struct XenBlkDev
*blkdev
)
120 struct ioreq
*ioreq
= NULL
;
122 if (QLIST_EMPTY(&blkdev
->freelist
)) {
123 if (blkdev
->requests_total
>= max_requests
) {
126 /* allocate new struct */
127 ioreq
= qemu_mallocz(sizeof(*ioreq
));
128 ioreq
->blkdev
= blkdev
;
129 blkdev
->requests_total
++;
130 qemu_iovec_init(&ioreq
->v
, BLKIF_MAX_SEGMENTS_PER_REQUEST
);
132 /* get one from freelist */
133 ioreq
= QLIST_FIRST(&blkdev
->freelist
);
134 QLIST_REMOVE(ioreq
, list
);
135 qemu_iovec_reset(&ioreq
->v
);
137 QLIST_INSERT_HEAD(&blkdev
->inflight
, ioreq
, list
);
138 blkdev
->requests_inflight
++;
144 static void ioreq_finish(struct ioreq
*ioreq
)
146 struct XenBlkDev
*blkdev
= ioreq
->blkdev
;
148 QLIST_REMOVE(ioreq
, list
);
149 QLIST_INSERT_HEAD(&blkdev
->finished
, ioreq
, list
);
150 blkdev
->requests_inflight
--;
151 blkdev
->requests_finished
++;
154 static void ioreq_release(struct ioreq
*ioreq
)
156 struct XenBlkDev
*blkdev
= ioreq
->blkdev
;
158 QLIST_REMOVE(ioreq
, list
);
159 memset(ioreq
, 0, sizeof(*ioreq
));
160 ioreq
->blkdev
= blkdev
;
161 QLIST_INSERT_HEAD(&blkdev
->freelist
, ioreq
, list
);
162 blkdev
->requests_finished
--;
166 * translate request into iovec + start offset
167 * do sanity checks along the way
169 static int ioreq_parse(struct ioreq
*ioreq
)
171 struct XenBlkDev
*blkdev
= ioreq
->blkdev
;
176 xen_be_printf(&blkdev
->xendev
, 3,
177 "op %d, nr %d, handle %d, id %" PRId64
", sector %" PRId64
"\n",
178 ioreq
->req
.operation
, ioreq
->req
.nr_segments
,
179 ioreq
->req
.handle
, ioreq
->req
.id
, ioreq
->req
.sector_number
);
180 switch (ioreq
->req
.operation
) {
182 ioreq
->prot
= PROT_WRITE
; /* to memory */
184 case BLKIF_OP_WRITE_BARRIER
:
185 if (!ioreq
->req
.nr_segments
) {
190 ioreq
->presync
= ioreq
->postsync
= 1;
194 ioreq
->prot
= PROT_READ
; /* from memory */
200 xen_be_printf(&blkdev
->xendev
, 0, "error: unknown operation (%d)\n",
201 ioreq
->req
.operation
);
205 if (ioreq
->req
.operation
!= BLKIF_OP_READ
&& blkdev
->mode
[0] != 'w') {
206 xen_be_printf(&blkdev
->xendev
, 0, "error: write req for ro device\n");
210 ioreq
->start
= ioreq
->req
.sector_number
* blkdev
->file_blk
;
211 for (i
= 0; i
< ioreq
->req
.nr_segments
; i
++) {
212 if (i
== BLKIF_MAX_SEGMENTS_PER_REQUEST
) {
213 xen_be_printf(&blkdev
->xendev
, 0, "error: nr_segments too big\n");
216 if (ioreq
->req
.seg
[i
].first_sect
> ioreq
->req
.seg
[i
].last_sect
) {
217 xen_be_printf(&blkdev
->xendev
, 0, "error: first > last sector\n");
220 if (ioreq
->req
.seg
[i
].last_sect
* BLOCK_SIZE
>= XC_PAGE_SIZE
) {
221 xen_be_printf(&blkdev
->xendev
, 0, "error: page crossing\n");
225 ioreq
->domids
[i
] = blkdev
->xendev
.dom
;
226 ioreq
->refs
[i
] = ioreq
->req
.seg
[i
].gref
;
228 mem
= ioreq
->req
.seg
[i
].first_sect
* blkdev
->file_blk
;
229 len
= (ioreq
->req
.seg
[i
].last_sect
- ioreq
->req
.seg
[i
].first_sect
+ 1) * blkdev
->file_blk
;
230 qemu_iovec_add(&ioreq
->v
, (void*)mem
, len
);
232 if (ioreq
->start
+ ioreq
->v
.size
> blkdev
->file_size
) {
233 xen_be_printf(&blkdev
->xendev
, 0, "error: access beyond end of file\n");
239 ioreq
->status
= BLKIF_RSP_ERROR
;
243 static void ioreq_unmap(struct ioreq
*ioreq
)
245 XenGnttab gnt
= ioreq
->blkdev
->xendev
.gnttabdev
;
248 if (ioreq
->v
.niov
== 0) {
255 if (xc_gnttab_munmap(gnt
, ioreq
->pages
, ioreq
->v
.niov
) != 0) {
256 xen_be_printf(&ioreq
->blkdev
->xendev
, 0, "xc_gnttab_munmap failed: %s\n",
259 ioreq
->blkdev
->cnt_map
-= ioreq
->v
.niov
;
262 for (i
= 0; i
< ioreq
->v
.niov
; i
++) {
263 if (!ioreq
->page
[i
]) {
266 if (xc_gnttab_munmap(gnt
, ioreq
->page
[i
], 1) != 0) {
267 xen_be_printf(&ioreq
->blkdev
->xendev
, 0, "xc_gnttab_munmap failed: %s\n",
270 ioreq
->blkdev
->cnt_map
--;
271 ioreq
->page
[i
] = NULL
;
276 static int ioreq_map(struct ioreq
*ioreq
)
278 XenGnttab gnt
= ioreq
->blkdev
->xendev
.gnttabdev
;
281 if (ioreq
->v
.niov
== 0) {
285 ioreq
->pages
= xc_gnttab_map_grant_refs
286 (gnt
, ioreq
->v
.niov
, ioreq
->domids
, ioreq
->refs
, ioreq
->prot
);
287 if (ioreq
->pages
== NULL
) {
288 xen_be_printf(&ioreq
->blkdev
->xendev
, 0,
289 "can't map %d grant refs (%s, %d maps)\n",
290 ioreq
->v
.niov
, strerror(errno
), ioreq
->blkdev
->cnt_map
);
293 for (i
= 0; i
< ioreq
->v
.niov
; i
++) {
294 ioreq
->v
.iov
[i
].iov_base
= ioreq
->pages
+ i
* XC_PAGE_SIZE
+
295 (uintptr_t)ioreq
->v
.iov
[i
].iov_base
;
297 ioreq
->blkdev
->cnt_map
+= ioreq
->v
.niov
;
299 for (i
= 0; i
< ioreq
->v
.niov
; i
++) {
300 ioreq
->page
[i
] = xc_gnttab_map_grant_ref
301 (gnt
, ioreq
->domids
[i
], ioreq
->refs
[i
], ioreq
->prot
);
302 if (ioreq
->page
[i
] == NULL
) {
303 xen_be_printf(&ioreq
->blkdev
->xendev
, 0,
304 "can't map grant ref %d (%s, %d maps)\n",
305 ioreq
->refs
[i
], strerror(errno
), ioreq
->blkdev
->cnt_map
);
309 ioreq
->v
.iov
[i
].iov_base
= ioreq
->page
[i
] + (uintptr_t)ioreq
->v
.iov
[i
].iov_base
;
310 ioreq
->blkdev
->cnt_map
++;
316 static int ioreq_runio_qemu_sync(struct ioreq
*ioreq
)
318 struct XenBlkDev
*blkdev
= ioreq
->blkdev
;
322 if (ioreq
->req
.nr_segments
&& ioreq_map(ioreq
) == -1) {
325 if (ioreq
->presync
) {
326 bdrv_flush(blkdev
->bs
);
329 switch (ioreq
->req
.operation
) {
332 for (i
= 0; i
< ioreq
->v
.niov
; i
++) {
333 rc
= bdrv_read(blkdev
->bs
, pos
/ BLOCK_SIZE
,
334 ioreq
->v
.iov
[i
].iov_base
,
335 ioreq
->v
.iov
[i
].iov_len
/ BLOCK_SIZE
);
337 xen_be_printf(&blkdev
->xendev
, 0, "rd I/O error (%p, len %zd)\n",
338 ioreq
->v
.iov
[i
].iov_base
,
339 ioreq
->v
.iov
[i
].iov_len
);
342 len
+= ioreq
->v
.iov
[i
].iov_len
;
343 pos
+= ioreq
->v
.iov
[i
].iov_len
;
347 case BLKIF_OP_WRITE_BARRIER
:
348 if (!ioreq
->req
.nr_segments
) {
352 for (i
= 0; i
< ioreq
->v
.niov
; i
++) {
353 rc
= bdrv_write(blkdev
->bs
, pos
/ BLOCK_SIZE
,
354 ioreq
->v
.iov
[i
].iov_base
,
355 ioreq
->v
.iov
[i
].iov_len
/ BLOCK_SIZE
);
357 xen_be_printf(&blkdev
->xendev
, 0, "wr I/O error (%p, len %zd)\n",
358 ioreq
->v
.iov
[i
].iov_base
,
359 ioreq
->v
.iov
[i
].iov_len
);
362 len
+= ioreq
->v
.iov
[i
].iov_len
;
363 pos
+= ioreq
->v
.iov
[i
].iov_len
;
367 /* unknown operation (shouldn't happen -- parse catches this) */
371 if (ioreq
->postsync
) {
372 bdrv_flush(blkdev
->bs
);
374 ioreq
->status
= BLKIF_RSP_OKAY
;
384 ioreq
->status
= BLKIF_RSP_ERROR
;
388 static void qemu_aio_complete(void *opaque
, int ret
)
390 struct ioreq
*ioreq
= opaque
;
393 xen_be_printf(&ioreq
->blkdev
->xendev
, 0, "%s I/O error\n",
394 ioreq
->req
.operation
== BLKIF_OP_READ
? "read" : "write");
398 ioreq
->aio_inflight
--;
399 if (ioreq
->aio_inflight
> 0) {
403 ioreq
->status
= ioreq
->aio_errors
? BLKIF_RSP_ERROR
: BLKIF_RSP_OKAY
;
406 qemu_bh_schedule(ioreq
->blkdev
->bh
);
409 static int ioreq_runio_qemu_aio(struct ioreq
*ioreq
)
411 struct XenBlkDev
*blkdev
= ioreq
->blkdev
;
413 if (ioreq
->req
.nr_segments
&& ioreq_map(ioreq
) == -1) {
417 ioreq
->aio_inflight
++;
418 if (ioreq
->presync
) {
419 bdrv_flush(blkdev
->bs
); /* FIXME: aio_flush() ??? */
422 switch (ioreq
->req
.operation
) {
424 ioreq
->aio_inflight
++;
425 bdrv_aio_readv(blkdev
->bs
, ioreq
->start
/ BLOCK_SIZE
,
426 &ioreq
->v
, ioreq
->v
.size
/ BLOCK_SIZE
,
427 qemu_aio_complete
, ioreq
);
430 case BLKIF_OP_WRITE_BARRIER
:
431 if (!ioreq
->req
.nr_segments
) {
434 ioreq
->aio_inflight
++;
435 bdrv_aio_writev(blkdev
->bs
, ioreq
->start
/ BLOCK_SIZE
,
436 &ioreq
->v
, ioreq
->v
.size
/ BLOCK_SIZE
,
437 qemu_aio_complete
, ioreq
);
440 /* unknown operation (shouldn't happen -- parse catches this) */
444 if (ioreq
->postsync
) {
445 bdrv_flush(blkdev
->bs
); /* FIXME: aio_flush() ??? */
447 qemu_aio_complete(ioreq
, 0);
455 ioreq
->status
= BLKIF_RSP_ERROR
;
459 static int blk_send_response_one(struct ioreq
*ioreq
)
461 struct XenBlkDev
*blkdev
= ioreq
->blkdev
;
463 int have_requests
= 0;
464 blkif_response_t resp
;
467 resp
.id
= ioreq
->req
.id
;
468 resp
.operation
= ioreq
->req
.operation
;
469 resp
.status
= ioreq
->status
;
471 /* Place on the response ring for the relevant domain. */
472 switch (blkdev
->protocol
) {
473 case BLKIF_PROTOCOL_NATIVE
:
474 dst
= RING_GET_RESPONSE(&blkdev
->rings
.native
, blkdev
->rings
.native
.rsp_prod_pvt
);
476 case BLKIF_PROTOCOL_X86_32
:
477 dst
= RING_GET_RESPONSE(&blkdev
->rings
.x86_32_part
,
478 blkdev
->rings
.x86_32_part
.rsp_prod_pvt
);
480 case BLKIF_PROTOCOL_X86_64
:
481 dst
= RING_GET_RESPONSE(&blkdev
->rings
.x86_64_part
,
482 blkdev
->rings
.x86_64_part
.rsp_prod_pvt
);
487 memcpy(dst
, &resp
, sizeof(resp
));
488 blkdev
->rings
.common
.rsp_prod_pvt
++;
490 RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&blkdev
->rings
.common
, send_notify
);
491 if (blkdev
->rings
.common
.rsp_prod_pvt
== blkdev
->rings
.common
.req_cons
) {
493 * Tail check for pending requests. Allows frontend to avoid
494 * notifications if requests are already in flight (lower
495 * overheads and promotes batching).
497 RING_FINAL_CHECK_FOR_REQUESTS(&blkdev
->rings
.common
, have_requests
);
498 } else if (RING_HAS_UNCONSUMED_REQUESTS(&blkdev
->rings
.common
)) {
508 /* walk finished list, send outstanding responses, free requests */
509 static void blk_send_response_all(struct XenBlkDev
*blkdev
)
514 while (!QLIST_EMPTY(&blkdev
->finished
)) {
515 ioreq
= QLIST_FIRST(&blkdev
->finished
);
516 send_notify
+= blk_send_response_one(ioreq
);
517 ioreq_release(ioreq
);
520 xen_be_send_notify(&blkdev
->xendev
);
524 static int blk_get_request(struct XenBlkDev
*blkdev
, struct ioreq
*ioreq
, RING_IDX rc
)
526 switch (blkdev
->protocol
) {
527 case BLKIF_PROTOCOL_NATIVE
:
528 memcpy(&ioreq
->req
, RING_GET_REQUEST(&blkdev
->rings
.native
, rc
),
531 case BLKIF_PROTOCOL_X86_32
:
532 blkif_get_x86_32_req(&ioreq
->req
,
533 RING_GET_REQUEST(&blkdev
->rings
.x86_32_part
, rc
));
535 case BLKIF_PROTOCOL_X86_64
:
536 blkif_get_x86_64_req(&ioreq
->req
,
537 RING_GET_REQUEST(&blkdev
->rings
.x86_64_part
, rc
));
543 static void blk_handle_requests(struct XenBlkDev
*blkdev
)
548 blkdev
->more_work
= 0;
550 rc
= blkdev
->rings
.common
.req_cons
;
551 rp
= blkdev
->rings
.common
.sring
->req_prod
;
552 xen_rmb(); /* Ensure we see queued requests up to 'rp'. */
555 blk_send_response_all(blkdev
);
558 /* pull request from ring */
559 if (RING_REQUEST_CONS_OVERFLOW(&blkdev
->rings
.common
, rc
)) {
562 ioreq
= ioreq_start(blkdev
);
567 blk_get_request(blkdev
, ioreq
, rc
);
568 blkdev
->rings
.common
.req_cons
= ++rc
;
571 if (ioreq_parse(ioreq
) != 0) {
572 if (blk_send_response_one(ioreq
)) {
573 xen_be_send_notify(&blkdev
->xendev
);
575 ioreq_release(ioreq
);
580 /* run i/o in aio mode */
581 ioreq_runio_qemu_aio(ioreq
);
583 /* run i/o in sync mode */
584 ioreq_runio_qemu_sync(ioreq
);
588 blk_send_response_all(blkdev
);
591 if (blkdev
->more_work
&& blkdev
->requests_inflight
< max_requests
) {
592 qemu_bh_schedule(blkdev
->bh
);
596 /* ------------------------------------------------------------- */
598 static void blk_bh(void *opaque
)
600 struct XenBlkDev
*blkdev
= opaque
;
601 blk_handle_requests(blkdev
);
604 static void blk_alloc(struct XenDevice
*xendev
)
606 struct XenBlkDev
*blkdev
= container_of(xendev
, struct XenBlkDev
, xendev
);
608 QLIST_INIT(&blkdev
->inflight
);
609 QLIST_INIT(&blkdev
->finished
);
610 QLIST_INIT(&blkdev
->freelist
);
611 blkdev
->bh
= qemu_bh_new(blk_bh
, blkdev
);
612 if (xen_mode
!= XEN_EMULATE
) {
617 static int blk_init(struct XenDevice
*xendev
)
619 struct XenBlkDev
*blkdev
= container_of(xendev
, struct XenBlkDev
, xendev
);
620 int index
, qflags
, have_barriers
, info
= 0;
623 /* read xenstore entries */
624 if (blkdev
->params
== NULL
) {
625 blkdev
->params
= xenstore_read_be_str(&blkdev
->xendev
, "params");
626 h
= strchr(blkdev
->params
, ':');
628 blkdev
->fileproto
= blkdev
->params
;
629 blkdev
->filename
= h
+1;
632 blkdev
->fileproto
= "<unset>";
633 blkdev
->filename
= blkdev
->params
;
636 if (blkdev
->mode
== NULL
) {
637 blkdev
->mode
= xenstore_read_be_str(&blkdev
->xendev
, "mode");
639 if (blkdev
->type
== NULL
) {
640 blkdev
->type
= xenstore_read_be_str(&blkdev
->xendev
, "type");
642 if (blkdev
->dev
== NULL
) {
643 blkdev
->dev
= xenstore_read_be_str(&blkdev
->xendev
, "dev");
645 if (blkdev
->devtype
== NULL
) {
646 blkdev
->devtype
= xenstore_read_be_str(&blkdev
->xendev
, "device-type");
649 /* do we have all we need? */
650 if (blkdev
->params
== NULL
||
651 blkdev
->mode
== NULL
||
652 blkdev
->type
== NULL
||
653 blkdev
->dev
== NULL
) {
658 if (strcmp(blkdev
->mode
, "w") == 0) {
659 qflags
= BDRV_O_RDWR
;
662 info
|= VDISK_READONLY
;
666 if (blkdev
->devtype
&& !strcmp(blkdev
->devtype
, "cdrom")) {
670 /* init qemu block driver */
671 index
= (blkdev
->xendev
.dev
- 202 * 256) / 16;
672 blkdev
->dinfo
= drive_get(IF_XEN
, 0, index
);
673 if (!blkdev
->dinfo
) {
674 /* setup via xenbus -> create new block driver instance */
675 xen_be_printf(&blkdev
->xendev
, 2, "create new bdrv (xenbus setup)\n");
676 blkdev
->bs
= bdrv_new(blkdev
->dev
);
677 if (bdrv_open(blkdev
->bs
, blkdev
->filename
, qflags
,
678 bdrv_find_whitelisted_format(blkdev
->fileproto
)) != 0) {
679 bdrv_delete(blkdev
->bs
);
683 /* setup via qemu cmdline -> already setup for us */
684 xen_be_printf(&blkdev
->xendev
, 2, "get configured bdrv (cmdline setup)\n");
685 blkdev
->bs
= blkdev
->dinfo
->bdrv
;
687 blkdev
->file_blk
= BLOCK_SIZE
;
688 blkdev
->file_size
= bdrv_getlength(blkdev
->bs
);
689 if (blkdev
->file_size
< 0) {
690 xen_be_printf(&blkdev
->xendev
, 1, "bdrv_getlength: %d (%s) | drv %s\n",
691 (int)blkdev
->file_size
, strerror(-blkdev
->file_size
),
692 blkdev
->bs
->drv
? blkdev
->bs
->drv
->format_name
: "-");
693 blkdev
->file_size
= 0;
695 have_barriers
= blkdev
->bs
->drv
&& blkdev
->bs
->drv
->bdrv_flush
? 1 : 0;
697 xen_be_printf(xendev
, 1, "type \"%s\", fileproto \"%s\", filename \"%s\","
698 " size %" PRId64
" (%" PRId64
" MB)\n",
699 blkdev
->type
, blkdev
->fileproto
, blkdev
->filename
,
700 blkdev
->file_size
, blkdev
->file_size
>> 20);
703 xenstore_write_be_int(&blkdev
->xendev
, "feature-barrier", have_barriers
);
704 xenstore_write_be_int(&blkdev
->xendev
, "info", info
);
705 xenstore_write_be_int(&blkdev
->xendev
, "sector-size", blkdev
->file_blk
);
706 xenstore_write_be_int(&blkdev
->xendev
, "sectors",
707 blkdev
->file_size
/ blkdev
->file_blk
);
711 static int blk_connect(struct XenDevice
*xendev
)
713 struct XenBlkDev
*blkdev
= container_of(xendev
, struct XenBlkDev
, xendev
);
715 if (xenstore_read_fe_int(&blkdev
->xendev
, "ring-ref", &blkdev
->ring_ref
) == -1) {
718 if (xenstore_read_fe_int(&blkdev
->xendev
, "event-channel",
719 &blkdev
->xendev
.remote_port
) == -1) {
723 blkdev
->protocol
= BLKIF_PROTOCOL_NATIVE
;
724 if (blkdev
->xendev
.protocol
) {
725 if (strcmp(blkdev
->xendev
.protocol
, XEN_IO_PROTO_ABI_X86_32
) == 0) {
726 blkdev
->protocol
= BLKIF_PROTOCOL_X86_32
;
728 if (strcmp(blkdev
->xendev
.protocol
, XEN_IO_PROTO_ABI_X86_64
) == 0) {
729 blkdev
->protocol
= BLKIF_PROTOCOL_X86_64
;
733 blkdev
->sring
= xc_gnttab_map_grant_ref(blkdev
->xendev
.gnttabdev
,
736 PROT_READ
| PROT_WRITE
);
737 if (!blkdev
->sring
) {
742 switch (blkdev
->protocol
) {
743 case BLKIF_PROTOCOL_NATIVE
:
745 blkif_sring_t
*sring_native
= blkdev
->sring
;
746 BACK_RING_INIT(&blkdev
->rings
.native
, sring_native
, XC_PAGE_SIZE
);
749 case BLKIF_PROTOCOL_X86_32
:
751 blkif_x86_32_sring_t
*sring_x86_32
= blkdev
->sring
;
753 BACK_RING_INIT(&blkdev
->rings
.x86_32_part
, sring_x86_32
, XC_PAGE_SIZE
);
756 case BLKIF_PROTOCOL_X86_64
:
758 blkif_x86_64_sring_t
*sring_x86_64
= blkdev
->sring
;
760 BACK_RING_INIT(&blkdev
->rings
.x86_64_part
, sring_x86_64
, XC_PAGE_SIZE
);
765 xen_be_bind_evtchn(&blkdev
->xendev
);
767 xen_be_printf(&blkdev
->xendev
, 1, "ok: proto %s, ring-ref %d, "
768 "remote port %d, local port %d\n",
769 blkdev
->xendev
.protocol
, blkdev
->ring_ref
,
770 blkdev
->xendev
.remote_port
, blkdev
->xendev
.local_port
);
774 static void blk_disconnect(struct XenDevice
*xendev
)
776 struct XenBlkDev
*blkdev
= container_of(xendev
, struct XenBlkDev
, xendev
);
779 if (!blkdev
->dinfo
) {
780 /* close/delete only if we created it ourself */
781 bdrv_close(blkdev
->bs
);
782 bdrv_delete(blkdev
->bs
);
786 xen_be_unbind_evtchn(&blkdev
->xendev
);
789 xc_gnttab_munmap(blkdev
->xendev
.gnttabdev
, blkdev
->sring
, 1);
791 blkdev
->sring
= NULL
;
795 static int blk_free(struct XenDevice
*xendev
)
797 struct XenBlkDev
*blkdev
= container_of(xendev
, struct XenBlkDev
, xendev
);
800 while (!QLIST_EMPTY(&blkdev
->freelist
)) {
801 ioreq
= QLIST_FIRST(&blkdev
->freelist
);
802 QLIST_REMOVE(ioreq
, list
);
803 qemu_iovec_destroy(&ioreq
->v
);
807 qemu_free(blkdev
->params
);
808 qemu_free(blkdev
->mode
);
809 qemu_free(blkdev
->type
);
810 qemu_free(blkdev
->dev
);
811 qemu_free(blkdev
->devtype
);
812 qemu_bh_delete(blkdev
->bh
);
816 static void blk_event(struct XenDevice
*xendev
)
818 struct XenBlkDev
*blkdev
= container_of(xendev
, struct XenBlkDev
, xendev
);
820 qemu_bh_schedule(blkdev
->bh
);
823 struct XenDevOps xen_blkdev_ops
= {
824 .size
= sizeof(struct XenBlkDev
),
825 .flags
= DEVOPS_FLAG_NEED_GNTDEV
,
828 .connect
= blk_connect
,
829 .disconnect
= blk_disconnect
,