File: diskdb.c

package info (click to toggle)
mcelog 104-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 996 kB
  • ctags: 1,508
  • sloc: ansic: 7,739; sh: 481; makefile: 87
file content (96 lines) | stat: -rw-r--r-- 1,831 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* High level interface to disk based DIMM database */
/* Note: obsolete: new design is in memdb.c */
#include <stdlib.h>
#include <getopt.h>
#include <stdio.h>
#include "mcelog.h"
#include "diskdb.h"
#include "paths.h"
#include "dimm.h"
#include "dmi.h"
 
char *error_trigger;
unsigned error_thresh = 20;
char *dimm_db_fn = DIMM_DB_FILENAME;

static void checkdimmdb(void)
{
	if (open_dimm_db(dimm_db_fn) < 0) 
		exit(1);
}

int diskdb_modifier(int opt)
{
	char *end;

	switch (opt) { 
	case O_DATABASE:
		dimm_db_fn = optarg;
		checkdmi();
		checkdimmdb();
		break;
	case O_ERROR_TRIGGER:
		checkdmi();
		open_dimm_db(dimm_db_fn);
		error_thresh = strtoul(optarg, &end, 0);
		if (end == optarg || *end != ',') 
			usage();
		error_trigger = end + 1; 
		break;
	default:
		return 0;
	}
	return 1;
}

void diskdb_resolve_addr(u64 addr)
{
	if (open_dimm_db(dimm_db_fn) >= 0) 
		new_error(addr, error_thresh, error_trigger);
}


void diskdb_usage(void)
{
	fprintf(stderr, 
		"Manage disk DIMM error database\n"
		"  mcelog [options] --drop-old-memory|--reset-memory locator\n"
		"  mcelog --dump-memory locator\n"
		"  old can be either locator or name\n"
		"Disk database options:"
		"--database fn       Set filename of DIMM database (default " DIMM_DB_FILENAME ")\n"
		"--error-trigger cmd,thresh   Run cmd on exceeding thresh errors per DIMM\n");
}


static void dimm_common(int ac, char **av)
{
	no_syslog();
	checkdmi();
	checkdimmdb();
	argsleft(ac, av); 
}

int diskdb_cmd(int opt, int ac, char **av)
{
	char *arg = optarg; 
	
	switch (opt) { 
	case O_DUMP_MEMORY:
		dimm_common(ac, av);
		if (arg)
			dump_dimm(arg);
		else
			dump_all_dimms();
		return 1;
	case O_RESET_MEMORY:
		dimm_common(ac, av);
		reset_dimm(arg);
		return 1;
	case O_DROP_OLD_MEMORY:
		dimm_common(ac, av);
		gc_dimms();
		return 1;
	}
	return 0;	
}