All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: Mike Snitzer <snitzer@redhat.com>
Cc: dm-devel@redhat.com, ejt@redhat.com, agk@redhat.com
Subject: Re: [PATCH] dm transaction manager: handle space map checker failure
Date: Wed, 20 Jun 2012 17:20:10 -0400	[thread overview]
Message-ID: <20120620212010.GK22599@redhat.com> (raw)
In-Reply-To: <1340220299-17771-1-git-send-email-snitzer@redhat.com>

On Wed, Jun 20, 2012 at 03:24:59PM -0400, Mike Snitzer wrote:
> If CONFIG_DM_DEBUG_SPACE_MAPS is enabled and dm_sm_checker_create()
> fails, dm_tm_create_internal() would still return success even though it
> cleaned up all resources it was supposed to have created.
> 
> Fix the space map checker code to return an appropriate ERR_PTR and have
> dm_tm_create_internal() check for it with IS_ERR.
> 

I tested the patch and it works. It fails gracefully instead of segfaulting.

device-mapper: reload ioctl failed: Cannot allocate memory

I still do get waring though about large memory allocation. That's a
separate issue though.

Thanks
Vivek

> Reported-by: Vivek Goyal <vgoyal@redhat.com>
> Signed-off-by: Mike Snitzer <snitzer@redhat.com>
> Cc: stable@vger.kernel.org
> ---
>  drivers/md/persistent-data/dm-space-map-checker.c  |   24 ++++++++++----------
>  .../md/persistent-data/dm-transaction-manager.c    |    8 +++++-
>  2 files changed, 18 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
> index 50ed53b..6d7c832 100644
> --- a/drivers/md/persistent-data/dm-space-map-checker.c
> +++ b/drivers/md/persistent-data/dm-space-map-checker.c
> @@ -343,25 +343,25 @@ struct dm_space_map *dm_sm_checker_create(struct dm_space_map *sm)
>  	int r;
>  	struct sm_checker *smc;
>  
> -	if (!sm)
> -		return NULL;
> +	if (IS_ERR_OR_NULL(sm))
> +		return ERR_PTR(-EINVAL);
>  
>  	smc = kmalloc(sizeof(*smc), GFP_KERNEL);
>  	if (!smc)
> -		return NULL;
> +		return ERR_PTR(-ENOMEM);
>  
>  	memcpy(&smc->sm, &ops_, sizeof(smc->sm));
>  	r = ca_create(&smc->old_counts, sm);
>  	if (r) {
>  		kfree(smc);
> -		return NULL;
> +		return ERR_PTR(r);
>  	}
>  
>  	r = ca_create(&smc->counts, sm);
>  	if (r) {
>  		ca_destroy(&smc->old_counts);
>  		kfree(smc);
> -		return NULL;
> +		return ERR_PTR(r);
>  	}
>  
>  	smc->real_sm = sm;
> @@ -371,7 +371,7 @@ struct dm_space_map *dm_sm_checker_create(struct dm_space_map *sm)
>  		ca_destroy(&smc->counts);
>  		ca_destroy(&smc->old_counts);
>  		kfree(smc);
> -		return NULL;
> +		return ERR_PTR(r);
>  	}
>  
>  	r = ca_commit(&smc->old_counts, &smc->counts);
> @@ -379,7 +379,7 @@ struct dm_space_map *dm_sm_checker_create(struct dm_space_map *sm)
>  		ca_destroy(&smc->counts);
>  		ca_destroy(&smc->old_counts);
>  		kfree(smc);
> -		return NULL;
> +		return ERR_PTR(r);
>  	}
>  
>  	return &smc->sm;
> @@ -391,25 +391,25 @@ struct dm_space_map *dm_sm_checker_create_fresh(struct dm_space_map *sm)
>  	int r;
>  	struct sm_checker *smc;
>  
> -	if (!sm)
> -		return NULL;
> +	if (IS_ERR_OR_NULL(sm))
> +		return ERR_PTR(-EINVAL);
>  
>  	smc = kmalloc(sizeof(*smc), GFP_KERNEL);
>  	if (!smc)
> -		return NULL;
> +		return ERR_PTR(-ENOMEM);
>  
>  	memcpy(&smc->sm, &ops_, sizeof(smc->sm));
>  	r = ca_create(&smc->old_counts, sm);
>  	if (r) {
>  		kfree(smc);
> -		return NULL;
> +		return ERR_PTR(r);
>  	}
>  
>  	r = ca_create(&smc->counts, sm);
>  	if (r) {
>  		ca_destroy(&smc->old_counts);
>  		kfree(smc);
> -		return NULL;
> +		return ERR_PTR(r);
>  	}
>  
>  	smc->real_sm = sm;
> diff --git a/drivers/md/persistent-data/dm-transaction-manager.c b/drivers/md/persistent-data/dm-transaction-manager.c
> index 02bf78e..e5604b3 100644
> --- a/drivers/md/persistent-data/dm-transaction-manager.c
> +++ b/drivers/md/persistent-data/dm-transaction-manager.c
> @@ -347,8 +347,10 @@ static int dm_tm_create_internal(struct dm_block_manager *bm,
>  		}
>  
>  		*sm = dm_sm_checker_create(inner);
> -		if (!*sm)
> +		if (IS_ERR(*sm)) {
> +			r = PTR_ERR(*sm);
>  			goto bad2;
> +		}
>  
>  	} else {
>  		r = dm_bm_write_lock(dm_tm_get_bm(*tm), sb_location,
> @@ -367,8 +369,10 @@ static int dm_tm_create_internal(struct dm_block_manager *bm,
>  		}
>  
>  		*sm = dm_sm_checker_create(inner);
> -		if (!*sm)
> +		if (IS_ERR(*sm)) {
> +			r = PTR_ERR(*sm);
>  			goto bad2;
> +		}
>  	}
>  
>  	return 0;
> -- 
> 1.7.4.4

  reply	other threads:[~2012-06-20 21:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-20 19:24 [PATCH] dm transaction manager: handle space map checker failure Mike Snitzer
2012-06-20 21:20 ` Vivek Goyal [this message]
2012-06-20 21:37   ` Vivek Goyal
2012-06-20 22:15     ` Mike Snitzer
2012-06-21  5:10       ` Mike Snitzer
2012-06-21  6:10         ` Mike Snitzer
2012-06-25 12:16           ` Joe Thornber

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=20120620212010.GK22599@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=agk@redhat.com \
    --cc=dm-devel@redhat.com \
    --cc=ejt@redhat.com \
    --cc=snitzer@redhat.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.