qed: Remove callback from qed_write_table()

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Kevin Wolf 2016-11-15 11:14:01 +01:00
parent 29470d11bf
commit 453e53e2a1
3 changed files with 22 additions and 45 deletions

View File

@ -61,12 +61,9 @@ out:
* @index: Index of first element * @index: Index of first element
* @n: Number of elements * @n: Number of elements
* @flush: Whether or not to sync to disk * @flush: Whether or not to sync to disk
* @cb: Completion function
* @opaque: Argument for completion function
*/ */
static void qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table, static int qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table,
unsigned int index, unsigned int n, bool flush, unsigned int index, unsigned int n, bool flush)
BlockCompletionFunc *cb, void *opaque)
{ {
unsigned int sector_mask = BDRV_SECTOR_SIZE / sizeof(uint64_t) - 1; unsigned int sector_mask = BDRV_SECTOR_SIZE / sizeof(uint64_t) - 1;
unsigned int start, end, i; unsigned int start, end, i;
@ -118,15 +115,7 @@ static void qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table,
ret = 0; ret = 0;
out: out:
qemu_vfree(new_table); qemu_vfree(new_table);
cb(opaque, ret); return ret;
}
/**
* Propagate return value from async callback
*/
static void qed_sync_cb(void *opaque, int ret)
{
*(int *)opaque = ret;
} }
int qed_read_l1_table_sync(BDRVQEDState *s) int qed_read_l1_table_sync(BDRVQEDState *s)
@ -134,23 +123,17 @@ int qed_read_l1_table_sync(BDRVQEDState *s)
return qed_read_table(s, s->header.l1_table_offset, s->l1_table); return qed_read_table(s, s->header.l1_table_offset, s->l1_table);
} }
void qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n, int qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n)
BlockCompletionFunc *cb, void *opaque)
{ {
BLKDBG_EVENT(s->bs->file, BLKDBG_L1_UPDATE); BLKDBG_EVENT(s->bs->file, BLKDBG_L1_UPDATE);
qed_write_table(s, s->header.l1_table_offset, return qed_write_table(s, s->header.l1_table_offset,
s->l1_table, index, n, false, cb, opaque); s->l1_table, index, n, false);
} }
int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index,
unsigned int n) unsigned int n)
{ {
int ret = -EINPROGRESS; return qed_write_l1_table(s, index, n);
qed_write_l1_table(s, index, n, qed_sync_cb, &ret);
BDRV_POLL_WHILE(s->bs, ret == -EINPROGRESS);
return ret;
} }
int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset) int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset)
@ -197,22 +180,16 @@ int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offset
return qed_read_l2_table(s, request, offset); return qed_read_l2_table(s, request, offset);
} }
void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, int qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
unsigned int index, unsigned int n, bool flush, unsigned int index, unsigned int n, bool flush)
BlockCompletionFunc *cb, void *opaque)
{ {
BLKDBG_EVENT(s->bs->file, BLKDBG_L2_UPDATE); BLKDBG_EVENT(s->bs->file, BLKDBG_L2_UPDATE);
qed_write_table(s, request->l2_table->offset, return qed_write_table(s, request->l2_table->offset,
request->l2_table->table, index, n, flush, cb, opaque); request->l2_table->table, index, n, flush);
} }
int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request, int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
unsigned int index, unsigned int n, bool flush) unsigned int index, unsigned int n, bool flush)
{ {
int ret = -EINPROGRESS; return qed_write_l2_table(s, request, index, n, flush);
qed_write_l2_table(s, request, index, n, flush, qed_sync_cb, &ret);
BDRV_POLL_WHILE(s->bs, ret == -EINPROGRESS);
return ret;
} }

View File

@ -1000,7 +1000,8 @@ static void qed_aio_write_l1_update(void *opaque, int ret)
index = qed_l1_index(s, acb->cur_pos); index = qed_l1_index(s, acb->cur_pos);
s->l1_table->offsets[index] = acb->request.l2_table->offset; s->l1_table->offsets[index] = acb->request.l2_table->offset;
qed_write_l1_table(s, index, 1, qed_commit_l2_update, acb); ret = qed_write_l1_table(s, index, 1);
qed_commit_l2_update(acb, ret);
} }
/** /**
@ -1027,12 +1028,13 @@ static void qed_aio_write_l2_update(QEDAIOCB *acb, int ret, uint64_t offset)
if (need_alloc) { if (need_alloc) {
/* Write out the whole new L2 table */ /* Write out the whole new L2 table */
qed_write_l2_table(s, &acb->request, 0, s->table_nelems, true, ret = qed_write_l2_table(s, &acb->request, 0, s->table_nelems, true);
qed_aio_write_l1_update, acb); qed_aio_write_l1_update(acb, ret);
} else { } else {
/* Write out only the updated part of the L2 table */ /* Write out only the updated part of the L2 table */
qed_write_l2_table(s, &acb->request, index, acb->cur_nclusters, false, ret = qed_write_l2_table(s, &acb->request, index, acb->cur_nclusters,
qed_aio_next_io_cb, acb); false);
qed_aio_next_io(acb, ret);
} }
return; return;

View File

@ -220,16 +220,14 @@ void qed_commit_l2_cache_entry(L2TableCache *l2_cache, CachedL2Table *l2_table);
* Table I/O functions * Table I/O functions
*/ */
int qed_read_l1_table_sync(BDRVQEDState *s); int qed_read_l1_table_sync(BDRVQEDState *s);
void qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n, int qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n);
BlockCompletionFunc *cb, void *opaque);
int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, int qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index,
unsigned int n); unsigned int n);
int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, int qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
uint64_t offset); uint64_t offset);
int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset); int qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset);
void qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, int qed_write_l2_table(BDRVQEDState *s, QEDRequest *request,
unsigned int index, unsigned int n, bool flush, unsigned int index, unsigned int n, bool flush);
BlockCompletionFunc *cb, void *opaque);
int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request, int qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request,
unsigned int index, unsigned int n, bool flush); unsigned int index, unsigned int n, bool flush);