Skip to content

librgw: Enforce single-call semantics for librgw_create() - #69644

Merged
anrao19 merged 2 commits into
ceph:mainfrom
anoopcs9:fix-librgw-create
Sep 3, 2026
Merged

anrao19 merged 2 commits into
ceph:mainfrom
anoopcs9:fix-librgw-create

Conversation

@anoopcs9

@anoopcs9 anoopcs9 commented Jun 22, 2026 •

Copy link
Copy Markdown
Contributor

librgw_create() is intended to be called once per process. On a second call the init block is skipped but the function still writes a valid handle to *rgw while returning -EINVAL, leaving the caller with an error code and a live handle at the same time.

Make the contract explicit: return -EINVAL with *rgw set to nullptr when librgw_create() is called more than once. Add a test verifying the expected behavior for both the first and subsequent calls.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

@github-actions github-actions Bot added the rgw label Jun 22, 2026
@anoopcs9
anoopcs9 force-pushed the fix-librgw-create branch from 0123592 to 26dec4c Compare June 23, 2026 10:57
@anoopcs9
anoopcs9 marked this pull request as ready for review June 23, 2026 10:59
@anoopcs9
anoopcs9 requested a review from a team as a code owner June 23, 2026 10:59
@anoopcs9

Copy link
Copy Markdown
Contributor Author

jenkins test api

@ivancich

Copy link
Copy Markdown
Member

@anoopcs9 Does this need a needs-review label?

@anoopcs9

Copy link
Copy Markdown
Contributor Author

@anoopcs9 Does this need a needs-review label?

I'm not sure because I've never had to add it before. If that's how it's supposed to be these days, I can add it.

@anoopcs9

anoopcs9 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test api

@ivancich
ivancich self-requested a review August 6, 2026 14:25
Comment thread src/rgw/librgw.cc Resolved
@ivancich

Copy link
Copy Markdown
Member

