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) 2014 Sebastien Ponce <sebastien.ponce@cern.ch>
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_LIBRADOSSTRIPERSTRIPER_MULTIAIOCOMPLETIONIMPL_H
16 #define CEPH_LIBRADOSSTRIPERSTRIPER_MULTIAIOCOMPLETIONIMPL_H
18 #include "common/Cond.h"
19 #include "common/Mutex.h"
21 #include "include/radosstriper/libradosstriper.hpp"
23 struct libradosstriper::MultiAioCompletionImpl
{
28 int pending_complete
, pending_safe
;
29 rados_callback_t callback_complete
, callback_safe
;
30 void *callback_complete_arg
, *callback_safe_arg
;
31 bool building
; ///< true if we are still building this completion
32 bufferlist bl
; /// only used for read case in C api of rados striper
33 std::list
<bufferlist
*> bllist
; /// keep temporary buffer lists used for destriping
35 MultiAioCompletionImpl() : lock("MultiAioCompletionImpl lock", false, false),
37 pending_complete(0), pending_safe(0),
38 callback_complete(0), callback_safe(0),
39 callback_complete_arg(0), callback_safe_arg(0),
42 ~MultiAioCompletionImpl() {
43 // deallocate temporary buffer lists
44 for (std::list
<bufferlist
*>::iterator it
= bllist
.begin();
52 int set_complete_callback(void *cb_arg
, rados_callback_t cb
) {
54 callback_complete
= cb
;
55 callback_complete_arg
= cb_arg
;
59 int set_safe_callback(void *cb_arg
, rados_callback_t cb
) {
62 callback_safe_arg
= cb_arg
;
66 int wait_for_complete() {
68 while (pending_complete
)
82 int r
= pending_complete
;
92 void wait_for_complete_and_cb() {
94 while (pending_complete
|| callback_complete
)
98 void wait_for_safe_and_cb() {
100 while (pending_safe
|| callback_safe
)
104 bool is_complete_and_cb() {
106 bool r
= ((0 == pending_complete
) && !callback_complete
);
110 bool is_safe_and_cb() {
112 int r
= ((0 == pending_safe
) && !callback_safe
);
116 int get_return_value() {
128 assert(lock
.is_locked());
151 void add_safe_request() {
158 assert(lock
.is_locked());
159 if (callback_complete
) {
160 callback_complete(this, callback_complete_arg
);
161 callback_complete
= 0;
166 assert(lock
.is_locked());
168 callback_safe(this, callback_safe_arg
);
174 void complete_request(ssize_t r
);
175 void safe_request(ssize_t r
);
176 void finish_adding_requests();
180 void intrusive_ptr_add_ref(libradosstriper::MultiAioCompletionImpl
*);
181 void intrusive_ptr_release(libradosstriper::MultiAioCompletionImpl
*);
183 #endif // CEPH_LIBRADOSSTRIPERSTRIPER_MULTIAIOCOMPLETIONIMPL_H