hw/block/nvme: add smart_critical_warning property
PATCH 1/1 hw/block/nvme: add smart_critical_warning property
There is a very low probability that hitting physical NVMe disk hardware critical warning case, it's hard to write & test a monitor agent service.
For debugging purposes, add a new 'smart_critical_warning' property to emulate this situation.
Test with this patch:
1, append 'smart_critical_warning=16' for nvme parameters. 2, run smartctl in guest
#smartctl -H -l error /dev/nvme0n1
=== START OF SMART DATA SECTION ===
SMART overall-health self-assessment test result: FAILED!
- volatile memory backup device has failed
--- hw/block/nvme.c | 4 ++++ hw/block/nvme.h | 1 + 2 files changed, 5 insertions(+)
hw/block/nvme.c +4 -0
@@ -1215,6 +1215,8 @@ static uint16_t nvme_smart_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, trans_len =MIN (sizeof (smart) - off, buf_len); + smart.critical_warning = n->params.smart_critical_warning; + smart.data_units_read[0 ] =cpu_to_le64 (DIV_ROUND_UP (stats.units_read,1000 )); smart.data_units_written[0] = cpu_to_le64(DIV_ROUND_UP(stats.units_written,
@@ -2824,6 +2826,8 @@ static Property nvme_props[] = {DEFINE_PROP_UINT32 ("aer_max_queued" , NvmeCtrl, params.aer_max_queued,64 ),DEFINE_PROP_UINT8 ("mdts" , NvmeCtrl, params.mdts,7 ),DEFINE_PROP_BOOL ("use-intel-id" , NvmeCtrl, params.use_intel_id, false), +DEFINE_PROP_UINT8 ("smart_critical_warning" , NvmeCtrl, + params.smart_critical_warning,0 ), DEFINE_PROP_END_OF_LIST(), };
hw/block/nvme.h +1 -0
@@ -16,6 +16,7 @@ typedef struct NvmeParams {uint32_t aer_max_queued;uint8_t mdts;bool use_intel_id; +uint8_t smart_critical_warning; } NvmeParams; typedef struct NvmeAsyncEvent {
Signature · 1 line
2.25.1
Quoted 50 lines · zhenwei pi
There is a very low probability that hitting physical NVMe disk hardware critical warning case, it's hard to write & test a monitor agent service.
For debugging purposes, add a new '
smart_critical_warning' property to emulate this situation.Test with this patch:
1, append 'smart_critical_warning=16' for nvme parameters. 2, run smartctl in guest
#smartctl -H -l error/dev/nvme0n1=== START OF SMART DATA SECTION ===
SMART overall-health self-assessment test result: FAILED!
- volatile memory backup device has failedSigned-off-by zhenwei pi <[email protected]>--- hw/block/nvme.c | 4 ++++ hw/block/nvme.h | 1 + 2 files changed, 5 insertions(+)hw/block/nvme.c +4
-0@@ -1215,6 +1215,8 @@ static uint16_t nvme_smart_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, trans_len =MIN (sizeof (smart) - off, buf_len); + smart.critical_warning = n->params.smart_critical_warning; + smart.data_units_read[0 ] =cpu_to_le64 (DIV_ROUND_UP (stats.units_read,1000 )); smart.data_units_written[0] = cpu_to_le64(DIV_ROUND_UP(stats.units_written,@@ -2824,6 +2826,8 @@ static Property nvme_props[] = {DEFINE_PROP_UINT32 ("aer_max_queued" , NvmeCtrl, params.aer_max_queued,64 ),DEFINE_PROP_UINT8 ("mdts" , NvmeCtrl, params.mdts,7 ),DEFINE_PROP_BOOL ("use-intel-id" , NvmeCtrl, params.use_intel_id, false), +DEFINE_PROP_UINT8 ("smart_critical_warning" , NvmeCtrl, + params.smart_critical_warning,0 ), DEFINE_PROP_END_OF_LIST(), };hw/block/nvme.h +0
-0
hw/block/nvme.h typedef struct NvmeParams { · line 22
Quoted 7 lines
hw/block/nvme.h +1
-0@@ -16,6 +16,7 @@ typedef struct NvmeParams {uint32_t aer_max_queued;uint8_t mdts;bool use_intel_id; +uint8_t smart_critical_warning; } NvmeParams; typedef struct NvmeAsyncEvent {
This is an easy way to achieve your goal.
However a better way is to add a QMP command to
change NvmeCtrl->temperature.
See for example tmp105_initfn() in hw/misc/tmp105.c and qmp_tmp105_set_temperature() in tests/qtest/tmp105-test.c.
Regards,
Phil.
Quoted 61 lines · Philippe Mathieu-Daudé
Quoted 50 lines · zhenwei pi
There is a very low probability that hitting physical NVMe disk hardware critical warning case, it's hard to write & test a monitor agent service.
For debugging purposes, add a new '
smart_critical_warning' property to emulate this situation.Test with this patch:
1, append 'smart_critical_warning=16' for nvme parameters. 2, run smartctl in guest
#smartctl -H -l error/dev/nvme0n1=== START OF SMART DATA SECTION ===
SMART overall-health self-assessment test result: FAILED!
- volatile memory backup device has failedSigned-off-by zhenwei pi <[email protected]>--- hw/block/nvme.c | 4 ++++ hw/block/nvme.h | 1 + 2 files changed, 5 insertions(+)hw/block/nvme.c +4
-0@@ -1215,6 +1215,8 @@ static uint16_t nvme_smart_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, trans_len =MIN (sizeof (smart) - off, buf_len); + smart.critical_warning = n->params.smart_critical_warning; + smart.data_units_read[0 ] =cpu_to_le64 (DIV_ROUND_UP (stats.units_read,1000 )); smart.data_units_written[0] = cpu_to_le64(DIV_ROUND_UP(stats.units_written,@@ -2824,6 +2826,8 @@ static Property nvme_props[] = {DEFINE_PROP_UINT32 ("aer_max_queued" , NvmeCtrl, params.aer_max_queued,64 ),DEFINE_PROP_UINT8 ("mdts" , NvmeCtrl, params.mdts,7 ),DEFINE_PROP_BOOL ("use-intel-id" , NvmeCtrl, params.use_intel_id, false), +DEFINE_PROP_UINT8 ("smart_critical_warning" , NvmeCtrl, + params.smart_critical_warning,0 ), DEFINE_PROP_END_OF_LIST(), };hw/block/nvme.h +0
-0hw/block/nvme.h typedef struct NvmeParams { · line 22
Quoted 7 lines
hw/block/nvme.h +1
-0@@ -16,6 +16,7 @@ typedef struct NvmeParams {uint32_t aer_max_queued;uint8_t mdts;bool use_intel_id; +uint8_t smart_critical_warning; } NvmeParams; typedef struct NvmeAsyncEvent {This is an easy way to achieve your goal.
Quoted 6 lines
However a better way is to add a QMP command to
changeNvmeCtrl->temperature.See for example
tmp105_initfn()inhw/misc/tmp105.candqmp_tmp105_set_temperature()intests/qtest/tmp105-test.c.
Nice.
+1 for this approach.
Quoted 65 lines · Klaus Jensen
Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 50 lines · zhenwei pi
There is a very low probability that hitting physical NVMe disk hardware critical warning case, it's hard to write & test a monitor agent service.
For debugging purposes, add a new '
smart_critical_warning' property to emulate this situation.Test with this patch:
1, append 'smart_critical_warning=16' for nvme parameters. 2, run smartctl in guest
#smartctl -H -l error/dev/nvme0n1=== START OF SMART DATA SECTION ===
SMART overall-health self-assessment test result: FAILED!
- volatile memory backup device has failedSigned-off-by zhenwei pi <[email protected]>--- hw/block/nvme.c | 4 ++++ hw/block/nvme.h | 1 + 2 files changed, 5 insertions(+)hw/block/nvme.c +4
-0@@ -1215,6 +1215,8 @@ static uint16_t nvme_smart_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, trans_len =MIN (sizeof (smart) - off, buf_len); + smart.critical_warning = n->params.smart_critical_warning; + smart.data_units_read[0 ] =cpu_to_le64 (DIV_ROUND_UP (stats.units_read,1000 )); smart.data_units_written[0] = cpu_to_le64(DIV_ROUND_UP(stats.units_written,@@ -2824,6 +2826,8 @@ static Property nvme_props[] = {DEFINE_PROP_UINT32 ("aer_max_queued" , NvmeCtrl, params.aer_max_queued,64 ),DEFINE_PROP_UINT8 ("mdts" , NvmeCtrl, params.mdts,7 ),DEFINE_PROP_BOOL ("use-intel-id" , NvmeCtrl, params.use_intel_id, false), +DEFINE_PROP_UINT8 ("smart_critical_warning" , NvmeCtrl, + params.smart_critical_warning,0 ), DEFINE_PROP_END_OF_LIST(), };hw/block/nvme.h +0
-0hw/block/nvme.h typedef struct NvmeParams { · line 22
Quoted 7 lines
hw/block/nvme.h +1
-0@@ -16,6 +16,7 @@ typedef struct NvmeParams {uint32_t aer_max_queued;uint8_t mdts;bool use_intel_id; +uint8_t smart_critical_warning; } NvmeParams; typedef struct NvmeAsyncEvent {This is an easy way to achieve your goal.
However a better way is to add a QMP command to
changeNvmeCtrl->temperature.
Quoted 8 lines
Quoted 3 lines
See for example
tmp105_initfn()inhw/misc/tmp105.candqmp_tmp105_set_temperature()intests/qtest/tmp105-test.c.Nice.
+1 for this approach.
Using QMP command to change NvmeCtrl->temperature only triggers NVME_SMART_TEMPERATURE warning, it's OK to test the work flow of uplayer software, but it's not enough to test all the cases of each warning.
From NVMe version 1.3 to 1.4, a new bit definition has been added(bit 5, Persistent Memory Region has become read-only or unreliable). Before we really hit this warning on a physical disk, we can use QEMU to test this feature(maybe another new feature in the future).
I don't disagree "add a QMP command" solution, but I think QEMU should be able to emulate all of the warnings(not only temperature).
Signature · 1 line
zhenwei pi
Quoted 75 lines · zhenwei pi
Quoted 61 lines · Klaus Jensen
Quoted 60 lines · Philippe Mathieu-Daudé
Quoted 46 lines · zhenwei pi
There is a very low probability that hitting physical NVMe disk hardware critical warning case, it's hard to write & test a monitor agent service.
For debugging purposes, add a new '
smart_critical_warning' property to emulate this situation.Test with this patch:
1, append 'smart_critical_warning=16' for nvme parameters. 2, run smartctl in guest
#smartctl -H -l error/dev/nvme0n1=== START OF SMART DATA SECTION ===
SMART overall-health self-assessment test result: FAILED!
- volatile memory backup device has failedSigned-off-by zhenwei pi <[email protected]>--- hw/block/nvme.c | 4 ++++ hw/block/nvme.h | 1 + 2 files changed, 5 insertions(+)hw/block/nvme.c +4
-0@@ -1215,6 +1215,8 @@ static uint16_t nvme_smart_info(NvmeCtrl *n, uint8_t rae, uint32_t buf_len, trans_len =MIN (sizeof (smart) - off, buf_len); + smart.critical_warning = n->params.smart_critical_warning; + smart.data_units_read[0 ] =cpu_to_le64 (DIV_ROUND_UP (stats.units_read,1000 )); smart.data_units_written[0] = cpu_to_le64(DIV_ROUND_UP(stats.units_written,@@ -2824,6 +2826,8 @@ static Property nvme_props[] = {DEFINE_PROP_UINT32 ("aer_max_queued" , NvmeCtrl, params.aer_max_queued,64 ),DEFINE_PROP_UINT8 ("mdts" , NvmeCtrl, params.mdts,7 ),DEFINE_PROP_BOOL ("use-intel-id" , NvmeCtrl, params.use_intel_id, false), +DEFINE_PROP_UINT8 ("smart_critical_warning" , NvmeCtrl, + params.smart_critical_warning,0 ), DEFINE_PROP_END_OF_LIST(), };hw/block/nvme.h +0
-0hw/block/nvme.h typedef struct NvmeParams { · line 22
Quoted 7 lines
hw/block/nvme.h +1
-0@@ -16,6 +16,7 @@ typedef struct NvmeParams {uint32_t aer_max_queued;uint8_t mdts;bool use_intel_id; +uint8_t smart_critical_warning; } NvmeParams; typedef struct NvmeAsyncEvent {This is an easy way to achieve your goal.
However a better way is to add a QMP command to
changeNvmeCtrl->temperature.Quoted 8 lines
Quoted 3 lines
See for example
tmp105_initfn()inhw/misc/tmp105.candqmp_tmp105_set_temperature()intests/qtest/tmp105-test.c.Nice.
+1 for this approach.
Using QMP command to change
NvmeCtrl->temperatureonly triggersNVME_SMART_TEMPERATUREwarning, it's OK to test the work flow of uplayer software, but it's not enough to test all the cases of each warning.
Quoted 8 lines
From NVMe version 1.3 to 1.4, a new bit definition has been
added(bit 5, Persistent Memory Region has become read-only or unreliable). Before we really hit this warning on a physical disk, we can use QEMU to test this feature(maybe another new feature in the future).I don't disagree "add a QMP command" solution, but I think QEMU should be able to emulate all of the warnings(not only temperature).
I think Philippe just made an example. It can be a QMP command that sets the critical warning field.