]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/append.c
Clean up some SD message nos.
[bacula/bacula] / bacula / src / stored / append.c
index 225b9cf86e06fda4863c743ccc9c071df5f6ac6d..27650e7915e3de5cfef74925f00825b7ff7aab2f 100644 (file)
@@ -5,7 +5,7 @@
  *  Version $Id$
  */
 /*
-   Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
+   Copyright (C) 2000-2003 Kern Sibbald and John Walker
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License as
@@ -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";
@@ -54,8 +51,6 @@ int do_append_data(JCR *jcr)
    /* Tell File daemon to send data */
    bnet_fsend(fd_sock, OK_data);
 
-   sm_check(__FILE__, __LINE__, False);
-
    if (!jcr->no_attributes && jcr->spool_attributes) {
       open_spool_file(jcr, jcr->dir_bsock);
    }
@@ -63,7 +58,7 @@ int do_append_data(JCR *jcr)
    ds = fd_sock;
 
    if (!bnet_set_buffer_size(ds, MAX_NETWORK_BUFFER_SIZE, BNET_SETBUF_WRITE)) {
-      jcr->JobStatus = JS_Cancelled;
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       Jmsg(jcr, M_FATAL, 0, _("Unable to set network buffer size.\n"));
       return 0;
    }
@@ -78,34 +73,44 @@ int do_append_data(JCR *jcr)
     *  subroutine.
     */
    Dmsg0(100, "just before acquire_device\n");
-   if (!acquire_device_for_append(jcr, dev, block)) {
-      jcr->JobStatus = JS_Cancelled;
+   if (!(dev=acquire_device_for_append(jcr, dev, block))) {
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       free_block(block);
       return 0;
    }
-   sm_check(__FILE__, __LINE__, False);
-
    Dmsg0(100, "Just after acquire_device_for_append\n");
    /*
     * Write Begin Session Record
     */
    if (!write_session_label(jcr, block, SOS_LABEL)) {
-      jcr->JobStatus = JS_Cancelled;
       Jmsg1(jcr, M_FATAL, 0, _("Write session label failed. ERR=%s\n"),
         strerror_dev(dev));
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       ok = FALSE;
    }
 
-   sm_check(__FILE__, __LINE__, False);
-
    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 */
-   for (last_file_index = 0; ok && !job_cancelled(jcr); ) {
+   for (last_file_index = 0; ok && !job_canceled(jcr); ) {
       char info[100];
 
       /* Read Stream header from the File daemon.
@@ -113,17 +118,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) {
          Jmsg1(jcr, M_FATAL, 0, _("Malformed data header from FD: %s\n"), ds->msg);
@@ -149,10 +154,8 @@ int do_append_data(JCR *jcr)
       /* Read data stream from the File daemon.
        *  The data stream is just raw bytes
        */
-      sm_check(__FILE__, __LINE__, False);
-      while ((n=bget_msg(ds)) > 0 && !job_cancelled(jcr)) {
+      while ((n=bget_msg(ds)) > 0 && !job_canceled(jcr)) {
 
-        sm_check(__FILE__, __LINE__, False);
         rec.VolSessionId = jcr->VolSessionId;
         rec.VolSessionTime = jcr->VolSessionTime;
         rec.FileIndex = file_index;
@@ -161,7 +164,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)) {
@@ -176,21 +179,23 @@ int do_append_data(JCR *jcr)
               break;
            }
         }
-        sm_check(__FILE__, __LINE__, False);
         if (!ok) {
             Dmsg0(400, "Not OK\n");
            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 || stream == STREAM_SHA1_SIGNATURE) { 
            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));
@@ -201,9 +206,8 @@ int do_append_data(JCR *jcr)
               jcr->dir_bsock->spool = 0;
            }
         }
-        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,28 +215,34 @@ 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 */
+   set_jcr_job_status(jcr, ok?JS_Terminated:JS_ErrorTerminated);
+
+   Dmsg1(200, "Write session label JobStatus=%d\n", jcr->JobStatus);
+
    if (!write_session_label(jcr, block, EOS_LABEL)) {
       Jmsg1(jcr, M_FATAL, 0, _("Error writting end session label. ERR=%s\n"),
          strerror_dev(dev));
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       ok = FALSE;
    }
    /* Write out final block of this session */
    if (!write_block_to_device(jcr, dev, block)) {
-      Pmsg0(000, "Set ok=FALSE after write_block_to_device.\n");
+      Pmsg0(000, _("Set ok=FALSE after write_block_to_device.\n"));
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       ok = FALSE;
    }
 
+   Dmsg1(200, "release device JobStatus=%d\n", jcr->JobStatus);
    /* Release the device */
-   if (!release_device(jcr, dev, block)) {
-      Pmsg0(000, "Error in release_device\n");
+   if (!release_device(jcr, dev)) {
+      Pmsg0(000, _("Error in release_device\n"));
+      set_jcr_job_status(jcr, JS_ErrorTerminated);
       ok = FALSE;
    }
 
@@ -243,6 +253,8 @@ int do_append_data(JCR *jcr)
       close_spool_file(jcr, jcr->dir_bsock);
    }
 
+   dir_send_job_status(jcr);         /* update director */
+
    Dmsg0(90, "return from do_append_data()\n");
    return ok ? 1 : 0;
 }