]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/append.c
Important protocol change -- see kes29Oct02
[bacula/bacula] / bacula / src / stored / append.c
index a9152b9380c4bf1105b22da46ef483416f698ee9..635477d5b8fcd9b48183c90020da929d31a9cb6e 100644 (file)
@@ -27,9 +27,6 @@
 #include "bacula.h"
 #include "stored.h"
 
-extern int  FiledDataChan;           /* File daemon data channel (port) */
-extern int BaculaTapeVersion;        /* Version number */
-extern char BaculaId[];              /* Id string */
 
 /* Responses sent to the File daemon */
 static char OK_data[]    = "3000 OK data\n";
@@ -101,7 +98,21 @@ int do_append_data(JCR *jcr)
    memset(&rec, 0, sizeof(rec));
 
    /* 
-    * Get Data from File daemon, write to device   
+    * Get Data from File daemon, write to device.  To clarify what is
+    *  going on here.  We expect:        
+    *    - A stream header
+    *    - Multiple records of data
+    *    - EOD record
+    *
+    *   The Stream header is just used to sychronize things, and
+    *   none of the stream header is written to tape.
+    *   The Multiple records of data, contain first the Attributes,
+    *   then after another stream header, the file data, then
+    *   after another stream header, the MD5 data if any.  
+    *
+    *  So we get the (stream header, data, EOD) three time for each
+    *  file. 1. for the Attributes, 2. for the file data if any, 
+    *  and 3. for the MD5 if any.
     */
    jcr->VolFirstFile = 0;
    time(&jcr->run_time);             /* start counting time for rates */
@@ -113,16 +124,17 @@ int do_append_data(JCR *jcr)
        *    file_index (sequential Bacula file index)
        *    stream     (arbitrary Bacula number to distinguish parts of data)
        *    info       (Info for Storage daemon -- compressed, encryped, ...)
+       *       info is not currently used, so is read, but ignored!
        */
-      if ((n=bget_msg(ds)) < 0) { 
+     if ((n=bget_msg(ds)) <= 0) {
+        if (n == BNET_SIGNAL && ds->msglen == BNET_EOD) {
+           break;                    /* end of data */
+        }
          Jmsg1(jcr, M_FATAL, 0, _("Error reading data header from FD. ERR=%s\n"),
            bnet_strerror(ds));
         ok = FALSE;
         break;
       }
-      if (n == 0 || job_cancelled(jcr)) {
-        break;                       /* all done */
-      }
       sm_check(__FILE__, __LINE__, False);
       ds->msg[ds->msglen] = 0;
       if (sscanf(ds->msg, "%ld %ld %100s", &file_index, &stream, info) != 3) {
@@ -161,7 +173,7 @@ int do_append_data(JCR *jcr)
         rec.data = ds->msg;            /* use message buffer */
 
          Dmsg4(250, "before writ_rec FI=%d SessId=%d Strm=%s len=%d\n",
-           rec.FileIndex, rec.VolSessionId, stream_to_ascii(rec.Stream), 
+           rec.FileIndex, rec.VolSessionId, stream_to_ascii(rec.Stream,rec.FileIndex), 
            rec.data_len);
          
         while (!write_record_to_block(block, &rec)) {
@@ -182,15 +194,18 @@ int do_append_data(JCR *jcr)
            break;
         }
         jcr->JobBytes += rec.data_len;   /* increment bytes this job */
-         Dmsg4(190, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
+         Dmsg4(200, "write_record FI=%s SessId=%d Strm=%s len=%d\n",
            FI_to_ascii(rec.FileIndex), rec.VolSessionId, 
-           stream_to_ascii(rec.Stream), rec.data_len);
+           stream_to_ascii(rec.Stream, rec.FileIndex), rec.data_len);
+
         /* Send attributes and MD5 to Director for Catalog */
-        if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_MD5_SIGNATURE) {
+        if (stream == STREAM_UNIX_ATTRIBUTES || stream == STREAM_MD5_SIGNATURE ||
+            stream == STREAM_WIN32_ATTRIBUTES) { 
            if (!jcr->no_attributes) {
               if (jcr->spool_attributes && jcr->dir_bsock->spool_fd) {
                  jcr->dir_bsock->spool = 1;
               }
+               Dmsg0(200, "Send attributes.\n");
               if (!dir_update_file_attributes(jcr, &rec)) {
                   Jmsg(jcr, M_FATAL, 0, _("Error updating file attributes. ERR=%s\n"),
                     bnet_strerror(jcr->dir_bsock));
@@ -203,7 +218,7 @@ int do_append_data(JCR *jcr)
         }
         sm_check(__FILE__, __LINE__, False);
       }
-      if (n < 0) {
+      if (is_bnet_error(ds)) {
          Jmsg1(jcr, M_FATAL, 0, _("Network error on data channel. ERR=%s\n"),
            bnet_strerror(ds));
         ok = FALSE;
@@ -211,14 +226,17 @@ int do_append_data(JCR *jcr)
       }
    }
    /* 
-    *******FIXME***** we should put the ok status in the End of
-    * session label 
-    *
     *   We probably need a new flag that says "Do not attempt
     *   to write because there is no tape".
     */
    sm_check(__FILE__, __LINE__, False);
    Dmsg0(90, "Write_end_session_label()\n");
+   /* Create Job status for end of session label */
+   if (!job_cancelled(jcr) && ok) {
+      jcr->JobStatus = JS_Terminated;
+   } else if (!ok) {
+      jcr->JobStatus = JS_ErrorTerminated;
+   }
    if (!write_session_label(jcr, block, EOS_LABEL)) {
       Jmsg1(jcr, M_FATAL, 0, _("Error writting end session label. ERR=%s\n"),
          strerror_dev(dev));