All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/18] Make block-backend-io.h API more consistent
@ 2022-05-17 11:35 Alberto Faria
  2022-05-17 11:35 ` [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success Alberto Faria
                   ` (18 more replies)
  0 siblings, 19 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Andrew Jeffery, Peter Maydell, qemu-block, Palmer Dabbelt,
	Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, Hanna Reitz,
	John Snow, Stefan Hajnoczi, Jeff Cody, qemu-riscv,
	Cédric Le Goater, Joel Stanley, Stefan Weil, Laurent Vivier,
	Denis V. Lunev, Juan Quintela, Dr. David Alan Gilbert,
	Niek Linnenbank, Greg Kurz, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson, Alberto Faria

Adjust existing pairs of non-coroutine and coroutine functions to share
the same calling convention, and add non-coroutine/coroutine
counterparts where they don't exist.

Also make the non-coroutine versions generated_co_wrappers.

This series sits on top of "[PATCH v2 00/10] Implement bdrv_{pread,
pwrite, pwrite_sync, pwrite_zeroes}() using generated_co_wrapper":

    https://lore.kernel.org/qemu-devel/20220513155418.2486450-1-afaria@redhat.com/

Based-on: <20220513155418.2486450-1-afaria@redhat.com>

Alberto Faria (18):
  block: Make blk_{pread,pwrite}() return 0 on success
  block: Add a 'flags' param to blk_pread()
  block: Change blk_{pread,pwrite}() param order
  block: Make 'bytes' param of blk_{pread,pwrite}() an int64_t
  block: Make blk_co_pwrite() take a const buffer
  block: Implement blk_{pread,pwrite}() using generated_co_wrapper
  block: Add blk_{preadv,pwritev}()
  block: Add blk_[co_]preadv_part()
  block: Export blk_pwritev_part() in block-backend-io.h
  block: Change blk_pwrite_compressed() param order
  block: Add blk_co_pwrite_compressed()
  block: Implement blk_pwrite_zeroes() using generated_co_wrapper
  block: Implement blk_pdiscard() using generated_co_wrapper
  block: Implement blk_flush() using generated_co_wrapper
  block: Add blk_co_ioctl()
  block: Add blk_co_truncate()
  block: Reorganize some declarations in block-backend-io.h
  block: Remove remaining unused symbols in coroutines.h

 block.c                           |  10 +-
 block/block-backend.c             | 150 ++++++++++++------------------
 block/commit.c                    |   4 +-
 block/coroutines.h                |  44 ---------
 block/crypto.c                    |   2 +-
 block/export/fuse.c               |   4 +-
 block/meson.build                 |   1 +
 block/parallels.c                 |   2 +-
 block/qcow.c                      |  14 +--
 block/qcow2.c                     |   4 +-
 block/qed.c                       |   8 +-
 block/vdi.c                       |   4 +-
 block/vhdx.c                      |  20 ++--
 block/vmdk.c                      |  10 +-
 block/vpc.c                       |  12 +--
 hw/arm/allwinner-h3.c             |   2 +-
 hw/arm/aspeed.c                   |   2 +-
 hw/block/block.c                  |   2 +-
 hw/block/fdc.c                    |  20 ++--
 hw/block/hd-geometry.c            |   2 +-
 hw/block/m25p80.c                 |   2 +-
 hw/block/nand.c                   |  47 +++++-----
 hw/block/onenand.c                |  32 +++----
 hw/block/pflash_cfi01.c           |   4 +-
 hw/block/pflash_cfi02.c           |   4 +-
 hw/ide/atapi.c                    |   4 +-
 hw/misc/mac_via.c                 |   6 +-
 hw/misc/sifive_u_otp.c            |  14 +--
 hw/nvram/eeprom_at24c.c           |   8 +-
 hw/nvram/spapr_nvram.c            |  16 ++--
 hw/nvram/xlnx-bbram.c             |   4 +-
 hw/nvram/xlnx-efuse.c             |   4 +-
 hw/ppc/pnv_pnor.c                 |   6 +-
 hw/sd/sd.c                        |   4 +-
 include/sysemu/block-backend-io.h | 105 ++++++++++++---------
 migration/block.c                 |   8 +-
 nbd/server.c                      |   8 +-
 qemu-img.c                        |  33 +++----
 qemu-io-cmds.c                    |  20 ++--
 tests/unit/test-block-iothread.c  | 141 ++++++++++++++++++++++++++--
 40 files changed, 433 insertions(+), 354 deletions(-)

-- 
2.35.3



^ permalink raw reply	[flat|nested] 64+ messages in thread

* [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
@ 2022-05-17 11:35 ` Alberto Faria
  2022-05-17 14:03   ` Greg Kurz
                     ` (2 more replies)
  2022-05-17 11:35 ` [PATCH 02/18] block: Add a 'flags' param to blk_pread() Alberto Faria
                   ` (17 subsequent siblings)
  18 siblings, 3 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Andrew Jeffery, Peter Maydell, qemu-block, Palmer Dabbelt,
	Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, Hanna Reitz,
	John Snow, Stefan Hajnoczi, Jeff Cody, qemu-riscv,
	Cédric Le Goater, Joel Stanley, Stefan Weil, Laurent Vivier,
	Denis V. Lunev, Juan Quintela, Dr. David Alan Gilbert,
	Niek Linnenbank, Greg Kurz, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson, Alberto Faria

They currently return the value of their 'bytes' parameter on success.

Make them return 0 instead, for consistency with other I/O functions and
in preparation to implement them using generated_co_wrapper. This also
makes it clear that short reads/writes are not possible.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block.c                          |  8 +++++---
 block/block-backend.c            |  7 ++-----
 block/qcow.c                     |  6 +++---
 hw/block/m25p80.c                |  2 +-
 hw/misc/mac_via.c                |  2 +-
 hw/misc/sifive_u_otp.c           |  2 +-
 hw/nvram/eeprom_at24c.c          |  4 ++--
 hw/nvram/spapr_nvram.c           | 12 ++++++------
 hw/ppc/pnv_pnor.c                |  2 +-
 qemu-img.c                       | 17 +++++++----------
 qemu-io-cmds.c                   | 18 ++++++++++++------
 tests/unit/test-block-iothread.c |  4 ++--
 12 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/block.c b/block.c
index 2c00dddd80..0fd830e2e2 100644
--- a/block.c
+++ b/block.c
@@ -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;
 }
 
 /**
diff --git a/block/block-backend.c b/block/block-backend.c
index e0e1aff4b1..c1c367bf9e 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1577,19 +1577,16 @@ int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes)
     ret = blk_do_preadv(blk, offset, bytes, &qiov, 0);
     blk_dec_in_flight(blk);
 
-    return ret < 0 ? ret : bytes;
+    return ret;
 }
 
 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;
+    return blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags);
 }
 
 int64_t blk_getlength(BlockBackend *blk)
diff --git a/block/qcow.c b/block/qcow.c
index c646d6b16d..25a43353c1 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -891,14 +891,14 @@ 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)) {
+    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) {
+        if (ret < 0) {
             goto exit;
         }
     }
@@ -908,7 +908,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
          i++) {
         ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
                          tmp, BDRV_SECTOR_SIZE, 0);
-        if (ret != BDRV_SECTOR_SIZE) {
+        if (ret < 0) {
             g_free(tmp);
             goto exit;
         }
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index 7d3d8b12e0..bd58c07bb6 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -1506,7 +1506,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->storage, s->size) < 0) {
             error_setg(errp, "failed to read the initial flash content");
             return;
         }
diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
index 525e38ce93..0515d1818e 100644
--- a/hw/misc/mac_via.c
+++ b/hw/misc/mac_via.c
@@ -1030,7 +1030,7 @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
         }
 
         len = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM));
-        if (len != sizeof(v1s->PRAM)) {
+        if (len < 0) {
             error_setg(errp, "can't read PRAM contents");
             return;
         }
diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
index 6d5f84e6c2..535acde08b 100644
--- a/hw/misc/sifive_u_otp.c
+++ b/hw/misc/sifive_u_otp.c
@@ -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, s->fuse, filesize) < 0) {
                 error_setg(errp, "failed to read the initial flash content");
                 return;
             }
diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index 01a3093600..84acd71f5a 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -65,7 +65,7 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
         DPRINTK("clear\n");
         if (ee->blk && ee->changed) {
             int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0);
-            if (len != ee->rsize) {
+            if (len < 0) {
                 ERR(TYPE_AT24C_EE
                         " : failed to write backing file\n");
             }
@@ -165,7 +165,7 @@ void at24c_eeprom_reset(DeviceState *state)
     if (ee->blk) {
         int len = blk_pread(ee->blk, 0, ee->mem, ee->rsize);
 
-        if (len != ee->rsize) {
+        if (len < 0) {
             ERR(TYPE_AT24C_EE
                     " : Failed initial sync with backing file\n");
         }
diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
index 18b43be7f6..6000b945c3 100644
--- a/hw/nvram/spapr_nvram.c
+++ b/hw/nvram/spapr_nvram.c
@@ -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, membuf, len, 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)
@@ -181,7 +181,7 @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp)
     if (nvram->blk) {
         int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);
 
-        if (alen != nvram->size) {
+        if (alen < 0) {
             error_setg(errp, "can't read spapr-nvram contents");
             return;
         }
diff --git a/hw/ppc/pnv_pnor.c b/hw/ppc/pnv_pnor.c
index 83ecccca28..1fb748afef 100644
--- a/hw/ppc/pnv_pnor.c
+++ b/hw/ppc/pnv_pnor.c
@@ -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->storage, s->size) < 0) {
             error_setg(errp, "failed to read the initial flash content");
             return;
         }
diff --git a/qemu-img.c b/qemu-img.c
index 4cf4d2423d..9d98ef63ac 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -5120,30 +5120,27 @@ 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_ret, out_ret;
 
-        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);
-        }
+        bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
+
+        in_ret = blk_pread(blk1, in_pos, in.buf, bytes);
         if (in_ret < 0) {
             error_report("error while reading from input image file: %s",
                          strerror(-in_ret));
             ret = -1;
             goto out;
         }
-        in_pos += in_ret;
-
-        out_ret = blk_pwrite(blk2, out_pos, in.buf, in_ret, 0);
+        in_pos += bytes;
 
+        out_ret = blk_pwrite(blk2, out_pos, in.buf, bytes, 0);
         if (out_ret < 0) {
             error_report("error while writing to output image file: %s",
                          strerror(-out_ret));
             ret = -1;
             goto out;
         }
-        out_pos += out_ret;
+        out_pos += bytes;
     }
 
 out:
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 2f0d8ac25a..443f22c732 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -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, (uint8_t *)buf, bytes);
+    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, (uint8_t *)buf, bytes, flags);
+    if (ret < 0) {
+        return ret;
     }
+    *total = bytes;
     return 1;
 }
 
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
index a5c163af7e..3c1a3f64a2 100644
--- a/tests/unit/test-block-iothread.c
+++ b/tests/unit/test-block-iothread.c
@@ -117,7 +117,7 @@ static void test_sync_op_blk_pread(BlockBackend *blk)
 
     /* Success */
     ret = blk_pread(blk, 0, buf, sizeof(buf));
-    g_assert_cmpint(ret, ==, 512);
+    g_assert_cmpint(ret, ==, 0);
 
     /* Early error: Negative offset */
     ret = blk_pread(blk, -2, buf, sizeof(buf));
@@ -131,7 +131,7 @@ static void test_sync_op_blk_pwrite(BlockBackend *blk)
 
     /* Success */
     ret = blk_pwrite(blk, 0, buf, sizeof(buf), 0);
-    g_assert_cmpint(ret, ==, 512);
+    g_assert_cmpint(ret, ==, 0);
 
     /* Early error: Negative offset */
     ret = blk_pwrite(blk, -2, buf, sizeof(buf), 0);
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 02/18] block: Add a 'flags' param to blk_pread()
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
  2022-05-17 11:35 ` [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success Alberto Faria
@ 2022-05-17 11:35 ` Alberto Faria
  2022-05-17 14:19   ` Paolo Bonzini
                     ` (2 more replies)
  2022-05-17 11:37 ` [PATCH 03/18] block: Change blk_{pread,pwrite}() param order Alberto Faria
                   ` (16 subsequent siblings)
  18 siblings, 3 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:35 UTC (permalink / raw)
  To: qemu-devel
  Cc: Andrew Jeffery, Peter Maydell, qemu-block, Palmer Dabbelt,
	Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, Hanna Reitz,
	John Snow, Stefan Hajnoczi, Jeff Cody, qemu-riscv,
	Cédric Le Goater, Joel Stanley, Stefan Weil, Laurent Vivier,
	Denis V. Lunev, Juan Quintela, Dr. David Alan Gilbert,
	Niek Linnenbank, Greg Kurz, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson, Alberto Faria

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>
---
 block.c                           |  2 +-
 block/block-backend.c             |  5 +++--
 block/commit.c                    |  2 +-
 block/export/fuse.c               |  2 +-
 hw/arm/allwinner-h3.c             |  2 +-
 hw/arm/aspeed.c                   |  2 +-
 hw/block/block.c                  |  2 +-
 hw/block/fdc.c                    |  6 +++---
 hw/block/hd-geometry.c            |  2 +-
 hw/block/m25p80.c                 |  2 +-
 hw/block/nand.c                   | 12 ++++++------
 hw/block/onenand.c                | 12 ++++++------
 hw/ide/atapi.c                    |  4 ++--
 hw/misc/mac_via.c                 |  2 +-
 hw/misc/sifive_u_otp.c            |  4 ++--
 hw/nvram/eeprom_at24c.c           |  2 +-
 hw/nvram/spapr_nvram.c            |  2 +-
 hw/nvram/xlnx-bbram.c             |  2 +-
 hw/nvram/xlnx-efuse.c             |  2 +-
 hw/ppc/pnv_pnor.c                 |  2 +-
 hw/sd/sd.c                        |  2 +-
 include/sysemu/block-backend-io.h |  3 ++-
 migration/block.c                 |  4 ++--
 nbd/server.c                      |  4 ++--
 qemu-img.c                        | 12 ++++++------
 qemu-io-cmds.c                    |  2 +-
 tests/unit/test-block-iothread.c  |  4 ++--
 27 files changed, 52 insertions(+), 50 deletions(-)

diff --git a/block.c b/block.c
index 0fd830e2e2..ed701b4889 100644
--- a/block.c
+++ b/block.c
@@ -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");
diff --git a/block/block-backend.c b/block/block-backend.c
index c1c367bf9e..da89450861 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1567,14 +1567,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;
diff --git a/block/commit.c b/block/commit.c
index 851d1c557a..e5b3ad08da 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -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;
             }
diff --git a/block/export/fuse.c b/block/export/fuse.c
index e80b24a867..dcf8f225f3 100644
--- a/block/export/fuse.c
+++ b/block/export/fuse.c
@@ -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 {
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
index 318ed4348c..788083b6fa 100644
--- a/hw/arm/allwinner-h3.c
+++ b/hw/arm/allwinner-h3.c
@@ -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;
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
index a74c13ab0f..06ab8cd0a5 100644
--- a/hw/arm/aspeed.c
+++ b/hw/arm/aspeed.c
@@ -269,7 +269,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;
     }
diff --git a/hw/block/block.c b/hw/block/block.c
index 25f45df723..effb89910c 100644
--- a/hw/block/block.c
+++ b/hw/block/block.c
@@ -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;
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 57bb355794..52f278ed82 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -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));
diff --git a/hw/block/hd-geometry.c b/hw/block/hd-geometry.c
index dcbccee294..24933eae82 100644
--- a/hw/block/hd-geometry.c
+++ b/hw/block/hd-geometry.c
@@ -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 */
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index bd58c07bb6..3e93769fed 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -1506,7 +1506,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;
         }
diff --git a/hw/block/nand.c b/hw/block/nand.c
index 8bc80e3514..ea3d33adf4 100644
--- a/hw/block/nand.c
+++ b/hw/block/nand.c
@@ -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);
             }
diff --git a/hw/block/onenand.c b/hw/block/onenand.c
index afc0cd3a0f..1225ec8076 100644
--- a/hw/block/onenand.c
+++ b/hw/block/onenand.c
@@ -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);
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index b626199e3d..7e405657df 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -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);
         }
diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
index 0515d1818e..d259def2d2 100644
--- a/hw/misc/mac_via.c
+++ b/hw/misc/mac_via.c
@@ -1029,7 +1029,7 @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
             return;
         }
 
-        len = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM));
+        len = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM), 0);
         if (len < 0) {
             error_setg(errp, "can't read PRAM contents");
             return;
diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
index 535acde08b..c730bb1ae0 100644
--- a/hw/misc/sifive_u_otp.c
+++ b/hw/misc/sifive_u_otp.c
@@ -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;
             }
diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index 84acd71f5a..876b3dd5dc 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -163,7 +163,7 @@ 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 len = blk_pread(ee->blk, 0, ee->mem, ee->rsize, 0);
 
         if (len < 0) {
             ERR(TYPE_AT24C_EE
diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
index 6000b945c3..4d32d92ad4 100644
--- a/hw/nvram/spapr_nvram.c
+++ b/hw/nvram/spapr_nvram.c
@@ -179,7 +179,7 @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp)
     }
 
     if (nvram->blk) {
-        int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);
+        int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size, 0);
 
         if (alen < 0) {
             error_setg(errp, "can't read spapr-nvram contents");
diff --git a/hw/nvram/xlnx-bbram.c b/hw/nvram/xlnx-bbram.c
index 6ed32adad9..cb245b864c 100644
--- a/hw/nvram/xlnx-bbram.c
+++ b/hw/nvram/xlnx-bbram.c
@@ -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);
diff --git a/hw/nvram/xlnx-efuse.c b/hw/nvram/xlnx-efuse.c
index a0fd77b586..edaac9cf7c 100644
--- a/hw/nvram/xlnx-efuse.c
+++ b/hw/nvram/xlnx-efuse.c
@@ -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;
diff --git a/hw/ppc/pnv_pnor.c b/hw/ppc/pnv_pnor.c
index 1fb748afef..f341f5a9c9 100644
--- a/hw/ppc/pnv_pnor.c
+++ b/hw/ppc/pnv_pnor.c
@@ -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;
         }
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 8e6fa09151..701170bf37 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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");
     }
 }
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 6517c39295..288bf39be1 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -102,7 +102,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,
diff --git a/migration/block.c b/migration/block.c
index 077a413325..fa216af025 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -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;
                 }
diff --git a/nbd/server.c b/nbd/server.c
index 213e00e761..849433aa3a 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -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);
diff --git a/qemu-img.c b/qemu-img.c
index 9d98ef63ac..edec9e4097 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -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;
@@ -5124,7 +5124,7 @@ static int img_dd(int argc, char **argv)
 
         bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
 
-        in_ret = blk_pread(blk1, in_pos, in.buf, bytes);
+        in_ret = blk_pread(blk1, in_pos, in.buf, bytes, 0);
         if (in_ret < 0) {
             error_report("error while reading from input image file: %s",
                          strerror(-in_ret));
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 443f22c732..582e1a7090 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -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;
     }
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
index 3c1a3f64a2..bfd12c9c15 100644
--- a/tests/unit/test-block-iothread.c
+++ b/tests/unit/test-block-iothread.c
@@ -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);
 }
 
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 03/18] block: Change blk_{pread,pwrite}() param order
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
  2022-05-17 11:35 ` [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success Alberto Faria
  2022-05-17 11:35 ` [PATCH 02/18] block: Add a 'flags' param to blk_pread() Alberto Faria
@ 2022-05-17 11:37 ` Alberto Faria
  2022-05-18 14:05   ` Eric Blake
  2022-07-04 15:21   ` Hanna Reitz
  2022-05-17 11:37 ` [PATCH 04/18] block: Make 'bytes' param of blk_{pread, pwrite}() an int64_t Alberto Faria
                   ` (15 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:37 UTC (permalink / raw)
  To: qemu-devel
  Cc: John Snow, Stefan Weil, Andrew Jeffery, Beniamino Galvani,
	qemu-block, Fam Zheng, Niek Linnenbank, Dr. David Alan Gilbert,
	Kevin Wolf, Stefan Hajnoczi, Eric Blake, Alistair Francis,
	Philippe Mathieu-Daudé,
	qemu-arm, qemu-riscv, Jeff Cody, Daniel Henrique Barboza,
	Cédric Le Goater, Edgar E. Iglesias, Juan Quintela,
	Joel Stanley, Peter Maydell, Laurent Vivier, Bin Meng, Greg Kurz,
	Vladimir Sementsov-Ogievskiy, Hanna Reitz, qemu-ppc,
	Palmer Dabbelt, David Gibson, Denis V. Lunev, Alberto Faria

Swap 'buf' and 'bytes' around for consistency with
blk_co_{pread,pwrite}(), and in preparation to implement these functions
using generated_co_wrapper.

Callers were updated using this Coccinelle script:

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

    @@ expression blk, offset, buf, bytes, flags; @@
    - blk_pwrite(blk, offset, buf, bytes, flags)
    + blk_pwrite(blk, offset, bytes, buf, flags)

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>
---
 block.c                           |  2 +-
 block/block-backend.c             |  4 +--
 block/commit.c                    |  4 +--
 block/crypto.c                    |  2 +-
 block/export/fuse.c               |  4 +--
 block/parallels.c                 |  2 +-
 block/qcow.c                      |  8 +++---
 block/qcow2.c                     |  4 +--
 block/qed.c                       |  8 +++---
 block/vdi.c                       |  4 +--
 block/vhdx.c                      | 20 ++++++-------
 block/vmdk.c                      | 10 +++----
 block/vpc.c                       | 12 ++++----
 hw/arm/allwinner-h3.c             |  2 +-
 hw/arm/aspeed.c                   |  2 +-
 hw/block/block.c                  |  2 +-
 hw/block/fdc.c                    | 20 ++++++-------
 hw/block/hd-geometry.c            |  2 +-
 hw/block/m25p80.c                 |  2 +-
 hw/block/nand.c                   | 47 ++++++++++++++++---------------
 hw/block/onenand.c                | 32 ++++++++++-----------
 hw/block/pflash_cfi01.c           |  4 +--
 hw/block/pflash_cfi02.c           |  4 +--
 hw/ide/atapi.c                    |  4 +--
 hw/misc/mac_via.c                 |  4 +--
 hw/misc/sifive_u_otp.c            | 14 ++++-----
 hw/nvram/eeprom_at24c.c           |  4 +--
 hw/nvram/spapr_nvram.c            |  6 ++--
 hw/nvram/xlnx-bbram.c             |  4 +--
 hw/nvram/xlnx-efuse.c             |  4 +--
 hw/ppc/pnv_pnor.c                 |  6 ++--
 hw/sd/sd.c                        |  4 +--
 include/sysemu/block-backend-io.h |  4 +--
 migration/block.c                 |  6 ++--
 nbd/server.c                      |  8 +++---
 qemu-img.c                        | 18 ++++++------
 qemu-io-cmds.c                    |  4 +--
 tests/unit/test-block-iothread.c  |  8 +++---
 38 files changed, 150 insertions(+), 149 deletions(-)

diff --git a/block.c b/block.c
index ed701b4889..bc85f46eed 100644
--- a/block.c
+++ b/block.c
@@ -1037,7 +1037,7 @@ static int find_image_format(BlockBackend *file, const char *filename,
         return ret;
     }
 
-    ret = blk_pread(file, 0, buf, sizeof(buf), 0);
+    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");
diff --git a/block/block-backend.c b/block/block-backend.c
index da89450861..16a0093c52 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1567,7 +1567,7 @@ 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, int bytes, void *buf,
               BdrvRequestFlags flags)
 {
     int ret;
@@ -1581,7 +1581,7 @@ int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes,
     return ret;
 }
 
-int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes,
+int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf,
                BdrvRequestFlags flags)
 {
     QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
diff --git a/block/commit.c b/block/commit.c
index e5b3ad08da..38571510cb 100644
--- a/block/commit.c
+++ b/block/commit.c
@@ -527,12 +527,12 @@ int bdrv_commit(BlockDriverState *bs)
             goto ro_cleanup;
         }
         if (ret) {
-            ret = blk_pread(src, offset, buf, n, 0);
+            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;
             }
diff --git a/block/crypto.c b/block/crypto.c
index 11c3ddbc73..7a57774b76 100644
--- a/block/crypto.c
+++ b/block/crypto.c
@@ -109,7 +109,7 @@ static int block_crypto_create_write_func(QCryptoBlock *block,
     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;
diff --git a/block/export/fuse.c b/block/export/fuse.c
index dcf8f225f3..1b26ddfcf3 100644
--- a/block/export/fuse.c
+++ b/block/export/fuse.c
@@ -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, 0);
+    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 {
diff --git a/block/parallels.c b/block/parallels.c
index 8b23b9580d..8b235b9505 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -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;
     }
diff --git a/block/qcow.c b/block/qcow.c
index 25a43353c1..311aaa8705 100644
--- a/block/qcow.c
+++ b/block/qcow.c
@@ -890,14 +890,14 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
     }
 
     /* write all the data */
-    ret = blk_pwrite(qcow_blk, 0, &header, sizeof(header), 0);
+    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);
+        ret = blk_pwrite(qcow_blk, sizeof(header), backing_filename_len,
+                         qcow_opts->backing_file, 0);
         if (ret < 0) {
             goto exit;
         }
