Skip to content

stored: add AccessMode SD->Device directive to reserve devices exclusively for reading or writing#1464

Merged
BareosBot merged 12 commits intobareos:masterfrom
SamuelBoerlin:read-write-only-devices
Aug 10, 2023
Merged

stored: add AccessMode SD->Device directive to reserve devices exclusively for reading or writing#1464
BareosBot merged 12 commits intobareos:masterfrom
SamuelBoerlin:read-write-only-devices

Conversation

@SamuelBoerlin
Copy link
Contributor

@SamuelBoerlin SamuelBoerlin commented May 10, 2023

Thank you for contributing to the Bareos Project!

Hello, I'm proposing to add a new config directive to SD->Device: AccessMode. The purpose of this directives is to make it possible to reserve devices exclusively for read or write jobs.
My use case is the following: I would like to have a pool which can both be written to (e.g. via virtualfull) and migrated/copied from to another pool at the same time. By reserving at least one device for write jobs only and others for read jobs only, I can ensure that the virtualfull jobs and migration/copy jobs can always run concurrently and don't block each other (unless they want to use same volume).
As far as I can tell, this is currently not possible. Simply adding more devices to the pool would not ensure that there is always a device free for the migration or copy jobs.

Is there interest for such a feature? If so I'd also look into adding tests, updating the relevant docs and diagrams if necessary.

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
  • Check backport line
  • Required backport PRs have been created
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

@arogge
Copy link
Member

arogge commented May 11, 2023

Hi!
Thank you very much for taking the time to work on Bareos.
Your approach looks reasonable, and the feature would really help a lot in the situations where reservation doesn't do the right thing.
We would really like to move forward here.

I guess we'll have some more-or-less picky change requests though :)

@SamuelBoerlin
Copy link
Contributor Author

Hi! Thank you very much for taking the time to work on Bareos. Your approach looks reasonable, and the feature would really help a lot in the situations where reservation doesn't do the right thing. We would really like to move forward here.

I guess we'll have some more-or-less picky change requests though :)

Hi Arogge! That's great to hear. In that case I'll continue working on this some more!
Please, go ahead and let me know about those change requests 👍

@SamuelBoerlin SamuelBoerlin force-pushed the read-write-only-devices branch from e458820 to c275f70 Compare May 18, 2023 13:28
Comment on lines +174 to +175
{"ReadOnly", CFG_TYPE_BOOL, ITEM(res_dev, read_only), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL},
{"WriteOnly", CFG_TYPE_BOOL, ITEM(res_dev, write_only), 0, CFG_ITEM_DEFAULT, "false", NULL, NULL},
Copy link
Member

Choose a reason for hiding this comment

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

I totally understand that you didn't want to add a new type to the configuration parser, but right now with the two booleans we can have four states:

  1. (ReadOnly == false && WriteOnly == false) the old default behaviour
  2. (ReadOnly == true && WriteOnly == false) only use this device for reading
  3. (ReadOnly == false && WriteOnly == true) only use this device for writing
  4. (ReadOnly == true && WriteOnly == true) what does this mean?

So I would argue that we should use one parameter of type IO_DIRECTION to configure this behaviour.
However, I have no thorough idea how to actually name that parameter.

In the process it would probably a good idea to refactor IO_DIRECTION to use "read" and "write" instead of "in" and "out" while retaining backwards compatibility.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, that makes much more sense. I'll look into it.
How about calling it "Access Mode"?

Copy link
Member

Choose a reason for hiding this comment

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

That sounds promising! Maybe then IO_DIRECTION should accept "readonly", "writeonly" and "readwrite", so we would end up with something like:

Access Mode = readonly

in the configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made it use IO_DIRECTION now and changed IO_DIRECTION to also accept read(only)/write(only) and readwrite. Next I'd rename AutoXflateMode and its values since it's no longer specific to the AutoXflate plugin. Am I on the right track with this?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it's definitely a good idea to rename that.

Also, please note that you should rebase your branch onto the latest master.

@SamuelBoerlin SamuelBoerlin force-pushed the read-write-only-devices branch from a8ca576 to 9c414f6 Compare June 30, 2023 15:50
@SamuelBoerlin SamuelBoerlin changed the title stored: add ReadOnly and WriteOnly SD->Device directives to reserve devices for read or write jobs stored: add AccessMode SD->Device directive to reserve devices exclusively for reading or writing Jun 30, 2023
@SamuelBoerlin
Copy link
Contributor Author

