[libvirt] [PATCH v2 02/10] qemu: Introduce qemuIsSharedHostdev

Peter Krempa pkrempa at redhat.com
Tue Jul 7 12:28:28 UTC 2015


On Mon, Jul 06, 2015 at 13:08:30 -0400, John Ferlan wrote:
> Add a single boolean function to handle whether the hostdev is shared or not.
> 
> Use the new function for the qemu{Add|Remove}SharedHostdev calls as well
> as qemuSetUnprivSGIO. NB: This second usage fixes a possible bug where

s/second/third/

> if this feature is enabled at some time in the future and the shareable flag
> wasn't set, the sgio would have been erroneously set.
> 
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
>  src/qemu/qemu_conf.c | 30 ++++++++++++++++++------------
>  1 file changed, 18 insertions(+), 12 deletions(-)
> 
> diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
> index d521886..48fb74a 100644
> --- a/src/qemu/qemu_conf.c
> +++ b/src/qemu/qemu_conf.c
> @@ -1201,6 +1201,19 @@ qemuAddSharedDisk(virQEMUDriverPtr driver,
>  }
>  
>  
> +static bool
> +qemuIsSharedHostdev(virDomainHostdevDefPtr hostdev)
> +{
> +    if (hostdev->shareable &&
> +        (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
> +         hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
> +         hostdev->source.subsys.u.scsi.protocol !=
> +         VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI))
> +        return true;
> +    return false;

Since the above condition is:
 if (condition)
   return true;
 else
   return false;

You might as well as return the result of the boolean expression
directly since it's equivalent.

> +}
> +
> +
>  static char *
>  qemuGetSharedHostdevKey(virDomainHostdevDefPtr hostdev)
>  {
> @@ -1238,10 +1251,7 @@ qemuAddSharedHostdev(virQEMUDriverPtr driver,
>      char *key = NULL;
>      int ret = -1;
>  
> -    if (!hostdev->shareable ||
> -        !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
> -          hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
> -          hostdev->source.subsys.u.scsi.protocol != VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI))
> +    if (!qemuIsSharedHostdev(hostdev))
>          return 0;
>  
>      if (!(key = qemuGetSharedHostdevKey(hostdev)))
> @@ -1342,10 +1352,7 @@ qemuRemoveSharedHostdev(virQEMUDriverPtr driver,
>      char *key = NULL;
>      int ret;
>  
> -    if (!hostdev->shareable ||
> -        !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
> -          hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
> -          hostdev->source.subsys.u.scsi.protocol != VIR_DOMAIN_HOSTDEV_SCSI_PROTOCOL_TYPE_ISCSI))
> +    if (!qemuIsSharedHostdev(hostdev))
>          return 0;
>  
>      if (!(key = qemuGetSharedHostdevKey(hostdev)))
> @@ -1407,11 +1414,10 @@ qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
>      } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
>          hostdev = dev->data.hostdev;
>  
> +        if (!qemuIsSharedHostdev(hostdev))
> +            return 0;
>  
> -        if (hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
> -            hostdev->source.subsys.type ==
> -            VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI &&
> -            hostdev->source.subsys.u.scsi.sgio) {
> +        if (hostdev->source.subsys.u.scsi.sgio) {
>              virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
>                             _("'sgio' is not supported for SCSI "
>                               "generic device yet "));

ACK,

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/20150707/8eb803e1/attachment-0001.sig>


More information about the libvir-list mailing list