All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xl: support specifing '[vars]' in 'xl create'
@ 2010-04-28  8:51 Yu Zhiguo
  2010-04-28 19:02 ` Stefano Stabellini
  0 siblings, 1 reply; 4+ messages in thread
From: Yu Zhiguo @ 2010-04-28  8:51 UTC (permalink / raw)
  To: Keir Fraser; +Cc: xen-devel@lists.xensource.com


Add support of specifing '[vars]' in 'xl create'.
It is said '[vars]' can be used in help message of 'xl create',
but in fact cannot now, so add this function.

After this fix:
# xl create pvguest1.conf
# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     2        r--    161.0
pvguest1                                    29   256     2        r--      0.5
# xl destroy pvguest1
# xl create pvguest1.conf vcpus=4 memory=512 'name="pv1"'
# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     2        r--    162.2
pv1                                         30   512     4        r--      0.2

Signed-off-by: Yu Zhiguo <yuzg@cn.fujitsu.com>

diff -r c87ec146229a -r 51bb2db1ed51 tools/libxl/xl.c
--- a/tools/libxl/xl.c	Fri Apr 23 15:04:26 2010 +0100
+++ b/tools/libxl/xl.c	Thu Apr 29 00:02:02 2010 +0800
@@ -777,7 +777,9 @@
     return r;
 }
 
-static int create_domain(int debug, int daemonize, const char *config_file, const char *restore_file, int paused, int migrate_fd /* -1 means none */, char **migration_domname_r)
+static int create_domain(int debug, int daemonize, const char *config_file, const char *restore_file,
+                         int paused, int migrate_fd /* -1 means none */, char **migration_domname_r,
+                         const char *extra_config)
 {
     libxl_domain_create_info info1;
     libxl_domain_build_info info2;
@@ -873,6 +875,21 @@
                                        &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)) {
+                fprintf(stderr, "Failed to attach extra configration\n");
+                return ERROR_FAIL;
+            }
+            config_data = realloc(config_data, config_len + strlen(extra_config) + 2);
+            if (!config_data) {
+                fprintf(stderr, "Failed to realloc config_data\n");
+                return ERROR_FAIL;
+            }
+            strcat(config_data, "\n");
+            strcat(config_data, extra_config);
+            strcat(config_data, "\n");
+            config_len += (strlen(extra_config) + 2);
+        }
     } else {
         if (!config_data) {
             fprintf(stderr, "Config file not specified and"
@@ -1935,7 +1952,7 @@
     rc = create_domain(debug, daemonize,
                        0 /* no config file, use incoming */,
                        "incoming migration stream", 1,
-                       0, &migration_domname);
+                       0, &migration_domname, NULL);
     if (rc) {
         fprintf(stderr, "migration target: Domain creation failed"
                 " (code %d).\n", rc);
@@ -2045,7 +2062,7 @@
         exit(2);
     }
     rc = create_domain(debug, daemonize, config_file,
-                       checkpoint_file, paused, -1, 0);
+                       checkpoint_file, paused, -1, 0, NULL);
     exit(-rc);
 }
 
@@ -2291,6 +2308,8 @@
 {
     char *filename = NULL;
     int debug = 0, daemonize = 1;
+#define MAX_EXTRA       1024
+    char *p, extra_config[MAX_EXTRA];
     int opt, rc;
 
     while ((opt = getopt(argc, argv, "hde")) != -1) {
@@ -2310,14 +2329,26 @@
         }
     }
 
-    if (optind >= argc) {
-        help("create");
-        exit(2);
+    memset(extra_config, 0, MAX_EXTRA);
+    while (optind < argc) {
+        if ((p = strchr(argv[optind], '='))) {
+            if (strlen(extra_config) + 1 < MAX_EXTRA) {
+                if (strlen(extra_config))
+                    strcat(extra_config, "\n");
+                strcat(extra_config, argv[optind]);
+            }
+        } else if (!filename) {
+            filename = argv[optind];
+        } else {
+            help("create");
+            exit(2);
+        }
+
+        optind++;
     }
 
-    filename = argv[optind];
     rc = create_domain(debug, daemonize, filename, NULL, 0,
-                       -1, 0);
+                       -1, 0, extra_config);
     exit(-rc);
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xl: support specifing '[vars]' in 'xl create'
  2010-04-28  8:51 [PATCH] xl: support specifing '[vars]' in 'xl create' Yu Zhiguo
@ 2010-04-28 19:02 ` Stefano Stabellini
  2010-04-29  4:32   ` Yu Zhiguo
  0 siblings, 1 reply; 4+ messages in thread
From: Stefano Stabellini @ 2010-04-28 19:02 UTC (permalink / raw)
  To: Yu Zhiguo; +Cc: xen-devel@lists.xensource.com, Keir Fraser

On Wed, 28 Apr 2010, Yu Zhiguo wrote:
> 
> Add support of specifing '[vars]' in 'xl create'.
> It is said '[vars]' can be used in help message of 'xl create',
> but in fact cannot now, so add this function.
> 
> After this fix:
> # xl create pvguest1.conf
> # xl list
> Name                                        ID   Mem VCPUs      State   Time(s)
> Domain-0                                     0  1024     2        r--    161.0
> pvguest1                                    29   256     2        r--      0.5
> # xl destroy pvguest1
> # xl create pvguest1.conf vcpus=4 memory=512 'name="pv1"'
> # xl list
> Name                                        ID   Mem VCPUs      State   Time(s)
> Domain-0                                     0  1024     2        r--    162.2
> pv1                                         30   512     4        r--      0.2
> 
> Signed-off-by: Yu Zhiguo <yuzg@cn.fujitsu.com>
> 
> diff -r c87ec146229a -r 51bb2db1ed51 tools/libxl/xl.c
> --- a/tools/libxl/xl.c	Fri Apr 23 15:04:26 2010 +0100
> +++ b/tools/libxl/xl.c	Thu Apr 29 00:02:02 2010 +0800
> @@ -777,7 +777,9 @@
>      return r;
>  }
>  
> -static int create_domain(int debug, int daemonize, const char *config_file, const char *restore_file, int paused, int migrate_fd /* -1 means none */, char **migration_domname_r)
> +static int create_domain(int debug, int daemonize, const char *config_file, const char *restore_file,
> +                         int paused, int migrate_fd /* -1 means none */, char **migration_domname_r,
> +                         const char *extra_config)

This line is misaligned.
Also, I feel that create_domain's arguments are growing too much, it would
be a good idea to reorganize them in a struct.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xl: support specifing '[vars]' in 'xl create'
  2010-04-28 19:02 ` Stefano Stabellini