I've tried updating the docs but I'm unable to get it to include the new AccessMode directive. Building the docs works fine, it just doesn't include AccessMode for some reason.

@SamuelBoerlin SamuelBoerlin requested a review from arogge July 4, 2023 10:07
@arogge
Copy link
Member

arogge commented Jul 13, 2023

Again, sorry for keeping you waiting so long.
To fix the problem with the docs, you have to build with -Ddocs-build-json=yes and -Dtraymonitor=yes once so the autogenerated configuration schema files get updated. The files will then show up as changed and you can commit them.

Concerning the PR as a whole, I really like the changes. However, I probably won't be able to review/discuss/merge it before my holiday, so it will be waiting till beginning of August. Sorry for that.

@SamuelBoerlin
Copy link
Contributor Author

No problem. My Bareos setup is currently running fine as is, so it's not urgent. But anyways, do you think this can be backported to 22 too, because I'm assuming version 23 would not release until around the end of this/beginning of next year?

Ah I see. I had tried docs-build-json=yes before but couldn't get it to work because I tried running it again a second time with yes, which then removed all those schema files again and errored out:

[100%] Built target clean-docs
Running Sphinx v4.3.2
/mount/bareos/docs/manuals
Traceback (most recent call last):
  File "/mount/bareos/docs/manuals/scripts/generate-resource-descriptions.py", line 497, in <module>
    with open(args.filename) as data_file:
FileNotFoundError: [Errno 2] No such file or directory: 'source/include/autogenerated/bareos-dir-config-schema.json'

Configuration error:
There is a programmable error in your configuration file:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/sphinx/config.py", line 329, in eval_config_file
    exec(code, namespace)
  File "/mount/bareos/docs/manuals/source/conf.py", line 415, in <module>
    subprocess.check_call(
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['scripts/generate-resource-descriptions.py', '--sphinx', 'source/include/autogenerated/bareos-dir-config-schema.json']' returned non-zero exit status 1.

make[3]: *** [docs/manuals/CMakeFiles/docs.dir/build.make:70: docs/manuals/CMakeFiles/docs] Error 2
make[2]: *** [CMakeFiles/Makefile2:6529: docs/manuals/CMakeFiles/docs.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:6536: docs/manuals/CMakeFiles/docs.dir/rule] Error 2
make: *** [Makefile:2176: docs] Error 2

Now it works, but I'm getting the following diffs which seems a bit odd. Should those paths really change? Or should I just commit the AccessMode entry?

[100%] Comparing json files in "/mount/bareos/docs/manuals/source/include/autogenerated" with git repo
 .../include/autogenerated/bareos-dir-config-schema.json       |  2 +-
 .../source/include/autogenerated/bareos-fd-config-schema.json |  4 ++--
 .../source/include/autogenerated/bareos-sd-config-schema.json | 11 +++++++++--
 docs/manuals/source/include/autogenerated/usage/bconsole.txt  |  6 ------
 4 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/docs/manuals/source/include/autogenerated/bareos-dir-config-schema.json b/docs/manuals/source/include/autogenerated/bareos-dir-config-schema.json
index 526ed6cd4..cf45d8fc3 100644
--- a/docs/manuals/source/include/autogenerated/bareos-dir-config-schema.json
+++ b/docs/manuals/source/include/autogenerated/bareos-dir-config-schema.json
@@ -54,7 +54,7 @@
         "WorkingDirectory": {
           "datatype": "DIRECTORY",
           "code": 0,
-          "default_value": "/var/lib/bareos",
+          "default_value": "/usr/local/var/lib/bareos",
           "platform_specific": true,
           "equals": true
         },
diff --git a/docs/manuals/source/include/autogenerated/bareos-fd-config-schema.json b/docs/manuals/source/include/autogenerated/bareos-fd-config-schema.json
index 596e0f573..172f3df03 100644
--- a/docs/manuals/source/include/autogenerated/bareos-fd-config-schema.json
+++ b/docs/manuals/source/include/autogenerated/bareos-fd-config-schema.json
@@ -198,7 +198,7 @@
         "WorkingDirectory": {
           "datatype": "DIRECTORY",
           "code": 0,
-          "default_value": "/var/lib/bareos",
+          "default_value": "/usr/local/var/lib/bareos",
           "platform_specific": true,
           "equals": true
         },
@@ -465,7 +465,7 @@
         "WorkingDirectory": {
           "datatype": "DIRECTORY",
           "code": 0,
-          "default_value": "/var/lib/bareos",
+          "default_value": "/usr/local/var/lib/bareos",
           "platform_specific": true,
           "equals": true
         },
diff --git a/docs/manuals/source/include/autogenerated/bareos-sd-config-schema.json b/docs/manuals/source/include/autogenerated/bareos-sd-config-schema.json
index b5aae5ebb..473c0d71b 100644
--- a/docs/manuals/source/include/autogenerated/bareos-sd-config-schema.json
+++ b/docs/manuals/source/include/autogenerated/bareos-sd-config-schema.json
@@ -198,14 +198,14 @@
         "WorkingDirectory": {
           "datatype": "DIRECTORY",
           "code": 0,
-          "default_value": "/var/lib/bareos",
+          "default_value": "/usr/local/var/lib/bareos",
           "platform_specific": true,
           "equals": true
         },
         "BackendDirectory": {
           "datatype": "DIRECTORY_LIST",
           "code": 0,
-          "default_value": "/usr/lib/bareos/backends",
+          "default_value": "/usr/local/lib/bareos/backends",
           "platform_specific": true,
           "equals": true
         },
@@ -641,6 +641,13 @@
           "default_value": "on",
           "equals": true
         },
