1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "include/types.h"
8 #include <boost/algorithm/string.hpp>
10 #include "objclass/objclass.h"
11 #include "cls/rgw/cls_rgw_ops.h"
12 #include "cls/rgw/cls_rgw_const.h"
13 #include "common/Clock.h"
14 #include "common/strtol.h"
15 #include "common/escape.h"
17 #include "include/compat.h"
18 #include <boost/lexical_cast.hpp>
26 using ceph::bufferlist
;
29 using ceph::make_timespan
;
30 using ceph::real_clock
;
31 using ceph::real_time
;
38 // No UTF-8 character can begin with 0x80, so this is a safe indicator
39 // of a special bucket-index entry for the first byte. Note: although
40 // it has no impact, the 2nd, 3rd, or 4th byte of a UTF-8 character
42 #define BI_PREFIX_CHAR 0x80
44 #define BI_BUCKET_OBJS_INDEX 0
45 #define BI_BUCKET_LOG_INDEX 1
46 #define BI_BUCKET_OBJ_INSTANCE_INDEX 2
47 #define BI_BUCKET_OLH_DATA_INDEX 3
49 #define BI_BUCKET_LAST_INDEX 4
51 static std::string bucket_index_prefixes
[] = { "", /* special handling for the objs list index */
52 "0_", /* bucket log index */
53 "1000_", /* obj instance index */
54 "1001_", /* olh data index */
56 /* this must be the last index */
59 // this string is greater than all ascii plain entries and less than
60 // all special entries
61 static const std::string BI_PREFIX_BEGIN
= string(1, BI_PREFIX_CHAR
);
63 // this string is greater than all special entries and less than all
64 // non-ascii plain entries
65 static const std::string BI_PREFIX_END
= string(1, BI_PREFIX_CHAR
) +
66 bucket_index_prefixes
[BI_BUCKET_LAST_INDEX
];
68 /* Returns whether parameter is not a key for a special entry. Empty
69 * strings are considered plain also, so, for example, an empty marker
70 * is also considered plain. TODO: check to make sure all callers are
71 * using appropriately.
73 static bool bi_is_plain_entry(const std::string
& s
) {
74 return (s
.empty() || (unsigned char)s
[0] != BI_PREFIX_CHAR
);
77 int bi_entry_type(const string
& s
)
79 if (bi_is_plain_entry(s
)) {
80 return BI_BUCKET_OBJS_INDEX
;
84 i
< sizeof(bucket_index_prefixes
) / sizeof(bucket_index_prefixes
[0]);
86 const string
& t
= bucket_index_prefixes
[i
];
88 if (s
.compare(1, t
.size(), t
) == 0) {
96 static bool bi_entry_gt(const string
& first
, const string
& second
)
98 int fi
= bi_entry_type(first
);
99 int si
= bi_entry_type(second
);
103 } else if (fi
< si
) {
107 return first
> second
;
110 static void get_time_key(real_time
& ut
, string
*key
)
113 ceph_timespec ts
= ceph::real_clock::to_ceph_timespec(ut
);
114 snprintf(buf
, 32, "%011llu.%09u", (unsigned long long)ts
.tv_sec
, (unsigned int)ts
.tv_nsec
);
118 static void get_index_ver_key(cls_method_context_t hctx
, uint64_t index_ver
, string
*key
)
121 snprintf(buf
, sizeof(buf
), "%011llu.%llu.%d", (unsigned long long)index_ver
,
122 (unsigned long long)cls_current_version(hctx
),
123 cls_current_subop_num(hctx
));
127 static void bi_log_prefix(string
& key
)
129 key
= BI_PREFIX_CHAR
;
130 key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
133 static void bi_log_index_key(cls_method_context_t hctx
, string
& key
, string
& id
, uint64_t index_ver
)
136 get_index_ver_key(hctx
, index_ver
, &id
);
140 static int log_index_operation(cls_method_context_t hctx
, const cls_rgw_obj_key
& obj_key
,
141 RGWModifyOp op
, const string
& tag
, real_time timestamp
,
142 const rgw_bucket_entry_ver
& ver
, RGWPendingState state
, uint64_t index_ver
,
143 string
& max_marker
, uint16_t bilog_flags
, string
*owner
, string
*owner_display_name
, rgw_zone_set
*zones_trace
)
147 rgw_bi_log_entry entry
;
149 entry
.object
= obj_key
.name
;
150 entry
.instance
= obj_key
.instance
;
151 entry
.timestamp
= timestamp
;
155 entry
.index_ver
= index_ver
;
157 entry
.bilog_flags
= bilog_flags
;
159 entry
.owner
= *owner
;
161 if (owner_display_name
) {
162 entry
.owner_display_name
= *owner_display_name
;
165 entry
.zones_trace
= std::move(*zones_trace
);
169 bi_log_index_key(hctx
, key
, entry
.id
, index_ver
);
173 if (entry
.id
> max_marker
)
174 max_marker
= entry
.id
;
176 return cls_cxx_map_set_val(hctx
, key
, &bl
);
180 * Read list of objects, skipping objects in the "ugly namespace". The
181 * "ugly namespace" entries begin with BI_PREFIX_CHAR (0x80). Valid
182 * UTF-8 object names can *both* preceed and follow the "ugly
185 static int get_obj_vals(cls_method_context_t hctx
,
186 const std::string
& start
,
187 const std::string
& filter_prefix
,
189 std::map
<std::string
, bufferlist
> *pkeys
,
192 int ret
= cls_cxx_map_get_vals(hctx
, start
, filter_prefix
,
193 num_entries
, pkeys
, pmore
);
198 if (pkeys
->empty()) {
202 auto last_element
= pkeys
->crbegin();
203 if ((unsigned char)last_element
->first
[0] < BI_PREFIX_CHAR
) {
204 /* if the first character of the last entry is less than the
205 * prefix then all entries must preceed the "ugly namespace" and
211 auto first_element
= pkeys
->cbegin();
212 if ((unsigned char)first_element
->first
[0] > BI_PREFIX_CHAR
) {
213 /* if the first character of the first entry is after the "ugly
214 * namespace" then all entries must follow the "ugly namespace"
215 * then all entries do and we're done
220 /* at this point we know we have entries that could precede the
221 * "ugly namespace", be in the "ugly namespace", and follow the
222 * "ugly namespace", so let's rebuild the list, only keeping entries
223 * outside the "ugly namespace"
226 auto comp
= [](const pair
<std::string
, bufferlist
>& l
, const std::string
&r
) {
229 std::string new_start
= {static_cast<char>(BI_PREFIX_CHAR
+ 1)};
231 auto lower
= pkeys
->lower_bound(string
{static_cast<char>(BI_PREFIX_CHAR
)});
232 auto upper
= std::lower_bound(lower
, pkeys
->end(), new_start
, comp
);
233 pkeys
->erase(lower
, upper
);
235 if (num_entries
== (int)pkeys
->size() || !(*pmore
)) {
239 if (pkeys
->size() && new_start
< pkeys
->crbegin()->first
) {
240 new_start
= pkeys
->rbegin()->first
;
243 std::map
<std::string
, bufferlist
> new_keys
;
245 /* now get some more keys */
246 ret
= cls_cxx_map_get_vals(hctx
, new_start
, filter_prefix
,
247 num_entries
- pkeys
->size(), &new_keys
, pmore
);
252 pkeys
->insert(std::make_move_iterator(new_keys
.begin()),
253 std::make_move_iterator(new_keys
.end()));
259 * get a monotonically decreasing string representation.
260 * For num = x, num = y, where x > y, str(x) < str(y)
261 * Another property is that string size starts short and grows as num increases
263 static void decreasing_str(uint64_t num
, string
*str
)
266 if (num
< 0x10) { /* 16 */
267 snprintf(buf
, sizeof(buf
), "9%02lld", 15 - (long long)num
);
268 } else if (num
< 0x100) { /* 256 */
269 snprintf(buf
, sizeof(buf
), "8%03lld", 255 - (long long)num
);
270 } else if (num
< 0x1000) /* 4096 */ {
271 snprintf(buf
, sizeof(buf
), "7%04lld", 4095 - (long long)num
);
272 } else if (num
< 0x10000) /* 65536 */ {
273 snprintf(buf
, sizeof(buf
), "6%05lld", 65535 - (long long)num
);
274 } else if (num
< 0x100000000) /* 4G */ {
275 snprintf(buf
, sizeof(buf
), "5%010lld", 0xFFFFFFFF - (long long)num
);
277 snprintf(buf
, sizeof(buf
), "4%020lld", (long long)-num
);
284 * We hold two different indexes for objects. The first one holds the
285 * list of objects in the order that we want them to be listed. The
286 * second one only holds the objects instances (for versioned
287 * objects), and they're not arranged in any particular order. When
288 * listing objects we'll use the first index, when doing operations on
289 * the objects themselves we'll use the second index. Note that
290 * regular objects only map to the first index anyway
293 static void get_list_index_key(rgw_bucket_dir_entry
& entry
, string
*index_key
)
295 *index_key
= entry
.key
.name
;
298 decreasing_str(entry
.versioned_epoch
, &ver_str
);
299 string
instance_delim("\0i", 2);
300 string
ver_delim("\0v", 2);
302 index_key
->append(ver_delim
);
303 index_key
->append(ver_str
);
304 index_key
->append(instance_delim
);
305 index_key
->append(entry
.key
.instance
);
308 static void encode_obj_versioned_data_key(const cls_rgw_obj_key
& key
, string
*index_key
, bool append_delete_marker_suffix
= false)
310 *index_key
= BI_PREFIX_CHAR
;
311 index_key
->append(bucket_index_prefixes
[BI_BUCKET_OBJ_INSTANCE_INDEX
]);
312 index_key
->append(key
.name
);
313 string
delim("\0i", 2);
314 index_key
->append(delim
);
315 index_key
->append(key
.instance
);
316 if (append_delete_marker_suffix
) {
318 index_key
->append(dm
);
322 static void encode_obj_index_key(const cls_rgw_obj_key
& key
, string
*index_key
)
324 if (key
.instance
.empty()) {
325 *index_key
= key
.name
;
327 encode_obj_versioned_data_key(key
, index_key
);
331 static void encode_olh_data_key(const cls_rgw_obj_key
& key
, string
*index_key
)
333 *index_key
= BI_PREFIX_CHAR
;
334 index_key
->append(bucket_index_prefixes
[BI_BUCKET_OLH_DATA_INDEX
]);
335 index_key
->append(key
.name
);
339 static int read_index_entry(cls_method_context_t hctx
, string
& name
, T
*entry
);
341 static int encode_list_index_key(cls_method_context_t hctx
, const cls_rgw_obj_key
& key
, string
*index_key
)
343 if (key
.instance
.empty()) {
344 *index_key
= key
.name
;
348 string obj_index_key
;
349 cls_rgw_obj_key
tmp_key(key
);
350 if (tmp_key
.instance
== "null") {
351 tmp_key
.instance
.clear();
353 encode_obj_versioned_data_key(tmp_key
, &obj_index_key
);
355 rgw_bucket_dir_entry entry
;
357 int ret
= read_index_entry(hctx
, obj_index_key
, &entry
);
358 if (ret
== -ENOENT
) {
359 /* couldn't find the entry, set key value after the current object */
360 char buf
[2] = { 0x1, 0 };
362 *index_key
= key
.name
+ s
;
366 CLS_LOG(1, "ERROR: encode_list_index_key(): cls_cxx_map_get_val returned %d", ret
);
370 get_list_index_key(entry
, index_key
);
375 static void split_key(const string
& key
, list
<string
>& vals
)
378 const char *p
= key
.c_str();
379 while (pos
< key
.size()) {
380 size_t len
= strlen(p
);
387 static std::string
escape_str(const std::string
& s
)
389 int len
= escape_json_attr_len(s
.c_str(), s
.size());
390 std::string
escaped(len
, 0);
391 escape_json_attr(s
.c_str(), s
.size(), escaped
.data());
396 * list index key structure:
398 * <obj name>\0[v<ver>\0i<instance id>]
400 static int decode_list_index_key(const string
& index_key
, cls_rgw_obj_key
*key
, uint64_t *ver
)
402 size_t len
= strlen(index_key
.c_str());
404 key
->instance
.clear();
407 if (len
== index_key
.size()) {
408 key
->name
= index_key
;
413 split_key(index_key
, vals
);
416 CLS_LOG(0, "ERROR: %s: bad index_key (%s): split_key() returned empty vals", __func__
, escape_str(index_key
).c_str());
420 auto iter
= vals
.begin();
424 if (iter
== vals
.end()) {
425 CLS_LOG(0, "ERROR: %s: bad index_key (%s): no vals", __func__
, escape_str(index_key
).c_str());
429 for (; iter
!= vals
.end(); ++iter
) {
432 key
->instance
= val
.substr(1);
433 } else if (val
[0] == 'v') {
435 const char *s
= val
.c_str() + 1;
436 *ver
= strict_strtoll(s
, 10, &err
);
438 CLS_LOG(0, "ERROR: %s: bad index_key (%s): could not parse val (v=%s)", __func__
, escape_str(index_key
).c_str(), s
);
447 static int read_bucket_header(cls_method_context_t hctx
,
448 rgw_bucket_dir_header
*header
)
451 int rc
= cls_cxx_map_read_header(hctx
, &bl
);
455 if (bl
.length() == 0) {
456 *header
= rgw_bucket_dir_header();
459 auto iter
= bl
.cbegin();
461 decode(*header
, iter
);
462 } catch (ceph::buffer::error
& err
) {
463 CLS_LOG(1, "ERROR: read_bucket_header(): failed to decode header\n");
470 int rgw_bucket_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
472 CLS_LOG(10, "entered %s", __func__
);
474 // maximum number of calls to get_obj_vals we'll try; compromise
475 // between wanting to return the requested # of entries, but not
476 // wanting to slow down this op with too many omap reads
477 constexpr int max_attempts
= 8;
479 auto iter
= in
->cbegin();
484 } catch (ceph::buffer::error
& err
) {
485 CLS_LOG(1, "ERROR: %s: failed to decode request", __func__
);
489 rgw_cls_list_ret ret
;
490 rgw_bucket_dir
& new_dir
= ret
.dir
;
491 auto& name_entry_map
= new_dir
.m
; // map of keys to entries
493 int rc
= read_bucket_header(hctx
, &new_dir
.header
);
495 CLS_LOG(1, "ERROR: %s: failed to read header", __func__
);
499 // some calls just want the header and request 0 entries
500 if (op
.num_entries
<= 0) {
501 ret
.is_truncated
= false;
506 // key that we can start listing at, one of a) sent in by caller, b)
507 // last item visited, or c) when delimiter present, a key that will
508 // move past the subdirectory
509 std::string start_after_omap_key
;
510 encode_list_index_key(hctx
, op
.start_obj
, &start_after_omap_key
);
512 // this is set whenenver start_after_omap_key is set to keep them in
513 // sync since this will be the returned marker when a marker is
515 cls_rgw_obj_key start_after_entry_key
;
517 // last key stored in result, so if we have to call get_obj_vals
518 // multiple times, we do not add the overlap to result
519 std::string prev_omap_key
;
521 // last prefix_key stored in result, so we can skip over entries
522 // with the same prefix_key
523 std::string prev_prefix_omap_key
;
525 bool done
= false; // whether we need to keep calling get_obj_vals
526 bool more
= true; // output parameter of get_obj_vals
527 bool has_delimiter
= !op
.delimiter
.empty();
530 start_after_omap_key
> op
.filter_prefix
&&
531 boost::algorithm::ends_with(start_after_omap_key
, op
.delimiter
)) {
532 // advance past all subdirectory entries if we start after a
534 start_after_omap_key
= cls_rgw_after_delim(start_after_omap_key
);
537 for (int attempt
= 0;
538 attempt
< max_attempts
&&
541 name_entry_map
.size() < op
.num_entries
;
543 std::map
<std::string
, bufferlist
> keys
;
545 // note: get_obj_vals skips past the "ugly namespace" (i.e.,
546 // entries that start with the BI_PREFIX_CHAR), so no need to
547 // check for such entries
548 rc
= get_obj_vals(hctx
, start_after_omap_key
, op
.filter_prefix
,
549 op
.num_entries
- name_entry_map
.size(),
554 CLS_LOG(20, "%s: on attempt %d get_obj_vls returned %ld entries, more=%d",
555 __func__
, attempt
, keys
.size(), more
);
559 for (auto kiter
= keys
.cbegin(); kiter
!= keys
.cend(); ++kiter
) {
560 rgw_bucket_dir_entry entry
;
562 const bufferlist
& entrybl
= kiter
->second
;
563 auto eiter
= entrybl
.cbegin();
564 decode(entry
, eiter
);
565 } catch (ceph::buffer::error
& err
) {
566 CLS_LOG(1, "ERROR: %s: failed to decode entry, key=%s",
567 __func__
, kiter
->first
.c_str());
571 start_after_omap_key
= kiter
->first
;
572 start_after_entry_key
= entry
.key
;
573 CLS_LOG(20, "%s: working on key=%s len=%zu",
574 __func__
, kiter
->first
.c_str(), kiter
->first
.size());
578 int ret
= decode_list_index_key(kiter
->first
, &key
, &ver
);
580 CLS_LOG(0, "ERROR: %s: failed to decode list index key (%s)",
581 __func__
, escape_str(kiter
->first
).c_str());
585 if (!entry
.is_valid()) {
586 CLS_LOG(20, "%s: entry %s[%s] is not valid",
587 __func__
, key
.name
.c_str(), key
.instance
.c_str());
591 // filter out noncurrent versions, delete markers, and initial marker
592 if (!op
.list_versions
&&
593 (!entry
.is_visible() || op
.start_obj
.name
== key
.name
)) {
594 CLS_LOG(20, "%s: entry %s[%s] is not visible",
595 __func__
, key
.name
.c_str(), key
.instance
.c_str());
600 int delim_pos
= key
.name
.find(op
.delimiter
, op
.filter_prefix
.size());
602 if (delim_pos
>= 0) {
603 /* extract key with trailing delimiter */
605 key
.name
.substr(0, delim_pos
+ op
.delimiter
.length());
607 if (prefix_key
== prev_prefix_omap_key
) {
608 continue; // we've already added this;
610 prev_prefix_omap_key
= prefix_key
;
613 if (name_entry_map
.size() < op
.num_entries
) {
614 rgw_bucket_dir_entry proxy_entry
;
615 cls_rgw_obj_key
proxy_key(prefix_key
);
616 proxy_entry
.key
= cls_rgw_obj_key(proxy_key
);
617 proxy_entry
.flags
= rgw_bucket_dir_entry::FLAG_COMMON_PREFIX
;
618 name_entry_map
[prefix_key
] = proxy_entry
;
620 CLS_LOG(20, "%s: got common prefix entry %s[%s] num entries=%lu",
621 __func__
, proxy_key
.name
.c_str(), proxy_key
.instance
.c_str(),
622 name_entry_map
.size());
625 // make sure that if this is the last item added to the
626 // result from this call to get_obj_vals, the next call will
627 // skip past rest of "subdirectory"
628 start_after_omap_key
= cls_rgw_after_delim(prefix_key
);
629 start_after_entry_key
.set(start_after_omap_key
);
631 // advance past this subdirectory, but then back up one,
632 // so the loop increment will put us in the right place
633 kiter
= keys
.lower_bound(start_after_omap_key
);
639 // no delimiter after prefix found, so this is a "top-level"
640 // item and we can just fall through
643 if (name_entry_map
.size() < op
.num_entries
&&
644 kiter
->first
!= prev_omap_key
) {
645 name_entry_map
[kiter
->first
] = entry
;
646 prev_omap_key
= kiter
->first
;
647 CLS_LOG(20, "%s: got object entry %s[%s] num entries=%d",
648 __func__
, key
.name
.c_str(), key
.instance
.c_str(),
649 int(name_entry_map
.size()));
651 } // for (auto kiter...
652 } // for (int attempt...
654 ret
.is_truncated
= more
&& !done
;
655 if (ret
.is_truncated
) {
656 ret
.marker
= start_after_entry_key
;
658 CLS_LOG(20, "%s: normal exit returning %ld entries, is_truncated=%d",
659 __func__
, ret
.dir
.m
.size(), ret
.is_truncated
);
662 if (ret
.is_truncated
&& name_entry_map
.size() == 0) {
663 CLS_LOG(5, "%s: returning value RGWBIAdvanceAndRetryError", __func__
);
664 return RGWBIAdvanceAndRetryError
;
671 static int check_index(cls_method_context_t hctx
,
672 rgw_bucket_dir_header
*existing_header
,
673 rgw_bucket_dir_header
*calc_header
)
675 int rc
= read_bucket_header(hctx
, existing_header
);
677 CLS_LOG(1, "ERROR: check_index(): failed to read header\n");
681 calc_header
->tag_timeout
= existing_header
->tag_timeout
;
682 calc_header
->ver
= existing_header
->ver
;
683 calc_header
->syncstopped
= existing_header
->syncstopped
;
685 map
<string
, bufferlist
> keys
;
687 string filter_prefix
;
689 #define CHECK_CHUNK_SIZE 1000
694 rc
= get_obj_vals(hctx
, start_obj
, filter_prefix
, CHECK_CHUNK_SIZE
, &keys
, &more
);
698 for (auto kiter
= keys
.begin(); kiter
!= keys
.end(); ++kiter
) {
699 if (!bi_is_plain_entry(kiter
->first
)) {
704 rgw_bucket_dir_entry entry
;
705 auto eiter
= kiter
->second
.cbegin();
707 decode(entry
, eiter
);
708 } catch (ceph::buffer::error
& err
) {
709 CLS_LOG(1, "ERROR: rgw_bucket_list(): failed to decode entry, key=%s", kiter
->first
.c_str());
712 rgw_bucket_category_stats
& stats
= calc_header
->stats
[entry
.meta
.category
];
714 stats
.total_size
+= entry
.meta
.accounted_size
;
715 stats
.total_size_rounded
+= cls_rgw_get_rounded_size(entry
.meta
.accounted_size
);
716 stats
.actual_size
+= entry
.meta
.size
;
718 start_obj
= kiter
->first
;
720 } while (keys
.size() == CHECK_CHUNK_SIZE
&& !done
);
725 int rgw_bucket_check_index(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
727 CLS_LOG(10, "entered %s", __func__
);
728 rgw_cls_check_index_ret ret
;
730 int rc
= check_index(hctx
, &ret
.existing_header
, &ret
.calculated_header
);
739 static int write_bucket_header(cls_method_context_t hctx
, rgw_bucket_dir_header
*header
)
743 bufferlist header_bl
;
744 encode(*header
, header_bl
);
745 return cls_cxx_map_write_header(hctx
, &header_bl
);
749 int rgw_bucket_rebuild_index(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
751 CLS_LOG(10, "entered %s", __func__
);
752 rgw_bucket_dir_header existing_header
;
753 rgw_bucket_dir_header calc_header
;
754 int rc
= check_index(hctx
, &existing_header
, &calc_header
);
758 return write_bucket_header(hctx
, &calc_header
);
761 int rgw_bucket_update_stats(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
763 CLS_LOG(10, "entered %s", __func__
);
765 rgw_cls_bucket_update_stats_op op
;
766 auto iter
= in
->cbegin();
769 } catch (ceph::buffer::error
& err
) {
770 CLS_LOG(1, "ERROR: %s: failed to decode request", __func__
);
774 rgw_bucket_dir_header header
;
775 int rc
= read_bucket_header(hctx
, &header
);
777 CLS_LOG(1, "ERROR: %s: failed to read header", __func__
);
781 for (auto& s
: op
.stats
) {
782 auto& dest
= header
.stats
[s
.first
];
786 dest
.total_size
+= s
.second
.total_size
;
787 dest
.total_size_rounded
+= s
.second
.total_size_rounded
;
788 dest
.num_entries
+= s
.second
.num_entries
;
789 dest
.actual_size
+= s
.second
.actual_size
;
793 return write_bucket_header(hctx
, &header
);
796 int rgw_bucket_init_index(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
798 CLS_LOG(10, "entered %s", __func__
);
799 bufferlist header_bl
;
800 int rc
= cls_cxx_map_read_header(hctx
, &header_bl
);
811 if (header_bl
.length() != 0) {
812 CLS_LOG(1, "ERROR: index already initialized\n");
818 return write_bucket_header(hctx
, &dir
.header
);
821 int rgw_bucket_set_tag_timeout(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
823 CLS_LOG(10, "entered %s", __func__
);
825 rgw_cls_tag_timeout_op op
;
826 auto iter
= in
->cbegin();
829 } catch (ceph::buffer::error
& err
) {
830 CLS_LOG(1, "ERROR: rgw_bucket_set_tag_timeout(): failed to decode request\n");
834 rgw_bucket_dir_header header
;
835 int rc
= read_bucket_header(hctx
, &header
);
837 CLS_LOG(1, "ERROR: rgw_bucket_set_tag_timeout(): failed to read header\n");
841 header
.tag_timeout
= op
.tag_timeout
;
843 return write_bucket_header(hctx
, &header
);
846 static int read_key_entry(cls_method_context_t hctx
, const cls_rgw_obj_key
& key
,
847 string
*idx
, rgw_bucket_dir_entry
*entry
,
848 bool special_delete_marker_name
= false);
850 int rgw_bucket_prepare_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
852 CLS_LOG(10, "entered %s", __func__
);
854 rgw_cls_obj_prepare_op op
;
855 auto iter
= in
->cbegin();
858 } catch (ceph::buffer::error
& err
) {
859 CLS_LOG(1, "ERROR: rgw_bucket_prepare_op(): failed to decode request\n");
863 if (op
.tag
.empty()) {
864 CLS_LOG(1, "ERROR: tag is empty\n");
868 CLS_LOG(1, "rgw_bucket_prepare_op(): request: op=%d name=%s instance=%s tag=%s",
869 op
.op
, op
.key
.name
.c_str(), op
.key
.instance
.c_str(), op
.tag
.c_str());
874 rgw_bucket_dir_entry entry
;
875 int rc
= read_key_entry(hctx
, op
.key
, &idx
, &entry
);
876 if (rc
< 0 && rc
!= -ENOENT
)
879 bool noent
= (rc
== -ENOENT
);
883 if (noent
) { // no entry, initialize fields
885 entry
.ver
= rgw_bucket_entry_ver();
886 entry
.exists
= false;
887 entry
.locator
= op
.locator
;
890 // fill in proper state
891 rgw_bucket_pending_info info
;
892 info
.timestamp
= real_clock::now();
893 info
.state
= CLS_RGW_STATE_PENDING_MODIFY
;
895 entry
.pending_map
.insert(pair
<string
, rgw_bucket_pending_info
>(op
.tag
, info
));
897 // write out new key to disk
899 encode(entry
, info_bl
);
900 return cls_cxx_map_set_val(hctx
, idx
, &info_bl
);
903 static void unaccount_entry(rgw_bucket_dir_header
& header
,
904 rgw_bucket_dir_entry
& entry
)
907 rgw_bucket_category_stats
& stats
= header
.stats
[entry
.meta
.category
];
909 stats
.total_size
-= entry
.meta
.accounted_size
;
910 stats
.total_size_rounded
-=
911 cls_rgw_get_rounded_size(entry
.meta
.accounted_size
);
912 stats
.actual_size
-= entry
.meta
.size
;
916 static void log_entry(const char *func
, const char *str
, rgw_bucket_dir_entry
*entry
)
918 CLS_LOG(1, "%s: %s: ver=%ld:%llu name=%s instance=%s locator=%s", func
, str
,
919 (long)entry
->ver
.pool
, (unsigned long long)entry
->ver
.epoch
,
920 entry
->key
.name
.c_str(), entry
->key
.instance
.c_str(), entry
->locator
.c_str());
923 static void log_entry(const char *func
, const char *str
, rgw_bucket_olh_entry
*entry
)
925 CLS_LOG(1, "%s: %s: epoch=%llu name=%s instance=%s tag=%s", func
, str
,
926 (unsigned long long)entry
->epoch
, entry
->key
.name
.c_str(), entry
->key
.instance
.c_str(),
931 static int read_omap_entry(cls_method_context_t hctx
, const std::string
& name
,
934 bufferlist current_entry
;
935 int rc
= cls_cxx_map_get_val(hctx
, name
, ¤t_entry
);
940 auto cur_iter
= current_entry
.cbegin();
942 decode(*entry
, cur_iter
);
943 } catch (ceph::buffer::error
& err
) {
944 CLS_LOG(1, "ERROR: %s: failed to decode entry", __func__
);
951 static int read_index_entry(cls_method_context_t hctx
, string
& name
, T
* entry
)
953 int ret
= read_omap_entry(hctx
, name
, entry
);
958 log_entry(__func__
, "existing entry", entry
);
962 static int read_key_entry(cls_method_context_t hctx
, const cls_rgw_obj_key
& key
,
963 string
*idx
, rgw_bucket_dir_entry
*entry
,
964 bool special_delete_marker_name
)
966 encode_obj_index_key(key
, idx
);
967 int rc
= read_index_entry(hctx
, *idx
, entry
);
972 if (key
.instance
.empty() &&
973 entry
->flags
& rgw_bucket_dir_entry::FLAG_VER_MARKER
) {
974 /* we only do it where key.instance is empty. In this case the
975 * delete marker will have a separate entry in the index to avoid
976 * collisions with the actual object, as it's mutable
978 if (special_delete_marker_name
) {
979 encode_obj_versioned_data_key(key
, idx
, true);
980 rc
= read_index_entry(hctx
, *idx
, entry
);
985 encode_obj_versioned_data_key(key
, idx
);
986 rc
= read_index_entry(hctx
, *idx
, entry
);
988 *entry
= rgw_bucket_dir_entry(); /* need to reset entry because we initialized it earlier */
996 // called by rgw_bucket_complete_op() for each item in op.remove_objs
997 static int complete_remove_obj(cls_method_context_t hctx
,
998 rgw_bucket_dir_header
& header
,
999 const cls_rgw_obj_key
& key
, bool log_op
)
1001 rgw_bucket_dir_entry entry
;
1003 int ret
= read_key_entry(hctx
, key
, &idx
, &entry
);
1005 CLS_LOG(1, "%s: read_key_entry name=%s instance=%s failed with %d",
1006 __func__
, key
.name
.c_str(), key
.instance
.c_str(), ret
);
1009 CLS_LOG(10, "%s: read entry name=%s instance=%s category=%d", __func__
,
1010 entry
.key
.name
.c_str(), entry
.key
.instance
.c_str(),
1011 int(entry
.meta
.category
));
1012 unaccount_entry(header
, entry
);
1015 ++header
.ver
; // increment index version, or we'll overwrite keys previously written
1016 const std::string tag
;
1017 ret
= log_index_operation(hctx
, key
, CLS_RGW_OP_DEL
, tag
, entry
.meta
.mtime
,
1018 entry
.ver
, CLS_RGW_STATE_COMPLETE
, header
.ver
,
1019 header
.max_marker
, 0, nullptr, nullptr, nullptr);
1025 ret
= cls_cxx_map_remove_key(hctx
, idx
);
1027 CLS_LOG(1, "%s: cls_cxx_map_remove_key failed with %d", __func__
, ret
);
1033 int rgw_bucket_complete_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1035 CLS_LOG(10, "entered %s", __func__
);
1038 rgw_cls_obj_complete_op op
;
1039 auto iter
= in
->cbegin();
1042 } catch (ceph::buffer::error
& err
) {
1043 CLS_LOG(1, "ERROR: rgw_bucket_complete_op(): failed to decode request\n");
1047 CLS_LOG(1, "rgw_bucket_complete_op(): request: op=%d name=%s instance=%s ver=%lu:%llu tag=%s",
1048 op
.op
, op
.key
.name
.c_str(), op
.key
.instance
.c_str(),
1049 (unsigned long)op
.ver
.pool
, (unsigned long long)op
.ver
.epoch
,
1052 rgw_bucket_dir_header header
;
1053 int rc
= read_bucket_header(hctx
, &header
);
1055 CLS_LOG(1, "ERROR: rgw_bucket_complete_op(): failed to read header\n");
1059 rgw_bucket_dir_entry entry
;
1063 rc
= read_key_entry(hctx
, op
.key
, &idx
, &entry
);
1064 if (rc
== -ENOENT
) {
1067 entry
.meta
= op
.meta
;
1068 entry
.locator
= op
.locator
;
1070 } else if (rc
< 0) {
1074 entry
.index_ver
= header
.ver
;
1075 /* resetting entry flags, entry might have been previously a delete
1077 entry
.flags
&= rgw_bucket_dir_entry::FLAG_VER
;
1079 if (op
.tag
.size()) {
1080 auto pinter
= entry
.pending_map
.find(op
.tag
);
1081 if (pinter
== entry
.pending_map
.end()) {
1082 CLS_LOG(1, "ERROR: couldn't find tag for pending operation\n");
1085 entry
.pending_map
.erase(pinter
);
1088 if (op
.tag
.size() && op
.op
== CLS_RGW_OP_CANCEL
) {
1089 CLS_LOG(1, "rgw_bucket_complete_op(): cancel requested\n");
1090 } else if (op
.ver
.pool
== entry
.ver
.pool
&&
1091 op
.ver
.epoch
&& op
.ver
.epoch
<= entry
.ver
.epoch
) {
1092 CLS_LOG(1, "rgw_bucket_complete_op(): skipping request, old epoch\n");
1093 op
.op
= CLS_RGW_OP_CANCEL
;
1096 // controls whether remove_objs deletions are logged
1097 const bool default_log_op
= op
.log_op
&& !header
.syncstopped
;
1098 // controls whether this operation is logged (depends on op.op and ondisk)
1099 bool log_op
= default_log_op
;
1102 if (op
.op
== CLS_RGW_OP_CANCEL
) {
1103 log_op
= false; // don't log cancelation
1104 if (op
.tag
.size()) {
1105 // we removed this tag from pending_map so need to write the changes
1106 bufferlist new_key_bl
;
1107 encode(entry
, new_key_bl
);
1108 rc
= cls_cxx_map_set_val(hctx
, idx
, &new_key_bl
);
1113 } // CLS_RGW_OP_CANCEL
1114 else if (op
.op
== CLS_RGW_OP_DEL
) {
1115 // unaccount deleted entry
1116 unaccount_entry(header
, entry
);
1118 entry
.meta
= op
.meta
;
1120 // no entry to erase
1122 } else if (!entry
.pending_map
.size()) {
1123 rc
= cls_cxx_map_remove_key(hctx
, idx
);
1128 entry
.exists
= false;
1129 bufferlist new_key_bl
;
1130 encode(entry
, new_key_bl
);
1131 rc
= cls_cxx_map_set_val(hctx
, idx
, &new_key_bl
);
1137 else if (op
.op
== CLS_RGW_OP_ADD
) {
1138 // unaccount overwritten entry
1139 unaccount_entry(header
, entry
);
1141 rgw_bucket_dir_entry_meta
& meta
= op
.meta
;
1142 rgw_bucket_category_stats
& stats
= header
.stats
[meta
.category
];
1145 entry
.exists
= true;
1147 // account for new entry
1148 stats
.num_entries
++;
1149 stats
.total_size
+= meta
.accounted_size
;
1150 stats
.total_size_rounded
+= cls_rgw_get_rounded_size(meta
.accounted_size
);
1151 stats
.actual_size
+= meta
.size
;
1152 bufferlist new_key_bl
;
1153 encode(entry
, new_key_bl
);
1154 rc
= cls_cxx_map_set_val(hctx
, idx
, &new_key_bl
);
1161 rc
= log_index_operation(hctx
, op
.key
, op
.op
, op
.tag
, entry
.meta
.mtime
,
1162 entry
.ver
, CLS_RGW_STATE_COMPLETE
, header
.ver
,
1163 header
.max_marker
, op
.bilog_flags
, NULL
, NULL
,
1170 CLS_LOG(20, "rgw_bucket_complete_op(): remove_objs.size()=%d",
1171 (int)op
.remove_objs
.size());
1172 for (const auto& remove_key
: op
.remove_objs
) {
1173 rc
= complete_remove_obj(hctx
, header
, remove_key
, default_log_op
);
1175 continue; // part cleanup errors are not fatal
1179 return write_bucket_header(hctx
, &header
);
1180 } // rgw_bucket_complete_op
1183 static int write_entry(cls_method_context_t hctx
, T
& entry
, const string
& key
)
1187 return cls_cxx_map_set_val(hctx
, key
, &bl
);
1190 static int read_olh(cls_method_context_t hctx
,cls_rgw_obj_key
& obj_key
, rgw_bucket_olh_entry
*olh_data_entry
, string
*index_key
, bool *found
)
1192 cls_rgw_obj_key olh_key
;
1193 olh_key
.name
= obj_key
.name
;
1195 encode_olh_data_key(olh_key
, index_key
);
1196 int ret
= read_index_entry(hctx
, *index_key
, olh_data_entry
);
1197 if (ret
< 0 && ret
!= -ENOENT
) {
1198 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_key
.name
.c_str(), ret
);
1202 *found
= (ret
!= -ENOENT
);
1207 static void update_olh_log(rgw_bucket_olh_entry
& olh_data_entry
, OLHLogOp op
, const string
& op_tag
,
1208 cls_rgw_obj_key
& key
, bool delete_marker
, uint64_t epoch
)
1210 vector
<rgw_bucket_olh_log_entry
>& log
= olh_data_entry
.pending_log
[olh_data_entry
.epoch
];
1211 rgw_bucket_olh_log_entry log_entry
;
1212 log_entry
.epoch
= epoch
;
1214 log_entry
.op_tag
= op_tag
;
1215 log_entry
.key
= key
;
1216 log_entry
.delete_marker
= delete_marker
;
1217 log
.push_back(log_entry
);
1220 static int write_obj_instance_entry(cls_method_context_t hctx
, rgw_bucket_dir_entry
& instance_entry
, const string
& instance_idx
)
1222 CLS_LOG(20, "write_entry() instance=%s idx=%s flags=%d", escape_str(instance_entry
.key
.instance
).c_str(), instance_idx
.c_str(), instance_entry
.flags
);
1223 /* write the instance entry */
1224 int ret
= write_entry(hctx
, instance_entry
, instance_idx
);
1226 CLS_LOG(0, "ERROR: write_entry() instance_key=%s ret=%d", escape_str(instance_idx
).c_str(), ret
);
1233 * write object instance entry, and if needed also the list entry
1235 static int write_obj_entries(cls_method_context_t hctx
, rgw_bucket_dir_entry
& instance_entry
, const string
& instance_idx
)
1237 int ret
= write_obj_instance_entry(hctx
, instance_entry
, instance_idx
);
1241 string instance_list_idx
;
1242 get_list_index_key(instance_entry
, &instance_list_idx
);
1244 if (instance_idx
!= instance_list_idx
) {
1245 CLS_LOG(20, "write_entry() idx=%s flags=%d", escape_str(instance_list_idx
).c_str(), instance_entry
.flags
);
1246 /* write a new list entry for the object instance */
1247 ret
= write_entry(hctx
, instance_entry
, instance_list_idx
);
1249 CLS_LOG(0, "ERROR: write_entry() instance=%s instance_list_idx=%s ret=%d", instance_entry
.key
.instance
.c_str(), instance_list_idx
.c_str(), ret
);
1257 class BIVerObjEntry
{
1258 cls_method_context_t hctx
;
1259 cls_rgw_obj_key key
;
1260 string instance_idx
;
1262 rgw_bucket_dir_entry instance_entry
;
1267 BIVerObjEntry(cls_method_context_t
& _hctx
, const cls_rgw_obj_key
& _key
) : hctx(_hctx
), key(_key
), initialized(false) {
1271 int init(bool check_delete_marker
= true) {
1272 int ret
= read_key_entry(hctx
, key
, &instance_idx
, &instance_entry
,
1273 check_delete_marker
&& key
.instance
.empty()); /* this is potentially a delete marker, for null objects we
1274 keep separate instance entry for the delete markers */
1277 CLS_LOG(0, "ERROR: read_key_entry() idx=%s ret=%d", instance_idx
.c_str(), ret
);
1281 CLS_LOG(20, "read instance_entry key.name=%s key.instance=%s flags=%d", instance_entry
.key
.name
.c_str(), instance_entry
.key
.instance
.c_str(), instance_entry
.flags
);
1285 rgw_bucket_dir_entry
& get_dir_entry() {
1286 return instance_entry
;
1289 void init_as_delete_marker(rgw_bucket_dir_entry_meta
& meta
) {
1290 /* a deletion marker, need to initialize it, there's no instance entry for it yet */
1291 instance_entry
.key
= key
;
1292 instance_entry
.flags
= rgw_bucket_dir_entry::FLAG_DELETE_MARKER
;
1293 instance_entry
.meta
= meta
;
1294 instance_entry
.tag
= "delete-marker";
1299 void set_epoch(uint64_t epoch
) {
1300 instance_entry
.versioned_epoch
= epoch
;
1303 int unlink_list_entry() {
1305 /* this instance has a previous list entry, remove that entry */
1306 get_list_index_key(instance_entry
, &list_idx
);
1307 CLS_LOG(20, "unlink_list_entry() list_idx=%s", escape_str(list_idx
).c_str());
1308 int ret
= cls_cxx_map_remove_key(hctx
, list_idx
);
1310 CLS_LOG(0, "ERROR: cls_cxx_map_remove_key() list_idx=%s ret=%d", list_idx
.c_str(), ret
);
1317 /* remove the instance entry */
1318 CLS_LOG(20, "unlink() idx=%s", escape_str(instance_idx
).c_str());
1319 int ret
= cls_cxx_map_remove_key(hctx
, instance_idx
);
1321 CLS_LOG(0, "ERROR: cls_cxx_map_remove_key() instance_idx=%s ret=%d", instance_idx
.c_str(), ret
);
1327 int write_entries(uint64_t flags_set
, uint64_t flags_reset
) {
1334 instance_entry
.flags
&= ~flags_reset
;
1335 instance_entry
.flags
|= flags_set
;
1337 /* write the instance and list entries */
1338 bool special_delete_marker_key
= (instance_entry
.is_delete_marker() && instance_entry
.key
.instance
.empty());
1339 encode_obj_versioned_data_key(key
, &instance_idx
, special_delete_marker_key
);
1340 int ret
= write_obj_entries(hctx
, instance_entry
, instance_idx
);
1342 CLS_LOG(0, "ERROR: write_obj_entries() instance_idx=%s ret=%d", instance_idx
.c_str(), ret
);
1349 int write(uint64_t epoch
, bool current
) {
1350 if (instance_entry
.versioned_epoch
> 0) {
1351 CLS_LOG(20, "%s: instance_entry.versioned_epoch=%d epoch=%d", __func__
, (int)instance_entry
.versioned_epoch
, (int)epoch
);
1352 /* this instance has a previous list entry, remove that entry */
1353 int ret
= unlink_list_entry();
1359 uint64_t flags
= rgw_bucket_dir_entry::FLAG_VER
;
1361 flags
|= rgw_bucket_dir_entry::FLAG_CURRENT
;
1364 instance_entry
.versioned_epoch
= epoch
;
1365 return write_entries(flags
, 0);
1368 int demote_current() {
1369 return write_entries(0, rgw_bucket_dir_entry::FLAG_CURRENT
);
1372 bool is_delete_marker() {
1373 return instance_entry
.is_delete_marker();
1376 int find_next_key(cls_rgw_obj_key
*next_key
, bool *found
) {
1378 /* this instance has a previous list entry, remove that entry */
1379 get_list_index_key(instance_entry
, &list_idx
);
1380 /* this is the current head, need to update! */
1381 map
<string
, bufferlist
> keys
;
1383 string filter
= key
.name
; /* list key starts with key name, filter it to avoid a case where we cross to
1384 different namespace */
1385 int ret
= cls_cxx_map_get_vals(hctx
, list_idx
, filter
, 1, &keys
, &more
);
1390 if (keys
.size() < 1) {
1395 rgw_bucket_dir_entry next_entry
;
1397 auto last
= keys
.rbegin();
1399 auto iter
= last
->second
.cbegin();
1400 decode(next_entry
, iter
);
1401 } catch (ceph::buffer::error
& err
) {
1402 CLS_LOG(0, "ERROR; failed to decode entry: %s", last
->first
.c_str());
1406 *found
= (key
.name
== next_entry
.key
.name
);
1408 *next_key
= next_entry
.key
;
1415 return instance_entry
.meta
.mtime
;
1417 }; // class BIVerObjEntry
1421 cls_method_context_t hctx
;
1422 cls_rgw_obj_key key
;
1424 string olh_data_idx
;
1425 rgw_bucket_olh_entry olh_data_entry
;
1429 BIOLHEntry(cls_method_context_t
& _hctx
, const cls_rgw_obj_key
& _key
) : hctx(_hctx
), key(_key
), initialized(false) { }
1431 int init(bool *exists
) {
1433 int ret
= read_olh(hctx
, key
, &olh_data_entry
, &olh_data_idx
, exists
);
1442 bool start_modify(uint64_t candidate_epoch
) {
1443 if (candidate_epoch
) {
1444 if (candidate_epoch
< olh_data_entry
.epoch
) {
1445 return false; /* olh cannot be modified, old epoch */
1447 olh_data_entry
.epoch
= candidate_epoch
;
1449 if (olh_data_entry
.epoch
== 0) {
1450 olh_data_entry
.epoch
= 2; /* versioned epoch should start with 2, 1 is reserved to converted plain entries */
1452 olh_data_entry
.epoch
++;
1458 uint64_t get_epoch() {
1459 return olh_data_entry
.epoch
;
1462 rgw_bucket_olh_entry
& get_entry() {
1463 return olh_data_entry
;
1466 void update(cls_rgw_obj_key
& key
, bool delete_marker
) {
1467 olh_data_entry
.delete_marker
= delete_marker
;
1468 olh_data_entry
.key
= key
;
1472 /* write the olh data entry */
1473 int ret
= write_entry(hctx
, olh_data_entry
, olh_data_idx
);
1475 CLS_LOG(0, "ERROR: write_entry() olh_key=%s ret=%d", olh_data_idx
.c_str(), ret
);
1482 void update_log(OLHLogOp op
, const string
& op_tag
, cls_rgw_obj_key
& key
, bool delete_marker
, uint64_t epoch
= 0) {
1484 epoch
= olh_data_entry
.epoch
;
1486 update_olh_log(olh_data_entry
, op
, op_tag
, key
, delete_marker
, epoch
);
1489 bool exists() { return olh_data_entry
.exists
; }
1491 void set_exists(bool exists
) {
1492 olh_data_entry
.exists
= exists
;
1495 bool pending_removal() { return olh_data_entry
.pending_removal
; }
1497 void set_pending_removal(bool pending_removal
) {
1498 olh_data_entry
.pending_removal
= pending_removal
;
1501 const string
& get_tag() { return olh_data_entry
.tag
; }
1502 void set_tag(const string
& tag
) {
1503 olh_data_entry
.tag
= tag
;
1507 static int write_version_marker(cls_method_context_t hctx
, cls_rgw_obj_key
& key
)
1509 rgw_bucket_dir_entry entry
;
1511 entry
.flags
= rgw_bucket_dir_entry::FLAG_VER_MARKER
;
1512 int ret
= write_entry(hctx
, entry
, key
.name
);
1514 CLS_LOG(0, "ERROR: write_entry returned ret=%d", ret
);
1521 * plain entries are the ones who were created when bucket was not
1522 * versioned, if we override these objects, we need to convert these
1523 * to versioned entries -- ones that have both data entry, and listing
1524 * key. Their version is going to be empty though
1526 static int convert_plain_entry_to_versioned(cls_method_context_t hctx
,
1527 cls_rgw_obj_key
& key
,
1528 bool demote_current
,
1531 if (!key
.instance
.empty()) {
1535 rgw_bucket_dir_entry entry
;
1538 int ret
= read_key_entry(hctx
, key
, &orig_idx
, &entry
);
1539 if (ret
!= -ENOENT
) {
1541 CLS_LOG(0, "ERROR: read_key_entry() returned ret=%d", ret
);
1545 entry
.versioned_epoch
= 1; /* converted entries are always 1 */
1546 entry
.flags
|= rgw_bucket_dir_entry::FLAG_VER
;
1548 if (demote_current
) {
1549 entry
.flags
&= ~rgw_bucket_dir_entry::FLAG_CURRENT
;
1553 encode_obj_versioned_data_key(key
, &new_idx
);
1555 if (instance_only
) {
1556 ret
= write_obj_instance_entry(hctx
, entry
, new_idx
);
1558 ret
= write_obj_entries(hctx
, entry
, new_idx
);
1561 CLS_LOG(0, "ERROR: write_obj_entries new_idx=%s returned %d",
1562 new_idx
.c_str(), ret
);
1567 ret
= write_version_marker(hctx
, key
);
1576 * Link an object version to an olh, update the relevant index
1577 * entries. It will also handle the deletion marker case. We have a
1578 * few entries that we need to take care of. For object 'foo',
1579 * instance BAR, we'd update the following (not actual encoding):
1581 * - olh data: [BI_BUCKET_OLH_DATA_INDEX]foo
1582 * - object instance data: [BI_BUCKET_OBJ_INSTANCE_INDEX]foo,BAR
1583 * - object instance list entry: foo,123,BAR
1585 * The instance list entry needs to be ordered by newer to older, so
1586 * we generate an appropriate number string that follows the name.
1587 * The top instance for each object is marked appropriately. We
1588 * generate instance entry for deletion markers here, as they are not
1591 static int rgw_bucket_link_olh(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1593 CLS_LOG(10, "entered %s", __func__
);
1594 string olh_data_idx
;
1595 string instance_idx
;
1598 rgw_cls_link_olh_op op
;
1599 auto iter
= in
->cbegin();
1602 } catch (ceph::buffer::error
& err
) {
1603 CLS_LOG(0, "ERROR: rgw_bucket_link_olh_op(): failed to decode request\n");
1607 /* read instance entry */
1608 BIVerObjEntry
obj(hctx
, op
.key
);
1609 int ret
= obj
.init(op
.delete_marker
);
1611 /* NOTE: When a delete is issued, a key instance is always provided,
1612 * either the one for which the delete is requested or a new random
1613 * one when no instance is specified. So we need to see which of
1614 * these two cases we're dealing with. The variable `existed` will
1615 * be true if the instance was specified and false if it was
1616 * randomly generated. It might have been cleaner if the instance
1617 * were empty and randomly generated here and returned in the reply,
1618 * as that would better allow a typo in the instance id. This code
1619 * should be audited and possibly cleaned up. */
1621 bool existed
= (ret
== 0);
1622 if (ret
== -ENOENT
&& op
.delete_marker
) {
1629 BIOLHEntry
olh(hctx
, op
.key
);
1630 bool olh_read_attempt
= false;
1631 bool olh_found
= false;
1632 if (!existed
&& op
.delete_marker
) {
1634 ret
= olh
.init(&olh_found
);
1638 olh_read_attempt
= true;
1640 // if we're deleting (i.e., adding a delete marker, and the OLH
1641 // indicates it already refers to a delete marker, error out)
1642 if (olh_found
&& olh
.get_entry().delete_marker
) {
1644 "%s: delete marker received for \"%s\" although OLH"
1645 " already refers to a delete marker",
1646 __func__
, escape_str(op
.key
.to_string()).c_str());
1651 if (existed
&& !real_clock::is_zero(op
.unmod_since
)) {
1652 timespec mtime
= ceph::real_clock::to_timespec(obj
.mtime());
1653 timespec unmod
= ceph::real_clock::to_timespec(op
.unmod_since
);
1654 if (!op
.high_precision_time
) {
1658 if (mtime
>= unmod
) {
1659 return 0; /* no need tof set error, we just return 0 and avoid
1660 * writing to the bi log */
1667 * Special handling for null instance object / delete-marker. For
1668 * these objects we're going to have separate instances for a data
1669 * object vs. delete-marker to avoid collisions. We now check if we
1670 * got to overwrite a previous entry, and in that case we'll remove
1673 if (op
.key
.instance
.empty()) {
1674 BIVerObjEntry
other_obj(hctx
, op
.key
);
1675 ret
= other_obj
.init(!op
.delete_marker
); /* try reading the other
1678 existed
= (ret
>= 0 && !other_obj
.is_delete_marker());
1679 if (ret
>= 0 && other_obj
.is_delete_marker() != op
.delete_marker
) {
1680 ret
= other_obj
.unlink_list_entry();
1686 removing
= existed
&& op
.delete_marker
;
1688 ret
= other_obj
.unlink();
1694 removing
= (existed
&& !obj
.is_delete_marker() && op
.delete_marker
);
1697 if (op
.delete_marker
) {
1698 /* a deletion marker, need to initialize entry as such */
1699 obj
.init_as_delete_marker(op
.meta
);
1703 if (!olh_read_attempt
) { // only read if we didn't attempt earlier
1704 ret
= olh
.init(&olh_found
);
1708 olh_read_attempt
= true;
1711 const uint64_t prev_epoch
= olh
.get_epoch();
1713 if (!olh
.start_modify(op
.olh_epoch
)) {
1714 ret
= obj
.write(op
.olh_epoch
, false);
1719 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false, op
.olh_epoch
);
1724 // promote this version to current if it's a newer epoch, or if it matches the
1725 // current epoch and sorts after the current instance
1726 const bool promote
= (olh
.get_epoch() > prev_epoch
) ||
1727 (olh
.get_epoch() == prev_epoch
&&
1728 olh
.get_entry().key
.instance
>= op
.key
.instance
);
1731 const string
& olh_tag
= olh
.get_tag();
1732 if (op
.olh_tag
!= olh_tag
) {
1733 if (!olh
.pending_removal()) {
1734 CLS_LOG(5, "NOTICE: op.olh_tag (%s) != olh.tag (%s)", op
.olh_tag
.c_str(), olh_tag
.c_str());
1737 /* if pending removal, this is a new olh instance */
1738 olh
.set_tag(op
.olh_tag
);
1740 if (promote
&& olh
.exists()) {
1741 rgw_bucket_olh_entry
& olh_entry
= olh
.get_entry();
1742 /* found olh, previous instance is no longer the latest, need to update */
1743 if (!(olh_entry
.key
== op
.key
)) {
1744 BIVerObjEntry
old_obj(hctx
, olh_entry
.key
);
1746 ret
= old_obj
.demote_current();
1748 CLS_LOG(0, "ERROR: could not demote current on previous key ret=%d", ret
);
1753 olh
.set_pending_removal(false);
1755 bool instance_only
= (op
.key
.instance
.empty() && op
.delete_marker
);
1756 cls_rgw_obj_key
key(op
.key
.name
);
1757 ret
= convert_plain_entry_to_versioned(hctx
, key
, promote
, instance_only
);
1759 CLS_LOG(0, "ERROR: convert_plain_entry_to_versioned ret=%d", ret
);
1762 olh
.set_tag(op
.olh_tag
);
1765 /* update the olh log */
1766 olh
.update_log(CLS_RGW_OLH_OP_LINK_OLH
, op
.op_tag
, op
.key
, op
.delete_marker
);
1768 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false);
1772 olh
.update(op
.key
, op
.delete_marker
);
1774 olh
.set_exists(true);
1778 CLS_LOG(0, "ERROR: failed to update olh ret=%d", ret
);
1782 /* write the instance and list entries */
1783 ret
= obj
.write(olh
.get_epoch(), promote
);
1792 rgw_bucket_dir_header header
;
1793 ret
= read_bucket_header(hctx
, &header
);
1795 CLS_LOG(1, "ERROR: rgw_bucket_link_olh(): failed to read header\n");
1798 if (header
.syncstopped
) {
1802 rgw_bucket_dir_entry
& entry
= obj
.get_dir_entry();
1804 rgw_bucket_entry_ver ver
;
1805 ver
.epoch
= (op
.olh_epoch
? op
.olh_epoch
: olh
.get_epoch());
1807 string
*powner
= NULL
;
1808 string
*powner_display_name
= NULL
;
1810 if (op
.delete_marker
) {
1811 powner
= &entry
.meta
.owner
;
1812 powner_display_name
= &entry
.meta
.owner_display_name
;
1815 RGWModifyOp operation
= (op
.delete_marker
? CLS_RGW_OP_LINK_OLH_DM
: CLS_RGW_OP_LINK_OLH
);
1816 ret
= log_index_operation(hctx
, op
.key
, operation
, op
.op_tag
,
1817 entry
.meta
.mtime
, ver
,
1818 CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, op
.bilog_flags
| RGW_BILOG_FLAG_VERSIONED_OP
,
1819 powner
, powner_display_name
, &op
.zones_trace
);
1823 return write_bucket_header(hctx
, &header
); /* updates header version */
1826 static int rgw_bucket_unlink_instance(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1828 CLS_LOG(10, "entered %s", __func__
);
1829 string olh_data_idx
;
1830 string instance_idx
;
1833 rgw_cls_unlink_instance_op op
;
1834 auto iter
= in
->cbegin();
1837 } catch (ceph::buffer::error
& err
) {
1838 CLS_LOG(0, "ERROR: rgw_bucket_rm_obj_instance_op(): failed to decode request\n");
1842 cls_rgw_obj_key dest_key
= op
.key
;
1843 if (dest_key
.instance
== "null") {
1844 dest_key
.instance
.clear();
1847 BIVerObjEntry
obj(hctx
, dest_key
);
1848 BIOLHEntry
olh(hctx
, dest_key
);
1850 int ret
= obj
.init();
1851 if (ret
== -ENOENT
) {
1852 return 0; /* already removed */
1855 CLS_LOG(0, "ERROR: obj.init() returned ret=%d", ret
);
1860 ret
= olh
.init(&olh_found
);
1862 CLS_LOG(0, "ERROR: olh.init() returned ret=%d", ret
);
1867 bool instance_only
= false;
1868 cls_rgw_obj_key
key(dest_key
.name
);
1869 ret
= convert_plain_entry_to_versioned(hctx
, key
, true, instance_only
);
1871 CLS_LOG(0, "ERROR: convert_plain_entry_to_versioned ret=%d", ret
);
1874 olh
.update(dest_key
, false);
1875 olh
.set_tag(op
.olh_tag
);
1880 if (!olh
.start_modify(op
.olh_epoch
)) {
1881 ret
= obj
.unlink_list_entry();
1886 if (obj
.is_delete_marker()) {
1890 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false, op
.olh_epoch
);
1894 rgw_bucket_olh_entry
& olh_entry
= olh
.get_entry();
1895 cls_rgw_obj_key
& olh_key
= olh_entry
.key
;
1896 CLS_LOG(20, "%s: updating olh log: existing olh entry: %s[%s] (delete_marker=%d)", __func__
,
1897 olh_key
.name
.c_str(), olh_key
.instance
.c_str(), olh_entry
.delete_marker
);
1899 if (olh_key
== dest_key
) {
1900 /* this is the current head, need to update! */
1901 cls_rgw_obj_key next_key
;
1903 ret
= obj
.find_next_key(&next_key
, &found
);
1905 CLS_LOG(0, "ERROR: obj.find_next_key() returned ret=%d", ret
);
1910 BIVerObjEntry
next(hctx
, next_key
);
1911 ret
= next
.write(olh
.get_epoch(), true);
1913 CLS_LOG(0, "ERROR: next.write() returned ret=%d", ret
);
1917 CLS_LOG(20, "%s: updating olh log: link olh -> %s[%s] (is_delete=%d)", __func__
,
1918 next_key
.name
.c_str(), next_key
.instance
.c_str(), (int)next
.is_delete_marker());
1920 olh
.update(next_key
, next
.is_delete_marker());
1921 olh
.update_log(CLS_RGW_OLH_OP_LINK_OLH
, op
.op_tag
, next_key
, next
.is_delete_marker());
1923 // next_key is empty, but we need to preserve its name in case this entry
1924 // gets resharded, because this key is used for hash placement
1925 next_key
.name
= dest_key
.name
;
1926 olh
.update(next_key
, false);
1927 olh
.update_log(CLS_RGW_OLH_OP_UNLINK_OLH
, op
.op_tag
, next_key
, false);
1928 olh
.set_exists(false);
1929 olh
.set_pending_removal(true);
1933 if (!obj
.is_delete_marker()) {
1934 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false);
1936 /* this is a delete marker, it's our responsibility to remove its
1944 ret
= obj
.unlink_list_entry();
1958 rgw_bucket_dir_header header
;
1959 ret
= read_bucket_header(hctx
, &header
);
1961 CLS_LOG(1, "ERROR: rgw_bucket_unlink_instance(): failed to read header\n");
1964 if (header
.syncstopped
) {
1968 rgw_bucket_entry_ver ver
;
1969 ver
.epoch
= (op
.olh_epoch
? op
.olh_epoch
: olh
.get_epoch());
1971 real_time mtime
= obj
.mtime(); /* mtime has no real meaning in
1972 * instance removal context */
1973 ret
= log_index_operation(hctx
, op
.key
, CLS_RGW_OP_UNLINK_INSTANCE
, op
.op_tag
,
1975 CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
,
1976 op
.bilog_flags
| RGW_BILOG_FLAG_VERSIONED_OP
, NULL
, NULL
, &op
.zones_trace
);
1980 return write_bucket_header(hctx
, &header
); /* updates header version */
1983 static int rgw_bucket_read_olh_log(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1985 CLS_LOG(10, "entered %s", __func__
);
1987 rgw_cls_read_olh_log_op op
;
1988 auto iter
= in
->cbegin();
1991 } catch (ceph::buffer::error
& err
) {
1992 CLS_LOG(0, "ERROR: rgw_bucket_read_olh_log(): failed to decode request\n");
1996 if (!op
.olh
.instance
.empty()) {
1997 CLS_LOG(1, "bad key passed in (non empty instance)");
2001 rgw_bucket_olh_entry olh_data_entry
;
2002 string olh_data_key
;
2003 encode_olh_data_key(op
.olh
, &olh_data_key
);
2004 int ret
= read_index_entry(hctx
, olh_data_key
, &olh_data_entry
);
2005 if (ret
< 0 && ret
!= -ENOENT
) {
2006 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
2010 if (olh_data_entry
.tag
!= op
.olh_tag
) {
2011 CLS_LOG(1, "NOTICE: %s: olh_tag_mismatch olh_data_entry.tag=%s op.olh_tag=%s", __func__
, olh_data_entry
.tag
.c_str(), op
.olh_tag
.c_str());
2015 rgw_cls_read_olh_log_ret op_ret
;
2017 #define MAX_OLH_LOG_ENTRIES 1000
2018 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >& log
= olh_data_entry
.pending_log
;
2020 if (log
.begin()->first
> op
.ver_marker
&& log
.size() <= MAX_OLH_LOG_ENTRIES
) {
2022 op_ret
.is_truncated
= false;
2024 auto iter
= log
.upper_bound(op
.ver_marker
);
2026 for (int i
= 0; i
< MAX_OLH_LOG_ENTRIES
&& iter
!= log
.end(); ++i
, ++iter
) {
2027 op_ret
.log
[iter
->first
] = iter
->second
;
2029 op_ret
.is_truncated
= (iter
!= log
.end());
2032 encode(op_ret
, *out
);
2037 static int rgw_bucket_trim_olh_log(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2039 CLS_LOG(10, "entered %s", __func__
);
2041 rgw_cls_trim_olh_log_op op
;
2042 auto iter
= in
->cbegin();
2045 } catch (ceph::buffer::error
& err
) {
2046 CLS_LOG(0, "ERROR: rgw_bucket_trim_olh_log(): failed to decode request\n");
2050 if (!op
.olh
.instance
.empty()) {
2051 CLS_LOG(1, "bad key passed in (non empty instance)");
2055 /* read olh entry */
2056 rgw_bucket_olh_entry olh_data_entry
;
2057 string olh_data_key
;
2058 encode_olh_data_key(op
.olh
, &olh_data_key
);
2059 int ret
= read_index_entry(hctx
, olh_data_key
, &olh_data_entry
);
2060 if (ret
< 0 && ret
!= -ENOENT
) {
2061 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
2065 if (olh_data_entry
.tag
!= op
.olh_tag
) {
2066 CLS_LOG(1, "NOTICE: %s: olh_tag_mismatch olh_data_entry.tag=%s op.olh_tag=%s", __func__
, olh_data_entry
.tag
.c_str(), op
.olh_tag
.c_str());
2070 /* remove all versions up to and including ver from the pending map */
2071 auto& log
= olh_data_entry
.pending_log
;
2072 auto liter
= log
.begin();
2073 while (liter
!= log
.end() && liter
->first
<= op
.ver
) {
2074 auto rm_iter
= liter
;
2079 /* write the olh data entry */
2080 ret
= write_entry(hctx
, olh_data_entry
, olh_data_key
);
2082 CLS_LOG(0, "ERROR: write_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
2089 static int rgw_bucket_clear_olh(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2091 CLS_LOG(10, "entered %s", __func__
);
2093 rgw_cls_bucket_clear_olh_op op
;
2094 auto iter
= in
->cbegin();
2097 } catch (ceph::buffer::error
& err
) {
2098 CLS_LOG(0, "ERROR: rgw_bucket_clear_olh(): failed to decode request\n");
2102 if (!op
.key
.instance
.empty()) {
2103 CLS_LOG(1, "bad key passed in (non empty instance)");
2107 /* read olh entry */
2108 rgw_bucket_olh_entry olh_data_entry
;
2109 string olh_data_key
;
2110 encode_olh_data_key(op
.key
, &olh_data_key
);
2111 int ret
= read_index_entry(hctx
, olh_data_key
, &olh_data_entry
);
2112 if (ret
< 0 && ret
!= -ENOENT
) {
2113 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
2117 if (olh_data_entry
.tag
!= op
.olh_tag
) {
2118 CLS_LOG(1, "NOTICE: %s: olh_tag_mismatch olh_data_entry.tag=%s op.olh_tag=%s", __func__
, olh_data_entry
.tag
.c_str(), op
.olh_tag
.c_str());
2122 ret
= cls_cxx_map_remove_key(hctx
, olh_data_key
);
2124 CLS_LOG(1, "NOTICE: %s: can't remove key %s ret=%d", __func__
, olh_data_key
.c_str(), ret
);
2128 rgw_bucket_dir_entry plain_entry
;
2130 /* read plain entry, make sure it's a versioned place holder */
2131 ret
= read_index_entry(hctx
, op
.key
.name
, &plain_entry
);
2132 if (ret
== -ENOENT
) {
2133 /* we're done, no entry existing */
2137 CLS_LOG(0, "ERROR: read_index_entry key=%s ret=%d", op
.key
.name
.c_str(), ret
);
2141 if ((plain_entry
.flags
& rgw_bucket_dir_entry::FLAG_VER_MARKER
) == 0) {
2142 /* it's not a version marker, don't remove it */
2146 ret
= cls_cxx_map_remove_key(hctx
, op
.key
.name
);
2148 CLS_LOG(1, "NOTICE: %s: can't remove key %s ret=%d", __func__
, op
.key
.name
.c_str(), ret
);
2155 int rgw_dir_suggest_changes(cls_method_context_t hctx
,
2156 bufferlist
*in
, bufferlist
*out
)
2158 CLS_LOG(1, "entered %s", __func__
);
2160 bufferlist header_bl
;
2161 rgw_bucket_dir_header header
;
2162 bool header_changed
= false;
2164 int rc
= read_bucket_header(hctx
, &header
);
2166 CLS_LOG(1, "ERROR: rgw_dir_suggest_changes(): failed to read header\n");
2170 timespan
tag_timeout(
2171 std::chrono::seconds(
2172 header
.tag_timeout
? header
.tag_timeout
: CEPH_RGW_TAG_TIMEOUT
));
2174 auto in_iter
= in
->cbegin();
2176 while (!in_iter
.end()) {
2178 rgw_bucket_dir_entry cur_change
;
2179 rgw_bucket_dir_entry cur_disk
;
2181 decode(op
, in_iter
);
2182 decode(cur_change
, in_iter
);
2183 } catch (ceph::buffer::error
& err
) {
2184 CLS_LOG(1, "ERROR: rgw_dir_suggest_changes(): failed to decode request\n");
2188 bufferlist cur_disk_bl
;
2189 string cur_change_key
;
2190 encode_obj_index_key(cur_change
.key
, &cur_change_key
);
2191 int ret
= cls_cxx_map_get_val(hctx
, cur_change_key
, &cur_disk_bl
);
2192 if (ret
< 0 && ret
!= -ENOENT
)
2195 if (ret
== -ENOENT
) {
2199 if (cur_disk_bl
.length()) {
2200 auto cur_disk_iter
= cur_disk_bl
.cbegin();
2202 decode(cur_disk
, cur_disk_iter
);
2203 } catch (ceph::buffer::error
& error
) {
2204 CLS_LOG(1, "ERROR: rgw_dir_suggest_changes(): failed to decode cur_disk\n");
2208 // remove any pending entries whose tag timeout has expired. until expiry,
2209 // these pending entries will prevent us from applying suggested changes
2210 real_time cur_time
= real_clock::now();
2211 auto iter
= cur_disk
.pending_map
.begin();
2212 while(iter
!= cur_disk
.pending_map
.end()) {
2213 auto cur_iter
= iter
++;
2214 if (cur_time
> (cur_iter
->second
.timestamp
+ timespan(tag_timeout
))) {
2215 cur_disk
.pending_map
.erase(cur_iter
);
2220 CLS_LOG(20, "cur_disk.pending_map.empty()=%d op=%d cur_disk.exists=%d "
2221 "cur_disk.index_ver=%d cur_change.exists=%d cur_change.index_ver=%d",
2222 cur_disk
.pending_map
.empty(), (int)op
, cur_disk
.exists
,
2223 (int)cur_disk
.index_ver
, cur_change
.exists
,
2224 (int)cur_change
.index_ver
);
2226 if (cur_change
.index_ver
< cur_disk
.index_ver
) {
2227 // a pending on-disk entry was completed since this suggestion was made,
2228 // don't apply it yet. if the index really is inconsistent, the next
2229 // listing will get the latest version and resend the suggestion
2233 if (cur_disk
.pending_map
.empty()) {
2234 if (cur_disk
.exists
) {
2235 rgw_bucket_category_stats
& old_stats
= header
.stats
[cur_disk
.meta
.category
];
2236 CLS_LOG(10, "total_entries: %" PRId64
" -> %" PRId64
"", old_stats
.num_entries
, old_stats
.num_entries
- 1);
2237 old_stats
.num_entries
--;
2238 old_stats
.total_size
-= cur_disk
.meta
.accounted_size
;
2239 old_stats
.total_size_rounded
-= cls_rgw_get_rounded_size(cur_disk
.meta
.accounted_size
);
2240 old_stats
.actual_size
-= cur_disk
.meta
.size
;
2241 header_changed
= true;
2243 rgw_bucket_category_stats
& stats
= header
.stats
[cur_change
.meta
.category
];
2244 bool log_op
= (op
& CEPH_RGW_DIR_SUGGEST_LOG_OP
) != 0;
2245 op
&= CEPH_RGW_DIR_SUGGEST_OP_MASK
;
2247 case CEPH_RGW_REMOVE
:
2248 CLS_LOG(10, "CEPH_RGW_REMOVE name=%s instance=%s", cur_change
.key
.name
.c_str(), cur_change
.key
.instance
.c_str());
2249 ret
= cls_cxx_map_remove_key(hctx
, cur_change_key
);
2252 if (log_op
&& cur_disk
.exists
&& !header
.syncstopped
) {
2253 ret
= log_index_operation(hctx
, cur_disk
.key
, CLS_RGW_OP_DEL
, cur_disk
.tag
, cur_disk
.meta
.mtime
,
2254 cur_disk
.ver
, CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, 0, NULL
, NULL
, NULL
);
2256 CLS_LOG(0, "ERROR: %s: failed to log operation ret=%d", __func__
, ret
);
2261 case CEPH_RGW_UPDATE
:
2262 CLS_LOG(10, "CEPH_RGW_UPDATE name=%s instance=%s total_entries: %" PRId64
" -> %" PRId64
"",
2263 cur_change
.key
.name
.c_str(), cur_change
.key
.instance
.c_str(), stats
.num_entries
, stats
.num_entries
+ 1);
2265 stats
.num_entries
++;
2266 stats
.total_size
+= cur_change
.meta
.accounted_size
;
2267 stats
.total_size_rounded
+= cls_rgw_get_rounded_size(cur_change
.meta
.accounted_size
);
2268 stats
.actual_size
+= cur_change
.meta
.size
;
2269 header_changed
= true;
2270 cur_change
.index_ver
= header
.ver
;
2271 bufferlist cur_state_bl
;
2272 encode(cur_change
, cur_state_bl
);
2273 ret
= cls_cxx_map_set_val(hctx
, cur_change_key
, &cur_state_bl
);
2276 if (log_op
&& !header
.syncstopped
) {
2277 ret
= log_index_operation(hctx
, cur_change
.key
, CLS_RGW_OP_ADD
, cur_change
.tag
, cur_change
.meta
.mtime
,
2278 cur_change
.ver
, CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, 0, NULL
, NULL
, NULL
);
2280 CLS_LOG(0, "ERROR: %s: failed to log operation ret=%d", __func__
, ret
);
2286 } // if (cur_disk.pending_map.empty())
2287 } // while (!in_iter.end())
2289 if (header_changed
) {
2290 return write_bucket_header(hctx
, &header
);
2295 static int rgw_obj_remove(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2297 CLS_LOG(10, "entered %s", __func__
);
2299 rgw_cls_obj_remove_op op
;
2300 auto iter
= in
->cbegin();
2303 } catch (ceph::buffer::error
& err
) {
2304 CLS_LOG(0, "ERROR: %s: failed to decode request", __func__
);
2308 if (op
.keep_attr_prefixes
.empty()) {
2309 return cls_cxx_remove(hctx
);
2312 map
<string
, bufferlist
> attrset
;
2313 int ret
= cls_cxx_getxattrs(hctx
, &attrset
);
2314 if (ret
< 0 && ret
!= -ENOENT
) {
2315 CLS_LOG(0, "ERROR: %s: cls_cxx_getxattrs() returned %d", __func__
, ret
);
2319 map
<string
, bufferlist
> new_attrs
;
2320 for (auto iter
= op
.keep_attr_prefixes
.begin();
2321 iter
!= op
.keep_attr_prefixes
.end(); ++iter
) {
2322 auto& check_prefix
= *iter
;
2324 for (auto aiter
= attrset
.lower_bound(check_prefix
);
2325 aiter
!= attrset
.end(); ++aiter
) {
2326 const string
& attr
= aiter
->first
;
2328 if (attr
.substr(0, check_prefix
.size()) > check_prefix
) {
2332 new_attrs
[attr
] = aiter
->second
;
2336 CLS_LOG(20, "%s: removing object", __func__
);
2337 ret
= cls_cxx_remove(hctx
);
2339 CLS_LOG(0, "ERROR: %s: cls_cxx_remove returned %d", __func__
, ret
);
2343 if (new_attrs
.empty()) {
2344 /* no data to keep */
2348 ret
= cls_cxx_create(hctx
, false);
2350 CLS_LOG(0, "ERROR: %s: cls_cxx_create returned %d", __func__
, ret
);
2354 for (auto aiter
= new_attrs
.begin();
2355 aiter
!= new_attrs
.end(); ++aiter
) {
2356 const auto& attr
= aiter
->first
;
2358 ret
= cls_cxx_setxattr(hctx
, attr
.c_str(), &aiter
->second
);
2359 CLS_LOG(20, "%s: setting attr: %s", __func__
, attr
.c_str());
2361 CLS_LOG(0, "ERROR: %s: cls_cxx_setxattr (attr=%s) returned %d", __func__
, attr
.c_str(), ret
);
2369 static int rgw_obj_store_pg_ver(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2371 CLS_LOG(10, "entered %s", __func__
);
2373 rgw_cls_obj_store_pg_ver_op op
;
2374 auto iter
= in
->cbegin();
2377 } catch (ceph::buffer::error
& err
) {
2378 CLS_LOG(0, "ERROR: %s: failed to decode request", __func__
);
2383 uint64_t ver
= cls_current_version(hctx
);
2385 int ret
= cls_cxx_setxattr(hctx
, op
.attr
.c_str(), &bl
);
2387 CLS_LOG(0, "ERROR: %s: cls_cxx_setxattr (attr=%s) returned %d", __func__
, op
.attr
.c_str(), ret
);
2394 static int rgw_obj_check_attrs_prefix(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2396 CLS_LOG(10, "entered %s", __func__
);
2398 rgw_cls_obj_check_attrs_prefix op
;
2399 auto iter
= in
->cbegin();
2402 } catch (ceph::buffer::error
& err
) {
2403 CLS_LOG(0, "ERROR: %s: failed to decode request", __func__
);
2407 if (op
.check_prefix
.empty()) {
2411 map
<string
, bufferlist
> attrset
;
2412 int ret
= cls_cxx_getxattrs(hctx
, &attrset
);
2413 if (ret
< 0 && ret
!= -ENOENT
) {
2414 CLS_LOG(0, "ERROR: %s: cls_cxx_getxattrs() returned %d", __func__
, ret
);
2420 for (auto aiter
= attrset
.lower_bound(op
.check_prefix
);
2421 aiter
!= attrset
.end(); ++aiter
) {
2422 const auto& attr
= aiter
->first
;
2424 if (attr
.substr(0, op
.check_prefix
.size()) > op
.check_prefix
) {
2431 if (exist
== op
.fail_if_exist
) {
2438 static int rgw_obj_check_mtime(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2440 CLS_LOG(10, "entered %s", __func__
);
2442 rgw_cls_obj_check_mtime op
;
2443 auto iter
= in
->cbegin();
2446 } catch (ceph::buffer::error
& err
) {
2447 CLS_LOG(0, "ERROR: %s: failed to decode request", __func__
);
2452 int ret
= cls_cxx_stat2(hctx
, NULL
, &obj_ut
);
2453 if (ret
< 0 && ret
!= -ENOENT
) {
2454 CLS_LOG(0, "ERROR: %s: cls_cxx_stat() returned %d", __func__
, ret
);
2457 if (ret
== -ENOENT
) {
2458 CLS_LOG(10, "object does not exist, skipping check");
2461 ceph_timespec obj_ts
= ceph::real_clock::to_ceph_timespec(obj_ut
);
2462 ceph_timespec op_ts
= ceph::real_clock::to_ceph_timespec(op
.mtime
);
2464 if (!op
.high_precision_time
) {
2469 CLS_LOG(10, "%s: obj_ut=%lld.%06lld op.mtime=%lld.%06lld", __func__
,
2470 (long long)obj_ts
.tv_sec
, (long long)obj_ts
.tv_nsec
,
2471 (long long)op_ts
.tv_sec
, (long long)op_ts
.tv_nsec
);
2476 case CLS_RGW_CHECK_TIME_MTIME_EQ
:
2477 check
= (obj_ts
== op_ts
);
2479 case CLS_RGW_CHECK_TIME_MTIME_LT
:
2480 check
= (obj_ts
< op_ts
);
2482 case CLS_RGW_CHECK_TIME_MTIME_LE
:
2483 check
= (obj_ts
<= op_ts
);
2485 case CLS_RGW_CHECK_TIME_MTIME_GT
:
2486 check
= (obj_ts
> op_ts
);
2488 case CLS_RGW_CHECK_TIME_MTIME_GE
:
2489 check
= (obj_ts
>= op_ts
);
2502 static int rgw_bi_get_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2504 CLS_LOG(10, "entered %s", __func__
);
2506 rgw_cls_bi_get_op op
;
2507 auto iter
= in
->cbegin();
2510 } catch (ceph::buffer::error
& err
) {
2511 CLS_LOG(0, "ERROR: %s: failed to decode request", __func__
);
2518 case BIIndexType::Plain
:
2521 case BIIndexType::Instance
:
2522 encode_obj_index_key(op
.key
, &idx
);
2524 case BIIndexType::OLH
:
2525 encode_olh_data_key(op
.key
, &idx
);
2528 CLS_LOG(10, "%s: invalid key type encoding: %d",
2529 __func__
, int(op
.type
));
2533 rgw_cls_bi_get_ret op_ret
;
2535 rgw_cls_bi_entry
& entry
= op_ret
.entry
;
2537 entry
.type
= op
.type
;
2540 int r
= cls_cxx_map_get_val(hctx
, idx
, &entry
.data
);
2542 CLS_LOG(10, "%s: cls_cxx_map_get_val() returned %d", __func__
, r
);
2546 encode(op_ret
, *out
);
2551 static int rgw_bi_put_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2553 CLS_LOG(10, "entered %s", __func__
);
2555 rgw_cls_bi_put_op op
;
2556 auto iter
= in
->cbegin();
2559 } catch (ceph::buffer::error
& err
) {
2560 CLS_LOG(0, "ERROR: %s: failed to decode request", __func__
);
2564 rgw_cls_bi_entry
& entry
= op
.entry
;
2566 int r
= cls_cxx_map_set_val(hctx
, entry
.idx
, &entry
.data
);
2568 CLS_LOG(0, "ERROR: %s: cls_cxx_map_set_val() returned r=%d", __func__
, r
);
2575 /* The plain entries in the bucket index are divided into two regions
2576 * divided by the special entries that begin with 0x80. Those below
2577 * ("Low") are ascii entries. Those above ("High") bring in unicode
2578 * entries. This enum allows either or both regions to be listed in
2579 * list_plain_entries(). It's convenient that "Both" be in between the
2580 * others so we can use "<= Both" or ">= Both" logic.
2582 enum class PlainEntriesRegion
{
2587 /* Queries the omap for plain entries in the range of start_after_key
2588 * to end_key, non-inclusive. Both of those values must either be
2589 * before the "ugly namespace" or after it.
2591 * Negative return values indicate errors. Non-negative return values
2592 * indicate number of entries retrieved. */
2593 static int list_plain_entries_help(cls_method_context_t hctx
,
2594 const std::string
& name_filter
,
2595 const std::string
& start_after_key
, // exclusive
2596 const std::string
& end_key
, // exclusive
2598 std::list
<rgw_cls_bi_entry
>* entries
,
2599 bool& end_key_reached
,
2602 CLS_LOG(10, "Entered %s: name_filter=\"%s\", start_after_key=\"%s\", end_key=\"%s\", max=%d",
2603 __func__
, escape_str(name_filter
).c_str(), escape_str(start_after_key
).c_str(),
2604 escape_str(end_key
).c_str(), max
);
2606 std::map
<std::string
, bufferlist
> raw_entries
;
2607 int ret
= cls_cxx_map_get_vals(hctx
, start_after_key
, name_filter
, max
,
2608 &raw_entries
, &more
);
2609 CLS_LOG(20, "%s: cls_cxx_map_get_vals ret=%d, raw_entries.size()=%lu, more=%d",
2610 __func__
, ret
, raw_entries
.size(), more
);
2615 end_key_reached
= false;
2616 for (auto iter
: raw_entries
) {
2617 if (!end_key
.empty() && iter
.first
>= end_key
) {
2618 CLS_LOG(20, "%s: end key reached at \"%s\"",
2619 __func__
, escape_str(iter
.first
).c_str());
2620 end_key_reached
= true;
2625 rgw_bucket_dir_entry e
;
2626 auto biter
= iter
.second
.cbegin();
2629 } catch (ceph::buffer::error
& err
) {
2630 CLS_LOG(0, "ERROR: %s: failed to decode buffer for plain bucket index entry \"%s\"",
2631 __func__
, escape_str(iter
.first
).c_str());
2635 if (!name_filter
.empty() && e
.key
.name
> name_filter
) {
2636 CLS_LOG(20, "%s: due to filter \"%s\", skipping entry.idx=\"%s\" e.key.name=\"%s\"",
2638 escape_str(name_filter
).c_str(),
2639 escape_str(iter
.first
).c_str(),
2640 escape_str(e
.key
.name
).c_str());
2641 // skip the rest of the entries
2643 end_key_reached
= true;
2647 rgw_cls_bi_entry entry
;
2648 entry
.type
= BIIndexType::Plain
;
2649 entry
.idx
= iter
.first
;
2650 entry
.data
= iter
.second
;
2652 entries
->push_back(entry
);
2655 CLS_LOG(20, "%s: adding entry %d entry.idx=\"%s\" e.key.name=\"%s\"",
2658 escape_str(entry
.idx
).c_str(),
2659 escape_str(e
.key
.name
).c_str());
2661 if (count
>= int(max
)) {
2662 // NB: this looks redundant, but leave in for time being
2668 } // list_plain_entries_help
2671 * Lists plain entries in either or both regions, the region of those
2672 * beginning with an ASCII character or a non-ASCII character, which
2673 * surround the "ugly" namespace used by special entries for versioned
2676 * The entries parameter is not cleared and additional entries are
2679 static int list_plain_entries(cls_method_context_t hctx
,
2680 const std::string
& name_filter
,
2681 const std::string
& marker
,
2683 std::list
<rgw_cls_bi_entry
>* entries
,
2685 const PlainEntriesRegion region
= PlainEntriesRegion::Both
)
2687 CLS_LOG(10, "entered %s: name_filter=\"%s\", marker=\"%s\", max=%d, region=%d",
2688 __func__
, escape_str(name_filter
).c_str(), escape_str(marker
).c_str(), max
, static_cast<int>(region
));
2690 bool end_key_reached
= false;
2692 const size_t start_size
= entries
->size();
2694 if (region
<= PlainEntriesRegion::Both
&& marker
< BI_PREFIX_BEGIN
) {
2695 // listing ascii plain namespace
2696 int r
= list_plain_entries_help(hctx
, name_filter
, marker
, BI_PREFIX_BEGIN
, max
,
2697 entries
, end_key_reached
, more
);
2698 CLS_LOG(20, "%s: first list_plain_entries_help r=%d, end_key_reached=%d, more=%d",
2699 __func__
, r
, end_key_reached
, more
);
2704 // see if we're done for this call (there may be more for a later call)
2705 if (r
>= int(max
) || !end_key_reached
|| (!more
&& region
== PlainEntriesRegion::Low
)) {
2710 return int(entries
->size() - start_size
);
2716 if (region
>= PlainEntriesRegion::Both
) {
2717 const std::string start_after_key
= std::max(marker
, BI_PREFIX_END
);
2719 // listing non-ascii plain namespace
2720 r
= list_plain_entries_help(hctx
, name_filter
, start_after_key
, {}, max
,
2721 entries
, end_key_reached
, more
);
2722 CLS_LOG(20, "%s: second list_plain_entries_help r=%d, end_key_reached=%d, more=%d",
2723 __func__
, r
, end_key_reached
, more
);
2733 return int(entries
->size() - start_size
);
2736 static int list_instance_entries(cls_method_context_t hctx
,
2738 const string
& marker
,
2740 list
<rgw_cls_bi_entry
> *entries
,
2743 cls_rgw_obj_key
key(name
);
2744 string first_instance_idx
;
2745 encode_obj_versioned_data_key(key
, &first_instance_idx
);
2746 string start_after_key
;
2748 if (!name
.empty()) {
2749 start_after_key
= first_instance_idx
;
2751 start_after_key
= BI_PREFIX_CHAR
;
2752 start_after_key
.append(bucket_index_prefixes
[BI_BUCKET_OBJ_INSTANCE_INDEX
]);
2754 string filter
= start_after_key
;
2755 if (bi_entry_gt(marker
, start_after_key
)) {
2756 start_after_key
= marker
;
2759 map
<string
, bufferlist
> keys
;
2761 int ret
= cls_cxx_map_get_val(hctx
, start_after_key
, &k
);
2762 if (ret
< 0 && ret
!= -ENOENT
) {
2765 bool found_first
= (ret
== 0);
2770 ret
= cls_cxx_map_get_vals(hctx
, start_after_key
, string(), max
,
2772 CLS_LOG(20, "%s: start_after_key=\"%s\" first_instance_idx=\"%s\" keys.size()=%d",
2773 __func__
, escape_str(start_after_key
).c_str(),
2774 escape_str(first_instance_idx
).c_str(), (int)keys
.size());
2780 keys
[start_after_key
] = std::move(k
);
2783 for (auto iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
2784 rgw_cls_bi_entry entry
;
2785 entry
.type
= BIIndexType::Instance
;
2786 entry
.idx
= iter
->first
;
2787 entry
.data
= iter
->second
;
2789 if (!filter
.empty() && entry
.idx
.compare(0, filter
.size(), filter
) != 0) {
2790 /* we are skipping the rest of the entries */
2797 CLS_LOG(20, "%s: entry.idx=\"%s\"", __func__
, escape_str(entry
.idx
).c_str());
2799 auto biter
= entry
.data
.cbegin();
2801 rgw_bucket_dir_entry e
;
2804 } catch (ceph::buffer::error
& err
) {
2805 CLS_LOG(0, "ERROR: %s: failed to decode buffer (size=%d)", __func__
, entry
.data
.length());
2809 if (!name
.empty() && e
.key
.name
!= name
) {
2810 /* we are skipping the rest of the entries */
2817 entries
->push_back(entry
);
2819 start_after_key
= entry
.idx
;
2825 static int list_olh_entries(cls_method_context_t hctx
,
2827 const string
& marker
,
2829 list
<rgw_cls_bi_entry
> *entries
,
2832 cls_rgw_obj_key
key(name
);
2833 string first_instance_idx
;
2834 encode_olh_data_key(key
, &first_instance_idx
);
2835 string start_after_key
;
2837 if (!name
.empty()) {
2838 start_after_key
= first_instance_idx
;
2840 start_after_key
= BI_PREFIX_CHAR
;
2841 start_after_key
.append(bucket_index_prefixes
[BI_BUCKET_OLH_DATA_INDEX
]);
2843 string filter
= start_after_key
;
2844 if (bi_entry_gt(marker
, start_after_key
)) {
2845 start_after_key
= marker
;
2848 map
<string
, bufferlist
> keys
;
2851 ret
= cls_cxx_map_get_val(hctx
, start_after_key
, &k
);
2852 if (ret
< 0 && ret
!= -ENOENT
) {
2855 bool found_first
= (ret
== 0);
2860 ret
= cls_cxx_map_get_vals(hctx
, start_after_key
, string(), max
,
2862 CLS_LOG(20, "%s: start_after_key=\"%s\", first_instance_idx=\"%s\", keys.size()=%d",
2863 __func__
, escape_str(start_after_key
).c_str(),
2864 escape_str(first_instance_idx
).c_str(), (int)keys
.size());
2871 keys
[start_after_key
] = std::move(k
);
2874 for (auto iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
2875 rgw_cls_bi_entry entry
;
2876 entry
.type
= BIIndexType::OLH
;
2877 entry
.idx
= iter
->first
;
2878 entry
.data
= iter
->second
;
2880 if (!filter
.empty() && entry
.idx
.compare(0, filter
.size(), filter
) != 0) {
2881 /* we are skipping the rest of the entries */
2888 CLS_LOG(20, "%s: entry.idx=\"%s\"", __func__
, escape_str(entry
.idx
).c_str());
2890 auto biter
= entry
.data
.cbegin();
2892 rgw_bucket_olh_entry e
;
2895 } catch (ceph::buffer::error
& err
) {
2896 CLS_LOG(0, "ERROR: %s: failed to decode buffer (size=%d)", __func__
, entry
.data
.length());
2900 if (!name
.empty() && e
.key
.name
!= name
) {
2901 /* we are skipping the rest of the entries */
2908 entries
->push_back(entry
);
2910 start_after_key
= entry
.idx
;
2916 /* Lists all the entries that appear in a bucket index listing.
2918 * It may not be obvious why this function calls three other "segment"
2919 * functions (list_plain_entries (twice), list_instance_entries,
2920 * list_olh_entries) that each list segments of the index space rather
2921 * than just move a marker through the space from start to end. The
2922 * reason is that a name filter may be provided in the op, and in that
2923 * case most entries will be skipped over, and small segments within
2924 * each larger segment will be listed.
2926 * Ideally, each of the three segment functions should be able to
2927 * handle a marker and filter, if either/both is provided,
2928 * efficiently. So, for example, if the marker is after the segment,
2929 * ideally return quickly rather than iterating through entries in the
2932 * Additionally, each of the three segment functions, if successful,
2933 * is expected to return the number of entries added to the output
2934 * list as a non-negative value. As per usual, negative return values
2935 * indicate error condtions.
2937 static int rgw_bi_list_op(cls_method_context_t hctx
,
2941 CLS_LOG(10, "entered %s", __func__
);
2943 rgw_cls_bi_list_op op
;
2944 auto iter
= in
->cbegin();
2947 } catch (ceph::buffer::error
& err
) {
2948 CLS_LOG(0, "ERROR: %s: failed to decode request", __func__
);
2952 constexpr uint32_t MAX_BI_LIST_ENTRIES
= 1000;
2953 const uint32_t max
= std::min(op
.max
, MAX_BI_LIST_ENTRIES
);
2955 CLS_LOG(20, "%s: op.marker=\"%s\", op.name_filter=\"%s\", op.max=%u max=%u",
2956 __func__
, escape_str(op
.marker
).c_str(), escape_str(op
.name_filter
).c_str(),
2962 rgw_cls_bi_list_ret op_ret
;
2964 ret
= list_plain_entries(hctx
, op
.name_filter
, op
.marker
, max
,
2965 &op_ret
.entries
, &more
, PlainEntriesRegion::Low
);
2967 CLS_LOG(0, "ERROR: %s: list_plain_entries (low) returned ret=%d, marker=\"%s\", filter=\"%s\", max=%d",
2968 __func__
, ret
, escape_str(op
.marker
).c_str(), escape_str(op
.name_filter
).c_str(), max
);
2973 CLS_LOG(20, "%s: found %d plain ascii (low) entries, count=%u", __func__
, ret
, count
);
2976 ret
= list_instance_entries(hctx
, op
.name_filter
, op
.marker
, max
- count
, &op_ret
.entries
, &more
);
2978 CLS_LOG(0, "ERROR: %s: list_instance_entries returned ret=%d", __func__
, ret
);
2983 CLS_LOG(20, "%s: found %d instance entries, count=%u", __func__
, ret
, count
);
2987 ret
= list_olh_entries(hctx
, op
.name_filter
, op
.marker
, max
- count
, &op_ret
.entries
, &more
);
2989 CLS_LOG(0, "ERROR: %s: list_olh_entries returned ret=%d", __func__
, ret
);
2994 CLS_LOG(20, "%s: found %d olh entries, count=%u", __func__
, ret
, count
);
2998 ret
= list_plain_entries(hctx
, op
.name_filter
, op
.marker
, max
- count
,
2999 &op_ret
.entries
, &more
, PlainEntriesRegion::High
);
3001 CLS_LOG(0, "ERROR: %s: list_plain_entries (high) returned ret=%d, marker=\"%s\", filter=\"%s\", max=%d",
3002 __func__
, ret
, escape_str(op
.marker
).c_str(), escape_str(op
.name_filter
).c_str(), max
);
3007 CLS_LOG(20, "%s: found %d non-ascii (high) plain entries, count=%u", __func__
, ret
, count
);
3010 op_ret
.is_truncated
= (count
> max
) || more
;
3011 while (count
> max
) {
3012 op_ret
.entries
.pop_back();
3016 CLS_LOG(20, "%s: returning %lu entries, is_truncated=%d", __func__
, op_ret
.entries
.size(), op_ret
.is_truncated
);
3017 encode(op_ret
, *out
);
3023 int bi_log_record_decode(bufferlist
& bl
, rgw_bi_log_entry
& e
)
3025 auto iter
= bl
.cbegin();
3028 } catch (ceph::buffer::error
& err
) {
3029 CLS_LOG(0, "ERROR: failed to decode rgw_bi_log_entry");
3036 static int bi_log_iterate_entries(cls_method_context_t hctx
,
3037 const string
& marker
,
3038 const string
& end_marker
,
3040 uint32_t max_entries
,
3042 int (*cb
)(cls_method_context_t
, const string
&, rgw_bi_log_entry
&, void *),
3045 CLS_LOG(10, "bi_log_iterate_range");
3047 map
<string
, bufferlist
> keys
;
3048 string filter_prefix
, end_key
;
3055 string start_after_key
;
3056 if (key_iter
.empty()) {
3057 key
= BI_PREFIX_CHAR
;
3058 key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
3061 start_after_key
= key
;
3063 start_after_key
= key_iter
;
3066 if (end_marker
.empty()) {
3067 end_key
= BI_PREFIX_CHAR
;
3068 end_key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
+ 1]);
3070 end_key
= BI_PREFIX_CHAR
;
3071 end_key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
3072 end_key
.append(end_marker
);
3075 CLS_LOG(10, "bi_log_iterate_entries start_after_key=%s end_key=%s",
3076 start_after_key
.c_str(), end_key
.c_str());
3080 int ret
= cls_cxx_map_get_vals(hctx
, start_after_key
, filter
, max_entries
,
3085 auto iter
= keys
.begin();
3086 if (iter
== keys
.end())
3089 uint32_t num_keys
= keys
.size();
3091 for (; iter
!= keys
.end(); ++iter
,++i
) {
3092 const string
& key
= iter
->first
;
3095 CLS_LOG(10, "bi_log_iterate_entries key=%s bl.length=%d", key
.c_str(), (int)iter
->second
.length());
3097 if (key
.compare(end_key
) > 0) {
3105 ret
= bi_log_record_decode(iter
->second
, e
);
3109 ret
= cb(hctx
, key
, e
, param
);
3113 if (i
== num_keys
- 1) {
3121 static int bi_log_list_cb(cls_method_context_t hctx
, const string
& key
, rgw_bi_log_entry
& info
, void *param
)
3123 list
<rgw_bi_log_entry
> *l
= (list
<rgw_bi_log_entry
> *)param
;
3128 static int bi_log_list_entries(cls_method_context_t hctx
, const string
& marker
,
3129 uint32_t max
, list
<rgw_bi_log_entry
>& entries
, bool *truncated
)
3133 int ret
= bi_log_iterate_entries(hctx
, marker
, end_marker
,
3134 key_iter
, max
, truncated
,
3135 bi_log_list_cb
, &entries
);
3139 static int rgw_bi_log_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3141 CLS_LOG(10, "entered %s", __func__
);
3142 auto in_iter
= in
->cbegin();
3144 cls_rgw_bi_log_list_op op
;
3146 decode(op
, in_iter
);
3147 } catch (ceph::buffer::error
& err
) {
3148 CLS_LOG(1, "ERROR: rgw_bi_log_list(): failed to decode entry\n");
3152 cls_rgw_bi_log_list_ret op_ret
;
3153 int ret
= bi_log_list_entries(hctx
, op
.marker
, op
.max
, op_ret
.entries
, &op_ret
.truncated
);
3157 encode(op_ret
, *out
);
3162 static int rgw_bi_log_trim(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3164 CLS_LOG(10, "entered %s", __func__
);
3165 auto in_iter
= in
->cbegin();
3167 cls_rgw_bi_log_trim_op op
;
3169 decode(op
, in_iter
);
3170 } catch (ceph::buffer::error
& err
) {
3171 CLS_LOG(1, "ERROR: rgw_bi_log_list(): failed to decode entry\n");
3175 string
key_begin(1, BI_PREFIX_CHAR
);
3176 key_begin
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
3177 key_begin
.append(op
.start_marker
);
3180 if (op
.end_marker
.empty()) {
3181 key_end
= BI_PREFIX_CHAR
;
3182 key_end
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
+ 1]);
3184 key_end
= BI_PREFIX_CHAR
;
3185 key_end
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
3186 key_end
.append(op
.end_marker
);
3187 // cls_cxx_map_remove_range() expects one-past-end
3188 key_end
.append(1, '\0');
3191 // list a single key to detect whether the range is empty
3192 const size_t max_entries
= 1;
3193 std::set
<std::string
> keys
;
3196 int rc
= cls_cxx_map_get_keys(hctx
, key_begin
, max_entries
, &keys
, &more
);
3198 CLS_LOG(1, "ERROR: cls_cxx_map_get_keys failed rc=%d", rc
);
3203 CLS_LOG(20, "range is empty key_begin=%s", key_begin
.c_str());
3207 const std::string
& first_key
= *keys
.begin();
3208 if (key_end
< first_key
) {
3209 CLS_LOG(20, "listed key %s past key_end=%s", first_key
.c_str(), key_end
.c_str());
3213 CLS_LOG(20, "listed key %s, removing through %s",
3214 first_key
.c_str(), key_end
.c_str());
3216 rc
= cls_cxx_map_remove_range(hctx
, first_key
, key_end
);
3218 CLS_LOG(1, "ERROR: cls_cxx_map_remove_range failed rc=%d", rc
);
3224 static int rgw_bi_log_resync(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3226 CLS_LOG(10, "entered %s", __func__
);
3227 rgw_bucket_dir_header header
;
3228 int rc
= read_bucket_header(hctx
, &header
);
3230 CLS_LOG(1, "ERROR: rgw_bucket_complete_op(): failed to read header\n");
3236 rgw_bi_log_entry entry
;
3238 entry
.timestamp
= real_clock::now();
3239 entry
.op
= RGWModifyOp::CLS_RGW_OP_RESYNC
;
3240 entry
.state
= RGWPendingState::CLS_RGW_STATE_COMPLETE
;
3243 bi_log_index_key(hctx
, key
, entry
.id
, header
.ver
);
3247 if (entry
.id
> header
.max_marker
)
3248 header
.max_marker
= entry
.id
;
3250 header
.syncstopped
= false;
3252 rc
= cls_cxx_map_set_val(hctx
, key
, &bl
);
3256 return write_bucket_header(hctx
, &header
);
3259 static int rgw_bi_log_stop(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3261 CLS_LOG(10, "entered %s", __func__
);
3262 rgw_bucket_dir_header header
;
3263 int rc
= read_bucket_header(hctx
, &header
);
3265 CLS_LOG(1, "ERROR: rgw_bucket_complete_op(): failed to read header\n");
3271 rgw_bi_log_entry entry
;
3273 entry
.timestamp
= real_clock::now();
3274 entry
.op
= RGWModifyOp::CLS_RGW_OP_SYNCSTOP
;
3275 entry
.state
= RGWPendingState::CLS_RGW_STATE_COMPLETE
;
3278 bi_log_index_key(hctx
, key
, entry
.id
, header
.ver
);
3282 if (entry
.id
> header
.max_marker
)
3283 header
.max_marker
= entry
.id
;
3284 header
.syncstopped
= true;
3286 rc
= cls_cxx_map_set_val(hctx
, key
, &bl
);
3290 return write_bucket_header(hctx
, &header
);
3294 static void usage_record_prefix_by_time(uint64_t epoch
, string
& key
)
3297 snprintf(buf
, sizeof(buf
), "%011llu", (long long unsigned)epoch
);
3301 static void usage_record_prefix_by_user(const string
& user
, uint64_t epoch
, string
& key
)
3303 char buf
[user
.size() + 32];
3304 snprintf(buf
, sizeof(buf
), "%s_%011llu_", user
.c_str(), (long long unsigned)epoch
);
3308 static void usage_record_name_by_time(uint64_t epoch
, const string
& user
, const string
& bucket
, string
& key
)
3310 char buf
[32 + user
.size() + bucket
.size()];
3311 snprintf(buf
, sizeof(buf
), "%011llu_%s_%s", (long long unsigned)epoch
, user
.c_str(), bucket
.c_str());
3315 static void usage_record_name_by_user(const string
& user
, uint64_t epoch
, const string
& bucket
, string
& key
)
3317 char buf
[32 + user
.size() + bucket
.size()];
3318 snprintf(buf
, sizeof(buf
), "%s_%011llu_%s", user
.c_str(), (long long unsigned)epoch
, bucket
.c_str());
3322 static int usage_record_decode(bufferlist
& record_bl
, rgw_usage_log_entry
& e
)
3324 auto kiter
= record_bl
.cbegin();
3327 } catch (ceph::buffer::error
& err
) {
3328 CLS_LOG(1, "ERROR: usage_record_decode(): failed to decode record_bl\n");
3335 int rgw_user_usage_log_add(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3337 CLS_LOG(10, "entered %s", __func__
);
3339 auto in_iter
= in
->cbegin();
3340 rgw_cls_usage_log_add_op op
;
3343 decode(op
, in_iter
);
3344 } catch (ceph::buffer::error
& err
) {
3345 CLS_LOG(1, "ERROR: rgw_user_usage_log_add(): failed to decode request\n");
3349 rgw_usage_log_info
& info
= op
.info
;
3351 for (auto iter
= info
.entries
.begin(); iter
!= info
.entries
.end(); ++iter
) {
3352 rgw_usage_log_entry
& entry
= *iter
;
3355 rgw_user
*puser
= (entry
.payer
.empty() ? &entry
.owner
: &entry
.payer
);
3357 usage_record_name_by_time(entry
.epoch
, puser
->to_str(), entry
.bucket
, key_by_time
);
3359 CLS_LOG(10, "rgw_user_usage_log_add user=%s bucket=%s", puser
->to_str().c_str(), entry
.bucket
.c_str());
3361 bufferlist record_bl
;
3362 int ret
= cls_cxx_map_get_val(hctx
, key_by_time
, &record_bl
);
3363 if (ret
< 0 && ret
!= -ENOENT
) {
3364 CLS_LOG(1, "ERROR: rgw_user_usage_log_add(): cls_cxx_map_read_key returned %d", ret
);
3368 rgw_usage_log_entry e
;
3369 ret
= usage_record_decode(record_bl
, e
);
3372 CLS_LOG(10, "rgw_user_usage_log_add aggregating existing bucket\n");
3376 bufferlist new_record_bl
;
3377 encode(entry
, new_record_bl
);
3378 ret
= cls_cxx_map_set_val(hctx
, key_by_time
, &new_record_bl
);
3383 usage_record_name_by_user(puser
->to_str(), entry
.epoch
, entry
.bucket
, key_by_user
);
3384 ret
= cls_cxx_map_set_val(hctx
, key_by_user
, &new_record_bl
);
3392 static int usage_iterate_range(cls_method_context_t hctx
, uint64_t start
, uint64_t end
, const string
& user
,
3393 const string
& bucket
, string
& key_iter
, uint32_t max_entries
, bool *truncated
,
3394 int (*cb
)(cls_method_context_t
, const string
&, rgw_usage_log_entry
&, void *),
3397 CLS_LOG(10, "entered %s", __func__
);
3399 map
<string
, bufferlist
> keys
;
3400 string filter_prefix
;
3401 string start_key
, end_key
;
3402 bool by_user
= !user
.empty();
3404 bool truncated_status
= false;
3406 ceph_assert(truncated
!= nullptr);
3409 usage_record_prefix_by_time(end
, end_key
);
3412 user_key
.append("_");
3415 if (key_iter
.empty()) {
3417 usage_record_prefix_by_user(user
, start
, start_key
);
3419 usage_record_prefix_by_time(start
, start_key
);
3422 start_key
= key_iter
;
3425 CLS_LOG(20, "usage_iterate_range start_key=%s", start_key
.c_str());
3426 int ret
= cls_cxx_map_get_vals(hctx
, start_key
, filter_prefix
, max_entries
, &keys
, &truncated_status
);
3430 *truncated
= truncated_status
;
3432 auto iter
= keys
.begin();
3433 if (iter
== keys
.end())
3436 for (; iter
!= keys
.end(); ++iter
) {
3437 const string
& key
= iter
->first
;
3438 rgw_usage_log_entry e
;
3441 if (!by_user
&& key
.compare(end_key
) >= 0) {
3442 CLS_LOG(20, "usage_iterate_range reached key=%s, done", key
.c_str());
3448 if (by_user
&& key
.compare(0, user_key
.size(), user_key
) != 0) {
3449 CLS_LOG(20, "usage_iterate_range reached key=%s, done", key
.c_str());
3455 ret
= usage_record_decode(iter
->second
, e
);
3459 if (!bucket
.empty() && bucket
.compare(e
.bucket
))
3462 if (e
.epoch
< start
)
3465 /* keys are sorted by epoch, so once we're past end we're done */
3466 if (e
.epoch
>= end
) {
3471 ret
= cb(hctx
, key
, e
, param
);
3478 static int usage_log_read_cb(cls_method_context_t hctx
, const string
& key
, rgw_usage_log_entry
& entry
, void *param
)
3480 map
<rgw_user_bucket
, rgw_usage_log_entry
> *usage
= (map
<rgw_user_bucket
, rgw_usage_log_entry
> *)param
;
3482 if (!entry
.payer
.empty()) {
3483 puser
= &entry
.payer
;
3485 puser
= &entry
.owner
;
3487 rgw_user_bucket
ub(puser
->to_str(), entry
.bucket
);
3488 rgw_usage_log_entry
& le
= (*usage
)[ub
];
3489 le
.aggregate(entry
);
3494 int rgw_user_usage_log_read(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3496 CLS_LOG(10, "entered %s", __func__
);
3498 auto in_iter
= in
->cbegin();
3499 rgw_cls_usage_log_read_op op
;
3502 decode(op
, in_iter
);
3503 } catch (ceph::buffer::error
& err
) {
3504 CLS_LOG(1, "ERROR: rgw_user_usage_log_read(): failed to decode request\n");
3508 rgw_cls_usage_log_read_ret ret_info
;
3509 map
<rgw_user_bucket
, rgw_usage_log_entry
> *usage
= &ret_info
.usage
;
3510 string iter
= op
.iter
;
3511 #define MAX_ENTRIES 1000
3512 uint32_t max_entries
= (op
.max_entries
? op
.max_entries
: MAX_ENTRIES
);
3513 int ret
= usage_iterate_range(hctx
, op
.start_epoch
, op
.end_epoch
, op
.owner
, op
.bucket
, iter
, max_entries
, &ret_info
.truncated
, usage_log_read_cb
, (void *)usage
);
3517 if (ret_info
.truncated
)
3518 ret_info
.next_iter
= iter
;
3520 encode(ret_info
, *out
);
3524 static int usage_log_trim_cb(cls_method_context_t hctx
, const string
& key
, rgw_usage_log_entry
& entry
, void *param
)
3526 bool *found
= (bool *)param
;
3533 string o
= entry
.owner
.to_str();
3534 usage_record_name_by_time(entry
.epoch
, o
, entry
.bucket
, key_by_time
);
3535 usage_record_name_by_user(o
, entry
.epoch
, entry
.bucket
, key_by_user
);
3537 int ret
= cls_cxx_map_remove_key(hctx
, key_by_time
);
3541 return cls_cxx_map_remove_key(hctx
, key_by_user
);
3544 int rgw_user_usage_log_trim(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3546 CLS_LOG(10, "entered %s", __func__
);
3548 /* only continue if object exists! */
3549 int ret
= cls_cxx_stat(hctx
, NULL
, NULL
);
3553 auto in_iter
= in
->cbegin();
3554 rgw_cls_usage_log_trim_op op
;
3557 decode(op
, in_iter
);
3558 } catch (ceph::buffer::error
& err
) {
3559 CLS_LOG(1, "ERROR: rgw_user_log_usage_log_trim(): failed to decode request\n");
3566 #define MAX_USAGE_TRIM_ENTRIES 1000
3567 ret
= usage_iterate_range(hctx
, op
.start_epoch
, op
.end_epoch
, op
.user
, op
.bucket
, iter
, MAX_USAGE_TRIM_ENTRIES
, &more
, usage_log_trim_cb
, (void *)&found
);
3571 if (!more
&& !found
)
3577 int rgw_usage_log_clear(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3579 CLS_LOG(10, "entered %s", __func__
);
3581 int ret
= cls_cxx_map_clear(hctx
);
3582 /* if object doesn't exist all the logs are cleared anyway */
3590 * We hold the garbage collection chain data under two different
3591 * indexes: the first 'name' index keeps them under a unique tag that
3592 * represents the chains, and a second 'time' index keeps them by
3593 * their expiration timestamp. Each is prefixed differently (see
3594 * gc_index_prefixes below).
3596 * Since key-value data is listed in lexical order by keys, generally
3597 * the name entries are retrieved first and then the time entries.
3598 * When listing the entries via `gc_iterate_entries` one parameter is
3599 * a marker, and if we were to pass "1_" (i.e.,
3600 * gc_index_prefixes[GC_OBJ_TIME_INDEX]), the listing would skip over
3601 * the 'name' entries and begin with the 'time' entries.
3603 * Furthermore, the times are converted to strings such that lexical
3604 * order correlates with chronological order, so the entries are
3605 * returned chronologically from the earliest expiring to the latest
3606 * expiring. This allows for starting at "1_" and to keep retrieving
3607 * chunks of entries, and as long as they are prior to the current
3608 * time, they're expired and processing can continue.
3610 #define GC_OBJ_NAME_INDEX 0
3611 #define GC_OBJ_TIME_INDEX 1
3613 static string gc_index_prefixes
[] = { "0_",
3616 static void prepend_index_prefix(const string
& src
, int index
, string
*dest
)
3618 *dest
= gc_index_prefixes
[index
];
3622 static int gc_omap_get(cls_method_context_t hctx
, int type
, const string
& key
, cls_rgw_gc_obj_info
*info
)
3625 prepend_index_prefix(key
, type
, &index
);
3627 int ret
= read_omap_entry(hctx
, index
, info
);
3634 static int gc_omap_set(cls_method_context_t hctx
, int type
, const string
& key
, const cls_rgw_gc_obj_info
*info
)
3639 string index
= gc_index_prefixes
[type
];
3642 int ret
= cls_cxx_map_set_val(hctx
, index
, &bl
);
3649 static int gc_omap_remove(cls_method_context_t hctx
, int type
, const string
& key
)
3651 string index
= gc_index_prefixes
[type
];
3654 int ret
= cls_cxx_map_remove_key(hctx
, index
);
3661 static bool key_in_index(const string
& key
, int index_type
)
3663 const string
& prefix
= gc_index_prefixes
[index_type
];
3664 return (key
.compare(0, prefix
.size(), prefix
) == 0);
3668 static int gc_update_entry(cls_method_context_t hctx
, uint32_t expiration_secs
,
3669 cls_rgw_gc_obj_info
& info
)
3671 cls_rgw_gc_obj_info old_info
;
3672 int ret
= gc_omap_get(hctx
, GC_OBJ_NAME_INDEX
, info
.tag
, &old_info
);
3675 get_time_key(old_info
.time
, &key
);
3676 ret
= gc_omap_remove(hctx
, GC_OBJ_TIME_INDEX
, key
);
3677 if (ret
< 0 && ret
!= -ENOENT
) {
3678 CLS_LOG(0, "ERROR: failed to remove key=%s", key
.c_str());
3683 // calculate time and time key
3684 info
.time
= ceph::real_clock::now();
3685 info
.time
+= make_timespan(expiration_secs
);
3687 get_time_key(info
.time
, &time_key
);
3689 if (info
.chain
.objs
.empty()) {
3691 "WARNING: %s setting GC log entry with zero-length chain, "
3692 "tag='%s', timekey='%s'",
3693 __func__
, info
.tag
.c_str(), time_key
.c_str());
3696 ret
= gc_omap_set(hctx
, GC_OBJ_NAME_INDEX
, info
.tag
, &info
);
3700 ret
= gc_omap_set(hctx
, GC_OBJ_TIME_INDEX
, time_key
, &info
);
3708 CLS_LOG(0, "ERROR: gc_set_entry error info.tag=%s, ret=%d",
3709 info
.tag
.c_str(), ret
);
3710 gc_omap_remove(hctx
, GC_OBJ_NAME_INDEX
, info
.tag
);
3715 static int gc_defer_entry(cls_method_context_t hctx
, const string
& tag
, uint32_t expiration_secs
)
3717 cls_rgw_gc_obj_info info
;
3718 int ret
= gc_omap_get(hctx
, GC_OBJ_NAME_INDEX
, tag
, &info
);
3721 return gc_update_entry(hctx
, expiration_secs
, info
);
3724 int gc_record_decode(bufferlist
& bl
, cls_rgw_gc_obj_info
& e
)
3726 auto iter
= bl
.cbegin();
3729 } catch (ceph::buffer::error
& err
) {
3730 CLS_LOG(0, "ERROR: failed to decode cls_rgw_gc_obj_info");
3736 static int rgw_cls_gc_set_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3738 CLS_LOG(10, "entered %s", __func__
);
3739 auto in_iter
= in
->cbegin();
3741 cls_rgw_gc_set_entry_op op
;
3743 decode(op
, in_iter
);
3744 } catch (ceph::buffer::error
& err
) {
3745 CLS_LOG(1, "ERROR: rgw_cls_gc_set_entry(): failed to decode entry\n");
3749 return gc_update_entry(hctx
, op
.expiration_secs
, op
.info
);
3752 static int rgw_cls_gc_defer_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3754 CLS_LOG(10, "entered %s", __func__
);
3755 auto in_iter
= in
->cbegin();
3757 cls_rgw_gc_defer_entry_op op
;
3759 decode(op
, in_iter
);
3760 } catch (ceph::buffer::error
& err
) {
3761 CLS_LOG(1, "ERROR: rgw_cls_gc_defer_entry(): failed to decode entry\n");
3765 return gc_defer_entry(hctx
, op
.tag
, op
.expiration_secs
);
3768 static int gc_iterate_entries(cls_method_context_t hctx
,
3769 const string
& marker
,
3772 uint32_t max_entries
,
3774 int (*cb
)(cls_method_context_t
,
3776 cls_rgw_gc_obj_info
&,
3780 CLS_LOG(10, "gc_iterate_entries");
3782 map
<string
, bufferlist
> keys
;
3783 string filter_prefix
, end_key
;
3790 if (marker
.empty()) {
3791 prepend_index_prefix(marker
, GC_OBJ_TIME_INDEX
, &start_key
);
3797 real_time now
= ceph::real_clock::now();
3799 get_time_key(now
, &now_str
);
3800 prepend_index_prefix(now_str
, GC_OBJ_TIME_INDEX
, &end_key
);
3802 CLS_LOG(10, "gc_iterate_entries end_key=%s", end_key
.c_str());
3807 int ret
= cls_cxx_map_get_vals(hctx
, start_key
, filter
, max_entries
,
3812 auto iter
= keys
.begin();
3813 if (iter
== keys
.end()) {
3814 // if keys empty must not come back as truncated
3815 ceph_assert(!truncated
|| !(*truncated
));
3819 const string
* last_key
= nullptr; // last key processed, for end-marker
3820 for (; iter
!= keys
.end(); ++iter
) {
3821 const string
& key
= iter
->first
;
3822 cls_rgw_gc_obj_info e
;
3824 CLS_LOG(10, "gc_iterate_entries key=%s", key
.c_str());
3826 if (!end_key
.empty() && key
.compare(end_key
) >= 0) {
3832 if (!key_in_index(key
, GC_OBJ_TIME_INDEX
)) {
3838 ret
= gc_record_decode(iter
->second
, e
);
3842 ret
= cb(hctx
, key
, e
, param
);
3845 last_key
= &(iter
->first
); // update when callback successful
3848 // set the out marker if either caller does not capture truncated or
3849 // if they do capture and we are truncated
3850 if (!truncated
|| *truncated
) {
3852 out_marker
= *last_key
;
3858 static int gc_list_cb(cls_method_context_t hctx
, const string
& key
, cls_rgw_gc_obj_info
& info
, void *param
)
3860 list
<cls_rgw_gc_obj_info
> *l
= (list
<cls_rgw_gc_obj_info
> *)param
;
3865 static int gc_list_entries(cls_method_context_t hctx
, const string
& marker
,
3866 uint32_t max
, bool expired_only
,
3867 list
<cls_rgw_gc_obj_info
>& entries
, bool *truncated
, string
& next_marker
)
3869 int ret
= gc_iterate_entries(hctx
, marker
, expired_only
,
3870 next_marker
, max
, truncated
,
3871 gc_list_cb
, &entries
);
3875 static int rgw_cls_gc_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3877 CLS_LOG(10, "entered %s", __func__
);
3878 auto in_iter
= in
->cbegin();
3880 cls_rgw_gc_list_op op
;
3882 decode(op
, in_iter
);
3883 } catch (ceph::buffer::error
& err
) {
3884 CLS_LOG(1, "ERROR: rgw_cls_gc_list(): failed to decode entry\n");
3888 cls_rgw_gc_list_ret op_ret
;
3889 #define GC_LIST_ENTRIES_DEFAULT 128
3890 int ret
= gc_list_entries(hctx
, op
.marker
, (op
.max
? op
.max
: GC_LIST_ENTRIES_DEFAULT
), op
.expired_only
,
3891 op_ret
.entries
, &op_ret
.truncated
, op_ret
.next_marker
);
3895 encode(op_ret
, *out
);
3900 static int gc_remove(cls_method_context_t hctx
, vector
<string
>& tags
)
3902 for (auto iter
= tags
.begin(); iter
!= tags
.end(); ++iter
) {
3903 string
& tag
= *iter
;
3904 cls_rgw_gc_obj_info info
;
3905 int ret
= gc_omap_get(hctx
, GC_OBJ_NAME_INDEX
, tag
, &info
);
3906 if (ret
== -ENOENT
) {
3907 CLS_LOG(0, "couldn't find tag in name index tag=%s", tag
.c_str());
3915 get_time_key(info
.time
, &time_key
);
3916 ret
= gc_omap_remove(hctx
, GC_OBJ_TIME_INDEX
, time_key
);
3917 if (ret
< 0 && ret
!= -ENOENT
)
3919 if (ret
== -ENOENT
) {
3920 CLS_LOG(0, "couldn't find key in time index key=%s", time_key
.c_str());
3923 ret
= gc_omap_remove(hctx
, GC_OBJ_NAME_INDEX
, tag
);
3924 if (ret
< 0 && ret
!= -ENOENT
)
3931 static int rgw_cls_gc_remove(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3933 CLS_LOG(10, "entered %s", __func__
);
3934 auto in_iter
= in
->cbegin();
3936 cls_rgw_gc_remove_op op
;
3938 decode(op
, in_iter
);
3939 } catch (ceph::buffer::error
& err
) {
3940 CLS_LOG(1, "ERROR: rgw_cls_gc_remove(): failed to decode entry\n");
3944 return gc_remove(hctx
, op
.tags
);
3947 static int rgw_cls_lc_get_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3949 CLS_LOG(10, "entered %s", __func__
);
3950 auto in_iter
= in
->cbegin();
3952 cls_rgw_lc_get_entry_op op
;
3954 decode(op
, in_iter
);
3955 } catch (ceph::buffer::error
& err
) {
3956 CLS_LOG(1, "ERROR: rgw_cls_lc_set_entry(): failed to decode entry\n");
3960 cls_rgw_lc_entry lc_entry
;
3961 int ret
= read_omap_entry(hctx
, op
.marker
, &lc_entry
);
3965 cls_rgw_lc_get_entry_ret
op_ret(std::move(lc_entry
));
3966 encode(op_ret
, *out
);
3971 static int rgw_cls_lc_set_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3973 CLS_LOG(10, "entered %s", __func__
);
3974 auto in_iter
= in
->cbegin();
3976 cls_rgw_lc_set_entry_op op
;
3978 decode(op
, in_iter
);
3979 } catch (ceph::buffer::error
& err
) {
3980 CLS_LOG(1, "ERROR: rgw_cls_lc_set_entry(): failed to decode entry\n");
3985 encode(op
.entry
, bl
);
3987 int ret
= cls_cxx_map_set_val(hctx
, op
.entry
.bucket
, &bl
);
3991 static int rgw_cls_lc_rm_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3993 CLS_LOG(10, "entered %s", __func__
);
3994 auto in_iter
= in
->cbegin();
3996 cls_rgw_lc_rm_entry_op op
;
3998 decode(op
, in_iter
);
3999 } catch (ceph::buffer::error
& err
) {
4000 CLS_LOG(1, "ERROR: rgw_cls_lc_rm_entry(): failed to decode entry\n");
4004 int ret
= cls_cxx_map_remove_key(hctx
, op
.entry
.bucket
);
4008 static int rgw_cls_lc_get_next_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
4010 CLS_LOG(10, "entered %s", __func__
);
4011 auto in_iter
= in
->cbegin();
4012 cls_rgw_lc_get_next_entry_ret op_ret
;
4013 cls_rgw_lc_get_next_entry_op op
;
4015 decode(op
, in_iter
);
4016 } catch (ceph::buffer::error
& err
) {
4017 CLS_LOG(1, "ERROR: rgw_cls_lc_get_next_entry: failed to decode op\n");
4021 map
<string
, bufferlist
> vals
;
4022 string filter_prefix
;
4024 int ret
= cls_cxx_map_get_vals(hctx
, op
.marker
, filter_prefix
, 1, &vals
, &more
);
4027 cls_rgw_lc_entry entry
;
4028 if (!vals
.empty()) {
4029 auto it
= vals
.begin();
4030 in_iter
= it
->second
.begin();
4032 decode(entry
, in_iter
);
4033 } catch (ceph::buffer::error
& err
) {
4034 CLS_LOG(1, "ERROR: rgw_cls_lc_get_next_entry(): failed to decode entry\n");
4038 op_ret
.entry
= entry
;
4039 encode(op_ret
, *out
);
4043 static int rgw_cls_lc_list_entries(cls_method_context_t hctx
, bufferlist
*in
,
4046 CLS_LOG(10, "entered %s", __func__
);
4047 cls_rgw_lc_list_entries_op op
;
4048 auto in_iter
= in
->cbegin();
4050 decode(op
, in_iter
);
4051 } catch (ceph::buffer::error
& err
) {
4052 CLS_LOG(1, "ERROR: rgw_cls_lc_list_entries(): failed to decode op\n");
4056 cls_rgw_lc_list_entries_ret
op_ret(op
.compat_v
);
4057 map
<string
, bufferlist
> vals
;
4058 string filter_prefix
;
4059 int ret
= cls_cxx_map_get_vals(hctx
, op
.marker
, filter_prefix
, op
.max_entries
,
4060 &vals
, &op_ret
.is_truncated
);
4063 for (auto it
= vals
.begin(); it
!= vals
.end(); ++it
) {
4064 cls_rgw_lc_entry entry
;
4065 auto iter
= it
->second
.cbegin();
4067 decode(entry
, iter
);
4068 } catch (buffer::error
& err
) {
4069 /* try backward compat */
4070 pair
<string
, int> oe
;
4072 iter
= it
->second
.begin();
4074 entry
= {oe
.first
, 0 /* start */, uint32_t(oe
.second
)};
4075 } catch(buffer::error
& err
) {
4077 1, "ERROR: rgw_cls_lc_list_entries(): failed to decode entry\n");
4081 op_ret
.entries
.push_back(entry
);
4083 encode(op_ret
, *out
);
4087 static int rgw_cls_lc_put_head(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
4089 CLS_LOG(10, "entered %s", __func__
);
4090 auto in_iter
= in
->cbegin();
4092 cls_rgw_lc_put_head_op op
;
4094 decode(op
, in_iter
);
4095 } catch (ceph::buffer::error
& err
) {
4096 CLS_LOG(1, "ERROR: rgw_cls_lc_put_head(): failed to decode entry\n");
4101 encode(op
.head
, bl
);
4102 int ret
= cls_cxx_map_write_header(hctx
,&bl
);
4106 static int rgw_cls_lc_get_head(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
4108 CLS_LOG(10, "entered %s", __func__
);
4110 int ret
= cls_cxx_map_read_header(hctx
, &bl
);
4113 cls_rgw_lc_obj_head head
;
4114 if (bl
.length() != 0) {
4115 auto iter
= bl
.cbegin();
4118 } catch (ceph::buffer::error
& err
) {
4119 CLS_LOG(0, "ERROR: rgw_cls_lc_get_head(): failed to decode entry %s",err
.what());
4123 head
.start_date
= 0;
4124 head
.marker
.clear();
4126 cls_rgw_lc_get_head_ret op_ret
;
4128 encode(op_ret
, *out
);
4132 static int rgw_reshard_add(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
4134 CLS_LOG(10, "entered %s", __func__
);
4135 auto in_iter
= in
->cbegin();
4137 cls_rgw_reshard_add_op op
;
4139 decode(op
, in_iter
);
4140 } catch (ceph::buffer::error
& err
) {
4141 CLS_LOG(1, "ERROR: rgw_reshard_add: failed to decode entry\n");
4147 op
.entry
.get_key(&key
);
4150 encode(op
.entry
, bl
);
4151 int ret
= cls_cxx_map_set_val(hctx
, key
, &bl
);
4153 CLS_ERR("error adding reshard job for bucket %s with key %s",op
.entry
.bucket_name
.c_str(), key
.c_str());
4160 static int rgw_reshard_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
4162 CLS_LOG(10, "entered %s", __func__
);
4163 cls_rgw_reshard_list_op op
;
4164 auto in_iter
= in
->cbegin();
4166 decode(op
, in_iter
);
4167 } catch (ceph::buffer::error
& err
) {
4168 CLS_LOG(1, "ERROR: rgw_cls_rehard_list(): failed to decode entry\n");
4171 cls_rgw_reshard_list_ret op_ret
;
4172 map
<string
, bufferlist
> vals
;
4173 string filter_prefix
;
4174 #define MAX_RESHARD_LIST_ENTRIES 1000
4175 /* one extra entry for identifying truncation */
4176 int32_t max
= (op
.max
&& (op
.max
< MAX_RESHARD_LIST_ENTRIES
) ? op
.max
: MAX_RESHARD_LIST_ENTRIES
);
4177 int ret
= cls_cxx_map_get_vals(hctx
, op
.marker
, filter_prefix
, max
, &vals
, &op_ret
.is_truncated
);
4180 cls_rgw_reshard_entry entry
;
4182 for (auto it
= vals
.begin(); i
< (int)op
.max
&& it
!= vals
.end(); ++it
, ++i
) {
4183 auto iter
= it
->second
.cbegin();
4185 decode(entry
, iter
);
4186 } catch (ceph::buffer::error
& err
) {
4187 CLS_LOG(1, "ERROR: rgw_cls_rehard_list(): failed to decode entry\n");
4190 op_ret
.entries
.push_back(entry
);
4192 encode(op_ret
, *out
);
4196 static int rgw_reshard_get(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
4198 CLS_LOG(10, "entered %s", __func__
);
4199 auto in_iter
= in
->cbegin();
4201 cls_rgw_reshard_get_op op
;
4203 decode(op
, in_iter
);
4204 } catch (ceph::buffer::error
& err
) {
4205 CLS_LOG(1, "ERROR: rgw_reshard_get: failed to decode entry\n");
4210 cls_rgw_reshard_entry entry
;
4211 op
.entry
.get_key(&key
);
4212 int ret
= read_omap_entry(hctx
, key
, &entry
);
4217 cls_rgw_reshard_get_ret op_ret
;
4218 op_ret
.entry
= entry
;
4219 encode(op_ret
, *out
);
4223 static int rgw_reshard_remove(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
4225 CLS_LOG(10, "entered %s", __func__
);
4226 auto in_iter
= in
->cbegin();
4228 cls_rgw_reshard_remove_op op
;
4230 decode(op
, in_iter
);
4231 } catch (ceph::buffer::error
& err
) {
4232 CLS_LOG(1, "ERROR: rgw_cls_rehard_remove: failed to decode entry\n");
4237 cls_rgw_reshard_entry entry
;
4238 cls_rgw_reshard_entry::generate_key(op
.tenant
, op
.bucket_name
, &key
);
4239 int ret
= read_omap_entry(hctx
, key
, &entry
);
4244 if (!op
.bucket_id
.empty() &&
4245 entry
.bucket_id
!= op
.bucket_id
) {
4249 ret
= cls_cxx_map_remove_key(hctx
, key
);
4251 CLS_LOG(0, "ERROR: failed to remove key: key=%s ret=%d", key
.c_str(), ret
);
4257 static int rgw_set_bucket_resharding(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
4259 CLS_LOG(10, "entered %s", __func__
);
4260 cls_rgw_set_bucket_resharding_op op
;
4262 auto in_iter
= in
->cbegin();
4264 decode(op
, in_iter
);
4265 } catch (ceph::buffer::error
& err
) {
4266 CLS_LOG(1, "ERROR: cls_rgw_set_bucket_resharding: failed to decode entry\n");
4270 rgw_bucket_dir_header header
;
4271 int rc
= read_bucket_header(hctx
, &header
);
4273 CLS_LOG(1, "ERROR: %s: failed to read header", __func__
);
4277 header
.new_instance
.set_status(op
.entry
.new_bucket_instance_id
, op
.entry
.num_shards
, op
.entry
.reshard_status
);
4279 return write_bucket_header(hctx
, &header
);
4282 static int rgw_clear_bucket_resharding(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
4284 CLS_LOG(10, "entered %s", __func__
);
4285 cls_rgw_clear_bucket_resharding_op op
;
4287 auto in_iter
= in
->cbegin();
4289 decode(op
, in_iter
);
4290 } catch (ceph::buffer::error
& err
) {
4291 CLS_LOG(1, "ERROR: cls_rgw_clear_bucket_resharding: failed to decode entry\n");
4295 rgw_bucket_dir_header header
;
4296 int rc
= read_bucket_header(hctx
, &header
);
4298 CLS_LOG(1, "ERROR: %s: failed to read header", __func__
);
4301 header
.new_instance
.clear();
4303 return write_bucket_header(hctx
, &header
);
4306 static int rgw_guard_bucket_resharding(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
4308 CLS_LOG(10, "entered %s", __func__
);
4309 cls_rgw_guard_bucket_resharding_op op
;
4311 auto in_iter
= in
->cbegin();
4313 decode(op
, in_iter
);
4314 } catch (ceph::buffer::error
& err
) {
4315 CLS_LOG(1, "ERROR: %s: failed to decode entry", __func__
);
4319 rgw_bucket_dir_header header
;
4320 int rc
= read_bucket_header(hctx
, &header
);
4322 CLS_LOG(1, "ERROR: %s: failed to read header", __func__
);
4326 if (header
.resharding()) {
4333 static int rgw_get_bucket_resharding(cls_method_context_t hctx
,
4334 bufferlist
*in
, bufferlist
*out
)
4336 CLS_LOG(10, "entered %s", __func__
);
4337 cls_rgw_get_bucket_resharding_op op
;
4339 auto in_iter
= in
->cbegin();
4341 decode(op
, in_iter
);
4342 } catch (ceph::buffer::error
& err
) {
4343 CLS_LOG(1, "ERROR: %s: failed to decode entry", __func__
);
4347 rgw_bucket_dir_header header
;
4348 int rc
= read_bucket_header(hctx
, &header
);
4350 CLS_LOG(1, "ERROR: %s: failed to read header", __func__
);
4354 cls_rgw_get_bucket_resharding_ret op_ret
;
4355 op_ret
.new_instance
= header
.new_instance
;
4357 encode(op_ret
, *out
);
4364 CLS_LOG(1, "Loaded rgw class!");
4366 cls_handle_t h_class
;
4367 cls_method_handle_t h_rgw_bucket_init_index
;
4368 cls_method_handle_t h_rgw_bucket_set_tag_timeout
;
4369 cls_method_handle_t h_rgw_bucket_list
;
4370 cls_method_handle_t h_rgw_bucket_check_index
;
4371 cls_method_handle_t h_rgw_bucket_rebuild_index
;
4372 cls_method_handle_t h_rgw_bucket_update_stats
;
4373 cls_method_handle_t h_rgw_bucket_prepare_op
;
4374 cls_method_handle_t h_rgw_bucket_complete_op
;
4375 cls_method_handle_t h_rgw_bucket_link_olh
;
4376 cls_method_handle_t h_rgw_bucket_unlink_instance_op
;
4377 cls_method_handle_t h_rgw_bucket_read_olh_log
;
4378 cls_method_handle_t h_rgw_bucket_trim_olh_log
;
4379 cls_method_handle_t h_rgw_bucket_clear_olh
;
4380 cls_method_handle_t h_rgw_obj_remove
;
4381 cls_method_handle_t h_rgw_obj_store_pg_ver
;
4382 cls_method_handle_t h_rgw_obj_check_attrs_prefix
;
4383 cls_method_handle_t h_rgw_obj_check_mtime
;
4384 cls_method_handle_t h_rgw_bi_get_op
;
4385 cls_method_handle_t h_rgw_bi_put_op
;
4386 cls_method_handle_t h_rgw_bi_list_op
;
4387 cls_method_handle_t h_rgw_bi_log_list_op
;
4388 cls_method_handle_t h_rgw_bi_log_resync_op
;
4389 cls_method_handle_t h_rgw_bi_log_stop_op
;
4390 cls_method_handle_t h_rgw_dir_suggest_changes
;
4391 cls_method_handle_t h_rgw_user_usage_log_add
;
4392 cls_method_handle_t h_rgw_user_usage_log_read
;
4393 cls_method_handle_t h_rgw_user_usage_log_trim
;
4394 cls_method_handle_t h_rgw_usage_log_clear
;
4395 cls_method_handle_t h_rgw_gc_set_entry
;
4396 cls_method_handle_t h_rgw_gc_list
;
4397 cls_method_handle_t h_rgw_gc_remove
;
4398 cls_method_handle_t h_rgw_lc_get_entry
;
4399 cls_method_handle_t h_rgw_lc_set_entry
;
4400 cls_method_handle_t h_rgw_lc_rm_entry
;
4401 cls_method_handle_t h_rgw_lc_get_next_entry
;
4402 cls_method_handle_t h_rgw_lc_put_head
;
4403 cls_method_handle_t h_rgw_lc_get_head
;
4404 cls_method_handle_t h_rgw_lc_list_entries
;
4405 cls_method_handle_t h_rgw_reshard_add
;
4406 cls_method_handle_t h_rgw_reshard_list
;
4407 cls_method_handle_t h_rgw_reshard_get
;
4408 cls_method_handle_t h_rgw_reshard_remove
;
4409 cls_method_handle_t h_rgw_set_bucket_resharding
;
4410 cls_method_handle_t h_rgw_clear_bucket_resharding
;
4411 cls_method_handle_t h_rgw_guard_bucket_resharding
;
4412 cls_method_handle_t h_rgw_get_bucket_resharding
;
4414 cls_register(RGW_CLASS
, &h_class
);
4417 cls_register_cxx_method(h_class
, RGW_BUCKET_INIT_INDEX
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bucket_init_index
, &h_rgw_bucket_init_index
);
4418 cls_register_cxx_method(h_class
, RGW_BUCKET_SET_TAG_TIMEOUT
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bucket_set_tag_timeout
, &h_rgw_bucket_set_tag_timeout
);
4419 cls_register_cxx_method(h_class
, RGW_BUCKET_LIST
, CLS_METHOD_RD
, rgw_bucket_list
, &h_rgw_bucket_list
);
4420 cls_register_cxx_method(h_class
, RGW_BUCKET_CHECK_INDEX
, CLS_METHOD_RD
, rgw_bucket_check_index
, &h_rgw_bucket_check_index
);
4421 cls_register_cxx_method(h_class
, RGW_BUCKET_REBUILD_INDEX
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bucket_rebuild_index
, &h_rgw_bucket_rebuild_index
);
4422 cls_register_cxx_method(h_class
, RGW_BUCKET_UPDATE_STATS
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bucket_update_stats
, &h_rgw_bucket_update_stats
);
4423 cls_register_cxx_method(h_class
, RGW_BUCKET_PREPARE_OP
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bucket_prepare_op
, &h_rgw_bucket_prepare_op
);
4424 cls_register_cxx_method(h_class
, RGW_BUCKET_COMPLETE_OP
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bucket_complete_op
, &h_rgw_bucket_complete_op
);
4425 cls_register_cxx_method(h_class
, RGW_BUCKET_LINK_OLH
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bucket_link_olh
, &h_rgw_bucket_link_olh
);
4426 cls_register_cxx_method(h_class
, RGW_BUCKET_UNLINK_INSTANCE
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bucket_unlink_instance
, &h_rgw_bucket_unlink_instance_op
);
4427 cls_register_cxx_method(h_class
, RGW_BUCKET_READ_OLH_LOG
, CLS_METHOD_RD
, rgw_bucket_read_olh_log
, &h_rgw_bucket_read_olh_log
);
4428 cls_register_cxx_method(h_class
, RGW_BUCKET_TRIM_OLH_LOG
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bucket_trim_olh_log
, &h_rgw_bucket_trim_olh_log
);
4429 cls_register_cxx_method(h_class
, RGW_BUCKET_CLEAR_OLH
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bucket_clear_olh
, &h_rgw_bucket_clear_olh
);
4431 cls_register_cxx_method(h_class
, RGW_OBJ_REMOVE
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_obj_remove
, &h_rgw_obj_remove
);
4432 cls_register_cxx_method(h_class
, RGW_OBJ_STORE_PG_VER
, CLS_METHOD_WR
, rgw_obj_store_pg_ver
, &h_rgw_obj_store_pg_ver
);
4433 cls_register_cxx_method(h_class
, RGW_OBJ_CHECK_ATTRS_PREFIX
, CLS_METHOD_RD
, rgw_obj_check_attrs_prefix
, &h_rgw_obj_check_attrs_prefix
);
4434 cls_register_cxx_method(h_class
, RGW_OBJ_CHECK_MTIME
, CLS_METHOD_RD
, rgw_obj_check_mtime
, &h_rgw_obj_check_mtime
);
4436 cls_register_cxx_method(h_class
, RGW_BI_GET
, CLS_METHOD_RD
, rgw_bi_get_op
, &h_rgw_bi_get_op
);
4437 cls_register_cxx_method(h_class
, RGW_BI_PUT
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bi_put_op
, &h_rgw_bi_put_op
);
4438 cls_register_cxx_method(h_class
, RGW_BI_LIST
, CLS_METHOD_RD
, rgw_bi_list_op
, &h_rgw_bi_list_op
);
4440 cls_register_cxx_method(h_class
, RGW_BI_LOG_LIST
, CLS_METHOD_RD
, rgw_bi_log_list
, &h_rgw_bi_log_list_op
);
4441 cls_register_cxx_method(h_class
, RGW_BI_LOG_TRIM
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bi_log_trim
, &h_rgw_bi_log_list_op
);
4442 cls_register_cxx_method(h_class
, RGW_DIR_SUGGEST_CHANGES
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_dir_suggest_changes
, &h_rgw_dir_suggest_changes
);
4444 cls_register_cxx_method(h_class
, RGW_BI_LOG_RESYNC
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bi_log_resync
, &h_rgw_bi_log_resync_op
);
4445 cls_register_cxx_method(h_class
, RGW_BI_LOG_STOP
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bi_log_stop
, &h_rgw_bi_log_stop_op
);
4448 cls_register_cxx_method(h_class
, RGW_USER_USAGE_LOG_ADD
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_user_usage_log_add
, &h_rgw_user_usage_log_add
);
4449 cls_register_cxx_method(h_class
, RGW_USER_USAGE_LOG_READ
, CLS_METHOD_RD
, rgw_user_usage_log_read
, &h_rgw_user_usage_log_read
);
4450 cls_register_cxx_method(h_class
, RGW_USER_USAGE_LOG_TRIM
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_user_usage_log_trim
, &h_rgw_user_usage_log_trim
);
4451 cls_register_cxx_method(h_class
, RGW_USAGE_LOG_CLEAR
, CLS_METHOD_WR
, rgw_usage_log_clear
, &h_rgw_usage_log_clear
);
4453 /* garbage collection */
4454 cls_register_cxx_method(h_class
, RGW_GC_SET_ENTRY
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_cls_gc_set_entry
, &h_rgw_gc_set_entry
);
4455 cls_register_cxx_method(h_class
, RGW_GC_DEFER_ENTRY
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_cls_gc_defer_entry
, &h_rgw_gc_set_entry
);
4456 cls_register_cxx_method(h_class
, RGW_GC_LIST
, CLS_METHOD_RD
, rgw_cls_gc_list
, &h_rgw_gc_list
);
4457 cls_register_cxx_method(h_class
, RGW_GC_REMOVE
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_cls_gc_remove
, &h_rgw_gc_remove
);
4459 /* lifecycle bucket list */
4460 cls_register_cxx_method(h_class
, RGW_LC_GET_ENTRY
, CLS_METHOD_RD
, rgw_cls_lc_get_entry
, &h_rgw_lc_get_entry
);
4461 cls_register_cxx_method(h_class
, RGW_LC_SET_ENTRY
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_cls_lc_set_entry
, &h_rgw_lc_set_entry
);
4462 cls_register_cxx_method(h_class
, RGW_LC_RM_ENTRY
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_cls_lc_rm_entry
, &h_rgw_lc_rm_entry
);
4463 cls_register_cxx_method(h_class
, RGW_LC_GET_NEXT_ENTRY
, CLS_METHOD_RD
, rgw_cls_lc_get_next_entry
, &h_rgw_lc_get_next_entry
);
4464 cls_register_cxx_method(h_class
, RGW_LC_PUT_HEAD
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_cls_lc_put_head
, &h_rgw_lc_put_head
);
4465 cls_register_cxx_method(h_class
, RGW_LC_GET_HEAD
, CLS_METHOD_RD
, rgw_cls_lc_get_head
, &h_rgw_lc_get_head
);
4466 cls_register_cxx_method(h_class
, RGW_LC_LIST_ENTRIES
, CLS_METHOD_RD
, rgw_cls_lc_list_entries
, &h_rgw_lc_list_entries
);
4469 cls_register_cxx_method(h_class
, RGW_RESHARD_ADD
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_reshard_add
, &h_rgw_reshard_add
);
4470 cls_register_cxx_method(h_class
, RGW_RESHARD_LIST
, CLS_METHOD_RD
, rgw_reshard_list
, &h_rgw_reshard_list
);
4471 cls_register_cxx_method(h_class
, RGW_RESHARD_GET
, CLS_METHOD_RD
,rgw_reshard_get
, &h_rgw_reshard_get
);
4472 cls_register_cxx_method(h_class
, RGW_RESHARD_REMOVE
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_reshard_remove
, &h_rgw_reshard_remove
);
4474 /* resharding attribute */
4475 cls_register_cxx_method(h_class
, RGW_SET_BUCKET_RESHARDING
, CLS_METHOD_RD
| CLS_METHOD_WR
,
4476 rgw_set_bucket_resharding
, &h_rgw_set_bucket_resharding
);
4477 cls_register_cxx_method(h_class
, RGW_CLEAR_BUCKET_RESHARDING
, CLS_METHOD_RD
| CLS_METHOD_WR
,
4478 rgw_clear_bucket_resharding
, &h_rgw_clear_bucket_resharding
);
4479 cls_register_cxx_method(h_class
, RGW_GUARD_BUCKET_RESHARDING
, CLS_METHOD_RD
,
4480 rgw_guard_bucket_resharding
, &h_rgw_guard_bucket_resharding
);
4481 cls_register_cxx_method(h_class
, RGW_GET_BUCKET_RESHARDING
, CLS_METHOD_RD
,
4482 rgw_get_bucket_resharding
, &h_rgw_get_bucket_resharding
);