aboutsummaryrefslogtreecommitdiffstats
path: root/lib/snmp/src/agent/snmpa_mib.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/snmp/src/agent/snmpa_mib.erl')
-rw-r--r--lib/snmp/src/agent/snmpa_mib.erl103
1 files changed, 53 insertions, 50 deletions
diff --git a/lib/snmp/src/agent/snmpa_mib.erl b/lib/snmp/src/agent/snmpa_mib.erl
index a5e4a4cb73..1bd7398a69 100644
--- a/lib/snmp/src/agent/snmpa_mib.erl
+++ b/lib/snmp/src/agent/snmpa_mib.erl
@@ -81,7 +81,7 @@
-record(state,
{data, meo, teo, backup,
cache, cache_tmr, cache_autogc, cache_gclimit, cache_age,
- mib_data_mod}).
+ data_mod}).
@@ -225,9 +225,9 @@ info(MibServer, Type) ->
call(MibServer, {info, Type}).
dump(MibServer) ->
- call(MibServer, dump).
+ dump(MibServer, io).
-dump(MibServer, File) when is_list(File) ->
+dump(MibServer, File) when (File =:= io) orelse is_list(File) ->
call(MibServer, {dump, File}).
backup(MibServer, BackupDir) when is_list(BackupDir) ->
@@ -290,15 +290,15 @@ do_init(Prio, Mibs, Opts) ->
MeOverride = get_me_override(Opts),
TeOverride = get_te_override(Opts),
MibStorage = get_mib_storage(Opts),
- MibDataMod = get_mib_data_mod(Otps),
- Data = snmpa_mib_data:new(MibStorage),
+ MibDataMod = get_data_mod(Opts),
+ Data = MibDataMod:new(MibStorage),
?vtrace("init -> mib data created",[]),
case (catch mib_operations(MibDataMod,
load_mib, Mibs, Data,
MeOverride, TeOverride, true)) of
{ok, Data2} ->
?vdebug("started",[]),
- snmpa_mib_data:sync(Data2),
+ MibDataMod:sync(Data2),
?vdebug("mib data synced",[]),
{ok, #state{data = Data2,
teo = TeOverride,
@@ -308,7 +308,7 @@ do_init(Prio, Mibs, Opts) ->
cache_autogc = CacheAutoGC,
cache_gclimit = CacheGcLimit,
cache_age = CacheAge,
- mib_data_mib = MibDataMib}};
+ data_mod = MibDataMod}};
{'aborted at', Mib, _NewData, Reason} ->
?vinfo("failed loading mib ~p: ~p",[Mib,Reason]),
{error, {Mib, Reason}}
@@ -341,12 +341,12 @@ mib_operation(Mod, Operation, Mib, Data0, MeOverride, TeOverride, Force)
when is_list(Mib) ->
?vtrace("mib operation on mib ~p", [Mib]),
case apply(Mod, Operation, [Data0, Mib, MeOverride, TeOverride]) of
- {error, 'already loaded'} when (Operation =:= load_mib) andalso
+ {error, already_loaded} when (Operation =:= load_mib) andalso
(Force =:= true) ->
?vlog("ignore mib ~p -> already loaded", [Mib]),
Data0;
- {error, 'not loaded'} when (Operation =:= unload_mib) andalso
- (Force =:= true) ->
+ {error, not_loaded} when (Operation =:= unload_mib) andalso
+ (Force =:= true) ->
?vlog("ignore mib ~p -> not loaded", [Mib]),
Data0;
{error, Reason} ->
@@ -401,7 +401,7 @@ handle_call({update_cache_opts, Key, Value}, _From, State) ->
{reply, Result, NewState};
handle_call({lookup, Oid}, _From,
- #state{data = Data, cache = Cache, mib_data_mod = Mod} = State) ->
+ #state{data = Data, cache = Cache, data_mod = Mod} = State) ->
?vlog("lookup ~p", [Oid]),
Key = {lookup, Oid},
{Reply, NewState} =
@@ -421,14 +421,14 @@ handle_call({lookup, Oid}, _From,
{reply, Reply, NewState};
handle_call({which_mib, Oid}, _From,
- #state{data = Data, mib_data_mod = Mod} = State) ->
+ #state{data = Data, data_mod = Mod} = State) ->
?vlog("which_mib ~p",[Oid]),
Reply = Mod:which_mib(Data, Oid),
?vdebug("which_mib: ~p",[Reply]),
{reply, Reply, State};
handle_call({next, Oid, MibView}, _From,
- #state{data = Data, cache = Cache, mib_data_mod = Mod} = State) ->
+ #state{data = Data, cache = Cache, data_mod = Mod} = State) ->
?vlog("next ~p [~p]", [Oid, MibView]),
Key = {next, Oid, MibView},
{Reply, NewState} =
@@ -452,18 +452,18 @@ handle_call({load_mibs, Mibs}, _From,
teo = TeOverride,
meo = MeOverride,
cache = Cache,
- mib_data_mod = Mod} = State) ->
+ data_mod = Mod} = State) ->
?vlog("load mibs ~p",[Mibs]),
%% Invalidate cache
NewCache = maybe_invalidate_cache(Cache),
- {NData,Reply} =
+ {NData, Reply} =
case (catch mib_operations(Mod, load_mib, Mibs, Data,
MeOverride, TeOverride)) of
{'aborted at', Mib, NewData, Reason} ->
?vlog("aborted at ~p for reason ~p",[Mib,Reason]),
- {NewData,{error, {'load aborted at', Mib, Reason}}};
+ {NewData, {error, {'load aborted at', Mib, Reason}}};
{ok, NewData} ->
- {NewData,ok}
+ {NewData, ok}
end,
Mod:sync(NData),
{reply, Reply, State#state{data = NData, cache = NewCache}};
@@ -473,38 +473,39 @@ handle_call({unload_mibs, Mibs}, _From,
teo = TeOverride,
meo = MeOverride,
cache = Cache,
- mib_data_mod = Mod} = State) ->
+ data_mod = Mod} = State) ->
?vlog("unload mibs ~p",[Mibs]),
%% Invalidate cache
NewCache = maybe_invalidate_cache(Cache),
%% Unload mib(s)
- {NData,Reply} =
+ {NData, Reply} =
case (catch mib_operations(Mod, unload_mib, Mibs, Data,
MeOverride, TeOverride)) of
{'aborted at', Mib, NewData, Reason} ->
- ?vlog("aborted at ~p for reason ~p",[Mib,Reason]),
+ ?vlog("aborted at ~p for reason ~p", [Mib,Reason]),
{NewData, {error, {'unload aborted at', Mib, Reason}}};
{ok, NewData} ->
- {NewData,ok}
+ {NewData, ok}
end,
Mod:sync(NData),
{reply, Reply, State#state{data = NData, cache = NewCache}};
-handle_call(which_mibs, _From, #state{data = Data} = State) ->
+handle_call(which_mibs, _From, #state{data = Data, data_mod = Mod} = State) ->
?vlog("which mibs",[]),
Reply = Mod:which_mibs(Data),
{reply, Reply, State};
handle_call({whereis_mib, Mib}, _From,
#state{data = Data,
- mib_data_mod = Mod} = State) ->
+ data_mod = Mod} = State) ->
?vlog("whereis mib: ~p",[Mib]),
Reply = Mod:whereis_mib(Data, Mib),
{reply, Reply, State};
handle_call({register_subagent, Oid, Pid}, _From,
- #state{data = Data, cache = Cache,
- mib_data_mod = Mod} = State) ->
+ #state{data = Data,
+ cache = Cache,
+ data_mod = Mod} = State) ->
?vlog("register subagent ~p, ~p",[Oid,Pid]),
%% Invalidate cache
NewCache = maybe_invalidate_cache(Cache),
@@ -512,29 +513,31 @@ handle_call({register_subagent, Oid, Pid}, _From,
{error, Reason} ->
?vlog("registration failed: ~p",[Reason]),
{reply, {error, Reason}, State#state{cache = NewCache}};
- NewData ->
+ {ok, NewData} ->
{reply, ok, State#state{data = NewData, cache = NewCache}}
end;
handle_call({unregister_subagent, OidOrPid}, _From,
- #state{data = Data, cache = Cache,
- mib_data_mod = Mod} = State) ->
+ #state{data = Data,
+ cache = Cache,
+ data_mod = Mod} = State) ->
?vlog("unregister subagent ~p",[OidOrPid]),
%% Invalidate cache
NewCache = maybe_invalidate_cache(Cache),
case Mod:unregister_subagent(Data, OidOrPid) of
+ {ok, NewData} ->
+ {reply, ok, State#state{data = NewData, cache = NewCache}};
{ok, NewData, DeletedSubagentPid} ->
{reply, {ok, DeletedSubagentPid}, State#state{data = NewData,
cache = NewCache}};
{error, Reason} ->
?vlog("unregistration failed: ~p",[Reason]),
- {reply, {error, Reason}, State#state{cache = NewCache}};
- NewData ->
- {reply, ok, State#state{data = NewData, cache = NewCache}}
+ {reply, {error, Reason}, State#state{cache = NewCache}}
end;
-handle_call(info, _From, #state{data = Data, cache = Cache,
- mib_data_mod = Mod} = State) ->
+handle_call(info, _From, #state{data = Data,
+ cache = Cache,
+ data_mod = Mod} = State) ->
?vlog("info",[]),
Reply =
case (catch Mod:info(Data)) of
@@ -546,8 +549,8 @@ handle_call(info, _From, #state{data = Data, cache = Cache,
{reply, Reply, State};
handle_call({info, Type}, _From,
- #state{data = Data,
- mib_data_mod = Mod} = State) ->
+ #state{data = Data,
+ data_mod = Mod} = State) ->
?vlog("info ~p",[Type]),
Reply =
case (catch Mod:info(Data, Type)) of
@@ -558,13 +561,8 @@ handle_call({info, Type}, _From,
end,
{reply, Reply, State};
-handle_call(dump, _From, #state{mib_data_mod = Mod} = _State) ->
- ?vlog("dump",[]),
- Reply = Mod:dump(State#state.data),
- {reply, Reply, State};
-
handle_call({dump, File}, _From,
- #state{data = Data, mib_data_mod = Mod} = State) ->
+ #state{data = Data, data_mod = Mod} = State) ->
?vlog("dump on ~s",[File]),
Reply = Mod:dump(Data, File),
{reply, Reply, State};
@@ -573,8 +571,9 @@ handle_call({dump, File}, _From,
%% done in the master agent process, but just in case a user issues
%% a backup call to this process directly, we add a similar check here.
handle_call({backup, BackupDir}, From,
- #state{backup = undefined,
- data = Data, mib_data_mod = Mod} = State) ->
+ #state{backup = undefined,
+ data = Data,
+ data_mod = Mod} = State) ->
?vlog("backup to ~s", [BackupDir]),
Pid = self(),
V = get(verbosity),
@@ -655,7 +654,7 @@ handle_info(Info, State) ->
warning_msg("received unknown info: ~n~p", [Info]),
{noreply, State}.
-terminate(_Reason, #state{data = Data, mib_data_mod = Mod}) ->
+terminate(_Reason, #state{data = Data, data_mod = Mod}) ->
catch Mod:close(Data),
ok.
@@ -673,6 +672,11 @@ terminate(_Reason, #state{data = Data, mib_data_mod = Mod}) ->
%% S2 = {state, Data, MEO, TEO, B},
%% {ok, S2};
+code_change({down, Vsn}, #state{data = Data0, data_mod = Mod} = State, Extra) ->
+ Data = Mod:code_change(down, Vsn, Extra, Data0),
+ {ok, State#state{data = Data}};
+
+
%% %% upgrade
%% %%
%% code_change(_Vsn, S1, upgrade_from_pre_4_12) ->
@@ -681,12 +685,8 @@ terminate(_Reason, #state{data = Data, mib_data_mod = Mod}) ->
%% S2 = #state{data = Data, meo = MEO, teo = TEO, backup = B, cache = Cache},
%% {ok, S2};
-code_change({down, _Vsn}, #state{mib_data_mod = Mod} = State, _Extra) ->
- Data = Mod:code_change(down, Data0),
- {ok, State#state{data = Data}};
-
-code_change(_Vsn, #state{mib_data_mod = Mod} = State, _Extra) ->
- Data = Mod:code_change(up, Data0),
+code_change(Vsn, #state{data = Data0, data_mod = Mod} = State, Extra) ->
+ Data = Mod:code_change(up, Vsn, Extra, Data0),
{ok, State#state{data = Data}}.
@@ -706,6 +706,9 @@ get_te_override(Options) ->
get_mib_storage(Options) ->
get_opt(mib_storage, Options, ets).
+get_data_mod(Options) ->
+ get_opt(data_module, Options, snmpa_mib_data_tttn).
+
get_cacheopt_autogc(Cache, CacheOpts) ->
IsValid = fun(AutoGC) when ((AutoGC =:= true) orelse
(AutoGC =:= false)) ->