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

Re: [libvirt] [PATCH 07/11] caps: Add virCapabilitiesDomainDataLookup



On 18.04.2015 03:45, Cole Robinson wrote:
> This is a helper function to look up all capabilities data for all
> the OS bits that are relevant to <domain>. This is
> 
> - os type
> - arch
> - domain type
> - emulator
> - machine type
> 
> This will be used to replace several functions in later commits.
> ---
>  src/conf/capabilities.c  | 163 +++++++++++++++++++++++++++++++++++-
>  src/conf/capabilities.h  |  18 ++++
>  src/libvirt_private.syms |   1 +
>  tests/Makefile.am        |   8 +-
>  tests/vircapstest.c      | 209 ++++++++++++++++++++++++++++++++++++++++++++++-
>  5 files changed, 393 insertions(+), 6 deletions(-)
> 
> diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
> index 9f84766..8d3d2a3 100644
> --- a/src/conf/capabilities.c
> +++ b/src/conf/capabilities.c
> @@ -225,7 +225,6 @@ virCapabilitiesDispose(void *object)
>      virCPUDefFree(caps->host.cpu);
>  }
>  
> -
>  /**
>   * virCapabilitiesAddHostFeature:
>   * @caps: capabilities to extend
> @@ -568,6 +567,168 @@ virCapabilitiesHostSecModelAddBaseLabel(virCapsHostSecModelPtr secmodel,
>      return -1;
>  }
>  
> +static bool
> +virCapsDomainDataCompare(virCapsGuestPtr guest,
> +                         virCapsGuestDomainPtr domain,
> +                         virCapsGuestMachinePtr machine,
> +                         int ostype,
> +                         virArch arch,
> +                         int domaintype,
> +                         const char *emulator,
> +                         const char *machinetype)
> +{
> +    char *check_emulator = NULL;

const char please to make it obvious we don't modify it.

> +
> +    if (ostype != -1 && guest->ostype != ostype)
> +        return false;
> +    if ((arch != VIR_ARCH_NONE) && (guest->arch.id != arch))
> +        return false;
> +
> +    if (domaintype != -1 && (!domain || domain->type != domaintype))
> +        return false;
> +
> +    if (emulator) {
> +        if (domain)
> +            check_emulator = domain->info.emulator;
> +        if (!check_emulator)
> +            check_emulator = guest->arch.defaultInfo.emulator;
> +        if (!check_emulator || STRNEQ(check_emulator, emulator))

or STRNEQ_NULLABLE()

> +            return false;
> +    }
> +
> +    if (machinetype) {
> +        if (!machine)
> +            return false;
> +        if (STRNEQ(machine->name, machinetype) &&
> +            (!machine->canonical || STRNEQ(machine->canonical, machinetype)))

and here as well.

> +            return false;
> +    }
> +
> +    return true;
> +}
> +

>  /**
>   * virCapabilitiesSupportsGuestArch:
>   * @caps: capabilities to query
> diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
> index 7ee834f..87acf39 100644
> --- a/src/conf/capabilities.h
> +++ b/src/conf/capabilities.h
> @@ -192,6 +192,16 @@ struct _virCaps {
>      virCapsGuestPtr *guests;
>  };
>  
> +typedef struct _virCapsDomainData virCapsDomainData;
> +typedef virCapsDomainData *virCapsDomainDataPtr;
> +struct _virCapsDomainData {
> +    int ostype;
> +    int arch;
> +    int domaintype;
> +    char *emulator;
> +    char *machinetype;

const char to both please. You are copying over the pointer to live data
so we must discourage people to free any of the pair. I know that
'const' is not a sufficient protection, but it's at least something.

> +};
> +
>  

Michal


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