From: Mykola Golub Date: Wed, 13 May 2020 12:15:39 +0000 (+0100) Subject: rbd-nbd: don't abuse rbd_cache_writethrough_until_flush X-Git-Tag: wip-pdonnell-testing-20200918.022351~1261^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=2f700460fb28e82ed088cb50c8cff7aaa13a8951;p=ceph-ci.git rbd-nbd: don't abuse rbd_cache_writethrough_until_flush If rbd_cache and rbd_cache_writethrough_until_flush options are set, do not use flush for internal purposes unless the user issued flush, so it won't unintentionally enable writeback cache when it is still unsafe. Signed-off-by: Mykola Golub --- diff --git a/src/tools/rbd_nbd/rbd-nbd.cc b/src/tools/rbd_nbd/rbd-nbd.cc index a9af90922c9..936dc3a05ca 100644 --- a/src/tools/rbd_nbd/rbd-nbd.cc +++ b/src/tools/rbd_nbd/rbd-nbd.cc @@ -168,13 +168,25 @@ public: , writer_thread(*this, &NBDServer::writer_entry) , quiesce_thread(*this, &NBDServer::quiesce_entry) , started(false) - {} + { + std::vector options; + image.config_list(&options); + for (auto &option : options) { + if ((option.name == std::string("rbd_cache") || + option.name == std::string("rbd_cache_writethrough_until_flush")) && + option.value == "false") { + allow_internal_flush = true; + break; + } + } + } private: ceph::mutex disconnect_lock = ceph::make_mutex("NBDServer::DisconnectLocker"); ceph::condition_variable disconnect_cond; std::atomic terminated = { false }; + std::atomic allow_internal_flush = { false }; void shutdown() { @@ -346,6 +358,7 @@ private: break; case NBD_CMD_FLUSH: image.aio_flush(c); + allow_internal_flush = true; break; case NBD_CMD_TRIM: image.aio_discard(pctx->request.from, pctx->request.len, c); @@ -418,6 +431,10 @@ signal: } void wait_inflight_io() { + if (!allow_internal_flush) { + return; + } + uint64_t features = 0; image.features(&features); if ((features & RBD_FEATURE_EXCLUSIVE_LOCK) != 0) {