]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/filed/fd_plugins.c
Correct binfo size per James
[bacula/bacula] / bacula / src / filed / fd_plugins.c
index cec7f7ec941c04c405e3874256d1e47bf304bbe1..db73eae976d9776effa4fc351bad7131695f8522 100644 (file)
@@ -69,7 +69,7 @@ static boffset_t my_plugin_blseek(BFILE *bfd, boffset_t offset, int whence);
 
 /* Bacula info */
 static bInfo binfo = {
-   sizeof(bFuncs),
+   sizeof(bInfo),
    FD_PLUGIN_INTERFACE_VERSION 
 };
 
@@ -193,6 +193,7 @@ int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
          jcr->plugin_sp = &sp;
          ff_pkt = jcr->ff;
          ff_pkt->fname = sp.fname;
+         ff_pkt->link = sp.link;
          ff_pkt->type = sp.type;
          memcpy(&ff_pkt->statp, &sp.statp, sizeof(ff_pkt->statp));
          Dmsg1(dbglvl, "Save_file: file=%s\n", ff_pkt->fname);
@@ -226,7 +227,7 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start)
            sd->bstrerror());
      return false;
    }
-   Dmsg1(000, "send: %s\n", sd->msg);
+   Dmsg1(50, "send: %s\n", sd->msg);
 
    if (start) {
       /* Send data -- not much */
@@ -248,8 +249,11 @@ bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start)
 /*
  * Plugin name stream found during restore.  The record passed in
  *  argument name was generated in send_plugin_name() above.
+ *
+ * Returns: true  if start of stream
+ *          false if end of steam
  */
-void plugin_name_stream(JCR *jcr, char *name)    
+bool plugin_name_stream(JCR *jcr, char *name)    
 {
    char *p = name;
    char *cmd;
@@ -258,9 +262,6 @@ void plugin_name_stream(JCR *jcr, char *name)
    int len;
    int i = 0;
    bpContext *plugin_ctx_list = (bpContext *)jcr->plugin_ctx_list;
-   if (!plugin_ctx_list) {
-      goto bail_out;
-   }
 
    Dmsg1(dbglvl, "Read plugin stream string=%s\n", name);
    skip_nonspaces(&p);             /* skip over jcr->JobFiles */
@@ -287,6 +288,9 @@ void plugin_name_stream(JCR *jcr, char *name)
       jcr->plugin = NULL;
       goto bail_out;
    }
+   if (!plugin_ctx_list) {
+      goto bail_out;
+   }
       
    /*
     * After this point, we are dealing with a restore start
@@ -321,10 +325,11 @@ void plugin_name_stream(JCR *jcr, char *name)
       }
       jcr->plugin_ctx = &plugin_ctx_list[i];
       jcr->plugin = plugin;
+      plug_func(plugin)->startRestoreFile((bpContext *)jcr->plugin_ctx, cmd);
       goto bail_out;
    }
 bail_out:
-   return;
+   return start;
 }
 
 /*
@@ -341,7 +346,8 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
    Plugin *plugin = (Plugin *)jcr->plugin;
    struct restore_pkt rp;
-   mode_t mode;
+   int flags;
+   int rc;
 
    if (!set_cmd_plugin(bfd, jcr)) {
       return CF_ERROR;
@@ -363,22 +369,38 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
    rp.replace = jcr->replace;
    rp.create_status = CF_ERROR;
    Dmsg1(dbglvl, "call plugin createFile=%s\n", rp.ofname);
-   if (plug_func(plugin)->createFile(plugin_ctx, &rp) != bRC_OK) {
+   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"),
+            rc, attr->ofname);
+      return CF_ERROR;
+   }
+   if (rp.create_status == CF_ERROR) {
+      Qmsg1(jcr, M_ERROR, 0, _("Plugin createFile call failed. Returned CF_ERROR file=%s\n"),
+            attr->ofname);
       return CF_ERROR;
    }
-   if (rp.create_status == CF_ERROR || rp.create_status == CF_CREATED) {
-      return rp.create_status;
+   /* Created link or directory? */
+   if (rp.create_status == CF_CREATED) {
+      return rp.create_status;        /* yes, no need to bopen */
    }
-   mode =  O_WRONLY | O_CREAT | O_TRUNC | O_BINARY;
+
+   flags =  O_WRONLY | O_CREAT | O_TRUNC | O_BINARY;
    Dmsg0(dbglvl, "call bopen\n");
-   if ((bopen(bfd, attr->ofname, mode, S_IRUSR | S_IWUSR)) < 0) {
+   int stat = bopen(bfd, attr->ofname, flags, S_IRUSR | S_IWUSR);
+   Dmsg1(50, "bopen status=%d\n", stat);
+   if (stat < 0) {
       berrno be;
       be.set_errno(bfd->berrno);
       Qmsg2(jcr, M_ERROR, 0, _("Could not create %s: ERR=%s\n"),
             attr->ofname, be.bstrerror());
-      Dmsg2(dbglvl,"Could not create %s: ERR=%s\n", attr->ofname, be.bstrerror());
+      Dmsg2(dbglvl,"Could not bopen file %s: ERR=%s\n", attr->ofname, be.bstrerror());
       return CF_ERROR;
    }
+
+   if (!is_bopen(bfd)) {
+      Dmsg0(000, "===== BFD is not open!!!!\n");
+   }
    return CF_EXTRACT;
 }
 
@@ -390,6 +412,10 @@ int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
 bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
 {
    Dmsg0(dbglvl, "plugin_set_attributes\n");
+   if (is_bopen(ofd)) {
+      bclose(ofd);
+   }
+   pm_strcpy(attr->ofname, "*none*");
    return true;
 }
 
@@ -492,7 +518,7 @@ static int my_plugin_bopen(BFILE *bfd, const char *fname, int flags, mode_t mode
    Plugin *plugin = (Plugin *)jcr->plugin;
    bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
    struct io_pkt io;
-   Dmsg0(dbglvl, "plugin_bopen\n");
+   Dmsg1(dbglvl, "plugin_bopen flags=%x\n", flags);
    io.pkt_size = sizeof(io);
    io.pkt_end = sizeof(io);
    io.func = IO_OPEN;
@@ -511,6 +537,7 @@ static int my_plugin_bopen(BFILE *bfd, const char *fname, int flags, mode_t mode
       errno = io.io_errno;
       bfd->lerror = io.lerror;
    }
+   Dmsg1(50, "Return from plugin open status=%d\n", io.status);
    return io.status;
 }
 
@@ -520,7 +547,7 @@ static int my_plugin_bclose(BFILE *bfd)
    Plugin *plugin = (Plugin *)jcr->plugin;
    bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
    struct io_pkt io;
-   Dmsg0(dbglvl, "plugin_bclose\n");
+   Dmsg0(dbglvl, "===== plugin_bclose\n");
    io.pkt_size = sizeof(io);
    io.pkt_end = sizeof(io);
    io.func = IO_CLOSE;