Minor cleanup of create_domain()
cover Minor cleanup of create_domain()
Something which has annoyed me for a long while decided to get in front of me again. As such getting some cleanup done as the start of addressing that annoyance.
This is some minor cleanup related to create_domain(). First is simply a bit of precursor Makefile cleanup. Next two are things which can be done earlier in the function and really look like they should be.
Elliott Mitchell (3):
tools/xl: use Make variable to retrieve xl object filename list tools/xl: free loaded configuration data earlier in create_domain() tools/xl: move some logic needed only once earlier in create_domain()
tools/xl/Makefile | 2 +- tools/xl/xl_vmcontrol.c | 36 +++++++++++++++++------------------- 2 files changed, 18 insertions(+), 20 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/3 tools/xl: use Make variable to retrieve xl object filename list
Irrelevant now, but $^ potentially makes the Makefile more maintainable. Hopefully some future author finds this valuable.
--- tools/xl/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/xl/Makefile +1 -1
@@ -34,7 +34,7 @@ $(XL_OBJS): CFLAGS += -include $(XEN_ROOT)/tools/config.h # libxl_json.h needs i all: xl xl: $(XL_OBJS) - $(CC) $(LDFLAGS) -o $@ $(XL_OBJS) $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(XEN_JSON_LIBS) $(APPEND_LDFLAGS) + $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS_libxenutil) $(LDLIBS_libxenlight) $(LDLIBS_libxentoollog) $(LDLIBS_libxenstore) $(XEN_JSON_LIBS) $(APPEND_LDFLAGS) .PHONY: install install: all
Signature · 1 line
2.47.3
PATCH 3/3 tools/xl: move some logic needed only once earlier in create_domain()
In reply to Elliott MitchellThe value of dom_info->console_autoconnect isn't going to change if a domain is rebooted. Nor does this logic need the lock to be held. As such moving this earlier makes sense.
The policy domain is set once and then never changed. Similar to above simply move before the reboot start point.
--- tools/xl/xl_vmcontrol.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)
tools/xl/xl_vmcontrol.c +15 -17
@@ -717,7 +717,8 @@ int create_domain(struct domain_create *dom_info)int restore_fd =-1 ;int restore_fd_to_close =-1 ;int send_back_fd =-1 ; -const libxl_asyncprogress_how *autoconnect_console_how; +const libxl_asyncprogress_how *autoconnect_console_how =NULL ; +libxl_asyncprogress_how autoconnect_console_how_buf;int notify_pipe[2 ] = {-1 ,-1 };struct save_file_header hdr;uint32_t domid_soft_reset =INVALID_DOMID ;
@@ -921,6 +922,19 @@ int create_domain(struct domain_create *dom_info)if (dryrun_only) goto out; +if (dom_info->console_autoconnect) { +if (libxl_pipe (ctx, notify_pipe)) { + ret =ERROR_FAIL ; + goto error_out; + } + autoconnect_console_how_buf.callback = autoconnect_console; + autoconnect_console_how_buf.for_callback = ¬ify_pipe[1 ]; + autoconnect_console_how = &autoconnect_console_how_buf; + } + +if (!libxl_domid_valid_guest (d_config.c_info.domid)) + d_config.c_info.domid = domid_policy; + start:assert (domid ==INVALID_DOMID );
@@ -938,22 +952,6 @@ start: } } -libxl_asyncprogress_how autoconnect_console_how_buf; -if ( dom_info->console_autoconnect ) { -if (libxl_pipe (ctx, notify_pipe)) { - ret =ERROR_FAIL ; - goto error_out; - } - autoconnect_console_how_buf.callback = autoconnect_console; - autoconnect_console_how_buf.for_callback = ¬ify_pipe[1 ]; - autoconnect_console_how = &autoconnect_console_how_buf; - }else { - autoconnect_console_how =0 ; - } - -if (!libxl_domid_valid_guest (d_config.c_info.domid)) - d_config.c_info.domid = domid_policy; -if ( restoring ) {libxl_domain_restore_params params;
Signature · 1 line
2.47.3
PATCH 2/3 tools/xl: free loaded configuration data earlier in create_domain()
In reply to Elliott MitchellRather than waiting for just before return, release the memory sooner. This potentially reduces process size due to be reused sooner. Also ensures it never gets into the daemon process.
--- tools/xl/xl_vmcontrol.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
tools/xl/xl_vmcontrol.c +2 -2
@@ -853,6 +853,8 @@ int create_domain(struct domain_create *dom_info)parse_config_data (config_source, config_data, config_len, &d_config); } +free (config_data); +if (!dom_info->ignore_global_affinity_masks) {libxl_domain_build_info *b_info = &d_config.b_info;
@@ -1200,8 +1202,6 @@ out:libxl_domain_config_dispose (&d_config); -free (config_data); -console_child_report (child_console);if (deathw)
Signature · 1 line
2.47.3
Re: [PATCH 3/3] tools/xl: move some logic needed only once earlier in
In reply to Elliott MitchellQuoted 27 lines · Elliott Mitchell
The value of
dom_info->console_autoconnectisn't going to change if a domain is rebooted. Nor does this logic need the lock to be held. As such moving this earlier makes sense.The policy domain is set once and then never changed. Similar to above simply move before the reboot start point.
Signed-off-by Elliott Mitchell <[email protected]>--- tools/xl/xl_vmcontrol.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)tools/xl/xl_vmcontrol.c +2
-1@@ -717,7 +717,8 @@ int create_domain(struct domain_create *dom_info)int restore_fd =-1 ;int restore_fd_to_close =-1 ;int send_back_fd =-1 ; -const libxl_asyncprogress_how *autoconnect_console_how; +const libxl_asyncprogress_how *autoconnect_console_how =NULL ; +libxl_asyncprogress_how autoconnect_console_how_buf;int notify_pipe[2 ] = {-1 ,-1 };struct save_file_header hdr;uint32_t domid_soft_reset =INVALID_DOMID ;
tools/xl/xl_vmcontrol.c int create_domain(struct domain_create *dom_info) · line 929
Quoted 8 lines
tools/xl/xl_vmcontrol.c +5
-0@@ -921,6 +922,19 @@ int create_domain(struct domain_create *dom_info)if (dryrun_only) goto out; +if (dom_info->console_autoconnect) { +if (libxl_pipe (ctx, notify_pipe)) { + ret =ERROR_FAIL ; + goto error_out; + }
It looks like a functional regression for the reboot path. Right before "goto start;" on the guest-reboot path there is:
/*
* Do not attempt to reconnect if we come round again due to a
* guest reboot -- the stdin/out will be disconnected by then.
*/
dom_info->console_autoconnect = 0;On reboot, dom_info->console_autoconnect is cleared before "goto start", but autoconnect_console_how now stays non-NULL, since it is no longer recomputed after "start:". The second create call will invoke autoconnect_console with the already-closed notify_pipe[1], and the read(notify_pipe[0]) will fail with EBADF.
Quoted 39 lines
tools/xl/xl_vmcontrol.c +8
-16+ autoconnect_console_how_buf.callback = autoconnect_console; + autoconnect_console_how_buf.for_callback = ¬ify_pipe[1 ]; + autoconnect_console_how = &autoconnect_console_how_buf; + } + +if (!libxl_domid_valid_guest (d_config.c_info.domid)) + d_config.c_info.domid = domid_policy; + start:assert (domid ==INVALID_DOMID );@@ -938,22 +952,6 @@ start: } } -libxl_asyncprogress_how autoconnect_console_how_buf; -if ( dom_info->console_autoconnect ) { -if (libxl_pipe (ctx, notify_pipe)) { - ret =ERROR_FAIL ; - goto error_out; - } - autoconnect_console_how_buf.callback = autoconnect_console; - autoconnect_console_how_buf.for_callback = ¬ify_pipe[1 ]; - autoconnect_console_how = &autoconnect_console_how_buf; - }else { - autoconnect_console_how =0 ; - } - -if (!libxl_domid_valid_guest (d_config.c_info.domid)) - d_config.c_info.domid = domid_policy; -if ( restoring ) {libxl_domain_restore_params params;Signature · 1 line
2.47.3
Re: [PATCH 3/3] tools/xl: move some logic needed only once earlier in
Quoted 47 lines · On Fri, Oct 16, 2026 at 01:07:21PM +0800, [email protected] wrote:
Quoted 27 lines · Elliott Mitchell
The value of
dom_info->console_autoconnectisn't going to change if a domain is rebooted. Nor does this logic need the lock to be held. As such moving this earlier makes sense.The policy domain is set once and then never changed. Similar to above simply move before the reboot start point.
Signed-off-by Elliott Mitchell <[email protected]>--- tools/xl/xl_vmcontrol.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-)tools/xl/xl_vmcontrol.c +2
-1@@ -717,7 +717,8 @@ int create_domain(struct domain_create *dom_info)int restore_fd =-1 ;int restore_fd_to_close =-1 ;int send_back_fd =-1 ; -const libxl_asyncprogress_how *autoconnect_console_how; +const libxl_asyncprogress_how *autoconnect_console_how =NULL ; +libxl_asyncprogress_how autoconnect_console_how_buf;int notify_pipe[2 ] = {-1 ,-1 };struct save_file_header hdr;uint32_t domid_soft_reset =INVALID_DOMID ;tools/xl/xl_vmcontrol.c int create_domain(struct domain_create *dom_info) · line 929
Quoted 8 lines
tools/xl/xl_vmcontrol.c +5
-0@@ -921,6 +922,19 @@ int create_domain(struct domain_create *dom_info)if (dryrun_only) goto out; +if (dom_info->console_autoconnect) { +if (libxl_pipe (ctx, notify_pipe)) { + ret =ERROR_FAIL ; + goto error_out; + }It looks like a functional regression for the reboot path. Right before "goto start;" on the guest-reboot path there is:
/* * Do not attempt to reconnect if we come round again due to a * guest reboot -- the stdin/out will be disconnected by then. */ dom_info->console_autoconnect = 0;
Quoted 5 lines
On reboot,
dom_info->console_autoconnectis cleared before "goto start", butautoconnect_console_hownow stays non-NULL, since it is no longer recomputed after "start:". The second create call will invokeautoconnect_consolewith the already-closed notify_pipe[1], and theread(notify_pipe[0])will fail with EBADF.
Yeah, I spotted this before you sent the message, but didn't get things done before you'd sent the message.
It gets worse. I'm pretty sure the patch is mostly correct, but this needed to be propogated further. The one and only consequence of the above hunk is to cause the autoconnect_console_how = 0; line to trigger.
In turn the one and only consequence of that setting is libxl_domain_soft_reset() gets passed 0/NULL as its final argument. The libxl_domain_soft_reset() call is only done on domain reboots. Worse, libxl_domain_soft_reset() is *always* done on domain reboots.
I've got the patch in my tree with the hunk you noticed removed and the call to libxl_domain_soft_reset() hard-coding the final argument as NULL. The only question is whether the comment should be preserved just before the libxl_domain_soft_reset() call.
Signature · 4 lines
(\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/) \BS ( | [email protected] PGP 87145445 | ) / \_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445