Skip to content

Commit

Permalink
Merge pull request #76 from NicholasCJL/develop
Browse files Browse the repository at this point in the history
Updated code for Device creation for nvme drives following smartmontools update
  • Loading branch information
ralequi committed Oct 25, 2023
2 parents 1c7d32c + a2f0f3b commit 82e8d0c
Show file tree
Hide file tree
Showing 7 changed files with 602 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pySMART/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -990,7 +990,7 @@ class members, including the SMART attribute table and self-test log.
# Get Tests
for test in self.if_attributes.tests:
self.tests.append(TestEntry('nvme', test.num, test.description, test.status, test.powerOnHours,
test.failingLBA, nsid=test.nsid, sct=test.sct, code=test.code, remain=100-test.progress))
test.failingLBA, nsid=test.nsid, segment=test.seg, sct=test.sct, code=test.code, remain=100-test.progress))

# Set running test
if any(test.status == 'Running' for test in self.if_attributes.tests):
Expand Down
39 changes: 30 additions & 9 deletions pySMART/interface/nvme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,20 +433,22 @@ class NvmeSelfTest(object):
powerOnHours (int): The power on hours
failingLBA (Optional[int]): The failing LBA
nsid (Optional[int]): The namespace ID
seg (Optional[int]): Manufacturer-specific self-test segment number
sct (Optional[str]): The SCT
code (Optional[str]): The code
progress (int): The progress of the test. Defaults to 100%
"""

def __init__(self, num: int, description: str, status: str, powerOnHours: int, failingLBA: Optional[int] = None, nsid: Optional[int] = None, sct: Optional[str] = None, code: Optional[str] = None, progress: int = 100):
def __init__(self, num: int, description: str, status: str, powerOnHours: int, failingLBA: Optional[int] = None, nsid: Optional[int] = None, seg: Optional[int] = None, sct: Optional[str] = None, code: Optional[str] = None, progress: int = 100):

self.num: int = num
self.description: str = description
self.status: str = status
self.powerOnHours: int = powerOnHours
self.failingLBA: Optional[int] = failingLBA
self.nsid: Optional[int] = nsid
self.seg: Optional[int] = seg
self.sct: Optional[str] = sct
self.code: Optional[str] = code
self.progress: int = progress
Expand All @@ -458,15 +460,29 @@ def __repr__(self):
# Example smartctl output
# Self-test Log (NVMe Log 0x06)
# Self-test status: Extended self-test in progress (28% completed)
# Num Test_Description Status Power_on_Hours Failing_LBA NSID SCT Code
# 0 Extended Completed without error 3441 - - - -
return ("{0:>2} {1:18}{2:29}{3:16}{4:13}{5:5}{6:4}{7:4}".format(
# Num Test_Description Status Power_on_Hours Failing_LBA NSID Seg SCT Code
# 0 Extended Completed without error 3441 - - - - -
if self.seg is not None:
# for backwards compatibility
return ("{0:>2} {1:18}{2:29}{3:16}{4:13}{5:5}{6:4}{7:4}".format(
self.num,
self.description,
self.status,
self.powerOnHours,
self.failingLBA,
self.nsid,
self.sct,
self.code
))

return ("{0:>2} {1:18}{2:29}{3:16}{4:>13}{5:>5}{6:>4}{7:>4}{8:>4}".format(
self.num,
self.description,
self.status,
self.powerOnHours,
self.failingLBA,
self.nsid,
self.seg,
self.sct,
self.code
))
Expand Down Expand Up @@ -688,10 +704,10 @@ def parse(self, data: Iterator[str]) -> None:
# Example smartctl output
# Self-test Log (NVMe Log 0x06)
# Self-test status: Extended self-test in progress (28% completed)
# Num Test_Description Status Power_on_Hours Failing_LBA NSID SCT Code
# 0 Extended Completed without error 3441 - - - -
# Num Test_Description Status Power_on_Hours Failing_LBA NSID Seg SCT Code
# 0 Extended Completed without error 3441 - - - - -
nvme_entry_regex = re.compile(
r'^[#\s]*(\d+)\s{2,}(.*[^\s])\s{2,}(.*[^\s])\s{2,}(\d+)\s{2,}(.*[^\s])\s{2,}(.*[^\s])\s{2,}(.*[^\s])\s{2,}(.*)$')
r'^[#\s]*(\d+)\s{2,}(.*[^\s])\s{2,}(.*[^\s])\s{2,}(\d+)\s{2,}(.*?[^\s])\s{2,}(.*?[^\s])(?:\s{2,}(.*[^\s]))?\s{2,}(.*[^\s])\s{2,}(.*)$')

line = next(data)

Expand Down Expand Up @@ -745,8 +761,12 @@ def parse(self, data: Iterator[str]) -> None:
if match.group(6) != '-':
nsid = int(match.group(6))

sct = match.group(7)
code = match.group(8)
seg = None
if match.group(7) is not None and match.group(7) != '-':
seg = int(match.group(7))

sct = match.group(8)
code = match.group(9)

test = NvmeSelfTest(
num=num,
Expand All @@ -755,6 +775,7 @@ def parse(self, data: Iterator[str]) -> None:
powerOnHours=powerOnHours,
failingLBA=failingLBA,
nsid=nsid,
seg=seg,
sct=sct,
code=code
)
Expand Down
7 changes: 4 additions & 3 deletions pySMART/testentry.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,16 @@ def __str__(self):
# Example smartctl output
# Self-test Log (NVMe Log 0x06)
# Self-test status: Extended self-test in progress (28% completed)
# Num Test_Description Status Power_on_Hours Failing_LBA NSID SCT Code
# 0 Extended Completed without error 3441 - - - -
return ("{0:^4} {1:<18}{2:<29}{3:>14}{4:>13}{5:>6}{6:>4}{7:>5}".format(
# Num Test_Description Status Power_on_Hours Failing_LBA NSID Seg SCT Code
# 0 Extended Completed without error 3441 - - - - -
return ("{0:^4} {1:<18}{2:<29}{3:>14}{4:>13}{5:>6}{6:>4}{7:>4}{8:>5}".format(
self.num,
self.type,
self.status,
self.hours,
self.LBA if self.LBA is not None else '-',
self.nsid if self.LBA is not None else '-',
self.segment if self.segment is not None else '-',
self.sct if self.LBA is not None else '-',
self.code if self.LBA is not None else '-'
))
Expand Down
76 changes: 76 additions & 0 deletions tests/dataset/singletests/nvme_11_issue_75/_-d_nvme_--all__dev_sda
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
smartctl 7.4 2023-08-01 r5530 [x86_64-linux-6.5.6-200.fc38.x86_64] (local build)
Copyright (C) 2002-23, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Number: KBG30ZMV256G TOSHIBA
Serial Number: 68APC048P12P
Firmware Version: ADHA0101
PCI Vendor/Subsystem ID: 0x1179
IEEE OUI Identifier: 0x00080d
Controller ID: 0
NVMe Version: 1.2.1
Number of Namespaces: 1
Namespace 1 Size/Capacity: 256.060.514.304 [256 GB]
Namespace 1 Formatted LBA Size: 512
Namespace 1 IEEE EUI-64: 00080d 040017b710
Local Time is: Tue Oct 17 10:11:33 2023 CEST
Firmware Updates (0x12): 1 Slot, no Reset required
Optional Admin Commands (0x0017): Security Format Frmw_DL Self_Test
Optional NVM Commands (0x0017): Comp Wr_Unc DS_Mngmt Sav/Sel_Feat
Log Page Attributes (0x02): Cmd_Eff_Lg
Maximum Data Transfer Size: 512 Pages
Warning Comp. Temp. Threshold: 82 Celsius
Critical Comp. Temp. Threshold: 85 Celsius

Supported Power States
St Op Max Active Idle RL RT WL WT Ent_Lat Ex_Lat
0 + 3.30W - - 0 0 0 0 0 0
1 + 2.70W - - 1 1 1 1 0 0
2 + 2.30W - - 2 2 2 2 0 0
3 - 0.0500W - - 4 4 4 4 8000 32000
4 - 0.0050W - - 4 4 4 4 8000 40000

Supported LBA Sizes (NSID 0x1)
Id Fmt Data Metadt Rel_Perf
0 - 4096 0 0
1 + 512 0 3

=== START OF SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

SMART/Health Information (NVMe Log 0x02)
Critical Warning: 0x00
Temperature: 48 Celsius
Available Spare: 100%
Available Spare Threshold: 10%
Percentage Used: 33%
Data Units Read: 35.495.552 [18,1 TB]
Data Units Written: 41.930.020 [21,4 TB]
Host Read Commands: 698.861.199
Host Write Commands: 1.134.862.706
Controller Busy Time: 16.624
Power Cycles: 1.639
Power On Hours: 10.188
Unsafe Shutdowns: 106
Media and Data Integrity Errors: 0
Error Information Log Entries: 2.888
Warning Comp. Temperature Time: 0
Critical Comp. Temperature Time: 0
Temperature Sensor 1: 48 Celsius
Thermal Temp. 1 Transition Count: 6122
Thermal Temp. 2 Transition Count: 3522
Thermal Temp. 1 Total Time: 74418
Thermal Temp. 2 Total Time: 7241

Error Information (NVMe Log 0x01, 16 of 64 entries)
Num ErrCount SQId CmdId Status PELoc LBA NSID VS Message
0 2888 0 0x0015 0xc005 0x028 - 0 - Invalid Field in Command

Self-test Log (NVMe Log 0x06)
Self-test status: No self-test in progress
Num Test_Description Status Power_on_Hours Failing_LBA NSID Seg SCT Code
0 Extended Completed without error 8754 - - - - -
1 Short Completed without error 8754 - - - - -
2 Extended Completed without error 8738 - - - - -
3 Short Completed without error 8737 - - - - -

Loading

0 comments on commit 82e8d0c

Please sign in to comment.