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

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

 



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@xxxxxxxxxx>
> ---
>  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.

Attachment: signature.asc
Description: PGP signature

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux