]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-journal-tool: check the headers in dump file after journal recovery
authorJos Collin <jcollin@redhat.com>
Thu, 14 Nov 2024 05:12:18 +0000 (10:42 +0530)
committerJos Collin <jcollin@redhat.com>
Thu, 24 Apr 2025 01:40:12 +0000 (07:10 +0530)
Fixes: https://tracker.ceph.com/issues/68954
Signed-off-by: Jos Collin <jcollin@redhat.com>
(cherry picked from commit 756a138fd7f0e09ea66bce4487ef7411abbcccdc)

 Conflicts:
    src/tools/cephfs/Dumper.cc
    - Resolved conflicts due to ceph@b302591 not backported to reef.

src/tools/cephfs/Dumper.cc

index 691ac49a18043f97b4217e9f3263f6959e21bfae..c1fb24307ec5f4d43c3e1f9fbf22f2ba1448e8fa 100644 (file)
@@ -295,23 +295,40 @@ 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;
+    }
     stripe_unit = journaler.last_committed.layout.stripe_unit;
     stripe_count = journaler.last_committed.layout.stripe_count;
     object_size = journaler.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;
     }