]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: refactor manufacturing of PGLSFilter.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 9 Aug 2019 12:19:51 +0000 (14:19 +0200)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Fri, 16 Aug 2019 14:58:53 +0000 (10:58 -0400)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/osd/PrimaryLogPG.cc
src/osd/PrimaryLogPG.h

index 95bb66194a27ac2514d413af79c422e12e905149..9ef2e93bf92505080c56f90b2fb6bb7f1d08ad30 100644 (file)
@@ -790,45 +790,46 @@ bool PGLSPlainFilter::filter(const hobject_t &obj, bufferlist& xattr_data)
   return true;
 }
 
-bool PrimaryLogPG::pgls_filter(PGLSFilter* filter, hobject_t& sobj)
+bool PrimaryLogPG::pgls_filter(PGLSFilter& filter, hobject_t& sobj)
 {
   bufferlist bl;
 
   // If filter has expressed an interest in an xattr, load it.
-  if (!filter->get_xattr().empty()) {
+  if (!filter.get_xattr().empty()) {
     int ret = pgbackend->objects_get_attr(
       sobj,
-      filter->get_xattr(),
+      filter.get_xattr(),
       &bl);
-    dout(0) << "getattr (sobj=" << sobj << ", attr=" << filter->get_xattr() << ") returned " << ret << dendl;
+    dout(0) << "getattr (sobj=" << sobj << ", attr=" << filter.get_xattr() << ") returned " << ret << dendl;
     if (ret < 0) {
-      if (ret != -ENODATA || filter->reject_empty_xattr()) {
+      if (ret != -ENODATA || filter.reject_empty_xattr()) {
         return false;
       }
     }
   }
 
-  return filter->filter(sobj, bl);
+  return filter.filter(sobj, bl);
 }
 
-int PrimaryLogPG::get_pgls_filter(bufferlist::const_iterator& iter, PGLSFilter **pfilter)
+std::pair<int, std::unique_ptr<PGLSFilter>>
+PrimaryLogPG::get_pgls_filter(bufferlist::const_iterator& iter)
 {
   string type;
-  PGLSFilter *filter;
+  std::unique_ptr<PGLSFilter> filter;
 
   try {
     decode(type, iter);
   }
   catch (buffer::error& e) {
-    return -EINVAL;
+    return { -EINVAL, nullptr };
   }
 
   if (type.compare("plain") == 0) {
-    filter = new PGLSPlainFilter();
+    filter = std::make_unique<PGLSPlainFilter>();
   } else {
     std::size_t dot = type.find(".");
     if (dot == std::string::npos || dot == 0 || dot == type.size() - 1) {
-      return -EINVAL;
+      return { -EINVAL, nullptr };
     }
 
     const std::string class_name = type.substr(0, dot);
@@ -840,7 +841,7 @@ int PrimaryLogPG::get_pgls_filter(bufferlist::const_iterator& iter, PGLSFilter *
            << cpp_strerror(r) << dendl;
       if (r != -EPERM) // propogate permission error
         r = -EINVAL;
-      return r;
+      return { r, nullptr };
     } else {
       ceph_assert(cls);
     }
@@ -849,15 +850,15 @@ int PrimaryLogPG::get_pgls_filter(bufferlist::const_iterator& iter, PGLSFilter *
     if (class_filter == NULL) {
       derr << "Error finding filter '" << filter_name << "' in class "
            << class_name << dendl;
-      return -EINVAL;
+      return { -EINVAL, nullptr };
     }
-    filter = class_filter->fn();
+    filter.reset(class_filter->fn());
     if (!filter) {
       // Object classes are obliged to return us something, but let's
       // give an error rather than asserting out.
       derr << "Buggy class " << class_name << " failed to construct "
               "filter " << filter_name << dendl;
-      return -EINVAL;
+      return { -EINVAL, nullptr };
     }
   }
 
@@ -866,12 +867,10 @@ int PrimaryLogPG::get_pgls_filter(bufferlist::const_iterator& iter, PGLSFilter *
   if (r < 0) {
     derr << "Error initializing filter " << type << ": "
          << cpp_strerror(r) << dendl;
-    delete filter;
-    return -EINVAL;
+    return { -EINVAL, nullptr };
   } else {
     // Successfully constructed and initialized, return it.
-    *pfilter = filter;
-    return 0;
+    return std::make_pair(0, std::move(filter));
   }
 }
 
@@ -1053,11 +1052,7 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op)
        result = -EINVAL;
        break;
       }
-      {
-        PGLSFilter* tmp_filter;
-        result = get_pgls_filter(bp, &tmp_filter);
-        filter.reset(tmp_filter);
-      }
+      std::tie(result, filter) = get_pgls_filter(bp);
       if (result < 0)
         break;
 
@@ -1179,7 +1174,7 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op)
                candidate.get_namespace() != m->get_hobj().nspace)
            continue;
 
-         if (filter && !pgls_filter(filter, candidate))
+         if (filter && !pgls_filter(*filter, candidate))
            continue;
 
           dout(20) << "pgnls item 0x" << std::hex
@@ -1223,12 +1218,7 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op)
        result = -EINVAL;
        break;
       }
-
-      {
-        PGLSFilter* tmp_filter;
-        result = get_pgls_filter(bp, &tmp_filter);
-        filter.reset(tmp_filter);
-      }
+      std::tie(result, filter) = get_pgls_filter(bp);
       if (result < 0)
         break;
 
@@ -1328,7 +1318,7 @@ void PrimaryLogPG::do_pg_op(OpRequestRef op)
          if (recovery_state.get_missing_loc().is_deleted(candidate))
            continue;
 
-         if (filter && !pgls_filter(filter, candidate))
+         if (filter && !pgls_filter(*filter, candidate))
            continue;
 
          response.entries.push_back(make_pair(candidate.oid,
index f3601874e9d76b5e82eb2120739ca0b15cfad0dc..674653ca30e92cb7e4a0292114fb0b9f47c3b2a6 100644 (file)
@@ -1410,8 +1410,10 @@ 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);
-  int get_pgls_filter(bufferlist::const_iterator& iter, PGLSFilter **pfilter);
+  bool pgls_filter(PGLSFilter& filter, hobject_t& sobj);
+
+  std::pair<int, std::unique_ptr<PGLSFilter>> get_pgls_filter(
+    bufferlist::const_iterator& iter);
 
   map<hobject_t, list<OpRequestRef>> in_progress_proxy_ops;
   void kick_proxy_ops_blocked(hobject_t& soid);