forked from openebs-archive/node-disk-manager
-
Notifications
You must be signed in to change notification settings - Fork 1
/
seachest.go
221 lines (186 loc) · 6.29 KB
/
seachest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
Copyright 2018 The OpenEBS Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// +build linux,cgo
package seachest
/*
#cgo LDFLAGS: -lopensea-operations -lopensea-transport -lopensea-common -lm
#cgo CFLAGS: -I../../../openSeaChest/include -I../../../openSeaChest/opensea-common/include -I../../../openSeaChest/opensea-operations/include -I../../../openSeaChest/opensea-transport/include
#include "common.h"
#include "openseachest_util_options.h"
#include "common_public.h"
#include "ata_helper.h"
#include "ata_helper_func.h"
#include "scsi_helper.h"
#include "scsi_helper_func.h"
#include "nvme_helper.h"
#include "nvme_helper_func.h"
#include "cmds.h"
#include "drive_info.h"
#include <libudev.h>
*/
import "C"
import (
"fmt"
"k8s.io/klog"
"unsafe"
)
// Seachest errors are converted to string using this function
func SeachestErrors(err int) string {
seachestErrorSting := []string{
"Success",
"Failed",
"Not Supported",
"Cmd Failure",
"In-progress",
"Aborted",
"Bad Parameter",
"Memory Allocation Failed",
"Cmd Passthrough Failed",
"Library Mismatch",
"Device Frozen",
"Permission Denied",
"File Open Error",
"Incomplete RFTRS",
"Cmd Time-out",
"Warning - Not all device enumerated",
"Invalid Checksum",
"Cmd not Available",
"Cmd Blocked",
"Cmd Interrupted",
"Unknown",
}
return seachestErrorSting[err]
}
// Identifier (devPath such as /dev/sda,etc) is an identifier for seachest probe
type Identifier struct {
DevPath string
}
func (I *Identifier) SeachestBasicDiskInfo() (*C.driveInformationSAS_SATA, int) {
var device C.tDevice
var Drive C.driveInformationSAS_SATA
str := C.CString(I.DevPath)
defer C.free(unsafe.Pointer(str))
err := int(C.get_Device(str, &device))
if err != 0 {
klog.Errorf("Unable to get device info for device:%s with error:%s", I.DevPath, SeachestErrors(err))
return nil, err
}
// close the device, once all info is fetched
defer closeDevice(&device, I.DevPath)
err = int(C.get_SCSI_Drive_Information(&device, &Drive))
if err != 0 {
klog.Errorf("Unable to get derive info for device:%s with error:%s", I.DevPath, SeachestErrors(err))
return nil, err
}
return &Drive, err
}
// closeDevice closes the device and log the error if any
func closeDevice(device *C.tDevice, devPath string) {
err := int(C.close_Device(device))
if err != 0 {
klog.Errorf("unable to close device: %s with error: %s", devPath, SeachestErrors(err))
}
}
func (I *Identifier) GetHostName(driveInfo *C.driveInformationSAS_SATA) string {
return ""
}
func (I *Identifier) GetModelNumber(driveInfo *C.driveInformationSAS_SATA) string {
var ptr *C.char
ptr = &driveInfo.modelNumber[0]
str := C.GoString(ptr)
return str
}
func (I *Identifier) GetUuid(driveInfo *C.driveInformationSAS_SATA) string {
myString := fmt.Sprintf("%v", driveInfo.worldWideName)
return myString
}
func (I *Identifier) GetCapacity(driveInfo *C.driveInformationSAS_SATA) uint64 {
var capacity C.uint64_t
capacity = (C.uint64_t)(driveInfo.maxLBA * ((C.uint64_t)(driveInfo.logicalSectorSize)))
return ((uint64)(capacity))
}
func (I *Identifier) GetSerialNumber(driveInfo *C.driveInformationSAS_SATA) string {
var ptr *C.char
ptr = &driveInfo.serialNumber[0]
str := C.GoString(ptr)
return str
}
func (I *Identifier) GetVendorID(driveInfo *C.driveInformationSAS_SATA) string {
var ptr *C.char
ptr = &driveInfo.vendorID[0]
str := C.GoString(ptr)
return str
}
func (I *Identifier) GetPath(driveInfo *C.driveInformationSAS_SATA) string {
return I.DevPath
}
func (I *Identifier) GetFirmwareRevision(driveInfo *C.driveInformationSAS_SATA) string {
var ptr *C.char
ptr = &driveInfo.firmwareRevision[0]
str := C.GoString(ptr)
return str
}
func (I *Identifier) GetLogicalSectorSize(driveInfo *C.driveInformationSAS_SATA) uint32 {
return ((uint32)(driveInfo.logicalSectorSize))
}
func (I *Identifier) GetPhysicalSectorSize(driveInfo *C.driveInformationSAS_SATA) uint32 {
return ((uint32)(driveInfo.physicalSectorSize))
}
func (I *Identifier) GetRotationRate(driveInfo *C.driveInformationSAS_SATA) uint16 {
if driveInfo.rotationRate > 1 {
return ((uint16)(driveInfo.rotationRate))
}
return 0
}
func (I *Identifier) DriveType(driveInfo *C.driveInformationSAS_SATA) string {
if driveInfo.rotationRate == 0x0000 {
return "Not Available"
}
if driveInfo.rotationRate == 0x0001 {
return "SSD"
}
return "HDD"
}
func (I *Identifier) GetTotalBytesRead(driveInfo *C.driveInformationSAS_SATA) uint64 {
return ((uint64)(driveInfo.totalBytesRead))
}
func (I *Identifier) GetTotalBytesWritten(driveInfo *C.driveInformationSAS_SATA) uint64 {
return ((uint64)(driveInfo.totalBytesWritten))
}
func (I *Identifier) GetDeviceUtilizationRate(driveInfo *C.driveInformationSAS_SATA) float64 {
return ((float64)(driveInfo.deviceReportedUtilizationRate))
}
func (I *Identifier) GetPercentEnduranceUsed(driveInfo *C.driveInformationSAS_SATA) float64 {
if driveInfo.percentEnduranceUsed != -1 {
return ((float64)(driveInfo.percentEnduranceUsed))
}
return 0
}
func (I *Identifier) GetTemperatureDataValidStatus(driveInfo *C.driveInformationSAS_SATA) bool {
return ((bool)(driveInfo.temperatureData.temperatureDataValid))
}
func (I *Identifier) GetCurrentTemperature(driveInfo *C.driveInformationSAS_SATA) int16 {
return ((int16)(driveInfo.temperatureData.currentTemperature))
}
func (I *Identifier) GetHighestValid(driveInfo *C.driveInformationSAS_SATA) bool {
return ((bool)(driveInfo.temperatureData.highestValid))
}
func (I *Identifier) GetHighestTemperature(driveInfo *C.driveInformationSAS_SATA) int16 {
return ((int16)(driveInfo.temperatureData.highestTemperature))
}
func (I *Identifier) GetLowestValid(driveInfo *C.driveInformationSAS_SATA) bool {
return ((bool)(driveInfo.temperatureData.lowestValid))
}
func (I *Identifier) GetLowestTemperature(driveInfo *C.driveInformationSAS_SATA) int16 {
return ((int16)(driveInfo.temperatureData.lowestTemperature))
}