@mattbenjamin This PR seeks to reverse a design decision from a PR you wrote a decade ago (#7634), specifically this commit 4b42c57. Would you be willing to weigh in?

@anoopcs9 anoopcs9 changed the title librgw: Fix librgw_create() returning -EINVAL on second call librgw: Fix librgw_create/librgw_shutdown lifecycle Aug 11, 2026
@mattbenjamin

mattbenjamin commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

librgw_create() is intended to be called once, because initialization can only be performed once. the "pattern" being adduced by AI is not controlling, if it's even correct. note the pattern is demonstrated in the various unit test programs. and shutdown is similar. what is gained by making many idempotent calls, but requiring them to be balanced? presumptively, I disagree with the logic here.

@anoopcs9

Copy link
Copy Markdown
Contributor Author

librgw_create() is intended to be called once, because initialization can only be performed once. the "pattern" being adduced by AI is not controlling, if it's even correct. note the pattern is demonstrated in the various unit test programs. and shutdown is similar. what is gained by making many idempotent calls, but requiring them to be balanced? presumptively, I disagree with the logic here.

I understand the position that librgw_create() is meant to be called once - the unit tests all follow that pattern.

But the bug isn't really about whether multiple calls should be supported. It's that the current code does two contradictory things on a second call: it returns -EINVAL to signal failure, but it also writes a valid ref-bumped handle to *rgw via g_ceph_context->get(). The caller gets an error code and a live handle at the same time. If second calls are invalid, the function should return the error without handing out a handle - but it doesn't.

I'm happy to drop the refcount commits if the position is that librgw_create() must only be called once. But the first commit still stands as a correctness fix - the function needs to do one thing or the other, not both. If we'd rather enforce single-call semantics, I can change it to return early with an error and not write to *rgw instead.

@mattbenjamin

mattbenjamin commented Aug 12, 2026 •

Copy link
Copy Markdown
Contributor

I agree the intent was that librgw_create() be called once, and librgw_shutdown() called once. If you object to returning the singleton handle if librgw_create() is called more than once, I have no objection to returning nullptr.

@anoopcs9

Copy link
Copy Markdown
Contributor Author

I agree the intent was that librgw_create() be called once, and librgw_shutdown() called once. If you object to returning the singleton handle if librgw_create() is called more than once, I have no objection to returning nullptr.

Makes sense, I'll update the patch to return nullptr on a second call and drop the refcount commits.

For context on the original motivation - in Samba's forking model, each client connection gets its own forked process, and a single client can connect to multiple RGW-backed shares. Each share's tree connect was calling librgw_create(), which meant multiple calls within the same forked process. We ended up building an internal refcount on the Samba side - calling librgw_create() only on the first tree connect and librgw_shutdown() only on the last disconnect - but having it in librgw would have been the natural place for it. That said, single-call semantics with a clear error is a reasonable contract and keeps librgw simple.

@anoopcs9 anoopcs9 changed the title librgw: Fix librgw_create/librgw_shutdown lifecycle librgw: Enforce single-call semantics for librgw_create() Aug 13, 2026
@anoopcs9

anoopcs9 commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor Author

@ivancich @mattbenjamin I've closed tracker #77574 as NOTABUG and removed its references from the commits and PR. Let me know if you think this change needs a backport - if so, I can reopen the tracker.

@anoopcs9
anoopcs9 requested a review from ivancich August 13, 2026 09:14
@ivancich

Copy link
Copy Markdown
Member

Unless your use of this needs backports, I think we can dispense with them. It's not a bug, just a slight modification of behavior.

@ivancich ivancich left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Although the policy is still being developed, it's heading towards documenting the use of AI in creating commits. So please follow the guidelines in the ai-coding-assistants.rst file in this RFC PR: https://github.com/ceph/ceph/pull/66788/changes . Thank you!

librgw_create() is intended to be called once per process. On a second
call g_ceph_context is already set, the init block is skipped, and rc
remains at its initial -EINVAL. However the function still writes a
valid handle to *rgw via g_ceph_context->get(), so the caller receives
an error code and a live handle at the same time.

Make the single-call contract explicit: return -EINVAL with *rgw set to
nullptr when librgw_create() is called more than once.

Signed-off-by: Anoop C S <[email protected]>
Add ceph_test_librgw_file_create which verifies that librgw_create()
succeeds on the first call and returns -EINVAL with a nullptr handle
on a subsequent call within the same process.

Assisted-by: Claude Opus 4.6 (1M context) <[email protected]>
Signed-off-by: Anoop C S <[email protected]>
@anoopcs9

Copy link
Copy Markdown
Contributor Author

Although the policy is still being developed, it's heading towards documenting the use of AI in creating commits. So please follow the guidelines in the ai-coding-assistants.rst file in this RFC PR: https://github.com/ceph/ceph/pull/66788/changes . Thank you!

I've amended the commit wherever appropriate to make the AI assistance explicit.

@anoopcs9
anoopcs9 requested a review from ivancich August 18, 2026 10:38
@ivancich

Copy link
Copy Markdown
Member

@anoopcs9 So this will be picked up for a QA run and we'll go from there. Thank you!

@anrao19

anrao19 commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by anuchaithra started 2026-08-19-07:20.

@anrao19

anrao19 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

This PR has been added to main integration testing by anuchaithra started 2026-08-19-07:20.

pr testing completed and approved by @ivancich , more details in : https://tracker.ceph.com/issues/79605
@anoopcs9 , if no further testing is needed then this pr can be merged

@anoopcs9

anoopcs9 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

This PR has been added to main integration testing by anuchaithra started 2026-08-19-07:20.

pr testing completed and approved by @ivancich , more details in : https://tracker.ceph.com/issues/79605 @anoopcs9 , if no further testing is needed then this pr can be merged

All good from my side, please go for it !

@anrao19
anrao19 merged commit ffcf988 into ceph:main Sep 3, 2026
7 checks passed
@anoopcs9
anoopcs9 deleted the fix-librgw-create branch October 1, 2026 04:57
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.

4 participants