+        "AccessMode": {
+          "datatype": "IO_DIRECTION",
+          "code": 0,
+          "default_value": "readwrite",
+          "equals": true,
+          "description": "Access mode specifies whetherthis device can be used for reading, writing or for both modes."
+        },
         "AutoSelect": {
           "datatype": "BOOLEAN",
           "code": 0,
diff --git a/docs/manuals/source/include/autogenerated/usage/bconsole.txt b/docs/manuals/source/include/autogenerated/usage/bconsole.txt
index 53a19ed0c..04aadfb72 100644
--- a/docs/manuals/source/include/autogenerated/usage/bconsole.txt
+++ b/docs/manuals/source/include/autogenerated/usage/bconsole.txt
@@ -22,12 +22,6 @@ Options:
     -l,--list-directors
         List defined Directors.

-    -p,--pam-credentials-filename <path>:FILE
-        PAM Credentials file.
-
-    -o
-        Force sending pam credentials unencrypted.
-
     -s,--no-signals
         No signals (for debugging)

make[3]: *** [docs/manuals/CMakeFiles/check-git.dir/build.make:89: docs/manuals/CMakeFiles/check-git] Error 1
make[2]: *** [CMakeFiles/Makefile2:6476: docs/manuals/CMakeFiles/check-git.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:6536: docs/manuals/CMakeFiles/docs.dir/rule] Error 2
make: *** [Makefile:2176: docs] Error 2

@arogge
Copy link
Member

arogge commented Jul 13, 2023

It may be possible to Backport this to 22. However, our plan is to release 23.0.0 earlier than at the end of the year.

Concerning the schema files: now you know why recreating them is not enabled by default. I think you can just git add -p and select the hunk that's relevant for you.

@SamuelBoerlin
Copy link
Contributor Author

Okay, thanks!

@SamuelBoerlin SamuelBoerlin force-pushed the read-write-only-devices branch from d9835df to f9377b6 Compare July 13, 2023 10:50
int oflags{}; /**< Read/write flags */
DeviceMode open_mode{DeviceMode::kUndefined};
std::string device_type{};
IODirection access_mode{}; /**< Allowed access mode(s) for reservation */
Copy link
Member

Choose a reason for hiding this comment

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

this should probably be inizialized to READ_WRITE

Copy link
Contributor Author

@SamuelBoerlin SamuelBoerlin Jul 13, 2023

Choose a reason for hiding this comment

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

That makes sense.
Done.

@arogge arogge force-pushed the read-write-only-devices branch from a6d5b0a to b01e08f Compare August 9, 2023 10:30
@arogge
Copy link
Member

arogge commented Aug 9, 2023

We discussed the backporting internally. Sadly we won't backport this feature to Bareos 22. You'll have to stick with a patched version or run Bareos Next until the release of Bareos 23 (which shouldn't take too long from now)

@SamuelBoerlin
Copy link
Contributor Author

We discussed the backporting internally. Sadly we won't backport this feature to Bareos 22. You'll have to stick with a patched version or run Bareos Next until the release of Bareos 23 (which shouldn't take too long from now)

Thanks - that's ok, I understand. Looking forward to Bareos 23.

@BareosBot BareosBot force-pushed the read-write-only-devices branch from 8b8047d to 7fe96ea Compare August 10, 2023 13:07
@BareosBot BareosBot merged commit 44db38c into bareos:master Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants