]> sourceware.org Git - lvm2.git/commitdiff
toolcontext: add switches to create_toolcontext for connections and filters init
authorPeter Rajnoha <prajnoha@redhat.com>
Thu, 30 Jul 2015 08:34:10 +0000 (10:34 +0200)
committerPeter Rajnoha <prajnoha@redhat.com>
Thu, 30 Jul 2015 11:54:09 +0000 (13:54 +0200)
Make it possible to decide whether we want to initialize connections and
filters together with toolcontext creation.

Add "filters" and "connections" fields to struct
cmd_context_initialized_parts and set these in cmd_context.initialized
instance accordingly.

(For now, all create_toolcontext calls do initialize connections and
filters, we'll change that in subsequent patch appropriately.)

daemons/clvmd/lvm-functions.c
daemons/lvmetad/testclient.c
lib/commands/toolcontext.c
lib/commands/toolcontext.h
liblvm/lvm_base.c
tools/lvm2cmdline.h
tools/lvmcmdlib.c
tools/lvmcmdline.c

index e7dbfde697ba542fc8015161220e5b4c02b4395a..99e731789ae79508b906c8799cc501c23bde7900 100644 (file)
@@ -899,7 +899,7 @@ int init_clvm(struct dm_hash_table *excl_uuid)
        if (!get_initial_state(excl_uuid))
                log_error("Cannot load initial lock states.");
 
-       if (!(cmd = create_toolcontext(1, NULL, 0, 1))) {
+       if (!(cmd = create_toolcontext(1, NULL, 0, 1, 1, 1))) {
                log_error("Failed to allocate command context");
                return 0;
        }
index fbf7b6509fa415f3a4d17fe67b6a338eb3beb7d5..59aedc6904c223b34a8d5110247fe66c64969f69 100644 (file)
@@ -124,7 +124,7 @@ int main(int argc, char **argv) {
 
        if (argc > 1) {
                int i;
-               struct cmd_context *cmd = create_toolcontext(0, NULL, 0, 0);
+               struct cmd_context *cmd = create_toolcontext(0, NULL, 0, 0, 1, 1);
                for (i = 1; i < argc; ++i) {
                        const char *uuid = NULL;
                        scan(h, argv[i]);
index dadb3c559eb658d184087575fcdcc539d36fc22e..c087820f989b1bd489caa94499e55dad9e8d4e42 100644 (file)
@@ -55,7 +55,6 @@
 #endif
 
 static const size_t linebuffer_size = 4096;
-static int _init_connections(struct cmd_context *cmd);
 
 /*
  * Copy the input string, removing invalid characters.
@@ -675,9 +674,6 @@ static int _process_config(struct cmd_context *cmd)
        init_detect_internal_vg_cache_corruption
                (find_config_tree_bool(cmd, global_detect_internal_vg_cache_corruption_CFG, NULL));
 
-       if (!_init_connections(cmd))
-               return_0;
-
        if (!_init_system_id(cmd))
                return_0;
 
@@ -1165,7 +1161,7 @@ bad:
  *     md component filter -> fw raid filter
  *
  */
-static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
+int init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
 {
        const char *dev_cache;
        struct dev_filter *filter = NULL, *filter_components[2] = {0};
@@ -1173,6 +1169,11 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
        const struct dm_config_node *cn;
        struct timespec ts, cts;
 
+       if (!cmd->initialized.connections) {
+               log_error(INTERNAL_ERROR "connections must be initialized before filters");
+               return 0;
+       }
+
        cmd->dump_filter = 0;
 
        cmd->lvmetad_filter = _init_lvmetad_filter_chain(cmd);
@@ -1253,6 +1254,7 @@ static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache
                                    dev_cache);
        }
 
+       cmd->initialized.filters = 1;
        return 1;
 bad:
        if (!filter) {
@@ -1276,6 +1278,7 @@ bad:
        if (cmd->lvmetad_filter)
                cmd->lvmetad_filter->destroy(cmd->lvmetad_filter);
 
+       cmd->initialized.filters = 0;
        return 0;
 }
 
@@ -1696,26 +1699,33 @@ static int _init_lvmpolld(struct cmd_context *cmd)
        return 1;
 }
 
-static int _init_connections(struct cmd_context *cmd)
+int init_connections(struct cmd_context *cmd)
 {
+
        if (!_init_lvmetad(cmd)) {
                log_error("Failed to initialize lvmetad connection.");
-               return 0;
+               goto bad;
        }
 
        if (!_init_lvmpolld(cmd)) {
                log_error("Failed to initialize lvmpolld connection.");
-               return 0;
+               goto bad;
        }
 
+       cmd->initialized.connections = 1;
        return 1;
+bad:
+       cmd->initialized.connections = 0;
+       return 0;
 }
 
 /* Entry point */
 struct cmd_context *create_toolcontext(unsigned is_long_lived,
                                       const char *system_dir,
                                       unsigned set_buffering,
-                                      unsigned threaded)
+                                      unsigned threaded,
+                                      unsigned set_connections,
+                                      unsigned set_filters)
 {
        struct cmd_context *cmd;
        FILE *new_stream;
@@ -1859,9 +1869,6 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
        if (!_init_dev_cache(cmd))
                goto_out;
 
-       if (!_init_filters(cmd, 1))
-               goto_out;
-
        memlock_init(cmd);
 
        if (!_init_formats(cmd))
@@ -1880,6 +1887,12 @@ struct cmd_context *create_toolcontext(unsigned is_long_lived,
 
        _init_globals(cmd);
 
+       if (set_connections && !init_connections(cmd))
+               return_0;
+
+       if (set_filters && !init_filters(cmd, 1))
+               goto_out;
+
        cmd->default_settings.cache_vgmetadata = 1;
        cmd->current_settings = cmd->default_settings;
 
@@ -1957,14 +1970,19 @@ static void _destroy_filters(struct cmd_context *cmd)
                cmd->full_filter->destroy(cmd->full_filter);
                cmd->lvmetad_filter = cmd->filter = cmd->full_filter = NULL;
        }
+       cmd->initialized.filters = 0;
 }
 
 int refresh_filters(struct cmd_context *cmd)
 {
        int r, saved_ignore_suspended_devices = ignore_suspended_devices();
 
+       if (!cmd->initialized.filters)
+               /* if filters not initialized, there's nothing to refresh */
+               return 1;
+
        _destroy_filters(cmd);
-       if (!(r = _init_filters(cmd, 0)))
+       if (!(r = init_filters(cmd, 0)))
                 stack;
 
        /*
@@ -2074,9 +2092,6 @@ int refresh_toolcontext(struct cmd_context *cmd)
        if (!_init_dev_cache(cmd))
                return_0;
 
-       if (!_init_filters(cmd, 0))
-               return_0;
-
        if (!_init_formats(cmd))
                return_0;
 
@@ -2091,6 +2106,12 @@ int refresh_toolcontext(struct cmd_context *cmd)
 
        cmd->initialized.config = 1;
 
+       if (cmd->initialized.connections && !init_connections(cmd))
+               return_0;
+
+       if (cmd->initialized.filters && !init_filters(cmd, 0))
+               return_0;
+
        reset_lvm_errno(1);
        return 1;
 }
@@ -2159,6 +2180,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
        lvmetad_release_token();
        lvmetad_disconnect();
        lvmpolld_disconnect();
+       cmd->initialized.connections = 0;
 
        release_log_memory();
        activation_exit();
index c59024b3bad7426d91b0e3183ee88a23f980fee4..57feb0183c3630f257faa001fb551948bf24704a 100644 (file)
@@ -62,6 +62,8 @@ struct config_tree_list {
 
 struct cmd_context_initialized_parts {
        unsigned config:1; /* used to reinitialize config if previous init was not successful */
+       unsigned filters:1;
+       unsigned connections:1;
 };
 
 /* FIXME Split into tool & library contexts */
@@ -171,13 +173,17 @@ struct cmd_context {
 struct cmd_context *create_toolcontext(unsigned is_long_lived,
                                       const char *system_dir,
                                       unsigned set_buffering,
-                                      unsigned threaded);
+                                      unsigned threaded,
+                                      unsigned set_connections,
+                                      unsigned set_filters);
 void destroy_toolcontext(struct cmd_context *cmd);
 int refresh_toolcontext(struct cmd_context *cmd);
 int refresh_filters(struct cmd_context *cmd);
 int process_profilable_config(struct cmd_context *cmd);
 int config_files_changed(struct cmd_context *cmd);
 int init_lvmcache_orphans(struct cmd_context *cmd);
+int init_filters(struct cmd_context *cmd, unsigned load_persistent_cache);
+int init_connections(struct cmd_context *cmd);
 
 struct format_type *get_format_by_name(struct cmd_context *cmd, const char *format);
 
index c1954d12fad4a1a6936447931b829a396c6b311b..5b14c3bdf17b1e9a78154fee793f625125322fd4 100644 (file)
@@ -45,7 +45,7 @@ static lvm_t _lvm_init(const char *system_dir)
        /* create context */
        /* FIXME: split create_toolcontext */
        /* FIXME: make all globals configurable */
-       cmd = create_toolcontext(0, system_dir, 0, 0);
+       cmd = create_toolcontext(0, system_dir, 0, 0, 1, 1);
        if (!cmd)
                return NULL;
 
index 5c4889e1ea7f4fbfc81a5effaa5ce6cb3546c0b2..fe77d569a19a03d083d5d036639ed391d1019a38 100644 (file)
@@ -31,7 +31,7 @@ int lvm2_main(int argc, char **argv);
 void *cmdlib_lvm2_init(unsigned static_compile);
 void lvm_fin(struct cmd_context *cmd);
 
-struct cmd_context *init_lvm(void);
+struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters);
 void lvm_register_commands(void);
 int lvm_split(char *str, int *argc, char **argv, int max);
 int lvm_run_command(struct cmd_context *cmd, int argc, char **argv);
index 76576c2fe2adf2368954b096220fb125e4aaaec5..26f160f88da34b48e933d50baa7a4372a4704902 100644 (file)
@@ -33,7 +33,7 @@ void *cmdlib_lvm2_init(unsigned static_compile)
        lvm_register_commands();
 
        init_is_static(static_compile);
-       if (!(cmd = init_lvm()))
+       if (!(cmd = init_lvm(1, 1)))
                return NULL;
 
        return (void *) cmd;
index 98a2c30709760fd4e483e19b37bc85d857989fc0..0c88164a7998f2b000aa090461b736a96ba48ac2 100644 (file)
@@ -1873,7 +1873,7 @@ static int _close_stray_fds(const char *command)
        return 1;
 }
 
-struct cmd_context *init_lvm(void)
+struct cmd_context *init_lvm(unsigned set_connections, unsigned set_filters)
 {
        struct cmd_context *cmd;
 
@@ -1887,7 +1887,8 @@ struct cmd_context *init_lvm(void)
         */
        dm_set_name_mangling_mode(DM_STRING_MANGLING_NONE);
 
-       if (!(cmd = create_toolcontext(0, NULL, 1, 0))) {
+       if (!(cmd = create_toolcontext(0, NULL, 1, 0,
+                       set_connections, set_filters))) {
                udev_fin_library_context();
                return_NULL;
        }
@@ -2055,7 +2056,7 @@ int lvm2_main(int argc, char **argv)
        if (!alias && argc > 1 && !strcmp(argv[1], "version"))
                return lvm_return_code(version(NULL, argc, argv));
 
-       if (!(cmd = init_lvm()))
+       if (!(cmd = init_lvm(1, 1)))
                return -1;
 
        cmd->argv = argv;
This page took 0.057298 seconds and 5 git commands to generate.