已合并
[sync] PR-177: Grow: fsync backup data before metadata #183
openeuler-ci-bot创建于 9月30日
[sync] PR-177: Grow: fsync backup data before metadata #183
已合并
共 2 个文件变更+69-1
| @@ -0,0 +1,64 @@ | |||
| 1 | +From 395910153c74a8a277caf45eb33a357d16f5ac6d Mon Sep 17 00:00:00 2001 | ||
| 2 | +From: Xiao Ni <xiao@kernel.org> | ||
| 3 | +Date: Wed, 26 Aug 2026 23:16:38 -0400 | ||
| 4 | +Subject: [PATCH] Grow: fsync backup data before metadata | ||
| 5 | + | ||
| 6 | +grow_backup() writes critical-section data to backup storage and then | ||
| 7 | +publishes md_backup_data metadata that makes the backup discoverable | ||
| 8 | +after a crash. | ||
| 9 | + | ||
| 10 | +If that metadata reaches stable storage before the backup data does, | ||
| 11 | +restart can accept checksum-valid metadata and restore incomplete or | ||
| 12 | +stale backup contents into the array. The old code issued one final | ||
| 13 | +fsync() after metadata writes and ignored its return value. | ||
| 14 | + | ||
| 15 | +Flush each backup target after save_stripes() succeeds and before | ||
| 16 | +writing valid backup metadata. Also treat metadata fsync() failure as | ||
| 17 | +a grow_backup() failure so child_monitor() aborts the reshape instead | ||
| 18 | +of advancing without a durable backup. | ||
| 19 | + | ||
| 20 | +Signed-off-by: Xiao Ni <xiao@kernel.org> | ||
| 21 | +--- | ||
| 22 | + Grow.c | 19 ++++++++++++++++++- | ||
| 23 | + 1 file changed, 18 insertions(+), 1 deletion(-) | ||
| 24 | + | ||
| 25 | +diff --git a/Grow.c b/Grow.c | ||
| 26 | +index efcdce8..773a2fe 100644 | ||
| 27 | +--- a/Grow.c | ||
| 28 | ++++ b/Grow.c | ||
| 29 | +@@ -4271,6 +4271,19 @@ static int grow_backup(struct mdinfo *sra, | ||
| 30 | + | ||
| 31 | + if (rv) | ||
| 32 | + return rv; | ||
| 33 | ++ | ||
| 34 | ++ /* | ||
| 35 | ++ * Make backup data durable before publishing metadata that marks it | ||
| 36 | ++ * usable after a crash. | ||
| 37 | ++ */ | ||
| 38 | ++ for (i = 0; i < dests; i++) { | ||
| 39 | ++ if (fsync(destfd[i]) != 0) { | ||
| 40 | ++ pr_err("Failed to fsync backup data: %s\n", | ||
| 41 | ++ strerror(errno)); | ||
| 42 | ++ return -1; | ||
| 43 | ++ } | ||
| 44 | ++ } | ||
| 45 | ++ | ||
| 46 | + bsb.mtime = __cpu_to_le64(time(0)); | ||
| 47 | + for (i = 0; i < dests; i++) { | ||
| 48 | + bsb.devstart = __cpu_to_le64(destoffsets[i]/512); | ||
| 49 | +@@ -4295,7 +4308,11 @@ static int grow_backup(struct mdinfo *sra, | ||
| 50 | + if (write(destfd[i], &bsb, 512) != 512) | ||
| 51 | + break; | ||
| 52 | + } | ||
| 53 | +- fsync(destfd[i]); | ||
| 54 | ++ if (fsync(destfd[i]) != 0) { | ||
| 55 | ++ pr_err("Failed to fsync backup metadata: %s\n", | ||
| 56 | ++ strerror(errno)); | ||
| 57 | ++ break; | ||
| 58 | ++ } | ||
| 59 | + rv = 0; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | +-- | ||
| 63 | +2.54.0 | ||
| 64 | + | ||
| @@ -1,6 +1,6 @@ | |||
| 1 | Name: mdadm | 1 | Name: mdadm |
| 2 | Version: 4.2 | 2 | Version: 4.2 |
| 3 | -Release: 23 | 3 | +Release: 24 |
| 4 | Summary: The software RAID arrays user manage tools | 4 | Summary: The software RAID arrays user manage tools |
| 5 | License: GPLv2+ | 5 | License: GPLv2+ |
| 6 | URL: http://www.kernel.org/pub/linux/utils/raid/mdadm/ | 6 | URL: http://www.kernel.org/pub/linux/utils/raid/mdadm/ |
| @@ -45,6 +45,7 @@ Patch32: 0032-Grow-fix-can-t-change-bitmap-type-from-none-to-clust.patch | |||
| 45 | Patch33: 0033-platform-intel-fix-buffer-overflow.patch | 45 | Patch33: 0033-platform-intel-fix-buffer-overflow.patch |
| 46 | Patch34: 0034-mdadm-Assemble-alloc-superblock-in-Assemble.patch | 46 | Patch34: 0034-mdadm-Assemble-alloc-superblock-in-Assemble.patch |
| 47 | Patch35: 0035-mdadm-Fix-memory-leak-in-Detail.patch | 47 | Patch35: 0035-mdadm-Fix-memory-leak-in-Detail.patch |
| 48 | +Patch36: 0036-Grow-fsync-backup-data-before-metadata.patch | ||
| 48 | 49 | ||
| 49 | BuildRequires: systemd gcc binutils libudev-devel | 50 | BuildRequires: systemd gcc binutils libudev-devel |
| 50 | 51 | ||
| @@ -111,6 +112,9 @@ install -d -m 710 %{buildroot}/var/run/mdadm/ | |||
| 111 | %{_mandir}/man*/* | 112 | %{_mandir}/man*/* |
| 112 | 113 | ||
| 113 | %changelog | 114 | %changelog |
| 115 | +* Wed Sep 16 2026 liuh <liuhuan01@kylinos.cn> - 4.2-24 | ||
| 116 | +- Grow: fsync backup data before metadata | ||
| 117 | + | ||
| 114 | * Thu Jun 18 2026 cenhuilin <cenhuilin@kylinos.cn> - 4.2-23 | 118 | * Thu Jun 18 2026 cenhuilin <cenhuilin@kylinos.cn> - 4.2-23 |
| 115 | - mdadm: Fix memory leak in Detail | 119 | - mdadm: Fix memory leak in Detail |
| 116 | 120 | ||