const int LFNIndex::FILENAME_PREFIX_LEN = FILENAME_SHORT_LEN - FILENAME_HASH_LEN -
FILENAME_COOKIE.size() -
FILENAME_EXTRA;
-void LFNIndex::maybe_inject_failure() {
+void LFNIndex::maybe_inject_failure()
+{
if (error_injection_enabled) {
if (current_failure > last_failure &&
(((double)(rand() % 10000))/((double)(10000))
/* Public methods */
-void LFNIndex::set_ref(std::tr1::shared_ptr<CollectionIndex> ref) {
+void LFNIndex::set_ref(std::tr1::shared_ptr<CollectionIndex> ref)
+{
self_ref = ref;
}
-int LFNIndex::init() {
+int LFNIndex::init()
+{
return _init();
}
-int LFNIndex::created(const hobject_t &hoid, const char *path) {
+int LFNIndex::created(const hobject_t &hoid, const char *path)
+{
vector<string> path_comp;
string short_name;
int r;
return _created(path_comp, hoid, short_name);
}
-int LFNIndex::unlink(const hobject_t &hoid) {
+int LFNIndex::unlink(const hobject_t &hoid)
+{
WRAP_RETRY(
vector<string> path;
string short_name;
);
}
-int LFNIndex::collection_list(vector<hobject_t> *ls) {
+int LFNIndex::collection_list(vector<hobject_t> *ls)
+{
return _collection_list(ls);
}
int max_count,
snapid_t seq,
vector<hobject_t> *ls,
- hobject_t *next) {
+ hobject_t *next)
+{
return _collection_list_partial(start, min_count, max_count, seq, ls, next);
}
/* Derived class utility methods */
-int LFNIndex::fsync_dir(const vector<string> &path) {
+int LFNIndex::fsync_dir(const vector<string> &path)
+{
maybe_inject_failure();
int fd = ::open(get_full_path_subdir(path).c_str(), O_RDONLY);
if (fd < 0)
return 0;
}
-int LFNIndex::create_path(const vector<string> &to_create) {
+int LFNIndex::create_path(const vector<string> &to_create)
+{
maybe_inject_failure();
int r = ::mkdir(get_full_path_subdir(to_create).c_str(), 0777);
maybe_inject_failure();
return 0;
}
-int LFNIndex::remove_path(const vector<string> &to_remove) {
+int LFNIndex::remove_path(const vector<string> &to_remove)
+{
maybe_inject_failure();
int r = ::rmdir(get_full_path_subdir(to_remove).c_str());
maybe_inject_failure();
return 0;
}
-int LFNIndex::path_exists(const vector<string> &to_check, int *exists) {
+int LFNIndex::path_exists(const vector<string> &to_check, int *exists)
+{
string full_path = get_full_path_subdir(to_check);
struct stat buf;
if (::stat(full_path.c_str(), &buf)) {
return chain_removexattr(full_path.c_str(), mangled_attr_name.c_str());
}
-string LFNIndex::lfn_generate_object_name_keyless(const hobject_t &hoid) {
+string LFNIndex::lfn_generate_object_name_keyless(const hobject_t &hoid)
+{
char s[FILENAME_MAX_LEN];
char *end = s + sizeof(s);
char *t = s;
static void append_escaped(string::const_iterator begin,
string::const_iterator end,
- string *out) {
+ string *out)
+{
for (string::const_iterator i = begin; i != end; ++i) {
if (*i == '\\') {
out->append("\\\\");
}
}
-string LFNIndex::lfn_generate_object_name(const hobject_t &hoid) {
+string LFNIndex::lfn_generate_object_name(const hobject_t &hoid)
+{
if (index_version == HASH_INDEX_TAG)
return lfn_generate_object_name_keyless(hoid);
if (index_version == HASH_INDEX_TAG_2)
return full_name;
}
-string LFNIndex::lfn_generate_object_name_poolless(const hobject_t &hoid) {
+string LFNIndex::lfn_generate_object_name_poolless(const hobject_t &hoid)
+{
if (index_version == HASH_INDEX_TAG)
return lfn_generate_object_name_keyless(hoid);
int LFNIndex::lfn_get_name(const vector<string> &path,
const hobject_t &hoid,
string *mangled_name, string *out_path,
- int *exists) {
+ int *exists)
+{
string subdir_path = get_full_path_subdir(path);
string full_name = lfn_generate_object_name(hoid);
int r;
int LFNIndex::lfn_created(const vector<string> &path,
const hobject_t &hoid,
- const string &mangled_name) {
+ const string &mangled_name)
+{
if (!lfn_is_hashed_filename(mangled_name))
return 0;
string full_path = get_full_path(path, mangled_name);
int LFNIndex::lfn_unlink(const vector<string> &path,
const hobject_t &hoid,
- const string &mangled_name) {
+ const string &mangled_name)
+{
if (!lfn_is_hashed_filename(mangled_name)) {
string full_path = get_full_path(path, mangled_name);
maybe_inject_failure();
int LFNIndex::lfn_translate(const vector<string> &path,
const string &short_name,
- hobject_t *out) {
+ hobject_t *out)
+{
if (!lfn_is_hashed_filename(short_name)) {
return lfn_parse_object_name(short_name, out);
}
return lfn_parse_object_name(long_name, out);
}
-bool LFNIndex::lfn_is_object(const string &short_name) {
+bool LFNIndex::lfn_is_object(const string &short_name)
+{
return lfn_is_hashed_filename(short_name) || !lfn_is_subdir(short_name, 0);
}
-bool LFNIndex::lfn_is_subdir(const string &name, string *demangled) {
+bool LFNIndex::lfn_is_subdir(const string &name, string *demangled)
+{
if (name.substr(0, SUBDIR_PREFIX.size()) == SUBDIR_PREFIX) {
if (demangled)
*demangled = demangle_path_component(name);
return 0;
}
-bool LFNIndex::lfn_parse_object_name_keyless(const string &long_name, hobject_t *out) {
+bool LFNIndex::lfn_parse_object_name_keyless(const string &long_name, hobject_t *out)
+{
bool r = parse_object(long_name.c_str(), *out);
int64_t pool = -1;
pg_t pg;
}
-bool LFNIndex::lfn_parse_object_name(const string &long_name, hobject_t *out) {
+bool LFNIndex::lfn_parse_object_name(const string &long_name, hobject_t *out)
+{
string name;
string key;
string ns;
return true;
}
-bool LFNIndex::lfn_is_hashed_filename(const string &name) {
+bool LFNIndex::lfn_is_hashed_filename(const string &name)
+{
if (name.size() < (unsigned)FILENAME_SHORT_LEN) {
return 0;
}
}
}
-bool LFNIndex::lfn_must_hash(const string &long_name) {
+bool LFNIndex::lfn_must_hash(const string &long_name)
+{
return (int)long_name.size() >= FILENAME_SHORT_LEN;
}
}
}
-string LFNIndex::lfn_get_short_name(const hobject_t &hoid, int i) {
+string LFNIndex::lfn_get_short_name(const hobject_t &hoid, int i)
+{
string long_name = lfn_generate_object_name(hoid);
assert(lfn_must_hash(long_name));
char buf[FILENAME_SHORT_LEN + 4];
return string(buf);
}
-const string &LFNIndex::get_base_path() {
+const string &LFNIndex::get_base_path()
+{
return base_path;
}
-string LFNIndex::get_full_path_subdir(const vector<string> &rel) {
+string LFNIndex::get_full_path_subdir(const vector<string> &rel)
+{
string retval = get_base_path();
for (vector<string>::const_iterator i = rel.begin();
i != rel.end();
return retval;
}
-string LFNIndex::get_full_path(const vector<string> &rel, const string &name) {
+string LFNIndex::get_full_path(const vector<string> &rel, const string &name)
+{
return get_full_path_subdir(rel) + "/" + name;
}
-string LFNIndex::mangle_path_component(const string &component) {
+string LFNIndex::mangle_path_component(const string &component)
+{
return SUBDIR_PREFIX + component;
}
-string LFNIndex::demangle_path_component(const string &component) {
+string LFNIndex::demangle_path_component(const string &component)
+{
return component.substr(SUBDIR_PREFIX.size(), component.size() - SUBDIR_PREFIX.size());
}
int LFNIndex::decompose_full_path(const char *in, vector<string> *out,
- hobject_t *hoid, string *shortname) {
+ hobject_t *hoid, string *shortname)
+{
const char *beginning = in + get_base_path().size();
const char *end = beginning;
while (1) {
return 0;
}
-string LFNIndex::mangle_attr_name(const string &attr) {
+string LFNIndex::mangle_attr_name(const string &attr)
+{
return PHASH_ATTR_PREFIX + attr;
}