Revert "Add F2FS Filesystem. (Flash-Friendly File System)"

This reverts commit d08c7e3f005eba2e7114b1b562ac562e1368a9dd.
fs: f2fs: Add F2FS from 3.8-rc2

Backport of these commits

48c6d12 f2fs: Don't assign e_id in f2fs_acl_from_disk
6666e6a f2fs: fix tracking parent inode number
3cd8a23 f2fs: cleanup the f2fs_bio_alloc routine
457d08e f2fs: introduce accessor to retrieve number of dentry slots
508198b f2fs: remove redundant call to f2fs_put_page in delete entry
a0d4253 f2fs: make use of GFP_F2FS_ZERO for setting gfp_mask
c212991 f2fs: rewrite f2fs_bio_alloc to make it simpler
705f814 f2fs: remove unused variable
61412b6 f2fs: move error condition for mkdir at proper place
1042d60 f2fs: remove unneeded initialization
1fa95b0 f2fs: check read only condition before beginning write out
154a086 f2fs: remove unneeded memset from init_once
72ce609 f2fs: show error in case of invalid mount arguments
be4124f f2fs: fix the compiler warning for uninitialized use of variable
573ea5f f2fs: resolve build failures
0a8165d f2fs: adjust kernel coding style
25ca923 f2fs: fix endian conversion bugs reported by sparse
cf0e3a6 f2fs: remove unneeded version.h header file from f2fs.h
a14d5393 f2fs: update Kconfig and Makefile
902829a f2fs: move proc files to debugfs
d624c96 f2fs: add recovery routines for roll-forward
7bc0900 f2fs: add garbage collection functions
af48b85 f2fs: add xattr and acl functionalities
6b4ea01 f2fs: add core directory operations
57397d8 f2fs: add inode operations for special inodes
19f99ce f2fs: add core inode operations
eb47b80 f2fs: add address space operations for data
fbfa2cc f2fs: add file operations
351df4b f2fs: add segment operations
e05df3b f2fs: add node operations
127e670 f2fs: add checkpoint operations
aff063e f2fs: add super block operations
39a53e0 f2fs: add superblock and major in-memory structure

a14d5393 f2fs: update Kconfig and Makefile

dd31866 f2fs: add on-disk layout

d08ab08 f2fs: fix a typo in f2fs documentation
5bb446a f2fs: update the f2fs document
98e4da8 f2fs: add document

Change-Id: I6afbc627f251a0e4f8f493136591f74ff29b5ef0
Reviewed-on: http://gerrit.pcs.mot.com/510414
Tested-by: Jira Key <JIRAKEY@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Reviewed-by: John Zafiris <qemx13@motorola.com>
Submit-Approved: Jira Key <JIRAKEY@motorola.com>
(cherry picked from commit 845e143f34b1af9980ef3ab2b3df339dfa362516)
fs: f2fs: Backport to K3.4

Backporting F2FS from K3.8-rc2 to K3.4

- Adjust for missing e_uid/e_gid in acl entries
- mismatch in posix_acl_to_xattr/posix_acl_from_xattr
- missing sb_start_pagefault/sb_end_pagefault
- request_list in request_queue is rq instead of root_rl
- missing i_uid_write, i_uid_read
- clear_inode renamed from end_writeback
- Missing QSTR_INIT definition
- f2fs_lookup prototype mismatch
- f2fs_create prototype mismatch

Change-Id: I6c2dd145822271d69f2a6fed0586179f7fcd6fbe
Reviewed-on: http://gerrit.pcs.mot.com/510430
Tested-by: Jira Key <JIRAKEY@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Reviewed-by: John Zafiris <qemx13@motorola.com>
Submit-Approved: Jira Key <JIRAKEY@motorola.com>
(cherry picked from commit 9c3783f4b8292c07395aae61dbca21e2fc4725b4)
f2fs: add missing #include <linux/prefetch.h>

m68k allmodconfig:

fs/f2fs/data.c: In function ‘read_end_io’:
fs/f2fs/data.c:311: error: implicit declaration of function ‘prefetchw’

fs/f2fs/segment.c: In function ‘f2fs_end_io_write’:
fs/f2fs/segment.c:628: error: implicit declaration of function ‘prefetchw’

Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 85c04df233ed235e589c2bd5b492bbd31b8758cd)
f2fs: invalidate the node page if allocation is failed

