Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / rbd_replay / PendingIO.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2014 Adam Crume <adamcrume@gmail.com>
7  *
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.
12  *
13  */
14
15 #include "PendingIO.hpp"
16 #include "rbd_replay_debug.hpp"
17
18 #define dout_context g_ceph_context
19
20 using namespace std;
21 using namespace rbd_replay;
22
23 extern "C"
24 void rbd_replay_pending_io_callback(librbd::completion_t cb, void *arg) {
25   PendingIO *io = static_cast<PendingIO*>(arg);
26   io->completed(cb);
27 }
28
29 PendingIO::PendingIO(action_id_t id,
30                      ActionCtx &worker)
31   : m_id(id),
32     m_completion(new librbd::RBD::AioCompletion(this, rbd_replay_pending_io_callback)),
33     m_worker(worker) {
34     }
35
36 PendingIO::~PendingIO() {
37   m_completion->release();
38 }
39
40 void PendingIO::completed(librbd::completion_t cb) {
41   dout(ACTION_LEVEL) << "Completed pending IO #" << m_id << dendl;
42   ssize_t r = m_completion->get_return_value();
43   assertf(r >= 0, "id = %d, r = %d", m_id, r);
44   m_worker.remove_pending(shared_from_this());
45 }