tap: Convert net_init_tap_one() to Error
[Dropped %s from "tap: open vhost char device failed: %s" since error_setg_errno() already prints a human-readable error string and there is no format string argument. --Stefan] Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Message-id: 1431691143-1015-9-git-send-email-armbru@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
80b832c300
commit
445f116cab
70
net/tap.c
70
net/tap.c
@ -600,11 +600,11 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr,
|
|||||||
|
|
||||||
#define MAX_TAP_QUEUES 1024
|
#define MAX_TAP_QUEUES 1024
|
||||||
|
|
||||||
static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
||||||
const char *model, const char *name,
|
const char *model, const char *name,
|
||||||
const char *ifname, const char *script,
|
const char *ifname, const char *script,
|
||||||
const char *downscript, const char *vhostfdname,
|
const char *downscript, const char *vhostfdname,
|
||||||
int vnet_hdr, int fd)
|
int vnet_hdr, int fd, Error **errp)
|
||||||
{
|
{
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr);
|
TAPState *s = net_tap_fd_init(peer, model, name, fd, vnet_hdr);
|
||||||
@ -612,8 +612,8 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
|||||||
|
|
||||||
tap_set_sndbuf(s->fd, tap, &err);
|
tap_set_sndbuf(s->fd, tap, &err);
|
||||||
if (err) {
|
if (err) {
|
||||||
error_report_err(err);
|
error_propagate(errp, err);
|
||||||
return -1;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tap->has_fd || tap->has_fds) {
|
if (tap->has_fd || tap->has_fds) {
|
||||||
@ -644,30 +644,28 @@ static int net_init_tap_one(const NetdevTapOptions *tap, NetClientState *peer,
|
|||||||
if (tap->has_vhostfd || tap->has_vhostfds) {
|
if (tap->has_vhostfd || tap->has_vhostfds) {
|
||||||
vhostfd = monitor_fd_param(cur_mon, vhostfdname, &err);
|
vhostfd = monitor_fd_param(cur_mon, vhostfdname, &err);
|
||||||
if (vhostfd == -1) {
|
if (vhostfd == -1) {
|
||||||
error_report_err(err);
|
error_propagate(errp, err);
|
||||||
return -1;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
vhostfd = open("/dev/vhost-net", O_RDWR);
|
vhostfd = open("/dev/vhost-net", O_RDWR);
|
||||||
if (vhostfd < 0) {
|
if (vhostfd < 0) {
|
||||||
error_report("tap: open vhost char device failed: %s",
|
error_setg_errno(errp, errno,
|
||||||
strerror(errno));
|
"tap: open vhost char device failed");
|
||||||
return -1;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
options.opaque = (void *)(uintptr_t)vhostfd;
|
options.opaque = (void *)(uintptr_t)vhostfd;
|
||||||
|
|
||||||
s->vhost_net = vhost_net_init(&options);
|
s->vhost_net = vhost_net_init(&options);
|
||||||
if (!s->vhost_net) {
|
if (!s->vhost_net) {
|
||||||
error_report("vhost-net requested but could not be initialized");
|
error_setg(errp,
|
||||||
return -1;
|
"vhost-net requested but could not be initialized");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
} else if (tap->has_vhostfd || tap->has_vhostfds) {
|
} else if (tap->has_vhostfd || tap->has_vhostfds) {
|
||||||
error_report("vhostfd= is not valid without vhost");
|
error_setg(errp, "vhostfd= is not valid without vhost");
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int get_fds(char *str, char *fds[], int max)
|
static int get_fds(char *str, char *fds[], int max)
|
||||||
@ -741,9 +739,11 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
|
|||||||
|
|
||||||
vnet_hdr = tap_probe_vnet_hdr(fd);
|
vnet_hdr = tap_probe_vnet_hdr(fd);
|
||||||
|
|
||||||
if (net_init_tap_one(tap, peer, "tap", name, NULL,
|
net_init_tap_one(tap, peer, "tap", name, NULL,
|
||||||
script, downscript,
|
script, downscript,
|
||||||
vhostfdname, vnet_hdr, fd)) {
|
vhostfdname, vnet_hdr, fd, &err);
|
||||||
|
if (err) {
|
||||||
|
error_report_err(err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (tap->has_fds) {
|
} else if (tap->has_fds) {
|
||||||
@ -786,10 +786,12 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_init_tap_one(tap, peer, "tap", name, ifname,
|
net_init_tap_one(tap, peer, "tap", name, ifname,
|
||||||
script, downscript,
|
script, downscript,
|
||||||
tap->has_vhostfds ? vhost_fds[i] : NULL,
|
tap->has_vhostfds ? vhost_fds[i] : NULL,
|
||||||
vnet_hdr, fd)) {
|
vnet_hdr, fd, &err);
|
||||||
|
if (err) {
|
||||||
|
error_report_err(err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -810,9 +812,11 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
|
|||||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||||
vnet_hdr = tap_probe_vnet_hdr(fd);
|
vnet_hdr = tap_probe_vnet_hdr(fd);
|
||||||
|
|
||||||
if (net_init_tap_one(tap, peer, "bridge", name, ifname,
|
net_init_tap_one(tap, peer, "bridge", name, ifname,
|
||||||
script, downscript, vhostfdname,
|
script, downscript, vhostfdname,
|
||||||
vnet_hdr, fd)) {
|
vnet_hdr, fd, &err);
|
||||||
|
if (err) {
|
||||||
|
error_report_err(err);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -846,10 +850,12 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_init_tap_one(tap, peer, "tap", name, ifname,
|
net_init_tap_one(tap, peer, "tap", name, ifname,
|
||||||
i >= 1 ? "no" : script,
|
i >= 1 ? "no" : script,
|
||||||
i >= 1 ? "no" : downscript,
|
i >= 1 ? "no" : downscript,
|
||||||
vhostfdname, vnet_hdr, fd)) {
|
vhostfdname, vnet_hdr, fd, &err);
|
||||||
|
if (err) {
|
||||||
|
error_report_err(err);
|
||||||
close(fd);
|
close(fd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user