diff options
author | Gerald Carter <jerry@samba.org> | 2005-11-08 16:33:45 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 11:05:21 -0500 |
commit | 77460a90756dcaa54ec12bbcd30a5266286103d7 (patch) | |
tree | aac95461d5cf4b3c0d9dc450bb78e8c2f6fef2d9 /source3 | |
parent | 38b54d063d7fd262902324e5da15205542878adf (diff) | |
download | samba-77460a90756dcaa54ec12bbcd30a5266286103d7.tar.gz samba-77460a90756dcaa54ec12bbcd30a5266286103d7.tar.bz2 samba-77460a90756dcaa54ec12bbcd30a5266286103d7.zip |
r11579: syncing up perf counter code cfrom trunk
(This used to be commit 59c00924b67aa3d37a933731a56d03963ec7f1b5)
Diffstat (limited to 'source3')
-rw-r--r-- | source3/param/loadparm.c | 3 | ||||
-rw-r--r-- | source3/registry/reg_frontend.c | 1 | ||||
-rw-r--r-- | source3/registry/reg_perfcount.c | 214 | ||||
-rw-r--r-- | source3/services/services_db.c | 1 | ||||
-rw-r--r-- | source3/utils/net_rpc_registry.c | 14 |
5 files changed, 184 insertions, 49 deletions
diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index d2cbf380da..d2d739fa72 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -121,7 +121,6 @@ typedef struct char *szConfigFile; char *szSMBPasswdFile; char *szPrivateDir; - char *szCountersDir; char **szPassdbBackend; char **szPreloadModules; char *szPasswordServer; @@ -848,7 +847,6 @@ static struct parm_struct parm_table[] = { {"password server", P_STRING, P_GLOBAL, &Globals.szPasswordServer, NULL, NULL, FLAG_ADVANCED | FLAG_WIZARD}, {"smb passwd file", P_STRING, P_GLOBAL, &Globals.szSMBPasswdFile, NULL, NULL, FLAG_ADVANCED}, {"private dir", P_STRING, P_GLOBAL, &Globals.szPrivateDir, NULL, NULL, FLAG_ADVANCED}, - {"counters dir", P_STRING, P_GLOBAL, &Globals.szCountersDir, NULL, NULL, FLAG_ADVANCED}, {"passdb backend", P_LIST, P_GLOBAL, &Globals.szPassdbBackend, NULL, NULL, FLAG_ADVANCED | FLAG_WIZARD}, {"algorithmic rid base", P_INTEGER, P_GLOBAL, &Globals.AlgorithmicRidBase, NULL, NULL, FLAG_ADVANCED}, {"root directory", P_STRING, P_GLOBAL, &Globals.szRootdir, NULL, NULL, FLAG_ADVANCED}, @@ -1711,7 +1709,6 @@ FN_GLOBAL_STRING(lp_logfile, &Globals.szLogFile) FN_GLOBAL_STRING(lp_configfile, &Globals.szConfigFile) FN_GLOBAL_STRING(lp_smb_passwd_file, &Globals.szSMBPasswdFile) FN_GLOBAL_STRING(lp_private_dir, &Globals.szPrivateDir) -FN_GLOBAL_STRING(lp_counters_dir, &Globals.szCountersDir) FN_GLOBAL_STRING(lp_serverstring, &Globals.szServerString) FN_GLOBAL_INTEGER(lp_printcap_cache_time, &Globals.PrintcapCacheTime) FN_GLOBAL_STRING(lp_enumports_cmd, &Globals.szEnumPortsCommand) diff --git a/source3/registry/reg_frontend.c b/source3/registry/reg_frontend.c index b0e713a882..d5a9d45e8c 100644 --- a/source3/registry/reg_frontend.c +++ b/source3/registry/reg_frontend.c @@ -131,6 +131,7 @@ BOOL init_registry( void ) svcctl_init_keys(); eventlog_init_keys(); + perfcount_init_keys(); /* close and let each smbd open up as necessary */ diff --git a/source3/registry/reg_perfcount.c b/source3/registry/reg_perfcount.c index fe8b355b95..a31154fc33 100644 --- a/source3/registry/reg_perfcount.c +++ b/source3/registry/reg_perfcount.c @@ -1,3 +1,25 @@ +/* + * Unix SMB/CIFS implementation. + * Virtual Windows Registry Layer + * + * Copyright (C) Marcin Krzysztof Porwit 2005, + * Copyright (C) Gerald (Jerry) Carter 2005. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + #include "includes.h" #undef DBGC_CLASS @@ -5,21 +27,54 @@ #define PERFCOUNT_MAX_LEN 256 +#define PERFCOUNTDIR "perfmon" +#define NAMES_DB "names.tdb" +#define DATA_DB "data.tdb" + +/********************************************************************* +*********************************************************************/ + +static char* counters_directory( const char *dbname ) +{ + static pstring fname; + fstring path; + + if ( !dbname ) + return NULL; + + fstr_sprintf( path, "%s/%s", PERFCOUNTDIR, dbname ); + + pstrcpy( fname, lock_path( path ) ); + + return fname; +} + +/********************************************************************* +*********************************************************************/ + +void perfcount_init_keys( void ) +{ + char *p = lock_path(PERFCOUNTDIR); + + /* no registry keys; just create the perfmon directory */ + + if ( !directory_exist( p, NULL ) ) + mkdir( p, 0755 ); + + return; +} + +/********************************************************************* +*********************************************************************/ + uint32 reg_perfcount_get_base_index(void) { - pstring fname; + const char *fname = counters_directory( NAMES_DB ); TDB_CONTEXT *names; TDB_DATA kbuf, dbuf; char key[] = "1"; uint32 retval = 0; char buf[PERFCOUNT_MAX_LEN]; - const char *counter_dir = lp_counters_dir(); - - - if ( !*counter_dir ) - return 0; - - pstr_sprintf( fname, "%s/names.tdb", counter_dir ); names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); @@ -62,6 +117,9 @@ uint32 reg_perfcount_get_base_index(void) return 0; } +/********************************************************************* +*********************************************************************/ + uint32 reg_perfcount_get_last_counter(uint32 base_index) { uint32 retval; @@ -74,6 +132,9 @@ uint32 reg_perfcount_get_last_counter(uint32 base_index) return retval; } +/********************************************************************* +*********************************************************************/ + uint32 reg_perfcount_get_last_help(uint32 last_counter) { uint32 retval; @@ -86,6 +147,10 @@ uint32 reg_perfcount_get_last_help(uint32 last_counter) return retval; } + +/********************************************************************* +*********************************************************************/ + static uint32 _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb, int keyval, char **retbuf, @@ -145,20 +210,20 @@ static uint32 _reg_perfcount_multi_sz_from_tdb(TDB_CONTEXT *tdb, return buffer_size; } +/********************************************************************* +*********************************************************************/ + uint32 reg_perfcount_get_counter_help(uint32 base_index, char **retbuf) { char *buf1 = NULL, *buf2 = NULL; uint32 buffer_size = 0; TDB_CONTEXT *names; - pstring fname; + const char *fname = counters_directory( NAMES_DB ); int i; if(base_index == 0) return 0; - pstrcpy(fname, lp_counters_dir()); - pstrcat(fname, "/names.tdb"); - names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); if(names == NULL) @@ -193,20 +258,20 @@ uint32 reg_perfcount_get_counter_help(uint32 base_index, char **retbuf) return buffer_size; } +/********************************************************************* +*********************************************************************/ + uint32 reg_perfcount_get_counter_names(uint32 base_index, char **retbuf) { char *buf1 = NULL, *buf2 = NULL; uint32 buffer_size = 0; TDB_CONTEXT *names; - pstring fname; + const char *fname = counters_directory( NAMES_DB ); int i; if(base_index == 0) return 0; - pstrcpy(fname, lp_counters_dir()); - pstrcat(fname, "/names.tdb"); - names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); if(names == NULL) @@ -243,6 +308,9 @@ uint32 reg_perfcount_get_counter_names(uint32 base_index, char **retbuf) return buffer_size; } +/********************************************************************* +*********************************************************************/ + static void _reg_perfcount_make_key(TDB_DATA *key, char *buf, int buflen, @@ -261,6 +329,9 @@ static void _reg_perfcount_make_key(TDB_DATA *key, return; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_isparent(TDB_DATA data) { if(data.dsize > 0) @@ -273,6 +344,9 @@ static BOOL _reg_perfcount_isparent(TDB_DATA data) return False; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_ischild(TDB_DATA data) { if(data.dsize > 0) @@ -285,6 +359,9 @@ static BOOL _reg_perfcount_ischild(TDB_DATA data) return False; } +/********************************************************************* +*********************************************************************/ + static uint32 _reg_perfcount_get_numinst(int objInd, TDB_CONTEXT *names) { TDB_DATA key, data; @@ -301,6 +378,9 @@ static uint32 _reg_perfcount_get_numinst(int objInd, TDB_CONTEXT *names) return (uint32)atoi(buf); } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_add_object(PERF_DATA_BLOCK *block, prs_struct *ps, int num, @@ -341,15 +421,14 @@ static BOOL _reg_perfcount_add_object(PERF_DATA_BLOCK *block, return True; } +/********************************************************************* +*********************************************************************/ + BOOL _reg_perfcount_get_counter_data(TDB_DATA key, TDB_DATA *data) { TDB_CONTEXT *counters; - - pstring fname; + const char *fname = counters_directory( DATA_DB ); - pstrcpy(fname, lp_counters_dir()); - pstrcat(fname, "/data.tdb"); - counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); if(counters == NULL) @@ -365,6 +444,9 @@ BOOL _reg_perfcount_get_counter_data(TDB_DATA key, TDB_DATA *data) return True; } +/********************************************************************* +*********************************************************************/ + static uint32 _reg_perfcount_get_size_field(uint32 CounterType) { uint32 retval; @@ -379,7 +461,10 @@ static uint32 _reg_perfcount_get_size_field(uint32 CounterType) return retval; } -static uint32 _reg_perfcount_compute_scale(long long int data) +/********************************************************************* +*********************************************************************/ + +static uint32 _reg_perfcount_compute_scale(SMB_BIG_INT data) { int scale = 0; if(data == 0) @@ -398,6 +483,9 @@ static uint32 _reg_perfcount_compute_scale(long long int data) return (uint32)scale; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_get_counter_info(PERF_DATA_BLOCK *block, prs_struct *ps, int CounterIndex, @@ -408,7 +496,7 @@ static BOOL _reg_perfcount_get_counter_info(PERF_DATA_BLOCK *block, char buf[PERFCOUNT_MAX_LEN]; size_t dsize, padding; long int data32, dbuf[2]; - long long int data64; + SMB_BIG_INT data64; uint32 counter_size; obj->counters[obj->NumCounters].DefaultScale = 0; @@ -447,7 +535,7 @@ static BOOL _reg_perfcount_get_counter_info(PERF_DATA_BLOCK *block, memcpy(buf, data.dptr, data.dsize); data32 = strtol(buf, NULL, 0); if((obj->counters[obj->NumCounters].CounterType & 0x00000F00) == PERF_TYPE_NUMBER) - obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale((long long int)data32); + obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale((SMB_BIG_INT)data32); else obj->counters[obj->NumCounters].DefaultScale = 0; dbuf[0] = data32; @@ -458,7 +546,7 @@ static BOOL _reg_perfcount_get_counter_info(PERF_DATA_BLOCK *block, dsize = sizeof(data64); memset(buf, 0, PERFCOUNT_MAX_LEN); memcpy(buf, data.dptr, data.dsize); - data64 = strtoll(buf, NULL, 0); + data64 = atof(buf); if((obj->counters[obj->NumCounters].CounterType & 0x00000F00) == PERF_TYPE_NUMBER) obj->counters[obj->NumCounters].DefaultScale = _reg_perfcount_compute_scale(data64); else @@ -504,6 +592,9 @@ static BOOL _reg_perfcount_get_counter_info(PERF_DATA_BLOCK *block, return True; } +/********************************************************************* +*********************************************************************/ + PERF_OBJECT_TYPE *_reg_perfcount_find_obj(PERF_DATA_BLOCK *block, int objind) { int i; @@ -521,6 +612,9 @@ PERF_OBJECT_TYPE *_reg_perfcount_find_obj(PERF_DATA_BLOCK *block, int objind) return obj; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_add_counter(PERF_DATA_BLOCK *block, prs_struct *ps, int num, @@ -582,6 +676,9 @@ static BOOL _reg_perfcount_add_counter(PERF_DATA_BLOCK *block, return True; } +/********************************************************************* +*********************************************************************/ + BOOL _reg_perfcount_get_instance_info(PERF_INSTANCE_DEFINITION *inst, prs_struct *ps, int instId, @@ -662,6 +759,9 @@ BOOL _reg_perfcount_get_instance_info(PERF_INSTANCE_DEFINITION *inst, return True; } +/********************************************************************* +*********************************************************************/ + BOOL _reg_perfcount_add_instance(PERF_OBJECT_TYPE *obj, prs_struct *ps, int instInd, @@ -689,6 +789,9 @@ BOOL _reg_perfcount_add_instance(PERF_OBJECT_TYPE *obj, return True; } +/********************************************************************* +*********************************************************************/ + static int _reg_perfcount_assemble_global(PERF_DATA_BLOCK *block, prs_struct *ps, int base_index, @@ -728,7 +831,10 @@ static int _reg_perfcount_assemble_global(PERF_DATA_BLOCK *block, return retval; } -static BOOL _reg_perfcount_get_64(unsigned long long *retval, +/********************************************************************* +*********************************************************************/ + +static BOOL _reg_perfcount_get_64(SMB_BIG_UINT *retval, TDB_CONTEXT *tdb, int key_part1, const char *key_part2) @@ -749,23 +855,21 @@ static BOOL _reg_perfcount_get_64(unsigned long long *retval, memcpy(buf, data.dptr, data.dsize); free(data.dptr); - *retval = strtoll(buf, NULL, 0); + *retval = atof(buf); return True; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_init_data_block_perf(PERF_DATA_BLOCK *block, TDB_CONTEXT *names) { - unsigned long long PerfFreq, PerfTime, PerfTime100nSec; + SMB_BIG_UINT PerfFreq, PerfTime, PerfTime100nSec; TDB_CONTEXT *counters; - BOOL status; - pstring fname; - - status = False; - - pstrcpy(fname, lp_counters_dir()); - pstrcat(fname, "/data.tdb"); + BOOL status = False; + const char *fname = counters_directory( DATA_DB ); counters = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); @@ -803,6 +907,9 @@ static BOOL _reg_perfcount_init_data_block_perf(PERF_DATA_BLOCK *block, return True; } +/********************************************************************* +*********************************************************************/ + static void _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block, prs_struct *ps, TDB_CONTEXT *names) { wpstring temp; @@ -839,6 +946,9 @@ static void _reg_perfcount_init_data_block(PERF_DATA_BLOCK *block, prs_struct *p return; } +/********************************************************************* +*********************************************************************/ + static uint32 _reg_perfcount_perf_data_block_fixup(PERF_DATA_BLOCK *block, prs_struct *ps) { int obj, cnt, inst, pad, i; @@ -923,20 +1033,20 @@ static uint32 _reg_perfcount_perf_data_block_fixup(PERF_DATA_BLOCK *block, prs_s return block->TotalByteLength; } - + +/********************************************************************* +*********************************************************************/ + uint32 reg_perfcount_get_perf_data_block(uint32 base_index, prs_struct *ps, PERF_DATA_BLOCK *block, char *object_ids) { uint32 buffer_size = 0, last_counter; - pstring fname; + const char *fname = counters_directory( NAMES_DB ); TDB_CONTEXT *names; int retval; - - pstrcpy(fname, lp_counters_dir()); - pstrcat(fname, "/names.tdb"); - + names = tdb_open_log(fname, 0, TDB_DEFAULT, O_RDONLY, 0444); if(names == NULL) @@ -966,6 +1076,9 @@ uint32 reg_perfcount_get_perf_data_block(uint32 base_index, return buffer_size + block->HeaderLength; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_marshall_perf_data_block(prs_struct *ps, PERF_DATA_BLOCK block, int depth) { int i; @@ -1017,6 +1130,9 @@ static BOOL _reg_perfcount_marshall_perf_data_block(prs_struct *ps, PERF_DATA_BL return True; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_marshall_perf_counters(prs_struct *ps, PERF_OBJECT_TYPE object, int depth) @@ -1058,6 +1174,9 @@ static BOOL _reg_perfcount_marshall_perf_counters(prs_struct *ps, return True; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_marshall_perf_counter_data(prs_struct *ps, PERF_COUNTER_BLOCK counter_data, int depth) @@ -1078,6 +1197,9 @@ static BOOL _reg_perfcount_marshall_perf_counter_data(prs_struct *ps, return True; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_marshall_perf_instances(prs_struct *ps, PERF_OBJECT_TYPE object, int depth) @@ -1116,6 +1238,9 @@ static BOOL _reg_perfcount_marshall_perf_instances(prs_struct *ps, return True; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_marshall_perf_objects(prs_struct *ps, PERF_DATA_BLOCK block, int depth) { int obj; @@ -1183,6 +1308,9 @@ static BOOL _reg_perfcount_marshall_perf_objects(prs_struct *ps, PERF_DATA_BLOCK return True; } +/********************************************************************* +*********************************************************************/ + static BOOL _reg_perfcount_marshall_hkpd(prs_struct *ps, PERF_DATA_BLOCK block) { int depth = 0; @@ -1193,6 +1321,10 @@ static BOOL _reg_perfcount_marshall_hkpd(prs_struct *ps, PERF_DATA_BLOCK block) } return False; } + +/********************************************************************* +*********************************************************************/ + WERROR reg_perfcount_get_hkpd(prs_struct *ps, uint32 max_buf_size, uint32 *outbuf_len, char *object_ids) { /* diff --git a/source3/services/services_db.c b/source3/services/services_db.c index 477bf4e269..5c87225f57 100644 --- a/source3/services/services_db.c +++ b/source3/services/services_db.c @@ -71,6 +71,7 @@ struct service_display_info common_unix_svcs[] = { { "apache", NULL, "HTTP Server", NULL }, { "autofs", NULL, "Automounter", NULL }, { "squid", NULL, "Web Cache Proxy ", NULL }, + { "perfcountd", NULL, "Performance Monitoring Daemon", NULL }, { NULL, NULL, NULL, NULL } }; diff --git a/source3/utils/net_rpc_registry.c b/source3/utils/net_rpc_registry.c index 7397c88d95..289fb59fea 100644 --- a/source3/utils/net_rpc_registry.c +++ b/source3/utils/net_rpc_registry.c @@ -117,11 +117,14 @@ static NTSTATUS rpc_registry_enumerate_internal(const DOM_SID *domain_sid, return werror_to_ntstatus(result); } - result = rpccli_reg_open_entry(pipe_hnd, mem_ctx, &pol_hive, subpath, MAXIMUM_ALLOWED_ACCESS, &pol_key ); - if ( !W_ERROR_IS_OK(result) ) { - d_printf("Unable to open [%s]\n", argv[0]); - return werror_to_ntstatus(result); + if ( strlen( subpath ) != 0 ) { + result = rpccli_reg_open_entry(pipe_hnd, mem_ctx, &pol_hive, subpath, MAXIMUM_ALLOWED_ACCESS, &pol_key ); + if ( !W_ERROR_IS_OK(result) ) { + d_printf("Unable to open [%s]\n", argv[0]); + return werror_to_ntstatus(result); + } } + memcpy( &pol_key, &pol_hive, sizeof(POLICY_HND) ); /* get the subkeys */ @@ -183,7 +186,8 @@ static NTSTATUS rpc_registry_enumerate_internal(const DOM_SID *domain_sid, out: /* cleanup */ - rpccli_reg_close(pipe_hnd, mem_ctx, &pol_key ); + if ( strlen( subpath ) != 0 ) + rpccli_reg_close(pipe_hnd, mem_ctx, &pol_key ); rpccli_reg_close(pipe_hnd, mem_ctx, &pol_hive ); return werror_to_ntstatus(result); |