CEPH filesystem development
 help / color / mirror / Atom feed
From: Alex Elder <elder@ieee.org>
To: Ilya Dryomov <ilya.dryomov@inktank.com>, ceph-devel@vger.kernel.org
Subject: Re: [PATCH 06/33] libceph: fixup error handling in osdmap_decode()
Date: Thu, 27 Mar 2014 14:25:28 -0500	[thread overview]
Message-ID: <53347B28.7060607@ieee.org> (raw)
In-Reply-To: <1395944299-21970-7-git-send-email-ilya.dryomov@inktank.com>

On 03/27/2014 01:17 PM, Ilya Dryomov wrote:
> The existing error handling scheme requires resetting err to -EINVAL
> prior to calling any ceph_decode_* macro.  This is ugly and fragile,
> and there already are a few places where we would return 0 on error,
> due to a missing reset.  Fix this by adding a special e_inval label to
> be used by all ceph_decode_* macros.

I don't see where it's returning 0 on error, but I think this
is a good change anyway.

I'd use "einval" or "err_inval" instead of "e_inval".  But
no matter.

Looks good.

Reviewed-by: Alex Elder <elder@linaro.org>


> Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
> ---
>  net/ceph/osdmap.c |   53 +++++++++++++++++++++++++++--------------------------
>  1 file changed, 27 insertions(+), 26 deletions(-)
> 
> diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
> index a82df6ea0749..298d076eee89 100644
> --- a/net/ceph/osdmap.c
> +++ b/net/ceph/osdmap.c
> @@ -688,36 +688,37 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
>  {
>  	u16 version;
>  	u32 len, max, i;
> -	int err = -EINVAL;
>  	u32 epoch = 0;
>  	void *start = *p;
> +	int err;
>  	struct ceph_pg_pool_info *pi;
>  
>  	dout("%s %p to %p len %d\n", __func__, *p, end, (int)(end - *p));
>  
> -	ceph_decode_16_safe(p, end, version, bad);
> +	ceph_decode_16_safe(p, end, version, e_inval);
>  	if (version > 6) {
>  		pr_warning("got unknown v %d > 6 of osdmap\n", version);
> -		goto bad;
> +		goto e_inval;
>  	}
>  	if (version < 6) {
>  		pr_warning("got old v %d < 6 of osdmap\n", version);
> -		goto bad;
> +		goto e_inval;
>  	}
>  
> -	ceph_decode_need(p, end, 2*sizeof(u64)+6*sizeof(u32), bad);
> +	ceph_decode_need(p, end, 2*sizeof(u64)+6*sizeof(u32), e_inval);
>  	ceph_decode_copy(p, &map->fsid, sizeof(map->fsid));
>  	epoch = map->epoch = ceph_decode_32(p);
>  	ceph_decode_copy(p, &map->created, sizeof(map->created));
>  	ceph_decode_copy(p, &map->modified, sizeof(map->modified));
>  
> -	ceph_decode_32_safe(p, end, max, bad);
> +	ceph_decode_32_safe(p, end, max, e_inval);
>  	while (max--) {
> -		ceph_decode_need(p, end, 8 + 2, bad);
> -		err = -ENOMEM;
> +		ceph_decode_need(p, end, 8 + 2, e_inval);
>  		pi = kzalloc(sizeof(*pi), GFP_NOFS);
> -		if (!pi)
> +		if (!pi) {
> +			err = -ENOMEM;
>  			goto bad;
> +		}
>  		pi->id = ceph_decode_64(p);
>  		err = __decode_pool(p, end, pi);
>  		if (err < 0) {
> @@ -728,27 +729,25 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
>  	}
>  
>  	err = __decode_pool_names(p, end, map);
> -	if (err < 0) {
> -		dout("fail to decode pool names");
> +	if (err)
>  		goto bad;
> -	}
>  
> -	ceph_decode_32_safe(p, end, map->pool_max, bad);
> +	ceph_decode_32_safe(p, end, map->pool_max, e_inval);
>  
> -	ceph_decode_32_safe(p, end, map->flags, bad);
> +	ceph_decode_32_safe(p, end, map->flags, e_inval);
>  
>  	max = ceph_decode_32(p);
>  
>  	/* (re)alloc osd arrays */
>  	err = osdmap_set_max_osd(map, max);
> -	if (err < 0)
> +	if (err)
>  		goto bad;
>  
>  	/* osds */
> -	err = -EINVAL;
>  	ceph_decode_need(p, end, 3*sizeof(u32) +
>  			 map->max_osd*(1 + sizeof(*map->osd_weight) +
> -				       sizeof(*map->osd_addr)), bad);
> +				       sizeof(*map->osd_addr)), e_inval);
> +
>  	*p += 4; /* skip length field (should match max) */
>  	ceph_decode_copy(p, map->osd_state, map->max_osd);
>  
> @@ -762,7 +761,7 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
>  		ceph_decode_addr(&map->osd_addr[i]);
>  
>  	/* pg_temp */
> -	ceph_decode_32_safe(p, end, len, bad);
> +	ceph_decode_32_safe(p, end, len, e_inval);
>  	for (i = 0; i < len; i++) {
>  		int n, j;
>  		struct ceph_pg pgid;
> @@ -771,16 +770,16 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
>  		err = ceph_decode_pgid(p, end, &pgid);
>  		if (err)
>  			goto bad;
> -		ceph_decode_need(p, end, sizeof(u32), bad);
> +		ceph_decode_need(p, end, sizeof(u32), e_inval);
>  		n = ceph_decode_32(p);
> -		err = -EINVAL;
>  		if (n > (UINT_MAX - sizeof(*pg)) / sizeof(u32))
> -			goto bad;
> -		ceph_decode_need(p, end, n * sizeof(u32), bad);
> -		err = -ENOMEM;
> +			goto e_inval;
> +		ceph_decode_need(p, end, n * sizeof(u32), e_inval);
>  		pg = kmalloc(sizeof(*pg) + n*sizeof(u32), GFP_NOFS);
> -		if (!pg)
> +		if (!pg) {
> +			err = -ENOMEM;
>  			goto bad;
> +		}
>  		pg->pgid = pgid;
>  		pg->len = n;
>  		for (j = 0; j < n; j++)
> @@ -794,10 +793,10 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
>  	}
>  
>  	/* crush */
> -	ceph_decode_32_safe(p, end, len, bad);
> +	ceph_decode_32_safe(p, end, len, e_inval);
>  	dout("osdmap_decode crush len %d from off 0x%x\n", len,
>  	     (int)(*p - start));
> -	ceph_decode_need(p, end, len, bad);
> +	ceph_decode_need(p, end, len, e_inval);
>  	map->crush = crush_decode(*p, end);
>  	*p += len;
>  	if (IS_ERR(map->crush)) {
> @@ -812,6 +811,8 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
>  	dout("full osdmap epoch %d max_osd %d\n", map->epoch, map->max_osd);
>  	return 0;
>  
> +e_inval:
> +	err = -EINVAL;
>  bad:
>  	pr_err("corrupt full osdmap (%d) epoch %d off %d (%p of %p-%p)\n",
>  	       err, epoch, (int)(*p - start), *p, start, end);
> 


  reply	other threads:[~2014-03-27 19:25 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-27 18:17 [PATCH 00/33] OSDMAP_ENC, primary_temp, PRIMARY_AFFINITY Ilya Dryomov
2014-03-27 18:17 ` [PATCH 01/33] libceph: refer to osdmap directly in osdmap_show() Ilya Dryomov
2014-03-27 19:09   ` Alex Elder
2014-03-27 18:17 ` [PATCH 02/33] libceph: do not prefix osd lines with \t in debugfs output Ilya Dryomov
2014-03-27 19:10   ` Alex Elder
2014-03-27 18:17 ` [PATCH 03/33] libceph: dump pg_temp mappings to debugfs Ilya Dryomov
2014-03-27 19:11   ` Alex Elder
2014-03-27 18:17 ` [PATCH 04/33] libceph: dump osdmap and enhance output on decode errors Ilya Dryomov
2014-03-27 19:15   ` Alex Elder
2014-03-27 18:17 ` [PATCH 05/33] libceph: split osdmap allocation and decode steps Ilya Dryomov
2014-03-27 19:18   ` Alex Elder
2014-03-27 18:17 ` [PATCH 06/33] libceph: fixup error handling in osdmap_decode() Ilya Dryomov
2014-03-27 19:25   ` Alex Elder [this message]
2014-03-28 14:56     ` Ilya Dryomov
2014-03-28 16:22       ` Alex Elder
2014-03-27 18:17 ` [PATCH 07/33] libceph: safely decode max_osd value " Ilya Dryomov
2014-03-27 19:27   ` Alex Elder
2014-03-27 18:17 ` [PATCH 08/33] libceph: assert length of osdmap osd arrays Ilya Dryomov
2014-03-27 19:30   ` Alex Elder
2014-03-28 14:57     ` Ilya Dryomov
2014-03-27 18:17 ` [PATCH 09/33] libceph: fix crush_decode() call site in osdmap_decode() Ilya Dryomov
2014-03-27 19:45   ` Alex Elder
2014-03-28 14:57     ` Ilya Dryomov
2014-03-27 18:17 ` [PATCH 10/33] libceph: fixup error handling in osdmap_apply_incremental() Ilya Dryomov
2014-03-27 19:49   ` Alex Elder
2014-03-28 14:58     ` Ilya Dryomov
2014-03-27 18:17 ` [PATCH 11/33] libceph: nuke bogus encoding version check " Ilya Dryomov
2014-03-27 19:50   ` Alex Elder
2014-03-27 18:17 ` [PATCH 12/33] libceph: fix and clarify ceph_decode_need() sizes Ilya Dryomov
2014-03-27 19:53   ` Alex Elder
2014-03-27 18:17 ` [PATCH 13/33] libceph: rename __decode_pool{,_names}() to decode_pool{,_names}() Ilya Dryomov
2014-03-27 19:54   ` Alex Elder
2014-03-27 18:18 ` [PATCH 14/33] libceph: introduce decode{,_new}_pools() and switch to them Ilya Dryomov
2014-03-27 19:56   ` Alex Elder
2014-03-27 18:18 ` [PATCH 15/33] libceph: switch osdmap_set_max_osd() to krealloc() Ilya Dryomov
2014-03-27 19:59   ` Alex Elder
2014-03-27 18:18 ` [PATCH 16/33] libceph: introduce decode{,_new}_pg_temp() and switch to them Ilya Dryomov
2014-03-27 20:05   ` Alex Elder
2014-03-27 18:18 ` [PATCH 17/33] libceph: introduce get_osdmap_client_data_v() Ilya Dryomov
2014-03-27 20:17   ` Alex Elder
2014-03-28 14:59     ` Ilya Dryomov
2014-03-27 18:18 ` [PATCH 18/33] libceph: generalize ceph_pg_mapping Ilya Dryomov
2014-03-27 18:18 ` [PATCH 19/33] libceph: primary_temp infrastructure Ilya Dryomov
2014-03-27 20:21   ` Alex Elder
2014-03-27 18:18 ` [PATCH 20/33] libceph: primary_temp decode bits Ilya Dryomov
2014-03-27 20:23   ` Alex Elder
2014-03-27 18:18 ` [PATCH 21/33] libceph: primary_affinity infrastructure Ilya Dryomov
2014-03-27 20:26   ` Alex Elder
2014-03-28 15:01     ` Ilya Dryomov
2014-03-27 18:18 ` [PATCH 22/33] libceph: primary_affinity decode bits Ilya Dryomov
2014-03-27 20:31   ` Alex Elder
2014-03-28 15:01     ` Ilya Dryomov
2014-03-27 18:18 ` [PATCH 23/33] libceph: enable OSDMAP_ENC feature bit Ilya Dryomov
2014-03-27 20:32   ` Alex Elder
2014-03-28 15:01     ` Ilya Dryomov
2014-03-27 18:18 ` [PATCH 24/33] libceph: ceph_osd_{exists,is_up,is_down}(osd) definitions Ilya Dryomov
2014-03-27 20:33   ` Alex Elder
2014-03-27 18:18 ` [PATCH 25/33] libceph: ceph_can_shift_osds(pool) and pool type defines Ilya Dryomov
2014-03-27 20:34   ` Alex Elder
2014-03-27 18:18 ` [PATCH 26/33] libceph: introduce pg_to_raw_osds() and raw_to_up_osds() helpers Ilya Dryomov
2014-03-27 20:36   ` Alex Elder
2014-03-27 18:18 ` [PATCH 27/33] libceph: introduce apply_temps() helper Ilya Dryomov
2014-03-27 20:41   ` Alex Elder
2014-03-27 18:18 ` [PATCH 28/33] libceph: switch ceph_calc_pg_acting() to new helpers Ilya Dryomov
2014-03-27 20:49   ` Alex Elder
2014-03-28 15:02     ` Ilya Dryomov
2014-03-27 18:18 ` [PATCH 29/33] libceph: return primary from ceph_calc_pg_acting() Ilya Dryomov
2014-03-27 20:50   ` Alex Elder
2014-03-27 18:18 ` [PATCH 30/33] libceph: add support for primary_temp mappings Ilya Dryomov
2014-03-27 20:51   ` Alex Elder
2014-03-27 18:18 ` [PATCH 31/33] libceph: add support for osd primary affinity Ilya Dryomov
2014-03-27 20:59   ` Alex Elder
2014-03-28 15:03     ` Ilya Dryomov
2014-03-27 18:18 ` [PATCH 32/33] libceph: redo ceph_calc_pg_primary() in terms of ceph_calc_pg_acting() Ilya Dryomov
2014-03-27 21:04   ` Alex Elder
2014-03-27 18:18 ` [PATCH 33/33] libceph: enable PRIMARY_AFFINITY feature bit Ilya Dryomov
2014-03-27 21:04   ` Alex Elder

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=53347B28.7060607@ieee.org \
    --to=elder@ieee.org \
    --cc=ceph-devel@vger.kernel.org \
    --cc=ilya.dryomov@inktank.com \
    /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