Skip to contentSkip to conversation

dm era: stop the worker before closing the metadata

PATCH New Ronnie Sahlberg 1 participant 1 message Nov 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm era: stop the worker before closing the metadata

era_destroy() closes the metadata and then destroys the workqueue. destroy_workqueue() drains the queue first, so a worker that is still queued or running at that point uses the metadata after it was freed.

The worker is only stopped by postsuspend, and there are two ways to get to era_destroy() with it still started:

- It is started by preresume before the era rollover, and stays started if the rollover fails. The device is then still suspended, so postsuspend is not called again before the table is destroyed.

- It is started from the constructor on, since era->suspended is initially zero. A status request for an inactive table runs it, and an inactive table is destroyed without ever being suspended:

     dmsetup load era --table "..."
     dmsetup status --inactive era
     dmsetup clear era

In both cases the worker can be busy digesting archived writesets, requeueing itself after every step, when the table is destroyed.

Stop the worker, which also stops it from requeueing itself, and destroy the workqueue before closing the metadata.

Fixes eec40579d848 ("dm: add era target")

---
An AI coding assistant (Claude) was used to review this patch and to help write the commit message.

 drivers/md/dm-era-target.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/md/dm-era-target.c +6 -3
index ea499adca4ce..8b8b8b3dfa19 100644
@@ -1438,12 +1438,15 @@ static void stop_worker(struct era *era)
  */
 static void era_destroy(struct era *era)
 {
+	/* The worker uses the metadata, and may still be digesting. */
+	if (era->wq) {
+		stop_worker(era);
+		destroy_workqueue(era->wq);
+	}
+
 	if (era->md)
 		metadata_close(era->md);
 
-	if (era->wq)
-		destroy_workqueue(era->wq);
-
 	if (era->origin_dev)
 		dm_put_device(era->ti, era->origin_dev);
 

base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc

Signature · 1 line
2.56.0