From: Patrick Donnelly Date: Mon, 15 Jan 2018 22:30:55 +0000 (-0800) Subject: mds: convert to allocator agnostic string_view X-Git-Tag: v13.0.2~309^2~8 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0c8ec93af7d7437d1ffd646be407c4bf64f505b4;p=ceph.git mds: convert to allocator agnostic string_view This is necessary to allow many interfaces to take mempool allocated strings. Signed-off-by: Patrick Donnelly --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 4265fa79b604e..69e0d74fb0081 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7610,7 +7610,7 @@ int Client::_readdir_get_frag(dir_result_t *dirp) req->head.args.readdir.frag = fg; req->head.args.readdir.flags = CEPH_READDIR_REPLY_BITFLAGS; if (dirp->last_name.length()) { - req->path2.set_path(dirp->last_name.c_str()); + req->path2.set_path(dirp->last_name); } else if (dirp->hash_order()) { req->head.args.readdir.offset_hash = dirp->offset_high(); } diff --git a/src/client/MetaRequest.h b/src/client/MetaRequest.h index 76c430fc0212e..dddd87cdddd00 100644 --- a/src/client/MetaRequest.h +++ b/src/client/MetaRequest.h @@ -169,7 +169,7 @@ public: void set_retry_attempt(int a) { head.num_retry = a; } void set_filepath(const filepath& fp) { path = fp; } void set_filepath2(const filepath& fp) { path2 = fp; } - void set_string2(const char *s) { path2.set_path(s, 0); } + void set_string2(const char *s) { path2.set_path(std::string_view(s), 0); } void set_caller_perms(const UserPerm& _perms) { perms.shallow_copy(_perms); head.caller_uid = perms.uid(); diff --git a/src/common/Formatter.cc b/src/common/Formatter.cc index 3b3589db805ca..3375cb792c390 100644 --- a/src/common/Formatter.cc +++ b/src/common/Formatter.cc @@ -52,11 +52,11 @@ Formatter::Formatter() { } Formatter::~Formatter() { } -Formatter *Formatter::create(const std::string &type, - const std::string& default_type, - const std::string& fallback) +Formatter *Formatter::create(std::string_view type, + std::string_view default_type, + std::string_view fallback) { - std::string mytype = type; + std::string mytype(type); if (mytype == "") mytype = default_type; @@ -161,11 +161,11 @@ void JSONFormatter::print_comma(json_formatter_stack_entry_d& entry) m_ss << " "; } -void JSONFormatter::print_quoted_string(const std::string& s) +void JSONFormatter::print_quoted_string(std::string_view s) { - int len = escape_json_attr_len(s.c_str(), s.size()); + int len = escape_json_attr_len(s.data(), s.size()); char escaped[len]; - escape_json_attr(s.c_str(), s.size(), escaped); + escape_json_attr(s.data(), s.size(), escaped); m_ss << '\"' << escaped << '\"'; } @@ -272,7 +272,7 @@ void JSONFormatter::dump_float(const char *name, double d) m_ss << foo; } -void JSONFormatter::dump_string(const char *name, const std::string& s) +void JSONFormatter::dump_string(const char *name, std::string_view s) { print_name(name); print_quoted_string(s); @@ -443,19 +443,19 @@ void XMLFormatter::dump_float(const char *name, double d) m_ss << "\n"; } -void XMLFormatter::dump_string(const char *name, const std::string& s) +void XMLFormatter::dump_string(const char *name, std::string_view s) { std::string e(name); std::transform(e.begin(), e.end(), e.begin(), [this](char c) { return this->to_lower_underscore(c); }); print_spaces(); - m_ss << "<" << e << ">" << escape_xml_str(s.c_str()) << ""; + m_ss << "<" << e << ">" << escape_xml_str(s.data()) << ""; if (m_pretty) m_ss << "\n"; } -void XMLFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) +void XMLFormatter::dump_string_with_attrs(const char *name, std::string_view s, const FormatterAttrs& attrs) { std::string e(name); std::transform(e.begin(), e.end(), e.begin(), @@ -464,7 +464,7 @@ void XMLFormatter::dump_string_with_attrs(const char *name, const std::string& s std::string attrs_str; get_attrs_str(&attrs, attrs_str); print_spaces(); - m_ss << "<" << e << attrs_str << ">" << escape_xml_str(s.c_str()) << ""; + m_ss << "<" << e << attrs_str << ">" << escape_xml_str(s.data()) << ""; if (m_pretty) m_ss << "\n"; } @@ -564,11 +564,11 @@ void XMLFormatter::print_spaces() } } -std::string XMLFormatter::escape_xml_str(const char *str) +std::string XMLFormatter::escape_xml_str(std::string_view str) { - int len = escape_xml_attr_len(str); + size_t len = escape_xml_attr_len(str.data()); std::vector escaped(len, '\0'); - escape_xml_attr(str, &escaped[0]); + escape_xml_attr(str.data(), &escaped[0]); return std::string(&escaped[0]); } @@ -837,7 +837,7 @@ void TableFormatter::dump_float(const char *name, double d) m_ss.str(""); } -void TableFormatter::dump_string(const char *name, const std::string& s) +void TableFormatter::dump_string(const char *name, std::string_view s) { finish_pending_string(); size_t i = m_vec_index(name); @@ -848,7 +848,7 @@ void TableFormatter::dump_string(const char *name, const std::string& s) m_ss.str(""); } -void TableFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) +void TableFormatter::dump_string_with_attrs(const char *name, std::string_view s, const FormatterAttrs& attrs) { finish_pending_string(); size_t i = m_vec_index(name); diff --git a/src/common/Formatter.h b/src/common/Formatter.h index df6c0a99a5eba..6cfe60dac04a1 100644 --- a/src/common/Formatter.h +++ b/src/common/Formatter.h @@ -23,14 +23,14 @@ namespace ceph { class Formatter { public: - static Formatter *create(const std::string& type, - const std::string& default_type, - const std::string& fallback); - static Formatter *create(const std::string& type, - const std::string& default_type) { + static Formatter *create(std::string_view type, + std::string_view default_type, + std::string_view fallback); + static Formatter *create(std::string_view type, + std::string_view default_type) { return create(type, default_type, ""); } - static Formatter *create(const std::string& type) { + static Formatter *create(std::string_view type) { return create(type, "json-pretty", ""); } @@ -54,7 +54,7 @@ namespace ceph { virtual void dump_unsigned(const char *name, uint64_t u) = 0; virtual void dump_int(const char *name, int64_t s) = 0; virtual void dump_float(const char *name, double d) = 0; - virtual void dump_string(const char *name, const std::string& s) = 0; + virtual void dump_string(const char *name, std::string_view s) = 0; virtual void dump_bool(const char *name, bool b) { dump_format_unquoted(name, "%s", (b ? "true" : "false")); @@ -81,7 +81,7 @@ namespace ceph { { open_object_section(name); } - virtual void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) + virtual void dump_string_with_attrs(const char *name, std::string_view s, const FormatterAttrs& attrs) { dump_string(name, s); } @@ -106,7 +106,7 @@ namespace ceph { void dump_unsigned(const char *name, uint64_t u) override; void dump_int(const char *name, int64_t u) override; void dump_float(const char *name, double d) override; - void dump_string(const char *name, const std::string& s) override; + void dump_string(const char *name, std::string_view s) override; std::ostream& dump_stream(const char *name) override; void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) override; int get_len() const override; @@ -122,7 +122,7 @@ namespace ceph { bool m_pretty; void open_section(const char *name, bool is_array); - void print_quoted_string(const std::string& s); + void print_quoted_string(std::string_view s); void print_name(const char *name); void print_comma(json_formatter_stack_entry_d& entry); void finish_pending_string(); @@ -154,7 +154,7 @@ namespace ceph { void dump_unsigned(const char *name, uint64_t u) override; void dump_int(const char *name, int64_t u) override; void dump_float(const char *name, double d) override; - void dump_string(const char *name, const std::string& s) override; + void dump_string(const char *name, std::string_view s) override; std::ostream& dump_stream(const char *name) override; void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) override; int get_len() const override; @@ -163,13 +163,13 @@ namespace ceph { /* with attrs */ void open_array_section_with_attrs(const char *name, const FormatterAttrs& attrs) override; void open_object_section_with_attrs(const char *name, const FormatterAttrs& attrs) override; - void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) override; + void dump_string_with_attrs(const char *name, std::string_view s, const FormatterAttrs& attrs) override; protected: void open_section_in_ns(const char *name, const char *ns, const FormatterAttrs *attrs); void finish_pending_string(); void print_spaces(); - static std::string escape_xml_str(const char *str); + static std::string escape_xml_str(std::string_view str); void get_attrs_str(const FormatterAttrs *attrs, std::string& attrs_str); char to_lower_underscore(char c) const; @@ -206,9 +206,9 @@ namespace ceph { void dump_unsigned(const char *name, uint64_t u) override; void dump_int(const char *name, int64_t u) override; void dump_float(const char *name, double d) override; - void dump_string(const char *name, const std::string& s) override; + void dump_string(const char *name, std::string_view s) override; void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) override; - void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) override; + void dump_string_with_attrs(const char *name, std::string_view s, const FormatterAttrs& attrs) override; std::ostream& dump_stream(const char *name) override; int get_len() const override; diff --git a/src/common/HTMLFormatter.cc b/src/common/HTMLFormatter.cc index 02ef744c4cbc7..c096ec5ceea64 100644 --- a/src/common/HTMLFormatter.cc +++ b/src/common/HTMLFormatter.cc @@ -107,18 +107,18 @@ void HTMLFormatter::dump_float(const char *name, double d) dump_template(name, d); } -void HTMLFormatter::dump_string(const char *name, const std::string& s) +void HTMLFormatter::dump_string(const char *name, std::string_view s) { - dump_template(name, escape_xml_str(s.c_str())); + dump_template(name, escape_xml_str(s.data())); } -void HTMLFormatter::dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) +void HTMLFormatter::dump_string_with_attrs(const char *name, std::string_view s, const FormatterAttrs& attrs) { std::string e(name); std::string attrs_str; get_attrs_str(&attrs, attrs_str); print_spaces(); - m_ss << "
  • " << e << ": " << escape_xml_str(s.c_str()) << attrs_str << "
  • "; + m_ss << "
  • " << e << ": " << escape_xml_str(s.data()) << attrs_str << "
  • "; if (m_pretty) m_ss << "\n"; } diff --git a/src/common/HTMLFormatter.h b/src/common/HTMLFormatter.h index c59296922478b..ab725062bebae 100644 --- a/src/common/HTMLFormatter.h +++ b/src/common/HTMLFormatter.h @@ -18,12 +18,12 @@ namespace ceph { void dump_unsigned(const char *name, uint64_t u) override; void dump_int(const char *name, int64_t u) override; void dump_float(const char *name, double d) override; - void dump_string(const char *name, const std::string& s) override; + void dump_string(const char *name, std::string_view s) override; std::ostream& dump_stream(const char *name) override; void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) override; /* with attrs */ - void dump_string_with_attrs(const char *name, const std::string& s, const FormatterAttrs& attrs) override; + void dump_string_with_attrs(const char *name, std::string_view s, const FormatterAttrs& attrs) override; private: template void dump_template(const char *name, T arg); diff --git a/src/include/encoding.h b/src/include/encoding.h index 943b42c8a1b3c..a13393ccfd420 100644 --- a/src/include/encoding.h +++ b/src/include/encoding.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -179,13 +180,17 @@ WRITE_INTTYPE_ENCODER(int16_t, le16) // string -inline void encode(const std::string& s, bufferlist& bl, uint64_t features=0) +inline void encode(std::string_view s, bufferlist& bl, uint64_t features=0) { __u32 len = s.length(); encode(len, bl); if (len) bl.append(s.data(), len); } +inline void encode(const std::string& s, bufferlist& bl, uint64_t features=0) +{ + return encode(std::string_view(s), bl, features); +} inline void decode(std::string& s, bufferlist::iterator& p) { __u32 len; @@ -194,10 +199,14 @@ inline void decode(std::string& s, bufferlist::iterator& p) p.copy(len, s); } -inline void encode_nohead(const std::string& s, bufferlist& bl) +inline void encode_nohead(std::string_view s, bufferlist& bl) { bl.append(s.data(), s.length()); } +inline void encode_nohead(const std::string& s, bufferlist& bl) +{ + encode_nohead(std::string_view(s), bl); +} inline void decode_nohead(int len, std::string& s, bufferlist::iterator& p) { s.clear(); @@ -207,10 +216,7 @@ inline void decode_nohead(int len, std::string& s, bufferlist::iterator& p) // const char* (encode only, string compatible) inline void encode(const char *s, bufferlist& bl) { - __u32 len = strlen(s); - encode(len, bl); - if (len) - bl.append(s, len); + encode(std::string_view(s, strlen(s)), bl); } diff --git a/src/include/filepath.h b/src/include/filepath.h index ae3430f6f80f8..096e40388eafb 100644 --- a/src/include/filepath.h +++ b/src/include/filepath.h @@ -25,6 +25,7 @@ #include #include +#include #include #include "buffer.h" @@ -72,6 +73,7 @@ class filepath { public: filepath() : ino(0), encoded(false) { } + filepath(std::string_view s, inodeno_t i) : ino(i), path(s), encoded(false) { } filepath(const string& s, inodeno_t i) : ino(i), path(s), encoded(false) { } filepath(const char* s, inodeno_t i) : ino(i), path(s), encoded(false) { } filepath(const filepath& o) { @@ -82,21 +84,24 @@ class filepath { } filepath(inodeno_t i) : ino(i), encoded(false) { } - void set_path(const char *s, inodeno_t b) { - path = s; - ino = b; - } - /* * if we are fed a relative path as a string, either set ino=0 (strictly * relative) or 1 (absolute). throw out any leading '/'. */ - filepath(const char *s) : encoded(false) { + filepath(std::string_view s) : encoded(false) { set_path(s); } - void set_path(const char *s) { + filepath(const char *s) : encoded(false) { + set_path(std::string_view(s)); + } + + void set_path(std::string_view s, inodeno_t b) { + path = s; + ino = b; + } + void set_path(std::string_view s) { if (s[0] == '/') { - path = s + 1; + path = s.substr(1); ino = 1; } else { ino = 0; @@ -162,17 +167,19 @@ class filepath { bits.pop_back(); rebuild_path(); } - void push_dentry(const string& s) { + void push_dentry(std::string_view s) { if (bits.empty() && path.length() > 0) parse_bits(); if (!bits.empty()) path += "/"; path += s; - bits.push_back(s); + bits.emplace_back(s); + } + void push_dentry(const string& s) { + push_dentry(std::string_view(s)); } void push_dentry(const char *cs) { - string s = cs; - push_dentry(s); + push_dentry(std::string_view(cs, strlen(cs))); } void push_front_dentry(const string& s) { bits.insert(bits.begin(), s); diff --git a/src/mds/Beacon.cc b/src/mds/Beacon.cc index 10a6529854010..7993585a68f26 100644 --- a/src/mds/Beacon.cc +++ b/src/mds/Beacon.cc @@ -34,7 +34,7 @@ #define dout_prefix *_dout << "mds.beacon." << name << ' ' -Beacon::Beacon(CephContext *cct_, MonClient *monc_, std::string name_) : +Beacon::Beacon(CephContext *cct_, MonClient *monc_, std::string_view name_) : Dispatcher(cct_), lock("Beacon"), monc(monc_), timer(g_ceph_context, lock), name(name_), standby_for_rank(MDS_RANK_NONE), standby_for_fscid(FS_CLUSTER_ID_NONE), want_state(MDSMap::STATE_BOOT), diff --git a/src/mds/Beacon.h b/src/mds/Beacon.h index 8b5ac30b6f4de..f176588dd324f 100644 --- a/src/mds/Beacon.h +++ b/src/mds/Beacon.h @@ -16,6 +16,8 @@ #ifndef BEACON_STATE_H #define BEACON_STATE_H +#include + #include "include/types.h" #include "include/Context.h" #include "common/Mutex.h" @@ -40,7 +42,7 @@ class MDSRank; class Beacon : public Dispatcher { public: - Beacon(CephContext *cct_, MonClient *monc_, std::string name); + Beacon(CephContext *cct_, MonClient *monc_, std::string_view name); ~Beacon() override; void init(MDSMap const *mdsmap); diff --git a/src/mds/CDentry.h b/src/mds/CDentry.h index 27a6419c55784..689f0ffe6c2cb 100644 --- a/src/mds/CDentry.h +++ b/src/mds/CDentry.h @@ -18,6 +18,7 @@ #define CEPH_CDENTRY_H #include +#include #include #include "include/counter.h" @@ -101,7 +102,7 @@ public: static const unsigned EXPORT_NONCE = 1; - CDentry(const std::string& n, __u32 h, + CDentry(std::string_view n, __u32 h, snapid_t f, snapid_t l) : name(n), hash(h), first(f), last(l), @@ -109,7 +110,7 @@ public: lock(this, &lock_type), versionlock(this, &versionlock_type) {} - CDentry(const std::string& n, __u32 h, inodeno_t ino, unsigned char dt, + CDentry(std::string_view n, __u32 h, inodeno_t ino, unsigned char dt, snapid_t f, snapid_t l) : name(n), hash(h), first(f), last(l), @@ -146,7 +147,7 @@ public: const CDir *get_dir() const { return dir; } CDir *get_dir() { return dir; } - const std::string& get_name() const { return name; } + std::string_view get_name() const { return std::string_view(name); } __u32 get_hash() const { return hash; } diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index 97d9c3fe85f69..c7be753a246b2 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -12,6 +12,7 @@ * */ +#include #include "include/types.h" @@ -291,14 +292,14 @@ bool CDir::check_rstats(bool scrub) return good; } -CDentry *CDir::lookup(const string& name, snapid_t snap) +CDentry *CDir::lookup(std::string_view name, snapid_t snap) { dout(20) << "lookup (" << snap << ", '" << name << "')" << dendl; - map_t::iterator iter = items.lower_bound(dentry_key_t(snap, name.c_str(), + map_t::iterator iter = items.lower_bound(dentry_key_t(snap, name, inode->hash_dentry_name(name))); if (iter == items.end()) return 0; - if (iter->second->name == name && + if (iter->second->get_name() == name && iter->second->first <= snap && iter->second->last >= snap) { dout(20) << " hit -> " << iter->first << dendl; @@ -308,8 +309,8 @@ CDentry *CDir::lookup(const string& name, snapid_t snap) return 0; } -CDentry *CDir::lookup_exact_snap(const string& name, snapid_t last) { - map_t::iterator p = items.find(dentry_key_t(last, name.c_str(), +CDentry *CDir::lookup_exact_snap(std::string_view name, snapid_t last) { + map_t::iterator p = items.find(dentry_key_t(last, name, inode->hash_dentry_name(name))); if (p == items.end()) return NULL; @@ -320,7 +321,7 @@ CDentry *CDir::lookup_exact_snap(const string& name, snapid_t last) { * linking fun */ -CDentry* CDir::add_null_dentry(const string& dname, +CDentry* CDir::add_null_dentry(std::string_view dname, snapid_t first, snapid_t last) { // foreign @@ -339,7 +340,7 @@ CDentry* CDir::add_null_dentry(const string& dname, // add to dir assert(items.count(dn->key()) == 0); - //assert(null_items.count(dn->name) == 0); + //assert(null_items.count(dn->get_name()) == 0); items[dn->key()] = dn; if (last == CEPH_NOSNAP) @@ -363,7 +364,7 @@ CDentry* CDir::add_null_dentry(const string& dname, } -CDentry* CDir::add_primary_dentry(const string& dname, CInode *in, +CDentry* CDir::add_primary_dentry(std::string_view dname, CInode *in, snapid_t first, snapid_t last) { // primary @@ -385,7 +386,7 @@ CDentry* CDir::add_primary_dentry(const string& dname, CInode *in, // add to dir assert(items.count(dn->key()) == 0); - //assert(null_items.count(dn->name) == 0); + //assert(null_items.count(dn->get_name()) == 0); items[dn->key()] = dn; @@ -413,7 +414,7 @@ CDentry* CDir::add_primary_dentry(const string& dname, CInode *in, return dn; } -CDentry* CDir::add_remote_dentry(const string& dname, inodeno_t ino, unsigned char d_type, +CDentry* CDir::add_remote_dentry(std::string_view dname, inodeno_t ino, unsigned char d_type, snapid_t first, snapid_t last) { // foreign @@ -430,7 +431,7 @@ CDentry* CDir::add_remote_dentry(const string& dname, inodeno_t ino, unsigned ch // add to dir assert(items.count(dn->key()) == 0); - //assert(null_items.count(dn->name) == 0); + //assert(null_items.count(dn->get_name()) == 0); items[dn->key()] = dn; if (last == CEPH_NOSNAP) @@ -678,14 +679,14 @@ void CDir::add_to_bloom(CDentry *dn) bloom.reset(new bloom_filter(size, 1.0 / size, 0)); } /* This size and false positive probability is completely random.*/ - bloom->insert(dn->name.c_str(), dn->name.size()); + bloom->insert(dn->get_name().data(), dn->get_name().size()); } -bool CDir::is_in_bloom(const string& name) +bool CDir::is_in_bloom(std::string_view name) { if (!bloom) return false; - return bloom->contains(name.c_str(), name.size()); + return bloom->contains(name.data(), name.size()); } void CDir::remove_null_dentries() { @@ -1009,7 +1010,7 @@ void CDir::split(int bits, list& subs, list& wai CDir::map_t::iterator p = items.begin(); CDentry *dn = p->second; - frag_t subfrag = inode->pick_dirfrag(dn->name); + frag_t subfrag = inode->pick_dirfrag(dn->get_name()); int n = (subfrag.value() & (subfrag.mask() ^ frag.mask())) >> subfrag.mask_shift(); dout(15) << " subfrag " << subfrag << " n=" << n << " for " << p->first << dendl; CDir *f = subfrags[n]; @@ -1212,7 +1213,7 @@ void CDir::assimilate_dirty_rstat_inodes_finish(MutationRef& mut, EMetaBlob *blo * WAITING */ -void CDir::add_dentry_waiter(const string& dname, snapid_t snapid, MDSInternalContextBase *c) +void CDir::add_dentry_waiter(std::string_view dname, snapid_t snapid, MDSInternalContextBase *c) { if (waiting_on_dentry.empty()) get(PIN_DNWAITER); @@ -1222,7 +1223,7 @@ void CDir::add_dentry_waiter(const string& dname, snapid_t snapid, MDSInternalCo << " " << c << " on " << *this << dendl; } -void CDir::take_dentry_waiting(const string& dname, snapid_t first, snapid_t last, +void CDir::take_dentry_waiting(std::string_view dname, snapid_t first, snapid_t last, list& ls) { if (waiting_on_dentry.empty()) @@ -1456,7 +1457,7 @@ void CDir::fetch(MDSInternalContextBase *c, bool ignore_authpinnability) return fetch(c, want, ignore_authpinnability); } -void CDir::fetch(MDSInternalContextBase *c, const string& want_dn, bool ignore_authpinnability) +void CDir::fetch(MDSInternalContextBase *c, std::string_view want_dn, bool ignore_authpinnability) { dout(10) << "fetch on " << *this << dendl; @@ -1494,7 +1495,7 @@ void CDir::fetch(MDSInternalContextBase *c, const string& want_dn, bool ignore_a } if (c) add_waiter(WAIT_COMPLETE, c); - if (!want_dn.empty()) wanted_items.insert(want_dn); + if (!want_dn.empty()) wanted_items.insert(std::string(want_dn)); // already fetching? if (state_test(CDir::STATE_FETCHING)) { @@ -1645,8 +1646,8 @@ void CDir::_omap_fetch_more( } CDentry *CDir::_load_dentry( - const std::string &key, - const std::string &dname, + std::string_view key, + std::string_view dname, const snapid_t last, bufferlist &bl, const int pos, @@ -1697,7 +1698,7 @@ CDentry *CDir::_load_dentry( if (stale) { if (!dn) { - stale_items.insert(key); + stale_items.insert(std::string(key)); *force_dirty = true; } return dn; @@ -1732,7 +1733,7 @@ CDentry *CDir::_load_dentry( if (stale) { if (!dn) { - stale_items.insert(key); + stale_items.insert(std::string(key)); *force_dirty = true; } return dn; @@ -2006,11 +2007,14 @@ void CDir::_go_bad() finish_waiting(WAIT_COMPLETE, -EIO); } -void CDir::go_bad_dentry(snapid_t last, const std::string &dname) +void CDir::go_bad_dentry(snapid_t last, std::string_view dname) { dout(10) << __func__ << " " << dname << dendl; + std::string path(get_path()); + path += "/"; + path += dname; const bool fatal = cache->mds->damage_table.notify_dentry( - inode->ino(), frag, last, dname, get_path() + "/" + dname); + inode->ino(), frag, last, dname, path); if (fatal) { cache->mds->damaged(); ceph_abort(); // unreachable, damaged() respawns us @@ -2138,11 +2142,11 @@ void CDir::_omap_commit(int op_prio) } if (dn->get_linkage()->is_null()) { - dout(10) << " rm " << dn->name << " " << *dn << dendl; + dout(10) << " rm " << dn->get_name() << " " << *dn << dendl; write_size += key.length(); to_remove.insert(key); } else { - dout(10) << " set " << dn->name << " " << *dn << dendl; + dout(10) << " set " << dn->get_name() << " " << *dn << dendl; bufferlist dnbl; _encode_dentry(dn, dnbl, snaps); write_size += key.length() + dnbl.length(); @@ -2231,7 +2235,7 @@ void CDir::_encode_dentry(CDentry *dn, bufferlist& bl, if (dn->linkage.is_remote()) { inodeno_t ino = dn->linkage.get_remote_ino(); unsigned char d_type = dn->linkage.get_remote_d_type(); - dout(14) << " pos " << bl.length() << " dn '" << dn->name << "' remote ino " << ino << dendl; + dout(14) << " pos " << bl.length() << " dn '" << dn->get_name() << "' remote ino " << ino << dendl; // marker, name, ino bl.append('L'); // remote link @@ -2242,7 +2246,7 @@ void CDir::_encode_dentry(CDentry *dn, bufferlist& bl, CInode *in = dn->linkage.get_inode(); assert(in); - dout(14) << " pos " << bl.length() << " dn '" << dn->name << "' inode " << *in << dendl; + dout(14) << " pos " << bl.length() << " dn '" << dn->get_name() << "' inode " << *in << dendl; // marker, name, inode, [symlink string] bl.append('I'); // inode diff --git a/src/mds/CDir.h b/src/mds/CDir.h index b18a5f8dd4c6e..13079557798ed 100644 --- a/src/mds/CDir.h +++ b/src/mds/CDir.h @@ -17,6 +17,13 @@ #ifndef CEPH_CDIR_H #define CEPH_CDIR_H +#include +#include +#include +#include +#include +#include + #include "include/counter.h" #include "include/types.h" #include "include/buffer_fwd.h" @@ -26,13 +33,6 @@ #include "MDSCacheObject.h" -#include - -#include -#include -#include -#include - #include "CInode.h" @@ -435,17 +435,17 @@ protected: // -- dentries and inodes -- public: - CDentry* lookup_exact_snap(const std::string& dname, snapid_t last); - CDentry* lookup(const std::string& n, snapid_t snap=CEPH_NOSNAP); + CDentry* lookup_exact_snap(std::string_view dname, snapid_t last); + CDentry* lookup(std::string_view n, snapid_t snap=CEPH_NOSNAP); CDentry* lookup(const char *n, snapid_t snap=CEPH_NOSNAP) { - return lookup(std::string(n), snap); + return lookup(std::string_view(n), snap); } - CDentry* add_null_dentry(const std::string& dname, + CDentry* add_null_dentry(std::string_view dname, snapid_t first=2, snapid_t last=CEPH_NOSNAP); - CDentry* add_primary_dentry(const std::string& dname, CInode *in, + CDentry* add_primary_dentry(std::string_view dname, CInode *in, snapid_t first=2, snapid_t last=CEPH_NOSNAP); - CDentry* add_remote_dentry(const std::string& dname, inodeno_t ino, unsigned char d_type, + CDentry* add_remote_dentry(std::string_view dname, inodeno_t ino, unsigned char d_type, snapid_t first=2, snapid_t last=CEPH_NOSNAP); void remove_dentry( CDentry *dn ); // delete dentry void link_remote_inode( CDentry *dn, inodeno_t ino, unsigned char d_type); @@ -455,7 +455,7 @@ protected: void try_remove_unlinked_dn(CDentry *dn); void add_to_bloom(CDentry *dn); - bool is_in_bloom(const std::string& name); + bool is_in_bloom(std::string_view name); bool has_bloom() { return (bloom ? true : false); } void remove_bloom() { bloom.reset(); @@ -591,7 +591,7 @@ private: return file_object_t(ino(), frag); } void fetch(MDSInternalContextBase *c, bool ignore_authpinnability=false); - void fetch(MDSInternalContextBase *c, const std::string& want_dn, bool ignore_authpinnability=false); + void fetch(MDSInternalContextBase *c, std::string_view want_dn, bool ignore_authpinnability=false); void fetch(MDSInternalContextBase *c, const std::set& keys); protected: compact_set wanted_items; @@ -601,8 +601,8 @@ protected: bufferlist& hdrbl, std::map& omap, MDSInternalContextBase *fin); CDentry *_load_dentry( - const std::string &key, - const std::string &dname, + std::string_view key, + std::string_view dname, snapid_t last, bufferlist &bl, int pos, @@ -618,7 +618,7 @@ protected: /** * Go bad due to a damaged dentry (register with damagetable and go BADFRAG) */ - void go_bad_dentry(snapid_t last, const std::string &dname); + void go_bad_dentry(snapid_t last, std::string_view dname); /** * Go bad due to a damaged header (register with damagetable and go BADFRAG) @@ -668,11 +668,11 @@ protected: compact_map< string_snap_t, std::list > waiting_on_dentry; public: - bool is_waiting_for_dentry(const std::string& dname, snapid_t snap) { + bool is_waiting_for_dentry(std::string_view dname, snapid_t snap) { return waiting_on_dentry.count(string_snap_t(dname, snap)); } - void add_dentry_waiter(const std::string& dentry, snapid_t snap, MDSInternalContextBase *c); - void take_dentry_waiting(const std::string& dentry, snapid_t first, snapid_t last, std::list& ls); + void add_dentry_waiter(std::string_view dentry, snapid_t snap, MDSInternalContextBase *c); + void take_dentry_waiting(std::string_view dentry, snapid_t first, snapid_t last, std::list& ls); void take_sub_waiting(std::list& ls); // dentry or ino void add_waiter(uint64_t mask, MDSInternalContextBase *c) override; diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 60b18b978ef8f..ed2ecde96553f 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -499,7 +499,7 @@ void CInode::pop_projected_snaprealm(sr_t *next_snaprealm) // dirfrags -__u32 InodeStoreBase::hash_dentry_name(const string &dn) +__u32 InodeStoreBase::hash_dentry_name(std::string_view dn) { int which = inode.dir_layout.dl_dir_hash; if (!which) @@ -508,7 +508,7 @@ __u32 InodeStoreBase::hash_dentry_name(const string &dn) return ceph_str_hash(which, dn.data(), dn.length()); } -frag_t InodeStoreBase::pick_dirfrag(const string& dn) +frag_t InodeStoreBase::pick_dirfrag(std::string_view dn) { if (dirfragtree.empty()) return frag_t(); // avoid the string hash if we can. @@ -1135,7 +1135,7 @@ void CInode::build_backtrace(int64_t pool, inode_backtrace_t& bt) CDentry *pdn = get_parent_dn(); while (pdn) { CInode *diri = pdn->get_dir()->get_inode(); - bt.ancestors.push_back(inode_backpointer_t(diri->ino(), pdn->name, in->inode.version)); + bt.ancestors.push_back(inode_backpointer_t(diri->ino(), pdn->get_name(), in->inode.version)); in = diri; pdn = in->get_parent_dn(); } @@ -1310,7 +1310,7 @@ void CInode::verify_diri_backtrace(bufferlist &bl, int err) decode(backtrace, bl); CDentry *pdn = get_parent_dn(); if (backtrace.ancestors.empty() || - backtrace.ancestors[0].dname != pdn->name || + backtrace.ancestors[0].dname != pdn->get_name() || backtrace.ancestors[0].dirino != pdn->get_dir()->ino()) err = -EINVAL; } @@ -3912,7 +3912,7 @@ 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 tag, + void fetch_backtrace_and_tag(CInode *in, std::string_view tag, Context *fin, int *bt_r, bufferlist *bt) { const int64_t pool = in->get_backtrace_pool(); @@ -3954,7 +3954,7 @@ void CInode::validate_disk_state(CInode::validated_data *results, // present) if (in->scrub_infop) { // I'm a non-orphan, so look up my ScrubHeader via my linkage - const std::string &tag = in->scrub_infop->header->get_tag(); + std::string_view tag = in->scrub_infop->header->get_tag(); // Rather than using the usual CInode::fetch_backtrace, // use a special variant that optionally writes a tag in the same // operation. diff --git a/src/mds/CInode.h b/src/mds/CInode.h index 39d5292e43259..41f066240b176 100644 --- a/src/mds/CInode.h +++ b/src/mds/CInode.h @@ -17,6 +17,11 @@ #ifndef CEPH_CINODE_H #define CEPH_CINODE_H +#include +#include +#include +#include + #include "common/config.h" #include "include/counter.h" #include "include/elist.h" @@ -35,10 +40,6 @@ #include "SnapRealm.h" #include "Mutation.h" -#include -#include -#include - #define dout_context g_ceph_context class Context; @@ -102,8 +103,8 @@ public: void dump(Formatter *f) const; /* For use by offline tools */ - __u32 hash_dentry_name(const std::string &dn); - frag_t pick_dirfrag(const std::string &dn); + __u32 hash_dentry_name(std::string_view dn); + frag_t pick_dirfrag(std::string_view dn); }; class InodeStore : public InodeStoreBase { diff --git a/src/mds/DamageTable.cc b/src/mds/DamageTable.cc index f7d023c1337fc..de6a5ee4b34f0 100644 --- a/src/mds/DamageTable.cc +++ b/src/mds/DamageTable.cc @@ -70,7 +70,7 @@ class DentryDamage : public DamageEntry DentryDamage( inodeno_t ino_, frag_t frag_, - std::string dname_, + std::string_view dname_, snapid_t snap_id_) : ino(ino_), frag(frag_), dname(dname_), snap_id(snap_id_) {} @@ -129,7 +129,7 @@ DamageEntry::~DamageEntry() bool DamageTable::notify_dentry( inodeno_t ino, frag_t frag, - snapid_t snap_id, const std::string &dname, const std::string &path) + snapid_t snap_id, std::string_view dname, std::string_view path) { if (oversized()) { return true; @@ -160,7 +160,7 @@ bool DamageTable::notify_dentry( } bool DamageTable::notify_dirfrag(inodeno_t ino, frag_t frag, - const std::string &path) + std::string_view path) { // Special cases: damage to these dirfrags is considered fatal to // the MDS rank that owns them. @@ -189,7 +189,7 @@ bool DamageTable::notify_dirfrag(inodeno_t ino, frag_t frag, return false; } -bool DamageTable::notify_remote_damaged(inodeno_t ino, const std::string &path) +bool DamageTable::notify_remote_damaged(inodeno_t ino, std::string_view path) { if (oversized()) { return true; @@ -212,7 +212,7 @@ bool DamageTable::oversized() const bool DamageTable::is_dentry_damaged( const CDir *dir_frag, - const std::string &dname, + std::string_view dname, const snapid_t snap_id) const { if (dentries.count( diff --git a/src/mds/DamageTable.h b/src/mds/DamageTable.h index 34c7da02e73c8..ba0f55fb8b046 100644 --- a/src/mds/DamageTable.h +++ b/src/mds/DamageTable.h @@ -16,6 +16,8 @@ #ifndef DAMAGE_TABLE_H_ #define DAMAGE_TABLE_H_ +#include + #include "mdstypes.h" #include "include/random.h" @@ -93,7 +95,7 @@ class DentryIdent } } - DentryIdent(const std::string &dname_, snapid_t snap_id_) + DentryIdent(std::string_view dname_, snapid_t snap_id_) : dname(dname_), snap_id(snap_id_) {} }; @@ -161,7 +163,7 @@ public: * * @return true if fatal */ - bool notify_dirfrag(inodeno_t ino, frag_t frag, const std::string &path); + bool notify_dirfrag(inodeno_t ino, frag_t frag, std::string_view path); /** * Indicate that a particular dentry cannot be loaded. @@ -170,17 +172,17 @@ public: */ bool notify_dentry( inodeno_t ino, frag_t frag, - snapid_t snap_id, const std::string &dname, const std::string &path); + snapid_t snap_id, std::string_view dname, std::string_view path); /** * Indicate that a particular Inode could not be loaded by number */ bool notify_remote_damaged( - inodeno_t ino, const std::string &path); + inodeno_t ino, std::string_view path); bool is_dentry_damaged( const CDir *dir_frag, - const std::string &dname, + std::string_view dname, const snapid_t snap_id) const; bool is_dirfrag_damaged( diff --git a/src/mds/FSMap.cc b/src/mds/FSMap.cc index 9cec722cceb9e..9737798b0bc0a 100644 --- a/src/mds/FSMap.cc +++ b/src/mds/FSMap.cc @@ -225,7 +225,7 @@ void FSMap::print_summary(Formatter *f, ostream *out) const } -void FSMap::create_filesystem(const std::string &name, +void FSMap::create_filesystem(std::string_view name, int64_t metadata_pool, int64_t data_pool, uint64_t features) { @@ -642,15 +642,16 @@ void Filesystem::decode(bufferlist::iterator& p) } int FSMap::parse_filesystem( - std::string const &ns_str, + std::string_view ns_str, std::shared_ptr *result ) const { std::string ns_err; - fs_cluster_id_t fscid = strict_strtol(ns_str.c_str(), 10, &ns_err); + std::string s(ns_str); + fs_cluster_id_t fscid = strict_strtol(s.c_str(), 10, &ns_err); if (!ns_err.empty() || filesystems.count(fscid) == 0) { for (auto &fs : filesystems) { - if (fs.second->mds_map.fs_name == ns_str) { + if (fs.second->mds_map.fs_name == s) { *result = std::const_pointer_cast(fs.second); return 0; } @@ -669,7 +670,7 @@ void Filesystem::print(std::ostream &out) const mds_map.print(out); } -mds_gid_t FSMap::find_standby_for(mds_role_t role, const std::string& name) const +mds_gid_t FSMap::find_standby_for(mds_role_t role, std::string_view name) const { mds_gid_t result = MDS_GID_NONE; @@ -744,7 +745,7 @@ mds_gid_t FSMap::find_unused_for(mds_role_t role, return MDS_GID_NONE; } -mds_gid_t FSMap::find_replacement_for(mds_role_t role, const std::string& name, +mds_gid_t FSMap::find_replacement_for(mds_role_t role, std::string_view name, bool force_standby_active) const { const mds_gid_t standby = find_standby_for(role, name); if (standby) @@ -994,7 +995,7 @@ std::list FSMap::stop(mds_gid_t who) * if legacy_client_ns is set. */ int FSMap::parse_role( - const std::string &role_str, + std::string_view role_str, mds_role_t *role, std::ostream &ss) const { @@ -1018,7 +1019,7 @@ int FSMap::parse_role( mds_rank_t rank; std::string err; - std::string rank_str = role_str.substr(rank_pos); + std::string rank_str(role_str.substr(rank_pos)); long rank_i = strict_strtol(rank_str.c_str(), 10, &err); if (rank_i < 0 || !err.empty()) { ss << "Invalid rank '" << rank_str << "'"; diff --git a/src/mds/FSMap.h b/src/mds/FSMap.h index 388abd4b1c171..4e123367194b5 100644 --- a/src/mds/FSMap.h +++ b/src/mds/FSMap.h @@ -16,6 +16,11 @@ #ifndef CEPH_FSMAP_H #define CEPH_FSMAP_H +#include +#include +#include +#include + #include #include "include/types.h" @@ -23,10 +28,6 @@ #include "msg/Message.h" #include "mds/MDSMap.h" -#include -#include -#include - #include "common/config.h" #include "include/CompatSet.h" @@ -199,7 +200,7 @@ public: /** * Resolve daemon name to GID */ - mds_gid_t find_mds_gid_by_name(const std::string& s) const + mds_gid_t find_mds_gid_by_name(std::string_view s) const { const auto info = get_mds_info(); for (const auto &p : info) { @@ -213,7 +214,7 @@ public: /** * Resolve daemon name to status */ - const MDSMap::mds_info_t* find_by_name(const std::string& name) const + const MDSMap::mds_info_t* find_by_name(std::string_view name) const { std::map result; for (const auto &i : standby_daemons) { @@ -304,7 +305,7 @@ public: * Caller must already have validated all arguments vs. the existing * FSMap and OSDMap contents. */ - void create_filesystem(const std::string &name, + void create_filesystem(std::string_view name, int64_t metadata_pool, int64_t data_pool, uint64_t features); @@ -419,7 +420,7 @@ public: bool filesystem_exists(fs_cluster_id_t fscid) const {return filesystems.count(fscid) > 0;} std::shared_ptr get_filesystem(fs_cluster_id_t fscid) const {return std::const_pointer_cast(filesystems.at(fscid));} std::shared_ptr get_filesystem(void) const {return std::const_pointer_cast(filesystems.begin()->second);} - std::shared_ptr get_filesystem(const std::string &name) const + std::shared_ptr get_filesystem(std::string_view name) const { for (const auto &i : filesystems) { if (i.second->mds_map.fs_name == name) { @@ -438,12 +439,12 @@ public: } int parse_filesystem( - std::string const &ns_str, + std::string_view ns_str, std::shared_ptr *result ) const; int parse_role( - const std::string &role_str, + std::string_view role_str, mds_role_t *role, std::ostream &ss) const; @@ -460,11 +461,11 @@ public: return false; } - mds_gid_t find_standby_for(mds_role_t mds, const std::string& name) const; + mds_gid_t find_standby_for(mds_role_t mds, std::string_view name) const; mds_gid_t find_unused_for(mds_role_t mds, bool force_standby_active) const; - mds_gid_t find_replacement_for(mds_role_t mds, const std::string& name, + mds_gid_t find_replacement_for(mds_role_t mds, std::string_view name, bool force_standby_active) const; void get_health(list >& summary, diff --git a/src/mds/FSMapUser.h b/src/mds/FSMapUser.h index cfc6687d348f4..2ae0792ffd016 100644 --- a/src/mds/FSMapUser.h +++ b/src/mds/FSMapUser.h @@ -14,9 +14,11 @@ #ifndef CEPH_FSMAPCOMPACT_H #define CEPH_FSMAPCOMPACT_H -#include "mds/mdstypes.h" #include #include +#include + +#include "mds/mdstypes.h" class FSMapUser { public: @@ -37,7 +39,7 @@ public: epoch_t get_epoch() const { return epoch; } - fs_cluster_id_t get_fs_cid(const std::string &name) const { + fs_cluster_id_t get_fs_cid(std::string_view name) const { for (auto &p : filesystems) { if (p.second.name == name) return p.first; diff --git a/src/mds/Locker.cc b/src/mds/Locker.cc index a79305335cd11..3d9fa6c3a56a0 100644 --- a/src/mds/Locker.cc +++ b/src/mds/Locker.cc @@ -12,6 +12,7 @@ * */ +#include #include "MDSRank.h" #include "MDCache.h" @@ -2966,7 +2967,7 @@ public: }; void Locker::process_request_cap_release(MDRequestRef& mdr, client_t client, const ceph_mds_request_release& item, - const string &dname) + std::string_view dname) { inodeno_t ino = (uint64_t)item.ino; uint64_t cap_id = item.cap_id; diff --git a/src/mds/Locker.h b/src/mds/Locker.h index b878451712864..1c0d3888e0869 100644 --- a/src/mds/Locker.h +++ b/src/mds/Locker.h @@ -15,6 +15,8 @@ #ifndef CEPH_MDS_LOCKER_H #define CEPH_MDS_LOCKER_H +#include + #include "include/types.h" #include @@ -177,7 +179,7 @@ public: bool should_defer_client_cap_frozen(CInode *in); void process_request_cap_release(MDRequestRef& mdr, client_t client, const ceph_mds_request_release& r, - const string &dname); + std::string_view dname); void kick_cap_releases(MDRequestRef& mdr); void kick_issue_caps(CInode *in, client_t client, ceph_seq_t seq); diff --git a/src/mds/LogEvent.cc b/src/mds/LogEvent.cc index 3aaea4eb85b40..19e0904906680 100644 --- a/src/mds/LogEvent.cc +++ b/src/mds/LogEvent.cc @@ -95,34 +95,34 @@ std::string LogEvent::get_type_str() const } } +const std::map LogEvent::types = { + {"SUBTREEMAP", EVENT_SUBTREEMAP}, + {"SUBTREEMAP_TEST", EVENT_SUBTREEMAP_TEST}, + {"EXPORT", EVENT_EXPORT}, + {"IMPORTSTART", EVENT_IMPORTSTART}, + {"IMPORTFINISH", EVENT_IMPORTFINISH}, + {"FRAGMENT", EVENT_FRAGMENT}, + {"RESETJOURNAL", EVENT_RESETJOURNAL}, + {"SESSION", EVENT_SESSION}, + {"SESSIONS_OLD", EVENT_SESSIONS_OLD}, + {"SESSIONS", EVENT_SESSIONS}, + {"UPDATE", EVENT_UPDATE}, + {"SLAVEUPDATE", EVENT_SLAVEUPDATE}, + {"OPEN", EVENT_OPEN}, + {"COMMITTED", EVENT_COMMITTED}, + {"TABLECLIENT", EVENT_TABLECLIENT}, + {"TABLESERVER", EVENT_TABLESERVER}, + {"NOOP", EVENT_NOOP} +}; /* * Resolve type string to type enum * * Return -1 if not found */ -LogEvent::EventType LogEvent::str_to_type(std::string const &str) +LogEvent::EventType LogEvent::str_to_type(std::string_view str) { - std::map types; - types["SUBTREEMAP"] = EVENT_SUBTREEMAP; - types["SUBTREEMAP_TEST"] = EVENT_SUBTREEMAP_TEST; - types["EXPORT"] = EVENT_EXPORT; - types["IMPORTSTART"] = EVENT_IMPORTSTART; - types["IMPORTFINISH"] = EVENT_IMPORTFINISH; - types["FRAGMENT"] = EVENT_FRAGMENT; - types["RESETJOURNAL"] = EVENT_RESETJOURNAL; - types["SESSION"] = EVENT_SESSION; - types["SESSIONS_OLD"] = EVENT_SESSIONS_OLD; - types["SESSIONS"] = EVENT_SESSIONS; - types["UPDATE"] = EVENT_UPDATE; - types["SLAVEUPDATE"] = EVENT_SLAVEUPDATE; - types["OPEN"] = EVENT_OPEN; - types["COMMITTED"] = EVENT_COMMITTED; - types["TABLECLIENT"] = EVENT_TABLECLIENT; - types["TABLESERVER"] = EVENT_TABLESERVER; - types["NOOP"] = EVENT_NOOP; - - return types[str]; + return LogEvent::types.at(std::string(str)); } diff --git a/src/mds/LogEvent.h b/src/mds/LogEvent.h index 5e6e918c5cf4c..681a957e50625 100644 --- a/src/mds/LogEvent.h +++ b/src/mds/LogEvent.h @@ -73,7 +73,7 @@ public: virtual ~LogEvent() { } string get_type_str() const; - static EventType str_to_type(std::string const &str); + static EventType str_to_type(std::string_view str); EventType get_type() const { return _type; } void set_type(EventType t) { _type = t; } @@ -117,6 +117,9 @@ public: * tools can examine metablobs while traversing lists of LogEvent. */ virtual EMetaBlob *get_metablob() { return NULL; } + +private: + static const std::map types; }; inline ostream& operator<<(ostream& out, const LogEvent &le) { diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index ab2ae7b4fed4c..2b119046e162a 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "MDCache.h" @@ -1602,7 +1603,7 @@ void MDCache::journal_cow_dentry(MutationImpl *mut, EMetaBlob *metablob, snapid_t oldfirst = dn->first; dn->first = dir_follows+1; if (realm->has_snaps_in_range(oldfirst, dir_follows)) { - CDentry *olddn = dn->dir->add_remote_dentry(dn->name, in->ino(), in->d_type(), + CDentry *olddn = dn->dir->add_remote_dentry(dn->get_name(), in->ino(), in->d_type(), oldfirst, dir_follows); olddn->pre_dirty(); dout(10) << " olddn " << *olddn << dendl; @@ -1668,7 +1669,7 @@ void MDCache::journal_cow_dentry(MutationImpl *mut, EMetaBlob *metablob, mut->add_cow_inode(oldin); if (pcow_inode) *pcow_inode = oldin; - CDentry *olddn = dn->dir->add_primary_dentry(dn->name, oldin, oldfirst, follows); + CDentry *olddn = dn->dir->add_primary_dentry(dn->get_name(), oldin, oldfirst, follows); oldin->inode.version = olddn->pre_dirty(); dout(10) << " olddn " << *olddn << dendl; bool need_snapflush = !oldin->client_snap_caps.empty(); @@ -1680,7 +1681,7 @@ void MDCache::journal_cow_dentry(MutationImpl *mut, EMetaBlob *metablob, mut->add_cow_dentry(olddn); } else { assert(dnl->is_remote()); - CDentry *olddn = dn->dir->add_remote_dentry(dn->name, dnl->get_remote_ino(), dnl->get_remote_d_type(), + CDentry *olddn = dn->dir->add_remote_dentry(dn->get_name(), dnl->get_remote_ino(), dnl->get_remote_d_type(), oldfirst, follows); olddn->pre_dirty(); dout(10) << " olddn " << *olddn << dendl; @@ -4182,7 +4183,7 @@ void MDCache::rejoin_walk(CDir *dir, MMDSCacheRejoin *rejoin) assert(dnl->is_primary()); CInode *in = dnl->get_inode(); assert(dnl->get_inode()->is_dir()); - rejoin->add_weak_primary_dentry(dir->ino(), dn->name.c_str(), dn->first, dn->last, in->ino()); + rejoin->add_weak_primary_dentry(dir->ino(), dn->get_name(), dn->first, dn->last, in->ino()); in->get_nested_dirfrags(nested); if (in->is_dirty_scattered()) { dout(10) << " sending scatterlock state on " << *in << dendl; @@ -4230,7 +4231,7 @@ void MDCache::rejoin_walk(CDir *dir, MMDSCacheRejoin *rejoin) } dout(15) << " add_strong_dentry " << *dn << dendl; - rejoin->add_strong_dentry(dir->dirfrag(), dn->name, dn->first, dn->last, + rejoin->add_strong_dentry(dir->dirfrag(), dn->get_name(), dn->first, dn->last, dnl->is_primary() ? dnl->get_inode()->ino():inodeno_t(0), dnl->is_remote() ? dnl->get_remote_ino():inodeno_t(0), dnl->is_remote() ? dnl->get_remote_d_type():0, @@ -4460,7 +4461,7 @@ void MDCache::handle_cache_rejoin_weak(MMDSCacheRejoin *weak) unsigned dnonce = dn->add_replica(from); dout(10) << " have " << *dn << dendl; if (ack) - ack->add_strong_dentry(dir->dirfrag(), dn->name, dn->first, dn->last, + ack->add_strong_dentry(dir->dirfrag(), dn->get_name(), dn->first, dn->last, dnl->get_inode()->ino(), inodeno_t(0), 0, dnonce, dn->lock.get_replica_state()); @@ -4594,7 +4595,7 @@ void MDCache::rejoin_scour_survivor_replicas(mds_rank_t from, MMDSCacheRejoin *a if (dn->is_replica(from) && (ack == NULL || ack->strong_dentries.count(dir->dirfrag()) == 0 || - ack->strong_dentries[dir->dirfrag()].count(string_snap_t(dn->name, dn->last)) == 0)) { + ack->strong_dentries[dir->dirfrag()].count(string_snap_t(dn->get_name(), dn->last)) == 0)) { dentry_remove_replica(dn, from, gather_locks); dout(10) << " rem " << *dn << dendl; } @@ -6054,7 +6055,7 @@ void MDCache::rejoin_send_acks() auto it = acks.find(r.first); if (it == acks.end()) continue; - it->second->add_strong_dentry(dir->dirfrag(), dn->name, dn->first, dn->last, + it->second->add_strong_dentry(dir->dirfrag(), dn->get_name(), dn->first, dn->last, dnl->is_primary() ? dnl->get_inode()->ino():inodeno_t(0), dnl->is_remote() ? dnl->get_remote_ino():inodeno_t(0), dnl->is_remote() ? dnl->get_remote_d_type():0, @@ -6750,7 +6751,7 @@ bool MDCache::trim_dentry(CDentry *dn, map& expiremap assert(a != mds->get_nodeid()); if (expiremap.count(a) == 0) expiremap[a] = new MCacheExpire(mds->get_nodeid()); - expiremap[a]->add_dentry(con->dirfrag(), dir->dirfrag(), dn->name, dn->last, dn->get_replica_nonce()); + expiremap[a]->add_dentry(con->dirfrag(), dir->dirfrag(), dn->get_name(), dn->last, dn->get_replica_nonce()); } } @@ -8228,7 +8229,7 @@ CInode *MDCache::cache_traverse(const filepath& fp) return NULL; for (unsigned i = 0; i < fp.depth(); i++) { - const string& dname = fp[i]; + std::string_view dname = fp[i]; frag_t fg = in->pick_dirfrag(dname); dout(20) << " " << i << " " << dname << " frag " << fg << " from " << *in << dendl; CDir *curdir = in->get_dirfrag(fg); @@ -8337,7 +8338,8 @@ void MDCache::_open_remote_dentry_finish(CDentry *dn, inodeno_t ino, MDSInternal CDir *dir = dn->get_dir(); if (dir) { dir->get_inode()->make_path_string(path); - path = path + "/" + dn->get_name(); + path += "/"; + path += dn->get_name(); } bool fatal = mds->damage_table.notify_remote_damaged(ino, path); @@ -8760,7 +8762,7 @@ void MDCache::handle_open_ino(MMDSOpenIno *m, int err) if (!pdn) break; CInode *diri = pdn->get_dir()->get_inode(); - reply->ancestors.push_back(inode_backpointer_t(diri->ino(), pdn->name, + reply->ancestors.push_back(inode_backpointer_t(diri->ino(), pdn->get_name(), in->inode.version)); in = diri; } @@ -10262,7 +10264,7 @@ void MDCache::replicate_dir(CDir *dir, mds_rank_t to, bufferlist& bl) void MDCache::replicate_dentry(CDentry *dn, mds_rank_t to, bufferlist& bl) { - encode(dn->name, bl); + encode(dn->get_name(), bl); encode(dn->last, bl); dn->encode_replica(to, bl, mds->get_state() < MDSMap::STATE_ACTIVE); } @@ -10507,7 +10509,7 @@ void MDCache::send_dentry_link(CDentry *dn, MDRequestRef& mdr) continue; CDentry::linkage_t *dnl = dn->get_linkage(); MDentryLink *m = new MDentryLink(subtree->dirfrag(), dn->get_dir()->dirfrag(), - dn->name, dnl->is_primary()); + dn->get_name(), dnl->is_primary()); if (dnl->is_primary()) { dout(10) << " primary " << *dnl->get_inode() << dendl; replicate_inode(dnl->get_inode(), p.first, m->bl, @@ -10593,7 +10595,7 @@ void MDCache::send_dentry_unlink(CDentry *dn, CDentry *straydn, MDRequestRef& md rejoin_gather.count(*it))) continue; - MDentryUnlink *unlink = new MDentryUnlink(dn->get_dir()->dirfrag(), dn->name); + MDentryUnlink *unlink = new MDentryUnlink(dn->get_dir()->dirfrag(), dn->get_name()); if (straydn) replicate_stray(straydn, *it, unlink->straybl); mds->send_message_mds(unlink, *it); @@ -11963,27 +11965,27 @@ int MDCache::cache_status(Formatter *f) return 0; } -int MDCache::dump_cache(std::string const &file_name) +int MDCache::dump_cache(std::string_view file_name) { - return dump_cache(file_name.c_str(), NULL); + return dump_cache(file_name, NULL); } int MDCache::dump_cache(Formatter *f) { - return dump_cache(NULL, f); + return dump_cache(std::string_view(""), f); } -int MDCache::dump_cache(const string& dump_root, int depth, Formatter *f) +int MDCache::dump_cache(std::string_view dump_root, int depth, Formatter *f) { - return dump_cache(NULL, f, dump_root, depth); + return dump_cache(std::string_view(""), f, dump_root, depth); } /** * Dump the metadata cache, either to a Formatter, if * provided, else to a plain text file. */ -int MDCache::dump_cache(const char *fn, Formatter *f, - const string& dump_root, int depth) +int MDCache::dump_cache(std::string_view fn, Formatter *f, + std::string_view dump_root, int depth) { int r = 0; int fd = -1; @@ -11991,17 +11993,18 @@ int MDCache::dump_cache(const char *fn, Formatter *f, if (f) { f->open_array_section("inodes"); } else { - char deffn[200]; - if (!fn) { - snprintf(deffn, sizeof(deffn), "cachedump.%d.mds%d", (int)mds->mdsmap->get_epoch(), int(mds->get_nodeid())); - fn = deffn; + char path[PATH_MAX] = ""; + if (fn.length()) { + snprintf(path, sizeof path, "%s", fn.data()); + } else { + snprintf(path, sizeof path, "cachedump.%d.mds%d", (int)mds->mdsmap->get_epoch(), int(mds->get_nodeid())); } - dout(1) << "dump_cache to " << fn << dendl; + dout(1) << "dump_cache to " << path << dendl; - fd = ::open(fn, O_WRONLY|O_CREAT|O_EXCL, 0600); + fd = ::open(path, O_WRONLY|O_CREAT|O_EXCL, 0600); if (fd < 0) { - derr << "failed to open " << fn << ": " << cpp_strerror(errno) << dendl; + derr << "failed to open " << path << ": " << cpp_strerror(errno) << dendl; return errno; } } @@ -12154,14 +12157,14 @@ public: }; void MDCache::enqueue_scrub( - const string& path, - const std::string &tag, + std::string_view path, + std::string_view tag, bool force, bool recursive, bool repair, Formatter *f, Context *fin) { dout(10) << __func__ << path << dendl; MDRequestRef mdr = request_start_internal(CEPH_MDS_OP_ENQUEUE_SCRUB); - filepath fp(path.c_str()); + filepath fp(path); mdr->set_filepath(fp); C_MDS_EnqueueScrub *cs = new C_MDS_EnqueueScrub(f, fin); @@ -12451,7 +12454,7 @@ do_rdlocks: mds->server->respond_to_request(mdr, 0); } -void MDCache::flush_dentry(const string& path, Context *fin) +void MDCache::flush_dentry(std::string_view path, Context *fin) { if (is_readonly()) { dout(10) << __func__ << ": read-only FS" << dendl; @@ -12460,7 +12463,7 @@ void MDCache::flush_dentry(const string& path, Context *fin) } dout(10) << "flush_dentry " << path << dendl; MDRequestRef mdr = request_start_internal(CEPH_MDS_OP_FLUSH); - filepath fp(path.c_str()); + filepath fp(path); mdr->set_filepath(fp); mdr->internal_op_finish = fin; flush_dentry_work(mdr); diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index f05ecb6d3c37d..7107fb1a358b5 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -17,6 +17,8 @@ #ifndef CEPH_MDCACHE_H #define CEPH_MDCACHE_H +#include + #include "include/types.h" #include "include/filepath.h" #include "include/elist.h" @@ -805,7 +807,7 @@ public: return NULL; return in->get_dirfrag(df.frag); } - CDir* get_dirfrag(inodeno_t ino, const string& dn) { + CDir* get_dirfrag(inodeno_t ino, std::string_view dn) { CInode *in = get_inode(ino); if (!in) return NULL; @@ -1170,14 +1172,14 @@ public: void discard_delayed_expire(CDir *dir); protected: - int dump_cache(const char *fn, Formatter *f, - const std::string& dump_root = "", + int dump_cache(std::string_view fn, Formatter *f, + std::string_view dump_root = "", int depth = -1); public: int dump_cache() { return dump_cache(NULL, NULL); } - int dump_cache(const std::string &filename); + int dump_cache(std::string_view filename); int dump_cache(Formatter *f); - int dump_cache(const std::string& dump_root, int depth, Formatter *f); + int dump_cache(std::string_view dump_root, int depth, Formatter *f); int cache_status(Formatter *f); @@ -1212,11 +1214,11 @@ protected: void repair_dirfrag_stats_work(MDRequestRef& mdr); friend class C_MDC_RepairDirfragStats; public: - void flush_dentry(const string& path, Context *fin); + void flush_dentry(std::string_view path, Context *fin); /** * Create and start an OP_ENQUEUE_SCRUB */ - void enqueue_scrub(const string& path, const std::string &tag, + void enqueue_scrub(std::string_view path, std::string_view tag, bool force, bool recursive, bool repair, Formatter *f, Context *fin); void repair_inode_stats(CInode *diri); diff --git a/src/mds/MDSAuthCaps.cc b/src/mds/MDSAuthCaps.cc index 9ecfbd9f510e1..aeb86d8851d90 100644 --- a/src/mds/MDSAuthCaps.cc +++ b/src/mds/MDSAuthCaps.cc @@ -12,6 +12,7 @@ * */ +#include #include #include @@ -110,7 +111,7 @@ void MDSCapMatch::normalize_path() // drop .. } -bool MDSCapMatch::match(const std::string &target_path, +bool MDSCapMatch::match(std::string_view target_path, const int caller_uid, const int caller_gid, const vector *caller_gid_list) const @@ -142,7 +143,7 @@ bool MDSCapMatch::match(const std::string &target_path, return true; } -bool MDSCapMatch::match_path(const std::string &target_path) const +bool MDSCapMatch::match_path(std::string_view target_path) const { if (path.length()) { if (target_path.find(path) != 0) @@ -162,7 +163,7 @@ bool MDSCapMatch::match_path(const std::string &target_path) const * Is the client *potentially* able to access this path? Actual * permission will depend on uids/modes in the full is_capable. */ -bool MDSAuthCaps::path_capable(const std::string &inode_path) const +bool MDSAuthCaps::path_capable(std::string_view inode_path) const { for (const auto &i : grants) { if (i.match.match_path(inode_path)) { @@ -180,7 +181,7 @@ bool MDSAuthCaps::path_capable(const std::string &inode_path) const * This is true if any of the 'grant' clauses in the capability match the * requested path + op. */ -bool MDSAuthCaps::is_capable(const std::string &inode_path, +bool MDSAuthCaps::is_capable(std::string_view inode_path, uid_t inode_uid, gid_t inode_gid, unsigned inode_mode, uid_t caller_uid, gid_t caller_gid, @@ -280,7 +281,7 @@ void MDSAuthCaps::set_allow_all() MDSCapMatch())); } -bool MDSAuthCaps::parse(CephContext *c, const std::string& str, ostream *err) +bool MDSAuthCaps::parse(CephContext *c, std::string_view str, ostream *err) { // Special case for legacy caps if (str == "allow") { @@ -289,9 +290,9 @@ bool MDSAuthCaps::parse(CephContext *c, const std::string& str, ostream *err) return true; } - MDSCapParser g; - std::string::const_iterator iter = str.begin(); - std::string::const_iterator end = str.end(); + auto iter = str.begin(); + auto end = str.end(); + MDSCapParser g; bool r = qi::phrase_parse(iter, end, g, ascii::space, *this); cct = c; // set after parser self-assignment diff --git a/src/mds/MDSAuthCaps.h b/src/mds/MDSAuthCaps.h index bb7d8f6610341..1e6cda68cc2b0 100644 --- a/src/mds/MDSAuthCaps.h +++ b/src/mds/MDSAuthCaps.h @@ -16,9 +16,11 @@ #ifndef MDS_AUTH_CAPS_H #define MDS_AUTH_CAPS_H -#include -#include #include +#include +#include +#include + #include "include/types.h" #include "common/debug.h" @@ -91,7 +93,7 @@ struct MDSCapMatch { } // check whether this grant matches against a given file and caller uid:gid - bool match(const std::string &target_path, + bool match(std::string_view target_path, const int caller_uid, const int caller_gid, const vector *caller_gid_list) const; @@ -102,7 +104,7 @@ struct MDSCapMatch { * * @param target_path filesystem path without leading '/' */ - bool match_path(const std::string &target_path) const; + bool match_path(std::string_view target_path) const; }; struct MDSCapGrant { @@ -128,14 +130,14 @@ public: : cct(NULL), grants(grants_) { } void set_allow_all(); - bool parse(CephContext *cct, const std::string &str, std::ostream *err); + bool parse(CephContext *cct, std::string_view str, std::ostream *err); bool allow_all() const; - bool is_capable(const std::string &inode_path, + bool is_capable(std::string_view inode_path, uid_t inode_uid, gid_t inode_gid, unsigned inode_mode, uid_t uid, gid_t gid, const vector *caller_gid_list, unsigned mask, uid_t new_uid, gid_t new_gid) const; - bool path_capable(const std::string &inode_path) const; + bool path_capable(std::string_view inode_path) const; friend std::ostream &operator<<(std::ostream &out, const MDSAuthCaps &cap); }; diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index 04fcc3d7f0b38..ca0dc8cfed840 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -69,7 +69,7 @@ #define dout_prefix *_dout << "mds." << name << ' ' // cons/des -MDSDaemon::MDSDaemon(const std::string &n, Messenger *m, MonClient *mc) : +MDSDaemon::MDSDaemon(std::string_view n, Messenger *m, MonClient *mc) : Dispatcher(m->cct), mds_lock("MDSDaemon::mds_lock"), stopping(false), @@ -564,7 +564,7 @@ void MDSDaemon::tick() void MDSDaemon::send_command_reply(MCommand *m, MDSRank *mds_rank, int r, bufferlist outbl, - const std::string& outs) + std::string_view outs) { Session *session = static_cast(m->get_connection()->get_priv()); assert(session != NULL); diff --git a/src/mds/MDSDaemon.h b/src/mds/MDSDaemon.h index 7eaf9755982cf..29a273afadcda 100644 --- a/src/mds/MDSDaemon.h +++ b/src/mds/MDSDaemon.h @@ -15,6 +15,8 @@ #ifndef CEPH_MDS_H #define CEPH_MDS_H +#include + #include "common/LogClient.h" #include "common/Mutex.h" #include "common/Timer.h" @@ -63,7 +65,7 @@ class MDSDaemon : public Dispatcher, public md_config_obs_t { MDSRankDispatcher *mds_rank; public: - MDSDaemon(const std::string &n, Messenger *m, MonClient *mc); + MDSDaemon(std::string_view n, Messenger *m, MonClient *mc); ~MDSDaemon() override; int orig_argc; const char **orig_argv; @@ -141,7 +143,7 @@ protected: // special message types friend class C_MDS_Send_Command_Reply; static void send_command_reply(MCommand *m, MDSRank* mds_rank, int r, - bufferlist outbl, const std::string& outs); + bufferlist outbl, std::string_view outs); int _handle_command( const cmdmap_t &cmdmap, MCommand *m, diff --git a/src/mds/MDSMap.h b/src/mds/MDSMap.h index a6cd411f64d7d..e46cbb05ad4a4 100644 --- a/src/mds/MDSMap.h +++ b/src/mds/MDSMap.h @@ -16,6 +16,12 @@ #ifndef CEPH_MDSMAP_H #define CEPH_MDSMAP_H +#include +#include +#include +#include +#include + #include #include "include/types.h" @@ -23,11 +29,6 @@ #include "msg/Message.h" #include "include/health.h" -#include -#include -#include -#include - #include "common/config.h" #include "include/CompatSet.h" @@ -268,7 +269,7 @@ public: void set_flag(int f) { flags |= f; } void clear_flag(int f) { flags &= ~f; } - const std::string &get_fs_name() const {return fs_name;} + std::string_view get_fs_name() const {return fs_name;} void set_snaps_allowed() { set_flag(CEPH_MDSMAP_ALLOW_SNAPS); @@ -349,7 +350,7 @@ public: assert(up.count(m) && mds_info.count(up.at(m))); return mds_info.at(up.at(m)); } - mds_gid_t find_mds_gid_by_name(const std::string& s) const { + mds_gid_t find_mds_gid_by_name(std::string_view s) const { for (std::map::const_iterator p = mds_info.begin(); p != mds_info.end(); ++p) { diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index b9af92eca3c03..fc27554632988 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -12,6 +12,8 @@ * */ +#include + #include "common/debug.h" #include "common/errno.h" @@ -2002,7 +2004,7 @@ protected: public: C_MDS_Send_Command_Reply(MDSRank *_mds, MCommand *_m) : MDSInternalContext(_mds), m(_m) { m->get(); } - void send (int r, const std::string& out_str) { + void send (int r, std::string_view out_str) { bufferlist bl; MDSDaemon::send_command_reply(m, mds, r, bl, out_str); m->put(); @@ -2098,7 +2100,7 @@ void MDSRankDispatcher::dump_sessions(const SessionFilter &filter, Formatter *f) f->close_section(); //sessions } -void MDSRank::command_scrub_path(Formatter *f, const string& path, vector& scrubop_vec) +void MDSRank::command_scrub_path(Formatter *f, std::string_view path, vector& scrubop_vec) { bool force = false; bool recursive = false; @@ -2121,7 +2123,7 @@ void MDSRank::command_scrub_path(Formatter *f, const string& path, vectoris_up(target) || !mdsmap->is_in(target)) { derr << "bad MDS target " << target << dendl; diff --git a/src/mds/MDSRank.h b/src/mds/MDSRank.h index 26c76fef8611d..2f69c94924334 100644 --- a/src/mds/MDSRank.h +++ b/src/mds/MDSRank.h @@ -15,6 +15,8 @@ #ifndef MDS_RANK_H_ #define MDS_RANK_H_ +#include + #include "common/DecayCounter.h" #include "common/LogClient.h" #include "common/Timer.h" @@ -414,14 +416,14 @@ class MDSRank { protected: void dump_clientreplay_status(Formatter *f) const; - void command_scrub_path(Formatter *f, const string& path, vector& scrubop_vec); - void command_tag_path(Formatter *f, const string& path, - const string &tag); - void command_flush_path(Formatter *f, const string& path); + void command_scrub_path(Formatter *f, std::string_view path, vector& scrubop_vec); + void command_tag_path(Formatter *f, std::string_view path, + std::string_view tag); + void command_flush_path(Formatter *f, std::string_view path); void command_flush_journal(Formatter *f); void command_get_subtrees(Formatter *f); void command_export_dir(Formatter *f, - const std::string &path, mds_rank_t dest); + std::string_view path, mds_rank_t dest); bool command_dirfrag_split( cmdmap_t cmdmap, std::ostream &ss); @@ -432,7 +434,7 @@ class MDSRank { cmdmap_t cmdmap, std::ostream &ss, Formatter *f); - int _command_export_dir(const std::string &path, mds_rank_t dest); + int _command_export_dir(std::string_view path, mds_rank_t dest); int _command_flush_journal(std::stringstream *ss); CDir *_command_dirfrag_get( const cmdmap_t &cmdmap, diff --git a/src/mds/Mantle.cc b/src/mds/Mantle.cc index 18d1bc697e130..1be12108515ff 100644 --- a/src/mds/Mantle.cc +++ b/src/mds/Mantle.cc @@ -44,7 +44,7 @@ static int dout_wrapper(lua_State *L) return 0; } -int Mantle::balance(const std::string &script, +int Mantle::balance(std::string_view script, mds_rank_t whoami, const std::vector> &metrics, std::map &my_targets) @@ -52,7 +52,7 @@ int Mantle::balance(const std::string &script, lua_settop(L, 0); /* clear the stack */ /* load the balancer */ - if (luaL_loadstring(L, script.c_str())) { + if (luaL_loadstring(L, script.data())) { mantle_dout(0) << "WARNING: mantle could not load balancer: " << lua_tostring(L, -1) << mantle_dendl; return -EINVAL; diff --git a/src/mds/Mantle.h b/src/mds/Mantle.h index 7970562846f7a..ffc1843a5e68f 100644 --- a/src/mds/Mantle.h +++ b/src/mds/Mantle.h @@ -15,6 +15,8 @@ #ifndef CEPH_MANTLE_H #define CEPH_MANTLE_H +#include + #include #include #include @@ -26,7 +28,7 @@ class Mantle { public: Mantle(); ~Mantle() { if (L) lua_close(L); } - int balance(const std::string &script, + int balance(std::string_view script, mds_rank_t whoami, const std::vector > &metrics, std::map &my_targets); diff --git a/src/mds/Migrator.cc b/src/mds/Migrator.cc index df83c171f58f7..7851c3b1720b0 100644 --- a/src/mds/Migrator.cc +++ b/src/mds/Migrator.cc @@ -1607,7 +1607,7 @@ uint64_t Migrator::encode_export_dir(bufferlist& exportbl, dout(7) << "encode_export_dir exporting " << *dn << dendl; // dn name - encode(dn->name, exportbl); + encode(dn->get_name(), exportbl); encode(dn->last, exportbl); // state diff --git a/src/mds/ScrubHeader.h b/src/mds/ScrubHeader.h index c22683d028081..753216199a1c1 100644 --- a/src/mds/ScrubHeader.h +++ b/src/mds/ScrubHeader.h @@ -16,6 +16,8 @@ #ifndef SCRUB_HEADER_H_ #define SCRUB_HEADER_H_ +#include + class CInode; /** @@ -24,7 +26,7 @@ class CInode; */ class ScrubHeader { public: - ScrubHeader(const std::string &tag_, bool force_, bool recursive_, + 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) @@ -40,7 +42,7 @@ public: bool get_repair() const { return repair; } bool get_force() const { return force; } const CInode *get_origin() const { return origin; } - const std::string &get_tag() const { return tag; } + std::string_view get_tag() const { return tag; } Formatter &get_formatter() const { return *formatter; } bool get_repaired() const { return repaired; } diff --git a/src/mds/ScrubStack.cc b/src/mds/ScrubStack.cc index cb31a93f0fd64..290c30a5d26d8 100644 --- a/src/mds/ScrubStack.cc +++ b/src/mds/ScrubStack.cc @@ -390,7 +390,7 @@ void ScrubStack::_validate_inode_done(CInode *in, int r, if (parent) { auto dir = parent->get_dir(); mdcache->mds->damage_table.notify_dentry( - dir->inode->ino(), dir->frag, parent->last, parent->name, path); + dir->inode->ino(), dir->frag, parent->last, parent->get_name(), path); } } diff --git a/src/mds/Server.cc b/src/mds/Server.cc index 294cc243a43be..460632fe91050 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -61,6 +61,7 @@ #include #include +#include #include "common/config.h" @@ -2470,7 +2471,7 @@ bool Server::check_fragment_space(MDRequestRef &mdr, CDir *in) * verify that the dir exists and would own the dname. * do not check if the dentry exists. */ -CDir *Server::validate_dentry_dir(MDRequestRef& mdr, CInode *diri, const string& dname) +CDir *Server::validate_dentry_dir(MDRequestRef& mdr, CInode *diri, std::string_view dname) { // make sure parent is a dir? if (!diri->is_dir()) { @@ -2500,7 +2501,7 @@ CDir *Server::validate_dentry_dir(MDRequestRef& mdr, CInode *diri, const string& * prepare a null (or existing) dentry in given dir. * wait for any dn lock. */ -CDentry* Server::prepare_null_dentry(MDRequestRef& mdr, CDir *dir, const string& dname, bool okexist) +CDentry* Server::prepare_null_dentry(MDRequestRef& mdr, CDir *dir, std::string_view dname, bool okexist) { dout(10) << "prepare_null_dentry " << dname << " in " << *dir << dendl; assert(dir->is_auth()); @@ -2896,7 +2897,7 @@ CDentry* Server::rdlock_path_xlock_dentry(MDRequestRef& mdr, int n, } // make a null dentry? - const string &dname = refpath.last_dentry(); + std::string_view dname = refpath.last_dentry(); CDentry *dn; if (mustexist) { dn = dir->lookup(dname); @@ -3843,7 +3844,7 @@ void Server::handle_client_readdir(MDRequestRef& mdr) } assert(in); - if ((int)(dnbl.length() + dn->name.length() + sizeof(__u32) + sizeof(LeaseStat)) > bytes_left) { + if ((int)(dnbl.length() + dn->get_name().length() + sizeof(__u32) + sizeof(LeaseStat)) > bytes_left) { dout(10) << " ran out of room, stopping at " << dnbl.length() << " < " << bytes_left << dendl; break; } @@ -3852,7 +3853,7 @@ void Server::handle_client_readdir(MDRequestRef& mdr) // dentry dout(12) << "including dn " << *dn << dendl; - encode(dn->name, dnbl); + encode(dn->get_name(), dnbl); mds->locker->issue_client_lease(dn, client, dnbl, now, mdr->session); // inode @@ -6198,7 +6199,7 @@ bool Server::_rmdir_prepare_witness(MDRequestRef& mdr, mds_rank_t who, vectorsrcdnpath = filepath(trace.front()->get_dir()->ino()); for (auto dn : trace) - req->srcdnpath.push_dentry(dn->name); + req->srcdnpath.push_dentry(dn->get_name()); mdcache->replicate_stray(straydn, who, req->stray); req->op_stamp = mdr->get_op_stamp(); @@ -6260,9 +6261,9 @@ void Server::handle_slave_rmdir_prep(MDRequestRef& mdr) rmdir_rollback rollback; rollback.reqid = mdr->reqid; rollback.src_dir = dn->get_dir()->dirfrag(); - rollback.src_dname = dn->name; + rollback.src_dname = dn->get_name(); rollback.dest_dir = straydn->get_dir()->dirfrag(); - rollback.dest_dname = straydn->name; + rollback.dest_dname = straydn->get_name(); encode(rollback, mdr->more()->rollback_bl); dout(20) << " rollback is " << mdr->more()->rollback_bl.length() << " bytes" << dendl; @@ -6602,7 +6603,7 @@ void Server::handle_client_rename(MDRequestRef& mdr) respond_to_request(mdr, -EINVAL); return; } - const string &destname = destpath.last_dentry(); + std::string_view destname = destpath.last_dentry(); vector& srctrace = mdr->dn[1]; vector& desttrace = mdr->dn[0]; @@ -6707,7 +6708,7 @@ void Server::handle_client_rename(MDRequestRef& mdr) } // src == dest? - if (srcdn->get_dir() == destdir && srcdn->name == destname) { + if (srcdn->get_dir() == destdir && srcdn->get_name() == destname) { dout(7) << "rename src=dest, noop" << dendl; respond_to_request(mdr, 0); return; @@ -7053,10 +7054,10 @@ bool Server::_rename_prepare_witness(MDRequestRef& mdr, mds_rank_t who, setsrcdnpath = filepath(srctrace.front()->get_dir()->ino()); for (auto dn : srctrace) - req->srcdnpath.push_dentry(dn->name); + req->srcdnpath.push_dentry(dn->get_name()); req->destdnpath = filepath(dsttrace.front()->get_dir()->ino()); for (auto dn : dsttrace) - req->destdnpath.push_dentry(dn->name); + req->destdnpath.push_dentry(dn->get_name()); if (straydn) mdcache->replicate_stray(straydn, who, req->stray); @@ -7785,7 +7786,7 @@ void Server::handle_slave_rename_prep(MDRequestRef& mdr) rollback.orig_src.dirfrag = srcdn->get_dir()->dirfrag(); rollback.orig_src.dirfrag_old_mtime = srcdn->get_dir()->get_projected_fnode()->fragstat.mtime; rollback.orig_src.dirfrag_old_rctime = srcdn->get_dir()->get_projected_fnode()->rstat.rctime; - rollback.orig_src.dname = srcdn->name; + rollback.orig_src.dname = srcdn->get_name(); if (srcdnl->is_primary()) rollback.orig_src.ino = srcdnl->get_inode()->ino(); else { @@ -7797,7 +7798,7 @@ void Server::handle_slave_rename_prep(MDRequestRef& mdr) rollback.orig_dest.dirfrag = destdn->get_dir()->dirfrag(); rollback.orig_dest.dirfrag_old_mtime = destdn->get_dir()->get_projected_fnode()->fragstat.mtime; rollback.orig_dest.dirfrag_old_rctime = destdn->get_dir()->get_projected_fnode()->rstat.rctime; - rollback.orig_dest.dname = destdn->name; + rollback.orig_dest.dname = destdn->get_name(); if (destdnl->is_primary()) rollback.orig_dest.ino = destdnl->get_inode()->ino(); else if (destdnl->is_remote()) { @@ -7809,7 +7810,7 @@ void Server::handle_slave_rename_prep(MDRequestRef& mdr) rollback.stray.dirfrag = straydn->get_dir()->dirfrag(); rollback.stray.dirfrag_old_mtime = straydn->get_dir()->get_projected_fnode()->fragstat.mtime; rollback.stray.dirfrag_old_rctime = straydn->get_dir()->get_projected_fnode()->rstat.rctime; - rollback.stray.dname = straydn->name; + rollback.stray.dname = straydn->get_name(); } encode(rollback, mdr->more()->rollback_bl); dout(20) << " rollback is " << mdr->more()->rollback_bl.length() << " bytes" << dendl; @@ -8601,7 +8602,7 @@ void Server::handle_client_mksnap(MDRequestRef& mdr) return; } - const string &snapname = req->get_filepath().last_dentry(); + std::string_view snapname = req->get_filepath().last_dentry(); if (mdr->client_request->get_caller_uid() < g_conf->mds_snap_min_uid || mdr->client_request->get_caller_uid() > g_conf->mds_snap_max_uid) { dout(20) << "mksnap " << snapname << " on " << *diri << " denied to uid " << mdr->client_request->get_caller_uid() << dendl; @@ -8740,7 +8741,7 @@ void Server::handle_client_rmsnap(MDRequestRef& mdr) return; } - const string &snapname = req->get_filepath().last_dentry(); + std::string_view snapname = req->get_filepath().last_dentry(); if (mdr->client_request->get_caller_uid() < g_conf->mds_snap_min_uid || mdr->client_request->get_caller_uid() > g_conf->mds_snap_max_uid) { dout(20) << "rmsnap " << snapname << " on " << *diri << " denied to uid " << mdr->client_request->get_caller_uid() << dendl; @@ -8878,8 +8879,8 @@ void Server::handle_client_renamesnap(MDRequestRef& mdr) return; } - const string &dstname = req->get_filepath().last_dentry(); - const string &srcname = req->get_filepath2().last_dentry(); + std::string_view dstname = req->get_filepath().last_dentry(); + std::string_view srcname = req->get_filepath2().last_dentry(); dout(10) << "renamesnap " << srcname << "->" << dstname << " on " << *diri << dendl; if (srcname.length() == 0 || srcname[0] == '_') { diff --git a/src/mds/Server.h b/src/mds/Server.h index ade5d7ba09a82..925bac9898bba 100644 --- a/src/mds/Server.h +++ b/src/mds/Server.h @@ -15,6 +15,8 @@ #ifndef CEPH_MDS_SERVER_H #define CEPH_MDS_SERVER_H +#include + #include "MDSRank.h" #include "Mutation.h" @@ -166,9 +168,9 @@ public: bool check_fragment_space(MDRequestRef& mdr, CDir *in); bool check_access(MDRequestRef& mdr, CInode *in, unsigned mask); bool _check_access(Session *session, CInode *in, unsigned mask, int caller_uid, int caller_gid, int setattr_uid, int setattr_gid); - CDir *validate_dentry_dir(MDRequestRef& mdr, CInode *diri, const string& dname); + CDir *validate_dentry_dir(MDRequestRef& mdr, CInode *diri, std::string_view dname); CDir *traverse_to_auth_dir(MDRequestRef& mdr, vector &trace, filepath refpath); - CDentry *prepare_null_dentry(MDRequestRef& mdr, CDir *dir, const string& dname, bool okexist=false); + CDentry *prepare_null_dentry(MDRequestRef& mdr, CDir *dir, std::string_view dname, bool okexist=false); CDentry *prepare_stray_dentry(MDRequestRef& mdr, CInode *in); CInode* prepare_new_inode(MDRequestRef& mdr, CDir *dir, inodeno_t useino, unsigned mode, file_layout_t *layout=NULL); diff --git a/src/mds/SessionMap.cc b/src/mds/SessionMap.cc index 93580d2399d03..dff223cf61171 100644 --- a/src/mds/SessionMap.cc +++ b/src/mds/SessionMap.cc @@ -972,7 +972,7 @@ int SessionFilter::parse( * Strict boolean parser. Allow true/false/0/1. * Anything else is -EINVAL. */ - auto is_true = [](const std::string &bstr, bool *out) -> bool + auto is_true = [](std::string_view bstr, bool *out) -> bool { assert(out != nullptr); diff --git a/src/mds/SnapClient.h b/src/mds/SnapClient.h index 486bd22daaefb..4cda3956ab5b8 100644 --- a/src/mds/SnapClient.h +++ b/src/mds/SnapClient.h @@ -15,6 +15,8 @@ #ifndef CEPH_SNAPCLIENT_H #define CEPH_SNAPCLIENT_H +#include + #include "MDSTableClient.h" #include "snap.h" @@ -29,7 +31,7 @@ public: void resend_queries() override {} void handle_query_result(MMDSTableRequest *m) override {} - void prepare_create(inodeno_t dirino, const string& name, utime_t stamp, + void prepare_create(inodeno_t dirino, std::string_view name, utime_t stamp, version_t *pstid, bufferlist *pbl, MDSInternalContextBase *onfinish) { bufferlist bl; __u32 op = TABLE_OP_CREATE; @@ -57,7 +59,7 @@ public: _prepare(bl, pstid, pbl, onfinish); } - void prepare_update(inodeno_t ino, snapid_t snapid, const string& name, utime_t stamp, + void prepare_update(inodeno_t ino, snapid_t snapid, std::string_view name, utime_t stamp, version_t *pstid, MDSInternalContextBase *onfinish) { bufferlist bl; __u32 op = TABLE_OP_UPDATE; diff --git a/src/mds/SnapRealm.cc b/src/mds/SnapRealm.cc index 438373a4cba45..4307fdd78bff6 100644 --- a/src/mds/SnapRealm.cc +++ b/src/mds/SnapRealm.cc @@ -16,6 +16,8 @@ #include "MDCache.h" #include "MDSRank.h" +#include + #include "messages/MClientSnap.h" @@ -338,7 +340,7 @@ void SnapRealm::get_snap_info(map& infomap, snapid_t first, parent->get_snap_info(infomap, std::max(first, srnode.current_parent_since), last); } -const string& SnapRealm::get_snapname(snapid_t snapid, inodeno_t atino) +std::string_view SnapRealm::get_snapname(snapid_t snapid, inodeno_t atino) { auto srnode_snaps_entry = srnode.snaps.find(snapid); if (srnode_snaps_entry != srnode.snaps.end()) { @@ -361,7 +363,7 @@ const string& SnapRealm::get_snapname(snapid_t snapid, inodeno_t atino) return parent->get_snapname(snapid, atino); } -snapid_t SnapRealm::resolve_snapname(const string& n, inodeno_t atino, snapid_t first, snapid_t last) +snapid_t SnapRealm::resolve_snapname(std::string_view n, inodeno_t atino, snapid_t first, snapid_t last) { // first try me dout(10) << "resolve_snapname '" << n << "' in [" << first << "," << last << "]" << dendl; @@ -378,7 +380,7 @@ snapid_t SnapRealm::resolve_snapname(const string& n, inodeno_t atino, snapid_t int next_ = n.find('_', 1); if (next_ < 0) return 0; pname = n.substr(1, next_ - 1); - pino = atoll(n.c_str() + next_ + 1); + pino = atoll(n.data() + next_ + 1); dout(10) << " " << n << " parses to name '" << pname << "' dirino " << pino << dendl; } diff --git a/src/mds/SnapRealm.h b/src/mds/SnapRealm.h index 4a99d639140a1..c0723882996e7 100644 --- a/src/mds/SnapRealm.h +++ b/src/mds/SnapRealm.h @@ -15,6 +15,8 @@ #ifndef CEPH_MDS_SNAPREALM_H #define CEPH_MDS_SNAPREALM_H +#include + #include "mdstypes.h" #include "snap.h" #include "include/xlist.h" @@ -63,7 +65,7 @@ public: inodes_with_caps(0) { } - bool exists(const string &name) const { + bool exists(std::string_view name) const { for (map::const_iterator p = srnode.snaps.begin(); p != srnode.snaps.end(); ++p) { @@ -94,8 +96,8 @@ public: const bufferlist& get_snap_trace(); void build_snap_trace(bufferlist& snapbl) const; - const string& get_snapname(snapid_t snapid, inodeno_t atino); - snapid_t resolve_snapname(const string &name, inodeno_t atino, snapid_t first=0, snapid_t last=CEPH_NOSNAP); + std::string_view get_snapname(snapid_t snapid, inodeno_t atino); + snapid_t resolve_snapname(std::string_view name, inodeno_t atino, snapid_t first=0, snapid_t last=CEPH_NOSNAP); const set& get_snaps() const; const SnapContext& get_snap_context() const; diff --git a/src/mds/events/EMetaBlob.h b/src/mds/events/EMetaBlob.h index 97a8a66b41384..55db2db31ec4c 100644 --- a/src/mds/events/EMetaBlob.h +++ b/src/mds/events/EMetaBlob.h @@ -15,6 +15,8 @@ #ifndef CEPH_MDS_EMETABLOB_H #define CEPH_MDS_EMETABLOB_H +#include + #include #include "../CInode.h" @@ -64,7 +66,7 @@ public: static const int STATE_DIRTYPOOL = (1<<2); static const int STATE_NEED_SNAPFLUSH = (1<<3); typedef compact_map old_inodes_t; - string dn; // dentry + std::string dn; // dentry snapid_t dnfirst, dnlast; version_t dnv{0}; inode_t inode; // if it's not @@ -79,7 +81,7 @@ public: fullbit(const fullbit& o); const fullbit& operator=(const fullbit& o); - fullbit(const string& d, snapid_t df, snapid_t dl, + fullbit(std::string_view d, snapid_t df, snapid_t dl, version_t v, const inode_t& i, const fragtree_t &dft, const map &xa, const string& sym, snapid_t os, const bufferlist &sbl, __u8 st, @@ -137,14 +139,14 @@ public: /* remotebit - a dentry + remote inode link (i.e. just an ino) */ struct remotebit { - string dn; + std::string dn; snapid_t dnfirst, dnlast; version_t dnv; inodeno_t ino; unsigned char d_type; bool dirty; - remotebit(const string& d, snapid_t df, snapid_t dl, version_t v, inodeno_t i, unsigned char dt, bool dr) : + remotebit(std::string_view d, snapid_t df, snapid_t dl, version_t v, inodeno_t i, unsigned char dt, bool dr) : dn(d), dnfirst(df), dnlast(dl), dnv(v), ino(i), d_type(dt), dirty(dr) { } explicit remotebit(bufferlist::iterator &p) { decode(p); } remotebit(): dnfirst(0), dnlast(0), dnv(0), ino(0), @@ -166,12 +168,12 @@ public: * nullbit - a null dentry */ struct nullbit { - string dn; + std::string dn; snapid_t dnfirst, dnlast; version_t dnv; bool dirty; - nullbit(const string& d, snapid_t df, snapid_t dl, version_t v, bool dr) : + nullbit(std::string_view d, snapid_t df, snapid_t dl, version_t v, bool dr) : dn(d), dnfirst(df), dnlast(dl), dnv(v), dirty(dr) { } explicit nullbit(bufferlist::iterator &p) { decode(p); } nullbit(): dnfirst(0), dnlast(0), dnv(0), dirty(false) {} diff --git a/src/mds/inode_backtrace.h b/src/mds/inode_backtrace.h index 08cbf65af9084..87b988f82821d 100644 --- a/src/mds/inode_backtrace.h +++ b/src/mds/inode_backtrace.h @@ -3,6 +3,8 @@ #ifndef CEPH_INODE_BACKTRACE_H #define CEPH_INODE_BACKTRACE_H +#include + #include "mdstypes.h" namespace ceph { @@ -25,7 +27,7 @@ struct inode_backpointer_t { version_t version; // child's version at time of backpointer creation inode_backpointer_t() : version(0) {} - inode_backpointer_t(inodeno_t i, const string &d, version_t v) : dirino(i), dname(d), version(v) {} + inode_backpointer_t(inodeno_t i, std::string_view d, version_t v) : dirino(i), dname(d), version(v) {} void encode(bufferlist& bl) const; void decode(bufferlist::iterator &bl); diff --git a/src/mds/journal.cc b/src/mds/journal.cc index 5efb3fe3d6563..a0feaed3bec88 100644 --- a/src/mds/journal.cc +++ b/src/mds/journal.cc @@ -984,21 +984,21 @@ void EMetaBlob::get_paths( for (list >::const_iterator iter = fb_list.begin(); iter != fb_list.end(); ++iter) { - std::string const &dentry = (*iter)->dn; - children[dir_ino].push_back(dentry); + std::string_view dentry = (*iter)->dn; + children[dir_ino].emplace_back(dentry); ino_locations[(*iter)->inode.ino] = Location(dir_ino, dentry); } for (list::const_iterator iter = nb_list.begin(); iter != nb_list.end(); ++iter) { - std::string const &dentry = iter->dn; - children[dir_ino].push_back(dentry); + std::string_view dentry = iter->dn; + children[dir_ino].emplace_back(dentry); } for (list::const_iterator iter = rb_list.begin(); iter != rb_list.end(); ++iter) { - std::string const &dentry = iter->dn; - children[dir_ino].push_back(dentry); + std::string_view dentry = iter->dn; + children[dir_ino].emplace_back(dentry); } } @@ -1015,7 +1015,7 @@ void EMetaBlob::get_paths( list > const &fb_list = dl.get_dfull(); for (list >::const_iterator iter = fb_list.begin(); iter != fb_list.end(); ++iter) { - std::string const &dentry = (*iter)->dn; + std::string_view dentry = (*iter)->dn; if (children.find((*iter)->inode.ino) == children.end()) { leaf_locations.push_back(Location(dir_ino, dentry)); } @@ -1024,14 +1024,14 @@ void EMetaBlob::get_paths( list const &nb_list = dl.get_dnull(); for (list::const_iterator iter = nb_list.begin(); iter != nb_list.end(); ++iter) { - std::string const &dentry = iter->dn; + std::string_view dentry = iter->dn; leaf_locations.push_back(Location(dir_ino, dentry)); } list const &rb_list = dl.get_dremote(); for (list::const_iterator iter = rb_list.begin(); iter != rb_list.end(); ++iter) { - std::string const &dentry = iter->dn; + std::string_view dentry = iter->dn; leaf_locations.push_back(Location(dir_ino, dentry)); } } diff --git a/src/mds/mdstypes.h b/src/mds/mdstypes.h index 36bca15d7a355..380cea18f4296 100644 --- a/src/mds/mdstypes.h +++ b/src/mds/mdstypes.h @@ -9,6 +9,7 @@ #include #include #include +#include #include "common/config.h" #include "common/Clock.h" @@ -723,13 +724,13 @@ WRITE_CLASS_ENCODER_FEATURES(session_info_t) struct dentry_key_t { snapid_t snapid = 0; - const char *name = nullptr; + std::string_view name; __u32 hash = 0; dentry_key_t() {} - dentry_key_t(snapid_t s, const char *n, __u32 h=0) : + dentry_key_t(snapid_t s, std::string_view n, __u32 h=0) : snapid(s), name(n), hash(h) {} - bool is_valid() { return name || snapid; } + bool is_valid() { return name.length() || snapid; } // encode into something that can be decoded as a string. // name_ (head) or name_%x (!head) @@ -756,19 +757,20 @@ struct dentry_key_t { decode(key, bl); decode_helper(key, nm, sn); } - static void decode_helper(const string& key, string& nm, snapid_t& sn) { + static void decode_helper(std::string_view key, string& nm, snapid_t& sn) { size_t i = key.find_last_of('_'); assert(i != string::npos); - if (key.compare(i+1, string::npos, "head") == 0) { + if (key.compare(i+1, std::string_view::npos, "head") == 0) { // name_head sn = CEPH_NOSNAP; } else { // name_%x long long unsigned x = 0; - sscanf(key.c_str() + i + 1, "%llx", &x); + std::string x_str(key.substr(i+1)); + sscanf(x_str.c_str(), "%llx", &x); sn = x; } - nm = string(key.c_str(), i); + nm = key.substr(0, i); } }; @@ -785,7 +787,7 @@ inline bool operator<(const dentry_key_t& k1, const dentry_key_t& k2) int c = ceph_frag_value(k1.hash) - ceph_frag_value(k2.hash); if (c) return c < 0; - c = strcmp(k1.name, k2.name); + c = k1.name.compare(k2.name); if (c) return c < 0; return k1.snapid < k2.snapid; @@ -799,7 +801,7 @@ struct string_snap_t { string name; snapid_t snapid; string_snap_t() {} - string_snap_t(const string& n, snapid_t s) : name(n), snapid(s) {} + string_snap_t(std::string_view n, snapid_t s) : name(n), snapid(s) {} string_snap_t(const char *n, snapid_t s) : name(n), snapid(s) {} void encode(bufferlist& bl) const; @@ -810,7 +812,7 @@ struct string_snap_t { WRITE_CLASS_ENCODER(string_snap_t) inline bool operator<(const string_snap_t& l, const string_snap_t& r) { - int c = strcmp(l.name.c_str(), r.name.c_str()); + int c = l.name.compare(r.name); return c < 0 || (c == 0 && l.snapid < r.snapid); } @@ -901,7 +903,7 @@ struct cap_reconnect_t { memset(&capinfo, 0, sizeof(capinfo)); snap_follows = 0; } - cap_reconnect_t(uint64_t cap_id, inodeno_t pino, const string& p, int w, int i, + cap_reconnect_t(uint64_t cap_id, inodeno_t pino, std::string_view p, int w, int i, inodeno_t sr, snapid_t sf, bufferlist& lb) : path(p) { capinfo.cap_id = cap_id; diff --git a/src/mds/snap.cc b/src/mds/snap.cc index 1d8106b032196..525bccf5b8592 100644 --- a/src/mds/snap.cc +++ b/src/mds/snap.cc @@ -12,6 +12,8 @@ * */ +#include + #include "snap.h" #include "common/Formatter.h" @@ -66,7 +68,7 @@ ostream& operator<<(ostream& out, const SnapInfo &sn) << "' " << sn.stamp << ")"; } -const string& SnapInfo::get_long_name() +std::string_view SnapInfo::get_long_name() { if (long_name.length() == 0) { char nm[80]; diff --git a/src/mds/snap.h b/src/mds/snap.h index 4032520c605a8..0c44c83cfc6bd 100644 --- a/src/mds/snap.h +++ b/src/mds/snap.h @@ -15,6 +15,8 @@ #ifndef CEPH_MDS_SNAP_H #define CEPH_MDS_SNAP_H +#include + #include "mdstypes.h" #include "common/snap_types.h" @@ -34,7 +36,7 @@ struct SnapInfo { void dump(Formatter *f) const; static void generate_test_instances(list& ls); - const string& get_long_name(); + std::string_view get_long_name(); }; WRITE_CLASS_ENCODER(SnapInfo) diff --git a/src/messages/MCacheExpire.h b/src/messages/MCacheExpire.h index 21acb5005bc03..d2b6ca579c8b5 100644 --- a/src/messages/MCacheExpire.h +++ b/src/messages/MCacheExpire.h @@ -15,6 +15,8 @@ #ifndef CEPH_MCACHEEXPIRE_H #define CEPH_MCACHEEXPIRE_H +#include + #include "mds/mdstypes.h" class MCacheExpire : public Message { @@ -78,7 +80,7 @@ public: void add_dir(dirfrag_t r, dirfrag_t df, unsigned nonce) { realms[r].dirs[df] = nonce; } - void add_dentry(dirfrag_t r, dirfrag_t df, const string& dn, snapid_t last, unsigned nonce) { + void add_dentry(dirfrag_t r, dirfrag_t df, std::string_view dn, snapid_t last, unsigned nonce) { realms[r].dentries[df][pair(dn,last)] = nonce; } diff --git a/src/messages/MClientLease.h b/src/messages/MClientLease.h index ecbaa8ddd4414..15b95024c9415 100644 --- a/src/messages/MClientLease.h +++ b/src/messages/MClientLease.h @@ -16,11 +16,13 @@ #ifndef CEPH_MCLIENTLEASE_H #define CEPH_MCLIENTLEASE_H +#include + #include "msg/Message.h" struct MClientLease : public Message { struct ceph_mds_lease h; - string dname; + std::string dname; int get_action() const { return h.action; } ceph_seq_t get_seq() const { return h.seq; } @@ -40,7 +42,7 @@ struct MClientLease : public Message { h.last = sl; h.duration_ms = 0; } - MClientLease(int ac, ceph_seq_t seq, int m, uint64_t i, uint64_t sf, uint64_t sl, const string& d) : + MClientLease(int ac, ceph_seq_t seq, int m, uint64_t i, uint64_t sf, uint64_t sl, std::string_view d) : Message(CEPH_MSG_CLIENT_LEASE), dname(d) { h.action = ac; diff --git a/src/messages/MClientRequest.h b/src/messages/MClientRequest.h index 1baa12f068cfb..5732c5f08a056 100644 --- a/src/messages/MClientRequest.h +++ b/src/messages/MClientRequest.h @@ -33,6 +33,8 @@ * */ +#include + #include "msg/Message.h" #include "include/filepath.h" #include "mds/mdstypes.h" @@ -137,7 +139,7 @@ public: void set_retry_attempt(int a) { head.num_retry = a; } void set_filepath(const filepath& fp) { path = fp; } void set_filepath2(const filepath& fp) { path2 = fp; } - void set_string2(const char *s) { path2.set_path(s, 0); } + void set_string2(const char *s) { path2.set_path(std::string_view(s), 0); } void set_caller_uid(unsigned u) { head.caller_uid = u; } void set_caller_gid(unsigned g) { head.caller_gid = g; } void set_gid_list(int count, const gid_t *gids) { diff --git a/src/messages/MCommandReply.h b/src/messages/MCommandReply.h index 4af21e4da045d..63e45c8a356e9 100644 --- a/src/messages/MCommandReply.h +++ b/src/messages/MCommandReply.h @@ -15,6 +15,8 @@ #ifndef CEPH_MCOMMANDREPLY_H #define CEPH_MCOMMANDREPLY_H +#include + #include "msg/Message.h" #include "MCommand.h" @@ -29,7 +31,7 @@ class MCommandReply : public Message { : Message(MSG_COMMAND_REPLY), r(_r) { header.tid = m->get_tid(); } - MCommandReply(int _r, string s) + MCommandReply(int _r, std::string_view s) : Message(MSG_COMMAND_REPLY), r(_r), rs(s) { } private: diff --git a/src/messages/MDentryLink.h b/src/messages/MDentryLink.h index 0e1c16064796f..fe686d1daa7b3 100644 --- a/src/messages/MDentryLink.h +++ b/src/messages/MDentryLink.h @@ -16,6 +16,8 @@ #ifndef CEPH_MDENTRYLINK_H #define CEPH_MDENTRYLINK_H +#include + class MDentryLink : public Message { dirfrag_t subtree; dirfrag_t dirfrag; @@ -32,7 +34,7 @@ class MDentryLink : public Message { MDentryLink() : Message(MSG_MDS_DENTRYLINK) { } - MDentryLink(dirfrag_t r, dirfrag_t df, string& n, bool p) : + MDentryLink(dirfrag_t r, dirfrag_t df, std::string_view n, bool p) : Message(MSG_MDS_DENTRYLINK), subtree(r), dirfrag(df), diff --git a/src/messages/MDentryUnlink.h b/src/messages/MDentryUnlink.h index 86f5f3d5f9354..c6f98369ce1bc 100644 --- a/src/messages/MDentryUnlink.h +++ b/src/messages/MDentryUnlink.h @@ -16,6 +16,8 @@ #ifndef CEPH_MDENTRYUNLINK_H #define CEPH_MDENTRYUNLINK_H +#include + class MDentryUnlink : public Message { dirfrag_t dirfrag; string dn; @@ -28,7 +30,7 @@ class MDentryUnlink : public Message { MDentryUnlink() : Message(MSG_MDS_DENTRYUNLINK) { } - MDentryUnlink(dirfrag_t df, string& n) : + MDentryUnlink(dirfrag_t df, std::string_view n) : Message(MSG_MDS_DENTRYUNLINK), dirfrag(df), dn(n) {} diff --git a/src/messages/MDiscoverReply.h b/src/messages/MDiscoverReply.h index 6e064c2ddb32b..54784ba81af66 100644 --- a/src/messages/MDiscoverReply.h +++ b/src/messages/MDiscoverReply.h @@ -97,7 +97,7 @@ class MDiscoverReply : public Message { bool is_flag_error_dn() { return flag_error_dn; } bool is_flag_error_dir() { return flag_error_dir; } - std::string& get_error_dentry() { return error_dentry; } + const std::string& get_error_dentry() { return error_dentry; } int get_starts_with() { return starts_with; } @@ -158,7 +158,7 @@ public: } // void set_flag_forward() { flag_forward = true; } - void set_flag_error_dn(const std::string& dn) { + void set_flag_error_dn(std::string_view dn) { flag_error_dn = true; error_dentry = dn; } @@ -168,7 +168,7 @@ public: void set_dir_auth_hint(int a) { dir_auth_hint = a; } - void set_error_dentry(const std::string& dn) { + void set_error_dentry(std::string_view dn) { error_dentry = dn; } diff --git a/src/messages/MMDSBeacon.h b/src/messages/MMDSBeacon.h index 1d3bac8eb355b..44a3eb9c63cb7 100644 --- a/src/messages/MMDSBeacon.h +++ b/src/messages/MMDSBeacon.h @@ -15,6 +15,8 @@ #ifndef CEPH_MMDSBEACON_H #define CEPH_MMDSBEACON_H +#include + #include "messages/PaxosServiceMessage.h" #include "include/types.h" @@ -138,7 +140,7 @@ struct MDSHealthMetric } MDSHealthMetric() : type(MDS_HEALTH_NULL), sev(HEALTH_OK) {} - MDSHealthMetric(mds_metric_t type_, health_status_t sev_, std::string const &message_) + MDSHealthMetric(mds_metric_t type_, health_status_t sev_, std::string_view message_) : type(type_), sev(sev_), message(message_) {} }; WRITE_CLASS_ENCODER(MDSHealthMetric) diff --git a/src/messages/MMDSCacheRejoin.h b/src/messages/MMDSCacheRejoin.h index b572be12069f7..a3d12eca2231d 100644 --- a/src/messages/MMDSCacheRejoin.h +++ b/src/messages/MMDSCacheRejoin.h @@ -15,6 +15,8 @@ #ifndef CEPH_MMDSCACHEREJOIN_H #define CEPH_MMDSCACHEREJOIN_H +#include + #include "msg/Message.h" #include "include/types.h" @@ -280,20 +282,20 @@ public: void add_weak_dirfrag(dirfrag_t df) { weak_dirfrags.insert(df); } - void add_weak_dentry(inodeno_t dirino, const string& dname, snapid_t last, dn_weak& dnw) { + void add_weak_dentry(inodeno_t dirino, std::string_view dname, snapid_t last, dn_weak& dnw) { weak[dirino][string_snap_t(dname, last)] = dnw; } - void add_weak_primary_dentry(inodeno_t dirino, const string& dname, snapid_t first, snapid_t last, inodeno_t ino) { + void add_weak_primary_dentry(inodeno_t dirino, std::string_view dname, snapid_t first, snapid_t last, inodeno_t ino) { weak[dirino][string_snap_t(dname, last)] = dn_weak(first, ino); } - void add_strong_dentry(dirfrag_t df, const string& dname, snapid_t first, snapid_t last, inodeno_t pi, inodeno_t ri, unsigned char rdt, int n, int ls) { + void add_strong_dentry(dirfrag_t df, std::string_view dname, snapid_t first, snapid_t last, inodeno_t pi, inodeno_t ri, unsigned char rdt, int n, int ls) { strong_dentries[df][string_snap_t(dname, last)] = dn_strong(first, pi, ri, rdt, n, ls); } - void add_dentry_authpin(dirfrag_t df, const string& dname, snapid_t last, + void add_dentry_authpin(dirfrag_t df, std::string_view dname, snapid_t last, const metareqid_t& ri, __u32 attempt) { authpinned_dentries[df][string_snap_t(dname, last)].push_back(slave_reqid(ri, attempt)); } - void add_dentry_xlock(dirfrag_t df, const string& dname, snapid_t last, + void add_dentry_xlock(dirfrag_t df, std::string_view dname, snapid_t last, const metareqid_t& ri, __u32 attempt) { xlocked_dentries[df][string_snap_t(dname, last)] = slave_reqid(ri, attempt); } diff --git a/src/mgr/PyFormatter.cc b/src/mgr/PyFormatter.cc index 4c9aec3053713..f2ef0de0b6f32 100644 --- a/src/mgr/PyFormatter.cc +++ b/src/mgr/PyFormatter.cc @@ -55,9 +55,9 @@ void PyFormatter::dump_float(const char *name, double d) dump_pyobject(name, PyFloat_FromDouble(d)); } -void PyFormatter::dump_string(const char *name, const std::string& s) +void PyFormatter::dump_string(const char *name, std::string_view s) { - dump_pyobject(name, PyString_FromString(s.c_str())); + dump_pyobject(name, PyString_FromString(s.data())); } void PyFormatter::dump_bool(const char *name, bool b) diff --git a/src/mgr/PyFormatter.h b/src/mgr/PyFormatter.h index e74f2fe7c49e0..8b44916a04758 100644 --- a/src/mgr/PyFormatter.h +++ b/src/mgr/PyFormatter.h @@ -85,7 +85,7 @@ public: void dump_unsigned(const char *name, uint64_t u) override; void dump_int(const char *name, int64_t u) override; void dump_float(const char *name, double d) override; - void dump_string(const char *name, const std::string& s) override; + void dump_string(const char *name, std::string_view s) override; std::ostream& dump_stream(const char *name) override; void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) override; diff --git a/src/rgw/rgw_formats.cc b/src/rgw/rgw_formats.cc index 96c709789af46..0803a614ff85e 100644 --- a/src/rgw/rgw_formats.cc +++ b/src/rgw/rgw_formats.cc @@ -125,9 +125,9 @@ void RGWFormatter_Plain::dump_float(const char *name, double d) dump_value_int(name, "%f", d); } -void RGWFormatter_Plain::dump_string(const char *name, const std::string& s) +void RGWFormatter_Plain::dump_string(const char *name, std::string_view s) { - dump_format(name, "%s", s.c_str()); + dump_format(name, "%s", s.data()); } std::ostream& RGWFormatter_Plain::dump_stream(const char *name) diff --git a/src/rgw/rgw_formats.h b/src/rgw/rgw_formats.h index a50965873836f..81cc5478d0627 100644 --- a/src/rgw/rgw_formats.h +++ b/src/rgw/rgw_formats.h @@ -41,7 +41,7 @@ public: void dump_unsigned(const char *name, uint64_t u) override; void dump_int(const char *name, int64_t u) override; void dump_float(const char *name, double d) override; - void dump_string(const char *name, const std::string& s) override; + void dump_string(const char *name, std::string_view s) override; std::ostream& dump_stream(const char *name) override; void dump_format_va(const char *name, const char *ns, bool quoted, const char *fmt, va_list ap) override; int get_len() const override;