block: Add a 'flags' param to blk_pread()

For consistency with other I/O functions, and in preparation to
implement it using generated_co_wrapper.

Callers were updated using this Coccinelle script:

    @@ expression blk, offset, buf, bytes; @@
    - blk_pread(blk, offset, buf, bytes)
    + blk_pread(blk, offset, buf, bytes, 0)

It had no effect on hw/block/nand.c, presumably due to the #if, so that
file was updated manually.

Overly-long lines were then fixed by hand.

Signed-off-by: Alberto Faria <afaria@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Greg Kurz <groug@kaod.org>
Reviewed-by: Hanna Reitz <hreitz@redhat.com>
Message-Id: <20220705161527.1054072-3-afaria@redhat.com>
Signed-off-by: Hanna Reitz <hreitz@redhat.com>
This commit is contained in:
Alberto Faria 2022-07-05 17:15:10 +01:00 committed by Hanna Reitz
parent bf5b16fa40
commit 3b35d4542c
27 changed files with 52 additions and 50 deletions

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, buf, sizeof(buf), 0);
if (ret < 0) {
error_setg_errno(errp, -ret, "Could not read image for determining its "
"format");

View File

@ -1563,14 +1563,15 @@ 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 blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes,
BdrvRequestFlags flags)
{
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);
ret = blk_do_preadv(blk, offset, bytes, &qiov, flags);
blk_dec_in_flight(blk);
return ret;

View File

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

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, buf, size, 0);
if (ret >= 0) {
fuse_reply_buf(req, buf, size);
} else {

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, buffer, rom_size, 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, storage, rom_size, 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, buf, size, 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), fdctrl->fifo,
BDRV_SECTOR_SIZE, 0) < 0) {
FLOPPY_DPRINTF("Floppy: error getting sector %d\n",
fd_sector(cur_drv));
/* Sure, image size is too small... */
@ -1741,7 +1741,7 @@ static uint32_t fdctrl_read_data(FDCtrl *fdctrl)
return 0;
}
if (blk_pread(cur_drv->blk, fd_offset(cur_drv), fdctrl->fifo,
BDRV_SECTOR_SIZE)
BDRV_SECTOR_SIZE, 0)
< 0) {
FLOPPY_DPRINTF("error getting sector %d\n",
fd_sector(cur_drv));

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, buf, BDRV_SECTOR_SIZE, 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) < 0) {
if (blk_pread(s->blk, 0, s->storage, s->size, 0) < 0) {
error_setg(errp, "failed to read the initial flash content");
return;
}

View File

@ -667,7 +667,7 @@ static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s)
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) {
PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, sector);
return;
}
@ -688,7 +688,7 @@ static void glue(nand_blk_write_, NAND_PAGE_SIZE)(NANDFlashState *s)
sector = off >> 9;
soff = off & 0x1ff;
if (blk_pread(s->blk, sector << BDRV_SECTOR_BITS, iobuf,
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS) < 0) {
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, sector);
return;
}
@ -731,7 +731,7 @@ static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s)
addr = PAGE_START(addr);
page = addr >> 9;
if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, iobuf,
BDRV_SECTOR_SIZE) < 0) {
BDRV_SECTOR_SIZE, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, page);
}
memset(iobuf + (addr & 0x1ff), 0xff, (~addr & 0x1ff) + 1);
@ -752,7 +752,7 @@ static void glue(nand_blk_erase_, NAND_PAGE_SIZE)(NANDFlashState *s)
page = i >> 9;
if (blk_pread(s->blk, page << BDRV_SECTOR_BITS, iobuf,
BDRV_SECTOR_SIZE) < 0) {
BDRV_SECTOR_SIZE, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n", __func__, page);
}
memset(iobuf, 0xff, ((addr - 1) & 0x1ff) + 1);
@ -773,7 +773,7 @@ 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) {
PAGE_SECTORS << BDRV_SECTOR_BITS, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n",
__func__, SECTOR(addr));
}
@ -783,7 +783,7 @@ static void glue(nand_blk_load_, NAND_PAGE_SIZE)(NANDFlashState *s,
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) {
(PAGE_SECTORS + 2) << BDRV_SECTOR_BITS, 0) < 0) {
printf("%s: read error in sector %" PRIu64 "\n",
__func__, PAGE_START(addr) >> 9);
}

View File

@ -230,7 +230,7 @@ static void onenand_reset(OneNANDState *s, int cold)
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) {
8 << BDRV_SECTOR_BITS, 0) < 0) {
hw_error("%s: Loading the BootRAM failed.\n", __func__);
}
}
@ -250,7 +250,7 @@ static inline int onenand_load_main(OneNANDState *s, int sec, int secn,
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;
secn << BDRV_SECTOR_BITS, 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, dp, size, 0) < 0) {
result = 1;
}
} else {
@ -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, buf, BDRV_SECTOR_SIZE, 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, dp, BDRV_SECTOR_SIZE, 0) < 0) {
result = 1;
} else {
dpp = dp + ((sec & 31) << 4);
@ -375,7 +375,7 @@ static inline int onenand_erase(OneNANDState *s, int sec, int num)
goto fail;
}
if (blk_pread(s->blk_cur, erasesec << BDRV_SECTOR_BITS, tmpbuf,
BDRV_SECTOR_SIZE) < 0) {
BDRV_SECTOR_SIZE, 0) < 0) {
goto fail;
}
memcpy(tmpbuf + ((sec & 31) << 4), blankbuf, 1 << 4);

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);
s->io_buffer, ATAPI_SECTOR_SIZE, 0);
break;
case 2352:
ret = blk_pread(s->blk, (int64_t)s->lba << ATAPI_SECTOR_BITS,
s->io_buffer + 16, ATAPI_SECTOR_SIZE);
s->io_buffer + 16, ATAPI_SECTOR_SIZE, 0);
if (ret >= 0) {
cd_data_to_raw(s->io_buffer, s->lba);
}

