[libvirt] [PATCH] lxc: simplify command when connecting lxc multi console

From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> If we config more than one consoles for container, we always named them as "consoleN". We had to type a complex option "--devname consoleN". This patch enables option "--devname N" to be equal to "--devname consoleN". Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_driver.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 61a90ca..13213a5 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2439,6 +2439,7 @@ lxcDomainOpenConsole(virDomainPtr dom, int ret = -1; virDomainChrDefPtr chr = NULL; size_t i; + char *tmp_name = NULL; virCheckFlags(0, -1); @@ -2455,9 +2456,17 @@ lxcDomainOpenConsole(virDomainPtr dom, } if (dev_name) { + if (STRPREFIX(dev_name, "console")) { + if (VIR_STRDUP(tmp_name, dev_name) < 0) + goto cleanup; + } else { + if (virAsprintf(&tmp_name, "console%s", dev_name) < 0) + goto cleanup; + } + for (i = 0; i < vm->def->nconsoles; i++) { if (vm->def->consoles[i]->info.alias && - STREQ(vm->def->consoles[i]->info.alias, dev_name)) { + STREQ(vm->def->consoles[i]->info.alias, tmp_name)) { chr = vm->def->consoles[i]; break; } @@ -2490,6 +2499,7 @@ lxcDomainOpenConsole(virDomainPtr dom, cleanup: if (vm) virObjectUnlock(vm); + VIR_FREE(tmp_name); return ret; } -- 1.8.2.1

On 12/18/2013 04:54 PM, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
If we config more than one consoles for container, we always named them as "consoleN". We had to type a complex option "--devname consoleN". This patch enables option "--devname N" to be equal to "--devname consoleN".
Do we really need this?
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_driver.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index 61a90ca..13213a5 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2439,6 +2439,7 @@ lxcDomainOpenConsole(virDomainPtr dom, int ret = -1; virDomainChrDefPtr chr = NULL; size_t i; + char *tmp_name = NULL;
virCheckFlags(0, -1);
@@ -2455,9 +2456,17 @@ lxcDomainOpenConsole(virDomainPtr dom, }
if (dev_name) { + if (STRPREFIX(dev_name, "console")) { + if (VIR_STRDUP(tmp_name, dev_name) < 0) + goto cleanup; + } else { + if (virAsprintf(&tmp_name, "console%s", dev_name) < 0) + goto cleanup; + } + for (i = 0; i < vm->def->nconsoles; i++) { if (vm->def->consoles[i]->info.alias && - STREQ(vm->def->consoles[i]->info.alias, dev_name)) { + STREQ(vm->def->consoles[i]->info.alias, tmp_name)) { chr = vm->def->consoles[i]; break; } @@ -2490,6 +2499,7 @@ lxcDomainOpenConsole(virDomainPtr dom, cleanup: if (vm) virObjectUnlock(vm); + VIR_FREE(tmp_name); return ret; }

On Wed, Dec 18, 2013 at 04:54:27PM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
If we config more than one consoles for container, we always named them as "consoleN". We had to type a complex option "--devname consoleN". This patch enables option "--devname N" to be equal to "--devname consoleN".
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_driver.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
NACK, I don't see any compelling reason todo this. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

On Wed, Dec 18, 2013 at 09:52:05AM +0000, Daniel P. Berrange wrote:
On Wed, Dec 18, 2013 at 04:54:27PM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
If we config more than one consoles for container, we always named them as "consoleN". We had to type a complex option "--devname consoleN". This patch enables option "--devname N" to be equal to "--devname consoleN".
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_driver.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
NACK, I don't see any compelling reason todo this.
I should say though if we want simplification in virsh code that would be acceptablee virsh console -n 2 myguestname would say connect to the 2nd <console> in the XML. virsh would get the XML description and find the 2nd <console> and extract the <alias> string from it, and then call the libvirt API with that string. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

-----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: Wednesday, December 18, 2013 5:55 PM To: Chen Hanxiao Cc: libvir-list@redhat.com Subject: Re: [libvirt] [PATCH] lxc: simplify command when connecting lxc multi console
On Wed, Dec 18, 2013 at 09:52:05AM +0000, Daniel P. Berrange wrote:
On Wed, Dec 18, 2013 at 04:54:27PM +0800, Chen Hanxiao wrote:
From: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
If we config more than one consoles for container, we always named them as "consoleN". We had to type a complex option "--devname consoleN". This patch enables option "--devname N" to be equal to "--devname consoleN".
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com> --- src/lxc/lxc_driver.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
NACK, I don't see any compelling reason todo this.
I should say though if we want simplification in virsh code that would be acceptablee
virsh console -n 2 myguestname
would say connect to the 2nd <console> in the XML. virsh would get the XML description and find the 2nd <console> and extract the <alias> string from it, and then call the libvirt API with that string.
Thanks, I see.
Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
participants (3)
-
Chen Hanxiao
-
Daniel P. Berrange
-
Gao feng