block: Convert bdrv_pwrite(v/_sync) to BdrvChild

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Max Reitz <mreitz@redhat.com>
Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
Kevin Wolf 2016-06-20 20:09:15 +02:00
parent cf2ab8fc34
commit d9ca2ea2e2
15 changed files with 66 additions and 70 deletions

View File

@ -737,11 +737,11 @@ int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes)
return bdrv_preadv(child, offset, &qiov); return bdrv_preadv(child, offset, &qiov);
} }
int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov) int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov)
{ {
int ret; int ret;
ret = bdrv_prwv_co(bs, offset, qiov, true, 0); ret = bdrv_prwv_co(child->bs, offset, qiov, true, 0);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
@ -749,8 +749,7 @@ int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov)
return qiov->size; return qiov->size;
} }
int bdrv_pwrite(BlockDriverState *bs, int64_t offset, int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int bytes)
const void *buf, int bytes)
{ {
QEMUIOVector qiov; QEMUIOVector qiov;
struct iovec iov = { struct iovec iov = {
@ -763,7 +762,7 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
} }
qemu_iovec_init_external(&qiov, &iov, 1); qemu_iovec_init_external(&qiov, &iov, 1);
return bdrv_pwritev(bs, offset, &qiov); return bdrv_pwritev(child, offset, &qiov);
} }
/* /*
@ -772,17 +771,17 @@ int bdrv_pwrite(BlockDriverState *bs, int64_t offset,
* *
* Returns 0 on success, -errno in error cases. * Returns 0 on success, -errno in error cases.
*/ */
int bdrv_pwrite_sync(BlockDriverState *bs, int64_t offset, int bdrv_pwrite_sync(BdrvChild *child, int64_t offset,
const void *buf, int count) const void *buf, int count)
{ {
int ret; int ret;
ret = bdrv_pwrite(bs, offset, buf, count); ret = bdrv_pwrite(child, offset, buf, count);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }
ret = bdrv_flush(bs); ret = bdrv_flush(child->bs);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
} }

View File

