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-2012 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.
15 #ifndef CEPH_LIBRADOS_IOCTXIMPL_H
16 #define CEPH_LIBRADOS_IOCTXIMPL_H
20 #include "common/Cond.h"
21 #include "common/ceph_mutex.h"
22 #include "common/snap_types.h"
23 #include "common/zipkin_trace.h"
24 #include "include/types.h"
25 #include "include/rados/librados.h"
26 #include "include/rados/librados.hpp"
27 #include "include/xlist.h"
28 #include "osd/osd_types.h"
29 #include "osdc/Objecter.h"
33 struct librados::IoCtxImpl
{
34 std::atomic
<uint64_t> ref_cnt
= { 0 };
35 RadosClient
*client
= nullptr;
39 uint64_t assert_ver
= 0;
40 version_t last_objver
= 0;
41 uint32_t notify_timeout
= 30;
42 object_locator_t oloc
;
43 int extra_op_flags
= 0;
45 ceph::mutex aio_write_list_lock
=
46 ceph::make_mutex("librados::IoCtxImpl::aio_write_list_lock");
47 ceph_tid_t aio_write_seq
= 0;
48 ceph::condition_variable aio_write_cond
;
49 xlist
<AioCompletionImpl
*> aio_write_list
;
50 std::map
<ceph_tid_t
, std::list
<AioCompletionImpl
*> > aio_write_waiters
;
52 Objecter
*objecter
= nullptr;
55 IoCtxImpl(RadosClient
*c
, Objecter
*objecter
,
56 int64_t poolid
, snapid_t s
);
58 void dup(const IoCtxImpl
& rhs
) {
59 // Copy everything except the ref count
62 snap_seq
= rhs
.snap_seq
;
64 assert_ver
= rhs
.assert_ver
;
65 last_objver
= rhs
.last_objver
;
66 notify_timeout
= rhs
.notify_timeout
;
68 extra_op_flags
= rhs
.extra_op_flags
;
69 objecter
= rhs
.objecter
;
72 void set_snap_read(snapid_t s
);
73 int set_snap_write_context(snapid_t seq
, std::vector
<snapid_t
>& snaps
);
84 void queue_aio_write(struct AioCompletionImpl
*c
);
85 void complete_aio_write(struct AioCompletionImpl
*c
);
86 void flush_aio_writes_async(AioCompletionImpl
*c
);
87 void flush_aio_writes();
93 std::string
get_cached_pool_name();
95 int get_object_hash_position(const std::string
& oid
, uint32_t *hash_position
);
96 int get_object_pg_hash_position(const std::string
& oid
, uint32_t *pg_hash_position
);
98 ::ObjectOperation
*prepare_assert_ops(::ObjectOperation
*op
);
101 int snap_list(std::vector
<uint64_t> *snaps
);
102 int snap_lookup(const char *name
, uint64_t *snapid
);
103 int snap_get_name(uint64_t snapid
, std::string
*s
);
104 int snap_get_stamp(uint64_t snapid
, time_t *t
);
105 int snap_create(const char* snapname
);
106 int selfmanaged_snap_create(uint64_t *snapid
);
107 void aio_selfmanaged_snap_create(uint64_t *snapid
, AioCompletionImpl
*c
);
108 int snap_remove(const char* snapname
);
109 int rollback(const object_t
& oid
, const char *snapName
);
110 int selfmanaged_snap_remove(uint64_t snapid
);
111 void aio_selfmanaged_snap_remove(uint64_t snapid
, AioCompletionImpl
*c
);
112 int selfmanaged_snap_rollback_object(const object_t
& oid
,
113 ::SnapContext
& snapc
, uint64_t snapid
);
116 int nlist(Objecter::NListContext
*context
, int max_entries
);
117 uint32_t nlist_seek(Objecter::NListContext
*context
, uint32_t pos
);
118 uint32_t nlist_seek(Objecter::NListContext
*context
, const rados_object_list_cursor
& cursor
);
119 rados_object_list_cursor
nlist_get_cursor(Objecter::NListContext
*context
);
120 void object_list_slice(
121 const hobject_t start
,
122 const hobject_t finish
,
125 hobject_t
*split_start
,
126 hobject_t
*split_finish
);
128 int create(const object_t
& oid
, bool exclusive
);
129 int write(const object_t
& oid
, bufferlist
& bl
, size_t len
, uint64_t off
);
130 int append(const object_t
& oid
, bufferlist
& bl
, size_t len
);
131 int write_full(const object_t
& oid
, bufferlist
& bl
);
132 int writesame(const object_t
& oid
, bufferlist
& bl
,
133 size_t write_len
, uint64_t offset
);
134 int read(const object_t
& oid
, bufferlist
& bl
, size_t len
, uint64_t off
);
135 int mapext(const object_t
& oid
, uint64_t off
, size_t len
,
136 std::map
<uint64_t,uint64_t>& m
);
137 int sparse_read(const object_t
& oid
, std::map
<uint64_t,uint64_t>& m
,
138 bufferlist
& bl
, size_t len
, uint64_t off
);
139 int checksum(const object_t
& oid
, uint8_t type
, const bufferlist
&init_value
,
140 size_t len
, uint64_t off
, size_t chunk_size
, bufferlist
*pbl
);
141 int remove(const object_t
& oid
);
142 int remove(const object_t
& oid
, int flags
);
143 int stat(const object_t
& oid
, uint64_t *psize
, time_t *pmtime
);
144 int stat2(const object_t
& oid
, uint64_t *psize
, struct timespec
*pts
);
145 int trunc(const object_t
& oid
, uint64_t size
);
146 int cmpext(const object_t
& oid
, uint64_t off
, bufferlist
& cmp_bl
);
148 int tmap_update(const object_t
& oid
, bufferlist
& cmdbl
);
150 int exec(const object_t
& oid
, const char *cls
, const char *method
, bufferlist
& inbl
, bufferlist
& outbl
);
152 int getxattr(const object_t
& oid
, const char *name
, bufferlist
& bl
);
153 int setxattr(const object_t
& oid
, const char *name
, bufferlist
& bl
);
154 int getxattrs(const object_t
& oid
, std::map
<std::string
, bufferlist
>& attrset
);
155 int rmxattr(const object_t
& oid
, const char *name
);
157 int operate(const object_t
& oid
, ::ObjectOperation
*o
, ceph::real_time
*pmtime
, int flags
=0);
158 int operate_read(const object_t
& oid
, ::ObjectOperation
*o
, bufferlist
*pbl
, int flags
=0);
159 int aio_operate(const object_t
& oid
, ::ObjectOperation
*o
,
160 AioCompletionImpl
*c
, const SnapContext
& snap_context
,
161 const ceph::real_time
*pmtime
, int flags
,
162 const blkin_trace_info
*trace_info
= nullptr);
163 int aio_operate_read(const object_t
& oid
, ::ObjectOperation
*o
,
164 AioCompletionImpl
*c
, int flags
, bufferlist
*pbl
, const blkin_trace_info
*trace_info
= nullptr);
166 struct C_aio_stat_Ack
: public Context
{
167 librados::AioCompletionImpl
*c
;
169 ceph::real_time mtime
;
170 C_aio_stat_Ack(AioCompletionImpl
*_c
, time_t *pm
);
171 void finish(int r
) override
;
174 struct C_aio_stat2_Ack
: public Context
{
175 librados::AioCompletionImpl
*c
;
176 struct timespec
*pts
;
177 ceph::real_time mtime
;
178 C_aio_stat2_Ack(AioCompletionImpl
*_c
, struct timespec
*pts
);
179 void finish(int r
) override
;
182 struct C_aio_Complete
: public Context
{
183 #if defined(WITH_EVENTTRACE)
186 AioCompletionImpl
*c
;
187 explicit C_aio_Complete(AioCompletionImpl
*_c
);
188 void finish(int r
) override
;
191 int aio_read(const object_t oid
, AioCompletionImpl
*c
,
192 bufferlist
*pbl
, size_t len
, uint64_t off
, uint64_t snapid
,
193 const blkin_trace_info
*info
= nullptr);
194 int aio_read(object_t oid
, AioCompletionImpl
*c
,
195 char *buf
, size_t len
, uint64_t off
, uint64_t snapid
,
196 const blkin_trace_info
*info
= nullptr);
197 int aio_sparse_read(const object_t oid
, AioCompletionImpl
*c
,
198 std::map
<uint64_t,uint64_t> *m
, bufferlist
*data_bl
,
199 size_t len
, uint64_t off
, uint64_t snapid
);
200 int aio_cmpext(const object_t
& oid
, AioCompletionImpl
*c
, uint64_t off
,
202 int aio_cmpext(const object_t
& oid
, AioCompletionImpl
*c
,
203 const char *cmp_buf
, size_t cmp_len
, uint64_t off
);
204 int aio_write(const object_t
&oid
, AioCompletionImpl
*c
,
205 const bufferlist
& bl
, size_t len
, uint64_t off
,
206 const blkin_trace_info
*info
= nullptr);
207 int aio_append(const object_t
&oid
, AioCompletionImpl
*c
,
208 const bufferlist
& bl
, size_t len
);
209 int aio_write_full(const object_t
&oid
, AioCompletionImpl
*c
,
210 const bufferlist
& bl
);
211 int aio_writesame(const object_t
&oid
, AioCompletionImpl
*c
,
212 const bufferlist
& bl
, size_t write_len
, uint64_t off
);
213 int aio_remove(const object_t
&oid
, AioCompletionImpl
*c
, int flags
=0);
214 int aio_exec(const object_t
& oid
, AioCompletionImpl
*c
, const char *cls
,
215 const char *method
, bufferlist
& inbl
, bufferlist
*outbl
);
216 int aio_exec(const object_t
& oid
, AioCompletionImpl
*c
, const char *cls
,
217 const char *method
, bufferlist
& inbl
, char *buf
, size_t out_len
);
218 int aio_stat(const object_t
& oid
, AioCompletionImpl
*c
, uint64_t *psize
, time_t *pmtime
);
219 int aio_stat2(const object_t
& oid
, AioCompletionImpl
*c
, uint64_t *psize
, struct timespec
*pts
);
220 int aio_getxattr(const object_t
& oid
, AioCompletionImpl
*c
,
221 const char *name
, bufferlist
& bl
);
222 int aio_setxattr(const object_t
& oid
, AioCompletionImpl
*c
,
223 const char *name
, bufferlist
& bl
);
224 int aio_getxattrs(const object_t
& oid
, AioCompletionImpl
*c
,
225 std::map
<std::string
, bufferlist
>& attrset
);
226 int aio_rmxattr(const object_t
& oid
, AioCompletionImpl
*c
,
228 int aio_cancel(AioCompletionImpl
*c
);
230 int hit_set_list(uint32_t hash
, AioCompletionImpl
*c
,
231 std::list
< std::pair
<time_t, time_t> > *pls
);
232 int hit_set_get(uint32_t hash
, AioCompletionImpl
*c
, time_t stamp
,
235 int get_inconsistent_objects(const pg_t
& pg
,
236 const librados::object_id_t
& start_after
,
238 AioCompletionImpl
*c
,
239 std::vector
<inconsistent_obj_t
>* objects
,
242 int get_inconsistent_snapsets(const pg_t
& pg
,
243 const librados::object_id_t
& start_after
,
245 AioCompletionImpl
*c
,
246 std::vector
<inconsistent_snapset_t
>* snapsets
,
249 void set_sync_op_version(version_t ver
);
250 int watch(const object_t
& oid
, uint64_t *cookie
, librados::WatchCtx
*ctx
,
251 librados::WatchCtx2
*ctx2
, bool internal
= false);
252 int watch(const object_t
& oid
, uint64_t *cookie
, librados::WatchCtx
*ctx
,
253 librados::WatchCtx2
*ctx2
, uint32_t timeout
, bool internal
= false);
254 int aio_watch(const object_t
& oid
, AioCompletionImpl
*c
, uint64_t *cookie
,
255 librados::WatchCtx
*ctx
, librados::WatchCtx2
*ctx2
,
256 bool internal
= false);
257 int aio_watch(const object_t
& oid
, AioCompletionImpl
*c
, uint64_t *cookie
,
258 librados::WatchCtx
*ctx
, librados::WatchCtx2
*ctx2
,
259 uint32_t timeout
, bool internal
= false);
260 int watch_check(uint64_t cookie
);
261 int unwatch(uint64_t cookie
);
262 int aio_unwatch(uint64_t cookie
, AioCompletionImpl
*c
);
263 int notify(const object_t
& oid
, bufferlist
& bl
, uint64_t timeout_ms
,
264 bufferlist
*preplybl
, char **preply_buf
, size_t *preply_buf_len
);
265 int notify_ack(const object_t
& oid
, uint64_t notify_id
, uint64_t cookie
,
267 int aio_notify(const object_t
& oid
, AioCompletionImpl
*c
, bufferlist
& bl
,
268 uint64_t timeout_ms
, bufferlist
*preplybl
, char **preply_buf
,
269 size_t *preply_buf_len
);
271 int set_alloc_hint(const object_t
& oid
,
272 uint64_t expected_object_size
,
273 uint64_t expected_write_size
,
276 version_t
last_version();
277 void set_assert_version(uint64_t ver
);
278 void set_notify_timeout(uint32_t timeout
);
280 int cache_pin(const object_t
& oid
);
281 int cache_unpin(const object_t
& oid
);
283 int application_enable(const std::string
& app_name
, bool force
);
284 void application_enable_async(const std::string
& app_name
, bool force
,
285 PoolAsyncCompletionImpl
*c
);
286 int application_list(std::set
<std::string
> *app_names
);
287 int application_metadata_get(const std::string
& app_name
,
288 const std::string
&key
,
290 int application_metadata_set(const std::string
& app_name
,
291 const std::string
&key
,
292 const std::string
& value
);
293 int application_metadata_remove(const std::string
& app_name
,
294 const std::string
&key
);
295 int application_metadata_list(const std::string
& app_name
,
296 std::map
<std::string
, std::string
> *values
);