1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-11 09:17:52 +03:00

conf: hostdev: Introduce virDomainHostdevSubsysSCSIClear

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@redhat.com>
This commit is contained in:
Erik Skultety 2017-03-09 10:25:47 +01:00
parent 83836d57c1
commit 428e71bd53

View File

@ -2303,6 +2303,17 @@ virDomainHostdevSubsysSCSIiSCSIClear(virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc
iscsisrc->auth = NULL; 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) void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
{ {
if (!def) if (!def)
@ -2336,17 +2347,17 @@ void virDomainHostdevDefClear(virDomainHostdevDefPtr def)
} }
break; break;
case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS: case VIR_DOMAIN_HOSTDEV_MODE_SUBSYS:
if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) { switch ((virDomainHostdevSubsysType) def->source.subsys.type) {
virDomainHostdevSubsysSCSIPtr scsisrc = &def->source.subsys.u.scsi; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
if (scsisrc->protocol == virDomainHostdevSubsysSCSIClear(&def->source.subsys.u.scsi);
VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) { break;
virDomainHostdevSubsysSCSIiSCSIClear(&scsisrc->u.iscsi); case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
} else { VIR_FREE(def->source.subsys.u.scsi_host.wwpn);
VIR_FREE(scsisrc->u.host.adapter); break;
} case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
} else if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) { case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
virDomainHostdevSubsysSCSIVHostPtr hostsrc = &def->source.subsys.u.scsi_host; case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST:
VIR_FREE(hostsrc->wwpn); break;
} }
break; break;
} }