]> sourceware.org Git - dm.git/commitdiff
Allow optional verbose logging
authorAlasdair Kergon <agk@redhat.com>
Tue, 21 Jan 2003 21:25:11 +0000 (21:25 +0000)
committerAlasdair Kergon <agk@redhat.com>
Tue, 21 Jan 2003 21:25:11 +0000 (21:25 +0000)
lib/.export.sym
lib/libdevmapper.h
lib/libdm-common.c
lib/libdm-common.h.in

index 6c72578ee741b7d33dba15369c77b5eb66271b4a..4cc251b1324464bd819d2d96fa6d78a5043b74d0 100644 (file)
@@ -1,6 +1,7 @@
-Base { 
+{
        global:
                dm_log_init;
+               dm_log_init_verbose;
                dm_task_create;
                dm_task_destroy;
                dm_task_set_name;
@@ -21,4 +22,3 @@ Base {
        local:
                *;
 };
-
index 0ecc88a234bb5f15e3f8a53f63acfa2f604b8a2c..1cd4865b25bc95854234ed726b9febbbecd22921 100644 (file)
@@ -29,6 +29,7 @@ typedef void (*dm_log_fn) (int level, const char *file, int line,
  * stderr.
  */
 void dm_log_init(dm_log_fn fn);
+void dm_log_init_verbose(int level);
 
 enum {
        DM_DEVICE_CREATE,
index 6ed3f47769b2b58c90591d2e83fe06f6317d0d16..654e5e58fd4290079b09de9ffe2b42a7b791d8c4 100644 (file)
@@ -6,25 +6,24 @@
 
 #include "libdm-targets.h"
 #include "libdm-common.h"
-#include "libdevmapper.h"
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <sys/param.h>
 #include <sys/stat.h>
-#include <sys/types.h>
+#include <unistd.h>
 #include <errno.h>
-#include <linux/kdev_t.h>
 #include <linux/dm-ioctl.h>
+#include <linux/kdev_t.h>
 
 #define DEV_DIR "/dev/"
 
 static char _dm_dir[PATH_MAX] = DEV_DIR DM_DIR;
 
+static int _verbose = 0;
+
 /*
  * Library users can provide their own logging
  * function.
@@ -34,19 +33,22 @@ static void _default_log(int level, const char *file, int line,
 {
        va_list ap;
 
-       if (level > _LOG_WARN)
+       if (level > _LOG_WARN && !_verbose)
                return;
 
        va_start(ap, f);
 
-       if (level == _LOG_WARN)
-               vprintf(f, ap);
-       else
+       if (level < _LOG_WARN)
                vfprintf(stderr, f, ap);
+       else
+               vprintf(f, ap);
 
        va_end(ap);
 
-       fprintf(stderr, "\n");
+       if (level < _LOG_WARN)
+               fprintf(stderr, "\n");
+       else
+               printf("\n");
 }
 
 dm_log_fn _log = _default_log;
@@ -56,6 +58,11 @@ void dm_log_init(dm_log_fn fn)
        _log = fn;
 }
 
+void dm_log_init_verbose(int level)
+{
+       _verbose = level;
+}
+
 static void _build_dev_path(char *buffer, size_t len, const char *dev_name)
 {
        /* If there's a /, assume caller knows what they're doing */
@@ -75,6 +82,9 @@ struct dm_task *dm_task_create(int type)
 {
        struct dm_task *dmt = malloc(sizeof(*dmt));
 
+       if (!dm_check_version())
+               return NULL;
+
        if (!dmt) {
                log_error("dm_task_create: malloc(%d) failed", sizeof(*dmt));
                return NULL;
@@ -84,6 +94,7 @@ struct dm_task *dm_task_create(int type)
 
        dmt->type = type;
        dmt->minor = -1;
+
        return dmt;
 }
 
@@ -163,10 +174,11 @@ int dm_task_add_target(struct dm_task *dmt, uint64_t start, uint64_t size,
        return 1;
 }
 
-int add_dev_node(const char *dev_name, dev_t dev)
+int add_dev_node(const char *dev_name, uint32_t major, uint32_t minor)
 {
        char path[PATH_MAX];
        struct stat info;
+       dev_t dev = MKDEV(major, minor);
 
        _build_dev_path(path, sizeof(path), dev_name);
 
@@ -212,7 +224,7 @@ int rename_dev_node(const char *old_name, const char *new_name)
                }
 
                if (unlink(newpath) < 0) {
-                       if (errno == EPERM) {   
+                       if (errno == EPERM) {
                                /* devfs, entry has already been renamed */
                                return 1;
                        }
index 85763cb6a16059f8621dd4a98e7d0b92e437b803..84eedd39bf5260d16ab69967ca06cf44e472c8d9 100644 (file)
@@ -7,6 +7,8 @@
 #ifndef LIB_DMCOMMON_H
 #define LIB_DMCOMMON_H
 
+#include "libdevmapper.h"
+
 #define _LOG_DEBUG 7
 #define _LOG_INFO 6
 #define _LOG_NOTICE 5
@@ -14,7 +16,7 @@
 #define _LOG_ERR 3
 #define _LOG_FATAL 2
 
-dm_log_fn _log;
+extern dm_log_fn _log;
 
 #define log_error(msg, x...) _log(_LOG_ERR, __FILE__, __LINE__, msg, ## x)
 #define log_print(msg, x...) _log(_LOG_WARN, __FILE__, __LINE__, msg, ## x)
@@ -23,10 +25,10 @@ dm_log_fn _log;
 #define log_debug(msg, x...) _log(_LOG_DEBUG, __FILE__, __LINE__, msg, ## x)
 
 struct target *create_target(uint64_t start,
-                             uint64_t len,
-                             const char *type, const char *params);
+                            uint64_t len,
+                            const char *type, const char *params);
 
-int add_dev_node(const char *dev_name, dev_t dev);
+int add_dev_node(const char *dev_name, uint32_t minor, uint32_t major);
 int rm_dev_node(const char *dev_name);
 int rename_dev_node(const char *old_name, const char *new_name);
 
This page took 0.032575 seconds and 5 git commands to generate.