]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cls_user: header cleanup
authorYehuda Sadeh <yehuda@inktank.com>
Mon, 13 Jan 2014 19:01:59 +0000 (11:01 -0800)
committerYehuda Sadeh <yehuda@inktank.com>
Fri, 24 Jan 2014 18:28:52 +0000 (10:28 -0800)
put stats under a new struct

Signed-off-by: Yehuda Sadeh <yehuda@inktank.com>
src/cls/user/cls_user.cc
src/cls/user/cls_user_types.cc
src/cls/user/cls_user_types.h
src/rgw/rgw_admin.cc
src/rgw/rgw_rados.cc

index ba172898bc296171a41a2e0005170dc7d2ce137a..a20075cc3c17e032c9a2c96bf2076f429f4569ed 100644 (file)
@@ -99,18 +99,18 @@ static int read_header(cls_method_context_t hctx, cls_user_header *header)
   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)
@@ -150,7 +150,7 @@ static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in,
       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",
@@ -162,12 +162,12 @@ static int cls_user_set_buckets_info(cls_method_context_t hctx, bufferlist *in,
     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);
   
@@ -212,7 +212,7 @@ static int cls_user_remove_bucket(cls_method_context_t hctx, bufferlist *in, buf
   }
 
   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());
index 59f0bdcac7a12047469d4eb519847fb78a65d00e..7edf2e13a7da6617bde4b335e3bd75ed4da8292a 100644 (file)
@@ -3,12 +3,17 @@
 
 #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);
+}
index d38bf9d1b39d82a66572bde55d4c33e269618b24..92cdd0be2641df1f159e56a1a9e815584879b744 100644 (file)
@@ -109,10 +109,7 @@ struct cls_user_bucket_entry {
 };
 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;
@@ -134,6 +131,27 @@ struct cls_user_header {
 
   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
index 0bef8864fc06a600c950a5cef35da3980ccd4e79..7470c7d8162752178ba6827ae148ae98d4c3f66f 100644 (file)
@@ -1981,7 +1981,7 @@ next:
       return -ret;
     }
 
-    encode_json("header", header, formatter);
+    encode_json("stats", header.stats, formatter);
     formatter->flush(cout);
   }
 
index f10003dfefcbd818862fdf75ba469211616cc110..9d45a6bfbb8509ee4d1a74425306d3c31c0e5dd6 100644 (file)
@@ -4717,12 +4717,13 @@ class RGWGetUserStatsContext : public RGWGetUserHeader_CB {
 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);
     }
@@ -4740,9 +4741,11 @@ int RGWRados::get_user_stats(const string& user, RGWStorageStats& 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;
 }