]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/fd_plugins.c
Pass Delta Sequence to save_pkt and restore_pkt
[bacula/bacula] / bacula / src / filed / fd_plugins.c
index ec18c2ca608b4d3f81563cbc9e7dad3dd0bb5479..804019e9f21f6a251814211fe9fdef9cd3adf060 100644 (file)
@@ -6,7 +6,7 @@
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation, which is 
    listed in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -34,6 +34,9 @@
 #include "bacula.h"
 #include "filed.h"
 
+extern CLIENT *me;
+extern DLL_IMP_EXP char *exepath;
+
 const int dbglvl = 150;
 #ifdef HAVE_WIN32
 const char *plugin_type = "-fd.dll";
@@ -42,6 +45,7 @@ const char *plugin_type = "-fd.so";
 #endif
 
 extern int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level);
+extern bool check_changes(JCR *jcr, FF_PKT *ff_pkt);
 
 /* Function pointers to be set here */
 extern DLL_IMP_EXP int     (*plugin_bopen)(BFILE *bfd, const char *fname, int flags, mode_t mode);
@@ -63,7 +67,15 @@ static void *baculaMalloc(bpContext *ctx, const char *file, int line,
               size_t size);
 static void baculaFree(bpContext *ctx, const char *file, int line, void *mem);
 static bRC  baculaAddExclude(bpContext *ctx, const char *file);
+static bRC baculaAddInclude(bpContext *ctx, const char *file);
+static bRC baculaAddOptions(bpContext *ctx, const char *opts);
+static bRC baculaAddRegex(bpContext *ctx, const char *item, int type);
+static bRC baculaAddWild(bpContext *ctx, const char *item, int type);
+static bRC baculaNewOptions(bpContext *ctx);
+static bRC baculaNewInclude(bpContext *ctx);
 static bool is_plugin_compatible(Plugin *plugin);
+static bool get_plugin_name(JCR *jcr, char *cmd, int *ret);
+static bRC baculaCheckChanges(bpContext *ctx, struct save_pkt *sp);
 
 /*
  * These will be plugged into the global pointer structure for
@@ -93,7 +105,14 @@ static bFuncs bfuncs = {
    baculaDebugMsg,
    baculaMalloc,
    baculaFree,
-   baculaAddExclude
+   baculaAddExclude,
+   baculaAddInclude,
+   baculaAddOptions,
+   baculaAddRegex,
+   baculaAddWild,
+   baculaNewOptions,
+   baculaNewInclude,
+   baculaCheckChanges
 };
 
 /* 
@@ -103,54 +122,94 @@ struct bacula_ctx {
    JCR *jcr;                             /* jcr for plugin */
    bRC  rc;                              /* last return code */
    bool disabled;                        /* set if plugin disabled */
-   findFILESET *fileset;                 /* pointer to exclude files */
+   findINCEXE *exclude;                  /* pointer to exclude files */
+   findINCEXE *include;                  /* pointer to include/exclude files */
 };
 
