Skip to contentSkip to conversation

qapi: Incorrect attempt to fix building with MC146818RTC=n

RFC PATCH In review Philippe Mathieu-Daudé 3 participants 12 messages Dec 31, 2019 – Jan 23, 2020

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 qapi: Incorrect attempt to fix building with MC146818RTC=n

When configured with --without-default-devices and setting MC146818RTC=n, the build fails:

    LINK    x86_64-softmmu/qemu-system-x86_64

/usr/bin/ld: qapi/qapi-commands-misc-target.o: in function `qmp_marshal_rtc_reset_reinjection':
qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection' /usr/bin/ld: qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-x86_64] Error 1
make: *** [Makefile:483: x86_64-softmmu/all] Error 2

This patch tries to fix this, but this is incorrect because QAPI scripts only provide TARGET definitions, so with MC146818RTC=y we get:

hw/rtc/mc146818rtc.c:113:6: error: no previous prototype for ‘qmp_rtc_reset_reinjection’ [-Werror=missing-prototypes]
113 | void qmp_rtc_reset_reinjection(Error **errp)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [rules.mak:69: hw/rtc/mc146818rtc.o] Error 1

Any idea? :)

---
 qapi/misc-target.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qapi/misc-target.json +1 -1
index a00fd821eb..8e49c113d1 100644
@@ -41,7 +41,7 @@
 #
 ##
 { 'command': 'rtc-reset-reinjection',
-  'if': 'defined(TARGET_I386)' }
+  'if': 'defined(TARGET_I386) && defined(CONFIG_MC146818RTC)' }
 
 
 ##
Signature · 1 line
2.21.0
#1 lore raw
Quoted 15 lines · Philippe Mathieu-Daudé

When configured with --without-default-devices and setting MC146818RTC=n, the build fails:

    LINK    x86_64-softmmu/qemu-system-x86_64

/usr/bin/ld: qapi/qapi-commands-misc-target.o: in function `qmp_marshal_rtc_reset_reinjection':
qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection' /usr/bin/ld: qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-x86_64] Error 1
make: *** [Makefile:483: x86_64-softmmu/all] Error 2

This patch tries to fix this, but this is incorrect because QAPI scripts only provide TARGET definitions, so with MC146818RTC=y we get:

Quoted 7 lines

hw/rtc/mc146818rtc.c:113:6: error: no previous prototype for ‘qmp_rtc_reset_reinjection’ [-Werror=missing-prototypes]
113 | void qmp_rtc_reset_reinjection(Error **errp)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [rules.mak:69: hw/rtc/mc146818rtc.o] Error 1

Any idea? :)

Adding a stub seems like a good alternative. Is the purpose of this to change MicroVM's select directive to imply?

Paolo

#2 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 33 lines · Philippe Mathieu-Daudé

When configured with --without-default-devices and setting MC146818RTC=n, the build fails:

    LINK    x86_64-softmmu/qemu-system-x86_64

