X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Fstored%2Fparse_bsr.c;h=4ff019b30c51ef272ebfef784fd06f822c736c10;hb=dc43fa5c6823b93c4206888e3bf639982af4563b;hp=91ee185c11212564eb33e9598a20469b232c1da9;hpb=f593d1be2383ca6ff2972de8def13749f6992c4d;p=bacula%2Fbacula diff --git a/bacula/src/stored/parse_bsr.c b/bacula/src/stored/parse_bsr.c index 91ee185c11..4ff019b30c 100755 --- a/bacula/src/stored/parse_bsr.c +++ b/bacula/src/stored/parse_bsr.c @@ -35,25 +35,35 @@ 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); +static BSR *store_stream(LEX *lc, BSR *bsr); +static BSR *store_slot(LEX *lc, BSR *bsr); +static bool is_fast_rejection_ok(BSR *bsr); +static bool is_positioning_ok(BSR *bsr); struct kw_items { - char *name; + const char *name; 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}, @@ -62,44 +72,78 @@ struct kw_items items[] = { {"include", store_include}, {"exclude", store_exclude}, {"volfile", store_volfile}, + {"volblock", store_volblock}, + {"stream", store_stream}, + {"slot", store_slot}, {NULL, NULL} }; -static BSR *new_bsr() +/* + * Create a BSR record + */ +static BSR *new_bsr() { BSR *bsr = (BSR *)malloc(sizeof(BSR)); memset(bsr, 0, sizeof(BSR)); return bsr; } +/* + * Format a scanner error message + */ +static void s_err(const char *file, int line, LEX *lc, const char *msg, ...) +{ + JCR *jcr = (JCR *)(lc->caller_ctx); + va_list arg_ptr; + char buf[MAXSTRING]; + + va_start(arg_ptr, msg); + bvsnprintf(buf, sizeof(buf), msg, arg_ptr); + va_end(arg_ptr); + + 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); + } +} + + /********************************************************************* * * Parse Bootstrap file * */ -BSR *parse_bsr(char *cf) +BSR *parse_bsr(JCR *jcr, char *fname) { LEX *lc = NULL; int token, i; BSR *root_bsr = new_bsr(); BSR *bsr = root_bsr; - - Dmsg0(200, "Enter parse_bsf()\n"); - lc = lex_open_file(lc, cf); + + Dmsg1(200, "Enter parse_bsf %s\n", fname); + lc = lex_open_file(lc, fname, 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; @@ -107,27 +151,99 @@ 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) { + break; } - } lc = lex_close_file(lc); Dmsg0(200, "Leave parse_bsf()\n"); + if (!bsr) { + free_bsr(root_bsr); + root_bsr = NULL; + } + if (root_bsr) { + root_bsr->use_fast_rejection = is_fast_rejection_ok(root_bsr); + root_bsr->use_positioning = is_positioning_ok(root_bsr); + } + for (bsr=root_bsr; bsr; bsr=bsr->next) { + bsr->root = root_bsr; + } return root_bsr; } +static bool is_fast_rejection_ok(BSR *bsr) +{ + /* + * Although, this can be optimized, for the moment, require + * all bsrs to have both sesstime and sessid set before + * we do fast rejection. + */ + if (!(bsr->sesstime && bsr->sessid)) { + return false; + } + if (bsr->next) { + return is_fast_rejection_ok(bsr->next); + } + return true; +} + +static bool is_positioning_ok(BSR *bsr) +{ + /* + * Every bsr should have a volfile entry and a volblock entry + * if we are going to use positioning + */ + if (!bsr->volfile || !bsr->volblock) { + return false; + } + if (bsr->next) { + return is_positioning_ok(bsr->next); + } + return true; +} + + static BSR *store_vol(LEX *lc, BSR *bsr) { int token; + BSR_VOLUME *volume; + char *p, *n; - token = lex_get_token(lc, T_NAME); - if (bsr->VolumeName) { + token = lex_get_token(lc, T_STRING); + if (token == T_ERROR) { + return NULL; + } + 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)); + bstrncpy(volume->VolumeName, p, sizeof(volume->VolumeName)); + /* 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; } @@ -138,9 +254,12 @@ static BSR *store_client(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_NAME); + if (token == T_ERROR) { + return NULL; + } client = (BSR_CLIENT *)malloc(sizeof(BSR_CLIENT)); memset(client, 0, sizeof(BSR_CLIENT)); - client->ClientName = bstrdup(lc->str); + bstrncpy(client->ClientName, lc->str, sizeof(client->ClientName)); /* Add it to the end of the client chain */ if (!bsr->client) { bsr->client = client; @@ -165,9 +284,12 @@ static BSR *store_job(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_NAME); + if (token == T_ERROR) { + return NULL; + } job = (BSR_JOB *)malloc(sizeof(BSR_JOB)); memset(job, 0, sizeof(BSR_JOB)); - job->Job = bstrdup(lc->str); + bstrncpy(job->Job, lc->str, sizeof(job->Job)); /* Add it to the end of the client chain */ if (!bsr->job) { bsr->job = job; @@ -193,6 +315,9 @@ static BSR *store_findex(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32_RANGE); + if (token == T_ERROR) { + return NULL; + } findex = (BSR_FINDEX *)malloc(sizeof(BSR_FINDEX)); memset(findex, 0, sizeof(BSR_FINDEX)); findex->findex = lc->pint32_val; @@ -223,6 +348,9 @@ static BSR *store_jobid(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32_RANGE); + if (token == T_ERROR) { + return NULL; + } jobid = (BSR_JOBID *)malloc(sizeof(BSR_JOBID)); memset(jobid, 0, sizeof(BSR_JOBID)); jobid->JobId = lc->pint32_val; @@ -245,6 +373,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****** */ @@ -273,6 +416,9 @@ static BSR *store_volfile(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32_RANGE); + if (token == T_ERROR) { + return NULL; + } volfile = (BSR_VOLFILE *)malloc(sizeof(BSR_VOLFILE)); memset(volfile, 0, sizeof(BSR_VOLFILE)); volfile->sfile = lc->pint32_val; @@ -296,6 +442,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) { @@ -304,6 +485,9 @@ static BSR *store_sessid(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32_RANGE); + if (token == T_ERROR) { + return NULL; + } sid = (BSR_SESSID *)malloc(sizeof(BSR_SESSID)); memset(sid, 0, sizeof(BSR_SESSID)); sid->sessid = lc->pint32_val; @@ -333,6 +517,9 @@ static BSR *store_sesstime(LEX *lc, BSR *bsr) for (;;) { token = lex_get_token(lc, T_PINT32); + if (token == T_ERROR) { + return NULL; + } stime = (BSR_SESSTIME *)malloc(sizeof(BSR_SESSTIME)); memset(stime, 0, sizeof(BSR_SESSTIME)); stime->sesstime = lc->pint32_val; @@ -354,6 +541,51 @@ static BSR *store_sesstime(LEX *lc, BSR *bsr) return bsr; } + +static BSR *store_stream(LEX *lc, BSR *bsr) +{ + int token; + BSR_STREAM *stream; + + for (;;) { + token = lex_get_token(lc, T_INT32); + if (token == T_ERROR) { + return NULL; + } + stream = (BSR_STREAM *)malloc(sizeof(BSR_STREAM)); + memset(stream, 0, sizeof(BSR_STREAM)); + stream->stream = lc->int32_val; + /* Add it to the end of the chain */ + if (!bsr->stream) { + bsr->stream = stream; + } else { + /* Add to end of chain */ + BSR_STREAM *bs = bsr->stream; + for ( ;bs->next; bs=bs->next) + { } + bs->next = stream; + } + token = lex_get_token(lc, T_ALL); + if (token != T_COMMA) { + break; + } + } + return bsr; +} + +static BSR *store_slot(LEX *lc, BSR *bsr) +{ + int token; + + token = lex_get_token(lc, T_PINT32); + if (token == T_ERROR) { + return NULL; + } + bsr->Slot = lc->pint32_val; + scan_to_eol(lc); + return bsr; +} + static BSR *store_include(LEX *lc, BSR *bsr) { scan_to_eol(lc); @@ -374,6 +606,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) { @@ -410,6 +651,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) { @@ -439,28 +688,42 @@ void dump_sesstime(BSR_SESSTIME *sesstime) -void dump_bsr(BSR *bsr) +void dump_bsr(BSR *bsr, bool recurse) { + int save_debug = debug_level; + debug_level = 1; if (!bsr) { Dmsg0(-1, "BSR is NULL\n"); + debug_level = save_debug; 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); + Dmsg1(-1, "Root bsr : 0x%x\n", bsr->root); + 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->next) { + if (bsr->Slot) { + Dmsg1(-1, "Slot : %u\n", bsr->Slot); + } + if (bsr->count) { + Dmsg1(-1, "count : %u\n", bsr->count); + Dmsg1(-1, "found : %u\n", bsr->found); + } + + Dmsg1(-1, "done : %s\n", bsr->done?"yes":"no"); + Dmsg1(-1, "positioning : %d\n", bsr->use_positioning); + Dmsg1(-1, "fast_reject : %d\n", bsr->use_fast_rejection); + if (recurse && bsr->next) { Dmsg0(-1, "\n"); - dump_bsr(bsr->next); + dump_bsr(bsr->next, true); } + debug_level = save_debug; } @@ -483,18 +746,138 @@ 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); } + +/***************************************************************** + * Routines for handling volumes + */ +VOL_LIST *new_vol() +{ + VOL_LIST *vol; + vol = (VOL_LIST *)malloc(sizeof(VOL_LIST)); + memset(vol, 0, sizeof(VOL_LIST)); + return vol; +} + +/* + * Add current volume to end of list, only if the Volume + * is not already in the list. + * + * returns: 1 if volume added + * 0 if volume already in list + */ +int add_vol(JCR *jcr, VOL_LIST *vol) +{ + VOL_LIST *next = jcr->VolList; + + if (!next) { /* list empty ? */ + jcr->VolList = vol; /* yes, add volume */ + } 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 */ + } + return 1; +} + +void free_vol_list(JCR *jcr) +{ + VOL_LIST *next = jcr->VolList; + VOL_LIST *tmp; + + for ( ; next; ) { + tmp = next->next; + 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 volumes to be processed + */ + jcr->NumVolumes = 0; + jcr->CurVolume = 0; + if (jcr->bsr) { + BSR *bsr = jcr->bsr; + if (!bsr->volume || !bsr->volume->VolumeName) { + return; + } + for ( ; bsr; bsr=bsr->next) { + 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(); + bstrncpy(vol->VolumeName, bsrvol->VolumeName, sizeof(vol->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 { + /* This is the old way -- deprecated */ + for (p = jcr->dcr->VolumeName; p && *p; ) { + n = strchr(p, '|'); /* volume name separator */ + if (n) { + *n++ = 0; /* Terminate name */ + } + vol = new_vol(); + bstrncpy(vol->VolumeName, p, sizeof(vol->VolumeName)); + if (add_vol(jcr, vol)) { + jcr->NumVolumes++; + } else { + free((char *)vol); + } + p = n; + } + } +}