Skip to content

core: make resource/configuration locking safer#1325

Merged
arogge merged 7 commits intobareos:masterfrom
alaaeddineelamri:dev/alaaeddineelamri/master/make-res-locking-safer
Jan 26, 2023
Merged

core: make resource/configuration locking safer#1325
arogge merged 7 commits intobareos:masterfrom
alaaeddineelamri:dev/alaaeddineelamri/master/make-res-locking-safer

Conversation

@alaaeddineelamri
Copy link
Contributor

@alaaeddineelamri alaaeddineelamri commented Dec 1, 2022

Thank you for contributing to the Bareos Project!

Description

When interacting with configuration within the code, we usually need to lock it and then unlock when we finish.
Locking and unlocking is currently done manually, which would increase the risk of locking and forgetting to unlock, or unlocking a config that is not locked.
This PR tries to mitigate that and make configuration locking and unlocking a bit more resilient

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)

General
  • PR name is meaningful
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
  • Check backport line
  • Is the PR title usable as CHANGELOG entry?
  • Separate commit for CHANGELOG.md ("update CHANGELOG.md"). The PR number is correct.
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
  • bareos-check-sources --since-merge does not report any problems

Jmsg(nullptr, M_FATAL, 0,
_("TLS required but not configured in BAREOS.\n"));
UnlockRes(my_config);
;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
;

int64_t StorageId;

LockRes(my_config);

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change

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.

If I did it right, then foreach_res() is now reload-safe. So if you only read the configuration in the loop body and it is basically just

lock();
foreach_res() {}
unlock();

then locking the configuration should not be required anymore.

@alaaeddineelamri alaaeddineelamri marked this pull request as draft December 7, 2022 10:50
@alaaeddineelamri alaaeddineelamri force-pushed the dev/alaaeddineelamri/master/make-res-locking-safer branch 3 times, most recently from 52f94fb to d66fc3c Compare December 14, 2022 12:04
@alaaeddineelamri alaaeddineelamri marked this pull request as ready for review December 14, 2022 13:43
@alaaeddineelamri alaaeddineelamri force-pushed the dev/alaaeddineelamri/master/make-res-locking-safer branch from d66fc3c to bc37afd Compare December 14, 2022 13:44
@alaaeddineelamri alaaeddineelamri force-pushed the dev/alaaeddineelamri/master/make-res-locking-safer branch from bc37afd to 3c8f42a Compare December 28, 2022 08:52
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 guess it makes sense to make ResLocker non-copyable and non-movable. Besides that it looks great.

@alaaeddineelamri alaaeddineelamri force-pushed the dev/alaaeddineelamri/master/make-res-locking-safer branch from 2c0bab0 to 3e4d227 Compare January 20, 2023 09:31
@arogge arogge force-pushed the dev/alaaeddineelamri/master/make-res-locking-safer branch 4 times, most recently from 57b98de to 4e4d665 Compare January 26, 2023 08:50
@arogge arogge force-pushed the dev/alaaeddineelamri/master/make-res-locking-safer branch from 974672b to bf067f6 Compare January 26, 2023 08:53
@arogge arogge merged commit eb2d714 into bareos:master Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants