Project

General

Profile

Actions

Bug #77574

closed
AC AC

librgw_create() returns -EINVAL on second call when g_ceph_context is already initialized

Bug #77574: librgw_create() returns -EINVAL on second call when g_ceph_context is already initialized

Added by Anoop C S 5 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
-
Due date:
% Done:

0%

Source:
Backport:
Regression:
No
Severity:
2 - major
Reviewed:
Affected Versions:
ceph-qa-suite:
rgw
Pull request ID:
Tags (freeform):
Merge Commit:
Fixed In:
Released In:
Upkeep Timestamp:
2026-09-03T11:55:21+00:00

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

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

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

librgw_second_create.c (748 Bytes) librgw_second_create.c Anoop C S, 06/22/2026 04:09 PM

AC Updated by Anoop C S 5 months ago Actions #1

  • Pull request ID set to 69644

JI Updated by J. Eric Ivancich 5 months ago Actions #2

  • Status changed from New to In Progress

JI Updated by J. Eric Ivancich 5 months ago Actions #3

  • Assignee set to Anoop C S

AC Updated by Anoop C S 5 months ago Actions #4

  • Status changed from In Progress to Fix Under Review

AC Updated by Anoop C S 4 months ago Actions #5

  • 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 Actions #6

  • Upkeep Timestamp set to 2026-09-03T11:55:21+00:00
Actions

Also available in: PDF Atom