F2FS: Backport to 3.4

Based off of patches here:
nowcomputing/f2fs-backports#1

Change-Id: I2be6d8abf4e3e4c6b9e8d635700930af432fe37a
diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index 683eb44..c7c3318 100644
--- a/fs/f2fs/acl.c
+++ b/fs/f2fs/acl.c
@@ -88,16 +88,8 @@
 			break;
 
 		case ACL_USER:
-			acl->a_entries[i].e_uid =
-				make_kuid(&init_user_ns,
-						le32_to_cpu(entry->e_id));
-			entry = (struct f2fs_acl_entry *)((char *)entry +
-					sizeof(struct f2fs_acl_entry));
-			break;
 		case ACL_GROUP:
-			acl->a_entries[i].e_gid =
-				make_kgid(&init_user_ns,
-						le32_to_cpu(entry->e_id));
+			acl->a_entries[i].e_id = le32_to_cpu(entry->e_id);
 			entry = (struct f2fs_acl_entry *)((char *)entry +
 					sizeof(struct f2fs_acl_entry));
 			break;
@@ -134,16 +126,8 @@
 
 		switch (acl->a_entries[i].e_tag) {
 		case ACL_USER:
-			entry->e_id = cpu_to_le32(
-					from_kuid(&init_user_ns,
-						acl->a_entries[i].e_uid));
-			entry = (struct f2fs_acl_entry *)((char *)entry +
-					sizeof(struct f2fs_acl_entry));
-			break;
 		case ACL_GROUP:
-			entry->e_id = cpu_to_le32(
-					from_kgid(&init_user_ns,
-						acl->a_entries[i].e_gid));
+			entry->e_id = cpu_to_le32(acl->a_entries[i].e_id);
 			entry = (struct f2fs_acl_entry *)((char *)entry +
 					sizeof(struct f2fs_acl_entry));
 			break;
@@ -357,7 +341,7 @@
 		return PTR_ERR(acl);
 	if (!acl)
 		return -ENODATA;
-	error = posix_acl_to_xattr(&init_user_ns, acl, buffer, size);
+	error = posix_acl_to_xattr(acl, buffer, size);
 	posix_acl_release(acl);
 
 	return error;
@@ -379,7 +363,7 @@
 		return -EPERM;
 
 	if (value) {
-		acl = posix_acl_from_xattr(&init_user_ns, value, size);
+		acl = posix_acl_from_xattr(value, size);
 		if (IS_ERR(acl))
 			return PTR_ERR(acl);
 		if (acl) {
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 25561d3..f5d19e5 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -38,7 +38,16 @@
 
 	f2fs_balance_fs(sbi);
 
-	sb_start_pagefault(inode->i_sb);
+	/* F2FS backport: We replace in old kernels sb_start_pagefault(inode->i_sb) with vfs_check_frozen()
+	 * and remove the original sb_end_pagefault(inode->i_sb) after the out label
+	 *
+	 * The introduction of sb_{start,end}_pagefault() was made post-3.2 kernels by Jan Kara
+	 * and merged in commit a0e881b7c189fa2bd76c024dbff91e79511c971d.
+	 * Discussed at https://lkml.org/lkml/2012/3/5/278
+	 *
+	 * - Alex
+	 */
+	vfs_check_frozen(inode->i_sb, SB_FREEZE_WRITE);
 
 	/* block allocation */
 	f2fs_lock_op(sbi);
@@ -78,14 +87,12 @@
 	/* fill the page */
 	wait_on_page_writeback(page);
 out:
-	sb_end_pagefault(inode->i_sb);
 	return block_page_mkwrite_return(err);
 }
 
 static const struct vm_operations_struct f2fs_file_vm_ops = {
-	.fault		= filemap_fault,
-	.page_mkwrite	= f2fs_vm_page_mkwrite,
-	.remap_pages	= generic_file_remap_pages,
+	.fault        = filemap_fault,
+	.page_mkwrite = f2fs_vm_page_mkwrite,
 };
 
 static int get_parent_ino(struct inode *inode, nid_t *pino)
@@ -189,6 +196,7 @@
 {
 	file_accessed(file);
 	vma->vm_ops = &f2fs_file_vm_ops;
+	vma->vm_flags |= VM_CAN_NONLINEAR;
 	return 0;
 }
 
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index c1f02fd..0c1072d 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -45,11 +45,6 @@
 		if (kthread_should_stop())
 			break;
 
-		if (sbi->sb->s_writers.frozen >= SB_FREEZE_WRITE) {
-			wait_ms = increase_sleep_time(gc_th, wait_ms);
-			continue;
-		}
-
 		/*
 		 * [GC triggering condition]
 		 * 0. GC is not conducted currently.
diff --git a/fs/f2fs/gc.h b/fs/f2fs/gc.h
index 5d5eb60..e423aef 100644
--- a/fs/f2fs/gc.h
+++ b/fs/f2fs/gc.h
@@ -105,6 +105,6 @@
 {
 	struct block_device *bdev = sbi->sb->s_bdev;
 	struct request_queue *q = bdev_get_queue(bdev);
-	struct request_list *rl = &q->root_rl;
+	struct request_list *rl = &q->rq;
 	return !(rl->count[BLK_RW_SYNC]) && !(rl->count[BLK_RW_ASYNC]);
 }
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 4d67ed7..3c30e74 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -87,8 +87,8 @@
 	ri = F2FS_INODE(node_page);
 
 	inode->i_mode = le16_to_cpu(ri->i_mode);
-	i_uid_write(inode, le32_to_cpu(ri->i_uid));
-	i_gid_write(inode, le32_to_cpu(ri->i_gid));
+	inode->i_uid = le32_to_cpu(ri->i_uid);
+	inode->i_gid = le32_to_cpu(ri->i_gid);
 	set_nlink(inode, le32_to_cpu(ri->i_links));
 	inode->i_size = le64_to_cpu(ri->i_size);
 	inode->i_blocks = le64_to_cpu(ri->i_blocks);
@@ -185,8 +185,8 @@
 
 	ri->i_mode = cpu_to_le16(inode->i_mode);
 	ri->i_advise = F2FS_I(inode)->i_advise;
-	ri->i_uid = cpu_to_le32(i_uid_read(inode));
-	ri->i_gid = cpu_to_le32(i_gid_read(inode));
+	ri->i_uid = cpu_to_le32(inode->i_uid);
+	ri->i_gid = cpu_to_le32(inode->i_gid);
 	ri->i_links = cpu_to_le32(inode->i_nlink);
 	ri->i_size = cpu_to_le64(i_size_read(inode));
 	ri->i_blocks = cpu_to_le64(inode->i_blocks);
@@ -272,7 +272,6 @@
 	if (inode->i_nlink || is_bad_inode(inode))
 		goto no_delete;
 
-	sb_start_intwrite(inode->i_sb);
 	set_inode_flag(F2FS_I(inode), FI_NO_ALLOC);
 	i_size_write(inode, 0);
 
@@ -284,7 +283,6 @@
 	stat_dec_inline_inode(inode);
 	f2fs_unlock_op(sbi);
 
-	sb_end_intwrite(inode->i_sb);
 no_delete:
-	clear_inode(inode);
+	end_writeback(inode);
 }
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index 3d32f29..540bac6 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -109,7 +109,7 @@
 }
 
 static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
-						bool excl)
+						struct nameidata *nd)
 {
 	struct super_block *sb = dir->i_sb;
 	struct f2fs_sb_info *sbi = F2FS_SB(sb);
@@ -181,7 +181,7 @@
 
 struct dentry *f2fs_get_parent(struct dentry *child)
 {
-	struct qstr dotdot = QSTR_INIT("..", 2);
+	struct qstr dotdot = { .name = "..", .len = 2 };
 	unsigned long ino = f2fs_inode_by_name(child->d_inode, &dotdot);
 	if (!ino)
 		return ERR_PTR(-ENOENT);
@@ -189,7 +189,7 @@
 }
 
 static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry,
-		unsigned int flags)
+		struct nameidata *nd)
 {
 	struct inode *inode = NULL;
 	struct f2fs_dir_entry *de;
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index c60b7b1..3be6d3d 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -450,22 +450,6 @@
 	return 0;
 }
 
-static int f2fs_freeze(struct super_block *sb)
-{
-	int err;
-
-	if (f2fs_readonly(sb))
-		return 0;
-
-	err = f2fs_sync_fs(sb, 1);
-	return err;
-}
-
-static int f2fs_unfreeze(struct super_block *sb)
-{
-	return 0;
-}
-
 static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
 	struct super_block *sb = dentry->d_sb;
@@ -551,7 +535,7 @@
 
 static int segment_info_open_fs(struct inode *inode, struct file *file)
 {
-	return single_open(file, segment_info_seq_show, PDE_DATA(inode));
+	return single_open(file, segment_info_seq_show, PDE(inode)->data);
 }
 
 static const struct file_operations f2fs_seq_segment_info_fops = {
@@ -624,8 +608,6 @@
 	.evict_inode	= f2fs_evict_inode,
 	.put_super	= f2fs_put_super,
 	.sync_fs	= f2fs_sync_fs,
-	.freeze_fs	= f2fs_freeze,
-	.unfreeze_fs	= f2fs_unfreeze,
 	.statfs		= f2fs_statfs,
 	.remount_fs	= f2fs_remount,
 };