On 08/17/2014 11:52 PM, Ivan Shapovalov wrote:
This is used for FITRIM ioctl which will iteratively grab, allocate and trim disk space
bit by bit to avoid starving the rest of system.
Signed-off-by: Ivan Shapovalov <intelfx100@xxxxxxxxx>
---
fs/reiser4/block_alloc.c | 5 +++++
fs/reiser4/block_alloc.h | 5 ++++-
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/fs/reiser4/block_alloc.c b/fs/reiser4/block_alloc.c
index d3d730c..9eed7fc 100644
--- a/fs/reiser4/block_alloc.c
+++ b/fs/reiser4/block_alloc.c
@@ -276,6 +276,11 @@ reiser4_grab(reiser4_context * ctx, __u64 count, reiser4_ba_flags_t flags)
free_blocks = sbinfo->blocks_free;
+ if (flags & BA_SOME_SPACE) {
+ /* Reserve 25% of all free space. */
if (free_blocks == 0) {
/* nothing to trim */
ret= RETERR(-ENOSPC);
goto unlock_and_ret;
}
+ count = free_blocks >> 2;
if (count == 0)
/* there are 1, 2, or 3 free blocks */
count = free_blocks;
+ }
+
if ((use_reserved && free_blocks < count) ||
(!use_reserved && free_blocks < count + sbinfo->blocks_reserved)) {
ret = RETERR(-ENOSPC);
diff --git a/fs/reiser4/block_alloc.h b/fs/reiser4/block_alloc.h
index a4e98af..bfc6be9 100644
--- a/fs/reiser4/block_alloc.h
+++ b/fs/reiser4/block_alloc.h
@@ -79,7 +79,10 @@ enum reiser4_ba_flags {
BA_FORCE = (1 << 5),
/* use default start value for free blocks search. */
- BA_USE_DEFAULT_SEARCH_START = (1 << 6)
+ BA_USE_DEFAULT_SEARCH_START = (1 << 6),
+
+ /* reserve some fixed amount of space */
+ BA_SOME_SPACE = (1 << 7),
};
typedef enum reiser4_ba_flags reiser4_ba_flags_t;
--
To unsubscribe from this list: send the line "unsubscribe reiserfs-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html