]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.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>
Tue, 24 Jun 2025 05:13:12 +0000 (10:43 +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 dfda045d6a9c312ef65979698e945c64b14ac0cb..9e852030bf29d9ae15d7257574c1c7c1b66eaa36 100644 (file)
@@ -298,23 +298,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;
     }