return 0;
}
-static void add_header_stats(cls_user_header *header, cls_user_bucket_entry& entry)
+static void add_header_stats(cls_user_stats *stats, cls_user_bucket_entry& entry)
{
- header->total_entries += entry.count;
- header->total_bytes += entry.size;
- header->total_bytes_rounded += entry.size_rounded;
+ stats->total_entries += entry.count;
+ stats->total_bytes += entry.size;
+ stats->total_bytes_rounded += entry.size_rounded;
}
-static void dec_header_stats(cls_user_header *header, cls_user_bucket_entry& entry)
+static void dec_header_stats(cls_user_stats *stats, cls_user_bucket_entry& entry)
{
- header->total_bytes -= entry.size;
- header->total_bytes_rounded -= entry.size_rounded;
- header->total_entries -= entry.count;
+ stats->total_bytes -= entry.size;
+ stats->total_bytes_rounded -= entry.size_rounded;
+ stats->total_entries -= entry.count;
}
static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in, bufferlist *out)
CLS_LOG(0, "ERROR: get_existing_bucket_entry() key=%s returned %d", key.c_str(), ret);
return ret;
} else if (ret >= 0 && old_entry.user_stats_sync) {
- dec_header_stats(&header, old_entry);
+ dec_header_stats(&header.stats, old_entry);
}
CLS_LOG(20, "storing entry for key=%s size=%lld count=%lld",
if (ret < 0)
return ret;
- add_header_stats(&header, entry);
+ add_header_stats(&header.stats, entry);
}
bufferlist bl;
- CLS_LOG(20, "header: total bytes=%lld entries=%lld", (long long)header.total_bytes, (long long)header.total_entries);
+ CLS_LOG(20, "header: total bytes=%lld entries=%lld", (long long)header.stats.total_bytes, (long long)header.stats.total_entries);
::encode(header, bl);
}
if (entry.user_stats_sync) {
- dec_header_stats(&header, entry);
+ dec_header_stats(&header.stats, entry);
}
CLS_LOG(20, "removing entry at %s", key.c_str());
#include "cls/user/cls_user_types.h"
#include "common/Formatter.h"
+#include "common/ceph_json.h"
-void cls_user_header::dump(Formatter *f) const
+void cls_user_stats::dump(Formatter *f) const
{
f->dump_int("total_entries", total_entries);
f->dump_int("total_bytes", total_bytes);
f->dump_int("total_bytes_rounded", total_bytes_rounded);
}
+void cls_user_header::dump(Formatter *f) const
+{
+ encode_json("stats", stats, f);
+}
};
WRITE_CLASS_ENCODER(cls_user_bucket_entry)
-/*
- * this needs to be compatible with with rgw_bucket, as it replaces it
- */
-struct cls_user_header {
+struct cls_user_stats {
uint64_t total_entries;
uint64_t total_bytes;
uint64_t total_bytes_rounded;
void dump(Formatter *f) const;
};
+WRITE_CLASS_ENCODER(cls_user_stats)
+
+/*
+ * this needs to be compatible with with rgw_bucket, as it replaces it
+ */
+struct cls_user_header {
+ cls_user_stats stats;
+
+ void encode(bufferlist& bl) const {
+ ENCODE_START(1, 1, bl);
+ ::encode(stats, bl);
+ ENCODE_FINISH(bl);
+ }
+ void decode(bufferlist::iterator& bl) {
+ DECODE_START(1, bl);
+ ::decode(stats, bl);
+ DECODE_FINISH(bl);
+ }
+
+ void dump(Formatter *f) const;
+};
WRITE_CLASS_ENCODER(cls_user_header)
#endif
return -ret;
}
- encode_json("header", header, formatter);
+ encode_json("stats", header.stats, formatter);
formatter->flush(cout);
}
public:
RGWGetUserStatsContext(RGWGetUserStats_CB *_cb) : cb(_cb) {}
void handle_response(int r, cls_user_header& header) {
+ cls_user_stats& hs = header.stats;
if (r >= 0) {
RGWStorageStats stats;
- stats.num_kb = (header.total_bytes + 1023) / 1024;
- stats.num_kb_rounded = (header.total_bytes_rounded + 1023) / 1024;
- stats.num_objects = header.total_entries;
+ stats.num_kb = (hs.total_bytes + 1023) / 1024;
+ stats.num_kb_rounded = (hs.total_bytes_rounded + 1023) / 1024;
+ stats.num_objects = hs.total_entries;
cb->set_response(stats);
}
if (r < 0)
return r;
- stats.num_kb = (header.total_bytes + 1023) / 1024;
- stats.num_kb_rounded = (header.total_bytes_rounded + 1023) / 1024;
- stats.num_objects = header.total_entries;
+ cls_user_stats& hs = header.stats;
+
+ stats.num_kb = (hs.total_bytes + 1023) / 1024;
+ stats.num_kb_rounded = (hs.total_bytes_rounded + 1023) / 1024;
+ stats.num_objects = hs.total_entries;
return 0;
}