[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 44/69] nbd: Switch to byte-based block access
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 44/69] nbd: Switch to byte-based block access |
Date: |
Thu, 12 May 2016 16:35:24 +0200 |
From: Eric Blake <address@hidden>
Sector-based blk_read() should die; switch to byte-based
blk_pread() instead.
Add a constant for our magic number 512, to make it obvious
that this size will NOT change even if BDRV_SECTOR_SIZE does,
even though the two happen to be the same for now. Split
assignments from conditionals to keep checkpatch.pl happy.
Signed-off-by: Eric Blake <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
qemu-nbd.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/qemu-nbd.c b/qemu-nbd.c
index c55b40f..3e54113 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -46,6 +46,8 @@
#define QEMU_NBD_OPT_TLSCREDS 261
#define QEMU_NBD_OPT_IMAGE_OPTS 262
+#define MBR_SIZE 512
+
static NBDExport *exp;
static bool newproto;
static int verbose;
@@ -159,12 +161,13 @@ static int find_partition(BlockBackend *blk, int
partition,
off_t *offset, off_t *size)
{
struct partition_record mbr[4];
- uint8_t data[512];
+ uint8_t data[MBR_SIZE];
int i;
int ext_partnum = 4;
int ret;
- if ((ret = blk_read(blk, 0, data, 1)) < 0) {
+ ret = blk_pread(blk, 0, data, sizeof(data));
+ if (ret < 0) {
error_report("error while reading: %s", strerror(-ret));
exit(EXIT_FAILURE);
}
@@ -182,10 +185,12 @@ static int find_partition(BlockBackend *blk, int
partition,
if (mbr[i].system == 0xF || mbr[i].system == 0x5) {
struct partition_record ext[4];
- uint8_t data1[512];
+ uint8_t data1[MBR_SIZE];
int j;
- if ((ret = blk_read(blk, mbr[i].start_sector_abs, data1, 1)) < 0) {
+ ret = blk_pread(blk, mbr[i].start_sector_abs * MBR_SIZE,
+ data1, sizeof(data1));
+ if (ret < 0) {
error_report("error while reading: %s", strerror(-ret));
exit(EXIT_FAILURE);
}
--
1.8.3.1
- [Qemu-devel] [PULL 21/69] vpc: Implement .bdrv_co_preadv() interface, (continued)
- [Qemu-devel] [PULL 21/69] vpc: Implement .bdrv_co_preadv() interface, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 14/69] cloop: Implement .bdrv_co_preadv() interface, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 18/69] vmdk: Add vmdk_find_offset_in_cluster(), Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 26/69] block: always compile-check debug prints, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 19/69] vmdk: Implement .bdrv_co_preadv() interface, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 22/69] vpc: Implement .bdrv_co_pwritev() interface, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 25/69] block: Fix typo in comment, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 27/69] Allow users to specify the vmdk virtual hardware version., Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 29/69] block: Allow BDRV_REQ_FUA through blk_pwrite(), Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 28/69] qemu-io: Fix memory leak in 'aio_write -z', Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 44/69] nbd: Switch to byte-based block access,
Kevin Wolf <=
- [Qemu-devel] [PULL 30/69] block: Switch blk_read_unthrottled() to byte interface, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 39/69] onenand: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 37/69] fdc: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 23/69] vvfat: Implement .bdrv_co_preadv/pwritev interfaces, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 31/69] block: Switch blk_*write_zeroes() to byte interface, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 47/69] block: Kill unused sector-based blk_* functions, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 46/69] qemu-io: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 34/69] scsi-disk: Switch to byte-based aio block access, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 32/69] block: Introduce byte-based aio read/write, Kevin Wolf, 2016/05/12
- [Qemu-devel] [PULL 51/69] nbd: Simplify client FUA handling, Kevin Wolf, 2016/05/12