Skip to content

Commit

Permalink
For consistency, NVME should always be NVMe.
Browse files Browse the repository at this point in the history
  • Loading branch information
TkTech committed Jun 23, 2024
1 parent e3f06ce commit d309029
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 40 deletions.
4 changes: 2 additions & 2 deletions docs/guide/discovery.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ For our example system, this would give us:

.. code-block:: python
LinuxNVMEDevice(path="/dev/nvme0n1")
LinuxNVMeDevice(path="/dev/nvme0n1")
LinuxSCSIDevice(path="/dev/sdb")
LinuxSCSIDevice(path="/dev/sdc")
LinuxNVMEDevice(path="/dev/nvme1n1")
LinuxNVMeDevice(path="/dev/nvme1n1")
LinuxSCSIDevice(path="/dev/sda")
Expand Down
10 changes: 5 additions & 5 deletions docs/guide/low_level.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ type of device you have:
from smartie.device import get_device
from smartie.scsi import SCSIDevice
from smartie.nvme import NVMEDevice
from smartie.nvme import NVMeDevice
with get_device('\\\\.\\PhysicalDrive0') as device:
if isinstance(device, SCSIDevice):
print('SCSI device')
elif isinstance(device, NVMEDevice):
elif isinstance(device, NVMeDevice):
print('NVMe device')
else:
print('Unknown device type')
Expand Down Expand Up @@ -83,10 +83,10 @@ To send an NVMe IDENTIFY command to a device:
with get_device('/dev/nvme0') as device:
# The structure that will be populated with the response.
data = structures.NVMEIdentifyResponse()
data = structures.NVMeIdentifyResponse()
device.issue_admin_command(
structures.NVMEAdminCommand(
opcode=structures.NVMEAdminCommands.IDENTIFY,
structures.NVMeAdminCommand(
opcode=structures.NVMeAdminCommands.IDENTIFY,
addr=ctypes.addressof(data),
data_len=ctypes.sizeof(data),
cdw10=1
Expand Down
8 changes: 4 additions & 4 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ from a device:
with get_device('/dev/nvme0') as device:
# The structure that will be populated with the response.
data = structures.NVMEIdentifyResponse()
data = structures.NVMeIdentifyResponse()
device.issue_admin_command(
structures.NVMEAdminCommand(
opcode=structures.NVMEAdminCommands.IDENTIFY,
structures.NVMeAdminCommand(
opcode=structures.NVMeAdminCommands.IDENTIFY,
addr=ctypes.addressof(data),
data_len=ctypes.sizeof(data),
cdw10=1
Expand All @@ -108,7 +108,7 @@ Supported Platforms
* - OS
- Device Discovery
- SCSI/ATA Supported
- NVME Supported
- NVMe Supported
* - Linux
- Yes
- Yes
Expand Down
10 changes: 5 additions & 5 deletions smartie/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from smartie.database import DRIVE_DATABASE, get_matching_drive_entries
from smartie.device import get_all_devices, get_device
from smartie.nvme import NVMEDevice
from smartie.nvme import NVMeDevice
from smartie.scsi import SCSIDevice
from smartie.structures import c_uint128, embed_bytes
from smartie.util import grouper_it
Expand Down Expand Up @@ -155,11 +155,11 @@ def blocks_to_gb(blocks: int) -> float:
str(entry.threshold),
entry.unit.name,
)
elif isinstance(device, NVMEDevice):
elif isinstance(device, NVMeDevice):
smart_table.add_column("Name", style="magenta")
smart_table.add_column("Value", style="green", justify="right")

smart,_ = device.smart()
smart, _ = device.smart()

# We only show a selection of attributes, as the full list is
# not terribly useful.
Expand Down Expand Up @@ -254,7 +254,7 @@ def dump_command(path: str, command: str, display: str = "pretty"):
return

structure = result()[0]
elif isinstance(device, NVMEDevice):
elif isinstance(device, NVMeDevice):
result = {"identify": device.identify, "smart": device.smart}.get(
command
)
Expand Down Expand Up @@ -396,7 +396,7 @@ def api_get_command(path: str):
"unit": entry.unit.name,
"flags": entry.flags,
}
elif isinstance(device, NVMEDevice):
elif isinstance(device, NVMeDevice):
result["smart"] = device.smart_table

print(json.dumps(result, indent=4, sort_keys=True))
4 changes: 2 additions & 2 deletions smartie/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ def get_device(path: Union[Path, str]) -> Device:

return WindowsSCSIDevice(path)
elif system == "Linux":
from smartie.nvme.linux import LinuxNVMEDevice
from smartie.nvme.linux import LinuxNVMeDevice
from smartie.scsi.linux import LinuxSCSIDevice

if "nvme" in str(path):
return LinuxNVMEDevice(path)
return LinuxNVMeDevice(path)
return LinuxSCSIDevice(path)
else:
raise NotImplementedError("Device not implemented for this platform.")
Expand Down
24 changes: 12 additions & 12 deletions smartie/nvme/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__all__ = ("NVMEDevice",)
__all__ = ("NVMeDevice",)
import abc
import sys
import ctypes
Expand All @@ -9,9 +9,9 @@
from smartie.device import Device
from smartie.nvme.errors import NVMeStatusFieldError
from smartie.nvme.structures import (
NVMEAdminCommand,
NVMEAdminCommands,
NVMEIdentifyResponse,
NVMeAdminCommand,
NVMeAdminCommands,
NVMeIdentifyResponse,
NVMeCQEStatusField,
SMARTPageResponse,
)
Expand Down Expand Up @@ -43,7 +43,7 @@ class NVMeResponse:
#: The status field data returned by the device.
status_field: Optional[NVMeCQEStatusField]
#: The command issued to the device.
command: Union[NVMEAdminCommand,]
command: Union[NVMeAdminCommand,]
#: Keep aligned with SCSIResponse. Not used for now.
#: The actual number of bytes transferred.
bytes_transferred: Optional[int]
Expand All @@ -58,7 +58,7 @@ def __bool__(self):
return self.succeeded


class NVMEDevice(Device, abc.ABC):
class NVMeDevice(Device, abc.ABC):
@classmethod
def parse_status_field(cls, status_blob) -> Optional[NVMeCQEStatusField]:
"""
Expand All @@ -81,15 +81,15 @@ def parse_status_field(cls, status_blob) -> Optional[NVMeCQEStatusField]:
def issue_admin_command(self, command):
pass

def identify(self) -> Tuple[NVMEIdentifyResponse, NVMeResponse]:
def identify(self) -> Tuple[NVMeIdentifyResponse, NVMeResponse]:
"""
Returns the parsed IDENTIFY results for CNS 01h, which contains
the controller information.
"""
data = NVMEIdentifyResponse()
data = NVMeIdentifyResponse()
response = self.issue_admin_command(
NVMEAdminCommand(
opcode=NVMEAdminCommands.IDENTIFY,
NVMeAdminCommand(
opcode=NVMeAdminCommands.IDENTIFY,
addr=ctypes.addressof(data),
data_len=ctypes.sizeof(data),
cdw10=1,
Expand All @@ -116,8 +116,8 @@ def read_log_page(
self, log_page_id: int, data: ctypes.Structure
) -> tuple[ctypes.Structure, NVMeResponse]:
response = self.issue_admin_command(
NVMEAdminCommand(
opcode=NVMEAdminCommands.GET_LOG_PAGE,
NVMeAdminCommand(
opcode=NVMeAdminCommands.GET_LOG_PAGE,
addr=ctypes.addressof(data),
data_len=ctypes.sizeof(data),
nsid=0xFFFFFFFF,
Expand Down
10 changes: 5 additions & 5 deletions smartie/nvme/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import os

from smartie.nvme import (
NVMEDevice,
NVMeDevice,
NVMeResponse,
local_byteorder,
)
from smartie.platforms.linux import get_libc
from smartie.nvme.structures import IOCTL_NVME_ADMIN_CMD, NVMEAdminCommand
from smartie.nvme.structures import IOCTL_NVMe_ADMIN_CMD, NVMeAdminCommand


class LinuxNVMEDevice(NVMEDevice):
class LinuxNVMeDevice(NVMeDevice):
"""
Represents an NVMe device on a Linux system.
"""
Expand All @@ -28,9 +28,9 @@ def __exit__(self, exc_type, exc_val, exc_tb):
self.fd = None
return False

def issue_admin_command(self, command: NVMEAdminCommand) -> NVMeResponse:
def issue_admin_command(self, command: NVMeAdminCommand) -> NVMeResponse:
result = get_libc().ioctl(
self.fd, IOCTL_NVME_ADMIN_CMD, ctypes.byref(command)
self.fd, IOCTL_NVMe_ADMIN_CMD, ctypes.byref(command)
)

return NVMeResponse(
Expand Down
10 changes: 5 additions & 5 deletions smartie/nvme/structures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""
This file contains the various low-level structure definitions used for sending
and receiving NVME commands, as well as the structures required for
and receiving NVMe commands, as well as the structures required for
platform-specific APIs.
"""
import ctypes
Expand All @@ -9,15 +9,15 @@
from smartie.structures import c_uint128

#: IOCTL for NVMe Admin commands on Linux.
IOCTL_NVME_ADMIN_CMD = 0xC0484E41
IOCTL_NVMe_ADMIN_CMD = 0xC0484E41


class NVMEAdminCommands(enum.IntEnum):
class NVMeAdminCommands(enum.IntEnum):
GET_LOG_PAGE = 0x02
IDENTIFY = 0x06


class NVMEAdminCommand(ctypes.Structure):
class NVMeAdminCommand(ctypes.Structure):
_pack_ = 1
_fields_ = [
("opcode", ctypes.c_ubyte),
Expand Down Expand Up @@ -55,7 +55,7 @@ class NVMeCQEStatusField(ctypes.Structure):
]


class NVMEIdentifyResponse(ctypes.Structure):
class NVMeIdentifyResponse(ctypes.Structure):
_fields_ = [
("vendor_id", ctypes.c_uint16),
("ssvid", ctypes.c_uint16),
Expand Down

0 comments on commit d309029

Please sign in to comment.