]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
objclass, osd: improve const-correctness of PGLSFilter. 29575/head
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 16 Aug 2019 09:46:35 +0000 (05:46 -0400)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 16 Aug 2019 14:58:55 +0000 (10:58 -0400)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/cls/cephfs/cls_cephfs.cc
src/cls/hello/cls_hello.cc
src/objclass/objclass.h
src/osd/PrimaryLogPG.cc
src/osd/PrimaryLogPG.h

index 3500ae6e497c72e57c5478ae97fb1bf45ecccb87..d05fee1d6ea7f6fc6db4ba50dfe5d29d89ef810a 100644 (file)
@@ -145,11 +145,13 @@ public:
   }
 
   ~PGLSCephFSFilter() override {}
-  bool reject_empty_xattr() override { return false; }
-  bool filter(const hobject_t &obj, bufferlist& xattr_data) override;
+  bool reject_empty_xattr() const override { return false; }
+  bool filter(const hobject_t& obj,
+              const bufferlist& xattr_data) const override;
 };
 
-bool PGLSCephFSFilter::filter(const hobject_t &obj, bufferlist& xattr_data)
+bool PGLSCephFSFilter::filter(const hobject_t &obj,
+                              const bufferlist& xattr_data) const
 {
   const std::string need_ending = ".00000000";
   const std::string &obj_name = obj.oid.name;
index 261b0f60e061ed969aca395ba4f8437d641ff85b..ac3beb3b6871addf7df0695f1d9513deec89303d 100644 (file)
@@ -266,15 +266,10 @@ public:
   }
 
   ~PGLSHelloFilter() override {}
-  bool filter(const hobject_t &obj, ceph::bufferlist& xattr_data) override
+  bool filter(const hobject_t& obj,
+              const bufferlist&  xattr_data) const override
   {
-    if (val.size() != xattr_data.length())
-      return false;
-
-    if (memcmp(val.c_str(), xattr_data.c_str(), val.size()))
-      return false;
-
-    return true;
+    return xattr_data.contents_equal(val.c_str(), val.size());
   }
 };
 
index 703f0cf706c509cd6f8193dd824fba59e2c221d4..21fce932294695120e70eee6c0e85708d9f254b6 100644 (file)
@@ -81,7 +81,8 @@ protected:
 public:
   PGLSFilter();
   virtual ~PGLSFilter();
-  virtual bool filter(const hobject_t &obj, ceph::buffer::list& xattr_data) = 0;
+  virtual bool filter(const hobject_t &obj,
+                      const ceph::buffer::list& xattr_data) const = 0;
 
   /**
    * Arguments passed from the RADOS client.  Implementations must
@@ -94,13 +95,13 @@ public:
    * xattr key, or empty string.  If non-empty, this xattr will be fetched
    * and the value passed into ::filter
    */
-  virtual std::string& get_xattr() { return xattr; }
+  virtual const std::string& get_xattr() const { return xattr; }
 
   /**
    * If true, objects without the named xattr (if xattr name is not empty)
    * will be rejected without calling ::filter
    */
-  virtual bool reject_empty_xattr() { return true; }
+  virtual bool reject_empty_xattr() const { return true; }
 };
 
 // Classes expose a filter constructor that returns a subclass of PGLSFilter
index 9ef2e93bf92505080c56f90b2fb6bb7f1d08ad30..6d0987b076271eb29d0690d6ca3d66af5e76cc77 100644 (file)
@@ -776,21 +776,13 @@ public:
     return 0;
   }
   ~PGLSPlainFilter() override {}
-  bool filter(const hobject_t &obj, bufferlist& xattr_data) override;
+  bool filter(const hobject_t& obj,
+              const bufferlist& xattr_data) const override {
+    return xattr_data.contents_equal(val.c_str(), val.size());
+  }
 };
 
-bool PGLSPlainFilter::filter(const hobject_t &obj, bufferlist& xattr_data)
-{
-  if (val.size() != xattr_data.length())
-    return false;
-
-  if (memcmp(val.c_str(), xattr_data.c_str(), val.size()))
-    return false;
-
-  return true;
-}
-
-bool PrimaryLogPG::pgls_filter(PGLSFilter& filter, hobject_t& sobj)
+bool PrimaryLogPG::pgls_filter(const PGLSFilter& filter, const hobject_t& sobj)
 {
   bufferlist bl;
 
@@ -811,10 +803,11 @@ bool PrimaryLogPG::pgls_filter(PGLSFilter& filter, hobject_t& sobj)
   return filter.filter(sobj, bl);
 }
 
-std::pair<int, std::unique_ptr<PGLSFilter>>
+std::pair<int, std::unique_ptr<const PGLSFilter>>
 PrimaryLogPG::get_pgls_filter(bufferlist::const_iterator& iter)
 {
   string type;
+  // storing non-const PGLSFilter for the sake of ::init()
   std::unique_ptr<PGLSFilter> filter;
 
   try {
@@ -1038,7 +1031,7 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op)
   vector<OSDOp> ops = m->ops;
 
   for (vector<OSDOp>::iterator p = ops.begin(); p != ops.end(); ++p) {
-    std::unique_ptr<PGLSFilter> filter;
+    std::unique_ptr<const PGLSFilter> filter;
     OSDOp& osd_op = *p;
     auto bp = p->indata.cbegin();
     switch (p->op.op) {
index 674653ca30e92cb7e4a0292114fb0b9f47c3b2a6..e8eeca9e009406cc8c7292c4e56328d4912bfe9e 100644 (file)
@@ -1410,9 +1410,9 @@ protected:
   int do_sparse_read(OpContext *ctx, OSDOp& osd_op);
   int do_writesame(OpContext *ctx, OSDOp& osd_op);
 
-  bool pgls_filter(PGLSFilter& filter, hobject_t& sobj);
+  bool pgls_filter(const PGLSFilter& filter, const hobject_t& sobj);
 
-  std::pair<int, std::unique_ptr<PGLSFilter>> get_pgls_filter(
+  std::pair<int, std::unique_ptr<const PGLSFilter>> get_pgls_filter(
     bufferlist::const_iterator& iter);
 
   map<hobject_t, list<OpRequestRef>> in_progress_proxy_ops;