Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External drive connected via USB does not work #83

Open
Galdanwing opened this issue Feb 28, 2024 · 5 comments
Open

External drive connected via USB does not work #83

Galdanwing opened this issue Feb 28, 2024 · 5 comments
Assignees

Comments

@Galdanwing
Copy link

Describe the bug
I tried to connect an external ssd via USB, but it does not get detected. calling smartctl from the cmdline does detect it.

Raw outputs

Python 3.12.2 (main, Feb  7 2024, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.20.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: from pySMART import Device, SMARTCTL

In [2]: SMARTCTL.sudo = True

In [3]: device = Device("/dev/sda")

In [4]: device.all_attributes()
This device does not support SMART attributes.
  • smartctl --scan-open
sudo smartctl --scan-open
/dev/sda -d sntasmedia # /dev/sda [USB NVMe ASMedia], NVMe device
/dev/nvme0 -d nvme # /dev/nvme0, NVMe device
  • smartctl --all <problematic device> # Example: smartctl --all /dev/nvme0
sudo smartctl /dev/sda -a 
smartctl 7.4 2023-08-01 r5530 [x86_64-linux-6.7.5-200.fc39.x86_64] (local build)
Copyright (C) 2002-23, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Number:                       Samsung Portable SSD T7 Shield
Serial Number:                      S76ZNJ0X101040A
Firmware Version:                   FXI72P2Q
PCI Vendor/Subsystem ID:            0x144d
IEEE OUI Identifier:                0x002538
Total NVM Capacity:                 4,000,787,030,016 [4.00 TB]
Unallocated NVM Capacity:           0
Controller ID:                      5
NVMe Version:                       1.4
Number of Namespaces:               1
Namespace 1 Size/Capacity:          4,000,787,030,016 [4.00 TB]
Namespace 1 Utilization:            785,408,978,944 [785 GB]
Namespace 1 Formatted LBA Size:     512
Local Time is:                      Wed Feb 28 14:00:44 2024 CET
Firmware Updates (0x16):            3 Slots, no Reset required
Optional Admin Commands (0x0007):   Security Format Frmw_DL
Optional NVM Commands (0x001d):     Comp DS_Mngmt Wr_Zero Sav/Sel_Feat
Log Page Attributes (0x0f):         S/H_per_NS Cmd_Eff_Lg Ext_Get_Lg Telmtry_Lg
Maximum Data Transfer Size:         512 Pages
Warning  Comp. Temp. Threshold:     75 Celsius
Critical Comp. Temp. Threshold:     80 Celsius
Namespace 1 Features (0x10):        NP_Fields

Supported Power States
St Op     Max   Active     Idle   RL RT WL WT  Ent_Lat  Ex_Lat
 0 +     4.83W       -        -    0  0  0  0        0       0
 1 +     3.54W       -        -    1  1  1  1        0       0
 2 +     3.04W       -        -    2  2  2  2        0     500
 3 -   0.0500W       -        -    3  3  3  3      210    1200

Supported LBA Sizes (NSID 0x1)
Id Fmt  Data  Metadt  Rel_Perf
 0 +     512       0         0

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

SMART/Health Information (NVMe Log 0x02)
Critical Warning:                   0x00
Temperature:                        28 Celsius
Available Spare:                    100%
Available Spare Threshold:          10%
Percentage Used:                    0%
Data Units Read:                    51,346,626 [26.2 TB]
Data Units Written:                 2,313,409 [1.18 TB]
Host Read Commands:                 242,864,448
Host Write Commands:                9,230,694
Controller Busy Time:               550
Power Cycles:                       31
Power On Hours:                     172
Unsafe Shutdowns:                   27
Media and Data Integrity Errors:    0
Error Information Log Entries:      0
Warning  Comp. Temperature Time:    0
Critical Comp. Temperature Time:    0
Temperature Sensor 1:               28 Celsius
Temperature Sensor 2:               28 Celsius

Warning: NVMe Get Log truncated to 0x200 bytes, 0x200 bytes zero filled
Error Information (NVMe Log 0x01, 16 of 64 entries)
No Errors Logged

Self-tests not supported

Environmental setup:

  • Complete smartctl version: smartctl 7.4 2023-08-01 r5530 [x86_64-linux-6.7.5-200.fc39.x86_64] (local build)
  • Py-SMART version: pySMART 1.3.0

Additional context
Add any other context about the problem here.

@amotin
Copy link

amotin commented Feb 28, 2024

Not saying anything about py-SMART, but smartctl has been known for using bridge specific commands to access SMART data behind USB bridges. There is no NVMe to SCSI command pass-through standard, so if the USB bridge does not emulate SCSI SMART, there is no standard way to get SMART from the NVMe device behind a USB bridge.

@ralequi
Copy link
Collaborator

ralequi commented Feb 28, 2024

Hi @Galdanwing ,

The function you are trying to call is this:

py-SMART/pySMART/device.py

Lines 563 to 579 in fbe13ae

def all_attributes(self, print_fn=print):
"""
Prints the entire SMART attribute table, in a format similar to
the output of smartctl.
allows usage of custom print function via parameter print_fn by default uses print
"""
header_printed = False
for attr in self.attributes:
if attr is not None:
if not header_printed:
print_fn("{0:>3} {1:24}{2:4}{3:4}{4:4}{5:9}{6:8}{7:12}{8}"
.format('ID#', 'ATTRIBUTE_NAME', 'CUR', 'WST', 'THR', 'TYPE', 'UPDATED', 'WHEN_FAIL',
'RAW'))
header_printed = True
print_fn(attr)
if not header_printed:
print_fn('This device does not support SMART attributes.')

This function should be deprecated already as what it does is to print old ATA attributes.

I don't know if that kind of error should happen anyway, but, normally, in a non-ATA device what you will get is an empty printed list. I'll try to check your output anyway

@Galdanwing
Copy link
Author

Not saying anything about py-SMART, but smartctl has been known for using bridge specific commands to access SMART data behind USB bridges. There is no NVMe to SCSI command pass-through standard, so if the USB bridge does not emulate SCSI SMART, there is no standard way to get SMART from the NVMe device behind a USB bridge.

Hi, I'm kind of confused. Am I not showing that I am able to get the data via just calling it directly showing that it is able to get that data?

@Galdanwing
Copy link
Author

Hi @Galdanwing ,

The function you are trying to call is this:

py-SMART/pySMART/device.py

Lines 563 to 579 in fbe13ae

def all_attributes(self, print_fn=print):
"""
Prints the entire SMART attribute table, in a format similar to
the output of smartctl.
allows usage of custom print function via parameter print_fn by default uses print
"""
header_printed = False
for attr in self.attributes:
if attr is not None:
if not header_printed:
print_fn("{0:>3} {1:24}{2:4}{3:4}{4:4}{5:9}{6:8}{7:12}{8}"
.format('ID#', 'ATTRIBUTE_NAME', 'CUR', 'WST', 'THR', 'TYPE', 'UPDATED', 'WHEN_FAIL',
'RAW'))
header_printed = True
print_fn(attr)
if not header_printed:
print_fn('This device does not support SMART attributes.')

This function should be deprecated already as what it does is to print old ATA attributes.

I don't know if that kind of error should happen anyway, but, normally, in a non-ATA device what you will get is an empty printed list. I'll try to check your output anyway

If you point me in the right way, I could try and contribute support for it, if you think that's valuable

@ralequi
Copy link
Collaborator

ralequi commented Mar 4, 2024

Not saying anything about py-SMART, but smartctl has been known for using bridge specific commands to access SMART data behind USB bridges. There is no NVMe to SCSI command pass-through standard, so if the USB bridge does not emulate SCSI SMART, there is no standard way to get SMART from the NVMe device behind a USB bridge.

Hi, I'm kind of confused. Am I not showing that I am able to get the data via just calling it directly showing that it is able to get that data?

AFAIK the output should be getting correctly readed. See the section SMART/Health Information (NVMe Log 0x02)

You can try to get this info by accessing this:

py-SMART/pySMART/device.py

Lines 246 to 250 in fbe13ae

self.if_attributes: Union[None, NvmeAttributes, AtaAttributes] = None
"""
**(NvmeAttributes):** This object may vary for each device interface attributes.
It will store all data obtained from smartctl
"""

An then, this:

class NvmeAttributes(CommonIface):
"""This class represents the attributes of a NVMe device
Attributes:
criticalWarning : Number of critical warnings
temperature : Temperature in Celsius
availableSpare : Available spare in percentage
availableSpareThreshold : Available spare threshold in percentage
percentageUsed : Data units used in percentage
dataUnitsRead : Data units (sectors) read
bytesRead : Bytes read
dataUnitsWritten : Data units (sectors) written
bytesWritten : Bytes written
hostReadCommands : Host read commands
hostWriteCommands : Host write commands
controllerBusyTime : Controller busy time in minutes
powerCycles : Power on cycles
powerOnHours : Power on hours
unsafeShutdowns : Unsafe shutdowns
integrityErrors : Integrity errors
errorEntries : Error log entries
warningTemperatureTime : Time in minutes at warning temperature
criticalTemperatureTime : Time in minutes at critical temperature
errors : List of errors
"""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants