multipath: add '-t' option to dump internal hwtable
authorHannes Reinecke <hare@suse.de>
Mon, 30 Apr 2007 07:37:38 +0000 (09:37 +0200)
committerHannes Reinecke <hare@suse.de>
Wed, 18 May 2011 12:21:59 +0000 (14:21 +0200)
This patch adds an option '-t' to dump the internal hardware table.
Quite handy if you want to know the default settings.
In doing so it also fixes the keyword allocation; currently the
keywords are only initialised if a configuration file is used.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/config.c
libmultipath/parser.c
libmultipath/parser.h
libmultipath/print.c
multipath/main.c

index 5906a96..87039f0 100644 (file)
@@ -513,6 +513,7 @@ load_config (char * file)
         * read the config file
         */
        set_current_keywords(&conf->keywords);
+       alloc_keywords();
        if (filepresent(file)) {
                int builtin_hwtable_size;
 
index a2cbd70..79c2d22 100644 (file)
@@ -25,8 +25,8 @@
 
 /* local vars */
 static int sublevel = 0;
-vector keywords = NULL;
-vector *keywords_addr = NULL;
+static vector keywords = NULL;
+static vector *keywords_addr = NULL;
 static int line_nr;
 
 void set_current_keywords (vector *k)
@@ -533,16 +533,23 @@ out:
        return r;
 }
 
