blob: acdc0767f77c66779852a4ed1088b98b9f5f95e1 [file] [log] [blame]
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +09001/*
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09002 * fs/f2fs/data.c
3 *
4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#include <linux/fs.h>
12#include <linux/f2fs_fs.h>
13#include <linux/buffer_head.h>
14#include <linux/mpage.h>
Kent Overstreeta27bb332013-05-07 16:19:08 -070015#include <linux/aio.h>
Jaegeuk Kimeb47b802012-11-02 17:10:12 +090016#include <linux/writeback.h>
17#include <linux/backing-dev.h>
18#include <linux/blkdev.h>
19#include <linux/bio.h>
Geert Uytterhoeven690e4a32012-12-19 22:19:30 +010020#include <linux/prefetch.h>
Jaegeuk Kimeb47b802012-11-02 17:10:12 +090021
22#include "f2fs.h"
23#include "node.h"
24#include "segment.h"
Jaegeuk Kimdb9f7c12014-12-17 20:04:08 -080025#include "trace.h"
Namjae Jeon848753a2013-04-23 16:38:02 +090026#include <trace/events/f2fs.h>
Jaegeuk Kimeb47b802012-11-02 17:10:12 +090027
Chao Yu429511c2015-02-05 17:54:31 +080028static struct kmem_cache *extent_tree_slab;
29static struct kmem_cache *extent_node_slab;
30
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090031static void f2fs_read_end_io(struct bio *bio, int err)
32{
Linus Torvaldsf5688492014-01-30 11:19:05 -080033 struct bio_vec *bvec;
34 int i;
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090035
Linus Torvaldsf5688492014-01-30 11:19:05 -080036 bio_for_each_segment_all(bvec, bio, i) {
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090037 struct page *page = bvec->bv_page;
38
Linus Torvaldsf5688492014-01-30 11:19:05 -080039 if (!err) {
40 SetPageUptodate(page);
41 } else {
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090042 ClearPageUptodate(page);
43 SetPageError(page);
44 }
45 unlock_page(page);
Linus Torvaldsf5688492014-01-30 11:19:05 -080046 }
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090047 bio_put(bio);
48}
49
50static void f2fs_write_end_io(struct bio *bio, int err)
51{
Jaegeuk Kim1b1f5592014-02-03 10:50:22 +090052 struct f2fs_sb_info *sbi = bio->bi_private;
Linus Torvaldsf5688492014-01-30 11:19:05 -080053 struct bio_vec *bvec;
54 int i;
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090055
Linus Torvaldsf5688492014-01-30 11:19:05 -080056 bio_for_each_segment_all(bvec, bio, i) {
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090057 struct page *page = bvec->bv_page;
58
Linus Torvaldsf5688492014-01-30 11:19:05 -080059 if (unlikely(err)) {
Jaegeuk Kimcf779ca2014-08-11 18:37:46 -070060 set_page_dirty(page);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090061 set_bit(AS_EIO, &page->mapping->flags);
Jaegeuk Kim744602c2014-01-24 09:42:16 +090062 f2fs_stop_checkpoint(sbi);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090063 }
64 end_page_writeback(page);
65 dec_page_count(sbi, F2FS_WRITEBACK);
Linus Torvaldsf5688492014-01-30 11:19:05 -080066 }
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090067
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090068 if (!get_pages(sbi, F2FS_WRITEBACK) &&
69 !list_empty(&sbi->cp_wait.task_list))
70 wake_up(&sbi->cp_wait);
71
72 bio_put(bio);
73}
74
Gu Zheng940a6d32013-12-20 17:39:59 +080075/*
76 * Low-level block read/write IO operations.
77 */
78static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr,
79 int npages, bool is_read)
80{
81 struct bio *bio;
82
83 /* No failure on bio allocation */
84 bio = bio_alloc(GFP_NOIO, npages);
85
86 bio->bi_bdev = sbi->sb->s_bdev;
Chao Yu55cf9cb2014-09-15 18:01:10 +080087 bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blk_addr);
Gu Zheng940a6d32013-12-20 17:39:59 +080088 bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io;
Jaegeuk Kim1b1f5592014-02-03 10:50:22 +090089 bio->bi_private = sbi;
Gu Zheng940a6d32013-12-20 17:39:59 +080090
91 return bio;
92}
93
Jaegeuk Kim458e6192013-12-11 13:54:01 +090094static void __submit_merged_bio(struct f2fs_bio_info *io)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090095{
Jaegeuk Kim458e6192013-12-11 13:54:01 +090096 struct f2fs_io_info *fio = &io->fio;
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090097
98 if (!io->bio)
99 return;
100
Jaegeuk Kim6a8f8ca2014-10-29 14:37:22 -0700101 if (is_read_io(fio->rw))
Chao Yu2ace38e2014-12-24 16:08:14 +0800102 trace_f2fs_submit_read_bio(io->sbi->sb, fio, io->bio);
Jaegeuk Kim6a8f8ca2014-10-29 14:37:22 -0700103 else
Chao Yu2ace38e2014-12-24 16:08:14 +0800104 trace_f2fs_submit_write_bio(io->sbi->sb, fio, io->bio);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900105
Jaegeuk Kim6a8f8ca2014-10-29 14:37:22 -0700106 submit_bio(fio->rw, io->bio);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900107 io->bio = NULL;
108}
109
110void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi,
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900111 enum page_type type, int rw)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900112{
113 enum page_type btype = PAGE_TYPE_OF_BIO(type);
114 struct f2fs_bio_info *io;
115
116 io = is_read_io(rw) ? &sbi->read_io : &sbi->write_io[btype];
117
Chao Yudf0f8dc2014-03-22 14:57:23 +0800118 down_write(&io->io_rwsem);
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900119
120 /* change META to META_FLUSH in the checkpoint procedure */
121 if (type >= META_FLUSH) {
122 io->fio.type = META_FLUSH;
Jaegeuk Kim0f7b2ab2014-07-23 09:57:31 -0700123 if (test_opt(sbi, NOBARRIER))
124 io->fio.rw = WRITE_FLUSH | REQ_META | REQ_PRIO;
125 else
126 io->fio.rw = WRITE_FLUSH_FUA | REQ_META | REQ_PRIO;
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900127 }
128 __submit_merged_bio(io);
Chao Yudf0f8dc2014-03-22 14:57:23 +0800129 up_write(&io->io_rwsem);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900130}
131
132/*
133 * Fill the locked page with data located in the block address.
134 * Return unlocked page.
135 */
136int f2fs_submit_page_bio(struct f2fs_sb_info *sbi, struct page *page,
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800137 struct f2fs_io_info *fio)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900138{
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900139 struct bio *bio;
140
Chao Yu2ace38e2014-12-24 16:08:14 +0800141 trace_f2fs_submit_page_bio(page, fio);
Jaegeuk Kimdb9f7c12014-12-17 20:04:08 -0800142 f2fs_trace_ios(page, fio, 0);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900143
144 /* Allocate a new bio */
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800145 bio = __bio_alloc(sbi, fio->blk_addr, 1, is_read_io(fio->rw));
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900146
147 if (bio_add_page(bio, page, PAGE_CACHE_SIZE, 0) < PAGE_CACHE_SIZE) {
148 bio_put(bio);
149 f2fs_put_page(page, 1);
150 return -EFAULT;
151 }
152
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800153 submit_bio(fio->rw, bio);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900154 return 0;
155}
156
157void f2fs_submit_page_mbio(struct f2fs_sb_info *sbi, struct page *page,
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800158 struct f2fs_io_info *fio)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900159{
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900160 enum page_type btype = PAGE_TYPE_OF_BIO(fio->type);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900161 struct f2fs_bio_info *io;
Gu Zheng940a6d32013-12-20 17:39:59 +0800162 bool is_read = is_read_io(fio->rw);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900163
Gu Zheng940a6d32013-12-20 17:39:59 +0800164 io = is_read ? &sbi->read_io : &sbi->write_io[btype];
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900165
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800166 verify_block_addr(sbi, fio->blk_addr);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900167
Chao Yudf0f8dc2014-03-22 14:57:23 +0800168 down_write(&io->io_rwsem);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900169
Gu Zheng940a6d32013-12-20 17:39:59 +0800170 if (!is_read)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900171 inc_page_count(sbi, F2FS_WRITEBACK);
172
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800173 if (io->bio && (io->last_block_in_bio != fio->blk_addr - 1 ||
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900174 io->fio.rw != fio->rw))
175 __submit_merged_bio(io);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900176alloc_new:
177 if (io->bio == NULL) {
Jaegeuk Kim90a893c2014-09-22 16:21:07 -0700178 int bio_blocks = MAX_BIO_BLOCKS(sbi);
Gu Zheng940a6d32013-12-20 17:39:59 +0800179
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800180 io->bio = __bio_alloc(sbi, fio->blk_addr, bio_blocks, is_read);
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900181 io->fio = *fio;
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900182 }
183
184 if (bio_add_page(io->bio, page, PAGE_CACHE_SIZE, 0) <
185 PAGE_CACHE_SIZE) {
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900186 __submit_merged_bio(io);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900187 goto alloc_new;
188 }
189
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800190 io->last_block_in_bio = fio->blk_addr;
Jaegeuk Kimdb9f7c12014-12-17 20:04:08 -0800191 f2fs_trace_ios(page, fio, 0);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900192
Chao Yudf0f8dc2014-03-22 14:57:23 +0800193 up_write(&io->io_rwsem);
Chao Yu2ace38e2014-12-24 16:08:14 +0800194 trace_f2fs_submit_page_mbio(page, fio);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900195}
196
197/*
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900198 * Lock ordering for the change of data block address:
199 * ->data_page
200 * ->node_page
201 * update block addresses in the node page
202 */
Jaegeuk Kime1509cf2014-12-30 22:57:55 -0800203static void __set_data_blkaddr(struct dnode_of_data *dn)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900204{
205 struct f2fs_node *rn;
206 __le32 *addr_array;
207 struct page *node_page = dn->node_page;
208 unsigned int ofs_in_node = dn->ofs_in_node;
209
Yuan Zhong5514f0a2014-01-10 07:26:14 +0000210 f2fs_wait_on_page_writeback(node_page, NODE);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900211
Gu Zheng45590712013-07-15 17:57:38 +0800212 rn = F2FS_NODE(node_page);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900213
214 /* Get physical address of data block */
215 addr_array = blkaddr_in_node(rn);
Jaegeuk Kime1509cf2014-12-30 22:57:55 -0800216 addr_array[ofs_in_node] = cpu_to_le32(dn->data_blkaddr);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900217 set_page_dirty(node_page);
218}
219
220int reserve_new_block(struct dnode_of_data *dn)
221{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700222 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900223
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900224 if (unlikely(is_inode_flag_set(F2FS_I(dn->inode), FI_NO_ALLOC)))
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900225 return -EPERM;
Chao Yucfb271d2013-12-05 17:15:22 +0800226 if (unlikely(!inc_valid_block_count(sbi, dn->inode, 1)))
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900227 return -ENOSPC;
228
Namjae Jeonc01e2852013-04-23 17:00:52 +0900229 trace_f2fs_reserve_new_block(dn->inode, dn->nid, dn->ofs_in_node);
230
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900231 dn->data_blkaddr = NEW_ADDR;
Jaegeuk Kime1509cf2014-12-30 22:57:55 -0800232 __set_data_blkaddr(dn);
Jaegeuk Kima18ff062014-01-21 13:32:12 +0900233 mark_inode_dirty(dn->inode);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900234 sync_inode_page(dn);
235 return 0;
236}
237
Huajun Lib6009652013-11-10 23:13:18 +0800238int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)
239{
240 bool need_put = dn->inode_page ? false : true;
241 int err;
242
243 err = get_dnode_of_data(dn, index, ALLOC_NODE);
244 if (err)
245 return err;
Jaegeuk Kima8865372013-12-27 17:04:17 +0900246
Huajun Lib6009652013-11-10 23:13:18 +0800247 if (dn->data_blkaddr == NULL_ADDR)
248 err = reserve_new_block(dn);
Jaegeuk Kima8865372013-12-27 17:04:17 +0900249 if (err || need_put)
Huajun Lib6009652013-11-10 23:13:18 +0800250 f2fs_put_dnode(dn);
251 return err;
252}
253
Chao Yua2e7d1b2015-02-05 17:50:30 +0800254static void f2fs_map_bh(struct super_block *sb, pgoff_t pgofs,
255 struct extent_info *ei, struct buffer_head *bh_result)
256{
257 unsigned int blkbits = sb->s_blocksize_bits;
258 size_t count;
259
260 set_buffer_new(bh_result);
261 map_bh(bh_result, sb, ei->blk + pgofs - ei->fofs);
262 count = ei->fofs + ei->len - pgofs;
263 if (count < (UINT_MAX >> blkbits))
264 bh_result->b_size = (count << blkbits);
265 else
266 bh_result->b_size = UINT_MAX;
267}
268
Chao Yu7e4dde72015-02-05 17:51:34 +0800269static bool lookup_extent_info(struct inode *inode, pgoff_t pgofs,
270 struct extent_info *ei)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900271{
272 struct f2fs_inode_info *fi = F2FS_I(inode);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900273 pgoff_t start_fofs, end_fofs;
274 block_t start_blkaddr;
275
Jaegeuk Kimc11abd12013-11-19 10:41:54 +0900276 if (is_inode_flag_set(fi, FI_NO_EXTENT))
Chao Yu7e4dde72015-02-05 17:51:34 +0800277 return false;
Jaegeuk Kimc11abd12013-11-19 10:41:54 +0900278
Chao Yu0c872e22015-02-05 17:46:29 +0800279 read_lock(&fi->ext_lock);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900280 if (fi->ext.len == 0) {
Chao Yu0c872e22015-02-05 17:46:29 +0800281 read_unlock(&fi->ext_lock);
Chao Yu7e4dde72015-02-05 17:51:34 +0800282 return false;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900283 }
284
Jaegeuk Kimdcdfff62013-10-22 20:56:10 +0900285 stat_inc_total_hit(inode->i_sb);
286
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900287 start_fofs = fi->ext.fofs;
288 end_fofs = fi->ext.fofs + fi->ext.len - 1;
Chao Yu4d0b0bd2015-02-05 17:47:25 +0800289 start_blkaddr = fi->ext.blk;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900290
291 if (pgofs >= start_fofs && pgofs <= end_fofs) {
Chao Yua2e7d1b2015-02-05 17:50:30 +0800292 *ei = fi->ext;
Jaegeuk Kimdcdfff62013-10-22 20:56:10 +0900293 stat_inc_read_hit(inode->i_sb);
Chao Yu0c872e22015-02-05 17:46:29 +0800294 read_unlock(&fi->ext_lock);
Chao Yu7e4dde72015-02-05 17:51:34 +0800295 return true;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900296 }
Chao Yu0c872e22015-02-05 17:46:29 +0800297 read_unlock(&fi->ext_lock);
Chao Yu7e4dde72015-02-05 17:51:34 +0800298 return false;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900299}
300
Chao Yu7e4dde72015-02-05 17:51:34 +0800301static bool update_extent_info(struct inode *inode, pgoff_t fofs,
302 block_t blkaddr)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900303{
Chao Yu7e4dde72015-02-05 17:51:34 +0800304 struct f2fs_inode_info *fi = F2FS_I(inode);
305 pgoff_t start_fofs, end_fofs;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900306 block_t start_blkaddr, end_blkaddr;
Jaegeuk Kimc11abd12013-11-19 10:41:54 +0900307 int need_update = true;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900308
Jaegeuk Kimc11abd12013-11-19 10:41:54 +0900309 if (is_inode_flag_set(fi, FI_NO_EXTENT))
Chao Yu7e4dde72015-02-05 17:51:34 +0800310 return false;
Jaegeuk Kim3547ea92014-12-30 23:08:26 -0800311
Chao Yu0c872e22015-02-05 17:46:29 +0800312 write_lock(&fi->ext_lock);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900313
314 start_fofs = fi->ext.fofs;
315 end_fofs = fi->ext.fofs + fi->ext.len - 1;
Chao Yu4d0b0bd2015-02-05 17:47:25 +0800316 start_blkaddr = fi->ext.blk;
317 end_blkaddr = fi->ext.blk + fi->ext.len - 1;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900318
319 /* Drop and initialize the matched extent */
320 if (fi->ext.len == 1 && fofs == start_fofs)
321 fi->ext.len = 0;
322
323 /* Initial extent */
324 if (fi->ext.len == 0) {
Chao Yu7e4dde72015-02-05 17:51:34 +0800325 if (blkaddr != NULL_ADDR) {
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900326 fi->ext.fofs = fofs;
Chao Yu7e4dde72015-02-05 17:51:34 +0800327 fi->ext.blk = blkaddr;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900328 fi->ext.len = 1;
329 }
330 goto end_update;
331 }
332
Namjae Jeon6224da82013-04-06 14:44:32 +0900333 /* Front merge */
Chao Yu7e4dde72015-02-05 17:51:34 +0800334 if (fofs == start_fofs - 1 && blkaddr == start_blkaddr - 1) {
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900335 fi->ext.fofs--;
Chao Yu4d0b0bd2015-02-05 17:47:25 +0800336 fi->ext.blk--;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900337 fi->ext.len++;
338 goto end_update;
339 }
340
341 /* Back merge */
Chao Yu7e4dde72015-02-05 17:51:34 +0800342 if (fofs == end_fofs + 1 && blkaddr == end_blkaddr + 1) {
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900343 fi->ext.len++;
344 goto end_update;
345 }
346
347 /* Split the existing extent */
348 if (fi->ext.len > 1 &&
349 fofs >= start_fofs && fofs <= end_fofs) {
350 if ((end_fofs - fofs) < (fi->ext.len >> 1)) {
351 fi->ext.len = fofs - start_fofs;
352 } else {
353 fi->ext.fofs = fofs + 1;
Chao Yu4d0b0bd2015-02-05 17:47:25 +0800354 fi->ext.blk = start_blkaddr + fofs - start_fofs + 1;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900355 fi->ext.len -= fofs - start_fofs + 1;
356 }
Jaegeuk Kimc11abd12013-11-19 10:41:54 +0900357 } else {
358 need_update = false;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900359 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900360
Jaegeuk Kimc11abd12013-11-19 10:41:54 +0900361 /* Finally, if the extent is very fragmented, let's drop the cache. */
362 if (fi->ext.len < F2FS_MIN_EXTENT_LEN) {
363 fi->ext.len = 0;
364 set_inode_flag(fi, FI_NO_EXTENT);
365 need_update = true;
366 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900367end_update:
Chao Yu0c872e22015-02-05 17:46:29 +0800368 write_unlock(&fi->ext_lock);
Chao Yu7e4dde72015-02-05 17:51:34 +0800369 return need_update;
370}
371
Chao Yu429511c2015-02-05 17:54:31 +0800372static struct extent_node *__attach_extent_node(struct f2fs_sb_info *sbi,
373 struct extent_tree *et, struct extent_info *ei,
374 struct rb_node *parent, struct rb_node **p)
375{
376 struct extent_node *en;
377
378 en = kmem_cache_alloc(extent_node_slab, GFP_ATOMIC);
379 if (!en)
380 return NULL;
381
382 en->ei = *ei;
383 INIT_LIST_HEAD(&en->list);
384
385 rb_link_node(&en->rb_node, parent, p);
386 rb_insert_color(&en->rb_node, &et->root);
387 et->count++;
388 atomic_inc(&sbi->total_ext_node);
389 return en;
390}
391
392static void __detach_extent_node(struct f2fs_sb_info *sbi,
393 struct extent_tree *et, struct extent_node *en)
394{
395 rb_erase(&en->rb_node, &et->root);
396 et->count--;
397 atomic_dec(&sbi->total_ext_node);
398}
399
400static struct extent_node *__lookup_extent_tree(struct extent_tree *et,
401 unsigned int fofs)
402{
403 struct rb_node *node = et->root.rb_node;
404 struct extent_node *en;
405
406 while (node) {
407 en = rb_entry(node, struct extent_node, rb_node);
408
409 if (fofs < en->ei.fofs)
410 node = node->rb_left;
411 else if (fofs >= en->ei.fofs + en->ei.len)
412 node = node->rb_right;
413 else
414 return en;
415 }
416 return NULL;
417}
418
419static struct extent_node *__try_back_merge(struct f2fs_sb_info *sbi,
420 struct extent_tree *et, struct extent_node *en)
421{
422 struct extent_node *prev;
423 struct rb_node *node;
424
425 node = rb_prev(&en->rb_node);
426 if (!node)
427 return NULL;
428
429 prev = rb_entry(node, struct extent_node, rb_node);
430 if (__is_back_mergeable(&en->ei, &prev->ei)) {
431 en->ei.fofs = prev->ei.fofs;
432 en->ei.blk = prev->ei.blk;
433 en->ei.len += prev->ei.len;
434 __detach_extent_node(sbi, et, prev);
435 return prev;
436 }
437 return NULL;
438}
439
440static struct extent_node *__try_front_merge(struct f2fs_sb_info *sbi,
441 struct extent_tree *et, struct extent_node *en)
442{
443 struct extent_node *next;
444 struct rb_node *node;
445
446 node = rb_next(&en->rb_node);
447 if (!node)
448 return NULL;
449
450 next = rb_entry(node, struct extent_node, rb_node);
451 if (__is_front_mergeable(&en->ei, &next->ei)) {
452 en->ei.len += next->ei.len;
453 __detach_extent_node(sbi, et, next);
454 return next;
455 }
456 return NULL;
457}
458
459static struct extent_node *__insert_extent_tree(struct f2fs_sb_info *sbi,
460 struct extent_tree *et, struct extent_info *ei,
461 struct extent_node **den)
462{
463 struct rb_node **p = &et->root.rb_node;
464 struct rb_node *parent = NULL;
465 struct extent_node *en;
466
467 while (*p) {
468 parent = *p;
469 en = rb_entry(parent, struct extent_node, rb_node);
470
471 if (ei->fofs < en->ei.fofs) {
472 if (__is_front_mergeable(ei, &en->ei)) {
473 f2fs_bug_on(sbi, !den);
474 en->ei.fofs = ei->fofs;
475 en->ei.blk = ei->blk;
476 en->ei.len += ei->len;
477 *den = __try_back_merge(sbi, et, en);
478 return en;
479 }
480 p = &(*p)->rb_left;
481 } else if (ei->fofs >= en->ei.fofs + en->ei.len) {
482 if (__is_back_mergeable(ei, &en->ei)) {
483 f2fs_bug_on(sbi, !den);
484 en->ei.len += ei->len;
485 *den = __try_front_merge(sbi, et, en);
486 return en;
487 }
488 p = &(*p)->rb_right;
489 } else {
490 f2fs_bug_on(sbi, 1);
491 }
492 }
493
494 return __attach_extent_node(sbi, et, ei, parent, p);
495}
496
497static unsigned int __free_extent_tree(struct f2fs_sb_info *sbi,
498 struct extent_tree *et, bool free_all)
499{
500 struct rb_node *node, *next;
501 struct extent_node *en;
502 unsigned int count = et->count;
503
504 node = rb_first(&et->root);
505 while (node) {
506 next = rb_next(node);
507 en = rb_entry(node, struct extent_node, rb_node);
508
509 if (free_all) {
510 spin_lock(&sbi->extent_lock);
511 if (!list_empty(&en->list))
512 list_del_init(&en->list);
513 spin_unlock(&sbi->extent_lock);
514 }
515
516 if (free_all || list_empty(&en->list)) {
517 __detach_extent_node(sbi, et, en);
518 kmem_cache_free(extent_node_slab, en);
519 }
520 node = next;
521 }
522
523 return count - et->count;
524}
525
526static bool f2fs_lookup_extent_tree(struct inode *inode, pgoff_t pgofs,
527 struct extent_info *ei)
528{
529 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
530 struct extent_tree *et;
531 struct extent_node *en;
532
533 if (is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT))
534 return false;
535
536 down_read(&sbi->extent_tree_lock);
537 et = radix_tree_lookup(&sbi->extent_tree_root, inode->i_ino);
538 if (!et) {
539 up_read(&sbi->extent_tree_lock);
540 return false;
541 }
542 atomic_inc(&et->refcount);
543 up_read(&sbi->extent_tree_lock);
544
545 read_lock(&et->lock);
546 en = __lookup_extent_tree(et, pgofs);
547 if (en) {
548 *ei = en->ei;
549 spin_lock(&sbi->extent_lock);
550 if (!list_empty(&en->list))
551 list_move_tail(&en->list, &sbi->extent_list);
552 spin_unlock(&sbi->extent_lock);
553 stat_inc_read_hit(sbi->sb);
554 }
555 stat_inc_total_hit(sbi->sb);
556 read_unlock(&et->lock);
557
558 atomic_dec(&et->refcount);
559 return en ? true : false;
560}
561
562static void f2fs_update_extent_tree(struct inode *inode, pgoff_t fofs,
563 block_t blkaddr)
564{
565 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
566 nid_t ino = inode->i_ino;
567 struct extent_tree *et;
568 struct extent_node *en = NULL, *en1 = NULL, *en2 = NULL, *en3 = NULL;
569 struct extent_node *den = NULL;
570 struct extent_info ei, dei;
571 unsigned int endofs;
572
573 if (is_inode_flag_set(F2FS_I(inode), FI_NO_EXTENT))
574 return;
575
576 down_write(&sbi->extent_tree_lock);
577 et = radix_tree_lookup(&sbi->extent_tree_root, ino);
578 if (!et) {
579 et = f2fs_kmem_cache_alloc(extent_tree_slab, GFP_NOFS);
580 f2fs_radix_tree_insert(&sbi->extent_tree_root, ino, et);
581 memset(et, 0, sizeof(struct extent_tree));
582 et->ino = ino;
583 et->root = RB_ROOT;
584 rwlock_init(&et->lock);
585 atomic_set(&et->refcount, 0);
586 et->count = 0;
587 sbi->total_ext_tree++;
588 }
589 atomic_inc(&et->refcount);
590 up_write(&sbi->extent_tree_lock);
591
592 write_lock(&et->lock);
593
594 /* 1. lookup and remove existing extent info in cache */
595 en = __lookup_extent_tree(et, fofs);
596 if (!en)
597 goto update_extent;
598
599 dei = en->ei;
600 __detach_extent_node(sbi, et, en);
601
602 /* 2. if extent can be split more, split and insert the left part */
603 if (dei.len > 1) {
604 /* insert left part of split extent into cache */
605 if (fofs - dei.fofs >= F2FS_MIN_EXTENT_LEN) {
606 set_extent_info(&ei, dei.fofs, dei.blk,
607 fofs - dei.fofs);
608 en1 = __insert_extent_tree(sbi, et, &ei, NULL);
609 }
610
611 /* insert right part of split extent into cache */
612 endofs = dei.fofs + dei.len - 1;
613 if (endofs - fofs >= F2FS_MIN_EXTENT_LEN) {
614 set_extent_info(&ei, fofs + 1,
615 fofs - dei.fofs + dei.blk, endofs - fofs);
616 en2 = __insert_extent_tree(sbi, et, &ei, NULL);
617 }
618 }
619
620update_extent:
621 /* 3. update extent in extent cache */
622 if (blkaddr) {
623 set_extent_info(&ei, fofs, blkaddr, 1);
624 en3 = __insert_extent_tree(sbi, et, &ei, &den);
625 }
626
627 /* 4. update in global extent list */
628 spin_lock(&sbi->extent_lock);
629 if (en && !list_empty(&en->list))
630 list_del(&en->list);
631 /*
632 * en1 and en2 split from en, they will become more and more smaller
633 * fragments after splitting several times. So if the length is smaller
634 * than F2FS_MIN_EXTENT_LEN, we will not add them into extent tree.
635 */
636 if (en1)
637 list_add_tail(&en1->list, &sbi->extent_list);
638 if (en2)
639 list_add_tail(&en2->list, &sbi->extent_list);
640 if (en3) {
641 if (list_empty(&en3->list))
642 list_add_tail(&en3->list, &sbi->extent_list);
643 else
644 list_move_tail(&en3->list, &sbi->extent_list);
645 }
646 if (den && !list_empty(&den->list))
647 list_del(&den->list);
648 spin_unlock(&sbi->extent_lock);
649
650 /* 5. release extent node */
651 if (en)
652 kmem_cache_free(extent_node_slab, en);
653 if (den)
654 kmem_cache_free(extent_node_slab, den);
655
656 write_unlock(&et->lock);
657 atomic_dec(&et->refcount);
658}
659
660void f2fs_shrink_extent_tree(struct f2fs_sb_info *sbi, int nr_shrink)
661{
662 struct extent_tree *treevec[EXT_TREE_VEC_SIZE];
663 struct extent_node *en, *tmp;
664 unsigned long ino = F2FS_ROOT_INO(sbi);
665 struct radix_tree_iter iter;
666 void **slot;
667 unsigned int found;
668
Chao Yu1dcc3362015-02-05 17:57:31 +0800669 if (!test_opt(sbi, EXTENT_CACHE))
670 return;
671
Chao Yu429511c2015-02-05 17:54:31 +0800672 if (available_free_memory(sbi, EXTENT_CACHE))
673 return;
674
675 spin_lock(&sbi->extent_lock);
676 list_for_each_entry_safe(en, tmp, &sbi->extent_list, list) {
677 if (!nr_shrink--)
678 break;
679 list_del_init(&en->list);
680 }
681 spin_unlock(&sbi->extent_lock);
682
683 down_read(&sbi->extent_tree_lock);
684 while ((found = radix_tree_gang_lookup(&sbi->extent_tree_root,
685 (void **)treevec, ino, EXT_TREE_VEC_SIZE))) {
686 unsigned i;
687
688 ino = treevec[found - 1]->ino + 1;
689 for (i = 0; i < found; i++) {
690 struct extent_tree *et = treevec[i];
691
692 atomic_inc(&et->refcount);
693 write_lock(&et->lock);
694 __free_extent_tree(sbi, et, false);
695 write_unlock(&et->lock);
696 atomic_dec(&et->refcount);
697 }
698 }
699 up_read(&sbi->extent_tree_lock);
700
701 down_write(&sbi->extent_tree_lock);
702 radix_tree_for_each_slot(slot, &sbi->extent_tree_root, &iter,
703 F2FS_ROOT_INO(sbi)) {
704 struct extent_tree *et = (struct extent_tree *)*slot;
705
706 if (!atomic_read(&et->refcount) && !et->count) {
707 radix_tree_delete(&sbi->extent_tree_root, et->ino);
708 kmem_cache_free(extent_tree_slab, et);
709 sbi->total_ext_tree--;
710 }
711 }
712 up_write(&sbi->extent_tree_lock);
713}
714
715void f2fs_destroy_extent_tree(struct inode *inode)
716{
717 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
718 struct extent_tree *et;
719
Chao Yu1dcc3362015-02-05 17:57:31 +0800720 if (!test_opt(sbi, EXTENT_CACHE))
721 return;
722
Chao Yu429511c2015-02-05 17:54:31 +0800723 down_read(&sbi->extent_tree_lock);
724 et = radix_tree_lookup(&sbi->extent_tree_root, inode->i_ino);
725 if (!et) {
726 up_read(&sbi->extent_tree_lock);
727 goto out;
728 }
729 atomic_inc(&et->refcount);
730 up_read(&sbi->extent_tree_lock);
731
732 /* free all extent info belong to this extent tree */
733 write_lock(&et->lock);
734 __free_extent_tree(sbi, et, true);
735 write_unlock(&et->lock);
736
737 atomic_dec(&et->refcount);
738
739 /* try to find and delete extent tree entry in radix tree */
740 down_write(&sbi->extent_tree_lock);
741 et = radix_tree_lookup(&sbi->extent_tree_root, inode->i_ino);
742 if (!et) {
743 up_write(&sbi->extent_tree_lock);
744 goto out;
745 }
746 f2fs_bug_on(sbi, atomic_read(&et->refcount) || et->count);
747 radix_tree_delete(&sbi->extent_tree_root, inode->i_ino);
748 kmem_cache_free(extent_tree_slab, et);
749 sbi->total_ext_tree--;
750 up_write(&sbi->extent_tree_lock);
751out:
752 return;
753}
754
Chao Yu7e4dde72015-02-05 17:51:34 +0800755static bool f2fs_lookup_extent_cache(struct inode *inode, pgoff_t pgofs,
756 struct extent_info *ei)
757{
Chao Yu1dcc3362015-02-05 17:57:31 +0800758 if (test_opt(F2FS_I_SB(inode), EXTENT_CACHE))
759 return f2fs_lookup_extent_tree(inode, pgofs, ei);
760
Chao Yu7e4dde72015-02-05 17:51:34 +0800761 return lookup_extent_info(inode, pgofs, ei);
762}
763
764void f2fs_update_extent_cache(struct dnode_of_data *dn)
765{
766 struct f2fs_inode_info *fi = F2FS_I(dn->inode);
767 pgoff_t fofs;
768
769 f2fs_bug_on(F2FS_I_SB(dn->inode), dn->data_blkaddr == NEW_ADDR);
770
771 /* Update the page address in the parent node */
772 __set_data_blkaddr(dn);
773
774 fofs = start_bidx_of_node(ofs_of_node(dn->node_page), fi) +
775 dn->ofs_in_node;
776
Chao Yu1dcc3362015-02-05 17:57:31 +0800777 if (test_opt(F2FS_I_SB(dn->inode), EXTENT_CACHE))
778 return f2fs_update_extent_tree(dn->inode, fofs,
779 dn->data_blkaddr);
780
Chao Yu7e4dde72015-02-05 17:51:34 +0800781 if (update_extent_info(dn->inode, fofs, dn->data_blkaddr))
Jaegeuk Kimc11abd12013-11-19 10:41:54 +0900782 sync_inode_page(dn);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900783}
784
Jaegeuk Kimc718379b2013-04-24 13:19:56 +0900785struct page *find_data_page(struct inode *inode, pgoff_t index, bool sync)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900786{
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900787 struct address_space *mapping = inode->i_mapping;
788 struct dnode_of_data dn;
789 struct page *page;
790 int err;
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800791 struct f2fs_io_info fio = {
792 .type = DATA,
793 .rw = sync ? READ_SYNC : READA,
794 };
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900795
796 page = find_get_page(mapping, index);
797 if (page && PageUptodate(page))
798 return page;
799 f2fs_put_page(page, 0);
800
801 set_new_dnode(&dn, inode, NULL, NULL, 0);
Jaegeuk Kim266e97a2013-02-26 13:10:46 +0900802 err = get_dnode_of_data(&dn, index, LOOKUP_NODE);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900803 if (err)
804 return ERR_PTR(err);
805 f2fs_put_dnode(&dn);
806
807 if (dn.data_blkaddr == NULL_ADDR)
808 return ERR_PTR(-ENOENT);
809
810 /* By fallocate(), there is no cached page, but with NEW_ADDR */
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900811 if (unlikely(dn.data_blkaddr == NEW_ADDR))
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900812 return ERR_PTR(-EINVAL);
813
Jaegeuk Kim9ac13492014-04-29 17:35:10 +0900814 page = grab_cache_page(mapping, index);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900815 if (!page)
816 return ERR_PTR(-ENOMEM);
817
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900818 if (PageUptodate(page)) {
819 unlock_page(page);
820 return page;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900821 }
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900822
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800823 fio.blk_addr = dn.data_blkaddr;
824 err = f2fs_submit_page_bio(F2FS_I_SB(inode), page, &fio);
Chao Yu1069bbf2013-11-28 15:43:43 +0800825 if (err)
826 return ERR_PTR(err);
827
Jaegeuk Kimc718379b2013-04-24 13:19:56 +0900828 if (sync) {
829 wait_on_page_locked(page);
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900830 if (unlikely(!PageUptodate(page))) {
Jaegeuk Kimc718379b2013-04-24 13:19:56 +0900831 f2fs_put_page(page, 0);
832 return ERR_PTR(-EIO);
833 }
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900834 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900835 return page;
836}
837
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900838/*
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900839 * If it tries to access a hole, return an error.
840 * Because, the callers, functions in dir.c and GC, should be able to know
841 * whether this page exists or not.
842 */
843struct page *get_lock_data_page(struct inode *inode, pgoff_t index)
844{
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900845 struct address_space *mapping = inode->i_mapping;
846 struct dnode_of_data dn;
847 struct page *page;
848 int err;
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800849 struct f2fs_io_info fio = {
850 .type = DATA,
851 .rw = READ_SYNC,
852 };
Jaegeuk Kimafcb7ca02013-04-26 11:55:17 +0900853repeat:
Jaegeuk Kim9ac13492014-04-29 17:35:10 +0900854 page = grab_cache_page(mapping, index);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900855 if (!page)
856 return ERR_PTR(-ENOMEM);
857
Jaegeuk Kim650495d2013-05-13 08:38:35 +0900858 set_new_dnode(&dn, inode, NULL, NULL, 0);
859 err = get_dnode_of_data(&dn, index, LOOKUP_NODE);
860 if (err) {
861 f2fs_put_page(page, 1);
862 return ERR_PTR(err);
863 }
864 f2fs_put_dnode(&dn);
865
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900866 if (unlikely(dn.data_blkaddr == NULL_ADDR)) {
Jaegeuk Kim650495d2013-05-13 08:38:35 +0900867 f2fs_put_page(page, 1);
868 return ERR_PTR(-ENOENT);
869 }
870
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900871 if (PageUptodate(page))
872 return page;
873
Jaegeuk Kimd59ff4d2013-08-20 19:13:07 +0900874 /*
875 * A new dentry page is allocated but not able to be written, since its
876 * new inode page couldn't be allocated due to -ENOSPC.
877 * In such the case, its blkaddr can be remained as NEW_ADDR.
878 * see, f2fs_add_link -> get_new_data_page -> init_inode_metadata.
879 */
880 if (dn.data_blkaddr == NEW_ADDR) {
881 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
882 SetPageUptodate(page);
883 return page;
884 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900885
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800886 fio.blk_addr = dn.data_blkaddr;
887 err = f2fs_submit_page_bio(F2FS_I_SB(inode), page, &fio);
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900888 if (err)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900889 return ERR_PTR(err);
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900890
891 lock_page(page);
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900892 if (unlikely(!PageUptodate(page))) {
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900893 f2fs_put_page(page, 1);
894 return ERR_PTR(-EIO);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900895 }
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900896 if (unlikely(page->mapping != mapping)) {
Jaegeuk Kimafcb7ca02013-04-26 11:55:17 +0900897 f2fs_put_page(page, 1);
898 goto repeat;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900899 }
900 return page;
901}
902
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900903/*
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900904 * Caller ensures that this data page is never allocated.
905 * A new zero-filled data page is allocated in the page cache.
Jaegeuk Kim39936832012-11-22 16:21:29 +0900906 *
Chao Yu4f4124d2013-12-21 18:02:14 +0800907 * Also, caller should grab and release a rwsem by calling f2fs_lock_op() and
908 * f2fs_unlock_op().
Jaegeuk Kima8865372013-12-27 17:04:17 +0900909 * Note that, ipage is set only by make_empty_dir.
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900910 */
Jaegeuk Kim64aa7ed2013-05-20 09:55:50 +0900911struct page *get_new_data_page(struct inode *inode,
Jaegeuk Kima8865372013-12-27 17:04:17 +0900912 struct page *ipage, pgoff_t index, bool new_i_size)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900913{
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900914 struct address_space *mapping = inode->i_mapping;
915 struct page *page;
916 struct dnode_of_data dn;
917 int err;
918
Jaegeuk Kima8865372013-12-27 17:04:17 +0900919 set_new_dnode(&dn, inode, ipage, NULL, 0);
Huajun Lib6009652013-11-10 23:13:18 +0800920 err = f2fs_reserve_block(&dn, index);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900921 if (err)
922 return ERR_PTR(err);
Jaegeuk Kimafcb7ca02013-04-26 11:55:17 +0900923repeat:
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900924 page = grab_cache_page(mapping, index);
Jaegeuk Kima8865372013-12-27 17:04:17 +0900925 if (!page) {
926 err = -ENOMEM;
927 goto put_err;
928 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900929
930 if (PageUptodate(page))
931 return page;
932
933 if (dn.data_blkaddr == NEW_ADDR) {
934 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900935 SetPageUptodate(page);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900936 } else {
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800937 struct f2fs_io_info fio = {
938 .type = DATA,
939 .rw = READ_SYNC,
940 .blk_addr = dn.data_blkaddr,
941 };
942 err = f2fs_submit_page_bio(F2FS_I_SB(inode), page, &fio);
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900943 if (err)
Jaegeuk Kima8865372013-12-27 17:04:17 +0900944 goto put_err;
945
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900946 lock_page(page);
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900947 if (unlikely(!PageUptodate(page))) {
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900948 f2fs_put_page(page, 1);
Jaegeuk Kima8865372013-12-27 17:04:17 +0900949 err = -EIO;
950 goto put_err;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900951 }
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900952 if (unlikely(page->mapping != mapping)) {
Jaegeuk Kimafcb7ca02013-04-26 11:55:17 +0900953 f2fs_put_page(page, 1);
954 goto repeat;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900955 }
956 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900957
958 if (new_i_size &&
959 i_size_read(inode) < ((index + 1) << PAGE_CACHE_SHIFT)) {
960 i_size_write(inode, ((index + 1) << PAGE_CACHE_SHIFT));
Jaegeuk Kim699489b2013-06-07 22:08:23 +0900961 /* Only the directory inode sets new_i_size */
962 set_inode_flag(F2FS_I(inode), FI_UPDATE_DIR);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900963 }
964 return page;
Jaegeuk Kima8865372013-12-27 17:04:17 +0900965
966put_err:
967 f2fs_put_dnode(&dn);
968 return ERR_PTR(err);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900969}
970
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900971static int __allocate_data_block(struct dnode_of_data *dn)
972{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700973 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
Jaegeuk Kim976e4c52014-09-15 19:32:16 -0700974 struct f2fs_inode_info *fi = F2FS_I(dn->inode);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900975 struct f2fs_summary sum;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900976 struct node_info ni;
Jaegeuk Kim38aa0882015-01-05 16:02:20 -0800977 int seg = CURSEG_WARM_DATA;
Jaegeuk Kim976e4c52014-09-15 19:32:16 -0700978 pgoff_t fofs;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900979
980 if (unlikely(is_inode_flag_set(F2FS_I(dn->inode), FI_NO_ALLOC)))
981 return -EPERM;
982 if (unlikely(!inc_valid_block_count(sbi, dn->inode, 1)))
983 return -ENOSPC;
984
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900985 get_node_info(sbi, dn->nid, &ni);
986 set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
987
Jaegeuk Kim38aa0882015-01-05 16:02:20 -0800988 if (dn->ofs_in_node == 0 && dn->inode_page == dn->node_page)
989 seg = CURSEG_DIRECT_IO;
990
991 allocate_data_block(sbi, NULL, NULL_ADDR, &dn->data_blkaddr, &sum, seg);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900992
993 /* direct IO doesn't use extent cache to maximize the performance */
Jaegeuk Kim41ef94b2014-12-30 23:12:11 -0800994 __set_data_blkaddr(dn);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900995
Jaegeuk Kim976e4c52014-09-15 19:32:16 -0700996 /* update i_size */
997 fofs = start_bidx_of_node(ofs_of_node(dn->node_page), fi) +
998 dn->ofs_in_node;
999 if (i_size_read(dn->inode) < ((fofs + 1) << PAGE_CACHE_SHIFT))
1000 i_size_write(dn->inode, ((fofs + 1) << PAGE_CACHE_SHIFT));
1001
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001002 return 0;
1003}
1004
Jaegeuk Kim59b802e2015-02-09 12:09:53 -08001005static void __allocate_data_blocks(struct inode *inode, loff_t offset,
1006 size_t count)
1007{
1008 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
1009 struct dnode_of_data dn;
1010 u64 start = F2FS_BYTES_TO_BLK(offset);
1011 u64 len = F2FS_BYTES_TO_BLK(count);
1012 bool allocated;
1013 u64 end_offset;
1014
1015 while (len) {
1016 f2fs_balance_fs(sbi);
1017 f2fs_lock_op(sbi);
1018
1019 /* When reading holes, we need its node page */
1020 set_new_dnode(&dn, inode, NULL, NULL, 0);
1021 if (get_dnode_of_data(&dn, start, ALLOC_NODE))
1022 goto out;
1023
1024 allocated = false;
1025 end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
1026
1027 while (dn.ofs_in_node < end_offset && len) {
1028 if (dn.data_blkaddr == NULL_ADDR) {
1029 if (__allocate_data_block(&dn))
1030 goto sync_out;
1031 allocated = true;
1032 }
1033 len--;
1034 start++;
1035 dn.ofs_in_node++;
1036 }
1037
1038 if (allocated)
1039 sync_inode_page(&dn);
1040
1041 f2fs_put_dnode(&dn);
1042 f2fs_unlock_op(sbi);
1043 }
1044 return;
1045
1046sync_out:
1047 if (allocated)
1048 sync_inode_page(&dn);
1049 f2fs_put_dnode(&dn);
1050out:
1051 f2fs_unlock_op(sbi);
1052 return;
1053}
1054
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +09001055/*
Chao Yu4f4124d2013-12-21 18:02:14 +08001056 * get_data_block() now supported readahead/bmap/rw direct_IO with mapped bh.
1057 * If original data blocks are allocated, then give them to blockdev.
1058 * Otherwise,
1059 * a. preallocate requested block addresses
1060 * b. do not use extent cache for better performance
1061 * c. give the block addresses to blockdev
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001062 */
Jaegeuk Kimccfb3002014-06-13 13:02:11 +09001063static int __get_data_block(struct inode *inode, sector_t iblock,
1064 struct buffer_head *bh_result, int create, bool fiemap)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001065{
1066 unsigned int blkbits = inode->i_sb->s_blocksize_bits;
1067 unsigned maxblocks = bh_result->b_size >> blkbits;
1068 struct dnode_of_data dn;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001069 int mode = create ? ALLOC_NODE : LOOKUP_NODE_RA;
1070 pgoff_t pgofs, end_offset;
1071 int err = 0, ofs = 1;
Chao Yua2e7d1b2015-02-05 17:50:30 +08001072 struct extent_info ei;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001073 bool allocated = false;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001074
1075 /* Get the page offset from the block offset(iblock) */
1076 pgofs = (pgoff_t)(iblock >> (PAGE_CACHE_SHIFT - blkbits));
1077
Chao Yu7e4dde72015-02-05 17:51:34 +08001078 if (f2fs_lookup_extent_cache(inode, pgofs, &ei)) {
Chao Yua2e7d1b2015-02-05 17:50:30 +08001079 f2fs_map_bh(inode->i_sb, pgofs, &ei, bh_result);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001080 goto out;
Chao Yua2e7d1b2015-02-05 17:50:30 +08001081 }
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001082
Jaegeuk Kim59b802e2015-02-09 12:09:53 -08001083 if (create)
Jaegeuk Kim40813632014-09-02 15:31:18 -07001084 f2fs_lock_op(F2FS_I_SB(inode));
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001085
1086 /* When reading holes, we need its node page */
1087 set_new_dnode(&dn, inode, NULL, NULL, 0);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001088 err = get_dnode_of_data(&dn, pgofs, mode);
Jaegeuk Kim1ec79082013-12-26 16:55:22 +09001089 if (err) {
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001090 if (err == -ENOENT)
1091 err = 0;
1092 goto unlock_out;
Namjae Jeon848753a2013-04-23 16:38:02 +09001093 }
Jaegeuk Kimccfb3002014-06-13 13:02:11 +09001094 if (dn.data_blkaddr == NEW_ADDR && !fiemap)
Jaegeuk Kim1ec79082013-12-26 16:55:22 +09001095 goto put_out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001096
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001097 if (dn.data_blkaddr != NULL_ADDR) {
Jaegeuk Kimda17eec2015-02-09 10:34:38 -08001098 set_buffer_new(bh_result);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001099 map_bh(bh_result, inode->i_sb, dn.data_blkaddr);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001100 } else if (create) {
1101 err = __allocate_data_block(&dn);
1102 if (err)
1103 goto put_out;
1104 allocated = true;
Jaegeuk Kimda17eec2015-02-09 10:34:38 -08001105 set_buffer_new(bh_result);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001106 map_bh(bh_result, inode->i_sb, dn.data_blkaddr);
1107 } else {
1108 goto put_out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001109 }
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001110
Chao Yu6403eb12014-04-26 19:59:52 +08001111 end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001112 bh_result->b_size = (((size_t)1) << blkbits);
1113 dn.ofs_in_node++;
1114 pgofs++;
1115
1116get_next:
1117 if (dn.ofs_in_node >= end_offset) {
1118 if (allocated)
1119 sync_inode_page(&dn);
1120 allocated = false;
1121 f2fs_put_dnode(&dn);
1122
1123 set_new_dnode(&dn, inode, NULL, NULL, 0);
1124 err = get_dnode_of_data(&dn, pgofs, mode);
Jaegeuk Kim1ec79082013-12-26 16:55:22 +09001125 if (err) {
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001126 if (err == -ENOENT)
1127 err = 0;
1128 goto unlock_out;
1129 }
Jaegeuk Kimccfb3002014-06-13 13:02:11 +09001130 if (dn.data_blkaddr == NEW_ADDR && !fiemap)
Jaegeuk Kim1ec79082013-12-26 16:55:22 +09001131 goto put_out;
1132
Chao Yu6403eb12014-04-26 19:59:52 +08001133 end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001134 }
1135
1136 if (maxblocks > (bh_result->b_size >> blkbits)) {
1137 block_t blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node);
1138 if (blkaddr == NULL_ADDR && create) {
1139 err = __allocate_data_block(&dn);
1140 if (err)
1141 goto sync_out;
1142 allocated = true;
1143 blkaddr = dn.data_blkaddr;
1144 }
arter97e1c42042014-08-06 23:22:50 +09001145 /* Give more consecutive addresses for the readahead */
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001146 if (blkaddr == (bh_result->b_blocknr + ofs)) {
1147 ofs++;
1148 dn.ofs_in_node++;
1149 pgofs++;
1150 bh_result->b_size += (((size_t)1) << blkbits);
1151 goto get_next;
1152 }
1153 }
1154sync_out:
1155 if (allocated)
1156 sync_inode_page(&dn);
1157put_out:
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001158 f2fs_put_dnode(&dn);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001159unlock_out:
1160 if (create)
Jaegeuk Kim40813632014-09-02 15:31:18 -07001161 f2fs_unlock_op(F2FS_I_SB(inode));
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001162out:
1163 trace_f2fs_get_data_block(inode, iblock, bh_result, err);
1164 return err;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001165}
1166
Jaegeuk Kimccfb3002014-06-13 13:02:11 +09001167static int get_data_block(struct inode *inode, sector_t iblock,
1168 struct buffer_head *bh_result, int create)
1169{
1170 return __get_data_block(inode, iblock, bh_result, create, false);
1171}
1172
1173static int get_data_block_fiemap(struct inode *inode, sector_t iblock,
1174 struct buffer_head *bh_result, int create)
1175{
1176 return __get_data_block(inode, iblock, bh_result, create, true);
1177}
1178
Jaegeuk Kim9ab70132014-06-08 04:30:14 +09001179int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
1180 u64 start, u64 len)
1181{
Jaegeuk Kimccfb3002014-06-13 13:02:11 +09001182 return generic_block_fiemap(inode, fieinfo,
1183 start, len, get_data_block_fiemap);
Jaegeuk Kim9ab70132014-06-08 04:30:14 +09001184}
1185
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001186static int f2fs_read_data_page(struct file *file, struct page *page)
1187{
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001188 struct inode *inode = page->mapping->host;
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001189 int ret = -EAGAIN;
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001190
Chao Yuc20e89c2014-05-06 16:53:08 +08001191 trace_f2fs_readpage(page, DATA);
1192
arter97e1c42042014-08-06 23:22:50 +09001193 /* If the file has inline data, try to read it directly */
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001194 if (f2fs_has_inline_data(inode))
1195 ret = f2fs_read_inline_data(inode, page);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001196 if (ret == -EAGAIN)
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001197 ret = mpage_readpage(page, get_data_block);
1198
1199 return ret;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001200}
1201
1202static int f2fs_read_data_pages(struct file *file,
1203 struct address_space *mapping,
1204 struct list_head *pages, unsigned nr_pages)
1205{
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001206 struct inode *inode = file->f_mapping->host;
1207
1208 /* If the file has inline data, skip readpages */
1209 if (f2fs_has_inline_data(inode))
1210 return 0;
1211
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001212 return mpage_readpages(mapping, pages, nr_pages, get_data_block);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001213}
1214
Jaegeuk Kim458e6192013-12-11 13:54:01 +09001215int do_write_data_page(struct page *page, struct f2fs_io_info *fio)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001216{
1217 struct inode *inode = page->mapping->host;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001218 struct dnode_of_data dn;
1219 int err = 0;
1220
1221 set_new_dnode(&dn, inode, NULL, NULL, 0);
Jaegeuk Kim266e97a2013-02-26 13:10:46 +09001222 err = get_dnode_of_data(&dn, page->index, LOOKUP_NODE);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001223 if (err)
1224 return err;
1225
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001226 fio->blk_addr = dn.data_blkaddr;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001227
1228 /* This page is already truncated */
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001229 if (fio->blk_addr == NULL_ADDR)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001230 goto out_writepage;
1231
1232 set_page_writeback(page);
1233
1234 /*
1235 * If current allocation needs SSR,
1236 * it had better in-place writes for updated data.
1237 */
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001238 if (unlikely(fio->blk_addr != NEW_ADDR &&
Haicheng Lib25958b2013-06-13 16:59:29 +08001239 !is_cold_data(page) &&
1240 need_inplace_update(inode))) {
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001241 rewrite_data_page(page, fio);
Jaegeuk Kimfff04f92014-07-25 07:40:59 -07001242 set_inode_flag(F2FS_I(inode), FI_UPDATE_WRITE);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001243 } else {
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001244 write_data_page(page, &dn, fio);
Chao Yu7e4dde72015-02-05 17:51:34 +08001245 f2fs_update_extent_cache(&dn);
Jaegeuk Kimfff04f92014-07-25 07:40:59 -07001246 set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001247 }
1248out_writepage:
1249 f2fs_put_dnode(&dn);
1250 return err;
1251}
1252
1253static int f2fs_write_data_page(struct page *page,
1254 struct writeback_control *wbc)
1255{
1256 struct inode *inode = page->mapping->host;
Jaegeuk Kim40813632014-09-02 15:31:18 -07001257 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001258 loff_t i_size = i_size_read(inode);
1259 const pgoff_t end_index = ((unsigned long long) i_size)
1260 >> PAGE_CACHE_SHIFT;
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001261 unsigned offset = 0;
Jaegeuk Kim39936832012-11-22 16:21:29 +09001262 bool need_balance_fs = false;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001263 int err = 0;
Jaegeuk Kim458e6192013-12-11 13:54:01 +09001264 struct f2fs_io_info fio = {
1265 .type = DATA,
Chris Fries6c311ec2014-01-17 14:44:39 -06001266 .rw = (wbc->sync_mode == WB_SYNC_ALL) ? WRITE_SYNC : WRITE,
Jaegeuk Kim458e6192013-12-11 13:54:01 +09001267 };
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001268
Chao Yuecda0de2014-05-06 16:48:26 +08001269 trace_f2fs_writepage(page, DATA);
1270
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001271 if (page->index < end_index)
Jaegeuk Kim39936832012-11-22 16:21:29 +09001272 goto write;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001273
1274 /*
1275 * If the offset is out-of-range of file size,
1276 * this page does not have to be written to disk.
1277 */
1278 offset = i_size & (PAGE_CACHE_SIZE - 1);
Jaegeuk Kim76f60262014-04-15 16:04:15 +09001279 if ((page->index >= end_index + 1) || !offset)
Jaegeuk Kim39936832012-11-22 16:21:29 +09001280 goto out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001281
1282 zero_user_segment(page, offset, PAGE_CACHE_SIZE);
Jaegeuk Kim39936832012-11-22 16:21:29 +09001283write:
Chao Yucaf00472015-01-28 17:48:42 +08001284 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001285 goto redirty_out;
Jaegeuk Kim1e843712014-12-09 06:08:59 -08001286 if (f2fs_is_drop_cache(inode))
1287 goto out;
1288 if (f2fs_is_volatile_file(inode) && !wbc->for_reclaim &&
1289 available_free_memory(sbi, BASE_CHECK))
1290 goto redirty_out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001291
Jaegeuk Kim39936832012-11-22 16:21:29 +09001292 /* Dentry blocks are controlled by checkpoint */
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001293 if (S_ISDIR(inode->i_mode)) {
Jaegeuk Kimcf779ca2014-08-11 18:37:46 -07001294 if (unlikely(f2fs_cp_error(sbi)))
1295 goto redirty_out;
Jaegeuk Kim458e6192013-12-11 13:54:01 +09001296 err = do_write_data_page(page, &fio);
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001297 goto done;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001298 }
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001299
Jaegeuk Kimcf779ca2014-08-11 18:37:46 -07001300 /* we should bypass data pages to proceed the kworkder jobs */
1301 if (unlikely(f2fs_cp_error(sbi))) {
1302 SetPageError(page);
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001303 goto out;
Jaegeuk Kimcf779ca2014-08-11 18:37:46 -07001304 }
1305
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001306 if (!wbc->for_reclaim)
1307 need_balance_fs = true;
1308 else if (has_not_enough_free_secs(sbi, 0))
Jaegeuk Kim39936832012-11-22 16:21:29 +09001309 goto redirty_out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001310
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001311 err = -EAGAIN;
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001312 f2fs_lock_op(sbi);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001313 if (f2fs_has_inline_data(inode))
1314 err = f2fs_write_inline_data(inode, page);
1315 if (err == -EAGAIN)
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001316 err = do_write_data_page(page, &fio);
1317 f2fs_unlock_op(sbi);
1318done:
1319 if (err && err != -ENOENT)
1320 goto redirty_out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001321
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001322 clear_cold_data(page);
Jaegeuk Kim39936832012-11-22 16:21:29 +09001323out:
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001324 inode_dec_dirty_pages(inode);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001325 unlock_page(page);
Jaegeuk Kim39936832012-11-22 16:21:29 +09001326 if (need_balance_fs)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001327 f2fs_balance_fs(sbi);
Jaegeuk Kim2aea39e2014-04-24 09:49:52 +09001328 if (wbc->for_reclaim)
1329 f2fs_submit_merged_bio(sbi, DATA, WRITE);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001330 return 0;
1331
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001332redirty_out:
Jaegeuk Kim76f60262014-04-15 16:04:15 +09001333 redirty_page_for_writepage(wbc, page);
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001334 return AOP_WRITEPAGE_ACTIVATE;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001335}
1336
Namjae Jeonfa9150a2013-01-15 16:45:24 +09001337static int __f2fs_writepage(struct page *page, struct writeback_control *wbc,
1338 void *data)
1339{
1340 struct address_space *mapping = data;
1341 int ret = mapping->a_ops->writepage(page, wbc);
1342 mapping_set_error(mapping, ret);
1343 return ret;
1344}
1345
Jaegeuk Kim25ca9232012-11-28 16:12:41 +09001346static int f2fs_write_data_pages(struct address_space *mapping,
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001347 struct writeback_control *wbc)
1348{
1349 struct inode *inode = mapping->host;
Jaegeuk Kim40813632014-09-02 15:31:18 -07001350 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +09001351 bool locked = false;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001352 int ret;
Jaegeuk Kim50c8cdb2014-03-18 13:47:11 +09001353 long diff;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001354
Chao Yue5748432014-05-06 16:51:24 +08001355 trace_f2fs_writepages(mapping->host, wbc, DATA);
1356
P J Pcfb185a2013-04-03 11:38:00 +09001357 /* deal with chardevs and other special file */
1358 if (!mapping->a_ops->writepage)
1359 return 0;
1360
Jaegeuk Kim87d6f892014-03-18 12:40:49 +09001361 if (S_ISDIR(inode->i_mode) && wbc->sync_mode == WB_SYNC_NONE &&
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001362 get_dirty_pages(inode) < nr_pages_to_skip(sbi, DATA) &&
Jaegeuk Kim6fb03f32014-04-16 10:47:06 +09001363 available_free_memory(sbi, DIRTY_DENTS))
Jaegeuk Kimd3baf952014-03-18 13:43:05 +09001364 goto skip_write;
Jaegeuk Kim87d6f892014-03-18 12:40:49 +09001365
Jaegeuk Kim50c8cdb2014-03-18 13:47:11 +09001366 diff = nr_pages_to_write(sbi, DATA, wbc);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001367
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +09001368 if (!S_ISDIR(inode->i_mode)) {
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001369 mutex_lock(&sbi->writepages);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +09001370 locked = true;
1371 }
Namjae Jeonfa9150a2013-01-15 16:45:24 +09001372 ret = write_cache_pages(mapping, wbc, __f2fs_writepage, mapping);
Jaegeuk Kim531ad7d2013-04-30 11:33:27 +09001373 if (locked)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001374 mutex_unlock(&sbi->writepages);
Jaegeuk Kim458e6192013-12-11 13:54:01 +09001375
1376 f2fs_submit_merged_bio(sbi, DATA, WRITE);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001377
1378 remove_dirty_dir_inode(inode);
1379
Jaegeuk Kim50c8cdb2014-03-18 13:47:11 +09001380 wbc->nr_to_write = max((long)0, wbc->nr_to_write - diff);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001381 return ret;
Jaegeuk Kimd3baf952014-03-18 13:43:05 +09001382
1383skip_write:
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001384 wbc->pages_skipped += get_dirty_pages(inode);
Jaegeuk Kimd3baf952014-03-18 13:43:05 +09001385 return 0;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001386}
1387
Chao Yu3aab8f82014-07-02 13:25:04 +08001388static void f2fs_write_failed(struct address_space *mapping, loff_t to)
1389{
1390 struct inode *inode = mapping->host;
1391
1392 if (to > inode->i_size) {
1393 truncate_pagecache(inode, inode->i_size);
Jaegeuk Kim764aa3e2014-08-14 16:32:54 -07001394 truncate_blocks(inode, inode->i_size, true);
Chao Yu3aab8f82014-07-02 13:25:04 +08001395 }
1396}
1397
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001398static int f2fs_write_begin(struct file *file, struct address_space *mapping,
1399 loff_t pos, unsigned len, unsigned flags,
1400 struct page **pagep, void **fsdata)
1401{
1402 struct inode *inode = mapping->host;
Jaegeuk Kim40813632014-09-02 15:31:18 -07001403 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001404 struct page *page, *ipage;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001405 pgoff_t index = ((unsigned long long) pos) >> PAGE_CACHE_SHIFT;
1406 struct dnode_of_data dn;
1407 int err = 0;
1408
Chao Yu62aed042014-05-06 16:46:04 +08001409 trace_f2fs_write_begin(inode, pos, len, flags);
1410
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001411 f2fs_balance_fs(sbi);
Jaegeuk Kim5f727392014-11-25 10:59:45 -08001412
1413 /*
1414 * We should check this at this moment to avoid deadlock on inode page
1415 * and #0 page. The locking rule for inline_data conversion should be:
1416 * lock_page(page #0) -> lock_page(inode_page)
1417 */
1418 if (index != 0) {
1419 err = f2fs_convert_inline_inode(inode);
1420 if (err)
1421 goto fail;
1422 }
Jaegeuk Kimafcb7ca02013-04-26 11:55:17 +09001423repeat:
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001424 page = grab_cache_page_write_begin(mapping, index, flags);
Chao Yu3aab8f82014-07-02 13:25:04 +08001425 if (!page) {
1426 err = -ENOMEM;
1427 goto fail;
1428 }
Jaegeuk Kimd5f66992014-04-30 09:22:45 +09001429
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001430 *pagep = page;
1431
Gu Zhenge4795562013-09-27 18:08:30 +08001432 f2fs_lock_op(sbi);
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001433
1434 /* check inline_data */
1435 ipage = get_node_page(sbi, inode->i_ino);
Chao Yucd34e292014-12-01 11:30:20 +08001436 if (IS_ERR(ipage)) {
1437 err = PTR_ERR(ipage);
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001438 goto unlock_fail;
Chao Yucd34e292014-12-01 11:30:20 +08001439 }
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001440
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001441 set_new_dnode(&dn, inode, ipage, ipage, 0);
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001442
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001443 if (f2fs_has_inline_data(inode)) {
1444 if (pos + len <= MAX_INLINE_DATA) {
1445 read_inline_data(page, ipage);
1446 set_inode_flag(F2FS_I(inode), FI_DATA_EXIST);
1447 sync_inode_page(&dn);
1448 goto put_next;
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001449 }
Jaegeuk Kim5f727392014-11-25 10:59:45 -08001450 err = f2fs_convert_inline_page(&dn, page);
1451 if (err)
1452 goto put_fail;
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001453 }
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001454 err = f2fs_reserve_block(&dn, index);
1455 if (err)
Jaegeuk Kim8cdcb712014-11-17 16:14:11 -08001456 goto put_fail;
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001457put_next:
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001458 f2fs_put_dnode(&dn);
1459 f2fs_unlock_op(sbi);
1460
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001461 if ((len == PAGE_CACHE_SIZE) || PageUptodate(page))
1462 return 0;
1463
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001464 f2fs_wait_on_page_writeback(page, DATA);
1465
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001466 if ((pos & PAGE_CACHE_MASK) >= i_size_read(inode)) {
1467 unsigned start = pos & (PAGE_CACHE_SIZE - 1);
1468 unsigned end = start + len;
1469
1470 /* Reading beyond i_size is simple: memset to zero */
1471 zero_user_segments(page, 0, start, end, PAGE_CACHE_SIZE);
Jaegeuk Kim393ff912013-03-08 21:29:23 +09001472 goto out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001473 }
1474
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001475 if (dn.data_blkaddr == NEW_ADDR) {
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001476 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
1477 } else {
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001478 struct f2fs_io_info fio = {
1479 .type = DATA,
1480 .rw = READ_SYNC,
1481 .blk_addr = dn.data_blkaddr,
1482 };
1483 err = f2fs_submit_page_bio(sbi, page, &fio);
Jan Kara9234f312014-10-22 15:21:47 +02001484 if (err)
1485 goto fail;
Chao Yud54c7952014-03-29 15:30:40 +08001486
Jaegeuk Kim393ff912013-03-08 21:29:23 +09001487 lock_page(page);
Jaegeuk Kim6bacf522013-12-06 15:00:58 +09001488 if (unlikely(!PageUptodate(page))) {
Jaegeuk Kim393ff912013-03-08 21:29:23 +09001489 f2fs_put_page(page, 1);
Chao Yu3aab8f82014-07-02 13:25:04 +08001490 err = -EIO;
1491 goto fail;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001492 }
Jaegeuk Kim6bacf522013-12-06 15:00:58 +09001493 if (unlikely(page->mapping != mapping)) {
Jaegeuk Kimafcb7ca02013-04-26 11:55:17 +09001494 f2fs_put_page(page, 1);
1495 goto repeat;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001496 }
1497 }
Jaegeuk Kim393ff912013-03-08 21:29:23 +09001498out:
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001499 SetPageUptodate(page);
1500 clear_cold_data(page);
1501 return 0;
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001502
Jaegeuk Kim8cdcb712014-11-17 16:14:11 -08001503put_fail:
1504 f2fs_put_dnode(&dn);
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001505unlock_fail:
1506 f2fs_unlock_op(sbi);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001507 f2fs_put_page(page, 1);
Chao Yu3aab8f82014-07-02 13:25:04 +08001508fail:
1509 f2fs_write_failed(mapping, pos + len);
1510 return err;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001511}
1512
Jaegeuk Kima1dd3c12013-06-27 13:04:08 +09001513static int f2fs_write_end(struct file *file,
1514 struct address_space *mapping,
1515 loff_t pos, unsigned len, unsigned copied,
1516 struct page *page, void *fsdata)
1517{
1518 struct inode *inode = page->mapping->host;
1519
Chao Yudfb2bf32014-05-06 16:47:23 +08001520 trace_f2fs_write_end(inode, pos, len, copied);
1521
Jaegeuk Kim34ba94b2014-10-09 13:19:53 -07001522 set_page_dirty(page);
Jaegeuk Kima1dd3c12013-06-27 13:04:08 +09001523
1524 if (pos + copied > i_size_read(inode)) {
1525 i_size_write(inode, pos + copied);
1526 mark_inode_dirty(inode);
1527 update_inode_page(inode);
1528 }
1529
Chao Yu75c3c8b2013-11-16 14:15:59 +08001530 f2fs_put_page(page, 1);
Jaegeuk Kima1dd3c12013-06-27 13:04:08 +09001531 return copied;
1532}
1533
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001534static int check_direct_IO(struct inode *inode, int rw,
Al Viro5b46f252014-03-16 18:07:34 -04001535 struct iov_iter *iter, loff_t offset)
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001536{
1537 unsigned blocksize_mask = inode->i_sb->s_blocksize - 1;
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001538
1539 if (rw == READ)
1540 return 0;
1541
1542 if (offset & blocksize_mask)
1543 return -EINVAL;
1544
Al Viro5b46f252014-03-16 18:07:34 -04001545 if (iov_iter_alignment(iter) & blocksize_mask)
1546 return -EINVAL;
1547
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001548 return 0;
1549}
1550
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001551static ssize_t f2fs_direct_IO(int rw, struct kiocb *iocb,
Al Virod8d3d942014-03-04 21:27:34 -05001552 struct iov_iter *iter, loff_t offset)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001553{
1554 struct file *file = iocb->ki_filp;
Chao Yu3aab8f82014-07-02 13:25:04 +08001555 struct address_space *mapping = file->f_mapping;
1556 struct inode *inode = mapping->host;
1557 size_t count = iov_iter_count(iter);
1558 int err;
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001559
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001560 /* we don't need to use inline_data strictly */
1561 if (f2fs_has_inline_data(inode)) {
1562 err = f2fs_convert_inline_inode(inode);
1563 if (err)
1564 return err;
1565 }
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001566
Al Viro5b46f252014-03-16 18:07:34 -04001567 if (check_direct_IO(inode, rw, iter, offset))
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001568 return 0;
1569
Chao Yu70407fad2014-07-31 21:11:22 +08001570 trace_f2fs_direct_IO_enter(inode, offset, count, rw);
1571
Jaegeuk Kim59b802e2015-02-09 12:09:53 -08001572 if (rw & WRITE)
1573 __allocate_data_blocks(inode, offset, count);
1574
Chao Yu3aab8f82014-07-02 13:25:04 +08001575 err = blockdev_direct_IO(rw, iocb, inode, iter, offset, get_data_block);
1576 if (err < 0 && (rw & WRITE))
1577 f2fs_write_failed(mapping, offset + count);
Chao Yu70407fad2014-07-31 21:11:22 +08001578
1579 trace_f2fs_direct_IO_exit(inode, offset, count, rw, err);
1580
Chao Yu3aab8f82014-07-02 13:25:04 +08001581 return err;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001582}
1583
Chao Yu487261f2015-02-05 17:44:29 +08001584void f2fs_invalidate_page(struct page *page, unsigned int offset,
1585 unsigned int length)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001586{
1587 struct inode *inode = page->mapping->host;
Chao Yu487261f2015-02-05 17:44:29 +08001588 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001589
Chao Yu487261f2015-02-05 17:44:29 +08001590 if (inode->i_ino >= F2FS_ROOT_INO(sbi) &&
1591 (offset % PAGE_CACHE_SIZE || length != PAGE_CACHE_SIZE))
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001592 return;
1593
Chao Yu487261f2015-02-05 17:44:29 +08001594 if (PageDirty(page)) {
1595 if (inode->i_ino == F2FS_META_INO(sbi))
1596 dec_page_count(sbi, F2FS_DIRTY_META);
1597 else if (inode->i_ino == F2FS_NODE_INO(sbi))
1598 dec_page_count(sbi, F2FS_DIRTY_NODES);
1599 else
1600 inode_dec_dirty_pages(inode);
1601 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001602 ClearPagePrivate(page);
1603}
1604
Chao Yu487261f2015-02-05 17:44:29 +08001605int f2fs_release_page(struct page *page, gfp_t wait)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001606{
Jaegeuk Kimf68daee2015-01-30 11:39:08 -08001607 /* If this is dirty page, keep PagePrivate */
1608 if (PageDirty(page))
1609 return 0;
1610
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001611 ClearPagePrivate(page);
Jaegeuk Kimc3850aa2013-03-14 09:24:32 +09001612 return 1;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001613}
1614
1615static int f2fs_set_data_page_dirty(struct page *page)
1616{
1617 struct address_space *mapping = page->mapping;
1618 struct inode *inode = mapping->host;
1619
Jaegeuk Kim26c6b882013-10-24 17:53:29 +09001620 trace_f2fs_set_page_dirty(page, DATA);
1621
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001622 SetPageUptodate(page);
Jaegeuk Kim34ba94b2014-10-09 13:19:53 -07001623
Jaegeuk Kim1e843712014-12-09 06:08:59 -08001624 if (f2fs_is_atomic_file(inode)) {
Jaegeuk Kim34ba94b2014-10-09 13:19:53 -07001625 register_inmem_page(inode, page);
1626 return 1;
1627 }
1628
Jaegeuk Kima18ff062014-01-21 13:32:12 +09001629 mark_inode_dirty(inode);
1630
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001631 if (!PageDirty(page)) {
1632 __set_page_dirty_nobuffers(page);
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001633 update_dirty_page(inode, page);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001634 return 1;
1635 }
1636 return 0;
1637}
1638
Jaegeuk Kimc01e54b2013-01-17 20:30:23 +09001639static sector_t f2fs_bmap(struct address_space *mapping, sector_t block)
1640{
Chao Yu454ae7e2014-04-22 13:34:01 +08001641 struct inode *inode = mapping->host;
1642
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001643 /* we don't need to use inline_data strictly */
1644 if (f2fs_has_inline_data(inode)) {
1645 int err = f2fs_convert_inline_inode(inode);
1646 if (err)
1647 return err;
1648 }
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +09001649 return generic_block_bmap(mapping, block, get_data_block);
Jaegeuk Kimc01e54b2013-01-17 20:30:23 +09001650}
1651
Chao Yu429511c2015-02-05 17:54:31 +08001652void init_extent_cache_info(struct f2fs_sb_info *sbi)
1653{
1654 INIT_RADIX_TREE(&sbi->extent_tree_root, GFP_NOIO);
1655 init_rwsem(&sbi->extent_tree_lock);
1656 INIT_LIST_HEAD(&sbi->extent_list);
1657 spin_lock_init(&sbi->extent_lock);
1658 sbi->total_ext_tree = 0;
1659 atomic_set(&sbi->total_ext_node, 0);
1660}
1661
1662int __init create_extent_cache(void)
1663{
1664 extent_tree_slab = f2fs_kmem_cache_create("f2fs_extent_tree",
1665 sizeof(struct extent_tree));
1666 if (!extent_tree_slab)
1667 return -ENOMEM;
1668 extent_node_slab = f2fs_kmem_cache_create("f2fs_extent_node",
1669 sizeof(struct extent_node));
1670 if (!extent_node_slab) {
1671 kmem_cache_destroy(extent_tree_slab);
1672 return -ENOMEM;
1673 }
1674 return 0;
1675}
1676
1677void destroy_extent_cache(void)
1678{
1679 kmem_cache_destroy(extent_node_slab);
1680 kmem_cache_destroy(extent_tree_slab);
1681}
1682
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001683const struct address_space_operations f2fs_dblock_aops = {
1684 .readpage = f2fs_read_data_page,
1685 .readpages = f2fs_read_data_pages,
1686 .writepage = f2fs_write_data_page,
1687 .writepages = f2fs_write_data_pages,
1688 .write_begin = f2fs_write_begin,
Jaegeuk Kima1dd3c12013-06-27 13:04:08 +09001689 .write_end = f2fs_write_end,
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001690 .set_page_dirty = f2fs_set_data_page_dirty,
Chao Yu487261f2015-02-05 17:44:29 +08001691 .invalidatepage = f2fs_invalidate_page,
1692 .releasepage = f2fs_release_page,
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001693 .direct_IO = f2fs_direct_IO,
Jaegeuk Kimc01e54b2013-01-17 20:30:23 +09001694 .bmap = f2fs_bmap,
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001695};