Skip to content

Commit 681f22e

Browse files
authored
Merge pull request #26 from tasleson/misc_changes
Misc changes
2 parents 82f0e0b + 1b2c0e9 commit 681f22e

File tree

3 files changed

+33
-20
lines changed

3 files changed

+33
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.ccls-cache
2+
.vscode/settings.json

localdisk/localdisk.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,21 +64,21 @@ func List() ([]string, error) {
6464
return disks, nil
6565
}
6666

67-
// Vpd83Seach searches local disks for vpd
68-
func Vpd83Seach(vpd string) ([]string, error) {
67+
// Vpd83Search searches local disks for vpd
68+
func Vpd83Search(vpd string) ([]string, error) {
6969

7070
cs := C.CString(vpd)
7171
defer C.free(unsafe.Pointer(cs))
7272

7373
var deviceList []string
7474

75-
var slist *C.lsm_string_list
75+
var str_list *C.lsm_string_list
7676
var lsmError *C.lsm_error
7777

78-
var err = C.lsm_local_disk_vpd83_search(cs, &slist, &lsmError)
78+
var err = C.lsm_local_disk_vpd83_search(cs, &str_list, &lsmError)
7979

8080
if err == 0 {
81-
deviceList = getStrings(slist, true)
81+
deviceList = getStrings(str_list, true)
8282
} else {
8383
return deviceList, processError(int(err), lsmError)
8484
}
@@ -236,16 +236,19 @@ func LinkSpeedGet(diskPath string) (uint32, error) {
236236
return 0, processError(int(rc), lsmError)
237237
}
238238

239-
type LedSlots struct {
239+
// Opaque type for LED Slots API
240+
type LedSlotsHandle struct {
240241
handle *C.lsm_led_handle
241242
}
242243

243-
func LedSlotsHandleGet() (*LedSlots, error) {
244+
// Retrieve the handle to use for interacting with LED Slots, make sure to call LedSlotsHandleFree
245+
// when done
246+
func LedSlotsHandleGet() (*LedSlotsHandle, error) {
244247
var l_handle *C.lsm_led_handle
245248
var rc = C.lsm_led_handle_get(&l_handle, 0)
246249

247250
if rc == 0 {
248-
return &LedSlots{handle: l_handle}, nil
251+
return &LedSlotsHandle{handle: l_handle}, nil
249252
}
250253

251254
return nil, &errors.LsmError{
@@ -254,16 +257,19 @@ func LedSlotsHandleGet() (*LedSlots, error) {
254257

255258
}
256259

257-
func LedSlotsHandleFree(led_slots *LedSlots) {
260+
// Frees the resources used by the LED Slot API, calling this is required to prevent a memory leak
261+
func LedSlotsHandleFree(led_slots *LedSlotsHandle) {
258262
C.lsm_led_handle_free(led_slots.handle)
259263
}
260264

265+
// Information about a specific LED slot
261266
type LedSlot struct {
262-
SlotId string
263-
Device string
267+
SlotId string // The slot identifier
268+
Device string // The slot device node, if it has one
264269
}
265270

266-
func (l *LedSlots) Slots() ([]LedSlot, error) {
271+
// Retrieves all the LED slots
272+
func (l *LedSlotsHandle) SlotsGet() ([]LedSlot, error) {
267273
var slots []LedSlot
268274
var itr *C.lsm_led_slot_itr
269275
var lsmError *C.lsm_error
@@ -297,7 +303,8 @@ func (l *LedSlots) Slots() ([]LedSlot, error) {
297303
return slots, processError(int(rc), lsmError)
298304
}
299305

300-
func (l *LedSlots) StatusGet(slot *LedSlot) (lsm.DiskLedStatusBitField, error) {
306+
// Retrieves the current status of the LED slot
307+
func (l *LedSlotsHandle) StatusGet(slot *LedSlot) (lsm.DiskLedStatusBitField, error) {
301308
var itr *C.lsm_led_slot_itr
302309
var lsmError *C.lsm_error
303310

@@ -326,7 +333,8 @@ func (l *LedSlots) StatusGet(slot *LedSlot) (lsm.DiskLedStatusBitField, error) {
326333
return 0, processError(int(rc), lsmError)
327334
}
328335

329-
func (l *LedSlots) StatusSet(slot *LedSlot, led_status lsm.DiskLedStatusBitField) error {
336+
// Sets the LED slot
337+
func (l *LedSlotsHandle) StatusSet(slot *LedSlot, led_status lsm.DiskLedStatusBitField) error {
330338
var itr *C.lsm_led_slot_itr
331339
var lsmError *C.lsm_error
332340

test/lsm_test.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestAvailablePluginsBadUds(t *testing.T) {
143143
os.Setenv(KEY, current)
144144
}
145145

146-
func TestBadSeach(t *testing.T) {
146+
func TestBadSearch(t *testing.T) {
147147
var c, _ = lsm.Client(URI, PASSWORD, TMO)
148148

149149
var _, sE = c.Volumes("what")
@@ -172,7 +172,7 @@ func TestPoolSearch(t *testing.T) {
172172
assert.Equal(t, nil, c.Close())
173173
}
174174

175-
func TestGoodSeach(t *testing.T) {
175+
func TestGoodSearch(t *testing.T) {
176176
var c, _ = lsm.Client(URI, PASSWORD, TMO)
177177

178178
var volumes, sE = c.Volumes("system_id", "sim-01")
@@ -1166,7 +1166,7 @@ func TestLocalDisk(t *testing.T) {
11661166
if vpdE == nil {
11671167
assert.True(t, len(vpd) > 0)
11681168

1169-
var search, searchErr = disks.Vpd83Seach(vpd)
1169+
var search, searchErr = disks.Vpd83Search(vpd)
11701170
assert.Nil(t, searchErr)
11711171
assert.True(t, len(search) > 0)
11721172
t.Logf("vpd search result = %v %s\n", search, d)
@@ -1178,7 +1178,7 @@ func TestLocalDisk(t *testing.T) {
11781178
}
11791179

11801180
func TestVpdMissingSearch(t *testing.T) {
1181-
var paths, err = disks.Vpd83Seach(rs("", 16))
1181+
var paths, err = disks.Vpd83Search(rs("", 16))
11821182
assert.Nil(t, err)
11831183
assert.True(t, len(paths) == 0)
11841184
}
@@ -1531,7 +1531,7 @@ func TestLocalDiskLedSlotsGet(t *testing.T) {
15311531
var handle, err = disks.LedSlotsHandleGet()
15321532
assert.Nil(t, err)
15331533

1534-
slots, err = handle.Slots()
1534+
slots, err = handle.SlotsGet()
15351535
assert.Nil(t, err)
15361536

15371537
for _, s := range slots {
@@ -1564,9 +1564,13 @@ func TestLocalDiskLedSlotsGetSet(t *testing.T) {
15641564
var handle, err = disks.LedSlotsHandleGet()
15651565
assert.Nil(t, err)
15661566

1567-
slots, err = handle.Slots()
1567+
slots, err = handle.SlotsGet()
15681568
assert.Nil(t, err)
15691569

1570+
if len(slots) == 0 {
1571+
t.Skip("No local disks to test!")
1572+
}
1573+
15701574
for _, s := range slots {
15711575

15721576
if len(s.Device) > 0 {

0 commit comments

Comments
 (0)