Skip to content

Commit b302591

Browse files
committed
mds: use Journaler getters
To access the Journaler::Header safely. Signed-off-by: Patrick Donnelly <[email protected]>
1 parent 55652f0 commit b302591

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

src/mds/PurgeQueue.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ void PurgeQueue::open(Context *completion)
225225
// Journaler only guarantees entries before head write_pos have been
226226
// fully flushed. Before appending new entries, we need to find and
227227
// drop any partial written entry.
228-
if (journaler.last_committed.write_pos < journaler.get_write_pos()) {
228+
auto&& last_committed = journaler.get_last_committed();
229+
if (last_committed.write_pos < journaler.get_write_pos()) {
229230
dout(4) << "recovering write_pos" << dendl;
230-
journaler.set_read_pos(journaler.last_committed.write_pos);
231+
journaler.set_read_pos(last_committed.write_pos);
231232
_recover();
232233
return;
233234
}
@@ -281,7 +282,8 @@ void PurgeQueue::_recover()
281282
if (journaler.get_read_pos() == journaler.get_write_pos()) {
282283
dout(4) << "write_pos recovered" << dendl;
283284
// restore original read_pos
284-
journaler.set_read_pos(journaler.last_committed.expire_pos);
285+
auto&& last_committed = journaler.get_last_committed();
286+
journaler.set_read_pos(last_committed.expire_pos);
285287
journaler.set_writeable();
286288
recovered = true;
287289
finish_contexts(g_ceph_context, waiting_for_recovery);

src/osdc/Journaler.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,9 @@ class Journaler {
217217
return stream_format;
218218
}
219219

220-
Header last_committed;
221-
222220
private:
223221
// me
222+
Header last_committed;
224223
CephContext *cct;
225224
mutable ceph::mutex lock;
226225
const std::string name;
@@ -528,6 +527,18 @@ class Journaler {
528527

529528
// Synchronous getters
530529
// ===================
530+
531+
Header get_last_committed() const {
532+
ceph_assert(!ceph_mutex_is_locked_by_me(lock));
533+
lock_guard l(lock);
534+
return last_committed;
535+
}
536+
Header get_last_written() const {
537+
ceph_assert(!ceph_mutex_is_locked_by_me(lock));
538+
lock_guard l(lock);
539+
return last_written;
540+
}
541+
531542
uint64_t get_layout_period() const {
532543
ceph_assert(!ceph_mutex_is_locked_by_me(lock));
533544
lock_guard l(lock);

src/tools/cephfs/Dumper.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,20 @@ int Dumper::dump(const char *dump_file)
112112
fsid.print(fsid_str);
113113
char buf[HEADER_LEN];
114114
memset(buf, 0, sizeof(buf));
115+
auto&& last_committed = journaler.get_last_committed();
115116
snprintf(buf, HEADER_LEN, "Ceph mds%d journal dump\n start offset %llu (0x%llx)\n\
116117
length %llu (0x%llx)\n write_pos %llu (0x%llx)\n format %llu\n\
117118
trimmed_pos %llu (0x%llx)\n stripe_unit %lu (0x%lx)\n stripe_count %lu (0x%lx)\n\
118119
object_size %lu (0x%lx)\n fsid %s\n%c",
119120
role.rank,
120121
(unsigned long long)start, (unsigned long long)start,
121122
(unsigned long long)len, (unsigned long long)len,
122-
(unsigned long long)journaler.last_committed.write_pos, (unsigned long long)journaler.last_committed.write_pos,
123-
(unsigned long long)journaler.last_committed.stream_format,
124-
(unsigned long long)journaler.last_committed.trimmed_pos, (unsigned long long)journaler.last_committed.trimmed_pos,
125-
(unsigned long)journaler.last_committed.layout.stripe_unit, (unsigned long)journaler.last_committed.layout.stripe_unit,
126-
(unsigned long)journaler.last_committed.layout.stripe_count, (unsigned long)journaler.last_committed.layout.stripe_count,
127-
(unsigned long)journaler.last_committed.layout.object_size, (unsigned long)journaler.last_committed.layout.object_size,
123+
(unsigned long long)last_committed.write_pos, (unsigned long long)last_committed.write_pos,
124+
(unsigned long long)last_committed.stream_format,
125+
(unsigned long long)last_committed.trimmed_pos, (unsigned long long)last_committed.trimmed_pos,
126+
(unsigned long)last_committed.layout.stripe_unit, (unsigned long)last_committed.layout.stripe_unit,
127+
(unsigned long)last_committed.layout.stripe_count, (unsigned long)last_committed.layout.stripe_count,
128+
(unsigned long)last_committed.layout.object_size, (unsigned long)last_committed.layout.object_size,
128129
fsid_str,
129130
4);
130131
r = safe_write(fd, buf, sizeof(buf));
@@ -156,8 +157,8 @@ int Dumper::dump(const char *dump_file)
156157

157158
C_SaferCond cond;
158159
lock.lock();
159-
filer.read(ino, &journaler.get_layout(), CEPH_NOSNAP,
160-
pos, read_size, &bl, 0, &cond);
160+
auto&& layout = journaler.get_layout();
161+
filer.read(ino, &layout, CEPH_NOSNAP, pos, read_size, &bl, 0, &cond);
161162
lock.unlock();
162163
r = cond.wait();
163164
if (r < 0) {
@@ -264,9 +265,10 @@ int Dumper::undump(const char *dump_file, bool force)
264265
}
265266

266267
if (recovered == 0) {
267-
stripe_unit = journaler.last_committed.layout.stripe_unit;
268-
stripe_count = journaler.last_committed.layout.stripe_count;
269-
object_size = journaler.last_committed.layout.object_size;
268+
auto&& last_committed = journaler.get_last_committed();
269+
stripe_unit = last_committed.layout.stripe_unit;
270+
stripe_count = last_committed.layout.stripe_count;
271+
object_size = last_committed.layout.object_size;
270272
} else {
271273
// try to get layout from dump file header, if failed set layout to default
272274
if (strstr(buf, "stripe_unit")) {

0 commit comments

Comments
 (0)