@@ -907,7 +907,7 @@ 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);
+                         BDRV_SECTOR_SIZE, tmp, 0);
         if (ret < 0) {
             g_free(tmp);
             goto exit;
diff --git a/block/qcow2.c b/block/qcow2.c
index 90a2dd406b..c6c6692fb7 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -3666,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");
@@ -3676,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) {
diff --git a/block/qed.c b/block/qed.c
index 55da91eb72..40943e679b 100644
--- a/block/qed.c
+++ b/block/qed.c
@@ -705,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;
     }
diff --git a/block/vdi.c b/block/vdi.c
index a0be2a23b9..e942325455 100644
--- a/block/vdi.c
+++ b/block/vdi.c
@@ -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;
diff --git a/block/vhdx.c b/block/vhdx.c
index 12f5261f80..e10e78ebfd 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -1665,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;
     }
@@ -1756,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;
@@ -1860,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;
@@ -2012,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");
@@ -2020,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;
diff --git a/block/vmdk.c b/block/vmdk.c
index 332565c80f..fe07a54866 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -2236,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;
@@ -2261,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;
@@ -2273,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);
     }
@@ -2584,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;
diff --git a/block/vpc.c b/block/vpc.c
index 7f20820193..4f49ef207f 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -834,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;
     }
@@ -850,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;
         }
@@ -878,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;
     }
@@ -901,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;
diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
index 788083b6fa..308ed15552 100644
--- a/hw/arm/allwinner-h3.c
+++ b/hw/arm/allwinner-h3.c
@@ -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) < 0) {
+    if (blk_pread(blk, 8 * KiB, rom_size, buffer, 0) < 0) {
         error_setg(&error_fatal, "%s: failed to read BlockBackend data",
                    __func__);
         return;
diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
index 06ab8cd0a5..4853d78236 100644
--- a/hw/arm/aspeed.c
+++ b/hw/arm/aspeed.c
@@ -269,7 +269,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) < 0) {
+    if (blk_pread(blk, 0, rom_size, storage, 0) < 0) {
         error_setg(errp, "failed to read the initial flash content");
         return;
     }
diff --git a/hw/block/block.c b/hw/block/block.c
index effb89910c..04279166ee 100644
--- a/hw/block/block.c
+++ b/hw/block/block.c
@@ -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, 0);
+    ret = blk_pread(blk, 0, size, buf, 0);
     if (ret < 0) {
         error_setg_errno(errp, -ret, "can't read block backend");
         return false;
diff --git a/hw/block/fdc.c b/hw/block/fdc.c
index 52f278ed82..64ae4a6899 100644
--- a/hw/block/fdc.c
+++ b/hw/block/fdc.c
@@ -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) < 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, 0)
+            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;
diff --git a/hw/block/hd-geometry.c b/hw/block/hd-geometry.c
index 24933eae82..112094358e 100644
--- a/hw/block/hd-geometry.c
+++ b/hw/block/hd-geometry.c
@@ -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) < 0) {
+    if (blk_pread(blk, 0, BDRV_SECTOR_SIZE, buf, 0) < 0) {
         return -1;
     }
     /* test msdos magic */
diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
index 3e93769fed..3e3e142d83 100644
--- a/hw/block/m25p80.c
+++ b/hw/block/m25p80.c
@@ -1506,7 +1506,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) < 0) {
+        if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
             error_setg(errp, "failed to read the initial flash content");
             return;
         }
diff --git a/hw/block/nand.c b/hw/block/nand.c
index ea3d33adf4..1aee1cb2b1 100644
--- a/hw/block/nand.c
+++ b/hw/block/nand.c
@@ -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) < 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) < 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) < 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) < 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) < 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) < 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);
             }
diff --git a/hw/block/onenand.c b/hw/block/onenand.c
index 1225ec8076..1fde975024 100644
--- a/hw/block/onenand.c
+++ b/hw/block/onenand.c
@@ -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) < 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) < 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) < 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) < 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) < 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) < 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 {
diff --git a/hw/block/pflash_cfi01.c b/hw/block/pflash_cfi01.c
index 74c7190302..0cbc2fb4cb 100644
--- a/hw/block/pflash_cfi01.c
+++ b/hw/block/pflash_cfi01.c
@@ -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));
diff --git a/hw/block/pflash_cfi02.c b/hw/block/pflash_cfi02.c
index 02c514fb6e..2a99b286b0 100644
--- a/hw/block/pflash_cfi02.c
+++ b/hw/block/pflash_cfi02.c
@@ -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));
diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
index 7e405657df..49b648f980 100644
--- a/hw/ide/atapi.c
+++ b/hw/ide/atapi.c
@@ -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, 0);
+                        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, 0);
+                        ATAPI_SECTOR_SIZE, s->io_buffer + 16, 0);
         if (ret >= 0) {
             cd_data_to_raw(s->io_buffer, s->lba);
         }
diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
index d259def2d2..1e749999ed 100644
--- a/hw/misc/mac_via.c
+++ b/hw/misc/mac_via.c
@@ -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,7 +1029,7 @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
             return;
         }
 
-        len = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM), 0);
+        len = blk_pread(v1s->blk, 0, sizeof(v1s->PRAM), v1s->PRAM, 0);
         if (len < 0) {
             error_setg(errp, "can't read PRAM contents");
             return;
diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
index c730bb1ae0..6d7fdb040a 100644
--- a/hw/misc/sifive_u_otp.c
+++ b/hw/misc/sifive_u_otp.c
@@ -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) < 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, 0) < 0) {
+            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;
         }
diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
index 876b3dd5dc..b480c8193c 100644
--- a/hw/nvram/eeprom_at24c.c
+++ b/hw/nvram/eeprom_at24c.c
@@ -64,7 +64,7 @@ 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);
+            int len = blk_pwrite(ee->blk, 0, ee->rsize, ee->mem, 0);
             if (len < 0) {
                 ERR(TYPE_AT24C_EE
                         " : failed to write backing file\n");
@@ -163,7 +163,7 @@ 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, 0);
+        int len = blk_pread(ee->blk, 0, ee->rsize, ee->mem, 0);
 
         if (len < 0) {
             ERR(TYPE_AT24C_EE
diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
index 4d32d92ad4..34f25afd4a 100644
--- a/hw/nvram/spapr_nvram.c
+++ b/hw/nvram/spapr_nvram.c
@@ -130,7 +130,7 @@ static void rtas_nvram_store(PowerPCCPU *cpu, SpaprMachineState *spapr,
 
     ret = 0;
     if (nvram->blk) {
-        ret = blk_pwrite(nvram->blk, offset, membuf, len, 0);
+        ret = blk_pwrite(nvram->blk, offset, len, membuf, 0);
     }
 
     assert(nvram->buf);
@@ -179,7 +179,7 @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp)
     }
 
     if (nvram->blk) {
-        int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size, 0);
+        int alen = blk_pread(nvram->blk, 0, nvram->size, nvram->buf, 0);
 
         if (alen < 0) {
             error_setg(errp, "can't read spapr-nvram contents");
@@ -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)
diff --git a/hw/nvram/xlnx-bbram.c b/hw/nvram/xlnx-bbram.c
index cb245b864c..c6b484cc85 100644
--- a/hw/nvram/xlnx-bbram.c
+++ b/hw/nvram/xlnx-bbram.c
@@ -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) < 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));
     }
diff --git a/hw/nvram/xlnx-efuse.c b/hw/nvram/xlnx-efuse.c
index edaac9cf7c..fdfffaab99 100644
--- a/hw/nvram/xlnx-efuse.c
+++ b/hw/nvram/xlnx-efuse.c
@@ -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) < 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);
     }
diff --git a/hw/ppc/pnv_pnor.c b/hw/ppc/pnv_pnor.c
index f341f5a9c9..6280408299 100644
--- a/hw/ppc/pnv_pnor.c
+++ b/hw/ppc/pnv_pnor.c
@@ -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, 0) < 0) {
+        if (blk_pread(s->blk, 0, s->size, s->storage, 0) < 0) {
             error_setg(errp, "failed to read the initial flash content");
             return;
         }
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 701170bf37..da5bdd134a 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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) < 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");
     }
 }
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 288bf39be1..357534e3de 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -102,9 +102,9 @@ 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, int bytes, void *buf,
               BdrvRequestFlags flags);
-int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes,
+int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf,
                BdrvRequestFlags flags);
 int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
                                int64_t bytes, QEMUIOVector *qiov,
diff --git a/migration/block.c b/migration/block.c
index fa216af025..9de7d4d20b 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -569,7 +569,7 @@ static int mig_save_device_dirty(QEMUFile *f, BlkMigDevState *bmds,
                 blk_mig_unlock();
             } else {
                 ret = blk_pread(bmds->blk, sector * BDRV_SECTOR_SIZE,
-                                blk->buf, nr_sectors * BDRV_SECTOR_SIZE, 0);
+                                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;
diff --git a/nbd/server.c b/nbd/server.c
index 849433aa3a..ada16089f3 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -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, 0);
+            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, 0);
+    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);
diff --git a/qemu-img.c b/qemu-img.c
index edec9e4097..8d214e649e 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -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, 0);
+    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, 0);
+                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, 0);
+                ret = blk_pread(blk2, offset, chunk, buf2, 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, 0);
+                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, 0);
+                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",
@@ -5124,7 +5124,7 @@ static int img_dd(int argc, char **argv)
 
         bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
 
-        in_ret = blk_pread(blk1, in_pos, in.buf, bytes, 0);
+        in_ret = blk_pread(blk1, in_pos, bytes, in.buf, 0);
         if (in_ret < 0) {
             error_report("error while reading from input image file: %s",
                          strerror(-in_ret));
@@ -5133,7 +5133,7 @@ static int img_dd(int argc, char **argv)
         }
         in_pos += bytes;
 
-        out_ret = blk_pwrite(blk2, out_pos, in.buf, bytes, 0);
+        out_ret = blk_pwrite(blk2, out_pos, bytes, in.buf, 0);
         if (out_ret < 0) {
             error_report("error while writing to output image file: %s",
                          strerror(-out_ret));
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 582e1a7090..c8cbaed0cd 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -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, 0);
+    ret = blk_pread(blk, offset, bytes, (uint8_t *)buf, 0);
     if (ret < 0) {
         return ret;
     }
@@ -564,7 +564,7 @@ static int do_pwrite(BlockBackend *blk, char *buf, int64_t offset,
         return -ERANGE;
     }
 
-    ret = blk_pwrite(blk, offset, (uint8_t *)buf, bytes, flags);
+    ret = blk_pwrite(blk, offset, bytes, (uint8_t *)buf, flags);
     if (ret < 0) {
         return ret;
     }
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
index bfd12c9c15..0ced5333ff 100644
--- a/tests/unit/test-block-iothread.c
+++ b/tests/unit/test-block-iothread.c
@@ -116,11 +116,11 @@ static void test_sync_op_blk_pread(BlockBackend *blk)
     int ret;
 
     /* Success */
-    ret = blk_pread(blk, 0, buf, sizeof(buf), 0);
+    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), 0);
+    ret = blk_pread(blk, -2, sizeof(buf), buf, 0);
     g_assert_cmpint(ret, ==, -EIO);
 }
 
@@ -130,11 +130,11 @@ static void test_sync_op_blk_pwrite(BlockBackend *blk)
     int ret;
 
     /* Success */
