@@ -22,6 +22,7 @@ package nvme
2222import (
2323 "encoding/binary"
2424 "fmt"
25+ "math/rand"
2526 "path"
2627 "regexp"
2728 "strconv"
@@ -33,6 +34,7 @@ import (
3334 "github.com/google/uuid"
3435
3536 "github.com/NearNodeFlash/nnf-ec/internal/switchtec/pkg/switchtec"
37+ "github.com/NearNodeFlash/nnf-ec/pkg/ec"
3638 sf "github.com/NearNodeFlash/nnf-ec/pkg/rfsf/pkg/models"
3739)
3840
@@ -1169,6 +1171,31 @@ func InterpretSmartLog(log *SmartLog) sf.ResourceState {
11691171 return sf .ENABLED_RST // Healthy
11701172}
11711173
1174+ func MangleSmartLog (log * SmartLog ) {
1175+
1176+ // Occaionally managle the smart log data
1177+ if rand .Intn (100 ) < 10 { // 10% chance of simulating critical condition
1178+ warningType := rand .Intn (6 )
1179+ switch warningType {
1180+ case 0 :
1181+ log .CriticalWarning .SpareCapacity = 1
1182+ log .AvailableSpare = 5 // Below threshold
1183+ case 1 :
1184+ log .CriticalWarning .Temperature = 1
1185+ log .CompositeTemperature = 358 // ~85°C
1186+ case 2 :
1187+ log .CriticalWarning .Degraded = 1
1188+ case 3 :
1189+ log .CriticalWarning .ReadOnly = 1
1190+ case 4 :
1191+ log .CriticalWarning .BackupFailed = 1
1192+ case 5 :
1193+ log .CriticalWarning .PersistentMemoryRegionReadOnly = 1
1194+ }
1195+ }
1196+
1197+ }
1198+
11721199// Log contstants
11731200const (
11741201 LogCdw10LogPageIdentiferMask = 0xFF
@@ -1224,3 +1251,26 @@ func (dev *Device) getLog(logPageIdentifier uint8, logSpecificField uint8, retai
12241251 return dev .ops .submitAdminPassthru (dev , & cmd , buf )
12251252
12261253}
1254+
1255+ // LogSmartLog outputs the SMART log data in a structured way for logging.
1256+ func LogSmartLog (log ec.Logger , smartLog * SmartLog , context ... interface {}) {
1257+ if smartLog == nil {
1258+ log .Error (nil , "SMART log is nil" , context ... )
1259+ return
1260+ }
1261+ log .Info ("SMART log data" ,
1262+ append (context ,
1263+ "criticalWarning.spareCapacity" , smartLog .CriticalWarning .SpareCapacity ,
1264+ "criticalWarning.temperature" , smartLog .CriticalWarning .Temperature ,
1265+ "criticalWarning.degraded" , smartLog .CriticalWarning .Degraded ,
1266+ "criticalWarning.readOnly" , smartLog .CriticalWarning .ReadOnly ,
1267+ "criticalWarning.backupFailed" , smartLog .CriticalWarning .BackupFailed ,
1268+ "criticalWarning.persistentMemoryRegionReadOnly" , smartLog .CriticalWarning .PersistentMemoryRegionReadOnly ,
1269+ "availableSpare" , smartLog .AvailableSpare ,
1270+ "availableSpareThreshold" , smartLog .AvailableSpareThreshold ,
1271+ "percentageUsed" , smartLog .PercentageUsed ,
1272+ "compositeTemperature" , smartLog .CompositeTemperature ,
1273+ "mediaErrorsLo" , smartLog .MediaErrorsLo ,
1274+ "numberErrorLogEntriesLo" , smartLog .NumberErrorLogEntriesLo ,
1275+ )... )
1276+ }
0 commit comments