mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
Add dm_log_with_errno and dm_log_with_errno_init, deprecating the old
Change plog to use dm_log_with_errno unless deprecated dm_log_init was used. Rename plog macro to LOG_LINE and use in dm_dump_memory_debug.
This commit is contained in:
parent
f1c90ec108
commit
a9cb6969b0
@ -1,5 +1,8 @@
|
|||||||
Version 1.02.34 -
|
Version 1.02.34 -
|
||||||
================================
|
================================
|
||||||
|
Rename plog macro to LOG_LINE and use in dm_dump_memory_debug.
|
||||||
|
Change plog to use dm_log_with_errno unless deprecated dm_log_init was used.
|
||||||
|
Add dm_log_with_errno and dm_log_with_errno_init, deprecating the old fns.
|
||||||
Fix whitespace in linear target line to fix identical table line detection.
|
Fix whitespace in linear target line to fix identical table line detection.
|
||||||
Add device number to more log messages during activation.
|
Add device number to more log messages during activation.
|
||||||
|
|
||||||
|
@ -50,17 +50,17 @@
|
|||||||
#define _LOG_ERR 3
|
#define _LOG_ERR 3
|
||||||
#define _LOG_FATAL 2
|
#define _LOG_FATAL 2
|
||||||
|
|
||||||
#define log_debug(x...) plog(_LOG_DEBUG, x)
|
#define log_debug(x...) LOG_LINE(_LOG_DEBUG, x)
|
||||||
#define log_info(x...) plog(_LOG_INFO, x)
|
#define log_info(x...) LOG_LINE(_LOG_INFO, x)
|
||||||
#define log_notice(x...) plog(_LOG_NOTICE, x)
|
#define log_notice(x...) LOG_LINE(_LOG_NOTICE, x)
|
||||||
#define log_warn(x...) plog(_LOG_WARN | _LOG_STDERR, x)
|
#define log_warn(x...) LOG_LINE(_LOG_WARN | _LOG_STDERR, x)
|
||||||
#define log_err(x...) plog(_LOG_ERR, x)
|
#define log_err(x...) LOG_LINE(_LOG_ERR, x)
|
||||||
#define log_fatal(x...) plog(_LOG_FATAL, x)
|
#define log_fatal(x...) LOG_LINE(_LOG_FATAL, x)
|
||||||
|
|
||||||
#define stack log_debug("<backtrace>") /* Backtrace on error */
|
#define stack log_debug("<backtrace>") /* Backtrace on error */
|
||||||
#define log_very_verbose(args...) log_info(args)
|
#define log_very_verbose(args...) log_info(args)
|
||||||
#define log_verbose(args...) log_notice(args)
|
#define log_verbose(args...) log_notice(args)
|
||||||
#define log_print(args...) plog(_LOG_WARN, args)
|
#define log_print(args...) LOG_LINE(_LOG_WARN, args)
|
||||||
#define log_error(args...) log_err(args)
|
#define log_error(args...) log_err(args)
|
||||||
|
|
||||||
/* System call equivalents */
|
/* System call equivalents */
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
void print_log(int level, const char *file, int line, const char *format, ...)
|
void print_log(int level, const char *file, int line, const char *format, ...)
|
||||||
__attribute__ ((format(printf, 4, 5)));
|
__attribute__ ((format(printf, 4, 5)));
|
||||||
|
|
||||||
#define plog(l, x...) print_log(l, __FILE__, __LINE__ , ## x)
|
#define LOG_LINE(l, x...) print_log(l, __FILE__, __LINE__ , ## x)
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
@ -6,6 +6,9 @@ dm_fclose
|
|||||||
dm_get_library_version
|
dm_get_library_version
|
||||||
dm_log
|
dm_log
|
||||||
dm_log_init
|
dm_log_init
|
||||||
|
dm_log_is_non_default
|
||||||
|
dm_log_with_errno
|
||||||
|
dm_log_with_errno_init
|
||||||
dm_log_init_verbose
|
dm_log_init_verbose
|
||||||
dm_task_create
|
dm_task_create
|
||||||
dm_task_destroy
|
dm_task_destroy
|
||||||
|
@ -30,30 +30,40 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
/*****************************************************************
|
/*****************************************************************
|
||||||
* The first section of this file provides direct access to the
|
* The first section of this file provides direct access to the
|
||||||
* individual device-mapper ioctls.
|
* individual device-mapper ioctls. Since it is quite laborious to
|
||||||
|
* build the ioctl arguments for the device-mapper, people are
|
||||||
|
* encouraged to use this library.
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Since it is quite laborious to build the ioctl
|
* The library user may wish to register their own
|
||||||
* arguments for the device-mapper people are
|
* logging function. By default errors go to stderr.
|
||||||
* encouraged to use this library.
|
* Use dm_log_with_errno_init(NULL) to restore the default log fn.
|
||||||
*
|
|
||||||
* You will need to build a struct dm_task for
|
|
||||||
* each ioctl command you want to execute.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
typedef void (*dm_log_with_errno_fn) (int level, const char *file, int line,
|
||||||
|
int dm_errno, const char *f, ...)
|
||||||
|
__attribute__ ((format(printf, 5, 6)));
|
||||||
|
|
||||||
|
void dm_log_with_errno_init(dm_log_with_errno_fn fn);
|
||||||
|
void dm_log_init_verbose(int level);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Original version of this function.
|
||||||
|
* dm_errno is set to 0.
|
||||||
|
*
|
||||||
|
* Deprecated: Use the _with_errno_ versions above instead.
|
||||||
|
*/
|
||||||
typedef void (*dm_log_fn) (int level, const char *file, int line,
|
typedef void (*dm_log_fn) (int level, const char *file, int line,
|
||||||
const char *f, ...)
|
const char *f, ...)
|
||||||
__attribute__ ((format(printf, 4, 5)));
|
__attribute__ ((format(printf, 4, 5)));
|
||||||
|
|
||||||
/*
|
|
||||||
* The library user may wish to register their own
|
|
||||||
* logging function, by default errors go to stderr.
|
|
||||||
* Use dm_log_init(NULL) to restore the default log fn.
|
|
||||||
*/
|
|
||||||
void dm_log_init(dm_log_fn fn);
|
void dm_log_init(dm_log_fn fn);
|
||||||
void dm_log_init_verbose(int level);
|
/*
|
||||||
|
* For backward-compatibility, indicate that dm_log_init() was used
|
||||||
|
* to set a non-default value of dm_log().
|
||||||
|
*/
|
||||||
|
int dm_log_is_non_default(void);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
DM_DEVICE_CREATE,
|
DM_DEVICE_CREATE,
|
||||||
@ -87,6 +97,11 @@ enum {
|
|||||||
DM_DEVICE_SET_GEOMETRY
|
DM_DEVICE_SET_GEOMETRY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* You will need to build a struct dm_task for
|
||||||
|
* each ioctl command you want to execute.
|
||||||
|
*/
|
||||||
|
|
||||||
struct dm_task;
|
struct dm_task;
|
||||||
|
|
||||||
struct dm_task *dm_task_create(int type);
|
struct dm_task *dm_task_create(int type);
|
||||||
|
@ -42,10 +42,12 @@ static int _verbose = 0;
|
|||||||
* Library users can provide their own logging
|
* Library users can provide their own logging
|
||||||
* function.
|
* function.
|
||||||
*/
|
*/
|
||||||
static void _default_log(int level, const char *file __attribute((unused)),
|
|
||||||
int line __attribute((unused)), const char *f, ...)
|
static void _default_log_line(int level,
|
||||||
|
const char *file __attribute((unused)),
|
||||||
|
int line __attribute((unused)), int dm_errno,
|
||||||
|
const char *f, va_list ap)
|
||||||
{
|
{
|
||||||
va_list ap;
|
|
||||||
int use_stderr = level & _LOG_STDERR;
|
int use_stderr = level & _LOG_STDERR;
|
||||||
|
|
||||||
level &= ~_LOG_STDERR;
|
level &= ~_LOG_STDERR;
|
||||||
@ -53,22 +55,41 @@ static void _default_log(int level, const char *file __attribute((unused)),
|
|||||||
if (level > _LOG_WARN && !_verbose)
|
if (level > _LOG_WARN && !_verbose)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
va_start(ap, f);
|
|
||||||
|
|
||||||
if (level < _LOG_WARN)
|
if (level < _LOG_WARN)
|
||||||
vfprintf(stderr, f, ap);
|
vfprintf(stderr, f, ap);
|
||||||
else
|
else
|
||||||
vfprintf(use_stderr ? stderr : stdout, f, ap);
|
vfprintf(use_stderr ? stderr : stdout, f, ap);
|
||||||
|
|
||||||
va_end(ap);
|
|
||||||
|
|
||||||
if (level < _LOG_WARN)
|
if (level < _LOG_WARN)
|
||||||
fprintf(stderr, "\n");
|
fprintf(stderr, "\n");
|
||||||
else
|
else
|
||||||
fprintf(use_stderr ? stderr : stdout, "\n");
|
fprintf(use_stderr ? stderr : stdout, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void _default_log_with_errno(int level,
|
||||||
|
const char *file __attribute((unused)),
|
||||||
|
int line __attribute((unused)), int dm_errno,
|
||||||
|
const char *f, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, f);
|
||||||
|
_default_log_line(level, file, line, dm_errno, f, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void _default_log(int level, const char *file,
|
||||||
|
int line, const char *f, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, f);
|
||||||
|
_default_log_line(level, file, line, 0, f, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
dm_log_fn dm_log = _default_log;
|
dm_log_fn dm_log = _default_log;
|
||||||
|
dm_log_with_errno_fn dm_log_with_errno = _default_log_with_errno;
|
||||||
|
|
||||||
void dm_log_init(dm_log_fn fn)
|
void dm_log_init(dm_log_fn fn)
|
||||||
{
|
{
|
||||||
@ -76,6 +97,23 @@ void dm_log_init(dm_log_fn fn)
|
|||||||
dm_log = fn;
|
dm_log = fn;
|
||||||
else
|
else
|
||||||
dm_log = _default_log;
|
dm_log = _default_log;
|
||||||
|
|
||||||
|
dm_log_with_errno = _default_log_with_errno;
|
||||||
|
}
|
||||||
|
|
||||||
|
int dm_log_is_non_default(void)
|
||||||
|
{
|
||||||
|
return (dm_log == _default_log) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void dm_log_with_errno_init(dm_log_with_errno_fn fn)
|
||||||
|
{
|
||||||
|
if (fn)
|
||||||
|
dm_log_with_errno = fn;
|
||||||
|
else
|
||||||
|
dm_log_with_errno = _default_log_with_errno;
|
||||||
|
|
||||||
|
dm_log = _default_log;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dm_log_init_verbose(int level)
|
void dm_log_init_verbose(int level)
|
||||||
|
@ -19,8 +19,15 @@
|
|||||||
#include "libdevmapper.h"
|
#include "libdevmapper.h"
|
||||||
|
|
||||||
extern dm_log_fn dm_log;
|
extern dm_log_fn dm_log;
|
||||||
|
extern dm_log_with_errno_fn dm_log_with_errno;
|
||||||
|
|
||||||
#define plog(l, x...) dm_log(l, __FILE__, __LINE__, ## x)
|
#define LOG_LINE(l, x...) \
|
||||||
|
do { \
|
||||||
|
if (dm_log_is_non_default()) \
|
||||||
|
dm_log(l, __FILE__, __LINE__, ## x); \
|
||||||
|
else \
|
||||||
|
dm_log_with_errno(l, __FILE__, __LINE__, 0, ## x); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
@ -205,9 +205,9 @@ int dm_dump_memory_debug(void)
|
|||||||
}
|
}
|
||||||
str[sizeof(str) - 1] = '\0';
|
str[sizeof(str) - 1] = '\0';
|
||||||
|
|
||||||
dm_log(_LOG_INFO, mb->file, mb->line,
|
LOG_LINE(_LOG_INFO, mb->file, mb->line,
|
||||||
"block %d at %p, size %" PRIsize_t "\t [%s]",
|
"block %d at %p, size %" PRIsize_t "\t [%s]",
|
||||||
mb->id, mb->magic, mb->length, str);
|
mb->id, mb->magic, mb->length, str);
|
||||||
tot += mb->length;
|
tot += mb->length;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,3 +21,6 @@
|
|||||||
|
|
||||||
#define print_log(level, file, line, format, args...) print_log(format, args)
|
#define print_log(level, file, line, format, args...) print_log(format, args)
|
||||||
#define dm_log(level, file, line, format, args...) dm_log(format, args)
|
#define dm_log(level, file, line, format, args...) dm_log(format, args)
|
||||||
|
#define dm_log_with_errno(level, file, line, format, dm_errno, args...) \
|
||||||
|
dm_log(format, args)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user