-static bool is_plugin_disabled(JCR *jcr)
+static bool is_plugin_disabled(bpContext *plugin_ctx)
 {
    bacula_ctx *b_ctx;
-   if (!jcr->plugin_ctx) {
+   if (!plugin_ctx) {
       return true;
    }
-   b_ctx = (bacula_ctx *)jcr->plugin_ctx->bContext;
+   b_ctx = (bacula_ctx *)plugin_ctx->bContext;
    return b_ctx->disabled;
 }
 
+static bool is_plugin_disabled(JCR *jcr)
+{
+   return is_plugin_disabled(jcr->plugin_ctx);
+}
 
 /**
  * Create a plugin event 
+ * When receiving bEventCancelCommand, this function is called by an other thread. 
  */
 void generate_plugin_event(JCR *jcr, bEventType eventType, void *value)     
 {
+   bpContext *plugin_ctx;
    bEvent event;
    Plugin *plugin;
    int i = 0;
+   char *name = NULL;
+   int len = 0;
+   bool call_if_canceled = false;
+   bRC rc;
 
-   if (!plugin_list || !jcr || !jcr->plugin_ctx_list || jcr->is_job_canceled()) {
+   if (!plugin_list || !jcr || !jcr->plugin_ctx_list) {
       return;                         /* Return if no plugins loaded */
    }
+   
+   /*
+    * Some events are sent to only a particular plugin or must be
+    *  called even if the job is canceled
+    */
+   switch(eventType) {
+   case bEventPluginCommand:
+      name = (char *)value;
+      if (!get_plugin_name(jcr, name, &len)) {
+         return;
+      }
+      break;
+   case bEventEndBackupJob:
+   case bEventEndVerifyJob:
+      call_if_canceled = true;
+      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;
+      }
+      break;
+   default:
+      break;
+   }
+
+   if (!call_if_canceled && jcr->is_job_canceled()) {
+      return;
+   }
 
    bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list;
    event.eventType = eventType;
 
    Dmsg2(dbglvl, "plugin_ctx=%p JobId=%d\n", jcr->plugin_ctx_list, jcr->JobId);
 
-   /* Pass event to every plugin */
+   /* Pass event to every plugin (except if name is set) */
    foreach_alist(plugin, plugin_list) {
-      bRC rc;
-      jcr->plugin_ctx = &plugin_ctx_list[i++];
-      jcr->plugin = plugin;
-      if (is_plugin_disabled(jcr)) {
+      if (name && strncmp(plugin->file, name, len) != 0) {
+         i++;
+         continue;
+      }
+      plugin_ctx = &plugin_ctx_list[i++];
+      if (is_plugin_disabled(plugin_ctx)) {
          continue;
       }
-      rc = plug_func(plugin)->handlePluginEvent(jcr->plugin_ctx, &event, value);
+      rc = plug_func(plugin)->handlePluginEvent(plugin_ctx, &event, value);
       if (rc != bRC_OK) {
          break;
       }
    }
-
-   jcr->plugin = NULL;
-   jcr->plugin_ctx = NULL;
    return;
 }
 
@@ -192,6 +251,40 @@ bool plugin_check_file(JCR *jcr, char *fname)
    return rc == bRC_Seen;
 }
 
+/* Get the first part of the the plugin command
+ *  systemstate:/@SYSTEMSTATE/ 
+ * => ret = 11
+ * => can use strncmp(plugin_name, cmd, ret);
+ *
+ * The plugin command can contain only the plugin name
+ *  Plugin = alldrives
+ * => ret = 9
+ */
+static bool get_plugin_name(JCR *jcr, char *cmd, int *ret)
+{
+   char *p;
+   int len;
+   if (!cmd || (*cmd == '\0')) {
+      return false;
+   }
+   /* Handle plugin command here backup */
+   Dmsg1(dbglvl, "plugin cmd=%s\n", cmd);
+   if ((p = strchr(cmd, ':')) == NULL) {
+      if (strchr(cmd, ' ') == NULL) { /* we have just the plugin name */
+         len = strlen(cmd);
+      } else {
+         Jmsg1(jcr, M_ERROR, 0, "Malformed plugin command: %s\n", cmd);
+         return false;
+      }
+   } else {                     /* plugin:argument */
+      len = p - cmd;
+      if (len <= 0) {
+         return false;
+      }
+   }
+   *ret = len;
+   return true;
+}
 
 /**  
  * Sequence of calls for a backup:
@@ -213,7 +306,6 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
    Plugin *plugin;
    int i = 0;
    int len;
-   char *p;
    char *cmd = ff_pkt->top_fname;
    struct save_pkt sp;
    bEvent event;
@@ -221,7 +313,7 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
    POOL_MEM link(PM_FNAME);
 
    if (!plugin_list || !jcr->plugin_ctx_list || jcr->is_job_canceled()) {
-      Jmsg1(jcr, M_FATAL, 0, "Command plugin \"%s\" not loaded.\n", cmd);
+      Jmsg1(jcr, M_FATAL, 0, "Command plugin \"%s\" requested, but is not loaded.\n", cmd);
       return 1;                            /* Return if no plugins loaded */
    }
 
