Support user domain create extensions
PATCH 1/1 Support user domain create extensions
This patch supports arbitrary extensions to xl create by being able to specify a script which is run at domain creation. The script is specified in the xl config file and will be started at domain creation with following parameters:
<script> restore|create <domid> <path of config file>
To be able to use non-standard devices a new device class "NSTD" is defined. The xl framework will remove all NSTD devices when destroying a domain.
This extension enables us (Fujitsu) to use standard Xen with xl for our Xen-based mainframe with BS2000 as DomU (this requires an additional Xen PV-device emulating the BS2000 I/O-system).
It might be interesting for others as well to be able to add new experimental devices or other features to Xen without having to change Xen (especially xl) itself.
7 files changed, 65 insertions(+) tools/examples/xl.conf | 11 +++++++++++ tools/libxl/libxl.h | 3 +++ tools/libxl/libxl_dom.c | 16 ++++++++++++++++ tools/libxl/libxl_types_internal.idl | 1 + tools/libxl/xl.c | 5 +++++ tools/libxl/xl.h | 1 + tools/libxl/xl_cmdimpl.c | 28 ++++++++++++++++++++++++++++
# HG changeset patch
# User Juergen Gross <[email protected]> # Date 1352886719 -3600
# Node ID 7c02a22ef82161c3930f996785b0a2565dba4c56 # Parent 8b93ac0c93f3fb8a140b4688ba71841ac927d4e3 Support user domain create extensions
This patch supports arbitrary extensions to xl create by being able to specify a script which is run at domain creation. The script is specified in the xl config file and will be started at domain creation with following parameters:
<script> restore|create <domid> <path of config file>
To be able to use non-standard devices a new device class "NSTD" is defined. The xl framework will remove all NSTD devices when destroying a domain.
This extension enables us (Fujitsu) to use standard Xen with xl for our Xen-based mainframe with BS2000 as DomU (this requires an additional Xen PV-device emulating the BS2000 I/O-system).
It might be interesting for others as well to be able to add new experimental devices or other features to Xen without having to change Xen (especially xl) itself.
tools/examples/xl.conf +11 -0
@@ -20,3 +20,14 @@ # if disabled the old behaviour will be used, and hotplug scripts will be # launched by udev. #run_hotplug_scripts=1 + +# additional script called on domain creation +# the script must be located in xl script directory. +# Arguments passed: +# <domain_create_script> restore|create <domid> <domain config file> +# restore|create restore: domain created by restore or migration action +# create: domain created by xl create +# <domid> +# <domain config file> full path to domain config file stored by xl +# If the script returns an exit code != 0, domain creation will by aborted. +#domain_create_script=
tools/libxl/libxl.h +3 -0
@@ -875,6 +875,9 @@ int libxl_userdata_retrieve(libxl_ctx *c* data_r and datalen_r may be 0. * On error return, *data_r and *datalen_r are undefined. */ +const char *libxl_userdata_path (libxl_ctx *ctx,uint32_t domid, +const char *userdata_userid, +const char *wh);int libxl_get_physinfo (libxl_ctx *ctx,libxl_physinfo *physinfo); int libxl_set_vcpuaffinity(libxl_ctx *ctx, uint32_t domid, uint32_t vcpuid,
tools/libxl/libxl_dom.c +16 -0
@@ -1508,6 +1508,22 @@ out:return ; } +const char *libxl_userdata_path (libxl_ctx *ctx,uint32_t domid, +const char *userdata_userid, +const char *wh) +{ +GC_INIT (ctx); +const char *path; + + path =userdata_path (gc, domid, userdata_userid,"d" ); +if (path) { + path =strdup (path); + } + +GC_FREE ; +return path; +} +int libxl_userdata_store (libxl_ctx *ctx,uint32_t domid,const char *userdata_userid,const uint8_t *data,int datalen)
tools/libxl/libxl_types_internal.idl +1 -0
@@ -20,6 +20,7 @@ libxl__device_kind = Enumeration("device (6, "VKBD"), (7, "CONSOLE"), (8, "VTPM"), + (9, "NSTD"), ]) libxl__console_backend = Enumeration("console_backend", [
tools/libxl/xl.c +5 -0
@@ -43,6 +43,7 @@ char *lockfile;char *lockfile;char *default_vifscript =NULL ;char *default_bridge =NULL ; +char *domain_create_script =NULL ;enum output_format default_output_format =OUTPUT_FORMAT_JSON ;static xentoollog_level minmsglevel =XTL_PROGRESS ;
@@ -102,6 +103,10 @@ static void parse_global_config(const ch }if (!xlu_cfg_get_string (config,"blkdev_start" , &buf,0 )) blkdev_start =strdup (buf); + +if (!xlu_cfg_get_string (config,"domain_create_script" , &buf,0 )) + domain_create_script =strdup (buf); +xlu_cfg_destroy (config); }
tools/libxl/xl.h +1 -0
@@ -149,6 +149,7 @@ extern char *default_vifscript;extern char *default_vifscript;extern char *default_bridge;extern char *blkdev_start; +extern char *domain_create_script;enum output_format {OUTPUT_FORMAT_JSON ,
tools/libxl/xl_cmdimpl.c +28 -0
@@ -1806,6 +1806,8 @@ static uint32_t create_domain(struct domint status =0 ;const libxl_asyncprogress_how *autoconnect_console_how;struct save_file_header hdr; + +char *domain_create_cmdline;int restoring = (restore_file || (migrate_fd >=0 ));
@@ -2020,6 +2022,32 @@ start:perror ("cannot save config file" ); ret =ERROR_FAIL ; goto error_out; + } + +if (domain_create_script) { +const char *conf; + +/* call additional domain create script +<script> restore|create <domid> <path of config file> +*/ + conf =libxl_userdata_path (ctx, domid,"xl" ,"d" ); +if (!conf) { +fprintf (stderr,"no config file found\n" ); + ret =ERROR_FAIL ; + goto error_out; + } +asprintf (&domain_create_cmdline,"%s/%s %s %d %s" , +XEN_SCRIPT_DIR , domain_create_script, + restoring ?"restore" :"create" , + domid, conf); + + ret =system (domain_create_cmdline); + +if (ret) { +perror ("domain create script failed" ); + ret =ERROR_FAIL ; + goto error_out; + } }release_lock ();
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Juergen Gross writes ("[Xen-devel] [PATCH] Support user domain create extensions"):
Quoted 6 lines
This patch supports arbitrary extensions to xl create by being able to specify a script which is run at domain creation. The script is specified in the xl config file and will be started at domain creation with following parameters:
<script> restore|create <domid> <path of config file>
Thanks. I think this is a reasonable idea.
I wonder if this might be profitably moved down into libxl.
Also the interface needs work. At the very least there needs to be a corresponding "destroy" script invocation.
Quoted 2 lines
To be able to use non-standard devices a new device class "NSTD" is defined. The xl framework will remove all NSTD devices when destroying a domain.
Did I miss the implementation of this ?
tools/libxl/libxl_dom.c out: · line 1513
Quoted 3 lines
tools/libxl/libxl_dom.c +3
-0+const char *libxl_userdata_path (libxl_ctx *ctx,uint32_t domid, +const char *userdata_userid, +const char *wh)
I don't think this is correct. We shouldn't be exposing the userdata path like this. But anyway if we are moving this into libxl then the config file won't be exposed to the script anyway.
What does your script need the config file for ? Writing a separate parser for it is clearly a mistake...
Ian.
Am 16.11.2012 16:48, schrieb Ian Jackson:
Quoted 10 lines
Juergen Gross writes ("[Xen-devel] [PATCH] Support user domain create extensions"):
Quoted 6 lines
This patch supports arbitrary extensions to xl create by being able to specify a script which is run at domain creation. The script is specified in the xl config file and will be started at domain creation with following parameters:
<script> restore|create<domid> <path of config file>
Thanks. I think this is a reasonable idea.
I wonder if this might be profitably moved down into libxl.
Okay, I'll try it.
Quoted 3 lines
Also the interface needs work. At the very least there needs to be a corresponding "destroy" script invocation.
Sounds reasonable.
Quoted 5 lines
Quoted 3 lines
To be able to use non-standard devices a new device class "NSTD" is defined. The xl framework will remove all NSTD devices when destroying a domain.
Did I miss the implementation of this ?
I haven't tested it myself. I thought libxl will cycle through all known device classes in the xenstore modifying the backend state of the devices connected to the domain. This should do the job. Have I missed something?
Quoted 11 lines
tools/libxl/libxl_dom.c out: · line 1513
Quoted 4 lines
tools/libxl/libxl_dom.c +3
-0+const char *libxl_userdata_path (libxl_ctx *ctx,uint32_t domid, +const char *userdata_userid, +const char *wh)I don't think this is correct. We shouldn't be exposing the userdata path like this. But anyway if we are moving this into libxl then the config file won't be exposed to the script anyway.
What does your script need the config file for ? Writing a separate parser for it is clearly a mistake...
We want to be able to:
- specify parameters for our NSTD device per domain
- make sure a domain with a NSTD device is started in the correct cpupool (license restriction)
So we need a way to access domain configuration parameters. There are some other ways to do this, using the config file was the most simple one. I could think of following alternatives:
- add a new xl subcommand to get a configuration parameter of a domain, e.g. xl domain-par <domain> <parameter>
- specify parameters of interest in the xl config file. Those parameters will be made available to the script via shell variables. Something like:
domain_create_script_pars="cpupool nstd_device"
leading to shell variables XLPAR_cpupool and XLPAR_nstd_device to be set to the correct values when invoking the script.
Juergen
Signature · 5 lines
Juergen Gross Principal Developer Operating Systems PBG PDG ES&S SWE OS6 Telephone: +49 (0) 89 3222 2967 Fujitsu Technology Solutions e-mail: [email protected] Domagkstr. 28 Internet: ts.fujitsu.com D-80807 Muenchen Company details: ts.fujitsu.com/imprint.html