]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/rados: default to include clone objects when excuting "cache-flush-evict-all"
authorMingxin Liu <mingxin@xsky.com>
Sat, 25 Jun 2016 03:19:01 +0000 (11:19 +0800)
committerDavid Disseldorp <ddiss@suse.de>
Mon, 14 Nov 2016 15:08:28 +0000 (16:08 +0100)
Signed-off-by: Mingxin Liu <mingxin@xsky.com>
(cherry picked from commit b1cf2d9276834d04172d45d5f4dd48ca3e99d338)

src/tools/rados/rados.cc

index 09f95dd2b3779ec061dd29fdf8ca37ad92ab6de9..4f53a68ed8a7aff4411888a41c61caee4f16e5d9 100644 (file)
@@ -1189,22 +1189,59 @@ static int do_cache_flush_evict_all(IoCtx& io_ctx, bool blocking)
        io_ctx.locator_set_key(string());
       }
       io_ctx.set_namespace(i->get_nspace());
-      if (blocking)
-       r = do_cache_flush(io_ctx, i->get_oid());
-      else
-       r = do_cache_try_flush(io_ctx, i->get_oid());
+      snap_set_t ls;
+      io_ctx.snap_set_read(LIBRADOS_SNAP_DIR);
+      r = io_ctx.list_snaps(i->get_oid(), &ls);
       if (r < 0) {
-       cerr << "failed to flush " << i->get_nspace() << "/" << i->get_oid() << ": "
-            << cpp_strerror(r) << std::endl;
-       ++errors;
-       continue;
+        cerr << "error listing snap shots " << i->get_nspace() << "/" << i->get_oid() << ": "
+             << cpp_strerror(r) << std::endl;
+        ++errors;
+        continue;
       }
-      r = do_cache_evict(io_ctx, i->get_oid());
-      if (r < 0) {
-       cerr << "failed to evict " << i->get_nspace() << "/" << i->get_oid() << ": "
-            << cpp_strerror(r) << std::endl;
-       ++errors;
-       continue;
+      std::vector<clone_info_t>::iterator ci = ls.clones.begin();
+      // no snapshots
+      if (ci == ls.clones.end()) {
+        io_ctx.snap_set_read(CEPH_NOSNAP);
+        if (blocking)
+          r = do_cache_flush(io_ctx, i->get_oid());
+        else
+          r = do_cache_try_flush(io_ctx, i->get_oid());
+        if (r < 0) {
+          cerr << "failed to flush " << i->get_nspace() << "/" << i->get_oid() << ": "
+               << cpp_strerror(r) << std::endl;
+          ++errors;
+          continue;
+        }
+        r = do_cache_evict(io_ctx, i->get_oid());
+        if (r < 0) {
+          cerr << "failed to evict " << i->get_nspace() << "/" << i->get_oid() << ": "
+               << cpp_strerror(r) << std::endl;
+          ++errors;
+          continue;
+        }
+      } else {
+      // has snapshots
+        for (std::vector<clone_info_t>::iterator ci = ls.clones.begin();
+             ci != ls.clones.end(); ++ci) {
+          io_ctx.snap_set_read(ci->cloneid);
+          if (blocking)
+           r = do_cache_flush(io_ctx, i->get_oid());
+          else
+           r = do_cache_try_flush(io_ctx, i->get_oid());
+          if (r < 0) {
+           cerr << "failed to flush " << i->get_nspace() << "/" << i->get_oid() << ": "
+                << cpp_strerror(r) << std::endl;
+           ++errors;
+           break;
+          }
+          r = do_cache_evict(io_ctx, i->get_oid());
+          if (r < 0) {
+           cerr << "failed to evict " << i->get_nspace() << "/" << i->get_oid() << ": "
+                << cpp_strerror(r) << std::endl;
+           ++errors;
+           break;
+          }
+        }
       }
     }
   }