1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

Rename _log to dm_log and export.

Fix misc compile-time warnings.
This commit is contained in:
Alasdair Kergon 2006-01-31 14:50:38 +00:00
parent c55b141005
commit 5e3bd86778
14 changed files with 78 additions and 71 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.03 -
============================
Rename _log to dm_log and export.
Add dm_tree_skip_lockfs.
Fix dm_strdup debug definition.
Fix hash function to avoid using a negative array offset.

View File

@ -44,11 +44,6 @@
#include <malloc.h>
#endif
/* FIXME Use dm library */
#define dbg_malloc(x...) malloc(x)
#define dbg_strdup(x...) strdup(x)
#define dbg_free(x...) free(x)
/* List (un)link macros. */
#define LINK(x, head) list_add(head, &(x)->list)
#define LINK_DSO(dso) LINK(dso, &dso_registry)
@ -131,7 +126,7 @@ struct thread_status {
struct dso_data *dso_data;/* DSO this thread accesses. */
char *device_path; /* Mapped device path. */
int event_nr; /* event number */
uint32_t event_nr; /* event number */
int processing; /* Set when event is being processed */
enum dm_event_type events; /* bitfield for event filter. */
enum dm_event_type current_events;/* bitfield for occured events. */
@ -152,12 +147,12 @@ static pthread_cond_t timeout_cond = PTHREAD_COND_INITIALIZER;
static struct thread_status *alloc_thread_status(struct message_data *data,
struct dso_data *dso_data)
{
struct thread_status *ret = (typeof(ret)) dbg_malloc(sizeof(*ret));
struct thread_status *ret = (typeof(ret)) dm_malloc(sizeof(*ret));
if (ret) {
if (!memset(ret, 0, sizeof(*ret)) ||
!(ret->device_path = dbg_strdup(data->device_path))) {
dbg_free(ret);
!(ret->device_path = dm_strdup(data->device_path))) {
dm_free(ret);
ret = NULL;
} else {
ret->dso_data = dso_data;
@ -172,19 +167,19 @@ static struct thread_status *alloc_thread_status(struct message_data *data,
static void free_thread_status(struct thread_status *thread)
{
dbg_free(thread->device_path);
dbg_free(thread);
dm_free(thread->device_path);
dm_free(thread);
}
/* Allocate/free DSO data. */
static struct dso_data *alloc_dso_data(struct message_data *data)
{
struct dso_data *ret = (typeof(ret)) dbg_malloc(sizeof(*ret));
struct dso_data *ret = (typeof(ret)) dm_malloc(sizeof(*ret));
if (ret) {
if (!memset(ret, 0, sizeof(*ret)) ||
!(ret->dso_name = dbg_strdup(data->dso_name))) {
dbg_free(ret);
!(ret->dso_name = dm_strdup(data->dso_name))) {
dm_free(ret);
ret = NULL;
}
}
@ -194,8 +189,8 @@ static struct dso_data *alloc_dso_data(struct message_data *data)
static void free_dso_data(struct dso_data *data)
{
dbg_free(data->dso_name);
dbg_free(data);
dm_free(data->dso_name);
dm_free(data);
}
/* FIXME: Factor out. */
@ -221,11 +216,11 @@ static int fetch_string(char **ptr, char **src)
if ((p = strchr(*src, delimiter)))
*p = 0;
if ((*ptr = dbg_strdup(*src))) {
if ((*ptr = dm_strdup(*src))) {
if ((len = strlen(*ptr)))
*src += len;
else {
dbg_free(*ptr);
dm_free(*ptr);
*ptr = NULL;
}
@ -243,10 +238,10 @@ static int fetch_string(char **ptr, char **src)
static void free_message(struct message_data *message_data)
{
if (message_data->dso_name)
dbg_free(message_data->dso_name);
dm_free(message_data->dso_name);
if (message_data->device_path)
dbg_free(message_data->device_path);
dm_free(message_data->device_path);
}
/* Parse a register message from the client. */
@ -269,12 +264,12 @@ static int parse_message(struct message_data *message_data)
* Free string representaion of events.
* Not needed an more.
*/
dbg_free(message_data->events.str);
dm_free(message_data->events.str);
message_data->events.field = i;
}
if (message_data->timeout.str) {
uint32_t secs = atoi(message_data->timeout.str);
dbg_free(message_data->timeout.str);
dm_free(message_data->timeout.str);
message_data->timeout.secs = secs ? secs :
DM_EVENT_DEFAULT_TIMEOUT;
}
@ -305,10 +300,10 @@ static int storepid(int lf)
if ((len = snprintf(pid, sizeof(pid), "%u\n", getpid())) < 0)
return 0;
if (len > sizeof(pid))
len = sizeof(pid);
if (len > (int) sizeof(pid))
len = (int) sizeof(pid);
if (write(lf, pid, len) != len)
if (write(lf, pid, (size_t) len) != len)
return 0;
fsync(lf);
@ -579,6 +574,8 @@ static void monitor_unregister(void *arg)
}
/* Device monitoring thread. */
static void *monitor_thread(void *arg)
__attribute((noreturn));
static void *monitor_thread(void *arg)
{
struct thread_status *thread = arg;
@ -712,7 +709,7 @@ static char *create_dso_file_name(char *dso_name)
static char prefix[] = "libdevmapper-event-";
static char suffix[] = ".so";
if ((ret = dbg_malloc(strlen(prefix) +
if ((ret = dm_malloc(strlen(prefix) +
strlen(dso_name) +
strlen(suffix) + 1)))
sprintf(ret, "%s%s%s", prefix, dso_name, suffix);
@ -761,7 +758,7 @@ static struct dso_data *load_dso(struct message_data *data)
dlclose(dl);
free_dso_file:
dbg_free(dso_file);
dm_free(dso_file);
return ret;
}
@ -1054,7 +1051,8 @@ static int open_fifos(struct dm_event_fifos *fifos)
*/
static int client_read(struct dm_event_fifos *fifos, struct dm_event_daemon_message *msg)
{
int bytes = 0, ret = 0;
unsigned bytes = 0;
int ret = 0;
fd_set fds;
errno = 0;
@ -1077,7 +1075,8 @@ static int client_read(struct dm_event_fifos *fifos, struct dm_event_daemon_mess
*/
static int client_write(struct dm_event_fifos *fifos, struct dm_event_daemon_message *msg)
{
int bytes = 0, ret = 0;
unsigned bytes = 0;
int ret = 0;
fd_set fds;
errno = 0;

View File

@ -7,6 +7,7 @@
#define EXIT_FIFO_FAILURE 5
#define EXIT_CHDIR_FAILURE 6
void dmeventd(void);
void dmeventd(void)
__attribute((noreturn));
#endif /* __DMEVENTD_DOT_H__ */

View File

@ -44,7 +44,7 @@ static char *fetch_string(char **src)
if ((p = strchr(*src, delimiter)))
*p = 0;
if ((ret = strdup(*src)))
if ((ret = dm_strdup(*src)))
*src += strlen(ret) + 1;
if (p)
@ -80,7 +80,8 @@ static int parse_message(struct dm_event_daemon_message *msg, char **dso_name,
*/
static int daemon_read(struct dm_event_fifos *fifos, struct dm_event_daemon_message *msg)
{
int bytes = 0, ret = 0;
unsigned bytes = 0;
int ret = 0;
fd_set fds;
memset(msg, 0, sizeof(*msg));
@ -115,7 +116,8 @@ static int daemon_read(struct dm_event_fifos *fifos, struct dm_event_daemon_mess
/* Write message to daemon. */
static int daemon_write(struct dm_event_fifos *fifos, struct dm_event_daemon_message *msg)
{
int bytes = 0, ret = 0;
unsigned bytes = 0;
int ret = 0;
fd_set fds;
while (bytes < sizeof(*msg)) {
@ -158,11 +160,11 @@ static int daemon_talk(struct dm_event_fifos *fifos, struct dm_event_daemon_mess
*/
msg->opcode.cmd = cmd;
if (sizeof(msg->msg) <= snprintf(msg->msg, sizeof(msg->msg),
"%s %s %u %"PRIu32,
dso_name ? dso_name : "",
device ? device : "",
events, timeout)) {
if (sizeof(msg->msg) <= (unsigned) snprintf(msg->msg, sizeof(msg->msg),
"%s %s %u %"PRIu32,
dso_name ? dso_name : "",
device ? device : "",
events, timeout)) {
stack;
return -ENAMETOOLONG;
}
@ -410,7 +412,7 @@ int dm_event_register(char *dso_name, char *device_path,
struct dm_event_daemon_message msg;
if (!device_exists(device_path)) {
log_error("%s: device not found");
log_error("%s: device not found", device_path);
return 0;
}
@ -431,7 +433,7 @@ int dm_event_unregister(char *dso_name, char *device_path,
struct dm_event_daemon_message msg;
if (!device_exists(device_path)) {
log_error("%s: device not found");
log_error("%s: device not found", device_path);
return 0;
}
@ -460,9 +462,9 @@ int dm_event_get_registered_device(char **dso_name, char **device_path,
if (next){
if (*dso_name)
free(*dso_name);
dm_free(*dso_name);
if (*device_path)
free(*device_path);
dm_free(*device_path);
*dso_name = dso_name_arg;
*device_path = device_path_arg;
} else {

View File

@ -2,6 +2,7 @@ dm_lib_release
dm_lib_exit
dm_driver_version
dm_get_library_version
dm_log
dm_log_init
dm_log_init_verbose
dm_task_create

View File

@ -57,7 +57,7 @@ void dm_bit_union(dm_bitset_t out, dm_bitset_t in1, dm_bitset_t in2)
*/
static inline int _test_word(uint32_t test, int bit)
{
while (bit < DM_BITS_PER_INT) {
while (bit < (int) DM_BITS_PER_INT) {
if (test & (0x1 << bit))
return bit;
bit++;
@ -73,7 +73,10 @@ int dm_bit_get_next(dm_bitset_t bs, int last_bit)
last_bit++; /* otherwise we'll return the same bit again */
while (last_bit < bs[0]) {
/*
* bs[0] holds number of bits
*/
while (last_bit < (int) bs[0]) {
word = last_bit >> INT_SHIFT;
test = bs[word + 1];
bit = last_bit & (DM_BITS_PER_INT - 1);

View File

@ -877,7 +877,7 @@ int dm_format_dev(char *buf, int bufsize, uint32_t dev_major,
if (bufsize < 8)
return 0;
r = snprintf(buf, bufsize, "%u:%u", dev_major, dev_minor);
r = snprintf(buf, (size_t) bufsize, "%u:%u", dev_major, dev_minor);
if (r < 0 || r > bufsize - 1)
return 0;
@ -1028,7 +1028,8 @@ struct target *create_target(uint64_t start, uint64_t len, const char *type,
struct target *t = dm_malloc(sizeof(*t));
if (!t) {
log_error("create_target: malloc(%d) failed", sizeof(*t));
log_error("create_target: malloc(%" PRIsize_t ") failed",
sizeof(*t));
return NULL;
}

View File

@ -42,7 +42,8 @@
*/
typedef void (*dm_log_fn) (int level, const char *file, int line,
const char *f, ...);
const char *f, ...)
__attribute__ ((format(printf, 4, 5)));
/*
* The library user may wish to register their own

View File

@ -61,14 +61,14 @@ static void _default_log(int level, const char *file, int line,
fprintf(stdout, "\n");
}
dm_log_fn _log = _default_log;
dm_log_fn dm_log = _default_log;
void dm_log_init(dm_log_fn fn)
{
if (fn)
_log = fn;
dm_log = fn;
else
_log = _default_log;
dm_log = _default_log;
}
void dm_log_init_verbose(int level)
@ -96,7 +96,8 @@ struct dm_task *dm_task_create(int type)
struct dm_task *dmt = dm_malloc(sizeof(*dmt));
if (!dmt) {
log_error("dm_task_create: malloc(%d) failed", sizeof(*dmt));
log_error("dm_task_create: malloc(%" PRIsize_t ") failed",
sizeof(*dmt));
return NULL;
}

View File

@ -141,7 +141,7 @@ static int _dm_snprintf(char *buf, size_t bufsize, const char *format, ...)
n = vsnprintf(buf, bufsize, format, ap);
va_end(ap);
if (n < 0 || (n > bufsize - 1))
if (n < 0 || (n > (int) bufsize - 1))
return -1;
return n;

View File

@ -20,10 +20,6 @@
#include <fcntl.h>
#include <dirent.h>
#ifdef linux
# include <malloc.h>
#endif
static int _create_dir_recursive(const char *dir)
{
char *orig, *s;
@ -31,7 +27,7 @@ static int _create_dir_recursive(const char *dir)
log_verbose("Creating directory \"%s\"", dir);
/* Create parent directories */
orig = s = strdup(dir);
orig = s = dm_strdup(dir);
while ((s = strchr(s, '/')) != NULL) {
*s = '\0';
if (*orig) {
@ -39,13 +35,13 @@ static int _create_dir_recursive(const char *dir)
if (rc < 0 && errno != EEXIST) {
log_error("%s: mkdir failed: %s", orig,
strerror(errno));
free(orig);
dm_free(orig);
return 0;
}
}
*s++ = '/';
}
free(orig);
dm_free(orig);
/* Create final directory */
rc = mkdir(dir, 0777);

View File

@ -198,9 +198,9 @@ int dm_dump_memory_debug(void)
}
str[sizeof(str) - 1] = '\0';
_log(_LOG_INFO, mb->file, mb->line,
"block %d at %p, size %" PRIsize_t "\t [%s]",
mb->id, mb->magic, mb->length, str);
dm_log(_LOG_INFO, mb->file, mb->line,
"block %d at %p, size %" PRIsize_t "\t [%s]",
mb->id, mb->magic, mb->length, str);
tot += mb->length;
}

View File

@ -85,7 +85,7 @@ void *dm_pool_alloc_aligned(struct dm_pool *p, size_t s, unsigned alignment)
/* have we got room ? */
if (!c || (c->begin > c->end) || (c->end - c->begin < s)) {
/* allocate new chunk */
int needed = s + alignment + sizeof(struct chunk);
size_t needed = s + alignment + sizeof(struct chunk);
c = _new_chunk(p, (needed > p->chunk_size) ?
needed : p->chunk_size);

View File

@ -438,7 +438,8 @@ static int _rename(int argc, char **argv, void *data)
static int _message(int argc, char **argv, void *data)
{
int r = 0, sz = 1, i;
int r = 0, i;
size_t sz = 1;
struct dm_task *dmt;
char *str;
@ -455,7 +456,7 @@ static int _message(int argc, char **argv, void *data)
argv++;
}
if (!dm_task_set_sector(dmt, atoll(argv[1])))
if (!dm_task_set_sector(dmt, (uint64_t) atoll(argv[1])))
goto out;
argc -= 2;
@ -580,7 +581,7 @@ static int _wait(int argc, char **argv, void *data)
}
return _simple(DM_DEVICE_WAITEVENT, name,
(argc > 1) ? atoi(argv[argc - 1]) : 0, 1);
(argc > 1) ? (uint32_t) atoi(argv[argc - 1]) : 0, 1);
}
static int _process_all(int argc, char **argv,
@ -622,7 +623,7 @@ static int _process_all(int argc, char **argv,
return r;
}
static void _display_dev(struct dm_task *dmt, char *name)
static void _display_dev(struct dm_task *dmt, const char *name)
{
struct dm_info info;
@ -635,7 +636,7 @@ static int _mknodes(int argc, char **argv, void *data)
return dm_mknodes(argc > 1 ? argv[1] : NULL);
}
static int _exec_command(char *name)
static int _exec_command(const char *name)
{
int n;
static char path[PATH_MAX];
@ -651,7 +652,7 @@ static int _exec_command(char *name)
return 0;
n = snprintf(path, sizeof(path), "%s/%s", dm_dir(), name);
if (n < 0 || n > sizeof(path) - 1)
if (n < 0 || n > (int) sizeof(path) - 1)
return 0;
if (!argc) {
@ -704,7 +705,7 @@ static int _status(int argc, char **argv, void *data)
char *params;
int cmd;
struct dm_names *names = (struct dm_names *) data;
char *name = NULL;
const char *name = NULL;
int matched = 0;
int ls_only = 0;
struct dm_info info;
@ -742,7 +743,7 @@ static int _status(int argc, char **argv, void *data)
goto out;
if (!name)
name = (char *) dm_task_get_name(dmt);
name = dm_task_get_name(dmt);
/* Fetch targets and print 'em */
do {