-    ret = blk_pwrite(blk, 0, buf, sizeof(buf), 0);
+    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);
 }
 
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 04/18] block: Make 'bytes' param of blk_{pread, pwrite}() an int64_t
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (2 preceding siblings ...)
  2022-05-17 11:37 ` [PATCH 03/18] block: Change blk_{pread,pwrite}() param order Alberto Faria
@ 2022-05-17 11:37 ` Alberto Faria
  2022-05-17 14:20   ` Paolo Bonzini
  2022-07-04 15:24   ` [PATCH 04/18] block: Make 'bytes' param of blk_{pread,pwrite}() " Hanna Reitz
  2022-05-17 11:38 ` [PATCH 05/18] block: Make blk_co_pwrite() take a const buffer Alberto Faria
                   ` (14 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:37 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-block, Hanna Reitz, Kevin Wolf, Alberto Faria

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

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             | 6 +++---
 include/sysemu/block-backend-io.h | 6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 16a0093c52..5b9706c443 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1567,7 +1567,7 @@ 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, int bytes, void *buf,
+int blk_pread(BlockBackend *blk, int64_t offset, int64_t bytes, void *buf,
               BdrvRequestFlags flags)
 {
     int ret;
@@ -1581,8 +1581,8 @@ int blk_pread(BlockBackend *blk, int64_t offset, int bytes, void *buf,
     return ret;
 }
 
-int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf,
-               BdrvRequestFlags flags)
+int blk_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();
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 357534e3de..6630316795 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -102,10 +102,10 @@ 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, int bytes, void *buf,
+int blk_pread(BlockBackend *blk, int64_t offset, int64_t bytes, void *buf,
               BdrvRequestFlags flags);
-int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf,
-               BdrvRequestFlags flags);
+int blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes,
+               const void *buf, BdrvRequestFlags flags);
 int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
                                int64_t bytes, QEMUIOVector *qiov,
                                BdrvRequestFlags flags);
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 05/18] block: Make blk_co_pwrite() take a const buffer
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (3 preceding siblings ...)
  2022-05-17 11:37 ` [PATCH 04/18] block: Make 'bytes' param of blk_{pread, pwrite}() an int64_t Alberto Faria
@ 2022-05-17 11:38 ` Alberto Faria
  2022-05-17 14:20   ` Paolo Bonzini
  2022-07-04 15:25   ` Hanna Reitz
  2022-05-17 11:38 ` [PATCH 06/18] block: Implement blk_{pread, pwrite}() using generated_co_wrapper Alberto Faria
                   ` (13 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block, Alberto Faria

It does not mutate the buffer.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 include/sysemu/block-backend-io.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 6630316795..6440e92028 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -130,7 +130,7 @@ static inline int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset,
 }
 
 static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset,
-                                             int64_t bytes, void *buf,
+                                             int64_t bytes, const void *buf,
                                              BdrvRequestFlags flags)
 {
     QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 06/18] block: Implement blk_{pread, pwrite}() using generated_co_wrapper
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (4 preceding siblings ...)
  2022-05-17 11:38 ` [PATCH 05/18] block: Make blk_co_pwrite() take a const buffer Alberto Faria
@ 2022-05-17 11:38 ` Alberto Faria
  2022-05-17 14:22   ` Paolo Bonzini
  2022-07-04 15:30   ` [PATCH 06/18] block: Implement blk_{pread,pwrite}() " Hanna Reitz
  2022-05-17 11:38 ` [PATCH 07/18] block: Add blk_{preadv,pwritev}() Alberto Faria
                   ` (12 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block, Alberto Faria

We need to add include/sysemu/block-backend-io.h to the inputs of the
block-gen.c target defined in block/meson.build.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             | 23 -----------------------
 block/coroutines.h                |  4 ----
 block/meson.build                 |  1 +
 include/sysemu/block-backend-io.h | 10 ++++++----
 4 files changed, 7 insertions(+), 31 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 5b9706c443..c2a4c44a99 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1567,29 +1567,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, int64_t bytes, void *buf,
-              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, flags);
-    blk_dec_in_flight(blk);
-
-    return ret;
-}
-
-int blk_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();
-
-    return blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags);
-}
-
 int64_t blk_getlength(BlockBackend *blk)
 {
     IO_CODE();
diff --git a/block/coroutines.h b/block/coroutines.h
index 3f41238b33..443ef2f2e6 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -112,10 +112,6 @@ 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,
diff --git a/block/meson.build b/block/meson.build
index 0b2a60c99b..60bc305597 100644
--- a/block/meson.build
+++ b/block/meson.build
@@ -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@'])
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 6440e92028..0804ce1c1d 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -102,10 +102,12 @@ 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, int64_t bytes, void *buf,
-              BdrvRequestFlags flags);
-int blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes,
-               const void *buf, BdrvRequestFlags flags);
+int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset,
+                                   int64_t bytes, void *buf,
+                                   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_preadv(BlockBackend *blk, int64_t offset,
                                int64_t bytes, QEMUIOVector *qiov,
                                BdrvRequestFlags flags);
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 07/18] block: Add blk_{preadv,pwritev}()
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (5 preceding siblings ...)
  2022-05-17 11:38 ` [PATCH 06/18] block: Implement blk_{pread, pwrite}() using generated_co_wrapper Alberto Faria
@ 2022-05-17 11:38 ` Alberto Faria
  2022-05-17 14:35   ` Paolo Bonzini
  2022-07-05  7:55   ` Hanna Reitz
  2022-05-17 11:38 ` [PATCH 08/18] block: Add blk_[co_]preadv_part() Alberto Faria
                   ` (11 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block, Alberto Faria

Implement them using generated_co_wrapper.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 include/sysemu/block-backend-io.h |  6 +++++
 tests/unit/test-block-iothread.c  | 42 ++++++++++++++++++++++++++++++-
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 0804ce1c1d..3b548a8ae1 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -108,6 +108,9 @@ int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset,
 int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset,
                                     int64_t bytes, const 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);
@@ -115,6 +118,9 @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
                                      int64_t bytes,
                                      QEMUIOVector *qiov, size_t qiov_offset,
                                      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);
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
index 0ced5333ff..b9c5da3a87 100644
--- a/tests/unit/test-block-iothread.c
+++ b/tests/unit/test-block-iothread.c
@@ -138,6 +138,36 @@ static void test_sync_op_blk_pwrite(BlockBackend *blk)
     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_load_vmstate(BdrvChild *c)
 {
     uint8_t buf[512];
@@ -301,6 +331,14 @@ 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/load_vmstate",
         .fn     = test_sync_op_load_vmstate,
@@ -349,7 +387,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);
     }
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 08/18] block: Add blk_[co_]preadv_part()
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (6 preceding siblings ...)
  2022-05-17 11:38 ` [PATCH 07/18] block: Add blk_{preadv,pwritev}() Alberto Faria
@ 2022-05-17 11:38 ` Alberto Faria
  2022-05-17 14:30   ` Paolo Bonzini
  2022-07-05  8:15   ` Hanna Reitz
  2022-05-17 11:38 ` [PATCH 09/18] block: Export blk_pwritev_part() in block-backend-io.h Alberto Faria
                   ` (10 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block, Alberto Faria

Implement blk_preadv_part() using generated_co_wrapper.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             | 30 +++++++++++++++++++++++-------
 block/coroutines.h                |  5 -----
 include/sysemu/block-backend-io.h |  7 +++++++
 tests/unit/test-block-iothread.c  | 19 +++++++++++++++++++
 4 files changed, 49 insertions(+), 12 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index c2a4c44a99..3920e1f45e 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1284,9 +1284,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;
@@ -1311,7 +1312,8 @@ 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;
 }
@@ -1324,7 +1326,21 @@ 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;
@@ -1541,8 +1557,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);
 }
 
diff --git a/block/coroutines.h b/block/coroutines.h
index 443ef2f2e6..85423f8db6 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -63,11 +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,
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 3b548a8ae1..29954a466c 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -108,6 +108,13 @@ int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset,
 int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset,
                                     int64_t bytes, const void *buf,
                                     BdrvRequestFlags flags);
+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_preadv(BlockBackend *blk, int64_t offset,
                                     int64_t bytes, QEMUIOVector *qiov,
                                     BdrvRequestFlags flags);
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
index b9c5da3a87..2fa1248445 100644
--- a/tests/unit/test-block-iothread.c
+++ b/tests/unit/test-block-iothread.c
@@ -168,6 +168,21 @@ static void test_sync_op_blk_pwritev(BlockBackend *blk)
     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_load_vmstate(BdrvChild *c)
 {
     uint8_t buf[512];
@@ -339,6 +354,10 @@ const SyncOpTest sync_op_tests[] = {
         .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/load_vmstate",
         .fn     = test_sync_op_load_vmstate,
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 09/18] block: Export blk_pwritev_part() in block-backend-io.h
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (7 preceding siblings ...)
  2022-05-17 11:38 ` [PATCH 08/18] block: Add blk_[co_]preadv_part() Alberto Faria
@ 2022-05-17 11:38 ` Alberto Faria
  2022-05-17 14:30   ` Paolo Bonzini
  2022-07-05  8:24   ` Hanna Reitz
  2022-05-17 11:38 ` [PATCH 10/18] block: Change blk_pwrite_compressed() param order Alberto Faria
                   ` (9 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block, Alberto Faria

Also convert it into a generated_co_wrapper.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             | 14 --------------
 block/coroutines.h                |  5 -----
 include/sysemu/block-backend-io.h |  4 ++++
 tests/unit/test-block-iothread.c  | 19 +++++++++++++++++++
 4 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 3920e1f45e..35bf35aadd 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1407,20 +1407,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;
diff --git a/block/coroutines.h b/block/coroutines.h
index 85423f8db6..94fd283f62 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -107,11 +107,6 @@ 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_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);
 
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 29954a466c..31ebd8b6cf 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -121,6 +121,10 @@ int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset,
 int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset,
                                int64_t bytes, QEMUIOVector *qiov,
                                BdrvRequestFlags flags);
+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,
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
index 2fa1248445..6061762c97 100644
--- a/tests/unit/test-block-iothread.c
+++ b/tests/unit/test-block-iothread.c
@@ -183,6 +183,21 @@ static void test_sync_op_blk_preadv_part(BlockBackend *blk)
     g_assert_cmpint(ret, ==, -EIO);
 }
 
+static void test_sync_op_blk_pwritev_part(BlockBackend *blk)
+{
+    uint8_t buf[512];
+    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_load_vmstate(BdrvChild *c)
 {
     uint8_t buf[512];
@@ -358,6 +373,10 @@ const SyncOpTest sync_op_tests[] = {
         .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/load_vmstate",
         .fn     = test_sync_op_load_vmstate,
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 10/18] block: Change blk_pwrite_compressed() param order
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (8 preceding siblings ...)
  2022-05-17 11:38 ` [PATCH 09/18] block: Export blk_pwritev_part() in block-backend-io.h Alberto Faria
@ 2022-05-17 11:38 ` Alberto Faria
  2022-05-17 14:25   ` Paolo Bonzini
  2022-07-05  8:29   ` Hanna Reitz
  2022-05-17 11:38 ` [PATCH 11/18] block: Add blk_co_pwrite_compressed() Alberto Faria
                   ` (8 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block, Alberto Faria

Swap 'buf' and 'bytes' around for consistency with other I/O functions.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             | 4 ++--
 include/sysemu/block-backend-io.h | 4 ++--
 qemu-img.c                        | 2 +-
 qemu-io-cmds.c                    | 2 +-
 4 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 35bf35aadd..ddb1d4e179 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -2324,8 +2324,8 @@ 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 blk_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();
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 31ebd8b6cf..c64207cdcb 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -168,8 +168,8 @@ int blk_flush(BlockBackend *blk);
 
 int blk_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_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes,
+                          const void *buf);
 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);
diff --git a/qemu-img.c b/qemu-img.c
index 8d214e649e..52f3aeed9b 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -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;
         }
diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index c8cbaed0cd..952dc940f1 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -631,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;
     }
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 11/18] block: Add blk_co_pwrite_compressed()
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (9 preceding siblings ...)
  2022-05-17 11:38 ` [PATCH 10/18] block: Change blk_pwrite_compressed() param order Alberto Faria
@ 2022-05-17 11:38 ` Alberto Faria
  2022-05-17 14:26   ` Paolo Bonzini
  2022-07-05  8:45   ` Hanna Reitz
  2022-05-17 11:39 ` [PATCH 12/18] block: Implement blk_pwrite_zeroes() using generated_co_wrapper Alberto Faria
                   ` (7 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:38 UTC (permalink / raw)
  To: qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block, Alberto Faria

Also convert blk_pwrite_compressed() into a generated_co_wrapper.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             |  8 ++++----
 include/sysemu/block-backend-io.h |  7 +++++--
 tests/unit/test-block-iothread.c  | 18 ++++++++++++++++++
 3 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index ddb1d4e179..cc85558813 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -2324,13 +2324,13 @@ 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, int64_t bytes,
-                          const void *buf)
+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,
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index c64207cdcb..d129e2bed3 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -168,8 +168,11 @@ int blk_flush(BlockBackend *blk);
 
 int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
 
-int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes,
-                          const void *buf);
+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);
 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);
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
index 6061762c97..b3e79d7698 100644
--- a/tests/unit/test-block-iothread.c
+++ b/tests/unit/test-block-iothread.c
@@ -198,6 +198,20 @@ static void test_sync_op_blk_pwritev_part(BlockBackend *blk)
     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_load_vmstate(BdrvChild *c)
 {
     uint8_t buf[512];
@@ -377,6 +391,10 @@ const SyncOpTest sync_op_tests[] = {
         .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/load_vmstate",
         .fn     = test_sync_op_load_vmstate,
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 12/18] block: Implement blk_pwrite_zeroes() using generated_co_wrapper
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (10 preceding siblings ...)
  2022-05-17 11:38 ` [PATCH 11/18] block: Add blk_co_pwrite_compressed() Alberto Faria
@ 2022-05-17 11:39 ` Alberto Faria
  2022-05-17 14:26   ` Paolo Bonzini
  2022-07-05  8:48   ` Hanna Reitz
  2022-05-17 11:39 ` [PATCH 13/18] block: Implement blk_pdiscard() " Alberto Faria
                   ` (6 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz, Alberto Faria

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             |  8 --------
 include/sysemu/block-backend-io.h |  5 +++--
 tests/unit/test-block-iothread.c  | 17 +++++++++++++++++
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index cc85558813..8129259e50 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1415,14 +1415,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();
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index d129e2bed3..5ce9b80023 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -174,8 +174,9 @@ int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk,
 int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset,
                                           int64_t bytes, const void *buf);
 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 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 blk_truncate(BlockBackend *blk, int64_t offset, bool exact,
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
index b3e79d7698..d701c5a056 100644
--- a/tests/unit/test-block-iothread.c
+++ b/tests/unit/test-block-iothread.c
@@ -212,6 +212,19 @@ static void test_sync_op_blk_pwrite_compressed(BlockBackend *blk)
     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);
+}
+
 static void test_sync_op_load_vmstate(BdrvChild *c)
 {
     uint8_t buf[512];
@@ -395,6 +408,10 @@ const SyncOpTest sync_op_tests[] = {
         .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,
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 13/18] block: Implement blk_pdiscard() using generated_co_wrapper
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (11 preceding siblings ...)
  2022-05-17 11:39 ` [PATCH 12/18] block: Implement blk_pwrite_zeroes() using generated_co_wrapper Alberto Faria
@ 2022-05-17 11:39 ` Alberto Faria
  2022-05-17 14:27   ` Paolo Bonzini
  2022-07-05  8:51   ` Hanna Reitz
  2022-05-17 11:39 ` [PATCH 14/18] block: Implement blk_flush() " Alberto Faria
                   ` (5 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz, Alberto Faria

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             | 12 ------------
 block/coroutines.h                |  3 ---
 include/sysemu/block-backend-io.h |  3 ++-
 3 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 8129259e50..823c98a031 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1715,18 +1715,6 @@ 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)
 {
diff --git a/block/coroutines.h b/block/coroutines.h
index 94fd283f62..2693ecabfb 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -110,9 +110,6 @@ nbd_do_establish_connection(BlockDriverState *bs, bool blocking, Error **errp);
 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 */
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 5ce9b80023..5c56737453 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -160,6 +160,8 @@ static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset,
     return blk_co_pwritev(blk, offset, bytes, &qiov, 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);
 
@@ -173,7 +175,6 @@ int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk,
                                                const void *buf);
 int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset,
                                           int64_t bytes, const void *buf);
-int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes);
 int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
                                            int64_t bytes,
                                            BdrvRequestFlags flags);
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 14/18] block: Implement blk_flush() using generated_co_wrapper
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (12 preceding siblings ...)
  2022-05-17 11:39 ` [PATCH 13/18] block: Implement blk_pdiscard() " Alberto Faria
@ 2022-05-17 11:39 ` Alberto Faria
  2022-05-17 14:27   ` Paolo Bonzini
  2022-07-05  8:56   ` Hanna Reitz
  2022-05-17 11:39 ` [PATCH 15/18] block: Add blk_co_ioctl() Alberto Faria
                   ` (4 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz, Alberto Faria

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             | 11 -----------
 block/coroutines.h                |  2 --
 include/sysemu/block-backend-io.h |  2 +-
 3 files changed, 1 insertion(+), 14 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 823c98a031..0718441b37 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1756,17 +1756,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);
diff --git a/block/coroutines.h b/block/coroutines.h
index 2693ecabfb..7e94b9fa83 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -110,6 +110,4 @@ nbd_do_establish_connection(BlockDriverState *bs, bool blocking, Error **errp);
 int generated_co_wrapper
 blk_do_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
 
-int generated_co_wrapper blk_do_flush(BlockBackend *blk);
-
 #endif /* BLOCK_COROUTINES_H */
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 5c56737453..e6af0d0ed0 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -165,8 +165,8 @@ int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset,
 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);
 
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 15/18] block: Add blk_co_ioctl()
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (13 preceding siblings ...)
  2022-05-17 11:39 ` [PATCH 14/18] block: Implement blk_flush() " Alberto Faria
@ 2022-05-17 11:39 ` Alberto Faria
  2022-05-17 14:28   ` Paolo Bonzini
  2022-07-05  9:02   ` Hanna Reitz
  2022-05-17 11:39 ` [PATCH 16/18] block: Add blk_co_truncate() Alberto Faria
                   ` (3 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz, Alberto Faria

Also convert blk_ioctl() into a generated_co_wrapper.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             | 7 ++++---
 block/coroutines.h                | 6 ------
 include/sysemu/block-backend-io.h | 5 ++++-
 3 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 0718441b37..7bad42259e 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1624,7 +1624,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();
@@ -1638,13 +1638,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;
diff --git a/block/coroutines.h b/block/coroutines.h
index 7e94b9fa83..d66551a277 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -68,9 +68,6 @@ 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);
 
@@ -107,7 +104,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_ioctl(BlockBackend *blk, unsigned long int req, void *buf);
-
 #endif /* BLOCK_COROUTINES_H */
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index e6af0d0ed0..bb1ae25863 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -168,7 +168,10 @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
 int generated_co_wrapper blk_flush(BlockBackend *blk);
 int coroutine_fn blk_co_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 generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk,
                                                int64_t offset, int64_t bytes,
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 16/18] block: Add blk_co_truncate()
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (14 preceding siblings ...)
  2022-05-17 11:39 ` [PATCH 15/18] block: Add blk_co_ioctl() Alberto Faria
@ 2022-05-17 11:39 ` Alberto Faria
  2022-05-17 14:28   ` Paolo Bonzini
  2022-07-05  9:08   ` Hanna Reitz
  2022-05-17 11:39 ` [PATCH 17/18] block: Reorganize some declarations in block-backend-io.h Alberto Faria
                   ` (2 subsequent siblings)
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz, Alberto Faria

