multiconsole support in xenconsole, xenconsoled and libxl
PATCH 1/1 multiconsole support in xenconsole, xenconsoled and libxl
multiple consoles support in xenconsole, xenconsoled and libxl
This patch implements the new protocol for handling pv consoles and emulated serials as described in the document docs/misc/console.txt.
The changes are:
- xenconsoled: do not write the pty under serial in xenstore if xenconsoled is handling a consolepath;
- xenconsole: implement support for an explicit console type parameter; the parameter can be "pv", to specify that the user wants to connect to a pv console, or "serial", to specify that the user wants to connect to an emulated serial. If the type parameter hasn't been specified be the user, xenconsole tries to guess which type of console it has to connect to, defaulting to pv console for pv guests and emulated serial for hvm guests.
- xenconsole: use the new xenstore paths;
- libxl: 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;
- libxl: add a new libxl_console_constype to specify if the console is an emulated serial or a pv console;
- libxl: support the new xenconsole "type" command line parameter;
- libxl: use the "output" node under console in xenstore to tell qemu where do we want the output of this pv console to go;
---
docs/misc/console.txt new file +91 -0
@@ -0,0 +1,91 @@ +Xen PV Console notes +------------------------------------------------------------------------ + Stefano Stabellini + [email protected] + + +Xen traditionally provided a single pv console to pv guests, storing the +relevant information in xenstore under /local/domain/$DOMID/console. + +Now many years after the introduction of the pv console we have +multiple pv consoles support for pv and hvm guests; multiple pv +console backends (qemu and xenconsoled) and emulated serial cards too. + +This document tries to describe how the whole system works and how the +different components interact with each others. + +The first PV console path in xenstore remains: + +/local/domain/$DOMID/console + +the other PV consoles follow the conventional xenstore device path and +live in: + +/local/domain/$DOMID/device/console/$DEVID. + +The output of a PV console, whether it should be a file, a pty, a +socket, or something else, is specified by the toolstack in the xenstore +node "output", under the relevant console section. +For example: + +# xenstore-read /local/domain/26/device/console/1/output +pty + +The backend chosen for a particular console is specified by the +toolstack in the "type" node on xenstore, under the relevant console +section. +For example: + +# xenstore-read /local/domain/26/console/type +xenconsoled + +The supported values are only xenconsoled or ioemu; xenconsoled has +several limitations: it can only be used for the first PV console and it +can only have a pty as output. + +If the output is a pty, backends write the device name to the "tty" node +in xenstore under the relevant console path. + +Emulated serials are provided by qemu-dm only to hvm guests; the number +of emulated serials depends on how many "-serial" command line options +are given to qemu. The output of a serial is specified as argument to +the -serial command line option to qemu. Qemu writes the tty name to +xenstore in the following path: + +/local/domain/$DOMID/serial/$SERIAL_NUM/tty + + +xenconsole is the tool to connect to a PV console or an emulated serial +that has a pty as output. Xenconsole takes a domid as parameter plus an +optional console type (pv for PV consoles or serial for emulated +serials) and console number. Depending on the type and console +number, xenconsole will look for the tty node in different xenstore +paths, as described above. If the user doesn't specify the console type +xenconsole will try to guess: if the guest is a pv guest it defaults to +PV console, if the guest is an hvm guest it defaults to emulated serial. + +By default xl creates a pv console for hvm guests, plus an emulated +serial if the user specified 'serial = "pty"' in the VM config file. +Considering that xenconsole defaults to emulated serials for hvm guests, +executing xl create -c "domain" causes xenconsole to attach to the +emulated serial tty. This is most probably what the user wanted because +currently no bootloaders support xen pv consoles so the only way to +interact with a bootloader like grub over a console is to use the +emulated serial. +However the pv console is still easy to use with Linux PV on HVM guests: +the user just need to pass "console=hvc0" to the kernel command line and +then execute "xl console -t pv <domain>" to connect to it. + +When using stubdoms the serial cards are still emulated by qemu (this +time running in the stubdom), the number of serial cards and where the +output goes is still specified using qemu command line options. +The difference is that for each emulated serial card there must be a pv +console connection between the stubdom and dom0 to export the serial +output from the stubdom to dom0. The pv console backend for stubdom's pv +consoles is always ioemu because multiple pv consoles support is a +requirement in this case, considering that minios has its own pv console +too. In order to simplify the setup when using stubdoms the hvm guest +can only have one pv console with xenstored as backend (the stubdom +could provide pv console backends to the hvm guest but then it would +need another pv console connection for each console backend to export +the pty to dom0).
tools/console/client/main.c +42 -2
82 lines not on this page · raw message
tools/console/daemon/io.c +17 -21
@@ -451,27 +451,6 @@ static int domain_create_tty(struct domafree (data); }free (path); - } - - success =asprintf (&path,"%s/limit" , dom->serialpath) !=-1 ; -if (!success) - goto out; - data =xs_read (xs,XBT_NULL , path, &len); -if (data) { - dom->buffer.max_capacity =strtoul (data,0 ,0 ); -free (data); - } -free (path); - - success =asprintf (&path,"%s/tty" , dom->serialpath) !=-1 ; -if (!success) - goto out; - success =xs_write (xs,XBT_NULL , path, slave,strlen (slave)); -free (path); -if (!success) - goto out; - -if (dom->use_consolepath) { success = (asprintf (&path,"%s/tty" , dom->conspath) !=-1 );if (!success) goto out;
@@ -479,6 +458,23 @@ static int domain_create_tty(struct domafree (path);if (!success) goto out; + }else { + success =asprintf (&path,"%s/limit" , dom->serialpath) !=-1 ; +if (!success) + goto out; + data =xs_read (xs,XBT_NULL , path, &len); +if (data) { + dom->buffer.max_capacity =strtoul (data,0 ,0 ); +free (data); + } +free (path); + success =asprintf (&path,"%s/tty" , dom->serialpath) !=-1 ; +if (!success) + goto out; + success =xs_write (xs,XBT_NULL , path, slave,strlen (slave)); +free (path); +if (!success) + goto out; }if (fcntl (dom->master_fd,F_SETFL ,O_NONBLOCK ) ==-1 )
tools/libxl/libxl.c +54 -56
186 lines not on this page · raw message
tools/libxl/libxl.h +11 -6
@@ -225,16 +225,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 {
@@ -432,7 +438,7 @@ int libxl_domain_setmaxmem(libxl_ctx *ctint 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
@@ -454,8 +460,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
tools/libxl/xl_cmdimpl.c +25 -7
@@ -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; }
@@ -1456,10 +1457,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 +1855,27 @@ int main_cd_insert(int argc, char **argvint 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 +1887,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 ; }
tools/libxl/xl_cmdtable.c +3 -1
@@ -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,
tools/ocaml/libs/xl/xl_stubs.c +1 -1
@@ -232,7 +232,7 @@ static int device_console_val(caml_gc *g c_val->backend_domid =Int_val (Field (v,0 )); c_val->devid =Int_val (Field (v,1 )); - c_val->constype = (Int_val (Field (v,2 ))) +CONSTYPE_XENCONSOLED ; + c_val->consback = (Int_val (Field (v,2 ))) +LIBXL_CONSBACK_XENCONSOLED ;CAMLreturn (0 ); }
Quoted 28 lines · Stefano Stabellini
multiple consoles support in xenconsole, xenconsoled and libxl
This patch implements the new protocol for handling pv consoles and emulated serials as described in the document
docs/misc/console.txt.The changes are:
- xenconsoled: do not write the pty under serial in xenstore if xenconsoled is handling a consolepath;
- xenconsole: implement support for an explicit console type parameter; the parameter can be "pv", to specify that the user wants to connect to a pv console, or "serial", to specify that the user wants to connect to an emulated serial. If the type parameter hasn't been specified be the user, xenconsole tries to guess which type of console it has to connect to, defaulting to pv console for pv guests and emulated serial for hvm guests.
- xenconsole: use the new xenstore paths;
- libxl: rename
libxl_console_constypetolibxl_console_consback:
constype is used to to specify whether qemu or xenconsoled provides the backend, so I renamed it tolibxl_console_consbackto make it more obvious that we are talking about backends;- libxl: add a new
libxl_console_constypeto specify if the console is an emulated serial or a pv console;
Quoted 7 lines
- libxl: support the new xenconsole "type" command line parameter;
- libxl: use the "output" node under console in xenstore to tell qemu where do we want the output of this pv console to go;
Signed-off-by Stefano Stabellini <[email protected]>
this patch didn't apply cleanly to xen-unstable tip: I am appending a rebased version of the patch with one additional change:
- remove the legacy "serialpath" from xenconsoled altogether
---
docs/misc/console.txt new file +91 -0
@@ -0,0 +1,91 @@ +Xen PV Console notes +------------------------------------------------------------------------ + Stefano Stabellini + [email protected] + + +Xen traditionally provided a single pv console to pv guests, storing the +relevant information in xenstore under /local/domain/$DOMID/console. + +Now many years after the introduction of the pv console we have +multiple pv consoles support for pv and hvm guests; multiple pv +console backends (qemu and xenconsoled) and emulated serial cards too. + +This document tries to describe how the whole system works and how the +different components interact with each others. + +The first PV console path in xenstore remains: + +/local/domain/$DOMID/console + +the other PV consoles follow the conventional xenstore device path and +live in: + +/local/domain/$DOMID/device/console/$DEVID. + +The output of a PV console, whether it should be a file, a pty, a +socket, or something else, is specified by the toolstack in the xenstore +node "output", under the relevant console section. +For example: + +# xenstore-read /local/domain/26/device/console/1/output +pty + +The backend chosen for a particular console is specified by the +toolstack in the "type" node on xenstore, under the relevant console +section. +For example: + +# xenstore-read /local/domain/26/console/type +xenconsoled + +The supported values are only xenconsoled or ioemu; xenconsoled has +several limitations: it can only be used for the first PV console and it +can only have a pty as output. + +If the output is a pty, backends write the device name to the "tty" node +in xenstore under the relevant console path. + +Emulated serials are provided by qemu-dm only to hvm guests; the number +of emulated serials depends on how many "-serial" command line options +are given to qemu. The output of a serial is specified as argument to +the -serial command line option to qemu. Qemu writes the tty name to +xenstore in the following path: + +/local/domain/$DOMID/serial/$SERIAL_NUM/tty + + +xenconsole is the tool to connect to a PV console or an emulated serial +that has a pty as output. Xenconsole takes a domid as parameter plus an +optional console type (pv for PV consoles or serial for emulated +serials) and console number. Depending on the type and console +number, xenconsole will look for the tty node in different xenstore +paths, as described above. If the user doesn't specify the console type +xenconsole will try to guess: if the guest is a pv guest it defaults to +PV console, if the guest is an hvm guest it defaults to emulated serial. + +By default xl creates a pv console for hvm guests, plus an emulated +serial if the user specified 'serial = "pty"' in the VM config file. +Considering that xenconsole defaults to emulated serials for hvm guests, +executing xl create -c "domain" causes xenconsole to attach to the +emulated serial tty. This is most probably what the user wanted because +currently no bootloaders support xen pv consoles so the only way to +interact with a bootloader like grub over a console is to use the +emulated serial. +However the pv console is still easy to use with Linux PV on HVM guests: +the user just need to pass "console=hvc0" to the kernel command line and +then execute "xl console -t pv <domain>" to connect to it. + +When using stubdoms the serial cards are still emulated by qemu (this +time running in the stubdom), the number of serial cards and where the +output goes is still specified using qemu command line options. +The difference is that for each emulated serial card there must be a pv +console connection between the stubdom and dom0 to export the serial +output from the stubdom to dom0. The pv console backend for stubdom's pv +consoles is always ioemu because multiple pv consoles support is a +requirement in this case, considering that minios has its own pv console +too. In order to simplify the setup when using stubdoms the hvm guest +can only have one pv console with xenstored as backend (the stubdom +could provide pv console backends to the hvm guest but then it would +need another pv console connection for each console backend to export +the pty to dom0).
tools/console/client/main.c +42 -2
82 lines not on this page · raw message
tools/console/daemon/io.c +13 -62
139 lines not on this page · raw message
tools/libxl/libxl.c +54 -56
186 lines not on this page · raw message
tools/libxl/libxl.h +11 -6
@@ -335,16 +335,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 {
@@ -542,7 +548,7 @@ int libxl_domain_setmaxmem(libxl_ctx *ctint 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
@@ -564,8 +570,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
tools/libxl/xl_cmdimpl.c +25 -7
@@ -371,7 +371,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; }
@@ -1457,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)
@@ -1855,13 +1856,27 @@ int main_cd_insert(int argc, char **argvint 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 ;
@@ -1873,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 ; }
tools/libxl/xl_cmdtable.c +3 -1
@@ -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,
tools/ocaml/libs/xl/xl_stubs.c +1 -1
@@ -232,7 +232,7 @@ static int device_console_val(caml_gc *g c_val->backend_domid =Int_val (Field (v,0 )); c_val->devid =Int_val (Field (v,1 )); - c_val->constype = (Int_val (Field (v,2 ))) +CONSTYPE_XENCONSOLED ; + c_val->consback = (Int_val (Field (v,2 ))) +LIBXL_CONSBACK_XENCONSOLED ;CAMLreturn (0 ); }