Block patches:

- Refactoring for non-coroutine variants of bdrv/blk_co_* functions:
   Auto-generate more of them with the block coroutine wrapper generator
   script
 - iotest fixes
 - Both for the storage daemon and the system emulator: Fix PID file
   handling when daemonizing (store the absolute path and delete that on
   exit, which is necessary because daemonizing will change the working
   directory to /)
 -----BEGIN PGP SIGNATURE-----
 
 iQJGBAABCAAwFiEEy2LXoO44KeRfAE00ofpA0JgBnN8FAmLNt54SHGhyZWl0ekBy
 ZWRoYXQuY29tAAoJEKH6QNCYAZzfkgwP/RMYolaa+p2w4Gy8KUY95YnvRWu6Ct3e
 COeM6ZXKgvXKg8lEGq6q66Zp3oJIPsljvNejJi/76BJcX4a658U/wvpNXQ4IoesC
 9fFrxgAMrZZ+6ZFFhJaUwFsqisTBqSe28xmmtfKCb8iCU8C9kAiwSTztjSc88LBl
 jyFL6iAhggXjfP1Wul2fZ2jeIlveLyNHSvVqujXN13jMvt0uQpGmSRi9AUQlSl/L
 TZ1qKuFe2AjukyzgigsmAMQIZBZb1gOFEt0VxdEgoS06VAaEURvt39ZFG4J1jD0T
 vnYk/RLFXEsaErwtiDQp8BENpIHglKFTucrGD0oUcc55yaupOIxwV/JUpG1CsPfV
 T+1Jw8PSXNi4V8rRnGeEd5kSK2v/uSLf6ktxC/BNzjx3J66/fQm60yoKymsEIVzO
 Y5ysYzq9VnDGw9+wP4v/BBms/UFOzp8zpZrNt8AeAsN0zfKGXoGCwsX0wNetoLpK
 G9dh48SHVkzF73Gd5AAC2ydR336/WebR9ibN+mYJVjraWYXHY1kbZtDZ1KPPIe0g
 Ld/YRI8xi3YtIEMDwCG8vyBBpHNxqbU6cuid9pBB6b4qH3lAH06Kkh4XD+Ht4GZ6
 DOdsqKx7DpDlFVfH7h0UMarVf5PU36u4xPgPt0xWIJUZku49XrJO+1SWj6mmp7jT
 i1t8cslVWSZ4
 =Z5a+
 -----END PGP SIGNATURE-----

Merge tag 'pull-block-2022-07-12' of https://gitlab.com/hreitz/qemu into staging

Block patches:
- Refactoring for non-coroutine variants of bdrv/blk_co_* functions:
  Auto-generate more of them with the block coroutine wrapper generator
  script
- iotest fixes
- Both for the storage daemon and the system emulator: Fix PID file
  handling when daemonizing (store the absolute path and delete that on
  exit, which is necessary because daemonizing will change the working
  directory to /)

# gpg: Signature made Tue 12 Jul 2022 19:04:14 BST
# gpg:                using RSA key CB62D7A0EE3829E45F004D34A1FA40D098019CDF
# gpg:                issuer "hreitz@redhat.com"
# gpg: Good signature from "Hanna Reitz <hreitz@redhat.com>" [marginal]
# gpg: WARNING: This key is not certified with sufficiently trusted signatures!
# gpg:          It is not certain that the signature belongs to the owner.
# Primary key fingerprint: CB62 D7A0 EE38 29E4 5F00  4D34 A1FA 40D0 9801 9CDF

* tag 'pull-block-2022-07-12' of https://gitlab.com/hreitz/qemu: (35 commits)
  vl: Unlink absolute PID file path
  vl: Conditionally register PID file unlink notifier
  qsd: Unlink absolute PID file path
  iotests/297: Have mypy ignore unused ignores
  qsd: Do not use error_report() before monitor_init
  block: Remove remaining unused symbols in coroutines.h
  block: Reorganize some declarations in block-backend-io.h
  block: Add blk_co_truncate()
  block: Add blk_co_ioctl()
  block: Implement blk_flush() using generated_co_wrapper
  block: Implement blk_pdiscard() using generated_co_wrapper
  block: Implement blk_pwrite_zeroes() using generated_co_wrapper
  block: Add blk_co_pwrite_compressed()
  block: Change blk_pwrite_compressed() param order
  block: Export blk_pwritev_part() in block-backend-io.h
  block: Add blk_[co_]preadv_part()
  block: Add blk_{preadv,pwritev}()
  block: Implement blk_{pread,pwrite}() using generated_co_wrapper
  block: Make blk_co_pwrite() take a const buffer
  block: Make 'bytes' param of blk_{pread,pwrite}() an int64_t
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2022-07-12 20:31:50 +01:00
commit 824824d122
65 changed files with 855 additions and 785 deletions

10
block.c
View File

@ -1037,7 +1037,7 @@ static int find_image_format(BlockBackend *file, const char *filename,
return ret;
}
ret = blk_pread(file, 0, buf, sizeof(buf));
ret = blk_pread(file, 0, sizeof(buf), buf, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read image for determining its "
"format");
@ -1045,14 +1045,16 @@ static int find_image_format(BlockBackend *file, const char *filename,
return ret;
}
drv = bdrv_probe_all(buf, ret, filename);
drv = bdrv_probe_all(buf, sizeof(buf), filename);
if (!drv) {
error_setg(errp, "Could not determine image format: No compatible "
"driver found");
ret = -ENOENT;
*pdrv = NULL;
return -ENOENT;
}
*pdrv = drv;
return ret;
return 0;
}
/**

View File

@ -107,8 +107,8 @@ static uint64_t blk_log_writes_find_cur_log_sector(BdrvChild *log,
struct log_write_entry cur_entry;
while (cur_idx < nr_entries) {
int read_ret = bdrv_pread(log, cur_sector << sector_bits, &cur_entry,
sizeof(cur_entry));
int read_ret = bdrv_pread(log, cur_sector << sector_bits,
sizeof(cur_entry), &cur_entry, 0);
if (read_ret < 0) {
error_setg_errno(errp, -read_ret,
"Failed to read log entry %"PRIu64, cur_idx);
@ -190,7 +190,7 @@ static int blk_log_writes_open(BlockDriverState *bs, QDict *options, int flags,
log_sb.nr_entries = cpu_to_le64(0);
log_sb.sectorsize = cpu_to_le32(BDRV_SECTOR_SIZE);
} else {
ret = bdrv_pread(s->log_file, 0, &log_sb, sizeof(log_sb));
ret = bdrv_pread(s->log_file, 0, sizeof(log_sb), &log_sb, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read log superblock");
goto fail_log;

View File

@ -1280,9 +1280,10 @@ static void coroutine_fn blk_wait_while_drained(BlockBackend *blk)
}
/* To be called between exactly one pair of blk_inc/dec_in_flight() */
int coroutine_fn
blk_co_do_preadv(BlockBackend *blk, int64_t offset, int64_t bytes,
QEMUIOVector *qiov, BdrvRequestFlags flags)
static int coroutine_fn
blk_co_do_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes,
QEMUIOVector *qiov, size_t qiov_offset,
BdrvRequestFlags flags)
{
int ret;
BlockDriverState *bs;
@ -1307,11 +1308,23 @@ blk_co_do_preadv(BlockBackend *blk, int64_t offset, int64_t bytes,
bytes, false);
}
ret = bdrv_co_preadv(blk->root, offset, bytes, qiov, flags);
ret = bdrv_co_preadv_part(blk->root, offset, bytes, qiov, qiov_offset,
flags);
bdrv_dec_in_flight(bs);
return ret;
}
int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, int64_t bytes,
void *buf, BdrvRequestFlags flags)
{
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_OR_GS_CODE();
assert(bytes <= SIZE_MAX);
return blk_co_preadv(blk, offset, bytes, &qiov, flags);
}
int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov,
BdrvRequestFlags flags)
@ -1320,14 +1333,28 @@ int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
IO_OR_GS_CODE();
blk_inc_in_flight(blk);
ret = blk_co_do_preadv(blk, offset, bytes, qiov, flags);
ret = blk_co_do_preadv_part(blk, offset, bytes, qiov, 0, flags);
blk_dec_in_flight(blk);
return ret;
}
int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov,
size_t qiov_offset, BdrvRequestFlags flags)
{
int ret;
IO_OR_GS_CODE();
blk_inc_in_flight(blk);
ret = blk_co_do_preadv_part(blk, offset, bytes, qiov, qiov_offset, flags);
blk_dec_in_flight(blk);
return ret;
}
/* To be called between exactly one pair of blk_inc/dec_in_flight() */
int coroutine_fn
static int coroutine_fn
blk_co_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes,
QEMUIOVector *qiov, size_t qiov_offset,
BdrvRequestFlags flags)
@ -1379,6 +1406,17 @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
return ret;
}
int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes,
const void *buf, BdrvRequestFlags flags)
{
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_OR_GS_CODE();
assert(bytes <= SIZE_MAX);
return blk_co_pwritev(blk, offset, bytes, &qiov, flags);
}
int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov,
BdrvRequestFlags flags)
@ -1387,20 +1425,6 @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
return blk_co_pwritev_part(blk, offset, bytes, qiov, 0, flags);
}
static int coroutine_fn blk_pwritev_part(BlockBackend *blk, int64_t offset,
int64_t bytes,
QEMUIOVector *qiov, size_t qiov_offset,
BdrvRequestFlags flags)
{
int ret;
blk_inc_in_flight(blk);
ret = blk_do_pwritev_part(blk, offset, bytes, qiov, qiov_offset, flags);
blk_dec_in_flight(blk);
return ret;
}
typedef struct BlkRwCo {
BlockBackend *blk;
int64_t offset;
@ -1409,14 +1433,6 @@ typedef struct BlkRwCo {
BdrvRequestFlags flags;
} BlkRwCo;
int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int64_t bytes, BdrvRequestFlags flags)
{
IO_OR_GS_CODE();
return blk_pwritev_part(blk, offset, bytes, NULL, 0,
flags | BDRV_REQ_ZERO_WRITE);
}
int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags)
{
GLOBAL_STATE_CODE();
@ -1537,8 +1553,8 @@ static void blk_aio_read_entry(void *opaque)
QEMUIOVector *qiov = rwco->iobuf;
assert(qiov->size == acb->bytes);
rwco->ret = blk_co_do_preadv(rwco->blk, rwco->offset, acb->bytes,
qiov, rwco->flags);
rwco->ret = blk_co_do_preadv_part(rwco->blk, rwco->offset, acb->bytes, qiov,
0, rwco->flags);
blk_aio_complete(acb);
}
@ -1563,31 +1579,6 @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
flags | BDRV_REQ_ZERO_WRITE, cb, opaque);
}
int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes)
{
int ret;
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_OR_GS_CODE();
blk_inc_in_flight(blk);
ret = blk_do_preadv(blk, offset, bytes, &qiov, 0);
blk_dec_in_flight(blk);
return ret < 0 ? ret : bytes;
}
int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes,
BdrvRequestFlags flags)
{
int ret;
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_OR_GS_CODE();
ret = blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags);
return ret < 0 ? ret : bytes;
}
int64_t blk_getlength(BlockBackend *blk)
{
IO_CODE();
@ -1651,7 +1642,7 @@ void blk_aio_cancel_async(BlockAIOCB *acb)
}
/* To be called between exactly one pair of blk_inc/dec_in_flight() */
int coroutine_fn
static int coroutine_fn
blk_co_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
{
IO_CODE();
@ -1665,13 +1656,14 @@ blk_co_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
return bdrv_co_ioctl(blk_bs(blk), req, buf);
}
int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf)
int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req,
void *buf)
{
int ret;
IO_OR_GS_CODE();
blk_inc_in_flight(blk);
ret = blk_do_ioctl(blk, req, buf);
ret = blk_co_do_ioctl(blk, req, buf);
blk_dec_in_flight(blk);
return ret;
@ -1695,7 +1687,7 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned long int req, void *buf,
}
/* To be called between exactly one pair of blk_inc/dec_in_flight() */
int coroutine_fn
static int coroutine_fn
blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes)
{
int ret;
@ -1742,20 +1734,8 @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
return ret;
}
int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes)
{
int ret;
IO_OR_GS_CODE();
blk_inc_in_flight(blk);
ret = blk_do_pdiscard(blk, offset, bytes);
blk_dec_in_flight(blk);
return ret;
}
/* To be called between exactly one pair of blk_inc/dec_in_flight() */
int coroutine_fn blk_co_do_flush(BlockBackend *blk)
static int coroutine_fn blk_co_do_flush(BlockBackend *blk)
{
blk_wait_while_drained(blk);
IO_CODE();
@ -1795,17 +1775,6 @@ int coroutine_fn blk_co_flush(BlockBackend *blk)
return ret;
}
int blk_flush(BlockBackend *blk)
{
int ret;
blk_inc_in_flight(blk);
ret = blk_do_flush(blk);
blk_dec_in_flight(blk);
return ret;
}
void blk_drain(BlockBackend *blk)
{
BlockDriverState *bs = blk_bs(blk);
@ -2337,17 +2306,18 @@ int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
flags | BDRV_REQ_ZERO_WRITE);
}
int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf,
int64_t bytes)
int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset,
int64_t bytes, const void *buf)
{
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_OR_GS_CODE();
return blk_pwritev_part(blk, offset, bytes, &qiov, 0,
BDRV_REQ_WRITE_COMPRESSED);
return blk_co_pwritev_part(blk, offset, bytes, &qiov, 0,
BDRV_REQ_WRITE_COMPRESSED);
}
int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
PreallocMode prealloc, BdrvRequestFlags flags, Error **errp)
int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact,
PreallocMode prealloc, BdrvRequestFlags flags,
Error **errp)
{
IO_OR_GS_CODE();
if (!blk_is_available(blk)) {
@ -2355,7 +2325,7 @@ int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
return -ENOMEDIUM;
}
return bdrv_truncate(blk->root, offset, exact, prealloc, flags, errp);
return bdrv_co_truncate(blk->root, offset, exact, prealloc, flags, errp);
}
int blk_save_vmstate(BlockBackend *blk, const uint8_t *buf,

View File

@ -116,7 +116,7 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
return -EINVAL;
}
ret = bdrv_pread(bs->file, 0, &bochs, sizeof(bochs));
ret = bdrv_pread(bs->file, 0, sizeof(bochs), &bochs, 0);
if (ret < 0) {
return ret;
}
@ -150,8 +150,8 @@ static int bochs_open(BlockDriverState *bs, QDict *options, int flags,
return -ENOMEM;
}
ret = bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_bitmap,
s->catalog_size * 4);
ret = bdrv_pread(bs->file, le32_to_cpu(bochs.header), s->catalog_size * 4,
s->catalog_bitmap, 0);
if (ret < 0) {
goto fail;
}
@ -224,8 +224,8 @@ static int64_t seek_to_sector(BlockDriverState *bs, int64_t sector_num)
(s->extent_blocks + s->bitmap_blocks));
/* read in bitmap for current extent */
ret = bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8),
&bitmap_entry, 1);
ret = bdrv_pread(bs->file, bitmap_offset + (extent_offset / 8), 1,
&bitmap_entry, 0);
if (ret < 0) {
return ret;
}

View File

@ -78,7 +78,7 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
}
/* read header */
ret = bdrv_pread(bs->file, 128, &s->block_size, 4);
ret = bdrv_pread(bs->file, 128, 4, &s->block_size, 0);
if (ret < 0) {
return ret;
}
@ -104,7 +104,7 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
return -EINVAL;
}
ret = bdrv_pread(bs->file, 128 + 4, &s->n_blocks, 4);
ret = bdrv_pread(bs->file, 128 + 4, 4, &s->n_blocks, 0);
if (ret < 0) {
return ret;
}
@ -135,7 +135,7 @@ static int cloop_open(BlockDriverState *bs, QDict *options, int flags,
return -ENOMEM;
}
ret = bdrv_pread(bs->file, 128 + 4 + 4, s->offsets, offsets_size);
ret = bdrv_pread(bs->file, 128 + 4 + 4, offsets_size, s->offsets, 0);
if (ret < 0) {
goto fail;
}
@ -220,9 +220,9 @@ static inline int cloop_read_block(BlockDriverState *bs, int block_num)
int ret;
uint32_t bytes = s->offsets[block_num + 1] - s->offsets[block_num];
ret = bdrv_pread(bs->file, s->offsets[block_num],
s->compressed_block, bytes);
if (ret != bytes) {
ret = bdrv_pread(bs->file, s->offsets[block_num], bytes,
s->compressed_block, 0);
if (ret < 0) {
return -1;
}

View File

@ -527,12 +527,12 @@ int bdrv_commit(BlockDriverState *bs)
goto ro_cleanup;
}
if (ret) {
ret = blk_pread(src, offset, buf, n);
ret = blk_pread(src, offset, n, buf, 0);
if (ret < 0) {
goto ro_cleanup;
}
ret = blk_pwrite(backing, offset, buf, n, 0);
ret = blk_pwrite(backing, offset, n, buf, 0);
if (ret < 0) {
goto ro_cleanup;
}

View File

@ -63,25 +63,6 @@ nbd_co_do_establish_connection(BlockDriverState *bs, bool blocking,
Error **errp);
int coroutine_fn
blk_co_do_preadv(BlockBackend *blk, int64_t offset, int64_t bytes,
QEMUIOVector *qiov, BdrvRequestFlags flags);
int coroutine_fn
blk_co_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes,
QEMUIOVector *qiov, size_t qiov_offset,
BdrvRequestFlags flags);
int coroutine_fn
blk_co_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
int coroutine_fn
blk_co_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes);
int coroutine_fn blk_co_do_flush(BlockBackend *blk);
/*
* "I/O or GS" API functions. These functions can run without
* the BQL, but only in one specific iothread/main loop.
@ -90,14 +71,6 @@ int coroutine_fn blk_co_do_flush(BlockBackend *blk);
* the "I/O or GS" API.
*/
int generated_co_wrapper
bdrv_preadv(BdrvChild *child, int64_t offset, unsigned int bytes,
QEMUIOVector *qiov, BdrvRequestFlags flags);
int generated_co_wrapper
bdrv_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes,
QEMUIOVector *qiov, BdrvRequestFlags flags);
int generated_co_wrapper
bdrv_common_block_status_above(BlockDriverState *bs,
BlockDriverState *base,
@ -112,21 +85,4 @@ bdrv_common_block_status_above(BlockDriverState *bs,
int generated_co_wrapper
nbd_do_establish_connection(BlockDriverState *bs, bool blocking, Error **errp);
int generated_co_wrapper
blk_do_preadv(BlockBackend *blk, int64_t offset, int64_t bytes,
QEMUIOVector *qiov, BdrvRequestFlags flags);
int generated_co_wrapper
blk_do_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes,
QEMUIOVector *qiov, size_t qiov_offset,
BdrvRequestFlags flags);
int generated_co_wrapper
blk_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
int generated_co_wrapper
blk_do_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes);
int generated_co_wrapper blk_do_flush(BlockBackend *blk);
#endif /* BLOCK_COROUTINES_H */