/usr/bin/ld: qapi/qapi-commands-misc-target.o: in function `qmp_marshal_rtc_reset_reinjection':
qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection' /usr/bin/ld: qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-x86_64] Error 1
make: *** [Makefile:483: x86_64-softmmu/all] Error 2

This patch tries to fix this, but this is incorrect because QAPI scripts only provide TARGET definitions, so with MC146818RTC=y we get:

hw/rtc/mc146818rtc.c:113:6: error: no previous prototype for ‘qmp_rtc_reset_reinjection’ [-Werror=missing-prototypes]
113 | void qmp_rtc_reset_reinjection(Error **errp)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [rules.mak:69: hw/rtc/mc146818rtc.o] Error 1

Any idea? :)

---
 qapi/misc-target.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qapi/misc-target.json +0 -0
index a00fd821eb..8e49c113d1 100644

qapi/misc-target.json line 47

Quoted 8 lines
qapi/misc-target.json +1 -1
@@ -41,7 +41,7 @@
 #
 ##
 { 'command': 'rtc-reset-reinjection',
-  'if': 'defined(TARGET_I386)' }
+  'if': 'defined(TARGET_I386) && defined(CONFIG_MC146818RTC)' }
 
 
 ##

The generated qapi-commands-misc-target.h duly has

    #if defined(TARGET_I386) && defined(CONFIG_MC146818RTC)
    void qmp_rtc_reset_reinjection(Error **errp);
    void qmp_marshal_rtc_reset_reinjection(QDict *args, QObject **ret, Error **errp);
    #endif /* defined(TARGET_I386) && defined(CONFIG_MC146818RTC) */

mc146818rtc.c includes it. But since it doesn't include config-devices.h, CONFIG_MC146818RTC remains undefined, and the prototype gets suppressed.

Crude fix: make mc146818rtc.c #include "config-devices.h".

#3 lore raw
Quoted 51 lines · Markus Armbruster
Quoted 33 lines · Philippe Mathieu-Daudé

When configured with --without-default-devices and setting MC146818RTC=n, the build fails:

    LINK    x86_64-softmmu/qemu-system-x86_64

/usr/bin/ld: qapi/qapi-commands-misc-target.o: in function `qmp_marshal_rtc_reset_reinjection':
qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection' /usr/bin/ld: qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-x86_64] Error 1
make: *** [Makefile:483: x86_64-softmmu/all] Error 2

This patch tries to fix this, but this is incorrect because QAPI scripts only provide TARGET definitions, so with MC146818RTC=y we get:

hw/rtc/mc146818rtc.c:113:6: error: no previous prototype for ‘qmp_rtc_reset_reinjection’ [-Werror=missing-prototypes]
113 | void qmp_rtc_reset_reinjection(Error **errp)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [rules.mak:69: hw/rtc/mc146818rtc.o] Error 1

Any idea? :)

---
 qapi/misc-target.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qapi/misc-target.json +0 -0
index a00fd821eb..8e49c113d1 100644

qapi/misc-target.json line 47

Quoted 8 lines
qapi/misc-target.json +1 -1
@@ -41,7 +41,7 @@
 #
 ##
 { 'command': 'rtc-reset-reinjection',
-  'if': 'defined(TARGET_I386)' }
+  'if': 'defined(TARGET_I386) && defined(CONFIG_MC146818RTC)' }
 
 
 ##

The generated qapi-commands-misc-target.h duly has

    #if defined(TARGET_I386) && defined(CONFIG_MC146818RTC)
    void qmp_rtc_reset_reinjection(Error **errp);
    void qmp_marshal_rtc_reset_reinjection(QDict *args, QObject **ret, Error **errp);
    #endif /* defined(TARGET_I386) && defined(CONFIG_MC146818RTC) */
Quoted 5 lines

mc146818rtc.c includes it. But since it doesn't include config-devices.h, CONFIG_MC146818RTC remains undefined, and the prototype gets suppressed.

Crude fix: make mc146818rtc.c #include "config-devices.h".

Can we modify the code generator to leave out the #if from the header, and only include it in the .c file? An extra prototype is harmless.

Paolo

#4 lore raw
Quoted 52 lines · Paolo Bonzini
Quoted 51 lines · Markus Armbruster
Quoted 33 lines · Philippe Mathieu-Daudé

When configured with --without-default-devices and setting MC146818RTC=n, the build fails:

    LINK    x86_64-softmmu/qemu-system-x86_64