+int alloc_keywords(void)
+{
+       if (!keywords)
+               keywords = vector_alloc();
+
+       if (!keywords)
+               return 1;
+
+       return 0;
+}
+
 /* Data initialization */
 int
 init_data(char *conf_file, void (*init_keywords) (void))
 {
        int r;
 
-       if (!keywords)
-               keywords = vector_alloc();
-       if (!keywords)
-               return 1;
        stream = fopen(conf_file, "r");
        if (!stream) {
                syslog(LOG_WARNING, "Configuration file open problem");
index fb182ec..8bf1c76 100644 (file)
@@ -77,6 +77,7 @@ extern vector read_value_block(void);
 extern int alloc_value_block(vector strvec, void (*alloc_func) (vector));
 extern void *set_value(vector strvec);
 extern int process_stream(vector keywords);
+extern int alloc_keywords(void);
 extern int init_data(char *conf_file, void (*init_keywords) (void));
 extern struct keyword * find_keyword(vector v, char * name);
 void set_current_keywords (vector *k);
index ba4210e..37a4e04 100644 (file)
@@ -860,7 +860,7 @@ snprint_hwentry (char * buff, int len, struct hwentry * hwe)
        if (fwd > len)
                return len;
        iterate_sub_keywords(rootkw, kw, i) {
-               fwd += snprint_keyword(buff + fwd, len - fwd, "\t\t%k %v\n",
+               fwd += snprint_keyword(buff + fwd, len - fwd, "\t\t%k \"%v\"\n",
                                kw, hwe);
                if (fwd > len)
                        return len;
index de50e65..f455985 100644 (file)
@@ -82,6 +82,7 @@ usage (char * progname)
        fprintf (stderr, "  %s [-d] [-r] [-v lvl] [-p pol] [-b fil] [dev]\n", progname);
        fprintf (stderr, "  %s -l|-ll|-f [-v lvl] [-b fil] [dev]\n", progname);
        fprintf (stderr, "  %s -F [-v lvl]\n", progname);
+       fprintf (stderr, "  %s -t\n", progname);
        fprintf (stderr, "  %s -h\n", progname);
        fprintf (stderr,
                "\n"
@@ -92,6 +93,7 @@ usage (char * progname)
                "  -f      flush a multipath device map\n" \
                "  -F      flush all multipath device maps\n" \
                "  -d      dry run, do not create or update devmaps\n" \
+               "  -t      dump internal hardware table\n" \
                "  -r      force devmap reload\n" \
                "  -p      policy failover|multibus|group_by_serial|group_by_prio\n" \
                "  -b fil  bindings file location\n" \
@@ -249,14 +251,14 @@ configure (void)
                else
                        dev = conf->dev;
        }
-       
+
        /*
         * if we have a blacklisted device parameter, exit early
         */
-       if (dev && 
+       if (dev &&
            (filter_devnode(conf->blist_devnode, conf->elist_devnode, dev) > 0))
                        goto out;
-       
+
        /*
         * scope limiting must be translated into a wwid
         * failing the translation is fatal (by policy)
@@ -323,6 +325,55 @@ out:
        return r;
 }
 
+static int
+dump_config (void)
+{
+       char * c;
+       char * reply;
+       unsigned int maxlen = 256;
+       int again = 1;
+
+       reply = MALLOC(maxlen);
+
+       while (again) {
+               if (!reply)
+                       return 1;
+               c = reply;
+               c += snprint_defaults(c, reply + maxlen - c);
+               again = ((c - reply) == maxlen);
+               if (again) {
+                       reply = REALLOC(reply, maxlen *= 2);
+                       continue;
+               }
+               c += snprint_blacklist(c, reply + maxlen - c);
+               again = ((c - reply) == maxlen);
+               if (again) {
+                       reply = REALLOC(reply, maxlen *= 2);
+                       continue;
+               }
+               c += snprint_blacklist_except(c, reply + maxlen - c);
+               again = ((c - reply) == maxlen);
+               if (again) {
+                       reply = REALLOC(reply, maxlen *= 2);
+                       continue;
+               }
+               c += snprint_hwtable(c, reply + maxlen - c, conf->hwtable);
+               again = ((c - reply) == maxlen);
+               if (again) {
+                       reply = REALLOC(reply, maxlen *= 2);
+                       continue;
+               }
+               c += snprint_mptable(c, reply + maxlen - c, conf->mptable);
+               again = ((c - reply) == maxlen);
+               if (again)
+                       reply = REALLOC(reply, maxlen *= 2);
+       }
+
+       printf("%s", reply);
+       FREE(reply);
+       return 0;
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -342,19 +393,11 @@ main (int argc, char *argv[])
        if (load_config(DEFAULT_CONFIGFILE))
                exit(1);
 
-       if (init_checkers()) {
-               condlog(0, "failed to initialize checkers");
-               exit(1);
-       }
-       if (init_prio()) {
-               condlog(0, "failed to initialize prioritizers");
-               exit(1);
-       }
        if (sysfs_init(conf->sysfs_dir, FILE_NAME_SIZE)) {
                condlog(0, "multipath tools need sysfs mounted");
                exit(1);
        }
-       while ((arg = getopt(argc, argv, ":dhl::FfM:v:p:b:Br")) != EOF ) {
+       while ((arg = getopt(argc, argv, ":dhl::FfM:v:p:b:Brt")) != EOF ) {
                switch(arg) {
                case 1: printf("optarg : %s\n",optarg);
                        break;
@@ -366,7 +409,7 @@ main (int argc, char *argv[])
                        conf->verbosity = atoi(optarg);
                        break;
                case 'b':
-                       conf->bindings_file = optarg;
+                       conf->bindings_file = strdup(optarg);
                        break;
                case 'B':
                        conf->bindings_read_only = 1;
@@ -398,23 +441,26 @@ main (int argc, char *argv[])
                        if (conf->pgpolicy_flag == -1) {
                                printf("'%s' is not a valid policy\n", optarg);
                                usage(argv[0]);
-                       }                
+                       }
                        break;
                case 'r':
                        conf->force_reload = 1;
                        break;
+               case 't':
+                       dump_config();
+                       goto out;
                case 'h':
                        usage(argv[0]);
                case ':':
                        fprintf(stderr, "Missing option arguement\n");
-                       usage(argv[0]);        
+                       usage(argv[0]);
                case '?':
                        fprintf(stderr, "Unknown switch: %s\n", optarg);
                        usage(argv[0]);
                default:
                        usage(argv[0]);
                }
-       }        
+       }
        if (optind < argc) {
                conf->dev = MALLOC(FILE_NAME_SIZE);
 
@@ -443,6 +489,14 @@ main (int argc, char *argv[])
                                conf->max_fds, strerror(errno));
        }
 
+       if (init_checkers()) {
+               condlog(0, "failed to initialize checkers");
+               exit(1);
+       }
+       if (init_prio()) {
+               condlog(0, "failed to initialize prioritizers");
+               exit(1);
+       }
        dm_init();
 
        if (conf->remove == FLUSH_ONE) {