virtio-blk: set correct config size for the host driver
PATCH 1/1 virtio-blk: set correct config size for the host driver
Commit caa1ee43 "vhost-user-blk: add discard/write zeroes features support" introduced extra fields to existing struct virtio_blk_config, when migration was executed from older QEMU version to current head, it will break the migration. While here, set the correct config size when initializing the host driver, for now, discard/write zeroes are not supported by virtio-blk host driver, so set the config size as before, users can change config size when adding the new feature bits support.
--- hw/block/virtio-blk.c | 15 +++++++++++---- include/hw/virtio/virtio-blk.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-)
hw/block/virtio-blk.c +11 -4
@@ -761,7 +761,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) blkcfg.alignment_offset =0 ; blkcfg.wce =blk_enable_write_cache (s->blk);virtio_stw_p (vdev, &blkcfg.num_queues, s->conf.num_queues); -memcpy (config, &blkcfg,sizeof (struct virtio_blk_config )); +memcpy (config, &blkcfg, s->config_size); }static void virtio_blk_set_config (VirtIODevice *vdev,const uint8_t *config)
@@ -769,7 +769,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)VirtIOBlock *s =VIRTIO_BLK (vdev);struct virtio_blk_config blkcfg; -memcpy (&blkcfg, config,sizeof (blkcfg)); +memcpy (&blkcfg, config, s->config_size);aio_context_acquire (blk_get_aio_context (s->blk));blk_set_enable_write_cache (s->blk, blkcfg.wce !=0 );
@@ -847,6 +847,13 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status) } } +static void virtio_blk_set_config_size (VirtIOBlock *s) +{ +/* VIRTIO_BLK_F_MQ is supported by host driver */ + s->config_size = offsetof(struct virtio_blk_config , num_queues) + + sizeof_field(struct virtio_blk_config, num_queues); +} +static void virtio_blk_save_device (VirtIODevice *vdev,QEMUFile *f) {VirtIOBlock *s =VIRTIO_BLK (vdev);
@@ -952,8 +959,8 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , -sizeof (struct virtio_blk_config )); +virtio_blk_set_config_size (s); +virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , s->config_size); s->blk = conf->conf.blk; s->rq =NULL ;
include/hw/virtio/virtio-blk.h +1 -0
@@ -51,6 +51,7 @@ typedef struct VirtIOBlock {void *rq;QEMUBH *bh;VirtIOBlkConf conf; +size_t config_size;unsigned short sector_mask;bool original_wce;VMChangeStateEntry *change;
Signature · 1 line
1.9.3
Quoted 38 lines · Changpeng Liu
Commit
caa1ee43"vhost-user-blk: add discard/write zeroes features support" introduced extra fields to existing structvirtio_blk_config, when migration was executed from older QEMU version to current head, it will break the migration. While here, set the correct config size when initializing the host driver, for now, discard/write zeroes are not supported by virtio-blk host driver, so set the config size as before, users can change config size when adding the new feature bits support.Signed-off-by Changpeng Liu <[email protected]>--- hw/block/virtio-blk.c | 15 +++++++++++---- include/hw/virtio/virtio-blk.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-)hw/block/virtio-blk.c +2
-2@@ -761,7 +761,7 @@ static void virtio_blk_update_config(VirtIODevice *vdev, uint8_t *config) blkcfg.alignment_offset =0 ; blkcfg.wce =blk_enable_write_cache (s->blk);virtio_stw_p (vdev, &blkcfg.num_queues, s->conf.num_queues); -memcpy (config, &blkcfg,sizeof (struct virtio_blk_config )); +memcpy (config, &blkcfg, s->config_size); }static void virtio_blk_set_config (VirtIODevice *vdev,const uint8_t *config)@@ -769,7 +769,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)VirtIOBlock *s =VIRTIO_BLK (vdev);struct virtio_blk_config blkcfg; -memcpy (&blkcfg, config,sizeof (blkcfg)); +memcpy (&blkcfg, config, s->config_size);aio_context_acquire (blk_get_aio_context (s->blk));blk_set_enable_write_cache (s->blk, blkcfg.wce !=0 );
hw/block/virtio-blk.c static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status) · line 852
Quoted 6 lines
hw/block/virtio-blk.c +3
-0@@ -847,6 +847,13 @@ static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status) } } +static void virtio_blk_set_config_size (VirtIOBlock *s) +{ +/* VIRTIO_BLK_F_MQ is supported by host driver */
It can be disabled though.
It just so happens that only the addition of max_discard_seg crosses the next power of 2 boundary.
Quoted 23 lines
hw/block/virtio-blk.c +6
-2+ s->config_size = offsetof(struct virtio_blk_config , num_queues) + + sizeof_field(struct virtio_blk_config, num_queues); +} +static void virtio_blk_save_device (VirtIODevice *vdev,QEMUFile *f) {VirtIOBlock *s =VIRTIO_BLK (vdev);@@ -952,8 +959,8 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)return ; } -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , -sizeof (struct virtio_blk_config )); +virtio_blk_set_config_size (s); +virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , s->config_size); s->blk = conf->conf.blk; s->rq =NULL ;include/hw/virtio/virtio-blk.h +0
-0
include/hw/virtio/virtio-blk.h typedef struct VirtIOBlock { · line 57
Quoted 7 lines
include/hw/virtio/virtio-blk.h +1
-0@@ -51,6 +51,7 @@ typedef struct VirtIOBlock {void *rq;QEMUBH *bh;VirtIOBlkConf conf; +size_t config_size;unsigned short sector_mask;bool original_wce;VMChangeStateEntry *change;
Well assuming you are looking for a minimal change, go further and drop config_size completely, replace with a macro.
Quoted 2 lines
Signature · 1 line
1.9.3
Quoted 52 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, February 12, 2019 12:31 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] virtio-blk: set correct config size for the host driverhw/block/virtio-blk.c static void virtio_blk_update_config(VirtIODevice
Quoted 20 lines · Changpeng Liu
Commit
caa1ee43"vhost-user-blk: add discard/write zeroes features support" introduced extra fields to existing structvirtio_blk_config, when migration was executed from older QEMU version to current head, it will break the migration. While here, set the correct config size when initializing the host driver, for now, discard/write zeroes are not supported by virtio-blk host driver, so set the config size as before, users can change config size when adding the new feature bits support.Signed-off-by Changpeng Liu <[email protected]>--- hw/block/virtio-blk.c | 15 +++++++++++---- include/hw/virtio/virtio-blk.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-)hw/block/virtio-blk.c +0
-0@@ -761,7 +761,7 @@ static void virtio_blk_update_config(VirtIODevice*vdev,
uint8_t*config)hw/block/virtio-blk.c static void virtio_blk_set_config(VirtIODevice *vdev,
Quoted 9 lines
hw/block/virtio-blk.c +1
-1blkcfg.alignment_offset =0 ; blkcfg.wce =blk_enable_write_cache (s->blk);virtio_stw_p (vdev, &blkcfg.num_queues, s->conf.num_queues); -memcpy (config, &blkcfg,sizeof (struct virtio_blk_config )); +memcpy (config, &blkcfg, s->config_size); }static void virtio_blk_set_config (VirtIODevice *vdev,const uint8_t *config)@@ -769,7 +769,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev,const
uint8_t*config)hw/block/virtio-blk.c static void virtio_blk_set_status(VirtIODevice *vdev,
Quoted 9 lines
hw/block/virtio-blk.c +1
-1VirtIOBlock *s =VIRTIO_BLK (vdev);struct virtio_blk_config blkcfg; -memcpy (&blkcfg, config,sizeof (blkcfg)); +memcpy (&blkcfg, config, s->config_size);aio_context_acquire (blk_get_aio_context (s->blk));blk_set_enable_write_cache (s->blk, blkcfg.wce !=0 );@@ -847,6 +847,13 @@ static void virtio_blk_set_status(VirtIODevice *vdev,
uint8_tstatus)
Quoted 8 lines
hw/block/virtio-blk.c static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status) · line 852
Quoted 6 lines
hw/block/virtio-blk.c +3
-0} } +static void virtio_blk_set_config_size (VirtIOBlock *s) +{ +/* VIRTIO_BLK_F_MQ is supported by host driver */ It can be disabled though.
It means the host driver can support this feature, users can use it or not. So the config_size is same with previous old version.
Quoted 32 lines
It just so happens that only the addition of
max_discard_segcrosses the next power of 2 boundary.hw/block/virtio-blk.c static void virtio_blk_device_realize(DeviceState *dev,
Quoted 8 lines
hw/block/virtio-blk.c +4
-0+ s->config_size = offsetof(struct virtio_blk_config , num_queues) + + sizeof_field(struct virtio_blk_config, num_queues); +} +static void virtio_blk_save_device (VirtIODevice *vdev,QEMUFile *f) {VirtIOBlock *s =VIRTIO_BLK (vdev);@@ -952,8 +959,8 @@ static void virtio_blk_device_realize(DeviceState *dev,Error **errp)
Quoted 18 lines
hw/block/virtio-blk.c +2
-2return ; } -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , -sizeof (struct virtio_blk_config )); +virtio_blk_set_config_size (s); +virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , s->config_size); s->blk = conf->conf.blk; s->rq =NULL ;include/hw/virtio/virtio-blk.h +0
-0@@ -51,6 +51,7 @@ typedef struct VirtIOBlock {void *rq;QEMUBH *bh;VirtIOBlkConf conf;
Quoted 8 lines
include/hw/virtio/virtio-blk.h typedef struct VirtIOBlock { · line 57
Quoted 4 lines
include/hw/virtio/virtio-blk.h +1
-0+size_t config_size;unsigned short sector_mask;bool original_wce;VMChangeStateEntry *change;Well assuming you are looking for a minimal change, go further and drop
config_sizecompletely, replace with a macro.
OK.
Quoted 4 lines
Quoted 4 lines
--
1.9.3
Quoted 55 lines · Changpeng
Quoted 55 lines
-----Original Message-----
From: Michael S. Tsirkin [mailto:[email protected]]
Sent: Tuesday, February 12, 2019 12:31 PM
To: Liu, Changpeng <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH] virtio-blk: set correct config size for the host driverhw/block/virtio-blk.c static void virtio_blk_update_config(VirtIODevice
Quoted 20 lines · Changpeng Liu
Commit
caa1ee43"vhost-user-blk: add discard/write zeroes features support" introduced extra fields to existing structvirtio_blk_config, when migration was executed from older QEMU version to current head, it will break the migration. While here, set the correct config size when initializing the host driver, for now, discard/write zeroes are not supported by virtio-blk host driver, so set the config size as before, users can change config size when adding the new feature bits support.Signed-off-by Changpeng Liu <[email protected]>--- hw/block/virtio-blk.c | 15 +++++++++++---- include/hw/virtio/virtio-blk.h | 1 + 2 files changed, 12 insertions(+), 4 deletions(-)hw/block/virtio-blk.c +0
-0@@ -761,7 +761,7 @@ static void virtio_blk_update_config(VirtIODevice*vdev,
uint8_t*config)hw/block/virtio-blk.c static void virtio_blk_set_config(VirtIODevice *vdev,
Quoted 9 lines
hw/block/virtio-blk.c +1
-1blkcfg.alignment_offset =0 ; blkcfg.wce =blk_enable_write_cache (s->blk);virtio_stw_p (vdev, &blkcfg.num_queues, s->conf.num_queues); -memcpy (config, &blkcfg,sizeof (struct virtio_blk_config )); +memcpy (config, &blkcfg, s->config_size); }static void virtio_blk_set_config (VirtIODevice *vdev,const uint8_t *config)@@ -769,7 +769,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev,const
uint8_t*config)hw/block/virtio-blk.c static void virtio_blk_set_status(VirtIODevice *vdev,
Quoted 9 lines
hw/block/virtio-blk.c +1
-1VirtIOBlock *s =VIRTIO_BLK (vdev);struct virtio_blk_config blkcfg; -memcpy (&blkcfg, config,sizeof (blkcfg)); +memcpy (&blkcfg, config, s->config_size);aio_context_acquire (blk_get_aio_context (s->blk));blk_set_enable_write_cache (s->blk, blkcfg.wce !=0 );@@ -847,6 +847,13 @@ static void virtio_blk_set_status(VirtIODevice *vdev,
uint8_tstatus)Quoted 3 lines
hw/block/virtio-blk.c +0
-0} }
Quoted 7 lines
Quoted 5 lines
hw/block/virtio-blk.c static void virtio_blk_set_status(VirtIODevice *vdev, uint8_t status) · line 852
Quoted 3 lines
hw/block/virtio-blk.c +3
-0+static void virtio_blk_set_config_size (VirtIOBlock *s) +{ +/* VIRTIO_BLK_F_MQ is supported by host driver */ It can be disabled though.
It means the host driver can support this feature, users can use it or not. So the
config_sizeis same with previous old version.
But MQ didn't exist since creation it was only added in 2016. For virtio pci it all just happens to be within same power of 2: between 32 and 64 bytes. It's probably wrong for e.g. s390, and maybe the difference is harmless.
Besides "host driver" makes no sense.
So something like "include all fields up to num_queues to match QEMU 4.0 and older".
Quoted 45 lines
Quoted 32 lines
It just so happens that only the addition of
max_discard_segcrosses the next power of 2 boundary.hw/block/virtio-blk.c static void virtio_blk_device_realize(DeviceState *dev,
Quoted 8 lines
hw/block/virtio-blk.c +4
-0+ s->config_size = offsetof(struct virtio_blk_config , num_queues) + + sizeof_field(struct virtio_blk_config, num_queues); +} +static void virtio_blk_save_device (VirtIODevice *vdev,QEMUFile *f) {VirtIOBlock *s =VIRTIO_BLK (vdev);@@ -952,8 +959,8 @@ static void virtio_blk_device_realize(DeviceState *dev,Error **errp)
Quoted 18 lines
hw/block/virtio-blk.c +2
-2return ; } -virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , -sizeof (struct virtio_blk_config )); +virtio_blk_set_config_size (s); +virtio_init (vdev,"virtio-blk" ,VIRTIO_ID_BLOCK , s->config_size); s->blk = conf->conf.blk; s->rq =NULL ;include/hw/virtio/virtio-blk.h +0
-0@@ -51,6 +51,7 @@ typedef struct VirtIOBlock {void *rq;QEMUBH *bh;VirtIOBlkConf conf;Quoted 8 lines
include/hw/virtio/virtio-blk.h typedef struct VirtIOBlock { · line 57
Quoted 4 lines
include/hw/virtio/virtio-blk.h +1
-0+size_t config_size;unsigned short sector_mask;bool original_wce;VMChangeStateEntry *change;Well assuming you are looking for a minimal change, go further and drop
config_sizecompletely, replace with a macro.OK.
Quoted 4 lines
Quoted 4 lines
--
1.9.3
Patchew URL: https://patchew.org/QEMU/[email protected]/
Patchew URL: https://patchew.org/QEMU/[email protected]/
Hi,
This series seems to have some coding style problems. See output below for more information:
Type: series
Message-id: [email protected]
Subject: [Qemu-devel] [PATCH] virtio-blk: set correct config size for the host driver
=== TEST SCRIPT BEGIN ===
#!/bin/bash
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===
Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
error: Ref refs/heads/master is at 0b5e750bea635b167eb03d86c3d9a09bbd43bc06 but expected e47f81b617684c4546af286d307b69014a83538a From https://github.com/patchew-project/qemu
! e47f81b..0b5e750 master -> master (unable to update local ref) * [new tag] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] - [tag update] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected] * [new tag] patchew/[email protected] -> patchew/[email protected] error: Could not fetch 3c8cf5a9c21ff8782164d1def7f44bd888713384 Traceback (most recent call last): File "patchew-tester/src/patchew-cli", line 521, in test_one git_clone_repo(clone, r["repo"], r["head"], logf, True)
File "patchew-tester/src/patchew-cli", line 48, in git_clone_repo
stdout=logf, stderr=logf)
File "/usr/lib64/python3.4/subprocess.py", line 558, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['git', 'remote', 'add', '-f', '--mirror=fetch', '3c8cf5a9c21ff8782164d1def7f44bd888713384', 'https://github.com/patchew-project/qemu']' returned non-zero exit status 1
The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]