[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] [PATCH] libxl: Add API to retrieve domain console tty



On Mon, 2012-05-21 at 12:07 +0100, Bamvor Jian Zhang wrote:
> This api retrieve domain console from xenstore. With this new api, it is easy 
> to implement "virsh console" command in libvirt libxl driver.
> 
> Signed-off-by: Bamvor Jian Zhang <bjzhang@xxxxxxxx>
> 
> diff -r f8279258e3c9 -r a1dc373628e4 tools/libxl/libxl.c
> --- a/tools/libxl/libxl.c     Mon May 14 17:15:36 2012 +0100
> +++ b/tools/libxl/libxl.c     Mon May 21 18:51:17 2012 +0800
> @@ -1552,6 +1552,61 @@ out:
>      return rc;
>  }
>  
> +int libxl_console_get_tty(libxl_ctx *ctx, uint32_t domid, int cons_num, 
> +                          libxl_console_type type, char **path)
> +{
> +    GC_INIT(ctx);
> +    char *dom_path = 0;
> +    char *tty_path = 0;
> +    char *tty = 0;
> +
> +    dom_path = libxl__xs_get_dompath(gc, domid);
> +    switch (type) {
> +    case LIBXL_CONSOLE_TYPE_SERIAL:
> +        tty_path = libxl__sprintf(gc, "%s/serial/0/tty", dom_path);
> +        break;
> +    case LIBXL_CONSOLE_TYPE_PV:
> +        if (cons_num == 0)
> +            tty_path = libxl__sprintf(gc, "%s/console/tty", dom_path);
> +        else
> +            tty_path = libxl__sprintf(gc, "%s/device/console/%d/tty", 
> dom_path, cons_num);
> +        break;
> +    default:
> +        goto out;

This should result in ERROR_INVAL.

> +    }
> +
> +    tty = libxl__xs_read(gc, XBT_NULL, tty_path);
> +    *path = strdup(tty);
> +
> +out:
> +    GC_FREE;
> +    return ERROR_FAIL;

There does not appear to be a success path out of this function... You
probably want an rc variable set appropriately.

> +}
> +
> +int libxl_primary_console_get_tty(libxl_ctx *ctx, uint32_t domid_vm, char 
> **path)
> +{
> +    GC_INIT(ctx);
> +    uint32_t stubdomid = libxl_get_stubdom_id(ctx, domid_vm);
> +    int rc;
> +    if (stubdomid)
> +        rc = libxl_console_get_tty(ctx, stubdomid,
> +                STUBDOM_CONSOLE_SERIAL, LIBXL_CONSOLE_TYPE_PV, path);
> +    else {
> +        switch (libxl__domain_type(gc, domid_vm)) {
> +        case LIBXL_DOMAIN_TYPE_HVM:
> +            rc = libxl_console_get_tty(ctx, domid_vm, 0, 
> LIBXL_CONSOLE_TYPE_SERIAL, path);
> +            break;
> +        case LIBXL_DOMAIN_TYPE_PV:
> +            rc = libxl_console_get_tty(ctx, domid_vm, 0, 
> LIBXL_CONSOLE_TYPE_PV, path);
> +            break;
> +        default:
> +            abort();
> +        }
> +    }
> +    GC_FREE;
> +    return rc;
> +}
> +
>  
>  static int libxl__append_disk_list_of_type(libxl__gc *gc,
>                                             uint32_t domid,
> diff -r f8279258e3c9 -r a1dc373628e4 tools/libxl/libxl.h
> --- a/tools/libxl/libxl.h     Mon May 14 17:15:36 2012 +0100
> +++ b/tools/libxl/libxl.h     Mon May 21 18:51:17 2012 +0800
> @@ -594,6 +594,15 @@ int libxl_console_exec(libxl_ctx *ctx, u
>   * case of HVM guests, and before libxl_run_bootloader in case of PV
>   * guests using pygrub. */
>  int libxl_primary_console_exec(libxl_ctx *ctx, uint32_t domid_vm);
> +/* libxl_console_get_tty retrieves the specified domain's console tty path
> + * and stores it in path. Caller is responsible for freeing the memory.
> + */
> +int libxl_console_get_tty(libxl_ctx *ctx, uint32_t domid, int cons_num, 
> +                          libxl_console_type type, char **path);
> +/* libxl_primary_console_get_tty retrieves the specified domain's console 
> tty 
> + * path and stores it in path.

"retrieves the specified domain's *primary* console tty path? Otherwise
this description doesn't differ from the previous function's...

>  Caller is responsible for freeing the memory.
> + */
> +int libxl_primary_console_get_tty(libxl_ctx *ctx, uint32_t domid_vm, char 
> **path);
>  
>  /* May be called with info_r == NULL to check for domain's existance */
>  int libxl_domain_info(libxl_ctx*, libxl_dominfo *info_r,



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.