qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH V2 2/3] qmp: Make Quorum error events more palat


From: Benoît Canet
Subject: Re: [Qemu-devel] [PATCH V2 2/3] qmp: Make Quorum error events more palatable.
Date: Sat, 22 Feb 2014 03:09:29 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

The Friday 21 Feb 2014 à 18:42:01 (-0700), Eric Blake wrote :
> On 02/21/2014 06:20 PM, Benoît Canet wrote:
> > Insert quorum QMP events documentation alphabetically.
> >
> > Also change the "ret" errno value by an optional "error" being an 
> > strerror(-ret)
> > in the QUORUM_REPORT_BAD qmp event.
> >
> > Signed-off-by: Benoit Canet <address@hidden>
> > ---
>
> >      assert(node_name);
> > -    data = qobject_from_jsonf("{ 'ret': %d"
> > -                              ", 'node-name': %s"
> > +    data = qobject_from_jsonf("{ 'node-name': %s"
> >                                ", 'sector-num': %" PRId64
> >                                ", 'sectors-count': %d }",
> > -                              ret, node_name, acb->sector_num, 
> > acb->nb_sectors);
> > +                              node_name, acb->sector_num, acb->nb_sectors);
> > +    if (ret < 0) {
> > +        QDict *dict = qobject_to_qdict(data);
> > +        qdict_put(dict, "error", qstring_from_str(strerror(-ret)));
> > +    }
>
> This puts it in dict, but never modifies data...

qobject_to_qdict is an enhanced cast.

/**
 * qobject_to_qdict(): Convert a QObject into a QDict
 */
QDict *qobject_to_qdict(const QObject *obj)
{
    if (qobject_type(obj) != QTYPE_QDICT)
        return NULL;

    return container_of(obj, QDict, base);
}

Also I took this snippet of code from what you pointed me as an example for the
error handling.

Best regards

Benoît

>
> >      monitor_protocol_event(QEVENT_QUORUM_REPORT_BAD, data);
>
> ...but you send data, not dict, over the wire.
>
> It might be easier to do something like...
>
> char *str = NULL;
> if (ret < 0)
>     str = strerror(-ret);
> data = qobject_from_jsonf("{ 'node-name': %s"
>                           "%s%s%s"
>                           ", 'sector-num': %" PRId64
>                           ", 'sectors-cont': %d }",
>                           node_name,
>                           str ? ", 'error': \"" : "", str ? str : "",
>                           str ? "\"" : "",
> ...);
>
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library http://libvirt.org
>





reply via email to

[Prev in Thread] Current Thread [Next in Thread]