diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-12-03 16:34:03 +0100 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-12-06 10:57:06 +0100 |
commit | eee7c40c1f91e5b19eafb7b1135c57d659ec8345 (patch) | |
tree | 7bdb6e82f58cfe122d6549f2f5d2fe4ead9be011 /src/hardware | |
parent | 2a0ab172d96c5f8eeab45641d5129aaacd78aa7a (diff) | |
download | openlmi-providers-eee7c40c1f91e5b19eafb7b1135c57d659ec8345.tar.gz openlmi-providers-eee7c40c1f91e5b19eafb7b1135c57d659ec8345.tar.xz openlmi-providers-eee7c40c1f91e5b19eafb7b1135c57d659ec8345.zip |
Hardware: added association class DiskDriveSystemDevice
New provider:
* LMI_DiskDriveSystemDeviceProvider
Diffstat (limited to 'src/hardware')
-rw-r--r-- | src/hardware/LMI_DiskDriveSystemDeviceProvider.c | 286 |
1 files changed, 286 insertions, 0 deletions
diff --git a/src/hardware/LMI_DiskDriveSystemDeviceProvider.c b/src/hardware/LMI_DiskDriveSystemDeviceProvider.c new file mode 100644 index 0000000..981de58 --- /dev/null +++ b/src/hardware/LMI_DiskDriveSystemDeviceProvider.c @@ -0,0 +1,286 @@ +/* + * 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_DiskDriveSystemDevice.h" +#include "LMI_Hardware.h" +#include "globals.h" +#include "smartctl.h" +#include "lsblk.h" + +static const CMPIBroker* _cb; + +static void LMI_DiskDriveSystemDeviceInitialize(const CMPIContext *ctx) +{ + lmi_init(provider_name, _cb, ctx, provider_config_defaults); +} + +static CMPIStatus LMI_DiskDriveSystemDeviceCleanup( + CMPIInstanceMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DiskDriveSystemDeviceEnumInstanceNames( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + return KDefaultEnumerateInstanceNames( + _cb, mi, cc, cr, cop); +} + +static CMPIStatus LMI_DiskDriveSystemDeviceEnumInstances( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const char** properties) +{ + LMI_DiskDriveSystemDevice lmi_hdd_sys; + LMI_DiskDriveRef lmi_hdd; + const char *ns = KNameSpace(cop); + unsigned i, hdds_nb = 0; + char *id; + 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) { + 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; + } + + 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; + } else { + id = lsblk_hdds[i].name; + } + + LMI_DiskDriveSystemDevice_Init(&lmi_hdd_sys, _cb, ns); + + LMI_DiskDriveRef_Init(&lmi_hdd, _cb, ns); + LMI_DiskDriveRef_Set_SystemCreationClassName(&lmi_hdd, + get_system_creation_class_name()); + LMI_DiskDriveRef_Set_SystemName(&lmi_hdd, get_system_name()); + LMI_DiskDriveRef_Set_CreationClassName(&lmi_hdd, + ORGID "_" DISK_DRIVE_CLASS_NAME); + LMI_DiskDriveRef_Set_DeviceID(&lmi_hdd, id); + + LMI_DiskDriveSystemDevice_SetObjectPath_GroupComponent( + &lmi_hdd_sys, lmi_get_computer_system()); + LMI_DiskDriveSystemDevice_Set_PartComponent(&lmi_hdd_sys, + &lmi_hdd); + + KReturnInstance(cr, lmi_hdd_sys); + } + +done: + smartctl_free_hdds(&smtcl_hdds, &smtcl_hdds_nb); + lsblk_free_hdds(&lsblk_hdds, &lsblk_hdds_nb); + + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DiskDriveSystemDeviceGetInstance( + 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_DiskDriveSystemDeviceCreateInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop, + const CMPIInstance* ci) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DiskDriveSystemDeviceModifyInstance( + 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_DiskDriveSystemDeviceDeleteInstance( + CMPIInstanceMI* mi, + const CMPIContext* cc, + const CMPIResult* cr, + const CMPIObjectPath* cop) +{ + CMReturn(CMPI_RC_ERR_NOT_SUPPORTED); +} + +static CMPIStatus LMI_DiskDriveSystemDeviceExecQuery( + 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_DiskDriveSystemDeviceAssociationCleanup( + CMPIAssociationMI* mi, + const CMPIContext* cc, + CMPIBoolean term) +{ + CMReturn(CMPI_RC_OK); +} + +static CMPIStatus LMI_DiskDriveSystemDeviceAssociators( + 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_DiskDriveSystemDevice_ClassName, + assocClass, + resultClass, + role, + resultRole, + properties); +} + +static CMPIStatus LMI_DiskDriveSystemDeviceAssociatorNames( + 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_DiskDriveSystemDevice_ClassName, + assocClass, + resultClass, + role, + resultRole); +} + +static CMPIStatus LMI_DiskDriveSystemDeviceReferences( + 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_DiskDriveSystemDevice_ClassName, + assocClass, + role, + properties); +} + +static CMPIStatus LMI_DiskDriveSystemDeviceReferenceNames( + 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_DiskDriveSystemDevice_ClassName, + assocClass, + role); +} + +CMInstanceMIStub( + LMI_DiskDriveSystemDevice, + LMI_DiskDriveSystemDevice, + _cb, + LMI_DiskDriveSystemDeviceInitialize(ctx)) + +CMAssociationMIStub( + LMI_DiskDriveSystemDevice, + LMI_DiskDriveSystemDevice, + _cb, + LMI_DiskDriveSystemDeviceInitialize(ctx)) + +KONKRET_REGISTRATION( + "root/cimv2", + "LMI_DiskDriveSystemDevice", + "LMI_DiskDriveSystemDevice", + "instance association") |