diff mbox

[18/32] hd-geometry: Switch to uint32_t to match BlockConf

Message ID 1340984094-5451-19-git-send-email-armbru@redhat.com
State New
Headers show

Commit Message

Markus Armbruster June 29, 2012, 3:34 p.m. UTC
Best to use the same type, to avoid unwanted truncation or sign
extension.

BlockConf can't use plain int for cyls, heads and secs, because
integer properties require an exact width.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 blockdev.h       |    2 +-
 hw/hd-geometry.c |    4 ++--
 hw/ide/core.c    |    2 +-
 hw/scsi-disk.c   |    2 +-
 hw/virtio-blk.c  |    2 +-
 5 files changed, 6 insertions(+), 6 deletions(-)

Comments

Blue Swirl June 29, 2012, 8:34 p.m. UTC | #1
On Fri, Jun 29, 2012 at 3:34 PM, Markus Armbruster <armbru@redhat.com> wrote:
> Best to use the same type, to avoid unwanted truncation or sign
> extension.

Awesome patch! :-)

>
> BlockConf can't use plain int for cyls, heads and secs, because
> integer properties require an exact width.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  blockdev.h       |    2 +-
>  hw/hd-geometry.c |    4 ++--
>  hw/ide/core.c    |    2 +-
>  hw/scsi-disk.c   |    2 +-
>  hw/virtio-blk.c  |    2 +-
>  5 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/blockdev.h b/blockdev.h
> index 5288cc8..4f29c8b 100644
> --- a/blockdev.h
> +++ b/blockdev.h
> @@ -66,7 +66,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
>
>  /* Hard disk geometry */
>  void hd_geometry_guess(BlockDriverState *bs,
> -                       int *pcyls, int *pheads, int *psecs,
> +                       uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
>                        int *ptrans);
>
>  #endif
> diff --git a/hw/hd-geometry.c b/hw/hd-geometry.c
> index 208cb42..6dd5713 100644
> --- a/hw/hd-geometry.c
> +++ b/hw/hd-geometry.c
> @@ -89,7 +89,7 @@ static int guess_disk_lchs(BlockDriverState *bs,
>  }
>
>  static void guess_chs_for_size(BlockDriverState *bs,
> -                               int *pcyls, int *pheads, int *psecs)
> +                uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs)
>  {
>     uint64_t nb_sectors;
>     int cylinders;
> @@ -108,7 +108,7 @@ static void guess_chs_for_size(BlockDriverState *bs,
>  }
>
>  void hd_geometry_guess(BlockDriverState *bs,
> -                       int *pcyls, int *pheads, int *psecs,
> +                       uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
>                        int *ptrans)
>  {
>     int cylinders, heads, secs, translation;
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index 4a54833..d8cd2a6 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -1926,7 +1926,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
>                    const char *version, const char *serial, const char *model,
>                    uint64_t wwn)
>  {
> -    int cylinders, heads, secs;
> +    uint32_t cylinders, heads, secs;
>     uint64_t nb_sectors;
>
>     s->bs = bs;
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index 7a75e15..e9efcd6 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -926,7 +926,7 @@ static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
>     };
>
>     BlockDriverState *bdrv = s->qdev.conf.bs;
> -    int cylinders, heads, secs;
> +    uint32_t cylinders, heads, secs;
>     uint8_t *p = *p_outbuf;
>
>     if ((mode_sense_valid[page] & (1 << s->qdev.type)) == 0) {
> diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
> index e4f9906..854739d 100644
> --- a/hw/virtio-blk.c
> +++ b/hw/virtio-blk.c
> @@ -589,7 +589,7 @@ static const BlockDevOps virtio_block_ops = {
>  VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
>  {
>     VirtIOBlock *s;
> -    int cylinders, heads, secs;
> +    uint32_t cylinders, heads, secs;
>     static int virtio_blk_id;
>     DriveInfo *dinfo;
>
> --
> 1.7.6.5
>
>
Stefan Hajnoczi July 2, 2012, 12:55 p.m. UTC | #2
On Fri, Jun 29, 2012 at 05:34:40PM +0200, Markus Armbruster wrote:
> Best to use the same type, to avoid unwanted truncation or sign
> extension.
> 
> BlockConf can't use plain int for cyls, heads and secs, because
> integer properties require an exact width.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> ---
>  blockdev.h       |    2 +-
>  hw/hd-geometry.c |    4 ++--
>  hw/ide/core.c    |    2 +-
>  hw/scsi-disk.c   |    2 +-
>  hw/virtio-blk.c  |    2 +-
>  5 files changed, 6 insertions(+), 6 deletions(-)

It would be nice to update the hd_geometry_lchs_guess() trace event that
you added to use uint32_t + %u instead of int + %d.

Stefan
Andreas Färber July 2, 2012, 1:07 p.m. UTC | #3
Am 02.07.2012 14:55, schrieb Stefan Hajnoczi:
> On Fri, Jun 29, 2012 at 05:34:40PM +0200, Markus Armbruster wrote:
>> Best to use the same type, to avoid unwanted truncation or sign
>> extension.
>>
>> BlockConf can't use plain int for cyls, heads and secs, because
>> integer properties require an exact width.
>>
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>> ---
>>  blockdev.h       |    2 +-
>>  hw/hd-geometry.c |    4 ++--
>>  hw/ide/core.c    |    2 +-
>>  hw/scsi-disk.c   |    2 +-
>>  hw/virtio-blk.c  |    2 +-
>>  5 files changed, 6 insertions(+), 6 deletions(-)
> 
> It would be nice to update the hd_geometry_lchs_guess() trace event that
> you added to use uint32_t + %u instead of int + %d.

PRIu32?

Andreas
Markus Armbruster July 2, 2012, 2:15 p.m. UTC | #4
Andreas Färber <afaerber@suse.de> writes:

> Am 02.07.2012 14:55, schrieb Stefan Hajnoczi:
>> On Fri, Jun 29, 2012 at 05:34:40PM +0200, Markus Armbruster wrote:
>>> Best to use the same type, to avoid unwanted truncation or sign
>>> extension.
>>>
>>> BlockConf can't use plain int for cyls, heads and secs, because
>>> integer properties require an exact width.
>>>
>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>> ---
>>>  blockdev.h       |    2 +-
>>>  hw/hd-geometry.c |    4 ++--
>>>  hw/ide/core.c    |    2 +-
>>>  hw/scsi-disk.c   |    2 +-
>>>  hw/virtio-blk.c  |    2 +-
>>>  5 files changed, 6 insertions(+), 6 deletions(-)
>> 
>> It would be nice to update the hd_geometry_lchs_guess() trace event that
>> you added to use uint32_t + %u instead of int + %d.
>
> PRIu32?

uint32_t: Good point, will do.

Conversion specifier: trace-events routinely prints uint32_t with %d and
%x, never with PRI*32.  I'm happy to change from %d to %u, but reluctant
to add the first use of PRIu32.
Stefan Hajnoczi July 2, 2012, 2:34 p.m. UTC | #5
On Mon, Jul 2, 2012 at 3:15 PM, Markus Armbruster <armbru@redhat.com> wrote:
> Andreas Färber <afaerber@suse.de> writes:
>
>> Am 02.07.2012 14:55, schrieb Stefan Hajnoczi:
>>> On Fri, Jun 29, 2012 at 05:34:40PM +0200, Markus Armbruster wrote:
>>>> Best to use the same type, to avoid unwanted truncation or sign
>>>> extension.
>>>>
>>>> BlockConf can't use plain int for cyls, heads and secs, because
>>>> integer properties require an exact width.
>>>>
>>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>>> ---
>>>>  blockdev.h       |    2 +-
>>>>  hw/hd-geometry.c |    4 ++--
>>>>  hw/ide/core.c    |    2 +-
>>>>  hw/scsi-disk.c   |    2 +-
>>>>  hw/virtio-blk.c  |    2 +-
>>>>  5 files changed, 6 insertions(+), 6 deletions(-)
>>>
>>> It would be nice to update the hd_geometry_lchs_guess() trace event that
>>> you added to use uint32_t + %u instead of int + %d.
>>
>> PRIu32?
>
> uint32_t: Good point, will do.
>
> Conversion specifier: trace-events routinely prints uint32_t with %d and
> %x, never with PRI*32.  I'm happy to change from %d to %u, but reluctant
> to add the first use of PRIu32.

Either is fine by me although we might as well continue to do %u.

Stefan
Blue Swirl July 3, 2012, 7:11 p.m. UTC | #6
On Mon, Jul 2, 2012 at 2:34 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
> On Mon, Jul 2, 2012 at 3:15 PM, Markus Armbruster <armbru@redhat.com> wrote:
>> Andreas Färber <afaerber@suse.de> writes:
>>
>>> Am 02.07.2012 14:55, schrieb Stefan Hajnoczi:
>>>> On Fri, Jun 29, 2012 at 05:34:40PM +0200, Markus Armbruster wrote:
>>>>> Best to use the same type, to avoid unwanted truncation or sign
>>>>> extension.
>>>>>
>>>>> BlockConf can't use plain int for cyls, heads and secs, because
>>>>> integer properties require an exact width.
>>>>>
>>>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>>>> ---
>>>>>  blockdev.h       |    2 +-
>>>>>  hw/hd-geometry.c |    4 ++--
>>>>>  hw/ide/core.c    |    2 +-
>>>>>  hw/scsi-disk.c   |    2 +-
>>>>>  hw/virtio-blk.c  |    2 +-
>>>>>  5 files changed, 6 insertions(+), 6 deletions(-)
>>>>
>>>> It would be nice to update the hd_geometry_lchs_guess() trace event that
>>>> you added to use uint32_t + %u instead of int + %d.
>>>
>>> PRIu32?
>>
>> uint32_t: Good point, will do.
>>
>> Conversion specifier: trace-events routinely prints uint32_t with %d and
>> %x, never with PRI*32.  I'm happy to change from %d to %u, but reluctant
>> to add the first use of PRIu32.
>
> Either is fine by me although we might as well continue to do %u.

I'd also vote for %u. PRI*32 do not seem very useful compared to plain
int versions.

>
> Stefan
>
Andreas Färber July 3, 2012, 8:15 p.m. UTC | #7
Am 03.07.2012 21:11, schrieb Blue Swirl:
> On Mon, Jul 2, 2012 at 2:34 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>> On Mon, Jul 2, 2012 at 3:15 PM, Markus Armbruster <armbru@redhat.com> wrote:
>>> Andreas Färber <afaerber@suse.de> writes:
>>>
>>>> Am 02.07.2012 14:55, schrieb Stefan Hajnoczi:
>>>>> On Fri, Jun 29, 2012 at 05:34:40PM +0200, Markus Armbruster wrote:
>>>>>> Best to use the same type, to avoid unwanted truncation or sign
>>>>>> extension.
>>>>>>
>>>>>> BlockConf can't use plain int for cyls, heads and secs, because
>>>>>> integer properties require an exact width.
>>>>>>
>>>>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>>>>> ---
>>>>>>  blockdev.h       |    2 +-
>>>>>>  hw/hd-geometry.c |    4 ++--
>>>>>>  hw/ide/core.c    |    2 +-
>>>>>>  hw/scsi-disk.c   |    2 +-
>>>>>>  hw/virtio-blk.c  |    2 +-
>>>>>>  5 files changed, 6 insertions(+), 6 deletions(-)
>>>>>
>>>>> It would be nice to update the hd_geometry_lchs_guess() trace event that
>>>>> you added to use uint32_t + %u instead of int + %d.
>>>>
>>>> PRIu32?
>>>
>>> uint32_t: Good point, will do.
>>>
>>> Conversion specifier: trace-events routinely prints uint32_t with %d and
>>> %x, never with PRI*32.  I'm happy to change from %d to %u, but reluctant
>>> to add the first use of PRIu32.
>>
>> Either is fine by me although we might as well continue to do %u.
> 
> I'd also vote for %u. PRI*32 do not seem very useful compared to plain
> int versions.

If it's not useful we should use unsigned int.

Mixing both is simply wrong. I'm okay with fixing it consistently in a
follow-up though. The Broken Window theory scores again (lack of const,
non-CamelCase type names, placement of {, wrong semicolons, etc.).

Andreas
Paolo Bonzini July 4, 2012, 4:19 p.m. UTC | #8
Il 03/07/2012 22:15, Andreas Färber ha scritto:
>> > 
>> > I'd also vote for %u. PRI*32 do not seem very useful compared to plain
>> > int versions.
> If it's not useful we should use unsigned int.

It just means that we're assuming 32-bit ints, which is a fact.  The day
an IL32 platform appears that has "typedef long int32_t", we'll worry
about PRIu32.

Paolo

> Mixing both is simply wrong. I'm okay with fixing it consistently in a
> follow-up though. The Broken Window theory scores again (lack of const,
> non-CamelCase type names, placement of {, wrong semicolons, etc.).
Eric Blake July 4, 2012, 4:36 p.m. UTC | #9
On 07/04/2012 10:19 AM, Paolo Bonzini wrote:
> Il 03/07/2012 22:15, Andreas Färber ha scritto:
>>>>
>>>> I'd also vote for %u. PRI*32 do not seem very useful compared to plain
>>>> int versions.
>> If it's not useful we should use unsigned int.
> 
> It just means that we're assuming 32-bit ints, which is a fact.  The day
> an IL32 platform appears that has "typedef long int32_t", we'll worry
> about PRIu32.

Newlib's <stdint.h> does just that, on platforms that __have_long32.
Which makes Cygwin a great platform for flushing out these sorts of type
discrepancies (since cygwin inherits from newlib).

http://sourceware.org/cgi-bin/cvsweb.cgi/src/newlib/libc/include/stdint.h.diff?r1=1.8&r2=1.9&cvsroot=src&f=h
Blue Swirl July 5, 2012, 6:30 p.m. UTC | #10
On Tue, Jul 3, 2012 at 8:15 PM, Andreas Färber <afaerber@suse.de> wrote:
> Am 03.07.2012 21:11, schrieb Blue Swirl:
>> On Mon, Jul 2, 2012 at 2:34 PM, Stefan Hajnoczi <stefanha@gmail.com> wrote:
>>> On Mon, Jul 2, 2012 at 3:15 PM, Markus Armbruster <armbru@redhat.com> wrote:
>>>> Andreas Färber <afaerber@suse.de> writes:
>>>>
>>>>> Am 02.07.2012 14:55, schrieb Stefan Hajnoczi:
>>>>>> On Fri, Jun 29, 2012 at 05:34:40PM +0200, Markus Armbruster wrote:
>>>>>>> Best to use the same type, to avoid unwanted truncation or sign
>>>>>>> extension.
>>>>>>>
>>>>>>> BlockConf can't use plain int for cyls, heads and secs, because
>>>>>>> integer properties require an exact width.
>>>>>>>
>>>>>>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>>>>>>> ---
>>>>>>>  blockdev.h       |    2 +-
>>>>>>>  hw/hd-geometry.c |    4 ++--
>>>>>>>  hw/ide/core.c    |    2 +-
>>>>>>>  hw/scsi-disk.c   |    2 +-
>>>>>>>  hw/virtio-blk.c  |    2 +-
>>>>>>>  5 files changed, 6 insertions(+), 6 deletions(-)
>>>>>>
>>>>>> It would be nice to update the hd_geometry_lchs_guess() trace event that
>>>>>> you added to use uint32_t + %u instead of int + %d.
>>>>>
>>>>> PRIu32?
>>>>
>>>> uint32_t: Good point, will do.
>>>>
>>>> Conversion specifier: trace-events routinely prints uint32_t with %d and
>>>> %x, never with PRI*32.  I'm happy to change from %d to %u, but reluctant
>>>> to add the first use of PRIu32.
>>>
>>> Either is fine by me although we might as well continue to do %u.
>>
>> I'd also vote for %u. PRI*32 do not seem very useful compared to plain
>> int versions.
>
> If it's not useful we should use unsigned int.
>
> Mixing both is simply wrong. I'm okay with fixing it consistently in a
> follow-up though. The Broken Window theory scores again (lack of const,
> non-CamelCase type names, placement of {, wrong semicolons, etc.).

Since the 'const' issues are not related to CODING_STYLE (for those
Anthony vetoes global reformatting), I think global patches
(preferably broken down for bisection though) should be OK.

What's wrong with the semicolons?

>
> Andreas
>
> --
> SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
> GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
Blue Swirl July 5, 2012, 6:37 p.m. UTC | #11
On Wed, Jul 4, 2012 at 4:36 PM, Eric Blake <eblake@redhat.com> wrote:
> On 07/04/2012 10:19 AM, Paolo Bonzini wrote:
>> Il 03/07/2012 22:15, Andreas Färber ha scritto:
>>>>>
>>>>> I'd also vote for %u. PRI*32 do not seem very useful compared to plain
>>>>> int versions.
>>> If it's not useful we should use unsigned int.
>>
>> It just means that we're assuming 32-bit ints, which is a fact.  The day
>> an IL32 platform appears that has "typedef long int32_t", we'll worry
>> about PRIu32.
>
> Newlib's <stdint.h> does just that, on platforms that __have_long32.
> Which makes Cygwin a great platform for flushing out these sorts of type
> discrepancies (since cygwin inherits from newlib).
>
> http://sourceware.org/cgi-bin/cvsweb.cgi/src/newlib/libc/include/stdint.h.diff?r1=1.8&r2=1.9&cvsroot=src&f=h

Interesting, my thoughts went pretty much along Paolo's line. Now I
think PRI*32 indeed makes some sense.

But we don't support Cygwin builds (only mingw), would that be useful?

>
> --
> Eric Blake   eblake@redhat.com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>
>
>
diff mbox

Patch

diff --git a/blockdev.h b/blockdev.h
index 5288cc8..4f29c8b 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -66,7 +66,7 @@  int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
 
 /* Hard disk geometry */
 void hd_geometry_guess(BlockDriverState *bs,
-                       int *pcyls, int *pheads, int *psecs,
+                       uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
                        int *ptrans);
 
 #endif
diff --git a/hw/hd-geometry.c b/hw/hd-geometry.c
index 208cb42..6dd5713 100644
--- a/hw/hd-geometry.c
+++ b/hw/hd-geometry.c
@@ -89,7 +89,7 @@  static int guess_disk_lchs(BlockDriverState *bs,
 }
 
 static void guess_chs_for_size(BlockDriverState *bs,
-                               int *pcyls, int *pheads, int *psecs)
+                uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs)
 {
     uint64_t nb_sectors;
     int cylinders;
@@ -108,7 +108,7 @@  static void guess_chs_for_size(BlockDriverState *bs,
 }
 
 void hd_geometry_guess(BlockDriverState *bs,
-                       int *pcyls, int *pheads, int *psecs,
+                       uint32_t *pcyls, uint32_t *pheads, uint32_t *psecs,
                        int *ptrans)
 {
     int cylinders, heads, secs, translation;
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 4a54833..d8cd2a6 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -1926,7 +1926,7 @@  int ide_init_drive(IDEState *s, BlockDriverState *bs, IDEDriveKind kind,
                    const char *version, const char *serial, const char *model,
                    uint64_t wwn)
 {
-    int cylinders, heads, secs;
+    uint32_t cylinders, heads, secs;
     uint64_t nb_sectors;
 
     s->bs = bs;
diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
index 7a75e15..e9efcd6 100644
--- a/hw/scsi-disk.c
+++ b/hw/scsi-disk.c
@@ -926,7 +926,7 @@  static int mode_sense_page(SCSIDiskState *s, int page, uint8_t **p_outbuf,
     };
 
     BlockDriverState *bdrv = s->qdev.conf.bs;
-    int cylinders, heads, secs;
+    uint32_t cylinders, heads, secs;
     uint8_t *p = *p_outbuf;
 
     if ((mode_sense_valid[page] & (1 << s->qdev.type)) == 0) {
diff --git a/hw/virtio-blk.c b/hw/virtio-blk.c
index e4f9906..854739d 100644
--- a/hw/virtio-blk.c
+++ b/hw/virtio-blk.c
@@ -589,7 +589,7 @@  static const BlockDevOps virtio_block_ops = {
 VirtIODevice *virtio_blk_init(DeviceState *dev, VirtIOBlkConf *blk)
 {
     VirtIOBlock *s;
-    int cylinders, heads, secs;
+    uint32_t cylinders, heads, secs;
     static int virtio_blk_id;
     DriveInfo *dinfo;