Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / mds / MDSContext.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) 2012 Red Hat
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
16 #include "MDSRank.h"
17
18 #include "MDSContext.h"
19
20 #include "common/dout.h"
21 #define dout_context g_ceph_context
22 #define dout_subsys ceph_subsys_mds
23
24 void MDSInternalContextBase::complete(int r) {
25   MDSRank *mds = get_mds();
26
27   dout(10) << "MDSInternalContextBase::complete: " << typeid(*this).name() << dendl;
28   assert(mds != NULL);
29   assert(mds->mds_lock.is_locked_by_me());
30   MDSContext::complete(r);
31 }
32
33
34 MDSRank *MDSInternalContext::get_mds() {
35   return mds;
36 }
37
38 MDSRank *MDSInternalContextWrapper::get_mds()
39 {
40   return mds;
41 }
42
43 void MDSInternalContextWrapper::finish(int r)
44 {
45   fin->complete(r);
46 }
47
48 void MDSIOContextBase::complete(int r) {
49   MDSRank *mds = get_mds();
50
51   dout(10) << "MDSIOContextBase::complete: " << typeid(*this).name() << dendl;
52   assert(mds != NULL);
53   Mutex::Locker l(mds->mds_lock);
54   if (mds->is_daemon_stopping()) {
55     dout(4) << "MDSIOContextBase::complete: dropping for stopping "
56             << typeid(*this).name() << dendl;
57     return;
58   }
59
60   if (r == -EBLACKLISTED) {
61     derr << "MDSIOContextBase: blacklisted!  Restarting..." << dendl;
62     mds->respawn();
63   } else {
64     MDSContext::complete(r);
65   }
66 }
67
68 void MDSLogContextBase::complete(int r) {
69   MDLog *mdlog = get_mds()->mdlog;
70   uint64_t safe_pos = write_pos;
71   pre_finish(r);
72   // MDSContextBase::complete() free this
73   MDSIOContextBase::complete(r);
74   mdlog->set_safe_pos(safe_pos);
75 }
76
77 MDSRank *MDSIOContext::get_mds() {
78   return mds;
79 }
80
81 MDSRank *MDSIOContextWrapper::get_mds() {
82   return mds;
83 }
84
85 void MDSIOContextWrapper::finish(int r)
86 {
87   fin->complete(r);
88 }
89
90 void C_IO_Wrapper::complete(int r)
91 {
92   if (async) {
93     async = false;
94     get_mds()->finisher->queue(this, r);
95   } else {
96     MDSIOContext::complete(r);
97   }
98 }
99
100 MDSRank *MDSInternalContextGather::get_mds()
101 {
102   derr << "Forbidden call to MDSInternalContextGather::get_mds by " << typeid(*this).name() << dendl;
103   ceph_abort();
104 }
105