summaryrefslogtreecommitdiffstats
path: root/src/rgw/services/svc_sys_obj.h
blob: f3e217dbde94dae3f95f9a3db2770763206324a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp

#pragma once

#include "common/static_ptr.h"

#include "rgw_service.h"

#include "svc_rados.h"
#include "svc_sys_obj_types.h"
#include "svc_sys_obj_core_types.h"


class RGWSI_Zone;
class RGWSI_SysObj;

struct rgw_cache_entry_info;

class RGWSI_SysObj : public RGWServiceInstance
{
  friend struct RGWServices_Def;

public:
  class Obj {
    friend class ROp;

    RGWSI_SysObj_Core *core_svc;
    rgw_raw_obj obj;

  public:
    Obj(RGWSI_SysObj_Core *_core_svc, const rgw_raw_obj& _obj)
        : core_svc(_core_svc), obj(_obj) {}

    rgw_raw_obj& get_obj() {
      return obj;
    }

    struct ROp {
      Obj& source;

      ceph::static_ptr<RGWSI_SysObj_Obj_GetObjState, sizeof(RGWSI_SysObj_Core_GetObjState)> state;
      
      RGWObjVersionTracker *objv_tracker{nullptr};
      std::map<std::string, bufferlist> *attrs{nullptr};
      bool raw_attrs{false};
      boost::optional<obj_version> refresh_version{boost::none};
      ceph::real_time *lastmod{nullptr};
      uint64_t *obj_size{nullptr};
      rgw_cache_entry_info *cache_info{nullptr};

      ROp& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
        objv_tracker = _objv_tracker;
        return *this;
      }

      ROp& set_last_mod(ceph::real_time *_lastmod) {
        lastmod = _lastmod;
        return *this;
      }

      ROp& set_obj_size(uint64_t *_obj_size) {
        obj_size = _obj_size;
        return *this;
      }

      ROp& set_attrs(std::map<std::string, bufferlist> *_attrs) {
        attrs = _attrs;
        return *this;
      }

      ROp& set_raw_attrs(bool ra) {
	raw_attrs = ra;
	return *this;
      }

      ROp& set_refresh_version(boost::optional<obj_version>& rf) {
        refresh_version = rf;
        return *this;
      }

      ROp& set_cache_info(rgw_cache_entry_info *ci) {
        cache_info = ci;
        return *this;
      }

      ROp(Obj& _source);

      int stat(optional_yield y, const DoutPrefixProvider *dpp);
      int read(const DoutPrefixProvider *dpp, int64_t ofs, int64_t end, bufferlist *pbl, optional_yield y);
      int read(const DoutPrefixProvider *dpp, bufferlist *pbl, optional_yield y) {
        return read(dpp, 0, -1, pbl, y);
      }
      int get_attr(const DoutPrefixProvider *dpp, const char *name, bufferlist *dest, optional_yield y);
    };

    struct WOp {
      Obj& source;

      RGWObjVersionTracker *objv_tracker{nullptr};
      std::map<std::string, bufferlist> attrs;
      ceph::real_time mtime;
      ceph::real_time *pmtime{nullptr};
      bool exclusive{false};

      WOp& set_objv_tracker(RGWObjVersionTracker *_objv_tracker) {
        objv_tracker = _objv_tracker;
        return *this;
      }

      WOp& set_attrs(std::map<std::string, bufferlist>& _attrs) {
        attrs = _attrs;
        return *this;
      }

      WOp& set_attrs(std::map<std::string, bufferlist>&& _attrs) {
        attrs = _attrs;
        return *this;
      }

      WOp& set_mtime(const ceph::real_time& _mtime) {
        mtime = _mtime;
        return *this;
      }

      WOp& set_pmtime(ceph::real_time *_pmtime) {
        pmtime = _pmtime;
        return *this;
      }

      WOp& set_exclusive(bool _exclusive = true) {
        exclusive = _exclusive;
        return *this;
      }

      WOp(Obj& _source) : source(_source) {}

      int remove(const DoutPrefixProvider *dpp, optional_yield y);
      int write(const DoutPrefixProvider *dpp, bufferlist& bl, optional_yield y);