View File

@ -55,40 +55,40 @@ static int block_crypto_probe_generic(QCryptoBlockFormat format,
}
static ssize_t block_crypto_read_func(QCryptoBlock *block,
size_t offset,
uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
static int block_crypto_read_func(QCryptoBlock *block,
size_t offset,
uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
{
BlockDriverState *bs = opaque;
ssize_t ret;
ret = bdrv_pread(bs->file, offset, buf, buflen);
ret = bdrv_pread(bs->file, offset, buflen, buf, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read encryption header");
return ret;
}
return ret;
return 0;
}
static ssize_t block_crypto_write_func(QCryptoBlock *block,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
static int block_crypto_write_func(QCryptoBlock *block,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
{
BlockDriverState *bs = opaque;
ssize_t ret;
ret = bdrv_pwrite(bs->file, offset, buf, buflen);
ret = bdrv_pwrite(bs->file, offset, buflen, buf, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write encryption header");
return ret;
}
return ret;
return 0;
}
@ -99,28 +99,28 @@ struct BlockCryptoCreateData {
};
static ssize_t block_crypto_create_write_func(QCryptoBlock *block,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
static int block_crypto_create_write_func(QCryptoBlock *block,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
{
struct BlockCryptoCreateData *data = opaque;
ssize_t ret;
ret = blk_pwrite(data->blk, offset, buf, buflen, 0);
ret = blk_pwrite(data->blk, offset, buflen, buf, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write encryption header");
return ret;
}
return ret;
return 0;
}
static ssize_t block_crypto_create_init_func(QCryptoBlock *block,
size_t headerlen,
void *opaque,
Error **errp)
static int block_crypto_create_init_func(QCryptoBlock *block,
size_t headerlen,
void *opaque,
Error **errp)
{
struct BlockCryptoCreateData *data = opaque;
Error *local_error = NULL;
@ -139,7 +139,7 @@ static ssize_t block_crypto_create_init_func(QCryptoBlock *block,
data->prealloc, 0, &local_error);
if (ret >= 0) {
return ret;
return 0;
}
error:

View File

@ -77,7 +77,7 @@ static int read_uint64(BlockDriverState *bs, int64_t offset, uint64_t *result)
uint64_t buffer;
int ret;
ret = bdrv_pread(bs->file, offset, &buffer, 8);
ret = bdrv_pread(bs->file, offset, 8, &buffer, 0);
if (ret < 0) {
return ret;
}
@ -91,7 +91,7 @@ static int read_uint32(BlockDriverState *bs, int64_t offset, uint32_t *result)
uint32_t buffer;
int ret;
ret = bdrv_pread(bs->file, offset, &buffer, 4);
ret = bdrv_pread(bs->file, offset, 4, &buffer, 0);
if (ret < 0) {
return ret;
}
@ -172,7 +172,7 @@ static int64_t dmg_find_koly_offset(BdrvChild *file, Error **errp)
offset = length - 511 - 512;
}
length = length < 515 ? length : 515;
ret = bdrv_pread(file, offset, buffer, length);
ret = bdrv_pread(file, offset, length, buffer, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed while reading UDIF trailer");
return ret;
@ -352,7 +352,7 @@ static int dmg_read_resource_fork(BlockDriverState *bs, DmgHeaderState *ds,
offset += 4;
buffer = g_realloc(buffer, count);
ret = bdrv_pread(bs->file, offset, buffer, count);
ret = bdrv_pread(bs->file, offset, count, buffer, 0);
if (ret < 0) {
goto fail;
}
@ -389,8 +389,8 @@ static int dmg_read_plist_xml(BlockDriverState *bs, DmgHeaderState *ds,
buffer = g_malloc(info_length + 1);
buffer[info_length] = '\0';
ret = bdrv_pread(bs->file, info_begin, buffer, info_length);
if (ret != info_length) {
ret = bdrv_pread(bs->file, info_begin, info_length, buffer, 0);
if (ret < 0) {
ret = -EINVAL;
goto fail;
}
@ -609,9 +609,9 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
case UDZO: { /* zlib compressed */
/* we need to buffer, because only the chunk as whole can be
* inflated. */
ret = bdrv_pread(bs->file, s->offsets[chunk],
s->compressed_chunk, s->lengths[chunk]);
if (ret != s->lengths[chunk]) {
ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
s->compressed_chunk, 0);
if (ret < 0) {
return -1;
}
@ -635,9 +635,9 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
}
/* we need to buffer, because only the chunk as whole can be
* inflated. */
ret = bdrv_pread(bs->file, s->offsets[chunk],
s->compressed_chunk, s->lengths[chunk]);
if (ret != s->lengths[chunk]) {
ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
s->compressed_chunk, 0);
if (ret < 0) {
return -1;
}
@ -656,9 +656,9 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
}
/* we need to buffer, because only the chunk as whole can be
* inflated. */
ret = bdrv_pread(bs->file, s->offsets[chunk],
s->compressed_chunk, s->lengths[chunk]);
if (ret != s->lengths[chunk]) {
ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
s->compressed_chunk, 0);
if (ret < 0) {
return -1;
}
@ -672,9 +672,9 @@ static inline int dmg_read_chunk(BlockDriverState *bs, uint64_t sector_num)
}
break;
case UDRW: /* copy */
ret = bdrv_pread(bs->file, s->offsets[chunk],
s->uncompressed_chunk, s->lengths[chunk]);
if (ret != s->lengths[chunk]) {
ret = bdrv_pread(bs->file, s->offsets[chunk], s->lengths[chunk],
s->uncompressed_chunk, 0);
if (ret < 0) {
return -1;
}
break;

View File

@ -554,7 +554,7 @@ static void fuse_read(fuse_req_t req, fuse_ino_t inode,
return;
}
ret = blk_pread(exp->common.blk, offset, buf, size);
ret = blk_pread(exp->common.blk, offset, size, buf, 0);
if (ret >= 0) {
fuse_reply_buf(req, buf, size);
} else {
@ -607,7 +607,7 @@ static void fuse_write(fuse_req_t req, fuse_ino_t inode, const char *buf,
}
}
ret = blk_pwrite(exp->common.blk, offset, buf, size, 0);
ret = blk_pwrite(exp->common.blk, offset, size, buf, 0);
if (ret >= 0) {
fuse_reply_write(req, size);
} else {

View File

@ -1046,14 +1046,6 @@ static int bdrv_check_request32(int64_t offset, int64_t bytes,
return 0;
}
int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
int64_t bytes, BdrvRequestFlags flags)
{
IO_CODE();
return bdrv_pwritev(child, offset, bytes, NULL,
BDRV_REQ_ZERO_WRITE | flags);
}
/*
* Completely zero out a block device with the help of bdrv_pwrite_zeroes.
* The operation is sped up by checking the block status and only writing
@ -1096,62 +1088,25 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags)
}
}
/* See bdrv_pwrite() for the return codes */
int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes)
{
int ret;
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_CODE();
if (bytes < 0) {
return -EINVAL;
}
ret = bdrv_preadv(child, offset, bytes, &qiov, 0);
return ret < 0 ? ret : bytes;
}
/* Return no. of bytes on success or < 0 on error. Important errors are:
-EIO generic I/O error (may happen for all errors)
-ENOMEDIUM No media inserted.
-EINVAL Invalid offset or number of bytes
-EACCES Trying to write a read-only device
*/
int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf,
int64_t bytes)
{
int ret;
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_CODE();
if (bytes < 0) {
return -EINVAL;
}
ret = bdrv_pwritev(child, offset, bytes, &qiov, 0);
return ret < 0 ? ret : bytes;
}
/*
* Writes to the file and ensures that no writes are reordered across this
* request (acts as a barrier)
*
* Returns 0 on success, -errno in error cases.
*/
int bdrv_pwrite_sync(BdrvChild *child, int64_t offset,
const void *buf, int64_t count)
int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset,
int64_t bytes, const void *buf,
BdrvRequestFlags flags)
{
int ret;
IO_CODE();
ret = bdrv_pwrite(child, offset, buf, count);
ret = bdrv_co_pwrite(child, offset, bytes, buf, flags);
if (ret < 0) {
return ret;
}
ret = bdrv_flush(child->bs);
ret = bdrv_co_flush(child->bs);
if (ret < 0) {
return ret;
}

View File

@ -136,6 +136,7 @@ block_gen_c = custom_target('block-gen.c',
input: files(
'../include/block/block-io.h',
'../include/block/block-global-state.h',
'../include/sysemu/block-backend-io.h',
'coroutines.h'
),
command: [wrapper_py, '@OUTPUT@', '@INPUT@'])

View File

@ -93,8 +93,8 @@ static int parallels_load_bitmap_data(BlockDriverState *bs,
if (entry == 1) {
bdrv_dirty_bitmap_deserialize_ones(bitmap, offset, count, false);
} else {
ret = bdrv_pread(bs->file, entry << BDRV_SECTOR_BITS, buf,
s->cluster_size);
ret = bdrv_pread(bs->file, entry << BDRV_SECTOR_BITS,
s->cluster_size, buf, 0);
if (ret < 0) {
error_setg_errno(errp, -ret,
"Failed to read bitmap data cluster");
@ -286,7 +286,7 @@ int parallels_read_format_extension(BlockDriverState *bs,
assert(ext_off > 0);
ret = bdrv_pread(bs->file, ext_off, ext_cluster, s->cluster_size);
ret = bdrv_pread(bs->file, ext_off, s->cluster_size, ext_cluster, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to read Format Extension cluster");
goto out;

View File

@ -277,8 +277,8 @@ static coroutine_fn int parallels_co_flush_to_os(BlockDriverState *bs)
if (off + to_write > s->header_size) {
to_write = s->header_size - off;
}
ret = bdrv_pwrite(bs->file, off, (uint8_t *)s->header + off,
to_write);
ret = bdrv_pwrite(bs->file, off, to_write, (uint8_t *)s->header + off,
0);
if (ret < 0) {
qemu_co_mutex_unlock(&s->lock);
return ret;
@ -481,7 +481,7 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs,
ret = 0;
if (flush_bat) {
ret = bdrv_pwrite_sync(bs->file, 0, s->header, s->header_size);
ret = bdrv_co_pwrite_sync(bs->file, 0, s->header_size, s->header, 0);
if (ret < 0) {
res->check_errors++;
goto out;
@ -599,7 +599,7 @@ static int coroutine_fn parallels_co_create(BlockdevCreateOptions* opts,
memset(tmp, 0, sizeof(tmp));
memcpy(tmp, &header, sizeof(header));
ret = blk_pwrite(blk, 0, tmp, BDRV_SECTOR_SIZE, 0);
ret = blk_pwrite(blk, 0, BDRV_SECTOR_SIZE, tmp, 0);
if (ret < 0) {
goto exit;
}
@ -723,7 +723,7 @@ static int parallels_update_header(BlockDriverState *bs)
if (size > s->header_size) {
size = s->header_size;
}
return bdrv_pwrite_sync(bs->file, 0, s->header, size);
return bdrv_pwrite_sync(bs->file, 0, size, s->header, 0);
}
static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
@ -742,7 +742,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
return -EINVAL;
}
ret = bdrv_pread(bs->file, 0, &ph, sizeof(ph));
ret = bdrv_pread(bs->file, 0, sizeof(ph), &ph, 0);
if (ret < 0) {
goto fail;
}
@ -798,7 +798,7 @@ static int parallels_open(BlockDriverState *bs, QDict *options, int flags,
s->header_size = size;
}
ret = bdrv_pread(bs->file, 0, s->header, s->header_size);
ret = bdrv_pread(bs->file, 0, s->header_size, s->header, 0);
if (ret < 0) {
goto fail;
}

View File

@ -128,7 +128,7 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
goto fail;
}
ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
ret = bdrv_pread(bs->file, 0, sizeof(header), &header, 0);
if (ret < 0) {
goto fail;
}
@ -260,8 +260,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
goto fail;
}
ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table,
s->l1_size * sizeof(uint64_t));
ret = bdrv_pread(bs->file, s->l1_table_offset,
s->l1_size * sizeof(uint64_t), s->l1_table, 0);
if (ret < 0) {
goto fail;
}
@ -291,8 +291,8 @@ static int qcow_open(BlockDriverState *bs, QDict *options, int flags,
ret = -EINVAL;
goto fail;
}
ret = bdrv_pread(bs->file, header.backing_file_offset,
bs->auto_backing_file, len);
ret = bdrv_pread(bs->file, header.backing_file_offset, len,
bs->auto_backing_file, 0);
if (ret < 0) {
goto fail;
}
@ -383,7 +383,7 @@ static int get_cluster_offset(BlockDriverState *bs,
BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE);
ret = bdrv_pwrite_sync(bs->file,
s->l1_table_offset + l1_index * sizeof(tmp),
&tmp, sizeof(tmp));
sizeof(tmp), &tmp, 0);
if (ret < 0) {
return ret;
}
@ -414,14 +414,14 @@ static int get_cluster_offset(BlockDriverState *bs,
BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD);
if (new_l2_table) {
memset(l2_table, 0, s->l2_size * sizeof(uint64_t));
ret = bdrv_pwrite_sync(bs->file, l2_offset, l2_table,
s->l2_size * sizeof(uint64_t));
ret = bdrv_pwrite_sync(bs->file, l2_offset,
s->l2_size * sizeof(uint64_t), l2_table, 0);
if (ret < 0) {
return ret;
}
} else {
ret = bdrv_pread(bs->file, l2_offset, l2_table,
s->l2_size * sizeof(uint64_t));
ret = bdrv_pread(bs->file, l2_offset, s->l2_size * sizeof(uint64_t),
l2_table, 0);
if (ret < 0) {
return ret;
}
@ -453,8 +453,8 @@ static int get_cluster_offset(BlockDriverState *bs,
cluster_offset = QEMU_ALIGN_UP(cluster_offset, s->cluster_size);
/* write the cluster content */
BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
ret = bdrv_pwrite(bs->file, cluster_offset, s->cluster_cache,
s->cluster_size);
ret = bdrv_pwrite(bs->file, cluster_offset, s->cluster_size,
s->cluster_cache, 0);
if (ret < 0) {
return ret;
}
@ -492,10 +492,9 @@ static int get_cluster_offset(BlockDriverState *bs,
return -EIO;
}
BLKDBG_EVENT(bs->file, BLKDBG_WRITE_AIO);
ret = bdrv_pwrite(bs->file,
cluster_offset + i,
s->cluster_data,
BDRV_SECTOR_SIZE);
ret = bdrv_pwrite(bs->file, cluster_offset + i,
BDRV_SECTOR_SIZE,
s->cluster_data, 0);
if (ret < 0) {
return ret;
}
@ -516,7 +515,7 @@ static int get_cluster_offset(BlockDriverState *bs,
BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE);
}
ret = bdrv_pwrite_sync(bs->file, l2_offset + l2_index * sizeof(tmp),
&tmp, sizeof(tmp));
sizeof(tmp), &tmp, 0);
if (ret < 0) {
return ret;
}
@ -597,8 +596,8 @@ static int decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset)
csize = cluster_offset >> (63 - s->cluster_bits);
csize &= (s->cluster_size - 1);
BLKDBG_EVENT(bs->file, BLKDBG_READ_COMPRESSED);
ret = bdrv_pread(bs->file, coffset, s->cluster_data, csize);
if (ret != csize)
ret = bdrv_pread(bs->file, coffset, csize, s->cluster_data, 0);
if (ret < 0)
return -1;
if (decompress_buffer(s->cluster_cache, s->cluster_size,
s->cluster_data, csize) < 0) {
@ -891,15 +890,15 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
}
/* write all the data */
ret = blk_pwrite(qcow_blk, 0, &header, sizeof(header), 0);
if (ret != sizeof(header)) {
ret = blk_pwrite(qcow_blk, 0, sizeof(header), &header, 0);
if (ret < 0) {
goto exit;
}
if (qcow_opts->has_backing_file) {
ret = blk_pwrite(qcow_blk, sizeof(header),
qcow_opts->backing_file, backing_filename_len, 0);
if (ret != backing_filename_len) {
ret = blk_pwrite(qcow_blk, sizeof(header), backing_filename_len,
qcow_opts->backing_file, 0);
if (ret < 0) {
goto exit;
}
}
@ -908,8 +907,8 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
for (i = 0; i < DIV_ROUND_UP(sizeof(uint64_t) * l1_size, BDRV_SECTOR_SIZE);
i++) {
ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
tmp, BDRV_SECTOR_SIZE, 0);
if (ret != BDRV_SECTOR_SIZE) {
BDRV_SECTOR_SIZE, tmp, 0);
if (ret < 0) {
g_free(tmp);
goto exit;
}
@ -1030,8 +1029,8 @@ static int qcow_make_empty(BlockDriverState *bs)
int ret;
memset(s->l1_table, 0, l1_length);
if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, s->l1_table,
l1_length) < 0)
if (bdrv_pwrite_sync(bs->file, s->l1_table_offset, l1_length, s->l1_table,
0) < 0)
return -1;
ret = bdrv_truncate(bs->file, s->l1_table_offset + l1_length, false,
PREALLOC_MODE_OFF, 0, NULL);

View File

@ -234,8 +234,8 @@ static int bitmap_table_load(BlockDriverState *bs, Qcow2BitmapTable *tb,
}
assert(tb->size <= BME_MAX_TABLE_SIZE);
ret = bdrv_pread(bs->file, tb->offset,
table, tb->size * BME_TABLE_ENTRY_SIZE);
ret = bdrv_pread(bs->file, tb->offset, tb->size * BME_TABLE_ENTRY_SIZE,
table, 0);
if (ret < 0) {
goto fail;
}
@ -317,7 +317,7 @@ static int load_bitmap_data(BlockDriverState *bs,
* already cleared */
}
} else {
ret = bdrv_pread(bs->file, data_offset, buf, s->cluster_size);
ret = bdrv_pread(bs->file, data_offset, s->cluster_size, buf, 0);
if (ret < 0) {
goto finish;
}
@ -575,7 +575,7 @@ static Qcow2BitmapList *bitmap_list_load(BlockDriverState *bs, uint64_t offset,
}
dir_end = dir + size;
ret = bdrv_pread(bs->file, offset, dir, size);
ret = bdrv_pread(bs->file, offset, size, dir, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to read bitmap directory");
goto fail;
@ -798,7 +798,7 @@ static int bitmap_list_store(BlockDriverState *bs, Qcow2BitmapList *bm_list,
goto fail;
}
ret = bdrv_pwrite(bs->file, dir_offset, dir, dir_size);
ret = bdrv_pwrite(bs->file, dir_offset, dir_size, dir, 0);
if (ret < 0) {
goto fail;
}
@ -1339,7 +1339,7 @@ static uint64_t *store_bitmap_data(BlockDriverState *bs,
goto fail;
}
ret = bdrv_pwrite(bs->file, off, buf, s->cluster_size);
ret = bdrv_pwrite(bs->file, off, s->cluster_size, buf, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write bitmap '%s' to file",
bm_name);
@ -1402,7 +1402,7 @@ static int store_bitmap(BlockDriverState *bs, Qcow2Bitmap *bm, Error **errp)
}
bitmap_table_to_be(tb, tb_size);
ret = bdrv_pwrite(bs->file, tb_offset, tb, tb_size * sizeof(tb[0]));
ret = bdrv_pwrite(bs->file, tb_offset, tb_size * sizeof(tb[0]), tb, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write bitmap '%s' to file",
bm_name);

View File

@ -223,8 +223,8 @@ static int qcow2_cache_entry_flush(BlockDriverState *bs, Qcow2Cache *c, int i)
BLKDBG_EVENT(bs->file, BLKDBG_L2_UPDATE);
}
ret = bdrv_pwrite(bs->file, c->entries[i].offset,
qcow2_cache_get_table_addr(c, i), c->table_size);
ret = bdrv_pwrite(bs->file, c->entries[i].offset, c->table_size,
qcow2_cache_get_table_addr(c, i), 0);
if (ret < 0) {
return ret;
}
@ -379,9 +379,8 @@ static int qcow2_cache_do_get(BlockDriverState *bs, Qcow2Cache *c,
BLKDBG_EVENT(bs->file, BLKDBG_L2_LOAD);
}
ret = bdrv_pread(bs->file, offset,
qcow2_cache_get_table_addr(c, i),
c->table_size);
ret = bdrv_pread(bs->file, offset, c->table_size,
qcow2_cache_get_table_addr(c, i), 0);
if (ret < 0) {
return ret;
}

View File

@ -159,8 +159,8 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
BLKDBG_EVENT(bs->file, BLKDBG_L1_GROW_WRITE_TABLE);
for(i = 0; i < s->l1_size; i++)
new_l1_table[i] = cpu_to_be64(new_l1_table[i]);
ret = bdrv_pwrite_sync(bs->file, new_l1_table_offset,
new_l1_table, new_l1_size2);
ret = bdrv_pwrite_sync(bs->file, new_l1_table_offset, new_l1_size2,
new_l1_table, 0);
if (ret < 0)
goto fail;
for(i = 0; i < s->l1_size; i++)
@ -171,7 +171,7 @@ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size,
stl_be_p(data, new_l1_size);
stq_be_p(data + 4, new_l1_table_offset);
ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_size),
data, sizeof(data));
sizeof(data), data, 0);
if (ret < 0) {
goto fail;
}
@ -249,7 +249,7 @@ int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index)
BLKDBG_EVENT(bs->file, BLKDBG_L1_UPDATE);
ret = bdrv_pwrite_sync(bs->file,
s->l1_table_offset + L1E_SIZE * l1_start_index,
buf, bufsize);
bufsize, buf, 0);
if (ret < 0) {
return ret;
}
@ -2260,7 +2260,8 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
(void **)&l2_slice);
} else {
/* load inactive L2 tables from disk */
ret = bdrv_pread(bs->file, slice_offset, l2_slice, slice_size2);
ret = bdrv_pread(bs->file, slice_offset, slice_size2,
l2_slice, 0);
}
if (ret < 0) {
goto fail;
@ -2376,8 +2377,8 @@ static int expand_zero_clusters_in_l1(BlockDriverState *bs, uint64_t *l1_table,
goto fail;
}
ret = bdrv_pwrite(bs->file, slice_offset,
l2_slice, slice_size2);
ret = bdrv_pwrite(bs->file, slice_offset, slice_size2,
l2_slice, 0);
if (ret < 0) {
goto fail;
}
@ -2470,8 +2471,8 @@ int qcow2_expand_zero_clusters(BlockDriverState *bs,
l1_table = new_l1_table;
ret = bdrv_pread(bs->file, s->snapshots[i].l1_table_offset,
l1_table, l1_size2);
ret = bdrv_pread(bs->file, s->snapshots[i].l1_table_offset, l1_size2,
l1_table, 0);
if (ret < 0) {
goto fail;
}

View File

@ -119,7 +119,7 @@ int qcow2_refcount_init(BlockDriverState *bs)
}
BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_LOAD);
ret = bdrv_pread(bs->file, s->refcount_table_offset,
s->refcount_table, refcount_table_size2);
refcount_table_size2, s->refcount_table, 0);
if (ret < 0) {
goto fail;
}
@ -439,7 +439,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_HOOKUP);
ret = bdrv_pwrite_sync(bs->file, s->refcount_table_offset +
refcount_table_index * REFTABLE_ENTRY_SIZE,
&data64, sizeof(data64));
sizeof(data64), &data64, 0);
if (ret < 0) {
goto fail;
}
@ -684,8 +684,8 @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t start_offset,
}
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_WRITE_TABLE);
ret = bdrv_pwrite_sync(bs->file, table_offset, new_table,
table_size * REFTABLE_ENTRY_SIZE);
ret = bdrv_pwrite_sync(bs->file, table_offset,
table_size * REFTABLE_ENTRY_SIZE, new_table, 0);
if (ret < 0) {
goto fail;
}
@ -704,7 +704,7 @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint64_t start_offset,
BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC_SWITCH_TABLE);
ret = bdrv_pwrite_sync(bs->file,
offsetof(QCowHeader, refcount_table_offset),
&data, sizeof(data));
sizeof(data), &data, 0);
if (ret < 0) {
goto fail;
}
@ -1274,7 +1274,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs,
}
l1_allocated = true;
ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size2);
ret = bdrv_pread(bs->file, l1_table_offset, l1_size2, l1_table, 0);
if (ret < 0) {
goto fail;
}
@ -1435,8 +1435,8 @@ fail:
cpu_to_be64s(&l1_table[i]);
}
ret = bdrv_pwrite_sync(bs->file, l1_table_offset,
l1_table, l1_size2);
ret = bdrv_pwrite_sync(bs->file, l1_table_offset, l1_size2, l1_table,
0);
for (i = 0; i < l1_size; i++) {
be64_to_cpus(&l1_table[i]);
@ -1633,8 +1633,8 @@ static int fix_l2_entry_by_zero(BlockDriverState *bs, BdrvCheckResult *res,
goto fail;
}
ret = bdrv_pwrite_sync(bs->file, l2e_offset, &l2_table[idx],
l2_entry_size(s));
ret = bdrv_pwrite_sync(bs->file, l2e_offset, l2_entry_size(s),
&l2_table[idx], 0);
if (ret < 0) {
fprintf(stderr, "ERROR: Failed to overwrite L2 "
"table entry: %s\n", strerror(-ret));
@ -1672,7 +1672,7 @@ static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *res,
bool metadata_overlap;
/* Read L2 table from disk */
ret = bdrv_pread(bs->file, l2_offset, l2_table, l2_size_bytes);
ret = bdrv_pread(bs->file, l2_offset, l2_size_bytes, l2_table, 0);
if (ret < 0) {
fprintf(stderr, "ERROR: I/O error in check_refcounts_l2\n");
res->check_errors++;
@ -1888,7 +1888,7 @@ static int check_refcounts_l1(BlockDriverState *bs,
}
/* Read L1 table entries from disk */
ret = bdrv_pread(bs->file, l1_table_offset, l1_table, l1_size_bytes);
ret = bdrv_pread(bs->file, l1_table_offset, l1_size_bytes, l1_table, 0);
if (ret < 0) {
fprintf(stderr, "ERROR: I/O error in check_refcounts_l1\n");
res->check_errors++;
@ -2004,8 +2004,8 @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
}
}
ret = bdrv_pread(bs->file, l2_offset, l2_table,
s->l2_size * l2_entry_size(s));
ret = bdrv_pread(bs->file, l2_offset, s->l2_size * l2_entry_size(s),
l2_table, 0);
if (ret < 0) {
fprintf(stderr, "ERROR: Could not read L2 table: %s\n",
strerror(-ret));
@ -2058,8 +2058,8 @@ static int check_oflag_copied(BlockDriverState *bs, BdrvCheckResult *res,
goto fail;
}
ret = bdrv_pwrite(bs->file, l2_offset, l2_table,
s->cluster_size);
ret = bdrv_pwrite(bs->file, l2_offset, s->cluster_size, l2_table,
0);
if (ret < 0) {
fprintf(stderr, "ERROR: Could not write L2 table: %s\n",
strerror(-ret));
@ -2577,8 +2577,8 @@ static int rebuild_refcounts_write_refblocks(
on_disk_refblock = (void *)((char *) *refcount_table +
refblock_index * s->cluster_size);
ret = bdrv_pwrite(bs->file, refblock_offset, on_disk_refblock,
s->cluster_size);
ret = bdrv_pwrite(bs->file, refblock_offset, s->cluster_size,
on_disk_refblock, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "ERROR writing refblock");
return ret;
@ -2733,8 +2733,8 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
}
assert(reftable_length < INT_MAX);
ret = bdrv_pwrite(bs->file, reftable_offset, on_disk_reftable,
reftable_length);
ret = bdrv_pwrite(bs->file, reftable_offset, reftable_length,
on_disk_reftable, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "ERROR writing reftable");
goto fail;
@ -2746,8 +2746,8 @@ static int rebuild_refcount_structure(BlockDriverState *bs,
cpu_to_be32(reftable_clusters);
ret = bdrv_pwrite_sync(bs->file,
offsetof(QCowHeader, refcount_table_offset),
&reftable_offset_and_clusters,
sizeof(reftable_offset_and_clusters));
sizeof(reftable_offset_and_clusters),
&reftable_offset_and_clusters, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "ERROR setting reftable");
goto fail;
@ -3009,7 +3009,7 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset,
return -ENOMEM;
}
ret = bdrv_pread(bs->file, l1_ofs, l1, l1_sz2);
ret = bdrv_pread(bs->file, l1_ofs, l1_sz2, l1, 0);
if (ret < 0) {
g_free(l1);
return ret;
@ -3180,7 +3180,7 @@ static int flush_refblock(BlockDriverState *bs, uint64_t **reftable,
return ret;
}
ret = bdrv_pwrite(bs->file, offset, refblock, s->cluster_size);
ret = bdrv_pwrite(bs->file, offset, s->cluster_size, refblock, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write refblock");
return ret;
@ -3452,8 +3452,9 @@ int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order,
cpu_to_be64s(&new_reftable[i]);
}
ret = bdrv_pwrite(bs->file, new_reftable_offset, new_reftable,
new_reftable_size * REFTABLE_ENTRY_SIZE);
ret = bdrv_pwrite(bs->file, new_reftable_offset,
new_reftable_size * REFTABLE_ENTRY_SIZE, new_reftable,
0);
for (i = 0; i < new_reftable_size; i++) {
be64_to_cpus(&new_reftable[i]);
@ -3656,8 +3657,9 @@ int qcow2_shrink_reftable(BlockDriverState *bs)
reftable_tmp[i] = unused_block ? 0 : cpu_to_be64(s->refcount_table[i]);
}
ret = bdrv_pwrite_sync(bs->file, s->refcount_table_offset, reftable_tmp,
s->refcount_table_size * REFTABLE_ENTRY_SIZE);
ret = bdrv_pwrite_sync(bs->file, s->refcount_table_offset,
s->refcount_table_size * REFTABLE_ENTRY_SIZE,
reftable_tmp, 0);
/*
* If the write in the reftable failed the image may contain a partially
* overwritten reftable. In this case it would be better to clear the

View File

@ -108,7 +108,7 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair,
/* Read statically sized part of the snapshot header */
offset = ROUND_UP(offset, 8);
ret = bdrv_pread(bs->file, offset, &h, sizeof(h));
ret = bdrv_pread(bs->file, offset, sizeof(h), &h, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to read snapshot table");
goto fail;
@ -146,8 +146,8 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair,
}
/* Read known extra data */
ret = bdrv_pread(bs->file, offset, &extra,
MIN(sizeof(extra), sn->extra_data_size));
ret = bdrv_pread(bs->file, offset,
MIN(sizeof(extra), sn->extra_data_size), &extra, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to read snapshot table");
goto fail;
@ -184,8 +184,8 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair,
/* Store unknown extra data */
unknown_extra_data_size = sn->extra_data_size - sizeof(extra);
sn->unknown_extra_data = g_malloc(unknown_extra_data_size);
ret = bdrv_pread(bs->file, offset, sn->unknown_extra_data,
unknown_extra_data_size);
ret = bdrv_pread(bs->file, offset, unknown_extra_data_size,
sn->unknown_extra_data, 0);
if (ret < 0) {
error_setg_errno(errp, -ret,
"Failed to read snapshot table");
@ -196,7 +196,7 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair,
/* Read snapshot ID */
sn->id_str = g_malloc(id_str_size + 1);
ret = bdrv_pread(bs->file, offset, sn->id_str, id_str_size);
ret = bdrv_pread(bs->file, offset, id_str_size, sn->id_str, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to read snapshot table");
goto fail;
@ -206,7 +206,7 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair,
/* Read snapshot name */
sn->name = g_malloc(name_size + 1);
ret = bdrv_pread(bs->file, offset, sn->name, name_size);
ret = bdrv_pread(bs->file, offset, name_size, sn->name, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to read snapshot table");
goto fail;
@ -349,13 +349,13 @@ int qcow2_write_snapshots(BlockDriverState *bs)
h.name_size = cpu_to_be16(name_size);
offset = ROUND_UP(offset, 8);
ret = bdrv_pwrite(bs->file, offset, &h, sizeof(h));
ret = bdrv_pwrite(bs->file, offset, sizeof(h), &h, 0);
if (ret < 0) {
goto fail;
}
offset += sizeof(h);
ret = bdrv_pwrite(bs->file, offset, &extra, sizeof(extra));
ret = bdrv_pwrite(bs->file, offset, sizeof(extra), &extra, 0);
if (ret < 0) {
goto fail;
}
@ -369,21 +369,21 @@ int qcow2_write_snapshots(BlockDriverState *bs)
assert(unknown_extra_data_size <= BDRV_REQUEST_MAX_BYTES);
assert(sn->unknown_extra_data);
ret = bdrv_pwrite(bs->file, offset, sn->unknown_extra_data,
unknown_extra_data_size);
ret = bdrv_pwrite(bs->file, offset, unknown_extra_data_size,
sn->unknown_extra_data, 0);
if (ret < 0) {
goto fail;
}
offset += unknown_extra_data_size;
}
ret = bdrv_pwrite(bs->file, offset, sn->id_str, id_str_size);
ret = bdrv_pwrite(bs->file, offset, id_str_size, sn->id_str, 0);
if (ret < 0) {
goto fail;
}
offset += id_str_size;
ret = bdrv_pwrite(bs->file, offset, sn->name, name_size);
ret = bdrv_pwrite(bs->file, offset, name_size, sn->name, 0);
if (ret < 0) {
goto fail;
}
@ -406,7 +406,7 @@ int qcow2_write_snapshots(BlockDriverState *bs)
header_data.snapshots_offset = cpu_to_be64(snapshots_offset);
ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots),
&header_data, sizeof(header_data));
sizeof(header_data), &header_data, 0);
if (ret < 0) {
goto fail;
}
@ -442,7 +442,8 @@ int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs,
/* qcow2_do_open() discards this information in check mode */
ret = bdrv_pread(bs->file, offsetof(QCowHeader, nb_snapshots),
&snapshot_table_pointer, sizeof(snapshot_table_pointer));
sizeof(snapshot_table_pointer), &snapshot_table_pointer,
0);
if (ret < 0) {
result->check_errors++;
fprintf(stderr, "ERROR failed to read the snapshot table pointer from "
@ -511,9 +512,9 @@ int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs,
assert(fix & BDRV_FIX_ERRORS);
snapshot_table_pointer.nb_snapshots = cpu_to_be32(s->nb_snapshots);
ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots),
&snapshot_table_pointer.nb_snapshots,
sizeof(snapshot_table_pointer.nb_snapshots));
ret = bdrv_co_pwrite_sync(bs->file, offsetof(QCowHeader, nb_snapshots),
sizeof(snapshot_table_pointer.nb_snapshots),
&snapshot_table_pointer.nb_snapshots, 0);
if (ret < 0) {
result->check_errors++;
fprintf(stderr, "ERROR failed to update the snapshot count in the "
@ -693,8 +694,8 @@ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info)
goto fail;
}
ret = bdrv_pwrite(bs->file, sn->l1_table_offset, l1_table,
s->l1_size * L1E_SIZE);
ret = bdrv_pwrite(bs->file, sn->l1_table_offset, s->l1_size * L1E_SIZE,
l1_table, 0);
if (ret < 0) {
goto fail;
}
@ -829,8 +830,8 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
goto fail;
}
ret = bdrv_pread(bs->file, sn->l1_table_offset,
sn_l1_table, sn_l1_bytes);
ret = bdrv_pread(bs->file, sn->l1_table_offset, sn_l1_bytes, sn_l1_table,
0);
if (ret < 0) {
goto fail;
}
@ -848,8 +849,8 @@ int qcow2_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
goto fail;
}
ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset, sn_l1_table,
cur_l1_bytes);
ret = bdrv_pwrite_sync(bs->file, s->l1_table_offset, cur_l1_bytes,
sn_l1_table, 0);
if (ret < 0) {
goto fail;
}
@ -1051,8 +1052,8 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs,
return -ENOMEM;
}
ret = bdrv_pread(bs->file, sn->l1_table_offset,
new_l1_table, new_l1_bytes);
ret = bdrv_pread(bs->file, sn->l1_table_offset, new_l1_bytes,
new_l1_table, 0);
if (ret < 0) {
error_setg(errp, "Failed to read l1 table for snapshot");
qemu_vfree(new_l1_table);

View File

@ -94,9 +94,9 @@ static int qcow2_probe(const uint8_t *buf, int buf_size, const char *filename)
}
static ssize_t qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset,
uint8_t *buf, size_t buflen,
void *opaque, Error **errp)
static int qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset,
uint8_t *buf, size_t buflen,
void *opaque, Error **errp)
{
BlockDriverState *bs = opaque;
BDRVQcow2State *s = bs->opaque;
@ -107,18 +107,18 @@ static ssize_t qcow2_crypto_hdr_read_func(QCryptoBlock *block, size_t offset,
return -1;
}
ret = bdrv_pread(bs->file,
s->crypto_header.offset + offset, buf, buflen);
ret = bdrv_pread(bs->file, s->crypto_header.offset + offset, buflen, buf,
0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read encryption header");
return -1;
}
return ret;
return 0;
}
static ssize_t qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen,
void *opaque, Error **errp)
static int qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen,
void *opaque, Error **errp)
{
BlockDriverState *bs = opaque;
BDRVQcow2State *s = bs->opaque;
@ -151,13 +151,13 @@ static ssize_t qcow2_crypto_hdr_init_func(QCryptoBlock *block, size_t headerlen,
return -1;
}
return ret;
return 0;
}
static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset,
const uint8_t *buf, size_t buflen,
void *opaque, Error **errp)
static int qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset,
const uint8_t *buf, size_t buflen,
void *opaque, Error **errp)
{
BlockDriverState *bs = opaque;
BDRVQcow2State *s = bs->opaque;
@ -168,13 +168,13 @@ static ssize_t qcow2_crypto_hdr_write_func(QCryptoBlock *block, size_t offset,
return -1;
}
ret = bdrv_pwrite(bs->file,
s->crypto_header.offset + offset, buf, buflen);
ret = bdrv_pwrite(bs->file, s->crypto_header.offset + offset, buflen, buf,
0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read encryption header");
return -1;
}
return ret;
return 0;
}
static QDict*
@ -227,7 +227,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
printf("attempting to read extended header in offset %lu\n", offset);
#endif
ret = bdrv_pread(bs->file, offset, &ext, sizeof(ext));
ret = bdrv_pread(bs->file, offset, sizeof(ext), &ext, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "qcow2_read_extension: ERROR: "
"pread fail from offset %" PRIu64, offset);
@ -255,7 +255,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
sizeof(bs->backing_format));
return 2;
}
ret = bdrv_pread(bs->file, offset, bs->backing_format, ext.len);
ret = bdrv_pread(bs->file, offset, ext.len, bs->backing_format, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "ERROR: ext_backing_format: "
"Could not read format name");
@ -271,7 +271,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
case QCOW2_EXT_MAGIC_FEATURE_TABLE:
if (p_feature_table != NULL) {
void *feature_table = g_malloc0(ext.len + 2 * sizeof(Qcow2Feature));
ret = bdrv_pread(bs->file, offset , feature_table, ext.len);
ret = bdrv_pread(bs->file, offset, ext.len, feature_table, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "ERROR: ext_feature_table: "
"Could not read table");
@ -296,7 +296,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
return -EINVAL;
}
ret = bdrv_pread(bs->file, offset, &s->crypto_header, ext.len);
ret = bdrv_pread(bs->file, offset, ext.len, &s->crypto_header, 0);
if (ret < 0) {
error_setg_errno(errp, -ret,
"Unable to read CRYPTO header extension");
@ -352,7 +352,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
break;
}
ret = bdrv_pread(bs->file, offset, &bitmaps_ext, ext.len);
ret = bdrv_pread(bs->file, offset, ext.len, &bitmaps_ext, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "bitmaps_ext: "
"Could not read ext header");
@ -416,7 +416,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
case QCOW2_EXT_MAGIC_DATA_FILE:
{
s->image_data_file = g_malloc0(ext.len + 1);
ret = bdrv_pread(bs->file, offset, s->image_data_file, ext.len);
ret = bdrv_pread(bs->file, offset, ext.len, s->image_data_file, 0);
if (ret < 0) {
error_setg_errno(errp, -ret,
"ERROR: Could not read data file name");
@ -440,7 +440,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
uext->len = ext.len;
QLIST_INSERT_HEAD(&s->unknown_header_ext, uext, next);
ret = bdrv_pread(bs->file, offset , uext->data, uext->len);
ret = bdrv_pread(bs->file, offset, uext->len, uext->data, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "ERROR: unknown extension: "
"Could not read data");
@ -516,12 +516,9 @@ int qcow2_mark_dirty(BlockDriverState *bs)
}
val = cpu_to_be64(s->incompatible_features | QCOW2_INCOMPAT_DIRTY);
ret = bdrv_pwrite(bs->file, offsetof(QCowHeader, incompatible_features),
&val, sizeof(val));
if (ret < 0) {
return ret;
}
ret = bdrv_flush(bs->file->bs);
ret = bdrv_pwrite_sync(bs->file,
offsetof(QCowHeader, incompatible_features),
sizeof(val), &val, 0);
if (ret < 0) {
return ret;
}
@ -1308,7 +1305,7 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
uint64_t l1_vm_state_index;
bool update_header = false;
ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
ret = bdrv_pread(bs->file, 0, sizeof(header), &header, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read qcow2 header");
goto fail;
@ -1384,8 +1381,9 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
if (header.header_length > sizeof(header)) {
s->unknown_header_fields_size = header.header_length - sizeof(header);
s->unknown_header_fields = g_malloc(s->unknown_header_fields_size);
ret = bdrv_pread(bs->file, sizeof(header), s->unknown_header_fields,
s->unknown_header_fields_size);
ret = bdrv_pread(bs->file, sizeof(header),
s->unknown_header_fields_size,
s->unknown_header_fields, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read unknown qcow2 header "
"fields");
@ -1580,8 +1578,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
ret = -ENOMEM;
goto fail;
}
ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_table,
s->l1_size * L1E_SIZE);
ret = bdrv_pread(bs->file, s->l1_table_offset, s->l1_size * L1E_SIZE,
s->l1_table, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read L1 table");
goto fail;
@ -1698,8 +1696,8 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options,
ret = -EINVAL;
goto fail;
}
ret = bdrv_pread(bs->file, header.backing_file_offset,
bs->auto_backing_file, len);
ret = bdrv_pread(bs->file, header.backing_file_offset, len,
bs->auto_backing_file, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read backing file name");
goto fail;
@ -3081,7 +3079,7 @@ int qcow2_update_header(BlockDriverState *bs)
}
/* Write the new header */
ret = bdrv_pwrite(bs->file, 0, header, s->cluster_size);
ret = bdrv_pwrite(bs->file, 0, s->cluster_size, header, 0);
if (ret < 0) {
goto fail;
}
@ -3668,7 +3666,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
cpu_to_be64(QCOW2_INCOMPAT_EXTL2);
}
ret = blk_pwrite(blk, 0, header, cluster_size, 0);
ret = blk_pwrite(blk, 0, cluster_size, header, 0);
g_free(header);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write qcow2 header");
@ -3678,7 +3676,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp)
/* Write a refcount table with one refcount block */
refcount_table = g_malloc0(2 * cluster_size);
refcount_table[0] = cpu_to_be64(2 * cluster_size);
ret = blk_pwrite(blk, cluster_size, refcount_table, 2 * cluster_size, 0);
ret = blk_pwrite(blk, cluster_size, 2 * cluster_size, refcount_table, 0);
g_free(refcount_table);
if (ret < 0) {
@ -4550,8 +4548,8 @@ static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t offset,
/* write updated header.size */
offset = cpu_to_be64(offset);
ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, size),
&offset, sizeof(offset));
ret = bdrv_co_pwrite_sync(bs->file, offsetof(QCowHeader, size),
sizeof(offset), &offset, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to update the image size");
goto fail;
@ -4828,7 +4826,7 @@ static int make_completely_empty(BlockDriverState *bs)
l1_ofs_rt_ofs_cls.reftable_offset = cpu_to_be64(s->cluster_size);
l1_ofs_rt_ofs_cls.reftable_clusters = cpu_to_be32(1);
ret = bdrv_pwrite_sync(bs->file, offsetof(QCowHeader, l1_table_offset),
&l1_ofs_rt_ofs_cls, sizeof(l1_ofs_rt_ofs_cls));
sizeof(l1_ofs_rt_ofs_cls), &l1_ofs_rt_ofs_cls, 0);
if (ret < 0) {
goto fail_broken_refcounts;
}
@ -4859,8 +4857,8 @@ static int make_completely_empty(BlockDriverState *bs)
/* Enter the first refblock into the reftable */
rt_entry = cpu_to_be64(2 * s->cluster_size);
ret = bdrv_pwrite_sync(bs->file, s->cluster_size,
&rt_entry, sizeof(rt_entry));
ret = bdrv_pwrite_sync(bs->file, s->cluster_size, sizeof(rt_entry),
&rt_entry, 0);
if (ret < 0) {
goto fail_broken_refcounts;
}

