aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2017-07-10 17:29:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-10 17:29:45 -0400
commit5cdd4c046864827e7ac140eed081c6768a4dbb16 (patch)
treecbcbf432df6c707926d3a4c016f5486aba9fddec
parent7cee9384cb3e25de33d75ecdbf08bb15b4ea9fa5 (diff)
parent0abd675e97e60d40e61d59532f8118b0e439034e (diff)
Merge tag 'for-f2fs-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs
Pull f2fs updates from Jaegeuk Kim: "In this round, we've added new features such as disk quota and statx, and modified internal bio management flow to merge more IOs depending on block types. We've also made internal threads freezeable for Android battery life. In addition to them, there are some patches to avoid lock contention as well as a couple of deadlock conditions. Enhancements: - support usrquota, grpquota, and statx - manage DATA/NODE typed bios separately to serialize more IOs - modify f2fs_lock_op/wio_mutex to avoid lock contention - prevent lock contention in migratepage Bug fixes: - fix missing load of written inode flag - fix worst case victim selection in GC - freezeable GC and discard threads for Android battery life - sanitize f2fs metadata to deal with security hole - clean up sysfs-related code and docs" * tag 'for-f2fs-4.13' of git://git.kernel.org/pub/scm/linux/kernel/git/jaegeuk/f2fs: (59 commits) f2fs: support plain user/group quota f2fs: avoid deadlock caused by lock order of page and lock_op f2fs: use spin_{,un}lock_irq{save,restore} f2fs: relax migratepage for atomic written page f2fs: don't count inode block in in-memory inode.i_blocks Revert "f2fs: fix to clean previous mount option when remount_fs" f2fs: do not set LOST_PINO for renamed dir f2fs: do not set LOST_PINO for newly created dir f2fs: skip ->writepages for {mete,node}_inode during recovery f2fs: introduce __check_sit_bitmap f2fs: stop gc/discard thread in prior during umount f2fs: introduce reserved_blocks in sysfs f2fs: avoid redundant f2fs_flush after remount f2fs: report # of free inodes more precisely f2fs: add ioctl to do gc with target block address f2fs: don't need to check encrypted inode for partial truncation f2fs: measure inode.i_blocks as generic filesystem f2fs: set CP_TRIMMED_FLAG correctly f2fs: require key for truncate(2) of encrypted file f2fs: move sysfs code from super.c to fs/f2fs/sysfs.c ...
-rw-r--r--Documentation/ABI/testing/sysfs-fs-f2fs20
-rw-r--r--Documentation/filesystems/f2fs.txt4
-rw-r--r--fs/f2fs/Makefile2
-rw-r--r--fs/f2fs/acl.c2
-rw-r--r--fs/f2fs/checkpoint.c33
-rw-r--r--fs/f2fs/data.c215
-rw-r--r--fs/f2fs/dir.c3
-rw-r--r--fs/f2fs/extent_cache.c12
-rw-r--r--fs/f2fs/f2fs.h201
-rw-r--r--fs/f2fs/file.c183
-rw-r--r--fs/f2fs/gc.c40
-rw-r--r--fs/f2fs/inline.c22
-rw-r--r--fs/f2fs/inode.c17
-rw-r--r--fs/f2fs/namei.c71
-rw-r--r--fs/f2fs/node.c67
-rw-r--r--fs/f2fs/node.h6
-rw-r--r--fs/f2fs/segment.c236
-rw-r--r--fs/f2fs/segment.h4
-rw-r--r--fs/f2fs/super.c705
-rw-r--r--fs/f2fs/sysfs.c364
-rw-r--r--include/trace/events/f2fs.h16
21 files changed, 1559 insertions, 664 deletions
diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs
index a809f6005f14..84c606fb3ca4 100644
--- a/Documentation/ABI/testing/sysfs-fs-f2fs
+++ b/Documentation/ABI/testing/sysfs-fs-f2fs
@@ -75,7 +75,7 @@ Contact: "Jaegeuk Kim" <jaegeuk.kim@samsung.com>
75Description: 75Description:
76 Controls the memory footprint used by f2fs. 76 Controls the memory footprint used by f2fs.
77 77
78What: /sys/fs/f2fs/<disk>/trim_sections 78What: /sys/fs/f2fs/<disk>/batched_trim_sections
79Date: February 2015 79Date: February 2015
80Contact: "Jaegeuk Kim" <jaegeuk@kernel.org> 80Contact: "Jaegeuk Kim" <jaegeuk@kernel.org>
81Description: 81Description:
@@ -112,3 +112,21 @@ Date: January 2016
112Contact: "Shuoran Liu" <liushuoran@huawei.com> 112Contact: "Shuoran Liu" <liushuoran@huawei.com>
113Description: 113Description:
114 Shows total written kbytes issued to disk. 114 Shows total written kbytes issued to disk.
115
116What: /sys/fs/f2fs/<disk>/inject_rate
117Date: May 2016
118Contact: "Sheng Yong" <shengyong1@huawei.com>
119Description:
120 Controls the injection rate.
121
122What: /sys/fs/f2fs/<disk>/inject_type
123Date: May 2016
124Contact: "Sheng Yong" <shengyong1@huawei.com>
125Description:
126 Controls the injection type.
127
128What: /sys/fs/f2fs/<disk>/reserved_blocks
129Date: June 2017
130Contact: "Chao Yu" <yuchao0@huawei.com>
131Description:
132 Controls current reserved blocks in system.
diff --git a/Documentation/filesystems/f2fs.txt b/Documentation/filesystems/f2fs.txt
index 4f6531a4701b..273ccb26885e 100644
--- a/Documentation/filesystems/f2fs.txt
+++ b/Documentation/filesystems/f2fs.txt
@@ -155,11 +155,15 @@ noinline_data Disable the inline data feature, inline data feature is
155 enabled by default. 155 enabled by default.
156data_flush Enable data flushing before checkpoint in order to 156data_flush Enable data flushing before checkpoint in order to
157 persist data of regular and symlink. 157 persist data of regular and symlink.
158fault_injection=%d Enable fault injection in all supported types with
159 specified injection rate.
158mode=%s Control block allocation mode which supports "adaptive" 160mode=%s Control block allocation mode which supports "adaptive"
159 and "lfs". In "lfs" mode, there should be no random 161 and "lfs". In "lfs" mode, there should be no random
160 writes towards main area. 162 writes towards main area.
161io_bits=%u Set the bit size of write IO requests. It should be set 163io_bits=%u Set the bit size of write IO requests. It should be set
162 with "mode=lfs". 164 with "mode=lfs".
165usrquota Enable plain user disk quota accounting.
166grpquota Enable plain group disk quota accounting.
163 167
164================================================================================ 168================================================================================
165DEBUGFS ENTRIES 169DEBUGFS ENTRIES
diff --git a/fs/f2fs/Makefile b/fs/f2fs/Makefile
index ca949ea7c02f..a0dc559b1b47 100644
--- a/fs/f2fs/Makefile
+++ b/fs/f2fs/Makefile
@@ -2,7 +2,7 @@ obj-$(CONFIG_F2FS_FS) += f2fs.o
2 2
3f2fs-y := dir.o file.o inode.o namei.o hash.o super.o inline.o 3f2fs-y := dir.o file.o inode.o namei.o hash.o super.o inline.o
4f2fs-y += checkpoint.o gc.o data.o node.o segment.o recovery.o 4f2fs-y += checkpoint.o gc.o data.o node.o segment.o recovery.o
5f2fs-y += shrinker.o extent_cache.o 5f2fs-y += shrinker.o extent_cache.o sysfs.o
6f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o 6f2fs-$(CONFIG_F2FS_STAT_FS) += debug.o
7f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o 7f2fs-$(CONFIG_F2FS_FS_XATTR) += xattr.o
8f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o 8f2fs-$(CONFIG_F2FS_FS_POSIX_ACL) += acl.o
diff --git a/fs/f2fs/acl.c b/fs/f2fs/acl.c
index 8f487692c21f..a140c5e3dc54 100644
--- a/fs/f2fs/acl.c
+++ b/fs/f2fs/acl.c
@@ -233,7 +233,7 @@ static int __f2fs_set_acl(struct inode *inode, int type,
233 value = f2fs_acl_to_disk(F2FS_I_SB(inode), acl, &size); 233 value = f2fs_acl_to_disk(F2FS_I_SB(inode), acl, &size);
234 if (IS_ERR(value)) { 234 if (IS_ERR(value)) {
235 clear_inode_flag(inode, FI_ACL_MODE); 235 clear_inode_flag(inode, FI_ACL_MODE);
236 return (int)PTR_ERR(value); 236 return PTR_ERR(value);
237 } 237 }
238 } 238 }
239 239
diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c
index ea9c317b5916..56bbf592e487 100644
--- a/fs/f2fs/checkpoint.c
+++ b/fs/f2fs/checkpoint.c
@@ -31,7 +31,7 @@ void f2fs_stop_checkpoint(struct f2fs_sb_info *sbi, bool end_io)
31 set_ckpt_flags(sbi, CP_ERROR_FLAG); 31 set_ckpt_flags(sbi, CP_ERROR_FLAG);
32 sbi->sb->s_flags |= MS_RDONLY; 32 sbi->sb->s_flags |= MS_RDONLY;
33 if (!end_io) 33 if (!end_io)
34 f2fs_flush_merged_bios(sbi); 34 f2fs_flush_merged_writes(sbi);
35} 35}
36 36
37/* 37/*
@@ -162,6 +162,7 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
162 .op = REQ_OP_READ, 162 .op = REQ_OP_READ,
163 .op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD, 163 .op_flags = sync ? (REQ_META | REQ_PRIO) : REQ_RAHEAD,
164 .encrypted_page = NULL, 164 .encrypted_page = NULL,
165 .in_list = false,
165 }; 166 };
166 struct blk_plug plug; 167 struct blk_plug plug;
167 168
@@ -207,12 +208,10 @@ int ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
207 } 208 }
208 209
209 fio.page = page; 210 fio.page = page;
210 fio.old_blkaddr = fio.new_blkaddr; 211 f2fs_submit_page_bio(&fio);
211 f2fs_submit_page_mbio(&fio);
212 f2fs_put_page(page, 0); 212 f2fs_put_page(page, 0);
213 } 213 }
214out: 214out:
215 f2fs_submit_merged_bio(sbi, META, READ);
216 blk_finish_plug(&plug); 215 blk_finish_plug(&plug);
217 return blkno - start; 216 return blkno - start;
218} 217}
@@ -249,13 +248,13 @@ static int f2fs_write_meta_page(struct page *page,
249 dec_page_count(sbi, F2FS_DIRTY_META); 248 dec_page_count(sbi, F2FS_DIRTY_META);
250 249
251 if (wbc->for_reclaim) 250 if (wbc->for_reclaim)
252 f2fs_submit_merged_bio_cond(sbi, page->mapping->host, 251 f2fs_submit_merged_write_cond(sbi, page->mapping->host,
253 0, page->index, META, WRITE); 252 0, page->index, META);
254 253
255 unlock_page(page); 254 unlock_page(page);
256 255
257 if (unlikely(f2fs_cp_error(sbi))) 256 if (unlikely(f2fs_cp_error(sbi)))
258 f2fs_submit_merged_bio(sbi, META, WRITE); 257 f2fs_submit_merged_write(sbi, META);
259 258
260 return 0; 259 return 0;
261 260
@@ -270,6 +269,9 @@ static int f2fs_write_meta_pages(struct address_space *mapping,
270 struct f2fs_sb_info *sbi = F2FS_M_SB(mapping); 269 struct f2fs_sb_info *sbi = F2FS_M_SB(mapping);
271 long diff, written; 270 long diff, written;
272 271
272 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
273 goto skip_write;
274
273 /* collect a number of dirty meta pages and write together */ 275 /* collect a number of dirty meta pages and write together */
274 if (wbc->for_kupdate || 276 if (wbc->for_kupdate ||
275 get_pages(sbi, F2FS_DIRTY_META) < nr_pages_to_skip(sbi, META)) 277 get_pages(sbi, F2FS_DIRTY_META) < nr_pages_to_skip(sbi, META))
@@ -358,7 +360,7 @@ continue_unlock:
358 } 360 }
359stop: 361stop:
360 if (nwritten) 362 if (nwritten)
361 f2fs_submit_merged_bio(sbi, type, WRITE); 363 f2fs_submit_merged_write(sbi, type);
362 364
363 blk_finish_plug(&plug); 365 blk_finish_plug(&plug);
364 366
@@ -906,7 +908,7 @@ retry:
906 * We should submit bio, since it exists several 908 * We should submit bio, since it exists several
907 * wribacking dentry pages in the freeing inode. 909 * wribacking dentry pages in the freeing inode.
908 */ 910 */
909 f2fs_submit_merged_bio(sbi, DATA, WRITE); 911 f2fs_submit_merged_write(sbi, DATA);
910 cond_resched(); 912 cond_resched();
911 } 913 }
912 goto retry; 914 goto retry;
@@ -1051,8 +1053,9 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1051{ 1053{
1052 unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num; 1054 unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num;
1053 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1055 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1056 unsigned long flags;
1054 1057
1055 spin_lock(&sbi->cp_lock); 1058 spin_lock_irqsave(&sbi->cp_lock, flags);
1056 1059
1057 if ((cpc->reason & CP_UMOUNT) && 1060 if ((cpc->reason & CP_UMOUNT) &&
1058 le32_to_cpu(ckpt->cp_pack_total_block_count) > 1061 le32_to_cpu(ckpt->cp_pack_total_block_count) >
@@ -1083,14 +1086,14 @@ static void update_ckpt_flags(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1083 /* set this flag to activate crc|cp_ver for recovery */ 1086 /* set this flag to activate crc|cp_ver for recovery */
1084 __set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG); 1087 __set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG);
1085 1088
1086 spin_unlock(&sbi->cp_lock); 1089 spin_unlock_irqrestore(&sbi->cp_lock, flags);
1087} 1090}
1088 1091
1089static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) 1092static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1090{ 1093{
1091 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1094 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1092 struct f2fs_nm_info *nm_i = NM_I(sbi); 1095 struct f2fs_nm_info *nm_i = NM_I(sbi);
1093 unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num; 1096 unsigned long orphan_num = sbi->im[ORPHAN_INO].ino_num, flags;
1094 block_t start_blk; 1097 block_t start_blk;
1095 unsigned int data_sum_blocks, orphan_blocks; 1098 unsigned int data_sum_blocks, orphan_blocks;
1096 __u32 crc32 = 0; 1099 __u32 crc32 = 0;
@@ -1132,12 +1135,12 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1132 1135
1133 /* 2 cp + n data seg summary + orphan inode blocks */ 1136 /* 2 cp + n data seg summary + orphan inode blocks */
1134 data_sum_blocks = npages_for_summary_flush(sbi, false); 1137 data_sum_blocks = npages_for_summary_flush(sbi, false);
1135 spin_lock(&sbi->cp_lock); 1138 spin_lock_irqsave(&sbi->cp_lock, flags);
1136 if (data_sum_blocks < NR_CURSEG_DATA_TYPE) 1139 if (data_sum_blocks < NR_CURSEG_DATA_TYPE)
1137 __set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); 1140 __set_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
1138 else 1141 else
1139 __clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); 1142 __clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG);
1140 spin_unlock(&sbi->cp_lock); 1143 spin_unlock_irqrestore(&sbi->cp_lock, flags);
1141 1144
1142 orphan_blocks = GET_ORPHAN_BLOCKS(orphan_num); 1145 orphan_blocks = GET_ORPHAN_BLOCKS(orphan_num);
1143 ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks + 1146 ckpt->cp_pack_start_sum = cpu_to_le32(1 + cp_payload_blks +
@@ -1295,7 +1298,7 @@ int write_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc)
1295 1298
1296 trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish block_ops"); 1299 trace_f2fs_write_checkpoint(sbi->sb, cpc->reason, "finish block_ops");
1297 1300
1298 f2fs_flush_merged_bios(sbi); 1301 f2fs_flush_merged_writes(sbi);
1299 1302
1300 /* this is the case of multiple fstrims without any changes */ 1303 /* this is the case of multiple fstrims without any changes */
1301 if (cpc->reason & CP_DISCARD) { 1304 if (cpc->reason & CP_DISCARD) {
diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
index 36fe82012a33..87c1f4150c64 100644
--- a/fs/f2fs/data.c
+++ b/fs/f2fs/data.c
@@ -282,29 +282,32 @@ static bool has_merged_page(struct f2fs_sb_info *sbi, struct inode *inode,
282 nid_t ino, pgoff_t idx, enum page_type type) 282 nid_t ino, pgoff_t idx, enum page_type type)
283{ 283{
284 enum page_type btype = PAGE_TYPE_OF_BIO(type); 284 enum page_type btype = PAGE_TYPE_OF_BIO(type);
285 struct f2fs_bio_info *io = &sbi->write_io[btype]; 285 enum temp_type temp;
286 bool ret; 286 struct f2fs_bio_info *io;
287 bool ret = false;
288
289 for (temp = HOT; temp < NR_TEMP_TYPE; temp++) {
290 io = sbi->write_io[btype] + temp;
291
292 down_read(&io->io_rwsem);
293 ret = __has_merged_page(io, inode, ino, idx);
294 up_read(&io->io_rwsem);
287 295
288 down_read(&io->io_rwsem); 296 /* TODO: use HOT temp only for meta pages now. */
289 ret = __has_merged_page(io, inode, ino, idx); 297 if (ret || btype == META)
290 up_read(&io->io_rwsem); 298 break;
299 }
291 return ret; 300 return ret;
292} 301}
293 302
294static void __f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, 303static void __f2fs_submit_merged_write(struct f2fs_sb_info *sbi,
295 struct inode *inode, nid_t ino, pgoff_t idx, 304 enum page_type type, enum temp_type temp)
296 enum page_type type, int rw)
297{ 305{
298 enum page_type btype = PAGE_TYPE_OF_BIO(type); 306 enum page_type btype = PAGE_TYPE_OF_BIO(type);
299 struct f2fs_bio_info *io; 307 struct f2fs_bio_info *io = sbi->write_io[btype] + temp;
300
301 io = is_read_io(rw) ? &sbi->read_io : &sbi->write_io[btype];
302 308
303 down_write(&io->io_rwsem); 309 down_write(&io->io_rwsem);
304 310
305 if (!__has_merged_page(io, inode, ino, idx))
306 goto out;
307
308 /* change META to META_FLUSH in the checkpoint procedure */ 311 /* change META to META_FLUSH in the checkpoint procedure */
309 if (type >= META_FLUSH) { 312 if (type >= META_FLUSH) {
310 io->fio.type = META_FLUSH; 313 io->fio.type = META_FLUSH;
@@ -314,29 +317,45 @@ static void __f2fs_submit_merged_bio(struct f2fs_sb_info *sbi,
314 io->fio.op_flags |= REQ_PREFLUSH | REQ_FUA; 317 io->fio.op_flags |= REQ_PREFLUSH | REQ_FUA;
315 } 318 }
316 __submit_merged_bio(io); 319 __submit_merged_bio(io);
317out:
318 up_write(&io->io_rwsem); 320 up_write(&io->io_rwsem);
319} 321}
320 322
321void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 323static void __submit_merged_write_cond(struct f2fs_sb_info *sbi,
322 int rw) 324 struct inode *inode, nid_t ino, pgoff_t idx,
325 enum page_type type, bool force)
323{ 326{
324 __f2fs_submit_merged_bio(sbi, NULL, 0, 0, type, rw); 327 enum temp_type temp;
328
329 if (!force && !has_merged_page(sbi, inode, ino, idx, type))
330 return;
331
332 for (temp = HOT; temp < NR_TEMP_TYPE; temp++) {
333
334 __f2fs_submit_merged_write(sbi, type, temp);
335
336 /* TODO: use HOT temp only for meta pages now. */
337 if (type >= META)
338 break;
339 }
325} 340}
326 341
327void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, 342void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type)
343{
344 __submit_merged_write_cond(sbi, NULL, 0, 0, type, true);
345}
346
347void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
328 struct inode *inode, nid_t ino, pgoff_t idx, 348 struct inode *inode, nid_t ino, pgoff_t idx,
329 enum page_type type, int rw) 349 enum page_type type)
330{ 350{
331 if (has_merged_page(sbi, inode, ino, idx, type)) 351 __submit_merged_write_cond(sbi, inode, ino, idx, type, false);
332 __f2fs_submit_merged_bio(sbi, inode, ino, idx, type, rw);
333} 352}
334 353
335void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi) 354void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi)
336{ 355{
337 f2fs_submit_merged_bio(sbi, DATA, WRITE); 356 f2fs_submit_merged_write(sbi, DATA);
338 f2fs_submit_merged_bio(sbi, NODE, WRITE); 357 f2fs_submit_merged_write(sbi, NODE);
339 f2fs_submit_merged_bio(sbi, META, WRITE); 358 f2fs_submit_merged_write(sbi, META);
340} 359}
341 360
342/* 361/*
@@ -368,16 +387,29 @@ int f2fs_submit_page_bio(struct f2fs_io_info *fio)
368 return 0; 387 return 0;
369} 388}
370 389
371int f2fs_submit_page_mbio(struct f2fs_io_info *fio) 390int f2fs_submit_page_write(struct f2fs_io_info *fio)
372{ 391{
373 struct f2fs_sb_info *sbi = fio->sbi; 392 struct f2fs_sb_info *sbi = fio->sbi;
374 enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); 393 enum page_type btype = PAGE_TYPE_OF_BIO(fio->type);
375 struct f2fs_bio_info *io; 394 struct f2fs_bio_info *io = sbi->write_io[btype] + fio->temp;
376 bool is_read = is_read_io(fio->op);
377 struct page *bio_page; 395 struct page *bio_page;
378 int err = 0; 396 int err = 0;
379 397
380 io = is_read ? &sbi->read_io : &sbi->write_io[btype]; 398 f2fs_bug_on(sbi, is_read_io(fio->op));
399
400 down_write(&io->io_rwsem);
401next:
402 if (fio->in_list) {
403 spin_lock(&io->io_lock);
404 if (list_empty(&io->io_list)) {
405 spin_unlock(&io->io_lock);
406 goto out_fail;
407 }
408 fio = list_first_entry(&io->io_list,
409 struct f2fs_io_info, list);
410 list_del(&fio->list);
411 spin_unlock(&io->io_lock);
412 }
381 413
382 if (fio->old_blkaddr != NEW_ADDR) 414 if (fio->old_blkaddr != NEW_ADDR)
383 verify_block_addr(sbi, fio->old_blkaddr); 415 verify_block_addr(sbi, fio->old_blkaddr);
@@ -388,10 +420,7 @@ int f2fs_submit_page_mbio(struct f2fs_io_info *fio)
388 /* set submitted = 1 as a return value */ 420 /* set submitted = 1 as a return value */
389 fio->submitted = 1; 421 fio->submitted = 1;
390 422
391 if (!is_read) 423 inc_page_count(sbi, WB_DATA_TYPE(bio_page));
392 inc_page_count(sbi, WB_DATA_TYPE(bio_page));
393
394 down_write(&io->io_rwsem);
395 424
396 if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 || 425 if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 ||
397 (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) || 426 (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags) ||
@@ -402,26 +431,28 @@ alloc_new:
402 if ((fio->type == DATA || fio->type == NODE) && 431 if ((fio->type == DATA || fio->type == NODE) &&
403 fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) { 432 fio->new_blkaddr & F2FS_IO_SIZE_MASK(sbi)) {
404 err = -EAGAIN; 433 err = -EAGAIN;
405 if (!is_read) 434 dec_page_count(sbi, WB_DATA_TYPE(bio_page));
406 dec_page_count(sbi, WB_DATA_TYPE(bio_page));
407 goto out_fail; 435 goto out_fail;
408 } 436 }
409 io->bio = __bio_alloc(sbi, fio->new_blkaddr, 437 io->bio = __bio_alloc(sbi, fio->new_blkaddr,
410 BIO_MAX_PAGES, is_read); 438 BIO_MAX_PAGES, false);
411 io->fio = *fio; 439 io->fio = *fio;
412 } 440 }
413 441
414 if (bio_add_page(io->bio, bio_page, PAGE_SIZE, 0) < 442 if (bio_add_page(io->bio, bio_page, PAGE_SIZE, 0) < PAGE_SIZE) {
415 PAGE_SIZE) {
416 __submit_merged_bio(io); 443 __submit_merged_bio(io);
417 goto alloc_new; 444 goto alloc_new;
418 } 445 }
419 446
420 io->last_block_in_bio = fio->new_blkaddr; 447 io->last_block_in_bio = fio->new_blkaddr;
421 f2fs_trace_ios(fio, 0); 448 f2fs_trace_ios(fio, 0);
449
450 trace_f2fs_submit_page_write(fio->page, fio);
451
452 if (fio->in_list)
453 goto next;
422out_fail: 454out_fail:
423 up_write(&io->io_rwsem); 455 up_write(&io->io_rwsem);
424 trace_f2fs_submit_page_mbio(fio->page, fio);
425 return err; 456 return err;
426} 457}
427 458
@@ -460,14 +491,15 @@ void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr)
460int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count) 491int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count)
461{ 492{
462 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); 493 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
494 int err;
463 495
464 if (!count) 496 if (!count)
465 return 0; 497 return 0;
466 498
467 if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC))) 499 if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC)))
468 return -EPERM; 500 return -EPERM;
469 if (unlikely(!inc_valid_block_count(sbi, dn->inode, &count))) 501 if (unlikely((err = inc_valid_block_count(sbi, dn->inode, &count))))
470 return -ENOSPC; 502 return err;
471 503
472 trace_f2fs_reserve_new_blocks(dn->inode, dn->nid, 504 trace_f2fs_reserve_new_blocks(dn->inode, dn->nid,
473 dn->ofs_in_node, count); 505 dn->ofs_in_node, count);
@@ -718,6 +750,7 @@ static int __allocate_data_block(struct dnode_of_data *dn)
718 struct node_info ni; 750 struct node_info ni;
719 pgoff_t fofs; 751 pgoff_t fofs;
720 blkcnt_t count = 1; 752 blkcnt_t count = 1;
753 int err;
721 754
722 if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC))) 755 if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC)))
723 return -EPERM; 756 return -EPERM;
@@ -726,15 +759,15 @@ static int __allocate_data_block(struct dnode_of_data *dn)
726 if (dn->data_blkaddr == NEW_ADDR) 759 if (dn->data_blkaddr == NEW_ADDR)
727 goto alloc; 760 goto alloc;
728 761
729 if (unlikely(!inc_valid_block_count(sbi, dn->inode, &count))) 762 if (unlikely((err = inc_valid_block_count(sbi, dn->inode, &count))))
730 return -ENOSPC; 763 return err;
731 764
732alloc: 765alloc:
733 get_node_info(sbi, dn->nid, &ni); 766 get_node_info(sbi, dn->nid, &ni);
734 set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); 767 set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
735 768
736 allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr, 769 allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr,
737 &sum, CURSEG_WARM_DATA); 770 &sum, CURSEG_WARM_DATA, NULL, false);
738 set_data_blkaddr(dn); 771 set_data_blkaddr(dn);
739 772
740 /* update i_size */ 773 /* update i_size */
@@ -1321,7 +1354,7 @@ retry_encrypt:
1321 1354
1322 /* flush pending IOs and wait for a while in the ENOMEM case */ 1355 /* flush pending IOs and wait for a while in the ENOMEM case */
1323 if (PTR_ERR(fio->encrypted_page) == -ENOMEM) { 1356 if (PTR_ERR(fio->encrypted_page) == -ENOMEM) {
1324 f2fs_flush_merged_bios(fio->sbi); 1357 f2fs_flush_merged_writes(fio->sbi);
1325 congestion_wait(BLK_RW_ASYNC, HZ/50); 1358 congestion_wait(BLK_RW_ASYNC, HZ/50);
1326 gfp_flags |= __GFP_NOFAIL; 1359 gfp_flags |= __GFP_NOFAIL;
1327 goto retry_encrypt; 1360 goto retry_encrypt;
@@ -1368,13 +1401,14 @@ int do_write_data_page(struct f2fs_io_info *fio)
1368 1401
1369 if (valid_ipu_blkaddr(fio)) { 1402 if (valid_ipu_blkaddr(fio)) {
1370 ipu_force = true; 1403 ipu_force = true;
1371 fio->need_lock = false; 1404 fio->need_lock = LOCK_DONE;
1372 goto got_it; 1405 goto got_it;
1373 } 1406 }
1374 } 1407 }
1375 1408
1376 if (fio->need_lock) 1409 /* Deadlock due to between page->lock and f2fs_lock_op */
1377 f2fs_lock_op(fio->sbi); 1410 if (fio->need_lock == LOCK_REQ && !f2fs_trylock_op(fio->sbi))
1411 return -EAGAIN;
1378 1412
1379 err = get_dnode_of_data(&dn, page->index, LOOKUP_NODE); 1413 err = get_dnode_of_data(&dn, page->index, LOOKUP_NODE);
1380 if (err) 1414 if (err)
@@ -1388,19 +1422,18 @@ int do_write_data_page(struct f2fs_io_info *fio)
1388 goto out_writepage; 1422 goto out_writepage;
1389 } 1423 }
1390got_it: 1424got_it:
1391 err = encrypt_one_page(fio);
1392 if (err)
1393 goto out_writepage;
1394
1395 set_page_writeback(page);
1396
1397 /* 1425 /*
1398 * If current allocation needs SSR, 1426 * If current allocation needs SSR,
1399 * it had better in-place writes for updated data. 1427 * it had better in-place writes for updated data.
1400 */ 1428 */
1401 if (ipu_force || (valid_ipu_blkaddr(fio) && need_inplace_update(fio))) { 1429 if (ipu_force || (valid_ipu_blkaddr(fio) && need_inplace_update(fio))) {
1430 err = encrypt_one_page(fio);
1431 if (err)
1432 goto out_writepage;
1433
1434 set_page_writeback(page);
1402 f2fs_put_dnode(&dn); 1435 f2fs_put_dnode(&dn);
1403 if (fio->need_lock) 1436 if (fio->need_lock == LOCK_REQ)
1404 f2fs_unlock_op(fio->sbi); 1437 f2fs_unlock_op(fio->sbi);
1405 err = rewrite_data_page(fio); 1438 err = rewrite_data_page(fio);
1406 trace_f2fs_do_write_data_page(fio->page, IPU); 1439 trace_f2fs_do_write_data_page(fio->page, IPU);
@@ -1408,6 +1441,20 @@ got_it:
1408 return err; 1441 return err;
1409 } 1442 }
1410 1443
1444 if (fio->need_lock == LOCK_RETRY) {
1445 if (!f2fs_trylock_op(fio->sbi)) {
1446 err = -EAGAIN;
1447 goto out_writepage;
1448 }
1449 fio->need_lock = LOCK_REQ;
1450 }
1451
1452 err = encrypt_one_page(fio);
1453 if (err)
1454 goto out_writepage;
1455
1456 set_page_writeback(page);
1457
1411 /* LFS mode write path */ 1458 /* LFS mode write path */
1412 write_data_page(&dn, fio); 1459 write_data_page(&dn, fio);
1413 trace_f2fs_do_write_data_page(page, OPU); 1460 trace_f2fs_do_write_data_page(page, OPU);
@@ -1417,7 +1464,7 @@ got_it:
1417out_writepage: 1464out_writepage:
1418 f2fs_put_dnode(&dn); 1465 f2fs_put_dnode(&dn);
1419out: 1466out:
1420 if (fio->need_lock) 1467 if (fio->need_lock == LOCK_REQ)
1421 f2fs_unlock_op(fio->sbi); 1468 f2fs_unlock_op(fio->sbi);
1422 return err; 1469 return err;
1423} 1470}
@@ -1443,11 +1490,14 @@ static int __write_data_page(struct page *page, bool *submitted,
1443 .page = page, 1490 .page = page,
1444 .encrypted_page = NULL, 1491 .encrypted_page = NULL,
1445 .submitted = false, 1492 .submitted = false,
1446 .need_lock = true, 1493 .need_lock = LOCK_RETRY,
1447 }; 1494 };
1448 1495
1449 trace_f2fs_writepage(page, DATA); 1496 trace_f2fs_writepage(page, DATA);
1450 1497
1498 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
1499 goto redirty_out;
1500
1451 if (page->index < end_index) 1501 if (page->index < end_index)
1452 goto write; 1502 goto write;
1453 1503
@@ -1461,8 +1511,6 @@ static int __write_data_page(struct page *page, bool *submitted,
1461 1511
1462 zero_user_segment(page, offset, PAGE_SIZE); 1512 zero_user_segment(page, offset, PAGE_SIZE);
1463write: 1513write:
1464 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
1465 goto redirty_out;
1466 if (f2fs_is_drop_cache(inode)) 1514 if (f2fs_is_drop_cache(inode))
1467 goto out; 1515 goto out;
1468 /* we should not write 0'th page having journal header */ 1516 /* we should not write 0'th page having journal header */
@@ -1479,7 +1527,7 @@ write:
1479 1527
1480 /* Dentry blocks are controlled by checkpoint */ 1528 /* Dentry blocks are controlled by checkpoint */
1481 if (S_ISDIR(inode->i_mode)) { 1529 if (S_ISDIR(inode->i_mode)) {
1482 fio.need_lock = false; 1530 fio.need_lock = LOCK_DONE;
1483 err = do_write_data_page(&fio); 1531 err = do_write_data_page(&fio);
1484 goto done; 1532 goto done;
1485 } 1533 }
@@ -1498,8 +1546,13 @@ write:
1498 goto out; 1546 goto out;
1499 } 1547 }
1500 1548
1501 if (err == -EAGAIN) 1549 if (err == -EAGAIN) {
1502 err = do_write_data_page(&fio); 1550 err = do_write_data_page(&fio);
1551 if (err == -EAGAIN) {
1552 fio.need_lock = LOCK_REQ;
1553 err = do_write_data_page(&fio);
1554 }
1555 }
1503 if (F2FS_I(inode)->last_disk_size < psize) 1556 if (F2FS_I(inode)->last_disk_size < psize)
1504 F2FS_I(inode)->last_disk_size = psize; 1557 F2FS_I(inode)->last_disk_size = psize;
1505 1558
@@ -1513,8 +1566,7 @@ out:
1513 ClearPageUptodate(page); 1566 ClearPageUptodate(page);
1514 1567
1515 if (wbc->for_reclaim) { 1568 if (wbc->for_reclaim) {
1516 f2fs_submit_merged_bio_cond(sbi, inode, 0, page->index, 1569 f2fs_submit_merged_write_cond(sbi, inode, 0, page->index, DATA);
1517 DATA, WRITE);
1518 clear_inode_flag(inode, FI_HOT_DATA); 1570 clear_inode_flag(inode, FI_HOT_DATA);
1519 remove_dirty_inode(inode); 1571 remove_dirty_inode(inode);
1520 submitted = NULL; 1572 submitted = NULL;
@@ -1525,7 +1577,7 @@ out:
1525 f2fs_balance_fs(sbi, need_balance_fs); 1577 f2fs_balance_fs(sbi, need_balance_fs);
1526 1578
1527 if (unlikely(f2fs_cp_error(sbi))) { 1579 if (unlikely(f2fs_cp_error(sbi))) {
1528 f2fs_submit_merged_bio(sbi, DATA, WRITE); 1580 f2fs_submit_merged_write(sbi, DATA);
1529 submitted = NULL; 1581 submitted = NULL;
1530 } 1582 }
1531 1583
@@ -1618,7 +1670,7 @@ retry:
1618 } 1670 }
1619 1671
1620 done_index = page->index; 1672 done_index = page->index;
1621 1673retry_write:
1622 lock_page(page); 1674 lock_page(page);
1623 1675
1624 if (unlikely(page->mapping != mapping)) { 1676 if (unlikely(page->mapping != mapping)) {
@@ -1654,6 +1706,15 @@ continue_unlock:
1654 unlock_page(page); 1706 unlock_page(page);
1655 ret = 0; 1707 ret = 0;
1656 continue; 1708 continue;
1709 } else if (ret == -EAGAIN) {
1710 ret = 0;
1711 if (wbc->sync_mode == WB_SYNC_ALL) {
1712 cond_resched();
1713 congestion_wait(BLK_RW_ASYNC,
1714 HZ/50);
1715 goto retry_write;
1716 }
1717 continue;
1657 } 1718 }
1658 done_index = page->index + 1; 1719 done_index = page->index + 1;
1659 done = 1; 1720 done = 1;
@@ -1684,8 +1745,8 @@ continue_unlock:
1684 mapping->writeback_index = done_index; 1745 mapping->writeback_index = done_index;
1685 1746
1686 if (last_idx != ULONG_MAX) 1747 if (last_idx != ULONG_MAX)
1687 f2fs_submit_merged_bio_cond(F2FS_M_SB(mapping), mapping->host, 1748 f2fs_submit_merged_write_cond(F2FS_M_SB(mapping), mapping->host,
1688 0, last_idx, DATA, WRITE); 1749 0, last_idx, DATA);
1689 1750
1690 return ret; 1751 return ret;
1691} 1752}
@@ -1706,6 +1767,10 @@ static int f2fs_write_data_pages(struct address_space *mapping,
1706 if (!get_dirty_pages(inode) && wbc->sync_mode == WB_SYNC_NONE) 1767 if (!get_dirty_pages(inode) && wbc->sync_mode == WB_SYNC_NONE)
1707 return 0; 1768 return 0;
1708 1769
1770 /* during POR, we don't need to trigger writepage at all. */
1771 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
1772 goto skip_write;
1773
1709 if (S_ISDIR(inode->i_mode) && wbc->sync_mode == WB_SYNC_NONE && 1774 if (S_ISDIR(inode->i_mode) && wbc->sync_mode == WB_SYNC_NONE &&
1710 get_dirty_pages(inode) < nr_pages_to_skip(sbi, DATA) && 1775 get_dirty_pages(inode) < nr_pages_to_skip(sbi, DATA) &&
1711 available_free_memory(sbi, DIRTY_DENTS)) 1776 available_free_memory(sbi, DIRTY_DENTS))
@@ -1715,10 +1780,6 @@ static int f2fs_write_data_pages(struct address_space *mapping,
1715 if (is_inode_flag_set(inode, FI_DO_DEFRAG)) 1780 if (is_inode_flag_set(inode, FI_DO_DEFRAG))
1716 goto skip_write; 1781 goto skip_write;
1717 1782
1718 /* during POR, we don't need to trigger writepage at all. */
1719 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
1720 goto skip_write;
1721
1722 trace_f2fs_writepages(mapping->host, wbc, DATA); 1783 trace_f2fs_writepages(mapping->host, wbc, DATA);
1723 1784
1724 /* to avoid spliting IOs due to mixed WB_SYNC_ALL and WB_SYNC_NONE */ 1785 /* to avoid spliting IOs due to mixed WB_SYNC_ALL and WB_SYNC_NONE */
@@ -1753,8 +1814,10 @@ static void f2fs_write_failed(struct address_space *mapping, loff_t to)
1753 loff_t i_size = i_size_read(inode); 1814 loff_t i_size = i_size_read(inode);
1754 1815
1755 if (to > i_size) { 1816 if (to > i_size) {
1817 down_write(&F2FS_I(inode)->i_mmap_sem);
1756 truncate_pagecache(inode, i_size); 1818 truncate_pagecache(inode, i_size);
1757 truncate_blocks(inode, i_size, true); 1819 truncate_blocks(inode, i_size, true);
1820 up_write(&F2FS_I(inode)->i_mmap_sem);
1758 } 1821 }
1759} 1822}
1760 1823
@@ -2152,8 +2215,12 @@ int f2fs_migrate_page(struct address_space *mapping,
2152 BUG_ON(PageWriteback(page)); 2215 BUG_ON(PageWriteback(page));
2153 2216
2154 /* migrating an atomic written page is safe with the inmem_lock hold */ 2217 /* migrating an atomic written page is safe with the inmem_lock hold */
2155 if (atomic_written && !mutex_trylock(&fi->inmem_lock)) 2218 if (atomic_written) {
2156 return -EAGAIN; 2219 if (mode != MIGRATE_SYNC)
2220 return -EBUSY;
2221 if (!mutex_trylock(&fi->inmem_lock))
2222 return -EAGAIN;
2223 }
2157 2224
2158 /* 2225 /*
2159 * A reference is expected if PagePrivate set when move mapping, 2226 * A reference is expected if PagePrivate set when move mapping,
diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c
index 94756f55a97e..37f9c7f55605 100644
--- a/fs/f2fs/dir.c
+++ b/fs/f2fs/dir.c
@@ -415,7 +415,8 @@ struct page *init_inode_metadata(struct inode *inode, struct inode *dir,
415 * We lost i_pino from now on. 415 * We lost i_pino from now on.
416 */ 416 */
417 if (is_inode_flag_set(inode, FI_INC_LINK)) { 417 if (is_inode_flag_set(inode, FI_INC_LINK)) {
418 file_lost_pino(inode); 418 if (!S_ISDIR(inode->i_mode))
419 file_lost_pino(inode);
419 /* 420 /*
420 * If link the tmpfile to alias through linkat path, 421 * If link the tmpfile to alias through linkat path,
421 * we should remove this inode from orphan list. 422 * we should remove this inode from orphan list.
diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index 2f98d7039701..ff2352a0ed15 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -320,7 +320,7 @@ static void __drop_largest_extent(struct inode *inode,
320} 320}
321 321
322/* return true, if inode page is changed */ 322/* return true, if inode page is changed */
323bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext) 323static bool __f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext)
324{ 324{
325 struct f2fs_sb_info *sbi = F2FS_I_SB(inode); 325 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
326 struct extent_tree *et; 326 struct extent_tree *et;
@@ -358,6 +358,16 @@ out:
358 return false; 358 return false;
359} 359}
360 360
361bool f2fs_init_extent_tree(struct inode *inode, struct f2fs_extent *i_ext)
362{
363 bool ret = __f2fs_init_extent_tree(inode, i_ext);
364
365 if (!F2FS_I(inode)->extent_tree)
366 set_inode_flag(inode, FI_NO_EXTENT);
367
368 return ret;
369}
370
361static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs, 371static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,
362 struct extent_info *ei) 372 struct extent_info *ei)
363{ 373{
diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h
index fd2e651bad6d..94a88b233e98 100644
--- a/fs/f2fs/f2fs.h
+++ b/fs/f2fs/f2fs.h
@@ -22,6 +22,7 @@
22#include <linux/vmalloc.h> 22#include <linux/vmalloc.h>
23#include <linux/bio.h> 23#include <linux/bio.h>
24#include <linux/blkdev.h> 24#include <linux/blkdev.h>
25#include <linux/quotaops.h>
25#ifdef CONFIG_F2FS_FS_ENCRYPTION 26#ifdef CONFIG_F2FS_FS_ENCRYPTION
26#include <linux/fscrypt_supp.h> 27#include <linux/fscrypt_supp.h>
27#else 28#else
@@ -88,6 +89,8 @@ extern char *fault_name[FAULT_MAX];
88#define F2FS_MOUNT_FAULT_INJECTION 0x00010000 89#define F2FS_MOUNT_FAULT_INJECTION 0x00010000
89#define F2FS_MOUNT_ADAPTIVE 0x00020000 90#define F2FS_MOUNT_ADAPTIVE 0x00020000
90#define F2FS_MOUNT_LFS 0x00040000 91#define F2FS_MOUNT_LFS 0x00040000
92#define F2FS_MOUNT_USRQUOTA 0x00080000
93#define F2FS_MOUNT_GRPQUOTA 0x00100000
91 94
92#define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option) 95#define clear_opt(sbi, option) ((sbi)->mount_opt.opt &= ~F2FS_MOUNT_##option)
93#define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option) 96#define set_opt(sbi, option) ((sbi)->mount_opt.opt |= F2FS_MOUNT_##option)
@@ -303,6 +306,8 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal,
303 struct f2fs_move_range) 306 struct f2fs_move_range)
304#define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \ 307#define F2FS_IOC_FLUSH_DEVICE _IOW(F2FS_IOCTL_MAGIC, 10, \
305 struct f2fs_flush_device) 308 struct f2fs_flush_device)
309#define F2FS_IOC_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11, \
310 struct f2fs_gc_range)
306 311
307#define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY 312#define F2FS_IOC_SET_ENCRYPTION_POLICY FS_IOC_SET_ENCRYPTION_POLICY
308#define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY 313#define F2FS_IOC_GET_ENCRYPTION_POLICY FS_IOC_GET_ENCRYPTION_POLICY
@@ -327,6 +332,12 @@ static inline bool __has_cursum_space(struct f2fs_journal *journal,
327#define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION 332#define F2FS_IOC32_GETVERSION FS_IOC32_GETVERSION
328#endif 333#endif
329 334
335struct f2fs_gc_range {
336 u32 sync;
337 u64 start;
338 u64 len;
339};
340
330struct f2fs_defragment { 341struct f2fs_defragment {
331 u64 start; 342 u64 start;
332 u64 len; 343 u64 len;
@@ -513,12 +524,19 @@ struct f2fs_inode_info {
513 nid_t i_xattr_nid; /* node id that contains xattrs */ 524 nid_t i_xattr_nid; /* node id that contains xattrs */
514 loff_t last_disk_size; /* lastly written file size */ 525 loff_t last_disk_size; /* lastly written file size */
515 526
527#ifdef CONFIG_QUOTA
528 struct dquot *i_dquot[MAXQUOTAS];
529
530 /* quota space reservation, managed internally by quota code */
531 qsize_t i_reserved_quota;
532#endif
516 struct list_head dirty_list; /* dirty list for dirs and files */ 533 struct list_head dirty_list; /* dirty list for dirs and files */
517 struct list_head gdirty_list; /* linked in global dirty list */ 534 struct list_head gdirty_list; /* linked in global dirty list */
518 struct list_head inmem_pages; /* inmemory pages managed by f2fs */ 535 struct list_head inmem_pages; /* inmemory pages managed by f2fs */
519 struct mutex inmem_lock; /* lock for inmemory pages */ 536 struct mutex inmem_lock; /* lock for inmemory pages */
520 struct extent_tree *extent_tree; /* cached extent_tree entry */ 537 struct extent_tree *extent_tree; /* cached extent_tree entry */
521 struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */ 538 struct rw_semaphore dio_rwsem[2];/* avoid racing between dio and gc */
539 struct rw_semaphore i_mmap_sem;
522}; 540};
523 541
524static inline void get_extent_info(struct extent_info *ext, 542static inline void get_extent_info(struct extent_info *ext,
@@ -792,17 +810,33 @@ enum page_type {
792 OPU, 810 OPU,
793}; 811};
794 812
813enum temp_type {
814 HOT = 0, /* must be zero for meta bio */
815 WARM,
816 COLD,
817 NR_TEMP_TYPE,
818};
819
820enum need_lock_type {
821 LOCK_REQ = 0,
822 LOCK_DONE,
823 LOCK_RETRY,
824};
825
795struct f2fs_io_info { 826struct f2fs_io_info {
796 struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */ 827 struct f2fs_sb_info *sbi; /* f2fs_sb_info pointer */
797 enum page_type type; /* contains DATA/NODE/META/META_FLUSH */ 828 enum page_type type; /* contains DATA/NODE/META/META_FLUSH */
829 enum temp_type temp; /* contains HOT/WARM/COLD */
798 int op; /* contains REQ_OP_ */ 830 int op; /* contains REQ_OP_ */
799 int op_flags; /* req_flag_bits */ 831 int op_flags; /* req_flag_bits */
800 block_t new_blkaddr; /* new block address to be written */ 832 block_t new_blkaddr; /* new block address to be written */
801 block_t old_blkaddr; /* old block address before Cow */ 833 block_t old_blkaddr; /* old block address before Cow */
802 struct page *page; /* page to be written */ 834 struct page *page; /* page to be written */
803 struct page *encrypted_page; /* encrypted page */ 835 struct page *encrypted_page; /* encrypted page */
836 struct list_head list; /* serialize IOs */
804 bool submitted; /* indicate IO submission */ 837 bool submitted; /* indicate IO submission */
805 bool need_lock; /* indicate we need to lock cp_rwsem */ 838 int need_lock; /* indicate we need to lock cp_rwsem */
839 bool in_list; /* indicate fio is in io_list */
806}; 840};
807 841
808#define is_read_io(rw) ((rw) == READ) 842#define is_read_io(rw) ((rw) == READ)
@@ -812,6 +846,8 @@ struct f2fs_bio_info {
812 sector_t last_block_in_bio; /* last block number */ 846 sector_t last_block_in_bio; /* last block number */
813 struct f2fs_io_info fio; /* store buffered io info. */ 847 struct f2fs_io_info fio; /* store buffered io info. */
814 struct rw_semaphore io_rwsem; /* blocking op for bio */ 848 struct rw_semaphore io_rwsem; /* blocking op for bio */
849 spinlock_t io_lock; /* serialize DATA/NODE IOs */
850 struct list_head io_list; /* track fios */
815}; 851};
816 852
817#define FDEV(i) (sbi->devs[i]) 853#define FDEV(i) (sbi->devs[i])
@@ -879,9 +915,9 @@ struct f2fs_sb_info {
879 struct f2fs_sm_info *sm_info; /* segment manager */ 915 struct f2fs_sm_info *sm_info; /* segment manager */
880 916
881 /* for bio operations */ 917 /* for bio operations */
882 struct f2fs_bio_info read_io; /* for read bios */ 918 struct f2fs_bio_info *write_io[NR_PAGE_TYPE]; /* for write bios */
883 struct f2fs_bio_info write_io[NR_PAGE_TYPE]; /* for write bios */ 919 struct mutex wio_mutex[NR_PAGE_TYPE - 1][NR_TEMP_TYPE];
884 struct mutex wio_mutex[NODE + 1]; /* bio ordering for NODE/DATA */ 920 /* bio ordering for NODE/DATA */
885 int write_io_size_bits; /* Write IO size bits */ 921 int write_io_size_bits; /* Write IO size bits */
886 mempool_t *write_io_dummy; /* Dummy pages */ 922 mempool_t *write_io_dummy; /* Dummy pages */
887 923
@@ -939,6 +975,8 @@ struct f2fs_sb_info {
939 block_t total_valid_block_count; /* # of valid blocks */ 975 block_t total_valid_block_count; /* # of valid blocks */
940 block_t discard_blks; /* discard command candidats */ 976 block_t discard_blks; /* discard command candidats */
941 block_t last_valid_block_count; /* for recovery */ 977 block_t last_valid_block_count; /* for recovery */
978 block_t reserved_blocks; /* configurable reserved blocks */
979
942 u32 s_next_generation; /* for NFS support */ 980 u32 s_next_generation; /* for NFS support */
943 981
944 /* # of pages, see count_type */ 982 /* # of pages, see count_type */
@@ -1228,9 +1266,11 @@ static inline void __set_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
1228 1266
1229static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1267static inline void set_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
1230{ 1268{
1231 spin_lock(&sbi->cp_lock); 1269 unsigned long flags;
1270
1271 spin_lock_irqsave(&sbi->cp_lock, flags);
1232 __set_ckpt_flags(F2FS_CKPT(sbi), f); 1272 __set_ckpt_flags(F2FS_CKPT(sbi), f);
1233 spin_unlock(&sbi->cp_lock); 1273 spin_unlock_irqrestore(&sbi->cp_lock, flags);
1234} 1274}
1235 1275
1236static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f) 1276static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f)
@@ -1244,22 +1284,26 @@ static inline void __clear_ckpt_flags(struct f2fs_checkpoint *cp, unsigned int f
1244 1284
1245static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f) 1285static inline void clear_ckpt_flags(struct f2fs_sb_info *sbi, unsigned int f)
1246{ 1286{
1247 spin_lock(&sbi->cp_lock); 1287 unsigned long flags;
1288
1289 spin_lock_irqsave(&sbi->cp_lock, flags);
1248 __clear_ckpt_flags(F2FS_CKPT(sbi), f); 1290 __clear_ckpt_flags(F2FS_CKPT(sbi), f);
1249 spin_unlock(&sbi->cp_lock); 1291 spin_unlock_irqrestore(&sbi->cp_lock, flags);
1250} 1292}
1251 1293
1252static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock) 1294static inline void disable_nat_bits(struct f2fs_sb_info *sbi, bool lock)
1253{ 1295{
1296 unsigned long flags;
1297
1254 set_sbi_flag(sbi, SBI_NEED_FSCK); 1298 set_sbi_flag(sbi, SBI_NEED_FSCK);
1255 1299
1256 if (lock) 1300 if (lock)
1257 spin_lock(&sbi->cp_lock); 1301 spin_lock_irqsave(&sbi->cp_lock, flags);
1258 __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG); 1302 __clear_ckpt_flags(F2FS_CKPT(sbi), CP_NAT_BITS_FLAG);
1259 kfree(NM_I(sbi)->nat_bits); 1303 kfree(NM_I(sbi)->nat_bits);
1260 NM_I(sbi)->nat_bits = NULL; 1304 NM_I(sbi)->nat_bits = NULL;
1261 if (lock) 1305 if (lock)
1262 spin_unlock(&sbi->cp_lock); 1306 spin_unlock_irqrestore(&sbi->cp_lock, flags);
1263} 1307}
1264 1308
1265static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi, 1309static inline bool enabled_nat_bits(struct f2fs_sb_info *sbi,
@@ -1275,6 +1319,11 @@ static inline void f2fs_lock_op(struct f2fs_sb_info *sbi)
1275 down_read(&sbi->cp_rwsem); 1319 down_read(&sbi->cp_rwsem);
1276} 1320}
1277 1321
1322static inline int f2fs_trylock_op(struct f2fs_sb_info *sbi)
1323{
1324 return down_read_trylock(&sbi->cp_rwsem);
1325}
1326
1278static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi) 1327static inline void f2fs_unlock_op(struct f2fs_sb_info *sbi)
1279{ 1328{
1280 up_read(&sbi->cp_rwsem); 1329 up_read(&sbi->cp_rwsem);
@@ -1324,17 +1373,14 @@ static inline int check_nid_range(struct f2fs_sb_info *sbi, nid_t nid)
1324 return 0; 1373 return 0;
1325} 1374}
1326 1375
1327#define F2FS_DEFAULT_ALLOCATED_BLOCKS 1
1328
1329/* 1376/*
1330 * Check whether the inode has blocks or not 1377 * Check whether the inode has blocks or not
1331 */ 1378 */
1332static inline int F2FS_HAS_BLOCKS(struct inode *inode) 1379static inline int F2FS_HAS_BLOCKS(struct inode *inode)
1333{ 1380{
1334 if (F2FS_I(inode)->i_xattr_nid) 1381 block_t xattr_block = F2FS_I(inode)->i_xattr_nid ? 1 : 0;
1335 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS + 1; 1382
1336 else 1383 return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block;
1337 return inode->i_blocks > F2FS_DEFAULT_ALLOCATED_BLOCKS;
1338} 1384}
1339 1385
1340static inline bool f2fs_has_xattr_block(unsigned int ofs) 1386static inline bool f2fs_has_xattr_block(unsigned int ofs)
@@ -1342,16 +1388,23 @@ static inline bool f2fs_has_xattr_block(unsigned int ofs)
1342 return ofs == XATTR_NODE_OFFSET; 1388 return ofs == XATTR_NODE_OFFSET;
1343} 1389}
1344 1390
1345static inline void f2fs_i_blocks_write(struct inode *, blkcnt_t, bool); 1391static inline void f2fs_i_blocks_write(struct inode *, block_t, bool, bool);
1346static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi, 1392static inline int inc_valid_block_count(struct f2fs_sb_info *sbi,
1347 struct inode *inode, blkcnt_t *count) 1393 struct inode *inode, blkcnt_t *count)
1348{ 1394{
1349 blkcnt_t diff; 1395 blkcnt_t diff = 0, release = 0;
1396 block_t avail_user_block_count;
1397 int ret;
1398
1399 ret = dquot_reserve_block(inode, *count);
1400 if (ret)
1401 return ret;
1350 1402
1351#ifdef CONFIG_F2FS_FAULT_INJECTION 1403#ifdef CONFIG_F2FS_FAULT_INJECTION
1352 if (time_to_inject(sbi, FAULT_BLOCK)) { 1404 if (time_to_inject(sbi, FAULT_BLOCK)) {
1353 f2fs_show_injection_info(FAULT_BLOCK); 1405 f2fs_show_injection_info(FAULT_BLOCK);
1354 return false; 1406 release = *count;
1407 goto enospc;
1355 } 1408 }
1356#endif 1409#endif
1357 /* 1410 /*
@@ -1362,32 +1415,42 @@ static inline bool inc_valid_block_count(struct f2fs_sb_info *sbi,
1362 1415
1363 spin_lock(&sbi->stat_lock); 1416 spin_lock(&sbi->stat_lock);
1364 sbi->total_valid_block_count += (block_t)(*count); 1417 sbi->total_valid_block_count += (block_t)(*count);
1365 if (unlikely(sbi->total_valid_block_count > sbi->user_block_count)) { 1418 avail_user_block_count = sbi->user_block_count - sbi->reserved_blocks;
1366 diff = sbi->total_valid_block_count - sbi->user_block_count; 1419 if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) {
1420 diff = sbi->total_valid_block_count - avail_user_block_count;
1367 *count -= diff; 1421 *count -= diff;
1368 sbi->total_valid_block_count = sbi->user_block_count; 1422 release = diff;
1423 sbi->total_valid_block_count = avail_user_block_count;
1369 if (!*count) { 1424 if (!*count) {
1370 spin_unlock(&sbi->stat_lock); 1425 spin_unlock(&sbi->stat_lock);
1371 percpu_counter_sub(&sbi->alloc_valid_block_count, diff); 1426 percpu_counter_sub(&sbi->alloc_valid_block_count, diff);
1372 return false; 1427 goto enospc;
1373 } 1428 }
1374 } 1429 }
1375 spin_unlock(&sbi->stat_lock); 1430 spin_unlock(&sbi->stat_lock);
1376 1431
1377 f2fs_i_blocks_write(inode, *count, true); 1432 if (release)
1378 return true; 1433 dquot_release_reservation_block(inode, release);
1434 f2fs_i_blocks_write(inode, *count, true, true);
1435 return 0;
1436
1437enospc:
1438 dquot_release_reservation_block(inode, release);
1439 return -ENOSPC;
1379} 1440}
1380 1441
1381static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, 1442static inline void dec_valid_block_count(struct f2fs_sb_info *sbi,
1382 struct inode *inode, 1443 struct inode *inode,
1383 blkcnt_t count) 1444 block_t count)
1384{ 1445{
1446 blkcnt_t sectors = count << F2FS_LOG_SECTORS_PER_BLOCK;
1447
1385 spin_lock(&sbi->stat_lock); 1448 spin_lock(&sbi->stat_lock);
1386 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count); 1449 f2fs_bug_on(sbi, sbi->total_valid_block_count < (block_t) count);
1387 f2fs_bug_on(sbi, inode->i_blocks < count); 1450 f2fs_bug_on(sbi, inode->i_blocks < sectors);
1388 sbi->total_valid_block_count -= (block_t)count; 1451 sbi->total_valid_block_count -= (block_t)count;
1389 spin_unlock(&sbi->stat_lock); 1452 spin_unlock(&sbi->stat_lock);
1390 f2fs_i_blocks_write(inode, count, false); 1453 f2fs_i_blocks_write(inode, count, false, true);
1391} 1454}
1392 1455
1393static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type) 1456static inline void inc_page_count(struct f2fs_sb_info *sbi, int count_type)
@@ -1516,51 +1579,70 @@ static inline block_t __start_sum_addr(struct f2fs_sb_info *sbi)
1516 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum); 1579 return le32_to_cpu(F2FS_CKPT(sbi)->cp_pack_start_sum);
1517} 1580}
1518 1581
1519static inline bool inc_valid_node_count(struct f2fs_sb_info *sbi, 1582static inline int inc_valid_node_count(struct f2fs_sb_info *sbi,
1520 struct inode *inode) 1583 struct inode *inode, bool is_inode)
1521{ 1584{
1522 block_t valid_block_count; 1585 block_t valid_block_count;
1523 unsigned int valid_node_count; 1586 unsigned int valid_node_count;
1587 bool quota = inode && !is_inode;
1588
1589 if (quota) {
1590 int ret = dquot_reserve_block(inode, 1);
1591 if (ret)
1592 return ret;
1593 }
1524 1594
1525 spin_lock(&sbi->stat_lock); 1595 spin_lock(&sbi->stat_lock);
1526 1596
1527 valid_block_count = sbi->total_valid_block_count + 1; 1597 valid_block_count = sbi->total_valid_block_count + 1;
1528 if (unlikely(valid_block_count > sbi->user_block_count)) { 1598 if (unlikely(valid_block_count + sbi->reserved_blocks >
1599 sbi->user_block_count)) {
1529 spin_unlock(&sbi->stat_lock); 1600 spin_unlock(&sbi->stat_lock);
1530 return false; 1601 goto enospc;
1531 } 1602 }
1532 1603
1533 valid_node_count = sbi->total_valid_node_count + 1; 1604 valid_node_count = sbi->total_valid_node_count + 1;
1534 if (unlikely(valid_node_count > sbi->total_node_count)) { 1605 if (unlikely(valid_node_count > sbi->total_node_count)) {
1535 spin_unlock(&sbi->stat_lock); 1606 spin_unlock(&sbi->stat_lock);
1536 return false; 1607 goto enospc;
1537 } 1608 }
1538 1609
1539 if (inode)
1540 f2fs_i_blocks_write(inode, 1, true);
1541
1542 sbi->total_valid_node_count++; 1610 sbi->total_valid_node_count++;
1543 sbi->total_valid_block_count++; 1611 sbi->total_valid_block_count++;
1544 spin_unlock(&sbi->stat_lock); 1612 spin_unlock(&sbi->stat_lock);
1545 1613
1614 if (inode) {
1615 if (is_inode)
1616 f2fs_mark_inode_dirty_sync(inode, true);
1617 else
1618 f2fs_i_blocks_write(inode, 1, true, true);
1619 }
1620
1546 percpu_counter_inc(&sbi->alloc_valid_block_count); 1621 percpu_counter_inc(&sbi->alloc_valid_block_count);
1547 return true; 1622 return 0;
1623
1624enospc:
1625 if (quota)
1626 dquot_release_reservation_block(inode, 1);
1627 return -ENOSPC;
1548} 1628}
1549 1629
1550static inline void dec_valid_node_count(struct f2fs_sb_info *sbi, 1630static inline void dec_valid_node_count(struct f2fs_sb_info *sbi,
1551 struct inode *inode) 1631 struct inode *inode, bool is_inode)
1552{ 1632{
1553 spin_lock(&sbi->stat_lock); 1633 spin_lock(&sbi->stat_lock);
1554 1634
1555 f2fs_bug_on(sbi, !sbi->total_valid_block_count); 1635 f2fs_bug_on(sbi, !sbi->total_valid_block_count);
1556 f2fs_bug_on(sbi, !sbi->total_valid_node_count); 1636 f2fs_bug_on(sbi, !sbi->total_valid_node_count);
1557 f2fs_bug_on(sbi, !inode->i_blocks); 1637 f2fs_bug_on(sbi, !is_inode && !inode->i_blocks);
1558 1638
1559 f2fs_i_blocks_write(inode, 1, false);
1560 sbi->total_valid_node_count--; 1639 sbi->total_valid_node_count--;
1561 sbi->total_valid_block_count--; 1640 sbi->total_valid_block_count--;
1562 1641
1563 spin_unlock(&sbi->stat_lock); 1642 spin_unlock(&sbi->stat_lock);
1643
1644 if (!is_inode)
1645 f2fs_i_blocks_write(inode, 1, false, true);
1564} 1646}
1565 1647
1566static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi) 1648static inline unsigned int valid_node_count(struct f2fs_sb_info *sbi)
@@ -1835,13 +1917,21 @@ static inline void f2fs_i_links_write(struct inode *inode, bool inc)
1835} 1917}
1836 1918
1837static inline void f2fs_i_blocks_write(struct inode *inode, 1919static inline void f2fs_i_blocks_write(struct inode *inode,
1838 blkcnt_t diff, bool add) 1920 block_t diff, bool add, bool claim)
1839{ 1921{
1840 bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE); 1922 bool clean = !is_inode_flag_set(inode, FI_DIRTY_INODE);
1841 bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER); 1923 bool recover = is_inode_flag_set(inode, FI_AUTO_RECOVER);
1842 1924
1843 inode->i_blocks = add ? inode->i_blocks + diff : 1925 /* add = 1, claim = 1 should be dquot_reserve_block in pair */
1844 inode->i_blocks - diff; 1926 if (add) {
1927 if (claim)
1928 dquot_claim_block(inode, diff);
1929 else
1930 dquot_alloc_block_nofail(inode, diff);
1931 } else {
1932 dquot_free_block(inode, diff);
1933 }
1934
1845 f2fs_mark_inode_dirty_sync(inode, true); 1935 f2fs_mark_inode_dirty_sync(inode, true);
1846 if (clean || recover) 1936 if (clean || recover)
1847 set_inode_flag(inode, FI_AUTO_RECOVER); 1937 set_inode_flag(inode, FI_AUTO_RECOVER);
@@ -2236,6 +2326,7 @@ void destroy_flush_cmd_control(struct f2fs_sb_info *sbi, bool free);
2236void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr); 2326void invalidate_blocks(struct f2fs_sb_info *sbi, block_t addr);
2237bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr); 2327bool is_checkpointed_data(struct f2fs_sb_info *sbi, block_t blkaddr);
2238void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new); 2328void refresh_sit_entry(struct f2fs_sb_info *sbi, block_t old, block_t new);
2329void stop_discard_thread(struct f2fs_sb_info *sbi);
2239void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi); 2330void f2fs_wait_discard_bios(struct f2fs_sb_info *sbi);
2240void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc); 2331void clear_prefree_segments(struct f2fs_sb_info *sbi, struct cp_control *cpc);
2241void release_discard_addrs(struct f2fs_sb_info *sbi); 2332void release_discard_addrs(struct f2fs_sb_info *sbi);
@@ -2258,7 +2349,8 @@ void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn,
2258 bool recover_newaddr); 2349 bool recover_newaddr);
2259void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2350void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
2260 block_t old_blkaddr, block_t *new_blkaddr, 2351 block_t old_blkaddr, block_t *new_blkaddr,
2261 struct f2fs_summary *sum, int type); 2352 struct f2fs_summary *sum, int type,
2353 struct f2fs_io_info *fio, bool add_list);
2262void f2fs_wait_on_page_writeback(struct page *page, 2354void f2fs_wait_on_page_writeback(struct page *page,
2263 enum page_type type, bool ordered); 2355 enum page_type type, bool ordered);
2264void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi, 2356void f2fs_wait_on_encrypted_page_writeback(struct f2fs_sb_info *sbi,
@@ -2308,14 +2400,13 @@ void destroy_checkpoint_caches(void);
2308/* 2400/*
2309 * data.c 2401 * data.c
2310 */ 2402 */
2311void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, 2403void f2fs_submit_merged_write(struct f2fs_sb_info *sbi, enum page_type type);
2312 int rw); 2404void f2fs_submit_merged_write_cond(struct f2fs_sb_info *sbi,
2313void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi,
2314 struct inode *inode, nid_t ino, pgoff_t idx, 2405 struct inode *inode, nid_t ino, pgoff_t idx,
2315 enum page_type type, int rw); 2406 enum page_type type);
2316void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi); 2407void f2fs_flush_merged_writes(struct f2fs_sb_info *sbi);
2317int f2fs_submit_page_bio(struct f2fs_io_info *fio); 2408int f2fs_submit_page_bio(struct f2fs_io_info *fio);
2318int f2fs_submit_page_mbio(struct f2fs_io_info *fio); 2409int f2fs_submit_page_write(struct f2fs_io_info *fio);
2319struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, 2410struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi,
2320 block_t blk_addr, struct bio *bio); 2411 block_t blk_addr, struct bio *bio);
2321int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr); 2412int f2fs_target_device_index(struct f2fs_sb_info *sbi, block_t blkaddr);
@@ -2633,6 +2724,14 @@ int __init create_extent_cache(void);
2633void destroy_extent_cache(void); 2724void destroy_extent_cache(void);
2634 2725
2635/* 2726/*
2727 * sysfs.c
2728 */
2729int __init f2fs_register_sysfs(void);
2730void f2fs_unregister_sysfs(void);
2731int f2fs_init_sysfs(struct f2fs_sb_info *sbi);
2732void f2fs_exit_sysfs(struct f2fs_sb_info *sbi);
2733
2734/*
2636 * crypto support 2735 * crypto support
2637 */ 2736 */
2638static inline bool f2fs_encrypted_inode(struct inode *inode) 2737static inline bool f2fs_encrypted_inode(struct inode *inode)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index 61af721329fa..a0e6d2c65a9e 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -33,6 +33,18 @@
33#include "trace.h" 33#include "trace.h"
34#include <trace/events/f2fs.h> 34#include <trace/events/f2fs.h>
35 35
36static int f2fs_filemap_fault(struct vm_fault *vmf)
37{
38 struct inode *inode = file_inode(vmf->vma->vm_file);
39 int err;
40
41 down_read(&F2FS_I(inode)->i_mmap_sem);
42 err = filemap_fault(vmf);
43 up_read(&F2FS_I(inode)->i_mmap_sem);
44
45 return err;
46}
47
36static int f2fs_vm_page_mkwrite(struct vm_fault *vmf) 48static int f2fs_vm_page_mkwrite(struct vm_fault *vmf)
37{ 49{
38 struct page *page = vmf->page; 50 struct page *page = vmf->page;
@@ -59,13 +71,14 @@ static int f2fs_vm_page_mkwrite(struct vm_fault *vmf)
59 f2fs_balance_fs(sbi, dn.node_changed); 71 f2fs_balance_fs(sbi, dn.node_changed);
60 72
61 file_update_time(vmf->vma->vm_file); 73 file_update_time(vmf->vma->vm_file);
74 down_read(&F2FS_I(inode)->i_mmap_sem);
62 lock_page(page); 75 lock_page(page);
63 if (unlikely(page->mapping != inode->i_mapping || 76 if (unlikely(page->mapping != inode->i_mapping ||
64 page_offset(page) > i_size_read(inode) || 77 page_offset(page) > i_size_read(inode) ||
65 !PageUptodate(page))) { 78 !PageUptodate(page))) {
66 unlock_page(page); 79 unlock_page(page);
67 err = -EFAULT; 80 err = -EFAULT;
68 goto out; 81 goto out_sem;
69 } 82 }
70 83
71 /* 84 /*
@@ -94,6 +107,8 @@ mapped:
94 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) 107 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
95 f2fs_wait_on_encrypted_page_writeback(sbi, dn.data_blkaddr); 108 f2fs_wait_on_encrypted_page_writeback(sbi, dn.data_blkaddr);
96 109
110out_sem:
111 up_read(&F2FS_I(inode)->i_mmap_sem);
97out: 112out:
98 sb_end_pagefault(inode->i_sb); 113 sb_end_pagefault(inode->i_sb);
99 f2fs_update_time(sbi, REQ_TIME); 114 f2fs_update_time(sbi, REQ_TIME);
@@ -101,7 +116,7 @@ out:
101} 116}
102 117
103static const struct vm_operations_struct f2fs_file_vm_ops = { 118static const struct vm_operations_struct f2fs_file_vm_ops = {
104 .fault = filemap_fault, 119 .fault = f2fs_filemap_fault,
105 .map_pages = filemap_map_pages, 120 .map_pages = filemap_map_pages,
106 .page_mkwrite = f2fs_vm_page_mkwrite, 121 .page_mkwrite = f2fs_vm_page_mkwrite,
107}; 122};
@@ -415,14 +430,6 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
415 struct inode *inode = file_inode(file); 430 struct inode *inode = file_inode(file);
416 int err; 431 int err;
417 432
418 if (f2fs_encrypted_inode(inode)) {
419 err = fscrypt_get_encryption_info(inode);
420 if (err)
421 return 0;
422 if (!f2fs_encrypted_inode(inode))
423 return -ENOKEY;
424 }
425
426 /* we don't need to use inline_data strictly */ 433 /* we don't need to use inline_data strictly */
427 err = f2fs_convert_inline_inode(inode); 434 err = f2fs_convert_inline_inode(inode);
428 if (err) 435 if (err)
@@ -435,11 +442,10 @@ static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma)
435 442
436static int f2fs_file_open(struct inode *inode, struct file *filp) 443static int f2fs_file_open(struct inode *inode, struct file *filp)
437{ 444{
438 int ret = generic_file_open(inode, filp);
439 struct dentry *dir; 445 struct dentry *dir;
440 446
441 if (!ret && f2fs_encrypted_inode(inode)) { 447 if (f2fs_encrypted_inode(inode)) {
442 ret = fscrypt_get_encryption_info(inode); 448 int ret = fscrypt_get_encryption_info(inode);
443 if (ret) 449 if (ret)
444 return -EACCES; 450 return -EACCES;
445 if (!fscrypt_has_encryption_key(inode)) 451 if (!fscrypt_has_encryption_key(inode))
@@ -452,7 +458,7 @@ static int f2fs_file_open(struct inode *inode, struct file *filp)
452 return -EPERM; 458 return -EPERM;
453 } 459 }
454 dput(dir); 460 dput(dir);
455 return ret; 461 return dquot_file_open(inode, filp);
456} 462}
457 463
458int truncate_data_blocks_range(struct dnode_of_data *dn, int count) 464int truncate_data_blocks_range(struct dnode_of_data *dn, int count)
@@ -527,8 +533,10 @@ static int truncate_partial_data_page(struct inode *inode, u64 from,
527truncate_out: 533truncate_out:
528 f2fs_wait_on_page_writeback(page, DATA, true); 534 f2fs_wait_on_page_writeback(page, DATA, true);
529 zero_user(page, offset, PAGE_SIZE - offset); 535 zero_user(page, offset, PAGE_SIZE - offset);
530 if (!cache_only || !f2fs_encrypted_inode(inode) || 536
531 !S_ISREG(inode->i_mode)) 537 /* An encrypted inode should have a key and truncate the last page. */
538 f2fs_bug_on(F2FS_I_SB(inode), cache_only && f2fs_encrypted_inode(inode));
539 if (!cache_only)
532 set_page_dirty(page); 540 set_page_dirty(page);
533 f2fs_put_page(page, 1); 541 f2fs_put_page(page, 1);
534 return 0; 542 return 0;
@@ -633,11 +641,31 @@ int f2fs_truncate(struct inode *inode)
633} 641}
634 642
635int f2fs_getattr(const struct path *path, struct kstat *stat, 643int f2fs_getattr(const struct path *path, struct kstat *stat,
636 u32 request_mask, unsigned int flags) 644 u32 request_mask, unsigned int query_flags)
637{ 645{
638 struct inode *inode = d_inode(path->dentry); 646 struct inode *inode = d_inode(path->dentry);
647 struct f2fs_inode_info *fi = F2FS_I(inode);
648 unsigned int flags;
649
650 flags = fi->i_flags & FS_FL_USER_VISIBLE;
651 if (flags & FS_APPEND_FL)
652 stat->attributes |= STATX_ATTR_APPEND;
653 if (flags & FS_COMPR_FL)
654 stat->attributes |= STATX_ATTR_COMPRESSED;
655 if (f2fs_encrypted_inode(inode))
656 stat->attributes |= STATX_ATTR_ENCRYPTED;
657 if (flags & FS_IMMUTABLE_FL)
658 stat->attributes |= STATX_ATTR_IMMUTABLE;
659 if (flags & FS_NODUMP_FL)
660 stat->attributes |= STATX_ATTR_NODUMP;
661
662 stat->attributes_mask |= (STATX_ATTR_APPEND |
663 STATX_ATTR_COMPRESSED |
664 STATX_ATTR_ENCRYPTED |
665 STATX_ATTR_IMMUTABLE |
666 STATX_ATTR_NODUMP);
667
639 generic_fillattr(inode, stat); 668 generic_fillattr(inode, stat);
640 stat->blocks <<= 3;
641 return 0; 669 return 0;
642} 670}
643 671
@@ -681,14 +709,34 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
681 if (err) 709 if (err)
682 return err; 710 return err;
683 711
712 if (is_quota_modification(inode, attr)) {
713 err = dquot_initialize(inode);
714 if (err)
715 return err;
716 }
717 if ((attr->ia_valid & ATTR_UID &&
718 !uid_eq(attr->ia_uid, inode->i_uid)) ||
719 (attr->ia_valid & ATTR_GID &&
720 !gid_eq(attr->ia_gid, inode->i_gid))) {
721 err = dquot_transfer(inode, attr);
722 if (err)
723 return err;
724 }
725
684 if (attr->ia_valid & ATTR_SIZE) { 726 if (attr->ia_valid & ATTR_SIZE) {
685 if (f2fs_encrypted_inode(inode) && 727 if (f2fs_encrypted_inode(inode)) {
686 fscrypt_get_encryption_info(inode)) 728 err = fscrypt_get_encryption_info(inode);
687 return -EACCES; 729 if (err)
730 return err;
731 if (!fscrypt_has_encryption_key(inode))
732 return -ENOKEY;
733 }
688 734
689 if (attr->ia_size <= i_size_read(inode)) { 735 if (attr->ia_size <= i_size_read(inode)) {
736 down_write(&F2FS_I(inode)->i_mmap_sem);
690 truncate_setsize(inode, attr->ia_size); 737 truncate_setsize(inode, attr->ia_size);
691 err = f2fs_truncate(inode); 738 err = f2fs_truncate(inode);
739 up_write(&F2FS_I(inode)->i_mmap_sem);
692 if (err) 740 if (err)
693 return err; 741 return err;
694 } else { 742 } else {
@@ -696,7 +744,9 @@ int f2fs_setattr(struct dentry *dentry, struct iattr *attr)
696 * do not trim all blocks after i_size if target size is 744 * do not trim all blocks after i_size if target size is
697 * larger than i_size. 745 * larger than i_size.
698 */ 746 */
747 down_write(&F2FS_I(inode)->i_mmap_sem);
699 truncate_setsize(inode, attr->ia_size); 748 truncate_setsize(inode, attr->ia_size);
749 up_write(&F2FS_I(inode)->i_mmap_sem);
700 750
701 /* should convert inline inode here */ 751 /* should convert inline inode here */
702 if (!f2fs_may_inline_data(inode)) { 752 if (!f2fs_may_inline_data(inode)) {
@@ -839,12 +889,14 @@ static int punch_hole(struct inode *inode, loff_t offset, loff_t len)
839 889
840 blk_start = (loff_t)pg_start << PAGE_SHIFT; 890 blk_start = (loff_t)pg_start << PAGE_SHIFT;
841 blk_end = (loff_t)pg_end << PAGE_SHIFT; 891 blk_end = (loff_t)pg_end << PAGE_SHIFT;
892 down_write(&F2FS_I(inode)->i_mmap_sem);
842 truncate_inode_pages_range(mapping, blk_start, 893 truncate_inode_pages_range(mapping, blk_start,
843 blk_end - 1); 894 blk_end - 1);
844 895
845 f2fs_lock_op(sbi); 896 f2fs_lock_op(sbi);
846 ret = truncate_hole(inode, pg_start, pg_end); 897 ret = truncate_hole(inode, pg_start, pg_end);
847 f2fs_unlock_op(sbi); 898 f2fs_unlock_op(sbi);
899 up_write(&F2FS_I(inode)->i_mmap_sem);
848 } 900 }
849 } 901 }
850 902
@@ -957,9 +1009,9 @@ static int __clone_blkaddrs(struct inode *src_inode, struct inode *dst_inode,
957 1009
958 if (do_replace[i]) { 1010 if (do_replace[i]) {
959 f2fs_i_blocks_write(src_inode, 1011 f2fs_i_blocks_write(src_inode,
960 1, false); 1012 1, false, false);
961 f2fs_i_blocks_write(dst_inode, 1013 f2fs_i_blocks_write(dst_inode,
962 1, true); 1014 1, true, false);
963 f2fs_replace_block(sbi, &dn, dn.data_blkaddr, 1015 f2fs_replace_block(sbi, &dn, dn.data_blkaddr,
964 blkaddr[i], ni.version, true, false); 1016 blkaddr[i], ni.version, true, false);
965 1017
@@ -1083,16 +1135,17 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
1083 pg_start = offset >> PAGE_SHIFT; 1135 pg_start = offset >> PAGE_SHIFT;
1084 pg_end = (offset + len) >> PAGE_SHIFT; 1136 pg_end = (offset + len) >> PAGE_SHIFT;
1085 1137
1138 down_write(&F2FS_I(inode)->i_mmap_sem);
1086 /* write out all dirty pages from offset */ 1139 /* write out all dirty pages from offset */
1087 ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); 1140 ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX);
1088 if (ret) 1141 if (ret)
1089 return ret; 1142 goto out;
1090 1143
1091 truncate_pagecache(inode, offset); 1144 truncate_pagecache(inode, offset);
1092 1145
1093 ret = f2fs_do_collapse(inode, pg_start, pg_end); 1146 ret = f2fs_do_collapse(inode, pg_start, pg_end);
1094 if (ret) 1147 if (ret)
1095 return ret; 1148 goto out;
1096 1149
1097 /* write out all moved pages, if possible */ 1150 /* write out all moved pages, if possible */
1098 filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); 1151 filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX);
@@ -1105,6 +1158,8 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len)
1105 if (!ret) 1158 if (!ret)
1106 f2fs_i_size_write(inode, new_size); 1159 f2fs_i_size_write(inode, new_size);
1107 1160
1161out:
1162 up_write(&F2FS_I(inode)->i_mmap_sem);
1108 return ret; 1163 return ret;
1109} 1164}
1110 1165
@@ -1169,9 +1224,10 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
1169 if (ret) 1224 if (ret)
1170 return ret; 1225 return ret;
1171 1226
1227 down_write(&F2FS_I(inode)->i_mmap_sem);
1172 ret = filemap_write_and_wait_range(mapping, offset, offset + len - 1); 1228 ret = filemap_write_and_wait_range(mapping, offset, offset + len - 1);
1173 if (ret) 1229 if (ret)
1174 return ret; 1230 goto out_sem;
1175 1231
1176 truncate_pagecache_range(inode, offset, offset + len - 1); 1232 truncate_pagecache_range(inode, offset, offset + len - 1);
1177 1233
@@ -1185,7 +1241,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
1185 ret = fill_zero(inode, pg_start, off_start, 1241 ret = fill_zero(inode, pg_start, off_start,
1186 off_end - off_start); 1242 off_end - off_start);
1187 if (ret) 1243 if (ret)
1188 return ret; 1244 goto out_sem;
1189 1245
1190 new_size = max_t(loff_t, new_size, offset + len); 1246 new_size = max_t(loff_t, new_size, offset + len);
1191 } else { 1247 } else {
@@ -1193,7 +1249,7 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
1193 ret = fill_zero(inode, pg_start++, off_start, 1249 ret = fill_zero(inode, pg_start++, off_start,
1194 PAGE_SIZE - off_start); 1250 PAGE_SIZE - off_start);
1195 if (ret) 1251 if (ret)
1196 return ret; 1252 goto out_sem;
1197 1253
1198 new_size = max_t(loff_t, new_size, 1254 new_size = max_t(loff_t, new_size,
1199 (loff_t)pg_start << PAGE_SHIFT); 1255 (loff_t)pg_start << PAGE_SHIFT);
@@ -1242,6 +1298,8 @@ static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len,
1242out: 1298out:
1243 if (!(mode & FALLOC_FL_KEEP_SIZE) && i_size_read(inode) < new_size) 1299 if (!(mode & FALLOC_FL_KEEP_SIZE) && i_size_read(inode) < new_size)
1244 f2fs_i_size_write(inode, new_size); 1300 f2fs_i_size_write(inode, new_size);
1301out_sem:
1302 up_write(&F2FS_I(inode)->i_mmap_sem);
1245 1303
1246 return ret; 1304 return ret;
1247} 1305}
@@ -1271,14 +1329,15 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
1271 1329
1272 f2fs_balance_fs(sbi, true); 1330 f2fs_balance_fs(sbi, true);
1273 1331
1332 down_write(&F2FS_I(inode)->i_mmap_sem);
1274 ret = truncate_blocks(inode, i_size_read(inode), true); 1333 ret = truncate_blocks(inode, i_size_read(inode), true);
1275 if (ret) 1334 if (ret)
1276 return ret; 1335 goto out;
1277 1336
1278 /* write out all dirty pages from offset */ 1337 /* write out all dirty pages from offset */
1279 ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); 1338 ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX);
1280 if (ret) 1339 if (ret)
1281 return ret; 1340 goto out;
1282 1341
1283 truncate_pagecache(inode, offset); 1342 truncate_pagecache(inode, offset);
1284 1343
@@ -1307,6 +1366,8 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len)
1307 1366
1308 if (!ret) 1367 if (!ret)
1309 f2fs_i_size_write(inode, new_size); 1368 f2fs_i_size_write(inode, new_size);
1369out:
1370 up_write(&F2FS_I(inode)->i_mmap_sem);
1310 return ret; 1371 return ret;
1311} 1372}
1312 1373
@@ -1475,6 +1536,13 @@ static int f2fs_ioc_setflags(struct file *filp, unsigned long arg)
1475 1536
1476 inode_lock(inode); 1537 inode_lock(inode);
1477 1538
1539 /* Is it quota file? Do not allow user to mess with it */
1540 if (IS_NOQUOTA(inode)) {
1541 inode_unlock(inode);
1542 ret = -EPERM;
1543 goto unlock_out;
1544 }
1545
1478 flags = f2fs_mask_flags(inode->i_mode, flags); 1546 flags = f2fs_mask_flags(inode->i_mode, flags);
1479 1547
1480 oldflags = fi->i_flags; 1548 oldflags = fi->i_flags;
@@ -1493,7 +1561,8 @@ static int f2fs_ioc_setflags(struct file *filp, unsigned long arg)
1493 1561
1494 inode->i_ctime = current_time(inode); 1562 inode->i_ctime = current_time(inode);
1495 f2fs_set_inode_flags(inode); 1563 f2fs_set_inode_flags(inode);
1496 1564 f2fs_mark_inode_dirty_sync(inode, false);
1565unlock_out:
1497 inode_unlock(inode); 1566 inode_unlock(inode);
1498out: 1567out:
1499 mnt_drop_write_file(filp); 1568 mnt_drop_write_file(filp);
@@ -1862,6 +1931,50 @@ out:
1862 return ret; 1931 return ret;
1863} 1932}
1864 1933
1934static int f2fs_ioc_gc_range(struct file *filp, unsigned long arg)
1935{
1936 struct inode *inode = file_inode(filp);
1937 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1938 struct f2fs_gc_range range;
1939 u64 end;
1940 int ret;
1941
1942 if (!capable(CAP_SYS_ADMIN))
1943 return -EPERM;
1944
1945 if (copy_from_user(&range, (struct f2fs_gc_range __user *)arg,
1946 sizeof(range)))
1947 return -EFAULT;
1948
1949 if (f2fs_readonly(sbi->sb))
1950 return -EROFS;
1951
1952 ret = mnt_want_write_file(filp);
1953 if (ret)
1954 return ret;
1955
1956 end = range.start + range.len;
1957 if (range.start < MAIN_BLKADDR(sbi) || end >= MAX_BLKADDR(sbi))
1958 return -EINVAL;
1959do_more:
1960 if (!range.sync) {
1961 if (!mutex_trylock(&sbi->gc_mutex)) {
1962 ret = -EBUSY;
1963 goto out;
1964 }
1965 } else {
1966 mutex_lock(&sbi->gc_mutex);
1967 }
1968
1969 ret = f2fs_gc(sbi, range.sync, true, GET_SEGNO(sbi, range.start));
1970 range.start += sbi->blocks_per_seg;
1971 if (range.start <= end)
1972 goto do_more;
1973out:
1974 mnt_drop_write_file(filp);
1975 return ret;
1976}
1977
1865static int f2fs_ioc_write_checkpoint(struct file *filp, unsigned long arg) 1978static int f2fs_ioc_write_checkpoint(struct file *filp, unsigned long arg)
1866{ 1979{
1867 struct inode *inode = file_inode(filp); 1980 struct inode *inode = file_inode(filp);
@@ -2306,6 +2419,8 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
2306 return f2fs_ioc_get_encryption_pwsalt(filp, arg); 2419 return f2fs_ioc_get_encryption_pwsalt(filp, arg);
2307 case F2FS_IOC_GARBAGE_COLLECT: 2420 case F2FS_IOC_GARBAGE_COLLECT:
2308 return f2fs_ioc_gc(filp, arg); 2421 return f2fs_ioc_gc(filp, arg);
2422 case F2FS_IOC_GARBAGE_COLLECT_RANGE:
2423 return f2fs_ioc_gc_range(filp, arg);
2309 case F2FS_IOC_WRITE_CHECKPOINT: 2424 case F2FS_IOC_WRITE_CHECKPOINT:
2310 return f2fs_ioc_write_checkpoint(filp, arg); 2425 return f2fs_ioc_write_checkpoint(filp, arg);
2311 case F2FS_IOC_DEFRAGMENT: 2426 case F2FS_IOC_DEFRAGMENT:
@@ -2326,11 +2441,6 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
2326 struct blk_plug plug; 2441 struct blk_plug plug;
2327 ssize_t ret; 2442 ssize_t ret;
2328 2443
2329 if (f2fs_encrypted_inode(inode) &&
2330 !fscrypt_has_encryption_key(inode) &&
2331 fscrypt_get_encryption_info(inode))
2332 return -EACCES;
2333
2334 inode_lock(inode); 2444 inode_lock(inode);
2335 ret = generic_write_checks(iocb, from); 2445 ret = generic_write_checks(iocb, from);
2336 if (ret > 0) { 2446 if (ret > 0) {
@@ -2379,6 +2489,7 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2379 case F2FS_IOC_GET_ENCRYPTION_PWSALT: 2489 case F2FS_IOC_GET_ENCRYPTION_PWSALT:
2380 case F2FS_IOC_GET_ENCRYPTION_POLICY: 2490 case F2FS_IOC_GET_ENCRYPTION_POLICY:
2381 case F2FS_IOC_GARBAGE_COLLECT: 2491 case F2FS_IOC_GARBAGE_COLLECT:
2492 case F2FS_IOC_GARBAGE_COLLECT_RANGE:
2382 case F2FS_IOC_WRITE_CHECKPOINT: 2493 case F2FS_IOC_WRITE_CHECKPOINT:
2383 case F2FS_IOC_DEFRAGMENT: 2494 case F2FS_IOC_DEFRAGMENT:
2384 case F2FS_IOC_MOVE_RANGE: 2495 case F2FS_IOC_MOVE_RANGE:
diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c
index 026522107ca3..fa3d2e2df8e7 100644
--- a/fs/f2fs/gc.c
+++ b/fs/f2fs/gc.c
@@ -32,13 +32,14 @@ static int gc_thread_func(void *data)
32 32
33 wait_ms = gc_th->min_sleep_time; 33 wait_ms = gc_th->min_sleep_time;
34 34
35 set_freezable();
35 do { 36 do {
37 wait_event_interruptible_timeout(*wq,
38 kthread_should_stop() || freezing(current),
39 msecs_to_jiffies(wait_ms));
40
36 if (try_to_freeze()) 41 if (try_to_freeze())
37 continue; 42 continue;
38 else
39 wait_event_interruptible_timeout(*wq,
40 kthread_should_stop(),
41 msecs_to_jiffies(wait_ms));
42 if (kthread_should_stop()) 43 if (kthread_should_stop())
43 break; 44 break;
44 45
@@ -258,11 +259,20 @@ static unsigned int get_greedy_cost(struct f2fs_sb_info *sbi,
258 valid_blocks * 2 : valid_blocks; 259 valid_blocks * 2 : valid_blocks;
259} 260}
260 261
262static unsigned int get_ssr_cost(struct f2fs_sb_info *sbi,
263 unsigned int segno)
264{
265 struct seg_entry *se = get_seg_entry(sbi, segno);
266
267 return se->ckpt_valid_blocks > se->valid_blocks ?
268 se->ckpt_valid_blocks : se->valid_blocks;
269}
270
261static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi, 271static inline unsigned int get_gc_cost(struct f2fs_sb_info *sbi,
262 unsigned int segno, struct victim_sel_policy *p) 272 unsigned int segno, struct victim_sel_policy *p)
263{ 273{
264 if (p->alloc_mode == SSR) 274 if (p->alloc_mode == SSR)
265 return get_seg_entry(sbi, segno)->ckpt_valid_blocks; 275 return get_ssr_cost(sbi, segno);
266 276
267 /* alloc_mode == LFS */ 277 /* alloc_mode == LFS */
268 if (p->gc_mode == GC_GREEDY) 278 if (p->gc_mode == GC_GREEDY)
@@ -586,9 +596,11 @@ static void move_encrypted_block(struct inode *inode, block_t bidx,
586 struct f2fs_io_info fio = { 596 struct f2fs_io_info fio = {
587 .sbi = F2FS_I_SB(inode), 597 .sbi = F2FS_I_SB(inode),
588 .type = DATA, 598 .type = DATA,
599 .temp = COLD,
589 .op = REQ_OP_READ, 600 .op = REQ_OP_READ,
590 .op_flags = 0, 601 .op_flags = 0,
591 .encrypted_page = NULL, 602 .encrypted_page = NULL,
603 .in_list = false,
592 }; 604 };
593 struct dnode_of_data dn; 605 struct dnode_of_data dn;
594 struct f2fs_summary sum; 606 struct f2fs_summary sum;
@@ -632,7 +644,7 @@ static void move_encrypted_block(struct inode *inode, block_t bidx,
632 fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr; 644 fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr;
633 645
634 allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr, 646 allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr,
635 &sum, CURSEG_COLD_DATA); 647 &sum, CURSEG_COLD_DATA, NULL, false);
636 648
637 fio.encrypted_page = pagecache_get_page(META_MAPPING(fio.sbi), newaddr, 649 fio.encrypted_page = pagecache_get_page(META_MAPPING(fio.sbi), newaddr,
638 FGP_LOCK | FGP_CREAT, GFP_NOFS); 650 FGP_LOCK | FGP_CREAT, GFP_NOFS);
@@ -670,7 +682,7 @@ static void move_encrypted_block(struct inode *inode, block_t bidx,
670 fio.op = REQ_OP_WRITE; 682 fio.op = REQ_OP_WRITE;
671 fio.op_flags = REQ_SYNC; 683 fio.op_flags = REQ_SYNC;
672 fio.new_blkaddr = newaddr; 684 fio.new_blkaddr = newaddr;
673 f2fs_submit_page_mbio(&fio); 685 f2fs_submit_page_write(&fio);
674 686
675 f2fs_update_data_blkaddr(&dn, newaddr); 687 f2fs_update_data_blkaddr(&dn, newaddr);
676 set_inode_flag(inode, FI_APPEND_WRITE); 688 set_inode_flag(inode, FI_APPEND_WRITE);
@@ -712,12 +724,13 @@ static void move_data_page(struct inode *inode, block_t bidx, int gc_type,
712 struct f2fs_io_info fio = { 724 struct f2fs_io_info fio = {
713 .sbi = F2FS_I_SB(inode), 725 .sbi = F2FS_I_SB(inode),
714 .type = DATA, 726 .type = DATA,
727 .temp = COLD,
715 .op = REQ_OP_WRITE, 728 .op = REQ_OP_WRITE,
716 .op_flags = REQ_SYNC, 729 .op_flags = REQ_SYNC,
717 .old_blkaddr = NULL_ADDR, 730 .old_blkaddr = NULL_ADDR,
718 .page = page, 731 .page = page,
719 .encrypted_page = NULL, 732 .encrypted_page = NULL,
720 .need_lock = true, 733 .need_lock = LOCK_REQ,
721 }; 734 };
722 bool is_dirty = PageDirty(page); 735 bool is_dirty = PageDirty(page);
723 int err; 736 int err;
@@ -936,8 +949,8 @@ next:
936 } 949 }
937 950
938 if (gc_type == FG_GC) 951 if (gc_type == FG_GC)
939 f2fs_submit_merged_bio(sbi, 952 f2fs_submit_merged_write(sbi,
940 (type == SUM_TYPE_NODE) ? NODE : DATA, WRITE); 953 (type == SUM_TYPE_NODE) ? NODE : DATA);
941 954
942 blk_finish_plug(&plug); 955 blk_finish_plug(&plug);
943 956
@@ -955,7 +968,7 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
955{ 968{
956 int gc_type = sync ? FG_GC : BG_GC; 969 int gc_type = sync ? FG_GC : BG_GC;
957 int sec_freed = 0; 970 int sec_freed = 0;
958 int ret = -EINVAL; 971 int ret;
959 struct cp_control cpc; 972 struct cp_control cpc;
960 unsigned int init_segno = segno; 973 unsigned int init_segno = segno;
961 struct gc_inode_list gc_list = { 974 struct gc_inode_list gc_list = {
@@ -965,8 +978,10 @@ int f2fs_gc(struct f2fs_sb_info *sbi, bool sync,
965 978
966 cpc.reason = __get_cp_reason(sbi); 979 cpc.reason = __get_cp_reason(sbi);
967gc_more: 980gc_more:
968 if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE))) 981 if (unlikely(!(sbi->sb->s_flags & MS_ACTIVE))) {
982 ret = -EINVAL;
969 goto stop; 983 goto stop;
984 }
970 if (unlikely(f2fs_cp_error(sbi))) { 985 if (unlikely(f2fs_cp_error(sbi))) {
971 ret = -EIO; 986 ret = -EIO;
972 goto stop; 987 goto stop;
@@ -987,6 +1002,7 @@ gc_more:
987 gc_type = FG_GC; 1002 gc_type = FG_GC;
988 } 1003 }
989 1004
1005 ret = -EINVAL;
990 /* f2fs_balance_fs doesn't need to do BG_GC in critical path. */ 1006 /* f2fs_balance_fs doesn't need to do BG_GC in critical path. */
991 if (gc_type == BG_GC && !background) 1007 if (gc_type == BG_GC && !background)
992 goto stop; 1008 goto stop;
diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c
index e4c527c4e7d0..e0fd4376e6fb 100644
--- a/fs/f2fs/inline.c
+++ b/fs/f2fs/inline.c
@@ -316,12 +316,12 @@ struct f2fs_dir_entry *find_in_inline_dir(struct inode *dir,
316int make_empty_inline_dir(struct inode *inode, struct inode *parent, 316int make_empty_inline_dir(struct inode *inode, struct inode *parent,
317 struct page *ipage) 317 struct page *ipage)
318{ 318{
319 struct f2fs_inline_dentry *dentry_blk; 319 struct f2fs_inline_dentry *inline_dentry;
320 struct f2fs_dentry_ptr d; 320 struct f2fs_dentry_ptr d;
321 321
322 dentry_blk = inline_data_addr(ipage); 322 inline_dentry = inline_data_addr(ipage);
323 323
324 make_dentry_ptr_inline(NULL, &d, dentry_blk); 324 make_dentry_ptr_inline(NULL, &d, inline_dentry);
325 do_make_empty_dir(inode, parent, &d); 325 do_make_empty_dir(inode, parent, &d);
326 326
327 set_page_dirty(ipage); 327 set_page_dirty(ipage);
@@ -500,7 +500,7 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
500 struct page *ipage; 500 struct page *ipage;
501 unsigned int bit_pos; 501 unsigned int bit_pos;
502 f2fs_hash_t name_hash; 502 f2fs_hash_t name_hash;
503 struct f2fs_inline_dentry *dentry_blk = NULL; 503 struct f2fs_inline_dentry *inline_dentry = NULL;
504 struct f2fs_dentry_ptr d; 504 struct f2fs_dentry_ptr d;
505 int slots = GET_DENTRY_SLOTS(new_name->len); 505 int slots = GET_DENTRY_SLOTS(new_name->len);
506 struct page *page = NULL; 506 struct page *page = NULL;
@@ -510,11 +510,11 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
510 if (IS_ERR(ipage)) 510 if (IS_ERR(ipage))
511 return PTR_ERR(ipage); 511 return PTR_ERR(ipage);
512 512
513 dentry_blk = inline_data_addr(ipage); 513 inline_dentry = inline_data_addr(ipage);
514 bit_pos = room_for_filename(&dentry_blk->dentry_bitmap, 514 bit_pos = room_for_filename(&inline_dentry->dentry_bitmap,
515 slots, NR_INLINE_DENTRY); 515 slots, NR_INLINE_DENTRY);
516 if (bit_pos >= NR_INLINE_DENTRY) { 516 if (bit_pos >= NR_INLINE_DENTRY) {
517 err = f2fs_convert_inline_dir(dir, ipage, dentry_blk); 517 err = f2fs_convert_inline_dir(dir, ipage, inline_dentry);
518 if (err) 518 if (err)
519 return err; 519 return err;
520 err = -EAGAIN; 520 err = -EAGAIN;
@@ -534,7 +534,7 @@ int f2fs_add_inline_entry(struct inode *dir, const struct qstr *new_name,
534 f2fs_wait_on_page_writeback(ipage, NODE, true); 534 f2fs_wait_on_page_writeback(ipage, NODE, true);
535 535
536 name_hash = f2fs_dentry_hash(new_name, NULL); 536 name_hash = f2fs_dentry_hash(new_name, NULL);
537 make_dentry_ptr_inline(NULL, &d, dentry_blk); 537 make_dentry_ptr_inline(NULL, &d, inline_dentry);
538 f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos); 538 f2fs_update_dentry(ino, mode, &d, new_name, name_hash, bit_pos);
539 539
540 set_page_dirty(ipage); 540 set_page_dirty(ipage);
@@ -586,14 +586,14 @@ bool f2fs_empty_inline_dir(struct inode *dir)
586 struct f2fs_sb_info *sbi = F2FS_I_SB(dir); 586 struct f2fs_sb_info *sbi = F2FS_I_SB(dir);
587 struct page *ipage; 587 struct page *ipage;
588 unsigned int bit_pos = 2; 588 unsigned int bit_pos = 2;
589 struct f2fs_inline_dentry *dentry_blk; 589 struct f2fs_inline_dentry *inline_dentry;
590 590
591 ipage = get_node_page(sbi, dir->i_ino); 591 ipage = get_node_page(sbi, dir->i_ino);
592 if (IS_ERR(ipage)) 592 if (IS_ERR(ipage))
593 return false; 593 return false;
594 594
595 dentry_blk = inline_data_addr(ipage); 595 inline_dentry = inline_data_addr(ipage);
596 bit_pos = find_next_bit_le(&dentry_blk->dentry_bitmap, 596 bit_pos = find_next_bit_le(&inline_dentry->dentry_bitmap,
597 NR_INLINE_DENTRY, 597 NR_INLINE_DENTRY,
598 bit_pos); 598 bit_pos);
599 599
diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c
index 518f49643092..6cd312a17c69 100644
--- a/fs/f2fs/inode.c
+++ b/fs/f2fs/inode.c
@@ -16,6 +16,7 @@
16 16
17#include "f2fs.h" 17#include "f2fs.h"
18#include "node.h" 18#include "node.h"
19#include "segment.h"
19 20
20#include <trace/events/f2fs.h> 21#include <trace/events/f2fs.h>
21 22
@@ -44,7 +45,6 @@ void f2fs_set_inode_flags(struct inode *inode)
44 new_fl |= S_DIRSYNC; 45 new_fl |= S_DIRSYNC;
45 inode_set_flags(inode, new_fl, 46 inode_set_flags(inode, new_fl,
46 S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC); 47 S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);
47 f2fs_mark_inode_dirty_sync(inode, false);
48} 48}
49 49
50static void __get_inode_rdev(struct inode *inode, struct f2fs_inode *ri) 50static void __get_inode_rdev(struct inode *inode, struct f2fs_inode *ri)
@@ -130,7 +130,7 @@ static int do_read_inode(struct inode *inode)
130 i_gid_write(inode, le32_to_cpu(ri->i_gid)); 130 i_gid_write(inode, le32_to_cpu(ri->i_gid));
131 set_nlink(inode, le32_to_cpu(ri->i_links)); 131 set_nlink(inode, le32_to_cpu(ri->i_links));
132 inode->i_size = le64_to_cpu(ri->i_size); 132 inode->i_size = le64_to_cpu(ri->i_size);
133 inode->i_blocks = le64_to_cpu(ri->i_blocks); 133 inode->i_blocks = SECTOR_FROM_BLOCK(le64_to_cpu(ri->i_blocks) - 1);
134 134
135 inode->i_atime.tv_sec = le64_to_cpu(ri->i_atime); 135 inode->i_atime.tv_sec = le64_to_cpu(ri->i_atime);
136 inode->i_ctime.tv_sec = le64_to_cpu(ri->i_ctime); 136 inode->i_ctime.tv_sec = le64_to_cpu(ri->i_ctime);
@@ -226,6 +226,7 @@ make_now:
226 ret = -EIO; 226 ret = -EIO;
227 goto bad_inode; 227 goto bad_inode;
228 } 228 }
229 f2fs_set_inode_flags(inode);
229 unlock_new_inode(inode); 230 unlock_new_inode(inode);
230 trace_f2fs_iget(inode); 231 trace_f2fs_iget(inode);
231 return inode; 232 return inode;
@@ -267,7 +268,7 @@ int update_inode(struct inode *inode, struct page *node_page)
267 ri->i_gid = cpu_to_le32(i_gid_read(inode)); 268 ri->i_gid = cpu_to_le32(i_gid_read(inode));
268 ri->i_links = cpu_to_le32(inode->i_nlink); 269 ri->i_links = cpu_to_le32(inode->i_nlink);
269 ri->i_size = cpu_to_le64(i_size_read(inode)); 270 ri->i_size = cpu_to_le64(i_size_read(inode));
270 ri->i_blocks = cpu_to_le64(inode->i_blocks); 271 ri->i_blocks = cpu_to_le64(SECTOR_TO_BLOCK(inode->i_blocks) + 1);
271 272
272 if (et) { 273 if (et) {
273 read_lock(&et->lock); 274 read_lock(&et->lock);
@@ -372,6 +373,8 @@ void f2fs_evict_inode(struct inode *inode)
372 if (inode->i_nlink || is_bad_inode(inode)) 373 if (inode->i_nlink || is_bad_inode(inode))
373 goto no_delete; 374 goto no_delete;
374 375
376 dquot_initialize(inode);
377
375 remove_ino_entry(sbi, inode->i_ino, APPEND_INO); 378 remove_ino_entry(sbi, inode->i_ino, APPEND_INO);
376 remove_ino_entry(sbi, inode->i_ino, UPDATE_INO); 379 remove_ino_entry(sbi, inode->i_ino, UPDATE_INO);
377 380
@@ -404,8 +407,11 @@ retry:
404 407
405 if (err) 408 if (err)
406 update_inode_page(inode); 409 update_inode_page(inode);
410 dquot_free_inode(inode);
407 sb_end_intwrite(inode->i_sb); 411 sb_end_intwrite(inode->i_sb);
408no_delete: 412no_delete:
413 dquot_drop(inode);
414
409 stat_dec_inline_xattr(inode); 415 stat_dec_inline_xattr(inode);
410 stat_dec_inline_dir(inode); 416 stat_dec_inline_dir(inode);
411 stat_dec_inline_inode(inode); 417 stat_dec_inline_inode(inode);
@@ -425,9 +431,10 @@ no_delete:
425 if (is_inode_flag_set(inode, FI_FREE_NID)) { 431 if (is_inode_flag_set(inode, FI_FREE_NID)) {
426 alloc_nid_failed(sbi, inode->i_ino); 432 alloc_nid_failed(sbi, inode->i_ino);
427 clear_inode_flag(inode, FI_FREE_NID); 433 clear_inode_flag(inode, FI_FREE_NID);
434 } else {
435 f2fs_bug_on(sbi, err &&
436 !exist_written_data(sbi, inode->i_ino, ORPHAN_INO));
428 } 437 }
429 f2fs_bug_on(sbi, err &&
430 !exist_written_data(sbi, inode->i_ino, ORPHAN_INO));
431out_clear: 438out_clear:
432 fscrypt_put_encryption_info(inode, NULL); 439 fscrypt_put_encryption_info(inode, NULL);
433 clear_inode(inode); 440 clear_inode(inode);
diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c
index c31b40e5f9cf..760d85223c81 100644
--- a/fs/f2fs/namei.c
+++ b/fs/f2fs/namei.c
@@ -15,6 +15,7 @@
15#include <linux/ctype.h> 15#include <linux/ctype.h>
16#include <linux/dcache.h> 16#include <linux/dcache.h>
17#include <linux/namei.h> 17#include <linux/namei.h>
18#include <linux/quotaops.h>
18 19
19#include "f2fs.h" 20#include "f2fs.h"
20#include "node.h" 21#include "node.h"
@@ -42,6 +43,8 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
42 } 43 }
43 f2fs_unlock_op(sbi); 44 f2fs_unlock_op(sbi);
44 45
46 nid_free = true;
47
45 inode_init_owner(inode, dir, mode); 48 inode_init_owner(inode, dir, mode);
46 49
47 inode->i_ino = ino; 50 inode->i_ino = ino;
@@ -52,10 +55,17 @@ static struct inode *f2fs_new_inode(struct inode *dir, umode_t mode)
52 err = insert_inode_locked(inode); 55 err = insert_inode_locked(inode);
53 if (err) { 56 if (err) {
54 err = -EINVAL; 57 err = -EINVAL;
55 nid_free = true;
56 goto fail; 58 goto fail;
57 } 59 }
58 60
61 err = dquot_initialize(inode);
62 if (err)
63 goto fail_drop;
64
65 err = dquot_alloc_inode(inode);
66 if (err)
67 goto fail_drop;
68
59 /* If the directory encrypted, then we should encrypt the inode. */ 69 /* If the directory encrypted, then we should encrypt the inode. */
60 if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode)) 70 if (f2fs_encrypted_inode(dir) && f2fs_may_encrypt(inode))
61 f2fs_set_encrypted_inode(inode); 71 f2fs_set_encrypted_inode(inode);
@@ -85,6 +95,16 @@ fail:
85 set_inode_flag(inode, FI_FREE_NID); 95 set_inode_flag(inode, FI_FREE_NID);
86 iput(inode); 96 iput(inode);
87 return ERR_PTR(err); 97 return ERR_PTR(err);
98fail_drop:
99 trace_f2fs_new_inode(inode, err);
100 dquot_drop(inode);
101 inode->i_flags |= S_NOQUOTA;
102 if (nid_free)
103 set_inode_flag(inode, FI_FREE_NID);
104 clear_nlink(inode);
105 unlock_new_inode(inode);
106 iput(inode);
107 return ERR_PTR(err);
88} 108}
89 109
90static int is_multimedia_file(const unsigned char *s, const char *sub) 110static int is_multimedia_file(const unsigned char *s, const char *sub)
@@ -136,6 +156,10 @@ static int f2fs_create(struct inode *dir, struct dentry *dentry, umode_t mode,
136 nid_t ino = 0; 156 nid_t ino = 0;
137 int err; 157 int err;
138 158
159 err = dquot_initialize(dir);
160 if (err)
161 return err;
162
139 inode = f2fs_new_inode(dir, mode); 163 inode = f2fs_new_inode(dir, mode);
140 if (IS_ERR(inode)) 164 if (IS_ERR(inode))
141 return PTR_ERR(inode); 165 return PTR_ERR(inode);
@@ -180,6 +204,10 @@ static int f2fs_link(struct dentry *old_dentry, struct inode *dir,
180 !fscrypt_has_permitted_context(dir, inode)) 204 !fscrypt_has_permitted_context(dir, inode))
181 return -EPERM; 205 return -EPERM;
182 206
207 err = dquot_initialize(dir);
208 if (err)
209 return err;
210
183 f2fs_balance_fs(sbi, true); 211 f2fs_balance_fs(sbi, true);
184 212
185 inode->i_ctime = current_time(inode); 213 inode->i_ctime = current_time(inode);
@@ -347,6 +375,10 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry)
347 375
348 trace_f2fs_unlink_enter(dir, dentry); 376 trace_f2fs_unlink_enter(dir, dentry);
349 377
378 err = dquot_initialize(dir);
379 if (err)
380 return err;
381
350 de = f2fs_find_entry(dir, &dentry->d_name, &page); 382 de = f2fs_find_entry(dir, &dentry->d_name, &page);
351 if (!de) { 383 if (!de) {
352 if (IS_ERR(page)) 384 if (IS_ERR(page))
@@ -413,6 +445,10 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
413 if (disk_link.len > dir->i_sb->s_blocksize) 445 if (disk_link.len > dir->i_sb->s_blocksize)
414 return -ENAMETOOLONG; 446 return -ENAMETOOLONG;
415 447
448 err = dquot_initialize(dir);
449 if (err)
450 return err;
451
416 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO); 452 inode = f2fs_new_inode(dir, S_IFLNK | S_IRWXUGO);
417 if (IS_ERR(inode)) 453 if (IS_ERR(inode))
418 return PTR_ERR(inode); 454 return PTR_ERR(inode);
@@ -500,6 +536,10 @@ static int f2fs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
500 struct inode *inode; 536 struct inode *inode;
501 int err; 537 int err;
502 538
539 err = dquot_initialize(dir);
540 if (err)
541 return err;
542
503 inode = f2fs_new_inode(dir, S_IFDIR | mode); 543 inode = f2fs_new_inode(dir, S_IFDIR | mode);
504 if (IS_ERR(inode)) 544 if (IS_ERR(inode))
505 return PTR_ERR(inode); 545 return PTR_ERR(inode);
@@ -548,6 +588,10 @@ static int f2fs_mknod(struct inode *dir, struct dentry *dentry,
548 struct inode *inode; 588 struct inode *inode;
549 int err = 0; 589 int err = 0;
550 590
591 err = dquot_initialize(dir);
592 if (err)
593 return err;
594
551 inode = f2fs_new_inode(dir, mode); 595 inode = f2fs_new_inode(dir, mode);
552 if (IS_ERR(inode)) 596 if (IS_ERR(inode))
553 return PTR_ERR(inode); 597 return PTR_ERR(inode);
@@ -583,6 +627,10 @@ static int __f2fs_tmpfile(struct inode *dir, struct dentry *dentry,
583 struct inode *inode; 627 struct inode *inode;
584 int err; 628 int err;
585 629
630 err = dquot_initialize(dir);
631 if (err)
632 return err;
633
586 inode = f2fs_new_inode(dir, mode); 634 inode = f2fs_new_inode(dir, mode);
587 if (IS_ERR(inode)) 635 if (IS_ERR(inode))
588 return PTR_ERR(inode); 636 return PTR_ERR(inode);
@@ -676,6 +724,14 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
676 goto out; 724 goto out;
677 } 725 }
678 726
727 err = dquot_initialize(old_dir);
728 if (err)
729 goto out;
730
731 err = dquot_initialize(new_dir);
732 if (err)
733 goto out;
734
679 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); 735 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
680 if (!old_entry) { 736 if (!old_entry) {
681 if (IS_ERR(old_page)) 737 if (IS_ERR(old_page))
@@ -772,7 +828,10 @@ static int f2fs_rename(struct inode *old_dir, struct dentry *old_dentry,
772 } 828 }
773 829
774 down_write(&F2FS_I(old_inode)->i_sem); 830 down_write(&F2FS_I(old_inode)->i_sem);
775 file_lost_pino(old_inode); 831 if (!old_dir_entry || whiteout)
832 file_lost_pino(old_inode);
833 else
834 F2FS_I(old_inode)->i_pino = new_dir->i_ino;
776 up_write(&F2FS_I(old_inode)->i_sem); 835 up_write(&F2FS_I(old_inode)->i_sem);
777 836
778 old_inode->i_ctime = current_time(old_inode); 837 old_inode->i_ctime = current_time(old_inode);
@@ -853,6 +912,14 @@ static int f2fs_cross_rename(struct inode *old_dir, struct dentry *old_dentry,
853 !fscrypt_has_permitted_context(old_dir, new_inode))) 912 !fscrypt_has_permitted_context(old_dir, new_inode)))
854 return -EPERM; 913 return -EPERM;
855 914
915 err = dquot_initialize(old_dir);
916 if (err)
917 goto out;
918
919 err = dquot_initialize(new_dir);
920 if (err)
921 goto out;
922
856 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page); 923 old_entry = f2fs_find_entry(old_dir, &old_dentry->d_name, &old_page);
857 if (!old_entry) { 924 if (!old_entry) {
858 if (IS_ERR(old_page)) 925 if (IS_ERR(old_page))
diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c
index 4547c5c5cd98..d53fe620939e 100644
--- a/fs/f2fs/node.c
+++ b/fs/f2fs/node.c
@@ -158,9 +158,6 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
158 nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid); 158 nid_t set = NAT_BLOCK_OFFSET(ne->ni.nid);
159 struct nat_entry_set *head; 159 struct nat_entry_set *head;
160 160
161 if (get_nat_flag(ne, IS_DIRTY))
162 return;
163
164 head = radix_tree_lookup(&nm_i->nat_set_root, set); 161 head = radix_tree_lookup(&nm_i->nat_set_root, set);
165 if (!head) { 162 if (!head) {
166 head = f2fs_kmem_cache_alloc(nat_entry_set_slab, GFP_NOFS); 163 head = f2fs_kmem_cache_alloc(nat_entry_set_slab, GFP_NOFS);
@@ -171,10 +168,18 @@ static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i,
171 head->entry_cnt = 0; 168 head->entry_cnt = 0;
172 f2fs_radix_tree_insert(&nm_i->nat_set_root, set, head); 169 f2fs_radix_tree_insert(&nm_i->nat_set_root, set, head);
173 } 170 }
174 list_move_tail(&ne->list, &head->entry_list); 171
172 if (get_nat_flag(ne, IS_DIRTY))
173 goto refresh_list;
174
175 nm_i->dirty_nat_cnt++; 175 nm_i->dirty_nat_cnt++;
176 head->entry_cnt++; 176 head->entry_cnt++;
177 set_nat_flag(ne, IS_DIRTY, true); 177 set_nat_flag(ne, IS_DIRTY, true);
178refresh_list:
179 if (nat_get_blkaddr(ne) == NEW_ADDR)
180 list_del_init(&ne->list);
181 else
182 list_move_tail(&ne->list, &head->entry_list);
178} 183}
179 184
180static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i, 185static void __clear_nat_cache_dirty(struct f2fs_nm_info *nm_i,
@@ -673,15 +678,11 @@ static void truncate_node(struct dnode_of_data *dn)
673 struct node_info ni; 678 struct node_info ni;
674 679
675 get_node_info(sbi, dn->nid, &ni); 680 get_node_info(sbi, dn->nid, &ni);
676 if (dn->inode->i_blocks == 0) {
677 f2fs_bug_on(sbi, ni.blk_addr != NULL_ADDR);
678 goto invalidate;
679 }
680 f2fs_bug_on(sbi, ni.blk_addr == NULL_ADDR); 681 f2fs_bug_on(sbi, ni.blk_addr == NULL_ADDR);
681 682
682 /* Deallocate node address */ 683 /* Deallocate node address */
683 invalidate_blocks(sbi, ni.blk_addr); 684 invalidate_blocks(sbi, ni.blk_addr);
684 dec_valid_node_count(sbi, dn->inode); 685 dec_valid_node_count(sbi, dn->inode, dn->nid == dn->inode->i_ino);
685 set_node_addr(sbi, &ni, NULL_ADDR, false); 686 set_node_addr(sbi, &ni, NULL_ADDR, false);
686 687
687 if (dn->nid == dn->inode->i_ino) { 688 if (dn->nid == dn->inode->i_ino) {
@@ -689,7 +690,7 @@ static void truncate_node(struct dnode_of_data *dn)
689 dec_valid_inode_count(sbi); 690 dec_valid_inode_count(sbi);
690 f2fs_inode_synced(dn->inode); 691 f2fs_inode_synced(dn->inode);
691 } 692 }
692invalidate: 693
693 clear_node_page_dirty(dn->node_page); 694 clear_node_page_dirty(dn->node_page);
694 set_sbi_flag(sbi, SBI_IS_DIRTY); 695 set_sbi_flag(sbi, SBI_IS_DIRTY);
695 696
@@ -1006,7 +1007,7 @@ int remove_inode_page(struct inode *inode)
1006 1007
1007 /* 0 is possible, after f2fs_new_inode() has failed */ 1008 /* 0 is possible, after f2fs_new_inode() has failed */
1008 f2fs_bug_on(F2FS_I_SB(inode), 1009 f2fs_bug_on(F2FS_I_SB(inode),
1009 inode->i_blocks != 0 && inode->i_blocks != 1); 1010 inode->i_blocks != 0 && inode->i_blocks != 8);
1010 1011
1011 /* will put inode & node pages */ 1012 /* will put inode & node pages */
1012 truncate_node(&dn); 1013 truncate_node(&dn);
@@ -1039,10 +1040,9 @@ struct page *new_node_page(struct dnode_of_data *dn,
1039 if (!page) 1040 if (!page)
1040 return ERR_PTR(-ENOMEM); 1041 return ERR_PTR(-ENOMEM);
1041 1042
1042 if (unlikely(!inc_valid_node_count(sbi, dn->inode))) { 1043 if (unlikely((err = inc_valid_node_count(sbi, dn->inode, !ofs))))
1043 err = -ENOSPC;
1044 goto fail; 1044 goto fail;
1045 } 1045
1046#ifdef CONFIG_F2FS_CHECK_FS 1046#ifdef CONFIG_F2FS_CHECK_FS
1047 get_node_info(sbi, dn->nid, &new_ni); 1047 get_node_info(sbi, dn->nid, &new_ni);
1048 f2fs_bug_on(sbi, new_ni.blk_addr != NULL_ADDR); 1048 f2fs_bug_on(sbi, new_ni.blk_addr != NULL_ADDR);
@@ -1152,6 +1152,7 @@ repeat:
1152 f2fs_put_page(page, 1); 1152 f2fs_put_page(page, 1);
1153 return ERR_PTR(err); 1153 return ERR_PTR(err);
1154 } else if (err == LOCKED_PAGE) { 1154 } else if (err == LOCKED_PAGE) {
1155 err = 0;
1155 goto page_hit; 1156 goto page_hit;
1156 } 1157 }
1157 1158
@@ -1165,15 +1166,22 @@ repeat:
1165 goto repeat; 1166 goto repeat;
1166 } 1167 }
1167 1168
1168 if (unlikely(!PageUptodate(page))) 1169 if (unlikely(!PageUptodate(page))) {
1170 err = -EIO;
1169 goto out_err; 1171 goto out_err;
1172 }
1170page_hit: 1173page_hit:
1171 if(unlikely(nid != nid_of_node(page))) { 1174 if(unlikely(nid != nid_of_node(page))) {
1172 f2fs_bug_on(sbi, 1); 1175 f2fs_msg(sbi->sb, KERN_WARNING, "inconsistent node block, "
1176 "nid:%lu, node_footer[nid:%u,ino:%u,ofs:%u,cpver:%llu,blkaddr:%u]",
1177 nid, nid_of_node(page), ino_of_node(page),
1178 ofs_of_node(page), cpver_of_node(page),
1179 next_blkaddr_of_node(page));
1173 ClearPageUptodate(page); 1180 ClearPageUptodate(page);
1181 err = -EINVAL;
1174out_err: 1182out_err:
1175 f2fs_put_page(page, 1); 1183 f2fs_put_page(page, 1);
1176 return ERR_PTR(-EIO); 1184 return ERR_PTR(err);
1177 } 1185 }
1178 return page; 1186 return page;
1179} 1187}
@@ -1373,15 +1381,15 @@ static int __write_node_page(struct page *page, bool atomic, bool *submitted,
1373 up_read(&sbi->node_write); 1381 up_read(&sbi->node_write);
1374 1382
1375 if (wbc->for_reclaim) { 1383 if (wbc->for_reclaim) {
1376 f2fs_submit_merged_bio_cond(sbi, page->mapping->host, 0, 1384 f2fs_submit_merged_write_cond(sbi, page->mapping->host, 0,
1377 page->index, NODE, WRITE); 1385 page->index, NODE);
1378 submitted = NULL; 1386 submitted = NULL;
1379 } 1387 }
1380 1388
1381 unlock_page(page); 1389 unlock_page(page);
1382 1390
1383 if (unlikely(f2fs_cp_error(sbi))) { 1391 if (unlikely(f2fs_cp_error(sbi))) {
1384 f2fs_submit_merged_bio(sbi, NODE, WRITE); 1392 f2fs_submit_merged_write(sbi, NODE);
1385 submitted = NULL; 1393 submitted = NULL;
1386 } 1394 }
1387 if (submitted) 1395 if (submitted)
@@ -1518,8 +1526,7 @@ continue_unlock:
1518 } 1526 }
1519out: 1527out:
1520 if (last_idx != ULONG_MAX) 1528 if (last_idx != ULONG_MAX)
1521 f2fs_submit_merged_bio_cond(sbi, NULL, ino, last_idx, 1529 f2fs_submit_merged_write_cond(sbi, NULL, ino, last_idx, NODE);
1522 NODE, WRITE);
1523 return ret ? -EIO: 0; 1530 return ret ? -EIO: 0;
1524} 1531}
1525 1532
@@ -1625,7 +1632,7 @@ continue_unlock:
1625 } 1632 }
1626out: 1633out:
1627 if (nwritten) 1634 if (nwritten)
1628 f2fs_submit_merged_bio(sbi, NODE, WRITE); 1635 f2fs_submit_merged_write(sbi, NODE);
1629 return ret; 1636 return ret;
1630} 1637}
1631 1638
@@ -1675,6 +1682,9 @@ static int f2fs_write_node_pages(struct address_space *mapping,
1675 struct blk_plug plug; 1682 struct blk_plug plug;
1676 long diff; 1683 long diff;
1677 1684
1685 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
1686 goto skip_write;
1687
1678 /* balancing f2fs's metadata in background */ 1688 /* balancing f2fs's metadata in background */
1679 f2fs_balance_fs_bg(sbi); 1689 f2fs_balance_fs_bg(sbi);
1680 1690
@@ -2192,14 +2202,14 @@ int recover_xattr_data(struct inode *inode, struct page *page, block_t blkaddr)
2192 get_node_info(sbi, prev_xnid, &ni); 2202 get_node_info(sbi, prev_xnid, &ni);
2193 f2fs_bug_on(sbi, ni.blk_addr == NULL_ADDR); 2203 f2fs_bug_on(sbi, ni.blk_addr == NULL_ADDR);
2194 invalidate_blocks(sbi, ni.blk_addr); 2204 invalidate_blocks(sbi, ni.blk_addr);
2195 dec_valid_node_count(sbi, inode); 2205 dec_valid_node_count(sbi, inode, false);
2196 set_node_addr(sbi, &ni, NULL_ADDR, false); 2206 set_node_addr(sbi, &ni, NULL_ADDR, false);
2197 2207
2198recover_xnid: 2208recover_xnid:
2199 /* 2: update xattr nid in inode */ 2209 /* 2: update xattr nid in inode */
2200 remove_free_nid(sbi, new_xnid); 2210 remove_free_nid(sbi, new_xnid);
2201 f2fs_i_xnid_write(inode, new_xnid); 2211 f2fs_i_xnid_write(inode, new_xnid);
2202 if (unlikely(!inc_valid_node_count(sbi, inode))) 2212 if (unlikely(inc_valid_node_count(sbi, inode, false)))
2203 f2fs_bug_on(sbi, 1); 2213 f2fs_bug_on(sbi, 1);
2204 update_inode_page(inode); 2214 update_inode_page(inode);
2205 2215
@@ -2257,7 +2267,7 @@ retry:
2257 new_ni = old_ni; 2267 new_ni = old_ni;
2258 new_ni.ino = ino; 2268 new_ni.ino = ino;
2259 2269
2260 if (unlikely(!inc_valid_node_count(sbi, NULL))) 2270 if (unlikely(inc_valid_node_count(sbi, NULL, true)))
2261 WARN_ON(1); 2271 WARN_ON(1);
2262 set_node_addr(sbi, &new_ni, NEW_ADDR, false); 2272 set_node_addr(sbi, &new_ni, NEW_ADDR, false);
2263 inc_valid_inode_count(sbi); 2273 inc_valid_inode_count(sbi);
@@ -2424,8 +2434,7 @@ static void __flush_nat_entry_set(struct f2fs_sb_info *sbi,
2424 nid_t nid = nat_get_nid(ne); 2434 nid_t nid = nat_get_nid(ne);
2425 int offset; 2435 int offset;
2426 2436
2427 if (nat_get_blkaddr(ne) == NEW_ADDR) 2437 f2fs_bug_on(sbi, nat_get_blkaddr(ne) == NEW_ADDR);
2428 continue;
2429 2438
2430 if (to_journal) { 2439 if (to_journal) {
2431 offset = lookup_journal_in_cursum(journal, 2440 offset = lookup_journal_in_cursum(journal,
@@ -2553,7 +2562,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi)
2553 return 0; 2562 return 0;
2554} 2563}
2555 2564
2556inline void load_free_nid_bitmap(struct f2fs_sb_info *sbi) 2565static inline void load_free_nid_bitmap(struct f2fs_sb_info *sbi)
2557{ 2566{
2558 struct f2fs_nm_info *nm_i = NM_I(sbi); 2567 struct f2fs_nm_info *nm_i = NM_I(sbi);
2559 unsigned int i = 0; 2568 unsigned int i = 0;
diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h
index 558048e33cf9..bb53e9955ff2 100644
--- a/fs/f2fs/node.h
+++ b/fs/f2fs/node.h
@@ -224,11 +224,7 @@ static inline pgoff_t next_nat_addr(struct f2fs_sb_info *sbi,
224 struct f2fs_nm_info *nm_i = NM_I(sbi); 224 struct f2fs_nm_info *nm_i = NM_I(sbi);
225 225
226 block_addr -= nm_i->nat_blkaddr; 226 block_addr -= nm_i->nat_blkaddr;
227 if ((block_addr >> sbi->log_blocks_per_seg) % 2) 227 block_addr ^= 1 << sbi->log_blocks_per_seg;
228 block_addr -= sbi->blocks_per_seg;
229 else
230 block_addr += sbi->blocks_per_seg;
231
232 return block_addr + nm_i->nat_blkaddr; 228 return block_addr + nm_i->nat_blkaddr;
233} 229}
234 230
diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c
index ea9f455d94ba..f964b68718c1 100644
--- a/fs/f2fs/segment.c
+++ b/fs/f2fs/segment.c
@@ -16,6 +16,7 @@
16#include <linux/kthread.h> 16#include <linux/kthread.h>
17#include <linux/swap.h> 17#include <linux/swap.h>
18#include <linux/timer.h> 18#include <linux/timer.h>
19#include <linux/freezer.h>
19 20
20#include "f2fs.h" 21#include "f2fs.h"
21#include "segment.h" 22#include "segment.h"
@@ -312,7 +313,7 @@ static int __commit_inmem_pages(struct inode *inode,
312 fio.page = page; 313 fio.page = page;
313 fio.old_blkaddr = NULL_ADDR; 314 fio.old_blkaddr = NULL_ADDR;
314 fio.encrypted_page = NULL; 315 fio.encrypted_page = NULL;
315 fio.need_lock = false, 316 fio.need_lock = LOCK_DONE;
316 err = do_write_data_page(&fio); 317 err = do_write_data_page(&fio);
317 if (err) { 318 if (err) {
318 unlock_page(page); 319 unlock_page(page);
@@ -328,8 +329,7 @@ static int __commit_inmem_pages(struct inode *inode,
328 } 329 }
329 330
330 if (last_idx != ULONG_MAX) 331 if (last_idx != ULONG_MAX)
331 f2fs_submit_merged_bio_cond(sbi, inode, 0, last_idx, 332 f2fs_submit_merged_write_cond(sbi, inode, 0, last_idx, DATA);
332 DATA, WRITE);
333 333
334 if (!err) 334 if (!err)
335 __revoke_inmem_pages(inode, revoke_list, false, false); 335 __revoke_inmem_pages(inode, revoke_list, false, false);
@@ -555,6 +555,8 @@ int create_flush_cmd_control(struct f2fs_sb_info *sbi)
555 555
556 if (SM_I(sbi)->fcc_info) { 556 if (SM_I(sbi)->fcc_info) {
557 fcc = SM_I(sbi)->fcc_info; 557 fcc = SM_I(sbi)->fcc_info;
558 if (fcc->f2fs_issue_flush)
559 return err;
558 goto init_thread; 560 goto init_thread;
559 } 561 }
560 562
@@ -566,6 +568,9 @@ int create_flush_cmd_control(struct f2fs_sb_info *sbi)
566 init_waitqueue_head(&fcc->flush_wait_queue); 568 init_waitqueue_head(&fcc->flush_wait_queue);
567 init_llist_head(&fcc->issue_list); 569 init_llist_head(&fcc->issue_list);
568 SM_I(sbi)->fcc_info = fcc; 570 SM_I(sbi)->fcc_info = fcc;
571 if (!test_opt(sbi, FLUSH_MERGE))
572 return err;
573
569init_thread: 574init_thread:
570 fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi, 575 fcc->f2fs_issue_flush = kthread_run(issue_flush_thread, sbi,
571 "f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev)); 576 "f2fs_flush-%u:%u", MAJOR(dev), MINOR(dev));
@@ -736,12 +741,15 @@ static void __remove_discard_cmd(struct f2fs_sb_info *sbi,
736{ 741{
737 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 742 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
738 743
744 f2fs_bug_on(sbi, dc->ref);
745
739 if (dc->error == -EOPNOTSUPP) 746 if (dc->error == -EOPNOTSUPP)
740 dc->error = 0; 747 dc->error = 0;
741 748
742 if (dc->error) 749 if (dc->error)
743 f2fs_msg(sbi->sb, KERN_INFO, 750 f2fs_msg(sbi->sb, KERN_INFO,
744 "Issue discard failed, ret: %d", dc->error); 751 "Issue discard(%u, %u, %u) failed, ret: %d",
752 dc->lstart, dc->start, dc->len, dc->error);
745 __detach_discard_cmd(dcc, dc); 753 __detach_discard_cmd(dcc, dc);
746} 754}
747 755
@@ -751,10 +759,34 @@ static void f2fs_submit_discard_endio(struct bio *bio)
751 759
752 dc->error = blk_status_to_errno(bio->bi_status); 760 dc->error = blk_status_to_errno(bio->bi_status);
753 dc->state = D_DONE; 761 dc->state = D_DONE;
754 complete(&dc->wait); 762 complete_all(&dc->wait);
755 bio_put(bio); 763 bio_put(bio);
756} 764}
757 765
766void __check_sit_bitmap(struct f2fs_sb_info *sbi,
767 block_t start, block_t end)
768{
769#ifdef CONFIG_F2FS_CHECK_FS
770 struct seg_entry *sentry;
771 unsigned int segno;
772 block_t blk = start;
773 unsigned long offset, size, max_blocks = sbi->blocks_per_seg;
774 unsigned long *map;
775
776 while (blk < end) {
777 segno = GET_SEGNO(sbi, blk);
778 sentry = get_seg_entry(sbi, segno);
779 offset = GET_BLKOFF_FROM_SEG0(sbi, blk);
780
781 size = min((unsigned long)(end - blk), max_blocks);
782 map = (unsigned long *)(sentry->cur_valid_map);
783 offset = __find_rev_next_bit(map, size, offset);
784 f2fs_bug_on(sbi, offset != size);
785 blk += size;
786 }
787#endif
788}
789
758/* this function is copied from blkdev_issue_discard from block/blk-lib.c */ 790/* this function is copied from blkdev_issue_discard from block/blk-lib.c */
759static void __submit_discard_cmd(struct f2fs_sb_info *sbi, 791static void __submit_discard_cmd(struct f2fs_sb_info *sbi,
760 struct discard_cmd *dc) 792 struct discard_cmd *dc)
@@ -782,6 +814,7 @@ static void __submit_discard_cmd(struct f2fs_sb_info *sbi,
782 bio->bi_opf |= REQ_SYNC; 814 bio->bi_opf |= REQ_SYNC;
783 submit_bio(bio); 815 submit_bio(bio);
784 list_move_tail(&dc->list, &dcc->wait_list); 816 list_move_tail(&dc->list, &dcc->wait_list);
817 __check_sit_bitmap(sbi, dc->start, dc->start + dc->len);
785 } 818 }
786 } else { 819 } else {
787 __remove_discard_cmd(sbi, dc); 820 __remove_discard_cmd(sbi, dc);
@@ -838,7 +871,6 @@ static void __punch_discard_cmd(struct f2fs_sb_info *sbi,
838 dc->len = blkaddr - dc->lstart; 871 dc->len = blkaddr - dc->lstart;
839 dcc->undiscard_blks += dc->len; 872 dcc->undiscard_blks += dc->len;
840 __relocate_discard_cmd(dcc, dc); 873 __relocate_discard_cmd(dcc, dc);
841 f2fs_bug_on(sbi, !__check_rb_tree_consistence(sbi, &dcc->root));
842 modified = true; 874 modified = true;
843 } 875 }
844 876
@@ -848,16 +880,12 @@ static void __punch_discard_cmd(struct f2fs_sb_info *sbi,
848 di.start + blkaddr + 1 - di.lstart, 880 di.start + blkaddr + 1 - di.lstart,
849 di.lstart + di.len - 1 - blkaddr, 881 di.lstart + di.len - 1 - blkaddr,
850 NULL, NULL); 882 NULL, NULL);
851 f2fs_bug_on(sbi,
852 !__check_rb_tree_consistence(sbi, &dcc->root));
853 } else { 883 } else {
854 dc->lstart++; 884 dc->lstart++;
855 dc->len--; 885 dc->len--;
856 dc->start++; 886 dc->start++;
857 dcc->undiscard_blks += dc->len; 887 dcc->undiscard_blks += dc->len;
858 __relocate_discard_cmd(dcc, dc); 888 __relocate_discard_cmd(dcc, dc);
859 f2fs_bug_on(sbi,
860 !__check_rb_tree_consistence(sbi, &dcc->root));
861 } 889 }
862 } 890 }
863} 891}
@@ -918,8 +946,6 @@ static void __update_discard_tree_range(struct f2fs_sb_info *sbi,
918 prev_dc->di.len += di.len; 946 prev_dc->di.len += di.len;
919 dcc->undiscard_blks += di.len; 947 dcc->undiscard_blks += di.len;
920 __relocate_discard_cmd(dcc, prev_dc); 948 __relocate_discard_cmd(dcc, prev_dc);
921 f2fs_bug_on(sbi,
922 !__check_rb_tree_consistence(sbi, &dcc->root));
923 di = prev_dc->di; 949 di = prev_dc->di;
924 tdc = prev_dc; 950 tdc = prev_dc;
925 merged = true; 951 merged = true;
@@ -935,16 +961,12 @@ static void __update_discard_tree_range(struct f2fs_sb_info *sbi,
935 __relocate_discard_cmd(dcc, next_dc); 961 __relocate_discard_cmd(dcc, next_dc);
936 if (tdc) 962 if (tdc)
937 __remove_discard_cmd(sbi, tdc); 963 __remove_discard_cmd(sbi, tdc);
938 f2fs_bug_on(sbi,
939 !__check_rb_tree_consistence(sbi, &dcc->root));
940 merged = true; 964 merged = true;
941 } 965 }
942 966
943 if (!merged) { 967 if (!merged) {
944 __insert_discard_tree(sbi, bdev, di.lstart, di.start, 968 __insert_discard_tree(sbi, bdev, di.lstart, di.start,
945 di.len, NULL, NULL); 969 di.len, NULL, NULL);
946 f2fs_bug_on(sbi,
947 !__check_rb_tree_consistence(sbi, &dcc->root));
948 } 970 }
949 next: 971 next:
950 prev_dc = next_dc; 972 prev_dc = next_dc;
@@ -983,6 +1005,8 @@ static void __issue_discard_cmd(struct f2fs_sb_info *sbi, bool issue_cond)
983 int i, iter = 0; 1005 int i, iter = 0;
984 1006
985 mutex_lock(&dcc->cmd_lock); 1007 mutex_lock(&dcc->cmd_lock);
1008 f2fs_bug_on(sbi,
1009 !__check_rb_tree_consistence(sbi, &dcc->root));
986 blk_start_plug(&plug); 1010 blk_start_plug(&plug);
987 for (i = MAX_PLIST_NUM - 1; i >= 0; i--) { 1011 for (i = MAX_PLIST_NUM - 1; i >= 0; i--) {
988 pend_list = &dcc->pend_list[i]; 1012 pend_list = &dcc->pend_list[i];
@@ -1000,22 +1024,47 @@ out:
1000 mutex_unlock(&dcc->cmd_lock); 1024 mutex_unlock(&dcc->cmd_lock);
1001} 1025}
1002 1026
1027static void __wait_one_discard_bio(struct f2fs_sb_info *sbi,
1028 struct discard_cmd *dc)
1029{
1030 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
1031
1032 wait_for_completion_io(&dc->wait);
1033 mutex_lock(&dcc->cmd_lock);
1034 f2fs_bug_on(sbi, dc->state != D_DONE);
1035 dc->ref--;
1036 if (!dc->ref)
1037 __remove_discard_cmd(sbi, dc);
1038 mutex_unlock(&dcc->cmd_lock);
1039}
1040
1003static void __wait_discard_cmd(struct f2fs_sb_info *sbi, bool wait_cond) 1041static void __wait_discard_cmd(struct f2fs_sb_info *sbi, bool wait_cond)
1004{ 1042{
1005 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 1043 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
1006 struct list_head *wait_list = &(dcc->wait_list); 1044 struct list_head *wait_list = &(dcc->wait_list);
1007 struct discard_cmd *dc, *tmp; 1045 struct discard_cmd *dc, *tmp;
1046 bool need_wait;
1047
1048next:
1049 need_wait = false;
1008 1050
1009 mutex_lock(&dcc->cmd_lock); 1051 mutex_lock(&dcc->cmd_lock);
1010 list_for_each_entry_safe(dc, tmp, wait_list, list) { 1052 list_for_each_entry_safe(dc, tmp, wait_list, list) {
1011 if (!wait_cond || dc->state == D_DONE) { 1053 if (!wait_cond || (dc->state == D_DONE && !dc->ref)) {
1012 if (dc->ref)
1013 continue;
1014 wait_for_completion_io(&dc->wait); 1054 wait_for_completion_io(&dc->wait);
1015 __remove_discard_cmd(sbi, dc); 1055 __remove_discard_cmd(sbi, dc);
1056 } else {
1057 dc->ref++;
1058 need_wait = true;
1059 break;
1016 } 1060 }
1017 } 1061 }
1018 mutex_unlock(&dcc->cmd_lock); 1062 mutex_unlock(&dcc->cmd_lock);
1063
1064 if (need_wait) {
1065 __wait_one_discard_bio(sbi, dc);
1066 goto next;
1067 }
1019} 1068}
1020 1069
1021/* This should be covered by global mutex, &sit_i->sentry_lock */ 1070/* This should be covered by global mutex, &sit_i->sentry_lock */
@@ -1037,14 +1086,19 @@ void f2fs_wait_discard_bio(struct f2fs_sb_info *sbi, block_t blkaddr)
1037 } 1086 }
1038 mutex_unlock(&dcc->cmd_lock); 1087 mutex_unlock(&dcc->cmd_lock);
1039 1088
1040 if (need_wait) { 1089 if (need_wait)
1041 wait_for_completion_io(&dc->wait); 1090 __wait_one_discard_bio(sbi, dc);
1042 mutex_lock(&dcc->cmd_lock); 1091}
1043 f2fs_bug_on(sbi, dc->state != D_DONE); 1092
1044 dc->ref--; 1093void stop_discard_thread(struct f2fs_sb_info *sbi)
1045 if (!dc->ref) 1094{
1046 __remove_discard_cmd(sbi, dc); 1095 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
1047 mutex_unlock(&dcc->cmd_lock); 1096
1097 if (dcc && dcc->f2fs_issue_discard) {
1098 struct task_struct *discard_thread = dcc->f2fs_issue_discard;
1099
1100 dcc->f2fs_issue_discard = NULL;
1101 kthread_stop(discard_thread);
1048 } 1102 }
1049} 1103}
1050 1104
@@ -1060,18 +1114,24 @@ static int issue_discard_thread(void *data)
1060 struct f2fs_sb_info *sbi = data; 1114 struct f2fs_sb_info *sbi = data;
1061 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info; 1115 struct discard_cmd_control *dcc = SM_I(sbi)->dcc_info;
1062 wait_queue_head_t *q = &dcc->discard_wait_queue; 1116 wait_queue_head_t *q = &dcc->discard_wait_queue;
1063repeat:
1064 if (kthread_should_stop())
1065 return 0;
1066 1117
1067 __issue_discard_cmd(sbi, true); 1118 set_freezable();
1068 __wait_discard_cmd(sbi, true);
1069 1119
1070 congestion_wait(BLK_RW_SYNC, HZ/50); 1120 do {
1121 wait_event_interruptible(*q, kthread_should_stop() ||
1122 freezing(current) ||
1123 atomic_read(&dcc->discard_cmd_cnt));
1124 if (try_to_freeze())
1125 continue;
1126 if (kthread_should_stop())
1127 return 0;
1071 1128
1072 wait_event_interruptible(*q, kthread_should_stop() || 1129 __issue_discard_cmd(sbi, true);
1073 atomic_read(&dcc->discard_cmd_cnt)); 1130 __wait_discard_cmd(sbi, true);
1074 goto repeat; 1131
1132 congestion_wait(BLK_RW_SYNC, HZ/50);
1133 } while (!kthread_should_stop());
1134 return 0;
1075} 1135}
1076 1136
1077#ifdef CONFIG_BLK_DEV_ZONED 1137#ifdef CONFIG_BLK_DEV_ZONED
@@ -1322,7 +1382,8 @@ find_next:
1322 sbi->blocks_per_seg, cur_pos); 1382 sbi->blocks_per_seg, cur_pos);
1323 len = next_pos - cur_pos; 1383 len = next_pos - cur_pos;
1324 1384
1325 if (force && len < cpc->trim_minlen) 1385 if (f2fs_sb_mounted_blkzoned(sbi->sb) ||
1386 (force && len < cpc->trim_minlen))
1326 goto skip; 1387 goto skip;
1327 1388
1328 f2fs_issue_discard(sbi, entry->start_blkaddr + cur_pos, 1389 f2fs_issue_discard(sbi, entry->start_blkaddr + cur_pos,
@@ -1398,12 +1459,7 @@ static void destroy_discard_cmd_control(struct f2fs_sb_info *sbi)
1398 if (!dcc) 1459 if (!dcc)
1399 return; 1460 return;
1400 1461
1401 if (dcc->f2fs_issue_discard) { 1462 stop_discard_thread(sbi);
1402 struct task_struct *discard_thread = dcc->f2fs_issue_discard;
1403
1404 dcc->f2fs_issue_discard = NULL;
1405 kthread_stop(discard_thread);
1406 }
1407 1463
1408 kfree(dcc); 1464 kfree(dcc);
1409 SM_I(sbi)->dcc_info = NULL; 1465 SM_I(sbi)->dcc_info = NULL;
@@ -2040,66 +2096,80 @@ static bool __has_curseg_space(struct f2fs_sb_info *sbi, int type)
2040 return false; 2096 return false;
2041} 2097}
2042 2098
2043static int __get_segment_type_2(struct page *page, enum page_type p_type) 2099static int __get_segment_type_2(struct f2fs_io_info *fio)
2044{ 2100{
2045 if (p_type == DATA) 2101 if (fio->type == DATA)
2046 return CURSEG_HOT_DATA; 2102 return CURSEG_HOT_DATA;
2047 else 2103 else
2048 return CURSEG_HOT_NODE; 2104 return CURSEG_HOT_NODE;
2049} 2105}
2050 2106
2051static int __get_segment_type_4(struct page *page, enum page_type p_type) 2107static int __get_segment_type_4(struct f2fs_io_info *fio)
2052{ 2108{
2053 if (p_type == DATA) { 2109 if (fio->type == DATA) {
2054 struct inode *inode = page->mapping->host; 2110 struct inode *inode = fio->page->mapping->host;
2055 2111
2056 if (S_ISDIR(inode->i_mode)) 2112 if (S_ISDIR(inode->i_mode))
2057 return CURSEG_HOT_DATA; 2113 return CURSEG_HOT_DATA;
2058 else 2114 else
2059 return CURSEG_COLD_DATA; 2115 return CURSEG_COLD_DATA;
2060 } else { 2116 } else {
2061 if (IS_DNODE(page) && is_cold_node(page)) 2117 if (IS_DNODE(fio->page) && is_cold_node(fio->page))
2062 return CURSEG_WARM_NODE; 2118 return CURSEG_WARM_NODE;
2063 else 2119 else
2064 return CURSEG_COLD_NODE; 2120 return CURSEG_COLD_NODE;
2065 } 2121 }
2066} 2122}
2067 2123
2068static int __get_segment_type_6(struct page *page, enum page_type p_type) 2124static int __get_segment_type_6(struct f2fs_io_info *fio)
2069{ 2125{
2070 if (p_type == DATA) { 2126 if (fio->type == DATA) {
2071 struct inode *inode = page->mapping->host; 2127 struct inode *inode = fio->page->mapping->host;
2072 2128
2073 if (is_cold_data(page) || file_is_cold(inode)) 2129 if (is_cold_data(fio->page) || file_is_cold(inode))
2074 return CURSEG_COLD_DATA; 2130 return CURSEG_COLD_DATA;
2075 if (is_inode_flag_set(inode, FI_HOT_DATA)) 2131 if (is_inode_flag_set(inode, FI_HOT_DATA))
2076 return CURSEG_HOT_DATA; 2132 return CURSEG_HOT_DATA;
2077 return CURSEG_WARM_DATA; 2133 return CURSEG_WARM_DATA;
2078 } else { 2134 } else {
2079 if (IS_DNODE(page)) 2135 if (IS_DNODE(fio->page))
2080 return is_cold_node(page) ? CURSEG_WARM_NODE : 2136 return is_cold_node(fio->page) ? CURSEG_WARM_NODE :
2081 CURSEG_HOT_NODE; 2137 CURSEG_HOT_NODE;
2082 return CURSEG_COLD_NODE; 2138 return CURSEG_COLD_NODE;
2083 } 2139 }
2084} 2140}
2085 2141
2086static int __get_segment_type(struct page *page, enum page_type p_type) 2142static int __get_segment_type(struct f2fs_io_info *fio)
2087{ 2143{
2088 switch (F2FS_P_SB(page)->active_logs) { 2144 int type = 0;
2145
2146 switch (fio->sbi->active_logs) {
2089 case 2: 2147 case 2:
2090 return __get_segment_type_2(page, p_type); 2148 type = __get_segment_type_2(fio);
2149 break;
2091 case 4: 2150 case 4:
2092 return __get_segment_type_4(page, p_type); 2151 type = __get_segment_type_4(fio);
2152 break;
2153 case 6:
2154 type = __get_segment_type_6(fio);
2155 break;
2156 default:
2157 f2fs_bug_on(fio->sbi, true);
2093 } 2158 }
2094 /* NR_CURSEG_TYPE(6) logs by default */ 2159
2095 f2fs_bug_on(F2FS_P_SB(page), 2160 if (IS_HOT(type))
2096 F2FS_P_SB(page)->active_logs != NR_CURSEG_TYPE); 2161 fio->temp = HOT;
2097 return __get_segment_type_6(page, p_type); 2162 else if (IS_WARM(type))
2163 fio->temp = WARM;
2164 else
2165 fio->temp = COLD;
2166 return type;
2098} 2167}
2099 2168
2100void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, 2169void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
2101 block_t old_blkaddr, block_t *new_blkaddr, 2170 block_t old_blkaddr, block_t *new_blkaddr,
2102 struct f2fs_summary *sum, int type) 2171 struct f2fs_summary *sum, int type,
2172 struct f2fs_io_info *fio, bool add_list)
2103{ 2173{
2104 struct sit_info *sit_i = SIT_I(sbi); 2174 struct sit_info *sit_i = SIT_I(sbi);
2105 struct curseg_info *curseg = CURSEG_I(sbi, type); 2175 struct curseg_info *curseg = CURSEG_I(sbi, type);
@@ -2135,29 +2205,35 @@ void allocate_data_block(struct f2fs_sb_info *sbi, struct page *page,
2135 if (page && IS_NODESEG(type)) 2205 if (page && IS_NODESEG(type))
2136 fill_node_footer_blkaddr(page, NEXT_FREE_BLKADDR(sbi, curseg)); 2206 fill_node_footer_blkaddr(page, NEXT_FREE_BLKADDR(sbi, curseg));
2137 2207
2208 if (add_list) {
2209 struct f2fs_bio_info *io;
2210
2211 INIT_LIST_HEAD(&fio->list);
2212 fio->in_list = true;
2213 io = sbi->write_io[fio->type] + fio->temp;
2214 spin_lock(&io->io_lock);
2215 list_add_tail(&fio->list, &io->io_list);
2216 spin_unlock(&io->io_lock);
2217 }
2218
2138 mutex_unlock(&curseg->curseg_mutex); 2219 mutex_unlock(&curseg->curseg_mutex);
2139} 2220}
2140 2221
2141static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio) 2222static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio)
2142{ 2223{
2143 int type = __get_segment_type(fio->page, fio->type); 2224 int type = __get_segment_type(fio);
2144 int err; 2225 int err;
2145 2226
2146 if (fio->type == NODE || fio->type == DATA)
2147 mutex_lock(&fio->sbi->wio_mutex[fio->type]);
2148reallocate: 2227reallocate:
2149 allocate_data_block(fio->sbi, fio->page, fio->old_blkaddr, 2228 allocate_data_block(fio->sbi, fio->page, fio->old_blkaddr,
2150 &fio->new_blkaddr, sum, type); 2229 &fio->new_blkaddr, sum, type, fio, true);
2151 2230
2152 /* writeout dirty page into bdev */ 2231 /* writeout dirty page into bdev */
2153 err = f2fs_submit_page_mbio(fio); 2232 err = f2fs_submit_page_write(fio);
2154 if (err == -EAGAIN) { 2233 if (err == -EAGAIN) {
2155 fio->old_blkaddr = fio->new_blkaddr; 2234 fio->old_blkaddr = fio->new_blkaddr;
2156 goto reallocate; 2235 goto reallocate;
2157 } 2236 }
2158
2159 if (fio->type == NODE || fio->type == DATA)
2160 mutex_unlock(&fio->sbi->wio_mutex[fio->type]);
2161} 2237}
2162 2238
2163void write_meta_page(struct f2fs_sb_info *sbi, struct page *page) 2239void write_meta_page(struct f2fs_sb_info *sbi, struct page *page)
@@ -2171,13 +2247,14 @@ void write_meta_page(struct f2fs_sb_info *sbi, struct page *page)
2171 .new_blkaddr = page->index, 2247 .new_blkaddr = page->index,
2172 .page = page, 2248 .page = page,
2173 .encrypted_page = NULL, 2249 .encrypted_page = NULL,
2250 .in_list = false,
2174 }; 2251 };
2175 2252
2176 if (unlikely(page->index >= MAIN_BLKADDR(sbi))) 2253 if (unlikely(page->index >= MAIN_BLKADDR(sbi)))
2177 fio.op_flags &= ~REQ_META; 2254 fio.op_flags &= ~REQ_META;
2178 2255
2179 set_page_writeback(page); 2256 set_page_writeback(page);
2180 f2fs_submit_page_mbio(&fio); 2257 f2fs_submit_page_write(&fio);
2181} 2258}
2182 2259
2183void write_node_page(unsigned int nid, struct f2fs_io_info *fio) 2260void write_node_page(unsigned int nid, struct f2fs_io_info *fio)
@@ -2296,8 +2373,8 @@ void f2fs_wait_on_page_writeback(struct page *page,
2296 if (PageWriteback(page)) { 2373 if (PageWriteback(page)) {
2297 struct f2fs_sb_info *sbi = F2FS_P_SB(page); 2374 struct f2fs_sb_info *sbi = F2FS_P_SB(page);
2298 2375
2299 f2fs_submit_merged_bio_cond(sbi, page->mapping->host, 2376 f2fs_submit_merged_write_cond(sbi, page->mapping->host,
2300 0, page->index, type, WRITE); 2377 0, page->index, type);
2301 if (ordered) 2378 if (ordered)
2302 wait_on_page_writeback(page); 2379 wait_on_page_writeback(page);
2303 else 2380 else
@@ -2455,6 +2532,8 @@ static int read_normal_summaries(struct f2fs_sb_info *sbi, int type)
2455 2532
2456static int restore_curseg_summaries(struct f2fs_sb_info *sbi) 2533static int restore_curseg_summaries(struct f2fs_sb_info *sbi)
2457{ 2534{
2535 struct f2fs_journal *sit_j = CURSEG_I(sbi, CURSEG_COLD_DATA)->journal;
2536 struct f2fs_journal *nat_j = CURSEG_I(sbi, CURSEG_HOT_DATA)->journal;
2458 int type = CURSEG_HOT_DATA; 2537 int type = CURSEG_HOT_DATA;
2459 int err; 2538 int err;
2460 2539
@@ -2481,6 +2560,11 @@ static int restore_curseg_summaries(struct f2fs_sb_info *sbi)
2481 return err; 2560 return err;
2482 } 2561 }
2483 2562
2563 /* sanity check for summary blocks */
2564 if (nats_in_cursum(nat_j) > NAT_JOURNAL_ENTRIES ||
2565 sits_in_cursum(sit_j) > SIT_JOURNAL_ENTRIES)
2566 return -EINVAL;
2567
2484 return 0; 2568 return 0;
2485} 2569}
2486 2570
@@ -3203,7 +3287,7 @@ int build_segment_manager(struct f2fs_sb_info *sbi)
3203 3287
3204 INIT_LIST_HEAD(&sm_info->sit_entry_set); 3288 INIT_LIST_HEAD(&sm_info->sit_entry_set);
3205 3289
3206 if (test_opt(sbi, FLUSH_MERGE) && !f2fs_readonly(sbi->sb)) { 3290 if (!f2fs_readonly(sbi->sb)) {
3207 err = create_flush_cmd_control(sbi); 3291 err = create_flush_cmd_control(sbi);
3208 if (err) 3292 if (err)
3209 return err; 3293 return err;
diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h
index 010f336a7573..6b871b492fd5 100644
--- a/fs/f2fs/segment.h
+++ b/fs/f2fs/segment.h
@@ -27,6 +27,10 @@
27#define IS_DATASEG(t) ((t) <= CURSEG_COLD_DATA) 27#define IS_DATASEG(t) ((t) <= CURSEG_COLD_DATA)
28#define IS_NODESEG(t) ((t) >= CURSEG_HOT_NODE) 28#define IS_NODESEG(t) ((t) >= CURSEG_HOT_NODE)
29 29
30#define IS_HOT(t) ((t) == CURSEG_HOT_NODE || (t) == CURSEG_HOT_DATA)
31#define IS_WARM(t) ((t) == CURSEG_WARM_NODE || (t) == CURSEG_WARM_DATA)
32#define IS_COLD(t) ((t) == CURSEG_COLD_NODE || (t) == CURSEG_COLD_DATA)
33
30#define IS_CURSEG(sbi, seg) \ 34#define IS_CURSEG(sbi, seg) \
31 (((seg) == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \ 35 (((seg) == CURSEG_I(sbi, CURSEG_HOT_DATA)->segno) || \
32 ((seg) == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) || \ 36 ((seg) == CURSEG_I(sbi, CURSEG_WARM_DATA)->segno) || \
diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c
index 0b89b0b7b9f7..32e4c025e97e 100644
--- a/fs/f2fs/super.c
+++ b/fs/f2fs/super.c
@@ -22,6 +22,7 @@
22#include <linux/random.h> 22#include <linux/random.h>
23#include <linux/exportfs.h> 23#include <linux/exportfs.h>
24#include <linux/blkdev.h> 24#include <linux/blkdev.h>
25#include <linux/quotaops.h>
25#include <linux/f2fs_fs.h> 26#include <linux/f2fs_fs.h>
26#include <linux/sysfs.h> 27#include <linux/sysfs.h>
27 28
@@ -35,9 +36,7 @@
35#define CREATE_TRACE_POINTS 36#define CREATE_TRACE_POINTS
36#include <trace/events/f2fs.h> 37#include <trace/events/f2fs.h>
37 38
38static struct proc_dir_entry *f2fs_proc_root;
39static struct kmem_cache *f2fs_inode_cachep; 39static struct kmem_cache *f2fs_inode_cachep;
40static struct kset *f2fs_kset;
41 40
42#ifdef CONFIG_F2FS_FAULT_INJECTION 41#ifdef CONFIG_F2FS_FAULT_INJECTION
43 42
@@ -108,6 +107,8 @@ enum {
108 Opt_fault_injection, 107 Opt_fault_injection,
109 Opt_lazytime, 108 Opt_lazytime,
110 Opt_nolazytime, 109 Opt_nolazytime,
110 Opt_usrquota,
111 Opt_grpquota,
111 Opt_err, 112 Opt_err,
112}; 113};
113 114
@@ -143,212 +144,11 @@ static match_table_t f2fs_tokens = {
143 {Opt_fault_injection, "fault_injection=%u"}, 144 {Opt_fault_injection, "fault_injection=%u"},
144 {Opt_lazytime, "lazytime"}, 145 {Opt_lazytime, "lazytime"},
145 {Opt_nolazytime, "nolazytime"}, 146 {Opt_nolazytime, "nolazytime"},
147 {Opt_usrquota, "usrquota"},
148 {Opt_grpquota, "grpquota"},
146 {Opt_err, NULL}, 149 {Opt_err, NULL},
147}; 150};
148 151
149/* Sysfs support for f2fs */
150enum {
151 GC_THREAD, /* struct f2fs_gc_thread */
152 SM_INFO, /* struct f2fs_sm_info */
153 DCC_INFO, /* struct discard_cmd_control */
154 NM_INFO, /* struct f2fs_nm_info */
155 F2FS_SBI, /* struct f2fs_sb_info */
156#ifdef CONFIG_F2FS_FAULT_INJECTION
157 FAULT_INFO_RATE, /* struct f2fs_fault_info */
158 FAULT_INFO_TYPE, /* struct f2fs_fault_info */
159#endif
160};
161
162struct f2fs_attr {
163 struct attribute attr;
164 ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *);
165 ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *,
166 const char *, size_t);
167 int struct_type;
168 int offset;
169};
170
171static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
172{
173 if (struct_type == GC_THREAD)
174 return (unsigned char *)sbi->gc_thread;
175 else if (struct_type == SM_INFO)
176 return (unsigned char *)SM_I(sbi);
177 else if (struct_type == DCC_INFO)
178 return (unsigned char *)SM_I(sbi)->dcc_info;
179 else if (struct_type == NM_INFO)
180 return (unsigned char *)NM_I(sbi);
181 else if (struct_type == F2FS_SBI)
182 return (unsigned char *)sbi;
183#ifdef CONFIG_F2FS_FAULT_INJECTION
184 else if (struct_type == FAULT_INFO_RATE ||
185 struct_type == FAULT_INFO_TYPE)
186 return (unsigned char *)&sbi->fault_info;
187#endif
188 return NULL;
189}
190
191static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
192 struct f2fs_sb_info *sbi, char *buf)
193{
194 struct super_block *sb = sbi->sb;
195
196 if (!sb->s_bdev->bd_part)
197 return snprintf(buf, PAGE_SIZE, "0\n");
198
199 return snprintf(buf, PAGE_SIZE, "%llu\n",
200 (unsigned long long)(sbi->kbytes_written +
201 BD_PART_WRITTEN(sbi)));
202}
203
204static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
205 struct f2fs_sb_info *sbi, char *buf)
206{
207 unsigned char *ptr = NULL;
208 unsigned int *ui;
209
210 ptr = __struct_ptr(sbi, a->struct_type);
211 if (!ptr)
212 return -EINVAL;
213
214 ui = (unsigned int *)(ptr + a->offset);
215
216 return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
217}
218
219static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
220 struct f2fs_sb_info *sbi,
221 const char *buf, size_t count)
222{
223 unsigned char *ptr;
224 unsigned long t;
225 unsigned int *ui;
226 ssize_t ret;
227
228 ptr = __struct_ptr(sbi, a->struct_type);
229 if (!ptr)
230 return -EINVAL;
231
232 ui = (unsigned int *)(ptr + a->offset);
233
234 ret = kstrtoul(skip_spaces(buf), 0, &t);
235 if (ret < 0)
236 return ret;
237#ifdef CONFIG_F2FS_FAULT_INJECTION
238 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
239 return -EINVAL;
240#endif
241 *ui = t;
242 return count;
243}
244
245static ssize_t f2fs_attr_show(struct kobject *kobj,
246 struct attribute *attr, char *buf)
247{
248 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
249 s_kobj);
250 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
251
252 return a->show ? a->show(a, sbi, buf) : 0;
253}
254
255static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
256 const char *buf, size_t len)
257{
258 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
259 s_kobj);
260 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
261
262 return a->store ? a->store(a, sbi, buf, len) : 0;
263}
264
265static void f2fs_sb_release(struct kobject *kobj)
266{
267 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
268 s_kobj);
269 complete(&sbi->s_kobj_unregister);
270}
271
272#define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
273static struct f2fs_attr f2fs_attr_##_name = { \
274 .attr = {.name = __stringify(_name), .mode = _mode }, \
275 .show = _show, \
276 .store = _store, \
277 .struct_type = _struct_type, \
278 .offset = _offset \
279}
280
281#define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
282 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
283 f2fs_sbi_show, f2fs_sbi_store, \
284 offsetof(struct struct_name, elname))
285
286#define F2FS_GENERAL_RO_ATTR(name) \
287static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
288
289F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
290F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
291F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
292F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle);
293F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
294F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
295F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
296F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
297F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
298F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
299F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
300F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
301F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
302F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
303F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
304F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
305F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
306F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
307#ifdef CONFIG_F2FS_FAULT_INJECTION
308F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
309F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
310#endif
311F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
312
313#define ATTR_LIST(name) (&f2fs_attr_##name.attr)
314static struct attribute *f2fs_attrs[] = {
315 ATTR_LIST(gc_min_sleep_time),
316 ATTR_LIST(gc_max_sleep_time),
317 ATTR_LIST(gc_no_gc_sleep_time),
318 ATTR_LIST(gc_idle),
319 ATTR_LIST(reclaim_segments),
320 ATTR_LIST(max_small_discards),
321 ATTR_LIST(batched_trim_sections),
322 ATTR_LIST(ipu_policy),
323 ATTR_LIST(min_ipu_util),
324 ATTR_LIST(min_fsync_blocks),
325 ATTR_LIST(min_hot_blocks),
326 ATTR_LIST(max_victim_search),
327 ATTR_LIST(dir_level),
328 ATTR_LIST(ram_thresh),
329 ATTR_LIST(ra_nid_pages),
330 ATTR_LIST(dirty_nats_ratio),
331 ATTR_LIST(cp_interval),
332 ATTR_LIST(idle_interval),
333#ifdef CONFIG_F2FS_FAULT_INJECTION
334 ATTR_LIST(inject_rate),
335 ATTR_LIST(inject_type),
336#endif
337 ATTR_LIST(lifetime_write_kbytes),
338 NULL,
339};
340
341static const struct sysfs_ops f2fs_attr_ops = {
342 .show = f2fs_attr_show,
343 .store = f2fs_attr_store,
344};
345
346static struct kobj_type f2fs_ktype = {
347 .default_attrs = f2fs_attrs,
348 .sysfs_ops = &f2fs_attr_ops,
349 .release = f2fs_sb_release,
350};
351
352void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...) 152void f2fs_msg(struct super_block *sb, const char *level, const char *fmt, ...)
353{ 153{
354 struct va_format vaf; 154 struct va_format vaf;
@@ -585,6 +385,20 @@ static int parse_options(struct super_block *sb, char *options)
585 case Opt_nolazytime: 385 case Opt_nolazytime:
586 sb->s_flags &= ~MS_LAZYTIME; 386 sb->s_flags &= ~MS_LAZYTIME;
587 break; 387 break;
388#ifdef CONFIG_QUOTA
389 case Opt_usrquota:
390 set_opt(sbi, USRQUOTA);
391 break;
392 case Opt_grpquota:
393 set_opt(sbi, GRPQUOTA);
394 break;
395#else
396 case Opt_usrquota:
397 case Opt_grpquota:
398 f2fs_msg(sb, KERN_INFO,
399 "quota operations not supported");
400 break;
401#endif
588 default: 402 default:
589 f2fs_msg(sb, KERN_ERR, 403 f2fs_msg(sb, KERN_ERR,
590 "Unrecognized mount option \"%s\" or missing value", 404 "Unrecognized mount option \"%s\" or missing value",
@@ -624,7 +438,12 @@ static struct inode *f2fs_alloc_inode(struct super_block *sb)
624 mutex_init(&fi->inmem_lock); 438 mutex_init(&fi->inmem_lock);
625 init_rwsem(&fi->dio_rwsem[READ]); 439 init_rwsem(&fi->dio_rwsem[READ]);
626 init_rwsem(&fi->dio_rwsem[WRITE]); 440 init_rwsem(&fi->dio_rwsem[WRITE]);
441 init_rwsem(&fi->i_mmap_sem);
627 442
443#ifdef CONFIG_QUOTA
444 memset(&fi->i_dquot, 0, sizeof(fi->i_dquot));
445 fi->i_reserved_quota = 0;
446#endif
628 /* Will be used by directory only */ 447 /* Will be used by directory only */
629 fi->i_dir_level = F2FS_SB(sb)->dir_level; 448 fi->i_dir_level = F2FS_SB(sb)->dir_level;
630 return &fi->vfs_inode; 449 return &fi->vfs_inode;
@@ -765,18 +584,13 @@ static void destroy_device_list(struct f2fs_sb_info *sbi)
765 kfree(sbi->devs); 584 kfree(sbi->devs);
766} 585}
767 586
587static void f2fs_quota_off_umount(struct super_block *sb);
768static void f2fs_put_super(struct super_block *sb) 588static void f2fs_put_super(struct super_block *sb)
769{ 589{
770 struct f2fs_sb_info *sbi = F2FS_SB(sb); 590 struct f2fs_sb_info *sbi = F2FS_SB(sb);
591 int i;
771 592
772 if (sbi->s_proc) { 593 f2fs_quota_off_umount(sb);
773 remove_proc_entry("segment_info", sbi->s_proc);
774 remove_proc_entry("segment_bits", sbi->s_proc);
775 remove_proc_entry(sb->s_id, f2fs_proc_root);
776 }
777 kobject_del(&sbi->s_kobj);
778
779 stop_gc_thread(sbi);
780 594
781 /* prevent remaining shrinker jobs */ 595 /* prevent remaining shrinker jobs */
782 mutex_lock(&sbi->umount_mutex); 596 mutex_lock(&sbi->umount_mutex);
@@ -797,7 +611,7 @@ static void f2fs_put_super(struct super_block *sb)
797 /* be sure to wait for any on-going discard commands */ 611 /* be sure to wait for any on-going discard commands */
798 f2fs_wait_discard_bios(sbi); 612 f2fs_wait_discard_bios(sbi);
799 613
800 if (!sbi->discard_blks) { 614 if (f2fs_discard_en(sbi) && !sbi->discard_blks) {
801 struct cp_control cpc = { 615 struct cp_control cpc = {
802 .reason = CP_UMOUNT | CP_TRIMMED, 616 .reason = CP_UMOUNT | CP_TRIMMED,
803 }; 617 };
@@ -817,7 +631,7 @@ static void f2fs_put_super(struct super_block *sb)
817 mutex_unlock(&sbi->umount_mutex); 631 mutex_unlock(&sbi->umount_mutex);
818 632
819 /* our cp_error case, we can wait for any writeback page */ 633 /* our cp_error case, we can wait for any writeback page */
820 f2fs_flush_merged_bios(sbi); 634 f2fs_flush_merged_writes(sbi);
821 635
822 iput(sbi->node_inode); 636 iput(sbi->node_inode);
823 iput(sbi->meta_inode); 637 iput(sbi->meta_inode);
@@ -827,8 +641,8 @@ static void f2fs_put_super(struct super_block *sb)
827 destroy_segment_manager(sbi); 641 destroy_segment_manager(sbi);
828 642
829 kfree(sbi->ckpt); 643 kfree(sbi->ckpt);
830 kobject_put(&sbi->s_kobj); 644
831 wait_for_completion(&sbi->s_kobj_unregister); 645 f2fs_exit_sysfs(sbi);
832 646
833 sb->s_fs_info = NULL; 647 sb->s_fs_info = NULL;
834 if (sbi->s_chksum_driver) 648 if (sbi->s_chksum_driver)
@@ -838,6 +652,8 @@ static void f2fs_put_super(struct super_block *sb)
838 destroy_device_list(sbi); 652 destroy_device_list(sbi);
839 mempool_destroy(sbi->write_io_dummy); 653 mempool_destroy(sbi->write_io_dummy);
840 destroy_percpu_info(sbi); 654 destroy_percpu_info(sbi);
655 for (i = 0; i < NR_PAGE_TYPE; i++)
656 kfree(sbi->write_io[i]);
841 kfree(sbi); 657 kfree(sbi);
842} 658}
843 659
@@ -888,6 +704,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
888 struct f2fs_sb_info *sbi = F2FS_SB(sb); 704 struct f2fs_sb_info *sbi = F2FS_SB(sb);
889 u64 id = huge_encode_dev(sb->s_bdev->bd_dev); 705 u64 id = huge_encode_dev(sb->s_bdev->bd_dev);
890 block_t total_count, user_block_count, start_count, ovp_count; 706 block_t total_count, user_block_count, start_count, ovp_count;
707 u64 avail_node_count;
891 708
892 total_count = le64_to_cpu(sbi->raw_super->block_count); 709 total_count = le64_to_cpu(sbi->raw_super->block_count);
893 user_block_count = sbi->user_block_count; 710 user_block_count = sbi->user_block_count;
@@ -898,11 +715,19 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf)
898 715
899 buf->f_blocks = total_count - start_count; 716 buf->f_blocks = total_count - start_count;
900 buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count; 717 buf->f_bfree = user_block_count - valid_user_blocks(sbi) + ovp_count;
901 buf->f_bavail = user_block_count - valid_user_blocks(sbi); 718 buf->f_bavail = user_block_count - valid_user_blocks(sbi) -
719 sbi->reserved_blocks;
902 720
903 buf->f_files = sbi->total_node_count - F2FS_RESERVED_NODE_NUM; 721 avail_node_count = sbi->total_node_count - F2FS_RESERVED_NODE_NUM;
904 buf->f_ffree = min(buf->f_files - valid_node_count(sbi), 722
905 buf->f_bavail); 723 if (avail_node_count > user_block_count) {
724 buf->f_files = user_block_count;
725 buf->f_ffree = buf->f_bavail;
726 } else {
727 buf->f_files = avail_node_count;
728 buf->f_ffree = min(avail_node_count - valid_node_count(sbi),
729 buf->f_bavail);
730 }
906 731
907 buf->f_namelen = F2FS_NAME_LEN; 732 buf->f_namelen = F2FS_NAME_LEN;
908 buf->f_fsid.val[0] = (u32)id; 733 buf->f_fsid.val[0] = (u32)id;
@@ -980,79 +805,19 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
980 seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi)); 805 seq_printf(seq, ",io_size=%uKB", F2FS_IO_SIZE_KB(sbi));
981#ifdef CONFIG_F2FS_FAULT_INJECTION 806#ifdef CONFIG_F2FS_FAULT_INJECTION
982 if (test_opt(sbi, FAULT_INJECTION)) 807 if (test_opt(sbi, FAULT_INJECTION))
983 seq_puts(seq, ",fault_injection"); 808 seq_printf(seq, ",fault_injection=%u",
809 sbi->fault_info.inject_rate);
810#endif
811#ifdef CONFIG_QUOTA
812 if (test_opt(sbi, USRQUOTA))
813 seq_puts(seq, ",usrquota");
814 if (test_opt(sbi, GRPQUOTA))
815 seq_puts(seq, ",grpquota");
984#endif 816#endif
985 817
986 return 0; 818 return 0;
987} 819}
988 820
989static int segment_info_seq_show(struct seq_file *seq, void *offset)
990{
991 struct super_block *sb = seq->private;
992 struct f2fs_sb_info *sbi = F2FS_SB(sb);
993 unsigned int total_segs =
994 le32_to_cpu(sbi->raw_super->segment_count_main);
995 int i;
996
997 seq_puts(seq, "format: segment_type|valid_blocks\n"
998 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
999
1000 for (i = 0; i < total_segs; i++) {
1001 struct seg_entry *se = get_seg_entry(sbi, i);
1002
1003 if ((i % 10) == 0)
1004 seq_printf(seq, "%-10d", i);
1005 seq_printf(seq, "%d|%-3u", se->type,
1006 get_valid_blocks(sbi, i, false));
1007 if ((i % 10) == 9 || i == (total_segs - 1))
1008 seq_putc(seq, '\n');
1009 else
1010 seq_putc(seq, ' ');
1011 }
1012
1013 return 0;
1014}
1015
1016static int segment_bits_seq_show(struct seq_file *seq, void *offset)
1017{
1018 struct super_block *sb = seq->private;
1019 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1020 unsigned int total_segs =
1021 le32_to_cpu(sbi->raw_super->segment_count_main);
1022 int i, j;
1023
1024 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
1025 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
1026
1027 for (i = 0; i < total_segs; i++) {
1028 struct seg_entry *se = get_seg_entry(sbi, i);
1029
1030 seq_printf(seq, "%-10d", i);
1031 seq_printf(seq, "%d|%-3u|", se->type,
1032 get_valid_blocks(sbi, i, false));
1033 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
1034 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
1035 seq_putc(seq, '\n');
1036 }
1037 return 0;
1038}
1039
1040#define F2FS_PROC_FILE_DEF(_name) \
1041static int _name##_open_fs(struct inode *inode, struct file *file) \
1042{ \
1043 return single_open(file, _name##_seq_show, PDE_DATA(inode)); \
1044} \
1045 \
1046static const struct file_operations f2fs_seq_##_name##_fops = { \
1047 .open = _name##_open_fs, \
1048 .read = seq_read, \
1049 .llseek = seq_lseek, \
1050 .release = single_release, \
1051};
1052
1053F2FS_PROC_FILE_DEF(segment_info);
1054F2FS_PROC_FILE_DEF(segment_bits);
1055
1056static void default_options(struct f2fs_sb_info *sbi) 821static void default_options(struct f2fs_sb_info *sbi)
1057{ 822{
1058 /* init some FS parameters */ 823 /* init some FS parameters */
@@ -1089,6 +854,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
1089{ 854{
1090 struct f2fs_sb_info *sbi = F2FS_SB(sb); 855 struct f2fs_sb_info *sbi = F2FS_SB(sb);
1091 struct f2fs_mount_info org_mount_opt; 856 struct f2fs_mount_info org_mount_opt;
857 unsigned long old_sb_flags;
1092 int err, active_logs; 858 int err, active_logs;
1093 bool need_restart_gc = false; 859 bool need_restart_gc = false;
1094 bool need_stop_gc = false; 860 bool need_stop_gc = false;
@@ -1102,6 +868,7 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
1102 * need to restore them. 868 * need to restore them.
1103 */ 869 */
1104 org_mount_opt = sbi->mount_opt; 870 org_mount_opt = sbi->mount_opt;
871 old_sb_flags = sb->s_flags;
1105 active_logs = sbi->active_logs; 872 active_logs = sbi->active_logs;
1106 873
1107 /* recover superblocks we couldn't write due to previous RO mount */ 874 /* recover superblocks we couldn't write due to previous RO mount */
@@ -1113,7 +880,6 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
1113 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE); 880 clear_sbi_flag(sbi, SBI_NEED_SB_WRITE);
1114 } 881 }
1115 882
1116 sbi->mount_opt.opt = 0;
1117 default_options(sbi); 883 default_options(sbi);
1118 884
1119 /* parse mount options */ 885 /* parse mount options */
@@ -1128,6 +894,16 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
1128 if (f2fs_readonly(sb) && (*flags & MS_RDONLY)) 894 if (f2fs_readonly(sb) && (*flags & MS_RDONLY))
1129 goto skip; 895 goto skip;
1130 896
897 if (!f2fs_readonly(sb) && (*flags & MS_RDONLY)) {
898 err = dquot_suspend(sb, -1);
899 if (err < 0)
900 goto restore_opts;
901 } else {
902 /* dquot_resume needs RW */
903 sb->s_flags &= ~MS_RDONLY;
904 dquot_resume(sb, -1);
905 }
906
1131 /* disallow enable/disable extent_cache dynamically */ 907 /* disallow enable/disable extent_cache dynamically */
1132 if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) { 908 if (no_extent_cache == !!test_opt(sbi, EXTENT_CACHE)) {
1133 err = -EINVAL; 909 err = -EINVAL;
@@ -1192,12 +968,237 @@ restore_gc:
1192restore_opts: 968restore_opts:
1193 sbi->mount_opt = org_mount_opt; 969 sbi->mount_opt = org_mount_opt;
1194 sbi->active_logs = active_logs; 970 sbi->active_logs = active_logs;
971 sb->s_flags = old_sb_flags;
1195#ifdef CONFIG_F2FS_FAULT_INJECTION 972#ifdef CONFIG_F2FS_FAULT_INJECTION
1196 sbi->fault_info = ffi; 973 sbi->fault_info = ffi;
1197#endif 974#endif
1198 return err; 975 return err;
1199} 976}
1200 977
978#ifdef CONFIG_QUOTA
979/* Read data from quotafile */
980static ssize_t f2fs_quota_read(struct super_block *sb, int type, char *data,
981 size_t len, loff_t off)
982{
983 struct inode *inode = sb_dqopt(sb)->files[type];
984 struct address_space *mapping = inode->i_mapping;
985 block_t blkidx = F2FS_BYTES_TO_BLK(off);
986 int offset = off & (sb->s_blocksize - 1);
987 int tocopy;
988 size_t toread;
989 loff_t i_size = i_size_read(inode);
990 struct page *page;
991 char *kaddr;
992
993 if (off > i_size)
994 return 0;
995
996 if (off + len > i_size)
997 len = i_size - off;
998 toread = len;
999 while (toread > 0) {
1000 tocopy = min_t(unsigned long, sb->s_blocksize - offset, toread);
1001repeat:
1002 page = read_mapping_page(mapping, blkidx, NULL);
1003 if (IS_ERR(page))
1004 return PTR_ERR(page);
1005
1006 lock_page(page);
1007
1008 if (unlikely(page->mapping != mapping)) {
1009 f2fs_put_page(page, 1);
1010 goto repeat;
1011 }
1012 if (unlikely(!PageUptodate(page))) {
1013 f2fs_put_page(page, 1);
1014 return -EIO;
1015 }
1016
1017 kaddr = kmap_atomic(page);
1018 memcpy(data, kaddr + offset, tocopy);
1019 kunmap_atomic(kaddr);
1020 f2fs_put_page(page, 1);
1021
1022 offset = 0;
1023 toread -= tocopy;
1024 data += tocopy;
1025 blkidx++;
1026 }
1027 return len;
1028}
1029
1030/* Write to quotafile */
1031static ssize_t f2fs_quota_write(struct super_block *sb, int type,
1032 const char *data, size_t len, loff_t off)
1033{
1034 struct inode *inode = sb_dqopt(sb)->files[type];
1035 struct address_space *mapping = inode->i_mapping;
1036 const struct address_space_operations *a_ops = mapping->a_ops;
1037 int offset = off & (sb->s_blocksize - 1);
1038 size_t towrite = len;
1039 struct page *page;
1040 char *kaddr;
1041 int err = 0;
1042 int tocopy;
1043
1044 while (towrite > 0) {
1045 tocopy = min_t(unsigned long, sb->s_blocksize - offset,
1046 towrite);
1047
1048 err = a_ops->write_begin(NULL, mapping, off, tocopy, 0,
1049 &page, NULL);
1050 if (unlikely(err))
1051 break;
1052
1053 kaddr = kmap_atomic(page);
1054 memcpy(kaddr + offset, data, tocopy);
1055 kunmap_atomic(kaddr);
1056 flush_dcache_page(page);
1057
1058 a_ops->write_end(NULL, mapping, off, tocopy, tocopy,
1059 page, NULL);
1060 offset = 0;
1061 towrite -= tocopy;
1062 off += tocopy;
1063 data += tocopy;
1064 cond_resched();
1065 }
1066
1067 if (len == towrite)
1068 return err;
1069 inode->i_version++;
1070 inode->i_mtime = inode->i_ctime = current_time(inode);
1071 f2fs_mark_inode_dirty_sync(inode, false);
1072 return len - towrite;
1073}
1074
1075static struct dquot **f2fs_get_dquots(struct inode *inode)
1076{
1077 return F2FS_I(inode)->i_dquot;
1078}
1079
1080static qsize_t *f2fs_get_reserved_space(struct inode *inode)
1081{
1082 return &F2FS_I(inode)->i_reserved_quota;
1083}
1084
1085static int f2fs_quota_sync(struct super_block *sb, int type)
1086{
1087 struct quota_info *dqopt = sb_dqopt(sb);
1088 int cnt;
1089 int ret;
1090
1091 ret = dquot_writeback_dquots(sb, type);
1092 if (ret)
1093 return ret;
1094
1095 /*
1096 * Now when everything is written we can discard the pagecache so
1097 * that userspace sees the changes.
1098 */
1099 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
1100 if (type != -1 && cnt != type)
1101 continue;
1102 if (!sb_has_quota_active(sb, cnt))
1103 continue;
1104
1105 ret = filemap_write_and_wait(dqopt->files[cnt]->i_mapping);
1106 if (ret)
1107 return ret;
1108
1109 inode_lock(dqopt->files[cnt]);
1110 truncate_inode_pages(&dqopt->files[cnt]->i_data, 0);
1111 inode_unlock(dqopt->files[cnt]);
1112 }
1113 return 0;
1114}
1115
1116static int f2fs_quota_on(struct super_block *sb, int type, int format_id,
1117 const struct path *path)
1118{
1119 struct inode *inode;
1120 int err;
1121
1122 err = f2fs_quota_sync(sb, -1);
1123 if (err)
1124 return err;
1125
1126 err = dquot_quota_on(sb, type, format_id, path);
1127 if (err)
1128 return err;
1129
1130 inode = d_inode(path->dentry);
1131
1132 inode_lock(inode);
1133 F2FS_I(inode)->i_flags |= FS_NOATIME_FL | FS_IMMUTABLE_FL;
1134 inode_set_flags(inode, S_NOATIME | S_IMMUTABLE,
1135 S_NOATIME | S_IMMUTABLE);
1136 inode_unlock(inode);
1137 f2fs_mark_inode_dirty_sync(inode, false);
1138
1139 return 0;
1140}
1141
1142static int f2fs_quota_off(struct super_block *sb, int type)
1143{
1144 struct inode *inode = sb_dqopt(sb)->files[type];
1145 int err;
1146
1147 if (!inode || !igrab(inode))
1148 return dquot_quota_off(sb, type);
1149
1150 f2fs_quota_sync(sb, -1);
1151
1152 err = dquot_quota_off(sb, type);
1153 if (err)
1154 goto out_put;
1155
1156 inode_lock(inode);
1157 F2FS_I(inode)->i_flags &= ~(FS_NOATIME_FL | FS_IMMUTABLE_FL);
1158 inode_set_flags(inode, 0, S_NOATIME | S_IMMUTABLE);
1159 inode_unlock(inode);
1160 f2fs_mark_inode_dirty_sync(inode, false);
1161out_put:
1162 iput(inode);
1163 return err;
1164}
1165
1166static void f2fs_quota_off_umount(struct super_block *sb)
1167{
1168 int type;
1169
1170 for (type = 0; type < MAXQUOTAS; type++)
1171 f2fs_quota_off(sb, type);
1172}
1173
1174static const struct dquot_operations f2fs_quota_operations = {
1175 .get_reserved_space = f2fs_get_reserved_space,
1176 .write_dquot = dquot_commit,
1177 .acquire_dquot = dquot_acquire,
1178 .release_dquot = dquot_release,
1179 .mark_dirty = dquot_mark_dquot_dirty,
1180 .write_info = dquot_commit_info,
1181 .alloc_dquot = dquot_alloc,
1182 .destroy_dquot = dquot_destroy,
1183 .get_next_id = dquot_get_next_id,
1184};
1185
1186static const struct quotactl_ops f2fs_quotactl_ops = {
1187 .quota_on = f2fs_quota_on,
1188 .quota_off = f2fs_quota_off,
1189 .quota_sync = f2fs_quota_sync,
1190 .get_state = dquot_get_state,
1191 .set_info = dquot_set_dqinfo,
1192 .get_dqblk = dquot_get_dqblk,
1193 .set_dqblk = dquot_set_dqblk,
1194 .get_nextdqblk = dquot_get_next_dqblk,
1195};
1196#else
1197static inline void f2fs_quota_off_umount(struct super_block *sb)
1198{
1199}
1200#endif
1201
1201static struct super_operations f2fs_sops = { 1202static struct super_operations f2fs_sops = {
1202 .alloc_inode = f2fs_alloc_inode, 1203 .alloc_inode = f2fs_alloc_inode,
1203 .drop_inode = f2fs_drop_inode, 1204 .drop_inode = f2fs_drop_inode,
@@ -1205,6 +1206,11 @@ static struct super_operations f2fs_sops = {
1205 .write_inode = f2fs_write_inode, 1206 .write_inode = f2fs_write_inode,
1206 .dirty_inode = f2fs_dirty_inode, 1207 .dirty_inode = f2fs_dirty_inode,
1207 .show_options = f2fs_show_options, 1208 .show_options = f2fs_show_options,
1209#ifdef CONFIG_QUOTA
1210 .quota_read = f2fs_quota_read,
1211 .quota_write = f2fs_quota_write,
1212 .get_dquots = f2fs_get_dquots,
1213#endif
1208 .evict_inode = f2fs_evict_inode, 1214 .evict_inode = f2fs_evict_inode,
1209 .put_super = f2fs_put_super, 1215 .put_super = f2fs_put_super,
1210 .sync_fs = f2fs_sync_fs, 1216 .sync_fs = f2fs_sync_fs,
@@ -1521,6 +1527,8 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
1521 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi); 1527 struct f2fs_super_block *raw_super = F2FS_RAW_SUPER(sbi);
1522 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi); 1528 struct f2fs_checkpoint *ckpt = F2FS_CKPT(sbi);
1523 unsigned int ovp_segments, reserved_segments; 1529 unsigned int ovp_segments, reserved_segments;
1530 unsigned int main_segs, blocks_per_seg;
1531 int i;
1524 1532
1525 total = le32_to_cpu(raw_super->segment_count); 1533 total = le32_to_cpu(raw_super->segment_count);
1526 fsmeta = le32_to_cpu(raw_super->segment_count_ckpt); 1534 fsmeta = le32_to_cpu(raw_super->segment_count_ckpt);
@@ -1542,6 +1550,20 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
1542 return 1; 1550 return 1;
1543 } 1551 }
1544 1552
1553 main_segs = le32_to_cpu(raw_super->segment_count_main);
1554 blocks_per_seg = sbi->blocks_per_seg;
1555
1556 for (i = 0; i < NR_CURSEG_NODE_TYPE; i++) {
1557 if (le32_to_cpu(ckpt->cur_node_segno[i]) >= main_segs ||
1558 le16_to_cpu(ckpt->cur_node_blkoff[i]) >= blocks_per_seg)
1559 return 1;
1560 }
1561 for (i = 0; i < NR_CURSEG_DATA_TYPE; i++) {
1562 if (le32_to_cpu(ckpt->cur_data_segno[i]) >= main_segs ||
1563 le16_to_cpu(ckpt->cur_data_blkoff[i]) >= blocks_per_seg)
1564 return 1;
1565 }
1566
1545 if (unlikely(f2fs_cp_error(sbi))) { 1567 if (unlikely(f2fs_cp_error(sbi))) {
1546 f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck"); 1568 f2fs_msg(sbi->sb, KERN_ERR, "A bug case: need to run fsck");
1547 return 1; 1569 return 1;
@@ -1552,7 +1574,7 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
1552static void init_sb_info(struct f2fs_sb_info *sbi) 1574static void init_sb_info(struct f2fs_sb_info *sbi)
1553{ 1575{
1554 struct f2fs_super_block *raw_super = sbi->raw_super; 1576 struct f2fs_super_block *raw_super = sbi->raw_super;
1555 int i; 1577 int i, j;
1556 1578
1557 sbi->log_sectors_per_block = 1579 sbi->log_sectors_per_block =
1558 le32_to_cpu(raw_super->log_sectors_per_block); 1580 le32_to_cpu(raw_super->log_sectors_per_block);
@@ -1584,8 +1606,9 @@ static void init_sb_info(struct f2fs_sb_info *sbi)
1584 1606
1585 INIT_LIST_HEAD(&sbi->s_list); 1607 INIT_LIST_HEAD(&sbi->s_list);
1586 mutex_init(&sbi->umount_mutex); 1608 mutex_init(&sbi->umount_mutex);
1587 mutex_init(&sbi->wio_mutex[NODE]); 1609 for (i = 0; i < NR_PAGE_TYPE - 1; i++)
1588 mutex_init(&sbi->wio_mutex[DATA]); 1610 for (j = HOT; j < NR_TEMP_TYPE; j++)
1611 mutex_init(&sbi->wio_mutex[i][j]);
1589 spin_lock_init(&sbi->cp_lock); 1612 spin_lock_init(&sbi->cp_lock);
1590} 1613}
1591 1614
@@ -1908,6 +1931,7 @@ try_onemore:
1908 if (f2fs_sb_mounted_blkzoned(sb)) { 1931 if (f2fs_sb_mounted_blkzoned(sb)) {
1909 f2fs_msg(sb, KERN_ERR, 1932 f2fs_msg(sb, KERN_ERR,
1910 "Zoned block device support is not enabled\n"); 1933 "Zoned block device support is not enabled\n");
1934 err = -EOPNOTSUPP;
1911 goto free_sb_buf; 1935 goto free_sb_buf;
1912 } 1936 }
1913#endif 1937#endif
@@ -1929,6 +1953,12 @@ try_onemore:
1929 sb->s_max_links = F2FS_LINK_MAX; 1953 sb->s_max_links = F2FS_LINK_MAX;
1930 get_random_bytes(&sbi->s_next_generation, sizeof(u32)); 1954 get_random_bytes(&sbi->s_next_generation, sizeof(u32));
1931 1955
1956#ifdef CONFIG_QUOTA
1957 sb->dq_op = &f2fs_quota_operations;
1958 sb->s_qcop = &f2fs_quotactl_ops;
1959 sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP;
1960#endif
1961
1932 sb->s_op = &f2fs_sops; 1962 sb->s_op = &f2fs_sops;
1933 sb->s_cop = &f2fs_cryptops; 1963 sb->s_cop = &f2fs_cryptops;
1934 sb->s_xattr = f2fs_xattr_handlers; 1964 sb->s_xattr = f2fs_xattr_handlers;
@@ -1950,13 +1980,24 @@ try_onemore:
1950 set_sbi_flag(sbi, SBI_POR_DOING); 1980 set_sbi_flag(sbi, SBI_POR_DOING);
1951 spin_lock_init(&sbi->stat_lock); 1981 spin_lock_init(&sbi->stat_lock);
1952 1982
1953 init_rwsem(&sbi->read_io.io_rwsem);
1954 sbi->read_io.sbi = sbi;
1955 sbi->read_io.bio = NULL;
1956 for (i = 0; i < NR_PAGE_TYPE; i++) { 1983 for (i = 0; i < NR_PAGE_TYPE; i++) {
1957 init_rwsem(&sbi->write_io[i].io_rwsem); 1984 int n = (i == META) ? 1: NR_TEMP_TYPE;
1958 sbi->write_io[i].sbi = sbi; 1985 int j;
1959 sbi->write_io[i].bio = NULL; 1986
1987 sbi->write_io[i] = kmalloc(n * sizeof(struct f2fs_bio_info),
1988 GFP_KERNEL);
1989 if (!sbi->write_io[i]) {
1990 err = -ENOMEM;
1991 goto free_options;
1992 }
1993
1994 for (j = HOT; j < n; j++) {
1995 init_rwsem(&sbi->write_io[i][j].io_rwsem);
1996 sbi->write_io[i][j].sbi = sbi;
1997 sbi->write_io[i][j].bio = NULL;
1998 spin_lock_init(&sbi->write_io[i][j].io_lock);
1999 INIT_LIST_HEAD(&sbi->write_io[i][j].io_list);
2000 }
1960 } 2001 }
1961 2002
1962 init_rwsem(&sbi->cp_rwsem); 2003 init_rwsem(&sbi->cp_rwsem);
@@ -1970,8 +2011,10 @@ try_onemore:
1970 if (F2FS_IO_SIZE(sbi) > 1) { 2011 if (F2FS_IO_SIZE(sbi) > 1) {
1971 sbi->write_io_dummy = 2012 sbi->write_io_dummy =
1972 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0); 2013 mempool_create_page_pool(2 * (F2FS_IO_SIZE(sbi) - 1), 0);
1973 if (!sbi->write_io_dummy) 2014 if (!sbi->write_io_dummy) {
2015 err = -ENOMEM;
1974 goto free_options; 2016 goto free_options;
2017 }
1975 } 2018 }
1976 2019
1977 /* get an inode for meta space */ 2020 /* get an inode for meta space */
@@ -2003,6 +2046,7 @@ try_onemore:
2003 sbi->total_valid_block_count = 2046 sbi->total_valid_block_count =
2004 le64_to_cpu(sbi->ckpt->valid_block_count); 2047 le64_to_cpu(sbi->ckpt->valid_block_count);
2005 sbi->last_valid_block_count = sbi->total_valid_block_count; 2048 sbi->last_valid_block_count = sbi->total_valid_block_count;
2049 sbi->reserved_blocks = 0;
2006 2050
2007 for (i = 0; i < NR_INODE_TYPE; i++) { 2051 for (i = 0; i < NR_INODE_TYPE; i++) {
2008 INIT_LIST_HEAD(&sbi->inode_list[i]); 2052 INIT_LIST_HEAD(&sbi->inode_list[i]);
@@ -2078,22 +2122,9 @@ try_onemore:
2078 goto free_root_inode; 2122 goto free_root_inode;
2079 } 2123 }
2080 2124
2081 if (f2fs_proc_root) 2125 err = f2fs_init_sysfs(sbi);
2082 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
2083
2084 if (sbi->s_proc) {
2085 proc_create_data("segment_info", S_IRUGO, sbi->s_proc,
2086 &f2fs_seq_segment_info_fops, sb);
2087 proc_create_data("segment_bits", S_IRUGO, sbi->s_proc,
2088 &f2fs_seq_segment_bits_fops, sb);
2089 }
2090
2091 sbi->s_kobj.kset = f2fs_kset;
2092 init_completion(&sbi->s_kobj_unregister);
2093 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL,
2094 "%s", sb->s_id);
2095 if (err) 2126 if (err)
2096 goto free_proc; 2127 goto free_root_inode;
2097 2128
2098 /* recover fsynced data */ 2129 /* recover fsynced data */
2099 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) { 2130 if (!test_opt(sbi, DISABLE_ROLL_FORWARD)) {
@@ -2104,7 +2135,7 @@ try_onemore:
2104 if (bdev_read_only(sb->s_bdev) && 2135 if (bdev_read_only(sb->s_bdev) &&
2105 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) { 2136 !is_set_ckpt_flags(sbi, CP_UMOUNT_FLAG)) {
2106 err = -EROFS; 2137 err = -EROFS;
2107 goto free_kobj; 2138 goto free_sysfs;
2108 } 2139 }
2109 2140
2110 if (need_fsck) 2141 if (need_fsck)
@@ -2118,7 +2149,7 @@ try_onemore:
2118 need_fsck = true; 2149 need_fsck = true;
2119 f2fs_msg(sb, KERN_ERR, 2150 f2fs_msg(sb, KERN_ERR,
2120 "Cannot recover all fsync data errno=%d", err); 2151 "Cannot recover all fsync data errno=%d", err);
2121 goto free_kobj; 2152 goto free_sysfs;
2122 } 2153 }
2123 } else { 2154 } else {
2124 err = recover_fsync_data(sbi, true); 2155 err = recover_fsync_data(sbi, true);
@@ -2127,7 +2158,7 @@ try_onemore:
2127 err = -EINVAL; 2158 err = -EINVAL;
2128 f2fs_msg(sb, KERN_ERR, 2159 f2fs_msg(sb, KERN_ERR,
2129 "Need to recover fsync data"); 2160 "Need to recover fsync data");
2130 goto free_kobj; 2161 goto free_sysfs;
2131 } 2162 }
2132 } 2163 }
2133skip_recovery: 2164skip_recovery:
@@ -2142,7 +2173,7 @@ skip_recovery:
2142 /* After POR, we can run background GC thread.*/ 2173 /* After POR, we can run background GC thread.*/
2143 err = start_gc_thread(sbi); 2174 err = start_gc_thread(sbi);
2144 if (err) 2175 if (err)
2145 goto free_kobj; 2176 goto free_sysfs;
2146 } 2177 }
2147 kfree(options); 2178 kfree(options);
2148 2179
@@ -2160,17 +2191,9 @@ skip_recovery:
2160 f2fs_update_time(sbi, REQ_TIME); 2191 f2fs_update_time(sbi, REQ_TIME);
2161 return 0; 2192 return 0;
2162 2193
2163free_kobj: 2194free_sysfs:
2164 f2fs_sync_inode_meta(sbi); 2195 f2fs_sync_inode_meta(sbi);
2165 kobject_del(&sbi->s_kobj); 2196 f2fs_exit_sysfs(sbi);
2166 kobject_put(&sbi->s_kobj);
2167 wait_for_completion(&sbi->s_kobj_unregister);
2168free_proc:
2169 if (sbi->s_proc) {
2170 remove_proc_entry("segment_info", sbi->s_proc);
2171 remove_proc_entry("segment_bits", sbi->s_proc);
2172 remove_proc_entry(sb->s_id, f2fs_proc_root);
2173 }
2174free_root_inode: 2197free_root_inode:
2175 dput(sb->s_root); 2198 dput(sb->s_root);
2176 sb->s_root = NULL; 2199 sb->s_root = NULL;
@@ -2202,6 +2225,8 @@ free_meta_inode:
2202free_io_dummy: 2225free_io_dummy:
2203 mempool_destroy(sbi->write_io_dummy); 2226 mempool_destroy(sbi->write_io_dummy);
2204free_options: 2227free_options:
2228 for (i = 0; i < NR_PAGE_TYPE; i++)
2229 kfree(sbi->write_io[i]);
2205 destroy_percpu_info(sbi); 2230 destroy_percpu_info(sbi);
2206 kfree(options); 2231 kfree(options);
2207free_sb_buf: 2232free_sb_buf:
@@ -2228,8 +2253,11 @@ static struct dentry *f2fs_mount(struct file_system_type *fs_type, int flags,
2228 2253
2229static void kill_f2fs_super(struct super_block *sb) 2254static void kill_f2fs_super(struct super_block *sb)
2230{ 2255{
2231 if (sb->s_root) 2256 if (sb->s_root) {
2232 set_sbi_flag(F2FS_SB(sb), SBI_IS_CLOSE); 2257 set_sbi_flag(F2FS_SB(sb), SBI_IS_CLOSE);
2258 stop_gc_thread(F2FS_SB(sb));
2259 stop_discard_thread(F2FS_SB(sb));
2260 }
2233 kill_block_super(sb); 2261 kill_block_super(sb);
2234} 2262}
2235 2263
@@ -2283,30 +2311,26 @@ static int __init init_f2fs_fs(void)
2283 err = create_extent_cache(); 2311 err = create_extent_cache();
2284 if (err) 2312 if (err)
2285 goto free_checkpoint_caches; 2313 goto free_checkpoint_caches;
2286 f2fs_kset = kset_create_and_add("f2fs", NULL, fs_kobj); 2314 err = f2fs_register_sysfs();
2287 if (!f2fs_kset) { 2315 if (err)
2288 err = -ENOMEM;
2289 goto free_extent_cache; 2316 goto free_extent_cache;
2290 }
2291 err = register_shrinker(&f2fs_shrinker_info); 2317 err = register_shrinker(&f2fs_shrinker_info);
2292 if (err) 2318 if (err)
2293 goto free_kset; 2319 goto free_sysfs;
2294
2295 err = register_filesystem(&f2fs_fs_type); 2320 err = register_filesystem(&f2fs_fs_type);
2296 if (err) 2321 if (err)
2297 goto free_shrinker; 2322 goto free_shrinker;
2298 err = f2fs_create_root_stats(); 2323 err = f2fs_create_root_stats();
2299 if (err) 2324 if (err)
2300 goto free_filesystem; 2325 goto free_filesystem;
2301 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
2302 return 0; 2326 return 0;
2303 2327
2304free_filesystem: 2328free_filesystem:
2305 unregister_filesystem(&f2fs_fs_type); 2329 unregister_filesystem(&f2fs_fs_type);
2306free_shrinker: 2330free_shrinker:
2307 unregister_shrinker(&f2fs_shrinker_info); 2331 unregister_shrinker(&f2fs_shrinker_info);
2308free_kset: 2332free_sysfs:
2309 kset_unregister(f2fs_kset); 2333 f2fs_unregister_sysfs();
2310free_extent_cache: 2334free_extent_cache:
2311 destroy_extent_cache(); 2335 destroy_extent_cache();
2312free_checkpoint_caches: 2336free_checkpoint_caches:
@@ -2323,11 +2347,10 @@ fail:
2323 2347
2324static void __exit exit_f2fs_fs(void) 2348static void __exit exit_f2fs_fs(void)
2325{ 2349{
2326 remove_proc_entry("fs/f2fs", NULL);
2327 f2fs_destroy_root_stats(); 2350 f2fs_destroy_root_stats();
2328 unregister_filesystem(&f2fs_fs_type); 2351 unregister_filesystem(&f2fs_fs_type);
2329 unregister_shrinker(&f2fs_shrinker_info); 2352 unregister_shrinker(&f2fs_shrinker_info);
2330 kset_unregister(f2fs_kset); 2353 f2fs_unregister_sysfs();
2331 destroy_extent_cache(); 2354 destroy_extent_cache();
2332 destroy_checkpoint_caches(); 2355 destroy_checkpoint_caches();
2333 destroy_segment_manager_caches(); 2356 destroy_segment_manager_caches();
diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c
new file mode 100644
index 000000000000..9adc202fcd6f
--- /dev/null
+++ b/fs/f2fs/sysfs.c
@@ -0,0 +1,364 @@
1/*
2 * f2fs sysfs interface
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 * Copyright (c) 2017 Chao Yu <chao@kernel.org>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12#include <linux/proc_fs.h>
13#include <linux/f2fs_fs.h>
14
15#include "f2fs.h"
16#include "segment.h"
17#include "gc.h"
18
19static struct proc_dir_entry *f2fs_proc_root;
20static struct kset *f2fs_kset;
21
22/* Sysfs support for f2fs */
23enum {
24 GC_THREAD, /* struct f2fs_gc_thread */
25 SM_INFO, /* struct f2fs_sm_info */
26 DCC_INFO, /* struct discard_cmd_control */
27 NM_INFO, /* struct f2fs_nm_info */
28 F2FS_SBI, /* struct f2fs_sb_info */
29#ifdef CONFIG_F2FS_FAULT_INJECTION
30 FAULT_INFO_RATE, /* struct f2fs_fault_info */
31 FAULT_INFO_TYPE, /* struct f2fs_fault_info */
32#endif
33 RESERVED_BLOCKS,
34};
35
36struct f2fs_attr {
37 struct attribute attr;
38 ssize_t (*show)(struct f2fs_attr *, struct f2fs_sb_info *, char *);
39 ssize_t (*store)(struct f2fs_attr *, struct f2fs_sb_info *,
40 const char *, size_t);
41 int struct_type;
42 int offset;
43};
44
45static unsigned char *__struct_ptr(struct f2fs_sb_info *sbi, int struct_type)
46{
47 if (struct_type == GC_THREAD)
48 return (unsigned char *)sbi->gc_thread;
49 else if (struct_type == SM_INFO)
50 return (unsigned char *)SM_I(sbi);
51 else if (struct_type == DCC_INFO)
52 return (unsigned char *)SM_I(sbi)->dcc_info;
53 else if (struct_type == NM_INFO)
54 return (unsigned char *)NM_I(sbi);
55 else if (struct_type == F2FS_SBI || struct_type == RESERVED_BLOCKS)
56 return (unsigned char *)sbi;
57#ifdef CONFIG_F2FS_FAULT_INJECTION
58 else if (struct_type == FAULT_INFO_RATE ||
59 struct_type == FAULT_INFO_TYPE)
60 return (unsigned char *)&sbi->fault_info;
61#endif
62 return NULL;
63}
64
65static ssize_t lifetime_write_kbytes_show(struct f2fs_attr *a,
66 struct f2fs_sb_info *sbi, char *buf)
67{
68 struct super_block *sb = sbi->sb;
69
70 if (!sb->s_bdev->bd_part)
71 return snprintf(buf, PAGE_SIZE, "0\n");
72
73 return snprintf(buf, PAGE_SIZE, "%llu\n",
74 (unsigned long long)(sbi->kbytes_written +
75 BD_PART_WRITTEN(sbi)));
76}
77
78static ssize_t f2fs_sbi_show(struct f2fs_attr *a,
79 struct f2fs_sb_info *sbi, char *buf)
80{
81 unsigned char *ptr = NULL;
82 unsigned int *ui;
83
84 ptr = __struct_ptr(sbi, a->struct_type);
85 if (!ptr)
86 return -EINVAL;
87
88 ui = (unsigned int *)(ptr + a->offset);
89
90 return snprintf(buf, PAGE_SIZE, "%u\n", *ui);
91}
92
93static ssize_t f2fs_sbi_store(struct f2fs_attr *a,
94 struct f2fs_sb_info *sbi,
95 const char *buf, size_t count)
96{
97 unsigned char *ptr;
98 unsigned long t;
99 unsigned int *ui;
100 ssize_t ret;
101
102 ptr = __struct_ptr(sbi, a->struct_type);
103 if (!ptr)
104 return -EINVAL;
105
106 ui = (unsigned int *)(ptr + a->offset);
107
108 ret = kstrtoul(skip_spaces(buf), 0, &t);
109 if (ret < 0)
110 return ret;
111#ifdef CONFIG_F2FS_FAULT_INJECTION
112 if (a->struct_type == FAULT_INFO_TYPE && t >= (1 << FAULT_MAX))
113 return -EINVAL;
114#endif
115 if (a->struct_type == RESERVED_BLOCKS) {
116 spin_lock(&sbi->stat_lock);
117 if ((unsigned long)sbi->total_valid_block_count + t >
118 (unsigned long)sbi->user_block_count) {
119 spin_unlock(&sbi->stat_lock);
120 return -EINVAL;
121 }
122 *ui = t;
123 spin_unlock(&sbi->stat_lock);
124 return count;
125 }
126 *ui = t;
127 return count;
128}
129
130static ssize_t f2fs_attr_show(struct kobject *kobj,
131 struct attribute *attr, char *buf)
132{
133 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
134 s_kobj);
135 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
136
137 return a->show ? a->show(a, sbi, buf) : 0;
138}
139
140static ssize_t f2fs_attr_store(struct kobject *kobj, struct attribute *attr,
141 const char *buf, size_t len)
142{
143 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
144 s_kobj);
145 struct f2fs_attr *a = container_of(attr, struct f2fs_attr, attr);
146
147 return a->store ? a->store(a, sbi, buf, len) : 0;
148}
149
150static void f2fs_sb_release(struct kobject *kobj)
151{
152 struct f2fs_sb_info *sbi = container_of(kobj, struct f2fs_sb_info,
153 s_kobj);
154 complete(&sbi->s_kobj_unregister);
155}
156
157#define F2FS_ATTR_OFFSET(_struct_type, _name, _mode, _show, _store, _offset) \
158static struct f2fs_attr f2fs_attr_##_name = { \
159 .attr = {.name = __stringify(_name), .mode = _mode }, \
160 .show = _show, \
161 .store = _store, \
162 .struct_type = _struct_type, \
163 .offset = _offset \
164}
165
166#define F2FS_RW_ATTR(struct_type, struct_name, name, elname) \
167 F2FS_ATTR_OFFSET(struct_type, name, 0644, \
168 f2fs_sbi_show, f2fs_sbi_store, \
169 offsetof(struct struct_name, elname))
170
171#define F2FS_GENERAL_RO_ATTR(name) \
172static struct f2fs_attr f2fs_attr_##name = __ATTR(name, 0444, name##_show, NULL)
173
174F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_min_sleep_time, min_sleep_time);
175F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_max_sleep_time, max_sleep_time);
176F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_no_gc_sleep_time, no_gc_sleep_time);
177F2FS_RW_ATTR(GC_THREAD, f2fs_gc_kthread, gc_idle, gc_idle);
178F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, reclaim_segments, rec_prefree_segments);
179F2FS_RW_ATTR(DCC_INFO, discard_cmd_control, max_small_discards, max_discards);
180F2FS_RW_ATTR(RESERVED_BLOCKS, f2fs_sb_info, reserved_blocks, reserved_blocks);
181F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, batched_trim_sections, trim_sections);
182F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, ipu_policy, ipu_policy);
183F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_ipu_util, min_ipu_util);
184F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_fsync_blocks, min_fsync_blocks);
185F2FS_RW_ATTR(SM_INFO, f2fs_sm_info, min_hot_blocks, min_hot_blocks);
186F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ram_thresh, ram_thresh);
187F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, ra_nid_pages, ra_nid_pages);
188F2FS_RW_ATTR(NM_INFO, f2fs_nm_info, dirty_nats_ratio, dirty_nats_ratio);
189F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, max_victim_search, max_victim_search);
190F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, dir_level, dir_level);
191F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, cp_interval, interval_time[CP_TIME]);
192F2FS_RW_ATTR(F2FS_SBI, f2fs_sb_info, idle_interval, interval_time[REQ_TIME]);
193#ifdef CONFIG_F2FS_FAULT_INJECTION
194F2FS_RW_ATTR(FAULT_INFO_RATE, f2fs_fault_info, inject_rate, inject_rate);
195F2FS_RW_ATTR(FAULT_INFO_TYPE, f2fs_fault_info, inject_type, inject_type);
196#endif
197F2FS_GENERAL_RO_ATTR(lifetime_write_kbytes);
198
199#define ATTR_LIST(name) (&f2fs_attr_##name.attr)
200static struct attribute *f2fs_attrs[] = {
201 ATTR_LIST(gc_min_sleep_time),
202 ATTR_LIST(gc_max_sleep_time),
203 ATTR_LIST(gc_no_gc_sleep_time),
204 ATTR_LIST(gc_idle),
205 ATTR_LIST(reclaim_segments),
206 ATTR_LIST(max_small_discards),
207 ATTR_LIST(batched_trim_sections),
208 ATTR_LIST(ipu_policy),
209 ATTR_LIST(min_ipu_util),
210 ATTR_LIST(min_fsync_blocks),
211 ATTR_LIST(min_hot_blocks),
212 ATTR_LIST(max_victim_search),
213 ATTR_LIST(dir_level),
214 ATTR_LIST(ram_thresh),
215 ATTR_LIST(ra_nid_pages),
216 ATTR_LIST(dirty_nats_ratio),
217 ATTR_LIST(cp_interval),
218 ATTR_LIST(idle_interval),
219#ifdef CONFIG_F2FS_FAULT_INJECTION
220 ATTR_LIST(inject_rate),
221 ATTR_LIST(inject_type),
222#endif
223 ATTR_LIST(lifetime_write_kbytes),
224 ATTR_LIST(reserved_blocks),
225 NULL,
226};
227
228static const struct sysfs_ops f2fs_attr_ops = {
229 .show = f2fs_attr_show,
230 .store = f2fs_attr_store,
231};
232
233static struct kobj_type f2fs_ktype = {
234 .default_attrs = f2fs_attrs,
235 .sysfs_ops = &f2fs_attr_ops,
236 .release = f2fs_sb_release,
237};
238
239static int segment_info_seq_show(struct seq_file *seq, void *offset)
240{
241 struct super_block *sb = seq->private;
242 struct f2fs_sb_info *sbi = F2FS_SB(sb);
243 unsigned int total_segs =
244 le32_to_cpu(sbi->raw_super->segment_count_main);
245 int i;
246
247 seq_puts(seq, "format: segment_type|valid_blocks\n"
248 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
249
250 for (i = 0; i < total_segs; i++) {
251 struct seg_entry *se = get_seg_entry(sbi, i);
252
253 if ((i % 10) == 0)
254 seq_printf(seq, "%-10d", i);
255 seq_printf(seq, "%d|%-3u", se->type,
256 get_valid_blocks(sbi, i, false));
257 if ((i % 10) == 9 || i == (total_segs - 1))
258 seq_putc(seq, '\n');
259 else
260 seq_putc(seq, ' ');
261 }
262
263 return 0;
264}
265
266static int segment_bits_seq_show(struct seq_file *seq, void *offset)
267{
268 struct super_block *sb = seq->private;
269 struct f2fs_sb_info *sbi = F2FS_SB(sb);
270 unsigned int total_segs =
271 le32_to_cpu(sbi->raw_super->segment_count_main);
272 int i, j;
273
274 seq_puts(seq, "format: segment_type|valid_blocks|bitmaps\n"
275 "segment_type(0:HD, 1:WD, 2:CD, 3:HN, 4:WN, 5:CN)\n");
276
277 for (i = 0; i < total_segs; i++) {
278 struct seg_entry *se = get_seg_entry(sbi, i);
279
280 seq_printf(seq, "%-10d", i);
281 seq_printf(seq, "%d|%-3u|", se->type,
282 get_valid_blocks(sbi, i, false));
283 for (j = 0; j < SIT_VBLOCK_MAP_SIZE; j++)
284 seq_printf(seq, " %.2x", se->cur_valid_map[j]);
285 seq_putc(seq, '\n');
286 }
287 return 0;
288}
289
290#define F2FS_PROC_FILE_DEF(_name) \
291static int _name##_open_fs(struct inode *inode, struct file *file) \
292{ \
293 return single_open(file, _name##_seq_show, PDE_DATA(inode)); \
294} \
295 \
296static const struct file_operations f2fs_seq_##_name##_fops = { \
297 .open = _name##_open_fs, \
298 .read = seq_read, \
299 .llseek = seq_lseek, \
300 .release = single_release, \
301};
302
303F2FS_PROC_FILE_DEF(segment_info);
304F2FS_PROC_FILE_DEF(segment_bits);
305
306int __init f2fs_register_sysfs(void)
307{
308 f2fs_proc_root = proc_mkdir("fs/f2fs", NULL);
309
310 f2fs_kset = kset_create_and_add("f2fs", NULL, fs_kobj);
311 if (!f2fs_kset)
312 return -ENOMEM;
313 return 0;
314}
315
316void f2fs_unregister_sysfs(void)
317{
318 kset_unregister(f2fs_kset);
319 remove_proc_entry("fs/f2fs", NULL);
320}
321
322int f2fs_init_sysfs(struct f2fs_sb_info *sbi)
323{
324 struct super_block *sb = sbi->sb;
325 int err;
326
327 if (f2fs_proc_root)
328 sbi->s_proc = proc_mkdir(sb->s_id, f2fs_proc_root);
329
330 if (sbi->s_proc) {
331 proc_create_data("segment_info", S_IRUGO, sbi->s_proc,
332 &f2fs_seq_segment_info_fops, sb);
333 proc_create_data("segment_bits", S_IRUGO, sbi->s_proc,
334 &f2fs_seq_segment_bits_fops, sb);
335 }
336
337 sbi->s_kobj.kset = f2fs_kset;
338 init_completion(&sbi->s_kobj_unregister);
339 err = kobject_init_and_add(&sbi->s_kobj, &f2fs_ktype, NULL,
340 "%s", sb->s_id);
341 if (err)
342 goto err_out;
343 return 0;
344err_out:
345 if (sbi->s_proc) {
346 remove_proc_entry("segment_info", sbi->s_proc);
347 remove_proc_entry("segment_bits", sbi->s_proc);
348 remove_proc_entry(sb->s_id, f2fs_proc_root);
349 }
350 return err;
351}
352
353void f2fs_exit_sysfs(struct f2fs_sb_info *sbi)
354{
355 kobject_del(&sbi->s_kobj);
356 kobject_put(&sbi->s_kobj);
357 wait_for_completion(&sbi->s_kobj_unregister);
358
359 if (sbi->s_proc) {
360 remove_proc_entry("segment_info", sbi->s_proc);
361 remove_proc_entry("segment_bits", sbi->s_proc);
362 remove_proc_entry(sbi->sb->s_id, f2fs_proc_root);
363 }
364}
diff --git a/include/trace/events/f2fs.h b/include/trace/events/f2fs.h
index 15da88c5c3a4..6f77a2755abb 100644
--- a/include/trace/events/f2fs.h
+++ b/include/trace/events/f2fs.h
@@ -19,6 +19,9 @@ TRACE_DEFINE_ENUM(INMEM_INVALIDATE);
19TRACE_DEFINE_ENUM(INMEM_REVOKE); 19TRACE_DEFINE_ENUM(INMEM_REVOKE);
20TRACE_DEFINE_ENUM(IPU); 20TRACE_DEFINE_ENUM(IPU);
21TRACE_DEFINE_ENUM(OPU); 21TRACE_DEFINE_ENUM(OPU);
22TRACE_DEFINE_ENUM(HOT);
23TRACE_DEFINE_ENUM(WARM);
24TRACE_DEFINE_ENUM(COLD);
22TRACE_DEFINE_ENUM(CURSEG_HOT_DATA); 25TRACE_DEFINE_ENUM(CURSEG_HOT_DATA);
23TRACE_DEFINE_ENUM(CURSEG_WARM_DATA); 26TRACE_DEFINE_ENUM(CURSEG_WARM_DATA);
24TRACE_DEFINE_ENUM(CURSEG_COLD_DATA); 27TRACE_DEFINE_ENUM(CURSEG_COLD_DATA);
@@ -59,6 +62,12 @@ TRACE_DEFINE_ENUM(CP_TRIMMED);
59 { IPU, "IN-PLACE" }, \ 62 { IPU, "IN-PLACE" }, \
60 { OPU, "OUT-OF-PLACE" }) 63 { OPU, "OUT-OF-PLACE" })
61 64
65#define show_block_temp(temp) \
66 __print_symbolic(temp, \
67 { HOT, "HOT" }, \
68 { WARM, "WARM" }, \
69 { COLD, "COLD" })
70
62#define F2FS_OP_FLAGS (REQ_RAHEAD | REQ_SYNC | REQ_META | REQ_PRIO | \ 71#define F2FS_OP_FLAGS (REQ_RAHEAD | REQ_SYNC | REQ_META | REQ_PRIO | \
63 REQ_PREFLUSH | REQ_FUA) 72 REQ_PREFLUSH | REQ_FUA)
64#define F2FS_BIO_FLAG_MASK(t) (t & F2FS_OP_FLAGS) 73#define F2FS_BIO_FLAG_MASK(t) (t & F2FS_OP_FLAGS)
@@ -757,6 +766,7 @@ DECLARE_EVENT_CLASS(f2fs__submit_page_bio,
757 __field(block_t, new_blkaddr) 766 __field(block_t, new_blkaddr)
758 __field(int, op) 767 __field(int, op)
759 __field(int, op_flags) 768 __field(int, op_flags)
769 __field(int, temp)
760 __field(int, type) 770 __field(int, type)
761 ), 771 ),
762 772
@@ -768,16 +778,18 @@ DECLARE_EVENT_CLASS(f2fs__submit_page_bio,
768 __entry->new_blkaddr = fio->new_blkaddr; 778 __entry->new_blkaddr = fio->new_blkaddr;
769 __entry->op = fio->op; 779 __entry->op = fio->op;
770 __entry->op_flags = fio->op_flags; 780 __entry->op_flags = fio->op_flags;
781 __entry->temp = fio->temp;
771 __entry->type = fio->type; 782 __entry->type = fio->type;
772 ), 783 ),
773 784
774 TP_printk("dev = (%d,%d), ino = %lu, page_index = 0x%lx, " 785 TP_printk("dev = (%d,%d), ino = %lu, page_index = 0x%lx, "
775 "oldaddr = 0x%llx, newaddr = 0x%llx, rw = %s(%s), type = %s", 786 "oldaddr = 0x%llx, newaddr = 0x%llx, rw = %s(%s), type = %s_%s",
776 show_dev_ino(__entry), 787 show_dev_ino(__entry),
777 (unsigned long)__entry->index, 788 (unsigned long)__entry->index,
778 (unsigned long long)__entry->old_blkaddr, 789 (unsigned long long)__entry->old_blkaddr,
779 (unsigned long long)__entry->new_blkaddr, 790 (unsigned long long)__entry->new_blkaddr,
780 show_bio_type(__entry->op, __entry->op_flags), 791 show_bio_type(__entry->op, __entry->op_flags),
792 show_block_temp(__entry->temp),
781 show_block_type(__entry->type)) 793 show_block_type(__entry->type))
782); 794);
783 795
@@ -790,7 +802,7 @@ DEFINE_EVENT_CONDITION(f2fs__submit_page_bio, f2fs_submit_page_bio,
790 TP_CONDITION(page->mapping) 802 TP_CONDITION(page->mapping)
791); 803);
792 804
793DEFINE_EVENT_CONDITION(f2fs__submit_page_bio, f2fs_submit_page_mbio, 805DEFINE_EVENT_CONDITION(f2fs__submit_page_bio, f2fs_submit_page_write,
794 806
795 TP_PROTO(struct page *page, struct f2fs_io_info *fio), 807 TP_PROTO(struct page *page, struct f2fs_io_info *fio),
796 808