/usr/bin/ld: qapi/qapi-commands-misc-target.o: in function `qmp_marshal_rtc_reset_reinjection':
qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection' /usr/bin/ld: qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-x86_64] Error 1
make: *** [Makefile:483: x86_64-softmmu/all] Error 2

This patch tries to fix this, but this is incorrect because QAPI scripts only provide TARGET definitions, so with MC146818RTC=y we get:

hw/rtc/mc146818rtc.c:113:6: error: no previous prototype for ‘qmp_rtc_reset_reinjection’ [-Werror=missing-prototypes]
113 | void qmp_rtc_reset_reinjection(Error **errp)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [rules.mak:69: hw/rtc/mc146818rtc.o] Error 1

Any idea? :)

---
 qapi/misc-target.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qapi/misc-target.json +0 -0
index a00fd821eb..8e49c113d1 100644

qapi/misc-target.json line 47

Quoted 8 lines
qapi/misc-target.json +1 -1
@@ -41,7 +41,7 @@
 #
 ##
 { 'command': 'rtc-reset-reinjection',
-  'if': 'defined(TARGET_I386)' }
+  'if': 'defined(TARGET_I386) && defined(CONFIG_MC146818RTC)' }
 
 
 ##

The generated qapi-commands-misc-target.h duly has

    #if defined(TARGET_I386) && defined(CONFIG_MC146818RTC)
    void qmp_rtc_reset_reinjection(Error **errp);
    void qmp_marshal_rtc_reset_reinjection(QDict *args, QObject **ret, Error **errp);
    #endif /* defined(TARGET_I386) && defined(CONFIG_MC146818RTC) */
Quoted 8 lines
Quoted 5 lines

mc146818rtc.c includes it. But since it doesn't include config-devices.h, CONFIG_MC146818RTC remains undefined, and the prototype gets suppressed.

Crude fix: make mc146818rtc.c #include "config-devices.h".

Can we modify the code generator to leave out the #if from the header, and only include it in the .c file? An extra prototype is harmless.

Is *everything* we generate into headers just as harmless?

Another idea: provide a hook to make the generator insert the #include necessary to get the macros used in 'if'.

Yet another idea: include it always in target-specific code, just like config-target.h.

#5 lore raw
Quoted 58 lines · Markus Armbruster
Quoted 56 lines · Paolo Bonzini
Quoted 55 lines · Markus Armbruster
Quoted 33 lines · Philippe Mathieu-Daudé

When configured with --without-default-devices and setting MC146818RTC=n, the build fails:

    LINK    x86_64-softmmu/qemu-system-x86_64

/usr/bin/ld: qapi/qapi-commands-misc-target.o: in function `qmp_marshal_rtc_reset_reinjection':
qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection' /usr/bin/ld: qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-x86_64] Error 1
make: *** [Makefile:483: x86_64-softmmu/all] Error 2

This patch tries to fix this, but this is incorrect because QAPI scripts only provide TARGET definitions, so with MC146818RTC=y we get:

hw/rtc/mc146818rtc.c:113:6: error: no previous prototype for ‘qmp_rtc_reset_reinjection’ [-Werror=missing-prototypes]
113 | void qmp_rtc_reset_reinjection(Error **errp)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [rules.mak:69: hw/rtc/mc146818rtc.o] Error 1

Any idea? :)

---
 qapi/misc-target.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qapi/misc-target.json +0 -0
index a00fd821eb..8e49c113d1 100644

qapi/misc-target.json line 47

Quoted 8 lines
qapi/misc-target.json +1 -1
@@ -41,7 +41,7 @@
 #
 ##
 { 'command': 'rtc-reset-reinjection',
-  'if': 'defined(TARGET_I386)' }
+  'if': 'defined(TARGET_I386) && defined(CONFIG_MC146818RTC)' }
 
 
 ##

The generated qapi-commands-misc-target.h duly has

    #if defined(TARGET_I386) && defined(CONFIG_MC146818RTC)
    void qmp_rtc_reset_reinjection(Error **errp);
    void qmp_marshal_rtc_reset_reinjection(QDict *args, QObject **ret, Error **errp);
    #endif /* defined(TARGET_I386) && defined(CONFIG_MC146818RTC) */

mc146818rtc.c includes it. But since it doesn't include config-devices.h, CONFIG_MC146818RTC remains undefined, and the prototype gets suppressed.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Crude fix: make mc146818rtc.c #include "config-devices.h".

Can we modify the code generator to leave out the #if from the header, and only include it in the .c file? An extra prototype is harmless.

Is *everything* we generate into headers just as harmless?

It should be, since it's just the C version of some JSON. The only problematic thing could be different definitions of the same command for multiple targets, and I think we want to avoid that anyway.

To see it a different way, these are the "C bindings" to QMP, just that the implementation is an in-process call rather than RPC. If the QAPI code generator was also able to generate Python bindings and the like, they would have to be the same for all QEMU binaries, wouldn't they?

Paolo

#6 lore raw
Quoted 66 lines · Paolo Bonzini
Quoted 58 lines · Markus Armbruster
Quoted 56 lines · Paolo Bonzini
Quoted 55 lines · Markus Armbruster
Quoted 33 lines · Philippe Mathieu-Daudé

When configured with --without-default-devices and setting MC146818RTC=n, the build fails:

    LINK    x86_64-softmmu/qemu-system-x86_64

/usr/bin/ld: qapi/qapi-commands-misc-target.o: in function `qmp_marshal_rtc_reset_reinjection':
qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection' /usr/bin/ld: qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-x86_64] Error 1
make: *** [Makefile:483: x86_64-softmmu/all] Error 2

This patch tries to fix this, but this is incorrect because QAPI scripts only provide TARGET definitions, so with MC146818RTC=y we get:

hw/rtc/mc146818rtc.c:113:6: error: no previous prototype for ‘qmp_rtc_reset_reinjection’ [-Werror=missing-prototypes]
113 | void qmp_rtc_reset_reinjection(Error **errp)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [rules.mak:69: hw/rtc/mc146818rtc.o] Error 1

Any idea? :)

---
 qapi/misc-target.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
qapi/misc-target.json +0 -0
index a00fd821eb..8e49c113d1 100644

qapi/misc-target.json line 47

Quoted 8 lines
qapi/misc-target.json +1 -1
@@ -41,7 +41,7 @@
 #
 ##
 { 'command': 'rtc-reset-reinjection',
-  'if': 'defined(TARGET_I386)' }
+  'if': 'defined(TARGET_I386) && defined(CONFIG_MC146818RTC)' }
 
 
 ##

The generated qapi-commands-misc-target.h duly has

    #if defined(TARGET_I386) && defined(CONFIG_MC146818RTC)
    void qmp_rtc_reset_reinjection(Error **errp);
    void qmp_marshal_rtc_reset_reinjection(QDict *args, QObject **ret, Error **errp);
    #endif /* defined(TARGET_I386) && defined(CONFIG_MC146818RTC) */

mc146818rtc.c includes it. But since it doesn't include config-devices.h, CONFIG_MC146818RTC remains undefined, and the prototype gets suppressed.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Crude fix: make mc146818rtc.c #include "config-devices.h".

Can we modify the code generator to leave out the #if from the header, and only include it in the .c file? An extra prototype is harmless.

Is *everything* we generate into headers just as harmless?

Quoted 8 lines

It should be, since it's just the C version of some JSON. The only problematic thing could be different definitions of the same command for multiple targets, and I think we want to avoid that anyway.

To see it a different way, these are the "C bindings" to QMP, just that the implementation is an in-process call rather than RPC. If the QAPI code generator was also able to generate Python bindings and the like, they would have to be the same for all QEMU binaries, wouldn't they?

Ommitting the kind of #if we've been discussing is relatively harmless:

    #if defined(TARGET_I386)
    void qmp_rtc_reset_reinjection(Error **errp);
    void qmp_marshal_rtc_reset_reinjection(QDict *args, QObject **ret, Error **errp);
    #endif /* defined(TARGET_I386) */

But what about this one, in qapi-types-block-core.h:

    typedef enum BlockdevDriver {
        BLOCKDEV_DRIVER_BLKDEBUG,
        [...]
    #if defined(CONFIG_REPLICATION)
        BLOCKDEV_DRIVER_REPLICATION,
    #endif /* defined(CONFIG_REPLICATION) */
        [...]
        BLOCKDEV_DRIVER__MAX,
    } BlockdevDriver;

If I omit it in the header, I then have to omit it in qapi-types-block-core.c's

    const QEnumLookup BlockdevDriver_lookup = {
        .array = (const char *const[]) {
            [BLOCKDEV_DRIVER_BLKDEBUG] = "blkdebug",
            [...]
    #if defined(CONFIG_REPLICATION)
            [BLOCKDEV_DRIVER_REPLICATION] = "replication",
    #endif /* defined(CONFIG_REPLICATION) */
            [...]
        },
        .size = BLOCKDEV_DRIVER__MAX
    };

and God knows what else. But I must not omit it in qapi-introspect.c's

        QLIT_QDICT(((QLitDictEntry[]) {
            { "meta-type", QLIT_QSTR("enum"), },
            { "name", QLIT_QSTR("245"), },
            { "values", QLIT_QLIST(((QLitObject[]) {
                QLIT_QSTR("blkdebug"),
                [...]
    #if defined(CONFIG_REPLICATION)
                QLIT_QSTR("replication"),
    #endif /* defined(CONFIG_REPLICATION) */
                [...]
                {}
            })), },
            {}
        })),

because that would defeat introspection.

I smell a swamp.

I'd rather not complicate the generator to support not including a header I feel we *should* include. #ifdef CONFIG_FOO can occur not just in QAPI-generated code, and neglecting to include the relevant header can cause *nasty* problems not just in QAPI-generated code. Like inconsistent struct definitions in separate compilation units. Been there, debugged that, wasn't fun, do not want to go there again.

#7 lore raw
Quoted 57 lines · Markus Armbruster
Quoted 55 lines · Paolo Bonzini
Quoted 54 lines · Markus Armbruster
Quoted 52 lines · Paolo Bonzini
Quoted 51 lines · Markus Armbruster
Quoted 33 lines · Philippe Mathieu-Daudé

When configured with --without-default-devices and setting MC146818RTC=n, the build fails:

     LINK    x86_64-softmmu/qemu-system-x86_64

/usr/bin/ld: qapi/qapi-commands-misc-target.o: in function `qmp_marshal_rtc_reset_reinjection':
qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection' /usr/bin/ld: qapi/qapi-commands-misc-target.c:46: undefined reference to qmp_rtc_reset_reinjection'
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:206: qemu-system-x86_64] Error 1
make: *** [Makefile:483: x86_64-softmmu/all] Error 2

