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
18 #include "common/Cond.h"
19 #include "common/Mutex.h"
20 #include "common/snap_types.h"
21 #include "common/zipkin_trace.h"
22 #include "include/atomic.h"
23 #include "include/types.h"
24 #include "include/rados/librados.h"
25 #include "include/rados/librados.hpp"
26 #include "include/xlist.h"
27 #include "osd/osd_types.h"
28 #include "osdc/Objecter.h"
32 struct librados::IoCtxImpl
{
39 version_t last_objver
;
40 uint32_t notify_timeout
;
41 object_locator_t oloc
;
43 Mutex aio_write_list_lock
;
44 ceph_tid_t aio_write_seq
;
46 xlist
<AioCompletionImpl
*> aio_write_list
;
47 map
<ceph_tid_t
, std::list
<AioCompletionImpl
*> > aio_write_waiters
;
52 IoCtxImpl(RadosClient
*c
, Objecter
*objecter
,
53 int64_t poolid
, snapid_t s
);
55 void dup(const IoCtxImpl
& rhs
) {
56 // Copy everything except the ref count
59 snap_seq
= rhs
.snap_seq
;
61 assert_ver
= rhs
.assert_ver
;
62 last_objver
= rhs
.last_objver
;
63 notify_timeout
= rhs
.notify_timeout
;
65 objecter
= rhs
.objecter
;
68 void set_snap_read(snapid_t s
);
69 int set_snap_write_context(snapid_t seq
, vector
<snapid_t
>& snaps
);
76 if (ref_cnt
.dec() == 0)
80 void queue_aio_write(struct AioCompletionImpl
*c
);
81 void complete_aio_write(struct AioCompletionImpl
*c
);
82 void flush_aio_writes_async(AioCompletionImpl
*c
);
83 void flush_aio_writes();
89 string
get_cached_pool_name();
91 int get_object_hash_position(const std::string
& oid
, uint32_t *hash_position
);
92 int get_object_pg_hash_position(const std::string
& oid
, uint32_t *pg_hash_position
);
94 ::ObjectOperation
*prepare_assert_ops(::ObjectOperation
*op
);
97 int snap_list(vector
<uint64_t> *snaps
);
98 int snap_lookup(const char *name
, uint64_t *snapid
);
99 int snap_get_name(uint64_t snapid
, std::string
*s
);
100 int snap_get_stamp(uint64_t snapid
, time_t *t
);
101 int snap_create(const char* snapname
);
102 int selfmanaged_snap_create(uint64_t *snapid
);
103 void aio_selfmanaged_snap_create(uint64_t *snapid
, AioCompletionImpl
*c
);
104 int snap_remove(const char* snapname
);
105 int rollback(const object_t
& oid
, const char *snapName
);
106 int selfmanaged_snap_remove(uint64_t snapid
);
107 void aio_selfmanaged_snap_remove(uint64_t snapid
, AioCompletionImpl
*c
);
108 int selfmanaged_snap_rollback_object(const object_t
& oid
,
109 ::SnapContext
& snapc
, uint64_t snapid
);
112 int nlist(Objecter::NListContext
*context
, int max_entries
);
113 uint32_t nlist_seek(Objecter::NListContext
*context
, uint32_t pos
);
114 uint32_t nlist_seek(Objecter::NListContext
*context
, const rados_object_list_cursor
& cursor
);
115 rados_object_list_cursor
nlist_get_cursor(Objecter::NListContext
*context
);
116 void object_list_slice(
117 const hobject_t start
,
118 const hobject_t finish
,
121 hobject_t
*split_start
,
122 hobject_t
*split_finish
);
124 int create(const object_t
& oid
, bool exclusive
);
125 int write(const object_t
& oid
, bufferlist
& bl
, size_t len
, uint64_t off
);
126 int append(const object_t
& oid
, bufferlist
& bl
, size_t len
);
127 int write_full(const object_t
& oid
, bufferlist
& bl
);
128 int writesame(const object_t
& oid
, bufferlist
& bl
,
129 size_t write_len
, uint64_t offset
);
130 int read(const object_t
& oid
, bufferlist
& bl
, size_t len
, uint64_t off
);
131 int mapext(const object_t
& oid
, uint64_t off
, size_t len
,
132 std::map
<uint64_t,uint64_t>& m
);
133 int sparse_read(const object_t
& oid
, std::map
<uint64_t,uint64_t>& m
,
134 bufferlist
& bl
, size_t len
, uint64_t off
);
135 int checksum(const object_t
& oid
, uint8_t type
, const bufferlist
&init_value
,
136 size_t len
, uint64_t off
, size_t chunk_size
, bufferlist
*pbl
);
137 int remove(const object_t
& oid
);
138 int remove(const object_t
& oid
, int flags
);
139 int stat(const object_t
& oid
, uint64_t *psize
, time_t *pmtime
);
140 int stat2(const object_t
& oid
, uint64_t *psize
, struct timespec
*pts
);
141 int trunc(const object_t
& oid
, uint64_t size
);
142 int cmpext(const object_t
& oid
, uint64_t off
, bufferlist
& cmp_bl
);
144 int tmap_update(const object_t
& oid
, bufferlist
& cmdbl
);
145 int tmap_put(const object_t
& oid
, bufferlist
& bl
);
146 int tmap_get(const object_t
& oid
, bufferlist
& bl
);
147 int tmap_to_omap(const object_t
& oid
, bool nullok
=false);
149 int exec(const object_t
& oid
, const char *cls
, const char *method
, bufferlist
& inbl
, bufferlist
& outbl
);
151 int getxattr(const object_t
& oid
, const char *name
, bufferlist
& bl
);
152 int setxattr(const object_t
& oid
, const char *name
, bufferlist
& bl
);
153 int getxattrs(const object_t
& oid
, map
<string
, bufferlist
>& attrset
);
154 int rmxattr(const object_t
& oid
, const char *name
);
156 int operate(const object_t
& oid
, ::ObjectOperation
*o
, ceph::real_time
*pmtime
, int flags
=0);
157 int operate_read(const object_t
& oid
, ::ObjectOperation
*o
, bufferlist
*pbl
, int flags
=0);
158 int aio_operate(const object_t
& oid
, ::ObjectOperation
*o
,
159 AioCompletionImpl
*c
, const SnapContext
& snap_context
,
160 int flags
, const blkin_trace_info
*trace_info
= nullptr);
161 int aio_operate_read(const object_t
& oid
, ::ObjectOperation
*o
,
162 AioCompletionImpl
*c
, int flags
, bufferlist
*pbl
, const blkin_trace_info
*trace_info
= nullptr);
164 struct C_aio_stat_Ack
: public Context
{
165 librados::AioCompletionImpl
*c
;
167 ceph::real_time mtime
;
168 C_aio_stat_Ack(AioCompletionImpl
*_c
, time_t *pm
);
169 void finish(int r
) override
;
172 struct C_aio_stat2_Ack
: public Context
{
173 librados::AioCompletionImpl
*c
;
174 struct timespec
*pts
;
175 ceph::real_time mtime
;
176 C_aio_stat2_Ack(AioCompletionImpl
*_c
, struct timespec
*pts
);
177 void finish(int r
) override
;
180 struct C_aio_Complete
: public Context
{
181 #if defined(WITH_LTTNG) && defined(WITH_EVENTTRACE)
184 AioCompletionImpl
*c
;
185 explicit C_aio_Complete(AioCompletionImpl
*_c
);
186 void finish(int r
) override
;
189 int aio_read(const object_t oid
, AioCompletionImpl
*c
,
190 bufferlist
*pbl
, size_t len
, uint64_t off
, uint64_t snapid
,
191 const blkin_trace_info
*info
= nullptr);
192 int aio_read(object_t oid
, AioCompletionImpl
*c
,
193 char *buf
, size_t len
, uint64_t off
, uint64_t snapid
,
194 const blkin_trace_info
*info
= nullptr);
195 int aio_sparse_read(const object_t oid
, AioCompletionImpl
*c
,
196 std::map
<uint64_t,uint64_t> *m
, bufferlist
*data_bl
,
197 size_t len
, uint64_t off
, uint64_t snapid
);
198 int aio_cmpext(const object_t
& oid
, AioCompletionImpl
*c
, uint64_t off
,
200 int aio_cmpext(const object_t
& oid
, AioCompletionImpl
*c
,
201 const char *cmp_buf
, size_t cmp_len
, uint64_t off
);
202 int aio_write(const object_t
&oid
, AioCompletionImpl
*c
,
203 const bufferlist
& bl
, size_t len
, uint64_t off
,
204 const blkin_trace_info
*info
= nullptr);
205 int aio_append(const object_t
&oid
, AioCompletionImpl
*c
,
206 const bufferlist
& bl
, size_t len
);
207 int aio_write_full(const object_t
&oid
, AioCompletionImpl
*c
,
208 const bufferlist
& bl
);
209 int aio_writesame(const object_t
&oid
, AioCompletionImpl
*c
,
210 const bufferlist
& bl
, size_t write_len
, uint64_t off
);
211 int aio_remove(const object_t
&oid
, AioCompletionImpl
*c
, int flags
=0);
212 int aio_exec(const object_t
& oid
, AioCompletionImpl
*c
, const char *cls
,
213 const char *method
, bufferlist
& inbl
, bufferlist
*outbl
);
214 int aio_exec(const object_t
& oid
, AioCompletionImpl
*c
, const char *cls
,
215 const char *method
, bufferlist
& inbl
, char *buf
, size_t out_len
);
216 int aio_stat(const object_t
& oid
, AioCompletionImpl
*c
, uint64_t *psize
, time_t *pmtime
);
217 int aio_stat2(const object_t
& oid
, AioCompletionImpl
*c
, uint64_t *psize
, struct timespec
*pts
);
218 int aio_getxattr(const object_t
& oid
, AioCompletionImpl
*c
,
219 const char *name
, bufferlist
& bl
);
220 int aio_setxattr(const object_t
& oid
, AioCompletionImpl
*c
,
221 const char *name
, bufferlist
& bl
);
222 int aio_getxattrs(const object_t
& oid
, AioCompletionImpl
*c
,
223 map
<string
, bufferlist
>& attrset
);
224 int aio_rmxattr(const object_t
& oid
, AioCompletionImpl
*c
,
226 int aio_cancel(AioCompletionImpl
*c
);
228 int pool_change_auid(unsigned long long auid
);
229 int pool_change_auid_async(unsigned long long auid
, PoolAsyncCompletionImpl
*c
);
231 int hit_set_list(uint32_t hash
, AioCompletionImpl
*c
,
232 std::list
< std::pair
<time_t, time_t> > *pls
);
233 int hit_set_get(uint32_t hash
, AioCompletionImpl
*c
, time_t stamp
,
236 int get_inconsistent_objects(const pg_t
& pg
,
237 const librados::object_id_t
& start_after
,
239 AioCompletionImpl
*c
,
240 std::vector
<inconsistent_obj_t
>* objects
,
243 int get_inconsistent_snapsets(const pg_t
& pg
,
244 const librados::object_id_t
& start_after
,
246 AioCompletionImpl
*c
,
247 std::vector
<inconsistent_snapset_t
>* snapsets
,
250 void set_sync_op_version(version_t ver
);
251 int watch(const object_t
& oid
, uint64_t *cookie
, librados::WatchCtx
*ctx
,
252 librados::WatchCtx2
*ctx2
, bool internal
= false);
253 int watch(const object_t
& oid
, uint64_t *cookie
, librados::WatchCtx
*ctx
,
254 librados::WatchCtx2
*ctx2
, uint32_t timeout
, bool internal
= false);
255 int aio_watch(const object_t
& oid
, AioCompletionImpl
*c
, uint64_t *cookie
,
256 librados::WatchCtx
*ctx
, librados::WatchCtx2
*ctx2
,
257 bool internal
= false);
258 int aio_watch(const object_t
& oid
, AioCompletionImpl
*c
, uint64_t *cookie
,
259 librados::WatchCtx
*ctx
, librados::WatchCtx2
*ctx2
,
260 uint32_t timeout
, bool internal
= false);
261 int watch_check(uint64_t cookie
);
262 int unwatch(uint64_t cookie
);
263 int aio_unwatch(uint64_t cookie
, AioCompletionImpl
*c
);
264 int notify(const object_t
& oid
, bufferlist
& bl
, uint64_t timeout_ms
,
265 bufferlist
*preplybl
, char **preply_buf
, size_t *preply_buf_len
);
266 int notify_ack(const object_t
& oid
, uint64_t notify_id
, uint64_t cookie
,
268 int aio_notify(const object_t
& oid
, AioCompletionImpl
*c
, bufferlist
& bl
,
269 uint64_t timeout_ms
, bufferlist
*preplybl
, char **preply_buf
,
270 size_t *preply_buf_len
);
272 int set_alloc_hint(const object_t
& oid
,
273 uint64_t expected_object_size
,
274 uint64_t expected_write_size
,
277 version_t
last_version();
278 void set_assert_version(uint64_t ver
);
279 void set_notify_timeout(uint32_t timeout
);
281 int cache_pin(const object_t
& oid
);
282 int cache_unpin(const object_t
& oid
);