Lines Matching refs:self
36 def __init__(self, filename): argument
37 self.filename = filename
38 self.file = open(self.filename, "rb")
40 def read64(self): argument
41 return int.from_bytes(self.file.read(8), byteorder='big', signed=False)
43 def read32(self): argument
44 return int.from_bytes(self.file.read(4), byteorder='big', signed=False)
46 def read16(self): argument
47 return int.from_bytes(self.file.read(2), byteorder='big', signed=False)
49 def read8(self): argument
50 return int.from_bytes(self.file.read(1), byteorder='big', signed=True)
52 def readstr(self, len = None): argument
53 return self.readvar(len).decode('utf-8')
55 def readvar(self, size = None): argument
57 size = self.read8()
60 value = self.file.read(size)
62 raise Exception("Unexpected end of %s at 0x%x" % (self.filename, self.file.tell()))
65 def tell(self): argument
66 return self.file.tell()
70 def read_migration_debug_json(self): argument
74 entrypos = self.file.tell()
77 self.file.seek(0, os.SEEK_END)
78 endpos = self.file.tell()
79 self.file.seek(max(-endpos, -10 * 1024 * 1024), os.SEEK_END)
80 datapos = self.file.tell()
81 data = self.file.read()
83 self.file = open(self.filename, "rb")
91 self.file.seek(datapos + jsonpos - 5, 0)
92 if self.read8() != QEMU_VM_VMDESCRIPTION:
95 jsonlen = self.read32()
98 self.file.seek(entrypos, 0)
103 def close(self): argument
104 self.file.close()
117 def __init__(self, file, version_id, ramargs, section_key): argument
121 self.file = file
122 self.section_key = section_key
123 self.TARGET_PAGE_SIZE = ramargs['page_size']
124 self.dump_memory = ramargs['dump_memory']
125 self.write_memory = ramargs['write_memory']
126 self.ignore_shared = ramargs['ignore_shared']
127 self.sizeinfo = collections.OrderedDict()
128 self.data = collections.OrderedDict()
129 self.data['section sizes'] = self.sizeinfo
130 self.name = ''
131 if self.write_memory:
132 self.files = { }
133 if self.dump_memory:
134 self.memory = collections.OrderedDict()
135 self.data['memory'] = self.memory
137 def __repr__(self): argument
138 return self.data.__repr__()
140 def __str__(self): argument
141 return self.data.__str__()
143 def getDict(self): argument
144 return self.data
146 def read(self): argument
149 addr = self.file.read64()
150 flags = addr & (self.TARGET_PAGE_SIZE - 1)
151 addr &= ~(self.TARGET_PAGE_SIZE - 1)
153 if flags & self.RAM_SAVE_FLAG_MEM_SIZE:
156 namelen = self.file.read8()
157 self.name = self.file.readstr(len = namelen)
158 len = self.file.read64()
160 self.sizeinfo[self.name] = '0x%016x' % len
161 if self.write_memory:
162 print(self.name)
163 mkdir_p('./' + os.path.dirname(self.name))
164 f = open('./' + self.name, "wb")
167 self.files[self.name] = f
168 if self.ignore_shared:
169 mr_addr = self.file.read64()
170 flags &= ~self.RAM_SAVE_FLAG_MEM_SIZE
172 if flags & self.RAM_SAVE_FLAG_COMPRESS:
173 if flags & self.RAM_SAVE_FLAG_CONTINUE:
174 flags &= ~self.RAM_SAVE_FLAG_CONTINUE
176 self.name = self.file.readstr()
177 fill_char = self.file.read8()
179 if self.write_memory and fill_char != 0:
180 self.files[self.name].seek(addr, os.SEEK_SET)
181 self.files[self.name].write(chr(fill_char) * self.TARGET_PAGE_SIZE)
182 if self.dump_memory:
183 … self.memory['%s (0x%016x)' % (self.name, addr)] = 'Filled with 0x%02x' % fill_char
184 flags &= ~self.RAM_SAVE_FLAG_COMPRESS
185 elif flags & self.RAM_SAVE_FLAG_PAGE:
186 if flags & self.RAM_SAVE_FLAG_CONTINUE:
187 flags &= ~self.RAM_SAVE_FLAG_CONTINUE
189 self.name = self.file.readstr()
191 if self.write_memory or self.dump_memory:
192 data = self.file.readvar(size = self.TARGET_PAGE_SIZE)
194 self.file.file.seek(self.TARGET_PAGE_SIZE, 1)
196 if self.write_memory:
197 self.files[self.name].seek(addr, os.SEEK_SET)
198 self.files[self.name].write(data)
199 if self.dump_memory:
201 self.memory['%s (0x%016x)' % (self.name, addr)] = hexdata
203 flags &= ~self.RAM_SAVE_FLAG_PAGE
204 elif flags & self.RAM_SAVE_FLAG_XBZRLE:
206 elif flags & self.RAM_SAVE_FLAG_HOOK:
208 if flags & self.RAM_SAVE_FLAG_MULTIFD_FLUSH:
212 if flags & self.RAM_SAVE_FLAG_EOS:
218 def __del__(self): argument
219 if self.write_memory:
220 for key in self.files:
221 self.files[key].close()
227 def __init__(self, file, version_id, device, section_key): argument
231 self.file = file
232 self.section_key = section_key
234 def read(self): argument
236 header = self.file.read32()
248 index = self.file.read32()
249 n_valid = self.file.read16()
250 n_invalid = self.file.read16()
255 self.file.readvar(n_valid * self.HASH_PTE_SIZE_64)
257 def getDict(self): argument
267 def __init__(self, file, version_id, device, section_key): argument
271 self.file = file
272 self.section_key = section_key
274 def read(self): argument
276 addr_flags = self.file.read64()
278 if (flags & (self.STATTR_FLAG_DONE | self.STATTR_FLAG_EOS)):
280 if (flags & self.STATTR_FLAG_ERROR):
282 count = self.file.read64()
283 self.file.readvar(count)
285 def getDict(self): argument
290 def __init__(self, file, desc): argument
291 self.file = file
292 self.desc = desc
293 self.caps = []
295 def parse_capabilities(self, vmsd_caps): argument
300 self.caps = vmsd_caps.data['capabilities']
302 if type(self.caps) != list:
303 self.caps = [self.caps]
305 if len(self.caps) != ncaps:
309 def has_capability(self, cap): argument
310 return any([str(c) == cap for c in self.caps])
312 def read(self): argument
313 if self.desc:
314 version_id = self.desc['version']
315 section = VMSDSection(self.file, version_id, self.desc,
318 self.parse_capabilities(
323 name_len = self.file.read32()
324 name = self.file.readstr(len = name_len)
327 def __init__(self, desc, file): argument
328 self.file = file
329 self.desc = desc
330 self.data = ""
332 def __repr__(self): argument
333 return str(self.__str__())
335 def __str__(self): argument
336 return " ".join("{0:02x}".format(c) for c in self.data)
338 def getDict(self): argument
339 return self.__str__()
341 def read(self): argument
342 size = int(self.desc['size'])
343 self.data = self.file.readvar(size)
344 return self.data
347 def __init__(self, desc, file): argument
348 self.file = file
349 self.desc = desc
350 self.data = ""
352 def __repr__(self): argument
353 return self.data
355 def __str__(self): argument
356 return self.data
358 def read(self): argument
359 len = self.file.read8()
360 self.data = self.file.readstr(len)
364 def __init__(self, desc, file): argument
365 super(VMSDFieldInt, self).__init__(desc, file)
366 self.size = int(desc['size'])
367 self.format = '0x%%0%dx' % (self.size * 2)
368 self.sdtype = '>i%d' % self.size
369 self.udtype = '>u%d' % self.size
371 def __repr__(self): argument
372 if self.data < 0:
373 return ('%s (%d)' % ((self.format % self.udata), self.data))
375 return self.format % self.data
377 def __str__(self): argument
378 return self.__repr__()
380 def getDict(self): argument
381 return self.__str__()
383 def read(self): argument
384 super(VMSDFieldInt, self).read()
385 self.sdata = int.from_bytes(self.data, byteorder='big', signed=True)
386 self.udata = int.from_bytes(self.data, byteorder='big', signed=False)
387 self.data = self.sdata
388 return self.data
391 def __init__(self, desc, file): argument
392 super(VMSDFieldUInt, self).__init__(desc, file)
394 def read(self): argument
395 super(VMSDFieldUInt, self).read()
396 self.data = self.udata
397 return self.data
400 def __init__(self, desc, file): argument
401 super(VMSDFieldIntLE, self).__init__(desc, file)
402 self.dtype = '<i%d' % self.size
405 def __init__(self, desc, file): argument
406 super(VMSDFieldBool, self).__init__(desc, file)
408 def __repr__(self): argument
409 return self.data.__repr__()
411 def __str__(self): argument
412 return self.data.__str__()
414 def getDict(self): argument
415 return self.data
417 def read(self): argument
418 super(VMSDFieldBool, self).read()
419 if self.data[0] == 0:
420 self.data = False
422 self.data = True
423 return self.data
428 def __init__(self, desc, file): argument
429 super(VMSDFieldStruct, self).__init__(desc, file)
430 self.data = collections.OrderedDict()
434 for field in self.desc['struct']['fields']:
446 self.desc['struct']['fields'] = new_fields
448 def __repr__(self): argument
449 return self.data.__repr__()
451 def __str__(self): argument
452 return self.data.__str__()
454 def read(self): argument
455 for field in self.desc['struct']['fields']:
461 field['data'] = reader(field, self.file)
465 if field['name'] not in self.data:
466 self.data[field['name']] = []
467 a = self.data[field['name']]
472 self.data[field['name']] = field['data']
474 if 'subsections' in self.desc['struct']:
475 for subsection in self.desc['struct']['subsections']:
476 if self.file.read8() != self.QEMU_VM_SUBSECTION:
477 …se Exception("Subsection %s not found at offset %x" % ( subsection['vmsd_name'], self.file.tell()))
478 name = self.file.readstr()
479 version_id = self.file.read32()
480 self.data[name] = VMSDSection(self.file, version_id, subsection, (name, 0))
481 self.data[name].read()
483 def getDictItem(self, value): argument
490 return self.getDictOrderedDict(value)
493 return self.getDictArray(value)
500 def getDictArray(self, array): argument
503 r.append(self.getDictItem(value))
506 def getDictOrderedDict(self, dict): argument
509 r[key] = self.getDictItem(value)
512 def getDict(self): argument
513 return self.getDictOrderedDict(self.data)
542 def __init__(self, file, version_id, device, section_key): argument
543 self.file = file
544 self.data = ""
545 self.vmsd_name = ""
546 self.section_key = section_key
549 self.vmsd_name = device['vmsd_name']
552 super(VMSDSection, self).__init__({ 'struct' : desc }, file)
569 def __init__(self, filename): argument
570 self.section_classes = {
575 self.filename = filename
576 self.vmsd_desc = None
578 def read(self, desc_only = False, dump_memory = False, write_memory = False): argument
580 file = MigrationFile(self.filename)
584 if data != self.QEMU_VM_FILE_MAGIC:
589 if data != self.QEMU_VM_FILE_VERSION:
592 self.load_vmsd_json(file)
595 self.sections = collections.OrderedDict()
601 ramargs['page_size'] = self.vmsd_desc['page_size']
605 self.section_classes[('ram',0)][1] = ramargs
609 if section_type == self.QEMU_VM_EOF:
611 elif section_type == self.QEMU_VM_CONFIGURATION:
612 config_desc = self.vmsd_desc.get('configuration')
616 … elif section_type == self.QEMU_VM_SECTION_START or section_type == self.QEMU_VM_SECTION_FULL:
622 classdesc = self.section_classes[section_key]
624 self.sections[section_id] = section
626 … elif section_type == self.QEMU_VM_SECTION_PART or section_type == self.QEMU_VM_SECTION_END:
628 self.sections[section_id].read()
629 elif section_type == self.QEMU_VM_SECTION_FOOTER:
637 def load_vmsd_json(self, file): argument
639 self.vmsd_desc = json.loads(vmsd_json, object_pairs_hook=collections.OrderedDict)
640 for device in self.vmsd_desc['devices']:
643 self.section_classes[key] = value
645 def getDict(self): argument
647 for (key, value) in self.sections.items():
655 def default(self, o): argument
658 return json.JSONEncoder.default(self, o)