aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-12-18 07:06:51 -0500
committerArtem Bityutskiy <Artem.Bityutskiy@nokia.com>2008-12-23 05:23:40 -0500
commit4d61db4f87b527734ac0cc830dda8fcc4e2add2f (patch)
tree881cb7614a928ba004f588a82c064592f461fee3 /fs
parentaf14a1ad792621942a03e4bd0e5f17b6e177e2e0 (diff)
UBIFS: use nicer 64-bit math
Instead of using do_div(), use better primitives from linux/math64.h. Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/ubifs/budget.c25
-rw-r--r--fs/ubifs/debug.c1
-rw-r--r--fs/ubifs/lpt.c15
-rw-r--r--fs/ubifs/sb.c10
-rw-r--r--fs/ubifs/super.c12
-rw-r--r--fs/ubifs/ubifs.h2
6 files changed, 30 insertions, 35 deletions
diff --git a/fs/ubifs/budget.c b/fs/ubifs/budget.c
index e42342547001..0bcb8031ca18 100644
--- a/fs/ubifs/budget.c
+++ b/fs/ubifs/budget.c
@@ -32,7 +32,7 @@
32 32
33#include "ubifs.h" 33#include "ubifs.h"
34#include <linux/writeback.h> 34#include <linux/writeback.h>
35#include <asm/div64.h> 35#include <linux/math64.h>
36 36
37/* 37/*
38 * When pessimistic budget calculations say that there is no enough space, 38 * When pessimistic budget calculations say that there is no enough space,
@@ -258,8 +258,8 @@ static int make_free_space(struct ubifs_info *c, struct retries_info *ri)
258 */ 258 */
259int ubifs_calc_min_idx_lebs(struct ubifs_info *c) 259int ubifs_calc_min_idx_lebs(struct ubifs_info *c)
260{ 260{
261 int ret; 261 int idx_lebs, eff_leb_size = c->leb_size - c->max_idx_node_sz;
262 uint64_t idx_size; 262 long long idx_size;
263 263
264 idx_size = c->old_idx_sz + c->budg_idx_growth + c->budg_uncommitted_idx; 264 idx_size = c->old_idx_sz + c->budg_idx_growth + c->budg_uncommitted_idx;
265 265
@@ -271,18 +271,16 @@ int ubifs_calc_min_idx_lebs(struct ubifs_info *c)
271 * pair, nor similarly the two variables for the new index size, so we 271 * pair, nor similarly the two variables for the new index size, so we
272 * have to do this costly 64-bit division on fast-path. 272 * have to do this costly 64-bit division on fast-path.
273 */ 273 */
274 if (do_div(idx_size, c->leb_size - c->max_idx_node_sz)) 274 idx_size += eff_leb_size - 1;
275 ret = idx_size + 1; 275 idx_lebs = div_u64(idx_size, eff_leb_size);
276 else
277 ret = idx_size;
278 /* 276 /*
279 * The index head is not available for the in-the-gaps method, so add an 277 * The index head is not available for the in-the-gaps method, so add an
280 * extra LEB to compensate. 278 * extra LEB to compensate.
281 */ 279 */
282 ret += 1; 280 idx_lebs += 1;
283 if (ret < MIN_INDEX_LEBS) 281 if (idx_lebs < MIN_INDEX_LEBS)
284 ret = MIN_INDEX_LEBS; 282 idx_lebs = MIN_INDEX_LEBS;
285 return ret; 283 return idx_lebs;
286} 284}
287 285
288/** 286/**
@@ -718,7 +716,7 @@ void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
718 * Note, the calculation is pessimistic, which means that most of the time 716 * Note, the calculation is pessimistic, which means that most of the time
719 * UBIFS reports less space than it actually has. 717 * UBIFS reports less space than it actually has.
720 */ 718 */
721long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free) 719long long ubifs_reported_space(const struct ubifs_info *c, long long free)
722{ 720{
723 int divisor, factor, f; 721 int divisor, factor, f;
724 722
@@ -740,8 +738,7 @@ long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free)
740 divisor = UBIFS_MAX_DATA_NODE_SZ; 738 divisor = UBIFS_MAX_DATA_NODE_SZ;
741 divisor += (c->max_idx_node_sz * 3) / (f - 1); 739 divisor += (c->max_idx_node_sz * 3) / (f - 1);
742 free *= factor; 740 free *= factor;
743 do_div(free, divisor); 741 return div_u64(free, divisor);
744 return free;
745} 742}
746 743
747/** 744/**
diff --git a/fs/ubifs/debug.c b/fs/ubifs/debug.c
index 6ecb01a99d14..a2be11584ad3 100644
--- a/fs/ubifs/debug.c
+++ b/fs/ubifs/debug.c
@@ -33,6 +33,7 @@
33#include <linux/module.h> 33#include <linux/module.h>
34#include <linux/moduleparam.h> 34#include <linux/moduleparam.h>
35#include <linux/debugfs.h> 35#include <linux/debugfs.h>
36#include <linux/math64.h>
36 37
37#ifdef CONFIG_UBIFS_FS_DEBUG 38#ifdef CONFIG_UBIFS_FS_DEBUG
38 39
diff --git a/fs/ubifs/lpt.c b/fs/ubifs/lpt.c
index 6d914160ec55..b2792e84d245 100644
--- a/fs/ubifs/lpt.c
+++ b/fs/ubifs/lpt.c
@@ -43,8 +43,9 @@
43 * mounted. 43 * mounted.
44 */ 44 */
45 45
46#include <linux/crc16.h>
47#include "ubifs.h" 46#include "ubifs.h"
47#include <linux/crc16.h>
48#include <linux/math64.h>
48 49
49/** 50/**
50 * do_calc_lpt_geom - calculate sizes for the LPT area. 51 * do_calc_lpt_geom - calculate sizes for the LPT area.
@@ -135,15 +136,13 @@ static void do_calc_lpt_geom(struct ubifs_info *c)
135int ubifs_calc_lpt_geom(struct ubifs_info *c) 136int ubifs_calc_lpt_geom(struct ubifs_info *c)
136{ 137{
137 int lebs_needed; 138 int lebs_needed;
138 uint64_t sz; 139 long long sz;
139 140
140 do_calc_lpt_geom(c); 141 do_calc_lpt_geom(c);
141 142
142 /* Verify that lpt_lebs is big enough */ 143 /* Verify that lpt_lebs is big enough */
143 sz = c->lpt_sz * 2; /* Must have at least 2 times the size */ 144 sz = c->lpt_sz * 2; /* Must have at least 2 times the size */
144 sz += c->leb_size - 1; 145 lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size);
145 do_div(sz, c->leb_size);
146 lebs_needed = sz;
147 if (lebs_needed > c->lpt_lebs) { 146 if (lebs_needed > c->lpt_lebs) {
148 ubifs_err("too few LPT LEBs"); 147 ubifs_err("too few LPT LEBs");
149 return -EINVAL; 148 return -EINVAL;
@@ -175,7 +174,7 @@ static int calc_dflt_lpt_geom(struct ubifs_info *c, int *main_lebs,
175 int *big_lpt) 174 int *big_lpt)
176{ 175{
177 int i, lebs_needed; 176 int i, lebs_needed;
178 uint64_t sz; 177 long long sz;
179 178
180 /* Start by assuming the minimum number of LPT LEBs */ 179 /* Start by assuming the minimum number of LPT LEBs */
181 c->lpt_lebs = UBIFS_MIN_LPT_LEBS; 180 c->lpt_lebs = UBIFS_MIN_LPT_LEBS;
@@ -202,9 +201,7 @@ static int calc_dflt_lpt_geom(struct ubifs_info *c, int *main_lebs,
202 /* Now check there are enough LPT LEBs */ 201 /* Now check there are enough LPT LEBs */
203 for (i = 0; i < 64 ; i++) { 202 for (i = 0; i < 64 ; i++) {
204 sz = c->lpt_sz * 4; /* Allow 4 times the size */ 203 sz = c->lpt_sz * 4; /* Allow 4 times the size */
205 sz += c->leb_size - 1; 204 lebs_needed = div_u64(sz + c->leb_size - 1, c->leb_size);
206 do_div(sz, c->leb_size);
207 lebs_needed = sz;
208 if (lebs_needed > c->lpt_lebs) { 205 if (lebs_needed > c->lpt_lebs) {
209 /* Not enough LPT LEBs so try again with more */ 206 /* Not enough LPT LEBs so try again with more */
210 c->lpt_lebs = lebs_needed; 207 c->lpt_lebs = lebs_needed;
diff --git a/fs/ubifs/sb.c b/fs/ubifs/sb.c
index c5da201ab54f..e070c643d1bb 100644
--- a/fs/ubifs/sb.c
+++ b/fs/ubifs/sb.c
@@ -28,6 +28,7 @@
28 28
29#include "ubifs.h" 29#include "ubifs.h"
30#include <linux/random.h> 30#include <linux/random.h>
31#include <linux/math64.h>
31 32
32/* 33/*
33 * Default journal size in logical eraseblocks as a percent of total 34 * Default journal size in logical eraseblocks as a percent of total
@@ -80,7 +81,7 @@ static int create_default_filesystem(struct ubifs_info *c)
80 int err, tmp, jnl_lebs, log_lebs, max_buds, main_lebs, main_first; 81 int err, tmp, jnl_lebs, log_lebs, max_buds, main_lebs, main_first;
81 int lpt_lebs, lpt_first, orph_lebs, big_lpt, ino_waste, sup_flags = 0; 82 int lpt_lebs, lpt_first, orph_lebs, big_lpt, ino_waste, sup_flags = 0;
82 int min_leb_cnt = UBIFS_MIN_LEB_CNT; 83 int min_leb_cnt = UBIFS_MIN_LEB_CNT;
83 uint64_t tmp64, main_bytes; 84 long long tmp64, main_bytes;
84 __le64 tmp_le64; 85 __le64 tmp_le64;
85 86
86 /* Some functions called from here depend on the @c->key_len filed */ 87 /* Some functions called from here depend on the @c->key_len filed */
@@ -160,7 +161,7 @@ static int create_default_filesystem(struct ubifs_info *c)
160 if (!sup) 161 if (!sup)
161 return -ENOMEM; 162 return -ENOMEM;
162 163
163 tmp64 = (uint64_t)max_buds * c->leb_size; 164 tmp64 = (long long)max_buds * c->leb_size;
164 if (big_lpt) 165 if (big_lpt)
165 sup_flags |= UBIFS_FLG_BIGLPT; 166 sup_flags |= UBIFS_FLG_BIGLPT;
166 167
@@ -187,9 +188,8 @@ static int create_default_filesystem(struct ubifs_info *c)
187 188
188 generate_random_uuid(sup->uuid); 189 generate_random_uuid(sup->uuid);
189 190
190 main_bytes = (uint64_t)main_lebs * c->leb_size; 191 main_bytes = (long long)main_lebs * c->leb_size;
191 tmp64 = main_bytes * DEFAULT_RP_PERCENT; 192 tmp64 = div_u64(main_bytes * DEFAULT_RP_PERCENT, 100);
192 do_div(tmp64, 100);
193 if (tmp64 > DEFAULT_MAX_RP_SIZE) 193 if (tmp64 > DEFAULT_MAX_RP_SIZE)
194 tmp64 = DEFAULT_MAX_RP_SIZE; 194 tmp64 = DEFAULT_MAX_RP_SIZE;
195 sup->rp_size = cpu_to_le64(tmp64); 195 sup->rp_size = cpu_to_le64(tmp64);
diff --git a/fs/ubifs/super.c b/fs/ubifs/super.c
index a6a7798d020b..c3cefc841374 100644
--- a/fs/ubifs/super.c
+++ b/fs/ubifs/super.c
@@ -34,6 +34,7 @@
34#include <linux/parser.h> 34#include <linux/parser.h>
35#include <linux/seq_file.h> 35#include <linux/seq_file.h>
36#include <linux/mount.h> 36#include <linux/mount.h>
37#include <linux/math64.h>
37#include "ubifs.h" 38#include "ubifs.h"
38 39
39/* 40/*
@@ -612,7 +613,7 @@ static int bud_wbuf_callback(struct ubifs_info *c, int lnum, int free, int pad)
612static int init_constants_late(struct ubifs_info *c) 613static int init_constants_late(struct ubifs_info *c)
613{ 614{
614 int tmp, err; 615 int tmp, err;
615 uint64_t tmp64; 616 long long tmp64;
616 617
617 c->main_bytes = (long long)c->main_lebs * c->leb_size; 618 c->main_bytes = (long long)c->main_lebs * c->leb_size;
618 c->max_znode_sz = sizeof(struct ubifs_znode) + 619 c->max_znode_sz = sizeof(struct ubifs_znode) +
@@ -639,9 +640,8 @@ static int init_constants_late(struct ubifs_info *c)
639 * Make sure that the log is large enough to fit reference nodes for 640 * Make sure that the log is large enough to fit reference nodes for
640 * all buds plus one reserved LEB. 641 * all buds plus one reserved LEB.
641 */ 642 */
642 tmp64 = c->max_bud_bytes; 643 tmp64 = c->max_bud_bytes + c->leb_size - 1;
643 tmp = do_div(tmp64, c->leb_size); 644 c->max_bud_cnt = div_u64(tmp64, c->leb_size);
644 c->max_bud_cnt = tmp64 + !!tmp;
645 tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1); 645 tmp = (c->ref_node_alsz * c->max_bud_cnt + c->leb_size - 1);
646 tmp /= c->leb_size; 646 tmp /= c->leb_size;
647 tmp += 1; 647 tmp += 1;
@@ -677,7 +677,7 @@ static int init_constants_late(struct ubifs_info *c)
677 * Consequently, if the journal is too small, UBIFS will treat it as 677 * Consequently, if the journal is too small, UBIFS will treat it as
678 * always full. 678 * always full.
679 */ 679 */
680 tmp64 = (uint64_t)(c->jhead_cnt + 1) * c->leb_size + 1; 680 tmp64 = (long long)(c->jhead_cnt + 1) * c->leb_size + 1;
681 if (c->bg_bud_bytes < tmp64) 681 if (c->bg_bud_bytes < tmp64)
682 c->bg_bud_bytes = tmp64; 682 c->bg_bud_bytes = tmp64;
683 if (c->max_bud_bytes < tmp64 + c->leb_size) 683 if (c->max_bud_bytes < tmp64 + c->leb_size)
@@ -699,7 +699,7 @@ static int init_constants_late(struct ubifs_info *c)
699 * head is available. 699 * head is available.
700 */ 700 */
701 tmp64 = c->main_lebs - 1 - 1 - MIN_INDEX_LEBS - c->jhead_cnt + 1; 701 tmp64 = c->main_lebs - 1 - 1 - MIN_INDEX_LEBS - c->jhead_cnt + 1;
702 tmp64 *= (uint64_t)c->leb_size - c->leb_overhead; 702 tmp64 *= (long long)c->leb_size - c->leb_overhead;
703 tmp64 = ubifs_reported_space(c, tmp64); 703 tmp64 = ubifs_reported_space(c, tmp64);
704 c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT; 704 c->block_cnt = tmp64 >> UBIFS_BLOCK_SHIFT;
705 705
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 543e850022eb..a17dd794ae92 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -1498,7 +1498,7 @@ void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
1498long long ubifs_get_free_space(struct ubifs_info *c); 1498long long ubifs_get_free_space(struct ubifs_info *c);
1499int ubifs_calc_min_idx_lebs(struct ubifs_info *c); 1499int ubifs_calc_min_idx_lebs(struct ubifs_info *c);
1500void ubifs_convert_page_budget(struct ubifs_info *c); 1500void ubifs_convert_page_budget(struct ubifs_info *c);
1501long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free); 1501long long ubifs_reported_space(const struct ubifs_info *c, long long free);
1502long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs); 1502long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);
1503 1503
1504/* find.c */ 1504/* find.c */