]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_user.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / rgw / rgw_user.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #include "rgw_sal_rados.h"
5
6 #include "include/types.h"
7 #include "rgw_user.h"
8
9 // until everything is moved from rgw_common
10 #include "rgw_common.h"
11
12 #define dout_subsys ceph_subsys_rgw
13
14 using namespace std;
15
16 int rgw_user_sync_all_stats(const DoutPrefixProvider *dpp, rgw::sal::Driver* driver,
17 rgw::sal::User* user, optional_yield y)
18 {
19 rgw::sal::BucketList user_buckets;
20
21 CephContext *cct = driver->ctx();
22 size_t max_entries = cct->_conf->rgw_list_buckets_max_chunk;
23 string marker;
24 int ret;
25
26 do {
27 ret = user->list_buckets(dpp, marker, string(), max_entries, false, user_buckets, y);
28 if (ret < 0) {
29 ldpp_dout(dpp, 0) << "failed to read user buckets: ret=" << ret << dendl;
30 return ret;
31 }
32 auto& buckets = user_buckets.get_buckets();
33 for (auto i = buckets.begin(); i != buckets.end(); ++i) {
34 marker = i->first;
35
36 auto& bucket = i->second;
37
38 ret = bucket->load_bucket(dpp, y);
39 if (ret < 0) {
40 ldpp_dout(dpp, 0) << "ERROR: could not read bucket info: bucket=" << bucket << " ret=" << ret << dendl;
41 continue;
42 }
43 ret = bucket->sync_user_stats(dpp, y);
44 if (ret < 0) {
45 ldout(cct, 0) << "ERROR: could not sync bucket stats: ret=" << ret << dendl;
46 return ret;
47 }
48 ret = bucket->check_bucket_shards(dpp);
49 if (ret < 0) {
50 ldpp_dout(dpp, 0) << "ERROR in check_bucket_shards: " << cpp_strerror(-ret)<< dendl;
51 }
52 }
53 } while (user_buckets.is_truncated());
54
55 ret = user->complete_flush_stats(dpp, y);
56 if (ret < 0) {
57 cerr << "ERROR: failed to complete syncing user stats: ret=" << ret << std::endl;
58 return ret;
59 }
60
61 return 0;
62 }
63
64 int rgw_user_get_all_buckets_stats(const DoutPrefixProvider *dpp,
65 rgw::sal::Driver* driver,
66 rgw::sal::User* user,
67 map<string, bucket_meta_entry>& buckets_usage_map,
68 optional_yield y)
69 {
70 CephContext *cct = driver->ctx();
71 size_t max_entries = cct->_conf->rgw_list_buckets_max_chunk;
72 bool done;
73 string marker;
74 int ret;
75
76 do {
77 rgw::sal::BucketList buckets;
78 ret = user->list_buckets(dpp, marker, string(), max_entries, false, buckets, y);
79 if (ret < 0) {
80 ldpp_dout(dpp, 0) << "failed to read user buckets: ret=" << ret << dendl;
81 return ret;
82 }
83 auto& m = buckets.get_buckets();
84 for (const auto& i : m) {
85 marker = i.first;
86
87 auto& bucket_ent = i.second;
88 ret = bucket_ent->load_bucket(dpp, y, true /* load user stats */);
89 if (ret < 0) {
90 ldpp_dout(dpp, 0) << "ERROR: could not get bucket stats: ret=" << ret << dendl;
91 return ret;
92 }
93 bucket_meta_entry entry;
94 entry.size = bucket_ent->get_size();
95 entry.size_rounded = bucket_ent->get_size_rounded();
96 entry.creation_time = bucket_ent->get_creation_time();
97 entry.count = bucket_ent->get_count();
98 buckets_usage_map.emplace(bucket_ent->get_name(), entry);
99 }
100 done = (buckets.count() < max_entries);
101 } while (!done);
102
103 return 0;
104 }
105
106 int rgw_validate_tenant_name(const string& t)
107 {
108 struct tench {
109 static bool is_good(char ch) {
110 return isalnum(ch) || ch == '_';
111 }
112 };
113 std::string::const_iterator it =
114 std::find_if_not(t.begin(), t.end(), tench::is_good);
115 return (it == t.end())? 0: -ERR_INVALID_TENANT_NAME;
116 }
117
118 /**
119 * Get the anonymous (ie, unauthenticated) user info.
120 */
121 void rgw_get_anon_user(RGWUserInfo& info)
122 {
123 info.user_id = RGW_USER_ANON_ID;
124 info.display_name.clear();
125 info.access_keys.clear();
126 }
127