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_client.h>
24 #include <sys/isi_stats_cifs.h>
26 extern struct current_user current_user
;
28 struct onefs_op_counter
{
29 struct isp_op_delta iod
;
30 struct onefs_op_counter
*next
;
31 struct onefs_op_counter
*prev
;
34 struct onefs_stats_context
{
36 struct isp_op_delta iod
;
38 /* ANDX commands stats stored here */
39 struct onefs_op_counter
*ops_chain
;
42 const char *onefs_stat_debug(struct isp_op_delta
*iod
);
44 struct onefs_stats_context g_context
;
46 static void onefs_smb_statistics_end(struct smb_perfcount_data
*pcd
);
48 struct isp_op_delta
*onefs_stats_get_op_delta(struct onefs_stats_context
*ctxt
)
50 /* operate on head of chain */
51 if (ctxt
->ops_chain
) {
52 #ifdef ONEFS_PERF_DEBUG
53 DEBUG(0,("************* CHAINED *****\n"));
55 return &ctxt
->ops_chain
->iod
;
60 /* statistics operations */
61 static void onefs_smb_statistics_start(struct smb_perfcount_data
*pcd
)
64 #ifdef ONEFS_PERF_DEBUG
65 if (g_context
.iod
.op
) {
66 DEBUG(0,("**************** OP Collision! %s(%d) \n",
67 onefs_stat_debug(&g_context
.iod
), g_context
.iod
.op
));
72 ISP_OP_BEG(&g_context
.iod
, ISP_PROTO_CIFS
, 0);
74 if (g_context
.iod
.enabled
)
75 pcd
->context
= &g_context
;
82 static void onefs_smb_statistics_add(struct smb_perfcount_data
*pcd
)
84 struct onefs_op_counter
*oc
;
85 struct onefs_stats_context
*ctxt
= pcd
->context
;
88 if (pcd
->context
== NULL
)
91 oc
= SMB_MALLOC_P(struct onefs_op_counter
);
96 #ifdef ONEFS_PERF_DEBUG
97 DEBUG(0,("*********** add chained op \n"));
100 DLIST_ADD(ctxt
->ops_chain
, oc
);
101 ISP_OP_BEG(&oc
->iod
, ISP_PROTO_CIFS
, 0);
104 static void onefs_smb_statistics_set_op(struct smb_perfcount_data
*pcd
, int op
)
106 struct onefs_stats_context
*ctxt
= pcd
->context
;
107 struct isp_op_delta
*iod
;
110 if (pcd
->context
== NULL
)
113 iod
= onefs_stats_get_op_delta(ctxt
);
114 iod
->op
= isp_cifs_op_id(op
);
116 #ifdef ONEFS_PERF_DEBUG
117 DEBUG(0,("***********SET op %s(%d)\n", onefs_stat_debug(iod
), op
));
119 /* no reply required */
120 if (op
== SMBntcancel
)
121 onefs_smb_statistics_end(pcd
);
125 static void onefs_smb_statistics_set_subop(struct smb_perfcount_data
*pcd
,
128 struct onefs_stats_context
*ctxt
= pcd
->context
;
129 struct isp_op_delta
*iod
;
132 if (pcd
->context
== NULL
)
135 iod
= onefs_stats_get_op_delta(ctxt
);
136 iod
->op
= isp_cifs_sub_op_id(iod
->op
, subop
);
138 #ifdef ONEFS_PERF_DEBUG
139 DEBUG(0,("******************** SET subop %s(%d)\n",
140 onefs_stat_debug(iod
), subop
));
144 * finalize this one - we don't need to know when it
145 * is set, but its useful as a counter
147 if (subop
== NT_TRANSACT_NOTIFY_CHANGE
)
148 onefs_smb_statistics_end(pcd
);
151 static void onefs_smb_statistics_set_ioctl(struct smb_perfcount_data
*pcd
,
154 struct onefs_stats_context
*ctxt
= pcd
->context
;
155 struct isp_op_delta
*iod
;
158 if (pcd
->context
== NULL
)
161 /* we only monitor shadow copy */
162 if (io_ctl
!= FSCTL_GET_SHADOW_COPY_DATA
)
165 iod
= onefs_stats_get_op_delta(ctxt
);
166 iod
->op
= isp_cifs_sub_op_id(iod
->op
, ISP_CIFS_NTRN_IOCTL_FGSCD
);
167 #ifdef ONEFS_PERF_DEBUG
168 DEBUG(0,("******************** SET ioctl %s(%d)\n",
169 onefs_stat_debug(iod
), io_ctl
));
173 static void onefs_smb_statistics_set_msglen_in(struct smb_perfcount_data
*pcd
,
176 struct onefs_stats_context
*ctxt
= pcd
->context
;
177 struct isp_op_delta
*iod
;
180 if (pcd
->context
== NULL
)
183 iod
= onefs_stats_get_op_delta(ctxt
);
184 iod
->in_bytes
= in_bytes
;
187 static void onefs_smb_statistics_set_msglen_out(struct smb_perfcount_data
*pcd
,
190 struct onefs_stats_context
*ctxt
= pcd
->context
;
193 if (pcd
->context
== NULL
)
197 ctxt
->ops_chain
->iod
.out_bytes
= out_bytes
;
199 ctxt
->iod
.out_bytes
= out_bytes
;
202 static int onefs_copy_perfcount_context(struct onefs_stats_context
*ctxt
,
203 struct onefs_stats_context
**dest
)
205 struct onefs_stats_context
*new_ctxt
;
207 /* make an alloc'd copy of the data */
208 new_ctxt
= SMB_MALLOC_P(struct onefs_stats_context
);
213 memcpy(new_ctxt
, ctxt
, sizeof(struct onefs_stats_context
));
214 new_ctxt
->alloced
= True
;
219 static void onefs_smb_statistics_copy_context(struct smb_perfcount_data
*pcd
,
220 struct smb_perfcount_data
*dest
)
222 struct onefs_stats_context
*ctxt
= pcd
->context
;
223 struct onefs_stats_context
*new_ctxt
;
227 if (pcd
->context
== NULL
)
230 #ifdef ONEFS_PERF_DEBUG
231 DEBUG(0,("******** COPYING op %s(%d)\n",
232 onefs_stat_debug(&ctxt
->iod
), ctxt
->iod
.op
));
235 ret
= onefs_copy_perfcount_context(ctxt
, &new_ctxt
);
239 /* instrumentation */
240 if (ctxt
== &g_context
)
241 ZERO_STRUCT(g_context
);
243 dest
->context
= new_ctxt
;
247 * For perf reasons, we usually use the global - sometimes, though,
248 * when an operation is deferred, we need to alloc a copy.
250 static void onefs_smb_statistics_defer_op(struct smb_perfcount_data
*pcd
,
251 struct smb_perfcount_data
*def_pcd
)
253 struct onefs_stats_context
*ctxt
= pcd
->context
;
254 struct onefs_stats_context
*deferred_ctxt
;
258 if (pcd
->context
== NULL
)
261 /* already allocated ? */
264 def_pcd
->context
= ctxt
;
269 #ifdef ONEFS_PERF_DEBUG
270 DEBUG(0,("******** DEFERRING op %s(%d)\n",
271 onefs_stat_debug(&ctxt
->iod
), ctxt
->iod
.op
));
274 ret
= onefs_copy_perfcount_context(ctxt
, &deferred_ctxt
);
278 def_pcd
->context
= (void*) deferred_ctxt
;
280 /* instrumentation */
281 if (ctxt
== &g_context
)
282 ZERO_STRUCT(g_context
);
288 static void onefs_smb_statistics_end(struct smb_perfcount_data
*pcd
)
290 struct onefs_stats_context
*ctxt
= pcd
->context
;
291 struct onefs_op_counter
*tmp
;
294 static in_addr_t rem_addr
= 0;
295 static in_addr_t loc_addr
= 0;
298 if (pcd
->context
== NULL
)
301 uid
= current_user
.ut
.uid
? current_user
.ut
.uid
: ISC_UNKNOWN_CLIENT_ID
;
303 /* get address info once, doesn't change for process */
306 #error Isilon, please remove this after testing the code below
310 addr
= talloc_sub_basic(talloc_tos(), "", "", "%I");
312 rem_addr
= interpret_addr(addr
);
315 rem_addr
= ISC_MASKED_ADDR
;
318 addr
= talloc_sub_basic(talloc_tos(), "", "", "%i");
320 loc_addr
= interpret_addr(addr
);
323 loc_addr
= ISC_MASKED_ADDR
;
328 * bug here - we aren't getting the outlens right,
329 * when dealing w/ chained requests.
331 for (tmp
= ctxt
->ops_chain
; tmp
; tmp
= tmp
->next
) {
332 tmp
->iod
.out_bytes
= ctxt
->iod
.out_bytes
;
333 isc_cookie_init(&tmp
->iod
.cookie
, rem_addr
, loc_addr
, uid
);
334 ISP_OP_END(&tmp
->iod
);
335 #ifdef ONEFS_PERF_DEBUG
336 DEBUG(0,("******** Finalized CHAIN op %s uid %llu in:%llu"
338 onefs_stat_debug(&tmp
->iod
), uid
,
339 tmp
->iod
.in_bytes
, tmp
->iod
.out_bytes
));
341 SAFE_FREE(DLIST_PREV(tmp
));
344 isc_cookie_init(&ctxt
->iod
.cookie
, rem_addr
, loc_addr
, uid
);
345 ISP_OP_END(&ctxt
->iod
);
346 #ifdef ONEFS_PERF_DEBUG
347 DEBUG(0,("******** Finalized op %s uid %llu in:%llu, out:%llu\n",
348 onefs_stat_debug(&ctxt
->iod
), uid
,
349 ctxt
->iod
.in_bytes
, ctxt
->iod
.out_bytes
));
361 static struct smb_perfcount_handlers onefs_pc_handlers
= {
362 onefs_smb_statistics_start
,
363 onefs_smb_statistics_add
,
364 onefs_smb_statistics_set_op
,
365 onefs_smb_statistics_set_subop
,
366 onefs_smb_statistics_set_ioctl
,
367 onefs_smb_statistics_set_msglen_in
,
368 onefs_smb_statistics_set_msglen_out
,
369 onefs_smb_statistics_copy_context
,
370 onefs_smb_statistics_defer_op
,
371 onefs_smb_statistics_end
374 NTSTATUS
perfcount_onefs_init(void)
376 return smb_register_perfcounter(SMB_PERFCOUNTER_INTERFACE_VERSION
,
377 "pc_onefs", &onefs_pc_handlers
);
380 #ifdef ONEFS_PERF_DEBUG
387 struct op_debug op_debug_table
[] = {
388 { 0x00, "mkdir"}, { 0x01, "rmdir"}, { 0x02, "open"}, { 0x03, "create"},
389 { 0x04, "close"}, { 0x05, "flush"}, { 0x06, "unlink"}, { 0x07, "mv"},
390 { 0x08, "getatr"}, { 0x09, "setatr"}, { 0x0a, "read"}, { 0x0b, "write"},
391 { 0x0c, "lock"}, { 0x0d, "unlock"}, { 0x0e, "ctemp"}, { 0x0f, "mknew"},
392 { 0x10, "chkpth"}, { 0x11, "exit"}, { 0x12, "lseek"}, { 0x13, "lockread"},
393 { 0x14, "writeunlock"}, { 0x1a, "readbraw"}, { 0x1b, "readbmpx"},
394 { 0x1c, "readbs"}, { 0x1d, "writebraw"}, { 0x1e, "writebmpx"},
395 { 0x1f, "writebs"}, { 0x20, "writec"}, { 0x22, "setattre"},
396 { 0x23, "getattre"}, { 0x24, "lockingx"}, { 0x25, "trans"},
397 { 0x26, "transs"}, { 0x27, "ioctl"}, { 0x28, "ioctls"}, { 0x29, "copy"},
398 { 0x2a, "move"}, { 0x2b, "echo"}, { 0x2c, "writeclose"}, { 0x2d, "openx"},
399 { 0x2e, "readx"}, { 0x2f, "writex"}, { 0x34, "findclose"},
400 { 0x35, "findnclose"}, { 0x70, "tcon"}, { 0x71, "tdis"},
401 { 0x72, "negprot"}, { 0x73, "sesssetupx"}, { 0x74, "ulogoffx"},
402 { 0x75, "tconx"}, { 0x80, "dskattr"}, { 0x81, "search"},
403 { 0x82, "ffirst"}, { 0x83, "funique"}, { 0x84, "fclose"},
404 { 0x400, "nttrans"},{ 0x500, "nttranss"},
405 { 0xa2, "ntcreatex"}, { 0xa4, "ntcancel"}, { 0xa5, "ntrename"},
406 { 0xc0, "splopen"}, { 0xc1, "splwr"}, { 0xc2, "splclose"},
407 { 0xc3, "splretq"}, { 0xd0, "sends"}, { 0xd1, "sendb"},
408 { 0xd2, "fwdname"}, { 0xd3, "cancelf"}, { 0xd4, "getmac"},
409 { 0xd5, "sendstrt"}, { 0xd6, "sendend"}, { 0xd7, "sendtxt"},
410 { ISP_CIFS_INVALID_OP
, "unknown"},
411 { ISP_CIFS_TRNS2
+ 0x00, "trans2:open"},
412 { ISP_CIFS_TRNS2
+ 0x01, "trans2:findfirst"},
413 { ISP_CIFS_TRNS2
+ 0x02, "trans2:findnext"},
414 { ISP_CIFS_TRNS2
+ 0x03, "trans2:qfsinfo"},
415 { ISP_CIFS_TRNS2
+ 0x04, "trans2:setfsinfo"},
416 { ISP_CIFS_TRNS2
+ 0x05, "trans2:qpathinfo"},
417 { ISP_CIFS_TRNS2
+ 0x06, "trans2:setpathinfo"},
418 { ISP_CIFS_TRNS2
+ 0x07, "trans2:qfileinfo"},
419 { ISP_CIFS_TRNS2
+ 0x08, "trans2:setfileinfo"},
420 { ISP_CIFS_TRNS2
+ 0x0a, "trans2:ioctl"},
421 { ISP_CIFS_TRNS2
+ 0x0b, "trans2:findnotifyfirst"},
422 { ISP_CIFS_TRNS2
+ 0x0c, "trans2:findnotifynext"},
423 { ISP_CIFS_TRNS2
+ 0x0d, "trans2:mkdir"},
424 { ISP_CIFS_TRNS2
+ 0x10, "trans2:get_dfs_ref"},
425 { ISP_CIFS_TRNS2
+ ISP_CIFS_SUBOP_UNKNOWN
, "trans2:unknown"},
426 { ISP_CIFS_TRNSS2
+0x00, "transs2:open"},
427 { ISP_CIFS_TRNSS2
+0x01, "transs2:findfirst"},
428 { ISP_CIFS_TRNSS2
+0x02, "transs2:findnext"},
429 { ISP_CIFS_TRNSS2
+0x03, "transs2:qfsinfo"},
430 { ISP_CIFS_TRNSS2
+0x04, "transs2:setfsinfo"},
431 { ISP_CIFS_TRNSS2
+0x05, "transs2:qpathinfo"},
432 { ISP_CIFS_TRNSS2
+0x06, "transs2:setpathinfo"},
433 { ISP_CIFS_TRNSS2
+0x07, "transs2:qfileinfo"},
434 { ISP_CIFS_TRNSS2
+0x08, "transs2:setfileinfo"},
435 { ISP_CIFS_TRNSS2
+0x0a, "transs2:ioctl"},
436 { ISP_CIFS_TRNSS2
+0x0b, "transs2:findnotifyfirst"},
437 { ISP_CIFS_TRNSS2
+0x0c, "transs2:findnotifynext"},
438 { ISP_CIFS_TRNSS2
+0x0d, "transs2:mkdir"},
439 { ISP_CIFS_TRNSS2
+0x10, "transs2:get_dfs_referral"},
440 { ISP_CIFS_TRNSS2
+ ISP_CIFS_SUBOP_UNKNOWN
, "transs2:unknown"},
441 { ISP_CIFS_NTRNS
+ 0x1, "nttrans:create"},
442 { ISP_CIFS_NTRNS
+ 0x2, "nttrans:ioctl"},
443 { ISP_CIFS_NTRNS
+ 0x3, "nttrans:set_security_desc"},
444 { ISP_CIFS_NTRNS
+ 0x4, "nttrans:notify_change"},
445 { ISP_CIFS_NTRNS
+ 0x5, "nttrans:rename"},
446 { ISP_CIFS_NTRNS
+ 0x6, "nttrans:qry_security_desc"},
447 { ISP_CIFS_NTRNS
+ 0x7, "nttrans:get_user_quota"},
448 { ISP_CIFS_NTRNS
+ 0x8, "nttrans:set_user_quota"},
449 { ISP_CIFS_NTRNS
+ ISP_CIFS_NTRN_IOCTL_FGSCD
,
450 "nttrans:ioctl:get_shadow_copy_data"},
451 { ISP_CIFS_NTRNS
+ ISP_CIFS_SUBOP_UNKNOWN
,
453 { ISP_CIFS_NTRNSS
+ 0x1, "nttranss:create"},
454 { ISP_CIFS_NTRNSS
+ 0x2, "nttranss:ioctl"},
455 { ISP_CIFS_NTRNSS
+ 0x3, "nttranss:set_security_desc"},
456 { ISP_CIFS_NTRNSS
+ 0x4, "nttranss:notify_change"},
457 { ISP_CIFS_NTRNSS
+ 0x5, "nttranss:rename"},
458 { ISP_CIFS_NTRNSS
+ 0x6, "nttranss:qry_security_desc"},
459 { ISP_CIFS_NTRNSS
+ 0x7, "nttranss:get_user_quota"},
460 { ISP_CIFS_NTRNSS
+ 0x8, "nttranss:set_user_quota"},
461 { ISP_CIFS_NTRNSS
+ ISP_CIFS_NTRN_IOCTL_FGSCD
,
462 "nttranss:ioctl:get_shadow_copy_data"},
463 { ISP_CIFS_NTRNSS
+ ISP_CIFS_SUBOP_UNKNOWN
,
467 int op_debug_table_count
= sizeof(op_debug_table
) / sizeof(op_debug_table
[0]);
469 const char *onefs_stat_debug(struct isp_op_delta
*iod
)
472 const char *unk
= "unknown";
473 for (i
=0; i
< op_debug_table_count
;i
++) {
474 if (iod
->op
== op_debug_table
[i
].type
)
475 return op_debug_table
[i
].name
;