]> git.proxmox.com Git - ceph.git/blob - ceph/src/osdc/Filer.h
import 15.2.4
[ceph.git] / ceph / src / osdc / Filer.h
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) 2004-2006 Sage Weil <sage@newdream.net>
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 #ifndef CEPH_FILER_H
17 #define CEPH_FILER_H
18
19 /*** Filer
20 *
21 * stripe file ranges onto objects.
22 * build list<ObjectExtent> for the objecter or objectcacher.
23 *
24 * also, provide convenience methods that call objecter for you.
25 *
26 * "files" are identified by ino.
27 */
28
29
30 #include <mutex>
31
32 #include "include/types.h"
33
34 #include "common/ceph_time.h"
35
36 #include "osd/OSDMap.h"
37 #include "Objecter.h"
38 #include "Striper.h"
39
40 class Context;
41 class Messenger;
42 class OSDMap;
43 class Finisher;
44
45
46 /**** Filer interface ***/
47
48 class Filer {
49 CephContext *cct;
50 Objecter *objecter;
51 Finisher *finisher;
52
53 // probes
54 struct Probe {
55 std::mutex lock;
56 typedef std::lock_guard<std::mutex> lock_guard;
57 typedef std::unique_lock<std::mutex> unique_lock;
58 inodeno_t ino;
59 file_layout_t layout;
60 snapid_t snapid;
61
62 uint64_t *psize;
63 ceph::real_time *pmtime;
64 utime_t *pumtime;
65
66 int flags;
67
68 bool fwd;
69
70 Context *onfinish;
71
72 std::vector<ObjectExtent> probing;
73 uint64_t probing_off, probing_len;
74
75 std::map<object_t, uint64_t> known_size;
76 ceph::real_time max_mtime;
77
78 std::set<object_t> ops;
79
80 int err;
81 bool found_size;
82
83 Probe(inodeno_t i, file_layout_t &l, snapid_t sn,
84 uint64_t f, uint64_t *e, ceph::real_time *m, int fl, bool fw,
85 Context *c) :
86 ino(i), layout(l), snapid(sn),
87 psize(e), pmtime(m), pumtime(nullptr), flags(fl), fwd(fw), onfinish(c),
88 probing_off(f), probing_len(0),
89 err(0), found_size(false) {}
90
91 Probe(inodeno_t i, file_layout_t &l, snapid_t sn,
92 uint64_t f, uint64_t *e, utime_t *m, int fl, bool fw,
93 Context *c) :
94 ino(i), layout(l), snapid(sn),
95 psize(e), pmtime(nullptr), pumtime(m), flags(fl), fwd(fw),
96 onfinish(c), probing_off(f), probing_len(0),
97 err(0), found_size(false) {}
98 };
99
100 class C_Probe;
101
102 void _probe(Probe *p, Probe::unique_lock& pl);
103 bool _probed(Probe *p, const object_t& oid, uint64_t size,
104 ceph::real_time mtime, Probe::unique_lock& pl);
105
106 public:
107 Filer(const Filer& other);
108 const Filer operator=(const Filer& other);
109
110 Filer(Objecter *o, Finisher *f) : cct(o->cct), objecter(o), finisher(f) {}
111 ~Filer() {}
112
113 bool is_active() {
114 return objecter->is_active(); // || (oc && oc->is_active());
115 }
116
117
118 /*** async file interface. scatter/gather as needed. ***/
119
120 void read(inodeno_t ino,
121 file_layout_t *layout,
122 snapid_t snap,
123 uint64_t offset,
124 uint64_t len,
125 ceph::buffer::list *bl, // ptr to data
126 int flags,
127 Context *onfinish,
128 int op_flags = 0) {
129 ceph_assert(snap); // (until there is a non-NOSNAP write)
130 std::vector<ObjectExtent> extents;
131 Striper::file_to_extents(cct, ino, layout, offset, len, 0, extents);
132 objecter->sg_read(extents, snap, bl, flags, onfinish, op_flags);
133 }
134
135 void read_trunc(inodeno_t ino,
136 file_layout_t *layout,
137 snapid_t snap,
138 uint64_t offset,
139 uint64_t len,
140 ceph::buffer::list *bl, // ptr to data
141 int flags,
142 uint64_t truncate_size,
143 __u32 truncate_seq,
144 Context *onfinish,
145 int op_flags = 0) {
146 ceph_assert(snap); // (until there is a non-NOSNAP write)
147 std::vector<ObjectExtent> extents;
148 Striper::file_to_extents(cct, ino, layout, offset, len, truncate_size,
149 extents);
150 objecter->sg_read_trunc(extents, snap, bl, flags,
151 truncate_size, truncate_seq, onfinish, op_flags);
152 }
153
154 void write(inodeno_t ino,
155 file_layout_t *layout,
156 const SnapContext& snapc,
157 uint64_t offset,
158 uint64_t len,
159 ceph::buffer::list& bl,
160 ceph::real_time mtime,
161 int flags,
162 Context *oncommit,
163 int op_flags = 0) {
164 std::vector<ObjectExtent> extents;
165 Striper::file_to_extents(cct, ino, layout, offset, len, 0, extents);
166 objecter->sg_write(extents, snapc, bl, mtime, flags, oncommit, op_flags);
167 }
168
169 void write_trunc(inodeno_t ino,
170 file_layout_t *layout,
171 const SnapContext& snapc,
172 uint64_t offset,
173 uint64_t len,
174 ceph::buffer::list& bl,
175 ceph::real_time mtime,
176 int flags,
177 uint64_t truncate_size,
178 __u32 truncate_seq,
179 Context *oncommit,
180 int op_flags = 0) {
181 std::vector<ObjectExtent> extents;
182 Striper::file_to_extents(cct, ino, layout, offset, len, truncate_size,
183 extents);
184 objecter->sg_write_trunc(extents, snapc, bl, mtime, flags,
185 truncate_size, truncate_seq, oncommit, op_flags);
186 }
187
188 void truncate(inodeno_t ino,
189 file_layout_t *layout,
190 const SnapContext& snapc,
191 uint64_t offset,
192 uint64_t len,
193 __u32 truncate_seq,
194 ceph::real_time mtime,
195 int flags,
196 Context *oncommit);
197 void _do_truncate_range(struct TruncRange *pr, int fin);
198
199 void zero(inodeno_t ino,
200 const file_layout_t *layout,
201 const SnapContext& snapc,
202 uint64_t offset,
203 uint64_t len,
204 ceph::real_time mtime,
205 int flags,
206 bool keep_first,
207 Context *oncommit) {
208 std::vector<ObjectExtent> extents;
209 Striper::file_to_extents(cct, ino, layout, offset, len, 0, extents);
210 if (extents.size() == 1) {
211 if (extents[0].offset == 0 && extents[0].length == layout->object_size
212 && (!keep_first || extents[0].objectno != 0))
213 objecter->remove(extents[0].oid, extents[0].oloc,
214 snapc, mtime, flags, oncommit);
215 else
216 objecter->zero(extents[0].oid, extents[0].oloc, extents[0].offset,
217 extents[0].length, snapc, mtime, flags, oncommit);
218 } else {
219 C_GatherBuilder gcom(cct, oncommit);
220 for (auto p = extents.begin(); p != extents.end(); ++p) {
221 if (p->offset == 0 && p->length == layout->object_size &&
222 (!keep_first || p->objectno != 0))
223 objecter->remove(p->oid, p->oloc,
224 snapc, mtime, flags,
225 oncommit ? gcom.new_sub():0);
226 else
227 objecter->zero(p->oid, p->oloc, p->offset, p->length,
228 snapc, mtime, flags,
229 oncommit ? gcom.new_sub():0);
230 }
231 gcom.activate();
232 }
233 }
234
235 void zero(inodeno_t ino,
236 file_layout_t *layout,
237 const SnapContext& snapc,
238 uint64_t offset,
239 uint64_t len,
240 ceph::real_time mtime,
241 int flags,
242 Context *oncommit) {
243 zero(ino, layout,
244 snapc, offset,
245 len, mtime,
246 flags, false,
247 oncommit);
248 }
249 // purge range of ino.### objects
250 int purge_range(inodeno_t ino,
251 const file_layout_t *layout,
252 const SnapContext& snapc,
253 uint64_t first_obj, uint64_t num_obj,
254 ceph::real_time mtime,
255 int flags, Context *oncommit);
256 void _do_purge_range(struct PurgeRange *pr, int fin, int err);
257
258 /*
259 * probe
260 * specify direction,
261 * and whether we stop when we find data, or hole.
262 */
263 int probe(inodeno_t ino,
264 file_layout_t *layout,
265 snapid_t snapid,
266 uint64_t start_from,
267 uint64_t *end,
268 ceph::real_time *mtime,
269 bool fwd,
270 int flags,
271 Context *onfinish);
272
273 int probe(inodeno_t ino,
274 file_layout_t *layout,
275 snapid_t snapid,
276 uint64_t start_from,
277 uint64_t *end,
278 bool fwd,
279 int flags,
280 Context *onfinish) {
281 return probe(ino, layout, snapid, start_from, end,
282 (ceph::real_time* )0, fwd, flags, onfinish);
283 }
284
285 int probe(inodeno_t ino,
286 file_layout_t *layout,
287 snapid_t snapid,
288 uint64_t start_from,
289 uint64_t *end,
290 utime_t *mtime,
291 bool fwd,
292 int flags,
293 Context *onfinish);
294
295 private:
296 int probe_impl(Probe* probe, file_layout_t *layout,
297 uint64_t start_from, uint64_t *end);
298 };
299
300 #endif // !CEPH_FILER_H