This patch tries to fix this, but this is incorrect because QAPI scripts only provide TARGET definitions, so with MC146818RTC=y we get:

hw/rtc/mc146818rtc.c:113:6: error: no previous prototype for ‘qmp_rtc_reset_reinjection’ [-Werror=missing-prototypes]
113 | void qmp_rtc_reset_reinjection(Error **errp)
| ^~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make[1]: *** [rules.mak:69: hw/rtc/mc146818rtc.o] Error 1

Any idea? :)

---
  qapi/misc-target.json | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
qapi/misc-target.json +0 -0
index a00fd821eb..8e49c113d1 100644

qapi/misc-target.json line 47

Quoted 8 lines
qapi/misc-target.json +1 -1
@@ -41,7 +41,7 @@
  #
  ##
  { 'command': 'rtc-reset-reinjection',
-  'if': 'defined(TARGET_I386)' }
+  'if': 'defined(TARGET_I386) && defined(CONFIG_MC146818RTC)' }
 
 
  ##

The generated qapi-commands-misc-target.h duly has

     #if defined(TARGET_I386) && defined(CONFIG_MC146818RTC)
     void qmp_rtc_reset_reinjection(Error **errp);
     void qmp_marshal_rtc_reset_reinjection(QDict *args, QObject **ret, Error **errp);
     #endif /* defined(TARGET_I386) && defined(CONFIG_MC146818RTC) */
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

mc146818rtc.c includes it. But since it doesn't include config-devices.h, CONFIG_MC146818RTC remains undefined, and the prototype gets suppressed.

Crude fix: make mc146818rtc.c #include "config-devices.h".

I am happy enough if this 'crude fix' works, I'll test it, thanks!

Quoted 77 lines
Quoted 6 lines
Quoted 5 lines
Quoted 3 lines

Can we modify the code generator to leave out the #if from the header, and only include it in the .c file? An extra prototype is harmless.

Is *everything* we generate into headers just as harmless?

