From: Michal Rakowski Date: Fri, 16 Apr 2021 06:17:18 +0000 (+0200) Subject: Fix #7375 About extending bls X-Git-Tag: Release-11.3.2~581 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=968b6b68b1c7849d22fea7a60d748244d96ecef7;p=thirdparty%2Fbacula.git Fix #7375 About extending bls Extend bls with number of retries when specifying incorrect Volume. --- diff --git a/bacula/src/stored/acquire.c b/bacula/src/stored/acquire.c index a94da236f..b1436ced1 100644 --- a/bacula/src/stored/acquire.c +++ b/bacula/src/stored/acquire.c @@ -39,7 +39,7 @@ static void set_dcr_from_vol(DCR *dcr, VOL_LIST *vol); * Returns: false if failed for any reason * true if successful */ -bool acquire_device_for_read(DCR *dcr) +bool acquire_device_for_read(DCR *dcr, uint32_t retry_count) { DEVICE *dev; JCR *jcr = dcr->jcr; @@ -49,7 +49,7 @@ bool acquire_device_for_read(DCR *dcr) bool try_autochanger = true; int i; int vol_label_status; - int retry = 0; + uint32_t retry = 0; Enter(rdbglvl); dev = dcr->dev; @@ -207,7 +207,7 @@ bool acquire_device_for_read(DCR *dcr) for ( ;; ) { /* If not polling limit retries */ - if (!dev->poll && retry++ > 10) { + if (!dev->poll && retry++ >= retry_count) { break; } dev->clear_labeled(); /* force reread of label */ diff --git a/bacula/src/stored/bextract.c b/bacula/src/stored/bextract.c index 1be559912..44a74ffbd 100644 --- a/bacula/src/stored/bextract.c +++ b/bacula/src/stored/bextract.c @@ -252,7 +252,7 @@ static void do_extract(char *devname) enable_backup_privileges(NULL, 1); - jcr = setup_jcr("bextract", devname, bsr, VolumeName, SD_READ, true/*read dedup data*/); + jcr = setup_jcr("bextract", devname, bsr, VolumeName, SD_READ, true/*read dedup data*/, 10/*retry count*/); if (!jcr) { exit(1); } diff --git a/bacula/src/stored/bls.c b/bacula/src/stored/bls.c index ba95c62b0..be7df2c0c 100644 --- a/bacula/src/stored/bls.c +++ b/bacula/src/stored/bls.c @@ -47,6 +47,7 @@ static DEV_RECORD *rec; static JCR *jcr; static SESSION_LABEL sessrec; static uint32_t num_files = 0; +static uint32_t retry_count = 10; static ATTR *attr; static CONFIG *config; @@ -82,6 +83,7 @@ PROG_COPYRIGHT " -j list jobs\n" " -k list blocks\n" " (no j or k option) list saved files\n" +" -n number of times user is aked to provide correct volume\n" " -L dump label\n" " -p proceed inspite of errors\n" " -V specify Volume names (separated by |)\n" @@ -119,7 +121,7 @@ int main (int argc, char *argv[]) ff = init_find_files(); - while ((ch = getopt(argc, argv, "b:c:d:e:i:jkLpvV:?EDF:")) != -1) { + while ((ch = getopt(argc, argv, "b:c:d:e:i:n:jkLpvV:?EDF:")) != -1) { switch (ch) { case 'b': bsrName = optarg; @@ -193,6 +195,9 @@ int main (int argc, char *argv[]) list_blocks = true; break; + case 'n': + retry_count = atoi(optarg); + break; case 'L': dump_label = true; break; @@ -253,7 +258,7 @@ int main (int argc, char *argv[]) if (bsrName) { bsr = parse_bsr(NULL, bsrName); } - jcr = setup_jcr("bls", argv[i], bsr, VolumeName, SD_READ); + jcr = setup_jcr("bls", argv[i], bsr, VolumeName, SD_READ, false/*read dedup data*/, retry_count); if (!jcr) { exit(1); } diff --git a/bacula/src/stored/butil.c b/bacula/src/stored/butil.c index 7424aaa0b..58bc95a8f 100644 --- a/bacula/src/stored/butil.c +++ b/bacula/src/stored/butil.c @@ -34,7 +34,7 @@ /* Forward referenced functions */ static DCR *setup_to_access_device(JCR *jcr, char *dev_name, - const char *VolumeName, bool writing, bool read_dedup_data); + const char *VolumeName, bool writing, bool read_dedup_data, uint32_t retry_count=10); static DEVRES *find_device_res(char *device_name, bool writing); static void my_free_jcr(JCR *jcr); @@ -88,7 +88,7 @@ void setup_me() * tools (e.g. bls, bextract, bscan, ...) */ JCR *setup_jcr(const char *name, char *dev_name, BSR *bsr, - const char *VolumeName, bool writing, bool read_dedup_data) + const char *VolumeName, bool writing, bool read_dedup_data, uint32_t retry_count) { DCR *dcr; JCR *jcr = new_jcr(sizeof(JCR), my_free_jcr); @@ -114,7 +114,7 @@ JCR *setup_jcr(const char *name, char *dev_name, BSR *bsr, init_autochangers(); create_volume_lists(); - dcr = setup_to_access_device(jcr, dev_name, VolumeName, writing, read_dedup_data); + dcr = setup_to_access_device(jcr, dev_name, VolumeName, writing, read_dedup_data, retry_count); if (!dcr) { return NULL; } @@ -132,7 +132,7 @@ JCR *setup_jcr(const char *name, char *dev_name, BSR *bsr, * the caller will do it. */ static DCR *setup_to_access_device(JCR *jcr, char *dev_name, - const char *VolumeName, bool writing, bool read_dedup_data) + const char *VolumeName, bool writing, bool read_dedup_data, uint32_t retry_count) { DEVICE *dev; char *p; @@ -190,7 +190,7 @@ static DCR *setup_to_access_device(JCR *jcr, char *dev_name, if (!writing) { /* read only access? */ Dmsg0(100, "Acquire device for read\n"); - if (!acquire_device_for_read(dcr)) { + if (!acquire_device_for_read(dcr, retry_count)) { return NULL; } jcr->read_dcr = dcr; diff --git a/bacula/src/stored/protos.h b/bacula/src/stored/protos.h index 0d747a599..dce4a6668 100644 --- a/bacula/src/stored/protos.h +++ b/bacula/src/stored/protos.h @@ -27,7 +27,7 @@ uint32_t new_VolSessionId(); /* From acquire.c */ DCR *acquire_device_for_append(DCR *dcr); -bool acquire_device_for_read(DCR *dcr); +bool acquire_device_for_read(DCR *dcr, uint32_t retry_count=10); bool release_device(DCR *dcr); bool clean_device(DCR *dcr); DCR *new_dcr(JCR *jcr, DCR *dcr, DEVICE *dev, bool writing=true); @@ -139,7 +139,7 @@ bool is_pool_size_reached(DCR *dcr, bool quiet); void setup_me(); void print_ls_output(const char *fname, const char *link, int type, struct stat *statp); JCR *setup_jcr(const char *name, char *dev_name, BSR *bsr, - const char *VolumeName, bool writing, bool read_dedup_data=true); + const char *VolumeName, bool writing, bool read_dedup_data=true, uint32_t retry_count=10); void display_tape_error_status(JCR *jcr, DEVICE *dev);