* [PATCH] xl/libxl: introducing libxl_primary_console_exec
@ 2010-07-16 17:03 Stefano Stabellini
2010-07-16 17:40 ` Gianni Tedesco
0 siblings, 1 reply; 3+ messages in thread
From: Stefano Stabellini @ 2010-07-16 17:03 UTC (permalink / raw)
To: xen-devel
Hi all,
this patch introduces libxl_primary_console_exec: a new libxl function
that finds the domid and console number corresponding to the primary
console of a given vm. The domid might be different from the domid of
the VM and the console number might not be 0 when using stubdoms.
The caller (xl_cmdimpl.c in this case) has to make sure that the stubdom
is already created before calling libxl_primary_console_exec in the hvm
case. In the PV case libxl_primary_console_exec has to be called before
libxl_run_bootloader.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
diff -r e382656e4dcc tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Fri Jul 16 16:19:51 2010 +0100
+++ b/tools/libxl/libxl.c Fri Jul 16 17:56:58 2010 +0100
@@ -803,6 +803,15 @@
return execl(p, p, domid_s, "--num", cons_num_s, (void *)NULL) == 0 ? 0 : ERROR_FAIL;
}
+int libxl_primary_console_exec(struct libxl_ctx *ctx, uint32_t domid_vm)
+{
+ uint32_t stubdomid = libxl_get_stubdom_id(ctx, domid_vm);
+ if (stubdomid)
+ return libxl_console_exec(ctx, stubdomid, 1);
+ else
+ return libxl_console_exec(ctx, domid_vm, 0);
+}
+
static char ** libxl_build_device_model_args(struct libxl_ctx *ctx,
libxl_device_model_info *info,
libxl_device_nic *vifs,
diff -r e382656e4dcc tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Fri Jul 16 16:19:51 2010 +0100
+++ b/tools/libxl/libxl.h Fri Jul 16 17:56:58 2010 +0100
@@ -399,6 +399,11 @@
int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce);
int libxl_console_exec(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
+/* libxl_primary_console_exec finds the domid and console number
+ * corresponding to the primary console of the given vm, then calls
+ * libxl_console_exec with the right arguments (domid might be different
+ * if the guest is using stubdoms) */
+int libxl_primary_console_exec(struct libxl_ctx *ctx, uint32_t domid_vm);
int libxl_domain_info(struct libxl_ctx*, struct libxl_dominfo *info_r,
uint32_t domid);
diff -r e382656e4dcc tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Fri Jul 16 16:19:51 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Fri Jul 16 17:56:58 2010 +0100
@@ -947,9 +947,9 @@
return r;
}
-int autoconnect_console(int cons_num)
+int autoconnect_console(int hvm)
{
- int status;
+ int status, options;
pid_t pid, r;
/*
@@ -966,14 +966,21 @@
return 0;
/*
- * Catch failure of the create process.
+ * In the PV case we only catch failure of the create process, in
+ * the HVM case we also wait for the creation process to be
+ * completed so that the stubdom is already up and running and we
+ * can connect to it.
*/
+ if (hvm)
+ options = 0;
+ else
+ options = WNOHANG;
sleep(1);
- r = waitpid(pid, &status, WNOHANG);
+ r = waitpid(pid, &status, options);
if (r > 0 && WIFEXITED(status) && WEXITSTATUS(status) != 0)
_exit(WEXITSTATUS(status));
- libxl_console_exec(&ctx, domid, cons_num);
+ libxl_primary_console_exec(&ctx, domid);
/* Do not return. xl continued in child process */
fprintf(stderr, "Unable to attach console\n");
_exit(1);
@@ -1170,7 +1177,7 @@
}
if (dom_info->console_autoconnect) {
- ret = autoconnect_console(0);
+ ret = autoconnect_console(info1.hvm);
if (ret)
goto error_out;
}
@@ -1624,18 +1631,13 @@
int main_console(int argc, char **argv)
{
- int opt = 0, cons_num = 0;
+ int opt = 0;
while ((opt = getopt(argc, argv, "hn:")) != -1) {
switch (opt) {
case 'h':
help("console");
exit(0);
- case 'n':
- if (optarg) {
- cons_num = strtol(optarg, NULL, 10);
- }
- break;
default:
fprintf(stderr, "option not supported\n");
break;
@@ -1647,7 +1649,7 @@
}
find_domain(argv[optind]);
- libxl_console_exec(&ctx, domid, 0);
+ libxl_primary_console_exec(&ctx, domid);
fprintf(stderr, "Unable to attach console\n");
return 1;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xl/libxl: introducing libxl_primary_console_exec
2010-07-16 17:03 [PATCH] xl/libxl: introducing libxl_primary_console_exec Stefano Stabellini
@ 2010-07-16 17:40 ` Gianni Tedesco
2010-07-19 10:55 ` Stefano Stabellini
0 siblings, 1 reply; 3+ messages in thread
From: Gianni Tedesco @ 2010-07-16 17:40 UTC (permalink / raw)
To: Stefano Stabellini; +Cc: xen-devel@lists.xensource.com
On Fri, 2010-07-16 at 18:03 +0100, Stefano Stabellini wrote:
> Hi all,
> this patch introduces libxl_primary_console_exec: a new libxl function
> that finds the domid and console number corresponding to the primary
> console of a given vm. The domid might be different from the domid of
> the VM and the console number might not be 0 when using stubdoms.
> The caller (xl_cmdimpl.c in this case) has to make sure that the stubdom
> is already created before calling libxl_primary_console_exec in the hvm
> case. In the PV case libxl_primary_console_exec has to be called before
> libxl_run_bootloader.
... snip ...
> int libxl_console_exec(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
> +/* libxl_primary_console_exec finds the domid and console number
> + * corresponding to the primary console of the given vm, then calls
> + * libxl_console_exec with the right arguments (domid might be different
> + * if the guest is using stubdoms) */
> +int libxl_primary_console_exec(struct libxl_ctx *ctx, uint32_t domid_vm);
If this call has some none-obvious ordering constraints then that should
be mentioned in the header no?
Gianni
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] xl/libxl: introducing libxl_primary_console_exec
2010-07-16 17:40 ` Gianni Tedesco
@ 2010-07-19 10:55 ` Stefano Stabellini
0 siblings, 0 replies; 3+ messages in thread
From: Stefano Stabellini @ 2010-07-19 10:55 UTC (permalink / raw)
To: Gianni Tedesco (3P); +Cc: xen-devel@lists.xensource.com, Stefano Stabellini
On Fri, 16 Jul 2010, Gianni Tedesco (3P) wrote:
> On Fri, 2010-07-16 at 18:03 +0100, Stefano Stabellini wrote:
> > Hi all,
> > this patch introduces libxl_primary_console_exec: a new libxl function
> > that finds the domid and console number corresponding to the primary
> > console of a given vm. The domid might be different from the domid of
> > the VM and the console number might not be 0 when using stubdoms.
> > The caller (xl_cmdimpl.c in this case) has to make sure that the stubdom
> > is already created before calling libxl_primary_console_exec in the hvm
> > case. In the PV case libxl_primary_console_exec has to be called before
> > libxl_run_bootloader.
>
> ... snip ...
>
> > int libxl_console_exec(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
> > +/* libxl_primary_console_exec finds the domid and console number
> > + * corresponding to the primary console of the given vm, then calls
> > + * libxl_console_exec with the right arguments (domid might be different
> > + * if the guest is using stubdoms) */
> > +int libxl_primary_console_exec(struct libxl_ctx *ctx, uint32_t domid_vm);
>
> If this call has some none-obvious ordering constraints then that should
> be mentioned in the header no?
>
Yes, you are right.
This is the updated version of the patch:
diff -r e382656e4dcc tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Fri Jul 16 16:19:51 2010 +0100
+++ b/tools/libxl/libxl.c Mon Jul 19 11:54:45 2010 +0100
@@ -803,6 +803,15 @@
return execl(p, p, domid_s, "--num", cons_num_s, (void *)NULL) == 0 ? 0 : ERROR_FAIL;
}
+int libxl_primary_console_exec(struct libxl_ctx *ctx, uint32_t domid_vm)
+{
+ uint32_t stubdomid = libxl_get_stubdom_id(ctx, domid_vm);
+ if (stubdomid)
+ return libxl_console_exec(ctx, stubdomid, 1);
+ else
+ return libxl_console_exec(ctx, domid_vm, 0);
+}
+
static char ** libxl_build_device_model_args(struct libxl_ctx *ctx,
libxl_device_model_info *info,
libxl_device_nic *vifs,
diff -r e382656e4dcc tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Fri Jul 16 16:19:51 2010 +0100
+++ b/tools/libxl/libxl.h Mon Jul 19 11:54:45 2010 +0100
@@ -399,6 +399,14 @@
int libxl_set_memory_target(struct libxl_ctx *ctx, uint32_t domid, uint32_t target_memkb, int enforce);
int libxl_console_exec(struct libxl_ctx *ctx, uint32_t domid, int cons_num);
+/* libxl_primary_console_exec finds the domid and console number
+ * corresponding to the primary console of the given vm, then calls
+ * libxl_console_exec with the right arguments (domid might be different
+ * if the guest is using stubdoms).
+ * This function can be called after creating the device model, in
+ * case of HVM guests, and before libxl_run_bootloader in case of PV
+ * guests using pygrub. */
+int libxl_primary_console_exec(struct libxl_ctx *ctx, uint32_t domid_vm);
int libxl_domain_info(struct libxl_ctx*, struct libxl_dominfo *info_r,
uint32_t domid);
diff -r e382656e4dcc tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Fri Jul 16 16:19:51 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Mon Jul 19 11:54:45 2010 +0100
@@ -947,9 +947,9 @@
return r;
}
-int autoconnect_console(int cons_num)
+int autoconnect_console(int hvm)
{
- int status;
+ int status, options;
pid_t pid, r;
/*
@@ -966,14 +966,21 @@
return 0;
/*
- * Catch failure of the create process.
+ * In the PV case we only catch failure of the create process, in
+ * the HVM case we also wait for the creation process to be
+ * completed so that the stubdom is already up and running and we
+ * can connect to it.
*/
+ if (hvm)
+ options = 0;
+ else
+ options = WNOHANG;
sleep(1);
- r = waitpid(pid, &status, WNOHANG);
+ r = waitpid(pid, &status, options);
if (r > 0 && WIFEXITED(status) && WEXITSTATUS(status) != 0)
_exit(WEXITSTATUS(status));
- libxl_console_exec(&ctx, domid, cons_num);
+ libxl_primary_console_exec(&ctx, domid);
/* Do not return. xl continued in child process */
fprintf(stderr, "Unable to attach console\n");
_exit(1);
@@ -1170,7 +1177,7 @@
}
if (dom_info->console_autoconnect) {
- ret = autoconnect_console(0);
+ ret = autoconnect_console(info1.hvm);
if (ret)
goto error_out;
}
@@ -1624,18 +1631,13 @@
int main_console(int argc, char **argv)
{
- int opt = 0, cons_num = 0;
+ int opt = 0;
while ((opt = getopt(argc, argv, "hn:")) != -1) {
switch (opt) {
case 'h':
help("console");
exit(0);
- case 'n':
- if (optarg) {
- cons_num = strtol(optarg, NULL, 10);
- }
- break;
default:
fprintf(stderr, "option not supported\n");
break;
@@ -1647,7 +1649,7 @@
}
find_domain(argv[optind]);
- libxl_console_exec(&ctx, domid, 0);
+ libxl_primary_console_exec(&ctx, domid);
fprintf(stderr, "Unable to attach console\n");
return 1;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-07-19 10:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-16 17:03 [PATCH] xl/libxl: introducing libxl_primary_console_exec Stefano Stabellini
2010-07-16 17:40 ` Gianni Tedesco
2010-07-19 10:55 ` Stefano Stabellini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).