Quoted 8 lines

It should be, since it's just the C version of some JSON. The only problematic thing could be different definitions of the same command for multiple targets, and I think we want to avoid that anyway.

To see it a different way, these are the "C bindings" to QMP, just that the implementation is an in-process call rather than RPC. If the QAPI code generator was also able to generate Python bindings and the like, they would have to be the same for all QEMU binaries, wouldn't they?

Ommitting the kind of #if we've been discussing is relatively harmless:

     #if defined(TARGET_I386)
     void qmp_rtc_reset_reinjection(Error **errp);
     void qmp_marshal_rtc_reset_reinjection(QDict *args, QObject **ret, Error **errp);
     #endif /* defined(TARGET_I386) */

But what about this one, in qapi-types-block-core.h:

     typedef enum BlockdevDriver {
         BLOCKDEV_DRIVER_BLKDEBUG,
         [...]
     #if defined(CONFIG_REPLICATION)
         BLOCKDEV_DRIVER_REPLICATION,
     #endif /* defined(CONFIG_REPLICATION) */
         [...]
         BLOCKDEV_DRIVER__MAX,
     } BlockdevDriver;

If I omit it in the header, I then have to omit it in qapi-types-block-core.c's

     const QEnumLookup BlockdevDriver_lookup = {
         .array = (const char *const[]) {
             [BLOCKDEV_DRIVER_BLKDEBUG] = "blkdebug",
             [...]
     #if defined(CONFIG_REPLICATION)
             [BLOCKDEV_DRIVER_REPLICATION] = "replication",
     #endif /* defined(CONFIG_REPLICATION) */
             [...]
         },
         .size = BLOCKDEV_DRIVER__MAX
     };

and God knows what else. But I must not omit it in qapi-introspect.c's

         QLIT_QDICT(((QLitDictEntry[]) {
             { "meta-type", QLIT_QSTR("enum"), },
             { "name", QLIT_QSTR("245"), },
             { "values", QLIT_QLIST(((QLitObject[]) {
                 QLIT_QSTR("blkdebug"),
                 [...]
     #if defined(CONFIG_REPLICATION)
                 QLIT_QSTR("replication"),
     #endif /* defined(CONFIG_REPLICATION) */
                 [...]
                 {}
             })), },
             {}
         })),

because that would defeat introspection.

I smell a swamp.

I'd rather not complicate the generator to support not including a header I feel we *should* include. #ifdef CONFIG_FOO can occur not just in QAPI-generated code, and neglecting to include the relevant header can cause *nasty* problems not just in QAPI-generated code. Like inconsistent struct definitions in separate compilation units. Been there, debugged that, wasn't fun, do not want to go there again.

#8 lore raw
In reply to Markus Armbruster

Il mar 21 gen 2020, 15:22 Markus Armbruster <[email protected]> ha scritto:

Quoted 8 lines
Quoted 4 lines

To see it a different way, these are the "C bindings" to QMP, just that the implementation is an in-process call rather than RPC. If the QAPI code generator was also able to generate Python bindings and the like, they would have to be the same for all QEMU binaries, wouldn't they?

Ommitting the kind of #if we've been discussing is relatively harmless but what about this one, in qapi-types-block-core.h:

Quoted 10 lines
    typedef enum BlockdevDriver {
        BLOCKDEV_DRIVER_BLKDEBUG,
        [...]
    #if defined(CONFIG_REPLICATION)
        BLOCKDEV_DRIVER_REPLICATION,
    #endif /* defined(CONFIG_REPLICATION) */
        [...]
        BLOCKDEV_DRIVER__MAX,
    } BlockdevDriver;

Well, I don't think this should be conditional at all. Introspection is a tool to detect unsupported features, not working features. KVM will be present in introspection data even if /dev/kvm doesn't exist on your machine or you don't have permission to access it. I would restrict very much #if usage in QAPI to the very minimum necessary.

Paolo

Quoted 44 lines

