summaryrefslogtreecommitdiffstats
path: root/src/hardware/LMI_DiskDriveProvider.c
diff options
context:
space:
mode:
authorPeter Schiffer <pschiffe@redhat.com>2013-12-10 19:23:37 +0100
committerPeter Schiffer <pschiffe@redhat.com>2013-12-10 19:23:37 +0100
commite99df5fdba9bb16dfec1e1a80f001fe97622e71b (patch)
tree2482189e6d504ee20fb6e957aa3303164ee5aa91 /src/hardware/LMI_DiskDriveProvider.c
parent4d3e9d9f3bda71faf6b46286e1ad78fb0e3696cf (diff)
downloadopenlmi-providers-e99df5fdba9bb16dfec1e1a80f001fe97622e71b.tar.gz
openlmi-providers-e99df5fdba9bb16dfec1e1a80f001fe97622e71b.tar.xz
openlmi-providers-e99df5fdba9bb16dfec1e1a80f001fe97622e71b.zip
Hardware: use lsblk as primary source for disks
This patch makes lsblk primary source for information about disks instead of smartctl. This change was needed because in virtual environment some disks might be recognized by smartctl while others not, and in this case, some disks would be missing in LMI classes. With lsblk, all disks are always listed. Smartctl is used as source of additional information if avaiable.
Diffstat (limited to 'src/hardware/LMI_DiskDriveProvider.c')
-rw-r--r--src/hardware/LMI_DiskDriveProvider.c101
1 files changed, 49 insertions, 52 deletions
diff --git a/src/hardware/LMI_DiskDriveProvider.c b/src/hardware/LMI_DiskDriveProvider.c
index 9bfe8df..31e4a48 100644
--- a/src/hardware/LMI_DiskDriveProvider.c
+++ b/src/hardware/LMI_DiskDriveProvider.c
@@ -64,44 +64,28 @@ static CMPIStatus LMI_DiskDriveEnumInstances(
{
LMI_DiskDrive lmi_hdd;
const char *ns = KNameSpace(cop);
- unsigned i, hdds_nb = 0, rotational = 0;
- char instance_id[INSTANCE_ID_LEN], *id, *name, path[PATH_MAX], *basename;
+ unsigned i, j, rotational = 0;
+ char instance_id[INSTANCE_ID_LEN], path[PATH_MAX], *name;
CMPIUint16 operational_status;
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);
- 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;
- }
+ for (i = 0; i < lsblk_hdds_nb; i++) {
+ /* use only disk devices from lsblk */
+ if (strcmp(lsblk_hdds[i].type, "disk") != 0) {
+ continue;
}
- if (smtcl_hdds_nb > 0) {
- id = smtcl_hdds[i].serial_number;
- name = smtcl_hdds[i].name;
- basename = smtcl_hdds[i].dev_basename;
- } else {
- id = lsblk_hdds[i].name;
- name = lsblk_hdds[i].name;
- basename = lsblk_hdds[i].basename;
- }
+ name = lsblk_hdds[i].name;
LMI_DiskDrive_Init(&lmi_hdd, _cb, ns);
@@ -115,37 +99,50 @@ static CMPIStatus LMI_DiskDriveEnumInstances(
"This object represents one physical disk drive in system.");
snprintf(instance_id, INSTANCE_ID_LEN,
- ORGID ":" ORGID "_" DISK_DRIVE_CLASS_NAME ":%s", id);
+ ORGID ":" ORGID "_" DISK_DRIVE_CLASS_NAME ":%s",
+ lsblk_hdds[i].name);
- LMI_DiskDrive_Set_DeviceID(&lmi_hdd, id);
- LMI_DiskDrive_Set_Name(&lmi_hdd, name);
- LMI_DiskDrive_Set_ElementName(&lmi_hdd, name);
+ LMI_DiskDrive_Set_DeviceID(&lmi_hdd, lsblk_hdds[i].name);
LMI_DiskDrive_Set_InstanceID(&lmi_hdd, instance_id);
- /* if we have smartctl output */
- if (smtcl_hdds_nb > 0) {
- operational_status = get_operational_status(
- smtcl_hdds[i].smart_status);
-
- LMI_DiskDrive_Init_OperationalStatus(&lmi_hdd, 1);
- LMI_DiskDrive_Set_OperationalStatus(&lmi_hdd, 0, operational_status);
- if (operational_status == LMI_DiskDrive_OperationalStatus_OK) {
- LMI_DiskDrive_Set_EnabledState(&lmi_hdd,
- LMI_DiskDrive_EnabledState_Enabled);
- } else {
- LMI_DiskDrive_Set_EnabledState(&lmi_hdd,
- LMI_DiskDrive_EnabledState_Unknown);
+ /* check for smartctl output */
+ for (j = 0; j < smtcl_hdds_nb; j++) {
+ if (strcmp(smtcl_hdds[j].dev_path, lsblk_hdds[i].name) == 0) {
+ operational_status = get_operational_status(
+ smtcl_hdds[j].smart_status);
+ if (strlen(smtcl_hdds[j].name)) {
+ name = smtcl_hdds[j].name;
+ } else if (strlen(smtcl_hdds[j].model)) {
+ name = smtcl_hdds[j].model;
+ }
+
+ LMI_DiskDrive_Init_OperationalStatus(&lmi_hdd, 1);
+ LMI_DiskDrive_Set_OperationalStatus(&lmi_hdd, 0, operational_status);
+ if (operational_status == LMI_DiskDrive_OperationalStatus_OK) {
+ LMI_DiskDrive_Set_EnabledState(&lmi_hdd,
+ LMI_DiskDrive_EnabledState_Enabled);
+ } else {
+ LMI_DiskDrive_Set_EnabledState(&lmi_hdd,
+ LMI_DiskDrive_EnabledState_Unknown);
+ }
+
+ LMI_DiskDrive_Set_FormFactor(&lmi_hdd,
+ get_hdd_form_factor(smtcl_hdds[j].form_factor));
+ LMI_DiskDrive_Set_RPM(&lmi_hdd, smtcl_hdds[j].rpm);
+ if (smtcl_hdds[j].port_speed) {
+ LMI_DiskDrive_Set_InterconnectSpeed(&lmi_hdd,
+ smtcl_hdds[j].port_speed);
+ }
+
+ break;
}
-
- LMI_DiskDrive_Set_FormFactor(&lmi_hdd,
- get_hdd_form_factor(smtcl_hdds[i].form_factor));
- LMI_DiskDrive_Set_InterconnectSpeed(&lmi_hdd,
- smtcl_hdds[i].port_speed);
- LMI_DiskDrive_Set_RPM(&lmi_hdd, smtcl_hdds[i].rpm);
}
+ LMI_DiskDrive_Set_Name(&lmi_hdd, name);
+ LMI_DiskDrive_Set_ElementName(&lmi_hdd, name);
+
snprintf(path, PATH_MAX, SYSFS_BLOCK_PATH "/%s/queue/rotational",
- basename);
+ lsblk_hdds[i].basename);
if (path_get_unsigned(path, &rotational) == 0) {
if (rotational == 1) {
LMI_DiskDrive_Set_DiskType(&lmi_hdd,
@@ -163,10 +160,10 @@ static CMPIStatus LMI_DiskDriveEnumInstances(
LMI_DiskDrive_DiskType_Unknown);
}
- if (basename[0] == 'h') {
+ if (lsblk_hdds[i].basename[0] == 'h') {
LMI_DiskDrive_Set_InterconnectType(&lmi_hdd,
LMI_DiskDrive_InterconnectType_ATA);
- } else if (basename[0] == 's') {
+ } else if (lsblk_hdds[i].basename[0] == 's') {
/* TODO: What about SAS? */
LMI_DiskDrive_Set_InterconnectType(&lmi_hdd,
LMI_DiskDrive_InterconnectType_SATA);