]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: dissect accounting interface from RGWClientIO.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 28 Jul 2016 13:48:53 +0000 (15:48 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 21 Oct 2016 20:57:18 +0000 (22:57 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_client_io.h
src/rgw/rgw_lib.h
src/rgw/rgw_log.cc

index 1012ca0985b71809c75374892228ecc6d6f6cede..b2465141c029e141b9e5b4041c613995dd277282 100644 (file)
@@ -28,10 +28,18 @@ public:
   }
 
   virtual int complete_request() = 0; /* XXX signature likely changing */
+}; /* RGWClient IO */
+
+
+class RGWClientIOAccounter {
+public:
+  virtual ~RGWClientIOAccounter() {}
+
+  virtual void set_account(bool enabled) = 0;
 
   virtual uint64_t get_bytes_sent() const = 0;
   virtual uint64_t get_bytes_received() const = 0;
-}; /* RGWClient IO */
+};
 
 
 class RGWStreamIOEngine : public RGWClientIO {
@@ -52,8 +60,10 @@ public:
   int read(char *buf, int max, int *actual);
 };
 
+
 /* HTTP IO: compatibility layer */
-class RGWStreamIO : public RGWStreamIOEngine {
+class RGWStreamIO : public RGWStreamIOEngine,
+                    public RGWClientIOAccounter {
   bool _account;
   size_t bytes_sent;
   size_t bytes_received;
@@ -80,7 +90,7 @@ public:
 
   std::string grab_aws4_sha256_hash();
 
-  void set_account(bool _accnt) {
+  void set_account(bool _accnt) override {
     _account = _accnt;
   }
 
index 5c66c2b26df0732140c195bfa55cbdb557efde3b..96b52cebc66f541ddd78e4fbfcd75193b3ff125f 100644 (file)
@@ -50,7 +50,8 @@ namespace rgw {
 
 /* request interface */
 
-  class RGWLibIO : public RGWClientIO
+  class RGWLibIO : public RGWClientIO,
+                   public RGWClientIOAccounter
   {
     RGWUserInfo user_info;
   public:
@@ -79,6 +80,10 @@ namespace rgw {
       return 0;
     };
 
+    void set_account(bool) override {
+      return;
+    }
+
     uint64_t get_bytes_sent() const override {
       return 0;
     }
index 3bef606b1041288d2d6d009c76a687685d0a2a6e..84c66c420f4d07eeefbce4fb1ece83d9de88049e 100644 (file)
@@ -179,6 +179,10 @@ void rgw_log_usage_finalize()
   usage_logger = NULL;
 }
 
+static inline RGWClientIOAccounter* ACCOUNTING_IO(struct req_state* s) {
+  return dynamic_cast<RGWClientIOAccounter*>(s->cio);
+}
+
 static void log_usage(struct req_state *s, const string& op_name)
 {
   if (s->system_request) /* don't log system user operations */
@@ -211,8 +215,8 @@ static void log_usage(struct req_state *s, const string& op_name)
   string p = payer.to_str();
   rgw_usage_log_entry entry(u, p, bucket_name);
 
-  uint64_t bytes_sent = s->cio->get_bytes_sent();
-  uint64_t bytes_received = s->cio->get_bytes_received();
+  uint64_t bytes_sent = ACCOUNTING_IO(s)->get_bytes_sent();
+  uint64_t bytes_received = ACCOUNTING_IO(s)->get_bytes_received();
 
   rgw_usage_data data(bytes_sent, bytes_received);
 
@@ -344,8 +348,8 @@ int rgw_log_op(RGWRados *store, struct req_state *s, const string& op_name, OpsL
     entry.object_owner = s->object_acl->get_owner().get_id();
   entry.bucket_owner = s->bucket_owner.get_id();
 
-  uint64_t bytes_sent = s->cio->get_bytes_sent();
-  uint64_t bytes_received = s->cio->get_bytes_received();
+  uint64_t bytes_sent = ACCOUNTING_IO(s)->get_bytes_sent();
+  uint64_t bytes_received = ACCOUNTING_IO(s)->get_bytes_received();
 
   entry.time = s->time;
   entry.total_time = ceph_clock_now(s->cct) - s->time;