Skip to contentSkip to conversation

libxl: Support cmdline= in xl config files

PATCH Ian Campbell 2 participants 3 messages Jan 19, 2016 – Jan 20, 2016 2 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

I went to ping this but noticed that I had sent it to "jimfehlig" (i.e. no domain), so no wonder there was no reply!

To: line fixed here, let me know if you would prefer a resend.

Ian.

Quoted 105 lines · Ian Campbell

... and consolidate the cmdline/extra/root parsing to facilitate doing so.

The logic is the same as xl's parse_cmdline from the current xen.git master branch (e6f0e099d2c17de47fd86e817b1998db903cab61), except I was unable to figure out how/where to route the warning about ignoring root+extra if cmdline was specified.

---
 src/xenconfig/xen_xl.c | 62 ++++++++++++++++++++++++++++++------------
--------

 1 file changed, 37 insertions(+), 25 deletions(-)
src/xenconfig/xen_xl.c +0 -0
index 91cdff6..ba8b938 100644
@@ -58,11 +58,45 @@ extern int xlu_disk_parse(XLU_Config *cfg,
                            libxl_device_disk *disk);
  #endif

src/xenconfig/xen_xl.c +35 -0
+static int xenParseCmdline(virConfPtr conf, char **r_cmdline)
+{
+    char *cmdline = NULL;
+    const char *root = NULL, *extra = NULL, *buf = NULL;
+
+    if (xenConfigGetString(conf, "cmdline", &buf, NULL) < 0)
+        return -1;
+
+    if (xenConfigGetString(conf, "root", &root, NULL) < 0)
+        return -1;
+
+    if (xenConfigGetString(conf, "extra", &extra, NULL) < 0)
+        return -1;
+
+    if (buf) {
+        if (VIR_STRDUP(cmdline, buf) < 0)
+            return -1;
+        /* root or extra are ignored in this case. */
+    } else {
+        if (root && extra) {
+            if (virAsprintf(&cmdline, "root=%s %s", root, extra) < 0)
+                return -1;
+        } else if (root) {
+            if (virAsprintf(&cmdline, "root=%s", root) < 0)
+                return -1;
+        } else if (extra) {
+            if (VIR_STRDUP(cmdline, extra) < 0)
+                return -1;
+        }
+    }
+
+    *r_cmdline = cmdline;
+    return 0;
+}
+

 static int
 xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) {
     size_t i;
-    const char *extra, *root;

     if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         const char *boot;

src/xenconfig/xen_xl.c +0 -0
@@ -84,19 +118,8 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def,
 virCapsPtr caps)

         if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) <
0)
             return -1;

-        if (xenConfigGetString(conf, "extra", &extra, NULL) < 0) -            return -1;
-
-        if (xenConfigGetString(conf, "root", &root, NULL) < 0) +        if (xenParseCmdline(conf, &def->os.cmdline) < 0) return -1;
-
-        if (root) {
-            if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
-                return -1;
-        } else {
-            if (VIR_STRDUP(def->os.cmdline, extra) < 0)
-                return -1;
-        }
 #endif

         if (xenConfigGetString(conf, "boot", &boot, "c") < 0)

src/xenconfig/xen_xl.c +0 -0
@@ -132,19 +155,8 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def,
 virCapsPtr caps)

         if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) <
0)
             return -1;

-        if (xenConfigGetString(conf, "extra", &extra, NULL) < 0) -            return -1;
-
-        if (xenConfigGetString(conf, "root", &root, NULL) < 0) +        if (xenParseCmdline(conf, &def->os.cmdline) < 0) return -1;
-
-        if (root) {
-            if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)

Quoted 8 lines

-                return -1;
-        } else {
-            if (VIR_STRDUP(def->os.cmdline, extra) < 0) -                return -1;
-        }
     }

     return 0;

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

#2 lore raw
Quoted 4 lines · Ian Campbell

I went to ping this but noticed that I had sent it to "jimfehlig" (i.e. no domain), so no wonder there was no reply!

To: line fixed here, let me know if you would prefer a resend.

That would be much appreciated, thanks!

Quoted 11 lines

Ian.

Quoted 7 lines · Ian Campbell

... and consolidate the cmdline/extra/root parsing to facilitate doing so.

The logic is the same as xl's parse_cmdline from the current xen.git master branch (e6f0e099d2c17de47fd86e817b1998db903cab61), except I was unable to figure out how/where to route the warning about ignoring root+extra if cmdline was specified.

I think VIR_WARN() would be appropriate.

Quoted 15 lines
Quoted 15 lines
---
 src/xenconfig/xen_xl.c | 62 ++++++++++++++++++++++++++++++------------
--------
 1 file changed, 37 insertions(+), 25 deletions(-)
src/xenconfig/xen_xl.c +0 -0
index 91cdff6..ba8b938 100644
@@ -58,11 +58,45 @@ extern int xlu_disk_parse(XLU_Config *cfg,
                           libxl_device_disk *disk);
 #endif
 
Quoted 4 lines