@ 2010-04-29  4:32   ` Yu Zhiguo
  2010-04-29 18:05     ` Stefano Stabellini
  0 siblings, 1 reply; 4+ messages in thread
From: Yu Zhiguo @ 2010-04-29  4:32 UTC (permalink / raw)
  To: Stefano Stabellini; +Cc: xen-devel@lists.xensource.com, Keir Fraser

Hi Stefano,

Stefano Stabellini wrote:
>> -static int create_domain(int debug, int daemonize, const char *config_file, const char *restore_file, int paused, int migrate_fd /* -1 means none */, char **migration_domname_r)
>> +static int create_domain(int debug, int daemonize, const char *config_file, const char *restore_file,
>> +                         int paused, int migrate_fd /* -1 means none */, char **migration_domname_r,
>> +                         const char *extra_config)
> 
> This line is misaligned.
> Also, I feel that create_domain's arguments are growing too much, it would
> be a good idea to reorganize them in a struct.
> 

Thanks for you advice, I think it's a good idea and fix the patch.
Could you ack the new version?

Regards
Yu Zhiguo

---------------v2--------------------

Add support of specifing '[vars]' in 'xl create'.
It is said '[vars]' can be used in help message of 'xl create',
but in fact cannot now, so add this function.

After this fix:
# xl create pvguest1.conf
# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     2     r-----    541.7
pvguest1                                    56   256     2     -b----      0.4
# xl destroy pvguest1
# xl create pvguest1.conf vcpus=4 memory=512 'name="pv1"'
# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0  1024     2        r--    542.2
pv1                                         57   512     4        r--      0.5

Signed-off-by: Yu Zhiguo <yuzg@cn.fujitsu.com>

diff -r 9a1d7caa2024 -r 262f87853b2d tools/libxl/xl.c
--- a/tools/libxl/xl.c	Mon Apr 26 12:13:23 2010 +0100
+++ b/tools/libxl/xl.c	Thu Apr 29 20:06:47 2010 +0800
@@ -70,6 +70,17 @@
    *            from target to source
    */
 
+struct domain_create {
+    int debug;
+    int daemonize;
+    int paused;
+    const char *config_file;
+    const char *extra_config; /* extra config string */
+    const char *restore_file;
+    int migrate_fd; /* -1 means none */
+    char **migration_domname_r;
+};
+
 struct save_file_header {
     char magic[32]; /* savefileheader_magic */
     /* All uint32_ts are in domain's byte order. */
@@ -777,7 +788,7 @@
     return r;
 }
 
-static int create_domain(int debug, int daemonize, const char *config_file, const char *restore_file, int paused, int migrate_fd /* -1 means none */, char **migration_domname_r)
+static int create_domain(struct domain_create *dom_info)
 {
     libxl_domain_create_info info1;
     libxl_domain_build_info info2;
@@ -789,6 +800,16 @@
     libxl_device_vfb *vfbs = NULL;
     libxl_device_vkb *vkbs = NULL;
     libxl_device_console console;
+
+    int debug = dom_info->debug;
+    int daemonize = dom_info->daemonize;
+    int paused = dom_info->paused;
+    const char *config_file = dom_info->config_file;
+    const char *extra_config = dom_info->extra_config;
+    const char *restore_file = dom_info->restore_file;
+    int migrate_fd = dom_info->migrate_fd;
+    char **migration_domname_r = dom_info->migration_domname_r;
+
     int num_disks = 0, num_vifs = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0;
     int i, fd;
     int need_daemon = 1;
@@ -873,6 +894,23 @@
                                        &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)) {
+                fprintf(stderr, "Failed to attach extra configration\n");
+                return ERROR_FAIL;
+            }
+            config_data = realloc(config_data, config_len
+                + strlen(extra_config) + 2);
+            if (!config_data) {
+                fprintf(stderr, "Failed to realloc config_data\n");
+                return ERROR_FAIL;
+            }
+            strcat(config_data, "\n");
+            strcat(config_data, extra_config);
+            strcat(config_data, "\n");
+            config_len += (strlen(extra_config) + 2);
+        }
     } else {
         if (!config_data) {
             fprintf(stderr, "Config file not specified and"
@@ -1921,6 +1959,7 @@
     int rc, rc2;
     char rc_buf;
     char *migration_domname;
+    struct domain_create dom_info;
 
     signal(SIGPIPE, SIG_IGN);
     /* if we get SIGPIPE we'd rather just have it as an error */
@@ -1933,10 +1972,14 @@
                                    "migration ack stream",
                                    "banner") );
 
-    rc = create_domain(debug, daemonize,
-                       0 /* no config file, use incoming */,
-                       "incoming migration stream", 1,
-                       0, &migration_domname);
+    memset(&dom_info, 0, sizeof(dom_info));
+    dom_info.debug = debug;
+    dom_info.daemonize = daemonize;
+    dom_info.paused = 1;
+    dom_info.restore_file = "incoming migration stream";
+    dom_info.migration_domname_r = &migration_domname;
+
+    rc = create_domain(&dom_info);
     if (rc) {
         fprintf(stderr, "migration target: Domain creation failed"
                 " (code %d).\n", rc);
@@ -2014,6 +2057,7 @@
     char *checkpoint_file = NULL;
     char *config_file = NULL;
     int paused = 0, debug = 0, daemonize = 1;
+    struct domain_create dom_info;
     int opt, rc;
 
     while ((opt = getopt(argc, argv, "hpde")) != -1) {
@@ -2045,8 +2089,16 @@
         help("restore");
         exit(2);
     }
-    rc = create_domain(debug, daemonize, config_file,
-                       checkpoint_file, paused, -1, 0);
+
+    memset(&dom_info, 0, sizeof(dom_info));
+    dom_info.debug = debug;
+    dom_info.daemonize = daemonize;
+    dom_info.paused = paused;
+    dom_info.config_file = config_file;
+    dom_info.restore_file = checkpoint_file;
+    dom_info.migrate_fd = -1;
+
+    rc = create_domain(&dom_info);
     exit(-rc);
 }
 
@@ -2292,6 +2344,9 @@
 {
     char *filename = NULL;
     int paused = 0, debug = 0, daemonize = 1;
+#define MAX_EXTRA       1024
+    char *p, extra_config[MAX_EXTRA];
+    struct domain_create dom_info;
     int opt, rc;
 
     while ((opt = getopt(argc, argv, "hdep")) != -1) {
@@ -2314,14 +2369,33 @@
         }
     }
 
-    if (optind >= argc) {
-        help("create");
-        exit(2);
+    memset(extra_config, 0, MAX_EXTRA);
+    while (optind < argc) {
+        if ((p = strchr(argv[optind], '='))) {
+            if (strlen(extra_config) + 1 < MAX_EXTRA) {
+                if (strlen(extra_config))
+                    strcat(extra_config, "\n");
+                strcat(extra_config, argv[optind]);
+            }
+        } else if (!filename) {
+            filename = argv[optind];
+        } else {
+            help("create");
+            exit(2);
+        }
+
+        optind++;
     }
 
-    filename = argv[optind];
-    rc = create_domain(debug, daemonize, filename, NULL, paused,
-                       -1, 0);
+    memset(&dom_info, 0, sizeof(dom_info));
+    dom_info.debug = debug;
+    dom_info.daemonize = daemonize;
+    dom_info.paused = paused;
+    dom_info.config_file = filename;
+    dom_info.extra_config = extra_config;
+    dom_info.migrate_fd = -1;
+
+    rc = create_domain(&dom_info);
     exit(-rc);
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] xl: support specifing '[vars]' in 'xl create'
  2010-04-29  4:32   ` Yu Zhiguo
@ 2010-04-29 18:05     ` Stefano Stabellini
  0 siblings, 0 replies; 4+ messages in thread
From: Stefano Stabellini @ 2010-04-29 18:05 UTC (permalink / raw)
  To: Yu Zhiguo; +Cc: xen-devel@lists.xensource.com, Keir Fraser, Stefano Stabellini

On Thu, 29 Apr 2010, Yu Zhiguo wrote:
> Hi Stefano,
> 
> Stefano Stabellini wrote:
> >> -static int create_domain(int debug, int daemonize, const char *config_file, const char *restore_file, int paused, int migrate_fd /* -1 means none */, char **migration_domname_r)
> >> +static int create_domain(int debug, int daemonize, const char *config_file, const char *restore_file,
> >> +                         int paused, int migrate_fd /* -1 means none */, char **migration_domname_r,
> >> +                         const char *extra_config)
> > 
> > This line is misaligned.
> > Also, I feel that create_domain's arguments are growing too much, it would
> > be a good idea to reorganize them in a struct.
> > 
> 
> Thanks for you advice, I think it's a good idea and fix the patch.
> Could you ack the new version?
> 

This patch looks good.

Acked-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-04-29 18:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-28  8:51 [PATCH] xl: support specifing '[vars]' in 'xl create' Yu Zhiguo
2010-04-28 19:02 ` Stefano Stabellini
2010-04-29  4:32   ` Yu Zhiguo
2010-04-29 18:05     ` Stefano Stabellini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.