net/virtio: fix dev_unplug_pending
PATCH 1/4 net/virtio: fix dev_unplug_pending
.dev_unplug_pending is set up by virtio-net code indepent of whether failover=on was set for the device or not. This gives a wrong result when we check for existing primary devices in migration code.
Fix this by actually calling dev_unplug_pending() instead of just checking if the function pointer was set. When the feature was not negotiated dev_unplug_pending() will always return false. This prevents us from going into the wait-unplug state when there's no primary device present.
--- hw/net/virtio-net.c | 3 +++ migration/savevm.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +3 -0
@@ -3124,6 +3124,9 @@ static bool primary_unplug_pending(void *opaque)VirtIODevice *vdev =VIRTIO_DEVICE (dev);VirtIONet *n =VIRTIO_NET (vdev); +if (!virtio_vdev_has_feature (vdev,VIRTIO_NET_F_STANDBY )) { +return false; + }return n->primary_dev ? n->primary_dev->pending_deleted_event : false; }
migration/savevm.c +2 -1
@@ -1119,7 +1119,8 @@ int qemu_savevm_nr_failover_devices(void)int n =0 ; QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { -if (se->vmsd && se->vmsd->dev_unplug_pending) { +if (se->vmsd && se->vmsd->dev_unplug_pending && + se->vmsd->dev_unplug_pending (se->opaque)) { n++; } }
Signature · 1 line
2.21.0
PATCH 2/4 net/virtio: return early when failover primary alread added
Bail out when primary device was already added before. This avoids printing a wrong warning message during reboot.
--- hw/net/virtio-net.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/net/virtio-net.c +4 -0
@@ -759,6 +759,10 @@ static void failover_add_primary(VirtIONet *n, Error **errp) {Error *err =NULL ; +if (n->primary_dev) { +return ; + } + n->primary_device_opts =qemu_opts_find (qemu_find_opts ("device" ), n->primary_device_id);if (n->primary_device_opts) {
Signature · 1 line
2.21.0
Re: [PATCH 2/4] net/virtio: return early when failover primary alread added
Quoted 5 lines · Jens Freimann
Bail out when primary device was already added before. This avoids printing a wrong warning message during reboot.
Fixes 9711cd0dfc3f ("net/virtio: add failover support")Signed-off-by Jens Freimann <[email protected]>
Quoted 21 lines
--- hw/net/virtio-net.c | 4 ++++ 1 file changed, 4 insertions(+)hw/net/virtio-net.c +4
-0@@ -759,6 +759,10 @@ static void failover_add_primary(VirtIONet *n, Error **errp) {Error *err =NULL ; +if (n->primary_dev) { +return ; + } + n->primary_device_opts =qemu_opts_find (qemu_find_opts ("device" ), n->primary_device_id);if (n->primary_device_opts) {Signature · 1 line
2.21.0
PATCH 3/4 net/virtio: avoid passing NULL to qdev_set_parent_bus
In reply to Jens FreimannMake sure no arguments for qdev_set_parent_bus are NULL. This fixes CID 1407224.
--- hw/net/virtio-net.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
hw/net/virtio-net.c +10 -4
@@ -2809,8 +2809,16 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)if (n->primary_device_opts) {if (n->primary_dev) { n->primary_bus = n->primary_dev->parent_bus; +if (n->primary_bus) { +qdev_set_parent_bus (n->primary_dev, n->primary_bus); + }else { +error_setg (errp,"virtio_net: couldn't set bus for primary" ); + goto out; + } + }else { +error_setg (errp,"virtio_net: couldn't find primary device" ); + goto out; } -qdev_set_parent_bus (n->primary_dev, n->primary_bus); n->primary_should_be_hidden = false;qemu_opt_set_bool (n->primary_device_opts,"partially_hotplugged" , true, errp);
@@ -2819,10 +2827,8 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)hotplug_handler_pre_plug (hotplug_ctrl, n->primary_dev, errp);hotplug_handler_plug (hotplug_ctrl, n->primary_dev, errp); } -if (!n->primary_dev) { -error_setg (errp,"virtio_net: couldn't find primary device" ); - } } +out:return *errp !=NULL ; }
Signature · 1 line
2.21.0
Re: [PATCH 3/4] net/virtio: avoid passing NULL to qdev_set_parent_bus
Quoted 17 lines · Jens Freimann
Make sure no arguments for
qdev_set_parent_busare NULL. This fixes CID 1407224.Fixes 9711cd0dfc3f ("net/virtio: add failover support")Signed-off-by Jens Freimann <[email protected]>--- hw/net/virtio-net.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)hw/net/virtio-net.c +0
-0@@ -2809,8 +2809,16 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)if (n->primary_device_opts) {if (n->primary_dev) { n->primary_bus = n->primary_dev->parent_bus;
hw/net/virtio-net.c static bool failover_replug_primary(VirtIONet *n, Error **errp) · line 2821
Quoted 10 lines
hw/net/virtio-net.c +9
-0+if (n->primary_bus) { +qdev_set_parent_bus (n->primary_dev, n->primary_bus); + }else { +error_setg (errp,"virtio_net: couldn't set bus for primary" ); + goto out; + } + }else { +error_setg (errp,"virtio_net: couldn't find primary device" ); + goto out; }
A bit less messy:
if (!n->primary_dev) {
error_setg(errp, "virtio_net: couldn't find primary device");
goto err;
}n->primary_bus = n->primary_dev->parent_bus;
if (!n->primary_bus) {
error_setg(errp, "virtio_net: couldn't find primary device");
goto err;
}qdev_set_parent_bus(n->primary_dev, n->primary_bus);
err:
return false;
also is it valid for primary_device_opts to not be present at all? Maybe we should check that too.
Quoted 5 lines
hw/net/virtio-net.c +0
-1-qdev_set_parent_bus (n->primary_dev, n->primary_bus); n->primary_should_be_hidden = false;qemu_opt_set_bool (n->primary_device_opts,"partially_hotplugged" , true, errp);
hw/net/virtio-net.c static bool failover_replug_primary(VirtIONet *n, Error **errp) · line 2833
Quoted 10 lines
hw/net/virtio-net.c +1
-3@@ -2819,10 +2827,8 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)hotplug_handler_pre_plug (hotplug_ctrl, n->primary_dev, errp);hotplug_handler_plug (hotplug_ctrl, n->primary_dev, errp); } -if (!n->primary_dev) { -error_setg (errp,"virtio_net: couldn't find primary device" ); - } } +out:return *errp !=NULL ; }
I'd handle errors separately from good path.
BTW I don't understand something here:
*errp != NULL is true on error, no?
Why are we returning success?
Confused.
Just return true would be cleaner imho.
Quoted 3 lines
Signature · 2 lines
-- 2.21.0
Re: [PATCH 3/4] net/virtio: avoid passing NULL to qdev_set_parent_bus
Quoted 67 lines · Michael S. Tsirkin
Quoted 17 lines · Jens Freimann
Make sure no arguments for
qdev_set_parent_busare NULL. This fixes CID 1407224.Fixes 9711cd0dfc3f ("net/virtio: add failover support")Signed-off-by Jens Freimann <[email protected]>--- hw/net/virtio-net.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)hw/net/virtio-net.c +0
-0@@ -2809,8 +2809,16 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)if (n->primary_device_opts) {if (n->primary_dev) { n->primary_bus = n->primary_dev->parent_bus;hw/net/virtio-net.c static bool failover_replug_primary(VirtIONet *n, Error **errp) · line 2821
Quoted 10 lines
hw/net/virtio-net.c +9
-0+if (n->primary_bus) { +qdev_set_parent_bus (n->primary_dev, n->primary_bus); + }else { +error_setg (errp,"virtio_net: couldn't set bus for primary" ); + goto out; + } + }else { +error_setg (errp,"virtio_net: couldn't find primary device" ); + goto out; }A bit less messy:
if (!n->primary_dev) { error_setg(errp, "virtio_net: couldn't find primary device"); goto err; }
n->primary_bus=n->primary_dev->parent_bus;if (!n->primary_bus) { error_setg(errp, "virtio_net: couldn't find primary device"); goto err; }
qdev_set_parent_bus(n->primary_dev, n->primary_bus);err:
return false;also is it valid for
primary_device_optsto not be present at all? Maybe we should check that too.Quoted 14 lines
hw/net/virtio-net.c +1
-4-qdev_set_parent_bus (n->primary_dev, n->primary_bus); n->primary_should_be_hidden = false;qemu_opt_set_bool (n->primary_device_opts,"partially_hotplugged" , true, errp);@@ -2819,10 +2827,8 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)hotplug_handler_pre_plug (hotplug_ctrl, n->primary_dev, errp);hotplug_handler_plug (hotplug_ctrl, n->primary_dev, errp); } -if (!n->primary_dev) { -error_setg (errp,"virtio_net: couldn't find primary device" ); - } } +out:return *errp !=NULL ;
Quoted 8 lines
hw/net/virtio-net.c static bool failover_replug_primary(VirtIONet *n, Error **errp) · line 2833
Quoted 1 line
hw/net/virtio-net.c +0
-0}I'd handle errors separately from good path.
BTW I don't understand something here:
*errp != NULL is true on error, no?
Why are we returning success?
Confused.
Just return true would be cleaner imho.
I'll fix this and sent a new version as a single patch. As you said this is not really a series, just individual patches.
Thanks!
regards
Jens
Re: [PATCH 3/4] net/virtio: avoid passing NULL to qdev_set_parent_bus
Quoted 77 lines · Jens Freimann
Quoted 67 lines · Michael S. Tsirkin
Quoted 17 lines · Jens Freimann
Make sure no arguments for
qdev_set_parent_busare NULL. This fixes CID 1407224.Fixes 9711cd0dfc3f ("net/virtio: add failover support")Signed-off-by Jens Freimann <[email protected]>--- hw/net/virtio-net.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)hw/net/virtio-net.c +0
-0@@ -2809,8 +2809,16 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)if (n->primary_device_opts) {if (n->primary_dev) { n->primary_bus = n->primary_dev->parent_bus;hw/net/virtio-net.c static bool failover_replug_primary(VirtIONet *n, Error **errp) · line 2821
Quoted 10 lines
hw/net/virtio-net.c +9
-0+if (n->primary_bus) { +qdev_set_parent_bus (n->primary_dev, n->primary_bus); + }else { +error_setg (errp,"virtio_net: couldn't set bus for primary" ); + goto out; + } + }else { +error_setg (errp,"virtio_net: couldn't find primary device" ); + goto out; }A bit less messy:
if (!n->primary_dev) { error_setg(errp, "virtio_net: couldn't find primary device"); goto err; }
n->primary_bus=n->primary_dev->parent_bus;if (!n->primary_bus) { error_setg(errp, "virtio_net: couldn't find primary device"); goto err; }
qdev_set_parent_bus(n->primary_dev, n->primary_bus);err:
return false;also is it valid for
primary_device_optsto not be present at all? Maybe we should check that too.Quoted 14 lines
hw/net/virtio-net.c +1
-4-qdev_set_parent_bus (n->primary_dev, n->primary_bus); n->primary_should_be_hidden = false;qemu_opt_set_bool (n->primary_device_opts,"partially_hotplugged" , true, errp);@@ -2819,10 +2827,8 @@ static bool failover_replug_primary(VirtIONet *n, Error **errp)hotplug_handler_pre_plug (hotplug_ctrl, n->primary_dev, errp);hotplug_handler_plug (hotplug_ctrl, n->primary_dev, errp); } -if (!n->primary_dev) { -error_setg (errp,"virtio_net: couldn't find primary device" ); - } } +out:return *errp !=NULL ;Quoted 8 lines
hw/net/virtio-net.c static bool failover_replug_primary(VirtIONet *n, Error **errp) · line 2833
Quoted 1 line
hw/net/virtio-net.c +0
-0}I'd handle errors separately from good path.
BTW I don't understand something here:
*errp != NULL is true on error, no?
Why are we returning success?
Confused.
Just return true would be cleaner imho.
Quoted 7 lines
I'll fix this and sent a new version as a single patch. As you said this is not really a series, just individual patches.
Thanks!
regards
Jens
I'd just repost them all then. The series was also threaded weirdly (e.g. there's no cover letter instead patches 2 and on link to patch 1).
Signature · 1 line
MST
PATCH 4/4 net/virtio: return error when device_opts arg is NULL
In reply to Jens Freimanndevice_opts could be NULL. Make sure we don't pass it to qemu_opts_to_dict. When we made sure it can't be NULL we can also remove it from the if condition.
This fixes CID 1407222.
--- hw/net/virtio-net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
hw/net/virtio-net.c +6 -3
@@ -2878,9 +2878,12 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener, QemuOpts *device_opts) {VirtIONet *n =container_of (listener, VirtIONet, primary_listener); -bool match_found; -bool hide; +bool match_found = false; +bool hide = false; +if (!device_opts) { +return -1 ; + } n->primary_device_dict =qemu_opts_to_qdict (device_opts, n->primary_device_dict);if (n->primary_device_dict) {
@@ -2888,7 +2891,7 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener, n->standby_id =g_strdup (qdict_get_try_str (n->primary_device_dict,"failover_pair_id" )); } -if (device_opts &&g_strcmp0 (n->standby_id, n->netclient_name) ==0 ) { +if (g_strcmp0 (n->standby_id, n->netclient_name) ==0 ) { match_found = true; }else { match_found = false;
Signature · 1 line
2.21.0
Re: [PATCH 4/4] net/virtio: return error when device_opts arg is NULL
Quoted 7 lines · Jens Freimann
device_optscould be NULL. Make sure we don't pass it toqemu_opts_to_dict. When we made sure it can't be NULL we can also remove it from the if condition.
This fixes CID 1407222.Fixes 9711cd0dfc3f ("net/virtio: add failover support")Signed-off-by Jens Freimann <[email protected]>
Quoted 34 lines
--- hw/net/virtio-net.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)hw/net/virtio-net.c +6
-3@@ -2878,9 +2878,12 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener, QemuOpts *device_opts) {VirtIONet *n =container_of (listener, VirtIONet, primary_listener); -bool match_found; -bool hide; +bool match_found = false; +bool hide = false; +if (!device_opts) { +return -1 ; + } n->primary_device_dict =qemu_opts_to_qdict (device_opts, n->primary_device_dict);if (n->primary_device_dict) {@@ -2888,7 +2891,7 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener, n->standby_id =g_strdup (qdict_get_try_str (n->primary_device_dict,"failover_pair_id" )); } -if (device_opts &&g_strcmp0 (n->standby_id, n->netclient_name) ==0 ) { +if (g_strcmp0 (n->standby_id, n->netclient_name) ==0 ) { match_found = true; }else { match_found = false;Signature · 1 line
2.21.0
Quoted 10 lines · Jens Freimann
.dev_unplug_pending is set up by virtio-net code indepent of whether failover=on was set for the device or not. This gives a wrong result when we check for existing primary devices in migration code.
Fix this by actually calling
dev_unplug_pending()instead of just checking if the function pointer was set. When the feature was not negotiateddev_unplug_pending()will always return false. This prevents us from going into the wait-unplug state when there's no primary device present.
Quoted 3 lines
Fixes 9711cd0dfc3f ("net/virtio: add failover support")Signed-off-by Jens Freimann <[email protected]>Reported-by Dr. David Alan Gilbert <[email protected]>
This isn't really a series, is it?
Just a bunch of independent patches...
anyway:
Quoted 35 lines
--- hw/net/virtio-net.c | 3 +++ migration/savevm.c | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-)hw/net/virtio-net.c +3
-0@@ -3124,6 +3124,9 @@ static bool primary_unplug_pending(void *opaque)VirtIODevice *vdev =VIRTIO_DEVICE (dev);VirtIONet *n =VIRTIO_NET (vdev); +if (!virtio_vdev_has_feature (vdev,VIRTIO_NET_F_STANDBY )) { +return false; + }return n->primary_dev ? n->primary_dev->pending_deleted_event : false; }migration/savevm.c +2
-1@@ -1119,7 +1119,8 @@ int qemu_savevm_nr_failover_devices(void)int n =0 ; QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { -if (se->vmsd && se->vmsd->dev_unplug_pending) { +if (se->vmsd && se->vmsd->dev_unplug_pending && + se->vmsd->dev_unplug_pending (se->opaque)) { n++; } }Signature · 1 line
2.21.0