aboutsummaryrefslogtreecommitdiff
path: root/net/net.c
diff options
context:
space:
mode:
authorThomas Huth <thuth@redhat.com>2022-11-10 13:52:22 +0100
committerJason Wang <jasowang@redhat.com>2023-02-17 13:31:33 +0800
commitc6941b3b9b7445f7760c462882f8397b9dc51e30 (patch)
treedb3f9ce119680c488433f24f99963c13103be0cc /net/net.c
parent6dffbe36af79e26a4d23f94a9a1c1201de99c261 (diff)
net: Move the code to collect available NIC models to a separate function
The code that collects the available NIC models is not really specific to PCI anymore and will be required in the next patch, too, so let's move this into a new separate function in net.c instead. Signed-off-by: Thomas Huth <thuth@redhat.com> Signed-off-by: Jason Wang <jasowang@redhat.com>
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/net/net.c b/net/net.c
index 251fc5ab55..476a4b71cc 100644
--- a/net/net.c
+++ b/net/net.c
@@ -899,6 +899,40 @@ static int nic_get_free_idx(void)
return -1;
}
+GPtrArray *qemu_get_nic_models(const char *device_type)
+{
+ GPtrArray *nic_models = g_ptr_array_new();
+ GSList *list = object_class_get_list_sorted(device_type, false);
+
+ while (list) {
+ DeviceClass *dc = OBJECT_CLASS_CHECK(DeviceClass, list->data,
+ TYPE_DEVICE);
+ GSList *next;
+ if (test_bit(DEVICE_CATEGORY_NETWORK, dc->categories) &&
+ dc->user_creatable) {
+ const char *name = object_class_get_name(list->data);
+ /*
+ * A network device might also be something else than a NIC, see
+ * e.g. the "rocker" device. Thus we have to look for the "netdev"
+ * property, too. Unfortunately, some devices like virtio-net only
+ * create this property during instance_init, so we have to create
+ * a temporary instance here to be able to check it.
+ */
+ Object *obj = object_new_with_class(OBJECT_CLASS(dc));
+ if (object_property_find(obj, "netdev")) {
+ g_ptr_array_add(nic_models, (gpointer)name);
+ }
+ object_unref(obj);
+ }
+ next = list->next;
+ g_slist_free_1(list);
+ list = next;
+ }
+ g_ptr_array_add(nic_models, NULL);
+
+ return nic_models;
+}
+
int qemu_show_nic_models(const char *arg, const char *const *models)
{
int i;