]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Fix #7375 About extending bls
authorMichal Rakowski <michal.rakowski@baculasystems.com>
Fri, 16 Apr 2021 06:17:18 +0000 (08:17 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 24 Mar 2022 08:03:01 +0000 (09:03 +0100)
Extend bls with number of retries when specifying incorrect Volume.

bacula/src/stored/acquire.c
bacula/src/stored/bextract.c
bacula/src/stored/bls.c
bacula/src/stored/butil.c
bacula/src/stored/protos.h

index a94da236fa9b98aa93a7157da2b66e905af63eb5..b1436ced18b9ab12c06aa9153c9d870a7eff0c77 100644 (file)
@@ -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 */
index 1be559912d8b64e1cfc8c316fefefc8a70a3632d..44a74ffbd9e3c3a87b8e2c951e4ee852d8b38ff1 100644 (file)
@@ -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);
    }
index ba95c62b0081c2157d8e9937203486f804ac4c1f..be7df2c0cc15d093a81d6914509655fb26306672 100644 (file)
@@ -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);
       }
index 7424aaa0b9ed2176e520a3a96ea21a2abaedbf52..58bc95a8f7b9d6bfe29eb9dc333ab507fee6c21d 100644 (file)
@@ -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;
index 0d747a599f02e17f872597fcef4ca5bf496361ef..dce4a6668367003232734c4998c58c9ebce87ab8 100644 (file)
@@ -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);