]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/fd_plugins.c
Track unbalanced start/end plugin stream
[bacula/bacula] / bacula / src / filed / fd_plugins.c
index 6d3ef3c7f5b18f0fdee8ea3b96a252c88ef5909a..b54adc9810f2462321688276513029b89764345d 100644 (file)
@@ -176,11 +176,18 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value)
    case bEventEndVerifyJob:
       call_if_canceled = true;
       break;
+   case bEventStartRestoreJob:
+      if (jcr->plugin) {
+         jcr->plugin->restoreFileStarted = false;
+         jcr->plugin->createFileCalled = false;
+      }
+      break;
    case bEventEndRestoreJob:
       call_if_canceled = true;
       if (jcr->plugin && jcr->plugin->restoreFileStarted) {
          plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx);
          jcr->plugin->restoreFileStarted = false;
+         jcr->plugin->createFileCalled = false;
       }
       break;
    default:
@@ -196,7 +203,10 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value)
 
    Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId);
 
-   /* Pass event to every plugin (except if name is set) */
+   /*
+    * 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, plugin_list) {
       if (name && !for_this_plug(plugin, name, len)) {
          i++;
@@ -328,7 +338,7 @@ 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, plugin_list) {
-      Dmsg4(0, "plugin=%s plen=%d cmd=%s len=%d\n", plugin->file, plugin->file_len, cmd, len);
+      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;
@@ -405,6 +415,13 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
                ff_pkt->flags &= ~FO_DELTA;   /* clean delta sequence number */
                ff_pkt->delta_seq = 0;
             }
+            if (sp.flags & FO_OFFSETS) {
+               ff_pkt->flags |= FO_OFFSETS;
+            }
+            if (sp.flags & FO_PORTABLE_DATA) {
+               ff_pkt->flags |= FO_PORTABLE_DATA;
+            }
+            ff_pkt->flags |= FO_PLUGIN;       /* data from plugin */
          }
 
          memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp));
@@ -468,7 +485,7 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start)
       stat = sd->fsend("%ld 1 %d %s%c", index, sp->portable, sp->cmd, 0);
    } else {
       /* Send end of data */
-      stat = sd->fsend("0 0");
+      stat = sd->fsend("%ld 0", jcr->JobFiles);
    }
    if (!stat) {
       Jmsg1(jcr, M_FATAL, 0, _("Network send error to SD. ERR=%s\n"),
@@ -517,6 +534,7 @@ bool plugin_name_stream(JCR *jcr, char *name)
       if (jcr->plugin && jcr->plugin->restoreFileStarted) {
          plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx);
          jcr->plugin->restoreFileStarted = false;
+         jcr->plugin->createFileCalled = false;
       }
       jcr->plugin_ctx = NULL;
       jcr->plugin = NULL;
@@ -554,11 +572,12 @@ bool plugin_name_stream(JCR *jcr, char *name)
             &event, cmd) != bRC_OK) {
          goto bail_out;
       }
-      /* ***FIXME**** check error code */
-      if (plugin->restoreFileStarted) {
-         plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx);
+      if (plugin->restoreFileStarted)
+      {
+         Jmsg0(jcr, M_FATAL, 0, "Unbalanced call to startRestoreFile\n");
+         goto bail_out;
       }
-      plug_func(plugin)->startRestoreFile((bpContext *)jcr->plugin_ctx, cmd);
+      plug_func(plugin)->startRestoreFile(jcr->plugin_ctx, cmd);
       plugin->restoreFileStarted = true;
       goto bail_out;
    }
@@ -592,6 +611,7 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
 
    rp.pkt_size = sizeof(rp);
    rp.pkt_end = sizeof(rp);
+   rp.delta_seq = attr->delta_seq;
    rp.stream = attr->stream;
    rp.data_stream = attr->data_stream;
    rp.type = attr->type;
@@ -611,6 +631,11 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    if (rp.attrEx) {
       Dmsg1(dbglvl, "attrEx=\"%s\"\n", rp.attrEx);
    }
+   if (!plugin->restoreFileStarted || plugin->createFileCalled)
+   {
+      Jmsg0(jcr, M_FATAL, 0, "Unbalanced call to createFile\n");
+      return CF_ERROR;
+   }
    rc = plug_func(plugin)->createFile(plugin_ctx, &rp);
    if (rc != bRC_OK) {
       Qmsg2(jcr, M_ERROR, 0, _("Plugin createFile call failed. Stat=%d file=%s\n"),