]> git-server-git.apps.pok.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)
committerMingxin Liu <mingxin@xsky.com>
Mon, 27 Jun 2016 09:41:32 +0000 (17:41 +0800)
Signed-off-by: Mingxin Liu <mingxin@xsky.com>
src/tools/rados/rados.cc

index 79d03f8f87781bf90e54522f473fb1ffa6d38bff..585bca5c7a4b49174f1c96a55880331ef8424449 100644 (file)
@@ -1190,22 +1190,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;
+          }
+        }
       }
     }
   }