[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 18/44] qemu-img: Switch to byte-based block acces
From: |
Eric Blake |
Subject: |
[Qemu-devel] [PATCH v3 18/44] qemu-img: Switch to byte-based block access |
Date: |
Fri, 22 Apr 2016 17:40:26 -0600 |
Sector-based blk_write() should die; switch to byte-based
blk_pwrite() instead. Likewise for blk_read().
Signed-off-by: Eric Blake <address@hidden>
---
qemu-img.c | 28 +++++++++++++++++++---------
1 file changed, 19 insertions(+), 9 deletions(-)
diff --git a/qemu-img.c b/qemu-img.c
index 1697762..2e4646e 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1092,7 +1092,8 @@ static int check_empty_sectors(BlockBackend *blk, int64_t
sect_num,
uint8_t *buffer, bool quiet)
{
int pnum, ret = 0;
- ret = blk_read(blk, sect_num, buffer, sect_count);
+ ret = blk_pread(blk, sect_num << BDRV_SECTOR_BITS, buffer,
+ sect_count << BDRV_SECTOR_BITS);
if (ret < 0) {
error_report("Error while reading offset %" PRId64 " of %s: %s",
sectors_to_bytes(sect_num), filename, strerror(-ret));
@@ -1307,7 +1308,8 @@ static int img_compare(int argc, char **argv)
nb_sectors = MIN(pnum1, pnum2);
} else if (allocated1 == allocated2) {
if (allocated1) {
- ret = blk_read(blk1, sector_num, buf1, nb_sectors);
+ ret = blk_pread(blk1, sector_num << BDRV_SECTOR_BITS, buf1,
+ nb_sectors << BDRV_SECTOR_BITS);
if (ret < 0) {
error_report("Error while reading offset %" PRId64 " of
%s:"
" %s", sectors_to_bytes(sector_num),
filename1,
@@ -1315,7 +1317,8 @@ static int img_compare(int argc, char **argv)
ret = 4;
goto out;
}
- ret = blk_read(blk2, sector_num, buf2, nb_sectors);
+ ret = blk_pread(blk2, sector_num << BDRV_SECTOR_BITS, buf2,
+ nb_sectors << BDRV_SECTOR_BITS);
if (ret < 0) {
error_report("Error while reading offset %" PRId64
" of %s: %s", sectors_to_bytes(sector_num),
@@ -1528,7 +1531,9 @@ static int convert_read(ImgConvertState *s, int64_t
sector_num, int nb_sectors,
bs_sectors = s->src_sectors[s->src_cur];
n = MIN(nb_sectors, bs_sectors - (sector_num - s->src_cur_offset));
- ret = blk_read(blk, sector_num - s->src_cur_offset, buf, n);
+ ret = blk_pread(blk,
+ (sector_num - s->src_cur_offset) << BDRV_SECTOR_BITS,
+ buf, n << BDRV_SECTOR_BITS);
if (ret < 0) {
return ret;
}
@@ -1583,7 +1588,8 @@ static int convert_write(ImgConvertState *s, int64_t
sector_num, int nb_sectors,
if (!s->min_sparse ||
is_allocated_sectors_min(buf, n, &n, s->min_sparse))
{
- ret = blk_write(s->target, sector_num, buf, n);
+ ret = blk_pwrite(s->target, sector_num << BDRV_SECTOR_BITS,
+ buf, n << BDRV_SECTOR_BITS, 0);
if (ret < 0) {
return ret;
}
@@ -3036,7 +3042,8 @@ static int img_rebase(int argc, char **argv)
n = old_backing_num_sectors - sector;
}
- ret = blk_read(blk_old_backing, sector, buf_old, n);
+ ret = blk_pread(blk_old_backing, sector << BDRV_SECTOR_BITS,
+ buf_old, n << BDRV_SECTOR_BITS);
if (ret < 0) {
error_report("error while reading from old backing file");
goto out;
@@ -3050,7 +3057,8 @@ static int img_rebase(int argc, char **argv)
n = new_backing_num_sectors - sector;
}
- ret = blk_read(blk_new_backing, sector, buf_new, n);
+ ret = blk_pread(blk_new_backing, sector << BDRV_SECTOR_BITS,
+ buf_new, n << BDRV_SECTOR_BITS);
if (ret < 0) {
error_report("error while reading from new backing file");
goto out;
@@ -3066,8 +3074,10 @@ static int img_rebase(int argc, char **argv)
if (compare_sectors(buf_old + written * 512,
buf_new + written * 512, n - written, &pnum))
{
- ret = blk_write(blk, sector + written,
- buf_old + written * 512, pnum);
+ ret = blk_pwrite(blk,
+ (sector + written) << BDRV_SECTOR_BITS,
+ buf_old + written * 512,
+ pnum << BDRV_SECTOR_BITS, 0);
if (ret < 0) {
error_report("Error while writing to COW image: %s",
strerror(-ret));
--
2.5.5
- [Qemu-devel] [PATCH v3 08/44] nbd: Add qemu-nbd -D for human-readable description, (continued)
- [Qemu-devel] [PATCH v3 08/44] nbd: Add qemu-nbd -D for human-readable description, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 07/44] nbd: Limit nbdflags to 16 bits, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 10/44] fdc: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 15/44] m25p80: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 14/44] sd: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 13/44] pflash: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 16/44] atapi: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 18/44] qemu-img: Switch to byte-based block access,
Eric Blake <=
- [Qemu-devel] [PATCH v3 23/44] qemu-io: Add missing option documentation, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 29/44] nbd: Avoid magic number for NBD max name size, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 31/44] nbd: Share common reply-sending code in server, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 06/44] nbd: Clean up ioctl handling of qemu-nbd -c, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 09/44] block: Allow BDRV_REQ_FUA through blk_pwrite(), Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 12/44] onenand: Switch to byte-based block access, Eric Blake, 2016/04/22
- [Qemu-devel] [PATCH v3 17/44] nbd: Switch to byte-based block access, Eric Blake, 2016/04/22