]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/catreq.c
Ensure that StorageId is updated after write
[bacula/bacula] / bacula / src / dird / catreq.c
index 7e9422e5b7aab5e12ba712cdff0fa23673ffa0ed..e193bff46466b3e244bd7271dc99d558edf2cb7d 100644 (file)
@@ -1,12 +1,12 @@
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2001-2010 Free Software Foundation Europe e.V.
+   Copyright (C) 2001-2012 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.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
+   modify it under the terms of version three of the GNU Affero General Public
    License as published by the Free Software Foundation and included
    in the file LICENSE.
 
@@ -15,7 +15,7 @@
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    General Public License for more details.
 
-   You should have received a copy of the GNU General Public License
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
@@ -114,7 +114,6 @@ void catalog_request(JCR *jcr, BSOCK *bs)
    utime_t VolFirstWritten;
    utime_t VolLastWritten;
 
-   memset(&mr, 0, sizeof(mr));
    memset(&sdmr, 0, sizeof(sdmr));
    memset(&jm, 0, sizeof(jm));
    Dsm_check(100);      
@@ -141,7 +140,7 @@ void catalog_request(JCR *jcr, BSOCK *bs)
       ok = db_get_pool_record(jcr, jcr->db, &pr);
       if (ok) {
          mr.PoolId = pr.PoolId;
-         mr.StorageId = jcr->wstore->StorageId;
+         set_storageid_in_mr(jcr->wstore, &mr);
          mr.ScratchPoolId = pr.ScratchPoolId;
          ok = find_next_volume_for_append(jcr, &mr, index, fnv_create_vol, fnv_prune);
          Dmsg3(050, "find_media ok=%d idx=%d vol=%s\n", ok, index, mr.VolumeName);
@@ -201,7 +200,7 @@ void catalog_request(JCR *jcr, BSOCK *bs)
             send_volume_info_to_storage_daemon(jcr, bs, &mr);
          } else {
             /* Not suitable volume */
-            bs->fsend(_("1998 Volume \"%s\" status is %s, %s.\n"), mr.VolumeName,
+            bs->fsend(_("1998 Volume \"%s\" catalog status is %s, %s.\n"), mr.VolumeName,
                mr.VolStatus, reason);
          }
 
@@ -281,14 +280,14 @@ void catalog_request(JCR *jcr, BSOCK *bs)
        *   However, do so only if we are writing the tape, i.e.
        *   the number of VolWrites has increased.
        */
-      if (jcr->wstore && jcr->wstore->StorageId && sdmr.VolWrites > mr.VolWrites) {
+      if (jcr->wstore && sdmr.VolWrites > mr.VolWrites) {
          Dmsg2(050, "Update StorageId old=%d new=%d\n",
                mr.StorageId, jcr->wstore->StorageId);
-         if (jcr->wstore->StorageId == 0) {
-            Jmsg(jcr, M_ERROR, 0, _("Attempt to set StorageId to zero.\n"));
-         } else {
-            mr.StorageId = jcr->wstore->StorageId;
-         }
+         /* Update StorageId after write */
+         set_storageid_in_mr(jcr->wstore, &mr);
+      } else {
+         /* Nothing written, reset same StorageId */
+         set_storageid_in_mr(NULL, &mr);
       }
 
       /* Copy updated values to original media record */
@@ -357,6 +356,7 @@ void catalog_request(JCR *jcr, BSOCK *bs)
       Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog request: %s"), omsg);
       free_memory(omsg);
    }
+
    Dmsg1(400, ">CatReq response: %s", bs->msg);
    Dmsg1(400, "Leave catreq jcr 0x%x\n", jcr);
    return;
@@ -418,6 +418,7 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen)
     *   Encoded attributes
     *   Link name (if type==FT_LNK or FT_LNKSAVED)
     *   Encoded extended-attributes (for Win32)
+    *   Delta sequence number (32 bit int)
     *
     * Restore Object
     *   File_index
@@ -447,14 +448,26 @@ static void update_attribute(JCR *jcr, char *msg, int32_t msglen)
       jcr->attr = check_pool_memory_size(jcr->attr, msglen);
       memcpy(jcr->attr, msg, msglen);
       p = jcr->attr - msg + p;    /* point p into jcr->attr */
-      skip_nonspaces(&p);             /* skip FileIndex */
+      skip_nonspaces(&p);         /* skip FileIndex */
       skip_spaces(&p);
       ar->FileType = str_to_int32(p); 
-      skip_nonspaces(&p);             /* skip FileType */
+      skip_nonspaces(&p);         /* skip FileType */
       skip_spaces(&p);
       fname = p;
       len = strlen(fname);        /* length before attributes */
       attr = &fname[len+1];
+      ar->DeltaSeq = 0;
+      if (ar->FileType == FT_REG) {
+         p = attr + strlen(attr) + 1;  /* point to link */
+         p = p + strlen(p) + 1;        /* point to extended attributes */
+         p = p + strlen(p) + 1;        /* point to delta sequence */
+         /*
+          * Older FDs don't have a delta sequence, so check if it is there 
+          */
+         if (p - jcr->attr < msglen) {
+            ar->DeltaSeq = str_to_int32(p); /* delta_seq */
+         }
+      }
 
       Dmsg2(400, "dird<stored: stream=%d %s\n", Stream, fname);
       Dmsg1(400, "dird<stored: attr=%s\n", attr);
@@ -621,8 +634,7 @@ bool despool_attributes_from_file(JCR *jcr, const char *file)
    bool ret=false;
    int32_t pktsiz;
    size_t nbytes;
-   ssize_t last = 0, size = 0;
-   int count = 0;
+   ssize_t size = 0;
    int32_t msglen;                    /* message length */
    POOLMEM *msg = get_pool_memory(PM_MESSAGE);
    FILE *spool_fd=NULL;
@@ -660,9 +672,6 @@ bool despool_attributes_from_file(JCR *jcr, const char *file)
             goto bail_out;
          }
          size += nbytes;
-         if ((++count & 0x3F) == 0) {
-            last = size;
-         }
       }
       if (!jcr->is_job_canceled()) {
          update_attribute(jcr, msg, msglen);