If I omit it in the header, I then have to omit it in qapi-types-block-core.c's

    const QEnumLookup BlockdevDriver_lookup = {
        .array = (const char *const[]) {
            [BLOCKDEV_DRIVER_BLKDEBUG] = "blkdebug",
            [...]
    #if defined(CONFIG_REPLICATION)
            [BLOCKDEV_DRIVER_REPLICATION] = "replication",
    #endif /* defined(CONFIG_REPLICATION) */
            [...]
        },
        .size = BLOCKDEV_DRIVER__MAX
    };

and God knows what else. But I must not omit it in qapi-introspect.c's

        QLIT_QDICT(((QLitDictEntry[]) {
            { "meta-type", QLIT_QSTR("enum"), },
            { "name", QLIT_QSTR("245"), },
            { "values", QLIT_QLIST(((QLitObject[]) {
                QLIT_QSTR("blkdebug"),
                [...]
    #if defined(CONFIG_REPLICATION)
                QLIT_QSTR("replication"),
    #endif /* defined(CONFIG_REPLICATION) */
                [...]
                {}
            })), },
            {}
        })),

because that would defeat introspection.

I smell a swamp.

I'd rather not complicate the generator to support not including a header I feel we *should* include. #ifdef CONFIG_FOO can occur not just in QAPI-generated code, and neglecting to include the relevant header can cause *nasty* problems not just in QAPI-generated code. Like inconsistent struct definitions in separate compilation units. Been there, debugged that, wasn't fun, do not want to go there again.

#9 lore raw
Quoted 21 lines · Paolo Bonzini

Il mar 21 gen 2020, 15:22 Markus Armbruster <[email protected]> ha scritto:

Quoted 8 lines
Quoted 4 lines

To see it a different way, these are the "C bindings" to QMP, just that the implementation is an in-process call rather than RPC. If the QAPI code generator was also able to generate Python bindings and the like, they would have to be the same for all QEMU binaries, wouldn't they?

Ommitting the kind of #if we've been discussing is relatively harmless but what about this one, in qapi-types-block-core.h:

Quoted 10 lines
    typedef enum BlockdevDriver {
        BLOCKDEV_DRIVER_BLKDEBUG,
        [...]
    #if defined(CONFIG_REPLICATION)
        BLOCKDEV_DRIVER_REPLICATION,
    #endif /* defined(CONFIG_REPLICATION) */
        [...]
        BLOCKDEV_DRIVER__MAX,
    } BlockdevDriver;
Quoted 2 lines

Well, I don't think this should be conditional at all. Introspection is a tool to detect unsupported features, not working features.

Isn't this what it does? To detect "replication" is unsupported, check whether it's absent, and "supported" does not imply "works".

Quoted 3 lines

KVM will be
present in introspection data even if /dev/kvm doesn't exist on your machine or you don't have permission to access it.

Yes.

Likewise, "nfs" is present in introspection data even if no NFS server exists on your network, or you don't have permission to use it.

QAPI/QMP introspection is compile-time static by design. It can't tell you more than "this QEMU build supports X". That's it's mission.

Quoted 2 lines

I would restrict very
much #if usage in QAPI to the very minimum necessary.

I'm not sure I understand how you propose to change introspection.

#10 lore raw
Quoted 23 lines · Markus Armbruster
Quoted 21 lines · Paolo Bonzini

Il mar 21 gen 2020, 15:22 Markus Armbruster <[email protected]> ha scritto:

Quoted 18 lines
Quoted 4 lines

To see it a different way, these are the "C bindings" to QMP, just that the implementation is an in-process call rather than RPC. If the QAPI code generator was also able to generate Python bindings and the like, they would have to be the same for all QEMU binaries, wouldn't they?

Ommitting the kind of #if we've been discussing is relatively harmless but what about this one, in qapi-types-block-core.h:

    typedef enum BlockdevDriver {
        BLOCKDEV_DRIVER_BLKDEBUG,
        [...]
    #if defined(CONFIG_REPLICATION)
        BLOCKDEV_DRIVER_REPLICATION,
    #endif /* defined(CONFIG_REPLICATION) */
        [...]
        BLOCKDEV_DRIVER__MAX,
    } BlockdevDriver;
