[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PULL 44/69] nbd: Switch to byte-based block access
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [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-block] [PULL 21/69] vpc: Implement .bdrv_co_preadv() interface, (continued)
- [Qemu-block] [PULL 21/69] vpc: Implement .bdrv_co_preadv() interface, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 28/69] qemu-io: Fix memory leak in 'aio_write -z', Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 29/69] block: Allow BDRV_REQ_FUA through blk_pwrite(), Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 34/69] scsi-disk: Switch to byte-based aio block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 33/69] ide: Switch to byte-based aio block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 38/69] nand: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 30/69] block: Switch blk_read_unthrottled() to byte interface, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 35/69] virtio: Switch to byte-based aio block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 40/69] pflash: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 37/69] fdc: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 44/69] nbd: Switch to byte-based block access,
Kevin Wolf <=
- [Qemu-block] [PULL 45/69] qemu-img: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 42/69] m25p80: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 47/69] block: Kill unused sector-based blk_* functions, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 43/69] atapi: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 41/69] sd: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 48/69] qcow2: improve qcow2_co_write_zeroes(), Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 39/69] onenand: Switch to byte-based block access, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 52/69] block: Invalidate all children, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 53/69] block: Drop superfluous invalidating bs->file from drivers, Kevin Wolf, 2016/05/12
- [Qemu-block] [PULL 55/69] iotests: fix the redirection order in 083, Kevin Wolf, 2016/05/12