summaryrefslogtreecommitdiffstats
path: root/src/osdc/Journaler.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/osdc/Journaler.h')
-rw-r--r--src/osdc/Journaler.h84
1 files changed, 67 insertions, 17 deletions
diff --git a/src/osdc/Journaler.h b/src/osdc/Journaler.h
index 1b40eadec16..d15862c08ba 100644
--- a/src/osdc/Journaler.h
+++ b/src/osdc/Journaler.h
@@ -186,6 +186,16 @@ public:
f->close_section(); // journal_header
}
+ void print(std::ostream& os) const {
+ os << std::hex
+ << "Journaler::Header"
+ "(t=" << trimmed_pos
+ << " e=" << expire_pos
+ << " w=" << write_pos
+ << ")"
+ << std::dec;
+ }
+
static void generate_test_instances(std::list<Header*> &ls)
{
ls.push_back(new Header());
@@ -207,15 +217,14 @@ public:
return stream_format;
}
- Header last_committed;
-
private:
// me
+ Header last_committed;
CephContext *cct;
- std::mutex lock;
+ mutable ceph::mutex lock;
const std::string name;
- typedef std::lock_guard<std::mutex> lock_guard;
- typedef std::unique_lock<std::mutex> unique_lock;
+ typedef std::lock_guard<ceph::mutex> lock_guard;
+ typedef std::unique_lock<ceph::mutex> unique_lock;
Finisher *finisher;
Header last_written;
inodeno_t ino;
@@ -398,7 +407,7 @@ public:
Journaler(const std::string &name_, inodeno_t ino_, int64_t pool,
const char *mag, Objecter *obj, PerfCounters *l, int lkey, Finisher *f) :
last_committed(mag),
- cct(obj->cct), name(name_), finisher(f), last_written(mag),
+ cct(obj->cct), lock(ceph::make_mutex("Journaler::" + name_)), name(name_), finisher(f), last_written(mag),
ino(ino_), pg_pool(pool), readonly(true),
stream_format(-1), journal_stream(-1),
magic(mag),
@@ -518,24 +527,65 @@ public:
// Synchronous getters
// ===================
- // TODO: need some locks on reads for true safety
+
+ Header get_last_committed() const {
+ lock_guard l(lock);
+ return last_committed;
+ }
+ Header get_last_written() const {
+ lock_guard l(lock);
+ return last_written;
+ }
+
uint64_t get_layout_period() const {
+ lock_guard l(lock);
return layout.get_period();
}
- file_layout_t& get_layout() { return layout; }
- bool is_active() { return state == STATE_ACTIVE; }
- bool is_stopping() { return state == STATE_STOPPING; }
- int get_error() { return error; }
- bool is_readonly() { return readonly; }
+ file_layout_t get_layout() const {
+ lock_guard l(lock);
+ return layout;
+ }
+ bool is_active() const {
+ lock_guard l(lock);
+ return state == STATE_ACTIVE;
+ }
+ bool is_stopping() const {
+ lock_guard l(lock);
+ return state == STATE_STOPPING;
+ }
+ int get_error() const {
+ lock_guard l(lock);
+ return error;
+ }
+ bool is_readonly() const {
+ lock_guard l(lock);
+ return readonly;
+ }
bool is_readable();
bool _is_readable();
bool try_read_entry(bufferlist& bl);
- uint64_t get_write_pos() const { return write_pos; }
- uint64_t get_write_safe_pos() const { return safe_pos; }
- uint64_t get_read_pos() const { return read_pos; }
- uint64_t get_expire_pos() const { return expire_pos; }
- uint64_t get_trimmed_pos() const { return trimmed_pos; }
+ uint64_t get_write_pos() const {
+ lock_guard l(lock);
+ return write_pos;
+ }
+ uint64_t get_write_safe_pos() const {
+ lock_guard l(lock);
+ return safe_pos;
+ }
+ uint64_t get_read_pos() const {
+ lock_guard l(lock);
+ return read_pos;
+ }
+ uint64_t get_expire_pos() const {
+ lock_guard l(lock);
+ return expire_pos;
+ }
+ uint64_t get_trimmed_pos() const {
+ lock_guard l(lock);
+ return trimmed_pos;
+ }
size_t get_journal_envelope_size() const {
+ lock_guard l(lock);
return journal_stream.get_envelope_size();
}
void check_isreadable();