[libvirt] [RFC PATCH 05/12] qemu: domain: Add helper to lookup disk by node name

Eric Blake eblake at redhat.com
Thu Feb 23 22:56:48 UTC 2017


On 02/23/2017 01:21 PM, Peter Krempa wrote:
> Looks up a disk and it's corresponding backing chain element by node
> name.
> ---
>  src/qemu/qemu_domain.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_domain.h |  6 ++++++
>  2 files changed, 50 insertions(+)
> 

> +virDomainDiskDefPtr
> +qemuDomainDiskLookupByNodename(virDomainDefPtr def,
> +                               const char *nodename,
> +                               virStorageSourcePtr *src,
> +                               unsigned int *idx)
> +{
> +    size_t i;
> +    unsigned int srcindex;
> +    virStorageSourcePtr tmp = NULL;

Sometimes, I find it easier to do:

if (!idx)
    idx = &srcindex;

so that later on...

> +
> +    if (src)
> +        *src = NULL;
> +
> +    if (idx)
> +        *idx = 0;
> +
> +    for (i = 0; i < def->ndisks; i++) {
> +        if ((tmp = virStorageSourceFindByNodeName(def->disks[i]->src,
> +                                                  nodename, &srcindex))) {

...I can just pass 'idx' instead of '&srcindex' here...

> +            if (src)
> +                *src = tmp;
> +
> +            if (idx)
> +                *idx = srcindex;

...and completely skip this conditional.  But not a show-stopper.

ACK

-- 
Eric Blake   eblake 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: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170223/94fb5e43/attachment-0001.sig>


More information about the libvir-list mailing list