mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-11 03:24:58 -06:00
block/qed: use qemu_iovec_init_buf
Use new qemu_iovec_init_buf() instead of qemu_iovec_init_external( ... , 1), which simplifies the code. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Reviewed-by: Eric Blake <eblake@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Message-id: 20190218140926.333779-11-vsementsov@virtuozzo.com Message-Id: <20190218140926.333779-11-vsementsov@virtuozzo.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
c793d4ff20
commit
342544f98b
2 changed files with 12 additions and 35 deletions
|
@ -21,16 +21,11 @@
|
||||||
/* 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;
|
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(
|
||||||
|
qiov, table->offsets, s->header.cluster_size * s->header.table_size);
|
||||||
int noffsets;
|
int noffsets;
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
|
||||||
struct iovec iov = {
|
|
||||||
.iov_base = table->offsets,
|
|
||||||
.iov_len = s->header.cluster_size * s->header.table_size,
|
|
||||||
};
|
|
||||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
|
||||||
|
|
||||||
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);
|
||||||
|
@ -71,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;
|
||||||
struct iovec iov;
|
|
||||||
QEMUIOVector qiov;
|
QEMUIOVector qiov;
|
||||||
size_t len_bytes;
|
size_t len_bytes;
|
||||||
int ret;
|
int ret;
|
||||||
|
@ -85,11 +79,7 @@ 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);
|
||||||
iov = (struct iovec) {
|
qemu_iovec_init_buf(&qiov, new_table->offsets, len_bytes);
|
||||||
.iov_base = new_table->offsets,
|
|
||||||
.iov_len = len_bytes,
|
|
||||||
};
|
|
||||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
|
||||||
|
|
||||||
/* Byteswap table */
|
/* Byteswap table */
|
||||||
for (i = start; i < end; i++) {
|
for (i = start; i < end; i++) {
|
||||||
|
|
31
block/qed.c
31
block/qed.c
|
@ -113,18 +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;
|
||||||
struct iovec iov;
|
|
||||||
QEMUIOVector qiov;
|
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);
|
||||||
iov = (struct iovec) {
|
qemu_iovec_init_buf(&qiov, buf, len);
|
||||||
.iov_base = buf,
|
|
||||||
.iov_len = len,
|
|
||||||
};
|
|
||||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
|
||||||
|
|
||||||
ret = bdrv_co_preadv(s->bs->file, 0, qiov.size, &qiov, 0);
|
ret = bdrv_co_preadv(s->bs->file, 0, qiov.size, &qiov, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -913,7 +908,6 @@ static int coroutine_fn qed_copy_from_backing_file(BDRVQEDState *s,
|
||||||
{
|
{
|
||||||
QEMUIOVector qiov;
|
QEMUIOVector qiov;
|
||||||
QEMUIOVector *backing_qiov = NULL;
|
QEMUIOVector *backing_qiov = NULL;
|
||||||
struct iovec iov;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Skip copy entirely if there is no work to do */
|
/* Skip copy entirely if there is no work to do */
|
||||||
|
@ -921,11 +915,7 @@ static int coroutine_fn qed_copy_from_backing_file(BDRVQEDState *s,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
iov = (struct iovec) {
|
qemu_iovec_init_buf(&qiov, qemu_blockalign(s->bs, len), len);
|
||||||
.iov_base = qemu_blockalign(s->bs, len),
|
|
||||||
.iov_len = len,
|
|
||||||
};
|
|
||||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
|
||||||
|
|
||||||
ret = qed_read_backing_file(s, pos, &qiov, &backing_qiov);
|
ret = qed_read_backing_file(s, pos, &qiov, &backing_qiov);
|
||||||
|
|
||||||
|
@ -946,7 +936,7 @@ static int coroutine_fn qed_copy_from_backing_file(BDRVQEDState *s,
|
||||||
}
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
out:
|
out:
|
||||||
qemu_vfree(iov.iov_base);
|
qemu_vfree(qemu_iovec_buf(&qiov));
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1447,8 +1437,12 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
|
||||||
BdrvRequestFlags flags)
|
BdrvRequestFlags flags)
|
||||||
{
|
{
|
||||||
BDRVQEDState *s = bs->opaque;
|
BDRVQEDState *s = bs->opaque;
|
||||||
QEMUIOVector qiov;
|
|
||||||
struct iovec iov;
|
/*
|
||||||
|
* Zero writes start without an I/O buffer. If a buffer becomes necessary
|
||||||
|
* then it will be allocated during request processing.
|
||||||
|
*/
|
||||||
|
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes);
|
||||||
|
|
||||||
/* Fall back if the request is not aligned */
|
/* Fall back if the request is not aligned */
|
||||||
if (qed_offset_into_cluster(s, offset) ||
|
if (qed_offset_into_cluster(s, offset) ||
|
||||||
|
@ -1456,13 +1450,6 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Zero writes start without an I/O buffer. If a buffer becomes necessary
|
|
||||||
* then it will be allocated during request processing.
|
|
||||||
*/
|
|
||||||
iov.iov_base = NULL;
|
|
||||||
iov.iov_len = bytes;
|
|
||||||
|
|
||||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
|
||||||
return qed_co_request(bs, offset >> BDRV_SECTOR_BITS, &qiov,
|
return qed_co_request(bs, offset >> BDRV_SECTOR_BITS, &qiov,
|
||||||
bytes >> BDRV_SECTOR_BITS,
|
bytes >> BDRV_SECTOR_BITS,
|
||||||
QED_AIOCB_WRITE | QED_AIOCB_ZERO);
|
QED_AIOCB_WRITE | QED_AIOCB_ZERO);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue