diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-11-18 18:25:28 +0100 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-11-20 12:54:42 +0100 |
commit | d543a65e8c1768f5afeedc660565d63c1dc24f11 (patch) | |
tree | 247cee7c7592d0a2ebbc1dce293024e125886601 | |
parent | 06916e0a4bb155ccc294bda6252dc9e32583e346 (diff) | |
download | openlmi-providers-d543a65e8c1768f5afeedc660565d63c1dc24f11.tar.gz openlmi-providers-d543a65e8c1768f5afeedc660565d63c1dc24f11.tar.xz openlmi-providers-d543a65e8c1768f5afeedc660565d63c1dc24f11.zip |
Hardware: Added LMI_DiskPhysicalPackageContainer association
Added LMI_DiskPhysicalPackageContainer association between
LMI_DiskPhysicalPackage and LMI_Chassis.
Also, added default values for disk manufacturer and model.
-rw-r--r-- | mof/60_LMI_Hardware.mof | 10 | ||||
-rw-r--r-- | src/hardware/LMI_DiskPhysicalPackageContainerProvider.c | 294 | ||||
-rw-r--r-- | src/hardware/lsblk.c | 4 | ||||
-rw-r--r-- | src/hardware/smartctl.c | 4 |
4 files changed, 308 insertions, 4 deletions
diff --git a/mof/60_LMI_Hardware.mof b/mof/60_LMI_Hardware.mof index 342f0e3..a50129c 100644 --- a/mof/60_LMI_Hardware.mof +++ b/mof/60_LMI_Hardware.mof @@ -1298,3 +1298,13 @@ class LMI_DiskPhysicalPackage: CIM_PhysicalPackage string InstanceID; }; +[ Version("0.5.0"), Provider("cmpi:cmpiLMI_DiskPhysicalPackageContainer"), Association ] +class LMI_DiskPhysicalPackageContainer: CIM_Container +{ + [ Override("GroupComponent") ] + LMI_Chassis REF GroupComponent; + + [ Override("PartComponent") ] + LMI_DiskPhysicalPackage REF PartComponent; +}; + diff --git a/src/hardware/LMI_DiskPhysicalPackageContainerProvider.c b/src/hardware/LMI_DiskPhysicalPackageContainerProvider.c new file mode 100644 index 0000000..ef6e41b --- /dev/null +++ b/src/hardware/LMI_DiskPhysicalPackageContainerProvider.c @@ -0,0 +1,294 @@ +/* + * 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_DiskPhysicalPackageContainer.h" +#include "LMI_Hardware.h" +#include "globals.h" +#include "dmidecode.h" +#include "smartctl.h" +#include "lsblk.h" + +static const CMPIBroker* _cb; + +static void LMI_DiskPhysicalPackageContainerInitialize() +{ +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + return KDefaultEnumerateInstanceNames( + _cb, mi, cc, cr, cop); +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + LMI_DiskPhysicalPackageContainer lmi_hdd_container; + LMI_DiskPhysicalPackageRef lmi_hdd; + LMI_ChassisRef lmi_chassis; + const char *ns = KNameSpace(cop); + unsigned i, hdds_nb = 0; + char *tag; + DmiChassis dmi_chassis; + SmartctlHdd *smtcl_hdds = NULL; + unsigned smtcl_hdds_nb = 0; + LsblkHdd *lsblk_hdds = NULL; + unsigned lsblk_hdds_nb = 0; + + if (dmi_get_chassis(&dmi_chassis) != 0) { + goto done; + } + if (smartctl_get_hdds(&smtcl_hdds, &smtcl_hdds_nb) != 0 || smtcl_hdds_nb < 1) { + smartctl_free_hdds(&smtcl_hdds, &smtcl_hdds_nb); + if (lsblk_get_hdds(&lsblk_hdds, &lsblk_hdds_nb) != 0 || lsblk_hdds_nb < 1) { + goto done; + } + } + + if (smtcl_hdds_nb > 0) { + hdds_nb = smtcl_hdds_nb; + } else { + hdds_nb = lsblk_hdds_nb; + } + + LMI_ChassisRef_Init(&lmi_chassis, _cb, ns); + LMI_ChassisRef_Set_CreationClassName(&lmi_chassis, + ORGID "_" CHASSIS_CLASS_NAME); + LMI_ChassisRef_Set_Tag(&lmi_chassis, dmi_get_chassis_tag(&dmi_chassis)); + + 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) { + tag = smtcl_hdds[i].serial_number; + } else { + tag = lsblk_hdds[i].name; + } + + LMI_DiskPhysicalPackageContainer_Init(&lmi_hdd_container, _cb, ns); + + LMI_DiskPhysicalPackageRef_Init(&lmi_hdd, _cb, ns); + LMI_DiskPhysicalPackageRef_Set_CreationClassName(&lmi_hdd, + ORGID "_" DISK_PHYS_PKG_CLASS_NAME); + LMI_DiskPhysicalPackageRef_Set_Tag(&lmi_hdd, tag); + + LMI_DiskPhysicalPackageContainer_Set_GroupComponent(&lmi_hdd_container, + &lmi_chassis); + LMI_DiskPhysicalPackageContainer_Set_PartComponent(&lmi_hdd_container, + &lmi_hdd); + + KReturnInstance(cr, lmi_hdd_container); + } + +done: + dmi_free_chassis(&dmi_chassis); + smartctl_free_hdds(&smtcl_hdds, &smtcl_hdds_nb); + lsblk_free_hdds(&lsblk_hdds, &lsblk_hdds_nb); + + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerGetInstance( + 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_DiskPhysicalPackageContainerCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerModifyInstance( + 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_DiskPhysicalPackageContainerDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerExecQuery( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* lang, + const char* query) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerAssociationCleanup( + CMPIAssociationMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerAssociators( + CMPIAssociationMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* assocClass, + const char* resultClass, + const char* role, + const char* resultRole, + const char** properties) +{ + return KDefaultAssociators( + _cb, + mi, + cc, + cr, + cop, + LMI_DiskPhysicalPackageContainer_ClassName, + assocClass, + resultClass, + role, + resultRole, + properties); +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerAssociatorNames( + CMPIAssociationMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* assocClass, + const char* resultClass, + const char* role, + const char* resultRole) +{ + return KDefaultAssociatorNames( + _cb, + mi, + cc, + cr, + cop, + LMI_DiskPhysicalPackageContainer_ClassName, + assocClass, + resultClass, + role, + resultRole); +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerReferences( + CMPIAssociationMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* assocClass, + const char* role, + const char** properties) +{ + return KDefaultReferences( + _cb, + mi, + cc, + cr, + cop, + LMI_DiskPhysicalPackageContainer_ClassName, + assocClass, + role, + properties); +} + +static CMPIStatus LMI_DiskPhysicalPackageContainerReferenceNames( + CMPIAssociationMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char* assocClass, + const char* role) +{ + return KDefaultReferenceNames( + _cb, + mi, + cc, + cr, + cop, + LMI_DiskPhysicalPackageContainer_ClassName, + assocClass, + role); +} + +CMInstanceMIStub( + LMI_DiskPhysicalPackageContainer, + LMI_DiskPhysicalPackageContainer, + _cb, + LMI_DiskPhysicalPackageContainerInitialize()) + +CMAssociationMIStub( + LMI_DiskPhysicalPackageContainer, + LMI_DiskPhysicalPackageContainer, + _cb, + LMI_DiskPhysicalPackageContainerInitialize()) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_DiskPhysicalPackageContainer", + "LMI_DiskPhysicalPackageContainer", + "instance association") diff --git a/src/hardware/lsblk.c b/src/hardware/lsblk.c index 74d4a2f..d8fc078 100644 --- a/src/hardware/lsblk.c +++ b/src/hardware/lsblk.c @@ -60,7 +60,7 @@ short check_lsblkhdd_attributes(LsblkHdd *hdd) } } if (!hdd->model) { - if (!(hdd->model = strdup(""))) { + if (!(hdd->model = strdup("Unknown"))) { goto done; } } @@ -75,7 +75,7 @@ short check_lsblkhdd_attributes(LsblkHdd *hdd) } } if (!hdd->vendor) { - if (!(hdd->vendor = strdup(""))) { + if (!(hdd->vendor = strdup("Unknown"))) { goto done; } } diff --git a/src/hardware/smartctl.c b/src/hardware/smartctl.c index 8ba724a..1067e9b 100644 --- a/src/hardware/smartctl.c +++ b/src/hardware/smartctl.c @@ -54,12 +54,12 @@ short check_smctlhdd_attributes(SmartctlHdd *hdd) } } if (!hdd->manufacturer) { - if (!(hdd->manufacturer = strdup(""))) { + if (!(hdd->manufacturer = strdup("Unknown"))) { goto done; } } if (!hdd->model) { - if (!(hdd->model = strdup(""))) { + if (!(hdd->model = strdup("Unknown"))) { goto done; } } |