All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Wysochanski <dwysocha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH 3/4] Udev integration: add cookie support for dmsetup
Date: Tue, 21 Apr 2009 14:33:58 -0400	[thread overview]
Message-ID: <1240338838.3705.63.camel@f10-node1> (raw)
In-Reply-To: <49DC978E.4040101@redhat.com>

On Wed, 2009-04-08 at 14:24 +0200, Peter Rajnoha wrote:
>  	if (argc == 3)
>  		file = argv[2];
> @@ -565,9 +566,19 @@ static int _create(int argc, char **argv, void *data __attribute((unused)))
>  				    _read_ahead_flags))
>  		goto out;
>  
> -	if (!dm_task_run(dmt))
> +	if (!dm_notification_sem_open(&cookie) ||
> +			!dm_notification_sem_inc(cookie) ||
> +			!dm_task_set_cookie(dmt, cookie))
>  		goto out;
>  
> +	if (!dm_task_run(dmt)) {
> +		dm_notification_sem_close(cookie);
> +		goto out;
> +	}
> +
> +	dm_notification_sem_wait_zero(cookie);
> +	dm_notification_sem_close(cookie);
> +
>  	r = 1;


This piece of code could exit without cleanup of the semaphore.  Should
the first 'if' only check !dm_notification_sem_open, and the sem_inc and
set_cookie be '||'d with dm_task_run in the second 'if'?


>  
>  	if (_switches[VERBOSE_ARG])
> @@ -583,6 +594,7 @@ static int _rename(int argc, char **argv, void *data __attribute((unused)))
>  {
>  	int r = 0;
>  	struct dm_task *dmt;
> +	uint32_t cookie;
>  
>  	if (!(dmt = dm_task_create(DM_DEVICE_RENAME)))
>  		return 0;
> @@ -597,8 +609,18 @@ static int _rename(int argc, char **argv, void *data __attribute((unused)))
>  	if (_switches[NOOPENCOUNT_ARG] && !dm_task_no_open_count(dmt))
>  		goto out;
>  
> -	if (!dm_task_run(dmt))
> +	if (!dm_notification_sem_open(&cookie) ||
> +			!dm_notification_sem_inc(cookie) ||
> +			!dm_task_set_cookie(dmt, cookie))
> +		goto out;
> +
> +	if (!dm_task_run(dmt)) {
> +		dm_notification_sem_close(cookie);
>  		goto out;
> +	}
> +
> +	dm_notification_sem_wait_zero(cookie);
> +	dm_notification_sem_close(cookie);
>  

Same comment as above.  If open fails, then we don't need close.  But in
all other cases we should be calling sem_close.


>  
>  static int _resume(int argc, char **argv, void *data __attribute((unused)))
>  {
> -	return _simple(DM_DEVICE_RESUME, argc > 1 ? argv[1] : NULL, 0, 1);
> +	uint32_t cookie;
> +
> +	if (!dm_notification_sem_open(&cookie) ||
> +		  !dm_notification_sem_inc(cookie))
> +		return 0;
> +
> +	if (!_simple(DM_DEVICE_RESUME, argc > 1 ? argv[1] : NULL, 0, cookie, 1)) {
> +		dm_notification_sem_close(cookie);
> +		return 0;
> +	}
> +
> +	dm_notification_sem_wait_zero(cookie);
> +	dm_notification_sem_close(cookie);
> +
> +	return 1;
>  }

Same comment - if sem_inc fails we keep the semaphore, but !_simple()
fails we remove it?



>  
> @@ -913,11 +966,24 @@ error:
>  static int _remove(int argc, char **argv, void *data __attribute((unused)))
>  {
>  	int r;
> +	uint32_t cookie;
>  
>  	if (_switches[FORCE_ARG] && argc > 1)
>  		r = _error_device(argc, argv, NULL);
>  
> -	return _simple(DM_DEVICE_REMOVE, argc > 1 ? argv[1] : NULL, 0, 0);
> +	if (!dm_notification_sem_open(&cookie) ||
> +			!dm_notification_sem_inc(cookie))
> +		return 0;
> +
> +	if (!_simple(DM_DEVICE_REMOVE, argc > 1 ? argv[1] : NULL, 0, cookie, 0)) {
> +		dm_notification_sem_close(cookie);
> +		return 0;
> +	}
> +
> +	dm_notification_sem_wait_zero(cookie);
> +	dm_notification_sem_close(cookie);
> +
> +	return 1;
>  }

Same comment as above.





  parent reply	other threads:[~2009-04-21 18:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-08 12:24 [PATCH 3/4] Udev integration: add cookie support for dmsetup Peter Rajnoha
2009-04-15 18:52 ` Alasdair G Kergon
2009-04-20 10:45   ` Peter Rajnoha
2009-04-21 18:33 ` Dave Wysochanski [this message]
2009-04-21 19:07   ` Peter Rajnoha

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=1240338838.3705.63.camel@f10-node1 \
    --to=dwysocha@redhat.com \
    --cc=lvm-devel@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.