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

Re: [libvirt] [PATCH 2/4] Factor out def assignment to existing domain from virDomainAssignDef



On 05/20/2010 08:54 AM, Jiri Denemark wrote:
> We need to be able to assign new def to an existing virDomainObj which
> is already locked. This patch factors out the relevant code from
> virDomainAssignDef into virDomainObjAssignDef.
> ---
>  src/conf/domain_conf.c   |   36 +++++++++++++++++++++---------------
>  src/conf/domain_conf.h   |    3 +++
>  src/libvirt_private.syms |    1 +
>  3 files changed, 25 insertions(+), 15 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 20c9c51..c77ee59 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -808,6 +808,26 @@ static virDomainObjPtr virDomainObjNew(virCapsPtr caps)
>      return domain;
>  }
>  
> +void virDomainObjAssignDef(virDomainObjPtr domain,
> +                           const virDomainDefPtr def,
> +                           bool live)
> +{
> +    if (!virDomainObjIsActive(domain)) {
> +        if (live) {
> +            /* save current configuration to be restored on domain shutdown */
> +            if (!domain->newDef)
> +                domain->newDef = domain->def;
> +            domain->def = def;
> +        } else {
> +            virDomainDefFree(domain->def);
> +            domain->def = def;
> +        }
> +    } else {
> +        virDomainDefFree(domain->newDef);
> +        domain->newDef = def;
> +    }
> +}
> +
>  virDomainObjPtr virDomainAssignDef(virCapsPtr caps,
>                                     virDomainObjListPtr doms,
>                                     const virDomainDefPtr def,
> @@ -817,21 +837,7 @@ virDomainObjPtr virDomainAssignDef(virCapsPtr caps,
>      char uuidstr[VIR_UUID_STRING_BUFLEN];
>  
>      if ((domain = virDomainFindByUUID(doms, def->uuid))) {
> -        if (!virDomainObjIsActive(domain)) {
> -            if (live) {
> -                /* save current configuration to be restored on domain shutdown */
> -                if (!domain->newDef)
> -                    domain->newDef = domain->def;
> -                domain->def = def;
> -            } else {
> -                virDomainDefFree(domain->def);
> -                domain->def = def;
> -            }
> -        } else {
> -            virDomainDefFree(domain->newDef);
> -            domain->newDef = def;
> -        }
> -
> +        virDomainObjAssignDef(domain, def, live);
>          return domain;
>      }
>  
> diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
> index a7206d3..9f87fc5 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -954,6 +954,9 @@ virDomainObjPtr virDomainAssignDef(virCapsPtr caps,
>                                     virDomainObjListPtr doms,
>                                     const virDomainDefPtr def,
>                                     bool live);
> +void virDomainObjAssignDef(virDomainObjPtr domain,
> +                           const virDomainDefPtr def,
> +                           bool live);
>  void virDomainRemoveInactive(virDomainObjListPtr doms,
>                               virDomainObjPtr dom);
>  
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index bdeab0f..1594a08 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -215,6 +215,7 @@ virDomainSnapshotObjUnref;
>  virDomainSnapshotDefParseString;
>  virDomainSnapshotDefFormat;
>  virDomainSnapshotAssignDef;
> +virDomainObjAssignDef;
>  
>  
>  # domain_event.h

ACK

- Cole


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