From 756a138fd7f0e09ea66bce4487ef7411abbcccdc Mon Sep 17 00:00:00 2001 From: Jos Collin Date: Thu, 14 Nov 2024 10:42:18 +0530 Subject: [PATCH] cephfs-journal-tool: check the headers in dump file after journal recovery Fixes: https://tracker.ceph.com/issues/68954 Signed-off-by: Jos Collin --- src/tools/cephfs/Dumper.cc | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/src/tools/cephfs/Dumper.cc b/src/tools/cephfs/Dumper.cc index e37c4bf01c197..882fe282cb069 100644 --- a/src/tools/cephfs/Dumper.cc +++ b/src/tools/cephfs/Dumper.cc @@ -293,24 +293,41 @@ int Dumper::undump(const char *dump_file, bool force) } if (recovered == 0) { + //Check if the headers are available in the dump file + if (!strstr(buf, "stripe_unit")) { + derr << "Invalid header, no 'stripe_unit' embedded" << dendl; + ::close(fd); + return -EINVAL; + } else if (!strstr(buf, "stripe_count")) { + derr << "Invalid header, no 'stripe_count' embedded" << dendl; + ::close(fd); + return -EINVAL; + } else if (!strstr(buf, "object_size")) { + derr << "Invalid header, no 'object_size' embedded" << dendl; + ::close(fd); + return -EINVAL; + } auto&& last_committed = journaler.get_last_committed(); stripe_unit = last_committed.layout.stripe_unit; stripe_count = last_committed.layout.stripe_count; object_size = last_committed.layout.object_size; } else { // try to get layout from dump file header, if failed set layout to default - if (strstr(buf, "stripe_unit")) { - sscanf(strstr(buf, "stripe_unit"), "stripe_unit %lu", &stripe_unit); + char *p_stripe_unit = strstr(buf, "stripe_unit"); + if (p_stripe_unit) { + sscanf(p_stripe_unit, "stripe_unit %lu", &stripe_unit); } else { stripe_unit = file_layout_t::get_default().stripe_unit; } - if (strstr(buf, "stripe_count")) { - sscanf(strstr(buf, "stripe_count"), "stripe_count %lu", &stripe_count); + char *p_stripe_count = strstr(buf, "stripe_count"); + if (p_stripe_count) { + sscanf(p_stripe_count, "stripe_count %lu", &stripe_count); } else { stripe_count = file_layout_t::get_default().stripe_count; } - if (strstr(buf, "object_size")) { - sscanf(strstr(buf, "object_size"), "object_size %lu", &object_size); + char *p_object_size = strstr(buf, "object_size"); + if (p_object_size) { + sscanf(p_object_size, "object_size %lu", &object_size); } else { object_size = file_layout_t::get_default().object_size; } -- 2.39.5