Skip to contentSkip to conversation

Supporting patches for netns/netdev

PATCH In review Dan Smith 2 participants 8 messages Feb 9, 2010 6 messages not in the archive

lore
Share & tools
lore

Dan Smith

author
#0 lore raw

These two patches make a couple of small (yet potentially controversial) changes to the cleanup of the objhash and the restore_obj() function. The way network devices have to get torn down (in the case of a failed restore) and the way I need to create veth pairs are why I need this sort of functionality.

Each could be done a number of different ways, but I'm hoping these quick changes are acceptable.

A message that is not in the archive (sent off-list or not yet received): 1265736604-24194-1-git-send-email-danms-r/[email protected]

author
#2 lore raw

PATCH 1/2 Make restore_obj() tolerate a preexisting object in the hash

... 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.

---
 checkpoint/objhash.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)
checkpoint/objhash.c +11 -8
index 0b06b06..6051c8d 100644
@@ -1059,16 +1059,19 @@ 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 = obj_find_by_objref(ctx, h->objref);
+	if (obj && (obj->ptr != ptr))
 		obj = ERR_PTR(-EINVAL);
-	else
+	else {
 		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.
+		 */
+		ops->ref_drop(ptr, 0);
+	}
 	if (IS_ERR(obj)) {
 		ops->ref_drop(ptr, 1);
 		return PTR_ERR(obj);
Signature · 1 line
1.6.2.5

A message that is not in the archive (sent off-list or not yet received): 1265736604-24194-2-git-send-email-danms-r/[email protected]

#4 lore raw

Re: [PATCH 1/2] Make restore_obj() tolerate a preexisting object in the hash

Quoted 19 lines · Dan Smith

... 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.

---
 checkpoint/objhash.c |   19 +++++++++++--------
 1 files changed, 11 insertions(+), 8 deletions(-)
checkpoint/objhash.c +0 -0
index 0b06b06..6051c8d 100644

checkpoint/objhash.c int restore_obj(struct ckpt_ctx *ctx, struct ckpt_hdr_objref *h) · line 1066

Quoted 10 lines
checkpoint/objhash.c +3 -2
@@ -1059,16 +1059,19 @@ 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 = obj_find_by_objref(ctx, h->objref);
+	if (obj && (obj->ptr != ptr))
 		obj = ERR_PTR(-EINVAL);
-	else
+	else {
 		obj = obj_new(ctx, ptr, h->objref, h->objtype);

Sorry, I *must* not be thinking straight, but...

don't you want to do the obj_new only if obj==NULL here? So

if (obj) {
	if (obj->ptr != ptr)
		return -EINVAL;
	else
		return obj->objref;
}

obj = obj_new(...)
...

?

Quoted 24 lines
checkpoint/objhash.c +8 -6
-	/*
-	 * 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.
+		 */
+		ops->ref_drop(ptr, 0);
+	}
 	if (IS_ERR(obj)) {
 		ops->ref_drop(ptr, 1);
 		return PTR_ERR(obj);
Signature · 6 lines
1.6.2.5

_______________________________________________
Containers mailing list
Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers

A message that is not in the archive (sent off-list or not yet received): 20100209212154.GA32513-r/[email protected]

author
#6 lore raw

Re: [PATCH 1/2] Make restore_obj() tolerate a preexisting object in the hash

SH> Sorry, I *must* not be thinking straight, but... SH> don't you want to do the obj_new only if obj==NULL here? So

Er, um, yes :)

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: danms-r/[email protected]
author
#7 lore raw

PATCH 2/2 Move ckpt_objhash_free() to before we destroy the deferqueues

In reply to a message not in the archive

This makes the deferqueue cleanup function run after all the objects have been purged from the hash and thus gives us an opportunity to cleanup things that *must* happen after the last reference is dropped (such as unregister_netdev()).

---
 checkpoint/sys.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
checkpoint/sys.c +2 -1
index f04b8b0..f739932 100644
@@ -223,6 +223,8 @@ static void ckpt_ctx_free(struct ckpt_ctx *ctx)
 	if (ctx->kflags & CKPT_CTX_RESTART)
 		restore_debug_free(ctx);
 
+	ckpt_obj_hash_free(ctx);
+
 	if (ctx->deferqueue)
 		deferqueue_destroy(ctx->deferqueue);
 
@@ -234,7 +236,6 @@ static void ckpt_ctx_free(struct ckpt_ctx *ctx)
 	if (ctx->logfile)
 		fput(ctx->logfile);
 
-	ckpt_obj_hash_free(ctx);
 	path_put(&ctx->root_fs_path);
 	ckpt_pgarr_free(ctx);
 
Signature · 1 line
1.6.2.5

A message that is not in the archive (sent off-list or not yet received): 1265736604-24194-3-git-send-email-danms-r/[email protected]

#9 lore raw

Re: [PATCH 2/2] Move ckpt_objhash_free() to before we destroy the deferqueues

Well you can't quite do that bc fs/eventpoll.c:ep_items_restore() will use ckpt_obj_fetch().

Would it be safe to make the order:

files_deferqueue()

ckpt_obj_hash_free()

deferqueue()

?

Though that's just waiting to bite us in the ankles whenever we put something in general deferqueue which must ckpt_obj_fetch()...

-serge

Quoted 38 lines · Dan Smith

This makes the deferqueue cleanup function run after all the objects have been purged from the hash and thus gives us an opportunity to cleanup things that *must* happen after the last reference is dropped (such as unregister_netdev()).

---
 checkpoint/sys.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
checkpoint/sys.c +2 -1
index f04b8b0..f739932 100644
@@ -223,6 +223,8 @@ static void ckpt_ctx_free(struct ckpt_ctx *ctx)
 	if (ctx->kflags & CKPT_CTX_RESTART)
 		restore_debug_free(ctx);
 
+	ckpt_obj_hash_free(ctx);
+
 	if (ctx->deferqueue)
 		deferqueue_destroy(ctx->deferqueue);
 
@@ -234,7 +236,6 @@ static void ckpt_ctx_free(struct ckpt_ctx *ctx)
 	if (ctx->logfile)
 		fput(ctx->logfile);
 
-	ckpt_obj_hash_free(ctx);
 	path_put(&ctx->root_fs_path);
 	ckpt_pgarr_free(ctx);
 
Signature · 6 lines
1.6.2.5

_______________________________________________
Containers mailing list
Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers

A message that is not in the archive (sent off-list or not yet received): 20100209212928.GB32513-r/[email protected]

author
#11 lore raw

Re: [PATCH 2/2] Move ckpt_objhash_free() to before we destroy the deferqueues

SH> Well you can't quite do that bc fs/eventpoll.c:ep_items_restore() SH> will use ckpt_obj_fetch().

That runs in the deferqueue_run() function, not the deferqueue_destroy() bit, which is what I'm actually changing the order of here. Right?

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: danms-r/[email protected]

A message that is not in the archive (sent off-list or not yet received): 877hqmhz80.fsf-FLMGYpZoEPULwtHQx/[email protected]

#13 lore raw

Re: [PATCH 2/2] Move ckpt_objhash_free() to before we destroy the deferqueues

Quoted 6 lines · Dan Smith

SH> Well you can't quite do that bc fs/eventpoll.c:ep_items_restore() SH> will use ckpt_obj_fetch().

That runs in the deferqueue_run() function, not the deferqueue_destroy() bit, which is what I'm actually changing the order of here. Right?

Oh. Uh, yeah :)

Can't see any problem with that then.

We'll just need to remember (bc I can't think where to sanely document it) that deferqueue->destructor method may not use ckpt_obj_fetch().

-serge