]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
Reorganize dynamically device order in Autochangers to use read-only devices first
authorEric Bollengier <eric@baculasystems.com>
Fri, 25 Feb 2022 17:37:19 +0000 (18:37 +0100)
committerEric Bollengier <eric@baculasystems.com>
Thu, 14 Sep 2023 11:56:59 +0000 (13:56 +0200)
bacula/src/stored/stored.c

index 4212b343634a7524886f585b6043665524fd9c62..37eae86060fa451f964ffdec06929f0c02d78324 100644 (file)
@@ -603,10 +603,30 @@ static int check_resources()
       }
    }
 
+   /* During the device selection, if we put read-only device first,
+    * they will be selected automatically during a restore, so we
+    * reorder the list to keep the device order, but put read-only
+    * devices first.
+    */
    foreach_res(changer, R_AUTOCHANGER) {
+      alist *org_list = changer->device;
+      alist *new_list = New(alist(org_list->size(), not_owned_by_alist));
+      /* We loop two times to keep the order of the devices
+       * per type (readonly/read-write)
+       */
       foreach_alist(device, changer->device) {
          device->cap_bits |= CAP_AUTOCHANGER;
+         if (device->read_only) {
+            new_list->append(device);
+         }
+      }
+      foreach_alist(device, changer->device) {
+         if (!device->read_only) {
+            new_list->append(device);
+         }
       }
+      changer->device = new_list;
+      delete org_list;
    }
 
    CLOUD *cloud;