The new_node_page() is processed as the following procedure.

1. A new node page is allocated.
2. Set PageUptodate with proper footer information.
3. Check if there is a free space for allocation
 4.a. If there is no space, f2fs returns with -ENOSPC.
 4.b. Otherwise, go next.

In the case of step #4.a, f2fs remains a wrong node page in the page cache
with the uptodate flag.

Also, even though a new node page is allocated successfully, an error can be
occurred afterwards due to allocation failure of the other data structures.
In such a case, remove_inode_page() would be triggered, so that we have to
clear uptodate flag in truncate_node() too.

So, we should remove the uptodate flag, if allocation is failed.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit b77127ad0dc94f37c71e07eb202f0d1d719fe001)
f2fs: return a default value for non-void function

This patch resolves a build warning reported by kbuild test robot.

"
fs/f2fs/segment.c: In function '__get_segment_type':
fs/f2fs/segment.c:806:1: warning: control reaches end of non-void
function [-Wreturn-type]
"

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 3712172e53d93e89bc010f94c54b45955b1b3dd7)
f2fs: fix equation of has_not_enough_free_secs()

Practically, has_not_enough_free_secs() should calculate with the numbers of
current node and directory data blocks together.
Actually the equation was implemented in need_to_flush().

So, this patch removes need_flush() and moves the equation into
has_not_enough_free_secs().

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit aab02b3cb763c80fd978afe47b94116fc53386ba)
f2fs: handle error from f2fs_iget_nowait

In case f2fs_iget_nowait returns error, it results in truncate_hole being
called with 'error' value as inode pointer. There is no check in truncate_hole
for valid inode, so it could result in crash due "invalid access to memory".
Avoid this by handling error condition properly.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 6db914051a046db7ac702e814a14ca9d9678b58c)
f2fs: remove unneeded initialization of nr_dirty in dirty_seglist_info

Since, the memory for the object of dirty_seglist_info is allocated
using kzalloc - which returns zeroed out memory. So, there is no need
to initialize the nr_dirty values with zeroes.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 1210b2deccb660a38ccbd9edb8f4e5a5d2e25565)
f2fs: fix fsync_inode list addition logic and avoid invalid access to memory

In function find_fsync_dnodes() - the fsync inodes gets added to the list, but
in one path suppose f2fs_iget results in error, in such case - error gets added
to the fsync inode list.
In next call to recover_data()->get_fsync_inode()
entry = list_entry(this, struct fsync_inode_entry, list);
                if (entry->inode->i_ino == ino)
This can result in "invalid access to memory" when it encounters 'error' as
entry in the fsync inode list.
So, add the fsync inode entry to the list only in case of no errors.
And, free the object at that point itself in case of issue.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 1e784d43411dcad5f722795e22fd8ac8e99ce741)
f2fs: remove unneeded variable from f2fs_sync_fs

We can directly return '0' from the function, instead of introducing a
'ret' variable.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 282378ffc48e407bfd4add9560bfc9bce8e18c7d)
f2fs: fix handling errors got by f2fs_write_inode

Ruslan reported that f2fs hangs with an infinite loop in f2fs_sync_file():

	while (sync_node_pages(sbi, inode->i_ino, &wbc) == 0)
		f2fs_write_inode(inode, NULL);

The reason was revealed that the cold flag is not set even thought this inode is
a normal file. Therefore, sync_node_pages() skips to write node blocks since it
only writes cold node blocks.

The cold flag is stored to the node_footer in node block, and whenever a new
node page is allocated, it is set according to its file type, file or directory.

But, after sudden-power-off, when recovering the inode page, f2fs doesn't recover
its cold flag.

So, let's assign the cold flag in more right places.

One more thing:
If f2fs_write_inode() returns an error due to whatever situations, there would
be no dirty node pages so that sync_node_pages() returns zero.
(i.e., zero means nothing was written.)

Reported-by: Ruslan N. Marchenko <me@ruff.mobi>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit fab198a9f0a513a48dd3d3f812f2c8f233f32d80)
f2fs: remove set_page_dirty for atomic f2fs_end_io_write

We should guarantee not to do *scheduling while atomic*.
I found, in atomic f2fs_end_io_write(), there is a set_page_dirty() call
to deal with IO errors.

But, set_page_dirty() calls:
 -> f2fs_set_data_page_dirty()
   -> set_dirty_dir_page()
      -> cond_resched() which results in scheduling.

