Skip to content

Commit 68fb3df

Browse files
authored
enhancement: Use pointer fields for FibreChannel* (#623)
* enhancement: Use pointer fields for `FibreChannel*` Allow fields to be `nil`-checked. Fixes: #612 Signed-off-by: Pranshu Srivastava <[email protected]> * fixup! enhancement: Use pointer fields for `FibreChannel*` Signed-off-by: Pranshu Srivastava <[email protected]> --------- Signed-off-by: Pranshu Srivastava <[email protected]>
1 parent 5cca38b commit 68fb3df

File tree

2 files changed

+153
-99
lines changed

2 files changed

+153
-99
lines changed

sysfs/class_fibrechannel.go

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,36 @@ import (
2828
const fibrechannelClassPath = "class/fc_host"
2929

3030
type FibreChannelCounters struct {
31-
DumpedFrames uint64 // /sys/class/fc_host/<Name>/statistics/dumped_frames
32-
ErrorFrames uint64 // /sys/class/fc_host/<Name>/statistics/error_frames
33-
InvalidCRCCount uint64 // /sys/class/fc_host/<Name>/statistics/invalid_crc_count
34-
RXFrames uint64 // /sys/class/fc_host/<Name>/statistics/rx_frames
35-
RXWords uint64 // /sys/class/fc_host/<Name>/statistics/rx_words
36-
TXFrames uint64 // /sys/class/fc_host/<Name>/statistics/tx_frames
37-
TXWords uint64 // /sys/class/fc_host/<Name>/statistics/tx_words
38-
SecondsSinceLastReset uint64 // /sys/class/fc_host/<Name>/statistics/seconds_since_last_reset
39-
InvalidTXWordCount uint64 // /sys/class/fc_host/<Name>/statistics/invalid_tx_word_count
40-
LinkFailureCount uint64 // /sys/class/fc_host/<Name>/statistics/link_failure_count
41-
LossOfSyncCount uint64 // /sys/class/fc_host/<Name>/statistics/loss_of_sync_count
42-
LossOfSignalCount uint64 // /sys/class/fc_host/<Name>/statistics/loss_of_signal_count
43-
NosCount uint64 // /sys/class/fc_host/<Name>/statistics/nos_count
44-
FCPPacketAborts uint64 // / sys/class/fc_host/<Name>/statistics/fcp_packet_aborts
31+
DumpedFrames *uint64 // /sys/class/fc_host/<Name>/statistics/dumped_frames
32+
ErrorFrames *uint64 // /sys/class/fc_host/<Name>/statistics/error_frames
33+
InvalidCRCCount *uint64 // /sys/class/fc_host/<Name>/statistics/invalid_crc_count
34+
RXFrames *uint64 // /sys/class/fc_host/<Name>/statistics/rx_frames
35+
RXWords *uint64 // /sys/class/fc_host/<Name>/statistics/rx_words
36+
TXFrames *uint64 // /sys/class/fc_host/<Name>/statistics/tx_frames
37+
TXWords *uint64 // /sys/class/fc_host/<Name>/statistics/tx_words
38+
SecondsSinceLastReset *uint64 // /sys/class/fc_host/<Name>/statistics/seconds_since_last_reset
39+
InvalidTXWordCount *uint64 // /sys/class/fc_host/<Name>/statistics/invalid_tx_word_count
40+
LinkFailureCount *uint64 // /sys/class/fc_host/<Name>/statistics/link_failure_count
41+
LossOfSyncCount *uint64 // /sys/class/fc_host/<Name>/statistics/loss_of_sync_count
42+
LossOfSignalCount *uint64 // /sys/class/fc_host/<Name>/statistics/loss_of_signal_count
43+
NosCount *uint64 // /sys/class/fc_host/<Name>/statistics/nos_count
44+
FCPPacketAborts *uint64 // /sys/class/fc_host/<Name>/statistics/fcp_packet_aborts
4545
}
4646

4747
type FibreChannelHost struct {
48-
Name string // /sys/class/fc_host/<Name>
49-
Speed string // /sys/class/fc_host/<Name>/speed
50-
PortState string // /sys/class/fc_host/<Name>/port_state
51-
PortType string // /sys/class/fc_host/<Name>/port_type
52-
SymbolicName string // /sys/class/fc_host/<Name>/symbolic_name
53-
NodeName string // /sys/class/fc_host/<Name>/node_name
54-
PortID string // /sys/class/fc_host/<Name>/port_id
55-
PortName string // /sys/class/fc_host/<Name>/port_name
56-
FabricName string // /sys/class/fc_host/<Name>/fabric_name
57-
DevLossTMO string // /sys/class/fc_host/<Name>/dev_loss_tmo
58-
SupportedClasses string // /sys/class/fc_host/<Name>/supported_classes
59-
SupportedSpeeds string // /sys/class/fc_host/<Name>/supported_speeds
60-
Counters FibreChannelCounters // /sys/class/fc_host/<Name>/statistics/*
48+
Name *string // /sys/class/fc_host/<Name>
49+
Speed *string // /sys/class/fc_host/<Name>/speed
50+
PortState *string // /sys/class/fc_host/<Name>/port_state
51+
PortType *string // /sys/class/fc_host/<Name>/port_type
52+
SymbolicName *string // /sys/class/fc_host/<Name>/symbolic_name
53+
NodeName *string // /sys/class/fc_host/<Name>/node_name
54+
PortID *string // /sys/class/fc_host/<Name>/port_id
55+
PortName *string // /sys/class/fc_host/<Name>/port_name
56+
FabricName *string // /sys/class/fc_host/<Name>/fabric_name
57+
DevLossTMO *string // /sys/class/fc_host/<Name>/dev_loss_tmo
58+
SupportedClasses *string // /sys/class/fc_host/<Name>/supported_classes
59+
SupportedSpeeds *string // /sys/class/fc_host/<Name>/supported_speeds
60+
Counters *FibreChannelCounters // /sys/class/fc_host/<Name>/statistics/*
6161
}
6262

6363
type FibreChannelClass map[string]FibreChannelHost
@@ -78,7 +78,7 @@ func (fs FS) FibreChannelClass() (FibreChannelClass, error) {
7878
return nil, err
7979
}
8080

81-
fcc[host.Name] = *host
81+
fcc[*host.Name] = *host
8282
}
8383

8484
return fcc, nil
@@ -87,7 +87,7 @@ func (fs FS) FibreChannelClass() (FibreChannelClass, error) {
8787
// Parse a single FC host.
8888
func (fs FS) parseFibreChannelHost(name string) (*FibreChannelHost, error) {
8989
path := fs.sys.Path(fibrechannelClassPath, name)
90-
host := FibreChannelHost{Name: name}
90+
host := FibreChannelHost{Name: &name}
9191

9292
for _, f := range [...]string{"speed", "port_state", "port_type", "node_name", "port_id", "port_name", "fabric_name", "dev_loss_tmo", "symbolic_name", "supported_classes", "supported_speeds"} {
9393
name := filepath.Join(path, f)
@@ -103,47 +103,47 @@ func (fs FS) parseFibreChannelHost(name string) (*FibreChannelHost, error) {
103103

104104
switch f {
105105
case "speed":
106-
host.Speed = value
106+
host.Speed = &value
107107
case "port_state":
108-
host.PortState = value
108+
host.PortState = &value
109109
case "port_type":
110-
host.PortType = value
110+
host.PortType = &value
111111
case "node_name":
112112
if len(value) > 2 {
113113
value = value[2:]
114114
}
115-
host.NodeName = value
115+
host.NodeName = &value
116116
case "port_id":
117117
if len(value) > 2 {
118118
value = value[2:]
119119
}
120-
host.PortID = value
120+
host.PortID = &value
121121
case "port_name":
122122
if len(value) > 2 {
123123
value = value[2:]
124124
}
125-
host.PortName = value
125+
host.PortName = &value
126126
case "fabric_name":
127127
if len(value) > 2 {
128128
value = value[2:]
129129
}
130-
host.FabricName = value
130+
host.FabricName = &value
131131
case "dev_loss_tmo":
132-
host.DevLossTMO = value
132+
host.DevLossTMO = &value
133133
case "supported_classes":
134-
host.SupportedClasses = value
134+
host.SupportedClasses = &value
135135
case "supported_speeds":
136-
host.SupportedSpeeds = value
136+
host.SupportedSpeeds = &value
137137
case "symbolic_name":
138-
host.SymbolicName = value
138+
host.SymbolicName = &value
139139
}
140140
}
141141

142142
counters, err := parseFibreChannelStatistics(path)
143143
if err != nil {
144144
return nil, err
145145
}
146-
host.Counters = *counters
146+
host.Counters = counters
147147

148148
return &host, nil
149149
}
@@ -178,9 +178,9 @@ func parseFibreChannelStatistics(hostPath string) (*FibreChannelCounters, error)
178178
// Below switch was automatically generated. Don't need everything in there yet, so the unwanted bits are commented out.
179179
switch f.Name() {
180180
case "dumped_frames":
181-
counters.DumpedFrames = *vp.PUInt64()
181+
counters.DumpedFrames = vp.PUInt64()
182182
case "error_frames":
183-
counters.ErrorFrames = *vp.PUInt64()
183+
counters.ErrorFrames = vp.PUInt64()
184184
/*
185185
case "fc_no_free_exch":
186186
counters.FcNoFreeExch = *vp.PUInt64()
@@ -208,41 +208,41 @@ func parseFibreChannelStatistics(hostPath string) (*FibreChannelCounters, error)
208208
counters.FcpOutputRequests = *vp.PUInt64()
209209
*/
210210
case "fcp_packet_aborts":
211-
counters.FCPPacketAborts = *vp.PUInt64()
211+
counters.FCPPacketAborts = vp.PUInt64()
212212
/*
213213
case "fcp_packet_alloc_failures":
214214
counters.FcpPacketAllocFailures = *vp.PUInt64()
215215
*/
216216
case "invalid_tx_word_count":
217-
counters.InvalidTXWordCount = *vp.PUInt64()
217+
counters.InvalidTXWordCount = vp.PUInt64()
218218
case "invalid_crc_count":
219-
counters.InvalidCRCCount = *vp.PUInt64()
219+
counters.InvalidCRCCount = vp.PUInt64()
220220
case "link_failure_count":
221-
counters.LinkFailureCount = *vp.PUInt64()
221+
counters.LinkFailureCount = vp.PUInt64()
222222
/*
223223
case "lip_count":
224224
counters.LipCount = *vp.PUInt64()
225225
*/
226226
case "loss_of_signal_count":
227-
counters.LossOfSignalCount = *vp.PUInt64()
227+
counters.LossOfSignalCount = vp.PUInt64()
228228
case "loss_of_sync_count":
229-
counters.LossOfSyncCount = *vp.PUInt64()
229+
counters.LossOfSyncCount = vp.PUInt64()
230230
case "nos_count":
231-
counters.NosCount = *vp.PUInt64()
231+
counters.NosCount = vp.PUInt64()
232232
/*
233233
case "prim_seq_protocol_err_count":
234234
counters.PrimSeqProtocolErrCount = *vp.PUInt64()
235235
*/
236236
case "rx_frames":
237-
counters.RXFrames = *vp.PUInt64()
237+
counters.RXFrames = vp.PUInt64()
238238
case "rx_words":
239-
counters.RXWords = *vp.PUInt64()
239+
counters.RXWords = vp.PUInt64()
240240
case "seconds_since_last_reset":
241-
counters.SecondsSinceLastReset = *vp.PUInt64()
241+
counters.SecondsSinceLastReset = vp.PUInt64()
242242
case "tx_frames":
243-
counters.TXFrames = *vp.PUInt64()
243+
counters.TXFrames = vp.PUInt64()
244244
case "tx_words":
245-
counters.TXWords = *vp.PUInt64()
245+
counters.TXWords = vp.PUInt64()
246246
}
247247

248248
if err := vp.Err(); err != nil {

sysfs/class_fibrechannel_test.go

Lines changed: 98 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -33,55 +33,109 @@ func TestFibreChannelClass(t *testing.T) {
3333
t.Fatal(err)
3434
}
3535

36+
// "host0" FibreChannelHost constants.
37+
var (
38+
name0 = "host0"
39+
speed0 = "16 Gbit"
40+
portState0 = "Online"
41+
portType0 = "Point-To-Point (direct nport connection)"
42+
portName0 = "1000e0071bce95f2"
43+
symbolicName0 = "Emulex SN1100E2P FV12.4.270.3 DV12.4.0.0. HN:gotest. OS:Linux"
44+
nodeName0 = "2000e0071bce95f2"
45+
portID0 = "000002"
46+
fabricName0 = "0"
47+
devLossTMO0 = "30"
48+
supportedClasses0 = "Class 3"
49+
supportedSpeeds0 = "4 Gbit, 8 Gbit, 16 Gbit"
50+
51+
// "host0" FibreChannelHost.Counters constants.
52+
dumpedFrames0 = ^uint64(0)
53+
errorFrames0 = uint64(0)
54+
invalidCRCCount0 = uint64(0x2)
55+
rxFrames0 = uint64(0x3)
56+
rxWords0 = uint64(0x4)
57+
txFrames0 = uint64(0x5)
58+
txWords0 = uint64(0x6)
59+
secondsSinceLastReset0 = uint64(0x7)
60+
invalidTXWordCount0 = uint64(0x8)
61+
linkFailureCount0 = uint64(0x9)
62+
lossOfSyncCount0 = uint64(0x10)
63+
lossOfSignalCount0 = uint64(0x11)
64+
nosCount0 = uint64(0x12)
65+
fcpPacketAborts0 = uint64(0x13)
66+
)
67+
68+
// "host1" FibreChannelHost constants.
69+
var (
70+
name1 = "host1"
71+
portState1 = "Online"
72+
73+
// "host1" FibreChannelHost.Counters constants.
74+
dumpedFrames1 = uint64(0)
75+
errorFrames1 = ^uint64(0)
76+
invalidCRCCount1 = uint64(0x20)
77+
rxFrames1 = uint64(0x30)
78+
rxWords1 = uint64(0x40)
79+
txFrames1 = uint64(0x50)
80+
txWords1 = uint64(0x60)
81+
secondsSinceLastReset1 = uint64(0x70)
82+
invalidTXWordCount1 = uint64(0x80)
83+
linkFailureCount1 = uint64(0x90)
84+
lossOfSyncCount1 = uint64(0x100)
85+
lossOfSignalCount1 = uint64(0x110)
86+
nosCount1 = uint64(0x120)
87+
fcpPacketAborts1 = uint64(0x130)
88+
)
89+
3690
want := FibreChannelClass{
3791
"host0": FibreChannelHost{
38-
Name: "host0",
39-
Speed: "16 Gbit",
40-
PortState: "Online",
41-
PortType: "Point-To-Point (direct nport connection)",
42-
PortName: "1000e0071bce95f2",
43-
SymbolicName: "Emulex SN1100E2P FV12.4.270.3 DV12.4.0.0. HN:gotest. OS:Linux",
44-
NodeName: "2000e0071bce95f2",
45-
PortID: "000002",
46-
FabricName: "0",
47-
DevLossTMO: "30",
48-
SupportedClasses: "Class 3",
49-
SupportedSpeeds: "4 Gbit, 8 Gbit, 16 Gbit",
50-
Counters: FibreChannelCounters{
51-
DumpedFrames: ^uint64(0),
52-
ErrorFrames: 0,
53-
InvalidCRCCount: 0x2,
54-
RXFrames: 0x3,
55-
RXWords: 0x4,
56-
TXFrames: 0x5,
57-
TXWords: 0x6,
58-
SecondsSinceLastReset: 0x7,
59-
InvalidTXWordCount: 0x8,
60-
LinkFailureCount: 0x9,
61-
LossOfSyncCount: 0x10,
62-
LossOfSignalCount: 0x11,
63-
NosCount: 0x12,
64-
FCPPacketAborts: 0x13,
92+
Name: &name0,
93+
Speed: &speed0,
94+
PortState: &portState0,
95+
PortType: &portType0,
96+
PortName: &portName0,
97+
SymbolicName: &symbolicName0,
98+
NodeName: &nodeName0,
99+
PortID: &portID0,
100+
FabricName: &fabricName0,
101+
DevLossTMO: &devLossTMO0,
102+
SupportedClasses: &supportedClasses0,
103+
SupportedSpeeds: &supportedSpeeds0,
104+
Counters: &FibreChannelCounters{
105+
DumpedFrames: &dumpedFrames0,
106+
ErrorFrames: &errorFrames0,
107+
InvalidCRCCount: &invalidCRCCount0,
108+
RXFrames: &rxFrames0,
109+
RXWords: &rxWords0,
110+
TXFrames: &txFrames0,
111+
TXWords: &txWords0,
112+
SecondsSinceLastReset: &secondsSinceLastReset0,
113+
InvalidTXWordCount: &invalidTXWordCount0,
114+
LinkFailureCount: &linkFailureCount0,
115+
LossOfSyncCount: &lossOfSyncCount0,
116+
LossOfSignalCount: &lossOfSignalCount0,
117+
NosCount: &nosCount0,
118+
FCPPacketAborts: &fcpPacketAborts0,
65119
},
66120
},
67121
"host1": FibreChannelHost{
68-
Name: "host1",
69-
PortState: "Online",
70-
Counters: FibreChannelCounters{
71-
DumpedFrames: 0,
72-
ErrorFrames: ^uint64(0),
73-
InvalidCRCCount: 0x20,
74-
RXFrames: 0x30,
75-
RXWords: 0x40,
76-
TXFrames: 0x50,
77-
TXWords: 0x60,
78-
SecondsSinceLastReset: 0x70,
79-
InvalidTXWordCount: 0x80,
80-
LinkFailureCount: 0x90,
81-
LossOfSyncCount: 0x100,
82-
LossOfSignalCount: 0x110,
83-
NosCount: 0x120,
84-
FCPPacketAborts: 0x130,
122+
Name: &name1,
123+
PortState: &portState1,
124+
Counters: &FibreChannelCounters{
125+
DumpedFrames: &dumpedFrames1,
126+
ErrorFrames: &errorFrames1,
127+
InvalidCRCCount: &invalidCRCCount1,
128+
RXFrames: &rxFrames1,
129+
RXWords: &rxWords1,
130+
TXFrames: &txFrames1,
131+
TXWords: &txWords1,
132+
SecondsSinceLastReset: &secondsSinceLastReset1,
133+
InvalidTXWordCount: &invalidTXWordCount1,
134+
LinkFailureCount: &linkFailureCount1,
135+
LossOfSyncCount: &lossOfSyncCount1,
136+
LossOfSignalCount: &lossOfSignalCount1,
137+
NosCount: &nosCount1,
138+
FCPPacketAborts: &fcpPacketAborts1,
85139
},
86140
},
87141
}

0 commit comments

Comments
 (0)