On 01/05/2015 11:00 PM, Peter Krempa wrote:
Subject: ... How about
conf: Introduce function to compare RNG devices.
On 01/03/15 06:06, Luyao Huang wrote:
> virDomainRNGEquals is a func which check if two rng device
> are the same.
>
> Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
> ---
> src/conf/domain_conf.c | 34 ++++++++++++++++++++++++++++++++++
> src/conf/domain_conf.h | 3 +++
> 2 files changed, 37 insertions(+)
>
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index aafc05e..91c114e 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -11922,6 +11922,40 @@ virDomainChrRemove(virDomainDefPtr vmdef,
> return ret;
> }
>
> +bool
> +virDomainRNGEquals(virDomainRNGDefPtr src,
> + virDomainRNGDefPtr tgt)
> +{
> + if (!src || !tgt)
> + return src == tgt;
> +
> + if (src->model != tgt->model)
> + return false;
> +
> + if (src->rate != tgt->rate || src->period != tgt->period)
> + return false;
> +
> + switch ((virDomainRNGModel) src->model) {
> + case VIR_DOMAIN_RNG_MODEL_VIRTIO:
> + switch ((virDomainRNGBackend) src->backend) {
> + case VIR_DOMAIN_RNG_BACKEND_RANDOM:
> + return STREQ_NULLABLE(src->source.file, tgt->source.file);
> + break;
> + case VIR_DOMAIN_RNG_BACKEND_EGD:
> + return virDomainChrSourceDefIsEqual((virDomainChrSourceDef *)
src->source.chardev,
> + (virDomainChrSourceDef *)
tgt->source.chardev);
No need for typecast here; both src->source.chardev and tgt ... are
already in the required type.
Got it, i will remove the typecast in next version.
> + break;
> + case VIR_DOMAIN_RNG_BACKEND_LAST:
> + break;
> + }
> + break;
> +
> + case VIR_DOMAIN_RNG_MODEL_LAST:
> + break;
> + }
> + return false;
> +}
> +
> char *
> virDomainDefGetDefaultEmulator(virDomainDefPtr def,
> virCapsPtr caps)
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index 57297cd..c197095 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -2597,6 +2597,9 @@ virDomainChrInsert(virDomainDefPtr vmdef,
> virDomainChrDefPtr
> virDomainChrRemove(virDomainDefPtr vmdef,
> virDomainChrDefPtr chr);
> +bool
> +virDomainRNGEquals(virDomainRNGDefPtr src,
> + virDomainRNGDefPtr tgt);
As in the case below, please add the type to the same line as the
declaration.
OKay
Thanks for your review
>
> int virDomainSaveXML(const char *configDir,
> virDomainDefPtr def,
>
Peter