aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ubifs
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ubifs')
-rw-r--r--fs/ubifs/budget.c45
-rw-r--r--fs/ubifs/misc.h32
-rw-r--r--fs/ubifs/ubifs.h1
3 files changed, 46 insertions, 32 deletions
diff --git a/fs/ubifs/budget.c b/fs/ubifs/budget.c
index 9ef630a594ca..7851480a6cea 100644
--- a/fs/ubifs/budget.c
+++ b/fs/ubifs/budget.c
@@ -702,6 +702,51 @@ void ubifs_release_dirty_inode_budget(struct ubifs_info *c,
702} 702}
703 703
704/** 704/**
705 * ubifs_reported_space - calculate reported free space.
706 * @c: the UBIFS file-system description object
707 * @free: amount of free space
708 *
709 * This function calculates amount of free space which will be reported to
710 * user-space. User-space application tend to expect that if the file-system
711 * (e.g., via the 'statfs()' call) reports that it has N bytes available, they
712 * are able to write a file of size N. UBIFS attaches node headers to each data
713 * node and it has to write indexind nodes as well. This introduces additional
714 * overhead, and UBIFS it has to report sligtly less free space to meet the
715 * above expectetion.
716 *
717 * This function assumes free space is made up of uncompressed data nodes and
718 * full index nodes (one per data node, tripled because we always allow enough
719 * space to write the index thrice).
720 *
721 * Note, the calculation is pessimistic, which means that most of the time
722 * UBIFS reports less space than it actually has.
723 */
724long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free)
725{
726 int divisor, factor;
727
728 /*
729 * Reported space size is @free * X, where X is UBIFS block size
730 * divided by UBIFS block size + all overhead one data block
731 * introduces. The overhead is the node header + indexing overhead.
732 *
733 * Indexing overhead is calculations are based on the following
734 * formula: I = N/(f - 1) + 1, where I - number of indexing nodes, N -
735 * number of data nodes, f - fanout. Because effective UBIFS fanout is
736 * twice as less than maximum fanout, we assume that each data node
737 * introduces 3 * @c->max_idx_node_sz / (@c->fanout/2 - 1) bytes.
738 * Note, the multiplier 3 is because UBIFS reseves thrice as more space
739 * for the index.
740 */
741 factor = UBIFS_BLOCK_SIZE;
742 divisor = UBIFS_MAX_DATA_NODE_SZ;
743 divisor += (c->max_idx_node_sz * 3) / ((c->fanout >> 1) - 1);
744 free *= factor;
745 do_div(free, divisor);
746 return free;
747}
748
749/**
705 * ubifs_budg_get_free_space - return amount of free space. 750 * ubifs_budg_get_free_space - return amount of free space.
706 * @c: UBIFS file-system description object 751 * @c: UBIFS file-system description object
707 * 752 *
diff --git a/fs/ubifs/misc.h b/fs/ubifs/misc.h
index 87ced4c74a61..4c12a9215d7f 100644
--- a/fs/ubifs/misc.h
+++ b/fs/ubifs/misc.h
@@ -284,38 +284,6 @@ static inline void *ubifs_idx_key(const struct ubifs_info *c,
284} 284}
285 285
286/** 286/**
287 * ubifs_reported_space - calculate reported free space.
288 * @c: the UBIFS file-system description object
289 * @free: amount of free space
290 *
291 * This function calculates amount of free space which will be reported to
292 * user-space. User-space application tend to expect that if the file-system
293 * (e.g., via the 'statfs()' call) reports that it has N bytes available, they
294 * are able to write a file of size N. UBIFS attaches node headers to each data
295 * node and it has to write indexind nodes as well. This introduces additional
296 * overhead, and UBIFS it has to report sligtly less free space to meet the
297 * above expectetion.
298 *
299 * This function assumes free space is made up of uncompressed data nodes and
300 * full index nodes (one per data node, doubled because we always allow enough
301 * space to write the index twice).
302 *
303 * Note, the calculation is pessimistic, which means that most of the time
304 * UBIFS reports less space than it actually has.
305 */
306static inline long long ubifs_reported_space(const struct ubifs_info *c,
307 uint64_t free)
308{
309 int divisor, factor;
310
311 divisor = UBIFS_MAX_DATA_NODE_SZ + (c->max_idx_node_sz * 3);
312 factor = UBIFS_MAX_DATA_NODE_SZ - UBIFS_DATA_NODE_SZ;
313 do_div(free, divisor);
314
315 return free * factor;
316}
317
318/**
319 * ubifs_current_time - round current time to time granularity. 287 * ubifs_current_time - round current time to time granularity.
320 * @inode: inode 288 * @inode: inode
321 */ 289 */
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 7828d69ca4f8..681d46e16286 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -1441,6 +1441,7 @@ void ubifs_cancel_ino_op(struct ubifs_info *c, struct inode *inode,
1441long long ubifs_budg_get_free_space(struct ubifs_info *c); 1441long long ubifs_budg_get_free_space(struct ubifs_info *c);
1442int ubifs_calc_min_idx_lebs(struct ubifs_info *c); 1442int ubifs_calc_min_idx_lebs(struct ubifs_info *c);
1443void ubifs_convert_page_budget(struct ubifs_info *c); 1443void ubifs_convert_page_budget(struct ubifs_info *c);
1444long long ubifs_reported_space(const struct ubifs_info *c, uint64_t free);
1444long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs); 1445long long ubifs_calc_available(const struct ubifs_info *c, int min_idx_lebs);
1445 1446
1446/* find.c */ 1447/* find.c */