public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xen/manage: unwind partial shutdown watcher setup on error
@ 2026-04-07  2:24 zhaoguohan
  2026-04-09  1:42 ` Stefano Stabellini
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: zhaoguohan @ 2026-04-07  2:24 UTC (permalink / raw)
  To: jgross, sstabellini
  Cc: oleksandr_tyshchenko, xen-devel, linux-kernel, GuoHan Zhao

From: GuoHan Zhao <zhaoguohan@kylinos.cn>

setup_shutdown_watcher() registers shutdown_watch first, then the sysrq
watch, and finally publishes the supported feature-* nodes in xenstore.
If sysrq watch registration fails, or xenbus_printf() fails after one or
more feature nodes were created, the function returns immediately without
undoing the earlier setup.

This leaves the system in a partially initialized state, with registered
watches and/or stale xenstore entries despite the function reporting
failure.

Unwind the partial setup before returning an error by unregistering any
watches that were already registered and removing feature nodes that were
already published.

Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
---
 drivers/xen/manage.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/drivers/xen/manage.c b/drivers/xen/manage.c
index e20c40a62e64..18bf09e0192a 100644
--- a/drivers/xen/manage.c
+++ b/drivers/xen/manage.c
@@ -343,12 +343,11 @@ static int setup_shutdown_watcher(void)
 		return err;
 	}
 
-
 #ifdef CONFIG_MAGIC_SYSRQ
 	err = register_xenbus_watch(&sysrq_watch);
 	if (err) {
 		pr_err("Failed to set sysrq watcher\n");
-		return err;
+		goto err_unregister_shutdown;
 	}
 #endif
 
@@ -361,11 +360,26 @@ static int setup_shutdown_watcher(void)
 		if (err) {
 			pr_err("%s: Error %d writing %s\n", __func__,
 				err, node);
-			return err;
+			goto err_remove_features;
 		}
 	}
 
 	return 0;
+
+err_remove_features:
+	while (--idx >= 0) {
+		if (!shutdown_handlers[idx].flag)
+			continue;
+		snprintf(node, FEATURE_PATH_SIZE, "feature-%s",
+			 shutdown_handlers[idx].command);
+		xenbus_rm(XBT_NIL, "control", node);
+	}
+#ifdef CONFIG_MAGIC_SYSRQ
+	unregister_xenbus_watch(&sysrq_watch);
+#endif
+err_unregister_shutdown:
+	unregister_xenbus_watch(&shutdown_watch);
+	return err;
 }
 
 static int shutdown_event(struct notifier_block *notifier,
-- 
2.43.0


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

end of thread, other threads:[~2026-04-21 19:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-07  2:24 [PATCH] xen/manage: unwind partial shutdown watcher setup on error zhaoguohan
2026-04-09  1:42 ` Stefano Stabellini
2026-04-21 11:08 ` kernel test robot
2026-04-21 19:33 ` kernel test robot

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