Re: [PATCH v4 02/14] conf: hostdev: Introduce virDomainHostdevSubsysSCSIClear

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

 



On 03/22/2017 11:27 AM, Erik Skultety wrote:
> Just a tiny wrapper over the SCSI def clearing logic to drop some
> if-else branches from a switch, mainly because extending the switch in
> the future would render the current code with branching less readable.
> 
> Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx>
> ---
>  src/conf/domain_conf.c | 33 ++++++++++++++++++++++-----------
>  1 file changed, 22 insertions(+), 11 deletions(-)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 17909820be..568bf6722e 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -2303,6 +2303,17 @@ virDomainHostdevSubsysSCSIiSCSIClear(virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc
>      iscsisrc->auth = NULL;
>  }
>  
> +
> +static void
> +virDomainHostdevSubsysSCSIClear(virDomainHostdevSubsysSCSIPtr scsisrc)
> +{
> +    if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI)
> +        virDomainHostdevSubsysSCSIiSCSIClear(&scsisrc->u.iscsi);
> +    else
> +        VIR_FREE(scsisrc->u.host.adapter);
> +}
> +
> +
>  void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
>  {
>      if (!def)
> @@ -2336,17 +2347,17 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
>          }
>          break;
>      case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
> -        if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
> -            virDomainHostdevSubsysSCSIPtr scsisrc = &def->source.subsys.u.scsi;
> -            if (scsisrc->protocol ==
> -                VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
> -                virDomainHostdevSubsysSCSIiSCSIClear(&scsisrc->u.iscsi);
> -            } else {
> -                VIR_FREE(scsisrc->u.host.adapter);
> -            }
> -        } else if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) {
> -            virDomainHostdevSubsysSCSIVHostPtr hostsrc = &def->source.subsys.u.scsi_host;
> -            VIR_FREE(hostsrc->wwpn);
> +        switch ((virDomainHostdevSubsysType) def->source.subsys.type) {
> +        case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
> +            virDomainHostdevSubsysSCSIClear(&def->source.subsys.u.scsi);
> +            break;
> +        case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
> +            VIR_FREE(def->source.subsys.u.scsi_host.wwpn);
> +            break;
> +        case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
> +        case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
> +        case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
> +            break;
>          }
>          break;
>      }
> 

ACK.

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux