]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/fd_plugins.c
Ensure that StorageId is updated after write
[bacula/bacula] / bacula / src / filed / fd_plugins.c
index 8f09df3744e634da46be97497006ef4c38b21a61..89895b6473f72a6a0ee3ee7081c85c826df342fb 100644 (file)
@@ -1,7 +1,7 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
+   Copyright (C) 2007-2012 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
@@ -159,7 +159,7 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value)
    bpContext *plugin_ctx;
    bEvent event;
    Plugin *plugin;
-   int i = 0;
+   int i;
    char *name = NULL;
    int len = 0;
    bool call_if_canceled = false;
@@ -198,7 +198,7 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value)
       call_if_canceled = true;
       break;
    case bEventStartRestoreJob:
-      foreach_alist(plugin, bplugin_list) {
+      foreach_alist_index(i, plugin, bplugin_list) {
          plugin->restoreFileStarted = false;
          plugin->createFileCalled = false;
       }
@@ -230,12 +230,11 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value)
     * Pass event to every plugin (except if name is set). If name
     *   is set, we pass it only to the plugin with that name.
     */
-   foreach_alist(plugin, bplugin_list) {
+   foreach_alist_index(i, plugin, bplugin_list) {
       if (name && !for_this_plug(plugin, name, len)) {
-         i++;
          continue;
       }
-      plugin_ctx = &plugin_ctx_list[i++];
+      plugin_ctx = &plugin_ctx_list[i];
       if (is_plugin_disabled(plugin_ctx)) {
          continue;
       }
@@ -251,7 +250,7 @@ bool plugin_check_file(JCR *jcr, char *fname)
 {
    Plugin *plugin;
    int rc = bRC_OK;
-   int i = 0;
+   int i;
 
    if (!bplugin_list || !jcr || !jcr->plugin_ctx_list || jcr->is_job_canceled()) {
       return false;                      /* Return if no plugins loaded */
@@ -262,8 +261,8 @@ bool plugin_check_file(JCR *jcr, char *fname)
    Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId);
 
    /* Pass event to every plugin */
-   foreach_alist(plugin, bplugin_list) {
-      jcr->plugin_ctx = &plugin_ctx_list[i++];
+   foreach_alist_index(i, plugin, bplugin_list) {
+      jcr->plugin_ctx = &plugin_ctx_list[i];
       jcr->plugin = plugin;
       if (is_plugin_disabled(jcr)) {
          continue;
@@ -320,6 +319,7 @@ static bool get_plugin_name(JCR *jcr, char *cmd, int *ret)
 
 static void update_ff_pkt(FF_PKT *ff_pkt, struct save_pkt *sp)
 {
+   ff_pkt->no_read = sp->no_read;
    ff_pkt->delta_seq = sp->delta_seq;
    if (sp->flags & FO_DELTA) {
       ff_pkt->flags |= FO_DELTA;
@@ -359,6 +359,7 @@ bRC plugin_option_handle_file(JCR *jcr, FF_PKT *ff_pkt, struct save_pkt *sp)
    sp->statp = ff_pkt->statp;
    sp->fname = ff_pkt->fname;
    sp->delta_seq = ff_pkt->delta_seq;
+   sp->accurate_found = ff_pkt->accurate_found;
 
    if (!bplugin_list || !jcr->plugin_ctx_list || jcr->is_job_canceled()) {
       Jmsg1(jcr, M_FATAL, 0, "Command plugin \"%s\" requested, but is not loaded.\n", cmd);
@@ -370,10 +371,9 @@ bRC plugin_option_handle_file(JCR *jcr, FF_PKT *ff_pkt, struct save_pkt *sp)
    }
 
    /* Note, we stop the loop on the first plugin that matches the name */
-   foreach_alist(plugin, bplugin_list) {
+   foreach_alist_index(i, plugin, bplugin_list) {
       Dmsg4(dbglvl, "plugin=%s plen=%d cmd=%s len=%d\n", plugin->file, plugin->file_len, cmd, len);
       if (!for_this_plug(plugin, cmd, len)) {
-         i++;
          continue;
       }
 
@@ -389,7 +389,7 @@ bRC plugin_option_handle_file(JCR *jcr, FF_PKT *ff_pkt, struct save_pkt *sp)
          jcr->opt_plugin = true;
          jcr->plugin = plugin;
          jcr->plugin_sp = sp;      /* Unset sp in save_file */
-         jcr->plugin_ctx = &plugin_ctx_list[i++];
+         jcr->plugin_ctx = &plugin_ctx_list[i];
 
          update_ff_pkt(ff_pkt, sp);
       }
@@ -418,7 +418,7 @@ bail_out:
 int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
 {
    Plugin *plugin;
-   int i = 0;
+   int i;
    int len;
    char *cmd = ff_pkt->top_fname;
    struct save_pkt sp;
@@ -440,10 +440,9 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
    }
 
    /* Note, we stop the loop on the first plugin that matches the name */
-   foreach_alist(plugin, bplugin_list) {
+   foreach_alist_index(i, plugin, bplugin_list) {
       Dmsg4(dbglvl, "plugin=%s plen=%d cmd=%s len=%d\n", plugin->file, plugin->file_len, cmd, len);
       if (!for_this_plug(plugin, cmd, len)) {
-         i++;
          continue;
       }
       /* 
@@ -556,8 +555,8 @@ bail_out:
 int plugin_estimate(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
 {
    Plugin *plugin;
-   int i = 0;
    int len;
+   int i;
    char *cmd = ff_pkt->top_fname;
    struct save_pkt sp;
    bEvent event;
@@ -579,10 +578,9 @@ int plugin_estimate(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
    }
 
    /* Note, we stop the loop on the first plugin that matches the name */
-   foreach_alist(plugin, bplugin_list) {
+   foreach_alist_index(i, plugin, bplugin_list) {
       Dmsg4(dbglvl, "plugin=%s plen=%d cmd=%s len=%d\n", plugin->file, plugin->file_len, cmd, len);
       if (!for_this_plug(plugin, cmd, len)) {
-         i++;
          continue;
       }
       /* 
@@ -730,7 +728,7 @@ bool plugin_name_stream(JCR *jcr, char *name)
    bool start;
    Plugin *plugin;
    int len;
-   int i = 0;
+   int i;
    bpContext *plugin_ctx_list = jcr->plugin_ctx_list;
 
    Dmsg1(dbglvl, "Read plugin stream string=%s\n", name);
@@ -775,11 +773,10 @@ bool plugin_name_stream(JCR *jcr, char *name)
    /*
     * Search for correct plugin as specified on the command 
     */
-   foreach_alist(plugin, bplugin_list) {
+   foreach_alist_index(i, plugin, bplugin_list) {
       bEvent event;
       Dmsg3(dbglvl, "plugin=%s cmd=%s len=%d\n", plugin->file, cmd, len);
       if (!for_this_plug(plugin, cmd, len)) {
-         i++;
          continue;
       }
       jcr->plugin_ctx = &plugin_ctx_list[i];
@@ -940,6 +937,7 @@ void dump_fd_plugin(Plugin *plugin, FILE *fp)
 void load_fd_plugins(const char *plugin_dir)
 {
    Plugin *plugin;
+   int i;
 
    if (!plugin_dir) {
       Dmsg0(dbglvl, "plugin dir is NULL\n");
@@ -969,7 +967,7 @@ void load_fd_plugins(const char *plugin_dir)
     * Verify that the plugin is acceptable, and print information
     *  about it.
     */
-   foreach_alist(plugin, bplugin_list) {
+   foreach_alist_index(i, plugin, bplugin_list) {
       Jmsg(NULL, M_INFO, 0, _("Loaded plugin: %s\n"), plugin->file);
       Dmsg1(dbglvl, "Loaded plugin: %s\n", plugin->file);
    }
@@ -1030,7 +1028,7 @@ static bool is_plugin_compatible(Plugin *plugin)
 void new_plugins(JCR *jcr)
 {
    Plugin *plugin;
-   int i = 0;
+   int i;
 
    if (!bplugin_list) {
       Dmsg0(dbglvl, "plugin list is NULL\n");
@@ -1051,14 +1049,14 @@ void new_plugins(JCR *jcr)
 
    bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list;
    Dmsg2(dbglvl, "Instantiate plugin_ctx=%p JobId=%d\n", plugin_ctx_list, jcr->JobId);
-   foreach_alist(plugin, bplugin_list) {
+   foreach_alist_index(i, plugin, bplugin_list) {
       /* Start a new instance of each plugin */
       bacula_ctx *b_ctx = (bacula_ctx *)malloc(sizeof(bacula_ctx));
       memset(b_ctx, 0, sizeof(bacula_ctx));
       b_ctx->jcr = jcr;
       plugin_ctx_list[i].bContext = (void *)b_ctx;   /* Bacula private context */
       plugin_ctx_list[i].pContext = NULL;
-      if (plug_func(plugin)->newPlugin(&plugin_ctx_list[i++]) != bRC_OK) {
+      if (plug_func(plugin)->newPlugin(&plugin_ctx_list[i]) != bRC_OK) {
          b_ctx->disabled = true;
       }
    }
@@ -1070,7 +1068,7 @@ void new_plugins(JCR *jcr)
 void free_plugins(JCR *jcr)
 {
    Plugin *plugin;
-   int i = 0;
+   int i;
 
    if (!bplugin_list || !jcr->plugin_ctx_list) {
       return;                         /* no plugins, nothing to do */
@@ -1078,10 +1076,10 @@ void free_plugins(JCR *jcr)
 
    bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list;
    Dmsg2(dbglvl, "Free instance plugin_ctx=%p JobId=%d\n", plugin_ctx_list, jcr->JobId);
-   foreach_alist(plugin, bplugin_list) {   
+   foreach_alist_index(i, plugin, bplugin_list) {   
       /* Free the plugin instance */
       plug_func(plugin)->freePlugin(&plugin_ctx_list[i]);
-      free(plugin_ctx_list[i++].bContext);     /* free Bacula private context */
+      free(plugin_ctx_list[i].bContext);     /* free Bacula private context */
    }
    free(plugin_ctx_list);
    jcr->plugin_ctx_list = NULL;
@@ -1300,6 +1298,10 @@ static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value)
       *((char **)value) = jcr->Job;
       Dmsg1(dbglvl, "Bacula: return Job name=%s\n", jcr->Job);
       break;
+   case bVarPrevJobName:
+      *((char **)value) = jcr->PrevJob;
+      Dmsg1(dbglvl, "Bacula: return Previous Job name=%s\n", jcr->PrevJob);
+      break;
    case bVarJobStatus:
       *((int *)value) = jcr->JobStatus;
       Dmsg1(dbglvl, "Bacula: return bVarJobStatus=%d\n", jcr->JobStatus);
@@ -1336,13 +1338,13 @@ static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value)
    case bVarRegexWhere:
       *(char **)value = jcr->RegexWhere;
       break;
-
    case bVarFDName:             /* get warning with g++ if we missed one */
    case bVarWorkingDir:
    case bVarExePath:
    case bVarVersion:
    case bVarDistName:
    case bVarBEEF:
+   case bVarPrefixLinks:
       break;
    }
    return bRC_OK;
@@ -1632,6 +1634,7 @@ static bRC baculaCheckChanges(bpContext *ctx, struct save_pkt *sp)
     * plugin 
     */
    sp->delta_seq = ff_pkt->delta_seq;
+   sp->accurate_found = ff_pkt->accurate_found;
 
 bail_out:
    Dmsg1(100, "checkChanges=%i\n", ret);