forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nfs4.go
255 lines (244 loc) · 5.51 KB
/
nfs4.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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
package nfs
import "fmt"
const (
opAccess = 3
opClose = 4
opCommit = 5
opCreate = 6
opDelegpurge = 7
opDelegreturn = 8
opGetattr = 9
opGetfh = 10
opLink = 11
opLock = 12
opLockt = 13
opLocku = 14
opLookup = 15
opLookupp = 16
opNverify = 17
opOpen = 18
opOpenattr = 19
opOpenConfirm = 20
opOpenDowngrade = 21
opPutfh = 22
opPutpubfh = 23
opPutrootfh = 24
opRead = 25
opReaddir = 26
opReadlink = 27
opRemove = 28
opRename = 29
opRenew = 30
opRestorefh = 31
opSavefh = 32
opSecinfo = 33
opSetattr = 34
opSetclientid = 35
opSetclientidConfirm = 36
opVerify = 37
opWrite = 38
opReleaseLockowner = 39
opBackchannelCtl = 40
opBindConnToSession = 41
opExchangeID = 42
opCreateSession = 43
opDestroySession = 44
opFreeStateid = 45
opGetDirDelegation = 46
opGetdeviceinfo = 47
opGetdevicelist = 48
opLayoutcommit = 49
opLayoutget = 50
opLayoutreturn = 51
opSecinfoNoName = 52
opSequence = 53
opSetSsv = 54
opTestStateid = 55
opWantDelegation = 56
opDestroyClientid = 57
opReclaimComplete = 58
opIllegal = 10044
)
var nfsOpnum4 = map[int]string{
3: "ACCESS",
4: "CLOSE",
5: "COMMIT",
6: "CREATE",
7: "DELEGPURGE",
8: "DELEGRETURN",
9: "GETATTR",
10: "GETFH",
11: "LINK",
12: "LOCK",
13: "LOCKT",
14: "LOCKU",
15: "LOOKUP",
16: "LOOKUPP",
17: "NVERIFY",
18: "OPEN",
19: "OPENATTR",
20: "OPEN_CONFIRM",
21: "OPEN_DOWNGRADE",
22: "PUTFH",
23: "PUTPUBFH",
24: "PUTROOTFH",
25: "READ",
26: "READDIR",
27: "READLINK",
28: "REMOVE",
29: "RENAME",
30: "RENEW",
31: "RESTOREFH",
32: "SAVEFH",
33: "SECINFO",
34: "SETATTR",
35: "SETCLIENTID",
36: "SETCLIENTID_CONFIRM",
37: "VERIFY",
38: "WRITE",
39: "RELEASE_LOCKOWNER",
40: "BACKCHANNEL_CTL",
41: "BIND_CONN_TO_SESSION",
42: "EXCHANGE_ID",
43: "CREATE_SESSION",
44: "DESTROY_SESSION",
45: "FREE_STATEID",
46: "GET_DIR_DELEGATION",
47: "GETDEVICEINFO",
48: "GETDEVICELIST",
49: "LAYOUTCOMMIT",
50: "LAYOUTGET",
51: "LAYOUTRETURN",
52: "SECINFO_NO_NAME",
53: "SEQUENCE",
54: "SET_SSV",
55: "TEST_STATEID",
56: "WANT_DELEGATION",
57: "DESTROY_CLIENTID",
58: "RECLAIM_COMPLETE",
10044: "ILLEGAL",
}
func (nfs *nfs) eatData(op int, xdr *xdr) {
switch op {
case opGetattr:
xdr.getUIntVector()
case opGetfh:
// nothing to eat
case opLookup:
xdr.getDynamicOpaque()
case opLookupp:
// nothing to eat
case opNverify:
xdr.getUIntVector()
xdr.getDynamicOpaque()
case opPutfh:
xdr.getDynamicOpaque()
case opPutpubfh:
// nothing to eat
case opPutrootfh:
// nothing to eat
case opReadlink:
// nothing to eat
case opRenew:
xdr.getUHyper()
case opRestorefh:
// nothing to eat
case opSavefh:
// nothing to eat
case opSecinfo:
xdr.getDynamicOpaque()
case opVerify:
xdr.getUIntVector()
xdr.getDynamicOpaque()
case opSequence:
xdr.getOpaque(16)
xdr.getUInt()
xdr.getUInt()
xdr.getUInt()
xdr.getUInt()
}
}
// findV4MainOpcode finds the main operation in a compound call. If no main operation can be found, the last operation
// in compound call is returned.
//
// Compound requests group multiple nfs operations into a single request. Nevertheless, all compound requests are
// triggered by end-user activity, like 'ls', 'open', 'stat' and IO calls. Depending on which operations are combined
// the main operation can be different. For example, in compound:
//
// PUTFH + READDIR + GETATTR
//
// READDIR is the main operation. while in
//
// PUTFH + GETATTR
//
// GETATTR is the main operation.
func (nfs *nfs) findV4MainOpcode(xdr *xdr) string {
// did we find a main operation opcode?
found := false
// default op code
currentOpname := "ILLEGAL"
opcount := int(xdr.getUInt())
for i := 0; !found && i < opcount; i++ {
op := int(xdr.getUInt())
opname, ok := nfsOpnum4[op]
if !ok {
return fmt.Sprintf("ILLEGAL (%d)", op)
}
currentOpname = opname
switch op {
// First class ops
//
// The first class ops usually the main operation in the compound.
// NFS spec allowes to build compound opertion where multiple
// first class ops are used, like OPEN->LOCK->WRITE->LOCKU->CLOSE,
// but such construnction are not used in the practice.
case
opAccess,
opBackchannelCtl,
opBindConnToSession,
opClose,
opCommit,
opCreate,
opCreateSession,
opDelegpurge,
opDelegreturn,
opDestroyClientid,
opDestroySession,
opExchangeID,
opFreeStateid,
opGetdeviceinfo,
opGetdevicelist,
opGetDirDelegation,
opLayoutcommit,
opLayoutget,
opLayoutreturn,
opLink,
opLock,
opLockt,
opLocku,
opOpen,
opOpenattr,
opOpenConfirm,
opOpenDowngrade,
opRead,
opReaddir,
opReadlink,
opReclaimComplete,
opReleaseLockowner,
opRemove,
opRename,
opSecinfoNoName,
opSetattr,
opSetclientid,
opSetclientidConfirm,
opSetSsv,
opTestStateid,
opWantDelegation,
opWrite:
found = true
default:
nfs.eatData(op, xdr)
}
}
return currentOpname
}