diff mbox

[12/13] dm-mpath: Introduce assign_bit()

Message ID 20170426183728.10821-13-bart.vanassche@sandisk.com (mailing list archive)
State Superseded, archived
Delegated to: Mike Snitzer
Headers show

Commit Message

Bart Van Assche April 26, 2017, 6:37 p.m. UTC
This patch does not change any functionality but makes the code
easier to read.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Hannes Reinecke <hare@suse.com>
---
 drivers/md/dm-mpath.c | 37 ++++++++++++++++---------------------
 1 file changed, 16 insertions(+), 21 deletions(-)

Comments

Hannes Reinecke April 27, 2017, 6:40 a.m. UTC | #1
On 04/26/2017 08:37 PM, Bart Van Assche wrote:
> This patch does not change any functionality but makes the code
> easier to read.
> 
> Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
> Cc: Hannes Reinecke <hare@suse.com>
> ---
>  drivers/md/dm-mpath.c | 37 ++++++++++++++++---------------------
>  1 file changed, 16 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
> index 0eafe7a2070b..57b467207741 100644
> --- a/drivers/md/dm-mpath.c
> +++ b/drivers/md/dm-mpath.c
> @@ -613,6 +613,14 @@ static void process_queued_bios(struct work_struct *work)
>  	blk_finish_plug(&plug);
>  }
>  
> +static void assign_bit(bool value, long nr, unsigned long *addr)
> +{
> +	if (value)
> +		set_bit(nr, addr);
> +	else
> +		clear_bit(nr, addr);
> +}
> +
>  /*
>   * If we run out of usable paths, should we queue I/O or error it?
>   */
> @@ -622,23 +630,12 @@ static int queue_if_no_path(struct multipath *m, bool queue_if_no_path,
>  	unsigned long flags;
>  
>  	spin_lock_irqsave(&m->lock, flags);
> -
> -	if (save_old_value) {
> -		if (test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags))
> -			set_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags);
> -		else
> -			clear_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags);
> -	} else {
> -		if (queue_if_no_path)
> -			set_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags);
> -		else
> -			clear_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags);
> -	}
> -	if (queue_if_no_path || dm_noflush_suspending(m->ti))
> -		set_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags);
> -	else
> -		clear_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags);
> -
> +	assign_bit((save_old_value &&
> +		    test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags)) ||
> +		   (!save_old_value && queue_if_no_path),
> +		   MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags);
> +	assign_bit(queue_if_no_path || dm_noflush_suspending(m->ti),
> +		   MPATHF_QUEUE_IF_NO_PATH, &m->flags);
>  	spin_unlock_irqrestore(&m->lock, flags);
>  
>  	if (!queue_if_no_path) {
> @@ -1593,10 +1590,8 @@ static void multipath_resume(struct dm_target *ti)
>  	unsigned long flags;
>  
>  	spin_lock_irqsave(&m->lock, flags);
> -	if (test_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags))
> -		set_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags);
> -	else
> -		clear_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags);
> +	assign_bit(test_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags),
> +		   MPATHF_QUEUE_IF_NO_PATH, &m->flags);
>  	spin_unlock_irqrestore(&m->lock, flags);
>  }
>  
> 
Not that it makes the code easier to read, but it's certainly shorter.
Personally, I would love to do away with the 'SAVED_QUEUE_IF_NO_PATH'
thingie. But anyway.

Reviewed-by: Hannes Reinecke <hare@suse.com>

Cheers,

Hannes
diff mbox

Patch

diff --git a/drivers/md/dm-mpath.c b/drivers/md/dm-mpath.c
index 0eafe7a2070b..57b467207741 100644
--- a/drivers/md/dm-mpath.c
+++ b/drivers/md/dm-mpath.c
@@ -613,6 +613,14 @@  static void process_queued_bios(struct work_struct *work)
 	blk_finish_plug(&plug);
 }
 
+static void assign_bit(bool value, long nr, unsigned long *addr)
+{
+	if (value)
+		set_bit(nr, addr);
+	else
+		clear_bit(nr, addr);
+}
+
 /*
  * If we run out of usable paths, should we queue I/O or error it?
  */
@@ -622,23 +630,12 @@  static int queue_if_no_path(struct multipath *m, bool queue_if_no_path,
 	unsigned long flags;
 
 	spin_lock_irqsave(&m->lock, flags);
-
-	if (save_old_value) {
-		if (test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags))
-			set_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags);
-		else
-			clear_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags);
-	} else {
-		if (queue_if_no_path)
-			set_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags);
-		else
-			clear_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags);
-	}
-	if (queue_if_no_path || dm_noflush_suspending(m->ti))
-		set_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags);
-	else
-		clear_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags);
-
+	assign_bit((save_old_value &&
+		    test_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags)) ||
+		   (!save_old_value && queue_if_no_path),
+		   MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags);
+	assign_bit(queue_if_no_path || dm_noflush_suspending(m->ti),
+		   MPATHF_QUEUE_IF_NO_PATH, &m->flags);
 	spin_unlock_irqrestore(&m->lock, flags);
 
 	if (!queue_if_no_path) {
@@ -1593,10 +1590,8 @@  static void multipath_resume(struct dm_target *ti)
 	unsigned long flags;
 
 	spin_lock_irqsave(&m->lock, flags);
-	if (test_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags))
-		set_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags);
-	else
-		clear_bit(MPATHF_QUEUE_IF_NO_PATH, &m->flags);
+	assign_bit(test_bit(MPATHF_SAVED_QUEUE_IF_NO_PATH, &m->flags),
+		   MPATHF_QUEUE_IF_NO_PATH, &m->flags);
 	spin_unlock_irqrestore(&m->lock, flags);
 }