]> git.proxmox.com Git - ceph.git/blame - ceph/src/rgw/rgw_tools.h
update download target update for octopus release
[ceph.git] / ceph / src / rgw / rgw_tools.h
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#ifndef CEPH_RGW_TOOLS_H
5#define CEPH_RGW_TOOLS_H
6
7#include <string>
8
9#include "include/types.h"
10#include "common/ceph_time.h"
11#include "rgw_common.h"
12
13class RGWRados;
11fdf7f2 14class RGWSysObjectCtx;
7c673cae 15struct RGWObjVersionTracker;
11fdf7f2 16class optional_yield;
7c673cae
FG
17
18struct obj_version;
19
494da23a
TL
20int rgw_init_ioctx(librados::Rados *rados, const rgw_pool& pool,
21 librados::IoCtx& ioctx,
22 bool create = false,
23 bool mostly_omap = false);
24
11fdf7f2 25int rgw_put_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid, bufferlist& data, bool exclusive,
7c673cae 26 RGWObjVersionTracker *objv_tracker, real_time set_mtime, map<string, bufferlist> *pattrs = NULL);
11fdf7f2 27int rgw_get_system_obj(RGWRados *rgwstore, RGWSysObjectCtx& obj_ctx, const rgw_pool& pool, const string& key, bufferlist& bl,
7c673cae 28 RGWObjVersionTracker *objv_tracker, real_time *pmtime, map<string, bufferlist> *pattrs = NULL,
b32b8144
FG
29 rgw_cache_entry_info *cache_info = NULL,
30 boost::optional<obj_version> refresh_version = boost::none);
7c673cae
FG
31int rgw_delete_system_obj(RGWRados *rgwstore, const rgw_pool& pool, const string& oid,
32 RGWObjVersionTracker *objv_tracker);
33
11fdf7f2
TL
34const char *rgw_find_mime_by_ext(string& ext);
35
36void rgw_filter_attrset(map<string, bufferlist>& unfiltered_attrset, const string& check_prefix,
37 map<string, bufferlist> *attrset);
38
39/// indicates whether the current thread is in boost::asio::io_context::run(),
40/// used to log warnings if synchronous librados calls are made
41extern thread_local bool is_asio_thread;
42
43/// perform the rados operation, using the yield context when given
44int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid,
45 librados::ObjectReadOperation *op, bufferlist* pbl,
46 optional_yield y);
47int rgw_rados_operate(librados::IoCtx& ioctx, const std::string& oid,
48 librados::ObjectWriteOperation *op, optional_yield y);
49
7c673cae
FG
50int rgw_tools_init(CephContext *cct);
51void rgw_tools_cleanup();
11fdf7f2
TL
52
53template<class H, size_t S>
54class RGWEtag
55{
56 H hash;
57
58public:
59 RGWEtag() {}
60
61 void update(const char *buf, size_t len) {
62 hash.Update((const unsigned char *)buf, len);
63 }
64
65 void update(bufferlist& bl) {
66 if (bl.length() > 0) {
67 update(bl.c_str(), bl.length());
68 }
69 }
70
71 void update(const string& s) {
72 if (!s.empty()) {
73 update(s.c_str(), s.size());
74 }
75 }
76 void finish(string *etag) {
77 char etag_buf[S];
78 char etag_buf_str[S * 2 + 16];
79
80 hash.Final((unsigned char *)etag_buf);
81 buf_to_hex((const unsigned char *)etag_buf, S,
82 etag_buf_str);
83
84 *etag = etag_buf_str;
85 }
86};
87
88using RGWMD5Etag = RGWEtag<MD5, CEPH_CRYPTO_MD5_DIGESTSIZE>;
89
90class RGWDataAccess
91{
92 RGWRados *store;
93 std::unique_ptr<RGWSysObjectCtx> sysobj_ctx;
94
95public:
96 RGWDataAccess(RGWRados *_store);
97
98 class Object;
99 class Bucket;
100
101 using BucketRef = std::shared_ptr<Bucket>;
102 using ObjectRef = std::shared_ptr<Object>;
103
104 class Bucket : public enable_shared_from_this<Bucket> {
105 friend class RGWDataAccess;
106 friend class Object;
107
108 RGWDataAccess *sd{nullptr};
109 RGWBucketInfo bucket_info;
110 string tenant;
111 string name;
112 string bucket_id;
113 ceph::real_time mtime;
114 map<std::string, bufferlist> attrs;
115
116 RGWAccessControlPolicy policy;
117 int finish_init();
118
119 Bucket(RGWDataAccess *_sd,
120 const string& _tenant,
121 const string& _name,
122 const string& _bucket_id) : sd(_sd),
123 tenant(_tenant),
124 name(_name),
125 bucket_id(_bucket_id) {}
126 Bucket(RGWDataAccess *_sd) : sd(_sd) {}
127 int init();
128 int init(const RGWBucketInfo& _bucket_info, const map<string, bufferlist>& _attrs);
129 public:
130 int get_object(const rgw_obj_key& key,
131 ObjectRef *obj);
132
133 };
134
135
136 class Object {
137 RGWDataAccess *sd{nullptr};
138 BucketRef bucket;
139 rgw_obj_key key;
140
141 ceph::real_time mtime;
142 string etag;
143 std::optional<uint64_t> olh_epoch;
144 ceph::real_time delete_at;
145 std::optional<string> user_data;
146
147 std::optional<bufferlist> aclbl;
148
149 Object(RGWDataAccess *_sd,
150 BucketRef&& _bucket,
151 const rgw_obj_key& _key) : sd(_sd),
152 bucket(_bucket),
153 key(_key) {}
154 public:
155 int put(bufferlist& data, map<string, bufferlist>& attrs); /* might modify attrs */
156
157 void set_mtime(const ceph::real_time& _mtime) {
158 mtime = _mtime;
159 }
160
161 void set_etag(const string& _etag) {
162 etag = _etag;
163 }
164
165 void set_olh_epoch(uint64_t epoch) {
166 olh_epoch = epoch;
167 }
168
169 void set_delete_at(ceph::real_time _delete_at) {
170 delete_at = _delete_at;
171 }
172
173 void set_user_data(const string& _user_data) {
174 user_data = _user_data;
175 }
176
177 void set_policy(const RGWAccessControlPolicy& policy);
178
179 friend class Bucket;
180 };
181
182 int get_bucket(const string& tenant,
183 const string name,
184 const string bucket_id,
185 BucketRef *bucket) {
186 bucket->reset(new Bucket(this, tenant, name, bucket_id));
187 return (*bucket)->init();
188 }
189
190 int get_bucket(const RGWBucketInfo& bucket_info,
191 const map<string, bufferlist>& attrs,
192 BucketRef *bucket) {
193 bucket->reset(new Bucket(this));
194 return (*bucket)->init(bucket_info, attrs);
195 }
196 friend class Bucket;
197 friend class Object;
198};
199
200using RGWDataAccessRef = std::shared_ptr<RGWDataAccess>;
7c673cae
FG
201
202#endif