From: Radoslaw Zarzynski Date: Fri, 16 Aug 2019 09:46:35 +0000 (-0400) Subject: objclass, osd: improve const-correctness of PGLSFilter. X-Git-Tag: v15.1.0~1790^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2228b7f12b961b741bcb169c7fadf4a760ff65f6;p=ceph.git objclass, osd: improve const-correctness of PGLSFilter. Signed-off-by: Radoslaw Zarzynski --- diff --git a/src/cls/cephfs/cls_cephfs.cc b/src/cls/cephfs/cls_cephfs.cc index 3500ae6e497c..d05fee1d6ea7 100644 --- a/src/cls/cephfs/cls_cephfs.cc +++ b/src/cls/cephfs/cls_cephfs.cc @@ -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; diff --git a/src/cls/hello/cls_hello.cc b/src/cls/hello/cls_hello.cc index 261b0f60e061..ac3beb3b6871 100644 --- a/src/cls/hello/cls_hello.cc +++ b/src/cls/hello/cls_hello.cc @@ -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()); } }; diff --git a/src/objclass/objclass.h b/src/objclass/objclass.h index 703f0cf706c5..21fce9322946 100644 --- a/src/objclass/objclass.h +++ b/src/objclass/objclass.h @@ -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 diff --git a/src/osd/PrimaryLogPG.cc b/src/osd/PrimaryLogPG.cc index 9ef2e93bf925..6d0987b07627 100644 --- a/src/osd/PrimaryLogPG.cc +++ b/src/osd/PrimaryLogPG.cc @@ -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> +std::pair> PrimaryLogPG::get_pgls_filter(bufferlist::const_iterator& iter) { string type; + // storing non-const PGLSFilter for the sake of ::init() std::unique_ptr filter; try { @@ -1038,7 +1031,7 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op) vector ops = m->ops; for (vector::iterator p = ops.begin(); p != ops.end(); ++p) { - std::unique_ptr filter; + std::unique_ptr filter; OSDOp& osd_op = *p; auto bp = p->indata.cbegin(); switch (p->op.op) { diff --git a/src/osd/PrimaryLogPG.h b/src/osd/PrimaryLogPG.h index 674653ca30e9..e8eeca9e0094 100644 --- a/src/osd/PrimaryLogPG.h +++ b/src/osd/PrimaryLogPG.h @@ -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> get_pgls_filter( + std::pair> get_pgls_filter( bufferlist::const_iterator& iter); map> in_progress_proxy_ops;