Also convert blk_truncate() into a generated_co_wrapper.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             |  7 ++++---
 include/sysemu/block-backend-io.h |  8 ++++++--
 tests/unit/test-block-iothread.c  | 14 ++++++++++++++
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 7bad42259e..52be1d9116 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -2303,8 +2303,9 @@ int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset,
                                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)) {
@@ -2312,7 +2313,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,
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index bb1ae25863..004493ec36 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -183,7 +183,11 @@ int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset,
                                            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 */
diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
index d701c5a056..9b7353ce89 100644
--- a/tests/unit/test-block-iothread.c
+++ b/tests/unit/test-block-iothread.c
@@ -298,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;
@@ -425,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,
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 17/18] block: Reorganize some declarations in block-backend-io.h
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (15 preceding siblings ...)
  2022-05-17 11:39 ` [PATCH 16/18] block: Add blk_co_truncate() Alberto Faria
@ 2022-05-17 11:39 ` Alberto Faria
  2022-05-17 14:29   ` Paolo Bonzini
  2022-07-05  9:18   ` Hanna Reitz
  2022-05-17 11:39 ` [PATCH 18/18] block: Remove remaining unused symbols in coroutines.h Alberto Faria
  2022-07-02 14:12 ` [PATCH 00/18] Make block-backend-io.h API more consistent Paolo Bonzini
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz, Alberto Faria

Keep generated_co_wrapper and coroutine_fn pairs together. This should
make it clear that each I/O function has these two versions.

Also move blk_co_{pread,pwrite}()'s implementations out of the header
file for consistency.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c             | 22 ++++++++
 include/sysemu/block-backend-io.h | 87 +++++++++++++------------------
 2 files changed, 59 insertions(+), 50 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 52be1d9116..920ba0dd1f 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1318,6 +1318,17 @@ blk_co_do_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes,
     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)
@@ -1399,6 +1410,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)
diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
index 004493ec36..30ed979fb1 100644
--- a/include/sysemu/block-backend-io.h
+++ b/include/sysemu/block-backend-io.h
@@ -88,11 +88,6 @@ uint32_t blk_get_request_alignment(BlockBackend *blk);
 uint32_t blk_get_max_transfer(BlockBackend *blk);
 uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
 
-int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
-                                   BlockBackend *blk_out, int64_t off_out,
-                                   int64_t bytes, BdrvRequestFlags read_flags,
-                                   BdrvRequestFlags write_flags);
-
 
 /*
  * "I/O or GS" API functions. These functions can run without
@@ -105,9 +100,16 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
 int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset,
                                    int64_t bytes, void *buf,
                                    BdrvRequestFlags flags);
-int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset,
-                                    int64_t bytes, const void *buf,
+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 generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset,
                                          int64_t bytes, QEMUIOVector *qiov,
                                          size_t qiov_offset,
@@ -115,12 +117,20 @@ int generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset,
 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_preadv(BlockBackend *blk, int64_t offset,
-                                    int64_t bytes, QEMUIOVector *qiov,
+
+int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset,
+                                    int64_t bytes, const void *buf,
                                     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_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);
+
 int generated_co_wrapper blk_pwritev_part(BlockBackend *blk, int64_t offset,
                                           int64_t bytes, QEMUIOVector *qiov,
                                           size_t qiov_offset,
@@ -129,36 +139,18 @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
                                      int64_t bytes,
                                      QEMUIOVector *qiov, size_t qiov_offset,
                                      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();
 
-    assert(bytes <= SIZE_MAX);
-
-    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, const void *buf,
-                                             BdrvRequestFlags flags)
-{
-    QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
-    IO_OR_GS_CODE();
-
-    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_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);
@@ -173,16 +165,6 @@ int generated_co_wrapper blk_ioctl(BlockBackend *blk, unsigned long int req,
 int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req,
                               void *buf);
 
-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);
-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_truncate(BlockBackend *blk, int64_t offset,
                                       bool exact, PreallocMode prealloc,
                                       BdrvRequestFlags flags, Error **errp);
@@ -190,4 +172,9 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact,
                                  PreallocMode prealloc, BdrvRequestFlags flags,
                                  Error **errp);
 
+int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
+                                   BlockBackend *blk_out, int64_t off_out,
+                                   int64_t bytes, BdrvRequestFlags read_flags,
+                                   BdrvRequestFlags write_flags);
+
 #endif /* BLOCK_BACKEND_IO_H */
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* [PATCH 18/18] block: Remove remaining unused symbols in coroutines.h
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (16 preceding siblings ...)
  2022-05-17 11:39 ` [PATCH 17/18] block: Reorganize some declarations in block-backend-io.h Alberto Faria
@ 2022-05-17 11:39 ` Alberto Faria
  2022-05-17 14:29   ` Paolo Bonzini
  2022-07-05  9:21   ` Hanna Reitz
  2022-07-02 14:12 ` [PATCH 00/18] Make block-backend-io.h API more consistent Paolo Bonzini
  18 siblings, 2 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-17 11:39 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz, Alberto Faria

Some can be made static, others are unused generated_co_wrappers.

Signed-off-by: Alberto Faria <afaria@redhat.com>
---
 block/block-backend.c |  6 +++---
 block/coroutines.h    | 19 -------------------
 2 files changed, 3 insertions(+), 22 deletions(-)

diff --git a/block/block-backend.c b/block/block-backend.c
index 920ba0dd1f..bf63f187ef 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1358,7 +1358,7 @@ int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset,
 }
 
 /* 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)
@@ -1691,7 +1691,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;
@@ -1739,7 +1739,7 @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset,
 }
 
 /* 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();
diff --git a/block/coroutines.h b/block/coroutines.h
index d66551a277..3a2bad564f 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -63,17 +63,6 @@ nbd_co_do_establish_connection(BlockDriverState *bs, bool blocking,
                                Error **errp);
 
 
-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_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.
@@ -82,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, int64_t bytes,
-            QEMUIOVector *qiov, BdrvRequestFlags flags);
-
-int generated_co_wrapper
-bdrv_pwritev(BdrvChild *child, int64_t offset, int64_t bytes,
-             QEMUIOVector *qiov, BdrvRequestFlags flags);
-
 int generated_co_wrapper
 bdrv_common_block_status_above(BlockDriverState *bs,
                                BlockDriverState *base,
-- 
2.35.3



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success
  2022-05-17 11:35 ` [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success Alberto Faria
@ 2022-05-17 14:03   ` Greg Kurz
  2022-05-18 12:57   ` Eric Blake
  2022-07-04 13:52   ` Hanna Reitz
  2 siblings, 0 replies; 64+ messages in thread
From: Greg Kurz @ 2022-05-17 14:03 UTC (permalink / raw)
  To: Alberto Faria
  Cc: qemu-devel, Andrew Jeffery, Peter Maydell, qemu-block,
	Palmer Dabbelt, Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, Hanna Reitz,
	John Snow, Stefan Hajnoczi, Jeff Cody, qemu-riscv,
	Cédric Le Goater, Joel Stanley, Stefan Weil, Laurent Vivier,
	Denis V. Lunev, Juan Quintela, Dr. David Alan Gilbert,
	Niek Linnenbank, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson

On Tue, 17 May 2022 12:35:07 +0100
Alberto Faria <afaria@redhat.com> wrote:

> They currently return the value of their 'bytes' parameter on success.
> 
> Make them return 0 instead, for consistency with other I/O functions and
> in preparation to implement them using generated_co_wrapper. This also
> makes it clear that short reads/writes are not possible.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>  block.c                          |  8 +++++---
>  block/block-backend.c            |  7 ++-----
>  block/qcow.c                     |  6 +++---
>  hw/block/m25p80.c                |  2 +-
>  hw/misc/mac_via.c                |  2 +-
>  hw/misc/sifive_u_otp.c           |  2 +-
>  hw/nvram/eeprom_at24c.c          |  4 ++--
>  hw/nvram/spapr_nvram.c           | 12 ++++++------
>  hw/ppc/pnv_pnor.c                |  2 +-

For PPC and sPAPR parts

Reviewed-by: Greg Kurz <groug@kaod.org>

>  qemu-img.c                       | 17 +++++++----------
>  qemu-io-cmds.c                   | 18 ++++++++++++------
>  tests/unit/test-block-iothread.c |  4 ++--
>  12 files changed, 43 insertions(+), 41 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 2c00dddd80..0fd830e2e2 100644
> --- a/block.c
> +++ b/block.c
> @@ -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;
>  }
>  
>  /**
> diff --git a/block/block-backend.c b/block/block-backend.c
> index e0e1aff4b1..c1c367bf9e 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -1577,19 +1577,16 @@ int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes)
>      ret = blk_do_preadv(blk, offset, bytes, &qiov, 0);
>      blk_dec_in_flight(blk);
>  
> -    return ret < 0 ? ret : bytes;
> +    return ret;
>  }
>  
>  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;
> +    return blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags);
>  }
>  
>  int64_t blk_getlength(BlockBackend *blk)
> diff --git a/block/qcow.c b/block/qcow.c
> index c646d6b16d..25a43353c1 100644
> --- a/block/qcow.c
> +++ b/block/qcow.c
> @@ -891,14 +891,14 @@ 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)) {
> +    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) {
> +        if (ret < 0) {
>              goto exit;
>          }
>      }
> @@ -908,7 +908,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOptions *opts,
>           i++) {
>          ret = blk_pwrite(qcow_blk, header_size + BDRV_SECTOR_SIZE * i,
>                           tmp, BDRV_SECTOR_SIZE, 0);
> -        if (ret != BDRV_SECTOR_SIZE) {
> +        if (ret < 0) {
>              g_free(tmp);
>              goto exit;
>          }
> diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
> index 7d3d8b12e0..bd58c07bb6 100644
> --- a/hw/block/m25p80.c
> +++ b/hw/block/m25p80.c
> @@ -1506,7 +1506,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->storage, s->size) < 0) {
>              error_setg(errp, "failed to read the initial flash content");
>              return;
>          }
> diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
> index 525e38ce93..0515d1818e 100644
> --- a/hw/misc/mac_via.c
> +++ b/hw/misc/mac_via.c
> @@ -1030,7 +1030,7 @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
>          }
>  
>          len = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM));
> -        if (len != sizeof(v1s->PRAM)) {
> +        if (len < 0) {
>              error_setg(errp, "can't read PRAM contents");
>              return;
>          }
> diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
> index 6d5f84e6c2..535acde08b 100644
> --- a/hw/misc/sifive_u_otp.c
> +++ b/hw/misc/sifive_u_otp.c
> @@ -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, s->fuse, filesize) < 0) {
>                  error_setg(errp, "failed to read the initial flash content");
>                  return;
>              }
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index 01a3093600..84acd71f5a 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -65,7 +65,7 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
>          DPRINTK("clear\n");
>          if (ee->blk && ee->changed) {
>              int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0);
> -            if (len != ee->rsize) {
> +            if (len < 0) {
>                  ERR(TYPE_AT24C_EE
>                          " : failed to write backing file\n");
>              }
> @@ -165,7 +165,7 @@ void at24c_eeprom_reset(DeviceState *state)
>      if (ee->blk) {
>          int len = blk_pread(ee->blk, 0, ee->mem, ee->rsize);
>  
> -        if (len != ee->rsize) {
> +        if (len < 0) {
>              ERR(TYPE_AT24C_EE
>                      " : Failed initial sync with backing file\n");
>          }
> diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
> index 18b43be7f6..6000b945c3 100644
> --- a/hw/nvram/spapr_nvram.c
> +++ b/hw/nvram/spapr_nvram.c
> @@ -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, membuf, len, 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)
> @@ -181,7 +181,7 @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp)
>      if (nvram->blk) {
>          int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);
>  
> -        if (alen != nvram->size) {
> +        if (alen < 0) {
>              error_setg(errp, "can't read spapr-nvram contents");
>              return;
>          }
> diff --git a/hw/ppc/pnv_pnor.c b/hw/ppc/pnv_pnor.c
> index 83ecccca28..1fb748afef 100644
> --- a/hw/ppc/pnv_pnor.c
> +++ b/hw/ppc/pnv_pnor.c
> @@ -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->storage, s->size) < 0) {
>              error_setg(errp, "failed to read the initial flash content");
>              return;
>          }
> diff --git a/qemu-img.c b/qemu-img.c
> index 4cf4d2423d..9d98ef63ac 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -5120,30 +5120,27 @@ 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_ret, out_ret;
>  
> -        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);
> -        }
> +        bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
> +
> +        in_ret = blk_pread(blk1, in_pos, in.buf, bytes);
>          if (in_ret < 0) {
>              error_report("error while reading from input image file: %s",
>                           strerror(-in_ret));
>              ret = -1;
>              goto out;
>          }
> -        in_pos += in_ret;
> -
> -        out_ret = blk_pwrite(blk2, out_pos, in.buf, in_ret, 0);
> +        in_pos += bytes;
>  
> +        out_ret = blk_pwrite(blk2, out_pos, in.buf, bytes, 0);
>          if (out_ret < 0) {
>              error_report("error while writing to output image file: %s",
>                           strerror(-out_ret));
>              ret = -1;
>              goto out;
>          }
> -        out_pos += out_ret;
> +        out_pos += bytes;
>      }
>  
>  out:
> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> index 2f0d8ac25a..443f22c732 100644
> --- a/qemu-io-cmds.c
> +++ b/qemu-io-cmds.c
> @@ -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, (uint8_t *)buf, bytes);
> +    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, (uint8_t *)buf, bytes, flags);
> +    if (ret < 0) {
> +        return ret;
>      }
> +    *total = bytes;
>      return 1;
>  }
>  
> diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
> index a5c163af7e..3c1a3f64a2 100644
> --- a/tests/unit/test-block-iothread.c
> +++ b/tests/unit/test-block-iothread.c
> @@ -117,7 +117,7 @@ static void test_sync_op_blk_pread(BlockBackend *blk)
>  
>      /* Success */
>      ret = blk_pread(blk, 0, buf, sizeof(buf));
> -    g_assert_cmpint(ret, ==, 512);
> +    g_assert_cmpint(ret, ==, 0);
>  
>      /* Early error: Negative offset */
>      ret = blk_pread(blk, -2, buf, sizeof(buf));
> @@ -131,7 +131,7 @@ static void test_sync_op_blk_pwrite(BlockBackend *blk)
>  
>      /* Success */
>      ret = blk_pwrite(blk, 0, buf, sizeof(buf), 0);
> -    g_assert_cmpint(ret, ==, 512);
> +    g_assert_cmpint(ret, ==, 0);
>  
>      /* Early error: Negative offset */
>      ret = blk_pwrite(blk, -2, buf, sizeof(buf), 0);



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 02/18] block: Add a 'flags' param to blk_pread()
  2022-05-17 11:35 ` [PATCH 02/18] block: Add a 'flags' param to blk_pread() Alberto Faria
@ 2022-05-17 14:19   ` Paolo Bonzini
  2022-05-17 16:26   ` Greg Kurz
  2022-07-04 14:04   ` Hanna Reitz
  2 siblings, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:19 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel
  Cc: Andrew Jeffery, Peter Maydell, qemu-block, Palmer Dabbelt,
	Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, Hanna Reitz,
	John Snow, Stefan Hajnoczi, Jeff Cody, qemu-riscv,
	Cédric Le Goater, Joel Stanley, Stefan Weil, Laurent Vivier,
	Denis V. Lunev, Juan Quintela, Dr. David Alan Gilbert,
	Niek Linnenbank, Greg Kurz, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson

On 5/17/22 13:35, Alberto Faria wrote:
> 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.

Whoa that's disgusting...

> Overly-long lines were then fixed by hand.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 04/18] block: Make 'bytes' param of blk_{pread, pwrite}() an int64_t
  2022-05-17 11:37 ` [PATCH 04/18] block: Make 'bytes' param of blk_{pread, pwrite}() an int64_t Alberto Faria
@ 2022-05-17 14:20   ` Paolo Bonzini
  2022-07-04 15:24   ` [PATCH 04/18] block: Make 'bytes' param of blk_{pread,pwrite}() " Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:20 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: qemu-block, Hanna Reitz, Kevin Wolf

On 5/17/22 13:37, Alberto Faria wrote:
> For consistency with other I/O functions, and in preparation to
> implement them using generated_co_wrapper.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 6 +++---
>   include/sysemu/block-backend-io.h | 6 +++---
>   2 files changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 05/18] block: Make blk_co_pwrite() take a const buffer
  2022-05-17 11:38 ` [PATCH 05/18] block: Make blk_co_pwrite() take a const buffer Alberto Faria
@ 2022-05-17 14:20   ` Paolo Bonzini
  2022-07-04 15:25   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:20 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block

On 5/17/22 13:38, Alberto Faria wrote:
> It does not mutate the buffer.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   include/sysemu/block-backend-io.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

> diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
> index 6630316795..6440e92028 100644
> --- a/include/sysemu/block-backend-io.h
> +++ b/include/sysemu/block-backend-io.h
> @@ -130,7 +130,7 @@ static inline int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset,
>   }
>   
>   static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset,
> -                                             int64_t bytes, void *buf,
> +                                             int64_t bytes, const void *buf,
>                                                BdrvRequestFlags flags)
>   {
>       QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 06/18] block: Implement blk_{pread, pwrite}() using generated_co_wrapper
  2022-05-17 11:38 ` [PATCH 06/18] block: Implement blk_{pread, pwrite}() using generated_co_wrapper Alberto Faria
@ 2022-05-17 14:22   ` Paolo Bonzini
  2022-05-18 13:34     ` Emanuele Giuseppe Esposito
  2022-07-04 15:30   ` [PATCH 06/18] block: Implement blk_{pread,pwrite}() " Hanna Reitz
  1 sibling, 1 reply; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:22 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel, Emanuele Giuseppe Esposito
  Cc: Hanna Reitz, Kevin Wolf, qemu-block

On 5/17/22 13:38, Alberto Faria wrote:
> We need to add include/sysemu/block-backend-io.h to the inputs of the
> block-gen.c target defined in block/meson.build.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>

Emanuele is looking it cleaning this up, so you two need to coordinate.

Emanuele, can you separate/post the initial patches to clean up the 
includes of block/coroutines.h and block/block-gen.c?

Apart from that, fewer block/coroutines.h declarations is only good stuff.

Thanks,

Paolo

