===============================================================

Question
LVM Logging is enabled by default in AIX 5.3 TL7 and 6.1

===============================================================

LVM Command Logging
Quick Reference
View a log:
alog -t [ lvmcfg | lvmt | lvmgs ] -o

Change lvmt verbosity:
LVMT_VERBOSE=[0-9]

Change lvmgs verbosity:
LVMGS_VERBOSE=[0-9]

Turn off lvmcfg log:
LVMCFG_OFF=1

Write lvmt output to STDOUT instead of log file:
LVMT_OUT=stdout

lvmt verbosities:
LVMT_ERROR, 1
LVMT_WARN, 2
LVMT_INFO, 3
LVMT_DETAIL, 7

notify verbosities:
NOTIFY_ERROR, 1
NOTIFY_WARN, 2
NOTIFY_INFO, 3
NOTIFY_DETAIL, 7

Overview

  • lvmcfg – Keeps track of what high level commands are run
    Is stored at /var/adm/ras/lvmcfg.log
  • lvmt – Trace for LVM command and libs
    Is stored at /tmp/lvmt.log
  • lvmgs – Trace for gsclvmd command
    Is stored at /tmp/lvmgs.log

There are two ways to use alog to access the log files.  The first and easiest way is to use the log name.  The log names are in bold in the list above.  You can use the -t flag with alog to specify a log name.  You can also use the filename.  The -f flag is used with alog to specify a filename.  In the rest of this document I will be using the -t flag but the -f flag can be used instead.
Using alog
The following alog commands can be used to work with any of the log files.  Just replace <log> with the log file you wish to work with (lvmcfg, lvmt, or lvmgs).

View a log file:
alog -t <log> -o

Add a marker to the end of a log file:
echo "Marker 1" | alog -t <log>

You can use the alog command to change the size of a log file but to fully change the size you must run two commands.  One to change the size of the actual log file and one to change the size of the log in ODM so if the file needs to be recreated it will use the new size.  Log sizes must be a multiple of 2048.

To change the actual size of the file:
alog -t  <log> -s 2048

To change the size of the log in ODM:
alog -C -t <log> -s 2048

Log Format
Here is the format of a start entry in the lvmcfg and lvmt logs:
[S 237694 221188 03/28/07-17:23:05:408 mklv.sh 613] mklv -y testlv00 testvg00 2

  • S = Verbosity
  • 237694 = pid
  • 221188 = ppid
  • 03/28/07-17:23:05:408 = timestamp
  • mklv = file writing to log
  • 613 = line number where log is being written
  • mklv -y testlv00 testvg00 2 = command and arguments

Here is the format of an end entry in the lvmcfg and lvmt logs:
[E 237694 1:733 mklv.sh 71] mklv: exited with rc=0

  • E = Verbosity
  • 237694 = pid
  • 1:733 = time elapsed since start entry(s:ms)
  • mklv.sh = file writing to log
  • 71 = line number where log is being written
  • mklv: = command exiting
  • exited with rc=0 = exit code of command

Here is the format of an lvmt log entry:
[1 106518 0:001 varyonvg.c 532] get_id_name: FAIL: vgid not found for bad_vg_name

  • 1 = Verbosity
  • 106518 = pid
  • 0:001 = time elapsed since start entry(s:ms)
  • varyonvg.c = file writing to log
  • 532 = line number where log is being written
  • get_id_name: = function name
  • FAIL: = flag for entries marking an error case
  • vgid not found for bad_vg_name = log entry

Here is the format for lvmgs entries:
[3 282636 1 03/29/07-12:21:07:950 gsclvmd.c 727] handle_child_req: vgid=0027b16d00004c00000001119eb6f641, id=20[STOPVG], rc=19[19]

  • e = Verbosity
  • 282636 = pid
  • 1 = tid
  • 03/29/07-12:21:07:950 = timestamp
  • gsclvmd.c = file writing to the log
  • 727 = line number where log is being written
  • handle_child_req: = function name
  • vgid=00…rc=19[19] = log entry



