[libvirt] [PATCH 3/9] storage: Invert logic for matchISCSISource

Peter Krempa pkrempa at redhat.com
Mon Apr 13 10:12:32 UTC 2015


On Thu, Apr 02, 2015 at 13:39:40 -0400, John Ferlan wrote:
> Invert the logic for better readability/flow and futher separation
> 
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
>  src/conf/storage_conf.c | 25 +++++++++++++------------
>  1 file changed, 13 insertions(+), 12 deletions(-)
> 
> diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
> index fa7a7f9..e4cb54b 100644
> --- a/src/conf/storage_conf.c
> +++ b/src/conf/storage_conf.c
> @@ -2297,18 +2297,19 @@ matchISCSISource(virStoragePoolObjPtr matchpool,
>  {
>      virStoragePoolSourcePtr poolsrc = &matchpool->def->source;
>      virStoragePoolSourcePtr defsrc = &def->source;
> -    if (poolsrc->nhost == 1 && defsrc->nhost == 1) {
> -        if (STREQ(poolsrc->hosts[0].name, defsrc->hosts[0].name)) {
> -            if (poolsrc->initiator.iqn && defsrc->initiator.iqn) {
> -                if (STREQ(poolsrc->initiator.iqn, defsrc->initiator.iqn))
> -                    return true;
> -                else
> -                    return false;
> -            }
> -            return true;
> -        }
> -    }
> -    return false;
> +
> +
> +    /* NB: nhost cannot be > 1 */

Remove this comment ...

> +    if (poolsrc->nhost == 0 || defsrc->nhost == 0)

change the conditions to != 1 so that the comment is redundant.

> +        return false;
> +
> +    if (STRNEQ(poolsrc->hosts[0].name, defsrc->hosts[0].name))
> +        return false;
> +
> +    if (STRNEQ_NULLABLE(poolsrc->initiator.iqn, defsrc->initiator.iqn))
> +        return false;
> +
> +    return true;
>  }

... and squash this together with patches 1 and 2. Doing the refactor
right away is probably better a in this case.

Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20150413/f15a101c/attachment-0001.sig>


More information about the libvir-list mailing list