• J
    Libvirt: virTypedParamsValidate: Fix detection of multiple parameters · 791c90cb
    Jason J. Herne 提交于
    virTypedParamsValidate currently uses an index based check to find
    duplicate parameters. This check does not work. Consider the following
    simple example:
    
    We have only 2 keys
    A  (multiples allowed)
    B  (multiples NOT allowed)
    
    We are given the following list of parameters to check:
    A
    A
    B
    
    If you work through the validation loop you will see that our last iteration
    through the loop has i=2 and j=1. In this case, i > j and keys[j].value.i will
    indicate that multiples are not allowed. Both conditionals are satisfied so
    an incorrect error will be given: "parameter '%s' occurs multiple times"
    
    This patch replaces the index based check with code that remembers
    the name of the last parameter seen and only triggers the error case if
    the current parameter name equals the last one. This works because the
    list is sorted and duplicate parameters will be grouped together.
    
    In reality, we hit this bug while using selective block migration to migrate
    a guest with 5 disks. 5 was apparently just the right number to push i > j
    and hit this bug.
    
    virsh migrate --live guestname --copy-storage-all
                  --migrate-disks vdb,vdc,vdd,vde,vdf
                  qemu+ssh://dsthost/systemSigned-off-by: NJason J. Herne <jjherne@linux.vnet.ibm.com>
    Reviewed-by: NEric Farman <farman@linux.vnet.ibm.com>
    (cherry picked from commit 0e570a6a)
    791c90cb
virtypedparamtest.c 9.2 KB