[PATCH linux-next v2] pstore/ram: Fix pstore lost information

chenguanxi11234@163.com posted 1 patch 1 month ago
fs/pstore/ram.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH linux-next v2] pstore/ram: Fix pstore lost information
Posted by chenguanxi11234@163.com 1 month ago
From: Chen Haonan <haonan.chen@zyt.com>

Background
==========
persistent_ram_zap() is used to prevent the corresponding file from 
still appearing after an unlink operation in the next boot, but 
this is unnecessary for console, pmsg, and ftrace. Worse yet, it 
causes the system to only show logs generated after the deletion 
operation the next time it reboots, following the removal of the 
corresponding file under /sys/fs/pstore.

Solution
==========
Before executing persistent_ram_zap(), check the file type and 
perform this operation only for dmesg logs. 

Result View
==========
Before patch:

root@ubuntu:/sys/fs/pstore# echo test1 > /dev/pmsg0 
root@ubuntu:/sys/fs/pstore# rm pmsg-ramoops-0 
root@ubuntu:/sys/fs/pstore# echo test2 > /dev/pmsg0 
root@ubuntu:/sys/fs/pstore# reboot
...
root@ubuntu:/sys/fs/pstore# cat pmsg-ramoops-0 
test2

After patch:

root@ubuntu:/sys/fs/pstore# echo test1 > /dev/pmsg0 
root@ubuntu:/sys/fs/pstore# rm pmsg-ramoops-0 
root@ubuntu:/sys/fs/pstore# echo test2 > /dev/pmsg0 
root@ubuntu:/sys/fs/pstore# reboot
...
root@ubuntu:/sys/fs/pstore# cat pmsg-ramoops-0
test1
test2

Signed-off-by: Chen Haonan <haonan.chen@zyt.com>
---
 fs/pstore/ram.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/pstore/ram.c b/fs/pstore/ram.c
index bc68b4de5287..48e4abd5dcad 100644
--- a/fs/pstore/ram.c
+++ b/fs/pstore/ram.c
@@ -436,7 +436,8 @@ static int ramoops_pstore_erase(struct pstore_record *record)
 	}
 
 	persistent_ram_free_old(prz);
-	persistent_ram_zap(prz);
+	if (record->type == PSTORE_TYPE_DMESG)
+		persistent_ram_zap(prz);
 
 	return 0;
 }
-- 
2.34.1