All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Jackson <ijackson@chiark.greenend.org.uk>
Subject: [PATCH] xl: replace config file disk spec parser with call to xlu_disk_parse
Date: Thu, 24 Mar 2011 17:49:48 +0000	[thread overview]
Message-ID: <1300988989-18305-3-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1300988989-18305-2-git-send-email-ian.jackson@eu.citrix.com>

From: Ian Jackson <ijackson@chiark.greenend.org.uk>

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
---
 tools/libxl/xl_cmdimpl.c |  160 +++++-----------------------------------------
 1 files changed, 16 insertions(+), 144 deletions(-)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 121a586..416de46 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -465,148 +465,22 @@ static int parse_action_on_shutdown(const char *buf, enum libxl_action_on_shutdo
 #define DSTATE_RW        5
 #define DSTATE_TERMINAL  6
 
-static int parse_disk_config(libxl_device_disk *disk, char *buf2)
+static void parse_disk_config(XLU_Config **config,
+			      libxl_device_disk *disk, const char *spec)
 {
-    int state = DSTATE_INITIAL;
-    char *p, *end, *tok;
-
-    memset(disk, 0, sizeof(*disk));
-
-    for(tok = p = buf2, end = buf2 + strlen(buf2) + 1; p < end; p++) {
-        switch(state){
-        case DSTATE_INITIAL:
-            if ( *p == ':' ) {
-                *p = '\0';
-                if ( !strcmp(tok, "phy") ) {
-                    state = DSTATE_PHYSPATH;
-                    disk->format = DISK_FORMAT_RAW;
-                    disk->backend = DISK_BACKEND_PHY;
-                }else if ( !strcmp(tok, "file") ) {
-                    state = DSTATE_PHYSPATH;
-                    disk->format = DISK_FORMAT_RAW;
-                    disk->backend = DISK_BACKEND_TAP;
-                }else if ((!strcmp(tok, "tap")) ||
-                          (!strcmp(tok, "tap2"))) {
-                    state = DSTATE_TAP;
-                }else{
-                    fprintf(stderr, "Unknown disk type: %s\n", tok);
-                    return 0;
-                }
-                tok = p + 1;
-            } else if (*p == ',') {
-                state = DSTATE_VIRTPATH;
-                disk->format = DISK_FORMAT_EMPTY;
-                disk->backend = DISK_BACKEND_TAP;
-                disk->pdev_path = strdup("");
-                tok = p + 1;
-            }
-            break;
-        case DSTATE_TAP:
-            if (*p == ',') {
-                disk->format = DISK_FORMAT_RAW;
-                disk->backend = DISK_BACKEND_TAP;
-                state = DSTATE_PHYSPATH;
-            } else if ( *p == ':' ) {
-                *p = '\0';
-                if (!strcmp(tok, "aio")) {
-                    tok = p + 1;
-                    break;
-                }
-                if (!strcmp(tok, "vhd")) {
-                    disk->format = DISK_FORMAT_VHD;
-                    disk->backend = DISK_BACKEND_TAP;
-                }else if ( !strcmp(tok, "qcow") ) {
-                    disk->format = DISK_FORMAT_QCOW;
-                    disk->backend = DISK_BACKEND_QDISK;
-                }else if ( !strcmp(tok, "qcow2") ) {
-                    disk->format = DISK_FORMAT_QCOW2;
-                    disk->backend = DISK_BACKEND_QDISK;
-                }else if (!strcmp(tok, "raw")) {
-                    disk->format = DISK_FORMAT_RAW;
-                    disk->backend = DISK_BACKEND_TAP;
-                }
-                else {
-                    fprintf(stderr, "Unknown tapdisk type: %s\n", tok);
-                    return 0;
-                }
+    int e;
 
-                tok = p + 1;
-                state = DSTATE_PHYSPATH;
-                break;
-            } else {
-                break;
-            }
-        case DSTATE_PHYSPATH:
-            if ( *p == ',' ) {
-                int ioemu_len;
-
-                *p = '\0';
-                disk->pdev_path = (*tok) ? strdup(tok) : NULL;
-                tok = p + 1;
-
-                /* hack for ioemu disk spec */
-                ioemu_len = strlen("ioemu:");
-                state = DSTATE_VIRTPATH;
-                if ( tok + ioemu_len < end &&
-                    !strncmp(tok, "ioemu:", ioemu_len)) {
-                    tok += ioemu_len;
-                    p += ioemu_len;
-                }
-            }
-            break;
-        case DSTATE_VIRTPATH:
-            if ( *p == ',' || *p == ':' || *p == '\0' ) {
-                switch(*p) {
-                case ':':
-                    state = DSTATE_VIRTTYPE;
-                    break;
-                case ',':
-                    state = DSTATE_RW;
-                    break;
-                case '\0':
-                    state = DSTATE_TERMINAL;
-                    break;
-                }
-                if ( tok == p )
-                    goto out;
-                *p = '\0';
-                disk->vdev = (*tok) ? strdup(tok) : NULL;
-                tok = p + 1;
-            }
-            break;
-        case DSTATE_VIRTTYPE:
-            if ( *p == ',' || *p == '\0' ) {
-                *p = '\0';
-                if ( !strcmp(tok, "cdrom") ) {
-                    disk->is_cdrom = 1;
-                    disk->unpluggable = 1;
-                }else{
-                    fprintf(stderr, "Unknown virtual disk type: %s\n", tok);
-                    return 0;
-                }
-                tok = p + 1;
-                state = (*p == ',') ? DSTATE_RW : DSTATE_TERMINAL;
-            }
-            break;
-        case DSTATE_RW:
-            if ( *p == '\0' ) {
-                disk->readwrite = (tok[0] == 'w');
-                tok = p + 1;
-                state = DSTATE_TERMINAL;
-            }
-            break;
-        case DSTATE_TERMINAL:
-            goto out;
-        }
+    if (!*config) {
+	*config = xlu_cfg_init(stderr, "command line");
+	if (!*config) { perror("xlu_cfg_init"); exit(-1); }
     }
 
-out:
-    if ( tok != p || state != DSTATE_TERMINAL ) {
-        fprintf(stderr, "parse error in disk config near '%s'\n", tok);
-        return 0;
+    e = xlu_disk_parse(*config, spec, disk);
+    if (e == EINVAL) exit(-1);
+    if (e) {
+	fprintf(stderr,"xlu_disk_parse failed: %s\n",strerror(errno));
+	exit(-1);
     }
-
-    return 1;
 }
 
 static void parse_config_data(const char *configfile_filename_report,
@@ -800,9 +674,7 @@ static void parse_config_data(const char *configfile_filename_report,
 
             d_config->disks = (libxl_device_disk *) realloc(d_config->disks, sizeof (libxl_device_disk) * (d_config->num_disks + 1));
             disk = d_config->disks + d_config->num_disks;
-            if ( !parse_disk_config(disk, buf2) ) {
-                exit(1);
-            }
+            parse_disk_config(&config, disk, buf2);
 
             free(buf2);
             d_config->num_disks++;
@@ -1873,6 +1745,7 @@ static void cd_insert(const char *dom, const char *virtdev, char *phys)
 {
     libxl_device_disk disk; /* we don't free disk's contents */
     char *buf = NULL;
+    XLU_Config *config;
 
     find_domain(dom);
 
@@ -1880,10 +1753,9 @@ static void cd_insert(const char *dom, const char *virtdev, char *phys)
         fprintf(stderr, "out of memory\n");
         return;
     }
-    if (!parse_disk_config(&disk, buf)) {
-        fprintf(stderr, "format error\n");
-        return;
-    }
+
+    parse_disk_config(&config, &disk, buf);
+
     disk.backend_domid = 0;
     disk.domid = domid;
 
-- 
1.5.6.5

  reply	other threads:[~2011-03-24 17:49 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-24 17:49 [PATCH] libxl: move TOSTRING to libxl_internal.h Ian Jackson
2011-03-24 17:49 ` [PATCH] libxl: new xlu_disk_parse function Ian Jackson
2011-03-24 17:49   ` Ian Jackson [this message]
2011-03-24 17:49     ` [PATCH] xl: replace block-attach disk config parser with call to xlu_parse_disk Ian Jackson
2011-03-28 17:31   ` [PATCH] libxl: new xlu_disk_parse function Gianni Tedesco
2011-03-28 18:13     ` Stefano Stabellini
2011-03-29  9:10       ` Ian Campbell
2011-03-31 17:33       ` Ian Jackson
2011-04-01 15:28         ` Stefano Stabellini
2011-03-31 17:30     ` Ian Jackson
2011-04-02  8:51       ` Ian Campbell
2011-04-04 11:29       ` Stefano Stabellini
2011-04-14  7:20       ` Gianni Tedesco

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1300988989-18305-3-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=ijackson@chiark.greenend.org.uk \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.