storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/smart/types.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2016-2020 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package smart
    18  
    19  import "math/big"
    20  
    21  // Defined in <linux/nvme_ioctl.h>
    22  //nolint:structcheck,deadcode
    23  type nvmePassthruCommand struct {
    24  	opcode      uint8
    25  	flags       uint8
    26  	rsvd1       uint16
    27  	nsid        uint32
    28  	cdw2        uint32
    29  	cdw3        uint32
    30  	metadata    uint64
    31  	addr        uint64
    32  	metadataLen uint32
    33  	dataLen     uint32
    34  	cdw10       uint32
    35  	cdw11       uint32
    36  	cdw12       uint32
    37  	cdw13       uint32
    38  	cdw14       uint32
    39  	cdw15       uint32
    40  	timeoutMS   uint32
    41  	result      uint32
    42  } // 72 bytes
    43  
    44  type nvmeIdentPowerState struct {
    45  	MaxPower        uint16 // Centiwatts
    46  	Rsvd2           uint8
    47  	Flags           uint8
    48  	EntryLat        uint32 // Microseconds
    49  	ExitLat         uint32 // Microseconds
    50  	ReadTput        uint8
    51  	ReadLat         uint8
    52  	WriteTput       uint8
    53  	WriteLat        uint8
    54  	IdlePower       uint16
    55  	IdleScale       uint8
    56  	Rsvd19          uint8
    57  	ActivePower     uint16
    58  	ActiveWorkScale uint8
    59  	Rsvd23          [9]byte
    60  }
    61  
    62  //nolint:deadcode
    63  type nvmeIdentController struct {
    64  	VendorID     uint16                  // PCI Vendor ID
    65  	Ssvid        uint16                  // PCI Subsystem Vendor ID
    66  	SerialNumber [20]byte                // Serial Number
    67  	ModelNumber  [40]byte                // Model Number
    68  	Firmware     [8]byte                 // Firmware Revision
    69  	Rab          uint8                   // Recommended Arbitration Burst
    70  	IEEE         [3]byte                 // IEEE OUI Identifier
    71  	Cmic         uint8                   // Controller Multi-Path I/O and Namespace Sharing Capabilities
    72  	Mdts         uint8                   // Maximum Data Transfer Size
    73  	Cntlid       uint16                  // Controller ID
    74  	Ver          uint32                  // Version
    75  	Rtd3r        uint32                  // RTD3 Resume Latency
    76  	Rtd3e        uint32                  // RTD3 Entry Latency
    77  	Oaes         uint32                  // Optional Asynchronous Events Supported
    78  	Rsvd96       [160]byte               // ...
    79  	Oacs         uint16                  // Optional Admin Command Support
    80  	ACL          uint8                   // Abort Command Limit
    81  	Aerl         uint8                   // Asynchronous Event Request Limit
    82  	Frmw         uint8                   // Firmware Updates
    83  	Lpa          uint8                   // Log Page Attributes
    84  	Elpe         uint8                   // Error Log Page Entries
    85  	Npss         uint8                   // Number of Power States Support
    86  	Avscc        uint8                   // Admin Vendor Specific Command Configuration
    87  	Apsta        uint8                   // Autonomous Power State Transition Attributes
    88  	Wctemp       uint16                  // Warning Composite Temperature Threshold
    89  	Cctemp       uint16                  // Critical Composite Temperature Threshold
    90  	Mtfa         uint16                  // Maximum Time for Firmware Activation
    91  	Hmpre        uint32                  // Host Memory Buffer Preferred Size
    92  	Hmmin        uint32                  // Host Memory Buffer Minimum Size
    93  	Tnvmcap      [16]byte                // Total NVM Capacity
    94  	Unvmcap      [16]byte                // Unallocated NVM Capacity
    95  	Rpmbs        uint32                  // Replay Protected Memory Block Support
    96  	Rsvd316      [196]byte               // ...
    97  	Sqes         uint8                   // Submission Queue Entry Size
    98  	Cqes         uint8                   // Completion Queue Entry Size
    99  	Rsvd514      [2]byte                 // (defined in NVMe 1.3 spec)
   100  	Nn           uint32                  // Number of Namespaces
   101  	Oncs         uint16                  // Optional NVM Command Support
   102  	Fuses        uint16                  // Fused Operation Support
   103  	Fna          uint8                   // Format NVM Attributes
   104  	Vwc          uint8                   // Volatile Write Cache
   105  	Awun         uint16                  // Atomic Write Unit Normal
   106  	Awupf        uint16                  // Atomic Write Unit Power Fail
   107  	Nvscc        uint8                   // NVM Vendor Specific Command Configuration
   108  	Rsvd531      uint8                   // ...
   109  	Acwu         uint16                  // Atomic Compare & Write Unit
   110  	Rsvd534      [2]byte                 // ...
   111  	Sgls         uint32                  // SGL Support
   112  	Rsvd540      [1508]byte              // ...
   113  	Psd          [32]nvmeIdentPowerState // Power State Descriptors
   114  	Vs           [1024]byte              // Vendor Specific
   115  } // 4096 bytes
   116  
   117  type nvmeLBAF struct {
   118  	Ms uint16
   119  	Ds uint8
   120  	Rp uint8
   121  }
   122  
   123  //nolint:deadcode
   124  type nvmeIdentNamespace struct {
   125  	Nsze    uint64
   126  	Ncap    uint64
   127  	Nuse    uint64
   128  	Nsfeat  uint8
   129  	Nlbaf   uint8
   130  	Flbas   uint8
   131  	Mc      uint8
   132  	Dpc     uint8
   133  	Dps     uint8
   134  	Nmic    uint8
   135  	Rescap  uint8
   136  	Fpi     uint8
   137  	Rsvd33  uint8
   138  	Nawun   uint16
   139  	Nawupf  uint16
   140  	Nacwu   uint16
   141  	Nabsn   uint16
   142  	Nabo    uint16
   143  	Nabspf  uint16
   144  	Rsvd46  [2]byte
   145  	Nvmcap  [16]byte
   146  	Rsvd64  [40]byte
   147  	Nguid   [16]byte
   148  	EUI64   [8]byte
   149  	Lbaf    [16]nvmeLBAF
   150  	Rsvd192 [192]byte
   151  	Vs      [3712]byte
   152  } // 4096 bytes
   153  
   154  //nolint:deadcode
   155  type nvmeSMARTLog struct {
   156  	CritWarning      uint8
   157  	Temperature      [2]uint8
   158  	AvailSpare       uint8
   159  	SpareThresh      uint8
   160  	PercentUsed      uint8
   161  	Rsvd6            [26]byte
   162  	DataUnitsRead    [16]byte
   163  	DataUnitsWritten [16]byte
   164  	HostReads        [16]byte
   165  	HostWrites       [16]byte
   166  	CtrlBusyTime     [16]byte
   167  	PowerCycles      [16]byte
   168  	PowerOnHours     [16]byte
   169  	UnsafeShutdowns  [16]byte
   170  	MediaErrors      [16]byte
   171  	NumErrLogEntries [16]byte
   172  	WarningTempTime  uint32
   173  	CritCompTime     uint32
   174  	TempSensor       [8]uint16
   175  	Rsvd216          [296]byte
   176  } // 512 bytes
   177  
   178  // NVMeDevice represents drive data about NVMe drives
   179  //nolint:structcheck
   180  type NVMeDevice struct {
   181  	Name string
   182  	fd   int
   183  }
   184  
   185  // Info contains S.M.A.R.T data about the drive
   186  type Info struct {
   187  	Device string `json:"device"`
   188  
   189  	Scsi *ScsiInfo `json:"scsi,omitempty"`
   190  	Nvme *NvmeInfo `json:"nvme,omitempty"`
   191  	Ata  *AtaInfo  `json:"ata,omitempty"`
   192  
   193  	Error string `json:"error,omitempty"`
   194  }
   195  
   196  // AtaInfo contains ATA drive info
   197  type AtaInfo struct {
   198  	LUWWNDeviceID         string `json:"scsiLuWWNDeviceID,omitempty"`
   199  	SerialNum             string `json:"serialNum,omitempty"`
   200  	ModelNum              string `json:"modelNum,omitempty"`
   201  	FirmwareRevision      string `json:"firmwareRevision,omitempty"`
   202  	RotationRate          string `json:"RotationRate,omitempty"`
   203  	ATAMajorVersion       string `json:"MajorVersion,omitempty"`
   204  	ATAMinorVersion       string `json:"MinorVersion,omitempty"`
   205  	SmartSupportAvailable bool   `json:"smartSupportAvailable,omitempty"`
   206  	SmartSupportEnabled   bool   `json:"smartSupportEnabled,omitempty"`
   207  	ErrorLog              string `json:"smartErrorLog,omitempty"`
   208  	Transport             string `json:"transport,omitempty"`
   209  }
   210  
   211  // ScsiInfo contains SCSI drive Info
   212  type ScsiInfo struct {
   213  	CapacityBytes int64  `json:"scsiCapacityBytes,omitempty"`
   214  	ModeSenseBuf  string `json:"scsiModeSenseBuf,omitempty"`
   215  	RespLen       int64  `json:"scsirespLen,omitempty"`
   216  	BdLen         int64  `json:"scsiBdLen,omitempty"`
   217  	Offset        int64  `json:"scsiOffset,omitempty"`
   218  	RPM           int64  `json:"sciRpm,omitempty"`
   219  }
   220  
   221  // NvmeInfo contains NVMe drive info
   222  type NvmeInfo struct {
   223  	SerialNum       string `json:"serialNum,omitempty"`
   224  	VendorID        string `json:"vendorId,omitempty"`
   225  	FirmwareVersion string `json:"firmwareVersion,omitempty"`
   226  	ModelNum        string `json:"modelNum,omitempty"`
   227  	SpareAvailable  string `json:"spareAvailable,omitempty"`
   228  	SpareThreshold  string `json:"spareThreshold,omitempty"`
   229  	Temperature     string `json:"temperature,omitempty"`
   230  	CriticalWarning string `json:"criticalWarning,omitempty"`
   231  
   232  	MaxDataTransferPages        int      `json:"maxDataTransferPages,omitempty"`
   233  	ControllerBusyTime          *big.Int `json:"controllerBusyTime,omitempty"`
   234  	PowerOnHours                *big.Int `json:"powerOnHours,omitempty"`
   235  	PowerCycles                 *big.Int `json:"powerCycles,omitempty"`
   236  	UnsafeShutdowns             *big.Int `json:"unsafeShutdowns,omitempty"`
   237  	MediaAndDataIntegrityErrors *big.Int `json:"mediaAndDataIntgerityErrors,omitempty"`
   238  	DataUnitsReadBytes          *big.Int `json:"dataUnitsReadBytes,omitempty"`
   239  	DataUnitsWrittenBytes       *big.Int `json:"dataUnitsWrittenBytes,omitempty"`
   240  	HostReadCommands            *big.Int `json:"hostReadCommands,omitempty"`
   241  	HostWriteCommands           *big.Int `json:"hostWriteCommands,omitempty"`
   242  }