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 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 struct 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
)
150 int ret
= cls_cxx_map_get_vals(hctx
, start
, filter_prefix
, num_entries
, pkeys
);
157 map
<string
, bufferlist
>::reverse_iterator last_element
= pkeys
->rbegin();
158 if ((unsigned char)last_element
->first
[0] < BI_PREFIX_CHAR
) {
159 /* nothing to see here, move along */
163 map
<string
, bufferlist
>::iterator 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 map
<string
, bufferlist
> old_keys
;
170 old_keys
.swap(*pkeys
);
172 for (map
<string
, bufferlist
>::iterator iter
= old_keys
.begin(); iter
!= old_keys
.end(); ++iter
) {
173 if ((unsigned char)iter
->first
[0] != BI_PREFIX_CHAR
) {
174 (*pkeys
)[iter
->first
] = iter
->second
;
178 if (num_entries
== (int)pkeys
->size())
181 map
<string
, bufferlist
> new_keys
;
182 char c
[] = { (char)(BI_PREFIX_CHAR
+ 1), 0 };
183 string new_start
= c
;
185 /* now get some more keys */
186 ret
= cls_cxx_map_get_vals(hctx
, new_start
, filter_prefix
, num_entries
- pkeys
->size(), &new_keys
);
190 for (map
<string
, bufferlist
>::iterator iter
= new_keys
.begin(); iter
!= new_keys
.end(); ++iter
) {
191 (*pkeys
)[iter
->first
] = iter
->second
;
198 * get a monotonically decreasing string representation.
199 * For num = x, num = y, where x > y, str(x) < str(y)
200 * Another property is that string size starts short and grows as num increases
202 static void decreasing_str(uint64_t num
, string
*str
)
205 if (num
< 0x10) { /* 16 */
206 snprintf(buf
, sizeof(buf
), "9%02lld", 15 - (long long)num
);
207 } else if (num
< 0x100) { /* 256 */
208 snprintf(buf
, sizeof(buf
), "8%03lld", 255 - (long long)num
);
209 } else if (num
< 0x1000) /* 4096 */ {
210 snprintf(buf
, sizeof(buf
), "7%04lld", 4095 - (long long)num
);
211 } else if (num
< 0x10000) /* 65536 */ {
212 snprintf(buf
, sizeof(buf
), "6%05lld", 65535 - (long long)num
);
213 } else if (num
< 0x100000000) /* 4G */ {
214 snprintf(buf
, sizeof(buf
), "5%010lld", 0xFFFFFFFF - (long long)num
);
216 snprintf(buf
, sizeof(buf
), "4%020lld", (long long)-num
);
223 * we now hold two different indexes for objects. The first one holds the list of objects in the
224 * order that we want them to be listed. The second one only holds the objects instances (for
225 * versioned objects), and they're not arranged in any particular order.
226 * When listing objects we'll use the first index, when doing operations on the objects themselves
227 * we'll use the second index. Note that regular objects only map to the first index anyway
230 static void get_list_index_key(struct rgw_bucket_dir_entry
& entry
, string
*index_key
)
232 *index_key
= entry
.key
.name
;
235 decreasing_str(entry
.versioned_epoch
, &ver_str
);
236 string
instance_delim("\0i", 2);
237 string
ver_delim("\0v", 2);
239 index_key
->append(ver_delim
);
240 index_key
->append(ver_str
);
241 index_key
->append(instance_delim
);
242 index_key
->append(entry
.key
.instance
);
245 static void encode_obj_versioned_data_key(const cls_rgw_obj_key
& key
, string
*index_key
, bool append_delete_marker_suffix
= false)
247 *index_key
= BI_PREFIX_CHAR
;
248 index_key
->append(bucket_index_prefixes
[BI_BUCKET_OBJ_INSTANCE_INDEX
]);
249 index_key
->append(key
.name
);
250 string
delim("\0i", 2);
251 index_key
->append(delim
);
252 index_key
->append(key
.instance
);
253 if (append_delete_marker_suffix
) {
255 index_key
->append(dm
);
259 static void encode_obj_index_key(const cls_rgw_obj_key
& key
, string
*index_key
)
261 if (key
.instance
.empty()) {
262 *index_key
= key
.name
;
264 encode_obj_versioned_data_key(key
, index_key
);
268 static void encode_olh_data_key(const cls_rgw_obj_key
& key
, string
*index_key
)
270 *index_key
= BI_PREFIX_CHAR
;
271 index_key
->append(bucket_index_prefixes
[BI_BUCKET_OLH_DATA_INDEX
]);
272 index_key
->append(key
.name
);
276 static int read_index_entry(cls_method_context_t hctx
, string
& name
, T
*entry
);
278 static int encode_list_index_key(cls_method_context_t hctx
, const cls_rgw_obj_key
& key
, string
*index_key
)
280 if (key
.instance
.empty()) {
281 *index_key
= key
.name
;
285 string obj_index_key
;
286 encode_obj_index_key(key
, &obj_index_key
);
288 rgw_bucket_dir_entry entry
;
290 int ret
= read_index_entry(hctx
, obj_index_key
, &entry
);
291 if (ret
== -ENOENT
) {
292 /* couldn't find the entry, set key value after the current object */
293 char buf
[2] = { 0x1, 0 };
295 *index_key
= key
.name
+ s
;
299 CLS_LOG(1, "ERROR: encode_list_index_key(): cls_cxx_map_get_val returned %d\n", ret
);
303 get_list_index_key(entry
, index_key
);
308 static void split_key(const string
& key
, list
<string
>& vals
)
311 const char *p
= key
.c_str();
312 while (pos
< key
.size()) {
313 size_t len
= strlen(p
);
321 * list index key structure:
323 * <obj name>\0[v<ver>\0i<instance id>]
325 static void decode_list_index_key(const string
& index_key
, cls_rgw_obj_key
*key
, uint64_t *ver
)
327 size_t len
= strlen(index_key
.c_str());
329 key
->instance
.clear();
332 if (len
== index_key
.size()) {
333 key
->name
= index_key
;
338 split_key(index_key
, vals
);
340 assert(!vals
.empty());
342 list
<string
>::iterator iter
= vals
.begin();
346 assert(iter
!= vals
.end());
348 for (; iter
!= vals
.end(); ++iter
) {
351 key
->instance
= val
.substr(1);
352 } else if (val
[0] == 'v') {
354 const char *s
= val
.c_str() + 1;
355 *ver
= strict_strtoll(s
, 10, &err
);
361 static int read_bucket_header(cls_method_context_t hctx
, struct rgw_bucket_dir_header
*header
)
364 int rc
= cls_cxx_map_read_header(hctx
, &bl
);
368 if (bl
.length() == 0) {
369 *header
= rgw_bucket_dir_header();
372 bufferlist::iterator iter
= bl
.begin();
374 ::decode(*header
, iter
);
375 } catch (buffer::error
& err
) {
376 CLS_LOG(1, "ERROR: read_bucket_header(): failed to decode header\n");
383 int rgw_bucket_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
385 bufferlist::iterator iter
= in
->begin();
387 struct rgw_cls_list_op op
;
390 } catch (buffer::error
& err
) {
391 CLS_LOG(1, "ERROR: rgw_bucket_list(): failed to decode request\n");
395 struct rgw_cls_list_ret ret
;
396 struct rgw_bucket_dir
& new_dir
= ret
.dir
;
397 int rc
= read_bucket_header(hctx
, &new_dir
.header
);
399 CLS_LOG(1, "ERROR: rgw_bucket_list(): failed to read header\n");
403 map
<string
, bufferlist
> keys
;
404 std::map
<string
, bufferlist
>::iterator kiter
;
406 encode_list_index_key(hctx
, op
.start_obj
, &start_key
);
408 uint32_t left_to_read
= op
.num_entries
+ 1;
411 rc
= get_obj_vals(hctx
, start_key
, op
.filter_prefix
, left_to_read
, &keys
);
415 std::map
<string
, struct rgw_bucket_dir_entry
>& m
= new_dir
.m
;
419 for (kiter
= keys
.begin(); kiter
!= keys
.end(); ++kiter
) {
420 struct rgw_bucket_dir_entry entry
;
422 if (!bi_is_objs_index(kiter
->first
)) {
427 bufferlist
& entrybl
= kiter
->second
;
428 bufferlist::iterator eiter
= entrybl
.begin();
430 ::decode(entry
, eiter
);
431 } catch (buffer::error
& err
) {
432 CLS_LOG(1, "ERROR: rgw_bucket_list(): failed to decode entry, key=%s\n", kiter
->first
.c_str());
438 decode_list_index_key(kiter
->first
, &key
, &ver
);
440 start_key
= kiter
->first
;
441 CLS_LOG(20, "start_key=%s len=%zu", start_key
.c_str(), start_key
.size());
443 if (!entry
.is_valid()) {
444 CLS_LOG(20, "entry %s[%s] is not valid\n", key
.name
.c_str(), key
.instance
.c_str());
448 if (!op
.list_versions
&& !entry
.is_visible()) {
449 CLS_LOG(20, "entry %s[%s] is not visible\n", key
.name
.c_str(), key
.instance
.c_str());
452 if (m
.size() < op
.num_entries
) {
453 m
[kiter
->first
] = entry
;
457 CLS_LOG(20, "got entry %s[%s] m.size()=%d\n", key
.name
.c_str(), key
.instance
.c_str(), (int)m
.size());
459 } while (left_to_read
> 0 && !done
);
461 ret
.is_truncated
= (left_to_read
== 0) && /* we found more entries than we were requested, meaning response is truncated */
468 static int check_index(cls_method_context_t hctx
, struct rgw_bucket_dir_header
*existing_header
, struct rgw_bucket_dir_header
*calc_header
)
470 int rc
= read_bucket_header(hctx
, existing_header
);
472 CLS_LOG(1, "ERROR: check_index(): failed to read header\n");
476 calc_header
->tag_timeout
= existing_header
->tag_timeout
;
477 calc_header
->ver
= existing_header
->ver
;
479 map
<string
, bufferlist
> keys
;
481 string filter_prefix
;
483 #define CHECK_CHUNK_SIZE 1000
487 rc
= get_obj_vals(hctx
, start_obj
, filter_prefix
, CHECK_CHUNK_SIZE
, &keys
);
491 std::map
<string
, bufferlist
>::iterator kiter
= keys
.begin();
492 for (; kiter
!= keys
.end(); ++kiter
) {
493 if (!bi_is_objs_index(kiter
->first
)) {
498 struct rgw_bucket_dir_entry entry
;
499 bufferlist::iterator eiter
= kiter
->second
.begin();
501 ::decode(entry
, eiter
);
502 } catch (buffer::error
& err
) {
503 CLS_LOG(1, "ERROR: rgw_bucket_list(): failed to decode entry, key=%s\n", kiter
->first
.c_str());
506 struct rgw_bucket_category_stats
& stats
= calc_header
->stats
[entry
.meta
.category
];
508 stats
.total_size
+= entry
.meta
.accounted_size
;
509 stats
.total_size_rounded
+= cls_rgw_get_rounded_size(entry
.meta
.accounted_size
);
510 stats
.actual_size
+= entry
.meta
.size
;
512 start_obj
= kiter
->first
;
514 } while (keys
.size() == CHECK_CHUNK_SIZE
&& !done
);
519 int rgw_bucket_check_index(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
521 struct rgw_cls_check_index_ret ret
;
523 int rc
= check_index(hctx
, &ret
.existing_header
, &ret
.calculated_header
);
532 static int write_bucket_header(cls_method_context_t hctx
, struct rgw_bucket_dir_header
*header
)
536 bufferlist header_bl
;
537 ::encode(*header
, header_bl
);
538 return cls_cxx_map_write_header(hctx
, &header_bl
);
542 int rgw_bucket_rebuild_index(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
544 struct rgw_bucket_dir_header existing_header
;
545 struct rgw_bucket_dir_header calc_header
;
546 int rc
= check_index(hctx
, &existing_header
, &calc_header
);
550 return write_bucket_header(hctx
, &calc_header
);
553 int rgw_bucket_update_stats(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
556 rgw_cls_bucket_update_stats_op op
;
557 auto iter
= in
->begin();
560 } catch (buffer::error
& err
) {
561 CLS_LOG(1, "ERROR: %s(): failed to decode request\n", __func__
);
565 struct rgw_bucket_dir_header header
;
566 int rc
= read_bucket_header(hctx
, &header
);
568 CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__
);
572 for (auto& s
: op
.stats
) {
573 auto& dest
= header
.stats
[s
.first
];
577 dest
.total_size
+= s
.second
.total_size
;
578 dest
.total_size_rounded
+= s
.second
.total_size_rounded
;
579 dest
.num_entries
+= s
.second
.num_entries
;
583 return write_bucket_header(hctx
, &header
);
586 int rgw_bucket_init_index(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
588 bufferlist::iterator iter
;
590 bufferlist header_bl
;
591 int rc
= cls_cxx_map_read_header(hctx
, &header_bl
);
602 if (header_bl
.length() != 0) {
603 CLS_LOG(1, "ERROR: index already initialized\n");
609 return write_bucket_header(hctx
, &dir
.header
);
612 int rgw_bucket_set_tag_timeout(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
615 rgw_cls_tag_timeout_op op
;
616 bufferlist::iterator iter
= in
->begin();
619 } catch (buffer::error
& err
) {
620 CLS_LOG(1, "ERROR: rgw_bucket_set_tag_timeout(): failed to decode request\n");
624 struct rgw_bucket_dir_header header
;
625 int rc
= read_bucket_header(hctx
, &header
);
627 CLS_LOG(1, "ERROR: rgw_bucket_set_tag_timeout(): failed to read header\n");
631 header
.tag_timeout
= op
.tag_timeout
;
633 return write_bucket_header(hctx
, &header
);
636 static int read_key_entry(cls_method_context_t hctx
, cls_rgw_obj_key
& key
, string
*idx
, struct rgw_bucket_dir_entry
*entry
,
637 bool special_delete_marker_name
= false);
639 int rgw_bucket_prepare_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
642 rgw_cls_obj_prepare_op op
;
643 bufferlist::iterator iter
= in
->begin();
646 } catch (buffer::error
& err
) {
647 CLS_LOG(1, "ERROR: rgw_bucket_prepare_op(): failed to decode request\n");
651 if (op
.tag
.empty()) {
652 CLS_LOG(1, "ERROR: tag is empty\n");
656 CLS_LOG(1, "rgw_bucket_prepare_op(): request: op=%d name=%s instance=%s tag=%s\n",
657 op
.op
, op
.key
.name
.c_str(), op
.key
.instance
.c_str(), op
.tag
.c_str());
662 struct rgw_bucket_dir_entry entry
;
663 int rc
= read_key_entry(hctx
, op
.key
, &idx
, &entry
);
664 if (rc
< 0 && rc
!= -ENOENT
)
667 bool noent
= (rc
== -ENOENT
);
671 if (noent
) { // no entry, initialize fields
673 entry
.ver
= rgw_bucket_entry_ver();
674 entry
.exists
= false;
675 entry
.locator
= op
.locator
;
678 // fill in proper state
679 struct rgw_bucket_pending_info info
;
680 info
.timestamp
= real_clock::now();
681 info
.state
= CLS_RGW_STATE_PENDING_MODIFY
;
683 entry
.pending_map
.insert(pair
<string
, rgw_bucket_pending_info
>(op
.tag
, info
));
685 struct rgw_bucket_dir_header header
;
686 rc
= read_bucket_header(hctx
, &header
);
688 CLS_LOG(1, "ERROR: rgw_bucket_prepare_op(): failed to read header\n");
693 rc
= log_index_operation(hctx
, op
.key
, op
.op
, op
.tag
, entry
.meta
.mtime
,
694 entry
.ver
, info
.state
, header
.ver
, header
.max_marker
, op
.bilog_flags
, NULL
, NULL
, &op
.zones_trace
);
699 // write out new key to disk
701 ::encode(entry
, info_bl
);
702 rc
= cls_cxx_map_set_val(hctx
, idx
, &info_bl
);
706 return write_bucket_header(hctx
, &header
);
709 static void unaccount_entry(struct rgw_bucket_dir_header
& header
, struct rgw_bucket_dir_entry
& entry
)
711 struct rgw_bucket_category_stats
& stats
= header
.stats
[entry
.meta
.category
];
713 stats
.total_size
-= entry
.meta
.accounted_size
;
714 stats
.total_size_rounded
-= cls_rgw_get_rounded_size(entry
.meta
.accounted_size
);
715 stats
.actual_size
-= entry
.meta
.size
;
718 static void log_entry(const char *func
, const char *str
, struct rgw_bucket_dir_entry
*entry
)
720 CLS_LOG(1, "%s(): %s: ver=%ld:%llu name=%s instance=%s locator=%s\n", func
, str
,
721 (long)entry
->ver
.pool
, (unsigned long long)entry
->ver
.epoch
,
722 entry
->key
.name
.c_str(), entry
->key
.instance
.c_str(), entry
->locator
.c_str());
725 static void log_entry(const char *func
, const char *str
, struct rgw_bucket_olh_entry
*entry
)
727 CLS_LOG(1, "%s(): %s: epoch=%llu name=%s instance=%s tag=%s\n", func
, str
,
728 (unsigned long long)entry
->epoch
, entry
->key
.name
.c_str(), entry
->key
.instance
.c_str(),
733 static int read_index_entry(cls_method_context_t hctx
, string
& name
, T
*entry
)
735 bufferlist current_entry
;
736 int rc
= cls_cxx_map_get_val(hctx
, name
, ¤t_entry
);
741 bufferlist::iterator cur_iter
= current_entry
.begin();
743 ::decode(*entry
, cur_iter
);
744 } catch (buffer::error
& err
) {
745 CLS_LOG(1, "ERROR: read_index_entry(): failed to decode entry\n");
749 log_entry(__func__
, "existing entry", entry
);
753 static int read_key_entry(cls_method_context_t hctx
, cls_rgw_obj_key
& key
, string
*idx
, struct rgw_bucket_dir_entry
*entry
,
754 bool special_delete_marker_name
)
756 encode_obj_index_key(key
, idx
);
757 int rc
= read_index_entry(hctx
, *idx
, entry
);
762 if (key
.instance
.empty() &&
763 entry
->flags
& RGW_BUCKET_DIRENT_FLAG_VER_MARKER
) {
764 /* we only do it where key.instance is empty. In this case the delete marker will have a
765 * separate entry in the index to avoid collisions with the actual object, as it's mutable
767 if (special_delete_marker_name
) {
768 encode_obj_versioned_data_key(key
, idx
, true);
769 rc
= read_index_entry(hctx
, *idx
, entry
);
774 encode_obj_versioned_data_key(key
, idx
);
775 rc
= read_index_entry(hctx
, *idx
, entry
);
777 *entry
= rgw_bucket_dir_entry(); /* need to reset entry because we initialized it earlier */
785 int rgw_bucket_complete_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
788 rgw_cls_obj_complete_op op
;
789 bufferlist::iterator iter
= in
->begin();
792 } catch (buffer::error
& err
) {
793 CLS_LOG(1, "ERROR: rgw_bucket_complete_op(): failed to decode request\n");
796 CLS_LOG(1, "rgw_bucket_complete_op(): request: op=%d name=%s instance=%s ver=%lu:%llu tag=%s\n",
797 op
.op
, op
.key
.name
.c_str(), op
.key
.instance
.c_str(),
798 (unsigned long)op
.ver
.pool
, (unsigned long long)op
.ver
.epoch
,
801 struct rgw_bucket_dir_header header
;
802 int rc
= read_bucket_header(hctx
, &header
);
804 CLS_LOG(1, "ERROR: rgw_bucket_complete_op(): failed to read header\n");
808 struct rgw_bucket_dir_entry entry
;
812 rc
= read_key_entry(hctx
, op
.key
, &idx
, &entry
);
816 entry
.meta
= op
.meta
;
817 entry
.locator
= op
.locator
;
823 entry
.index_ver
= header
.ver
;
824 entry
.flags
= (entry
.key
.instance
.empty() ? 0 : RGW_BUCKET_DIRENT_FLAG_VER
); /* resetting entry flags, entry might have been previously a delete marker */
827 map
<string
, struct rgw_bucket_pending_info
>::iterator pinter
= entry
.pending_map
.find(op
.tag
);
828 if (pinter
== entry
.pending_map
.end()) {
829 CLS_LOG(1, "ERROR: couldn't find tag for pending operation\n");
832 entry
.pending_map
.erase(pinter
);
836 bufferlist update_bl
;
838 if (op
.tag
.size() && op
.op
== CLS_RGW_OP_CANCEL
) {
839 CLS_LOG(1, "rgw_bucket_complete_op(): cancel requested\n");
841 } else if (op
.ver
.pool
== entry
.ver
.pool
&&
842 op
.ver
.epoch
&& op
.ver
.epoch
<= entry
.ver
.epoch
) {
843 CLS_LOG(1, "rgw_bucket_complete_op(): skipping request, old epoch\n");
850 rc
= log_index_operation(hctx
, op
.key
, op
.op
, op
.tag
, entry
.meta
.mtime
, entry
.ver
,
851 CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, op
.bilog_flags
, NULL
, NULL
, &op
.zones_trace
);
857 bufferlist new_key_bl
;
858 ::encode(entry
, new_key_bl
);
859 return cls_cxx_map_set_val(hctx
, idx
, &new_key_bl
);
866 unaccount_entry(header
, entry
);
870 switch ((int)op
.op
) {
872 entry
.meta
= op
.meta
;
874 if (!entry
.pending_map
.size()) {
875 int ret
= cls_cxx_map_remove_key(hctx
, idx
);
879 entry
.exists
= false;
880 bufferlist new_key_bl
;
881 ::encode(entry
, new_key_bl
);
882 int ret
= cls_cxx_map_set_val(hctx
, idx
, &new_key_bl
);
892 struct rgw_bucket_dir_entry_meta
& meta
= op
.meta
;
893 struct rgw_bucket_category_stats
& stats
= header
.stats
[meta
.category
];
899 stats
.total_size
+= meta
.accounted_size
;
900 stats
.total_size_rounded
+= cls_rgw_get_rounded_size(meta
.accounted_size
);
901 stats
.actual_size
+= meta
.size
;
902 bufferlist new_key_bl
;
903 ::encode(entry
, new_key_bl
);
904 int ret
= cls_cxx_map_set_val(hctx
, idx
, &new_key_bl
);
912 rc
= log_index_operation(hctx
, op
.key
, op
.op
, op
.tag
, entry
.meta
.mtime
, entry
.ver
,
913 CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, op
.bilog_flags
, NULL
, NULL
, &op
.zones_trace
);
918 list
<cls_rgw_obj_key
>::iterator remove_iter
;
919 CLS_LOG(20, "rgw_bucket_complete_op(): remove_objs.size()=%d\n", (int)op
.remove_objs
.size());
920 for (remove_iter
= op
.remove_objs
.begin(); remove_iter
!= op
.remove_objs
.end(); ++remove_iter
) {
921 cls_rgw_obj_key
& remove_key
= *remove_iter
;
922 CLS_LOG(1, "rgw_bucket_complete_op(): removing entries, read_index_entry name=%s instance=%s\n",
923 remove_key
.name
.c_str(), remove_key
.instance
.c_str());
924 struct rgw_bucket_dir_entry remove_entry
;
926 int ret
= read_key_entry(hctx
, remove_key
, &k
, &remove_entry
);
928 CLS_LOG(1, "rgw_bucket_complete_op(): removing entries, read_index_entry name=%s instance=%s ret=%d\n",
929 remove_key
.name
.c_str(), remove_key
.instance
.c_str(), ret
);
932 CLS_LOG(0, "rgw_bucket_complete_op(): entry.name=%s entry.instance=%s entry.meta.category=%d\n",
933 remove_entry
.key
.name
.c_str(), remove_entry
.key
.instance
.c_str(), remove_entry
.meta
.category
);
934 unaccount_entry(header
, remove_entry
);
937 rc
= log_index_operation(hctx
, remove_key
, CLS_RGW_OP_DEL
, op
.tag
, remove_entry
.meta
.mtime
,
938 remove_entry
.ver
, CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, op
.bilog_flags
, NULL
, NULL
, &op
.zones_trace
);
943 ret
= cls_cxx_map_remove_key(hctx
, k
);
945 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
);
950 return write_bucket_header(hctx
, &header
);
954 static int write_entry(cls_method_context_t hctx
, T
& entry
, const string
& key
)
958 return cls_cxx_map_set_val(hctx
, key
, &bl
);
961 static int read_olh(cls_method_context_t hctx
,cls_rgw_obj_key
& obj_key
, struct rgw_bucket_olh_entry
*olh_data_entry
, string
*index_key
, bool *found
)
963 cls_rgw_obj_key olh_key
;
964 olh_key
.name
= obj_key
.name
;
966 encode_olh_data_key(olh_key
, index_key
);
967 int ret
= read_index_entry(hctx
, *index_key
, olh_data_entry
);
968 if (ret
< 0 && ret
!= -ENOENT
) {
969 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_key
.name
.c_str(), ret
);
973 *found
= (ret
!= -ENOENT
);
978 static void update_olh_log(struct rgw_bucket_olh_entry
& olh_data_entry
, OLHLogOp op
, const string
& op_tag
,
979 cls_rgw_obj_key
& key
, bool delete_marker
, uint64_t epoch
)
981 vector
<rgw_bucket_olh_log_entry
>& log
= olh_data_entry
.pending_log
[olh_data_entry
.epoch
];
982 rgw_bucket_olh_log_entry log_entry
;
983 log_entry
.epoch
= epoch
;
985 log_entry
.op_tag
= op_tag
;
987 log_entry
.delete_marker
= delete_marker
;
988 log
.push_back(log_entry
);
991 static string
escape_str(const string
& s
)
993 int len
= escape_json_attr_len(s
.c_str(), s
.size());
995 escape_json_attr(s
.c_str(), s
.size(), escaped
);
996 return string(escaped
);
999 static int write_obj_instance_entry(cls_method_context_t hctx
, struct rgw_bucket_dir_entry
& instance_entry
, const string
& instance_idx
)
1001 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
);
1002 /* write the instance entry */
1003 int ret
= write_entry(hctx
, instance_entry
, instance_idx
);
1005 CLS_LOG(0, "ERROR: write_entry() instance_key=%s ret=%d", escape_str(instance_idx
).c_str(), ret
);
1012 * write object instance entry, and if needed also the list entry
1014 static int write_obj_entries(cls_method_context_t hctx
, struct rgw_bucket_dir_entry
& instance_entry
, const string
& instance_idx
)
1016 int ret
= write_obj_instance_entry(hctx
, instance_entry
, instance_idx
);
1020 string instance_list_idx
;
1021 get_list_index_key(instance_entry
, &instance_list_idx
);
1023 if (instance_idx
!= instance_list_idx
) {
1024 CLS_LOG(20, "write_entry() idx=%s flags=%d", escape_str(instance_list_idx
).c_str(), instance_entry
.flags
);
1025 /* write a new list entry for the object instance */
1026 ret
= write_entry(hctx
, instance_entry
, instance_list_idx
);
1028 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
);
1036 class BIVerObjEntry
{
1037 cls_method_context_t hctx
;
1038 cls_rgw_obj_key key
;
1039 string instance_idx
;
1041 struct rgw_bucket_dir_entry instance_entry
;
1046 BIVerObjEntry(cls_method_context_t
& _hctx
, const cls_rgw_obj_key
& _key
) : hctx(_hctx
), key(_key
), initialized(false) {
1049 int init(bool check_delete_marker
= true) {
1050 int ret
= read_key_entry(hctx
, key
, &instance_idx
, &instance_entry
,
1051 check_delete_marker
&& key
.instance
.empty()); /* this is potentially a delete marker, for null objects we
1052 keep separate instance entry for the delete markers */
1055 CLS_LOG(0, "ERROR: read_key_entry() idx=%s ret=%d", instance_idx
.c_str(), ret
);
1059 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
);
1063 rgw_bucket_dir_entry
& get_dir_entry() {
1064 return instance_entry
;
1067 void init_as_delete_marker(rgw_bucket_dir_entry_meta
& meta
) {
1068 /* a deletion marker, need to initialize it, there's no instance entry for it yet */
1069 instance_entry
.key
= key
;
1070 instance_entry
.flags
= RGW_BUCKET_DIRENT_FLAG_DELETE_MARKER
;
1071 instance_entry
.meta
= meta
;
1072 instance_entry
.tag
= "delete-marker";
1077 void set_epoch(uint64_t epoch
) {
1078 instance_entry
.versioned_epoch
= epoch
;
1081 int unlink_list_entry() {
1083 /* this instance has a previous list entry, remove that entry */
1084 get_list_index_key(instance_entry
, &list_idx
);
1085 CLS_LOG(20, "unlink_list_entry() list_idx=%s", escape_str(list_idx
).c_str());
1086 int ret
= cls_cxx_map_remove_key(hctx
, list_idx
);
1088 CLS_LOG(0, "ERROR: cls_cxx_map_remove_key() list_idx=%s ret=%d", list_idx
.c_str(), ret
);
1095 /* remove the instance entry */
1096 CLS_LOG(20, "unlink() idx=%s", escape_str(instance_idx
).c_str());
1097 int ret
= cls_cxx_map_remove_key(hctx
, instance_idx
);
1099 CLS_LOG(0, "ERROR: cls_cxx_map_remove_key() instance_idx=%s ret=%d", instance_idx
.c_str(), ret
);
1105 int write_entries(uint64_t flags_set
, uint64_t flags_reset
) {
1112 instance_entry
.flags
&= ~flags_reset
;
1113 instance_entry
.flags
|= flags_set
;
1115 /* write the instance and list entries */
1116 bool special_delete_marker_key
= (instance_entry
.is_delete_marker() && instance_entry
.key
.instance
.empty());
1117 encode_obj_versioned_data_key(key
, &instance_idx
, special_delete_marker_key
);
1118 int ret
= write_obj_entries(hctx
, instance_entry
, instance_idx
);
1120 CLS_LOG(0, "ERROR: write_obj_entries() instance_idx=%s ret=%d", instance_idx
.c_str(), ret
);
1127 int write(uint64_t epoch
, bool current
) {
1128 if (instance_entry
.versioned_epoch
> 0) {
1129 CLS_LOG(20, "%s(): instance_entry.versioned_epoch=%d epoch=%d", __func__
, (int)instance_entry
.versioned_epoch
, (int)epoch
);
1130 /* this instance has a previous list entry, remove that entry */
1131 int ret
= unlink_list_entry();
1137 uint64_t flags
= RGW_BUCKET_DIRENT_FLAG_VER
;
1139 flags
|= RGW_BUCKET_DIRENT_FLAG_CURRENT
;
1142 instance_entry
.versioned_epoch
= epoch
;
1143 return write_entries(flags
, 0);
1146 int demote_current() {
1147 return write_entries(0, RGW_BUCKET_DIRENT_FLAG_CURRENT
);
1150 bool is_delete_marker() {
1151 return instance_entry
.is_delete_marker();
1154 int find_next_key(cls_rgw_obj_key
*next_key
, bool *found
) {
1156 /* this instance has a previous list entry, remove that entry */
1157 get_list_index_key(instance_entry
, &list_idx
);
1158 /* this is the current head, need to update! */
1159 map
<string
, bufferlist
> keys
;
1160 string filter
= key
.name
; /* list key starts with key name, filter it to avoid a case where we cross to
1161 different namespace */
1162 int ret
= cls_cxx_map_get_vals(hctx
, list_idx
, filter
, 1, &keys
);
1167 if (keys
.size() < 1) {
1172 rgw_bucket_dir_entry next_entry
;
1174 map
<string
, bufferlist
>::reverse_iterator last
= keys
.rbegin();
1176 bufferlist::iterator iter
= last
->second
.begin();
1177 ::decode(next_entry
, iter
);
1178 } catch (buffer::error
& err
) {
1179 CLS_LOG(0, "ERROR; failed to decode entry: %s", last
->first
.c_str());
1183 *found
= (key
.name
== next_entry
.key
.name
);
1185 *next_key
= next_entry
.key
;
1192 return instance_entry
.meta
.mtime
;
1198 cls_method_context_t hctx
;
1199 cls_rgw_obj_key key
;
1201 string olh_data_idx
;
1202 struct rgw_bucket_olh_entry olh_data_entry
;
1206 BIOLHEntry(cls_method_context_t
& _hctx
, const cls_rgw_obj_key
& _key
) : hctx(_hctx
), key(_key
), initialized(false) { }
1208 int init(bool *exists
) {
1210 int ret
= read_olh(hctx
, key
, &olh_data_entry
, &olh_data_idx
, exists
);
1219 bool apply_epoch(uint64_t candidate_epoch
) {
1220 if (candidate_epoch
< olh_data_entry
.epoch
) {
1224 olh_data_entry
.epoch
= candidate_epoch
;
1228 bool start_modify(uint64_t candidate_epoch
) {
1229 if (candidate_epoch
) {
1230 if (candidate_epoch
< olh_data_entry
.epoch
) {
1231 return false; /* olh cannot be modified, old epoch */
1233 olh_data_entry
.epoch
= candidate_epoch
;
1235 if (olh_data_entry
.epoch
== 0) {
1236 olh_data_entry
.epoch
= 2; /* versioned epoch should start with 2, 1 is reserved to converted plain entries */
1238 olh_data_entry
.epoch
++;
1244 uint64_t get_epoch() {
1245 return olh_data_entry
.epoch
;
1248 rgw_bucket_olh_entry
& get_entry() {
1249 return olh_data_entry
;
1252 void update(cls_rgw_obj_key
& key
, bool delete_marker
) {
1253 olh_data_entry
.delete_marker
= delete_marker
;
1254 olh_data_entry
.key
= key
;
1258 /* write the olh data entry */
1259 int ret
= write_entry(hctx
, olh_data_entry
, olh_data_idx
);
1261 CLS_LOG(0, "ERROR: write_entry() olh_key=%s ret=%d", olh_data_idx
.c_str(), ret
);
1268 void update_log(OLHLogOp op
, const string
& op_tag
, cls_rgw_obj_key
& key
, bool delete_marker
, uint64_t epoch
= 0) {
1270 epoch
= olh_data_entry
.epoch
;
1272 update_olh_log(olh_data_entry
, op
, op_tag
, key
, delete_marker
, epoch
);
1275 bool exists() { return olh_data_entry
.exists
; }
1277 void set_exists(bool exists
) {
1278 olh_data_entry
.exists
= exists
;
1281 bool pending_removal() { return olh_data_entry
.pending_removal
; }
1283 void set_pending_removal(bool pending_removal
) {
1284 olh_data_entry
.pending_removal
= pending_removal
;
1287 const string
& get_tag() { return olh_data_entry
.tag
; }
1288 void set_tag(const string
& tag
) {
1289 olh_data_entry
.tag
= tag
;
1293 static int write_version_marker(cls_method_context_t hctx
, cls_rgw_obj_key
& key
)
1295 struct rgw_bucket_dir_entry entry
;
1297 entry
.flags
= RGW_BUCKET_DIRENT_FLAG_VER_MARKER
;
1298 int ret
= write_entry(hctx
, entry
, key
.name
);
1300 CLS_LOG(0, "ERROR: write_entry returned ret=%d", ret
);
1307 * plain entries are the ones who were created when bucket was not versioned,
1308 * if we override these objects, we need to convert these to versioned entries -- ones that have
1309 * both data entry, and listing key. Their version is going to be empty though
1311 static int convert_plain_entry_to_versioned(cls_method_context_t hctx
, cls_rgw_obj_key
& key
, bool demote_current
, bool instance_only
)
1313 if (!key
.instance
.empty()) {
1317 struct rgw_bucket_dir_entry entry
;
1320 int ret
= read_key_entry(hctx
, key
, &orig_idx
, &entry
);
1321 if (ret
!= -ENOENT
) {
1323 CLS_LOG(0, "ERROR: read_key_entry() returned ret=%d", ret
);
1327 entry
.versioned_epoch
= 1; /* converted entries are always 1 */
1328 entry
.flags
|= RGW_BUCKET_DIRENT_FLAG_VER
;
1330 if (demote_current
) {
1331 entry
.flags
&= ~RGW_BUCKET_DIRENT_FLAG_CURRENT
;
1335 encode_obj_versioned_data_key(key
, &new_idx
);
1337 if (instance_only
) {
1338 ret
= write_obj_instance_entry(hctx
, entry
, new_idx
);
1340 ret
= write_obj_entries(hctx
, entry
, new_idx
);
1343 CLS_LOG(0, "ERROR: write_obj_entries new_idx=%s returned %d", new_idx
.c_str(), ret
);
1348 ret
= write_version_marker(hctx
, key
);
1357 * link an object version to an olh, update the relevant index entries. It will also handle the
1358 * deletion marker case. We have a few entries that we need to take care of. For object 'foo',
1359 * instance BAR, we'd update the following (not actual encoding):
1360 * - olh data: [BI_BUCKET_OLH_DATA_INDEX]foo
1361 * - object instance data: [BI_BUCKET_OBJ_INSTANCE_INDEX]foo,BAR
1362 * - object instance list entry: foo,123,BAR
1364 * The instance list entry needs to be ordered by newer to older, so we generate an appropriate
1365 * number string that follows the name.
1366 * The top instance for each object is marked appropriately.
1367 * We generate instance entry for deletion markers here, as they are not created prior.
1369 static int rgw_bucket_link_olh(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1371 string olh_data_idx
;
1372 string instance_idx
;
1375 rgw_cls_link_olh_op op
;
1376 bufferlist::iterator iter
= in
->begin();
1379 } catch (buffer::error
& err
) {
1380 CLS_LOG(0, "ERROR: rgw_bucket_link_olh_op(): failed to decode request\n");
1384 BIVerObjEntry
obj(hctx
, op
.key
);
1385 BIOLHEntry
olh(hctx
, op
.key
);
1387 /* read instance entry */
1388 int ret
= obj
.init(op
.delete_marker
);
1389 bool existed
= (ret
== 0);
1390 if (ret
== -ENOENT
&& op
.delete_marker
) {
1397 if (existed
&& !real_clock::is_zero(op
.unmod_since
)) {
1398 struct timespec mtime
= ceph::real_clock::to_timespec(obj
.mtime());
1399 struct timespec unmod
= ceph::real_clock::to_timespec(op
.unmod_since
);
1400 if (!op
.high_precision_time
) {
1404 if (mtime
>= unmod
) {
1405 return 0; /* no need to set error, we just return 0 and avoid writing to the bi log */
1412 * Special handling for null instance object / delete-marker. For these objects we're going to
1413 * have separate instances for a data object vs. delete-marker to avoid collisions. We now check
1414 * if we got to overwrite a previous entry, and in that case we'll remove its list entry.
1416 if (op
.key
.instance
.empty()) {
1417 BIVerObjEntry
other_obj(hctx
, op
.key
);
1418 ret
= other_obj
.init(!op
.delete_marker
); /* try reading the other null versioned entry */
1419 existed
= (ret
>= 0 && !other_obj
.is_delete_marker());
1420 if (ret
>= 0 && other_obj
.is_delete_marker() != op
.delete_marker
) {
1421 ret
= other_obj
.unlink_list_entry();
1425 ret
= other_obj
.unlink();
1431 removing
= existed
&& op
.delete_marker
;
1433 removing
= (existed
&& !obj
.is_delete_marker() && op
.delete_marker
);
1436 if (op
.delete_marker
) {
1437 /* a deletion marker, need to initialize entry as such */
1438 obj
.init_as_delete_marker(op
.meta
);
1443 ret
= olh
.init(&olh_found
);
1448 if (!olh
.start_modify(op
.olh_epoch
)) {
1449 ret
= obj
.write(op
.olh_epoch
, false);
1454 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false, op
.olh_epoch
);
1460 const string
& olh_tag
= olh
.get_tag();
1461 if (op
.olh_tag
!= olh_tag
) {
1462 if (!olh
.pending_removal()) {
1463 CLS_LOG(5, "NOTICE: op.olh_tag (%s) != olh.tag (%s)", op
.olh_tag
.c_str(), olh_tag
.c_str());
1466 /* if pending removal, this is a new olh instance */
1467 olh
.set_tag(op
.olh_tag
);
1470 rgw_bucket_olh_entry
& olh_entry
= olh
.get_entry();
1471 /* found olh, previous instance is no longer the latest, need to update */
1472 if (!(olh_entry
.key
== op
.key
)) {
1473 BIVerObjEntry
old_obj(hctx
, olh_entry
.key
);
1475 ret
= old_obj
.demote_current();
1477 CLS_LOG(0, "ERROR: could not demote current on previous key ret=%d", ret
);
1482 olh
.set_pending_removal(false);
1484 bool instance_only
= (op
.key
.instance
.empty() && op
.delete_marker
);
1485 cls_rgw_obj_key
key(op
.key
.name
);
1486 ret
= convert_plain_entry_to_versioned(hctx
, key
, true, instance_only
);
1488 CLS_LOG(0, "ERROR: convert_plain_entry_to_versioned ret=%d", ret
);
1491 olh
.set_tag(op
.olh_tag
);
1494 /* update the olh log */
1495 olh
.update_log(CLS_RGW_OLH_OP_LINK_OLH
, op
.op_tag
, op
.key
, op
.delete_marker
);
1497 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false);
1500 olh
.update(op
.key
, op
.delete_marker
);
1502 olh
.set_exists(true);
1506 CLS_LOG(0, "ERROR: failed to update olh ret=%d", ret
);
1510 /* write the instance and list entries */
1511 ret
= obj
.write(olh
.get_epoch(), true);
1516 struct rgw_bucket_dir_header header
;
1517 ret
= read_bucket_header(hctx
, &header
);
1519 CLS_LOG(1, "ERROR: rgw_bucket_unlink_instance(): failed to read header\n");
1524 rgw_bucket_dir_entry
& entry
= obj
.get_dir_entry();
1526 rgw_bucket_entry_ver ver
;
1527 ver
.epoch
= (op
.olh_epoch
? op
.olh_epoch
: olh
.get_epoch());
1529 string
*powner
= NULL
;
1530 string
*powner_display_name
= NULL
;
1532 if (op
.delete_marker
) {
1533 powner
= &entry
.meta
.owner
;
1534 powner_display_name
= &entry
.meta
.owner_display_name
;
1537 RGWModifyOp operation
= (op
.delete_marker
? CLS_RGW_OP_LINK_OLH_DM
: CLS_RGW_OP_LINK_OLH
);
1538 ret
= log_index_operation(hctx
, op
.key
, operation
, op
.op_tag
,
1539 entry
.meta
.mtime
, ver
,
1540 CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, op
.bilog_flags
| RGW_BILOG_FLAG_VERSIONED_OP
,
1541 powner
, powner_display_name
, &op
.zones_trace
);
1546 return write_bucket_header(hctx
, &header
); /* updates header version */
1549 static int rgw_bucket_unlink_instance(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1551 string olh_data_idx
;
1552 string instance_idx
;
1555 rgw_cls_unlink_instance_op op
;
1556 bufferlist::iterator iter
= in
->begin();
1559 } catch (buffer::error
& err
) {
1560 CLS_LOG(0, "ERROR: rgw_bucket_rm_obj_instance_op(): failed to decode request\n");
1564 cls_rgw_obj_key dest_key
= op
.key
;
1565 if (dest_key
.instance
== "null") {
1566 dest_key
.instance
.clear();
1569 BIVerObjEntry
obj(hctx
, dest_key
);
1570 BIOLHEntry
olh(hctx
, dest_key
);
1572 int ret
= obj
.init();
1573 if (ret
== -ENOENT
) {
1574 return 0; /* already removed */
1577 CLS_LOG(0, "ERROR: obj.init() returned ret=%d", ret
);
1582 ret
= olh
.init(&olh_found
);
1584 CLS_LOG(0, "ERROR: olh.init() returned ret=%d", ret
);
1589 bool instance_only
= false;
1590 cls_rgw_obj_key
key(dest_key
.name
);
1591 ret
= convert_plain_entry_to_versioned(hctx
, key
, true, instance_only
);
1593 CLS_LOG(0, "ERROR: convert_plain_entry_to_versioned ret=%d", ret
);
1596 olh
.update(dest_key
, false);
1597 olh
.set_tag(op
.olh_tag
);
1602 if (!olh
.start_modify(op
.olh_epoch
)) {
1603 ret
= obj
.unlink_list_entry();
1608 if (!obj
.is_delete_marker()) {
1609 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false, op
.olh_epoch
);
1615 rgw_bucket_olh_entry
& olh_entry
= olh
.get_entry();
1616 cls_rgw_obj_key
& olh_key
= olh_entry
.key
;
1617 CLS_LOG(20, "%s(): updating olh log: existing olh entry: %s[%s] (delete_marker=%d)", __func__
,
1618 olh_key
.name
.c_str(), olh_key
.instance
.c_str(), olh_entry
.delete_marker
);
1620 if (olh_key
== dest_key
) {
1621 /* this is the current head, need to update! */
1622 cls_rgw_obj_key next_key
;
1624 ret
= obj
.find_next_key(&next_key
, &found
);
1626 CLS_LOG(0, "ERROR: obj.find_next_key() returned ret=%d", ret
);
1631 BIVerObjEntry
next(hctx
, next_key
);
1632 ret
= next
.write(olh
.get_epoch(), true);
1634 CLS_LOG(0, "ERROR: next.write() returned ret=%d", ret
);
1638 CLS_LOG(20, "%s(): updating olh log: link olh -> %s[%s] (is_delete=%d)", __func__
,
1639 next_key
.name
.c_str(), next_key
.instance
.c_str(), (int)next
.is_delete_marker());
1641 olh
.update(next_key
, next
.is_delete_marker());
1642 olh
.update_log(CLS_RGW_OLH_OP_LINK_OLH
, op
.op_tag
, next_key
, next
.is_delete_marker());
1644 /* next_key is empty */
1645 olh
.update(next_key
, false);
1646 olh
.update_log(CLS_RGW_OLH_OP_UNLINK_OLH
, op
.op_tag
, next_key
, false);
1647 olh
.set_exists(false);
1648 olh
.set_pending_removal(true);
1652 if (!obj
.is_delete_marker()) {
1653 olh
.update_log(CLS_RGW_OLH_OP_REMOVE_INSTANCE
, op
.op_tag
, op
.key
, false);
1655 /* this is a delete marker, it's our responsibility to remove its instance entry */
1662 ret
= obj
.unlink_list_entry();
1672 struct rgw_bucket_dir_header header
;
1673 ret
= read_bucket_header(hctx
, &header
);
1675 CLS_LOG(1, "ERROR: rgw_bucket_unlink_instance(): failed to read header\n");
1680 rgw_bucket_entry_ver ver
;
1681 ver
.epoch
= (op
.olh_epoch
? op
.olh_epoch
: olh
.get_epoch());
1683 real_time mtime
= real_clock::now(); /* mtime has no real meaning in instance removal context */
1684 ret
= log_index_operation(hctx
, op
.key
, CLS_RGW_OP_UNLINK_INSTANCE
, op
.op_tag
,
1686 CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
,
1687 op
.bilog_flags
| RGW_BILOG_FLAG_VERSIONED_OP
, NULL
, NULL
, &op
.zones_trace
);
1692 return write_bucket_header(hctx
, &header
); /* updates header version */
1695 static int rgw_bucket_read_olh_log(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1698 rgw_cls_read_olh_log_op op
;
1699 bufferlist::iterator iter
= in
->begin();
1702 } catch (buffer::error
& err
) {
1703 CLS_LOG(0, "ERROR: rgw_bucket_read_olh_log(): failed to decode request\n");
1707 if (!op
.olh
.instance
.empty()) {
1708 CLS_LOG(1, "bad key passed in (non empty instance)");
1712 struct rgw_bucket_olh_entry olh_data_entry
;
1713 string olh_data_key
;
1714 encode_olh_data_key(op
.olh
, &olh_data_key
);
1715 int ret
= read_index_entry(hctx
, olh_data_key
, &olh_data_entry
);
1716 if (ret
< 0 && ret
!= -ENOENT
) {
1717 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
1721 if (olh_data_entry
.tag
!= op
.olh_tag
) {
1722 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());
1726 rgw_cls_read_olh_log_ret op_ret
;
1728 #define MAX_OLH_LOG_ENTRIES 1000
1729 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >& log
= olh_data_entry
.pending_log
;
1731 if (log
.begin()->first
> op
.ver_marker
&& log
.size() <= MAX_OLH_LOG_ENTRIES
) {
1733 op_ret
.is_truncated
= false;
1735 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >::iterator iter
= log
.upper_bound(op
.ver_marker
);
1737 for (int i
= 0; i
< MAX_OLH_LOG_ENTRIES
&& iter
!= log
.end(); ++i
, ++iter
) {
1738 op_ret
.log
[iter
->first
] = iter
->second
;
1740 op_ret
.is_truncated
= (iter
!= log
.end());
1743 ::encode(op_ret
, *out
);
1748 static int rgw_bucket_trim_olh_log(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1751 rgw_cls_trim_olh_log_op op
;
1752 bufferlist::iterator iter
= in
->begin();
1755 } catch (buffer::error
& err
) {
1756 CLS_LOG(0, "ERROR: rgw_bucket_trim_olh_log(): failed to decode request\n");
1760 if (!op
.olh
.instance
.empty()) {
1761 CLS_LOG(1, "bad key passed in (non empty instance)");
1765 /* read olh entry */
1766 struct rgw_bucket_olh_entry olh_data_entry
;
1767 string olh_data_key
;
1768 encode_olh_data_key(op
.olh
, &olh_data_key
);
1769 int ret
= read_index_entry(hctx
, olh_data_key
, &olh_data_entry
);
1770 if (ret
< 0 && ret
!= -ENOENT
) {
1771 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
1775 if (olh_data_entry
.tag
!= op
.olh_tag
) {
1776 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());
1780 /* remove all versions up to and including ver from the pending map */
1781 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >& log
= olh_data_entry
.pending_log
;
1782 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >::iterator liter
= log
.begin();
1783 while (liter
!= log
.end() && liter
->first
<= op
.ver
) {
1784 map
<uint64_t, vector
<rgw_bucket_olh_log_entry
> >::iterator rm_iter
= liter
;
1789 /* write the olh data entry */
1790 ret
= write_entry(hctx
, olh_data_entry
, olh_data_key
);
1792 CLS_LOG(0, "ERROR: write_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
1799 static int rgw_bucket_clear_olh(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1802 rgw_cls_bucket_clear_olh_op op
;
1803 bufferlist::iterator iter
= in
->begin();
1806 } catch (buffer::error
& err
) {
1807 CLS_LOG(0, "ERROR: rgw_bucket_clear_olh(): failed to decode request\n");
1811 if (!op
.key
.instance
.empty()) {
1812 CLS_LOG(1, "bad key passed in (non empty instance)");
1816 /* read olh entry */
1817 struct rgw_bucket_olh_entry olh_data_entry
;
1818 string olh_data_key
;
1819 encode_olh_data_key(op
.key
, &olh_data_key
);
1820 int ret
= read_index_entry(hctx
, olh_data_key
, &olh_data_entry
);
1821 if (ret
< 0 && ret
!= -ENOENT
) {
1822 CLS_LOG(0, "ERROR: read_index_entry() olh_key=%s ret=%d", olh_data_key
.c_str(), ret
);
1826 if (olh_data_entry
.tag
!= op
.olh_tag
) {
1827 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());
1831 ret
= cls_cxx_map_remove_key(hctx
, olh_data_key
);
1833 CLS_LOG(1, "NOTICE: %s(): can't remove key %s ret=%d", __func__
, olh_data_key
.c_str(), ret
);
1837 rgw_bucket_dir_entry plain_entry
;
1839 /* read plain entry, make sure it's a versioned place holder */
1840 ret
= read_index_entry(hctx
, op
.key
.name
, &plain_entry
);
1841 if (ret
== -ENOENT
) {
1842 /* we're done, no entry existing */
1846 CLS_LOG(0, "ERROR: read_index_entry key=%s ret=%d", op
.key
.name
.c_str(), ret
);
1850 if ((plain_entry
.flags
& RGW_BUCKET_DIRENT_FLAG_VER_MARKER
) == 0) {
1851 /* it's not a version marker, don't remove it */
1855 ret
= cls_cxx_map_remove_key(hctx
, op
.key
.name
);
1857 CLS_LOG(1, "NOTICE: %s(): can't remove key %s ret=%d", __func__
, op
.key
.name
.c_str(), ret
);
1864 int rgw_dir_suggest_changes(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1866 CLS_LOG(1, "rgw_dir_suggest_changes()");
1868 bufferlist header_bl
;
1869 struct rgw_bucket_dir_header header
;
1870 bool header_changed
= false;
1872 int rc
= read_bucket_header(hctx
, &header
);
1874 CLS_LOG(1, "ERROR: rgw_dir_suggest_changes(): failed to read header\n");
1878 timespan
tag_timeout(
1879 std::chrono::seconds(
1880 header
.tag_timeout
? header
.tag_timeout
: CEPH_RGW_TAG_TIMEOUT
));
1882 bufferlist::iterator in_iter
= in
->begin();
1884 while (!in_iter
.end()) {
1886 rgw_bucket_dir_entry cur_change
;
1887 rgw_bucket_dir_entry cur_disk
;
1889 ::decode(op
, in_iter
);
1890 ::decode(cur_change
, in_iter
);
1891 } catch (buffer::error
& err
) {
1892 CLS_LOG(1, "ERROR: rgw_dir_suggest_changes(): failed to decode request\n");
1896 bufferlist cur_disk_bl
;
1897 string cur_change_key
;
1898 encode_obj_index_key(cur_change
.key
, &cur_change_key
);
1899 int ret
= cls_cxx_map_get_val(hctx
, cur_change_key
, &cur_disk_bl
);
1900 if (ret
< 0 && ret
!= -ENOENT
)
1903 if (cur_disk_bl
.length()) {
1904 bufferlist::iterator cur_disk_iter
= cur_disk_bl
.begin();
1906 ::decode(cur_disk
, cur_disk_iter
);
1907 } catch (buffer::error
& error
) {
1908 CLS_LOG(1, "ERROR: rgw_dir_suggest_changes(): failed to decode cur_disk\n");
1912 real_time cur_time
= real_clock::now();
1913 map
<string
, struct rgw_bucket_pending_info
>::iterator iter
=
1914 cur_disk
.pending_map
.begin();
1915 while(iter
!= cur_disk
.pending_map
.end()) {
1916 map
<string
, struct rgw_bucket_pending_info
>::iterator cur_iter
=iter
++;
1917 if (cur_time
> (cur_iter
->second
.timestamp
+ timespan(tag_timeout
))) {
1918 cur_disk
.pending_map
.erase(cur_iter
);
1923 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",
1924 cur_disk
.pending_map
.empty(), (int)op
, cur_disk
.exists
,
1925 (int)cur_change
.pending_map
.size(), cur_change
.exists
);
1927 if (cur_disk
.pending_map
.empty()) {
1928 if (cur_disk
.exists
) {
1929 struct rgw_bucket_category_stats
& old_stats
= header
.stats
[cur_disk
.meta
.category
];
1930 CLS_LOG(10, "total_entries: %" PRId64
" -> %" PRId64
"\n", old_stats
.num_entries
, old_stats
.num_entries
- 1);
1931 old_stats
.num_entries
--;
1932 old_stats
.total_size
-= cur_disk
.meta
.accounted_size
;
1933 old_stats
.total_size_rounded
-= cls_rgw_get_rounded_size(cur_disk
.meta
.accounted_size
);
1934 old_stats
.actual_size
-= cur_disk
.meta
.size
;
1935 header_changed
= true;
1937 struct rgw_bucket_category_stats
& stats
=
1938 header
.stats
[cur_change
.meta
.category
];
1939 bool log_op
= (op
& CEPH_RGW_DIR_SUGGEST_LOG_OP
) != 0;
1940 op
&= CEPH_RGW_DIR_SUGGEST_OP_MASK
;
1942 case CEPH_RGW_REMOVE
:
1943 CLS_LOG(10, "CEPH_RGW_REMOVE name=%s instance=%s\n", cur_change
.key
.name
.c_str(), cur_change
.key
.instance
.c_str());
1944 ret
= cls_cxx_map_remove_key(hctx
, cur_change_key
);
1947 if (log_op
&& cur_disk
.exists
) {
1948 ret
= log_index_operation(hctx
, cur_disk
.key
, CLS_RGW_OP_DEL
, cur_disk
.tag
, cur_disk
.meta
.mtime
,
1949 cur_disk
.ver
, CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, 0, NULL
, NULL
, NULL
);
1951 CLS_LOG(0, "ERROR: %s(): failed to log operation ret=%d", __func__
, ret
);
1956 case CEPH_RGW_UPDATE
:
1957 CLS_LOG(10, "CEPH_RGW_UPDATE name=%s instance=%s total_entries: %" PRId64
" -> %" PRId64
"\n",
1958 cur_change
.key
.name
.c_str(), cur_change
.key
.instance
.c_str(), stats
.num_entries
, stats
.num_entries
+ 1);
1959 stats
.num_entries
++;
1960 stats
.total_size
+= cur_change
.meta
.accounted_size
;
1961 stats
.total_size_rounded
+= cls_rgw_get_rounded_size(cur_change
.meta
.accounted_size
);
1962 stats
.actual_size
+= cur_change
.meta
.size
;
1963 header_changed
= true;
1964 cur_change
.index_ver
= header
.ver
;
1965 bufferlist cur_state_bl
;
1966 ::encode(cur_change
, cur_state_bl
);
1967 ret
= cls_cxx_map_set_val(hctx
, cur_change_key
, &cur_state_bl
);
1971 ret
= log_index_operation(hctx
, cur_change
.key
, CLS_RGW_OP_ADD
, cur_change
.tag
, cur_change
.meta
.mtime
,
1972 cur_change
.ver
, CLS_RGW_STATE_COMPLETE
, header
.ver
, header
.max_marker
, 0, NULL
, NULL
, NULL
);
1974 CLS_LOG(0, "ERROR: %s(): failed to log operation ret=%d", __func__
, ret
);
1984 if (header_changed
) {
1985 return write_bucket_header(hctx
, &header
);
1990 static int rgw_obj_remove(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
1993 rgw_cls_obj_remove_op op
;
1994 bufferlist::iterator iter
= in
->begin();
1997 } catch (buffer::error
& err
) {
1998 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2002 if (op
.keep_attr_prefixes
.empty()) {
2003 return cls_cxx_remove(hctx
);
2006 map
<string
, bufferlist
> attrset
;
2007 int ret
= cls_cxx_getxattrs(hctx
, &attrset
);
2008 if (ret
< 0 && ret
!= -ENOENT
) {
2009 CLS_LOG(0, "ERROR: %s(): cls_cxx_getxattrs() returned %d", __func__
, ret
);
2013 map
<string
, bufferlist
> new_attrs
;
2014 for (list
<string
>::iterator iter
= op
.keep_attr_prefixes
.begin();
2015 iter
!= op
.keep_attr_prefixes
.end(); ++iter
) {
2016 string
& check_prefix
= *iter
;
2018 for (map
<string
, bufferlist
>::iterator aiter
= attrset
.lower_bound(check_prefix
);
2019 aiter
!= attrset
.end(); ++aiter
) {
2020 const string
& attr
= aiter
->first
;
2022 if (attr
.substr(0, check_prefix
.size()) > check_prefix
) {
2026 new_attrs
[attr
] = aiter
->second
;
2030 CLS_LOG(20, "%s(): removing object", __func__
);
2031 ret
= cls_cxx_remove(hctx
);
2033 CLS_LOG(0, "ERROR: %s(): cls_cxx_remove returned %d", __func__
, ret
);
2037 if (new_attrs
.empty()) {
2038 /* no data to keep */
2042 ret
= cls_cxx_create(hctx
, false);
2044 CLS_LOG(0, "ERROR: %s(): cls_cxx_create returned %d", __func__
, ret
);
2048 for (map
<string
, bufferlist
>::iterator aiter
= new_attrs
.begin();
2049 aiter
!= new_attrs
.end(); ++aiter
) {
2050 const string
& attr
= aiter
->first
;
2052 ret
= cls_cxx_setxattr(hctx
, attr
.c_str(), &aiter
->second
);
2053 CLS_LOG(20, "%s(): setting attr: %s", __func__
, attr
.c_str());
2055 CLS_LOG(0, "ERROR: %s(): cls_cxx_setxattr (attr=%s) returned %d", __func__
, attr
.c_str(), ret
);
2063 static int rgw_obj_store_pg_ver(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2066 rgw_cls_obj_store_pg_ver_op op
;
2067 bufferlist::iterator iter
= in
->begin();
2070 } catch (buffer::error
& err
) {
2071 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2076 uint64_t ver
= cls_current_version(hctx
);
2078 int ret
= cls_cxx_setxattr(hctx
, op
.attr
.c_str(), &bl
);
2080 CLS_LOG(0, "ERROR: %s(): cls_cxx_setxattr (attr=%s) returned %d", __func__
, op
.attr
.c_str(), ret
);
2087 static int rgw_obj_check_attrs_prefix(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2090 rgw_cls_obj_check_attrs_prefix op
;
2091 bufferlist::iterator iter
= in
->begin();
2094 } catch (buffer::error
& err
) {
2095 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2099 if (op
.check_prefix
.empty()) {
2103 map
<string
, bufferlist
> attrset
;
2104 int ret
= cls_cxx_getxattrs(hctx
, &attrset
);
2105 if (ret
< 0 && ret
!= -ENOENT
) {
2106 CLS_LOG(0, "ERROR: %s(): cls_cxx_getxattrs() returned %d", __func__
, ret
);
2112 for (map
<string
, bufferlist
>::iterator aiter
= attrset
.lower_bound(op
.check_prefix
);
2113 aiter
!= attrset
.end(); ++aiter
) {
2114 const string
& attr
= aiter
->first
;
2116 if (attr
.substr(0, op
.check_prefix
.size()) > op
.check_prefix
) {
2123 if (exist
== op
.fail_if_exist
) {
2130 static int rgw_obj_check_mtime(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2133 rgw_cls_obj_check_mtime op
;
2134 bufferlist::iterator iter
= in
->begin();
2137 } catch (buffer::error
& err
) {
2138 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2143 int ret
= cls_cxx_stat2(hctx
, NULL
, &obj_ut
);
2144 if (ret
< 0 && ret
!= -ENOENT
) {
2145 CLS_LOG(0, "ERROR: %s(): cls_cxx_stat() returned %d", __func__
, ret
);
2148 if (ret
== -ENOENT
) {
2149 CLS_LOG(10, "object does not exist, skipping check");
2152 ceph_timespec obj_ts
= ceph::real_clock::to_ceph_timespec(obj_ut
);
2153 ceph_timespec op_ts
= ceph::real_clock::to_ceph_timespec(op
.mtime
);
2155 if (!op
.high_precision_time
) {
2160 CLS_LOG(10, "%s: obj_ut=%lld.%06lld op.mtime=%lld.%06lld", __func__
,
2161 (long long)obj_ts
.tv_sec
, (long long)obj_ts
.tv_nsec
,
2162 (long long)op_ts
.tv_sec
, (long long)op_ts
.tv_nsec
);
2167 case CLS_RGW_CHECK_TIME_MTIME_EQ
:
2168 check
= (obj_ts
== op_ts
);
2170 case CLS_RGW_CHECK_TIME_MTIME_LT
:
2171 check
= (obj_ts
< op_ts
);
2173 case CLS_RGW_CHECK_TIME_MTIME_LE
:
2174 check
= (obj_ts
<= op_ts
);
2176 case CLS_RGW_CHECK_TIME_MTIME_GT
:
2177 check
= (obj_ts
> op_ts
);
2179 case CLS_RGW_CHECK_TIME_MTIME_GE
:
2180 check
= (obj_ts
>= op_ts
);
2193 static int rgw_bi_get_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2196 rgw_cls_bi_get_op op
;
2197 bufferlist::iterator iter
= in
->begin();
2200 } catch (buffer::error
& err
) {
2201 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2212 encode_obj_index_key(op
.key
, &idx
);
2215 encode_olh_data_key(op
.key
, &idx
);
2218 CLS_LOG(10, "%s(): invalid key type encoding: %d", __func__
, op
.type
);
2222 rgw_cls_bi_get_ret op_ret
;
2224 rgw_cls_bi_entry
& entry
= op_ret
.entry
;
2226 entry
.type
= op
.type
;
2229 int r
= cls_cxx_map_get_val(hctx
, idx
, &entry
.data
);
2231 CLS_LOG(10, "%s(): cls_cxx_map_get_val() returned %d", __func__
, r
);
2235 ::encode(op_ret
, *out
);
2240 static int rgw_bi_put_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2243 rgw_cls_bi_put_op op
;
2244 bufferlist::iterator iter
= in
->begin();
2247 } catch (buffer::error
& err
) {
2248 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2252 rgw_cls_bi_entry
& entry
= op
.entry
;
2254 int r
= cls_cxx_map_set_val(hctx
, entry
.idx
, &entry
.data
);
2256 CLS_LOG(0, "ERROR: %s(): cls_cxx_map_set_val() returned r=%d", __func__
, r
);
2262 static int list_plain_entries(cls_method_context_t hctx
, const string
& name
, const string
& marker
, uint32_t max
,
2263 list
<rgw_cls_bi_entry
> *entries
)
2265 string filter
= name
;
2266 string start_key
= marker
;
2268 string end_key
; // stop listing at bi_log_prefix
2269 bi_log_prefix(end_key
);
2272 map
<string
, bufferlist
> keys
;
2274 if (count
>= (int)max
) {
2278 #define BI_GET_NUM_KEYS 128
2279 int ret
= cls_cxx_map_get_vals(hctx
, start_key
, filter
, BI_GET_NUM_KEYS
, &keys
);
2284 map
<string
, bufferlist
>::iterator iter
;
2285 for (iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
2286 if (iter
->first
>= end_key
) {
2287 /* past the end of plain namespace */
2291 rgw_cls_bi_entry entry
;
2292 entry
.type
= PlainIdx
;
2293 entry
.idx
= iter
->first
;
2294 entry
.data
= iter
->second
;
2296 bufferlist::iterator biter
= entry
.data
.begin();
2298 rgw_bucket_dir_entry e
;
2301 } catch (buffer::error
& err
) {
2302 CLS_LOG(0, "ERROR: %s(): failed to decode buffer", __func__
);
2306 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());
2308 if (!name
.empty() && e
.key
.name
!= name
) {
2312 entries
->push_back(entry
);
2314 if (count
>= (int)max
) {
2317 start_key
= entry
.idx
;
2319 } while (!keys
.empty());
2324 static int list_instance_entries(cls_method_context_t hctx
, const string
& name
, const string
& marker
, uint32_t max
,
2325 list
<rgw_cls_bi_entry
> *entries
)
2327 cls_rgw_obj_key
key(name
);
2328 string first_instance_idx
;
2329 encode_obj_versioned_data_key(key
, &first_instance_idx
);
2332 if (!name
.empty()) {
2333 start_key
= first_instance_idx
;
2335 start_key
= BI_PREFIX_CHAR
;
2336 start_key
.append(bucket_index_prefixes
[BI_BUCKET_OBJ_INSTANCE_INDEX
]);
2338 string filter
= start_key
;
2339 if (bi_entry_gt(marker
, start_key
)) {
2343 map
<string
, bufferlist
> keys
;
2344 bool started
= true;
2346 if (count
>= (int)max
) {
2350 #define BI_GET_NUM_KEYS 128
2353 ret
= cls_cxx_map_get_val(hctx
, start_key
, &keys
[start_key
]);
2354 if (ret
== -ENOENT
) {
2355 ret
= cls_cxx_map_get_vals(hctx
, start_key
, string(), BI_GET_NUM_KEYS
, &keys
);
2359 ret
= cls_cxx_map_get_vals(hctx
, start_key
, string(), BI_GET_NUM_KEYS
, &keys
);
2361 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());
2366 map
<string
, bufferlist
>::iterator iter
;
2367 for (iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
2368 rgw_cls_bi_entry entry
;
2369 entry
.type
= InstanceIdx
;
2370 entry
.idx
= iter
->first
;
2371 entry
.data
= iter
->second
;
2373 if (!filter
.empty() && entry
.idx
.compare(0, filter
.size(), filter
) != 0) {
2377 CLS_LOG(20, "%s(): entry.idx=%s", __func__
, escape_str(entry
.idx
).c_str());
2379 bufferlist::iterator biter
= entry
.data
.begin();
2381 rgw_bucket_dir_entry e
;
2384 } catch (buffer::error
& err
) {
2385 CLS_LOG(0, "ERROR: %s(): failed to decode buffer (size=%d)", __func__
, entry
.data
.length());
2389 if (!name
.empty() && e
.key
.name
!= name
) {
2393 entries
->push_back(entry
);
2395 start_key
= entry
.idx
;
2397 } while (!keys
.empty());
2402 static int list_olh_entries(cls_method_context_t hctx
, const string
& name
, const string
& marker
, uint32_t max
,
2403 list
<rgw_cls_bi_entry
> *entries
)
2405 cls_rgw_obj_key
key(name
);
2406 string first_instance_idx
;
2407 encode_olh_data_key(key
, &first_instance_idx
);
2410 if (!name
.empty()) {
2411 start_key
= first_instance_idx
;
2413 start_key
= BI_PREFIX_CHAR
;
2414 start_key
.append(bucket_index_prefixes
[BI_BUCKET_OLH_DATA_INDEX
]);
2416 string filter
= start_key
;
2417 if (bi_entry_gt(marker
, start_key
)) {
2421 map
<string
, bufferlist
> keys
;
2422 bool started
= true;
2424 if (count
>= (int)max
) {
2428 #define BI_GET_NUM_KEYS 128
2431 ret
= cls_cxx_map_get_val(hctx
, start_key
, &keys
[start_key
]);
2432 if (ret
== -ENOENT
) {
2433 ret
= cls_cxx_map_get_vals(hctx
, start_key
, string(), BI_GET_NUM_KEYS
, &keys
);
2437 ret
= cls_cxx_map_get_vals(hctx
, start_key
, string(), BI_GET_NUM_KEYS
, &keys
);
2439 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());
2444 map
<string
, bufferlist
>::iterator iter
;
2445 for (iter
= keys
.begin(); iter
!= keys
.end(); ++iter
) {
2446 rgw_cls_bi_entry entry
;
2447 entry
.type
= OLHIdx
;
2448 entry
.idx
= iter
->first
;
2449 entry
.data
= iter
->second
;
2451 if (!filter
.empty() && entry
.idx
.compare(0, filter
.size(), filter
) != 0) {
2455 CLS_LOG(20, "%s(): entry.idx=%s", __func__
, escape_str(entry
.idx
).c_str());
2457 bufferlist::iterator biter
= entry
.data
.begin();
2459 rgw_bucket_olh_entry e
;
2462 } catch (buffer::error
& err
) {
2463 CLS_LOG(0, "ERROR: %s(): failed to decode buffer (size=%d)", __func__
, entry
.data
.length());
2467 if (!name
.empty() && e
.key
.name
!= name
) {
2471 entries
->push_back(entry
);
2473 start_key
= entry
.idx
;
2475 } while (!keys
.empty());
2480 static int rgw_bi_list_op(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2483 rgw_cls_bi_list_op op
;
2484 bufferlist::iterator iter
= in
->begin();
2487 } catch (buffer::error
& err
) {
2488 CLS_LOG(0, "ERROR: %s(): failed to decode request", __func__
);
2492 rgw_cls_bi_list_ret op_ret
;
2494 string filter
= op
.name
;
2495 #define MAX_BI_LIST_ENTRIES 1000
2496 int32_t max
= (op
.max
< MAX_BI_LIST_ENTRIES
? op
.max
: MAX_BI_LIST_ENTRIES
) + 1; /* one extra entry for identifying truncation */
2497 string start_key
= op
.marker
;
2498 int ret
= list_plain_entries(hctx
, op
.name
, op
.marker
, max
, &op_ret
.entries
);
2500 CLS_LOG(0, "ERROR: %s(): list_plain_entries retured ret=%d", __func__
, ret
);
2505 CLS_LOG(20, "found %d plain entries", count
);
2507 ret
= list_instance_entries(hctx
, op
.name
, op
.marker
, max
- count
, &op_ret
.entries
);
2509 CLS_LOG(0, "ERROR: %s(): list_instance_entries retured ret=%d", __func__
, ret
);
2515 ret
= list_olh_entries(hctx
, op
.name
, op
.marker
, max
- count
, &op_ret
.entries
);
2517 CLS_LOG(0, "ERROR: %s(): list_olh_entries retured ret=%d", __func__
, ret
);
2523 op_ret
.is_truncated
= (count
>= max
);
2524 while (count
>= max
) {
2525 op_ret
.entries
.pop_back();
2529 ::encode(op_ret
, *out
);
2534 int bi_log_record_decode(bufferlist
& bl
, rgw_bi_log_entry
& e
)
2536 bufferlist::iterator iter
= bl
.begin();
2539 } catch (buffer::error
& err
) {
2540 CLS_LOG(0, "ERROR: failed to decode rgw_bi_log_entry");
2546 static int bi_log_iterate_entries(cls_method_context_t hctx
, const string
& marker
, const string
& end_marker
,
2547 string
& key_iter
, uint32_t max_entries
, bool *truncated
,
2548 int (*cb
)(cls_method_context_t
, const string
&, rgw_bi_log_entry
&, void *),
2551 CLS_LOG(10, "bi_log_iterate_range");
2553 map
<string
, bufferlist
> keys
;
2554 string filter_prefix
, end_key
;
2562 if (key_iter
.empty()) {
2563 key
= BI_PREFIX_CHAR
;
2564 key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
2569 start_key
= key_iter
;
2572 if (end_marker
.empty()) {
2573 end_key
= BI_PREFIX_CHAR
;
2574 end_key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
+ 1]);
2576 end_key
= BI_PREFIX_CHAR
;
2577 end_key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
2578 end_key
.append(end_marker
);
2581 CLS_LOG(0, "bi_log_iterate_entries start_key=%s end_key=%s\n", start_key
.c_str(), end_key
.c_str());
2586 #define BI_NUM_KEYS 128
2587 int ret
= cls_cxx_map_get_vals(hctx
, start_key
, filter
, BI_NUM_KEYS
, &keys
);
2591 map
<string
, bufferlist
>::iterator iter
= keys
.begin();
2592 if (iter
== keys
.end())
2595 for (; iter
!= keys
.end(); ++iter
) {
2596 const string
& key
= iter
->first
;
2599 CLS_LOG(0, "bi_log_iterate_entries key=%s bl.length=%d\n", key
.c_str(), (int)iter
->second
.length());
2601 if (key
.compare(end_key
) > 0)
2604 ret
= bi_log_record_decode(iter
->second
, e
);
2608 if (max_entries
&& (i
>= max_entries
)) {
2615 ret
= cb(hctx
, key
, e
, param
);
2622 start_key
= iter
->first
;
2627 static int bi_log_list_cb(cls_method_context_t hctx
, const string
& key
, rgw_bi_log_entry
& info
, void *param
)
2629 list
<rgw_bi_log_entry
> *l
= (list
<rgw_bi_log_entry
> *)param
;
2634 static int bi_log_list_entries(cls_method_context_t hctx
, const string
& marker
,
2635 uint32_t max
, list
<rgw_bi_log_entry
>& entries
, bool *truncated
)
2639 int ret
= bi_log_iterate_entries(hctx
, marker
, end_marker
,
2640 key_iter
, max
, truncated
,
2641 bi_log_list_cb
, &entries
);
2645 static int rgw_bi_log_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2647 bufferlist::iterator in_iter
= in
->begin();
2649 cls_rgw_bi_log_list_op op
;
2651 ::decode(op
, in_iter
);
2652 } catch (buffer::error
& err
) {
2653 CLS_LOG(1, "ERROR: rgw_bi_log_list(): failed to decode entry\n");
2657 cls_rgw_bi_log_list_ret op_ret
;
2658 int ret
= bi_log_list_entries(hctx
, op
.marker
, op
.max
, op_ret
.entries
, &op_ret
.truncated
);
2662 ::encode(op_ret
, *out
);
2667 static int bi_log_list_trim_cb(cls_method_context_t hctx
, const string
& key
, rgw_bi_log_entry
& info
, void *param
)
2669 list
<rgw_bi_log_entry
> *entries
= (list
<rgw_bi_log_entry
> *)param
;
2671 entries
->push_back(info
);
2675 static int bi_log_remove_entry(cls_method_context_t hctx
, rgw_bi_log_entry
& entry
)
2678 key
= BI_PREFIX_CHAR
;
2679 key
.append(bucket_index_prefixes
[BI_BUCKET_LOG_INDEX
]);
2680 key
.append(entry
.id
);
2681 return cls_cxx_map_remove_key(hctx
, key
);
2684 static int bi_log_list_trim_entries(cls_method_context_t hctx
,
2685 const string
& start_marker
, const string
& end_marker
,
2686 list
<rgw_bi_log_entry
>& entries
, bool *truncated
)
2689 #define MAX_TRIM_ENTRIES 1000 /* max entries to trim in a single operation */
2690 int ret
= bi_log_iterate_entries(hctx
, start_marker
, end_marker
,
2691 key_iter
, MAX_TRIM_ENTRIES
, truncated
,
2692 bi_log_list_trim_cb
, &entries
);
2696 static int rgw_bi_log_trim(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2698 bufferlist::iterator in_iter
= in
->begin();
2700 cls_rgw_bi_log_trim_op op
;
2702 ::decode(op
, in_iter
);
2703 } catch (buffer::error
& err
) {
2704 CLS_LOG(1, "ERROR: rgw_bi_log_list(): failed to decode entry\n");
2708 cls_rgw_bi_log_list_ret op_ret
;
2709 list
<rgw_bi_log_entry
> entries
;
2710 #define MAX_TRIM_ENTRIES 1000 /* don't do more than that in a single operation */
2712 int ret
= bi_log_list_trim_entries(hctx
, op
.start_marker
, op
.end_marker
, entries
, &truncated
);
2716 if (entries
.empty())
2719 list
<rgw_bi_log_entry
>::iterator iter
;
2720 for (iter
= entries
.begin(); iter
!= entries
.end(); ++iter
) {
2721 rgw_bi_log_entry
& entry
= *iter
;
2723 ret
= bi_log_remove_entry(hctx
, entry
);
2731 static void usage_record_prefix_by_time(uint64_t epoch
, string
& key
)
2734 snprintf(buf
, sizeof(buf
), "%011llu", (long long unsigned)epoch
);
2738 static void usage_record_prefix_by_user(string
& user
, uint64_t epoch
, string
& key
)
2740 char buf
[user
.size() + 32];
2741 snprintf(buf
, sizeof(buf
), "%s_%011llu_", user
.c_str(), (long long unsigned)epoch
);
2745 static void usage_record_name_by_time(uint64_t epoch
, const string
& user
, string
& bucket
, string
& key
)
2747 char buf
[32 + user
.size() + bucket
.size()];
2748 snprintf(buf
, sizeof(buf
), "%011llu_%s_%s", (long long unsigned)epoch
, user
.c_str(), bucket
.c_str());
2752 static void usage_record_name_by_user(const string
& user
, uint64_t epoch
, string
& bucket
, string
& key
)
2754 char buf
[32 + user
.size() + bucket
.size()];
2755 snprintf(buf
, sizeof(buf
), "%s_%011llu_%s", user
.c_str(), (long long unsigned)epoch
, bucket
.c_str());
2759 static int usage_record_decode(bufferlist
& record_bl
, rgw_usage_log_entry
& e
)
2761 bufferlist::iterator kiter
= record_bl
.begin();
2764 } catch (buffer::error
& err
) {
2765 CLS_LOG(1, "ERROR: usage_record_decode(): failed to decode record_bl\n");
2772 int rgw_user_usage_log_add(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2774 CLS_LOG(10, "rgw_user_usage_log_add()");
2776 bufferlist::iterator in_iter
= in
->begin();
2777 rgw_cls_usage_log_add_op op
;
2780 ::decode(op
, in_iter
);
2781 } catch (buffer::error
& err
) {
2782 CLS_LOG(1, "ERROR: rgw_user_usage_log_add(): failed to decode request\n");
2786 rgw_usage_log_info
& info
= op
.info
;
2787 vector
<rgw_usage_log_entry
>::iterator iter
;
2789 for (iter
= info
.entries
.begin(); iter
!= info
.entries
.end(); ++iter
) {
2790 rgw_usage_log_entry
& entry
= *iter
;
2793 rgw_user
*puser
= (entry
.payer
.empty() ? &entry
.owner
: &entry
.payer
);
2795 usage_record_name_by_time(entry
.epoch
, puser
->to_str(), entry
.bucket
, key_by_time
);
2797 CLS_LOG(10, "rgw_user_usage_log_add user=%s bucket=%s\n", puser
->to_str().c_str(), entry
.bucket
.c_str());
2799 bufferlist record_bl
;
2800 int ret
= cls_cxx_map_get_val(hctx
, key_by_time
, &record_bl
);
2801 if (ret
< 0 && ret
!= -ENOENT
) {
2802 CLS_LOG(1, "ERROR: rgw_user_usage_log_add(): cls_cxx_map_read_key returned %d\n", ret
);
2806 rgw_usage_log_entry e
;
2807 ret
= usage_record_decode(record_bl
, e
);
2810 CLS_LOG(10, "rgw_user_usage_log_add aggregating existing bucket\n");
2814 bufferlist new_record_bl
;
2815 ::encode(entry
, new_record_bl
);
2816 ret
= cls_cxx_map_set_val(hctx
, key_by_time
, &new_record_bl
);
2821 usage_record_name_by_user(puser
->to_str(), entry
.epoch
, entry
.bucket
, key_by_user
);
2822 ret
= cls_cxx_map_set_val(hctx
, key_by_user
, &new_record_bl
);
2830 static int usage_iterate_range(cls_method_context_t hctx
, uint64_t start
, uint64_t end
,
2831 string
& user
, string
& key_iter
, uint32_t max_entries
, bool *truncated
,
2832 int (*cb
)(cls_method_context_t
, const string
&, rgw_usage_log_entry
&, void *),
2835 CLS_LOG(10, "usage_iterate_range");
2837 map
<string
, bufferlist
> keys
;
2839 string filter_prefix
;
2840 string start_key
, end_key
;
2841 bool by_user
= !user
.empty();
2849 usage_record_prefix_by_time(end
, end_key
);
2852 user_key
.append("_");
2855 if (key_iter
.empty()) {
2857 usage_record_prefix_by_user(user
, start
, start_key
);
2859 usage_record_prefix_by_time(start
, start_key
);
2862 start_key
= key_iter
;
2866 CLS_LOG(20, "usage_iterate_range start_key=%s", start_key
.c_str());
2867 int ret
= cls_cxx_map_get_vals(hctx
, start_key
, filter_prefix
, NUM_KEYS
, &keys
);
2872 map
<string
, bufferlist
>::iterator iter
= keys
.begin();
2873 if (iter
== keys
.end())
2876 for (; iter
!= keys
.end(); ++iter
) {
2877 const string
& key
= iter
->first
;
2878 rgw_usage_log_entry e
;
2880 if (!by_user
&& key
.compare(end_key
) >= 0) {
2881 CLS_LOG(20, "usage_iterate_range reached key=%s, done", key
.c_str());
2885 if (by_user
&& key
.compare(0, user_key
.size(), user_key
) != 0) {
2886 CLS_LOG(20, "usage_iterate_range reached key=%s, done", key
.c_str());
2890 ret
= usage_record_decode(iter
->second
, e
);
2894 if (e
.epoch
< start
)
2897 /* keys are sorted by epoch, so once we're past end we're done */
2901 ret
= cb(hctx
, key
, e
, param
);
2907 if (max_entries
&& (i
> max_entries
)) {
2908 CLS_LOG(20, "usage_iterate_range reached max_entries (%d), done", max_entries
);
2915 start_key
= iter
->first
;
2920 static int usage_log_read_cb(cls_method_context_t hctx
, const string
& key
, rgw_usage_log_entry
& entry
, void *param
)
2922 map
<rgw_user_bucket
, rgw_usage_log_entry
> *usage
= (map
<rgw_user_bucket
, rgw_usage_log_entry
> *)param
;
2924 if (!entry
.payer
.empty()) {
2925 puser
= &entry
.payer
;
2927 puser
= &entry
.owner
;
2929 rgw_user_bucket
ub(puser
->to_str(), entry
.bucket
);
2930 rgw_usage_log_entry
& le
= (*usage
)[ub
];
2931 le
.aggregate(entry
);
2936 int rgw_user_usage_log_read(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2938 CLS_LOG(10, "rgw_user_usage_log_read()");
2940 bufferlist::iterator in_iter
= in
->begin();
2941 rgw_cls_usage_log_read_op op
;
2944 ::decode(op
, in_iter
);
2945 } catch (buffer::error
& err
) {
2946 CLS_LOG(1, "ERROR: rgw_user_usage_log_read(): failed to decode request\n");
2950 rgw_cls_usage_log_read_ret ret_info
;
2951 map
<rgw_user_bucket
, rgw_usage_log_entry
> *usage
= &ret_info
.usage
;
2952 string iter
= op
.iter
;
2953 #define MAX_ENTRIES 1000
2954 uint32_t max_entries
= (op
.max_entries
? op
.max_entries
: MAX_ENTRIES
);
2955 int ret
= usage_iterate_range(hctx
, op
.start_epoch
, op
.end_epoch
, op
.owner
, iter
, max_entries
, &ret_info
.truncated
, usage_log_read_cb
, (void *)usage
);
2959 if (ret_info
.truncated
)
2960 ret_info
.next_iter
= iter
;
2962 ::encode(ret_info
, *out
);
2966 static int usage_log_trim_cb(cls_method_context_t hctx
, const string
& key
, rgw_usage_log_entry
& entry
, void *param
)
2971 string o
= entry
.owner
.to_str();
2972 usage_record_name_by_time(entry
.epoch
, o
, entry
.bucket
, key_by_time
);
2973 usage_record_name_by_user(o
, entry
.epoch
, entry
.bucket
, key_by_user
);
2975 int ret
= cls_cxx_map_remove_key(hctx
, key_by_time
);
2979 return cls_cxx_map_remove_key(hctx
, key_by_user
);
2982 int rgw_user_usage_log_trim(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
2984 CLS_LOG(10, "rgw_user_usage_log_trim()");
2986 /* only continue if object exists! */
2987 int ret
= cls_cxx_stat(hctx
, NULL
, NULL
);
2991 bufferlist::iterator in_iter
= in
->begin();
2992 rgw_cls_usage_log_trim_op op
;
2995 ::decode(op
, in_iter
);
2996 } catch (buffer::error
& err
) {
2997 CLS_LOG(1, "ERROR: rgw_user_log_usage_log_trim(): failed to decode request\n");
3002 ret
= usage_iterate_range(hctx
, op
.start_epoch
, op
.end_epoch
, op
.user
, iter
, 0, NULL
, usage_log_trim_cb
, NULL
);
3010 * We hold the garbage collection chain data under two different indexes: the first 'name' index
3011 * keeps them under a unique tag that represents the chains, and a second 'time' index keeps
3012 * them by their expiration timestamp
3014 #define GC_OBJ_NAME_INDEX 0
3015 #define GC_OBJ_TIME_INDEX 1
3017 static string gc_index_prefixes
[] = { "0_",
3020 static void prepend_index_prefix(const string
& src
, int index
, string
*dest
)
3022 *dest
= gc_index_prefixes
[index
];
3026 static int gc_omap_get(cls_method_context_t hctx
, int type
, const string
& key
, cls_rgw_gc_obj_info
*info
)
3029 prepend_index_prefix(key
, type
, &index
);
3032 int ret
= cls_cxx_map_get_val(hctx
, index
, &bl
);
3037 bufferlist::iterator iter
= bl
.begin();
3038 ::decode(*info
, iter
);
3039 } catch (buffer::error
& err
) {
3040 CLS_LOG(0, "ERROR: rgw_cls_gc_omap_get(): failed to decode index=%s\n", index
.c_str());
3046 static int gc_omap_set(cls_method_context_t hctx
, int type
, const string
& key
, const cls_rgw_gc_obj_info
*info
)
3049 ::encode(*info
, bl
);
3051 string index
= gc_index_prefixes
[type
];
3054 int ret
= cls_cxx_map_set_val(hctx
, index
, &bl
);
3061 static int gc_omap_remove(cls_method_context_t hctx
, int type
, const string
& key
)
3063 string index
= gc_index_prefixes
[type
];
3066 int ret
= cls_cxx_map_remove_key(hctx
, index
);
3073 static bool key_in_index(const string
& key
, int index_type
)
3075 const string
& prefix
= gc_index_prefixes
[index_type
];
3076 return (key
.compare(0, prefix
.size(), prefix
) == 0);
3080 static int gc_update_entry(cls_method_context_t hctx
, uint32_t expiration_secs
,
3081 cls_rgw_gc_obj_info
& info
)
3083 cls_rgw_gc_obj_info old_info
;
3084 int ret
= gc_omap_get(hctx
, GC_OBJ_NAME_INDEX
, info
.tag
, &old_info
);
3087 get_time_key(old_info
.time
, &key
);
3088 ret
= gc_omap_remove(hctx
, GC_OBJ_TIME_INDEX
, key
);
3089 if (ret
< 0 && ret
!= -ENOENT
) {
3090 CLS_LOG(0, "ERROR: failed to remove key=%s\n", key
.c_str());
3094 info
.time
= ceph::real_clock::now();
3095 info
.time
+= make_timespan(expiration_secs
);
3096 ret
= gc_omap_set(hctx
, GC_OBJ_NAME_INDEX
, info
.tag
, &info
);
3101 get_time_key(info
.time
, &key
);
3102 ret
= gc_omap_set(hctx
, GC_OBJ_TIME_INDEX
, key
, &info
);
3109 CLS_LOG(0, "ERROR: gc_set_entry error info.tag=%s, ret=%d\n", info
.tag
.c_str(), ret
);
3110 gc_omap_remove(hctx
, GC_OBJ_NAME_INDEX
, info
.tag
);
3114 static int gc_defer_entry(cls_method_context_t hctx
, const string
& tag
, uint32_t expiration_secs
)
3116 cls_rgw_gc_obj_info info
;
3117 int ret
= gc_omap_get(hctx
, GC_OBJ_NAME_INDEX
, tag
, &info
);
3122 return gc_update_entry(hctx
, expiration_secs
, info
);
3125 int gc_record_decode(bufferlist
& bl
, cls_rgw_gc_obj_info
& e
)
3127 bufferlist::iterator iter
= bl
.begin();
3130 } catch (buffer::error
& err
) {
3131 CLS_LOG(0, "ERROR: failed to decode cls_rgw_gc_obj_info");
3137 static int rgw_cls_gc_set_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3139 bufferlist::iterator in_iter
= in
->begin();
3141 cls_rgw_gc_set_entry_op op
;
3143 ::decode(op
, in_iter
);
3144 } catch (buffer::error
& err
) {
3145 CLS_LOG(1, "ERROR: rgw_cls_gc_set_entry(): failed to decode entry\n");
3149 return gc_update_entry(hctx
, op
.expiration_secs
, op
.info
);
3152 static int rgw_cls_gc_defer_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3154 bufferlist::iterator in_iter
= in
->begin();
3156 cls_rgw_gc_defer_entry_op op
;
3158 ::decode(op
, in_iter
);
3159 } catch (buffer::error
& err
) {
3160 CLS_LOG(1, "ERROR: rgw_cls_gc_defer_entry(): failed to decode entry\n");
3164 return gc_defer_entry(hctx
, op
.tag
, op
.expiration_secs
);
3167 static int gc_iterate_entries(cls_method_context_t hctx
, const string
& marker
, bool expired_only
,
3168 string
& key_iter
, uint32_t max_entries
, bool *truncated
,
3169 int (*cb
)(cls_method_context_t
, const string
&, cls_rgw_gc_obj_info
&, void *),
3172 CLS_LOG(10, "gc_iterate_range");
3174 map
<string
, bufferlist
> keys
;
3175 string filter_prefix
, end_key
;
3183 if (marker
.empty()) {
3184 prepend_index_prefix(marker
, GC_OBJ_TIME_INDEX
, &start_key
);
3190 real_time now
= ceph::real_clock::now();
3192 get_time_key(now
, &now_str
);
3193 prepend_index_prefix(now_str
, GC_OBJ_TIME_INDEX
, &end_key
);
3195 CLS_LOG(0, "gc_iterate_entries end_key=%s\n", end_key
.c_str());
3201 #define GC_NUM_KEYS 32
3202 int ret
= cls_cxx_map_get_vals(hctx
, start_key
, filter
, GC_NUM_KEYS
, &keys
);
3207 map
<string
, bufferlist
>::iterator iter
= keys
.begin();
3208 if (iter
== keys
.end())
3211 for (; iter
!= keys
.end(); ++iter
) {
3212 const string
& key
= iter
->first
;
3213 cls_rgw_gc_obj_info e
;
3215 CLS_LOG(10, "gc_iterate_entries key=%s\n", key
.c_str());
3217 if (!end_key
.empty() && key
.compare(end_key
) >= 0)
3220 if (!key_in_index(key
, GC_OBJ_TIME_INDEX
))
3223 ret
= gc_record_decode(iter
->second
, e
);
3227 if (max_entries
&& (i
>= max_entries
)) {
3231 key_iter
= iter
->first
;
3235 ret
= cb(hctx
, key
, e
, param
);
3242 start_key
= iter
->first
;
3247 static int gc_list_cb(cls_method_context_t hctx
, const string
& key
, cls_rgw_gc_obj_info
& info
, void *param
)
3249 list
<cls_rgw_gc_obj_info
> *l
= (list
<cls_rgw_gc_obj_info
> *)param
;
3254 static int gc_list_entries(cls_method_context_t hctx
, const string
& marker
,
3255 uint32_t max
, bool expired_only
,
3256 list
<cls_rgw_gc_obj_info
>& entries
, bool *truncated
, string
& next_marker
)
3258 int ret
= gc_iterate_entries(hctx
, marker
, expired_only
,
3259 next_marker
, max
, truncated
,
3260 gc_list_cb
, &entries
);
3264 static int rgw_cls_gc_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3266 bufferlist::iterator in_iter
= in
->begin();
3268 cls_rgw_gc_list_op op
;
3270 ::decode(op
, in_iter
);
3271 } catch (buffer::error
& err
) {
3272 CLS_LOG(1, "ERROR: rgw_cls_gc_list(): failed to decode entry\n");
3276 cls_rgw_gc_list_ret op_ret
;
3277 int ret
= gc_list_entries(hctx
, op
.marker
, op
.max
, op
.expired_only
,
3278 op_ret
.entries
, &op_ret
.truncated
, op_ret
.next_marker
);
3282 ::encode(op_ret
, *out
);
3287 static int gc_remove(cls_method_context_t hctx
, list
<string
>& tags
)
3289 list
<string
>::iterator iter
;
3291 for (iter
= tags
.begin(); iter
!= tags
.end(); ++iter
) {
3292 string
& tag
= *iter
;
3293 cls_rgw_gc_obj_info info
;
3294 int ret
= gc_omap_get(hctx
, GC_OBJ_NAME_INDEX
, tag
, &info
);
3295 if (ret
== -ENOENT
) {
3296 CLS_LOG(0, "couldn't find tag in name index tag=%s\n", tag
.c_str());
3304 get_time_key(info
.time
, &time_key
);
3305 ret
= gc_omap_remove(hctx
, GC_OBJ_TIME_INDEX
, time_key
);
3306 if (ret
< 0 && ret
!= -ENOENT
)
3308 if (ret
== -ENOENT
) {
3309 CLS_LOG(0, "couldn't find key in time index key=%s\n", time_key
.c_str());
3312 ret
= gc_omap_remove(hctx
, GC_OBJ_NAME_INDEX
, tag
);
3313 if (ret
< 0 && ret
!= -ENOENT
)
3320 static int rgw_cls_gc_remove(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3322 bufferlist::iterator in_iter
= in
->begin();
3324 cls_rgw_gc_remove_op op
;
3326 ::decode(op
, in_iter
);
3327 } catch (buffer::error
& err
) {
3328 CLS_LOG(1, "ERROR: rgw_cls_gc_remove(): failed to decode entry\n");
3332 return gc_remove(hctx
, op
.tags
);
3335 static int rgw_cls_lc_set_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3337 bufferlist::iterator in_iter
= in
->begin();
3339 cls_rgw_lc_set_entry_op op
;
3341 ::decode(op
, in_iter
);
3342 } catch (buffer::error
& err
) {
3343 CLS_LOG(1, "ERROR: rgw_cls_lc_set_entry(): failed to decode entry\n");
3348 ::encode(op
.entry
, bl
);
3350 int ret
= cls_cxx_map_set_val(hctx
, op
.entry
.first
, &bl
);
3354 static int rgw_cls_lc_rm_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3356 bufferlist::iterator in_iter
= in
->begin();
3358 cls_rgw_lc_rm_entry_op op
;
3360 ::decode(op
, in_iter
);
3361 } catch (buffer::error
& err
) {
3362 CLS_LOG(1, "ERROR: rgw_cls_lc_rm_entry(): failed to decode entry\n");
3367 ::encode(op
.entry
, bl
);
3369 int ret
= cls_cxx_map_remove_key(hctx
, op
.entry
.first
);
3373 static int rgw_cls_lc_get_next_entry(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3375 bufferlist::iterator in_iter
= in
->begin();
3376 cls_rgw_lc_get_next_entry_ret op_ret
;
3377 cls_rgw_lc_get_next_entry_op op
;
3379 ::decode(op
, in_iter
);
3380 } catch (buffer::error
& err
) {
3381 CLS_LOG(1, "ERROR: rgw_cls_lc_get_next_entry: failed to decode op\n");
3385 map
<string
, bufferlist
> vals
;
3386 string filter_prefix
;
3387 int ret
= cls_cxx_map_get_vals(hctx
, op
.marker
, filter_prefix
, 1, &vals
);
3390 map
<string
, bufferlist
>::iterator it
;
3391 pair
<string
, int> entry
;
3392 if (!vals
.empty()) {
3394 in_iter
= it
->second
.begin();
3396 ::decode(entry
, in_iter
);
3397 } catch (buffer::error
& err
) {
3398 CLS_LOG(1, "ERROR: rgw_cls_lc_get_next_entry(): failed to decode entry\n");
3402 op_ret
.entry
= entry
;
3403 ::encode(op_ret
, *out
);
3407 static int rgw_cls_lc_list_entries(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3409 cls_rgw_lc_list_entries_op op
;
3410 bufferlist::iterator in_iter
= in
->begin();
3412 ::decode(op
, in_iter
);
3413 } catch (buffer::error
& err
) {
3414 CLS_LOG(1, "ERROR: rgw_cls_lc_list_entries(): failed to decode op\n");
3418 cls_rgw_lc_list_entries_ret op_ret
;
3419 bufferlist::iterator iter
;
3420 map
<string
, bufferlist
> vals
;
3421 string filter_prefix
;
3422 int ret
= cls_cxx_map_get_vals(hctx
, op
.marker
, filter_prefix
, op
.max_entries
, &vals
);
3425 map
<string
, bufferlist
>::iterator it
;
3426 pair
<string
, int> entry
;
3427 for (it
= vals
.begin(); it
!= vals
.end(); ++it
) {
3428 iter
= it
->second
.begin();
3430 ::decode(entry
, iter
);
3431 } catch (buffer::error
& err
) {
3432 CLS_LOG(1, "ERROR: rgw_cls_lc_list_entries(): failed to decode entry\n");
3435 op_ret
.entries
.insert(entry
);
3437 ::encode(op_ret
, *out
);
3441 static int rgw_cls_lc_put_head(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3443 bufferlist::iterator in_iter
= in
->begin();
3445 cls_rgw_lc_put_head_op op
;
3447 ::decode(op
, in_iter
);
3448 } catch (buffer::error
& err
) {
3449 CLS_LOG(1, "ERROR: rgw_cls_lc_put_head(): failed to decode entry\n");
3454 ::encode(op
.head
, bl
);
3455 int ret
= cls_cxx_map_write_header(hctx
,&bl
);
3459 static int rgw_cls_lc_get_head(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3462 int ret
= cls_cxx_map_read_header(hctx
, &bl
);
3465 cls_rgw_lc_obj_head head
;
3466 if (bl
.length() != 0) {
3467 bufferlist::iterator iter
= bl
.begin();
3469 ::decode(head
, iter
);
3470 } catch (buffer::error
& err
) {
3471 CLS_LOG(0, "ERROR: rgw_cls_lc_get_head(): failed to decode entry %s\n",err
.what());
3475 head
.start_date
= 0;
3476 head
.marker
.clear();
3478 cls_rgw_lc_get_head_ret op_ret
;
3480 ::encode(op_ret
, *out
);
3484 static int rgw_reshard_add(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3486 bufferlist::iterator in_iter
= in
->begin();
3488 cls_rgw_reshard_add_op op
;
3490 ::decode(op
, in_iter
);
3491 } catch (buffer::error
& err
) {
3492 CLS_LOG(1, "ERROR: rgw_reshard_add: failed to decode entry\n");
3498 op
.entry
.get_key(&key
);
3501 ::encode(op
.entry
, bl
);
3502 int ret
= cls_cxx_map_set_val(hctx
, key
, &bl
);
3504 CLS_ERR("error adding reshard job for bucket %s with key %s",op
.entry
.bucket_name
.c_str(), key
.c_str());
3511 static int rgw_reshard_list(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3513 cls_rgw_reshard_list_op op
;
3514 bufferlist::iterator in_iter
= in
->begin();
3516 ::decode(op
, in_iter
);
3517 } catch (buffer::error
& err
) {
3518 CLS_LOG(1, "ERROR: rgw_cls_rehard_list(): failed to decode entry\n");
3521 cls_rgw_reshard_list_ret op_ret
;
3522 bufferlist::iterator iter
;
3523 map
<string
, bufferlist
> vals
;
3524 string filter_prefix
;
3525 #define MAX_RESHARD_LIST_ENTRIES 1000
3526 /* one extra entry for identifying truncation */
3527 int32_t max
= (op
.max
< MAX_RESHARD_LIST_ENTRIES
? op
.max
: MAX_RESHARD_LIST_ENTRIES
) + 1;
3528 int ret
= cls_cxx_map_get_vals(hctx
, op
.marker
, filter_prefix
, max
, &vals
);
3531 map
<string
, bufferlist
>::iterator it
;
3532 cls_rgw_reshard_entry entry
;
3534 for (it
= vals
.begin(); i
< (int)op
.max
&& it
!= vals
.end(); ++it
, ++i
) {
3535 iter
= it
->second
.begin();
3537 ::decode(entry
, iter
);
3538 } catch (buffer::error
& err
) {
3539 CLS_LOG(1, "ERROR: rgw_cls_rehard_list(): failed to decode entry\n");
3542 op_ret
.entries
.push_back(entry
);
3544 op_ret
.is_truncated
= op
.max
&& (vals
.size() > op
.max
);
3545 ::encode(op_ret
, *out
);
3549 static int get_reshard_entry(cls_method_context_t hctx
, const string
& key
, cls_rgw_reshard_entry
*entry
)
3552 int ret
= cls_cxx_map_get_val(hctx
, key
, &bl
);
3555 bufferlist::iterator iter
= bl
.begin();
3557 ::decode(*entry
, iter
);
3558 } catch (buffer::error
& err
) {
3559 CLS_LOG(0, "ERROR: %s : failed to decode entry %s\n", __func__
, err
.what());
3565 static int rgw_reshard_get(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3567 bufferlist::iterator in_iter
= in
->begin();
3569 cls_rgw_reshard_get_op op
;
3571 ::decode(op
, in_iter
);
3572 } catch (buffer::error
& err
) {
3573 CLS_LOG(1, "ERROR: rgw_reshard_get: failed to decode entry\n");
3578 cls_rgw_reshard_entry entry
;
3579 op
.entry
.get_key(&key
);
3580 int ret
= get_reshard_entry(hctx
, key
, &entry
);
3585 cls_rgw_reshard_get_ret op_ret
;
3586 op_ret
.entry
= entry
;
3587 ::encode(op_ret
, *out
);
3591 static int rgw_reshard_remove(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3593 bufferlist::iterator in_iter
= in
->begin();
3595 cls_rgw_reshard_remove_op op
;
3597 ::decode(op
, in_iter
);
3598 } catch (buffer::error
& err
) {
3599 CLS_LOG(1, "ERROR: rgw_cls_rehard_remove: failed to decode entry\n");
3604 cls_rgw_reshard_entry entry
;
3605 cls_rgw_reshard_entry::generate_key(op
.tenant
, op
.bucket_name
, &key
);
3606 int ret
= get_reshard_entry(hctx
, key
, &entry
);
3611 if (!op
.bucket_id
.empty() &&
3612 entry
.bucket_id
!= op
.bucket_id
) {
3616 ret
= cls_cxx_map_remove_key(hctx
, key
);
3618 CLS_LOG(0, "ERROR: failed to remove key: key=%s ret=%d", key
.c_str(), ret
);
3624 static int rgw_set_bucket_resharding(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3626 cls_rgw_set_bucket_resharding_op op
;
3628 bufferlist::iterator in_iter
= in
->begin();
3630 ::decode(op
, in_iter
);
3631 } catch (buffer::error
& err
) {
3632 CLS_LOG(1, "ERROR: cls_rgw_set_bucket_resharding: failed to decode entry\n");
3636 struct rgw_bucket_dir_header header
;
3637 int rc
= read_bucket_header(hctx
, &header
);
3639 CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__
);
3643 header
.new_instance
.set_status(op
.entry
.new_bucket_instance_id
, op
.entry
.num_shards
, op
.entry
.reshard_status
);
3645 return write_bucket_header(hctx
, &header
);
3648 static int rgw_clear_bucket_resharding(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3650 cls_rgw_set_bucket_resharding_op op
;
3652 bufferlist::iterator in_iter
= in
->begin();
3654 ::decode(op
, in_iter
);
3655 } catch (buffer::error
& err
) {
3656 CLS_LOG(1, "ERROR: cls_rgw_clear_bucket_resharding: failed to decode entry\n");
3660 struct rgw_bucket_dir_header header
;
3661 int rc
= read_bucket_header(hctx
, &header
);
3663 CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__
);
3666 header
.new_instance
.clear();
3668 return write_bucket_header(hctx
, &header
);
3671 static int rgw_guard_bucket_resharding(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3673 cls_rgw_guard_bucket_resharding_op op
;
3675 bufferlist::iterator in_iter
= in
->begin();
3677 ::decode(op
, in_iter
);
3678 } catch (buffer::error
& err
) {
3679 CLS_LOG(1, "ERROR: cls_rgw_clear_bucket_resharding: failed to decode entry\n");
3683 struct rgw_bucket_dir_header header
;
3684 int rc
= read_bucket_header(hctx
, &header
);
3686 CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__
);
3690 if (header
.resharding()) {
3697 static int rgw_get_bucket_resharding(cls_method_context_t hctx
, bufferlist
*in
, bufferlist
*out
)
3699 cls_rgw_get_bucket_resharding_op op
;
3701 bufferlist::iterator in_iter
= in
->begin();
3703 ::decode(op
, in_iter
);
3704 } catch (buffer::error
& err
) {
3705 CLS_LOG(1, "ERROR: cls_rgw_clear_bucket_resharding: failed to decode entry\n");
3709 struct rgw_bucket_dir_header header
;
3710 int rc
= read_bucket_header(hctx
, &header
);
3712 CLS_LOG(1, "ERROR: %s(): failed to read header\n", __func__
);
3716 cls_rgw_get_bucket_resharding_ret op_ret
;
3717 op_ret
.new_instance
= header
.new_instance
;
3719 ::encode(op_ret
, *out
);
3726 CLS_LOG(1, "Loaded rgw class!");
3728 cls_handle_t h_class
;
3729 cls_method_handle_t h_rgw_bucket_init_index
;
3730 cls_method_handle_t h_rgw_bucket_set_tag_timeout
;
3731 cls_method_handle_t h_rgw_bucket_list
;
3732 cls_method_handle_t h_rgw_bucket_check_index
;
3733 cls_method_handle_t h_rgw_bucket_rebuild_index
;
3734 cls_method_handle_t h_rgw_bucket_update_stats
;
3735 cls_method_handle_t h_rgw_bucket_prepare_op
;
3736 cls_method_handle_t h_rgw_bucket_complete_op
;
3737 cls_method_handle_t h_rgw_bucket_link_olh
;
3738 cls_method_handle_t h_rgw_bucket_unlink_instance_op
;
3739 cls_method_handle_t h_rgw_bucket_read_olh_log
;
3740 cls_method_handle_t h_rgw_bucket_trim_olh_log
;
3741 cls_method_handle_t h_rgw_bucket_clear_olh
;
3742 cls_method_handle_t h_rgw_obj_remove
;
3743 cls_method_handle_t h_rgw_obj_store_pg_ver
;
3744 cls_method_handle_t h_rgw_obj_check_attrs_prefix
;
3745 cls_method_handle_t h_rgw_obj_check_mtime
;
3746 cls_method_handle_t h_rgw_bi_get_op
;
3747 cls_method_handle_t h_rgw_bi_put_op
;
3748 cls_method_handle_t h_rgw_bi_list_op
;
3749 cls_method_handle_t h_rgw_bi_log_list_op
;
3750 cls_method_handle_t h_rgw_dir_suggest_changes
;
3751 cls_method_handle_t h_rgw_user_usage_log_add
;
3752 cls_method_handle_t h_rgw_user_usage_log_read
;
3753 cls_method_handle_t h_rgw_user_usage_log_trim
;
3754 cls_method_handle_t h_rgw_gc_set_entry
;
3755 cls_method_handle_t h_rgw_gc_list
;
3756 cls_method_handle_t h_rgw_gc_remove
;
3757 cls_method_handle_t h_rgw_lc_set_entry
;
3758 cls_method_handle_t h_rgw_lc_rm_entry
;
3759 cls_method_handle_t h_rgw_lc_get_next_entry
;
3760 cls_method_handle_t h_rgw_lc_put_head
;
3761 cls_method_handle_t h_rgw_lc_get_head
;
3762 cls_method_handle_t h_rgw_lc_list_entries
;
3763 cls_method_handle_t h_rgw_reshard_add
;
3764 cls_method_handle_t h_rgw_reshard_list
;
3765 cls_method_handle_t h_rgw_reshard_get
;
3766 cls_method_handle_t h_rgw_reshard_remove
;
3767 cls_method_handle_t h_rgw_set_bucket_resharding
;
3768 cls_method_handle_t h_rgw_clear_bucket_resharding
;
3769 cls_method_handle_t h_rgw_guard_bucket_resharding
;
3770 cls_method_handle_t h_rgw_get_bucket_resharding
;
3773 cls_register(RGW_CLASS
, &h_class
);
3776 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
);
3777 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
);
3778 cls_register_cxx_method(h_class
, RGW_BUCKET_LIST
, CLS_METHOD_RD
, rgw_bucket_list
, &h_rgw_bucket_list
);
3779 cls_register_cxx_method(h_class
, RGW_BUCKET_CHECK_INDEX
, CLS_METHOD_RD
, rgw_bucket_check_index
, &h_rgw_bucket_check_index
);
3780 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
);
3781 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
);
3782 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
);
3783 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
);
3784 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
);
3785 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
);
3786 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
);
3787 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
);
3788 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
);
3790 cls_register_cxx_method(h_class
, RGW_OBJ_REMOVE
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_obj_remove
, &h_rgw_obj_remove
);
3791 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
);
3792 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
);
3793 cls_register_cxx_method(h_class
, RGW_OBJ_CHECK_MTIME
, CLS_METHOD_RD
, rgw_obj_check_mtime
, &h_rgw_obj_check_mtime
);
3795 cls_register_cxx_method(h_class
, RGW_BI_GET
, CLS_METHOD_RD
, rgw_bi_get_op
, &h_rgw_bi_get_op
);
3796 cls_register_cxx_method(h_class
, RGW_BI_PUT
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_bi_put_op
, &h_rgw_bi_put_op
);
3797 cls_register_cxx_method(h_class
, RGW_BI_LIST
, CLS_METHOD_RD
, rgw_bi_list_op
, &h_rgw_bi_list_op
);
3799 cls_register_cxx_method(h_class
, RGW_BI_LOG_LIST
, CLS_METHOD_RD
, rgw_bi_log_list
, &h_rgw_bi_log_list_op
);
3800 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
);
3801 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
);
3804 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
);
3805 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
);
3806 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
);
3808 /* garbage collection */
3809 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
);
3810 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
);
3811 cls_register_cxx_method(h_class
, RGW_GC_LIST
, CLS_METHOD_RD
, rgw_cls_gc_list
, &h_rgw_gc_list
);
3812 cls_register_cxx_method(h_class
, RGW_GC_REMOVE
, CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_cls_gc_remove
, &h_rgw_gc_remove
);
3814 /* lifecycle bucket list */
3815 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
);
3816 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
);
3817 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
);
3818 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
);
3819 cls_register_cxx_method(h_class
, RGW_LC_GET_HEAD
, CLS_METHOD_RD
, rgw_cls_lc_get_head
, &h_rgw_lc_get_head
);
3820 cls_register_cxx_method(h_class
, RGW_LC_LIST_ENTRIES
, CLS_METHOD_RD
, rgw_cls_lc_list_entries
, &h_rgw_lc_list_entries
);
3821 cls_register_cxx_method(h_class
, "reshard_add", CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_reshard_add
, &h_rgw_reshard_add
);
3822 cls_register_cxx_method(h_class
, "reshard_list", CLS_METHOD_RD
, rgw_reshard_list
, &h_rgw_reshard_list
);
3823 cls_register_cxx_method(h_class
, "reshard_get", CLS_METHOD_RD
,rgw_reshard_get
, &h_rgw_reshard_get
);
3824 cls_register_cxx_method(h_class
, "reshard_remove", CLS_METHOD_RD
| CLS_METHOD_WR
, rgw_reshard_remove
, &h_rgw_reshard_remove
);
3825 cls_register_cxx_method(h_class
, "set_bucket_resharding", CLS_METHOD_RD
| CLS_METHOD_WR
,
3826 rgw_set_bucket_resharding
, &h_rgw_set_bucket_resharding
);
3827 cls_register_cxx_method(h_class
, "clear_bucket_resharding", CLS_METHOD_RD
| CLS_METHOD_WR
,
3828 rgw_clear_bucket_resharding
, &h_rgw_clear_bucket_resharding
);
3829 cls_register_cxx_method(h_class
, "guard_bucket_resharding", CLS_METHOD_RD
,
3830 rgw_guard_bucket_resharding
, &h_rgw_guard_bucket_resharding
);
3831 cls_register_cxx_method(h_class
, "get_bucket_resharding", CLS_METHOD_RD
,
3832 rgw_get_bucket_resharding
, &h_rgw_get_bucket_resharding
);