Search is not available for this dataset
repo
stringlengths
2
152
file
stringlengths
15
239
code
stringlengths
0
58.4M
file_length
int64
0
58.4M
avg_line_length
float64
0
1.81M
max_line_length
int64
0
12.7M
extension_type
stringclasses
364 values
null
ceph-main/src/mds/cephfs_features.cc
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include <array> #include "cephfs_features.h" #include "mdstypes.h" #include <fmt/format.h> static const std::array feature_names { "reserved", "reserved", "reserved", "reserved", "reserved", "jewel", "kraken", "luminous", "mimic", "reply_encoding", "reclaim_client", "lazy_caps_wanted", "multi_reconnect", "deleg_ino", "metric_collect", "alternate_name", "notify_session_state", "op_getvxattr", "32bits_retry_fwd", "new_snaprealm_info", }; static_assert(feature_names.size() == CEPHFS_FEATURE_MAX + 1); std::string_view cephfs_feature_name(size_t id) { if (id > feature_names.size()) return "unknown"; return feature_names[id]; } int cephfs_feature_from_name(std::string_view name) { if (name == "reserved") { return -1; } for (size_t i = 0; i < feature_names.size(); ++i) { if (name == feature_names[i]) return i; } return -1; } std::string cephfs_stringify_features(const feature_bitset_t& features) { CachedStackStringStream css; bool first = true; *css << "{"; for (size_t i = 0; i < feature_names.size(); ++i) { if (!features.test(i)) continue; if (!first) *css << ","; *css << i << "=" << cephfs_feature_name(i); first = false; } *css << "}"; return css->str(); } void cephfs_dump_features(ceph::Formatter *f, const feature_bitset_t& features) { for (size_t i = 0; i < feature_names.size(); ++i) { if (!features.test(i)) continue; f->dump_string(fmt::format("feature_{}", i), cephfs_feature_name(i)); } }
1,654
19.6875
79
cc
null
ceph-main/src/mds/cephfs_features.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPHFS_FEATURES_H #define CEPHFS_FEATURES_H #include "include/cephfs/metrics/Types.h" class feature_bitset_t; namespace ceph { class Formatter; } // When adding a new release, please update the "current" release below, add a // feature bit for that release, add that feature bit to CEPHFS_FEATURES_ALL, // and update Server::update_required_client_features(). This feature bit // is used to indicate that operator only wants clients from that release or // later to mount CephFS. #define CEPHFS_CURRENT_RELEASE CEPH_RELEASE_REEF // The first 5 bits are reserved for old ceph releases. #define CEPHFS_FEATURE_JEWEL 5 #define CEPHFS_FEATURE_KRAKEN 6 #define CEPHFS_FEATURE_LUMINOUS 7 #define CEPHFS_FEATURE_MIMIC 8 #define CEPHFS_FEATURE_REPLY_ENCODING 9 #define CEPHFS_FEATURE_RECLAIM_CLIENT 10 #define CEPHFS_FEATURE_LAZY_CAP_WANTED 11 #define CEPHFS_FEATURE_MULTI_RECONNECT 12 #define CEPHFS_FEATURE_NAUTILUS 12 #define CEPHFS_FEATURE_DELEG_INO 13 #define CEPHFS_FEATURE_OCTOPUS 13 #define CEPHFS_FEATURE_METRIC_COLLECT 14 #define CEPHFS_FEATURE_ALTERNATE_NAME 15 #define CEPHFS_FEATURE_NOTIFY_SESSION_STATE 16 #define CEPHFS_FEATURE_OP_GETVXATTR 17 #define CEPHFS_FEATURE_32BITS_RETRY_FWD 18 #define CEPHFS_FEATURE_NEW_SNAPREALM_INFO 19 #define CEPHFS_FEATURE_MAX 19 #define CEPHFS_FEATURES_ALL { \ 0, 1, 2, 3, 4, \ CEPHFS_FEATURE_JEWEL, \ CEPHFS_FEATURE_KRAKEN, \ CEPHFS_FEATURE_LUMINOUS, \ CEPHFS_FEATURE_MIMIC, \ CEPHFS_FEATURE_REPLY_ENCODING, \ CEPHFS_FEATURE_RECLAIM_CLIENT, \ CEPHFS_FEATURE_LAZY_CAP_WANTED, \ CEPHFS_FEATURE_MULTI_RECONNECT, \ CEPHFS_FEATURE_NAUTILUS, \ CEPHFS_FEATURE_DELEG_INO, \ CEPHFS_FEATURE_OCTOPUS, \ CEPHFS_FEATURE_METRIC_COLLECT, \ CEPHFS_FEATURE_ALTERNATE_NAME, \ CEPHFS_FEATURE_NOTIFY_SESSION_STATE, \ CEPHFS_FEATURE_OP_GETVXATTR, \ CEPHFS_FEATURE_32BITS_RETRY_FWD, \ CEPHFS_FEATURE_NEW_SNAPREALM_INFO \ } #define CEPHFS_METRIC_FEATURES_ALL { \ CLIENT_METRIC_TYPE_CAP_INFO, \ CLIENT_METRIC_TYPE_READ_LATENCY, \ CLIENT_METRIC_TYPE_WRITE_LATENCY, \ CLIENT_METRIC_TYPE_METADATA_LATENCY, \ CLIENT_METRIC_TYPE_DENTRY_LEASE, \ CLIENT_METRIC_TYPE_OPENED_FILES, \ CLIENT_METRIC_TYPE_PINNED_ICAPS, \ CLIENT_METRIC_TYPE_OPENED_INODES, \ CLIENT_METRIC_TYPE_READ_IO_SIZES, \ CLIENT_METRIC_TYPE_WRITE_IO_SIZES, \ CLIENT_METRIC_TYPE_AVG_READ_LATENCY, \ CLIENT_METRIC_TYPE_STDEV_READ_LATENCY, \ CLIENT_METRIC_TYPE_AVG_WRITE_LATENCY, \ CLIENT_METRIC_TYPE_STDEV_WRITE_LATENCY, \ CLIENT_METRIC_TYPE_AVG_METADATA_LATENCY, \ CLIENT_METRIC_TYPE_STDEV_METADATA_LATENCY, \ } #define CEPHFS_FEATURES_MDS_SUPPORTED CEPHFS_FEATURES_ALL #define CEPHFS_FEATURES_CLIENT_SUPPORTED CEPHFS_FEATURES_ALL extern std::string_view cephfs_feature_name(size_t id); extern int cephfs_feature_from_name(std::string_view name); std::string cephfs_stringify_features(const feature_bitset_t& features); void cephfs_dump_features(ceph::Formatter *f, const feature_bitset_t& features); #endif
3,629
34.940594
80
h
null
ceph-main/src/mds/flock.cc
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include <errno.h> #include "common/debug.h" #include "mdstypes.h" #include "mds/flock.h" #define dout_subsys ceph_subsys_mds using std::list; using std::pair; using std::multimap; static multimap<ceph_filelock, ceph_lock_state_t*> global_waiting_locks; static void remove_global_waiting(ceph_filelock &fl, ceph_lock_state_t *lock_state) { for (auto p = global_waiting_locks.find(fl); p != global_waiting_locks.end(); ) { if (p->first != fl) break; if (p->second == lock_state) { global_waiting_locks.erase(p); break; } ++p; } } ceph_lock_state_t::~ceph_lock_state_t() { if (type == CEPH_LOCK_FCNTL) { for (auto p = waiting_locks.begin(); p != waiting_locks.end(); ++p) { remove_global_waiting(p->second, this); } } } bool ceph_lock_state_t::is_waiting(const ceph_filelock &fl) const { auto p = waiting_locks.find(fl.start); while (p != waiting_locks.end()) { if (p->second.start > fl.start) return false; if (p->second.length == fl.length && ceph_filelock_owner_equal(p->second, fl)) return true; ++p; } return false; } void ceph_lock_state_t::remove_waiting(const ceph_filelock& fl) { for (auto p = waiting_locks.find(fl.start); p != waiting_locks.end(); ) { if (p->second.start > fl.start) break; if (p->second.length == fl.length && ceph_filelock_owner_equal(p->second, fl)) { if (type == CEPH_LOCK_FCNTL) { remove_global_waiting(p->second, this); } waiting_locks.erase(p); --client_waiting_lock_counts[(client_t)fl.client]; if (!client_waiting_lock_counts[(client_t)fl.client]) { client_waiting_lock_counts.erase((client_t)fl.client); } break; } ++p; } } bool ceph_lock_state_t::is_deadlock(const ceph_filelock& fl, list<multimap<uint64_t, ceph_filelock>::iterator>& overlapping_locks, const ceph_filelock *first_fl, unsigned depth) const { ldout(cct,15) << "is_deadlock " << fl << dendl; // only for posix lock if (type != CEPH_LOCK_FCNTL) return false; // find conflict locks' owners std::set<ceph_filelock> lock_owners; for (auto p = overlapping_locks.begin(); p != overlapping_locks.end(); ++p) { if (fl.type == CEPH_LOCK_SHARED && (*p)->second.type == CEPH_LOCK_SHARED) continue; // circle detected if (first_fl && ceph_filelock_owner_equal(*first_fl, (*p)->second)) { ldout(cct,15) << " detect deadlock" << dendl; return true; } ceph_filelock tmp = (*p)->second; tmp.start = 0; tmp.length = 0; tmp.type = 0; lock_owners.insert(tmp); } if (depth >= MAX_DEADLK_DEPTH) return false; first_fl = first_fl ? first_fl : &fl; for (auto p = lock_owners.begin(); p != lock_owners.end(); ++p) { ldout(cct,15) << " conflict lock owner " << *p << dendl; // if conflict lock' owner is waiting for other lock? for (auto q = global_waiting_locks.lower_bound(*p); q != global_waiting_locks.end(); ++q) { if (!ceph_filelock_owner_equal(q->first, *p)) break; list<multimap<uint64_t, ceph_filelock>::iterator> _overlapping_locks, _self_overlapping_locks; ceph_lock_state_t& state = *(q->second); if (state.get_overlapping_locks(q->first, _overlapping_locks)) { state.split_by_owner(q->first, _overlapping_locks, _self_overlapping_locks); } if (!_overlapping_locks.empty()) { if (is_deadlock(q->first, _overlapping_locks, first_fl, depth + 1)) return true; } } } return false; } void ceph_lock_state_t::add_waiting(const ceph_filelock& fl) { waiting_locks.insert(pair<uint64_t, ceph_filelock>(fl.start, fl)); ++client_waiting_lock_counts[(client_t)fl.client]; if (type == CEPH_LOCK_FCNTL) { global_waiting_locks.insert(pair<ceph_filelock,ceph_lock_state_t*>(fl, this)); } } bool ceph_lock_state_t::add_lock(ceph_filelock& new_lock, bool wait_on_fail, bool replay, bool *deadlock) { ldout(cct,15) << "add_lock " << new_lock << dendl; bool ret = false; list<multimap<uint64_t, ceph_filelock>::iterator> overlapping_locks, self_overlapping_locks, neighbor_locks; // first, get any overlapping locks and split them into owned-by-us and not if (get_overlapping_locks(new_lock, overlapping_locks, &neighbor_locks)) { ldout(cct,15) << "got overlapping lock, splitting by owner" << dendl; split_by_owner(new_lock, overlapping_locks, self_overlapping_locks); } if (!overlapping_locks.empty()) { //overlapping locks owned by others :( if (CEPH_LOCK_EXCL == new_lock.type) { //can't set, we want an exclusive ldout(cct,15) << "overlapping lock, and this lock is exclusive, can't set" << dendl; if (wait_on_fail && !replay) { if (is_deadlock(new_lock, overlapping_locks)) *deadlock = true; else add_waiting(new_lock); } } else { //shared lock, check for any exclusive locks blocking us if (contains_exclusive_lock(overlapping_locks)) { //blocked :( ldout(cct,15) << " blocked by exclusive lock in overlapping_locks" << dendl; if (wait_on_fail && !replay) { if (is_deadlock(new_lock, overlapping_locks)) *deadlock = true; else add_waiting(new_lock); } } else { //yay, we can insert a shared lock ldout(cct,15) << "inserting shared lock" << dendl; remove_waiting(new_lock); adjust_locks(self_overlapping_locks, new_lock, neighbor_locks); held_locks.insert(pair<uint64_t, ceph_filelock>(new_lock.start, new_lock)); ret = true; } } } else { //no overlapping locks except our own remove_waiting(new_lock); adjust_locks(self_overlapping_locks, new_lock, neighbor_locks); ldout(cct,15) << "no conflicts, inserting " << new_lock << dendl; held_locks.insert(pair<uint64_t, ceph_filelock> (new_lock.start, new_lock)); ret = true; } if (ret) { ++client_held_lock_counts[(client_t)new_lock.client]; } return ret; } void ceph_lock_state_t::look_for_lock(ceph_filelock& testing_lock) { list<multimap<uint64_t, ceph_filelock>::iterator> overlapping_locks, self_overlapping_locks; if (get_overlapping_locks(testing_lock, overlapping_locks)) { split_by_owner(testing_lock, overlapping_locks, self_overlapping_locks); } if (!overlapping_locks.empty()) { //somebody else owns overlapping lock if (CEPH_LOCK_EXCL == testing_lock.type) { //any lock blocks it testing_lock = (*overlapping_locks.begin())->second; } else { ceph_filelock *blocking_lock; if ((blocking_lock = contains_exclusive_lock(overlapping_locks))) { testing_lock = *blocking_lock; } else { //nothing blocking! testing_lock.type = CEPH_LOCK_UNLOCK; } } return; } //if we get here, only our own locks block testing_lock.type = CEPH_LOCK_UNLOCK; } void ceph_lock_state_t::remove_lock(ceph_filelock removal_lock, list<ceph_filelock>& activated_locks) { list<multimap<uint64_t, ceph_filelock>::iterator> overlapping_locks, self_overlapping_locks; if (get_overlapping_locks(removal_lock, overlapping_locks)) { ldout(cct,15) << "splitting by owner" << dendl; split_by_owner(removal_lock, overlapping_locks, self_overlapping_locks); } else ldout(cct,15) << "attempt to remove lock at " << removal_lock.start << " but no locks there!" << dendl; bool remove_to_end = (0 == removal_lock.length); uint64_t removal_start = removal_lock.start; uint64_t removal_end = removal_start + removal_lock.length - 1; __s64 old_lock_client = 0; ceph_filelock *old_lock; ldout(cct,15) << "examining " << self_overlapping_locks.size() << " self-overlapping locks for removal" << dendl; for (list<multimap<uint64_t, ceph_filelock>::iterator>::iterator iter = self_overlapping_locks.begin(); iter != self_overlapping_locks.end(); ++iter) { ldout(cct,15) << "self overlapping lock " << (*iter)->second << dendl; old_lock = &(*iter)->second; bool old_lock_to_end = (0 == old_lock->length); uint64_t old_lock_end = old_lock->start + old_lock->length - 1; old_lock_client = old_lock->client; if (remove_to_end) { if (old_lock->start < removal_start) { old_lock->length = removal_start - old_lock->start; } else { ldout(cct,15) << "erasing " << (*iter)->second << dendl; held_locks.erase(*iter); --client_held_lock_counts[old_lock_client]; } } else if (old_lock_to_end) { ceph_filelock append_lock = *old_lock; append_lock.start = removal_end+1; held_locks.insert(pair<uint64_t, ceph_filelock> (append_lock.start, append_lock)); ++client_held_lock_counts[(client_t)old_lock->client]; if (old_lock->start >= removal_start) { ldout(cct,15) << "erasing " << (*iter)->second << dendl; held_locks.erase(*iter); --client_held_lock_counts[old_lock_client]; } else old_lock->length = removal_start - old_lock->start; } else { if (old_lock_end > removal_end) { ceph_filelock append_lock = *old_lock; append_lock.start = removal_end + 1; append_lock.length = old_lock_end - append_lock.start + 1; held_locks.insert(pair<uint64_t, ceph_filelock> (append_lock.start, append_lock)); ++client_held_lock_counts[(client_t)old_lock->client]; } if (old_lock->start < removal_start) { old_lock->length = removal_start - old_lock->start; } else { ldout(cct,15) << "erasing " << (*iter)->second << dendl; held_locks.erase(*iter); --client_held_lock_counts[old_lock_client]; } } if (!client_held_lock_counts[old_lock_client]) { client_held_lock_counts.erase(old_lock_client); } } } bool ceph_lock_state_t::remove_all_from (client_t client) { bool cleared_any = false; if (client_held_lock_counts.count(client)) { multimap<uint64_t, ceph_filelock>::iterator iter = held_locks.begin(); while (iter != held_locks.end()) { if ((client_t)iter->second.client == client) { held_locks.erase(iter++); } else ++iter; } client_held_lock_counts.erase(client); cleared_any = true; } if (client_waiting_lock_counts.count(client)) { multimap<uint64_t, ceph_filelock>::iterator iter = waiting_locks.begin(); while (iter != waiting_locks.end()) { if ((client_t)iter->second.client != client) { ++iter; continue; } if (type == CEPH_LOCK_FCNTL) { remove_global_waiting(iter->second, this); } waiting_locks.erase(iter++); } client_waiting_lock_counts.erase(client); } return cleared_any; } void ceph_lock_state_t::adjust_locks(list<multimap<uint64_t, ceph_filelock>::iterator> old_locks, ceph_filelock& new_lock, list<multimap<uint64_t, ceph_filelock>::iterator> neighbor_locks) { ldout(cct,15) << "adjust_locks" << dendl; bool new_lock_to_end = (0 == new_lock.length); __s64 old_lock_client = 0; ceph_filelock *old_lock; for (list<multimap<uint64_t, ceph_filelock>::iterator>::iterator iter = old_locks.begin(); iter != old_locks.end(); ++iter) { old_lock = &(*iter)->second; ldout(cct,15) << "adjusting lock: " << *old_lock << dendl; bool old_lock_to_end = (0 == old_lock->length); uint64_t old_lock_start = old_lock->start; uint64_t old_lock_end = old_lock->start + old_lock->length - 1; uint64_t new_lock_start = new_lock.start; uint64_t new_lock_end = new_lock.start + new_lock.length - 1; old_lock_client = old_lock->client; if (new_lock_to_end || old_lock_to_end) { //special code path to deal with a length set at 0 ldout(cct,15) << "one lock extends forever" << dendl; if (old_lock->type == new_lock.type) { //just unify them in new lock, remove old lock ldout(cct,15) << "same lock type, unifying" << dendl; new_lock.start = (new_lock_start < old_lock_start) ? new_lock_start : old_lock_start; new_lock.length = 0; held_locks.erase(*iter); --client_held_lock_counts[old_lock_client]; } else { //not same type, have to keep any remains of old lock around ldout(cct,15) << "shrinking old lock" << dendl; if (new_lock_to_end) { if (old_lock_start < new_lock_start) { old_lock->length = new_lock_start - old_lock_start; } else { held_locks.erase(*iter); --client_held_lock_counts[old_lock_client]; } } else { //old lock extends past end of new lock ceph_filelock appended_lock = *old_lock; appended_lock.start = new_lock_end + 1; held_locks.insert(pair<uint64_t, ceph_filelock> (appended_lock.start, appended_lock)); ++client_held_lock_counts[(client_t)old_lock->client]; if (old_lock_start < new_lock_start) { old_lock->length = new_lock_start - old_lock_start; } else { held_locks.erase(*iter); --client_held_lock_counts[old_lock_client]; } } } } else { if (old_lock->type == new_lock.type) { //just merge them! ldout(cct,15) << "merging locks, they're the same type" << dendl; new_lock.start = (old_lock_start < new_lock_start ) ? old_lock_start : new_lock_start; int new_end = (new_lock_end > old_lock_end) ? new_lock_end : old_lock_end; new_lock.length = new_end - new_lock.start + 1; ldout(cct,15) << "erasing lock " << (*iter)->second << dendl; held_locks.erase(*iter); --client_held_lock_counts[old_lock_client]; } else { //we'll have to update sizes and maybe make new locks ldout(cct,15) << "locks aren't same type, changing sizes" << dendl; if (old_lock_end > new_lock_end) { //add extra lock after new_lock ceph_filelock appended_lock = *old_lock; appended_lock.start = new_lock_end + 1; appended_lock.length = old_lock_end - appended_lock.start + 1; held_locks.insert(pair<uint64_t, ceph_filelock> (appended_lock.start, appended_lock)); ++client_held_lock_counts[(client_t)old_lock->client]; } if (old_lock_start < new_lock_start) { old_lock->length = new_lock_start - old_lock_start; } else { //old_lock starts inside new_lock, so remove it //if it extended past new_lock_end it's been replaced held_locks.erase(*iter); --client_held_lock_counts[old_lock_client]; } } } if (!client_held_lock_counts[old_lock_client]) { client_held_lock_counts.erase(old_lock_client); } } //make sure to coalesce neighboring locks for (list<multimap<uint64_t, ceph_filelock>::iterator>::iterator iter = neighbor_locks.begin(); iter != neighbor_locks.end(); ++iter) { old_lock = &(*iter)->second; old_lock_client = old_lock->client; ldout(cct,15) << "lock to coalesce: " << *old_lock << dendl; /* because if it's a neighboring lock there can't be any self-overlapping locks that covered it */ if (old_lock->type == new_lock.type) { //merge them if (0 == new_lock.length) { if (old_lock->start + old_lock->length == new_lock.start) { new_lock.start = old_lock->start; } else ceph_abort(); /* if there's no end to new_lock, the neighbor HAS TO be to left side */ } else if (0 == old_lock->length) { if (new_lock.start + new_lock.length == old_lock->start) { new_lock.length = 0; } else ceph_abort(); //same as before, but reversed } else { if (old_lock->start + old_lock->length == new_lock.start) { new_lock.start = old_lock->start; new_lock.length = old_lock->length + new_lock.length; } else if (new_lock.start + new_lock.length == old_lock->start) { new_lock.length = old_lock->length + new_lock.length; } } held_locks.erase(*iter); --client_held_lock_counts[old_lock_client]; } if (!client_held_lock_counts[old_lock_client]) { client_held_lock_counts.erase(old_lock_client); } } } multimap<uint64_t, ceph_filelock>::iterator ceph_lock_state_t::get_lower_bound(uint64_t start, multimap<uint64_t, ceph_filelock>& lock_map) { multimap<uint64_t, ceph_filelock>::iterator lower_bound = lock_map.lower_bound(start); if ((lower_bound->first != start) && (start != 0) && (lower_bound != lock_map.begin())) --lower_bound; if (lock_map.end() == lower_bound) ldout(cct,15) << "get_lower_dout(15)eturning end()" << dendl; else ldout(cct,15) << "get_lower_bound returning iterator pointing to " << lower_bound->second << dendl; return lower_bound; } multimap<uint64_t, ceph_filelock>::iterator ceph_lock_state_t::get_last_before(uint64_t end, multimap<uint64_t, ceph_filelock>& lock_map) { multimap<uint64_t, ceph_filelock>::iterator last = lock_map.upper_bound(end); if (last != lock_map.begin()) --last; if (lock_map.end() == last) ldout(cct,15) << "get_last_before returning end()" << dendl; else ldout(cct,15) << "get_last_before returning iterator pointing to " << last->second << dendl; return last; } bool ceph_lock_state_t::share_space( multimap<uint64_t, ceph_filelock>::iterator& iter, uint64_t start, uint64_t end) { bool ret = ((iter->first >= start && iter->first <= end) || ((iter->first < start) && (((iter->first + iter->second.length - 1) >= start) || (0 == iter->second.length)))); ldout(cct,15) << "share_space got start: " << start << ", end: " << end << ", lock: " << iter->second << ", returning " << ret << dendl; return ret; } bool ceph_lock_state_t::get_overlapping_locks(const ceph_filelock& lock, list<multimap<uint64_t, ceph_filelock>::iterator> & overlaps, list<multimap<uint64_t, ceph_filelock>::iterator> *self_neighbors) { ldout(cct,15) << "get_overlapping_locks" << dendl; // create a lock starting one earlier and ending one later // to check for neighbors ceph_filelock neighbor_check_lock = lock; if (neighbor_check_lock.start != 0) { neighbor_check_lock.start = neighbor_check_lock.start - 1; if (neighbor_check_lock.length) neighbor_check_lock.length = neighbor_check_lock.length + 2; } else { if (neighbor_check_lock.length) neighbor_check_lock.length = neighbor_check_lock.length + 1; } //find the last held lock starting at the point after lock uint64_t endpoint = lock.start; if (lock.length) { endpoint += lock.length; } else { endpoint = uint64_t(-1); // max offset } multimap<uint64_t, ceph_filelock>::iterator iter = get_last_before(endpoint, held_locks); bool cont = iter != held_locks.end(); while(cont) { if (share_space(iter, lock)) { overlaps.push_front(iter); } else if (self_neighbors && ceph_filelock_owner_equal(neighbor_check_lock, iter->second) && share_space(iter, neighbor_check_lock)) { self_neighbors->push_front(iter); } if ((iter->first < lock.start) && (CEPH_LOCK_EXCL == iter->second.type)) { //can't be any more overlapping locks or they'd interfere with this one cont = false; } else if (held_locks.begin() == iter) cont = false; else --iter; } return !overlaps.empty(); } bool ceph_lock_state_t::get_waiting_overlaps(const ceph_filelock& lock, list<multimap<uint64_t, ceph_filelock>::iterator>& overlaps) { ldout(cct,15) << "get_waiting_overlaps" << dendl; multimap<uint64_t, ceph_filelock>::iterator iter = get_last_before(lock.start + lock.length - 1, waiting_locks); bool cont = iter != waiting_locks.end(); while(cont) { if (share_space(iter, lock)) overlaps.push_front(iter); if (waiting_locks.begin() == iter) cont = false; --iter; } return !overlaps.empty(); } void ceph_lock_state_t::split_by_owner(const ceph_filelock& owner, list<multimap<uint64_t, ceph_filelock>::iterator>& locks, list<multimap<uint64_t, ceph_filelock>::iterator>& owned_locks) { list<multimap<uint64_t, ceph_filelock>::iterator>::iterator iter = locks.begin(); ldout(cct,15) << "owner lock: " << owner << dendl; while (iter != locks.end()) { ldout(cct,15) << "comparing to " << (*iter)->second << dendl; if (ceph_filelock_owner_equal((*iter)->second, owner)) { ldout(cct,15) << "success, pushing to owned_locks" << dendl; owned_locks.push_back(*iter); iter = locks.erase(iter); } else { ldout(cct,15) << "failure, something not equal in this group " << (*iter)->second.client << ":" << owner.client << "," << (*iter)->second.owner << ":" << owner.owner << "," << (*iter)->second.pid << ":" << owner.pid << dendl; ++iter; } } } ceph_filelock * ceph_lock_state_t::contains_exclusive_lock(list<multimap<uint64_t, ceph_filelock>::iterator>& locks) { for (list<multimap<uint64_t, ceph_filelock>::iterator>::iterator iter = locks.begin(); iter != locks.end(); ++iter) { if (CEPH_LOCK_EXCL == (*iter)->second.type) return &(*iter)->second; } return NULL; }
22,235
35.998336
97
cc
null
ceph-main/src/mds/flock.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MDS_FLOCK_H #define CEPH_MDS_FLOCK_H #include <errno.h> #include "common/debug.h" #include "mdstypes.h" inline std::ostream& operator<<(std::ostream& out, const ceph_filelock& l) { out << "start: " << l.start << ", length: " << l.length << ", client: " << l.client << ", owner: " << l.owner << ", pid: " << l.pid << ", type: " << (int)l.type << std::endl; return out; } inline bool ceph_filelock_owner_equal(const ceph_filelock& l, const ceph_filelock& r) { if (l.client != r.client || l.owner != r.owner) return false; // The file lock is from old client if the most significant bit of // 'owner' is not set. Old clients use both 'owner' and 'pid' to // identify the owner of lock. if (l.owner & (1ULL << 63)) return true; return l.pid == r.pid; } inline int ceph_filelock_owner_compare(const ceph_filelock& l, const ceph_filelock& r) { if (l.client != r.client) return l.client > r.client ? 1 : -1; if (l.owner != r.owner) return l.owner > r.owner ? 1 : -1; if (l.owner & (1ULL << 63)) return 0; if (l.pid != r.pid) return l.pid > r.pid ? 1 : -1; return 0; } inline int ceph_filelock_compare(const ceph_filelock& l, const ceph_filelock& r) { int ret = ceph_filelock_owner_compare(l, r); if (ret) return ret; if (l.start != r.start) return l.start > r.start ? 1 : -1; if (l.length != r.length) return l.length > r.length ? 1 : -1; if (l.type != r.type) return l.type > r.type ? 1 : -1; return 0; } inline bool operator<(const ceph_filelock& l, const ceph_filelock& r) { return ceph_filelock_compare(l, r) < 0; } inline bool operator==(const ceph_filelock& l, const ceph_filelock& r) { return ceph_filelock_compare(l, r) == 0; } inline bool operator!=(const ceph_filelock& l, const ceph_filelock& r) { return ceph_filelock_compare(l, r) != 0; } class ceph_lock_state_t { public: explicit ceph_lock_state_t(CephContext *cct_, int type_) : cct(cct_), type(type_) {} ~ceph_lock_state_t(); /** * Check if a lock is on the waiting_locks list. * * @param fl The filelock to check for * @returns True if the lock is waiting, false otherwise */ bool is_waiting(const ceph_filelock &fl) const; /** * Remove a lock from the waiting_locks list * * @param fl The filelock to remove */ void remove_waiting(const ceph_filelock& fl); /* * Try to set a new lock. If it's blocked and wait_on_fail is true, * add the lock to waiting_locks. * The lock needs to be of type CEPH_LOCK_EXCL or CEPH_LOCK_SHARED. * This may merge previous locks, or convert the type of already-owned * locks. * * @param new_lock The lock to set * @param wait_on_fail whether to wait until the lock can be set. * Otherwise it fails immediately when blocked. * * @returns true if set, false if not set. */ bool add_lock(ceph_filelock& new_lock, bool wait_on_fail, bool replay, bool *deadlock); /** * See if a lock is blocked by existing locks. If the lock is blocked, * it will be set to the value of the first blocking lock. Otherwise, * it will be returned unchanged, except for setting the type field * to CEPH_LOCK_UNLOCK. * * @param testing_lock The lock to check for conflicts on. */ void look_for_lock(ceph_filelock& testing_lock); /* * Remove lock(s) described in old_lock. This may involve splitting a * previous lock or making a previous lock smaller. * * @param removal_lock The lock to remove * @param activated_locks A return parameter, holding activated wait locks. */ void remove_lock(const ceph_filelock removal_lock, std::list<ceph_filelock>& activated_locks); bool remove_all_from(client_t client); void encode(ceph::bufferlist& bl) const { using ceph::encode; encode(held_locks, bl); encode(client_held_lock_counts, bl); } void decode(ceph::bufferlist::const_iterator& bl) { using ceph::decode; decode(held_locks, bl); decode(client_held_lock_counts, bl); } bool empty() const { return held_locks.empty() && waiting_locks.empty() && client_held_lock_counts.empty() && client_waiting_lock_counts.empty(); } std::multimap<uint64_t, ceph_filelock> held_locks; // current locks std::multimap<uint64_t, ceph_filelock> waiting_locks; // locks waiting for other locks // both of the above are keyed by starting offset std::map<client_t, int> client_held_lock_counts; std::map<client_t, int> client_waiting_lock_counts; private: static const unsigned MAX_DEADLK_DEPTH = 5; /** * Check if adding the lock causes deadlock * * @param fl The blocking filelock * @param overlapping_locks list of all overlapping locks * @param first_fl * @depth recursion call depth */ bool is_deadlock(const ceph_filelock& fl, std::list<std::multimap<uint64_t, ceph_filelock>::iterator>& overlapping_locks, const ceph_filelock *first_fl=NULL, unsigned depth=0) const; /** * Add a lock to the waiting_locks list * * @param fl The filelock to add */ void add_waiting(const ceph_filelock& fl); /** * Adjust old locks owned by a single process so that process can set * a new lock of different type. Handle any changes needed to the old locks * (and the new lock) so that once the new lock is inserted into the * held_locks list the process has a coherent, non-fragmented set of lock * ranges. Make sure any overlapping locks are combined, trimmed, and removed * as needed. * This function should only be called once you know the lock will be * inserted, as it DOES adjust new_lock. You can call this function * on an empty list, in which case it does nothing. * This function does not remove elements from old_locks, so regard the list * as bad information following function invocation. * * @param new_lock The new lock the process has requested. * @param old_locks list of all locks currently held by same * client/process that overlap new_lock. * @param neighbor_locks locks owned by same process that neighbor new_lock on * left or right side. */ void adjust_locks(std::list<std::multimap<uint64_t, ceph_filelock>::iterator> old_locks, ceph_filelock& new_lock, std::list<std::multimap<uint64_t, ceph_filelock>::iterator> neighbor_locks); //get last lock prior to start position std::multimap<uint64_t, ceph_filelock>::iterator get_lower_bound(uint64_t start, std::multimap<uint64_t, ceph_filelock>& lock_map); //get latest-starting lock that goes over the byte "end" std::multimap<uint64_t, ceph_filelock>::iterator get_last_before(uint64_t end, std::multimap<uint64_t, ceph_filelock>& lock_map); /* * See if an iterator's lock covers any of the same bounds as a given range * Rules: locks cover "length" bytes from "start", so the last covered * byte is at start + length - 1. * If the length is 0, the lock covers from "start" to the end of the file. */ bool share_space(std::multimap<uint64_t, ceph_filelock>::iterator& iter, uint64_t start, uint64_t end); bool share_space(std::multimap<uint64_t, ceph_filelock>::iterator& iter, const ceph_filelock &lock) { uint64_t end = lock.start; if (lock.length) { end += lock.length - 1; } else { // zero length means end of file end = uint64_t(-1); } return share_space(iter, lock.start, end); } /* *get a list of all locks overlapping with the given lock's range * lock: the lock to compare with. * overlaps: an empty list, to be filled. * Returns: true if at least one lock overlaps. */ bool get_overlapping_locks(const ceph_filelock& lock, std::list<std::multimap<uint64_t, ceph_filelock>::iterator> & overlaps, std::list<std::multimap<uint64_t, ceph_filelock>::iterator> *self_neighbors); bool get_overlapping_locks(const ceph_filelock& lock, std::list<std::multimap<uint64_t, ceph_filelock>::iterator>& overlaps) { return get_overlapping_locks(lock, overlaps, NULL); } /** * Get a list of all waiting locks that overlap with the given lock's range. * lock: specifies the range to compare with * overlaps: an empty list, to be filled * Returns: true if at least one waiting_lock overlaps */ bool get_waiting_overlaps(const ceph_filelock& lock, std::list<std::multimap<uint64_t, ceph_filelock>::iterator>& overlaps); /* * split a list of locks up by whether they're owned by same * process as given lock * owner: the owning lock * locks: the list of locks (obtained from get_overlapping_locks, probably) * Will have all locks owned by owner removed * owned_locks: an empty list, to be filled with the locks owned by owner */ void split_by_owner(const ceph_filelock& owner, std::list<std::multimap<uint64_t, ceph_filelock>::iterator> & locks, std::list<std::multimap<uint64_t, ceph_filelock>::iterator> & owned_locks); ceph_filelock *contains_exclusive_lock(std::list<std::multimap<uint64_t, ceph_filelock>::iterator>& locks); CephContext *cct; int type; }; WRITE_CLASS_ENCODER(ceph_lock_state_t) inline std::ostream& operator<<(std::ostream &out, const ceph_lock_state_t &l) { out << "ceph_lock_state_t. held_locks.size()=" << l.held_locks.size() << ", waiting_locks.size()=" << l.waiting_locks.size() << ", client_held_lock_counts -- " << l.client_held_lock_counts << "\n client_waiting_lock_counts -- " << l.client_waiting_lock_counts << "\n held_locks -- "; for (auto iter = l.held_locks.begin(); iter != l.held_locks.end(); ++iter) out << iter->second; out << "\n waiting_locks -- "; for (auto iter =l.waiting_locks.begin(); iter != l.waiting_locks.end(); ++iter) out << iter->second << "\n"; return out; } #endif
10,330
34.624138
90
h
null
ceph-main/src/mds/fscrypt.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPHFS_FSCRYPT_H #define CEPHFS_FSCRYPT_H struct ceph_fscrypt_last_block_header { __u8 ver; __u8 compat; /* If the last block is located in a file hole the length * will be sizeof(i_version + file_offset + block_size), * or will plus to extra BLOCK SIZE. */ uint32_t data_len; /* inode change attr version */ uint64_t change_attr; /* * For a file hole, this will be 0, or it will be the offset from * which will write the last block */ uint64_t file_offset; /* It should always be the fscrypt block size */ uint32_t block_size; }; #endif
995
22.714286
70
h
null
ceph-main/src/mds/inode_backtrace.cc
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include "inode_backtrace.h" #include "common/Formatter.h" /* inode_backpointer_t */ void inode_backpointer_t::encode(ceph::buffer::list& bl) const { ENCODE_START(2, 2, bl); encode(dirino, bl); encode(dname, bl); encode(version, bl); ENCODE_FINISH(bl); } void inode_backpointer_t::decode(ceph::buffer::list::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(dirino, bl); decode(dname, bl); decode(version, bl); DECODE_FINISH(bl); } void inode_backpointer_t::decode_old(ceph::buffer::list::const_iterator& bl) { using ceph::decode; decode(dirino, bl); decode(dname, bl); decode(version, bl); } void inode_backpointer_t::dump(ceph::Formatter *f) const { f->dump_unsigned("dirino", dirino); f->dump_string("dname", dname); f->dump_unsigned("version", version); } void inode_backpointer_t::generate_test_instances(std::list<inode_backpointer_t*>& ls) { ls.push_back(new inode_backpointer_t); ls.push_back(new inode_backpointer_t); ls.back()->dirino = 1; ls.back()->dname = "foo"; ls.back()->version = 123; } /* * inode_backtrace_t */ void inode_backtrace_t::encode(ceph::buffer::list& bl) const { ENCODE_START(5, 4, bl); encode(ino, bl); encode(ancestors, bl); encode(pool, bl); encode(old_pools, bl); ENCODE_FINISH(bl); } void inode_backtrace_t::decode(ceph::buffer::list::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(5, 4, 4, bl); if (struct_v < 3) return; // sorry, the old data was crap decode(ino, bl); if (struct_v >= 4) { decode(ancestors, bl); } else { __u32 n; decode(n, bl); while (n--) { ancestors.push_back(inode_backpointer_t()); ancestors.back().decode_old(bl); } } if (struct_v >= 5) { decode(pool, bl); decode(old_pools, bl); } DECODE_FINISH(bl); } void inode_backtrace_t::dump(ceph::Formatter *f) const { f->dump_unsigned("ino", ino); f->open_array_section("ancestors"); for (auto p = ancestors.begin(); p != ancestors.end(); ++p) { f->open_object_section("backpointer"); p->dump(f); f->close_section(); } f->close_section(); f->dump_int("pool", pool); f->open_array_section("old_pools"); for (auto p = old_pools.begin(); p != old_pools.end(); ++p) { f->dump_int("old_pool", *p); } f->close_section(); } void inode_backtrace_t::generate_test_instances(std::list<inode_backtrace_t*>& ls) { ls.push_back(new inode_backtrace_t); ls.push_back(new inode_backtrace_t); ls.back()->ino = 1; ls.back()->ancestors.push_back(inode_backpointer_t()); ls.back()->ancestors.back().dirino = 123; ls.back()->ancestors.back().dname = "bar"; ls.back()->ancestors.back().version = 456; ls.back()->pool = 0; ls.back()->old_pools.push_back(10); ls.back()->old_pools.push_back(7); } int inode_backtrace_t::compare(const inode_backtrace_t& other, bool *equivalent, bool *divergent) const { int min_size = std::min(ancestors.size(),other.ancestors.size()); *equivalent = true; *divergent = false; if (min_size == 0) return 0; int comparator = 0; if (ancestors[0].version > other.ancestors[0].version) comparator = 1; else if (ancestors[0].version < other.ancestors[0].version) comparator = -1; if (ancestors[0].dirino != other.ancestors[0].dirino || ancestors[0].dname != other.ancestors[0].dname) *divergent = true; for (int i = 1; i < min_size; ++i) { if (*divergent) { /** * we already know the dentries and versions are * incompatible; no point checking farther */ break; } if (ancestors[i].dirino != other.ancestors[i].dirino || ancestors[i].dname != other.ancestors[i].dname) { *equivalent = false; return comparator; } else if (ancestors[i].version > other.ancestors[i].version) { if (comparator < 0) *divergent = true; comparator = 1; } else if (ancestors[i].version < other.ancestors[i].version) { if (comparator > 0) *divergent = true; comparator = -1; } } if (*divergent) *equivalent = false; return comparator; }
4,234
24.823171
86
cc
null
ceph-main/src/mds/inode_backtrace.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_INODE_BACKTRACE_H #define CEPH_INODE_BACKTRACE_H #include <string_view> #include "mdstypes.h" namespace ceph { class Formatter; } /** metadata backpointers **/ /* * - inode_backpointer_t is just the _pointer_ portion; it doesn't * tell us who we point _from_. * * - it _does_ include a version of the source object, so we can look * at two different pointers (from the same inode) and tell which is * newer. */ struct inode_backpointer_t { inode_backpointer_t() {} inode_backpointer_t(inodeno_t i, std::string_view d, version_t v) : dirino(i), dname(d), version(v) {} void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator &bl); void decode_old(ceph::buffer::list::const_iterator &bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<inode_backpointer_t*>& ls); inodeno_t dirino; // containing directory ino std::string dname; // linking dentry name version_t version = 0; // child's version at time of backpointer creation }; WRITE_CLASS_ENCODER(inode_backpointer_t) inline bool operator==(const inode_backpointer_t& l, const inode_backpointer_t& r) { return l.dirino == r.dirino && l.version == r.version && l.dname == r.dname; } inline std::ostream& operator<<(std::ostream& out, const inode_backpointer_t& ib) { return out << "<" << ib.dirino << "/" << ib.dname << " v" << ib.version << ">"; } /* * inode_backtrace_t is a complete ancestor backtraces for a given inode. * we include who _we_ are, so that the backtrace can stand alone (as, say, * an xattr on an object). */ struct inode_backtrace_t { inode_backtrace_t() {} void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator &bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<inode_backtrace_t*>& ls); /** * Compare two backtraces *for the same inode*. * @pre The backtraces are for the same inode * * @param other The backtrace to compare ourselves with * @param equivalent A bool pointer which will be set to true if * the other backtrace is equivalent to our own (has the same dentries) * @param divergent A bool pointer which will be set to true if * the backtraces have differing entries without versions supporting them * * @returns 1 if we are newer than the other, 0 if equal, -1 if older */ int compare(const inode_backtrace_t& other, bool *equivalent, bool *divergent) const; void clear() { ancestors.clear(); old_pools.clear(); } inodeno_t ino; // my ino std::vector<inode_backpointer_t> ancestors; int64_t pool = -1; std::vector<int64_t> old_pools; }; WRITE_CLASS_ENCODER(inode_backtrace_t) inline std::ostream& operator<<(std::ostream& out, const inode_backtrace_t& it) { return out << "(" << it.pool << ")" << it.ino << ":" << it.ancestors << "//" << it.old_pools; } inline bool operator==(const inode_backtrace_t& l, const inode_backtrace_t& r) { return l.ino == r.ino && l.pool == r.pool && l.old_pools == r.old_pools && l.ancestors == r.ancestors; } #endif
3,291
31.594059
104
h
null
ceph-main/src/mds/journal.cc
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #include "common/config.h" #include "osdc/Journaler.h" #include "events/ESubtreeMap.h" #include "events/ESession.h" #include "events/ESessions.h" #include "events/EMetaBlob.h" #include "events/EResetJournal.h" #include "events/ENoOp.h" #include "events/EUpdate.h" #include "events/EPeerUpdate.h" #include "events/EOpen.h" #include "events/ECommitted.h" #include "events/EPurged.h" #include "events/EExport.h" #include "events/EImportStart.h" #include "events/EImportFinish.h" #include "events/EFragment.h" #include "events/ETableClient.h" #include "events/ETableServer.h" #include "include/stringify.h" #include "LogSegment.h" #include "MDSRank.h" #include "MDLog.h" #include "MDCache.h" #include "Server.h" #include "Migrator.h" #include "Mutation.h" #include "InoTable.h" #include "MDSTableClient.h" #include "MDSTableServer.h" #include "Locker.h" #define dout_context g_ceph_context #define dout_subsys ceph_subsys_mds #undef dout_prefix #define dout_prefix *_dout << "mds." << mds->get_nodeid() << ".journal " using std::list; using std::map; using std::ostream; using std::pair; using std::set; using std::string; using std::vector; // ----------------------- // LogSegment struct BatchStoredBacktrace : public MDSIOContext { MDSContext *fin; std::vector<CInodeCommitOperations> ops_vec; BatchStoredBacktrace(MDSRank *m, MDSContext *f, std::vector<CInodeCommitOperations>&& ops) : MDSIOContext(m), fin(f), ops_vec(std::move(ops)) {} void finish(int r) override { for (auto& op : ops_vec) { op.in->_stored_backtrace(r, op.version, nullptr); } fin->complete(r); } void print(ostream& out) const override { out << "batch backtrace_store"; } }; struct BatchCommitBacktrace : public Context { MDSRank *mds; MDSContext *fin; std::vector<CInodeCommitOperations> ops_vec; BatchCommitBacktrace(MDSRank *m, MDSContext *f, std::vector<CInodeCommitOperations>&& ops) : mds(m), fin(f), ops_vec(std::move(ops)) {} void finish(int r) override { C_GatherBuilder gather(g_ceph_context); for (auto &op : ops_vec) { op.in->_commit_ops(r, gather, op.ops_vec, op.bt); op.ops_vec.clear(); op.bt.clear(); } ceph_assert(gather.has_subs()); gather.set_finisher(new C_OnFinisher( new BatchStoredBacktrace(mds, fin, std::move(ops_vec)), mds->finisher)); gather.activate(); } }; void LogSegment::try_to_expire(MDSRank *mds, MDSGatherBuilder &gather_bld, int op_prio) { set<CDir*> commit; dout(6) << "LogSegment(" << seq << "/" << offset << ").try_to_expire" << dendl; ceph_assert(g_conf()->mds_kill_journal_expire_at != 1); // commit dirs for (elist<CDir*>::iterator p = new_dirfrags.begin(); !p.end(); ++p) { dout(20) << " new_dirfrag " << **p << dendl; ceph_assert((*p)->is_auth()); commit.insert(*p); } for (elist<CDir*>::iterator p = dirty_dirfrags.begin(); !p.end(); ++p) { dout(20) << " dirty_dirfrag " << **p << dendl; ceph_assert((*p)->is_auth()); commit.insert(*p); } for (elist<CDentry*>::iterator p = dirty_dentries.begin(); !p.end(); ++p) { dout(20) << " dirty_dentry " << **p << dendl; ceph_assert((*p)->is_auth()); commit.insert((*p)->get_dir()); } for (elist<CInode*>::iterator p = dirty_inodes.begin(); !p.end(); ++p) { dout(20) << " dirty_inode " << **p << dendl; ceph_assert((*p)->is_auth()); if ((*p)->is_base()) { (*p)->store(gather_bld.new_sub()); } else commit.insert((*p)->get_parent_dn()->get_dir()); } if (!commit.empty()) { for (set<CDir*>::iterator p = commit.begin(); p != commit.end(); ++p) { CDir *dir = *p; ceph_assert(dir->is_auth()); if (dir->can_auth_pin()) { dout(15) << "try_to_expire committing " << *dir << dendl; dir->commit(0, gather_bld.new_sub(), false, op_prio); } else { dout(15) << "try_to_expire waiting for unfreeze on " << *dir << dendl; dir->add_waiter(CDir::WAIT_UNFREEZE, gather_bld.new_sub()); } } } // leader ops with possibly uncommitted peers for (set<metareqid_t>::iterator p = uncommitted_leaders.begin(); p != uncommitted_leaders.end(); ++p) { dout(10) << "try_to_expire waiting for peers to ack commit on " << *p << dendl; mds->mdcache->wait_for_uncommitted_leader(*p, gather_bld.new_sub()); } // peer ops that haven't been committed for (set<metareqid_t>::iterator p = uncommitted_peers.begin(); p != uncommitted_peers.end(); ++p) { dout(10) << "try_to_expire waiting for leader to ack OP_FINISH on " << *p << dendl; mds->mdcache->wait_for_uncommitted_peer(*p, gather_bld.new_sub()); } // uncommitted fragments for (set<dirfrag_t>::iterator p = uncommitted_fragments.begin(); p != uncommitted_fragments.end(); ++p) { dout(10) << "try_to_expire waiting for uncommitted fragment " << *p << dendl; mds->mdcache->wait_for_uncommitted_fragment(*p, gather_bld.new_sub()); } // nudge scatterlocks for (elist<CInode*>::iterator p = dirty_dirfrag_dir.begin(); !p.end(); ++p) { CInode *in = *p; dout(10) << "try_to_expire waiting for dirlock flush on " << *in << dendl; mds->locker->scatter_nudge(&in->filelock, gather_bld.new_sub()); } for (elist<CInode*>::iterator p = dirty_dirfrag_dirfragtree.begin(); !p.end(); ++p) { CInode *in = *p; dout(10) << "try_to_expire waiting for dirfragtreelock flush on " << *in << dendl; mds->locker->scatter_nudge(&in->dirfragtreelock, gather_bld.new_sub()); } for (elist<CInode*>::iterator p = dirty_dirfrag_nest.begin(); !p.end(); ++p) { CInode *in = *p; dout(10) << "try_to_expire waiting for nest flush on " << *in << dendl; mds->locker->scatter_nudge(&in->nestlock, gather_bld.new_sub()); } ceph_assert(g_conf()->mds_kill_journal_expire_at != 2); // open files and snap inodes if (!open_files.empty()) { ceph_assert(!mds->mdlog->is_capped()); // hmm FIXME EOpen *le = 0; LogSegment *ls = mds->mdlog->get_current_segment(); ceph_assert(ls != this); elist<CInode*>::iterator p = open_files.begin(member_offset(CInode, item_open_file)); while (!p.end()) { CInode *in = *p; ++p; if (in->last != CEPH_NOSNAP && in->is_auth() && !in->client_snap_caps.empty()) { // journal snap inodes that need flush. This simplify the mds failover hanlding dout(20) << "try_to_expire requeueing snap needflush inode " << *in << dendl; if (!le) { le = new EOpen(mds->mdlog); mds->mdlog->start_entry(le); } le->add_clean_inode(in); ls->open_files.push_back(&in->item_open_file); } else { // open files are tracked by open file table, no need to journal them again in->item_open_file.remove_myself(); } } if (le) { mds->mdlog->submit_entry(le); mds->mdlog->wait_for_safe(gather_bld.new_sub()); dout(10) << "try_to_expire waiting for open files to rejournal" << dendl; } } ceph_assert(g_conf()->mds_kill_journal_expire_at != 3); size_t count = 0; for (elist<CInode*>::iterator it = dirty_parent_inodes.begin(); !it.end(); ++it) count++; std::vector<CInodeCommitOperations> ops_vec; ops_vec.reserve(count); // backtraces to be stored/updated for (elist<CInode*>::iterator p = dirty_parent_inodes.begin(); !p.end(); ++p) { CInode *in = *p; ceph_assert(in->is_auth()); if (in->can_auth_pin()) { dout(15) << "try_to_expire waiting for storing backtrace on " << *in << dendl; ops_vec.resize(ops_vec.size() + 1); in->store_backtrace(ops_vec.back(), op_prio); } else { dout(15) << "try_to_expire waiting for unfreeze on " << *in << dendl; in->add_waiter(CInode::WAIT_UNFREEZE, gather_bld.new_sub()); } } if (!ops_vec.empty()) mds->finisher->queue(new BatchCommitBacktrace(mds, gather_bld.new_sub(), std::move(ops_vec))); ceph_assert(g_conf()->mds_kill_journal_expire_at != 4); // idalloc if (inotablev > mds->inotable->get_committed_version()) { dout(10) << "try_to_expire saving inotable table, need " << inotablev << ", committed is " << mds->inotable->get_committed_version() << " (" << mds->inotable->get_committing_version() << ")" << dendl; mds->inotable->save(gather_bld.new_sub(), inotablev); } // sessionmap if (sessionmapv > mds->sessionmap.get_committed()) { dout(10) << "try_to_expire saving sessionmap, need " << sessionmapv << ", committed is " << mds->sessionmap.get_committed() << " (" << mds->sessionmap.get_committing() << ")" << dendl; mds->sessionmap.save(gather_bld.new_sub(), sessionmapv); } // updates to sessions for completed_requests mds->sessionmap.save_if_dirty(touched_sessions, &gather_bld); touched_sessions.clear(); // pending commit atids for (map<int, ceph::unordered_set<version_t> >::iterator p = pending_commit_tids.begin(); p != pending_commit_tids.end(); ++p) { MDSTableClient *client = mds->get_table_client(p->first); ceph_assert(client); for (ceph::unordered_set<version_t>::iterator q = p->second.begin(); q != p->second.end(); ++q) { dout(10) << "try_to_expire " << get_mdstable_name(p->first) << " transaction " << *q << " pending commit (not yet acked), waiting" << dendl; ceph_assert(!client->has_committed(*q)); client->wait_for_ack(*q, gather_bld.new_sub()); } } // table servers for (map<int, version_t>::iterator p = tablev.begin(); p != tablev.end(); ++p) { MDSTableServer *server = mds->get_table_server(p->first); ceph_assert(server); if (p->second > server->get_committed_version()) { dout(10) << "try_to_expire waiting for " << get_mdstable_name(p->first) << " to save, need " << p->second << dendl; server->save(gather_bld.new_sub()); } } // truncating for (set<CInode*>::iterator p = truncating_inodes.begin(); p != truncating_inodes.end(); ++p) { dout(10) << "try_to_expire waiting for truncate of " << **p << dendl; (*p)->add_waiter(CInode::WAIT_TRUNC, gather_bld.new_sub()); } // purge inodes dout(10) << "try_to_expire waiting for purge of " << purging_inodes << dendl; if (purging_inodes.size()) set_purged_cb(gather_bld.new_sub()); if (gather_bld.has_subs()) { dout(6) << "LogSegment(" << seq << "/" << offset << ").try_to_expire waiting" << dendl; mds->mdlog->flush(); } else { ceph_assert(g_conf()->mds_kill_journal_expire_at != 5); dout(6) << "LogSegment(" << seq << "/" << offset << ").try_to_expire success" << dendl; } } // ----------------------- // EMetaBlob void EMetaBlob::add_dir_context(CDir *dir, int mode) { MDSRank *mds = dir->mdcache->mds; list<CDentry*> parents; // it may be okay not to include the maybe items, if // - we journaled the maybe child inode in this segment // - that subtree turns out to be unambiguously auth list<CDentry*> maybe; bool maybenot = false; while (true) { // already have this dir? (we must always add in order) if (lump_map.count(dir->dirfrag())) { dout(20) << "EMetaBlob::add_dir_context(" << dir << ") have lump " << dir->dirfrag() << dendl; break; } // stop at root/stray CInode *diri = dir->get_inode(); CDentry *parent = diri->get_projected_parent_dn(); if (mode == TO_AUTH_SUBTREE_ROOT) { // subtree root? if (dir->is_subtree_root()) { // match logic in MDCache::create_subtree_map() if (dir->get_dir_auth().first == mds->get_nodeid()) { mds_authority_t parent_auth = parent ? parent->authority() : CDIR_AUTH_UNDEF; if (parent_auth.first == dir->get_dir_auth().first) { if (parent_auth.second == CDIR_AUTH_UNKNOWN && !dir->is_ambiguous_dir_auth() && !dir->state_test(CDir::STATE_EXPORTBOUND) && !dir->state_test(CDir::STATE_AUXSUBTREE) && !diri->state_test(CInode::STATE_AMBIGUOUSAUTH)) { dout(0) << "EMetaBlob::add_dir_context unexpected subtree " << *dir << dendl; ceph_abort(); } dout(20) << "EMetaBlob::add_dir_context(" << dir << ") ambiguous or transient subtree " << dendl; } else { // it's an auth subtree, we don't need maybe (if any), and we're done. dout(20) << "EMetaBlob::add_dir_context(" << dir << ") reached unambig auth subtree, don't need " << maybe << " at " << *dir << dendl; maybe.clear(); break; } } else { dout(20) << "EMetaBlob::add_dir_context(" << dir << ") reached ambig or !auth subtree, need " << maybe << " at " << *dir << dendl; // we need the maybe list after all! parents.splice(parents.begin(), maybe); maybenot = false; } } // was the inode journaled in this blob? if (event_seq && diri->last_journaled == event_seq) { dout(20) << "EMetaBlob::add_dir_context(" << dir << ") already have diri this blob " << *diri << dendl; break; } // have we journaled this inode since the last subtree map? if (!maybenot && last_subtree_map && diri->last_journaled >= last_subtree_map) { dout(20) << "EMetaBlob::add_dir_context(" << dir << ") already have diri in this segment (" << diri->last_journaled << " >= " << last_subtree_map << "), setting maybenot flag " << *diri << dendl; maybenot = true; } } if (!parent) break; if (maybenot) { dout(25) << "EMetaBlob::add_dir_context(" << dir << ") maybe " << *parent << dendl; maybe.push_front(parent); } else { dout(25) << "EMetaBlob::add_dir_context(" << dir << ") definitely " << *parent << dendl; parents.push_front(parent); } dir = parent->get_dir(); } parents.splice(parents.begin(), maybe); dout(20) << "EMetaBlob::add_dir_context final: " << parents << dendl; for (const auto& dentry : parents) { ceph_assert(dentry->get_projected_linkage()->is_primary()); add_dentry(dentry, false); } } void EMetaBlob::update_segment(LogSegment *ls) { // dirty inode mtimes // -> handled directly by Server.cc, replay() // alloc table update? if (inotablev) ls->inotablev = inotablev; if (sessionmapv) ls->sessionmapv = sessionmapv; // truncated inodes // -> handled directly by Server.cc // client requests // note the newest request per client //if (!client_reqs.empty()) // ls->last_client_tid[client_reqs.rbegin()->client] = client_reqs.rbegin()->tid); } // EMetaBlob::fullbit void EMetaBlob::fullbit::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(9, 5, bl); encode(dn, bl); encode(dnfirst, bl); encode(dnlast, bl); encode(dnv, bl); encode(*inode, bl, features); if (xattrs) encode(*xattrs, bl); else encode((__u32)0, bl); if (inode->is_symlink()) encode(symlink, bl); if (inode->is_dir()) { encode(dirfragtree, bl); encode(snapbl, bl); } encode(state, bl); if (!old_inodes || old_inodes->empty()) { encode(false, bl); } else { encode(true, bl); encode(*old_inodes, bl, features); } if (!inode->is_dir()) encode(snapbl, bl); encode(oldest_snap, bl); encode(alternate_name, bl); ENCODE_FINISH(bl); } void EMetaBlob::fullbit::decode(bufferlist::const_iterator &bl) { DECODE_START(9, bl); decode(dn, bl); decode(dnfirst, bl); decode(dnlast, bl); decode(dnv, bl); { auto _inode = CInode::allocate_inode(); decode(*_inode, bl); inode = std::move(_inode); } { CInode::mempool_xattr_map tmp; decode_noshare(tmp, bl); if (!tmp.empty()) xattrs = CInode::allocate_xattr_map(std::move(tmp)); } if (inode->is_symlink()) decode(symlink, bl); if (inode->is_dir()) { decode(dirfragtree, bl); decode(snapbl, bl); } decode(state, bl); bool old_inodes_present; decode(old_inodes_present, bl); if (old_inodes_present) { auto _old_inodes = CInode::allocate_old_inode_map(); decode(*_old_inodes, bl); old_inodes = std::move(_old_inodes); } if (!inode->is_dir()) { decode(snapbl, bl); } decode(oldest_snap, bl); if (struct_v >= 9) { decode(alternate_name, bl); } DECODE_FINISH(bl); } void EMetaBlob::fullbit::dump(Formatter *f) const { f->dump_string("dentry", dn); f->dump_stream("snapid.first") << dnfirst; f->dump_stream("snapid.last") << dnlast; f->dump_int("dentry version", dnv); f->open_object_section("inode"); inode->dump(f); f->close_section(); // inode f->open_object_section("xattrs"); if (xattrs) { for (const auto &p : *xattrs) { std::string s(p.second.c_str(), p.second.length()); f->dump_string(p.first.c_str(), s); } } f->close_section(); // xattrs if (inode->is_symlink()) { f->dump_string("symlink", symlink); } if (inode->is_dir()) { f->dump_stream("frag tree") << dirfragtree; f->dump_string("has_snapbl", snapbl.length() ? "true" : "false"); if (inode->has_layout()) { f->open_object_section("file layout policy"); // FIXME f->dump_string("layout", "the layout exists"); f->close_section(); // file layout policy } } f->dump_string("state", state_string()); if (old_inodes && !old_inodes->empty()) { f->open_array_section("old inodes"); for (const auto &p : *old_inodes) { f->open_object_section("inode"); f->dump_int("snapid", p.first); p.second.dump(f); f->close_section(); // inode } f->close_section(); // old inodes } f->dump_string("alternate_name", alternate_name); } void EMetaBlob::fullbit::generate_test_instances(std::list<EMetaBlob::fullbit*>& ls) { auto _inode = CInode::allocate_inode(); fragtree_t fragtree; auto _xattrs = CInode::allocate_xattr_map(); bufferlist empty_snapbl; fullbit *sample = new fullbit("/testdn", "", 0, 0, 0, _inode, fragtree, _xattrs, "", 0, empty_snapbl, false, NULL); ls.push_back(sample); } void EMetaBlob::fullbit::update_inode(MDSRank *mds, CInode *in) { in->reset_inode(std::move(inode)); in->reset_xattrs(std::move(xattrs)); if (in->is_dir()) { if (is_export_ephemeral_random()) { dout(15) << "random ephemeral pin on " << *in << dendl; in->set_ephemeral_pin(false, true); } in->maybe_export_pin(); if (!(in->dirfragtree == dirfragtree)) { dout(10) << "EMetaBlob::fullbit::update_inode dft " << in->dirfragtree << " -> " << dirfragtree << " on " << *in << dendl; in->dirfragtree = std::move(dirfragtree); in->force_dirfrags(); if (in->get_num_dirfrags() && in->authority() == CDIR_AUTH_UNDEF) { auto&& ls = in->get_nested_dirfrags(); for (const auto& dir : ls) { if (dir->get_num_any() == 0 && mds->mdcache->can_trim_non_auth_dirfrag(dir)) { dout(10) << " closing empty non-auth dirfrag " << *dir << dendl; in->close_dirfrag(dir->get_frag()); } } } } } else if (in->is_symlink()) { in->symlink = symlink; } in->reset_old_inodes(std::move(old_inodes)); if (in->is_any_old_inodes()) { snapid_t min_first = in->get_old_inodes()->rbegin()->first + 1; if (min_first > in->first) in->first = min_first; } /* * we can do this before linking hte inode bc the split_at would * be a no-op.. we have no children (namely open snaprealms) to * divy up */ in->oldest_snap = oldest_snap; in->decode_snap_blob(snapbl); /* * In case there was anything malformed in the journal that we are * replaying, do sanity checks on the inodes we're replaying and * go damaged instead of letting any trash into a live cache */ if (in->is_file()) { // Files must have valid layouts with a pool set if (in->get_inode()->layout.pool_id == -1 || !in->get_inode()->layout.is_valid()) { dout(0) << "EMetaBlob.replay invalid layout on ino " << *in << ": " << in->get_inode()->layout << dendl; CachedStackStringStream css; *css << "Invalid layout for inode " << in->ino() << " in journal"; mds->clog->error() << css->strv(); mds->damaged(); ceph_abort(); // Should be unreachable because damaged() calls respawn() } } } // EMetaBlob::remotebit void EMetaBlob::remotebit::encode(bufferlist& bl) const { ENCODE_START(3, 2, bl); encode(dn, bl); encode(dnfirst, bl); encode(dnlast, bl); encode(dnv, bl); encode(ino, bl); encode(d_type, bl); encode(dirty, bl); encode(alternate_name, bl); ENCODE_FINISH(bl); } void EMetaBlob::remotebit::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); decode(dn, bl); decode(dnfirst, bl); decode(dnlast, bl); decode(dnv, bl); decode(ino, bl); decode(d_type, bl); decode(dirty, bl); if (struct_v >= 3) decode(alternate_name, bl); DECODE_FINISH(bl); } void EMetaBlob::remotebit::dump(Formatter *f) const { f->dump_string("dentry", dn); f->dump_int("snapid.first", dnfirst); f->dump_int("snapid.last", dnlast); f->dump_int("dentry version", dnv); f->dump_int("inodeno", ino); uint32_t type = DTTOIF(d_type) & S_IFMT; // convert to type entries string type_string; switch(type) { case S_IFREG: type_string = "file"; break; case S_IFLNK: type_string = "symlink"; break; case S_IFDIR: type_string = "directory"; break; case S_IFIFO: type_string = "fifo"; break; case S_IFCHR: type_string = "chr"; break; case S_IFBLK: type_string = "blk"; break; case S_IFSOCK: type_string = "sock"; break; default: assert (0 == "unknown d_type!"); } f->dump_string("d_type", type_string); f->dump_string("dirty", dirty ? "true" : "false"); f->dump_string("alternate_name", alternate_name); } void EMetaBlob::remotebit:: generate_test_instances(std::list<EMetaBlob::remotebit*>& ls) { remotebit *remote = new remotebit("/test/dn", "", 0, 10, 15, 1, IFTODT(S_IFREG), false); ls.push_back(remote); remote = new remotebit("/test/dn2", "foo", 0, 10, 15, 1, IFTODT(S_IFREG), false); ls.push_back(remote); } // EMetaBlob::nullbit void EMetaBlob::nullbit::encode(bufferlist& bl) const { ENCODE_START(2, 2, bl); encode(dn, bl); encode(dnfirst, bl); encode(dnlast, bl); encode(dnv, bl); encode(dirty, bl); ENCODE_FINISH(bl); } void EMetaBlob::nullbit::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(dn, bl); decode(dnfirst, bl); decode(dnlast, bl); decode(dnv, bl); decode(dirty, bl); DECODE_FINISH(bl); } void EMetaBlob::nullbit::dump(Formatter *f) const { f->dump_string("dentry", dn); f->dump_int("snapid.first", dnfirst); f->dump_int("snapid.last", dnlast); f->dump_int("dentry version", dnv); f->dump_string("dirty", dirty ? "true" : "false"); } void EMetaBlob::nullbit::generate_test_instances(std::list<nullbit*>& ls) { nullbit *sample = new nullbit("/test/dentry", 0, 10, 15, false); nullbit *sample2 = new nullbit("/test/dirty", 10, 20, 25, true); ls.push_back(sample); ls.push_back(sample2); } // EMetaBlob::dirlump void EMetaBlob::dirlump::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(2, 2, bl); encode(*fnode, bl); encode(state, bl); encode(nfull, bl); encode(nremote, bl); encode(nnull, bl); _encode_bits(features); encode(dnbl, bl); ENCODE_FINISH(bl); } void EMetaBlob::dirlump::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl) { auto _fnode = CDir::allocate_fnode(); decode(*_fnode, bl); fnode = std::move(_fnode); } decode(state, bl); decode(nfull, bl); decode(nremote, bl); decode(nnull, bl); decode(dnbl, bl); dn_decoded = false; // don't decode bits unless we need them. DECODE_FINISH(bl); } void EMetaBlob::dirlump::dump(Formatter *f) const { if (!dn_decoded) { dirlump *me = const_cast<dirlump*>(this); me->_decode_bits(); } f->open_object_section("fnode"); fnode->dump(f); f->close_section(); // fnode f->dump_string("state", state_string()); f->dump_int("nfull", nfull); f->dump_int("nremote", nremote); f->dump_int("nnull", nnull); f->open_array_section("full bits"); for (const auto& iter : dfull) { f->open_object_section("fullbit"); iter.dump(f); f->close_section(); // fullbit } f->close_section(); // full bits f->open_array_section("remote bits"); for (const auto& iter : dremote) { f->open_object_section("remotebit"); iter.dump(f); f->close_section(); // remotebit } f->close_section(); // remote bits f->open_array_section("null bits"); for (const auto& iter : dnull) { f->open_object_section("null bit"); iter.dump(f); f->close_section(); // null bit } f->close_section(); // null bits } void EMetaBlob::dirlump::generate_test_instances(std::list<dirlump*>& ls) { auto dl = new dirlump(); dl->fnode = CDir::allocate_fnode(); ls.push_back(dl); } /** * EMetaBlob proper */ void EMetaBlob::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(8, 5, bl); encode(lump_order, bl); encode(lump_map, bl, features); encode(roots, bl, features); encode(table_tids, bl); encode(opened_ino, bl); encode(allocated_ino, bl); encode(used_preallocated_ino, bl); encode(preallocated_inos, bl); encode(client_name, bl); encode(inotablev, bl); encode(sessionmapv, bl); encode(truncate_start, bl); encode(truncate_finish, bl); encode(destroyed_inodes, bl); encode(client_reqs, bl); encode(renamed_dirino, bl); encode(renamed_dir_frags, bl); { // make MDSRank use v6 format happy int64_t i = -1; bool b = false; encode(i, bl); encode(b, bl); } encode(client_flushes, bl); ENCODE_FINISH(bl); } void EMetaBlob::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(8, 5, 5, bl); decode(lump_order, bl); decode(lump_map, bl); if (struct_v >= 4) { decode(roots, bl); } else { bufferlist rootbl; decode(rootbl, bl); if (rootbl.length()) { auto p = rootbl.cbegin(); roots.emplace_back(p); } } decode(table_tids, bl); decode(opened_ino, bl); decode(allocated_ino, bl); decode(used_preallocated_ino, bl); decode(preallocated_inos, bl); decode(client_name, bl); decode(inotablev, bl); decode(sessionmapv, bl); decode(truncate_start, bl); decode(truncate_finish, bl); decode(destroyed_inodes, bl); if (struct_v >= 2) { decode(client_reqs, bl); } else { list<metareqid_t> r; decode(r, bl); while (!r.empty()) { client_reqs.push_back(pair<metareqid_t,uint64_t>(r.front(), 0)); r.pop_front(); } } if (struct_v >= 3) { decode(renamed_dirino, bl); decode(renamed_dir_frags, bl); } if (struct_v >= 6) { // ignore int64_t i; bool b; decode(i, bl); decode(b, bl); } if (struct_v >= 8) { decode(client_flushes, bl); } DECODE_FINISH(bl); } /** * Get all inodes touched by this metablob. Includes the 'bits' within * dirlumps, and the inodes of the dirs themselves. */ void EMetaBlob::get_inodes( std::set<inodeno_t> &inodes) const { // For all dirlumps in this metablob for (std::map<dirfrag_t, dirlump>::const_iterator i = lump_map.begin(); i != lump_map.end(); ++i) { // Record inode of dirlump inodeno_t const dir_ino = i->first.ino; inodes.insert(dir_ino); // Decode dirlump bits dirlump const &dl = i->second; dl._decode_bits(); // Record inodes of fullbits for (const auto& iter : dl.get_dfull()) { inodes.insert(iter.inode->ino); } // Record inodes of remotebits for (const auto& iter : dl.get_dremote()) { inodes.insert(iter.ino); } } } /** * Get a map of dirfrag to set of dentries in that dirfrag which are * touched in this operation. */ void EMetaBlob::get_dentries(std::map<dirfrag_t, std::set<std::string> > &dentries) const { for (std::map<dirfrag_t, dirlump>::const_iterator i = lump_map.begin(); i != lump_map.end(); ++i) { dirlump const &dl = i->second; dirfrag_t const &df = i->first; // Get all bits dl._decode_bits(); // For all bits, store dentry for (const auto& iter : dl.get_dfull()) { dentries[df].insert(iter.dn); } for (const auto& iter : dl.get_dremote()) { dentries[df].insert(iter.dn); } for (const auto& iter : dl.get_dnull()) { dentries[df].insert(iter.dn); } } } /** * Calculate all paths that we can infer are touched by this metablob. Only uses * information local to this metablob so it may only be the path within the * subtree. */ void EMetaBlob::get_paths( std::vector<std::string> &paths) const { // Each dentry has a 'location' which is a 2-tuple of parent inode and dentry name typedef std::pair<inodeno_t, std::string> Location; // Whenever we see a dentry within a dirlump, we remember it as a child of // the dirlump's inode std::map<inodeno_t, std::vector<std::string> > children; // Whenever we see a location for an inode, remember it: this allows us to // build a path given an inode std::map<inodeno_t, Location> ino_locations; // Special case: operations on root inode populate roots but not dirlumps if (lump_map.empty() && !roots.empty()) { paths.push_back("/"); return; } // First pass // ========== // Build a tiny local metadata cache for the path structure in this metablob for (std::map<dirfrag_t, dirlump>::const_iterator i = lump_map.begin(); i != lump_map.end(); ++i) { inodeno_t const dir_ino = i->first.ino; dirlump const &dl = i->second; dl._decode_bits(); for (const auto& iter : dl.get_dfull()) { std::string_view dentry = iter.dn; children[dir_ino].emplace_back(dentry); ino_locations[iter.inode->ino] = Location(dir_ino, dentry); } for (const auto& iter : dl.get_dremote()) { std::string_view dentry = iter.dn; children[dir_ino].emplace_back(dentry); } for (const auto& iter : dl.get_dnull()) { std::string_view dentry = iter.dn; children[dir_ino].emplace_back(dentry); } } std::vector<Location> leaf_locations; // Second pass // =========== // Output paths for all childless nodes in the metablob for (std::map<dirfrag_t, dirlump>::const_iterator i = lump_map.begin(); i != lump_map.end(); ++i) { inodeno_t const dir_ino = i->first.ino; dirlump const &dl = i->second; dl._decode_bits(); for (const auto& iter : dl.get_dfull()) { std::string_view dentry = iter.dn; if (children.find(iter.inode->ino) == children.end()) { leaf_locations.push_back(Location(dir_ino, dentry)); } } for (const auto& iter : dl.get_dremote()) { std::string_view dentry = iter.dn; leaf_locations.push_back(Location(dir_ino, dentry)); } for (const auto& iter : dl.get_dnull()) { std::string_view dentry = iter.dn; leaf_locations.push_back(Location(dir_ino, dentry)); } } // For all the leaf locations identified, generate paths for (std::vector<Location>::iterator i = leaf_locations.begin(); i != leaf_locations.end(); ++i) { Location const &loc = *i; std::string path = loc.second; inodeno_t ino = loc.first; std::map<inodeno_t, Location>::iterator iter = ino_locations.find(ino); while(iter != ino_locations.end()) { Location const &loc = iter->second; if (!path.empty()) { path = loc.second + "/" + path; } else { path = loc.second + path; } iter = ino_locations.find(loc.first); } paths.push_back(path); } } void EMetaBlob::dump(Formatter *f) const { f->open_array_section("lumps"); for (const auto& d : lump_order) { f->open_object_section("lump"); f->open_object_section("dirfrag"); f->dump_stream("dirfrag") << d; f->close_section(); // dirfrag f->open_object_section("dirlump"); lump_map.at(d).dump(f); f->close_section(); // dirlump f->close_section(); // lump } f->close_section(); // lumps f->open_array_section("roots"); for (const auto& iter : roots) { f->open_object_section("root"); iter.dump(f); f->close_section(); // root } f->close_section(); // roots f->open_array_section("tableclient tranactions"); for (const auto& p : table_tids) { f->open_object_section("transaction"); f->dump_int("tid", p.first); f->dump_int("version", p.second); f->close_section(); // transaction } f->close_section(); // tableclient transactions f->dump_int("renamed directory inodeno", renamed_dirino); f->open_array_section("renamed directory fragments"); for (const auto& p : renamed_dir_frags) { f->dump_int("frag", p); } f->close_section(); // renamed directory fragments f->dump_int("inotable version", inotablev); f->dump_int("SessionMap version", sessionmapv); f->dump_int("allocated ino", allocated_ino); f->dump_stream("preallocated inos") << preallocated_inos; f->dump_int("used preallocated ino", used_preallocated_ino); f->open_object_section("client name"); client_name.dump(f); f->close_section(); // client name f->open_array_section("inodes starting a truncate"); for(const auto& ino : truncate_start) { f->dump_int("inodeno", ino); } f->close_section(); // truncate inodes f->open_array_section("inodes finishing a truncated"); for(const auto& p : truncate_finish) { f->open_object_section("inode+segment"); f->dump_int("inodeno", p.first); f->dump_int("truncate starting segment", p.second); f->close_section(); // truncated inode } f->close_section(); // truncate finish inodes f->open_array_section("destroyed inodes"); for(vector<inodeno_t>::const_iterator i = destroyed_inodes.begin(); i != destroyed_inodes.end(); ++i) { f->dump_int("inodeno", *i); } f->close_section(); // destroyed inodes f->open_array_section("client requests"); for(const auto& p : client_reqs) { f->open_object_section("Client request"); f->dump_stream("request ID") << p.first; f->dump_int("oldest request on client", p.second); f->close_section(); // request } f->close_section(); // client requests } void EMetaBlob::generate_test_instances(std::list<EMetaBlob*>& ls) { ls.push_back(new EMetaBlob()); } void EMetaBlob::replay(MDSRank *mds, LogSegment *logseg, int type, MDPeerUpdate *peerup) { dout(10) << "EMetaBlob.replay " << lump_map.size() << " dirlumps by " << client_name << dendl; ceph_assert(logseg); ceph_assert(g_conf()->mds_kill_journal_replay_at != 1); for (auto& p : roots) { CInode *in = mds->mdcache->get_inode(p.inode->ino); bool isnew = in ? false:true; if (!in) in = new CInode(mds->mdcache, false, 2, CEPH_NOSNAP); p.update_inode(mds, in); if (isnew) mds->mdcache->add_inode(in); if (p.is_dirty()) in->_mark_dirty(logseg); dout(10) << "EMetaBlob.replay " << (isnew ? " added root ":" updated root ") << *in << dendl; } CInode *renamed_diri = 0; CDir *olddir = 0; if (renamed_dirino) { renamed_diri = mds->mdcache->get_inode(renamed_dirino); if (renamed_diri) dout(10) << "EMetaBlob.replay renamed inode is " << *renamed_diri << dendl; else dout(10) << "EMetaBlob.replay don't have renamed ino " << renamed_dirino << dendl; int nnull = 0; for (const auto& lp : lump_order) { dirlump &lump = lump_map[lp]; if (lump.nnull) { dout(10) << "EMetaBlob.replay found null dentry in dir " << lp << dendl; nnull += lump.nnull; } } ceph_assert(nnull <= 1); } // keep track of any inodes we unlink and don't relink elsewhere map<CInode*, CDir*> unlinked; set<CInode*> linked; // walk through my dirs (in order!) int count = 0; for (const auto& lp : lump_order) { dout(10) << "EMetaBlob.replay dir " << lp << dendl; dirlump &lump = lump_map[lp]; // the dir CDir *dir = mds->mdcache->get_force_dirfrag(lp, true); if (!dir) { // hmm. do i have the inode? CInode *diri = mds->mdcache->get_inode((lp).ino); if (!diri) { if (MDS_INO_IS_MDSDIR(lp.ino)) { ceph_assert(MDS_INO_MDSDIR(mds->get_nodeid()) != lp.ino); diri = mds->mdcache->create_system_inode(lp.ino, S_IFDIR|0755); diri->state_clear(CInode::STATE_AUTH); dout(10) << "EMetaBlob.replay created base " << *diri << dendl; } else { dout(0) << "EMetaBlob.replay missing dir ino " << lp.ino << dendl; mds->clog->error() << "failure replaying journal (EMetaBlob)"; mds->damaged(); ceph_abort(); // Should be unreachable because damaged() calls respawn() } } // create the dirfrag dir = diri->get_or_open_dirfrag(mds->mdcache, lp.frag); if (MDS_INO_IS_BASE(lp.ino)) mds->mdcache->adjust_subtree_auth(dir, CDIR_AUTH_UNDEF); dout(10) << "EMetaBlob.replay added dir " << *dir << dendl; } dir->reset_fnode(std::move(lump.fnode)); dir->update_projected_version(); if (lump.is_importing()) { dir->state_set(CDir::STATE_AUTH); dir->state_clear(CDir::STATE_COMPLETE); } if (lump.is_dirty()) { dir->_mark_dirty(logseg); if (!(dir->get_fnode()->rstat == dir->get_fnode()->accounted_rstat)) { dout(10) << "EMetaBlob.replay dirty nestinfo on " << *dir << dendl; mds->locker->mark_updated_scatterlock(&dir->inode->nestlock); logseg->dirty_dirfrag_nest.push_back(&dir->inode->item_dirty_dirfrag_nest); } else { dout(10) << "EMetaBlob.replay clean nestinfo on " << *dir << dendl; } if (!(dir->get_fnode()->fragstat == dir->get_fnode()->accounted_fragstat)) { dout(10) << "EMetaBlob.replay dirty fragstat on " << *dir << dendl; mds->locker->mark_updated_scatterlock(&dir->inode->filelock); logseg->dirty_dirfrag_dir.push_back(&dir->inode->item_dirty_dirfrag_dir); } else { dout(10) << "EMetaBlob.replay clean fragstat on " << *dir << dendl; } } if (lump.is_dirty_dft()) { dout(10) << "EMetaBlob.replay dirty dirfragtree on " << *dir << dendl; dir->state_set(CDir::STATE_DIRTYDFT); mds->locker->mark_updated_scatterlock(&dir->inode->dirfragtreelock); logseg->dirty_dirfrag_dirfragtree.push_back(&dir->inode->item_dirty_dirfrag_dirfragtree); } if (lump.is_new()) dir->mark_new(logseg); if (lump.is_complete()) dir->mark_complete(); dout(10) << "EMetaBlob.replay updated dir " << *dir << dendl; // decode bits lump._decode_bits(); // full dentry+inode pairs for (auto& fb : lump._get_dfull()) { CDentry *dn = dir->lookup_exact_snap(fb.dn, fb.dnlast); if (!dn) { dn = dir->add_null_dentry(fb.dn, fb.dnfirst, fb.dnlast); dn->set_version(fb.dnv); if (fb.is_dirty()) dn->_mark_dirty(logseg); dout(10) << "EMetaBlob.replay added (full) " << *dn << dendl; } else { dn->set_version(fb.dnv); if (fb.is_dirty()) dn->_mark_dirty(logseg); dout(10) << "EMetaBlob.replay for [" << fb.dnfirst << "," << fb.dnlast << "] had " << *dn << dendl; dn->first = fb.dnfirst; ceph_assert(dn->last == fb.dnlast); } if (lump.is_importing()) dn->mark_auth(); CInode *in = mds->mdcache->get_inode(fb.inode->ino, fb.dnlast); if (!in) { in = new CInode(mds->mdcache, dn->is_auth(), fb.dnfirst, fb.dnlast); fb.update_inode(mds, in); mds->mdcache->add_inode(in); if (!dn->get_linkage()->is_null()) { if (dn->get_linkage()->is_primary()) { unlinked[dn->get_linkage()->get_inode()] = dir; CachedStackStringStream css; *css << "EMetaBlob.replay FIXME had dentry linked to wrong inode " << *dn << " " << *dn->get_linkage()->get_inode() << " should be " << in->ino(); dout(0) << css->strv() << dendl; mds->clog->warn() << css->strv(); } dir->unlink_inode(dn, false); } if (unlinked.count(in)) linked.insert(in); dir->link_primary_inode(dn, in); dout(10) << "EMetaBlob.replay added " << *in << dendl; } else { in->first = fb.dnfirst; fb.update_inode(mds, in); if (dn->get_linkage()->get_inode() != in && in->get_parent_dn()) { dout(10) << "EMetaBlob.replay unlinking " << *in << dendl; unlinked[in] = in->get_parent_dir(); in->get_parent_dir()->unlink_inode(in->get_parent_dn()); } if (dn->get_linkage()->get_inode() != in) { if (!dn->get_linkage()->is_null()) { // note: might be remote. as with stray reintegration. if (dn->get_linkage()->is_primary()) { unlinked[dn->get_linkage()->get_inode()] = dir; CachedStackStringStream css; *css << "EMetaBlob.replay FIXME had dentry linked to wrong inode " << *dn << " " << *dn->get_linkage()->get_inode() << " should be " << in->ino(); dout(0) << css->strv() << dendl; mds->clog->warn() << css->strv(); } dir->unlink_inode(dn, false); } if (unlinked.count(in)) linked.insert(in); dir->link_primary_inode(dn, in); dout(10) << "EMetaBlob.replay linked " << *in << dendl; } else { dout(10) << "EMetaBlob.replay for [" << fb.dnfirst << "," << fb.dnlast << "] had " << *in << dendl; } ceph_assert(in->first == fb.dnfirst || (in->is_multiversion() && in->first > fb.dnfirst)); } if (fb.is_dirty()) in->_mark_dirty(logseg); if (fb.is_dirty_parent()) in->mark_dirty_parent(logseg, fb.is_dirty_pool()); if (fb.need_snapflush()) logseg->open_files.push_back(&in->item_open_file); if (dn->is_auth()) in->state_set(CInode::STATE_AUTH); else in->state_clear(CInode::STATE_AUTH); ceph_assert(g_conf()->mds_kill_journal_replay_at != 2); { auto do_corruption = mds->get_inject_journal_corrupt_dentry_first(); if (unlikely(do_corruption > 0.0)) { auto r = ceph::util::generate_random_number(0.0, 1.0); if (r < do_corruption) { dout(0) << "corrupting dn: " << *dn << dendl; dn->first = -10; } } } if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } // remote dentries for (const auto& rb : lump.get_dremote()) { CDentry *dn = dir->lookup_exact_snap(rb.dn, rb.dnlast); if (!dn) { dn = dir->add_remote_dentry(rb.dn, rb.ino, rb.d_type, mempool::mds_co::string(rb.alternate_name), rb.dnfirst, rb.dnlast); dn->set_version(rb.dnv); if (rb.dirty) dn->_mark_dirty(logseg); dout(10) << "EMetaBlob.replay added " << *dn << dendl; } else { if (!dn->get_linkage()->is_null()) { dout(10) << "EMetaBlob.replay unlinking " << *dn << dendl; if (dn->get_linkage()->is_primary()) { unlinked[dn->get_linkage()->get_inode()] = dir; CachedStackStringStream css; *css << "EMetaBlob.replay FIXME had dentry linked to wrong inode " << *dn << " " << *dn->get_linkage()->get_inode() << " should be remote " << rb.ino; dout(0) << css->strv() << dendl; } dir->unlink_inode(dn, false); } dn->set_alternate_name(mempool::mds_co::string(rb.alternate_name)); dir->link_remote_inode(dn, rb.ino, rb.d_type); dn->set_version(rb.dnv); if (rb.dirty) dn->_mark_dirty(logseg); dout(10) << "EMetaBlob.replay for [" << rb.dnfirst << "," << rb.dnlast << "] had " << *dn << dendl; dn->first = rb.dnfirst; ceph_assert(dn->last == rb.dnlast); } if (lump.is_importing()) dn->mark_auth(); if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } // null dentries for (const auto& nb : lump.get_dnull()) { CDentry *dn = dir->lookup_exact_snap(nb.dn, nb.dnlast); if (!dn) { dn = dir->add_null_dentry(nb.dn, nb.dnfirst, nb.dnlast); dn->set_version(nb.dnv); if (nb.dirty) dn->_mark_dirty(logseg); dout(10) << "EMetaBlob.replay added (nullbit) " << *dn << dendl; } else { dn->first = nb.dnfirst; if (!dn->get_linkage()->is_null()) { dout(10) << "EMetaBlob.replay unlinking " << *dn << dendl; CInode *in = dn->get_linkage()->get_inode(); // For renamed inode, We may call CInode::force_dirfrag() later. // CInode::force_dirfrag() doesn't work well when inode is detached // from the hierarchy. if (!renamed_diri || renamed_diri != in) { if (dn->get_linkage()->is_primary()) unlinked[in] = dir; dir->unlink_inode(dn); } } dn->set_version(nb.dnv); if (nb.dirty) dn->_mark_dirty(logseg); dout(10) << "EMetaBlob.replay had " << *dn << dendl; ceph_assert(dn->last == nb.dnlast); } olddir = dir; if (lump.is_importing()) dn->mark_auth(); // Make null dentries the first things we trim dout(10) << "EMetaBlob.replay pushing to bottom of lru " << *dn << dendl; if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } } ceph_assert(g_conf()->mds_kill_journal_replay_at != 3); if (renamed_dirino) { if (renamed_diri) { ceph_assert(unlinked.count(renamed_diri)); ceph_assert(linked.count(renamed_diri)); olddir = unlinked[renamed_diri]; } else { // we imported a diri we haven't seen before renamed_diri = mds->mdcache->get_inode(renamed_dirino); ceph_assert(renamed_diri); // it was in the metablob } if (olddir) { if (olddir->authority() != CDIR_AUTH_UNDEF && renamed_diri->authority() == CDIR_AUTH_UNDEF) { ceph_assert(peerup); // auth to non-auth, must be peer prepare frag_vec_t leaves; renamed_diri->dirfragtree.get_leaves(leaves); for (const auto& leaf : leaves) { CDir *dir = renamed_diri->get_dirfrag(leaf); ceph_assert(dir); if (dir->get_dir_auth() == CDIR_AUTH_UNDEF) // preserve subtree bound until peer commit peerup->olddirs.insert(dir->inode); else dir->state_set(CDir::STATE_AUTH); if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } } mds->mdcache->adjust_subtree_after_rename(renamed_diri, olddir, false); // see if we can discard the subtree we renamed out of CDir *root = mds->mdcache->get_subtree_root(olddir); if (root->get_dir_auth() == CDIR_AUTH_UNDEF) { if (peerup) // preserve the old dir until peer commit peerup->olddirs.insert(olddir->inode); else mds->mdcache->try_trim_non_auth_subtree(root); } } // if we are the srci importer, we'll also have some dirfrags we have to open up... if (renamed_diri->authority() != CDIR_AUTH_UNDEF) { for (const auto& p : renamed_dir_frags) { CDir *dir = renamed_diri->get_dirfrag(p); if (dir) { // we already had the inode before, and we already adjusted this subtree accordingly. dout(10) << " already had+adjusted rename import bound " << *dir << dendl; ceph_assert(olddir); continue; } dir = renamed_diri->get_or_open_dirfrag(mds->mdcache, p); dout(10) << " creating new rename import bound " << *dir << dendl; dir->state_clear(CDir::STATE_AUTH); mds->mdcache->adjust_subtree_auth(dir, CDIR_AUTH_UNDEF); if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } } // rename may overwrite an empty directory and move it into stray dir. unlinked.erase(renamed_diri); for (map<CInode*, CDir*>::iterator p = unlinked.begin(); p != unlinked.end(); ++p) { if (!linked.count(p->first)) continue; ceph_assert(p->first->is_dir()); mds->mdcache->adjust_subtree_after_rename(p->first, p->second, false); if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } } if (!unlinked.empty()) { for (set<CInode*>::iterator p = linked.begin(); p != linked.end(); ++p) unlinked.erase(*p); dout(10) << " unlinked set contains " << unlinked << dendl; for (map<CInode*, CDir*>::iterator p = unlinked.begin(); p != unlinked.end(); ++p) { CInode *in = p->first; if (peerup) { // preserve unlinked inodes until peer commit peerup->unlinked.insert(in); if (in->snaprealm) in->snaprealm->adjust_parent(); } else mds->mdcache->remove_inode_recursive(in); if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } } // table client transactions for (const auto& p : table_tids) { dout(10) << "EMetaBlob.replay noting " << get_mdstable_name(p.first) << " transaction " << p.second << dendl; MDSTableClient *client = mds->get_table_client(p.first); if (client) client->got_journaled_agree(p.second, logseg); if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } // opened ino? if (opened_ino) { CInode *in = mds->mdcache->get_inode(opened_ino); ceph_assert(in); dout(10) << "EMetaBlob.replay noting opened inode " << *in << dendl; logseg->open_files.push_back(&in->item_open_file); } bool skip_replaying_inotable = g_conf()->mds_inject_skip_replaying_inotable; // allocated_inos if (inotablev) { if (mds->inotable->get_version() >= inotablev || unlikely(type == EVENT_UPDATE && skip_replaying_inotable)) { dout(10) << "EMetaBlob.replay inotable tablev " << inotablev << " <= table " << mds->inotable->get_version() << dendl; if (allocated_ino) mds->mdcache->insert_taken_inos(allocated_ino); } else { dout(10) << "EMetaBlob.replay inotable v " << inotablev << " - 1 == table " << mds->inotable->get_version() << " allocated+used " << allocated_ino << " prealloc " << preallocated_inos << dendl; if (allocated_ino) mds->inotable->replay_alloc_id(allocated_ino); if (preallocated_inos.size()) mds->inotable->replay_alloc_ids(preallocated_inos); // repair inotable updates in case inotable wasn't persist in time if (inotablev > mds->inotable->get_version()) { mds->clog->error() << "journal replay inotablev mismatch " << mds->inotable->get_version() << " -> " << inotablev << ", will force replay it."; mds->inotable->force_replay_version(inotablev); } ceph_assert(inotablev == mds->inotable->get_version()); } } if (sessionmapv) { if (mds->sessionmap.get_version() >= sessionmapv || unlikely(type == EVENT_UPDATE && skip_replaying_inotable)) { dout(10) << "EMetaBlob.replay sessionmap v " << sessionmapv << " <= table " << mds->sessionmap.get_version() << dendl; if (used_preallocated_ino) mds->mdcache->insert_taken_inos(used_preallocated_ino); } else { dout(10) << "EMetaBlob.replay sessionmap v " << sessionmapv << ", table " << mds->sessionmap.get_version() << " prealloc " << preallocated_inos << " used " << used_preallocated_ino << dendl; Session *session = mds->sessionmap.get_session(client_name); if (session) { dout(20) << " (session prealloc " << session->info.prealloc_inos << ")" << dendl; if (used_preallocated_ino) { if (!session->info.prealloc_inos.empty()) { inodeno_t ino = session->take_ino(used_preallocated_ino); session->info.prealloc_inos.erase(ino); ceph_assert(ino == used_preallocated_ino); } mds->sessionmap.replay_dirty_session(session); } if (!preallocated_inos.empty()) { session->free_prealloc_inos.insert(preallocated_inos); session->info.prealloc_inos.insert(preallocated_inos); mds->sessionmap.replay_dirty_session(session); } } else { dout(10) << "EMetaBlob.replay no session for " << client_name << dendl; if (used_preallocated_ino) mds->sessionmap.replay_advance_version(); if (!preallocated_inos.empty()) mds->sessionmap.replay_advance_version(); } // repair sessionmap updates in case sessionmap wasn't persist in time if (sessionmapv > mds->sessionmap.get_version()) { mds->clog->error() << "EMetaBlob.replay sessionmapv mismatch " << sessionmapv << " -> " << mds->sessionmap.get_version() << ", will force replay it."; if (g_conf()->mds_wipe_sessions) { mds->sessionmap.wipe(); } // force replay sessionmap version mds->sessionmap.set_version(sessionmapv); } ceph_assert(sessionmapv == mds->sessionmap.get_version()); } } // truncating inodes for (const auto& ino : truncate_start) { CInode *in = mds->mdcache->get_inode(ino); ceph_assert(in); mds->mdcache->add_recovered_truncate(in, logseg); if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } for (const auto& p : truncate_finish) { LogSegment *ls = mds->mdlog->get_segment(p.second); if (ls) { CInode *in = mds->mdcache->get_inode(p.first); ceph_assert(in); mds->mdcache->remove_recovered_truncate(in, ls); } if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } // destroyed inodes if (!destroyed_inodes.empty()) { for (vector<inodeno_t>::iterator p = destroyed_inodes.begin(); p != destroyed_inodes.end(); ++p) { CInode *in = mds->mdcache->get_inode(*p); if (in) { dout(10) << "EMetaBlob.replay destroyed " << *p << ", dropping " << *in << dendl; CDentry *parent = in->get_parent_dn(); mds->mdcache->remove_inode(in); if (parent) { dout(10) << "EMetaBlob.replay unlinked from dentry " << *parent << dendl; ceph_assert(parent->get_linkage()->is_null()); } } else { dout(10) << "EMetaBlob.replay destroyed " << *p << ", not in cache" << dendl; } if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } mds->mdcache->open_file_table.note_destroyed_inos(logseg->seq, destroyed_inodes); } // client requests for (const auto& p : client_reqs) { if (p.first.name.is_client()) { dout(10) << "EMetaBlob.replay request " << p.first << " trim_to " << p.second << dendl; inodeno_t created = allocated_ino ? allocated_ino : used_preallocated_ino; // if we allocated an inode, there should be exactly one client request id. ceph_assert(created == inodeno_t() || client_reqs.size() == 1); Session *session = mds->sessionmap.get_session(p.first.name); if (session) { session->add_completed_request(p.first.tid, created); if (p.second) session->trim_completed_requests(p.second); } } if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } // client flushes for (const auto& p : client_flushes) { if (p.first.name.is_client()) { dout(10) << "EMetaBlob.replay flush " << p.first << " trim_to " << p.second << dendl; Session *session = mds->sessionmap.get_session(p.first.name); if (session) { session->add_completed_flush(p.first.tid); if (p.second) session->trim_completed_flushes(p.second); } } if (!(++count % mds->heartbeat_reset_grace())) mds->heartbeat_reset(); } // update segment update_segment(logseg); ceph_assert(g_conf()->mds_kill_journal_replay_at != 4); } // ----------------------- // EPurged void EPurged::update_segment() { if (inos.size() && inotablev) get_segment()->inotablev = inotablev; return; } void EPurged::replay(MDSRank *mds) { if (inos.size()) { LogSegment *ls = mds->mdlog->get_segment(seq); if (ls) ls->purging_inodes.subtract(inos); if (mds->inotable->get_version() >= inotablev) { dout(10) << "EPurged.replay inotable " << mds->inotable->get_version() << " >= " << inotablev << ", noop" << dendl; } else { dout(10) << "EPurged.replay inotable " << mds->inotable->get_version() << " < " << inotablev << " " << dendl; mds->inotable->replay_release_ids(inos); ceph_assert(mds->inotable->get_version() == inotablev); } } update_segment(); } void EPurged::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(1, 1, bl); encode(inos, bl); encode(inotablev, bl); encode(seq, bl); ENCODE_FINISH(bl); } void EPurged::decode(bufferlist::const_iterator& bl) { DECODE_START(1, bl); decode(inos, bl); decode(inotablev, bl); decode(seq, bl); DECODE_FINISH(bl); } void EPurged::dump(Formatter *f) const { f->dump_stream("inos") << inos; f->dump_int("inotable version", inotablev); f->dump_int("segment seq", seq); } // ----------------------- // ESession void ESession::update_segment() { get_segment()->sessionmapv = cmapv; if (inos_to_free.size() && inotablev) get_segment()->inotablev = inotablev; } void ESession::replay(MDSRank *mds) { if (inos_to_purge.size()) get_segment()->purging_inodes.insert(inos_to_purge); if (mds->sessionmap.get_version() >= cmapv) { dout(10) << "ESession.replay sessionmap " << mds->sessionmap.get_version() << " >= " << cmapv << ", noop" << dendl; } else if (mds->sessionmap.get_version() + 1 == cmapv) { dout(10) << "ESession.replay sessionmap " << mds->sessionmap.get_version() << " < " << cmapv << " " << (open ? "open":"close") << " " << client_inst << dendl; Session *session; if (open) { session = mds->sessionmap.get_or_add_session(client_inst); mds->sessionmap.set_state(session, Session::STATE_OPEN); session->set_client_metadata(client_metadata); dout(10) << " opened session " << session->info.inst << dendl; } else { session = mds->sessionmap.get_session(client_inst.name); if (session) { // there always should be a session, but there's a bug if (session->get_connection() == NULL) { dout(10) << " removed session " << session->info.inst << dendl; mds->sessionmap.remove_session(session); session = NULL; } else { session->clear(); // the client has reconnected; keep the Session, but reset dout(10) << " reset session " << session->info.inst << " (they reconnected)" << dendl; } } else { mds->clog->error() << "replayed stray Session close event for " << client_inst << " from time " << stamp << ", ignoring"; } } if (session) { mds->sessionmap.replay_dirty_session(session); } else { mds->sessionmap.replay_advance_version(); } ceph_assert(mds->sessionmap.get_version() == cmapv); } else { mds->clog->error() << "ESession.replay sessionmap v " << cmapv << " - 1 > table " << mds->sessionmap.get_version(); ceph_assert(g_conf()->mds_wipe_sessions); mds->sessionmap.wipe(); mds->sessionmap.set_version(cmapv); } if (inos_to_free.size() && inotablev) { if (mds->inotable->get_version() >= inotablev) { dout(10) << "ESession.replay inotable " << mds->inotable->get_version() << " >= " << inotablev << ", noop" << dendl; } else { dout(10) << "ESession.replay inotable " << mds->inotable->get_version() << " < " << inotablev << " " << (open ? "add":"remove") << dendl; ceph_assert(!open); // for now mds->inotable->replay_release_ids(inos_to_free); ceph_assert(mds->inotable->get_version() == inotablev); } } update_segment(); } void ESession::encode(bufferlist &bl, uint64_t features) const { ENCODE_START(6, 5, bl); encode(stamp, bl); encode(client_inst, bl, features); encode(open, bl); encode(cmapv, bl); encode(inos_to_free, bl); encode(inotablev, bl); encode(client_metadata, bl); encode(inos_to_purge, bl); ENCODE_FINISH(bl); } void ESession::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(6, 3, 3, bl); if (struct_v >= 2) decode(stamp, bl); decode(client_inst, bl); decode(open, bl); decode(cmapv, bl); decode(inos_to_free, bl); decode(inotablev, bl); if (struct_v == 4) { decode(client_metadata.kv_map, bl); } else if (struct_v >= 5) { decode(client_metadata, bl); } if (struct_v >= 6){ decode(inos_to_purge, bl); } DECODE_FINISH(bl); } void ESession::dump(Formatter *f) const { f->dump_stream("client instance") << client_inst; f->dump_string("open", open ? "true" : "false"); f->dump_int("client map version", cmapv); f->dump_stream("inos_to_free") << inos_to_free; f->dump_int("inotable version", inotablev); f->open_object_section("client_metadata"); f->dump_stream("inos_to_purge") << inos_to_purge; client_metadata.dump(f); f->close_section(); // client_metadata } void ESession::generate_test_instances(std::list<ESession*>& ls) { ls.push_back(new ESession); } // ----------------------- // ESessions void ESessions::encode(bufferlist &bl, uint64_t features) const { ENCODE_START(2, 1, bl); encode(client_map, bl, features); encode(cmapv, bl); encode(stamp, bl); encode(client_metadata_map, bl); ENCODE_FINISH(bl); } void ESessions::decode_old(bufferlist::const_iterator &bl) { using ceph::decode; decode(client_map, bl); decode(cmapv, bl); if (!bl.end()) decode(stamp, bl); } void ESessions::decode_new(bufferlist::const_iterator &bl) { DECODE_START(2, bl); decode(client_map, bl); decode(cmapv, bl); decode(stamp, bl); if (struct_v >= 2) decode(client_metadata_map, bl); DECODE_FINISH(bl); } void ESessions::dump(Formatter *f) const { f->dump_int("client map version", cmapv); f->open_array_section("client map"); for (map<client_t,entity_inst_t>::const_iterator i = client_map.begin(); i != client_map.end(); ++i) { f->open_object_section("client"); f->dump_int("client id", i->first.v); f->dump_stream("client entity") << i->second; f->close_section(); // client } f->close_section(); // client map } void ESessions::generate_test_instances(std::list<ESessions*>& ls) { ls.push_back(new ESessions()); } void ESessions::update_segment() { get_segment()->sessionmapv = cmapv; } void ESessions::replay(MDSRank *mds) { if (mds->sessionmap.get_version() >= cmapv) { dout(10) << "ESessions.replay sessionmap " << mds->sessionmap.get_version() << " >= " << cmapv << ", noop" << dendl; } else { dout(10) << "ESessions.replay sessionmap " << mds->sessionmap.get_version() << " < " << cmapv << dendl; mds->sessionmap.replay_open_sessions(cmapv, client_map, client_metadata_map); } update_segment(); } // ----------------------- // ETableServer void ETableServer::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(3, 3, bl); encode(stamp, bl); encode(table, bl); encode(op, bl); encode(reqid, bl); encode(bymds, bl); encode(mutation, bl); encode(tid, bl); encode(version, bl); ENCODE_FINISH(bl); } void ETableServer::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl); if (struct_v >= 2) decode(stamp, bl); decode(table, bl); decode(op, bl); decode(reqid, bl); decode(bymds, bl); decode(mutation, bl); decode(tid, bl); decode(version, bl); DECODE_FINISH(bl); } void ETableServer::dump(Formatter *f) const { f->dump_int("table id", table); f->dump_int("op", op); f->dump_int("request id", reqid); f->dump_int("by mds", bymds); f->dump_int("tid", tid); f->dump_int("version", version); } void ETableServer::generate_test_instances(std::list<ETableServer*>& ls) { ls.push_back(new ETableServer()); } void ETableServer::update_segment() { get_segment()->tablev[table] = version; } void ETableServer::replay(MDSRank *mds) { MDSTableServer *server = mds->get_table_server(table); if (!server) return; if (server->get_version() >= version) { dout(10) << "ETableServer.replay " << get_mdstable_name(table) << " " << get_mdstableserver_opname(op) << " event " << version << " <= table " << server->get_version() << dendl; return; } dout(10) << " ETableServer.replay " << get_mdstable_name(table) << " " << get_mdstableserver_opname(op) << " event " << version << " - 1 == table " << server->get_version() << dendl; ceph_assert(version-1 == server->get_version()); switch (op) { case TABLESERVER_OP_PREPARE: { server->_note_prepare(bymds, reqid, true); bufferlist out; server->_prepare(mutation, reqid, bymds, out); mutation = std::move(out); break; } case TABLESERVER_OP_COMMIT: server->_commit(tid, ref_t<MMDSTableRequest>()); server->_note_commit(tid, true); break; case TABLESERVER_OP_ROLLBACK: server->_rollback(tid); server->_note_rollback(tid, true); break; case TABLESERVER_OP_SERVER_UPDATE: server->_server_update(mutation); server->_note_server_update(mutation, true); break; default: mds->clog->error() << "invalid tableserver op in ETableServer"; mds->damaged(); ceph_abort(); // Should be unreachable because damaged() calls respawn() } ceph_assert(version == server->get_version()); update_segment(); } // --------------------- // ETableClient void ETableClient::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(3, 3, bl); encode(stamp, bl); encode(table, bl); encode(op, bl); encode(tid, bl); ENCODE_FINISH(bl); } void ETableClient::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl); if (struct_v >= 2) decode(stamp, bl); decode(table, bl); decode(op, bl); decode(tid, bl); DECODE_FINISH(bl); } void ETableClient::dump(Formatter *f) const { f->dump_int("table", table); f->dump_int("op", op); f->dump_int("tid", tid); } void ETableClient::generate_test_instances(std::list<ETableClient*>& ls) { ls.push_back(new ETableClient()); } void ETableClient::replay(MDSRank *mds) { dout(10) << " ETableClient.replay " << get_mdstable_name(table) << " op " << get_mdstableserver_opname(op) << " tid " << tid << dendl; MDSTableClient *client = mds->get_table_client(table); if (!client) return; ceph_assert(op == TABLESERVER_OP_ACK); client->got_journaled_ack(tid); } // ----------------------- // ESnap /* void ESnap::update_segment() { get_segment()->tablev[TABLE_SNAP] = version; } void ESnap::replay(MDSRank *mds) { if (mds->snaptable->get_version() >= version) { dout(10) << "ESnap.replay event " << version << " <= table " << mds->snaptable->get_version() << dendl; return; } dout(10) << " ESnap.replay event " << version << " - 1 == table " << mds->snaptable->get_version() << dendl; ceph_assert(version-1 == mds->snaptable->get_version()); if (create) { version_t v; snapid_t s = mds->snaptable->create(snap.dirino, snap.name, snap.stamp, &v); ceph_assert(s == snap.snapid); } else { mds->snaptable->remove(snap.snapid); } ceph_assert(version == mds->snaptable->get_version()); } */ // ----------------------- // EUpdate void EUpdate::encode(bufferlist &bl, uint64_t features) const { ENCODE_START(4, 4, bl); encode(stamp, bl); encode(type, bl); encode(metablob, bl, features); encode(client_map, bl); encode(cmapv, bl); encode(reqid, bl); encode(had_peers, bl); ENCODE_FINISH(bl); } void EUpdate::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(4, 4, 4, bl); if (struct_v >= 2) decode(stamp, bl); decode(type, bl); decode(metablob, bl); decode(client_map, bl); if (struct_v >= 3) decode(cmapv, bl); decode(reqid, bl); decode(had_peers, bl); DECODE_FINISH(bl); } void EUpdate::dump(Formatter *f) const { f->open_object_section("metablob"); metablob.dump(f); f->close_section(); // metablob f->dump_string("type", type); f->dump_int("client map length", client_map.length()); f->dump_int("client map version", cmapv); f->dump_stream("reqid") << reqid; f->dump_string("had peers", had_peers ? "true" : "false"); } void EUpdate::generate_test_instances(std::list<EUpdate*>& ls) { ls.push_back(new EUpdate()); } void EUpdate::update_segment() { auto&& segment = get_segment(); metablob.update_segment(segment); if (client_map.length()) segment->sessionmapv = cmapv; if (had_peers) segment->uncommitted_leaders.insert(reqid); } void EUpdate::replay(MDSRank *mds) { auto&& segment = get_segment(); dout(10) << "EUpdate::replay" << dendl; metablob.replay(mds, segment, EVENT_UPDATE); if (had_peers) { dout(10) << "EUpdate.replay " << reqid << " had peers, expecting a matching ECommitted" << dendl; segment->uncommitted_leaders.insert(reqid); set<mds_rank_t> peers; mds->mdcache->add_uncommitted_leader(reqid, segment, peers, true); } if (client_map.length()) { if (mds->sessionmap.get_version() >= cmapv) { dout(10) << "EUpdate.replay sessionmap v " << cmapv << " <= table " << mds->sessionmap.get_version() << dendl; } else { dout(10) << "EUpdate.replay sessionmap " << mds->sessionmap.get_version() << " < " << cmapv << dendl; // open client sessions? map<client_t,entity_inst_t> cm; map<client_t,client_metadata_t> cmm; auto blp = client_map.cbegin(); using ceph::decode; decode(cm, blp); if (!blp.end()) decode(cmm, blp); mds->sessionmap.replay_open_sessions(cmapv, cm, cmm); } } update_segment(); } // ------------------------ // EOpen void EOpen::encode(bufferlist &bl, uint64_t features) const { ENCODE_START(4, 3, bl); encode(stamp, bl); encode(metablob, bl, features); encode(inos, bl); encode(snap_inos, bl); ENCODE_FINISH(bl); } void EOpen::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl); if (struct_v >= 2) decode(stamp, bl); decode(metablob, bl); decode(inos, bl); if (struct_v >= 4) decode(snap_inos, bl); DECODE_FINISH(bl); } void EOpen::dump(Formatter *f) const { f->open_object_section("metablob"); metablob.dump(f); f->close_section(); // metablob f->open_array_section("inos involved"); for (vector<inodeno_t>::const_iterator i = inos.begin(); i != inos.end(); ++i) { f->dump_int("ino", *i); } f->close_section(); // inos } void EOpen::generate_test_instances(std::list<EOpen*>& ls) { ls.push_back(new EOpen()); ls.push_back(new EOpen()); ls.back()->add_ino(0); } void EOpen::update_segment() { // ?? } void EOpen::replay(MDSRank *mds) { dout(10) << "EOpen.replay " << dendl; auto&& segment = get_segment(); metablob.replay(mds, segment, EVENT_OPEN); // note which segments inodes belong to, so we don't have to start rejournaling them for (const auto &ino : inos) { CInode *in = mds->mdcache->get_inode(ino); if (!in) { dout(0) << "EOpen.replay ino " << ino << " not in metablob" << dendl; ceph_assert(in); } segment->open_files.push_back(&in->item_open_file); } for (const auto &vino : snap_inos) { CInode *in = mds->mdcache->get_inode(vino); if (!in) { dout(0) << "EOpen.replay ino " << vino << " not in metablob" << dendl; ceph_assert(in); } segment->open_files.push_back(&in->item_open_file); } } // ----------------------- // ECommitted void ECommitted::replay(MDSRank *mds) { if (mds->mdcache->uncommitted_leaders.count(reqid)) { dout(10) << "ECommitted.replay " << reqid << dendl; mds->mdcache->uncommitted_leaders[reqid].ls->uncommitted_leaders.erase(reqid); mds->mdcache->uncommitted_leaders.erase(reqid); } else { dout(10) << "ECommitted.replay " << reqid << " -- didn't see original op" << dendl; } } void ECommitted::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(3, 3, bl); encode(stamp, bl); encode(reqid, bl); ENCODE_FINISH(bl); } void ECommitted::decode(bufferlist::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl); if (struct_v >= 2) decode(stamp, bl); decode(reqid, bl); DECODE_FINISH(bl); } void ECommitted::dump(Formatter *f) const { f->dump_stream("stamp") << stamp; f->dump_stream("reqid") << reqid; } void ECommitted::generate_test_instances(std::list<ECommitted*>& ls) { ls.push_back(new ECommitted); ls.push_back(new ECommitted); ls.back()->stamp = utime_t(1, 2); ls.back()->reqid = metareqid_t(entity_name_t::CLIENT(123), 456); } // ----------------------- // EPeerUpdate void link_rollback::encode(bufferlist &bl) const { ENCODE_START(3, 2, bl); encode(reqid, bl); encode(ino, bl); encode(was_inc, bl); encode(old_ctime, bl); encode(old_dir_mtime, bl); encode(old_dir_rctime, bl); encode(snapbl, bl); ENCODE_FINISH(bl); } void link_rollback::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); decode(reqid, bl); decode(ino, bl); decode(was_inc, bl); decode(old_ctime, bl); decode(old_dir_mtime, bl); decode(old_dir_rctime, bl); if (struct_v >= 3) decode(snapbl, bl); DECODE_FINISH(bl); } void link_rollback::dump(Formatter *f) const { f->dump_stream("metareqid") << reqid; f->dump_int("ino", ino); f->dump_string("was incremented", was_inc ? "true" : "false"); f->dump_stream("old_ctime") << old_ctime; f->dump_stream("old_dir_mtime") << old_dir_mtime; f->dump_stream("old_dir_rctime") << old_dir_rctime; } void link_rollback::generate_test_instances(std::list<link_rollback*>& ls) { ls.push_back(new link_rollback()); } void rmdir_rollback::encode(bufferlist& bl) const { ENCODE_START(3, 2, bl); encode(reqid, bl); encode(src_dir, bl); encode(src_dname, bl); encode(dest_dir, bl); encode(dest_dname, bl); encode(snapbl, bl); ENCODE_FINISH(bl); } void rmdir_rollback::decode(bufferlist::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); decode(reqid, bl); decode(src_dir, bl); decode(src_dname, bl); decode(dest_dir, bl); decode(dest_dname, bl); if (struct_v >= 3) decode(snapbl, bl); DECODE_FINISH(bl); } void rmdir_rollback::dump(Formatter *f) const { f->dump_stream("metareqid") << reqid; f->dump_stream("source directory") << src_dir; f->dump_string("source dname", src_dname); f->dump_stream("destination directory") << dest_dir; f->dump_string("destination dname", dest_dname); } void rmdir_rollback::generate_test_instances(std::list<rmdir_rollback*>& ls) { ls.push_back(new rmdir_rollback()); } void rename_rollback::drec::encode(bufferlist &bl) const { ENCODE_START(2, 2, bl); encode(dirfrag, bl); encode(dirfrag_old_mtime, bl); encode(dirfrag_old_rctime, bl); encode(ino, bl); encode(remote_ino, bl); encode(dname, bl); encode(remote_d_type, bl); encode(old_ctime, bl); ENCODE_FINISH(bl); } void rename_rollback::drec::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(dirfrag, bl); decode(dirfrag_old_mtime, bl); decode(dirfrag_old_rctime, bl); decode(ino, bl); decode(remote_ino, bl); decode(dname, bl); decode(remote_d_type, bl); decode(old_ctime, bl); DECODE_FINISH(bl); } void rename_rollback::drec::dump(Formatter *f) const { f->dump_stream("directory fragment") << dirfrag; f->dump_stream("directory old mtime") << dirfrag_old_mtime; f->dump_stream("directory old rctime") << dirfrag_old_rctime; f->dump_int("ino", ino); f->dump_int("remote ino", remote_ino); f->dump_string("dname", dname); uint32_t type = DTTOIF(remote_d_type) & S_IFMT; // convert to type entries string type_string; switch(type) { case S_IFREG: type_string = "file"; break; case S_IFLNK: type_string = "symlink"; break; case S_IFDIR: type_string = "directory"; break; default: type_string = "UNKNOWN-" + stringify((int)type); break; } f->dump_string("remote dtype", type_string); f->dump_stream("old ctime") << old_ctime; } void rename_rollback::drec::generate_test_instances(std::list<drec*>& ls) { ls.push_back(new drec()); ls.back()->remote_d_type = IFTODT(S_IFREG); } void rename_rollback::encode(bufferlist &bl) const { ENCODE_START(3, 2, bl); encode(reqid, bl); encode(orig_src, bl); encode(orig_dest, bl); encode(stray, bl); encode(ctime, bl); encode(srci_snapbl, bl); encode(desti_snapbl, bl); ENCODE_FINISH(bl); } void rename_rollback::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); decode(reqid, bl); decode(orig_src, bl); decode(orig_dest, bl); decode(stray, bl); decode(ctime, bl); if (struct_v >= 3) { decode(srci_snapbl, bl); decode(desti_snapbl, bl); } DECODE_FINISH(bl); } void rename_rollback::dump(Formatter *f) const { f->dump_stream("request id") << reqid; f->open_object_section("original src drec"); orig_src.dump(f); f->close_section(); // original src drec f->open_object_section("original dest drec"); orig_dest.dump(f); f->close_section(); // original dest drec f->open_object_section("stray drec"); stray.dump(f); f->close_section(); // stray drec f->dump_stream("ctime") << ctime; } void rename_rollback::generate_test_instances(std::list<rename_rollback*>& ls) { ls.push_back(new rename_rollback()); ls.back()->orig_src.remote_d_type = IFTODT(S_IFREG); ls.back()->orig_dest.remote_d_type = IFTODT(S_IFREG); ls.back()->stray.remote_d_type = IFTODT(S_IFREG); } void EPeerUpdate::encode(bufferlist &bl, uint64_t features) const { ENCODE_START(3, 3, bl); encode(stamp, bl); encode(type, bl); encode(reqid, bl); encode(leader, bl); encode(op, bl); encode(origop, bl); encode(commit, bl, features); encode(rollback, bl); ENCODE_FINISH(bl); } void EPeerUpdate::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl); if (struct_v >= 2) decode(stamp, bl); decode(type, bl); decode(reqid, bl); decode(leader, bl); decode(op, bl); decode(origop, bl); decode(commit, bl); decode(rollback, bl); DECODE_FINISH(bl); } void EPeerUpdate::dump(Formatter *f) const { f->open_object_section("metablob"); commit.dump(f); f->close_section(); // metablob f->dump_int("rollback length", rollback.length()); f->dump_string("type", type); f->dump_stream("metareqid") << reqid; f->dump_int("leader", leader); f->dump_int("op", op); f->dump_int("original op", origop); } void EPeerUpdate::generate_test_instances(std::list<EPeerUpdate*>& ls) { ls.push_back(new EPeerUpdate()); } void EPeerUpdate::replay(MDSRank *mds) { MDPeerUpdate *su; auto&& segment = get_segment(); switch (op) { case EPeerUpdate::OP_PREPARE: dout(10) << "EPeerUpdate.replay prepare " << reqid << " for mds." << leader << ": applying commit, saving rollback info" << dendl; su = new MDPeerUpdate(origop, rollback); commit.replay(mds, segment, EVENT_PEERUPDATE, su); mds->mdcache->add_uncommitted_peer(reqid, segment, leader, su); break; case EPeerUpdate::OP_COMMIT: dout(10) << "EPeerUpdate.replay commit " << reqid << " for mds." << leader << dendl; mds->mdcache->finish_uncommitted_peer(reqid, false); break; case EPeerUpdate::OP_ROLLBACK: dout(10) << "EPeerUpdate.replay abort " << reqid << " for mds." << leader << ": applying rollback commit blob" << dendl; commit.replay(mds, segment, EVENT_PEERUPDATE); mds->mdcache->finish_uncommitted_peer(reqid, false); break; default: mds->clog->error() << "invalid op in EPeerUpdate"; mds->damaged(); ceph_abort(); // Should be unreachable because damaged() calls respawn() } } // ----------------------- // ESubtreeMap void ESubtreeMap::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(6, 5, bl); encode(stamp, bl); encode(metablob, bl, features); encode(subtrees, bl); encode(ambiguous_subtrees, bl); encode(expire_pos, bl); encode(event_seq, bl); ENCODE_FINISH(bl); } void ESubtreeMap::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(6, 5, 5, bl); if (struct_v >= 2) decode(stamp, bl); decode(metablob, bl); decode(subtrees, bl); if (struct_v >= 4) decode(ambiguous_subtrees, bl); if (struct_v >= 3) decode(expire_pos, bl); if (struct_v >= 6) decode(event_seq, bl); DECODE_FINISH(bl); } void ESubtreeMap::dump(Formatter *f) const { f->open_object_section("metablob"); metablob.dump(f); f->close_section(); // metablob f->open_array_section("subtrees"); for(map<dirfrag_t,vector<dirfrag_t> >::const_iterator i = subtrees.begin(); i != subtrees.end(); ++i) { f->open_object_section("tree"); f->dump_stream("root dirfrag") << i->first; for (vector<dirfrag_t>::const_iterator j = i->second.begin(); j != i->second.end(); ++j) { f->dump_stream("bound dirfrag") << *j; } f->close_section(); // tree } f->close_section(); // subtrees f->open_array_section("ambiguous subtrees"); for(set<dirfrag_t>::const_iterator i = ambiguous_subtrees.begin(); i != ambiguous_subtrees.end(); ++i) { f->dump_stream("dirfrag") << *i; } f->close_section(); // ambiguous subtrees f->dump_int("expire position", expire_pos); } void ESubtreeMap::generate_test_instances(std::list<ESubtreeMap*>& ls) { ls.push_back(new ESubtreeMap()); } void ESubtreeMap::replay(MDSRank *mds) { if (expire_pos && expire_pos > mds->mdlog->journaler->get_expire_pos()) mds->mdlog->journaler->set_expire_pos(expire_pos); // suck up the subtree map? if (mds->mdcache->is_subtrees()) { dout(10) << "ESubtreeMap.replay -- i already have import map; verifying" << dendl; int errors = 0; for (map<dirfrag_t, vector<dirfrag_t> >::iterator p = subtrees.begin(); p != subtrees.end(); ++p) { CDir *dir = mds->mdcache->get_dirfrag(p->first); if (!dir) { mds->clog->error() << " replayed ESubtreeMap at " << get_start_off() << " subtree root " << p->first << " not in cache"; ++errors; continue; } if (!mds->mdcache->is_subtree(dir)) { mds->clog->error() << " replayed ESubtreeMap at " << get_start_off() << " subtree root " << p->first << " not a subtree in cache"; ++errors; continue; } if (dir->get_dir_auth().first != mds->get_nodeid()) { mds->clog->error() << " replayed ESubtreeMap at " << get_start_off() << " subtree root " << p->first << " is not mine in cache (it's " << dir->get_dir_auth() << ")"; ++errors; continue; } for (vector<dirfrag_t>::iterator q = p->second.begin(); q != p->second.end(); ++q) mds->mdcache->get_force_dirfrag(*q, true); set<CDir*> bounds; mds->mdcache->get_subtree_bounds(dir, bounds); for (vector<dirfrag_t>::iterator q = p->second.begin(); q != p->second.end(); ++q) { CDir *b = mds->mdcache->get_dirfrag(*q); if (!b) { mds->clog->error() << " replayed ESubtreeMap at " << get_start_off() << " subtree " << p->first << " bound " << *q << " not in cache"; ++errors; continue; } if (bounds.count(b) == 0) { mds->clog->error() << " replayed ESubtreeMap at " << get_start_off() << " subtree " << p->first << " bound " << *q << " not a bound in cache"; ++errors; continue; } bounds.erase(b); } for (set<CDir*>::iterator q = bounds.begin(); q != bounds.end(); ++q) { mds->clog->error() << " replayed ESubtreeMap at " << get_start_off() << " subtree " << p->first << " has extra bound in cache " << (*q)->dirfrag(); ++errors; } if (ambiguous_subtrees.count(p->first)) { if (!mds->mdcache->have_ambiguous_import(p->first)) { mds->clog->error() << " replayed ESubtreeMap at " << get_start_off() << " subtree " << p->first << " is ambiguous but is not in our cache"; ++errors; } } else { if (mds->mdcache->have_ambiguous_import(p->first)) { mds->clog->error() << " replayed ESubtreeMap at " << get_start_off() << " subtree " << p->first << " is not ambiguous but is in our cache"; ++errors; } } } std::vector<CDir*> dirs; mds->mdcache->get_subtrees(dirs); for (const auto& dir : dirs) { if (dir->get_dir_auth().first != mds->get_nodeid()) continue; if (subtrees.count(dir->dirfrag()) == 0) { mds->clog->error() << " replayed ESubtreeMap at " << get_start_off() << " does not include cache subtree " << dir->dirfrag(); ++errors; } } if (errors) { dout(0) << "journal subtrees: " << subtrees << dendl; dout(0) << "journal ambig_subtrees: " << ambiguous_subtrees << dendl; mds->mdcache->show_subtrees(); ceph_assert(!g_conf()->mds_debug_subtrees || errors == 0); } return; } dout(10) << "ESubtreeMap.replay -- reconstructing (auth) subtree spanning tree" << dendl; // first, stick the spanning tree in my cache //metablob.print(*_dout); metablob.replay(mds, get_segment(), EVENT_SUBTREEMAP); // restore import/export maps for (map<dirfrag_t, vector<dirfrag_t> >::iterator p = subtrees.begin(); p != subtrees.end(); ++p) { CDir *dir = mds->mdcache->get_dirfrag(p->first); ceph_assert(dir); if (ambiguous_subtrees.count(p->first)) { // ambiguous! mds->mdcache->add_ambiguous_import(p->first, p->second); mds->mdcache->adjust_bounded_subtree_auth(dir, p->second, mds_authority_t(mds->get_nodeid(), mds->get_nodeid())); } else { // not ambiguous mds->mdcache->adjust_bounded_subtree_auth(dir, p->second, mds->get_nodeid()); } } mds->mdcache->recalc_auth_bits(true); mds->mdcache->show_subtrees(); } // ----------------------- // EFragment void EFragment::replay(MDSRank *mds) { dout(10) << "EFragment.replay " << op_name(op) << " " << ino << " " << basefrag << " by " << bits << dendl; std::vector<CDir*> resultfrags; MDSContext::vec waiters; // in may be NULL if it wasn't in our cache yet. if it's a prepare // it will be once we replay the metablob , but first we need to // refragment anything we already have in the cache. CInode *in = mds->mdcache->get_inode(ino); auto&& segment = get_segment(); switch (op) { case OP_PREPARE: mds->mdcache->add_uncommitted_fragment(dirfrag_t(ino, basefrag), bits, orig_frags, segment, &rollback); if (in) mds->mdcache->adjust_dir_fragments(in, basefrag, bits, &resultfrags, waiters, true); break; case OP_ROLLBACK: { frag_vec_t old_frags; if (in) { in->dirfragtree.get_leaves_under(basefrag, old_frags); if (orig_frags.empty()) { // old format EFragment mds->mdcache->adjust_dir_fragments(in, basefrag, -bits, &resultfrags, waiters, true); } else { for (const auto& fg : orig_frags) mds->mdcache->force_dir_fragment(in, fg); } } mds->mdcache->rollback_uncommitted_fragment(dirfrag_t(ino, basefrag), std::move(old_frags)); break; } case OP_COMMIT: case OP_FINISH: mds->mdcache->finish_uncommitted_fragment(dirfrag_t(ino, basefrag), op); break; default: ceph_abort(); } metablob.replay(mds, segment, EVENT_FRAGMENT); if (in && g_conf()->mds_debug_frag) in->verify_dirfrags(); } void EFragment::encode(bufferlist &bl, uint64_t features) const { ENCODE_START(5, 4, bl); encode(stamp, bl); encode(op, bl); encode(ino, bl); encode(basefrag, bl); encode(bits, bl); encode(metablob, bl, features); encode(orig_frags, bl); encode(rollback, bl); ENCODE_FINISH(bl); } void EFragment::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(5, 4, 4, bl); if (struct_v >= 2) decode(stamp, bl); if (struct_v >= 3) decode(op, bl); decode(ino, bl); decode(basefrag, bl); decode(bits, bl); decode(metablob, bl); if (struct_v >= 5) { decode(orig_frags, bl); decode(rollback, bl); } DECODE_FINISH(bl); } void EFragment::dump(Formatter *f) const { /*f->open_object_section("Metablob"); metablob.dump(f); // sadly we don't have this; dunno if we'll get it f->close_section();*/ f->dump_string("op", op_name(op)); f->dump_stream("ino") << ino; f->dump_stream("base frag") << basefrag; f->dump_int("bits", bits); } void EFragment::generate_test_instances(std::list<EFragment*>& ls) { ls.push_back(new EFragment); ls.push_back(new EFragment); ls.back()->op = OP_PREPARE; ls.back()->ino = 1; ls.back()->bits = 5; } void dirfrag_rollback::encode(bufferlist &bl) const { ENCODE_START(1, 1, bl); encode(*fnode, bl); ENCODE_FINISH(bl); } void dirfrag_rollback::decode(bufferlist::const_iterator &bl) { DECODE_START(1, bl); { auto _fnode = CDir::allocate_fnode(); decode(*_fnode, bl); fnode = std::move(_fnode); } DECODE_FINISH(bl); } // ========================================================================= // ----------------------- // EExport void EExport::replay(MDSRank *mds) { dout(10) << "EExport.replay " << base << dendl; auto&& segment = get_segment(); metablob.replay(mds, segment, EVENT_EXPORT); CDir *dir = mds->mdcache->get_dirfrag(base); ceph_assert(dir); set<CDir*> realbounds; for (set<dirfrag_t>::iterator p = bounds.begin(); p != bounds.end(); ++p) { CDir *bd = mds->mdcache->get_dirfrag(*p); ceph_assert(bd); realbounds.insert(bd); } // adjust auth away mds->mdcache->adjust_bounded_subtree_auth(dir, realbounds, CDIR_AUTH_UNDEF); mds->mdcache->try_trim_non_auth_subtree(dir); } void EExport::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(4, 3, bl); encode(stamp, bl); encode(metablob, bl, features); encode(base, bl); encode(bounds, bl); encode(target, bl); ENCODE_FINISH(bl); } void EExport::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl); if (struct_v >= 2) decode(stamp, bl); decode(metablob, bl); decode(base, bl); decode(bounds, bl); if (struct_v >= 4) decode(target, bl); DECODE_FINISH(bl); } void EExport::dump(Formatter *f) const { f->dump_float("stamp", (double)stamp); /*f->open_object_section("Metablob"); metablob.dump(f); // sadly we don't have this; dunno if we'll get it f->close_section();*/ f->dump_stream("base dirfrag") << base; f->open_array_section("bounds dirfrags"); for (set<dirfrag_t>::const_iterator i = bounds.begin(); i != bounds.end(); ++i) { f->dump_stream("dirfrag") << *i; } f->close_section(); // bounds dirfrags } void EExport::generate_test_instances(std::list<EExport*>& ls) { EExport *sample = new EExport(); ls.push_back(sample); } // ----------------------- // EImportStart void EImportStart::update_segment() { get_segment()->sessionmapv = cmapv; } void EImportStart::replay(MDSRank *mds) { dout(10) << "EImportStart.replay " << base << " bounds " << bounds << dendl; //metablob.print(*_dout); auto&& segment = get_segment(); metablob.replay(mds, segment, EVENT_IMPORTSTART); // put in ambiguous import list mds->mdcache->add_ambiguous_import(base, bounds); // set auth partially to us so we don't trim it CDir *dir = mds->mdcache->get_dirfrag(base); ceph_assert(dir); set<CDir*> realbounds; for (vector<dirfrag_t>::iterator p = bounds.begin(); p != bounds.end(); ++p) { CDir *bd = mds->mdcache->get_dirfrag(*p); ceph_assert(bd); if (!bd->is_subtree_root()) bd->state_clear(CDir::STATE_AUTH); realbounds.insert(bd); } mds->mdcache->adjust_bounded_subtree_auth(dir, realbounds, mds_authority_t(mds->get_nodeid(), mds->get_nodeid())); // open client sessions? if (mds->sessionmap.get_version() >= cmapv) { dout(10) << "EImportStart.replay sessionmap " << mds->sessionmap.get_version() << " >= " << cmapv << ", noop" << dendl; } else { dout(10) << "EImportStart.replay sessionmap " << mds->sessionmap.get_version() << " < " << cmapv << dendl; map<client_t,entity_inst_t> cm; map<client_t,client_metadata_t> cmm; auto blp = client_map.cbegin(); using ceph::decode; decode(cm, blp); if (!blp.end()) decode(cmm, blp); mds->sessionmap.replay_open_sessions(cmapv, cm, cmm); } update_segment(); } void EImportStart::encode(bufferlist &bl, uint64_t features) const { ENCODE_START(4, 3, bl); encode(stamp, bl); encode(base, bl); encode(metablob, bl, features); encode(bounds, bl); encode(cmapv, bl); encode(client_map, bl); encode(from, bl); ENCODE_FINISH(bl); } void EImportStart::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl); if (struct_v >= 2) decode(stamp, bl); decode(base, bl); decode(metablob, bl); decode(bounds, bl); decode(cmapv, bl); decode(client_map, bl); if (struct_v >= 4) decode(from, bl); DECODE_FINISH(bl); } void EImportStart::dump(Formatter *f) const { f->dump_stream("base dirfrag") << base; f->open_array_section("boundary dirfrags"); for (vector<dirfrag_t>::const_iterator iter = bounds.begin(); iter != bounds.end(); ++iter) { f->dump_stream("frag") << *iter; } f->close_section(); } void EImportStart::generate_test_instances(std::list<EImportStart*>& ls) { ls.push_back(new EImportStart); } // ----------------------- // EImportFinish void EImportFinish::replay(MDSRank *mds) { if (mds->mdcache->have_ambiguous_import(base)) { dout(10) << "EImportFinish.replay " << base << " success=" << success << dendl; if (success) { mds->mdcache->finish_ambiguous_import(base); } else { CDir *dir = mds->mdcache->get_dirfrag(base); ceph_assert(dir); vector<dirfrag_t> bounds; mds->mdcache->get_ambiguous_import_bounds(base, bounds); mds->mdcache->adjust_bounded_subtree_auth(dir, bounds, CDIR_AUTH_UNDEF); mds->mdcache->cancel_ambiguous_import(dir); mds->mdcache->try_trim_non_auth_subtree(dir); } } else { // this shouldn't happen unless this is an old journal dout(10) << "EImportFinish.replay " << base << " success=" << success << " on subtree not marked as ambiguous" << dendl; mds->clog->error() << "failure replaying journal (EImportFinish)"; mds->damaged(); ceph_abort(); // Should be unreachable because damaged() calls respawn() } } void EImportFinish::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(3, 3, bl); encode(stamp, bl); encode(base, bl); encode(success, bl); ENCODE_FINISH(bl); } void EImportFinish::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 3, 3, bl); if (struct_v >= 2) decode(stamp, bl); decode(base, bl); decode(success, bl); DECODE_FINISH(bl); } void EImportFinish::dump(Formatter *f) const { f->dump_stream("base dirfrag") << base; f->dump_string("success", success ? "true" : "false"); } void EImportFinish::generate_test_instances(std::list<EImportFinish*>& ls) { ls.push_back(new EImportFinish); ls.push_back(new EImportFinish); ls.back()->success = true; } // ------------------------ // EResetJournal void EResetJournal::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(2, 2, bl); encode(stamp, bl); ENCODE_FINISH(bl); } void EResetJournal::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(stamp, bl); DECODE_FINISH(bl); } void EResetJournal::dump(Formatter *f) const { f->dump_stream("timestamp") << stamp; } void EResetJournal::generate_test_instances(std::list<EResetJournal*>& ls) { ls.push_back(new EResetJournal()); } void EResetJournal::replay(MDSRank *mds) { dout(1) << "EResetJournal" << dendl; mds->sessionmap.wipe(); mds->inotable->replay_reset(); if (mds->mdsmap->get_root() == mds->get_nodeid()) { CDir *rootdir = mds->mdcache->get_root()->get_or_open_dirfrag(mds->mdcache, frag_t()); mds->mdcache->adjust_subtree_auth(rootdir, mds->get_nodeid()); } CDir *mydir = mds->mdcache->get_myin()->get_or_open_dirfrag(mds->mdcache, frag_t()); mds->mdcache->adjust_subtree_auth(mydir, mds->get_nodeid()); mds->mdcache->recalc_auth_bits(true); mds->mdcache->show_subtrees(); } void ENoOp::encode(bufferlist &bl, uint64_t features) const { ENCODE_START(2, 2, bl); encode(pad_size, bl); uint8_t const pad = 0xff; for (unsigned int i = 0; i < pad_size; ++i) { encode(pad, bl); } ENCODE_FINISH(bl); } void ENoOp::decode(bufferlist::const_iterator &bl) { DECODE_START(2, bl); decode(pad_size, bl); if (bl.get_remaining() != pad_size) { // This is spiritually an assertion, but expressing in a way that will let // journal debug tools catch it and recognise a malformed entry. throw buffer::end_of_buffer(); } else { bl += pad_size; } DECODE_FINISH(bl); } void ENoOp::replay(MDSRank *mds) { dout(4) << "ENoOp::replay, " << pad_size << " bytes skipped in journal" << dendl; } /** * If re-formatting an old journal that used absolute log position * references as segment sequence numbers, use this function to update * it. * * @param mds * MDSRank instance, just used for logging * @param old_to_new * Map of old journal segment sequence numbers to new journal segment sequence numbers * * @return * True if the event was modified. */ bool EMetaBlob::rewrite_truncate_finish(MDSRank const *mds, std::map<LogSegment::seq_t, LogSegment::seq_t> const &old_to_new) { bool modified = false; map<inodeno_t, LogSegment::seq_t> new_trunc_finish; for (const auto& p : truncate_finish) { auto q = old_to_new.find(p.second); if (q != old_to_new.end()) { dout(20) << __func__ << " applying segment seq mapping " << p.second << " -> " << q->second << dendl; new_trunc_finish.emplace(p.first, q->second); modified = true; } else { dout(20) << __func__ << " no segment seq mapping found for " << p.second << dendl; new_trunc_finish.insert(p); } } truncate_finish.swap(new_trunc_finish); return modified; }
97,765
28.297573
122
cc
null
ceph-main/src/mds/locks.c
#include "include/int_types.h" #include "locks.h" /* Duplicated from ceph_fs.h, which we cannot include into a C file. */ #define CEPH_CAP_GSHARED 1 /* client can reads */ #define CEPH_CAP_GEXCL 2 /* client can read and update */ #define CEPH_CAP_GCACHE 4 /* (file) client can cache reads */ #define CEPH_CAP_GRD 8 /* (file) client can read */ #define CEPH_CAP_GWR 16 /* (file) client can write */ #define CEPH_CAP_GBUFFER 32 /* (file) client can buffer writes */ #define CEPH_CAP_GWREXTEND 64 /* (file) client can extend EOF */ #define CEPH_CAP_GLAZYIO 128 /* (file) client can perform lazy io */ static const struct sm_state_t simplelock[LOCK_MAX] = { // stable loner rep state r rp rd wr fwr l x caps,other [LOCK_SYNC] = { 0, false, LOCK_SYNC, ANY, 0, ANY, 0, 0, ANY, 0, CEPH_CAP_GSHARED,0,0,CEPH_CAP_GSHARED }, [LOCK_LOCK_SYNC] = { LOCK_SYNC, false, LOCK_LOCK, AUTH, XCL, XCL, 0, 0, XCL, 0, 0,0,0,0 }, [LOCK_EXCL_SYNC] = { LOCK_SYNC, true, LOCK_LOCK, 0, 0, 0, 0, XCL, 0, 0, 0,CEPH_CAP_GSHARED,0,0 }, [LOCK_SNAP_SYNC] = { LOCK_SYNC, false, LOCK_LOCK, 0, 0, 0, 0, AUTH,0, 0, 0,0,0,0 }, [LOCK_LOCK] = { 0, false, LOCK_LOCK, AUTH, 0, REQ, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_SYNC_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, ANY, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_EXCL_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, XCL, 0, 0, 0,0,0,0 }, [LOCK_PREXLOCK] = { LOCK_LOCK, false, LOCK_LOCK, 0, XCL, 0, 0, 0, 0, ANY, 0,0,0,0 }, [LOCK_XLOCK] = { LOCK_SYNC, false, LOCK_LOCK, 0, XCL, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_XLOCKDONE] = { LOCK_SYNC, false, LOCK_LOCK, XCL, XCL, XCL, 0, 0, XCL, 0, 0,0,CEPH_CAP_GSHARED,0 }, [LOCK_LOCK_XLOCK]= { LOCK_PREXLOCK,false,LOCK_LOCK,0, XCL, 0, 0, 0, 0, XCL, 0,0,0,0 }, [LOCK_EXCL] = { 0, true, LOCK_LOCK, 0, 0, REQ, XCL, 0, 0, 0, 0,CEPH_CAP_GEXCL|CEPH_CAP_GSHARED,0,0 }, [LOCK_SYNC_EXCL] = { LOCK_EXCL, true, LOCK_LOCK, ANY, 0, 0, 0, 0, 0, 0, 0,CEPH_CAP_GSHARED,0,0 }, [LOCK_LOCK_EXCL] = { LOCK_EXCL, false, LOCK_LOCK, AUTH, 0, 0, 0, 0, 0, 0, CEPH_CAP_GSHARED,0,0,0 }, [LOCK_REMOTEXLOCK]={ LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, }; const struct sm_t sm_simplelock = { .states = simplelock, .allowed_ever_auth = CEPH_CAP_GSHARED | CEPH_CAP_GEXCL, .allowed_ever_replica = CEPH_CAP_GSHARED, .careful = CEPH_CAP_GSHARED | CEPH_CAP_GEXCL, .can_remote_xlock = 1, }; // lock state machine states: // Sync -- Lock -- sCatter // Tempsync _/ // (out of date) static const struct sm_state_t scatterlock[LOCK_MAX] = { // stable loner rep state r rp rd wr fwr l x caps,other [LOCK_SYNC] = { 0, false, LOCK_SYNC, ANY, 0, ANY, 0, 0, ANY, 0, CEPH_CAP_GSHARED,0,0,CEPH_CAP_GSHARED }, [LOCK_LOCK_SYNC] = { LOCK_SYNC, false, LOCK_LOCK, AUTH, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_MIX_SYNC] = { LOCK_SYNC, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_SNAP_SYNC] = { LOCK_SYNC, false, LOCK_LOCK, 0, 0, 0, 0, AUTH,0, 0, 0,0,0,0 }, [LOCK_LOCK] = { 0, false, LOCK_LOCK, AUTH, 0, REQ, AUTH,0, 0, ANY, 0,0,0,0 }, [LOCK_SYNC_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, ANY, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_MIX_LOCK] = { LOCK_LOCK, false, LOCK_MIX, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_MIX_LOCK2] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_TSYN_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, AUTH, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_TSYN] = { 0, false, LOCK_LOCK, AUTH, 0, AUTH,0, 0, 0, 0, 0,0,0,0 }, [LOCK_LOCK_TSYN] = { LOCK_TSYN, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_MIX_TSYN] = { LOCK_TSYN, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_MIX] = { 0, false, LOCK_MIX, 0, 0, REQ, ANY, 0, 0, 0, 0,0,0,0 }, [LOCK_TSYN_MIX] = { LOCK_MIX, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_SYNC_MIX] = { LOCK_MIX, false, LOCK_SYNC_MIX2,ANY,0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_SYNC_MIX2] = { LOCK_MIX, false, 0, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, }; const struct sm_t sm_scatterlock = { .states = scatterlock, .allowed_ever_auth = CEPH_CAP_GSHARED | CEPH_CAP_GEXCL, .allowed_ever_replica = CEPH_CAP_GSHARED, .careful = CEPH_CAP_GSHARED | CEPH_CAP_GEXCL, .can_remote_xlock = 0, }; const struct sm_state_t filelock[LOCK_MAX] = { // stable loner rep state r rp rd wr fwr l x caps(any,loner,xlocker,replica) [LOCK_SYNC] = { 0, false, LOCK_SYNC, ANY, 0, ANY, 0, 0, ANY, 0, CEPH_CAP_GSHARED|CEPH_CAP_GCACHE|CEPH_CAP_GRD|CEPH_CAP_GLAZYIO,0,0,CEPH_CAP_GSHARED|CEPH_CAP_GCACHE|CEPH_CAP_GRD }, [LOCK_LOCK_SYNC] = { LOCK_SYNC, false, LOCK_LOCK, AUTH, 0, 0, 0, 0, 0, 0, CEPH_CAP_GCACHE,0,0,0 }, [LOCK_EXCL_SYNC] = { LOCK_SYNC, true, LOCK_LOCK, 0, 0, 0, 0, XCL, 0, 0, 0,CEPH_CAP_GSHARED|CEPH_CAP_GCACHE|CEPH_CAP_GRD,0,0 }, [LOCK_MIX_SYNC] = { LOCK_SYNC, false, LOCK_MIX_SYNC2,0,0, 0, 0, 0, 0, 0, CEPH_CAP_GRD|CEPH_CAP_GLAZYIO,0,0,CEPH_CAP_GRD }, [LOCK_MIX_SYNC2] = { LOCK_SYNC, false, 0, 0, 0, 0, 0, 0, 0, 0, CEPH_CAP_GRD|CEPH_CAP_GLAZYIO,0,0,CEPH_CAP_GRD }, [LOCK_SNAP_SYNC] = { LOCK_SYNC, false, LOCK_LOCK, 0, 0, 0, 0, AUTH,0, 0, 0,0,0,0 }, [LOCK_XSYN_SYNC] = { LOCK_SYNC, true, LOCK_LOCK, AUTH, 0, AUTH,0, 0, 0, 0, 0,CEPH_CAP_GCACHE,0,0 }, [LOCK_LOCK] = { 0, false, LOCK_LOCK, AUTH, 0, REQ, AUTH,0, 0, 0, CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0,0 }, [LOCK_SYNC_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, ANY, 0, REQ, 0, 0, 0, 0, CEPH_CAP_GCACHE,0,0,0 }, [LOCK_EXCL_LOCK] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, XCL, 0, 0, CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0,0 }, [LOCK_MIX_LOCK] = { LOCK_LOCK, false, LOCK_MIX, 0, 0, REQ, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_MIX_LOCK2] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, REQ, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_XSYN_LOCK] = { LOCK_LOCK, true, LOCK_LOCK, AUTH, 0, 0, XCL, 0, 0, 0, 0,CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0 }, [LOCK_PREXLOCK] = { LOCK_LOCK, false, LOCK_LOCK, 0, XCL, 0, 0, 0, 0, ANY, CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0,0 }, [LOCK_XLOCK] = { LOCK_LOCK, false, LOCK_LOCK, 0, XCL, 0, 0, 0, 0, 0, CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0,0 }, [LOCK_XLOCKDONE] = { LOCK_LOCK, false, LOCK_LOCK, XCL, XCL, XCL, 0, 0, XCL, 0, CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,CEPH_CAP_GSHARED,0 }, [LOCK_XLOCKSNAP] = { LOCK_LOCK, false, LOCK_LOCK, 0, XCL, 0, 0, 0, 0, 0, CEPH_CAP_GCACHE,0,0,0 }, [LOCK_LOCK_XLOCK]= { LOCK_PREXLOCK,false,LOCK_LOCK,0, XCL, 0, 0, 0, 0, XCL, CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0,0 }, [LOCK_MIX] = { 0, false, LOCK_MIX, 0, 0, REQ, ANY, 0, 0, 0, CEPH_CAP_GRD|CEPH_CAP_GWR|CEPH_CAP_GLAZYIO,0,0,CEPH_CAP_GRD }, [LOCK_SYNC_MIX] = { LOCK_MIX, false, LOCK_SYNC_MIX2,ANY,0, 0, 0, 0, 0, 0, CEPH_CAP_GRD|CEPH_CAP_GLAZYIO,0,0,CEPH_CAP_GRD }, [LOCK_SYNC_MIX2] = { LOCK_MIX, false, 0, 0, 0, 0, 0, 0, 0, 0, CEPH_CAP_GRD|CEPH_CAP_GLAZYIO,0,0,CEPH_CAP_GRD }, [LOCK_EXCL_MIX] = { LOCK_MIX, true, LOCK_LOCK, 0, 0, 0, XCL, 0, 0, 0, 0,CEPH_CAP_GRD|CEPH_CAP_GWR,0,0 }, [LOCK_XSYN_MIX] = { LOCK_MIX, true, LOCK_LOCK, 0, 0, 0, XCL, 0, 0, 0, 0,0,0,0 }, [LOCK_EXCL] = { 0, true, LOCK_LOCK, 0, 0, XCL, XCL, 0, 0, 0, 0,CEPH_CAP_GSHARED|CEPH_CAP_GEXCL|CEPH_CAP_GCACHE|CEPH_CAP_GRD|CEPH_CAP_GWR|CEPH_CAP_GBUFFER,0,0 }, [LOCK_SYNC_EXCL] = { LOCK_EXCL, true, LOCK_LOCK, ANY, 0, 0, 0, 0, 0, 0, 0,CEPH_CAP_GSHARED|CEPH_CAP_GCACHE|CEPH_CAP_GRD,0,0 }, [LOCK_MIX_EXCL] = { LOCK_EXCL, true, LOCK_LOCK, 0, 0, 0, XCL, 0, 0, 0, 0,CEPH_CAP_GRD|CEPH_CAP_GWR,0,0 }, [LOCK_LOCK_EXCL] = { LOCK_EXCL, true, LOCK_LOCK, AUTH, 0, 0, 0, 0, 0, 0, 0,CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0 }, [LOCK_XSYN_EXCL] = { LOCK_EXCL, true, LOCK_LOCK, AUTH, 0, XCL, 0, 0, 0, 0, 0,CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0 }, [LOCK_XSYN] = { 0, true, LOCK_LOCK, AUTH, AUTH,AUTH,XCL, 0, 0, 0, 0,CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0 }, [LOCK_EXCL_XSYN] = { LOCK_XSYN, false, LOCK_LOCK, 0, 0, XCL, 0, 0, 0, 0, 0,CEPH_CAP_GCACHE|CEPH_CAP_GBUFFER,0,0 }, [LOCK_PRE_SCAN] = { LOCK_SCAN, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, [LOCK_SCAN] = { LOCK_LOCK, false, LOCK_LOCK, 0, 0, 0, 0, 0, 0, 0, 0,0,0,0 }, }; const struct sm_t sm_filelock = { .states = filelock, .allowed_ever_auth = (CEPH_CAP_GSHARED | CEPH_CAP_GEXCL | CEPH_CAP_GCACHE | CEPH_CAP_GRD | CEPH_CAP_GWR | CEPH_CAP_GWREXTEND | CEPH_CAP_GBUFFER | CEPH_CAP_GLAZYIO), .allowed_ever_replica = (CEPH_CAP_GSHARED | CEPH_CAP_GCACHE | CEPH_CAP_GRD | CEPH_CAP_GLAZYIO), .careful = (CEPH_CAP_GSHARED | CEPH_CAP_GEXCL | CEPH_CAP_GCACHE | CEPH_CAP_GBUFFER), .can_remote_xlock = 0, }; const struct sm_state_t locallock[LOCK_MAX] = { // stable loner rep state r rp rd wr fwr l x caps(any,loner,xlocker,replica) [LOCK_LOCK] = { 0, false, LOCK_LOCK, ANY, 0, ANY, 0, 0, ANY, AUTH,0,0,0,0 }, }; const struct sm_t sm_locallock = { .states = locallock, .allowed_ever_auth = 0, .allowed_ever_replica = 0, .careful = 0, .can_remote_xlock = 0, };
10,165
62.5375
205
c
null
ceph-main/src/mds/locks.h
#ifndef CEPH_MDS_LOCKS_H #define CEPH_MDS_LOCKS_H #include <stdbool.h> struct sm_state_t { int next; // 0 if stable bool loner; int replica_state; char can_read; char can_read_projected; char can_rdlock; char can_wrlock; char can_force_wrlock; char can_lease; char can_xlock; int caps; int loner_caps; int xlocker_caps; int replica_caps; }; struct sm_t { const struct sm_state_t *states; int allowed_ever_auth; int allowed_ever_replica; int careful; int can_remote_xlock; }; #define ANY 1 // auth or replica #define AUTH 2 // auth only #define XCL 3 // auth or exclusive client //#define FW 4 // fw to auth, if replica #define REQ 5 // req state change from auth, if replica extern const struct sm_t sm_simplelock; extern const struct sm_t sm_filelock; extern const struct sm_t sm_scatterlock; extern const struct sm_t sm_locallock; // -- lock states -- // sync <-> lock enum { LOCK_UNDEF = 0, // auth rep LOCK_SYNC, // AR R . RD L . / C . R RD L . / C . LOCK_LOCK, // AR R . .. . X / . . . .. . . / . . LOCK_PREXLOCK, // A . . .. . . / . . (lock) LOCK_XLOCK, // A . . .. . . / . . (lock) LOCK_XLOCKDONE, // A r p rd l x / . . (lock) <-- by same client only!! LOCK_XLOCKSNAP, // also revoke Fb LOCK_LOCK_XLOCK, LOCK_SYNC_LOCK, // AR R . .. . . / . . R .. . . / . . LOCK_LOCK_SYNC, // A R p rd l . / . . (lock) <-- lc by same client only LOCK_EXCL, // A . . .. . . / c x * (lock) LOCK_EXCL_SYNC, // A . . .. . . / c . * (lock) LOCK_EXCL_LOCK, // A . . .. . . / . . (lock) LOCK_SYNC_EXCL, // Ar R . .. . . / c . * (sync->lock) LOCK_LOCK_EXCL, // A R . .. . . / . . (lock) LOCK_REMOTEXLOCK, // on NON-auth // * = loner mode LOCK_MIX, LOCK_SYNC_MIX, LOCK_SYNC_MIX2, LOCK_LOCK_MIX, LOCK_EXCL_MIX, LOCK_MIX_SYNC, LOCK_MIX_SYNC2, LOCK_MIX_LOCK, LOCK_MIX_LOCK2, LOCK_MIX_EXCL, LOCK_TSYN, LOCK_TSYN_LOCK, LOCK_TSYN_MIX, LOCK_LOCK_TSYN, LOCK_MIX_TSYN, LOCK_PRE_SCAN, LOCK_SCAN, LOCK_SNAP_SYNC, LOCK_XSYN, LOCK_XSYN_EXCL, LOCK_EXCL_XSYN, LOCK_XSYN_SYNC, LOCK_XSYN_LOCK, LOCK_XSYN_MIX, LOCK_MAX, }; // ------------------------- // lock actions // for replicas #define LOCK_AC_SYNC -1 #define LOCK_AC_MIX -2 #define LOCK_AC_LOCK -3 #define LOCK_AC_LOCKFLUSHED -4 // for auth #define LOCK_AC_SYNCACK 1 #define LOCK_AC_MIXACK 2 #define LOCK_AC_LOCKACK 3 #define LOCK_AC_REQSCATTER 7 #define LOCK_AC_REQUNSCATTER 8 #define LOCK_AC_NUDGE 9 #define LOCK_AC_REQRDLOCK 10 #define LOCK_AC_FOR_REPLICA(a) ((a) < 0) #define LOCK_AC_FOR_AUTH(a) ((a) > 0) #endif
2,801
21.062992
82
h
null
ceph-main/src/mds/mds_table_types.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDSTABLETYPES_H #define CEPH_MDSTABLETYPES_H // MDS TABLES #include <string_view> enum { TABLE_ANCHOR, TABLE_SNAP, }; inline std::string_view get_mdstable_name(int t) { switch (t) { case TABLE_ANCHOR: return "anchortable"; case TABLE_SNAP: return "snaptable"; default: ceph_abort(); return std::string_view(); } } enum { TABLESERVER_OP_QUERY = 1, TABLESERVER_OP_QUERY_REPLY = -2, TABLESERVER_OP_PREPARE = 3, TABLESERVER_OP_AGREE = -4, TABLESERVER_OP_COMMIT = 5, TABLESERVER_OP_ACK = -6, TABLESERVER_OP_ROLLBACK = 7, TABLESERVER_OP_SERVER_UPDATE = 8, TABLESERVER_OP_SERVER_READY = -9, TABLESERVER_OP_NOTIFY_ACK = 10, TABLESERVER_OP_NOTIFY_PREP = -11, }; inline std::string_view get_mdstableserver_opname(int op) { switch (op) { case TABLESERVER_OP_QUERY: return "query"; case TABLESERVER_OP_QUERY_REPLY: return "query_reply"; case TABLESERVER_OP_PREPARE: return "prepare"; case TABLESERVER_OP_AGREE: return "agree"; case TABLESERVER_OP_COMMIT: return "commit"; case TABLESERVER_OP_ACK: return "ack"; case TABLESERVER_OP_ROLLBACK: return "rollback"; case TABLESERVER_OP_SERVER_UPDATE: return "server_update"; case TABLESERVER_OP_SERVER_READY: return "server_ready"; case TABLESERVER_OP_NOTIFY_ACK: return "notify_ack"; case TABLESERVER_OP_NOTIFY_PREP: return "notify_prep"; default: ceph_abort(); return std::string_view(); } } enum { TABLE_OP_CREATE, TABLE_OP_UPDATE, TABLE_OP_DESTROY, }; inline std::string_view get_mdstable_opname(int op) { switch (op) { case TABLE_OP_CREATE: return "create"; case TABLE_OP_UPDATE: return "update"; case TABLE_OP_DESTROY: return "destroy"; default: ceph_abort(); return std::string_view(); } } #endif
2,215
26.02439
71
h
null
ceph-main/src/mds/mdstypes.cc
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #include "mdstypes.h" #include "include/cephfs/types.h" #include "MDSContext.h" #include "common/Formatter.h" #include "common/StackStringStream.h" const mds_gid_t MDS_GID_NONE = mds_gid_t(0); using std::list; using std::make_pair; using std::ostream; using std::set; using std::vector; using ceph::bufferlist; using ceph::Formatter; /* * frag_info_t */ void frag_info_t::encode(bufferlist &bl) const { ENCODE_START(3, 2, bl); encode(version, bl); encode(mtime, bl); encode(nfiles, bl); encode(nsubdirs, bl); encode(change_attr, bl); ENCODE_FINISH(bl); } void frag_info_t::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); decode(version, bl); decode(mtime, bl); decode(nfiles, bl); decode(nsubdirs, bl); if (struct_v >= 3) decode(change_attr, bl); else change_attr = 0; DECODE_FINISH(bl); } void frag_info_t::dump(Formatter *f) const { f->dump_unsigned("version", version); f->dump_stream("mtime") << mtime; f->dump_unsigned("num_files", nfiles); f->dump_unsigned("num_subdirs", nsubdirs); f->dump_unsigned("change_attr", change_attr); } void frag_info_t::decode_json(JSONObj *obj){ JSONDecoder::decode_json("version", version, obj, true); JSONDecoder::decode_json("mtime", mtime, obj, true); JSONDecoder::decode_json("num_files", nfiles, obj, true); JSONDecoder::decode_json("num_subdirs", nsubdirs, obj, true); JSONDecoder::decode_json("change_attr", change_attr, obj, true); } void frag_info_t::generate_test_instances(std::list<frag_info_t*>& ls) { ls.push_back(new frag_info_t); ls.push_back(new frag_info_t); ls.back()->version = 1; ls.back()->mtime = utime_t(2, 3); ls.back()->nfiles = 4; ls.back()->nsubdirs = 5; } ostream& operator<<(ostream &out, const frag_info_t &f) { if (f == frag_info_t()) return out << "f()"; out << "f(v" << f.version; if (f.mtime != utime_t()) out << " m" << f.mtime; if (f.nfiles || f.nsubdirs) out << " " << f.size() << "=" << f.nfiles << "+" << f.nsubdirs; out << ")"; return out; } /* * nest_info_t */ void nest_info_t::encode(bufferlist &bl) const { ENCODE_START(3, 2, bl); encode(version, bl); encode(rbytes, bl); encode(rfiles, bl); encode(rsubdirs, bl); { // removed field int64_t ranchors = 0; encode(ranchors, bl); } encode(rsnaps, bl); encode(rctime, bl); ENCODE_FINISH(bl); } void nest_info_t::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); decode(version, bl); decode(rbytes, bl); decode(rfiles, bl); decode(rsubdirs, bl); { int64_t ranchors; decode(ranchors, bl); } decode(rsnaps, bl); decode(rctime, bl); DECODE_FINISH(bl); } void nest_info_t::dump(Formatter *f) const { f->dump_unsigned("version", version); f->dump_unsigned("rbytes", rbytes); f->dump_unsigned("rfiles", rfiles); f->dump_unsigned("rsubdirs", rsubdirs); f->dump_unsigned("rsnaps", rsnaps); f->dump_stream("rctime") << rctime; } void nest_info_t::decode_json(JSONObj *obj){ JSONDecoder::decode_json("version", version, obj, true); JSONDecoder::decode_json("rbytes", rbytes, obj, true); JSONDecoder::decode_json("rfiles", rfiles, obj, true); JSONDecoder::decode_json("rsubdirs", rsubdirs, obj, true); JSONDecoder::decode_json("rsnaps", rsnaps, obj, true); JSONDecoder::decode_json("rctime", rctime, obj, true); } void nest_info_t::generate_test_instances(std::list<nest_info_t*>& ls) { ls.push_back(new nest_info_t); ls.push_back(new nest_info_t); ls.back()->version = 1; ls.back()->rbytes = 2; ls.back()->rfiles = 3; ls.back()->rsubdirs = 4; ls.back()->rsnaps = 6; ls.back()->rctime = utime_t(7, 8); } ostream& operator<<(ostream &out, const nest_info_t &n) { if (n == nest_info_t()) return out << "n()"; out << "n(v" << n.version; if (n.rctime != utime_t()) out << " rc" << n.rctime; if (n.rbytes) out << " b" << n.rbytes; if (n.rsnaps) out << " rs" << n.rsnaps; if (n.rfiles || n.rsubdirs) out << " " << n.rsize() << "=" << n.rfiles << "+" << n.rsubdirs; out << ")"; return out; } /* * quota_info_t */ void quota_info_t::dump(Formatter *f) const { f->dump_int("max_bytes", max_bytes); f->dump_int("max_files", max_files); } void quota_info_t::decode_json(JSONObj *obj){ JSONDecoder::decode_json("max_bytes", max_bytes, obj, true); JSONDecoder::decode_json("max_files", max_files, obj, true); } void quota_info_t::generate_test_instances(std::list<quota_info_t *>& ls) { ls.push_back(new quota_info_t); ls.push_back(new quota_info_t); ls.back()->max_bytes = 16; ls.back()->max_files = 16; } ostream& operator<<(ostream &out, const quota_info_t &n) { out << "quota(" << "max_bytes = " << n.max_bytes << " max_files = " << n.max_files << ")"; return out; } /* * client_writeable_range_t */ void client_writeable_range_t::encode(bufferlist &bl) const { ENCODE_START(2, 2, bl); encode(range.first, bl); encode(range.last, bl); encode(follows, bl); ENCODE_FINISH(bl); } void client_writeable_range_t::decode(bufferlist::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(range.first, bl); decode(range.last, bl); decode(follows, bl); DECODE_FINISH(bl); } void client_writeable_range_t::dump(Formatter *f) const { f->open_object_section("byte range"); f->dump_unsigned("first", range.first); f->dump_unsigned("last", range.last); f->close_section(); f->dump_unsigned("follows", follows); } void client_writeable_range_t::byte_range_t::decode_json(JSONObj *obj){ JSONDecoder::decode_json("first", first, obj, true); JSONDecoder::decode_json("last", last, obj, true); } void client_writeable_range_t::generate_test_instances(std::list<client_writeable_range_t*>& ls) { ls.push_back(new client_writeable_range_t); ls.push_back(new client_writeable_range_t); ls.back()->range.first = 123; ls.back()->range.last = 456; ls.back()->follows = 12; } ostream& operator<<(ostream& out, const client_writeable_range_t& r) { return out << r.range.first << '-' << r.range.last << "@" << r.follows; } /* * inline_data_t */ void inline_data_t::encode(bufferlist &bl) const { using ceph::encode; encode(version, bl); if (blp) encode(*blp, bl); else encode(bufferlist(), bl); } void inline_data_t::decode(bufferlist::const_iterator &p) { using ceph::decode; decode(version, p); uint32_t inline_len; decode(inline_len, p); if (inline_len > 0) { ceph::buffer::list bl; decode_nohead(inline_len, bl, p); set_data(bl); } else free_data(); } /* * fnode_t */ void fnode_t::encode(bufferlist &bl) const { ENCODE_START(4, 3, bl); encode(version, bl); encode(snap_purged_thru, bl); encode(fragstat, bl); encode(accounted_fragstat, bl); encode(rstat, bl); encode(accounted_rstat, bl); encode(damage_flags, bl); encode(recursive_scrub_version, bl); encode(recursive_scrub_stamp, bl); encode(localized_scrub_version, bl); encode(localized_scrub_stamp, bl); ENCODE_FINISH(bl); } void fnode_t::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(3, 2, 2, bl); decode(version, bl); decode(snap_purged_thru, bl); decode(fragstat, bl); decode(accounted_fragstat, bl); decode(rstat, bl); decode(accounted_rstat, bl); if (struct_v >= 3) { decode(damage_flags, bl); } if (struct_v >= 4) { decode(recursive_scrub_version, bl); decode(recursive_scrub_stamp, bl); decode(localized_scrub_version, bl); decode(localized_scrub_stamp, bl); } DECODE_FINISH(bl); } void fnode_t::dump(Formatter *f) const { f->dump_unsigned("version", version); f->dump_unsigned("snap_purged_thru", snap_purged_thru); f->open_object_section("fragstat"); fragstat.dump(f); f->close_section(); f->open_object_section("accounted_fragstat"); accounted_fragstat.dump(f); f->close_section(); f->open_object_section("rstat"); rstat.dump(f); f->close_section(); f->open_object_section("accounted_rstat"); accounted_rstat.dump(f); f->close_section(); } void fnode_t::decode_json(JSONObj *obj){ JSONDecoder::decode_json("version", version, obj, true); uint64_t tmp; JSONDecoder::decode_json("snap_purged_thru", tmp, obj, true); snap_purged_thru.val = tmp; JSONDecoder::decode_json("fragstat", fragstat, obj, true); JSONDecoder::decode_json("accounted_fragstat", accounted_fragstat, obj, true); JSONDecoder::decode_json("rstat", rstat, obj, true); JSONDecoder::decode_json("accounted_rstat", accounted_rstat, obj, true); } void fnode_t::generate_test_instances(std::list<fnode_t*>& ls) { ls.push_back(new fnode_t); ls.push_back(new fnode_t); ls.back()->version = 1; ls.back()->snap_purged_thru = 2; list<frag_info_t*> fls; frag_info_t::generate_test_instances(fls); ls.back()->fragstat = *fls.back(); ls.back()->accounted_fragstat = *fls.front(); list<nest_info_t*> nls; nest_info_t::generate_test_instances(nls); ls.back()->rstat = *nls.front(); ls.back()->accounted_rstat = *nls.back(); } /* * old_rstat_t */ void old_rstat_t::encode(bufferlist& bl) const { ENCODE_START(2, 2, bl); encode(first, bl); encode(rstat, bl); encode(accounted_rstat, bl); ENCODE_FINISH(bl); } void old_rstat_t::decode(bufferlist::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(first, bl); decode(rstat, bl); decode(accounted_rstat, bl); DECODE_FINISH(bl); } void old_rstat_t::dump(Formatter *f) const { f->dump_unsigned("snapid", first); f->open_object_section("rstat"); rstat.dump(f); f->close_section(); f->open_object_section("accounted_rstat"); accounted_rstat.dump(f); f->close_section(); } void old_rstat_t::generate_test_instances(std::list<old_rstat_t*>& ls) { ls.push_back(new old_rstat_t()); ls.push_back(new old_rstat_t()); ls.back()->first = 12; list<nest_info_t*> nls; nest_info_t::generate_test_instances(nls); ls.back()->rstat = *nls.back(); ls.back()->accounted_rstat = *nls.front(); } /* * feature_bitset_t */ feature_bitset_t::feature_bitset_t(unsigned long value) { if (value) { for (size_t i = 0; i < sizeof(value) * 8; i += bits_per_block) { _vec.push_back((block_type)(value >> i)); } } } feature_bitset_t::feature_bitset_t(const vector<size_t>& array) { if (!array.empty()) { size_t n = array.back(); n += bits_per_block; n /= bits_per_block; _vec.resize(n, 0); size_t last = 0; for (auto& bit : array) { if (bit > last) last = bit; else ceph_assert(bit == last); _vec[bit / bits_per_block] |= (block_type)1 << (bit % bits_per_block); } } } feature_bitset_t& feature_bitset_t::operator-=(const feature_bitset_t& other) { for (size_t i = 0; i < _vec.size(); ++i) { if (i >= other._vec.size()) break; _vec[i] &= ~other._vec[i]; } return *this; } void feature_bitset_t::encode(bufferlist& bl) const { using ceph::encode; using ceph::encode_nohead; uint32_t len = _vec.size() * sizeof(block_type); encode(len, bl); encode_nohead(_vec, bl); } void feature_bitset_t::decode(bufferlist::const_iterator &p) { using ceph::decode; using ceph::decode_nohead; uint32_t len; decode(len, p); _vec.clear(); if (len >= sizeof(block_type)) decode_nohead(len / sizeof(block_type), _vec, p); if (len % sizeof(block_type)) { ceph_le64 buf{}; p.copy(len % sizeof(block_type), (char*)&buf); _vec.push_back((block_type)buf); } } void feature_bitset_t::dump(Formatter *f) const { CachedStackStringStream css; print(*css); f->dump_string("feature_bits", css->strv()); } void feature_bitset_t::print(ostream& out) const { std::ios_base::fmtflags f(out.flags()); int size = _vec.size(); if (!size) { out << "0x0"; } else { out << "0x"; for (int i = size - 1; i >= 0; --i) out << std::setfill('0') << std::setw(sizeof(block_type) * 2) << std::hex << _vec[i]; } out.flags(f); } /* * metric_spec_t */ void metric_spec_t::encode(bufferlist& bl) const { using ceph::encode; ENCODE_START(1, 1, bl); encode(metric_flags, bl); ENCODE_FINISH(bl); } void metric_spec_t::decode(bufferlist::const_iterator &p) { using ceph::decode; DECODE_START(1, p); decode(metric_flags, p); DECODE_FINISH(p); } void metric_spec_t::dump(Formatter *f) const { f->dump_object("metric_flags", metric_flags); } void metric_spec_t::print(ostream& out) const { out << "{metric_flags: '" << metric_flags << "'}"; } /* * client_metadata_t */ void client_metadata_t::encode(bufferlist& bl) const { ENCODE_START(3, 1, bl); encode(kv_map, bl); encode(features, bl); encode(metric_spec, bl); ENCODE_FINISH(bl); } void client_metadata_t::decode(bufferlist::const_iterator& p) { DECODE_START(3, p); decode(kv_map, p); if (struct_v >= 2) decode(features, p); if (struct_v >= 3) { decode(metric_spec, p); } DECODE_FINISH(p); } void client_metadata_t::dump(Formatter *f) const { f->dump_object("client_features", features); f->dump_object("metric_spec", metric_spec); for (const auto& [name, val] : kv_map) f->dump_string(name.c_str(), val); } /* * session_info_t */ void session_info_t::encode(bufferlist& bl, uint64_t features) const { ENCODE_START(7, 7, bl); encode(inst, bl, features); encode(completed_requests, bl); encode(prealloc_inos, bl); // hacky, see below. encode((__u32)0, bl); // used_inos encode(completed_flushes, bl); encode(auth_name, bl); encode(client_metadata, bl); ENCODE_FINISH(bl); } void session_info_t::decode(bufferlist::const_iterator& p) { DECODE_START_LEGACY_COMPAT_LEN(7, 2, 2, p); decode(inst, p); if (struct_v <= 2) { set<ceph_tid_t> s; decode(s, p); while (!s.empty()) { completed_requests[*s.begin()] = inodeno_t(); s.erase(s.begin()); } } else { decode(completed_requests, p); } decode(prealloc_inos, p); { interval_set<inodeno_t> used_inos; decode(used_inos, p); prealloc_inos.insert(used_inos); } if (struct_v >= 4 && struct_v < 7) { decode(client_metadata.kv_map, p); } if (struct_v >= 5) { decode(completed_flushes, p); } if (struct_v >= 6) { decode(auth_name, p); } if (struct_v >= 7) { decode(client_metadata, p); } DECODE_FINISH(p); } void session_info_t::dump(Formatter *f) const { f->dump_stream("inst") << inst; f->open_array_section("completed_requests"); for (const auto& [tid, ino] : completed_requests) { f->open_object_section("request"); f->dump_unsigned("tid", tid); f->dump_stream("created_ino") << ino; f->close_section(); } f->close_section(); f->open_array_section("prealloc_inos"); for (const auto& [start, len] : prealloc_inos) { f->open_object_section("ino_range"); f->dump_stream("start") << start; f->dump_unsigned("length", len); f->close_section(); } f->close_section(); f->dump_object("client_metadata", client_metadata); } void session_info_t::generate_test_instances(std::list<session_info_t*>& ls) { ls.push_back(new session_info_t); ls.push_back(new session_info_t); ls.back()->inst = entity_inst_t(entity_name_t::MDS(12), entity_addr_t()); ls.back()->completed_requests.insert(make_pair(234, inodeno_t(111222))); ls.back()->completed_requests.insert(make_pair(237, inodeno_t(222333))); ls.back()->prealloc_inos.insert(333, 12); ls.back()->prealloc_inos.insert(377, 112); // we can't add used inos; they're cleared on decode } /* * string_snap_t */ void string_snap_t::encode(bufferlist& bl) const { ENCODE_START(2, 2, bl); encode(name, bl); encode(snapid, bl); ENCODE_FINISH(bl); } void string_snap_t::decode(bufferlist::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(name, bl); decode(snapid, bl); DECODE_FINISH(bl); } void string_snap_t::dump(Formatter *f) const { f->dump_string("name", name); f->dump_unsigned("snapid", snapid); } void string_snap_t::generate_test_instances(std::list<string_snap_t*>& ls) { ls.push_back(new string_snap_t); ls.push_back(new string_snap_t); ls.back()->name = "foo"; ls.back()->snapid = 123; ls.push_back(new string_snap_t); ls.back()->name = "bar"; ls.back()->snapid = 456; } /* * MDSCacheObjectInfo */ void MDSCacheObjectInfo::encode(bufferlist& bl) const { ENCODE_START(2, 2, bl); encode(ino, bl); encode(dirfrag, bl); encode(dname, bl); encode(snapid, bl); ENCODE_FINISH(bl); } void MDSCacheObjectInfo::decode(bufferlist::const_iterator& p) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, p); decode(ino, p); decode(dirfrag, p); decode(dname, p); decode(snapid, p); DECODE_FINISH(p); } void MDSCacheObjectInfo::dump(Formatter *f) const { f->dump_unsigned("ino", ino); f->dump_stream("dirfrag") << dirfrag; f->dump_string("name", dname); f->dump_unsigned("snapid", snapid); } void MDSCacheObjectInfo::generate_test_instances(std::list<MDSCacheObjectInfo*>& ls) { ls.push_back(new MDSCacheObjectInfo); ls.push_back(new MDSCacheObjectInfo); ls.back()->ino = 1; ls.back()->dirfrag = dirfrag_t(2, 3); ls.back()->dname = "fooname"; ls.back()->snapid = CEPH_NOSNAP; ls.push_back(new MDSCacheObjectInfo); ls.back()->ino = 121; ls.back()->dirfrag = dirfrag_t(222, 0); ls.back()->dname = "bar foo"; ls.back()->snapid = 21322; } /* * mds_table_pending_t */ void mds_table_pending_t::encode(bufferlist& bl) const { ENCODE_START(2, 2, bl); encode(reqid, bl); encode(mds, bl); encode(tid, bl); ENCODE_FINISH(bl); } void mds_table_pending_t::decode(bufferlist::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(reqid, bl); decode(mds, bl); decode(tid, bl); DECODE_FINISH(bl); } void mds_table_pending_t::dump(Formatter *f) const { f->dump_unsigned("reqid", reqid); f->dump_unsigned("mds", mds); f->dump_unsigned("tid", tid); } void mds_table_pending_t::generate_test_instances(std::list<mds_table_pending_t*>& ls) { ls.push_back(new mds_table_pending_t); ls.push_back(new mds_table_pending_t); ls.back()->reqid = 234; ls.back()->mds = 2; ls.back()->tid = 35434; } /* * inode_load_vec_t */ void inode_load_vec_t::encode(bufferlist &bl) const { ENCODE_START(2, 2, bl); for (const auto &i : vec) { encode(i, bl); } ENCODE_FINISH(bl); } void inode_load_vec_t::decode(bufferlist::const_iterator &p) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, p); for (auto &i : vec) { decode(i, p); } DECODE_FINISH(p); } void inode_load_vec_t::dump(Formatter *f) const { f->open_array_section("Decay Counters"); for (const auto &i : vec) { f->open_object_section("Decay Counter"); i.dump(f); f->close_section(); } f->close_section(); } void inode_load_vec_t::generate_test_instances(std::list<inode_load_vec_t*>& ls) { ls.push_back(new inode_load_vec_t(DecayRate())); } /* * dirfrag_load_vec_t */ void dirfrag_load_vec_t::dump(Formatter *f) const { f->open_array_section("Decay Counters"); for (const auto &i : vec) { f->open_object_section("Decay Counter"); i.dump(f); f->close_section(); } f->close_section(); } void dirfrag_load_vec_t::dump(Formatter *f, const DecayRate& rate) const { f->dump_float("meta_load", meta_load()); f->dump_float("IRD", get(META_POP_IRD).get()); f->dump_float("IWR", get(META_POP_IWR).get()); f->dump_float("READDIR", get(META_POP_READDIR).get()); f->dump_float("FETCH", get(META_POP_FETCH).get()); f->dump_float("STORE", get(META_POP_STORE).get()); } void dirfrag_load_vec_t::generate_test_instances(std::list<dirfrag_load_vec_t*>& ls) { ls.push_back(new dirfrag_load_vec_t(DecayRate())); } /* * mds_load_t */ void mds_load_t::encode(bufferlist &bl) const { ENCODE_START(2, 2, bl); encode(auth, bl); encode(all, bl); encode(req_rate, bl); encode(cache_hit_rate, bl); encode(queue_len, bl); encode(cpu_load_avg, bl); ENCODE_FINISH(bl); } void mds_load_t::decode(bufferlist::const_iterator &bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(auth, bl); decode(all, bl); decode(req_rate, bl); decode(cache_hit_rate, bl); decode(queue_len, bl); decode(cpu_load_avg, bl); DECODE_FINISH(bl); } void mds_load_t::dump(Formatter *f) const { f->dump_float("request rate", req_rate); f->dump_float("cache hit rate", cache_hit_rate); f->dump_float("queue length", queue_len); f->dump_float("cpu load", cpu_load_avg); f->open_object_section("auth dirfrag"); auth.dump(f); f->close_section(); f->open_object_section("all dirfrags"); all.dump(f); f->close_section(); } void mds_load_t::generate_test_instances(std::list<mds_load_t*>& ls) { ls.push_back(new mds_load_t(DecayRate())); } /* * cap_reconnect_t */ void cap_reconnect_t::encode(bufferlist& bl) const { ENCODE_START(2, 1, bl); encode_old(bl); // extract out when something changes encode(snap_follows, bl); ENCODE_FINISH(bl); } void cap_reconnect_t::encode_old(bufferlist& bl) const { using ceph::encode; encode(path, bl); capinfo.flock_len = flockbl.length(); encode(capinfo, bl); ceph::encode_nohead(flockbl, bl); } void cap_reconnect_t::decode(bufferlist::const_iterator& bl) { DECODE_START(2, bl); decode_old(bl); // extract out when something changes if (struct_v >= 2) decode(snap_follows, bl); DECODE_FINISH(bl); } void cap_reconnect_t::decode_old(bufferlist::const_iterator& bl) { using ceph::decode; decode(path, bl); decode(capinfo, bl); ceph::decode_nohead(capinfo.flock_len, flockbl, bl); } void cap_reconnect_t::dump(Formatter *f) const { f->dump_string("path", path); f->dump_int("cap_id", capinfo.cap_id); f->dump_string("cap wanted", ccap_string(capinfo.wanted)); f->dump_string("cap issued", ccap_string(capinfo.issued)); f->dump_int("snaprealm", capinfo.snaprealm); f->dump_int("path base ino", capinfo.pathbase); f->dump_string("has file locks", capinfo.flock_len ? "true" : "false"); } void cap_reconnect_t::generate_test_instances(std::list<cap_reconnect_t*>& ls) { ls.push_back(new cap_reconnect_t); ls.back()->path = "/test/path"; ls.back()->capinfo.cap_id = 1; } /* * snaprealm_reconnect_t */ void snaprealm_reconnect_t::encode(bufferlist& bl) const { ENCODE_START(1, 1, bl); encode_old(bl); // extract out when something changes ENCODE_FINISH(bl); } void snaprealm_reconnect_t::encode_old(bufferlist& bl) const { using ceph::encode; encode(realm, bl); } void snaprealm_reconnect_t::decode(bufferlist::const_iterator& bl) { DECODE_START(1, bl); decode_old(bl); // extract out when something changes DECODE_FINISH(bl); } void snaprealm_reconnect_t::decode_old(bufferlist::const_iterator& bl) { using ceph::decode; decode(realm, bl); } void snaprealm_reconnect_t::dump(Formatter *f) const { f->dump_int("ino", realm.ino); f->dump_int("seq", realm.seq); f->dump_int("parent", realm.parent); } void snaprealm_reconnect_t::generate_test_instances(std::list<snaprealm_reconnect_t*>& ls) { ls.push_back(new snaprealm_reconnect_t); ls.back()->realm.ino = 0x10000000001ULL; ls.back()->realm.seq = 2; ls.back()->realm.parent = 1; }
23,326
22.900615
96
cc
null
ceph-main/src/mds/mdstypes.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MDSTYPES_H #define CEPH_MDSTYPES_H #include "include/int_types.h" #include <ostream> #include <set> #include <map> #include <string_view> #include "common/config.h" #include "common/Clock.h" #include "common/DecayCounter.h" #include "common/StackStringStream.h" #include "common/entity_name.h" #include "include/compat.h" #include "include/Context.h" #include "include/frag.h" #include "include/xlist.h" #include "include/interval_set.h" #include "include/compact_set.h" #include "include/fs_types.h" #include "include/ceph_fs.h" #include "inode_backtrace.h" #include <boost/spirit/include/qi.hpp> #include <boost/pool/pool.hpp> #include "include/ceph_assert.h" #include "common/ceph_json.h" #include "include/cephfs/types.h" #define MDS_PORT_CACHE 0x200 #define MDS_PORT_LOCKER 0x300 #define MDS_PORT_MIGRATOR 0x400 #define NUM_STRAY 10 // Inode numbers 1,2 and 4 please see CEPH_INO_* in include/ceph_fs.h #define MDS_INO_MDSDIR_OFFSET (1*MAX_MDS) #define MDS_INO_STRAY_OFFSET (6*MAX_MDS) // Locations for journal data #define MDS_INO_LOG_OFFSET (2*MAX_MDS) #define MDS_INO_LOG_BACKUP_OFFSET (3*MAX_MDS) #define MDS_INO_LOG_POINTER_OFFSET (4*MAX_MDS) #define MDS_INO_PURGE_QUEUE (5*MAX_MDS) #define MDS_INO_SYSTEM_BASE ((6*MAX_MDS) + (MAX_MDS * NUM_STRAY)) #define MDS_INO_STRAY(x,i) (MDS_INO_STRAY_OFFSET+((((unsigned)(x))*NUM_STRAY)+((unsigned)(i)))) #define MDS_INO_MDSDIR(x) (MDS_INO_MDSDIR_OFFSET+((unsigned)x)) #define MDS_INO_IS_STRAY(i) ((i) >= MDS_INO_STRAY_OFFSET && (i) < (MDS_INO_STRAY_OFFSET+(MAX_MDS*NUM_STRAY))) #define MDS_INO_IS_MDSDIR(i) ((i) >= MDS_INO_MDSDIR_OFFSET && (i) < (MDS_INO_MDSDIR_OFFSET+MAX_MDS)) #define MDS_INO_MDSDIR_OWNER(i) (signed ((unsigned (i)) - MDS_INO_MDSDIR_OFFSET)) #define MDS_INO_IS_BASE(i) ((i) == CEPH_INO_ROOT || (i) == CEPH_INO_GLOBAL_SNAPREALM || MDS_INO_IS_MDSDIR(i)) #define MDS_INO_STRAY_OWNER(i) (signed (((unsigned (i)) - MDS_INO_STRAY_OFFSET) / NUM_STRAY)) #define MDS_INO_STRAY_INDEX(i) (((unsigned (i)) - MDS_INO_STRAY_OFFSET) % NUM_STRAY) #define MDS_IS_PRIVATE_INO(i) ((i) < MDS_INO_SYSTEM_BASE && (i) >= MDS_INO_MDSDIR_OFFSET) class mds_role_t { public: mds_role_t(fs_cluster_id_t fscid_, mds_rank_t rank_) : fscid(fscid_), rank(rank_) {} mds_role_t() {} bool operator<(mds_role_t const &rhs) const { if (fscid < rhs.fscid) { return true; } else if (fscid == rhs.fscid) { return rank < rhs.rank; } else { return false; } } bool is_none() const { return (rank == MDS_RANK_NONE); } fs_cluster_id_t fscid = FS_CLUSTER_ID_NONE; mds_rank_t rank = MDS_RANK_NONE; }; inline std::ostream& operator<<(std::ostream& out, const mds_role_t& role) { return out << role.fscid << ":" << role.rank; } // CAPS inline std::string gcap_string(int cap) { std::string s; if (cap & CEPH_CAP_GSHARED) s += "s"; if (cap & CEPH_CAP_GEXCL) s += "x"; if (cap & CEPH_CAP_GCACHE) s += "c"; if (cap & CEPH_CAP_GRD) s += "r"; if (cap & CEPH_CAP_GWR) s += "w"; if (cap & CEPH_CAP_GBUFFER) s += "b"; if (cap & CEPH_CAP_GWREXTEND) s += "a"; if (cap & CEPH_CAP_GLAZYIO) s += "l"; return s; } inline std::string ccap_string(int cap) { std::string s; if (cap & CEPH_CAP_PIN) s += "p"; int a = (cap >> CEPH_CAP_SAUTH) & 3; if (a) s += 'A' + gcap_string(a); a = (cap >> CEPH_CAP_SLINK) & 3; if (a) s += 'L' + gcap_string(a); a = (cap >> CEPH_CAP_SXATTR) & 3; if (a) s += 'X' + gcap_string(a); a = cap >> CEPH_CAP_SFILE; if (a) s += 'F' + gcap_string(a); if (s.length() == 0) s = "-"; return s; } namespace std { template<> struct hash<vinodeno_t> { size_t operator()(const vinodeno_t &vino) const { hash<inodeno_t> H; hash<uint64_t> I; return H(vino.ino) ^ I(vino.snapid); } }; } inline std::ostream& operator<<(std::ostream &out, const vinodeno_t &vino) { out << vino.ino; if (vino.snapid == CEPH_NOSNAP) out << ".head"; else if (vino.snapid) out << '.' << vino.snapid; return out; } typedef uint32_t damage_flags_t; template<template<typename> class Allocator> using alloc_string = std::basic_string<char,std::char_traits<char>,Allocator<char>>; template<template<typename> class Allocator> using xattr_map = std::map<alloc_string<Allocator>, ceph::bufferptr, std::less<alloc_string<Allocator>>, Allocator<std::pair<const alloc_string<Allocator>, ceph::bufferptr>>>; // FIXME bufferptr not in mempool template<template<typename> class Allocator> inline void decode_noshare(xattr_map<Allocator>& xattrs, ceph::buffer::list::const_iterator &p) { __u32 n; decode(n, p); while (n-- > 0) { alloc_string<Allocator> key; decode(key, p); __u32 len; decode(len, p); p.copy_deep(len, xattrs[key]); } } template<template<typename> class Allocator = std::allocator> struct old_inode_t { snapid_t first; inode_t<Allocator> inode; xattr_map<Allocator> xattrs; void encode(ceph::buffer::list &bl, uint64_t features) const; void decode(ceph::buffer::list::const_iterator& bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<old_inode_t*>& ls); }; // These methods may be moved back to mdstypes.cc when we have pmr template<template<typename> class Allocator> void old_inode_t<Allocator>::encode(ceph::buffer::list& bl, uint64_t features) const { ENCODE_START(2, 2, bl); encode(first, bl); encode(inode, bl, features); encode(xattrs, bl); ENCODE_FINISH(bl); } template<template<typename> class Allocator> void old_inode_t<Allocator>::decode(ceph::buffer::list::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(first, bl); decode(inode, bl); decode_noshare<Allocator>(xattrs, bl); DECODE_FINISH(bl); } template<template<typename> class Allocator> void old_inode_t<Allocator>::dump(ceph::Formatter *f) const { f->dump_unsigned("first", first); inode.dump(f); f->open_object_section("xattrs"); for (const auto &p : xattrs) { std::string v(p.second.c_str(), p.second.length()); f->dump_string(p.first.c_str(), v); } f->close_section(); } template<template<typename> class Allocator> void old_inode_t<Allocator>::generate_test_instances(std::list<old_inode_t<Allocator>*>& ls) { ls.push_back(new old_inode_t<Allocator>); ls.push_back(new old_inode_t<Allocator>); ls.back()->first = 2; std::list<inode_t<Allocator>*> ils; inode_t<Allocator>::generate_test_instances(ils); ls.back()->inode = *ils.back(); ls.back()->xattrs["user.foo"] = ceph::buffer::copy("asdf", 4); ls.back()->xattrs["user.unprintable"] = ceph::buffer::copy("\000\001\002", 3); } template<template<typename> class Allocator> inline void encode(const old_inode_t<Allocator> &c, ::ceph::buffer::list &bl, uint64_t features) { ENCODE_DUMP_PRE(); c.encode(bl, features); ENCODE_DUMP_POST(cl); } template<template<typename> class Allocator> inline void decode(old_inode_t<Allocator> &c, ::ceph::buffer::list::const_iterator &p) { c.decode(p); } /* * like an inode, but for a dir frag */ struct fnode_t { void encode(ceph::buffer::list &bl) const; void decode(ceph::buffer::list::const_iterator& bl); void dump(ceph::Formatter *f) const; void decode_json(JSONObj *obj); static void generate_test_instances(std::list<fnode_t*>& ls); version_t version = 0; snapid_t snap_purged_thru; // the max_last_destroy snapid we've been purged thru frag_info_t fragstat, accounted_fragstat; nest_info_t rstat, accounted_rstat; damage_flags_t damage_flags = 0; // we know we and all our descendants have been scrubbed since this version version_t recursive_scrub_version = 0; utime_t recursive_scrub_stamp; // version at which we last scrubbed our personal data structures version_t localized_scrub_version = 0; utime_t localized_scrub_stamp; }; WRITE_CLASS_ENCODER(fnode_t) struct old_rstat_t { void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator& p); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<old_rstat_t*>& ls); snapid_t first; nest_info_t rstat, accounted_rstat; }; WRITE_CLASS_ENCODER(old_rstat_t) inline std::ostream& operator<<(std::ostream& out, const old_rstat_t& o) { return out << "old_rstat(first " << o.first << " " << o.rstat << " " << o.accounted_rstat << ")"; } class feature_bitset_t { public: typedef uint64_t block_type; static const size_t bits_per_block = sizeof(block_type) * 8; feature_bitset_t(const feature_bitset_t& other) : _vec(other._vec) {} feature_bitset_t(feature_bitset_t&& other) : _vec(std::move(other._vec)) {} feature_bitset_t(unsigned long value = 0); feature_bitset_t(const std::vector<size_t>& array); feature_bitset_t& operator=(const feature_bitset_t& other) { _vec = other._vec; return *this; } feature_bitset_t& operator=(feature_bitset_t&& other) { _vec = std::move(other._vec); return *this; } feature_bitset_t& operator-=(const feature_bitset_t& other); bool empty() const { //block_type is a uint64_t. If the vector is only composed of 0s, then it's still "empty" for (auto& v : _vec) { if (v) return false; } return true; } bool test(size_t bit) const { if (bit >= bits_per_block * _vec.size()) return false; return _vec[bit / bits_per_block] & ((block_type)1 << (bit % bits_per_block)); } void insert(size_t bit) { size_t n = bit / bits_per_block; if (n >= _vec.size()) _vec.resize(n + 1); _vec[n] |= ((block_type)1 << (bit % bits_per_block)); } void erase(size_t bit) { size_t n = bit / bits_per_block; if (n >= _vec.size()) return; _vec[n] &= ~((block_type)1 << (bit % bits_per_block)); if (n + 1 == _vec.size()) { while (!_vec.empty() && _vec.back() == 0) _vec.pop_back(); } } void clear() { _vec.clear(); } bool operator==(const feature_bitset_t& other) const { return _vec == other._vec; } bool operator!=(const feature_bitset_t& other) const { return _vec != other._vec; } void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator &p); void dump(ceph::Formatter *f) const; void print(std::ostream& out) const; private: std::vector<block_type> _vec; }; WRITE_CLASS_ENCODER(feature_bitset_t) inline std::ostream& operator<<(std::ostream& out, const feature_bitset_t& s) { s.print(out); return out; } struct metric_spec_t { metric_spec_t() {} metric_spec_t(const metric_spec_t& other) : metric_flags(other.metric_flags) {} metric_spec_t(metric_spec_t&& other) : metric_flags(std::move(other.metric_flags)) {} metric_spec_t(const feature_bitset_t& mf) : metric_flags(mf) {} metric_spec_t(feature_bitset_t&& mf) : metric_flags(std::move(mf)) {} metric_spec_t& operator=(const metric_spec_t& other) { metric_flags = other.metric_flags; return *this; } metric_spec_t& operator=(metric_spec_t&& other) { metric_flags = std::move(other.metric_flags); return *this; } bool empty() const { return metric_flags.empty(); } void clear() { metric_flags.clear(); } void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator& p); void dump(ceph::Formatter *f) const; void print(std::ostream& out) const; // set of metrics that a client is capable of forwarding feature_bitset_t metric_flags; }; WRITE_CLASS_ENCODER(metric_spec_t) inline std::ostream& operator<<(std::ostream& out, const metric_spec_t& mst) { mst.print(out); return out; } /* * client_metadata_t */ struct client_metadata_t { using kv_map_t = std::map<std::string,std::string>; using iterator = kv_map_t::const_iterator; client_metadata_t() {} client_metadata_t(const kv_map_t& kv, const feature_bitset_t &f, const metric_spec_t &mst) : kv_map(kv), features(f), metric_spec(mst) {} client_metadata_t& operator=(const client_metadata_t& other) { kv_map = other.kv_map; features = other.features; metric_spec = other.metric_spec; return *this; } bool empty() const { return kv_map.empty() && features.empty() && metric_spec.empty(); } iterator find(const std::string& key) const { return kv_map.find(key); } iterator begin() const { return kv_map.begin(); } iterator end() const { return kv_map.end(); } void erase(iterator it) { kv_map.erase(it); } std::string& operator[](const std::string& key) { return kv_map[key]; } void merge(const client_metadata_t& other) { kv_map.insert(other.kv_map.begin(), other.kv_map.end()); features = other.features; metric_spec = other.metric_spec; } void clear() { kv_map.clear(); features.clear(); metric_spec.clear(); } void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator& p); void dump(ceph::Formatter *f) const; kv_map_t kv_map; feature_bitset_t features; metric_spec_t metric_spec; }; WRITE_CLASS_ENCODER(client_metadata_t) /* * session_info_t - durable part of a Session */ struct session_info_t { client_t get_client() const { return client_t(inst.name.num()); } bool has_feature(size_t bit) const { return client_metadata.features.test(bit); } const entity_name_t& get_source() const { return inst.name; } void clear_meta() { prealloc_inos.clear(); completed_requests.clear(); completed_flushes.clear(); client_metadata.clear(); } void encode(ceph::buffer::list& bl, uint64_t features) const; void decode(ceph::buffer::list::const_iterator& p); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<session_info_t*>& ls); entity_inst_t inst; std::map<ceph_tid_t,inodeno_t> completed_requests; interval_set<inodeno_t> prealloc_inos; // preallocated, ready to use. client_metadata_t client_metadata; std::set<ceph_tid_t> completed_flushes; EntityName auth_name; }; WRITE_CLASS_ENCODER_FEATURES(session_info_t) // dentries struct dentry_key_t { dentry_key_t() {} dentry_key_t(snapid_t s, std::string_view n, __u32 h=0) : snapid(s), name(n), hash(h) {} bool is_valid() { return name.length() || snapid; } // encode into something that can be decoded as a string. // name_ (head) or name_%x (!head) void encode(ceph::buffer::list& bl) const { std::string key; encode(key); using ceph::encode; encode(key, bl); } void encode(std::string& key) const { char b[20]; if (snapid != CEPH_NOSNAP) { uint64_t val(snapid); snprintf(b, sizeof(b), "%" PRIx64, val); } else { snprintf(b, sizeof(b), "%s", "head"); } CachedStackStringStream css; *css << name << "_" << b; key = css->strv(); } static void decode_helper(ceph::buffer::list::const_iterator& bl, std::string& nm, snapid_t& sn) { std::string key; using ceph::decode; decode(key, bl); decode_helper(key, nm, sn); } static void decode_helper(std::string_view key, std::string& nm, snapid_t& sn) { size_t i = key.find_last_of('_'); ceph_assert(i != std::string::npos); if (key.compare(i+1, std::string_view::npos, "head") == 0) { // name_head sn = CEPH_NOSNAP; } else { // name_%x long long unsigned x = 0; std::string x_str(key.substr(i+1)); sscanf(x_str.c_str(), "%llx", &x); sn = x; } nm = key.substr(0, i); } snapid_t snapid = 0; std::string_view name; __u32 hash = 0; }; inline std::ostream& operator<<(std::ostream& out, const dentry_key_t &k) { return out << "(" << k.name << "," << k.snapid << ")"; } inline bool operator<(const dentry_key_t& k1, const dentry_key_t& k2) { /* * order by hash, name, snap */ int c = ceph_frag_value(k1.hash) - ceph_frag_value(k2.hash); if (c) return c < 0; c = k1.name.compare(k2.name); if (c) return c < 0; return k1.snapid < k2.snapid; } /* * string_snap_t is a simple (string, snapid_t) pair */ struct string_snap_t { string_snap_t() {} string_snap_t(std::string_view n, snapid_t s) : name(n), snapid(s) {} int compare(const string_snap_t& r) const { int ret = name.compare(r.name); if (ret) return ret; if (snapid == r.snapid) return 0; return snapid > r.snapid ? 1 : -1; } void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator& p); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<string_snap_t*>& ls); std::string name; snapid_t snapid; }; WRITE_CLASS_ENCODER(string_snap_t) inline bool operator==(const string_snap_t& l, const string_snap_t& r) { return l.name == r.name && l.snapid == r.snapid; } inline bool operator<(const string_snap_t& l, const string_snap_t& r) { int c = l.name.compare(r.name); return c < 0 || (c == 0 && l.snapid < r.snapid); } inline std::ostream& operator<<(std::ostream& out, const string_snap_t &k) { return out << "(" << k.name << "," << k.snapid << ")"; } /* * mds_table_pending_t * * For mds's requesting any pending ops, child needs to encode the corresponding * pending mutation state in the table. */ struct mds_table_pending_t { void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator& bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<mds_table_pending_t*>& ls); uint64_t reqid = 0; __s32 mds = 0; version_t tid = 0; }; WRITE_CLASS_ENCODER(mds_table_pending_t) // requests struct metareqid_t { metareqid_t() {} metareqid_t(entity_name_t n, ceph_tid_t t) : name(n), tid(t) {} void encode(ceph::buffer::list& bl) const { using ceph::encode; encode(name, bl); encode(tid, bl); } void decode(ceph::buffer::list::const_iterator &p) { using ceph::decode; decode(name, p); decode(tid, p); } entity_name_t name; uint64_t tid = 0; }; WRITE_CLASS_ENCODER(metareqid_t) inline std::ostream& operator<<(std::ostream& out, const metareqid_t& r) { return out << r.name << ":" << r.tid; } inline bool operator==(const metareqid_t& l, const metareqid_t& r) { return (l.name == r.name) && (l.tid == r.tid); } inline bool operator!=(const metareqid_t& l, const metareqid_t& r) { return (l.name != r.name) || (l.tid != r.tid); } inline bool operator<(const metareqid_t& l, const metareqid_t& r) { return (l.name < r.name) || (l.name == r.name && l.tid < r.tid); } inline bool operator<=(const metareqid_t& l, const metareqid_t& r) { return (l.name < r.name) || (l.name == r.name && l.tid <= r.tid); } inline bool operator>(const metareqid_t& l, const metareqid_t& r) { return !(l <= r); } inline bool operator>=(const metareqid_t& l, const metareqid_t& r) { return !(l < r); } namespace std { template<> struct hash<metareqid_t> { size_t operator()(const metareqid_t &r) const { hash<uint64_t> H; return H(r.name.num()) ^ H(r.name.type()) ^ H(r.tid); } }; } // namespace std // cap info for client reconnect struct cap_reconnect_t { cap_reconnect_t() {} cap_reconnect_t(uint64_t cap_id, inodeno_t pino, std::string_view p, int w, int i, inodeno_t sr, snapid_t sf, ceph::buffer::list& lb) : path(p) { capinfo.cap_id = cap_id; capinfo.wanted = w; capinfo.issued = i; capinfo.snaprealm = sr; capinfo.pathbase = pino; capinfo.flock_len = 0; snap_follows = sf; flockbl = std::move(lb); } void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator& bl); void encode_old(ceph::buffer::list& bl) const; void decode_old(ceph::buffer::list::const_iterator& bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<cap_reconnect_t*>& ls); std::string path; mutable ceph_mds_cap_reconnect capinfo = {}; snapid_t snap_follows = 0; ceph::buffer::list flockbl; }; WRITE_CLASS_ENCODER(cap_reconnect_t) struct snaprealm_reconnect_t { snaprealm_reconnect_t() {} snaprealm_reconnect_t(inodeno_t ino, snapid_t seq, inodeno_t parent) { realm.ino = ino; realm.seq = seq; realm.parent = parent; } void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator& bl); void encode_old(ceph::buffer::list& bl) const; void decode_old(ceph::buffer::list::const_iterator& bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<snaprealm_reconnect_t*>& ls); mutable ceph_mds_snaprealm_reconnect realm = {}; }; WRITE_CLASS_ENCODER(snaprealm_reconnect_t) // compat for pre-FLOCK feature struct old_ceph_mds_cap_reconnect { ceph_le64 cap_id; ceph_le32 wanted; ceph_le32 issued; ceph_le64 old_size; struct ceph_timespec old_mtime, old_atime; ceph_le64 snaprealm; ceph_le64 pathbase; /* base ino for our path to this ino */ } __attribute__ ((packed)); WRITE_RAW_ENCODER(old_ceph_mds_cap_reconnect) struct old_cap_reconnect_t { const old_cap_reconnect_t& operator=(const cap_reconnect_t& n) { path = n.path; capinfo.cap_id = n.capinfo.cap_id; capinfo.wanted = n.capinfo.wanted; capinfo.issued = n.capinfo.issued; capinfo.snaprealm = n.capinfo.snaprealm; capinfo.pathbase = n.capinfo.pathbase; return *this; } operator cap_reconnect_t() { cap_reconnect_t n; n.path = path; n.capinfo.cap_id = capinfo.cap_id; n.capinfo.wanted = capinfo.wanted; n.capinfo.issued = capinfo.issued; n.capinfo.snaprealm = capinfo.snaprealm; n.capinfo.pathbase = capinfo.pathbase; return n; } void encode(ceph::buffer::list& bl) const { using ceph::encode; encode(path, bl); encode(capinfo, bl); } void decode(ceph::buffer::list::const_iterator& bl) { using ceph::decode; decode(path, bl); decode(capinfo, bl); } std::string path; old_ceph_mds_cap_reconnect capinfo; }; WRITE_CLASS_ENCODER(old_cap_reconnect_t) // dir frag struct dirfrag_t { dirfrag_t() {} dirfrag_t(inodeno_t i, frag_t f) : ino(i), frag(f) { } void encode(ceph::buffer::list& bl) const { using ceph::encode; encode(ino, bl); encode(frag, bl); } void decode(ceph::buffer::list::const_iterator& bl) { using ceph::decode; decode(ino, bl); decode(frag, bl); } inodeno_t ino = 0; frag_t frag; }; WRITE_CLASS_ENCODER(dirfrag_t) inline std::ostream& operator<<(std::ostream& out, const dirfrag_t &df) { out << df.ino; if (!df.frag.is_root()) out << "." << df.frag; return out; } inline bool operator<(dirfrag_t l, dirfrag_t r) { if (l.ino < r.ino) return true; if (l.ino == r.ino && l.frag < r.frag) return true; return false; } inline bool operator==(dirfrag_t l, dirfrag_t r) { return l.ino == r.ino && l.frag == r.frag; } namespace std { template<> struct hash<dirfrag_t> { size_t operator()(const dirfrag_t &df) const { static rjhash<uint64_t> H; static rjhash<uint32_t> I; return H(df.ino) ^ I(df.frag); } }; } // namespace std // ================================================================ #define META_POP_IRD 0 #define META_POP_IWR 1 #define META_POP_READDIR 2 #define META_POP_FETCH 3 #define META_POP_STORE 4 #define META_NPOP 5 class inode_load_vec_t { public: using time = DecayCounter::time; using clock = DecayCounter::clock; static const size_t NUM = 2; inode_load_vec_t() : vec{DecayCounter(DecayRate()), DecayCounter(DecayRate())} {} inode_load_vec_t(const DecayRate &rate) : vec{DecayCounter(rate), DecayCounter(rate)} {} DecayCounter &get(int t) { return vec[t]; } void zero() { for (auto &d : vec) { d.reset(); } } void encode(ceph::buffer::list &bl) const; void decode(ceph::buffer::list::const_iterator& p); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<inode_load_vec_t*>& ls); private: std::array<DecayCounter, NUM> vec; }; inline void encode(const inode_load_vec_t &c, ceph::buffer::list &bl) { c.encode(bl); } inline void decode(inode_load_vec_t & c, ceph::buffer::list::const_iterator &p) { c.decode(p); } class dirfrag_load_vec_t { public: using time = DecayCounter::time; using clock = DecayCounter::clock; static const size_t NUM = 5; dirfrag_load_vec_t() : vec{DecayCounter(DecayRate()), DecayCounter(DecayRate()), DecayCounter(DecayRate()), DecayCounter(DecayRate()), DecayCounter(DecayRate()) } {} dirfrag_load_vec_t(const DecayRate &rate) : vec{DecayCounter(rate), DecayCounter(rate), DecayCounter(rate), DecayCounter(rate), DecayCounter(rate)} {} void encode(ceph::buffer::list &bl) const { ENCODE_START(2, 2, bl); for (const auto &i : vec) { encode(i, bl); } ENCODE_FINISH(bl); } void decode(ceph::buffer::list::const_iterator &p) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, p); for (auto &i : vec) { decode(i, p); } DECODE_FINISH(p); } void dump(ceph::Formatter *f) const; void dump(ceph::Formatter *f, const DecayRate& rate) const; static void generate_test_instances(std::list<dirfrag_load_vec_t*>& ls); const DecayCounter &get(int t) const { return vec[t]; } DecayCounter &get(int t) { return vec[t]; } void adjust(double d) { for (auto &i : vec) { i.adjust(d); } } void zero() { for (auto &i : vec) { i.reset(); } } double meta_load() const { return 1*vec[META_POP_IRD].get() + 2*vec[META_POP_IWR].get() + 1*vec[META_POP_READDIR].get() + 2*vec[META_POP_FETCH].get() + 4*vec[META_POP_STORE].get(); } void add(dirfrag_load_vec_t& r) { for (size_t i=0; i<dirfrag_load_vec_t::NUM; i++) vec[i].adjust(r.vec[i].get()); } void sub(dirfrag_load_vec_t& r) { for (size_t i=0; i<dirfrag_load_vec_t::NUM; i++) vec[i].adjust(-r.vec[i].get()); } void scale(double f) { for (size_t i=0; i<dirfrag_load_vec_t::NUM; i++) vec[i].scale(f); } private: friend inline std::ostream& operator<<(std::ostream& out, const dirfrag_load_vec_t& dl); std::array<DecayCounter, NUM> vec; }; inline void encode(const dirfrag_load_vec_t &c, ceph::buffer::list &bl) { c.encode(bl); } inline void decode(dirfrag_load_vec_t& c, ceph::buffer::list::const_iterator &p) { c.decode(p); } inline std::ostream& operator<<(std::ostream& out, const dirfrag_load_vec_t& dl) { CachedStackStringStream css; *css << std::setprecision(1) << std::fixed << "[pop" " IRD:" << dl.vec[0] << " IWR:" << dl.vec[1] << " RDR:" << dl.vec[2] << " FET:" << dl.vec[3] << " STR:" << dl.vec[4] << " *LOAD:" << dl.meta_load() << "]"; return out << css->strv(); } struct mds_load_t { using clock = dirfrag_load_vec_t::clock; using time = dirfrag_load_vec_t::time; dirfrag_load_vec_t auth; dirfrag_load_vec_t all; mds_load_t() : auth(DecayRate()), all(DecayRate()) {} mds_load_t(const DecayRate &rate) : auth(rate), all(rate) {} double req_rate = 0.0; double cache_hit_rate = 0.0; double queue_len = 0.0; double cpu_load_avg = 0.0; double mds_load() const; // defiend in MDBalancer.cc void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator& bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<mds_load_t*>& ls); }; inline void encode(const mds_load_t &c, ceph::buffer::list &bl) { c.encode(bl); } inline void decode(mds_load_t &c, ceph::buffer::list::const_iterator &p) { c.decode(p); } inline std::ostream& operator<<(std::ostream& out, const mds_load_t& load) { return out << "mdsload<" << load.auth << "/" << load.all << ", req " << load.req_rate << ", hr " << load.cache_hit_rate << ", qlen " << load.queue_len << ", cpu " << load.cpu_load_avg << ">"; } // ================================================================ typedef std::pair<mds_rank_t, mds_rank_t> mds_authority_t; // -- authority delegation -- // directory authority types // >= 0 is the auth mds #define CDIR_AUTH_PARENT mds_rank_t(-1) // default #define CDIR_AUTH_UNKNOWN mds_rank_t(-2) #define CDIR_AUTH_DEFAULT mds_authority_t(CDIR_AUTH_PARENT, CDIR_AUTH_UNKNOWN) #define CDIR_AUTH_UNDEF mds_authority_t(CDIR_AUTH_UNKNOWN, CDIR_AUTH_UNKNOWN) //#define CDIR_AUTH_ROOTINODE pair<int,int>( 0, -2) class MDSCacheObjectInfo { public: void encode(ceph::buffer::list& bl) const; void decode(ceph::buffer::list::const_iterator& bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<MDSCacheObjectInfo*>& ls); inodeno_t ino = 0; dirfrag_t dirfrag; std::string dname; snapid_t snapid; }; inline std::ostream& operator<<(std::ostream& out, const MDSCacheObjectInfo &info) { if (info.ino) return out << info.ino << "." << info.snapid; if (info.dname.length()) return out << info.dirfrag << "/" << info.dname << " snap " << info.snapid; return out << info.dirfrag; } inline bool operator==(const MDSCacheObjectInfo& l, const MDSCacheObjectInfo& r) { if (l.ino || r.ino) return l.ino == r.ino && l.snapid == r.snapid; else return l.dirfrag == r.dirfrag && l.dname == r.dname; } WRITE_CLASS_ENCODER(MDSCacheObjectInfo) #endif
29,502
27.839687
111
h
null
ceph-main/src/mds/snap.cc
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004- Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #include <string_view> #include "snap.h" #include "common/Formatter.h" using namespace std; /* * SnapInfo */ void SnapInfo::encode(bufferlist& bl) const { ENCODE_START(4, 2, bl); encode(snapid, bl); encode(ino, bl); encode(stamp, bl); encode(name, bl); encode(metadata, bl); encode(alternate_name, bl); ENCODE_FINISH(bl); } void SnapInfo::decode(bufferlist::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(4, 2, 2, bl); decode(snapid, bl); decode(ino, bl); decode(stamp, bl); decode(name, bl); if (struct_v >= 3) { decode(metadata, bl); } if (struct_v >= 4) { decode(alternate_name, bl); } DECODE_FINISH(bl); } void SnapInfo::dump(Formatter *f) const { f->dump_unsigned("snapid", snapid); f->dump_unsigned("ino", ino); f->dump_stream("stamp") << stamp; f->dump_string("name", name); f->open_object_section("metadata"); for (auto &[key, value] : metadata) { f->dump_string(key, value); } f->close_section(); } void SnapInfo::generate_test_instances(std::list<SnapInfo*>& ls) { ls.push_back(new SnapInfo); ls.push_back(new SnapInfo); ls.back()->snapid = 1; ls.back()->ino = 2; ls.back()->stamp = utime_t(3, 4); ls.back()->name = "foo"; ls.back()->metadata = {{"foo", "bar"}}; } ostream& operator<<(ostream& out, const SnapInfo &sn) { return out << "snap(" << sn.snapid << " " << sn.ino << " '" << sn.name << "' " << sn.stamp << ")"; } std::string_view SnapInfo::get_long_name() const { if (long_name.empty() || long_name.compare(1, name.size(), name) || long_name.find_last_of("_") != name.size() + 1) { std::ostringstream oss; oss << "_" << name << "_" << (unsigned long long)ino; long_name = oss.str(); } return long_name; } /* * snaplink_t */ void snaplink_t::encode(bufferlist& bl) const { ENCODE_START(2, 2, bl); encode(ino, bl); encode(first, bl); ENCODE_FINISH(bl); } void snaplink_t::decode(bufferlist::const_iterator& bl) { DECODE_START_LEGACY_COMPAT_LEN(2, 2, 2, bl); decode(ino, bl); decode(first, bl); DECODE_FINISH(bl); } void snaplink_t::dump(Formatter *f) const { f->dump_unsigned("ino", ino); f->dump_unsigned("first", first); } void snaplink_t::generate_test_instances(std::list<snaplink_t*>& ls) { ls.push_back(new snaplink_t); ls.push_back(new snaplink_t); ls.back()->ino = 2; ls.back()->first = 123; } ostream& operator<<(ostream& out, const snaplink_t &l) { return out << l.ino << "@" << l.first; } /* * sr_t */ void sr_t::encode(bufferlist& bl) const { ENCODE_START(7, 4, bl); encode(seq, bl); encode(created, bl); encode(last_created, bl); encode(last_destroyed, bl); encode(current_parent_since, bl); encode(snaps, bl); encode(past_parents, bl); encode(past_parent_snaps, bl); encode(flags, bl); encode(last_modified, bl); encode(change_attr, bl); ENCODE_FINISH(bl); } void sr_t::decode(bufferlist::const_iterator& p) { DECODE_START_LEGACY_COMPAT_LEN(6, 4, 4, p); if (struct_v == 2) { __u8 struct_v; decode(struct_v, p); // yes, really: extra byte for v2 encoding only, see 6ee52e7d. } decode(seq, p); decode(created, p); decode(last_created, p); decode(last_destroyed, p); decode(current_parent_since, p); decode(snaps, p); decode(past_parents, p); if (struct_v >= 5) decode(past_parent_snaps, p); if (struct_v >= 6) decode(flags, p); else flags = 0; if (struct_v >= 7) { decode(last_modified, p); decode(change_attr, p); } DECODE_FINISH(p); } void sr_t::dump(Formatter *f) const { f->dump_unsigned("seq", seq); f->dump_unsigned("created", created); f->dump_unsigned("last_created", last_created); f->dump_unsigned("last_destroyed", last_destroyed); f->dump_stream("last_modified") << last_modified; f->dump_unsigned("change_attr", change_attr); f->dump_unsigned("current_parent_since", current_parent_since); f->open_array_section("snaps"); for (map<snapid_t,SnapInfo>::const_iterator p = snaps.begin(); p != snaps.end(); ++p) { f->open_object_section("snapinfo"); f->dump_unsigned("last", p->first); p->second.dump(f); f->close_section(); } f->close_section(); f->open_array_section("past_parents"); for (map<snapid_t,snaplink_t>::const_iterator p = past_parents.begin(); p != past_parents.end(); ++p) { f->open_object_section("past_parent"); f->dump_unsigned("last", p->first); p->second.dump(f); f->close_section(); } f->close_section(); f->open_array_section("past_parent_snaps"); for (auto p = past_parent_snaps.begin(); p != past_parent_snaps.end(); ++p) { f->open_object_section("snapinfo"); f->dump_unsigned("snapid", *p); f->close_section(); } f->close_section(); } void sr_t::generate_test_instances(std::list<sr_t*>& ls) { ls.push_back(new sr_t); ls.push_back(new sr_t); ls.back()->seq = 1; ls.back()->created = 2; ls.back()->last_created = 3; ls.back()->last_destroyed = 4; ls.back()->current_parent_since = 5; ls.back()->snaps[123].snapid = 7; ls.back()->snaps[123].ino = 8; ls.back()->snaps[123].stamp = utime_t(9, 10); ls.back()->snaps[123].name = "name1"; ls.back()->past_parents[12].ino = 12; ls.back()->past_parents[12].first = 3; ls.back()->past_parent_snaps.insert(5); ls.back()->past_parent_snaps.insert(6); ls.back()->last_modified = utime_t(9, 10); ls.back()->change_attr++; }
5,846
22.963115
105
cc
null
ceph-main/src/mds/snap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_SNAP_H #define CEPH_MDS_SNAP_H #include <map> #include <string_view> #include "mdstypes.h" #include "common/snap_types.h" #include "Capability.h" /* * generic snap descriptor. */ struct SnapInfo { void encode(ceph::buffer::list &bl) const; void decode(ceph::buffer::list::const_iterator &bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<SnapInfo*>& ls); std::string_view get_long_name() const; snapid_t snapid; inodeno_t ino; utime_t stamp; std::string name; std::string alternate_name; mutable std::string long_name; ///< cached _$ino_$name std::map<std::string,std::string> metadata; }; WRITE_CLASS_ENCODER(SnapInfo) inline bool operator==(const SnapInfo &l, const SnapInfo &r) { return l.snapid == r.snapid && l.ino == r.ino && l.stamp == r.stamp && l.name == r.name; } std::ostream& operator<<(std::ostream& out, const SnapInfo &sn); /* * SnapRealm - a subtree that shares the same set of snapshots. */ struct SnapRealm; struct snaplink_t { void encode(ceph::buffer::list &bl) const; void decode(ceph::buffer::list::const_iterator &bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<snaplink_t*>& ls); inodeno_t ino; snapid_t first; }; WRITE_CLASS_ENCODER(snaplink_t) std::ostream& operator<<(std::ostream& out, const snaplink_t &l); // carry data about a specific version of a SnapRealm struct sr_t { void mark_parent_global() { flags |= PARENT_GLOBAL; } void clear_parent_global() { flags &= ~PARENT_GLOBAL; } bool is_parent_global() const { return flags & PARENT_GLOBAL; } void mark_subvolume() { flags |= SUBVOLUME; } void clear_subvolume() { flags &= ~SUBVOLUME; } bool is_subvolume() const { return flags & SUBVOLUME; } void encode(ceph::buffer::list &bl) const; void decode(ceph::buffer::list::const_iterator &bl); void dump(ceph::Formatter *f) const; static void generate_test_instances(std::list<sr_t*>& ls); snapid_t seq = 0; // basically, a version/seq # for changes to _this_ realm. snapid_t created = 0; // when this realm was created. snapid_t last_created = 0; // last snap created in _this_ realm. snapid_t last_destroyed = 0; // seq for last removal snapid_t current_parent_since = 1; std::map<snapid_t, SnapInfo> snaps; std::map<snapid_t, snaplink_t> past_parents; // key is "last" (or NOSNAP) std::set<snapid_t> past_parent_snaps; utime_t last_modified; // timestamp when this realm // was last changed. uint64_t change_attr = 0; // tracks changes to snap // realm attrs. __u32 flags = 0; enum { PARENT_GLOBAL = 1 << 0, SUBVOLUME = 1 << 1, }; }; WRITE_CLASS_ENCODER(sr_t) class MDCache; #endif
3,321
28.660714
98
h
null
ceph-main/src/mds/balancers/greedyspill.lua
local metrics = {"auth.meta_load", "all.meta_load", "req_rate", "queue_len", "cpu_load_avg"} -- Metric for balancing is the workload; also dumps metrics local function mds_load() for rank, mds in pairs(mds) do local s = "MDS"..rank..": < " for _, metric in ipairs(metrics) do s = s..metric.."="..mds[metric].." " end mds.load = mds["all.meta_load"] BAL_LOG(5, s.."> load="..mds.load) end end -- Shed load when you have load and your neighbor doesn't local function when() if not mds[whoami+1] then -- i'm the last rank BAL_LOG(5, "when: not migrating! I am the last rank, nothing to spill to."); return false end my_load = mds[whoami]["load"] his_load = mds[whoami+1]["load"] if my_load > 0.01 and his_load < 0.01 then BAL_LOG(5, "when: migrating! my_load="..my_load.." hisload="..his_load) return true end BAL_LOG(5, "when: not migrating! my_load="..my_load.." hisload="..his_load) return false end -- Shed half your load to your neighbor -- neighbor=whoami+2 because Lua tables are indexed starting at 1 local function where(targets) targets[whoami+1] = mds[whoami]["load"]/2 return targets end local targets = {} for rank in pairs(mds) do targets[rank] = 0 end mds_load() if when() then where(targets) end return targets
1,304
25.1
92
lua
null
ceph-main/src/mds/events/ECommitted.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_ECOMMITTED_H #define CEPH_MDS_ECOMMITTED_H #include "../LogEvent.h" #include "EMetaBlob.h" class ECommitted : public LogEvent { public: metareqid_t reqid; ECommitted() : LogEvent(EVENT_COMMITTED) { } explicit ECommitted(metareqid_t r) : LogEvent(EVENT_COMMITTED), reqid(r) { } void print(std::ostream& out) const override { out << "ECommitted " << reqid; } void encode(bufferlist &bl, uint64_t features) const override; void decode(bufferlist::const_iterator &bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<ECommitted*>& ls); void update_segment() override {} void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(ECommitted) #endif
1,183
25.909091
71
h
null
ceph-main/src/mds/events/EExport.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_EEXPORT_H #define CEPH_EEXPORT_H #include "common/config.h" #include "include/types.h" #include "../MDSRank.h" #include "EMetaBlob.h" #include "../LogEvent.h" class EExport : public LogEvent { public: EMetaBlob metablob; // exported dir protected: dirfrag_t base; std::set<dirfrag_t> bounds; mds_rank_t target; public: EExport() : LogEvent(EVENT_EXPORT), target(MDS_RANK_NONE) { } EExport(MDLog *mdlog, CDir *dir, mds_rank_t t) : LogEvent(EVENT_EXPORT), base(dir->dirfrag()), target(t) { } std::set<dirfrag_t> &get_bounds() { return bounds; } void print(std::ostream& out) const override { out << "EExport " << base << " to mds." << target << " " << metablob; } EMetaBlob *get_metablob() override { return &metablob; } void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator &bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<EExport*>& ls); void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(EExport) #endif
1,532
24.983051
73
h
null
ceph-main/src/mds/events/EFragment.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_EFRAGMENT_H #define CEPH_MDS_EFRAGMENT_H #include "../LogEvent.h" #include "EMetaBlob.h" struct dirfrag_rollback { CDir::fnode_const_ptr fnode; dirfrag_rollback() { } void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& bl); }; WRITE_CLASS_ENCODER(dirfrag_rollback) class EFragment : public LogEvent { public: EMetaBlob metablob; __u8 op{0}; inodeno_t ino; frag_t basefrag; __s32 bits{0}; // positive for split (from basefrag), negative for merge (to basefrag) frag_vec_t orig_frags; bufferlist rollback; EFragment() : LogEvent(EVENT_FRAGMENT) { } EFragment(MDLog *mdlog, int o, dirfrag_t df, int b) : LogEvent(EVENT_FRAGMENT), op(o), ino(df.ino), basefrag(df.frag), bits(b) { } void print(std::ostream& out) const override { out << "EFragment " << op_name(op) << " " << ino << " " << basefrag << " by " << bits << " " << metablob; } enum { OP_PREPARE = 1, OP_COMMIT = 2, OP_ROLLBACK = 3, OP_FINISH = 4 // finish deleting orphan dirfrags }; static std::string_view op_name(int o) { switch (o) { case OP_PREPARE: return "prepare"; case OP_COMMIT: return "commit"; case OP_ROLLBACK: return "rollback"; case OP_FINISH: return "finish"; default: return "???"; } } void add_orig_frag(frag_t df, dirfrag_rollback *drb=NULL) { using ceph::encode; orig_frags.push_back(df); if (drb) encode(*drb, rollback); } EMetaBlob *get_metablob() override { return &metablob; } void encode(bufferlist &bl, uint64_t features) const override; void decode(bufferlist::const_iterator &bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<EFragment*>& ls); void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(EFragment) #endif
2,279
26.804878
109
h
null
ceph-main/src/mds/events/EImportFinish.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_EIMPORTFINISH_H #define CEPH_EIMPORTFINISH_H #include "common/config.h" #include "include/types.h" #include "../MDSRank.h" #include "../LogEvent.h" class EImportFinish : public LogEvent { protected: dirfrag_t base; // imported dir bool success; public: EImportFinish(CDir *dir, bool s) : LogEvent(EVENT_IMPORTFINISH), base(dir->dirfrag()), success(s) { } EImportFinish() : LogEvent(EVENT_IMPORTFINISH), base(), success(false) { } void print(std::ostream& out) const override { out << "EImportFinish " << base; if (success) out << " success"; else out << " failed"; } void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator &bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<EImportFinish*>& ls); void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(EImportFinish) #endif
1,404
25.018519
76
h
null
ceph-main/src/mds/events/EImportStart.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_EIMPORTSTART_H #define CEPH_EIMPORTSTART_H #include "common/config.h" #include "include/types.h" class MDLog; class MDSRank; #include "EMetaBlob.h" #include "../LogEvent.h" class EImportStart : public LogEvent { protected: dirfrag_t base; std::vector<dirfrag_t> bounds; mds_rank_t from; public: EMetaBlob metablob; bufferlist client_map; // encoded map<__u32,entity_inst_t> version_t cmapv{0}; EImportStart(MDLog *log, dirfrag_t di, const std::vector<dirfrag_t>& b, mds_rank_t f) : LogEvent(EVENT_IMPORTSTART), base(di), bounds(b), from(f) { } EImportStart() : LogEvent(EVENT_IMPORTSTART), from(MDS_RANK_NONE) { } void print(std::ostream& out) const override { out << "EImportStart " << base << " from mds." << from << " " << metablob; } EMetaBlob *get_metablob() override { return &metablob; } void encode(bufferlist &bl, uint64_t features) const override; void decode(bufferlist::const_iterator &bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<EImportStart*>& ls); void update_segment() override; void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(EImportStart) #endif
1,651
25.645161
89
h
null
ceph-main/src/mds/events/EMetaBlob.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_EMETABLOB_H #define CEPH_MDS_EMETABLOB_H #include <string_view> #include "../CInode.h" #include "../CDir.h" #include "../CDentry.h" #include "../LogSegment.h" #include "include/interval_set.h" #include "common/strescape.h" class MDSRank; class MDLog; class LogSegment; struct MDPeerUpdate; /* * a bunch of metadata in the journal */ /* notes: * * - make sure you adjust the inode.version for any modified inode you * journal. CDir and CDentry maintain a projected_version, but CInode * doesn't, since the journaled inode usually has to be modified * manually anyway (to delay the change in the MDS's cache until after * it is journaled). * */ class EMetaBlob { public: /* fullbit - a regular dentry + inode * * We encode this one a bit weirdly, just because (also, it's marginally faster * on multiple encodes, which I think can happen): * Encode a bufferlist on struct creation with all data members, without a struct_v. * When encode is called, encode struct_v and then append the bufferlist. * Decode straight into the appropriate variables. * * So, if you add members, encode them in the constructor and then change * the struct_v in the encode function! */ struct fullbit { static const int STATE_DIRTY = (1<<0); static const int STATE_DIRTYPARENT = (1<<1); static const int STATE_DIRTYPOOL = (1<<2); static const int STATE_NEED_SNAPFLUSH = (1<<3); static const int STATE_EPHEMERAL_RANDOM = (1<<4); std::string dn; // dentry std::string alternate_name; snapid_t dnfirst, dnlast; version_t dnv{0}; CInode::inode_const_ptr inode; // if it's not XXX should not be part of mempool; wait for std::pmr to simplify CInode::xattr_map_const_ptr xattrs; fragtree_t dirfragtree; std::string symlink; snapid_t oldest_snap; bufferlist snapbl; __u8 state{0}; CInode::old_inode_map_const_ptr old_inodes; // XXX should not be part of mempool; wait for std::pmr to simplify fullbit(std::string_view d, std::string_view an, snapid_t df, snapid_t dl, version_t v, const CInode::inode_const_ptr& i, const fragtree_t &dft, const CInode::xattr_map_const_ptr& xa, std::string_view sym, snapid_t os, const bufferlist &sbl, __u8 st, const CInode::old_inode_map_const_ptr& oi) : dn(d), alternate_name(an), dnfirst(df), dnlast(dl), dnv(v), inode(i), xattrs(xa), oldest_snap(os), state(st), old_inodes(oi) { if (i->is_symlink()) symlink = sym; if (i->is_dir()) dirfragtree = dft; snapbl = sbl; } explicit fullbit(bufferlist::const_iterator &p) { decode(p); } fullbit() = default; fullbit(const fullbit&) = delete; ~fullbit() {} fullbit& operator=(const fullbit&) = delete; void encode(bufferlist& bl, uint64_t features) const; void decode(bufferlist::const_iterator &bl); void dump(Formatter *f) const; static void generate_test_instances(std::list<EMetaBlob::fullbit*>& ls); void update_inode(MDSRank *mds, CInode *in); bool is_dirty() const { return (state & STATE_DIRTY); } bool is_dirty_parent() const { return (state & STATE_DIRTYPARENT); } bool is_dirty_pool() const { return (state & STATE_DIRTYPOOL); } bool need_snapflush() const { return (state & STATE_NEED_SNAPFLUSH); } bool is_export_ephemeral_random() const { return (state & STATE_EPHEMERAL_RANDOM); } void print(std::ostream& out) const { out << " fullbit dn " << dn << " [" << dnfirst << "," << dnlast << "] dnv " << dnv << " inode " << inode->ino << " state=" << state; if (!alternate_name.empty()) { out << " altn " << binstrprint(alternate_name, 8); } out << std::endl; } std::string state_string() const { std::string state_string; bool marked_already = false; if (is_dirty()) { state_string.append("dirty"); marked_already = true; } if (is_dirty_parent()) { state_string.append(marked_already ? "+dirty_parent" : "dirty_parent"); if (is_dirty_pool()) state_string.append("+dirty_pool"); } return state_string; } }; WRITE_CLASS_ENCODER_FEATURES(fullbit) /* remotebit - a dentry + remote inode link (i.e. just an ino) */ struct remotebit { std::string dn; std::string alternate_name; snapid_t dnfirst = 0, dnlast = 0; version_t dnv = 0; inodeno_t ino = 0; unsigned char d_type = '\0'; bool dirty = false; remotebit(std::string_view d, std::string_view an, snapid_t df, snapid_t dl, version_t v, inodeno_t i, unsigned char dt, bool dr) : dn(d), alternate_name(an), dnfirst(df), dnlast(dl), dnv(v), ino(i), d_type(dt), dirty(dr) { } explicit remotebit(bufferlist::const_iterator &p) { decode(p); } remotebit() = default; void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator &bl); void print(std::ostream& out) const { out << " remotebit dn " << dn << " [" << dnfirst << "," << dnlast << "] dnv " << dnv << " ino " << ino << " dirty=" << dirty; if (!alternate_name.empty()) { out << " altn " << binstrprint(alternate_name, 8); } out << std::endl; } void dump(Formatter *f) const; static void generate_test_instances(std::list<remotebit*>& ls); }; WRITE_CLASS_ENCODER(remotebit) /* * nullbit - a null dentry */ struct nullbit { std::string dn; snapid_t dnfirst, dnlast; version_t dnv; bool dirty; 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::const_iterator &p) { decode(p); } nullbit(): dnfirst(0), dnlast(0), dnv(0), dirty(false) {} void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator &bl); void dump(Formatter *f) const; static void generate_test_instances(std::list<nullbit*>& ls); void print(std::ostream& out) const { out << " nullbit dn " << dn << " [" << dnfirst << "," << dnlast << "] dnv " << dnv << " dirty=" << dirty << std::endl; } }; WRITE_CLASS_ENCODER(nullbit) /* dirlump - contains metadata for any dir we have contents for. */ public: struct dirlump { static const int STATE_COMPLETE = (1<<1); static const int STATE_DIRTY = (1<<2); // dirty due to THIS journal item, that is! static const int STATE_NEW = (1<<3); // new directory static const int STATE_IMPORTING = (1<<4); // importing directory static const int STATE_DIRTYDFT = (1<<5); // dirty dirfragtree //version_t dirv; CDir::fnode_const_ptr fnode; __u32 state; __u32 nfull, nremote, nnull; private: mutable bufferlist dnbl; mutable bool dn_decoded; mutable std::list<fullbit> dfull; mutable std::vector<remotebit> dremote; mutable std::vector<nullbit> dnull; public: dirlump() : state(0), nfull(0), nremote(0), nnull(0), dn_decoded(true) { } dirlump(const dirlump&) = delete; dirlump& operator=(const dirlump&) = delete; bool is_complete() const { return state & STATE_COMPLETE; } void mark_complete() { state |= STATE_COMPLETE; } bool is_dirty() const { return state & STATE_DIRTY; } void mark_dirty() { state |= STATE_DIRTY; } bool is_new() const { return state & STATE_NEW; } void mark_new() { state |= STATE_NEW; } bool is_importing() { return state & STATE_IMPORTING; } void mark_importing() { state |= STATE_IMPORTING; } bool is_dirty_dft() { return state & STATE_DIRTYDFT; } void mark_dirty_dft() { state |= STATE_DIRTYDFT; } const std::list<fullbit> &get_dfull() const { return dfull; } std::list<fullbit> &_get_dfull() { return dfull; } const std::vector<remotebit> &get_dremote() const { return dremote; } const std::vector<nullbit> &get_dnull() const { return dnull; } template< class... Args> void add_dfull(Args&&... args) { dfull.emplace_back(std::forward<Args>(args)...); } template< class... Args> void add_dremote(Args&&... args) { dremote.emplace_back(std::forward<Args>(args)...); } template< class... Args> void add_dnull(Args&&... args) { dnull.emplace_back(std::forward<Args>(args)...); } void print(dirfrag_t dirfrag, std::ostream& out) const { out << "dirlump " << dirfrag << " v " << fnode->version << " state " << state << " num " << nfull << "/" << nremote << "/" << nnull << std::endl; _decode_bits(); for (const auto& p : dfull) p.print(out); for (const auto& p : dremote) p.print(out); for (const auto& p : dnull) p.print(out); } std::string state_string() const { std::string state_string; bool marked_already = false; if (is_complete()) { state_string.append("complete"); marked_already = true; } if (is_dirty()) { state_string.append(marked_already ? "+dirty" : "dirty"); marked_already = true; } if (is_new()) { state_string.append(marked_already ? "+new" : "new"); } return state_string; } // if this changes, update the versioning in encode for it! void _encode_bits(uint64_t features) const { using ceph::encode; if (!dn_decoded) return; encode(dfull, dnbl, features); encode(dremote, dnbl); encode(dnull, dnbl); } void _decode_bits() const { using ceph::decode; if (dn_decoded) return; auto p = dnbl.cbegin(); decode(dfull, p); decode(dremote, p); decode(dnull, p); dn_decoded = true; } void encode(bufferlist& bl, uint64_t features) const; void decode(bufferlist::const_iterator &bl); void dump(Formatter *f) const; static void generate_test_instances(std::list<dirlump*>& ls); }; WRITE_CLASS_ENCODER_FEATURES(dirlump) // my lumps. preserve the order we added them in a list. std::vector<dirfrag_t> lump_order; std::map<dirfrag_t, dirlump> lump_map; std::list<fullbit> roots; public: std::vector<std::pair<__u8,version_t> > table_tids; // tableclient transactions inodeno_t opened_ino; public: inodeno_t renamed_dirino; std::vector<frag_t> renamed_dir_frags; private: // ino (pre)allocation. may involve both inotable AND session state. version_t inotablev, sessionmapv; inodeno_t allocated_ino; // inotable interval_set<inodeno_t> preallocated_inos; // inotable + session inodeno_t used_preallocated_ino; // session entity_name_t client_name; // session // inodes i've truncated std::vector<inodeno_t> truncate_start; // start truncate std::map<inodeno_t, LogSegment::seq_t> truncate_finish; // finished truncate (started in segment blah) public: std::vector<inodeno_t> destroyed_inodes; private: // idempotent op(s) std::vector<std::pair<metareqid_t,uint64_t> > client_reqs; std::vector<std::pair<metareqid_t,uint64_t> > client_flushes; public: void encode(bufferlist& bl, uint64_t features) const; void decode(bufferlist::const_iterator& bl); void get_inodes(std::set<inodeno_t> &inodes) const; void get_paths(std::vector<std::string> &paths) const; void get_dentries(std::map<dirfrag_t, std::set<std::string> > &dentries) const; entity_name_t get_client_name() const {return client_name;} void dump(Formatter *f) const; static void generate_test_instances(std::list<EMetaBlob*>& ls); // soft stateadd uint64_t last_subtree_map; uint64_t event_seq; // for replay, in certain cases //LogSegment *_segment; EMetaBlob() : opened_ino(0), renamed_dirino(0), inotablev(0), sessionmapv(0), allocated_ino(0), last_subtree_map(0), event_seq(0) {} EMetaBlob(const EMetaBlob&) = delete; ~EMetaBlob() { } EMetaBlob& operator=(const EMetaBlob&) = delete; void print(std::ostream& out) { for (const auto &p : lump_order) lump_map[p].print(p, out); } void add_client_req(metareqid_t r, uint64_t tid=0) { client_reqs.push_back(std::pair<metareqid_t,uint64_t>(r, tid)); } void add_client_flush(metareqid_t r, uint64_t tid=0) { client_flushes.push_back(std::pair<metareqid_t,uint64_t>(r, tid)); } void add_table_transaction(int table, version_t tid) { table_tids.emplace_back(table, tid); } void add_opened_ino(inodeno_t ino) { ceph_assert(!opened_ino); opened_ino = ino; } void set_ino_alloc(inodeno_t alloc, inodeno_t used_prealloc, interval_set<inodeno_t>& prealloc, entity_name_t client, version_t sv, version_t iv) { allocated_ino = alloc; used_preallocated_ino = used_prealloc; preallocated_inos = prealloc; client_name = client; sessionmapv = sv; inotablev = iv; } void add_truncate_start(inodeno_t ino) { truncate_start.push_back(ino); } void add_truncate_finish(inodeno_t ino, uint64_t segoff) { truncate_finish[ino] = segoff; } bool rewrite_truncate_finish(MDSRank const *mds, std::map<uint64_t, uint64_t> const &old_to_new); void add_destroyed_inode(inodeno_t ino) { destroyed_inodes.push_back(ino); } void add_null_dentry(CDentry *dn, bool dirty) { add_null_dentry(add_dir(dn->get_dir(), false), dn, dirty); } void add_null_dentry(dirlump& lump, CDentry *dn, bool dirty) { // add the dir dn->check_corruption(false); lump.nnull++; lump.add_dnull(dn->get_name(), dn->first, dn->last, dn->get_projected_version(), dirty); } void add_remote_dentry(CDentry *dn, bool dirty) { add_remote_dentry(add_dir(dn->get_dir(), false), dn, dirty, 0, 0); } void add_remote_dentry(CDentry *dn, bool dirty, inodeno_t rino, int rdt) { add_remote_dentry(add_dir(dn->get_dir(), false), dn, dirty, rino, rdt); } void add_remote_dentry(dirlump& lump, CDentry *dn, bool dirty, inodeno_t rino=0, unsigned char rdt=0) { dn->check_corruption(false); if (!rino) { rino = dn->get_projected_linkage()->get_remote_ino(); rdt = dn->get_projected_linkage()->get_remote_d_type(); } lump.nremote++; lump.add_dremote(dn->get_name(), dn->get_alternate_name(), dn->first, dn->last, dn->get_projected_version(), rino, rdt, dirty); } // return remote pointer to to-be-journaled inode void add_primary_dentry(CDentry *dn, CInode *in, bool dirty, bool dirty_parent=false, bool dirty_pool=false, bool need_snapflush=false) { __u8 state = 0; if (dirty) state |= fullbit::STATE_DIRTY; if (dirty_parent) state |= fullbit::STATE_DIRTYPARENT; if (dirty_pool) state |= fullbit::STATE_DIRTYPOOL; if (need_snapflush) state |= fullbit::STATE_NEED_SNAPFLUSH; add_primary_dentry(add_dir(dn->get_dir(), false), dn, in, state); } void add_primary_dentry(dirlump& lump, CDentry *dn, CInode *in, __u8 state) { dn->check_corruption(false); if (!in) in = dn->get_projected_linkage()->get_inode(); if (in->is_ephemeral_rand()) { state |= fullbit::STATE_EPHEMERAL_RANDOM; } const auto& pi = in->get_projected_inode(); ceph_assert(pi->version > 0); if ((state & fullbit::STATE_DIRTY) && pi->is_backtrace_updated()) state |= fullbit::STATE_DIRTYPARENT; bufferlist snapbl; const sr_t *sr = in->get_projected_srnode(); if (sr) sr->encode(snapbl); lump.nfull++; lump.add_dfull(dn->get_name(), dn->get_alternate_name(), dn->first, dn->last, dn->get_projected_version(), pi, in->dirfragtree, in->get_projected_xattrs(), in->symlink, in->oldest_snap, snapbl, state, in->get_old_inodes()); // make note of where this inode was last journaled in->last_journaled = event_seq; //cout << "journaling " << in->inode.ino << " at " << my_offset << std::endl; } // convenience: primary or remote? figure it out. void add_dentry(CDentry *dn, bool dirty) { dirlump& lump = add_dir(dn->get_dir(), false); add_dentry(lump, dn, dirty, false, false); } void add_import_dentry(CDentry *dn) { bool dirty_parent = false; bool dirty_pool = false; if (dn->get_linkage()->is_primary()) { dirty_parent = dn->get_linkage()->get_inode()->is_dirty_parent(); dirty_pool = dn->get_linkage()->get_inode()->is_dirty_pool(); } dirlump& lump = add_dir(dn->get_dir(), false); add_dentry(lump, dn, dn->is_dirty(), dirty_parent, dirty_pool); } void add_dentry(dirlump& lump, CDentry *dn, bool dirty, bool dirty_parent, bool dirty_pool) { // primary or remote if (dn->get_projected_linkage()->is_remote()) { add_remote_dentry(dn, dirty); } else if (dn->get_projected_linkage()->is_null()) { add_null_dentry(dn, dirty); } else { ceph_assert(dn->get_projected_linkage()->is_primary()); add_primary_dentry(dn, 0, dirty, dirty_parent, dirty_pool); } } void add_root(bool dirty, CInode *in) { in->last_journaled = event_seq; //cout << "journaling " << in->inode.ino << " at " << my_offset << std::endl; const auto& pi = in->get_projected_inode(); const auto& px = in->get_projected_xattrs(); const auto& pdft = in->dirfragtree; bufferlist snapbl; const sr_t *sr = in->get_projected_srnode(); if (sr) sr->encode(snapbl); for (auto p = roots.begin(); p != roots.end(); ++p) { if (p->inode->ino == in->ino()) { roots.erase(p); break; } } std::string empty; roots.emplace_back(empty, "", in->first, in->last, 0, pi, pdft, px, in->symlink, in->oldest_snap, snapbl, (dirty ? fullbit::STATE_DIRTY : 0), in->get_old_inodes()); } dirlump& add_dir(CDir *dir, bool dirty, bool complete=false) { return add_dir(dir->dirfrag(), dir->get_projected_fnode(), dirty, complete); } dirlump& add_new_dir(CDir *dir) { return add_dir(dir->dirfrag(), dir->get_projected_fnode(), true, true, true); // dirty AND complete AND new } dirlump& add_import_dir(CDir *dir) { // dirty=false would be okay in some cases return add_dir(dir->dirfrag(), dir->get_projected_fnode(), dir->is_dirty(), dir->is_complete(), false, true, dir->is_dirty_dft()); } dirlump& add_fragmented_dir(CDir *dir, bool dirty, bool dirtydft) { return add_dir(dir->dirfrag(), dir->get_projected_fnode(), dirty, false, false, false, dirtydft); } dirlump& add_dir(dirfrag_t df, const CDir::fnode_const_ptr& pf, bool dirty, bool complete=false, bool isnew=false, bool importing=false, bool dirty_dft=false) { if (lump_map.count(df) == 0) lump_order.push_back(df); dirlump& l = lump_map[df]; l.fnode = pf; if (complete) l.mark_complete(); if (dirty) l.mark_dirty(); if (isnew) l.mark_new(); if (importing) l.mark_importing(); if (dirty_dft) l.mark_dirty_dft(); return l; } static const int TO_AUTH_SUBTREE_ROOT = 0; // default. static const int TO_ROOT = 1; void add_dir_context(CDir *dir, int mode = TO_AUTH_SUBTREE_ROOT); bool empty() { return roots.empty() && lump_order.empty() && table_tids.empty() && truncate_start.empty() && truncate_finish.empty() && destroyed_inodes.empty() && client_reqs.empty() && opened_ino == 0 && inotablev == 0 && sessionmapv == 0; } void print(std::ostream& out) const { out << "[metablob"; if (!lump_order.empty()) out << " " << lump_order.front() << ", " << lump_map.size() << " dirs"; if (!table_tids.empty()) out << " table_tids=" << table_tids; if (allocated_ino || preallocated_inos.size()) { if (allocated_ino) out << " alloc_ino=" << allocated_ino; if (preallocated_inos.size()) out << " prealloc_ino=" << preallocated_inos; if (used_preallocated_ino) out << " used_prealloc_ino=" << used_preallocated_ino; out << " v" << inotablev; } out << "]"; } void update_segment(LogSegment *ls); void replay(MDSRank *mds, LogSegment *ls, int type, MDPeerUpdate *su=NULL); }; WRITE_CLASS_ENCODER_FEATURES(EMetaBlob) WRITE_CLASS_ENCODER_FEATURES(EMetaBlob::fullbit) WRITE_CLASS_ENCODER(EMetaBlob::remotebit) WRITE_CLASS_ENCODER(EMetaBlob::nullbit) WRITE_CLASS_ENCODER_FEATURES(EMetaBlob::dirlump) inline std::ostream& operator<<(std::ostream& out, const EMetaBlob& t) { t.print(out); return out; } #endif
20,859
32.754045
136
h
null
ceph-main/src/mds/events/ENoOp.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_ENOOP_H #define CEPH_MDS_ENOOP_H #include "../LogEvent.h" class ENoOp : public LogEvent { uint32_t pad_size; public: ENoOp() : LogEvent(EVENT_NOOP), pad_size(0) { } explicit ENoOp(uint32_t size_) : LogEvent(EVENT_NOOP), pad_size(size_){ } void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator& bl) override; void dump(Formatter *f) const override {} void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(ENoOp) #endif
946
25.305556
75
h
null
ceph-main/src/mds/events/EOpen.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_EOPEN_H #define CEPH_MDS_EOPEN_H #include "../LogEvent.h" #include "EMetaBlob.h" class EOpen : public LogEvent { public: EMetaBlob metablob; std::vector<inodeno_t> inos; std::vector<vinodeno_t> snap_inos; EOpen() : LogEvent(EVENT_OPEN) { } explicit EOpen(MDLog *mdlog) : LogEvent(EVENT_OPEN) { } void print(std::ostream& out) const override { out << "EOpen " << metablob << ", " << inos.size() << " open files"; } EMetaBlob *get_metablob() override { return &metablob; } void add_clean_inode(CInode *in) { if (!in->is_base()) { metablob.add_dir_context(in->get_projected_parent_dn()->get_dir()); metablob.add_primary_dentry(in->get_projected_parent_dn(), 0, false); if (in->last == CEPH_NOSNAP) inos.push_back(in->ino()); else snap_inos.push_back(in->vino()); } } void add_ino(inodeno_t ino) { inos.push_back(ino); } void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator& bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<EOpen*>& ls); void update_segment() override; void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(EOpen) #endif
1,685
26.193548
75
h
null
ceph-main/src/mds/events/EPeerUpdate.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_EPEERUPDATE_H #define CEPH_MDS_EPEERUPDATE_H #include <string_view> #include "../LogEvent.h" #include "EMetaBlob.h" /* * rollback records, for remote/peer updates, which may need to be manually * rolled back during journal replay. (or while active if leader fails, but in * that case these records aren't needed.) */ struct link_rollback { metareqid_t reqid; inodeno_t ino; bool was_inc; utime_t old_ctime; utime_t old_dir_mtime; utime_t old_dir_rctime; bufferlist snapbl; link_rollback() : ino(0), was_inc(false) {} void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(std::list<link_rollback*>& ls); }; WRITE_CLASS_ENCODER(link_rollback) /* * this is only used on an empty dir with a dirfrag on a remote node. * we are auth for nothing. all we need to do is relink the directory * in the hierarchy properly during replay to avoid breaking the * subtree map. */ struct rmdir_rollback { metareqid_t reqid; dirfrag_t src_dir; std::string src_dname; dirfrag_t dest_dir; std::string dest_dname; bufferlist snapbl; void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(std::list<rmdir_rollback*>& ls); }; WRITE_CLASS_ENCODER(rmdir_rollback) struct rename_rollback { struct drec { dirfrag_t dirfrag; utime_t dirfrag_old_mtime; utime_t dirfrag_old_rctime; inodeno_t ino, remote_ino; std::string dname; char remote_d_type; utime_t old_ctime; drec() : remote_d_type((char)S_IFREG) {} void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(std::list<drec*>& ls); }; WRITE_CLASS_MEMBER_ENCODER(drec) metareqid_t reqid; drec orig_src, orig_dest; drec stray; // we know this is null, but we want dname, old mtime/rctime utime_t ctime; bufferlist srci_snapbl; bufferlist desti_snapbl; void encode(bufferlist& bl) const; void decode(bufferlist::const_iterator& bl); void dump(Formatter *f) const; static void generate_test_instances(std::list<rename_rollback*>& ls); }; WRITE_CLASS_ENCODER(rename_rollback::drec) WRITE_CLASS_ENCODER(rename_rollback) class EPeerUpdate : public LogEvent { public: const static int OP_PREPARE = 1; const static int OP_COMMIT = 2; const static int OP_ROLLBACK = 3; const static int LINK = 1; const static int RENAME = 2; const static int RMDIR = 3; /* * we journal a rollback metablob that contains the unmodified metadata * too, because we may be updating previously dirty metadata, which * will allow old log segments to be trimmed. if we end of rolling back, * those updates could be lost.. so we re-journal the unmodified metadata, * and replay will apply _either_ commit or rollback. */ EMetaBlob commit; bufferlist rollback; std::string type; metareqid_t reqid; mds_rank_t leader; __u8 op; // prepare, commit, abort __u8 origop; // link | rename EPeerUpdate() : LogEvent(EVENT_PEERUPDATE), leader(0), op(0), origop(0) { } EPeerUpdate(MDLog *mdlog, std::string_view s, metareqid_t ri, int leadermds, int o, int oo) : LogEvent(EVENT_PEERUPDATE), type(s), reqid(ri), leader(leadermds), op(o), origop(oo) { } void print(std::ostream& out) const override { if (type.length()) out << type << " "; out << " " << (int)op; if (origop == LINK) out << " link"; if (origop == RENAME) out << " rename"; out << " " << reqid; out << " for mds." << leader; out << commit; } EMetaBlob *get_metablob() override { return &commit; } void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator& bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<EPeerUpdate*>& ls); void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(EPeerUpdate) #endif
4,541
27.746835
95
h
null
ceph-main/src/mds/events/EPurged.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_EPURGE_H #define CEPH_MDS_EPURGE_H #include "common/config.h" #include "include/types.h" #include "../LogEvent.h" class EPurged : public LogEvent { public: EPurged() : LogEvent(EVENT_PURGED) { } EPurged(const interval_set<inodeno_t>& _inos, LogSegment::seq_t _seq, version_t iv) : LogEvent(EVENT_PURGED), inos(_inos), seq(_seq), inotablev(iv) { } void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator& bl) override; void dump(Formatter *f) const override; void print(std::ostream& out) const override { out << "Eurged " << inos.size() << " inos, inotable v" << inotablev; } void update_segment() override; void replay(MDSRank *mds) override; protected: interval_set<inodeno_t> inos; LogSegment::seq_t seq; version_t inotablev{0}; }; WRITE_CLASS_ENCODER_FEATURES(EPurged) #endif // CEPH_MDS_EPURGE_H
1,330
27.319149
85
h
null
ceph-main/src/mds/events/EResetJournal.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_ERESETJOURNAL_H #define CEPH_MDS_ERESETJOURNAL_H #include "../LogEvent.h" // generic log event class EResetJournal : public LogEvent { public: EResetJournal() : LogEvent(EVENT_RESETJOURNAL) { } ~EResetJournal() override {} void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator& bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<EResetJournal*>& ls); void print(std::ostream& out) const override { out << "EResetJournal"; } void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(EResetJournal) #endif
1,086
26.175
71
h
null
ceph-main/src/mds/events/ESession.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_ESESSION_H #define CEPH_MDS_ESESSION_H #include "common/config.h" #include "include/types.h" #include "../LogEvent.h" class ESession : public LogEvent { protected: entity_inst_t client_inst; bool open; // open or close version_t cmapv{0}; // client map version interval_set<inodeno_t> inos_to_free; version_t inotablev{0}; interval_set<inodeno_t> inos_to_purge; // Client metadata stored during open client_metadata_t client_metadata; public: ESession() : LogEvent(EVENT_SESSION), open(false) { } ESession(const entity_inst_t& inst, bool o, version_t v, const client_metadata_t& cm) : LogEvent(EVENT_SESSION), client_inst(inst), open(o), cmapv(v), inotablev(0), client_metadata(cm) { } ESession(const entity_inst_t& inst, bool o, version_t v, const interval_set<inodeno_t>& to_free, version_t iv, const interval_set<inodeno_t>& to_purge) : LogEvent(EVENT_SESSION), client_inst(inst), open(o), cmapv(v), inos_to_free(to_free), inotablev(iv), inos_to_purge(to_purge) {} void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator& bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<ESession*>& ls); void print(std::ostream& out) const override { if (open) out << "ESession " << client_inst << " open cmapv " << cmapv; else out << "ESession " << client_inst << " close cmapv " << cmapv; if (inos_to_free.size() || inos_to_purge.size()) out << " (" << inos_to_free.size() << " to free, v" << inotablev << ", " << inos_to_purge.size() << " to purge)"; } void update_segment() override; void replay(MDSRank *mds) override; entity_inst_t get_client_inst() const {return client_inst;} }; WRITE_CLASS_ENCODER_FEATURES(ESession) #endif
2,289
30.805556
71
h
null
ceph-main/src/mds/events/ESessions.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_ESESSIONS_H #define CEPH_MDS_ESESSIONS_H #include "common/config.h" #include "include/types.h" #include "../LogEvent.h" class ESessions : public LogEvent { protected: version_t cmapv; // client map version bool old_style_encode; public: std::map<client_t,entity_inst_t> client_map; std::map<client_t,client_metadata_t> client_metadata_map; ESessions() : LogEvent(EVENT_SESSIONS), cmapv(0), old_style_encode(false) { } ESessions(version_t pv, std::map<client_t,entity_inst_t>&& cm, std::map<client_t,client_metadata_t>&& cmm) : LogEvent(EVENT_SESSIONS), cmapv(pv), old_style_encode(false), client_map(std::move(cm)), client_metadata_map(std::move(cmm)) {} void mark_old_encoding() { old_style_encode = true; } void encode(bufferlist &bl, uint64_t features) const override; void decode_old(bufferlist::const_iterator &bl); void decode_new(bufferlist::const_iterator &bl); void decode(bufferlist::const_iterator &bl) override { if (old_style_encode) decode_old(bl); else decode_new(bl); } void dump(Formatter *f) const override; static void generate_test_instances(std::list<ESessions*>& ls); void print(std::ostream& out) const override { out << "ESessions " << client_map.size() << " opens cmapv " << cmapv; } void update_segment() override; void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(ESessions) #endif
1,857
28.967742
79
h
null
ceph-main/src/mds/events/ESubtreeMap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_ESUBTREEMAP_H #define CEPH_MDS_ESUBTREEMAP_H #include "../LogEvent.h" #include "EMetaBlob.h" class ESubtreeMap : public LogEvent { public: EMetaBlob metablob; std::map<dirfrag_t, std::vector<dirfrag_t> > subtrees; std::set<dirfrag_t> ambiguous_subtrees; uint64_t expire_pos; uint64_t event_seq; ESubtreeMap() : LogEvent(EVENT_SUBTREEMAP), expire_pos(0), event_seq(0) { } void print(std::ostream& out) const override { out << "ESubtreeMap " << subtrees.size() << " subtrees " << ", " << ambiguous_subtrees.size() << " ambiguous " << metablob; } EMetaBlob *get_metablob() override { return &metablob; } void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator& bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<ESubtreeMap*>& ls); void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(ESubtreeMap) #endif
1,403
27.653061
77
h
null
ceph-main/src/mds/events/ETableClient.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_ETABLECLIENT_H #define CEPH_MDS_ETABLECLIENT_H #include "common/config.h" #include "include/types.h" #include "../mds_table_types.h" #include "../LogEvent.h" struct ETableClient : public LogEvent { __u16 table; __s16 op; version_t tid; ETableClient() : LogEvent(EVENT_TABLECLIENT), table(0), op(0), tid(0) { } ETableClient(int t, int o, version_t ti) : LogEvent(EVENT_TABLECLIENT), table(t), op(o), tid(ti) { } void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator& bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<ETableClient*>& ls); void print(std::ostream& out) const override { out << "ETableClient " << get_mdstable_name(table) << " " << get_mdstableserver_opname(op); if (tid) out << " tid " << tid; } //void update_segment(); void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(ETableClient) #endif
1,422
27.46
95
h
null
ceph-main/src/mds/events/ETableServer.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_ETABLESERVER_H #define CEPH_MDS_ETABLESERVER_H #include "common/config.h" #include "include/types.h" #include "../mds_table_types.h" #include "../LogEvent.h" struct ETableServer : public LogEvent { __u16 table; __s16 op; uint64_t reqid; mds_rank_t bymds; bufferlist mutation; version_t tid; version_t version; ETableServer() : LogEvent(EVENT_TABLESERVER), table(0), op(0), reqid(0), bymds(MDS_RANK_NONE), tid(0), version(0) { } ETableServer(int t, int o, uint64_t ri, mds_rank_t m, version_t ti, version_t v) : LogEvent(EVENT_TABLESERVER), table(t), op(o), reqid(ri), bymds(m), tid(ti), version(v) { } void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator& bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<ETableServer*>& ls); void print(std::ostream& out) const override { out << "ETableServer " << get_mdstable_name(table) << " " << get_mdstableserver_opname(op); if (reqid) out << " reqid " << reqid; if (bymds >= 0) out << " mds." << bymds; if (tid) out << " tid " << tid; if (version) out << " version " << version; if (mutation.length()) out << " mutation=" << mutation.length() << " bytes"; } void update_segment() override; void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(ETableServer) #endif
1,851
29.866667
84
h
null
ceph-main/src/mds/events/EUpdate.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDS_EUPDATE_H #define CEPH_MDS_EUPDATE_H #include <string_view> #include "../LogEvent.h" #include "EMetaBlob.h" class EUpdate : public LogEvent { public: EMetaBlob metablob; std::string type; bufferlist client_map; version_t cmapv; metareqid_t reqid; bool had_peers; EUpdate() : LogEvent(EVENT_UPDATE), cmapv(0), had_peers(false) { } EUpdate(MDLog *mdlog, std::string_view s) : LogEvent(EVENT_UPDATE), type(s), cmapv(0), had_peers(false) { } void print(std::ostream& out) const override { if (type.length()) out << "EUpdate " << type << " "; out << metablob; } EMetaBlob *get_metablob() override { return &metablob; } void encode(bufferlist& bl, uint64_t features) const override; void decode(bufferlist::const_iterator& bl) override; void dump(Formatter *f) const override; static void generate_test_instances(std::list<EUpdate*>& ls); void update_segment() override; void replay(MDSRank *mds) override; }; WRITE_CLASS_ENCODER_FEATURES(EUpdate) #endif
1,462
25.125
71
h
null
ceph-main/src/messages/MAuth.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MAUTH_H #define CEPH_MAUTH_H #include <string_view> #include "include/encoding.h" #include "msg/Message.h" #include "msg/MessageRef.h" #include "messages/PaxosServiceMessage.h" class MAuth final : public PaxosServiceMessage { public: __u32 protocol; ceph::buffer::list auth_payload; epoch_t monmap_epoch; /* if protocol == 0, then auth_payload is a set<__u32> listing protocols the client supports */ MAuth() : PaxosServiceMessage{CEPH_MSG_AUTH, 0}, protocol(0), monmap_epoch(0) { } private: ~MAuth() final {} public: std::string_view get_type_name() const override { return "auth"; } void print(std::ostream& out) const override { out << "auth(proto " << protocol << " " << auth_payload.length() << " bytes" << " epoch " << monmap_epoch << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(protocol, p); decode(auth_payload, p); if (!p.end()) decode(monmap_epoch, p); else monmap_epoch = 0; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(protocol, payload); encode(auth_payload, payload); encode(monmap_epoch, payload); } ceph::buffer::list& get_auth_payload() { return auth_payload; } }; #endif
1,750
25.134328
97
h
null
ceph-main/src/messages/MAuthReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MAUTHREPLY_H #define CEPH_MAUTHREPLY_H #include "msg/Message.h" #include "common/errno.h" class MAuthReply final : public Message { public: __u32 protocol; errorcode32_t result; uint64_t global_id; // if zero, meaningless std::string result_msg; ceph::buffer::list result_bl; MAuthReply() : Message(CEPH_MSG_AUTH_REPLY), protocol(0), result(0), global_id(0) {} MAuthReply(__u32 p, ceph::buffer::list *bl = NULL, int r = 0, uint64_t gid=0, const char *msg = "") : Message(CEPH_MSG_AUTH_REPLY), protocol(p), result(r), global_id(gid), result_msg(msg) { if (bl) result_bl = *bl; } private: ~MAuthReply() final {} public: std::string_view get_type_name() const override { return "auth_reply"; } void print(std::ostream& o) const override { o << "auth_reply(proto " << protocol << " " << result << " " << cpp_strerror(result); if (result_msg.length()) o << ": " << result_msg; o << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(protocol, p); decode(result, p); decode(global_id, p); decode(result_bl, p); decode(result_msg, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(protocol, payload); encode(result, payload); encode(global_id, payload); encode(result_bl, payload); encode(result_msg, payload); } }; #endif
1,869
26.101449
103
h
null
ceph-main/src/messages/MBackfillReserve.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MBACKFILL_H #define CEPH_MBACKFILL_H #include "msg/Message.h" #include "messages/MOSDPeeringOp.h" #include "osd/PGPeeringEvent.h" class MBackfillReserve : public MOSDPeeringOp { private: static constexpr int HEAD_VERSION = 5; static constexpr int COMPAT_VERSION = 4; public: spg_t pgid; epoch_t query_epoch; enum { REQUEST = 0, // primary->replica: please reserve a slot GRANT = 1, // replica->primary: ok, i reserved it REJECT_TOOFULL = 2, // replica->primary: too full, sorry, try again later (*) RELEASE = 3, // primary->replcia: release the slot i reserved before REVOKE_TOOFULL = 4, // replica->primary: too full, stop backfilling REVOKE = 5, // replica->primary: i'm taking back the slot i gave you // (*) NOTE: prior to luminous, REJECT was overloaded to also mean release }; uint32_t type; uint32_t priority; int64_t primary_num_bytes; int64_t shard_num_bytes; spg_t get_spg() const { return pgid; } epoch_t get_map_epoch() const { return query_epoch; } epoch_t get_min_epoch() const { return query_epoch; } PGPeeringEvent *get_event() override { switch (type) { case REQUEST: return new PGPeeringEvent( query_epoch, query_epoch, RequestBackfillPrio(priority, primary_num_bytes, shard_num_bytes)); case GRANT: return new PGPeeringEvent( query_epoch, query_epoch, RemoteBackfillReserved()); case REJECT_TOOFULL: // NOTE: this is replica -> primary "i reject your request" // and also primary -> replica "cancel my previously-granted request" // (for older peers) // and also replica -> primary "i revoke your reservation" // (for older peers) return new PGPeeringEvent( query_epoch, query_epoch, RemoteReservationRejectedTooFull()); case RELEASE: return new PGPeeringEvent( query_epoch, query_epoch, RemoteReservationCanceled()); case REVOKE_TOOFULL: return new PGPeeringEvent( query_epoch, query_epoch, RemoteReservationRevokedTooFull()); case REVOKE: return new PGPeeringEvent( query_epoch, query_epoch, RemoteReservationRevoked()); default: ceph_abort(); } } MBackfillReserve() : MOSDPeeringOp{MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION}, query_epoch(0), type(-1), priority(-1), primary_num_bytes(0), shard_num_bytes(0) {} MBackfillReserve(int type, spg_t pgid, epoch_t query_epoch, unsigned prio = -1, int64_t primary_num_bytes = 0, int64_t shard_num_bytes = 0) : MOSDPeeringOp{MSG_OSD_BACKFILL_RESERVE, HEAD_VERSION, COMPAT_VERSION}, pgid(pgid), query_epoch(query_epoch), type(type), priority(prio), primary_num_bytes(primary_num_bytes), shard_num_bytes(shard_num_bytes) {} std::string_view get_type_name() const override { return "MBackfillReserve"; } void inner_print(std::ostream& out) const override { switch (type) { case REQUEST: out << "REQUEST"; break; case GRANT: out << "GRANT"; break; case REJECT_TOOFULL: out << "REJECT_TOOFULL"; break; case RELEASE: out << "RELEASE"; break; case REVOKE_TOOFULL: out << "REVOKE_TOOFULL"; break; case REVOKE: out << "REVOKE"; break; } if (type == REQUEST) out << " prio: " << priority; return; } void decode_payload() override { auto p = payload.cbegin(); using ceph::decode; decode(pgid.pgid, p); decode(query_epoch, p); decode(type, p); decode(priority, p); decode(pgid.shard, p); if (header.version >= 5) { decode(primary_num_bytes, p); decode(shard_num_bytes, p); } else { primary_num_bytes = 0; shard_num_bytes = 0; } } void encode_payload(uint64_t features) override { using ceph::encode; if (!HAVE_FEATURE(features, RECOVERY_RESERVATION_2)) { header.version = 3; header.compat_version = 3; encode(pgid.pgid, payload); encode(query_epoch, payload); encode((type == RELEASE || type == REVOKE_TOOFULL || type == REVOKE) ? REJECT_TOOFULL : type, payload); encode(priority, payload); encode(pgid.shard, payload); return; } header.version = HEAD_VERSION; header.compat_version = COMPAT_VERSION; encode(pgid.pgid, payload); encode(query_epoch, payload); encode(type, payload); encode(priority, payload); encode(pgid.shard, payload); encode(primary_num_bytes, payload); encode(shard_num_bytes, payload); } }; #endif
5,103
27.198895
84
h
null
ceph-main/src/messages/MCacheExpire.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCACHEEXPIRE_H #define CEPH_MCACHEEXPIRE_H #include <string_view> #include "mds/mdstypes.h" #include "messages/MMDSOp.h" class MCacheExpire final : public MMDSOp { private: __s32 from; public: /* group things by realm (auth delgation root), since that's how auth is determined. that makes it less work to process when exports are in progress. */ struct realm { std::map<vinodeno_t, uint32_t> inodes; std::map<dirfrag_t, uint32_t> dirs; std::map<dirfrag_t, std::map<std::pair<std::string,snapid_t>,uint32_t> > dentries; void merge(const realm& o) { inodes.insert(o.inodes.begin(), o.inodes.end()); dirs.insert(o.dirs.begin(), o.dirs.end()); for (const auto &p : o.dentries) { auto em = dentries.emplace(std::piecewise_construct, std::forward_as_tuple(p.first), std::forward_as_tuple(p.second)); if (!em.second) { em.first->second.insert(p.second.begin(), p.second.end()); } } } void encode(ceph::buffer::list &bl) const { using ceph::encode; encode(inodes, bl); encode(dirs, bl); encode(dentries, bl); } void decode(ceph::buffer::list::const_iterator &bl) { using ceph::decode; decode(inodes, bl); decode(dirs, bl); decode(dentries, bl); } }; WRITE_CLASS_ENCODER(realm) std::map<dirfrag_t, realm> realms; int get_from() const { return from; } protected: MCacheExpire() : MMDSOp{MSG_MDS_CACHEEXPIRE}, from(-1) {} MCacheExpire(int f) : MMDSOp{MSG_MDS_CACHEEXPIRE}, from(f) { } ~MCacheExpire() final {} public: std::string_view get_type_name() const override { return "cache_expire";} void add_inode(dirfrag_t r, vinodeno_t vino, unsigned nonce) { realms[r].inodes[vino] = nonce; } 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, std::string_view dn, snapid_t last, unsigned nonce) { realms[r].dentries[df][std::pair<std::string,snapid_t>(dn,last)] = nonce; } void add_realm(dirfrag_t df, const realm& r) { auto em = realms.emplace(std::piecewise_construct, std::forward_as_tuple(df), std::forward_as_tuple(r)); if (!em.second) { em.first->second.merge(r); } } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(from, p); decode(realms, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(from, payload); encode(realms, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; WRITE_CLASS_ENCODER(MCacheExpire::realm) #endif
3,254
27.304348
126
h
null
ceph-main/src/messages/MClientCapRelease.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTCAPRELEASE_H #define CEPH_MCLIENTCAPRELEASE_H #include "msg/Message.h" class MClientCapRelease final : public SafeMessage { public: std::string_view get_type_name() const override { return "client_cap_release";} void print(std::ostream& out) const override { out << "client_cap_release(" << caps.size() << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(head, p); ceph::decode_nohead(head.num, caps, p); if (header.version >= 2) { decode(osd_epoch_barrier, p); } } void encode_payload(uint64_t features) override { using ceph::encode; head.num = caps.size(); encode(head, payload); ceph::encode_nohead(caps, payload); encode(osd_epoch_barrier, payload); } struct ceph_mds_cap_release head; std::vector<ceph_mds_cap_item> caps; // The message receiver must wait for this OSD epoch // before actioning this cap release. epoch_t osd_epoch_barrier = 0; private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; MClientCapRelease() : SafeMessage{CEPH_MSG_CLIENT_CAPRELEASE, HEAD_VERSION, COMPAT_VERSION} { memset(&head, 0, sizeof(head)); } ~MClientCapRelease() final {} }; #endif
1,913
26.342857
81
h
null
ceph-main/src/messages/MClientCaps.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTCAPS_H #define CEPH_MCLIENTCAPS_H #include "msg/Message.h" #include "mds/mdstypes.h" #include "include/ceph_features.h" class MClientCaps final : public SafeMessage { private: static constexpr int HEAD_VERSION = 12; static constexpr int COMPAT_VERSION = 1; public: static constexpr unsigned FLAG_SYNC = (1<<0); static constexpr unsigned FLAG_NO_CAPSNAP = (1<<1); // unused static constexpr unsigned FLAG_PENDING_CAPSNAP = (1<<2); struct ceph_mds_caps_head head; uint64_t size = 0; uint64_t max_size = 0; uint64_t truncate_size = 0; uint64_t change_attr = 0; uint32_t truncate_seq = 0; utime_t mtime, atime, ctime, btime; uint32_t time_warp_seq = 0; int64_t nfiles = -1; // files in dir int64_t nsubdirs = -1; // subdirs in dir struct ceph_mds_cap_peer peer; ceph::buffer::list snapbl; ceph::buffer::list xattrbl; ceph::buffer::list flockbl; version_t inline_version = 0; ceph::buffer::list inline_data; // Receivers may not use their new caps until they have this OSD map epoch_t osd_epoch_barrier = 0; ceph_tid_t oldest_flush_tid = 0; uint32_t caller_uid = 0; uint32_t caller_gid = 0; /* advisory CLIENT_CAPS_* flags to send to mds */ unsigned flags = 0; std::vector<uint8_t> fscrypt_auth; std::vector<uint8_t> fscrypt_file; int get_caps() const { return head.caps; } int get_wanted() const { return head.wanted; } int get_dirty() const { return head.dirty; } ceph_seq_t get_seq() const { return head.seq; } ceph_seq_t get_issue_seq() const { return head.issue_seq; } ceph_seq_t get_mseq() const { return head.migrate_seq; } inodeno_t get_ino() const { return inodeno_t(head.ino); } inodeno_t get_realm() const { return inodeno_t(head.realm); } uint64_t get_cap_id() const { return head.cap_id; } uint64_t get_size() const { return size; } uint64_t get_max_size() const { return max_size; } __u32 get_truncate_seq() const { return truncate_seq; } uint64_t get_truncate_size() const { return truncate_size; } utime_t get_ctime() const { return ctime; } utime_t get_btime() const { return btime; } utime_t get_mtime() const { return mtime; } utime_t get_atime() const { return atime; } __u64 get_change_attr() const { return change_attr; } __u32 get_time_warp_seq() const { return time_warp_seq; } uint64_t get_nfiles() const { return nfiles; } uint64_t get_nsubdirs() const { return nsubdirs; } bool dirstat_is_valid() const { return nfiles != -1 || nsubdirs != -1; } const file_layout_t& get_layout() const { return layout; } void set_layout(const file_layout_t &l) { layout = l; } int get_migrate_seq() const { return head.migrate_seq; } int get_op() const { return head.op; } uint64_t get_client_tid() const { return get_tid(); } void set_client_tid(uint64_t s) { set_tid(s); } snapid_t get_snap_follows() const { return snapid_t(head.snap_follows); } void set_snap_follows(snapid_t s) { head.snap_follows = s; } void set_caps(int c) { head.caps = c; } void set_wanted(int w) { head.wanted = w; } void set_max_size(uint64_t ms) { max_size = ms; } void set_migrate_seq(unsigned m) { head.migrate_seq = m; } void set_op(int o) { head.op = o; } void set_size(loff_t s) { size = s; } void set_mtime(const utime_t &t) { mtime = t; } void set_ctime(const utime_t &t) { ctime = t; } void set_atime(const utime_t &t) { atime = t; } void set_cap_peer(uint64_t id, ceph_seq_t seq, ceph_seq_t mseq, int mds, int flags) { peer.cap_id = id; peer.seq = seq; peer.mseq = mseq; peer.mds = mds; peer.flags = flags; } void set_oldest_flush_tid(ceph_tid_t tid) { oldest_flush_tid = tid; } ceph_tid_t get_oldest_flush_tid() const { return oldest_flush_tid; } void clear_dirty() { head.dirty = 0; } protected: MClientCaps() : SafeMessage{CEPH_MSG_CLIENT_CAPS, HEAD_VERSION, COMPAT_VERSION} {} MClientCaps(int op, inodeno_t ino, inodeno_t realm, uint64_t id, long seq, int caps, int wanted, int dirty, int mseq, epoch_t oeb) : SafeMessage{CEPH_MSG_CLIENT_CAPS, HEAD_VERSION, COMPAT_VERSION}, osd_epoch_barrier(oeb) { memset(&head, 0, sizeof(head)); head.op = op; head.ino = ino; head.realm = realm; head.cap_id = id; head.seq = seq; head.caps = caps; head.wanted = wanted; head.dirty = dirty; head.migrate_seq = mseq; memset(&peer, 0, sizeof(peer)); } MClientCaps(int op, inodeno_t ino, inodeno_t realm, uint64_t id, int mseq, epoch_t oeb) : SafeMessage{CEPH_MSG_CLIENT_CAPS, HEAD_VERSION, COMPAT_VERSION}, osd_epoch_barrier(oeb) { memset(&head, 0, sizeof(head)); head.op = op; head.ino = ino; head.realm = realm; head.cap_id = id; head.migrate_seq = mseq; memset(&peer, 0, sizeof(peer)); } ~MClientCaps() final {} private: file_layout_t layout; public: std::string_view get_type_name() const override { return "Cfcap";} void print(std::ostream& out) const override { out << "client_caps(" << ceph_cap_op_name(head.op) << " ino " << inodeno_t(head.ino) << " " << head.cap_id << " seq " << head.seq; if (get_tid()) out << " tid " << get_tid(); out << " caps=" << ccap_string(head.caps) << " dirty=" << ccap_string(head.dirty) << " wanted=" << ccap_string(head.wanted); out << " follows " << snapid_t(head.snap_follows); if (head.migrate_seq) out << " mseq " << head.migrate_seq; out << " size " << size << "/" << max_size; if (truncate_seq) out << " ts " << truncate_seq << "/" << truncate_size; out << " mtime " << mtime << " ctime " << ctime << " change_attr " << change_attr; if (time_warp_seq) out << " tws " << time_warp_seq; if (head.xattr_version) out << " xattrs(v=" << head.xattr_version << " l=" << xattrbl.length() << ")"; out << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(head, p); if (head.op == CEPH_CAP_OP_EXPORT) { ceph_mds_caps_export_body body; decode(body, p); peer = body.peer; p += (sizeof(ceph_mds_caps_non_export_body) - sizeof(ceph_mds_caps_export_body)); } else { ceph_mds_caps_non_export_body body; decode(body, p); size = body.size; max_size = body.max_size; truncate_size = body.truncate_size; truncate_seq = body.truncate_seq; mtime = utime_t(body.mtime); atime = utime_t(body.atime); ctime = utime_t(body.ctime); layout.from_legacy(body.layout); time_warp_seq = body.time_warp_seq; } ceph::decode_nohead(head.snap_trace_len, snapbl, p); ceph_assert(middle.length() == head.xattr_len); if (head.xattr_len) xattrbl = middle; // conditionally decode flock metadata if (header.version >= 2) decode(flockbl, p); if (header.version >= 3) { if (head.op == CEPH_CAP_OP_IMPORT) decode(peer, p); } if (header.version >= 4) { decode(inline_version, p); decode(inline_data, p); } else { inline_version = CEPH_INLINE_NONE; } if (header.version >= 5) { decode(osd_epoch_barrier, p); } if (header.version >= 6) { decode(oldest_flush_tid, p); } if (header.version >= 7) { decode(caller_uid, p); decode(caller_gid, p); } if (header.version >= 8) { decode(layout.pool_ns, p); } if (header.version >= 9) { decode(btime, p); decode(change_attr, p); } if (header.version >= 10) { decode(flags, p); } if (header.version >= 11) { decode(nfiles, p); decode(nsubdirs, p); } if (header.version >= 12) { decode(fscrypt_auth, p); decode(fscrypt_file, p); } } void encode_payload(uint64_t features) override { using ceph::encode; header.version = HEAD_VERSION; head.snap_trace_len = snapbl.length(); head.xattr_len = xattrbl.length(); encode(head, payload); static_assert(sizeof(ceph_mds_caps_non_export_body) > sizeof(ceph_mds_caps_export_body)); if (head.op == CEPH_CAP_OP_EXPORT) { ceph_mds_caps_export_body body; body.peer = peer; encode(body, payload); payload.append_zero(sizeof(ceph_mds_caps_non_export_body) - sizeof(ceph_mds_caps_export_body)); } else { ceph_mds_caps_non_export_body body; body.size = size; body.max_size = max_size; body.truncate_size = truncate_size; body.truncate_seq = truncate_seq; mtime.encode_timeval(&body.mtime); atime.encode_timeval(&body.atime); ctime.encode_timeval(&body.ctime); layout.to_legacy(&body.layout); body.time_warp_seq = time_warp_seq; encode(body, payload); } ceph::encode_nohead(snapbl, payload); middle = xattrbl; // conditionally include flock metadata if (features & CEPH_FEATURE_FLOCK) { encode(flockbl, payload); } else { header.version = 1; return; } if (features & CEPH_FEATURE_EXPORT_PEER) { if (head.op == CEPH_CAP_OP_IMPORT) encode(peer, payload); } else { header.version = 2; return; } if (features & CEPH_FEATURE_MDS_INLINE_DATA) { encode(inline_version, payload); encode(inline_data, payload); } else { encode(inline_version, payload); encode(ceph::buffer::list(), payload); } encode(osd_epoch_barrier, payload); encode(oldest_flush_tid, payload); encode(caller_uid, payload); encode(caller_gid, payload); encode(layout.pool_ns, payload); encode(btime, payload); encode(change_attr, payload); encode(flags, payload); encode(nfiles, payload); encode(nsubdirs, payload); encode(fscrypt_auth, payload); encode(fscrypt_file, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
10,587
28.32964
87
h
null
ceph-main/src/messages/MClientLease.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTLEASE_H #define CEPH_MCLIENTLEASE_H #include <string_view> #include "msg/Message.h" class MClientLease final : public SafeMessage { public: struct ceph_mds_lease h; std::string dname; int get_action() const { return h.action; } ceph_seq_t get_seq() const { return h.seq; } int get_mask() const { return h.mask; } inodeno_t get_ino() const { return inodeno_t(h.ino); } snapid_t get_first() const { return snapid_t(h.first); } snapid_t get_last() const { return snapid_t(h.last); } protected: MClientLease() : SafeMessage(CEPH_MSG_CLIENT_LEASE) {} MClientLease(const MClientLease& m) : SafeMessage(CEPH_MSG_CLIENT_LEASE), h(m.h), dname(m.dname) {} MClientLease(int ac, ceph_seq_t seq, int m, uint64_t i, uint64_t sf, uint64_t sl) : SafeMessage(CEPH_MSG_CLIENT_LEASE) { h.action = ac; h.seq = seq; h.mask = m; h.ino = i; h.first = sf; 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, std::string_view d) : SafeMessage(CEPH_MSG_CLIENT_LEASE), dname(d) { h.action = ac; h.seq = seq; h.mask = m; h.ino = i; h.first = sf; h.last = sl; h.duration_ms = 0; } ~MClientLease() final {} public: std::string_view get_type_name() const override { return "client_lease"; } void print(std::ostream& out) const override { out << "client_lease(a=" << ceph_lease_op_name(get_action()) << " seq " << get_seq() << " mask " << get_mask(); out << " " << get_ino(); if (h.last != CEPH_NOSNAP) out << " [" << snapid_t(h.first) << "," << snapid_t(h.last) << "]"; if (dname.length()) out << "/" << dname; out << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(h, p); decode(dname, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(h, payload); encode(dname, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,656
26.112245
105
h
null
ceph-main/src/messages/MClientMetrics.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MDS_CLIENT_METRICS_H #define CEPH_MDS_CLIENT_METRICS_H #include <vector> #include "msg/Message.h" #include "include/cephfs/metrics/Types.h" class MClientMetrics final : public SafeMessage { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: std::vector<ClientMetricMessage> updates; protected: MClientMetrics() : MClientMetrics(std::vector<ClientMetricMessage>{}) { } MClientMetrics(std::vector<ClientMetricMessage> updates) : SafeMessage(CEPH_MSG_CLIENT_METRICS, HEAD_VERSION, COMPAT_VERSION), updates(updates) { } ~MClientMetrics() final {} public: std::string_view get_type_name() const override { return "client_metrics"; } void print(std::ostream &out) const override { out << "client_metrics "; for (auto &i : updates) { i.print(&out); } } void encode_payload(uint64_t features) override { using ceph::encode; encode(updates, payload); } void decode_payload() override { using ceph::decode; auto iter = payload.cbegin(); decode(updates, iter); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif // CEPH_MDS_CLIENT_METRICS_H
1,446
24.385965
92
h
null
ceph-main/src/messages/MClientQuota.h
#ifndef CEPH_MCLIENTQUOTA_H #define CEPH_MCLIENTQUOTA_H #include "msg/Message.h" class MClientQuota final : public SafeMessage { public: inodeno_t ino; nest_info_t rstat; quota_info_t quota; protected: MClientQuota() : SafeMessage{CEPH_MSG_CLIENT_QUOTA}, ino(0) {} ~MClientQuota() final {} public: std::string_view get_type_name() const override { return "client_quota"; } void print(std::ostream& out) const override { out << "client_quota("; out << " [" << ino << "] "; out << rstat << " "; out << quota; out << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(ino, payload); encode(rstat.rctime, payload); encode(rstat.rbytes, payload); encode(rstat.rfiles, payload); encode(rstat.rsubdirs, payload); encode(quota, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(ino, p); decode(rstat.rctime, p); decode(rstat.rbytes, p); decode(rstat.rfiles, p); decode(rstat.rsubdirs, p); decode(quota, p); ceph_assert(p.end()); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,350
22.701754
76
h
null
ceph-main/src/messages/MClientReclaim.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTRECLAIM_H #define CEPH_MCLIENTRECLAIM_H #include "msg/Message.h" class MClientReclaim final : public SafeMessage { public: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; static constexpr uint32_t FLAG_FINISH = 1U << 31; uint32_t get_flags() const { return flags; } std::string_view get_uuid() const { return uuid; } std::string_view get_type_name() const override { return "client_reclaim"; } void print(std::ostream& o) const override { std::ios_base::fmtflags f(o.flags()); o << "client_reclaim(" << get_uuid() << " flags 0x" << std::hex << get_flags() << ")"; o.flags(f); } void encode_payload(uint64_t features) override { using ceph::encode; encode(uuid, payload); encode(flags, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(uuid, p); decode(flags, p); } protected: MClientReclaim() : SafeMessage{CEPH_MSG_CLIENT_RECLAIM, HEAD_VERSION, COMPAT_VERSION} {} MClientReclaim(std::string_view _uuid, uint32_t _flags) : SafeMessage{CEPH_MSG_CLIENT_RECLAIM, HEAD_VERSION, COMPAT_VERSION}, uuid(_uuid), flags(_flags) {} private: ~MClientReclaim() final {} std::string uuid; uint32_t flags = 0; template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,934
27.043478
90
h
null
ceph-main/src/messages/MClientReclaimReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTRECLAIMREPLY_H #define CEPH_MCLIENTRECLAIMREPLY_H #include "msg/Message.h" class MClientReclaimReply final : public SafeMessage { public: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; int32_t get_result() const { return result; } void set_result(int r) { result = r; } epoch_t get_epoch() const { return epoch; } void set_epoch(epoch_t e) { epoch = e; } const entity_addrvec_t& get_addrs() const { return addrs; } void set_addrs(const entity_addrvec_t& _addrs) { addrs = _addrs; } std::string_view get_type_name() const override { return "client_reclaim_reply"; } void print(std::ostream& o) const override { o << "client_reclaim_reply(" << result << " e " << epoch << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(result, payload); encode(epoch, payload); encode(addrs, payload, features); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(result, p); decode(epoch, p); decode(addrs, p); } protected: MClientReclaimReply() : MClientReclaimReply{0, 0} {} MClientReclaimReply(int r, epoch_t e=0) : SafeMessage{CEPH_MSG_CLIENT_RECLAIM_REPLY, HEAD_VERSION, COMPAT_VERSION}, result(r), epoch(e) {} private: ~MClientReclaimReply() final {} int32_t result; epoch_t epoch; entity_addrvec_t addrs; template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,071
26.626667
84
h
null
ceph-main/src/messages/MClientReconnect.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTRECONNECT_H #define CEPH_MCLIENTRECONNECT_H #include "msg/Message.h" #include "mds/mdstypes.h" #include "include/ceph_features.h" class MClientReconnect final : public SafeMessage { private: static constexpr int HEAD_VERSION = 5; static constexpr int COMPAT_VERSION = 4; public: std::map<inodeno_t, cap_reconnect_t> caps; // only head inodes std::vector<snaprealm_reconnect_t> realms; bool more = false; private: MClientReconnect() : SafeMessage{CEPH_MSG_CLIENT_RECONNECT, HEAD_VERSION, COMPAT_VERSION} {} ~MClientReconnect() final {} size_t cap_size = 0; size_t realm_size = 0; size_t approx_size = sizeof(__u32) + sizeof(__u32) + 1; void calc_item_size() { using ceph::encode; { ceph::buffer::list bl; inodeno_t ino; cap_reconnect_t cr; encode(ino, bl); encode(cr, bl); cap_size = bl.length(); } { ceph::buffer::list bl; snaprealm_reconnect_t sr; encode(sr, bl); realm_size = bl.length(); } } public: std::string_view get_type_name() const override { return "client_reconnect"; } void print(std::ostream& out) const override { out << "client_reconnect(" << caps.size() << " caps " << realms.size() << " realms )"; } // Force to use old encoding. // Use connection's features to choose encoding if version is set to 0. void set_encoding_version(int v) { header.version = v; if (v <= 3) header.compat_version = 0; } size_t get_approx_size() { return approx_size; } void mark_more() { more = true; } bool has_more() const { return more; } void add_cap(inodeno_t ino, uint64_t cap_id, inodeno_t pathbase, const std::string& path, int wanted, int issued, inodeno_t sr, snapid_t sf, ceph::buffer::list& lb) { caps[ino] = cap_reconnect_t(cap_id, pathbase, path, wanted, issued, sr, sf, lb); if (!cap_size) calc_item_size(); approx_size += cap_size + path.length() + lb.length(); } void add_snaprealm(inodeno_t ino, snapid_t seq, inodeno_t parent) { snaprealm_reconnect_t r; r.realm.ino = ino; r.realm.seq = seq; r.realm.parent = parent; realms.push_back(r); if (!realm_size) calc_item_size(); approx_size += realm_size; } void encode_payload(uint64_t features) override { if (header.version == 0) { if (features & CEPH_FEATURE_MDSENC) header.version = 3; else if (features & CEPH_FEATURE_FLOCK) header.version = 2; else header.version = 1; } using ceph::encode; data.clear(); if (header.version >= 4) { encode(caps, data); encode(realms, data); encode(more, data); } else { // compat crap if (header.version == 3) { encode(caps, data); } else if (header.version == 2) { __u32 n = caps.size(); encode(n, data); for (auto& p : caps) { encode(p.first, data); p.second.encode_old(data); } } else { std::map<inodeno_t, old_cap_reconnect_t> ocaps; for (auto& p : caps) { ocaps[p.first] = p.second; encode(ocaps, data); } for (auto& r : realms) r.encode_old(data); } } } void decode_payload() override { using ceph::decode; auto p = data.cbegin(); if (header.version >= 4) { decode(caps, p); decode(realms, p); if (header.version >= 5) decode(more, p); } else { // compat crap if (header.version == 3) { decode(caps, p); } else if (header.version == 2) { __u32 n; decode(n, p); inodeno_t ino; while (n--) { decode(ino, p); caps[ino].decode_old(p); } } else { std::map<inodeno_t, old_cap_reconnect_t> ocaps; decode(ocaps, p); for (auto &q : ocaps) caps[q.first] = q.second; } while (!p.end()) { realms.push_back(snaprealm_reconnect_t()); realms.back().decode_old(p); } } } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
4,489
24.083799
91
h
null
ceph-main/src/messages/MClientReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTREPLY_H #define CEPH_MCLIENTREPLY_H #include "include/types.h" #include "include/fs_types.h" #include "include/mempool.h" #include "MClientRequest.h" #include "msg/Message.h" #include "include/ceph_features.h" #include "common/errno.h" #include "common/strescape.h" /*** * * MClientReply - container message for MDS reply to a client's MClientRequest * * key fields: * long tid - transaction id, so the client can match up with pending request * int result - error code, or fh if it was open * * for most requests: * trace is a vector of InodeStat's tracing from root to the file/dir/whatever * the operation referred to, so that the client can update it's info about what * metadata lives on what MDS. * * for readdir replies: * dir_contents is a vector of InodeStat*'s. * * that's mostly it, i think! * */ struct LeaseStat { // this matches ceph_mds_reply_lease __u16 mask = 0; __u32 duration_ms = 0; __u32 seq = 0; std::string alternate_name; LeaseStat() = default; LeaseStat(__u16 msk, __u32 dur, __u32 sq) : mask{msk}, duration_ms{dur}, seq{sq} {} void decode(ceph::buffer::list::const_iterator &bl, const uint64_t features) { using ceph::decode; if (features == (uint64_t)-1) { DECODE_START(2, bl); decode(mask, bl); decode(duration_ms, bl); decode(seq, bl); if (struct_v >= 2) decode(alternate_name, bl); DECODE_FINISH(bl); } else { decode(mask, bl); decode(duration_ms, bl); decode(seq, bl); } } }; inline std::ostream& operator<<(std::ostream& out, const LeaseStat& l) { out << "lease(mask " << l.mask << " dur " << l.duration_ms; if (l.alternate_name.size()) { out << " altn " << binstrprint(l.alternate_name, 128) << ")"; } return out << ")"; } struct DirStat { // mds distribution hints frag_t frag; __s32 auth; std::set<__s32> dist; DirStat() : auth(CDIR_AUTH_PARENT) {} DirStat(ceph::buffer::list::const_iterator& p, const uint64_t features) { decode(p, features); } void decode(ceph::buffer::list::const_iterator& p, const uint64_t features) { using ceph::decode; if (features == (uint64_t)-1) { DECODE_START(1, p); decode(frag, p); decode(auth, p); decode(dist, p); DECODE_FINISH(p); } else { decode(frag, p); decode(auth, p); decode(dist, p); } } // see CDir::encode_dirstat for encoder. }; struct InodeStat { vinodeno_t vino; uint32_t rdev = 0; version_t version = 0; version_t xattr_version = 0; ceph_mds_reply_cap cap; file_layout_t layout; utime_t ctime, btime, mtime, atime, snap_btime; uint32_t time_warp_seq = 0; uint64_t size = 0, max_size = 0; uint64_t change_attr = 0; uint64_t truncate_size = 0; uint32_t truncate_seq = 0; uint32_t mode = 0, uid = 0, gid = 0, nlink = 0; frag_info_t dirstat; nest_info_t rstat; fragtree_t dirfragtree; std::string symlink; // symlink content (if symlink) ceph_dir_layout dir_layout; ceph::buffer::list xattrbl; ceph::buffer::list inline_data; version_t inline_version; quota_info_t quota; mds_rank_t dir_pin; std::map<std::string,std::string> snap_metadata; std::vector<uint8_t> fscrypt_auth; std::vector<uint8_t> fscrypt_file; public: InodeStat() {} InodeStat(ceph::buffer::list::const_iterator& p, const uint64_t features) { decode(p, features); } void decode(ceph::buffer::list::const_iterator &p, const uint64_t features) { using ceph::decode; if (features == (uint64_t)-1) { DECODE_START(7, p); decode(vino.ino, p); decode(vino.snapid, p); decode(rdev, p); decode(version, p); decode(xattr_version, p); decode(cap, p); { ceph_file_layout legacy_layout; decode(legacy_layout, p); layout.from_legacy(legacy_layout); } decode(ctime, p); decode(mtime, p); decode(atime, p); decode(time_warp_seq, p); decode(size, p); decode(max_size, p); decode(truncate_size, p); decode(truncate_seq, p); decode(mode, p); decode(uid, p); decode(gid, p); decode(nlink, p); decode(dirstat.nfiles, p); decode(dirstat.nsubdirs, p); decode(rstat.rbytes, p); decode(rstat.rfiles, p); decode(rstat.rsubdirs, p); decode(rstat.rctime, p); decode(dirfragtree, p); decode(symlink, p); decode(dir_layout, p); decode(xattrbl, p); decode(inline_version, p); decode(inline_data, p); decode(quota, p); decode(layout.pool_ns, p); decode(btime, p); decode(change_attr, p); if (struct_v > 1) { decode(dir_pin, p); } else { dir_pin = -ENODATA; } if (struct_v >= 3) { decode(snap_btime, p); } // else remains zero if (struct_v >= 4) { decode(rstat.rsnaps, p); } // else remains zero if (struct_v >= 5) { decode(snap_metadata, p); } if (struct_v >= 6) { bool fscrypt_flag; decode(fscrypt_flag, p); // ignore this } if (struct_v >= 7) { decode(fscrypt_auth, p); decode(fscrypt_file, p); } DECODE_FINISH(p); } else { decode(vino.ino, p); decode(vino.snapid, p); decode(rdev, p); decode(version, p); decode(xattr_version, p); decode(cap, p); { ceph_file_layout legacy_layout; decode(legacy_layout, p); layout.from_legacy(legacy_layout); } decode(ctime, p); decode(mtime, p); decode(atime, p); decode(time_warp_seq, p); decode(size, p); decode(max_size, p); decode(truncate_size, p); decode(truncate_seq, p); decode(mode, p); decode(uid, p); decode(gid, p); decode(nlink, p); decode(dirstat.nfiles, p); decode(dirstat.nsubdirs, p); decode(rstat.rbytes, p); decode(rstat.rfiles, p); decode(rstat.rsubdirs, p); decode(rstat.rctime, p); decode(dirfragtree, p); decode(symlink, p); if (features & CEPH_FEATURE_DIRLAYOUTHASH) decode(dir_layout, p); else memset(&dir_layout, 0, sizeof(dir_layout)); decode(xattrbl, p); if (features & CEPH_FEATURE_MDS_INLINE_DATA) { decode(inline_version, p); decode(inline_data, p); } else { inline_version = CEPH_INLINE_NONE; } if (features & CEPH_FEATURE_MDS_QUOTA) decode(quota, p); else quota = quota_info_t{}; if ((features & CEPH_FEATURE_FS_FILE_LAYOUT_V2)) decode(layout.pool_ns, p); if ((features & CEPH_FEATURE_FS_BTIME)) { decode(btime, p); decode(change_attr, p); } else { btime = utime_t(); change_attr = 0; } } } // see CInode::encode_inodestat for encoder. }; struct openc_response_t { _inodeno_t created_ino; interval_set<inodeno_t> delegated_inos; public: void encode(ceph::buffer::list& bl) const { using ceph::encode; ENCODE_START(1, 1, bl); encode(created_ino, bl); encode(delegated_inos, bl); ENCODE_FINISH(bl); } void decode(ceph::buffer::list::const_iterator &p) { using ceph::decode; DECODE_START(1, p); decode(created_ino, p); decode(delegated_inos, p); DECODE_FINISH(p); } } __attribute__ ((__may_alias__)); WRITE_CLASS_ENCODER(openc_response_t) class MClientReply final : public MMDSOp { public: // reply data struct ceph_mds_reply_head head {}; ceph::buffer::list trace_bl; ceph::buffer::list extra_bl; ceph::buffer::list snapbl; int get_op() const { return head.op; } void set_mdsmap_epoch(epoch_t e) { head.mdsmap_epoch = e; } epoch_t get_mdsmap_epoch() const { return head.mdsmap_epoch; } int get_result() const { #ifdef _WIN32 // libclient and libcephfs return CEPHFS_E* errors, which are basically // Linux errno codes. If we convert mds errors to host errno values, we // end up mixing error codes. // // For Windows, we'll preserve the original error value, which is expected // to be a linux (CEPHFS_E*) error. It may be worth doing the same for // other platforms. return head.result; #else return ceph_to_hostos_errno((__s32)(__u32)head.result); #endif } void set_result(int r) { head.result = r; } void set_unsafe() { head.safe = 0; } bool is_safe() const { return head.safe; } protected: MClientReply() : MMDSOp{CEPH_MSG_CLIENT_REPLY} {} MClientReply(const MClientRequest &req, int result = 0) : MMDSOp{CEPH_MSG_CLIENT_REPLY} { memset(&head, 0, sizeof(head)); header.tid = req.get_tid(); head.op = req.get_op(); head.result = result; head.safe = 1; } ~MClientReply() final {} public: std::string_view get_type_name() const override { return "creply"; } void print(std::ostream& o) const override { o << "client_reply(???:" << get_tid(); o << " = " << get_result(); if (get_result() <= 0) { o << " " << cpp_strerror(get_result()); } if (head.op & CEPH_MDS_OP_WRITE) { if (head.safe) o << " safe"; else o << " unsafe"; } o << ")"; } // serialization void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(head, p); decode(trace_bl, p); decode(extra_bl, p); decode(snapbl, p); ceph_assert(p.end()); } void encode_payload(uint64_t features) override { using ceph::encode; encode(head, payload); encode(trace_bl, payload); encode(extra_bl, payload); encode(snapbl, payload); } // dir contents void set_extra_bl(ceph::buffer::list& bl) { extra_bl = std::move(bl); } ceph::buffer::list& get_extra_bl() { return extra_bl; } const ceph::buffer::list& get_extra_bl() const { return extra_bl; } // trace void set_trace(ceph::buffer::list& bl) { trace_bl = std::move(bl); } ceph::buffer::list& get_trace_bl() { return trace_bl; } const ceph::buffer::list& get_trace_bl() const { return trace_bl; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
10,834
24.434272
85
h
null
ceph-main/src/messages/MClientRequest.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTREQUEST_H #define CEPH_MCLIENTREQUEST_H /** * * MClientRequest - container for a client METADATA request. created/sent by clients. * can be forwarded around between MDS's. * * int client - the originating client * long tid - transaction id, unique among requests for that client. probably just a counter! * -> the MDS passes the Request to the Reply constructor, so this always matches. * * int op - the metadata op code. MDS_OP_RENAME, etc. * int caller_uid, _gid - guess * * fixed size arguments are in a union. * there's also a string argument, for e.g. symlink(). * */ #include <string_view> #include "include/filepath.h" #include "mds/mdstypes.h" #include "include/ceph_features.h" #include "messages/MMDSOp.h" #include <sys/types.h> #include <utime.h> #include <sys/stat.h> #include <fcntl.h> struct SnapPayload { std::map<std::string, std::string> metadata; void encode(ceph::buffer::list &bl) const { ENCODE_START(1, 1, bl); encode(metadata, bl); ENCODE_FINISH(bl); } void decode(ceph::buffer::list::const_iterator &iter) { DECODE_START(1, iter); decode(metadata, iter); DECODE_FINISH(iter); } }; WRITE_CLASS_ENCODER(SnapPayload) // metadata ops. class MClientRequest final : public MMDSOp { private: static constexpr int HEAD_VERSION = 6; static constexpr int COMPAT_VERSION = 1; public: mutable struct ceph_mds_request_head head; /* XXX HACK! */ utime_t stamp; bool peer_old_version = false; struct Release { mutable ceph_mds_request_release item; std::string dname; Release() : item(), dname() {} Release(const ceph_mds_request_release& rel, std::string name) : item(rel), dname(name) {} void encode(ceph::buffer::list& bl) const { using ceph::encode; item.dname_len = dname.length(); encode(item, bl); ceph::encode_nohead(dname, bl); } void decode(ceph::buffer::list::const_iterator& bl) { using ceph::decode; decode(item, bl); ceph::decode_nohead(item.dname_len, dname, bl); } }; mutable std::vector<Release> releases; /* XXX HACK! */ // path arguments filepath path, path2; std::string alternate_name; std::vector<uint64_t> gid_list; std::vector<uint8_t> fscrypt_auth; std::vector<uint8_t> fscrypt_file; /* XXX HACK */ mutable bool queued_for_replay = false; protected: // cons MClientRequest() : MMDSOp(CEPH_MSG_CLIENT_REQUEST, HEAD_VERSION, COMPAT_VERSION) { memset(&head, 0, sizeof(head)); } MClientRequest(int op, bool over=true) : MMDSOp(CEPH_MSG_CLIENT_REQUEST, HEAD_VERSION, COMPAT_VERSION) { memset(&head, 0, sizeof(head)); head.op = op; peer_old_version = over; } ~MClientRequest() final {} public: void set_mdsmap_epoch(epoch_t e) { head.mdsmap_epoch = e; } epoch_t get_mdsmap_epoch() const { return head.mdsmap_epoch; } epoch_t get_osdmap_epoch() const { ceph_assert(head.op == CEPH_MDS_OP_SETXATTR); if (header.version >= 3) return head.args.setxattr.osdmap_epoch; else return 0; } void set_osdmap_epoch(epoch_t e) { ceph_assert(head.op == CEPH_MDS_OP_SETXATTR); head.args.setxattr.osdmap_epoch = e; } metareqid_t get_reqid() const { // FIXME: for now, assume clients always have 1 incarnation return metareqid_t(get_orig_source(), header.tid); } /*bool open_file_mode_is_readonly() { return file_mode_is_readonly(ceph_flags_to_mode(head.args.open.flags)); }*/ bool may_write() const { return (head.op & CEPH_MDS_OP_WRITE) || (head.op == CEPH_MDS_OP_OPEN && (head.args.open.flags & (O_CREAT|O_TRUNC))); } int get_flags() const { return head.flags; } bool is_replay() const { return get_flags() & CEPH_MDS_FLAG_REPLAY; } bool is_async() const { return get_flags() & CEPH_MDS_FLAG_ASYNC; } // normal fields void set_stamp(utime_t t) { stamp = t; } void set_oldest_client_tid(ceph_tid_t t) { head.oldest_client_tid = t; } void inc_num_fwd() { head.ext_num_fwd = head.ext_num_fwd + 1; } void set_retry_attempt(int a) { head.ext_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(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) { gid_list.reserve(count); for (int i = 0; i < count; ++i) { gid_list.push_back(gids[i]); } } void set_dentry_wanted() { head.flags = head.flags | CEPH_MDS_FLAG_WANT_DENTRY; } void set_replayed_op() { head.flags = head.flags | CEPH_MDS_FLAG_REPLAY; } void set_async_op() { head.flags = head.flags | CEPH_MDS_FLAG_ASYNC; } void set_alternate_name(std::string _alternate_name) { alternate_name = std::move(_alternate_name); } void set_alternate_name(bufferptr&& cipher) { alternate_name = std::move(cipher.c_str()); } utime_t get_stamp() const { return stamp; } ceph_tid_t get_oldest_client_tid() const { return head.oldest_client_tid; } int get_num_fwd() const { return head.ext_num_fwd; } int get_retry_attempt() const { return head.ext_num_retry; } int get_op() const { return head.op; } unsigned get_caller_uid() const { return head.caller_uid; } unsigned get_caller_gid() const { return head.caller_gid; } const std::vector<uint64_t>& get_caller_gid_list() const { return gid_list; } const std::string& get_path() const { return path.get_path(); } const filepath& get_filepath() const { return path; } const std::string& get_path2() const { return path2.get_path(); } const filepath& get_filepath2() const { return path2; } std::string_view get_alternate_name() const { return std::string_view(alternate_name); } int get_dentry_wanted() const { return get_flags() & CEPH_MDS_FLAG_WANT_DENTRY; } void mark_queued_for_replay() const { queued_for_replay = true; } bool is_queued_for_replay() const { return queued_for_replay; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); if (header.version >= 4) { decode(head, p); } else { struct ceph_mds_request_head_legacy old_mds_head; decode(old_mds_head, p); copy_from_legacy_head(&head, &old_mds_head); head.version = 0; /* Can't set the btime from legacy struct */ if (head.op == CEPH_MDS_OP_SETATTR) { int localmask = head.args.setattr.mask; localmask &= ~CEPH_SETATTR_BTIME; head.args.setattr.btime = { ceph_le32(0), ceph_le32(0) }; head.args.setattr.mask = localmask; } } decode(path, p); decode(path2, p); ceph::decode_nohead(head.num_releases, releases, p); if (header.version >= 2) decode(stamp, p); if (header.version >= 4) // epoch 3 was for a ceph_mds_request_args change decode(gid_list, p); if (header.version >= 5) decode(alternate_name, p); if (header.version >= 6) { decode(fscrypt_auth, p); decode(fscrypt_file, p); } } void encode_payload(uint64_t features) override { using ceph::encode; head.num_releases = releases.size(); /* * If the peer is old version, we must skip all the * new members, because the old version of MDS or * client will just copy the 'head' memory and isn't * that smart to skip them. */ if (peer_old_version) { head.version = 1; } else { head.version = CEPH_MDS_REQUEST_HEAD_VERSION; } if (features & CEPH_FEATURE_FS_BTIME) { encode(head, payload, peer_old_version); } else { struct ceph_mds_request_head_legacy old_mds_head; copy_to_legacy_head(&old_mds_head, &head); encode(old_mds_head, payload); } encode(path, payload); encode(path2, payload); ceph::encode_nohead(releases, payload); encode(stamp, payload); encode(gid_list, payload); encode(alternate_name, payload); encode(fscrypt_auth, payload); encode(fscrypt_file, payload); } std::string_view get_type_name() const override { return "creq"; } void print(std::ostream& out) const override { out << "client_request(" << get_orig_source() << ":" << get_tid() << " " << ceph_mds_op_name(get_op()); if (head.op == CEPH_MDS_OP_GETATTR) out << " " << ccap_string(head.args.getattr.mask); if (head.op == CEPH_MDS_OP_SETATTR) { if (head.args.setattr.mask & CEPH_SETATTR_MODE) out << " mode=0" << std::oct << head.args.setattr.mode << std::dec; if (head.args.setattr.mask & CEPH_SETATTR_UID) out << " uid=" << head.args.setattr.uid; if (head.args.setattr.mask & CEPH_SETATTR_GID) out << " gid=" << head.args.setattr.gid; if (head.args.setattr.mask & CEPH_SETATTR_SIZE) out << " size=" << head.args.setattr.size; if (head.args.setattr.mask & CEPH_SETATTR_MTIME) out << " mtime=" << utime_t(head.args.setattr.mtime); if (head.args.setattr.mask & CEPH_SETATTR_ATIME) out << " atime=" << utime_t(head.args.setattr.atime); } if (head.op == CEPH_MDS_OP_SETFILELOCK || head.op == CEPH_MDS_OP_GETFILELOCK) { out << " rule " << (int)head.args.filelock_change.rule << ", type " << (int)head.args.filelock_change.type << ", owner " << head.args.filelock_change.owner << ", pid " << head.args.filelock_change.pid << ", start " << head.args.filelock_change.start << ", length " << head.args.filelock_change.length << ", wait " << (int)head.args.filelock_change.wait; } //if (!get_filepath().empty()) out << " " << get_filepath(); if (alternate_name.size()) out << " (" << alternate_name << ") "; if (!get_filepath2().empty()) out << " " << get_filepath2(); if (stamp != utime_t()) out << " " << stamp; if (head.ext_num_fwd) out << " FWD=" << (int)head.ext_num_fwd; if (head.ext_num_retry) out << " RETRY=" << (int)head.ext_num_retry; if (is_async()) out << " ASYNC"; if (is_replay()) out << " REPLAY"; if (queued_for_replay) out << " QUEUED_FOR_REPLAY"; out << " caller_uid=" << head.caller_uid << ", caller_gid=" << head.caller_gid << '{'; for (auto i = gid_list.begin(); i != gid_list.end(); ++i) out << *i << ','; out << '}' << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; WRITE_CLASS_ENCODER(MClientRequest::Release) #endif
11,113
30.131653
98
h
null
ceph-main/src/messages/MClientRequestForward.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTREQUESTFORWARD_H #define CEPH_MCLIENTREQUESTFORWARD_H #include "msg/Message.h" class MClientRequestForward final : public SafeMessage { private: int32_t dest_mds; int32_t num_fwd; bool client_must_resend; protected: MClientRequestForward() : SafeMessage{CEPH_MSG_CLIENT_REQUEST_FORWARD}, dest_mds(-1), num_fwd(-1), client_must_resend(false) {} MClientRequestForward(ceph_tid_t t, int dm, int nf, bool cmr) : SafeMessage{CEPH_MSG_CLIENT_REQUEST_FORWARD}, dest_mds(dm), num_fwd(nf), client_must_resend(cmr) { ceph_assert(client_must_resend); header.tid = t; } ~MClientRequestForward() final {} public: int get_dest_mds() const { return dest_mds; } int get_num_fwd() const { return num_fwd; } bool must_resend() const { return client_must_resend; } std::string_view get_type_name() const override { return "client_request_forward"; } void print(std::ostream& o) const override { o << "client_request_forward(" << get_tid() << " to mds." << dest_mds << " num_fwd=" << num_fwd << (client_must_resend ? " client_must_resend":"") << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(dest_mds, payload); encode(num_fwd, payload); encode(client_must_resend, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dest_mds, p); decode(num_fwd, p); decode(client_must_resend, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,152
27.706667
86
h
null
ceph-main/src/messages/MClientSession.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTSESSION_H #define CEPH_MCLIENTSESSION_H #include "msg/Message.h" #include "mds/mdstypes.h" class MClientSession final : public SafeMessage { private: static constexpr int HEAD_VERSION = 5; static constexpr int COMPAT_VERSION = 1; public: ceph_mds_session_head head; static constexpr unsigned SESSION_BLOCKLISTED = (1<<0); unsigned flags = 0; std::map<std::string, std::string> metadata; feature_bitset_t supported_features; metric_spec_t metric_spec; int get_op() const { return head.op; } version_t get_seq() const { return head.seq; } utime_t get_stamp() const { return utime_t(head.stamp); } int get_max_caps() const { return head.max_caps; } int get_max_leases() const { return head.max_leases; } protected: MClientSession() : SafeMessage{CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION} { } MClientSession(int o, version_t s=0, unsigned msg_flags=0) : SafeMessage{CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION}, flags(msg_flags) { memset(&head, 0, sizeof(head)); head.op = o; head.seq = s; } MClientSession(int o, utime_t st) : SafeMessage{CEPH_MSG_CLIENT_SESSION, HEAD_VERSION, COMPAT_VERSION} { memset(&head, 0, sizeof(head)); head.op = o; head.seq = 0; st.encode_timeval(&head.stamp); } ~MClientSession() final {} public: std::string_view get_type_name() const override { return "client_session"; } void print(std::ostream& out) const override { out << "client_session(" << ceph_session_op_name(get_op()); if (get_seq()) out << " seq " << get_seq(); if (get_op() == CEPH_SESSION_RECALL_STATE) out << " max_caps " << head.max_caps << " max_leases " << head.max_leases; out << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(head, p); if (header.version >= 2) decode(metadata, p); if (header.version >= 3) decode(supported_features, p); if (header.version >= 4) { decode(metric_spec, p); } if (header.version >= 5) { decode(flags, p); } } void encode_payload(uint64_t features) override { using ceph::encode; encode(head, payload); if (metadata.empty() && supported_features.empty()) { // If we're not trying to send any metadata (always the case if // we are a server) then send older-format message to avoid upsetting // old kernel clients. header.version = 1; } else { header.version = HEAD_VERSION; encode(metadata, payload); encode(supported_features, payload); encode(metric_spec, payload); encode(flags, payload); } } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
3,326
29.522936
91
h
null
ceph-main/src/messages/MClientSnap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCLIENTSNAP_H #define CEPH_MCLIENTSNAP_H #include "msg/Message.h" class MClientSnap final : public SafeMessage { public: ceph_mds_snap_head head; ceph::buffer::list bl; // (for split only) std::vector<inodeno_t> split_inos; std::vector<inodeno_t> split_realms; protected: MClientSnap(int o=0) : SafeMessage{CEPH_MSG_CLIENT_SNAP} { memset(&head, 0, sizeof(head)); head.op = o; } ~MClientSnap() final {} public: std::string_view get_type_name() const override { return "client_snap"; } void print(std::ostream& out) const override { out << "client_snap(" << ceph_snap_op_name(head.op); if (head.split) out << " split=" << inodeno_t(head.split); out << " tracelen=" << bl.length(); out << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; head.num_split_inos = split_inos.size(); head.num_split_realms = split_realms.size(); head.trace_len = bl.length(); encode(head, payload); ceph::encode_nohead(split_inos, payload); ceph::encode_nohead(split_realms, payload); ceph::encode_nohead(bl, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(head, p); ceph::decode_nohead(head.num_split_inos, split_inos, p); ceph::decode_nohead(head.num_split_realms, split_realms, p); ceph::decode_nohead(head.trace_len, bl, p); ceph_assert(p.end()); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,106
27.472973
75
h
null
ceph-main/src/messages/MCommand.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCOMMAND_H #define CEPH_MCOMMAND_H #include <vector> #include "msg/Message.h" class MCommand final : public Message { public: uuid_d fsid; std::vector<std::string> cmd; MCommand() : Message{MSG_COMMAND} {} MCommand(const uuid_d &f) : Message{MSG_COMMAND}, fsid(f) { } private: ~MCommand() final {} public: std::string_view get_type_name() const override { return "command"; } void print(std::ostream& o) const override { o << "command(tid " << get_tid() << ": "; for (unsigned i=0; i<cmd.size(); i++) { if (i) o << ' '; o << cmd[i]; } o << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(fsid, payload); encode(cmd, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(fsid, p); decode(cmd, p); } }; #endif
1,335
20.901639
71
h
null
ceph-main/src/messages/MCommandReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MCOMMANDREPLY_H #define CEPH_MCOMMANDREPLY_H #include <string_view> #include "msg/Message.h" #include "MCommand.h" class MCommandReply final : public Message { public: errorcode32_t r; std::string rs; MCommandReply() : Message{MSG_COMMAND_REPLY} {} MCommandReply(MCommand *m, int _r) : Message{MSG_COMMAND_REPLY}, r(_r) { header.tid = m->get_tid(); } MCommandReply(int _r, std::string_view s) : Message{MSG_COMMAND_REPLY}, r(_r), rs(s) { } private: ~MCommandReply() final {} public: std::string_view get_type_name() const override { return "command_reply"; } void print(std::ostream& o) const override { o << "command_reply(tid " << get_tid() << ": " << r << " " << rs << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(r, payload); encode(rs, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(r, p); decode(rs, p); } }; #endif
1,448
23.15
77
h
null
ceph-main/src/messages/MConfig.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "msg/Message.h" class MConfig : public Message { public: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; // use transparent comparator so we can lookup in it by std::string_view keys std::map<std::string,std::string,std::less<>> config; MConfig() : Message{MSG_CONFIG, HEAD_VERSION, COMPAT_VERSION} { } MConfig(const std::map<std::string,std::string,std::less<>>& c) : Message{MSG_CONFIG, HEAD_VERSION, COMPAT_VERSION}, config{c} {} MConfig(std::map<std::string,std::string,std::less<>>&& c) : Message{MSG_CONFIG, HEAD_VERSION, COMPAT_VERSION}, config{std::move(c)} {} std::string_view get_type_name() const override { return "config"; } void print(std::ostream& o) const override { o << "config(" << config.size() << " keys" << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(config, p); } void encode_payload(uint64_t) override { using ceph::encode; encode(config, payload); } };
1,167
26.162791
79
h
null
ceph-main/src/messages/MDentryLink.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDENTRYLINK_H #define CEPH_MDENTRYLINK_H #include <string_view> #include "messages/MMDSOp.h" class MDentryLink final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; dirfrag_t subtree; dirfrag_t dirfrag; std::string dn; bool is_primary = false; public: dirfrag_t get_subtree() const { return subtree; } dirfrag_t get_dirfrag() const { return dirfrag; } const std::string& get_dn() const { return dn; } bool get_is_primary() const { return is_primary; } ceph::buffer::list bl; protected: MDentryLink() : MMDSOp(MSG_MDS_DENTRYLINK, HEAD_VERSION, COMPAT_VERSION) { } MDentryLink(dirfrag_t r, dirfrag_t df, std::string_view n, bool p) : MMDSOp(MSG_MDS_DENTRYLINK, HEAD_VERSION, COMPAT_VERSION), subtree(r), dirfrag(df), dn(n), is_primary(p) {} ~MDentryLink() final {} public: std::string_view get_type_name() const override { return "dentry_link";} void print(std::ostream& o) const override { o << "dentry_link(" << dirfrag << " " << dn << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(subtree, p); decode(dirfrag, p); decode(dn, p); decode(is_primary, p); decode(bl, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(subtree, payload); encode(dirfrag, payload); encode(dn, payload); encode(is_primary, payload); encode(bl, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,173
25.192771
74
h
null
ceph-main/src/messages/MDentryUnlink.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDENTRYUNLINK_H #define CEPH_MDENTRYUNLINK_H #include <string_view> #include "messages/MMDSOp.h" class MDentryUnlink final : public MMDSOp { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; dirfrag_t dirfrag; std::string dn; bool unlinking = false; public: dirfrag_t get_dirfrag() const { return dirfrag; } const std::string& get_dn() const { return dn; } bool is_unlinking() const { return unlinking; } ceph::buffer::list straybl; ceph::buffer::list snapbl; protected: MDentryUnlink() : MMDSOp(MSG_MDS_DENTRYUNLINK, HEAD_VERSION, COMPAT_VERSION) { } MDentryUnlink(dirfrag_t df, std::string_view n, bool u=false) : MMDSOp(MSG_MDS_DENTRYUNLINK, HEAD_VERSION, COMPAT_VERSION), dirfrag(df), dn(n), unlinking(u) {} ~MDentryUnlink() final {} public: std::string_view get_type_name() const override { return "dentry_unlink";} void print(std::ostream& o) const override { o << "dentry_unlink(" << dirfrag << " " << dn << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dirfrag, p); decode(dn, p); decode(straybl, p); if (header.version >= 2) decode(unlinking, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(dirfrag, payload); encode(dn, payload); encode(straybl, payload); encode(unlinking, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; class MDentryUnlinkAck final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; dirfrag_t dirfrag; std::string dn; public: dirfrag_t get_dirfrag() const { return dirfrag; } const std::string& get_dn() const { return dn; } protected: MDentryUnlinkAck() : MMDSOp(MSG_MDS_DENTRYUNLINK_ACK, HEAD_VERSION, COMPAT_VERSION) { } MDentryUnlinkAck(dirfrag_t df, std::string_view n) : MMDSOp(MSG_MDS_DENTRYUNLINK_ACK, HEAD_VERSION, COMPAT_VERSION), dirfrag(df), dn(n) {} ~MDentryUnlinkAck() final {} public: std::string_view get_type_name() const override { return "dentry_unlink_ack";} void print(std::ostream& o) const override { o << "dentry_unlink_ack(" << dirfrag << " " << dn << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dirfrag, p); decode(dn, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(dirfrag, payload); encode(dn, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
3,369
26.622951
80
h
null
ceph-main/src/messages/MDirUpdate.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDIRUPDATE_H #define CEPH_MDIRUPDATE_H #include "messages/MMDSOp.h" class MDirUpdate final : public MMDSOp { public: mds_rank_t get_source_mds() const { return from_mds; } dirfrag_t get_dirfrag() const { return dirfrag; } int get_dir_rep() const { return dir_rep; } const std::set<int32_t>& get_dir_rep_by() const { return dir_rep_by; } bool should_discover() const { return discover > tried_discover; } const filepath& get_path() const { return path; } bool has_tried_discover() const { return tried_discover > 0; } void inc_tried_discover() const { ++tried_discover; } std::string_view get_type_name() const override { return "dir_update"; } void print(std::ostream& out) const override { out << "dir_update(" << get_dirfrag() << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(from_mds, p); decode(dirfrag, p); decode(dir_rep, p); decode(discover, p); decode(dir_rep_by, p); decode(path, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(from_mds, payload); encode(dirfrag, payload); encode(dir_rep, payload); encode(discover, payload); encode(dir_rep_by, payload); encode(path, payload); } protected: ~MDirUpdate() final {} MDirUpdate() : MMDSOp(MSG_MDS_DIRUPDATE, HEAD_VERSION, COMPAT_VERSION) {} MDirUpdate(mds_rank_t f, dirfrag_t dirfrag, int dir_rep, const std::set<int32_t>& dir_rep_by, filepath& path, bool discover = false) : MMDSOp(MSG_MDS_DIRUPDATE, HEAD_VERSION, COMPAT_VERSION), from_mds(f), dirfrag(dirfrag), dir_rep(dir_rep), dir_rep_by(dir_rep_by), path(path) { this->discover = discover ? 5 : 0; } MDirUpdate(const MDirUpdate& m) : MMDSOp{MSG_MDS_DIRUPDATE}, from_mds(m.from_mds), dirfrag(m.dirfrag), dir_rep(m.dir_rep), discover(m.discover), dir_rep_by(m.dir_rep_by), path(m.path), tried_discover(m.tried_discover) {} mds_rank_t from_mds = -1; dirfrag_t dirfrag; int32_t dir_rep = 5; int32_t discover = 5; std::set<int32_t> dir_rep_by; filepath path; mutable int tried_discover = 0; // XXX HACK private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,972
28.435644
91
h
null
ceph-main/src/messages/MDiscover.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDISCOVER_H #define CEPH_MDISCOVER_H #include "include/filepath.h" #include "messages/MMDSOp.h" #include <string> class MDiscover final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; inodeno_t base_ino; // 1 -> root frag_t base_dir_frag; snapid_t snapid; filepath want; // ... [/]need/this/stuff bool want_base_dir = true; bool path_locked = false; public: inodeno_t get_base_ino() const { return base_ino; } frag_t get_base_dir_frag() const { return base_dir_frag; } snapid_t get_snapid() const { return snapid; } const filepath& get_want() const { return want; } const std::string& get_dentry(int n) const { return want[n]; } bool wants_base_dir() const { return want_base_dir; } bool is_path_locked() const { return path_locked; } void set_base_dir_frag(frag_t f) { base_dir_frag = f; } protected: MDiscover() : MMDSOp(MSG_MDS_DISCOVER, HEAD_VERSION, COMPAT_VERSION) { } MDiscover(inodeno_t base_ino_, frag_t base_frag_, snapid_t s, filepath& want_path_, bool want_base_dir_ = true, bool path_locked_ = false) : MMDSOp{MSG_MDS_DISCOVER}, base_ino(base_ino_), base_dir_frag(base_frag_), snapid(s), want(want_path_), want_base_dir(want_base_dir_), path_locked(path_locked_) { } ~MDiscover() final {} public: std::string_view get_type_name() const override { return "Dis"; } void print(std::ostream &out) const override { out << "discover(" << header.tid << " " << base_ino << "." << base_dir_frag << " " << want << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(base_ino, p); decode(base_dir_frag, p); decode(snapid, p); decode(want, p); decode(want_base_dir, p); decode(path_locked, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(base_ino, payload); encode(base_dir_frag, payload); encode(snapid, payload); encode(want, payload); encode(want_base_dir, payload); encode(path_locked, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,849
26.669903
79
h
null
ceph-main/src/messages/MDiscoverReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDISCOVERREPLY_H #define CEPH_MDISCOVERREPLY_H #include "include/filepath.h" #include "messages/MMDSOp.h" #include <string> /** * MDiscoverReply - return new replicas (of inodes, dirs, dentries) * * we group returned items by (dir, dentry, inode). each * item in each set shares an index (it's "depth"). * * we can start and end with any type. * no_base_dir = true if the first group has an inode but no dir * no_base_dentry = true if the first group has an inode but no dentry * they are false if there is no returned data, ie the first group is empty. * * we also return errors: * error_flag_dn(std::string) - the specified dentry dne * error_flag_dir - the last item wasn't a dir, so we couldn't continue. * * and sometimes, * dir_auth_hint - where we think the dir auth is * * depth() gives us the number of depth units/indices for which we have * information. this INCLUDES those for which we have errors but no data. * * see MDCache::handle_discover, handle_discover_reply. * * * so basically, we get * * dir den ino i * x 0 * x x x 1 * or * x x 0 * x x x 1 * or * x x x 0 * x x x 1 * ...and trail off however we want. * * */ class MDiscoverReply final : public MMDSOp { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 2; // info about original request inodeno_t base_ino; frag_t base_dir_frag; bool wanted_base_dir = false; bool path_locked = false; snapid_t wanted_snapid; // and the response bool flag_error_dn = false; bool flag_error_dir = false; std::string error_dentry; // dentry that was not found (to trigger waiters on asker) bool unsolicited = false; mds_rank_t dir_auth_hint = 0; public: __u8 starts_with = 0; ceph::buffer::list trace; enum { DIR, DENTRY, INODE }; // accessors inodeno_t get_base_ino() const { return base_ino; } frag_t get_base_dir_frag() const { return base_dir_frag; } bool get_wanted_base_dir() const { return wanted_base_dir; } bool is_path_locked() const { return path_locked; } snapid_t get_wanted_snapid() const { return wanted_snapid; } bool is_flag_error_dn() const { return flag_error_dn; } bool is_flag_error_dir() const { return flag_error_dir; } const std::string& get_error_dentry() const { return error_dentry; } int get_starts_with() const { return starts_with; } mds_rank_t get_dir_auth_hint() const { return dir_auth_hint; } bool is_unsolicited() const { return unsolicited; } void mark_unsolicited() { unsolicited = true; } void set_base_dir_frag(frag_t df) { base_dir_frag = df; } protected: MDiscoverReply() : MMDSOp{MSG_MDS_DISCOVERREPLY, HEAD_VERSION, COMPAT_VERSION} { } MDiscoverReply(const MDiscover &dis) : MMDSOp{MSG_MDS_DISCOVERREPLY, HEAD_VERSION, COMPAT_VERSION}, base_ino(dis.get_base_ino()), base_dir_frag(dis.get_base_dir_frag()), wanted_base_dir(dis.wants_base_dir()), path_locked(dis.is_path_locked()), wanted_snapid(dis.get_snapid()), flag_error_dn(false), flag_error_dir(false), unsolicited(false), dir_auth_hint(CDIR_AUTH_UNKNOWN), starts_with(DIR) { header.tid = dis.get_tid(); } MDiscoverReply(dirfrag_t df) : MMDSOp{MSG_MDS_DISCOVERREPLY, HEAD_VERSION, COMPAT_VERSION}, base_ino(df.ino), base_dir_frag(df.frag), wanted_base_dir(false), path_locked(false), wanted_snapid(CEPH_NOSNAP), flag_error_dn(false), flag_error_dir(false), unsolicited(false), dir_auth_hint(CDIR_AUTH_UNKNOWN), starts_with(DIR) { header.tid = 0; } ~MDiscoverReply() final {} public: std::string_view get_type_name() const override { return "discover_reply"; } void print(std::ostream& out) const override { out << "discover_reply(" << header.tid << " " << base_ino << ")"; } // builders bool is_empty() const { return trace.length() == 0 && !flag_error_dn && !flag_error_dir && dir_auth_hint == CDIR_AUTH_UNKNOWN; } // void set_flag_forward() { flag_forward = true; } void set_flag_error_dn(std::string_view dn) { flag_error_dn = true; error_dentry = dn; } void set_flag_error_dir() { flag_error_dir = true; } void set_dir_auth_hint(int a) { dir_auth_hint = a; } void set_error_dentry(std::string_view dn) { error_dentry = dn; } // ... void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(base_ino, p); decode(base_dir_frag, p); decode(wanted_base_dir, p); decode(path_locked, p); decode(wanted_snapid, p); decode(flag_error_dn, p); decode(flag_error_dir, p); decode(error_dentry, p); decode(dir_auth_hint, p); decode(unsolicited, p); decode(starts_with, p); decode(trace, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(base_ino, payload); encode(base_dir_frag, payload); encode(wanted_base_dir, payload); encode(path_locked, payload); encode(wanted_snapid, payload); encode(flag_error_dn, payload); encode(flag_error_dir, payload); encode(error_dentry, payload); encode(dir_auth_hint, payload); encode(unsolicited, payload); encode(starts_with, payload); encode(trace, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
6,051
26.761468
88
h
null
ceph-main/src/messages/MExportCaps.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTCAPS_H #define CEPH_MEXPORTCAPS_H #include "messages/MMDSOp.h" class MExportCaps final : public MMDSOp { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; public: inodeno_t ino; ceph::buffer::list cap_bl; std::map<client_t,entity_inst_t> client_map; std::map<client_t,client_metadata_t> client_metadata_map; protected: MExportCaps() : MMDSOp{MSG_MDS_EXPORTCAPS, HEAD_VERSION, COMPAT_VERSION} {} ~MExportCaps() final {} public: std::string_view get_type_name() const override { return "export_caps"; } void print(std::ostream& o) const override { o << "export_caps(" << ino << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(ino, payload); encode(cap_bl, payload); encode(client_map, payload, features); encode(client_metadata_map, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(ino, p); decode(cap_bl, p); decode(client_map, p); if (header.version >= 2) decode(client_metadata_map, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,783
25.626866
75
h
null
ceph-main/src/messages/MExportCapsAck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTCAPSACK_H #define CEPH_MEXPORTCAPSACK_H #include "messages/MMDSOp.h" class MExportCapsAck final : public MMDSOp { static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: inodeno_t ino; ceph::buffer::list cap_bl; protected: MExportCapsAck() : MMDSOp{MSG_MDS_EXPORTCAPSACK, HEAD_VERSION, COMPAT_VERSION} {} MExportCapsAck(inodeno_t i) : MMDSOp{MSG_MDS_EXPORTCAPSACK, HEAD_VERSION, COMPAT_VERSION}, ino(i) {} ~MExportCapsAck() final {} public: std::string_view get_type_name() const override { return "export_caps_ack"; } void print(std::ostream& o) const override { o << "export_caps_ack(" << ino << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(ino, payload); encode(cap_bl, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(ino, p); decode(cap_bl, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,619
25.557377
79
h
null
ceph-main/src/messages/MExportDir.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTDIR_H #define CEPH_MEXPORTDIR_H #include "messages/MMDSOp.h" class MExportDir final : public MMDSOp { public: dirfrag_t dirfrag; ceph::buffer::list export_data; std::vector<dirfrag_t> bounds; ceph::buffer::list client_map; protected: MExportDir() : MMDSOp{MSG_MDS_EXPORTDIR} {} MExportDir(dirfrag_t df, uint64_t tid) : MMDSOp{MSG_MDS_EXPORTDIR}, dirfrag(df) { set_tid(tid); } ~MExportDir() final {} public: std::string_view get_type_name() const override { return "Ex"; } void print(std::ostream& o) const override { o << "export(" << dirfrag << ")"; } void add_export(dirfrag_t df) { bounds.push_back(df); } void encode_payload(uint64_t features) override { using ceph::encode; encode(dirfrag, payload); encode(bounds, payload); encode(export_data, payload); encode(client_map, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dirfrag, p); decode(bounds, p); decode(export_data, p); decode(client_map, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,733
24.130435
71
h
null
ceph-main/src/messages/MExportDirAck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTDIRACK_H #define CEPH_MEXPORTDIRACK_H #include "MExportDir.h" #include "messages/MMDSOp.h" class MExportDirAck final : public MMDSOp { public: dirfrag_t dirfrag; ceph::buffer::list imported_caps; dirfrag_t get_dirfrag() const { return dirfrag; } protected: MExportDirAck() : MMDSOp{MSG_MDS_EXPORTDIRACK} {} MExportDirAck(dirfrag_t df, uint64_t tid) : MMDSOp{MSG_MDS_EXPORTDIRACK}, dirfrag(df) { set_tid(tid); } ~MExportDirAck() final {} public: std::string_view get_type_name() const override { return "ExAck"; } void print(std::ostream& o) const override { o << "export_ack(" << dirfrag << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dirfrag, p); decode(imported_caps, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(dirfrag, payload); encode(imported_caps, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,603
25.295082
71
h
null
ceph-main/src/messages/MExportDirCancel.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTDIRCANCEL_H #define CEPH_MEXPORTDIRCANCEL_H #include "include/types.h" #include "messages/MMDSOp.h" class MExportDirCancel final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; dirfrag_t dirfrag; public: dirfrag_t get_dirfrag() const { return dirfrag; } protected: MExportDirCancel() : MMDSOp{MSG_MDS_EXPORTDIRCANCEL, HEAD_VERSION, COMPAT_VERSION} {} MExportDirCancel(dirfrag_t df, uint64_t tid) : MMDSOp{MSG_MDS_EXPORTDIRCANCEL, HEAD_VERSION, COMPAT_VERSION}, dirfrag(df) { set_tid(tid); } ~MExportDirCancel() final {} public: std::string_view get_type_name() const override { return "ExCancel"; } void print(std::ostream& o) const override { o << "export_cancel(" << dirfrag << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(dirfrag, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dirfrag, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,686
26.655738
87
h
null
ceph-main/src/messages/MExportDirDiscover.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTDIRDISCOVER_H #define CEPH_MEXPORTDIRDISCOVER_H #include "include/types.h" #include "messages/MMDSOp.h" class MExportDirDiscover final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; mds_rank_t from = -1; dirfrag_t dirfrag; filepath path; public: mds_rank_t get_source_mds() const { return from; } inodeno_t get_ino() const { return dirfrag.ino; } dirfrag_t get_dirfrag() const { return dirfrag; } const filepath& get_path() const { return path; } bool started; protected: MExportDirDiscover() : MMDSOp{MSG_MDS_EXPORTDIRDISCOVER, HEAD_VERSION, COMPAT_VERSION}, started(false) { } MExportDirDiscover(dirfrag_t df, filepath& p, mds_rank_t f, uint64_t tid) : MMDSOp{MSG_MDS_EXPORTDIRDISCOVER, HEAD_VERSION, COMPAT_VERSION}, from(f), dirfrag(df), path(p), started(false) { set_tid(tid); } ~MExportDirDiscover() final {} public: std::string_view get_type_name() const override { return "ExDis"; } void print(std::ostream& o) const override { o << "export_discover(" << dirfrag << " " << path << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(from, p); decode(dirfrag, p); decode(path, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(from, payload); encode(dirfrag, payload); encode(path, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,123
26.947368
77
h
null
ceph-main/src/messages/MExportDirDiscoverAck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTDIRDISCOVERACK_H #define CEPH_MEXPORTDIRDISCOVERACK_H #include "include/types.h" #include "messages/MMDSOp.h" class MExportDirDiscoverAck final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; dirfrag_t dirfrag; bool success; public: inodeno_t get_ino() const { return dirfrag.ino; } dirfrag_t get_dirfrag() const { return dirfrag; } bool is_success() const { return success; } protected: MExportDirDiscoverAck() : MMDSOp{MSG_MDS_EXPORTDIRDISCOVERACK, HEAD_VERSION, COMPAT_VERSION} {} MExportDirDiscoverAck(dirfrag_t df, uint64_t tid, bool s=true) : MMDSOp{MSG_MDS_EXPORTDIRDISCOVERACK, HEAD_VERSION, COMPAT_VERSION}, dirfrag(df), success(s) { set_tid(tid); } ~MExportDirDiscoverAck() final {} public: std::string_view get_type_name() const override { return "ExDisA"; } void print(std::ostream& o) const override { o << "export_discover_ack(" << dirfrag; if (success) o << " success)"; else o << " failure)"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dirfrag, p); decode(success, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(dirfrag, payload); encode(success, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,996
26.736111
97
h
null
ceph-main/src/messages/MExportDirFinish.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTDIRFINISH_H #define CEPH_MEXPORTDIRFINISH_H #include "messages/MMDSOp.h" class MExportDirFinish final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; dirfrag_t dirfrag; bool last; public: dirfrag_t get_dirfrag() const { return dirfrag; } bool is_last() const { return last; } protected: MExportDirFinish() : MMDSOp{MSG_MDS_EXPORTDIRFINISH, HEAD_VERSION, COMPAT_VERSION}, last(false) {} MExportDirFinish(dirfrag_t df, bool l, uint64_t tid) : MMDSOp{MSG_MDS_EXPORTDIRFINISH, HEAD_VERSION, COMPAT_VERSION}, dirfrag(df), last(l) { set_tid(tid); } ~MExportDirFinish() final {} public: std::string_view get_type_name() const override { return "ExFin"; } void print(std::ostream& o) const override { o << "export_finish(" << dirfrag << (last ? " last" : "") << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(dirfrag, payload); encode(last, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dirfrag, p); decode(last, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,821
26.606061
89
h
null
ceph-main/src/messages/MExportDirNotify.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTDIRNOTIFY_H #define CEPH_MEXPORTDIRNOTIFY_H #include "messages/MMDSOp.h" class MExportDirNotify final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; dirfrag_t base; bool ack; std::pair<__s32,__s32> old_auth, new_auth; std::list<dirfrag_t> bounds; // bounds; these dirs are _not_ included (tho the dirfragdes are) public: dirfrag_t get_dirfrag() const { return base; } std::pair<__s32,__s32> get_old_auth() const { return old_auth; } std::pair<__s32,__s32> get_new_auth() const { return new_auth; } bool wants_ack() const { return ack; } const std::list<dirfrag_t>& get_bounds() const { return bounds; } std::list<dirfrag_t>& get_bounds() { return bounds; } protected: MExportDirNotify() : MMDSOp{MSG_MDS_EXPORTDIRNOTIFY, HEAD_VERSION, COMPAT_VERSION} {} MExportDirNotify(dirfrag_t i, uint64_t tid, bool a, std::pair<__s32,__s32> oa, std::pair<__s32,__s32> na) : MMDSOp{MSG_MDS_EXPORTDIRNOTIFY, HEAD_VERSION, COMPAT_VERSION}, base(i), ack(a), old_auth(oa), new_auth(na) { set_tid(tid); } ~MExportDirNotify() final {} public: std::string_view get_type_name() const override { return "ExNot"; } void print(std::ostream& o) const override { o << "export_notify(" << base; o << " " << old_auth << " -> " << new_auth; if (ack) o << " ack)"; else o << " no ack)"; } void copy_bounds(std::list<dirfrag_t>& ex) { this->bounds = ex; } void copy_bounds(std::set<dirfrag_t>& ex) { for (auto i = ex.begin(); i != ex.end(); ++i) bounds.push_back(*i); } void encode_payload(uint64_t features) override { using ceph::encode; encode(base, payload); encode(ack, payload); encode(old_auth, payload); encode(new_auth, payload); encode(bounds, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(base, p); decode(ack, p); decode(old_auth, p); decode(new_auth, p); decode(bounds, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,724
28.301075
97
h
null
ceph-main/src/messages/MExportDirNotifyAck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTDIRNOTIFYACK_H #define CEPH_MEXPORTDIRNOTIFYACK_H #include "messages/MMDSOp.h" class MExportDirNotifyAck final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; dirfrag_t dirfrag; std::pair<__s32,__s32> new_auth; public: dirfrag_t get_dirfrag() const { return dirfrag; } std::pair<__s32,__s32> get_new_auth() const { return new_auth; } protected: MExportDirNotifyAck() : MMDSOp{MSG_MDS_EXPORTDIRNOTIFYACK, HEAD_VERSION, COMPAT_VERSION} {} MExportDirNotifyAck(dirfrag_t df, uint64_t tid, std::pair<__s32,__s32> na) : MMDSOp{MSG_MDS_EXPORTDIRNOTIFYACK, HEAD_VERSION, COMPAT_VERSION}, dirfrag(df), new_auth(na) { set_tid(tid); } ~MExportDirNotifyAck() final {} public: std::string_view get_type_name() const override { return "ExNotA"; } void print(std::ostream& o) const override { o << "export_notify_ack(" << dirfrag << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(dirfrag, payload); encode(new_auth, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dirfrag, p); decode(new_auth, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,891
27.666667
97
h
null
ceph-main/src/messages/MExportDirPrep.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTDIRPREP_H #define CEPH_MEXPORTDIRPREP_H #include "include/types.h" #include "messages/MMDSOp.h" class MExportDirPrep final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; dirfrag_t dirfrag; public: ceph::buffer::list basedir; std::list<dirfrag_t> bounds; std::list<ceph::buffer::list> traces; private: std::set<mds_rank_t> bystanders; bool b_did_assim = false; public: dirfrag_t get_dirfrag() const { return dirfrag; } const std::list<dirfrag_t>& get_bounds() const { return bounds; } const std::set<mds_rank_t> &get_bystanders() const { return bystanders; } bool did_assim() const { return b_did_assim; } void mark_assim() { b_did_assim = true; } protected: MExportDirPrep() = default; MExportDirPrep(dirfrag_t df, uint64_t tid) : MMDSOp{MSG_MDS_EXPORTDIRPREP, HEAD_VERSION, COMPAT_VERSION}, dirfrag(df) { set_tid(tid); } ~MExportDirPrep() final {} public: std::string_view get_type_name() const override { return "ExP"; } void print(std::ostream& o) const override { o << "export_prep(" << dirfrag << ")"; } void add_bound(dirfrag_t df) { bounds.push_back( df ); } void add_trace(ceph::buffer::list& bl) { traces.push_back(bl); } void add_bystander(mds_rank_t who) { bystanders.insert(who); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dirfrag, p); decode(basedir, p); decode(bounds, p); decode(traces, p); decode(bystanders, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(dirfrag, payload); encode(basedir, payload); encode(bounds, payload); encode(traces, payload); encode(bystanders, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,464
24.677083
75
h
null
ceph-main/src/messages/MExportDirPrepAck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MEXPORTDIRPREPACK_H #define CEPH_MEXPORTDIRPREPACK_H #include "include/types.h" #include "messages/MMDSOp.h" class MExportDirPrepAck final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; dirfrag_t dirfrag; bool success = false; public: dirfrag_t get_dirfrag() const { return dirfrag; } protected: MExportDirPrepAck() : MMDSOp{MSG_MDS_EXPORTDIRPREPACK, HEAD_VERSION, COMPAT_VERSION} {} MExportDirPrepAck(dirfrag_t df, bool s, uint64_t tid) : MMDSOp{MSG_MDS_EXPORTDIRPREPACK, HEAD_VERSION, COMPAT_VERSION}, dirfrag(df), success(s) { set_tid(tid); } ~MExportDirPrepAck() final {} public: bool is_success() const { return success; } std::string_view get_type_name() const override { return "ExPAck"; } void print(std::ostream& o) const override { o << "export_prep_ack(" << dirfrag << (success ? " success)" : " fail)"); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(dirfrag, p); decode(success, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(dirfrag, payload); encode(success, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,876
27.014925
93
h
null
ceph-main/src/messages/MFSMap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MFSMAP_H #define CEPH_MFSMAP_H #include "msg/Message.h" #include "mds/FSMap.h" #include "include/ceph_features.h" class MFSMap final : public Message { public: epoch_t epoch; version_t get_epoch() const { return epoch; } const FSMap& get_fsmap() const {return fsmap;} MFSMap() : Message{CEPH_MSG_FS_MAP}, epoch(0) {} MFSMap(const uuid_d &f, const FSMap &fsmap_) : Message{CEPH_MSG_FS_MAP}, epoch(fsmap_.get_epoch()), fsmap{fsmap_} {} private: FSMap fsmap; ~MFSMap() final {} public: std::string_view get_type_name() const override { return "fsmap"; } void print(std::ostream& out) const override { out << "fsmap(e " << epoch << ")"; } // marshalling void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(epoch, p); decode(fsmap, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(epoch, payload); encode(fsmap, payload, features); } }; #endif
1,440
21.873016
71
h
null
ceph-main/src/messages/MFSMapUser.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. */ #ifndef CEPH_MFSMAPCOMPACT_H #define CEPH_MFSMAPCOMPACT_H #include "msg/Message.h" #include "mds/FSMapUser.h" #include "include/ceph_features.h" class MFSMapUser final : public Message { public: epoch_t epoch; version_t get_epoch() const { return epoch; } const FSMapUser& get_fsmap() const { return fsmap; } MFSMapUser() : Message{CEPH_MSG_FS_MAP_USER}, epoch(0) {} MFSMapUser(const uuid_d &f, const FSMapUser &fsmap_) : Message{CEPH_MSG_FS_MAP_USER}, epoch(fsmap_.epoch), fsmap{fsmap_} {} private: FSMapUser fsmap; ~MFSMapUser() final {} public: std::string_view get_type_name() const override { return "fsmap.user"; } void print(std::ostream& out) const override { out << "fsmap.user(e " << epoch << ")"; } // marshalling void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(epoch, p); decode(fsmap, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(epoch, payload); encode(fsmap, payload, features); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,611
23.8
74
h
null
ceph-main/src/messages/MForward.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2010 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * * Client requests often need to get forwarded from some monitor * to the leader. This class encapsulates the original message * along with the client's caps so the leader can do proper permissions * checking. */ #ifndef CEPH_MFORWARD_H #define CEPH_MFORWARD_H #include "msg/Message.h" #include "mon/MonCap.h" #include "include/encoding.h" #include "include/stringify.h" class MForward final : public Message { public: uint64_t tid; uint8_t client_type; entity_addrvec_t client_addrs; entity_addr_t client_socket_addr; MonCap client_caps; uint64_t con_features; EntityName entity_name; PaxosServiceMessage *msg; // incoming or outgoing message std::string msg_desc; // for operator<< only static constexpr int HEAD_VERSION = 4; static constexpr int COMPAT_VERSION = 4; MForward() : Message{MSG_FORWARD, HEAD_VERSION, COMPAT_VERSION}, tid(0), con_features(0), msg(NULL) {} MForward(uint64_t t, PaxosServiceMessage *m, uint64_t feat, const MonCap& caps) : Message{MSG_FORWARD, HEAD_VERSION, COMPAT_VERSION}, tid(t), client_caps(caps), msg(NULL) { client_type = m->get_source().type(); client_addrs = m->get_source_addrs(); #ifdef WITH_SEASTAR ceph_abort("In crimson, conn is independently maintained outside Message"); #else if (auto &con = m->get_connection()) { client_socket_addr = con->get_peer_socket_addr(); } #endif con_features = feat; msg = (PaxosServiceMessage*)m->get(); } private: ~MForward() final { if (msg) { // message was unclaimed msg->put(); msg = NULL; } } public: void encode_payload(uint64_t features) override { using ceph::encode; if (!HAVE_FEATURE(features, SERVER_NAUTILUS)) { header.version = 3; header.compat_version = 3; encode(tid, payload); entity_inst_t client; client.name = entity_name_t(client_type, -1); client.addr = client_addrs.legacy_addr(); encode(client, payload, features); encode(client_caps, payload, features); // Encode client message with intersection of target and source // features. This could matter if the semantics of the encoded // message are changed when reencoding with more features than the // client had originally. That should never happen, but we may as // well be defensive here. if (con_features != features) { msg->clear_payload(); } encode_message(msg, features & con_features, payload); encode(con_features, payload); encode(entity_name, payload); return; } header.version = HEAD_VERSION; header.compat_version = COMPAT_VERSION; encode(tid, payload); encode(client_type, payload, features); encode(client_addrs, payload, features); encode(client_socket_addr, payload, features); encode(client_caps, payload, features); // Encode client message with intersection of target and source // features. This could matter if the semantics of the encoded // message are changed when reencoding with more features than the // client had originally. That should never happen, but we may as // well be defensive here. if (con_features != features) { msg->clear_payload(); } encode_message(msg, features & con_features, payload); encode(con_features, payload); encode(entity_name, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(tid, p); if (header.version < 4) { entity_inst_t client; decode(client, p); client_type = client.name.type(); client_addrs = entity_addrvec_t(client.addr); client_socket_addr = client.addr; } else { decode(client_type, p); decode(client_addrs, p); decode(client_socket_addr, p); } decode(client_caps, p); msg = (PaxosServiceMessage *)decode_message(NULL, 0, p); decode(con_features, p); decode(entity_name, p); } PaxosServiceMessage *claim_message() { // let whoever is claiming the message deal with putting it. ceph_assert(msg); msg_desc = stringify(*msg); PaxosServiceMessage *m = msg; msg = NULL; return m; } std::string_view get_type_name() const override { return "forward"; } void print(std::ostream& o) const override { o << "forward("; if (msg) { o << *msg; } else { o << msg_desc; } o << " caps " << client_caps << " tid " << tid << " con_features " << con_features << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
5,094
30.257669
79
h
null
ceph-main/src/messages/MGatherCaps.h
#ifndef CEPH_MGATHERCAPS_H #define CEPH_MGATHERCAPS_H #include "messages/MMDSOp.h" class MGatherCaps final : public MMDSOp { static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: inodeno_t ino; protected: MGatherCaps() : MMDSOp{MSG_MDS_GATHERCAPS, HEAD_VERSION, COMPAT_VERSION} {} ~MGatherCaps() final {} public: std::string_view get_type_name() const override { return "gather_caps"; } void print(std::ostream& o) const override { o << "gather_caps(" << ino << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(ino, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(ino, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
976
22.261905
75
h
null
ceph-main/src/messages/MGenericMessage.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MGENERICMESSAGE_H #define CEPH_MGENERICMESSAGE_H #include "msg/Message.h" class MGenericMessage : public Message { private: char tname[20]; //long pcid; public: MGenericMessage(int t=0) : Message{t} { snprintf(tname, sizeof(tname), "generic%d", get_type()); } //void set_pcid(long pcid) { this->pcid = pcid; } //long get_pcid() { return pcid; } std::string_view get_type_name() const override { return tname; } void decode_payload() override { } void encode_payload(uint64_t features) override { } }; #endif
981
22.95122
71
h
null
ceph-main/src/messages/MGetConfig.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "msg/Message.h" class MGetConfig : public Message { public: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; EntityName name; ///< e.g., mon.a, client.foo std::string host; ///< our hostname std::string device_class; MGetConfig() : Message{MSG_GET_CONFIG, HEAD_VERSION, COMPAT_VERSION} { } MGetConfig(const EntityName& n, const std::string& h) : Message{MSG_GET_CONFIG, HEAD_VERSION, COMPAT_VERSION}, name(n), host(h) {} std::string_view get_type_name() const override { return "get_config"; } void print(std::ostream& o) const override { o << "get_config(" << name << "@" << host; if (device_class.size()) { o << " device_class " << device_class; } o << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(name, p); decode(host, p); decode(device_class, p); } void encode_payload(uint64_t) override { using ceph::encode; encode(name, payload); encode(host, payload); encode(device_class, payload); } };
1,219
23.897959
74
h
null
ceph-main/src/messages/MGetPoolStats.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MGETPOOLSTATS_H #define CEPH_MGETPOOLSTATS_H #include "messages/PaxosServiceMessage.h" class MGetPoolStats final : public PaxosServiceMessage { public: uuid_d fsid; std::vector<std::string> pools; MGetPoolStats() : PaxosServiceMessage{MSG_GETPOOLSTATS, 0} {} MGetPoolStats(const uuid_d& f, ceph_tid_t t, std::vector<std::string>& ls, version_t l) : PaxosServiceMessage{MSG_GETPOOLSTATS, l}, fsid(f), pools(ls) { set_tid(t); } private: ~MGetPoolStats() final {} public: std::string_view get_type_name() const override { return "getpoolstats"; } void print(std::ostream& out) const override { out << "getpoolstats(" << get_tid() << " " << pools << " v" << version << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(fsid, payload); encode(pools, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(fsid, p); decode(pools, p); } }; #endif
1,479
24.517241
91
h
null
ceph-main/src/messages/MGetPoolStatsReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MGETPOOLSTATSREPLY_H #define CEPH_MGETPOOLSTATSREPLY_H class MGetPoolStatsReply final : public PaxosServiceMessage { static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; public: uuid_d fsid; boost::container::flat_map<std::string, pool_stat_t> pool_stats; bool per_pool = false; MGetPoolStatsReply() : PaxosServiceMessage{MSG_GETPOOLSTATSREPLY, 0, HEAD_VERSION, COMPAT_VERSION} {} MGetPoolStatsReply(uuid_d& f, ceph_tid_t t, version_t v) : PaxosServiceMessage{MSG_GETPOOLSTATSREPLY, v, HEAD_VERSION, COMPAT_VERSION}, fsid(f) { set_tid(t); } private: ~MGetPoolStatsReply() final {} public: std::string_view get_type_name() const override { return "getpoolstats"; } void print(std::ostream& out) const override { out << "getpoolstatsreply(" << get_tid(); if (per_pool) out << " per_pool"; out << " v" << version << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(fsid, payload); encode(pool_stats, payload, features); encode(per_pool, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(fsid, p); decode(pool_stats, p); if (header.version >= 2) { decode(per_pool, p); } else { per_pool = false; } } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,956
25.445946
76
h
null
ceph-main/src/messages/MHeartbeat.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MHEARTBEAT_H #define CEPH_MHEARTBEAT_H #include "include/types.h" #include "common/DecayCounter.h" #include "messages/MMDSOp.h" class MHeartbeat final : public MMDSOp { private: mds_load_t load; __s32 beat = 0; std::map<mds_rank_t, float> import_map; public: const mds_load_t& get_load() const { return load; } int get_beat() const { return beat; } const std::map<mds_rank_t, float>& get_import_map() const { return import_map; } std::map<mds_rank_t, float>& get_import_map() { return import_map; } protected: MHeartbeat() : MMDSOp(MSG_MDS_HEARTBEAT), load(DecayRate()) {} MHeartbeat(mds_load_t& load, int beat) : MMDSOp(MSG_MDS_HEARTBEAT), load(load), beat(beat) {} ~MHeartbeat() final {} public: std::string_view get_type_name() const override { return "HB"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(load, payload); encode(beat, payload); encode(import_map, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(load, p); decode(beat, p); decode(import_map, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,806
25.188406
82
h
null
ceph-main/src/messages/MInodeFileCaps.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MINODEFILECAPS_H #define CEPH_MINODEFILECAPS_H #include "messages/MMDSOp.h" class MInodeFileCaps final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; inodeno_t ino; __u32 caps = 0; public: inodeno_t get_ino() const { return ino; } int get_caps() const { return caps; } protected: MInodeFileCaps() : MMDSOp(MSG_MDS_INODEFILECAPS, HEAD_VERSION, COMPAT_VERSION) {} MInodeFileCaps(inodeno_t ino, int caps) : MMDSOp(MSG_MDS_INODEFILECAPS, HEAD_VERSION, COMPAT_VERSION) { this->ino = ino; this->caps = caps; } ~MInodeFileCaps() final {} public: std::string_view get_type_name() const override { return "inode_file_caps";} void print(std::ostream& out) const override { out << "inode_file_caps(" << ino << " " << ccap_string(caps) << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(ino, payload); encode(caps, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(ino, p); decode(caps, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,787
26.090909
83
h
null
ceph-main/src/messages/MKVData.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #pragma once #include "msg/Message.h" class MKVData : public Message { public: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; version_t version; std::string prefix; bool incremental = false; // use transparent comparator so we can lookup in it by std::string_view keys std::map<std::string,std::optional<bufferlist>,std::less<>> data; MKVData() : Message{MSG_KV_DATA, HEAD_VERSION, COMPAT_VERSION} { } std::string_view get_type_name() const override { return "kv_data"; } void print(std::ostream& o) const override { o << "kv_data(v" << version << " prefix " << prefix << ", " << (incremental ? "incremental, " : "full, ") << data.size() << " keys" << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(version, p); decode(prefix, p); decode(incremental, p); decode(data, p); } void encode_payload(uint64_t) override { using ceph::encode; encode(version, payload); encode(prefix, payload); encode(incremental, payload); encode(data, payload); } };
1,233
24.183673
79
h
null
ceph-main/src/messages/MLock.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MLOCK_H #define CEPH_MLOCK_H #include "mds/locks.h" #include "mds/SimpleLock.h" #include "messages/MMDSOp.h" class MLock final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; int32_t action = 0; // action type mds_rank_t asker = 0; // who is initiating this request metareqid_t reqid; // for remote lock requests __u16 lock_type = 0; // lock object type MDSCacheObjectInfo object_info; ceph::buffer::list lockdata; // and possibly some data public: ceph::buffer::list& get_data() { return lockdata; } const ceph::buffer::list& get_data() const { return lockdata; } int get_asker() const { return asker; } int get_action() const { return action; } metareqid_t get_reqid() const { return reqid; } int get_lock_type() const { return lock_type; } const MDSCacheObjectInfo &get_object_info() const { return object_info; } MDSCacheObjectInfo &get_object_info() { return object_info; } protected: MLock() : MMDSOp{MSG_MDS_LOCK, HEAD_VERSION, COMPAT_VERSION} {} MLock(int ac, mds_rank_t as) : MMDSOp{MSG_MDS_LOCK, HEAD_VERSION, COMPAT_VERSION}, action(ac), asker(as), lock_type(0) { } MLock(SimpleLock *lock, int ac, mds_rank_t as) : MMDSOp{MSG_MDS_LOCK, HEAD_VERSION, COMPAT_VERSION}, action(ac), asker(as), lock_type(lock->get_type()) { lock->get_parent()->set_object_info(object_info); } MLock(SimpleLock *lock, int ac, mds_rank_t as, ceph::buffer::list& bl) : MMDSOp{MSG_MDS_LOCK, HEAD_VERSION, COMPAT_VERSION}, action(ac), asker(as), lock_type(lock->get_type()) { lock->get_parent()->set_object_info(object_info); lockdata = std::move(bl); } ~MLock() final {} public: std::string_view get_type_name() const override { return "ILock"; } void print(std::ostream& out) const override { out << "lock(a=" << SimpleLock::get_lock_action_name(action) << " " << SimpleLock::get_lock_type_name(lock_type) << " " << object_info << ")"; } void set_reqid(metareqid_t ri) { reqid = ri; } void set_data(const ceph::buffer::list& lockdata) { this->lockdata = lockdata; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(asker, p); decode(action, p); decode(reqid, p); decode(lock_type, p); decode(object_info, p); decode(lockdata, p); } void encode_payload(uint64_t features) override { using ceph::encode; encode(asker, payload); encode(action, payload); encode(reqid, payload); encode(lock_type, payload); encode(object_info, payload); encode(lockdata, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
3,334
29.59633
75
h
null
ceph-main/src/messages/MLog.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MLOG_H #define CEPH_MLOG_H #include "common/LogEntry.h" #include "messages/PaxosServiceMessage.h" #include <deque> class MLog final : public PaxosServiceMessage { public: uuid_d fsid; std::deque<LogEntry> entries; MLog() : PaxosServiceMessage{MSG_LOG, 0} {} MLog(const uuid_d& f, std::deque<LogEntry>&& e) : PaxosServiceMessage{MSG_LOG, 0}, fsid(f), entries{std::move(e)} { } MLog(const uuid_d& f) : PaxosServiceMessage(MSG_LOG, 0), fsid(f) { } private: ~MLog() final {} public: std::string_view get_type_name() const override { return "log"; } void print(std::ostream& out) const override { out << "log("; if (entries.size()) out << entries.size() << " entries from seq " << entries.front().seq << " at " << entries.front().stamp; out << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(fsid, payload); encode(entries, payload, features); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(fsid, p); decode(entries, p); } }; #endif
1,575
24.836066
74
h
null
ceph-main/src/messages/MLogAck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MLOGACK_H #define CEPH_MLOGACK_H #include <iostream> #include <string> #include <string_view> #include "include/uuid.h" #include "msg/Message.h" class MLogAck final : public Message { public: uuid_d fsid; version_t last = 0; std::string channel; MLogAck() : Message{MSG_LOGACK} {} MLogAck(uuid_d& f, version_t l) : Message{MSG_LOGACK}, fsid(f), last(l) {} private: ~MLogAck() final {} public: std::string_view get_type_name() const override { return "log_ack"; } void print(std::ostream& out) const override { out << "log(last " << last << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(fsid, payload); encode(last, payload); encode(channel, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(fsid, p); decode(last, p); if (!p.end()) decode(channel, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); }; #endif
1,489
22.650794
76
h
null
ceph-main/src/messages/MMDSBeacon.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MMDSBEACON_H #define CEPH_MMDSBEACON_H #include <string_view> #include "msg/Message.h" #include "messages/PaxosServiceMessage.h" #include "include/types.h" #include "mds/MDSMap.h" /** * Unique ID for each type of metric we can send to the mon, so that if the mon * knows about the IDs then it can implement special behaviour for certain * messages. */ enum mds_metric_t { MDS_HEALTH_NULL = 0, MDS_HEALTH_TRIM, MDS_HEALTH_CLIENT_RECALL, MDS_HEALTH_CLIENT_LATE_RELEASE, MDS_HEALTH_CLIENT_RECALL_MANY, MDS_HEALTH_CLIENT_LATE_RELEASE_MANY, MDS_HEALTH_CLIENT_OLDEST_TID, MDS_HEALTH_CLIENT_OLDEST_TID_MANY, MDS_HEALTH_DAMAGE, MDS_HEALTH_READ_ONLY, MDS_HEALTH_SLOW_REQUEST, MDS_HEALTH_CACHE_OVERSIZED, MDS_HEALTH_SLOW_METADATA_IO, MDS_HEALTH_CLIENTS_LAGGY, MDS_HEALTH_DUMMY, // not a real health warning, for testing }; inline const char *mds_metric_name(mds_metric_t m) { switch (m) { case MDS_HEALTH_TRIM: return "MDS_TRIM"; case MDS_HEALTH_CLIENT_RECALL: return "MDS_CLIENT_RECALL"; case MDS_HEALTH_CLIENT_LATE_RELEASE: return "MDS_CLIENT_LATE_RELEASE"; case MDS_HEALTH_CLIENT_RECALL_MANY: return "MDS_CLIENT_RECALL_MANY"; case MDS_HEALTH_CLIENT_LATE_RELEASE_MANY: return "MDS_CLIENT_LATE_RELEASE_MANY"; case MDS_HEALTH_CLIENT_OLDEST_TID: return "MDS_CLIENT_OLDEST_TID"; case MDS_HEALTH_CLIENT_OLDEST_TID_MANY: return "MDS_CLIENT_OLDEST_TID_MANY"; case MDS_HEALTH_DAMAGE: return "MDS_DAMAGE"; case MDS_HEALTH_READ_ONLY: return "MDS_READ_ONLY"; case MDS_HEALTH_SLOW_REQUEST: return "MDS_SLOW_REQUEST"; case MDS_HEALTH_CACHE_OVERSIZED: return "MDS_CACHE_OVERSIZED"; case MDS_HEALTH_SLOW_METADATA_IO: return "MDS_SLOW_METADATA_IO"; case MDS_HEALTH_CLIENTS_LAGGY: return "MDS_CLIENTS_LAGGY"; case MDS_HEALTH_DUMMY: return "MDS_DUMMY"; default: return "???"; } } inline const char *mds_metric_summary(mds_metric_t m) { switch (m) { case MDS_HEALTH_TRIM: return "%num% MDSs behind on trimming"; case MDS_HEALTH_CLIENT_RECALL: return "%num% clients failing to respond to cache pressure"; case MDS_HEALTH_CLIENT_LATE_RELEASE: return "%num% clients failing to respond to capability release"; case MDS_HEALTH_CLIENT_RECALL_MANY: return "%num% MDSs have many clients failing to respond to cache pressure"; case MDS_HEALTH_CLIENT_LATE_RELEASE_MANY: return "%num% MDSs have many clients failing to respond to capability " "release"; case MDS_HEALTH_CLIENT_OLDEST_TID: return "%num% clients failing to advance oldest client/flush tid"; case MDS_HEALTH_CLIENT_OLDEST_TID_MANY: return "%num% MDSs have clients failing to advance oldest client/flush tid"; case MDS_HEALTH_DAMAGE: return "%num% MDSs report damaged metadata"; case MDS_HEALTH_READ_ONLY: return "%num% MDSs are read only"; case MDS_HEALTH_SLOW_REQUEST: return "%num% MDSs report slow requests"; case MDS_HEALTH_CACHE_OVERSIZED: return "%num% MDSs report oversized cache"; case MDS_HEALTH_SLOW_METADATA_IO: return "%num% MDSs report slow metadata IOs"; case MDS_HEALTH_CLIENTS_LAGGY: return "%num% client(s) laggy due to laggy OSDs"; default: return "???"; } } /** * This structure is designed to allow some flexibility in how we emit health * complaints, such that: * - The mon doesn't have to have foreknowledge of all possible metrics: we can * implement new messages in the MDS and have the mon pass them through to the user * (enables us to do complex checks inside the MDS, and allows mon to be older version * than MDS) * - The mon has enough information to perform reductions on some types of metric, for * example complaints about the same client from multiple MDSs where we might want * to reduce three "client X is stale on MDS y" metrics into one "client X is stale * on 3 MDSs" message. */ struct MDSHealthMetric { mds_metric_t type; health_status_t sev; std::string message; std::map<std::string, std::string> metadata; void encode(ceph::buffer::list& bl) const { ENCODE_START(1, 1, bl); ceph_assert(type != MDS_HEALTH_NULL); encode((uint16_t)type, bl); encode((uint8_t)sev, bl); encode(message, bl); encode(metadata, bl); ENCODE_FINISH(bl); } void decode(ceph::buffer::list::const_iterator& bl) { DECODE_START(1, bl); uint16_t raw_type; decode(raw_type, bl); type = (mds_metric_t)raw_type; ceph_assert(type != MDS_HEALTH_NULL); uint8_t raw_sev; decode(raw_sev, bl); sev = (health_status_t)raw_sev; decode(message, bl); decode(metadata, bl); DECODE_FINISH(bl); } bool operator==(MDSHealthMetric const &other) const { return (type == other.type && sev == other.sev && message == other.message); } MDSHealthMetric() : type(MDS_HEALTH_NULL), sev(HEALTH_OK) {} MDSHealthMetric(mds_metric_t type_, health_status_t sev_, std::string_view message_) : type(type_), sev(sev_), message(message_) {} }; WRITE_CLASS_ENCODER(MDSHealthMetric) /** * Health metrics send by the MDS to the mon, so that the mon can generate * user friendly warnings about undesirable states. */ struct MDSHealth { std::vector<MDSHealthMetric> metrics; void encode(ceph::buffer::list& bl) const { ENCODE_START(1, 1, bl); encode(metrics, bl); ENCODE_FINISH(bl); } void decode(ceph::buffer::list::const_iterator& bl) { DECODE_START(1, bl); decode(metrics, bl); DECODE_FINISH(bl); } bool operator==(MDSHealth const &other) const { return metrics == other.metrics; } }; WRITE_CLASS_ENCODER(MDSHealth) class MMDSBeacon final : public PaxosServiceMessage { private: static constexpr int HEAD_VERSION = 8; static constexpr int COMPAT_VERSION = 6; uuid_d fsid; mds_gid_t global_id = MDS_GID_NONE; std::string name; MDSMap::DaemonState state = MDSMap::STATE_NULL; version_t seq = 0; CompatSet compat; MDSHealth health; std::map<std::string, std::string> sys_info; uint64_t mds_features = 0; std::string fs; protected: MMDSBeacon() : PaxosServiceMessage(MSG_MDS_BEACON, 0, HEAD_VERSION, COMPAT_VERSION) { set_priority(CEPH_MSG_PRIO_HIGH); } MMDSBeacon(const uuid_d &f, mds_gid_t g, const std::string& n, epoch_t les, MDSMap::DaemonState st, version_t se, uint64_t feat) : PaxosServiceMessage(MSG_MDS_BEACON, les, HEAD_VERSION, COMPAT_VERSION), fsid(f), global_id(g), name(n), state(st), seq(se), mds_features(feat) { set_priority(CEPH_MSG_PRIO_HIGH); } ~MMDSBeacon() final {} public: const uuid_d& get_fsid() const { return fsid; } mds_gid_t get_global_id() const { return global_id; } const std::string& get_name() const { return name; } epoch_t get_last_epoch_seen() const { return version; } MDSMap::DaemonState get_state() const { return state; } version_t get_seq() const { return seq; } std::string_view get_type_name() const override { return "mdsbeacon"; } uint64_t get_mds_features() const { return mds_features; } CompatSet const& get_compat() const { return compat; } void set_compat(const CompatSet& c) { compat = c; } MDSHealth const& get_health() const { return health; } void set_health(const MDSHealth &h) { health = h; } const std::string& get_fs() const { return fs; } void set_fs(std::string_view s) { fs = s; } const std::map<std::string, std::string>& get_sys_info() const { return sys_info; } void set_sys_info(const std::map<std::string, std::string>& i) { sys_info = i; } void print(std::ostream& out) const override { out << "mdsbeacon(" << global_id << "/" << name << " " << ceph_mds_state_name(state); if (fs.size()) { out << " fs=" << fs; } out << " seq=" << seq << " v" << version << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(fsid, payload); encode(global_id, payload); encode((__u32)state, payload); encode(seq, payload); encode(name, payload); encode(MDS_RANK_NONE, payload); encode(std::string(), payload); encode(compat, payload); encode(health, payload); if (state == MDSMap::STATE_BOOT) { encode(sys_info, payload); } encode(mds_features, payload); encode(FS_CLUSTER_ID_NONE, payload); encode(false, payload); encode(fs, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(fsid, p); decode(global_id, p); __u32 raw_state; decode(raw_state, p); state = (MDSMap::DaemonState)raw_state; decode(seq, p); decode(name, p); { mds_rank_t standby_for_rank; decode(standby_for_rank, p); } { std::string standby_for_name; decode(standby_for_name, p); } decode(compat, p); decode(health, p); if (state == MDSMap::STATE_BOOT) { decode(sys_info, p); } decode(mds_features, p); { fs_cluster_id_t standby_for_fscid; decode(standby_for_fscid, p); } if (header.version >= 7) { bool standby_replay; decode(standby_replay, p); } if (header.version < 7 && state == MDSMap::STATE_STANDBY_REPLAY) { // Old MDS daemons request the state, instead of explicitly // advertising that they are configured as a replay daemon. state = MDSMap::STATE_STANDBY; } if (header.version >= 8) { decode(fs, p); } } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
10,079
29.453172
88
h
null
ceph-main/src/messages/MMDSCacheRejoin.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MMDSCACHEREJOIN_H #define CEPH_MMDSCACHEREJOIN_H #include <string_view> #include "include/types.h" #include "mds/CInode.h" #include "mds/CDir.h" #include "mds/mdstypes.h" #include "messages/MMDSOp.h" // sent from replica to auth class MMDSCacheRejoin final : public MMDSOp { public: static constexpr int OP_WEAK = 1; // replica -> auth, i exist, + maybe open files. static constexpr int OP_STRONG = 2; // replica -> auth, i exist, + open files and lock state. static constexpr int OP_ACK = 3; // auth -> replica, here is your lock state. static const char *get_opname(int op) { switch (op) { case OP_WEAK: return "weak"; case OP_STRONG: return "strong"; case OP_ACK: return "ack"; default: ceph_abort(); return 0; } } // -- types -- struct inode_strong { uint32_t nonce = 0; int32_t caps_wanted = 0; int32_t filelock = 0, nestlock = 0, dftlock = 0; inode_strong() {} inode_strong(int n, int cw, int dl, int nl, int dftl) : nonce(n), caps_wanted(cw), filelock(dl), nestlock(nl), dftlock(dftl) { } void encode(ceph::buffer::list &bl) const { using ceph::encode; encode(nonce, bl); encode(caps_wanted, bl); encode(filelock, bl); encode(nestlock, bl); encode(dftlock, bl); } void decode(ceph::buffer::list::const_iterator &bl) { using ceph::decode; decode(nonce, bl); decode(caps_wanted, bl); decode(filelock, bl); decode(nestlock, bl); decode(dftlock, bl); } }; WRITE_CLASS_ENCODER(inode_strong) struct dirfrag_strong { uint32_t nonce = 0; int8_t dir_rep = 0; dirfrag_strong() {} dirfrag_strong(int n, int dr) : nonce(n), dir_rep(dr) {} void encode(ceph::buffer::list &bl) const { using ceph::encode; encode(nonce, bl); encode(dir_rep, bl); } void decode(ceph::buffer::list::const_iterator &bl) { using ceph::decode; decode(nonce, bl); decode(dir_rep, bl); } }; WRITE_CLASS_ENCODER(dirfrag_strong) struct dn_strong { snapid_t first; std::string alternate_name; inodeno_t ino = 0; inodeno_t remote_ino = 0; unsigned char remote_d_type = 0; uint32_t nonce = 0; int32_t lock = 0; dn_strong() = default; dn_strong(snapid_t f, std::string_view altn, inodeno_t pi, inodeno_t ri, unsigned char rdt, int n, int l) : first(f), alternate_name(altn), ino(pi), remote_ino(ri), remote_d_type(rdt), nonce(n), lock(l) {} bool is_primary() const { return ino > 0; } bool is_remote() const { return remote_ino > 0; } bool is_null() const { return ino == 0 && remote_ino == 0; } void encode(ceph::buffer::list &bl) const { using ceph::encode; encode(first, bl); encode(ino, bl); encode(remote_ino, bl); encode(remote_d_type, bl); encode(nonce, bl); encode(lock, bl); encode(alternate_name, bl); } void decode(ceph::buffer::list::const_iterator &bl) { using ceph::decode; decode(first, bl); decode(ino, bl); decode(remote_ino, bl); decode(remote_d_type, bl); decode(nonce, bl); decode(lock, bl); decode(alternate_name, bl); } }; WRITE_CLASS_ENCODER(dn_strong) struct dn_weak { snapid_t first; inodeno_t ino = 0; dn_weak() = default; dn_weak(snapid_t f, inodeno_t pi) : first(f), ino(pi) {} void encode(ceph::buffer::list &bl) const { using ceph::encode; encode(first, bl); encode(ino, bl); } void decode(ceph::buffer::list::const_iterator &bl) { using ceph::decode; decode(first, bl); decode(ino, bl); } }; WRITE_CLASS_ENCODER(dn_weak) struct lock_bls { ceph::buffer::list file, nest, dft; void encode(ceph::buffer::list& bl) const { using ceph::encode; encode(file, bl); encode(nest, bl); encode(dft, bl); } void decode(ceph::buffer::list::const_iterator& bl) { using ceph::decode; decode(file, bl); decode(nest, bl); decode(dft, bl); } }; WRITE_CLASS_ENCODER(lock_bls) // authpins, xlocks struct peer_reqid { metareqid_t reqid; __u32 attempt; peer_reqid() : attempt(0) {} peer_reqid(const metareqid_t& r, __u32 a) : reqid(r), attempt(a) {} void encode(ceph::buffer::list& bl) const { using ceph::encode; encode(reqid, bl); encode(attempt, bl); } void decode(ceph::buffer::list::const_iterator& bl) { using ceph::decode; decode(reqid, bl); decode(attempt, bl); } }; std::string_view get_type_name() const override { return "cache_rejoin"; } void print(std::ostream& out) const override { out << "cache_rejoin " << get_opname(op); } // -- builders -- // inodes void add_weak_inode(vinodeno_t i) { weak_inodes.insert(i); } void add_strong_inode(vinodeno_t i, int n, int cw, int dl, int nl, int dftl) { strong_inodes[i] = inode_strong(n, cw, dl, nl, dftl); } void add_inode_locks(CInode *in, __u32 nonce, ceph::buffer::list& bl) { using ceph::encode; encode(in->ino(), inode_locks); encode(in->last, inode_locks); encode(nonce, inode_locks); encode(bl, inode_locks); } void add_inode_base(CInode *in, uint64_t features) { using ceph::encode; encode(in->ino(), inode_base); encode(in->last, inode_base); ceph::buffer::list bl; in->_encode_base(bl, features); encode(bl, inode_base); } void add_inode_authpin(vinodeno_t ino, const metareqid_t& ri, __u32 attempt) { authpinned_inodes[ino].push_back(peer_reqid(ri, attempt)); } void add_inode_frozen_authpin(vinodeno_t ino, const metareqid_t& ri, __u32 attempt) { frozen_authpin_inodes[ino] = peer_reqid(ri, attempt); } void add_inode_xlock(vinodeno_t ino, int lt, const metareqid_t& ri, __u32 attempt) { xlocked_inodes[ino][lt] = peer_reqid(ri, attempt); } void add_inode_wrlock(vinodeno_t ino, int lt, const metareqid_t& ri, __u32 attempt) { wrlocked_inodes[ino][lt].push_back(peer_reqid(ri, attempt)); } void add_scatterlock_state(CInode *in) { if (inode_scatterlocks.count(in->ino())) return; // already added this one in->encode_lock_state(CEPH_LOCK_IFILE, inode_scatterlocks[in->ino()].file); in->encode_lock_state(CEPH_LOCK_INEST, inode_scatterlocks[in->ino()].nest); in->encode_lock_state(CEPH_LOCK_IDFT, inode_scatterlocks[in->ino()].dft); } // dirfrags void add_strong_dirfrag(dirfrag_t df, int n, int dr) { strong_dirfrags[df] = dirfrag_strong(n, dr); } void add_dirfrag_base(CDir *dir) { ceph::buffer::list& bl = dirfrag_bases[dir->dirfrag()]; dir->_encode_base(bl); } // dentries void add_weak_dirfrag(dirfrag_t df) { weak_dirfrags.insert(df); } 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, 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, std::string_view dname, std::string_view altn, snapid_t first, snapid_t last, inodeno_t pi, inodeno_t ri, unsigned char rdt, int n, int ls) { auto& m = strong_dentries[df]; m.insert_or_assign(string_snap_t(dname, last), dn_strong(first, altn, pi, ri, rdt, n, ls)); } 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(peer_reqid(ri, attempt)); } 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)] = peer_reqid(ri, attempt); } // -- encoding -- void encode_payload(uint64_t features) override { using ceph::encode; encode(op, payload); encode(strong_inodes, payload); encode(inode_base, payload); encode(inode_locks, payload); encode(inode_scatterlocks, payload); encode(authpinned_inodes, payload); encode(frozen_authpin_inodes, payload); encode(xlocked_inodes, payload); encode(wrlocked_inodes, payload); encode(cap_exports, payload); encode(client_map, payload, features); encode(imported_caps, payload); encode(strong_dirfrags, payload); encode(dirfrag_bases, payload); encode(weak, payload); encode(weak_dirfrags, payload); encode(weak_inodes, payload); encode(strong_dentries, payload); encode(authpinned_dentries, payload); encode(xlocked_dentries, payload); encode(client_metadata_map, payload); } void decode_payload() override { auto p = payload.cbegin(); using ceph::decode; decode(op, p); decode(strong_inodes, p); decode(inode_base, p); decode(inode_locks, p); decode(inode_scatterlocks, p); decode(authpinned_inodes, p); decode(frozen_authpin_inodes, p); decode(xlocked_inodes, p); decode(wrlocked_inodes, p); decode(cap_exports, p); decode(client_map, p); decode(imported_caps, p); decode(strong_dirfrags, p); decode(dirfrag_bases, p); decode(weak, p); decode(weak_dirfrags, p); decode(weak_inodes, p); decode(strong_dentries, p); decode(authpinned_dentries, p); decode(xlocked_dentries, p); if (header.version >= 2) decode(client_metadata_map, p); } // -- data -- int32_t op = 0; // weak std::map<inodeno_t, std::map<string_snap_t, dn_weak> > weak; std::set<dirfrag_t> weak_dirfrags; std::set<vinodeno_t> weak_inodes; std::map<inodeno_t, lock_bls> inode_scatterlocks; // strong std::map<dirfrag_t, dirfrag_strong> strong_dirfrags; std::map<dirfrag_t, std::map<string_snap_t, dn_strong> > strong_dentries; std::map<vinodeno_t, inode_strong> strong_inodes; // open std::map<inodeno_t,std::map<client_t, cap_reconnect_t> > cap_exports; std::map<client_t, entity_inst_t> client_map; std::map<client_t,client_metadata_t> client_metadata_map; ceph::buffer::list imported_caps; // full ceph::buffer::list inode_base; ceph::buffer::list inode_locks; std::map<dirfrag_t, ceph::buffer::list> dirfrag_bases; std::map<vinodeno_t, std::list<peer_reqid> > authpinned_inodes; std::map<vinodeno_t, peer_reqid> frozen_authpin_inodes; std::map<vinodeno_t, std::map<__s32, peer_reqid> > xlocked_inodes; std::map<vinodeno_t, std::map<__s32, std::list<peer_reqid> > > wrlocked_inodes; std::map<dirfrag_t, std::map<string_snap_t, std::list<peer_reqid> > > authpinned_dentries; std::map<dirfrag_t, std::map<string_snap_t, peer_reqid> > xlocked_dentries; private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; MMDSCacheRejoin(int o) : MMDSCacheRejoin() { op = o; } MMDSCacheRejoin() : MMDSOp{MSG_MDS_CACHEREJOIN, HEAD_VERSION, COMPAT_VERSION} {} ~MMDSCacheRejoin() final {} }; WRITE_CLASS_ENCODER(MMDSCacheRejoin::inode_strong) WRITE_CLASS_ENCODER(MMDSCacheRejoin::dirfrag_strong) WRITE_CLASS_ENCODER(MMDSCacheRejoin::dn_strong) WRITE_CLASS_ENCODER(MMDSCacheRejoin::dn_weak) WRITE_CLASS_ENCODER(MMDSCacheRejoin::lock_bls) WRITE_CLASS_ENCODER(MMDSCacheRejoin::peer_reqid) inline std::ostream& operator<<(std::ostream& out, const MMDSCacheRejoin::peer_reqid& r) { return out << r.reqid << '.' << r.attempt; } #endif
12,132
31.880759
180
h
null
ceph-main/src/messages/MMDSFindIno.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2011 New Dream Network * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDSFINDINO_H #define CEPH_MDSFINDINO_H #include "include/filepath.h" #include "messages/MMDSOp.h" class MMDSFindIno final : public MMDSOp { static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: ceph_tid_t tid {0}; inodeno_t ino; protected: MMDSFindIno() : MMDSOp{MSG_MDS_FINDINO, HEAD_VERSION, COMPAT_VERSION} {} MMDSFindIno(ceph_tid_t t, inodeno_t i) : MMDSOp{MSG_MDS_FINDINO, HEAD_VERSION, COMPAT_VERSION}, tid(t), ino(i) {} ~MMDSFindIno() final {} public: std::string_view get_type_name() const override { return "findino"; } void print(std::ostream &out) const override { out << "findino(" << tid << " " << ino << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(tid, payload); encode(ino, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(tid, p); decode(ino, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,601
26.62069
115
h
null
ceph-main/src/messages/MMDSFindInoReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2011 New Dream Network * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDSFINDINOREPLY_H #define CEPH_MDSFINDINOREPLY_H #include "include/filepath.h" #include "messages/MMDSOp.h" class MMDSFindInoReply final : public MMDSOp { static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: ceph_tid_t tid = 0; filepath path; protected: MMDSFindInoReply() : MMDSOp{MSG_MDS_FINDINOREPLY, HEAD_VERSION, COMPAT_VERSION} {} MMDSFindInoReply(ceph_tid_t t) : MMDSOp{MSG_MDS_FINDINOREPLY, HEAD_VERSION, COMPAT_VERSION}, tid(t) {} ~MMDSFindInoReply() final {} public: std::string_view get_type_name() const override { return "findinoreply"; } void print(std::ostream &out) const override { out << "findinoreply(" << tid << " " << path << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(tid, payload); encode(path, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(tid, p); decode(path, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,633
27.172414
104
h
null
ceph-main/src/messages/MMDSFragmentNotify.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MMDSFRAGMENTNOTIFY_H #define CEPH_MMDSFRAGMENTNOTIFY_H #include "messages/MMDSOp.h" class MMDSFragmentNotify final : public MMDSOp { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; dirfrag_t base_dirfrag; int8_t bits = 0; bool ack_wanted = false; public: inodeno_t get_ino() const { return base_dirfrag.ino; } frag_t get_basefrag() const { return base_dirfrag.frag; } dirfrag_t get_base_dirfrag() const { return base_dirfrag; } int get_bits() const { return bits; } bool is_ack_wanted() const { return ack_wanted; } void mark_ack_wanted() { ack_wanted = true; } ceph::buffer::list basebl; protected: MMDSFragmentNotify() : MMDSOp{MSG_MDS_FRAGMENTNOTIFY, HEAD_VERSION, COMPAT_VERSION} {} MMDSFragmentNotify(dirfrag_t df, int b, uint64_t tid) : MMDSOp{MSG_MDS_FRAGMENTNOTIFY, HEAD_VERSION, COMPAT_VERSION}, base_dirfrag(df), bits(b) { set_tid(tid); } ~MMDSFragmentNotify() final {} public: std::string_view get_type_name() const override { return "fragment_notify"; } void print(std::ostream& o) const override { o << "fragment_notify(" << base_dirfrag << " " << (int)bits << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(base_dirfrag, payload); encode(bits, payload); encode(basebl, payload); encode(ack_wanted, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(base_dirfrag, p); decode(bits, p); decode(basebl, p); if (header.version >= 2) decode(ack_wanted, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,285
27.936709
79
h
null
ceph-main/src/messages/MMDSFragmentNotifyAck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MMDSFRAGMENTNOTIFYAck_H #define CEPH_MMDSFRAGMENTNOTIFYAck_H #include "messages/MMDSOp.h" class MMDSFragmentNotifyAck final : public MMDSOp { private: dirfrag_t base_dirfrag; int8_t bits = 0; public: dirfrag_t get_base_dirfrag() const { return base_dirfrag; } int get_bits() const { return bits; } ceph::buffer::list basebl; protected: MMDSFragmentNotifyAck() : MMDSOp{MSG_MDS_FRAGMENTNOTIFYACK} {} MMDSFragmentNotifyAck(dirfrag_t df, int b, uint64_t tid) : MMDSOp{MSG_MDS_FRAGMENTNOTIFYACK}, base_dirfrag(df), bits(b) { set_tid(tid); } ~MMDSFragmentNotifyAck() final {} public: std::string_view get_type_name() const override { return "fragment_notify_ack"; } void print(std::ostream& o) const override { o << "fragment_notify_ack(" << base_dirfrag << " " << (int)bits << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(base_dirfrag, payload); encode(bits, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(base_dirfrag, p); decode(bits, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,778
26.369231
83
h
null
ceph-main/src/messages/MMDSLoadTargets.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2009 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MMDSLoadTargets_H #define CEPH_MMDSLoadTargets_H #include "msg/Message.h" #include "mds/mdstypes.h" #include "messages/PaxosServiceMessage.h" #include "include/types.h" #include <map> using std::map; class MMDSLoadTargets final : public PaxosServiceMessage { public: mds_gid_t global_id; std::set<mds_rank_t> targets; protected: MMDSLoadTargets() : PaxosServiceMessage(MSG_MDS_OFFLOAD_TARGETS, 0) {} MMDSLoadTargets(mds_gid_t g, std::set<mds_rank_t>& mds_targets) : PaxosServiceMessage(MSG_MDS_OFFLOAD_TARGETS, 0), global_id(g), targets(mds_targets) {} ~MMDSLoadTargets() final {} public: std::string_view get_type_name() const override { return "mds_load_targets"; } void print(std::ostream& o) const override { o << "mds_load_targets(" << global_id << " " << targets << ")"; } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); paxos_decode(p); decode(global_id, p); decode(targets, p); } void encode_payload(uint64_t features) override { using ceph::encode; paxos_encode(); encode(global_id, payload); encode(targets, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,800
26.287879
80
h
null
ceph-main/src/messages/MMDSMap.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MMDSMAP_H #define CEPH_MMDSMAP_H #include "msg/Message.h" #include "mds/MDSMap.h" #include "include/ceph_features.h" class MMDSMap final : public SafeMessage { private: static constexpr int HEAD_VERSION = 2; static constexpr int COMPAT_VERSION = 1; public: uuid_d fsid; epoch_t epoch = 0; ceph::buffer::list encoded; // don't really need map_fs_name. it was accidentally added in 51af2346fdf // set it to empty string. std::string map_fs_name = std::string(); version_t get_epoch() const { return epoch; } const ceph::buffer::list& get_encoded() const { return encoded; } protected: MMDSMap() : SafeMessage{CEPH_MSG_MDS_MAP, HEAD_VERSION, COMPAT_VERSION} {} MMDSMap(const uuid_d &f, const MDSMap &mm) : SafeMessage{CEPH_MSG_MDS_MAP, HEAD_VERSION, COMPAT_VERSION}, fsid(f) { epoch = mm.get_epoch(); mm.encode(encoded, -1); // we will reencode with fewer features as necessary } ~MMDSMap() final {} public: std::string_view get_type_name() const override { return "mdsmap"; } void print(std::ostream& out) const override { out << "mdsmap(e " << epoch << ")"; } // marshalling void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(fsid, p); decode(epoch, p); decode(encoded, p); if (header.version >= 2) { decode(map_fs_name, p); } } void encode_payload(uint64_t features) override { using ceph::encode; encode(fsid, payload); encode(epoch, payload); if ((features & CEPH_FEATURE_PGID64) == 0 || (features & CEPH_FEATURE_MDSENC) == 0 || (features & CEPH_FEATURE_MSG_ADDR2) == 0 || !HAVE_FEATURE(features, SERVER_NAUTILUS)) { // reencode for old clients. MDSMap m; m.decode(encoded); encoded.clear(); m.encode(encoded, features); } encode(encoded, payload); encode(map_fs_name, payload); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
2,557
26.505376
81
h
null
ceph-main/src/messages/MMDSMetrics.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MDS_METRICS_H #define CEPH_MDS_METRICS_H #include "messages/MMDSOp.h" #include "mds/MDSPerfMetricTypes.h" class MMDSMetrics final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: // metrics messsage (client -> metrics map, rank, etc..) metrics_message_t metrics_message; protected: MMDSMetrics() : MMDSOp(MSG_MDS_METRICS, HEAD_VERSION, COMPAT_VERSION) { } MMDSMetrics(metrics_message_t metrics_message) : MMDSOp(MSG_MDS_METRICS, HEAD_VERSION, COMPAT_VERSION), metrics_message(metrics_message) { } ~MMDSMetrics() final {} public: std::string_view get_type_name() const override { return "mds_metrics"; } void print(std::ostream &out) const override { out << "mds_metrics from rank=" << metrics_message.rank << " carrying " << metrics_message.client_metrics_map.size() << " metric updates"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(metrics_message, payload, features); } void decode_payload() override { using ceph::decode; auto iter = payload.cbegin(); decode(metrics_message, iter); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif // CEPH_MDS_METRICS_H
1,533
26.392857
75
h
null
ceph-main/src/messages/MMDSOp.h
#pragma once #include "msg/Message.h" /* * MMDSOp is used to ensure that all incoming MDS-MDS * messages in MDSRankDispatcher are versioned. Therefore * all MDS-MDS messages must be of type MMDSOp. */ class MMDSOp : public SafeMessage { public: template<typename... Types> MMDSOp(Types&&... args) : SafeMessage(std::forward<Types>(args)...) {} };
361
21.625
57
h
null
ceph-main/src/messages/MMDSOpenIno.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2011 New Dream Network * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDSOPENINO_H #define CEPH_MDSOPENINO_H #include "messages/MMDSOp.h" class MMDSOpenIno final : public MMDSOp { static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: inodeno_t ino; std::vector<inode_backpointer_t> ancestors; protected: MMDSOpenIno() : MMDSOp{MSG_MDS_OPENINO, HEAD_VERSION, COMPAT_VERSION} {} MMDSOpenIno(ceph_tid_t t, inodeno_t i, std::vector<inode_backpointer_t>* pa) : MMDSOp{MSG_MDS_OPENINO, HEAD_VERSION, COMPAT_VERSION}, ino(i) { header.tid = t; if (pa) ancestors = *pa; } ~MMDSOpenIno() final {} public: std::string_view get_type_name() const override { return "openino"; } void print(std::ostream &out) const override { out << "openino(" << header.tid << " " << ino << " " << ancestors << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(ino, payload); encode(ancestors, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(ino, p); decode(ancestors, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,723
26.806452
80
h
null
ceph-main/src/messages/MMDSOpenInoReply.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2011 New Dream Network * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MDSOPENINOREPLY_H #define CEPH_MDSOPENINOREPLY_H #include "messages/MMDSOp.h" class MMDSOpenInoReply final : public MMDSOp { public: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; inodeno_t ino; std::vector<inode_backpointer_t> ancestors; mds_rank_t hint; int32_t error; protected: MMDSOpenInoReply() : MMDSOp{MSG_MDS_OPENINOREPLY, HEAD_VERSION, COMPAT_VERSION}, error(0) {} MMDSOpenInoReply(ceph_tid_t t, inodeno_t i, mds_rank_t h=MDS_RANK_NONE, int e=0) : MMDSOp{MSG_MDS_OPENINOREPLY, HEAD_VERSION, COMPAT_VERSION}, ino(i), hint(h), error(e) { header.tid = t; } public: std::string_view get_type_name() const override { return "openinoreply"; } void print(std::ostream &out) const override { out << "openinoreply(" << header.tid << " " << ino << " " << hint << " " << ancestors << ")"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(ino, payload); encode(ancestors, payload); encode(hint, payload); encode(error, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(ino, p); decode(ancestors, p); decode(hint, p); decode(error, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,886
27.164179
94
h
null
ceph-main/src/messages/MMDSPeerRequest.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MMDSPEERREQUEST_H #define CEPH_MMDSPEERREQUEST_H #include "mds/mdstypes.h" #include "messages/MMDSOp.h" class MMDSPeerRequest final : public MMDSOp { static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: static constexpr int OP_XLOCK = 1; static constexpr int OP_XLOCKACK = -1; static constexpr int OP_UNXLOCK = 2; static constexpr int OP_AUTHPIN = 3; static constexpr int OP_AUTHPINACK = -3; static constexpr int OP_LINKPREP = 4; static constexpr int OP_UNLINKPREP = 5; static constexpr int OP_LINKPREPACK = -4; static constexpr int OP_RENAMEPREP = 7; static constexpr int OP_RENAMEPREPACK = -7; static constexpr int OP_WRLOCK = 8; static constexpr int OP_WRLOCKACK = -8; static constexpr int OP_UNWRLOCK = 9; static constexpr int OP_RMDIRPREP = 10; static constexpr int OP_RMDIRPREPACK = -10; static constexpr int OP_DROPLOCKS = 11; static constexpr int OP_RENAMENOTIFY = 12; static constexpr int OP_RENAMENOTIFYACK = -12; static constexpr int OP_FINISH = 17; static constexpr int OP_COMMITTED = -18; static constexpr int OP_ABORT = 20; // used for recovery only //static constexpr int OP_COMMIT = 21; // used for recovery only static const char *get_opname(int o) { switch (o) { case OP_XLOCK: return "xlock"; case OP_XLOCKACK: return "xlock_ack"; case OP_UNXLOCK: return "unxlock"; case OP_AUTHPIN: return "authpin"; case OP_AUTHPINACK: return "authpin_ack"; case OP_LINKPREP: return "link_prep"; case OP_LINKPREPACK: return "link_prep_ack"; case OP_UNLINKPREP: return "unlink_prep"; case OP_RENAMEPREP: return "rename_prep"; case OP_RENAMEPREPACK: return "rename_prep_ack"; case OP_FINISH: return "finish"; // commit case OP_COMMITTED: return "committed"; case OP_WRLOCK: return "wrlock"; case OP_WRLOCKACK: return "wrlock_ack"; case OP_UNWRLOCK: return "unwrlock"; case OP_RMDIRPREP: return "rmdir_prep"; case OP_RMDIRPREPACK: return "rmdir_prep_ack"; case OP_DROPLOCKS: return "drop_locks"; case OP_RENAMENOTIFY: return "rename_notify"; case OP_RENAMENOTIFYACK: return "rename_notify_ack"; case OP_ABORT: return "abort"; //case OP_COMMIT: return "commit"; default: ceph_abort(); return 0; } } private: metareqid_t reqid; __u32 attempt; __s16 op; mutable __u16 flags; /* XXX HACK for mark_interrupted */ static constexpr unsigned FLAG_NONBLOCKING = 1<<0; static constexpr unsigned FLAG_WOULDBLOCK = 1<<1; static constexpr unsigned FLAG_NOTJOURNALED = 1<<2; static constexpr unsigned FLAG_EROFS = 1<<3; static constexpr unsigned FLAG_ABORT = 1<<4; static constexpr unsigned FLAG_INTERRUPTED = 1<<5; static constexpr unsigned FLAG_NOTIFYBLOCKING = 1<<6; static constexpr unsigned FLAG_REQBLOCKED = 1<<7; // for locking __u16 lock_type; // lock object type MDSCacheObjectInfo object_info; // for authpins std::vector<MDSCacheObjectInfo> authpins; public: // for rename prep filepath srcdnpath; filepath destdnpath; std::string alternate_name; std::set<mds_rank_t> witnesses; ceph::buffer::list inode_export; version_t inode_export_v; mds_rank_t srcdn_auth; utime_t op_stamp; mutable ceph::buffer::list straybl; // stray dir + dentry ceph::buffer::list srci_snapbl; ceph::buffer::list desti_snapbl; public: metareqid_t get_reqid() const { return reqid; } __u32 get_attempt() const { return attempt; } int get_op() const { return op; } bool is_reply() const { return op < 0; } int get_lock_type() const { return lock_type; } const MDSCacheObjectInfo &get_object_info() const { return object_info; } MDSCacheObjectInfo &get_object_info() { return object_info; } const MDSCacheObjectInfo &get_authpin_freeze() const { return object_info; } MDSCacheObjectInfo &get_authpin_freeze() { return object_info; } const std::vector<MDSCacheObjectInfo>& get_authpins() const { return authpins; } std::vector<MDSCacheObjectInfo>& get_authpins() { return authpins; } void mark_nonblocking() { flags |= FLAG_NONBLOCKING; } bool is_nonblocking() const { return (flags & FLAG_NONBLOCKING); } void mark_error_wouldblock() { flags |= FLAG_WOULDBLOCK; } bool is_error_wouldblock() const { return (flags & FLAG_WOULDBLOCK); } void mark_not_journaled() { flags |= FLAG_NOTJOURNALED; } bool is_not_journaled() const { return (flags & FLAG_NOTJOURNALED); } void mark_error_rofs() { flags |= FLAG_EROFS; } bool is_error_rofs() const { return (flags & FLAG_EROFS); } bool is_abort() const { return (flags & FLAG_ABORT); } void mark_abort() { flags |= FLAG_ABORT; } bool is_interrupted() const { return (flags & FLAG_INTERRUPTED); } void mark_interrupted() const { flags |= FLAG_INTERRUPTED; } bool should_notify_blocking() const { return (flags & FLAG_NOTIFYBLOCKING); } void mark_notify_blocking() { flags |= FLAG_NOTIFYBLOCKING; } void clear_notify_blocking() const { flags &= ~FLAG_NOTIFYBLOCKING; } bool is_req_blocked() const { return (flags & FLAG_REQBLOCKED); } void mark_req_blocked() { flags |= FLAG_REQBLOCKED; } void set_lock_type(int t) { lock_type = t; } const ceph::buffer::list& get_lock_data() const { return inode_export; } ceph::buffer::list& get_lock_data() { return inode_export; } protected: MMDSPeerRequest() : MMDSOp{MSG_MDS_PEER_REQUEST, HEAD_VERSION, COMPAT_VERSION} { } MMDSPeerRequest(metareqid_t ri, __u32 att, int o) : MMDSOp{MSG_MDS_PEER_REQUEST, HEAD_VERSION, COMPAT_VERSION}, reqid(ri), attempt(att), op(o), flags(0), lock_type(0), inode_export_v(0), srcdn_auth(MDS_RANK_NONE) { } ~MMDSPeerRequest() final {} public: void encode_payload(uint64_t features) override { using ceph::encode; encode(reqid, payload); encode(attempt, payload); encode(op, payload); encode(flags, payload); encode(lock_type, payload); encode(object_info, payload); encode(authpins, payload); encode(srcdnpath, payload); encode(destdnpath, payload); encode(witnesses, payload); encode(op_stamp, payload); encode(inode_export, payload); encode(inode_export_v, payload); encode(srcdn_auth, payload); encode(straybl, payload); encode(srci_snapbl, payload); encode(desti_snapbl, payload); encode(alternate_name, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(reqid, p); decode(attempt, p); decode(op, p); decode(flags, p); decode(lock_type, p); decode(object_info, p); decode(authpins, p); decode(srcdnpath, p); decode(destdnpath, p); decode(witnesses, p); decode(op_stamp, p); decode(inode_export, p); decode(inode_export_v, p); decode(srcdn_auth, p); decode(straybl, p); decode(srci_snapbl, p); decode(desti_snapbl, p); decode(alternate_name, p); } std::string_view get_type_name() const override { return "peer_request"; } void print(std::ostream& out) const override { out << "peer_request(" << reqid << "." << attempt << " " << get_opname(op) << ")"; } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
7,821
32.144068
84
h
null
ceph-main/src/messages/MMDSPing.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab #ifndef CEPH_MESSAGES_MMDSPING_H #define CEPH_MESSAGES_MMDSPING_H #include "include/types.h" #include "messages/MMDSOp.h" class MMDSPing final : public MMDSOp { private: static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: version_t seq; protected: MMDSPing() : MMDSOp(MSG_MDS_PING, HEAD_VERSION, COMPAT_VERSION) { } MMDSPing(version_t seq) : MMDSOp(MSG_MDS_PING, HEAD_VERSION, COMPAT_VERSION), seq(seq) { } ~MMDSPing() final {} public: std::string_view get_type_name() const override { return "mdsping"; } void print(std::ostream &out) const override { out << "mdsping"; } void encode_payload(uint64_t features) override { using ceph::encode; encode(seq, payload); } void decode_payload() override { using ceph::decode; auto iter = payload.cbegin(); decode(seq, iter); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif // CEPH_MESSAGES_MMDSPING_H
1,228
22.188679
70
h
null
ceph-main/src/messages/MMDSResolve.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MMDSRESOLVE_H #define CEPH_MMDSRESOLVE_H #include "include/types.h" #include "mds/Capability.h" #include "messages/MMDSOp.h" class MMDSResolve final : public MMDSOp { static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: std::map<dirfrag_t, std::vector<dirfrag_t>> subtrees; std::map<dirfrag_t, std::vector<dirfrag_t>> ambiguous_imports; class peer_inode_cap { public: inodeno_t ino; std::map<client_t,Capability::Export> cap_exports; peer_inode_cap() {} peer_inode_cap(inodeno_t a, std::map<client_t, Capability::Export> b) : ino(a), cap_exports(b) {} void encode(ceph::buffer::list &bl) const { ENCODE_START(1, 1, bl); encode(ino, bl); encode(cap_exports, bl); ENCODE_FINISH(bl); } void decode(ceph::buffer::list::const_iterator &blp) { DECODE_START(1, blp); decode(ino, blp); decode(cap_exports, blp); DECODE_FINISH(blp); } }; WRITE_CLASS_ENCODER(peer_inode_cap) struct peer_request { ceph::buffer::list inode_caps; bool committing; peer_request() : committing(false) {} void encode(ceph::buffer::list &bl) const { ENCODE_START(1, 1, bl); encode(inode_caps, bl); encode(committing, bl); ENCODE_FINISH(bl); } void decode(ceph::buffer::list::const_iterator &blp) { DECODE_START(1, blp); decode(inode_caps, blp); decode(committing, blp); DECODE_FINISH(blp); } }; std::map<metareqid_t, peer_request> peer_requests; // table client information struct table_client { __u8 type; std::set<version_t> pending_commits; table_client() : type(0) {} table_client(int _type, const std::set<version_t>& commits) : type(_type), pending_commits(commits) {} void encode(ceph::buffer::list& bl) const { using ceph::encode; encode(type, bl); encode(pending_commits, bl); } void decode(ceph::buffer::list::const_iterator& bl) { using ceph::decode; decode(type, bl); decode(pending_commits, bl); } }; std::list<table_client> table_clients; protected: MMDSResolve() : MMDSOp{MSG_MDS_RESOLVE, HEAD_VERSION, COMPAT_VERSION} {} ~MMDSResolve() final {} public: std::string_view get_type_name() const override { return "mds_resolve"; } void print(std::ostream& out) const override { out << "mds_resolve(" << subtrees.size() << "+" << ambiguous_imports.size() << " subtrees +" << peer_requests.size() << " peer requests)"; } void add_subtree(dirfrag_t im) { subtrees[im].clear(); } void add_subtree_bound(dirfrag_t im, dirfrag_t ex) { subtrees[im].push_back(ex); } void add_ambiguous_import(dirfrag_t im, const std::vector<dirfrag_t>& m) { ambiguous_imports[im] = m; } void add_peer_request(metareqid_t reqid, bool committing) { peer_requests[reqid].committing = committing; } void add_peer_request(metareqid_t reqid, ceph::buffer::list& bl) { peer_requests[reqid].inode_caps = std::move(bl); } void add_table_commits(int table, const std::set<version_t>& pending_commits) { table_clients.push_back(table_client(table, pending_commits)); } void encode_payload(uint64_t features) override { using ceph::encode; encode(subtrees, payload); encode(ambiguous_imports, payload); encode(peer_requests, payload); encode(table_clients, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(subtrees, p); decode(ambiguous_imports, p); decode(peer_requests, p); decode(table_clients, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; inline std::ostream& operator<<(std::ostream& out, const MMDSResolve::peer_request&) { return out; } WRITE_CLASS_ENCODER(MMDSResolve::peer_request) WRITE_CLASS_ENCODER(MMDSResolve::table_client) WRITE_CLASS_ENCODER(MMDSResolve::peer_inode_cap) #endif
4,552
26.932515
101
h
null
ceph-main/src/messages/MMDSResolveAck.h
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab /* * Ceph - scalable distributed file system * * Copyright (C) 2004-2006 Sage Weil <[email protected]> * * This is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License version 2.1, as published by the Free Software * Foundation. See file COPYING. * */ #ifndef CEPH_MMDSRESOLVEACK_H #define CEPH_MMDSRESOLVEACK_H #include "include/types.h" #include "messages/MMDSOp.h" class MMDSResolveAck final : public MMDSOp { static constexpr int HEAD_VERSION = 1; static constexpr int COMPAT_VERSION = 1; public: std::map<metareqid_t, ceph::buffer::list> commit; std::vector<metareqid_t> abort; protected: MMDSResolveAck() : MMDSOp{MSG_MDS_RESOLVEACK, HEAD_VERSION, COMPAT_VERSION} {} ~MMDSResolveAck() final {} public: std::string_view get_type_name() const override { return "resolve_ack"; } /*void print(ostream& out) const { out << "resolve_ack.size() << "+" << ambiguous_imap.size() << " imports +" << peer_requests.size() << " peer requests)"; } */ void add_commit(metareqid_t r) { commit[r].clear(); } void add_abort(metareqid_t r) { abort.push_back(r); } void encode_payload(uint64_t features) override { using ceph::encode; encode(commit, payload); encode(abort, payload); } void decode_payload() override { using ceph::decode; auto p = payload.cbegin(); decode(commit, p); decode(abort, p); } private: template<class T, typename... Args> friend boost::intrusive_ptr<T> ceph::make_message(Args&&... args); template<class T, typename... Args> friend MURef<T> crimson::make_message(Args&&... args); }; #endif
1,777
25.147059
80
h