]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/dird.c
Add heap stats to Dir and SD -- eliminate #ifdefs
[bacula/bacula] / bacula / src / dird / dird.c
index c119440985667687fa9041f476c44a730105bab2..38a6678a6efa18fec3bbe52c38460a197e6bbd9a 100644 (file)
@@ -298,10 +298,10 @@ static void free_saved_resources(int table)
    int num = r_last - r_first + 1;
    RES **res_tab = reload_table[table].res_table;
    if (!res_tab) {
-      Dmsg1(000, "res_tab for table %d already released.\n", table);
+      Dmsg1(100, "res_tab for table %d already released.\n", table);
       return;
    }
-   Dmsg1(000, "Freeing resources for table %d\n", table);
+   Dmsg1(100, "Freeing resources for table %d\n", table);
    for (int j=0; j<num; j++) {
       free_resource(res_tab[j], r_first + j);
    }
@@ -316,18 +316,15 @@ static void free_saved_resources(int table)
  * it goes to zero, no one is using the associated
  * resource table, so free it.
  */
-static void reload_job_end_cb(JCR *jcr)
+static void reload_job_end_cb(JCR *jcr, void *ctx)
 {
-   if (jcr->reload_id == 0) {
-      return;                        /* nothing to do */
-   }
-   int i = jcr->reload_id - 1;
-   Dmsg3(000, "reload job_end JobId=%d table=%d cnt=%d\n", jcr->JobId,
-      i, reload_table[i].job_count);
+   int reload_id = (int)ctx;
+   Dmsg3(100, "reload job_end JobId=%d table=%d cnt=%d\n", jcr->JobId,
+      reload_id, reload_table[reload_id].job_count);
    lock_jcr_chain();
    LockRes();
-   if (--reload_table[i].job_count <= 0) {
-      free_saved_resources(i);
+   if (--reload_table[reload_id].job_count <= 0) {
+      free_saved_resources(reload_id);
    }
    UnlockRes();
    unlock_jcr_chain();
@@ -350,9 +347,8 @@ static int find_free_reload_table_entry()
  *    reread our configuration file. 
  *
  * The algorithm used is as follows: we count how many jobs are
- *   running since the last reload and set those jobs to make a
- *   callback. Also, we set each job with the current reload table
- *   id. . The old config is saved with the reload table
+ *   running and mark the running jobs to make a callback on 
+ *   exiting. The old config is saved with the reload table
  *   id in a reload table. The new config file is read. Now, as
  *   each job exits, it calls back to the reload_job_end_cb(), which
  *   decrements the count of open jobs for the given reload table.
@@ -371,7 +367,7 @@ void reload_config(int sig)
    static bool already_here = false;
    sigset_t set;       
    JCR *jcr;
-   int njobs = 0;
+   int njobs = 0;                    /* number of running jobs */
    int table, rtable;
 
    if (already_here) {
@@ -393,27 +389,13 @@ void reload_config(int sig)
       goto bail_out;
    }
 
-   /*
-    * Hook all active jobs that are not already hooked (i.e.
-    *  reload_id == 0
-    */
-   foreach_jcr(jcr) {
-      if (jcr->reload_id == 0 && jcr->JobType != JT_SYSTEM) {
-        reload_table[table].job_count++;
-        jcr->reload_id = table + 1;
-        job_end_push(jcr, reload_job_end_cb);
-        njobs++;
-      }
-      free_locked_jcr(jcr);
-   }
-   Dmsg1(000, "Reload_config njobs=%d\n", njobs);
+   Dmsg1(100, "Reload_config njobs=%d\n", njobs);
    reload_table[table].res_table = save_config_resources();
-   Dmsg1(000, "Saved old config in table %d\n", table);
+   Dmsg1(100, "Saved old config in table %d\n", table);
 
-   Dmsg0(000, "Calling parse config\n");
    parse_config(configfile);
 
-   Dmsg0(000, "Reloaded config file\n");
+   Dmsg0(100, "Reloaded config file\n");
    if (!check_resources()) {
       rtable = find_free_reload_table_entry();   /* save new, bad table */
       if (rtable < 0) {
@@ -430,15 +412,18 @@ void reload_config(int sig)
         res_head[i] = res_tab[i];
       }
       table = rtable;                /* release new, bad, saved table below */
-      if (njobs != 0) {
-        foreach_jcr(jcr) {
-           if (jcr->reload_id == table) {
-              jcr->reload_id = 0;
-           }
-           free_locked_jcr(jcr);
+   } else {
+      /*
+       * Hook all active jobs so that they release this table 
+       */
+      foreach_jcr(jcr) {
+        if (jcr->JobType != JT_SYSTEM) {
+           reload_table[table].job_count++;
+           job_end_push(jcr, reload_job_end_cb, (void *)table);
+           njobs++;
         }
+        free_locked_jcr(jcr);
       }
-      njobs = 0;                     /* force bad tabel to be released below */
    }
 
    /* Reset globals */
@@ -531,7 +516,7 @@ Without that I don't know who I am :-(\n"), configfile);
                       job->hdr.name, job_items[i].name, *def_svalue, i, offset);
                  svalue = (char **)((char *)job + offset);
                  if (*svalue) {
-                     Dmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
+                     Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
                  }
                  *svalue = bstrdup(*def_svalue);
                  set_bit(i, job->hdr.item_present);
@@ -541,7 +526,7 @@ Without that I don't know who I am :-(\n"), configfile);
                       job->hdr.name, job_items[i].name, i, offset);
                  svalue = (char **)((char *)job + offset);
                  if (*svalue) {
-                     Dmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
+                     Pmsg1(000, "Hey something is wrong. p=0x%lu\n", *svalue);
                  }
                  *svalue = *def_svalue;
                  set_bit(i, job->hdr.item_present);