From: Samuel Just Date: Tue, 12 Mar 2013 02:32:15 +0000 (-0700) Subject: FileJournal: add testing methods to corrupt entries X-Git-Tag: v0.60~64^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a22cdc67b076cad1e38d6f29e5f3b91967b2e3fc;p=ceph.git FileJournal: add testing methods to corrupt entries Signed-off-by: Samuel Just --- diff --git a/src/os/FileJournal.cc b/src/os/FileJournal.cc index 887158ba36ba..601f5a6e496e 100644 --- a/src/os/FileJournal.cc +++ b/src/os/FileJournal.cc @@ -1797,3 +1797,104 @@ void FileJournal::throttle() if (throttle_bytes.wait(g_conf->journal_queue_max_bytes)) dout(2) << "throttle: waited for bytes" << dendl; } + +void FileJournal::get_header( + uint64_t wanted_seq, + off64_t *_pos, + entry_header_t *h) +{ + off64_t pos = header.start; + off64_t next_pos = pos; + bufferlist bl; + uint64_t seq = 0; + while (1) { + bl.clear(); + pos = next_pos; + read_entry_result result = do_read_entry( + pos, + &next_pos, + &bl, + &seq, + 0, + h); + if (result == FAILURE || result == MAYBE_CORRUPT) + assert(0); + if (seq == wanted_seq) { + if (_pos) + *_pos = pos; + return; + } + } + assert(0); // not reachable +} + +void FileJournal::corrupt( + int wfd, + off64_t corrupt_at) +{ + if (corrupt_at >= header.max_size) + corrupt_at = corrupt_at + get_top() - header.max_size; + +#ifdef DARWIN + int64_t actual = ::lseek(fd, corrupt_at, SEEK_SET); +#else + int64_t actual = ::lseek64(fd, corrupt_at, SEEK_SET); +#endif + assert(actual == corrupt_at); + + char buf[10]; + int r = safe_read_exact(fd, buf, 1); + assert(r == 0); + +#ifdef DARWIN + actual = ::lseek(wfd, corrupt_at, SEEK_SET); +#else + actual = ::lseek64(wfd, corrupt_at, SEEK_SET); +#endif + assert(actual == corrupt_at); + + buf[0]++; + r = safe_write(wfd, buf, 1); + assert(r == 0); +} + +void FileJournal::corrupt_payload( + int wfd, + uint64_t seq) +{ + off64_t pos = 0; + entry_header_t h; + get_header(seq, &pos, &h); + off64_t corrupt_at = + pos + sizeof(entry_header_t) + h.pre_pad; + corrupt(wfd, corrupt_at); +} + + +void FileJournal::corrupt_footer_magic( + int wfd, + uint64_t seq) +{ + off64_t pos = 0; + entry_header_t h; + get_header(seq, &pos, &h); + off64_t corrupt_at = + pos + sizeof(entry_header_t) + h.pre_pad + + h.len + h.post_pad + + (reinterpret_cast(&h.magic2) - reinterpret_cast(&h)); + corrupt(wfd, corrupt_at); +} + + +void FileJournal::corrupt_header_magic( + int wfd, + uint64_t seq) +{ + off64_t pos = 0; + entry_header_t h; + get_header(seq, &pos, &h); + off64_t corrupt_at = + pos + + (reinterpret_cast(&h.magic2) - reinterpret_cast(&h)); + corrupt(wfd, corrupt_at); +} diff --git a/src/os/FileJournal.h b/src/os/FileJournal.h index fabaad65a4bf..c5cc12de6598 100644 --- a/src/os/FileJournal.h +++ b/src/os/FileJournal.h @@ -429,6 +429,24 @@ private: uint64_t &last_seq) { return read_entry(bl, last_seq, 0); } + + // Debug/Testing + void get_header( + uint64_t wanted_seq, + off64_t *_pos, + entry_header_t *h); + void corrupt( + int wfd, + off64_t corrupt_at); + void corrupt_payload( + int wfd, + uint64_t seq); + void corrupt_footer_magic( + int wfd, + uint64_t seq); + void corrupt_header_magic( + int wfd, + uint64_t seq); }; WRITE_CLASS_ENCODER(FileJournal::header_t)