@ -250,7 +250,7 @@ static coroutine_fn int parallels_co_flush_to_os(BlockDriverState *bs)
if (off + to_write > s->header_size) { if (off + to_write > s->header_size) {
to_write = s->header_size - off; to_write = s->header_size - off;
} }
ret = bdrv_pwrite(bs->file->bs, off, (uint8_t *)s->header + off, ret = bdrv_pwrite(bs->file, off, (uint8_t *)s->header + off,
to_write); to_write);
if (ret < 0) { if (ret < 0) {
qemu_co_mutex_unlock(&s->lock); qemu_co_mutex_unlock(&s->lock);
@ -432,7 +432,7 @@ static int parallels_check(BlockDriverState *bs, BdrvCheckResult *res,
} }
if (flush_bat) { if (flush_bat) {
ret = bdrv_pwrite_sync(bs->file->bs, 0, s->header, s->header_size); ret = bdrv_pwrite_sync(bs->file, 0, s->header, s->header_size);
if (ret < 0) { if (ret < 0) {
res->check_errors++; res->check_errors++;
return ret; return ret;
@ -563,7 +563,7 @@ static int parallels_update_header(BlockDriverState *bs)
if (size > s->header_size) { if (size > s->header_size) {
size = s->header_size; size = s->header_size;
} }
return bdrv_pwrite_sync(bs->file->bs, 0, s->header, size); return bdrv_pwrite_sync(bs->file, 0, s->header, size);
} }
static int parallels_open(BlockDriverState *bs, QDict *options, int flags, static int parallels_open(BlockDriverState *bs, QDict *options, int flags,

View File

@ -390,7 +390,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
/* update the L1 entry */ /* update the L1 entry */
s->l1_table[l1_index] = l2_offset; s->l1_table[l1_index] = l2_offset;
tmp = cpu_to_be64(l2_offset); tmp = cpu_to_be64(l2_offset);
if (bdrv_pwrite_sync(bs->file->bs, if (bdrv_pwrite_sync(bs->file,
s->l1_table_offset + l1_index * sizeof(tmp), s->l1_table_offset + l1_index * sizeof(tmp),
&tmp, sizeof(tmp)) < 0) &tmp, sizeof(tmp)) < 0)
return 0; return 0;
@ -420,7 +420,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
l2_table = s->l2_cache + (min_index << s->l2_bits); l2_table = s->l2_cache + (min_index << s->l2_bits);
if (new_l2_table) { if (new_l2_table) {
memset(l2_table, 0, s->l2_size * sizeof(uint64_t)); memset(l2_table, 0, s->l2_size * sizeof(uint64_t));
if (bdrv_pwrite_sync(bs->file->bs, l2_offset, l2_table, if (bdrv_pwrite_sync(bs->file, l2_offset, l2_table,
s->l2_size * sizeof(uint64_t)) < 0) s->l2_size * sizeof(uint64_t)) < 0)
return 0; return 0;
} else { } else {
@ -450,7 +450,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
cluster_offset = (cluster_offset + s->cluster_size - 1) & cluster_offset = (cluster_offset + s->cluster_size - 1) &
~(s->cluster_size - 1); ~(s->cluster_size - 1);
/* write the cluster content */ /* write the cluster content */
if (bdrv_pwrite(bs->file->bs, cluster_offset, s->cluster_cache, if (bdrv_pwrite(bs->file, cluster_offset, s->cluster_cache,
s->cluster_size) != s->cluster_size) !=
s->cluster_size) s->cluster_size)
return -1; return -1;
@ -480,7 +480,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
errno = EIO; errno = EIO;
return -1; return -1;
} }
if (bdrv_pwrite(bs->file->bs, if (bdrv_pwrite(bs->file,
cluster_offset + i * 512, cluster_offset + i * 512,
s->cluster_data, 512) != 512) s->cluster_data, 512) != 512)
return -1; return -1;
@ -495,7 +495,7 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
/* update L2 table */ /* update L2 table */
tmp = cpu_to_be64(cluster_offset); tmp = cpu_to_be64(cluster_offset);
l2_table[l2_index] = tmp; l2_table[l2_index] = tmp;
if (bdrv_pwrite_sync(bs->file->bs, l2_offset + l2_index * sizeof(tmp), if (bdrv_pwrite_sync(bs->file, l2_offset + l2_index * sizeof(tmp),
&tmp, sizeof(tmp)) < 0) &tmp, sizeof(tmp)) < 0)
return 0; return 0;
} }
@ -899,7 +899,7 @@ static int qcow_make_empty(BlockDriverState *bs)
int ret; int ret;
memset(s->l1_table, 0, l1_length); memset(s->l1_table, 0, l1_length);
if (bdrv_pwrite_sync(bs->file->bs, s->l1_table_offset, s->l1_table, if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table,
l1_length) < 0) l1_length) < 0)
return -1; return -1;
ret = bdrv_truncate(bs->file->bs, s->l1_table_offset + l1_length); ret = bdrv_truncate(bs->file->bs, s->l1_table_offset + l1_length);
@ -1025,7 +1025,7 @@ static int qcow_write_compressed(BlockDriverState *bs, int64_t sector_num,
} }
cluster_offset &= s->cluster_offset_mask; cluster_offset &= s->cluster_offset_mask;
ret = bdrv_pwrite(bs->file->bs, cluster_offset, out_buf, out_len); ret = bdrv_pwrite(bs->file, cluster_offset, out_buf, out_len);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }

View File

