diff mbox series

[v4,4/7] python/qemu/machine: Allow to use other serial consoles than default

Message ID 20200120235159.18510-5-f4bug@amsat.org
State New
Headers show
Series hw/arm/raspi: Run U-Boot on the raspi machines | expand

Commit Message

Philippe Mathieu-Daudé Jan. 20, 2020, 11:51 p.m. UTC
Currently the QEMU Python module limits the QEMUMachine class to
use the first serial console.

Some machines/guest might use another console than the first one as
the 'boot console'. For example the Raspberry Pi uses the second
(AUX) console.

To be able to use the Nth console as default, we simply need to
connect all the N - 1 consoles to the null chardev.

Add an index argument, so we can use a specific serial console as
default.

Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
v2:
- renamed 'console_index', added docstring (Cleber)
- reworded description (pm215)
---
 python/qemu/machine.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Philippe Mathieu-Daudé Jan. 21, 2020, 8:20 a.m. UTC | #1
On 1/21/20 12:51 AM, Philippe Mathieu-Daudé wrote:
> Currently the QEMU Python module limits the QEMUMachine class to
> use the first serial console.
> 
> Some machines/guest might use another console than the first one as
> the 'boot console'. For example the Raspberry Pi uses the second
> (AUX) console.
> 
> To be able to use the Nth console as default, we simply need to
> connect all the N - 1 consoles to the null chardev.
> 
> Add an index argument, so we can use a specific serial console as
> default.
> 
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
> v2:
> - renamed 'console_index', added docstring (Cleber)
> - reworded description (pm215)
> ---
>   python/qemu/machine.py | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/python/qemu/machine.py b/python/qemu/machine.py
> index 734efd8536..ef9f5b213f 100644
> --- a/python/qemu/machine.py
> +++ b/python/qemu/machine.py
> @@ -241,6 +241,8 @@ class QEMUMachine(object):
>                            'chardev=mon,mode=control'])
>           if self._machine is not None:
>               args.extend(['-machine', self._machine])
> +        for i in range(self._console_index):
> +            args.extend(['-serial', 'null'])

This patch is not sufficient, we have to initialize _console_index in 
__init__():

-- >8 --
diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index ef9f5b213f..183d8f3d38 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -112,6 +112,7 @@ class QEMUMachine(object):
          self._sock_dir = sock_dir
          self._launched = False
          self._machine = None
+        self._console_index = 0
          self._console_set = False
          self._console_device_type = None
          self._console_address = None
---

Else for tests not calling self.set_console() we get:

  'QEMUMachine' object has no attribute '_console_index'

