From b6c68dd55272f9066d7b5cf2fa30ea44f7c36533 Mon Sep 17 00:00:00 2001 From: chenyupeng360 Date: Tue, 22 May 2018 12:34:51 +0800 Subject: [PATCH] cephfs-journal-tool: Fix purging when importing an zero-length journal. When importing a zero-length purge_queue journal exported previously, the last object and the following one are now being purged for removing potential junks. In this case, there will be no writing performed actually, so the purged last object get lost permanently. This can be fixed by purging the object following the last object, and by zeroing the last object starting from the offset determined by the write_pos. Fixes: https://tracker.ceph.com/issues/24239 Signed-off-by: yupeng chen Signed-off-by: zhongyan gu --- src/tools/cephfs/Dumper.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/tools/cephfs/Dumper.cc b/src/tools/cephfs/Dumper.cc index 67252eaa326fb..746263e5d6dab 100644 --- a/src/tools/cephfs/Dumper.cc +++ b/src/tools/cephfs/Dumper.cc @@ -286,8 +286,15 @@ int Dumper::undump(const char *dump_file) { uint32_t const object_size = h.layout.object_size; assert(object_size > 0); - uint64_t const last_obj = h.write_pos / object_size; - uint64_t const purge_count = 2; + uint64_t last_obj = h.write_pos / object_size; + uint64_t purge_count = 2; + /* When the length is zero, the last_obj should be zeroed + * from the offset determined by the new write_pos instead of being purged. + */ + if (!len) { + purge_count = 1; + ++last_obj; + } C_SaferCond purge_cond; cout << "Purging " << purge_count << " objects from " << last_obj << std::endl; lock.Lock(); @@ -296,6 +303,20 @@ int Dumper::undump(const char *dump_file) lock.Unlock(); purge_cond.wait(); } + /* When the length is zero, zero the last object + * from the offset determined by the new write_pos. + */ + if (!len) { + uint64_t offset_in_obj = h.write_pos % h.layout.object_size; + uint64_t len = h.layout.object_size - offset_in_obj; + C_SaferCond zero_cond; + cout << "Zeroing " << len << " bytes in the last object." << std::endl; + + lock.Lock(); + filer.zero(ino, &h.layout, snapc, h.write_pos, len, ceph::real_clock::now(), 0, &zero_cond); + lock.Unlock(); + zero_cond.wait(); + } // Stream from `fd` to `filer` uint64_t pos = start; -- 2.39.5