Linux Container Development
 help / color / mirror / Atom feed
From: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org
Subject: [PATCH 1/5] Add _ckpt_read_hdr_type() helper
Date: Wed, 22 Jul 2009 13:41:37 -0700	[thread overview]
Message-ID: <1248295301-30930-2-git-send-email-danms@us.ibm.com> (raw)
In-Reply-To: <1248295301-30930-1-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

This helper function gives us a way to read a header object and the
subsequent payload from the checkpoint stream directly into our own
buffer.  This is used by the net/checkpoint.c code to read skb's
without a memcpy().

Signed-off-by: Dan Smith <danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
 checkpoint/restart.c       |   36 ++++++++++++++++++++++++++++++++++--
 include/linux/checkpoint.h |    4 ++++
 2 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/checkpoint/restart.c b/checkpoint/restart.c
index 677f030..5cbe491 100644
--- a/checkpoint/restart.c
+++ b/checkpoint/restart.c
@@ -178,6 +178,38 @@ int _ckpt_read_string(struct ckpt_ctx *ctx, void *ptr, int len)
 }
 
 /**
+ * _ckpt_read_hdr_type - read a header record and check the type
+ * @ctx: checkpoint context
+ * @h: provided header buffer (returned)
+ * @type: optional type, 0 to ignore
+ *
+ * Returns the size of the payload to follow or negative on error
+ */
+int _ckpt_read_hdr_type(struct ckpt_ctx *ctx, struct ckpt_hdr *h, int type)
+{
+	int ret;
+
+	ret = ckpt_kread(ctx, h, sizeof(*h));
+	if (ret < 0)
+		return ret;
+	else if (type && h->type != type)
+		return -EINVAL;
+	else
+		return h->len - sizeof(*h);
+}
+
+/**
+ * _ckpt_read_payload - read the payload associated with a recent header read
+ * @ctx: checkpoint_context
+ * @h: header returned from _ckpt_read_hdr_type()
+ * @buffer: pre-allocated buffer to store payload
+ */
+int _ckpt_read_payload(struct ckpt_ctx *ctx, struct ckpt_hdr *h, void *buffer)
+{
+	return ckpt_kread(ctx, buffer, h->len - sizeof(*h));
+}
+
+/**
  * ckpt_read_obj - allocate and read an object (ckpt_hdr followed by payload)
  * @ctx: checkpoint context
  * @h: object descriptor
@@ -193,7 +225,7 @@ static void *ckpt_read_obj(struct ckpt_ctx *ctx, int len, int max)
 	int ret;
 
  again:
-	ret = ckpt_kread(ctx, &hh, sizeof(hh));
+	ret = _ckpt_read_hdr_type(ctx, &hh, 0);
 	if (ret < 0)
 		return ERR_PTR(ret);
 	_ckpt_debug(CKPT_DRW, "type %d len %d(%d,%d)\n",
@@ -218,7 +250,7 @@ static void *ckpt_read_obj(struct ckpt_ctx *ctx, int len, int max)
 
 	*h = hh;	/* yay ! */
 
-	ret = ckpt_kread(ctx, (h + 1), hh.len - sizeof(struct ckpt_hdr));
+	ret = _ckpt_read_payload(ctx, &hh, (h + 1));
 	if (ret < 0) {
 		ckpt_hdr_put(ctx, h);
 		h = ERR_PTR(ret);
diff --git a/include/linux/checkpoint.h b/include/linux/checkpoint.h
index 60d1116..2e9772e 100644
--- a/include/linux/checkpoint.h
+++ b/include/linux/checkpoint.h
@@ -63,6 +63,10 @@ extern int ckpt_write_string(struct ckpt_ctx *ctx, char *str, int len);
 extern void __ckpt_write_err(struct ckpt_ctx *ctx, char *fmt, ...);
 extern int ckpt_write_err(struct ckpt_ctx *ctx, char *fmt, ...);
 
+extern int _ckpt_read_payload(struct ckpt_ctx *ctx, struct ckpt_hdr *h,
+			      void *buffer);
+extern int _ckpt_read_hdr_type(struct ckpt_ctx *ctx, struct ckpt_hdr *h,
+			       int type);
 extern int _ckpt_read_obj_type(struct ckpt_ctx *ctx,
 			       void *ptr, int len, int type);
 extern int _ckpt_read_nbuffer(struct ckpt_ctx *ctx, void *ptr, int len);
-- 
1.6.2.5

  parent reply	other threads:[~2009-07-22 20:41 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-22 20:41 Add Checkpoint/Restart support for UNIX sockets Dan Smith
     [not found] ` <1248295301-30930-1-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-07-22 20:41   ` Dan Smith [this message]
     [not found]     ` <1248295301-30930-2-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-07-23  3:59       ` [PATCH 1/5] Add _ckpt_read_hdr_type() helper Oren Laadan
     [not found]         ` <4A67E027.1050602-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>
2009-07-23 16:43           ` Dan Smith
2009-07-22 20:41   ` [PATCH 2/5] Add an errno validation function Dan Smith
     [not found]     ` <1248295301-30930-3-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-07-23  3:17       ` Oren Laadan
     [not found]         ` <4A67D654.2000206-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-07-23 15:40           ` Dan Smith
2009-07-22 20:41   ` [PATCH 3/5] Add a ckpt_read_string() function to allow reading of a variable-length (but length-capped) string from the checkpoint stream Dan Smith
     [not found]     ` <1248295301-30930-4-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-07-23  4:19       ` Oren Laadan
     [not found]         ` <4A67E4EC.3070509-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-07-23 16:58           ` Dan Smith
     [not found]             ` <87y6qfnxoq.fsf-FLMGYpZoEPULwtHQx/6qkW3U47Q5hpJU@public.gmane.org>
2009-07-24  1:32               ` Oren Laadan
2009-07-22 20:41   ` [PATCH 4/5] Add a common sock_bind() helper to unify the security hook Dan Smith
2009-07-22 20:41 ` [PATCH 5/5] c/r: Add AF_UNIX support (v6) Dan Smith
     [not found]   ` <1248295301-30930-6-git-send-email-danms-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-07-28 16:54     ` Oren Laadan
2009-07-28 20:34       ` Dan Smith
2009-07-28 21:18         ` Oren Laadan
2009-07-29 13:36           ` Serge E. Hallyn
2009-07-29 14:49             ` Dan Smith
2009-07-29 14:59               ` Serge E. Hallyn
2009-07-29 15:03                 ` Dan Smith
2009-07-29 15:34             ` Oren Laadan
2009-07-29 18:37           ` Dan Smith
2009-07-30 15:49           ` Dan Smith
2009-07-30 22:10             ` John Dykstra
2009-07-30 22:12               ` John Dykstra
2009-07-30 22:14                 ` Dan Smith
2009-08-04  8:27             ` Oren Laadan
2009-08-04 15:16               ` Dan Smith
2009-08-04 17:05                 ` Oren Laadan
2009-08-04 17:13                   ` Dan Smith
2009-07-29  1:56         ` Serge E. Hallyn

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=1248295301-30930-2-git-send-email-danms@us.ibm.com \
    --to=danms-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@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