1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
4 #include "rgw_sal_rados.h"
6 #include "include/types.h"
9 // until everything is moved from rgw_common
10 #include "rgw_common.h"
12 #define dout_subsys ceph_subsys_rgw
16 int rgw_user_sync_all_stats(const DoutPrefixProvider
*dpp
, rgw::sal::Driver
* driver
,
17 rgw::sal::User
* user
, optional_yield y
)
19 rgw::sal::BucketList user_buckets
;
21 CephContext
*cct
= driver
->ctx();
22 size_t max_entries
= cct
->_conf
->rgw_list_buckets_max_chunk
;
27 ret
= user
->list_buckets(dpp
, marker
, string(), max_entries
, false, user_buckets
, y
);
29 ldpp_dout(dpp
, 0) << "failed to read user buckets: ret=" << ret
<< dendl
;
32 auto& buckets
= user_buckets
.get_buckets();
33 for (auto i
= buckets
.begin(); i
!= buckets
.end(); ++i
) {
36 auto& bucket
= i
->second
;
38 ret
= bucket
->load_bucket(dpp
, y
);
40 ldpp_dout(dpp
, 0) << "ERROR: could not read bucket info: bucket=" << bucket
<< " ret=" << ret
<< dendl
;
43 ret
= bucket
->sync_user_stats(dpp
, y
);
45 ldout(cct
, 0) << "ERROR: could not sync bucket stats: ret=" << ret
<< dendl
;
48 ret
= bucket
->check_bucket_shards(dpp
);
50 ldpp_dout(dpp
, 0) << "ERROR in check_bucket_shards: " << cpp_strerror(-ret
)<< dendl
;
53 } while (user_buckets
.is_truncated());
55 ret
= user
->complete_flush_stats(dpp
, y
);
57 cerr
<< "ERROR: failed to complete syncing user stats: ret=" << ret
<< std::endl
;
64 int rgw_user_get_all_buckets_stats(const DoutPrefixProvider
*dpp
,
65 rgw::sal::Driver
* driver
,
67 map
<string
, bucket_meta_entry
>& buckets_usage_map
,
70 CephContext
*cct
= driver
->ctx();
71 size_t max_entries
= cct
->_conf
->rgw_list_buckets_max_chunk
;
77 rgw::sal::BucketList buckets
;
78 ret
= user
->list_buckets(dpp
, marker
, string(), max_entries
, false, buckets
, y
);
80 ldpp_dout(dpp
, 0) << "failed to read user buckets: ret=" << ret
<< dendl
;
83 auto& m
= buckets
.get_buckets();
84 for (const auto& i
: m
) {
87 auto& bucket_ent
= i
.second
;
88 ret
= bucket_ent
->load_bucket(dpp
, y
, true /* load user stats */);
90 ldpp_dout(dpp
, 0) << "ERROR: could not get bucket stats: ret=" << ret
<< dendl
;
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
);
100 done
= (buckets
.count() < max_entries
);
106 int rgw_validate_tenant_name(const string
& t
)
109 static bool is_good(char ch
) {
110 return isalnum(ch
) || ch
== '_';
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
;
119 * Get the anonymous (ie, unauthenticated) user info.
121 void rgw_get_anon_user(RGWUserInfo
& info
)
123 info
.user_id
= RGW_USER_ANON_ID
;
124 info
.display_name
.clear();
125 info
.access_keys
.clear();