Skip to content

Commit f6e65ed

Browse files
committed
librbd: get rid of AIO_STATE_CALLBACK in AioCompletion
After commit 002afa0 ("librbd: avoid using lock within AIO completion where possible"), the only method whose behavior would change if AIO_STATE_CALLBACK is removed is is_complete() and it actually needs fixing anyway: because of state != AIO_STATE_PENDING test, is_complete() returns true both for AIO_STATE_CALLBACK and AIO_STATE_COMPLETE, while wait_for_complete() still blocks on AIO_STATE_CALLBACK and returns only on AIO_STATE_COMPLETE. These methods back public APIs, so this inconsistency is exposed to users. If we move to setting state to AIO_STATE_COMPLETE at the top of mark_complete_and_notify() (i.e. before event socket notification), the transient state for callbacks can be eliminated entirely and the inconsistency goes away. Signed-off-by: Ilya Dryomov <[email protected]>
1 parent ed082db commit f6e65ed

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/librbd/io/AioCompletion.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ void AioCompletion::complete() {
9797
}
9898
}
9999

100-
state = AIO_STATE_CALLBACK;
101100
if (complete_cb) {
102101
if (external_callback) {
103102
complete_external_callback();
@@ -238,7 +237,7 @@ void AioCompletion::complete_request(ssize_t r)
238237

239238
bool AioCompletion::is_complete() {
240239
tracepoint(librbd, aio_is_complete_enter, this);
241-
bool done = (this->state != AIO_STATE_PENDING);
240+
bool done = (this->state == AIO_STATE_COMPLETE);
242241
tracepoint(librbd, aio_is_complete_exit, done);
243242
return done;
244243
}
@@ -263,13 +262,13 @@ void AioCompletion::complete_external_callback() {
263262
}
264263

265264
void AioCompletion::mark_complete_and_notify() {
265+
state = AIO_STATE_COMPLETE;
266+
266267
if (ictx != nullptr && event_notify && ictx->event_socket.is_valid()) {
267268
ictx->event_socket_completions.push(this);
268269
ictx->event_socket.notify();
269270
}
270271

271-
state = AIO_STATE_COMPLETE;
272-
273272
{
274273
std::unique_lock<std::mutex> locker(lock);
275274
cond.notify_all();

src/librbd/io/AioCompletion.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ namespace io {
4040
struct AioCompletion {
4141
typedef enum {
4242
AIO_STATE_PENDING = 0,
43-
AIO_STATE_CALLBACK,
4443
AIO_STATE_COMPLETE,
4544
} aio_state_t;
4645

0 commit comments

Comments
 (0)