Skip to content

Commit 3fed40c

Browse files
Miao XieJosef Bacik
authored andcommitted
Btrfs: cleanup duplicated division functions
div_factor{_fine} has been implemented for two times, cleanup it. And I move them into a independent file named math.h because they are common math functions. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
1 parent 2959440 commit 3fed40c

3 files changed

Lines changed: 46 additions & 40 deletions

File tree

‎fs/btrfs/extent-tree.c‎

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "volumes.h"
3434
#include "locking.h"
3535
#include "free-space-cache.h"
36+
#include "math.h"
3637

3738
#undef SCRAMBLE_DELAYED_REFS
3839

@@ -649,24 +650,6 @@ void btrfs_clear_space_info_full(struct btrfs_fs_info *info)
649650
rcu_read_unlock();
650651
}
651652

652-
static u64 div_factor(u64 num, int factor)
653-
{
654-
if (factor == 10)
655-
return num;
656-
num *= factor;
657-
do_div(num, 10);
658-
return num;
659-
}
660-
661-
static u64 div_factor_fine(u64 num, int factor)
662-
{
663-
if (factor == 100)
664-
return num;
665-
num *= factor;
666-
do_div(num, 100);
667-
return num;
668-
}
669-
670653
u64 btrfs_find_block_group(struct btrfs_root *root,
671654
u64 search_start, u64 search_hint, int owner)
672655
{

‎fs/btrfs/math.h‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
/*
3+
* Copyright (C) 2012 Fujitsu. All rights reserved.
4+
* Written by Miao Xie <miaox@cn.fujitsu.com>
5+
*
6+
* This program is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU General Public
8+
* License v2 as published by the Free Software Foundation.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public
16+
* License along with this program; if not, write to the
17+
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18+
* Boston, MA 021110-1307, USA.
19+
*/
20+
21+
#ifndef __BTRFS_MATH_H
22+
#define __BTRFS_MATH_H
23+
24+
#include <asm/div64.h>
25+
26+
static inline u64 div_factor(u64 num, int factor)
27+
{
28+
if (factor == 10)
29+
return num;
30+
num *= factor;
31+
do_div(num, 10);
32+
return num;
33+
}
34+
35+
static inline u64 div_factor_fine(u64 num, int factor)
36+
{
37+
if (factor == 100)
38+
return num;
39+
num *= factor;
40+
do_div(num, 100);
41+
return num;
42+
}
43+
44+
#endif

‎fs/btrfs/volumes.c‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <linux/capability.h>
2626
#include <linux/ratelimit.h>
2727
#include <linux/kthread.h>
28-
#include <asm/div64.h>
2928
#include "compat.h"
3029
#include "ctree.h"
3130
#include "extent_map.h"
@@ -36,6 +35,7 @@
3635
#include "async-thread.h"
3736
#include "check-integrity.h"
3837
#include "rcu-string.h"
38+
#include "math.h"
3939

4040
static int init_first_rw_device(struct btrfs_trans_handle *trans,
4141
struct btrfs_root *root,
@@ -2338,18 +2338,6 @@ static int chunk_profiles_filter(u64 chunk_type,
23382338
return 1;
23392339
}
23402340

2341-
static u64 div_factor_fine(u64 num, int factor)
2342-
{
2343-
if (factor <= 0)
2344-
return 0;
2345-
if (factor >= 100)
2346-
return num;
2347-
2348-
num *= factor;
2349-
do_div(num, 100);
2350-
return num;
2351-
}
2352-
23532341
static int chunk_usage_filter(struct btrfs_fs_info *fs_info, u64 chunk_offset,
23542342
struct btrfs_balance_args *bargs)
23552343
{
@@ -2514,15 +2502,6 @@ static int should_balance_chunk(struct btrfs_root *root,
25142502
return 1;
25152503
}
25162504

2517-
static u64 div_factor(u64 num, int factor)
2518-
{
2519-
if (factor == 10)
2520-
return num;
2521-
num *= factor;
2522-
do_div(num, 10);
2523-
return num;
2524-
}
2525-
25262505
static int __btrfs_balance(struct btrfs_fs_info *fs_info)
25272506
{
25282507
struct btrfs_balance_control *bctl = fs_info->balance_ctl;

0 commit comments

Comments
 (0)