net: net_client_init(): use error_set()
Callers are changed to use qerror_report_err() to keep their QError semantics. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-By: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
parent
42dcc547e1
commit
4559a1dbcc
|
@ -39,6 +39,7 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
|
||||||
const char *devaddr,
|
const char *devaddr,
|
||||||
const char *opts_str)
|
const char *opts_str)
|
||||||
{
|
{
|
||||||
|
Error *local_err = NULL;
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
PCIBus *bus;
|
PCIBus *bus;
|
||||||
int ret, devfn;
|
int ret, devfn;
|
||||||
|
@ -60,9 +61,12 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon,
|
||||||
|
|
||||||
qemu_opt_set(opts, "type", "nic");
|
qemu_opt_set(opts, "type", "nic");
|
||||||
|
|
||||||
ret = net_client_init(opts, 0);
|
ret = net_client_init(opts, 0, &local_err);
|
||||||
if (ret < 0)
|
if (error_is_set(&local_err)) {
|
||||||
|
qerror_report_err(local_err);
|
||||||
|
error_free(local_err);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
if (nd_table[ret].devaddr) {
|
if (nd_table[ret].devaddr) {
|
||||||
monitor_printf(mon, "Parameter addr not supported\n");
|
monitor_printf(mon, "Parameter addr not supported\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -1356,6 +1356,7 @@ static int usb_net_initfn(USBDevice *dev)
|
||||||
|
|
||||||
static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
|
static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
|
||||||
{
|
{
|
||||||
|
Error *local_err = NULL;
|
||||||
USBDevice *dev;
|
USBDevice *dev;
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
int idx;
|
int idx;
|
||||||
|
@ -1367,8 +1368,10 @@ static USBDevice *usb_net_init(USBBus *bus, const char *cmdline)
|
||||||
qemu_opt_set(opts, "type", "nic");
|
qemu_opt_set(opts, "type", "nic");
|
||||||
qemu_opt_set(opts, "model", "usb");
|
qemu_opt_set(opts, "model", "usb");
|
||||||
|
|
||||||
idx = net_client_init(opts, 0);
|
idx = net_client_init(opts, 0, &local_err);
|
||||||
if (idx == -1) {
|
if (error_is_set(&local_err)) {
|
||||||
|
qerror_report_err(local_err);
|
||||||
|
error_free(local_err);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
54
net.c
54
net.c
|
@ -1081,7 +1081,7 @@ static const struct {
|
||||||
#endif /* CONFIG_NET_BRIDGE */
|
#endif /* CONFIG_NET_BRIDGE */
|
||||||
};
|
};
|
||||||
|
|
||||||
int net_client_init(QemuOpts *opts, int is_netdev)
|
int net_client_init(QemuOpts *opts, int is_netdev, Error **errp)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
const char *type;
|
const char *type;
|
||||||
|
@ -1089,7 +1089,7 @@ int net_client_init(QemuOpts *opts, int is_netdev)
|
||||||
|
|
||||||
type = qemu_opt_get(opts, "type");
|
type = qemu_opt_get(opts, "type");
|
||||||
if (!type) {
|
if (!type) {
|
||||||
qerror_report(QERR_MISSING_PARAMETER, "type");
|
error_set(errp, QERR_MISSING_PARAMETER, "type");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1105,21 +1105,21 @@ int net_client_init(QemuOpts *opts, int is_netdev)
|
||||||
strcmp(type, "vde") != 0 &&
|
strcmp(type, "vde") != 0 &&
|
||||||
#endif
|
#endif
|
||||||
strcmp(type, "socket") != 0) {
|
strcmp(type, "socket") != 0) {
|
||||||
qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
|
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "type",
|
||||||
"a netdev backend type");
|
"a netdev backend type");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qemu_opt_get(opts, "vlan")) {
|
if (qemu_opt_get(opts, "vlan")) {
|
||||||
qerror_report(QERR_INVALID_PARAMETER, "vlan");
|
error_set(errp, QERR_INVALID_PARAMETER, "vlan");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (qemu_opt_get(opts, "name")) {
|
if (qemu_opt_get(opts, "name")) {
|
||||||
qerror_report(QERR_INVALID_PARAMETER, "name");
|
error_set(errp, QERR_INVALID_PARAMETER, "name");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (!qemu_opts_id(opts)) {
|
if (!qemu_opts_id(opts)) {
|
||||||
qerror_report(QERR_MISSING_PARAMETER, "id");
|
error_set(errp, QERR_MISSING_PARAMETER, "id");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1138,8 +1138,7 @@ int net_client_init(QemuOpts *opts, int is_netdev)
|
||||||
|
|
||||||
qemu_opts_validate(opts, &net_client_types[i].desc[0], &local_err);
|
qemu_opts_validate(opts, &net_client_types[i].desc[0], &local_err);
|
||||||
if (error_is_set(&local_err)) {
|
if (error_is_set(&local_err)) {
|
||||||
qerror_report_err(local_err);
|
error_propagate(errp, local_err);
|
||||||
error_free(local_err);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1155,7 +1154,7 @@ int net_client_init(QemuOpts *opts, int is_netdev)
|
||||||
ret = net_client_types[i].init(opts, name, vlan);
|
ret = net_client_types[i].init(opts, name, vlan);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
/* TODO push error reporting into init() methods */
|
/* TODO push error reporting into init() methods */
|
||||||
qerror_report(QERR_DEVICE_INIT_FAILED, type);
|
error_set(errp, QERR_DEVICE_INIT_FAILED, type);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1163,8 +1162,8 @@ int net_client_init(QemuOpts *opts, int is_netdev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
|
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "type",
|
||||||
"a network client type");
|
"a network client type");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1195,6 +1194,7 @@ void net_host_device_add(Monitor *mon, const QDict *qdict)
|
||||||
{
|
{
|
||||||
const char *device = qdict_get_str(qdict, "device");
|
const char *device = qdict_get_str(qdict, "device");
|
||||||
const char *opts_str = qdict_get_try_str(qdict, "opts");
|
const char *opts_str = qdict_get_try_str(qdict, "opts");
|
||||||
|
Error *local_err = NULL;
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
|
|
||||||
if (!net_host_check_device(device)) {
|
if (!net_host_check_device(device)) {
|
||||||
|
@ -1209,7 +1209,10 @@ void net_host_device_add(Monitor *mon, const QDict *qdict)
|
||||||
|
|
||||||
qemu_opt_set(opts, "type", device);
|
qemu_opt_set(opts, "type", device);
|
||||||
|
|
||||||
if (net_client_init(opts, 0) < 0) {
|
net_client_init(opts, 0, &local_err);
|
||||||
|
if (error_is_set(&local_err)) {
|
||||||
|
qerror_report_err(local_err);
|
||||||
|
error_free(local_err);
|
||||||
monitor_printf(mon, "adding host network device %s failed\n", device);
|
monitor_printf(mon, "adding host network device %s failed\n", device);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1244,8 +1247,10 @@ int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = net_client_init(opts, 1);
|
res = net_client_init(opts, 1, &local_err);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
|
qerror_report_err(local_err);
|
||||||
|
error_free(local_err);
|
||||||
qemu_opts_del(opts);
|
qemu_opts_del(opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1427,14 +1432,31 @@ void net_check_clients(void)
|
||||||
|
|
||||||
static int net_init_client(QemuOpts *opts, void *dummy)
|
static int net_init_client(QemuOpts *opts, void *dummy)
|
||||||
{
|
{
|
||||||
if (net_client_init(opts, 0) < 0)
|
Error *local_err = NULL;
|
||||||
|
|
||||||
|
net_client_init(opts, 0, &local_err);
|
||||||
|
if (error_is_set(&local_err)) {
|
||||||
|
qerror_report_err(local_err);
|
||||||
|
error_free(local_err);
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int net_init_netdev(QemuOpts *opts, void *dummy)
|
static int net_init_netdev(QemuOpts *opts, void *dummy)
|
||||||
{
|
{
|
||||||
return net_client_init(opts, 1);
|
Error *local_err = NULL;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = net_client_init(opts, 1, &local_err);
|
||||||
|
if (error_is_set(&local_err)) {
|
||||||
|
qerror_report_err(local_err);
|
||||||
|
error_free(local_err);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int net_init_clients(void)
|
int net_init_clients(void)
|
||||||
|
|
2
net.h
2
net.h
|
@ -163,7 +163,7 @@ struct HCIInfo *qemu_next_hci(void);
|
||||||
extern const char *legacy_tftp_prefix;
|
extern const char *legacy_tftp_prefix;
|
||||||
extern const char *legacy_bootp_filename;
|
extern const char *legacy_bootp_filename;
|
||||||
|
|
||||||
int net_client_init(QemuOpts *opts, int is_netdev);
|
int net_client_init(QemuOpts *opts, int is_netdev, Error **errp);
|
||||||
int net_client_parse(QemuOptsList *opts_list, const char *str);
|
int net_client_parse(QemuOptsList *opts_list, const char *str);
|
||||||
int net_init_clients(void);
|
int net_init_clients(void);
|
||||||
void net_check_clients(void);
|
void net_check_clients(void);
|
||||||
|
|
Loading…
Reference in a new issue