mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-25 11:01:52 -06:00
xen_disk: remove open-coded use of libxengnttab
Now that helpers are present in xen_backend, this patch removes open-coded calls to libxengnttab from the xen_disk code. This patch also fixes one whitspace error in the assignment of the XenDevOps initialise method. Signed-off-by: Paul Durrant <paul.durrant@citrix.com> Acked-by: Anthony Perard <anthony.perard@citrix.com> Signed-off-by: Stefano Stabellini <sstabellini@kernel.org>
This commit is contained in:
parent
9838824aff
commit
5ee1d99913
1 changed files with 32 additions and 90 deletions
|
@ -68,7 +68,6 @@ struct ioreq {
|
||||||
uint8_t mapped;
|
uint8_t mapped;
|
||||||
|
|
||||||
/* grant mapping */
|
/* grant mapping */
|
||||||
uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
|
||||||
uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
||||||
int prot;
|
int prot;
|
||||||
void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
||||||
|
@ -142,7 +141,6 @@ static void ioreq_reset(struct ioreq *ioreq)
|
||||||
ioreq->presync = 0;
|
ioreq->presync = 0;
|
||||||
ioreq->mapped = 0;
|
ioreq->mapped = 0;
|
||||||
|
|
||||||
memset(ioreq->domids, 0, sizeof(ioreq->domids));
|
|
||||||
memset(ioreq->refs, 0, sizeof(ioreq->refs));
|
memset(ioreq->refs, 0, sizeof(ioreq->refs));
|
||||||
ioreq->prot = 0;
|
ioreq->prot = 0;
|
||||||
memset(ioreq->page, 0, sizeof(ioreq->page));
|
memset(ioreq->page, 0, sizeof(ioreq->page));
|
||||||
|
@ -168,16 +166,12 @@ static gint int_cmp(gconstpointer a, gconstpointer b, gpointer user_data)
|
||||||
static void destroy_grant(gpointer pgnt)
|
static void destroy_grant(gpointer pgnt)
|
||||||
{
|
{
|
||||||
PersistentGrant *grant = pgnt;
|
PersistentGrant *grant = pgnt;
|
||||||
xengnttab_handle *gnt = grant->blkdev->xendev.gnttabdev;
|
struct XenBlkDev *blkdev = grant->blkdev;
|
||||||
|
struct XenDevice *xendev = &blkdev->xendev;
|
||||||
|
|
||||||
if (xengnttab_unmap(gnt, grant->page, 1) != 0) {
|
xen_be_unmap_grant_ref(xendev, grant->page);
|
||||||
xen_pv_printf(&grant->blkdev->xendev, 0,
|
|
||||||
"xengnttab_unmap failed: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
}
|
|
||||||
grant->blkdev->persistent_gnt_count--;
|
grant->blkdev->persistent_gnt_count--;
|
||||||
xen_pv_printf(&grant->blkdev->xendev, 3,
|
xen_pv_printf(xendev, 3, "unmapped grant %p\n", grant->page);
|
||||||
"unmapped grant %p\n", grant->page);
|
|
||||||
g_free(grant);
|
g_free(grant);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,15 +179,10 @@ static void remove_persistent_region(gpointer data, gpointer dev)
|
||||||
{
|
{
|
||||||
PersistentRegion *region = data;
|
PersistentRegion *region = data;
|
||||||
struct XenBlkDev *blkdev = dev;
|
struct XenBlkDev *blkdev = dev;
|
||||||
xengnttab_handle *gnt = blkdev->xendev.gnttabdev;
|
struct XenDevice *xendev = &blkdev->xendev;
|
||||||
|
|
||||||
if (xengnttab_unmap(gnt, region->addr, region->num) != 0) {
|
xen_be_unmap_grant_refs(xendev, region->addr, region->num);
|
||||||
xen_pv_printf(&blkdev->xendev, 0,
|
xen_pv_printf(xendev, 3, "unmapped grant region %p with %d pages\n",
|
||||||
"xengnttab_unmap region %p failed: %s\n",
|
|
||||||
region->addr, strerror(errno));
|
|
||||||
}
|
|
||||||
xen_pv_printf(&blkdev->xendev, 3,
|
|
||||||
"unmapped grant region %p with %d pages\n",
|
|
||||||
region->addr, region->num);
|
region->addr, region->num);
|
||||||
g_free(region);
|
g_free(region);
|
||||||
}
|
}
|
||||||
|
@ -304,7 +293,6 @@ static int ioreq_parse(struct ioreq *ioreq)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
ioreq->domids[i] = blkdev->xendev.dom;
|
|
||||||
ioreq->refs[i] = ioreq->req.seg[i].gref;
|
ioreq->refs[i] = ioreq->req.seg[i].gref;
|
||||||
|
|
||||||
mem = ioreq->req.seg[i].first_sect * blkdev->file_blk;
|
mem = ioreq->req.seg[i].first_sect * blkdev->file_blk;
|
||||||
|
@ -324,7 +312,8 @@ err:
|
||||||
|
|
||||||
static void ioreq_unmap(struct ioreq *ioreq)
|
static void ioreq_unmap(struct ioreq *ioreq)
|
||||||
{
|
{
|
||||||
xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
|
struct XenBlkDev *blkdev = ioreq->blkdev;
|
||||||
|
struct XenDevice *xendev = &blkdev->xendev;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (ioreq->num_unmap == 0 || ioreq->mapped == 0) {
|
if (ioreq->num_unmap == 0 || ioreq->mapped == 0) {
|
||||||
|
@ -334,11 +323,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
|
||||||
if (!ioreq->pages) {
|
if (!ioreq->pages) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (xengnttab_unmap(gnt, ioreq->pages, ioreq->num_unmap) != 0) {
|
xen_be_unmap_grant_refs(xendev, ioreq->pages, ioreq->num_unmap);
|
||||||
xen_pv_printf(&ioreq->blkdev->xendev, 0,
|
|
||||||
"xengnttab_unmap failed: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
}
|
|
||||||
ioreq->blkdev->cnt_map -= ioreq->num_unmap;
|
ioreq->blkdev->cnt_map -= ioreq->num_unmap;
|
||||||
ioreq->pages = NULL;
|
ioreq->pages = NULL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -346,11 +331,7 @@ static void ioreq_unmap(struct ioreq *ioreq)
|
||||||
if (!ioreq->page[i]) {
|
if (!ioreq->page[i]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (xengnttab_unmap(gnt, ioreq->page[i], 1) != 0) {
|
xen_be_unmap_grant_ref(xendev, ioreq->page[i]);
|
||||||
xen_pv_printf(&ioreq->blkdev->xendev, 0,
|
|
||||||
"xengnttab_unmap failed: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
}
|
|
||||||
ioreq->blkdev->cnt_map--;
|
ioreq->blkdev->cnt_map--;
|
||||||
ioreq->page[i] = NULL;
|
ioreq->page[i] = NULL;
|
||||||
}
|
}
|
||||||
|
@ -360,14 +341,14 @@ static void ioreq_unmap(struct ioreq *ioreq)
|
||||||
|
|
||||||
static int ioreq_map(struct ioreq *ioreq)
|
static int ioreq_map(struct ioreq *ioreq)
|
||||||
{
|
{
|
||||||
xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
|
struct XenBlkDev *blkdev = ioreq->blkdev;
|
||||||
uint32_t domids[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
struct XenDevice *xendev = &blkdev->xendev;
|
||||||
uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
uint32_t refs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
||||||
void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
void *page[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
||||||
int i, j, new_maps = 0;
|
int i, j, new_maps = 0;
|
||||||
PersistentGrant *grant;
|
PersistentGrant *grant;
|
||||||
PersistentRegion *region;
|
PersistentRegion *region;
|
||||||
/* domids and refs variables will contain the information necessary
|
/* refs variable will contain the information necessary
|
||||||
* to map the grants that are needed to fulfill this request.
|
* to map the grants that are needed to fulfill this request.
|
||||||
*
|
*
|
||||||
* After mapping the needed grants, the page array will contain the
|
* After mapping the needed grants, the page array will contain the
|
||||||
|
@ -392,7 +373,6 @@ static int ioreq_map(struct ioreq *ioreq)
|
||||||
/* Add the grant to the list of grants that
|
/* Add the grant to the list of grants that
|
||||||
* should be mapped
|
* should be mapped
|
||||||
*/
|
*/
|
||||||
domids[new_maps] = ioreq->domids[i];
|
|
||||||
refs[new_maps] = ioreq->refs[i];
|
refs[new_maps] = ioreq->refs[i];
|
||||||
page[i] = NULL;
|
page[i] = NULL;
|
||||||
new_maps++;
|
new_maps++;
|
||||||
|
@ -405,14 +385,13 @@ static int ioreq_map(struct ioreq *ioreq)
|
||||||
} else {
|
} else {
|
||||||
/* All grants in the request should be mapped */
|
/* All grants in the request should be mapped */
|
||||||
memcpy(refs, ioreq->refs, sizeof(refs));
|
memcpy(refs, ioreq->refs, sizeof(refs));
|
||||||
memcpy(domids, ioreq->domids, sizeof(domids));
|
|
||||||
memset(page, 0, sizeof(page));
|
memset(page, 0, sizeof(page));
|
||||||
new_maps = ioreq->v.niov;
|
new_maps = ioreq->v.niov;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (batch_maps && new_maps) {
|
if (batch_maps && new_maps) {
|
||||||
ioreq->pages = xengnttab_map_grant_refs
|
ioreq->pages = xen_be_map_grant_refs(xendev, refs, new_maps,
|
||||||
(gnt, new_maps, domids, refs, ioreq->prot);
|
ioreq->prot);
|
||||||
if (ioreq->pages == NULL) {
|
if (ioreq->pages == NULL) {
|
||||||
xen_pv_printf(&ioreq->blkdev->xendev, 0,
|
xen_pv_printf(&ioreq->blkdev->xendev, 0,
|
||||||
"can't map %d grant refs (%s, %d maps)\n",
|
"can't map %d grant refs (%s, %d maps)\n",
|
||||||
|
@ -427,8 +406,8 @@ static int ioreq_map(struct ioreq *ioreq)
|
||||||
ioreq->blkdev->cnt_map += new_maps;
|
ioreq->blkdev->cnt_map += new_maps;
|
||||||
} else if (new_maps) {
|
} else if (new_maps) {
|
||||||
for (i = 0; i < new_maps; i++) {
|
for (i = 0; i < new_maps; i++) {
|
||||||
ioreq->page[i] = xengnttab_map_grant_ref
|
ioreq->page[i] = xen_be_map_grant_ref(xendev, refs[i],
|
||||||
(gnt, domids[i], refs[i], ioreq->prot);
|
ioreq->prot);
|
||||||
if (ioreq->page[i] == NULL) {
|
if (ioreq->page[i] == NULL) {
|
||||||
xen_pv_printf(&ioreq->blkdev->xendev, 0,
|
xen_pv_printf(&ioreq->blkdev->xendev, 0,
|
||||||
"can't map grant ref %d (%s, %d maps)\n",
|
"can't map grant ref %d (%s, %d maps)\n",
|
||||||
|
@ -527,10 +506,12 @@ static int ioreq_init_copy_buffers(struct ioreq *ioreq)
|
||||||
|
|
||||||
static int ioreq_grant_copy(struct ioreq *ioreq)
|
static int ioreq_grant_copy(struct ioreq *ioreq)
|
||||||
{
|
{
|
||||||
xengnttab_handle *gnt = ioreq->blkdev->xendev.gnttabdev;
|
struct XenBlkDev *blkdev = ioreq->blkdev;
|
||||||
xengnttab_grant_copy_segment_t segs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
struct XenDevice *xendev = &blkdev->xendev;
|
||||||
|
XenGrantCopySegment segs[BLKIF_MAX_SEGMENTS_PER_REQUEST];
|
||||||
int i, count, rc;
|
int i, count, rc;
|
||||||
int64_t file_blk = ioreq->blkdev->file_blk;
|
int64_t file_blk = ioreq->blkdev->file_blk;
|
||||||
|
bool to_domain = (ioreq->req.operation == BLKIF_OP_READ);
|
||||||
|
|
||||||
if (ioreq->v.niov == 0) {
|
if (ioreq->v.niov == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -539,16 +520,12 @@ static int ioreq_grant_copy(struct ioreq *ioreq)
|
||||||
count = ioreq->v.niov;
|
count = ioreq->v.niov;
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
if (ioreq->req.operation == BLKIF_OP_READ) {
|
if (to_domain) {
|
||||||
segs[i].flags = GNTCOPY_dest_gref;
|
|
||||||
segs[i].dest.foreign.ref = ioreq->refs[i];
|
segs[i].dest.foreign.ref = ioreq->refs[i];
|
||||||
segs[i].dest.foreign.domid = ioreq->domids[i];
|
|
||||||
segs[i].dest.foreign.offset = ioreq->req.seg[i].first_sect * file_blk;
|
segs[i].dest.foreign.offset = ioreq->req.seg[i].first_sect * file_blk;
|
||||||
segs[i].source.virt = ioreq->v.iov[i].iov_base;
|
segs[i].source.virt = ioreq->v.iov[i].iov_base;
|
||||||
} else {
|
} else {
|
||||||
segs[i].flags = GNTCOPY_source_gref;
|
|
||||||
segs[i].source.foreign.ref = ioreq->refs[i];
|
segs[i].source.foreign.ref = ioreq->refs[i];
|
||||||
segs[i].source.foreign.domid = ioreq->domids[i];
|
|
||||||
segs[i].source.foreign.offset = ioreq->req.seg[i].first_sect * file_blk;
|
segs[i].source.foreign.offset = ioreq->req.seg[i].first_sect * file_blk;
|
||||||
segs[i].dest.virt = ioreq->v.iov[i].iov_base;
|
segs[i].dest.virt = ioreq->v.iov[i].iov_base;
|
||||||
}
|
}
|
||||||
|
@ -556,7 +533,7 @@ static int ioreq_grant_copy(struct ioreq *ioreq)
|
||||||
- ioreq->req.seg[i].first_sect + 1) * file_blk;
|
- ioreq->req.seg[i].first_sect + 1) * file_blk;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = xengnttab_grant_copy(gnt, count, segs);
|
rc = xen_be_copy_grant_refs(xendev, to_domain, segs, count);
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
xen_pv_printf(&ioreq->blkdev->xendev, 0,
|
xen_pv_printf(&ioreq->blkdev->xendev, 0,
|
||||||
|
@ -565,16 +542,6 @@ static int ioreq_grant_copy(struct ioreq *ioreq)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
|
||||||
if (segs[i].status != GNTST_okay) {
|
|
||||||
xen_pv_printf(&ioreq->blkdev->xendev, 3,
|
|
||||||
"failed to copy data %d for gref %d, domid %d\n",
|
|
||||||
segs[i].status, ioreq->refs[i], ioreq->domids[i]);
|
|
||||||
ioreq->aio_errors++;
|
|
||||||
rc = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1067,7 +1034,6 @@ static int blk_connect(struct XenDevice *xendev)
|
||||||
int order, ring_ref;
|
int order, ring_ref;
|
||||||
unsigned int ring_size, max_grants;
|
unsigned int ring_size, max_grants;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
uint32_t *domids;
|
|
||||||
|
|
||||||
trace_xen_disk_connect(xendev->name);
|
trace_xen_disk_connect(xendev->name);
|
||||||
|
|
||||||
|
@ -1229,31 +1195,11 @@ static int blk_connect(struct XenDevice *xendev)
|
||||||
/* Add on the number needed for the ring pages */
|
/* Add on the number needed for the ring pages */
|
||||||
max_grants += blkdev->nr_ring_ref;
|
max_grants += blkdev->nr_ring_ref;
|
||||||
|
|
||||||
blkdev->xendev.gnttabdev = xengnttab_open(NULL, 0);
|
xen_be_set_max_grant_refs(xendev, max_grants);
|
||||||
if (blkdev->xendev.gnttabdev == NULL) {
|
|
||||||
xen_pv_printf(xendev, 0, "xengnttab_open failed: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (xengnttab_set_max_grants(blkdev->xendev.gnttabdev, max_grants)) {
|
|
||||||
xen_pv_printf(xendev, 0, "xengnttab_set_max_grants failed: %s\n",
|
|
||||||
strerror(errno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
domids = g_new0(uint32_t, blkdev->nr_ring_ref);
|
|
||||||
for (i = 0; i < blkdev->nr_ring_ref; i++) {
|
|
||||||
domids[i] = blkdev->xendev.dom;
|
|
||||||
}
|
|
||||||
|
|
||||||
blkdev->sring = xengnttab_map_grant_refs(blkdev->xendev.gnttabdev,
|
|
||||||
blkdev->nr_ring_ref,
|
|
||||||
domids,
|
|
||||||
blkdev->ring_ref,
|
|
||||||
PROT_READ | PROT_WRITE);
|
|
||||||
|
|
||||||
g_free(domids);
|
|
||||||
|
|
||||||
|
blkdev->sring = xen_be_map_grant_refs(xendev, blkdev->ring_ref,
|
||||||
|
blkdev->nr_ring_ref,
|
||||||
|
PROT_READ | PROT_WRITE);
|
||||||
if (!blkdev->sring) {
|
if (!blkdev->sring) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1326,8 +1272,8 @@ static void blk_disconnect(struct XenDevice *xendev)
|
||||||
aio_context_release(blkdev->ctx);
|
aio_context_release(blkdev->ctx);
|
||||||
|
|
||||||
if (blkdev->sring) {
|
if (blkdev->sring) {
|
||||||
xengnttab_unmap(blkdev->xendev.gnttabdev, blkdev->sring,
|
xen_be_unmap_grant_refs(xendev, blkdev->sring,
|
||||||
blkdev->nr_ring_ref);
|
blkdev->nr_ring_ref);
|
||||||
blkdev->cnt_map--;
|
blkdev->cnt_map--;
|
||||||
blkdev->sring = NULL;
|
blkdev->sring = NULL;
|
||||||
}
|
}
|
||||||
|
@ -1351,11 +1297,6 @@ static void blk_disconnect(struct XenDevice *xendev)
|
||||||
}
|
}
|
||||||
blkdev->feature_persistent = false;
|
blkdev->feature_persistent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blkdev->xendev.gnttabdev) {
|
|
||||||
xengnttab_close(blkdev->xendev.gnttabdev);
|
|
||||||
blkdev->xendev.gnttabdev = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int blk_free(struct XenDevice *xendev)
|
static int blk_free(struct XenDevice *xendev)
|
||||||
|
@ -1392,10 +1333,11 @@ static void blk_event(struct XenDevice *xendev)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct XenDevOps xen_blkdev_ops = {
|
struct XenDevOps xen_blkdev_ops = {
|
||||||
|
.flags = DEVOPS_FLAG_NEED_GNTDEV,
|
||||||
.size = sizeof(struct XenBlkDev),
|
.size = sizeof(struct XenBlkDev),
|
||||||
.alloc = blk_alloc,
|
.alloc = blk_alloc,
|
||||||
.init = blk_init,
|
.init = blk_init,
|
||||||
.initialise = blk_connect,
|
.initialise = blk_connect,
|
||||||
.disconnect = blk_disconnect,
|
.disconnect = blk_disconnect,
|
||||||
.event = blk_event,
|
.event = blk_event,
|
||||||
.free = blk_free,
|
.free = blk_free,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue