All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: "Michael S. Tsirkin" <mst@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, armbru@redhat.com, dgilbert@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 1/3] error: don't rely on pointer comparisons
Date: Wed, 17 Jun 2015 09:21:00 -0600	[thread overview]
Message-ID: <5581905C.5060406@redhat.com> (raw)
In-Reply-To: <1434525861-21768-2-git-send-email-mst@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3015 bytes --]

On 06/17/2015 01:24 AM, Michael S. Tsirkin wrote:
> makes it possible to copy error_abort pointers,
> not just pass them on directly.
> 
> This is needed because follow-up patches add support for
>     Error *local_err = ...;
> as a way to set an abort-on-error pointer, which requires that we have
> more than just a global error_abort abort-on-error pointer, but that any
> number of pointers all resolve to something specific.
> 
> Add an assert statement when class is retrieved, to make sure we still
> get a core-dump if we (somehow) attempt to output the abort errp by
> mistake.
> 
> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> Reviewed-by: Eric Blake <eblake@redhat.com>

I think you made enough changes from v1 (functional change of an added
assertion, but also better justification via improved commit message)
that I would have dropped R-b if I were the one submitting it.

Your argument of aiding gdb debugging of error objects by making the
pointer point somewhere valid makes sense, when compared to my hack of
an invalid pointer that would segfault even when trying to view it
through gdb.  The added assertion in this version definitely helps avoid
code making the mistake of dereferencing the magic error pointer.

> ---
>  util/error.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/util/error.c b/util/error.c
> index 14f4351..e10cb34 100644
> --- a/util/error.c
> +++ b/util/error.c
> @@ -20,7 +20,13 @@ struct Error
>      ErrorClass err_class;
>  };
>  
> -Error *error_abort;
> +static Error error_abort_st = { .err_class = ERROR_CLASS_MAX };
> +Error *error_abort = &error_abort_st;
> +
> +static bool error_is_abort(Error **errp)
> +{
> +    return errp && *errp == error_abort;

However, now I don't like the subject line.  This is still a pointer
comparison (just a different pointer than before).  So while I'm now
happy with the state of the code, I think a better commit message would be:

error: don't rely on address of global variable

The old implementation used the address of a global pointer variable
(&error_abort, type Error**) as a sentinel.  This patch changes to using
the value of the global pointer variable itself (error_abort, type
Error*), so that the sentinel value can be easily copied to other Error*
pointers, regardless of their address.  The new sentinel points to an
actual object, in case it is inspected through a debugger, although
working code should never dereference it.

This is needed because...[snipped]

> @@ -144,6 +150,7 @@ Error *error_copy(const Error *err)
>  
>  ErrorClass error_get_class(const Error *err)
>  {
> +    assert(err->err_class < ERROR_CLASS_MAX);

I also think you should add this assert in error_copy() a few lines
above, as well as in error_get_pretty() and error_free() a few lines below.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

  reply	other threads:[~2015-06-17 15:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-17  7:24 [Qemu-devel] [PATCH v2 0/3] error: allow local errors to trigger abort Michael S. Tsirkin
2015-06-17  7:24 ` [Qemu-devel] [PATCH v2 1/3] error: don't rely on pointer comparisons Michael S. Tsirkin
2015-06-17 15:21   ` Eric Blake [this message]
2015-06-17 15:41   ` Eric Blake
2015-06-18 15:36     ` Markus Armbruster
2015-06-18 16:10   ` Markus Armbruster
2015-06-17  7:24 ` [Qemu-devel] [PATCH v2 2/3] error: allow local errors to trigger abort Michael S. Tsirkin
2015-06-17  7:24 ` [Qemu-devel] [PATCH v2 3/3] block/nfs: switch to error_init_local Michael S. Tsirkin
2015-06-17 15:32   ` Eric Blake
2015-06-23  9:03     ` Michael S. Tsirkin
2015-06-18 16:34 ` [Qemu-devel] [PATCH v2 0/3] error: allow local errors to trigger abort Markus Armbruster
2015-06-18 16:49   ` Paolo Bonzini
2015-06-22 11:31     ` Markus Armbruster

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=5581905C.5060406@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.