View File

@ -1029,7 +1029,7 @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
return;
}
ret = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM));
ret = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM), 0);
if (ret < 0) {
error_setg(errp, "can't read PRAM contents");
return;

View File

@ -65,7 +65,7 @@ static uint64_t sifive_u_otp_read(void *opaque, hwaddr addr, unsigned int size)
int32_t buf;
if (blk_pread(s->blk, s->pa * SIFIVE_U_OTP_FUSE_WORD, &buf,
SIFIVE_U_OTP_FUSE_WORD) < 0) {
SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
error_report("read error index<%d>", s->pa);
return 0xff;
}
@ -240,7 +240,7 @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
return;
}
if (blk_pread(s->blk, 0, s->fuse, filesize) < 0) {
if (blk_pread(s->blk, 0, s->fuse, filesize, 0) < 0) {
error_setg(errp, "failed to read the initial flash content");
return;
}

View File

@ -165,7 +165,7 @@ void at24c_eeprom_reset(DeviceState *state)
memset(ee->mem, 0, ee->rsize);
if (ee->blk) {
int ret = blk_pread(ee->blk, 0, ee->mem, ee->rsize);
int ret = blk_pread(ee->blk, 0, ee->mem, ee->rsize, 0);
if (ret < 0) {
ERR(TYPE_AT24C_EE

View File

@ -179,7 +179,7 @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp)
}
if (nvram->blk) {
ret = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);
ret = blk_pread(nvram->blk, 0, nvram->buf, nvram->size, 0);
if (ret < 0) {
error_setg(errp, "can't read spapr-nvram contents");

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, ram, nr, 0) < 0) {
error_setg(errp,
"%s: Failed to read %u bytes from BBRAM backstore.",
blk_name(s->blk), nr);

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, ram, nr, 0) < 0) {
error_setg(errp, "%s: Failed to read %u bytes from eFUSE backstore.",
blk_name(s->blk), nr);
return -1;

View File

@ -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) < 0) {
if (blk_pread(s->blk, 0, s->storage, s->size, 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, sd->data, len, 0) < 0) {
fprintf(stderr, "sd_blk_read: read error on host side\n");
}
}

View File

@ -101,7 +101,8 @@ 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_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes,
BdrvRequestFlags flags);
int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes,
BdrvRequestFlags flags);
int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,

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,
blk->buf, nr_sectors * BDRV_SECTOR_SIZE, 0);
if (ret < 0) {
goto error;
}

View File

@ -2040,7 +2040,7 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client,
ret = nbd_co_send_iov(client, iov, 1, errp);
} else {
ret = blk_pread(exp->common.blk, offset + progress,
data + progress, pnum);
data + progress, pnum, 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, data, request->len, 0);
if (ret < 0) {
return nbd_send_generic_reply(client, request->handle, ret,
"reading from 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, buffer, bytes, 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, buf1, chunk, 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, buf2, chunk, 0);
if (ret < 0) {
error_report("Error while reading offset %" PRId64
" of %s: %s",
@ -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, buf_old, n, 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, buf_new, n, 0);
if (ret < 0) {
error_report("error while reading from new backing file");
goto out;
@ -5122,7 +5122,7 @@ static int img_dd(int argc, char **argv)
for (out_pos = 0; in_pos < size; block_count++) {
int bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
ret = blk_pread(blk1, in_pos, in.buf, bytes);
ret = blk_pread(blk1, in_pos, in.buf, bytes, 0);
if (ret < 0) {
error_report("error while reading from input image file: %s",
strerror(-ret));

View File

@ -547,7 +547,7 @@ static int do_pread(BlockBackend *blk, char *buf, int64_t offset,
return -ERANGE;
}
ret = blk_pread(blk, offset, (uint8_t *)buf, bytes);
ret = blk_pread(blk, offset, (uint8_t *)buf, bytes, 0);
if (ret < 0) {
return ret;
}

View File

@ -116,11 +116,11 @@ static void test_sync_op_blk_pread(BlockBackend *blk)
int ret;
/* Success */
ret = blk_pread(blk, 0, buf, sizeof(buf));
ret = blk_pread(blk, 0, buf, sizeof(buf), 0);
g_assert_cmpint(ret, ==, 0);
/* Early error: Negative offset */
ret = blk_pread(blk, -2, buf, sizeof(buf));
ret = blk_pread(blk, -2, buf, sizeof(buf), 0);
g_assert_cmpint(ret, ==, -EIO);
}