Commit 598a83cf authored by Ruslan Kuprieiev's avatar Ruslan Kuprieiev Committed by Pavel Emelyanov

pycriu:images: treat pagemap.img as a special one

pagemap.img is the special one, as it starts with an entry
of pagemap_head type and is followed by entries of
pagemap_entry type. Currently we treat pagemap as if
pagemap_head is a payload and pagemap_entry's are
an extra, which is wrong.
Signed-off-by: 's avatarRuslan Kuprieiev <kupruser@gmail.com>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 4997896b
...@@ -124,33 +124,51 @@ class entry_handler: ...@@ -124,33 +124,51 @@ class entry_handler:
self.dump(entries, f) self.dump(entries, f)
return f.read() return f.read()
# Some custom extra handlers # Special handler for pagemap.img
class pagemap_handler:
class pagemap_extra_handler: """
def load(self, f, pload): Special entry handler for pagemap.img, which is unique in a way
array = [] that it has a header of pagemap_head type followed by entries
of pagemap_entry type.
"""
def load(self, f):
entries = []
pb = pagemap_head()
while True: while True:
pb = pagemap_entry()
buf = f.read(4) buf = f.read(4)
if buf == '': if buf == '':
break break
size, = struct.unpack('i', buf) size, = struct.unpack('i', buf)
pb.ParseFromString(f.read(size)) pb.ParseFromString(f.read(size))
array.append(pb2dict.pb2dict(pb)) entries.append(pb2dict.pb2dict(pb))
return array
def dump(self, extra, f, pload):
for item in extra:
pb = pagemap_entry() pb = pagemap_entry()
return entries
def loads(self, s):
f = io.BytesIO(s)
return self.load(f)
def dump(self, entries, f):
pb = pagemap_head()
for item in entries:
pb2dict.dict2pb(item, pb) pb2dict.dict2pb(item, pb)
pb_str = pb.SerializeToString() pb_str = pb.SerializeToString()
size = len(pb_str) size = len(pb_str)
f.write(struct.pack('i', size)) f.write(struct.pack('i', size))
f.write(pb_str) f.write(pb_str)
# In following handlers we use base64 encoding pb = pagemap_entry()
def dumps(self, entries):
f = io.BytesIO('')
self.dump(entries, f)
return f.read()
# In following extra handlers we use base64 encoding
# to store binary data. Even though, the nature # to store binary data. Even though, the nature
# of base64 is that it increases the total size, # of base64 is that it increases the total size,
# it doesn't really matter, because our images # it doesn't really matter, because our images
...@@ -198,7 +216,7 @@ handlers = { ...@@ -198,7 +216,7 @@ handlers = {
'CGROUP' : entry_handler(cgroup_entry), 'CGROUP' : entry_handler(cgroup_entry),
'TCP_STREAM' : entry_handler(tcp_stream_entry), 'TCP_STREAM' : entry_handler(tcp_stream_entry),
'STATS' : entry_handler(stats_entry), 'STATS' : entry_handler(stats_entry),
'PAGEMAP' : entry_handler(pagemap_head, pagemap_extra_handler()), 'PAGEMAP' : pagemap_handler(), # Special one
'PSTREE' : entry_handler(pstree_entry), 'PSTREE' : entry_handler(pstree_entry),
'REG_FILES' : entry_handler(reg_file_entry), 'REG_FILES' : entry_handler(reg_file_entry),
'NS_FILES' : entry_handler(ns_file_entry), 'NS_FILES' : entry_handler(ns_file_entry),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment