Received: from eggs.gnu.org ([2001:4830:134:3::10]:43978) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abNVR-00033F-6A for qemu-devel@nongnu.org; Thu, 03 Mar 2016 02:17:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1abNVN-0002vo-4y for qemu-devel@nongnu.org; Thu, 03 Mar 2016 02:17:05 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56628) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1abNVM-0002v8-U6 for qemu-devel@nongnu.org; Thu, 03 Mar 2016 02:17:01 -0500 From: Markus Armbruster References: <1456771254-17511-1-git-send-email-armbru@redhat.com> <1456771254-17511-25-git-send-email-armbru@redhat.com> <87fuw8d66i.fsf@blackfin.pond.sub.org> Date: Thu, 03 Mar 2016 08:16:57 +0100 In-Reply-To: (=?utf-8?Q?=22Marc-Andr=C3=A9?= Lureau"'s message of "Thu, 3 Mar 2016 01:03:24 +0100") Message-ID: <877fhk9gk6.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 24/38] ivshmem: Propagate errors through ivshmem_recv_setup() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Marc-Andr=C3=A9?= Lureau Cc: Paolo Bonzini , cam , Claudio Fontana , QEMU , David Marchand Marc-Andr=C3=A9 Lureau writes: > Hi > > On Wed, Mar 2, 2016 at 8:35 PM, Markus Armbruster wro= te: >> You know, I'd prefer that, too, and I've argued for it unsuccessfully. >> As it is, we fairly consistently return void when the function returns >> errors through Error ** and has no non-error value. > > Good to know we are on same side. > >>>> { >>>> PCIDevice *pdev =3D PCI_DEVICE(s); >>>> MSIMessage msg =3D msix_get_message(pdev, vector); >>>> @@ -522,22 +518,21 @@ static int ivshmem_add_kvm_msi_virq(IVShmemState= *s, int vector) >>>> >>>> ret =3D kvm_irqchip_add_msi_route(kvm_state, msg, pdev); >>>> if (ret < 0) { >>>> - error_report("ivshmem: kvm_irqchip_add_msi_route failed"); >>>> - return -1; >>>> + error_setg(errp, "kvm_irqchip_add_msi_route failed"); >>>> + return; >>>> } >>>> >>>> s->msi_vectors[vector].virq =3D ret; >>>> s->msi_vectors[vector].pdev =3D pdev; >>>> - >>>> - return 0; >>>> } >>>> >>>> -static void setup_interrupt(IVShmemState *s, int vector) >>>> +static void setup_interrupt(IVShmemState *s, int vector, Error **errp) >>>> { >>>> EventNotifier *n =3D &s->peers[s->vm_id].eventfds[vector]; >>>> bool with_irqfd =3D kvm_msi_via_irqfd_enabled() && >>>> ivshmem_has_feature(s, IVSHMEM_MSI); >>>> PCIDevice *pdev =3D PCI_DEVICE(s); >>>> + Error *err =3D NULL; >>>> >>>> IVSHMEM_DPRINTF("setting up interrupt for vector: %d\n", vector); >>>> >>>> @@ -546,13 +541,16 @@ static void setup_interrupt(IVShmemState *s, int= vector) >>>> watch_vector_notifier(s, n, vector); >>>> } else if (msix_enabled(pdev)) { >>>> IVSHMEM_DPRINTF("with irqfd\n"); >>>> - if (ivshmem_add_kvm_msi_virq(s, vector) < 0) { >>>> + ivshmem_add_kvm_msi_virq(s, vector, &err); >>>> + if (err) { >>>> + error_propagate(errp, err); >>>> return; >>> >>> That would make this simpler, avoiding local err variables, and >>> propagate. But you seem to prefer that form. I don't know if there is >>> any conventions (I am used to glib conventions, and usually a bool >>> success is returned, even if the function takes a GError) >> >> Does GLib spell out this convention somewhere? > > For glib, there is a paragraph about return bool/GError conventions > (which is usually adapted to other return type): > https://developer.gnome.org/glib/unstable/glib-Error-Reporting.html While I can't see a hard-and-fast rule there, the text clearly shows a strong preference for making the function value a reliable error indicator whenever possible. Thanks! >> >> I can perhaps try to cook up a patch to demonstrate the advantages of >> returning a success/failure value even with Error **, and try to get our >> convention changed. >> >> Until then, we better stick to the existing convention, whether we like >> it or not. > > ok