@@ -229,14 +321,7 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
    bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list;
    event.eventType = bEventBackupCommand;
 
-   /* Handle plugin command here backup */
-   Dmsg1(dbglvl, "plugin cmd=%s\n", cmd);
-   if (!(p = strchr(cmd, ':'))) {
-      Jmsg1(jcr, M_ERROR, 0, "Malformed plugin command: %s\n", cmd);
-      goto bail_out;
-   }
-   len = p - cmd;
-   if (len <= 0) {
+   if (!get_plugin_name(jcr, cmd, &len)) {
       goto bail_out;
    }
 
@@ -269,6 +354,7 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
          sp.pkt_size = sizeof(sp);
          sp.pkt_end = sizeof(sp);
          sp.portable = true;
+         sp.flags = 0;
          sp.cmd = cmd;
          Dmsg3(dbglvl, "startBackup st_size=%p st_blocks=%p sp=%p\n", &sp.statp.st_size, &sp.statp.st_blocks,
                 &sp);
@@ -276,8 +362,8 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
          if (plug_func(plugin)->startBackupFile(jcr->plugin_ctx, &sp) != bRC_OK) {
             goto bail_out;
          }
-         if (sp.type == 0 || sp.fname == NULL) {
-            Jmsg1(jcr, M_FATAL, 0, _("Command plugin \"%s\" returned bad startBackupFile packet.\n"),
+         if (sp.type == 0) {
+            Jmsg1(jcr, M_FATAL, 0, _("Command plugin \"%s\": no type in startBackupFile packet.\n"),
                cmd);
             goto bail_out;
          }
@@ -287,21 +373,45 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
           * Copy fname and link because save_file() zaps them.  This 
           *  avoids zaping the plugin's strings.
           */
-         pm_strcpy(fname, sp.fname);
-         pm_strcpy(link, sp.link);
-         ff_pkt->fname = fname.c_str();
-         ff_pkt->link = link.c_str();
          ff_pkt->type = sp.type;
-         ff_pkt->object = sp.object;
-         ff_pkt->object_len = sp.object_len;
          if (sp.type == FT_RESTORE_FIRST) {
-            ff_pkt->LinkFI = sp.index;     /* restore object index */
+            if (!sp.object_name) {
+               Jmsg1(jcr, M_FATAL, 0, _("Command plugin \"%s\": no object_name in startBackupFile packet.\n"),
+                  cmd);
+               goto bail_out;
+            }
+            ff_pkt->fname = cmd;                 /* full plugin string */
+            ff_pkt->object_name = sp.object_name;
+            ff_pkt->object_index = sp.index;     /* restore object index */
+            ff_pkt->object_compression = 0;      /* no compression for now */
+            ff_pkt->object = sp.object;
+            ff_pkt->object_len = sp.object_len;
+         } else {
+            if (!sp.fname) {
+               Jmsg1(jcr, M_FATAL, 0, _("Command plugin \"%s\": no fname in startBackupFile packet.\n"),
+                  cmd);
+               goto bail_out;
+            }
+            pm_strcpy(fname, sp.fname);
+            pm_strcpy(link, sp.link);
+            ff_pkt->fname = fname.c_str();
+            ff_pkt->link = link.c_str();
+            ff_pkt->delta_seq = sp.delta_seq;
+            if (sp.flags & FO_DELTA) {
+               ff_pkt->flags |= FO_DELTA;
+               ff_pkt->delta_seq++;          /* make new delta sequence number */
+            } else {
+               ff_pkt->flags &= ~FO_DELTA;   /* clean delta sequence number */
+               ff_pkt->delta_seq = 0;
+            }
          }
+
          memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp));
          Dmsg2(dbglvl, "startBackup returned type=%d, fname=%s\n", sp.type, sp.fname);
          if (sp.object) {
             Dmsg2(dbglvl, "index=%d object=%s\n", sp.index, sp.object);
          }   
+         /* Call Bacula core code to backup the plugin's file */
          save_file(jcr, ff_pkt, true);
          bRC rc = plug_func(plugin)->endBackupFile(jcr->plugin_ctx);
          if (rc == bRC_More || rc == bRC_OK) {
@@ -311,9 +421,9 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
             continue;
          }
          goto bail_out;
-      }
+      } /* end while loop */
       goto bail_out;
