From: John Snow <jsnow@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: Amit Shah <amit.shah@redhat.com>,
peter.maydell@linaro.org, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2] virtio-rng: Add human-readable error message for negative max-bytes parameter
Date: Mon, 21 Jul 2014 16:13:06 -0400 [thread overview]
Message-ID: <53CD7452.2060204@redhat.com> (raw)
In-Reply-To: <8761iq7cbt.fsf@blackfin.pond.sub.org>
On 07/21/2014 03:15 PM, Markus Armbruster wrote:
> John Snow <jsnow@redhat.com> writes:
>
>> On 07/21/2014 01:33 PM, Markus Armbruster wrote:
>>> John Snow <jsnow@redhat.com> writes:
>>>
>>>> On 07/21/2014 03:48 AM, Markus Armbruster wrote:
>>>>> It certainly could check whether the value fits into uint64_t.
>>>>>
>>>>> A quick peek at how string-input-visitor.c uses strtoll() makes me
>>>>> cringe.
>>>>>
>>>>> [...]
>>>> What I meant by that was to say that by the time a value was returned
>>>> to visit_type_uint64, the value has already been possibly converted
>>>> implicitly from a negative value, and we can't tell at this level if
>>>> that happened without re-inspecting the string we were passed. At that
>>>> point, why not just fix the string parsing mechanics one more layer
>>>> down in parse_type_int() -- or by creating another routine primitive;
>>>> i.e parse_type_uint.
>>>>
>>>> As Eric Blake noted elsewhere in the thread, it would be nice to have
>>>> the ability to have three behaviors at the lowest level -- signed,
>>>> unsigned with wraparound, and unsigned strict. The biggest question in
>>>> my mind is how to add the property flag to allow authors to opt-in to
>>>> the unsigned with wraparound option, where the unsigned strict option
>>>> makes the most sense to me as a default.
>>> Do we have a use case for silently mapping negative numbers to positive
>>> ones?
>> Via Eric Blake, for cases where "-1" is a convenient shorthand for
>> "MAX" in lieu of writing out gibberish values like 4 billion or 18
>> quintillion. I don't know if anyone actually relies on this behavior,
>> but I don't know that they're not. I can easily imagine something like
>> --max-log-messages=-1, for instance.
> That's a pretty horrid way to let people say "maximum, please".
>
> But I accept a backward compatibility argument.
>
Semantically and from an end-user usability standpoint, I certainly
don't disagree. In almost all cases, --no-limit or --use-maximum or
similar explicit commands are more meaningful, but knowing whether or
not we need to support parsing negative integers for unsigned properties
will come later. Perhaps in our case we will be able to avoid supporting
such a case and force people to use semantically meaningful properties.
I can certainly grep through the code to find out who is using unsigned
properties. In the case of uint32, -1 I believe will already wrap around
but then overflow (because we parse as uint64_t) and throw an error, so
I don't expect we will see anyone using -1 to signify "MAX" for less
than 64bit properties. In the case of uint64, it may be more difficult
to see who, if anyone, is abusing such behavior.
However, from a quick look-see it looks like DEFINE_PROP_UINT64 is used
in 26 places. The fourth argument is "default value" and you can see
many authors using -1 here, so either these authors expect wraparound or
are trying to set the default value to something invalid that they will
try to catch later on somehow.
CC'ing Eric Blake again for input, since he went through a similar
ordeal recently and might have some input.
next prev parent reply other threads:[~2014-07-21 20:13 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-17 20:47 [Qemu-devel] [PATCH v2] virtio-rng: Add human-readable error message for negative max-bytes parameter John Snow
2014-07-18 6:27 ` Markus Armbruster
2014-07-18 7:46 ` Amit Shah
2014-07-18 11:15 ` Markus Armbruster
2014-07-18 11:27 ` Amit Shah
2014-07-18 11:54 ` Markus Armbruster
2014-07-18 12:14 ` Amit Shah
2014-07-18 13:16 ` Markus Armbruster
2014-07-18 16:22 ` John Snow
2014-07-21 7:38 ` Markus Armbruster
2014-07-18 21:14 ` John Snow
2014-07-18 21:53 ` Eric Blake
2014-07-21 7:48 ` Markus Armbruster
2014-07-21 15:44 ` John Snow
2014-07-21 17:33 ` Markus Armbruster
2014-07-21 17:53 ` John Snow
2014-07-21 19:15 ` Markus Armbruster
2014-07-21 20:13 ` John Snow [this message]
2014-07-21 20:31 ` Eric Blake
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=53CD7452.2060204@redhat.com \
--to=jsnow@redhat.com \
--cc=amit.shah@redhat.com \
--cc=armbru@redhat.com \
--cc=peter.maydell@linaro.org \
--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.