]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_rgw: store more info for each entry, stats categories
authorYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 21 Sep 2011 23:19:02 +0000 (16:19 -0700)
committerYehuda Sadeh <yehuda@hq.newdream.net>
Wed, 21 Sep 2011 23:19:02 +0000 (16:19 -0700)
src/cls_rgw.cc
src/rgw/rgw_cls_api.h

index 6b9bb9f0b1c778472ea09efa874795c8af181053..83cfe390437f6f3a643cfd3a4efd063260a560ac 100644 (file)
@@ -17,6 +17,14 @@ cls_method_handle_t h_rgw_bucket_init_index;
 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;
@@ -133,6 +141,11 @@ int rgw_bucket_modify(cls_method_context_t hctx, bufferlist *in, bufferlist *out
       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) {
@@ -143,7 +156,13 @@ int rgw_bucket_modify(cls_method_context_t hctx, bufferlist *in, bufferlist *out
       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;
   }
 
index 5ca4bc7a1b2225584ef730d4ec6021edd167f200..ccbb85a6038ccbea924e8960ea94d92ed8f1bb55 100644 (file)
@@ -8,8 +8,12 @@
 
 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 {
@@ -18,6 +22,9 @@ struct rgw_bucket_dir_entry {
     ::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;
@@ -25,12 +32,16 @@ struct rgw_bucket_dir_entry {
     ::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 {
@@ -46,6 +57,22 @@ struct rgw_bucket_dir_header {
     ::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 {