• D
    qemu_command: tidy up qemuBuildHostdevCommandLine loop · aed9bcd1
    Daniel Henrique Barboza 提交于
    The current 'for' loop with 5 consecutive 'ifs' inside
    qemuBuildHostdevCommandLine can be a bit smarter:
    
    - all 5 'ifs' fails if hostdev->mode is not equal to
    VIR_DOMAIN_HOSTDEV_MODE_SUBSYS. This check can be moved to the
    start of the loop, failing to the next element immediately
    in case it fails;
    
    - all 5 'ifs' checks for a specific subsys->type to build the proper
    command line argument (virHostdevIsSCSIDevice and virHostdevIsMdevDevice
    do that but within a helper). Problem is that the code will keep
    checking for matches even if one was already found, and there is
    no way a hostdev will fit more than one 'if' (i.e. a hostdev can't
    have 2+ different types). This means that a SUBSYS_TYPE_USB will
    create its command line argument in the first 'if', then all other
    conditionals will surely fail but will end up being checked anyway.
    
    All of this can be avoided by moving the hostdev->mode comparing
    to the start of the loop and using a switch statement with
    subsys->type to execute the proper code for a given hostdev
    type.
    Suggested-by: NJán Tomko <jtomko@redhat.com>
    Signed-off-by: NDaniel Henrique Barboza <danielhb413@gmail.com>
    Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
    Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
    aed9bcd1
qemu_command.c 342.9 KB