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) 2014 Sebastien Ponce <sebastien.ponce@cern.ch>
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_LIBRADOSSTRIPER_RADOSSTRIPERIMPL_H
16 #define CEPH_LIBRADOSSTRIPER_RADOSSTRIPERIMPL_H
20 #include "include/rados/librados.h"
21 #include "include/rados/librados.hpp"
22 #include "include/radosstriper/libradosstriper.h"
23 #include "include/radosstriper/libradosstriper.hpp"
24 #include "MultiAioCompletionImpl.h"
26 #include "librados/IoCtxImpl.h"
27 #include "librados/AioCompletionImpl.h"
28 #include "common/RefCountedObj.h"
30 namespace libradosstriper
{
32 using MultiAioCompletionImplPtr
=
33 boost::intrusive_ptr
<MultiAioCompletionImpl
>;
35 struct RadosStriperImpl
{
38 * exception wrapper around an error code
41 ErrorCode(int error
) : m_code(error
) {};
47 * @param cluster_name name of the cluster, can be NULL
48 * @param client_name has 2 meanings depending on cluster_name
49 * - if cluster_name is null : this is the client id
50 * - else : this is the full client name in format type.id
52 RadosStriperImpl(librados::IoCtx
& ioctx
, librados::IoCtxImpl
*ioctx_impl
);
54 ~RadosStriperImpl() {};
57 int setObjectLayoutStripeUnit(unsigned int stripe_unit
);
58 int setObjectLayoutStripeCount(unsigned int stripe_count
);
59 int setObjectLayoutObjectSize(unsigned int object_size
);
62 int getxattr(const object_t
& soid
, const char *name
, bufferlist
& bl
);
63 int setxattr(const object_t
& soid
, const char *name
, bufferlist
& bl
);
64 int getxattrs(const object_t
& soid
, map
<string
, bufferlist
>& attrset
);
65 int rmxattr(const object_t
& soid
, const char *name
);
68 int write(const std::string
& soid
, const bufferlist
& bl
, size_t len
, uint64_t off
);
69 int append(const std::string
& soid
, const bufferlist
& bl
, size_t len
);
70 int write_full(const std::string
& soid
, const bufferlist
& bl
);
71 int read(const std::string
& soid
, bufferlist
* pbl
, size_t len
, uint64_t off
);
74 int aio_write(const std::string
& soid
, librados::AioCompletionImpl
*c
,
75 const bufferlist
& bl
, size_t len
, uint64_t off
);
76 int aio_append(const std::string
& soid
, librados::AioCompletionImpl
*c
,
77 const bufferlist
& bl
, size_t len
);
78 int aio_write_full(const std::string
& soid
, librados::AioCompletionImpl
*c
,
79 const bufferlist
& bl
);
80 int aio_read(const std::string
& soid
, librados::AioCompletionImpl
*c
,
81 bufferlist
* pbl
, size_t len
, uint64_t off
);
82 int aio_read(const std::string
& soid
, librados::AioCompletionImpl
*c
,
83 char* buf
, size_t len
, uint64_t off
);
86 // stat, deletion and truncation
87 int stat(const std::string
& soid
, uint64_t *psize
, time_t *pmtime
);
88 int stat2(const std::string
& soid
, uint64_t *psize
, struct timespec
*pts
);
89 template<class TimeType
>
91 typedef int (librados::IoCtxImpl::*Type
) (const object_t
& oid
,
92 librados::AioCompletionImpl
*c
,
93 uint64_t *psize
, TimeType
*pmtime
);
95 template<class TimeType
>
96 int aio_generic_stat(const std::string
& soid
, librados::AioCompletionImpl
*c
,
97 uint64_t *psize
, TimeType
*pmtime
,
98 typename StatFunction
<TimeType
>::Type statFunction
);
99 int aio_stat(const std::string
& soid
, librados::AioCompletionImpl
*c
,
100 uint64_t *psize
, time_t *pmtime
);
101 int aio_stat2(const std::string
& soid
, librados::AioCompletionImpl
*c
,
102 uint64_t *psize
, struct timespec
*pts
);
103 int remove(const std::string
& soid
, int flags
=0);
104 int trunc(const std::string
& soid
, uint64_t size
);
106 // asynchronous remove. Note that the removal is not 100% parallelized :
107 // the removal of the first rados object of the striped object will be
108 // done via a syncrhonous call after the completion of all other removals.
109 // These are done asynchrounously and in parallel
110 int aio_remove(const std::string
& soid
, librados::AioCompletionImpl
*c
, int flags
=0);
112 // reference counting
119 bool deleteme
= false;
130 // objectid manipulation
131 std::string
getObjectId(const object_t
& soid
, long long unsigned objectno
);
133 // opening and closing of striped objects
134 void unlockObject(const std::string
& soid
,
135 const std::string
& lockCookie
);
136 void aio_unlockObject(const std::string
& soid
,
137 const std::string
& lockCookie
,
138 librados::AioCompletion
*c
);
140 // internal versions of IO method
141 int write_in_open_object(const std::string
& soid
,
142 const ceph_file_layout
& layout
,
143 const std::string
& lockCookie
,
144 const bufferlist
& bl
,
147 int aio_write_in_open_object(const std::string
& soid
,
148 librados::AioCompletionImpl
*c
,
149 const ceph_file_layout
& layout
,
150 const std::string
& lockCookie
,
151 const bufferlist
& bl
,
154 int internal_aio_write(const std::string
& soid
,
155 MultiAioCompletionImplPtr c
,
156 const bufferlist
& bl
,
159 const ceph_file_layout
& layout
);
161 int extract_uint32_attr(std::map
<std::string
, bufferlist
> &attrs
,
162 const std::string
& key
,
165 int extract_sizet_attr(std::map
<std::string
, bufferlist
> &attrs
,
166 const std::string
& key
,
169 int internal_get_layout_and_size(const std::string
& oid
,
170 ceph_file_layout
*layout
,
173 int internal_aio_remove(const std::string
& soid
,
174 MultiAioCompletionImplPtr multi_completion
,
178 * opens an existing striped object and takes a shared lock on it
179 * @return 0 if everything is ok and the lock was taken. -errcode otherwise
180 * In particulae, if the striped object does not exists, -ENOENT is returned
181 * In case the return code in not 0, no lock is taken
183 int openStripedObjectForRead(const std::string
& soid
,
184 ceph_file_layout
*layout
,
186 std::string
*lockCookie
);
189 * opens an existing striped object, takes a shared lock on it
190 * and sets its size to the size it will have after the write.
191 * In case the striped object does not exists, it will create it by
192 * calling createOrOpenStripedObject.
193 * @param layout this is filled with the layout of the file
194 * @param size new size of the file (together with isFileSizeAbsolute)
195 * In case of success, this is filled with the size of the file before the opening
196 * @param isFileSizeAbsolute if false, this means that the given size should
197 * be added to the current file size (append mode)
198 * @return 0 if everything is ok and the lock was taken. -errcode otherwise
199 * In case the return code in not 0, no lock is taken
201 int openStripedObjectForWrite(const std::string
& soid
,
202 ceph_file_layout
*layout
,
204 std::string
*lockCookie
,
205 bool isFileSizeAbsolute
);
207 * creates an empty striped object with the given size and opens it calling
208 * openStripedObjectForWrite, which implies taking a shared lock on it
209 * Also deals with the cases where the object was created in the mean time
210 * @param isFileSizeAbsolute if false, this means that the given size should
211 * be added to the current file size (append mode). This of course only makes
212 * sense in case the striped object already exists
213 * @return 0 if everything is ok and the lock was taken. -errcode otherwise
214 * In case the return code in not 0, no lock is taken
216 int createAndOpenStripedObject(const std::string
& soid
,
217 ceph_file_layout
*layout
,
219 std::string
*lockCookie
,
220 bool isFileSizeAbsolute
);
223 * truncates an object synchronously. Should only be called with size < original_size
225 int truncate(const std::string
& soid
,
226 uint64_t original_size
,
228 ceph_file_layout
&layout
);
231 * truncates an object asynchronously. Should only be called with size < original_size
232 * note that the method is not 100% asynchronous, only the removal of rados objects
233 * is, the (potential) truncation of the rados object residing just at the truncation
234 * point is synchronous for lack of asynchronous truncation in the rados layer
236 int aio_truncate(const std::string
& soid
,
237 MultiAioCompletionImplPtr c
,
238 uint64_t original_size
,
240 ceph_file_layout
&layout
);
243 * grows an object (adding 0s). Should only be called with size > original_size
245 int grow(const std::string
& soid
,
246 uint64_t original_size
,
248 ceph_file_layout
&layout
);
251 * creates a unique identifier
253 static std::string
getUUID();
256 return (CephContext
*)m_radosCluster
.cct();
259 // reference counting
266 librados::Rados m_radosCluster
;
267 librados::IoCtx m_ioCtx
;
268 librados::IoCtxImpl
*m_ioCtxImpl
;
271 ceph_file_layout m_layout
;