]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/spool.c
Remove broken run when code
[bacula/bacula] / bacula / src / stored / spool.c
index 03d222196a06e63ce45ad3a981715519f2366526..7e9d57e9cf63f9ef4eb34b23f1a24b44fe22517d 100644 (file)
@@ -1,14 +1,7 @@
-/*
- *  Spooling code
- *
- *      Kern Sibbald, March 2004
- *
- *  Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2004-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2004-2007 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ *  Spooling code
+ *
+ *      Kern Sibbald, March 2004
+ *
+ *  Version $Id$
+ */
 
 #include "bacula.h"
 #include "stored.h"
@@ -77,18 +77,17 @@ enum {
 
 void list_spool_stats(void sendit(const char *msg, int len, void *sarg), void *arg)
 {
-   char *msg, ed1[30], ed2[30];
+   char ed1[30], ed2[30];
+   POOL_MEM msg(PM_MESSAGE);
    int len;
 
-   msg = (char *)get_pool_memory(PM_MESSAGE);
-
    if (spool_stats.data_jobs || spool_stats.max_data_size) {
       len = Mmsg(msg, _("Data spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes/job.\n"),
          spool_stats.data_jobs, edit_uint64_with_commas(spool_stats.data_size, ed1),
          spool_stats.total_data_jobs,
          edit_uint64_with_commas(spool_stats.max_data_size, ed2));
 
-      sendit(msg, len, arg);
+      sendit(msg.c_str(), len, arg);
    }
    if (spool_stats.attr_jobs || spool_stats.max_attr_size) {
       len = Mmsg(msg, _("Attr spooling: %u active jobs, %s bytes; %u total jobs, %s max bytes.\n"),
@@ -96,10 +95,8 @@ void list_spool_stats(void sendit(const char *msg, int len, void *sarg), void *a
          spool_stats.total_attr_jobs,
          edit_uint64_with_commas(spool_stats.max_attr_size, ed2));
    
-      sendit(msg, len, arg);
+      sendit(msg.c_str(), len, arg);
    }
-
-   free_pool_memory(msg);
 }
 
 bool begin_data_spool(DCR *dcr)
@@ -154,8 +151,8 @@ static void make_unique_data_spool_filename(DCR *dcr, POOLMEM **name)
    } else {
       dir = working_directory;
    }
-   Mmsg(name, "%s/%s.data.%s.%s.spool", dir, my_name, dcr->jcr->Job, 
-        dcr->device->hdr.name);
+   Mmsg(name, "%s/%s.data.%u.%s.%s.spool", dir, my_name, dcr->jcr->JobId,
+        dcr->jcr->Job, dcr->device->hdr.name);
 }
 
 
@@ -171,7 +168,7 @@ static bool open_data_spool_file(DCR *dcr)
    } else {
       berrno be;
       Jmsg(dcr->jcr, M_FATAL, 0, _("Open data spool file %s failed: ERR=%s\n"), name,
-           be.strerror());
+           be.bstrerror());
       free_pool_memory(name);
       return false;
    }
@@ -207,6 +204,10 @@ static bool close_data_spool_file(DCR *dcr)
 
 static const char *spool_name = "*spool*";
 
+/*
+ * NB! This routine locks the device, but if committing will
+ *     not unlock it. If not committing, it will be unlocked.
+ */
 static bool despool_data(DCR *dcr, bool commit)
 {
    DEVICE *rdev;
@@ -218,7 +219,8 @@ static bool despool_data(DCR *dcr, bool commit)
    char ec1[50];
 
    Dmsg0(100, "Despooling data\n");
-   /* Commit means that the job is done, so we commit, otherwise, we
+   /*
+    * Commit means that the job is done, so we commit, otherwise, we
     *  are despooling because of user spool size max or some error  
     *  (e.g. filesystem full).
     */
@@ -232,7 +234,7 @@ static bool despool_data(DCR *dcr, bool commit)
    }
    dcr->despool_wait = true;
    dcr->spooling = false;
-   lock_device(dcr->dev);
+   dcr->dev->r_dlock();
    dcr->despool_wait = false;
    dcr->despooling = true;
    dcr->dev_locked = true;
@@ -251,7 +253,7 @@ static bool despool_data(DCR *dcr, bool commit)
    rdev->max_block_size = dcr->dev->max_block_size;
    rdev->min_block_size = dcr->dev->min_block_size;
    rdev->device = dcr->dev->device;
-   rdcr = new_dcr(NULL, rdev);
+   rdcr = new_dcr(jcr, rdev);
    rdcr->spool_fd = dcr->spool_fd;
    rdcr->jcr = jcr;                   /* set a valid jcr */
    block = dcr->block;                /* save block */
@@ -260,6 +262,10 @@ static bool despool_data(DCR *dcr, bool commit)
    Dmsg1(800, "read/write block size = %d\n", block->buf_len);
    lseek(rdcr->spool_fd, 0, SEEK_SET); /* rewind */
 
+#if defined(HAVE_POSIX_FADVISE) && defined(POSIX_FADV_WILLNEED)
+   posix_fadvise(rdcr->spool_fd, 0, 0, POSIX_FADV_WILLNEED);
+#endif
+
    /* Add run time, to get current wait time */
    time_t despool_start = time(NULL) - jcr->run_time;
 