@ -210,7 +210,7 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i)
BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE); BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE);
} }
ret = bdrv_pwrite(bs->file->bs, c->entries[i].offset, ret = bdrv_pwrite(bs->file, c->entries[i].offset,
qcow2_cache_get_table_addr(bs, c, i), s->cluster_size); qcow2_cache_get_table_addr(bs, c, i), s->cluster_size);
if (ret < 0) { if (ret < 0) {
return ret; return ret;

View File

@ -108,7 +108,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_WRITE_TABLE); BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_WRITE_TABLE);
for(i = 0; i < s->l1_size; i++) for(i = 0; i < s->l1_size; i++)
new_l1_table[i] = cpu_to_be64(new_l1_table[i]); new_l1_table[i] = cpu_to_be64(new_l1_table[i]);
ret = bdrv_pwrite_sync(bs->file->bs, new_l1_table_offset, ret = bdrv_pwrite_sync(bs->file, new_l1_table_offset,
new_l1_table, new_l1_size2); new_l1_table, new_l1_size2);
if (ret < 0) if (ret < 0)
goto fail; goto fail;
@ -119,7 +119,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_ACTIVATE_TABLE); BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_ACTIVATE_TABLE);
cpu_to_be32w((uint32_t*)data, new_l1_size); cpu_to_be32w((uint32_t*)data, new_l1_size);
stq_be_p(data + 4, new_l1_table_offset); stq_be_p(data + 4, new_l1_table_offset);
ret = bdrv_pwrite_sync(bs->file->bs, offsetof(QCowHeader, l1_size), ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_size),
data, sizeof(data)); data, sizeof(data));
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
@ -185,7 +185,7 @@ int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index)
} }
BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE); BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE);
ret = bdrv_pwrite_sync(bs->file->bs, ret = bdrv_pwrite_sync(bs->file,
s->l1_table_offset + 8 * l1_start_index, s->l1_table_offset + 8 * l1_start_index,
buf, sizeof(buf)); buf, sizeof(buf));
if (ret < 0) { if (ret < 0) {

View File

@ -431,7 +431,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
if (refcount_table_index < s->refcount_table_size) { if (refcount_table_index < s->refcount_table_size) {
uint64_t data64 = cpu_to_be64(new_block); uint64_t data64 = cpu_to_be64(new_block);
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_HOOKUP); BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_HOOKUP);
ret = bdrv_pwrite_sync(bs->file->bs, ret = bdrv_pwrite_sync(bs->file,
s->refcount_table_offset + refcount_table_index * sizeof(uint64_t), s->refcount_table_offset + refcount_table_index * sizeof(uint64_t),
&data64, sizeof(data64)); &data64, sizeof(data64));
if (ret < 0) { if (ret < 0) {
@ -533,7 +533,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
/* Write refcount blocks to disk */ /* Write refcount blocks to disk */
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS); BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_BLOCKS);
ret = bdrv_pwrite_sync(bs->file->bs, meta_offset, new_blocks, ret = bdrv_pwrite_sync(bs->file, meta_offset, new_blocks,
blocks_clusters * s->cluster_size); blocks_clusters * s->cluster_size);
g_free(new_blocks); g_free(new_blocks);
new_blocks = NULL; new_blocks = NULL;
@ -547,7 +547,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
} }
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE); BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE);
ret = bdrv_pwrite_sync(bs->file->bs, table_offset, new_table, ret = bdrv_pwrite_sync(bs->file, table_offset, new_table,
table_size * sizeof(uint64_t)); table_size * sizeof(uint64_t));
if (ret < 0) { if (ret < 0) {
goto fail_table; goto fail_table;
@ -565,7 +565,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
cpu_to_be64w(&data.d64, table_offset); cpu_to_be64w(&data.d64, table_offset);
cpu_to_be32w(&data.d32, table_clusters); cpu_to_be32w(&data.d32, table_clusters);
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE); BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE);
ret = bdrv_pwrite_sync(bs->file->bs, ret = bdrv_pwrite_sync(bs->file,
offsetof(QCowHeader, refcount_table_offset), offsetof(QCowHeader, refcount_table_offset),
&data, sizeof(data)); &data, sizeof(data));
if (ret < 0) { if (ret < 0) {
@ -1223,7 +1223,7 @@ fail:
cpu_to_be64s(&l1_table[i]); cpu_to_be64s(&l1_table[i]);
} }
ret = bdrv_pwrite_sync(bs->file->bs, l1_table_offset, ret = bdrv_pwrite_sync(bs->file, l1_table_offset,
l1_table, l1_size2); l1_table, l1_size2);
for (i = 0; i < l1_size; i++) { for (i = 0; i < l1_size; i++) {
@ -1664,7 +1664,7 @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
goto fail; goto fail;
} }
ret = bdrv_pwrite(bs->file->bs, l2_offset, l2_table, ret = bdrv_pwrite(bs->file, l2_offset, l2_table,
s->cluster_size); s->cluster_size);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "ERROR: Could not write L2 table: %s\n", fprintf(stderr, "ERROR: Could not write L2 table: %s\n",
@ -2147,7 +2147,7 @@ write_refblocks:
} }
assert(reftable_size < INT_MAX / sizeof(uint64_t)); assert(reftable_size < INT_MAX / sizeof(uint64_t));
ret = bdrv_pwrite(bs->file->bs, reftable_offset, on_disk_reftable, ret = bdrv_pwrite(bs->file, reftable_offset, on_disk_reftable,
reftable_size * sizeof(uint64_t)); reftable_size * sizeof(uint64_t));
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "ERROR writing reftable: %s\n", strerror(-ret)); fprintf(stderr, "ERROR writing reftable: %s\n", strerror(-ret));
@ -2159,8 +2159,8 @@ write_refblocks:
reftable_offset); reftable_offset);
cpu_to_be32w(&reftable_offset_and_clusters.reftable_clusters, cpu_to_be32w(&reftable_offset_and_clusters.reftable_clusters,
size_to_clusters(s, reftable_size * sizeof(uint64_t))); size_to_clusters(s, reftable_size * sizeof(uint64_t)));
ret = bdrv_pwrite_sync(bs->file->bs, offsetof(QCowHeader, ret = bdrv_pwrite_sync(bs->file,
refcount_table_offset), offsetof(QCowHeader, refcount_table_offset),
&reftable_offset_and_clusters, &reftable_offset_and_clusters,
sizeof(reftable_offset_and_clusters)); sizeof(reftable_offset_and_clusters));
if (ret < 0) { if (ret < 0) {
@ -2560,7 +2560,7 @@ static int flush_refblock(BlockDriverState *bs, uint64_t **reftable,
return ret; return ret;
} }
ret = bdrv_pwrite(bs->file->bs, offset, refblock, s->cluster_size); ret = bdrv_pwrite(bs->file, offset, refblock, s->cluster_size);
if (ret < 0) { if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write refblock"); error_setg_errno(errp, -ret, "Failed to write refblock");
return ret; return ret;
@ -2830,7 +2830,7 @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
cpu_to_be64s(&new_reftable[i]); cpu_to_be64s(&new_reftable[i]);
} }
ret = bdrv_pwrite(bs->file->bs, new_reftable_offset, new_reftable, ret = bdrv_pwrite(bs->file, new_reftable_offset, new_reftable,
new_reftable_size * sizeof(uint64_t)); new_reftable_size * sizeof(uint64_t));
for (i = 0; i < new_reftable_size; i++) { for (i = 0; i < new_reftable_size; i++) {

View File

@ -217,25 +217,25 @@ static int qcow2_write_snapshots(BlockDriverState *bs)
h.name_size = cpu_to_be16(name_size); h.name_size = cpu_to_be16(name_size);
offset = align_offset(offset, 8); offset = align_offset(offset, 8);
ret = bdrv_pwrite(bs->file->bs, offset, &h, sizeof(h)); ret = bdrv_pwrite(bs->file, offset, &h, sizeof(h));
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
offset += sizeof(h); offset += sizeof(h);
ret = bdrv_pwrite(bs->file->bs, offset, &extra, sizeof(extra)); ret = bdrv_pwrite(bs->file, offset, &extra, sizeof(extra));
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
offset += sizeof(extra); offset += sizeof(extra);
ret = bdrv_pwrite(bs->file->bs, offset, sn->id_str, id_str_size); ret = bdrv_pwrite(bs->file, offset, sn->id_str, id_str_size);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
offset += id_str_size; offset += id_str_size;
ret = bdrv_pwrite(bs->file->bs, offset, sn->name, name_size); ret = bdrv_pwrite(bs->file, offset, sn->name, name_size);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
@ -257,7 +257,7 @@ static int qcow2_write_snapshots(BlockDriverState *bs)
header_data.nb_snapshots = cpu_to_be32(s->nb_snapshots); header_data.nb_snapshots = cpu_to_be32(s->nb_snapshots);
header_data.snapshots_offset = cpu_to_be64(snapshots_offset); header_data.snapshots_offset = cpu_to_be64(snapshots_offset);
ret = bdrv_pwrite_sync(bs->file->bs, offsetof(QCowHeader, nb_snapshots), ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots),
&header_data, sizeof(header_data)); &header_data, sizeof(header_data));
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
@ -399,7 +399,7 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
goto fail; goto fail;
} }
ret = bdrv_pwrite(bs->file->bs, sn->l1_table_offset, l1_table, ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table,
s->l1_size * sizeof(uint64_t)); s->l1_size * sizeof(uint64_t));
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
@ -530,7 +530,7 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
goto fail; goto fail;
} }
ret = bdrv_pwrite_sync(bs->file->bs, s->l1_table_offset, sn_l1_table, ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset, sn_l1_table,
cur_l1_bytes); cur_l1_bytes);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;

