1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
|
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2012 Red Hat
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#ifndef MDS_CONTEXT_H
#define MDS_CONTEXT_H
#include "include/Context.h"
class MDS;
/**
* Completion which has access to a reference to the global MDS instance.
*
* This class exists so that Context subclasses can provide the MDS pointer
* from a pointer they already had, e.g. MDCache or Locker, rather than
* necessarily having to carry around an extra MDS* pointer.
*/
class MDSContext : public Context
{
protected:
virtual MDS *get_mds() = 0;
};
/**
* A context which must be called with the big MDS lock held. Subclass
* this with a get_mds implementation.
*/
class MDSInternalContextBase : public MDSContext
{
public:
void complete(int r);
};
/**
* General purpose, lets you pass in an MDS pointer.
*/
class MDSInternalContext : public MDSInternalContextBase
{
protected:
MDS *mds;
virtual MDS* get_mds();
public:
MDSInternalContext(MDS *mds_) : mds(mds_) {
assert(mds != NULL);
}
};
/**
* Wrap a regular Context up as an Internal context. Useful
* if you're trying to work with one of our more generic frameworks.
*/
class MDSInternalContextWrapper : public MDSInternalContextBase
{
protected:
MDS *mds;
Context *fin;
MDS *get_mds();
public:
MDSInternalContextWrapper(MDS *m, Context *c) : mds(m), fin(c) {}
void finish(int r);
};
class MDSIOContextBase : public MDSContext
{
void complete(int r);
};
/**
* Completion for an I/O operation, takes big MDS lock
* before executing finish function.
*/
class MDSIOContext : public MDSIOContextBase
{
protected:
MDS *mds;
virtual MDS* get_mds();
public:
MDSIOContext(MDS *mds_) : mds(mds_) {
assert(mds != NULL);
}
};
/**
* Wrap a regular Context up as an IO Context. Useful
* if you're trying to work with one of our more generic frameworks.
*/
class MDSIOContextWrapper : public MDSIOContextBase
{
protected:
MDS *mds;
Context *fin;
MDS *get_mds();
public:
MDSIOContextWrapper(MDS *m, Context *c) : mds(m), fin(c) {}
void finish(int r);
};
/**
* No-op for callers expecting MDSInternalContextBase
*/
class C_MDSInternalNoop : public MDSInternalContextBase
{
virtual MDS* get_mds() {assert(0);}
public:
void finish(int r) {}
void complete(int r) {}
};
/**
* This class is used where you have an MDSInternalContextBase but
* you sometimes want to call it back from an I/O completion.
*/
class C_IO_Wrapper : public MDSIOContext
{
private:
MDSInternalContextBase *wrapped;
public:
C_IO_Wrapper(MDS *mds_, MDSInternalContextBase *wrapped_) : MDSIOContext(mds_), wrapped(wrapped_) {
assert(wrapped != NULL);
}
virtual void finish(int r) {
wrapped->complete(r);
}
};
/**
* Gather needs a default-constructable class
*/
class MDSInternalContextGather : public MDSInternalContextBase
{
protected:
MDS *get_mds();
};
class MDSGather : public C_GatherBase<MDSInternalContextBase, MDSInternalContextGather>
{
public:
MDSGather(CephContext *cct, MDSInternalContextBase *onfinish) : C_GatherBase<MDSInternalContextBase, MDSInternalContextGather>(cct, onfinish) {}
protected:
virtual MDS *get_mds() {return NULL;}
};
typedef C_GatherBuilderBase<MDSInternalContextBase, MDSGather> MDSGatherBuilder;
#endif // MDS_CONTEXT_H
|