[libvirt] How to connect to console of domain on PowerPC?

Hi, I tried to use libvirt to run KVM/QEMU on Freescale PowerPC platforms. So far there's only one serial device (spapr-vty) defined in QEMU to work as console for IBM PSeries platform. There's no serial device support in QEMU for Freescale PowerPC (ePAPR). libvirt/src/qemu/qemu_command.c /* This function generates the correct '-device' string for character * devices of each architecture. */ char * qemuBuildChrDeviceStr(virDomainChrDefPtr serial, virBitmapPtr qemuCaps, char *os_arch, char *machine) { virBuffer cmd = VIR_BUFFER_INITIALIZER; if (STREQ(os_arch, "ppc64") && STREQ(machine, "pseries")) { if (serial->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL && serial->source.type == VIR_DOMAIN_CHR_TYPE_PTY && serial->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_SPAPRVIO) { virBufferAsprintf(&cmd, "spapr-vty,chardev=char%s", serial->info.alias); if (qemuBuildDeviceAddressStr(&cmd, &serial->info, qemuCaps) < 0) goto error; } } else virBufferAsprintf(&cmd, "isa-serial,chardev=char%s,id=%s", serial->info.alias, serial->info.alias); if (virBufferError(&cmd)) { virReportOOMError(); goto error; } return virBufferContentAndReset(&cmd); error: virBufferFreeAndReset(&cmd); return NULL; } We usually connect guest with telnet. For instance, /usr/bin/qemu-system-ppc -name demo -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial tcp::4445,server Then to run 'telnet 10.193.20.xxx 4445' could connect the guest. The temporary workaround is not add '-device' string after '-serial' option. diff -Nur libvirt-0.10.1.orig/src/qemu/qemu_command.c libvirt-0.10.1/src/qemu/qemu_command.c --- libvirt-0.10.1.orig/src/qemu/qemu_command.c 2012-08-30 15:35:18.000000000 +0530 +++ libvirt-0.10.1/src/qemu/qemu_command.c 2012-10-05 17:19:32.060368755 +0530 @@ -5501,13 +5501,15 @@ virCommandAddArg(cmd, devstr); VIR_FREE(devstr); - virCommandAddArg(cmd, "-device"); - if (!(devstr = qemuBuildChrDeviceStr(serial, qemuCaps, + if (!STREQ(def->os.arch, "ppc")) { + virCommandAddArg(cmd, "-device"); + if (!(devstr = qemuBuildChrDeviceStr(serial, + qemuCaps, def->os.arch, def->os.machine))) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); + goto error; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } } else { virCommandAddArg(cmd, "-serial"); if (!(devstr = qemuBuildChrArgStr(&serial->source, NULL))) Applying the above patch to libvirt, all the other domain control commands could work except 'virsh console domain'. # cat >demo.args <<EOF
/usr/bin/qemu-system-ppc -name demo -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial tcp::4445,server -net nic EOF
# vi demo.args /usr/bin/qemu-system-ppc -name demo -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial tcp::4445,server -net nic # virsh domxml-from-native qemu-argv demo.args >demo.xml # vi demo.xml <domain type='kvm'> <name>demo</name> <uuid>985d7154-83c8-0763-cbac-ecd159eee8a6</uuid> <memory unit='KiB'>262144</memory> <currentMemory unit='KiB'>262144</currentMemory> <vcpu placement='static'>1</vcpu> <os> <type arch='ppc' machine='ppce500v2'>hvm</type> <kernel>/media/ram/uImage</kernel> <initrd>/media/ram/ramdisk</initrd> <cmdline>root=/dev/ram rw console=ttyS0,115200</cmdline> </os> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-ppc</emulator> <serial type='tcp'> <source mode='bind' host='' service='4445'/> <protocol type='raw'/> <target port='0'/> </serial> <console type='tcp'> <source mode='bind' host='' service='4445'/> <protocol type='raw'/> <target type='serial' port='0'/> </console> <memballoon model='virtio'/> </devices> </domain> # virsh -c qemu:///system define demo.xml # virsh -c qemu:///system start demo But it seemed that can't connect to the console. # virsh -c qemu:///system console demo Connected to domain test Escape character is ^] error: internal error character device (null) is not using a PTY I tried also use '-serial pty' option, /usr/bin/qemu-system-ppc -name test -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial pty Then there's no other output after the below message: # virsh -c qemu:///system console demo Connected to domain test Escape character is ^] It seemed not libvirt group issue. I also tried the LXC. It could connect to the console if <init>/bin/sh/</init> instead of <init>/sbin/init</init> Best Regards, Olivia

On Mon, Feb 04, 2013 at 02:22:03AM +0000, Yin Olivia-R63875 wrote:
For instance, /usr/bin/qemu-system-ppc -name demo -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial tcp::4445,server
Then to run 'telnet 10.193.20.xxx 4445' could connect the guest.
The temporary workaround is not add '-device' string after '-serial' option.
This is wrong. -serial is legacy command line syntax that libvirt should never use for any QEMU released in the last 2 years. New syntax is uses a combination of -device + -chardev.
diff -Nur libvirt-0.10.1.orig/src/qemu/qemu_command.c libvirt-0.10.1/src/qemu/qemu_command.c --- libvirt-0.10.1.orig/src/qemu/qemu_command.c 2012-08-30 15:35:18.000000000 +0530 +++ libvirt-0.10.1/src/qemu/qemu_command.c 2012-10-05 17:19:32.060368755 +0530 @@ -5501,13 +5501,15 @@ virCommandAddArg(cmd, devstr); VIR_FREE(devstr);
- virCommandAddArg(cmd, "-device"); - if (!(devstr = qemuBuildChrDeviceStr(serial, qemuCaps, + if (!STREQ(def->os.arch, "ppc")) { + virCommandAddArg(cmd, "-device"); + if (!(devstr = qemuBuildChrDeviceStr(serial, + qemuCaps, def->os.arch, def->os.machine))) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); + goto error; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } } else { virCommandAddArg(cmd, "-serial"); if (!(devstr = qemuBuildChrArgStr(&serial->source, NULL)))
Applying the above patch to libvirt, all the other domain control commands could work except 'virsh console domain'.
# cat >demo.args <<EOF
/usr/bin/qemu-system-ppc -name demo -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial tcp::4445,server -net nic EOF
# vi demo.args /usr/bin/qemu-system-ppc -name demo -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial tcp::4445,server -net nic
If you think libvirt has a problem generating command line args, then rather than telling us about some random command line args you've created yourself, please provide the actual args that libvirt has generated. See /var/log/libvirt/qemu/$GUESTNAME.log for those. 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 :|

Hi Daniel, Thanks for your comments. So far there's no device in QEMU to align with chardev on FSL PowerPC platforms like spapr-pty for IBM PSeries. Maybe it needs patches to QEMU. I'll take deeper investigation on it. Anyway for LXC instance, it doesn't depend on the syntax. I can connect to the console if connect a domain with simple shell. # vi vm1.xml <domain type='lxc'> <name>vm1</name> <memory>32768</memory> <os> <type>exe</type> <init>/bin/sh</init> </os> <vcpu>1</vcpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <console type='pty' tty='/dev/pts/3'> <source path='/dev/pts/3'/> <target port='0'/> </console> </devices> </domain> # virsh -c lxc:/// define vm1.xml # virsh -c lxc:/// start vm1 Domain vm1 started # virsh -c lxc:/// console vm1 Connected to domain vm1 Escape character is ^] sh-4.2# pwd / sh-4.2# ps PID TTY TIME CMD 1 pts/2 00:00:00 sh 3 pts/2 00:00:00 ps But can't get any output when connecting domain with a simple private root filesystem. # vi vm2.xml <domain type='lxc'> <name>vm2</name> <memory>25536</memory> <os> <type>exe</type> <init>/sbin/init</init> </os> <vcpu>1</vcpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <filesystem type='mount'> <source dir='/media/ram/vm1-root'/> <target dir='/var/lib/libvirt/lxc/rootfs'/> </filesystem> <interface type='network'> <source network='default'/> </interface> <console type='pty' /> </devices> </domain> # virsh -c lxc:/// define vm2.xml # virsh -c lxc:/// start vm2 Domain vm2 started # virsh -c lxc:/// console vm2 Connected to domain vm2 Escape character is ^] Do you have any suggestion? Best Regards, Olivia -----Original Message----- From: Daniel P. Berrange [mailto:berrange@redhat.com] Sent: Monday, February 04, 2013 6:19 PM To: Yin Olivia-R63875 Cc: libvir-list@redhat.com Subject: Re: [libvirt] How to connect to console of domain on PowerPC? On Mon, Feb 04, 2013 at 02:22:03AM +0000, Yin Olivia-R63875 wrote:
For instance, /usr/bin/qemu-system-ppc -name demo -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial tcp::4445,server
Then to run 'telnet 10.193.20.xxx 4445' could connect the guest.
The temporary workaround is not add '-device' string after '-serial' option.
This is wrong. -serial is legacy command line syntax that libvirt should never use for any QEMU released in the last 2 years. New syntax is uses a combination of -device + -chardev.
diff -Nur libvirt-0.10.1.orig/src/qemu/qemu_command.c libvirt-0.10.1/src/qemu/qemu_command.c --- libvirt-0.10.1.orig/src/qemu/qemu_command.c 2012-08-30 15:35:18.000000000 +0530 +++ libvirt-0.10.1/src/qemu/qemu_command.c 2012-10-05 17:19:32.060368755 +0530 @@ -5501,13 +5501,15 @@ virCommandAddArg(cmd, devstr); VIR_FREE(devstr);
- virCommandAddArg(cmd, "-device"); - if (!(devstr = qemuBuildChrDeviceStr(serial, qemuCaps, + if (!STREQ(def->os.arch, "ppc")) { + virCommandAddArg(cmd, "-device"); + if (!(devstr = qemuBuildChrDeviceStr(serial, + qemuCaps, def->os.arch, def->os.machine))) - goto error; - virCommandAddArg(cmd, devstr); - VIR_FREE(devstr); + goto error; + virCommandAddArg(cmd, devstr); + VIR_FREE(devstr); + } } else { virCommandAddArg(cmd, "-serial"); if (!(devstr = qemuBuildChrArgStr(&serial->source, NULL)))
Applying the above patch to libvirt, all the other domain control commands could work except 'virsh console domain'.
# cat >demo.args <<EOF
/usr/bin/qemu-system-ppc -name demo -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial tcp::4445,server -net nic EOF
# vi demo.args /usr/bin/qemu-system-ppc -name demo -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial tcp::4445,server -net nic
If you think libvirt has a problem generating command line args, then rather than telling us about some random command line args you've created yourself, please provide the actual args that libvirt has generated. See /var/log/libvirt/qemu/$GUESTNAME.log for those. 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 Tue, Feb 05, 2013 at 03:05:58AM +0000, Yin Olivia-R63875 wrote:
Hi Daniel,
Thanks for your comments. So far there's no device in QEMU to align with chardev on FSL PowerPC platforms like spapr-pty for IBM PSeries. Maybe it needs patches to QEMU. I'll take deeper investigation on it.
That's really a QEMU issue then - every chardev needs to have a corresponding -device to associtte with.
But can't get any output when connecting domain with a simple private root filesystem. # vi vm2.xml <domain type='lxc'> <name>vm2</name> <memory>25536</memory> <os> <type>exe</type> <init>/sbin/init</init> </os> <vcpu>1</vcpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <filesystem type='mount'> <source dir='/media/ram/vm1-root'/> <target dir='/var/lib/libvirt/lxc/rootfs'/> </filesystem> <interface type='network'> <source network='default'/> </interface> <console type='pty' /> </devices> </domain>
# virsh -c lxc:/// define vm2.xml # virsh -c lxc:/// start vm2 Domain vm2 started
# virsh -c lxc:/// console vm2 Connected to domain vm2 Escape character is ^]
Do you have any suggestion?
Most likely is that the OS you are running has not decided to run any login process on the console '/sbin/init' itself does not directly provide any console interaction It needs to be configured to run a mingetty process or similar 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: Tuesday, February 05, 2013 6:18 PM To: Yin Olivia-R63875 Cc: libvir-list@redhat.com Subject: Re: [libvirt] How to connect to console of domain on PowerPC?
Hi Daniel,
Thanks for your comments. So far there's no device in QEMU to align with chardev on FSL PowerPC
On Tue, Feb 05, 2013 at 03:05:58AM +0000, Yin Olivia-R63875 wrote: platforms like spapr-pty for IBM PSeries.
Maybe it needs patches to QEMU. I'll take deeper investigation on it.
That's really a QEMU issue then - every chardev needs to have a corresponding -device to associtte with.
'-serial' syntax may be legacy but it should still work. There're two examples for "-serial tcp" use cases: $ cat libvirt/tests/qemuxml2argvdata/qemuxml2argv-serial-tcp.args LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ pc -m 214 -smp 1 -nographic -monitor unix:/tmp/test-monitor,server,nowait \ -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -net none -serial \ tcp:127.0.0.1:9999 -parallel none -usb $ cat libvirt/tests/qemuxml2argvdata/qemuxml2argv-serial-tcp-chardev.args LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test /usr/bin/qemu -S -M \ pc -m 214 -smp 1 -nographic -nodefconfig -nodefaults -chardev socket,\ id=charmonitor,path=/tmp/test-monitor,server,nowait -mon chardev=charmonitor,\ id=monitor,mode=readline -no-acpi -boot c -hda /dev/HostVG/QEMUGuest1 -chardev \ socket,id=charserial0,host=127.0.0.1,port=9999 -device isa-serial,\ chardev=charserial0,id=serial0 -usb -device virtio-balloon-pci,id=balloon0,\ bus=pci.0,addr=0x3
But can't get any output when connecting domain with a simple private root filesystem. # vi vm2.xml <domain type='lxc'> <name>vm2</name> <memory>25536</memory> <os> <type>exe</type> <init>/sbin/init</init> </os> <vcpu>1</vcpu> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/libexec/libvirt_lxc</emulator> <filesystem type='mount'> <source dir='/media/ram/vm1-root'/> <target dir='/var/lib/libvirt/lxc/rootfs'/> </filesystem> <interface type='network'> <source network='default'/> </interface> <console type='pty' /> </devices> </domain>
# virsh -c lxc:/// define vm2.xml # virsh -c lxc:/// start vm2 Domain vm2 started
# virsh -c lxc:/// console vm2 Connected to domain vm2 Escape character is ^]
Do you have any suggestion?
Most likely is that the OS you are running has not decided to run any login process on the console
'/sbin/init' itself does not directly provide any console interaction It needs to be configured to run a mingetty process or similar
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 :|

Hi Daniel, Since there's no machine serial port for FSL PowerPC board, I just use '-serial' option for ppc architecture. libvirt-0.10.1/src/qemu/qemu_command.c: @@ -5491,7 +5491,8 @@ /* Use -chardev with -device if they are available */ if (qemuCapsGet(qemuCaps, QEMU_CAPS_CHARDEV) && - qemuCapsGet(qemuCaps, QEMU_CAPS_DEVICE)) { + qemuCapsGet(qemuCaps, QEMU_CAPS_DEVICE) && + !STREQ(def->os.arch, "ppc")) { virCommandAddArg(cmd, "-chardev"); if (!(devstr = qemuBuildChrChardevStr(&serial->source, serial->info.alias, The QEMU command is: # /usr/bin/qemu-system-ppc -name demo -M ppce500v2 -enable-kvm -m 256 -nographic -kernel /media/ram/uImage -initrd /media/ram/ramdisk -append "root=/dev/ram rw console=ttyS0,115200" -serial pty -serial tcp::4445,server Use virsh to generate XML file as below: <domain type='kvm'> <name>demo</name> <uuid>83014cf3-40c8-4a79-ed2a-71fa1767bb4e</uuid> <memory unit='KiB'>262144</memory> <currentMemory unit='KiB'>262144</currentMemory> <vcpu placement='static'>1</vcpu> <os> <type arch='ppc' machine='ppce500v2'>hvm</type> <kernel>/media/ram/uImage</kernel> <initrd>/media/ram/ramdisk</initrd> <cmdline>root=/dev/ram rw console=ttyS0,115200</cmdline> </os> <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-ppc</emulator> <serial type='pty'> <target port='0'/> </serial> <serial type='tcp'> <source mode='bind' host='' service='4445'/> <protocol type='raw'/> <target port='1'/> </serial> <console type='pty'> <target type='serial' port='0'/> </console> <memballoon model='virtio'/> </devices> </domain> # virsh -c qemu:///system define demo.xml # virsh -c qemu:///system start demo # virsh -c qemu:///system console demo It could print the booting message now but still can't capture user's input. Otherwise users could not login and operate on the guest rootfs or run user space application on guest VM. Exactly if reset the domain, the console could display the kernel reboot message on domain. # virsh -c qemu:///system reset dome It seemed that the console is readonly instead of read/write. Do you have any suggestion about this issue? Best Regards, Olivia
participants (2)
-
Daniel P. Berrange
-
Yin Olivia-R63875