> ---
>   block/block-backend.c             | 23 -----------------------
>   block/coroutines.h                |  4 ----
>   block/meson.build                 |  1 +
>   include/sysemu/block-backend-io.h | 10 ++++++----
>   4 files changed, 7 insertions(+), 31 deletions(-)
> 
> diff --git a/block/block-backend.c b/block/block-backend.c
> index 5b9706c443..c2a4c44a99 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -1567,29 +1567,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, int64_t bytes, void *buf,
> -              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, flags);
> -    blk_dec_in_flight(blk);
> -
> -    return ret;
> -}
> -
> -int blk_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();
> -
> -    return blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags);
> -}
> -
>   int64_t blk_getlength(BlockBackend *blk)
>   {
>       IO_CODE();
> diff --git a/block/coroutines.h b/block/coroutines.h
> index 3f41238b33..443ef2f2e6 100644
> --- a/block/coroutines.h
> +++ b/block/coroutines.h
> @@ -112,10 +112,6 @@ 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,
> diff --git a/block/meson.build b/block/meson.build
> index 0b2a60c99b..60bc305597 100644
> --- a/block/meson.build
> +++ b/block/meson.build
> @@ -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@'])
> diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
> index 6440e92028..0804ce1c1d 100644
> --- a/include/sysemu/block-backend-io.h
> +++ b/include/sysemu/block-backend-io.h
> @@ -102,10 +102,12 @@ 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, int64_t bytes, void *buf,
> -              BdrvRequestFlags flags);
> -int blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes,
> -               const void *buf, BdrvRequestFlags flags);
> +int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset,
> +                                   int64_t bytes, void *buf,
> +                                   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_preadv(BlockBackend *blk, int64_t offset,
>                                  int64_t bytes, QEMUIOVector *qiov,
>                                  BdrvRequestFlags flags);



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 10/18] block: Change blk_pwrite_compressed() param order
  2022-05-17 11:38 ` [PATCH 10/18] block: Change blk_pwrite_compressed() param order Alberto Faria
@ 2022-05-17 14:25   ` Paolo Bonzini
  2022-07-05  8:29   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:25 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block

On 5/17/22 13:38, Alberto Faria wrote:
> Swap 'buf' and 'bytes' around for consistency with other I/O functions.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

> ---
>   block/block-backend.c             | 4 ++--
>   include/sysemu/block-backend-io.h | 4 ++--
>   qemu-img.c                        | 2 +-
>   qemu-io-cmds.c                    | 2 +-
>   4 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/block/block-backend.c b/block/block-backend.c
> index 35bf35aadd..ddb1d4e179 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -2324,8 +2324,8 @@ 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 blk_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();
> diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
> index 31ebd8b6cf..c64207cdcb 100644
> --- a/include/sysemu/block-backend-io.h
> +++ b/include/sysemu/block-backend-io.h
> @@ -168,8 +168,8 @@ int blk_flush(BlockBackend *blk);
>   
>   int blk_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_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes,
> +                          const void *buf);
>   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);
> diff --git a/qemu-img.c b/qemu-img.c
> index 8d214e649e..52f3aeed9b 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -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;
>           }
> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> index c8cbaed0cd..952dc940f1 100644
> --- a/qemu-io-cmds.c
> +++ b/qemu-io-cmds.c
> @@ -631,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;
>       }



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 11/18] block: Add blk_co_pwrite_compressed()
  2022-05-17 11:38 ` [PATCH 11/18] block: Add blk_co_pwrite_compressed() Alberto Faria
@ 2022-05-17 14:26   ` Paolo Bonzini
  2022-07-05  8:45   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:26 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block

On 5/17/22 13:38, Alberto Faria wrote:
> Also convert blk_pwrite_compressed() into a generated_co_wrapper.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 12/18] block: Implement blk_pwrite_zeroes() using generated_co_wrapper
  2022-05-17 11:39 ` [PATCH 12/18] block: Implement blk_pwrite_zeroes() using generated_co_wrapper Alberto Faria
@ 2022-05-17 14:26   ` Paolo Bonzini
  2022-07-05  8:48   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:26 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz

On 5/17/22 13:39, Alberto Faria wrote:
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             |  8 --------
>   include/sysemu/block-backend-io.h |  5 +++--
>   tests/unit/test-block-iothread.c  | 17 +++++++++++++++++
>   3 files changed, 20 insertions(+), 10 deletions(-)

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 13/18] block: Implement blk_pdiscard() using generated_co_wrapper
  2022-05-17 11:39 ` [PATCH 13/18] block: Implement blk_pdiscard() " Alberto Faria
@ 2022-05-17 14:27   ` Paolo Bonzini
  2022-07-05  8:51   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:27 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz

On 5/17/22 13:39, Alberto Faria wrote:
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 12 ------------
>   block/coroutines.h                |  3 ---
>   include/sysemu/block-backend-io.h |  3 ++-
>   3 files changed, 2 insertions(+), 16 deletions(-)


Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 14/18] block: Implement blk_flush() using generated_co_wrapper
  2022-05-17 11:39 ` [PATCH 14/18] block: Implement blk_flush() " Alberto Faria
@ 2022-05-17 14:27   ` Paolo Bonzini
  2022-07-05  8:56   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:27 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz

On 5/17/22 13:39, Alberto Faria wrote:
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 11 -----------
>   block/coroutines.h                |  2 --
>   include/sysemu/block-backend-io.h |  2 +-
>   3 files changed, 1 insertion(+), 14 deletions(-)

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 15/18] block: Add blk_co_ioctl()
  2022-05-17 11:39 ` [PATCH 15/18] block: Add blk_co_ioctl() Alberto Faria
@ 2022-05-17 14:28   ` Paolo Bonzini
  2022-07-05  9:02   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:28 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz

On 5/17/22 13:39, Alberto Faria wrote:
> Also convert blk_ioctl() into a generated_co_wrapper.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 7 ++++---
>   block/coroutines.h                | 6 ------
>   include/sysemu/block-backend-io.h | 5 ++++-
>   3 files changed, 8 insertions(+), 10 deletions(-)

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 16/18] block: Add blk_co_truncate()
  2022-05-17 11:39 ` [PATCH 16/18] block: Add blk_co_truncate() Alberto Faria
@ 2022-05-17 14:28   ` Paolo Bonzini
  2022-07-05  9:08   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:28 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz

On 5/17/22 13:39, Alberto Faria wrote:
> Also convert blk_truncate() into a generated_co_wrapper.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             |  7 ++++---
>   include/sysemu/block-backend-io.h |  8 ++++++--
>   tests/unit/test-block-iothread.c  | 14 ++++++++++++++
>   3 files changed, 24 insertions(+), 5 deletions(-)

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 17/18] block: Reorganize some declarations in block-backend-io.h
  2022-05-17 11:39 ` [PATCH 17/18] block: Reorganize some declarations in block-backend-io.h Alberto Faria
@ 2022-05-17 14:29   ` Paolo Bonzini
  2022-07-05  9:18   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:29 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz

On 5/17/22 13:39, Alberto Faria wrote:
> Keep generated_co_wrapper and coroutine_fn pairs together. This should
> make it clear that each I/O function has these two versions.
> 
> Also move blk_co_{pread,pwrite}()'s implementations out of the header
> file for consistency.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

> ---
>   block/block-backend.c             | 22 ++++++++
>   include/sysemu/block-backend-io.h | 87 +++++++++++++------------------
>   2 files changed, 59 insertions(+), 50 deletions(-)
> 
> diff --git a/block/block-backend.c b/block/block-backend.c
> index 52be1d9116..920ba0dd1f 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -1318,6 +1318,17 @@ blk_co_do_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes,
>       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)
> @@ -1399,6 +1410,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)
> diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
> index 004493ec36..30ed979fb1 100644
> --- a/include/sysemu/block-backend-io.h
> +++ b/include/sysemu/block-backend-io.h
> @@ -88,11 +88,6 @@ uint32_t blk_get_request_alignment(BlockBackend *blk);
>   uint32_t blk_get_max_transfer(BlockBackend *blk);
>   uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
>   
> -int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
> -                                   BlockBackend *blk_out, int64_t off_out,
> -                                   int64_t bytes, BdrvRequestFlags read_flags,
> -                                   BdrvRequestFlags write_flags);
> -
>   
>   /*
>    * "I/O or GS" API functions. These functions can run without
> @@ -105,9 +100,16 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
>   int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset,
>                                      int64_t bytes, void *buf,
>                                      BdrvRequestFlags flags);
> -int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset,
> -                                    int64_t bytes, const void *buf,
> +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 generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset,
>                                            int64_t bytes, QEMUIOVector *qiov,
>                                            size_t qiov_offset,
> @@ -115,12 +117,20 @@ int generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset,
>   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_preadv(BlockBackend *blk, int64_t offset,
> -                                    int64_t bytes, QEMUIOVector *qiov,
> +
> +int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset,
> +                                    int64_t bytes, const void *buf,
>                                       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_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);
> +
>   int generated_co_wrapper blk_pwritev_part(BlockBackend *blk, int64_t offset,
>                                             int64_t bytes, QEMUIOVector *qiov,
>                                             size_t qiov_offset,
> @@ -129,36 +139,18 @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
>                                        int64_t bytes,
>                                        QEMUIOVector *qiov, size_t qiov_offset,
>                                        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();
>   
> -    assert(bytes <= SIZE_MAX);
> -
> -    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, const void *buf,
> -                                             BdrvRequestFlags flags)
> -{
> -    QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes);
> -    IO_OR_GS_CODE();
> -
> -    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_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);
> @@ -173,16 +165,6 @@ int generated_co_wrapper blk_ioctl(BlockBackend *blk, unsigned long int req,
>   int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req,
>                                 void *buf);
>   
> -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);
> -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_truncate(BlockBackend *blk, int64_t offset,
>                                         bool exact, PreallocMode prealloc,
>                                         BdrvRequestFlags flags, Error **errp);
> @@ -190,4 +172,9 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact,
>                                    PreallocMode prealloc, BdrvRequestFlags flags,
>                                    Error **errp);
>   
> +int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
> +                                   BlockBackend *blk_out, int64_t off_out,
> +                                   int64_t bytes, BdrvRequestFlags read_flags,
> +                                   BdrvRequestFlags write_flags);
> +
>   #endif /* BLOCK_BACKEND_IO_H */



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 18/18] block: Remove remaining unused symbols in coroutines.h
  2022-05-17 11:39 ` [PATCH 18/18] block: Remove remaining unused symbols in coroutines.h Alberto Faria
@ 2022-05-17 14:29   ` Paolo Bonzini
  2022-07-05  9:21   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:29 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block, Hanna Reitz

On 5/17/22 13:39, Alberto Faria wrote:
> Some can be made static, others are unused generated_co_wrappers.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c |  6 +++---
>   block/coroutines.h    | 19 -------------------
>   2 files changed, 3 insertions(+), 22 deletions(-)


Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 08/18] block: Add blk_[co_]preadv_part()
  2022-05-17 11:38 ` [PATCH 08/18] block: Add blk_[co_]preadv_part() Alberto Faria
@ 2022-05-17 14:30   ` Paolo Bonzini
  2022-07-05  8:15   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:30 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block

On 5/17/22 13:38, Alberto Faria wrote:
> Implement blk_preadv_part() using generated_co_wrapper.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 30 +++++++++++++++++++++++-------
>   block/coroutines.h                |  5 -----
>   include/sysemu/block-backend-io.h |  7 +++++++
>   tests/unit/test-block-iothread.c  | 19 +++++++++++++++++++
>   4 files changed, 49 insertions(+), 12 deletions(-)

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

> diff --git a/block/block-backend.c b/block/block-backend.c
> index c2a4c44a99..3920e1f45e 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -1284,9 +1284,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;
> @@ -1311,7 +1312,8 @@ 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;
>   }
> @@ -1324,7 +1326,21 @@ 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;
> @@ -1541,8 +1557,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);
>   }
>   
> diff --git a/block/coroutines.h b/block/coroutines.h
> index 443ef2f2e6..85423f8db6 100644
> --- a/block/coroutines.h
> +++ b/block/coroutines.h
> @@ -63,11 +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,
> diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
> index 3b548a8ae1..29954a466c 100644
> --- a/include/sysemu/block-backend-io.h
> +++ b/include/sysemu/block-backend-io.h
> @@ -108,6 +108,13 @@ int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset,
>   int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset,
>                                       int64_t bytes, const void *buf,
>                                       BdrvRequestFlags flags);
> +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_preadv(BlockBackend *blk, int64_t offset,
>                                       int64_t bytes, QEMUIOVector *qiov,
>                                       BdrvRequestFlags flags);
> diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
> index b9c5da3a87..2fa1248445 100644
> --- a/tests/unit/test-block-iothread.c
> +++ b/tests/unit/test-block-iothread.c
> @@ -168,6 +168,21 @@ static void test_sync_op_blk_pwritev(BlockBackend *blk)
>       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_load_vmstate(BdrvChild *c)
>   {
>       uint8_t buf[512];
> @@ -339,6 +354,10 @@ const SyncOpTest sync_op_tests[] = {
>           .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/load_vmstate",
>           .fn     = test_sync_op_load_vmstate,



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 09/18] block: Export blk_pwritev_part() in block-backend-io.h
  2022-05-17 11:38 ` [PATCH 09/18] block: Export blk_pwritev_part() in block-backend-io.h Alberto Faria
@ 2022-05-17 14:30   ` Paolo Bonzini
  2022-07-05  8:24   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:30 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block

On 5/17/22 13:38, Alberto Faria wrote:
> Also convert it into a generated_co_wrapper.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 14 --------------
>   block/coroutines.h                |  5 -----
>   include/sysemu/block-backend-io.h |  4 ++++
>   tests/unit/test-block-iothread.c  | 19 +++++++++++++++++++
>   4 files changed, 23 insertions(+), 19 deletions(-)


Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 07/18] block: Add blk_{preadv,pwritev}()
  2022-05-17 11:38 ` [PATCH 07/18] block: Add blk_{preadv,pwritev}() Alberto Faria
@ 2022-05-17 14:35   ` Paolo Bonzini
  2022-07-05  7:55   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-17 14:35 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Hanna Reitz, Kevin Wolf, qemu-block

On 5/17/22 13:38, Alberto Faria wrote:
> Implement them using generated_co_wrapper.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   include/sysemu/block-backend-io.h |  6 +++++
>   tests/unit/test-block-iothread.c  | 42 ++++++++++++++++++++++++++++++-
>   2 files changed, 47 insertions(+), 1 deletion(-)

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>

> diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
> index 0804ce1c1d..3b548a8ae1 100644
> --- a/include/sysemu/block-backend-io.h
> +++ b/include/sysemu/block-backend-io.h
> @@ -108,6 +108,9 @@ int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset,
>   int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset,
>                                       int64_t bytes, const 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);
> @@ -115,6 +118,9 @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset,
>                                        int64_t bytes,
>                                        QEMUIOVector *qiov, size_t qiov_offset,
>                                        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);
> diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
> index 0ced5333ff..b9c5da3a87 100644
> --- a/tests/unit/test-block-iothread.c
> +++ b/tests/unit/test-block-iothread.c
> @@ -138,6 +138,36 @@ static void test_sync_op_blk_pwrite(BlockBackend *blk)
>       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_load_vmstate(BdrvChild *c)
>   {
>       uint8_t buf[512];
> @@ -301,6 +331,14 @@ 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/load_vmstate",
>           .fn     = test_sync_op_load_vmstate,
> @@ -349,7 +387,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);
>       }



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 02/18] block: Add a 'flags' param to blk_pread()
  2022-05-17 11:35 ` [PATCH 02/18] block: Add a 'flags' param to blk_pread() Alberto Faria
  2022-05-17 14:19   ` Paolo Bonzini
@ 2022-05-17 16:26   ` Greg Kurz
  2022-07-04 14:04   ` Hanna Reitz
  2 siblings, 0 replies; 64+ messages in thread
From: Greg Kurz @ 2022-05-17 16:26 UTC (permalink / raw)
  To: Alberto Faria
  Cc: qemu-devel, Andrew Jeffery, Peter Maydell, qemu-block,
	Palmer Dabbelt, Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, Hanna Reitz,
	John Snow, Stefan Hajnoczi, Jeff Cody, qemu-riscv,
	Cédric Le Goater, Joel Stanley, Stefan Weil, Laurent Vivier,
	Denis V. Lunev, Juan Quintela, Dr. David Alan Gilbert,
	Niek Linnenbank, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson

On Tue, 17 May 2022 12:35:08 +0100
Alberto Faria <afaria@redhat.com> wrote:

> 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: Greg Kurz <groug@kaod.org>

