From: Venky Shankar Date: Mon, 5 Nov 2018 05:49:44 +0000 (-0500) Subject: mds: generate random scrub tag when empty X-Git-Tag: v14.1.0~502^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=17045c43889b32ebaaba70923317d92087e39d6c;p=ceph.git mds: generate random scrub tag when empty With this, scrub operations are tagged with a random uuid if tag is unspecified. This also helps to show in-progress scrub operations via "scrub status" command (introduced in later commits). Signed-off-by: Venky Shankar --- diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 801b20a1e7f1..636e64ed796f 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -4110,7 +4110,8 @@ void CInode::validate_disk_state(CInode::validated_data *results, /** * Fetch backtrace and set tag if tag is non-empty */ - void fetch_backtrace_and_tag(CInode *in, std::string_view tag, + void fetch_backtrace_and_tag(CInode *in, + std::string_view tag, bool is_internal, Context *fin, int *bt_r, bufferlist *bt) { const int64_t pool = in->get_backtrace_pool(); @@ -4121,8 +4122,8 @@ void CInode::validate_disk_state(CInode::validated_data *results, in->mdcache->mds->objecter->read(oid, object_locator_t(pool), fetch, CEPH_NOSNAP, NULL, 0, fin); using ceph::encode; - if (!tag.empty()) { - ObjectOperation scrub_tag; + if (!is_internal) { + ObjectOperation scrub_tag; bufferlist tag_bl; encode(tag, tag_bl); scrub_tag.setxattr("scrub_tag", tag_bl); @@ -4153,10 +4154,11 @@ void CInode::validate_disk_state(CInode::validated_data *results, in->mdcache->mds->finisher); std::string_view tag = in->scrub_infop->header->get_tag(); + bool is_internal = in->scrub_infop->header->is_internal_tag(); // Rather than using the usual CInode::fetch_backtrace, // use a special variant that optionally writes a tag in the same // operation. - fetch_backtrace_and_tag(in, tag, conf, &results->backtrace.ondisk_read_retval, &bl); + fetch_backtrace_and_tag(in, tag, is_internal, conf, &results->backtrace.ondisk_read_retval, &bl); return false; } @@ -4800,12 +4802,8 @@ void CInode::scrub_finished(MDSInternalContextBase **c) { if (scrub_infop->header->get_origin() == this) { // We are at the point that a tagging scrub was initiated LogChannelRef clog = mdcache->mds->clog; - if (scrub_infop->header->get_tag().empty()) { - clog->info() << "scrub complete"; - } else { - clog->info() << "scrub complete with tag '" - << scrub_infop->header->get_tag() << "'"; - } + clog->info() << "scrub complete with tag '" + << scrub_infop->header->get_tag() << "'"; } } diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 94163ab8944f..2d841f77174b 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -12351,8 +12351,18 @@ void MDCache::enqueue_scrub( } C_MDS_EnqueueScrub *cs = new C_MDS_EnqueueScrub(f, fin); + + bool is_internal = false; + std::string tag_str(tag); + if (tag_str.empty()) { + uuid_d uuid_gen; + uuid_gen.generate_random(); + tag_str = uuid_gen.to_string(); + is_internal = true; + } + cs->header = std::make_shared( - tag, force, recursive, repair, f); + tag_str, is_internal, force, recursive, repair, f); mdr->internal_op_finish = cs; enqueue_scrub_work(mdr); diff --git a/src/mds/ScrubHeader.h b/src/mds/ScrubHeader.h index 02acc84fb520..f49598d85e06 100644 --- a/src/mds/ScrubHeader.h +++ b/src/mds/ScrubHeader.h @@ -26,10 +26,10 @@ class CInode; */ class ScrubHeader { public: - ScrubHeader(std::string_view tag_, bool force_, bool recursive_, - bool repair_, Formatter *f_) - : tag(tag_), force(force_), recursive(recursive_), repair(repair_), - formatter(f_), origin(nullptr) + ScrubHeader(std::string_view tag_, bool is_tag_internal_, bool force_, + bool recursive_, bool repair_, Formatter *f_) + : tag(tag_), is_tag_internal(is_tag_internal_), force(force_), + recursive(recursive_), repair(repair_), formatter(f_), origin(nullptr) { ceph_assert(formatter != nullptr); } @@ -41,6 +41,7 @@ public: bool get_recursive() const { return recursive; } bool get_repair() const { return repair; } bool get_force() const { return force; } + bool is_internal_tag() const { return is_tag_internal; } CInode *get_origin() const { return origin; } std::string_view get_tag() const { return tag; } Formatter &get_formatter() const { return *formatter; } @@ -50,6 +51,7 @@ public: protected: const std::string tag; + bool is_tag_internal; const bool force; const bool recursive; const bool repair;