]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/dird/catreq.c
This commit was manufactured by cvs2svn to create tag
[bacula/bacula] / bacula / src / dird / catreq.c
index c563d35eace0ded4e37351142a0fe6e3a50c3267..7cfa64ba05d4dc3f6d1f6a814dcebdce66aa9646 100644 (file)
@@ -85,7 +85,7 @@ static int send_volume_info_to_storage_daemon(JCR *jcr, BSOCK *sd, MEDIA_DBR *mr
    return stat;
 }
 
-void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
+void catalog_request(JCR *jcr, BSOCK *bs)
 {
    MEDIA_DBR mr, sdmr;
    JOBMEDIA_DBR jm;
@@ -117,10 +117,12 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
    if (sscanf(bs->msg, Find_media, &Job, &index, &pool_name, &mr.MediaType) == 4) {
       memset(&pr, 0, sizeof(pr));
       bstrncpy(pr.Name, pool_name, sizeof(pr.Name));
+      unbash_spaces(pr.Name);
       ok = db_get_pool_record(jcr, jcr->db, &pr);
       if (ok) {
          mr.PoolId = pr.PoolId;
-         ok = find_next_volume_for_append(jcr, &mr, true /*permit create new vol*/);
+         mr.StorageId = jcr->store->StorageId;
+         ok = find_next_volume_for_append(jcr, &mr, index, true /*permit create new vol*/);
       }
       /*
        * Send Find Media response to Storage daemon
@@ -160,16 +162,6 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
             } else if (strcmp(mr.MediaType, jcr->store->media_type) != 0) {
                reason = _("not correct MediaType");
             } else {
-              /*
-               * ****FIXME***
-               *   This test (accept_any_volume) is turned off
-               *   because it doesn't properly check if the volume
-               *   really is out of sequence!
-               *
-               * } else if (!jcr->pool->accept_any_volume) {
-               *    reason = "Volume not in sequence";
-               */
-
                /*
                 * Now try recycling if necessary
                 *   reason set non-NULL if we cannot use it
@@ -235,7 +227,8 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
             Jmsg(jcr, M_FATAL, 0, _("Volume Files at %u being set to %u"
                  " for Volume \"%s\". This is incorrect.\n"),
                mr.VolFiles, sdmr.VolFiles, mr.VolumeName);
-            bnet_fsend(bs, _("1992 Update Media error\n"));
+            bnet_fsend(bs, _("1992 Update Media error. VolFiles=%u, CatFiles=%u\n"),
+               sdmr.VolFiles, mr.VolFiles);
             db_unlock(jcr->db);
             return;
          }
@@ -256,19 +249,23 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
       mr.VolWriteTime = sdmr.VolWriteTime;
       mr.VolParts     = sdmr.VolParts;
       bstrncpy(mr.VolStatus, sdmr.VolStatus, sizeof(mr.VolStatus));
+      if (jcr->store->StorageId) {
+         mr.StorageId = jcr->store->StorageId;
+      }
 
       Dmsg2(400, "db_update_media_record. Stat=%s Vol=%s\n", mr.VolStatus, mr.VolumeName);
       /*
-       * Check if it has expired, and if not update the DB. Note, if
-       *   Volume has expired, has_volume_expired() will update the DB.
+       * Update the database, then before sending the response to the
+       *  SD, check if the Volume has expired.
        */
-      if (has_volume_expired(jcr, &mr) || db_update_media_record(jcr, jcr->db, &mr)) {
-         send_volume_info_to_storage_daemon(jcr, bs, &mr);
-      } else {
+      if (!db_update_media_record(jcr, jcr->db, &mr)) {
          Jmsg(jcr, M_FATAL, 0, _("Catalog error updating Media record. %s"),
             db_strerror(jcr->db));
-         bnet_fsend(bs, _("1992 Update Media error\n"));
+         bnet_fsend(bs, _("1993 Update Media error\n"));
          Dmsg0(400, "send error\n");
+      } else {
+         (void)has_volume_expired(jcr, &mr);
+         send_volume_info_to_storage_daemon(jcr, bs, &mr);
       }
       db_unlock(jcr->db);
 
@@ -311,7 +308,7 @@ void catalog_request(JCR *jcr, BSOCK *bs, char *msg)
  *  VolSessionId, VolSessionTime, FileIndex, and file name
  *  to store in the catalog.
  */
-void catalog_update(JCR *jcr, BSOCK *bs, char *msg)
+void catalog_update(JCR *jcr, BSOCK *bs)
 {
    unser_declare;
    uint32_t VolSessionId, VolSessionTime;
@@ -322,10 +319,20 @@ void catalog_update(JCR *jcr, BSOCK *bs, char *msg)
    int len;
    char *fname, *attr;
    ATTR_DBR *ar = NULL;
+   POOLMEM *omsg;
 
    if (!jcr->pool->catalog_files) {
       return;                         /* user disabled cataloging */
    }
+   if (!jcr->db) {
+      omsg = get_memory(bs->msglen+1);
+      pm_strcpy(omsg, bs->msg);
+      bnet_fsend(bs, _("1991 Invalid Catalog Update: %s"), omsg);    
+      Jmsg1(jcr, M_FATAL, 0, _("Invalid Catalog Update; DB not open: %s"), omsg);
+      free_memory(omsg);
+      return;
+   }
+
    /* Start transaction allocates jcr->attr and jcr->ar if needed */
    db_start_transaction(jcr, jcr->db);     /* start transaction if not already open */
    ar = jcr->ar;      
@@ -387,7 +394,7 @@ void catalog_update(JCR *jcr, BSOCK *bs, char *msg)
       Dmsg2(400, "dird<filed: stream=%d %s\n", Stream, fname);
       Dmsg1(400, "dird<filed: attr=%s\n", attr);
 
-#ifdef xxx
+#ifdef xxx_old_code
       if (!db_create_file_attributes_record(jcr, jcr->db, ar)) {
          Jmsg1(jcr, M_FATAL, 0, _("Attribute create error. %s"), db_strerror(jcr->db));
       }