*/
#include "includes.h"
+#include "smbd/smbd.h"
#define PARM_PC_TEST_TYPE "pc_test"
#define PARM_DUMPON_COUNT "count"
DEBUG(0,("##### Dumping Performance Counters #####\n"));
- for (i=0; i < 256; i++) {
- for (head = g_list[i]; head != NULL; head = head->next) {
- perfcount_test_dump_counter(head, 0);
- head->prev = NULL;
- SAFE_FREE(head->prev);
- }
- SAFE_FREE(head);
+ for (i=0; i < MAX_OP; i++) {
+ struct perfcount_test_counter *next;
+ for (head = g_list[i]; head != NULL; head = next) {
+ next = head->next;
+ perfcount_test_dump_counter(head, 0);
+ SAFE_FREE(head);
+ }
+ g_list[i] = NULL;
}
}
static void perfcount_test_add(struct smb_perfcount_data *pcd)
{
- struct perfcount_test_context *ctxt = pcd->context;
+ struct perfcount_test_context *ctxt =
+ (struct perfcount_test_context *)pcd->context;
struct perfcount_test_counter *ctr;
- if (pcd->context == NULL) {
- DEBUG(0,("perfcount_test_add - uninitialized "
- "perfcount context - %p\n", pcd));
+ if (pcd->context == NULL)
return;
- }
ctr = SMB_MALLOC_P(struct perfcount_test_counter);
if (!ctr) {
static void perfcount_test_set_op(struct smb_perfcount_data *pcd, int op)
{
- struct perfcount_test_context *ctxt = pcd->context;
+ struct perfcount_test_context *ctxt =
+ (struct perfcount_test_context *)pcd->context;
- if (pcd->context == NULL) {
- DEBUG(0,("perfcount_test_set_op - uninitialized "
- "perfcount context - %p\n", pcd));
+ if (pcd->context == NULL)
return;
- }
ctxt->ops->op = op;
}
static void perfcount_test_set_subop(struct smb_perfcount_data *pcd, int sub_op)
{
- struct perfcount_test_context *ctxt = pcd->context;
+ struct perfcount_test_context *ctxt =
+ (struct perfcount_test_context *)pcd->context;
- if (pcd->context == NULL) {
- DEBUG(0,("perfcount_test_set_sub_op - uninitialized "
- "perfcount context - %p\n", pcd));
+ if (pcd->context == NULL)
return;
- }
ctxt->ops->sub_op = sub_op;
}
static void perfcount_test_set_ioctl(struct smb_perfcount_data *pcd, int io_ctl)
{
- struct perfcount_test_context *ctxt = pcd->context;
- if (pcd->context == NULL) {
- DEBUG(0,("perfcount_test_set_ioctl - uninitialized "
- "perfcount context - %p\n", pcd));
+ struct perfcount_test_context *ctxt =
+ (struct perfcount_test_context *)pcd->context;
+ if (pcd->context == NULL)
return;
- }
+
ctxt->ops->ioctl = io_ctl;
}
static void perfcount_test_set_msglen_in(struct smb_perfcount_data *pcd,
uint64_t bytes_in)
{
- struct perfcount_test_context *ctxt = pcd->context;
- if (pcd->context == NULL) {
- DEBUG(0,("perfcount_test_set_msglen_in - "
- "uninitialized perfcount context - %p\n", pcd));
+ struct perfcount_test_context *ctxt =
+ (struct perfcount_test_context *)pcd->context;
+ if (pcd->context == NULL)
return;
- }
+
ctxt->ops->bytes_in = bytes_in;
}
static void perfcount_test_set_msglen_out(struct smb_perfcount_data *pcd,
uint64_t bytes_out)
{
- struct perfcount_test_context *ctxt = pcd->context;
+ struct perfcount_test_context *ctxt =
+ (struct perfcount_test_context *)pcd->context;
- if (pcd->context == NULL) {
- DEBUG(0,("perfcount_test_set_msglen_out - uninitialized "
- "perfcount context - %p\n", pcd));
+ if (pcd->context == NULL)
return;
- }
ctxt->ops->bytes_out = bytes_out;
}
+static void perfcount_test_copy_context(struct smb_perfcount_data *pcd,
+ struct smb_perfcount_data *new_pcd)
+{
+ struct perfcount_test_context *ctxt =
+ (struct perfcount_test_context *)pcd->context;
+ struct perfcount_test_context *new_ctxt;
+
+ struct perfcount_test_counter *ctr;
+ struct perfcount_test_counter *new_ctr;
+
+ if (pcd->context == NULL)
+ return;
+
+ new_ctxt = SMB_MALLOC_P(struct perfcount_test_context);
+ if (!new_ctxt) {
+ return;
+ }
+
+ memcpy(new_ctxt, ctxt, sizeof(struct perfcount_test_context));
+
+ for (ctr = ctxt->ops; ctr != NULL; ctr = ctr->next) {
+ new_ctr = SMB_MALLOC_P(struct perfcount_test_counter);
+ if (!new_ctr) {
+ goto error;
+ }
+
+ memcpy(new_ctr, ctr, sizeof(struct perfcount_test_counter));
+ new_ctr->next = NULL;
+ new_ctr->prev = NULL;
+ DLIST_ADD(new_ctxt->ops, new_ctr);
+ }
+
+ new_pcd->context = new_ctxt;
+ return;
+
+error:
+
+ for (ctr = new_ctxt->ops; ctr != NULL; ) {
+ new_ctr = ctr->next;
+ SAFE_FREE(ctr);
+ ctr = new_ctr;
+ }
+
+ SAFE_FREE(new_ctxt);
+}
+
/*
* For perf reasons, its best to use some global state
* when an operation is deferred, we need to alloc a copy.
struct smb_perfcount_data *def_pcd)
{
/* we don't do anything special to deferred ops */
- if (pcd->context == NULL) {
- DEBUG(0,("perfcount_test_set_msglen_out - uninitialized "
- "perfcount context - %p\n", pcd));
- return;
- }
-}
-
-static void perfcount_test_set_client(struct smb_perfcount_data *pcd,
- uid_t uid, const char *user,
- const char *domain)
-{
- // WIP
return;
}
static void perfcount_test_end(struct smb_perfcount_data *pcd)
{
- struct perfcount_test_context *ctxt = pcd->context;
- if (pcd->context == NULL) {
- DEBUG(0,("perfcount_test_end - uninitialized "
- "perfcount context - %p\n", pcd));
+ struct perfcount_test_context *ctxt =
+ (struct perfcount_test_context *)pcd->context;
+ if (pcd->context == NULL)
return;
- }
/* @bug - we don't store outbytes right for chained cmds */
perfcount_test_add_counters(ctxt);
perfcount_test_dump_counters();
+ pcd->context = NULL;
SAFE_FREE(ctxt);
}
perfcount_test_set_ioctl,
perfcount_test_set_msglen_in,
perfcount_test_set_msglen_out,
- perfcount_test_set_client,
+ perfcount_test_copy_context,
perfcount_test_defer_op,
perfcount_test_end
};
-NTSTATUS perfcount_test_init(void)
+NTSTATUS samba_init_module(void)
{
return smb_register_perfcounter(SMB_PERFCOUNTER_INTERFACE_VERSION,
"pc_test", &perfcount_test_handlers);