smart

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2020 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package smart provides details about a particular disk device which includes both basic details such as vendor, model, serial, etc as well as smart details such as Raw_Read_Error_Rate, Temperature_Celsius, Spin_Up_Time, etc by parsing various disk pages such as inquiry page, ata command set page ,etc using various SCSI commands such as scsi inquiry, read device capacity, mode sense, etc.

NOTE : For now, the implementation is only for getting the basic details (not smart details) of SCSI disks such as vendor,serial, model, firmware revision, logical sector size,etc.

Usage:

import "github.com/openebs/node-disk-manager/pkg/smart"

S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology; often written as SMART) is a monitoring system included in computer hard disk drives (HDDs), solid-state drives (SSDs), and eMMC drives. Its primary function is to detect and report various indicators of drive reliability with the intent of anticipating imminent hardware failures. When S.M.A.R.T. data indicates a possible imminent drive failure, software running on the host system may notify the user so preventative action can be taken to prevent data loss, and the failing drive can be replaced and data integrity maintained.

This smart go library provides functionality to get the list of all the SCSI disk devices attached to it and a list of disk smart attributes along with the basic disk attributes such as serial no, sector size, wwn, rpm, vendor, etc.

For getting the basic SCSI disk details, one should import this library and then a call to function SCSIBasicDiskInfo("device-path") where device-path is the devpath of the scsi device e.g. /dev/sda, /dev/sdb, etc for which we want to fetch the basic disk details such as vendor, model, serial, wwn, logical and physical sector size, etc is to be fetched. This function would return a struct of disk details alongwith errors if any, filled by smart library for the particular disk device whose devpath has been given.

If a user wants to only get the detail of a particular disk attribute such as vendor, serial, etc for a particular SCSI device then function SCSIBasicDiskInfoByAttrName(attrName string) (where attrName refers to the attribute whose value is to be fetched such as Vendor) should be called which will return the detail or value of that particular attribute only alongwith the errors if any occurred while fetching the detail.

An example usage can be like this -

package smartusageexample

import (

"fmt"

"k8s.io/klog"
"github.com/openebs/node-disk-manager/pkg/smart"

)

func main() {
	deviceBasicSCSIInfo, err := smart.SCSIBasicDiskInfo("/dev/sda")
	if err != nil {
		klog.Fatal(err)
	}

	fmt.Printf("Vendor :%s \n",deviceBasicSCSIInfo.Vendor)
	fmt.Printf("Compliance :%s \n",deviceBasicSCSIInfo.Compliance)
	fmt.Printf("FirmwareRevision :%s \n",deviceBasicSCSIInfo.FirmwareRevision)
	fmt.Printf("Capacity :%d \n",deviceBasicSCSIInfo.Capacity)
}

NOTE : This document will remain in continuous updation whenever more features and functionalities are implemented.

Please refer to the design doc here - https://docs.google.com/document/d/1avZrFI3j1AOmWIY_43oyK9Nkj5IYT37fzIhAAbp0Bxs/edit?usp=sharing

Index

Constants

View Source
const (
	SCSIModeSense                 = 0x1a // mode sense command
	SCSIReadCapacity10            = 0x25 // read capacity (10) command
	SCSIReadCapacity16            = 0x9e // read capacity (16) command
	SCSIReadCapacityServiceAction = 0x10 // read capacity (16) service action
	SCSIATAPassThru               = 0x85 // ata passthru command
)

SCSI commands being used

View Source
const (
	SCSIInquiry = 0x12 // inquiry command

	// Minimum length of standard INQUIRY response
	INQRespLen = 56
)

commands used to fetch various information of a disk from a set of defined scsi pages

View Source
const (
	SGDxferNone      = -1     //SCSI Test Unit Ready command
	SGDxferToDev     = -2     //SCSI WRITE command
	SGDxferFromDev   = -3     //SCSI READ command
	SGDxferToFromDev = -4     //relevant to indirect IO (otherwise it is treated like SGDxferFromDev)
	SGInfoOk         = 0x0    //no sense, host nor driver "noise" or error
	SGInfoOkMask     = 0x1    //indicates whether some error or status field is non-zero
	SGIO             = 0x2285 //scsi generic ioctl command
	DefaultTimeout   = 20000  //DefaultTimeout in millisecs
)

