diff mbox series

[v2,4/6] migration: Fix analyze-migration.py when ignore-shared is used

Message ID 20231009184326.15777-5-farosas@suse.de
State New
Headers show
Series scripts/migration: Fix analyze-migration.py and add a test | expand

Commit Message

Fabiano Rosas Oct. 9, 2023, 6:43 p.m. UTC
The script is currently broken when the x-ignore-shared capability is
used:

Traceback (most recent call last):
  File "./scripts/analyze-migration.py", line 656, in <module>
    dump.read(dump_memory = args.memory)
  File "./scripts/analyze-migration.py", line 593, in read
    section.read()
  File "./scripts/analyze-migration.py", line 163, in read
    self.name = self.file.readstr(len = namelen)
  File "./scripts/analyze-migration.py", line 53, in readstr
    return self.readvar(len).decode('utf-8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 55: invalid start byte

We're currently adding data to the middle of the ram section depending
on the presence of the capability. As a consequence, any code loading
the ram section needs to know about capabilities so it can interpret
the stream.

Skip the byte that's added when x-ignore-shared is used to fix the
script.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 scripts/analyze-migration.py | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Juan Quintela Oct. 11, 2023, 1:23 p.m. UTC | #1
Fabiano Rosas <farosas@suse.de> wrote:
> The script is currently broken when the x-ignore-shared capability is
> used:
>
> Traceback (most recent call last):
>   File "./scripts/analyze-migration.py", line 656, in <module>
>     dump.read(dump_memory = args.memory)
>   File "./scripts/analyze-migration.py", line 593, in read
>     section.read()
>   File "./scripts/analyze-migration.py", line 163, in read
>     self.name = self.file.readstr(len = namelen)
>   File "./scripts/analyze-migration.py", line 53, in readstr
>     return self.readvar(len).decode('utf-8')
> UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 55: invalid start byte
>
> We're currently adding data to the middle of the ram section depending
> on the presence of the capability. As a consequence, any code loading
> the ram section needs to know about capabilities so it can interpret
> the stream.
>
> Skip the byte that's added when x-ignore-shared is used to fix the
> script.
>
> Signed-off-by: Fabiano Rosas <farosas@suse.de>

Reviewed-by: Juan Quintela <quintela@redhat.com>

> @@ -582,6 +586,7 @@ def read(self, desc_only = False, dump_memory = False, write_memory = False):
>                  config_desc = self.vmsd_desc.get('configuration')
>                  section = ConfigurationSection(file, config_desc)
>                  section.read()
> +                ramargs['ignore_shared'] = section.has_capability('x-ignore-shared')

should we consider s/x-ignore-shared/ignore-shared/?

>              elif section_type == self.QEMU_VM_SECTION_START or section_type == self.QEMU_VM_SECTION_FULL:
>                  section_id = file.read32()
>                  name = file.readstr()
Fabiano Rosas Oct. 11, 2023, 1:32 p.m. UTC | #2
Juan Quintela <quintela@redhat.com> writes:

> Fabiano Rosas <farosas@suse.de> wrote:
>> The script is currently broken when the x-ignore-shared capability is
>> used:
>>
>> Traceback (most recent call last):
>>   File "./scripts/analyze-migration.py", line 656, in <module>
>>     dump.read(dump_memory = args.memory)
>>   File "./scripts/analyze-migration.py", line 593, in read
>>     section.read()
>>   File "./scripts/analyze-migration.py", line 163, in read
>>     self.name = self.file.readstr(len = namelen)
>>   File "./scripts/analyze-migration.py", line 53, in readstr
>>     return self.readvar(len).decode('utf-8')
>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 55: invalid start byte
>>
>> We're currently adding data to the middle of the ram section depending
>> on the presence of the capability. As a consequence, any code loading
>> the ram section needs to know about capabilities so it can interpret
>> the stream.
>>
>> Skip the byte that's added when x-ignore-shared is used to fix the
>> script.
>>
>> Signed-off-by: Fabiano Rosas <farosas@suse.de>
>
> Reviewed-by: Juan Quintela <quintela@redhat.com>
>
>> @@ -582,6 +586,7 @@ def read(self, desc_only = False, dump_memory = False, write_memory = False):
>>                  config_desc = self.vmsd_desc.get('configuration')
>>                  section = ConfigurationSection(file, config_desc)
>>                  section.read()
>> +                ramargs['ignore_shared'] = section.has_capability('x-ignore-shared')
>
> should we consider s/x-ignore-shared/ignore-shared/?
>

We can consider s/ignore-shared/x-ignore-shared/ if that's what you
mean. The way you suggested doesn't work because the cap name comes from
QEMU with the "x-" part in it.

If you meant filtering the x out when parsing the capabilities in this
script, I think that would cause a sort of a UX issue because we need to
use x-ignore-shared to set the cap in QMP/HMP.
Juan Quintela Oct. 11, 2023, 2:10 p.m. UTC | #3
Fabiano Rosas <farosas@suse.de> wrote:
> Juan Quintela <quintela@redhat.com> writes:
>
>> Fabiano Rosas <farosas@suse.de> wrote:
>>> The script is currently broken when the x-ignore-shared capability is
>>> used:
>>>
>>> Traceback (most recent call last):
>>>   File "./scripts/analyze-migration.py", line 656, in <module>
>>>     dump.read(dump_memory = args.memory)
>>>   File "./scripts/analyze-migration.py", line 593, in read
>>>     section.read()
>>>   File "./scripts/analyze-migration.py", line 163, in read
>>>     self.name = self.file.readstr(len = namelen)
>>>   File "./scripts/analyze-migration.py", line 53, in readstr
>>>     return self.readvar(len).decode('utf-8')
>>> UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 55: invalid start byte
>>>
>>> We're currently adding data to the middle of the ram section depending
>>> on the presence of the capability. As a consequence, any code loading
>>> the ram section needs to know about capabilities so it can interpret
>>> the stream.
>>>
>>> Skip the byte that's added when x-ignore-shared is used to fix the
>>> script.
>>>
>>> Signed-off-by: Fabiano Rosas <farosas@suse.de>
>>
>> Reviewed-by: Juan Quintela <quintela@redhat.com>
>>
>>> @@ -582,6 +586,7 @@ def read(self, desc_only = False, dump_memory = False, write_memory = False):
>>>                  config_desc = self.vmsd_desc.get('configuration')
>>>                  section = ConfigurationSection(file, config_desc)
>>>                  section.read()
>>> +                ramargs['ignore_shared'] = section.has_capability('x-ignore-shared')
>>
>> should we consider s/x-ignore-shared/ignore-shared/?
>>
>
> We can consider s/ignore-shared/x-ignore-shared/ if that's what you
> mean. The way you suggested doesn't work because the cap name comes from
> QEMU with the "x-" part in it.
>
> If you meant filtering the x out when parsing the capabilities in this
> script, I think that would cause a sort of a UX issue because we need to
> use x-ignore-shared to set the cap in QMP/HMP.

No.

I mean if we should start supporting ignore-shared.

Later, Juan.
diff mbox series

Patch

diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py
index c700fed64d..56ab04dd2d 100755
--- a/scripts/analyze-migration.py
+++ b/scripts/analyze-migration.py
@@ -123,6 +123,7 @@  def __init__(self, file, version_id, ramargs, section_key):
         self.TARGET_PAGE_SIZE = ramargs['page_size']
         self.dump_memory = ramargs['dump_memory']
         self.write_memory = ramargs['write_memory']
+        self.ignore_shared = ramargs['ignore_shared']
         self.sizeinfo = collections.OrderedDict()
         self.data = collections.OrderedDict()
         self.data['section sizes'] = self.sizeinfo
@@ -169,6 +170,8 @@  def read(self):
                         f.truncate(0)
                         f.truncate(len)
                         self.files[self.name] = f
+                    if self.ignore_shared:
+                        mr_addr = self.file.read64()
                 flags &= ~self.RAM_SAVE_FLAG_MEM_SIZE
 
             if flags & self.RAM_SAVE_FLAG_COMPRESS:
@@ -572,6 +575,7 @@  def read(self, desc_only = False, dump_memory = False, write_memory = False):
         ramargs['page_size'] = self.vmsd_desc['page_size']
         ramargs['dump_memory'] = dump_memory
         ramargs['write_memory'] = write_memory
+        ramargs['ignore_shared'] = False
         self.section_classes[('ram',0)][1] = ramargs
 
         while True:
@@ -582,6 +586,7 @@  def read(self, desc_only = False, dump_memory = False, write_memory = False):
                 config_desc = self.vmsd_desc.get('configuration')
                 section = ConfigurationSection(file, config_desc)
                 section.read()
+                ramargs['ignore_shared'] = section.has_capability('x-ignore-shared')
             elif section_type == self.QEMU_VM_SECTION_START or section_type == self.QEMU_VM_SECTION_FULL:
                 section_id = file.read32()
                 name = file.readstr()