Skip to contentSkip to conversation

libxl: Set path to console on domain startup

PATCH In review Anthony PERARD 5 participants 11 messages Dec 5, 2014 – Dec 9, 2014 5 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: Set path to console on domain startup

Hi,

I'm trying to fix an issue when using OpenStack with libvirt+xen (libxenlight). OpenStack cannot access the console output of a Xen PV guest, because the XML generated by libvirt for a domain is missing the path to the pty. The path actually appear in the XML once one call virDomainOpenConsole().

The patch intend to get the path to the pty without having to call virDomainOpenConsole, so I've done the work in libxlDomainStart(). So I have a few question:
Is libxlDomainStart will be called on restore/migrate/reboot?
I guest the function libxlDomainOpenConsole() would not need to do the same work if the console path is settup properly.

There is a bug report about this:
https://bugzilla.redhat.com/show_bug.cgi?id=1170743

Regards,

Anthony PERARD (1):
libxl: Set path to console on domain startup.

 src/libxl/libxl_domain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Signature · 1 line
Anthony PERARD
#1 lore raw

PATCH 1/1 libxl: Set path to console on domain startup.

The path to the pty of a Xen PV console is set only in virDomainOpenConsole. But this is done too late. A call to virDomainGetXMLDesc done before OpenConsole will not have the path to the pty, but a call after OpenConsole will.

e.g. of the current issue.
Starting a domain with '<console type="pty"/>'
Then:
virDomainGetXMLDesc():
<devices>

    <console type='pty'>
      <target type='xen' port='0'/>
    </console>

</devices>
virDomainOpenConsole()
virDomainGetXMLDesc():
<devices>

    <console type='pty' tty='/dev/pts/30'>
      <source path='/dev/pts/30'/>
      <target type='xen' port='0'/>
    </console>

</devices>

The patch intend to get the tty path on the first call of GetXMLDesc.

---
 src/libxl/libxl_domain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
src/libxl/libxl_domain.c +17 -0
index 9c62291..de56054 100644
@@ -1290,6 +1290,23 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
     if (libxlDomainSetVcpuAffinities(driver, vm) < 0)
         goto cleanup_dom;
 
