diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-11-15 15:01:04 +0100 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-11-18 14:25:32 +0100 |
commit | de7e807310e00883ae39c59cc9cd14a66eaa4586 (patch) | |
tree | 4d1dffb9efb5d2fb64cb10a083150ed6fef927e7 /src/hardware/LMI_DiskPhysicalPackageProvider.c | |
parent | 2a6a28e5c8ee57b2adbb431370d6066d01df6719 (diff) | |
download | openlmi-providers-de7e807310e00883ae39c59cc9cd14a66eaa4586.tar.gz openlmi-providers-de7e807310e00883ae39c59cc9cd14a66eaa4586.tar.xz openlmi-providers-de7e807310e00883ae39c59cc9cd14a66eaa4586.zip |
Hardware: added lsblk fallback for physical disks
Smartctl doesn't work in virtual machine environment. Lsblk program reads sysfs
filesystem and outputs data about block devices. Advantage in using lsblk
instead of reading sysfs is, that it's not easy to distinguish between cd-roms,
disks, partitions, lvm.. Lsblk is doing some magic when determining the type of
device, so instead of duplicating the code, I'm using it's output. Lsblk is part
of the util-linux package, so no new dependency was introduced.
Diffstat (limited to 'src/hardware/LMI_DiskPhysicalPackageProvider.c')
-rw-r--r-- | src/hardware/LMI_DiskPhysicalPackageProvider.c | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/src/hardware/LMI_DiskPhysicalPackageProvider.c b/src/hardware/LMI_DiskPhysicalPackageProvider.c index a2945f1..daa0133 100644 --- a/src/hardware/LMI_DiskPhysicalPackageProvider.c +++ b/src/hardware/LMI_DiskPhysicalPackageProvider.c @@ -23,6 +23,7 @@ #include "LMI_Hardware.h" #include "globals.h" #include "smartctl.h" +#include "lsblk.h" static const CMPIBroker* _cb = NULL; @@ -57,38 +58,68 @@ static CMPIStatus LMI_DiskPhysicalPackageEnumInstances( { LMI_DiskPhysicalPackage lmi_hdd; const char *ns = KNameSpace(cop); - unsigned i; - char instance_id[INSTANCE_ID_LEN]; + unsigned i, hdds_nb = 0; + char instance_id[INSTANCE_ID_LEN], *id, *manufacturer, *serial_nb, + *name, *model; SmartctlHdd *smtcl_hdds = NULL; unsigned smtcl_hdds_nb = 0; + LsblkHdd *lsblk_hdds = NULL; + unsigned lsblk_hdds_nb = 0; if (smartctl_get_hdds(&smtcl_hdds, &smtcl_hdds_nb) != 0 || smtcl_hdds_nb < 1) { - goto done; + smartctl_free_hdds(&smtcl_hdds, &smtcl_hdds_nb); + if (lsblk_get_hdds(&lsblk_hdds, &lsblk_hdds_nb) != 0 || lsblk_hdds_nb < 1) { + goto done; + } } - for (i = 0; i < smtcl_hdds_nb; i++) { + if (smtcl_hdds_nb > 0) { + hdds_nb = smtcl_hdds_nb; + } else { + hdds_nb = lsblk_hdds_nb; + } + + for (i = 0; i < hdds_nb; i++) { + /* in fallback mode, use only disk devices from lsblk */ + if (smtcl_hdds_nb < 1) { + if (strcmp(lsblk_hdds[i].type, "disk") != 0) { + continue; + } + } + + if (smtcl_hdds_nb > 0) { + id = smtcl_hdds[i].serial_number; + manufacturer = smtcl_hdds[i].manufacturer; + model = smtcl_hdds[i].model; + serial_nb = smtcl_hdds[i].serial_number; + name = smtcl_hdds[i].name; + } else { + id = lsblk_hdds[i].name; + manufacturer = lsblk_hdds[i].vendor; + model = lsblk_hdds[i].model; + serial_nb = lsblk_hdds[i].serial; + name = lsblk_hdds[i].name; + } + LMI_DiskPhysicalPackage_Init(&lmi_hdd, _cb, ns); LMI_DiskPhysicalPackage_Set_CreationClassName(&lmi_hdd, ORGID "_" DISK_PHYS_PKG_CLASS_NAME); LMI_DiskPhysicalPackage_Set_PackageType(&lmi_hdd, LMI_DiskPhysicalPackage_PackageType_Storage_Media_Package_e_g___Disk_or_Tape_Drive); - - snprintf(instance_id, INSTANCE_ID_LEN, - ORGID ":" ORGID "_" DISK_PHYS_PKG_CLASS_NAME ":%s", - smtcl_hdds[i].serial_number); - - LMI_DiskPhysicalPackage_Set_Tag(&lmi_hdd, smtcl_hdds[i].serial_number); - LMI_DiskPhysicalPackage_Set_Manufacturer(&lmi_hdd, - smtcl_hdds[i].manufacturer); - LMI_DiskPhysicalPackage_Set_Model(&lmi_hdd, smtcl_hdds[i].model); - LMI_DiskPhysicalPackage_Set_SerialNumber(&lmi_hdd, - smtcl_hdds[i].serial_number); LMI_DiskPhysicalPackage_Set_Caption(&lmi_hdd, "Physical Disk Package"); LMI_DiskPhysicalPackage_Set_Description(&lmi_hdd, "This object represents one physical disk package in system."); - LMI_DiskPhysicalPackage_Set_Name(&lmi_hdd, smtcl_hdds[i].name); - LMI_DiskPhysicalPackage_Set_ElementName(&lmi_hdd, smtcl_hdds[i].name); + + snprintf(instance_id, INSTANCE_ID_LEN, + ORGID ":" ORGID "_" DISK_PHYS_PKG_CLASS_NAME ":%s", id); + + LMI_DiskPhysicalPackage_Set_Tag(&lmi_hdd, id); + LMI_DiskPhysicalPackage_Set_Manufacturer(&lmi_hdd, manufacturer); + LMI_DiskPhysicalPackage_Set_Model(&lmi_hdd, model); + LMI_DiskPhysicalPackage_Set_SerialNumber(&lmi_hdd, serial_nb); + LMI_DiskPhysicalPackage_Set_Name(&lmi_hdd, name); + LMI_DiskPhysicalPackage_Set_ElementName(&lmi_hdd, name); LMI_DiskPhysicalPackage_Set_InstanceID(&lmi_hdd, instance_id); KReturnInstance(cr, lmi_hdd); @@ -96,6 +127,7 @@ static CMPIStatus LMI_DiskPhysicalPackageEnumInstances( done: smartctl_free_hdds(&smtcl_hdds, &smtcl_hdds_nb); + lsblk_free_hdds(&lsblk_hdds, &lsblk_hdds_nb); CMReturn(CMPI_RC_OK); } |