View File

@ -249,7 +249,7 @@ int qcow2_mark_dirty(BlockDriverState *bs)
} }
val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY); val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY);
ret = bdrv_pwrite(bs->file->bs, offsetof(QCowHeader, incompatible_features), ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_features),
&val, sizeof(val)); &val, sizeof(val));
if (ret < 0) { if (ret < 0) {
return ret; return ret;
@ -1976,7 +1976,7 @@ int qcow2_update_header(BlockDriverState *bs)
} }
/* Write the new header */ /* Write the new header */
ret = bdrv_pwrite(bs->file->bs, 0, header, s->cluster_size); ret = bdrv_pwrite(bs->file, 0, header, s->cluster_size);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
@ -2059,7 +2059,7 @@ static int preallocate(BlockDriverState *bs)
*/ */
if (host_offset != 0) { if (host_offset != 0) {
uint8_t data = 0; uint8_t data = 0;
ret = bdrv_pwrite(bs->file->bs, (host_offset + cur_bytes) - 1, ret = bdrv_pwrite(bs->file, (host_offset + cur_bytes) - 1,
&data, 1); &data, 1);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
@ -2523,7 +2523,7 @@ static int qcow2_truncate(BlockDriverState *bs, int64_t offset)
/* write updated header.size */ /* write updated header.size */
offset = cpu_to_be64(offset); offset = cpu_to_be64(offset);
ret = bdrv_pwrite_sync(bs->file->bs, offsetof(QCowHeader, size), ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size),
&offset, sizeof(uint64_t)); &offset, sizeof(uint64_t));
if (ret < 0) { if (ret < 0) {
return ret; return ret;
@ -2660,7 +2660,7 @@ static int qcow2_write_compressed(BlockDriverState *bs, int64_t sector_num,
} }
BLKDBG_EVENT(bs->file, BLKDBG_WRITE_COMPRESSED); BLKDBG_EVENT(bs->file, BLKDBG_WRITE_COMPRESSED);
ret = bdrv_pwrite(bs->file->bs, cluster_offset, out_buf, out_len); ret = bdrv_pwrite(bs->file, cluster_offset, out_buf, out_len);
if (ret < 0) { if (ret < 0) {
goto fail; goto fail;
} }
@ -2742,7 +2742,7 @@ static int make_completely_empty(BlockDriverState *bs)
cpu_to_be64w(&l1_ofs_rt_ofs_cls.l1_offset, 3 * s->cluster_size); cpu_to_be64w(&l1_ofs_rt_ofs_cls.l1_offset, 3 * s->cluster_size);
cpu_to_be64w(&l1_ofs_rt_ofs_cls.reftable_offset, s->cluster_size); cpu_to_be64w(&l1_ofs_rt_ofs_cls.reftable_offset, s->cluster_size);
cpu_to_be32w(&l1_ofs_rt_ofs_cls.reftable_clusters, 1); cpu_to_be32w(&l1_ofs_rt_ofs_cls.reftable_clusters, 1);
ret = bdrv_pwrite_sync(bs->file->bs, offsetof(QCowHeader, l1_table_offset), ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_table_offset),
&l1_ofs_rt_ofs_cls, sizeof(l1_ofs_rt_ofs_cls)); &l1_ofs_rt_ofs_cls, sizeof(l1_ofs_rt_ofs_cls));
if (ret < 0) { if (ret < 0) {
goto fail_broken_refcounts; goto fail_broken_refcounts;
@ -2773,7 +2773,7 @@ static int make_completely_empty(BlockDriverState *bs)
/* Enter the first refblock into the reftable */ /* Enter the first refblock into the reftable */
rt_entry = cpu_to_be64(2 * s->cluster_size); rt_entry = cpu_to_be64(2 * s->cluster_size);
ret = bdrv_pwrite_sync(bs->file->bs, s->cluster_size, ret = bdrv_pwrite_sync(bs->file, s->cluster_size,
&rt_entry, sizeof(rt_entry)); &rt_entry, sizeof(rt_entry));
if (ret < 0) { if (ret < 0) {
goto fail_broken_refcounts; goto fail_broken_refcounts;

View File

@ -86,7 +86,7 @@ int qed_write_header_sync(BDRVQEDState *s)
int ret; int ret;
qed_header_cpu_to_le(&s->header, &le); qed_header_cpu_to_le(&s->header, &le);
ret = bdrv_pwrite(s->bs->file->bs, 0, &le, sizeof(le)); ret = bdrv_pwrite(s->bs->file, 0, &le, sizeof(le));
if (ret != sizeof(le)) { if (ret != sizeof(le)) {
return ret; return ret;
} }
@ -1575,7 +1575,7 @@ static int bdrv_qed_change_backing_file(BlockDriverState *bs,
} }
/* Write new header */ /* Write new header */
ret = bdrv_pwrite_sync(bs->file->bs, 0, buffer, buffer_len); ret = bdrv_pwrite_sync(bs->file, 0, buffer, buffer_len);
g_free(buffer); g_free(buffer);
if (ret == 0) { if (ret == 0) {
memcpy(&s->header, &new_header, sizeof(new_header)); memcpy(&s->header, &new_header, sizeof(new_header));

View File

@ -670,7 +670,7 @@ vdi_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
* acquire the lock and thus the padded cluster is written before * acquire the lock and thus the padded cluster is written before
* the other coroutines can write to the affected area. */ * the other coroutines can write to the affected area. */
qemu_co_mutex_lock(&s->write_lock); qemu_co_mutex_lock(&s->write_lock);
ret = bdrv_pwrite(bs->file->bs, data_offset, block, s->block_size); ret = bdrv_pwrite(bs->file, data_offset, block, s->block_size);
qemu_co_mutex_unlock(&s->write_lock); qemu_co_mutex_unlock(&s->write_lock);
} else { } else {
uint64_t data_offset = s->header.offset_data + uint64_t data_offset = s->header.offset_data +

View File

@ -194,7 +194,7 @@ static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
/* full */ /* full */
break; break;
} }
ret = bdrv_pwrite(bs->file->bs, offset, buffer_tmp, ret = bdrv_pwrite(bs->file, offset, buffer_tmp,
VHDX_LOG_SECTOR_SIZE); VHDX_LOG_SECTOR_SIZE);
if (ret < 0) { if (ret < 0) {
goto exit; goto exit;
@ -466,7 +466,7 @@ static int vhdx_log_flush_desc(BlockDriverState *bs, VHDXLogDescriptor *desc,
/* count is only > 1 if we are writing zeroes */ /* count is only > 1 if we are writing zeroes */
for (i = 0; i < count; i++) { for (i = 0; i < count; i++) {
ret = bdrv_pwrite_sync(bs->file->bs, file_offset, buffer, ret = bdrv_pwrite_sync(bs->file, file_offset, buffer,
VHDX_LOG_SECTOR_SIZE); VHDX_LOG_SECTOR_SIZE);
if (ret < 0) { if (ret < 0) {
goto exit; goto exit;

View File

@ -330,7 +330,7 @@ static int vhdx_write_header(BdrvChild *file, VHDXHeader *hdr,
vhdx_header_le_export(hdr, header_le); vhdx_header_le_export(hdr, header_le);
vhdx_update_checksum(buffer, VHDX_HEADER_SIZE, vhdx_update_checksum(buffer, VHDX_HEADER_SIZE,
offsetof(VHDXHeader, checksum)); offsetof(VHDXHeader, checksum));
ret = bdrv_pwrite_sync(bs_file, offset, header_le, sizeof(VHDXHeader)); ret = bdrv_pwrite_sync(file, offset, header_le, sizeof(VHDXHeader));
exit: exit:
qemu_vfree(buffer); qemu_vfree(buffer);

View File

@ -306,7 +306,7 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
pstrcat(desc, DESC_SIZE, tmp_desc); pstrcat(desc, DESC_SIZE, tmp_desc);
} }
ret = bdrv_pwrite_sync(bs->file->bs, s->desc_offset, desc, DESC_SIZE); ret = bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE);
out: out:
g_free(desc); g_free(desc);
@ -1052,7 +1052,7 @@ static int get_whole_cluster(BlockDriverState *bs,
goto exit; goto exit;
} }
} }
ret = bdrv_pwrite(extent->file->bs, cluster_offset, whole_grain, ret = bdrv_pwrite(extent->file, cluster_offset, whole_grain,
skip_start_bytes); skip_start_bytes);
if (ret < 0) { if (ret < 0) {
ret = VMDK_ERROR; ret = VMDK_ERROR;
@ -1070,7 +1070,7 @@ static int get_whole_cluster(BlockDriverState *bs,
goto exit; goto exit;
} }
} }
ret = bdrv_pwrite(extent->file->bs, cluster_offset + skip_end_bytes, ret = bdrv_pwrite(extent->file, cluster_offset + skip_end_bytes,
whole_grain + skip_end_bytes, whole_grain + skip_end_bytes,
cluster_bytes - skip_end_bytes); cluster_bytes - skip_end_bytes);
if (ret < 0) { if (ret < 0) {
@ -1090,8 +1090,7 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data,
{ {
offset = cpu_to_le32(offset); offset = cpu_to_le32(offset);
/* update L2 table */ /* update L2 table */
if (bdrv_pwrite_sync( if (bdrv_pwrite_sync(extent->file,
extent->file->bs,
((int64_t)m_data->l2_offset * 512) ((int64_t)m_data->l2_offset * 512)
+ (m_data->l2_index * sizeof(offset)), + (m_data->l2_index * sizeof(offset)),
&offset, sizeof(offset)) < 0) { &offset, sizeof(offset)) < 0) {
@ -1100,8 +1099,7 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data,
/* update backup L2 table */ /* update backup L2 table */
if (extent->l1_backup_table_offset != 0) { if (extent->l1_backup_table_offset != 0) {
m_data->l2_offset = extent->l1_backup_table[m_data->l1_index]; m_data->l2_offset = extent->l1_backup_table[m_data->l1_index];
if (bdrv_pwrite_sync( if (bdrv_pwrite_sync(extent->file,
extent->file->bs,
((int64_t)m_data->l2_offset * 512) ((int64_t)m_data->l2_offset * 512)
+ (m_data->l2_index * sizeof(offset)), + (m_data->l2_index * sizeof(offset)),
&offset, sizeof(offset)) < 0) { &offset, sizeof(offset)) < 0) {

View File

@ -481,7 +481,7 @@ static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset,
s->last_bitmap_offset = bitmap_offset; s->last_bitmap_offset = bitmap_offset;
memset(bitmap, 0xff, s->bitmap_size); memset(bitmap, 0xff, s->bitmap_size);
bdrv_pwrite_sync(bs->file->bs, bitmap_offset, bitmap, s->bitmap_size); bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_size);
} }
return block_offset; return block_offset;
@ -505,7 +505,7 @@ static int rewrite_footer(BlockDriverState* bs)
BDRVVPCState *s = bs->opaque; BDRVVPCState *s = bs->opaque;
int64_t offset = s->free_data_block_offset; int64_t offset = s->free_data_block_offset;
ret = bdrv_pwrite_sync(bs->file->bs, offset, s->footer_buf, HEADER_SIZE); ret = bdrv_pwrite_sync(bs->file, offset, s->footer_buf, HEADER_SIZE);
if (ret < 0) if (ret < 0)
return ret; return ret;
@ -539,7 +539,7 @@ static int64_t alloc_block(BlockDriverState* bs, int64_t offset)
/* Initialize the block's bitmap */ /* Initialize the block's bitmap */
memset(bitmap, 0xff, s->bitmap_size); memset(bitmap, 0xff, s->bitmap_size);
ret = bdrv_pwrite_sync(bs->file->bs, s->free_data_block_offset, bitmap, ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap,
s->bitmap_size); s->bitmap_size);
if (ret < 0) { if (ret < 0) {
return ret; return ret;
@ -554,7 +554,7 @@ static int64_t alloc_block(BlockDriverState* bs, int64_t offset)
/* Write BAT entry to disk */ /* Write BAT entry to disk */
bat_offset = s->bat_offset + (4 * index); bat_offset = s->bat_offset + (4 * index);
bat_value = cpu_to_be32(s->pagetable[index]); bat_value = cpu_to_be32(s->pagetable[index]);
ret = bdrv_pwrite_sync(bs->file->bs, bat_offset, &bat_value, 4); ret = bdrv_pwrite_sync(bs->file, bat_offset, &bat_value, 4);
if (ret < 0) if (ret < 0)
goto fail; goto fail;

View File

@ -235,11 +235,10 @@ int bdrv_pwrite_zeroes(BlockDriverState *bs, int64_t offset,
int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags); int bdrv_make_zero(BlockDriverState *bs, BdrvRequestFlags flags);
int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes); int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes);
int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov); int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov);
int bdrv_pwrite(BlockDriverState *bs, int64_t offset, int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int bytes);
const void *buf, int count); int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov);
int bdrv_pwritev(BlockDriverState *bs, int64_t offset, QEMUIOVector *qiov); int bdrv_pwrite_sync(BdrvChild *child, 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(BdrvChild *child, int64_t sector_num, int coroutine_fn bdrv_co_readv(BdrvChild *child, int64_t sector_num,
int nb_sectors, QEMUIOVector *qiov); int nb_sectors, QEMUIOVector *qiov);
int coroutine_fn bdrv_co_writev(BdrvChild *child, int64_t sector_num, int coroutine_fn bdrv_co_writev(BdrvChild *child, int64_t sector_num,