2 * Unix SMB/CIFS implementation.
3 * Support for OneFS protocol statistics / perfcounters
5 * Copyright (C) Todd Stecher 2008
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include <sys/isi_stats_protocol.h>
23 #include <sys/isi_stats_cifs.h>
25 struct onefs_op_counter
{
26 struct isp_op_delta iod
;
27 struct onefs_op_counter
*next
;
28 struct onefs_op_counter
*prev
;
31 struct onefs_stats_context
{
33 struct isp_op_delta iod
;
35 /* ANDX commands stats stored here */
36 struct onefs_op_counter
*ops_chain
;
39 const char *onefs_stat_debug(struct isp_op_delta
*iod
);
41 struct onefs_stats_context g_context
;
43 static void onefs_smb_statistics_end(struct smb_perfcount_data
*pcd
);
45 struct isp_op_delta
*onefs_stats_get_op_delta(struct onefs_stats_context
*ctxt
)
47 /* operate on head of chain */
48 if (ctxt
->ops_chain
) {
49 #ifdef ONEFS_PERF_DEBUG
50 DEBUG(0,("************* CHAINED *****\n"));
52 return &ctxt
->ops_chain
->iod
;
57 /* statistics operations */
58 static void onefs_smb_statistics_start(struct smb_perfcount_data
*pcd
)
61 #ifdef ONEFS_PERF_DEBUG
62 if (g_context
.iod
.op
) {
63 DEBUG(0,("**************** OP Collision! %s(%d) \n",
64 onefs_stat_debug(&g_context
.iod
), g_context
.iod
.op
));
69 ISP_OP_BEG(&g_context
.iod
, ISP_PROTO_CIFS
, 0);
71 if (g_context
.iod
.enabled
)
72 pcd
->context
= &g_context
;
79 static void onefs_smb_statistics_add(struct smb_perfcount_data
*pcd
)
81 struct onefs_op_counter
*oc
;
82 struct onefs_stats_context
*ctxt
= pcd
->context
;
85 if (pcd
->context
== NULL
)
88 oc
= SMB_MALLOC_P(struct onefs_op_counter
);
93 #ifdef ONEFS_PERF_DEBUG
94 DEBUG(0,("*********** add chained op \n"));
97 DLIST_ADD(ctxt
->ops_chain
, oc
);
98 ISP_OP_BEG(&oc
->iod
, ISP_PROTO_CIFS
, 0);
101 static void onefs_smb_statistics_set_op(struct smb_perfcount_data
*pcd
, int op
)
103 struct onefs_stats_context
*ctxt
= pcd
->context
;
104 struct isp_op_delta
*iod
;
107 if (pcd
->context
== NULL
)
111 iod
= onefs_stats_get_op_delta(ctxt
);
112 iod
->op
= isp_cifs_op_id(op
);
114 #ifdef ONEFS_PERF_DEBUG
115 DEBUG(0,("***********SET op %s(%d)\n", onefs_stat_debug(iod
), op
));
117 /* no reply required */
118 if (op
== SMBntcancel
)
119 onefs_smb_statistics_end(pcd
);
123 static void onefs_smb_statistics_set_subop(struct smb_perfcount_data
*pcd
,
126 struct onefs_stats_context
*ctxt
= pcd
->context
;
127 struct isp_op_delta
*iod
;
130 if (pcd
->context
== NULL
)
133 iod
= onefs_stats_get_op_delta(ctxt
);
134 iod
->op
= isp_cifs_sub_op_id(iod
->op
, subop
);
136 #ifdef ONEFS_PERF_DEBUG
137 DEBUG(0,("******************** SET subop %s(%d)\n",
138 onefs_stat_debug(iod
), subop
));
142 * finalize this one - we don't need to know when it
143 * is set, but its useful as a counter
145 if (subop
== NT_TRANSACT_NOTIFY_CHANGE
)
146 onefs_smb_statistics_end(pcd
);
149 static void onefs_smb_statistics_set_ioctl(struct smb_perfcount_data
*pcd
,
152 struct onefs_stats_context
*ctxt
= pcd
->context
;
153 struct isp_op_delta
*iod
;
156 if (pcd
->context
== NULL
)
159 /* we only monitor shadow copy */
160 if (io_ctl
!= FSCTL_GET_SHADOW_COPY_DATA
)
163 iod
= onefs_stats_get_op_delta(ctxt
);
164 iod
->op
= isp_cifs_sub_op_id(iod
->op
, ISP_CIFS_NTRN_IOCTL_FGSCD
);
165 #ifdef ONEFS_PERF_DEBUG
166 DEBUG(0,("******************** SET ioctl %s(%d)\n",
167 onefs_stat_debug(iod
), io_ctl
));
171 static void onefs_smb_statistics_set_msglen_in(struct smb_perfcount_data
*pcd
,
174 struct onefs_stats_context
*ctxt
= pcd
->context
;
175 struct isp_op_delta
*iod
;
178 if (pcd
->context
== NULL
)
181 iod
= onefs_stats_get_op_delta(ctxt
);
182 iod
->in_bytes
= in_bytes
;
185 static void onefs_smb_statistics_set_msglen_out(struct smb_perfcount_data
*pcd
,
188 struct onefs_stats_context
*ctxt
= pcd
->context
;
191 if (pcd
->context
== NULL
)
195 ctxt
->ops_chain
->iod
.out_bytes
= out_bytes
;
197 ctxt
->iod
.out_bytes
= out_bytes
;
201 * For perf reasons, we usually use the global - sometimes, though,
202 * when an operation is deferred, we need to alloc a copy.
204 static void onefs_smb_statistics_defer_op(struct smb_perfcount_data
*pcd
,
205 struct smb_perfcount_data
*def_pcd
)
207 struct onefs_stats_context
*ctxt
= pcd
->context
;
208 struct onefs_stats_context
*deferred_ctxt
;
211 if (pcd
->context
== NULL
)
214 /* already allocated ? */
217 def_pcd
->context
= ctxt
;
223 #ifdef ONEFS_PERF_DEBUG
224 DEBUG(0,("******** DEFERRING op %s(%d)\n",
225 onefs_stat_debug(&ctxt
->iod
), ctxt
->iod
.op
));
228 /* make an alloc'd copy of the data */
229 deferred_ctxt
= SMB_MALLOC_P(struct onefs_stats_context
);
230 if (!deferred_ctxt
) {
231 /* disable for now - we'll get bogus stats, though */
232 def_pcd
->context
= NULL
;
236 memcpy(deferred_ctxt
, ctxt
, sizeof(struct onefs_stats_context
));
237 deferred_ctxt
->deferred
= True
;
238 def_pcd
->context
= (void*) deferred_ctxt
;
240 /* instrumentation */
241 if (ctxt
== &g_context
)
242 ZERO_STRUCT(g_context
);
248 static void onefs_smb_statistics_set_client(struct smb_perfcount_data
*pcd
,
249 uid_t uid
, const char *user
,
252 // not implemented...
256 static void onefs_smb_statistics_end(struct smb_perfcount_data
*pcd
)
258 struct onefs_stats_context
*ctxt
= pcd
->context
;
259 struct onefs_op_counter
*tmp
;
262 if (pcd
->context
== NULL
)
266 * bug here - we aren't getting the outlens right,
267 * when dealing w/ chained requests.
269 for (tmp
= ctxt
->ops_chain
; tmp
; tmp
= tmp
->next
) {
270 tmp
->iod
.out_bytes
= ctxt
->iod
.out_bytes
;
271 ISP_OP_END(&tmp
->iod
);
272 #ifdef ONEFS_PERF_DEBUG
273 DEBUG(0,("******** Finalized CHAIN op %s in:%llu, out:%llu\n",
274 onefs_stat_debug(&tmp
->iod
),
275 tmp
->iod
.in_bytes
, tmp
->iod
.out_bytes
));
277 SAFE_FREE(tmp
->prev
);
280 ISP_OP_END(&ctxt
->iod
);
281 #ifdef ONEFS_PERF_DEBUG
282 DEBUG(0,("******** Finalized op %s in:%llu, out:%llu\n",
283 onefs_stat_debug(&ctxt
->iod
),
284 ctxt
->iod
.in_bytes
, ctxt
->iod
.out_bytes
));
296 static struct smb_perfcount_handlers onefs_pc_handlers
= {
297 onefs_smb_statistics_start
,
298 onefs_smb_statistics_add
,
299 onefs_smb_statistics_set_op
,
300 onefs_smb_statistics_set_subop
,
301 onefs_smb_statistics_set_ioctl
,
302 onefs_smb_statistics_set_msglen_in
,
303 onefs_smb_statistics_set_msglen_out
,
304 onefs_smb_statistics_set_client
,
305 onefs_smb_statistics_defer_op
,
306 onefs_smb_statistics_end
309 NTSTATUS
perfcount_onefs_init(void)
311 return smb_register_perfcounter(SMB_PERFCOUNTER_INTERFACE_VERSION
,
312 "pc_onefs", &onefs_pc_handlers
);
315 #ifdef ONEFS_PERF_DEBUG
322 struct op_debug op_debug_table
[] = {
323 { 0x00, "mkdir"}, { 0x01, "rmdir"}, { 0x02, "open"}, { 0x03, "create"},
324 { 0x04, "close"}, { 0x05, "flush"}, { 0x06, "unlink"}, { 0x07, "mv"},
325 { 0x08, "getatr"}, { 0x09, "setatr"}, { 0x0a, "read"}, { 0x0b, "write"},
326 { 0x0c, "lock"}, { 0x0d, "unlock"}, { 0x0e, "ctemp"}, { 0x0f, "mknew"},
327 { 0x10, "chkpth"}, { 0x11, "exit"}, { 0x12, "lseek"}, { 0x13, "lockread"},
328 { 0x14, "writeunlock"}, { 0x1a, "readbraw"}, { 0x1b, "readbmpx"},
329 { 0x1c, "readbs"}, { 0x1d, "writebraw"}, { 0x1e, "writebmpx"},
330 { 0x1f, "writebs"}, { 0x20, "writec"}, { 0x22, "setattre"},
331 { 0x23, "getattre"}, { 0x24, "lockingx"}, { 0x25, "trans"},
332 { 0x26, "transs"}, { 0x27, "ioctl"}, { 0x28, "ioctls"}, { 0x29, "copy"},
333 { 0x2a, "move"}, { 0x2b, "echo"}, { 0x2c, "writeclose"}, { 0x2d, "openx"},
334 { 0x2e, "readx"}, { 0x2f, "writex"}, { 0x34, "findclose"},
335 { 0x35, "findnclose"}, { 0x70, "tcon"}, { 0x71, "tdis"},
336 { 0x72, "negprot"}, { 0x73, "sesssetupx"}, { 0x74, "ulogoffx"},
337 { 0x75, "tconx"}, { 0x80, "dskattr"}, { 0x81, "search"},
338 { 0x82, "ffirst"}, { 0x83, "funique"}, { 0x84, "fclose"},
339 { 0x400, "nttrans"},{ 0x500, "nttranss"},
340 { 0xa2, "ntcreatex"}, { 0xa4, "ntcancel"}, { 0xa5, "ntrename"},
341 { 0xc0, "splopen"}, { 0xc1, "splwr"}, { 0xc2, "splclose"},
342 { 0xc3, "splretq"}, { 0xd0, "sends"}, { 0xd1, "sendb"},
343 { 0xd2, "fwdname"}, { 0xd3, "cancelf"}, { 0xd4, "getmac"},
344 { 0xd5, "sendstrt"}, { 0xd6, "sendend"}, { 0xd7, "sendtxt"},
345 { ISP_CIFS_INVALID_OP
, "unknown"},
346 { ISP_CIFS_TRNS2
+ 0x00, "trans2:open"},
347 { ISP_CIFS_TRNS2
+ 0x01, "trans2:findfirst"},
348 { ISP_CIFS_TRNS2
+ 0x02, "trans2:findnext"},
349 { ISP_CIFS_TRNS2
+ 0x03, "trans2:qfsinfo"},
350 { ISP_CIFS_TRNS2
+ 0x04, "trans2:setfsinfo"},
351 { ISP_CIFS_TRNS2
+ 0x05, "trans2:qpathinfo"},
352 { ISP_CIFS_TRNS2
+ 0x06, "trans2:setpathinfo"},
353 { ISP_CIFS_TRNS2
+ 0x07, "trans2:qfileinfo"},
354 { ISP_CIFS_TRNS2
+ 0x08, "trans2:setfileinfo"},
355 { ISP_CIFS_TRNS2
+ 0x0a, "trans2:ioctl"},
356 { ISP_CIFS_TRNS2
+ 0x0b, "trans2:findnotifyfirst"},
357 { ISP_CIFS_TRNS2
+ 0x0c, "trans2:findnotifynext"},
358 { ISP_CIFS_TRNS2
+ 0x0d, "trans2:mkdir"},
359 { ISP_CIFS_TRNS2
+ 0x10, "trans2:get_dfs_ref"},
360 { ISP_CIFS_TRNS2
+ ISP_CIFS_SUBOP_UNKNOWN
, "trans2:unknown"},
361 { ISP_CIFS_TRNSS2
+0x00, "transs2:open"},
362 { ISP_CIFS_TRNSS2
+0x01, "transs2:findfirst"},
363 { ISP_CIFS_TRNSS2
+0x02, "transs2:findnext"},
364 { ISP_CIFS_TRNSS2
+0x03, "transs2:qfsinfo"},
365 { ISP_CIFS_TRNSS2
+0x04, "transs2:setfsinfo"},
366 { ISP_CIFS_TRNSS2
+0x05, "transs2:qpathinfo"},
367 { ISP_CIFS_TRNSS2
+0x06, "transs2:setpathinfo"},
368 { ISP_CIFS_TRNSS2
+0x07, "transs2:qfileinfo"},
369 { ISP_CIFS_TRNSS2
+0x08, "transs2:setfileinfo"},
370 { ISP_CIFS_TRNSS2
+0x0a, "transs2:ioctl"},
371 { ISP_CIFS_TRNSS2
+0x0b, "transs2:findnotifyfirst"},
372 { ISP_CIFS_TRNSS2
+0x0c, "transs2:findnotifynext"},
373 { ISP_CIFS_TRNSS2
+0x0d, "transs2:mkdir"},
374 { ISP_CIFS_TRNSS2
+0x10, "transs2:get_dfs_referral"},
375 { ISP_CIFS_TRNSS2
+ ISP_CIFS_SUBOP_UNKNOWN
, "transs2:unknown"},
376 { ISP_CIFS_NTRNS
+ 0x1, "nttrans:create"},
377 { ISP_CIFS_NTRNS
+ 0x2, "nttrans:ioctl"},
378 { ISP_CIFS_NTRNS
+ 0x3, "nttrans:set_security_desc"},
379 { ISP_CIFS_NTRNS
+ 0x4, "nttrans:notify_change"},
380 { ISP_CIFS_NTRNS
+ 0x5, "nttrans:rename"},
381 { ISP_CIFS_NTRNS
+ 0x6, "nttrans:qry_security_desc"},
382 { ISP_CIFS_NTRNS
+ 0x7, "nttrans:get_user_quota"},
383 { ISP_CIFS_NTRNS
+ 0x8, "nttrans:set_user_quota"},
384 { ISP_CIFS_NTRNS
+ ISP_CIFS_NTRN_IOCTL_FGSCD
,
385 "nttrans:ioctl:get_shadow_copy_data"},
386 { ISP_CIFS_NTRNS
+ ISP_CIFS_SUBOP_UNKNOWN
,
388 { ISP_CIFS_NTRNSS
+ 0x1, "nttranss:create"},
389 { ISP_CIFS_NTRNSS
+ 0x2, "nttranss:ioctl"},
390 { ISP_CIFS_NTRNSS
+ 0x3, "nttranss:set_security_desc"},
391 { ISP_CIFS_NTRNSS
+ 0x4, "nttranss:notify_change"},
392 { ISP_CIFS_NTRNSS
+ 0x5, "nttranss:rename"},
393 { ISP_CIFS_NTRNSS
+ 0x6, "nttranss:qry_security_desc"},
394 { ISP_CIFS_NTRNSS
+ 0x7, "nttranss:get_user_quota"},
395 { ISP_CIFS_NTRNSS
+ 0x8, "nttranss:set_user_quota"},
396 { ISP_CIFS_NTRNSS
+ ISP_CIFS_NTRN_IOCTL_FGSCD
,
397 "nttranss:ioctl:get_shadow_copy_data"},
398 { ISP_CIFS_NTRNSS
+ ISP_CIFS_SUBOP_UNKNOWN
,
402 int op_debug_table_count
= sizeof(op_debug_table
) / sizeof(op_debug_table
[0]);
404 const char *onefs_stat_debug(struct isp_op_delta
*iod
)
407 const char *unk
= "unknown";
408 for (i
=0; i
< op_debug_table_count
;i
++) {
409 if (iod
->op
== op_debug_table
[i
].type
)
410 return op_debug_table
[i
].name
;