diff mbox

[v2,2/7] virtio-blk: avoid qdev property definition duplication

Message ID 1400773210-7584-3-git-send-email-stefanha@redhat.com
State New
Headers show

Commit Message

Stefan Hajnoczi May 22, 2014, 3:40 p.m. UTC
It becomes unwiedly to duplicate all virtio-blk qdev property
definitions due to an #ifdef.  The C preprocessor syntax makes it a
little hard to resolve this cleanly but we can extract the #ifdef and
call a macro it defines later.

Avoiding duplication is important since it will only get worse when we
move the x-data-plane qdev property here too.  We'd have a combinatorial
explosion since x-data-plane has its own #ifdef.

Suggested-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 include/hw/virtio/virtio-blk.h | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

Comments

Peter Crosthwaite May 29, 2014, 8:48 a.m. UTC | #1
On Fri, May 23, 2014 at 1:40 AM, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> It becomes unwiedly to duplicate all virtio-blk qdev property
> definitions due to an #ifdef.  The C preprocessor syntax makes it a
> little hard to resolve this cleanly but we can extract the #ifdef and
> call a macro it defines later.
>
> Avoiding duplication is important since it will only get worse when we
> move the x-data-plane qdev property here too.  We'd have a combinatorial
> explosion since x-data-plane has its own #ifdef.
>
> Suggested-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

> ---
>  include/hw/virtio/virtio-blk.h | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
> index e4c41ff..fa416db 100644
> --- a/include/hw/virtio/virtio-blk.h
> +++ b/include/hw/virtio/virtio-blk.h
> @@ -137,21 +137,19 @@ typedef struct VirtIOBlock {
>          DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
>
>  #ifdef __linux__
> -#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field)                          \
> -        DEFINE_BLOCK_PROPERTIES(_state, _field.conf),                         \
> -        DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf),                     \
> -        DEFINE_PROP_STRING("serial", _state, _field.serial),                  \
> -        DEFINE_PROP_BIT("config-wce", _state, _field.config_wce, 0, true),    \
> -        DEFINE_PROP_BIT("scsi", _state, _field.scsi, 0, true),                \
> -        DEFINE_PROP_IOTHREAD("x-iothread", _state, _field.iothread)
> +#define DEFINE_VIRTIO_BLK_PROPERTIES_LINUX(_state, _field) \
> +        DEFINE_PROP_BIT("scsi", _state, _field.scsi, 0, true),
>  #else
> +#define DEFINE_VIRTIO_BLK_PROPERTIES_LINUX(_state, _field)
> +#endif
> +
>  #define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field)                          \
> +        DEFINE_VIRTIO_BLK_PROPERTIES_LINUX(_state, _field)                    \
>          DEFINE_BLOCK_PROPERTIES(_state, _field.conf),                         \
>          DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf),                     \
>          DEFINE_PROP_STRING("serial", _state, _field.serial),                  \
>          DEFINE_PROP_BIT("config-wce", _state, _field.config_wce, 0, true),    \
>          DEFINE_PROP_IOTHREAD("x-iothread", _state, _field.iothread)
> -#endif /* __linux__ */
>
>  void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk);
>
> --
> 1.9.0
>
>
diff mbox

Patch

diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h
index e4c41ff..fa416db 100644
--- a/include/hw/virtio/virtio-blk.h
+++ b/include/hw/virtio/virtio-blk.h
@@ -137,21 +137,19 @@  typedef struct VirtIOBlock {
         DEFINE_VIRTIO_COMMON_FEATURES(_state, _field)
 
 #ifdef __linux__
-#define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field)                          \
-        DEFINE_BLOCK_PROPERTIES(_state, _field.conf),                         \
-        DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf),                     \
-        DEFINE_PROP_STRING("serial", _state, _field.serial),                  \
-        DEFINE_PROP_BIT("config-wce", _state, _field.config_wce, 0, true),    \
-        DEFINE_PROP_BIT("scsi", _state, _field.scsi, 0, true),                \
-        DEFINE_PROP_IOTHREAD("x-iothread", _state, _field.iothread)
+#define DEFINE_VIRTIO_BLK_PROPERTIES_LINUX(_state, _field) \
+        DEFINE_PROP_BIT("scsi", _state, _field.scsi, 0, true),
 #else
+#define DEFINE_VIRTIO_BLK_PROPERTIES_LINUX(_state, _field)
+#endif
+
 #define DEFINE_VIRTIO_BLK_PROPERTIES(_state, _field)                          \
+        DEFINE_VIRTIO_BLK_PROPERTIES_LINUX(_state, _field)                    \
         DEFINE_BLOCK_PROPERTIES(_state, _field.conf),                         \
         DEFINE_BLOCK_CHS_PROPERTIES(_state, _field.conf),                     \
         DEFINE_PROP_STRING("serial", _state, _field.serial),                  \
         DEFINE_PROP_BIT("config-wce", _state, _field.config_wce, 0, true),    \
         DEFINE_PROP_IOTHREAD("x-iothread", _state, _field.iothread)
-#endif /* __linux__ */
 
 void virtio_blk_set_conf(DeviceState *dev, VirtIOBlkConf *blk);