In order to avoid this, I'd like to remove simply set_page_dirty(),
since the page is already marked as ERROR and f2fs will be operated
as the read-only mode as well.
So, there is no recovery issue with this.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 32c29d3402a9592ca7aecc8d115d1733b6dbd699)
f2fs: fix wrong calculation on f_files in statfs

In f2fs_statfs(), f_files should be the total number of available inodes
instead of the currently allocated inodes.
So, this patch should resolve the reported bug below.

Note that, showing 10% usage is not a bug, since f2fs reveals whole volume size
as much as possible and shows the space overhead as *used*.
This policy is fair enough with respect to other file systems.

<Reported Bug>
(loop0 is backed by 1GiB file)

$ mkfs.f2fs /dev/loop0

F2FS-tools: Ver: 1.1.0 (2012-12-11)
Info: sector size = 512
Info: total sectors = 2097152 (in 512bytes)
Info: zone aligned segment0 blkaddr: 512
Info: format successful

$ mount /dev/loop0 mnt/

$ df mnt/
Filesystem     1K-blocks  Used Available Use% Mounted on
/dev/loop0       1046528 98312    929784  10%
/home/zeta/linux-devel/mtd-bench/mnt

$ df mnt/ -i
Filesystem     Inodes   IUsed  IFree IUse% Mounted on
/dev/loop0       1 -465918 465919     - /home/zeta/linux-devel/mtd-bench/mnt

Notice IUsed is negative. Also, 10% usage on a fresh f2fs seems too
much to be correct.

Reported-and-Tested-by: Ezequiel Garcia <elezegarcia@gmail.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 40bc2dcc5ab77ac839ded5e7aa18ee13438cb006)
f2fs: fix up f2fs_get_parent issue to retrieve correct parent inode number

Test Case:
[NFS Client]
ls -lR .

[NFS Server]
while [ 1 ]
do
echo 3 > /proc/sys/vm/drop_caches
done

Error on NFS Client: "No such file or directory"

When cache is dropped at the server, it results in lookup failure at the
NFS client due to non-connection with the parent. The default path is it
initiates a lookup by calculating the hash value for the name, even though
the hash values stored on the disk for "." and ".." is maintained as zero,
which results in failure from find_in_block due to not matching HASH values.
Fix up, by using the correct hashing values for these entries.

Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Amit Sahrawat <a.sahrawat@samsung.com>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 83870fe24752101cc570f2cb16956a101d4901a0)
f2fs: should recover orphan and fsync data

The recovery routine should do all the time regardless of normal umount action.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit bdb9af4f84538e7fd5244933904285a4da393ca0)
f2fs: do f2fs_balance_fs in front of dir operations

In order to conserve free sections to deal with the worst-case scenarios, f2fs
should be able to freeze all the directory operations especially when there are
not enough free sections. The f2fs_balance_fs() is for this use.

When FS utilization becomes almost 100%, directory operations can be failed due
to -ENOSPC frequently, which produces some dirty node pages occasionally.

Previously, in such a case, f2fs_balance_fs() is not able to be triggered since
it is triggered only if the directory operation ends up with success.

So, this patch triggers f2fs_balance_fs() at first before handling directory
operations.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 2447cac4d5df9686bc94f6c9073e1223a8b63e53)
f2fs: clean up the start_bidx_of_node function

This patch also resolves the following warning reported by kbuild test robot.

fs/f2fs/gc.c: In function 'start_bidx_of_node':
fs/f2fs/gc.c:453:21: warning: 'bidx' may be used uninitialized in this function

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit f4b76e8e4ed6a276a8635d641111b187cd40a0f1)
f2fs: clean up unused variables and return values

This patch cleans up a couple of unnecessary codes related to unused variables
and return values.

Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit 47452510dcd999ac2e3c02a4f3c233bb7d4c4023)
f2fs: unify string length declarations and usage

This patch is intended to unify string length declarations and usage.
There are number of calls to strlen which return size_t object.
The size of this object depends on compiler if it will be bigger,
equal or even smaller than an unsigned int

Signed-off-by: Leon Romanovsky <leon@leon.nu>
Signed-off-by: Jaegeuk Kim <jaegeuk.kim@samsung.com>
(cherry picked from commit abe33e5e9a9b30e48ad8c089abfa18bcfd826e41)