All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org, Thomas Huth <thuth@redhat.com>
Subject: Re: [PATCH v2 4/7] migration: Rename vmstate_info_nullptr
Date: Thu, 09 Jan 2025 12:53:14 -0300	[thread overview]
Message-ID: <87tta82dcl.fsf@suse.de> (raw)
In-Reply-To: <Z3_br0JVQ0F_Zas6@x1n>

Peter Xu <peterx@redhat.com> writes:

> On Thu, Jan 09, 2025 at 11:09:56AM -0300, Fabiano Rosas wrote:
>> Rename vmstate_info_nullptr from "uint64_t" to "nullptr". This vmstate
>> actually reads and writes just a byte, so the proper name would be
>> uint8. However, since this is a marker for a NULL pointer, it's
>> convenient to have a more explicit name that can be identified by the
>> consumers of the JSON part of the stream.
>> 
>> Change the name to "nullptr" and add support for it in the
>> analyze-migration.py script. Arbitrarily use the name of the type as
>> the value of the field to avoid the script showing 0x30 or '0', which
>> could be confusing for readers.
>> 
>> Signed-off-by: Fabiano Rosas <farosas@suse.de>
>> ---
>>  migration/vmstate-types.c    |  2 +-
>>  scripts/analyze-migration.py | 22 ++++++++++++++++++++++
>>  2 files changed, 23 insertions(+), 1 deletion(-)
>> 
>> diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c
>> index e83bfccb9e..d70d573dbd 100644
>> --- a/migration/vmstate-types.c
>> +++ b/migration/vmstate-types.c
>> @@ -338,7 +338,7 @@ static int put_nullptr(QEMUFile *f, void *pv, size_t size,
>>  }
>>  
>>  const VMStateInfo vmstate_info_nullptr = {
>> -    .name = "uint64",
>> +    .name = "nullptr",
>>      .get  = get_nullptr,
>>      .put  = put_nullptr,
>>  };
>> diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py
>> index fcda11f31d..134c25f20a 100755
>> --- a/scripts/analyze-migration.py
>> +++ b/scripts/analyze-migration.py
>> @@ -377,6 +377,8 @@ def read(self):
>>  
>>  
>>  class VMSDFieldInt(VMSDFieldGeneric):
>> +    NULL_PTR_MARKER = 0x30
>> +
>>      def __init__(self, desc, file):
>>          super(VMSDFieldInt, self).__init__(desc, file)
>>          self.size = int(desc['size'])
>> @@ -385,6 +387,16 @@ def __init__(self, desc, file):
>>          self.udtype = '>u%d' % self.size
>>  
>>      def __repr__(self):
>> +
>> +        # A NULL pointer is encoded in the stream as a '0' to
>> +        # disambiguate from a mere 0x0 value and avoid consumers
>> +        # trying to follow the NULL pointer. Displaying '0', 0x30 or
>> +        # 0x0 when analyzing the JSON debug stream could become
>> +        # confusing, so use an explicit term instead. The actual value
>> +        # in the stream was already validated by VMSDFieldNull.
>> +        if self.data == self.NULL_PTR_MARKER:
>> +            return "nullptr"
>
> What happens if a real int field has value 0x30 which is not a marker?
> Would it be wrongly represented as "nullptr"?
>

Yes, better to not inherit from VMSDFieldInt then.

>> +
>>          if self.data < 0:
>>              return ('%s (%d)' % ((self.format % self.udata), self.data))
>>          else:
>> @@ -417,6 +429,15 @@ def __init__(self, desc, file):
>>          super(VMSDFieldIntLE, self).__init__(desc, file)
>>          self.dtype = '<i%d' % self.size
>>  
>> +class VMSDFieldNull(VMSDFieldUInt):
>> +    def __init__(self, desc, file):
>> +        super(VMSDFieldUInt, self).__init__(desc, file)
>> +
>> +    def read(self):
>> +        super(VMSDFieldUInt, self).read()
>> +        assert(self.data == self.NULL_PTR_MARKER)
>> +        return self.data
>> +
>>  class VMSDFieldBool(VMSDFieldGeneric):
>>      def __init__(self, desc, file):
>>          super(VMSDFieldBool, self).__init__(desc, file)
>> @@ -558,6 +579,7 @@ def getDict(self):
>>      "bitmap" : VMSDFieldGeneric,
>>      "struct" : VMSDFieldStruct,
>>      "capability": VMSDFieldCap,
>> +    "nullptr": VMSDFieldNull,
>>      "unknown" : VMSDFieldGeneric,
>>  }
>>  
>> -- 
>> 2.35.3
>> 


  reply	other threads:[~2025-01-09 15:54 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-09 14:09 [PATCH v2 0/7] migration: Fix s390 regressions + migration script Fabiano Rosas
2025-01-09 14:09 ` [PATCH v2 1/7] migration: Add more error handling to analyze-migration.py Fabiano Rosas
2025-01-09 14:09 ` [PATCH v2 2/7] migration: Remove unused argument in vmsd_desc_field_end Fabiano Rosas
2025-01-09 14:09 ` [PATCH v2 3/7] migration: Fix parsing of s390 stream Fabiano Rosas
2025-01-09 14:09 ` [PATCH v2 4/7] migration: Rename vmstate_info_nullptr Fabiano Rosas
2025-01-09 14:22   ` Peter Xu
2025-01-09 15:53     ` Fabiano Rosas [this message]
2025-01-09 14:09 ` [PATCH v2 5/7] migration: Dump correct JSON format for nullptr replacement Fabiano Rosas
2025-01-09 14:09 ` [PATCH v2 6/7] migration: Fix arrays of pointers in JSON writer Fabiano Rosas
2025-01-09 14:34   ` Peter Xu
2025-01-09 16:16     ` Fabiano Rosas
2025-01-09 16:21       ` Peter Xu
2025-01-09 16:25         ` Fabiano Rosas
2025-01-09 14:09 ` [PATCH v2 7/7] s390x: Fix CSS migration Fabiano Rosas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tta82dcl.fsf@suse.de \
    --to=farosas@suse.de \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.