This patch splits out the function from virStorageBackendCreateQemuImg. New function virStorageBackendFindQemuImgTool has a char** argument so it can be used without virConnect and virStoragePool. --- src/storage/storage_backend.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c index 2e14af9..efb5ce5 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -1129,6 +1129,25 @@ virStorageBackendCreateQemuImgCmdFromVol(virConnectPtr conn, return cmd; } +static +int virStorageBackendFindQemuImgTool(char** create_tool) +{ + if (!create_tool) + return -1; + + /* KVM is usually ahead of qemu on features, so try that first */ + *create_tool = virFindFileInPath("kvm-img"); + if (!*create_tool) + *create_tool = virFindFileInPath("qemu-img"); + + if (!*create_tool) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("unable to find kvm-img or qemu-img")); + return -1; + } + return 0; +} + static int virStorageBackendCreateQemuImg(virConnectPtr conn, virStoragePoolObjPtr pool, @@ -1143,16 +1162,8 @@ virStorageBackendCreateQemuImg(virConnectPtr conn, virCheckFlags(VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA, -1); - /* KVM is usually ahead of qemu on features, so try that first */ - create_tool = virFindFileInPath("kvm-img"); - if (!create_tool) - create_tool = virFindFileInPath("qemu-img"); - - if (!create_tool) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("unable to find kvm-img or qemu-img")); + if (virStorageBackendFindQemuImgTool(&create_tool) < 0) return -1; - } imgformat = virStorageBackendQEMUImgBackingFormat(create_tool); if (imgformat < 0) -- 1.8.3.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list