[PATCH 1/2] Minor simplification of cr_ctx_alloc(), cr_ctx_free()

Oren Laadan orenl at cs.columbia.edu
Tue Oct 21 13:04:36 PDT 2008


Decalre 'static' cr_ctx_alloc(), cr_ctx_free()
Common error path in cr_ctx_alloc()
Add comment for preempt_disable()/enable() in cr_write_cpu_fpu()
---
 arch/x86/mm/checkpoint.c |   10 ++++++----
 checkpoint/sys.c         |   35 ++++++++++++++++++-----------------
 2 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/arch/x86/mm/checkpoint.c b/arch/x86/mm/checkpoint.c
index 554dbff..9c2d949 100644
--- a/arch/x86/mm/checkpoint.c
+++ b/arch/x86/mm/checkpoint.c
@@ -154,7 +154,7 @@ void cr_write_cpu_fpu(struct cr_hdr_cpu *hh, struct task_struct *t)
 
 	/* i387 + MMU + SSE logic */
 
-	preempt_disable();
+	preempt_disable();	/* needed if t == current */
 
 	hh->used_math = tsk_used_math(t) ? 1 : 0;
 	if (hh->used_math) {
@@ -163,14 +163,16 @@ void cr_write_cpu_fpu(struct cr_hdr_cpu *hh, struct task_struct *t)
 		 * have been cleared when task was conexted-switched out...
 		 * except if we are in process context, in which case we do
 		 */
-		if (thread_info->status & TS_USEDFPU)
-			unlazy_fpu(current);
+		if (t == current) {
+			if (thread_info->status & TS_USEDFPU)
+				   unlazy_fpu(current);
+		}
 
 		hh->has_fxsr = cpu_has_fxsr;
 		memcpy(&hh->xstate, thread->xstate, sizeof(*thread->xstate));
 	}
 
-	preempt_enable();
+	preempt_enable();	/* needed if t == current */
 }
 
 #endif	/* CONFIG_X86_64 */
diff --git a/checkpoint/sys.c b/checkpoint/sys.c
index c1f2c8f..aa519ab 100644
--- a/checkpoint/sys.c
+++ b/checkpoint/sys.c
@@ -156,7 +156,7 @@ void cr_hbuf_put(struct cr_ctx *ctx, int n)
 /* unique checkpoint identifier (FIXME: should be per-container) */
 static atomic_t cr_ctx_count;
 
-void cr_ctx_free(struct cr_ctx *ctx)
+static void cr_ctx_free(struct cr_ctx *ctx)
 {
 	if (ctx->file)
 		fput(ctx->file);
@@ -172,30 +172,30 @@ void cr_ctx_free(struct cr_ctx *ctx)
 	kfree(ctx);
 }
 
-struct cr_ctx *cr_ctx_alloc(pid_t pid, int fd, unsigned long flags)
+static struct cr_ctx *cr_ctx_alloc(pid_t pid, int fd, unsigned long flags)
 {
 	struct cr_ctx *ctx;
+	int err;
 
 	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
 	if (!ctx)
 		return ERR_PTR(-ENOMEM);
 
+	ctx->flags = flags;
+	ctx->pid = pid;
+
+	err = -EBADF;
 	ctx->file = fget(fd);
-	if (!ctx->file) {
-		cr_ctx_free(ctx);
-		return ERR_PTR(-EBADF);
-	}
+	if (!ctx->file)
+		goto err;
 
+	err = -ENOMEM;
 	ctx->hbuf = kmalloc(CR_HBUF_TOTAL, GFP_KERNEL);
-	if (!ctx->hbuf) {
-		cr_ctx_free(ctx);
-		return ERR_PTR(-ENOMEM);
-	}
+	if (!ctx->hbuf)
+		goto err;
 
-	if (cr_objhash_alloc(ctx) < 0) {
-		cr_ctx_free(ctx);
-		return ERR_PTR(-ENOMEM);
-	}
+	if (cr_objhash_alloc(ctx) < 0)
+		goto err;
 
 	/*
 	 * assume checkpointer is in container's root vfs
@@ -206,12 +206,13 @@ struct cr_ctx *cr_ctx_alloc(pid_t pid, int fd, unsigned long flags)
 
 	INIT_LIST_HEAD(&ctx->pgarr_list);
 
-	ctx->pid = pid;
-	ctx->flags = flags;
-
 	ctx->crid = atomic_inc_return(&cr_ctx_count);
 
 	return ctx;
+
+ err:
+	cr_ctx_free(ctx);
+	return ERR_PTR(err);
 }
 
 /**
-- 
1.5.4.3

------------------------------------------------------------------------



More information about the Containers mailing list