Quoted 5 lines
Quoted 2 lines

Well, I don't think this should be conditional at all. Introspection is a tool to detect unsupported features, not working features.

Isn't this what it does? To detect "replication" is unsupported, check whether it's absent, and "supported" does not imply "works".

Indeed...

Quoted 8 lines
Quoted 3 lines

KVM will be
present in introspection data even if /dev/kvm doesn't exist on your machine or you don't have permission to access it.

Yes.

QAPI/QMP introspection is compile-time static by design. It can't tell you more than "this QEMU build supports X".

... and I think it would be fine even if it told you less: "this QEMU will not give a parse error if X appears in QMP syntax". For example, QEMU could accept "replication" even if CONFIG_REPLICATION is not defined and therefore using it would always fail. This would allow limiting even more use of conditional compilation.

Paolo

#11 lore raw
Quoted 38 lines · Paolo Bonzini
Quoted 23 lines · Markus Armbruster
Quoted 21 lines · Paolo Bonzini

Il mar 21 gen 2020, 15:22 Markus Armbruster <[email protected]> ha scritto:

Quoted 18 lines
Quoted 4 lines

To see it a different way, these are the "C bindings" to QMP, just that the implementation is an in-process call rather than RPC. If the QAPI code generator was also able to generate Python bindings and the like, they would have to be the same for all QEMU binaries, wouldn't they?

Ommitting the kind of #if we've been discussing is relatively harmless but what about this one, in qapi-types-block-core.h:

    typedef enum BlockdevDriver {
        BLOCKDEV_DRIVER_BLKDEBUG,
        [...]
    #if defined(CONFIG_REPLICATION)
        BLOCKDEV_DRIVER_REPLICATION,
    #endif /* defined(CONFIG_REPLICATION) */
        [...]
        BLOCKDEV_DRIVER__MAX,
    } BlockdevDriver;
Quoted 5 lines
Quoted 2 lines

Well, I don't think this should be conditional at all. Introspection is a tool to detect unsupported features, not working features.

Isn't this what it does? To detect "replication" is unsupported, check whether it's absent, and "supported" does not imply "works".

Indeed...

Quoted 6 lines
Quoted 3 lines

KVM will be
present in introspection data even if /dev/kvm doesn't exist on your machine or you don't have permission to access it.

Yes.

Quoted 8 lines
Quoted 2 lines

QAPI/QMP introspection is compile-time static by design. It can't tell you more than "this QEMU build supports X".

... and I think it would be fine even if it told you less: "this QEMU will not give a parse error if X appears in QMP syntax". For example, QEMU could accept "replication" even if CONFIG_REPLICATION is not defined and therefore using it would always fail. This would allow limiting even more use of conditional compilation.

This is effectively how things worked before we added 'if' to the QAPI schema language.

A feature F may

(1) not exist in this version of QEMU

(2) exist, but configured off for this build of QEMU

(3) be present in this build of QEMU

When the management application sees (1) or (2), it knows that using F cannot possibly work no matter what you do to the host short of using another build of QEMU. The management application can then reject attempts to use F with a useful error message, or make such attempts impossible (think graying out menu entries).

When the management application sees (3), it still needs to be prepared for actual use to fail. Possible failures depend on the feature. Identifying the various kinds of failures can be awkward and/or brittle. Useful error reporting is often hard.

A management application doesn't care for the difference between (1) and (2). We added 'if' to the QAPI schema language in part to make the difference disappear.

Without it, introspection munges together (2) and (3) instead. The management application's information degrades from "the QEMU I have does not provide F" to "something went wrong". Perhaps the management application can figure out what went wrong, perhaps it can't. Perhaps it doesn't need to know.

My point is: we trade away information at the external interface for the benefit of "limiting even more use of conditional compilation". I doubt that's a good trade, not least because I can't quite see how exactly the benefit is, well, beneficial[*].

Anyway, we've had introspection reflect compile time configuration since v3.0.0. I don't think we can break that now.

[*] It saves us including headers we really should be including. Anything else?