2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 01:51:51 +00:00

py: Fix tabs in code comments

These were left by yapf formatter

Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
Radostin Stoyanov 2019-06-28 20:17:35 +03:00 committed by Andrei Vagin
parent 34dbf67b24
commit 72402c6e7a
5 changed files with 156 additions and 156 deletions

View File

@ -9,24 +9,24 @@
#
# On my x86_64 systems with fresh kernel ~3.17 core dump looks like:
#
# 1) Elf file header;
# 2) PT_NOTE program header describing notes section;
# 3) PT_LOAD program headers for (almost?) each vma;
# 4) NT_PRPSINFO note with elf_prpsinfo inside;
# 5) An array of notes for each thread of the process:
# NT_PRSTATUS note with elf_prstatus inside;
# NT_FPREGSET note with elf_fpregset inside;
# NT_X86_XSTATE note with x86 extended state using xsave;
# NT_SIGINFO note with siginfo_t inside;
# 6) NT_AUXV note with auxv;
# 7) NT_FILE note with mapped files;
# 8) VMAs themselves;
# 1) Elf file header;
# 2) PT_NOTE program header describing notes section;
# 3) PT_LOAD program headers for (almost?) each vma;
# 4) NT_PRPSINFO note with elf_prpsinfo inside;
# 5) An array of notes for each thread of the process:
# NT_PRSTATUS note with elf_prstatus inside;
# NT_FPREGSET note with elf_fpregset inside;
# NT_X86_XSTATE note with x86 extended state using xsave;
# NT_SIGINFO note with siginfo_t inside;
# 6) NT_AUXV note with auxv;
# 7) NT_FILE note with mapped files;
# 8) VMAs themselves;
#
# Or, you can represent it in less details as:
# 1) Elf file header;
# 2) Program table;
# 3) Notes;
# 4) VMAs contents;
# 1) Elf file header;
# 2) Program table;
# 3) Notes;
# 4) VMAs contents;
#
import io
import elf
@ -65,9 +65,9 @@ class elf_note:
class coredump:
"""
A class to keep elf core dump components inside and
functions to properly write them to file.
"""
A class to keep elf core dump components inside and
functions to properly write them to file.
"""
ehdr = None # Elf ehdr;
phdrs = [] # Array of Phdrs;
notes = [] # Array of elf_notes;
@ -77,8 +77,8 @@ class coredump:
def write(self, f):
"""
Write core dump to file f.
"""
Write core dump to file f.
"""
buf = io.BytesIO()
buf.write(self.ehdr)
@ -117,8 +117,8 @@ class coredump:
class coredump_generator:
"""
Generate core dump from criu images.
"""
Generate core dump from criu images.
"""
coredumps = {} # coredumps by pid;
pstree = {} # process info by pid;
@ -129,8 +129,8 @@ class coredump_generator:
def _img_open_and_strip(self, name, single=False, pid=None):
"""
Load criu image and strip it from magic and redundant list.
"""
Load criu image and strip it from magic and redundant list.
"""
path = self._imgs_dir + "/" + name
if pid:
path += "-" + str(pid)
@ -146,8 +146,8 @@ class coredump_generator:
def __call__(self, imgs_dir):
"""
Parse criu images stored in directory imgs_dir to fill core dumps.
"""
Parse criu images stored in directory imgs_dir to fill core dumps.
"""
self._imgs_dir = imgs_dir
pstree = self._img_open_and_strip("pstree")
@ -171,9 +171,9 @@ class coredump_generator:
def write(self, coredumps_dir, pid=None):
"""
Write core dumpt to cores_dir directory. Specify pid to choose
core dump of only one process.
"""
Write core dumpt to cores_dir directory. Specify pid to choose
core dump of only one process.
"""
for p in self.coredumps:
if pid and p != pid:
continue
@ -182,8 +182,8 @@ class coredump_generator:
def _gen_coredump(self, pid):
"""
Generate core dump for pid.
"""
Generate core dump for pid.
"""
cd = coredump()
# Generate everything backwards so it is easier to calculate offset.
@ -196,8 +196,8 @@ class coredump_generator:
def _gen_ehdr(self, pid, phdrs):
"""
Generate elf header for process pid with program headers phdrs.
"""
Generate elf header for process pid with program headers phdrs.
"""
ehdr = elf.Elf64_Ehdr()
ctypes.memset(ctypes.addressof(ehdr), 0, ctypes.sizeof(ehdr))
@ -223,8 +223,8 @@ class coredump_generator:
def _gen_phdrs(self, pid, notes, vmas):
"""
Generate program headers for process pid.
"""
Generate program headers for process pid.
"""
phdrs = []
offset = ctypes.sizeof(elf.Elf64_Ehdr())
@ -272,8 +272,8 @@ class coredump_generator:
def _gen_prpsinfo(self, pid):
"""
Generate NT_PRPSINFO note for process pid.
"""
Generate NT_PRPSINFO note for process pid.
"""
pstree = self.pstree[pid]
core = self.cores[pid]
@ -324,8 +324,8 @@ class coredump_generator:
def _gen_prstatus(self, pid, tid):
"""
Generate NT_PRSTATUS note for thread tid of process pid.
"""
Generate NT_PRSTATUS note for thread tid of process pid.
"""
core = self.cores[tid]
regs = core["thread_info"]["gpregs"]
pstree = self.pstree[pid]
@ -382,8 +382,8 @@ class coredump_generator:
def _gen_fpregset(self, pid, tid):
"""
Generate NT_FPREGSET note for thread tid of process pid.
"""
Generate NT_FPREGSET note for thread tid of process pid.
"""
core = self.cores[tid]
regs = core["thread_info"]["fpregs"]
@ -402,7 +402,7 @@ class coredump_generator:
*regs["st_space"])
fpregset.xmm_space = (ctypes.c_uint * len(regs["xmm_space"]))(
*regs["xmm_space"])
#fpregset.padding = regs["padding"] unused
#fpregset.padding = regs["padding"] unused
nhdr = elf.Elf64_Nhdr()
nhdr.n_namesz = 5
@ -418,8 +418,8 @@ class coredump_generator:
def _gen_x86_xstate(self, pid, tid):
"""
Generate NT_X86_XSTATE note for thread tid of process pid.
"""
Generate NT_X86_XSTATE note for thread tid of process pid.
"""
core = self.cores[tid]
fpregs = core["thread_info"]["fpregs"]
@ -459,8 +459,8 @@ class coredump_generator:
def _gen_siginfo(self, pid, tid):
"""
Generate NT_SIGINFO note for thread tid of process pid.
"""
Generate NT_SIGINFO note for thread tid of process pid.
"""
siginfo = elf.siginfo_t()
# FIXME zeroify everything for now
ctypes.memset(ctypes.addressof(siginfo), 0, ctypes.sizeof(siginfo))
@ -479,8 +479,8 @@ class coredump_generator:
def _gen_auxv(self, pid):
"""
Generate NT_AUXV note for thread tid of process pid.
"""
Generate NT_AUXV note for thread tid of process pid.
"""
mm = self.mms[pid]
num_auxv = len(mm["mm_saved_auxv"]) / 2
@ -506,8 +506,8 @@ class coredump_generator:
def _gen_files(self, pid):
"""
Generate NT_FILE note for process pid.
"""
Generate NT_FILE note for process pid.
"""
mm = self.mms[pid]
class mmaped_file_info:
@ -597,8 +597,8 @@ class coredump_generator:
def _gen_notes(self, pid):
"""
Generate notes for core dump of process pid.
"""
Generate notes for core dump of process pid.
"""
notes = []
notes.append(self._gen_prpsinfo(pid))
@ -622,8 +622,8 @@ class coredump_generator:
def _get_page(self, pid, page_no):
"""
Try to find memory page page_no in pages.img image for process pid.
"""
Try to find memory page page_no in pages.img image for process pid.
"""
pagemap = self.pagemaps[pid]
# First entry is pagemap_head, we will need it later to open
@ -654,8 +654,8 @@ class coredump_generator:
def _gen_mem_chunk(self, pid, vma, size):
"""
Obtain vma contents for process pid.
"""
Obtain vma contents for process pid.
"""
f = None
if size == 0:
@ -749,8 +749,8 @@ class coredump_generator:
def _gen_cmdline(self, pid):
"""
Generate full command with arguments.
"""
Generate full command with arguments.
"""
mm = self.mms[pid]
vma = {}
@ -768,8 +768,8 @@ class coredump_generator:
def _get_vma_dump_size(self, vma):
"""
Calculate amount of vma to put into core dump.
"""
Calculate amount of vma to put into core dump.
"""
if vma["status"] & status["VMA_AREA_VVAR"] or \
vma["status"] & status["VMA_AREA_VSYSCALL"] or \
vma["status"] & status["VMA_AREA_VDSO"]:
@ -791,8 +791,8 @@ class coredump_generator:
def _get_vma_flags(self, vma):
"""
Convert vma flags int elf flags.
"""
Convert vma flags int elf flags.
"""
flags = 0
if vma['prot'] & prot["PROT_READ"]:
@ -808,8 +808,8 @@ class coredump_generator:
def _gen_vmas(self, pid):
"""
Generate vma contents for core dump for process pid.
"""
Generate vma contents for core dump for process pid.
"""
mm = self.mms[pid]
class vma_class:

View File

@ -120,9 +120,9 @@ NT_FPREGSET = 2 # #define NT_FPREGSET 2 /* Contains copy of f
NT_PRPSINFO = 3 # #define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */
NT_AUXV = 6 # #define NT_AUXV 6 /* Contains copy of auxv array */
NT_SIGINFO = 0x53494749 # #define NT_SIGINFO 0x53494749 /* Contains copy of siginfo_t,
# size might increase */
# size might increase */
NT_FILE = 0x46494c45 # #define NT_FILE 0x46494c45 /* Contains information about mapped
# files */
# files */
NT_X86_XSTATE = 0x202 # #define NT_X86_XSTATE 0x202 /* x86 extended state using xsave */
@ -259,7 +259,7 @@ class user_regs_struct(ctypes.Structure): # struct user_regs_struct
] # };
#elf_greg_t = ctypes.c_ulonglong
#elf_greg_t = ctypes.c_ulonglong
#ELF_NGREG = ctypes.sizeof(user_regs_struct)/ctypes.sizeof(elf_greg_t)
#elf_gregset_t = elf_greg_t*ELF_NGREG
elf_gregset_t = user_regs_struct
@ -450,7 +450,7 @@ class _siginfo_t_U_sigpoll(ctypes.Structure): # struct
] # } _sigpoll;
# /* SIGSYS. */
# /* SIGSYS. */
class _siginfo_t_U_sigsys(ctypes.Structure): # struct
_fields_ = [ # {
("_call_addr", ctypes.c_void_p
@ -515,7 +515,7 @@ class _siginfo_t_U(ctypes.Union): # union
# int si_fd;
# } _sigpoll;
#
# /* SIGSYS. */
# /* SIGSYS. */
("_sigsys", _siginfo_t_U_sigpoll) # struct
# {
# void *_call_addr; /* Calling user insn. */
@ -587,7 +587,7 @@ class siginfo_t(ctypes.Structure): # typedef struct
# int si_fd;
# } _sigpoll;
#
# /* SIGSYS. */
# /* SIGSYS. */
# struct
# {
# void *_call_addr; /* Calling user insn. */

View File

@ -11,8 +11,8 @@ import pycriu.rpc_pb2 as rpc
class _criu_comm:
"""
Base class for communication classes.
"""
Base class for communication classes.
"""
COMM_SK = 0
COMM_FD = 1
COMM_BIN = 2
@ -22,22 +22,22 @@ class _criu_comm:
def connect(self, daemon):
"""
Connect to criu and return socket object.
daemon -- is for whether or not criu should daemonize if executing criu from binary(comm_bin).
"""
Connect to criu and return socket object.
daemon -- is for whether or not criu should daemonize if executing criu from binary(comm_bin).
"""
pass
def disconnect(self):
"""
Disconnect from criu.
"""
Disconnect from criu.
"""
pass
class _criu_comm_sk(_criu_comm):
"""
Communication class for unix socket.
"""
Communication class for unix socket.
"""
def __init__(self, sk_path):
self.comm_type = self.COMM_SK
@ -55,8 +55,8 @@ class _criu_comm_sk(_criu_comm):
class _criu_comm_fd(_criu_comm):
"""
Communication class for file descriptor.
"""
Communication class for file descriptor.
"""
def __init__(self, fd):
self.comm_type = self.COMM_FD
@ -74,8 +74,8 @@ class _criu_comm_fd(_criu_comm):
class _criu_comm_bin(_criu_comm):
"""
Communication class for binary.
"""
Communication class for binary.
"""
def __init__(self, bin_path):
self.comm_type = self.COMM_BIN
@ -139,8 +139,8 @@ class _criu_comm_bin(_criu_comm):
class CRIUException(Exception):
"""
Exception class for handling and storing criu errors.
"""
Exception class for handling and storing criu errors.
"""
typ = None
_str = None
@ -150,8 +150,8 @@ class CRIUException(Exception):
class CRIUExceptionInternal(CRIUException):
"""
Exception class for handling and storing internal errors.
"""
Exception class for handling and storing internal errors.
"""
def __init__(self, typ, s):
self.typ = typ
@ -161,8 +161,8 @@ class CRIUExceptionInternal(CRIUException):
class CRIUExceptionExternal(CRIUException):
"""
Exception class for handling and storing criu RPC errors.
"""
Exception class for handling and storing criu RPC errors.
"""
def __init__(self, req_typ, resp_typ, errno):
self.typ = req_typ
@ -196,8 +196,8 @@ class CRIUExceptionExternal(CRIUException):
class criu:
"""
Call criu through RPC.
"""
Call criu through RPC.
"""
opts = None #CRIU options in pb format
_comm = None #Communication method
@ -209,26 +209,26 @@ class criu:
def use_sk(self, sk_name):
"""
Access criu using unix socket which that belongs to criu service daemon.
"""
Access criu using unix socket which that belongs to criu service daemon.
"""
self._comm = _criu_comm_sk(sk_name)
def use_fd(self, fd):
"""
Access criu using provided fd.
"""
Access criu using provided fd.
"""
self._comm = _criu_comm_fd(fd)
def use_binary(self, bin_name):
"""
Access criu by execing it using provided path to criu binary.
"""
Access criu by execing it using provided path to criu binary.
"""
self._comm = _criu_comm_bin(bin_name)
def _send_req_and_recv_resp(self, req):
"""
As simple as send request and receive response.
"""
As simple as send request and receive response.
"""
# In case of self-dump we need to spawn criu swrk detached
# from our current process, as criu has a hard time separating
# process resources from its own if criu is located in a same
@ -262,8 +262,8 @@ class criu:
def check(self):
"""
Checks whether the kernel support is up-to-date.
"""
Checks whether the kernel support is up-to-date.
"""
req = rpc.criu_req()
req.type = rpc.CHECK
@ -274,8 +274,8 @@ class criu:
def dump(self):
"""
Checkpoint a process/tree identified by opts.pid.
"""
Checkpoint a process/tree identified by opts.pid.
"""
req = rpc.criu_req()
req.type = rpc.DUMP
req.opts.MergeFrom(self.opts)
@ -289,8 +289,8 @@ class criu:
def pre_dump(self):
"""
Checkpoint a process/tree identified by opts.pid.
"""
Checkpoint a process/tree identified by opts.pid.
"""
req = rpc.criu_req()
req.type = rpc.PRE_DUMP
req.opts.MergeFrom(self.opts)
@ -304,8 +304,8 @@ class criu:
def restore(self):
"""
Restore a process/tree.
"""
Restore a process/tree.
"""
req = rpc.criu_req()
req.type = rpc.RESTORE
req.opts.MergeFrom(self.opts)

View File

@ -12,8 +12,8 @@
# SIZE ::= "32 bit integer, equals the PAYLOAD length"
#
# Images v1.1 NOTE: MAGIC now consist of 2 32 bit integers, first one is
# MAGIC_COMMON or MAGIC_SERVICE and the second one is same as MAGIC
# in images V1.0. We don't keep "first" magic in json images.
# MAGIC_COMMON or MAGIC_SERVICE and the second one is same as MAGIC
# in images V1.0. We don't keep "first" magic in json images.
#
# In order to convert images to human-readable format, we use dict(json).
# Using json not only allows us to easily read\write images, but also
@ -23,18 +23,18 @@
# Using dict(json) format, criu images can be described like:
#
# {
# 'magic' : 'FOO',
# 'entries' : [
# entry,
# ...
# ]
# 'magic' : 'FOO',
# 'entries' : [
# entry,
# ...
# ]
# }
#
# Entry, in its turn, could be described as:
#
# {
# pb_msg,
# 'extra' : extra_msg
# pb_msg,
# 'extra' : extra_msg
# }
#
import io
@ -72,23 +72,23 @@ class MagicException(Exception):
# format to/from dict(json).
class entry_handler:
"""
Generic class to handle loading/dumping criu images
entries from/to bin format to/from dict(json).
"""
Generic class to handle loading/dumping criu images
entries from/to bin format to/from dict(json).
"""
def __init__(self, payload, extra_handler=None):
"""
Sets payload class and extra handler class.
"""
Sets payload class and extra handler class.
"""
self.payload = payload
self.extra_handler = extra_handler
def load(self, f, pretty=False, no_payload=False):
"""
Convert criu image entries from binary format to dict(json).
Takes a file-like object and returnes a list with entries in
dict(json) format.
"""
Convert criu image entries from binary format to dict(json).
Takes a file-like object and returnes a list with entries in
dict(json) format.
"""
entries = []
while True:
@ -128,17 +128,17 @@ class entry_handler:
def loads(self, s, pretty=False):
"""
Same as load(), but takes a string as an argument.
"""
Same as load(), but takes a string as an argument.
"""
f = io.BytesIO(s)
return self.load(f, pretty)
def dump(self, entries, f):
"""
Convert criu image entries from dict(json) format to binary.
Takes a list of entries and a file-like object to write entries
in binary format to.
"""
Convert criu image entries from dict(json) format to binary.
Takes a list of entries and a file-like object to write entries
in binary format to.
"""
for entry in entries:
extra = entry.pop('extra', None)
@ -156,17 +156,17 @@ class entry_handler:
def dumps(self, entries):
"""
Same as dump(), but doesn't take file-like object and just
returns a string.
"""
Same as dump(), but doesn't take file-like object and just
returns a string.
"""
f = io.BytesIO('')
self.dump(entries, f)
return f.read()
def count(self, f):
"""
Counts the number of top-level object in the image file
"""
Counts the number of top-level object in the image file
"""
entries = 0
while True:
@ -183,10 +183,10 @@ class entry_handler:
# Special handler for pagemap.img
class pagemap_handler:
"""
Special entry handler for pagemap.img, which is unique in a way
that it has a header of pagemap_head type followed by entries
of pagemap_entry type.
"""
Special entry handler for pagemap.img, which is unique in a way
that it has a header of pagemap_head type followed by entries
of pagemap_entry type.
"""
def load(self, f, pretty=False, no_payload=False):
entries = []
@ -547,10 +547,10 @@ def __rhandler(f):
def load(f, pretty=False, no_payload=False):
"""
Convert criu image from binary format to dict(json).
Takes a file-like object to read criu image from.
Returns criu image in dict(json) format.
"""
Convert criu image from binary format to dict(json).
Takes a file-like object to read criu image from.
Returns criu image in dict(json) format.
"""
image = {}
m, handler = __rhandler(f)
@ -574,18 +574,18 @@ def info(f):
def loads(s, pretty=False):
"""
Same as load(), but takes a string.
"""
Same as load(), but takes a string.
"""
f = io.BytesIO(s)
return load(f, pretty)
def dump(img, f):
"""
Convert criu image from dict(json) format to binary.
Takes an image in dict(json) format and file-like
object to write to.
"""
Convert criu image from dict(json) format to binary.
Takes an image in dict(json) format and file-like
object to write to.
"""
m = img['magic']
magic_val = magic.by_name[img['magic']]
@ -609,9 +609,9 @@ def dump(img, f):
def dumps(img):
"""
Same as dump(), but takes only an image and returns
a string.
"""
Same as dump(), but takes only an image and returns
a string.
"""
f = io.BytesIO(b'')
dump(img, f)
return f.getvalue()

View File

@ -15,8 +15,8 @@ def main(argv):
out = open(magic_py, 'w+')
# all_magic is used to parse constructions like:
# #define PAGEMAP_MAGIC 0x56084025
# #define SHMEM_PAGEMAP_MAGIC PAGEMAP_MAGIC
# #define PAGEMAP_MAGIC 0x56084025
# #define SHMEM_PAGEMAP_MAGIC PAGEMAP_MAGIC
all_magic = {}
# and magic is used to store only unique magic.
magic = {}