Configuration API: Difference between revisions

From wiki.zmanda.com
Jump to navigation Jump to search
No edit summary
(updated with examples, note on memory allocation)
Line 29: Line 29:
There are lot of macros tapetype_*, dumptype_*, interface_*, holdingdisk_* to retrieve configuration values.
There are lot of macros tapetype_*, dumptype_*, interface_*, holdingdisk_* to retrieve configuration values.


To retrieve global value, developer must use one of these functions: getconf_int, getconf_long, getconf_size, getconf_time, getconf_am64, getconf_real, getconf_str,
To retrieve global value, use one of these functions: getconf_int, getconf_long, getconf_size, getconf_time, getconf_am64, getconf_real, getconf_str.


===server-src/conffile.c===
===server-src/conffile.c===
Line 39: Line 39:
; interface_var : Array describing interface options
; interface_var : Array describing interface options


==How to add a new configuration option==
= Accessing Configuration =
Accessing configuration values from Amanda applications is straightforward.  Global configuration options are accessed with ''getconf_xxx'' (depending on type):
conf_tapetype = getconf_str(CNF_TAPETYPE);
run_tapes = getconf_int(CNF_RUNTAPES);
Note that ''getconf_str()'' returns a pointer to a string in the configuration data structures -- '''do not''' free the result!
 
To access one of the named configuration sections (dumptypes, holding disks, etc.), first look up the object you want:
tape = lookup_tapetype(getconf_str(CNF_TAPETYPE));
then use one of the macros for that object to get the actual value:
tt_blocksize_kb = (size_t)tapetype_get_blocksize(tape);
See {{file|conffile.h}} for the full list of such macros.
 
= Adding New Options =
==How to add a new global option==
==How to add a new global option==
* Add a token in tok_t (CONF_*)
* Add a token in tok_t (CONF_*)

Revision as of 23:20, 18 June 2007

This section describes how Amanda reads amanda.conf and amanda-client.conf configuration files.

Data Structures

common/util.h

conftype_t
all possible types of config options.
tok_t
tokens
keytab_t
string to tok_t conversion.
command_option_t
data structure to keep -o command line argument.
val_t
Store the value of a configuration option. It has following fields:
    • v  : value
    • seen : If the value was seen on a config file
    • type : the type of the value
t_conf_var
structure for all configuration options with following fields:
    • token : the internal token use.
    • type : the type of the value
    • read_function : the function to read that value
    • parm : confparm_t, tapetype_ee, dumptype_ee, interface_ee or holdingdisk_ee
    • validate : a function to validate the value

server-src/conffile.h

confparm_t
global option
tapetype_ee, dumptype_ee, interface_ee,holdingdisk_ee
tapetype/dumptype/interface/holding options
tapetype_t, dumptype_t, interface_t, holdingdisk_t
Data structures with following fields:
    • seen:
    • name: name of the option
    • value: all value of that tapetype/dumptype/interface

There are lot of macros tapetype_*, dumptype_*, interface_*, holdingdisk_* to retrieve configuration values.

To retrieve global value, use one of these functions: getconf_int, getconf_long, getconf_size, getconf_time, getconf_am64, getconf_real, getconf_str.

server-src/conffile.c

server_keytab
Keytab for the server configuration
server_var
Array describing global server options
holding_var
Array describing holdingdisk options
dumptype_var
Array describing dumptype options
tapetype_var
Array describing tapetype options
interface_var
Array describing interface options

Accessing Configuration

Accessing configuration values from Amanda applications is straightforward. Global configuration options are accessed with getconf_xxx (depending on type):

conf_tapetype = getconf_str(CNF_TAPETYPE);
run_tapes = getconf_int(CNF_RUNTAPES);

Note that getconf_str() returns a pointer to a string in the configuration data structures -- do not free the result!

To access one of the named configuration sections (dumptypes, holding disks, etc.), first look up the object you want:

tape = lookup_tapetype(getconf_str(CNF_TAPETYPE));

then use one of the macros for that object to get the actual value:

tt_blocksize_kb = (size_t)tapetype_get_blocksize(tape);

See conffile.h for the full list of such macros.

Adding New Options

How to add a new global option

  • Add a token in tok_t (CONF_*)
  • Add a token in confparm_t (CNF_*)
  • Add an entry in server_keytab
  • Add an entry in server_var
  • Change init_defaults(): Set default value for the option
  • User should use the correct getconf_* function according to the data type given in server_var

How to add a dumptype option

  • Add a token in tok_t (CONF_*)
  • Add a token in dumptype_ee (DUMPTYPE_*)
  • Add a macro to retrive the value (dumptype_get_*)
  • Add an entry in server_keytab
  • Add an entry in dumptype_var
  • Change init_dumptype_defaults(): Set default value.
  • The dumptype_get_* macro should return the correct field according to the type defined in dumptype_var

Adding a tapetype, holdingdisk or interface option is done similar to adding a dumptype option.

  • For a dumptype, the value must also be copied to the disk_t structure.
    • Add a NEWVAR field in the disk_t struct with the type.
    • In diskfile.c(parse_diskline) you must add the following line:
   disk->NEWVAR = dumptype_get_NEWVAR(dtype);
You can then use disk->NEWVAR as you like.