cls_method_handle_t h_rgw_bucket_list;
cls_method_handle_t h_rgw_bucket_modify;
+
+#define ROUND_BLOCK_SIZE 4096
+
+static uint64_t get_rounded_size(uint64_t size)
+{
+ return (size + ROUND_BLOCK_SIZE - 1) & ~(ROUND_BLOCK_SIZE - 1);
+}
+
static int read_bucket_dir(cls_method_context_t hctx, struct rgw_bucket_dir& dir)
{
bufferlist bl;
CLS_LOG("rgw_bucket_modify(): skipping request, old epoch\n");
return 0;
}
+
+ struct rgw_bucket_category_stats& stats = dir.header.stats[entry.category];
+ stats.num_entries--;
+ stats.total_size -= entry.size;
+ stats.total_size_rounded -= get_rounded_size(entry.size);
}
switch (op.op) {
return -ENOENT;
break;
case CLS_RGW_OP_ADD:
- dir.m[op.entry.name] = op.entry;
+ {
+ struct rgw_bucket_category_stats& stats = dir.header.stats[op.entry.category];
+ dir.m[op.entry.name] = op.entry;
+ stats.num_entries++;
+ stats.total_size += op.entry.size;
+ stats.total_size_rounded += get_rounded_size(op.entry.size);
+ }
break;
}
struct rgw_bucket_dir_entry {
std::string name;
+ uint8_t category;
uint64_t size;
utime_t mtime;
+ string etag;
+ string owner_id;
+ string owner_display_name;
uint64_t epoch;
void encode(bufferlist &bl) const {
::encode(name, bl);
::encode(mtime, bl);
::encode(epoch, bl);
+ ::encode(etag, bl);
+ ::encode(owner_id, bl);
+ ::encode(owner_display_name, bl);
}
void decode(bufferlist::iterator &bl) {
__u8 struct_v;
::decode(name, bl);
::decode(mtime, bl);
::decode(epoch, bl);
+ ::decode(etag, bl);
+ ::decode(owner_id, bl);
+ ::decode(owner_display_name, bl);
}
};
WRITE_CLASS_ENCODER(rgw_bucket_dir_entry)
-struct rgw_bucket_dir_header {
+struct rgw_bucket_category_stats {
uint64_t total_size;
+ uint64_t total_size_rounded;
uint64_t num_entries;
void encode(bufferlist &bl) const {
::decode(num_entries, bl);
}
};
+WRITE_CLASS_ENCODER(rgw_bucket_category_stats)
+
+struct rgw_bucket_dir_header {
+ map<uint8_t, rgw_bucket_category_stats> stats;
+
+ void encode(bufferlist &bl) const {
+ __u8 struct_v = 1;
+ ::encode(struct_v, bl);
+ ::encode(stats, bl);
+ }
+ void decode(bufferlist::iterator &bl) {
+ __u8 struct_v;
+ ::decode(struct_v, bl);
+ ::decode(stats, bl);
+ }
+};
WRITE_CLASS_ENCODER(rgw_bucket_dir_header)
struct rgw_bucket_dir {