Drop config_error(), use qemu_error() instead
PATCH 1/1 Drop config_error(), use qemu_error() instead
Diagnostic output goes to stderr, except when we're in a monitor command, when it goes to the monitor instead.
config_error() implements this with a monitor argument: if it's non-null, report there, else to stderr. This obliges us to pass the monitor down various call chains, to make it available to config_error().
The recently created qemu_error() doesn't need a monitor argument to route output. Use it.
There's one user-visible difference: config_error() prepended "qemu: " to a message bound for stderr. qemu_error() doesn't, which means the prefix goes away with this commit. If such a prefix is desired for stderr, then I figure it should be slapped on all error messages, not just the ones that used to go through config_error().
--- net.c | 128 ++++++++++++++++++++++++++++------------------------------------- 1 files changed, 55 insertions(+), 73 deletions(-)
net.c +55 -73
@@ -641,21 +641,6 @@ qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt)return qemu_sendv_packet_async (vc, iov, iovcnt,NULL ); } -static void config_error (Monitor *mon,const char *fmt, ...) -{ -va_list ap; - -va_start (ap, fmt); -if (mon) { -monitor_vprintf (mon, fmt, ap); - }else { -fprintf (stderr,"qemu: " ); -vfprintf (stderr, fmt, ap); -exit (1 ); - } -va_end (ap); -} -#if defined(CONFIG_SLIRP )/* slirp network adapter */
@@ -685,15 +670,15 @@ const char *legacy_bootp_filename; static TAILQ_HEAD(slirp_stacks, SlirpState) slirp_stacks =TAILQ_HEAD_INITIALIZER (slirp_stacks); -static void slirp_hostfwd (SlirpState *s,Monitor *mon,const char *redir_str, +static void slirp_hostfwd (SlirpState *s,const char *redir_str,int legacy_format); -static void slirp_guestfwd (SlirpState *s,Monitor *mon,const char *config_str, +static void slirp_guestfwd (SlirpState *s,const char *config_str,int legacy_format);#ifndef _WIN32static const char *legacy_smb_export; -static void slirp_smb (SlirpState *s,Monitor *mon,const char *exported_dir, +static void slirp_smb (SlirpState *s,const char *exported_dir,struct in_addr vserver_addr);static void slirp_smb_cleanup (SlirpState *s);#else
@@ -740,7 +725,7 @@ static void net_slirp_cleanup(VLANClientState *vc)qemu_free (s); } -static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model, +static int net_slirp_init(VLANState *vlan, const char *model, const char *name, int restricted, const char *vnetwork, const char *vhost, const char *vhostname, const char *tftp_export,
@@ -850,10 +835,10 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,struct slirp_config_str *config = slirp_configs;if (config->flags &SLIRP_CFG_HOSTFWD ) { -slirp_hostfwd (s, mon, config->str, +slirp_hostfwd (s, config->str, config->flags &SLIRP_CFG_LEGACY ); }else { -slirp_guestfwd (s, mon, config->str, +slirp_guestfwd (s, config->str, config->flags &SLIRP_CFG_LEGACY ); } slirp_configs = config->next;
@@ -864,7 +849,7 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model, smb_export = legacy_smb_export; }if (smb_export) { -slirp_smb (s, mon, smb_export, smbsrv); +slirp_smb (s, smb_export, smbsrv); }#endif
@@ -957,7 +942,7 @@ void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict)monitor_printf (mon,"invalid format\n" ); } -static void slirp_hostfwd (SlirpState *s,Monitor *mon,const char *redir_str, +static void slirp_hostfwd (SlirpState *s,const char *redir_str,int legacy_format) {struct in_addr host_addr = { .s_addr =INADDR_ANY };
@@ -1011,13 +996,13 @@ static void slirp_hostfwd(SlirpState *s, Monitor *mon, const char *redir_str,if (slirp_add_hostfwd (s->slirp, is_udp, host_addr, host_port, guest_addr, guest_port) <0 ) { -config_error (mon,"could not set up host forwarding rule '%s'\n" , - redir_str); +qemu_error ("could not set up host forwarding rule '%s'\n" , + redir_str); }return ; fail_syntax: -config_error (mon,"invalid host forwarding rule '%s'\n" , redir_str); +qemu_error ("invalid host forwarding rule '%s'\n" , redir_str); }void net_slirp_hostfwd_add (Monitor *mon,const QDict *qdict)
@@ -1036,7 +1021,7 @@ void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict) redir_str = arg1; }if (s) { -slirp_hostfwd (s, mon, redir_str,0 ); +slirp_hostfwd (s, redir_str,0 ); } }
@@ -1054,7 +1039,7 @@ void net_slirp_redir(const char *redir_str)return ; } -slirp_hostfwd (TAILQ_FIRST (&slirp_stacks),NULL , redir_str,1 ); +slirp_hostfwd (TAILQ_FIRST (&slirp_stacks), redir_str,1 ); }#ifndef _WIN32
@@ -1071,7 +1056,7 @@ static void slirp_smb_cleanup(SlirpState *s) } } -static void slirp_smb (SlirpState * s,Monitor *mon,const char *exported_dir, +static void slirp_smb (SlirpState * s,const char *exported_dir,struct in_addr vserver_addr) {static int instance;
@@ -1082,8 +1067,7 @@ static void slirp_smb(SlirpState* s, Monitor *mon, const char *exported_dir,snprintf (s->smb_dir,sizeof (s->smb_dir),"/tmp/qemu-smb.%ld-%d" , (long )getpid (), instance++);if (mkdir (s->smb_dir,0700 ) <0 ) { -config_error (mon,"could not create samba server dir '%s'\n" , - s->smb_dir); +qemu_error ("could not create samba server dir '%s'\n" , s->smb_dir);return ; }snprintf (smb_conf,sizeof (smb_conf),"%s/%s" , s->smb_dir,"smb.conf" );
@@ -1091,8 +1075,8 @@ static void slirp_smb(SlirpState* s, Monitor *mon, const char *exported_dir, f =fopen (smb_conf,"w" );if (!f) {slirp_smb_cleanup (s); -config_error (mon,"could not create samba server " -"configuration file '%s'\n" , smb_conf); +qemu_error ("could not create samba server configuration file '%s'\n" , + smb_conf);return ; } fprintf(f,
@@ -1123,7 +1107,7 @@ static void slirp_smb(SlirpState* s, Monitor *mon, const char *exported_dir,if (slirp_add_exec (s->slirp,0 , smb_cmdline, &vserver_addr,139 ) <0 ) {slirp_smb_cleanup (s); -config_error (mon,"conflicting/invalid smbserver address\n" ); +qemu_error ("conflicting/invalid smbserver address\n" ); } }
@@ -1138,7 +1122,7 @@ void net_slirp_smb(const char *exported_dir) } legacy_smb_export = exported_dir;if (!TAILQ_EMPTY (&slirp_stacks)) { -slirp_smb (TAILQ_FIRST (&slirp_stacks),NULL , exported_dir, +slirp_smb (TAILQ_FIRST (&slirp_stacks), exported_dir, vserver_addr); } }
@@ -1164,7 +1148,7 @@ static void guestfwd_read(void *opaque, const uint8_t *buf, int size)slirp_socket_recv (fwd->slirp, fwd->server, fwd->port, buf, size); } -static void slirp_guestfwd (SlirpState *s,Monitor *mon,const char *config_str, +static void slirp_guestfwd (SlirpState *s,const char *config_str,int legacy_format) {struct in_addr server = { .s_addr =0 };
@@ -1205,15 +1189,14 @@ static void slirp_guestfwd(SlirpState *s, Monitor *mon, const char *config_str,snprintf (buf,sizeof (buf),"guestfwd.tcp:%d" , port); fwd->hd =qemu_chr_open (buf, p,NULL );if (!fwd->hd) { -config_error (mon,"could not open guest forwarding device '%s'\n" , - buf); +qemu_error ("could not open guest forwarding device '%s'\n" , buf);qemu_free (fwd);return ; }if (slirp_add_exec (s->slirp,3 , fwd->hd, &server, port) <0 ) { -config_error (mon,"conflicting/invalid host:port in guest forwarding " -"rule '%s'\n" , config_str); +qemu_error ("conflicting/invalid host:port in guest forwarding " +"rule '%s'\n" , config_str);qemu_free (fwd);return ; }
@@ -1226,7 +1209,7 @@ static void slirp_guestfwd(SlirpState *s, Monitor *mon, const char *config_str,return ; fail_syntax: -config_error (mon,"invalid guest forwarding rule '%s'\n" , config_str); +qemu_error ("invalid guest forwarding rule '%s'\n" , config_str); }void do_info_usernet (Monitor *mon)
@@ -1376,7 +1359,7 @@ static void tap_send(void *opaque)*/ #define TAP_DEFAULT_SNDBUF 1024*1024 -static void tap_set_sndbuf (TAPState *s,const char *sndbuf_str,Monitor *mon) +static void tap_set_sndbuf (TAPState *s,const char *sndbuf_str) {int sndbuf =TAP_DEFAULT_SNDBUF ;
@@ -1389,15 +1372,14 @@ static void tap_set_sndbuf(TAPState *s, const char *sndbuf_str, Monitor *mon) }if (ioctl (s->fd,TUNSETSNDBUF , &sndbuf) ==-1 && sndbuf_str) { -config_error (mon,"TUNSETSNDBUF ioctl failed: %s\n" , -strerror (errno)); +qemu_error ("TUNSETSNDBUF ioctl failed: %s\n" ,strerror (errno)); } }#else -static void tap_set_sndbuf (TAPState *s,const char *sndbuf_str,Monitor *mon) +static void tap_set_sndbuf (TAPState *s,const char *sndbuf_str) {if (sndbuf_str) { -config_error (mon,"No '-net tap,sndbuf=<nbytes>' support available\n" ); +qemu_error ("No '-net tap,sndbuf=<nbytes>' support available\n" ); } }#endif /* TUNSETSNDBUF */
@@ -2279,7 +2261,7 @@ static void net_dump_cleanup(VLANClientState *vc)qemu_free (s); } -static int net_dump_init (Monitor *mon,VLANState *vlan,const char *device, +static int net_dump_init (VLANState *vlan,const char *device,const char *name,const char *filename,int len) {struct pcap_file_hdr hdr;
@@ -2289,7 +2271,7 @@ static int net_dump_init(Monitor *mon, VLANState *vlan, const char *device, s->fd =open (filename,O_CREAT |O_WRONLY |O_BINARY ,0644 );if (s->fd <0 ) { -config_error (mon,"-net dump: can't open %s\n" , filename); +qemu_error ("-net dump: can't open %s\n" , filename);return -1 ; }
@@ -2304,7 +2286,7 @@ static int net_dump_init(Monitor *mon, VLANState *vlan, const char *device, hdr.linktype =1 ;if (write (s->fd, &hdr,sizeof (hdr)) <sizeof (hdr)) { -config_error (mon,"-net dump write error: %s\n" ,strerror (errno)); +qemu_error ("-net dump write error: %s\n" ,strerror (errno));close (s->fd);qemu_free (s);return -1 ;
@@ -2390,7 +2372,7 @@ static int net_handle_fd_param(Monitor *mon, const char *param) fd =monitor_get_fd (mon, param);if (fd ==-1 ) { -config_error (mon,"No file descriptor named %s found" , param); +qemu_error ("No file descriptor named %s found" , param);return -1 ; }
@@ -2425,12 +2407,12 @@ int net_client_init(Monitor *mon, const char *device, const char *p)int idx =nic_get_free_idx ();if (check_params (buf,sizeof (buf), nic_params, p) <0 ) { -config_error (mon,"invalid parameter '%s' in '%s'\n" , buf, p); +qemu_error ("invalid parameter '%s' in '%s'\n" , buf, p); ret =-1 ; goto out; }if (idx ==-1 || nb_nics >=MAX_NICS ) { -config_error (mon,"Too Many NICs\n" ); +qemu_error ("Too Many NICs\n" ); ret =-1 ; goto out; }
@@ -2445,7 +2427,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)if (get_param_value (buf,sizeof (buf),"macaddr" , p)) {if (parse_macaddr (macaddr, buf) <0 ) { -config_error (mon,"invalid syntax for ethernet address\n" ); +qemu_error ("invalid syntax for ethernet address\n" ); ret =-1 ; goto out; }
@@ -2464,12 +2446,12 @@ int net_client_init(Monitor *mon, const char *device, const char *p)char *endptr;long vectors =strtol (buf, &endptr,0 );if (*endptr) { -config_error (mon,"invalid syntax for # of vectors\n" ); +qemu_error ("invalid syntax for # of vectors\n" ); ret =-1 ; goto out; }if (vectors <0 || vectors >0x7ffffff ) { -config_error (mon,"invalid # of vectors\n" ); +qemu_error ("invalid # of vectors\n" ); ret =-1 ; goto out; }
@@ -2485,7 +2467,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) }else if (!strcmp (device,"none" )) {if (*p !='\0' ) { -config_error (mon,"'none' takes no parameters\n" ); +qemu_error ("'none' takes no parameters\n" ); ret =-1 ; goto out; }
@@ -2514,7 +2496,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)const char *q;if (check_params (buf,sizeof (buf), slirp_params, p) <0 ) { -config_error (mon,"invalid parameter '%s' in '%s'\n" , buf, p); +qemu_error ("invalid parameter '%s' in '%s'\n" , buf, p); ret =-1 ; goto out; }
@@ -2581,7 +2563,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) }qemu_free (config); vlan->nb_host_devs++; - ret =net_slirp_init (mon, vlan, device, name, restricted, vnet, vhost, + ret =net_slirp_init (vlan, device, name, restricted, vnet, vhost, vhostname, tftp_export, bootfile, vdhcp_start, vnamesrv, smb_export, vsmbsrv);qemu_free (vnet);
@@ -2603,7 +2585,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) config->next = slirp_configs; slirp_configs = config; }else { -slirp_guestfwd (TAILQ_FIRST (&slirp_stacks), mon, p,1 ); +slirp_guestfwd (TAILQ_FIRST (&slirp_stacks), p,1 ); } ret =0 ; }else
@@ -2616,12 +2598,12 @@ int net_client_init(Monitor *mon, const char *device, const char *p)char ifname[64 ];if (check_params (buf,sizeof (buf), tap_params, p) <0 ) { -config_error (mon,"invalid parameter '%s' in '%s'\n" , buf, p); +qemu_error ("invalid parameter '%s' in '%s'\n" , buf, p); ret =-1 ; goto out; }if (get_param_value (ifname,sizeof (ifname),"ifname" , p) <=0 ) { -config_error (mon,"tap: no interface name\n" ); +qemu_error ("tap: no interface name\n" ); ret =-1 ; goto out; }
@@ -2642,7 +2624,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) }; ret =-1 ;if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) { -config_error (mon,"invalid parameter '%s' in '%s'\n" , chkbuf, p); +qemu_error ("invalid parameter '%s' in '%s'\n" , chkbuf, p); goto out; } fd =net_handle_fd_param (mon, buf);
@@ -2659,7 +2641,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) "vlan", "name", "ifname", "script", "downscript", "sndbuf", NULL };if (check_params (chkbuf,sizeof (chkbuf), tap_params, p) <0 ) { -config_error (mon,"invalid parameter '%s' in '%s'\n" , chkbuf, p); +qemu_error ("invalid parameter '%s' in '%s'\n" , chkbuf, p); ret =-1 ; goto out; }
@@ -2679,7 +2661,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)if (get_param_value (buf,sizeof (buf),"sndbuf" , p)) { sndbuf_str = buf; } -tap_set_sndbuf (s, sndbuf_str, mon); +tap_set_sndbuf (s, sndbuf_str); ret =0 ; }else { ret =-1 ;
@@ -2695,7 +2677,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)int fd; ret =-1 ;if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) { -config_error (mon,"invalid parameter '%s' in '%s'\n" , chkbuf, p); +qemu_error ("invalid parameter '%s' in '%s'\n" , chkbuf, p); goto out; } fd =net_handle_fd_param (mon, buf);
@@ -2712,7 +2694,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) "vlan", "name", "listen", NULL };if (check_params (chkbuf,sizeof (chkbuf), listen_params, p) <0 ) { -config_error (mon,"invalid parameter '%s' in '%s'\n" , chkbuf, p); +qemu_error ("invalid parameter '%s' in '%s'\n" , chkbuf, p); ret =-1 ; goto out; }
@@ -2722,7 +2704,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p) "vlan", "name", "connect", NULL };if (check_params (chkbuf,sizeof (chkbuf), connect_params, p) <0 ) { -config_error (mon,"invalid parameter '%s' in '%s'\n" , chkbuf, p); +qemu_error ("invalid parameter '%s' in '%s'\n" , chkbuf, p); ret =-1 ; goto out; }
@@ -2732,13 +2714,13 @@ int net_client_init(Monitor *mon, const char *device, const char *p) "vlan", "name", "mcast", NULL };if (check_params (chkbuf,sizeof (chkbuf), mcast_params, p) <0 ) { -config_error (mon,"invalid parameter '%s' in '%s'\n" , chkbuf, p); +qemu_error ("invalid parameter '%s' in '%s'\n" , chkbuf, p); ret =-1 ; goto out; } ret =net_socket_mcast_init (vlan, device, name, buf); }else { -config_error (mon,"Unknown socket options: %s\n" , p); +qemu_error ("Unknown socket options: %s\n" , p); ret =-1 ; goto out; }
@@ -2753,7 +2735,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)int vde_port, vde_mode;if (check_params (buf,sizeof (buf), vde_params, p) <0 ) { -config_error (mon,"invalid parameter '%s' in '%s'\n" , buf, p); +qemu_error ("invalid parameter '%s' in '%s'\n" , buf, p); ret =-1 ; goto out; }
@@ -2786,14 +2768,14 @@ int net_client_init(Monitor *mon, const char *device, const char *p)if (!get_param_value (buf,sizeof (buf),"file" , p)) {snprintf (buf,sizeof (buf),"qemu-vlan%d.pcap" , vlan_id); } - ret =net_dump_init (mon, vlan, device, name, buf, len); + ret =net_dump_init (vlan, device, name, buf, len); }else { -config_error (mon,"Unknown network device: %s\n" , device); +qemu_error ("Unknown network device: %s\n" , device); ret =-1 ; goto out; }if (ret <0 ) { -config_error (mon,"Could not initialize device '%s'\n" , device); +qemu_error ("Could not initialize device '%s'\n" , device); } out:qemu_free (name);
Signature · 1 line
1.6.2.5
Quoted 3 lines · Markus Armbruster
There's one user-visible difference:
config_error()prepended "qemu: " to a message bound for stderr.qemu_error()doesn't, which means the prefix goes away with this commit.
...
Quoted 13 lines
--- net.c | 128 ++++++++++++++++++++++++++++------------------------------------- 1 files changed, 55 insertions(+), 73 deletions(-)net.c +0
-1@@ -641,21 +641,6 @@ qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt)return qemu_sendv_packet_async (vc, iov, iovcnt,NULL ); } -static void config_error (Monitor *mon,const char *fmt, ...)
net.c qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt) · line 654
Quoted 10 lines
net.c +0
-10-{ -va_list ap; - -va_start (ap, fmt); -if (mon) { -monitor_vprintf (mon, fmt, ap); - }else { -fprintf (stderr,"qemu: " ); -vfprintf (stderr, fmt, ap); -exit (1 );
There's another difference, actually - qemu_error() doesn't abort when printing an error to stderr
I'm fine with that, but could you check all callers to make sure that's sane?
Thanks,
Mark.
Quoted 33 lines · Mark McLoughlin
Quoted 3 lines · Markus Armbruster
There's one user-visible difference:
config_error()prepended "qemu: " to a message bound for stderr.qemu_error()doesn't, which means the prefix goes away with this commit....
Quoted 13 lines
--- net.c | 128 ++++++++++++++++++++++++++++------------------------------------- 1 files changed, 55 insertions(+), 73 deletions(-)net.c +0
-1@@ -641,21 +641,6 @@ qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt)return qemu_sendv_packet_async (vc, iov, iovcnt,NULL ); } -static void config_error (Monitor *mon,const char *fmt, ...)net.c qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt) · line 654
Quoted 10 lines
net.c +0
-10-{ -va_list ap; - -va_start (ap, fmt); -if (mon) { -monitor_vprintf (mon, fmt, ap); - }else { -fprintf (stderr,"qemu: " ); -vfprintf (stderr, fmt, ap); -exit (1 );There's another difference, actually -
qemu_error()doesn't abort when printing an error to stderr
Quoted 2 lines
I'm fine with that, but could you check all callers to make sure that's sane?
Valid remark. I think the effect will be that we continue with parameter evaluation or even VM startup even though parts of the setup failed / was skipped. May produce funny subsequent errors that will only confuse the user.
Jan
Quoted 33 lines · Mark McLoughlin
Quoted 3 lines · Markus Armbruster
There's one user-visible difference:
config_error()prepended "qemu: " to a message bound for stderr.qemu_error()doesn't, which means the prefix goes away with this commit....
Quoted 13 lines
--- net.c | 128 ++++++++++++++++++++++++++++------------------------------------- 1 files changed, 55 insertions(+), 73 deletions(-)net.c +0
-1@@ -641,21 +641,6 @@ qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt)return qemu_sendv_packet_async (vc, iov, iovcnt,NULL ); } -static void config_error (Monitor *mon,const char *fmt, ...)net.c qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt) · line 654
Quoted 10 lines
net.c +0
-10-{ -va_list ap; - -va_start (ap, fmt); -if (mon) { -monitor_vprintf (mon, fmt, ap); - }else { -fprintf (stderr,"qemu: " ); -vfprintf (stderr, fmt, ap); -exit (1 );There's another difference, actually -
qemu_error()doesn't abort when printing an error to stderr
Quoted 2 lines
I'm fine with that, but could you check all callers to make sure that's sane?
I meant to do that, but it somehow slipped my mind. I had a quick look, and I think I dropped error exits on some call chains. I need to redo this patch.
Thanks!