2019-11-04 11:56:46

by Chengguang Xu

[permalink] [raw]
Subject: [PATCH 4/5] ext2: code cleanup for ext2_try_to_allocate()

Code cleanup by removing duplicated code.

Signed-off-by: Chengguang Xu <[email protected]>
---
fs/ext2/balloc.c | 32 ++++++++++++++------------------
1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
index a0c22e166682..9a9bd566243d 100644
--- a/fs/ext2/balloc.c
+++ b/fs/ext2/balloc.c
@@ -710,29 +710,25 @@ ext2_try_to_allocate(struct super_block *sb, int group,
;
}
}
- start = grp_goal;

-repeat:
- if (ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group), grp_goal,
- bitmap_bh->b_data)) {
- /*
- * The block was allocated by another thread, or it was
- * allocated and then freed by another thread
- */
- start++;
- grp_goal++;
- if (start >= end)
- goto fail_access;
- goto repeat;
- }
- num++;
- grp_goal++;
- while (num < *count && grp_goal < end
- && !ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group),
+ while (num < *count && grp_goal < end) {
+ if (ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group),
grp_goal, bitmap_bh->b_data)) {
+ if (num == 0) {
+ grp_goal++;
+ continue;
+ } else {
+ break;
+ }
+ }
+
num++;
grp_goal++;
}
+
+ if (!num)
+ goto fail_access;
+
*count = num;
return grp_goal - num;
fail_access:
--
2.20.1




2019-11-06 15:59:38

by Jan Kara

[permalink] [raw]
Subject: Re: [PATCH 4/5] ext2: code cleanup for ext2_try_to_allocate()

On Mon 04-11-19 19:40:35, Chengguang Xu wrote:
> Code cleanup by removing duplicated code.
>
> Signed-off-by: Chengguang Xu <[email protected]>

Thanks for the patch! I've merged it with a small update to switch the
while() loop into a for() loop which is somewhat more natural in that
situation. Resulting patch attached.

Honza

> ---
> fs/ext2/balloc.c | 32 ++++++++++++++------------------
> 1 file changed, 14 insertions(+), 18 deletions(-)
>
> diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
> index a0c22e166682..9a9bd566243d 100644
> --- a/fs/ext2/balloc.c
> +++ b/fs/ext2/balloc.c
> @@ -710,29 +710,25 @@ ext2_try_to_allocate(struct super_block *sb, int group,
> ;
> }
> }
> - start = grp_goal;
>
> -repeat:
> - if (ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group), grp_goal,
> - bitmap_bh->b_data)) {
> - /*
> - * The block was allocated by another thread, or it was
> - * allocated and then freed by another thread
> - */
> - start++;
> - grp_goal++;
> - if (start >= end)
> - goto fail_access;
> - goto repeat;
> - }
> - num++;
> - grp_goal++;
> - while (num < *count && grp_goal < end
> - && !ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group),
> + while (num < *count && grp_goal < end) {
> + if (ext2_set_bit_atomic(sb_bgl_lock(EXT2_SB(sb), group),
> grp_goal, bitmap_bh->b_data)) {
> + if (num == 0) {
> + grp_goal++;
> + continue;
> + } else {
> + break;
> + }
> + }
> +
> num++;
> grp_goal++;
> }
> +
> + if (!num)
> + goto fail_access;
> +
> *count = num;
> return grp_goal - num;
> fail_access:
> --
> 2.20.1
>
>
>
--
Jan Kara <[email protected]>
SUSE Labs, CR


Attachments:
(No filename) (1.71 kB)
0001-ext2-code-cleanup-for-ext2_try_to_allocate.patch (1.59 kB)
Download all attachments

2019-11-07 02:58:46

by Chengguang Xu

[permalink] [raw]
Subject: Re: [PATCH 4/5] ext2: code cleanup for ext2_try_to_allocate()

---- 在 星期三, 2019-11-06 23:59:00 Jan Kara <[email protected]> 撰写 ----
> On Mon 04-11-19 19:40:35, Chengguang Xu wrote:
> > Code cleanup by removing duplicated code.
> >
> > Signed-off-by: Chengguang Xu <[email protected]>
>
> Thanks for the patch! I've merged it with a small update to switch the
> while() loop into a for() loop which is somewhat more natural in that
> situation. Resulting patch attached.
>

Looks fine to me.


Thanks,
Chengguang