[CRIU] [PATCH 13/32] tools: cpt2 -- Introduce "object" abstraction

Cyrill Gorcunov gorcunov at openvz.org
Sat Mar 30 17:42:51 EDT 2013


Objects are aimed to carry real data read from dump files.
Usually the data read is placed after the __payload pointer

[ though the object may carry another structures like a
  container and in this case __payload is followed by
  embedded data while image data addressed by o_image
  member, will be explained later ].

For fast lookup of objects by their position read from dumpfile
there is 16K object chain-hash. 16K should be enough for now,
still if one day we see serious contention (which I quite doubt
in) the hash size can be easily increased by tuning OBJS_HASH_BITS
value.

Because of dumpfile format specifics objects types up to CPT_OBJ_MAX
are linked to per-type lists, allowing a caller to walk over all
of them via regular list helpers code. If possible try to not use
@o_list member for anything else, until really needed.

When read, each object is assigned with unique 32 bit id.

Because objects on its own are not that usefull, the general
idea of their presense is to carry other structures. For this
sake a number of macros provided in obj.h header file.

Lets consider we need to work with the following structure

struct some_struct {
	struct list_head	list;
	struct cpt_image	image;
} *entry;

where @list is a member we use for own linking (outside of objects'
subsystem) and @image is some member from cpt-image.h file and
represent a record in dumpfile.

First we allocate structure as

	entry = obj_alloc_to(struct some_struct, image);

then we may read data to @image member with help of
read_obj_cpt() macro.

Once object no longer needed, we can call to obj_free_to(entry)
and get it destroyed.

For convenience helpers are postfixed with _to and _of names,
_to is used when operate with pointer to a compound object, and
_of operate with pointer to obj_t.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 tools/cpt2/src/Makefile      |   1 +
 tools/cpt2/src/include/obj.h | 223 +++++++++++++++++++++++++++++++++++
 tools/cpt2/src/obj.c         | 270 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 494 insertions(+)
 create mode 100644 tools/cpt2/src/include/obj.h
 create mode 100644 tools/cpt2/src/obj.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0013-tools-cpt2-Introduce-object-abstraction.patch
Type: text/x-patch
Size: 12932 bytes
Desc: not available
URL: <http://lists.openvz.org/pipermail/criu/attachments/20130331/abdd6e7f/attachment-0001.bin>


More information about the CRIU mailing list