Skip to contentSkip to conversation

rbd: shift byte count as a 64-bit value

PATCH In review Paolo Bonzini 2 participants 2 messages Oct 10, 2016 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rbd: shift byte count as a 64-bit value

Otherwise, reads of more than 2GB fail. Until commit 7bbca9e290a9c7c217b5a24fc6094e91e54bd05d, reads of 2^41 bytes succeeded at least theoretically.

In fact, pdiscard ought to receive a 64-bit integer as the count for the same reason.

Reported by Coverity.

Fixes 7bbca9e290a9c7c217b5a24fc6094e91e54bd05d
---
 block/rbd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
block/rbd.c +2 -2
index 6f9eb6f..f6e1d4b 100644
@@ -733,7 +733,7 @@ static BlockAIOCB *qemu_rbd_aio_readv(BlockDriverState *bs,
                                       void *opaque)
 {
     return rbd_start_aio(bs, sector_num << BDRV_SECTOR_BITS, qiov,
-                         nb_sectors << BDRV_SECTOR_BITS, cb, opaque,
+                         (int64_t) nb_sectors << BDRV_SECTOR_BITS, cb, opaque,
                          RBD_AIO_READ);
 }
 
@@ -745,7 +745,7 @@ static BlockAIOCB *qemu_rbd_aio_writev(BlockDriverState *bs,
                                        void *opaque)
 {
     return rbd_start_aio(bs, sector_num << BDRV_SECTOR_BITS, qiov,
-                         nb_sectors << BDRV_SECTOR_BITS, cb, opaque,
+                         (int64_t) nb_sectors << BDRV_SECTOR_BITS, cb, opaque,
                          RBD_AIO_WRITE);
 }
 
Signature · 1 line
2.7.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Paolo Bonzini

Otherwise, reads of more than 2GB fail. Until commit 7bbca9e290a9c7c217b5a24fc6094e91e54bd05d, reads of 2^41 bytes succeeded at least theoretically.

I don't think the block layer ever passes a read request down to drivers that large in the first place; we have a lot of code in io.c that clamps/asserts things to be smaller than 2^31 (ie. BDRV_REQUEST_MAX_SECTORS). So this may just be cleaning up something that would become latent with a future block change to support larger sizes, rather than an actual bug fix today. But it is worth making.

Quoted 2 lines

In fact, pdiscard ought to receive a 64-bit integer as the count for the same reason.

Yes, auditing ALL of the block code for eliminating arbitrary 32-bit limits would be a big project.

Quoted 11 lines

Reported by Coverity.

Fixes 7bbca9e290a9c7c217b5a24fc6094e91e54bd05d
---
 block/rbd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org