diff mbox

[v5,19/22] blkdebug: Alias "errno" as "error"

Message ID 1386954633-28905-20-git-send-email-mreitz@redhat.com
State New
Headers show

Commit Message

Max Reitz Dec. 13, 2013, 5:10 p.m. UTC
Introduce an alias "error" for "errno", since using the latter for QMP
is sure to result in various syntax errors due to the name being used
directly as an identifier.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block/blkdebug.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Kevin Wolf Dec. 13, 2013, 8:49 p.m. UTC | #1
Am 13.12.2013 um 18:10 hat Max Reitz geschrieben:
> Introduce an alias "error" for "errno", since using the latter for QMP
> is sure to result in various syntax errors due to the name being used
> directly as an identifier.
> 
> Signed-off-by: Max Reitz <mreitz@redhat.com>

I can't say I like this, but it seems we don't have an option.

Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Eric Blake Dec. 13, 2013, 9 p.m. UTC | #2
On 12/13/2013 01:49 PM, Kevin Wolf wrote:
> Am 13.12.2013 um 18:10 hat Max Reitz geschrieben:
>> Introduce an alias "error" for "errno", since using the latter for QMP
>> is sure to result in various syntax errors due to the name being used
>> directly as an identifier.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
> 
> I can't say I like this, but it seems we don't have an option.

Don't we already have a way to use QMP keys that collide with C keywords
(for example, "unix" in qapi's SocketAddress becomes "q_unix" in C)?
Why can't we reuse that mechanism, and just add "errno" to the polluted
words list so that the generated C code uses "q_errno" rather than
having to invent an "error" alias?
Kevin Wolf Dec. 13, 2013, 9:23 p.m. UTC | #3
Am 13.12.2013 um 22:00 hat Eric Blake geschrieben:
> On 12/13/2013 01:49 PM, Kevin Wolf wrote:
> > Am 13.12.2013 um 18:10 hat Max Reitz geschrieben:
> >> Introduce an alias "error" for "errno", since using the latter for QMP
> >> is sure to result in various syntax errors due to the name being used
> >> directly as an identifier.
> >>
> >> Signed-off-by: Max Reitz <mreitz@redhat.com>
> > 
> > I can't say I like this, but it seems we don't have an option.
> 
> Don't we already have a way to use QMP keys that collide with C keywords
> (for example, "unix" in qapi's SocketAddress becomes "q_unix" in C)?
> Why can't we reuse that mechanism, and just add "errno" to the polluted
> words list so that the generated C code uses "q_errno" rather than
> having to invent an "error" alias?

Oh, I didn't know that this exists. Sounds better then, because it makes
the external interfaces uniform, even though internally we'd still have
aliases (errno/q_errno instead of errno/error then).

Kevin
Max Reitz Dec. 13, 2013, 11:59 p.m. UTC | #4
On 13.12.2013 22:00, Eric Blake wrote:
> On 12/13/2013 01:49 PM, Kevin Wolf wrote:
>> Am 13.12.2013 um 18:10 hat Max Reitz geschrieben:
>>> Introduce an alias "error" for "errno", since using the latter for QMP
>>> is sure to result in various syntax errors due to the name being used
>>> directly as an identifier.
>>>
>>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> I can't say I like this, but it seems we don't have an option.
> Don't we already have a way to use QMP keys that collide with C keywords
> (for example, "unix" in qapi's SocketAddress becomes "q_unix" in C)?
> Why can't we reuse that mechanism, and just add "errno" to the polluted
> words list so that the generated C code uses "q_errno" rather than
> having to invent an "error" alias?

Great, I'll have a look.

Max
diff mbox

Patch

diff --git a/block/blkdebug.c b/block/blkdebug.c
index fdfc6b0..522a766 100644
--- a/block/blkdebug.c
+++ b/block/blkdebug.c
@@ -100,6 +100,10 @@  static QemuOptsList inject_error_opts = {
             .type = QEMU_OPT_NUMBER,
         },
         {
+            .name = "error",
+            .type = QEMU_OPT_NUMBER,
+        },
+        {
             .name = "sector",
             .type = QEMU_OPT_NUMBER,
         },
@@ -232,7 +236,8 @@  static int add_rule(QemuOpts *opts, void *opaque)
     /* Parse action-specific options */
     switch (d->action) {
     case ACTION_INJECT_ERROR:
-        rule->options.inject.error = qemu_opt_get_number(opts, "errno", EIO);
+        rule->options.inject.error = qemu_opt_get_number(opts,
+                qemu_opt_get(opts, "errno") ? "errno" : "error", EIO);
         rule->options.inject.once  = qemu_opt_get_bool(opts, "once", 0);
         rule->options.inject.immediately =
             qemu_opt_get_bool(opts, "immediately", 0);