]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/stored/parse_bsr.c
Make btape fill/unfill work
[bacula/bacula] / bacula / src / stored / parse_bsr.c
index 1d5ba45a252cb90fbce5b179d904d232b46625ea..270747760047d0f0fd5321863a11266ad20ee2d8 100755 (executable)
@@ -35,11 +35,13 @@ static BSR *store_vol(LEX *lc, BSR *bsr);
 static BSR *store_client(LEX *lc, BSR *bsr);
 static BSR *store_job(LEX *lc, BSR *bsr);
 static BSR *store_jobid(LEX *lc, BSR *bsr);
+static BSR *store_count(LEX *lc, BSR *bsr);
 static BSR *store_jobtype(LEX *lc, BSR *bsr);
 static BSR *store_joblevel(LEX *lc, BSR *bsr);
 static BSR *store_findex(LEX *lc, BSR *bsr);
 static BSR *store_sessid(LEX *lc, BSR *bsr);
 static BSR *store_volfile(LEX *lc, BSR *bsr);
+static BSR *store_volblock(LEX *lc, BSR *bsr);
 static BSR *store_sesstime(LEX *lc, BSR *bsr);
 static BSR *store_include(LEX *lc, BSR *bsr);
 static BSR *store_exclude(LEX *lc, BSR *bsr);
@@ -51,11 +53,15 @@ struct kw_items {
    ITEM_HANDLER *handler;
 };
 
