From 12b8290fa59c899e07c71edf3c987e8612d8eec9 Mon Sep 17 00:00:00 2001 From: Nehal J Wani Date: Tue, 25 Mar 2014 13:53:14 +0530 Subject: [PATCH] Use virFileFindResource to locate parthelper for storage backend Instead of hardcoding LIBEXECDIR as the location of the libvirt_parthelper binary, use virFileFindResource to optionally find it in the current build directory. Signed-off-by: Daniel P. Berrange --- src/storage/storage_backend_disk.c | 31 +++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c index 9cebccae2b..71634c6a1d 100644 --- a/src/storage/storage_backend_disk.c +++ b/src/storage/storage_backend_disk.c @@ -40,8 +40,6 @@ VIR_LOG_INIT("storage.storage_backend_disk"); -#define PARTHELPER LIBEXECDIR "/libvirt_parthelper" - #define SECTOR_SIZE 512 static int @@ -262,15 +260,24 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool, * - normal metadata 100027630080 100030242304 2612736 * */ - virCommandPtr cmd = virCommandNewArgList(PARTHELPER, - pool->def->source.devices[0].path, - NULL); + + char *parthelper_path; + virCommandPtr cmd; struct virStorageBackendDiskPoolVolData cbdata = { .pool = pool, .vol = vol, }; int ret; + if (!(parthelper_path = virFileFindResource("libvirt_parthelper", + "src", + LIBEXECDIR))) + return -1; + + cmd = virCommandNewArgList(parthelper_path, + pool->def->source.devices[0].path, + NULL); + pool->def->allocation = pool->def->capacity = pool->def->available = 0; ret = virCommandRunNul(cmd, @@ -278,6 +285,7 @@ virStorageBackendDiskReadPartitions(virStoragePoolObjPtr pool, virStorageBackendDiskMakeVol, &cbdata); virCommandFree(cmd); + VIR_FREE(parthelper_path); return ret; } @@ -302,17 +310,26 @@ virStorageBackendDiskMakePoolGeometry(size_t ntok ATTRIBUTE_UNUSED, static int virStorageBackendDiskReadGeometry(virStoragePoolObjPtr pool) { - virCommandPtr cmd = virCommandNewArgList(PARTHELPER, + char *parthelper_path; + virCommandPtr cmd; + int ret; + + if (!(parthelper_path = virFileFindResource("libvirt_parthelper", + "src", + LIBEXECDIR))) + return -1; + + cmd = virCommandNewArgList(parthelper_path, pool->def->source.devices[0].path, "-g", NULL); - int ret; ret = virCommandRunNul(cmd, 3, virStorageBackendDiskMakePoolGeometry, pool); virCommandFree(cmd); + VIR_FREE(parthelper_path); return ret; } -- GitLab