>  block.c                           |  2 +-
>  block/block-backend.c             |  5 +++--
>  block/commit.c                    |  2 +-
>  block/export/fuse.c               |  2 +-
>  hw/arm/allwinner-h3.c             |  2 +-
>  hw/arm/aspeed.c                   |  2 +-
>  hw/block/block.c                  |  2 +-
>  hw/block/fdc.c                    |  6 +++---
>  hw/block/hd-geometry.c            |  2 +-
>  hw/block/m25p80.c                 |  2 +-
>  hw/block/nand.c                   | 12 ++++++------
>  hw/block/onenand.c                | 12 ++++++------
>  hw/ide/atapi.c                    |  4 ++--
>  hw/misc/mac_via.c                 |  2 +-
>  hw/misc/sifive_u_otp.c            |  4 ++--
>  hw/nvram/eeprom_at24c.c           |  2 +-
>  hw/nvram/spapr_nvram.c            |  2 +-
>  hw/nvram/xlnx-bbram.c             |  2 +-
>  hw/nvram/xlnx-efuse.c             |  2 +-
>  hw/ppc/pnv_pnor.c                 |  2 +-
>  hw/sd/sd.c                        |  2 +-
>  include/sysemu/block-backend-io.h |  3 ++-
>  migration/block.c                 |  4 ++--
>  nbd/server.c                      |  4 ++--
>  qemu-img.c                        | 12 ++++++------
>  qemu-io-cmds.c                    |  2 +-
>  tests/unit/test-block-iothread.c  |  4 ++--
>  27 files changed, 52 insertions(+), 50 deletions(-)
> 
> diff --git a/block.c b/block.c
> index 0fd830e2e2..ed701b4889 100644
> --- a/block.c
> +++ b/block.c
> @@ -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");
> diff --git a/block/block-backend.c b/block/block-backend.c
> index c1c367bf9e..da89450861 100644
> --- a/block/block-backend.c
> +++ b/block/block-backend.c
> @@ -1567,14 +1567,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;
> diff --git a/block/commit.c b/block/commit.c
> index 851d1c557a..e5b3ad08da 100644
> --- a/block/commit.c
> +++ b/block/commit.c
> @@ -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;
>              }
> diff --git a/block/export/fuse.c b/block/export/fuse.c
> index e80b24a867..dcf8f225f3 100644
> --- a/block/export/fuse.c
> +++ b/block/export/fuse.c
> @@ -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 {
> diff --git a/hw/arm/allwinner-h3.c b/hw/arm/allwinner-h3.c
> index 318ed4348c..788083b6fa 100644
> --- a/hw/arm/allwinner-h3.c
> +++ b/hw/arm/allwinner-h3.c
> @@ -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;
> diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c
> index a74c13ab0f..06ab8cd0a5 100644
> --- a/hw/arm/aspeed.c
> +++ b/hw/arm/aspeed.c
> @@ -269,7 +269,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;
>      }
> diff --git a/hw/block/block.c b/hw/block/block.c
> index 25f45df723..effb89910c 100644
> --- a/hw/block/block.c
> +++ b/hw/block/block.c
> @@ -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;
> diff --git a/hw/block/fdc.c b/hw/block/fdc.c
> index 57bb355794..52f278ed82 100644
> --- a/hw/block/fdc.c
> +++ b/hw/block/fdc.c
> @@ -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));
> diff --git a/hw/block/hd-geometry.c b/hw/block/hd-geometry.c
> index dcbccee294..24933eae82 100644
> --- a/hw/block/hd-geometry.c
> +++ b/hw/block/hd-geometry.c
> @@ -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 */
> diff --git a/hw/block/m25p80.c b/hw/block/m25p80.c
> index bd58c07bb6..3e93769fed 100644
> --- a/hw/block/m25p80.c
> +++ b/hw/block/m25p80.c
> @@ -1506,7 +1506,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;
>          }
> diff --git a/hw/block/nand.c b/hw/block/nand.c
> index 8bc80e3514..ea3d33adf4 100644
> --- a/hw/block/nand.c
> +++ b/hw/block/nand.c
> @@ -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);
>              }
> diff --git a/hw/block/onenand.c b/hw/block/onenand.c
> index afc0cd3a0f..1225ec8076 100644
> --- a/hw/block/onenand.c
> +++ b/hw/block/onenand.c
> @@ -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);
> diff --git a/hw/ide/atapi.c b/hw/ide/atapi.c
> index b626199e3d..7e405657df 100644
> --- a/hw/ide/atapi.c
> +++ b/hw/ide/atapi.c
> @@ -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);
>          }
> diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
> index 0515d1818e..d259def2d2 100644
> --- a/hw/misc/mac_via.c
> +++ b/hw/misc/mac_via.c
> @@ -1029,7 +1029,7 @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
>              return;
>          }
>  
> -        len = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM));
> +        len = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM), 0);
>          if (len < 0) {
>              error_setg(errp, "can't read PRAM contents");
>              return;
> diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
> index 535acde08b..c730bb1ae0 100644
> --- a/hw/misc/sifive_u_otp.c
> +++ b/hw/misc/sifive_u_otp.c
> @@ -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;
>              }
> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index 84acd71f5a..876b3dd5dc 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -163,7 +163,7 @@ 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 len = blk_pread(ee->blk, 0, ee->mem, ee->rsize, 0);
>  
>          if (len < 0) {
>              ERR(TYPE_AT24C_EE
> diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
> index 6000b945c3..4d32d92ad4 100644
> --- a/hw/nvram/spapr_nvram.c
> +++ b/hw/nvram/spapr_nvram.c
> @@ -179,7 +179,7 @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp)
>      }
>  
>      if (nvram->blk) {
> -        int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);
> +        int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size, 0);
>  
>          if (alen < 0) {
>              error_setg(errp, "can't read spapr-nvram contents");
> diff --git a/hw/nvram/xlnx-bbram.c b/hw/nvram/xlnx-bbram.c
> index 6ed32adad9..cb245b864c 100644
> --- a/hw/nvram/xlnx-bbram.c
> +++ b/hw/nvram/xlnx-bbram.c
> @@ -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);
> diff --git a/hw/nvram/xlnx-efuse.c b/hw/nvram/xlnx-efuse.c
> index a0fd77b586..edaac9cf7c 100644
> --- a/hw/nvram/xlnx-efuse.c
> +++ b/hw/nvram/xlnx-efuse.c
> @@ -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;
> diff --git a/hw/ppc/pnv_pnor.c b/hw/ppc/pnv_pnor.c
> index 1fb748afef..f341f5a9c9 100644
> --- a/hw/ppc/pnv_pnor.c
> +++ b/hw/ppc/pnv_pnor.c
> @@ -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;
>          }
> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
> index 8e6fa09151..701170bf37 100644
> --- a/hw/sd/sd.c
> +++ b/hw/sd/sd.c
> @@ -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");
>      }
>  }
> diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
> index 6517c39295..288bf39be1 100644
> --- a/include/sysemu/block-backend-io.h
> +++ b/include/sysemu/block-backend-io.h
> @@ -102,7 +102,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,
> diff --git a/migration/block.c b/migration/block.c
> index 077a413325..fa216af025 100644
> --- a/migration/block.c
> +++ b/migration/block.c
> @@ -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;
>                  }
> diff --git a/nbd/server.c b/nbd/server.c
> index 213e00e761..849433aa3a 100644
> --- a/nbd/server.c
> +++ b/nbd/server.c
> @@ -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);
> diff --git a/qemu-img.c b/qemu-img.c
> index 9d98ef63ac..edec9e4097 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -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;
> @@ -5124,7 +5124,7 @@ static int img_dd(int argc, char **argv)
>  
>          bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
>  
> -        in_ret = blk_pread(blk1, in_pos, in.buf, bytes);
> +        in_ret = blk_pread(blk1, in_pos, in.buf, bytes, 0);
>          if (in_ret < 0) {
>              error_report("error while reading from input image file: %s",
>                           strerror(-in_ret));
> diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
> index 443f22c732..582e1a7090 100644
> --- a/qemu-io-cmds.c
> +++ b/qemu-io-cmds.c
> @@ -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;
>      }
> diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
> index 3c1a3f64a2..bfd12c9c15 100644
> --- a/tests/unit/test-block-iothread.c
> +++ b/tests/unit/test-block-iothread.c
> @@ -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);
>  }
>  



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success
  2022-05-17 11:35 ` [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success Alberto Faria
  2022-05-17 14:03   ` Greg Kurz
@ 2022-05-18 12:57   ` Eric Blake
  2022-07-04 13:52   ` Hanna Reitz
  2 siblings, 0 replies; 64+ messages in thread
From: Eric Blake @ 2022-05-18 12:57 UTC (permalink / raw)
  To: Alberto Faria
  Cc: qemu-devel, Andrew Jeffery, Peter Maydell, qemu-block,
	Palmer Dabbelt, Philippe Mathieu-Daudé,
	qemu-ppc, Vladimir Sementsov-Ogievskiy, Hanna Reitz, John Snow,
	Stefan Hajnoczi, Jeff Cody, qemu-riscv, Cédric Le Goater,
	Joel Stanley, Stefan Weil, Laurent Vivier, Denis V. Lunev,
	Juan Quintela, Dr. David Alan Gilbert, Niek Linnenbank,
	Greg Kurz, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson

On Tue, May 17, 2022 at 12:35:07PM +0100, Alberto Faria wrote:
> They currently return the value of their 'bytes' parameter on success.
> 
> Make them return 0 instead, for consistency with other I/O functions and
> in preparation to implement them using generated_co_wrapper. This also
> makes it clear that short reads/writes are not possible.
> 
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---

> +++ b/qemu-img.c
> @@ -5120,30 +5120,27 @@ 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++) {

in_pos, out_pos, and size are int64_t...

> -        int in_ret, out_ret;
> +        int bytes, in_ret, out_ret;
>  
> -        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);
> -        }
> +        bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;

...but in.bsz is int, so declaring 'int bytes' appears safe.

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 06/18] block: Implement blk_{pread, pwrite}() using generated_co_wrapper
  2022-05-17 14:22   ` Paolo Bonzini
@ 2022-05-18 13:34     ` Emanuele Giuseppe Esposito
  2022-05-18 14:02       ` Paolo Bonzini
  2022-05-19 13:25       ` Alberto Faria
  0 siblings, 2 replies; 64+ messages in thread
From: Emanuele Giuseppe Esposito @ 2022-05-18 13:34 UTC (permalink / raw)
  To: Paolo Bonzini, Alberto Faria, qemu-devel
  Cc: Hanna Reitz, Kevin Wolf, qemu-block



Am 17/05/2022 um 16:22 schrieb Paolo Bonzini:
> On 5/17/22 13:38, Alberto Faria wrote:
>> We need to add include/sysemu/block-backend-io.h to the inputs of the
>> block-gen.c target defined in block/meson.build.
>>
>> Signed-off-by: Alberto Faria <afaria@redhat.com>
> 
> Emanuele is looking it cleaning this up, so you two need to coordinate.
> 
> Emanuele, can you separate/post the initial patches to clean up the
> includes of block/coroutines.h and block/block-gen.c?
> 
> Apart from that, fewer block/coroutines.h declarations is only good stuff.
> 

This is the main patch: it just moves headers from block/coroutines.h to
the script (block_gen.c).

This allows you to keep generated_co_wrapper functions in the header
where they originally were (no need to move the function in coroutines.h
and include it everywhere).

Btw @Alberto can you also cc me in the next series? So that I can follow
too.

Thank you,
Emanuele

From 84fcea52c09024adcfe24bb0d6d2ec6842c6826b Mon Sep 17 00:00:00 2001
From: Emanuele Giuseppe Esposito <eesposit@redhat.com>
Date: Tue, 17 May 2022 13:35:54 -0400
Subject: [PATCH] block-coroutine-wrapper: remove includes from coroutines.h

These includes in coroutines.h are not needed. Instead, they can
be moved in block-gen.c since they are needed by the generated
functions.

Signed-off-by: Emanuele Giuseppe Esposito <eesposit@redhat.com>
---
 block/coroutines.h                 | 5 -----
 scripts/block-coroutine-wrapper.py | 3 +++
 2 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/block/coroutines.h b/block/coroutines.h
index b293e943c8..45ecbfcc6a 100644
--- a/block/coroutines.h
+++ b/block/coroutines.h
@@ -25,11 +25,6 @@
 #ifndef BLOCK_COROUTINES_INT_H
 #define BLOCK_COROUTINES_INT_H

-#include "block/block_int.h"
-
-/* For blk_bs() in generated block/block-gen.c */
-#include "sysemu/block-backend.h"
-
 /*
  * I/O API functions. These functions are thread-safe.
  *
diff --git a/scripts/block-coroutine-wrapper.py
b/scripts/block-coroutine-wrapper.py
index 625b03e3ab..39fb1e8a4f 100644
--- a/scripts/block-coroutine-wrapper.py
+++ b/scripts/block-coroutine-wrapper.py
@@ -40,6 +40,9 @@ def gen_header():
  */

 #include "qemu/osdep.h"
+/* For blk_bs() in generated block/block-gen.c */
+#include "sysemu/block-backend.h"
+#include "block/block_int.h"
 #include "block/coroutines.h"
 #include "block/block-gen.h"
 #include "block/block_int.h"\
-- 
2.31.1

>> ---
>>   block/block-backend.c             | 23 -----------------------
>>   block/coroutines.h                |  4 ----
>>   block/meson.build                 |  1 +
>>   include/sysemu/block-backend-io.h | 10 ++++++----
>>   4 files changed, 7 insertions(+), 31 deletions(-)
>>
>> diff --git a/block/block-backend.c b/block/block-backend.c
>> index 5b9706c443..c2a4c44a99 100644
>> --- a/block/block-backend.c
>> +++ b/block/block-backend.c
>> @@ -1567,29 +1567,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, int64_t bytes,
>> void *buf,
>> -              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, flags);
>> -    blk_dec_in_flight(blk);
>> -
>> -    return ret;
>> -}
>> -
>> -int blk_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();
>> -
>> -    return blk_pwritev_part(blk, offset, bytes, &qiov, 0, flags);
>> -}
>> -
>>   int64_t blk_getlength(BlockBackend *blk)
>>   {
>>       IO_CODE();
>> diff --git a/block/coroutines.h b/block/coroutines.h
>> index 3f41238b33..443ef2f2e6 100644
>> --- a/block/coroutines.h
>> +++ b/block/coroutines.h
>> @@ -112,10 +112,6 @@ 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,
>> diff --git a/block/meson.build b/block/meson.build
>> index 0b2a60c99b..60bc305597 100644
>> --- a/block/meson.build
>> +++ b/block/meson.build
>> @@ -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@'])
>> diff --git a/include/sysemu/block-backend-io.h
>> b/include/sysemu/block-backend-io.h
>> index 6440e92028..0804ce1c1d 100644
>> --- a/include/sysemu/block-backend-io.h
>> +++ b/include/sysemu/block-backend-io.h
>> @@ -102,10 +102,12 @@ 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, int64_t bytes,
>> void *buf,
>> -              BdrvRequestFlags flags);
>> -int blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes,
>> -               const void *buf, BdrvRequestFlags flags);
>> +int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset,
>> +                                   int64_t bytes, void *buf,
>> +                                   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_preadv(BlockBackend *blk, int64_t offset,
>>                                  int64_t bytes, QEMUIOVector *qiov,
>>                                  BdrvRequestFlags flags);
> 



^ permalink raw reply related	[flat|nested] 64+ messages in thread

* Re: [PATCH 06/18] block: Implement blk_{pread, pwrite}() using generated_co_wrapper
  2022-05-18 13:34     ` Emanuele Giuseppe Esposito
@ 2022-05-18 14:02       ` Paolo Bonzini
  2022-05-19 13:25       ` Alberto Faria
  1 sibling, 0 replies; 64+ messages in thread
From: Paolo Bonzini @ 2022-05-18 14:02 UTC (permalink / raw)
  To: Emanuele Giuseppe Esposito, Alberto Faria, qemu-devel
  Cc: Hanna Reitz, Kevin Wolf, qemu-block

On 5/18/22 15:34, Emanuele Giuseppe Esposito wrote:
> +/* For blk_bs() in generated block/block-gen.c */
> +#include "sysemu/block-backend.h"
> +#include "block/block_int.h"
>   #include "block/coroutines.h"
>   #include "block/block-gen.h"
>   #include "block/block_int.h"\

This second include of block_int.h is unnecessary.

Paolo


^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 03/18] block: Change blk_{pread,pwrite}() param order
  2022-05-17 11:37 ` [PATCH 03/18] block: Change blk_{pread,pwrite}() param order Alberto Faria
@ 2022-05-18 14:05   ` Eric Blake
  2022-07-04 15:21   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Eric Blake @ 2022-05-18 14:05 UTC (permalink / raw)
  To: Alberto Faria
  Cc: qemu-devel, John Snow, Stefan Weil, Andrew Jeffery,
	Beniamino Galvani, qemu-block, Fam Zheng, Niek Linnenbank,
	Dr. David Alan Gilbert, Kevin Wolf, Stefan Hajnoczi,
	Alistair Francis, Philippe Mathieu-Daudé,
	qemu-arm, qemu-riscv, Jeff Cody, Daniel Henrique Barboza,
	Cédric Le Goater, Edgar E. Iglesias, Juan Quintela,
	Joel Stanley, Peter Maydell, Laurent Vivier, Bin Meng, Greg Kurz,
	Vladimir Sementsov-Ogievskiy, Hanna Reitz, qemu-ppc,
	Palmer Dabbelt, David Gibson, Denis V. Lunev

On Tue, May 17, 2022 at 12:37:31PM +0100, Alberto Faria wrote:
> Swap 'buf' and 'bytes' around for consistency with
> blk_co_{pread,pwrite}(), and in preparation to implement these functions
> using generated_co_wrapper.
> 
> Callers were updated using this Coccinelle script:
> 
>     @@ expression blk, offset, buf, bytes, flags; @@
>     - blk_pread(blk, offset, buf, bytes, flags)
>     + blk_pread(blk, offset, bytes, buf, flags)
> 
>     @@ expression blk, offset, buf, bytes, flags; @@
>     - blk_pwrite(blk, offset, buf, bytes, flags)
>     + blk_pwrite(blk, offset, bytes, buf, flags)
> 
> 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: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 06/18] block: Implement blk_{pread, pwrite}() using generated_co_wrapper
  2022-05-18 13:34     ` Emanuele Giuseppe Esposito
  2022-05-18 14:02       ` Paolo Bonzini
@ 2022-05-19 13:25       ` Alberto Faria
  1 sibling, 0 replies; 64+ messages in thread
From: Alberto Faria @ 2022-05-19 13:25 UTC (permalink / raw)
  To: Emanuele Giuseppe Esposito
  Cc: Paolo Bonzini, qemu-devel, Hanna Reitz, Kevin Wolf, qemu-block

On Wed, May 18, 2022 at 2:34 PM Emanuele Giuseppe Esposito
<eesposit@redhat.com> wrote:
> This is the main patch: it just moves headers from block/coroutines.h to
> the script (block_gen.c).
>
> This allows you to keep generated_co_wrapper functions in the header
> where they originally were (no need to move the function in coroutines.h
> and include it everywhere).

Thanks. It doesn't look like it will conflict with this series.

> Btw @Alberto can you also cc me in the next series? So that I can follow
> too.

Will do!

Alberto



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 00/18] Make block-backend-io.h API more consistent
  2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
                   ` (17 preceding siblings ...)
  2022-05-17 11:39 ` [PATCH 18/18] block: Remove remaining unused symbols in coroutines.h Alberto Faria
@ 2022-07-02 14:12 ` Paolo Bonzini
  2022-07-03 22:22   ` Alberto Faria
  18 siblings, 1 reply; 64+ messages in thread
From: Paolo Bonzini @ 2022-07-02 14:12 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel
  Cc: Andrew Jeffery, Peter Maydell, qemu-block, Palmer Dabbelt,
	Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, Hanna Reitz,
	John Snow, Stefan Hajnoczi, Jeff Cody, qemu-riscv,
	Cédric Le Goater, Joel Stanley, Stefan Weil, Laurent Vivier,
	Denis V. Lunev, Juan Quintela, Dr. David Alan Gilbert,
	Niek Linnenbank, Greg Kurz, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson

On 5/17/22 13:35, Alberto Faria wrote:
> Adjust existing pairs of non-coroutine and coroutine functions to share
> the same calling convention, and add non-coroutine/coroutine
> counterparts where they don't exist.
> 
> Also make the non-coroutine versions generated_co_wrappers.
> 
> This series sits on top of "[PATCH v2 00/10] Implement bdrv_{pread,
> pwrite, pwrite_sync, pwrite_zeroes}() using generated_co_wrapper":
> 
>      https://lore.kernel.org/qemu-devel/20220513155418.2486450-1-afaria@redhat.com/

Alberto, does this need a rebase?

Paolo

