}
~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;
}
~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());
}
};
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
* 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
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;
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 {
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) {
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;