>           if self._console_set:
>               self._console_address = os.path.join(self._sock_dir,
>                                                    self._name + "-console.sock")
> @@ -527,7 +529,7 @@ class QEMUMachine(object):
>           """
>           self._machine = machine_type
>   
> -    def set_console(self, device_type=None):
> +    def set_console(self, device_type=None, console_index=0):
>           """
>           Sets the device type for a console device
>   
> @@ -548,9 +550,14 @@ class QEMUMachine(object):
>                               chardev:console" command line argument will
>                               be used instead, resorting to the machine's
>                               default device type.
> +        @param console_index: the index of the console device to use.
> +                              If not zero, the command line will create
> +                              'index - 1' consoles and connect them to
> +                              the 'null' backing character device.
>           """
>           self._console_set = True
>           self._console_device_type = device_type
> +        self._console_index = console_index
>   
>       @property
>       def console_socket(self):
>
Liam Merwick Jan. 28, 2020, 11:01 a.m. UTC | #2
On 21/01/2020 08:20, Philippe Mathieu-Daudé wrote:
> On 1/21/20 12:51 AM, Philippe Mathieu-Daudé wrote:
>> Currently the QEMU Python module limits the QEMUMachine class to
>> use the first serial console.
>>
>> Some machines/guest might use another console than the first one as
>> the 'boot console'. For example the Raspberry Pi uses the second
>> (AUX) console.
>>
>> To be able to use the Nth console as default, we simply need to
>> connect all the N - 1 consoles to the null chardev.
>>
>> Add an index argument, so we can use a specific serial console as
>> default.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> v2:
>> - renamed 'console_index', added docstring (Cleber)
>> - reworded description (pm215)
>> ---
>>   python/qemu/machine.py | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/python/qemu/machine.py b/python/qemu/machine.py
>> index 734efd8536..ef9f5b213f 100644
>> --- a/python/qemu/machine.py
>> +++ b/python/qemu/machine.py
>> @@ -241,6 +241,8 @@ class QEMUMachine(object):
>>                            'chardev=mon,mode=control'])
>>           if self._machine is not None:
>>               args.extend(['-machine', self._machine])
>> +        for i in range(self._console_index):
>> +            args.extend(['-serial', 'null'])
> 
> This patch is not sufficient, we have to initialize _console_index in 
> __init__():
> 

with that fix applied

Reviewed-by: Liam Merwick <liam.merwick@oracle.com>
Tested-by: Liam Merwick <liam.merwick@oracle.com>




> -- >8 --
> diff --git a/python/qemu/machine.py b/python/qemu/machine.py
> index ef9f5b213f..183d8f3d38 100644
> --- a/python/qemu/machine.py
> +++ b/python/qemu/machine.py
> @@ -112,6 +112,7 @@ class QEMUMachine(object):
>           self._sock_dir = sock_dir
>           self._launched = False
>           self._machine = None
> +        self._console_index = 0
>           self._console_set = False
>           self._console_device_type = None
>           self._console_address = None
> ---
> 
> Else for tests not calling self.set_console() we get:
> 
>   'QEMUMachine' object has no attribute '_console_index'
> 
>>           if self._console_set:
>>               self._console_address = os.path.join(self._sock_dir,
>>                                                    self._name + 
>> "-console.sock")
>> @@ -527,7 +529,7 @@ class QEMUMachine(object):
>>           """
>>           self._machine = machine_type
>> -    def set_console(self, device_type=None):
>> +    def set_console(self, device_type=None, console_index=0):
>>           """
>>           Sets the device type for a console device
>> @@ -548,9 +550,14 @@ class QEMUMachine(object):
>>                               chardev:console" command line argument will
>>                               be used instead, resorting to the machine's
>>                               default device type.
>> +        @param console_index: the index of the console device to use.
>> +                              If not zero, the command line will create
>> +                              'index - 1' consoles and connect them to
>> +                              the 'null' backing character device.
>>           """
>>           self._console_set = True
>>           self._console_device_type = device_type
>> +        self._console_index = console_index
>>       @property
>>       def console_socket(self):
>>
> 
>
Wainer dos Santos Moschetta Jan. 28, 2020, 7:12 p.m. UTC | #3
On 1/21/20 6:20 AM, Philippe Mathieu-Daudé wrote:
> On 1/21/20 12:51 AM, Philippe Mathieu-Daudé wrote:
>> Currently the QEMU Python module limits the QEMUMachine class to
>> use the first serial console.
>>
>> Some machines/guest might use another console than the first one as
>> the 'boot console'. For example the Raspberry Pi uses the second
>> (AUX) console.
>>
>> To be able to use the Nth console as default, we simply need to
>> connect all the N - 1 consoles to the null chardev.
>>
>> Add an index argument, so we can use a specific serial console as
>> default.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> v2:
>> - renamed 'console_index', added docstring (Cleber)
>> - reworded description (pm215)
>> ---
>>   python/qemu/machine.py | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/python/qemu/machine.py b/python/qemu/machine.py
>> index 734efd8536..ef9f5b213f 100644
>> --- a/python/qemu/machine.py
>> +++ b/python/qemu/machine.py
>> @@ -241,6 +241,8 @@ class QEMUMachine(object):
>>                            'chardev=mon,mode=control'])
>>           if self._machine is not None:
>>               args.extend(['-machine', self._machine])
>> +        for i in range(self._console_index):
>> +            args.extend(['-serial', 'null'])
>
> This patch is not sufficient, we have to initialize _console_index in 
> __init__():
>
> -- >8 --
> diff --git a/python/qemu/machine.py b/python/qemu/machine.py
> index ef9f5b213f..183d8f3d38 100644
> --- a/python/qemu/machine.py
> +++ b/python/qemu/machine.py
> @@ -112,6 +112,7 @@ class QEMUMachine(object):
>          self._sock_dir = sock_dir
>          self._launched = False
>          self._machine = None
> +        self._console_index = 0
>          self._console_set = False
>          self._console_device_type = None
>          self._console_address = None
> ---
>

OK, with that fix:

Reviewed-by: Wainer dos Santos Moschetta <wainersm@redhat.com>


