1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2012 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #ifndef CEPH_LIBRADOS_AIOCOMPLETIONIMPL_H
16 #define CEPH_LIBRADOS_AIOCOMPLETIONIMPL_H
18 #include "common/Cond.h"
19 #include "common/Mutex.h"
21 #include "include/buffer.h"
22 #include "include/rados/librados.h"
23 #include "include/rados/librados.hpp"
24 #include "include/xlist.h"
25 #include "osd/osd_types.h"
29 struct librados::AioCompletionImpl
{
38 rados_callback_t callback_complete
, callback_safe
;
39 void *callback_complete_arg
, *callback_safe_arg
;
48 ceph_tid_t aio_write_seq
;
49 xlist
<AioCompletionImpl
*>::item aio_write_list_item
;
51 AioCompletionImpl() : lock("AioCompletionImpl lock", false, false),
52 ref(1), rval(0), released(false),
58 callback_complete_arg(0),
60 is_read(false), blp(nullptr), out_buf(nullptr),
61 io(NULL
), aio_write_seq(0), aio_write_list_item(this) { }
63 int set_complete_callback(void *cb_arg
, rados_callback_t cb
) {
65 callback_complete
= cb
;
66 callback_complete_arg
= cb_arg
;
70 int set_safe_callback(void *cb_arg
, rados_callback_t cb
) {
73 callback_safe_arg
= cb_arg
;
77 int wait_for_complete() {
85 return wait_for_complete();
96 int wait_for_complete_and_cb() {
98 while (!complete
|| callback_complete
|| callback_safe
)
103 int wait_for_safe_and_cb() {
104 return wait_for_complete_and_cb();
106 int is_complete_and_cb() {
108 int r
= complete
&& !callback_complete
&& !callback_safe
;
112 int is_safe_and_cb() {
113 return is_complete_and_cb();
115 int get_return_value() {
121 uint64_t get_version() {
123 version_t v
= objver
;
134 assert(lock
.is_locked());
158 struct C_AioComplete
: public Context
{
159 AioCompletionImpl
*c
;
161 explicit C_AioComplete(AioCompletionImpl
*cc
) : c(cc
) {
165 void finish(int r
) override
{
166 rados_callback_t cb_complete
= c
->callback_complete
;
167 void *cb_complete_arg
= c
->callback_complete_arg
;
169 cb_complete(c
, cb_complete_arg
);
171 rados_callback_t cb_safe
= c
->callback_safe
;
172 void *cb_safe_arg
= c
->callback_safe_arg
;
174 cb_safe(c
, cb_safe_arg
);
177 c
->callback_complete
= NULL
;
178 c
->callback_safe
= NULL
;
185 * Fills in all completed request data, and calls both
186 * complete and safe callbacks if they exist.
188 * Not useful for usual I/O, but for special things like
189 * flush where we only want to wait for things to be safe,
190 * but allow users to specify any of the callbacks.
192 struct C_AioCompleteAndSafe
: public Context
{
193 AioCompletionImpl
*c
;
195 explicit C_AioCompleteAndSafe(AioCompletionImpl
*cc
) : c(cc
) {
199 void finish(int r
) override
{
205 rados_callback_t cb_complete
= c
->callback_complete
;
206 void *cb_complete_arg
= c
->callback_complete_arg
;
208 cb_complete(c
, cb_complete_arg
);
210 rados_callback_t cb_safe
= c
->callback_safe
;
211 void *cb_safe_arg
= c
->callback_safe_arg
;
213 cb_safe(c
, cb_safe_arg
);
216 c
->callback_complete
= NULL
;
217 c
->callback_safe
= NULL
;