Blame SOURCES/0108-Dump-get-stat-from-a-wrong-metadata-file-when-restor.patch

e95a18
From 75562b57d43bd252399b55d0004b8eac4b337a67 Mon Sep 17 00:00:00 2001
e95a18
From: Lidong Zhong <lidong.zhong@suse.com>
e95a18
Date: Mon, 14 Dec 2020 22:51:33 +0800
e95a18
Subject: [PATCH 108/108] Dump: get stat from a wrong metadata file when
e95a18
 restoring metadata
e95a18
e95a18
The dumped metadata files are shown as below
e95a18
localhost:~ # ll -ih test/
e95a18
total 16K
e95a18
34565564 -rw-r--r-- 2 root root 1.0G Dec 14 21:15
e95a18
scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-3
e95a18
34565563 -rw-r--r-- 2 root root 1.0G Dec 14 21:15
e95a18
scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-4
e95a18
34565563 -rw-r--r-- 2 root root 1.0G Dec 14 21:15 sda
e95a18
34565564 -rw-r--r-- 2 root root 1.0G Dec 14 21:15 sdb
e95a18
e95a18
It reports such error when trying to restore metadata for /dev/sda
e95a18
localhost:~ # mdadm --restore=test /dev/sda
e95a18
mdadm: test/scsi-0QEMU_QEMU_HARDDISK_drive-scsi0-0-0-4 is not the same
e95a18
size as /dev/sda - cannot restore.
e95a18
It's because the stb value has been changed to other metadata file in
e95a18
the while statement.
e95a18
e95a18
Signed-off-by: Lidong Zhong <lidong.zhong@suse.com>
e95a18
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
e95a18
---
e95a18
 Dump.c | 5 +++++
e95a18
 1 file changed, 5 insertions(+)
e95a18
e95a18
diff --git a/Dump.c b/Dump.c
e95a18
index 38e8f23..736bcb6 100644
e95a18
--- a/Dump.c
e95a18
+++ b/Dump.c
e95a18
@@ -272,6 +272,11 @@ int Restore_metadata(char *dev, char *dir, struct context *c,
e95a18
 		       fname);
e95a18
 		goto err;
e95a18
 	}
e95a18
+	if (stat(fname, &stb) != 0) {
e95a18
+		pr_err("Could not stat %s for --restore.\n",
e95a18
+		       fname);
e95a18
+		goto err;
e95a18
+	}
e95a18
 	if (((unsigned long long)stb.st_size) != size) {
e95a18
 		pr_err("%s is not the same size as %s - cannot restore.\n",
e95a18
 		       fname, dev);
e95a18
-- 
e95a18
2.7.5
e95a18