Skip to content

Commit

Permalink
xen/grant: introduce func gnttab_unmap_refs_sync()
Browse files Browse the repository at this point in the history
There are several place using gnttab async unmap and wait for
completion, so move the common code to a function
gnttab_unmap_refs_sync().

Signed-off-by: Bob Liu <bob.liu@oracle.com>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Signed-off-by: David Vrabel <david.vrabel@citrix.com>
  • Loading branch information
Bob Liu authored and David Vrabel committed Apr 27, 2015
1 parent 325d73b commit b44166c
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 53 deletions.
31 changes: 3 additions & 28 deletions drivers/block/xen-blkback/blkback.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,6 @@ static void put_persistent_gnt(struct xen_blkif *blkif,
atomic_dec(&blkif->persistent_gnt_in_use);
}

static void free_persistent_gnts_unmap_callback(int result,
struct gntab_unmap_queue_data *data)
{
struct completion *c = data->data;

/* BUG_ON used to reproduce existing behaviour,
but is this the best way to deal with this? */
BUG_ON(result);
complete(c);
}

static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
unsigned int num)
{
Expand All @@ -285,12 +274,7 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
struct rb_node *n;
int segs_to_unmap = 0;
struct gntab_unmap_queue_data unmap_data;
struct completion unmap_completion;

init_completion(&unmap_completion);

unmap_data.data = &unmap_completion;
unmap_data.done = &free_persistent_gnts_unmap_callback;
unmap_data.pages = pages;
unmap_data.unmap_ops = unmap;
unmap_data.kunmap_ops = NULL;
Expand All @@ -310,8 +294,7 @@ static void free_persistent_gnts(struct xen_blkif *blkif, struct rb_root *root,
!rb_next(&persistent_gnt->node)) {

unmap_data.count = segs_to_unmap;
gnttab_unmap_refs_async(&unmap_data);
wait_for_completion(&unmap_completion);
BUG_ON(gnttab_unmap_refs_sync(&unmap_data));

put_free_pages(blkif, pages, segs_to_unmap);
segs_to_unmap = 0;
Expand All @@ -332,12 +315,7 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)
int segs_to_unmap = 0;
struct xen_blkif *blkif = container_of(work, typeof(*blkif), persistent_purge_work);
struct gntab_unmap_queue_data unmap_data;
struct completion unmap_completion;

init_completion(&unmap_completion);

unmap_data.data = &unmap_completion;
unmap_data.done = &free_persistent_gnts_unmap_callback;
unmap_data.pages = pages;
unmap_data.unmap_ops = unmap;
unmap_data.kunmap_ops = NULL;
Expand All @@ -357,18 +335,15 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)

if (++segs_to_unmap == BLKIF_MAX_SEGMENTS_PER_REQUEST) {
unmap_data.count = segs_to_unmap;
gnttab_unmap_refs_async(&unmap_data);
wait_for_completion(&unmap_completion);

BUG_ON(gnttab_unmap_refs_sync(&unmap_data));
put_free_pages(blkif, pages, segs_to_unmap);
segs_to_unmap = 0;
}
kfree(persistent_gnt);
}
if (segs_to_unmap > 0) {
unmap_data.count = segs_to_unmap;
gnttab_unmap_refs_async(&unmap_data);
wait_for_completion(&unmap_completion);
BUG_ON(gnttab_unmap_refs_sync(&unmap_data));
put_free_pages(blkif, pages, segs_to_unmap);
}
}
Expand Down
28 changes: 3 additions & 25 deletions drivers/xen/gntdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,30 +327,10 @@ static int map_grant_pages(struct grant_map *map)
return err;
}

struct unmap_grant_pages_callback_data
{
struct completion completion;
int result;
};

static void unmap_grant_callback(int result,
struct gntab_unmap_queue_data *data)
{
struct unmap_grant_pages_callback_data* d = data->data;

d->result = result;
complete(&d->completion);
}

static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
{
int i, err = 0;
struct gntab_unmap_queue_data unmap_data;
struct unmap_grant_pages_callback_data data;

init_completion(&data.completion);
unmap_data.data = &data;
unmap_data.done= &unmap_grant_callback;

if (map->notify.flags & UNMAP_NOTIFY_CLEAR_BYTE) {
int pgno = (map->notify.addr >> PAGE_SHIFT);
Expand All @@ -367,11 +347,9 @@ static int __unmap_grant_pages(struct grant_map *map, int offset, int pages)
unmap_data.pages = map->pages + offset;
unmap_data.count = pages;

gnttab_unmap_refs_async(&unmap_data);

wait_for_completion(&data.completion);
if (data.result)
return data.result;
err = gnttab_unmap_refs_sync(&unmap_data);
if (err)
return err;

for (i = 0; i < pages; i++) {
if (map->unmap_ops[offset+i].status)
Expand Down
28 changes: 28 additions & 0 deletions drivers/xen/grant-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ struct gnttab_ops {
int (*query_foreign_access)(grant_ref_t ref);
};

struct unmap_refs_callback_data {
struct completion completion;
int result;
};

static struct gnttab_ops *gnttab_interface;

static int grant_table_version;
Expand Down Expand Up @@ -863,6 +868,29 @@ void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item)
}
EXPORT_SYMBOL_GPL(gnttab_unmap_refs_async);

static void unmap_refs_callback(int result,
struct gntab_unmap_queue_data *data)
{
struct unmap_refs_callback_data *d = data->data;

d->result = result;
complete(&d->completion);
}

int gnttab_unmap_refs_sync(struct gntab_unmap_queue_data *item)
{
struct unmap_refs_callback_data data;

init_completion(&data.completion);
item->data = &data;
item->done = &unmap_refs_callback;
gnttab_unmap_refs_async(item);
wait_for_completion(&data.completion);

return data.result;
}
EXPORT_SYMBOL_GPL(gnttab_unmap_refs_sync);

static int gnttab_map_frames_v1(xen_pfn_t *frames, unsigned int nr_gframes)
{
int rc;
Expand Down
1 change: 1 addition & 0 deletions include/xen/grant_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ int gnttab_unmap_refs(struct gnttab_unmap_grant_ref *unmap_ops,
struct gnttab_unmap_grant_ref *kunmap_ops,
struct page **pages, unsigned int count);
void gnttab_unmap_refs_async(struct gntab_unmap_queue_data* item);
int gnttab_unmap_refs_sync(struct gntab_unmap_queue_data *item);


/* Perform a batch of grant map/copy operations. Retry every batch slot
Expand Down

0 comments on commit b44166c

Please sign in to comment.