Remove bdrv_read() and bdrv_write()
cover Remove bdrv_read() and bdrv_write()
Hi,
this API only had a few users left so it can be easily removed.
Regards,
Berto
Alberto Garcia (5):
qcow2: Replace bdrv_write() with bdrv_pwrite()
vdi: Replace bdrv_{read,write}() with bdrv_{pread,pwrite}()
vvfat: Replace bdrv_{read,write}() with bdrv_{pread,pwrite}()
block: Remove bdrv_read() and bdrv_write()
qcow2: Remove BDRVQcow2State.cluster_sectors
block/io.c | 36 ------------------------------------ block/qcow2-refcount.c | 4 ++-- block/qcow2.c | 1 - block/qcow2.h | 1 - block/vdi.c | 11 ++++++----- block/vvfat.c | 10 ++++++---- include/block/block.h | 4 ---- 7 files changed, 14 insertions(+), 53 deletions(-)
Signature · 1 line
2.11.0
PATCH 2/5 vdi: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}()
There's only a couple of bdrv_read() and bdrv_write() calls left in the vdi code, and they can be trivially replaced with the byte-based bdrv_pread() and bdrv_pwrite().
--- block/vdi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
block/vdi.c +6 -5
@@ -384,7 +384,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,logout ("\n" ); - ret =bdrv_read (bs->file,0 , (uint8_t *)&header,1 ); + ret =bdrv_pread (bs->file,0 , (uint8_t *)&header,sizeof (header));if (ret <0 ) { goto fail; }
@@ -484,8 +484,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } - ret =bdrv_read (bs->file, s->bmap_sector, (uint8_t *)s->bmap, - bmap_size); + ret =bdrv_pread (bs->file, header.offset_bmap, (uint8_t *)s->bmap, + bmap_size *SECTOR_SIZE );if (ret <0 ) { goto fail_free_bmap; }
@@ -704,7 +704,7 @@ nonallocating_write:assert (VDI_IS_ALLOCATED (bmap_first)); *header = s->header;vdi_header_to_le (header); - ret =bdrv_write (bs->file,0 , block,1 ); + ret =bdrv_pwrite (bs->file,0 , block,sizeof (*block));g_free (block); block =NULL ;
@@ -722,7 +722,8 @@ nonallocating_write: base = ((uint8_t *)&s->bmap[0 ]) + bmap_first *SECTOR_SIZE ;logout ("will write %u block map sectors starting from entry %u\n" , n_sectors, bmap_first); - ret =bdrv_write (bs->file, offset, base, n_sectors); + ret =bdrv_pwrite (bs->file, offset *SECTOR_SIZE , base, + n_sectors *SECTOR_SIZE ); }return ret;
Signature · 1 line
2.11.0
PATCH 4/5 block: Remove bdrv_read() and bdrv_write()
In reply to Alberto GarciaNo one is using these functions anymore, all callers have switched to the byte-based bdrv_pread() and bdrv_pwrite()
--- block/io.c | 36 ------------------------------------ include/block/block.h | 4 ---- 2 files changed, 40 deletions(-)
block/io.c +0 -36
@@ -837,42 +837,6 @@ static int bdrv_prwv_co(BdrvChild *child, int64_t offset,return rwco.ret; } -/* -* Process a synchronous request using coroutines -*/ -static int bdrv_rw_co (BdrvChild *child,int64_t sector_num,uint8_t *buf, -int nb_sectors,bool is_write,BdrvRequestFlags flags) -{ -QEMUIOVector qiov =QEMU_IOVEC_INIT_BUF (qiov, buf, - nb_sectors *BDRV_SECTOR_SIZE ); - -if (nb_sectors <0 || nb_sectors >BDRV_REQUEST_MAX_SECTORS ) { -return -EINVAL ; - } - -return bdrv_prwv_co (child, sector_num <<BDRV_SECTOR_BITS , - &qiov, is_write, flags); -} - -/* return < 0 if error. See bdrv_write() for the return codes */ -int bdrv_read (BdrvChild *child,int64_t sector_num, -uint8_t *buf,int nb_sectors) -{ -return bdrv_rw_co (child, sector_num, buf, nb_sectors, false,0 ); -} - -/* Return < 0 if error. Important errors are: --EIO generic I/O error (may happen for all errors) --ENOMEDIUM No media inserted. --EINVAL Invalid sector number or nb_sectors --EACCES Trying to write a read-only device -*/ -int bdrv_write (BdrvChild *child,int64_t sector_num, -const uint8_t *buf,int nb_sectors) -{ -return bdrv_rw_co (child, sector_num, (uint8_t *)buf, nb_sectors, true,0 ); -} -int bdrv_pwrite_zeroes (BdrvChild *child,int64_t offset,int bytes,BdrvRequestFlags flags) {
include/block/block.h +0 -4
@@ -316,10 +316,6 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, BlockReopenQueue *queue, Error **errp);void bdrv_reopen_commit (BDRVReopenState *reopen_state);void bdrv_reopen_abort (BDRVReopenState *reopen_state); -int bdrv_read (BdrvChild *child,int64_t sector_num, -uint8_t *buf,int nb_sectors); -int bdrv_write (BdrvChild *child,int64_t sector_num, -const uint8_t *buf,int nb_sectors);int bdrv_pwrite_zeroes (BdrvChild *child,int64_t offset,int bytes,BdrvRequestFlags flags);int bdrv_make_zero (BdrvChild *child,BdrvRequestFlags flags);
Signature · 1 line
2.11.0
PATCH 1/5 qcow2: Replace bdrv_write() with bdrv_pwrite()
In reply to Alberto GarciaThere's only one bdrv_write() call left in the qcow2 code, and it can be trivially replaced with the byte-based bdrv_pwrite().
--- block/qcow2-refcount.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/qcow2-refcount.c +2 -2
@@ -2409,8 +2409,8 @@ write_refblocks: on_disk_refblock = (void *)((char *) *refcount_table + refblock_index * s->cluster_size); - ret =bdrv_write (bs->file, refblock_offset /BDRV_SECTOR_SIZE , - on_disk_refblock, s->cluster_sectors); + ret =bdrv_pwrite (bs->file, refblock_offset, on_disk_refblock, + s->cluster_size);if (ret <0 ) {fprintf (stderr,"ERROR writing refblock: %s\n" ,strerror (-ret)); goto fail;
Signature · 1 line
2.11.0
PATCH 3/5 vvfat: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}()
In reply to Alberto GarciaThere's only a couple of bdrv_read() and bdrv_write() calls left in the vvfat code, and they can be trivially replaced with the byte-based bdrv_pread() and bdrv_pwrite().
--- block/vvfat.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
block/vvfat.c +6 -4
@@ -1494,8 +1494,8 @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num,DLOG (fprintf (stderr,"sectors %" PRId64"+%" PRId64" allocated\n" , sector_num, n >>BDRV_SECTOR_BITS )); -if (bdrv_read (s->qcow, sector_num, buf + i *0x200 , - n >>BDRV_SECTOR_BITS )) { +if (bdrv_pread (s->qcow, sector_num *BDRV_SECTOR_SIZE , + buf + i *0x200 , n)) {return -1 ; } i += (n >>BDRV_SECTOR_BITS ) -1 ;
@@ -1983,7 +1983,8 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,if (res) {return -1 ; } - res =bdrv_write (s->qcow, offset, s->cluster_buffer,1 ); + res =bdrv_pwrite (s->qcow, offset *BDRV_SECTOR_SIZE , + s->cluster_buffer,BDRV_SECTOR_SIZE );if (res) {return -2 ; }
@@ -3050,7 +3051,8 @@ DLOG(checkpoint());* Use qcow backend. Commit later. */ DLOG (fprintf (stderr,"Write to qcow backend: %d + %d\n" , (int )sector_num, nb_sectors)); - ret =bdrv_write (s->qcow, sector_num, buf, nb_sectors); + ret =bdrv_pwrite (s->qcow, sector_num *BDRV_SECTOR_SIZE , buf, + nb_sectors *BDRV_SECTOR_SIZE );if (ret <0 ) {fprintf (stderr,"Error writing to qcow backend\n" );return ret;
Signature · 1 line
2.11.0
PATCH 5/5 qcow2: Remove BDRVQcow2State.cluster_sectors
In reply to Alberto GarciaThe last user of this field disappeared when we replace the sector-based bdrv_write() with the byte-based bdrv_pwrite().
--- block/qcow2.c | 1 - block/qcow2.h | 1 - 2 files changed, 2 deletions(-)
block/qcow2.c +0 -1
@@ -1259,7 +1259,6 @@ static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, s->cluster_bits = header.cluster_bits; s->cluster_size =1 << s->cluster_bits; - s->cluster_sectors =1 << (s->cluster_bits -BDRV_SECTOR_BITS );/* Initialise version 3 header fields */ if (header.version ==2 ) {
block/qcow2.h +0 -1
@@ -266,7 +266,6 @@ typedef struct Qcow2BitmapHeaderExt { typedef struct BDRVQcow2State { int cluster_bits; int cluster_size; - int cluster_sectors; int l2_slice_size; int l2_bits; int l2_size;
Signature · 1 line
2.11.0
Quoted 3 lines · Alberto Garcia
Hi,
this API only had a few users left so it can be easily removed.
Sounds very similar to my earlier attempt at the same:
https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg02769.html
Quoted 21 lines
Regards,
Berto
Alberto Garcia (5):
qcow2: Replacebdrv_write()withbdrv_pwrite()
vdi: Replace bdrv_{read,write}() with bdrv_{pread,pwrite}()
vvfat: Replace bdrv_{read,write}() with bdrv_{pread,pwrite}()
block: Removebdrv_read()andbdrv_write()
qcow2: Remove BDRVQcow2State.cluster_sectorsblock/io.c | 36 ------------------------------------ block/qcow2-refcount.c | 4 ++-- block/qcow2.c | 1 - block/qcow2.h | 1 - block/vdi.c | 11 ++++++----- block/vvfat.c | 10 ++++++---- include/block/block.h | 4 ---- 7 files changed, 14 insertions(+), 53 deletions(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH 3/5] vvfat: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}()
In reply to Alberto GarciaAm 29.04.2019 um 20:42 hat Alberto Garcia geschrieben:
Quoted 14 lines
There's only a couple of
bdrv_read()andbdrv_write()calls left in the vvfat code, and they can be trivially replaced with the byte-basedbdrv_pread()andbdrv_pwrite().Signed-off-by Alberto Garcia <[email protected]>--- block/vvfat.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)block/vvfat.c +0
-0
block/vvfat.c static int vvfat_read(BlockDriverState *bs, int64_t sector_num, · line 1498
Quoted 7 lines
block/vvfat.c +2
-2@@ -1494,8 +1494,8 @@ static int vvfat_read(BlockDriverState *bs, int64_t sector_num,DLOG (fprintf (stderr,"sectors %" PRId64"+%" PRId64" allocated\n" , sector_num, n >>BDRV_SECTOR_BITS )); -if (bdrv_read (s->qcow, sector_num, buf + i *0x200 , - n >>BDRV_SECTOR_BITS )) { +if (bdrv_pread (s->qcow, sector_num *BDRV_SECTOR_SIZE , + buf + i *0x200 , n)) {
bdrv_pread() returns a positive number of bytes in the success case, so this error check is wrong. (No real reason why it couldn't return 0, but we would have to check and possibly update all callers, so we never did that.)
block/vvfat.c static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s, · line 1988
Quoted 11 lines
block/vvfat.c +2
-1return -1 ; } i += (n >>BDRV_SECTOR_BITS ) -1 ;@@ -1983,7 +1983,8 @@ static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s,if (res) {return -1 ; } - res =bdrv_write (s->qcow, offset, s->cluster_buffer,1 ); + res =bdrv_pwrite (s->qcow, offset *BDRV_SECTOR_SIZE , + s->cluster_buffer,BDRV_SECTOR_SIZE );if (res) {
Same here, this needs to be res < 0 now.
block/vvfat.c DLOG(checkpoint()); · line 3056
Quoted 10 lines
block/vvfat.c +2
-1return -2 ; }@@ -3050,7 +3051,8 @@ DLOG(checkpoint());* Use qcow backend. Commit later. */ DLOG (fprintf (stderr,"Write to qcow backend: %d + %d\n" , (int )sector_num, nb_sectors)); - ret =bdrv_write (s->qcow, sector_num, buf, nb_sectors); + ret =bdrv_pwrite (s->qcow, sector_num *BDRV_SECTOR_SIZE , buf, + nb_sectors *BDRV_SECTOR_SIZE );if (ret <0 ) {
This one is already correct.
block/vvfat.c DLOG(checkpoint()); · line 3058
Quoted 2 lines
block/vvfat.c +0
-0fprintf (stderr,"Error writing to qcow backend\n" );return ret;
Kevin
Re: [Qemu-devel] [PATCH 2/5] vdi: Replace bdrv_{read, write}() with bdrv_{pread, pwrite}()
In reply to Alberto GarciaAm 29.04.2019 um 20:42 hat Alberto Garcia geschrieben:
Quoted 14 lines
There's only a couple of
bdrv_read()andbdrv_write()calls left in the vdi code, and they can be trivially replaced with the byte-basedbdrv_pread()andbdrv_pwrite().Signed-off-by Alberto Garcia <[email protected]>--- block/vdi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)block/vdi.c +0
-0
block/vdi.c static int vdi_open(BlockDriverState *bs, QDict *options, int flags, · line 387
Quoted 5 lines
block/vdi.c +1
-1@@ -384,7 +384,7 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags,logout ("\n" ); - ret =bdrv_read (bs->file,0 , (uint8_t *)&header,1 ); + ret =bdrv_pread (bs->file,0 , (uint8_t *)&header,sizeof (header));
Maybe worth adding this after the VdiHeader declaration?
QEMU_BUILD_BUG_ON(sizeof(VdiHeader) != 512);
Quoted 15 lines
block/vdi.c +2
-2if (ret <0 ) { goto fail; }@@ -484,8 +484,8 @@ static int vdi_open(BlockDriverState *bs, QDict *options, int flags, goto fail; } - ret =bdrv_read (bs->file, s->bmap_sector, (uint8_t *)s->bmap, - bmap_size); + ret =bdrv_pread (bs->file, header.offset_bmap, (uint8_t *)s->bmap, + bmap_size *SECTOR_SIZE );if (ret <0 ) { goto fail_free_bmap; }
block/vdi.c nonallocating_write: · line 707
Quoted 5 lines
block/vdi.c +1
-1@@ -704,7 +704,7 @@ nonallocating_write:assert (VDI_IS_ALLOCATED (bmap_first)); *header = s->header;vdi_header_to_le (header); - ret =bdrv_write (bs->file,0 , block,1 ); + ret =bdrv_pwrite (bs->file,0 , block,sizeof (*block));
block is uint8_t*, so sizeof(*block) == 1. This is not what you want. (qemu-iotests catches this pretty early.)
block/vdi.c nonallocating_write: · line 729
Quoted 13 lines
block/vdi.c +2
-1g_free (block); block =NULL ;@@ -722,7 +722,8 @@ nonallocating_write: base = ((uint8_t *)&s->bmap[0 ]) + bmap_first *SECTOR_SIZE ;logout ("will write %u block map sectors starting from entry %u\n" , n_sectors, bmap_first); - ret =bdrv_write (bs->file, offset, base, n_sectors); + ret =bdrv_pwrite (bs->file, offset *SECTOR_SIZE , base, + n_sectors *SECTOR_SIZE ); }return ret;
Let's avoid returning a non-zero positive number in the success case here. bdrv_driver_pwritev() checks ret == 0 for BDRV_REQ_FUA emulation, and its callers don't expect positive results either.
Maybe we should actually assert() in bdrv_driver_preadv/pwritev() that the result is <= 0.
Kevin
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the docker-mingw@fedora build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-mingw@fedora SHOW_ENV=1 J=14 NETWORK=1 === TEST SCRIPT END ===
The full log is available at
http://patchew.org/logs/[email protected]/testing.docker-mingw@fedora/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series failed the asan build test. Please find the testing commands and their output below. If you have Docker installed, you can probably reproduce it locally.
=== TEST SCRIPT BEGIN ===
#!/bin/bash
time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1 === TEST SCRIPT END ===
The full log is available at
http://patchew.org/logs/[email protected]/testing.asan/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]