From a074d0b5c320547ecbb376611f3e0c6d33eb8184 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 19 May 2012 15:58:32 -0700 Subject: [PATCH] filejournal: add check() method Check if a journal appears to be valid, where valid means the header is intact and has a matching fsid. Signed-off-by: Sage Weil --- src/os/FileJournal.cc | 29 +++++++++++++++++++++++++++++ src/os/FileJournal.h | 1 + src/os/Journal.h | 7 ++++--- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 0cbb9e1e6c9..4366f046e4d 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -343,6 +343,35 @@ int FileJournal::_open_file(int64_t oldsize, blksize_t blksize, return 0; } +int FileJournal::check() +{ + int ret; + + ret = _open(false, false); + if (ret < 0) + goto done; + + ret = read_header(); + if (ret < 0) + goto done; + + if (header.fsid != fsid) { + derr << "check: ondisk fsid " << header.fsid << " doesn't match expected " << fsid + << ", invalid (someone else's?) journal" << dendl; + ret = -EINVAL; + goto done; + } + + dout(1) << "check: header looks ok" << dendl; + ret = 0; + + done: + TEMP_FAILURE_RETRY(::close(fd)); + fd = -1; + return ret; +} + + int FileJournal::create() { void *buf = 0; diff --git a/src/os/FileJournal.h b/src/os/FileJournal.h index 7e2bb315cc0..800d3ba22e1 100644 --- a/src/os/FileJournal.h +++ b/src/os/FileJournal.h @@ -318,6 +318,7 @@ private: delete[] zero_buf; } + int check(); int create(); int open(uint64_t fs_op_seq); void close(); diff --git a/src/os/Journal.h b/src/os/Journal.h index 0d5799872b7..ad4f4a1af0b 100644 --- a/src/os/Journal.h +++ b/src/os/Journal.h @@ -42,9 +42,10 @@ public: wait_on_full(false) { } virtual ~Journal() { } - virtual int create() = 0; - virtual int open(uint64_t fs_op_seq) = 0; - virtual void close() = 0; + virtual int check() = 0; ///< check if journal appears valid + virtual int create() = 0; ///< create a fresh journal + virtual int open(uint64_t fs_op_seq) = 0; ///< open an existing journal + virtual void close() = 0; ///< close an open journal virtual void flush() = 0; virtual void throttle() = 0;