diff mbox series

[v2,2/8] virtio-blk: utilize VirtIOConfigSizeParams & virtio_get_config_size

Message ID 20220826143248.580939-3-d-tatianin@yandex-team.ru (mailing list archive)
State New, archived
Headers show
Series vhost-user-blk: dynamically resize config space based on features | expand

Commit Message

Daniil Tatianin Aug. 26, 2022, 2:32 p.m. UTC
Use the common helper instead of duplicating the same logic.

Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
---
 hw/block/virtio-blk.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Comments

Raphael Norwitz Sept. 2, 2022, 5:52 p.m. UTC | #1
On Fri, Aug 26, 2022 at 05:32:42PM +0300, Daniil Tatianin wrote:
> Use the common helper instead of duplicating the same logic.
> 
> Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>

Reviewed-by: Raphael Norwitz <raphael.norwitz@nutanix.com>

> ---
>  hw/block/virtio-blk.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
> index e9ba752f6b..10c47c2934 100644
> --- a/hw/block/virtio-blk.c
> +++ b/hw/block/virtio-blk.c
> @@ -49,13 +49,11 @@ static const VirtIOFeature feature_sizes[] = {
>      {}
>  };
>  
> -static void virtio_blk_set_config_size(VirtIOBlock *s, uint64_t host_features)
> -{
> -    s->config_size = MAX(VIRTIO_BLK_CFG_SIZE,
> -        virtio_feature_get_config_size(feature_sizes, host_features));
> -
> -    assert(s->config_size <= sizeof(struct virtio_blk_config));
> -}
> +static const VirtIOConfigSizeParams cfg_size_params = {
> +    .min_size = VIRTIO_BLK_CFG_SIZE,
> +    .max_size = sizeof(struct virtio_blk_config),
> +    .feature_sizes = feature_sizes
> +};
>  
>  static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
>                                      VirtIOBlockReq *req)
> @@ -1204,8 +1202,8 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
>          return;
>      }
>  
> -    virtio_blk_set_config_size(s, s->host_features);
> -
> +    s->config_size = virtio_get_config_size(&cfg_size_params,
> +                                            s->host_features);
>      virtio_init(vdev, VIRTIO_ID_BLOCK, s->config_size);
>  
>      s->blk = conf->conf.blk;
> -- 
> 2.25.1
>
diff mbox series

Patch

diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index e9ba752f6b..10c47c2934 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -49,13 +49,11 @@  static const VirtIOFeature feature_sizes[] = {
     {}
 };
 
-static void virtio_blk_set_config_size(VirtIOBlock *s, uint64_t host_features)
-{
-    s->config_size = MAX(VIRTIO_BLK_CFG_SIZE,
-        virtio_feature_get_config_size(feature_sizes, host_features));
-
-    assert(s->config_size <= sizeof(struct virtio_blk_config));
-}
+static const VirtIOConfigSizeParams cfg_size_params = {
+    .min_size = VIRTIO_BLK_CFG_SIZE,
+    .max_size = sizeof(struct virtio_blk_config),
+    .feature_sizes = feature_sizes
+};
 
 static void virtio_blk_init_request(VirtIOBlock *s, VirtQueue *vq,
                                     VirtIOBlockReq *req)
@@ -1204,8 +1202,8 @@  static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
         return;
     }
 
-    virtio_blk_set_config_size(s, s->host_features);
-
+    s->config_size = virtio_get_config_size(&cfg_size_params,
+                                            s->host_features);
     virtio_init(vdev, VIRTIO_ID_BLOCK, s->config_size);
 
     s->blk = conf->conf.blk;