-   }
+   } /* end loop over all plugins */
    Jmsg1(jcr, M_FATAL, 0, "Command plugin \"%s\" not found.\n", cmd);
 
 bail_out:
@@ -403,8 +513,9 @@ bool plugin_name_stream(JCR *jcr, char *name)
        * End of plugin data, notify plugin, then clear flags   
        */
       Dmsg2(dbglvl, "End plugin data plugin=%p ctx=%p\n", jcr->plugin, jcr->plugin_ctx);
-      if (jcr->plugin) {
+      if (jcr->plugin && jcr->plugin->restoreFileStarted) {
          plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx);
+         jcr->plugin->restoreFileStarted = false;
       }
       jcr->plugin_ctx = NULL;
       jcr->plugin = NULL;
@@ -417,15 +528,7 @@ bool plugin_name_stream(JCR *jcr, char *name)
    /*
     * After this point, we are dealing with a restore start
     */
-
-// Dmsg1(dbglvl, "plugin restore cmd=%s\n", cmd);
-   if (!(p = strchr(cmd, ':'))) {
-      Jmsg1(jcr, M_ERROR, 0,
-           _("Malformed plugin command. Name not terminated by colon: %s\n"), cmd);
-      goto bail_out;
-   }
-   len = p - cmd;
-   if (len <= 0) {
+   if (!get_plugin_name(jcr, cmd, &len)) {
       goto bail_out;
    }
 
@@ -451,7 +554,11 @@ bool plugin_name_stream(JCR *jcr, char *name)
          goto bail_out;
       }
       /* ***FIXME**** check error code */
+      if (plugin->restoreFileStarted) {
+         plug_func(jcr->plugin)->endRestoreFile(jcr->plugin_ctx);
+      }
       plug_func(plugin)->startRestoreFile((bpContext *)jcr->plugin_ctx, cmd);
+      plugin->restoreFileStarted = true;
       goto bail_out;
    }
    Jmsg1(jcr, M_WARNING, 0, _("Plugin=%s not found.\n"), cmd);
@@ -509,6 +616,9 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
             rc, attr->ofname);
       return CF_ERROR;
    }
+   if (rp.create_status == CF_SKIP) {
+      return CF_SKIP;
+   }
    if (rp.create_status == CF_ERROR) {
       Qmsg1(jcr, M_ERROR, 0, _("Plugin createFile call failed. Returned CF_ERROR file=%s\n"),
             attr->ofname);
@@ -642,8 +752,8 @@ static bool is_plugin_compatible(Plugin *plugin)
            plugin->file, FD_PLUGIN_INTERFACE_VERSION, info->version);
       return false;
    }
