block: Introduce bdrv_pwritev() for qcow2_save_vmstate
Directly pass the QEMUIOVector on instead of linearising it. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
05fcc84888
commit
8d3b1a2d0b
80
block.c
80
block.c
|
@ -2131,27 +2131,21 @@ static void coroutine_fn bdrv_rw_co_entry(void *opaque)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Process a synchronous request using coroutines
|
* Process a vectored synchronous request using coroutines
|
||||||
*/
|
*/
|
||||||
static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
|
static int bdrv_rwv_co(BlockDriverState *bs, int64_t sector_num,
|
||||||
int nb_sectors, bool is_write)
|
QEMUIOVector *qiov, bool is_write)
|
||||||
{
|
{
|
||||||
QEMUIOVector qiov;
|
|
||||||
struct iovec iov = {
|
|
||||||
.iov_base = (void *)buf,
|
|
||||||
.iov_len = nb_sectors * BDRV_SECTOR_SIZE,
|
|
||||||
};
|
|
||||||
Coroutine *co;
|
Coroutine *co;
|
||||||
RwCo rwco = {
|
RwCo rwco = {
|
||||||
.bs = bs,
|
.bs = bs,
|
||||||
.sector_num = sector_num,
|
.sector_num = sector_num,
|
||||||
.nb_sectors = nb_sectors,
|
.nb_sectors = qiov->size >> BDRV_SECTOR_BITS,
|
||||||
.qiov = &qiov,
|
.qiov = qiov,
|
||||||
.is_write = is_write,
|
.is_write = is_write,
|
||||||
.ret = NOT_DONE,
|
.ret = NOT_DONE,
|
||||||
};
|
};
|
||||||
|
assert((qiov->size & (BDRV_SECTOR_SIZE - 1)) == 0);
|
||||||
qemu_iovec_init_external(&qiov, &iov, 1);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In sync call context, when the vcpu is blocked, this throttling timer
|
* In sync call context, when the vcpu is blocked, this throttling timer
|
||||||
|
@ -2177,6 +2171,22 @@ static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
|
||||||
return rwco.ret;
|
return rwco.ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Process a synchronous request using coroutines
|
||||||
|
*/
|
||||||
|
static int bdrv_rw_co(BlockDriverState *bs, int64_t sector_num, uint8_t *buf,
|
||||||
|
int nb_sectors, bool is_write)
|
||||||
|
{
|
||||||
|
QEMUIOVector qiov;
|
||||||
|
struct iovec iov = {
|
||||||
|
.iov_base = (void *)buf,
|
||||||
|
.iov_len = nb_sectors * BDRV_SECTOR_SIZE,
|
||||||
|
};
|
||||||
|
|
||||||
|
qemu_iovec_init_external(&qiov, &iov, 1);
|
||||||
|
return bdrv_rwv_co(bs, sector_num, &qiov, is_write);
|
||||||
|
}
|
||||||
|
|
||||||
/* return < 0 if error. See bdrv_write() for the return codes */
|
/* return < 0 if error. See bdrv_write() for the return codes */
|
||||||
int bdrv_read(BlockDriverState *bs, int64_t sector_num,
|
int bdrv_read(BlockDriverState *bs, int64_t sector_num,
|
||||||
uint8_t *buf, int nb_sectors)
|
uint8_t *buf, int nb_sectors)
|
||||||
|
@ -2210,6 +2220,11 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
||||||
return bdrv_rw_co(bs, sector_num, (uint8_t *)buf, nb_sectors, true);
|
return bdrv_rw_co(bs, sector_num, (uint8_t *)buf, nb_sectors, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov)
|
||||||
|
{
|
||||||
|
return bdrv_rwv_co(bs, sector_num, qiov, true);
|
||||||
|
}
|
||||||
|
|
||||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||||
void *buf, int count1)
|
void *buf, int count1)
|
||||||
{
|
{
|
||||||
|
@ -2255,15 +2270,15 @@ int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||||
return count1;
|
return count1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov)
|
||||||
const void *buf, int count1)
|
|
||||||
{
|
{
|
||||||
uint8_t tmp_buf[BDRV_SECTOR_SIZE];
|
uint8_t tmp_buf[BDRV_SECTOR_SIZE];
|
||||||
int len, nb_sectors, count;
|
int len, nb_sectors, count;
|
||||||
int64_t sector_num;
|
int64_t sector_num;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
count = count1;
|
count = qiov->size;
|
||||||
|
|
||||||
/* first write to align to sector start */
|
/* first write to align to sector start */
|
||||||
len = (BDRV_SECTOR_SIZE - offset) & (BDRV_SECTOR_SIZE - 1);
|
len = (BDRV_SECTOR_SIZE - offset) & (BDRV_SECTOR_SIZE - 1);
|
||||||
if (len > count)
|
if (len > count)
|
||||||
|
@ -2272,24 +2287,32 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
|
if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
memcpy(tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)), buf, len);
|
qemu_iovec_to_buf(qiov, 0, tmp_buf + (offset & (BDRV_SECTOR_SIZE - 1)),
|
||||||
|
len);
|
||||||
if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
|
if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
count -= len;
|
count -= len;
|
||||||
if (count == 0)
|
if (count == 0)
|
||||||
return count1;
|
return qiov->size;
|
||||||
sector_num++;
|
sector_num++;
|
||||||
buf += len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write the sectors "in place" */
|
/* write the sectors "in place" */
|
||||||
nb_sectors = count >> BDRV_SECTOR_BITS;
|
nb_sectors = count >> BDRV_SECTOR_BITS;
|
||||||
if (nb_sectors > 0) {
|
if (nb_sectors > 0) {
|
||||||
if ((ret = bdrv_write(bs, sector_num, buf, nb_sectors)) < 0)
|
QEMUIOVector qiov_inplace;
|
||||||
|
|
||||||
|
qemu_iovec_init(&qiov_inplace, qiov->niov);
|
||||||
|
qemu_iovec_concat(&qiov_inplace, qiov, len,
|
||||||
|
nb_sectors << BDRV_SECTOR_BITS);
|
||||||
|
ret = bdrv_writev(bs, sector_num, &qiov_inplace);
|
||||||
|
qemu_iovec_destroy(&qiov_inplace);
|
||||||
|
if (ret < 0) {
|
||||||
return ret;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
sector_num += nb_sectors;
|
sector_num += nb_sectors;
|
||||||
len = nb_sectors << BDRV_SECTOR_BITS;
|
len = nb_sectors << BDRV_SECTOR_BITS;
|
||||||
buf += len;
|
|
||||||
count -= len;
|
count -= len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2297,11 +2320,24 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
|
if ((ret = bdrv_read(bs, sector_num, tmp_buf, 1)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
memcpy(tmp_buf, buf, count);
|
qemu_iovec_to_buf(qiov, qiov->size - count, tmp_buf, count);
|
||||||
if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
|
if ((ret = bdrv_write(bs, sector_num, tmp_buf, 1)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
return count1;
|
return qiov->size;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
||||||
|
const void *buf, int count1)
|
||||||
|
{
|
||||||
|
QEMUIOVector qiov;
|
||||||
|
struct iovec iov = {
|
||||||
|
.iov_base = (void *) buf,
|
||||||
|
.iov_len = count1,
|
||||||
|
};
|
||||||
|
|
||||||
|
qemu_iovec_init_external(&qiov, &iov, 1);
|
||||||
|
return bdrv_pwritev(bs, offset, &qiov);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -1658,18 +1658,12 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,
|
||||||
BDRVQcowState *s = bs->opaque;
|
BDRVQcowState *s = bs->opaque;
|
||||||
int growable = bs->growable;
|
int growable = bs->growable;
|
||||||
int ret;
|
int ret;
|
||||||
void *buf;
|
|
||||||
|
|
||||||
buf = qemu_blockalign(bs, qiov->size);
|
|
||||||
qemu_iovec_to_buf(qiov, 0, buf, qiov->size);
|
|
||||||
|
|
||||||
BLKDBG_EVENT(bs->file, BLKDBG_VMSTATE_SAVE);
|
BLKDBG_EVENT(bs->file, BLKDBG_VMSTATE_SAVE);
|
||||||
bs->growable = 1;
|
bs->growable = 1;
|
||||||
ret = bdrv_pwrite(bs, qcow2_vm_state_offset(s) + pos, buf, qiov->size);
|
ret = bdrv_pwritev(bs, qcow2_vm_state_offset(s) + pos, qiov);
|
||||||
bs->growable = growable;
|
bs->growable = growable;
|
||||||
|
|
||||||
qemu_vfree(buf);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,10 +166,12 @@ int bdrv_read_unthrottled(BlockDriverState *bs, int64_t sector_num,
|
||||||
uint8_t *buf, int nb_sectors);
|
uint8_t *buf, int nb_sectors);
|
||||||
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
int bdrv_write(BlockDriverState *bs, int64_t sector_num,
|
||||||
const uint8_t *buf, int nb_sectors);
|
const uint8_t *buf, int nb_sectors);
|
||||||
|
int bdrv_writev(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qiov);
|
||||||
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
int bdrv_pread(BlockDriverState *bs, int64_t offset,
|
||||||
void *buf, int count);
|
void *buf, int count);
|
||||||
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
|
||||||
const void *buf, int count);
|
const void *buf, int count);
|
||||||
|
int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov);
|
||||||
int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
|
int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset,
|
||||||
const void *buf, int count);
|
const void *buf, int count);
|
||||||
int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
|
int coroutine_fn bdrv_co_readv(BlockDriverState *bs, int64_t sector_num,
|
||||||
|
|
Loading…
Reference in New Issue