> Based-on: <20220513155418.2486450-1-afaria@redhat.com>
> 
> Alberto Faria (18):
>    block: Make blk_{pread,pwrite}() return 0 on success
>    block: Add a 'flags' param to blk_pread()
>    block: Change blk_{pread,pwrite}() param order
>    block: Make 'bytes' param of blk_{pread,pwrite}() an int64_t
>    block: Make blk_co_pwrite() take a const buffer
>    block: Implement blk_{pread,pwrite}() using generated_co_wrapper
>    block: Add blk_{preadv,pwritev}()
>    block: Add blk_[co_]preadv_part()
>    block: Export blk_pwritev_part() in block-backend-io.h
>    block: Change blk_pwrite_compressed() param order
>    block: Add blk_co_pwrite_compressed()
>    block: Implement blk_pwrite_zeroes() using generated_co_wrapper
>    block: Implement blk_pdiscard() using generated_co_wrapper
>    block: Implement blk_flush() using generated_co_wrapper
>    block: Add blk_co_ioctl()
>    block: Add blk_co_truncate()
>    block: Reorganize some declarations in block-backend-io.h
>    block: Remove remaining unused symbols in coroutines.h
> 
>   block.c                           |  10 +-
>   block/block-backend.c             | 150 ++++++++++++------------------
>   block/commit.c                    |   4 +-
>   block/coroutines.h                |  44 ---------
>   block/crypto.c                    |   2 +-
>   block/export/fuse.c               |   4 +-
>   block/meson.build                 |   1 +
>   block/parallels.c                 |   2 +-
>   block/qcow.c                      |  14 +--
>   block/qcow2.c                     |   4 +-
>   block/qed.c                       |   8 +-
>   block/vdi.c                       |   4 +-
>   block/vhdx.c                      |  20 ++--
>   block/vmdk.c                      |  10 +-
>   block/vpc.c                       |  12 +--
>   hw/arm/allwinner-h3.c             |   2 +-
>   hw/arm/aspeed.c                   |   2 +-
>   hw/block/block.c                  |   2 +-
>   hw/block/fdc.c                    |  20 ++--
>   hw/block/hd-geometry.c            |   2 +-
>   hw/block/m25p80.c                 |   2 +-
>   hw/block/nand.c                   |  47 +++++-----
>   hw/block/onenand.c                |  32 +++----
>   hw/block/pflash_cfi01.c           |   4 +-
>   hw/block/pflash_cfi02.c           |   4 +-
>   hw/ide/atapi.c                    |   4 +-
>   hw/misc/mac_via.c                 |   6 +-
>   hw/misc/sifive_u_otp.c            |  14 +--
>   hw/nvram/eeprom_at24c.c           |   8 +-
>   hw/nvram/spapr_nvram.c            |  16 ++--
>   hw/nvram/xlnx-bbram.c             |   4 +-
>   hw/nvram/xlnx-efuse.c             |   4 +-
>   hw/ppc/pnv_pnor.c                 |   6 +-
>   hw/sd/sd.c                        |   4 +-
>   include/sysemu/block-backend-io.h | 105 ++++++++++++---------
>   migration/block.c                 |   8 +-
>   nbd/server.c                      |   8 +-
>   qemu-img.c                        |  33 +++----
>   qemu-io-cmds.c                    |  20 ++--
>   tests/unit/test-block-iothread.c  | 141 ++++++++++++++++++++++++++--
>   40 files changed, 433 insertions(+), 354 deletions(-)
> 



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 00/18] Make block-backend-io.h API more consistent
  2022-07-02 14:12 ` [PATCH 00/18] Make block-backend-io.h API more consistent Paolo Bonzini
@ 2022-07-03 22:22   ` Alberto Faria
  0 siblings, 0 replies; 64+ messages in thread
From: Alberto Faria @ 2022-07-03 22:22 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: qemu-devel, Andrew Jeffery, Peter Maydell, qemu-block,
	Palmer Dabbelt, Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, Hanna Reitz,
	John Snow, Stefan Hajnoczi, Jeff Cody, qemu-riscv,
	Cédric Le Goater, Joel Stanley, Stefan Weil, Laurent Vivier,
	Denis V. Lunev, Juan Quintela, Dr. David Alan Gilbert,
	Niek Linnenbank, Greg Kurz, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson

On Sat, Jul 2, 2022 at 3:12 PM Paolo Bonzini <pbonzini@redhat.com> wrote:
> Alberto, does this need a rebase?

This applies cleanly on "[PATCH v5 00/10] Implement
bdrv_{pread,pwrite,pwrite_sync,pwrite_zeroes}() using
generated_co_wrapper" [1], which applies cleanly to master.

Alberto

[1] https://lore.kernel.org/qemu-devel/20220609152744.3891847-1-afaria@redhat.com/



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success
  2022-05-17 11:35 ` [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success Alberto Faria
  2022-05-17 14:03   ` Greg Kurz
  2022-05-18 12:57   ` Eric Blake
@ 2022-07-04 13:52   ` Hanna Reitz
  2022-07-04 16:20     ` [PATCH 01/18] block: Make blk_{pread, pwrite}() " Alberto Faria
  2 siblings, 1 reply; 64+ messages in thread
From: Hanna Reitz @ 2022-07-04 13:52 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel
  Cc: Andrew Jeffery, Peter Maydell, qemu-block, Palmer Dabbelt,
	Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, John Snow,
	Stefan Hajnoczi, Jeff Cody, qemu-riscv, Cédric Le Goater,
	Joel Stanley, Stefan Weil, Laurent Vivier, Denis V. Lunev,
	Juan Quintela, Dr. David Alan Gilbert, Niek Linnenbank,
	Greg Kurz, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson

On 17.05.22 13:35, Alberto Faria wrote:
> They currently return the value of their 'bytes' parameter on success.
>
> Make them return 0 instead, for consistency with other I/O functions and
> in preparation to implement them using generated_co_wrapper. This also
> makes it clear that short reads/writes are not possible.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block.c                          |  8 +++++---
>   block/block-backend.c            |  7 ++-----
>   block/qcow.c                     |  6 +++---
>   hw/block/m25p80.c                |  2 +-
>   hw/misc/mac_via.c                |  2 +-
>   hw/misc/sifive_u_otp.c           |  2 +-
>   hw/nvram/eeprom_at24c.c          |  4 ++--
>   hw/nvram/spapr_nvram.c           | 12 ++++++------
>   hw/ppc/pnv_pnor.c                |  2 +-
>   qemu-img.c                       | 17 +++++++----------
>   qemu-io-cmds.c                   | 18 ++++++++++++------
>   tests/unit/test-block-iothread.c |  4 ++--
>   12 files changed, 43 insertions(+), 41 deletions(-)

Overall, looks good to me, so first of all:

Reviewed-by: Hanna Reitz <hreitz@redhat.com>

There are a couple of places where you decided to replace “*len” 
variables that used to store the return value by a plain “ret”. That 
seems good to me, given how these functions no longer return length 
values, but you haven’t done so consistently.  Below, I have noted 
places where this wasn’t done; I wonder why, but my R-b stands 
regardless of whether you change them too or not.

[...]

> diff --git a/hw/misc/mac_via.c b/hw/misc/mac_via.c
> index 525e38ce93..0515d1818e 100644
> --- a/hw/misc/mac_via.c
> +++ b/hw/misc/mac_via.c
> @@ -1030,7 +1030,7 @@ static void mos6522_q800_via1_realize(DeviceState *dev, Error **errp)
>           }
>   
>           len = blk_pread(v1s->blk, 0, v1s->PRAM, sizeof(v1s->PRAM));
> -        if (len != sizeof(v1s->PRAM)) {
> +        if (len < 0) {

We could use `ret` here instead.

>               error_setg(errp, "can't read PRAM contents");
>               return;
>           }

[...]

> diff --git a/hw/nvram/eeprom_at24c.c b/hw/nvram/eeprom_at24c.c
> index 01a3093600..84acd71f5a 100644
> --- a/hw/nvram/eeprom_at24c.c
> +++ b/hw/nvram/eeprom_at24c.c
> @@ -65,7 +65,7 @@ int at24c_eeprom_event(I2CSlave *s, enum i2c_event event)
>           DPRINTK("clear\n");
>           if (ee->blk && ee->changed) {
>               int len = blk_pwrite(ee->blk, 0, ee->mem, ee->rsize, 0);
> -            if (len != ee->rsize) {
> +            if (len < 0) {
>                   ERR(TYPE_AT24C_EE
>                           " : failed to write backing file\n");
>               }
> @@ -165,7 +165,7 @@ void at24c_eeprom_reset(DeviceState *state)
>       if (ee->blk) {
>           int len = blk_pread(ee->blk, 0, ee->mem, ee->rsize);
>   
> -        if (len != ee->rsize) {
> +        if (len < 0) {

We could rename `len` to `ret` in both of these hunks.

>               ERR(TYPE_AT24C_EE
>                       " : Failed initial sync with backing file\n");
>           }
> diff --git a/hw/nvram/spapr_nvram.c b/hw/nvram/spapr_nvram.c
> index 18b43be7f6..6000b945c3 100644
> --- a/hw/nvram/spapr_nvram.c
> +++ b/hw/nvram/spapr_nvram.c

[...]

> @@ -181,7 +181,7 @@ static void spapr_nvram_realize(SpaprVioDevice *dev, Error **errp)
>       if (nvram->blk) {
>           int alen = blk_pread(nvram->blk, 0, nvram->buf, nvram->size);
>   
> -        if (alen != nvram->size) {
> +        if (alen < 0) {

As above (and the other case in this file), might be nice to drop `alen` 
here and just use `ret` instead.

>               error_setg(errp, "can't read spapr-nvram contents");
>               return;
>           }

[...]

> diff --git a/qemu-img.c b/qemu-img.c
> index 4cf4d2423d..9d98ef63ac 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -5120,30 +5120,27 @@ 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_ret, out_ret;
>   
> -        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);
> -        }
> +        bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
> +
> +        in_ret = blk_pread(blk1, in_pos, in.buf, bytes);
>           if (in_ret < 0) {
>               error_report("error while reading from input image file: %s",
>                            strerror(-in_ret));
>               ret = -1;
>               goto out;
>           }
> -        in_pos += in_ret;
> -
> -        out_ret = blk_pwrite(blk2, out_pos, in.buf, in_ret, 0);
> +        in_pos += bytes;
>   
> +        out_ret = blk_pwrite(blk2, out_pos, in.buf, bytes, 0);
>           if (out_ret < 0) {
>               error_report("error while writing to output image file: %s",
>                            strerror(-out_ret));
>               ret = -1;
>               goto out;
>           }
> -        out_pos += out_ret;
> +        out_pos += bytes;
>       }
>   
>   out:

We could use this opportunity to drop in_ret and out_ret altogether (but 
we can also decide not to).

Hanna



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 02/18] block: Add a 'flags' param to blk_pread()
  2022-05-17 11:35 ` [PATCH 02/18] block: Add a 'flags' param to blk_pread() Alberto Faria
  2022-05-17 14:19   ` Paolo Bonzini
  2022-05-17 16:26   ` Greg Kurz
@ 2022-07-04 14:04   ` Hanna Reitz
  2 siblings, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-04 14:04 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel
  Cc: Andrew Jeffery, Peter Maydell, qemu-block, Palmer Dabbelt,
	Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, John Snow,
	Stefan Hajnoczi, Jeff Cody, qemu-riscv, Cédric Le Goater,
	Joel Stanley, Stefan Weil, Laurent Vivier, Denis V. Lunev,
	Juan Quintela, Dr. David Alan Gilbert, Niek Linnenbank,
	Greg Kurz, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson

On 17.05.22 13:35, Alberto Faria wrote:
> 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>
> ---
>   block.c                           |  2 +-
>   block/block-backend.c             |  5 +++--
>   block/commit.c                    |  2 +-
>   block/export/fuse.c               |  2 +-
>   hw/arm/allwinner-h3.c             |  2 +-
>   hw/arm/aspeed.c                   |  2 +-
>   hw/block/block.c                  |  2 +-
>   hw/block/fdc.c                    |  6 +++---
>   hw/block/hd-geometry.c            |  2 +-
>   hw/block/m25p80.c                 |  2 +-
>   hw/block/nand.c                   | 12 ++++++------
>   hw/block/onenand.c                | 12 ++++++------
>   hw/ide/atapi.c                    |  4 ++--
>   hw/misc/mac_via.c                 |  2 +-
>   hw/misc/sifive_u_otp.c            |  4 ++--
>   hw/nvram/eeprom_at24c.c           |  2 +-
>   hw/nvram/spapr_nvram.c            |  2 +-
>   hw/nvram/xlnx-bbram.c             |  2 +-
>   hw/nvram/xlnx-efuse.c             |  2 +-
>   hw/ppc/pnv_pnor.c                 |  2 +-
>   hw/sd/sd.c                        |  2 +-
>   include/sysemu/block-backend-io.h |  3 ++-
>   migration/block.c                 |  4 ++--
>   nbd/server.c                      |  4 ++--
>   qemu-img.c                        | 12 ++++++------
>   qemu-io-cmds.c                    |  2 +-
>   tests/unit/test-block-iothread.c  |  4 ++--
>   27 files changed, 52 insertions(+), 50 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 03/18] block: Change blk_{pread,pwrite}() param order
  2022-05-17 11:37 ` [PATCH 03/18] block: Change blk_{pread,pwrite}() param order Alberto Faria
  2022-05-18 14:05   ` Eric Blake
@ 2022-07-04 15:21   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-04 15:21 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel
  Cc: John Snow, Stefan Weil, Andrew Jeffery, Beniamino Galvani,
	qemu-block, Fam Zheng, Niek Linnenbank, Dr. David Alan Gilbert,
	Kevin Wolf, Stefan Hajnoczi, Eric Blake, Alistair Francis,
	Philippe Mathieu-Daudé,
	qemu-arm, qemu-riscv, Jeff Cody, Daniel Henrique Barboza,
	Cédric Le Goater, Edgar E. Iglesias, Juan Quintela,
	Joel Stanley, Peter Maydell, Laurent Vivier, Bin Meng, Greg Kurz,
	Vladimir Sementsov-Ogievskiy, qemu-ppc, Palmer Dabbelt,
	David Gibson, Denis V. Lunev

On 17.05.22 13:37, Alberto Faria wrote:
> Swap 'buf' and 'bytes' around for consistency with
> blk_co_{pread,pwrite}(), and in preparation to implement these functions
> using generated_co_wrapper.
>
> Callers were updated using this Coccinelle script:
>
>      @@ expression blk, offset, buf, bytes, flags; @@
>      - blk_pread(blk, offset, buf, bytes, flags)
>      + blk_pread(blk, offset, bytes, buf, flags)
>
>      @@ expression blk, offset, buf, bytes, flags; @@
>      - blk_pwrite(blk, offset, buf, bytes, flags)
>      + blk_pwrite(blk, offset, bytes, buf, flags)
>
> 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>
> ---
>   block.c                           |  2 +-
>   block/block-backend.c             |  4 +--
>   block/commit.c                    |  4 +--
>   block/crypto.c                    |  2 +-
>   block/export/fuse.c               |  4 +--
>   block/parallels.c                 |  2 +-
>   block/qcow.c                      |  8 +++---
>   block/qcow2.c                     |  4 +--
>   block/qed.c                       |  8 +++---
>   block/vdi.c                       |  4 +--
>   block/vhdx.c                      | 20 ++++++-------
>   block/vmdk.c                      | 10 +++----
>   block/vpc.c                       | 12 ++++----
>   hw/arm/allwinner-h3.c             |  2 +-
>   hw/arm/aspeed.c                   |  2 +-
>   hw/block/block.c                  |  2 +-
>   hw/block/fdc.c                    | 20 ++++++-------
>   hw/block/hd-geometry.c            |  2 +-
>   hw/block/m25p80.c                 |  2 +-
>   hw/block/nand.c                   | 47 ++++++++++++++++---------------
>   hw/block/onenand.c                | 32 ++++++++++-----------
>   hw/block/pflash_cfi01.c           |  4 +--
>   hw/block/pflash_cfi02.c           |  4 +--
>   hw/ide/atapi.c                    |  4 +--
>   hw/misc/mac_via.c                 |  4 +--
>   hw/misc/sifive_u_otp.c            | 14 ++++-----
>   hw/nvram/eeprom_at24c.c           |  4 +--
>   hw/nvram/spapr_nvram.c            |  6 ++--
>   hw/nvram/xlnx-bbram.c             |  4 +--
>   hw/nvram/xlnx-efuse.c             |  4 +--
>   hw/ppc/pnv_pnor.c                 |  6 ++--
>   hw/sd/sd.c                        |  4 +--
>   include/sysemu/block-backend-io.h |  4 +--
>   migration/block.c                 |  6 ++--
>   nbd/server.c                      |  8 +++---
>   qemu-img.c                        | 18 ++++++------
>   qemu-io-cmds.c                    |  4 +--
>   tests/unit/test-block-iothread.c  |  8 +++---
>   38 files changed, 150 insertions(+), 149 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 04/18] block: Make 'bytes' param of blk_{pread,pwrite}() an int64_t
  2022-05-17 11:37 ` [PATCH 04/18] block: Make 'bytes' param of blk_{pread, pwrite}() an int64_t Alberto Faria
  2022-05-17 14:20   ` Paolo Bonzini
@ 2022-07-04 15:24   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-04 15:24 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: qemu-block, Kevin Wolf

On 17.05.22 13:37, Alberto Faria wrote:
> For consistency with other I/O functions, and in preparation to
> implement them using generated_co_wrapper.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 6 +++---
>   include/sysemu/block-backend-io.h | 6 +++---
>   2 files changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 05/18] block: Make blk_co_pwrite() take a const buffer
  2022-05-17 11:38 ` [PATCH 05/18] block: Make blk_co_pwrite() take a const buffer Alberto Faria
  2022-05-17 14:20   ` Paolo Bonzini
@ 2022-07-04 15:25   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-04 15:25 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:38, Alberto Faria wrote:
> It does not mutate the buffer.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   include/sysemu/block-backend-io.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 06/18] block: Implement blk_{pread,pwrite}() using generated_co_wrapper
  2022-05-17 11:38 ` [PATCH 06/18] block: Implement blk_{pread, pwrite}() using generated_co_wrapper Alberto Faria
  2022-05-17 14:22   ` Paolo Bonzini
@ 2022-07-04 15:30   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-04 15:30 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:38, Alberto Faria wrote:
> We need to add include/sysemu/block-backend-io.h to the inputs of the
> block-gen.c target defined in block/meson.build.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 23 -----------------------
>   block/coroutines.h                |  4 ----
>   block/meson.build                 |  1 +
>   include/sysemu/block-backend-io.h | 10 ++++++----
>   4 files changed, 7 insertions(+), 31 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 01/18] block: Make blk_{pread, pwrite}() return 0 on success
  2022-07-04 13:52   ` Hanna Reitz
