[libvirt] [PATCH 10/17] conf: hostdev utility functions

Eric Blake eblake at redhat.com
Sat Mar 3 05:01:21 UTC 2012


On 02/28/2012 01:14 PM, Laine Stump wrote:
> Three new functions useful in other files:
> 
> virDomainHostdevInsert:
> 
> Add a new hostdev at the end of the array. This would more sensibly be
> called virDomainHostdevAppend, but the existing functions for other
> types of devices are called Insert.
> 
> virDomainHostdevRemove:
> 
> Eliminates one entry from the hostdevs array, but doesn't free it;
> patterned after the code at the end of the two
> qemuDomainDetachHostXXXDevice functions (and also other pre-existing
> virDomainXXXRemove functions for other device types).
> 
> virDomainHostdevFind:
> 
> This function is patterned from the search loops at the top of
> qemuDomainDetachHostPciDevice and qemuDomainDetachHostUsbDevice, and
> will be used to re-factor those (and other detach-related) functions.
> ---
> New patch for V2.
> 
>  src/conf/domain_conf.c   |   94 ++++++++++++++++++++++++++++++++++++++++++++++
>  src/conf/domain_conf.h   |    5 ++
>  src/libvirt_private.syms |    3 +
>  3 files changed, 102 insertions(+), 0 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 93fd8d7..94ee634 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -6769,6 +6769,100 @@ virDomainChrTargetTypeToString(int deviceType,
>  }
>  
>  int
> +virDomainHostdevInsert(virDomainDefPtr def, virDomainHostdevDefPtr hostdev)
> +{
> +    if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs + 1) < 0)
> +        return -1;
> +    def->hostdevs[def->nhostdevs++]  = hostdev;

Is the double space intended?

> +    return 0;
> +}
> +
> +void
> +virDomainHostdevRemove(virDomainDefPtr def, size_t i)
> +{
> +    if (def->nhostdevs > 1) {
> +        memmove(def->hostdevs + i,
> +                def->hostdevs + i + 1,
> +                sizeof(*def->hostdevs) *
> +                (def->nhostdevs - (i + 1)));
> +        def->nhostdevs--;
> +        if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs) < 0) {

I know this is copy and paste, but we could clean this pattern up
throughout the file (later) to use VIR_SHRINK_N.

ACK.

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120302/e46f8992/attachment-0001.sig>


More information about the libvir-list mailing list