> Else for tests not calling self.set_console() we get:
>
>  'QEMUMachine' object has no attribute '_console_index'
>
>>           if self._console_set:
>>               self._console_address = os.path.join(self._sock_dir,
>>                                                    self._name + 
>> "-console.sock")
>> @@ -527,7 +529,7 @@ class QEMUMachine(object):
>>           """
>>           self._machine = machine_type
>>   -    def set_console(self, device_type=None):
>> +    def set_console(self, device_type=None, console_index=0):
>>           """
>>           Sets the device type for a console device
>>   @@ -548,9 +550,14 @@ class QEMUMachine(object):
>>                               chardev:console" command line argument 
>> will
>>                               be used instead, resorting to the 
>> machine's
>>                               default device type.
>> +        @param console_index: the index of the console device to use.
>> +                              If not zero, the command line will create
>> +                              'index - 1' consoles and connect them to
>> +                              the 'null' backing character device.
>>           """
>>           self._console_set = True
>>           self._console_device_type = device_type
>> +        self._console_index = console_index
>>         @property
>>       def console_socket(self):
>>
>
>
Philippe Mathieu-Daudé Jan. 30, 2020, 10:15 p.m. UTC | #4
On 1/21/20 9:20 AM, Philippe Mathieu-Daudé wrote:
> On 1/21/20 12:51 AM, Philippe Mathieu-Daudé wrote:
>> Currently the QEMU Python module limits the QEMUMachine class to
>> use the first serial console.
>>
>> Some machines/guest might use another console than the first one as
>> the 'boot console'. For example the Raspberry Pi uses the second
>> (AUX) console.
>>
>> To be able to use the Nth console as default, we simply need to
>> connect all the N - 1 consoles to the null chardev.
>>
>> Add an index argument, so we can use a specific serial console as
>> default.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
>> ---
>> v2:
>> - renamed 'console_index', added docstring (Cleber)
>> - reworded description (pm215)
>> ---
>>   python/qemu/machine.py | 9 ++++++++-
>>   1 file changed, 8 insertions(+), 1 deletion(-)
>>
>> diff --git a/python/qemu/machine.py b/python/qemu/machine.py
>> index 734efd8536..ef9f5b213f 100644
>> --- a/python/qemu/machine.py
>> +++ b/python/qemu/machine.py
>> @@ -241,6 +241,8 @@ class QEMUMachine(object):
>>                            'chardev=mon,mode=control'])
>>           if self._machine is not None:
>>               args.extend(['-machine', self._machine])
>> +        for i in range(self._console_index):
>> +            args.extend(['-serial', 'null'])
> 
> This patch is not sufficient, we have to initialize _console_index in 
> __init__():
> 
> -- >8 --
> diff --git a/python/qemu/machine.py b/python/qemu/machine.py
> index ef9f5b213f..183d8f3d38 100644
> --- a/python/qemu/machine.py
> +++ b/python/qemu/machine.py
> @@ -112,6 +112,7 @@ class QEMUMachine(object):
>           self._sock_dir = sock_dir
>           self._launched = False
>           self._machine = None
> +        self._console_index = 0
>           self._console_set = False
>           self._console_device_type = None
>           self._console_address = None
> ---
> 
> Else for tests not calling self.set_console() we get:
> 
>   'QEMUMachine' object has no attribute '_console_index'
> 
>>           if self._console_set:
>>               self._console_address = os.path.join(self._sock_dir,
>>                                                    self._name + 
>> "-console.sock")
>> @@ -527,7 +529,7 @@ class QEMUMachine(object):
>>           """
>>           self._machine = machine_type
>> -    def set_console(self, device_type=None):
>> +    def set_console(self, device_type=None, console_index=0):
>>           """
>>           Sets the device type for a console device
>> @@ -548,9 +550,14 @@ class QEMUMachine(object):
>>                               chardev:console" command line argument will
>>                               be used instead, resorting to the machine's
>>                               default device type.
>> +        @param console_index: the index of the console device to use.
>> +                              If not zero, the command line will create
>> +                              'index - 1' consoles and connect them to
>> +                              the 'null' backing character device.
>>           """
>>           self._console_set = True
>>           self._console_device_type = device_type
>> +        self._console_index = console_index
>>       @property
>>       def console_socket(self):
>>

Thanks, added missing line and applied to my python-next tree:
https://gitlab.com/philmd/qemu/commits/python-next
diff mbox series

Patch

diff --git a/python/qemu/machine.py b/python/qemu/machine.py
index 734efd8536..ef9f5b213f 100644
--- a/python/qemu/machine.py
+++ b/python/qemu/machine.py
@@ -241,6 +241,8 @@  class QEMUMachine(object):
                          'chardev=mon,mode=control'])
         if self._machine is not None:
             args.extend(['-machine', self._machine])
+        for i in range(self._console_index):
+            args.extend(['-serial', 'null'])
         if self._console_set:
             self._console_address = os.path.join(self._sock_dir,
                                                  self._name + "-console.sock")
@@ -527,7 +529,7 @@  class QEMUMachine(object):
         """
         self._machine = machine_type
 
-    def set_console(self, device_type=None):
+    def set_console(self, device_type=None, console_index=0):
         """
         Sets the device type for a console device
 
@@ -548,9 +550,14 @@  class QEMUMachine(object):
                             chardev:console" command line argument will
                             be used instead, resorting to the machine's
                             default device type.
+        @param console_index: the index of the console device to use.
+                              If not zero, the command line will create
+                              'index - 1' consoles and connect them to
+                              the 'null' backing character device.
         """
         self._console_set = True
         self._console_device_type = device_type
+        self._console_index = console_index
 
     @property
     def console_socket(self):