View File

@ -87,14 +87,9 @@ static void qed_header_cpu_to_le(const QEDHeader *cpu, QEDHeader *le)
int qed_write_header_sync(BDRVQEDState *s)
{
QEDHeader le;
int ret;
qed_header_cpu_to_le(&s->header, &le);
ret = bdrv_pwrite(s->bs->file, 0, &le, sizeof(le));
if (ret != sizeof(le)) {
return ret;
}
return 0;
return bdrv_pwrite(s->bs->file, 0, sizeof(le), &le, 0);
}
/**
@ -207,7 +202,7 @@ static int qed_read_string(BdrvChild *file, uint64_t offset, size_t n,
if (n >= buflen) {
return -EINVAL;
}
ret = bdrv_pread(file, offset, buf, n);
ret = bdrv_pread(file, offset, n, buf, 0);
if (ret < 0) {
return ret;
}
@ -392,7 +387,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *options,
int64_t file_size;
int ret;
ret = bdrv_pread(bs->file, 0, &le_header, sizeof(le_header));
ret = bdrv_pread(bs->file, 0, sizeof(le_header), &le_header, 0);
if (ret < 0) {
error_setg(errp, "Failed to read QED header");
return ret;
@ -710,18 +705,18 @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCreateOptions *opts,
}
qed_header_cpu_to_le(&header, &le_header);
ret = blk_pwrite(blk, 0, &le_header, sizeof(le_header), 0);
ret = blk_pwrite(blk, 0, sizeof(le_header), &le_header, 0);
if (ret < 0) {
goto out;
}
ret = blk_pwrite(blk, sizeof(le_header), qed_opts->backing_file,
header.backing_filename_size, 0);
ret = blk_pwrite(blk, sizeof(le_header), header.backing_filename_size,
qed_opts->backing_file, 0);
if (ret < 0) {
goto out;
}
l1_table = g_malloc0(l1_size);
ret = blk_pwrite(blk, header.l1_table_offset, l1_table, l1_size, 0);
ret = blk_pwrite(blk, header.l1_table_offset, l1_size, l1_table, 0);
if (ret < 0) {
goto out;
}
@ -1545,7 +1540,7 @@ static int bdrv_qed_change_backing_file(BlockDriverState *bs,
}
/* Write new header */
ret = bdrv_pwrite_sync(bs->file, 0, buffer, buffer_len);
ret = bdrv_pwrite_sync(bs->file, 0, buffer_len, buffer, 0);
g_free(buffer);
if (ret == 0) {
memcpy(&s->header, &new_header, sizeof(new_header));

View File

@ -385,7 +385,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
logout("\n");
ret = bdrv_pread(bs->file, 0, &header, sizeof(header));
ret = bdrv_pread(bs->file, 0, sizeof(header), &header, 0);
if (ret < 0) {
goto fail;
}
@ -485,8 +485,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,
goto fail;
}
ret = bdrv_pread(bs->file, header.offset_bmap, s->bmap,
bmap_size * SECTOR_SIZE);
ret = bdrv_pread(bs->file, header.offset_bmap, bmap_size * SECTOR_SIZE,
s->bmap, 0);
if (ret < 0) {
goto fail_free_bmap;
}
@ -664,7 +664,7 @@ vdi_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes,
* so this full-cluster write does not overlap a partial write
* of the same cluster, issued from the "else" branch.
*/
ret = bdrv_pwrite(bs->file, data_offset, block, s->block_size);
ret = bdrv_pwrite(bs->file, data_offset, s->block_size, block, 0);
qemu_co_rwlock_unlock(&s->bmap_lock);
} else {
nonallocating_write:
@ -709,7 +709,7 @@ nonallocating_write:
assert(VDI_IS_ALLOCATED(bmap_first));
*header = s->header;
vdi_header_to_le(header);
ret = bdrv_pwrite(bs->file, 0, header, sizeof(*header));
ret = bdrv_pwrite(bs->file, 0, sizeof(*header), header, 0);
g_free(header);
if (ret < 0) {
@ -726,11 +726,11 @@ nonallocating_write:
base = ((uint8_t *)&s->bmap[0]) + bmap_first * SECTOR_SIZE;
logout("will write %u block map sectors starting from entry %u\n",
n_sectors, bmap_first);
ret = bdrv_pwrite(bs->file, offset * SECTOR_SIZE, base,
n_sectors * SECTOR_SIZE);
ret = bdrv_pwrite(bs->file, offset * SECTOR_SIZE,
n_sectors * SECTOR_SIZE, base, 0);
}
return ret < 0 ? ret : 0;
return ret;
}
static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
@ -845,7 +845,7 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
vdi_header_print(&header);
}
vdi_header_to_le(&header);
ret = blk_pwrite(blk, offset, &header, sizeof(header), 0);
ret = blk_pwrite(blk, offset, sizeof(header), &header, 0);
if (ret < 0) {
error_setg(errp, "Error writing header");
goto exit;
@ -866,7 +866,7 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreateOptions *create_options,
bmap[i] = VDI_UNALLOCATED;
}
}
ret = blk_pwrite(blk, offset, bmap, bmap_size, 0);
ret = blk_pwrite(blk, offset, bmap_size, bmap, 0);
if (ret < 0) {
error_setg(errp, "Error writing bmap");
goto exit;

View File

@ -84,7 +84,7 @@ static int vhdx_log_peek_hdr(BlockDriverState *bs, VHDXLogEntries *log,
offset = log->offset + read;
ret = bdrv_pread(bs->file, offset, hdr, sizeof(VHDXLogEntryHeader));
ret = bdrv_pread(bs->file, offset, sizeof(VHDXLogEntryHeader), hdr, 0);
if (ret < 0) {
goto exit;
}
@ -144,7 +144,7 @@ static int vhdx_log_read_sectors(BlockDriverState *bs, VHDXLogEntries *log,
}
offset = log->offset + read;
ret = bdrv_pread(bs->file, offset, buffer, VHDX_LOG_SECTOR_SIZE);
ret = bdrv_pread(bs->file, offset, VHDX_LOG_SECTOR_SIZE, buffer, 0);
if (ret < 0) {
goto exit;
}
@ -194,8 +194,8 @@ static int vhdx_log_write_sectors(BlockDriverState *bs, VHDXLogEntries *log,
/* full */
break;
}
ret = bdrv_pwrite(bs->file, offset, buffer_tmp,
VHDX_LOG_SECTOR_SIZE);
ret = bdrv_pwrite(bs->file, offset, VHDX_LOG_SECTOR_SIZE, buffer_tmp,
0);
if (ret < 0) {
goto exit;
}
@ -466,8 +466,8 @@ static int vhdx_log_flush_desc(BlockDriverState *bs, VHDXLogDescriptor *desc,
/* count is only > 1 if we are writing zeroes */
for (i = 0; i < count; i++) {
ret = bdrv_pwrite_sync(bs->file, file_offset, buffer,
VHDX_LOG_SECTOR_SIZE);
ret = bdrv_pwrite_sync(bs->file, file_offset, VHDX_LOG_SECTOR_SIZE,
buffer, 0);
if (ret < 0) {
goto exit;
}
@ -970,8 +970,8 @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
if (i == 0 && leading_length) {
/* partial sector at the front of the buffer */
ret = bdrv_pread(bs->file, file_offset, merged_sector,
VHDX_LOG_SECTOR_SIZE);
ret = bdrv_pread(bs->file, file_offset, VHDX_LOG_SECTOR_SIZE,
merged_sector, 0);
if (ret < 0) {
goto exit;
}
@ -980,10 +980,9 @@ static int vhdx_log_write(BlockDriverState *bs, BDRVVHDXState *s,
sector_write = merged_sector;
} else if (i == sectors - 1 && trailing_length) {
/* partial sector at the end of the buffer */
ret = bdrv_pread(bs->file,
file_offset,
merged_sector + trailing_length,
VHDX_LOG_SECTOR_SIZE - trailing_length);
ret = bdrv_pread(bs->file, file_offset,
VHDX_LOG_SECTOR_SIZE - trailing_length,
merged_sector + trailing_length, 0);
if (ret < 0) {
goto exit;
}

View File

@ -326,7 +326,7 @@ static int vhdx_write_header(BdrvChild *file, VHDXHeader *hdr,
buffer = qemu_blockalign(bs_file, VHDX_HEADER_SIZE);
if (read) {
/* if true, we can't assume the extra reserved bytes are 0 */
ret = bdrv_pread(file, offset, buffer, VHDX_HEADER_SIZE);
ret = bdrv_pread(file, offset, VHDX_HEADER_SIZE, buffer, 0);
if (ret < 0) {
goto exit;
}
@ -340,7 +340,7 @@ static int vhdx_write_header(BdrvChild *file, VHDXHeader *hdr,
vhdx_header_le_export(hdr, header_le);
vhdx_update_checksum(buffer, VHDX_HEADER_SIZE,
offsetof(VHDXHeader, checksum));
ret = bdrv_pwrite_sync(file, offset, header_le, sizeof(VHDXHeader));
ret = bdrv_pwrite_sync(file, offset, sizeof(VHDXHeader), header_le, 0);
exit:
qemu_vfree(buffer);
@ -440,8 +440,8 @@ static void vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s,
/* We have to read the whole VHDX_HEADER_SIZE instead of
* sizeof(VHDXHeader), because the checksum is over the whole
* region */
ret = bdrv_pread(bs->file, VHDX_HEADER1_OFFSET, buffer,
VHDX_HEADER_SIZE);
ret = bdrv_pread(bs->file, VHDX_HEADER1_OFFSET, VHDX_HEADER_SIZE, buffer,
0);
if (ret < 0) {
goto fail;
}
@ -457,8 +457,8 @@ static void vhdx_parse_header(BlockDriverState *bs, BDRVVHDXState *s,
}
}
ret = bdrv_pread(bs->file, VHDX_HEADER2_OFFSET, buffer,
VHDX_HEADER_SIZE);
ret = bdrv_pread(bs->file, VHDX_HEADER2_OFFSET, VHDX_HEADER_SIZE, buffer,
0);
if (ret < 0) {
goto fail;
}
@ -531,8 +531,8 @@ static int vhdx_open_region_tables(BlockDriverState *bs, BDRVVHDXState *s)
* whole block */
buffer = qemu_blockalign(bs, VHDX_HEADER_BLOCK_SIZE);
ret = bdrv_pread(bs->file, VHDX_REGION_TABLE_OFFSET, buffer,
VHDX_HEADER_BLOCK_SIZE);
ret = bdrv_pread(bs->file, VHDX_REGION_TABLE_OFFSET,
VHDX_HEADER_BLOCK_SIZE, buffer, 0);
if (ret < 0) {
goto fail;
}
@ -644,8 +644,8 @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s)
buffer = qemu_blockalign(bs, VHDX_METADATA_TABLE_MAX_SIZE);
ret = bdrv_pread(bs->file, s->metadata_rt.file_offset, buffer,
VHDX_METADATA_TABLE_MAX_SIZE);
ret = bdrv_pread(bs->file, s->metadata_rt.file_offset,
VHDX_METADATA_TABLE_MAX_SIZE, buffer, 0);
if (ret < 0) {
goto exit;
}
@ -750,8 +750,9 @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s)
ret = bdrv_pread(bs->file,
s->metadata_entries.file_parameters_entry.offset
+ s->metadata_rt.file_offset,
sizeof(s->params),
&s->params,
sizeof(s->params));
0);
if (ret < 0) {
goto exit;
@ -785,24 +786,27 @@ static int vhdx_parse_metadata(BlockDriverState *bs, BDRVVHDXState *s)
ret = bdrv_pread(bs->file,
s->metadata_entries.virtual_disk_size_entry.offset
+ s->metadata_rt.file_offset,
sizeof(uint64_t),
&s->virtual_disk_size,
sizeof(uint64_t));
0);
if (ret < 0) {
goto exit;
}
ret = bdrv_pread(bs->file,
s->metadata_entries.logical_sector_size_entry.offset
+ s->metadata_rt.file_offset,
sizeof(uint32_t),
&s->logical_sector_size,
sizeof(uint32_t));
0);
if (ret < 0) {
goto exit;
}
ret = bdrv_pread(bs->file,
s->metadata_entries.phys_sector_size_entry.offset
+ s->metadata_rt.file_offset,
sizeof(uint32_t),
&s->physical_sector_size,
sizeof(uint32_t));
0);
if (ret < 0) {
goto exit;
}
@ -1010,7 +1014,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
QLIST_INIT(&s->regions);
/* validate the file signature */
ret = bdrv_pread(bs->file, 0, &signature, sizeof(uint64_t));
ret = bdrv_pread(bs->file, 0, sizeof(uint64_t), &signature, 0);
if (ret < 0) {
goto fail;
}
@ -1069,7 +1073,7 @@ static int vhdx_open(BlockDriverState *bs, QDict *options, int flags,
goto fail;
}
ret = bdrv_pread(bs->file, s->bat_offset, s->bat, s->bat_rt.length);
ret = bdrv_pread(bs->file, s->bat_offset, s->bat_rt.length, s->bat, 0);
if (ret < 0) {
goto fail;
}
@ -1661,13 +1665,13 @@ static int vhdx_create_new_metadata(BlockBackend *blk,
VHDX_META_FLAGS_IS_VIRTUAL_DISK;
vhdx_metadata_entry_le_export(&md_table_entry[4]);
ret = blk_pwrite(blk, metadata_offset, buffer, VHDX_HEADER_BLOCK_SIZE, 0);
ret = blk_pwrite(blk, metadata_offset, VHDX_HEADER_BLOCK_SIZE, buffer, 0);
if (ret < 0) {
goto exit;
}
ret = blk_pwrite(blk, metadata_offset + (64 * KiB), entry_buffer,
VHDX_METADATA_ENTRY_BUFFER_SIZE, 0);
ret = blk_pwrite(blk, metadata_offset + (64 * KiB),
VHDX_METADATA_ENTRY_BUFFER_SIZE, entry_buffer, 0);
if (ret < 0) {
goto exit;
}
@ -1752,7 +1756,7 @@ static int vhdx_create_bat(BlockBackend *blk, BDRVVHDXState *s,
s->bat[sinfo.bat_idx] = cpu_to_le64(s->bat[sinfo.bat_idx]);
sector_num += s->sectors_per_block;
}
ret = blk_pwrite(blk, file_offset, s->bat, length, 0);
ret = blk_pwrite(blk, file_offset, length, s->bat, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write the BAT");
goto exit;
@ -1856,15 +1860,15 @@ static int vhdx_create_new_region_table(BlockBackend *blk,
}
/* Now write out the region headers to disk */
ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, buffer,
VHDX_HEADER_BLOCK_SIZE, 0);
ret = blk_pwrite(blk, VHDX_REGION_TABLE_OFFSET, VHDX_HEADER_BLOCK_SIZE,
buffer, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write first region table");
goto exit;
}
ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, buffer,
VHDX_HEADER_BLOCK_SIZE, 0);
ret = blk_pwrite(blk, VHDX_REGION_TABLE2_OFFSET, VHDX_HEADER_BLOCK_SIZE,
buffer, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write second region table");
goto exit;
@ -2008,7 +2012,7 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
creator = g_utf8_to_utf16("QEMU v" QEMU_VERSION, -1, NULL,
&creator_items, NULL);
signature = cpu_to_le64(VHDX_FILE_SIGNATURE);
ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, &signature, sizeof(signature),
ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET, sizeof(signature), &signature,
0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write file signature");
@ -2016,7 +2020,7 @@ static int coroutine_fn vhdx_co_create(BlockdevCreateOptions *opts,
}
if (creator) {
ret = blk_pwrite(blk, VHDX_FILE_ID_OFFSET + sizeof(signature),
creator, creator_items * sizeof(gunichar2), 0);
creator_items * sizeof(gunichar2), creator, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to write creator field");
goto delete_and_exit;

View File

@ -307,7 +307,7 @@ static int vmdk_read_cid(BlockDriverState *bs, int parent, uint32_t *pcid)
int ret;
desc = g_malloc0(DESC_SIZE);
ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE);
ret = bdrv_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
if (ret < 0) {
goto out;
}
@ -348,7 +348,7 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
desc = g_malloc0(DESC_SIZE);
tmp_desc = g_malloc0(DESC_SIZE);
ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE);
ret = bdrv_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
if (ret < 0) {
goto out;
}
@ -368,7 +368,7 @@ static int vmdk_write_cid(BlockDriverState *bs, uint32_t cid)
pstrcat(desc, DESC_SIZE, tmp_desc);
}
ret = bdrv_pwrite_sync(bs->file, s->desc_offset, desc, DESC_SIZE);
ret = bdrv_pwrite_sync(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
out:
g_free(desc);
@ -469,11 +469,10 @@ static int vmdk_parent_open(BlockDriverState *bs)
int ret;
desc = g_malloc0(DESC_SIZE + 1);
ret = bdrv_pread(bs->file, s->desc_offset, desc, DESC_SIZE);
ret = bdrv_pread(bs->file, s->desc_offset, DESC_SIZE, desc, 0);
if (ret < 0) {
goto out;
}
ret = 0;
p_name = strstr(desc, "parentFileNameHint");
if (p_name != NULL) {
@ -589,10 +588,8 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent,
return -ENOMEM;
}
ret = bdrv_pread(extent->file,
extent->l1_table_offset,
extent->l1_table,
l1_size);
ret = bdrv_pread(extent->file, extent->l1_table_offset, l1_size,
extent->l1_table, 0);
if (ret < 0) {
bdrv_refresh_filename(extent->file->bs);
error_setg_errno(errp, -ret,
@ -616,10 +613,8 @@ static int vmdk_init_tables(BlockDriverState *bs, VmdkExtent *extent,
ret = -ENOMEM;
goto fail_l1;
}
ret = bdrv_pread(extent->file,
extent->l1_backup_table_offset,
extent->l1_backup_table,
l1_size);
ret = bdrv_pread(extent->file, extent->l1_backup_table_offset,
l1_size, extent->l1_backup_table, 0);
if (ret < 0) {
bdrv_refresh_filename(extent->file->bs);
error_setg_errno(errp, -ret,
@ -651,7 +646,7 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
VMDK3Header header;
VmdkExtent *extent = NULL;
ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
ret = bdrv_pread(file, sizeof(magic), sizeof(header), &header, 0);
if (ret < 0) {
bdrv_refresh_filename(file->bs);
error_setg_errno(errp, -ret,
@ -815,7 +810,7 @@ static int vmdk_open_se_sparse(BlockDriverState *bs,
assert(sizeof(const_header) == SECTOR_SIZE);
ret = bdrv_pread(file, 0, &const_header, sizeof(const_header));
ret = bdrv_pread(file, 0, sizeof(const_header), &const_header, 0);
if (ret < 0) {
bdrv_refresh_filename(file->bs);
error_setg_errno(errp, -ret,
@ -832,9 +827,8 @@ static int vmdk_open_se_sparse(BlockDriverState *bs,
assert(sizeof(volatile_header) == SECTOR_SIZE);
ret = bdrv_pread(file,
const_header.volatile_header_offset * SECTOR_SIZE,
&volatile_header, sizeof(volatile_header));
ret = bdrv_pread(file, const_header.volatile_header_offset * SECTOR_SIZE,
sizeof(volatile_header), &volatile_header, 0);
if (ret < 0) {
bdrv_refresh_filename(file->bs);
error_setg_errno(errp, -ret,
@ -904,13 +898,13 @@ static char *vmdk_read_desc(BdrvChild *file, uint64_t desc_offset, Error **errp)
size = MIN(size, (1 << 20) - 1); /* avoid unbounded allocation */
buf = g_malloc(size + 1);
ret = bdrv_pread(file, desc_offset, buf, size);
ret = bdrv_pread(file, desc_offset, size, buf, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read from file");
g_free(buf);
return NULL;
}
buf[ret] = 0;
buf[size] = 0;
return buf;
}
@ -928,7 +922,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
int64_t l1_backup_offset = 0;
bool compressed;
ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
ret = bdrv_pread(file, sizeof(magic), sizeof(header), &header, 0);
if (ret < 0) {
bdrv_refresh_filename(file->bs);
error_setg_errno(errp, -ret,
@ -979,9 +973,8 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
} QEMU_PACKED eos_marker;
} QEMU_PACKED footer;
ret = bdrv_pread(file,
bs->file->bs->total_sectors * 512 - 1536,
&footer, sizeof(footer));
ret = bdrv_pread(file, bs->file->bs->total_sectors * 512 - 1536,
sizeof(footer), &footer, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Failed to read footer");
return ret;
@ -1448,16 +1441,16 @@ static int get_whole_cluster(BlockDriverState *bs,
if (copy_from_backing) {
/* qcow2 emits this on bs->file instead of bs->backing */
BLKDBG_EVENT(extent->file, BLKDBG_COW_READ);
ret = bdrv_pread(bs->backing, offset, whole_grain,
skip_start_bytes);
ret = bdrv_pread(bs->backing, offset, skip_start_bytes,
whole_grain, 0);
if (ret < 0) {
ret = VMDK_ERROR;
goto exit;
}
}
BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE);
ret = bdrv_pwrite(extent->file, cluster_offset, whole_grain,
skip_start_bytes);
ret = bdrv_pwrite(extent->file, cluster_offset, skip_start_bytes,
whole_grain, 0);
if (ret < 0) {
ret = VMDK_ERROR;
goto exit;
@ -1469,8 +1462,8 @@ static int get_whole_cluster(BlockDriverState *bs,
/* qcow2 emits this on bs->file instead of bs->backing */
BLKDBG_EVENT(extent->file, BLKDBG_COW_READ);
ret = bdrv_pread(bs->backing, offset + skip_end_bytes,
whole_grain + skip_end_bytes,
cluster_bytes - skip_end_bytes);
cluster_bytes - skip_end_bytes,
whole_grain + skip_end_bytes, 0);
if (ret < 0) {
ret = VMDK_ERROR;
goto exit;
@ -1478,8 +1471,8 @@ static int get_whole_cluster(BlockDriverState *bs,
}
BLKDBG_EVENT(extent->file, BLKDBG_COW_WRITE);
ret = bdrv_pwrite(extent->file, cluster_offset + skip_end_bytes,
whole_grain + skip_end_bytes,
cluster_bytes - skip_end_bytes);
cluster_bytes - skip_end_bytes,
whole_grain + skip_end_bytes, 0);
if (ret < 0) {
ret = VMDK_ERROR;
goto exit;
@ -1501,7 +1494,7 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data,
if (bdrv_pwrite(extent->file,
((int64_t)m_data->l2_offset * 512)
+ (m_data->l2_index * sizeof(offset)),
&offset, sizeof(offset)) < 0) {
sizeof(offset), &offset, 0) < 0) {
return VMDK_ERROR;
}
/* update backup L2 table */
@ -1510,7 +1503,7 @@ static int vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data,
if (bdrv_pwrite(extent->file,
((int64_t)m_data->l2_offset * 512)
+ (m_data->l2_index * sizeof(offset)),
&offset, sizeof(offset)) < 0) {
sizeof(offset), &offset, 0) < 0) {
return VMDK_ERROR;
}
}
@ -1633,9 +1626,10 @@ static int get_cluster_offset(BlockDriverState *bs,
BLKDBG_EVENT(extent->file, BLKDBG_L2_LOAD);
if (bdrv_pread(extent->file,
(int64_t)l2_offset * 512,
l2_size_bytes,
l2_table,
l2_size_bytes
) != l2_size_bytes) {
0
) < 0) {
return VMDK_ERROR;
}
@ -1903,9 +1897,7 @@ static int vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset,
cluster_buf = g_malloc(buf_bytes);
uncomp_buf = g_malloc(cluster_bytes);
BLKDBG_EVENT(extent->file, BLKDBG_READ_COMPRESSED);
ret = bdrv_pread(extent->file,
cluster_offset,
cluster_buf, buf_bytes);
ret = bdrv_pread(extent->file, cluster_offset, buf_bytes, cluster_buf, 0);
if (ret < 0) {
goto out;
}
@ -2244,12 +2236,12 @@ static int vmdk_init_extent(BlockBackend *blk,
header.check_bytes[3] = 0xa;
/* write all the data */
ret = blk_pwrite(blk, 0, &magic, sizeof(magic), 0);
ret = blk_pwrite(blk, 0, sizeof(magic), &magic, 0);
if (ret < 0) {
error_setg(errp, QERR_IO_ERROR);
goto exit;
}
ret = blk_pwrite(blk, sizeof(magic), &header, sizeof(header), 0);
ret = blk_pwrite(blk, sizeof(magic), sizeof(header), &header, 0);
if (ret < 0) {
error_setg(errp, QERR_IO_ERROR);
goto exit;
@ -2269,7 +2261,7 @@ static int vmdk_init_extent(BlockBackend *blk,
gd_buf[i] = cpu_to_le32(tmp);
}
ret = blk_pwrite(blk, le64_to_cpu(header.rgd_offset) * BDRV_SECTOR_SIZE,
gd_buf, gd_buf_size, 0);
gd_buf_size, gd_buf, 0);
if (ret < 0) {
error_setg(errp, QERR_IO_ERROR);
goto exit;
@ -2281,7 +2273,7 @@ static int vmdk_init_extent(BlockBackend *blk,
gd_buf[i] = cpu_to_le32(tmp);
}
ret = blk_pwrite(blk, le64_to_cpu(header.gd_offset) * BDRV_SECTOR_SIZE,
gd_buf, gd_buf_size, 0);
gd_buf_size, gd_buf, 0);
if (ret < 0) {
error_setg(errp, QERR_IO_ERROR);
}
@ -2592,7 +2584,7 @@ static int coroutine_fn vmdk_co_do_create(int64_t size,
desc_offset = 0x200;
}
ret = blk_pwrite(blk, desc_offset, desc, desc_len, 0);
ret = blk_pwrite(blk, desc_offset, desc_len, desc, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not write description");
goto exit;

View File

@ -252,7 +252,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
goto fail;
}
ret = bdrv_pread(bs->file, 0, &s->footer, sizeof(s->footer));
ret = bdrv_pread(bs->file, 0, sizeof(s->footer), &s->footer, 0);
if (ret < 0) {
error_setg(errp, "Unable to read VHD header");
goto fail;
@ -272,8 +272,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
}
/* If a fixed disk, the footer is found only at the end of the file */
ret = bdrv_pread(bs->file, offset - sizeof(*footer),
footer, sizeof(*footer));
ret = bdrv_pread(bs->file, offset - sizeof(*footer), sizeof(*footer),
footer, 0);
if (ret < 0) {
goto fail;
}
@ -347,7 +347,7 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
if (disk_type == VHD_DYNAMIC) {
ret = bdrv_pread(bs->file, be64_to_cpu(footer->data_offset),
&dyndisk_header, sizeof(dyndisk_header));
sizeof(dyndisk_header), &dyndisk_header, 0);
if (ret < 0) {
error_setg(errp, "Error reading dynamic VHD header");
goto fail;
@ -401,8 +401,8 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
s->bat_offset = be64_to_cpu(dyndisk_header.table_offset);
ret = bdrv_pread(bs->file, s->bat_offset, s->pagetable,
pagetable_size);
ret = bdrv_pread(bs->file, s->bat_offset, pagetable_size,
s->pagetable, 0);
if (ret < 0) {
error_setg(errp, "Error reading pagetable");
goto fail;
@ -516,7 +516,8 @@ static inline int64_t get_image_offset(BlockDriverState *bs, uint64_t offset,
s->last_bitmap_offset = bitmap_offset;
memset(bitmap, 0xff, s->bitmap_size);
r = bdrv_pwrite_sync(bs->file, bitmap_offset, bitmap, s->bitmap_size);
r = bdrv_pwrite_sync(bs->file, bitmap_offset, s->bitmap_size, bitmap,
0);
if (r < 0) {
*err = r;
return -2;
@ -538,7 +539,7 @@ static int rewrite_footer(BlockDriverState *bs)
BDRVVPCState *s = bs->opaque;
int64_t offset = s->free_data_block_offset;
ret = bdrv_pwrite_sync(bs->file, offset, &s->footer, sizeof(s->footer));
ret = bdrv_pwrite_sync(bs->file, offset, sizeof(s->footer), &s->footer, 0);
if (ret < 0)
return ret;
@ -572,8 +573,8 @@ static int64_t alloc_block(BlockDriverState *bs, int64_t offset)
/* Initialize the block's bitmap */
memset(bitmap, 0xff, s->bitmap_size);
ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset, bitmap,
s->bitmap_size);
ret = bdrv_pwrite_sync(bs->file, s->free_data_block_offset,
s->bitmap_size, bitmap, 0);
if (ret < 0) {
return ret;
}
@ -587,7 +588,7 @@ static int64_t alloc_block(BlockDriverState *bs, int64_t offset)
/* Write BAT entry to disk */
bat_offset = s->bat_offset + (4 * index);
bat_value = cpu_to_be32(s->pagetable[index]);
ret = bdrv_pwrite_sync(bs->file, bat_offset, &bat_value, 4);
ret = bdrv_pwrite_sync(bs->file, bat_offset, 4, &bat_value, 0);
if (ret < 0)
goto fail;
@ -833,13 +834,13 @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
block_size = 0x200000;
num_bat_entries = DIV_ROUND_UP(total_sectors, block_size / 512);
ret = blk_pwrite(blk, offset, footer, sizeof(*footer), 0);
ret = blk_pwrite(blk, offset, sizeof(*footer), footer, 0);
if (ret < 0) {
goto fail;
}
offset = 1536 + ((num_bat_entries * 4 + 511) & ~511);
ret = blk_pwrite(blk, offset, footer, sizeof(*footer), 0);
ret = blk_pwrite(blk, offset, sizeof(*footer), footer, 0);
if (ret < 0) {
goto fail;
}
@ -849,7 +850,7 @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
memset(bat_sector, 0xFF, 512);
for (i = 0; i < DIV_ROUND_UP(num_bat_entries * 4, 512); i++) {
ret = blk_pwrite(blk, offset, bat_sector, 512, 0);
ret = blk_pwrite(blk, offset, 512, bat_sector, 0);
if (ret < 0) {
goto fail;
}
@ -877,7 +878,7 @@ static int create_dynamic_disk(BlockBackend *blk, VHDFooter *footer,
/* Write the header */
offset = 512;
ret = blk_pwrite(blk, offset, &dyndisk_header, sizeof(dyndisk_header), 0);
ret = blk_pwrite(blk, offset, sizeof(dyndisk_header), &dyndisk_header, 0);
if (ret < 0) {
goto fail;
}
@ -900,8 +901,8 @@ static int create_fixed_disk(BlockBackend *blk, VHDFooter *footer,
return ret;
}
ret = blk_pwrite(blk, total_size - sizeof(*footer),
footer, sizeof(*footer), 0);
ret = blk_pwrite(blk, total_size - sizeof(*footer), sizeof(*footer),
footer, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Unable to write VHD header");
return ret;

View File

@ -1488,8 +1488,8 @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num,
DLOG(fprintf(stderr, "sectors %" PRId64 "+%" PRId64
" allocated\n", sector_num,
n >> BDRV_SECTOR_BITS));
if (bdrv_pread(s->qcow, sector_num * BDRV_SECTOR_SIZE,
buf + i * 0x200, n) < 0) {
if (bdrv_pread(s->qcow, sector_num * BDRV_SECTOR_SIZE, n,
buf + i * 0x200, 0) < 0) {
return -1;
}
i += (n >> BDRV_SECTOR_BITS) - 1;
@ -1978,7 +1978,8 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,
return -1;
}
res = bdrv_pwrite(s->qcow, offset * BDRV_SECTOR_SIZE,
s->cluster_buffer, BDRV_SECTOR_SIZE);
BDRV_SECTOR_SIZE, s->cluster_buffer,
0);
if (res < 0) {
return -2;
}
@ -3062,8 +3063,8 @@ DLOG(checkpoint());
* Use qcow backend. Commit later.
*/
DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num, nb_sectors));
ret = bdrv_pwrite(s->qcow, sector_num * BDRV_SECTOR_SIZE, buf,
nb_sectors * BDRV_SECTOR_SIZE);
ret = bdrv_pwrite(s->qcow, sector_num * BDRV_SECTOR_SIZE,
nb_sectors * BDRV_SECTOR_SIZE, buf, 0);
if (ret < 0) {
fprintf(stderr, "Error writing to qcow backend\n");
return ret;

View File

@ -495,7 +495,7 @@ qcrypto_block_luks_load_header(QCryptoBlock *block,
void *opaque,
Error **errp)
{
ssize_t rv;
int rv;
size_t i;
QCryptoBlockLUKS *luks = block->opaque;
@ -856,7 +856,7 @@ qcrypto_block_luks_store_key(QCryptoBlock *block,
QCRYPTO_BLOCK_LUKS_SECTOR_SIZE,
splitkey, splitkeylen,
opaque,
errp) != splitkeylen) {
errp) < 0) {
goto cleanup;
}
@ -903,7 +903,7 @@ qcrypto_block_luks_load_key(QCryptoBlock *block,
g_autofree uint8_t *splitkey = NULL;
size_t splitkeylen;
g_autofree uint8_t *possiblekey = NULL;
ssize_t rv;
int rv;
g_autoptr(QCryptoCipher) cipher = NULL;
uint8_t keydigest[QCRYPTO_BLOCK_LUKS_DIGEST_LEN];
g_autoptr(QCryptoIVGen) ivgen = NULL;
@ -1193,7 +1193,7 @@ qcrypto_block_luks_erase_key(QCryptoBlock *block,
garbagesplitkey,
splitkeylen,
opaque,
&local_err) != splitkeylen) {
&local_err) < 0) {
error_propagate(errp, local_err);
return -1;
}

View File

@ -115,7 +115,7 @@ QCryptoBlock *qcrypto_block_create(QCryptoBlockCreateOptions *options,
}
static ssize_t qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block,
static int qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block,
size_t headerlen, void *opaque, Error **errp)
{
size_t *headerlenp = opaque;
@ -126,12 +126,12 @@ static ssize_t qcrypto_block_headerlen_hdr_init_func(QCryptoBlock *block,
}
static ssize_t qcrypto_block_headerlen_hdr_write_func(QCryptoBlock *block,
static int qcrypto_block_headerlen_hdr_write_func(QCryptoBlock *block,
size_t offset, const uint8_t *buf, size_t buflen,
void *opaque, Error **errp)
{
/* Discard the bytes, we're not actually writing to an image */
return buflen;
return 0;
}

View File

@ -174,7 +174,7 @@ void allwinner_h3_bootrom_setup(AwH3State *s, BlockBackend *blk)
const int64_t rom_size = 32 * KiB;
g_autofree uint8_t *buffer = g_new0(uint8_t, rom_size);
if (blk_pread(blk, 8 * KiB, buffer, rom_size) < 0) {
if (blk_pread(blk, 8 * KiB, rom_size, buffer, 0) < 0) {
error_setg(&error_fatal, "%s: failed to read BlockBackend data",
__func__);
return;

View File

@ -253,7 +253,7 @@ static void write_boot_rom(DriveInfo *dinfo, hwaddr addr, size_t rom_size,
}
storage = g_malloc0(rom_size);
if (blk_pread(blk, 0, storage, rom_size) < 0) {
if (blk_pread(blk, 0, rom_size, storage, 0) < 0) {
error_setg(errp, "failed to read the initial flash content");
return;
}

View File

@ -53,7 +53,7 @@ bool blk_check_size_and_read_all(BlockBackend *blk, void *buf, hwaddr size,
* block device and read only on demand.
*/
assert(size <= BDRV_REQUEST_MAX_BYTES);
ret = blk_pread(blk, 0, buf, size);
ret = blk_pread(blk, 0, size, buf, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "can't read block backend");
return false;

View File

@ -1628,8 +1628,8 @@ int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_len)
if (fdctrl->data_dir != FD_DIR_WRITE ||
len < FD_SECTOR_LEN || rel_pos != 0) {
/* READ & SCAN commands and realign to a sector for WRITE */
if (blk_pread(cur_drv->blk, fd_offset(cur_drv),
fdctrl->fifo, BDRV_SECTOR_SIZE) < 0) {
if (blk_pread(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE,
fdctrl->fifo, 0) < 0) {
FLOPPY_DPRINTF("Floppy: error getting sector %d\n",
fd_sector(cur_drv));
/* Sure, image size is too small... */
@ -1656,8 +1656,8 @@ int fdctrl_transfer_handler(void *opaque, int nchan, int dma_pos, int dma_len)
k->read_memory(fdctrl->dma, nchan, fdctrl->fifo + rel_pos,
fdctrl->data_pos, len);
if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv),
fdctrl->fifo, BDRV_SECTOR_SIZE, 0) < 0) {
if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE,
fdctrl->fifo, 0) < 0) {
FLOPPY_DPRINTF("error writing sector %d\n",
fd_sector(cur_drv));
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
@ -1740,8 +1740,8 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
fd_sector(cur_drv));
return 0;
}
if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
BDRV_SECTOR_SIZE)
if (blk_pread(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE,
fdctrl->fifo, 0)
< 0) {
FLOPPY_DPRINTF("error getting sector %d\n",
fd_sector(cur_drv));
@ -1820,8 +1820,8 @@ static void fdctrl_format_sector(FDCtrl *fdctrl)
}
memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
if (cur_drv->blk == NULL ||
blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
BDRV_SECTOR_SIZE, 0) < 0) {
blk_pwrite(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE,
fdctrl->fifo, 0) < 0) {
FLOPPY_DPRINTF("error formatting sector %d\n", fd_sector(cur_drv));
fdctrl_stop_transfer(fdctrl, FD_SR0_ABNTERM | FD_SR0_SEEK, 0x00, 0x00);
} else {
@ -2244,8 +2244,8 @@ static void fdctrl_write_data(FDCtrl *fdctrl, uint32_t value)
if (pos == FD_SECTOR_LEN - 1 ||
fdctrl->data_pos == fdctrl->data_len) {
cur_drv = get_cur_drv(fdctrl);
if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
BDRV_SECTOR_SIZE, 0) < 0) {
if (blk_pwrite(cur_drv->blk, fd_offset(cur_drv), BDRV_SECTOR_SIZE,
fdctrl->fifo, 0) < 0) {
FLOPPY_DPRINTF("error writing sector %d\n",
fd_sector(cur_drv));
break;

View File

@ -63,7 +63,7 @@ static int guess_disk_lchs(BlockBackend *blk,
blk_get_geometry(blk, &nb_sectors);
if (blk_pread(blk, 0, buf, BDRV_SECTOR_SIZE) < 0) {
if (blk_pread(blk, 0, BDRV_SECTOR_SIZE, buf, 0) < 0) {
return -1;
}
/* test msdos magic */

View File

@ -1532,7 +1532,7 @@ static void m25p80_realize(SSIPeripheral *ss, Error **errp)
trace_m25p80_binding(s);
s->storage = blk_blockalign(s->blk, s->size);
if (blk_pread(s->blk, 0, s->storage, s->size) != s->size) {
if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
error_setg(errp, "failed to read the initial flash content");
return;
}

View File

@ -666,8 +666,8 @@ static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s)
sector = SECTOR(s->addr);
off = (s->addr & PAGE_MASK) + s->offset;
soff = SECTOR_OFFSET(s->addr);
if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, iobuf,
PAGE_SECTORS << BDRV_SECTOR_BITS) < 0) {
if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS,
PAGE_SECTORS << BDRV_SECTOR_BITS, iobuf, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, sector);
return;
}
@ -679,24 +679,24 @@ static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s)
MIN(OOB_SIZE, off + s->iolen - NAND_PAGE_SIZE));
}
if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS, iobuf,
PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) {
if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS,
PAGE_SECTORS << BDRV_SECTOR_BITS, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", __func__, sector);
}
} else {
off = PAGE_START(s->addr) + (s->addr & PAGE_MASK) + s->offset;
sector = off >> 9;
soff = off & 0x1ff;
if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, iobuf,
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS) < 0) {
if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS,
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, iobuf, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, sector);
return;
}
mem_and(iobuf + soff, s->io, s->iolen);
if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS, iobuf,
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) {
if (blk_pwrite(s->blk, sector << BDRV_SECTOR_BITS,
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", __func__, sector);
}
}
@ -723,20 +723,20 @@ static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s)
i = SECTOR(addr);
page = SECTOR(addr + (1 << (ADDR_SHIFT + s->erase_shift)));
for (; i < page; i ++)
if (blk_pwrite(s->blk, i << BDRV_SECTOR_BITS, iobuf,
BDRV_SECTOR_SIZE, 0) < 0) {
if (blk_pwrite(s->blk, i << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", __func__, i);
}
} else {
addr = PAGE_START(addr);
page = addr >> 9;
if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, iobuf,
BDRV_SECTOR_SIZE) < 0) {
if (blk_pread(s->blk, page << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, page);
}
memset(iobuf + (addr & 0x1ff), 0xff, (~addr & 0x1ff) + 1);
if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS, iobuf,
BDRV_SECTOR_SIZE, 0) < 0) {
if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", __func__, page);
}
@ -744,20 +744,20 @@ static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s)
i = (addr & ~0x1ff) + 0x200;
for (addr += ((NAND_PAGE_SIZE + OOB_SIZE) << s->erase_shift) - 0x200;
i < addr; i += 0x200) {
if (blk_pwrite(s->blk, i, iobuf, BDRV_SECTOR_SIZE, 0) < 0) {
if (blk_pwrite(s->blk, i, BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n",
__func__, i >> 9);
}
}
page = i >> 9;
if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, iobuf,
BDRV_SECTOR_SIZE) < 0) {
if (blk_pread(s->blk, page << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, page);
}
memset(iobuf, 0xff, ((addr - 1) & 0x1ff) + 1);
if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS, iobuf,
BDRV_SECTOR_SIZE, 0) < 0) {
if (blk_pwrite(s->blk, page << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, iobuf, 0) < 0) {
printf("%s: write error in sector %" PRIu64 "\n", __func__, page);
}
}
@ -772,8 +772,8 @@ static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s,
if (s->blk) {
if (s->mem_oob) {
if (blk_pread(s->blk, SECTOR(addr) << BDRV_SECTOR_BITS, s->io,
PAGE_SECTORS << BDRV_SECTOR_BITS) < 0) {
if (blk_pread(s->blk, SECTOR(addr) << BDRV_SECTOR_BITS,
PAGE_SECTORS << BDRV_SECTOR_BITS, s->io, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n",
__func__, SECTOR(addr));
}
@ -782,8 +782,9 @@ static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s,
OOB_SIZE);
s->ioaddr = s->io + SECTOR_OFFSET(s->addr) + offset;
} else {
if (blk_pread(s->blk, PAGE_START(addr), s->io,
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS) < 0) {
if (blk_pread(s->blk, PAGE_START(addr),
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, s->io, 0)
< 0) {
printf("%s: read error in sector %" PRIu64 "\n",
__func__, PAGE_START(addr) >> 9);
}

View File

@ -229,8 +229,8 @@ static void onenand_reset(OneNANDState *s, int cold)
/* Lock the whole flash */
memset(s->blockwp, ONEN_LOCK_LOCKED, s->blocks);
if (s->blk_cur && blk_pread(s->blk_cur, 0, s->boot[0],
8 << BDRV_SECTOR_BITS) < 0) {
if (s->blk_cur && blk_pread(s->blk_cur, 0, 8 << BDRV_SECTOR_BITS,
s->boot[0], 0) < 0) {
hw_error("%s: Loading the BootRAM failed.\n", __func__);
}
}
@ -249,8 +249,8 @@ static inline int onenand_load_main(OneNANDState *s, int sec, int secn,
assert(UINT32_MAX >> BDRV_SECTOR_BITS > sec);
assert(UINT32_MAX >> BDRV_SECTOR_BITS > secn);
if (s->blk_cur) {
return blk_pread(s->blk_cur, sec << BDRV_SECTOR_BITS, dest,
secn << BDRV_SECTOR_BITS) < 0;
return blk_pread(s->blk_cur, sec << BDRV_SECTOR_BITS,
secn << BDRV_SECTOR_BITS, dest, 0) < 0;
} else if (sec + secn > s->secs_cur) {
return 1;
}
@ -274,7 +274,7 @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn,
uint8_t *dp = 0;
if (s->blk_cur) {
dp = g_malloc(size);
if (!dp || blk_pread(s->blk_cur, offset, dp, size) < 0) {
if (!dp || blk_pread(s->blk_cur, offset, size, dp, 0) < 0) {
result = 1;
}
} else {
@ -290,7 +290,7 @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn,
dp[i] &= sp[i];
}
if (s->blk_cur) {
result = blk_pwrite(s->blk_cur, offset, dp, size, 0) < 0;
result = blk_pwrite(s->blk_cur, offset, size, dp, 0) < 0;
}
}
if (dp && s->blk_cur) {
@ -308,7 +308,7 @@ static inline int onenand_load_spare(OneNANDState *s, int sec, int secn,
if (s->blk_cur) {
uint32_t offset = (s->secs_cur + (sec >> 5)) << BDRV_SECTOR_BITS;
if (blk_pread(s->blk_cur, offset, buf, BDRV_SECTOR_SIZE) < 0) {
if (blk_pread(s->blk_cur, offset, BDRV_SECTOR_SIZE, buf, 0) < 0) {
return 1;
}
memcpy(dest, buf + ((sec & 31) << 4), secn << 4);
@ -333,7 +333,7 @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn,
if (s->blk_cur) {
dp = g_malloc(512);
if (!dp
|| blk_pread(s->blk_cur, offset, dp, BDRV_SECTOR_SIZE) < 0) {
|| blk_pread(s->blk_cur, offset, BDRV_SECTOR_SIZE, dp, 0) < 0) {
result = 1;
} else {
dpp = dp + ((sec & 31) << 4);
@ -351,8 +351,8 @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn,
dpp[i] &= sp[i];
}
if (s->blk_cur) {
result = blk_pwrite(s->blk_cur, offset, dp,
BDRV_SECTOR_SIZE, 0) < 0;
result = blk_pwrite(s->blk_cur, offset, BDRV_SECTOR_SIZE, dp,
0) < 0;
}
}
g_free(dp);
@ -370,17 +370,17 @@ static inline int onenand_erase(OneNANDState *s, int sec, int num)
for (; num > 0; num--, sec++) {
if (s->blk_cur) {
int erasesec = s->secs_cur + (sec >> 5);
if (blk_pwrite(s->blk_cur, sec << BDRV_SECTOR_BITS, blankbuf,
BDRV_SECTOR_SIZE, 0) < 0) {
if (blk_pwrite(s->blk_cur, sec << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, blankbuf, 0) < 0) {
goto fail;
}
if (blk_pread(s->blk_cur, erasesec << BDRV_SECTOR_BITS, tmpbuf,
BDRV_SECTOR_SIZE) < 0) {
if (blk_pread(s->blk_cur, erasesec << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, tmpbuf, 0) < 0) {
goto fail;
}
memcpy(tmpbuf + ((sec & 31) << 4), blankbuf, 1 << 4);
if (blk_pwrite(s->blk_cur, erasesec << BDRV_SECTOR_BITS, tmpbuf,
BDRV_SECTOR_SIZE, 0) < 0) {
if (blk_pwrite(s->blk_cur, erasesec << BDRV_SECTOR_BITS,
BDRV_SECTOR_SIZE, tmpbuf, 0) < 0) {
goto fail;
}
} else {

View File

@ -392,8 +392,8 @@ static void pflash_update(PFlashCFI01 *pfl, int offset,
/* widen to sector boundaries */
offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE);
ret = blk_pwrite(pfl->blk, offset, pfl->storage + offset,
offset_end - offset, 0);
ret = blk_pwrite(pfl->blk, offset, offset_end - offset,
pfl->storage + offset, 0);
if (ret < 0) {
/* TODO set error bit in status */
error_report("Could not update PFLASH: %s", strerror(-ret));

View File

@ -400,8 +400,8 @@ static void pflash_update(PFlashCFI02 *pfl, int offset, int size)
/* widen to sector boundaries */
offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE);
ret = blk_pwrite(pfl->blk, offset, pfl->storage + offset,
offset_end - offset, 0);
ret = blk_pwrite(pfl->blk, offset, offset_end - offset,
pfl->storage + offset, 0);
if (ret < 0) {
/* TODO set error bit in status */
error_report("Could not update PFLASH: %s", strerror(-ret));

View File

@ -98,11 +98,11 @@ cd_read_sector_sync(IDEState *s)
switch (s->cd_sector_size) {
case 2048:
ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS,
s->io_buffer, ATAPI_SECTOR_SIZE);
ATAPI_SECTOR_SIZE, s->io_buffer, 0);
break;
case 2352:
ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS,
s->io_buffer + 16, ATAPI_SECTOR_SIZE);
ATAPI_SECTOR_SIZE, s->io_buffer + 16, 0);
if (ret >= 0) {
cd_data_to_raw(s->io_buffer, s->lba);
}

View File

@ -351,7 +351,7 @@ static void via1_one_second(void *opaque)
static void pram_update(MOS6522Q800VIA1State *v1s)
{
if (v1s->blk) {
if (blk_pwrite(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM), 0) < 0) {
if (blk_pwrite(v1s->blk, 0, sizeof(v1s->PRAM), v1s->PRAM, 0) < 0) {
qemu_log("pram_update: cannot write to file\n");
}
}
@ -1029,8 +1029,8 @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
return;
}
len = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM));
if (len != sizeof(v1s->PRAM)) {
ret = blk_pread(v1s->blk, 0, sizeof(v1s->PRAM), v1s->PRAM, 0);
if (ret < 0) {
error_setg(errp, "can't read PRAM contents");
return;
}

View File

@ -64,8 +64,8 @@ static uint64_t sifive_u_otp_read(void *opaque, hwaddr addr, unsigned int size)
if (s->blk) {
int32_t buf;
if (blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, &buf,
SIFIVE_U_OTP_FUSE_WORD) < 0) {
if (blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD,
SIFIVE_U_OTP_FUSE_WORD, &buf, 0) < 0) {
error_report("read error index<%d>", s->pa);
return 0xff;
}
@ -167,8 +167,8 @@ static void sifive_u_otp_write(void *opaque, hwaddr addr,
/* write to backend */
if (s->blk) {
if (blk_pwrite(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD,
&s->fuse[s->pa], SIFIVE_U_OTP_FUSE_WORD,
0) < 0) {
SIFIVE_U_OTP_FUSE_WORD, &s->fuse[s->pa], 0)
< 0) {
error_report("write error index<%d>", s->pa);
}
}
@ -240,7 +240,7 @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
return;
}
if (blk_pread(s->blk, 0, s->fuse, filesize) != filesize) {
if (blk_pread(s->blk, 0, filesize, s->fuse, 0) < 0) {
error_setg(errp, "failed to read the initial flash content");
return;
}
@ -261,14 +261,14 @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
serial_data = s->serial;
if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
&serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
SIFIVE_U_OTP_FUSE_WORD, &serial_data, 0) < 0) {
error_setg(errp, "failed to write index<%d>", index);
return;
}
serial_data = ~(s->serial);
if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
&serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
SIFIVE_U_OTP_FUSE_WORD, &serial_data, 0) < 0) {
error_setg(errp, "failed to write index<%d>", index + 1);
return;
}

View File

@ -64,8 +64,8 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
case I2C_START_RECV:
DPRINTK("clear\n");
if (ee->blk && ee->changed) {
int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0);
if (len != ee->rsize) {
int ret = blk_pwrite(ee->blk, 0, ee->rsize, ee->mem, 0);
if (ret < 0) {
ERR(TYPE_AT24C_EE
" : failed to write backing file\n");
}
@ -165,9 +165,9 @@ void at24c_eeprom_reset(DeviceState *state)
memset(ee->mem, 0, ee->rsize);
if (ee->blk) {
int len = blk_pread(ee->blk, 0, ee->mem, ee->rsize);
int ret = blk_pread(ee->blk, 0, ee->rsize, ee->mem, 0);
if (len != ee->rsize) {
if (ret < 0) {
ERR(TYPE_AT24C_EE
" : Failed initial sync with backing file\n");
}

View File

@ -103,7 +103,7 @@ static void rtas_nvram_store(PowerPCCPU *cpu, SpaprMachineState *spapr,
{
SpaprNvram *nvram = spapr->nvram;
hwaddr offset, buffer, len;
int alen;
int ret;
void *membuf;
if ((nargs != 3) || (nret != 2)) {
@ -128,9 +128,9 @@ static void rtas_nvram_store(PowerPCCPU *cpu, SpaprMachineState *spapr,
membuf = cpu_physical_memory_map(buffer, &len, false);
alen = len;
ret = 0;
if (nvram->blk) {
alen = blk_pwrite(nvram->blk, offset, membuf, len, 0);
ret = blk_pwrite(nvram->blk, offset, len, membuf, 0);
}
assert(nvram->buf);
@ -138,8 +138,8 @@ static void rtas_nvram_store(PowerPCCPU *cpu, SpaprMachineState *spapr,
cpu_physical_memory_unmap(membuf, len, 0, len);
rtas_st(rets, 0, (alen < len) ? RTAS_OUT_HW_ERROR : RTAS_OUT_SUCCESS);
rtas_st(rets, 1, (alen < 0) ? 0 : alen);
rtas_st(rets, 0, (ret < 0) ? RTAS_OUT_HW_ERROR : RTAS_OUT_SUCCESS);
rtas_st(rets, 1, (ret < 0) ? 0 : len);
}
static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp)
@ -179,9 +179,9 @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp)
}
if (nvram->blk) {
int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);
ret = blk_pread(nvram->blk, 0, nvram->size, nvram->buf, 0);
if (alen != nvram->size) {
if (ret < 0) {
error_setg(errp, "can't read spapr-nvram contents");
return;
}
@ -224,7 +224,7 @@ static void postload_update_cb(void *opaque, bool running, RunState state)
qemu_del_vm_change_state_handler(nvram->vmstate);
nvram->vmstate = NULL;
blk_pwrite(nvram->blk, 0, nvram->buf, nvram->size, 0);
blk_pwrite(nvram->blk, 0, nvram->size, nvram->buf, 0);
}
static int spapr_nvram_post_load(void *opaque, int version_id)

View File

@ -124,7 +124,7 @@ static void bbram_bdrv_read(XlnxBBRam *s, Error **errp)
blk_name(s->blk));
}
if (blk_pread(s->blk, 0, ram, nr) < 0) {
if (blk_pread(s->blk, 0, nr, ram, 0) < 0) {
error_setg(errp,
"%s: Failed to read %u bytes from BBRAM backstore.",
blk_name(s->blk), nr);
@ -159,7 +159,7 @@ static void bbram_bdrv_sync(XlnxBBRam *s, uint64_t hwaddr)
}
offset = hwaddr - A_BBRAM_0;
rc = blk_pwrite(s->blk, offset, &le32, 4, 0);
rc = blk_pwrite(s->blk, offset, 4, &le32, 0);
if (rc < 0) {
bbram_bdrv_error(s, rc, g_strdup_printf("write to offset %u", offset));
}

View File

@ -77,7 +77,7 @@ static int efuse_bdrv_read(XlnxEFuse *s, Error **errp)
blk_name(s->blk));
}
if (blk_pread(s->blk, 0, ram, nr) < 0) {
if (blk_pread(s->blk, 0, nr, ram, 0) < 0) {
error_setg(errp, "%s: Failed to read %u bytes from eFUSE backstore.",
blk_name(s->blk), nr);
return -1;
@ -105,7 +105,7 @@ static void efuse_bdrv_sync(XlnxEFuse *s, unsigned int bit)
le32 = cpu_to_le32(xlnx_efuse_get_row(s, bit));
row_offset = (bit / 32) * 4;
if (blk_pwrite(s->blk, row_offset, &le32, 4, 0) < 0) {
if (blk_pwrite(s->blk, row_offset, 4, &le32, 0) < 0) {
error_report("%s: Failed to write offset %u of eFUSE backstore.",
blk_name(s->blk), row_offset);
}

View File

@ -44,8 +44,8 @@ static void pnv_pnor_update(PnvPnor *s, int offset, int size)
offset = QEMU_ALIGN_DOWN(offset, BDRV_SECTOR_SIZE);
offset_end = QEMU_ALIGN_UP(offset_end, BDRV_SECTOR_SIZE);
ret = blk_pwrite(s->blk, offset, s->storage + offset,
offset_end - offset, 0);
ret = blk_pwrite(s->blk, offset, offset_end - offset, s->storage + offset,
0);
if (ret < 0) {
error_report("Could not update PNOR offset=0x%" PRIx32" : %s", offset,
strerror(-ret));
@ -99,7 +99,7 @@ static void pnv_pnor_realize(DeviceState *dev, Error **errp)
s->storage = blk_blockalign(s->blk, s->size);
if (blk_pread(s->blk, 0, s->storage, s->size) != s->size) {
if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
error_setg(errp, "failed to read the initial flash content");
return;
}

View File

@ -752,7 +752,7 @@ void sd_set_cb(SDState *sd, qemu_irq readonly, qemu_irq insert)
static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len)
{
trace_sdcard_read_block(addr, len);
if (!sd->blk || blk_pread(sd->blk, addr, sd->data, len) < 0) {
if (!sd->blk || blk_pread(sd->blk, addr, len, sd->data, 0) < 0) {
fprintf(stderr, "sd_blk_read: read error on host side\n");
}
}
@ -760,7 +760,7 @@ static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len)
static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len)
{
trace_sdcard_write_block(addr, len);
if (!sd->blk || blk_pwrite(sd->blk, addr, sd->data, len, 0) < 0) {
if (!sd->blk || blk_pwrite(sd->blk, addr, len, sd->data, 0) < 0) {
fprintf(stderr, "sd_blk_write: write error on host side\n");
}
}

View File

@ -39,14 +39,22 @@
* to catch when they are accidentally called by the wrong API.
*/
int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
int64_t bytes, BdrvRequestFlags flags);
int generated_co_wrapper bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset,
int64_t bytes,
BdrvRequestFlags flags);
int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags);
int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes);
int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf,
int64_t bytes);
int bdrv_pwrite_sync(BdrvChild *child, int64_t offset,
const void *buf, int64_t bytes);
int generated_co_wrapper bdrv_pread(BdrvChild *child, int64_t offset,
int64_t bytes, void *buf,
BdrvRequestFlags flags);
int generated_co_wrapper bdrv_pwrite(BdrvChild *child, int64_t offset,
int64_t bytes, const void *buf,
BdrvRequestFlags flags);
int generated_co_wrapper bdrv_pwrite_sync(BdrvChild *child, int64_t offset,
int64_t bytes, const void *buf,
BdrvRequestFlags flags);
int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset,
int64_t bytes, const void *buf,
BdrvRequestFlags flags);
/*
* Efficiently zero a region of the disk image. Note that this is a regular
* I/O request like read or write and should have a reasonable size. This

View File

@ -56,7 +56,7 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child,
QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags);
static inline int coroutine_fn bdrv_co_pread(BdrvChild *child,
int64_t offset, unsigned int bytes, void *buf, BdrvRequestFlags flags)
int64_t offset, int64_t bytes, void *buf, BdrvRequestFlags flags)
{
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_CODE();
@ -65,7 +65,7 @@ static inline int coroutine_fn bdrv_co_pread(BdrvChild *child,
}
static inline int coroutine_fn bdrv_co_pwrite(BdrvChild *child,
int64_t offset, unsigned int bytes, void *buf, BdrvRequestFlags flags)
int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags)
{
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_CODE();

View File

@ -29,24 +29,24 @@ typedef struct QCryptoBlock QCryptoBlock;
/* See also QCryptoBlockFormat, QCryptoBlockCreateOptions
* and QCryptoBlockOpenOptions in qapi/crypto.json */
typedef ssize_t (*QCryptoBlockReadFunc)(QCryptoBlock *block,
size_t offset,
uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp);
typedef int (*QCryptoBlockReadFunc)(QCryptoBlock *block,
size_t offset,
uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp);
typedef ssize_t (*QCryptoBlockInitFunc)(QCryptoBlock *block,
size_t headerlen,
void *opaque,
Error **errp);
typedef int (*QCryptoBlockInitFunc)(QCryptoBlock *block,
size_t headerlen,
void *opaque,
Error **errp);
typedef ssize_t (*QCryptoBlockWriteFunc)(QCryptoBlock *block,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp);
typedef int (*QCryptoBlockWriteFunc)(QCryptoBlock *block,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp);
/**
* qcrypto_block_has_format:

View File

@ -101,60 +101,79 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
* the "I/O or GS" API.
*/
int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes);
int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes,
BdrvRequestFlags flags);
int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset,
int64_t bytes, void *buf,
BdrvRequestFlags flags);
int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, int64_t bytes,
void *buf, BdrvRequestFlags flags);
int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov,
BdrvRequestFlags flags);
int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov,
BdrvRequestFlags flags);
int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
int64_t bytes,
QEMUIOVector *qiov, size_t qiov_offset,
int generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov,
size_t qiov_offset,
BdrvRequestFlags flags);
int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov,
size_t qiov_offset, BdrvRequestFlags flags);
int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset,
int64_t bytes, const void *buf,
BdrvRequestFlags flags);
int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes,
const void *buf, BdrvRequestFlags flags);
int generated_co_wrapper blk_pwritev(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov,
BdrvRequestFlags flags);
int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov,
BdrvRequestFlags flags);
static inline int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset,
int64_t bytes, void *buf,
BdrvRequestFlags flags)
{
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_OR_GS_CODE();
int generated_co_wrapper blk_pwritev_part(BlockBackend *blk, int64_t offset,
int64_t bytes, QEMUIOVector *qiov,
size_t qiov_offset,
BdrvRequestFlags flags);
int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
int64_t bytes,
QEMUIOVector *qiov, size_t qiov_offset,
BdrvRequestFlags flags);
assert(bytes <= SIZE_MAX);
int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk,
int64_t offset, int64_t bytes,
const void *buf);
int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset,
int64_t bytes, const void *buf);
return blk_co_preadv(blk, offset, bytes, &qiov, flags);
}
static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset,
int64_t bytes, void *buf,
BdrvRequestFlags flags)
{
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
IO_OR_GS_CODE();
assert(bytes <= SIZE_MAX);
return blk_co_pwritev(blk, offset, bytes, &qiov, flags);
}
int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int64_t bytes,
BdrvRequestFlags flags);
int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int64_t bytes, BdrvRequestFlags flags);
int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset,
int64_t bytes);
int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
int64_t bytes);
int generated_co_wrapper blk_flush(BlockBackend *blk);
int coroutine_fn blk_co_flush(BlockBackend *blk);
int blk_flush(BlockBackend *blk);
int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
int generated_co_wrapper blk_ioctl(BlockBackend *blk, unsigned long int req,
void *buf);
int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req,
void *buf);
int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf,
int64_t bytes);
int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes);
int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int64_t bytes, BdrvRequestFlags flags);
int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset,
int64_t bytes, BdrvRequestFlags flags);
int blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
PreallocMode prealloc, BdrvRequestFlags flags, Error **errp);
int generated_co_wrapper blk_truncate(BlockBackend *blk, int64_t offset,
bool exact, PreallocMode prealloc,
BdrvRequestFlags flags, Error **errp);
int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact,
PreallocMode prealloc, BdrvRequestFlags flags,
Error **errp);
#endif /* BLOCK_BACKEND_IO_H */

View File

@ -568,8 +568,8 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds,
bmds_set_aio_inflight(bmds, sector, nr_sectors, 1);
blk_mig_unlock();
} else {
ret = blk_pread(bmds->blk, sector * BDRV_SECTOR_SIZE, blk->buf,
nr_sectors * BDRV_SECTOR_SIZE);
ret = blk_pread(bmds->blk, sector * BDRV_SECTOR_SIZE,
nr_sectors * BDRV_SECTOR_SIZE, blk->buf, 0);
if (ret < 0) {
goto error;
}
@ -976,8 +976,8 @@ static int block_load(QEMUFile *f, void *opaque, int version_id)
cluster_size,
BDRV_REQ_MAY_UNMAP);
} else {
ret = blk_pwrite(blk, cur_addr, cur_buf,
cluster_size, 0);
ret = blk_pwrite(blk, cur_addr, cluster_size, cur_buf,
0);
}
if (ret < 0) {
break;

View File

@ -2039,8 +2039,8 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client,
stl_be_p(&chunk.length, pnum);
ret = nbd_co_send_iov(client, iov, 1, errp);
} else {
ret = blk_pread(exp->common.blk, offset + progress,
data + progress, pnum);
ret = blk_pread(exp->common.blk, offset + progress, pnum,
data + progress, 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "reading from file failed");
break;
@ -2444,7 +2444,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request,
data, request->len, errp);
}
ret = blk_pread(exp->common.blk, request->from, data, request->len);
ret = blk_pread(exp->common.blk, request->from, request->len, data, 0);
if (ret < 0) {
return nbd_send_generic_reply(client, request->handle, ret,
"reading from file failed", errp);
@ -2511,7 +2511,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
if (request->flags & NBD_CMD_FLAG_FUA) {
flags |= BDRV_REQ_FUA;
}
ret = blk_pwrite(exp->common.blk, request->from, data, request->len,
ret = blk_pwrite(exp->common.blk, request->from, request->len, data,
flags);
return nbd_send_generic_reply(client, request->handle, ret,
"writing to file failed", errp);

View File

@ -1309,7 +1309,7 @@ static int check_empty_sectors(BlockBackend *blk, int64_t offset,
int ret = 0;
int64_t idx;
ret = blk_pread(blk, offset, buffer, bytes);
ret = blk_pread(blk, offset, bytes, buffer, 0);
if (ret < 0) {
error_report("Error while reading offset %" PRId64 " of %s: %s",
offset, filename, strerror(-ret));
@ -1526,7 +1526,7 @@ static int img_compare(int argc, char **argv)
int64_t pnum;
chunk = MIN(chunk, IO_BUF_SIZE);
ret = blk_pread(blk1, offset, buf1, chunk);
ret = blk_pread(blk1, offset, chunk, buf1, 0);
if (ret < 0) {
error_report("Error while reading offset %" PRId64
" of %s: %s",
@ -1534,7 +1534,7 @@ static int img_compare(int argc, char **argv)
ret = 4;
goto out;
}
ret = blk_pread(blk2, offset, buf2, chunk);
ret = blk_pread(blk2, offset, chunk, buf2, 0);
if (ret < 0) {
error_report("Error while reading offset %" PRId64
" of %s: %s",
@ -2114,7 +2114,7 @@ static int convert_do_copy(ImgConvertState *s)
if (s->compressed && !s->ret) {
/* signal EOF to align */
ret = blk_pwrite_compressed(s->target, 0, NULL, 0);
ret = blk_pwrite_compressed(s->target, 0, 0, NULL);
if (ret < 0) {
return ret;
}
@ -3779,7 +3779,7 @@ static int img_rebase(int argc, char **argv)
n = old_backing_size - offset;
}
ret = blk_pread(blk_old_backing, offset, buf_old, n);
ret = blk_pread(blk_old_backing, offset, n, buf_old, 0);
if (ret < 0) {
error_report("error while reading from old backing file");
goto out;
@ -3793,7 +3793,7 @@ static int img_rebase(int argc, char **argv)
n = new_backing_size - offset;
}
ret = blk_pread(blk_new_backing, offset, buf_new, n);
ret = blk_pread(blk_new_backing, offset, n, buf_new, 0);
if (ret < 0) {
error_report("error while reading from new backing file");
goto out;
@ -3812,8 +3812,8 @@ static int img_rebase(int argc, char **argv)
if (buf_old_is_zero) {
ret = blk_pwrite_zeroes(blk, offset + written, pnum, 0);
} else {
ret = blk_pwrite(blk, offset + written,
buf_old + written, pnum, 0);
ret = blk_pwrite(blk, offset + written, pnum,
buf_old + written, 0);
}
if (ret < 0) {
error_report("Error while writing to COW image: %s",
@ -5120,30 +5120,23 @@ static int img_dd(int argc, char **argv)
in.buf = g_new(uint8_t, in.bsz);
for (out_pos = 0; in_pos < size; block_count++) {
int in_ret, out_ret;
int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
if (in_pos + in.bsz > size) {
in_ret = blk_pread(blk1, in_pos, in.buf, size - in_pos);
} else {
in_ret = blk_pread(blk1, in_pos, in.buf, in.bsz);
}
if (in_ret < 0) {
ret = blk_pread(blk1, in_pos, bytes, in.buf, 0);
if (ret < 0) {
error_report("error while reading from input image file: %s",
strerror(-in_ret));
ret = -1;
strerror(-ret));
goto out;
}
in_pos += in_ret;
in_pos += bytes;
out_ret = blk_pwrite(blk2, out_pos, in.buf, in_ret, 0);
if (out_ret < 0) {
ret = blk_pwrite(blk2, out_pos, bytes, in.buf, 0);
if (ret < 0) {
error_report("error while writing to output image file: %s",
strerror(-out_ret));
ret = -1;
strerror(-ret));
goto out;
}
out_pos += out_ret;
out_pos += bytes;
}
out:

View File

@ -541,28 +541,34 @@ fail:
static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
int64_t bytes, int64_t *total)
{
int ret;
if (bytes > INT_MAX) {
return -ERANGE;
}
*total = blk_pread(blk, offset, (uint8_t *)buf, bytes);
if (*total < 0) {
return *total;
ret = blk_pread(blk, offset, bytes, (uint8_t *)buf, 0);
if (ret < 0) {
return ret;
}
*total = bytes;
return 1;
}
static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset,
int64_t bytes, int flags, int64_t *total)
{
int ret;
if (bytes > INT_MAX) {
return -ERANGE;
}
*total = blk_pwrite(blk, offset, (uint8_t *)buf, bytes, flags);
if (*total < 0) {
return *total;
ret = blk_pwrite(blk, offset, bytes, (uint8_t *)buf, flags);
if (ret < 0) {
return ret;
}
*total = bytes;
return 1;
}
@ -625,7 +631,7 @@ static int do_write_compressed(BlockBackend *blk, char *buf, int64_t offset,
return -ERANGE;
}
ret = blk_pwrite_compressed(blk, offset, buf, bytes);
ret = blk_pwrite_compressed(blk, offset, bytes, buf);
if (ret < 0) {
return ret;
}

View File

@ -1522,13 +1522,18 @@ machine_parse_property_opt(QemuOptsList *opts_list, const char *propname,
}
static const char *pid_file;
static Notifier qemu_unlink_pidfile_notifier;
struct UnlinkPidfileNotifier {
Notifier notifier;
char *pid_file_realpath;
};
static struct UnlinkPidfileNotifier qemu_unlink_pidfile_notifier;
static void qemu_unlink_pidfile(Notifier *n, void *data)
{
if (pid_file) {
unlink(pid_file);
}
struct UnlinkPidfileNotifier *upn;
upn = DO_UPCAST(struct UnlinkPidfileNotifier, notifier, n);
unlink(upn->pid_file_realpath);
}
static const QEMUOption *lookup_opt(int argc, char **argv,
@ -2431,13 +2436,30 @@ static void qemu_maybe_daemonize(const char *pid_file)
os_daemonize();
rcu_disable_atfork();
if (pid_file && !qemu_write_pidfile(pid_file, &err)) {
error_reportf_err(err, "cannot create PID file: ");
exit(1);
}
if (pid_file) {
char *pid_file_realpath = NULL;
qemu_unlink_pidfile_notifier.notify = qemu_unlink_pidfile;
qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier);
if (!qemu_write_pidfile(pid_file, &err)) {
error_reportf_err(err, "cannot create PID file: ");
exit(1);
}
pid_file_realpath = g_malloc0(PATH_MAX);
if (!realpath(pid_file, pid_file_realpath)) {
error_report("cannot resolve PID file path: %s: %s",
pid_file, strerror(errno));
unlink(pid_file);
exit(1);
}
qemu_unlink_pidfile_notifier = (struct UnlinkPidfileNotifier) {
.notifier = {
.notify = qemu_unlink_pidfile,
},
.pid_file_realpath = pid_file_realpath,
};
qemu_add_exit_notifier(&qemu_unlink_pidfile_notifier.notifier);
}
}
static void qemu_init_displays(void)

View File

@ -61,6 +61,7 @@
#include "trace/control.h"
static const char *pid_file;
static char *pid_file_realpath;
static volatile bool exit_requested = false;
void qemu_system_killed(int signal, pid_t pid)
@ -296,7 +297,11 @@ static void process_options(int argc, char *argv[], bool pre_init_pass)
}
case OPTION_DAEMONIZE:
if (os_set_daemonize(true) < 0) {
error_report("--daemonize not supported in this build");
/*
* --daemonize is parsed before monitor_init_globals_core(), so
* error_report() does not work yet
*/
fprintf(stderr, "--daemonize not supported in this build\n");
exit(EXIT_FAILURE);
}
break;
@ -359,7 +364,7 @@ static void process_options(int argc, char *argv[], bool pre_init_pass)
static void pid_file_cleanup(void)
{
unlink(pid_file);
unlink(pid_file_realpath);
}
static void pid_file_init(void)
@ -375,6 +380,14 @@ static void pid_file_init(void)
exit(EXIT_FAILURE);
}
pid_file_realpath = g_malloc(PATH_MAX);
if (!realpath(pid_file, pid_file_realpath)) {
error_report("cannot resolve PID file path: %s: %s",
pid_file, strerror(errno));
unlink(pid_file);
exit(EXIT_FAILURE);
}
atexit(pid_file_cleanup);
}

View File

@ -60,6 +60,11 @@ if sudo -n losetup &>/dev/null; then
else
loopdev=false
# Check for usable FUSE in the host environment:
if test ! -c "/dev/fuse"; then
_notrun 'No passwordless sudo nor usable /dev/fuse'
fi
# QSD --export fuse will either yield "Parameter 'id' is missing"
# or "Invalid parameter 'fuse'", depending on whether there is
# FUSE support or not.

View File

@ -93,7 +93,7 @@ exports available: 3
export: 'n2'
description: some text
size: 4194304
flags: 0xced ( flush fua trim zeroes df cache fast-zero )
flags: 0xded ( flush fua trim zeroes df multi cache fast-zero )
min block: 1
opt block: 4096
max block: 33554432
@ -212,7 +212,7 @@ exports available: 3
export: 'n2'
description: some text
size: 4194304
flags: 0xced ( flush fua trim zeroes df cache fast-zero )
flags: 0xded ( flush fua trim zeroes df multi cache fast-zero )
min block: 1
opt block: 4096
max block: 33554432

View File

@ -83,7 +83,7 @@ exports available: 2
export: 'export1'
description: This is the writable second export
size: 67108864
flags: 0xced ( flush fua trim zeroes df cache fast-zero )
flags: 0xded ( flush fua trim zeroes df multi cache fast-zero )
min block: XXX
opt block: XXX
max block: XXX
@ -109,7 +109,7 @@ exports available: 1
export: 'export1'
description: This is the writable second export
size: 67108864
flags: 0xced ( flush fua trim zeroes df cache fast-zero )
flags: 0xded ( flush fua trim zeroes df multi cache fast-zero )
min block: XXX
opt block: XXX
max block: XXX

View File

@ -9,4 +9,4 @@ no_implicit_optional = True
scripts_are_modules = True
warn_redundant_casts = True
warn_unused_configs = True
warn_unused_ignores = True
warn_unused_ignores = False

View File

@ -88,11 +88,11 @@ static void test_sync_op_pread(BdrvChild *c)
int ret;
/* Success */
ret = bdrv_pread(c, 0, buf, sizeof(buf));
g_assert_cmpint(ret, ==, 512);
ret = bdrv_pread(c, 0, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = bdrv_pread(c, -2, buf, sizeof(buf));
ret = bdrv_pread(c, -2, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, -EIO);
}
@ -102,11 +102,11 @@ static void test_sync_op_pwrite(BdrvChild *c)
int ret;
/* Success */
ret = bdrv_pwrite(c, 0, buf, sizeof(buf));
g_assert_cmpint(ret, ==, 512);
ret = bdrv_pwrite(c, 0, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = bdrv_pwrite(c, -2, buf, sizeof(buf));
ret = bdrv_pwrite(c, -2, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, -EIO);
}
@ -116,11 +116,11 @@ static void test_sync_op_blk_pread(BlockBackend *blk)
int ret;
/* Success */
ret = blk_pread(blk, 0, buf, sizeof(buf));
g_assert_cmpint(ret, ==, 512);
ret = blk_pread(blk, 0, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = blk_pread(blk, -2, buf, sizeof(buf));
ret = blk_pread(blk, -2, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, -EIO);
}
@ -130,11 +130,98 @@ static void test_sync_op_blk_pwrite(BlockBackend *blk)
int ret;
/* Success */
ret = blk_pwrite(blk, 0, buf, sizeof(buf), 0);
g_assert_cmpint(ret, ==, 512);
ret = blk_pwrite(blk, 0, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = blk_pwrite(blk, -2, buf, sizeof(buf), 0);
ret = blk_pwrite(blk, -2, sizeof(buf), buf, 0);
g_assert_cmpint(ret, ==, -EIO);
}
static void test_sync_op_blk_preadv(BlockBackend *blk)
{
uint8_t buf[512];
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, sizeof(buf));
int ret;
/* Success */
ret = blk_preadv(blk, 0, sizeof(buf), &qiov, 0);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = blk_preadv(blk, -2, sizeof(buf), &qiov, 0);
g_assert_cmpint(ret, ==, -EIO);
}
static void test_sync_op_blk_pwritev(BlockBackend *blk)
{
uint8_t buf[512] = { 0 };
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, sizeof(buf));
int ret;
/* Success */
ret = blk_pwritev(blk, 0, sizeof(buf), &qiov, 0);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = blk_pwritev(blk, -2, sizeof(buf), &qiov, 0);
g_assert_cmpint(ret, ==, -EIO);
}
static void test_sync_op_blk_preadv_part(BlockBackend *blk)
{
uint8_t buf[512];
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, sizeof(buf));
int ret;
/* Success */
ret = blk_preadv_part(blk, 0, sizeof(buf), &qiov, 0, 0);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = blk_preadv_part(blk, -2, sizeof(buf), &qiov, 0, 0);
g_assert_cmpint(ret, ==, -EIO);
}
static void test_sync_op_blk_pwritev_part(BlockBackend *blk)
{
uint8_t buf[512] = { 0 };
QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, sizeof(buf));
int ret;
/* Success */
ret = blk_pwritev_part(blk, 0, sizeof(buf), &qiov, 0, 0);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = blk_pwritev_part(blk, -2, sizeof(buf), &qiov, 0, 0);
g_assert_cmpint(ret, ==, -EIO);
}
static void test_sync_op_blk_pwrite_compressed(BlockBackend *blk)
{
uint8_t buf[512] = { 0 };
int ret;
/* Late error: Not supported */
ret = blk_pwrite_compressed(blk, 0, sizeof(buf), buf);
g_assert_cmpint(ret, ==, -ENOTSUP);
/* Early error: Negative offset */
ret = blk_pwrite_compressed(blk, -2, sizeof(buf), buf);
g_assert_cmpint(ret, ==, -EIO);
}
static void test_sync_op_blk_pwrite_zeroes(BlockBackend *blk)
{
int ret;
/* Success */
ret = blk_pwrite_zeroes(blk, 0, 512, 0);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = blk_pwrite_zeroes(blk, -2, 512, 0);
g_assert_cmpint(ret, ==, -EIO);
}
@ -211,6 +298,19 @@ static void test_sync_op_truncate(BdrvChild *c)
c->bs->open_flags |= BDRV_O_RDWR;
}
static void test_sync_op_blk_truncate(BlockBackend *blk)
{
int ret;
/* Normal success path */
ret = blk_truncate(blk, 65536, false, PREALLOC_MODE_OFF, 0, NULL);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = blk_truncate(blk, -2, false, PREALLOC_MODE_OFF, 0, NULL);
g_assert_cmpint(ret, ==, -EINVAL);
}
static void test_sync_op_block_status(BdrvChild *c)
{
int ret;
@ -301,6 +401,30 @@ const SyncOpTest sync_op_tests[] = {
.name = "/sync-op/pwrite",
.fn = test_sync_op_pwrite,
.blkfn = test_sync_op_blk_pwrite,
}, {
.name = "/sync-op/preadv",
.fn = NULL,
.blkfn = test_sync_op_blk_preadv,
}, {
.name = "/sync-op/pwritev",
.fn = NULL,
.blkfn = test_sync_op_blk_pwritev,
}, {
.name = "/sync-op/preadv_part",
.fn = NULL,
.blkfn = test_sync_op_blk_preadv_part,
}, {
.name = "/sync-op/pwritev_part",
.fn = NULL,
.blkfn = test_sync_op_blk_pwritev_part,
}, {
.name = "/sync-op/pwrite_compressed",
.fn = NULL,
.blkfn = test_sync_op_blk_pwrite_compressed,
}, {
.name = "/sync-op/pwrite_zeroes",
.fn = NULL,
.blkfn = test_sync_op_blk_pwrite_zeroes,
}, {
.name = "/sync-op/load_vmstate",
.fn = test_sync_op_load_vmstate,
@ -314,6 +438,7 @@ const SyncOpTest sync_op_tests[] = {
}, {
.name = "/sync-op/truncate",
.fn = test_sync_op_truncate,
.blkfn = test_sync_op_blk_truncate,
}, {
.name = "/sync-op/block_status",
.fn = test_sync_op_block_status,
@ -349,7 +474,9 @@ static void test_sync_op(const void *opaque)
blk_set_aio_context(blk, ctx, &error_abort);
aio_context_acquire(ctx);
t->fn(c);
if (t->fn) {
t->fn(c);
}
if (t->blkfn) {
t->blkfn(blk);
}

View File

@ -188,12 +188,12 @@ static struct QCryptoBlockTestData {
};
static ssize_t test_block_read_func(QCryptoBlock *block,
size_t offset,
uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
static int test_block_read_func(QCryptoBlock *block,
size_t offset,
uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
{
Buffer *header = opaque;
@ -201,14 +201,14 @@ static ssize_t test_block_read_func(QCryptoBlock *block,
memcpy(buf, header->buffer + offset, buflen);
return buflen;
return 0;
}
static ssize_t test_block_init_func(QCryptoBlock *block,
size_t headerlen,
void *opaque,
Error **errp)
static int test_block_init_func(QCryptoBlock *block,
size_t headerlen,
void *opaque,
Error **errp)
{
Buffer *header = opaque;
@ -216,16 +216,16 @@ static ssize_t test_block_init_func(QCryptoBlock *block,
buffer_reserve(header, headerlen);
return headerlen;
return 0;
}
static ssize_t test_block_write_func(QCryptoBlock *block,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
static int test_block_write_func(QCryptoBlock *block,
size_t offset,
const uint8_t *buf,
size_t buflen,
void *opaque,
Error **errp)
{
Buffer *header = opaque;
@ -234,7 +234,7 @@ static ssize_t test_block_write_func(QCryptoBlock *block,
memcpy(header->buffer + offset, buf, buflen);
header->offset = offset + buflen;
return buflen;
return 0;
}