]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
dedup: Fix #7033 device not initialized when using legacy config format
authorAlain Spineux <alain@baculasystems.com>
Tue, 24 Nov 2020 13:11:40 +0000 (14:11 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:02:59 +0000 (09:02 +0100)
- the default dedupengine had no driver_type and was not initialized as
  a Legacy or Dedup2 dedupengine
- When no Dedupengine is specified in a Device resource and if there is
  only one dedupengine specified in the Storage resource or in a
  Dedupengine resource then use this one. Else return an error.

bacula/src/stored/stored_conf.c

index baa1d618768d51a7f89bfb5eac57fcc0cc1dfb9e..f66803d340e336728e7da04e875230ce195ae020 100644 (file)
@@ -1096,12 +1096,25 @@ bool save_resource(CONFIG *config, int type, RES_ITEM *items, int pass)
           * "default_legacy_dedupengine" aka the DDE defined in storage
           */
          if (res->res_dev.dev_type == B_DEDUP_DEV && res->res_dev.dedup == NULL) {
-            URES *dedup;
-            if ((dedup = (URES *)GetResWithName(R_DEDUP, default_legacy_dedupengine)) == NULL) {
-               Mmsg(config->m_errmsg,  _("Cannot find dedupengine for device %s\n"), res_all.res_dir.hdr.name);
+            /* The "Dedupengine" is not specified in this Device resource */
+            /* If there is only one Dedupengine defined use it */
+            int i = 0;
+            DEDUPRES *dedup, *prev_dedup = NULL;
+            foreach_res(dedup, R_DEDUP) {
+               prev_dedup = dedup;
+               i++;
+            }
+            if (i == 1) {
+               res->res_dev.dedup = prev_dedup;
+               Dmsg2(0, "Select dedupengine %s for device %s\n", prev_dedup->hdr.name, res_all.res_dir.hdr.name);
+            } else if (i == 0){
+               Mmsg(config->m_errmsg,  _("Cannot find any dedupengine for the device %s\n"), res_all.res_dir.hdr.name);
+               return false;
+            } else {
+               /* i > 1 */
+               Mmsg(config->m_errmsg,  _("Dedupengine unspecified for device %s\n"), res_all.res_dir.hdr.name);
                return false;
             }
-            res->res_dev.dedup = &dedup->res_dedup;
          }
 #endif
          break;