On 17.03.2014 16:19, Francesco Romani wrote:
this patch decouples the binary and the capabilities detection from the guest initialization. The purpose is to make testing easier. --- src/qemu/qemu_capabilities.c | 45 +++++++++++++++++++++++++++++--------------- src/qemu/qemu_capabilities.h | 7 +++++++ 2 files changed, 37 insertions(+), 15 deletions(-)
I had to rebase this, but that's not your fault.
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 061ddae..6faef02 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -689,18 +689,12 @@ virQEMUCapsInitGuest(virCapsPtr caps, virArch hostarch, virArch guestarch) { - virCapsGuestPtr guest; size_t i; - bool haskvm = false; - bool haskqemu = false; char *kvmbin = NULL; char *binary = NULL; - virCapsGuestMachinePtr *machines = NULL; - size_t nmachines = 0; virQEMUCapsPtr qemubinCaps = NULL; virQEMUCapsPtr kvmbinCaps = NULL; int ret = -1; - bool hasdisksnapshot = false; /* Check for existence of base emulator, or alternate base * which can be used with magic cpu choice @@ -748,6 +742,35 @@ virQEMUCapsInitGuest(virCapsPtr caps, } } + ret = virQEMUCapsInitGuestFromBinary(caps, + binary, qemubinCaps, + kvmbin, kvmbinCaps, + guestarch); + + VIR_FREE(binary); + VIR_FREE(kvmbin); + virObjectUnref(qemubinCaps); + virObjectUnref(kvmbinCaps); + + return ret; +} + +int +virQEMUCapsInitGuestFromBinary(virCapsPtr caps, + const char *binary, + virQEMUCapsPtr qemubinCaps, + const char *kvmbin, + virQEMUCapsPtr kvmbinCaps, + virArch guestarch) +{ + virCapsGuestPtr guest; + bool haskvm = false; + bool haskqemu = false; + virCapsGuestMachinePtr *machines = NULL; + size_t nmachines = 0; + int ret = -1; + bool hasdisksnapshot = false; + if (!binary) return 0; @@ -845,18 +868,10 @@ virQEMUCapsInitGuest(virCapsPtr caps, ret = 0; -cleanup: - VIR_FREE(binary); - VIR_FREE(kvmbin); - virObjectUnref(qemubinCaps); - virObjectUnref(kvmbinCaps); - - return ret; - error: virCapabilitiesFreeMachines(machines, nmachines); - goto cleanup; + return ret; }
We tend to use cleanup in this pattern. Error path should be used only for error not for successful return path too. Such approach, however, requires the substitution of 'error' with 'cleanup' in the rest of the function. I'll take care of that.
Michal -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list