]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
LXC from native: convert lxc.tty to console devices
authorCédric Bosdonnat <cbosdonnat@suse.com>
Wed, 5 Feb 2014 14:10:06 +0000 (15:10 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 12 Feb 2014 17:52:46 +0000 (17:52 +0000)
src/lxc/lxc_native.c
tests/lxcconf2xmldata/lxcconf2xml-simple.xml

index 2e4245535cc33ef12fa342d3a4808a90a05c7f49..10a371f4c0f7df711124ab1d12f805bb48c83d2b 100644 (file)
@@ -503,6 +503,46 @@ lxcConvertNetworkSettings(virDomainDefPtr def, virConfPtr properties)
     return 0;
 }
 
+static int
+lxcCreateConsoles(virDomainDefPtr def, virConfPtr properties)
+{
+    virConfValuePtr value;
+    int nbttys = 0;
+    virDomainChrDefPtr console;
+    size_t i;
+
+    if (!(value = virConfGetValue(properties, "lxc.tty")) || !value->str)
+        return 0;
+
+    if (virStrToLong_i(value->str, NULL, 10, &nbttys) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, _("failed to parse int: '%s'"),
+                       value->str);
+        return -1;
+    }
+
+    if (VIR_ALLOC_N(def->consoles, nbttys) < 0)
+        return -1;
+
+    def->nconsoles = nbttys;
+    for (i = 0; i < nbttys; i++) {
+        if (!(console = virDomainChrDefNew()))
+            goto error;
+
+        console->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
+        console->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LXC;
+        console->target.port = i;
+        console->source.type = VIR_DOMAIN_CHR_TYPE_PTY;
+
+        def->consoles[i] = console;
+    }
+
+    return 0;
+
+error:
+    virDomainChrDefFree(console);
+    return -1;
+}
+
 virDomainDefPtr
 lxcParseConfigString(const char *config)
 {
@@ -567,6 +607,10 @@ lxcParseConfigString(const char *config)
     if (lxcConvertNetworkSettings(vmdef, properties) < 0)
         goto error;
 
+    /* Consoles */
+    if (lxcCreateConsoles(vmdef, properties) < 0)
+        goto error;
+
     goto cleanup;
 
 error:
index 75c3b2809fce21fff9d09e027445d59a6b79e82e..711e0d91d5053e65554784a71beb762dc4a1d4e2 100644 (file)
       <source bridge='virbr0'/>
       <link state='up'/>
     </interface>
+    <console type='pty'>
+      <target type='lxc' port='0'/>
+    </console>
+    <console type='pty'>
+      <target type='lxc' port='1'/>
+    </console>
   </devices>
 </domain>