Skip to content

stored: implicitly create autochanger from device with count > 1#2198

Merged
BareosBot merged 35 commits intobareos:masterfrom
florian-at-bareos:dev/fburger/master/implicitly-create-autochanger
Nov 3, 2025
Merged

stored: implicitly create autochanger from device with count > 1#2198
BareosBot merged 35 commits intobareos:masterfrom
florian-at-bareos:dev/fburger/master/implicitly-create-autochanger

Conversation

@florian-at-bareos
Copy link
Contributor

@florian-at-bareos florian-at-bareos commented Mar 3, 2025

Automatically create Autochanger and devices 0000 - Count if the "Device" resource has set a "Count" directive > 1.

The new behaviour of the "Count" directive in the "Device" resource is the following:

  1. If no autochanger is associated with that device, create one named and add the device.
  2. Multiply the device Count + 1 times, starting from 0000. If devices of that name already exist, discard them.
  3. If the device with serial number 0000 was implicitly created in 3. , set "autoselect" to false.
  4. link all serial devices to the autochanger.
  5. If the original device is linked to the autochanger, remove it.

If devices or the autochanger was not implicitly created, a warning is printed.
If the another autochanger which is not associated with the device has the name ,
no autochanger is created even if no autochanger yet exists for that device and a warning is printed..

Thank you for contributing to the Bareos Project!

Please check

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

If you have any questions or problems, please give a comment in the PR.

Helpful documentation and best practices

Checklist for the reviewer of the PR (will be processed by the Bareos team)

Make sure you check/merge the PR using devtools/pr-tool to have some simple automated checks run and a proper changelog record added.

General
  • Is the PR title usable as CHANGELOG entry?
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
  • Correct milestone is set
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR
Tests
  • Decision taken that a test is required (if not, then remove this paragraph)
  • The choice of the type of test (unit test or systemtest) is reasonable
  • Testname matches exactly what is being tested
  • On a fail, output of the test leads quickly to the origin of the fault

@florian-at-bareos florian-at-bareos added this to the 25.0.0 milestone Mar 3, 2025
@florian-at-bareos florian-at-bareos self-assigned this Mar 3, 2025
@florian-at-bareos florian-at-bareos requested a review from arogge March 6, 2025 12:02
@florian-at-bareos florian-at-bareos force-pushed the dev/fburger/master/implicitly-create-autochanger branch from c07a2da to cac6065 Compare March 14, 2025 13:18
@florian-at-bareos
Copy link
Contributor Author

still requires documentation

@bruno-at-bareos bruno-at-bareos self-requested a review March 18, 2025 10:45
@florian-at-bareos florian-at-bareos marked this pull request as ready for review March 19, 2025 14:30
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a quick first look. I found a typo in the docs and the systemtest does not seem to work correctly yet.

@florian-at-bareos florian-at-bareos force-pushed the dev/fburger/master/implicitly-create-autochanger branch from b9d5aa4 to 256fa9d Compare April 9, 2025 08:18
Copy link
Contributor

@bruno-at-bareos bruno-at-bareos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally good, work quite well and being helpful.
Please checks the remarks.

@bruno-at-bareos bruno-at-bareos added the requires no backport This will not be backported label Apr 14, 2025
@florian-at-bareos
Copy link
Contributor Author

florian-at-bareos commented Apr 23, 2025

maybe it is time to split this testrunner to separate start clean default

You think that is necessary? I personally would just leave it as is as long as there is no second testrunner or the file grows too large.

@florian-at-bareos florian-at-bareos force-pushed the dev/fburger/master/implicitly-create-autochanger branch from 256fa9d to 6cb508f Compare April 23, 2025 13:38
@bruno-at-bareos bruno-at-bareos changed the title stored: implicitly create autochanger from device stored: implicitly create autochanger from device with count > 1 May 5, 2025
Copy link
Contributor

@bruno-at-bareos bruno-at-bareos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still to be done:

  • In the documentation, we must also rephrase the :config:option:sd/device/Count option, some of its properties have changed.
  • adapt the changelog

Copy link
Contributor