+/*
+ * List of all keywords permitted in bsr files and their handlers
+ */
 struct kw_items items[] = {
    {"volume", store_vol},
    {"client", store_client},
    {"job", store_job},
    {"jobid", store_jobid},
+   {"count", store_count},
    {"fileindex", store_findex},
    {"jobtype", store_jobtype},
    {"joblevel", store_joblevel},
@@ -64,12 +70,16 @@ struct kw_items items[] = {
    {"include", store_include},
    {"exclude", store_exclude},
    {"volfile", store_volfile},
+   {"volblock", store_volblock},
    {"stream",  store_stream},
    {"slot",    store_slot},
    {NULL, NULL}
 
 };
 
+/* 
+ * Create a BSR record
+ */
 static BSR *new_bsr() 
 {
    BSR *bsr = (BSR *)malloc(sizeof(BSR));
@@ -82,6 +92,7 @@ static BSR *new_bsr()
  */
 static void s_err(char *file, int line, LEX *lc, char *msg, ...)
 {
+   JCR *jcr = (JCR *)(lc->caller_ctx);
    va_list arg_ptr;
    char buf[MAXSTRING];
 
@@ -89,9 +100,15 @@ static void s_err(char *file, int line, LEX *lc, char *msg, ...)
    bvsnprintf(buf, sizeof(buf), msg, arg_ptr);
    va_end(arg_ptr);
      
-   e_msg(file, line, M_FATAL, 0, "Config error: %s\n\
-            : Line %d, col %d of file %s\n%s\n",
-      buf, lc->line_no, lc->col_no, lc->fname, lc->line);
+   if (jcr) {
+      Jmsg(jcr, M_FATAL, 0, _("Bootstrap file error: %s\n\
+            : Line %d, col %d of file %s\n%s\n"),
+        buf, lc->line_no, lc->col_no, lc->fname, lc->line);
+   } else {
+      e_msg(file, line, M_FATAL, 0, _("Bootstrap file error: %s\n\
+            : Line %d, col %d of file %s\n%s\n"),
+        buf, lc->line_no, lc->col_no, lc->fname, lc->line);
+   }
 }
 
 
@@ -100,30 +117,31 @@ static void s_err(char *file, int line, LEX *lc, char *msg, ...)
  *     Parse Bootstrap file
  *
  */
-BSR *parse_bsr(char *cf)
+BSR *parse_bsr(JCR *jcr, char *cf)
 {
    LEX *lc = NULL;
    int token, i;
    BSR *root_bsr = new_bsr();
    BSR *bsr = root_bsr;
 
-   Dmsg0(200, "Enter parse_bsf()\n");
+   Dmsg1(200, "Enter parse_bsf %s\n", cf);
    lc = lex_open_file(lc, cf, s_err);
+   lc->caller_ctx = (void *)jcr;
    while ((token=lex_get_token(lc, T_ALL)) != T_EOF) {
-      Dmsg1(150, "parse got token=%s\n", lex_tok_to_str(token));
+      Dmsg1(200, "parse got token=%s\n", lex_tok_to_str(token));
       if (token == T_EOL) {
         continue;
       }
       for (i=0; items[i].name; i++) {
         if (strcasecmp(items[i].name, lc->str) == 0) {
            token = lex_get_token(lc, T_ALL);
-            Dmsg1 (150, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
+            Dmsg1 (200, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
            if (token != T_EQUALS) {
                scan_err1(lc, "expected an equals, got: %s", lc->str);
               bsr = NULL;
               break;
            }
-            Dmsg1(100, "calling handler for %s\n", items[i].name);
+            Dmsg1(200, "calling handler for %s\n", items[i].name);
            /* Call item handler */
            bsr = items[i].handler(lc, bsr);
            i = -1;
@@ -131,8 +149,9 @@ BSR *parse_bsr(char *cf)
         }
       }
       if (i >= 0) {
-         Dmsg1(150, "Keyword = %s\n", lc->str);
+         Dmsg1(200, "Keyword = %s\n", lc->str);
          scan_err1(lc, "Keyword %s not found", lc->str);
+        bsr = NULL;
         break;
       }
       if (!bsr) {
@@ -151,17 +170,39 @@ BSR *parse_bsr(char *cf)
 static BSR *store_vol(LEX *lc, BSR *bsr)
 {
    int token;
+   BSR_VOLUME *volume;
+   char *p, *n;
     
-   token = lex_get_token(lc, T_NAME);
+   token = lex_get_token(lc, T_STRING);
    if (token == T_ERROR) {
       return NULL;
    }
-   if (bsr->VolumeName) {
+   if (bsr->volume) {
       bsr->next = new_bsr();
       bsr = bsr->next;
    }
-   bsr->VolumeName = bstrdup(lc->str);
-   scan_to_eol(lc);
+   /* This may actually be more than one volume separated by a |  
+    * If so, separate them.
+    */
+   for (p=lc->str; p && *p; ) {
+      n = strchr(p, '|');
+      if (n) {
+        *n++ = 0;
+      }
+      volume = (BSR_VOLUME *)malloc(sizeof(BSR_VOLUME));
+      memset(volume, 0, sizeof(BSR_VOLUME));
+      strcpy(volume->VolumeName, p);
+      /* Add it to the end of the volume chain */
+      if (!bsr->volume) {
+        bsr->volume = volume;
+      } else {
+        BSR_VOLUME *bc = bsr->volume;
+        for ( ;bc->next; bc=bc->next)  
+           { }
+        bc->next = volume;
+      }
+      p = n;
+   }
    return bsr;
 }
 
@@ -291,6 +332,21 @@ static BSR *store_jobid(LEX *lc, BSR *bsr)
    return bsr;
 }
 
+
+static BSR *store_count(LEX *lc, BSR *bsr)
+{
+   int token;
+
+   token = lex_get_token(lc, T_PINT32);
+   if (token == T_ERROR) {
+      return NULL;
+   }
+   bsr->count = lc->pint32_val;
+   scan_to_eol(lc);
+   return bsr;
+}
+
+
 static BSR *store_jobtype(LEX *lc, BSR *bsr)
 {
    /* *****FIXME****** */
@@ -345,6 +401,41 @@ static BSR *store_volfile(LEX *lc, BSR *bsr)
 }
 
 
+/*
+ * Routine to handle Volume start/end Block  
+ */
+static BSR *store_volblock(LEX *lc, BSR *bsr)
+{
+   int token;
+   BSR_VOLBLOCK *volblock;
+
+   for (;;) {
+      token = lex_get_token(lc, T_PINT32_RANGE);
+      if (token == T_ERROR) {
+        return NULL;
+      }
+      volblock = (BSR_VOLBLOCK *)malloc(sizeof(BSR_VOLBLOCK));
+      memset(volblock, 0, sizeof(BSR_VOLBLOCK));
+      volblock->sblock = lc->pint32_val;
+      volblock->eblock = lc->pint32_val2;
+      /* Add it to the end of the chain */
+      if (!bsr->volblock) {
+        bsr->volblock = volblock;
+      } else {
+        /* Add to end of chain */
+        BSR_VOLBLOCK *bs = bsr->volblock;
+        for ( ;bs->next; bs=bs->next)
+           {  }
+        bs->next = volblock;
+      }
+      token = lex_get_token(lc, T_ALL);
+      if (token != T_COMMA) {
+        break;
+      }
+   }
+   return bsr;
+}
+
 
 static BSR *store_sessid(LEX *lc, BSR *bsr)
 {
@@ -474,6 +565,15 @@ void dump_volfile(BSR_VOLFILE *volfile)
    }
 }
 
+void dump_volblock(BSR_VOLBLOCK *volblock)
+{
+   if (volblock) {
+      Dmsg2(-1, "VolBlock    : %u-%u\n", volblock->sblock, volblock->eblock);
+      dump_volblock(volblock->next);
+   }
+}
+
+
 void dump_findex(BSR_FINDEX *FileIndex)
 {
    if (FileIndex) {
@@ -510,6 +610,14 @@ void dump_sessid(BSR_SESSID *sessid)
    }
 }
 
+void dump_volume(BSR_VOLUME *volume)
+{
+   if (volume) {
+      Dmsg1(-1, "VolumeName  : %s\n", volume->VolumeName);
+      dump_volume(volume->next);
+   }
+}
+
 
 void dump_client(BSR_CLIENT *client)
 {
@@ -545,18 +653,23 @@ void dump_bsr(BSR *bsr)
       Dmsg0(-1, "BSR is NULL\n");
       return;
    }
-   Dmsg2(-1,   
-"Next        : 0x%x\n"
-"VolumeName  : %s\n",
-                bsr->next,
-                 bsr->VolumeName ? bsr->VolumeName : "*None*");
+   Dmsg1(-1,   
+"Next        : 0x%x\n", bsr->next);
+   dump_volume(bsr->volume);
    dump_sessid(bsr->sessid);
    dump_sesstime(bsr->sesstime);
    dump_volfile(bsr->volfile);
+   dump_volblock(bsr->volblock);
    dump_client(bsr->client);
    dump_jobid(bsr->JobId);
    dump_job(bsr->job);
    dump_findex(bsr->FileIndex);
+   if (bsr->Slot) {
+      Dmsg1(-1, "Slot        : %u\n", bsr->Slot);
+   }
+   if (bsr->count) {
+      Dmsg1(-1, "count       : %u\n", bsr->count);
+   }
    if (bsr->next) {
       Dmsg0(-1, "\n");
       dump_bsr(bsr->next);
@@ -583,18 +696,17 @@ void free_bsr(BSR *bsr)
    if (!bsr) {
       return;
    }
+   free_bsr_item((BSR *)bsr->volume);
    free_bsr_item((BSR *)bsr->client);
    free_bsr_item((BSR *)bsr->sessid);
    free_bsr_item((BSR *)bsr->sesstime);
    free_bsr_item((BSR *)bsr->volfile);
+   free_bsr_item((BSR *)bsr->volblock);
    free_bsr_item((BSR *)bsr->JobId);
    free_bsr_item((BSR *)bsr->job);
    free_bsr_item((BSR *)bsr->FileIndex);
    free_bsr_item((BSR *)bsr->JobType);
    free_bsr_item((BSR *)bsr->JobLevel);
-   if (bsr->VolumeName) {
-      free(bsr->VolumeName);
-   }
    free_bsr(bsr->next);
    free(bsr);
 }
@@ -626,10 +738,16 @@ int add_vol(JCR *jcr, VOL_LIST *vol)
    } else {
       for ( ; next->next; next=next->next) {
         if (strcmp(vol->VolumeName, next->VolumeName) == 0) {
+           if (vol->start_file < next->start_file) {
+              next->start_file = vol->start_file;
+           }
            return 0;                 /* already in list */
         }
       }
       if (strcmp(vol->VolumeName, next->VolumeName) == 0) {
+        if (vol->start_file < next->start_file) {
+           next->start_file = vol->start_file;
+        }
         return 0;                    /* already in list */
       }
       next->next = vol;              /* add volume */
@@ -647,30 +765,52 @@ void free_vol_list(JCR *jcr)
       free(next);
       next = tmp;
    }
+   jcr->VolList = NULL;
 }
 
+/*
+ * Create a list of Volumes (and Slots and Start positions) to be
+ *  used in the current restore job.
+ */
 void create_vol_list(JCR *jcr)
 {
    char *p, *n;
    VOL_LIST *vol;
 
    /* 
-    * Build a list of volume to be processed
+    * Build a list of volumes to be processed
     */
    jcr->NumVolumes = 0;
-   jcr->CurVolume = 1;
+   jcr->CurVolume = 0;
    if (jcr->bsr) {
       BSR *bsr = jcr->bsr;
-      strcpy(jcr->VolumeName, bsr->VolumeName); /* setup first volume */
+      if (!bsr->volume || !bsr->volume->VolumeName) {
+        return;
+      }
       for ( ; bsr; bsr=bsr->next) {
-        vol = new_vol();
-        strcpy(vol->VolumeName, bsr->VolumeName);
-        if (add_vol(jcr, vol)) {
-           jcr->NumVolumes++;
-            Dmsg1(400, "Added volume %s\n", vol->VolumeName);
-        } else {
-            Dmsg1(400, "Duplicate volume %s\n", vol->VolumeName);
-           free((char *)vol);
+        BSR_VOLUME *bsrvol;
+        BSR_VOLFILE *volfile;
+        uint32_t sfile = UINT32_MAX;
+
+        /* Find minimum start file so that we can forward space to it */
+        for (volfile = bsr->volfile; volfile; volfile=volfile->next) {
+           if (volfile->sfile < sfile) {
+              sfile = volfile->sfile;
+           }
+        }
+        /* Now add volumes for this bsr */
+        for (bsrvol = bsr->volume; bsrvol; bsrvol=bsrvol->next) {
+           vol = new_vol();
+           strcpy(vol->VolumeName, bsrvol->VolumeName);
+           vol->start_file = sfile;
+           if (add_vol(jcr, vol)) {
+              jcr->NumVolumes++;
+               Dmsg1(400, "Added volume %s\n", vol->VolumeName);
+           } else {
+               Dmsg1(400, "Duplicate volume %s\n", vol->VolumeName);
+              free((char *)vol);
+           }
+           sfile = 0;                /* start at beginning of second volume */
         }
       }
    } else {