Linux Container Development
 help / color / mirror / Atom feed
From: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Cc: containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org,
	davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org
Subject: Re: [PATCH 1/7] Make restore_obj() tolerate a preexisting object in the hash (v2)
Date: Fri, 19 Mar 2010 08:01:01 -0700	[thread overview]
Message-ID: <8739zwgxua.fsf@caffeine.danplanet.com> (raw)
In-Reply-To: <20100319000434.GA5505-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org> (Serge E. Hallyn's message of "Thu\, 18 Mar 2010 19\:04\:34 -0500")

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

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

As just discussed on IRC, I couldn't really correct the comment
because the logic it was describing was incorrect.  Below is a version
with the correct comment *and* logic :)

-- 
Dan Smith
IBM Linux Technology Center
email: danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org

Make restore_obj() tolerate a preexisting object in the hash (v3)

... 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 v3:
 - Fix the logic in the case where we need to do an obj_new() and fail,
   so that we don't do ref_drop() twice

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-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/checkpoint/objhash.c b/checkpoint/objhash.c
index 7208382..3b360cb 100644
--- a/checkpoint/objhash.c
+++ b/checkpoint/objhash.c
@@ -1064,17 +1064,32 @@ 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 to balance the one taken by obj_new()
+		 */
+		if (!IS_ERR(obj))
+			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)) {
+		/* This releases our final reference on the object
+		 * returned by ops->restore()
+		 */
 		ops->ref_drop(ptr, 1);
 		return PTR_ERR(obj);
 	}

  parent reply	other threads:[~2010-03-19 15:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-18 20:51 C/R netdev and netns support Dan Smith
     [not found] ` <1268945512-18814-1-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-18 20:51   ` [PATCH 1/7] Make restore_obj() tolerate a preexisting object in the hash (v2) Dan Smith
     [not found]     ` <1268945512-18814-2-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-19  0:04       ` Serge E. Hallyn
     [not found]         ` <20100319000434.GA5505-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-19 15:01           ` Dan Smith [this message]
     [not found]             ` <8739zwgxua.fsf-FLMGYpZoEPULwtHQx/6qkW3U47Q5hpJU@public.gmane.org>
2010-03-19 15:21               ` Serge E. Hallyn
2010-03-18 20:51   ` [PATCH 2/7] Add checkpoint and collect hooks to net_device_ops Dan Smith
2010-03-18 20:51   ` [PATCH 3/7] C/R: Basic support for network namespaces and devices (v6) Dan Smith
     [not found]     ` <1268945512-18814-4-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-19  0:27       ` Serge E. Hallyn
2010-03-19 15:15         ` Dan Smith
2010-03-18 20:51   ` [PATCH 4/7] Add checkpoint support for veth devices (v2) Dan Smith
2010-03-18 20:51   ` [PATCH 5/7] Add loopback checkpoint support (v2) Dan Smith
2010-03-18 20:51   ` [PATCH 6/7] Add a checkpoint handler to the 'sit' device Dan Smith
2010-03-18 20:51   ` [PATCH 7/7] Add checkpoint support to macvlan driver Dan Smith
2010-03-30  4:53   ` C/R netdev and netns support Oren Laadan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8739zwgxua.fsf@caffeine.danplanet.com \
    --to=danms-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
    --cc=davem-fT/PcQaiUtIeIZ0/mPfg9Q@public.gmane.org \
    --cc=serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox