blob: a82abe921b895c7c6811f5ad9fa1a421e17b6cfd [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>
15#include <linux/writeback.h>
16#include <linux/backing-dev.h>
Chao Yu8f46dca2015-07-14 18:56:10 +080017#include <linux/pagevec.h>
Jaegeuk Kimeb47b802012-11-02 17:10:12 +090018#include <linux/blkdev.h>
19#include <linux/bio.h>
Geert Uytterhoeven690e4a32012-12-19 22:19:30 +010020#include <linux/prefetch.h>
Christoph Hellwige2e40f22015-02-22 08:58:50 -080021#include <linux/uio.h>
Jaegeuk Kimf1e88662015-04-09 11:20:42 -070022#include <linux/cleancache.h>
Jaegeuk Kimeb47b802012-11-02 17:10:12 +090023
24#include "f2fs.h"
25#include "node.h"
26#include "segment.h"
Jaegeuk Kimdb9f7c12014-12-17 20:04:08 -080027#include "trace.h"
Namjae Jeon848753a2013-04-23 16:38:02 +090028#include <trace/events/f2fs.h>
Jaegeuk Kimeb47b802012-11-02 17:10:12 +090029
Christoph Hellwig4246a0b2015-07-20 15:29:37 +020030static void f2fs_read_end_io(struct bio *bio)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090031{
Linus Torvaldsf5688492014-01-30 11:19:05 -080032 struct bio_vec *bvec;
33 int i;
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090034
Chao Yu12377022015-05-25 18:03:38 +080035 if (f2fs_bio_encrypted(bio)) {
Christoph Hellwig4246a0b2015-07-20 15:29:37 +020036 if (bio->bi_error) {
Chao Yu12377022015-05-25 18:03:38 +080037 f2fs_release_crypto_ctx(bio->bi_private);
38 } else {
39 f2fs_end_io_crypto_work(bio->bi_private, bio);
40 return;
41 }
42 }
43
Linus Torvaldsf5688492014-01-30 11:19:05 -080044 bio_for_each_segment_all(bvec, bio, i) {
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090045 struct page *page = bvec->bv_page;
46
Christoph Hellwig4246a0b2015-07-20 15:29:37 +020047 if (!bio->bi_error) {
Linus Torvaldsf5688492014-01-30 11:19:05 -080048 SetPageUptodate(page);
49 } else {
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090050 ClearPageUptodate(page);
51 SetPageError(page);
52 }
53 unlock_page(page);
Linus Torvaldsf5688492014-01-30 11:19:05 -080054 }
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090055 bio_put(bio);
56}
57
Christoph Hellwig4246a0b2015-07-20 15:29:37 +020058static void f2fs_write_end_io(struct bio *bio)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090059{
Jaegeuk Kim1b1f5592014-02-03 10:50:22 +090060 struct f2fs_sb_info *sbi = bio->bi_private;
Linus Torvaldsf5688492014-01-30 11:19:05 -080061 struct bio_vec *bvec;
62 int i;
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090063
Linus Torvaldsf5688492014-01-30 11:19:05 -080064 bio_for_each_segment_all(bvec, bio, i) {
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090065 struct page *page = bvec->bv_page;
66
Jaegeuk Kim4375a332015-04-23 12:04:33 -070067 f2fs_restore_and_release_control_page(&page);
68
Christoph Hellwig4246a0b2015-07-20 15:29:37 +020069 if (unlikely(bio->bi_error)) {
Jaegeuk Kimcf779ca2014-08-11 18:37:46 -070070 set_page_dirty(page);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090071 set_bit(AS_EIO, &page->mapping->flags);
Jaegeuk Kim744602c2014-01-24 09:42:16 +090072 f2fs_stop_checkpoint(sbi);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090073 }
74 end_page_writeback(page);
75 dec_page_count(sbi, F2FS_WRITEBACK);
Linus Torvaldsf5688492014-01-30 11:19:05 -080076 }
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090077
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +090078 if (!get_pages(sbi, F2FS_WRITEBACK) &&
79 !list_empty(&sbi->cp_wait.task_list))
80 wake_up(&sbi->cp_wait);
81
82 bio_put(bio);
83}
84
Gu Zheng940a6d32013-12-20 17:39:59 +080085/*
86 * Low-level block read/write IO operations.
87 */
88static struct bio *__bio_alloc(struct f2fs_sb_info *sbi, block_t blk_addr,
89 int npages, bool is_read)
90{
91 struct bio *bio;
92
Jaegeuk Kim740432f2015-08-14 11:43:56 -070093 bio = f2fs_bio_alloc(npages);
Gu Zheng940a6d32013-12-20 17:39:59 +080094
95 bio->bi_bdev = sbi->sb->s_bdev;
Chao Yu55cf9cb2014-09-15 18:01:10 +080096 bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blk_addr);
Gu Zheng940a6d32013-12-20 17:39:59 +080097 bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io;
Chao Yu12377022015-05-25 18:03:38 +080098 bio->bi_private = is_read ? NULL : sbi;
Gu Zheng940a6d32013-12-20 17:39:59 +080099
100 return bio;
101}
102
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900103static void __submit_merged_bio(struct f2fs_bio_info *io)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900104{
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900105 struct f2fs_io_info *fio = &io->fio;
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900106
107 if (!io->bio)
108 return;
109
Jaegeuk Kim6a8f8ca2014-10-29 14:37:22 -0700110 if (is_read_io(fio->rw))
Chao Yu2ace38e2014-12-24 16:08:14 +0800111 trace_f2fs_submit_read_bio(io->sbi->sb, fio, io->bio);
Jaegeuk Kim6a8f8ca2014-10-29 14:37:22 -0700112 else
Chao Yu2ace38e2014-12-24 16:08:14 +0800113 trace_f2fs_submit_write_bio(io->sbi->sb, fio, io->bio);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900114
Jaegeuk Kim6a8f8ca2014-10-29 14:37:22 -0700115 submit_bio(fio->rw, io->bio);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900116 io->bio = NULL;
117}
118
119void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi,
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900120 enum page_type type, int rw)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900121{
122 enum page_type btype = PAGE_TYPE_OF_BIO(type);
123 struct f2fs_bio_info *io;
124
125 io = is_read_io(rw) ? &sbi->read_io : &sbi->write_io[btype];
126
Chao Yudf0f8dc2014-03-22 14:57:23 +0800127 down_write(&io->io_rwsem);
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900128
129 /* change META to META_FLUSH in the checkpoint procedure */
130 if (type >= META_FLUSH) {
131 io->fio.type = META_FLUSH;
Jaegeuk Kim0f7b2ab2014-07-23 09:57:31 -0700132 if (test_opt(sbi, NOBARRIER))
133 io->fio.rw = WRITE_FLUSH | REQ_META | REQ_PRIO;
134 else
135 io->fio.rw = WRITE_FLUSH_FUA | REQ_META | REQ_PRIO;
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900136 }
137 __submit_merged_bio(io);
Chao Yudf0f8dc2014-03-22 14:57:23 +0800138 up_write(&io->io_rwsem);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900139}
140
141/*
142 * Fill the locked page with data located in the block address.
143 * Return unlocked page.
144 */
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700145int f2fs_submit_page_bio(struct f2fs_io_info *fio)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900146{
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900147 struct bio *bio;
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700148 struct page *page = fio->encrypted_page ? fio->encrypted_page : fio->page;
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900149
Chao Yu2ace38e2014-12-24 16:08:14 +0800150 trace_f2fs_submit_page_bio(page, fio);
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700151 f2fs_trace_ios(fio, 0);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900152
153 /* Allocate a new bio */
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700154 bio = __bio_alloc(fio->sbi, fio->blk_addr, 1, is_read_io(fio->rw));
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900155
156 if (bio_add_page(bio, page, PAGE_CACHE_SIZE, 0) < PAGE_CACHE_SIZE) {
157 bio_put(bio);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900158 return -EFAULT;
159 }
160
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800161 submit_bio(fio->rw, bio);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900162 return 0;
163}
164
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700165void f2fs_submit_page_mbio(struct f2fs_io_info *fio)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900166{
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700167 struct f2fs_sb_info *sbi = fio->sbi;
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900168 enum page_type btype = PAGE_TYPE_OF_BIO(fio->type);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900169 struct f2fs_bio_info *io;
Gu Zheng940a6d32013-12-20 17:39:59 +0800170 bool is_read = is_read_io(fio->rw);
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700171 struct page *bio_page;
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900172
Gu Zheng940a6d32013-12-20 17:39:59 +0800173 io = is_read ? &sbi->read_io : &sbi->write_io[btype];
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900174
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800175 verify_block_addr(sbi, fio->blk_addr);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900176
Chao Yudf0f8dc2014-03-22 14:57:23 +0800177 down_write(&io->io_rwsem);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900178
Gu Zheng940a6d32013-12-20 17:39:59 +0800179 if (!is_read)
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900180 inc_page_count(sbi, F2FS_WRITEBACK);
181
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800182 if (io->bio && (io->last_block_in_bio != fio->blk_addr - 1 ||
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900183 io->fio.rw != fio->rw))
184 __submit_merged_bio(io);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900185alloc_new:
186 if (io->bio == NULL) {
Jaegeuk Kim90a893c2014-09-22 16:21:07 -0700187 int bio_blocks = MAX_BIO_BLOCKS(sbi);
Gu Zheng940a6d32013-12-20 17:39:59 +0800188
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800189 io->bio = __bio_alloc(sbi, fio->blk_addr, bio_blocks, is_read);
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900190 io->fio = *fio;
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900191 }
192
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700193 bio_page = fio->encrypted_page ? fio->encrypted_page : fio->page;
194
195 if (bio_add_page(io->bio, bio_page, PAGE_CACHE_SIZE, 0) <
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900196 PAGE_CACHE_SIZE) {
Jaegeuk Kim458e6192013-12-11 13:54:01 +0900197 __submit_merged_bio(io);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900198 goto alloc_new;
199 }
200
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800201 io->last_block_in_bio = fio->blk_addr;
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700202 f2fs_trace_ios(fio, 0);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900203
Chao Yudf0f8dc2014-03-22 14:57:23 +0800204 up_write(&io->io_rwsem);
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700205 trace_f2fs_submit_page_mbio(fio->page, fio);
Jaegeuk Kim93dfe2a2013-11-30 12:51:14 +0900206}
207
208/*
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900209 * Lock ordering for the change of data block address:
210 * ->data_page
211 * ->node_page
212 * update block addresses in the node page
213 */
Chao Yu216a6202015-03-19 19:23:32 +0800214void set_data_blkaddr(struct dnode_of_data *dn)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900215{
216 struct f2fs_node *rn;
217 __le32 *addr_array;
218 struct page *node_page = dn->node_page;
219 unsigned int ofs_in_node = dn->ofs_in_node;
220
Yuan Zhong5514f0a2014-01-10 07:26:14 +0000221 f2fs_wait_on_page_writeback(node_page, NODE);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900222
Gu Zheng45590712013-07-15 17:57:38 +0800223 rn = F2FS_NODE(node_page);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900224
225 /* Get physical address of data block */
226 addr_array = blkaddr_in_node(rn);
Jaegeuk Kime1509cf2014-12-30 22:57:55 -0800227 addr_array[ofs_in_node] = cpu_to_le32(dn->data_blkaddr);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900228 set_page_dirty(node_page);
229}
230
231int reserve_new_block(struct dnode_of_data *dn)
232{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700233 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900234
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900235 if (unlikely(is_inode_flag_set(F2FS_I(dn->inode), FI_NO_ALLOC)))
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900236 return -EPERM;
Chao Yucfb271d2013-12-05 17:15:22 +0800237 if (unlikely(!inc_valid_block_count(sbi, dn->inode, 1)))
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900238 return -ENOSPC;
239
Namjae Jeonc01e2852013-04-23 17:00:52 +0900240 trace_f2fs_reserve_new_block(dn->inode, dn->nid, dn->ofs_in_node);
241
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900242 dn->data_blkaddr = NEW_ADDR;
Chao Yu216a6202015-03-19 19:23:32 +0800243 set_data_blkaddr(dn);
Jaegeuk Kima18ff062014-01-21 13:32:12 +0900244 mark_inode_dirty(dn->inode);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900245 sync_inode_page(dn);
246 return 0;
247}
248
Huajun Lib6009652013-11-10 23:13:18 +0800249int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index)
250{
251 bool need_put = dn->inode_page ? false : true;
252 int err;
253
254 err = get_dnode_of_data(dn, index, ALLOC_NODE);
255 if (err)
256 return err;
Jaegeuk Kima8865372013-12-27 17:04:17 +0900257
Huajun Lib6009652013-11-10 23:13:18 +0800258 if (dn->data_blkaddr == NULL_ADDR)
259 err = reserve_new_block(dn);
Jaegeuk Kima8865372013-12-27 17:04:17 +0900260 if (err || need_put)
Huajun Lib6009652013-11-10 23:13:18 +0800261 f2fs_put_dnode(dn);
262 return err;
263}
264
Fan Li759af1c2015-08-05 15:52:16 +0800265int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900266{
Chao Yu028a41e2015-03-19 19:26:02 +0800267 struct extent_info ei;
Fan Li759af1c2015-08-05 15:52:16 +0800268 struct inode *inode = dn->inode;
Chao Yu028a41e2015-03-19 19:26:02 +0800269
Fan Li759af1c2015-08-05 15:52:16 +0800270 if (f2fs_lookup_extent_cache(inode, index, &ei)) {
271 dn->data_blkaddr = ei.blk + index - ei.fofs;
272 return 0;
Chao Yu429511c2015-02-05 17:54:31 +0800273 }
274
Fan Li759af1c2015-08-05 15:52:16 +0800275 return f2fs_reserve_block(dn, index);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900276}
277
Jaegeuk Kim43f3eae2015-04-30 17:00:33 -0700278struct page *get_read_data_page(struct inode *inode, pgoff_t index, int rw)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900279{
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900280 struct address_space *mapping = inode->i_mapping;
281 struct dnode_of_data dn;
282 struct page *page;
Chao Yucb3bc9e2015-02-05 18:03:40 +0800283 struct extent_info ei;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900284 int err;
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800285 struct f2fs_io_info fio = {
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700286 .sbi = F2FS_I_SB(inode),
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800287 .type = DATA,
Jaegeuk Kim43f3eae2015-04-30 17:00:33 -0700288 .rw = rw,
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700289 .encrypted_page = NULL,
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800290 };
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900291
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700292 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
293 return read_mapping_page(mapping, index, NULL);
294
Jaegeuk Kim9ac13492014-04-29 17:35:10 +0900295 page = grab_cache_page(mapping, index);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900296 if (!page)
297 return ERR_PTR(-ENOMEM);
298
Chao Yucb3bc9e2015-02-05 18:03:40 +0800299 if (f2fs_lookup_extent_cache(inode, index, &ei)) {
300 dn.data_blkaddr = ei.blk + index - ei.fofs;
301 goto got_it;
302 }
303
Jaegeuk Kim650495d2013-05-13 08:38:35 +0900304 set_new_dnode(&dn, inode, NULL, NULL, 0);
305 err = get_dnode_of_data(&dn, index, LOOKUP_NODE);
Jaegeuk Kim86531d62015-07-15 13:08:21 -0700306 if (err)
307 goto put_err;
Jaegeuk Kim650495d2013-05-13 08:38:35 +0900308 f2fs_put_dnode(&dn);
309
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900310 if (unlikely(dn.data_blkaddr == NULL_ADDR)) {
Jaegeuk Kim86531d62015-07-15 13:08:21 -0700311 err = -ENOENT;
312 goto put_err;
Jaegeuk Kim650495d2013-05-13 08:38:35 +0900313 }
Chao Yucb3bc9e2015-02-05 18:03:40 +0800314got_it:
Jaegeuk Kim43f3eae2015-04-30 17:00:33 -0700315 if (PageUptodate(page)) {
316 unlock_page(page);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900317 return page;
Jaegeuk Kim43f3eae2015-04-30 17:00:33 -0700318 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900319
Jaegeuk Kimd59ff4d2013-08-20 19:13:07 +0900320 /*
321 * A new dentry page is allocated but not able to be written, since its
322 * new inode page couldn't be allocated due to -ENOSPC.
323 * In such the case, its blkaddr can be remained as NEW_ADDR.
324 * see, f2fs_add_link -> get_new_data_page -> init_inode_metadata.
325 */
326 if (dn.data_blkaddr == NEW_ADDR) {
327 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
328 SetPageUptodate(page);
Jaegeuk Kim43f3eae2015-04-30 17:00:33 -0700329 unlock_page(page);
Jaegeuk Kimd59ff4d2013-08-20 19:13:07 +0900330 return page;
331 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900332
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -0800333 fio.blk_addr = dn.data_blkaddr;
Jaegeuk Kim05ca3632015-04-23 14:38:15 -0700334 fio.page = page;
335 err = f2fs_submit_page_bio(&fio);
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900336 if (err)
Jaegeuk Kim86531d62015-07-15 13:08:21 -0700337 goto put_err;
Jaegeuk Kim43f3eae2015-04-30 17:00:33 -0700338 return page;
Jaegeuk Kim86531d62015-07-15 13:08:21 -0700339
340put_err:
341 f2fs_put_page(page, 1);
342 return ERR_PTR(err);
Jaegeuk Kim43f3eae2015-04-30 17:00:33 -0700343}
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900344
Jaegeuk Kim43f3eae2015-04-30 17:00:33 -0700345struct page *find_data_page(struct inode *inode, pgoff_t index)
346{
347 struct address_space *mapping = inode->i_mapping;
348 struct page *page;
349
350 page = find_get_page(mapping, index);
351 if (page && PageUptodate(page))
352 return page;
353 f2fs_put_page(page, 0);
354
355 page = get_read_data_page(inode, index, READ_SYNC);
356 if (IS_ERR(page))
357 return page;
358
359 if (PageUptodate(page))
360 return page;
361
362 wait_on_page_locked(page);
363 if (unlikely(!PageUptodate(page))) {
364 f2fs_put_page(page, 0);
365 return ERR_PTR(-EIO);
366 }
367 return page;
368}
369
370/*
371 * If it tries to access a hole, return an error.
372 * Because, the callers, functions in dir.c and GC, should be able to know
373 * whether this page exists or not.
374 */
375struct page *get_lock_data_page(struct inode *inode, pgoff_t index)
376{
377 struct address_space *mapping = inode->i_mapping;
378 struct page *page;
379repeat:
380 page = get_read_data_page(inode, index, READ_SYNC);
381 if (IS_ERR(page))
382 return page;
383
384 /* wait for read completion */
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900385 lock_page(page);
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900386 if (unlikely(!PageUptodate(page))) {
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900387 f2fs_put_page(page, 1);
388 return ERR_PTR(-EIO);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900389 }
Jaegeuk Kim6bacf522013-12-06 15:00:58 +0900390 if (unlikely(page->mapping != mapping)) {
Jaegeuk Kimafcb7ca02013-04-26 11:55:17 +0900391 f2fs_put_page(page, 1);
392 goto repeat;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900393 }
394 return page;
395}
396
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900397/*
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900398 * Caller ensures that this data page is never allocated.
399 * A new zero-filled data page is allocated in the page cache.
Jaegeuk Kim39936832012-11-22 16:21:29 +0900400 *
Chao Yu4f4124d2013-12-21 18:02:14 +0800401 * Also, caller should grab and release a rwsem by calling f2fs_lock_op() and
402 * f2fs_unlock_op().
Chao Yu470f00e2015-07-14 18:14:06 +0800403 * Note that, ipage is set only by make_empty_dir, and if any error occur,
404 * ipage should be released by this function.
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900405 */
Jaegeuk Kim64aa7ed2013-05-20 09:55:50 +0900406struct page *get_new_data_page(struct inode *inode,
Jaegeuk Kima8865372013-12-27 17:04:17 +0900407 struct page *ipage, pgoff_t index, bool new_i_size)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900408{
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900409 struct address_space *mapping = inode->i_mapping;
410 struct page *page;
411 struct dnode_of_data dn;
412 int err;
Jaegeuk Kim01f28612015-04-29 11:18:42 -0700413repeat:
414 page = grab_cache_page(mapping, index);
Chao Yu470f00e2015-07-14 18:14:06 +0800415 if (!page) {
416 /*
417 * before exiting, we should make sure ipage will be released
418 * if any error occur.
419 */
420 f2fs_put_page(ipage, 1);
Jaegeuk Kim01f28612015-04-29 11:18:42 -0700421 return ERR_PTR(-ENOMEM);
Chao Yu470f00e2015-07-14 18:14:06 +0800422 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900423
Jaegeuk Kima8865372013-12-27 17:04:17 +0900424 set_new_dnode(&dn, inode, ipage, NULL, 0);
Huajun Lib6009652013-11-10 23:13:18 +0800425 err = f2fs_reserve_block(&dn, index);
Jaegeuk Kim01f28612015-04-29 11:18:42 -0700426 if (err) {
427 f2fs_put_page(page, 1);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900428 return ERR_PTR(err);
Jaegeuk Kima8865372013-12-27 17:04:17 +0900429 }
Jaegeuk Kim01f28612015-04-29 11:18:42 -0700430 if (!ipage)
431 f2fs_put_dnode(&dn);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900432
433 if (PageUptodate(page))
Jaegeuk Kim01f28612015-04-29 11:18:42 -0700434 goto got_it;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900435
436 if (dn.data_blkaddr == NEW_ADDR) {
437 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
Jaegeuk Kim393ff912013-03-08 21:29:23 +0900438 SetPageUptodate(page);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900439 } else {
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700440 f2fs_put_page(page, 1);
Jaegeuk Kima8865372013-12-27 17:04:17 +0900441
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700442 page = get_read_data_page(inode, index, READ_SYNC);
443 if (IS_ERR(page))
Jaegeuk Kimafcb7ca02013-04-26 11:55:17 +0900444 goto repeat;
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700445
446 /* wait for read completion */
447 lock_page(page);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900448 }
Jaegeuk Kim01f28612015-04-29 11:18:42 -0700449got_it:
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900450 if (new_i_size &&
451 i_size_read(inode) < ((index + 1) << PAGE_CACHE_SHIFT)) {
452 i_size_write(inode, ((index + 1) << PAGE_CACHE_SHIFT));
Jaegeuk Kim699489b2013-06-07 22:08:23 +0900453 /* Only the directory inode sets new_i_size */
454 set_inode_flag(F2FS_I(inode), FI_UPDATE_DIR);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900455 }
456 return page;
457}
458
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900459static int __allocate_data_block(struct dnode_of_data *dn)
460{
Jaegeuk Kim40813632014-09-02 15:31:18 -0700461 struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode);
Jaegeuk Kim976e4c52014-09-15 19:32:16 -0700462 struct f2fs_inode_info *fi = F2FS_I(dn->inode);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900463 struct f2fs_summary sum;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900464 struct node_info ni;
Jaegeuk Kim38aa0882015-01-05 16:02:20 -0800465 int seg = CURSEG_WARM_DATA;
Jaegeuk Kim976e4c52014-09-15 19:32:16 -0700466 pgoff_t fofs;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900467
468 if (unlikely(is_inode_flag_set(F2FS_I(dn->inode), FI_NO_ALLOC)))
469 return -EPERM;
Chao Yudf6136e2015-03-23 10:33:37 +0800470
471 dn->data_blkaddr = datablock_addr(dn->node_page, dn->ofs_in_node);
472 if (dn->data_blkaddr == NEW_ADDR)
473 goto alloc;
474
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900475 if (unlikely(!inc_valid_block_count(sbi, dn->inode, 1)))
476 return -ENOSPC;
477
Chao Yudf6136e2015-03-23 10:33:37 +0800478alloc:
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900479 get_node_info(sbi, dn->nid, &ni);
480 set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version);
481
Jaegeuk Kim38aa0882015-01-05 16:02:20 -0800482 if (dn->ofs_in_node == 0 && dn->inode_page == dn->node_page)
483 seg = CURSEG_DIRECT_IO;
484
Chao Yudf6136e2015-03-23 10:33:37 +0800485 allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr,
486 &sum, seg);
Chao Yu216a6202015-03-19 19:23:32 +0800487 set_data_blkaddr(dn);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900488
Jaegeuk Kim976e4c52014-09-15 19:32:16 -0700489 /* update i_size */
490 fofs = start_bidx_of_node(ofs_of_node(dn->node_page), fi) +
491 dn->ofs_in_node;
492 if (i_size_read(dn->inode) < ((fofs + 1) << PAGE_CACHE_SHIFT))
493 i_size_write(dn->inode, ((fofs + 1) << PAGE_CACHE_SHIFT));
494
Jaegeuk Kim3e72f722015-06-19 17:53:26 -0700495 /* direct IO doesn't use extent cache to maximize the performance */
Chao Yua28ef1f2015-07-08 17:59:36 +0800496 f2fs_drop_largest_extent(dn->inode, fofs);
Jaegeuk Kim3e72f722015-06-19 17:53:26 -0700497
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900498 return 0;
499}
500
Jaegeuk Kim59b802e2015-02-09 12:09:53 -0800501static void __allocate_data_blocks(struct inode *inode, loff_t offset,
502 size_t count)
503{
504 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
505 struct dnode_of_data dn;
506 u64 start = F2FS_BYTES_TO_BLK(offset);
507 u64 len = F2FS_BYTES_TO_BLK(count);
508 bool allocated;
509 u64 end_offset;
510
511 while (len) {
512 f2fs_balance_fs(sbi);
513 f2fs_lock_op(sbi);
514
515 /* When reading holes, we need its node page */
516 set_new_dnode(&dn, inode, NULL, NULL, 0);
517 if (get_dnode_of_data(&dn, start, ALLOC_NODE))
518 goto out;
519
520 allocated = false;
521 end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
522
523 while (dn.ofs_in_node < end_offset && len) {
Chao Yud6d4f1c2015-03-12 17:04:24 +0800524 block_t blkaddr;
525
526 blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node);
Chao Yudf6136e2015-03-23 10:33:37 +0800527 if (blkaddr == NULL_ADDR || blkaddr == NEW_ADDR) {
Jaegeuk Kim59b802e2015-02-09 12:09:53 -0800528 if (__allocate_data_block(&dn))
529 goto sync_out;
530 allocated = true;
531 }
532 len--;
533 start++;
534 dn.ofs_in_node++;
535 }
536
537 if (allocated)
538 sync_inode_page(&dn);
539
540 f2fs_put_dnode(&dn);
541 f2fs_unlock_op(sbi);
542 }
543 return;
544
545sync_out:
546 if (allocated)
547 sync_inode_page(&dn);
548 f2fs_put_dnode(&dn);
549out:
550 f2fs_unlock_op(sbi);
551 return;
552}
553
Jaegeuk Kim0a8165d2012-11-29 13:28:09 +0900554/*
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700555 * f2fs_map_blocks() now supported readahead/bmap/rw direct_IO with
556 * f2fs_map_blocks structure.
Chao Yu4f4124d2013-12-21 18:02:14 +0800557 * If original data blocks are allocated, then give them to blockdev.
558 * Otherwise,
559 * a. preallocate requested block addresses
560 * b. do not use extent cache for better performance
561 * c. give the block addresses to blockdev
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900562 */
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700563static int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map,
Chao Yue2b4e2b2015-08-19 19:11:19 +0800564 int create, int flag)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900565{
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700566 unsigned int maxblocks = map->m_len;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900567 struct dnode_of_data dn;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900568 int mode = create ? ALLOC_NODE : LOOKUP_NODE_RA;
569 pgoff_t pgofs, end_offset;
570 int err = 0, ofs = 1;
Chao Yua2e7d1b2015-02-05 17:50:30 +0800571 struct extent_info ei;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900572 bool allocated = false;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900573
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700574 map->m_len = 0;
575 map->m_flags = 0;
576
577 /* it only supports block size == page size */
578 pgofs = (pgoff_t)map->m_lblk;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900579
Chao Yu7e4dde72015-02-05 17:51:34 +0800580 if (f2fs_lookup_extent_cache(inode, pgofs, &ei)) {
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700581 map->m_pblk = ei.blk + pgofs - ei.fofs;
582 map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs);
583 map->m_flags = F2FS_MAP_MAPPED;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900584 goto out;
Chao Yua2e7d1b2015-02-05 17:50:30 +0800585 }
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900586
Jaegeuk Kim59b802e2015-02-09 12:09:53 -0800587 if (create)
Jaegeuk Kim40813632014-09-02 15:31:18 -0700588 f2fs_lock_op(F2FS_I_SB(inode));
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900589
590 /* When reading holes, we need its node page */
591 set_new_dnode(&dn, inode, NULL, NULL, 0);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900592 err = get_dnode_of_data(&dn, pgofs, mode);
Jaegeuk Kim1ec79082013-12-26 16:55:22 +0900593 if (err) {
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900594 if (err == -ENOENT)
595 err = 0;
596 goto unlock_out;
Namjae Jeon848753a2013-04-23 16:38:02 +0900597 }
Chao Yue2b4e2b2015-08-19 19:11:19 +0800598 if (dn.data_blkaddr == NEW_ADDR) {
599 if (flag == F2FS_GET_BLOCK_BMAP) {
600 err = -ENOENT;
601 goto put_out;
602 } else if (flag == F2FS_GET_BLOCK_READ ||
603 flag == F2FS_GET_BLOCK_DIO) {
604 goto put_out;
605 }
606 /*
607 * if it is in fiemap call path (flag = F2FS_GET_BLOCK_FIEMAP),
608 * mark it as mapped and unwritten block.
609 */
610 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900611
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900612 if (dn.data_blkaddr != NULL_ADDR) {
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700613 map->m_flags = F2FS_MAP_MAPPED;
614 map->m_pblk = dn.data_blkaddr;
Jaegeuk Kim7f63eb72015-05-08 19:30:32 -0700615 if (dn.data_blkaddr == NEW_ADDR)
616 map->m_flags |= F2FS_MAP_UNWRITTEN;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900617 } else if (create) {
618 err = __allocate_data_block(&dn);
619 if (err)
620 goto put_out;
621 allocated = true;
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700622 map->m_flags = F2FS_MAP_NEW | F2FS_MAP_MAPPED;
623 map->m_pblk = dn.data_blkaddr;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900624 } else {
Chao Yue2b4e2b2015-08-19 19:11:19 +0800625 if (flag == F2FS_GET_BLOCK_BMAP)
626 err = -ENOENT;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900627 goto put_out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900628 }
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900629
Chao Yu6403eb12014-04-26 19:59:52 +0800630 end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700631 map->m_len = 1;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900632 dn.ofs_in_node++;
633 pgofs++;
634
635get_next:
636 if (dn.ofs_in_node >= end_offset) {
637 if (allocated)
638 sync_inode_page(&dn);
639 allocated = false;
640 f2fs_put_dnode(&dn);
641
642 set_new_dnode(&dn, inode, NULL, NULL, 0);
643 err = get_dnode_of_data(&dn, pgofs, mode);
Jaegeuk Kim1ec79082013-12-26 16:55:22 +0900644 if (err) {
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900645 if (err == -ENOENT)
646 err = 0;
647 goto unlock_out;
648 }
Chao Yue2b4e2b2015-08-19 19:11:19 +0800649
650 if (dn.data_blkaddr == NEW_ADDR &&
651 flag != F2FS_GET_BLOCK_FIEMAP)
Jaegeuk Kim1ec79082013-12-26 16:55:22 +0900652 goto put_out;
653
Chao Yu6403eb12014-04-26 19:59:52 +0800654 end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode));
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900655 }
656
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700657 if (maxblocks > map->m_len) {
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900658 block_t blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node);
659 if (blkaddr == NULL_ADDR && create) {
660 err = __allocate_data_block(&dn);
661 if (err)
662 goto sync_out;
663 allocated = true;
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700664 map->m_flags |= F2FS_MAP_NEW;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900665 blkaddr = dn.data_blkaddr;
666 }
arter97e1c42042014-08-06 23:22:50 +0900667 /* Give more consecutive addresses for the readahead */
Jaegeuk Kim7f63eb72015-05-08 19:30:32 -0700668 if ((map->m_pblk != NEW_ADDR &&
669 blkaddr == (map->m_pblk + ofs)) ||
670 (map->m_pblk == NEW_ADDR &&
671 blkaddr == NEW_ADDR)) {
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900672 ofs++;
673 dn.ofs_in_node++;
674 pgofs++;
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700675 map->m_len++;
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900676 goto get_next;
677 }
678 }
679sync_out:
680 if (allocated)
681 sync_inode_page(&dn);
682put_out:
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900683 f2fs_put_dnode(&dn);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900684unlock_out:
685 if (create)
Jaegeuk Kim40813632014-09-02 15:31:18 -0700686 f2fs_unlock_op(F2FS_I_SB(inode));
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900687out:
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700688 trace_f2fs_map_blocks(inode, map, err);
Jaegeuk Kimbfad7c22013-12-16 19:04:05 +0900689 return err;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900690}
691
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700692static int __get_data_block(struct inode *inode, sector_t iblock,
Chao Yue2b4e2b2015-08-19 19:11:19 +0800693 struct buffer_head *bh, int create, int flag)
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700694{
695 struct f2fs_map_blocks map;
696 int ret;
697
698 map.m_lblk = iblock;
699 map.m_len = bh->b_size >> inode->i_blkbits;
700
Chao Yue2b4e2b2015-08-19 19:11:19 +0800701 ret = f2fs_map_blocks(inode, &map, create, flag);
Jaegeuk Kim003a3e12015-04-06 19:55:34 -0700702 if (!ret) {
703 map_bh(bh, inode->i_sb, map.m_pblk);
704 bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags;
705 bh->b_size = map.m_len << inode->i_blkbits;
706 }
707 return ret;
708}
709
Jaegeuk Kimccfb3002014-06-13 13:02:11 +0900710static int get_data_block(struct inode *inode, sector_t iblock,
Chao Yue2b4e2b2015-08-19 19:11:19 +0800711 struct buffer_head *bh_result, int create, int flag)
Jaegeuk Kimccfb3002014-06-13 13:02:11 +0900712{
Chao Yue2b4e2b2015-08-19 19:11:19 +0800713 return __get_data_block(inode, iblock, bh_result, create, flag);
Jaegeuk Kimccfb3002014-06-13 13:02:11 +0900714}
715
Chao Yue2b4e2b2015-08-19 19:11:19 +0800716static int get_data_block_dio(struct inode *inode, sector_t iblock,
Jaegeuk Kimccfb3002014-06-13 13:02:11 +0900717 struct buffer_head *bh_result, int create)
718{
Chao Yue2b4e2b2015-08-19 19:11:19 +0800719 return __get_data_block(inode, iblock, bh_result, create,
720 F2FS_GET_BLOCK_DIO);
721}
722
723static int get_data_block_bmap(struct inode *inode, sector_t iblock,
724 struct buffer_head *bh_result, int create)
725{
726 return __get_data_block(inode, iblock, bh_result, create,
727 F2FS_GET_BLOCK_BMAP);
Jaegeuk Kimccfb3002014-06-13 13:02:11 +0900728}
729
Jaegeuk Kim7f63eb72015-05-08 19:30:32 -0700730static inline sector_t logical_to_blk(struct inode *inode, loff_t offset)
731{
732 return (offset >> inode->i_blkbits);
733}
734
735static inline loff_t blk_to_logical(struct inode *inode, sector_t blk)
736{
737 return (blk << inode->i_blkbits);
738}
739
Jaegeuk Kim9ab70132014-06-08 04:30:14 +0900740int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
741 u64 start, u64 len)
742{
Jaegeuk Kim7f63eb72015-05-08 19:30:32 -0700743 struct buffer_head map_bh;
744 sector_t start_blk, last_blk;
745 loff_t isize = i_size_read(inode);
746 u64 logical = 0, phys = 0, size = 0;
747 u32 flags = 0;
748 bool past_eof = false, whole_file = false;
749 int ret = 0;
750
751 ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC);
752 if (ret)
753 return ret;
754
755 mutex_lock(&inode->i_mutex);
756
757 if (len >= isize) {
758 whole_file = true;
759 len = isize;
760 }
761
762 if (logical_to_blk(inode, len) == 0)
763 len = blk_to_logical(inode, 1);
764
765 start_blk = logical_to_blk(inode, start);
766 last_blk = logical_to_blk(inode, start + len - 1);
767next:
768 memset(&map_bh, 0, sizeof(struct buffer_head));
769 map_bh.b_size = len;
770
Chao Yue2b4e2b2015-08-19 19:11:19 +0800771 ret = get_data_block(inode, start_blk, &map_bh, 0,
772 F2FS_GET_BLOCK_FIEMAP);
Jaegeuk Kim7f63eb72015-05-08 19:30:32 -0700773 if (ret)
774 goto out;
775
776 /* HOLE */
777 if (!buffer_mapped(&map_bh)) {
778 start_blk++;
779
780 if (!past_eof && blk_to_logical(inode, start_blk) >= isize)
781 past_eof = 1;
782
783 if (past_eof && size) {
784 flags |= FIEMAP_EXTENT_LAST;
785 ret = fiemap_fill_next_extent(fieinfo, logical,
786 phys, size, flags);
787 } else if (size) {
788 ret = fiemap_fill_next_extent(fieinfo, logical,
789 phys, size, flags);
790 size = 0;
791 }
792
793 /* if we have holes up to/past EOF then we're done */
794 if (start_blk > last_blk || past_eof || ret)
795 goto out;
796 } else {
797 if (start_blk > last_blk && !whole_file) {
798 ret = fiemap_fill_next_extent(fieinfo, logical,
799 phys, size, flags);
800 goto out;
801 }
802
803 /*
804 * if size != 0 then we know we already have an extent
805 * to add, so add it.
806 */
807 if (size) {
808 ret = fiemap_fill_next_extent(fieinfo, logical,
809 phys, size, flags);
810 if (ret)
811 goto out;
812 }
813
814 logical = blk_to_logical(inode, start_blk);
815 phys = blk_to_logical(inode, map_bh.b_blocknr);
816 size = map_bh.b_size;
817 flags = 0;
818 if (buffer_unwritten(&map_bh))
819 flags = FIEMAP_EXTENT_UNWRITTEN;
820
821 start_blk += logical_to_blk(inode, size);
822
823 /*
824 * If we are past the EOF, then we need to make sure as
825 * soon as we find a hole that the last extent we found
826 * is marked with FIEMAP_EXTENT_LAST
827 */
828 if (!past_eof && logical + size >= isize)
829 past_eof = true;
830 }
831 cond_resched();
832 if (fatal_signal_pending(current))
833 ret = -EINTR;
834 else
835 goto next;
836out:
837 if (ret == 1)
838 ret = 0;
839
840 mutex_unlock(&inode->i_mutex);
841 return ret;
Jaegeuk Kim9ab70132014-06-08 04:30:14 +0900842}
843
Jaegeuk Kimf1e88662015-04-09 11:20:42 -0700844/*
845 * This function was originally taken from fs/mpage.c, and customized for f2fs.
846 * Major change was from block_size == page_size in f2fs by default.
847 */
848static int f2fs_mpage_readpages(struct address_space *mapping,
849 struct list_head *pages, struct page *page,
850 unsigned nr_pages)
851{
852 struct bio *bio = NULL;
853 unsigned page_idx;
854 sector_t last_block_in_bio = 0;
855 struct inode *inode = mapping->host;
856 const unsigned blkbits = inode->i_blkbits;
857 const unsigned blocksize = 1 << blkbits;
858 sector_t block_in_file;
859 sector_t last_block;
860 sector_t last_block_in_file;
861 sector_t block_nr;
862 struct block_device *bdev = inode->i_sb->s_bdev;
863 struct f2fs_map_blocks map;
864
865 map.m_pblk = 0;
866 map.m_lblk = 0;
867 map.m_len = 0;
868 map.m_flags = 0;
869
870 for (page_idx = 0; nr_pages; page_idx++, nr_pages--) {
871
872 prefetchw(&page->flags);
873 if (pages) {
874 page = list_entry(pages->prev, struct page, lru);
875 list_del(&page->lru);
876 if (add_to_page_cache_lru(page, mapping,
877 page->index, GFP_KERNEL))
878 goto next_page;
879 }
880
881 block_in_file = (sector_t)page->index;
882 last_block = block_in_file + nr_pages;
883 last_block_in_file = (i_size_read(inode) + blocksize - 1) >>
884 blkbits;
885 if (last_block > last_block_in_file)
886 last_block = last_block_in_file;
887
888 /*
889 * Map blocks using the previous result first.
890 */
891 if ((map.m_flags & F2FS_MAP_MAPPED) &&
892 block_in_file > map.m_lblk &&
893 block_in_file < (map.m_lblk + map.m_len))
894 goto got_it;
895
896 /*
897 * Then do more f2fs_map_blocks() calls until we are
898 * done with this page.
899 */
900 map.m_flags = 0;
901
902 if (block_in_file < last_block) {
903 map.m_lblk = block_in_file;
904 map.m_len = last_block - block_in_file;
905
906 if (f2fs_map_blocks(inode, &map, 0, false))
907 goto set_error_page;
908 }
909got_it:
910 if ((map.m_flags & F2FS_MAP_MAPPED)) {
911 block_nr = map.m_pblk + block_in_file - map.m_lblk;
912 SetPageMappedToDisk(page);
913
914 if (!PageUptodate(page) && !cleancache_get_page(page)) {
915 SetPageUptodate(page);
916 goto confused;
917 }
918 } else {
919 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
920 SetPageUptodate(page);
921 unlock_page(page);
922 goto next_page;
923 }
924
925 /*
926 * This page will go to BIO. Do we need to send this
927 * BIO off first?
928 */
929 if (bio && (last_block_in_bio != block_nr - 1)) {
930submit_and_realloc:
931 submit_bio(READ, bio);
932 bio = NULL;
933 }
934 if (bio == NULL) {
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700935 struct f2fs_crypto_ctx *ctx = NULL;
936
937 if (f2fs_encrypted_inode(inode) &&
938 S_ISREG(inode->i_mode)) {
939 struct page *cpage;
940
941 ctx = f2fs_get_crypto_ctx(inode);
942 if (IS_ERR(ctx))
943 goto set_error_page;
944
945 /* wait the page to be moved by cleaning */
946 cpage = find_lock_page(
947 META_MAPPING(F2FS_I_SB(inode)),
948 block_nr);
949 if (cpage) {
950 f2fs_wait_on_page_writeback(cpage,
951 DATA);
952 f2fs_put_page(cpage, 1);
953 }
954 }
955
Jaegeuk Kimf1e88662015-04-09 11:20:42 -0700956 bio = bio_alloc(GFP_KERNEL,
Kent Overstreetb54ffb72015-05-19 14:31:01 +0200957 min_t(int, nr_pages, BIO_MAX_PAGES));
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700958 if (!bio) {
959 if (ctx)
960 f2fs_release_crypto_ctx(ctx);
Jaegeuk Kimf1e88662015-04-09 11:20:42 -0700961 goto set_error_page;
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700962 }
Jaegeuk Kimf1e88662015-04-09 11:20:42 -0700963 bio->bi_bdev = bdev;
964 bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(block_nr);
Chao Yu12377022015-05-25 18:03:38 +0800965 bio->bi_end_io = f2fs_read_end_io;
Jaegeuk Kim4375a332015-04-23 12:04:33 -0700966 bio->bi_private = ctx;
Jaegeuk Kimf1e88662015-04-09 11:20:42 -0700967 }
968
969 if (bio_add_page(bio, page, blocksize, 0) < blocksize)
970 goto submit_and_realloc;
971
972 last_block_in_bio = block_nr;
973 goto next_page;
974set_error_page:
975 SetPageError(page);
976 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
977 unlock_page(page);
978 goto next_page;
979confused:
980 if (bio) {
981 submit_bio(READ, bio);
982 bio = NULL;
983 }
984 unlock_page(page);
985next_page:
986 if (pages)
987 page_cache_release(page);
988 }
989 BUG_ON(pages && !list_empty(pages));
990 if (bio)
991 submit_bio(READ, bio);
992 return 0;
993}
994
Jaegeuk Kimeb47b802012-11-02 17:10:12 +0900995static int f2fs_read_data_page(struct file *file, struct page *page)
996{
Huajun Li9ffe0fb2013-11-10 23:13:20 +0800997 struct inode *inode = page->mapping->host;
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -0700998 int ret = -EAGAIN;
Huajun Li9ffe0fb2013-11-10 23:13:20 +0800999
Chao Yuc20e89c2014-05-06 16:53:08 +08001000 trace_f2fs_readpage(page, DATA);
1001
arter97e1c42042014-08-06 23:22:50 +09001002 /* If the file has inline data, try to read it directly */
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001003 if (f2fs_has_inline_data(inode))
1004 ret = f2fs_read_inline_data(inode, page);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001005 if (ret == -EAGAIN)
Jaegeuk Kimf1e88662015-04-09 11:20:42 -07001006 ret = f2fs_mpage_readpages(page->mapping, NULL, page, 1);
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001007 return ret;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001008}
1009
1010static int f2fs_read_data_pages(struct file *file,
1011 struct address_space *mapping,
1012 struct list_head *pages, unsigned nr_pages)
1013{
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001014 struct inode *inode = file->f_mapping->host;
1015
1016 /* If the file has inline data, skip readpages */
1017 if (f2fs_has_inline_data(inode))
1018 return 0;
1019
Jaegeuk Kimf1e88662015-04-09 11:20:42 -07001020 return f2fs_mpage_readpages(mapping, pages, NULL, nr_pages);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001021}
1022
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001023int do_write_data_page(struct f2fs_io_info *fio)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001024{
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001025 struct page *page = fio->page;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001026 struct inode *inode = page->mapping->host;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001027 struct dnode_of_data dn;
1028 int err = 0;
1029
1030 set_new_dnode(&dn, inode, NULL, NULL, 0);
Jaegeuk Kim266e97a2013-02-26 13:10:46 +09001031 err = get_dnode_of_data(&dn, page->index, LOOKUP_NODE);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001032 if (err)
1033 return err;
1034
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001035 fio->blk_addr = dn.data_blkaddr;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001036
1037 /* This page is already truncated */
Jaegeuk Kim2bca1e22015-02-25 19:25:01 -08001038 if (fio->blk_addr == NULL_ADDR) {
1039 ClearPageUptodate(page);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001040 goto out_writepage;
Jaegeuk Kim2bca1e22015-02-25 19:25:01 -08001041 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001042
Jaegeuk Kim4375a332015-04-23 12:04:33 -07001043 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) {
1044 fio->encrypted_page = f2fs_encrypt(inode, fio->page);
1045 if (IS_ERR(fio->encrypted_page)) {
1046 err = PTR_ERR(fio->encrypted_page);
1047 goto out_writepage;
1048 }
1049 }
1050
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001051 set_page_writeback(page);
1052
1053 /*
1054 * If current allocation needs SSR,
1055 * it had better in-place writes for updated data.
1056 */
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001057 if (unlikely(fio->blk_addr != NEW_ADDR &&
Haicheng Lib25958b2013-06-13 16:59:29 +08001058 !is_cold_data(page) &&
1059 need_inplace_update(inode))) {
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001060 rewrite_data_page(fio);
Jaegeuk Kimfff04f92014-07-25 07:40:59 -07001061 set_inode_flag(F2FS_I(inode), FI_UPDATE_WRITE);
Jaegeuk Kim8ce67cb2015-03-17 17:58:08 -07001062 trace_f2fs_do_write_data_page(page, IPU);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001063 } else {
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001064 write_data_page(&dn, fio);
Chao Yu216a6202015-03-19 19:23:32 +08001065 set_data_blkaddr(&dn);
Chao Yu7e4dde72015-02-05 17:51:34 +08001066 f2fs_update_extent_cache(&dn);
Jaegeuk Kim8ce67cb2015-03-17 17:58:08 -07001067 trace_f2fs_do_write_data_page(page, OPU);
Jaegeuk Kimfff04f92014-07-25 07:40:59 -07001068 set_inode_flag(F2FS_I(inode), FI_APPEND_WRITE);
Jaegeuk Kim3c6c2be2015-03-17 17:16:35 -07001069 if (page->index == 0)
1070 set_inode_flag(F2FS_I(inode), FI_FIRST_BLOCK_WRITTEN);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001071 }
1072out_writepage:
1073 f2fs_put_dnode(&dn);
1074 return err;
1075}
1076
1077static int f2fs_write_data_page(struct page *page,
1078 struct writeback_control *wbc)
1079{
1080 struct inode *inode = page->mapping->host;
Jaegeuk Kim40813632014-09-02 15:31:18 -07001081 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001082 loff_t i_size = i_size_read(inode);
1083 const pgoff_t end_index = ((unsigned long long) i_size)
1084 >> PAGE_CACHE_SHIFT;
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001085 unsigned offset = 0;
Jaegeuk Kim39936832012-11-22 16:21:29 +09001086 bool need_balance_fs = false;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001087 int err = 0;
Jaegeuk Kim458e6192013-12-11 13:54:01 +09001088 struct f2fs_io_info fio = {
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001089 .sbi = sbi,
Jaegeuk Kim458e6192013-12-11 13:54:01 +09001090 .type = DATA,
Chris Fries6c311ec2014-01-17 14:44:39 -06001091 .rw = (wbc->sync_mode == WB_SYNC_ALL) ? WRITE_SYNC : WRITE,
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001092 .page = page,
Jaegeuk Kim4375a332015-04-23 12:04:33 -07001093 .encrypted_page = NULL,
Jaegeuk Kim458e6192013-12-11 13:54:01 +09001094 };
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001095
Chao Yuecda0de2014-05-06 16:48:26 +08001096 trace_f2fs_writepage(page, DATA);
1097
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001098 if (page->index < end_index)
Jaegeuk Kim39936832012-11-22 16:21:29 +09001099 goto write;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001100
1101 /*
1102 * If the offset is out-of-range of file size,
1103 * this page does not have to be written to disk.
1104 */
1105 offset = i_size & (PAGE_CACHE_SIZE - 1);
Jaegeuk Kim76f60262014-04-15 16:04:15 +09001106 if ((page->index >= end_index + 1) || !offset)
Jaegeuk Kim39936832012-11-22 16:21:29 +09001107 goto out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001108
1109 zero_user_segment(page, offset, PAGE_CACHE_SIZE);
Jaegeuk Kim39936832012-11-22 16:21:29 +09001110write:
Chao Yucaf00472015-01-28 17:48:42 +08001111 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001112 goto redirty_out;
Jaegeuk Kim1e843712014-12-09 06:08:59 -08001113 if (f2fs_is_drop_cache(inode))
1114 goto out;
1115 if (f2fs_is_volatile_file(inode) && !wbc->for_reclaim &&
1116 available_free_memory(sbi, BASE_CHECK))
1117 goto redirty_out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001118
Jaegeuk Kim39936832012-11-22 16:21:29 +09001119 /* Dentry blocks are controlled by checkpoint */
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001120 if (S_ISDIR(inode->i_mode)) {
Jaegeuk Kimcf779ca2014-08-11 18:37:46 -07001121 if (unlikely(f2fs_cp_error(sbi)))
1122 goto redirty_out;
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001123 err = do_write_data_page(&fio);
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001124 goto done;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001125 }
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001126
Jaegeuk Kimcf779ca2014-08-11 18:37:46 -07001127 /* we should bypass data pages to proceed the kworkder jobs */
1128 if (unlikely(f2fs_cp_error(sbi))) {
1129 SetPageError(page);
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001130 goto out;
Jaegeuk Kimcf779ca2014-08-11 18:37:46 -07001131 }
1132
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001133 if (!wbc->for_reclaim)
1134 need_balance_fs = true;
1135 else if (has_not_enough_free_secs(sbi, 0))
Jaegeuk Kim39936832012-11-22 16:21:29 +09001136 goto redirty_out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001137
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001138 err = -EAGAIN;
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001139 f2fs_lock_op(sbi);
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001140 if (f2fs_has_inline_data(inode))
1141 err = f2fs_write_inline_data(inode, page);
1142 if (err == -EAGAIN)
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001143 err = do_write_data_page(&fio);
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001144 f2fs_unlock_op(sbi);
1145done:
1146 if (err && err != -ENOENT)
1147 goto redirty_out;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001148
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001149 clear_cold_data(page);
Jaegeuk Kim39936832012-11-22 16:21:29 +09001150out:
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001151 inode_dec_dirty_pages(inode);
Jaegeuk Kim2bca1e22015-02-25 19:25:01 -08001152 if (err)
1153 ClearPageUptodate(page);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001154 unlock_page(page);
Jaegeuk Kim39936832012-11-22 16:21:29 +09001155 if (need_balance_fs)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001156 f2fs_balance_fs(sbi);
Jaegeuk Kim2aea39e2014-04-24 09:49:52 +09001157 if (wbc->for_reclaim)
1158 f2fs_submit_merged_bio(sbi, DATA, WRITE);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001159 return 0;
1160
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001161redirty_out:
Jaegeuk Kim76f60262014-04-15 16:04:15 +09001162 redirty_page_for_writepage(wbc, page);
Jaegeuk Kim8618b882014-02-17 19:29:27 +09001163 return AOP_WRITEPAGE_ACTIVATE;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001164}
1165
Namjae Jeonfa9150a2013-01-15 16:45:24 +09001166static int __f2fs_writepage(struct page *page, struct writeback_control *wbc,
1167 void *data)
1168{
1169 struct address_space *mapping = data;
1170 int ret = mapping->a_ops->writepage(page, wbc);
1171 mapping_set_error(mapping, ret);
1172 return ret;
1173}
1174
Chao Yu8f46dca2015-07-14 18:56:10 +08001175/*
1176 * This function was copied from write_cche_pages from mm/page-writeback.c.
1177 * The major change is making write step of cold data page separately from
1178 * warm/hot data page.
1179 */
1180static int f2fs_write_cache_pages(struct address_space *mapping,
1181 struct writeback_control *wbc, writepage_t writepage,
1182 void *data)
1183{
1184 int ret = 0;
1185 int done = 0;
1186 struct pagevec pvec;
1187 int nr_pages;
1188 pgoff_t uninitialized_var(writeback_index);
1189 pgoff_t index;
1190 pgoff_t end; /* Inclusive */
1191 pgoff_t done_index;
1192 int cycled;
1193 int range_whole = 0;
1194 int tag;
1195 int step = 0;
1196
1197 pagevec_init(&pvec, 0);
1198next:
1199 if (wbc->range_cyclic) {
1200 writeback_index = mapping->writeback_index; /* prev offset */
1201 index = writeback_index;
1202 if (index == 0)
1203 cycled = 1;
1204 else
1205 cycled = 0;
1206 end = -1;
1207 } else {
1208 index = wbc->range_start >> PAGE_CACHE_SHIFT;
1209 end = wbc->range_end >> PAGE_CACHE_SHIFT;
1210 if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
1211 range_whole = 1;
1212 cycled = 1; /* ignore range_cyclic tests */
1213 }
1214 if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
1215 tag = PAGECACHE_TAG_TOWRITE;
1216 else
1217 tag = PAGECACHE_TAG_DIRTY;
1218retry:
1219 if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages)
1220 tag_pages_for_writeback(mapping, index, end);
1221 done_index = index;
1222 while (!done && (index <= end)) {
1223 int i;
1224
1225 nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag,
1226 min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1);
1227 if (nr_pages == 0)
1228 break;
1229
1230 for (i = 0; i < nr_pages; i++) {
1231 struct page *page = pvec.pages[i];
1232
1233 if (page->index > end) {
1234 done = 1;
1235 break;
1236 }
1237
1238 done_index = page->index;
1239
1240 lock_page(page);
1241
1242 if (unlikely(page->mapping != mapping)) {
1243continue_unlock:
1244 unlock_page(page);
1245 continue;
1246 }
1247
1248 if (!PageDirty(page)) {
1249 /* someone wrote it for us */
1250 goto continue_unlock;
1251 }
1252
Tiezhu Yang737f1892015-07-17 12:56:00 +08001253 if (step == is_cold_data(page))
Chao Yu8f46dca2015-07-14 18:56:10 +08001254 goto continue_unlock;
1255
1256 if (PageWriteback(page)) {
1257 if (wbc->sync_mode != WB_SYNC_NONE)
1258 f2fs_wait_on_page_writeback(page, DATA);
1259 else
1260 goto continue_unlock;
1261 }
1262
1263 BUG_ON(PageWriteback(page));
1264 if (!clear_page_dirty_for_io(page))
1265 goto continue_unlock;
1266
1267 ret = (*writepage)(page, wbc, data);
1268 if (unlikely(ret)) {
1269 if (ret == AOP_WRITEPAGE_ACTIVATE) {
1270 unlock_page(page);
1271 ret = 0;
1272 } else {
1273 done_index = page->index + 1;
1274 done = 1;
1275 break;
1276 }
1277 }
1278
1279 if (--wbc->nr_to_write <= 0 &&
1280 wbc->sync_mode == WB_SYNC_NONE) {
1281 done = 1;
1282 break;
1283 }
1284 }
1285 pagevec_release(&pvec);
1286 cond_resched();
1287 }
1288
1289 if (step < 1) {
1290 step++;
1291 goto next;
1292 }
1293
1294 if (!cycled && !done) {
1295 cycled = 1;
1296 index = 0;
1297 end = writeback_index - 1;
1298 goto retry;
1299 }
1300 if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
1301 mapping->writeback_index = done_index;
1302
1303 return ret;
1304}
1305
Jaegeuk Kim25ca9232012-11-28 16:12:41 +09001306static int f2fs_write_data_pages(struct address_space *mapping,
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001307 struct writeback_control *wbc)
1308{
1309 struct inode *inode = mapping->host;
Jaegeuk Kim40813632014-09-02 15:31:18 -07001310 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
Jaegeuk Kim5463e7c2015-04-21 10:40:54 -07001311 bool locked = false;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001312 int ret;
Jaegeuk Kim50c8cdb2014-03-18 13:47:11 +09001313 long diff;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001314
Chao Yue5748432014-05-06 16:51:24 +08001315 trace_f2fs_writepages(mapping->host, wbc, DATA);
1316
P J Pcfb185a2013-04-03 11:38:00 +09001317 /* deal with chardevs and other special file */
1318 if (!mapping->a_ops->writepage)
1319 return 0;
1320
Chao Yu6a290542015-07-17 18:02:39 +08001321 /* skip writing if there is no dirty page in this inode */
1322 if (!get_dirty_pages(inode) && wbc->sync_mode == WB_SYNC_NONE)
1323 return 0;
1324
Jaegeuk Kim87d6f892014-03-18 12:40:49 +09001325 if (S_ISDIR(inode->i_mode) && wbc->sync_mode == WB_SYNC_NONE &&
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001326 get_dirty_pages(inode) < nr_pages_to_skip(sbi, DATA) &&
Jaegeuk Kim6fb03f32014-04-16 10:47:06 +09001327 available_free_memory(sbi, DIRTY_DENTS))
Jaegeuk Kimd3baf952014-03-18 13:43:05 +09001328 goto skip_write;
Jaegeuk Kim87d6f892014-03-18 12:40:49 +09001329
Jaegeuk Kimd5669f72015-02-27 13:37:39 -08001330 /* during POR, we don't need to trigger writepage at all. */
1331 if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING)))
1332 goto skip_write;
1333
Jaegeuk Kim50c8cdb2014-03-18 13:47:11 +09001334 diff = nr_pages_to_write(sbi, DATA, wbc);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001335
Jaegeuk Kim5463e7c2015-04-21 10:40:54 -07001336 if (!S_ISDIR(inode->i_mode)) {
1337 mutex_lock(&sbi->writepages);
1338 locked = true;
1339 }
Chao Yu8f46dca2015-07-14 18:56:10 +08001340 ret = f2fs_write_cache_pages(mapping, wbc, __f2fs_writepage, mapping);
Chao Yubb96a8d2015-07-06 20:31:49 +08001341 f2fs_submit_merged_bio(sbi, DATA, WRITE);
Jaegeuk Kim5463e7c2015-04-21 10:40:54 -07001342 if (locked)
1343 mutex_unlock(&sbi->writepages);
Jaegeuk Kim458e6192013-12-11 13:54:01 +09001344
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001345 remove_dirty_dir_inode(inode);
1346
Jaegeuk Kim50c8cdb2014-03-18 13:47:11 +09001347 wbc->nr_to_write = max((long)0, wbc->nr_to_write - diff);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001348 return ret;
Jaegeuk Kimd3baf952014-03-18 13:43:05 +09001349
1350skip_write:
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001351 wbc->pages_skipped += get_dirty_pages(inode);
Jaegeuk Kimd3baf952014-03-18 13:43:05 +09001352 return 0;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001353}
1354
Chao Yu3aab8f82014-07-02 13:25:04 +08001355static void f2fs_write_failed(struct address_space *mapping, loff_t to)
1356{
1357 struct inode *inode = mapping->host;
1358
1359 if (to > inode->i_size) {
1360 truncate_pagecache(inode, inode->i_size);
Jaegeuk Kim764aa3e2014-08-14 16:32:54 -07001361 truncate_blocks(inode, inode->i_size, true);
Chao Yu3aab8f82014-07-02 13:25:04 +08001362 }
1363}
1364
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001365static int f2fs_write_begin(struct file *file, struct address_space *mapping,
1366 loff_t pos, unsigned len, unsigned flags,
1367 struct page **pagep, void **fsdata)
1368{
1369 struct inode *inode = mapping->host;
Jaegeuk Kim40813632014-09-02 15:31:18 -07001370 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
Jaegeuk Kim86531d62015-07-15 13:08:21 -07001371 struct page *page = NULL;
1372 struct page *ipage;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001373 pgoff_t index = ((unsigned long long) pos) >> PAGE_CACHE_SHIFT;
1374 struct dnode_of_data dn;
1375 int err = 0;
1376
Chao Yu62aed042014-05-06 16:46:04 +08001377 trace_f2fs_write_begin(inode, pos, len, flags);
1378
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001379 f2fs_balance_fs(sbi);
Jaegeuk Kim5f727392014-11-25 10:59:45 -08001380
1381 /*
1382 * We should check this at this moment to avoid deadlock on inode page
1383 * and #0 page. The locking rule for inline_data conversion should be:
1384 * lock_page(page #0) -> lock_page(inode_page)
1385 */
1386 if (index != 0) {
1387 err = f2fs_convert_inline_inode(inode);
1388 if (err)
1389 goto fail;
1390 }
Jaegeuk Kimafcb7ca02013-04-26 11:55:17 +09001391repeat:
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001392 page = grab_cache_page_write_begin(mapping, index, flags);
Chao Yu3aab8f82014-07-02 13:25:04 +08001393 if (!page) {
1394 err = -ENOMEM;
1395 goto fail;
1396 }
Jaegeuk Kimd5f66992014-04-30 09:22:45 +09001397
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001398 *pagep = page;
1399
Gu Zhenge4795562013-09-27 18:08:30 +08001400 f2fs_lock_op(sbi);
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001401
1402 /* check inline_data */
1403 ipage = get_node_page(sbi, inode->i_ino);
Chao Yucd34e292014-12-01 11:30:20 +08001404 if (IS_ERR(ipage)) {
1405 err = PTR_ERR(ipage);
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001406 goto unlock_fail;
Chao Yucd34e292014-12-01 11:30:20 +08001407 }
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001408
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001409 set_new_dnode(&dn, inode, ipage, ipage, 0);
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001410
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001411 if (f2fs_has_inline_data(inode)) {
1412 if (pos + len <= MAX_INLINE_DATA) {
1413 read_inline_data(page, ipage);
1414 set_inode_flag(F2FS_I(inode), FI_DATA_EXIST);
1415 sync_inode_page(&dn);
1416 goto put_next;
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001417 }
Jaegeuk Kim5f727392014-11-25 10:59:45 -08001418 err = f2fs_convert_inline_page(&dn, page);
1419 if (err)
1420 goto put_fail;
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001421 }
Fan Li759af1c2015-08-05 15:52:16 +08001422
1423 err = f2fs_get_block(&dn, index);
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001424 if (err)
Jaegeuk Kim8cdcb712014-11-17 16:14:11 -08001425 goto put_fail;
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001426put_next:
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001427 f2fs_put_dnode(&dn);
1428 f2fs_unlock_op(sbi);
1429
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001430 f2fs_wait_on_page_writeback(page, DATA);
1431
Chao Yu90d43882015-07-08 18:24:38 +08001432 if (len == PAGE_CACHE_SIZE)
1433 goto out_update;
1434 if (PageUptodate(page))
1435 goto out_clear;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001436
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001437 if ((pos & PAGE_CACHE_MASK) >= i_size_read(inode)) {
1438 unsigned start = pos & (PAGE_CACHE_SIZE - 1);
1439 unsigned end = start + len;
1440
1441 /* Reading beyond i_size is simple: memset to zero */
1442 zero_user_segments(page, 0, start, end, PAGE_CACHE_SIZE);
Chao Yu90d43882015-07-08 18:24:38 +08001443 goto out_update;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001444 }
1445
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001446 if (dn.data_blkaddr == NEW_ADDR) {
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001447 zero_user_segment(page, 0, PAGE_CACHE_SIZE);
1448 } else {
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001449 struct f2fs_io_info fio = {
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001450 .sbi = sbi,
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001451 .type = DATA,
1452 .rw = READ_SYNC,
1453 .blk_addr = dn.data_blkaddr,
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001454 .page = page,
Jaegeuk Kim4375a332015-04-23 12:04:33 -07001455 .encrypted_page = NULL,
Jaegeuk Kimcf04e8e2014-12-17 19:33:13 -08001456 };
Jaegeuk Kim05ca3632015-04-23 14:38:15 -07001457 err = f2fs_submit_page_bio(&fio);
Jan Kara9234f312014-10-22 15:21:47 +02001458 if (err)
1459 goto fail;
Chao Yud54c7952014-03-29 15:30:40 +08001460
Jaegeuk Kim393ff912013-03-08 21:29:23 +09001461 lock_page(page);
Jaegeuk Kim6bacf522013-12-06 15:00:58 +09001462 if (unlikely(!PageUptodate(page))) {
Chao Yu3aab8f82014-07-02 13:25:04 +08001463 err = -EIO;
1464 goto fail;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001465 }
Jaegeuk Kim6bacf522013-12-06 15:00:58 +09001466 if (unlikely(page->mapping != mapping)) {
Jaegeuk Kimafcb7ca02013-04-26 11:55:17 +09001467 f2fs_put_page(page, 1);
1468 goto repeat;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001469 }
Jaegeuk Kim4375a332015-04-23 12:04:33 -07001470
1471 /* avoid symlink page */
1472 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) {
1473 err = f2fs_decrypt_one(inode, page);
Jaegeuk Kim86531d62015-07-15 13:08:21 -07001474 if (err)
Jaegeuk Kim4375a332015-04-23 12:04:33 -07001475 goto fail;
Jaegeuk Kim4375a332015-04-23 12:04:33 -07001476 }
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001477 }
Chao Yu90d43882015-07-08 18:24:38 +08001478out_update:
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001479 SetPageUptodate(page);
Chao Yu90d43882015-07-08 18:24:38 +08001480out_clear:
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001481 clear_cold_data(page);
1482 return 0;
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001483
Jaegeuk Kim8cdcb712014-11-17 16:14:11 -08001484put_fail:
1485 f2fs_put_dnode(&dn);
Jaegeuk Kim9ba69cf2014-10-17 20:33:55 -07001486unlock_fail:
1487 f2fs_unlock_op(sbi);
Chao Yu3aab8f82014-07-02 13:25:04 +08001488fail:
Jaegeuk Kim86531d62015-07-15 13:08:21 -07001489 f2fs_put_page(page, 1);
Chao Yu3aab8f82014-07-02 13:25:04 +08001490 f2fs_write_failed(mapping, pos + len);
1491 return err;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001492}
1493
Jaegeuk Kima1dd3c12013-06-27 13:04:08 +09001494static int f2fs_write_end(struct file *file,
1495 struct address_space *mapping,
1496 loff_t pos, unsigned len, unsigned copied,
1497 struct page *page, void *fsdata)
1498{
1499 struct inode *inode = page->mapping->host;
1500
Chao Yudfb2bf32014-05-06 16:47:23 +08001501 trace_f2fs_write_end(inode, pos, len, copied);
1502
Jaegeuk Kim34ba94b2014-10-09 13:19:53 -07001503 set_page_dirty(page);
Jaegeuk Kima1dd3c12013-06-27 13:04:08 +09001504
1505 if (pos + copied > i_size_read(inode)) {
1506 i_size_write(inode, pos + copied);
1507 mark_inode_dirty(inode);
1508 update_inode_page(inode);
1509 }
1510
Chao Yu75c3c8b2013-11-16 14:15:59 +08001511 f2fs_put_page(page, 1);
Jaegeuk Kima1dd3c12013-06-27 13:04:08 +09001512 return copied;
1513}
1514
Omar Sandoval6f673762015-03-16 04:33:52 -07001515static int check_direct_IO(struct inode *inode, struct iov_iter *iter,
1516 loff_t offset)
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001517{
1518 unsigned blocksize_mask = inode->i_sb->s_blocksize - 1;
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001519
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001520 if (offset & blocksize_mask)
1521 return -EINVAL;
1522
Al Viro5b46f252014-03-16 18:07:34 -04001523 if (iov_iter_alignment(iter) & blocksize_mask)
1524 return -EINVAL;
1525
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001526 return 0;
1527}
1528
Omar Sandoval22c61862015-03-16 04:33:53 -07001529static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter,
1530 loff_t offset)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001531{
1532 struct file *file = iocb->ki_filp;
Chao Yu3aab8f82014-07-02 13:25:04 +08001533 struct address_space *mapping = file->f_mapping;
1534 struct inode *inode = mapping->host;
1535 size_t count = iov_iter_count(iter);
1536 int err;
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001537
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001538 /* we don't need to use inline_data strictly */
1539 if (f2fs_has_inline_data(inode)) {
1540 err = f2fs_convert_inline_inode(inode);
1541 if (err)
1542 return err;
1543 }
Huajun Li9ffe0fb2013-11-10 23:13:20 +08001544
Jaegeuk Kimfcc85a42015-04-21 20:39:58 -07001545 if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode))
1546 return 0;
1547
Chao Yuc15e8592015-08-07 18:39:32 +08001548 err = check_direct_IO(inode, iter, offset);
1549 if (err)
1550 return err;
Jaegeuk Kim944fcfc2013-12-26 20:15:09 +09001551
Omar Sandoval6f673762015-03-16 04:33:52 -07001552 trace_f2fs_direct_IO_enter(inode, offset, count, iov_iter_rw(iter));
Chao Yu70407fa2014-07-31 21:11:22 +08001553
Omar Sandoval6f673762015-03-16 04:33:52 -07001554 if (iov_iter_rw(iter) == WRITE)
Jaegeuk Kim59b802e2015-02-09 12:09:53 -08001555 __allocate_data_blocks(inode, offset, count);
1556
Chao Yue2b4e2b2015-08-19 19:11:19 +08001557 err = blockdev_direct_IO(iocb, inode, iter, offset, get_data_block_dio);
Omar Sandoval6f673762015-03-16 04:33:52 -07001558 if (err < 0 && iov_iter_rw(iter) == WRITE)
Chao Yu3aab8f82014-07-02 13:25:04 +08001559 f2fs_write_failed(mapping, offset + count);
Chao Yu70407fa2014-07-31 21:11:22 +08001560
Omar Sandoval6f673762015-03-16 04:33:52 -07001561 trace_f2fs_direct_IO_exit(inode, offset, count, iov_iter_rw(iter), err);
Chao Yu70407fa2014-07-31 21:11:22 +08001562
Chao Yu3aab8f82014-07-02 13:25:04 +08001563 return err;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001564}
1565
Chao Yu487261f2015-02-05 17:44:29 +08001566void f2fs_invalidate_page(struct page *page, unsigned int offset,
1567 unsigned int length)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001568{
1569 struct inode *inode = page->mapping->host;
Chao Yu487261f2015-02-05 17:44:29 +08001570 struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001571
Chao Yu487261f2015-02-05 17:44:29 +08001572 if (inode->i_ino >= F2FS_ROOT_INO(sbi) &&
1573 (offset % PAGE_CACHE_SIZE || length != PAGE_CACHE_SIZE))
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001574 return;
1575
Chao Yu487261f2015-02-05 17:44:29 +08001576 if (PageDirty(page)) {
1577 if (inode->i_ino == F2FS_META_INO(sbi))
1578 dec_page_count(sbi, F2FS_DIRTY_META);
1579 else if (inode->i_ino == F2FS_NODE_INO(sbi))
1580 dec_page_count(sbi, F2FS_DIRTY_NODES);
1581 else
1582 inode_dec_dirty_pages(inode);
1583 }
Chao Yudecd36b2015-08-07 18:42:09 +08001584
1585 /* This is atomic written page, keep Private */
1586 if (IS_ATOMIC_WRITTEN_PAGE(page))
1587 return;
1588
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001589 ClearPagePrivate(page);
1590}
1591
Chao Yu487261f2015-02-05 17:44:29 +08001592int f2fs_release_page(struct page *page, gfp_t wait)
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001593{
Jaegeuk Kimf68daee2015-01-30 11:39:08 -08001594 /* If this is dirty page, keep PagePrivate */
1595 if (PageDirty(page))
1596 return 0;
1597
Chao Yudecd36b2015-08-07 18:42:09 +08001598 /* This is atomic written page, keep Private */
1599 if (IS_ATOMIC_WRITTEN_PAGE(page))
1600 return 0;
1601
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001602 ClearPagePrivate(page);
Jaegeuk Kimc3850aa2013-03-14 09:24:32 +09001603 return 1;
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001604}
1605
1606static int f2fs_set_data_page_dirty(struct page *page)
1607{
1608 struct address_space *mapping = page->mapping;
1609 struct inode *inode = mapping->host;
1610
Jaegeuk Kim26c6b882013-10-24 17:53:29 +09001611 trace_f2fs_set_page_dirty(page, DATA);
1612
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001613 SetPageUptodate(page);
Jaegeuk Kim34ba94b2014-10-09 13:19:53 -07001614
Jaegeuk Kim1e843712014-12-09 06:08:59 -08001615 if (f2fs_is_atomic_file(inode)) {
Chao Yudecd36b2015-08-07 18:42:09 +08001616 if (!IS_ATOMIC_WRITTEN_PAGE(page)) {
1617 register_inmem_page(inode, page);
1618 return 1;
1619 }
1620 /*
1621 * Previously, this page has been registered, we just
1622 * return here.
1623 */
1624 return 0;
Jaegeuk Kim34ba94b2014-10-09 13:19:53 -07001625 }
1626
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001627 if (!PageDirty(page)) {
1628 __set_page_dirty_nobuffers(page);
Jaegeuk Kima7ffdbe2014-09-12 15:53:45 -07001629 update_dirty_page(inode, page);
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001630 return 1;
1631 }
1632 return 0;
1633}
1634
Jaegeuk Kimc01e54b2013-01-17 20:30:23 +09001635static sector_t f2fs_bmap(struct address_space *mapping, sector_t block)
1636{
Chao Yu454ae7e2014-04-22 13:34:01 +08001637 struct inode *inode = mapping->host;
1638
Jaegeuk Kimb3d208f2014-10-23 19:48:09 -07001639 /* we don't need to use inline_data strictly */
1640 if (f2fs_has_inline_data(inode)) {
1641 int err = f2fs_convert_inline_inode(inode);
1642 if (err)
1643 return err;
1644 }
Chao Yue2b4e2b2015-08-19 19:11:19 +08001645 return generic_block_bmap(mapping, block, get_data_block_bmap);
Chao Yu429511c2015-02-05 17:54:31 +08001646}
1647
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001648const struct address_space_operations f2fs_dblock_aops = {
1649 .readpage = f2fs_read_data_page,
1650 .readpages = f2fs_read_data_pages,
1651 .writepage = f2fs_write_data_page,
1652 .writepages = f2fs_write_data_pages,
1653 .write_begin = f2fs_write_begin,
Jaegeuk Kima1dd3c12013-06-27 13:04:08 +09001654 .write_end = f2fs_write_end,
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001655 .set_page_dirty = f2fs_set_data_page_dirty,
Chao Yu487261f2015-02-05 17:44:29 +08001656 .invalidatepage = f2fs_invalidate_page,
1657 .releasepage = f2fs_release_page,
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001658 .direct_IO = f2fs_direct_IO,
Jaegeuk Kimc01e54b2013-01-17 20:30:23 +09001659 .bmap = f2fs_bmap,
Jaegeuk Kimeb47b802012-11-02 17:10:12 +09001660};