@bruno-at-bareos bruno-at-bareos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All's good for me, I'll give an approval.
@arogge would you mind to have a recheck for c++ code ?

Copy link
Contributor

@sebsura sebsura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs some more time in the oven. I could very reliably create a crash:

Add an implicit autochanger with 4 devices. Set MaxConcurrentJobs to 10 everywhere. Start 10 concurrent jobs. Then the sd crashes.

This is because the sd tries to use the original device resource, which is not setup correctly (it has changer_res set, but not changer_command; see OpenDevice).

@florian-at-bareos florian-at-bareos requested a review from sebsura May 19, 2025 09:00
@florian-at-bareos florian-at-bareos force-pushed the dev/fburger/master/implicitly-create-autochanger branch from 3746b81 to 3fc4a38 Compare May 20, 2025 15:17
Copy link
Contributor

@sebsura sebsura left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely have a systemtest that actually uses this feature. I imagine the test could check

  1. that the maximum number of running jobs equals the count specified in the resource
  2. that one device was created with autoselect = no
    ...

This test would also make it easier to reproduce bugs as we would not have to set up the environment from scratch every time :)

Im still getting messages like this when running multiple jobs:

2025-06-05 07:51:23 bareos-sd JobId 5: Using Device "FileStorage" (storage) to write.

So im guessing the issue with the extra device is still not fixed. Could you double check that ?

Interestingly the device does not turn up in status sd.

@sebsura
Copy link
Contributor

sebsura commented Jun 5, 2025

*show storage
Storage {
  Name = "File"
  Address = "localhost"
  Port = 30363
  Password = "[md5]519001602a0e85b0fe7dbead5d95d710"
  Device = "FileStorage"
  MediaType = "File"
  AutoChanger = Yes
  MaximumConcurrentJobs = 20
}

$ cat etc/bareos/bareos-sd.d/device/FileStorage.conf 
Device {
  Name = FileStorage
  Media Type = File
  Device Type = File
  Archive Device = storage
  LabelMedia = yes;                   # lets Bareos label unlabeled media
  Random Access = yes;
  AutomaticMount = yes;               # when device opened, read it
  RemovableMedia = no;
  AlwaysOpen = yes;
  Description = "File device. A connecting Director must have the same Name and MediaType."
  Count = 4
}

if you want to try and reproduce this.

@florian-at-bareos florian-at-bareos force-pushed the dev/fburger/master/implicitly-create-autochanger branch from ab96693 to a3a9053 Compare June 10, 2025 14:29
@sebsura sebsura force-pushed the dev/fburger/master/implicitly-create-autochanger branch from a3a9053 to db08ef1 Compare September 22, 2025 08:17
@sebsura sebsura force-pushed the dev/fburger/master/implicitly-create-autochanger branch from cc4c262 to 5e5d429 Compare October 13, 2025 06:14
@sebsura sebsura dismissed their stale review October 30, 2025 09:12

I took over the work, so i cannot review it anymore

florian-at-bareos and others added 22 commits October 31, 2025 08:23
accounting for review suggestions
and add note to changelog about changed behaviour
where the member changer_command is not set
from stored_conf.cc to the AutochangerResource class.
Also add a flag for implicitly created autochangers so they don't get
config-dumped.
This was needed when the Count directive reused the original device for
a copied device. Now that we changed this behaviour, this code is
obsolete.
only its copies should be displayed in the status view
When adding a device with Count > 1 to an AutochangerResource, it is now
printed.
The return value is never checked and other "unused" configs also
simply return true in this case.
Having some kind of error here would be nice, but I am not sure how to
really handle it.
@sebsura sebsura force-pushed the dev/fburger/master/implicitly-create-autochanger branch from c734249 to 50d1444 Compare October 31, 2025 07:23
@sebsura sebsura force-pushed the dev/fburger/master/implicitly-create-autochanger branch from 9ddf237 to 65a3ebc Compare October 31, 2025 09:47
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@BareosBot BareosBot merged commit abe3f01 into bareos:master Nov 3, 2025
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement requires no backport This will not be backported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants