[libvirt] [PATCH v1 15/19] conf: Create vhost-scsi hostdev protocol in dumpxml

Michal Privoznik mprivozn at redhat.com
Tue Aug 9 12:13:41 UTC 2016


On 25.07.2016 22:48, Eric Farman wrote:
> When issuing virsh dumpxml and parsing a hostdev element,
> the vhost-scsi protocol needs to be handled separately from
> the existing options, to create valid XML.
> 
> Signed-off-by: Eric Farman <farman at linux.vnet.ibm.com>
> Reviewed-by: Bjoern Walk <bwalk at linux.vnet.ibm.com>
> Reviewed-by: Boris Fiuczynski <fiuczy at linux.vnet.ibm.com>
> ---
>  src/conf/domain_conf.c | 20 ++++++++++++++++----
>  1 file changed, 16 insertions(+), 4 deletions(-)

Yet again, this should go into very same patch that changes the parser.

> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index b67d0ea..79087b2 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -20441,6 +20441,7 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
>      virDomainHostdevSubsysSCSIPtr scsisrc = &def->source.subsys.u.scsi;
>      virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
>      virDomainHostdevSubsysSCSIiSCSIPtr iscsisrc = &scsisrc->u.iscsi;
> +    virDomainHostdevSubsysSCSIVhostPtr vhostsrc = &scsisrc->u.vhost;
>  
>      if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
>          pcisrc->backend != VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT) {
> @@ -20470,13 +20471,22 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
>              virBufferAddLit(buf, " missing='yes'");
>      }
>  
> -    if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
> -        scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI) {
> +    if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
>          const char *protocol =
>              virDomainHostdevSubsysSCSIProtocolTypeToString(scsisrc->protocol);
>  
> -        virBufferAsprintf(buf, " protocol='%s' name='%s'",
> -                          protocol, iscsisrc->path);
> +        switch (scsisrc->protocol) {

The idea of switch() is that compiler will check for all the missing
enum members. For some reasons, we store @protocol as int, therefore you
should type cast this to virDomainHostdevSCSIProtocolType and drop the
'default' label. Next time somebody is introducing new SCSI protocol,
they will thank you because compiler will identify majority of the
places they need too look at.

> +        case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI:
> +            virBufferAsprintf(buf, " protocol='%s' name='%s'",
> +                              protocol, iscsisrc->path);
> +            break;
> +        case VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_VHOST:
> +            virBufferAsprintf(buf, " protocol='%s' wwpn='%s'",
> +                              protocol, vhostsrc->wwpn);
> +            break;
> +        default:
> +            break;
> +        }
>      }
>  
>      virBufferAddLit(buf, ">\n");
> @@ -20522,6 +20532,8 @@ virDomainHostdevDefFormatSubsys(virBufferPtr buf,
>              virBufferEscapeString(buf, " name='%s'", iscsisrc->hosts[0].name);
>              virBufferEscapeString(buf, " port='%s'", iscsisrc->hosts[0].port);
>              virBufferAddLit(buf, "/>\n");
> +        } else if (scsisrc->protocol == VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_VHOST) {
> +            /* Nothing to do here */
>          } else {
>              virBufferAsprintf(buf, "<adapter name='%s'/>\n",
>                                scsihostsrc->adapter);
> 


Michal




More information about the libvir-list mailing list