On Fri, 2009-03-20 at 14:47 -0400, Oren Laadan wrote:
> + /* if file-backed, add 'file' to the hash (will keep a reference) */
> + if (vma->vm_file) {
> + new = cr_obj_add_ptr(ctx, vma->vm_file,
> + &objref, CR_OBJ_FILE, 0);
> + cr_debug("vma %p objref %d file %p)\n",
> + vma, objref, vma->vm_file);
> + if (new < 0) {
> + ret = new;
> + goto out;
> + }
> + }
This is a very, very common pattern in these patches now.
Can't we do better than this? The objhash already has intimate
knowledge of the files with which it deals. So, why not also teach it
how to write those into the checkpoint stream?
int cr_obj_add_ptr(struct cr_ctx *ctx, void *ptr, int *objref,
unsigned short type, unsigned short flags)
{
struct cr_objref *obj;
int ret = 0;
obj = cr_obj_find_by_ptr(ctx, ptr);
if (!obj) {
obj = cr_obj_new(ctx, ptr, 0, type, flags);
if (IS_ERR(obj))
return PTR_ERR(obj);
else
ret = 1;
} else if (obj->type != type) /* sanity check */
return -EINVAL;
*objref = obj->objref;
- return ret;
+ return cr_write_object(ctx, ptr, type);
}
int cr_write_object(ctx, ptr, type)
{
switch(type) {
...
case CR_OBJ_FILE:
return cr_write_file(ctx, (file *)ptr);
...
}
}
Why not? It fits in with the rest of the objhash.
-- Dave
_______________________________________________
Containers mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/containers
_______________________________________________
Devel mailing list
[email protected]
https://openvz.org/mailman/listinfo/devel