From: David Woodhouse Date: Tue, 9 Jul 2024 12:34:44 +0000 (+0100) Subject: net: Reinstate '-net nic, model=help' output as documented in man page X-Git-Tag: v9.0.3~48 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8636d5a32cee3f840e5a4a5daff20f032aa0fac1;p=thirdparty%2Fqemu.git net: Reinstate '-net nic, model=help' output as documented in man page While refactoring the NIC initialization code, I broke '-net nic,model=help' which no longer outputs a list of available NIC models. Fixes: 2cdeca04adab ("net: report list of available models according to platform") Cc: qemu-stable@nongnu.org Signed-off-by: David Woodhouse Reviewed-by: Michael Tokarev Signed-off-by: Jason Wang (cherry picked from commit 64f75f57f9d2c8c12ac6d9355fa5d3a2af5879ca) Signed-off-by: Michael Tokarev --- diff --git a/net/net.c b/net/net.c index a2f0c828bbf..e6ca2529bb1 100644 --- a/net/net.c +++ b/net/net.c @@ -1150,6 +1150,21 @@ NICInfo *qemu_find_nic_info(const char *typename, bool match_default, return NULL; } +static bool is_nic_model_help_option(const char *model) +{ + if (model && is_help_option(model)) { + /* + * Trigger the help output by instantiating the hash table which + * will gather tha available models as they get registered. + */ + if (!nic_model_help) { + nic_model_help = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, NULL); + } + return true; + } + return false; +} /* "I have created a device. Please configure it if you can" */ bool qemu_configure_nic_device(DeviceState *dev, bool match_default, @@ -1733,6 +1748,12 @@ void net_check_clients(void) static int net_init_client(void *dummy, QemuOpts *opts, Error **errp) { + const char *model = qemu_opt_get_del(opts, "model"); + + if (is_nic_model_help_option(model)) { + return 0; + } + return net_client_init(opts, false, errp); } @@ -1789,9 +1810,7 @@ static int net_param_nic(void *dummy, QemuOpts *opts, Error **errp) memset(ni, 0, sizeof(*ni)); ni->model = qemu_opt_get_del(opts, "model"); - if (!nic_model_help && !g_strcmp0(ni->model, "help")) { - nic_model_help = g_hash_table_new_full(g_str_hash, g_str_equal, - g_free, NULL); + if (is_nic_model_help_option(ni->model)) { return 0; }