src/xenconfig/xen_xl.c extern int xlu_disk_parse(XLU_Config *cfg, · line 64

Quoted 4 lines
src/xenconfig/xen_xl.c +4 -0
+static int xenParseCmdline(virConfPtr conf, char **r_cmdline)
+{
+    char *cmdline = NULL;
+    const char *root = NULL, *extra = NULL, *buf = NULL;

In theory, these three don't need to be initialized since xenConfigGetString will do that. But in practice, I worry that Coverity might complain :-/.

Regards,
Jim

Quoted 91 lines
Quoted 84 lines
src/xenconfig/xen_xl.c +32 -13
+
+    if (xenConfigGetString(conf, "cmdline", &buf, NULL) < 0)
+        return -1;
+
+    if (xenConfigGetString(conf, "root", &root, NULL) < 0)
+        return -1;
+
+    if (xenConfigGetString(conf, "extra", &extra, NULL) < 0)
+        return -1;
+
+    if (buf) {
+        if (VIR_STRDUP(cmdline, buf) < 0)
+            return -1;
+        /* root or extra are ignored in this case. */
+    } else {
+        if (root && extra) {
+            if (virAsprintf(&cmdline, "root=%s %s", root, extra) < 0)
+                return -1;
+        } else if (root) {
+            if (virAsprintf(&cmdline, "root=%s", root) < 0)
+                return -1;
+        } else if (extra) {
+            if (VIR_STRDUP(cmdline, extra) < 0)
+                return -1;
+        }
+    }
+
+    *r_cmdline = cmdline;
+    return 0;
+}
+
 static int
 xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
 {
     size_t i;
-    const char *extra, *root;
 
     if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         const char *boot;
@@ -84,19 +118,8 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def,
 virCapsPtr caps)
         if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) <
 0)
             return -1;
 
-        if (xenConfigGetString(conf, "extra", &extra, NULL) < 0)
-            return -1;
-
-        if (xenConfigGetString(conf, "root", &root, NULL) < 0)
+        if (xenParseCmdline(conf, &def->os.cmdline) < 0)
             return -1;
-
-        if (root) {
-            if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra)
 < 0)
-                return -1;
-        } else {
-            if (VIR_STRDUP(def->os.cmdline, extra) < 0)
-                return -1;
-        }

#endif

         if (xenConfigGetString(conf, "boot", &boot, "c") < 0)
src/xenconfig/xen_xl.c +1 -12
@@ -132,19 +155,8 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def,
 virCapsPtr caps)
         if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) <
 0)
             return -1;
 
-        if (xenConfigGetString(conf, "extra", &extra, NULL) < 0)
-            return -1;
-
-        if (xenConfigGetString(conf, "root", &root, NULL) < 0)
+        if (xenParseCmdline(conf, &def->os.cmdline) < 0)
             return -1;
-
-        if (root) {
-            if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra)
 < 0)
-                return -1;
-        } else {
-            if (VIR_STRDUP(def->os.cmdline, extra) < 0)
-                return -1;
-        }
Quoted 3 lines
     }
 
     return 0;

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

A message that is not in the archive (sent off-list or not yet received): [email protected]

#4 lore raw
Quoted 17 lines · Jim Fehlig
Quoted 5 lines · Ian Campbell

I went to ping this but noticed that I had sent it to "jimfehlig" (i.e. no
domain), so no wonder there was no reply!

To: line fixed here, let me know if you would prefer a resend.

That would be much appreciated, thanks!

Quoted 8 lines

Ian.

Quoted 4 lines · Ian Campbell

... and consolidate the cmdline/extra/root parsing to facilitate doing
so.

Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

The logic is the same as xl's parse_cmdline from the current xen.git master
branch (e6f0e099d2c17de47fd86e817b1998db903cab61), except I was unable
to figure out how/where to route the warning about ignoring root+extra if cmdline was specified.

I think VIR_WARN() would be appropriate.

Ok, will do, thanks.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

---
 src/xenconfig/xen_xl.c | 62 ++++++++++++++++++++++++++++++--------
----
--------

 1 file changed, 37 insertions(+), 25 deletions(-)
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
src/xenconfig/xen_xl.c +0 -0
index 91cdff6..ba8b938 100644
Quoted 8 lines

src/xenconfig/xen_xl.c

Quoted 8 lines
src/xenconfig/xen_xl.c +0 -0
@@ -58,11 +58,45 @@ extern int xlu_disk_parse(XLU_Config *cfg,
                            libxl_device_disk *disk);
  #endif

src/xenconfig/xen_xl.c +4 -0
+static int xenParseCmdline(virConfPtr conf, char **r_cmdline)
+{
+    char *cmdline = NULL;
+    const char *root = NULL, *extra = NULL, *buf = NULL;

In theory, these three don't need to be initialized since xenConfigGetString
will do that. But in practice, I worry that Coverity might complain :-/.

It looks like some of the callers of xenConfigGetString initialise the value to NULL, while others don't. I can't see any public libvirt scan results to look if some of the ones which don't have been picked up or not.

I've just noticed also that the code I am moving/removing didn't initialise to NULL, so I think I'll remove these initialisers.

Ian.

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