[PATCH 1/7] Make restore_obj() tolerate a preexisting object in the hash (v2)

Serge E. Hallyn serue at us.ibm.com
Thu Mar 18 17:04:34 PDT 2010


Quoting Dan Smith (danms at us.ibm.com):
> ... as long as the pointer is the same as that returned from the restore
> function.  Also move the compulsory ref_drop() so that it only gets
> done if we created the new object.
> 
> The existing object tolerance is important for netdev restore because it
> means that I can refer to a peer by its objref instead of needing the
> (previously-rejected) veth_peer() function.  If this is not acceptable,
> then I'll need to keep a separate list of pairs.
> 
> Changes in v2:
>  - Check that the type of the object already in the hash matches that
>    of the objref header we're reading.
>  - Add a comment about why and how we might get into this sort of
>    situation.
> 
> Signed-off-by: Dan Smith <danms at us.ibm.com>
> ---
>  checkpoint/objhash.c |   31 ++++++++++++++++++++++---------
>  1 files changed, 22 insertions(+), 9 deletions(-)
> 
> diff --git a/checkpoint/objhash.c b/checkpoint/objhash.c
> index 7208382..65875e3 100644
> --- a/checkpoint/objhash.c
> +++ b/checkpoint/objhash.c
> @@ -1064,16 +1064,29 @@ int restore_obj(struct ckpt_ctx *ctx, struct ckpt_hdr_objref *h)
>  	if (IS_ERR(ptr))
>  		return PTR_ERR(ptr);
> 
> -	if (obj_find_by_objref(ctx, h->objref))
> -		obj = ERR_PTR(-EINVAL);
> -	else
> +	obj = obj_find_by_objref(ctx, h->objref);
> +	if (!obj) {
>  		obj = obj_new(ctx, ptr, h->objref, h->objtype);
> -	/*
> -	 * Drop an extra reference to the object returned by ops->restore:
> -	 * On success, this clears the extra reference taken by obj_new(),
> -	 * and on failure, this cleans up the object itself.
> -	 */
> -	ops->ref_drop(ptr, 0);
> +		/*
> +		 * Drop an extra reference to the object returned by
> +		 * ops->restore: On success, this clears the extra
> +		 * reference taken by obj_new(), and on failure, this
> +		 * cleans up the object itself.

I don't think this part of the comment is quite right here.  The
"on failure this cleans up the object itself" really is for the
ref_drop under IS_ERR() check below.

The ref_drop here is for the ref taken by obj_new(), which is only
done in this path of course.

> +		 */
> +		ops->ref_drop(ptr, 0);
> +	} else if ((obj->ptr != ptr) || (obj->ops->obj_type != h->objtype)) {
> +		/* Normally, we expect an object to not already exist
> +		 * in the hash.  However, for some special scenarios
> +		 * where we're restoring sets of objects that must be
> +		 * co-allocated (such, as veth netdev pairs) we need
> +		 * to tolerate this case if the second restore returns
> +		 * the correct type and pointer, as specified in the
> +		 * existing object.  If either of those don't match,
> +		 * we fail.
> +		 */
> +		obj = ERR_PTR(-EINVAL);
> +	}
> +
>  	if (IS_ERR(obj)) {

Here point out that we are putting the reference taken by
ops->restore().  If obj is not an error, then we keep an
extra ref to pin obj while it is on the hash.

>  		ops->ref_drop(ptr, 1);
>  		return PTR_ERR(obj);

-serge


More information about the Containers mailing list