-   if (strcmp(info->plugin_license, "Bacula GPLv2") != 0 &&
-       strcmp(info->plugin_license, "GPLv2") != 0) {
+   if (strcmp(info->plugin_license, "Bacula AGPLv3") != 0 &&
+       strcmp(info->plugin_license, "AGPLv3") != 0) {
       Jmsg(NULL, M_ERROR, 0, _("Plugin license incompatible. Plugin=%s license=%s\n"),
            plugin->file, info->plugin_license);
       Dmsg2(50, "Plugin license incompatible. Plugin=%s license=%s\n",
@@ -874,24 +984,38 @@ static boffset_t my_plugin_blseek(BFILE *bfd, boffset_t offset, int whence)
 static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value)
 {
    JCR *jcr;
-   if (!value || !ctx) {
+   if (!value) {
       return bRC_Error;
    }
-// Dmsg1(dbglvl, "bacula: baculaGetValue var=%d\n", var);
+
+   switch (var) {               /* General variables, no need of ctx */
+   case bVarFDName:
+      *((char **)value) = my_name;
+      break;
+   case bVarWorkingDir:
+      *(void **)value = me->working_directory;
+      break;
+   case bVarExePath:
+      *(char **)value = exepath;
+      break;
+   default:
+      break;
+   }
+
+   if (!ctx) {                  /* Other variables need context */
+      return bRC_Error;
+   }
+
    jcr = ((bacula_ctx *)ctx->bContext)->jcr;
    if (!jcr) {
       return bRC_Error;
    }
-// Dmsg1(dbglvl, "Bacula: jcr=%p\n", jcr); 
+
    switch (var) {
    case bVarJobId:
       *((int *)value) = jcr->JobId;
       Dmsg1(dbglvl, "Bacula: return bVarJobId=%d\n", jcr->JobId);
       break;
-   case bVarFDName:
-      *((char **)value) = my_name;
-      Dmsg1(dbglvl, "Bacula: return my_name=%s\n", my_name);
-      break;
    case bVarLevel:
       *((int *)value) = jcr->getJobLevel();
       Dmsg1(dbglvl, "Bacula: return bVarJobLevel=%d\n", jcr->getJobLevel());
@@ -938,6 +1062,17 @@ static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value)
        }
 #endif
        return bRC_Error;
+   case bVarWhere:
+      *(char **)value = jcr->where;
+      break;
+   case bVarRegexWhere:
+      *(char **)value = jcr->RegexWhere;
+      break;
+
+   case bVarFDName:             /* get warning with g++ if we missed one */
+   case bVarWorkingDir:
+   case bVarExePath:
+      break;
    }
    return bRC_OK;
 }
@@ -1035,6 +1170,22 @@ static void baculaFree(bpContext *ctx, const char *file, int line, void *mem)
 #endif
 }
 
