PERFORCE change 80629 for review
soc-victor
soc-victor at FreeBSD.org
Wed Jul 20 20:29:32 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=80629
Change 80629 by soc-victor at soc-victor_82.76.158.176 on 2005/07/20 20:29:18
Added the implementation for both hrSWRunTable and hrSWRunPerfTable (which AUGMENTS hrSWRunTable ).
Both tables need some performance improvements; also hrSWRunTable needs SNMP SET support.
Affected files ...
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#8 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c#6 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#8 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#10 edit
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrun_tbl.c#1 add
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_swrunperf_tbl.c#1 add
Differences ...
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/Makefile#8 (text+ko) ====
@@ -7,7 +7,8 @@
MOD= hostres
SRCS= hostres_snmp.c hostres_scalars.c \
- hostres_storage_tbl.c hostres_fs_tbl.c
+ hostres_storage_tbl.c hostres_fs_tbl.c \
+ hostres_swrun_tbl.c hostres_swrunperf_tbl.c
WARNS?= 6
#Not having NDEBUG defined will enable assertions and a lot of output on stderr
CFLAGS+= -DNDEBUG
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_scalars.c#6 (text+ko) ====
@@ -487,7 +487,7 @@
return (-1); /*error*/
}
- if( kvm_getprocs(hrState_g.kd, KERN_PROC_PROC, 0, &proc_count) == NULL ) {
+ if( kvm_getprocs(hrState_g.kd, KERN_PROC_ALL, 0, &proc_count) == NULL ) {
syslog(LOG_ERR, "kvm_getprocs failed: %m ");
return (-1);/*error*/
}
@@ -569,3 +569,31 @@
}
return (-1); /*error*/
}
+
+int op_hrSWRun(struct snmp_context *ctx __unused,
+ struct snmp_value *value,
+ u_int sub,
+ u_int iidx __unused,
+ enum snmp_op curr_op)
+{
+
+
+ if(curr_op == SNMP_OP_GET) {
+ switch (value->var.subs[sub - 1]) {
+ case LEAF_hrSWOSIndex:
+ value->v.uint32 = hrState_g.hrSWOSIndex;
+ return (SNMP_ERR_NOERROR);
+ default:
+ assert(0);
+ return (SNMP_ERR_NOSUCHNAME);
+
+ }/*end switch*/
+ } else if (curr_op == SNMP_OP_SET) {
+ return (SNMP_ERR_NOT_WRITEABLE);
+ } else {
+ assert(0);
+ return (SNMP_ERR_GENERR);
+ }
+
+}
+
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.c#8 (text+ko) ====
@@ -54,14 +54,18 @@
struct hostres_state hrState_g;
/*
-HOST RESOURCES mib module initialization hook.
-Returns 0 on success, < 0 on error
-*/
+ * HOST RESOURCES mib module initialization hook.
+ * Returns 0 on success, < 0 on error
+ */
static
int hostres_init(struct lmodule * mod, int argc __unused, char *argv[] __unused) {
+
hostres_module = mod;
+ /*
+ * NOTE: order of these calls is important here!
+ */
hrState_g.utmp_fp = (FILE*)NULL;
hrState_g.kd = (kvm_t*)NULL;
hrState_g.kernel_boot = 0;
@@ -86,6 +90,7 @@
return (-1); /*error*/
}
+ hrState_g.hrSWOSIndex = 0;
hrState_g.next_hrStorage_index = 1;
@@ -100,16 +105,21 @@
TAILQ_INIT(&hrState_g.hr_fs_tbl);
+ TAILQ_INIT(&hrState_g.hr_swrun_tbl);
hrState_g.hr_storage_tick = 0;
hrState_g.hr_fs_tick = 0;
+ hrState_g.hr_swrun_tick = 0;
hrState_g.hrStorage_tbl_age = 0;
hrState_g.hrFS_tbl_age = 0;
+ hrState_g.hrSWRun_tbl_age = 0;
+
init_hrStorage_tbl_v();
init_hrFS_tbl_v();
-
+ init_hrSWRun_tbl_v();
+
HR_DPRINTF((stderr, "[%s] done.\n", __func__));
return (0);
@@ -152,7 +162,18 @@
fini_hrStorage_tbl_v();
fini_hrFS_tbl_v();
-
+ fini_hrSWRun_tbl_v();
+
+ hrState_g.hr_storage_tick = 0;
+ hrState_g.hr_fs_tick = 0;
+ hrState_g.hr_swrun_tick = 0;
+
+ hrState_g.hrStorage_tbl_age = 0;
+ hrState_g.hrFS_tbl_age = 0;
+ hrState_g.hrSWRun_tbl_age = 0;
+
+ hrState_g.hrSWOSIndex = 0;
+
if( host_registration_id > 0){
or_unregister(host_registration_id);
}
@@ -175,6 +196,11 @@
HR_DPRINTF((stderr, "%s: hrFSTable needs refresh\n ", __func__));
refresh_hrFS_tbl_v();
}
+ if ( (time(NULL) - hrState_g.hrSWRun_tbl_age) > HR_SWRUN_TBL_REFRESH ) {
+ HR_DPRINTF((stderr, "%s: hrSWRunTable needs refresh\n ", __func__));
+ refresh_hrStorage_tbl_v();
+ }
+
HR_DPRINTF((stderr, "[%s] done.\n ", __func__));
}
@@ -307,35 +333,11 @@
-int op_hrSWRun(struct snmp_context *ctx __unused,
- struct snmp_value *value __unused,
- u_int sub __unused,
- u_int iidx __unused,
- enum snmp_op curr_op __unused)
-{
- return (SNMP_ERR_NOSUCHNAME);
-}
-int op_hrSWRunTable(struct snmp_context *ctx __unused,
- struct snmp_value *value __unused,
- u_int sub __unused,
- u_int iidx __unused,
- enum snmp_op curr_op __unused)
-{
- return (SNMP_ERR_NOSUCHNAME);
-}
-int op_hrSWRunPerfTable(struct snmp_context *ctx __unused,
- struct snmp_value *value __unused,
- u_int sub __unused,
- u_int iidx __unused,
- enum snmp_op curr_op __unused)
-{
- return (SNMP_ERR_NOSUCHNAME);
-}
int op_hrSWInstalled(struct snmp_context *ctx __unused,
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_snmp.h#10 (text+ko) ====
@@ -59,7 +59,7 @@
/*
- * This structure is used to hold on SNMP table entry
+ * This structure is used to hold a SNMP table entry
* for HOST-RESOURCES-MIB's hrStorageTable
*/
@@ -110,10 +110,14 @@
SNMP_FALSE= 2
};
+/*
+ * This structure is used to hold a SNMP table entry
+ * for HOST-RESOURCES-MIB's hrFSTable
+ */
struct hrFSTblEntry {
int32_t index;
- u_char mountPoint[128];
- u_char remoteMountPoint[128];
+ u_char mountPoint[128+11];
+ u_char remoteMountPoint[128+1];
struct asn_oid type;
int32_t access; /* enum hrFSAccess, see above */
int32_t bootable; /* enum snmpTCTruthValue, see above */
@@ -150,6 +154,44 @@
STAILQ_HEAD(fs_map_list, FSNameMapEntry);
+enum SWRunType {
+ SRT_UNKNOWN = 1,
+ SRT_OPERATING_SYSTEM = 2,
+ SRT_DEVICE_DRIVER = 3,
+ SRT_APPLICATION = 4
+
+};
+
+enum SWRunStatus {
+ SRS_RUNNING = 1,
+ SRS_RUNNABLE = 2,
+ SRS_NOT_RUNNABLE = 3,
+ SRS_INVALID = 4
+};
+
+/*
+ * This structure is used to hold a SNMP table entry
+ * for both hrSWRunTable and hrSWRunPerfTable because
+ * hrSWRunPerfTable AUGMENTS hrSWRunTable
+ */
+struct hrSWRunTblEntry {
+ int32_t index;
+ u_char name[64+1];
+ struct asn_oid id;
+ u_char path[128+1];
+ u_char parameters[128+1];
+ int32_t type; /* one item from enum SWRunType, see above */
+ int32_t status; /* one item from enum SWRunStatus, see above */
+ int32_t perfCPU;
+ int32_t perfMemory;
+#define HR_SWRUN_FOUND 0x001
+ uint32_t flags; /*not from the SNMP mib table, only to be used internally*/
+ TAILQ_ENTRY(hrSWRunTblEntry) link;
+};
+
+TAILQ_HEAD(swrun_tbl, hrSWRunTblEntry);
+
+
struct hostres_state {
FILE *utmp_fp; /*file pointer to keep an open instance of utmp*/
kvm_t *kd; /*kernel descriptor*/
@@ -171,9 +213,9 @@
storage_tbl hr_storage_tbl; /*the head of the list with table's entries */
uint64_t hr_storage_tick; /*last (agent) tick when hrStorageTable was updated */
struct kvm_swap *swap_devs; /*for kvm_getswapinfo, malloc'd*/
- size_t swap_devs_len; /*idem */
+ size_t swap_devs_len; /*item count for swap_devs */
struct statfs *fs_buf; /*for getfsstat, malloc'd*/
- size_t fs_buf_count; /*idem*/
+ size_t fs_buf_count; /*item count for fs_buf */
struct vmtotal mem_stats;
uint32_t next_hrStorage_index; /*next int available for indexing the hrStorageTable*/
time_t hrStorage_tbl_age;
@@ -189,7 +231,17 @@
time_t hrFS_tbl_age;
uint64_t hr_fs_tick; /*last (agent) tick when hrFSTable was updated */
-
+ /*
+ * next items are used for both hrSWRunTable and hrSWRunPerfTable
+ */
+ struct
+ swrun_tbl hr_swrun_tbl; /*the head of the list with hrSWRunTable's entries */
+
+ time_t hrSWRun_tbl_age;
+ uint64_t hr_swrun_tick; /*last (agent) tick when hrSWRunTable and hrSWRunPerTable
+ were updated */
+ int32_t hrSWOSIndex; /* the value of the MIB objecy with the same name*/
+
};
/*
@@ -267,6 +319,35 @@
*/
void refresh_hrFS_tbl_v(void);
+/*
+ * Find an entry in hrSWRunTable (or hrSWRunPerfTable) by its SNMP index
+ * Returns NULL if none found
+ */
+struct hrSWRunTblEntry *
+hrSWRunTblEntry_find_by_index(int32_t idx);
+
+/*
+ * Init the things for both of hrSWRunTable an hrSWRunPerfTable
+ */
+void init_hrSWRun_tbl_v(void);
+
+/*
+ * Finalization routine for both of hrSWRunTable an hrSWRunPerfTable
+ * It destroys the lists and frees any allocated heap memory
+ */
+void fini_hrSWRun_tbl_v(void);
+
+/*
+ * Next macro represents the number of seconds
+ * between two consecutive queries to the OS for getting the new data
+ * for both of hrSWRunTable and hrSWRunPerfTable
+ */
+#define HR_SWRUN_TBL_REFRESH 3
+/*
+ * Refresh routine for both of hrSWRunTable and hrSWRunPerfTable
+ * Usable for polling the system for any changes.
+ */
+void refresh_hrSWRun_tbl_v(void);
#endif /*__HOSTRES_SNMP_H_INCLUDED__ */
More information about the p4-projects
mailing list