[libvirt] [PATCH 5/6] libvirt: Ensure modern APIs are implemented

Peter Krempa pkrempa at redhat.com
Tue Jul 9 09:02:03 UTC 2019


On Mon, Jul 08, 2019 at 22:37:02 -0500, Eric Blake wrote:
> As shown in recent patches, several drivers provided only an older
> counterpart of an API, making it harder to uniformly use the newer
> preferred API form. We can prevent future instances of this by failing
> the driver at initialization time if a modern API is forgotten when an
> older API is present.  For now, the list includes any interface with a
> Flags counterpart, except virDomainBlockStatsFlags which is a bit more
> complex than virDomainBlockStats.
> 
> Signed-off-by: Eric Blake <eblake at redhat.com>
> ---
>  src/libvirt.c | 42 ++++++++++++++++++++++++++++++++++++++----
>  1 file changed, 38 insertions(+), 4 deletions(-)
> 
> diff --git a/src/libvirt.c b/src/libvirt.c
> index 7e665b6cba..a12a72a31b 100644
> --- a/src/libvirt.c
> +++ b/src/libvirt.c
> @@ -567,19 +567,53 @@ int
>  virRegisterConnectDriver(virConnectDriverPtr driver,
>                           bool setSharedDrivers)
>  {
> -    VIR_DEBUG("driver=%p name=%s", driver,
> -              driver ? NULLSTR(driver->hypervisorDriver->name) : "(null)");
> +    const char *driver_name;
> +
> +    driver_name = driver ? NULLSTR(driver->hypervisorDriver->name) : "(null)";
> +    VIR_DEBUG("driver=%p name=%s", driver, driver_name);
> 
>      virCheckNonNullArgReturn(driver, -1);
>      if (virConnectDriverTabCount >= MAX_DRIVERS) {
>          virReportError(VIR_ERR_INTERNAL_ERROR,
>                         _("Too many drivers, cannot register %s"),
> -                       driver->hypervisorDriver->name);
> +                       driver_name);
>          return -1;
>      }
> 
> +    /* Check for drivers failing to provide a modern counterpart to an
> +     * older API */
> +#define REQUIRE_API(old, new) \
> +    do { \
> +        if (driver->hypervisorDriver->old && \
> +            !driver->hypervisorDriver->new) { \
> +            fprintf(stderr, " ***FIXME!: driver %s is broken on %s\n", \
> +                    driver ? NULLSTR(driver->hypervisorDriver->name) : "(null)", #new); \

fprintf in a library function is really wrong.

Also I don't think this really requires a runtime check as the APIs
aren't really going to just disappear.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20190709/8d6e3ab3/attachment-0001.sig>


More information about the libvir-list mailing list