From: Mingxin Liu Date: Mon, 27 Jun 2016 06:35:45 +0000 (+0800) Subject: tools/rados: add --with-clones option to include clones for cache-flush/cache-evict X-Git-Tag: v10.2.6~30^2~3^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=c74a4fa811e40dda2ed331ca885183542c301913;p=ceph.git tools/rados: add --with-clones option to include clones for cache-flush/cache-evict Signed-off-by: Mingxin Liu (cherry picked from commit 3dd9fa2fb39c76ba3977d7bc09cd28bb3465d56c) --- diff --git a/src/tools/rados/rados.cc b/src/tools/rados/rados.cc index 4f53a68ed8a7a..f91835dc63e4b 100644 --- a/src/tools/rados/rados.cc +++ b/src/tools/rados/rados.cc @@ -219,6 +219,8 @@ void usage(ostream& out) " --read-percent percent of operations that are read\n" " --target-throughput target throughput (in bytes)\n" " --run-length total time (in seconds)\n" +"CACHE POOLS OPTIONS:\n" +" --with-clones include clones when doing flush or evict\n" ; } @@ -1548,6 +1550,7 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, bool cleanup = true; bool no_verify = false; bool use_striper = false; + bool with_clones = false; const char *snapname = NULL; snap_t snapid = CEPH_NOSNAP; std::map::const_iterator i; @@ -1755,6 +1758,10 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, if (i != opts.end()) { bench_write_dest |= static_cast(OP_WRITE_DEST_XATTR); } + i = opts.find("with-clones"); + if (i != opts.end()) { + with_clones = true; + } // open rados ret = rados.init_with_context(g_ceph_context); @@ -3167,31 +3174,100 @@ static int rados_tool_common(const std::map < std::string, std::string > &opts, if (!pool_name || nargs.size() < 2) usage_exit(); string oid(nargs[1]); - ret = do_cache_flush(io_ctx, oid); - if (ret < 0) { - cerr << "error from cache-flush " << oid << ": " - << cpp_strerror(ret) << std::endl; - goto out; + if (with_clones) { + snap_set_t ls; + io_ctx.snap_set_read(LIBRADOS_SNAP_DIR); + ret = io_ctx.list_snaps(oid, &ls); + if (ret < 0) { + cerr << "error listing snapshots " << pool_name << "/" << oid << ": " + << cpp_strerror(ret) << std::endl; + goto out; + } + for (std::vector::iterator ci = ls.clones.begin(); + ci != ls.clones.end(); ++ci) { + if (snapid != CEPH_NOSNAP && ci->cloneid > snapid) + break; + io_ctx.snap_set_read(ci->cloneid); + ret = do_cache_flush(io_ctx, oid); + if (ret < 0) { + cerr << "error from cache-flush " << oid << ": " + << cpp_strerror(ret) << std::endl; + goto out; + } + } + } else { + ret = do_cache_flush(io_ctx, oid); + if (ret < 0) { + cerr << "error from cache-flush " << oid << ": " + << cpp_strerror(ret) << std::endl; + goto out; + } } } else if (strcmp(nargs[0], "cache-try-flush") == 0) { if (!pool_name || nargs.size() < 2) usage_exit(); string oid(nargs[1]); - ret = do_cache_try_flush(io_ctx, oid); - if (ret < 0) { - cerr << "error from cache-try-flush " << oid << ": " - << cpp_strerror(ret) << std::endl; - goto out; + if (with_clones) { + snap_set_t ls; + io_ctx.snap_set_read(LIBRADOS_SNAP_DIR); + ret = io_ctx.list_snaps(oid, &ls); + if (ret < 0) { + cerr << "error listing snapshots " << pool_name << "/" << oid << ": " + << cpp_strerror(ret) << std::endl; + goto out; + } + for (std::vector::iterator ci = ls.clones.begin(); + ci != ls.clones.end(); ++ci) { + if (snapid != CEPH_NOSNAP && ci->cloneid > snapid) + break; + io_ctx.snap_set_read(ci->cloneid); + ret = do_cache_try_flush(io_ctx, oid); + if (ret < 0) { + cerr << "error from cache-flush " << oid << ": " + << cpp_strerror(ret) << std::endl; + goto out; + } + } + } else { + ret = do_cache_try_flush(io_ctx, oid); + if (ret < 0) { + cerr << "error from cache-flush " << oid << ": " + << cpp_strerror(ret) << std::endl; + goto out; + } } } else if (strcmp(nargs[0], "cache-evict") == 0) { if (!pool_name || nargs.size() < 2) usage_exit(); string oid(nargs[1]); - ret = do_cache_evict(io_ctx, oid); - if (ret < 0) { - cerr << "error from cache-evict " << oid << ": " - << cpp_strerror(ret) << std::endl; - goto out; + if (with_clones) { + snap_set_t ls; + io_ctx.snap_set_read(LIBRADOS_SNAP_DIR); + ret = io_ctx.list_snaps(oid, &ls); + if (ret < 0) { + cerr << "error listing snapshots " << pool_name << "/" << oid << ": " + << cpp_strerror(ret) << std::endl; + goto out; + } + for (std::vector::iterator ci = ls.clones.begin(); + ci != ls.clones.end(); ++ci) { + if (snapid != CEPH_NOSNAP && ci->cloneid > snapid) + break; + io_ctx.snap_set_read(ci->cloneid); + ret = do_cache_evict(io_ctx, oid); + if (ret < 0) { + cerr << "error from cache-flush " << oid << ": " + << cpp_strerror(ret) << std::endl; + goto out; + } + } + } else { + ret = do_cache_evict(io_ctx, oid); + if (ret < 0) { + cerr << "error from cache-flush " << oid << ": " + << cpp_strerror(ret) << std::endl; + goto out; + } } } else if (strcmp(nargs[0], "cache-flush-evict-all") == 0) { if (!pool_name) @@ -3410,6 +3486,8 @@ int main(int argc, const char **argv) opts["write-dest-obj"] = "true"; } else if (ceph_argparse_flag(args, i, "--write-xattr", (char*)NULL)) { opts["write-dest-xattr"] = "true"; + } else if (ceph_argparse_flag(args, i, "--with-clones", (char*)NULL)) { + opts["with-clones"] = "true"; } else { if (val[0] == '-') usage_exit();