Received: from eggs.gnu.org ([2001:4830:134:3::10]:60849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuKLr-0000AJ-Ta for qemu-devel@nongnu.org; Thu, 05 Nov 2015 08:13:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZuKLn-0002CC-Fv for qemu-devel@nongnu.org; Thu, 05 Nov 2015 08:13:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48940) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZuKLn-0002C5-93 for qemu-devel@nongnu.org; Thu, 05 Nov 2015 08:13:11 -0500 From: Markus Armbruster References: <4cf3dbbbfb40109379e0926406c2cda32ce38c62.1446714761.git.v.maffione@gmail.com> Date: Thu, 05 Nov 2015 14:13:07 +0100 In-Reply-To: <4cf3dbbbfb40109379e0926406c2cda32ce38c62.1446714761.git.v.maffione@gmail.com> (Vincenzo Maffione's message of "Thu, 5 Nov 2015 10:35:41 +0100") Message-ID: <87r3k4vbbw.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH 2/2] net: netmap: use error_setg_errno() in place of error_report() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vincenzo Maffione Cc: jasowang@redhat.com, g.lettieri@iet.unipi.it, rizzo@iet.unipi.it, qemu-devel@nongnu.org, stefanha@redhat.com Vincenzo Maffione writes: > This update was required to align netmap backend to the other > net backends in terms of error reporting. Thank you very much for helping to complete this job! Recommend to point to commit a30ecde in your commit message. > Signed-off-by: Vincenzo Maffione > --- > net/netmap.c | 14 ++++++-------- > 1 file changed, 6 insertions(+), 8 deletions(-) > > diff --git a/net/netmap.c b/net/netmap.c > index 4197a9c..45290d8 100644 > --- a/net/netmap.c > +++ b/net/netmap.c > @@ -90,7 +90,7 @@ pkt_copy(const void *_src, void *_dst, int l) > * Open a netmap device. We assume there is only one queue > * (which is the case for the VALE bridge). > */ > -static int netmap_open(NetmapPriv *me) > +static int netmap_open(NetmapPriv *me, Error **errp) > { > int fd; > int err; > @@ -99,8 +99,8 @@ static int netmap_open(NetmapPriv *me) > > me->fd = fd = open(me->fdname, O_RDWR); > if (fd < 0) { > - error_report("Unable to open netmap device '%s' (%s)", > - me->fdname, strerror(errno)); > + error_setg_errno(errp, errno, "Unable to open netmap device '%s'", > + me->fdname); > return -1; > } > memset(&req, 0, sizeof(req)); > @@ -109,15 +109,14 @@ static int netmap_open(NetmapPriv *me) > req.nr_version = NETMAP_API; > err = ioctl(fd, NIOCREGIF, &req); > if (err) { > - error_report("Unable to register %s: %s", me->ifname, strerror(errno)); > + error_setg_errno(errp, errno, "Unable to register %s", me->ifname); > goto error; > } > l = me->memsize = req.nr_memsize; > > me->mem = mmap(0, l, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0); > if (me->mem == MAP_FAILED) { > - error_report("Unable to mmap netmap shared memory: %s", > - strerror(errno)); > + error_setg_errno(errp, errno, "Unable to mmap netmap shared memory"); > me->mem = NULL; > goto error; > } > @@ -438,7 +437,6 @@ static NetClientInfo net_netmap_info = { > int net_init_netmap(const NetClientOptions *opts, > const char *name, NetClientState *peer, Error **errp) > { > - /* FIXME error_setg(errp, ...) on failure */ > const NetdevNetmapOptions *netmap_opts = opts->u.netmap; > NetClientState *nc; > NetmapPriv me; > @@ -448,7 +446,7 @@ int net_init_netmap(const NetClientOptions *opts, > netmap_opts->has_devname ? netmap_opts->devname : "/dev/netmap"); > /* Set default name for the port if not supplied. */ > pstrcpy(me.ifname, sizeof(me.ifname), netmap_opts->ifname); > - if (netmap_open(&me)) { > + if (netmap_open(&me, errp)) { > return -1; > } > /* Create the object. */ netmap_open() returns 0 on success, -1 on failure. For better or worse, we avoid such returns for functions that reports errors via an Error ** parameter. For an example, see commit 445f116. Since errp can be null, you can't test *err, but have to use a local variable, like this: netmap_open(&me, &err); if (err) { error_propagate(errp, err); return; } See the big comment in include/qapi/error.h. I actually like the way you did it, but consistency is more important than what I like here.