[CRIU] [PATCH 13/32] tools: cpt2 -- Introduce "object" abstraction
Pavel Emelyanov
xemul at parallels.com
Mon Apr 1 06:24:42 EDT 2013
On 03/31/2013 01:42 AM, Cyrill Gorcunov wrote:
>
> 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
>
> +extern int read_obj_cont(int fd, void *p, size_t size);
> +
> +#define read_obj_cont(fd, p) \
> +({ \
> + int __ret = -1; \
> + void *__p = (void *)(p) + sizeof(struct cpt_object_hdr); \
> + u64 __size = sizeof(*p) - sizeof(struct cpt_object_hdr); \
> + \
> + if (read_data(fd, __p, __size, false) == 0) \
> + __ret = 0; \
> + else \
> + pr_err("Can't read object payload\n"); \
> + \
> + __ret; \
> +})
Huh?
More information about the CRIU
mailing list