]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/fd_plugins.c
Convert restore object to use STREAM_RESTORE_OBJECT; cleaner code
[bacula/bacula] / bacula / src / filed / fd_plugins.c
index 5407a146cc6f231eda590c996451f43bede3a030..4d7abba2633867a7e274bb1ff02ebd4ca074c8a0 100644 (file)
@@ -126,7 +126,7 @@ void generate_plugin_event(JCR *jcr, bEventType eventType, void *value)
    Plugin *plugin;
    int i = 0;
 
-   if (!plugin_list || !jcr || !jcr->plugin_ctx_list || job_canceled(jcr)) {
+   if (!plugin_list || !jcr || !jcr->plugin_ctx_list || jcr->is_job_canceled()) {
       return;                         /* Return if no plugins loaded */
    }
 
@@ -163,7 +163,7 @@ bool plugin_check_file(JCR *jcr, char *fname)
    int rc = bRC_OK;
    int i = 0;
 
-   if (!plugin_list || !jcr || !jcr->plugin_ctx_list || job_canceled(jcr)) {
+   if (!plugin_list || !jcr || !jcr->plugin_ctx_list || jcr->is_job_canceled()) {
       return false;                      /* Return if no plugins loaded */
    }
 
@@ -220,7 +220,7 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
    POOL_MEM fname(PM_FNAME);
    POOL_MEM link(PM_FNAME);
 
-   if (!plugin_list || !jcr->plugin_ctx_list || job_canceled(jcr)) {
+   if (!plugin_list || !jcr->plugin_ctx_list || jcr->is_job_canceled()) {
       Jmsg1(jcr, M_FATAL, 0, "Command plugin \"%s\" not loaded.\n", cmd);
       return 1;                            /* Return if no plugins loaded */
    }
@@ -264,7 +264,7 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
          goto bail_out;
       }
       /* Loop getting filenames to backup then saving them */
-      while (!job_canceled(jcr)) { 
+      while (!jcr->is_job_canceled()) { 
          memset(&sp, 0, sizeof(sp));
          sp.pkt_size = sizeof(sp);
          sp.pkt_end = sizeof(sp);
@@ -272,12 +272,12 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
          sp.cmd = cmd;
          Dmsg3(dbglvl, "startBackup st_size=%p st_blocks=%p sp=%p\n", &sp.statp.st_size, &sp.statp.st_blocks,
                 &sp);
-         /* Get the file save parameters */
+         /* Get the file save parameters. I.e. the stat pkt ... */
          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,13 +287,37 @@ 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;
+         if (sp.type == FT_RESTORE_FIRST) {
+            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();
+         }
+
          memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp));
-         Dmsg1(dbglvl, "Save_file: file=%s\n", fname.c_str());
+         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) {
@@ -328,7 +352,7 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start)
       Jmsg0(jcr, M_FATAL, 0, _("Plugin save packet not found.\n"));
       return false;
    }
-   if (job_canceled(jcr)) {
+   if (jcr->is_job_canceled()) {
       return false;
    }
   
@@ -342,7 +366,7 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start)
            sd->bstrerror());
      return false;
    }
-   Dmsg1(50, "send: %s\n", sd->msg);
+   Dmsg1(50, "send plugin name hdr: %s\n", sd->msg);
 
    if (start) {
       /* Send data -- not much */
@@ -356,7 +380,7 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start)
             sd->bstrerror());
          return false;
    }
-   Dmsg1(dbglvl, "send: %s\n", sd->msg);
+   Dmsg1(dbglvl, "send plugin start/end: %s\n", sd->msg);
    sd->signal(BNET_EOD);            /* indicate end of plugin name data */
    return true;
 }
@@ -470,9 +494,10 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    int flags;
    int rc;
 
-   if (!plugin || !plugin_ctx || !set_cmd_plugin(bfd, jcr) || job_canceled(jcr)) {
+   if (!plugin || !plugin_ctx || !set_cmd_plugin(bfd, jcr) || jcr->is_job_canceled()) {
       return CF_ERROR;
    }
+
    rp.pkt_size = sizeof(rp);
    rp.pkt_end = sizeof(rp);
    rp.stream = attr->stream;
@@ -489,7 +514,11 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    rp.RegexWhere = jcr->RegexWhere;
    rp.replace = jcr->replace;
    rp.create_status = CF_ERROR;
-   Dmsg1(dbglvl, "call plugin createFile=%s\n", rp.ofname);
+   Dmsg4(dbglvl, "call plugin createFile stream=%d type=%d LinkFI=%d File=%s\n", 
+         rp.stream, rp.type, rp.LinkFI, rp.ofname);
+   if (rp.attrEx) {
+      Dmsg1(dbglvl, "attrEx=\"%s\"\n", rp.attrEx);
+   }
    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"),
@@ -656,7 +685,7 @@ void new_plugins(JCR *jcr)
       Dmsg0(dbglvl, "plugin list is NULL\n");
       return;
    }
-   if (job_canceled(jcr)) {
+   if (jcr->is_job_canceled() || jcr->JobId == 0) {
       return;
    }
 
@@ -915,6 +944,14 @@ static bRC baculaGetValue(bpContext *ctx, bVariable var, void *value)
          *(void **)value = g_pVSSClient->GetVssObject();
          break;
        }
+#endif
+       return bRC_Error;
+   case bVarVssDllHandle:
+#ifdef HAVE_WIN32
+      if (g_pVSSClient) {
+         *(void **)value = g_pVSSClient->GetVssDllHandle();
+         break;
+       }
 #endif
        return bRC_Error;
    }
@@ -1022,7 +1059,7 @@ static bRC baculaAddExclude(bpContext *ctx, const char *file)
 {
    JCR *jcr;
    bacula_ctx *bctx;
-   if (ctx) {
+   if (!ctx) {
       return bRC_Error;
    }
    if (!file) {