@@ -300,9 +306,8 @@ static bool despool_data(DCR *dcr, bool commit)
    if (ftruncate(rdcr->spool_fd, 0) != 0) {
       berrno be;
       Jmsg(dcr->jcr, M_ERROR, 0, _("Ftruncate spool file failed: ERR=%s\n"),
-         be.strerror());
-      Pmsg1(000, _("Bad return from ftruncate. ERR=%s\n"), be.strerror());
-      ok = false;
+         be.bstrerror());
+      /* Note, try continuing despite ftruncate problem */
    }
 
    P(mutex);
@@ -328,7 +333,7 @@ static bool despool_data(DCR *dcr, bool commit)
    /* If doing a commit, leave the device locked -- unlocked in release_device() */
    if (!commit) {
       dcr->dev_locked = false;
-      unlock_device(dcr->dev);
+      dcr->dev->dunlock();
    }
    return ok;
 }
@@ -356,7 +361,7 @@ static int read_block_from_spool_file(DCR *dcr)
       if (stat == -1) {
          berrno be;
          Jmsg(dcr->jcr, M_FATAL, 0, _("Spool header read error. ERR=%s\n"),
-              be.strerror());
+              be.bstrerror());
       } else {
          Pmsg2(000, _("Spool read error. Wanted %u bytes, got %d\n"), rlen, stat);
          Jmsg2(dcr->jcr, M_FATAL, 0, _("Spool header read error. Wanted %u bytes, got %d\n"), rlen, stat);
@@ -471,7 +476,7 @@ static bool write_spool_header(DCR *dcr)
       if (stat == -1) {
          berrno be;
          Jmsg(dcr->jcr, M_FATAL, 0, _("Error writing header to spool file. ERR=%s\n"),
-              be.strerror());
+              be.bstrerror());
       }
       if (stat != (ssize_t)sizeof(hdr)) {
          /* If we wrote something, truncate it, then despool */
@@ -483,9 +488,9 @@ static bool write_spool_header(DCR *dcr)
 #endif
             if (ftruncate(dcr->spool_fd, pos - stat) != 0) {
                berrno be;
-               Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"),
-                  be.strerror());
-               return false;
+               Jmsg(dcr->jcr, M_ERROR, 0, _("Ftruncate spool file failed: ERR=%s\n"),
+                  be.bstrerror());
+              /* Note, try continuing despite ftruncate problem */
             }
          }
          if (!despool_data(dcr, false)) {
@@ -511,7 +516,7 @@ static bool write_spool_data(DCR *dcr)
       if (stat == -1) {
          berrno be;
          Jmsg(dcr->jcr, M_FATAL, 0, _("Error writing data to spool file. ERR=%s\n"),
-              be.strerror());
+              be.bstrerror());
       }
       if (stat != (ssize_t)block->binbuf) {
          /*
@@ -525,9 +530,9 @@ static bool write_spool_data(DCR *dcr)
 #endif
             if (ftruncate(dcr->spool_fd, pos - stat - sizeof(spool_hdr)) != 0) {
                berrno be;
-               Jmsg(dcr->jcr, M_FATAL, 0, _("Ftruncate spool file failed: ERR=%s\n"),
-                  be.strerror());
-               return false;
+               Jmsg(dcr->jcr, M_ERROR, 0, _("Ftruncate spool file failed: ERR=%s\n"),
+                  be.bstrerror());
+               /* Note, try continuing despite ftruncate problem */
             }
          }
          if (!despool_data(dcr, false)) {
@@ -597,14 +602,14 @@ bool commit_attribute_spool(JCR *jcr)
       if (fseeko(jcr->dir_bsock->spool_fd, 0, SEEK_END) != 0) {
          berrno be;
          Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"),
-              be.strerror());
+              be.bstrerror());
          goto bail_out;
       }
       size = ftello(jcr->dir_bsock->spool_fd);
       if (size < 0) {
          berrno be;
          Jmsg(jcr, M_FATAL, 0, _("Fseek on attributes file failed: ERR=%s\n"),
-              be.strerror());
+              be.bstrerror());
          goto bail_out;
       }
       P(mutex);
@@ -615,7 +620,7 @@ bool commit_attribute_spool(JCR *jcr)
       V(mutex);
       Jmsg(jcr, M_INFO, 0, _("Sending spooled attrs to the Director. Despooling %s bytes ...\n"),
             edit_uint64_with_commas(size, ec1));
-      bnet_despool_to_bsock(jcr->dir_bsock, update_attr_spool_size, size);
+      jcr->dir_bsock->despool(update_attr_spool_size, size);
       return close_attr_spool_file(jcr, jcr->dir_bsock);
    }
    return true;
@@ -641,7 +646,7 @@ bool open_attr_spool_file(JCR *jcr, BSOCK *bs)
    if (!bs->spool_fd) {
       berrno be;
       Jmsg(jcr, M_FATAL, 0, _("fopen attr spool file %s failed: ERR=%s\n"), name,
-           be.strerror());
+           be.bstrerror());
       free_pool_memory(name);
       return false;
    }