@ 2022-07-04 16:20     ` Alberto Faria
  0 siblings, 0 replies; 64+ messages in thread
From: Alberto Faria @ 2022-07-04 16:20 UTC (permalink / raw)
  To: Hanna Reitz
  Cc: qemu-devel, Andrew Jeffery, Peter Maydell, qemu-block,
	Palmer Dabbelt, Philippe Mathieu-Daudé,
	qemu-ppc, Eric Blake, Vladimir Sementsov-Ogievskiy, John Snow,
	Stefan Hajnoczi, Jeff Cody, qemu-riscv, Cédric Le Goater,
	Joel Stanley, Stefan Weil, Laurent Vivier, Denis V. Lunev,
	Juan Quintela, Dr. David Alan Gilbert, Niek Linnenbank,
	Greg Kurz, Daniel Henrique Barboza, Kevin Wolf,
	Edgar E. Iglesias, qemu-arm, Fam Zheng, Alistair Francis,
	Beniamino Galvani, Bin Meng, David Gibson

On Mon, Jul 4, 2022 at 2:52 PM Hanna Reitz <hreitz@redhat.com> wrote:
> There are a couple of places where you decided to replace “*len”
> variables that used to store the return value by a plain “ret”. That
> seems good to me, given how these functions no longer return length
> values, but you haven’t done so consistently.  Below, I have noted
> places where this wasn’t done; I wonder why, but my R-b stands
> regardless of whether you change them too or not.

Thanks, this was just an oversight on my part. I'll fix it.

> > diff --git a/qemu-img.c b/qemu-img.c
> > index 4cf4d2423d..9d98ef63ac 100644
> > --- a/qemu-img.c
> > +++ b/qemu-img.c
> > @@ -5120,30 +5120,27 @@ 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_ret, out_ret;
> >
> > -        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);
> > -        }
> > +        bytes = (in_pos + in.bsz > size) ? size - in_pos : in.bsz;
> > +
> > +        in_ret = blk_pread(blk1, in_pos, in.buf, bytes);
> >           if (in_ret < 0) {
> >               error_report("error while reading from input image file: %s",
> >                            strerror(-in_ret));
> >               ret = -1;
> >               goto out;
> >           }
> > -        in_pos += in_ret;
> > -
> > -        out_ret = blk_pwrite(blk2, out_pos, in.buf, in_ret, 0);
> > +        in_pos += bytes;
> >
> > +        out_ret = blk_pwrite(blk2, out_pos, in.buf, bytes, 0);
> >           if (out_ret < 0) {
> >               error_report("error while writing to output image file: %s",
> >                            strerror(-out_ret));
> >               ret = -1;
> >               goto out;
> >           }
> > -        out_pos += out_ret;
> > +        out_pos += bytes;
> >       }
> >
> >   out:
>
> We could use this opportunity to drop in_ret and out_ret altogether (but
> we can also decide not to).

Dropping them sounds good to me.

Alberto



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 07/18] block: Add blk_{preadv,pwritev}()
  2022-05-17 11:38 ` [PATCH 07/18] block: Add blk_{preadv,pwritev}() Alberto Faria
  2022-05-17 14:35   ` Paolo Bonzini
@ 2022-07-05  7:55   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  7:55 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:38, Alberto Faria wrote:
> Implement them using generated_co_wrapper.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   include/sysemu/block-backend-io.h |  6 +++++
>   tests/unit/test-block-iothread.c  | 42 ++++++++++++++++++++++++++++++-
>   2 files changed, 47 insertions(+), 1 deletion(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 08/18] block: Add blk_[co_]preadv_part()
  2022-05-17 11:38 ` [PATCH 08/18] block: Add blk_[co_]preadv_part() Alberto Faria
  2022-05-17 14:30   ` Paolo Bonzini
@ 2022-07-05  8:15   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  8:15 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:38, Alberto Faria wrote:
> Implement blk_preadv_part() using generated_co_wrapper.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 30 +++++++++++++++++++++++-------
>   block/coroutines.h                |  5 -----
>   include/sysemu/block-backend-io.h |  7 +++++++
>   tests/unit/test-block-iothread.c  | 19 +++++++++++++++++++
>   4 files changed, 49 insertions(+), 12 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 09/18] block: Export blk_pwritev_part() in block-backend-io.h
  2022-05-17 11:38 ` [PATCH 09/18] block: Export blk_pwritev_part() in block-backend-io.h Alberto Faria
  2022-05-17 14:30   ` Paolo Bonzini
@ 2022-07-05  8:24   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  8:24 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:38, Alberto Faria wrote:
> Also convert it into a generated_co_wrapper.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 14 --------------
>   block/coroutines.h                |  5 -----
>   include/sysemu/block-backend-io.h |  4 ++++
>   tests/unit/test-block-iothread.c  | 19 +++++++++++++++++++
>   4 files changed, 23 insertions(+), 19 deletions(-)

[...]

> diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothread.c
> index 2fa1248445..6061762c97 100644
> --- a/tests/unit/test-block-iothread.c
> +++ b/tests/unit/test-block-iothread.c
> @@ -183,6 +183,21 @@ static void test_sync_op_blk_preadv_part(BlockBackend *blk)
>       g_assert_cmpint(ret, ==, -EIO);
>   }
>   
> +static void test_sync_op_blk_pwritev_part(BlockBackend *blk)
> +{
> +    uint8_t buf[512];

Given you’ve initialized this in test_sync_op_blk_pwritev(), I think it 
should be initialized here, too.

With that done:

Reviewed-by: Hanna Reitz <hreitz@redhat.com>

> +    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);
> +}
> +



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 10/18] block: Change blk_pwrite_compressed() param order
  2022-05-17 11:38 ` [PATCH 10/18] block: Change blk_pwrite_compressed() param order Alberto Faria
  2022-05-17 14:25   ` Paolo Bonzini
@ 2022-07-05  8:29   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  8:29 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:38, Alberto Faria wrote:
> Swap 'buf' and 'bytes' around for consistency with other I/O functions.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 4 ++--
>   include/sysemu/block-backend-io.h | 4 ++--
>   qemu-img.c                        | 2 +-
>   qemu-io-cmds.c                    | 2 +-
>   4 files changed, 6 insertions(+), 6 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 11/18] block: Add blk_co_pwrite_compressed()
  2022-05-17 11:38 ` [PATCH 11/18] block: Add blk_co_pwrite_compressed() Alberto Faria
  2022-05-17 14:26   ` Paolo Bonzini
@ 2022-07-05  8:45   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  8:45 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:38, Alberto Faria wrote:
> Also convert blk_pwrite_compressed() into a generated_co_wrapper.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             |  8 ++++----
>   include/sysemu/block-backend-io.h |  7 +++++--
>   tests/unit/test-block-iothread.c  | 18 ++++++++++++++++++
>   3 files changed, 27 insertions(+), 6 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 12/18] block: Implement blk_pwrite_zeroes() using generated_co_wrapper
  2022-05-17 11:39 ` [PATCH 12/18] block: Implement blk_pwrite_zeroes() using generated_co_wrapper Alberto Faria
  2022-05-17 14:26   ` Paolo Bonzini
@ 2022-07-05  8:48   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  8:48 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:39, Alberto Faria wrote:
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             |  8 --------
>   include/sysemu/block-backend-io.h |  5 +++--
>   tests/unit/test-block-iothread.c  | 17 +++++++++++++++++
>   3 files changed, 20 insertions(+), 10 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 13/18] block: Implement blk_pdiscard() using generated_co_wrapper
  2022-05-17 11:39 ` [PATCH 13/18] block: Implement blk_pdiscard() " Alberto Faria
  2022-05-17 14:27   ` Paolo Bonzini
@ 2022-07-05  8:51   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  8:51 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:39, Alberto Faria wrote:
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 12 ------------
>   block/coroutines.h                |  3 ---
>   include/sysemu/block-backend-io.h |  3 ++-
>   3 files changed, 2 insertions(+), 16 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 14/18] block: Implement blk_flush() using generated_co_wrapper
  2022-05-17 11:39 ` [PATCH 14/18] block: Implement blk_flush() " Alberto Faria
  2022-05-17 14:27   ` Paolo Bonzini
@ 2022-07-05  8:56   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  8:56 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:39, Alberto Faria wrote:
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 11 -----------
>   block/coroutines.h                |  2 --
>   include/sysemu/block-backend-io.h |  2 +-
>   3 files changed, 1 insertion(+), 14 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 15/18] block: Add blk_co_ioctl()
  2022-05-17 11:39 ` [PATCH 15/18] block: Add blk_co_ioctl() Alberto Faria
  2022-05-17 14:28   ` Paolo Bonzini
@ 2022-07-05  9:02   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  9:02 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:39, Alberto Faria wrote:
> Also convert blk_ioctl() into a generated_co_wrapper.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 7 ++++---
>   block/coroutines.h                | 6 ------
>   include/sysemu/block-backend-io.h | 5 ++++-
>   3 files changed, 8 insertions(+), 10 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 16/18] block: Add blk_co_truncate()
  2022-05-17 11:39 ` [PATCH 16/18] block: Add blk_co_truncate() Alberto Faria
  2022-05-17 14:28   ` Paolo Bonzini
@ 2022-07-05  9:08   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  9:08 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:39, Alberto Faria wrote:
> Also convert blk_truncate() into a generated_co_wrapper.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             |  7 ++++---
>   include/sysemu/block-backend-io.h |  8 ++++++--
>   tests/unit/test-block-iothread.c  | 14 ++++++++++++++
>   3 files changed, 24 insertions(+), 5 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 17/18] block: Reorganize some declarations in block-backend-io.h
  2022-05-17 11:39 ` [PATCH 17/18] block: Reorganize some declarations in block-backend-io.h Alberto Faria
  2022-05-17 14:29   ` Paolo Bonzini
@ 2022-07-05  9:18   ` Hanna Reitz
  2022-07-05 15:26     ` Alberto Faria
  1 sibling, 1 reply; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  9:18 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:39, Alberto Faria wrote:
> Keep generated_co_wrapper and coroutine_fn pairs together. This should
> make it clear that each I/O function has these two versions.
>
> Also move blk_co_{pread,pwrite}()'s implementations out of the header
> file for consistency.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c             | 22 ++++++++
>   include/sysemu/block-backend-io.h | 87 +++++++++++++------------------
>   2 files changed, 59 insertions(+), 50 deletions(-)

[...]

> diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h
> index 004493ec36..30ed979fb1 100644
> --- a/include/sysemu/block-backend-io.h
> +++ b/include/sysemu/block-backend-io.h
> @@ -88,11 +88,6 @@ uint32_t blk_get_request_alignment(BlockBackend *blk);
>   uint32_t blk_get_max_transfer(BlockBackend *blk);
>   uint64_t blk_get_max_hw_transfer(BlockBackend *blk);
>   
> -int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
> -                                   BlockBackend *blk_out, int64_t off_out,
> -                                   int64_t bytes, BdrvRequestFlags read_flags,
> -                                   BdrvRequestFlags write_flags);
> -
>   
>   /*
>    * "I/O or GS" API functions. These functions can run without

[...]

> @@ -190,4 +172,9 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact,
>                                    PreallocMode prealloc, BdrvRequestFlags flags,
>                                    Error **errp);
>   
> +int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in,
> +                                   BlockBackend *blk_out, int64_t off_out,
> +                                   int64_t bytes, BdrvRequestFlags read_flags,
> +                                   BdrvRequestFlags write_flags);
> +
>   #endif /* BLOCK_BACKEND_IO_H */

This moves blk_co_copy_range() from the “I/O API functions” section of 
this header into the “"I/O or GS" API functions” section.  Is that intended?

The rest looks good to me, but I wonder about this one function.

Hanna



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 18/18] block: Remove remaining unused symbols in coroutines.h
  2022-05-17 11:39 ` [PATCH 18/18] block: Remove remaining unused symbols in coroutines.h Alberto Faria
  2022-05-17 14:29   ` Paolo Bonzini
@ 2022-07-05  9:21   ` Hanna Reitz
  1 sibling, 0 replies; 64+ messages in thread
From: Hanna Reitz @ 2022-07-05  9:21 UTC (permalink / raw)
  To: Alberto Faria, qemu-devel; +Cc: Kevin Wolf, qemu-block

On 17.05.22 13:39, Alberto Faria wrote:
> Some can be made static, others are unused generated_co_wrappers.
>
> Signed-off-by: Alberto Faria <afaria@redhat.com>
> ---
>   block/block-backend.c |  6 +++---
>   block/coroutines.h    | 19 -------------------
>   2 files changed, 3 insertions(+), 22 deletions(-)

Reviewed-by: Hanna Reitz <hreitz@redhat.com>



^ permalink raw reply	[flat|nested] 64+ messages in thread

* Re: [PATCH 17/18] block: Reorganize some declarations in block-backend-io.h
  2022-07-05  9:18   ` Hanna Reitz
@ 2022-07-05 15:26     ` Alberto Faria
  0 siblings, 0 replies; 64+ messages in thread
From: Alberto Faria @ 2022-07-05 15:26 UTC (permalink / raw)
  To: Hanna Reitz; +Cc: qemu-devel, Kevin Wolf, qemu-block

On Tue, Jul 5, 2022 at 10:18 AM Hanna Reitz <hreitz@redhat.com> wrote:
> This moves blk_co_copy_range() from the “I/O API functions” section of
> this header into the “"I/O or GS" API functions” section.  Is that intended?

Oops, thanks, it wasn't intended. Will fix.

Alberto



^ permalink raw reply	[flat|nested] 64+ messages in thread

end of thread, other threads:[~2022-07-05 15:28 UTC | newest]

Thread overview: 64+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-17 11:35 [PATCH 00/18] Make block-backend-io.h API more consistent Alberto Faria
2022-05-17 11:35 ` [PATCH 01/18] block: Make blk_{pread,pwrite}() return 0 on success Alberto Faria
2022-05-17 14:03   ` Greg Kurz
2022-05-18 12:57   ` Eric Blake
2022-07-04 13:52   ` Hanna Reitz
2022-07-04 16:20     ` [PATCH 01/18] block: Make blk_{pread, pwrite}() " Alberto Faria
2022-05-17 11:35 ` [PATCH 02/18] block: Add a 'flags' param to blk_pread() Alberto Faria
2022-05-17 14:19   ` Paolo Bonzini
2022-05-17 16:26   ` Greg Kurz
2022-07-04 14:04   ` Hanna Reitz
2022-05-17 11:37 ` [PATCH 03/18] block: Change blk_{pread,pwrite}() param order Alberto Faria
2022-05-18 14:05   ` Eric Blake
2022-07-04 15:21   ` Hanna Reitz
2022-05-17 11:37 ` [PATCH 04/18] block: Make 'bytes' param of blk_{pread, pwrite}() an int64_t Alberto Faria
2022-05-17 14:20   ` Paolo Bonzini
2022-07-04 15:24   ` [PATCH 04/18] block: Make 'bytes' param of blk_{pread,pwrite}() " Hanna Reitz
2022-05-17 11:38 ` [PATCH 05/18] block: Make blk_co_pwrite() take a const buffer Alberto Faria
2022-05-17 14:20   ` Paolo Bonzini
2022-07-04 15:25   ` Hanna Reitz
2022-05-17 11:38 ` [PATCH 06/18] block: Implement blk_{pread, pwrite}() using generated_co_wrapper Alberto Faria
2022-05-17 14:22   ` Paolo Bonzini
2022-05-18 13:34     ` Emanuele Giuseppe Esposito
2022-05-18 14:02       ` Paolo Bonzini
2022-05-19 13:25       ` Alberto Faria
2022-07-04 15:30   ` [PATCH 06/18] block: Implement blk_{pread,pwrite}() " Hanna Reitz
2022-05-17 11:38 ` [PATCH 07/18] block: Add blk_{preadv,pwritev}() Alberto Faria
2022-05-17 14:35   ` Paolo Bonzini
2022-07-05  7:55   ` Hanna Reitz
2022-05-17 11:38 ` [PATCH 08/18] block: Add blk_[co_]preadv_part() Alberto Faria
2022-05-17 14:30   ` Paolo Bonzini
2022-07-05  8:15   ` Hanna Reitz
2022-05-17 11:38 ` [PATCH 09/18] block: Export blk_pwritev_part() in block-backend-io.h Alberto Faria
2022-05-17 14:30   ` Paolo Bonzini
2022-07-05  8:24   ` Hanna Reitz
2022-05-17 11:38 ` [PATCH 10/18] block: Change blk_pwrite_compressed() param order Alberto Faria
2022-05-17 14:25   ` Paolo Bonzini
2022-07-05  8:29   ` Hanna Reitz
2022-05-17 11:38 ` [PATCH 11/18] block: Add blk_co_pwrite_compressed() Alberto Faria
2022-05-17 14:26   ` Paolo Bonzini
2022-07-05  8:45   ` Hanna Reitz
2022-05-17 11:39 ` [PATCH 12/18] block: Implement blk_pwrite_zeroes() using generated_co_wrapper Alberto Faria
2022-05-17 14:26   ` Paolo Bonzini
2022-07-05  8:48   ` Hanna Reitz
2022-05-17 11:39 ` [PATCH 13/18] block: Implement blk_pdiscard() " Alberto Faria
2022-05-17 14:27   ` Paolo Bonzini
2022-07-05  8:51   ` Hanna Reitz
2022-05-17 11:39 ` [PATCH 14/18] block: Implement blk_flush() " Alberto Faria
2022-05-17 14:27   ` Paolo Bonzini
2022-07-05  8:56   ` Hanna Reitz
2022-05-17 11:39 ` [PATCH 15/18] block: Add blk_co_ioctl() Alberto Faria
2022-05-17 14:28   ` Paolo Bonzini
2022-07-05  9:02   ` Hanna Reitz
2022-05-17 11:39 ` [PATCH 16/18] block: Add blk_co_truncate() Alberto Faria
2022-05-17 14:28   ` Paolo Bonzini
2022-07-05  9:08   ` Hanna Reitz
2022-05-17 11:39 ` [PATCH 17/18] block: Reorganize some declarations in block-backend-io.h Alberto Faria
2022-05-17 14:29   ` Paolo Bonzini
2022-07-05  9:18   ` Hanna Reitz
2022-07-05 15:26     ` Alberto Faria
2022-05-17 11:39 ` [PATCH 18/18] block: Remove remaining unused symbols in coroutines.h Alberto Faria
2022-05-17 14:29   ` Paolo Bonzini
2022-07-05  9:21   ` Hanna Reitz
2022-07-02 14:12 ` [PATCH 00/18] Make block-backend-io.h API more consistent Paolo Bonzini
2022-07-03 22:22   ` Alberto Faria

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.