This is necessary to allow many interfaces to take mempool allocated strings.
Signed-off-by: Patrick Donnelly <pdonnell@redhat.com>
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();
}
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();
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;
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 << '\"';
}
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);
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()) << "</" << e << ">";
+ m_ss << "<" << e << ">" << escape_xml_str(s.data()) << "</" << e << ">";
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(),
std::string attrs_str;
get_attrs_str(&attrs, attrs_str);
print_spaces();
- m_ss << "<" << e << attrs_str << ">" << escape_xml_str(s.c_str()) << "</" << e << ">";
+ m_ss << "<" << e << attrs_str << ">" << escape_xml_str(s.data()) << "</" << e << ">";
if (m_pretty)
m_ss << "\n";
}
}
}
-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<char> escaped(len, '\0');
- escape_xml_attr(str, &escaped[0]);
+ escape_xml_attr(str.data(), &escaped[0]);
return std::string(&escaped[0]);
}
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);
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);
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", "");
}
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"));
{
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);
}
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;
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();
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;
/* 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;
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;
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 << "<li>" << e << ": " << escape_xml_str(s.c_str()) << attrs_str << "</li>";
+ m_ss << "<li>" << e << ": " << escape_xml_str(s.data()) << attrs_str << "</li>";
if (m_pretty)
m_ss << "\n";
}
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 <typename T> void dump_template(const char *name, T arg);
#include <deque>
#include <vector>
#include <string>
+#include <string_view>
#include <tuple>
#include <boost/optional/optional_io.hpp>
#include <boost/tuple/tuple.hpp>
// 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;
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();
// 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);
}
#include <iosfwd>
#include <string>
+#include <string_view>
#include <vector>
#include "buffer.h"
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) {
}
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;
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);
#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),
#ifndef BEACON_STATE_H
#define BEACON_STATE_H
+#include <string_view>
+
#include "include/types.h"
#include "include/Context.h"
#include "common/Mutex.h"
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);
#define CEPH_CDENTRY_H
#include <string>
+#include <string_view>
#include <set>
#include "include/counter.h"
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),
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),
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; }
*
*/
+#include <string_view>
#include "include/types.h"
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;
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;
* 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
// 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)
}
-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
// 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;
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
// 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)
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() {
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];
* 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);
<< " " << 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<MDSInternalContextBase*>& ls)
{
if (waiting_on_dentry.empty())
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;
}
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)) {
}
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,
if (stale) {
if (!dn) {
- stale_items.insert(key);
+ stale_items.insert(std::string(key));
*force_dirty = true;
}
return dn;
if (stale) {
if (!dn) {
- stale_items.insert(key);
+ stale_items.insert(std::string(key));
*force_dirty = true;
}
return dn;
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
}
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();
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
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
#ifndef CEPH_CDIR_H
#define CEPH_CDIR_H
+#include <iosfwd>
+#include <list>
+#include <map>
+#include <set>
+#include <string>
+#include <string_view>
+
#include "include/counter.h"
#include "include/types.h"
#include "include/buffer_fwd.h"
#include "MDSCacheObject.h"
-#include <iosfwd>
-
-#include <list>
-#include <set>
-#include <map>
-#include <string>
-
#include "CInode.h"
// -- 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);
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();
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<dentry_key_t>& keys);
protected:
compact_set<string> wanted_items;
bufferlist& hdrbl, std::map<std::string, bufferlist>& 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,
/**
* 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)
compact_map< string_snap_t, std::list<MDSInternalContextBase*> > 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<MDSInternalContextBase*>& 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<MDSInternalContextBase*>& ls);
void take_sub_waiting(std::list<MDSInternalContextBase*>& ls); // dentry or ino
void add_waiter(uint64_t mask, MDSInternalContextBase *c) override;
// 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)
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.
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();
}
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;
}
/**
* 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();
// 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.
#ifndef CEPH_CINODE_H
#define CEPH_CINODE_H
+#include <list>
+#include <map>
+#include <set>
+#include <string_view>
+
#include "common/config.h"
#include "include/counter.h"
#include "include/elist.h"
#include "SnapRealm.h"
#include "Mutation.h"
-#include <list>
-#include <set>
-#include <map>
-
#define dout_context g_ceph_context
class Context;
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 {
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_)
{}
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;
}
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.
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;
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(
#ifndef DAMAGE_TABLE_H_
#define DAMAGE_TABLE_H_
+#include <string_view>
+
#include "mdstypes.h"
#include "include/random.h"
}
}
- DentryIdent(const std::string &dname_, snapid_t snap_id_)
+ DentryIdent(std::string_view dname_, snapid_t snap_id_)
: dname(dname_), snap_id(snap_id_)
{}
};
*
* @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.
*/
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(
}
-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)
{
}
int FSMap::parse_filesystem(
- std::string const &ns_str,
+ std::string_view ns_str,
std::shared_ptr<const Filesystem> *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<const Filesystem>(fs.second);
return 0;
}
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;
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)
* 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
{
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 << "'";
#ifndef CEPH_FSMAP_H
#define CEPH_FSMAP_H
+#include <map>
+#include <set>
+#include <string>
+#include <string_view>
+
#include <errno.h>
#include "include/types.h"
#include "msg/Message.h"
#include "mds/MDSMap.h"
-#include <set>
-#include <map>
-#include <string>
-
#include "common/config.h"
#include "include/CompatSet.h"
/**
* 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) {
/**
* 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<mds_gid_t, MDSMap::mds_info_t> result;
for (const auto &i : standby_daemons) {
* 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);
bool filesystem_exists(fs_cluster_id_t fscid) const {return filesystems.count(fscid) > 0;}
std::shared_ptr<const Filesystem> get_filesystem(fs_cluster_id_t fscid) const {return std::const_pointer_cast<const Filesystem>(filesystems.at(fscid));}
std::shared_ptr<const Filesystem> get_filesystem(void) const {return std::const_pointer_cast<const Filesystem>(filesystems.begin()->second);}
- std::shared_ptr<const Filesystem> get_filesystem(const std::string &name) const
+ std::shared_ptr<const Filesystem> get_filesystem(std::string_view name) const
{
for (const auto &i : filesystems) {
if (i.second->mds_map.fs_name == name) {
}
int parse_filesystem(
- std::string const &ns_str,
+ std::string_view ns_str,
std::shared_ptr<const Filesystem> *result
) const;
int parse_role(
- const std::string &role_str,
+ std::string_view role_str,
mds_role_t *role,
std::ostream &ss) const;
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<pair<health_status_t,std::string> >& summary,
#ifndef CEPH_FSMAPCOMPACT_H
#define CEPH_FSMAPCOMPACT_H
-#include "mds/mdstypes.h"
#include <map>
#include <string>
+#include <string_view>
+
+#include "mds/mdstypes.h"
class FSMapUser {
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;
*
*/
+#include <string_view>
#include "MDSRank.h"
#include "MDCache.h"
};
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;
#ifndef CEPH_MDS_LOCKER_H
#define CEPH_MDS_LOCKER_H
+#include <string_view>
+
#include "include/types.h"
#include <map>
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);
}
}
+const std::map<std::string, LogEvent::EventType> 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<std::string, EventType> 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));
}
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; }
* tools can examine metablobs while traversing lists of LogEvent.
*/
virtual EMetaBlob *get_metablob() { return NULL; }
+
+private:
+ static const std::map<std::string, LogEvent::EventType> types;
};
inline ostream& operator<<(ostream& out, const LogEvent &le) {
#include <iostream>
#include <sstream>
#include <string>
+#include <string_view>
#include <map>
#include "MDCache.h"
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;
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();
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;
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;
}
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,
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());
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;
}
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,
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());
}
}
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);
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);
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;
}
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);
}
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,
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);
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;
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;
}
}
};
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);
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;
}
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);
#ifndef CEPH_MDCACHE_H
#define CEPH_MDCACHE_H
+#include <string_view>
+
#include "include/types.h"
#include "include/filepath.h"
#include "include/elist.h"
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;
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);
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);
*
*/
+#include <string_view>
#include <errno.h>
#include <fcntl.h>
// 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<uint64_t> *caller_gid_list) const
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)
* 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)) {
* 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,
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") {
return true;
}
- MDSCapParser<std::string::const_iterator> g;
- std::string::const_iterator iter = str.begin();
- std::string::const_iterator end = str.end();
+ auto iter = str.begin();
+ auto end = str.end();
+ MDSCapParser<decltype(iter)> g;
bool r = qi::phrase_parse(iter, end, g, ascii::space, *this);
cct = c; // set after parser self-assignment
#ifndef MDS_AUTH_CAPS_H
#define MDS_AUTH_CAPS_H
-#include <vector>
-#include <string>
#include <sstream>
+#include <string>
+#include <string_view>
+#include <vector>
+
#include "include/types.h"
#include "common/debug.h"
}
// 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<uint64_t> *caller_gid_list) const;
*
* @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 {
: 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<uint64_t> *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);
};
#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),
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<Session *>(m->get_connection()->get_priv());
assert(session != NULL);
#ifndef CEPH_MDS_H
#define CEPH_MDS_H
+#include <string_view>
+
#include "common/LogClient.h"
#include "common/Mutex.h"
#include "common/Timer.h"
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;
// 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,
#ifndef CEPH_MDSMAP_H
#define CEPH_MDSMAP_H
+#include <algorithm>
+#include <map>
+#include <set>
+#include <string>
+#include <string_view>
+
#include <errno.h>
#include "include/types.h"
#include "msg/Message.h"
#include "include/health.h"
-#include <set>
-#include <map>
-#include <string>
-#include <algorithm>
-
#include "common/config.h"
#include "include/CompatSet.h"
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);
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<mds_gid_t,mds_info_t>::const_iterator p = mds_info.begin();
p != mds_info.end();
++p) {
*
*/
+#include <string_view>
+
#include "common/debug.h"
#include "common/errno.h"
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();
f->close_section(); //sessions
}
-void MDSRank::command_scrub_path(Formatter *f, const string& path, vector<string>& scrubop_vec)
+void MDSRank::command_scrub_path(Formatter *f, std::string_view path, vector<string>& scrubop_vec)
{
bool force = false;
bool recursive = false;
}
void MDSRank::command_tag_path(Formatter *f,
- const string& path, const std::string &tag)
+ std::string_view path, std::string_view tag)
{
C_SaferCond scond;
{
scond.wait();
}
-void MDSRank::command_flush_path(Formatter *f, const string& path)
+void MDSRank::command_flush_path(Formatter *f, std::string_view path)
{
C_SaferCond scond;
{
void MDSRank::command_export_dir(Formatter *f,
- const std::string &path,
+ std::string_view path,
mds_rank_t target)
{
int r = _command_export_dir(path, target);
}
int MDSRank::_command_export_dir(
- const std::string &path,
+ std::string_view path,
mds_rank_t target)
{
Mutex::Locker l(mds_lock);
- filepath fp(path.c_str());
+ filepath fp(path);
if (target == whoami || !mdsmap->is_up(target) || !mdsmap->is_in(target)) {
derr << "bad MDS target " << target << dendl;
#ifndef MDS_RANK_H_
#define MDS_RANK_H_
+#include <string_view>
+
#include "common/DecayCounter.h"
#include "common/LogClient.h"
#include "common/Timer.h"
protected:
void dump_clientreplay_status(Formatter *f) const;
- void command_scrub_path(Formatter *f, const string& path, vector<string>& 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<string>& 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);
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,
return 0;
}
-int Mantle::balance(const std::string &script,
+int Mantle::balance(std::string_view script,
mds_rank_t whoami,
const std::vector<std::map<std::string, double>> &metrics,
std::map<mds_rank_t, double> &my_targets)
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;
#ifndef CEPH_MANTLE_H
#define CEPH_MANTLE_H
+#include <string_view>
+
#include <lua.hpp>
#include <vector>
#include <map>
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 <std::map<std::string, double>> &metrics,
std::map<mds_rank_t,double> &my_targets);
dout(7) << "encode_export_dir exporting " << *dn << dendl;
// dn name
- encode(dn->name, exportbl);
+ encode(dn->get_name(), exportbl);
encode(dn->last, exportbl);
// state
#ifndef SCRUB_HEADER_H_
#define SCRUB_HEADER_H_
+#include <string_view>
+
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)
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; }
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);
}
}
#include <list>
#include <iostream>
+#include <string_view>
#include "common/config.h"
* 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()) {
* 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());
}
// 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);
}
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;
}
// 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
MMDSSlaveRequest::OP_RMDIRPREP);
req->srcdnpath = 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();
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;
respond_to_request(mdr, -EINVAL);
return;
}
- const string &destname = destpath.last_dentry();
+ std::string_view destname = destpath.last_dentry();
vector<CDentry*>& srctrace = mdr->dn[1];
vector<CDentry*>& desttrace = mdr->dn[0];
}
// 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;
req->srcdnpath = 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);
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 {
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()) {
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;
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;
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;
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] == '_') {
#ifndef CEPH_MDS_SERVER_H
#define CEPH_MDS_SERVER_H
+#include <string_view>
+
#include "MDSRank.h"
#include "Mutation.h"
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<CDentry*> &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);
* 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);
#ifndef CEPH_SNAPCLIENT_H
#define CEPH_SNAPCLIENT_H
+#include <string_view>
+
#include "MDSTableClient.h"
#include "snap.h"
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;
_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;
#include "MDCache.h"
#include "MDSRank.h"
+#include <string_view>
+
#include "messages/MClientSnap.h"
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()) {
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;
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;
}
#ifndef CEPH_MDS_SNAPREALM_H
#define CEPH_MDS_SNAPREALM_H
+#include <string_view>
+
#include "mdstypes.h"
#include "snap.h"
#include "include/xlist.h"
inodes_with_caps(0)
{ }
- bool exists(const string &name) const {
+ bool exists(std::string_view name) const {
for (map<snapid_t,SnapInfo>::const_iterator p = srnode.snaps.begin();
p != srnode.snaps.end();
++p) {
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<snapid_t>& get_snaps() const;
const SnapContext& get_snap_context() const;
#ifndef CEPH_MDS_EMETABLOB_H
#define CEPH_MDS_EMETABLOB_H
+#include <string_view>
+
#include <stdlib.h>
#include "../CInode.h"
static const int STATE_DIRTYPOOL = (1<<2);
static const int STATE_NEED_SNAPFLUSH = (1<<3);
typedef compact_map<snapid_t, old_inode_t> 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
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<string,bufferptr> &xa, const string& sym,
snapid_t os, const bufferlist &sbl, __u8 st,
/* 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),
* 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) {}
#ifndef CEPH_INODE_BACKTRACE_H
#define CEPH_INODE_BACKTRACE_H
+#include <string_view>
+
#include "mdstypes.h"
namespace ceph {
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);
for (list<ceph::shared_ptr<fullbit> >::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<nullbit>::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<remotebit>::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);
}
}
list<ceph::shared_ptr<fullbit> > const &fb_list = dl.get_dfull();
for (list<ceph::shared_ptr<fullbit> >::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));
}
list<nullbit> const &nb_list = dl.get_dnull();
for (list<nullbit>::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<remotebit> const &rb_list = dl.get_dremote();
for (list<remotebit>::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));
}
}
#include <ostream>
#include <set>
#include <map>
+#include <string_view>
#include "common/config.h"
#include "common/Clock.h"
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)
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);
}
};
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;
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;
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);
}
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;
*
*/
+#include <string_view>
+
#include "snap.h"
#include "common/Formatter.h"
<< "' " << sn.stamp << ")";
}
-const string& SnapInfo::get_long_name()
+std::string_view SnapInfo::get_long_name()
{
if (long_name.length() == 0) {
char nm[80];
#ifndef CEPH_MDS_SNAP_H
#define CEPH_MDS_SNAP_H
+#include <string_view>
+
#include "mdstypes.h"
#include "common/snap_types.h"
void dump(Formatter *f) const;
static void generate_test_instances(list<SnapInfo*>& ls);
- const string& get_long_name();
+ std::string_view get_long_name();
};
WRITE_CLASS_ENCODER(SnapInfo)
#ifndef CEPH_MCACHEEXPIRE_H
#define CEPH_MCACHEEXPIRE_H
+#include <string_view>
+
#include "mds/mdstypes.h"
class MCacheExpire : public Message {
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<string,snapid_t>(dn,last)] = nonce;
}
#ifndef CEPH_MCLIENTLEASE_H
#define CEPH_MCLIENTLEASE_H
+#include <string_view>
+
#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; }
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;
*
*/
+#include <string_view>
+
#include "msg/Message.h"
#include "include/filepath.h"
#include "mds/mdstypes.h"
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) {
#ifndef CEPH_MCOMMANDREPLY_H
#define CEPH_MCOMMANDREPLY_H
+#include <string_view>
+
#include "msg/Message.h"
#include "MCommand.h"
: 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:
#ifndef CEPH_MDENTRYLINK_H
#define CEPH_MDENTRYLINK_H
+#include <string_view>
+
class MDentryLink : public Message {
dirfrag_t subtree;
dirfrag_t dirfrag;
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),
#ifndef CEPH_MDENTRYUNLINK_H
#define CEPH_MDENTRYUNLINK_H
+#include <string_view>
+
class MDentryUnlink : public Message {
dirfrag_t dirfrag;
string dn;
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) {}
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; }
}
// 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;
}
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;
}
#ifndef CEPH_MMDSBEACON_H
#define CEPH_MMDSBEACON_H
+#include <string_view>
+
#include "messages/PaxosServiceMessage.h"
#include "include/types.h"
}
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)
#ifndef CEPH_MMDSCACHEREJOIN_H
#define CEPH_MMDSCACHEREJOIN_H
+#include <string_view>
+
#include "msg/Message.h"
#include "include/types.h"
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);
}
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)
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;
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)
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;