On Mon, 9 Aug 2010, Stefano Stabellini wrote:
> This patch modifies libxenlight to support multiple consoles and
> separates the xenstore paths for pv and serial consoles:
>
> - rename libxl_console_constype to libxl_console_consback: constype is
> used to to specify whether qemu or xenconsoled provides the backend, so I
> renamed it to libxl_console_consback to make it more obvious that we are
> talking about backends;
>
> - add a new libxl_console_constype to specify if the console is an
> emulated serial or a pv console;
>
> - support the new xenconsole "type" command line parameter;
>
> - use the "output" node under console in xenstore to tell qemu where do we
> want the output of this pv console to go;
>
>
actually I missed one change in the patch: pv console number 0 only
needs to be added to dompath/console, dompath/device/console/0 should be
avoided because the backends don't respond to changes in the xenbus state
there.
This is the updated patch.
---
This patch modifies libxenlight to support multiple consoles and
separates the xenstore paths for pv and serial consoles:
- rename libxl_console_constype to libxl_console_consback: constype is
used to to specify whether qemu or xenconsoled provides the backend, so I
renamed it to libxl_console_consback to make it more obvious that we are
talking about backends;
- add a new libxl_console_constype to specify if the console is an
emulated serial or a pv console;
- support the new xenconsole "type" command line parameter;
- use the "output" node under console in xenstore to tell qemu where do we
want the output of this pv console to go;
- do not setup pv console 0 on device/console/0 too.
Signed-off-by: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
diff -r 1644b4efef8a tools/libxl/libxl.c
--- a/tools/libxl/libxl.c Mon Aug 09 17:46:39 2010 +0100
+++ b/tools/libxl/libxl.c Mon Aug 09 17:51:18 2010 +0100
@@ -884,21 +884,31 @@ int libxl_domain_destroy(libxl_ctx *ctx,
return 0;
}
-int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num)
+int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num,
libxl_console_constype type)
{
char *p = libxl_sprintf(ctx, "%s/xenconsole", libxl_private_bindir_path());
char *domid_s = libxl_sprintf(ctx, "%d", domid);
char *cons_num_s = libxl_sprintf(ctx, "%d", cons_num);
- return execl(p, p, domid_s, "--num", cons_num_s, (void *)NULL) == 0 ? 0 :
ERROR_FAIL;
+ char *cons_type_s;
+
+ if (type == LIBXL_CONSTYPE_PV)
+ cons_type_s = "pv";
+ else
+ cons_type_s = "serial";
+ return execl(p, p, domid_s, "--num", cons_num_s, "--type", cons_type_s,
(void *)NULL) == 0 ? 0 : ERROR_FAIL;
}
int libxl_primary_console_exec(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);
+ return libxl_console_exec(ctx, stubdomid, 1, LIBXL_CONSTYPE_PV);
+ else {
+ if (is_hvm(ctx, domid_vm))
+ return libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSTYPE_SERIAL);
+ else
+ return libxl_console_exec(ctx, domid_vm, 0, LIBXL_CONSTYPE_PV);
+ }
}
int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass)
@@ -1450,14 +1460,21 @@ retry_transaction:
for (i = 0; i < num_console; i++) {
console[i].devid = i;
- console[i].constype = CONSTYPE_IOEMU;
+ console[i].consback = LIBXL_CONSBACK_IOEMU;
console[i].domid = domid;
- if (!i)
+ if (!i) {
+ char *filename;
+ char *name = libxl_sprintf(ctx, "qemu-dm-%s",
libxl_domid_to_name(ctx, info->domid));
+ libxl_create_logfile(ctx, name, &filename);
+ console[i].output = libxl_sprintf(ctx, "file:%s", filename);
console[i].build_state = &state;
+ free(filename);
+ } else
+ console[i].output = "pty";
ret = libxl_device_console_add(ctx, domid, &console[i]);
if (ret) return ret;
}
- if (libxl_create_xenpv_qemu(ctx, vfb, num_console, console, &dm_starting)
< 0) {
+ if (libxl_create_xenpv_qemu(ctx, domid, vfb, &dm_starting) < 0) {
free(args);
return ERROR_FAIL;
}
@@ -2136,7 +2153,7 @@ int libxl_device_console_add(libxl_ctx *
if (console->build_state) {
xs_transaction_t t;
- char **ents = (char **) libxl_calloc(ctx, 9, sizeof(char *));
+ char **ents = (char **) libxl_calloc(ctx, 11, sizeof(char *));
ents[0] = "console/port";
ents[1] = libxl_sprintf(ctx, "%"PRIu32,
console->build_state->console_port);
ents[2] = "console/ring-ref";
@@ -2144,16 +2161,19 @@ int libxl_device_console_add(libxl_ctx *
ents[4] = "console/limit";
ents[5] = libxl_sprintf(ctx, "%d", LIBXL_XENCONSOLE_LIMIT);
ents[6] = "console/type";
- if (console->constype == CONSTYPE_XENCONSOLED)
+ if (console->consback == LIBXL_CONSBACK_XENCONSOLED)
ents[7] = "xenconsoled";
else
ents[7] = "ioemu";
+ ents[8] = "console/output";
+ ents[9] = console->output;
retry_transaction:
t = xs_transaction_start(ctx->xsh);
libxl_xs_writev(ctx, t, libxl_xs_get_dompath(ctx, console->domid),
ents);
if (!xs_transaction_end(ctx->xsh, t, 0))
if (errno == EAGAIN)
goto retry_transaction;
+ return 0;
}
front = flexarray_make(16, 1);
@@ -2190,10 +2210,12 @@ retry_transaction:
flexarray_set(front, foffset++, "protocol");
flexarray_set(front, foffset++, LIBXL_XENCONSOLE_PROTOCOL);
flexarray_set(front, foffset++, "type");
- if (console->constype == CONSTYPE_XENCONSOLED)
+ if (console->consback == LIBXL_CONSBACK_XENCONSOLED)
flexarray_set(front, foffset++, "xenconsoled");
else
flexarray_set(front, foffset++, "ioemu");
+ flexarray_set(front, foffset++, "output");
+ flexarray_set(front, foffset++, console->output);
libxl_device_generic_add(ctx, &device,
libxl_xs_kvs_of_flexarray(ctx, back, boffset),
@@ -2384,64 +2406,39 @@ int libxl_cdrom_insert(libxl_ctx *ctx, u
/******************************************************************************/
static int libxl_build_xenpv_qemu_args(libxl_ctx *ctx,
+ uint32_t domid,
libxl_device_vfb *vfb,
- int num_console,
- libxl_device_console *console,
libxl_device_model_info *info)
{
- int i = 0, j = 0, num = 0;
memset(info, 0x00, sizeof(libxl_device_model_info));
- info->vnc = vfb->vnc;
- if (vfb->vnclisten)
- info->vnclisten = libxl_strdup(ctx, vfb->vnclisten);
- info->vncdisplay = vfb->vncdisplay;
- info->vncunused = vfb->vncunused;
- if (vfb->vncpasswd)
- info->vncpasswd = vfb->vncpasswd;
- if (vfb->keymap)
- info->keymap = libxl_strdup(ctx, vfb->keymap);
- info->sdl = vfb->sdl;
- info->opengl = vfb->opengl;
- for (i = 0; i < num_console; i++) {
- if (console->constype == CONSTYPE_IOEMU)
- num++;
- }
- if (num > 0) {
- uint32_t guest_domid;
- if (libxl_is_stubdom(ctx, vfb->domid, &guest_domid)) {
- char *filename;
- char *name = libxl_sprintf(ctx, "qemu-dm-%s",
libxl_domid_to_name(ctx, guest_domid));
- libxl_create_logfile(ctx, name, &filename);
- info->serial = libxl_sprintf(ctx, "file:%s", filename);
- free(filename);
- } else {
- info->serial = "pty";
- }
- num--;
- }
- if (num > 0) {
- info->extra = (char **) libxl_calloc(ctx, num * 2 + 1, sizeof(char *));
- for (j = 0; j < num * 2; j = j + 2) {
- info->extra[j] = "-serial";
- info->extra[j + 1] = "pty";
- }
- info->extra[j] = NULL;
- }
- info->domid = vfb->domid;
- info->dom_name = libxl_domid_to_name(ctx, vfb->domid);
+ if (vfb != NULL) {
+ info->vnc = vfb->vnc;
+ if (vfb->vnclisten)
+ info->vnclisten = libxl_strdup(ctx, vfb->vnclisten);
+ info->vncdisplay = vfb->vncdisplay;
+ info->vncunused = vfb->vncunused;
+ if (vfb->vncpasswd)
+ info->vncpasswd = vfb->vncpasswd;
+ if (vfb->keymap)
+ info->keymap = libxl_strdup(ctx, vfb->keymap);
+ info->sdl = vfb->sdl;
+ info->opengl = vfb->opengl;
+ } else
+ info->nographic = 1;
+ info->domid = domid;
+ info->dom_name = libxl_domid_to_name(ctx, domid);
info->device_model = libxl_abs_path(ctx, "qemu-dm", libxl_libexec_path());
info->type = XENPV;
return 0;
}
-int libxl_create_xenpv_qemu(libxl_ctx *ctx, libxl_device_vfb *vfb,
- int num_console, libxl_device_console *console,
+int libxl_create_xenpv_qemu(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb
*vfb,
libxl_device_model_starting **starting_r)
{
libxl_device_model_info info;
- libxl_build_xenpv_qemu_args(ctx, vfb, num_console, console, &info);
+ libxl_build_xenpv_qemu_args(ctx, domid, vfb, &info);
libxl_create_device_model(ctx, &info, NULL, 0, NULL, 0, starting_r);
return 0;
}
diff -r 1644b4efef8a tools/libxl/libxl.h
--- a/tools/libxl/libxl.h Mon Aug 09 17:46:39 2010 +0100
+++ b/tools/libxl/libxl.h Mon Aug 09 17:51:18 2010 +0100
@@ -229,16 +229,22 @@ typedef struct {
} libxl_device_vkb;
typedef enum {
- CONSTYPE_XENCONSOLED,
- CONSTYPE_IOEMU,
+ LIBXL_CONSTYPE_SERIAL,
+ LIBXL_CONSTYPE_PV,
} libxl_console_constype;
+typedef enum {
+ LIBXL_CONSBACK_XENCONSOLED,
+ LIBXL_CONSBACK_IOEMU,
+} libxl_console_consback;
+
typedef struct {
uint32_t backend_domid;
uint32_t domid;
int devid;
- libxl_console_constype constype;
+ libxl_console_consback consback;
libxl_domain_build_state *build_state;
+ char *output;
} libxl_device_console;
typedef enum {
@@ -436,7 +442,7 @@ int libxl_domain_setmaxmem(libxl_ctx *ct
int libxl_set_memory_target(libxl_ctx *ctx, uint32_t domid, uint32_t
target_memkb, int enforce);
int libxl_vncviewer_exec(libxl_ctx *ctx, uint32_t domid, int autopass);
-int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num);
+int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num,
libxl_console_constype type);
/* 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
@@ -458,8 +464,7 @@ int libxl_create_device_model(libxl_ctx
libxl_device_disk *disk, int num_disks,
libxl_device_nic *vifs, int num_vifs,
libxl_device_model_starting **starting_r);
-int libxl_create_xenpv_qemu(libxl_ctx *ctx, libxl_device_vfb *vfb,
- int num_console, libxl_device_console *console,
+int libxl_create_xenpv_qemu(libxl_ctx *ctx, uint32_t domid, libxl_device_vfb
*vfb,
libxl_device_model_starting **starting_r);
/* Caller must either: pass starting_r==0, or on successful
* return pass *starting_r (which will be non-0) to
diff -r 1644b4efef8a tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c Mon Aug 09 17:46:39 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c Mon Aug 09 17:51:18 2010 +0100
@@ -370,7 +370,8 @@ static void init_console_info(libxl_devi
{
memset(console, 0x00, sizeof(libxl_device_console));
console->devid = dev_num;
- console->constype = CONSTYPE_XENCONSOLED;
+ console->consback = LIBXL_CONSBACK_XENCONSOLED;
+ console->output = "pty";
if (state)
console->build_state = state;
}
@@ -1440,6 +1441,7 @@ start:
if (d_config.c_info.hvm) {
init_console_info(&console, 0, &state);
console.domid = domid;
+ console.consback = LIBXL_CONSBACK_IOEMU;
libxl_device_console_add(&ctx, domid, &console);
dm_info.domid = domid;
MUST( libxl_create_device_model(&ctx, &dm_info,
@@ -1456,10 +1458,10 @@ start:
init_console_info(&console, 0, &state);
console.domid = domid;
if (d_config.num_vfbs)
- console.constype = CONSTYPE_IOEMU;
+ console.consback = LIBXL_CONSBACK_IOEMU;
libxl_device_console_add(&ctx, domid, &console);
if (d_config.num_vfbs)
- libxl_create_xenpv_qemu(&ctx, d_config.vfbs, 1, &console,
&dm_starting);
+ libxl_create_xenpv_qemu(&ctx, domid, d_config.vfbs, &dm_starting);
}
if (dm_starting)
@@ -1854,13 +1856,27 @@ int main_cd_insert(int argc, char **argv
int main_console(int argc, char **argv)
{
- int opt = 0;
-
- while ((opt = getopt(argc, argv, "hn:")) != -1) {
+ int opt = 0, num = 0;
+ libxl_console_constype type = -1;
+
+ while ((opt = getopt(argc, argv, "hn:t:")) != -1) {
switch (opt) {
case 'h':
help("console");
return 0;
+ case 't':
+ if (!strcmp(optarg, "pv"))
+ type = LIBXL_CONSTYPE_PV;
+ else if (!strcmp(optarg, "serial"))
+ type = LIBXL_CONSTYPE_SERIAL;
+ else {
+ fprintf(stderr, "console type supported are: pv, serial\n");
+ return 2;
+ }
+ break;
+ case 'n':
+ num = atoi(optarg);
+ break;
default:
fprintf(stderr, "option not supported\n");
break;
@@ -1872,7 +1888,10 @@ int main_console(int argc, char **argv)
}
find_domain(argv[optind]);
- libxl_primary_console_exec(&ctx, domid);
+ if (type <= 0 && num == 0)
+ libxl_primary_console_exec(&ctx, domid);
+ else
+ libxl_console_exec(&ctx, domid, num, type);
fprintf(stderr, "Unable to attach console\n");
return 1;
}
diff -r 1644b4efef8a tools/libxl/xl_cmdtable.c
--- a/tools/libxl/xl_cmdtable.c Mon Aug 09 17:46:39 2010 +0100
+++ b/tools/libxl/xl_cmdtable.c Mon Aug 09 17:51:18 2010 +0100
@@ -86,7 +86,9 @@ struct cmd_spec cmd_table[] = {
{ "console",
&main_console,
"Attach to domain's console",
- "<Domain>",
+ "[options] <Domain>\n"
+ "-t <type> console type, pv or serial\n"
+ "-n <number> console number"
},
{ "vncviewer",
&main_vncviewer,
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|