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) 2012 Red Hat
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.
19 #include "include/Context.h"
25 * Completion which has access to a reference to the global MDS instance.
27 * This class exists so that Context subclasses can provide the MDS pointer
28 * from a pointer they already had, e.g. MDCache or Locker, rather than
29 * necessarily having to carry around an extra MDS* pointer.
31 class MDSContext : public Context
34 virtual MDSRank *get_mds() = 0;
39 * A context which must be called with the big MDS lock held. Subclass
40 * this with a get_mds implementation.
42 class MDSInternalContextBase : public MDSContext
45 void complete(int r) override;
49 * General purpose, lets you pass in an MDS pointer.
51 class MDSInternalContext : public MDSInternalContextBase
55 MDSRank* get_mds() override;
58 explicit MDSInternalContext(MDSRank *mds_) : mds(mds_) {
64 * Wrap a regular Context up as an Internal context. Useful
65 * if you're trying to work with one of our more generic frameworks.
67 class MDSInternalContextWrapper : public MDSInternalContextBase
72 MDSRank *get_mds() override;
74 MDSInternalContextWrapper(MDSRank *m, Context *c) : mds(m), fin(c) {}
75 void finish(int r) override;
78 class MDSIOContextBase : public MDSContext
81 void complete(int r) override;
85 * Completion for an log operation, takes big MDSRank lock
86 * before executing finish function. Update log's safe pos
87 * after finish functuon return.
89 class MDSLogContextBase : public MDSIOContextBase
94 MDSLogContextBase() : write_pos(0) {}
95 void complete(int r) final;
96 void set_write_pos(uint64_t wp) { write_pos = wp; }
97 virtual void pre_finish(int r) {}
101 * Completion for an I/O operation, takes big MDSRank lock
102 * before executing finish function.
104 class MDSIOContext : public MDSIOContextBase
108 MDSRank* get_mds() override;
111 explicit MDSIOContext(MDSRank *mds_) : mds(mds_) {
117 * Wrap a regular Context up as an IO Context. Useful
118 * if you're trying to work with one of our more generic frameworks.
120 class MDSIOContextWrapper : public MDSIOContextBase
125 MDSRank *get_mds() override;
127 MDSIOContextWrapper(MDSRank *m, Context *c) : mds(m), fin(c) {}
128 void finish(int r) override;
132 * No-op for callers expecting MDSInternalContextBase
134 class C_MDSInternalNoop final : public MDSInternalContextBase
136 MDSRank* get_mds() override {ceph_abort();}
138 void finish(int r) override {}
139 void complete(int r) override { delete this; }
144 * This class is used where you have an MDSInternalContextBase but
145 * you sometimes want to call it back from an I/O completion.
147 class C_IO_Wrapper : public MDSIOContext
151 MDSInternalContextBase *wrapped;
152 void finish(int r) override {
153 wrapped->complete(r);
157 C_IO_Wrapper(MDSRank *mds_, MDSInternalContextBase *wrapped_) :
158 MDSIOContext(mds_), async(true), wrapped(wrapped_) {
159 assert(wrapped != NULL);
162 ~C_IO_Wrapper() override {
163 if (wrapped != nullptr) {
168 void complete(int r) final;
173 * Gather needs a default-constructable class
175 class MDSInternalContextGather : public MDSInternalContextBase
178 MDSRank *get_mds() override;
182 class MDSGather : public C_GatherBase<MDSInternalContextBase, MDSInternalContextGather>
185 MDSGather(CephContext *cct, MDSInternalContextBase *onfinish) : C_GatherBase<MDSInternalContextBase, MDSInternalContextGather>(cct, onfinish) {}
187 MDSRank *get_mds() override {return NULL;}
191 typedef C_GatherBuilderBase<MDSInternalContextBase, MDSGather> MDSGatherBuilder;
193 #endif // MDS_CONTEXT_H