diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-12-16 17:10:35 +0100 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-12-17 14:59:19 +0100 |
commit | f8ebe2155ae4ae3a38af266bcd0fadd6b812a79e (patch) | |
tree | acebb51f6ddcc133ed3e4eb786c923929bcc9410 | |
parent | 44c28b2baeb7a99bfd8734e7f7c4f53444e56c04 (diff) | |
download | openlmi-providers-f8ebe2155ae4ae3a38af266bcd0fadd6b812a79e.tar.gz openlmi-providers-f8ebe2155ae4ae3a38af266bcd0fadd6b812a79e.tar.xz openlmi-providers-f8ebe2155ae4ae3a38af266bcd0fadd6b812a79e.zip |
Hardware: added DiskDriveSoftwareIdentity provider
New provider:
* LMI_DiskDriveSoftwareIdentity
-rw-r--r-- | mof/60_LMI_Hardware.mof | 34 | ||||
-rw-r--r-- | src/hardware/LMI_DiskDriveSoftwareIdentityProvider.c | 219 | ||||
-rw-r--r-- | src/hardware/LMI_Hardware.h | 1 | ||||
-rw-r--r-- | src/hardware/smartctl.c | 27 | ||||
-rw-r--r-- | src/hardware/smartctl.h | 1 |
5 files changed, 282 insertions, 0 deletions
diff --git a/mof/60_LMI_Hardware.mof b/mof/60_LMI_Hardware.mof index dc5da14..c094208 100644 --- a/mof/60_LMI_Hardware.mof +++ b/mof/60_LMI_Hardware.mof @@ -1380,3 +1380,37 @@ class LMI_DiskDriveSystemDevice: CIM_SystemDevice LMI_DiskDrive REF PartComponent; }; +[ Version("0.5.0"), Provider("cmpi:cmpiLMI_DiskDriveSoftwareIdentity") ] +class LMI_DiskDriveSoftwareIdentity: CIM_SoftwareIdentity +{ + [ Implemented(true), Override("InstanceID") ] + string InstanceID; + + [ Implemented(true), Override("VersionString") ] + string VersionString; + + [ Implemented(true), Override("Caption") ] + string Caption; + + [ Implemented(true), Override("Description") ] + string Description; + + [ Implemented(true), Override("Classifications") ] + uint16 Classifications[]; + + [ Implemented(true), Override("ElementName") ] + string ElementName; + + [ Implemented(true), Override("Name") ] + string Name; + + [ Implemented(true), Override("Manufacturer") ] + string Manufacturer; + + [ Implemented(true), Override("IsEntity") ] + boolean IsEntity; + + [ Implemented(true), Override("IsLargeBuildNumber") ] + boolean IsLargeBuildNumber; +}; + diff --git a/src/hardware/LMI_DiskDriveSoftwareIdentityProvider.c b/src/hardware/LMI_DiskDriveSoftwareIdentityProvider.c new file mode 100644 index 0000000..08f9a22 --- /dev/null +++ b/src/hardware/LMI_DiskDriveSoftwareIdentityProvider.c @@ -0,0 +1,219 @@ +/* + * Copyright (C) 2013 Red Hat, Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: Peter Schiffer <pschiffe@redhat.com> + */ + +#include <konkret/konkret.h> +#include "LMI_DiskDriveSoftwareIdentity.h" +#include "LMI_Hardware.h" +#include "globals.h" +#include "smartctl.h" +#include "lsblk.h" + +static const CMPIBroker* _cb = NULL; + +static void LMI_DiskDriveSoftwareIdentityInitialize(const CMPIContext *ctx) +{ + lmi_init(provider_name, _cb, ctx, provider_config_defaults); +} + +static CMPIStatus LMI_DiskDriveSoftwareIdentityCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DiskDriveSoftwareIdentityEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + return KDefaultEnumerateInstanceNames( + _cb, mi, cc, cr, cop); +} + +static CMPIStatus LMI_DiskDriveSoftwareIdentityEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + LMI_DiskDriveSoftwareIdentity lmi_hdd_swi; + const char *ns = KNameSpace(cop); + unsigned i, j; + char instance_id[INSTANCE_ID_LEN], *fw_ver = NULL, name[ELEMENT_NAME_LEN]; + SmartctlHdd *smtcl_hdds = NULL; + unsigned smtcl_hdds_nb = 0; + LsblkHdd *lsblk_hdds = NULL; + unsigned lsblk_hdds_nb = 0; + + if (lsblk_get_hdds(&lsblk_hdds, &lsblk_hdds_nb) != 0 || lsblk_hdds_nb < 1) { + goto done; + } + if (smartctl_get_hdds(&smtcl_hdds, &smtcl_hdds_nb) != 0 || smtcl_hdds_nb < 1) { + smartctl_free_hdds(&smtcl_hdds, &smtcl_hdds_nb); + } + + for (i = 0; i < lsblk_hdds_nb; i++) { + /* use only disk devices from lsblk */ + if (strcmp(lsblk_hdds[i].type, "disk") != 0) { + continue; + } + + LMI_DiskDriveSoftwareIdentity_Init(&lmi_hdd_swi, _cb, ns); + + LMI_DiskDriveSoftwareIdentity_Init_Classifications(&lmi_hdd_swi, 1); + LMI_DiskDriveSoftwareIdentity_Set_Classifications(&lmi_hdd_swi, 0, + LMI_DiskDriveSoftwareIdentity_Classifications_Firmware); + LMI_DiskDriveSoftwareIdentity_Set_Caption(&lmi_hdd_swi, "Disk Firmware"); + LMI_DiskDriveSoftwareIdentity_Set_Description(&lmi_hdd_swi, + "This object represents firmware of disk drive in system."); + + snprintf(instance_id, INSTANCE_ID_LEN, + ORGID ":" ORGID "_" DISK_DRIVE_SW_IDENTITY_CLASS_NAME ":%s", + lsblk_hdds[i].name); + snprintf(name, ELEMENT_NAME_LEN, "%s disk firmware", + lsblk_hdds[i].name); + + LMI_DiskDriveSoftwareIdentity_Set_InstanceID(&lmi_hdd_swi, instance_id); + LMI_DiskDriveSoftwareIdentity_Set_Name(&lmi_hdd_swi, name); + LMI_DiskDriveSoftwareIdentity_Set_ElementName(&lmi_hdd_swi, name); + + /* check for smartctl output */ + for (j = 0; j < smtcl_hdds_nb; j++) { + if (strcmp(smtcl_hdds[j].dev_path, lsblk_hdds[i].name) == 0) { + fw_ver = smtcl_hdds[j].firmware; + break; + } + } + + if (fw_ver) { + LMI_DiskDriveSoftwareIdentity_Set_VersionString( + &lmi_hdd_swi, fw_ver); + } else { + LMI_DiskDriveSoftwareIdentity_Set_VersionString( + &lmi_hdd_swi, "Unknown"); + } + + LMI_DiskDriveSoftwareIdentity_Set_Manufacturer(&lmi_hdd_swi, + lsblk_hdds[i].vendor); + + KReturnInstance(cr, lmi_hdd_swi); + } + +done: + smartctl_free_hdds(&smtcl_hdds, &smtcl_hdds_nb); + lsblk_free_hdds(&lsblk_hdds, &lsblk_hdds_nb); + + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DiskDriveSoftwareIdentityGetInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + return KDefaultGetInstance( + _cb, mi, cc, cr, cop, properties); +} + +static CMPIStatus LMI_DiskDriveSoftwareIdentityCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DiskDriveSoftwareIdentityModifyInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci, + const char** properties) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DiskDriveSoftwareIdentityDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DiskDriveSoftwareIdentityExecQuery( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* lang, + const char* query) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +CMInstanceMIStub( + LMI_DiskDriveSoftwareIdentity, + LMI_DiskDriveSoftwareIdentity, + _cb, + LMI_DiskDriveSoftwareIdentityInitialize(ctx)) + +static CMPIStatus LMI_DiskDriveSoftwareIdentityMethodCleanup( + CMPIMethodMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DiskDriveSoftwareIdentityInvokeMethod( + CMPIMethodMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* meth, + const CMPIArgs* in, + CMPIArgs* out) +{ + return LMI_DiskDriveSoftwareIdentity_DispatchMethod( + _cb, mi, cc, cr, cop, meth, in, out); +} + +CMMethodMIStub( + LMI_DiskDriveSoftwareIdentity, + LMI_DiskDriveSoftwareIdentity, + _cb, + LMI_DiskDriveSoftwareIdentityInitialize(ctx)) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_DiskDriveSoftwareIdentity", + "LMI_DiskDriveSoftwareIdentity", + "instance method") diff --git a/src/hardware/LMI_Hardware.h b/src/hardware/LMI_Hardware.h index 52756ac..aca9b70 100644 --- a/src/hardware/LMI_Hardware.h +++ b/src/hardware/LMI_Hardware.h @@ -48,5 +48,6 @@ const char *provider_name; #define PCI_BRIDGE_CLASS_NAME "PCIBridge" #define DISK_PHYS_PKG_CLASS_NAME "DiskPhysicalPackage" #define DISK_DRIVE_CLASS_NAME "DiskDrive" +#define DISK_DRIVE_SW_IDENTITY_CLASS_NAME "DiskDriveSoftwareIdentity" #endif /* LMI_HARDWARE_H_ */ diff --git a/src/hardware/smartctl.c b/src/hardware/smartctl.c index 4e7c04c..349f198 100644 --- a/src/hardware/smartctl.c +++ b/src/hardware/smartctl.c @@ -33,6 +33,7 @@ void init_smctlhdd_struct(SmartctlHdd *hdd) hdd->serial_number = NULL; hdd->name = NULL; hdd->smart_status = NULL; + hdd->firmware = NULL; hdd->form_factor = 0; hdd->port_speed = 0; hdd->rpm = 0xffffffff; @@ -82,6 +83,11 @@ short check_smctlhdd_attributes(SmartctlHdd *hdd) goto done; } } + if (!hdd->firmware) { + if (!(hdd->firmware = strdup("Unknown"))) { + goto done; + } + } ret = 0; @@ -253,6 +259,25 @@ short smartctl_get_hdds(SmartctlHdd **hdds, unsigned *hdds_nb) buf = NULL; continue; } + /* Firmware version */ + buf = copy_string_part_after_delim(buffer[i], "Firmware Version:"); + if (buf) { + free((*hdds)[curr_hdd].firmware); + (*hdds)[curr_hdd].firmware = buf; + buf = NULL; + continue; + } + /* Firmware version, second version */ + buf = copy_string_part_after_delim(buffer[i], "Revision:"); + if (buf) { + if (!(*hdds)[curr_hdd].firmware) { + (*hdds)[curr_hdd].firmware = buf; + } else { + free(buf); + } + buf = NULL; + continue; + } /* Form Factor */ /* Form Factor is stored in the 168. word * of the IDENTIFY DEVICE data table. Line with this info looks like: @@ -329,6 +354,8 @@ void smartctl_free_hdds(SmartctlHdd **hdds, unsigned *hdds_nb) (*hdds)[i].name = NULL; free((*hdds)[i].smart_status); (*hdds)[i].smart_status = NULL; + free((*hdds)[i].firmware); + (*hdds)[i].firmware = NULL; } free(*hdds); } diff --git a/src/hardware/smartctl.h b/src/hardware/smartctl.h index 560effa..4f3eadb 100644 --- a/src/hardware/smartctl.h +++ b/src/hardware/smartctl.h @@ -41,6 +41,7 @@ typedef struct _SmartctlHdd { char *serial_number; /* Serial Number */ char *name; /* Name */ char *smart_status; /* SMART status */ + char *firmware; /* Firmware version */ unsigned short form_factor; /* Form Factor */ unsigned long port_speed; /* Port Speed in b/s */ unsigned rpm; /* RPM of drive */ |