reiser4: fix reservation and deadlock

Reserve space in reiser4_write_begin() properly:
1) for update_sd() when changing file size;
2) for update_sd() when updating mtime/ctime.

Fix deadlock (reiser4 lock ordering violation):
release page lock in reiser4_dirty_inode()
before acquiring a longterm lock.

Signed-off-by: Edward Shishkin <edward.shishkin@gmail.com>
reiser4: lock ->i_mutex in sync_file_common().

This is probably required since the said locking has been removed from
the caller by upstream.

Also, added error handling of "filemap_write_and_wait_range()".
reiser4: add i_nlink management macros.

They are named INODE_{INC,DROP,CLEAR,SET}_NLINK and use an internal
INODE_OPERATE_NLINK macro.

Their purpose is to use new i_nlink management functions
{inc,drop,clear,set}_nlink() together with inode_check_scale().
reiser4: use i_nlink management macros.

Replace successive calls to library functions {set,drop,clear,inc}_nlink()
and inode_check_scale() with usages of i_nlink management macros.

Places where only *_nlink() library function is called without a
inode_check_scale() call following were not converted to macros as that
would change the semantics.
reiser4: do not make reiser4_permission_common() bail out on rcu-walk.

The reason is that generic_permission() is actually rcu-aware.
reiser4: do not clear-then-add nlink on inode creation.

Increasing i_nlink 0 -> 1 spawns a warning at fs/inode.c:336;
thus avoid messing with it when creating an inode.

Instead, only clear it in "failed" code path before calling iput() on
the inode. This is required because clearing i_nlink increases
superblock's s_remove_count, and iput()/iput_final() ultimately calls
__destroy_inode() which decreases said s_remove_count.

Also, do not clear nlink in set_plug_in_inode_common(), because
1) this was redundant, and
2) current solution interferes with it.
It is safe because file_plugin's ->set_plug_in_inode() is called only
from do_create_vfs_child().
reiser4: fix i_nlink management macros: check scale before assignment.
reiser4: fixes to cryptcompress main search procedure.

- Make a full-fledged tree traversal in the case we encountered empty
  right neighbor;
- Unlock the left neighbor only in the case we moved to right.

Signed-off-by: Edward Shishkin <edward.shishkin@gmail.com>
reiser4: lock bdi_writeback* wb when calling generic_writeback_sb_inodes().

Signed-off-by: Edward Shishkin <edward.shishkin@gmail.com>
reiser4: capture superblock on sync (+ make gcc happy).

Signed-off-by: Edward Shishkin <edward.shishkin@gmail.com>
reiser4: update delimiting keys in squeeze_right_twig().
reiser4: fix cluster nodes accounting.
reiser4: fix "edward-1547" assertion in balance_dirty_page_cluster().

nr_dirtied == 0 means truncating at the boundary of logical
cluster. In this case nothing is dirtied, so we don't need to
throttle writes (as well as extra lock of checkin_mutex).
reiser4: fix warning in reiser4_init_read_super: replace sizeof() with strlen().
reiser4: fix reiser4_rename_common: memset (foo, 0, sizeof foo).
reiser4: implement a full-fledged ->migratepage() method.

Use a modified copy of ->releasepage() logic.
Unlike the original ->releasepage(), update the jnode-page link instead
of just removing it.

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: ->migratepage(): reset non-NULL private sometimes encountered in "newpage".

Don't know why this happens, but as far as it does not affect runtime,
just workaround to avoid a panic in jnode_attach_page().

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: ->migratepage(): export and use mm/migrate.c:writeout() instead of write_one_page().

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: ->migratepage(): use correct error codes (-EAGAIN instead of -EIO).

Signed-off-by: Ivan Shapovalov <intelfx100@gmail.com>
reiser4: ->migratepage(): debug non-NULL private field on migration dest pages.

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