Skip to contentSkip to conversation

fix bdrv_check_request for byte-granularity requests

PATCH In review Christoph Hellwig 2 participants 5 messages Mar 14, 2009 – Mar 29, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fix bdrv_check_request for byte-granularity requests

We never allow the offset to be byte-granularity for the sector-based interface, instead the negative value for byte values applied to the request length.

block.c +5 -5
Index: qemu/block.c
===================================================================
@@ -542,15 +542,15 @@ static int bdrv_check_byte_request(Block
 static int bdrv_check_request(BlockDriverState *bs, int64_t sector_num,
                               int nb_sectors)
 {
-    int64_t offset;
+    size_t len;
 
     /* Deal with byte accesses */
-    if (sector_num < 0)
-        offset = -sector_num;
+    if (nb_sectors < 0)
+        len = -nb_sectors;
     else
-        offset = sector_num * 512;
+        len = nb_sectors * 512;
 
-    return bdrv_check_byte_request(bs, offset, nb_sectors * 512);
+    return bdrv_check_byte_request(bs, sector_num * 512, len);
 }
 
 /* return < 0 if error. See bdrv_write() for the return codes */
#1 lore raw
Quoted 3 lines · Christoph Hellwig

We never allow the offset to be byte-granularity for the sector-based interface, instead the negative value for byte values applied to the request length.

Actually - looking over the updates that happened during the week that I was away it looks like the whole negative length hack is gone now, so we can simplify bdrv_check_request instead:

block.c +1 -9
Index: qemu/block.c
===================================================================
@@ -546,15 +546,7 @@ static int bdrv_check_byte_request(Block
 static int bdrv_check_request(BlockDriverState *bs, int64_t sector_num,
                               int nb_sectors)
 {
-    int64_t offset;
-
-    /* Deal with byte accesses */
-    if (sector_num < 0)
-        offset = -sector_num;
-    else
-        offset = sector_num * 512;
-
-    return bdrv_check_byte_request(bs, offset, nb_sectors * 512);
+    return bdrv_check_byte_request(bs, sector_num * 512, nb_sectors * 512);
 }
 
 /* return < 0 if error. See bdrv_write() for the return codes */
#2 lore raw
Quoted 11 lines · Christoph Hellwig
Quoted 4 lines · Christoph Hellwig

We never allow the offset to be byte-granularity for the sector-based interface, instead the negative value for byte values applied to the request length.

Actually - looking over the updates that happened during the week that I was away it looks like the whole negative length hack is gone now, so we can simplify bdrv_check_request instead:

Needs a SoB.

Regards,

Anthony Liguori

Quoted 25 lines

Index: qemu/block.c
===================================================================

block.c +1 -9
@@ -546,15 +546,7 @@ static int bdrv_check_byte_request(Block
 static int bdrv_check_request(BlockDriverState *bs, int64_t sector_num,
                               int nb_sectors)
 {
-    int64_t offset;
-
-    /* Deal with byte accesses */
-    if (sector_num < 0)
-        offset = -sector_num;
-    else
-        offset = sector_num * 512;
-
-    return bdrv_check_byte_request(bs, offset, nb_sectors * 512);
+    return bdrv_check_byte_request(bs, sector_num * 512, nb_sectors * 512);
 }
 
 /* return < 0 if error. See bdrv_write() for the return codes */
#3 lore raw

PATCH 1/1 remove dead code in bdrv_check_request

Remove code dealing with negative sector numbers for byte access in bdrv_check_request as sector numbers can't ever be negative.

Previously we supported negative sector counts for byte access, but never sector numbers.

block.c +1 -9
Index: qemu/block.c
===================================================================
@@ -546,15 +546,7 @@ static int bdrv_check_byte_request(Block
 static int bdrv_check_request(BlockDriverState *bs, int64_t sector_num,
                               int nb_sectors)
 {
-    int64_t offset;
-
-    /* Deal with byte accesses */
-    if (sector_num < 0)
-        offset = -sector_num;
-    else
-        offset = sector_num * 512;
-
-    return bdrv_check_byte_request(bs, offset, nb_sectors * 512);
+    return bdrv_check_byte_request(bs, sector_num * 512, nb_sectors * 512);
 }
 
 /* return < 0 if error. See bdrv_write() for the return codes */
#4 lore raw

Re: [Qemu-devel] [PATCH] remove dead code in bdrv_check_request

Quoted 9 lines · Christoph Hellwig

Remove code dealing with negative sector numbers for byte access in bdrv_check_request as sector numbers can't ever be negative.

Previously we supported negative sector counts for byte access, but never sector numbers.

Applied. Thanks for resending this.

Regards,

Anthony Liguori

Quoted 25 lines

Index: qemu/block.c
===================================================================

block.c +1 -9
@@ -546,15 +546,7 @@ static int bdrv_check_byte_request(Block
 static int bdrv_check_request(BlockDriverState *bs, int64_t sector_num,
                               int nb_sectors)
 {
-    int64_t offset;
-
-    /* Deal with byte accesses */
-    if (sector_num < 0)
-        offset = -sector_num;
-    else
-        offset = sector_num * 512;
-
-    return bdrv_check_byte_request(bs, offset, nb_sectors * 512);
+    return bdrv_check_byte_request(bs, sector_num * 512, nb_sectors * 512);
 }
 
 /* return < 0 if error. See bdrv_write() for the return codes */