qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Cc: "Fam Zheng" <fam@euphon.net>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Jeff Cody" <codyprime@gmail.com>,
	"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
	"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
	"Michael Roth" <mdroth@linux.vnet.ibm.com>,
	"Gerd Hoffmann" <kraxel@redhat.com>,
	"Max Reitz" <mreitz@redhat.com>,
	"qemu-block@nongnu.org" <qemu-block@nongnu.org>,
	"Juan Quintela" <quintela@redhat.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Halil Pasic" <pasic@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@de.ibm.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Richard Henderson" <rth@twiddle.net>,
	"Eric Farman" <farman@linux.ibm.com>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Yuval Shaia" <yuval.shaia@oracle.com>,
	"Alex Williamson" <alex.williamson@redhat.com>,
	"qemu-arm@nongnu.org" <qemu-arm@nongnu.org>,
	"John Snow" <jsnow@redhat.com>,
	"David Gibson" <david@gibson.dropbear.id.au>,
	"Kevin Wolf" <kwolf@redhat.com>,
	"berrange@redhat.com" <berrange@redhat.com>,
	"Cornelia Huck" <cohuck@redhat.com>,
	qemu-s390x@nongnu.org,
	"Subbaraya Sundeep" <sundeep.lkml@gmail.com>,
	"qemu-ppc@nongnu.org" <qemu-ppc@nongnu.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 02/17] block: Pass local error object pointer to error_append_hint()
Date: Tue, 17 Sep 2019 17:37:56 +0200	[thread overview]
Message-ID: <20190917173756.5ff0e571@bahia.lan> (raw)
In-Reply-To: <5dba090e-8a59-6f42-a93a-eb676422211e@virtuozzo.com>

On Tue, 17 Sep 2019 13:25:03 +0000
Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> wrote:

