public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs_repair: fix progress reporting
@ 2020-05-18 22:35 Eric Sandeen
  2020-05-19  0:58 ` Darrick J. Wong
  2020-05-19  1:29 ` [PATCH V2] " Eric Sandeen
  0 siblings, 2 replies; 10+ messages in thread
From: Eric Sandeen @ 2020-05-18 22:35 UTC (permalink / raw)
  To: linux-xfs; +Cc: Leonardo Vaz

Long ago, a young developer tried to fix a segfault in xfs_repair where
a short progress reporting interval could cause a timer to go off and try
to print a progress mesage before any had been properly set up because
we were still busy zeroing the log, and a NULL pointer dereference
ensued.

That young developer got it wrong, and completely broke progress
reporting, because the change caused us to exit early from the pthread
start routine, and not initialize the progress timer at all.

That developer is now slightly older and wiser, and finally realizes that
the simple and correct solution here is to initialize the message format
to the first one in the list, so that we will be ready to go with a
progress message no matter when the first timer goes off.

Reported-by: Leonardo Vaz <lvaz@redhat.com>
Fixes: 7f2d6b811755 ("xfs_repair: avoid segfault if reporting progre...")
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

It might be nice to add progress reporting for the log zeroing, but that
requires renumbering all these macros, and we don't/can't actually get
any fine-grained progress at all, so probably not worth it.

diff --git a/repair/progress.c b/repair/progress.c
index 5ee08229..d7baa606 100644
--- a/repair/progress.c
+++ b/repair/progress.c
@@ -125,7 +125,11 @@ init_progress_rpt (void)
 	 */
 
 	pthread_mutex_init(&global_msgs.mutex, NULL);
-	global_msgs.format = NULL;
+	/*
+	 * Ensure the format string is not NULL in case the first timer
+	 * goes off before any stage calls set_progress_msg() to set it.
+	 */
+	global_msgs.format = &progress_rpt_reports[0];
 	global_msgs.count = glob_agcount;
 	global_msgs.interval = report_interval;
 	global_msgs.done   = prog_rpt_done;
@@ -171,10 +175,6 @@ progress_rpt_thread (void *p)
 	msg_block_t *msgp = (msg_block_t *)p;
 	uint64_t percent;
 
-	/* It's possible to get here very early w/ no progress msg set */
-	if (!msgp->format)
-		return NULL;
-
 	if ((msgbuf = (char *)malloc(DURATION_BUF_SIZE)) == NULL)
 		do_error (_("progress_rpt: cannot malloc progress msg buffer\n"));
 


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-05-19 23:39 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-05-18 22:35 [PATCH] xfs_repair: fix progress reporting Eric Sandeen
2020-05-19  0:58 ` Darrick J. Wong
2020-05-19  1:03   ` Eric Sandeen
2020-05-19  1:13     ` Darrick J. Wong
2020-05-19  1:15       ` Eric Sandeen
2020-05-19  1:29 ` [PATCH V2] " Eric Sandeen
2020-05-19  2:04   ` Darrick J. Wong
2020-05-19  7:03   ` Donald Douwsma
2020-05-19 12:53     ` Eric Sandeen
2020-05-19 23:38       ` Donald Douwsma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox