Re: [Qemu-block] [PATCH v2] block: unify blocksize types

2018-02-16 Thread Alberto Garcia
On Fri 09 Feb 2018 10:53:12 AM CET, Piotr Sarna wrote:
> BlockSizes structure used in block size probing has uint32_t types
> for logical and physical sizes. These fields are wrongfully assigned
> to uint16_t in BlockConf, which results, among other errors,
> in assigning 0 instead of 65536 (which will be the case in at least
> future LizardFS block device driver among other things).
>
> This commit makes BlockConf's physical_block_size and logical_block_size
> fields uint32_t to avoid inconsistencies.
>
> Signed-off-by: Piotr Sarna 
> ---
>  hw/core/qdev-properties.c| 10 +-
>  include/hw/block/block.h |  4 ++--
>  include/hw/qdev-properties.h |  2 +-
>  3 files changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 5bbc2d9..1400ba5 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -731,14 +731,14 @@ static void set_blocksize(Object *obj, Visitor *v, 
> const char *name,
>  uint16_t value, *ptr = qdev_get_prop_ptr(dev, prop);
>  Error *local_err = NULL;
>  const int64_t min = 512;
> -const int64_t max = 32768;
> +const int64_t max = 2147483648;
>  
>  if (dev->realized) {
>  qdev_prop_set_after_realize(dev, name, errp);
>  return;
>  }
>  
> -visit_type_uint16(v, name, , _err);
> +visit_type_uint32(v, name, , _err);

I'm not familiar with this code so apologies if there's something that I
have overlooked, but it catches my attention that

   a) you're using 2147483648 as an upper limit, that's INT32_MAX + 1.
  Where does that value come from? It's certainly not the highest
  value that a uint32_t can hold, and it doesn't fit in an int32_t
  either.

   b) you're using visit_type_uint32() but the 'value' you're passing is
  a uint16_t (also *ptr later in the same function).

Berto



[Qemu-block] [PATCH v2] block: unify blocksize types

2018-02-09 Thread Piotr Sarna
BlockSizes structure used in block size probing has uint32_t types
for logical and physical sizes. These fields are wrongfully assigned
to uint16_t in BlockConf, which results, among other errors,
in assigning 0 instead of 65536 (which will be the case in at least
future LizardFS block device driver among other things).

This commit makes BlockConf's physical_block_size and logical_block_size
fields uint32_t to avoid inconsistencies.

Signed-off-by: Piotr Sarna 
---
 hw/core/qdev-properties.c| 10 +-
 include/hw/block/block.h |  4 ++--
 include/hw/qdev-properties.h |  2 +-
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 5bbc2d9..1400ba5 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -731,14 +731,14 @@ static void set_blocksize(Object *obj, Visitor *v, const 
char *name,
 uint16_t value, *ptr = qdev_get_prop_ptr(dev, prop);
 Error *local_err = NULL;
 const int64_t min = 512;
-const int64_t max = 32768;
+const int64_t max = 2147483648;
 
 if (dev->realized) {
 qdev_prop_set_after_realize(dev, name, errp);
 return;
 }
 
-visit_type_uint16(v, name, , _err);
+visit_type_uint32(v, name, , _err);
 if (local_err) {
 error_propagate(errp, local_err);
 return;
@@ -762,9 +762,9 @@ static void set_blocksize(Object *obj, Visitor *v, const 
char *name,
 }
 
 const PropertyInfo qdev_prop_blocksize = {
-.name  = "uint16",
-.description = "A power of two between 512 and 32768",
-.get   = get_uint16,
+.name  = "uint32",
+.description = "A power of two between 512 and 2147483648",
+.get   = get_uint32,
 .set   = set_blocksize,
 .set_default_value = set_default_value_uint,
 };
diff --git a/include/hw/block/block.h b/include/hw/block/block.h
index 64b9298..c9e6e27 100644
--- a/include/hw/block/block.h
+++ b/include/hw/block/block.h
@@ -17,8 +17,8 @@
 
 typedef struct BlockConf {
 BlockBackend *blk;
-uint16_t physical_block_size;
-uint16_t logical_block_size;
+uint32_t physical_block_size;
+uint32_t logical_block_size;
 uint16_t min_io_size;
 uint32_t opt_io_size;
 int32_t bootindex;
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 1d61a35..c68d7bf 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -210,7 +210,7 @@ extern const PropertyInfo qdev_prop_off_auto_pcibar;
 #define DEFINE_PROP_BIOS_CHS_TRANS(_n, _s, _f, _d) \
 DEFINE_PROP_SIGNED(_n, _s, _f, _d, qdev_prop_bios_chs_trans, int)
 #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f) \
-DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint16_t)
+DEFINE_PROP_UNSIGNED(_n, _s, _f, 0, qdev_prop_blocksize, uint32_t)
 #define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
 DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
 #define DEFINE_PROP_MEMORY_REGION(_n, _s, _f) \
-- 
2.7.4