aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2015-05-15 13:59:00 +0200
committerStefan Hajnoczi <stefanha@redhat.com>2015-05-27 10:34:07 +0100
commit4bce487e14bf8949a91883a3213c2b7fa9d668bc (patch)
tree1ae70aa970bc8c66ec3d4f8f4ad4e8b656226d39
parent47896e2fd3dd80685434b320cb0e10164995e31c (diff)
tap-bsd: Convert tap_open() to Error
Fixes inappropriate use of stderr in monitor command handler. While there, improve some of the messages a bit. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 1431691143-1015-13-git-send-email-armbru@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
-rw-r--r--net/tap-bsd.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/net/tap-bsd.c b/net/tap-bsd.c
index bbbe446b1b..5889920eac 100644
--- a/net/tap-bsd.c
+++ b/net/tap-bsd.c
@@ -37,7 +37,6 @@
int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
int vnet_hdr_required, int mq_required, Error **errp)
{
- /* FIXME error_setg(errp, ...) on failure */
int fd;
#ifdef TAPGIFNAME
struct ifreq ifr;
@@ -72,23 +71,19 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
}
}
if (fd < 0) {
- error_report("warning: could not open %s (%s): no virtual network emulation",
- dname, strerror(errno));
+ error_setg_errno(errp, errno, "could not open %s", dname);
return -1;
}
#ifdef TAPGIFNAME
if (ioctl(fd, TAPGIFNAME, (void *)&ifr) < 0) {
- fprintf(stderr, "warning: could not get tap name: %s\n",
- strerror(errno));
+ error_setg_errno(errp, errno, "could not get tap name");
return -1;
}
pstrcpy(ifname, ifname_size, ifr.ifr_name);
#else
if (fstat(fd, &s) < 0) {
- fprintf(stderr,
- "warning: could not stat /dev/tap: no virtual network emulation: %s\n",
- strerror(errno));
+ error_setg_errno(errp, errno, "could not stat %s", dname);
return -1;
}
dev = devname(s.st_rdev, S_IFCHR);
@@ -100,8 +95,8 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
*vnet_hdr = 0;
if (vnet_hdr_required && !*vnet_hdr) {
- error_report("vnet_hdr=1 requested, but no kernel "
- "support for IFF_VNET_HDR available");
+ error_setg(errp, "vnet_hdr=1 requested, but no kernel "
+ "support for IFF_VNET_HDR available");
close(fd);
return -1;
}
@@ -117,13 +112,12 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
int vnet_hdr_required, int mq_required, Error **errp)
{
- /* FIXME error_setg(errp, ...) on failure */
int fd, s, ret;
struct ifreq ifr;
TFR(fd = open(PATH_NET_TAP, O_RDWR));
if (fd < 0) {
- error_report("could not open %s: %s", PATH_NET_TAP, strerror(errno));
+ error_setg_errno(errp, errno, "could not open %s", PATH_NET_TAP);
return -1;
}
@@ -131,7 +125,7 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
ret = ioctl(fd, TAPGIFNAME, (void *)&ifr);
if (ret < 0) {
- error_report("could not get tap interface name");
+ error_setg_errno(errp, errno, "could not get tap interface name");
goto error;
}
@@ -139,14 +133,15 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
/* User requested the interface to have a specific name */
s = socket(AF_LOCAL, SOCK_DGRAM, 0);
if (s < 0) {
- error_report("could not open socket to set interface name");
+ error_setg_errno(errp, errno,
+ "could not open socket to set interface name");
goto error;
}
ifr.ifr_data = ifname;
ret = ioctl(s, SIOCSIFNAME, (void *)&ifr);
close(s);
if (ret < 0) {
- error_report("could not set tap interface name");
+ error_setg(errp, "could not set tap interface name");
goto error;
}
} else {
@@ -158,14 +153,14 @@ int tap_open(char *ifname, int ifname_size, int *vnet_hdr,
*vnet_hdr = 0;
if (vnet_hdr_required && !*vnet_hdr) {
- error_report("vnet_hdr=1 requested, but no kernel "
- "support for IFF_VNET_HDR available");
+ error_setg(errp, "vnet_hdr=1 requested, but no kernel "
+ "support for IFF_VNET_HDR available");
goto error;
}
}
if (mq_required) {
- error_report("mq_required requested, but not kernel support"
- "for IFF_MULTI_QUEUE available");
+ error_setg(errp, "mq_required requested, but no kernel support"
+ " for IFF_MULTI_QUEUE available");
goto error;
}