+    if (vm->def->nconsoles) {
+        virDomainChrDefPtr chr = NULL;
+        chr = vm->def->consoles[0];
+        if (chr && chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) {
+            libxl_console_type console_type;
+            char *console = NULL;
+            console_type =
+                (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ?
+                 LIBXL_CONSOLE_TYPE_SERIAL : LIBXL_CONSOLE_TYPE_PV);
+            ret = libxl_console_get_tty(priv->ctx, vm->def->id, chr->target.port,
+                                        console_type, &console);
+            if (!ret)
+                ignore_value(VIR_STRDUP(chr->source.data.file.path, console));
+            VIR_FREE(console);
+        }
+    }
+
     if (!start_paused) {
         libxl_domain_unpause(priv->ctx, domid);
         virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
Signature · 1 line
Anthony PERARD

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

#3 lore raw

Re: [PATCH] libxl: Set path to console on domain startup.

Not really familiar with libvirt, but...

Quoted 35 lines · On Fri, 5 Dec 2014 16:30:06 +0000 Anthony PERARD <[email protected]>…

The path to the pty of a Xen PV console is set only in virDomainOpenConsole. But this is done too late. A call to virDomainGetXMLDesc done before OpenConsole will not have the path to the pty, but a call after OpenConsole will.

e.g. of the current issue.
Starting a domain with '<console type="pty"/>'
Then:
virDomainGetXMLDesc():
<devices>

    <console type='pty'>
      <target type='xen' port='0'/>
    </console>

</devices>
virDomainOpenConsole()
virDomainGetXMLDesc():
<devices>

    <console type='pty' tty='/dev/pts/30'>
      <source path='/dev/pts/30'/>
      <target type='xen' port='0'/>
    </console>

</devices>

The patch intend to get the tty path on the first call of GetXMLDesc.

---
 src/libxl/libxl_domain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
src/libxl/libxl_domain.c +0 -0
index 9c62291..de56054 100644

src/libxl/libxl_domain.c libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, · line 1294

Quoted 5 lines
src/libxl/libxl_domain.c +2 -0
@@ -1290,6 +1290,23 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
     if (libxlDomainSetVcpuAffinities(driver, vm) < 0)
         goto cleanup_dom;
 
+    if (vm->def->nconsoles) {
+        virDomainChrDefPtr chr = NULL;

Pointless initializer. Possibly combine with following statement.

-d

Quoted 27 lines
src/libxl/libxl_domain.c +15 -0
+        chr = vm->def->consoles[0];
+        if (chr && chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) {
+            libxl_console_type console_type;
+            char *console = NULL;
+            console_type =
+                (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ?
+                 LIBXL_CONSOLE_TYPE_SERIAL : LIBXL_CONSOLE_TYPE_PV);
+            ret = libxl_console_get_tty(priv->ctx, vm->def->id, chr->target.port,
+                                        console_type, &console);
+            if (!ret)
+                ignore_value(VIR_STRDUP(chr->source.data.file.path, console));
+            VIR_FREE(console);
+        }
+    }
+
     if (!start_paused) {
         libxl_domain_unpause(priv->ctx, domid);
         virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
Signature · 7 lines
Anthony PERARD


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

Re: [PATCH] libxl: Set path to console on domain startup.

In reply to a message not in the archive

On Fri, 2014-12-05 at 16:30 +0000, Anthony PERARD wrote:

Jim Fehlig maintains the libxl driver in libvirt, so you should CC him (I've done so here...)

Quoted 17 lines

The path to the pty of a Xen PV console is set only in virDomainOpenConsole. But this is done too late. A call to virDomainGetXMLDesc done before OpenConsole will not have the path to the pty, but a call after OpenConsole will.

e.g. of the current issue.
Starting a domain with '<console type="pty"/>'
Then:
virDomainGetXMLDesc():
<devices>

    <console type='pty'>
      <target type='xen' port='0'/>
    </console>

</devices>
virDomainOpenConsole()
virDomainGetXMLDesc():
<devices>

Quoted 7 lines
    <console type='pty' tty='/dev/pts/30'>
      <source path='/dev/pts/30'/>
      <target type='xen' port='0'/>
    </console>

</devices>

The patch intend to get the tty path on the first call of GetXMLDesc.

Doesn't it actually do it on domain start (which makes more sense to me anyway).

Quoted 17 lines
---
 src/libxl/libxl_domain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
src/libxl/libxl_domain.c +3 -0
index 9c62291..de56054 100644
@@ -1290,6 +1290,23 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
     if (libxlDomainSetVcpuAffinities(driver, vm) < 0)
         goto cleanup_dom;
 
+    if (vm->def->nconsoles) {
+        virDomainChrDefPtr chr = NULL;
+        chr = vm->def->consoles[0];

src/libxl/libxl_domain.c libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, · line 1305

Quoted 10 lines
src/libxl/libxl_domain.c +10 -0
+        if (chr && chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) {
+            libxl_console_type console_type;
+            char *console = NULL;
+            console_type =
+                (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ?
+                 LIBXL_CONSOLE_TYPE_SERIAL : LIBXL_CONSOLE_TYPE_PV);
+            ret = libxl_console_get_tty(priv->ctx, vm->def->id, chr->target.port,
+                                        console_type, &console);
+            if (!ret)
+                ignore_value(VIR_STRDUP(chr->source.data.file.path, console));

libxlDomainOpenConsole will strdup another (well, probably the same) value here, causing a leak I think, so you'll need some check there too I expect.

Quoted 7 lines
src/libxl/libxl_domain.c +4 -0
+            VIR_FREE(console);
+        }
+    }
+
     if (!start_paused) {
         libxl_domain_unpause(priv->ctx, domid);
         virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);

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

#6 lore raw

Re: [PATCH] libxl: Set path to console on domain startup.

Quoted 4 lines · Ian Campbell

On Fri, 2014-12-05 at 16:30 +0000, Anthony PERARD wrote:

Jim Fehlig maintains the libxl driver in libvirt, so you should CC him (I've done so here...)

Thanks.

Quoted 23 lines
Quoted 23 lines

The path to the pty of a Xen PV console is set only in virDomainOpenConsole. But this is done too late. A call to virDomainGetXMLDesc done before OpenConsole will not have the path to the pty, but a call after OpenConsole will.

e.g. of the current issue.
Starting a domain with '<console type="pty"/>'
Then:
virDomainGetXMLDesc():
<devices>

    <console type='pty'>
      <target type='xen' port='0'/>
    </console>

</devices>
virDomainOpenConsole()
virDomainGetXMLDesc():
<devices>

    <console type='pty' tty='/dev/pts/30'>
      <source path='/dev/pts/30'/>
      <target type='xen' port='0'/>
    </console>

</devices>

Quoted 4 lines
Quoted 1 line

The patch intend to get the tty path on the first call of GetXMLDesc.

Doesn't it actually do it on domain start (which makes more sense to me anyway).

Just a wording issue. I meant: Have GetXMLDesc always return the path to the tty.

Quoted 23 lines
Quoted 23 lines
---
 src/libxl/libxl_domain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
src/libxl/libxl_domain.c +9 -0
index 9c62291..de56054 100644
@@ -1290,6 +1290,23 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
     if (libxlDomainSetVcpuAffinities(driver, vm) < 0)
         goto cleanup_dom;
 
+    if (vm->def->nconsoles) {
+        virDomainChrDefPtr chr = NULL;
+        chr = vm->def->consoles[0];
+        if (chr && chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) {
+            libxl_console_type console_type;
+            char *console = NULL;
+            console_type =
+                (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ?
+                 LIBXL_CONSOLE_TYPE_SERIAL : LIBXL_CONSOLE_TYPE_PV);
Quoted 8 lines

src/libxl/libxl_domain.c libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, · line 1305

Quoted 4 lines
src/libxl/libxl_domain.c +4 -0
+            ret = libxl_console_get_tty(priv->ctx, vm->def->id, chr->target.port,
+                                        console_type, &console);
+            if (!ret)
+                ignore_value(VIR_STRDUP(chr->source.data.file.path, console));

libxlDomainOpenConsole will strdup another (well, probably the same) value here, causing a leak I think, so you'll need some check there too I expect.

So, if OpenConsole is call twice, there will also be a leak? Or maybe it can not be called twice.

Anyway, I though from the use of VIR_STRDUP there that it was safe to call VIR_STRDUP several times and it well free the destination. I might be wrong.

Quoted 7 lines
Quoted 7 lines
src/libxl/libxl_domain.c +4 -0
+            VIR_FREE(console);
+        }
+    }
+
     if (!start_paused) {
         libxl_domain_unpause(priv->ctx, domid);
         virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);
Signature · 1 line
Anthony PERARD

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

#8 lore raw

Re: [PATCH] libxl: Set path to console on domain startup.

Quoted 8 lines · Anthony PERARD
Quoted 4 lines
Quoted 1 line

The patch intend to get the tty path on the first call of GetXMLDesc.

Doesn't it actually do it on domain start (which makes more sense to me anyway).

Just a wording issue. I meant: Have GetXMLDesc always return the path to the tty.

Ah, yes, I get what you meant now.

Quoted 32 lines
Quoted 23 lines
Quoted 23 lines
---
 src/libxl/libxl_domain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
src/libxl/libxl_domain.c +9 -0
index 9c62291..de56054 100644
@@ -1290,6 +1290,23 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
     if (libxlDomainSetVcpuAffinities(driver, vm) < 0)
         goto cleanup_dom;
 
+    if (vm->def->nconsoles) {
+        virDomainChrDefPtr chr = NULL;
+        chr = vm->def->consoles[0];
+        if (chr && chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) {
+            libxl_console_type console_type;
+            char *console = NULL;
+            console_type =
+                (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ?
+                 LIBXL_CONSOLE_TYPE_SERIAL : LIBXL_CONSOLE_TYPE_PV);
Quoted 8 lines

src/libxl/libxl_domain.c libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, · line 1305

Quoted 4 lines
src/libxl/libxl_domain.c +4 -0
+            ret = libxl_console_get_tty(priv->ctx, vm->def->id, chr->target.port,
+                                        console_type, &console);
+            if (!ret)
+                ignore_value(VIR_STRDUP(chr->source.data.file.path, console));

libxlDomainOpenConsole will strdup another (well, probably the same) value here, causing a leak I think, so you'll need some check there too I expect.

Quoted 2 lines

So, if OpenConsole is call twice, there will also be a leak? Or maybe it can not be called twice.

I'm not sure, there may be an existing issue here I suppose.

Quoted 3 lines

Anyway, I though from the use of VIR_STRDUP there that it was safe to call VIR_STRDUP several times and it well free the destination. I might be wrong.

I wondered about that, but AFAICS VIR_STRDUP is a wrapper around virStrdup and virStrdup doesn't free any existing destination.

Ian.

#9 lore raw

Re: [libvirt] [PATCH] libxl: Set path to console on domain startup.

In reply to a message not in the archive
Quoted 5 lines · Anthony PERARD

The path to the pty of a Xen PV console is set only in virDomainOpenConsole. But this is done too late. A call to virDomainGetXMLDesc done before OpenConsole will not have the path to the pty, but a call after OpenConsole will.

Hi Anthony,

Thanks for the patch. Can you address the comments made by others, my comments below, and provide a V2?

Quoted 37 lines

e.g. of the current issue.
Starting a domain with '<console type="pty"/>'
Then:
virDomainGetXMLDesc():
<devices>

    <console type='pty'>
      <target type='xen' port='0'/>
    </console>

</devices>
virDomainOpenConsole()
virDomainGetXMLDesc():
<devices>

    <console type='pty' tty='/dev/pts/30'>
      <source path='/dev/pts/30'/>
      <target type='xen' port='0'/>
    </console>

</devices>

The patch intend to get the tty path on the first call of GetXMLDesc.

---
 src/libxl/libxl_domain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
src/libxl/libxl_domain.c +4 -0
index 9c62291..de56054 100644
@@ -1290,6 +1290,23 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
     if (libxlDomainSetVcpuAffinities(driver, vm) < 0)
         goto cleanup_dom;
 
+    if (vm->def->nconsoles) {
+        virDomainChrDefPtr chr = NULL;
+        chr = vm->def->consoles[0];
+        if (chr && chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) {

src/libxl/libxl_domain.c libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, · line 1306

Quoted 10 lines
src/libxl/libxl_domain.c +9 -0
+            libxl_console_type console_type;
+            char *console = NULL;
+            console_type =
+                (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ?
+                 LIBXL_CONSOLE_TYPE_SERIAL : LIBXL_CONSOLE_TYPE_PV);
+            ret = libxl_console_get_tty(priv->ctx, vm->def->id, chr->target.port,
+                                        console_type, &console);
+            if (!ret)
+                ignore_value(VIR_STRDUP(chr->source.data.file.path, console));
 

VIR_STRDUP will not free an existing value. You should VIR_FREE first, which btw can handle a NULL argument. And since you're initializing source.data.file.path when starting the domain, I think we can drop the similar code in libxlDomainOpenConsole().

Regards,
Jim

Quoted 8 lines
src/libxl/libxl_domain.c +4 -0
+            VIR_FREE(console);
+        }
+    }
+
     if (!start_paused) {
         libxl_domain_unpause(priv->ctx, domid);
         virDomainObjSetState(vm, VIR_DOMAIN_RUNNING, VIR_DOMAIN_RUNNING_BOOTED);

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

#11 lore raw

Re: [libvirt] [PATCH] libxl: Set path to console on domain startup.

Quoted 11 lines · Jim Fehlig
Quoted 5 lines · Anthony PERARD

The path to the pty of a Xen PV console is set only in virDomainOpenConsole. But this is done too late. A call to virDomainGetXMLDesc done before OpenConsole will not have the path to the pty, but a call after OpenConsole will.

Hi Anthony,

Thanks for the patch. Can you address the comments made by others, my comments below, and provide a V2?

Will do.

Quoted 44 lines
Quoted 44 lines

e.g. of the current issue.
Starting a domain with '<console type="pty"/>'
Then:
virDomainGetXMLDesc():
<devices>

    <console type='pty'>
      <target type='xen' port='0'/>
    </console>

</devices>
virDomainOpenConsole()
virDomainGetXMLDesc():
<devices>

    <console type='pty' tty='/dev/pts/30'>
      <source path='/dev/pts/30'/>
      <target type='xen' port='0'/>
    </console>

</devices>

The patch intend to get the tty path on the first call of GetXMLDesc.

---
 src/libxl/libxl_domain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
src/libxl/libxl_domain.c +11 -0
index 9c62291..de56054 100644
@@ -1290,6 +1290,23 @@ libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm,
     if (libxlDomainSetVcpuAffinities(driver, vm) < 0)
         goto cleanup_dom;
 
+    if (vm->def->nconsoles) {
+        virDomainChrDefPtr chr = NULL;
+        chr = vm->def->consoles[0];
+        if (chr && chr->source.type == VIR_DOMAIN_CHR_TYPE_PTY) {
+            libxl_console_type console_type;
+            char *console = NULL;
+            console_type =
+                (chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ?
+                 LIBXL_CONSOLE_TYPE_SERIAL : LIBXL_CONSOLE_TYPE_PV);
+            ret = libxl_console_get_tty(priv->ctx, vm->def->id, chr->target.port,
+                                        console_type, &console);
Quoted 8 lines

src/libxl/libxl_domain.c libxlDomainStart(libxlDriverPrivatePtr driver, virDomainObjPtr vm, · line 1306

Quoted 3 lines
src/libxl/libxl_domain.c +2 -0
+            if (!ret)
+                ignore_value(VIR_STRDUP(chr->source.data.file.path, console));
 

VIR_STRDUP will not free an existing value. You should VIR_FREE first, which btw can handle a NULL argument. And since you're initializing source.data.file.path when starting the domain, I think we can drop the similar code in libxlDomainOpenConsole().

I will do that.
Thanks,

Signature · 1 line
Anthony PERARD
#12 lore raw
In reply to Anthony PERARD
Quoted 14 lines · Anthony PERARD

Hi,

I'm trying to fix an issue when using OpenStack with libvirt+xen (libxenlight). OpenStack cannot access the console output of a Xen PV guest, because the XML generated by libvirt for a domain is missing the path to the pty. The path actually appear in the XML once one call virDomainOpenConsole().

The patch intend to get the path to the pty without having to call virDomainOpenConsole, so I've done the work in libxlDomainStart(). So I have a few question:
Is libxlDomainStart will be called on restore/migrate/reboot?
I guest the function libxlDomainOpenConsole() would not need to do the same work if the console path is settup properly.

Quoted 3 lines

There is a bug report about this:
https://bugzilla.redhat.com/show_bug.cgi?id=1170743

Hi,

you can leave the bugzilla link in the commit message, if somebody ever needs more context.

(And the patch looks good to me, but I'm no libxl expert)

Jan

Quoted 8 lines

Regards,

Anthony PERARD (1):
libxl: Set path to console on domain startup.

 src/libxl/libxl_domain.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

_______________________________________________
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]

#14 lore raw
Quoted 15 lines · Ján Tomko
Quoted 14 lines · Anthony PERARD

Hi,

I'm trying to fix an issue when using OpenStack with libvirt+xen (libxenlight). OpenStack cannot access the console output of a Xen PV guest, because the XML generated by libvirt for a domain is missing the path to the pty. The path actually appear in the XML once one call virDomainOpenConsole().

The patch intend to get the path to the pty without having to call virDomainOpenConsole, so I've done the work in libxlDomainStart(). So I have a few question:
Is libxlDomainStart will be called on restore/migrate/reboot?
I guest the function libxlDomainOpenConsole() would not need to do the same work if the console path is settup properly.

Quoted 8 lines
Quoted 3 lines

There is a bug report about this:
https://bugzilla.redhat.com/show_bug.cgi?id=1170743

Hi,

you can leave the bugzilla link in the commit message, if somebody ever needs more context.

Ok.

Quoted 1 line

(And the patch looks good to me, but I'm no libxl expert)

Thanks,

Signature · 1 line
Anthony PERARD
#15 lore raw
In reply to Anthony PERARD
Quoted 7 lines · Anthony PERARD

Hi,

I'm trying to fix an issue when using OpenStack with libvirt+xen (libxenlight). OpenStack cannot access the console output of a Xen PV guest, because the XML generated by libvirt for a domain is missing the path to the pty. The path actually appear in the XML once one call virDomainOpenConsole().

Quoted 5 lines

The patch intend to get the path to the pty without having to call virDomainOpenConsole, so I've done the work in libxlDomainStart(). So I have a few question:
Is libxlDomainStart will be called on restore/migrate/reboot?

Yes.

Quoted 3 lines

I guest the function libxlDomainOpenConsole() would not need to do the same work if the console path is settup properly.

Yes, agreed.

Regards,
Jim