2009-04-22 19:19:30 +04:00
|
|
|
/*
|
|
|
|
* xen paravirt block device backend
|
|
|
|
*
|
|
|
|
* (c) Gerd Hoffmann <kraxel@redhat.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; under version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
2009-07-17 00:47:01 +04:00
|
|
|
* with this program; if not, see <http://www.gnu.org/licenses/>.
|
2012-01-13 20:44:23 +04:00
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2009-04-22 19:19:30 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/uio.h>
|
|
|
|
|
|
|
|
#include <xs.h>
|
|
|
|
#include <xenctrl.h>
|
|
|
|
#include <xen/io/xenbus.h>
|
|
|
|
|
|
|
|
#include "hw.h"
|
|
|
|
#include "block_int.h"
|
|
|
|
#include "qemu-char.h"
|
|
|
|
#include "xen_blkif.h"
|
|
|
|
#include "xen_backend.h"
|
2010-08-24 19:22:24 +04:00
|
|
|
#include "blockdev.h"
|
2009-04-22 19:19:30 +04:00
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int syncwrite = 0;
|
|
|
|
static int batch_maps = 0;
|
|
|
|
|
|
|
|
static int max_requests = 32;
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
#define BLOCK_SIZE 512
|
|
|
|
#define IOCB_COUNT (BLKIF_MAX_SEGMENTS_PER_REQUEST + 2)
|
|
|
|
|
|
|
|
struct ioreq {
|
|
|
|
blkif_request_t req;
|
|
|
|
int16_t status;
|
|
|
|
|
|
|
|
/* parsed request */
|
|
|
|
off_t start;
|
|
|
|
QEMUIOVector v;
|
|
|
|
int presync;
|
|
|
|
int postsync;
|
|
|
|
|
|
|
|
/* grant mapping */
|
|
|
|
uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
|
|
|
uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
|
|
|
int prot;
|
|
|
|
void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
|
|
|
void *pages;
|
|
|
|
|
|
|
|
/* aio status */
|
|
|
|
int aio_inflight;
|
|
|
|
int aio_errors;
|
|
|
|
|
|
|
|
struct XenBlkDev *blkdev;
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_ENTRY(ioreq) list;
|
2011-08-25 10:26:01 +04:00
|
|
|
BlockAcctCookie acct;
|
2009-04-22 19:19:30 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct XenBlkDev {
|
|
|
|
struct XenDevice xendev; /* must be first */
|
|
|
|
char *params;
|
|
|
|
char *mode;
|
|
|
|
char *type;
|
|
|
|
char *dev;
|
|
|
|
char *devtype;
|
|
|
|
const char *fileproto;
|
|
|
|
const char *filename;
|
|
|
|
int ring_ref;
|
|
|
|
void *sring;
|
|
|
|
int64_t file_blk;
|
|
|
|
int64_t file_size;
|
|
|
|
int protocol;
|
|
|
|
blkif_back_rings_t rings;
|
|
|
|
int more_work;
|
|
|
|
int cnt_map;
|
|
|
|
|
|
|
|
/* request lists */
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_HEAD(inflight_head, ioreq) inflight;
|
|
|
|
QLIST_HEAD(finished_head, ioreq) finished;
|
|
|
|
QLIST_HEAD(freelist_head, ioreq) freelist;
|
2009-04-22 19:19:30 +04:00
|
|
|
int requests_total;
|
|
|
|
int requests_inflight;
|
|
|
|
int requests_finished;
|
|
|
|
|
|
|
|
/* qemu block driver */
|
2009-07-22 18:42:57 +04:00
|
|
|
DriveInfo *dinfo;
|
2009-04-22 19:19:30 +04:00
|
|
|
BlockDriverState *bs;
|
|
|
|
QEMUBH *bh;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static struct ioreq *ioreq_start(struct XenBlkDev *blkdev)
|
|
|
|
{
|
|
|
|
struct ioreq *ioreq = NULL;
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
if (QLIST_EMPTY(&blkdev->freelist)) {
|
2010-09-23 15:28:45 +04:00
|
|
|
if (blkdev->requests_total >= max_requests) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
/* allocate new struct */
|
2011-08-21 07:09:37 +04:00
|
|
|
ioreq = g_malloc0(sizeof(*ioreq));
|
2010-09-23 15:28:45 +04:00
|
|
|
ioreq->blkdev = blkdev;
|
|
|
|
blkdev->requests_total++;
|
2009-04-22 19:19:30 +04:00
|
|
|
qemu_iovec_init(&ioreq->v, BLKIF_MAX_SEGMENTS_PER_REQUEST);
|
|
|
|
} else {
|
2010-09-23 15:28:45 +04:00
|
|
|
/* get one from freelist */
|
|
|
|
ioreq = QLIST_FIRST(&blkdev->freelist);
|
|
|
|
QLIST_REMOVE(ioreq, list);
|
2009-04-22 19:19:30 +04:00
|
|
|
qemu_iovec_reset(&ioreq->v);
|
|
|
|
}
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_INSERT_HEAD(&blkdev->inflight, ioreq, list);
|
2009-04-22 19:19:30 +04:00
|
|
|
blkdev->requests_inflight++;
|
|
|
|
|
|
|
|
out:
|
|
|
|
return ioreq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ioreq_finish(struct ioreq *ioreq)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = ioreq->blkdev;
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_REMOVE(ioreq, list);
|
|
|
|
QLIST_INSERT_HEAD(&blkdev->finished, ioreq, list);
|
2009-04-22 19:19:30 +04:00
|
|
|
blkdev->requests_inflight--;
|
|
|
|
blkdev->requests_finished++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ioreq_release(struct ioreq *ioreq)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = ioreq->blkdev;
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_REMOVE(ioreq, list);
|
2009-04-22 19:19:30 +04:00
|
|
|
memset(ioreq, 0, sizeof(*ioreq));
|
|
|
|
ioreq->blkdev = blkdev;
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_INSERT_HEAD(&blkdev->freelist, ioreq, list);
|
2009-04-22 19:19:30 +04:00
|
|
|
blkdev->requests_finished--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* translate request into iovec + start offset
|
|
|
|
* do sanity checks along the way
|
|
|
|
*/
|
|
|
|
static int ioreq_parse(struct ioreq *ioreq)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = ioreq->blkdev;
|
|
|
|
uintptr_t mem;
|
|
|
|
size_t len;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
xen_be_printf(&blkdev->xendev, 3,
|
2010-09-23 15:28:45 +04:00
|
|
|
"op %d, nr %d, handle %d, id %" PRId64 ", sector %" PRId64 "\n",
|
|
|
|
ioreq->req.operation, ioreq->req.nr_segments,
|
|
|
|
ioreq->req.handle, ioreq->req.id, ioreq->req.sector_number);
|
2009-04-22 19:19:30 +04:00
|
|
|
switch (ioreq->req.operation) {
|
|
|
|
case BLKIF_OP_READ:
|
2010-09-23 15:28:45 +04:00
|
|
|
ioreq->prot = PROT_WRITE; /* to memory */
|
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
case BLKIF_OP_WRITE_BARRIER:
|
2010-11-24 16:08:03 +03:00
|
|
|
if (!ioreq->req.nr_segments) {
|
|
|
|
ioreq->presync = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-09-23 15:28:45 +04:00
|
|
|
if (!syncwrite) {
|
|
|
|
ioreq->presync = ioreq->postsync = 1;
|
|
|
|
}
|
|
|
|
/* fall through */
|
2009-04-22 19:19:30 +04:00
|
|
|
case BLKIF_OP_WRITE:
|
2010-09-23 15:28:45 +04:00
|
|
|
ioreq->prot = PROT_READ; /* from memory */
|
|
|
|
if (syncwrite) {
|
|
|
|
ioreq->postsync = 1;
|
|
|
|
}
|
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
default:
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(&blkdev->xendev, 0, "error: unknown operation (%d)\n",
|
|
|
|
ioreq->req.operation);
|
|
|
|
goto err;
|
2009-04-22 19:19:30 +04:00
|
|
|
};
|
|
|
|
|
2009-06-11 13:32:48 +04:00
|
|
|
if (ioreq->req.operation != BLKIF_OP_READ && blkdev->mode[0] != 'w') {
|
|
|
|
xen_be_printf(&blkdev->xendev, 0, "error: write req for ro device\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2009-04-22 19:19:30 +04:00
|
|
|
ioreq->start = ioreq->req.sector_number * blkdev->file_blk;
|
|
|
|
for (i = 0; i < ioreq->req.nr_segments; i++) {
|
2010-09-23 15:28:45 +04:00
|
|
|
if (i == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
|
|
|
|
xen_be_printf(&blkdev->xendev, 0, "error: nr_segments too big\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (ioreq->req.seg[i].first_sect > ioreq->req.seg[i].last_sect) {
|
|
|
|
xen_be_printf(&blkdev->xendev, 0, "error: first > last sector\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
if (ioreq->req.seg[i].last_sect * BLOCK_SIZE >= XC_PAGE_SIZE) {
|
|
|
|
xen_be_printf(&blkdev->xendev, 0, "error: page crossing\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
ioreq->domids[i] = blkdev->xendev.dom;
|
|
|
|
ioreq->refs[i] = ioreq->req.seg[i].gref;
|
|
|
|
|
|
|
|
mem = ioreq->req.seg[i].first_sect * blkdev->file_blk;
|
|
|
|
len = (ioreq->req.seg[i].last_sect - ioreq->req.seg[i].first_sect + 1) * blkdev->file_blk;
|
2009-04-22 19:19:30 +04:00
|
|
|
qemu_iovec_add(&ioreq->v, (void*)mem, len);
|
|
|
|
}
|
|
|
|
if (ioreq->start + ioreq->v.size > blkdev->file_size) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xen_be_printf(&blkdev->xendev, 0, "error: access beyond end of file\n");
|
|
|
|
goto err;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
ioreq->status = BLKIF_RSP_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ioreq_unmap(struct ioreq *ioreq)
|
|
|
|
{
|
2011-02-25 19:20:34 +03:00
|
|
|
XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
|
2009-04-22 19:19:30 +04:00
|
|
|
int i;
|
|
|
|
|
2010-09-23 15:28:45 +04:00
|
|
|
if (ioreq->v.niov == 0) {
|
2009-04-22 19:19:30 +04:00
|
|
|
return;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
if (batch_maps) {
|
2010-09-23 15:28:45 +04:00
|
|
|
if (!ioreq->pages) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (xc_gnttab_munmap(gnt, ioreq->pages, ioreq->v.niov) != 0) {
|
|
|
|
xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
}
|
|
|
|
ioreq->blkdev->cnt_map -= ioreq->v.niov;
|
|
|
|
ioreq->pages = NULL;
|
2009-04-22 19:19:30 +04:00
|
|
|
} else {
|
2010-09-23 15:28:45 +04:00
|
|
|
for (i = 0; i < ioreq->v.niov; i++) {
|
|
|
|
if (!ioreq->page[i]) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (xc_gnttab_munmap(gnt, ioreq->page[i], 1) != 0) {
|
|
|
|
xen_be_printf(&ioreq->blkdev->xendev, 0, "xc_gnttab_munmap failed: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
}
|
|
|
|
ioreq->blkdev->cnt_map--;
|
|
|
|
ioreq->page[i] = NULL;
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ioreq_map(struct ioreq *ioreq)
|
|
|
|
{
|
2011-02-25 19:20:34 +03:00
|
|
|
XenGnttab gnt = ioreq->blkdev->xendev.gnttabdev;
|
2009-04-22 19:19:30 +04:00
|
|
|
int i;
|
|
|
|
|
2010-09-23 15:28:45 +04:00
|
|
|
if (ioreq->v.niov == 0) {
|
2009-04-22 19:19:30 +04:00
|
|
|
return 0;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
if (batch_maps) {
|
2010-09-23 15:28:45 +04:00
|
|
|
ioreq->pages = xc_gnttab_map_grant_refs
|
|
|
|
(gnt, ioreq->v.niov, ioreq->domids, ioreq->refs, ioreq->prot);
|
|
|
|
if (ioreq->pages == NULL) {
|
|
|
|
xen_be_printf(&ioreq->blkdev->xendev, 0,
|
|
|
|
"can't map %d grant refs (%s, %d maps)\n",
|
|
|
|
ioreq->v.niov, strerror(errno), ioreq->blkdev->cnt_map);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
for (i = 0; i < ioreq->v.niov; i++) {
|
|
|
|
ioreq->v.iov[i].iov_base = ioreq->pages + i * XC_PAGE_SIZE +
|
|
|
|
(uintptr_t)ioreq->v.iov[i].iov_base;
|
|
|
|
}
|
|
|
|
ioreq->blkdev->cnt_map += ioreq->v.niov;
|
2009-04-22 19:19:30 +04:00
|
|
|
} else {
|
2010-09-23 15:28:45 +04:00
|
|
|
for (i = 0; i < ioreq->v.niov; i++) {
|
|
|
|
ioreq->page[i] = xc_gnttab_map_grant_ref
|
|
|
|
(gnt, ioreq->domids[i], ioreq->refs[i], ioreq->prot);
|
|
|
|
if (ioreq->page[i] == NULL) {
|
|
|
|
xen_be_printf(&ioreq->blkdev->xendev, 0,
|
|
|
|
"can't map grant ref %d (%s, %d maps)\n",
|
|
|
|
ioreq->refs[i], strerror(errno), ioreq->blkdev->cnt_map);
|
|
|
|
ioreq_unmap(ioreq);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ioreq->v.iov[i].iov_base = ioreq->page[i] + (uintptr_t)ioreq->v.iov[i].iov_base;
|
|
|
|
ioreq->blkdev->cnt_map++;
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void qemu_aio_complete(void *opaque, int ret)
|
|
|
|
{
|
|
|
|
struct ioreq *ioreq = opaque;
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
xen_be_printf(&ioreq->blkdev->xendev, 0, "%s I/O error\n",
|
|
|
|
ioreq->req.operation == BLKIF_OP_READ ? "read" : "write");
|
|
|
|
ioreq->aio_errors++;
|
|
|
|
}
|
|
|
|
|
|
|
|
ioreq->aio_inflight--;
|
2010-09-23 15:28:45 +04:00
|
|
|
if (ioreq->aio_inflight > 0) {
|
2009-04-22 19:19:30 +04:00
|
|
|
return;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2012-03-23 15:37:25 +04:00
|
|
|
if (ioreq->postsync) {
|
|
|
|
bdrv_flush(ioreq->blkdev->bs);
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
|
|
|
|
ioreq->status = ioreq->aio_errors ? BLKIF_RSP_ERROR : BLKIF_RSP_OKAY;
|
|
|
|
ioreq_unmap(ioreq);
|
|
|
|
ioreq_finish(ioreq);
|
2011-08-25 10:26:01 +04:00
|
|
|
bdrv_acct_done(ioreq->blkdev->bs, &ioreq->acct);
|
2009-04-22 19:19:30 +04:00
|
|
|
qemu_bh_schedule(ioreq->blkdev->bh);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ioreq_runio_qemu_aio(struct ioreq *ioreq)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = ioreq->blkdev;
|
|
|
|
|
2010-09-23 15:28:45 +04:00
|
|
|
if (ioreq->req.nr_segments && ioreq_map(ioreq) == -1) {
|
|
|
|
goto err_no_map;
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
|
|
|
|
ioreq->aio_inflight++;
|
2010-09-23 15:28:45 +04:00
|
|
|
if (ioreq->presync) {
|
|
|
|
bdrv_flush(blkdev->bs); /* FIXME: aio_flush() ??? */
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
|
|
|
|
switch (ioreq->req.operation) {
|
|
|
|
case BLKIF_OP_READ:
|
2011-08-25 10:26:01 +04:00
|
|
|
bdrv_acct_start(blkdev->bs, &ioreq->acct, ioreq->v.size, BDRV_ACCT_READ);
|
2009-04-22 19:19:30 +04:00
|
|
|
ioreq->aio_inflight++;
|
|
|
|
bdrv_aio_readv(blkdev->bs, ioreq->start / BLOCK_SIZE,
|
|
|
|
&ioreq->v, ioreq->v.size / BLOCK_SIZE,
|
|
|
|
qemu_aio_complete, ioreq);
|
2010-09-23 15:28:45 +04:00
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
case BLKIF_OP_WRITE:
|
|
|
|
case BLKIF_OP_WRITE_BARRIER:
|
2010-09-23 15:28:45 +04:00
|
|
|
if (!ioreq->req.nr_segments) {
|
2010-11-24 16:08:03 +03:00
|
|
|
break;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2011-08-25 10:26:01 +04:00
|
|
|
|
|
|
|
bdrv_acct_start(blkdev->bs, &ioreq->acct, ioreq->v.size, BDRV_ACCT_WRITE);
|
2011-03-09 16:19:35 +03:00
|
|
|
ioreq->aio_inflight++;
|
2009-04-22 19:19:30 +04:00
|
|
|
bdrv_aio_writev(blkdev->bs, ioreq->start / BLOCK_SIZE,
|
|
|
|
&ioreq->v, ioreq->v.size / BLOCK_SIZE,
|
|
|
|
qemu_aio_complete, ioreq);
|
2010-09-23 15:28:45 +04:00
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
default:
|
2010-09-23 15:28:45 +04:00
|
|
|
/* unknown operation (shouldn't happen -- parse catches this) */
|
|
|
|
goto err;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
qemu_aio_complete(ioreq, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
2011-03-29 05:00:15 +04:00
|
|
|
ioreq_unmap(ioreq);
|
|
|
|
err_no_map:
|
|
|
|
ioreq_finish(ioreq);
|
2009-04-22 19:19:30 +04:00
|
|
|
ioreq->status = BLKIF_RSP_ERROR;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int blk_send_response_one(struct ioreq *ioreq)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = ioreq->blkdev;
|
|
|
|
int send_notify = 0;
|
|
|
|
int have_requests = 0;
|
|
|
|
blkif_response_t resp;
|
|
|
|
void *dst;
|
|
|
|
|
|
|
|
resp.id = ioreq->req.id;
|
|
|
|
resp.operation = ioreq->req.operation;
|
|
|
|
resp.status = ioreq->status;
|
|
|
|
|
|
|
|
/* Place on the response ring for the relevant domain. */
|
|
|
|
switch (blkdev->protocol) {
|
|
|
|
case BLKIF_PROTOCOL_NATIVE:
|
2010-09-23 15:28:45 +04:00
|
|
|
dst = RING_GET_RESPONSE(&blkdev->rings.native, blkdev->rings.native.rsp_prod_pvt);
|
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
case BLKIF_PROTOCOL_X86_32:
|
2009-04-25 12:00:11 +04:00
|
|
|
dst = RING_GET_RESPONSE(&blkdev->rings.x86_32_part,
|
|
|
|
blkdev->rings.x86_32_part.rsp_prod_pvt);
|
2010-09-23 15:28:45 +04:00
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
case BLKIF_PROTOCOL_X86_64:
|
2009-04-25 12:00:11 +04:00
|
|
|
dst = RING_GET_RESPONSE(&blkdev->rings.x86_64_part,
|
|
|
|
blkdev->rings.x86_64_part.rsp_prod_pvt);
|
2010-09-23 15:28:45 +04:00
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
default:
|
2010-09-23 15:28:45 +04:00
|
|
|
dst = NULL;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
memcpy(dst, &resp, sizeof(resp));
|
|
|
|
blkdev->rings.common.rsp_prod_pvt++;
|
|
|
|
|
|
|
|
RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(&blkdev->rings.common, send_notify);
|
|
|
|
if (blkdev->rings.common.rsp_prod_pvt == blkdev->rings.common.req_cons) {
|
2010-09-23 15:28:45 +04:00
|
|
|
/*
|
|
|
|
* Tail check for pending requests. Allows frontend to avoid
|
|
|
|
* notifications if requests are already in flight (lower
|
|
|
|
* overheads and promotes batching).
|
|
|
|
*/
|
|
|
|
RING_FINAL_CHECK_FOR_REQUESTS(&blkdev->rings.common, have_requests);
|
2009-04-22 19:19:30 +04:00
|
|
|
} else if (RING_HAS_UNCONSUMED_REQUESTS(&blkdev->rings.common)) {
|
2010-09-23 15:28:45 +04:00
|
|
|
have_requests = 1;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
|
2010-09-23 15:28:45 +04:00
|
|
|
if (have_requests) {
|
|
|
|
blkdev->more_work++;
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
return send_notify;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* walk finished list, send outstanding responses, free requests */
|
|
|
|
static void blk_send_response_all(struct XenBlkDev *blkdev)
|
|
|
|
{
|
|
|
|
struct ioreq *ioreq;
|
|
|
|
int send_notify = 0;
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
while (!QLIST_EMPTY(&blkdev->finished)) {
|
|
|
|
ioreq = QLIST_FIRST(&blkdev->finished);
|
2010-09-23 15:28:45 +04:00
|
|
|
send_notify += blk_send_response_one(ioreq);
|
|
|
|
ioreq_release(ioreq);
|
|
|
|
}
|
|
|
|
if (send_notify) {
|
|
|
|
xen_be_send_notify(&blkdev->xendev);
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int blk_get_request(struct XenBlkDev *blkdev, struct ioreq *ioreq, RING_IDX rc)
|
|
|
|
{
|
|
|
|
switch (blkdev->protocol) {
|
|
|
|
case BLKIF_PROTOCOL_NATIVE:
|
2010-09-23 15:28:45 +04:00
|
|
|
memcpy(&ioreq->req, RING_GET_REQUEST(&blkdev->rings.native, rc),
|
|
|
|
sizeof(ioreq->req));
|
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
case BLKIF_PROTOCOL_X86_32:
|
2009-04-25 12:00:11 +04:00
|
|
|
blkif_get_x86_32_req(&ioreq->req,
|
|
|
|
RING_GET_REQUEST(&blkdev->rings.x86_32_part, rc));
|
2010-09-23 15:28:45 +04:00
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
case BLKIF_PROTOCOL_X86_64:
|
2009-04-25 12:00:11 +04:00
|
|
|
blkif_get_x86_64_req(&ioreq->req,
|
|
|
|
RING_GET_REQUEST(&blkdev->rings.x86_64_part, rc));
|
2010-09-23 15:28:45 +04:00
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void blk_handle_requests(struct XenBlkDev *blkdev)
|
|
|
|
{
|
|
|
|
RING_IDX rc, rp;
|
|
|
|
struct ioreq *ioreq;
|
|
|
|
|
|
|
|
blkdev->more_work = 0;
|
|
|
|
|
|
|
|
rc = blkdev->rings.common.req_cons;
|
|
|
|
rp = blkdev->rings.common.sring->req_prod;
|
|
|
|
xen_rmb(); /* Ensure we see queued requests up to 'rp'. */
|
|
|
|
|
2011-10-28 20:03:58 +04:00
|
|
|
blk_send_response_all(blkdev);
|
2009-04-23 22:29:47 +04:00
|
|
|
while (rc != rp) {
|
2009-04-22 19:19:30 +04:00
|
|
|
/* pull request from ring */
|
2010-09-23 15:28:45 +04:00
|
|
|
if (RING_REQUEST_CONS_OVERFLOW(&blkdev->rings.common, rc)) {
|
2009-04-22 19:19:30 +04:00
|
|
|
break;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
ioreq = ioreq_start(blkdev);
|
|
|
|
if (ioreq == NULL) {
|
|
|
|
blkdev->more_work++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
blk_get_request(blkdev, ioreq, rc);
|
|
|
|
blkdev->rings.common.req_cons = ++rc;
|
|
|
|
|
|
|
|
/* parse them */
|
|
|
|
if (ioreq_parse(ioreq) != 0) {
|
2010-09-23 15:28:45 +04:00
|
|
|
if (blk_send_response_one(ioreq)) {
|
2009-04-22 19:19:30 +04:00
|
|
|
xen_be_send_notify(&blkdev->xendev);
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
ioreq_release(ioreq);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-10-28 20:03:58 +04:00
|
|
|
ioreq_runio_qemu_aio(ioreq);
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
|
2010-09-23 15:28:45 +04:00
|
|
|
if (blkdev->more_work && blkdev->requests_inflight < max_requests) {
|
2009-04-22 19:19:30 +04:00
|
|
|
qemu_bh_schedule(blkdev->bh);
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void blk_bh(void *opaque)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = opaque;
|
|
|
|
blk_handle_requests(blkdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void blk_alloc(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_INIT(&blkdev->inflight);
|
|
|
|
QLIST_INIT(&blkdev->finished);
|
|
|
|
QLIST_INIT(&blkdev->freelist);
|
2009-04-22 19:19:30 +04:00
|
|
|
blkdev->bh = qemu_bh_new(blk_bh, blkdev);
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xen_mode != XEN_EMULATE) {
|
2009-04-22 19:19:30 +04:00
|
|
|
batch_maps = 1;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int blk_init(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
|
2011-10-21 14:16:44 +04:00
|
|
|
int index, qflags, info = 0;
|
2009-04-22 19:19:30 +04:00
|
|
|
|
|
|
|
/* read xenstore entries */
|
|
|
|
if (blkdev->params == NULL) {
|
2011-06-27 19:10:01 +04:00
|
|
|
char *h = NULL;
|
2010-09-23 15:28:45 +04:00
|
|
|
blkdev->params = xenstore_read_be_str(&blkdev->xendev, "params");
|
2011-06-27 19:10:01 +04:00
|
|
|
if (blkdev->params != NULL) {
|
|
|
|
h = strchr(blkdev->params, ':');
|
|
|
|
}
|
2010-09-23 15:28:45 +04:00
|
|
|
if (h != NULL) {
|
|
|
|
blkdev->fileproto = blkdev->params;
|
|
|
|
blkdev->filename = h+1;
|
|
|
|
*h = 0;
|
|
|
|
} else {
|
|
|
|
blkdev->fileproto = "<unset>";
|
|
|
|
blkdev->filename = blkdev->params;
|
|
|
|
}
|
|
|
|
}
|
2011-06-30 18:42:31 +04:00
|
|
|
if (!strcmp("aio", blkdev->fileproto)) {
|
|
|
|
blkdev->fileproto = "raw";
|
|
|
|
}
|
2010-09-23 15:28:45 +04:00
|
|
|
if (blkdev->mode == NULL) {
|
|
|
|
blkdev->mode = xenstore_read_be_str(&blkdev->xendev, "mode");
|
|
|
|
}
|
|
|
|
if (blkdev->type == NULL) {
|
|
|
|
blkdev->type = xenstore_read_be_str(&blkdev->xendev, "type");
|
|
|
|
}
|
|
|
|
if (blkdev->dev == NULL) {
|
|
|
|
blkdev->dev = xenstore_read_be_str(&blkdev->xendev, "dev");
|
|
|
|
}
|
|
|
|
if (blkdev->devtype == NULL) {
|
|
|
|
blkdev->devtype = xenstore_read_be_str(&blkdev->xendev, "device-type");
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
|
|
|
|
/* do we have all we need? */
|
|
|
|
if (blkdev->params == NULL ||
|
2010-09-23 15:28:45 +04:00
|
|
|
blkdev->mode == NULL ||
|
|
|
|
blkdev->type == NULL ||
|
|
|
|
blkdev->dev == NULL) {
|
2011-06-27 19:10:01 +04:00
|
|
|
goto out_error;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
|
|
|
|
/* read-only ? */
|
2012-03-23 15:39:51 +04:00
|
|
|
qflags = BDRV_O_NOCACHE | BDRV_O_CACHE_WB | BDRV_O_NATIVE_AIO;
|
2009-04-22 19:19:30 +04:00
|
|
|
if (strcmp(blkdev->mode, "w") == 0) {
|
2012-03-23 15:39:51 +04:00
|
|
|
qflags |= BDRV_O_RDWR;
|
2009-04-22 19:19:30 +04:00
|
|
|
} else {
|
2010-09-23 15:28:45 +04:00
|
|
|
info |= VDISK_READONLY;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* cdrom ? */
|
2010-09-23 15:28:45 +04:00
|
|
|
if (blkdev->devtype && !strcmp(blkdev->devtype, "cdrom")) {
|
|
|
|
info |= VDISK_CDROM;
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
|
|
|
|
/* init qemu block driver */
|
2009-07-22 18:42:57 +04:00
|
|
|
index = (blkdev->xendev.dev - 202 * 256) / 16;
|
|
|
|
blkdev->dinfo = drive_get(IF_XEN, 0, index);
|
|
|
|
if (!blkdev->dinfo) {
|
2009-04-22 19:19:30 +04:00
|
|
|
/* setup via xenbus -> create new block driver instance */
|
|
|
|
xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus setup)\n");
|
2010-12-16 17:37:41 +03:00
|
|
|
blkdev->bs = bdrv_new(blkdev->dev);
|
2011-06-27 19:10:01 +04:00
|
|
|
if (blkdev->bs) {
|
|
|
|
if (bdrv_open(blkdev->bs, blkdev->filename, qflags,
|
|
|
|
bdrv_find_whitelisted_format(blkdev->fileproto)) != 0) {
|
|
|
|
bdrv_delete(blkdev->bs);
|
|
|
|
blkdev->bs = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!blkdev->bs) {
|
|
|
|
goto out_error;
|
2010-12-16 17:37:41 +03:00
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
} else {
|
|
|
|
/* setup via qemu cmdline -> already setup for us */
|
|
|
|
xen_be_printf(&blkdev->xendev, 2, "get configured bdrv (cmdline setup)\n");
|
2010-09-23 15:28:45 +04:00
|
|
|
blkdev->bs = blkdev->dinfo->bdrv;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
2011-08-03 17:07:40 +04:00
|
|
|
bdrv_attach_dev_nofail(blkdev->bs, blkdev);
|
2009-04-22 19:19:30 +04:00
|
|
|
blkdev->file_blk = BLOCK_SIZE;
|
|
|
|
blkdev->file_size = bdrv_getlength(blkdev->bs);
|
|
|
|
if (blkdev->file_size < 0) {
|
|
|
|
xen_be_printf(&blkdev->xendev, 1, "bdrv_getlength: %d (%s) | drv %s\n",
|
|
|
|
(int)blkdev->file_size, strerror(-blkdev->file_size),
|
|
|
|
blkdev->bs->drv ? blkdev->bs->drv->format_name : "-");
|
2010-09-23 15:28:45 +04:00
|
|
|
blkdev->file_size = 0;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
xen_be_printf(xendev, 1, "type \"%s\", fileproto \"%s\", filename \"%s\","
|
2010-09-23 15:28:45 +04:00
|
|
|
" size %" PRId64 " (%" PRId64 " MB)\n",
|
|
|
|
blkdev->type, blkdev->fileproto, blkdev->filename,
|
|
|
|
blkdev->file_size, blkdev->file_size >> 20);
|
2009-04-22 19:19:30 +04:00
|
|
|
|
|
|
|
/* fill info */
|
2011-10-21 14:16:44 +04:00
|
|
|
xenstore_write_be_int(&blkdev->xendev, "feature-barrier", 1);
|
2009-04-22 19:19:30 +04:00
|
|
|
xenstore_write_be_int(&blkdev->xendev, "info", info);
|
|
|
|
xenstore_write_be_int(&blkdev->xendev, "sector-size", blkdev->file_blk);
|
|
|
|
xenstore_write_be_int(&blkdev->xendev, "sectors",
|
2010-09-23 15:28:45 +04:00
|
|
|
blkdev->file_size / blkdev->file_blk);
|
2009-04-22 19:19:30 +04:00
|
|
|
return 0;
|
2011-06-27 19:10:01 +04:00
|
|
|
|
|
|
|
out_error:
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(blkdev->params);
|
2011-06-27 19:10:01 +04:00
|
|
|
blkdev->params = NULL;
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(blkdev->mode);
|
2011-06-27 19:10:01 +04:00
|
|
|
blkdev->mode = NULL;
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(blkdev->type);
|
2011-06-27 19:10:01 +04:00
|
|
|
blkdev->type = NULL;
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(blkdev->dev);
|
2011-06-27 19:10:01 +04:00
|
|
|
blkdev->dev = NULL;
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(blkdev->devtype);
|
2011-06-27 19:10:01 +04:00
|
|
|
blkdev->devtype = NULL;
|
|
|
|
return -1;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int blk_connect(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
|
|
|
|
|
2010-09-23 15:28:45 +04:00
|
|
|
if (xenstore_read_fe_int(&blkdev->xendev, "ring-ref", &blkdev->ring_ref) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
if (xenstore_read_fe_int(&blkdev->xendev, "event-channel",
|
2010-09-23 15:28:45 +04:00
|
|
|
&blkdev->xendev.remote_port) == -1) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
|
|
|
|
blkdev->protocol = BLKIF_PROTOCOL_NATIVE;
|
|
|
|
if (blkdev->xendev.protocol) {
|
2010-09-23 15:28:45 +04:00
|
|
|
if (strcmp(blkdev->xendev.protocol, XEN_IO_PROTO_ABI_X86_32) == 0) {
|
2009-04-22 19:19:30 +04:00
|
|
|
blkdev->protocol = BLKIF_PROTOCOL_X86_32;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
|
|
|
if (strcmp(blkdev->xendev.protocol, XEN_IO_PROTO_ABI_X86_64) == 0) {
|
2009-04-22 19:19:30 +04:00
|
|
|
blkdev->protocol = BLKIF_PROTOCOL_X86_64;
|
2010-09-23 15:28:45 +04:00
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
blkdev->sring = xc_gnttab_map_grant_ref(blkdev->xendev.gnttabdev,
|
2010-09-23 15:28:45 +04:00
|
|
|
blkdev->xendev.dom,
|
|
|
|
blkdev->ring_ref,
|
|
|
|
PROT_READ | PROT_WRITE);
|
|
|
|
if (!blkdev->sring) {
|
|
|
|
return -1;
|
|
|
|
}
|
2009-04-22 19:19:30 +04:00
|
|
|
blkdev->cnt_map++;
|
|
|
|
|
|
|
|
switch (blkdev->protocol) {
|
|
|
|
case BLKIF_PROTOCOL_NATIVE:
|
|
|
|
{
|
2010-09-23 15:28:45 +04:00
|
|
|
blkif_sring_t *sring_native = blkdev->sring;
|
|
|
|
BACK_RING_INIT(&blkdev->rings.native, sring_native, XC_PAGE_SIZE);
|
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
case BLKIF_PROTOCOL_X86_32:
|
|
|
|
{
|
2010-09-23 15:28:45 +04:00
|
|
|
blkif_x86_32_sring_t *sring_x86_32 = blkdev->sring;
|
2009-04-25 12:00:11 +04:00
|
|
|
|
|
|
|
BACK_RING_INIT(&blkdev->rings.x86_32_part, sring_x86_32, XC_PAGE_SIZE);
|
2010-09-23 15:28:45 +04:00
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
case BLKIF_PROTOCOL_X86_64:
|
|
|
|
{
|
2010-09-23 15:28:45 +04:00
|
|
|
blkif_x86_64_sring_t *sring_x86_64 = blkdev->sring;
|
2009-04-25 12:00:11 +04:00
|
|
|
|
|
|
|
BACK_RING_INIT(&blkdev->rings.x86_64_part, sring_x86_64, XC_PAGE_SIZE);
|
2010-09-23 15:28:45 +04:00
|
|
|
break;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
xen_be_bind_evtchn(&blkdev->xendev);
|
|
|
|
|
|
|
|
xen_be_printf(&blkdev->xendev, 1, "ok: proto %s, ring-ref %d, "
|
2010-09-23 15:28:45 +04:00
|
|
|
"remote port %d, local port %d\n",
|
|
|
|
blkdev->xendev.protocol, blkdev->ring_ref,
|
|
|
|
blkdev->xendev.remote_port, blkdev->xendev.local_port);
|
2009-04-22 19:19:30 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void blk_disconnect(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
|
|
|
|
|
|
|
|
if (blkdev->bs) {
|
2009-07-22 18:42:57 +04:00
|
|
|
if (!blkdev->dinfo) {
|
2009-04-22 19:19:30 +04:00
|
|
|
/* close/delete only if we created it ourself */
|
|
|
|
bdrv_close(blkdev->bs);
|
2012-03-27 20:03:07 +04:00
|
|
|
bdrv_detach_dev(blkdev->bs, blkdev);
|
2009-04-22 19:19:30 +04:00
|
|
|
bdrv_delete(blkdev->bs);
|
|
|
|
}
|
2010-09-23 15:28:45 +04:00
|
|
|
blkdev->bs = NULL;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
xen_be_unbind_evtchn(&blkdev->xendev);
|
|
|
|
|
|
|
|
if (blkdev->sring) {
|
2010-09-23 15:28:45 +04:00
|
|
|
xc_gnttab_munmap(blkdev->xendev.gnttabdev, blkdev->sring, 1);
|
|
|
|
blkdev->cnt_map--;
|
|
|
|
blkdev->sring = NULL;
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int blk_free(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
|
|
|
|
struct ioreq *ioreq;
|
|
|
|
|
2009-09-12 11:36:22 +04:00
|
|
|
while (!QLIST_EMPTY(&blkdev->freelist)) {
|
2010-09-23 15:28:45 +04:00
|
|
|
ioreq = QLIST_FIRST(&blkdev->freelist);
|
2009-09-12 11:36:22 +04:00
|
|
|
QLIST_REMOVE(ioreq, list);
|
2009-04-22 19:19:30 +04:00
|
|
|
qemu_iovec_destroy(&ioreq->v);
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(ioreq);
|
2009-04-22 19:19:30 +04:00
|
|
|
}
|
|
|
|
|
2011-08-21 07:09:37 +04:00
|
|
|
g_free(blkdev->params);
|
|
|
|
g_free(blkdev->mode);
|
|
|
|
g_free(blkdev->type);
|
|
|
|
g_free(blkdev->dev);
|
|
|
|
g_free(blkdev->devtype);
|
2009-04-22 19:19:30 +04:00
|
|
|
qemu_bh_delete(blkdev->bh);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void blk_event(struct XenDevice *xendev)
|
|
|
|
{
|
|
|
|
struct XenBlkDev *blkdev = container_of(xendev, struct XenBlkDev, xendev);
|
|
|
|
|
|
|
|
qemu_bh_schedule(blkdev->bh);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct XenDevOps xen_blkdev_ops = {
|
|
|
|
.size = sizeof(struct XenBlkDev),
|
|
|
|
.flags = DEVOPS_FLAG_NEED_GNTDEV,
|
|
|
|
.alloc = blk_alloc,
|
|
|
|
.init = blk_init,
|
2011-06-17 16:15:35 +04:00
|
|
|
.initialise = blk_connect,
|
2009-04-22 19:19:30 +04:00
|
|
|
.disconnect = blk_disconnect,
|
|
|
|
.event = blk_event,
|
|
|
|
.free = blk_free,
|
|
|
|
};
|