]>
git.proxmox.com Git - ceph.git/blob - 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
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
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.
21 * stripe file ranges onto objects.
22 * build list<ObjectExtent> for the objecter or objectcacher.
24 * also, provide convenience methods that call objecter for you.
26 * "files" are identified by ino.
32 #include "include/types.h"
34 #include "common/ceph_time.h"
36 #include "osd/OSDMap.h"
46 /**** Filer interface ***/
56 typedef std::lock_guard
<std::mutex
> lock_guard
;
57 typedef std::unique_lock
<std::mutex
> unique_lock
;
63 ceph::real_time
*pmtime
;
72 std::vector
<ObjectExtent
> probing
;
73 uint64_t probing_off
, probing_len
;
75 std::map
<object_t
, uint64_t> known_size
;
76 ceph::real_time max_mtime
;
78 std::set
<object_t
> ops
;
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
,
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) {}
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
,
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) {}
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
);
107 Filer(const Filer
& other
);
108 const Filer
operator=(const Filer
& other
);
110 Filer(Objecter
*o
, Finisher
*f
) : cct(o
->cct
), objecter(o
), finisher(f
) {}
114 return objecter
->is_active(); // || (oc && oc->is_active());
118 /*** async file interface. scatter/gather as needed. ***/
120 void read(inodeno_t ino
,
121 file_layout_t
*layout
,
125 ceph::buffer::list
*bl
, // ptr to data
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
);
135 void read_trunc(inodeno_t ino
,
136 file_layout_t
*layout
,
140 ceph::buffer::list
*bl
, // ptr to data
142 uint64_t truncate_size
,
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
,
150 objecter
->sg_read_trunc(extents
, snap
, bl
, flags
,
151 truncate_size
, truncate_seq
, onfinish
, op_flags
);
154 void write(inodeno_t ino
,
155 file_layout_t
*layout
,
156 const SnapContext
& snapc
,
159 ceph::buffer::list
& bl
,
160 ceph::real_time mtime
,
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
);
169 void write_trunc(inodeno_t ino
,
170 file_layout_t
*layout
,
171 const SnapContext
& snapc
,
174 ceph::buffer::list
& bl
,
175 ceph::real_time mtime
,
177 uint64_t truncate_size
,
181 std::vector
<ObjectExtent
> extents
;
182 Striper::file_to_extents(cct
, ino
, layout
, offset
, len
, truncate_size
,
184 objecter
->sg_write_trunc(extents
, snapc
, bl
, mtime
, flags
,
185 truncate_size
, truncate_seq
, oncommit
, op_flags
);
188 void truncate(inodeno_t ino
,
189 file_layout_t
*layout
,
190 const SnapContext
& snapc
,
194 ceph::real_time mtime
,
197 void _do_truncate_range(struct TruncRange
*pr
, int fin
);
199 void zero(inodeno_t ino
,
200 const file_layout_t
*layout
,
201 const SnapContext
& snapc
,
204 ceph::real_time mtime
,
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
);
216 objecter
->zero(extents
[0].oid
, extents
[0].oloc
, extents
[0].offset
,
217 extents
[0].length
, snapc
, mtime
, flags
, oncommit
);
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
,
225 oncommit
? gcom
.new_sub():0);
227 objecter
->zero(p
->oid
, p
->oloc
, p
->offset
, p
->length
,
229 oncommit
? gcom
.new_sub():0);
235 void zero(inodeno_t ino
,
236 file_layout_t
*layout
,
237 const SnapContext
& snapc
,
240 ceph::real_time mtime
,
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
);
261 * and whether we stop when we find data, or hole.
263 int probe(inodeno_t ino
,
264 file_layout_t
*layout
,
268 ceph::real_time
*mtime
,
273 int probe(inodeno_t ino
,
274 file_layout_t
*layout
,
281 return probe(ino
, layout
, snapid
, start_from
, end
,
282 (ceph::real_time
* )0, fwd
, flags
, onfinish
);
285 int probe(inodeno_t ino
,
286 file_layout_t
*layout
,
296 int probe_impl(Probe
* probe
, file_layout_t
*layout
,
297 uint64_t start_from
, uint64_t *end
);
300 #endif // !CEPH_FILER_H