]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
erasure-code: allow loading a plugin from factory()
authorLoic Dachary <loic@dachary.org>
Sat, 25 Jan 2014 21:35:34 +0000 (22:35 +0100)
committerLoic Dachary <loic@dachary.org>
Thu, 27 Mar 2014 13:26:54 +0000 (14:26 +0100)
The Mutex scope is restricted to only protect the load() method and not
the factory() method. This allows a plugin to load another plugin from
within the factory() method.

Reviewed-By: Christophe Courtaut <christophe.courtaut@gmail.com>
Signed-off-by: Loic Dachary <loic@dachary.org>
src/erasure-code/ErasureCodePlugin.cc

index a76d6140ccab9cab2f63df914c3340b658a37ffa..63494415de6f9543f3f251b2558e18b0b47de6e1 100644 (file)
@@ -68,15 +68,18 @@ int ErasureCodePluginRegistry::factory(const std::string &plugin_name,
                                       ErasureCodeInterfaceRef *erasure_code,
                                       ostream &ss)
 {
-  Mutex::Locker l(lock);
-  ErasureCodePlugin *plugin = get(plugin_name);
-  if (plugin == 0) {
+  ErasureCodePlugin *plugin;
+  {
+    Mutex::Locker l(lock);
     int r = 0;
-    loading = true;
-    r = load(plugin_name, parameters, &plugin, ss);
-    loading = false;
-    if (r != 0)
-      return r;
+    plugin = get(plugin_name);
+    if (plugin == 0) {
+      loading = true;
+      r = load(plugin_name, parameters, &plugin, ss);
+      loading = false;
+      if (r != 0)
+       return r;
+    }
   }
 
   return plugin->factory(parameters, erasure_code);