diff mbox

[v6,17/20] nbd: Switch to byte-based block access

Message ID 1462406126-22946-18-git-send-email-eblake@redhat.com
State New
Headers show

Commit Message

Eric Blake May 4, 2016, 11:55 p.m. UTC
Sector-based blk_read() should die; switch to byte-based
blk_pread() instead.

Signed-off-by: Eric Blake <eblake@redhat.com>
---
 qemu-nbd.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Kevin Wolf May 6, 2016, 1:08 p.m. UTC | #1
Am 05.05.2016 um 01:55 hat Eric Blake geschrieben:
> Sector-based blk_read() should die; switch to byte-based
> blk_pread() instead.
> 
> Signed-off-by: Eric Blake <eblake@redhat.com>
> ---
>  qemu-nbd.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/qemu-nbd.c b/qemu-nbd.c
> index c55b40f..c07ceef 100644
> --- a/qemu-nbd.c
> +++ b/qemu-nbd.c
> @@ -159,12 +159,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[BDRV_SECTOR_SIZE];

I like 512 better, actually. This is not the size of the arbitrary unit
that some block layer functions use, but the size of an MBR. If you
don't like the magic number, a new #define would probably be best.

>      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 +183,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[BDRV_SECTOR_SIZE];

Same here.

>              int j;
> 
> -            if ((ret = blk_read(blk, mbr[i].start_sector_abs, data1, 1)) < 0) {
> +            ret = blk_pread(blk, mbr[i].start_sector_abs << BDRV_SECTOR_BITS,
> +                            data1, sizeof(data1));
> +            if (ret < 0) {
>                  error_report("error while reading: %s", strerror(-ret));
>                  exit(EXIT_FAILURE);
>              }

Kevin
Eric Blake May 6, 2016, 2:19 p.m. UTC | #2
On 05/06/2016 07:08 AM, Kevin Wolf wrote:
> Am 05.05.2016 um 01:55 hat Eric Blake geschrieben:
>> Sector-based blk_read() should die; switch to byte-based
>> blk_pread() instead.
>>
>> Signed-off-by: Eric Blake <eblake@redhat.com>
>> ---
>>  qemu-nbd.c | 11 +++++++----
>>  1 file changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/qemu-nbd.c b/qemu-nbd.c
>> index c55b40f..c07ceef 100644
>> --- a/qemu-nbd.c
>> +++ b/qemu-nbd.c
>> @@ -159,12 +159,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[BDRV_SECTOR_SIZE];
> 
> I like 512 better, actually. This is not the size of the arbitrary unit
> that some block layer functions use, but the size of an MBR. If you
> don't like the magic number, a new #define would probably be best.

MBR_SIZE it will be :)
diff mbox

Patch

diff --git a/qemu-nbd.c b/qemu-nbd.c
index c55b40f..c07ceef 100644
--- a/qemu-nbd.c
+++ b/qemu-nbd.c
@@ -159,12 +159,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[BDRV_SECTOR_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 +183,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[BDRV_SECTOR_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 << BDRV_SECTOR_BITS,
+                            data1, sizeof(data1));
+            if (ret < 0) {
                 error_report("error while reading: %s", strerror(-ret));
                 exit(EXIT_FAILURE);
             }