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 "objclass/objclass.h"
9 #include "cls/rgw/cls_rgw_ops.h"
10 #include "cls/rgw/cls_rgw_const.h"
11 #include "common/Clock.h"
12 #include "common/strtol.h"
13 #include "common/escape.h"
15 #include "include/compat.h"
21 #define BI_PREFIX_CHAR 0x80
23 #define BI_BUCKET_OBJS_INDEX 0
24 #define BI_BUCKET_LOG_INDEX 1
25 #define BI_BUCKET_OBJ_INSTANCE_INDEX 2
26 #define BI_BUCKET_OLH_DATA_INDEX 3
28 #define BI_BUCKET_LAST_INDEX 4
30 static std::string bucket_index_prefixes
[] = { "", /* special handling for the objs list index */
31 "0_", /* bucket log index */
32 "1000_", /* obj instance index */
33 "1001_", /* olh data index */
35 /* this must be the last index */
38 static bool bi_is_objs_index(const string
& s
) {
39 return ((unsigned char)s
[0] != BI_PREFIX_CHAR
);
42 int bi_entry_type(const string
& s
)
44 if (bi_is_objs_index(s
)) {
45 return BI_BUCKET_OBJS_INDEX
;
49 i
< sizeof(bucket_index_prefixes
) / sizeof(bucket_index_prefixes
[0]);
51 const string
& t
= bucket_index_prefixes
[i
];
53 if (s
.compare(1, t
.size(), t
) == 0) {
61 static bool bi_entry_gt(const string
& first
, const string
& second
)
63 int fi
= bi_entry_type(first
);
64 int si
= bi_entry_type(second
);
72 return first
> second
;
75 static void get_time_key(real_time
& ut
, string
*key
)
78 ceph_timespec ts
= ceph::real_clock::to_ceph_timespec(ut
);
79 snprintf(buf
, 32, "%011llu.%09u", (unsigned long long)ts
.tv_sec
, (unsigned int)ts
.tv_nsec
);
83 static void get_index_ver_key(cls_method_context_t hctx
, uint64_t index_ver
, string
*key
)
86 snprintf(buf
, sizeof(buf
), "%011llu.%llu.%d", (unsigned long long)index_ver
,
87 (unsigned long long)cls_current_version(hctx
),
88 cls_current_subop_num(hctx
));
92 static void bi_log_prefix(string
& key
)
95 key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
98 static void bi_log_index_key(cls_method_context_t hctx
, string
& key
, string
& id
, uint64_t index_ver
)
101 get_index_ver_key(hctx
, index_ver
, &id
);
105 static int log_index_operation(cls_method_context_t hctx
, cls_rgw_obj_key
& obj_key
, RGWModifyOp op
,
106 string
& tag
, real_time
& timestamp
,
107 rgw_bucket_entry_ver
& ver
, RGWPendingState state
, uint64_t index_ver
,
108 string
& max_marker
, uint16_t bilog_flags
, string
*owner
, string
*owner_display_name
, rgw_zone_set
*zones_trace
)
112 rgw_bi_log_entry entry
;
114 entry
.object
= obj_key
.name
;
115 entry
.instance
= obj_key
.instance
;
116 entry
.timestamp
= timestamp
;
120 entry
.index_ver
= index_ver
;
122 entry
.bilog_flags
= bilog_flags
;
124 entry
.owner
= *owner
;
126 if (owner_display_name
) {
127 entry
.owner_display_name
= *owner_display_name
;
130 entry
.zones_trace
= std::move(*zones_trace
);
134 bi_log_index_key(hctx
, key
, entry
.id
, index_ver
);
138 if (entry
.id
> max_marker
)
139 max_marker
= entry
.id
;
141 return cls_cxx_map_set_val(hctx
, key
, &bl
);
145 * read list of objects, skips objects in the ugly namespace
147 static int get_obj_vals(cls_method_context_t hctx
, const string
& start
, const string
& filter_prefix
,
148 int num_entries
, map
<string
, bufferlist
> *pkeys
, bool *pmore
)
150 int ret
= cls_cxx_map_get_vals(hctx
, start
, filter_prefix
, num_entries
, pkeys
, pmore
);
157 auto last_element
= pkeys
->rbegin();
158 if ((unsigned char)last_element
->first
[0] < BI_PREFIX_CHAR
) {
159 /* nothing to see here, move along */
163 auto first_element
= pkeys
->begin();
164 if ((unsigned char)first_element
->first
[0] > BI_PREFIX_CHAR
) {
168 /* let's rebuild the list, only keep entries we're interested in */
169 auto comp
= [](const pair
<string
, bufferlist
>& l
, const string
&r
) { return l
.first
< r
; };
170 string new_start
= {static_cast<char>(BI_PREFIX_CHAR
+ 1)};
172 auto lower
= pkeys
->lower_bound(string
{static_cast<char>(BI_PREFIX_CHAR
)});
173 auto upper
= std::lower_bound(lower
, pkeys
->end(), new_start
, comp
);
174 pkeys
->erase(lower
, upper
);
176 if (num_entries
== (int)pkeys
->size() || !(*pmore
))
179 if (pkeys
->size() && new_start
< pkeys
->rbegin()->first
) {
180 new_start
= pkeys
->rbegin()->first
;
183 map
<string
, bufferlist
> new_keys
;
185 /* now get some more keys */
186 ret
= cls_cxx_map_get_vals(hctx
, new_start
, filter_prefix
, num_entries
- pkeys
->size(), &new_keys
, pmore
);
190 pkeys
->insert(std::make_move_iterator(new_keys
.begin()),
191 std::make_move_iterator(new_keys
.end()));
196 * get a monotonically decreasing string representation.
197 * For num = x, num = y, where x > y, str(x) < str(y)
198 * Another property is that string size starts short and grows as num increases
200 static void decreasing_str(uint64_t num
, string
*str
)
203 if (num
< 0x10) { /* 16 */
204 snprintf(buf
, sizeof(buf
), "9%02lld", 15 - (long long)num
);
205 } else if (num
< 0x100) { /* 256 */
206 snprintf(buf
, sizeof(buf
), "8%03lld", 255 - (long long)num
);
207 } else if (num
< 0x1000) /* 4096 */ {
208 snprintf(buf
, sizeof(buf
), "7%04lld", 4095 - (long long)num
);
209 } else if (num
< 0x10000) /* 65536 */ {
210 snprintf(buf
, sizeof(buf
), "6%05lld", 65535 - (long long)num
);
211 } else if (num
< 0x100000000) /* 4G */ {
212 snprintf(buf
, sizeof(buf
), "5%010lld", 0xFFFFFFFF - (long long)num
);
214 snprintf(buf
, sizeof(buf
), "4%020lld", (long long)-num
);
221 * we now hold two different indexes for objects. The first one holds the list of objects in the
222 * order that we want them to be listed. The second one only holds the objects instances (for
223 * versioned objects), and they're not arranged in any particular order.
224 * When listing objects we'll use the first index, when doing operations on the objects themselves
225 * we'll use the second index. Note that regular objects only map to the first index anyway
228 static void get_list_index_key(rgw_bucket_dir_entry
& entry
, string
*index_key
)
230 *index_key
= entry
.key
.name
;
233 decreasing_str(entry
.versioned_epoch
, &ver_str
);
234 string
instance_delim("\0i", 2);
235 string
ver_delim("\0v", 2);
237 index_key
->append(ver_delim
);
238 index_key
->append(ver_str
);
239 index_key
->append(instance_delim
);
240 index_key
->append(entry
.key
.instance
);
243 static void encode_obj_versioned_data_key(const cls_rgw_obj_key
& key
, string
*index_key
, bool append_delete_marker_suffix
= false)
245 *index_key
= BI_PREFIX_CHAR
;
246 index_key
->append(bucket_index_prefixes
[BI_BUCKET_OBJ_INSTANCE_INDEX
]);
247 index_key
->append(key
.name
);
248 string
delim("\0i", 2);
249 index_key
->append(delim
);
250 index_key
->append(key
.instance
);
251 if (append_delete_marker_suffix
) {
253 index_key
->append(dm
);
257 static void encode_obj_index_key(const cls_rgw_obj_key
& key
, string
*index_key
)
259 if (key
.instance
.empty()) {
260 *index_key
= key
.name
;
262 encode_obj_versioned_data_key(key
, index_key
);
266 static void encode_olh_data_key(const cls_rgw_obj_key
& key
, string
*index_key
)
268 *index_key
= BI_PREFIX_CHAR
;
269 index_key
->append(bucket_index_prefixes
[BI_BUCKET_OLH_DATA_INDEX
]);
270 index_key
->append(key
.name
);
274 static int read_index_entry(cls_method_context_t hctx
, string
& name
, T
*entry
);
276 static int encode_list_index_key(cls_method_context_t hctx
, const cls_rgw_obj_key
& key
, string
*index_key
)
278 if (key
.instance
.empty()) {
279 *index_key
= key
.name
;
283 string obj_index_key
;
284 encode_obj_index_key(key
, &obj_index_key
);
286 rgw_bucket_dir_entry entry
;
288 int ret
= read_index_entry(hctx
, obj_index_key
, &entry
);
289 if (ret
== -ENOENT
) {
290 /* couldn't find the entry, set key value after the current object */
291 char buf
[2] = { 0x1, 0 };
293 *index_key
= key
.name
+ s
;
297 CLS_LOG(1, "ERROR: encode_list_index_key(): cls_cxx_map_get_val returned %d\n", ret
);
301 get_list_index_key(entry
, index_key
);
306 static void split_key(const string
& key
, list
<string
>& vals
)
309 const char *p
= key
.c_str();
310 while (pos
< key
.size()) {
311 size_t len
= strlen(p
);
318 static string
escape_str(const string
& s
)
320 int len
= escape_json_attr_len(s
.c_str(), s
.size());
321 std::string
escaped(len
, 0);
322 escape_json_attr(s
.c_str(), s
.size(), escaped
.data());
327 * list index key structure:
329 * <obj name>\0[v<ver>\0i<instance id>]
331 static int decode_list_index_key(const string
& index_key
, cls_rgw_obj_key
*key
, uint64_t *ver
)
333 size_t len
= strlen(index_key
.c_str());
335 key
->instance
.clear();
338 if (len
== index_key
.size()) {
339 key
->name
= index_key
;
344 split_key(index_key
, vals
);
347 CLS_LOG(0, "ERROR: %s(): bad index_key (%s): split_key() returned empty vals", __func__
, escape_str(index_key
).c_str());
351 list
<string
>::iterator iter
= vals
.begin();
355 if (iter
== vals
.end()) {
356 CLS_LOG(0, "ERROR: %s(): bad index_key (%s): no vals", __func__
, escape_str(index_key
).c_str());
360 for (; iter
!= vals
.end(); ++iter
) {
363 key
->instance
= val
.substr(1);
364 } else if (val
[0] == 'v') {
366 const char *s
= val
.c_str() + 1;
367 *ver
= strict_strtoll(s
, 10, &err
);
369 CLS_LOG(0, "ERROR: %s(): bad index_key (%s): could not parse val (v=%s)", __func__
, escape_str(index_key
).c_str(), s
);
378 static int read_bucket_header(cls_method_context_t hctx
,
379 rgw_bucket_dir_header
*header
)
382 int rc
= cls_cxx_map_read_header(hctx
, &bl
);
386 if (bl
.length() == 0) {
387 *header
= rgw_bucket_dir_header();
390 auto iter
= bl
.cbegin();
392 decode(*header
, iter
);
393 } catch (buffer::error
& err
) {
394 CLS_LOG(1, "ERROR: read_bucket_header(): failed to decode header\n");
401 int rgw_bucket_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
403 auto iter
= in
->cbegin();
408 } catch (buffer::error
& err
) {
409 CLS_LOG(1, "ERROR: rgw_bucket_list(): failed to decode request\n");
413 rgw_cls_list_ret ret
;
414 rgw_bucket_dir
& new_dir
= ret
.dir
;
415 int rc
= read_bucket_header(hctx
, &new_dir
.header
);
417 CLS_LOG(1, "ERROR: rgw_bucket_list(): failed to read header\n");
421 map
<string
, bufferlist
> keys
;
422 std::map
<string
, bufferlist
>::iterator kiter
;
424 encode_list_index_key(hctx
, op
.start_obj
, &start_key
);
426 uint32_t left_to_read
= op
.num_entries
;
430 rc
= get_obj_vals(hctx
, start_key
, op
.filter_prefix
, left_to_read
, &keys
, &more
);
434 std::map
<string
, rgw_bucket_dir_entry
>& m
= new_dir
.m
;
438 for (kiter
= keys
.begin(); kiter
!= keys
.end(); ++kiter
) {
439 rgw_bucket_dir_entry entry
;
441 if (!bi_is_objs_index(kiter
->first
)) {
446 bufferlist
& entrybl
= kiter
->second
;
447 auto eiter
= entrybl
.cbegin();
449 decode(entry
, eiter
);
450 } catch (buffer::error
& err
) {
451 CLS_LOG(1, "ERROR: rgw_bucket_list(): failed to decode entry, key=%s\n", kiter
->first
.c_str());
458 start_key
= kiter
->first
;
459 CLS_LOG(20, "start_key=%s len=%zu", start_key
.c_str(), start_key
.size());
461 int ret
= decode_list_index_key(kiter
->first
, &key
, &ver
);
463 CLS_LOG(0, "ERROR: failed to decode list index key (%s)\n", escape_str(kiter
->first
).c_str());
467 if (!entry
.is_valid()) {
468 CLS_LOG(20, "entry %s[%s] is not valid\n", key
.name
.c_str(), key
.instance
.c_str());
472 // filter out noncurrent versions, delete markers, and initial marker
473 if (!op
.list_versions
&& (!entry
.is_visible() || op
.start_obj
.name
== key
.name
)) {
474 CLS_LOG(20, "entry %s[%s] is not visible\n", key
.name
.c_str(), key
.instance
.c_str());
477 if (m
.size() < op
.num_entries
) {
478 m
[kiter
->first
] = entry
;
482 CLS_LOG(20, "got entry %s[%s] m.size()=%d\n", key
.name
.c_str(), key
.instance
.c_str(), (int)m
.size());
484 } while (left_to_read
> 0 && !done
);
486 ret
.is_truncated
= more
&& !done
;
492 static int check_index(cls_method_context_t hctx
,
493 rgw_bucket_dir_header
*existing_header
,
494 rgw_bucket_dir_header
*calc_header
)
496 int rc
= read_bucket_header(hctx
, existing_header
);
498 CLS_LOG(1, "ERROR: check_index(): failed to read header\n");
502 calc_header
->tag_timeout
= existing_header
->tag_timeout
;
503 calc_header
->ver
= existing_header
->ver
;
505 map
<string
, bufferlist
> keys
;
507 string filter_prefix
;
509 #define CHECK_CHUNK_SIZE 1000
514 rc
= get_obj_vals(hctx
, start_obj
, filter_prefix
, CHECK_CHUNK_SIZE
, &keys
, &more
);
518 std::map
<string
, bufferlist
>::iterator kiter
= keys
.begin();
519 for (; kiter
!= keys
.end(); ++kiter
) {
520 if (!bi_is_objs_index(kiter
->first
)) {
525 rgw_bucket_dir_entry entry
;
526 auto eiter
= kiter
->second
.cbegin();
528 decode(entry
, eiter
);
529 } catch (buffer::error
& err
) {
530 CLS_LOG(1, "ERROR: rgw_bucket_list(): failed to decode entry, key=%s\n", kiter
->first
.c_str());
533 rgw_bucket_category_stats
& stats
= calc_header
->stats
[entry
.meta
.category
];
535 stats
.total_size
+= entry
.meta
.accounted_size
;
536 stats
.total_size_rounded
+= cls_rgw_get_rounded_size(entry
.meta
.accounted_size
);
537 stats
.actual_size
+= entry
.meta
.size
;
539 start_obj
= kiter
->first
;
541 } while (keys
.size() == CHECK_CHUNK_SIZE
&& !done
);
546 int rgw_bucket_check_index(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
548 rgw_cls_check_index_ret ret
;
550 int rc
= check_index(hctx
, &ret
.existing_header
, &ret
.calculated_header
);
559 static int write_bucket_header(cls_method_context_t hctx
, rgw_bucket_dir_header
*header
)
563 bufferlist header_bl
;
564 encode(*header
, header_bl
);
565 return cls_cxx_map_write_header(hctx
, &header_bl
);
569 int rgw_bucket_rebuild_index(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
571 rgw_bucket_dir_header existing_header
;
572 rgw_bucket_dir_header calc_header
;
573 int rc
= check_index(hctx
, &existing_header
, &calc_header
);
577 return write_bucket_header(hctx
, &calc_header
);
580 int rgw_bucket_update_stats(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
583 rgw_cls_bucket_update_stats_op op
;
584 auto iter
= in
->cbegin();
587 } catch (buffer::error
& err
) {
588 CLS_LOG(1, "ERROR: %s(): failed to decode request\n", __func__
);
592 rgw_bucket_dir_header header
;
593 int rc
= read_bucket_header(hctx
, &header
);
595 CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__
);
599 for (auto& s
: op
.stats
) {
600 auto& dest
= header
.stats
[s
.first
];
604 dest
.total_size
+= s
.second
.total_size
;
605 dest
.total_size_rounded
+= s
.second
.total_size_rounded
;
606 dest
.num_entries
+= s
.second
.num_entries
;
607 dest
.actual_size
+= s
.second
.actual_size
;
611 return write_bucket_header(hctx
, &header
);
614 int rgw_bucket_init_index(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
616 bufferlist header_bl
;
617 int rc
= cls_cxx_map_read_header(hctx
, &header_bl
);
628 if (header_bl
.length() != 0) {
629 CLS_LOG(1, "ERROR: index already initialized\n");
635 return write_bucket_header(hctx
, &dir
.header
);
638 int rgw_bucket_set_tag_timeout(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
641 rgw_cls_tag_timeout_op op
;
642 auto iter
= in
->cbegin();
645 } catch (buffer::error
& err
) {
646 CLS_LOG(1, "ERROR: rgw_bucket_set_tag_timeout(): failed to decode request\n");
650 rgw_bucket_dir_header header
;
651 int rc
= read_bucket_header(hctx
, &header
);
653 CLS_LOG(1, "ERROR: rgw_bucket_set_tag_timeout(): failed to read header\n");
657 header
.tag_timeout
= op
.tag_timeout
;
659 return write_bucket_header(hctx
, &header
);
662 static int read_key_entry(cls_method_context_t hctx
, cls_rgw_obj_key
& key
,
663 string
*idx
, rgw_bucket_dir_entry
*entry
,
664 bool special_delete_marker_name
= false);
666 int rgw_bucket_prepare_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
669 rgw_cls_obj_prepare_op op
;
670 auto iter
= in
->cbegin();
673 } catch (buffer::error
& err
) {
674 CLS_LOG(1, "ERROR: rgw_bucket_prepare_op(): failed to decode request\n");
678 if (op
.tag
.empty()) {
679 CLS_LOG(1, "ERROR: tag is empty\n");
683 CLS_LOG(1, "rgw_bucket_prepare_op(): request: op=%d name=%s instance=%s tag=%s\n",
684 op
.op
, op
.key
.name
.c_str(), op
.key
.instance
.c_str(), op
.tag
.c_str());
689 rgw_bucket_dir_entry entry
;
690 int rc
= read_key_entry(hctx
, op
.key
, &idx
, &entry
);
691 if (rc
< 0 && rc
!= -ENOENT
)
694 bool noent
= (rc
== -ENOENT
);
698 if (noent
) { // no entry, initialize fields
700 entry
.ver
= rgw_bucket_entry_ver();
701 entry
.exists
= false;
702 entry
.locator
= op
.locator
;
705 // fill in proper state
706 rgw_bucket_pending_info info
;
707 info
.timestamp
= real_clock::now();
708 info
.state
= CLS_RGW_STATE_PENDING_MODIFY
;
710 entry
.pending_map
.insert(pair
<string
, rgw_bucket_pending_info
>(op
.tag
, info
));
712 rgw_bucket_dir_header header
;
713 rc
= read_bucket_header(hctx
, &header
);
715 CLS_LOG(1, "ERROR: rgw_bucket_prepare_op(): failed to read header\n");
719 if (op
.log_op
&& !header
.syncstopped
) {
720 rc
= log_index_operation(hctx
, op
.key
, op
.op
, op
.tag
, entry
.meta
.mtime
,
721 entry
.ver
, info
.state
, header
.ver
, header
.max_marker
, op
.bilog_flags
, NULL
, NULL
, &op
.zones_trace
);
726 // write out new key to disk
728 encode(entry
, info_bl
);
729 rc
= cls_cxx_map_set_val(hctx
, idx
, &info_bl
);
733 if (op
.log_op
&& !header
.syncstopped
)
734 return write_bucket_header(hctx
, &header
);
738 static void unaccount_entry(rgw_bucket_dir_header
& header
,
739 rgw_bucket_dir_entry
& entry
)
741 rgw_bucket_category_stats
& stats
= header
.stats
[entry
.meta
.category
];
743 stats
.total_size
-= entry
.meta
.accounted_size
;
744 stats
.total_size_rounded
-= cls_rgw_get_rounded_size(entry
.meta
.accounted_size
);
745 stats
.actual_size
-= entry
.meta
.size
;
748 static void log_entry(const char *func
, const char *str
, rgw_bucket_dir_entry
*entry
)
750 CLS_LOG(1, "%s(): %s: ver=%ld:%llu name=%s instance=%s locator=%s\n", func
, str
,
751 (long)entry
->ver
.pool
, (unsigned long long)entry
->ver
.epoch
,
752 entry
->key
.name
.c_str(), entry
->key
.instance
.c_str(), entry
->locator
.c_str());
755 static void log_entry(const char *func
, const char *str
, rgw_bucket_olh_entry
*entry
)
757 CLS_LOG(1, "%s(): %s: epoch=%llu name=%s instance=%s tag=%s\n", func
, str
,
758 (unsigned long long)entry
->epoch
, entry
->key
.name
.c_str(), entry
->key
.instance
.c_str(),
763 static int read_omap_entry(cls_method_context_t hctx
, const std::string
& name
,
766 bufferlist current_entry
;
767 int rc
= cls_cxx_map_get_val(hctx
, name
, ¤t_entry
);
772 auto cur_iter
= current_entry
.cbegin();
774 decode(*entry
, cur_iter
);
775 } catch (buffer::error
& err
) {
776 CLS_LOG(1, "ERROR: %s(): failed to decode entry\n", __func__
);
783 static int read_index_entry(cls_method_context_t hctx
, string
& name
, T
* entry
)
785 int ret
= read_omap_entry(hctx
, name
, entry
);
790 log_entry(__func__
, "existing entry", entry
);
794 static int read_key_entry(cls_method_context_t hctx
, cls_rgw_obj_key
& key
,
795 string
*idx
, rgw_bucket_dir_entry
*entry
,
796 bool special_delete_marker_name
)
798 encode_obj_index_key(key
, idx
);
799 int rc
= read_index_entry(hctx
, *idx
, entry
);
804 if (key
.instance
.empty() &&
805 entry
->flags
& RGW_BUCKET_DIRENT_FLAG_VER_MARKER
) {
806 /* we only do it where key.instance is empty. In this case the delete marker will have a
807 * separate entry in the index to avoid collisions with the actual object, as it's mutable
809 if (special_delete_marker_name
) {
810 encode_obj_versioned_data_key(key
, idx
, true);
811 rc
= read_index_entry(hctx
, *idx
, entry
);
816 encode_obj_versioned_data_key(key
, idx
);
817 rc
= read_index_entry(hctx
, *idx
, entry
);
819 *entry
= rgw_bucket_dir_entry(); /* need to reset entry because we initialized it earlier */
827 int rgw_bucket_complete_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
830 rgw_cls_obj_complete_op op
;
831 auto iter
= in
->cbegin();
834 } catch (buffer::error
& err
) {
835 CLS_LOG(1, "ERROR: rgw_bucket_complete_op(): failed to decode request\n");
838 CLS_LOG(1, "rgw_bucket_complete_op(): request: op=%d name=%s instance=%s ver=%lu:%llu tag=%s\n",
839 op
.op
, op
.key
.name
.c_str(), op
.key
.instance
.c_str(),
840 (unsigned long)op
.ver
.pool
, (unsigned long long)op
.ver
.epoch
,
843 rgw_bucket_dir_header header
;
844 int rc
= read_bucket_header(hctx
, &header
);
846 CLS_LOG(1, "ERROR: rgw_bucket_complete_op(): failed to read header\n");
850 rgw_bucket_dir_entry entry
;
854 rc
= read_key_entry(hctx
, op
.key
, &idx
, &entry
);
858 entry
.meta
= op
.meta
;
859 entry
.locator
= op
.locator
;
865 entry
.index_ver
= header
.ver
;
866 entry
.flags
= (entry
.key
.instance
.empty() ? 0 : RGW_BUCKET_DIRENT_FLAG_VER
); /* resetting entry flags, entry might have been previously a delete marker */
869 map
<string
, rgw_bucket_pending_info
>::iterator pinter
= entry
.pending_map
.find(op
.tag
);
870 if (pinter
== entry
.pending_map
.end()) {
871 CLS_LOG(1, "ERROR: couldn't find tag for pending operation\n");
874 entry
.pending_map
.erase(pinter
);
878 bufferlist update_bl
;
880 if (op
.tag
.size() && op
.op
== CLS_RGW_OP_CANCEL
) {
881 CLS_LOG(1, "rgw_bucket_complete_op(): cancel requested\n");
883 } else if (op
.ver
.pool
== entry
.ver
.pool
&&
884 op
.ver
.epoch
&& op
.ver
.epoch
<= entry
.ver
.epoch
) {
885 CLS_LOG(1, "rgw_bucket_complete_op(): skipping request, old epoch\n");
891 if (op
.log_op
&& !header
.syncstopped
) {
892 rc
= log_index_operation(hctx
, op
.key
, op
.op
, op
.tag
, entry
.meta
.mtime
, entry
.ver
,
893 CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, op
.bilog_flags
, NULL
, NULL
, &op
.zones_trace
);
899 bufferlist new_key_bl
;
900 encode(entry
, new_key_bl
);
901 rc
= cls_cxx_map_set_val(hctx
, idx
, &new_key_bl
);
906 if (op
.log_op
&& !header
.syncstopped
) {
907 return write_bucket_header(hctx
, &header
);
913 unaccount_entry(header
, entry
);
917 switch ((int)op
.op
) {
919 entry
.meta
= op
.meta
;
921 if (!entry
.pending_map
.size()) {
922 int ret
= cls_cxx_map_remove_key(hctx
, idx
);
926 entry
.exists
= false;
927 bufferlist new_key_bl
;
928 encode(entry
, new_key_bl
);
929 int ret
= cls_cxx_map_set_val(hctx
, idx
, &new_key_bl
);
939 rgw_bucket_dir_entry_meta
& meta
= op
.meta
;
940 rgw_bucket_category_stats
& stats
= header
.stats
[meta
.category
];
946 stats
.total_size
+= meta
.accounted_size
;
947 stats
.total_size_rounded
+= cls_rgw_get_rounded_size(meta
.accounted_size
);
948 stats
.actual_size
+= meta
.size
;
949 bufferlist new_key_bl
;
950 encode(entry
, new_key_bl
);
951 int ret
= cls_cxx_map_set_val(hctx
, idx
, &new_key_bl
);
958 if (op
.log_op
&& !header
.syncstopped
) {
959 rc
= log_index_operation(hctx
, op
.key
, op
.op
, op
.tag
, entry
.meta
.mtime
, entry
.ver
,
960 CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, op
.bilog_flags
, NULL
, NULL
, &op
.zones_trace
);
965 list
<cls_rgw_obj_key
>::iterator remove_iter
;
966 CLS_LOG(20, "rgw_bucket_complete_op(): remove_objs.size()=%d\n", (int)op
.remove_objs
.size());
967 for (remove_iter
= op
.remove_objs
.begin(); remove_iter
!= op
.remove_objs
.end(); ++remove_iter
) {
968 cls_rgw_obj_key
& remove_key
= *remove_iter
;
969 CLS_LOG(1, "rgw_bucket_complete_op(): removing entries, read_index_entry name=%s instance=%s\n",
970 remove_key
.name
.c_str(), remove_key
.instance
.c_str());
971 rgw_bucket_dir_entry remove_entry
;
973 int ret
= read_key_entry(hctx
, remove_key
, &k
, &remove_entry
);
975 CLS_LOG(1, "rgw_bucket_complete_op(): removing entries, read_index_entry name=%s instance=%s ret=%d\n",
976 remove_key
.name
.c_str(), remove_key
.instance
.c_str(), ret
);
980 "rgw_bucket_complete_op(): entry.name=%s entry.instance=%s entry.meta.category=%d\n",
981 remove_entry
.key
.name
.c_str(),
982 remove_entry
.key
.instance
.c_str(),
983 int(remove_entry
.meta
.category
));
984 unaccount_entry(header
, remove_entry
);
986 if (op
.log_op
&& !header
.syncstopped
) {
987 ++header
.ver
; // increment index version, or we'll overwrite keys previously written
988 rc
= log_index_operation(hctx
, remove_key
, CLS_RGW_OP_DEL
, op
.tag
, remove_entry
.meta
.mtime
,
989 remove_entry
.ver
, CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, op
.bilog_flags
, NULL
, NULL
, &op
.zones_trace
);
994 ret
= cls_cxx_map_remove_key(hctx
, k
);
996 CLS_LOG(1, "rgw_bucket_complete_op(): cls_cxx_map_remove_key, failed to remove entry, name=%s instance=%s read_index_entry ret=%d\n", remove_key
.name
.c_str(), remove_key
.instance
.c_str(), rc
);
1001 return write_bucket_header(hctx
, &header
);
1005 static int write_entry(cls_method_context_t hctx
, T
& entry
, const string
& key
)
1009 return cls_cxx_map_set_val(hctx
, key
, &bl
);
1012 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
)
1014 cls_rgw_obj_key olh_key
;
1015 olh_key
.name
= obj_key
.name
;
1017 encode_olh_data_key(olh_key
, index_key
);
1018 int ret
= read_index_entry(hctx
, *index_key
, olh_data_entry
);
1019 if (ret
< 0 && ret
!= -ENOENT
) {
1020 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_key
.name
.c_str(), ret
);
1024 *found
= (ret
!= -ENOENT
);
1029 static void update_olh_log(rgw_bucket_olh_entry
& olh_data_entry
, OLHLogOp op
, const string
& op_tag
,
1030 cls_rgw_obj_key
& key
, bool delete_marker
, uint64_t epoch
)
1032 vector
<rgw_bucket_olh_log_entry
>& log
= olh_data_entry
.pending_log
[olh_data_entry
.epoch
];
1033 rgw_bucket_olh_log_entry log_entry
;
1034 log_entry
.epoch
= epoch
;
1036 log_entry
.op_tag
= op_tag
;
1037 log_entry
.key
= key
;
1038 log_entry
.delete_marker
= delete_marker
;
1039 log
.push_back(log_entry
);
1042 static int write_obj_instance_entry(cls_method_context_t hctx
, rgw_bucket_dir_entry
& instance_entry
, const string
& instance_idx
)
1044 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
);
1045 /* write the instance entry */
1046 int ret
= write_entry(hctx
, instance_entry
, instance_idx
);
1048 CLS_LOG(0, "ERROR: write_entry() instance_key=%s ret=%d", escape_str(instance_idx
).c_str(), ret
);
1055 * write object instance entry, and if needed also the list entry
1057 static int write_obj_entries(cls_method_context_t hctx
, rgw_bucket_dir_entry
& instance_entry
, const string
& instance_idx
)
1059 int ret
= write_obj_instance_entry(hctx
, instance_entry
, instance_idx
);
1063 string instance_list_idx
;
1064 get_list_index_key(instance_entry
, &instance_list_idx
);
1066 if (instance_idx
!= instance_list_idx
) {
1067 CLS_LOG(20, "write_entry() idx=%s flags=%d", escape_str(instance_list_idx
).c_str(), instance_entry
.flags
);
1068 /* write a new list entry for the object instance */
1069 ret
= write_entry(hctx
, instance_entry
, instance_list_idx
);
1071 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
);
1079 class BIVerObjEntry
{
1080 cls_method_context_t hctx
;
1081 cls_rgw_obj_key key
;
1082 string instance_idx
;
1084 rgw_bucket_dir_entry instance_entry
;
1089 BIVerObjEntry(cls_method_context_t
& _hctx
, const cls_rgw_obj_key
& _key
) : hctx(_hctx
), key(_key
), initialized(false) {
1092 int init(bool check_delete_marker
= true) {
1093 int ret
= read_key_entry(hctx
, key
, &instance_idx
, &instance_entry
,
1094 check_delete_marker
&& key
.instance
.empty()); /* this is potentially a delete marker, for null objects we
1095 keep separate instance entry for the delete markers */
1098 CLS_LOG(0, "ERROR: read_key_entry() idx=%s ret=%d", instance_idx
.c_str(), ret
);
1102 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
);
1106 rgw_bucket_dir_entry
& get_dir_entry() {
1107 return instance_entry
;
1110 void init_as_delete_marker(rgw_bucket_dir_entry_meta
& meta
) {
1111 /* a deletion marker, need to initialize it, there's no instance entry for it yet */
1112 instance_entry
.key
= key
;
1113 instance_entry
.flags
= RGW_BUCKET_DIRENT_FLAG_DELETE_MARKER
;
1114 instance_entry
.meta
= meta
;
1115 instance_entry
.tag
= "delete-marker";
1120 void set_epoch(uint64_t epoch
) {
1121 instance_entry
.versioned_epoch
= epoch
;
1124 int unlink_list_entry() {
1126 /* this instance has a previous list entry, remove that entry */
1127 get_list_index_key(instance_entry
, &list_idx
);
1128 CLS_LOG(20, "unlink_list_entry() list_idx=%s", escape_str(list_idx
).c_str());
1129 int ret
= cls_cxx_map_remove_key(hctx
, list_idx
);
1131 CLS_LOG(0, "ERROR: cls_cxx_map_remove_key() list_idx=%s ret=%d", list_idx
.c_str(), ret
);
1138 /* remove the instance entry */
1139 CLS_LOG(20, "unlink() idx=%s", escape_str(instance_idx
).c_str());
1140 int ret
= cls_cxx_map_remove_key(hctx
, instance_idx
);
1142 CLS_LOG(0, "ERROR: cls_cxx_map_remove_key() instance_idx=%s ret=%d", instance_idx
.c_str(), ret
);
1148 int write_entries(uint64_t flags_set
, uint64_t flags_reset
) {
1155 instance_entry
.flags
&= ~flags_reset
;
1156 instance_entry
.flags
|= flags_set
;
1158 /* write the instance and list entries */
1159 bool special_delete_marker_key
= (instance_entry
.is_delete_marker() && instance_entry
.key
.instance
.empty());
1160 encode_obj_versioned_data_key(key
, &instance_idx
, special_delete_marker_key
);
1161 int ret
= write_obj_entries(hctx
, instance_entry
, instance_idx
);
1163 CLS_LOG(0, "ERROR: write_obj_entries() instance_idx=%s ret=%d", instance_idx
.c_str(), ret
);
1170 int write(uint64_t epoch
, bool current
) {
1171 if (instance_entry
.versioned_epoch
> 0) {
1172 CLS_LOG(20, "%s(): instance_entry.versioned_epoch=%d epoch=%d", __func__
, (int)instance_entry
.versioned_epoch
, (int)epoch
);
1173 /* this instance has a previous list entry, remove that entry */
1174 int ret
= unlink_list_entry();
1180 uint64_t flags
= RGW_BUCKET_DIRENT_FLAG_VER
;
1182 flags
|= RGW_BUCKET_DIRENT_FLAG_CURRENT
;
1185 instance_entry
.versioned_epoch
= epoch
;
1186 return write_entries(flags
, 0);
1189 int demote_current() {
1190 return write_entries(0, RGW_BUCKET_DIRENT_FLAG_CURRENT
);
1193 bool is_delete_marker() {
1194 return instance_entry
.is_delete_marker();
1197 int find_next_key(cls_rgw_obj_key
*next_key
, bool *found
) {
1199 /* this instance has a previous list entry, remove that entry */
1200 get_list_index_key(instance_entry
, &list_idx
);
1201 /* this is the current head, need to update! */
1202 map
<string
, bufferlist
> keys
;
1204 string filter
= key
.name
; /* list key starts with key name, filter it to avoid a case where we cross to
1205 different namespace */
1206 int ret
= cls_cxx_map_get_vals(hctx
, list_idx
, filter
, 1, &keys
, &more
);
1211 if (keys
.size() < 1) {
1216 rgw_bucket_dir_entry next_entry
;
1218 map
<string
, bufferlist
>::reverse_iterator last
= keys
.rbegin();
1220 auto iter
= last
->second
.cbegin();
1221 decode(next_entry
, iter
);
1222 } catch (buffer::error
& err
) {
1223 CLS_LOG(0, "ERROR; failed to decode entry: %s", last
->first
.c_str());
1227 *found
= (key
.name
== next_entry
.key
.name
);
1229 *next_key
= next_entry
.key
;
1236 return instance_entry
.meta
.mtime
;
1242 cls_method_context_t hctx
;
1243 cls_rgw_obj_key key
;
1245 string olh_data_idx
;
1246 rgw_bucket_olh_entry olh_data_entry
;
1250 BIOLHEntry(cls_method_context_t
& _hctx
, const cls_rgw_obj_key
& _key
) : hctx(_hctx
), key(_key
), initialized(false) { }
1252 int init(bool *exists
) {
1254 int ret
= read_olh(hctx
, key
, &olh_data_entry
, &olh_data_idx
, exists
);
1263 bool start_modify(uint64_t candidate_epoch
) {
1264 if (candidate_epoch
) {
1265 if (candidate_epoch
< olh_data_entry
.epoch
) {
1266 return false; /* olh cannot be modified, old epoch */
1268 olh_data_entry
.epoch
= candidate_epoch
;
1270 if (olh_data_entry
.epoch
== 0) {
1271 olh_data_entry
.epoch
= 2; /* versioned epoch should start with 2, 1 is reserved to converted plain entries */
1273 olh_data_entry
.epoch
++;
1279 uint64_t get_epoch() {
1280 return olh_data_entry
.epoch
;
1283 rgw_bucket_olh_entry
& get_entry() {
1284 return olh_data_entry
;
1287 void update(cls_rgw_obj_key
& key
, bool delete_marker
) {
1288 olh_data_entry
.delete_marker
= delete_marker
;
1289 olh_data_entry
.key
= key
;
1293 /* write the olh data entry */
1294 int ret
= write_entry(hctx
, olh_data_entry
, olh_data_idx
);
1296 CLS_LOG(0, "ERROR: write_entry() olh_key=%s ret=%d", olh_data_idx
.c_str(), ret
);
1303 void update_log(OLHLogOp op
, const string
& op_tag
, cls_rgw_obj_key
& key
, bool delete_marker
, uint64_t epoch
= 0) {
1305 epoch
= olh_data_entry
.epoch
;
1307 update_olh_log(olh_data_entry
, op
, op_tag
, key
, delete_marker
, epoch
);
1310 bool exists() { return olh_data_entry
.exists
; }
1312 void set_exists(bool exists
) {
1313 olh_data_entry
.exists
= exists
;
1316 bool pending_removal() { return olh_data_entry
.pending_removal
; }
1318 void set_pending_removal(bool pending_removal
) {
1319 olh_data_entry
.pending_removal
= pending_removal
;
1322 const string
& get_tag() { return olh_data_entry
.tag
; }
1323 void set_tag(const string
& tag
) {
1324 olh_data_entry
.tag
= tag
;
1328 static int write_version_marker(cls_method_context_t hctx
, cls_rgw_obj_key
& key
)
1330 rgw_bucket_dir_entry entry
;
1332 entry
.flags
= RGW_BUCKET_DIRENT_FLAG_VER_MARKER
;
1333 int ret
= write_entry(hctx
, entry
, key
.name
);
1335 CLS_LOG(0, "ERROR: write_entry returned ret=%d", ret
);
1342 * plain entries are the ones who were created when bucket was not versioned,
1343 * if we override these objects, we need to convert these to versioned entries -- ones that have
1344 * both data entry, and listing key. Their version is going to be empty though
1346 static int convert_plain_entry_to_versioned(cls_method_context_t hctx
, cls_rgw_obj_key
& key
, bool demote_current
, bool instance_only
)
1348 if (!key
.instance
.empty()) {
1352 rgw_bucket_dir_entry entry
;
1355 int ret
= read_key_entry(hctx
, key
, &orig_idx
, &entry
);
1356 if (ret
!= -ENOENT
) {
1358 CLS_LOG(0, "ERROR: read_key_entry() returned ret=%d", ret
);
1362 entry
.versioned_epoch
= 1; /* converted entries are always 1 */
1363 entry
.flags
|= RGW_BUCKET_DIRENT_FLAG_VER
;
1365 if (demote_current
) {
1366 entry
.flags
&= ~RGW_BUCKET_DIRENT_FLAG_CURRENT
;
1370 encode_obj_versioned_data_key(key
, &new_idx
);
1372 if (instance_only
) {
1373 ret
= write_obj_instance_entry(hctx
, entry
, new_idx
);
1375 ret
= write_obj_entries(hctx
, entry
, new_idx
);
1378 CLS_LOG(0, "ERROR: write_obj_entries new_idx=%s returned %d", new_idx
.c_str(), ret
);
1383 ret
= write_version_marker(hctx
, key
);
1392 * link an object version to an olh, update the relevant index entries. It will also handle the
1393 * deletion marker case. We have a few entries that we need to take care of. For object 'foo',
1394 * instance BAR, we'd update the following (not actual encoding):
1395 * - olh data: [BI_BUCKET_OLH_DATA_INDEX]foo
1396 * - object instance data: [BI_BUCKET_OBJ_INSTANCE_INDEX]foo,BAR
1397 * - object instance list entry: foo,123,BAR
1399 * The instance list entry needs to be ordered by newer to older, so we generate an appropriate
1400 * number string that follows the name.
1401 * The top instance for each object is marked appropriately.
1402 * We generate instance entry for deletion markers here, as they are not created prior.
1404 static int rgw_bucket_link_olh(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1406 string olh_data_idx
;
1407 string instance_idx
;
1410 rgw_cls_link_olh_op op
;
1411 auto iter
= in
->cbegin();
1414 } catch (buffer::error
& err
) {
1415 CLS_LOG(0, "ERROR: rgw_bucket_link_olh_op(): failed to decode request\n");
1419 BIVerObjEntry
obj(hctx
, op
.key
);
1420 BIOLHEntry
olh(hctx
, op
.key
);
1422 /* read instance entry */
1423 int ret
= obj
.init(op
.delete_marker
);
1424 bool existed
= (ret
== 0);
1425 if (ret
== -ENOENT
&& op
.delete_marker
) {
1432 if (existed
&& !real_clock::is_zero(op
.unmod_since
)) {
1433 timespec mtime
= ceph::real_clock::to_timespec(obj
.mtime());
1434 timespec unmod
= ceph::real_clock::to_timespec(op
.unmod_since
);
1435 if (!op
.high_precision_time
) {
1439 if (mtime
>= unmod
) {
1440 return 0; /* no need to set error, we just return 0 and avoid writing to the bi log */
1447 * Special handling for null instance object / delete-marker. For these objects we're going to
1448 * have separate instances for a data object vs. delete-marker to avoid collisions. We now check
1449 * if we got to overwrite a previous entry, and in that case we'll remove its list entry.
1451 if (op
.key
.instance
.empty()) {
1452 BIVerObjEntry
other_obj(hctx
, op
.key
);
1453 ret
= other_obj
.init(!op
.delete_marker
); /* try reading the other null versioned entry */
1454 existed
= (ret
>= 0 && !other_obj
.is_delete_marker());
1455 if (ret
>= 0 && other_obj
.is_delete_marker() != op
.delete_marker
) {
1456 ret
= other_obj
.unlink_list_entry();
1462 removing
= existed
&& op
.delete_marker
;
1464 ret
= other_obj
.unlink();
1470 removing
= (existed
&& !obj
.is_delete_marker() && op
.delete_marker
);
1473 if (op
.delete_marker
) {
1474 /* a deletion marker, need to initialize entry as such */
1475 obj
.init_as_delete_marker(op
.meta
);
1480 ret
= olh
.init(&olh_found
);
1485 if (!olh
.start_modify(op
.olh_epoch
)) {
1486 ret
= obj
.write(op
.olh_epoch
, false);
1491 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false, op
.olh_epoch
);
1497 const string
& olh_tag
= olh
.get_tag();
1498 if (op
.olh_tag
!= olh_tag
) {
1499 if (!olh
.pending_removal()) {
1500 CLS_LOG(5, "NOTICE: op.olh_tag (%s) != olh.tag (%s)", op
.olh_tag
.c_str(), olh_tag
.c_str());
1503 /* if pending removal, this is a new olh instance */
1504 olh
.set_tag(op
.olh_tag
);
1507 rgw_bucket_olh_entry
& olh_entry
= olh
.get_entry();
1508 /* found olh, previous instance is no longer the latest, need to update */
1509 if (!(olh_entry
.key
== op
.key
)) {
1510 BIVerObjEntry
old_obj(hctx
, olh_entry
.key
);
1512 ret
= old_obj
.demote_current();
1514 CLS_LOG(0, "ERROR: could not demote current on previous key ret=%d", ret
);
1519 olh
.set_pending_removal(false);
1521 bool instance_only
= (op
.key
.instance
.empty() && op
.delete_marker
);
1522 cls_rgw_obj_key
key(op
.key
.name
);
1523 ret
= convert_plain_entry_to_versioned(hctx
, key
, true, instance_only
);
1525 CLS_LOG(0, "ERROR: convert_plain_entry_to_versioned ret=%d", ret
);
1528 olh
.set_tag(op
.olh_tag
);
1531 /* update the olh log */
1532 olh
.update_log(CLS_RGW_OLH_OP_LINK_OLH
, op
.op_tag
, op
.key
, op
.delete_marker
);
1534 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false);
1537 olh
.update(op
.key
, op
.delete_marker
);
1539 olh
.set_exists(true);
1543 CLS_LOG(0, "ERROR: failed to update olh ret=%d", ret
);
1547 /* write the instance and list entries */
1548 ret
= obj
.write(olh
.get_epoch(), true);
1553 rgw_bucket_dir_header header
;
1554 ret
= read_bucket_header(hctx
, &header
);
1556 CLS_LOG(1, "ERROR: rgw_bucket_link_olh(): failed to read header\n");
1560 if (op
.log_op
&& !header
.syncstopped
) {
1561 rgw_bucket_dir_entry
& entry
= obj
.get_dir_entry();
1563 rgw_bucket_entry_ver ver
;
1564 ver
.epoch
= (op
.olh_epoch
? op
.olh_epoch
: olh
.get_epoch());
1566 string
*powner
= NULL
;
1567 string
*powner_display_name
= NULL
;
1569 if (op
.delete_marker
) {
1570 powner
= &entry
.meta
.owner
;
1571 powner_display_name
= &entry
.meta
.owner_display_name
;
1574 RGWModifyOp operation
= (op
.delete_marker
? CLS_RGW_OP_LINK_OLH_DM
: CLS_RGW_OP_LINK_OLH
);
1575 ret
= log_index_operation(hctx
, op
.key
, operation
, op
.op_tag
,
1576 entry
.meta
.mtime
, ver
,
1577 CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, op
.bilog_flags
| RGW_BILOG_FLAG_VERSIONED_OP
,
1578 powner
, powner_display_name
, &op
.zones_trace
);
1582 return write_bucket_header(hctx
, &header
); /* updates header version */
1588 static int rgw_bucket_unlink_instance(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1590 string olh_data_idx
;
1591 string instance_idx
;
1594 rgw_cls_unlink_instance_op op
;
1595 auto iter
= in
->cbegin();
1598 } catch (buffer::error
& err
) {
1599 CLS_LOG(0, "ERROR: rgw_bucket_rm_obj_instance_op(): failed to decode request\n");
1603 cls_rgw_obj_key dest_key
= op
.key
;
1604 if (dest_key
.instance
== "null") {
1605 dest_key
.instance
.clear();
1608 BIVerObjEntry
obj(hctx
, dest_key
);
1609 BIOLHEntry
olh(hctx
, dest_key
);
1611 int ret
= obj
.init();
1612 if (ret
== -ENOENT
) {
1613 return 0; /* already removed */
1616 CLS_LOG(0, "ERROR: obj.init() returned ret=%d", ret
);
1621 ret
= olh
.init(&olh_found
);
1623 CLS_LOG(0, "ERROR: olh.init() returned ret=%d", ret
);
1628 bool instance_only
= false;
1629 cls_rgw_obj_key
key(dest_key
.name
);
1630 ret
= convert_plain_entry_to_versioned(hctx
, key
, true, instance_only
);
1632 CLS_LOG(0, "ERROR: convert_plain_entry_to_versioned ret=%d", ret
);
1635 olh
.update(dest_key
, false);
1636 olh
.set_tag(op
.olh_tag
);
1641 if (!olh
.start_modify(op
.olh_epoch
)) {
1642 ret
= obj
.unlink_list_entry();
1647 if (!obj
.is_delete_marker()) {
1648 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false, op
.olh_epoch
);
1654 rgw_bucket_olh_entry
& olh_entry
= olh
.get_entry();
1655 cls_rgw_obj_key
& olh_key
= olh_entry
.key
;
1656 CLS_LOG(20, "%s(): updating olh log: existing olh entry: %s[%s] (delete_marker=%d)", __func__
,
1657 olh_key
.name
.c_str(), olh_key
.instance
.c_str(), olh_entry
.delete_marker
);
1659 if (olh_key
== dest_key
) {
1660 /* this is the current head, need to update! */
1661 cls_rgw_obj_key next_key
;
1663 ret
= obj
.find_next_key(&next_key
, &found
);
1665 CLS_LOG(0, "ERROR: obj.find_next_key() returned ret=%d", ret
);
1670 BIVerObjEntry
next(hctx
, next_key
);
1671 ret
= next
.write(olh
.get_epoch(), true);
1673 CLS_LOG(0, "ERROR: next.write() returned ret=%d", ret
);
1677 CLS_LOG(20, "%s(): updating olh log: link olh -> %s[%s] (is_delete=%d)", __func__
,
1678 next_key
.name
.c_str(), next_key
.instance
.c_str(), (int)next
.is_delete_marker());
1680 olh
.update(next_key
, next
.is_delete_marker());
1681 olh
.update_log(CLS_RGW_OLH_OP_LINK_OLH
, op
.op_tag
, next_key
, next
.is_delete_marker());
1683 /* next_key is empty */
1684 olh
.update(next_key
, false);
1685 olh
.update_log(CLS_RGW_OLH_OP_UNLINK_OLH
, op
.op_tag
, next_key
, false);
1686 olh
.set_exists(false);
1687 olh
.set_pending_removal(true);
1691 if (!obj
.is_delete_marker()) {
1692 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false);
1694 /* this is a delete marker, it's our responsibility to remove its instance entry */
1701 ret
= obj
.unlink_list_entry();
1711 rgw_bucket_dir_header header
;
1712 ret
= read_bucket_header(hctx
, &header
);
1714 CLS_LOG(1, "ERROR: rgw_bucket_unlink_instance(): failed to read header\n");
1718 if (op
.log_op
&& !header
.syncstopped
) {
1719 rgw_bucket_entry_ver ver
;
1720 ver
.epoch
= (op
.olh_epoch
? op
.olh_epoch
: olh
.get_epoch());
1722 real_time mtime
= obj
.mtime(); /* mtime has no real meaning in instance removal context */
1723 ret
= log_index_operation(hctx
, op
.key
, CLS_RGW_OP_UNLINK_INSTANCE
, op
.op_tag
,
1725 CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
,
1726 op
.bilog_flags
| RGW_BILOG_FLAG_VERSIONED_OP
, NULL
, NULL
, &op
.zones_trace
);
1730 return write_bucket_header(hctx
, &header
); /* updates header version */
1736 static int rgw_bucket_read_olh_log(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1739 rgw_cls_read_olh_log_op op
;
1740 auto iter
= in
->cbegin();
1743 } catch (buffer::error
& err
) {
1744 CLS_LOG(0, "ERROR: rgw_bucket_read_olh_log(): failed to decode request\n");
1748 if (!op
.olh
.instance
.empty()) {
1749 CLS_LOG(1, "bad key passed in (non empty instance)");
1753 rgw_bucket_olh_entry olh_data_entry
;
1754 string olh_data_key
;
1755 encode_olh_data_key(op
.olh
, &olh_data_key
);
1756 int ret
= read_index_entry(hctx
, olh_data_key
, &olh_data_entry
);
1757 if (ret
< 0 && ret
!= -ENOENT
) {
1758 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
1762 if (olh_data_entry
.tag
!= op
.olh_tag
) {
1763 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());
1767 rgw_cls_read_olh_log_ret op_ret
;
1769 #define MAX_OLH_LOG_ENTRIES 1000
1770 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >& log
= olh_data_entry
.pending_log
;
1772 if (log
.begin()->first
> op
.ver_marker
&& log
.size() <= MAX_OLH_LOG_ENTRIES
) {
1774 op_ret
.is_truncated
= false;
1776 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >::iterator iter
= log
.upper_bound(op
.ver_marker
);
1778 for (int i
= 0; i
< MAX_OLH_LOG_ENTRIES
&& iter
!= log
.end(); ++i
, ++iter
) {
1779 op_ret
.log
[iter
->first
] = iter
->second
;
1781 op_ret
.is_truncated
= (iter
!= log
.end());
1784 encode(op_ret
, *out
);
1789 static int rgw_bucket_trim_olh_log(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1792 rgw_cls_trim_olh_log_op op
;
1793 auto iter
= in
->cbegin();
1796 } catch (buffer::error
& err
) {
1797 CLS_LOG(0, "ERROR: rgw_bucket_trim_olh_log(): failed to decode request\n");
1801 if (!op
.olh
.instance
.empty()) {
1802 CLS_LOG(1, "bad key passed in (non empty instance)");
1806 /* read olh entry */
1807 rgw_bucket_olh_entry olh_data_entry
;
1808 string olh_data_key
;
1809 encode_olh_data_key(op
.olh
, &olh_data_key
);
1810 int ret
= read_index_entry(hctx
, olh_data_key
, &olh_data_entry
);
1811 if (ret
< 0 && ret
!= -ENOENT
) {
1812 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
1816 if (olh_data_entry
.tag
!= op
.olh_tag
) {
1817 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());
1821 /* remove all versions up to and including ver from the pending map */
1822 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >& log
= olh_data_entry
.pending_log
;
1823 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >::iterator liter
= log
.begin();
1824 while (liter
!= log
.end() && liter
->first
<= op
.ver
) {
1825 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >::iterator rm_iter
= liter
;
1830 /* write the olh data entry */
1831 ret
= write_entry(hctx
, olh_data_entry
, olh_data_key
);
1833 CLS_LOG(0, "ERROR: write_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
1840 static int rgw_bucket_clear_olh(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1843 rgw_cls_bucket_clear_olh_op op
;
1844 auto iter
= in
->cbegin();
1847 } catch (buffer::error
& err
) {
1848 CLS_LOG(0, "ERROR: rgw_bucket_clear_olh(): failed to decode request\n");
1852 if (!op
.key
.instance
.empty()) {
1853 CLS_LOG(1, "bad key passed in (non empty instance)");
1857 /* read olh entry */
1858 rgw_bucket_olh_entry olh_data_entry
;
1859 string olh_data_key
;
1860 encode_olh_data_key(op
.key
, &olh_data_key
);
1861 int ret
= read_index_entry(hctx
, olh_data_key
, &olh_data_entry
);
1862 if (ret
< 0 && ret
!= -ENOENT
) {
1863 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
1867 if (olh_data_entry
.tag
!= op
.olh_tag
) {
1868 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());
1872 ret
= cls_cxx_map_remove_key(hctx
, olh_data_key
);
1874 CLS_LOG(1, "NOTICE: %s(): can't remove key %s ret=%d", __func__
, olh_data_key
.c_str(), ret
);
1878 rgw_bucket_dir_entry plain_entry
;
1880 /* read plain entry, make sure it's a versioned place holder */
1881 ret
= read_index_entry(hctx
, op
.key
.name
, &plain_entry
);
1882 if (ret
== -ENOENT
) {
1883 /* we're done, no entry existing */
1887 CLS_LOG(0, "ERROR: read_index_entry key=%s ret=%d", op
.key
.name
.c_str(), ret
);
1891 if ((plain_entry
.flags
& RGW_BUCKET_DIRENT_FLAG_VER_MARKER
) == 0) {
1892 /* it's not a version marker, don't remove it */
1896 ret
= cls_cxx_map_remove_key(hctx
, op
.key
.name
);
1898 CLS_LOG(1, "NOTICE: %s(): can't remove key %s ret=%d", __func__
, op
.key
.name
.c_str(), ret
);
1905 int rgw_dir_suggest_changes(cls_method_context_t hctx
,
1906 bufferlist
*in
, bufferlist
*out
)
1908 CLS_LOG(1, "rgw_dir_suggest_changes()");
1910 bufferlist header_bl
;
1911 rgw_bucket_dir_header header
;
1912 bool header_changed
= false;
1914 int rc
= read_bucket_header(hctx
, &header
);
1916 CLS_LOG(1, "ERROR: rgw_dir_suggest_changes(): failed to read header\n");
1920 timespan
tag_timeout(
1921 std::chrono::seconds(
1922 header
.tag_timeout
? header
.tag_timeout
: CEPH_RGW_TAG_TIMEOUT
));
1924 auto in_iter
= in
->cbegin();
1926 while (!in_iter
.end()) {
1928 rgw_bucket_dir_entry cur_change
;
1929 rgw_bucket_dir_entry cur_disk
;
1931 decode(op
, in_iter
);
1932 decode(cur_change
, in_iter
);
1933 } catch (buffer::error
& err
) {
1934 CLS_LOG(1, "ERROR: rgw_dir_suggest_changes(): failed to decode request\n");
1938 bufferlist cur_disk_bl
;
1939 string cur_change_key
;
1940 encode_obj_index_key(cur_change
.key
, &cur_change_key
);
1941 int ret
= cls_cxx_map_get_val(hctx
, cur_change_key
, &cur_disk_bl
);
1942 if (ret
< 0 && ret
!= -ENOENT
)
1945 if (ret
== -ENOENT
) {
1949 if (cur_disk_bl
.length()) {
1950 auto cur_disk_iter
= cur_disk_bl
.cbegin();
1952 decode(cur_disk
, cur_disk_iter
);
1953 } catch (buffer::error
& error
) {
1954 CLS_LOG(1, "ERROR: rgw_dir_suggest_changes(): failed to decode cur_disk\n");
1958 real_time cur_time
= real_clock::now();
1959 map
<string
, rgw_bucket_pending_info
>::iterator iter
=
1960 cur_disk
.pending_map
.begin();
1961 while(iter
!= cur_disk
.pending_map
.end()) {
1962 map
<string
, rgw_bucket_pending_info
>::iterator cur_iter
=iter
++;
1963 if (cur_time
> (cur_iter
->second
.timestamp
+ timespan(tag_timeout
))) {
1964 cur_disk
.pending_map
.erase(cur_iter
);
1969 CLS_LOG(20, "cur_disk.pending_map.empty()=%d op=%d cur_disk.exists=%d cur_change.pending_map.size()=%d cur_change.exists=%d\n",
1970 cur_disk
.pending_map
.empty(), (int)op
, cur_disk
.exists
,
1971 (int)cur_change
.pending_map
.size(), cur_change
.exists
);
1973 if (cur_disk
.pending_map
.empty()) {
1974 if (cur_disk
.exists
) {
1975 rgw_bucket_category_stats
& old_stats
= header
.stats
[cur_disk
.meta
.category
];
1976 CLS_LOG(10, "total_entries: %" PRId64
" -> %" PRId64
"\n", old_stats
.num_entries
, old_stats
.num_entries
- 1);
1977 old_stats
.num_entries
--;
1978 old_stats
.total_size
-= cur_disk
.meta
.accounted_size
;
1979 old_stats
.total_size_rounded
-= cls_rgw_get_rounded_size(cur_disk
.meta
.accounted_size
);
1980 old_stats
.actual_size
-= cur_disk
.meta
.size
;
1981 header_changed
= true;
1983 rgw_bucket_category_stats
& stats
= header
.stats
[cur_change
.meta
.category
];
1984 bool log_op
= (op
& CEPH_RGW_DIR_SUGGEST_LOG_OP
) != 0;
1985 op
&= CEPH_RGW_DIR_SUGGEST_OP_MASK
;
1987 case CEPH_RGW_REMOVE
:
1988 CLS_LOG(10, "CEPH_RGW_REMOVE name=%s instance=%s\n", cur_change
.key
.name
.c_str(), cur_change
.key
.instance
.c_str());
1989 ret
= cls_cxx_map_remove_key(hctx
, cur_change_key
);
1992 if (log_op
&& cur_disk
.exists
&& !header
.syncstopped
) {
1993 ret
= log_index_operation(hctx
, cur_disk
.key
, CLS_RGW_OP_DEL
, cur_disk
.tag
, cur_disk
.meta
.mtime
,
1994 cur_disk
.ver
, CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, 0, NULL
, NULL
, NULL
);
1996 CLS_LOG(0, "ERROR: %s(): failed to log operation ret=%d", __func__
, ret
);
2001 case CEPH_RGW_UPDATE
:
2002 CLS_LOG(10, "CEPH_RGW_UPDATE name=%s instance=%s total_entries: %" PRId64
" -> %" PRId64
"\n",
2003 cur_change
.key
.name
.c_str(), cur_change
.key
.instance
.c_str(), stats
.num_entries
, stats
.num_entries
+ 1);
2005 stats
.num_entries
++;
2006 stats
.total_size
+= cur_change
.meta
.accounted_size
;
2007 stats
.total_size_rounded
+= cls_rgw_get_rounded_size(cur_change
.meta
.accounted_size
);
2008 stats
.actual_size
+= cur_change
.meta
.size
;
2009 header_changed
= true;
2010 cur_change
.index_ver
= header
.ver
;
2011 bufferlist cur_state_bl
;
2012 encode(cur_change
, cur_state_bl
);
2013 ret
= cls_cxx_map_set_val(hctx
, cur_change_key
, &cur_state_bl
);
2016 if (log_op
&& !header
.syncstopped
) {
2017 ret
= log_index_operation(hctx
, cur_change
.key
, CLS_RGW_OP_ADD
, cur_change
.tag
, cur_change
.meta
.mtime
,
2018 cur_change
.ver
, CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, 0, NULL
, NULL
, NULL
);
2020 CLS_LOG(0, "ERROR: %s(): failed to log operation ret=%d", __func__
, ret
);
2026 } // if (cur_disk.pending_map.empty())
2027 } // while (!in_iter.end())
2029 if (header_changed
) {
2030 return write_bucket_header(hctx
, &header
);
2035 static int rgw_obj_remove(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2038 rgw_cls_obj_remove_op op
;
2039 auto iter
= in
->cbegin();
2042 } catch (buffer::error
& err
) {
2043 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2047 if (op
.keep_attr_prefixes
.empty()) {
2048 return cls_cxx_remove(hctx
);
2051 map
<string
, bufferlist
> attrset
;
2052 int ret
= cls_cxx_getxattrs(hctx
, &attrset
);
2053 if (ret
< 0 && ret
!= -ENOENT
) {
2054 CLS_LOG(0, "ERROR: %s(): cls_cxx_getxattrs() returned %d", __func__
, ret
);
2058 map
<string
, bufferlist
> new_attrs
;
2059 for (list
<string
>::iterator iter
= op
.keep_attr_prefixes
.begin();
2060 iter
!= op
.keep_attr_prefixes
.end(); ++iter
) {
2061 string
& check_prefix
= *iter
;
2063 for (map
<string
, bufferlist
>::iterator aiter
= attrset
.lower_bound(check_prefix
);
2064 aiter
!= attrset
.end(); ++aiter
) {
2065 const string
& attr
= aiter
->first
;
2067 if (attr
.substr(0, check_prefix
.size()) > check_prefix
) {
2071 new_attrs
[attr
] = aiter
->second
;
2075 CLS_LOG(20, "%s(): removing object", __func__
);
2076 ret
= cls_cxx_remove(hctx
);
2078 CLS_LOG(0, "ERROR: %s(): cls_cxx_remove returned %d", __func__
, ret
);
2082 if (new_attrs
.empty()) {
2083 /* no data to keep */
2087 ret
= cls_cxx_create(hctx
, false);
2089 CLS_LOG(0, "ERROR: %s(): cls_cxx_create returned %d", __func__
, ret
);
2093 for (map
<string
, bufferlist
>::iterator aiter
= new_attrs
.begin();
2094 aiter
!= new_attrs
.end(); ++aiter
) {
2095 const string
& attr
= aiter
->first
;
2097 ret
= cls_cxx_setxattr(hctx
, attr
.c_str(), &aiter
->second
);
2098 CLS_LOG(20, "%s(): setting attr: %s", __func__
, attr
.c_str());
2100 CLS_LOG(0, "ERROR: %s(): cls_cxx_setxattr (attr=%s) returned %d", __func__
, attr
.c_str(), ret
);
2108 static int rgw_obj_store_pg_ver(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2111 rgw_cls_obj_store_pg_ver_op op
;
2112 auto iter
= in
->cbegin();
2115 } catch (buffer::error
& err
) {
2116 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2121 uint64_t ver
= cls_current_version(hctx
);
2123 int ret
= cls_cxx_setxattr(hctx
, op
.attr
.c_str(), &bl
);
2125 CLS_LOG(0, "ERROR: %s(): cls_cxx_setxattr (attr=%s) returned %d", __func__
, op
.attr
.c_str(), ret
);
2132 static int rgw_obj_check_attrs_prefix(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2135 rgw_cls_obj_check_attrs_prefix op
;
2136 auto iter
= in
->cbegin();
2139 } catch (buffer::error
& err
) {
2140 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2144 if (op
.check_prefix
.empty()) {
2148 map
<string
, bufferlist
> attrset
;
2149 int ret
= cls_cxx_getxattrs(hctx
, &attrset
);
2150 if (ret
< 0 && ret
!= -ENOENT
) {
2151 CLS_LOG(0, "ERROR: %s(): cls_cxx_getxattrs() returned %d", __func__
, ret
);
2157 for (map
<string
, bufferlist
>::iterator aiter
= attrset
.lower_bound(op
.check_prefix
);
2158 aiter
!= attrset
.end(); ++aiter
) {
2159 const string
& attr
= aiter
->first
;
2161 if (attr
.substr(0, op
.check_prefix
.size()) > op
.check_prefix
) {
2168 if (exist
== op
.fail_if_exist
) {
2175 static int rgw_obj_check_mtime(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2178 rgw_cls_obj_check_mtime op
;
2179 auto iter
= in
->cbegin();
2182 } catch (buffer::error
& err
) {
2183 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2188 int ret
= cls_cxx_stat2(hctx
, NULL
, &obj_ut
);
2189 if (ret
< 0 && ret
!= -ENOENT
) {
2190 CLS_LOG(0, "ERROR: %s(): cls_cxx_stat() returned %d", __func__
, ret
);
2193 if (ret
== -ENOENT
) {
2194 CLS_LOG(10, "object does not exist, skipping check");
2197 ceph_timespec obj_ts
= ceph::real_clock::to_ceph_timespec(obj_ut
);
2198 ceph_timespec op_ts
= ceph::real_clock::to_ceph_timespec(op
.mtime
);
2200 if (!op
.high_precision_time
) {
2205 CLS_LOG(10, "%s: obj_ut=%lld.%06lld op.mtime=%lld.%06lld", __func__
,
2206 (long long)obj_ts
.tv_sec
, (long long)obj_ts
.tv_nsec
,
2207 (long long)op_ts
.tv_sec
, (long long)op_ts
.tv_nsec
);
2212 case CLS_RGW_CHECK_TIME_MTIME_EQ
:
2213 check
= (obj_ts
== op_ts
);
2215 case CLS_RGW_CHECK_TIME_MTIME_LT
:
2216 check
= (obj_ts
< op_ts
);
2218 case CLS_RGW_CHECK_TIME_MTIME_LE
:
2219 check
= (obj_ts
<= op_ts
);
2221 case CLS_RGW_CHECK_TIME_MTIME_GT
:
2222 check
= (obj_ts
> op_ts
);
2224 case CLS_RGW_CHECK_TIME_MTIME_GE
:
2225 check
= (obj_ts
>= op_ts
);
2238 static int rgw_bi_get_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2241 rgw_cls_bi_get_op op
;
2242 auto iter
= in
->cbegin();
2245 } catch (buffer::error
& err
) {
2246 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2253 case BIIndexType::Plain
:
2256 case BIIndexType::Instance
:
2257 encode_obj_index_key(op
.key
, &idx
);
2259 case BIIndexType::OLH
:
2260 encode_olh_data_key(op
.key
, &idx
);
2263 CLS_LOG(10, "%s(): invalid key type encoding: %d",
2264 __func__
, int(op
.type
));
2268 rgw_cls_bi_get_ret op_ret
;
2270 rgw_cls_bi_entry
& entry
= op_ret
.entry
;
2272 entry
.type
= op
.type
;
2275 int r
= cls_cxx_map_get_val(hctx
, idx
, &entry
.data
);
2277 CLS_LOG(10, "%s(): cls_cxx_map_get_val() returned %d", __func__
, r
);
2281 encode(op_ret
, *out
);
2286 static int rgw_bi_put_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2289 rgw_cls_bi_put_op op
;
2290 auto iter
= in
->cbegin();
2293 } catch (buffer::error
& err
) {
2294 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2298 rgw_cls_bi_entry
& entry
= op
.entry
;
2300 int r
= cls_cxx_map_set_val(hctx
, entry
.idx
, &entry
.data
);
2302 CLS_LOG(0, "ERROR: %s(): cls_cxx_map_set_val() returned r=%d", __func__
, r
);
2308 static int list_plain_entries(cls_method_context_t hctx
, const string
& name
, const string
& marker
, uint32_t max
,
2309 list
<rgw_cls_bi_entry
> *entries
, bool *pmore
)
2311 string filter
= name
;
2312 string start_key
= marker
;
2314 string end_key
; // stop listing at bi_log_prefix
2315 bi_log_prefix(end_key
);
2318 map
<string
, bufferlist
> keys
;
2319 int ret
= cls_cxx_map_get_vals(hctx
, start_key
, filter
, max
, &keys
, pmore
);
2324 map
<string
, bufferlist
>::iterator iter
;
2325 for (iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
2326 if (iter
->first
>= end_key
) {
2327 /* past the end of plain namespace */
2334 rgw_cls_bi_entry entry
;
2335 entry
.type
= BIIndexType::Plain
;
2336 entry
.idx
= iter
->first
;
2337 entry
.data
= iter
->second
;
2339 auto biter
= entry
.data
.cbegin();
2341 rgw_bucket_dir_entry e
;
2344 } catch (buffer::error
& err
) {
2345 CLS_LOG(0, "ERROR: %s(): failed to decode buffer", __func__
);
2349 CLS_LOG(20, "%s(): entry.idx=%s e.key.name=%s", __func__
, escape_str(entry
.idx
).c_str(), escape_str(e
.key
.name
).c_str());
2351 if (!name
.empty() && e
.key
.name
!= name
) {
2352 /* we are skipping the rest of the entries */
2359 entries
->push_back(entry
);
2361 if (count
>= (int)max
) {
2364 start_key
= entry
.idx
;
2370 static int list_instance_entries(cls_method_context_t hctx
, const string
& name
, const string
& marker
, uint32_t max
,
2371 list
<rgw_cls_bi_entry
> *entries
, bool *pmore
)
2373 cls_rgw_obj_key
key(name
);
2374 string first_instance_idx
;
2375 encode_obj_versioned_data_key(key
, &first_instance_idx
);
2378 if (!name
.empty()) {
2379 start_key
= first_instance_idx
;
2381 start_key
= BI_PREFIX_CHAR
;
2382 start_key
.append(bucket_index_prefixes
[BI_BUCKET_OBJ_INSTANCE_INDEX
]);
2384 string filter
= start_key
;
2385 if (bi_entry_gt(marker
, start_key
)) {
2389 map
<string
, bufferlist
> keys
;
2391 int ret
= cls_cxx_map_get_val(hctx
, start_key
, &k
);
2392 if (ret
< 0 && ret
!= -ENOENT
) {
2395 bool found_first
= (ret
== 0);
2400 ret
= cls_cxx_map_get_vals(hctx
, start_key
, string(), max
, &keys
, pmore
);
2401 CLS_LOG(20, "%s(): start_key=%s first_instance_idx=%s keys.size()=%d", __func__
, escape_str(start_key
).c_str(), escape_str(first_instance_idx
).c_str(), (int)keys
.size());
2407 keys
[start_key
].claim(k
);
2410 map
<string
, bufferlist
>::iterator iter
;
2411 for (iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
2412 rgw_cls_bi_entry entry
;
2413 entry
.type
= BIIndexType::Instance
;
2414 entry
.idx
= iter
->first
;
2415 entry
.data
= iter
->second
;
2417 if (!filter
.empty() && entry
.idx
.compare(0, filter
.size(), filter
) != 0) {
2418 /* we are skipping the rest of the entries */
2425 CLS_LOG(20, "%s(): entry.idx=%s", __func__
, escape_str(entry
.idx
).c_str());
2427 auto biter
= entry
.data
.cbegin();
2429 rgw_bucket_dir_entry e
;
2432 } catch (buffer::error
& err
) {
2433 CLS_LOG(0, "ERROR: %s(): failed to decode buffer (size=%d)", __func__
, entry
.data
.length());
2437 if (!name
.empty() && e
.key
.name
!= name
) {
2438 /* we are skipping the rest of the entries */
2445 entries
->push_back(entry
);
2447 start_key
= entry
.idx
;
2453 static int list_olh_entries(cls_method_context_t hctx
, const string
& name
, const string
& marker
, uint32_t max
,
2454 list
<rgw_cls_bi_entry
> *entries
, bool *pmore
)
2456 cls_rgw_obj_key
key(name
);
2457 string first_instance_idx
;
2458 encode_olh_data_key(key
, &first_instance_idx
);
2461 if (!name
.empty()) {
2462 start_key
= first_instance_idx
;
2464 start_key
= BI_PREFIX_CHAR
;
2465 start_key
.append(bucket_index_prefixes
[BI_BUCKET_OLH_DATA_INDEX
]);
2467 string filter
= start_key
;
2468 if (bi_entry_gt(marker
, start_key
)) {
2472 map
<string
, bufferlist
> keys
;
2475 ret
= cls_cxx_map_get_val(hctx
, start_key
, &k
);
2476 if (ret
< 0 && ret
!= -ENOENT
) {
2479 bool found_first
= (ret
== 0);
2484 ret
= cls_cxx_map_get_vals(hctx
, start_key
, string(), max
, &keys
, pmore
);
2485 CLS_LOG(20, "%s(): start_key=%s first_instance_idx=%s keys.size()=%d", __func__
, escape_str(start_key
).c_str(), escape_str(first_instance_idx
).c_str(), (int)keys
.size());
2492 keys
[start_key
].claim(k
);
2495 map
<string
, bufferlist
>::iterator iter
;
2496 for (iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
2497 rgw_cls_bi_entry entry
;
2498 entry
.type
= BIIndexType::OLH
;
2499 entry
.idx
= iter
->first
;
2500 entry
.data
= iter
->second
;
2502 if (!filter
.empty() && entry
.idx
.compare(0, filter
.size(), filter
) != 0) {
2503 /* we are skipping the rest of the entries */
2510 CLS_LOG(20, "%s(): entry.idx=%s", __func__
, escape_str(entry
.idx
).c_str());
2512 auto biter
= entry
.data
.cbegin();
2514 rgw_bucket_olh_entry e
;
2517 } catch (buffer::error
& err
) {
2518 CLS_LOG(0, "ERROR: %s(): failed to decode buffer (size=%d)", __func__
, entry
.data
.length());
2522 if (!name
.empty() && e
.key
.name
!= name
) {
2523 /* we are skipping the rest of the entries */
2530 entries
->push_back(entry
);
2532 start_key
= entry
.idx
;
2538 static int rgw_bi_list_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2541 rgw_cls_bi_list_op op
;
2542 auto iter
= in
->cbegin();
2545 } catch (buffer::error
& err
) {
2546 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2550 rgw_cls_bi_list_ret op_ret
;
2552 string filter
= op
.name
;
2553 #define MAX_BI_LIST_ENTRIES 1000
2554 int32_t max
= (op
.max
< MAX_BI_LIST_ENTRIES
? op
.max
: MAX_BI_LIST_ENTRIES
);
2555 string start_key
= op
.marker
;
2557 int ret
= list_plain_entries(hctx
, op
.name
, op
.marker
, max
, &op_ret
.entries
, &more
);
2559 CLS_LOG(0, "ERROR: %s(): list_plain_entries returned ret=%d", __func__
, ret
);
2564 CLS_LOG(20, "found %d plain entries", count
);
2567 ret
= list_instance_entries(hctx
, op
.name
, op
.marker
, max
- count
, &op_ret
.entries
, &more
);
2569 CLS_LOG(0, "ERROR: %s(): list_instance_entries returned ret=%d", __func__
, ret
);
2577 ret
= list_olh_entries(hctx
, op
.name
, op
.marker
, max
- count
, &op_ret
.entries
, &more
);
2579 CLS_LOG(0, "ERROR: %s(): list_olh_entries returned ret=%d", __func__
, ret
);
2586 op_ret
.is_truncated
= (count
>= max
) || more
;
2587 while (count
> max
) {
2588 op_ret
.entries
.pop_back();
2592 encode(op_ret
, *out
);
2597 int bi_log_record_decode(bufferlist
& bl
, rgw_bi_log_entry
& e
)
2599 auto iter
= bl
.cbegin();
2602 } catch (buffer::error
& err
) {
2603 CLS_LOG(0, "ERROR: failed to decode rgw_bi_log_entry");
2609 static int bi_log_iterate_entries(cls_method_context_t hctx
, const string
& marker
, const string
& end_marker
,
2610 string
& key_iter
, uint32_t max_entries
, bool *truncated
,
2611 int (*cb
)(cls_method_context_t
, const string
&, rgw_bi_log_entry
&, void *),
2614 CLS_LOG(10, "bi_log_iterate_range");
2616 map
<string
, bufferlist
> keys
;
2617 string filter_prefix
, end_key
;
2625 if (key_iter
.empty()) {
2626 key
= BI_PREFIX_CHAR
;
2627 key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
2632 start_key
= key_iter
;
2635 if (end_marker
.empty()) {
2636 end_key
= BI_PREFIX_CHAR
;
2637 end_key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
+ 1]);
2639 end_key
= BI_PREFIX_CHAR
;
2640 end_key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
2641 end_key
.append(end_marker
);
2644 CLS_LOG(10, "bi_log_iterate_entries start_key=%s end_key=%s\n", start_key
.c_str(), end_key
.c_str());
2648 int ret
= cls_cxx_map_get_vals(hctx
, start_key
, filter
, max_entries
, &keys
, truncated
);
2652 map
<string
, bufferlist
>::iterator iter
= keys
.begin();
2653 if (iter
== keys
.end())
2656 uint32_t num_keys
= keys
.size();
2658 for (; iter
!= keys
.end(); ++iter
,++i
) {
2659 const string
& key
= iter
->first
;
2662 CLS_LOG(10, "bi_log_iterate_entries key=%s bl.length=%d\n", key
.c_str(), (int)iter
->second
.length());
2664 if (key
.compare(end_key
) > 0) {
2672 ret
= bi_log_record_decode(iter
->second
, e
);
2676 ret
= cb(hctx
, key
, e
, param
);
2680 if (i
== num_keys
- 1) {
2688 static int bi_log_list_cb(cls_method_context_t hctx
, const string
& key
, rgw_bi_log_entry
& info
, void *param
)
2690 list
<rgw_bi_log_entry
> *l
= (list
<rgw_bi_log_entry
> *)param
;
2695 static int bi_log_list_entries(cls_method_context_t hctx
, const string
& marker
,
2696 uint32_t max
, list
<rgw_bi_log_entry
>& entries
, bool *truncated
)
2700 int ret
= bi_log_iterate_entries(hctx
, marker
, end_marker
,
2701 key_iter
, max
, truncated
,
2702 bi_log_list_cb
, &entries
);
2706 static int rgw_bi_log_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2708 auto in_iter
= in
->cbegin();
2710 cls_rgw_bi_log_list_op op
;
2712 decode(op
, in_iter
);
2713 } catch (buffer::error
& err
) {
2714 CLS_LOG(1, "ERROR: rgw_bi_log_list(): failed to decode entry\n");
2718 cls_rgw_bi_log_list_ret op_ret
;
2719 int ret
= bi_log_list_entries(hctx
, op
.marker
, op
.max
, op_ret
.entries
, &op_ret
.truncated
);
2723 encode(op_ret
, *out
);
2728 static int bi_log_list_trim_cb(cls_method_context_t hctx
, const string
& key
, rgw_bi_log_entry
& info
, void *param
)
2730 list
<rgw_bi_log_entry
> *entries
= (list
<rgw_bi_log_entry
> *)param
;
2732 entries
->push_back(info
);
2736 static int bi_log_remove_entry(cls_method_context_t hctx
, rgw_bi_log_entry
& entry
)
2739 key
= BI_PREFIX_CHAR
;
2740 key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
2741 key
.append(entry
.id
);
2742 return cls_cxx_map_remove_key(hctx
, key
);
2745 static int bi_log_list_trim_entries(cls_method_context_t hctx
,
2746 const string
& start_marker
, const string
& end_marker
,
2747 list
<rgw_bi_log_entry
>& entries
, bool *truncated
)
2750 #define MAX_TRIM_ENTRIES 1000 /* max entries to trim in a single operation */
2751 int ret
= bi_log_iterate_entries(hctx
, start_marker
, end_marker
,
2752 key_iter
, MAX_TRIM_ENTRIES
, truncated
,
2753 bi_log_list_trim_cb
, &entries
);
2757 static int rgw_bi_log_trim(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2759 auto in_iter
= in
->cbegin();
2761 cls_rgw_bi_log_trim_op op
;
2763 decode(op
, in_iter
);
2764 } catch (buffer::error
& err
) {
2765 CLS_LOG(1, "ERROR: rgw_bi_log_list(): failed to decode entry\n");
2769 cls_rgw_bi_log_list_ret op_ret
;
2770 list
<rgw_bi_log_entry
> entries
;
2771 #define MAX_TRIM_ENTRIES 1000 /* don't do more than that in a single operation */
2773 int ret
= bi_log_list_trim_entries(hctx
, op
.start_marker
, op
.end_marker
, entries
, &truncated
);
2777 if (entries
.empty())
2780 list
<rgw_bi_log_entry
>::iterator iter
;
2781 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
2782 rgw_bi_log_entry
& entry
= *iter
;
2784 ret
= bi_log_remove_entry(hctx
, entry
);
2792 static int rgw_bi_log_resync(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2794 rgw_bucket_dir_header header
;
2795 int rc
= read_bucket_header(hctx
, &header
);
2797 CLS_LOG(1, "ERROR: rgw_bucket_complete_op(): failed to read header\n");
2803 rgw_bi_log_entry entry
;
2805 entry
.timestamp
= real_clock::now();
2806 entry
.op
= RGWModifyOp::CLS_RGW_OP_RESYNC
;
2807 entry
.state
= RGWPendingState::CLS_RGW_STATE_COMPLETE
;
2810 bi_log_index_key(hctx
, key
, entry
.id
, header
.ver
);
2814 if (entry
.id
> header
.max_marker
)
2815 header
.max_marker
= entry
.id
;
2817 header
.syncstopped
= false;
2819 rc
= cls_cxx_map_set_val(hctx
, key
, &bl
);
2823 return write_bucket_header(hctx
, &header
);
2826 static int rgw_bi_log_stop(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2828 rgw_bucket_dir_header header
;
2829 int rc
= read_bucket_header(hctx
, &header
);
2831 CLS_LOG(1, "ERROR: rgw_bucket_complete_op(): failed to read header\n");
2837 rgw_bi_log_entry entry
;
2839 entry
.timestamp
= real_clock::now();
2840 entry
.op
= RGWModifyOp::CLS_RGW_OP_SYNCSTOP
;
2841 entry
.state
= RGWPendingState::CLS_RGW_STATE_COMPLETE
;
2844 bi_log_index_key(hctx
, key
, entry
.id
, header
.ver
);
2848 if (entry
.id
> header
.max_marker
)
2849 header
.max_marker
= entry
.id
;
2850 header
.syncstopped
= true;
2852 rc
= cls_cxx_map_set_val(hctx
, key
, &bl
);
2856 return write_bucket_header(hctx
, &header
);
2860 static void usage_record_prefix_by_time(uint64_t epoch
, string
& key
)
2863 snprintf(buf
, sizeof(buf
), "%011llu", (long long unsigned)epoch
);
2867 static void usage_record_prefix_by_user(const string
& user
, uint64_t epoch
, string
& key
)
2869 char buf
[user
.size() + 32];
2870 snprintf(buf
, sizeof(buf
), "%s_%011llu_", user
.c_str(), (long long unsigned)epoch
);
2874 static void usage_record_name_by_time(uint64_t epoch
, const string
& user
, const string
& bucket
, string
& key
)
2876 char buf
[32 + user
.size() + bucket
.size()];
2877 snprintf(buf
, sizeof(buf
), "%011llu_%s_%s", (long long unsigned)epoch
, user
.c_str(), bucket
.c_str());
2881 static void usage_record_name_by_user(const string
& user
, uint64_t epoch
, const string
& bucket
, string
& key
)
2883 char buf
[32 + user
.size() + bucket
.size()];
2884 snprintf(buf
, sizeof(buf
), "%s_%011llu_%s", user
.c_str(), (long long unsigned)epoch
, bucket
.c_str());
2888 static int usage_record_decode(bufferlist
& record_bl
, rgw_usage_log_entry
& e
)
2890 auto kiter
= record_bl
.cbegin();
2893 } catch (buffer::error
& err
) {
2894 CLS_LOG(1, "ERROR: usage_record_decode(): failed to decode record_bl\n");
2901 int rgw_user_usage_log_add(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2903 CLS_LOG(10, "rgw_user_usage_log_add()");
2905 auto in_iter
= in
->cbegin();
2906 rgw_cls_usage_log_add_op op
;
2909 decode(op
, in_iter
);
2910 } catch (buffer::error
& err
) {
2911 CLS_LOG(1, "ERROR: rgw_user_usage_log_add(): failed to decode request\n");
2915 rgw_usage_log_info
& info
= op
.info
;
2916 vector
<rgw_usage_log_entry
>::iterator iter
;
2918 for (iter
= info
.entries
.begin(); iter
!= info
.entries
.end(); ++iter
) {
2919 rgw_usage_log_entry
& entry
= *iter
;
2922 rgw_user
*puser
= (entry
.payer
.empty() ? &entry
.owner
: &entry
.payer
);
2924 usage_record_name_by_time(entry
.epoch
, puser
->to_str(), entry
.bucket
, key_by_time
);
2926 CLS_LOG(10, "rgw_user_usage_log_add user=%s bucket=%s\n", puser
->to_str().c_str(), entry
.bucket
.c_str());
2928 bufferlist record_bl
;
2929 int ret
= cls_cxx_map_get_val(hctx
, key_by_time
, &record_bl
);
2930 if (ret
< 0 && ret
!= -ENOENT
) {
2931 CLS_LOG(1, "ERROR: rgw_user_usage_log_add(): cls_cxx_map_read_key returned %d\n", ret
);
2935 rgw_usage_log_entry e
;
2936 ret
= usage_record_decode(record_bl
, e
);
2939 CLS_LOG(10, "rgw_user_usage_log_add aggregating existing bucket\n");
2943 bufferlist new_record_bl
;
2944 encode(entry
, new_record_bl
);
2945 ret
= cls_cxx_map_set_val(hctx
, key_by_time
, &new_record_bl
);
2950 usage_record_name_by_user(puser
->to_str(), entry
.epoch
, entry
.bucket
, key_by_user
);
2951 ret
= cls_cxx_map_set_val(hctx
, key_by_user
, &new_record_bl
);
2959 static int usage_iterate_range(cls_method_context_t hctx
, uint64_t start
, uint64_t end
, const string
& user
,
2960 const string
& bucket
, string
& key_iter
, uint32_t max_entries
, bool *truncated
,
2961 int (*cb
)(cls_method_context_t
, const string
&, rgw_usage_log_entry
&, void *),
2964 CLS_LOG(10, "usage_iterate_range");
2966 map
<string
, bufferlist
> keys
;
2968 string filter_prefix
;
2969 string start_key
, end_key
;
2970 bool by_user
= !user
.empty();
2973 bool truncated_status
= false;
2975 ceph_assert(truncated
!= nullptr);
2978 usage_record_prefix_by_time(end
, end_key
);
2981 user_key
.append("_");
2984 if (key_iter
.empty()) {
2986 usage_record_prefix_by_user(user
, start
, start_key
);
2988 usage_record_prefix_by_time(start
, start_key
);
2991 start_key
= key_iter
;
2994 CLS_LOG(20, "usage_iterate_range start_key=%s", start_key
.c_str());
2995 int ret
= cls_cxx_map_get_vals(hctx
, start_key
, filter_prefix
, max_entries
, &keys
, &truncated_status
);
2999 *truncated
= truncated_status
;
3001 map
<string
, bufferlist
>::iterator iter
= keys
.begin();
3002 if (iter
== keys
.end())
3005 uint32_t num_keys
= keys
.size();
3007 for (; iter
!= keys
.end(); ++iter
,++i
) {
3008 const string
& key
= iter
->first
;
3009 rgw_usage_log_entry e
;
3011 if (!by_user
&& key
.compare(end_key
) >= 0) {
3012 CLS_LOG(20, "usage_iterate_range reached key=%s, done", key
.c_str());
3018 if (by_user
&& key
.compare(0, user_key
.size(), user_key
) != 0) {
3019 CLS_LOG(20, "usage_iterate_range reached key=%s, done", key
.c_str());
3025 ret
= usage_record_decode(iter
->second
, e
);
3029 if (!bucket
.empty() && bucket
.compare(e
.bucket
))
3032 if (e
.epoch
< start
)
3035 /* keys are sorted by epoch, so once we're past end we're done */
3036 if (e
.epoch
>= end
) {
3041 ret
= cb(hctx
, key
, e
, param
);
3046 if (i
== num_keys
- 1) {
3054 static int usage_log_read_cb(cls_method_context_t hctx
, const string
& key
, rgw_usage_log_entry
& entry
, void *param
)
3056 map
<rgw_user_bucket
, rgw_usage_log_entry
> *usage
= (map
<rgw_user_bucket
, rgw_usage_log_entry
> *)param
;
3058 if (!entry
.payer
.empty()) {
3059 puser
= &entry
.payer
;
3061 puser
= &entry
.owner
;
3063 rgw_user_bucket
ub(puser
->to_str(), entry
.bucket
);
3064 rgw_usage_log_entry
& le
= (*usage
)[ub
];
3065 le
.aggregate(entry
);
3070 int rgw_user_usage_log_read(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3072 CLS_LOG(10, "rgw_user_usage_log_read()");
3074 auto in_iter
= in
->cbegin();
3075 rgw_cls_usage_log_read_op op
;
3078 decode(op
, in_iter
);
3079 } catch (buffer::error
& err
) {
3080 CLS_LOG(1, "ERROR: rgw_user_usage_log_read(): failed to decode request\n");
3084 rgw_cls_usage_log_read_ret ret_info
;
3085 map
<rgw_user_bucket
, rgw_usage_log_entry
> *usage
= &ret_info
.usage
;
3086 string iter
= op
.iter
;
3087 #define MAX_ENTRIES 1000
3088 uint32_t max_entries
= (op
.max_entries
? op
.max_entries
: MAX_ENTRIES
);
3089 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
);
3093 if (ret_info
.truncated
)
3094 ret_info
.next_iter
= iter
;
3096 encode(ret_info
, *out
);
3100 static int usage_log_trim_cb(cls_method_context_t hctx
, const string
& key
, rgw_usage_log_entry
& entry
, void *param
)
3102 bool *found
= (bool *)param
;
3109 string o
= entry
.owner
.to_str();
3110 usage_record_name_by_time(entry
.epoch
, o
, entry
.bucket
, key_by_time
);
3111 usage_record_name_by_user(o
, entry
.epoch
, entry
.bucket
, key_by_user
);
3113 int ret
= cls_cxx_map_remove_key(hctx
, key_by_time
);
3117 return cls_cxx_map_remove_key(hctx
, key_by_user
);
3120 int rgw_user_usage_log_trim(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3122 CLS_LOG(10, "rgw_user_usage_log_trim()");
3124 /* only continue if object exists! */
3125 int ret
= cls_cxx_stat(hctx
, NULL
, NULL
);
3129 auto in_iter
= in
->cbegin();
3130 rgw_cls_usage_log_trim_op op
;
3133 decode(op
, in_iter
);
3134 } catch (buffer::error
& err
) {
3135 CLS_LOG(1, "ERROR: rgw_user_log_usage_log_trim(): failed to decode request\n");
3142 #define MAX_USAGE_TRIM_ENTRIES 128
3143 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
);
3147 if (!more
&& !found
)
3153 int rgw_usage_log_clear(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3155 CLS_LOG(10,"%s", __func__
);
3157 int ret
= cls_cxx_map_clear(hctx
);
3158 /* if object doesn't exist all the logs are cleared anyway */
3165 * We hold the garbage collection chain data under two different indexes: the first 'name' index
3166 * keeps them under a unique tag that represents the chains, and a second 'time' index keeps
3167 * them by their expiration timestamp
3169 #define GC_OBJ_NAME_INDEX 0
3170 #define GC_OBJ_TIME_INDEX 1
3172 static string gc_index_prefixes
[] = { "0_",
3175 static void prepend_index_prefix(const string
& src
, int index
, string
*dest
)
3177 *dest
= gc_index_prefixes
[index
];
3181 static int gc_omap_get(cls_method_context_t hctx
, int type
, const string
& key
, cls_rgw_gc_obj_info
*info
)
3184 prepend_index_prefix(key
, type
, &index
);
3186 int ret
= read_omap_entry(hctx
, index
, info
);
3193 static int gc_omap_set(cls_method_context_t hctx
, int type
, const string
& key
, const cls_rgw_gc_obj_info
*info
)
3198 string index
= gc_index_prefixes
[type
];
3201 int ret
= cls_cxx_map_set_val(hctx
, index
, &bl
);
3208 static int gc_omap_remove(cls_method_context_t hctx
, int type
, const string
& key
)
3210 string index
= gc_index_prefixes
[type
];
3213 int ret
= cls_cxx_map_remove_key(hctx
, index
);
3220 static bool key_in_index(const string
& key
, int index_type
)
3222 const string
& prefix
= gc_index_prefixes
[index_type
];
3223 return (key
.compare(0, prefix
.size(), prefix
) == 0);
3227 static int gc_update_entry(cls_method_context_t hctx
, uint32_t expiration_secs
,
3228 cls_rgw_gc_obj_info
& info
)
3230 cls_rgw_gc_obj_info old_info
;
3231 int ret
= gc_omap_get(hctx
, GC_OBJ_NAME_INDEX
, info
.tag
, &old_info
);
3234 get_time_key(old_info
.time
, &key
);
3235 ret
= gc_omap_remove(hctx
, GC_OBJ_TIME_INDEX
, key
);
3236 if (ret
< 0 && ret
!= -ENOENT
) {
3237 CLS_LOG(0, "ERROR: failed to remove key=%s\n", key
.c_str());
3242 // calculate time and time key
3243 info
.time
= ceph::real_clock::now();
3244 info
.time
+= make_timespan(expiration_secs
);
3246 get_time_key(info
.time
, &time_key
);
3248 if (info
.chain
.objs
.empty()) {
3250 "WARNING: %s setting GC log entry with zero-length chain, "
3251 "tag='%s', timekey='%s'",
3252 __func__
, info
.tag
.c_str(), time_key
.c_str());
3255 ret
= gc_omap_set(hctx
, GC_OBJ_NAME_INDEX
, info
.tag
, &info
);
3259 ret
= gc_omap_set(hctx
, GC_OBJ_TIME_INDEX
, time_key
, &info
);
3267 CLS_LOG(0, "ERROR: gc_set_entry error info.tag=%s, ret=%d\n",
3268 info
.tag
.c_str(), ret
);
3269 gc_omap_remove(hctx
, GC_OBJ_NAME_INDEX
, info
.tag
);
3274 static int gc_defer_entry(cls_method_context_t hctx
, const string
& tag
, uint32_t expiration_secs
)
3276 cls_rgw_gc_obj_info info
;
3277 int ret
= gc_omap_get(hctx
, GC_OBJ_NAME_INDEX
, tag
, &info
);
3282 return gc_update_entry(hctx
, expiration_secs
, info
);
3285 int gc_record_decode(bufferlist
& bl
, cls_rgw_gc_obj_info
& e
)
3287 auto iter
= bl
.cbegin();
3290 } catch (buffer::error
& err
) {
3291 CLS_LOG(0, "ERROR: failed to decode cls_rgw_gc_obj_info");
3297 static int rgw_cls_gc_set_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3299 auto in_iter
= in
->cbegin();
3301 cls_rgw_gc_set_entry_op op
;
3303 decode(op
, in_iter
);
3304 } catch (buffer::error
& err
) {
3305 CLS_LOG(1, "ERROR: rgw_cls_gc_set_entry(): failed to decode entry\n");
3309 return gc_update_entry(hctx
, op
.expiration_secs
, op
.info
);
3312 static int rgw_cls_gc_defer_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3314 auto in_iter
= in
->cbegin();
3316 cls_rgw_gc_defer_entry_op op
;
3318 decode(op
, in_iter
);
3319 } catch (buffer::error
& err
) {
3320 CLS_LOG(1, "ERROR: rgw_cls_gc_defer_entry(): failed to decode entry\n");
3324 return gc_defer_entry(hctx
, op
.tag
, op
.expiration_secs
);
3327 static int gc_iterate_entries(cls_method_context_t hctx
,
3328 const string
& marker
,
3331 uint32_t max_entries
,
3333 int (*cb
)(cls_method_context_t
,
3335 cls_rgw_gc_obj_info
&,
3339 CLS_LOG(10, "gc_iterate_entries");
3341 map
<string
, bufferlist
> keys
;
3342 string filter_prefix
, end_key
;
3349 if (marker
.empty()) {
3350 prepend_index_prefix(marker
, GC_OBJ_TIME_INDEX
, &start_key
);
3356 real_time now
= ceph::real_clock::now();
3358 get_time_key(now
, &now_str
);
3359 prepend_index_prefix(now_str
, GC_OBJ_TIME_INDEX
, &end_key
);
3361 CLS_LOG(10, "gc_iterate_entries end_key=%s\n", end_key
.c_str());
3366 int ret
= cls_cxx_map_get_vals(hctx
, start_key
, filter
, max_entries
,
3371 map
<string
, bufferlist
>::iterator iter
= keys
.begin();
3372 if (iter
== keys
.end()) {
3373 // if keys empty must not come back as truncated
3374 ceph_assert(!truncated
|| !(*truncated
));
3378 const string
* last_key
= nullptr; // last key processed, for end-marker
3379 for (; iter
!= keys
.end(); ++iter
) {
3380 const string
& key
= iter
->first
;
3381 cls_rgw_gc_obj_info e
;
3383 CLS_LOG(10, "gc_iterate_entries key=%s\n", key
.c_str());
3385 if (!end_key
.empty() && key
.compare(end_key
) >= 0) {
3391 if (!key_in_index(key
, GC_OBJ_TIME_INDEX
)) {
3397 ret
= gc_record_decode(iter
->second
, e
);
3401 ret
= cb(hctx
, key
, e
, param
);
3404 last_key
= &(iter
->first
); // update when callback successful
3407 // set the out marker if either caller does not capture truncated or
3408 // if they do capture and we are truncated
3409 if (!truncated
|| *truncated
) {
3411 out_marker
= *last_key
;
3417 static int gc_list_cb(cls_method_context_t hctx
, const string
& key
, cls_rgw_gc_obj_info
& info
, void *param
)
3419 list
<cls_rgw_gc_obj_info
> *l
= (list
<cls_rgw_gc_obj_info
> *)param
;
3424 static int gc_list_entries(cls_method_context_t hctx
, const string
& marker
,
3425 uint32_t max
, bool expired_only
,
3426 list
<cls_rgw_gc_obj_info
>& entries
, bool *truncated
, string
& next_marker
)
3428 int ret
= gc_iterate_entries(hctx
, marker
, expired_only
,
3429 next_marker
, max
, truncated
,
3430 gc_list_cb
, &entries
);
3434 static int rgw_cls_gc_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3436 auto in_iter
= in
->cbegin();
3438 cls_rgw_gc_list_op op
;
3440 decode(op
, in_iter
);
3441 } catch (buffer::error
& err
) {
3442 CLS_LOG(1, "ERROR: rgw_cls_gc_list(): failed to decode entry\n");
3446 cls_rgw_gc_list_ret op_ret
;
3447 #define GC_LIST_ENTRIES_DEFAULT 128
3448 int ret
= gc_list_entries(hctx
, op
.marker
, (op
.max
? op
.max
: GC_LIST_ENTRIES_DEFAULT
), op
.expired_only
,
3449 op_ret
.entries
, &op_ret
.truncated
, op_ret
.next_marker
);
3453 encode(op_ret
, *out
);
3458 static int gc_remove(cls_method_context_t hctx
, vector
<string
>& tags
)
3460 for (auto iter
= tags
.begin(); iter
!= tags
.end(); ++iter
) {
3461 string
& tag
= *iter
;
3462 cls_rgw_gc_obj_info info
;
3463 int ret
= gc_omap_get(hctx
, GC_OBJ_NAME_INDEX
, tag
, &info
);
3464 if (ret
== -ENOENT
) {
3465 CLS_LOG(0, "couldn't find tag in name index tag=%s\n", tag
.c_str());
3473 get_time_key(info
.time
, &time_key
);
3474 ret
= gc_omap_remove(hctx
, GC_OBJ_TIME_INDEX
, time_key
);
3475 if (ret
< 0 && ret
!= -ENOENT
)
3477 if (ret
== -ENOENT
) {
3478 CLS_LOG(0, "couldn't find key in time index key=%s\n", time_key
.c_str());
3481 ret
= gc_omap_remove(hctx
, GC_OBJ_NAME_INDEX
, tag
);
3482 if (ret
< 0 && ret
!= -ENOENT
)
3489 static int rgw_cls_gc_remove(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3491 auto in_iter
= in
->cbegin();
3493 cls_rgw_gc_remove_op op
;
3495 decode(op
, in_iter
);
3496 } catch (buffer::error
& err
) {
3497 CLS_LOG(1, "ERROR: rgw_cls_gc_remove(): failed to decode entry\n");
3501 return gc_remove(hctx
, op
.tags
);
3504 static int rgw_cls_lc_get_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3506 auto in_iter
= in
->cbegin();
3508 cls_rgw_lc_get_entry_op op
;
3510 decode(op
, in_iter
);
3511 } catch (buffer::error
& err
) {
3512 CLS_LOG(1, "ERROR: rgw_cls_lc_set_entry(): failed to decode entry\n");
3516 rgw_lc_entry_t lc_entry
;
3517 int ret
= read_omap_entry(hctx
, op
.marker
, &lc_entry
);
3521 cls_rgw_lc_get_entry_ret
op_ret(std::move(lc_entry
));
3522 encode(op_ret
, *out
);
3527 static int rgw_cls_lc_set_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3529 auto in_iter
= in
->cbegin();
3531 cls_rgw_lc_set_entry_op op
;
3533 decode(op
, in_iter
);
3534 } catch (buffer::error
& err
) {
3535 CLS_LOG(1, "ERROR: rgw_cls_lc_set_entry(): failed to decode entry\n");
3540 encode(op
.entry
, bl
);
3542 int ret
= cls_cxx_map_set_val(hctx
, op
.entry
.first
, &bl
);
3546 static int rgw_cls_lc_rm_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3548 auto in_iter
= in
->cbegin();
3550 cls_rgw_lc_rm_entry_op op
;
3552 decode(op
, in_iter
);
3553 } catch (buffer::error
& err
) {
3554 CLS_LOG(1, "ERROR: rgw_cls_lc_rm_entry(): failed to decode entry\n");
3558 int ret
= cls_cxx_map_remove_key(hctx
, op
.entry
.first
);
3562 static int rgw_cls_lc_get_next_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3564 auto in_iter
= in
->cbegin();
3565 cls_rgw_lc_get_next_entry_ret op_ret
;
3566 cls_rgw_lc_get_next_entry_op op
;
3568 decode(op
, in_iter
);
3569 } catch (buffer::error
& err
) {
3570 CLS_LOG(1, "ERROR: rgw_cls_lc_get_next_entry: failed to decode op\n");
3574 map
<string
, bufferlist
> vals
;
3575 string filter_prefix
;
3577 int ret
= cls_cxx_map_get_vals(hctx
, op
.marker
, filter_prefix
, 1, &vals
, &more
);
3580 map
<string
, bufferlist
>::iterator it
;
3581 pair
<string
, int> entry
;
3582 if (!vals
.empty()) {
3584 in_iter
= it
->second
.begin();
3586 decode(entry
, in_iter
);
3587 } catch (buffer::error
& err
) {
3588 CLS_LOG(1, "ERROR: rgw_cls_lc_get_next_entry(): failed to decode entry\n");
3592 op_ret
.entry
= entry
;
3593 encode(op_ret
, *out
);
3597 static int rgw_cls_lc_list_entries(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3599 cls_rgw_lc_list_entries_op op
;
3600 auto in_iter
= in
->cbegin();
3602 decode(op
, in_iter
);
3603 } catch (buffer::error
& err
) {
3604 CLS_LOG(1, "ERROR: rgw_cls_lc_list_entries(): failed to decode op\n");
3608 cls_rgw_lc_list_entries_ret op_ret
;
3609 bufferlist::const_iterator iter
;
3610 map
<string
, bufferlist
> vals
;
3611 string filter_prefix
;
3612 int ret
= cls_cxx_map_get_vals(hctx
, op
.marker
, filter_prefix
, op
.max_entries
, &vals
, &op_ret
.is_truncated
);
3615 map
<string
, bufferlist
>::iterator it
;
3616 pair
<string
, int> entry
;
3617 for (it
= vals
.begin(); it
!= vals
.end(); ++it
) {
3618 iter
= it
->second
.cbegin();
3620 decode(entry
, iter
);
3621 } catch (buffer::error
& err
) {
3622 CLS_LOG(1, "ERROR: rgw_cls_lc_list_entries(): failed to decode entry\n");
3625 op_ret
.entries
.insert(entry
);
3627 encode(op_ret
, *out
);
3631 static int rgw_cls_lc_put_head(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3633 auto in_iter
= in
->cbegin();
3635 cls_rgw_lc_put_head_op op
;
3637 decode(op
, in_iter
);
3638 } catch (buffer::error
& err
) {
3639 CLS_LOG(1, "ERROR: rgw_cls_lc_put_head(): failed to decode entry\n");
3644 encode(op
.head
, bl
);
3645 int ret
= cls_cxx_map_write_header(hctx
,&bl
);
3649 static int rgw_cls_lc_get_head(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3652 int ret
= cls_cxx_map_read_header(hctx
, &bl
);
3655 cls_rgw_lc_obj_head head
;
3656 if (bl
.length() != 0) {
3657 auto iter
= bl
.cbegin();
3660 } catch (buffer::error
& err
) {
3661 CLS_LOG(0, "ERROR: rgw_cls_lc_get_head(): failed to decode entry %s\n",err
.what());
3665 head
.start_date
= 0;
3666 head
.marker
.clear();
3668 cls_rgw_lc_get_head_ret op_ret
;
3670 encode(op_ret
, *out
);
3674 static int rgw_reshard_add(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3676 auto in_iter
= in
->cbegin();
3678 cls_rgw_reshard_add_op op
;
3680 decode(op
, in_iter
);
3681 } catch (buffer::error
& err
) {
3682 CLS_LOG(1, "ERROR: rgw_reshard_add: failed to decode entry\n");
3688 op
.entry
.get_key(&key
);
3691 encode(op
.entry
, bl
);
3692 int ret
= cls_cxx_map_set_val(hctx
, key
, &bl
);
3694 CLS_ERR("error adding reshard job for bucket %s with key %s",op
.entry
.bucket_name
.c_str(), key
.c_str());
3701 static int rgw_reshard_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3703 cls_rgw_reshard_list_op op
;
3704 auto in_iter
= in
->cbegin();
3706 decode(op
, in_iter
);
3707 } catch (buffer::error
& err
) {
3708 CLS_LOG(1, "ERROR: rgw_cls_rehard_list(): failed to decode entry\n");
3711 cls_rgw_reshard_list_ret op_ret
;
3712 bufferlist::const_iterator iter
;
3713 map
<string
, bufferlist
> vals
;
3714 string filter_prefix
;
3715 #define MAX_RESHARD_LIST_ENTRIES 1000
3716 /* one extra entry for identifying truncation */
3717 int32_t max
= (op
.max
&& (op
.max
< MAX_RESHARD_LIST_ENTRIES
) ? op
.max
: MAX_RESHARD_LIST_ENTRIES
);
3718 int ret
= cls_cxx_map_get_vals(hctx
, op
.marker
, filter_prefix
, max
, &vals
, &op_ret
.is_truncated
);
3721 map
<string
, bufferlist
>::iterator it
;
3722 cls_rgw_reshard_entry entry
;
3724 for (it
= vals
.begin(); i
< (int)op
.max
&& it
!= vals
.end(); ++it
, ++i
) {
3725 iter
= it
->second
.cbegin();
3727 decode(entry
, iter
);
3728 } catch (buffer::error
& err
) {
3729 CLS_LOG(1, "ERROR: rgw_cls_rehard_list(): failed to decode entry\n");
3732 op_ret
.entries
.push_back(entry
);
3734 encode(op_ret
, *out
);
3738 static int rgw_reshard_get(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3740 auto in_iter
= in
->cbegin();
3742 cls_rgw_reshard_get_op op
;
3744 decode(op
, in_iter
);
3745 } catch (buffer::error
& err
) {
3746 CLS_LOG(1, "ERROR: rgw_reshard_get: failed to decode entry\n");
3751 cls_rgw_reshard_entry entry
;
3752 op
.entry
.get_key(&key
);
3753 int ret
= read_omap_entry(hctx
, key
, &entry
);
3758 cls_rgw_reshard_get_ret op_ret
;
3759 op_ret
.entry
= entry
;
3760 encode(op_ret
, *out
);
3764 static int rgw_reshard_remove(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3766 auto in_iter
= in
->cbegin();
3768 cls_rgw_reshard_remove_op op
;
3770 decode(op
, in_iter
);
3771 } catch (buffer::error
& err
) {
3772 CLS_LOG(1, "ERROR: rgw_cls_rehard_remove: failed to decode entry\n");
3777 cls_rgw_reshard_entry entry
;
3778 cls_rgw_reshard_entry::generate_key(op
.tenant
, op
.bucket_name
, &key
);
3779 int ret
= read_omap_entry(hctx
, key
, &entry
);
3784 if (!op
.bucket_id
.empty() &&
3785 entry
.bucket_id
!= op
.bucket_id
) {
3789 ret
= cls_cxx_map_remove_key(hctx
, key
);
3791 CLS_LOG(0, "ERROR: failed to remove key: key=%s ret=%d", key
.c_str(), ret
);
3797 static int rgw_set_bucket_resharding(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3799 cls_rgw_set_bucket_resharding_op op
;
3801 auto in_iter
= in
->cbegin();
3803 decode(op
, in_iter
);
3804 } catch (buffer::error
& err
) {
3805 CLS_LOG(1, "ERROR: cls_rgw_set_bucket_resharding: failed to decode entry\n");
3809 rgw_bucket_dir_header header
;
3810 int rc
= read_bucket_header(hctx
, &header
);
3812 CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__
);
3816 header
.new_instance
.set_status(op
.entry
.new_bucket_instance_id
, op
.entry
.num_shards
, op
.entry
.reshard_status
);
3818 return write_bucket_header(hctx
, &header
);
3821 static int rgw_clear_bucket_resharding(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3823 cls_rgw_clear_bucket_resharding_op op
;
3825 auto in_iter
= in
->cbegin();
3827 decode(op
, in_iter
);
3828 } catch (buffer::error
& err
) {
3829 CLS_LOG(1, "ERROR: cls_rgw_clear_bucket_resharding: failed to decode entry\n");
3833 rgw_bucket_dir_header header
;
3834 int rc
= read_bucket_header(hctx
, &header
);
3836 CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__
);
3839 header
.new_instance
.clear();
3841 return write_bucket_header(hctx
, &header
);
3844 static int rgw_guard_bucket_resharding(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3846 cls_rgw_guard_bucket_resharding_op op
;
3848 auto in_iter
= in
->cbegin();
3850 decode(op
, in_iter
);
3851 } catch (buffer::error
& err
) {
3852 CLS_LOG(1, "ERROR: cls_rgw_clear_bucket_resharding: failed to decode entry\n");
3856 rgw_bucket_dir_header header
;
3857 int rc
= read_bucket_header(hctx
, &header
);
3859 CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__
);
3863 if (header
.resharding()) {
3870 static int rgw_get_bucket_resharding(cls_method_context_t hctx
,
3871 bufferlist
*in
, bufferlist
*out
)
3873 cls_rgw_get_bucket_resharding_op op
;
3875 auto in_iter
= in
->cbegin();
3877 decode(op
, in_iter
);
3878 } catch (buffer::error
& err
) {
3879 CLS_LOG(1, "ERROR: cls_rgw_clear_bucket_resharding: failed to decode entry\n");
3883 rgw_bucket_dir_header header
;
3884 int rc
= read_bucket_header(hctx
, &header
);
3886 CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__
);
3890 cls_rgw_get_bucket_resharding_ret op_ret
;
3891 op_ret
.new_instance
= header
.new_instance
;
3893 encode(op_ret
, *out
);
3900 CLS_LOG(1, "Loaded rgw class!");
3902 cls_handle_t h_class
;
3903 cls_method_handle_t h_rgw_bucket_init_index
;
3904 cls_method_handle_t h_rgw_bucket_set_tag_timeout
;
3905 cls_method_handle_t h_rgw_bucket_list
;
3906 cls_method_handle_t h_rgw_bucket_check_index
;
3907 cls_method_handle_t h_rgw_bucket_rebuild_index
;
3908 cls_method_handle_t h_rgw_bucket_update_stats
;
3909 cls_method_handle_t h_rgw_bucket_prepare_op
;
3910 cls_method_handle_t h_rgw_bucket_complete_op
;
3911 cls_method_handle_t h_rgw_bucket_link_olh
;
3912 cls_method_handle_t h_rgw_bucket_unlink_instance_op
;
3913 cls_method_handle_t h_rgw_bucket_read_olh_log
;
3914 cls_method_handle_t h_rgw_bucket_trim_olh_log
;
3915 cls_method_handle_t h_rgw_bucket_clear_olh
;
3916 cls_method_handle_t h_rgw_obj_remove
;
3917 cls_method_handle_t h_rgw_obj_store_pg_ver
;
3918 cls_method_handle_t h_rgw_obj_check_attrs_prefix
;
3919 cls_method_handle_t h_rgw_obj_check_mtime
;
3920 cls_method_handle_t h_rgw_bi_get_op
;
3921 cls_method_handle_t h_rgw_bi_put_op
;
3922 cls_method_handle_t h_rgw_bi_list_op
;
3923 cls_method_handle_t h_rgw_bi_log_list_op
;
3924 cls_method_handle_t h_rgw_bi_log_resync_op
;
3925 cls_method_handle_t h_rgw_bi_log_stop_op
;
3926 cls_method_handle_t h_rgw_dir_suggest_changes
;
3927 cls_method_handle_t h_rgw_user_usage_log_add
;
3928 cls_method_handle_t h_rgw_user_usage_log_read
;
3929 cls_method_handle_t h_rgw_user_usage_log_trim
;
3930 cls_method_handle_t h_rgw_usage_log_clear
;
3931 cls_method_handle_t h_rgw_gc_set_entry
;
3932 cls_method_handle_t h_rgw_gc_list
;
3933 cls_method_handle_t h_rgw_gc_remove
;
3934 cls_method_handle_t h_rgw_lc_get_entry
;
3935 cls_method_handle_t h_rgw_lc_set_entry
;
3936 cls_method_handle_t h_rgw_lc_rm_entry
;
3937 cls_method_handle_t h_rgw_lc_get_next_entry
;
3938 cls_method_handle_t h_rgw_lc_put_head
;
3939 cls_method_handle_t h_rgw_lc_get_head
;
3940 cls_method_handle_t h_rgw_lc_list_entries
;
3941 cls_method_handle_t h_rgw_reshard_add
;
3942 cls_method_handle_t h_rgw_reshard_list
;
3943 cls_method_handle_t h_rgw_reshard_get
;
3944 cls_method_handle_t h_rgw_reshard_remove
;
3945 cls_method_handle_t h_rgw_set_bucket_resharding
;
3946 cls_method_handle_t h_rgw_clear_bucket_resharding
;
3947 cls_method_handle_t h_rgw_guard_bucket_resharding
;
3948 cls_method_handle_t h_rgw_get_bucket_resharding
;
3951 cls_register(RGW_CLASS
, &h_class
);
3954 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
);
3955 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
);
3956 cls_register_cxx_method(h_class
, RGW_BUCKET_LIST
, CLS_METHOD_RD
, rgw_bucket_list
, &h_rgw_bucket_list
);
3957 cls_register_cxx_method(h_class
, RGW_BUCKET_CHECK_INDEX
, CLS_METHOD_RD
, rgw_bucket_check_index
, &h_rgw_bucket_check_index
);
3958 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
);
3959 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
);
3960 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
);
3961 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
);
3962 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
);
3963 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
);
3964 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
);
3965 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
);
3966 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
);
3968 cls_register_cxx_method(h_class
, RGW_OBJ_REMOVE
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_obj_remove
, &h_rgw_obj_remove
);
3969 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
);
3970 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
);
3971 cls_register_cxx_method(h_class
, RGW_OBJ_CHECK_MTIME
, CLS_METHOD_RD
, rgw_obj_check_mtime
, &h_rgw_obj_check_mtime
);
3973 cls_register_cxx_method(h_class
, RGW_BI_GET
, CLS_METHOD_RD
, rgw_bi_get_op
, &h_rgw_bi_get_op
);
3974 cls_register_cxx_method(h_class
, RGW_BI_PUT
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bi_put_op
, &h_rgw_bi_put_op
);
3975 cls_register_cxx_method(h_class
, RGW_BI_LIST
, CLS_METHOD_RD
, rgw_bi_list_op
, &h_rgw_bi_list_op
);
3977 cls_register_cxx_method(h_class
, RGW_BI_LOG_LIST
, CLS_METHOD_RD
, rgw_bi_log_list
, &h_rgw_bi_log_list_op
);
3978 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
);
3979 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
);
3981 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
);
3982 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
);
3985 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
);
3986 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
);
3987 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
);
3988 cls_register_cxx_method(h_class
, RGW_USAGE_LOG_CLEAR
, CLS_METHOD_WR
, rgw_usage_log_clear
, &h_rgw_usage_log_clear
);
3990 /* garbage collection */
3991 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
);
3992 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
);
3993 cls_register_cxx_method(h_class
, RGW_GC_LIST
, CLS_METHOD_RD
, rgw_cls_gc_list
, &h_rgw_gc_list
);
3994 cls_register_cxx_method(h_class
, RGW_GC_REMOVE
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_cls_gc_remove
, &h_rgw_gc_remove
);
3996 /* lifecycle bucket list */
3997 cls_register_cxx_method(h_class
, RGW_LC_GET_ENTRY
, CLS_METHOD_RD
, rgw_cls_lc_get_entry
, &h_rgw_lc_get_entry
);
3998 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
);
3999 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
);
4000 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
);
4001 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
);
4002 cls_register_cxx_method(h_class
, RGW_LC_GET_HEAD
, CLS_METHOD_RD
, rgw_cls_lc_get_head
, &h_rgw_lc_get_head
);
4003 cls_register_cxx_method(h_class
, RGW_LC_LIST_ENTRIES
, CLS_METHOD_RD
, rgw_cls_lc_list_entries
, &h_rgw_lc_list_entries
);
4006 cls_register_cxx_method(h_class
, RGW_RESHARD_ADD
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_reshard_add
, &h_rgw_reshard_add
);
4007 cls_register_cxx_method(h_class
, RGW_RESHARD_LIST
, CLS_METHOD_RD
, rgw_reshard_list
, &h_rgw_reshard_list
);
4008 cls_register_cxx_method(h_class
, RGW_RESHARD_GET
, CLS_METHOD_RD
,rgw_reshard_get
, &h_rgw_reshard_get
);
4009 cls_register_cxx_method(h_class
, RGW_RESHARD_REMOVE
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_reshard_remove
, &h_rgw_reshard_remove
);
4011 /* resharding attribute */
4012 cls_register_cxx_method(h_class
, RGW_SET_BUCKET_RESHARDING
, CLS_METHOD_RD
| CLS_METHOD_WR
,
4013 rgw_set_bucket_resharding
, &h_rgw_set_bucket_resharding
);
4014 cls_register_cxx_method(h_class
, RGW_CLEAR_BUCKET_RESHARDING
, CLS_METHOD_RD
| CLS_METHOD_WR
,
4015 rgw_clear_bucket_resharding
, &h_rgw_clear_bucket_resharding
);
4016 cls_register_cxx_method(h_class
, RGW_GUARD_BUCKET_RESHARDING
, CLS_METHOD_RD
,
4017 rgw_guard_bucket_resharding
, &h_rgw_guard_bucket_resharding
);
4018 cls_register_cxx_method(h_class
, RGW_GET_BUCKET_RESHARDING
, CLS_METHOD_RD
,
4019 rgw_get_bucket_resharding
, &h_rgw_get_bucket_resharding
);