[PATCH] Fix DiskRASD size reporting

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1216823843 25200 # Node ID e8d39d291bb30a5337605c4ba97f20acb97ab859 # Parent 427e74d2c45881820ee33b8b6cdeb9cff57a68c0 Fix DiskRASD size reporting I *know* this was in place at one point, but I think it might have gotten lost in the changes to add libvirt storage support. We definitely need a test for this to make sure this functionality doesn't regress again. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 427e74d2c458 -r e8d39d291bb3 src/Virt_RASD.c --- a/src/Virt_RASD.c Mon Jul 21 13:28:13 2008 -0700 +++ b/src/Virt_RASD.c Wed Jul 23 07:37:23 2008 -0700 @@ -142,6 +142,83 @@ return s; } +#if LIBVIR_VERSION_NUMBER > 4000 +static bool get_vol_size(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const char *image, + uint64_t *size) +{ + virConnectPtr conn = NULL; + virStorageVolPtr vol = NULL; + virStorageVolInfo volinfo; + CMPIStatus s; + + *size = 0; + + conn = connect_by_classname(broker, CLASSNAME(ref), &s); + if (conn == NULL) + return false; + + vol = virStorageVolLookupByPath(conn, image); + if (vol != NULL) { + if (virStorageVolGetInfo(vol, &volinfo) != 0) { + CU_DEBUG("Failed to get info for volume %s", image); + } else { + *size = volinfo.capacity; + } + } + + virStorageVolFree(vol); + virConnectClose(conn); + + return true; +} +#else +static bool get_vol_size(const CMPIBroker * broker, + const CMPIObjectPath *ref, + const char *image, + uint64_t *size) +{ + struct stat st; + + if (stat(image, &st) == -1) + return false; + + *size = st.st_size; + + return true; +} +#endif + +static CMPIStatus set_disk_rasd_params(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const struct virt_device *dev, + CMPIInstance *inst) +{ + uint64_t cap = 0; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + get_vol_size(broker, ref, dev->dev.disk.source, &cap); + + CMSetProperty(inst, "VirtualQuantity", + (CMPIValue *)&cap, CMPI_uint64); + + CMSetProperty(inst, "AllocationUnits", + (CMPIValue *)"Bytes", CMPI_chars); + + CMSetProperty(inst, + "VirtualDevice", + (CMPIValue *)dev->dev.disk.virtual_dev, + CMPI_chars); + + CMSetProperty(inst, + "Address", + (CMPIValue *)dev->dev.disk.source, + CMPI_chars); + + return s; +} + static CMPIInstance *rasd_from_vdev(const CMPIBroker *broker, struct virt_device *dev, const char *host, @@ -192,14 +269,7 @@ (CMPIValue *)&type, CMPI_uint16); if (dev->type == CIM_RES_TYPE_DISK) { - CMSetProperty(inst, - "VirtualDevice", - (CMPIValue *)dev->dev.disk.virtual_dev, - CMPI_chars); - CMSetProperty(inst, - "Address", - (CMPIValue *)dev->dev.disk.source, - CMPI_chars); + s = set_disk_rasd_params(broker, ref, dev, inst); } else if (dev->type == CIM_RES_TYPE_NET) { CMSetProperty(inst, "NetworkType",

+#if LIBVIR_VERSION_NUMBER > 4000 +static bool get_vol_size(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const char *image, + uint64_t *size) +{ + virConnectPtr conn = NULL; + virStorageVolPtr vol = NULL; + virStorageVolInfo volinfo; + CMPIStatus s; + + *size = 0; + + conn = connect_by_classname(broker, CLASSNAME(ref), &s); + if (conn == NULL) + return false; + + vol = virStorageVolLookupByPath(conn, image); + if (vol != NULL) { + if (virStorageVolGetInfo(vol, &volinfo) != 0) { + CU_DEBUG("Failed to get info for volume %s", image);
You don't set a return code here, so you'll return true in this case. You're not using the return code of this function in the calling function, but that may change in the future.
+ } else { + *size = volinfo.capacity; + } + } + + virStorageVolFree(vol); + virConnectClose(conn); + + return true;
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Dan Smith
-
Kaitlin Rupert