      int write_data(const DoutPrefixProvider *dpp, bufferlist& bl, optional_yield y); /* write data only */
      int write_attrs(const DoutPrefixProvider *dpp, optional_yield y); /* write attrs only */
      int write_attr(const DoutPrefixProvider *dpp, const char *name, bufferlist& bl,
                     optional_yield y); /* write attrs only */
    };

    struct OmapOp {
      Obj& source;

      bool must_exist{false};

      OmapOp& set_must_exist(bool _must_exist = true) {
        must_exist = _must_exist;
        return *this;
      }

      OmapOp(Obj& _source) : source(_source) {}

      int get_all(const DoutPrefixProvider *dpp, std::map<std::string, bufferlist> *m, optional_yield y);
      int get_vals(const DoutPrefixProvider *dpp, const std::string& marker, uint64_t count,
                   std::map<std::string, bufferlist> *m,
                   bool *pmore, optional_yield y);
      int set(const DoutPrefixProvider *dpp, const std::string& key, bufferlist& bl, optional_yield y);
      int set(const DoutPrefixProvider *dpp, const std::map<std::string, bufferlist>& m, optional_yield y);
      int del(const DoutPrefixProvider *dpp, const std::string& key, optional_yield y);
    };

    struct WNOp {
      Obj& source;

      WNOp(Obj& _source) : source(_source) {}

      int notify(const DoutPrefixProvider *dpp, bufferlist& bl, uint64_t timeout_ms, bufferlist *pbl,
                 optional_yield y);
    };
    ROp rop() {
      return ROp(*this);
    }

    WOp wop() {
      return WOp(*this);
    }

    OmapOp omap() {
      return OmapOp(*this);
    }

    WNOp wn() {
      return WNOp(*this);
    }
  };

  class Pool {
    friend class Op;
    friend class RGWSI_SysObj_Core;

    RGWSI_SysObj_Core *core_svc;
    rgw_pool pool;

  protected:
    using ListImplInfo = RGWSI_SysObj_Pool_ListInfo;

    struct ListCtx {
      ceph::static_ptr<ListImplInfo, sizeof(RGWSI_SysObj_Core_PoolListImplInfo)> impl; /* update this if creating new backend types */
    };

  public:
    Pool(RGWSI_SysObj_Core *_core_svc,
         const rgw_pool& _pool) : core_svc(_core_svc),
                                  pool(_pool) {}

    rgw_pool& get_pool() {
      return pool;
    }

    struct Op {
      Pool& source;
      ListCtx ctx;

      Op(Pool& _source) : source(_source) {}

      int init(const DoutPrefixProvider *dpp, const std::string& marker, const std::string& prefix);
      int get_next(const DoutPrefixProvider *dpp, int max, std::vector<std::string> *oids, bool *is_truncated);
      int get_marker(std::string *marker);
    };

    int list_prefixed_objs(const DoutPrefixProvider *dpp, const std::string& prefix, std::function<void(const std::string&)> cb);

    template <typename Container>
    int list_prefixed_objs(const DoutPrefixProvider *dpp, const std::string& prefix,
                           Container *result) {
      return list_prefixed_objs(dpp, prefix, [&](const std::string& val) {
        result->push_back(val);
      });
    }

    Op op() {
      return Op(*this);
    }
  };

  friend class Obj;
  friend class Obj::ROp;
  friend class Obj::WOp;
  friend class Pool;
  friend class Pool::Op;

protected:
  RGWSI_RADOS *rados_svc{nullptr};
  RGWSI_SysObj_Core *core_svc{nullptr};

  void init(RGWSI_RADOS *_rados_svc,
            RGWSI_SysObj_Core *_core_svc) {
    rados_svc = _rados_svc;
    core_svc = _core_svc;
  }

public:
  RGWSI_SysObj(CephContext *cct): RGWServiceInstance(cct) {}

  Obj get_obj(const rgw_raw_obj& obj);

  Pool get_pool(const rgw_pool& pool) {
    return Pool(core_svc, pool);
  }

  RGWSI_Zone *get_zone_svc();
};

using RGWSysObj = RGWSI_SysObj::Obj;