Using "xl create" without domain config file
I found it useful to use xm without a domain configuration file:
xm create /dev/null kernel=...
The xl command does not support this. See a previous thread I started:
http://lists.xen.org/archives/html/xen-devel/2011-08/msg00330.html
I just found the time to modify xl so that it works without a domain configuration file. For example:
xl create kernel=\"...\" ...
Would it be possible to add this feature? The xl command already supports augmenting a domain configuration file with additional information from the command line. My changes just modify xl so that the entire configuration may be specified on the command line.
To test this patch, run:
1. xl create -c /path/to/config
2. xl create -c /path/to/config someAdditionalDomainParam=\"value\"
3. xl create -c kernel=\"/path/to/kernel\"
The third test covers the new case.
Signature · 3 lines
Mike :wq
tools/libxl/xl_cmdimpl.c +19 -17
@@ -1442,30 +1442,32 @@ &config_data, &config_len);if (ret) {fprintf (stderr,"Failed to read config file: %s: %s\n" , config_file,strerror (errno));return ERROR_FAIL ; } -if (!restore_file && extra_config &&strlen (extra_config)) { -if (config_len >INT_MAX - (strlen (extra_config) +2 +1 )) { -fprintf (stderr,"Failed to attach extra configration\n" ); -return ERROR_FAIL ; - } -/* allocate space for the extra config plus two EOLs plus \0 */ - config_data =realloc (config_data, config_len - +strlen (extra_config) +2 +1 ); -if (!config_data) { -fprintf (stderr,"Failed to realloc config_data\n" ); -return ERROR_FAIL ; - } - config_len +=sprintf (config_data + config_len,"\n%s\n" , - extra_config); - } }else { -if (!config_data) { -fprintf (stderr,"Config file not specified and" +if (!config_data && !extra_config) { +fprintf (stderr,"Domain config file not specified," +" none on command line, and" " none in save file\n" );return ERROR_INVAL ; } config_file ="<saved>" ; } +if (!restore_file && extra_config &&strlen (extra_config)) { +if (config_len >INT_MAX - (strlen (extra_config) +2 +1 )) { +fprintf (stderr,"Failed to attach extra configration\n" ); +return ERROR_FAIL ; + } +/* allocate space for the extra config plus two EOLs plus \0 */ + config_data =realloc (config_data, config_len + +strlen (extra_config) +2 +1 ); +if (!config_data) { +fprintf (stderr,"Failed to realloc config_data\n" ); +return ERROR_FAIL ; + } + config_len +=sprintf (config_data + config_len,"\n%s\n" , + extra_config); + } +if (!dom_info->quiet)printf ("Parsing config file %s\n" , config_file);
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 20 lines · W. Michael Petullo
I found it useful to use xm without a domain configuration file:
xm create
/dev/nullkernel=...The xl command does not support this. See a previous thread I started:
http://lists.xen.org/archives/html/xen-devel/2011-08/msg00330.htmlI just found the time to modify xl so that it works without a domain configuration file. For example:
xl create kernel=\"...\" ...Would it be possible to add this feature? The xl command already supports augmenting a domain configuration file with additional information from the command line. My changes just modify xl so that the entire configuration may be specified on the command line.
To test this patch, run:
Quoted 7 lines
1. xl create -c /path/to/config
2. xl create -c /path/to/config someAdditionalDomainParam=\"value\"
3. xl create -c kernel=\"/path/to/kernel\"
The third test covers the new case.
Does #3 actually work? I ask because name=".." is mandatory...
Please can you supply a proposed commit message including a signed-off-by as per http://wiki.xen.org/wiki/Submitting_Xen_Patches
Please can you also check that docs/man/xl*.pod do not need updating after this change.
Ian.
W. Michael Petullo writes ("[Xen-devel] Using "xl create" without domain config file"):
Quoted 7 lines
I found it useful to use xm without a domain configuration file:
xm create
/dev/nullkernel=...The xl command does not support this. See a previous thread I started:
http://lists.xen.org/archives/html/xen-devel/2011-08/msg00330.html
I would be happy to support the /dev/null form.
Quoted 4 lines
I just found the time to modify xl so that it works without a domain configuration file. For example:
xl create kernel=\"...\" ...
This, however, is ambiguous. It's not clear from your patch below how this ambiguity is resolved but I don't think what you've done can be sufficient in itself.
What if the domain config filename contains a `=' ?
Ian.
Quoted 9 lines
Quoted 7 lines
I found it useful to use xm without a domain configuration file:
xm create
/dev/nullkernel=...The xl command does not support this. See a previous thread I started:
http://lists.xen.org/archives/html/xen-devel/2011-08/msg00330.htmlI would be happy to support the
/dev/nullform.
This patch supports the /dev/null form.
# HG changeset patch
# Parent 435493696053a079ec17d6e1a63e5f2be3a2c9d0
xl: Allow use of /dev/null with xl create to enable command-line definition
xm allows specifying /dev/null as the domain configuration argument to its create option; add same functionality to xl. Whereas xl used to check to ensure the domain configuration argument was a regular file, it now checks to ensure it is not a directory. This allows specifying an entire domain configuration on the command line.
tools/libxl/libxl_utils.c +2 -2
@@ -324,8 +324,8 @@ int libxl_read_file_contents(libxl_ctx * goto xe; } -if (!S_ISREG (stab.st_mode)) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"%s is not a plain file" , filename); +if (S_ISDIR (stab.st_mode)) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"%s is a directory" , filename); errno =ENOTTY ; goto xe; }
W. Michael Petullo writes ("Re: [Xen-devel] Using "xl create" without domain config file"):
...
tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx * · line 328
Quoted 4 lines
tools/libxl/libxl_utils.c +2
-2-if (!S_ISREG (stab.st_mode)) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"%s is not a plain file" , filename); +if (S_ISDIR (stab.st_mode)) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"%s is a directory" , filename);
This is not correct. If, for example, /dev/tty is specified, it will go wrong.
The reason for the restriction to plain files is that those are the only thing on which stat works to provide the size. If we are to support other objects, we need to change the reading algorithm.
Ian.
Ian Jackson writes ("Re: [Xen-devel] Using "xl create" without domain config file"):
Quoted 7 lines
W. Michael Petullo writes ("Re: [Xen-devel] Using "xl create" without domain config file"):
...tools/libxl/libxl_utils.c int libxl_read_file_contents(libxl_ctx * · line 328
Quoted 4 lines
tools/libxl/libxl_utils.c +2
-2-if (!S_ISREG (stab.st_mode)) { -LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"%s is not a plain file" , filename); +if (S_ISDIR (stab.st_mode)) { +LIBXL__LOG_ERRNO (ctx,LIBXL__LOG_ERROR ,"%s is a directory" , filename);
Quoted 6 lines
This is not correct. If, for example,
/dev/ttyis specified, it will go wrong.The reason for the restriction to plain files is that those are the only thing on which stat works to provide the size. If we are to support other objects, we need to change the reading algorithm.
Another alternative would be to special-case the string "/dev/null" (in xl, not libxl) and not read a config file at all in that case.
Ian.
[...]
Quoted 8 lines
Quoted 8 lines
Review
Quoted 4 lines
(quoted diff) +2
-2- if (!S_ISREG(stab.st_mode)) { - LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "%s is not a plain file", filename); + if (S_ISDIR(stab.st_mode)) { + LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "%s is a directory", filename);This is not correct. If, for example,
/dev/ttyis specified, it will go wrong.
Quoted 6 lines
Quoted 3 lines
The reason for the restriction to plain files is that those are the only thing on which stat works to provide the size. If we are to support other objects, we need to change the reading algorithm.
Another alternative would be to special-case the string "
/dev/null" (in xl, not libxl) and not read a config file at all in that case.
This patch treats /dev/null as a special case.
# HG changeset patch
# Parent 435493696053a079ec17d6e1a63e5f2be3a2c9d0
xl: Allow use of /dev/null with xl create to enable command-line definition
xm allows specifying /dev/null as the domain configuration argument to its create option; add same functionality to xl. xl treats the configuration argument /dev/null as a special case. This allows specifying an entire domain configuration on the command line.
tools/libxl/xl_cmdimpl.c Thu Jun 07 22:40:58 2012 -0500 renamed from tools/libxl/xl_cmdimpl.c Fri May 25 08:18:47 2012 +0100 +7 -4
@@ -1454,10 +1454,13 @@ static int create_domain(struct domain_c if (config_file) { free(config_data); config_data = 0; - ret = libxl_read_file_contents(&ctx, config_file, - &config_data, &config_len); - if (ret) { fprintf(stderr, "Failed to read config file: %s: %s\n", - config_file, strerror(errno)); return ERROR_FAIL; } + // /dev/null represents special case (read config. from command line) + if (strcmp(config_file, "/dev/null")) { + ret = libxl_read_file_contents(&ctx, config_file, + &config_data, &config_len); + if (ret) { fprintf(stderr, "Failed to read config file: %s: %s\n", + config_file, strerror(errno)); return ERROR_FAIL; } + } if (!restore_file && extra_config && strlen(extra_config)) { if (config_len > INT_MAX - (strlen(extra_config) + 2 + 1)) { fprintf(stderr, "Failed to attach extra configration\n");
W. Michael Petullo writes ("Re: [Xen-devel] Using "xl create" without domain config file"):
Quoted 5 lines
[...]
Quoted 2 lines
Another alternative would be to special-case the string "
/dev/null" (in xl, not libxl) and not read a config file at all in that case.This patch treats
/dev/nullas a special case.
Thanks, this is going in the right direction I think. Just two niggles:
Quoted 7 lines
diff -r 435493696053
tools/libxl/xl_cmdimpl.ctools/libxl/xl_cmdimpl.c Thu Jun 07 22:40:58 2012 -0500 renamed from tools/libxl/xl_cmdimpl.c Fri May 25 08:18:47 2012 +0100 +0
-0@@ -1454,10 +1454,13 @@ static int create_domain(struct domain_c if (config_file) { free(config_data); config_data = 0;
...
Quoted 1 line
+ //
/dev/nullrepresents special case (read config. from command line)
libxl coding style uses /*...*/ comments.
tools/libxl/xl_cmdimpl.c Thu Jun 07 22:40:58 2012 -0500 static int create_domain(struct domain_c · line 1460
Quoted 3 lines
tools/libxl/xl_cmdimpl.c Thu Jun 07 22:40:58 2012 -0500 renamed from tools/libxl/xl_cmdimpl.c Fri May 25 08:18:47 2012 +0100 +3
-0+ if (strcmp(config_file, "/dev/null")) { + ret = libxl_read_file_contents(&ctx, config_file, + &config_data, &config_len);
I think this fails to set config_len to 0 in the /dev/null case, which it should do. Although config_len is initialised to 0 it may have been set to a non-0 value from the length of the old config file if we're doing a restore, and in this case it needs to be rezeroed.
tools/libxl/xl_cmdimpl.c Thu Jun 07 22:40:58 2012 -0500 static int create_domain(struct domain_c · line 1466
Quoted 6 lines
tools/libxl/xl_cmdimpl.c Thu Jun 07 22:40:58 2012 -0500 renamed from tools/libxl/xl_cmdimpl.c Fri May 25 08:18:47 2012 +0100 +3
-0+ if (ret) { fprintf(stderr, "Failed to read config file: %s: %s\n", + config_file, strerror(errno)); return ERROR_FAIL; } + } if (!restore_file && extra_config && strlen(extra_config)) { if (config_len > INT_MAX - (strlen(extra_config) + 2 + 1)) { fprintf(stderr, "Failed to attach extra configration\n");
thanks,
Ian.
[...]
Quoted 10 lines
Thanks, this is going in the right direction I think. Just two niggles:
Quoted 7 lines
diff -r 435493696053
tools/libxl/xl_cmdimpl.ctools/libxl/xl_cmdimpl.c Thu Jun 07 22:40:58 2012 -0500 renamed from tools/libxl/xl_cmdimpl.c Fri May 25 08:18:47 2012 +0100 +0
-0@@ -1454,10 +1454,13 @@ static int create_domain(struct domain_c if (config_file) { free(config_data); config_data = 0;
[...]
Quoted 4 lines
Quoted 1 line
+ //
/dev/nullrepresents special case (read config. from command line)libxl coding style uses /*...*/ comments.
Quoted 15 lines
tools/libxl/xl_cmdimpl.c Thu Jun 07 22:40:58 2012 -0500
Quoted 3 lines
tools/libxl/xl_cmdimpl.c Thu Jun 07 22:40:58 2012 -0500 renamed from tools/libxl/xl_cmdimpl.c Fri May 25 08:18:47 2012 +0100 +3
-0+ if (strcmp(config_file, "/dev/null")) { + ret = libxl_read_file_contents(&ctx, config_file, + &config_data, &config_len);I think this fails to set
config_lento 0 in the/dev/nullcase, which it should do. Althoughconfig_lenis initialised to 0 it may have been set to a non-0 value from the length of the old config file if we're doing a restore, and in this case it needs to be rezeroed.Quoted 6 lines
tools/libxl/xl_cmdimpl.c Thu Jun 07 22:40:58 2012 -0500 renamed from tools/libxl/xl_cmdimpl.c Fri May 25 08:18:47 2012 +0100 +3
-0+ if (ret) { fprintf(stderr, "Failed to read config file: %s: %s\n", + config_file, strerror(errno)); return ERROR_FAIL; } + } if (!restore_file && extra_config && strlen(extra_config)) { if (config_len > INT_MAX - (strlen(extra_config) + 2 + 1)) { fprintf(stderr, "Failed to attach extra configration\n");
This version addresses the two issues above:
# HG changeset patch
# Parent 435493696053a079ec17d6e1a63e5f2be3a2c9d0
xl: Allow use of /dev/null with xl create to enable command-line definition
xm allows specifying /dev/null as the domain configuration argument to its create option; add same functionality to xl. xl treats the configuration argument /dev/null as a special case. This allows specifying an entire domain configuration on the command line.
tools/libxl/xl_cmdimpl.c +9 -4
@@ -1454,10 +1454,15 @@ static int create_domain(struct domain_cif (config_file) {free (config_data); config_data =0 ; - ret =libxl_read_file_contents (&ctx, config_file, - &config_data, &config_len); -if (ret) {fprintf (stderr,"Failed to read config file: %s: %s\n" , - config_file,strerror (errno));return ERROR_FAIL ; } +/* /dev/null represents special case (read config. from command line) */ +if (!strcmp (config_file,"/dev/null" )) { + config_len =0 ; + }else { + ret =libxl_read_file_contents (&ctx, config_file, + &config_data, &config_len); +if (ret) {fprintf (stderr,"Failed to read config file: %s: %s\n" , + config_file,strerror (errno));return ERROR_FAIL ; } + }if (!restore_file && extra_config &&strlen (extra_config)) {if (config_len >INT_MAX - (strlen (extra_config) +2 +1 )) {fprintf (stderr,"Failed to attach extra configration\n" );
Quoted 10 lines
# HG changeset patch
# Parent435493696053a079ec17d6e1a63e5f2be3a2c9d0
xl: Allow use of/dev/nullwith xl create to enable command-line definitionxm allows specifying
/dev/nullas the domain configuration argument to its create option; add same functionality to xl. xl treats the configuration argument/dev/nullas a special case. This allows specifying an entire domain configuration on the command line.Signed-off-by W. Michael Petullo <[email protected]>
Hi Michael,
I have applied this patch but it seems to be against the xen 4.1 tree and not against xen-unstable. In this case I think I was able to trivially resolve the conflicts, but please do check I got it right.
For future reference we generally require patches to be against unstable. Once applied there they can then be nominated for backporting to 4.1 but except in very unusual circumstances we would not apply a patch directly to a stable branch.
You might also want to consider patching the xl config-update command?
Ian.
Quoted 29 lines
diff -r 435493696053
tools/libxl/xl_cmdimpl.ctools/libxl/xl_cmdimpl.c +9
-4@@ -1454,10 +1454,15 @@ static int create_domain(struct domain_cif (config_file) {free (config_data); config_data =0 ; - ret =libxl_read_file_contents (&ctx, config_file, - &config_data, &config_len); -if (ret) {fprintf (stderr,"Failed to read config file: %s: %s\n" , - config_file,strerror (errno));return ERROR_FAIL ; } +/* /dev/null represents special case (read config. from command line) */ +if (!strcmp (config_file,"/dev/null" )) { + config_len =0 ; + }else { + ret =libxl_read_file_contents (&ctx, config_file, + &config_data, &config_len); +if (ret) {fprintf (stderr,"Failed to read config file: %s: %s\n" , + config_file,strerror (errno));return ERROR_FAIL ; } + }if (!restore_file && extra_config &&strlen (extra_config)) {if (config_len >INT_MAX - (strlen (extra_config) +2 +1 )) {fprintf (stderr,"Failed to attach extra configration\n" );_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 9 lines
Quoted 9 lines
# HG changeset patch
# Parent435493696053a079ec17d6e1a63e5f2be3a2c9d0
xl: Allow use of/dev/nullwith xl create to enable command-line definitionxm allows specifying
/dev/nullas the domain configuration argument to its create option; add same functionality to xl. xl treats the configuration argument/dev/nullas a special case. This allows specifying an entire domain configuration on the command line.
Quoted 5 lines
Quoted 1 line
Signed-off-by W. Michael Petullo <[email protected]>I have applied this patch but it seems to be against the xen 4.1 tree and not against xen-unstable. In this case I think I was able to trivially resolve the conflicts, but please do check I got it right.
Things work nicely in Xen 4.2.0 RC2. Thank you.
Signature · 3 lines
Mike :wq