> 17.09.2019 13:20, Greg Kurz wrote:
> > Ensure that hints are added even if errp is &error_fatal or &error_abort.
> > 
> > Signed-off-by: Greg Kurz <groug@kaod.org>
> > ---
> >   block/backup.c       |    7 +++++--
> >   block/dirty-bitmap.c |    7 +++++--
> >   block/file-posix.c   |   20 +++++++++++++-------
> >   block/gluster.c      |   23 +++++++++++++++--------
> >   block/qcow.c         |   10 ++++++----
> >   block/qcow2.c        |    7 +++++--
> >   block/vhdx-log.c     |    7 +++++--
> >   block/vpc.c          |    7 +++++--
> >   8 files changed, 59 insertions(+), 29 deletions(-)
> > 
> > diff --git a/block/backup.c b/block/backup.c
> > index 763f0d7ff6db..d8c422a0e3bc 100644
> > --- a/block/backup.c
> > +++ b/block/backup.c
> > @@ -602,11 +602,14 @@ static int64_t backup_calculate_cluster_size(BlockDriverState *target,
> >                       BACKUP_CLUSTER_SIZE_DEFAULT);
> >           return BACKUP_CLUSTER_SIZE_DEFAULT;
> >       } else if (ret < 0 && !target->backing) {
> > -        error_setg_errno(errp, -ret,
> > +        Error *local_err = NULL;
> > +
> > +        error_setg_errno(&local_err, -ret,
> >               "Couldn't determine the cluster size of the target image, "
> >               "which has no backing file");
> > -        error_append_hint(errp,
> > +        error_append_hint(&local_err,
> >               "Aborting, since this may create an unusable destination image\n");
> > +        error_propagate(errp, local_err);
> >           return ret;
> >       } else if (ret < 0 && target->backing) {
> >           /* Not fatal; just trudge on ahead. */
> 
> 
> Pain.. Do we need these hints, if they are so painful?
> 

I agree that the one above doesn't qualify as a useful hint.
It just tells that QEMU is giving up and gives no indication
to the user on how to avoid the issue. It should probably be
dropped.

> At least for cases like this, we can create helper function
> 
> error_setg_errno_hint(..., error, hint)

Not very useful if hint has to be forged separately with
g_sprintf(), and we can't have such a thing as:

error_setg_errno_hint(errp, err_fmt, ..., hint_fmt, ...)

> 
> But what could be done when we call function, which may or may not set errp?
> 
> ret = f(errp);
> if (ret) {
>     error_append_hint(errp, hint);
> }
> 

Same problem. If errp is &error_fatal and f() does errno_setg(errp), it
ends up calling exit().

> Hmmm..
> 
> Can it look like
> 
> ret = f(..., hint_helper(errp, hint))
> 
> ?
> 

Nope, hint_helper() will get called before f() and things are worse.
If errp is NULL then error_append_hint() does nothing and if it is
&error_fatal then it aborts.

> I can't imagine how to do it, as someone should remove hint from error_abort object on
> success path..
> 
> But seems, the following is possible, which seems better for me than local-error approach:
> 
> error_push_hint(errp, hint);
> ret = f(.., errp);
> error_pop_hint(errp);
> 

Matter of taste... also, it looks awkward to come up with a hint
before knowing what happened. I mean the appropriate hint could
depend on the value returned by f() and/or errno for example.

> ===
> 
> Continue thinking on this:
> 
> It may look like just
> ret = f(..., set_hint(errp, hint));
> 
> or (just to split long line):
> set_hint(errp, hint);
> ret = f(..., errp);
> 
> if in each function with errp does error_push_hint(errp) on start and error_pop_hint(errp) on exit,
> which may be just one call at function start of macro, which will call error_push_hint(errp) and
> define local variable by g_auto, with cleanup which will call error_pop_hint(errp) on function
> exit..
> 
> Or, may be, more direct way to set cleanup for function exists?
> 
> ===
> 
> Also, we can implement some code generation, to generate for functions with errp argument
> wrappers with additional hint parameter, and just use these wrappers..
> 
> ===
> 
> If nobody likes any of my suggestions, then ignore them. I understand that this series fixes
> real issue and much effort has already been spent. May be one day I'll try to rewrite it...
> 

For the reason exposed above, I don't think it makes sense to
build the hint before calling a function that calls error_setg().
I'm afraid we're stuck with local_err... it is then up to the
people to make it as less painful as possible.


  reply	other threads:[~2019-09-17 15:47 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-17 10:20 [Qemu-devel] [PATCH 00/17] Fix usage of error_append_hint() Greg Kurz
2019-09-17 10:20 ` [Qemu-devel] [PATCH 01/17] error: Update error_append_hint()'s documentation Greg Kurz
2019-09-17 11:21   ` Cornelia Huck
2019-09-17 14:36   ` Eric Blake
2019-09-17 10:20 ` [Qemu-devel] [PATCH 02/17] block: Pass local error object pointer to error_append_hint() Greg Kurz
2019-09-17 13:25   ` Vladimir Sementsov-Ogievskiy
2019-09-17 15:37     ` Greg Kurz [this message]
2019-09-17 17:40       ` Vladimir Sementsov-Ogievskiy
2019-09-18  7:58         ` Greg Kurz
2019-09-18 10:17           ` Vladimir Sementsov-Ogievskiy
2019-09-17 14:39   ` Eric Blake
2019-09-17 14:46     ` Kevin Wolf
2019-09-17 16:40       ` Greg Kurz
2019-09-17 19:10       ` John Snow
2019-09-18  7:33         ` Kevin Wolf
2019-09-17 10:20 ` [Qemu-devel] [PATCH 03/17] char/spice: " Greg Kurz
2019-09-17 10:20 ` [Qemu-devel] [PATCH 04/17] ppc: " Greg Kurz
2019-09-18  0:12   ` David Gibson
2019-09-17 10:21 ` [Qemu-devel] [PATCH 05/17] arm: " Greg Kurz
2019-09-17 10:21 ` [Qemu-devel] [PATCH 06/17] vfio: " Greg Kurz
2019-09-17 11:26   ` Cornelia Huck
2019-09-17 10:21 ` [Qemu-devel] [PATCH 07/17] virtio-pci: " Greg Kurz
2019-09-17 10:21 ` [Qemu-devel] [PATCH 08/17] pcie_root_port: " Greg Kurz
2019-09-17 10:21 ` [Qemu-devel] [PATCH 09/17] hw/rdma: Fix missing conversion to rdma_error_report() Greg Kurz
2019-09-17 14:51   ` Yuval Shaia
2019-09-17 16:15     ` Greg Kurz
2019-09-17 10:21 ` [Qemu-devel] [PATCH 10/17] s390x/css: Pass local error object pointer to error_append_hint() Greg Kurz
2019-09-17 11:24   ` Cornelia Huck
2019-09-17 11:44     ` David Hildenbrand
2019-09-17 16:36     ` Greg Kurz
2019-09-18 10:26       ` Cornelia Huck
2019-09-18 17:46         ` Eric Blake
2019-09-19  8:50           ` Cornelia Huck
2019-09-17 10:21 ` [Qemu-devel] [PATCH 11/17] scsi: " Greg Kurz
2019-09-17 10:21 ` [Qemu-devel] [PATCH 12/17] migration: " Greg Kurz
2019-09-17 10:32   ` Dr. David Alan Gilbert
2019-09-17 10:21 ` [Qemu-devel] [PATCH 13/17] nbd: " Greg Kurz
2019-09-17 15:15   ` Eric Blake
2019-09-17 16:26     ` Greg Kurz
2019-09-17 10:21 ` [Qemu-devel] [PATCH 14/17] ccid-card-emul: " Greg Kurz
2019-09-17 10:22 ` [Qemu-devel] [PATCH 15/17] option: " Greg Kurz
2019-09-17 10:22 ` [Qemu-devel] [PATCH 16/17] socket: " Greg Kurz
2019-09-17 10:22 ` [Qemu-devel] [PATCH 17/17] checkpatch: Warn when errp is passed " Greg Kurz
2019-09-17 10:56   ` Philippe Mathieu-Daudé
2019-09-17 11:29   ` Cornelia Huck
2019-09-17 11:47     ` Greg Kurz
2019-09-17 11:00 ` [Qemu-devel] [PATCH 00/17] Fix usage of error_append_hint() Philippe Mathieu-Daudé
2019-09-17 11:45   ` Greg Kurz
2019-09-17 11:49     ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190917173756.5ff0e571@bahia.lan \
    --to=groug@kaod.org \
    --cc=alex.williamson@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=borntraeger@de.ibm.com \
    --cc=codyprime@gmail.com \
    --cc=cohuck@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=david@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=fam@euphon.net \
    --cc=farman@linux.ibm.com \
    --cc=jsnow@redhat.com \
    --cc=kraxel@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mark.cave-ayland@ilande.co.uk \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@nongnu.org \
    --cc=qemu-s390x@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=rth@twiddle.net \
    --cc=sundeep.lkml@gmail.com \
    --cc=vsementsov@virtuozzo.com \
    --cc=yuval.shaia@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).