block/qed: use buffer-based io

Move to _co_ versions of io functions qed_read_table() and
qed_write_table(), as we use qemu_co_mutex_unlock()
anyway.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
Vladimir Sementsov-Ogievskiy 2019-04-22 17:58:33 +03:00 committed by Kevin Wolf
parent 4ed3e0c486
commit 696e8cb292
2 changed files with 7 additions and 11 deletions

View File

@ -21,22 +21,22 @@
/* Called with table_lock held. */ /* Called with table_lock held. */
static int qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *table) static int qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *table)
{ {
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF( unsigned int bytes = s->header.cluster_size * s->header.table_size;
qiov, table->offsets, s->header.cluster_size * s->header.table_size);
int noffsets; int noffsets;
int i, ret; int i, ret;
trace_qed_read_table(s, offset, table); trace_qed_read_table(s, offset, table);
qemu_co_mutex_unlock(&s->table_lock); qemu_co_mutex_unlock(&s->table_lock);
ret = bdrv_preadv(s->bs->file, offset, &qiov); ret = bdrv_co_pread(s->bs->file, offset, bytes, table->offsets, 0);
qemu_co_mutex_lock(&s->table_lock); qemu_co_mutex_lock(&s->table_lock);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }
/* Byteswap offsets */ /* Byteswap offsets */
noffsets = qiov.size / sizeof(uint64_t); noffsets = bytes / sizeof(uint64_t);
for (i = 0; i < noffsets; i++) { for (i = 0; i < noffsets; i++) {
table->offsets[i] = le64_to_cpu(table->offsets[i]); table->offsets[i] = le64_to_cpu(table->offsets[i]);
} }
@ -66,7 +66,6 @@ static int qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table,
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;
QEDTable *new_table; QEDTable *new_table;
QEMUIOVector qiov;
size_t len_bytes; size_t len_bytes;
int ret; int ret;
@ -79,7 +78,6 @@ static int qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table,
len_bytes = (end - start) * sizeof(uint64_t); len_bytes = (end - start) * sizeof(uint64_t);
new_table = qemu_blockalign(s->bs, len_bytes); new_table = qemu_blockalign(s->bs, len_bytes);
qemu_iovec_init_buf(&qiov, new_table->offsets, len_bytes);
/* Byteswap table */ /* Byteswap table */
for (i = start; i < end; i++) { for (i = start; i < end; i++) {
@ -91,7 +89,7 @@ static int qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table,
offset += start * sizeof(uint64_t); offset += start * sizeof(uint64_t);
qemu_co_mutex_unlock(&s->table_lock); qemu_co_mutex_unlock(&s->table_lock);
ret = bdrv_pwritev(s->bs->file, offset, &qiov); ret = bdrv_co_pwrite(s->bs->file, offset, len_bytes, new_table->offsets, 0);
qemu_co_mutex_lock(&s->table_lock); qemu_co_mutex_lock(&s->table_lock);
trace_qed_write_table_cb(s, table, flush, ret); trace_qed_write_table_cb(s, table, flush, ret);
if (ret < 0) { if (ret < 0) {

View File

@ -113,15 +113,13 @@ static int coroutine_fn qed_write_header(BDRVQEDState *s)
int nsectors = DIV_ROUND_UP(sizeof(QEDHeader), BDRV_SECTOR_SIZE); int nsectors = DIV_ROUND_UP(sizeof(QEDHeader), BDRV_SECTOR_SIZE);
size_t len = nsectors * BDRV_SECTOR_SIZE; size_t len = nsectors * BDRV_SECTOR_SIZE;
uint8_t *buf; uint8_t *buf;
QEMUIOVector qiov;
int ret; int ret;
assert(s->allocating_acb || s->allocating_write_reqs_plugged); assert(s->allocating_acb || s->allocating_write_reqs_plugged);
buf = qemu_blockalign(s->bs, len); buf = qemu_blockalign(s->bs, len);
qemu_iovec_init_buf(&qiov, buf, len);
ret = bdrv_co_preadv(s->bs->file, 0, qiov.size, &qiov, 0); ret = bdrv_co_pread(s->bs->file, 0, len, buf, 0);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }
@ -129,7 +127,7 @@ static int coroutine_fn qed_write_header(BDRVQEDState *s)
/* Update header */ /* Update header */
qed_header_cpu_to_le(&s->header, (QEDHeader *) buf); qed_header_cpu_to_le(&s->header, (QEDHeader *) buf);
ret = bdrv_co_pwritev(s->bs->file, 0, qiov.size, &qiov, 0); ret = bdrv_co_pwrite(s->bs->file, 0, len, buf, 0);
if (ret < 0) { if (ret < 0) {
goto out; goto out;
} }