]> git.proxmox.com Git - ceph.git/blob - ceph/src/mds/MDSContext.cc
update sources to 12.2.10
[ceph.git] / 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 elist<MDSIOContextBase*> MDSIOContextBase::ctx_list(member_offset(MDSIOContextBase, list_item));
49 std::atomic_flag MDSIOContextBase::ctx_list_lock = ATOMIC_FLAG_INIT;
50
51 MDSIOContextBase::MDSIOContextBase(bool track)
52 {
53 created_at = ceph::coarse_mono_clock::now();
54 if (track) {
55 simple_spin_lock(&ctx_list_lock);
56 ctx_list.push_back(&list_item);
57 simple_spin_unlock(&ctx_list_lock);
58 }
59 }
60
61 MDSIOContextBase::~MDSIOContextBase()
62 {
63 simple_spin_lock(&ctx_list_lock);
64 list_item.remove_myself();
65 simple_spin_unlock(&ctx_list_lock);
66 }
67
68 bool MDSIOContextBase::check_ios_in_flight(ceph::coarse_mono_time cutoff,
69 std::string& slow_count,
70 ceph::coarse_mono_time& oldest)
71 {
72 static const unsigned MAX_COUNT = 100;
73 unsigned slow = 0;
74
75 simple_spin_lock(&ctx_list_lock);
76 for (elist<MDSIOContextBase*>::iterator p = ctx_list.begin(); !p.end(); ++p) {
77 MDSIOContextBase *c = *p;
78 if (c->created_at >= cutoff)
79 break;
80 ++slow;
81 if (slow > MAX_COUNT)
82 break;
83 if (slow == 1)
84 oldest = c->created_at;
85 }
86 simple_spin_unlock(&ctx_list_lock);
87
88 if (slow > 0) {
89 if (slow > MAX_COUNT)
90 slow_count = std::to_string(MAX_COUNT) + "+";
91 else
92 slow_count = std::to_string(slow);
93 return true;
94 } else {
95 return false;
96 }
97 }
98
99 void MDSIOContextBase::complete(int r) {
100 MDSRank *mds = get_mds();
101
102 dout(10) << "MDSIOContextBase::complete: " << typeid(*this).name() << dendl;
103 assert(mds != NULL);
104 Mutex::Locker l(mds->mds_lock);
105
106 if (mds->is_daemon_stopping()) {
107 dout(4) << "MDSIOContextBase::complete: dropping for stopping "
108 << typeid(*this).name() << dendl;
109 return;
110 }
111
112 if (r == -EBLACKLISTED) {
113 derr << "MDSIOContextBase: blacklisted! Restarting..." << dendl;
114 mds->respawn();
115 } else {
116 MDSContext::complete(r);
117 }
118 }
119
120 void MDSLogContextBase::complete(int r) {
121 MDLog *mdlog = get_mds()->mdlog;
122 uint64_t safe_pos = write_pos;
123 pre_finish(r);
124 // MDSContextBase::complete() free this
125 MDSIOContextBase::complete(r);
126 mdlog->set_safe_pos(safe_pos);
127 }
128
129 MDSRank *MDSIOContext::get_mds() {
130 return mds;
131 }
132
133 MDSRank *MDSIOContextWrapper::get_mds() {
134 return mds;
135 }
136
137 void MDSIOContextWrapper::finish(int r)
138 {
139 fin->complete(r);
140 }
141
142 void C_IO_Wrapper::complete(int r)
143 {
144 if (async) {
145 async = false;
146 get_mds()->finisher->queue(this, r);
147 } else {
148 MDSIOContext::complete(r);
149 }
150 }
151
152 MDSRank *MDSInternalContextGather::get_mds()
153 {
154 derr << "Forbidden call to MDSInternalContextGather::get_mds by " << typeid(*this).name() << dendl;
155 ceph_abort();
156 }
157