Bug #77574
closedlibrgw_create() returns -EINVAL on second call when g_ceph_context is already initialized
0%
Description
In librgw_create(), the return code variable rc is initialized to -EINVAL. On the first call, g_ceph_context@ is NULL, so the initialization block runs and overwrites rc with the result of rgwlib.init(). On any subsequent call within the same process, g_ceph_context@ is already set, the initialization block is skipped, and rc stays at -EINVAL causing the caller to see a spurious failure.
This makes it impossible for any consumer of librgw to call librgw_create() more than once in the same process.
Steps to Reproduce¶
Compile and run the attached standalone C reproducer below against a cluster with RGW:
# gcc librgw_second_create.c -lrgw
Expected results
# ./a.out
¶
# ./a.out
First librgw_create()...OK
Second librgw_create()...OK
Both calls succeeded
2026-06-22T21:32:51.054+0530 7f99c1c7a100 -1 shutting down
2026-06-22T21:32:51.061+0530 7f98715ca6c0 -1 received signal: User defined signal 1, si_code : -6, si_value (int): 0, si_value (ptr): 0, si_errno: 0, si_pid : 194672, si_uid : 0, si_addr0x2f870, si_status0
Actual results
# ./a.out
¶
# ./a.out
First librgw_create()...OK
Second librgw_create()...FAILED (ret=-22, Invalid argument)
2026-06-22T21:34:23.219+0530 7fc80037a100 -1 shutting down
2026-06-22T21:34:23.264+0530 7fc6b1dcb6c0 -1 received signal: User defined signal 1, si_code : -6, si_value (int): 0, si_value (ptr): 0, si_errno: 0, si_pid : 196865, si_uid : 0, si_addr0x30101, si_status0
Files
JI Updated by J. Eric Ivancich 5 months ago
- Status changed from New to In Progress
JI Updated by J. Eric Ivancich 5 months ago
- Assignee set to Anoop C S
AC Updated by Anoop C S 4 months ago
- Status changed from Fix Under Review to Closed
Closing as NOTABUG. After discussion on the PR, the consensus is that librgw_create() is intended to be called once per process and returning -EINVAL on a subsequent call is the correct behavior. The only issue was that the function also handed out a valid handle alongside the error, which has been proposed (https://github.com/ceph/ceph/pull/69644) to be fixed by returning nullptr instead. Consumers that need multiple handles within the same process should manage their own lifecycle (call librgw_create() once and refcount internally).
UB Updated by Upkeep Bot 3 months ago
- Upkeep Timestamp set to 2026-09-03T11:55:21+00:00