summaryrefslogtreecommitdiffstats
path: root/src/rgw/services/svc_user_rados.h
blob: f0b025e9db04c224beec133b999a8e60a9f54eae (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
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab ft=cpp

/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2019 Red Hat, Inc.
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software
 * Foundation. See file COPYING.
 *
 */


#pragma once

#include "rgw/rgw_service.h"

#include "svc_meta_be.h"
#include "svc_user.h"

class RGWSI_RADOS;
class RGWSI_Zone;
class RGWSI_SysObj;
class RGWSI_SysObj_Cache;
class RGWSI_Meta;
class RGWSI_SyncModules;
class RGWSI_MetaBackend_Handler;

struct rgw_cache_entry_info;

class RGWUserBuckets;

class RGWGetUserHeader_CB;
class RGWGetUserStats_CB;

template <class T>
class RGWChainedCacheImpl;

class RGWSI_User_RADOS : public RGWSI_User
{
  friend class PutOperation;

  std::unique_ptr<RGWSI_MetaBackend::Module> be_module;
  RGWSI_MetaBackend_Handler *be_handler;

  struct user_info_cache_entry {
    RGWUserInfo info;
    RGWObjVersionTracker objv_tracker;
    real_time mtime;
  };

  using RGWChainedCacheImpl_user_info_cache_entry = RGWChainedCacheImpl<user_info_cache_entry>;
  unique_ptr<RGWChainedCacheImpl_user_info_cache_entry> uinfo_cache;

  rgw_raw_obj get_buckets_obj(const rgw_user& user_id) const;

  int get_user_info_from_index(RGWSI_MetaBackend::Context *ctx,
                               const string& key,
                               const rgw_pool& pool,
                               RGWUserInfo *info,
                               RGWObjVersionTracker * const objv_tracker,
                               real_time * const pmtime,
                               optional_yield y,
                               const DoutPrefixProvider *dpp);

  int remove_uid_index(RGWSI_MetaBackend::Context *ctx, const RGWUserInfo& user_info, RGWObjVersionTracker *objv_tracker,
                       optional_yield y, const DoutPrefixProvider *dpp);

  int remove_key_index(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *ctx, const RGWAccessKey& access_key, optional_yield y);
  int remove_email_index(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *ctx, const string& email, optional_yield y);
  int remove_swift_name_index(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *ctx, const string& swift_name, optional_yield y);

  /* admin management */
  int cls_user_update_buckets(const DoutPrefixProvider *dpp, rgw_raw_obj& obj, list<cls_user_bucket_entry>& entries, bool add, optional_yield y);
  int cls_user_add_bucket(const DoutPrefixProvider *dpp, rgw_raw_obj& obj, const cls_user_bucket_entry& entry, optional_yield y);
  int cls_user_remove_bucket(const DoutPrefixProvider *dpp, rgw_raw_obj& obj, const cls_user_bucket& bucket, optional_yield y);

  /* quota stats */
  int cls_user_flush_bucket_stats(const DoutPrefixProvider *dpp, rgw_raw_obj& user_obj,
                                  const RGWBucketEnt& ent, optional_yield y);
  int cls_user_list_buckets(const DoutPrefixProvider *dpp, 
                            rgw_raw_obj& obj,
                            const string& in_marker,
                            const string& end_marker,
                            const int max_entries,
                            list<cls_user_bucket_entry>& entries,
                            string * const out_marker,
                            bool * const truncated,
                            optional_yield y);

  int cls_user_reset_stats(const DoutPrefixProvider *dpp, const rgw_user& user, optional_yield y);
  int cls_user_get_header(const DoutPrefixProvider *dpp, const rgw_user& user, cls_user_header *header, optional_yield y);
  int cls_user_get_header_async(const DoutPrefixProvider *dpp, const string& user, RGWGetUserHeader_CB *cb);

  int do_start(optional_yield, const DoutPrefixProvider *dpp) override;
public:
  struct Svc {
    RGWSI_User_RADOS *user{nullptr};
    RGWSI_RADOS *rados{nullptr};
    RGWSI_Zone *zone{nullptr};
    RGWSI_SysObj *sysobj{nullptr};
    RGWSI_SysObj_Cache *cache{nullptr};
    RGWSI_Meta *meta{nullptr};
    RGWSI_MetaBackend *meta_be{nullptr};
    RGWSI_SyncModules *sync_modules{nullptr};
  } svc;

  RGWSI_User_RADOS(CephContext *cct);
  ~RGWSI_User_RADOS();

  void init(RGWSI_RADOS *_rados_svc,
            RGWSI_Zone *_zone_svc, RGWSI_SysObj *_sysobj_svc,
	    RGWSI_SysObj_Cache *_cache_svc, RGWSI_Meta *_meta_svc,
            RGWSI_MetaBackend *_meta_be_svc,
	    RGWSI_SyncModules *_sync_modules);

  RGWSI_MetaBackend_Handler *get_be_handler() override {
    return be_handler;
  }

  int read_user_info(RGWSI_MetaBackend::Context *ctx,
                     const rgw_user& user,
                     RGWUserInfo *info,
                     RGWObjVersionTracker * const objv_tracker,
                     real_time * const pmtime,
                     rgw_cache_entry_info * const cache_info,
                     map<string, bufferlist> * const pattrs,
                     optional_yield y,
                     const DoutPrefixProvider *dpp) override;

  int store_user_info(RGWSI_MetaBackend::Context *ctx,
                      const RGWUserInfo& info,
                      RGWUserInfo *old_info,
                      RGWObjVersionTracker *objv_tracker,
                      const real_time& mtime,
                      bool exclusive,
                      map<string, bufferlist> *attrs,
                      optional_yield y,
                      const DoutPrefixProvider *dpp) override;

  int remove_user_info(RGWSI_MetaBackend::Context *ctx,
                       const RGWUserInfo& info,
                       RGWObjVersionTracker *objv_tracker,
                       optional_yield y,
                       const DoutPrefixProvider *dpp) override;

  int get_user_info_by_email(RGWSI_MetaBackend::Context *ctx,
                             const string& email, RGWUserInfo *info,
                             RGWObjVersionTracker *objv_tracker,
                             real_time *pmtime,
                             optional_yield y,
                             const DoutPrefixProvider *dpp) override;
  int get_user_info_by_swift(RGWSI_MetaBackend::Context *ctx,
                             const string& swift_name,
                             RGWUserInfo *info,        /* out */
                             RGWObjVersionTracker * const objv_tracker,
                             real_time * const pmtime,
                             optional_yield y,
                             const DoutPrefixProvider *dpp) override;
  int get_user_info_by_access_key(RGWSI_MetaBackend::Context *ctx,
                                  const std::string& access_key,
                                  RGWUserInfo *info,
                                  RGWObjVersionTracker* objv_tracker,
                                  real_time *pmtime,
                                  optional_yield y,
                                  const DoutPrefixProvider *dpp) override;

  /* user buckets directory */

  int add_bucket(const DoutPrefixProvider *dpp, 
                 RGWSI_MetaBackend::Context *ctx,
                 const rgw_user& user,
                 const rgw_bucket& bucket,
                 ceph::real_time creation_time,
                 optional_yield y) override;
  int remove_bucket(const DoutPrefixProvider *dpp, 
                    RGWSI_MetaBackend::Context *ctx,
                    const rgw_user& user,
                    const rgw_bucket& _bucket,
                    optional_yield y) override;
  int list_buckets(const DoutPrefixProvider *dpp, 
                   RGWSI_MetaBackend::Context *ctx,
                   const rgw_user& user,
                   const string& marker,
                   const string& end_marker,
                   uint64_t max,
                   RGWUserBuckets *buckets,
                   bool *is_truncated,
                   optional_yield y) override;

  /* quota related */
  int flush_bucket_stats(const DoutPrefixProvider *dpp, 
                         RGWSI_MetaBackend::Context *ctx,
                         const rgw_user& user,
                         const RGWBucketEnt& ent, optional_yield y) override;

  int complete_flush_stats(const DoutPrefixProvider *dpp, 
                           RGWSI_MetaBackend::Context *ctx,
			   const rgw_user& user, optional_yield y) override;

  int reset_bucket_stats(const DoutPrefixProvider *dpp, 
                         RGWSI_MetaBackend::Context *ctx,
			 const rgw_user& user,
                         optional_yield y) override;
  int read_stats(const DoutPrefixProvider *dpp, 
                 RGWSI_MetaBackend::Context *ctx,
		 const rgw_user& user, RGWStorageStats *stats,
		 ceph::real_time *last_stats_sync,              /* last time a full stats sync completed */
		 ceph::real_time *last_stats_update,
                 optional_yield y) override;  /* last time a stats update was done */

  int read_stats_async(const DoutPrefixProvider *dpp, RGWSI_MetaBackend::Context *ctx,
		       const rgw_user& user, RGWGetUserStats_CB *cb) override;
};