From: Laurent Vivier <lvivier@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
qemu-trivial@nongnu.org, Jason Wang <jasowang@redhat.com>,
quintela@redhat.com, Michael Tokarev <mjt@tls.msk.ru>,
Laurent Vivier <laurent@vivier.eu>,
jfreimann@redhat.com
Subject: [PATCH v2 3/3] failover: really display a warning when the primary device is not found
Date: Wed, 10 Feb 2021 18:45:18 +0100 [thread overview]
Message-ID: <20210210174518.2493928-4-lvivier@redhat.com> (raw)
In-Reply-To: <20210210174518.2493928-1-lvivier@redhat.com>
In failover_add_primary(), we search the id of the failover device by
scanning the list of the devices in the opts list to find a device with
a failover_pair_id equals to the id of the virtio-net device.
If the failover_pair_id is not found, QEMU ignores the primary
device silently (which also means it will not be hidden and
it will be enabled directly at boot).
After that, we search the id in the opts list to do a qdev_device_add()
with it. The device will be always found as otherwise we had exited
before, and thus the warning is never displayed.
Fix that by moving the error report to the first exit condition.
Also add a g_assert() to be sure the compiler will not complain
about a possibly NULL pointer.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
---
hw/net/virtio-net.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 1c5af08dc556..439f823b190c 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -855,21 +855,19 @@ static void failover_add_primary(VirtIONet *n, Error **errp)
id = failover_find_primary_device_id(n);
if (!id) {
+ error_setg(errp, "Primary device not found");
+ error_append_hint(errp, "Virtio-net failover will not work. Make "
+ "sure primary device has parameter"
+ " failover_pair_id=%s\n", n->netclient_name);
return;
}
opts = qemu_opts_find(qemu_find_opts("device"), id);
- if (opts) {
- dev = qdev_device_add(opts, &err);
- if (err) {
- qemu_opts_del(opts);
- } else {
- object_unref(OBJECT(dev));
- }
+ g_assert(opts); /* cannot be NULL because id was found using opts list */
+ dev = qdev_device_add(opts, &err);
+ if (err) {
+ qemu_opts_del(opts);
} else {
- error_setg(errp, "Primary device not found");
- error_append_hint(errp, "Virtio-net failover will not work. Make "
- "sure primary device has parameter"
- " failover_pair_id=<virtio-net-id>\n");
+ object_unref(OBJECT(dev));
}
error_propagate(errp, err);
}
--
2.29.2
next prev parent reply other threads:[~2021-02-10 17:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-10 17:45 [PATCH v2 0/3] failover: trivial cleanup and fix Laurent Vivier
2021-02-10 17:45 ` [PATCH v2 1/3] pci: cleanup failover sanity check Laurent Vivier
2021-02-18 5:56 ` Jason Wang
2021-02-10 17:45 ` [PATCH v2 2/3] virtio-net: add missing object_unref() Laurent Vivier
2021-02-18 5:57 ` Jason Wang
2021-02-10 17:45 ` Laurent Vivier [this message]
2021-02-18 6:01 ` [PATCH v2 3/3] failover: really display a warning when the primary device is not found Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210210174518.2493928-4-lvivier@redhat.com \
--to=lvivier@redhat.com \
--cc=jasowang@redhat.com \
--cc=jfreimann@redhat.com \
--cc=laurent@vivier.eu \
--cc=mjt@tls.msk.ru \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-trivial@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).