Log Verbosities
To change verbosity for the lvmt log:
export LVMT_VERBOSE=7
# Verbosity can be 0-9, 0 will turn of lvmt logging and 9 is the most detailed.

To turn off the lvmcfg log:
export LVMCFG_OFF=1

To change verbosity for the lvmgs log:
export LVMGS_VERBOSE=7
# Verbosity can be 0-9, 0 will turn off lvmgs logging and 9 is the most detailed.

In order to change the setting for the entire machine, instead of just the current environment, create or edit the file /etc/lvmtlog.cfg.  Add one or more of the following lines, depending of what you want to do:
LVMT_VERBOSE=7
LVMCFG_OFF=1
LVMGS_VERBOSE=7

NOTE: The environment variables will override what is set in the lvmtlog.cfg file.

To send the lvmt output to stdout instead of to the log file, set the environment variable:
LVMT_OUT=stdout

Using logging in C code

lvmcfg

To add a c command to the lvmcfg log, you must:

1. Add the following line to the beginning of the commands main routine:
lvmcfg_start(LVMCFG_START, argc, argv);

2. (Optional) Create a global variable for the command name and set it to argv[0], if it does not already exist.
3. Add the following line to each exit call and each return from main:
lvmcfg_end(LVMCFG_END, progname, rc);

Where progname is the variable used in step 2 or the command name, and rc is the exit code.


lvmt

lvmt entries are made with a call to the lvmt() function.

lvmt(LVMT_VERBOSITY, "function_name: Message", msg_arg0, ...);

LVMT_VERBOSITY can be any of the following:

  • LVMT_ERROR – Error conditions, verbosity of 1
  • LVMT_WARN – Warning messages, verbosity of 2
  • LVMT_INFO – Basic trace information, verbosity of 3
  • LVMT_DETAIL – Detailed trace information, verbosity of 7


If you want to change the verbosity for a section of code (ie. a function call failed, so you want to call the function again with the highest verbosity), you can use the lvmt_verbosity() function:

int old_verbosity;
old_verbosity = lvmt_verbosity(7);
/* High verbosity code */
lvmt_verbosity(old_verbosity);


lvmgs

lvmgs entries are made with a call to the notify() function:

notify(NOTIFY_VERBOSITY, "function_name: Message", msg_arg0, ...);

NOTIFY_VERBOSITY can be any of the following:

  • NOTIFY_ERROR – Error conditions, verbosity of 1
  • NOTIFY_WARN – Warning message, verbosity of 2
  • NOTIFY_INFO – Basic trace information, verbosity of 3
  • NOTIFY_DETAIL – Detailed trace information verbosity of 7

There are some places where the old NOTIFY macros are used (NOTIFY_ALL, NOTIFY_NOTIME, NOTIFY_NOMUTEX, NOTIFY_NONE). This is becuase they use a different verbosity than the ones defined above. If they are used, a number 1-9, representing the verbosity, must be the first argument to the notify() function followed by the NOTIFY macro being used.
Using logging in ksh code
The lvmcfg and lvmt logs may be used in ksh scripts using the lvmt command.

In order to get all the information for log preamble the following flags should be used (They are not necessary, but they are encouraged. Without them the preamble will default to 0′s and “” which may be confusing when viewing the log):

  • -f <filename of source file>
  • -l <line number of lvmt call> – the ksh variable $LINENO may be useful here
  • -p <pid of parent process> – the ksh variable $PPID may be useful here


To add a start entry to the lvmcfg log, you can use the following:

/usr/sbin/lvmt -s -f filename.sh -l $LINENO -p $PPID $@

To add an end entry to the lvmcfg log, you can use the following:
/usr/sbin/lvmt -e -f filename.sh -l $LINENO -p $PPID $COMMAND $EXIT_CODE

Where $COMMAND is the command being run(COMMAND=`basename $0`) and $EXIT_CODE is the exit code.

To add an lvmt entry to the lvmt log, you can use the following:
/usr/sbin/lvmt -t 3 -f filename.sh -l $LINENO -p $PPID lvmt message