[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 1/2] xl: disk parsing preparation for empty cdrom devices



Prepare the ground for parsing the xend empty cdrom syntax, by
separating out some non-functional changes as this pre-patch:

* Clarify the disk syntax documentation wording to refer to deprecated
  syntaxes too.

* Make DPC in libxlu_disk_l.l useable in the helper functions as well
  as in lexer rules, by providing two definitions, each in force in
  the appropriate parts of the file.

* Break the <vdev>[:<devtype>] parsing out into a helper function,
  `vdev_and_devtype'.

No functional change.

Signed-off-by: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 docs/misc/xl-disk-configuration.txt |   11 ++--
 tools/libxl/libxlu_disk_l.c         |  112 ++++++++++++++++++-----------------
 tools/libxl/libxlu_disk_l.h         |   10 +---
 tools/libxl/libxlu_disk_l.l         |   44 +++++++++-----
 4 files changed, 93 insertions(+), 84 deletions(-)

diff --git a/docs/misc/xl-disk-configuration.txt 
b/docs/misc/xl-disk-configuration.txt
index 3bf20bf..740b8f6 100644
--- a/docs/misc/xl-disk-configuration.txt
+++ b/docs/misc/xl-disk-configuration.txt
@@ -164,16 +164,17 @@ information to be interpreted by 
/etc/xen/scripts/block-<script>.
 
 
 
-==================================
-DEPRECATED PARAMETERS AND PREFIXES
-==================================
+============================================
+DEPRECATED PARAMETERS, PREFIXES AND SYNTAXES
+============================================
 
-Deprecated values are acceptable and are intended work compatibly with
+Deprecated forms are acceptable and are intended work compatibly with
 xend and xl from xen 4.1.  In future they may print a warning.
 Support for deprecated parameters and syntaxes are likely to be
 dropped in future versions of xl.
 
-There is also support for a deprecated old syntax for <diskspec>:
+
+There is support for a deprecated old syntax for <diskspec>:
 
   [<format>:][<target>],<vdev>[:<devtype>],<access>   (deprecated)
 
diff --git a/tools/libxl/libxlu_disk_l.c b/tools/libxl/libxlu_disk_l.c
index 2f0f283..aac816a 100644
--- a/tools/libxl/libxlu_disk_l.c
+++ b/tools/libxl/libxlu_disk_l.c
@@ -794,8 +794,6 @@ void xlu__disk_yyset_column(int  column_no, yyscan_t 
yyscanner);
  * and particularly to avoid repeating boilerplate values such as
  * DPC->disk, yytext, etc. */
 
-#define DPC ((DiskParseContext*)yyextra)
-
 /* Sets an enum, checking it hasn't already been set to a different value  */
 #define DSET(dpc,member,enumname,str,valname) do{                      \
        if (dpc->disk->member != LIBXL_DISK_##enumname##_UNKNOWN &&     \
@@ -828,6 +826,8 @@ static void savestring(DiskParseContext *dpc, const char 
*what_respecified,
     *update = strdup(value);
 }
 
+#define DPC dpc /* our convention in lexer helper functions */
+
 /* Sets ->readwrite from the string.  This ought to be an enum, perhaps. */
 static void setaccess(DiskParseContext *dpc, const char *str) {
     if (!strcmp(str, "r") || !strcmp(str, "ro")) {
@@ -859,8 +859,32 @@ static void setbackendtype(DiskParseContext *dpc, const 
char *str) {
 
 #define DEPRECATE(usewhatinstead) /* not currently reported */
 
+/* Handles a vdev positional parameter which includes a devtype. */
+static int vdev_and_devtype(DiskParseContext *dpc, char *str) {
+    /* returns 1 if it was <vdev>:<devtype>, 0 (doing nothing) otherwise */
+    char *colon = strrchr(str, ':');
+    if (!colon)
+        return 0;
+
+    DEPRECATE("use `devtype=...'");
+    *colon++ = 0;
+    SAVESTRING("vdev", vdev, str);
+
+    if (!strcmp(colon,"cdrom")) {
+        DPC->disk->is_cdrom = 1;
+    } else if (!strcmp(colon,"disk")) {
+        DPC->disk->is_cdrom = 0;
+    } else {
+        xlu__disk_err(DPC,colon,"unknown deprecated type");
+    }
+    return 1;
+}
+
+#undef DPC /* needs to be defined differently the actual lexer */
+#define DPC ((DiskParseContext*)yyextra)
 
-#line 864 "libxlu_disk_l.c"
+
+#line 888 "libxlu_disk_l.c"
 
 #define INITIAL 0
 #define LEXERR 1
@@ -1096,12 +1120,12 @@ YY_DECL
        register int yy_act;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
 
