Linux Container Development
 help / color / mirror / Atom feed
From: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Oren Laadan <orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: Re: [PATCH] c/r: factor out objref handling from {_,}ckpt_read_obj()
Date: Thu, 29 Oct 2009 14:52:13 -0500	[thread overview]
Message-ID: <20091029195213.GA29874@us.ibm.com> (raw)
In-Reply-To: <1256838612-17372-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>

Quoting Oren Laadan (orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org):
> As noted by Matt Helsley, a portion of one of these functions was
> missing the block "dispatching" errors. Otherwise the handling of
> shard objects is pretty much the same, so this patch factors out the
> common code.
> 
> Cc: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
> Signed-off-by: Oren Laadan <orenl-eQaUEPhvms7ENvBUuze7eA@public.gmane.org>

Acked-by: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

Although you could go one step further and pass in len and max
and check those in ckpt_read_obj_dispatch() as well.

-serge

> ---
>  checkpoint/restart.c |   58 ++++++++++++++++++++++++++-----------------------
>  1 files changed, 31 insertions(+), 27 deletions(-)
> 
> diff --git a/checkpoint/restart.c b/checkpoint/restart.c
> index 9b75de8..130b4b2 100644
> --- a/checkpoint/restart.c
> +++ b/checkpoint/restart.c
> @@ -238,6 +238,35 @@ static int _ckpt_read_objref(struct ckpt_ctx *ctx, struct ckpt_hdr *hh)
>  	return ret;
>  }
> 
> +/**
> + * ckpt_read_obj_dispatch - dispatch ERRORs and OBJREFs; don't return them
> + * @ctx: checkpoint context
> + * @h: desired ckpt_hdr
> + */
> +static int ckpt_read_obj_dispatch(struct ckpt_ctx *ctx, struct ckpt_hdr *h)
> +{
> +	int ret;
> +
> +	while (1) {
> +		ret = ckpt_kread(ctx, h, sizeof(*h));
> +		if (ret < 0)
> +			return ret;
> +		_ckpt_debug(CKPT_DRW, "type %d len %d\n", h->type, h->len);
> +		if (h->len < sizeof(*h))
> +			return -EINVAL;
> +
> +		if (h->type == CKPT_HDR_ERROR) {
> +			ret = _ckpt_read_err(ctx, h);
> +			if (ret < 0)
> +				return ret;
> +		} else if (h->type == CKPT_HDR_OBJREF) {
> +			ret = _ckpt_read_objref(ctx, h);
> +			if (ret < 0)
> +				return ret;
> +		} else
> +			return 0;
> +	}
> +}
> 
>  /**
>   * _ckpt_read_obj - read an object (ckpt_hdr followed by payload)
> @@ -254,26 +283,11 @@ static int _ckpt_read_obj(struct ckpt_ctx *ctx, struct ckpt_hdr *h,
>  {
>  	int ret;
> 
> - again:
> -	ret = ckpt_kread(ctx, h, sizeof(*h));
> +	ret = ckpt_read_obj_dispatch(ctx, h);
>  	if (ret < 0)
>  		return ret;
>  	_ckpt_debug(CKPT_DRW, "type %d len %d(%d,%d)\n",
>  		    h->type, h->len, len, max);
> -	if (h->len < sizeof(*h))
> -		return -EINVAL;
> -
> -	if (h->type == CKPT_HDR_ERROR) {
> -		ret = _ckpt_read_err(ctx, h);
> -		if (ret < 0)
> -			return ret;
> -		goto again;
> -	} else if (h->type == CKPT_HDR_OBJREF) {
> -		ret = _ckpt_read_objref(ctx, h);
> -		if (ret < 0)
> -			return ret;
> -		goto again;
> -	}
> 
>  	/* if len specified, enforce, else if maximum specified, enforce */
>  	if ((len && h->len != len) || (!len && max && h->len > max))
> @@ -362,21 +376,11 @@ static void *ckpt_read_obj(struct ckpt_ctx *ctx, int len, int max)
>  	struct ckpt_hdr *h;
>  	int ret;
> 
> - again:
> -	ret = ckpt_kread(ctx, &hh, sizeof(hh));
> +	ret = ckpt_read_obj_dispatch(ctx, &hh);
>  	if (ret < 0)
>  		return ERR_PTR(ret);
>  	_ckpt_debug(CKPT_DRW, "type %d len %d(%d,%d)\n",
>  		    hh.type, hh.len, len, max);
> -	if (hh.len < sizeof(*h))
> -		return ERR_PTR(-EINVAL);
> -
> -	if (hh.type == CKPT_HDR_OBJREF) {
> -		ret = _ckpt_read_objref(ctx, &hh);
> -		if (ret < 0)
> -			return ERR_PTR(ret);
> -		goto again;
> -	}
> 
>  	/* if len specified, enforce, else if maximum specified, enforce */
>  	if ((len && hh.len != len) || (!len && max && hh.len > max))
> -- 
> 1.6.0.4
> 
> _______________________________________________
> Containers mailing list
> Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
> https://lists.linux-foundation.org/mailman/listinfo/containers

  parent reply	other threads:[~2009-10-29 19:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-28  6:13 [PATCH] [RFC] Factor out shared portion of [_]ckpt_read_obj Matt Helsley
     [not found] ` <1256710435-3266-1-git-send-email-matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-28 20:35   ` Serge E. Hallyn
     [not found]     ` <20091028203504.GA26291-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-29  1:03       ` Oren Laadan
2009-10-29 17:50   ` [PATCH] c/r: factor out objref handling from {_,}ckpt_read_obj() Oren Laadan
     [not found]     ` <1256838612-17372-1-git-send-email-orenl-RdfvBDnrOixBDgjK7y7TUQ@public.gmane.org>
2009-10-29 19:52       ` Serge E. Hallyn [this message]
     [not found]         ` <20091029195213.GA29874-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2009-10-29 21:21           ` Matt Helsley
2009-10-29 21:30       ` Matt Helsley

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=20091029195213.GA29874@us.ibm.com \
    --to=serue-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=orenl-RdfvBDnrOixBDgjK7y7TUQ@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