reiser4: block_alloc: add BA_SOME_SPACE flag for grabbing a fixed amount of space.

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@gmail.com>
reiser4: block_alloc: add a "monotonic_forward" parameter to reiser4_blocknr_hint to allocate blocks only in forward direction.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: block_alloc: move block accounting by pre-commit hook into block_alloc.c and document BA_DEFER behavior.

BA_DEFER deallocations ignore target_stage and other flags and use some implied
values for these parameters. Document these values and where they do matter.

Also move deallocated block accounting into block_alloc.c because
1) it is allocator-independent;
2) it allows discard code to rely on that accounting is done in pre-commit hook and
   not later, so that discard code should not use BA_PERMANENT in its allocations.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: txnmgr: free allocated but unneeded atom in atom_begin_and_assign_to_txnh().

It is unclear why it hasn't been done before, as there was a
corresponding notice, and such change apparently does not carry any side
effects.

Do this to avoid duplicating code in the next commit.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: txnmgr: add reiser4_create_atom() which creates an empty atom without capturing any nodes.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: txnmgr: move "empty atom" shortcut slightly below.

reiser4_trim_fs() generate empty (atom->capture_count == 0) atoms which
still have non-empty delete sets. That is, such atoms take a "goto done"
shortcut in commit_current_atom().

First, this shortcut must not preclude calling current_atom_complete_writes()
to process and detach atom's flush queues (otherwise atom_isclean() will
return false).

Second, reiser4_post_write_back_hook() needs to be called explicitly
to process atom's delete sets.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: batch discard support: add a dummy FITRIM ioctl handler for directories.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: batch discard support: actually implement the FITRIM ioctl handler.

It works in an iterative way, grabbing some fixed amount of space and allocating
blocks until grabbed space is exhausted or partition's end is reached.

Blocks are scheduled for discard by allocating them and immediately adding them
to the atom's delete set, which is read and processed at atom commit time.

After reaching the allocation stop condition, the atom is force-committed and,
if the allocation has been stopped due to grabbed space exhaustion (not due to
reaching end of partition), another iteration happens.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: block_alloc: add a "min_len" parameter to reiser4_blocknr_hint to limit allocated extent length from below.

The default has been 1, that is, the first encountered free extent with any length
from 1 to requested is allocated and returned.

So, allow changing minimal extent length to allocate.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: batch discard support: honor minimal extent length passed from the userspace.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>