-#line 126 "libxlu_disk_l.l"
+#line 150 "libxlu_disk_l.l"
 
 
  /*----- the scanner rules which do the parsing -----*/
 
-#line 1105 "libxlu_disk_l.c"
+#line 1129 "libxlu_disk_l.c"
 
        if ( !yyg->yy_init )
                {
@@ -1222,72 +1246,72 @@ do_action:      /* This label is used only to access 
EOF actions. */
 case 1:
 /* rule 1 can match eol */
 YY_RULE_SETUP
-#line 130 "libxlu_disk_l.l"
+#line 154 "libxlu_disk_l.l"
 { /* ignore whitespace before parameters */ }
        YY_BREAK
 /* ordinary parameters setting enums or strings */
 case 2:
 /* rule 2 can match eol */
 YY_RULE_SETUP
-#line 134 "libxlu_disk_l.l"
+#line 158 "libxlu_disk_l.l"
 { STRIP(','); setformat(DPC, FROMEQUALS); }
        YY_BREAK
 case 3:
 YY_RULE_SETUP
-#line 136 "libxlu_disk_l.l"
+#line 160 "libxlu_disk_l.l"
 { DPC->disk->is_cdrom = 1; }
        YY_BREAK
 case 4:
 YY_RULE_SETUP
-#line 137 "libxlu_disk_l.l"
+#line 161 "libxlu_disk_l.l"
 { DPC->disk->is_cdrom = 1; }
        YY_BREAK
 case 5:
 YY_RULE_SETUP
-#line 138 "libxlu_disk_l.l"
+#line 162 "libxlu_disk_l.l"
 { DPC->disk->is_cdrom = 0; }
        YY_BREAK
 case 6:
 /* rule 6 can match eol */
 YY_RULE_SETUP
-#line 139 "libxlu_disk_l.l"
+#line 163 "libxlu_disk_l.l"
 { xlu__disk_err(DPC,yytext,"unknown value for type"); }
        YY_BREAK
 case 7:
 /* rule 7 can match eol */
 YY_RULE_SETUP
-#line 141 "libxlu_disk_l.l"
+#line 165 "libxlu_disk_l.l"
 { STRIP(','); setaccess(DPC, FROMEQUALS); }
        YY_BREAK
 case 8:
 /* rule 8 can match eol */
 YY_RULE_SETUP
-#line 142 "libxlu_disk_l.l"
+#line 166 "libxlu_disk_l.l"
 { STRIP(','); setbackendtype(DPC,FROMEQUALS); }
        YY_BREAK
 case 9:
 /* rule 9 can match eol */
 YY_RULE_SETUP
-#line 144 "libxlu_disk_l.l"
+#line 168 "libxlu_disk_l.l"
 { STRIP(','); SAVESTRING("vdev", vdev, FROMEQUALS); }
        YY_BREAK
 case 10:
 /* rule 10 can match eol */
 YY_RULE_SETUP
-#line 145 "libxlu_disk_l.l"
+#line 169 "libxlu_disk_l.l"
 { STRIP(','); SAVESTRING("script", script, FROMEQUALS); }
        YY_BREAK
 /* the target magic parameter, eats the rest of the string */
 case 11:
 YY_RULE_SETUP
-#line 149 "libxlu_disk_l.l"
+#line 173 "libxlu_disk_l.l"
 { STRIP(','); SAVESTRING("target", pdev_path, FROMEQUALS); }
        YY_BREAK
 /* unknown parameters */
 case 12:
 /* rule 12 can match eol */
 YY_RULE_SETUP
-#line 153 "libxlu_disk_l.l"
+#line 177 "libxlu_disk_l.l"
 { xlu__disk_err(DPC,yytext,"unknown parameter"); }
        YY_BREAK
 /* deprecated prefixes */
@@ -1295,7 +1319,7 @@ YY_RULE_SETUP
    * matched the whole string, so these patterns take precedence */
 case 13:
 YY_RULE_SETUP
-#line 160 "libxlu_disk_l.l"
+#line 184 "libxlu_disk_l.l"
 {
                     STRIP(':');
                     DPC->had_depr_prefix=1; DEPRECATE("use `[format=]...,'");
@@ -1304,7 +1328,7 @@ YY_RULE_SETUP
        YY_BREAK
 case 14:
 YY_RULE_SETUP
-#line 166 "libxlu_disk_l.l"
+#line 190 "libxlu_disk_l.l"
 {
                    STRIP(':');
                     DPC->had_depr_prefix=1; DEPRECATE("use `script=...'");
@@ -1316,12 +1340,12 @@ case 15:
 yyg->yy_c_buf_p = yy_cp = yy_bp + 8;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 172 "libxlu_disk_l.l"
+#line 196 "libxlu_disk_l.l"
 { DPC->had_depr_prefix=1; DEPRECATE(0); }
        YY_BREAK
 case 16:
 YY_RULE_SETUP
-#line 173 "libxlu_disk_l.l"
+#line 197 "libxlu_disk_l.l"
 { DPC->had_depr_prefix=1; DEPRECATE(0); }
        YY_BREAK
 case 17:
@@ -1329,7 +1353,7 @@ case 17:
 yyg->yy_c_buf_p = yy_cp = yy_bp + 4;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 174 "libxlu_disk_l.l"
+#line 198 "libxlu_disk_l.l"
 { DPC->had_depr_prefix=1; DEPRECATE(0); }
        YY_BREAK
 case 18:
@@ -1337,7 +1361,7 @@ case 18:
 yyg->yy_c_buf_p = yy_cp = yy_bp + 6;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 175 "libxlu_disk_l.l"
+#line 199 "libxlu_disk_l.l"
 { DPC->had_depr_prefix=1; DEPRECATE(0); }
        YY_BREAK
 case 19:
@@ -1345,7 +1369,7 @@ case 19:
 yyg->yy_c_buf_p = yy_cp = yy_bp + 5;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 176 "libxlu_disk_l.l"
+#line 200 "libxlu_disk_l.l"
 { DPC->had_depr_prefix=1; DEPRECATE(0); }
        YY_BREAK
 case 20:
@@ -1353,13 +1377,13 @@ case 20:
 yyg->yy_c_buf_p = yy_cp = yy_bp + 4;
 YY_DO_BEFORE_ACTION; /* set up yytext again */
 YY_RULE_SETUP
-#line 177 "libxlu_disk_l.l"
+#line 201 "libxlu_disk_l.l"
 { DPC->had_depr_prefix=1; DEPRECATE(0); }
        YY_BREAK
 case 21:
 /* rule 21 can match eol */
 YY_RULE_SETUP
-#line 179 "libxlu_disk_l.l"
+#line 203 "libxlu_disk_l.l"
 {
                  xlu__disk_err(DPC,yytext,"unknown deprecated disk prefix");
                  return 0;
@@ -1369,9 +1393,8 @@ YY_RULE_SETUP
 case 22:
 /* rule 22 can match eol */
 YY_RULE_SETUP
-#line 186 "libxlu_disk_l.l"
+#line 210 "libxlu_disk_l.l"
 {
-    char *colon;
     STRIP(',');
 
     if (DPC->err) {
@@ -1382,19 +1405,8 @@ YY_RULE_SETUP
                DPC->disk->format == LIBXL_DISK_FORMAT_UNKNOWN) {
         setformat(DPC,yytext);
     } else if (!DPC->disk->vdev) {
-        colon = strrchr(yytext, ':');
-        if (colon) {
-            DEPRECATE("use `devtype=...'");
-            *colon++ = 0;
-            if (!strcmp(colon,"cdrom")) {
-                DPC->disk->is_cdrom = 1;
-            } else if (!strcmp(colon,"disk")) {
-                DPC->disk->is_cdrom = 0;
-            } else {
-                xlu__disk_err(DPC,colon,"unknown deprecated type");
-            }
-        }
-        SAVESTRING("vdev", vdev, yytext);
+        if (!vdev_and_devtype(DPC,yytext))
+            SAVESTRING("vdev", vdev, yytext);
     } else if (!DPC->access_set) {
         DPC->access_set = 1;
         setaccess(DPC,yytext);
@@ -1406,7 +1418,7 @@ YY_RULE_SETUP
        YY_BREAK
 case 23:
 YY_RULE_SETUP
-#line 220 "libxlu_disk_l.l"
+#line 232 "libxlu_disk_l.l"
 {
     BEGIN(LEXERR);
     yymore();
@@ -1414,17 +1426,17 @@ YY_RULE_SETUP
        YY_BREAK
 case 24:
 YY_RULE_SETUP
-#line 224 "libxlu_disk_l.l"
+#line 236 "libxlu_disk_l.l"
 {
     xlu__disk_err(DPC,yytext,"bad disk syntax"); return 0;
 }
        YY_BREAK
 case 25:
 YY_RULE_SETUP
-#line 227 "libxlu_disk_l.l"
+#line 239 "libxlu_disk_l.l"
 YY_FATAL_ERROR( "flex scanner jammed" );
        YY_BREAK
-#line 1428 "libxlu_disk_l.c"
+#line 1440 "libxlu_disk_l.c"
                        case YY_STATE_EOF(INITIAL):
                        case YY_STATE_EOF(LEXERR):
                                yyterminate();
@@ -2516,12 +2528,4 @@ void xlu__disk_yyfree (void * ptr , yyscan_t yyscanner)
 
 #define YYTABLES_NAME "yytables"
 
-#line 227 "libxlu_disk_l.l"
-
-/*
- * Local variables:
- * mode: C
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
+#line 239 "libxlu_disk_l.l"
diff --git a/tools/libxl/libxlu_disk_l.h b/tools/libxl/libxlu_disk_l.h
index a3fbd72..72b82cb 100644
--- a/tools/libxl/libxlu_disk_l.h
+++ b/tools/libxl/libxlu_disk_l.h
@@ -340,16 +340,8 @@ extern int xlu__disk_yylex (yyscan_t yyscanner);
 #undef YY_DECL
 #endif
 
-#line 227 "libxlu_disk_l.l"
+#line 239 "libxlu_disk_l.l"
 
 #line 346 "libxlu_disk_l.h"
 #undef xlu__disk_yyIN_HEADER
 #endif /* xlu__disk_yyHEADER_H */
-
-/*
- * Local variables:
- * mode: C
- * c-basic-offset: 4
- * indent-tabs-mode: nil
- * End:
- */
diff --git a/tools/libxl/libxlu_disk_l.l b/tools/libxl/libxlu_disk_l.l
index a3e7180..9fbc1ad 100644
--- a/tools/libxl/libxlu_disk_l.l
+++ b/tools/libxl/libxlu_disk_l.l
@@ -45,8 +45,6 @@ void xlu__disk_yyset_column(int  column_no, yyscan_t 
yyscanner);
  * and particularly to avoid repeating boilerplate values such as
  * DPC->disk, yytext, etc. */
 
-#define DPC ((DiskParseContext*)yyextra)
-
 /* Sets an enum, checking it hasn't already been set to a different value  */
 #define DSET(dpc,member,enumname,str,valname) do{                      \
        if (dpc->disk->member != LIBXL_DISK_##enumname##_UNKNOWN &&     \
@@ -79,6 +77,8 @@ static void savestring(DiskParseContext *dpc, const char 
*what_respecified,
     *update = strdup(value);
 }
 
+#define DPC dpc /* our convention in lexer helper functions */
+
 /* Sets ->readwrite from the string.  This ought to be an enum, perhaps. */
 static void setaccess(DiskParseContext *dpc, const char *str) {
     if (!strcmp(str, "r") || !strcmp(str, "ro")) {
@@ -110,6 +110,30 @@ static void setbackendtype(DiskParseContext *dpc, const 
char *str) {
 
 #define DEPRECATE(usewhatinstead) /* not currently reported */
 
+/* Handles a vdev positional parameter which includes a devtype. */
+static int vdev_and_devtype(DiskParseContext *dpc, char *str) {
+    /* returns 1 if it was <vdev>:<devtype>, 0 (doing nothing) otherwise */
+    char *colon = strrchr(str, ':');
+    if (!colon)
+        return 0;
+
+    DEPRECATE("use `devtype=...'");
+    *colon++ = 0;
+    SAVESTRING("vdev", vdev, str);
+
+    if (!strcmp(colon,"cdrom")) {
+        DPC->disk->is_cdrom = 1;
+    } else if (!strcmp(colon,"disk")) {
+        DPC->disk->is_cdrom = 0;
+    } else {
+        xlu__disk_err(DPC,colon,"unknown deprecated type");
+    }
+    return 1;
+}
+
+#undef DPC /* needs to be defined differently the actual lexer */
+#define DPC ((DiskParseContext*)yyextra)
+
 %}
 
 %option warn
@@ -184,7 +208,6 @@ phy:/.*             { DPC->had_depr_prefix=1; DEPRECATE(0); 
}
  /* positional parameters */
 
 [^=,]*,|[^=,]+,?  {
-    char *colon;
     STRIP(',');
 
     if (DPC->err) {
@@ -195,19 +218,8 @@ phy:/.*            { DPC->had_depr_prefix=1; DEPRECATE(0); 
}
                DPC->disk->format == LIBXL_DISK_FORMAT_UNKNOWN) {
         setformat(DPC,yytext);
     } else if (!DPC->disk->vdev) {
-        colon = strrchr(yytext, ':');
-        if (colon) {
-            DEPRECATE("use `devtype=...'");
-            *colon++ = 0;
-            if (!strcmp(colon,"cdrom")) {
-                DPC->disk->is_cdrom = 1;
-            } else if (!strcmp(colon,"disk")) {
-                DPC->disk->is_cdrom = 0;
-            } else {
-                xlu__disk_err(DPC,colon,"unknown deprecated type");
-            }
-        }
-        SAVESTRING("vdev", vdev, yytext);
+        if (!vdev_and_devtype(DPC,yytext))
+            SAVESTRING("vdev", vdev, yytext);
     } else if (!DPC->access_set) {
         DPC->access_set = 1;
         setaccess(DPC,yytext);
-- 
1.7.2.5


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.