[PATCH] Fix _diskpool_is_member() to return correct pool

# HG changeset patch # User Kaitlin Rupert <karupert@us.ibm.com> # Date 1228416687 28800 # Node ID ef2cf614ff223321ea10fe8d17909a55035affee # Parent ef03ffafe2dd00f3e2a78a2bce1cb9b4836b5d2b Fix _diskpool_is_member() to return correct pool. Verifying the volume exists isn't enough to prove the disk_pool struct is the proper pool. We need to verify the volume is in the pool of a given pool struct. Signed-off-by: Kaitlin Rupert <karupert@us.ibm.com> diff -r ef03ffafe2dd -r ef2cf614ff22 src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Thu Dec 04 09:41:51 2008 -0700 +++ b/src/Virt_DevicePool.c Thu Dec 04 10:51:27 2008 -0800 @@ -140,21 +140,26 @@ static bool _diskpool_is_member(virConnectPtr conn, const struct disk_pool *pool, - const char *file) + const char *file, + virStorageVolPtr vol) { - virStorageVolPtr vol = NULL; bool result = false; + virStoragePoolPtr pool_vol = NULL; + const char *pool_name = NULL; - vol = virStorageVolLookupByPath(conn, file); - if (vol != NULL) - result = true; - + pool_vol = virStoragePoolLookupByVolume(vol); + if (vol != NULL) { + pool_name = virStoragePoolGetName(pool_vol); + if ((pool_name != NULL) && (STREQC(pool_name, pool->tag))) + result = true; + } + CU_DEBUG("Image %s in pool %s: %s", file, pool->tag, result ? "YES": "NO"); - virStorageVolFree(vol); + virStoragePoolFree(pool_vol); return result; } @@ -270,13 +275,18 @@ int count; int i; char *pool = NULL; + virStorageVolPtr vol = NULL; count = get_diskpool_config(conn, &pools); if (count == 0) return NULL; + vol = virStorageVolLookupByPath(conn, file); + if (vol == NULL) + goto out; + for (i = 0; i < count; i++) { - if (_diskpool_is_member(conn, &pools[i], file)) { + if (_diskpool_is_member(conn, &pools[i], file, vol)) { int ret; ret = asprintf(&pool, "DiskPool/%s", pools[i].tag); @@ -286,7 +296,9 @@ } } + out: free_diskpool(pools, count); + virStorageVolFree(vol); return pool; }

KR> Verifying the volume exists isn't enough to prove the disk_pool KR> struct is the proper pool. We need to verify the volume is in the KR> pool of a given pool struct. Hmm, that's bizarre. Why don't all images show up in all pools then? I definitely agree with the second statement, but I find it interesting that we haven't seen this until now... KR> static bool _diskpool_is_member(virConnectPtr conn, KR> const struct disk_pool *pool, KR> - const char *file) KR> + const char *file, KR> + virStorageVolPtr vol) KR> { This change (well, the dependent one below) means that this code won't compile on libvirt < 0.4.0. KR> - virStorageVolPtr vol = NULL; KR> bool result = false; KR> + virStoragePoolPtr pool_vol = NULL; KR> + const char *pool_name = NULL; KR> - vol = virStorageVolLookupByPath(conn, file); KR> - if (vol != NULL) KR> - result = true; KR> - KR> + pool_vol = virStoragePoolLookupByVolume(vol); KR> + if (vol != NULL) { KR> + pool_name = virStoragePoolGetName(pool_vol); KR> + if ((pool_name != NULL) && (STREQC(pool_name, pool->tag))) KR> + result = true; KR> + } Why make the caller do the lookup? I can't see any reason why the virStorageVolLookupByPath() should be moved to the caller, which its part of the pool implementation and would work just fine here. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
KR> Verifying the volume exists isn't enough to prove the disk_pool KR> struct is the proper pool. We need to verify the volume is in the KR> pool of a given pool struct.
Hmm, that's bizarre. Why don't all images show up in all pools then? I definitely agree with the second statement, but I find it interesting that we haven't seen this until now...
There was a bug in the test case we had.. you only see this issue if you have multiple diskpools defined. Sometimes, you get lucky and the right pool is returned. It depends on the order the pools are looped through.
KR> static bool _diskpool_is_member(virConnectPtr conn, KR> const struct disk_pool *pool, KR> - const char *file) KR> + const char *file, KR> + virStorageVolPtr vol) KR> {
This change (well, the dependent one below) means that this code won't compile on libvirt < 0.4.0.
Ah, yuck.
KR> - virStorageVolPtr vol = NULL; KR> bool result = false; KR> + virStoragePoolPtr pool_vol = NULL; KR> + const char *pool_name = NULL;
KR> - vol = virStorageVolLookupByPath(conn, file); KR> - if (vol != NULL) KR> - result = true; KR> - KR> + pool_vol = virStoragePoolLookupByVolume(vol); KR> + if (vol != NULL) { KR> + pool_name = virStoragePoolGetName(pool_vol); KR> + if ((pool_name != NULL) && (STREQC(pool_name, pool->tag))) KR> + result = true; KR> + }
Why make the caller do the lookup? I can't see any reason why the virStorageVolLookupByPath() should be moved to the caller, which its part of the pool implementation and would work just fine here.
You end up getting the vol each time through the loop - you really only need to get it once. But good call about how it won't compile with libvirt < 0.4.0. I'll re-work it (and test with a version of libvirt < 0.4.0 this time around =). -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Dan Smith
-
Kaitlin Rupert