From 3a3bb6de3c47ac4a53db0f60769cb776b36dcbae Mon Sep 17 00:00:00 2001 From: Loic Dachary Date: Thu, 12 Feb 2015 15:34:40 +0100 Subject: [PATCH] common: capture check_experimental_feature_enabled message Implement check_experimental_feature_enabled so that it returns the message instead of unconditionally displaying it via derr. It allows the caller to display it in another context. Signed-off-by: Loic Dachary --- src/common/ceph_context.cc | 37 +++++++++++++++++++++++-------------- src/common/ceph_context.h | 4 +++- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 7f1adb091f4d5..79aff8b8cf181 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -182,27 +182,36 @@ public: } }; -bool CephContext::check_experimental_feature_enabled(std::string feat) +bool CephContext::check_experimental_feature_enabled(const std::string& feat) +{ + stringstream message; + bool enabled = check_experimental_feature_enabled(feat, &message); + lderr(this) << message.str() << dendl; + return enabled; +} + +bool CephContext::check_experimental_feature_enabled(const std::string& feat, + std::ostream *message) { ceph_spin_lock(&_feature_lock); bool enabled = _experimental_features.count(feat); ceph_spin_unlock(&_feature_lock); if (enabled) { - lderr(this) << "WARNING: experimental feature '" << feat << "' is enabled" << dendl; - lderr(this) << "Please be aware that this feature is experimental, untested," << dendl; - lderr(this) << "unsupported, and may result in data corruption, data loss," << dendl; - lderr(this) << "and/or irreparable damage to your cluster. Do not use" << dendl; - lderr(this) << "feature with important data." << dendl; + (*message) << "WARNING: experimental feature '" << feat << "' is enabled\n"; + (*message) << "Please be aware that this feature is experimental, untested,\n"; + (*message) << "unsupported, and may result in data corruption, data loss,\n"; + (*message) << "and/or irreparable damage to your cluster. Do not use\n"; + (*message) << "feature with important data.\n"; } else { - lderr(this) << "*** experimental feature '" << feat << "' is not enabled ***" << dendl; - lderr(this) << "This feature is marked as experimental, which means it" << dendl; - lderr(this) << " - is untested" << dendl; - lderr(this) << " - is unsupported" << dendl; - lderr(this) << " - may corrupt your data" << dendl; - lderr(this) << " - may break your cluster is an unrecoverable fashion" << dendl; - lderr(this) << "To enable this feature, add this to your ceph.conf:" << dendl; - lderr(this) << " enable experimental unrecoverable data corrupting features = " << feat << dendl; + (*message) << "*** experimental feature '" << feat << "' is not enabled ***\n"; + (*message) << "This feature is marked as experimental, which means it\n"; + (*message) << " - is untested\n"; + (*message) << " - is unsupported\n"; + (*message) << " - may corrupt your data\n"; + (*message) << " - may break your cluster is an unrecoverable fashion\n"; + (*message) << "To enable this feature, add this to your ceph.conf:\n"; + (*message) << " enable experimental unrecoverable data corrupting features = " << feat << "\n"; } return enabled; } diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index c332bdfa70bc3..a8dfec55410e7 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -126,7 +126,9 @@ public: CryptoHandler *get_crypto_handler(int type); /// check if experimental feature is enable, and emit appropriate warnings - bool check_experimental_feature_enabled(std::string feature); + bool check_experimental_feature_enabled(const std::string& feature); + bool check_experimental_feature_enabled(const std::string& feature, + std::ostream *message); private: CephContext(const CephContext &rhs); -- 2.39.5