diff options
author | Sage Weil <sage@inktank.com> | 2013-07-15 15:55:39 -0700 |
---|---|---|
committer | Dan Mick <dan.mick@inktank.com> | 2013-07-16 15:13:30 -0700 |
commit | 93fc07c184c9f48702ef76437e414cd2423c6278 (patch) | |
tree | 25a8d698e814a79f66ee0b9dcd3b6963bfae804d | |
parent | 0d66c9ebbf626117c641c975a8682a0aaba588c4 (diff) | |
download | ceph-93fc07c184c9f48702ef76437e414cd2423c6278.tar.gz |
crush: add is_valid_crush_name() helper
[A-Za-z0-9-_.]+
Signed-off-by: Sage Weil <sage@inktank.com>
Reviewed-by: Dan Mick <dan.mick@inktank.com>
-rw-r--r-- | src/crush/CrushWrapper.cc | 17 | ||||
-rw-r--r-- | src/crush/CrushWrapper.h | 3 |
2 files changed, 20 insertions, 0 deletions
diff --git a/src/crush/CrushWrapper.cc b/src/crush/CrushWrapper.cc index 8a9addfb6c2..1a4097c08b9 100644 --- a/src/crush/CrushWrapper.cc +++ b/src/crush/CrushWrapper.cc @@ -1109,3 +1109,20 @@ void CrushWrapper::generate_test_instances(list<CrushWrapper*>& o) o.push_back(new CrushWrapper); // fixme } + + +bool CrushWrapper::is_valid_crush_name(const string& s) +{ + if (s.empty()) + return false; + for (string::const_iterator p = s.begin(); p != s.end(); ++p) { + if (!(*p == '-') && + !(*p == '_') && + !(*p == '.') && + !(*p >= '0' && *p <= '9') && + !(*p >= 'A' && *p <= 'Z') && + !(*p >= 'a' && *p <= 'z')) + return false; + } + return true; +} diff --git a/src/crush/CrushWrapper.h b/src/crush/CrushWrapper.h index f5a88c8bdd5..f399e342110 100644 --- a/src/crush/CrushWrapper.h +++ b/src/crush/CrushWrapper.h @@ -790,6 +790,9 @@ public: void dump_rules(Formatter *f) const; void list_rules(Formatter *f) const; static void generate_test_instances(list<CrushWrapper*>& o); + + + static bool is_valid_crush_name(const string& s); }; WRITE_CLASS_ENCODER(CrushWrapper) |