hostres_storage_tbl.c (154137) | hostres_storage_tbl.c (160341) |
---|---|
1/*- 2 * Copyright (c) 2005-2006 The FreeBSD Project 3 * All rights reserved. 4 * 5 * Author: Victor Cruceru <soc-victor@freebsd.org> 6 * 7 * Redistribution of this software and documentation and use in source and 8 * binary forms, with or without modification, are permitted provided that --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * | 1/*- 2 * Copyright (c) 2005-2006 The FreeBSD Project 3 * All rights reserved. 4 * 5 * Author: Victor Cruceru <soc-victor@freebsd.org> 6 * 7 * Redistribution of this software and documentation and use in source and 8 * binary forms, with or without modification, are permitted provided that --- 12 unchanged lines hidden (view full) --- 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * |
29 * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c 154133 2006-01-09 12:33:45Z harti $ | 29 * $FreeBSD: head/usr.sbin/bsnmpd/modules/snmp_hostres/hostres_storage_tbl.c 160341 2006-07-14 09:07:56Z harti $ |
30 */ 31 32/* 33 * Host Resources MIB for SNMPd. Implementation for hrStorageTable 34 */ 35 36#include <sys/types.h> 37#include <sys/param.h> --- 6 unchanged lines hidden (view full) --- 44#include <assert.h> 45#include <err.h> 46#include <limits.h> 47#include <memstat.h> 48#include <paths.h> 49#include <stdlib.h> 50#include <string.h> 51#include <syslog.h> | 30 */ 31 32/* 33 * Host Resources MIB for SNMPd. Implementation for hrStorageTable 34 */ 35 36#include <sys/types.h> 37#include <sys/param.h> --- 6 unchanged lines hidden (view full) --- 44#include <assert.h> 45#include <err.h> 46#include <limits.h> 47#include <memstat.h> 48#include <paths.h> 49#include <stdlib.h> 50#include <string.h> 51#include <syslog.h> |
52#include <unistd.h> /*for getpagesize()*/ | 52#include <unistd.h> /* for getpagesize() */ 53#include <sysexits.h> |
53 54#include "hostres_snmp.h" 55#include "hostres_oid.h" 56#include "hostres_tree.h" 57 | 54 55#include "hostres_snmp.h" 56#include "hostres_oid.h" 57#include "hostres_tree.h" 58 |
59/* maximum length for descritpion string according to MIB */ 60#define SE_DESC_MLEN (255 + 1) 61 |
|
58/* 59 * This structure is used to hold a SNMP table entry 60 * for HOST-RESOURCES-MIB's hrStorageTable 61 */ 62struct storage_entry { 63 int32_t index; | 62/* 63 * This structure is used to hold a SNMP table entry 64 * for HOST-RESOURCES-MIB's hrStorageTable 65 */ 66struct storage_entry { 67 int32_t index; |
64 struct asn_oid type; 65 u_char descr[255 + 1]; | 68 const struct asn_oid *type; 69 u_char *descr; |
66 int32_t allocationUnits; 67 int32_t size; 68 int32_t used; 69 uint32_t allocationFailures; | 70 int32_t allocationUnits; 71 int32_t size; 72 int32_t used; 73 uint32_t allocationFailures; |
70#define HR_STORAGE_FOUND 0x001 | 74#define HR_STORAGE_FOUND 0x001 |
71 uint32_t flags; /* to be used internally*/ 72 TAILQ_ENTRY(storage_entry) link; 73}; 74TAILQ_HEAD(storage_tbl, storage_entry); 75 76/* 77 * Next structure is used to keep o list of mappings from a specific name 78 * (a_name) to an entry in the hrStorageTblEntry. We are trying to keep the 79 * same index for a specific name at least for the duration of one SNMP agent 80 * run. 81 */ 82struct storage_map_entry { | 75 uint32_t flags; /* to be used internally*/ 76 TAILQ_ENTRY(storage_entry) link; 77}; 78TAILQ_HEAD(storage_tbl, storage_entry); 79 80/* 81 * Next structure is used to keep o list of mappings from a specific name 82 * (a_name) to an entry in the hrStorageTblEntry. We are trying to keep the 83 * same index for a specific name at least for the duration of one SNMP agent 84 * run. 85 */ 86struct storage_map_entry { |
83 int32_t hrIndex; /* used for hrStorageTblEntry::index */ | 87 int32_t hrIndex; /* used for storage_entry::index */ |
84 | 88 |
85 /* map key, also used for hrStorageTblEntry::descr */ 86 u_char a_name[255 + 1]; | 89 /* map key, also used for storage_entry::descr */ 90 u_char *a_name; |
87 88 /* | 91 92 /* |
89 * next may be NULL if the respective hrStorageTblEntry | 93 * next may be NULL if the respective storage_entry |
90 * is (temporally) gone 91 */ 92 struct storage_entry *entry; 93 STAILQ_ENTRY(storage_map_entry) link; 94}; 95STAILQ_HEAD(storage_map, storage_map_entry); 96 97/* the head of the list with table's entries */ --- 34 unchanged lines hidden (view full) --- 132 * Create a new entry into the storage table and, if neccessary, an 133 * entry into the storage map. 134 */ 135static struct storage_entry * 136storage_entry_create(const char *name) 137{ 138 struct storage_entry *entry; 139 struct storage_map_entry *map; | 94 * is (temporally) gone 95 */ 96 struct storage_entry *entry; 97 STAILQ_ENTRY(storage_map_entry) link; 98}; 99STAILQ_HEAD(storage_map, storage_map_entry); 100 101/* the head of the list with table's entries */ --- 34 unchanged lines hidden (view full) --- 136 * Create a new entry into the storage table and, if neccessary, an 137 * entry into the storage map. 138 */ 139static struct storage_entry * 140storage_entry_create(const char *name) 141{ 142 struct storage_entry *entry; 143 struct storage_map_entry *map; |
144 size_t name_len; |
|
140 | 145 |
141 if ((entry = malloc(sizeof(*entry))) == NULL) { 142 syslog(LOG_WARNING, "%s: %m", __func__); 143 return (NULL); 144 } | 146 assert(name != NULL); 147 assert(strlen(name) > 0); |
145 | 148 |
146 strlcpy(entry->descr, name, sizeof(entry->descr)); 147 | |
148 STAILQ_FOREACH(map, &storage_map, link) | 149 STAILQ_FOREACH(map, &storage_map, link) |
149 if (strcmp(map->a_name, entry->descr) == 0) { 150 entry->index = map->hrIndex; 151 map->entry = entry; | 150 if (strcmp(map->a_name, name) == 0) |
152 break; | 151 break; |
153 } | |
154 155 if (map == NULL) { 156 /* new object - get a new index */ 157 if (next_storage_index > INT_MAX) { 158 syslog(LOG_ERR, 159 "%s: hrStorageTable index wrap", __func__); | 152 153 if (map == NULL) { 154 /* new object - get a new index */ 155 if (next_storage_index > INT_MAX) { 156 syslog(LOG_ERR, 157 "%s: hrStorageTable index wrap", __func__); |
160 free(entry); 161 return (NULL); | 158 errx(EX_SOFTWARE, "hrStorageTable index wrap"); |
162 } 163 164 if ((map = malloc(sizeof(*map))) == NULL) { 165 syslog(LOG_ERR, "hrStorageTable: %s: %m", __func__ ); | 159 } 160 161 if ((map = malloc(sizeof(*map))) == NULL) { 162 syslog(LOG_ERR, "hrStorageTable: %s: %m", __func__ ); |
166 free(entry); | |
167 return (NULL); 168 } 169 | 163 return (NULL); 164 } 165 |
170 map->hrIndex = next_storage_index ++; 171 strlcpy(map->a_name, entry->descr, sizeof(map->a_name)); 172 map->entry = entry; | 166 name_len = strlen(name) + 1; 167 if (name_len > SE_DESC_MLEN) 168 name_len = SE_DESC_MLEN; |
173 | 169 |
170 if ((map->a_name = malloc(name_len)) == NULL) { 171 free(map); 172 return (NULL); 173 } 174 175 strlcpy(map->a_name, name, name_len); 176 map->hrIndex = next_storage_index++; 177 |
|
174 STAILQ_INSERT_TAIL(&storage_map, map, link); 175 176 HRDBG("%s added into hrStorageMap at index=%d", 177 name, map->hrIndex); 178 } else { 179 HRDBG("%s exists in hrStorageMap index=%d\n", 180 name, map->hrIndex); 181 } 182 | 178 STAILQ_INSERT_TAIL(&storage_map, map, link); 179 180 HRDBG("%s added into hrStorageMap at index=%d", 181 name, map->hrIndex); 182 } else { 183 HRDBG("%s exists in hrStorageMap index=%d\n", 184 name, map->hrIndex); 185 } 186 |
187 if ((entry = malloc(sizeof(*entry))) == NULL) { 188 syslog(LOG_WARNING, "%s: %m", __func__); 189 return (NULL); 190 } 191 memset(entry, 0, sizeof(*entry)); 192 |
|
183 entry->index = map->hrIndex; 184 | 193 entry->index = map->hrIndex; 194 |
195 if ((entry->descr = strdup(map->a_name)) == NULL) { 196 free(entry); 197 return (NULL); 198 } 199 200 map->entry = entry; 201 |
|
185 INSERT_OBJECT_INT(entry, &storage_tbl); 186 187 return (entry); 188} 189 190/** 191 * Delete an entry from the storage table. 192 */ --- 5 unchanged lines hidden (view full) --- 198 assert(entry != NULL); 199 200 TAILQ_REMOVE(&storage_tbl, entry, link); 201 STAILQ_FOREACH(map, &storage_map, link) 202 if (map->entry == entry) { 203 map->entry = NULL; 204 break; 205 } | 202 INSERT_OBJECT_INT(entry, &storage_tbl); 203 204 return (entry); 205} 206 207/** 208 * Delete an entry from the storage table. 209 */ --- 5 unchanged lines hidden (view full) --- 215 assert(entry != NULL); 216 217 TAILQ_REMOVE(&storage_tbl, entry, link); 218 STAILQ_FOREACH(map, &storage_map, link) 219 if (map->entry == entry) { 220 map->entry = NULL; 221 break; 222 } |
206 | 223 free(entry->descr); |
207 free(entry); 208} 209 210/** 211 * Find a table entry by its name. 212 */ 213static struct storage_entry * 214storage_find_by_name(const char *name) 215{ 216 struct storage_entry *entry; 217 218 TAILQ_FOREACH(entry, &storage_tbl, link) | 224 free(entry); 225} 226 227/** 228 * Find a table entry by its name. 229 */ 230static struct storage_entry * 231storage_find_by_name(const char *name) 232{ 233 struct storage_entry *entry; 234 235 TAILQ_FOREACH(entry, &storage_tbl, link) |
219 if (strncmp(entry->descr, name, 220 sizeof(entry->descr) - 1) == 0) | 236 if (strcmp(entry->descr, name) == 0) |
221 return (entry); 222 223 return (NULL); 224} 225 226/* 227 * VM info. 228 */ --- 16 unchanged lines hidden (view full) --- 245 page_size_bytes = getpagesize(); 246 247 /* Real Memory Metrics */ 248 if ((entry = storage_find_by_name("Real Memory Metrics")) == NULL && 249 (entry = storage_entry_create("Real Memory Metrics")) == NULL) 250 return; /* I'm out of luck now, maybe next time */ 251 252 entry->flags |= HR_STORAGE_FOUND; | 237 return (entry); 238 239 return (NULL); 240} 241 242/* 243 * VM info. 244 */ --- 16 unchanged lines hidden (view full) --- 261 page_size_bytes = getpagesize(); 262 263 /* Real Memory Metrics */ 264 if ((entry = storage_find_by_name("Real Memory Metrics")) == NULL && 265 (entry = storage_entry_create("Real Memory Metrics")) == NULL) 266 return; /* I'm out of luck now, maybe next time */ 267 268 entry->flags |= HR_STORAGE_FOUND; |
253 entry->type = OIDX_hrStorageRam_c; | 269 entry->type = &OIDX_hrStorageRam_c; |
254 entry->allocationUnits = page_size_bytes; 255 entry->size = mem_stats.t_rm; 256 entry->used = mem_stats.t_arm; /* ACTIVE is not USED - FIXME */ 257 entry->allocationFailures = 0; 258 259 /* Shared Real Memory Metrics */ 260 if ((entry = storage_find_by_name("Shared Real Memory Metrics")) == 261 NULL && 262 (entry = storage_entry_create("Shared Real Memory Metrics")) == 263 NULL) 264 return; 265 266 entry->flags |= HR_STORAGE_FOUND; | 270 entry->allocationUnits = page_size_bytes; 271 entry->size = mem_stats.t_rm; 272 entry->used = mem_stats.t_arm; /* ACTIVE is not USED - FIXME */ 273 entry->allocationFailures = 0; 274 275 /* Shared Real Memory Metrics */ 276 if ((entry = storage_find_by_name("Shared Real Memory Metrics")) == 277 NULL && 278 (entry = storage_entry_create("Shared Real Memory Metrics")) == 279 NULL) 280 return; 281 282 entry->flags |= HR_STORAGE_FOUND; |
267 entry->type = OIDX_hrStorageRam_c; | 283 entry->type = &OIDX_hrStorageRam_c; |
268 entry->allocationUnits = page_size_bytes; 269 entry->size = mem_stats.t_rmshr; 270 /* ACTIVE is not USED - FIXME */ 271 entry->used = mem_stats.t_armshr; 272 entry->allocationFailures = 0; 273} 274 275static void 276storage_OS_get_memstat(void) 277{ 278 struct memory_type *mt_item; 279 struct storage_entry *entry; 280 281 if (mt_list == NULL) { 282 if ((mt_list = memstat_mtl_alloc()) == NULL) 283 /* again? we have a serious problem */ | 284 entry->allocationUnits = page_size_bytes; 285 entry->size = mem_stats.t_rmshr; 286 /* ACTIVE is not USED - FIXME */ 287 entry->used = mem_stats.t_armshr; 288 entry->allocationFailures = 0; 289} 290 291static void 292storage_OS_get_memstat(void) 293{ 294 struct memory_type *mt_item; 295 struct storage_entry *entry; 296 297 if (mt_list == NULL) { 298 if ((mt_list = memstat_mtl_alloc()) == NULL) 299 /* again? we have a serious problem */ |
284 return; | 300 return; |
285 } 286 287 if (memstat_sysctl_all(mt_list, 0) < 0) { 288 syslog(LOG_ERR, "memstat_sysctl_all failed: %s", 289 memstat_strerror(memstat_mtl_geterror(mt_list)) ); | 301 } 302 303 if (memstat_sysctl_all(mt_list, 0) < 0) { 304 syslog(LOG_ERR, "memstat_sysctl_all failed: %s", 305 memstat_strerror(memstat_mtl_geterror(mt_list)) ); |
290 return; 291 } | 306 return; 307 } |
292 293 if ((mt_item = memstat_mtl_first(mt_list)) == NULL) { 294 /* usually this is not an error, no errno for this failure*/ 295 HRDBG("memstat_mtl_first failed"); | 308 309 if ((mt_item = memstat_mtl_first(mt_list)) == NULL) { 310 /* usually this is not an error, no errno for this failure*/ 311 HRDBG("memstat_mtl_first failed"); |
296 return; | 312 return; |
297 } 298 299 do { 300 const char *memstat_name; 301 uint64_t tmp_size; 302 int allocator; | 313 } 314 315 do { 316 const char *memstat_name; 317 uint64_t tmp_size; 318 int allocator; |
303 char alloc_descr[255 + 1]; | 319 char alloc_descr[SE_DESC_MLEN]; |
304 305 memstat_name = memstat_get_name(mt_item); 306 | 320 321 memstat_name = memstat_get_name(mt_item); 322 |
307 if (memstat_name == NULL || strlen(memstat_name) == 0) | 323 if (memstat_name == NULL || strlen(memstat_name) == 0) |
308 continue; 309 310 switch (allocator = memstat_get_allocator(mt_item)) { 311 | 324 continue; 325 326 switch (allocator = memstat_get_allocator(mt_item)) { 327 |
312 case ALLOCATOR_MALLOC: | 328 case ALLOCATOR_MALLOC: |
313 snprintf(alloc_descr, sizeof(alloc_descr), 314 "MALLOC: %s", memstat_name); | 329 snprintf(alloc_descr, sizeof(alloc_descr), 330 "MALLOC: %s", memstat_name); |
315 break; | 331 break; |
316 317 case ALLOCATOR_UMA: 318 snprintf(alloc_descr, sizeof(alloc_descr), 319 "UMA: %s", memstat_name); 320 break; 321 322 default: 323 snprintf(alloc_descr, sizeof(alloc_descr), 324 "UNKNOWN%d: %s", allocator, memstat_name); 325 break; 326 } 327 328 if ((entry = storage_find_by_name(alloc_descr)) == NULL && 329 (entry = storage_entry_create(alloc_descr)) == NULL) 330 return; 331 332 entry->flags |= HR_STORAGE_FOUND; | 332 333 case ALLOCATOR_UMA: 334 snprintf(alloc_descr, sizeof(alloc_descr), 335 "UMA: %s", memstat_name); 336 break; 337 338 default: 339 snprintf(alloc_descr, sizeof(alloc_descr), 340 "UNKNOWN%d: %s", allocator, memstat_name); 341 break; 342 } 343 344 if ((entry = storage_find_by_name(alloc_descr)) == NULL && 345 (entry = storage_entry_create(alloc_descr)) == NULL) 346 return; 347 348 entry->flags |= HR_STORAGE_FOUND; |
333 entry->type = OIDX_hrStorageRam_c; | 349 entry->type = &OIDX_hrStorageRam_c; |
334 335 if ((tmp_size = memstat_get_size(mt_item)) == 0) 336 tmp_size = memstat_get_sizemask(mt_item); | 350 351 if ((tmp_size = memstat_get_size(mt_item)) == 0) 352 tmp_size = memstat_get_sizemask(mt_item); |
337 entry->allocationUnits = | 353 entry->allocationUnits = |
338 (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); 339 340 tmp_size = memstat_get_countlimit(mt_item); | 354 (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); 355 356 tmp_size = memstat_get_countlimit(mt_item); |
341 entry->size = | 357 entry->size = |
342 (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); 343 | 358 (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); 359 |
344 tmp_size = memstat_get_count(mt_item); 345 entry->used = | 360 tmp_size = memstat_get_count(mt_item); 361 entry->used = |
346 (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); 347 348 tmp_size = memstat_get_failures(mt_item); | 362 (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); 363 364 tmp_size = memstat_get_failures(mt_item); |
349 entry->allocationFailures = | 365 entry->allocationFailures = |
350 (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); 351 352 } while((mt_item = memstat_mtl_next(mt_item)) != NULL); 353} 354 355/** 356 * Get swap info 357 */ 358static void 359storage_OS_get_swap(void) 360{ 361 int nswapdev = 0; 362 size_t len = sizeof(nswapdev); 363 struct storage_entry *entry; | 366 (tmp_size > INT_MAX ? INT_MAX : (int32_t)tmp_size); 367 368 } while((mt_item = memstat_mtl_next(mt_item)) != NULL); 369} 370 371/** 372 * Get swap info 373 */ 374static void 375storage_OS_get_swap(void) 376{ 377 int nswapdev = 0; 378 size_t len = sizeof(nswapdev); 379 struct storage_entry *entry; |
364 char swap_w_prefix[255 + 1]; | 380 char swap_w_prefix[SE_DESC_MLEN]; |
365 366 if (sysctlbyname("vm.nswapdev", &nswapdev, &len, NULL,0 ) < 0) { 367 syslog(LOG_ERR, 368 "hrStorageTable: sysctlbyname(\"vm.nswapdev\") " 369 "failed. %m"); 370 assert(0); 371 return; 372 } --- 32 unchanged lines hidden (view full) --- 405 if (entry == NULL) 406 entry = storage_entry_create(swap_w_prefix); 407 408 assert (entry != NULL); 409 if (entry == NULL) 410 return; /* Out of luck */ 411 412 entry->flags |= HR_STORAGE_FOUND; | 381 382 if (sysctlbyname("vm.nswapdev", &nswapdev, &len, NULL,0 ) < 0) { 383 syslog(LOG_ERR, 384 "hrStorageTable: sysctlbyname(\"vm.nswapdev\") " 385 "failed. %m"); 386 assert(0); 387 return; 388 } --- 32 unchanged lines hidden (view full) --- 421 if (entry == NULL) 422 entry = storage_entry_create(swap_w_prefix); 423 424 assert (entry != NULL); 425 if (entry == NULL) 426 return; /* Out of luck */ 427 428 entry->flags |= HR_STORAGE_FOUND; |
413 entry->type = OIDX_hrStorageVirtualMemory_c; | 429 entry->type = &OIDX_hrStorageVirtualMemory_c; |
414 entry->allocationUnits = getpagesize(); 415 entry->size = swap_devs[len].ksw_total; 416 entry->used = swap_devs[len].ksw_used; 417 entry->allocationFailures = 0; 418 } 419} 420 421/** 422 * Query the underlaying OS for the mounted file systems 423 * anf fill in the respective lists (for hrStorageTable and for hrFSTable) 424 */ 425static void 426storage_OS_get_fs(void) 427{ 428 struct storage_entry *entry; 429 uint64_t used_blocks_count = 0; | 430 entry->allocationUnits = getpagesize(); 431 entry->size = swap_devs[len].ksw_total; 432 entry->used = swap_devs[len].ksw_used; 433 entry->allocationFailures = 0; 434 } 435} 436 437/** 438 * Query the underlaying OS for the mounted file systems 439 * anf fill in the respective lists (for hrStorageTable and for hrFSTable) 440 */ 441static void 442storage_OS_get_fs(void) 443{ 444 struct storage_entry *entry; 445 uint64_t used_blocks_count = 0; |
430 char fs_string[255+1]; | 446 char fs_string[SE_DESC_MLEN]; |
431 int mounted_fs_count; 432 int i = 0; 433 434 if ((mounted_fs_count = getfsstat(NULL, 0, MNT_NOWAIT)) < 0) { 435 syslog(LOG_ERR, "hrStorageTable: getfsstat() failed: %m"); 436 return; /* out of luck this time */ 437 } 438 --- 26 unchanged lines hidden (view full) --- 465 if (entry == NULL) 466 entry = storage_entry_create(fs_string); 467 468 assert (entry != NULL); 469 if (entry == NULL) 470 return; /* Out of luck */ 471 472 entry->flags |= HR_STORAGE_FOUND; | 447 int mounted_fs_count; 448 int i = 0; 449 450 if ((mounted_fs_count = getfsstat(NULL, 0, MNT_NOWAIT)) < 0) { 451 syslog(LOG_ERR, "hrStorageTable: getfsstat() failed: %m"); 452 return; /* out of luck this time */ 453 } 454 --- 26 unchanged lines hidden (view full) --- 481 if (entry == NULL) 482 entry = storage_entry_create(fs_string); 483 484 assert (entry != NULL); 485 if (entry == NULL) 486 return; /* Out of luck */ 487 488 entry->flags |= HR_STORAGE_FOUND; |
473 entry->type = *fs_get_type(&fs_buf[i]); | 489 entry->type = fs_get_type(&fs_buf[i]); /*XXX - This is wrong*/ |
474 475 if (fs_buf[i].f_bsize > INT_MAX) 476 entry->allocationUnits = INT_MAX; 477 else 478 entry->allocationUnits = fs_buf[i].f_bsize; 479 480 if (fs_buf[i].f_blocks > INT_MAX) 481 entry->size = INT_MAX; --- 45 unchanged lines hidden (view full) --- 527 fs_buf = NULL; 528 } 529 fs_buf_count = 0; 530 531 while ((n1 = STAILQ_FIRST(&storage_map)) != NULL) { 532 STAILQ_REMOVE_HEAD(&storage_map, link); 533 if (n1->entry != NULL) { 534 TAILQ_REMOVE(&storage_tbl, n1->entry, link); | 490 491 if (fs_buf[i].f_bsize > INT_MAX) 492 entry->allocationUnits = INT_MAX; 493 else 494 entry->allocationUnits = fs_buf[i].f_bsize; 495 496 if (fs_buf[i].f_blocks > INT_MAX) 497 entry->size = INT_MAX; --- 45 unchanged lines hidden (view full) --- 543 fs_buf = NULL; 544 } 545 fs_buf_count = 0; 546 547 while ((n1 = STAILQ_FIRST(&storage_map)) != NULL) { 548 STAILQ_REMOVE_HEAD(&storage_map, link); 549 if (n1->entry != NULL) { 550 TAILQ_REMOVE(&storage_tbl, n1->entry, link); |
551 free(n1->entry->descr); |
|
535 free(n1->entry); 536 } | 552 free(n1->entry); 553 } |
554 free(n1->a_name); |
|
537 free(n1); 538 } 539 assert(TAILQ_EMPTY(&storage_tbl)); 540} 541 542void 543refresh_storage_tbl(int force) 544{ --- 71 unchanged lines hidden (view full) --- 616 get: 617 switch (value->var.subs[sub - 1]) { 618 619 case LEAF_hrStorageIndex: 620 value->v.integer = entry->index; 621 return (SNMP_ERR_NOERROR); 622 623 case LEAF_hrStorageType: | 555 free(n1); 556 } 557 assert(TAILQ_EMPTY(&storage_tbl)); 558} 559 560void 561refresh_storage_tbl(int force) 562{ --- 71 unchanged lines hidden (view full) --- 634 get: 635 switch (value->var.subs[sub - 1]) { 636 637 case LEAF_hrStorageIndex: 638 value->v.integer = entry->index; 639 return (SNMP_ERR_NOERROR); 640 641 case LEAF_hrStorageType: |
624 value->v.oid = entry->type; | 642 assert(entry->type != NULL); 643 value->v.oid = *entry->type; |
625 return (SNMP_ERR_NOERROR); 626 627 case LEAF_hrStorageDescr: | 644 return (SNMP_ERR_NOERROR); 645 646 case LEAF_hrStorageDescr: |
647 assert(entry->descr != NULL); |
|
628 return (string_get(value, entry->descr, -1)); 629 break; 630 631 case LEAF_hrStorageAllocationUnits: 632 value->v.integer = entry->allocationUnits; 633 return (SNMP_ERR_NOERROR); 634 635 case LEAF_hrStorageSize: --- 13 unchanged lines hidden --- | 648 return (string_get(value, entry->descr, -1)); 649 break; 650 651 case LEAF_hrStorageAllocationUnits: 652 value->v.integer = entry->allocationUnits; 653 return (SNMP_ERR_NOERROR); 654 655 case LEAF_hrStorageSize: --- 13 unchanged lines hidden --- |