SCSI generic (sg) See dxfer_direction http://sg.danny.cz/sg/p/sg_v3_ho.html

View Source
const (
	Compliance         = "Compliance"
	Vendor             = "Vendor"
	Capacity           = "Capacity"
	LogicalSectorSize  = "LogicalSectorSize"
	PhysicalSectorSize = "PhysicalSectorSize"
	SerialNumber       = "SerialNumber"
	WWN                = "LuWWNDeviceID"
	FirmwareRev        = "FirmwareRevision"
	ModelNumber        = "ModelNumber"
	RPM                = "RPM"
	ATAMajor           = "ATAMajorVersion"
	ATAMinor           = "ATAMinorVersion"
	AtATransport       = "AtaTransport"
	SupportedBusType   = "SCSI"
)

Constants being used by switch case for returning disk details

View Source
const (
	SCSIInqErr        = "SCSIInquiryError"
	SCSIReadCapErr    = "SCSIReadcapacityError"
	ATAIdentifyErr    = "AtaIdentifyError"
	RPMErr            = "RPMError"
	SCSiGetLBSizeErr  = "GetLogicalBlockSizeError"
	DetectSCSITypeErr = "DetectScsiTypeError"
)

Constants being used as keys for sending map of errors

View Source
const (
	AtaIdentifyDevice = 0xec
)

ATA command being used

Variables

ATACSAttr is the list of attributes fetched using ATACSPage

View Source
var (
	NativeEndian binary.ByteOrder
)

A ByteOrder specifies how to convert byte sequences into 16-, 32-, or 64-bit unsigned integers.

ScsiInqAttr is the list of attributes fetched by SCSI Inquiry command

SimpleSCSIAttr is the list of attributes fetched by simple SCSI commands such as readCapacity,etc

Functions

func CheckBinaryPerm

func CheckBinaryPerm() error

CheckBinaryPerm invokes the linux CAPGET syscall which checks for necessary capabilities required for a binary to access a device. Note that this depends on the binary having the capabilities set (i.e., via the `setcap` utility), and on VFS support i.e. with VFS support, for capset() calls the only permitted values for userCapHeader->pid are 0 Note : If the binary is executed as root, it automatically has all capabilities set.

func Ioctl

func Ioctl(fd, cmd, ptr uintptr) error

Ioctl function executes an ioctl command on the specified file descriptor ioctl (an abbreviation of input/output control) is a system call for device-specific input/output operations and other operations which cannot be expressed by regular system calls. It takes a parameter specifying a request code; the effect of a call depends completely on the request code

func MSignificantBit

func MSignificantBit(i uint) int

MSignificantBit finds the most significant bit set in a uint

Types

type ATACSPage

type ATACSPage struct {
	SerialNumber [20]byte // Word 10..19, device serial number.

	MajorVer uint16 // Word 80, major version number.
	MinorVer uint16 // Word 81, minor version number.

	SectorSize uint16 // Word 106, Logical/physical sector size.

	WWN [4]uint16 // Word 108..111, WWN (World Wide Name).

	RotationRate uint16 // Word 217, nominal media rotation rate.

	AtaTransportMajor uint16 // Word 222, Transport major version number.
	// contains filtered or unexported fields

} // 512 bytes

ATACSPage struct is an ATA IDENTIFY DEVICE struct. ATA8-ACS defines this as a page of 16-bit words. _ (underscore) is used here to skip the words which we don't want to parse or get the data while parsing the ata identify device data struct page.

func (*ATACSPage) IdentifySerialATAType

func (d *ATACSPage) IdentifySerialATAType() (s string)

IdentifySerialATAType identifies the type of SATA transport being used by a disk

type ATADiskAttr

type ATADiskAttr struct {
	ATAMajorVersion string
	ATAMinorVersion string
	AtaTransport    string
}

ATADiskAttr is the struct for disk attributes that are specific to ATA disks

type BasicDiskAttr

type BasicDiskAttr struct {
	Compliance       string
	Vendor           string
	ModelNumber      string
	SerialNumber     string
	FirmwareRevision string
	WWN              string
	Capacity         uint64
	LBSize           uint32
	PBSize           uint32
	RotationRate     uint16
}

BasicDiskAttr is the structure being used for returning basic disk details

type CDB10

type CDB10 [10]byte

CDB10 is an array of 10 byte

type CDB16

type CDB16 [16]byte

CDB16 is an array of 16 byte

type CDB6

type CDB6 [6]byte

CDB6 is an array of 6 byte

type Dev

Dev is the top-level device interface. All supported device types must implement these interfaces.

type DevBasicDiskInfo

type DevBasicDiskInfo interface {
	// contains filtered or unexported methods
}

DevBasicDiskInfo interface implements getBasicDiskInfo method for getting all the available details for a particular disk device

type DevBasicinfoByAttr

type DevBasicinfoByAttr interface {
	// contains filtered or unexported methods
}

DevBasicinfoByAttr interface implements getBasicDiskInfoByAttr method for getting particular attribute detail of a disk device

type DevClose

type DevClose interface {
	Close() error
}

DevClose interface implements close method for closing a disk device

type DevOpen

type DevOpen interface {
	Open() error
}

DevOpen interface implements open method for opening a disk device

type DiskAttr

type DiskAttr struct {
	BasicDiskAttr
	ATADiskAttr
}

DiskAttr is struct being used for returning all the available disk details (both basic and smart) For now, only basic disk attr are being fetched so it is returning only basic attrs

type ErrorCollector

type ErrorCollector struct {
	// contains filtered or unexported fields
}

ErrorCollector Struct is a struct for map of errors

func NewErrorCollector

func NewErrorCollector() *ErrorCollector

NewErrorCollector returns a pointer to the ErrorCollector

func (*ErrorCollector) Collect

func (c *ErrorCollector) Collect(key string, e error) bool

Collect function is used to collect errors corresponding to the keys given to it

func (*ErrorCollector) Error

func (c *ErrorCollector) Error() (errorMap map[string]error)

Error is used to return all the collected errors as a map

type Identifier

type Identifier struct {
	DevPath string
}

Identifier (devPath such as /dev/sda,etc) is an identifier for smart probe

func (*Identifier) SCSIBasicDiskInfo

func (I *Identifier) SCSIBasicDiskInfo() (DiskAttr, map[string]error)

SCSIBasicDiskInfo returns all the available disk details for a particular disk device

func (*Identifier) SCSIBasicDiskInfoByAttrName

func (I *Identifier) SCSIBasicDiskInfoByAttrName(attrName string) (string, error)

SCSIBasicDiskInfoByAttrName returns disk details(disk attributes and their values such as vendor,serialno,etc) of a disk

type InquiryResponse

type InquiryResponse struct {
	Version byte // implemented specification version such as SPC-1,SPC-2,etc

	VendorID     [8]byte  // Vendor Identification
	ProductID    [16]byte // Product Identification
	ProductRev   [4]byte  // Product Revision Level
	SerialNumber [20]byte // Serial Number
	// contains filtered or unexported fields
}

InquiryResponse is used for parsing response fetched by sending a scsi inquiry command to a scsi device Here underscore (_) is used to skip the words which we don't want to parse as of now..

type MockOsDiskDetails

type MockOsDiskDetails struct {
	Compliance       string
	FirmwareRevision string
	Capacity         uint64
	LBSize           uint32
	DevPath          string
}

MockOsDiskDetails struct contains the basic details of the disk

func MockScsiBasicDiskInfo

func MockScsiBasicDiskInfo() (MockOsDiskDetails, error)

MockScsiBasicDiskInfo is used to fetch basic disk details for a scsi disk

type SATA

type SATA struct {
	SCSIDev
}

SATA is a simple wrapper around an embedded SCSIDevice type, which handles sending ATA commands via SCSI pass-through (SCSI-ATA Translation).

type SCSIDev

type SCSIDev struct {
	DevName string // SCSI device name
	// contains filtered or unexported fields
}

SCSIDev represents a particular scsi device with device name and file descriptor

func (*SCSIDev) Close

func (d *SCSIDev) Close() error

Close returns error if a SCSI device is not closed

func (*SCSIDev) Open

func (d *SCSIDev) Open() (err error)

Open returns error if a SCSI device returns error when opened

type SmartDiskAttr

type SmartDiskAttr struct {
}

SmartDiskAttr is the structure defined for smart disk attrs (Note : Not being used yet)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL