]> git.proxmox.com Git - ceph.git/blob - ceph/src/rgw/rgw_json_enc.cc
import 15.2.0 Octopus source
[ceph.git] / ceph / src / rgw / rgw_json_enc.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab ft=cpp
3
4 #include "rgw_common.h"
5 #include "rgw_rados.h"
6 #include "rgw_zone.h"
7 #include "rgw_log.h"
8 #include "rgw_acl.h"
9 #include "rgw_acl_s3.h"
10 #include "rgw_cache.h"
11 #include "rgw_bucket.h"
12 #include "rgw_keystone.h"
13 #include "rgw_basic_types.h"
14 #include "rgw_op.h"
15 #include "rgw_data_sync.h"
16 #include "rgw_sync.h"
17 #include "rgw_orphan.h"
18 #include "rgw_bucket_sync.h"
19 #include "rgw_tools.h"
20
21 #include "common/ceph_json.h"
22 #include "common/Formatter.h"
23
24 #define dout_context g_ceph_context
25 #define dout_subsys ceph_subsys_rgw
26
27 void encode_json(const char *name, const obj_version& v, Formatter *f)
28 {
29 f->open_object_section(name);
30 f->dump_string("tag", v.tag);
31 f->dump_unsigned("ver", v.ver);
32 f->close_section();
33 }
34
35 void decode_json_obj(obj_version& v, JSONObj *obj)
36 {
37 JSONDecoder::decode_json("tag", v.tag, obj);
38 JSONDecoder::decode_json("ver", v.ver, obj);
39 }
40
41 void encode_json(const char *name, const RGWUserCaps& val, Formatter *f)
42 {
43 val.dump(f, name);
44 }
45
46
47 void encode_json(const char *name, const rgw_pool& pool, Formatter *f)
48 {
49 f->dump_string(name, pool.to_str());
50 }
51
52 void decode_json_obj(rgw_pool& pool, JSONObj *obj)
53 {
54 string s;
55 decode_json_obj(s, obj);
56 pool = rgw_pool(s);
57 }
58
59 void encode_json(const char *name, const rgw_placement_rule& r, Formatter *f)
60 {
61 encode_json(name, r.to_str(), f);
62 }
63
64 void decode_json_obj(rgw_placement_rule& v, JSONObj *obj)
65 {
66 string s;
67 decode_json_obj(s, obj);
68 v.from_str(s);
69 }
70
71 void RGWOLHInfo::dump(Formatter *f) const
72 {
73 encode_json("target", target, f);
74 }
75
76 void RGWOLHPendingInfo::dump(Formatter *f) const
77 {
78 utime_t ut(time);
79 encode_json("time", ut, f);
80 }
81
82 void RGWObjManifestPart::dump(Formatter *f) const
83 {
84 f->open_object_section("loc");
85 loc.dump(f);
86 f->close_section();
87 f->dump_unsigned("loc_ofs", loc_ofs);
88 f->dump_unsigned("size", size);
89 }
90
91 void RGWObjManifestRule::dump(Formatter *f) const
92 {
93 encode_json("start_part_num", start_part_num, f);
94 encode_json("start_ofs", start_ofs, f);
95 encode_json("part_size", part_size, f);
96 encode_json("stripe_max_size", stripe_max_size, f);
97 encode_json("override_prefix", override_prefix, f);
98 }
99
100 void rgw_bucket_placement::dump(Formatter *f) const
101 {
102 encode_json("bucket", bucket, f);
103 encode_json("placement_rule", placement_rule, f);
104 }
105
106 void rgw_obj_select::dump(Formatter *f) const
107 {
108 f->dump_string("placement_rule", placement_rule.to_str());
109 f->dump_object("obj", obj);
110 f->dump_object("raw_obj", raw_obj);
111 f->dump_bool("is_raw", is_raw);
112 }
113
114 void RGWObjManifest::obj_iterator::dump(Formatter *f) const
115 {
116 f->dump_unsigned("part_ofs", part_ofs);
117 f->dump_unsigned("stripe_ofs", stripe_ofs);
118 f->dump_unsigned("ofs", ofs);
119 f->dump_unsigned("stripe_size", stripe_size);
120 f->dump_int("cur_part_id", cur_part_id);
121 f->dump_int("cur_stripe", cur_stripe);
122 f->dump_string("cur_override_prefix", cur_override_prefix);
123 f->dump_object("location", location);
124 }
125
126 void RGWObjManifest::dump(Formatter *f) const
127 {
128 map<uint64_t, RGWObjManifestPart>::const_iterator iter = objs.begin();
129 f->open_array_section("objs");
130 for (; iter != objs.end(); ++iter) {
131 f->dump_unsigned("ofs", iter->first);
132 f->open_object_section("part");
133 iter->second.dump(f);
134 f->close_section();
135 }
136 f->close_section();
137 f->dump_unsigned("obj_size", obj_size);
138 ::encode_json("explicit_objs", explicit_objs, f);
139 ::encode_json("head_size", head_size, f);
140 ::encode_json("max_head_size", max_head_size, f);
141 ::encode_json("prefix", prefix, f);
142 ::encode_json("rules", rules, f);
143 ::encode_json("tail_instance", tail_instance, f);
144 ::encode_json("tail_placement", tail_placement, f);
145
146 f->dump_object("begin_iter", begin_iter);
147 f->dump_object("end_iter", end_iter);
148 }
149
150 void rgw_log_entry::dump(Formatter *f) const
151 {
152 f->dump_string("object_owner", object_owner.to_str());
153 f->dump_string("bucket_owner", bucket_owner.to_str());
154 f->dump_string("bucket", bucket);
155 f->dump_stream("time") << time;
156 f->dump_string("remote_addr", remote_addr);
157 f->dump_string("user", user);
158 stringstream s;
159 s << obj;
160 f->dump_string("obj", s.str());
161 f->dump_string("op", op);
162 f->dump_string("uri", uri);
163 f->dump_string("http_status", http_status);
164 f->dump_string("error_code", error_code);
165 f->dump_unsigned("bytes_sent", bytes_sent);
166 f->dump_unsigned("bytes_received", bytes_received);
167 f->dump_unsigned("obj_size", obj_size);
168 f->dump_stream("total_time") << total_time;
169 f->dump_string("user_agent", user_agent);
170 f->dump_string("referrer", referrer);
171 f->dump_string("bucket_id", bucket_id);
172 f->dump_string("trans_id", trans_id);
173 }
174
175 void ACLPermission::dump(Formatter *f) const
176 {
177 f->dump_int("flags", flags);
178 }
179
180 void ACLGranteeType::dump(Formatter *f) const
181 {
182 f->dump_unsigned("type", type);
183 }
184
185 void ACLGrant::dump(Formatter *f) const
186 {
187 f->open_object_section("type");
188 type.dump(f);
189 f->close_section();
190
191 f->dump_string("id", id.to_str());
192 f->dump_string("email", email);
193
194 f->open_object_section("permission");
195 permission.dump(f);
196 f->close_section();
197
198 f->dump_string("name", name);
199 f->dump_int("group", (int)group);
200 f->dump_string("url_spec", url_spec);
201 }
202
203 void RGWAccessControlList::dump(Formatter *f) const
204 {
205 map<string, int>::const_iterator acl_user_iter = acl_user_map.begin();
206 f->open_array_section("acl_user_map");
207 for (; acl_user_iter != acl_user_map.end(); ++acl_user_iter) {
208 f->open_object_section("entry");
209 f->dump_string("user", acl_user_iter->first);
210 f->dump_int("acl", acl_user_iter->second);
211 f->close_section();
212 }
213 f->close_section();
214
215 map<uint32_t, int>::const_iterator acl_group_iter = acl_group_map.begin();
216 f->open_array_section("acl_group_map");
217 for (; acl_group_iter != acl_group_map.end(); ++acl_group_iter) {
218 f->open_object_section("entry");
219 f->dump_unsigned("group", acl_group_iter->first);
220 f->dump_int("acl", acl_group_iter->second);
221 f->close_section();
222 }
223 f->close_section();
224
225 multimap<string, ACLGrant>::const_iterator giter = grant_map.begin();
226 f->open_array_section("grant_map");
227 for (; giter != grant_map.end(); ++giter) {
228 f->open_object_section("entry");
229 f->dump_string("id", giter->first);
230 f->open_object_section("grant");
231 giter->second.dump(f);
232 f->close_section();
233 f->close_section();
234 }
235 f->close_section();
236 }
237
238 void ACLOwner::dump(Formatter *f) const
239 {
240 encode_json("id", id.to_str(), f);
241 encode_json("display_name", display_name, f);
242 }
243
244 void ACLOwner::decode_json(JSONObj *obj) {
245 string id_str;
246 JSONDecoder::decode_json("id", id_str, obj);
247 id.from_str(id_str);
248 JSONDecoder::decode_json("display_name", display_name, obj);
249 }
250
251 void RGWAccessControlPolicy::dump(Formatter *f) const
252 {
253 encode_json("acl", acl, f);
254 encode_json("owner", owner, f);
255 }
256
257 void ObjectMetaInfo::dump(Formatter *f) const
258 {
259 encode_json("size", size, f);
260 encode_json("mtime", utime_t(mtime), f);
261 }
262
263 void ObjectCacheInfo::dump(Formatter *f) const
264 {
265 encode_json("status", status, f);
266 encode_json("flags", flags, f);
267 encode_json("data", data, f);
268 encode_json_map("xattrs", "name", "value", "length", xattrs, f);
269 encode_json_map("rm_xattrs", "name", "value", "length", rm_xattrs, f);
270 encode_json("meta", meta, f);
271
272 }
273
274 void RGWCacheNotifyInfo::dump(Formatter *f) const
275 {
276 encode_json("op", op, f);
277 encode_json("obj", obj, f);
278 encode_json("obj_info", obj_info, f);
279 encode_json("ofs", ofs, f);
280 encode_json("ns", ns, f);
281 }
282
283 void RGWAccessKey::dump(Formatter *f) const
284 {
285 encode_json("access_key", id, f);
286 encode_json("secret_key", key, f);
287 encode_json("subuser", subuser, f);
288 }
289
290 void RGWAccessKey::dump_plain(Formatter *f) const
291 {
292 encode_json("access_key", id, f);
293 encode_json("secret_key", key, f);
294 }
295
296 void encode_json_plain(const char *name, const RGWAccessKey& val, Formatter *f)
297 {
298 f->open_object_section(name);
299 val.dump_plain(f);
300 f->close_section();
301 }
302
303 void RGWAccessKey::dump(Formatter *f, const string& user, bool swift) const
304 {
305 string u = user;
306 if (!subuser.empty()) {
307 u.append(":");
308 u.append(subuser);
309 }
310 encode_json("user", u, f);
311 if (!swift) {
312 encode_json("access_key", id, f);
313 }
314 encode_json("secret_key", key, f);
315 }
316
317 void RGWAccessKey::decode_json(JSONObj *obj) {
318 JSONDecoder::decode_json("access_key", id, obj, true);
319 JSONDecoder::decode_json("secret_key", key, obj, true);
320 if (!JSONDecoder::decode_json("subuser", subuser, obj)) {
321 string user;
322 JSONDecoder::decode_json("user", user, obj);
323 int pos = user.find(':');
324 if (pos >= 0) {
325 subuser = user.substr(pos + 1);
326 }
327 }
328 }
329
330 void RGWAccessKey::decode_json(JSONObj *obj, bool swift) {
331 if (!swift) {
332 decode_json(obj);
333 return;
334 }
335
336 if (!JSONDecoder::decode_json("subuser", subuser, obj)) {
337 JSONDecoder::decode_json("user", id, obj, true);
338 int pos = id.find(':');
339 if (pos >= 0) {
340 subuser = id.substr(pos + 1);
341 }
342 }
343 JSONDecoder::decode_json("secret_key", key, obj, true);
344 }
345
346 struct rgw_flags_desc {
347 uint32_t mask;
348 const char *str;
349 };
350
351 static struct rgw_flags_desc rgw_perms[] = {
352 { RGW_PERM_FULL_CONTROL, "full-control" },
353 { RGW_PERM_READ | RGW_PERM_WRITE, "read-write" },
354 { RGW_PERM_READ, "read" },
355 { RGW_PERM_WRITE, "write" },
356 { RGW_PERM_READ_ACP, "read-acp" },
357 { RGW_PERM_WRITE_ACP, "write-acp" },
358 { 0, NULL }
359 };
360
361 template <class T>
362 static void mask_to_str(T *mask_list, uint32_t mask, char *buf, int len)
363 {
364 const char *sep = "";
365 int pos = 0;
366 if (!mask) {
367 snprintf(buf, len, "<none>");
368 return;
369 }
370 while (mask) {
371 uint32_t orig_mask = mask;
372 for (int i = 0; mask_list[i].mask; i++) {
373 T *desc = &mask_list[i];
374 if ((mask & desc->mask) == desc->mask) {
375 pos += snprintf(buf + pos, len - pos, "%s%s", sep, desc->str);
376 if (pos == len)
377 return;
378 sep = ", ";
379 mask &= ~desc->mask;
380 if (!mask)
381 return;
382 }
383 }
384 if (mask == orig_mask) // no change
385 break;
386 }
387 }
388
389 static void perm_to_str(uint32_t mask, char *buf, int len)
390 {
391 return mask_to_str(rgw_perms, mask, buf, len);
392 }
393
394 static struct rgw_flags_desc op_type_flags[] = {
395 { RGW_OP_TYPE_READ, "read" },
396 { RGW_OP_TYPE_WRITE, "write" },
397 { RGW_OP_TYPE_DELETE, "delete" },
398 { 0, NULL }
399 };
400
401 extern void op_type_to_str(uint32_t mask, char *buf, int len)
402 {
403 return mask_to_str(op_type_flags, mask, buf, len);
404 }
405
406 void RGWSubUser::dump(Formatter *f) const
407 {
408 encode_json("id", name, f);
409 char buf[256];
410 perm_to_str(perm_mask, buf, sizeof(buf));
411 encode_json("permissions", (const char *)buf, f);
412 }
413
414 void RGWSubUser::dump(Formatter *f, const string& user) const
415 {
416 string s = user;
417 s.append(":");
418 s.append(name);
419 encode_json("id", s, f);
420 char buf[256];
421 perm_to_str(perm_mask, buf, sizeof(buf));
422 encode_json("permissions", (const char *)buf, f);
423 }
424
425 static uint32_t str_to_perm(const string& s)
426 {
427 if (s.compare("read") == 0)
428 return RGW_PERM_READ;
429 else if (s.compare("write") == 0)
430 return RGW_PERM_WRITE;
431 else if (s.compare("read-write") == 0)
432 return RGW_PERM_READ | RGW_PERM_WRITE;
433 else if (s.compare("full-control") == 0)
434 return RGW_PERM_FULL_CONTROL;
435 return 0;
436 }
437
438 void RGWSubUser::decode_json(JSONObj *obj)
439 {
440 string uid;
441 JSONDecoder::decode_json("id", uid, obj);
442 int pos = uid.find(':');
443 if (pos >= 0)
444 name = uid.substr(pos + 1);
445 string perm_str;
446 JSONDecoder::decode_json("permissions", perm_str, obj);
447 perm_mask = str_to_perm(perm_str);
448 }
449
450 static void user_info_dump_subuser(const char *name, const RGWSubUser& subuser, Formatter *f, void *parent)
451 {
452 RGWUserInfo *info = static_cast<RGWUserInfo *>(parent);
453 subuser.dump(f, info->user_id.to_str());
454 }
455
456 static void user_info_dump_key(const char *name, const RGWAccessKey& key, Formatter *f, void *parent)
457 {
458 RGWUserInfo *info = static_cast<RGWUserInfo *>(parent);
459 key.dump(f, info->user_id.to_str(), false);
460 }
461
462 static void user_info_dump_swift_key(const char *name, const RGWAccessKey& key, Formatter *f, void *parent)
463 {
464 RGWUserInfo *info = static_cast<RGWUserInfo *>(parent);
465 key.dump(f, info->user_id.to_str(), true);
466 }
467
468 void RGWUserInfo::dump(Formatter *f) const
469 {
470
471 encode_json("user_id", user_id.to_str(), f);
472 encode_json("display_name", display_name, f);
473 encode_json("email", user_email, f);
474 encode_json("suspended", (int)suspended, f);
475 encode_json("max_buckets", (int)max_buckets, f);
476
477 encode_json_map("subusers", NULL, "subuser", NULL, user_info_dump_subuser,(void *)this, subusers, f);
478 encode_json_map("keys", NULL, "key", NULL, user_info_dump_key,(void *)this, access_keys, f);
479 encode_json_map("swift_keys", NULL, "key", NULL, user_info_dump_swift_key,(void *)this, swift_keys, f);
480
481 encode_json("caps", caps, f);
482
483 char buf[256];
484 op_type_to_str(op_mask, buf, sizeof(buf));
485 encode_json("op_mask", (const char *)buf, f);
486
487 if (system) { /* no need to show it for every user */
488 encode_json("system", (bool)system, f);
489 }
490 if (admin) {
491 encode_json("admin", (bool)admin, f);
492 }
493 encode_json("default_placement", default_placement.name, f);
494 encode_json("default_storage_class", default_placement.storage_class, f);
495 encode_json("placement_tags", placement_tags, f);
496 encode_json("bucket_quota", bucket_quota, f);
497 encode_json("user_quota", user_quota, f);
498 encode_json("temp_url_keys", temp_url_keys, f);
499
500 string user_source_type;
501 switch ((RGWIdentityType)type) {
502 case TYPE_RGW:
503 user_source_type = "rgw";
504 break;
505 case TYPE_KEYSTONE:
506 user_source_type = "keystone";
507 break;
508 case TYPE_LDAP:
509 user_source_type = "ldap";
510 break;
511 case TYPE_NONE:
512 user_source_type = "none";
513 break;
514 default:
515 user_source_type = "none";
516 break;
517 }
518 encode_json("type", user_source_type, f);
519 encode_json("mfa_ids", mfa_ids, f);
520 }
521
522
523 static void decode_access_keys(map<string, RGWAccessKey>& m, JSONObj *o)
524 {
525 RGWAccessKey k;
526 k.decode_json(o);
527 m[k.id] = k;
528 }
529
530 static void decode_swift_keys(map<string, RGWAccessKey>& m, JSONObj *o)
531 {
532 RGWAccessKey k;
533 k.decode_json(o, true);
534 m[k.id] = k;
535 }
536
537 static void decode_subusers(map<string, RGWSubUser>& m, JSONObj *o)
538 {
539 RGWSubUser u;
540 u.decode_json(o);
541 m[u.name] = u;
542 }
543
544 void RGWUserInfo::decode_json(JSONObj *obj)
545 {
546 string uid;
547
548 JSONDecoder::decode_json("user_id", uid, obj, true);
549 user_id.from_str(uid);
550
551 JSONDecoder::decode_json("display_name", display_name, obj);
552 JSONDecoder::decode_json("email", user_email, obj);
553 bool susp = false;
554 JSONDecoder::decode_json("suspended", susp, obj);
555 suspended = (__u8)susp;
556 JSONDecoder::decode_json("max_buckets", max_buckets, obj);
557
558 JSONDecoder::decode_json("keys", access_keys, decode_access_keys, obj);
559 JSONDecoder::decode_json("swift_keys", swift_keys, decode_swift_keys, obj);
560 JSONDecoder::decode_json("subusers", subusers, decode_subusers, obj);
561
562 JSONDecoder::decode_json("caps", caps, obj);
563
564 string mask_str;
565 JSONDecoder::decode_json("op_mask", mask_str, obj);
566 rgw_parse_op_type_list(mask_str, &op_mask);
567
568 bool sys = false;
569 JSONDecoder::decode_json("system", sys, obj);
570 system = (__u8)sys;
571 bool ad = false;
572 JSONDecoder::decode_json("admin", ad, obj);
573 admin = (__u8)ad;
574 JSONDecoder::decode_json("default_placement", default_placement.name, obj);
575 JSONDecoder::decode_json("default_storage_class", default_placement.storage_class, obj);
576 JSONDecoder::decode_json("placement_tags", placement_tags, obj);
577 JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
578 JSONDecoder::decode_json("user_quota", user_quota, obj);
579 JSONDecoder::decode_json("temp_url_keys", temp_url_keys, obj);
580
581 string user_source_type;
582 JSONDecoder::decode_json("type", user_source_type, obj);
583 if (user_source_type == "rgw") {
584 type = TYPE_RGW;
585 } else if (user_source_type == "keystone") {
586 type = TYPE_KEYSTONE;
587 } else if (user_source_type == "ldap") {
588 type = TYPE_LDAP;
589 } else if (user_source_type == "none") {
590 type = TYPE_NONE;
591 }
592 JSONDecoder::decode_json("mfa_ids", mfa_ids, obj);
593 }
594
595 void RGWQuotaInfo::dump(Formatter *f) const
596 {
597 f->dump_bool("enabled", enabled);
598 f->dump_bool("check_on_raw", check_on_raw);
599
600 f->dump_int("max_size", max_size);
601 f->dump_int("max_size_kb", rgw_rounded_kb(max_size));
602 f->dump_int("max_objects", max_objects);
603 }
604
605 void RGWQuotaInfo::decode_json(JSONObj *obj)
606 {
607 if (false == JSONDecoder::decode_json("max_size", max_size, obj)) {
608 /* We're parsing an older version of the struct. */
609 int64_t max_size_kb = 0;
610
611 JSONDecoder::decode_json("max_size_kb", max_size_kb, obj);
612 max_size = max_size_kb * 1024;
613 }
614 JSONDecoder::decode_json("max_objects", max_objects, obj);
615
616 JSONDecoder::decode_json("check_on_raw", check_on_raw, obj);
617 JSONDecoder::decode_json("enabled", enabled, obj);
618 }
619
620 void rgw_data_placement_target::dump(Formatter *f) const
621 {
622 encode_json("data_pool", data_pool, f);
623 encode_json("data_extra_pool", data_extra_pool, f);
624 encode_json("index_pool", index_pool, f);
625 }
626
627 void rgw_data_placement_target::decode_json(JSONObj *obj) {
628 JSONDecoder::decode_json("data_pool", data_pool, obj);
629 JSONDecoder::decode_json("data_extra_pool", data_extra_pool, obj);
630 JSONDecoder::decode_json("index_pool", index_pool, obj);
631 }
632
633 void rgw_bucket::dump(Formatter *f) const
634 {
635 encode_json("name", name, f);
636 encode_json("marker", marker, f);
637 encode_json("bucket_id", bucket_id, f);
638 encode_json("tenant", tenant, f);
639 encode_json("explicit_placement", explicit_placement, f);
640 }
641
642 void rgw_bucket::decode_json(JSONObj *obj) {
643 JSONDecoder::decode_json("name", name, obj);
644 JSONDecoder::decode_json("marker", marker, obj);
645 JSONDecoder::decode_json("bucket_id", bucket_id, obj);
646 JSONDecoder::decode_json("tenant", tenant, obj);
647 JSONDecoder::decode_json("explicit_placement", explicit_placement, obj);
648 if (explicit_placement.data_pool.empty()) {
649 /* decoding old format */
650 JSONDecoder::decode_json("pool", explicit_placement.data_pool, obj);
651 JSONDecoder::decode_json("data_extra_pool", explicit_placement.data_extra_pool, obj);
652 JSONDecoder::decode_json("index_pool", explicit_placement.index_pool, obj);
653 }
654 }
655
656 void RGWBucketEntryPoint::dump(Formatter *f) const
657 {
658 encode_json("bucket", bucket, f);
659 encode_json("owner", owner, f);
660 utime_t ut(creation_time);
661 encode_json("creation_time", ut, f);
662 encode_json("linked", linked, f);
663 encode_json("has_bucket_info", has_bucket_info, f);
664 if (has_bucket_info) {
665 encode_json("old_bucket_info", old_bucket_info, f);
666 }
667 }
668
669 void RGWBucketEntryPoint::decode_json(JSONObj *obj) {
670 JSONDecoder::decode_json("bucket", bucket, obj);
671 JSONDecoder::decode_json("owner", owner, obj);
672 utime_t ut;
673 JSONDecoder::decode_json("creation_time", ut, obj);
674 creation_time = ut.to_real_time();
675 JSONDecoder::decode_json("linked", linked, obj);
676 JSONDecoder::decode_json("has_bucket_info", has_bucket_info, obj);
677 if (has_bucket_info) {
678 JSONDecoder::decode_json("old_bucket_info", old_bucket_info, obj);
679 }
680 }
681
682 void RGWStorageStats::dump(Formatter *f) const
683 {
684 encode_json("size", size, f);
685 encode_json("size_actual", size_rounded, f);
686 encode_json("size_utilized", size_utilized, f);
687 encode_json("size_kb", rgw_rounded_kb(size), f);
688 encode_json("size_kb_actual", rgw_rounded_kb(size_rounded), f);
689 encode_json("size_kb_utilized", rgw_rounded_kb(size_utilized), f);
690 encode_json("num_objects", num_objects, f);
691 }
692
693 void RGWRedirectInfo::dump(Formatter *f) const
694 {
695 encode_json("protocol", protocol, f);
696 encode_json("hostname", hostname, f);
697 encode_json("http_redirect_code", (int)http_redirect_code, f);
698 }
699
700 void RGWRedirectInfo::decode_json(JSONObj *obj) {
701 JSONDecoder::decode_json("protocol", protocol, obj);
702 JSONDecoder::decode_json("hostname", hostname, obj);
703 int code;
704 JSONDecoder::decode_json("http_redirect_code", code, obj);
705 http_redirect_code = code;
706 }
707
708 void RGWBWRedirectInfo::dump(Formatter *f) const
709 {
710 encode_json("redirect", redirect, f);
711 encode_json("replace_key_prefix_with", replace_key_prefix_with, f);
712 encode_json("replace_key_with", replace_key_with, f);
713 }
714
715 void RGWBWRedirectInfo::decode_json(JSONObj *obj) {
716 JSONDecoder::decode_json("redirect", redirect, obj);
717 JSONDecoder::decode_json("replace_key_prefix_with", replace_key_prefix_with, obj);
718 JSONDecoder::decode_json("replace_key_with", replace_key_with, obj);
719 }
720
721 void RGWBWRoutingRuleCondition::dump(Formatter *f) const
722 {
723 encode_json("key_prefix_equals", key_prefix_equals, f);
724 encode_json("http_error_code_returned_equals", (int)http_error_code_returned_equals, f);
725 }
726
727 void RGWBWRoutingRuleCondition::decode_json(JSONObj *obj) {
728 JSONDecoder::decode_json("key_prefix_equals", key_prefix_equals, obj);
729 int code;
730 JSONDecoder::decode_json("http_error_code_returned_equals", code, obj);
731 http_error_code_returned_equals = code;
732 }
733
734 void RGWBWRoutingRule::dump(Formatter *f) const
735 {
736 encode_json("condition", condition, f);
737 encode_json("redirect_info", redirect_info, f);
738 }
739
740 void RGWBWRoutingRule::decode_json(JSONObj *obj) {
741 JSONDecoder::decode_json("condition", condition, obj);
742 JSONDecoder::decode_json("redirect_info", redirect_info, obj);
743 }
744
745 void RGWBWRoutingRules::dump(Formatter *f) const
746 {
747 encode_json("rules", rules, f);
748 }
749
750 void RGWBWRoutingRules::decode_json(JSONObj *obj) {
751 JSONDecoder::decode_json("rules", rules, obj);
752 }
753
754 void RGWBucketWebsiteConf::dump(Formatter *f) const
755 {
756 if (!redirect_all.hostname.empty()) {
757 encode_json("redirect_all", redirect_all, f);
758 } else {
759 encode_json("index_doc_suffix", index_doc_suffix, f);
760 encode_json("error_doc", error_doc, f);
761 encode_json("routing_rules", routing_rules, f);
762 }
763 }
764
765 void RGWBucketWebsiteConf::decode_json(JSONObj *obj) {
766 JSONDecoder::decode_json("redirect_all", redirect_all, obj);
767 JSONDecoder::decode_json("index_doc_suffix", index_doc_suffix, obj);
768 JSONDecoder::decode_json("error_doc", error_doc, obj);
769 JSONDecoder::decode_json("routing_rules", routing_rules, obj);
770 }
771
772 void RGWBucketInfo::dump(Formatter *f) const
773 {
774 encode_json("bucket", bucket, f);
775 utime_t ut(creation_time);
776 encode_json("creation_time", ut, f);
777 encode_json("owner", owner.to_str(), f);
778 encode_json("flags", flags, f);
779 encode_json("zonegroup", zonegroup, f);
780 encode_json("placement_rule", placement_rule, f);
781 encode_json("has_instance_obj", has_instance_obj, f);
782 encode_json("quota", quota, f);
783 encode_json("num_shards", num_shards, f);
784 encode_json("bi_shard_hash_type", (uint32_t)bucket_index_shard_hash_type, f);
785 encode_json("requester_pays", requester_pays, f);
786 encode_json("has_website", has_website, f);
787 if (has_website) {
788 encode_json("website_conf", website_conf, f);
789 }
790 encode_json("swift_versioning", swift_versioning, f);
791 encode_json("swift_ver_location", swift_ver_location, f);
792 encode_json("index_type", (uint32_t)index_type, f);
793 encode_json("mdsearch_config", mdsearch_config, f);
794 encode_json("reshard_status", (int)reshard_status, f);
795 encode_json("new_bucket_instance_id", new_bucket_instance_id, f);
796 if (!empty_sync_policy()) {
797 encode_json("sync_policy", *sync_policy, f);
798 }
799 }
800
801 void RGWBucketInfo::decode_json(JSONObj *obj) {
802 JSONDecoder::decode_json("bucket", bucket, obj);
803 utime_t ut;
804 JSONDecoder::decode_json("creation_time", ut, obj);
805 creation_time = ut.to_real_time();
806 JSONDecoder::decode_json("owner", owner, obj);
807 JSONDecoder::decode_json("flags", flags, obj);
808 JSONDecoder::decode_json("zonegroup", zonegroup, obj);
809 /* backward compatability with region */
810 if (zonegroup.empty()) {
811 JSONDecoder::decode_json("region", zonegroup, obj);
812 }
813 string pr;
814 JSONDecoder::decode_json("placement_rule", pr, obj);
815 placement_rule.from_str(pr);
816 JSONDecoder::decode_json("has_instance_obj", has_instance_obj, obj);
817 JSONDecoder::decode_json("quota", quota, obj);
818 JSONDecoder::decode_json("num_shards", num_shards, obj);
819 uint32_t hash_type;
820 JSONDecoder::decode_json("bi_shard_hash_type", hash_type, obj);
821 bucket_index_shard_hash_type = (uint8_t)hash_type;
822 JSONDecoder::decode_json("requester_pays", requester_pays, obj);
823 JSONDecoder::decode_json("has_website", has_website, obj);
824 if (has_website) {
825 JSONDecoder::decode_json("website_conf", website_conf, obj);
826 }
827 JSONDecoder::decode_json("swift_versioning", swift_versioning, obj);
828 JSONDecoder::decode_json("swift_ver_location", swift_ver_location, obj);
829 uint32_t it;
830 JSONDecoder::decode_json("index_type", it, obj);
831 index_type = (RGWBucketIndexType)it;
832 JSONDecoder::decode_json("mdsearch_config", mdsearch_config, obj);
833 int rs;
834 JSONDecoder::decode_json("reshard_status", rs, obj);
835 reshard_status = (cls_rgw_reshard_status)rs;
836
837 rgw_sync_policy_info sp;
838 JSONDecoder::decode_json("sync_policy", sp, obj);
839 if (!sp.empty()) {
840 set_sync_policy(std::move(sp));
841 }
842 }
843
844 void rgw_sync_directional_rule::dump(Formatter *f) const
845 {
846 encode_json("source_zone", source_zone, f);
847 encode_json("dest_zone", dest_zone, f);
848 }
849
850 void rgw_sync_directional_rule::decode_json(JSONObj *obj)
851 {
852 JSONDecoder::decode_json("source_zone", source_zone, obj);
853 JSONDecoder::decode_json("dest_zone", dest_zone, obj);
854 }
855
856 void rgw_sync_symmetric_group::dump(Formatter *f) const
857 {
858 encode_json("id", id, f);
859 encode_json("zones", zones, f);
860 }
861
862 void rgw_sync_symmetric_group::decode_json(JSONObj *obj)
863 {
864 JSONDecoder::decode_json("id", id, obj);
865 JSONDecoder::decode_json("zones", zones, obj);
866 }
867
868 void rgw_sync_bucket_entity::dump(Formatter *f) const
869 {
870 encode_json("zone", zone, f);
871 encode_json("bucket", bucket_key(), f);
872 }
873
874 void rgw_sync_bucket_entity::decode_json(JSONObj *obj)
875 {
876 JSONDecoder::decode_json("zone", zone, obj);
877 string s;
878 if (JSONDecoder::decode_json("bucket", s, obj)) {
879 rgw_bucket b;
880 int ret = rgw_bucket_parse_bucket_key(nullptr, s, &b, nullptr);
881 if (ret >= 0) {
882 bucket = b;
883 } else {
884 bucket.reset();
885 }
886 }
887 }
888
889 void rgw_sync_pipe_filter_tag::dump(Formatter *f) const
890 {
891 encode_json("key", key, f);
892 encode_json("value", value, f);
893 }
894
895 void rgw_sync_pipe_filter_tag::decode_json(JSONObj *obj)
896 {
897 JSONDecoder::decode_json("key", key, obj);
898 JSONDecoder::decode_json("value", value, obj);
899 }
900
901 void rgw_sync_pipe_filter::dump(Formatter *f) const
902 {
903 encode_json("prefix", prefix, f);
904 encode_json("tags", tags, f);
905 }
906
907 void rgw_sync_pipe_filter::decode_json(JSONObj *obj)
908 {
909 JSONDecoder::decode_json("prefix", prefix, obj);
910 JSONDecoder::decode_json("tags", tags, obj);
911 }
912
913 void rgw_sync_pipe_acl_translation::dump(Formatter *f) const
914 {
915 encode_json("owner", owner, f);
916 }
917
918 void rgw_sync_pipe_acl_translation::decode_json(JSONObj *obj)
919 {
920 JSONDecoder::decode_json("owner", owner, obj);
921 }
922
923 void rgw_sync_pipe_source_params::dump(Formatter *f) const
924 {
925 encode_json("filter", filter, f);
926 }
927
928 void rgw_sync_pipe_source_params::decode_json(JSONObj *obj)
929 {
930 JSONDecoder::decode_json("filter", filter, obj);
931 }
932
933 void rgw_sync_pipe_dest_params::dump(Formatter *f) const
934 {
935 encode_json("acl_translation", acl_translation, f);
936 encode_json("storage_class", storage_class, f);
937 }
938
939 void rgw_sync_pipe_dest_params::decode_json(JSONObj *obj)
940 {
941 JSONDecoder::decode_json("acl_translation", acl_translation, obj);
942 JSONDecoder::decode_json("storage_class", storage_class, obj);
943 }
944
945 void rgw_sync_pipe_params::dump(Formatter *f) const
946 {
947 encode_json("source", source, f);
948 encode_json("dest", dest, f);
949 encode_json("priority", priority, f);
950 string s;
951 switch (mode) {
952 case MODE_SYSTEM:
953 s = "system";
954 break;
955 default:
956 s = "user";
957 }
958 encode_json("mode", s, f);
959 encode_json("user", user, f);
960 }
961
962 void rgw_sync_pipe_params::decode_json(JSONObj *obj)
963 {
964 JSONDecoder::decode_json("source", source, obj);
965 JSONDecoder::decode_json("dest", dest, obj);
966 JSONDecoder::decode_json("priority", priority, obj);
967 string s;
968 JSONDecoder::decode_json("mode", s, obj);
969 if (s == "system") {
970 mode = MODE_SYSTEM;
971 } else {
972 mode = MODE_USER;
973 }
974 JSONDecoder::decode_json("user", user, obj);
975 }
976
977
978 void rgw_sync_bucket_entities::dump(Formatter *f) const
979 {
980 encode_json("bucket", rgw_sync_bucket_entities::bucket_key(bucket), f);
981 if (zones) {
982 encode_json("zones", zones, f);
983 } else if (all_zones) {
984 set<string> z = { "*" };
985 encode_json("zones", z, f);
986 }
987 }
988
989 void rgw_sync_bucket_entities::decode_json(JSONObj *obj)
990 {
991 string s;
992 JSONDecoder::decode_json("bucket", s, obj);
993 if (s == "*") {
994 bucket.reset();
995 } else {
996 rgw_bucket b;
997 int ret = rgw_bucket_parse_bucket_key(nullptr, s, &b, nullptr);
998 if (ret < 0) {
999 bucket.reset();
1000 } else {
1001 if (b.tenant == "*") {
1002 b.tenant.clear();
1003 }
1004 if (b.name == "*") {
1005 b.name.clear();
1006 }
1007 if (b.bucket_id == "*") {
1008 b.bucket_id.clear();
1009 }
1010 bucket = b;
1011 }
1012 }
1013 JSONDecoder::decode_json("zones", zones, obj);
1014 if (zones && zones->size() == 1) {
1015 auto iter = zones->begin();
1016 if (*iter == "*") {
1017 zones.reset();
1018 all_zones = true;
1019 }
1020 }
1021 }
1022
1023 void rgw_sync_bucket_pipe::dump(Formatter *f) const
1024 {
1025 encode_json("id", id, f);
1026 encode_json("source", source, f);
1027 encode_json("dest", dest, f);
1028 encode_json("params", params, f);
1029 }
1030
1031 void rgw_sync_bucket_pipe::decode_json(JSONObj *obj)
1032 {
1033 JSONDecoder::decode_json("id", id, obj);
1034 JSONDecoder::decode_json("source", source, obj);
1035 JSONDecoder::decode_json("dest", dest, obj);
1036 JSONDecoder::decode_json("params", params, obj);
1037 }
1038
1039 void rgw_sync_bucket_pipes::dump(Formatter *f) const
1040 {
1041 encode_json("id", id, f);
1042 encode_json("source", source, f);
1043 encode_json("dest", dest, f);
1044 encode_json("params", params, f);
1045 }
1046
1047 void rgw_sync_bucket_pipes::decode_json(JSONObj *obj)
1048 {
1049 JSONDecoder::decode_json("id", id, obj);
1050 JSONDecoder::decode_json("source", source, obj);
1051 JSONDecoder::decode_json("dest", dest, obj);
1052 JSONDecoder::decode_json("params", params, obj);
1053 }
1054
1055 void rgw_sync_data_flow_group::dump(Formatter *f) const
1056 {
1057 if (!symmetrical.empty()) {
1058 encode_json("symmetrical", symmetrical, f);
1059 }
1060
1061 if (!directional.empty()) {
1062 encode_json("directional", directional, f);
1063 }
1064 }
1065
1066 void rgw_sync_data_flow_group::decode_json(JSONObj *obj)
1067 {
1068 JSONDecoder::decode_json("symmetrical", symmetrical, obj);
1069 JSONDecoder::decode_json("directional", directional, obj);
1070 }
1071
1072 void rgw_sync_policy_group::dump(Formatter *f) const
1073 {
1074 encode_json("id", id, f);
1075 encode_json("data_flow", data_flow, f);
1076 encode_json("pipes", pipes, f);
1077 string s;
1078 switch (status) {
1079 case rgw_sync_policy_group::Status::FORBIDDEN:
1080 s = "forbidden";
1081 break;
1082 case rgw_sync_policy_group::Status::ALLOWED:
1083 s = "allowed";
1084 break;
1085 case rgw_sync_policy_group::Status::ENABLED:
1086 s = "enabled";
1087 break;
1088 default:
1089 s = "unknown";
1090 }
1091 encode_json("status", s, f);
1092 }
1093
1094 void rgw_sync_policy_group::decode_json(JSONObj *obj)
1095 {
1096 JSONDecoder::decode_json("id", id, obj);
1097 JSONDecoder::decode_json("data_flow", data_flow, obj);
1098 JSONDecoder::decode_json("pipes", pipes, obj);
1099 string s;
1100 JSONDecoder::decode_json("status", s, obj);
1101 set_status(s);
1102 }
1103
1104 void rgw_sync_policy_info::dump(Formatter *f) const
1105 {
1106 Formatter::ArraySection section(*f, "groups");
1107 for (auto& group : groups ) {
1108 encode_json("group", group.second, f);
1109 }
1110 }
1111
1112 void rgw_sync_policy_info::decode_json(JSONObj *obj)
1113 {
1114 vector<rgw_sync_policy_group> groups_vec;
1115
1116 JSONDecoder::decode_json("groups", groups_vec, obj);
1117
1118 for (auto& group : groups_vec) {
1119 groups.emplace(std::make_pair(group.id, std::move(group)));
1120 }
1121 }
1122
1123 void rgw_obj_key::dump(Formatter *f) const
1124 {
1125 encode_json("name", name, f);
1126 encode_json("instance", instance, f);
1127 encode_json("ns", ns, f);
1128 }
1129
1130 void rgw_obj_key::decode_json(JSONObj *obj)
1131 {
1132 JSONDecoder::decode_json("name", name, obj);
1133 JSONDecoder::decode_json("instance", instance, obj);
1134 JSONDecoder::decode_json("ns", ns, obj);
1135 }
1136
1137 void RGWBucketEnt::dump(Formatter *f) const
1138 {
1139 encode_json("bucket", bucket, f);
1140 encode_json("size", size, f);
1141 encode_json("size_rounded", size_rounded, f);
1142 utime_t ut(creation_time);
1143 encode_json("mtime", ut, f); /* mtime / creation time discrepency needed for backward compatibility */
1144 encode_json("count", count, f);
1145 encode_json("placement_rule", placement_rule.to_str(), f);
1146 }
1147
1148 void RGWUploadPartInfo::dump(Formatter *f) const
1149 {
1150 encode_json("num", num, f);
1151 encode_json("size", size, f);
1152 encode_json("etag", etag, f);
1153 utime_t ut(modified);
1154 encode_json("modified", ut, f);
1155 }
1156
1157 void rgw_raw_obj::dump(Formatter *f) const
1158 {
1159 encode_json("pool", pool, f);
1160 encode_json("oid", oid, f);
1161 encode_json("loc", loc, f);
1162 }
1163
1164 void rgw_raw_obj::decode_json(JSONObj *obj) {
1165 JSONDecoder::decode_json("pool", pool, obj);
1166 JSONDecoder::decode_json("oid", oid, obj);
1167 JSONDecoder::decode_json("loc", loc, obj);
1168 }
1169
1170 void rgw_obj::dump(Formatter *f) const
1171 {
1172 encode_json("bucket", bucket, f);
1173 encode_json("key", key, f);
1174 }
1175
1176 void RGWDefaultSystemMetaObjInfo::dump(Formatter *f) const {
1177 encode_json("default_id", default_id, f);
1178 }
1179
1180 void RGWDefaultSystemMetaObjInfo::decode_json(JSONObj *obj) {
1181 JSONDecoder::decode_json("default_id", default_id, obj);
1182 }
1183
1184 void RGWNameToId::dump(Formatter *f) const {
1185 encode_json("obj_id", obj_id, f);
1186 }
1187
1188 void RGWNameToId::decode_json(JSONObj *obj) {
1189 JSONDecoder::decode_json("obj_id", obj_id, obj);
1190 }
1191
1192 void RGWSystemMetaObj::dump(Formatter *f) const
1193 {
1194 encode_json("id", id , f);
1195 encode_json("name", name , f);
1196 }
1197
1198 void RGWSystemMetaObj::decode_json(JSONObj *obj)
1199 {
1200 JSONDecoder::decode_json("id", id, obj);
1201 JSONDecoder::decode_json("name", name, obj);
1202 }
1203
1204 void RGWPeriodLatestEpochInfo::dump(Formatter *f) const {
1205 encode_json("latest_epoch", epoch, f);
1206 }
1207
1208 void RGWPeriodLatestEpochInfo::decode_json(JSONObj *obj) {
1209 JSONDecoder::decode_json("latest_epoch", epoch, obj);
1210 }
1211
1212 void RGWPeriod::dump(Formatter *f) const
1213 {
1214 encode_json("id", id, f);
1215 encode_json("epoch", epoch , f);
1216 encode_json("predecessor_uuid", predecessor_uuid, f);
1217 encode_json("sync_status", sync_status, f);
1218 encode_json("period_map", period_map, f);
1219 encode_json("master_zonegroup", master_zonegroup, f);
1220 encode_json("master_zone", master_zone, f);
1221 encode_json("period_config", period_config, f);
1222 encode_json("realm_id", realm_id, f);
1223 encode_json("realm_name", realm_name, f);
1224 encode_json("realm_epoch", realm_epoch, f);
1225 }
1226
1227 void RGWPeriod::decode_json(JSONObj *obj)
1228 {
1229 JSONDecoder::decode_json("id", id, obj);
1230 JSONDecoder::decode_json("epoch", epoch, obj);
1231 JSONDecoder::decode_json("predecessor_uuid", predecessor_uuid, obj);
1232 JSONDecoder::decode_json("sync_status", sync_status, obj);
1233 JSONDecoder::decode_json("period_map", period_map, obj);
1234 JSONDecoder::decode_json("master_zonegroup", master_zonegroup, obj);
1235 JSONDecoder::decode_json("master_zone", master_zone, obj);
1236 JSONDecoder::decode_json("period_config", period_config, obj);
1237 JSONDecoder::decode_json("realm_id", realm_id, obj);
1238 JSONDecoder::decode_json("realm_name", realm_name, obj);
1239 JSONDecoder::decode_json("realm_epoch", realm_epoch, obj);
1240 }
1241
1242 void RGWZoneParams::dump(Formatter *f) const
1243 {
1244 RGWSystemMetaObj::dump(f);
1245 encode_json("domain_root", domain_root, f);
1246 encode_json("control_pool", control_pool, f);
1247 encode_json("gc_pool", gc_pool, f);
1248 encode_json("lc_pool", lc_pool, f);
1249 encode_json("log_pool", log_pool, f);
1250 encode_json("intent_log_pool", intent_log_pool, f);
1251 encode_json("usage_log_pool", usage_log_pool, f);
1252 encode_json("roles_pool", roles_pool, f);
1253 encode_json("reshard_pool", reshard_pool, f);
1254 encode_json("user_keys_pool", user_keys_pool, f);
1255 encode_json("user_email_pool", user_email_pool, f);
1256 encode_json("user_swift_pool", user_swift_pool, f);
1257 encode_json("user_uid_pool", user_uid_pool, f);
1258 encode_json("otp_pool", otp_pool, f);
1259 encode_json_plain("system_key", system_key, f);
1260 encode_json("placement_pools", placement_pools, f);
1261 encode_json("tier_config", tier_config, f);
1262 encode_json("realm_id", realm_id, f);
1263 }
1264
1265 void RGWZoneStorageClass::dump(Formatter *f) const
1266 {
1267 if (data_pool) {
1268 encode_json("data_pool", data_pool.get(), f);
1269 }
1270 if (compression_type) {
1271 encode_json("compression_type", compression_type.get(), f);
1272 }
1273 }
1274
1275 void RGWZoneStorageClass::decode_json(JSONObj *obj)
1276 {
1277 JSONDecoder::decode_json("data_pool", data_pool, obj);
1278 JSONDecoder::decode_json("compression_type", compression_type, obj);
1279 }
1280
1281 void RGWZoneStorageClasses::dump(Formatter *f) const
1282 {
1283 for (auto& i : m) {
1284 encode_json(i.first.c_str(), i.second, f);
1285 }
1286 }
1287
1288 void RGWZoneStorageClasses::decode_json(JSONObj *obj)
1289 {
1290 JSONFormattable f;
1291 decode_json_obj(f, obj);
1292
1293 for (auto& field : f.object()) {
1294 JSONObj *field_obj = obj->find_obj(field.first);
1295 assert(field_obj);
1296
1297 decode_json_obj(m[field.first], field_obj);
1298 }
1299 standard_class = &m[RGW_STORAGE_CLASS_STANDARD];
1300 }
1301
1302 void RGWZonePlacementInfo::dump(Formatter *f) const
1303 {
1304 encode_json("index_pool", index_pool, f);
1305 encode_json("storage_classes", storage_classes, f);
1306 encode_json("data_extra_pool", data_extra_pool, f);
1307 encode_json("index_type", (uint32_t)index_type, f);
1308
1309 /* no real need for backward compatibility of compression_type and data_pool in here,
1310 * rather not clutter the output */
1311 }
1312
1313 void RGWZonePlacementInfo::decode_json(JSONObj *obj)
1314 {
1315 JSONDecoder::decode_json("index_pool", index_pool, obj);
1316 JSONDecoder::decode_json("storage_classes", storage_classes, obj);
1317 JSONDecoder::decode_json("data_extra_pool", data_extra_pool, obj);
1318 uint32_t it;
1319 JSONDecoder::decode_json("index_type", it, obj);
1320 index_type = (RGWBucketIndexType)it;
1321
1322 /* backward compatibility, these are now defined in storage_classes */
1323 string standard_compression_type;
1324 string *pcompression = nullptr;
1325 if (JSONDecoder::decode_json("compression", standard_compression_type, obj)) {
1326 pcompression = &standard_compression_type;
1327 }
1328 rgw_pool standard_data_pool;
1329 rgw_pool *ppool = nullptr;
1330 if (JSONDecoder::decode_json("data_pool", standard_data_pool, obj)) {
1331 ppool = &standard_data_pool;
1332 }
1333 if (ppool || pcompression) {
1334 storage_classes.set_storage_class(RGW_STORAGE_CLASS_STANDARD, ppool, pcompression);
1335 }
1336 }
1337
1338 void RGWZoneParams::decode_json(JSONObj *obj)
1339 {
1340 RGWSystemMetaObj::decode_json(obj);
1341 JSONDecoder::decode_json("domain_root", domain_root, obj);
1342 JSONDecoder::decode_json("control_pool", control_pool, obj);
1343 JSONDecoder::decode_json("gc_pool", gc_pool, obj);
1344 JSONDecoder::decode_json("lc_pool", lc_pool, obj);
1345 JSONDecoder::decode_json("log_pool", log_pool, obj);
1346 JSONDecoder::decode_json("intent_log_pool", intent_log_pool, obj);
1347 JSONDecoder::decode_json("roles_pool", roles_pool, obj);
1348 JSONDecoder::decode_json("reshard_pool", reshard_pool, obj);
1349 JSONDecoder::decode_json("usage_log_pool", usage_log_pool, obj);
1350 JSONDecoder::decode_json("user_keys_pool", user_keys_pool, obj);
1351 JSONDecoder::decode_json("user_email_pool", user_email_pool, obj);
1352 JSONDecoder::decode_json("user_swift_pool", user_swift_pool, obj);
1353 JSONDecoder::decode_json("user_uid_pool", user_uid_pool, obj);
1354 JSONDecoder::decode_json("otp_pool", otp_pool, obj);
1355 JSONDecoder::decode_json("system_key", system_key, obj);
1356 JSONDecoder::decode_json("placement_pools", placement_pools, obj);
1357 JSONDecoder::decode_json("tier_config", tier_config, obj);
1358 JSONDecoder::decode_json("realm_id", realm_id, obj);
1359
1360 }
1361
1362 void RGWZone::dump(Formatter *f) const
1363 {
1364 encode_json("id", id, f);
1365 encode_json("name", name, f);
1366 encode_json("endpoints", endpoints, f);
1367 encode_json("log_meta", log_meta, f);
1368 encode_json("log_data", log_data, f);
1369 encode_json("bucket_index_max_shards", bucket_index_max_shards, f);
1370 encode_json("read_only", read_only, f);
1371 encode_json("tier_type", tier_type, f);
1372 encode_json("sync_from_all", sync_from_all, f);
1373 encode_json("sync_from", sync_from, f);
1374 encode_json("redirect_zone", redirect_zone, f);
1375 }
1376
1377 void RGWZone::decode_json(JSONObj *obj)
1378 {
1379 JSONDecoder::decode_json("id", id, obj);
1380 JSONDecoder::decode_json("name", name, obj);
1381 if (id.empty()) {
1382 id = name;
1383 }
1384 JSONDecoder::decode_json("endpoints", endpoints, obj);
1385 JSONDecoder::decode_json("log_meta", log_meta, obj);
1386 JSONDecoder::decode_json("log_data", log_data, obj);
1387 JSONDecoder::decode_json("bucket_index_max_shards", bucket_index_max_shards, obj);
1388 JSONDecoder::decode_json("read_only", read_only, obj);
1389 JSONDecoder::decode_json("tier_type", tier_type, obj);
1390 JSONDecoder::decode_json("sync_from_all", sync_from_all, true, obj);
1391 JSONDecoder::decode_json("sync_from", sync_from, obj);
1392 JSONDecoder::decode_json("redirect_zone", redirect_zone, obj);
1393 }
1394
1395 void RGWZoneGroupPlacementTarget::dump(Formatter *f) const
1396 {
1397 encode_json("name", name, f);
1398 encode_json("tags", tags, f);
1399 encode_json("storage_classes", storage_classes, f);
1400 }
1401
1402 void RGWZoneGroupPlacementTarget::decode_json(JSONObj *obj)
1403 {
1404 JSONDecoder::decode_json("name", name, obj);
1405 JSONDecoder::decode_json("tags", tags, obj);
1406 JSONDecoder::decode_json("storage_classes", storage_classes, obj);
1407 if (storage_classes.empty()) {
1408 storage_classes.insert(RGW_STORAGE_CLASS_STANDARD);
1409 }
1410 }
1411
1412 void RGWZoneGroup::dump(Formatter *f) const
1413 {
1414 RGWSystemMetaObj::dump(f);
1415 encode_json("api_name", api_name, f);
1416 encode_json("is_master", is_master, f);
1417 encode_json("endpoints", endpoints, f);
1418 encode_json("hostnames", hostnames, f);
1419 encode_json("hostnames_s3website", hostnames_s3website, f);
1420 encode_json("master_zone", master_zone, f);
1421 encode_json_map("zones", zones, f); /* more friendly representation */
1422 encode_json_map("placement_targets", placement_targets, f); /* more friendly representation */
1423 encode_json("default_placement", default_placement, f);
1424 encode_json("realm_id", realm_id, f);
1425 encode_json("sync_policy", sync_policy, f);
1426 }
1427
1428 static void decode_zones(map<rgw_zone_id, RGWZone>& zones, JSONObj *o)
1429 {
1430 RGWZone z;
1431 z.decode_json(o);
1432 zones[z.id] = z;
1433 }
1434
1435 static void decode_placement_targets(map<string, RGWZoneGroupPlacementTarget>& targets, JSONObj *o)
1436 {
1437 RGWZoneGroupPlacementTarget t;
1438 t.decode_json(o);
1439 targets[t.name] = t;
1440 }
1441
1442
1443 void RGWZoneGroup::decode_json(JSONObj *obj)
1444 {
1445 RGWSystemMetaObj::decode_json(obj);
1446 if (id.empty()) {
1447 derr << "old format " << dendl;
1448 JSONDecoder::decode_json("name", name, obj);
1449 id = name;
1450 }
1451 JSONDecoder::decode_json("api_name", api_name, obj);
1452 JSONDecoder::decode_json("is_master", is_master, obj);
1453 JSONDecoder::decode_json("endpoints", endpoints, obj);
1454 JSONDecoder::decode_json("hostnames", hostnames, obj);
1455 JSONDecoder::decode_json("hostnames_s3website", hostnames_s3website, obj);
1456 JSONDecoder::decode_json("master_zone", master_zone, obj);
1457 JSONDecoder::decode_json("zones", zones, decode_zones, obj);
1458 JSONDecoder::decode_json("placement_targets", placement_targets, decode_placement_targets, obj);
1459 JSONDecoder::decode_json("default_placement", default_placement.name, obj);
1460 JSONDecoder::decode_json("default_storage_class", default_placement.storage_class, obj);
1461 JSONDecoder::decode_json("realm_id", realm_id, obj);
1462 JSONDecoder::decode_json("sync_policy", sync_policy, obj);
1463 }
1464
1465
1466 void RGWPeriodMap::dump(Formatter *f) const
1467 {
1468 encode_json("id", id, f);
1469 encode_json_map("zonegroups", zonegroups, f);
1470 encode_json("short_zone_ids", short_zone_ids, f);
1471 }
1472
1473 static void decode_zonegroups(map<string, RGWZoneGroup>& zonegroups, JSONObj *o)
1474 {
1475 RGWZoneGroup zg;
1476 zg.decode_json(o);
1477 zonegroups[zg.get_id()] = zg;
1478 }
1479
1480 void RGWPeriodMap::decode_json(JSONObj *obj)
1481 {
1482 JSONDecoder::decode_json("id", id, obj);
1483 JSONDecoder::decode_json("zonegroups", zonegroups, decode_zonegroups, obj);
1484 /* backward compatability with region */
1485 if (zonegroups.empty()) {
1486 JSONDecoder::decode_json("regions", zonegroups, obj);
1487 }
1488 /* backward compatability with region */
1489 if (master_zonegroup.empty()) {
1490 JSONDecoder::decode_json("master_region", master_zonegroup, obj);
1491 }
1492 JSONDecoder::decode_json("short_zone_ids", short_zone_ids, obj);
1493 }
1494
1495
1496 void RGWPeriodConfig::dump(Formatter *f) const
1497 {
1498 encode_json("bucket_quota", bucket_quota, f);
1499 encode_json("user_quota", user_quota, f);
1500 }
1501
1502 void RGWPeriodConfig::decode_json(JSONObj *obj)
1503 {
1504 JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
1505 JSONDecoder::decode_json("user_quota", user_quota, obj);
1506 }
1507
1508 void RGWRegionMap::dump(Formatter *f) const
1509 {
1510 encode_json("regions", regions, f);
1511 encode_json("master_region", master_region, f);
1512 encode_json("bucket_quota", bucket_quota, f);
1513 encode_json("user_quota", user_quota, f);
1514 }
1515
1516 void RGWRegionMap::decode_json(JSONObj *obj)
1517 {
1518 JSONDecoder::decode_json("regions", regions, obj);
1519 JSONDecoder::decode_json("master_region", master_region, obj);
1520 JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
1521 JSONDecoder::decode_json("user_quota", user_quota, obj);
1522 }
1523
1524 void RGWZoneGroupMap::dump(Formatter *f) const
1525 {
1526 encode_json("zonegroups", zonegroups, f);
1527 encode_json("master_zonegroup", master_zonegroup, f);
1528 encode_json("bucket_quota", bucket_quota, f);
1529 encode_json("user_quota", user_quota, f);
1530 }
1531
1532 void RGWZoneGroupMap::decode_json(JSONObj *obj)
1533 {
1534 JSONDecoder::decode_json("zonegroups", zonegroups, obj);
1535 /* backward compatability with region */
1536 if (zonegroups.empty()) {
1537 JSONDecoder::decode_json("regions", zonegroups, obj);
1538 }
1539 JSONDecoder::decode_json("master_zonegroup", master_zonegroup, obj);
1540 /* backward compatability with region */
1541 if (master_zonegroup.empty()) {
1542 JSONDecoder::decode_json("master_region", master_zonegroup, obj);
1543 }
1544
1545 JSONDecoder::decode_json("bucket_quota", bucket_quota, obj);
1546 JSONDecoder::decode_json("user_quota", user_quota, obj);
1547 }
1548
1549 void RGWMetadataLogInfo::dump(Formatter *f) const
1550 {
1551 encode_json("marker", marker, f);
1552 utime_t ut(last_update);
1553 encode_json("last_update", ut, f);
1554 }
1555
1556 void RGWMetadataLogInfo::decode_json(JSONObj *obj)
1557 {
1558 JSONDecoder::decode_json("marker", marker, obj);
1559 utime_t ut;
1560 JSONDecoder::decode_json("last_update", ut, obj);
1561 last_update = ut.to_real_time();
1562 }
1563
1564 void RGWDataChangesLogInfo::dump(Formatter *f) const
1565 {
1566 encode_json("marker", marker, f);
1567 utime_t ut(last_update);
1568 encode_json("last_update", ut, f);
1569 }
1570
1571 void RGWDataChangesLogInfo::decode_json(JSONObj *obj)
1572 {
1573 JSONDecoder::decode_json("marker", marker, obj);
1574 utime_t ut;
1575 JSONDecoder::decode_json("last_update", ut, obj);
1576 last_update = ut.to_real_time();
1577 }
1578
1579
1580 void RGWRealm::dump(Formatter *f) const
1581 {
1582 RGWSystemMetaObj::dump(f);
1583 encode_json("current_period", current_period, f);
1584 encode_json("epoch", epoch, f);
1585 }
1586
1587
1588 void RGWRealm::decode_json(JSONObj *obj)
1589 {
1590 RGWSystemMetaObj::decode_json(obj);
1591 JSONDecoder::decode_json("current_period", current_period, obj);
1592 JSONDecoder::decode_json("epoch", epoch, obj);
1593 }
1594
1595 void rgw::keystone::TokenEnvelope::Token::decode_json(JSONObj *obj)
1596 {
1597 string expires_iso8601;
1598 struct tm t;
1599
1600 JSONDecoder::decode_json("id", id, obj, true);
1601 JSONDecoder::decode_json("tenant", tenant_v2, obj, true);
1602 JSONDecoder::decode_json("expires", expires_iso8601, obj, true);
1603
1604 if (parse_iso8601(expires_iso8601.c_str(), &t)) {
1605 expires = internal_timegm(&t);
1606 } else {
1607 expires = 0;
1608 throw JSONDecoder::err("Failed to parse ISO8601 expiration date from Keystone response.");
1609 }
1610 }
1611
1612 void rgw::keystone::TokenEnvelope::Role::decode_json(JSONObj *obj)
1613 {
1614 JSONDecoder::decode_json("id", id, obj);
1615 JSONDecoder::decode_json("name", name, obj, true);
1616 }
1617
1618 void rgw::keystone::TokenEnvelope::Domain::decode_json(JSONObj *obj)
1619 {
1620 JSONDecoder::decode_json("id", id, obj, true);
1621 JSONDecoder::decode_json("name", name, obj, true);
1622 }
1623
1624 void rgw::keystone::TokenEnvelope::Project::decode_json(JSONObj *obj)
1625 {
1626 JSONDecoder::decode_json("id", id, obj, true);
1627 JSONDecoder::decode_json("name", name, obj, true);
1628 JSONDecoder::decode_json("domain", domain, obj);
1629 }
1630
1631 void rgw::keystone::TokenEnvelope::User::decode_json(JSONObj *obj)
1632 {
1633 JSONDecoder::decode_json("id", id, obj, true);
1634 JSONDecoder::decode_json("name", name, obj, true);
1635 JSONDecoder::decode_json("domain", domain, obj);
1636 JSONDecoder::decode_json("roles", roles_v2, obj);
1637 }
1638
1639 void rgw::keystone::TokenEnvelope::decode_v3(JSONObj* const root_obj)
1640 {
1641 std::string expires_iso8601;
1642
1643 JSONDecoder::decode_json("user", user, root_obj, true);
1644 JSONDecoder::decode_json("expires_at", expires_iso8601, root_obj, true);
1645 JSONDecoder::decode_json("roles", roles, root_obj, true);
1646 JSONDecoder::decode_json("project", project, root_obj, true);
1647
1648 struct tm t;
1649 if (parse_iso8601(expires_iso8601.c_str(), &t)) {
1650 token.expires = internal_timegm(&t);
1651 } else {
1652 token.expires = 0;
1653 throw JSONDecoder::err("Failed to parse ISO8601 expiration date"
1654 "from Keystone response.");
1655 }
1656 }
1657
1658 void rgw::keystone::TokenEnvelope::decode_v2(JSONObj* const root_obj)
1659 {
1660 JSONDecoder::decode_json("user", user, root_obj, true);
1661 JSONDecoder::decode_json("token", token, root_obj, true);
1662
1663 roles = user.roles_v2;
1664 project = token.tenant_v2;
1665 }
1666
1667 void rgw_slo_entry::decode_json(JSONObj *obj)
1668 {
1669 JSONDecoder::decode_json("path", path, obj);
1670 JSONDecoder::decode_json("etag", etag, obj);
1671 JSONDecoder::decode_json("size_bytes", size_bytes, obj);
1672 };
1673
1674 void rgw_meta_sync_info::decode_json(JSONObj *obj)
1675 {
1676 string s;
1677 JSONDecoder::decode_json("status", s, obj);
1678 if (s == "init") {
1679 state = StateInit;
1680 } else if (s == "building-full-sync-maps") {
1681 state = StateBuildingFullSyncMaps;
1682 } else if (s == "sync") {
1683 state = StateSync;
1684 }
1685 JSONDecoder::decode_json("num_shards", num_shards, obj);
1686 JSONDecoder::decode_json("period", period, obj);
1687 JSONDecoder::decode_json("realm_epoch", realm_epoch, obj);
1688 }
1689
1690 void rgw_meta_sync_info::dump(Formatter *f) const
1691 {
1692 string s;
1693 switch ((SyncState)state) {
1694 case StateInit:
1695 s = "init";
1696 break;
1697 case StateBuildingFullSyncMaps:
1698 s = "building-full-sync-maps";
1699 break;
1700 case StateSync:
1701 s = "sync";
1702 break;
1703 default:
1704 s = "unknown";
1705 break;
1706 }
1707 encode_json("status", s, f);
1708 encode_json("num_shards", num_shards, f);
1709 encode_json("period", period, f);
1710 encode_json("realm_epoch", realm_epoch, f);
1711 }
1712
1713 void rgw_meta_sync_marker::decode_json(JSONObj *obj)
1714 {
1715 int s;
1716 JSONDecoder::decode_json("state", s, obj);
1717 state = s;
1718 JSONDecoder::decode_json("marker", marker, obj);
1719 JSONDecoder::decode_json("next_step_marker", next_step_marker, obj);
1720 JSONDecoder::decode_json("total_entries", total_entries, obj);
1721 JSONDecoder::decode_json("pos", pos, obj);
1722 utime_t ut;
1723 JSONDecoder::decode_json("timestamp", ut, obj);
1724 timestamp = ut.to_real_time();
1725 JSONDecoder::decode_json("realm_epoch", realm_epoch, obj);
1726 }
1727
1728 void rgw_meta_sync_marker::dump(Formatter *f) const
1729 {
1730 encode_json("state", (int)state, f);
1731 encode_json("marker", marker, f);
1732 encode_json("next_step_marker", next_step_marker, f);
1733 encode_json("total_entries", total_entries, f);
1734 encode_json("pos", pos, f);
1735 encode_json("timestamp", utime_t(timestamp), f);
1736 encode_json("realm_epoch", realm_epoch, f);
1737 }
1738
1739 void rgw_meta_sync_status::decode_json(JSONObj *obj)
1740 {
1741 JSONDecoder::decode_json("info", sync_info, obj);
1742 JSONDecoder::decode_json("markers", sync_markers, obj);
1743 }
1744
1745 void rgw_meta_sync_status::dump(Formatter *f) const {
1746 encode_json("info", sync_info, f);
1747 encode_json("markers", sync_markers, f);
1748 }
1749
1750 void rgw_sync_error_info::dump(Formatter *f) const {
1751 encode_json("source_zone", source_zone, f);
1752 encode_json("error_code", error_code, f);
1753 encode_json("message", message, f);
1754 }
1755
1756 void rgw_bucket_shard_full_sync_marker::decode_json(JSONObj *obj)
1757 {
1758 JSONDecoder::decode_json("position", position, obj);
1759 JSONDecoder::decode_json("count", count, obj);
1760 }
1761
1762 void rgw_bucket_shard_full_sync_marker::dump(Formatter *f) const
1763 {
1764 encode_json("position", position, f);
1765 encode_json("count", count, f);
1766 }
1767
1768 void rgw_bucket_shard_inc_sync_marker::decode_json(JSONObj *obj)
1769 {
1770 JSONDecoder::decode_json("position", position, obj);
1771 }
1772
1773 void rgw_bucket_shard_inc_sync_marker::dump(Formatter *f) const
1774 {
1775 encode_json("position", position, f);
1776 }
1777
1778 void rgw_bucket_shard_sync_info::decode_json(JSONObj *obj)
1779 {
1780 std::string s;
1781 JSONDecoder::decode_json("status", s, obj);
1782 if (s == "full-sync") {
1783 state = StateFullSync;
1784 } else if (s == "incremental-sync") {
1785 state = StateIncrementalSync;
1786 } else if (s == "stopped") {
1787 state = StateStopped;
1788 } else {
1789 state = StateInit;
1790 }
1791 JSONDecoder::decode_json("full_marker", full_marker, obj);
1792 JSONDecoder::decode_json("inc_marker", inc_marker, obj);
1793 }
1794
1795 void rgw_bucket_shard_sync_info::dump(Formatter *f) const
1796 {
1797 const char *s{nullptr};
1798 switch ((SyncState)state) {
1799 case StateInit:
1800 s = "init";
1801 break;
1802 case StateFullSync:
1803 s = "full-sync";
1804 break;
1805 case StateIncrementalSync:
1806 s = "incremental-sync";
1807 break;
1808 case StateStopped:
1809 s = "stopped";
1810 break;
1811 default:
1812 s = "unknown";
1813 break;
1814 }
1815 encode_json("status", s, f);
1816 encode_json("full_marker", full_marker, f);
1817 encode_json("inc_marker", inc_marker, f);
1818 }
1819
1820 /* This utility function shouldn't conflict with the overload of std::to_string
1821 * provided by string_ref since Boost 1.54 as it's defined outside of the std
1822 * namespace. I hope we'll remove it soon - just after merging the Matt's PR
1823 * for bundled Boost. It would allow us to forget that CentOS 7 has Boost 1.53. */
1824 static inline std::string to_string(const boost::string_ref& s)
1825 {
1826 return std::string(s.data(), s.length());
1827 }
1828
1829 void rgw::keystone::AdminTokenRequestVer2::dump(Formatter* const f) const
1830 {
1831 f->open_object_section("token_request");
1832 f->open_object_section("auth");
1833 f->open_object_section("passwordCredentials");
1834 encode_json("username", ::to_string(conf.get_admin_user()), f);
1835 encode_json("password", ::to_string(conf.get_admin_password()), f);
1836 f->close_section();
1837 encode_json("tenantName", ::to_string(conf.get_admin_tenant()), f);
1838 f->close_section();
1839 f->close_section();
1840 }
1841
1842 void rgw::keystone::AdminTokenRequestVer3::dump(Formatter* const f) const
1843 {
1844 f->open_object_section("token_request");
1845 f->open_object_section("auth");
1846 f->open_object_section("identity");
1847 f->open_array_section("methods");
1848 f->dump_string("", "password");
1849 f->close_section();
1850 f->open_object_section("password");
1851 f->open_object_section("user");
1852 f->open_object_section("domain");
1853 encode_json("name", ::to_string(conf.get_admin_domain()), f);
1854 f->close_section();
1855 encode_json("name", ::to_string(conf.get_admin_user()), f);
1856 encode_json("password", ::to_string(conf.get_admin_password()), f);
1857 f->close_section();
1858 f->close_section();
1859 f->close_section();
1860 f->open_object_section("scope");
1861 f->open_object_section("project");
1862 if (! conf.get_admin_project().empty()) {
1863 encode_json("name", ::to_string(conf.get_admin_project()), f);
1864 } else {
1865 encode_json("name", ::to_string(conf.get_admin_tenant()), f);
1866 }
1867 f->open_object_section("domain");
1868 encode_json("name", ::to_string(conf.get_admin_domain()), f);
1869 f->close_section();
1870 f->close_section();
1871 f->close_section();
1872 f->close_section();
1873 f->close_section();
1874 }
1875
1876
1877 void rgw::keystone::BarbicanTokenRequestVer2::dump(Formatter* const f) const
1878 {
1879 f->open_object_section("token_request");
1880 f->open_object_section("auth");
1881 f->open_object_section("passwordCredentials");
1882 encode_json("username", cct->_conf->rgw_keystone_barbican_user, f);
1883 encode_json("password", cct->_conf->rgw_keystone_barbican_password, f);
1884 f->close_section();
1885 encode_json("tenantName", cct->_conf->rgw_keystone_barbican_tenant, f);
1886 f->close_section();
1887 f->close_section();
1888 }
1889
1890 void rgw::keystone::BarbicanTokenRequestVer3::dump(Formatter* const f) const
1891 {
1892 f->open_object_section("token_request");
1893 f->open_object_section("auth");
1894 f->open_object_section("identity");
1895 f->open_array_section("methods");
1896 f->dump_string("", "password");
1897 f->close_section();
1898 f->open_object_section("password");
1899 f->open_object_section("user");
1900 f->open_object_section("domain");
1901 encode_json("name", cct->_conf->rgw_keystone_barbican_domain, f);
1902 f->close_section();
1903 encode_json("name", cct->_conf->rgw_keystone_barbican_user, f);
1904 encode_json("password", cct->_conf->rgw_keystone_barbican_password, f);
1905 f->close_section();
1906 f->close_section();
1907 f->close_section();
1908 f->open_object_section("scope");
1909 f->open_object_section("project");
1910 if (!cct->_conf->rgw_keystone_barbican_project.empty()) {
1911 encode_json("name", cct->_conf->rgw_keystone_barbican_project, f);
1912 } else {
1913 encode_json("name", cct->_conf->rgw_keystone_barbican_tenant, f);
1914 }
1915 f->open_object_section("domain");
1916 encode_json("name", cct->_conf->rgw_keystone_barbican_domain, f);
1917 f->close_section();
1918 f->close_section();
1919 f->close_section();
1920 f->close_section();
1921 f->close_section();
1922 }
1923
1924 void RGWOrphanSearchStage::dump(Formatter *f) const
1925 {
1926 f->open_object_section("orphan_search_stage");
1927 string s;
1928 switch(stage){
1929 case ORPHAN_SEARCH_STAGE_INIT:
1930 s = "init";
1931 break;
1932 case ORPHAN_SEARCH_STAGE_LSPOOL:
1933 s = "lspool";
1934 break;
1935 case ORPHAN_SEARCH_STAGE_LSBUCKETS:
1936 s = "lsbuckets";
1937 break;
1938 case ORPHAN_SEARCH_STAGE_ITERATE_BI:
1939 s = "iterate_bucket_index";
1940 break;
1941 case ORPHAN_SEARCH_STAGE_COMPARE:
1942 s = "comparing";
1943 break;
1944 default:
1945 s = "unknown";
1946 }
1947 f->dump_string("search_stage", s);
1948 f->dump_int("shard",shard);
1949 f->dump_string("marker",marker);
1950 f->close_section();
1951 }
1952
1953 void RGWOrphanSearchInfo::dump(Formatter *f) const
1954 {
1955 f->open_object_section("orphan_search_info");
1956 f->dump_string("job_name", job_name);
1957 encode_json("pool", pool, f);
1958 f->dump_int("num_shards", num_shards);
1959 encode_json("start_time", start_time, f);
1960 f->close_section();
1961 }
1962
1963 void RGWOrphanSearchState::dump(Formatter *f) const
1964 {
1965 f->open_object_section("orphan_search_state");
1966 encode_json("info", info, f);
1967 encode_json("stage", stage, f);
1968 f->close_section();
1969 }
1970
1971 void RGWObjTags::dump(Formatter *f) const
1972 {
1973 f->open_object_section("tagset");
1974 for (auto& tag: tag_map){
1975 f->dump_string(tag.first.c_str(), tag.second);
1976 }
1977 f->close_section();
1978 }
1979
1980 void lc_op::dump(Formatter *f) const
1981 {
1982 f->dump_bool("status", status);
1983 f->dump_bool("dm_expiration", dm_expiration);
1984
1985 f->dump_int("expiration", expiration);
1986 f->dump_int("noncur_expiration", noncur_expiration);
1987 f->dump_int("mp_expiration", mp_expiration);
1988 if (expiration_date) {
1989 utime_t ut(*expiration_date);
1990 f->dump_stream("expiration_date") << ut;
1991 }
1992 if (obj_tags) {
1993 f->dump_object("obj_tags", *obj_tags);
1994 }
1995 }
1996
1997 void LCFilter::dump(Formatter *f) const
1998 {
1999 f->dump_string("prefix", prefix);
2000 f->dump_object("obj_tags", obj_tags);
2001 }
2002
2003 void LCExpiration::dump(Formatter *f) const
2004 {
2005 f->dump_string("days", days);
2006 f->dump_string("date", date);
2007 }
2008
2009 void LCRule::dump(Formatter *f) const
2010 {
2011 f->dump_string("id", id);
2012 f->dump_string("prefix", prefix);
2013 f->dump_string("status", status);
2014 f->dump_object("expiration", expiration);
2015 f->dump_object("noncur_expiration", noncur_expiration);
2016 f->dump_object("mp_expiration", mp_expiration);
2017 f->dump_object("filter", filter);
2018 f->dump_bool("dm_expiration", dm_expiration);
2019 }
2020
2021 void RGWLifecycleConfiguration::dump(Formatter *f) const
2022 {
2023 f->open_object_section("prefix_map");
2024 for (auto& prefix : prefix_map) {
2025 f->dump_object(prefix.first.c_str(), prefix.second);
2026 }
2027 f->close_section();
2028
2029 f->open_array_section("rule_map");
2030 for (auto& rule : rule_map) {
2031 f->open_object_section("entry");
2032 f->dump_string("id", rule.first);
2033 f->open_object_section("rule");
2034 rule.second.dump(f);
2035 f->close_section();
2036 f->close_section();
2037 }
2038 f->close_section();
2039 }
2040
2041 void compression_block::dump(Formatter *f) const
2042 {
2043 f->dump_unsigned("old_ofs", old_ofs);
2044 f->dump_unsigned("new_ofs", new_ofs);
2045 f->dump_unsigned("len", len);
2046 }
2047
2048 void RGWCompressionInfo::dump(Formatter *f) const
2049 {
2050 f->dump_string("compression_type", compression_type);
2051 f->dump_unsigned("orig_size", orig_size);
2052 ::encode_json("blocks", blocks, f);
2053 }
2054
2055 void objexp_hint_entry::dump(Formatter *f) const
2056 {
2057 f->open_object_section("objexp_hint_entry");
2058 encode_json("tenant", tenant, f);
2059 encode_json("bucket_name", bucket_name, f);
2060 encode_json("bucket_id", bucket_id, f);
2061 encode_json("rgw_obj_key", obj_key, f);
2062 utime_t ut(exp_time);
2063 encode_json("exp_time", ut, f);
2064 f->close_section();
2065 }
2066
2067 void rgw_user::dump(Formatter *f) const
2068 {
2069 ::encode_json("user", *this, f);
2070 }
2071