diff mbox

[14/24] dm cache: use is_write_io() in more places

Message ID 1382639437-27007-15-git-send-email-snitzer@redhat.com (mailing list archive)
State Superseded, archived
Delegated to: Mike Snitzer
Headers show

Commit Message

Mike Snitzer Oct. 24, 2013, 6:30 p.m. UTC
From: Heinz Mauelshagen <heinzm@redhat.com>

Use is_write_io() consistently where it is makes sense.

Signed-off-by: Heinz Mauelshagen <heinzm@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>
---
 drivers/md/dm-cache-target.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

Comments

Alasdair G Kergon Oct. 25, 2013, 7:53 p.m. UTC | #1
On Thu, Oct 24, 2013 at 02:30:27PM -0400, Mike Snitzer wrote:
> From: Heinz Mauelshagen <heinzm@redhat.com>
 
> Use is_write_io() consistently where it is makes sense.
 
> +++ b/drivers/md/dm-cache-target.c

> +static bool is_write_io(struct bio *bio)
> +{
> +	return bio_data_dir(bio) == WRITE;
> +}

I'm not really convinced about this one, though I can see some superficial
attractiveness.  I think introducing it in a single file (rather than
kernel-wide) is obfuscating the code rather than making it more readable.

If a change like this were to happen, wouldn't fs.h be a better place?

Alasdair

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
Mike Snitzer Oct. 25, 2013, 8:11 p.m. UTC | #2
On Fri, Oct 25 2013 at  3:53pm -0400,
Alasdair G Kergon <agk@redhat.com> wrote:

> On Thu, Oct 24, 2013 at 02:30:27PM -0400, Mike Snitzer wrote:
> > From: Heinz Mauelshagen <heinzm@redhat.com>
>  
> > Use is_write_io() consistently where it is makes sense.
>  
> > +++ b/drivers/md/dm-cache-target.c
> 
> > +static bool is_write_io(struct bio *bio)
> > +{
> > +	return bio_data_dir(bio) == WRITE;
> > +}
> 
> I'm not really convinced about this one, though I can see some superficial
> attractiveness.  I think introducing it in a single file (rather than
> kernel-wide) is obfuscating the code rather than making it more readable.
> 
> If a change like this were to happen, wouldn't fs.h be a better place?

is_write_io() was already in dm-cache-target.c, this patch just makes
use of it in more applicable places.

But I'm fine with completely eliminating is_write_io()... whatever
others would prefer.

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
diff mbox

Patch

diff --git a/drivers/md/dm-cache-target.c b/drivers/md/dm-cache-target.c
index 3bf8cc7..5fb4d64 100644
--- a/drivers/md/dm-cache-target.c
+++ b/drivers/md/dm-cache-target.c
@@ -631,12 +631,17 @@  static void check_if_tick_bio_needed(struct cache *cache, struct bio *bio)
 	spin_unlock_irqrestore(&cache->lock, flags);
 }
 
+static bool is_write_io(struct bio *bio)
+{
+	return bio_data_dir(bio) == WRITE;
+}
+
 static void remap_to_origin_clear_discard(struct cache *cache, struct bio *bio,
 				  dm_oblock_t oblock)
 {
 	check_if_tick_bio_needed(cache, bio);
 	remap_to_origin(cache, bio);
-	if (bio_data_dir(bio) == WRITE)
+	if (is_write_io(bio))
 		clear_discard(cache, oblock_to_dblock(cache, oblock));
 }
 
@@ -644,7 +649,7 @@  static void remap_to_cache_dirty(struct cache *cache, struct bio *bio,
 				 dm_oblock_t oblock, dm_cblock_t cblock)
 {
 	remap_to_cache(cache, bio, cblock);
-	if (bio_data_dir(bio) == WRITE) {
+	if (is_write_io(bio)) {
 		set_dirty(cache, oblock, cblock);
 		clear_discard(cache, oblock_to_dblock(cache, oblock));
 	}
@@ -1172,21 +1177,16 @@  static bool spare_migration_bandwidth(struct cache *cache)
 	return current_volume < cache->migration_threshold;
 }
 
-static bool is_write_io(struct bio *bio)
-{
-	return bio_data_dir(bio) == WRITE;
-}
-
 static void inc_hit_counter(struct cache *cache, struct bio *bio)
 {
-	atomic_inc(bio_data_dir(bio) == READ ?
-		   &cache->stats.read_hit : &cache->stats.write_hit);
+	atomic_inc(is_write_io(bio) ?
+		   &cache->stats.write_hit : &cache->stats.read_hit);
 }
 
 static void inc_miss_counter(struct cache *cache, struct bio *bio)
 {
-	atomic_inc(bio_data_dir(bio) == READ ?
-		   &cache->stats.read_miss : &cache->stats.write_miss);
+	atomic_inc(is_write_io(bio) ?
+		   &cache->stats.write_miss : &cache->stats.read_miss);
 }
 
 static void issue_cache_bio(struct cache *cache, struct bio *bio,