[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v6 09/20] parallels: Switch to .bdrv_co_block_st
From: |
Eric Blake |
Subject: |
Re: [Qemu-devel] [PATCH v6 09/20] parallels: Switch to .bdrv_co_block_status() |
Date: |
Tue, 12 Dec 2017 10:32:18 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 |
On 12/11/2017 09:24 AM, Vladimir Sementsov-Ogievskiy wrote:
>> On the other hand, '<< BDRV_SECTOR_BITS' only produces the same size
>> output as the input; if the left side is 32 bits, it risks overflowing.
>> But '* BDRV_SECTOR_SIZE' always produces a 64-bit value. So I've
>> learned (from past mistakes in other byte-conversion series) that the
>> multiply form is less likely to introduce unintended truncation bugs.
>
> hm, now I doubt. I've wrote tiny program:
>
> #include <stdint.h>
> #include <stdio.h>
>
> int main() {
> uint32_t blocks = 1 << 20;
> int block_bits = 15;
> uint32_t block_size = 1 << block_bits;
> uint64_t a = blocks * block_size;
> uint64_t b = blocks << block_bits;
> uint64_t c = (uint64_t)blocks * block_size;
Not the same. 'block_size' in your code is 'uint32_t', so your
multiplication is still 32-bit if you don't cast blocks; while qemu has::
include/block/block.h:#define BDRV_SECTOR_BITS 9
include/block/block.h:#define BDRV_SECTOR_SIZE (1ULL << BDRV_SECTOR_BITS)
and the 1ULL in the qemu definition forces 'unsigned long long' results
whether or not you cast.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature
- Re: [Qemu-devel] [PATCH v6 05/20] iscsi: Switch cluster_sectors to byte-based, (continued)
[Qemu-devel] [PATCH v6 10/20] qcow: Switch to .bdrv_co_block_status(), Eric Blake, 2017/12/07
[Qemu-devel] [PATCH v6 11/20] qcow2: Switch to .bdrv_co_block_status(), Eric Blake, 2017/12/07
[Qemu-devel] [PATCH v6 12/20] qed: Switch to .bdrv_co_block_status(), Eric Blake, 2017/12/07
[Qemu-devel] [PATCH v6 13/20] raw: Switch to .bdrv_co_block_status(), Eric Blake, 2017/12/07
[Qemu-devel] [PATCH v6 14/20] sheepdog: Switch to .bdrv_co_block_status(), Eric Blake, 2017/12/07