nvme/identify: allow negative Celsius temperatures

The original temperature values are all in (unsigned) Kelvin and cannot
be negative due to the laws of physics, but when we convert these
temperatures to Celsius, they can be negative.  Fix the printf
specifiers and calculations to take this into account.

Change-Id: I0326b96bf71137a5c1cdaf068ab6bcd91d8411b9
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/408907
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Maciej Szwed <maciej.szwed@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2018-04-24 17:43:31 -07:00 committed by Ben Walker
parent 080a301d8f
commit dbcc9c1e4b

View File

@ -1103,12 +1103,12 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport
health_page.critical_warning.bits.read_only ? "Yes" : "No");
printf(" Volatile Memory Backup: %s\n",
health_page.critical_warning.bits.volatile_memory_backup ? "WARNING" : "OK");
printf("Current Temperature: %u Kelvin (%u Celsius)\n",
printf("Current Temperature: %u Kelvin (%d Celsius)\n",
health_page.temperature,
health_page.temperature - 273);
printf("Temperature Threshold: %u Kelvin (%u Celsius)\n",
(int)health_page.temperature - 273);
printf("Temperature Threshold: %u Kelvin (%d Celsius)\n",
features[SPDK_NVME_FEAT_TEMPERATURE_THRESHOLD].result,
features[SPDK_NVME_FEAT_TEMPERATURE_THRESHOLD].result - 273);
(int)features[SPDK_NVME_FEAT_TEMPERATURE_THRESHOLD].result - 273);
printf("Available Spare: %u%%\n", health_page.available_spare);
printf("Available Spare Threshold: %u%%\n", health_page.available_spare_threshold);
printf("Life Percentage Used: %u%%\n", health_page.percentage_used);
@ -1146,9 +1146,9 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport
printf("Critical Temperature Time: %u minutes\n", health_page.critical_temp_time);
for (i = 0; i < 8; i++) {
if (health_page.temp_sensor[i] != 0) {
printf("Temperature Sensor %d: %u Kelvin (%u Celsius)\n",
printf("Temperature Sensor %d: %u Kelvin (%d Celsius)\n",
i + 1, health_page.temp_sensor[i],
health_page.temp_sensor[i] - 273);
(int)health_page.temp_sensor[i] - 273);
}
}
printf("\n");
@ -1169,13 +1169,13 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_transport
printf("==================================\n");
printf("Minimum Thermal Management Temperature: ");
if (cdata->mntmt) {
printf("%u Kelvin (%u Celsius)\n", cdata->mntmt, cdata->mntmt - 273);
printf("%u Kelvin (%d Celsius)\n", cdata->mntmt, (int)cdata->mntmt - 273);
} else {
printf("Not Reported\n");
}
printf("Maximum Thermal Managment Temperature: ");
if (cdata->mxtmt) {
printf("%u Kelvin (%u Celsius)\n", cdata->mxtmt, cdata->mxtmt - 273);
printf("%u Kelvin (%d Celsius)\n", cdata->mxtmt, (int)cdata->mxtmt - 273);
} else {
printf("Not Reported\n");
}