Skip to contentSkip to conversation

xl: Don't require a config file for cpupools

PATCH Superseded George Dunlap 3 participants 4 messages Apr 3, 2012 – Apr 25, 2012

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xl: Don't require a config file for cpupools

Since the key information can be fairly simply put on the command-line, there's no need to require an actual config file.

Also improve the help to cross-reference the xlcpupool.cfg manpage.

docs/man/xl.pod.1 +5 -3
diff -r 30cc13e25e01 -r 0fb728d56bae docs/man/xl.pod.1
@@ -848,11 +848,13 @@ Cpu-pools can be specified either by nam
 
 =over 4
 
-=item B<cpupool-create> [I<OPTIONS>] I<ConfigFile> [I<Variable=Value> ...]
+=item B<cpupool-create> [I<OPTIONS>] [I<ConfigFile>] [I<Variable=Value> ...]
 
-Create a cpu pool based an I<ConfigFile>.
+Create a cpu pool based an config from a I<ConfigFile> or command-line parameters.
 Variable settings from the I<ConfigFile> may be altered by specifying new
-or additional assignments on the command line.
+or additional assignments on the command line.  
+
+See the xlcpupool.cfg manpage for more information.
 
 B<OPTIONS>
 
tools/libxl/xl_cmdimpl.c +22 -15
diff -r 30cc13e25e01 -r 0fb728d56bae tools/libxl/xl_cmdimpl.c
@@ -5407,7 +5407,7 @@ int main_tmem_freeable(int argc, char **
 
 int main_cpupoolcreate(int argc, char **argv)
 {
-    const char *filename = NULL;
+    const char *filename = NULL, *config_src=NULL;
     const char *p;
     char extra_config[1024];
     int opt;
@@ -5471,23 +5471,26 @@ int main_cpupoolcreate(int argc, char **
         optind++;
     }
 
-    if (!filename) {
-        help("cpupool-create");
-        return -ERROR_FAIL;
-    }
-
-    if (libxl_read_file_contents(ctx, filename, (void **)&config_data, &config_len)) {
-        fprintf(stderr, "Failed to read config file: %s: %s\n",
-                filename, strerror(errno));
-        return -ERROR_FAIL;
-    }
+    if (filename)
+    {
+        if (libxl_read_file_contents(ctx, filename, (void **)&config_data,
+                                     &config_len)) {
+            fprintf(stderr, "Failed to read config file: %s: %s\n",
+                    filename, strerror(errno));
+            return -ERROR_FAIL;
+        }
+        config_src=filename;
+    }
+    else
+        config_src="command line";
+
     if (strlen(extra_config)) {
         if (config_len > INT_MAX - (strlen(extra_config) + 2)) {
             fprintf(stderr, "Failed to attach extra configration\n");
             return -ERROR_FAIL;
         }
         config_data = xrealloc(config_data,
-                              config_len + strlen(extra_config) + 2);
+                               config_len + strlen(extra_config) + 2);
         if (!config_data) {
             fprintf(stderr, "Failed to realloc config_data\n");
             return -ERROR_FAIL;
@@ -5498,7 +5501,7 @@ int main_cpupoolcreate(int argc, char **
         config_len += strlen(extra_config) + 1;
     }
 
-    config = xlu_cfg_init(stderr, filename);
+    config = xlu_cfg_init(stderr, config_src);
     if (!config) {
         fprintf(stderr, "Failed to allocate for configuration\n");
         return -ERROR_FAIL;
@@ -5512,8 +5515,12 @@ int main_cpupoolcreate(int argc, char **
 
     if (!xlu_cfg_get_string (config, "name", &buf, 0))
         name = strdup(buf);
-    else
+    else if (filename)
         name = libxl_basename(filename);
+    else {
+        fprintf(stderr, "Missing cpupool name!\n");
+        return -ERROR_FAIL;
+    }
     if (!libxl_name_to_cpupoolid(ctx, name, &poolid)) {
         fprintf(stderr, "Pool name \"%s\" already exists\n", name);
         return -ERROR_FAIL;
@@ -5595,7 +5602,7 @@ int main_cpupoolcreate(int argc, char **
 
     libxl_uuid_generate(&uuid);
 
-    printf("Using config file \"%s\"\n", filename);
+    printf("Using config file \"%s\"\n", config_src);
     printf("cpupool name:   %s\n", name);
     printf("scheduler:      %s\n", libxl_scheduler_to_string(sched));
     printf("number of cpus: %d\n", n_cpus);
tools/libxl/xl_cmdtable.c +5 -3
diff -r 30cc13e25e01 -r 0fb728d56bae tools/libxl/xl_cmdtable.c
@@ -364,12 +364,14 @@ struct cmd_spec cmd_table[] = {
     },
     { "cpupool-create",
       &main_cpupoolcreate, 1,
-      "Create a CPU pool based an ConfigFile",
-      "[options] <ConfigFile> [vars]",
+      "Create a new CPU pool",
+      "[options] [<ConfigFile>] [Variable=value ...]",
       "-h, --help                   Print this help.\n"
       "-f FILE, --defconfig=FILE    Use the given configuration file.\n"
       "-n, --dryrun                 Dry run - prints the resulting configuration.\n"
-      "                              (deprecated in favour of global -N option)."
+      "                              (deprecated in favour of global -N option).\n"
+      "\nSee the xlcpupool.cfg manpage for more information.",
+
     },
     { "cpupool-list",
       &main_cpupoollist, 0,
#1 lore raw
Quoted 6 lines · George Dunlap

Since the key information can be fairly simply put on the command-line, there's no need to require an actual config file.

Also improve the help to cross-reference the xlcpupool.cfg manpage.

Code looks good to me, couple of comments on the docs aspects below.

Quoted 5 lines

diff -r 30cc13e25e01 -r 0fb728d56bae docs/man/xl.pod.1

docs/man/xl.pod.1 +0 -0
@@ -848,11 +848,13 @@ Cpu-pools can be specified either by nam
 

docs/man/xl.pod.1 Cpu-pools can be specified either by nam · line 855

Quoted 10 lines
docs/man/xl.pod.1 +3 -3
 =over 4
 
-=item B<cpupool-create> [I<OPTIONS>] I<ConfigFile> [I<Variable=Value> ...]
+=item B<cpupool-create> [I<OPTIONS>] [I<ConfigFile>] [I<Variable=Value> ...]
 
-Create a cpu pool based an I<ConfigFile>.
+Create a cpu pool based an config from a I<ConfigFile> or command-line parameters.
 Variable settings from the I<ConfigFile> may be altered by specifying new
-or additional assignments on the command line.
+or additional assignments on the command line.

Could do with rewrapping? Or a blank line between the paras if that's what they are meant to be (that's prexisting in that case)

docs/man/xl.pod.1 Cpu-pools can be specified either by nam · line 857

Quoted 2 lines
docs/man/xl.pod.1 +2 -0
+
+See the xlcpupool.cfg manpage for more information.

I think this should be "L<xlcpupool.cfg(N)>" in here. (N for whichever section the manpage is in).

Quoted 7 lines

diff -r 30cc13e25e01 -r 0fb728d56bae tools/libxl/xl_cmdtable.c

tools/libxl/xl_cmdtable.c +0 -0
@@ -364,12 +364,14 @@ struct cmd_spec cmd_table[] = {
     },
     { "cpupool-create",
       &main_cpupoolcreate, 1,

tools/libxl/xl_cmdtable.c struct cmd_spec cmd_table[] = { · line 373

Quoted 10 lines
tools/libxl/xl_cmdtable.c +4 -3
-      "Create a CPU pool based an ConfigFile",
-      "[options] <ConfigFile> [vars]",
+      "Create a new CPU pool",
+      "[options] [<ConfigFile>] [Variable=value ...]",
       "-h, --help                   Print this help.\n"
       "-f FILE, --defconfig=FILE    Use the given configuration file.\n"
       "-n, --dryrun                 Dry run - prints the resulting configuration.\n"
-      "                              (deprecated in favour of global -N option)."
+      "                              (deprecated in favour of global -N option).\n"
+      "\nSee the xlcpupool.cfg manpage for more information.",

xlcpupool.cfg(N) here too.

Quoted 9 lines
tools/libxl/xl_cmdtable.c +1 -0
+
     },
     { "cpupool-list",
       &main_cpupoollist, 0,

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#2 lore raw
In reply to George Dunlap

George Dunlap writes ("[Xen-devel] [PATCH] xl: Don't require a config file for cpupools"):

Quoted 2 lines

Since the key information can be fairly simply put on the command-line, there's no need to require an actual config file.

Thanks. Just a few tiny coding style nits. I agree with Ian Campbell's comments, and also:

tools/libxl/xl_cmdimpl.c int main_tmem_freeable(int argc, char ** · line 5410

Quoted 2 lines
tools/libxl/xl_cmdimpl.c +1 -1
-    const char *filename = NULL;
+    const char *filename = NULL, *config_src=NULL;

This has inconsistent use of whitespace.

tools/libxl/xl_cmdimpl.c int main_cpupoolcreate(int argc, char ** · line 5475

Quoted 2 lines
tools/libxl/xl_cmdimpl.c +2 -0
+    if (filename)
+    {

This should have { on the same line as the if.

tools/libxl/xl_cmdimpl.c int main_cpupoolcreate(int argc, char ** · line 5482

Quoted 7 lines
tools/libxl/xl_cmdimpl.c +7 -0
+        if (libxl_read_file_contents(ctx, filename, (void **)&config_data,
+                                     &config_len)) {
+            fprintf(stderr, "Failed to read config file: %s: %s\n",
+                    filename, strerror(errno));
+            return -ERROR_FAIL;
+        }
+        config_src=filename;

We put spaces around "=". (Here and a few lines further on.)

Review

Quoted 2 lines
(quoted diff) +2 -0
+    }
+    else

And on the same line as the else. And having { } for the if, I think putting { } for the else block would be more conventional.

tools/libxl/xl_cmdimpl.c int main_cpupoolcreate(int argc, char ** · line 5605

Quoted 2 lines
tools/libxl/xl_cmdimpl.c +1 -1
-    printf("Using config file \"%s\"\n", filename);
+    printf("Using config file \"%s\"\n", config_src);

This will print
Using config file "command line"
which is rather an odd message. Perhaps change the string to `<command line>' and remove the quotes ?

Ian.

#3 lore raw
Quoted 7 lines · Ian Jackson
Quoted 2 lines

-    printf("Using config file \"%s\"\n", filename);
+    printf("Using config file \"%s\"\n", config_src);

This will print
  Using config file "command line"
which is rather an odd message.  Perhaps change the string to `<command line>' and remove the quotes ?

Changing the string to <command line> makes sense. I think the point of putting quotes there is to avoid getting strange results if your filenames have spaces. But I suppose if you're strange enough to be using spaces in your filenames, you should be able to figure out what's going on yourself. :-)

New patch on the way...
-George