+static bool is_ctx_good(bpContext *ctx, JCR *&jcr, bacula_ctx *&bctx)
+{
+   if (!ctx) {
+      return false;
+   }
+   bctx = (bacula_ctx *)ctx->bContext;
+   if (!bctx) {
+      return false;
+   }
+   jcr = bctx->jcr;
+   if (!jcr) {
+      return false;
+   }
+   return true;
+}
+
 /**
  * Let the plugin define files/directories to be excluded
  *  from the main backup.
@@ -1043,28 +1194,163 @@ static bRC baculaAddExclude(bpContext *ctx, const char *file)
 {
    JCR *jcr;
    bacula_ctx *bctx;
-   if (!ctx) {
+   if (!is_ctx_good(ctx, jcr, bctx)) {
       return bRC_Error;
    }
    if (!file) {
       return bRC_Error;
    }
-   bctx = (bacula_ctx *)ctx->bContext;
-   if (!bctx) {
+   if (!bctx->exclude) {  
+      bctx->exclude = new_exclude(jcr);
+      new_options(jcr, bctx->exclude);
+   }
+   set_incexe(jcr, bctx->exclude);
+   add_file_to_fileset(jcr, file, true);
+   Dmsg1(100, "Add exclude file=%s\n", file);
+   return bRC_OK;
+}
+
+/**
+ * Let the plugin define files/directories to be excluded
+ *  from the main backup.
+ */
+static bRC baculaAddInclude(bpContext *ctx, const char *file)
+{
+   JCR *jcr;
+   bacula_ctx *bctx;
+   if (!is_ctx_good(ctx, jcr, bctx)) {
       return bRC_Error;
    }
-   jcr = bctx->jcr;
-   if (!jcr) {
+   if (!file) {
+      return bRC_Error;
+   }
+   if (!bctx->include) {  
+      bctx->include = new_preinclude(jcr);
+      new_options(jcr, bctx->include);
+   }
+   set_incexe(jcr, bctx->include);
+   add_file_to_fileset(jcr, file, true);
+   Dmsg1(100, "Add include file=%s\n", file);
+   return bRC_OK;
+}
+
+static bRC baculaAddOptions(bpContext *ctx, const char *opts)
+{
+   JCR *jcr;
+   bacula_ctx *bctx;
+   if (!is_ctx_good(ctx, jcr, bctx)) {
+      return bRC_Error;
+   }
+   if (!opts) {
+      return bRC_Error;
+   }
+   add_options_to_fileset(jcr, opts);
+   Dmsg1(1000, "Add options=%s\n", opts);
+   return bRC_OK;
+}
+
+static bRC baculaAddRegex(bpContext *ctx, const char *item, int type)
+{
+   JCR *jcr;
+   bacula_ctx *bctx;
+   if (!is_ctx_good(ctx, jcr, bctx)) {
+      return bRC_Error;
+   }
+   if (!item) {
+      return bRC_Error;
+   }
+   add_regex_to_fileset(jcr, item, type);
+   Dmsg1(100, "Add regex=%s\n", item);
+   return bRC_OK;
+}
+
+static bRC baculaAddWild(bpContext *ctx, const char *item, int type)
+{
+   JCR *jcr;
+   bacula_ctx *bctx;
+   if (!is_ctx_good(ctx, jcr, bctx)) {
+      return bRC_Error;
+   }
+   if (!item) {
+      return bRC_Error;
+   }
+   add_wild_to_fileset(jcr, item, type);
+   Dmsg1(100, "Add wild=%s\n", item);
+   return bRC_OK;
+}
+
+static bRC baculaNewOptions(bpContext *ctx)
+{
+   JCR *jcr;
+   bacula_ctx *bctx;
+   if (!is_ctx_good(ctx, jcr, bctx)) {
       return bRC_Error;
    }
-   if (!bctx->fileset) {  
-      bctx->fileset = new_exclude(jcr);
+   (void)new_options(jcr, NULL);
+   return bRC_OK;
+}
+
+static bRC baculaNewInclude(bpContext *ctx)
+{
+   JCR *jcr;
+   bacula_ctx *bctx;
+   if (!is_ctx_good(ctx, jcr, bctx)) {
+      return bRC_Error;
    }
-   add_file_to_fileset(jcr, file, bctx->fileset, true);
+   (void)new_include(jcr);
    return bRC_OK;
 }
 
 
+/* 
+ * Check if a file have to be backuped using Accurate code
+ */
+static bRC baculaCheckChanges(bpContext *ctx, struct save_pkt *sp)
+{
+   JCR *jcr;
+   bacula_ctx *bctx;
+   FF_PKT *ff_pkt;
+   bRC ret = bRC_Error;
+
+   if (!is_ctx_good(ctx, jcr, bctx)) {
+      goto bail_out;
+   }
+   if (!sp) {
+      goto bail_out;
+   }
+   
+   ff_pkt = jcr->ff;
+   /*
+    * Copy fname and link because save_file() zaps them.  This 
+    *  avoids zaping the plugin's strings.
+    */
+   ff_pkt->type = sp->type;
+   if (!sp->fname) {
+      Jmsg0(jcr, M_FATAL, 0, _("Command plugin: no fname in baculaCheckChanges packet.\n"));
+      goto bail_out;
+   }
+
+   ff_pkt->fname = sp->fname;
+   ff_pkt->link = sp->link;
+   memcpy(&ff_pkt->statp, &sp->statp, sizeof(ff_pkt->statp));
+
+   if (check_changes(jcr, ff_pkt))  {
+      ret = bRC_OK;
+   } else {
+      ret = bRC_Seen;
+   }
+
+   /* check_changes() can update delta sequence number, return it to the
+    * plugin 
+    */
+   sp->delta_seq = ff_pkt->delta_seq;
+
+bail_out:
+   Dmsg1(100, "checkChanges=%i\n", ret);
+   return ret;
+}
+
+
 #ifdef TEST_PROGRAM
 
 int     (*plugin_bopen)(JCR *jcr, const char *fname, int flags, mode_t mode) = NULL;
@@ -1112,7 +1398,7 @@ int main(int argc, char *argv[])
 
    Dmsg0(dbglvl, "bacula: OK ...\n");
    close_memory_pool();
-   sm_dump(false);
+   sm_dump(false);     /* unit test */
    return 0;
 }