* [PATCH] btrfs: use need_full_stripe() in __btrfs_map_block()
@ 2017-10-12 8:43 Anand Jain
2017-10-12 8:51 ` Qu Wenruo
2017-10-12 9:03 ` Nikolay Borisov
0 siblings, 2 replies; 5+ messages in thread
From: Anand Jain @ 2017-10-12 8:43 UTC (permalink / raw)
To: linux-btrfs
A cleanup patch, use need_full_stripe() to replace the open code.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
fs/btrfs/volumes.c | 16 ++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 3b3ba1ecd88b..f5dee43f8f3f 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5673,10 +5673,10 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
stripe_nr = div_u64_rem(stripe_nr, map->num_stripes,
&stripe_index);
- if (op != BTRFS_MAP_WRITE && op != BTRFS_MAP_GET_READ_MIRRORS)
+ if (!need_full_stripe(op))
mirror_num = 1;
} else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
- if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS)
+ if (need_full_stripe(op))
num_stripes = map->num_stripes;
else if (mirror_num)
stripe_index = mirror_num - 1;
@@ -5689,7 +5689,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
}
} else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
- if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) {
+ if (need_full_stripe(op)) {
num_stripes = map->num_stripes;
} else if (mirror_num) {
stripe_index = mirror_num - 1;
@@ -5703,7 +5703,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index);
stripe_index *= map->sub_stripes;
- if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS)
+ if (need_full_stripe(op))
num_stripes = map->sub_stripes;
else if (mirror_num)
stripe_index += mirror_num - 1;
@@ -5718,9 +5718,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
}
} else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
- if (need_raid_map &&
- (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS ||
- mirror_num > 1)) {
+ if (need_raid_map && (need_full_stripe(op) || mirror_num > 1)) {
/* push stripe_nr back to the start of the full stripe */
stripe_nr = div64_u64(raid56_full_stripe_start,
stripe_len * nr_data_stripes(map));
@@ -5747,9 +5745,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
/* We distribute the parity blocks across stripes */
div_u64_rem(stripe_nr + stripe_index, map->num_stripes,
&stripe_index);
- if ((op != BTRFS_MAP_WRITE &&
- op != BTRFS_MAP_GET_READ_MIRRORS) &&
- mirror_num <= 1)
+ if (!need_full_stripe(op) && mirror_num <= 1)
mirror_num = 1;
}
} else {
--
2.13.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs: use need_full_stripe() in __btrfs_map_block()
2017-10-12 8:43 [PATCH] btrfs: use need_full_stripe() in __btrfs_map_block() Anand Jain
@ 2017-10-12 8:51 ` Qu Wenruo
2017-10-12 9:03 ` Nikolay Borisov
1 sibling, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2017-10-12 8:51 UTC (permalink / raw)
To: Anand Jain, linux-btrfs
On 2017年10月12日 16:43, Anand Jain wrote:
> A cleanup patch, use need_full_stripe() to replace the open code.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Qu Wenruo <quwenruo.btrfs@gmx.com>
Thanks,
Qu
> ---
> fs/btrfs/volumes.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 3b3ba1ecd88b..f5dee43f8f3f 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -5673,10 +5673,10 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
> if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
> stripe_nr = div_u64_rem(stripe_nr, map->num_stripes,
> &stripe_index);
> - if (op != BTRFS_MAP_WRITE && op != BTRFS_MAP_GET_READ_MIRRORS)
> + if (!need_full_stripe(op))
> mirror_num = 1;
> } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
> - if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS)
> + if (need_full_stripe(op))
> num_stripes = map->num_stripes;
> else if (mirror_num)
> stripe_index = mirror_num - 1;
> @@ -5689,7 +5689,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
> }
>
> } else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
> - if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) {
> + if (need_full_stripe(op)) {
> num_stripes = map->num_stripes;
> } else if (mirror_num) {
> stripe_index = mirror_num - 1;
> @@ -5703,7 +5703,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
> stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index);
> stripe_index *= map->sub_stripes;
>
> - if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS)
> + if (need_full_stripe(op))
> num_stripes = map->sub_stripes;
> else if (mirror_num)
> stripe_index += mirror_num - 1;
> @@ -5718,9 +5718,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
> }
>
> } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
> - if (need_raid_map &&
> - (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS ||
> - mirror_num > 1)) {
> + if (need_raid_map && (need_full_stripe(op) || mirror_num > 1)) {
> /* push stripe_nr back to the start of the full stripe */
> stripe_nr = div64_u64(raid56_full_stripe_start,
> stripe_len * nr_data_stripes(map));
> @@ -5747,9 +5745,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
> /* We distribute the parity blocks across stripes */
> div_u64_rem(stripe_nr + stripe_index, map->num_stripes,
> &stripe_index);
> - if ((op != BTRFS_MAP_WRITE &&
> - op != BTRFS_MAP_GET_READ_MIRRORS) &&
> - mirror_num <= 1)
> + if (!need_full_stripe(op) && mirror_num <= 1)
> mirror_num = 1;
> }
> } else {
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs: use need_full_stripe() in __btrfs_map_block()
2017-10-12 8:43 [PATCH] btrfs: use need_full_stripe() in __btrfs_map_block() Anand Jain
2017-10-12 8:51 ` Qu Wenruo
@ 2017-10-12 9:03 ` Nikolay Borisov
2017-10-16 14:17 ` David Sterba
1 sibling, 1 reply; 5+ messages in thread
From: Nikolay Borisov @ 2017-10-12 9:03 UTC (permalink / raw)
To: Anand Jain, linux-btrfs
On 12.10.2017 11:43, Anand Jain wrote:
> A cleanup patch, use need_full_stripe() to replace the open code.
The code is equivalent by merit of De Morgan's law (I had to actually go
look up the equivalence classes before I convinced myself it was correct)
~A ^ ~B == ~(A or B)
Reviewed-by: Nikolay Borisov <nborisov@suse.com>
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
> ---
> fs/btrfs/volumes.c | 16 ++++++----------
> 1 file changed, 6 insertions(+), 10 deletions(-)
>
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 3b3ba1ecd88b..f5dee43f8f3f 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -5673,10 +5673,10 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
> if (map->type & BTRFS_BLOCK_GROUP_RAID0) {
> stripe_nr = div_u64_rem(stripe_nr, map->num_stripes,
> &stripe_index);
> - if (op != BTRFS_MAP_WRITE && op != BTRFS_MAP_GET_READ_MIRRORS)
> + if (!need_full_stripe(op))
> mirror_num = 1;
> } else if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
> - if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS)
> + if (need_full_stripe(op))
> num_stripes = map->num_stripes;
> else if (mirror_num)
> stripe_index = mirror_num - 1;
> @@ -5689,7 +5689,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
> }
>
> } else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
> - if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS) {
> + if (need_full_stripe(op)) {
> num_stripes = map->num_stripes;
> } else if (mirror_num) {
> stripe_index = mirror_num - 1;
> @@ -5703,7 +5703,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
> stripe_nr = div_u64_rem(stripe_nr, factor, &stripe_index);
> stripe_index *= map->sub_stripes;
>
> - if (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS)
> + if (need_full_stripe(op))
> num_stripes = map->sub_stripes;
> else if (mirror_num)
> stripe_index += mirror_num - 1;
> @@ -5718,9 +5718,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
> }
>
> } else if (map->type & BTRFS_BLOCK_GROUP_RAID56_MASK) {
> - if (need_raid_map &&
> - (op == BTRFS_MAP_WRITE || op == BTRFS_MAP_GET_READ_MIRRORS ||
> - mirror_num > 1)) {
> + if (need_raid_map && (need_full_stripe(op) || mirror_num > 1)) {
> /* push stripe_nr back to the start of the full stripe */
> stripe_nr = div64_u64(raid56_full_stripe_start,
> stripe_len * nr_data_stripes(map));
> @@ -5747,9 +5745,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info,
> /* We distribute the parity blocks across stripes */
> div_u64_rem(stripe_nr + stripe_index, map->num_stripes,
> &stripe_index);
> - if ((op != BTRFS_MAP_WRITE &&
> - op != BTRFS_MAP_GET_READ_MIRRORS) &&
> - mirror_num <= 1)
> + if (!need_full_stripe(op) && mirror_num <= 1)
> mirror_num = 1;
> }
> } else {
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs: use need_full_stripe() in __btrfs_map_block()
2017-10-12 9:03 ` Nikolay Borisov
@ 2017-10-16 14:17 ` David Sterba
2017-10-16 14:26 ` Nikolay Borisov
0 siblings, 1 reply; 5+ messages in thread
From: David Sterba @ 2017-10-16 14:17 UTC (permalink / raw)
To: Nikolay Borisov; +Cc: Anand Jain, linux-btrfs
On Thu, Oct 12, 2017 at 12:03:31PM +0300, Nikolay Borisov wrote:
>
>
> On 12.10.2017 11:43, Anand Jain wrote:
> > A cleanup patch, use need_full_stripe() to replace the open code.
>
> The code is equivalent by merit of De Morgan's law (I had to actually go
> look up the equivalence classes before I convinced myself it was correct)
>
> ~A ^ ~B == ~(A or B)
You confused me first by the bitwise operators here, while the patch is
actually for the logical ones (and correct).
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] btrfs: use need_full_stripe() in __btrfs_map_block()
2017-10-16 14:17 ` David Sterba
@ 2017-10-16 14:26 ` Nikolay Borisov
0 siblings, 0 replies; 5+ messages in thread
From: Nikolay Borisov @ 2017-10-16 14:26 UTC (permalink / raw)
To: dsterba, Anand Jain, linux-btrfs
On 16.10.2017 17:17, David Sterba wrote:
> You confused me first by the bitwise operators here, while the patch is
> actually for the logical ones (and correct).
actualy I used ~ as the "not" and ^ as "and" rather than XOR.
Not A AND Not B == NOT(A or B) that's what I wanted to express ...
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-10-16 14:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-12 8:43 [PATCH] btrfs: use need_full_stripe() in __btrfs_map_block() Anand Jain
2017-10-12 8:51 ` Qu Wenruo
2017-10-12 9:03 ` Nikolay Borisov
2017-10-16 14:17 ` David Sterba
2017-10-16 14:26 ` Nikolay Borisov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).