Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 1 | /* |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 2 | * 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 Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 17 | #include <linux/pagevec.h> |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 18 | #include <linux/blkdev.h> |
| 19 | #include <linux/bio.h> |
Geert Uytterhoeven | 690e4a3 | 2012-12-19 22:19:30 +0100 | [diff] [blame] | 20 | #include <linux/prefetch.h> |
Christoph Hellwig | e2e40f2 | 2015-02-22 08:58:50 -0800 | [diff] [blame] | 21 | #include <linux/uio.h> |
Jaegeuk Kim | fe76b79 | 2016-06-30 18:40:10 -0700 | [diff] [blame] | 22 | #include <linux/mm.h> |
| 23 | #include <linux/memcontrol.h> |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 24 | #include <linux/cleancache.h> |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 25 | |
| 26 | #include "f2fs.h" |
| 27 | #include "node.h" |
| 28 | #include "segment.h" |
Jaegeuk Kim | db9f7c1 | 2014-12-17 20:04:08 -0800 | [diff] [blame] | 29 | #include "trace.h" |
Namjae Jeon | 848753a | 2013-04-23 16:38:02 +0900 | [diff] [blame] | 30 | #include <trace/events/f2fs.h> |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 31 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 32 | static void f2fs_read_end_io(struct bio *bio) |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 33 | { |
Linus Torvalds | f568849 | 2014-01-30 11:19:05 -0800 | [diff] [blame] | 34 | struct bio_vec *bvec; |
| 35 | int i; |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 36 | |
Chao Yu | 1237702 | 2015-05-25 18:03:38 +0800 | [diff] [blame] | 37 | if (f2fs_bio_encrypted(bio)) { |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 38 | if (bio->bi_error) { |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 39 | fscrypt_release_ctx(bio->bi_private); |
Chao Yu | 1237702 | 2015-05-25 18:03:38 +0800 | [diff] [blame] | 40 | } else { |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 41 | fscrypt_decrypt_bio_pages(bio->bi_private, bio); |
Chao Yu | 1237702 | 2015-05-25 18:03:38 +0800 | [diff] [blame] | 42 | return; |
| 43 | } |
| 44 | } |
| 45 | |
Linus Torvalds | f568849 | 2014-01-30 11:19:05 -0800 | [diff] [blame] | 46 | bio_for_each_segment_all(bvec, bio, i) { |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 47 | struct page *page = bvec->bv_page; |
| 48 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 49 | if (!bio->bi_error) { |
Jaegeuk Kim | 237c079 | 2016-06-30 18:49:15 -0700 | [diff] [blame] | 50 | if (!PageUptodate(page)) |
| 51 | SetPageUptodate(page); |
Linus Torvalds | f568849 | 2014-01-30 11:19:05 -0800 | [diff] [blame] | 52 | } else { |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 53 | ClearPageUptodate(page); |
| 54 | SetPageError(page); |
| 55 | } |
| 56 | unlock_page(page); |
Linus Torvalds | f568849 | 2014-01-30 11:19:05 -0800 | [diff] [blame] | 57 | } |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 58 | bio_put(bio); |
| 59 | } |
| 60 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 61 | static void f2fs_write_end_io(struct bio *bio) |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 62 | { |
Jaegeuk Kim | 1b1f559 | 2014-02-03 10:50:22 +0900 | [diff] [blame] | 63 | struct f2fs_sb_info *sbi = bio->bi_private; |
Linus Torvalds | f568849 | 2014-01-30 11:19:05 -0800 | [diff] [blame] | 64 | struct bio_vec *bvec; |
| 65 | int i; |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 66 | |
Linus Torvalds | f568849 | 2014-01-30 11:19:05 -0800 | [diff] [blame] | 67 | bio_for_each_segment_all(bvec, bio, i) { |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 68 | struct page *page = bvec->bv_page; |
| 69 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 70 | fscrypt_pullback_bio_page(&page, true); |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 71 | |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 72 | if (unlikely(bio->bi_error)) { |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 73 | set_bit(AS_EIO, &page->mapping->flags); |
Jaegeuk Kim | 38f91ca | 2016-05-18 14:07:56 -0700 | [diff] [blame] | 74 | f2fs_stop_checkpoint(sbi, true); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 75 | } |
| 76 | end_page_writeback(page); |
Linus Torvalds | f568849 | 2014-01-30 11:19:05 -0800 | [diff] [blame] | 77 | } |
Jaegeuk Kim | f573018 | 2016-05-17 16:23:36 -0700 | [diff] [blame] | 78 | if (atomic_dec_and_test(&sbi->nr_wb_bios) && |
| 79 | wq_has_sleeper(&sbi->cp_wait)) |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 80 | wake_up(&sbi->cp_wait); |
| 81 | |
| 82 | bio_put(bio); |
| 83 | } |
| 84 | |
Gu Zheng | 940a6d3 | 2013-12-20 17:39:59 +0800 | [diff] [blame] | 85 | /* |
| 86 | * Low-level block read/write IO operations. |
| 87 | */ |
| 88 | static 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 Kim | 740432f | 2015-08-14 11:43:56 -0700 | [diff] [blame] | 93 | bio = f2fs_bio_alloc(npages); |
Gu Zheng | 940a6d3 | 2013-12-20 17:39:59 +0800 | [diff] [blame] | 94 | |
| 95 | bio->bi_bdev = sbi->sb->s_bdev; |
Chao Yu | 55cf9cb | 2014-09-15 18:01:10 +0800 | [diff] [blame] | 96 | bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blk_addr); |
Gu Zheng | 940a6d3 | 2013-12-20 17:39:59 +0800 | [diff] [blame] | 97 | bio->bi_end_io = is_read ? f2fs_read_end_io : f2fs_write_end_io; |
Chao Yu | 1237702 | 2015-05-25 18:03:38 +0800 | [diff] [blame] | 98 | bio->bi_private = is_read ? NULL : sbi; |
Gu Zheng | 940a6d3 | 2013-12-20 17:39:59 +0800 | [diff] [blame] | 99 | |
| 100 | return bio; |
| 101 | } |
| 102 | |
Linus Torvalds | 4fc29c1 | 2016-07-27 10:36:31 -0700 | [diff] [blame] | 103 | static inline void __submit_bio(struct f2fs_sb_info *sbi, |
| 104 | struct bio *bio, enum page_type type) |
Jaegeuk Kim | f573018 | 2016-05-17 16:23:36 -0700 | [diff] [blame] | 105 | { |
Linus Torvalds | 4fc29c1 | 2016-07-27 10:36:31 -0700 | [diff] [blame] | 106 | if (!is_read_io(bio_op(bio))) { |
Jaegeuk Kim | f573018 | 2016-05-17 16:23:36 -0700 | [diff] [blame] | 107 | atomic_inc(&sbi->nr_wb_bios); |
Jaegeuk Kim | 52763a4 | 2016-06-13 09:47:48 -0700 | [diff] [blame] | 108 | if (f2fs_sb_mounted_hmsmr(sbi->sb) && |
| 109 | current->plug && (type == DATA || type == NODE)) |
Jaegeuk Kim | 19a5f5e | 2016-06-04 14:25:24 -0700 | [diff] [blame] | 110 | blk_finish_plug(current->plug); |
| 111 | } |
Mike Christie | 4e49ea4 | 2016-06-05 14:31:41 -0500 | [diff] [blame] | 112 | submit_bio(bio); |
Jaegeuk Kim | f573018 | 2016-05-17 16:23:36 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 115 | static void __submit_merged_bio(struct f2fs_bio_info *io) |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 116 | { |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 117 | struct f2fs_io_info *fio = &io->fio; |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 118 | |
| 119 | if (!io->bio) |
| 120 | return; |
| 121 | |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 122 | if (is_read_io(fio->op)) |
Chao Yu | 2ace38e | 2014-12-24 16:08:14 +0800 | [diff] [blame] | 123 | trace_f2fs_submit_read_bio(io->sbi->sb, fio, io->bio); |
Jaegeuk Kim | 6a8f8ca | 2014-10-29 14:37:22 -0700 | [diff] [blame] | 124 | else |
Chao Yu | 2ace38e | 2014-12-24 16:08:14 +0800 | [diff] [blame] | 125 | trace_f2fs_submit_write_bio(io->sbi->sb, fio, io->bio); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 126 | |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 127 | bio_set_op_attrs(io->bio, fio->op, fio->op_flags); |
| 128 | |
Linus Torvalds | 4fc29c1 | 2016-07-27 10:36:31 -0700 | [diff] [blame] | 129 | __submit_bio(io->sbi, io->bio, fio->type); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 130 | io->bio = NULL; |
| 131 | } |
| 132 | |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 133 | static bool __has_merged_page(struct f2fs_bio_info *io, struct inode *inode, |
| 134 | struct page *page, nid_t ino) |
Chao Yu | 0fd785e | 2016-01-18 18:24:59 +0800 | [diff] [blame] | 135 | { |
Chao Yu | 0fd785e | 2016-01-18 18:24:59 +0800 | [diff] [blame] | 136 | struct bio_vec *bvec; |
| 137 | struct page *target; |
| 138 | int i; |
| 139 | |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 140 | if (!io->bio) |
Chao Yu | 0fd785e | 2016-01-18 18:24:59 +0800 | [diff] [blame] | 141 | return false; |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 142 | |
| 143 | if (!inode && !page && !ino) |
| 144 | return true; |
Chao Yu | 0fd785e | 2016-01-18 18:24:59 +0800 | [diff] [blame] | 145 | |
| 146 | bio_for_each_segment_all(bvec, io->bio, i) { |
| 147 | |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 148 | if (bvec->bv_page->mapping) |
Chao Yu | 0fd785e | 2016-01-18 18:24:59 +0800 | [diff] [blame] | 149 | target = bvec->bv_page; |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 150 | else |
| 151 | target = fscrypt_control_page(bvec->bv_page); |
Chao Yu | 0fd785e | 2016-01-18 18:24:59 +0800 | [diff] [blame] | 152 | |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 153 | if (inode && inode == target->mapping->host) |
Chao Yu | 0fd785e | 2016-01-18 18:24:59 +0800 | [diff] [blame] | 154 | return true; |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 155 | if (page && page == target) |
| 156 | return true; |
| 157 | if (ino && ino == ino_of_node(target)) |
| 158 | return true; |
Chao Yu | 0fd785e | 2016-01-18 18:24:59 +0800 | [diff] [blame] | 159 | } |
| 160 | |
Chao Yu | 0fd785e | 2016-01-18 18:24:59 +0800 | [diff] [blame] | 161 | return false; |
| 162 | } |
| 163 | |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 164 | static bool has_merged_page(struct f2fs_sb_info *sbi, struct inode *inode, |
| 165 | struct page *page, nid_t ino, |
| 166 | enum page_type type) |
| 167 | { |
| 168 | enum page_type btype = PAGE_TYPE_OF_BIO(type); |
| 169 | struct f2fs_bio_info *io = &sbi->write_io[btype]; |
| 170 | bool ret; |
| 171 | |
| 172 | down_read(&io->io_rwsem); |
| 173 | ret = __has_merged_page(io, inode, page, ino); |
| 174 | up_read(&io->io_rwsem); |
| 175 | return ret; |
| 176 | } |
| 177 | |
| 178 | static void __f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, |
| 179 | struct inode *inode, struct page *page, |
| 180 | nid_t ino, enum page_type type, int rw) |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 181 | { |
| 182 | enum page_type btype = PAGE_TYPE_OF_BIO(type); |
| 183 | struct f2fs_bio_info *io; |
| 184 | |
| 185 | io = is_read_io(rw) ? &sbi->read_io : &sbi->write_io[btype]; |
| 186 | |
Chao Yu | df0f8dc | 2014-03-22 14:57:23 +0800 | [diff] [blame] | 187 | down_write(&io->io_rwsem); |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 188 | |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 189 | if (!__has_merged_page(io, inode, page, ino)) |
| 190 | goto out; |
| 191 | |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 192 | /* change META to META_FLUSH in the checkpoint procedure */ |
| 193 | if (type >= META_FLUSH) { |
| 194 | io->fio.type = META_FLUSH; |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 195 | io->fio.op = REQ_OP_WRITE; |
Jaegeuk Kim | 0f7b2ab | 2014-07-23 09:57:31 -0700 | [diff] [blame] | 196 | if (test_opt(sbi, NOBARRIER)) |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 197 | io->fio.op_flags = WRITE_FLUSH | REQ_META | REQ_PRIO; |
Jaegeuk Kim | 0f7b2ab | 2014-07-23 09:57:31 -0700 | [diff] [blame] | 198 | else |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 199 | io->fio.op_flags = WRITE_FLUSH_FUA | REQ_META | |
| 200 | REQ_PRIO; |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 201 | } |
| 202 | __submit_merged_bio(io); |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 203 | out: |
Chao Yu | df0f8dc | 2014-03-22 14:57:23 +0800 | [diff] [blame] | 204 | up_write(&io->io_rwsem); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 205 | } |
| 206 | |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 207 | void f2fs_submit_merged_bio(struct f2fs_sb_info *sbi, enum page_type type, |
| 208 | int rw) |
| 209 | { |
| 210 | __f2fs_submit_merged_bio(sbi, NULL, NULL, 0, type, rw); |
| 211 | } |
| 212 | |
| 213 | void f2fs_submit_merged_bio_cond(struct f2fs_sb_info *sbi, |
| 214 | struct inode *inode, struct page *page, |
| 215 | nid_t ino, enum page_type type, int rw) |
| 216 | { |
| 217 | if (has_merged_page(sbi, inode, page, ino, type)) |
| 218 | __f2fs_submit_merged_bio(sbi, inode, page, ino, type, rw); |
| 219 | } |
| 220 | |
Chao Yu | 406657d | 2016-02-24 17:17:55 +0800 | [diff] [blame] | 221 | void f2fs_flush_merged_bios(struct f2fs_sb_info *sbi) |
| 222 | { |
| 223 | f2fs_submit_merged_bio(sbi, DATA, WRITE); |
| 224 | f2fs_submit_merged_bio(sbi, NODE, WRITE); |
| 225 | f2fs_submit_merged_bio(sbi, META, WRITE); |
| 226 | } |
| 227 | |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 228 | /* |
| 229 | * Fill the locked page with data located in the block address. |
| 230 | * Return unlocked page. |
| 231 | */ |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 232 | int f2fs_submit_page_bio(struct f2fs_io_info *fio) |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 233 | { |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 234 | struct bio *bio; |
Jaegeuk Kim | 0b81d07 | 2015-05-15 16:26:10 -0700 | [diff] [blame] | 235 | struct page *page = fio->encrypted_page ? |
| 236 | fio->encrypted_page : fio->page; |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 237 | |
Chao Yu | 2ace38e | 2014-12-24 16:08:14 +0800 | [diff] [blame] | 238 | trace_f2fs_submit_page_bio(page, fio); |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 239 | f2fs_trace_ios(fio, 0); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 240 | |
| 241 | /* Allocate a new bio */ |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 242 | bio = __bio_alloc(fio->sbi, fio->new_blkaddr, 1, is_read_io(fio->op)); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 243 | |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 244 | if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 245 | bio_put(bio); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 246 | return -EFAULT; |
| 247 | } |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 248 | bio_set_op_attrs(bio, fio->op, fio->op_flags); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 249 | |
Linus Torvalds | 4fc29c1 | 2016-07-27 10:36:31 -0700 | [diff] [blame] | 250 | __submit_bio(fio->sbi, bio, fio->type); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 251 | return 0; |
| 252 | } |
| 253 | |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 254 | void f2fs_submit_page_mbio(struct f2fs_io_info *fio) |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 255 | { |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 256 | struct f2fs_sb_info *sbi = fio->sbi; |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 257 | enum page_type btype = PAGE_TYPE_OF_BIO(fio->type); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 258 | struct f2fs_bio_info *io; |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 259 | bool is_read = is_read_io(fio->op); |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 260 | struct page *bio_page; |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 261 | |
Gu Zheng | 940a6d3 | 2013-12-20 17:39:59 +0800 | [diff] [blame] | 262 | io = is_read ? &sbi->read_io : &sbi->write_io[btype]; |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 263 | |
Chao Yu | 7a9d754 | 2016-02-22 18:36:38 +0800 | [diff] [blame] | 264 | if (fio->old_blkaddr != NEW_ADDR) |
| 265 | verify_block_addr(sbi, fio->old_blkaddr); |
| 266 | verify_block_addr(sbi, fio->new_blkaddr); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 267 | |
Chao Yu | df0f8dc | 2014-03-22 14:57:23 +0800 | [diff] [blame] | 268 | down_write(&io->io_rwsem); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 269 | |
Chao Yu | 7a9d754 | 2016-02-22 18:36:38 +0800 | [diff] [blame] | 270 | if (io->bio && (io->last_block_in_bio != fio->new_blkaddr - 1 || |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 271 | (io->fio.op != fio->op || io->fio.op_flags != fio->op_flags))) |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 272 | __submit_merged_bio(io); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 273 | alloc_new: |
| 274 | if (io->bio == NULL) { |
Jaegeuk Kim | 90a893c | 2014-09-22 16:21:07 -0700 | [diff] [blame] | 275 | int bio_blocks = MAX_BIO_BLOCKS(sbi); |
Gu Zheng | 940a6d3 | 2013-12-20 17:39:59 +0800 | [diff] [blame] | 276 | |
Chao Yu | 7a9d754 | 2016-02-22 18:36:38 +0800 | [diff] [blame] | 277 | io->bio = __bio_alloc(sbi, fio->new_blkaddr, |
| 278 | bio_blocks, is_read); |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 279 | io->fio = *fio; |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 280 | } |
| 281 | |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 282 | bio_page = fio->encrypted_page ? fio->encrypted_page : fio->page; |
| 283 | |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 284 | if (bio_add_page(io->bio, bio_page, PAGE_SIZE, 0) < |
| 285 | PAGE_SIZE) { |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 286 | __submit_merged_bio(io); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 287 | goto alloc_new; |
| 288 | } |
| 289 | |
Chao Yu | 7a9d754 | 2016-02-22 18:36:38 +0800 | [diff] [blame] | 290 | io->last_block_in_bio = fio->new_blkaddr; |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 291 | f2fs_trace_ios(fio, 0); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 292 | |
Chao Yu | df0f8dc | 2014-03-22 14:57:23 +0800 | [diff] [blame] | 293 | up_write(&io->io_rwsem); |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 294 | trace_f2fs_submit_page_mbio(fio->page, fio); |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 295 | } |
| 296 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 297 | static void __set_data_blkaddr(struct dnode_of_data *dn) |
| 298 | { |
| 299 | struct f2fs_node *rn = F2FS_NODE(dn->node_page); |
| 300 | __le32 *addr_array; |
| 301 | |
| 302 | /* Get physical address of data block */ |
| 303 | addr_array = blkaddr_in_node(rn); |
| 304 | addr_array[dn->ofs_in_node] = cpu_to_le32(dn->data_blkaddr); |
| 305 | } |
| 306 | |
Jaegeuk Kim | 93dfe2a | 2013-11-30 12:51:14 +0900 | [diff] [blame] | 307 | /* |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 308 | * Lock ordering for the change of data block address: |
| 309 | * ->data_page |
| 310 | * ->node_page |
| 311 | * update block addresses in the node page |
| 312 | */ |
Chao Yu | 216a620 | 2015-03-19 19:23:32 +0800 | [diff] [blame] | 313 | void set_data_blkaddr(struct dnode_of_data *dn) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 314 | { |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 315 | f2fs_wait_on_page_writeback(dn->node_page, NODE, true); |
| 316 | __set_data_blkaddr(dn); |
| 317 | if (set_page_dirty(dn->node_page)) |
Jaegeuk Kim | 12719ae | 2016-01-07 13:23:12 -0800 | [diff] [blame] | 318 | dn->node_changed = true; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 319 | } |
| 320 | |
Chao Yu | f28b343 | 2016-02-24 17:16:47 +0800 | [diff] [blame] | 321 | void f2fs_update_data_blkaddr(struct dnode_of_data *dn, block_t blkaddr) |
| 322 | { |
| 323 | dn->data_blkaddr = blkaddr; |
| 324 | set_data_blkaddr(dn); |
| 325 | f2fs_update_extent_cache(dn); |
| 326 | } |
| 327 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 328 | /* dn->ofs_in_node will be returned with up-to-date last block pointer */ |
| 329 | int reserve_new_blocks(struct dnode_of_data *dn, blkcnt_t count) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 330 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 331 | struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 332 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 333 | if (!count) |
| 334 | return 0; |
| 335 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 336 | if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC))) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 337 | return -EPERM; |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 338 | if (unlikely(!inc_valid_block_count(sbi, dn->inode, &count))) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 339 | return -ENOSPC; |
| 340 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 341 | trace_f2fs_reserve_new_blocks(dn->inode, dn->nid, |
| 342 | dn->ofs_in_node, count); |
Namjae Jeon | c01e285 | 2013-04-23 17:00:52 +0900 | [diff] [blame] | 343 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 344 | f2fs_wait_on_page_writeback(dn->node_page, NODE, true); |
| 345 | |
| 346 | for (; count > 0; dn->ofs_in_node++) { |
| 347 | block_t blkaddr = |
| 348 | datablock_addr(dn->node_page, dn->ofs_in_node); |
| 349 | if (blkaddr == NULL_ADDR) { |
| 350 | dn->data_blkaddr = NEW_ADDR; |
| 351 | __set_data_blkaddr(dn); |
| 352 | count--; |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | if (set_page_dirty(dn->node_page)) |
| 357 | dn->node_changed = true; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 358 | return 0; |
| 359 | } |
| 360 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 361 | /* Should keep dn->ofs_in_node unchanged */ |
| 362 | int reserve_new_block(struct dnode_of_data *dn) |
| 363 | { |
| 364 | unsigned int ofs_in_node = dn->ofs_in_node; |
| 365 | int ret; |
| 366 | |
| 367 | ret = reserve_new_blocks(dn, 1); |
| 368 | dn->ofs_in_node = ofs_in_node; |
| 369 | return ret; |
| 370 | } |
| 371 | |
Huajun Li | b600965 | 2013-11-10 23:13:18 +0800 | [diff] [blame] | 372 | int f2fs_reserve_block(struct dnode_of_data *dn, pgoff_t index) |
| 373 | { |
| 374 | bool need_put = dn->inode_page ? false : true; |
| 375 | int err; |
| 376 | |
| 377 | err = get_dnode_of_data(dn, index, ALLOC_NODE); |
| 378 | if (err) |
| 379 | return err; |
Jaegeuk Kim | a886537 | 2013-12-27 17:04:17 +0900 | [diff] [blame] | 380 | |
Huajun Li | b600965 | 2013-11-10 23:13:18 +0800 | [diff] [blame] | 381 | if (dn->data_blkaddr == NULL_ADDR) |
| 382 | err = reserve_new_block(dn); |
Jaegeuk Kim | a886537 | 2013-12-27 17:04:17 +0900 | [diff] [blame] | 383 | if (err || need_put) |
Huajun Li | b600965 | 2013-11-10 23:13:18 +0800 | [diff] [blame] | 384 | f2fs_put_dnode(dn); |
| 385 | return err; |
| 386 | } |
| 387 | |
Fan Li | 759af1c | 2015-08-05 15:52:16 +0800 | [diff] [blame] | 388 | int f2fs_get_block(struct dnode_of_data *dn, pgoff_t index) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 389 | { |
Chao Yu | 028a41e | 2015-03-19 19:26:02 +0800 | [diff] [blame] | 390 | struct extent_info ei; |
Fan Li | 759af1c | 2015-08-05 15:52:16 +0800 | [diff] [blame] | 391 | struct inode *inode = dn->inode; |
Chao Yu | 028a41e | 2015-03-19 19:26:02 +0800 | [diff] [blame] | 392 | |
Fan Li | 759af1c | 2015-08-05 15:52:16 +0800 | [diff] [blame] | 393 | if (f2fs_lookup_extent_cache(inode, index, &ei)) { |
| 394 | dn->data_blkaddr = ei.blk + index - ei.fofs; |
| 395 | return 0; |
Chao Yu | 429511c | 2015-02-05 17:54:31 +0800 | [diff] [blame] | 396 | } |
| 397 | |
Fan Li | 759af1c | 2015-08-05 15:52:16 +0800 | [diff] [blame] | 398 | return f2fs_reserve_block(dn, index); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 399 | } |
| 400 | |
Jaegeuk Kim | a56c7c6 | 2015-10-09 15:11:38 -0700 | [diff] [blame] | 401 | struct page *get_read_data_page(struct inode *inode, pgoff_t index, |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 402 | int op_flags, bool for_write) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 403 | { |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 404 | struct address_space *mapping = inode->i_mapping; |
| 405 | struct dnode_of_data dn; |
| 406 | struct page *page; |
Chao Yu | cb3bc9e | 2015-02-05 18:03:40 +0800 | [diff] [blame] | 407 | struct extent_info ei; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 408 | int err; |
Jaegeuk Kim | cf04e8e | 2014-12-17 19:33:13 -0800 | [diff] [blame] | 409 | struct f2fs_io_info fio = { |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 410 | .sbi = F2FS_I_SB(inode), |
Jaegeuk Kim | cf04e8e | 2014-12-17 19:33:13 -0800 | [diff] [blame] | 411 | .type = DATA, |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 412 | .op = REQ_OP_READ, |
| 413 | .op_flags = op_flags, |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 414 | .encrypted_page = NULL, |
Jaegeuk Kim | cf04e8e | 2014-12-17 19:33:13 -0800 | [diff] [blame] | 415 | }; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 416 | |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 417 | if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) |
| 418 | return read_mapping_page(mapping, index, NULL); |
| 419 | |
Jaegeuk Kim | a56c7c6 | 2015-10-09 15:11:38 -0700 | [diff] [blame] | 420 | page = f2fs_grab_cache_page(mapping, index, for_write); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 421 | if (!page) |
| 422 | return ERR_PTR(-ENOMEM); |
| 423 | |
Chao Yu | cb3bc9e | 2015-02-05 18:03:40 +0800 | [diff] [blame] | 424 | if (f2fs_lookup_extent_cache(inode, index, &ei)) { |
| 425 | dn.data_blkaddr = ei.blk + index - ei.fofs; |
| 426 | goto got_it; |
| 427 | } |
| 428 | |
Jaegeuk Kim | 650495d | 2013-05-13 08:38:35 +0900 | [diff] [blame] | 429 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
| 430 | err = get_dnode_of_data(&dn, index, LOOKUP_NODE); |
Jaegeuk Kim | 86531d6 | 2015-07-15 13:08:21 -0700 | [diff] [blame] | 431 | if (err) |
| 432 | goto put_err; |
Jaegeuk Kim | 650495d | 2013-05-13 08:38:35 +0900 | [diff] [blame] | 433 | f2fs_put_dnode(&dn); |
| 434 | |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 435 | if (unlikely(dn.data_blkaddr == NULL_ADDR)) { |
Jaegeuk Kim | 86531d6 | 2015-07-15 13:08:21 -0700 | [diff] [blame] | 436 | err = -ENOENT; |
| 437 | goto put_err; |
Jaegeuk Kim | 650495d | 2013-05-13 08:38:35 +0900 | [diff] [blame] | 438 | } |
Chao Yu | cb3bc9e | 2015-02-05 18:03:40 +0800 | [diff] [blame] | 439 | got_it: |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 440 | if (PageUptodate(page)) { |
| 441 | unlock_page(page); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 442 | return page; |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 443 | } |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 444 | |
Jaegeuk Kim | d59ff4d | 2013-08-20 19:13:07 +0900 | [diff] [blame] | 445 | /* |
| 446 | * A new dentry page is allocated but not able to be written, since its |
| 447 | * new inode page couldn't be allocated due to -ENOSPC. |
| 448 | * In such the case, its blkaddr can be remained as NEW_ADDR. |
| 449 | * see, f2fs_add_link -> get_new_data_page -> init_inode_metadata. |
| 450 | */ |
| 451 | if (dn.data_blkaddr == NEW_ADDR) { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 452 | zero_user_segment(page, 0, PAGE_SIZE); |
Jaegeuk Kim | 237c079 | 2016-06-30 18:49:15 -0700 | [diff] [blame] | 453 | if (!PageUptodate(page)) |
| 454 | SetPageUptodate(page); |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 455 | unlock_page(page); |
Jaegeuk Kim | d59ff4d | 2013-08-20 19:13:07 +0900 | [diff] [blame] | 456 | return page; |
| 457 | } |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 458 | |
Chao Yu | 7a9d754 | 2016-02-22 18:36:38 +0800 | [diff] [blame] | 459 | fio.new_blkaddr = fio.old_blkaddr = dn.data_blkaddr; |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 460 | fio.page = page; |
| 461 | err = f2fs_submit_page_bio(&fio); |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 462 | if (err) |
Jaegeuk Kim | 86531d6 | 2015-07-15 13:08:21 -0700 | [diff] [blame] | 463 | goto put_err; |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 464 | return page; |
Jaegeuk Kim | 86531d6 | 2015-07-15 13:08:21 -0700 | [diff] [blame] | 465 | |
| 466 | put_err: |
| 467 | f2fs_put_page(page, 1); |
| 468 | return ERR_PTR(err); |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 469 | } |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 470 | |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 471 | struct page *find_data_page(struct inode *inode, pgoff_t index) |
| 472 | { |
| 473 | struct address_space *mapping = inode->i_mapping; |
| 474 | struct page *page; |
| 475 | |
| 476 | page = find_get_page(mapping, index); |
| 477 | if (page && PageUptodate(page)) |
| 478 | return page; |
| 479 | f2fs_put_page(page, 0); |
| 480 | |
Jaegeuk Kim | a56c7c6 | 2015-10-09 15:11:38 -0700 | [diff] [blame] | 481 | page = get_read_data_page(inode, index, READ_SYNC, false); |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 482 | if (IS_ERR(page)) |
| 483 | return page; |
| 484 | |
| 485 | if (PageUptodate(page)) |
| 486 | return page; |
| 487 | |
| 488 | wait_on_page_locked(page); |
| 489 | if (unlikely(!PageUptodate(page))) { |
| 490 | f2fs_put_page(page, 0); |
| 491 | return ERR_PTR(-EIO); |
| 492 | } |
| 493 | return page; |
| 494 | } |
| 495 | |
| 496 | /* |
| 497 | * If it tries to access a hole, return an error. |
| 498 | * Because, the callers, functions in dir.c and GC, should be able to know |
| 499 | * whether this page exists or not. |
| 500 | */ |
Jaegeuk Kim | a56c7c6 | 2015-10-09 15:11:38 -0700 | [diff] [blame] | 501 | struct page *get_lock_data_page(struct inode *inode, pgoff_t index, |
| 502 | bool for_write) |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 503 | { |
| 504 | struct address_space *mapping = inode->i_mapping; |
| 505 | struct page *page; |
| 506 | repeat: |
Jaegeuk Kim | a56c7c6 | 2015-10-09 15:11:38 -0700 | [diff] [blame] | 507 | page = get_read_data_page(inode, index, READ_SYNC, for_write); |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 508 | if (IS_ERR(page)) |
| 509 | return page; |
| 510 | |
| 511 | /* wait for read completion */ |
Jaegeuk Kim | 393ff91 | 2013-03-08 21:29:23 +0900 | [diff] [blame] | 512 | lock_page(page); |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 513 | if (unlikely(page->mapping != mapping)) { |
Jaegeuk Kim | afcb7ca0 | 2013-04-26 11:55:17 +0900 | [diff] [blame] | 514 | f2fs_put_page(page, 1); |
| 515 | goto repeat; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 516 | } |
Chao Yu | 1563ac7 | 2016-07-03 22:05:12 +0800 | [diff] [blame] | 517 | if (unlikely(!PageUptodate(page))) { |
| 518 | f2fs_put_page(page, 1); |
| 519 | return ERR_PTR(-EIO); |
| 520 | } |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 521 | return page; |
| 522 | } |
| 523 | |
Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 524 | /* |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 525 | * Caller ensures that this data page is never allocated. |
| 526 | * A new zero-filled data page is allocated in the page cache. |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 527 | * |
Chao Yu | 4f4124d | 2013-12-21 18:02:14 +0800 | [diff] [blame] | 528 | * Also, caller should grab and release a rwsem by calling f2fs_lock_op() and |
| 529 | * f2fs_unlock_op(). |
Chao Yu | 470f00e | 2015-07-14 18:14:06 +0800 | [diff] [blame] | 530 | * Note that, ipage is set only by make_empty_dir, and if any error occur, |
| 531 | * ipage should be released by this function. |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 532 | */ |
Jaegeuk Kim | 64aa7ed | 2013-05-20 09:55:50 +0900 | [diff] [blame] | 533 | struct page *get_new_data_page(struct inode *inode, |
Jaegeuk Kim | a886537 | 2013-12-27 17:04:17 +0900 | [diff] [blame] | 534 | struct page *ipage, pgoff_t index, bool new_i_size) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 535 | { |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 536 | struct address_space *mapping = inode->i_mapping; |
| 537 | struct page *page; |
| 538 | struct dnode_of_data dn; |
| 539 | int err; |
Jaegeuk Kim | 7612118 | 2016-01-01 22:03:47 -0800 | [diff] [blame] | 540 | |
Jaegeuk Kim | a56c7c6 | 2015-10-09 15:11:38 -0700 | [diff] [blame] | 541 | page = f2fs_grab_cache_page(mapping, index, true); |
Chao Yu | 470f00e | 2015-07-14 18:14:06 +0800 | [diff] [blame] | 542 | if (!page) { |
| 543 | /* |
| 544 | * before exiting, we should make sure ipage will be released |
| 545 | * if any error occur. |
| 546 | */ |
| 547 | f2fs_put_page(ipage, 1); |
Jaegeuk Kim | 01f2861 | 2015-04-29 11:18:42 -0700 | [diff] [blame] | 548 | return ERR_PTR(-ENOMEM); |
Chao Yu | 470f00e | 2015-07-14 18:14:06 +0800 | [diff] [blame] | 549 | } |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 550 | |
Jaegeuk Kim | a886537 | 2013-12-27 17:04:17 +0900 | [diff] [blame] | 551 | set_new_dnode(&dn, inode, ipage, NULL, 0); |
Huajun Li | b600965 | 2013-11-10 23:13:18 +0800 | [diff] [blame] | 552 | err = f2fs_reserve_block(&dn, index); |
Jaegeuk Kim | 01f2861 | 2015-04-29 11:18:42 -0700 | [diff] [blame] | 553 | if (err) { |
| 554 | f2fs_put_page(page, 1); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 555 | return ERR_PTR(err); |
Jaegeuk Kim | a886537 | 2013-12-27 17:04:17 +0900 | [diff] [blame] | 556 | } |
Jaegeuk Kim | 01f2861 | 2015-04-29 11:18:42 -0700 | [diff] [blame] | 557 | if (!ipage) |
| 558 | f2fs_put_dnode(&dn); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 559 | |
| 560 | if (PageUptodate(page)) |
Jaegeuk Kim | 01f2861 | 2015-04-29 11:18:42 -0700 | [diff] [blame] | 561 | goto got_it; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 562 | |
| 563 | if (dn.data_blkaddr == NEW_ADDR) { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 564 | zero_user_segment(page, 0, PAGE_SIZE); |
Jaegeuk Kim | 237c079 | 2016-06-30 18:49:15 -0700 | [diff] [blame] | 565 | if (!PageUptodate(page)) |
| 566 | SetPageUptodate(page); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 567 | } else { |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 568 | f2fs_put_page(page, 1); |
Jaegeuk Kim | a886537 | 2013-12-27 17:04:17 +0900 | [diff] [blame] | 569 | |
Jaegeuk Kim | 7612118 | 2016-01-01 22:03:47 -0800 | [diff] [blame] | 570 | /* if ipage exists, blkaddr should be NEW_ADDR */ |
| 571 | f2fs_bug_on(F2FS_I_SB(inode), ipage); |
| 572 | page = get_lock_data_page(inode, index, true); |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 573 | if (IS_ERR(page)) |
Jaegeuk Kim | 7612118 | 2016-01-01 22:03:47 -0800 | [diff] [blame] | 574 | return page; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 575 | } |
Jaegeuk Kim | 01f2861 | 2015-04-29 11:18:42 -0700 | [diff] [blame] | 576 | got_it: |
Chao Yu | 9edcdab | 2015-09-11 14:43:52 +0800 | [diff] [blame] | 577 | if (new_i_size && i_size_read(inode) < |
Jaegeuk Kim | ee6d182 | 2016-05-20 16:32:49 -0700 | [diff] [blame] | 578 | ((loff_t)(index + 1) << PAGE_SHIFT)) |
Jaegeuk Kim | fc9581c | 2016-05-20 09:22:03 -0700 | [diff] [blame] | 579 | f2fs_i_size_write(inode, ((loff_t)(index + 1) << PAGE_SHIFT)); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 580 | return page; |
| 581 | } |
| 582 | |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 583 | static int __allocate_data_block(struct dnode_of_data *dn) |
| 584 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 585 | struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 586 | struct f2fs_summary sum; |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 587 | struct node_info ni; |
Jaegeuk Kim | 38aa088 | 2015-01-05 16:02:20 -0800 | [diff] [blame] | 588 | int seg = CURSEG_WARM_DATA; |
Jaegeuk Kim | 976e4c5 | 2014-09-15 19:32:16 -0700 | [diff] [blame] | 589 | pgoff_t fofs; |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 590 | blkcnt_t count = 1; |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 591 | |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 592 | if (unlikely(is_inode_flag_set(dn->inode, FI_NO_ALLOC))) |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 593 | return -EPERM; |
Chao Yu | df6136e | 2015-03-23 10:33:37 +0800 | [diff] [blame] | 594 | |
| 595 | dn->data_blkaddr = datablock_addr(dn->node_page, dn->ofs_in_node); |
| 596 | if (dn->data_blkaddr == NEW_ADDR) |
| 597 | goto alloc; |
| 598 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 599 | if (unlikely(!inc_valid_block_count(sbi, dn->inode, &count))) |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 600 | return -ENOSPC; |
| 601 | |
Chao Yu | df6136e | 2015-03-23 10:33:37 +0800 | [diff] [blame] | 602 | alloc: |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 603 | get_node_info(sbi, dn->nid, &ni); |
| 604 | set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); |
| 605 | |
Jaegeuk Kim | 38aa088 | 2015-01-05 16:02:20 -0800 | [diff] [blame] | 606 | if (dn->ofs_in_node == 0 && dn->inode_page == dn->node_page) |
| 607 | seg = CURSEG_DIRECT_IO; |
| 608 | |
Chao Yu | df6136e | 2015-03-23 10:33:37 +0800 | [diff] [blame] | 609 | allocate_data_block(sbi, NULL, dn->data_blkaddr, &dn->data_blkaddr, |
| 610 | &sum, seg); |
Chao Yu | 216a620 | 2015-03-19 19:23:32 +0800 | [diff] [blame] | 611 | set_data_blkaddr(dn); |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 612 | |
Jaegeuk Kim | 976e4c5 | 2014-09-15 19:32:16 -0700 | [diff] [blame] | 613 | /* update i_size */ |
Chao Yu | 81ca735 | 2016-01-26 15:39:35 +0800 | [diff] [blame] | 614 | fofs = start_bidx_of_node(ofs_of_node(dn->node_page), dn->inode) + |
Jaegeuk Kim | 976e4c5 | 2014-09-15 19:32:16 -0700 | [diff] [blame] | 615 | dn->ofs_in_node; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 616 | if (i_size_read(dn->inode) < ((loff_t)(fofs + 1) << PAGE_SHIFT)) |
Jaegeuk Kim | fc9581c | 2016-05-20 09:22:03 -0700 | [diff] [blame] | 617 | f2fs_i_size_write(dn->inode, |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 618 | ((loff_t)(fofs + 1) << PAGE_SHIFT)); |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 619 | return 0; |
| 620 | } |
| 621 | |
Jaegeuk Kim | b439b10 | 2016-02-03 13:09:09 -0800 | [diff] [blame] | 622 | ssize_t f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) |
Jaegeuk Kim | 59b802e | 2015-02-09 12:09:53 -0800 | [diff] [blame] | 623 | { |
Jaegeuk Kim | b439b10 | 2016-02-03 13:09:09 -0800 | [diff] [blame] | 624 | struct inode *inode = file_inode(iocb->ki_filp); |
Chao Yu | 5b8db7f | 2016-01-26 15:38:29 +0800 | [diff] [blame] | 625 | struct f2fs_map_blocks map; |
Jaegeuk Kim | b439b10 | 2016-02-03 13:09:09 -0800 | [diff] [blame] | 626 | ssize_t ret = 0; |
Jaegeuk Kim | 59b802e | 2015-02-09 12:09:53 -0800 | [diff] [blame] | 627 | |
Jaegeuk Kim | 0080c50 | 2016-05-07 08:52:57 -0700 | [diff] [blame] | 628 | map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos); |
Chao Yu | dfd02e4 | 2016-08-20 15:12:01 +0800 | [diff] [blame] | 629 | map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from)); |
| 630 | if (map.m_len > map.m_lblk) |
| 631 | map.m_len -= map.m_lblk; |
| 632 | else |
| 633 | map.m_len = 0; |
| 634 | |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 635 | map.m_next_pgofs = NULL; |
Jaegeuk Kim | 59b802e | 2015-02-09 12:09:53 -0800 | [diff] [blame] | 636 | |
Jaegeuk Kim | 24b8491 | 2016-02-03 13:49:44 -0800 | [diff] [blame] | 637 | if (f2fs_encrypted_inode(inode)) |
| 638 | return 0; |
| 639 | |
| 640 | if (iocb->ki_flags & IOCB_DIRECT) { |
Jaegeuk Kim | b439b10 | 2016-02-03 13:09:09 -0800 | [diff] [blame] | 641 | ret = f2fs_convert_inline_inode(inode); |
| 642 | if (ret) |
| 643 | return ret; |
Jaegeuk Kim | 24b8491 | 2016-02-03 13:49:44 -0800 | [diff] [blame] | 644 | return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO); |
Jaegeuk Kim | b439b10 | 2016-02-03 13:09:09 -0800 | [diff] [blame] | 645 | } |
Jaegeuk Kim | 24b8491 | 2016-02-03 13:49:44 -0800 | [diff] [blame] | 646 | if (iocb->ki_pos + iov_iter_count(from) > MAX_INLINE_DATA) { |
| 647 | ret = f2fs_convert_inline_inode(inode); |
| 648 | if (ret) |
| 649 | return ret; |
| 650 | } |
| 651 | if (!f2fs_has_inline_data(inode)) |
| 652 | return f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO); |
Jaegeuk Kim | b439b10 | 2016-02-03 13:09:09 -0800 | [diff] [blame] | 653 | return ret; |
Jaegeuk Kim | 59b802e | 2015-02-09 12:09:53 -0800 | [diff] [blame] | 654 | } |
| 655 | |
Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 656 | /* |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 657 | * f2fs_map_blocks() now supported readahead/bmap/rw direct_IO with |
| 658 | * f2fs_map_blocks structure. |
Chao Yu | 4f4124d | 2013-12-21 18:02:14 +0800 | [diff] [blame] | 659 | * If original data blocks are allocated, then give them to blockdev. |
| 660 | * Otherwise, |
| 661 | * a. preallocate requested block addresses |
| 662 | * b. do not use extent cache for better performance |
| 663 | * c. give the block addresses to blockdev |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 664 | */ |
Chao Yu | d323d00 | 2015-10-27 09:53:45 +0800 | [diff] [blame] | 665 | int f2fs_map_blocks(struct inode *inode, struct f2fs_map_blocks *map, |
Chao Yu | e2b4e2b | 2015-08-19 19:11:19 +0800 | [diff] [blame] | 666 | int create, int flag) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 667 | { |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 668 | unsigned int maxblocks = map->m_len; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 669 | struct dnode_of_data dn; |
Chao Yu | f981170 | 2015-09-21 20:17:52 +0800 | [diff] [blame] | 670 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | ac6f199 | 2016-06-16 17:03:23 -0700 | [diff] [blame] | 671 | int mode = create ? ALLOC_NODE : LOOKUP_NODE; |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 672 | pgoff_t pgofs, end_offset, end; |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 673 | int err = 0, ofs = 1; |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 674 | unsigned int ofs_in_node, last_ofs_in_node; |
| 675 | blkcnt_t prealloc; |
Chao Yu | a2e7d1b | 2015-02-05 17:50:30 +0800 | [diff] [blame] | 676 | struct extent_info ei; |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 677 | bool allocated = false; |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 678 | block_t blkaddr; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 679 | |
Chao Yu | dfd02e4 | 2016-08-20 15:12:01 +0800 | [diff] [blame] | 680 | if (!maxblocks) |
| 681 | return 0; |
| 682 | |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 683 | map->m_len = 0; |
| 684 | map->m_flags = 0; |
| 685 | |
| 686 | /* it only supports block size == page size */ |
| 687 | pgofs = (pgoff_t)map->m_lblk; |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 688 | end = pgofs + maxblocks; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 689 | |
Jaegeuk Kim | 24b8491 | 2016-02-03 13:49:44 -0800 | [diff] [blame] | 690 | if (!create && f2fs_lookup_extent_cache(inode, pgofs, &ei)) { |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 691 | map->m_pblk = ei.blk + pgofs - ei.fofs; |
| 692 | map->m_len = min((pgoff_t)maxblocks, ei.fofs + ei.len - pgofs); |
| 693 | map->m_flags = F2FS_MAP_MAPPED; |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 694 | goto out; |
Chao Yu | a2e7d1b | 2015-02-05 17:50:30 +0800 | [diff] [blame] | 695 | } |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 696 | |
Chao Yu | 4fe71e8 | 2016-01-26 15:37:38 +0800 | [diff] [blame] | 697 | next_dnode: |
Jaegeuk Kim | 59b802e | 2015-02-09 12:09:53 -0800 | [diff] [blame] | 698 | if (create) |
Chao Yu | 3104af3 | 2015-12-23 17:11:43 +0800 | [diff] [blame] | 699 | f2fs_lock_op(sbi); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 700 | |
| 701 | /* When reading holes, we need its node page */ |
| 702 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 703 | err = get_dnode_of_data(&dn, pgofs, mode); |
Jaegeuk Kim | 1ec7908 | 2013-12-26 16:55:22 +0900 | [diff] [blame] | 704 | if (err) { |
Chao Yu | 43473f9 | 2016-05-05 19:13:02 +0800 | [diff] [blame] | 705 | if (flag == F2FS_GET_BLOCK_BMAP) |
| 706 | map->m_pblk = 0; |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 707 | if (err == -ENOENT) { |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 708 | err = 0; |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 709 | if (map->m_next_pgofs) |
| 710 | *map->m_next_pgofs = |
| 711 | get_next_page_offset(&dn, pgofs); |
| 712 | } |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 713 | goto unlock_out; |
Namjae Jeon | 848753a | 2013-04-23 16:38:02 +0900 | [diff] [blame] | 714 | } |
Chao Yu | 973163f | 2015-09-18 16:51:51 +0800 | [diff] [blame] | 715 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 716 | prealloc = 0; |
| 717 | ofs_in_node = dn.ofs_in_node; |
Chao Yu | 81ca735 | 2016-01-26 15:39:35 +0800 | [diff] [blame] | 718 | end_offset = ADDRS_PER_PAGE(dn.node_page, inode); |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 719 | |
Chao Yu | 4fe71e8 | 2016-01-26 15:37:38 +0800 | [diff] [blame] | 720 | next_block: |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 721 | blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node); |
Chao Yu | 973163f | 2015-09-18 16:51:51 +0800 | [diff] [blame] | 722 | |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 723 | if (blkaddr == NEW_ADDR || blkaddr == NULL_ADDR) { |
| 724 | if (create) { |
| 725 | if (unlikely(f2fs_cp_error(sbi))) { |
| 726 | err = -EIO; |
| 727 | goto sync_out; |
Chao Yu | 973163f | 2015-09-18 16:51:51 +0800 | [diff] [blame] | 728 | } |
Jaegeuk Kim | 24b8491 | 2016-02-03 13:49:44 -0800 | [diff] [blame] | 729 | if (flag == F2FS_GET_BLOCK_PRE_AIO) { |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 730 | if (blkaddr == NULL_ADDR) { |
| 731 | prealloc++; |
| 732 | last_ofs_in_node = dn.ofs_in_node; |
| 733 | } |
Jaegeuk Kim | 24b8491 | 2016-02-03 13:49:44 -0800 | [diff] [blame] | 734 | } else { |
| 735 | err = __allocate_data_block(&dn); |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 736 | if (!err) { |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 737 | set_inode_flag(inode, FI_APPEND_WRITE); |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 738 | allocated = true; |
| 739 | } |
Jaegeuk Kim | 24b8491 | 2016-02-03 13:49:44 -0800 | [diff] [blame] | 740 | } |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 741 | if (err) |
| 742 | goto sync_out; |
Chao Yu | 4fe71e8 | 2016-01-26 15:37:38 +0800 | [diff] [blame] | 743 | map->m_flags = F2FS_MAP_NEW; |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 744 | blkaddr = dn.data_blkaddr; |
| 745 | } else { |
Chao Yu | 43473f9 | 2016-05-05 19:13:02 +0800 | [diff] [blame] | 746 | if (flag == F2FS_GET_BLOCK_BMAP) { |
| 747 | map->m_pblk = 0; |
| 748 | goto sync_out; |
| 749 | } |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 750 | if (flag == F2FS_GET_BLOCK_FIEMAP && |
| 751 | blkaddr == NULL_ADDR) { |
| 752 | if (map->m_next_pgofs) |
| 753 | *map->m_next_pgofs = pgofs + 1; |
| 754 | } |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 755 | if (flag != F2FS_GET_BLOCK_FIEMAP || |
Chao Yu | 43473f9 | 2016-05-05 19:13:02 +0800 | [diff] [blame] | 756 | blkaddr != NEW_ADDR) |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 757 | goto sync_out; |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 758 | } |
| 759 | } |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 760 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 761 | if (flag == F2FS_GET_BLOCK_PRE_AIO) |
| 762 | goto skip; |
| 763 | |
Chao Yu | 4fe71e8 | 2016-01-26 15:37:38 +0800 | [diff] [blame] | 764 | if (map->m_len == 0) { |
| 765 | /* preallocated unwritten block should be mapped for fiemap. */ |
| 766 | if (blkaddr == NEW_ADDR) |
| 767 | map->m_flags |= F2FS_MAP_UNWRITTEN; |
| 768 | map->m_flags |= F2FS_MAP_MAPPED; |
| 769 | |
| 770 | map->m_pblk = blkaddr; |
| 771 | map->m_len = 1; |
| 772 | } else if ((map->m_pblk != NEW_ADDR && |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 773 | blkaddr == (map->m_pblk + ofs)) || |
Jaegeuk Kim | b439b10 | 2016-02-03 13:09:09 -0800 | [diff] [blame] | 774 | (map->m_pblk == NEW_ADDR && blkaddr == NEW_ADDR) || |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 775 | flag == F2FS_GET_BLOCK_PRE_DIO) { |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 776 | ofs++; |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 777 | map->m_len++; |
Chao Yu | 4fe71e8 | 2016-01-26 15:37:38 +0800 | [diff] [blame] | 778 | } else { |
| 779 | goto sync_out; |
| 780 | } |
| 781 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 782 | skip: |
Chao Yu | 4fe71e8 | 2016-01-26 15:37:38 +0800 | [diff] [blame] | 783 | dn.ofs_in_node++; |
| 784 | pgofs++; |
| 785 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 786 | /* preallocate blocks in batch for one dnode page */ |
| 787 | if (flag == F2FS_GET_BLOCK_PRE_AIO && |
| 788 | (pgofs == end || dn.ofs_in_node == end_offset)) { |
Chao Yu | 4fe71e8 | 2016-01-26 15:37:38 +0800 | [diff] [blame] | 789 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 790 | dn.ofs_in_node = ofs_in_node; |
| 791 | err = reserve_new_blocks(&dn, prealloc); |
| 792 | if (err) |
| 793 | goto sync_out; |
Chao Yu | 58383be | 2016-08-20 15:12:02 +0800 | [diff] [blame] | 794 | allocated = dn.node_changed; |
Chao Yu | 4fe71e8 | 2016-01-26 15:37:38 +0800 | [diff] [blame] | 795 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 796 | map->m_len += dn.ofs_in_node - ofs_in_node; |
| 797 | if (prealloc && dn.ofs_in_node != last_ofs_in_node + 1) { |
| 798 | err = -ENOSPC; |
| 799 | goto sync_out; |
Chao Yu | 4fe71e8 | 2016-01-26 15:37:38 +0800 | [diff] [blame] | 800 | } |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 801 | dn.ofs_in_node = end_offset; |
Fan Li | 7df3a43 | 2015-12-17 13:20:59 +0800 | [diff] [blame] | 802 | } |
| 803 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 804 | if (pgofs >= end) |
| 805 | goto sync_out; |
| 806 | else if (dn.ofs_in_node < end_offset) |
| 807 | goto next_block; |
| 808 | |
Chao Yu | 46008c6 | 2016-05-09 19:56:30 +0800 | [diff] [blame] | 809 | f2fs_put_dnode(&dn); |
| 810 | |
| 811 | if (create) { |
| 812 | f2fs_unlock_op(sbi); |
| 813 | f2fs_balance_fs(sbi, allocated); |
| 814 | } |
| 815 | allocated = false; |
| 816 | goto next_dnode; |
| 817 | |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 818 | sync_out: |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 819 | f2fs_put_dnode(&dn); |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 820 | unlock_out: |
Jaegeuk Kim | 2a34076 | 2015-12-22 13:23:35 -0800 | [diff] [blame] | 821 | if (create) { |
Chao Yu | 3104af3 | 2015-12-23 17:11:43 +0800 | [diff] [blame] | 822 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 3c082b7 | 2016-01-23 13:35:18 -0800 | [diff] [blame] | 823 | f2fs_balance_fs(sbi, allocated); |
Jaegeuk Kim | 2a34076 | 2015-12-22 13:23:35 -0800 | [diff] [blame] | 824 | } |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 825 | out: |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 826 | trace_f2fs_map_blocks(inode, map, err); |
Jaegeuk Kim | bfad7c2 | 2013-12-16 19:04:05 +0900 | [diff] [blame] | 827 | return err; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 828 | } |
| 829 | |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 830 | static int __get_data_block(struct inode *inode, sector_t iblock, |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 831 | struct buffer_head *bh, int create, int flag, |
| 832 | pgoff_t *next_pgofs) |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 833 | { |
| 834 | struct f2fs_map_blocks map; |
| 835 | int ret; |
| 836 | |
| 837 | map.m_lblk = iblock; |
| 838 | map.m_len = bh->b_size >> inode->i_blkbits; |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 839 | map.m_next_pgofs = next_pgofs; |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 840 | |
Chao Yu | e2b4e2b | 2015-08-19 19:11:19 +0800 | [diff] [blame] | 841 | ret = f2fs_map_blocks(inode, &map, create, flag); |
Jaegeuk Kim | 003a3e1 | 2015-04-06 19:55:34 -0700 | [diff] [blame] | 842 | if (!ret) { |
| 843 | map_bh(bh, inode->i_sb, map.m_pblk); |
| 844 | bh->b_state = (bh->b_state & ~F2FS_MAP_FLAGS) | map.m_flags; |
| 845 | bh->b_size = map.m_len << inode->i_blkbits; |
| 846 | } |
| 847 | return ret; |
| 848 | } |
| 849 | |
Jaegeuk Kim | ccfb300 | 2014-06-13 13:02:11 +0900 | [diff] [blame] | 850 | static int get_data_block(struct inode *inode, sector_t iblock, |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 851 | struct buffer_head *bh_result, int create, int flag, |
| 852 | pgoff_t *next_pgofs) |
Jaegeuk Kim | ccfb300 | 2014-06-13 13:02:11 +0900 | [diff] [blame] | 853 | { |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 854 | return __get_data_block(inode, iblock, bh_result, create, |
| 855 | flag, next_pgofs); |
Jaegeuk Kim | ccfb300 | 2014-06-13 13:02:11 +0900 | [diff] [blame] | 856 | } |
| 857 | |
Chao Yu | e2b4e2b | 2015-08-19 19:11:19 +0800 | [diff] [blame] | 858 | static int get_data_block_dio(struct inode *inode, sector_t iblock, |
Jaegeuk Kim | ccfb300 | 2014-06-13 13:02:11 +0900 | [diff] [blame] | 859 | struct buffer_head *bh_result, int create) |
| 860 | { |
Chao Yu | e2b4e2b | 2015-08-19 19:11:19 +0800 | [diff] [blame] | 861 | return __get_data_block(inode, iblock, bh_result, create, |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 862 | F2FS_GET_BLOCK_DIO, NULL); |
Chao Yu | e2b4e2b | 2015-08-19 19:11:19 +0800 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | static int get_data_block_bmap(struct inode *inode, sector_t iblock, |
| 866 | struct buffer_head *bh_result, int create) |
| 867 | { |
Yunlei He | 179448b | 2015-12-28 21:48:32 +0800 | [diff] [blame] | 868 | /* Block number less than F2FS MAX BLOCKS */ |
Chao Yu | e0afc4d | 2015-12-31 14:35:37 +0800 | [diff] [blame] | 869 | if (unlikely(iblock >= F2FS_I_SB(inode)->max_file_blocks)) |
Yunlei He | 179448b | 2015-12-28 21:48:32 +0800 | [diff] [blame] | 870 | return -EFBIG; |
| 871 | |
Chao Yu | e2b4e2b | 2015-08-19 19:11:19 +0800 | [diff] [blame] | 872 | return __get_data_block(inode, iblock, bh_result, create, |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 873 | F2FS_GET_BLOCK_BMAP, NULL); |
Jaegeuk Kim | ccfb300 | 2014-06-13 13:02:11 +0900 | [diff] [blame] | 874 | } |
| 875 | |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 876 | static inline sector_t logical_to_blk(struct inode *inode, loff_t offset) |
| 877 | { |
| 878 | return (offset >> inode->i_blkbits); |
| 879 | } |
| 880 | |
| 881 | static inline loff_t blk_to_logical(struct inode *inode, sector_t blk) |
| 882 | { |
| 883 | return (blk << inode->i_blkbits); |
| 884 | } |
| 885 | |
Jaegeuk Kim | 9ab7013 | 2014-06-08 04:30:14 +0900 | [diff] [blame] | 886 | int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
| 887 | u64 start, u64 len) |
| 888 | { |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 889 | struct buffer_head map_bh; |
| 890 | sector_t start_blk, last_blk; |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 891 | pgoff_t next_pgofs; |
Fan Li | de1475c | 2016-01-04 15:56:50 +0800 | [diff] [blame] | 892 | loff_t isize; |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 893 | u64 logical = 0, phys = 0, size = 0; |
| 894 | u32 flags = 0; |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 895 | int ret = 0; |
| 896 | |
| 897 | ret = fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC); |
| 898 | if (ret) |
| 899 | return ret; |
| 900 | |
Jaegeuk Kim | 67f8cf3 | 2015-10-15 11:34:49 -0700 | [diff] [blame] | 901 | if (f2fs_has_inline_data(inode)) { |
| 902 | ret = f2fs_inline_data_fiemap(inode, fieinfo, start, len); |
| 903 | if (ret != -EAGAIN) |
| 904 | return ret; |
| 905 | } |
| 906 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 907 | inode_lock(inode); |
Fan Li | de1475c | 2016-01-04 15:56:50 +0800 | [diff] [blame] | 908 | |
| 909 | isize = i_size_read(inode); |
Fan Li | 9a950d5 | 2015-12-26 18:07:41 +0800 | [diff] [blame] | 910 | if (start >= isize) |
| 911 | goto out; |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 912 | |
Fan Li | 9a950d5 | 2015-12-26 18:07:41 +0800 | [diff] [blame] | 913 | if (start + len > isize) |
| 914 | len = isize - start; |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 915 | |
| 916 | if (logical_to_blk(inode, len) == 0) |
| 917 | len = blk_to_logical(inode, 1); |
| 918 | |
| 919 | start_blk = logical_to_blk(inode, start); |
| 920 | last_blk = logical_to_blk(inode, start + len - 1); |
Fan Li | 9a950d5 | 2015-12-26 18:07:41 +0800 | [diff] [blame] | 921 | |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 922 | next: |
| 923 | memset(&map_bh, 0, sizeof(struct buffer_head)); |
| 924 | map_bh.b_size = len; |
| 925 | |
Chao Yu | e2b4e2b | 2015-08-19 19:11:19 +0800 | [diff] [blame] | 926 | ret = get_data_block(inode, start_blk, &map_bh, 0, |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 927 | F2FS_GET_BLOCK_FIEMAP, &next_pgofs); |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 928 | if (ret) |
| 929 | goto out; |
| 930 | |
| 931 | /* HOLE */ |
| 932 | if (!buffer_mapped(&map_bh)) { |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 933 | start_blk = next_pgofs; |
Fan Li | 9a950d5 | 2015-12-26 18:07:41 +0800 | [diff] [blame] | 934 | /* Go through holes util pass the EOF */ |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 935 | if (blk_to_logical(inode, start_blk) < isize) |
Fan Li | 9a950d5 | 2015-12-26 18:07:41 +0800 | [diff] [blame] | 936 | goto prep_next; |
| 937 | /* Found a hole beyond isize means no more extents. |
| 938 | * Note that the premise is that filesystems don't |
| 939 | * punch holes beyond isize and keep size unchanged. |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 940 | */ |
Fan Li | 9a950d5 | 2015-12-26 18:07:41 +0800 | [diff] [blame] | 941 | flags |= FIEMAP_EXTENT_LAST; |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 942 | } |
Fan Li | 9a950d5 | 2015-12-26 18:07:41 +0800 | [diff] [blame] | 943 | |
Chao Yu | da5af12 | 2016-01-08 20:19:27 +0800 | [diff] [blame] | 944 | if (size) { |
| 945 | if (f2fs_encrypted_inode(inode)) |
| 946 | flags |= FIEMAP_EXTENT_DATA_ENCRYPTED; |
| 947 | |
Fan Li | 9a950d5 | 2015-12-26 18:07:41 +0800 | [diff] [blame] | 948 | ret = fiemap_fill_next_extent(fieinfo, logical, |
| 949 | phys, size, flags); |
Chao Yu | da5af12 | 2016-01-08 20:19:27 +0800 | [diff] [blame] | 950 | } |
Fan Li | 9a950d5 | 2015-12-26 18:07:41 +0800 | [diff] [blame] | 951 | |
| 952 | if (start_blk > last_blk || ret) |
| 953 | goto out; |
| 954 | |
| 955 | logical = blk_to_logical(inode, start_blk); |
| 956 | phys = blk_to_logical(inode, map_bh.b_blocknr); |
| 957 | size = map_bh.b_size; |
| 958 | flags = 0; |
| 959 | if (buffer_unwritten(&map_bh)) |
| 960 | flags = FIEMAP_EXTENT_UNWRITTEN; |
| 961 | |
| 962 | start_blk += logical_to_blk(inode, size); |
| 963 | |
| 964 | prep_next: |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 965 | cond_resched(); |
| 966 | if (fatal_signal_pending(current)) |
| 967 | ret = -EINTR; |
| 968 | else |
| 969 | goto next; |
| 970 | out: |
| 971 | if (ret == 1) |
| 972 | ret = 0; |
| 973 | |
Al Viro | 5955102 | 2016-01-22 15:40:57 -0500 | [diff] [blame] | 974 | inode_unlock(inode); |
Jaegeuk Kim | 7f63eb7 | 2015-05-08 19:30:32 -0700 | [diff] [blame] | 975 | return ret; |
Jaegeuk Kim | 9ab7013 | 2014-06-08 04:30:14 +0900 | [diff] [blame] | 976 | } |
| 977 | |
Wei Yongjun | 6a7a3ae | 2016-08-23 15:23:59 +0000 | [diff] [blame] | 978 | static struct bio *f2fs_grab_bio(struct inode *inode, block_t blkaddr, |
| 979 | unsigned nr_pages) |
Chao Yu | 78682f7 | 2016-07-03 22:05:11 +0800 | [diff] [blame] | 980 | { |
| 981 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 982 | struct fscrypt_ctx *ctx = NULL; |
| 983 | struct block_device *bdev = sbi->sb->s_bdev; |
| 984 | struct bio *bio; |
| 985 | |
| 986 | if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) { |
| 987 | ctx = fscrypt_get_ctx(inode, GFP_NOFS); |
| 988 | if (IS_ERR(ctx)) |
| 989 | return ERR_CAST(ctx); |
| 990 | |
| 991 | /* wait the page to be moved by cleaning */ |
| 992 | f2fs_wait_on_encrypted_page_writeback(sbi, blkaddr); |
| 993 | } |
| 994 | |
| 995 | bio = bio_alloc(GFP_KERNEL, min_t(int, nr_pages, BIO_MAX_PAGES)); |
| 996 | if (!bio) { |
| 997 | if (ctx) |
| 998 | fscrypt_release_ctx(ctx); |
| 999 | return ERR_PTR(-ENOMEM); |
| 1000 | } |
| 1001 | bio->bi_bdev = bdev; |
| 1002 | bio->bi_iter.bi_sector = SECTOR_FROM_BLOCK(blkaddr); |
| 1003 | bio->bi_end_io = f2fs_read_end_io; |
| 1004 | bio->bi_private = ctx; |
| 1005 | |
| 1006 | return bio; |
| 1007 | } |
| 1008 | |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1009 | /* |
| 1010 | * This function was originally taken from fs/mpage.c, and customized for f2fs. |
| 1011 | * Major change was from block_size == page_size in f2fs by default. |
| 1012 | */ |
| 1013 | static int f2fs_mpage_readpages(struct address_space *mapping, |
| 1014 | struct list_head *pages, struct page *page, |
| 1015 | unsigned nr_pages) |
| 1016 | { |
| 1017 | struct bio *bio = NULL; |
| 1018 | unsigned page_idx; |
| 1019 | sector_t last_block_in_bio = 0; |
| 1020 | struct inode *inode = mapping->host; |
| 1021 | const unsigned blkbits = inode->i_blkbits; |
| 1022 | const unsigned blocksize = 1 << blkbits; |
| 1023 | sector_t block_in_file; |
| 1024 | sector_t last_block; |
| 1025 | sector_t last_block_in_file; |
| 1026 | sector_t block_nr; |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1027 | struct f2fs_map_blocks map; |
| 1028 | |
| 1029 | map.m_pblk = 0; |
| 1030 | map.m_lblk = 0; |
| 1031 | map.m_len = 0; |
| 1032 | map.m_flags = 0; |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 1033 | map.m_next_pgofs = NULL; |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1034 | |
| 1035 | for (page_idx = 0; nr_pages; page_idx++, nr_pages--) { |
| 1036 | |
| 1037 | prefetchw(&page->flags); |
| 1038 | if (pages) { |
| 1039 | page = list_entry(pages->prev, struct page, lru); |
| 1040 | list_del(&page->lru); |
| 1041 | if (add_to_page_cache_lru(page, mapping, |
Michal Hocko | 8a5c743 | 2016-07-26 15:24:53 -0700 | [diff] [blame] | 1042 | page->index, |
| 1043 | readahead_gfp_mask(mapping))) |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1044 | goto next_page; |
| 1045 | } |
| 1046 | |
| 1047 | block_in_file = (sector_t)page->index; |
| 1048 | last_block = block_in_file + nr_pages; |
| 1049 | last_block_in_file = (i_size_read(inode) + blocksize - 1) >> |
| 1050 | blkbits; |
| 1051 | if (last_block > last_block_in_file) |
| 1052 | last_block = last_block_in_file; |
| 1053 | |
| 1054 | /* |
| 1055 | * Map blocks using the previous result first. |
| 1056 | */ |
| 1057 | if ((map.m_flags & F2FS_MAP_MAPPED) && |
| 1058 | block_in_file > map.m_lblk && |
| 1059 | block_in_file < (map.m_lblk + map.m_len)) |
| 1060 | goto got_it; |
| 1061 | |
| 1062 | /* |
| 1063 | * Then do more f2fs_map_blocks() calls until we are |
| 1064 | * done with this page. |
| 1065 | */ |
| 1066 | map.m_flags = 0; |
| 1067 | |
| 1068 | if (block_in_file < last_block) { |
| 1069 | map.m_lblk = block_in_file; |
| 1070 | map.m_len = last_block - block_in_file; |
| 1071 | |
Chao Yu | 46c9e14 | 2015-09-18 16:54:16 +0800 | [diff] [blame] | 1072 | if (f2fs_map_blocks(inode, &map, 0, |
Chao Yu | da85985 | 2016-01-26 15:42:58 +0800 | [diff] [blame] | 1073 | F2FS_GET_BLOCK_READ)) |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1074 | goto set_error_page; |
| 1075 | } |
| 1076 | got_it: |
| 1077 | if ((map.m_flags & F2FS_MAP_MAPPED)) { |
| 1078 | block_nr = map.m_pblk + block_in_file - map.m_lblk; |
| 1079 | SetPageMappedToDisk(page); |
| 1080 | |
| 1081 | if (!PageUptodate(page) && !cleancache_get_page(page)) { |
| 1082 | SetPageUptodate(page); |
| 1083 | goto confused; |
| 1084 | } |
| 1085 | } else { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1086 | zero_user_segment(page, 0, PAGE_SIZE); |
Jaegeuk Kim | 237c079 | 2016-06-30 18:49:15 -0700 | [diff] [blame] | 1087 | if (!PageUptodate(page)) |
| 1088 | SetPageUptodate(page); |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1089 | unlock_page(page); |
| 1090 | goto next_page; |
| 1091 | } |
| 1092 | |
| 1093 | /* |
| 1094 | * This page will go to BIO. Do we need to send this |
| 1095 | * BIO off first? |
| 1096 | */ |
| 1097 | if (bio && (last_block_in_bio != block_nr - 1)) { |
| 1098 | submit_and_realloc: |
Linus Torvalds | 4fc29c1 | 2016-07-27 10:36:31 -0700 | [diff] [blame] | 1099 | __submit_bio(F2FS_I_SB(inode), bio, DATA); |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1100 | bio = NULL; |
| 1101 | } |
| 1102 | if (bio == NULL) { |
Chao Yu | 78682f7 | 2016-07-03 22:05:11 +0800 | [diff] [blame] | 1103 | bio = f2fs_grab_bio(inode, block_nr, nr_pages); |
Jaegeuk Kim | 1d353eb | 2016-07-12 09:38:48 -0700 | [diff] [blame] | 1104 | if (IS_ERR(bio)) { |
| 1105 | bio = NULL; |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1106 | goto set_error_page; |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 1107 | } |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 1108 | bio_set_op_attrs(bio, REQ_OP_READ, 0); |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | if (bio_add_page(bio, page, blocksize, 0) < blocksize) |
| 1112 | goto submit_and_realloc; |
| 1113 | |
| 1114 | last_block_in_bio = block_nr; |
| 1115 | goto next_page; |
| 1116 | set_error_page: |
| 1117 | SetPageError(page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1118 | zero_user_segment(page, 0, PAGE_SIZE); |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1119 | unlock_page(page); |
| 1120 | goto next_page; |
| 1121 | confused: |
| 1122 | if (bio) { |
Linus Torvalds | 4fc29c1 | 2016-07-27 10:36:31 -0700 | [diff] [blame] | 1123 | __submit_bio(F2FS_I_SB(inode), bio, DATA); |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1124 | bio = NULL; |
| 1125 | } |
| 1126 | unlock_page(page); |
| 1127 | next_page: |
| 1128 | if (pages) |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1129 | put_page(page); |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1130 | } |
| 1131 | BUG_ON(pages && !list_empty(pages)); |
| 1132 | if (bio) |
Linus Torvalds | 4fc29c1 | 2016-07-27 10:36:31 -0700 | [diff] [blame] | 1133 | __submit_bio(F2FS_I_SB(inode), bio, DATA); |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1134 | return 0; |
| 1135 | } |
| 1136 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1137 | static int f2fs_read_data_page(struct file *file, struct page *page) |
| 1138 | { |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 1139 | struct inode *inode = page->mapping->host; |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 1140 | int ret = -EAGAIN; |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 1141 | |
Chao Yu | c20e89c | 2014-05-06 16:53:08 +0800 | [diff] [blame] | 1142 | trace_f2fs_readpage(page, DATA); |
| 1143 | |
arter97 | e1c4204 | 2014-08-06 23:22:50 +0900 | [diff] [blame] | 1144 | /* If the file has inline data, try to read it directly */ |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 1145 | if (f2fs_has_inline_data(inode)) |
| 1146 | ret = f2fs_read_inline_data(inode, page); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 1147 | if (ret == -EAGAIN) |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1148 | ret = f2fs_mpage_readpages(page->mapping, NULL, page, 1); |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 1149 | return ret; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | static int f2fs_read_data_pages(struct file *file, |
| 1153 | struct address_space *mapping, |
| 1154 | struct list_head *pages, unsigned nr_pages) |
| 1155 | { |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 1156 | struct inode *inode = file->f_mapping->host; |
Chao Yu | b8c2940 | 2015-10-12 17:02:26 +0800 | [diff] [blame] | 1157 | struct page *page = list_entry(pages->prev, struct page, lru); |
| 1158 | |
| 1159 | trace_f2fs_readpages(inode, page, nr_pages); |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 1160 | |
| 1161 | /* If the file has inline data, skip readpages */ |
| 1162 | if (f2fs_has_inline_data(inode)) |
| 1163 | return 0; |
| 1164 | |
Jaegeuk Kim | f1e8866 | 2015-04-09 11:20:42 -0700 | [diff] [blame] | 1165 | return f2fs_mpage_readpages(mapping, pages, NULL, nr_pages); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1166 | } |
| 1167 | |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 1168 | int do_write_data_page(struct f2fs_io_info *fio) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1169 | { |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 1170 | struct page *page = fio->page; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1171 | struct inode *inode = page->mapping->host; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1172 | struct dnode_of_data dn; |
| 1173 | int err = 0; |
| 1174 | |
| 1175 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
Jaegeuk Kim | 266e97a | 2013-02-26 13:10:46 +0900 | [diff] [blame] | 1176 | err = get_dnode_of_data(&dn, page->index, LOOKUP_NODE); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1177 | if (err) |
| 1178 | return err; |
| 1179 | |
Chao Yu | 28bc106 | 2016-02-06 14:40:34 +0800 | [diff] [blame] | 1180 | fio->old_blkaddr = dn.data_blkaddr; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1181 | |
| 1182 | /* This page is already truncated */ |
Chao Yu | 7a9d754 | 2016-02-22 18:36:38 +0800 | [diff] [blame] | 1183 | if (fio->old_blkaddr == NULL_ADDR) { |
Jaegeuk Kim | 2bca1e2 | 2015-02-25 19:25:01 -0800 | [diff] [blame] | 1184 | ClearPageUptodate(page); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1185 | goto out_writepage; |
Jaegeuk Kim | 2bca1e2 | 2015-02-25 19:25:01 -0800 | [diff] [blame] | 1186 | } |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1187 | |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 1188 | if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) { |
Jaegeuk Kim | b32e4482 | 2016-04-11 15:51:57 -0700 | [diff] [blame] | 1189 | gfp_t gfp_flags = GFP_NOFS; |
Chao Yu | 08b39fb | 2015-10-08 13:27:34 +0800 | [diff] [blame] | 1190 | |
| 1191 | /* wait for GCed encrypted page writeback */ |
| 1192 | f2fs_wait_on_encrypted_page_writeback(F2FS_I_SB(inode), |
Chao Yu | 7a9d754 | 2016-02-22 18:36:38 +0800 | [diff] [blame] | 1193 | fio->old_blkaddr); |
Jaegeuk Kim | b32e4482 | 2016-04-11 15:51:57 -0700 | [diff] [blame] | 1194 | retry_encrypt: |
| 1195 | fio->encrypted_page = fscrypt_encrypt_page(inode, fio->page, |
| 1196 | gfp_flags); |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 1197 | if (IS_ERR(fio->encrypted_page)) { |
| 1198 | err = PTR_ERR(fio->encrypted_page); |
Jaegeuk Kim | b32e4482 | 2016-04-11 15:51:57 -0700 | [diff] [blame] | 1199 | if (err == -ENOMEM) { |
| 1200 | /* flush pending ios and wait for a while */ |
| 1201 | f2fs_flush_merged_bios(F2FS_I_SB(inode)); |
| 1202 | congestion_wait(BLK_RW_ASYNC, HZ/50); |
| 1203 | gfp_flags |= __GFP_NOFAIL; |
| 1204 | err = 0; |
| 1205 | goto retry_encrypt; |
| 1206 | } |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 1207 | goto out_writepage; |
| 1208 | } |
| 1209 | } |
| 1210 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1211 | set_page_writeback(page); |
| 1212 | |
| 1213 | /* |
| 1214 | * If current allocation needs SSR, |
| 1215 | * it had better in-place writes for updated data. |
| 1216 | */ |
Chao Yu | 7a9d754 | 2016-02-22 18:36:38 +0800 | [diff] [blame] | 1217 | if (unlikely(fio->old_blkaddr != NEW_ADDR && |
Haicheng Li | b25958b | 2013-06-13 16:59:29 +0800 | [diff] [blame] | 1218 | !is_cold_data(page) && |
Chao Yu | 2da3e027 | 2015-10-28 17:56:14 +0800 | [diff] [blame] | 1219 | !IS_ATOMIC_WRITTEN_PAGE(page) && |
Haicheng Li | b25958b | 2013-06-13 16:59:29 +0800 | [diff] [blame] | 1220 | need_inplace_update(inode))) { |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 1221 | rewrite_data_page(fio); |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 1222 | set_inode_flag(inode, FI_UPDATE_WRITE); |
Jaegeuk Kim | 8ce67cb | 2015-03-17 17:58:08 -0700 | [diff] [blame] | 1223 | trace_f2fs_do_write_data_page(page, IPU); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1224 | } else { |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 1225 | write_data_page(&dn, fio); |
Jaegeuk Kim | 8ce67cb | 2015-03-17 17:58:08 -0700 | [diff] [blame] | 1226 | trace_f2fs_do_write_data_page(page, OPU); |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 1227 | set_inode_flag(inode, FI_APPEND_WRITE); |
Jaegeuk Kim | 3c6c2be | 2015-03-17 17:16:35 -0700 | [diff] [blame] | 1228 | if (page->index == 0) |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 1229 | set_inode_flag(inode, FI_FIRST_BLOCK_WRITTEN); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1230 | } |
| 1231 | out_writepage: |
| 1232 | f2fs_put_dnode(&dn); |
| 1233 | return err; |
| 1234 | } |
| 1235 | |
| 1236 | static int f2fs_write_data_page(struct page *page, |
| 1237 | struct writeback_control *wbc) |
| 1238 | { |
| 1239 | struct inode *inode = page->mapping->host; |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 1240 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1241 | loff_t i_size = i_size_read(inode); |
| 1242 | const pgoff_t end_index = ((unsigned long long) i_size) |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1243 | >> PAGE_SHIFT; |
Jaegeuk Kim | 26de9b1 | 2016-05-20 20:42:37 -0700 | [diff] [blame] | 1244 | loff_t psize = (page->index + 1) << PAGE_SHIFT; |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 1245 | unsigned offset = 0; |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1246 | bool need_balance_fs = false; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1247 | int err = 0; |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 1248 | struct f2fs_io_info fio = { |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 1249 | .sbi = sbi, |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 1250 | .type = DATA, |
Mike Christie | 04d328d | 2016-06-05 14:31:55 -0500 | [diff] [blame] | 1251 | .op = REQ_OP_WRITE, |
| 1252 | .op_flags = (wbc->sync_mode == WB_SYNC_ALL) ? WRITE_SYNC : 0, |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 1253 | .page = page, |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 1254 | .encrypted_page = NULL, |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 1255 | }; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1256 | |
Chao Yu | ecda0de | 2014-05-06 16:48:26 +0800 | [diff] [blame] | 1257 | trace_f2fs_writepage(page, DATA); |
| 1258 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1259 | if (page->index < end_index) |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1260 | goto write; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1261 | |
| 1262 | /* |
| 1263 | * If the offset is out-of-range of file size, |
| 1264 | * this page does not have to be written to disk. |
| 1265 | */ |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1266 | offset = i_size & (PAGE_SIZE - 1); |
Jaegeuk Kim | 76f6026 | 2014-04-15 16:04:15 +0900 | [diff] [blame] | 1267 | if ((page->index >= end_index + 1) || !offset) |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1268 | goto out; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1269 | |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1270 | zero_user_segment(page, offset, PAGE_SIZE); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1271 | write: |
Chao Yu | caf0047 | 2015-01-28 17:48:42 +0800 | [diff] [blame] | 1272 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1273 | goto redirty_out; |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 1274 | if (f2fs_is_drop_cache(inode)) |
| 1275 | goto out; |
Jaegeuk Kim | e6e5f56 | 2016-04-14 16:48:52 -0700 | [diff] [blame] | 1276 | /* we should not write 0'th page having journal header */ |
| 1277 | if (f2fs_is_volatile_file(inode) && (!page->index || |
| 1278 | (!wbc->for_reclaim && |
| 1279 | available_free_memory(sbi, BASE_CHECK)))) |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 1280 | goto redirty_out; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1281 | |
Jaegeuk Kim | cf779ca | 2014-08-11 18:37:46 -0700 | [diff] [blame] | 1282 | /* we should bypass data pages to proceed the kworkder jobs */ |
| 1283 | if (unlikely(f2fs_cp_error(sbi))) { |
Jaegeuk Kim | 7f31997 | 2016-06-03 12:28:26 -0700 | [diff] [blame] | 1284 | mapping_set_error(page->mapping, -EIO); |
Jaegeuk Kim | a7ffdbe | 2014-09-12 15:53:45 -0700 | [diff] [blame] | 1285 | goto out; |
Jaegeuk Kim | cf779ca | 2014-08-11 18:37:46 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Jaegeuk Kim | b230e6c | 2016-05-29 21:18:23 -0700 | [diff] [blame] | 1288 | /* Dentry blocks are controlled by checkpoint */ |
| 1289 | if (S_ISDIR(inode->i_mode)) { |
| 1290 | err = do_write_data_page(&fio); |
| 1291 | goto done; |
| 1292 | } |
| 1293 | |
Jaegeuk Kim | 8618b88 | 2014-02-17 19:29:27 +0900 | [diff] [blame] | 1294 | if (!wbc->for_reclaim) |
| 1295 | need_balance_fs = true; |
Jaegeuk Kim | 7f3037a | 2016-09-01 12:02:51 -0700 | [diff] [blame] | 1296 | else if (has_not_enough_free_secs(sbi, 0, 0)) |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1297 | goto redirty_out; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1298 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 1299 | err = -EAGAIN; |
Jaegeuk Kim | 8618b88 | 2014-02-17 19:29:27 +0900 | [diff] [blame] | 1300 | f2fs_lock_op(sbi); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 1301 | if (f2fs_has_inline_data(inode)) |
| 1302 | err = f2fs_write_inline_data(inode, page); |
| 1303 | if (err == -EAGAIN) |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 1304 | err = do_write_data_page(&fio); |
Jaegeuk Kim | 26de9b1 | 2016-05-20 20:42:37 -0700 | [diff] [blame] | 1305 | if (F2FS_I(inode)->last_disk_size < psize) |
| 1306 | F2FS_I(inode)->last_disk_size = psize; |
Jaegeuk Kim | 8618b88 | 2014-02-17 19:29:27 +0900 | [diff] [blame] | 1307 | f2fs_unlock_op(sbi); |
| 1308 | done: |
| 1309 | if (err && err != -ENOENT) |
| 1310 | goto redirty_out; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1311 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1312 | clear_cold_data(page); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 1313 | out: |
Jaegeuk Kim | a7ffdbe | 2014-09-12 15:53:45 -0700 | [diff] [blame] | 1314 | inode_dec_dirty_pages(inode); |
Jaegeuk Kim | 2bca1e2 | 2015-02-25 19:25:01 -0800 | [diff] [blame] | 1315 | if (err) |
| 1316 | ClearPageUptodate(page); |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 1317 | |
| 1318 | if (wbc->for_reclaim) { |
| 1319 | f2fs_submit_merged_bio_cond(sbi, NULL, page, 0, DATA, WRITE); |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 1320 | remove_dirty_inode(inode); |
Chao Yu | eb7e813 | 2015-11-10 18:45:07 +0800 | [diff] [blame] | 1321 | } |
Chao Yu | 0c3a579 | 2016-01-18 18:28:11 +0800 | [diff] [blame] | 1322 | |
| 1323 | unlock_page(page); |
| 1324 | f2fs_balance_fs(sbi, need_balance_fs); |
| 1325 | |
| 1326 | if (unlikely(f2fs_cp_error(sbi))) |
| 1327 | f2fs_submit_merged_bio(sbi, DATA, WRITE); |
| 1328 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1329 | return 0; |
| 1330 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1331 | redirty_out: |
Jaegeuk Kim | 76f6026 | 2014-04-15 16:04:15 +0900 | [diff] [blame] | 1332 | redirty_page_for_writepage(wbc, page); |
Jaegeuk Kim | b230e6c | 2016-05-29 21:18:23 -0700 | [diff] [blame] | 1333 | unlock_page(page); |
| 1334 | return err; |
Namjae Jeon | fa9150a | 2013-01-15 16:45:24 +0900 | [diff] [blame] | 1335 | } |
| 1336 | |
Chao Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 1337 | /* |
| 1338 | * This function was copied from write_cche_pages from mm/page-writeback.c. |
| 1339 | * The major change is making write step of cold data page separately from |
| 1340 | * warm/hot data page. |
| 1341 | */ |
| 1342 | static int f2fs_write_cache_pages(struct address_space *mapping, |
Jaegeuk Kim | b230e6c | 2016-05-29 21:18:23 -0700 | [diff] [blame] | 1343 | struct writeback_control *wbc) |
Chao Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 1344 | { |
| 1345 | int ret = 0; |
| 1346 | int done = 0; |
| 1347 | struct pagevec pvec; |
| 1348 | int nr_pages; |
| 1349 | pgoff_t uninitialized_var(writeback_index); |
| 1350 | pgoff_t index; |
| 1351 | pgoff_t end; /* Inclusive */ |
| 1352 | pgoff_t done_index; |
| 1353 | int cycled; |
| 1354 | int range_whole = 0; |
| 1355 | int tag; |
Chao Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 1356 | |
| 1357 | pagevec_init(&pvec, 0); |
Jaegeuk Kim | 46ae957 | 2016-05-25 20:57:16 -0700 | [diff] [blame] | 1358 | |
Chao Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 1359 | if (wbc->range_cyclic) { |
| 1360 | writeback_index = mapping->writeback_index; /* prev offset */ |
| 1361 | index = writeback_index; |
| 1362 | if (index == 0) |
| 1363 | cycled = 1; |
| 1364 | else |
| 1365 | cycled = 0; |
| 1366 | end = -1; |
| 1367 | } else { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1368 | index = wbc->range_start >> PAGE_SHIFT; |
| 1369 | end = wbc->range_end >> PAGE_SHIFT; |
Chao Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 1370 | if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) |
| 1371 | range_whole = 1; |
| 1372 | cycled = 1; /* ignore range_cyclic tests */ |
| 1373 | } |
| 1374 | if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) |
| 1375 | tag = PAGECACHE_TAG_TOWRITE; |
| 1376 | else |
| 1377 | tag = PAGECACHE_TAG_DIRTY; |
| 1378 | retry: |
| 1379 | if (wbc->sync_mode == WB_SYNC_ALL || wbc->tagged_writepages) |
| 1380 | tag_pages_for_writeback(mapping, index, end); |
| 1381 | done_index = index; |
| 1382 | while (!done && (index <= end)) { |
| 1383 | int i; |
| 1384 | |
| 1385 | nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, tag, |
| 1386 | min(end - index, (pgoff_t)PAGEVEC_SIZE - 1) + 1); |
| 1387 | if (nr_pages == 0) |
| 1388 | break; |
| 1389 | |
| 1390 | for (i = 0; i < nr_pages; i++) { |
| 1391 | struct page *page = pvec.pages[i]; |
| 1392 | |
| 1393 | if (page->index > end) { |
| 1394 | done = 1; |
| 1395 | break; |
| 1396 | } |
| 1397 | |
| 1398 | done_index = page->index; |
| 1399 | |
| 1400 | lock_page(page); |
| 1401 | |
| 1402 | if (unlikely(page->mapping != mapping)) { |
| 1403 | continue_unlock: |
| 1404 | unlock_page(page); |
| 1405 | continue; |
| 1406 | } |
| 1407 | |
| 1408 | if (!PageDirty(page)) { |
| 1409 | /* someone wrote it for us */ |
| 1410 | goto continue_unlock; |
| 1411 | } |
| 1412 | |
Chao Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 1413 | if (PageWriteback(page)) { |
| 1414 | if (wbc->sync_mode != WB_SYNC_NONE) |
Jaegeuk Kim | fec1d65 | 2016-01-20 23:43:51 +0800 | [diff] [blame] | 1415 | f2fs_wait_on_page_writeback(page, |
| 1416 | DATA, true); |
Chao Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 1417 | else |
| 1418 | goto continue_unlock; |
| 1419 | } |
| 1420 | |
| 1421 | BUG_ON(PageWriteback(page)); |
| 1422 | if (!clear_page_dirty_for_io(page)) |
| 1423 | goto continue_unlock; |
| 1424 | |
Jaegeuk Kim | b230e6c | 2016-05-29 21:18:23 -0700 | [diff] [blame] | 1425 | ret = mapping->a_ops->writepage(page, wbc); |
Chao Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 1426 | if (unlikely(ret)) { |
Jaegeuk Kim | b230e6c | 2016-05-29 21:18:23 -0700 | [diff] [blame] | 1427 | done_index = page->index + 1; |
| 1428 | done = 1; |
| 1429 | break; |
Chao Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | if (--wbc->nr_to_write <= 0 && |
| 1433 | wbc->sync_mode == WB_SYNC_NONE) { |
| 1434 | done = 1; |
| 1435 | break; |
| 1436 | } |
| 1437 | } |
| 1438 | pagevec_release(&pvec); |
| 1439 | cond_resched(); |
| 1440 | } |
| 1441 | |
Chao Yu | 8f46dca | 2015-07-14 18:56:10 +0800 | [diff] [blame] | 1442 | if (!cycled && !done) { |
| 1443 | cycled = 1; |
| 1444 | index = 0; |
| 1445 | end = writeback_index - 1; |
| 1446 | goto retry; |
| 1447 | } |
| 1448 | if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0)) |
| 1449 | mapping->writeback_index = done_index; |
| 1450 | |
| 1451 | return ret; |
| 1452 | } |
| 1453 | |
Jaegeuk Kim | 25ca923 | 2012-11-28 16:12:41 +0900 | [diff] [blame] | 1454 | static int f2fs_write_data_pages(struct address_space *mapping, |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1455 | struct writeback_control *wbc) |
| 1456 | { |
| 1457 | struct inode *inode = mapping->host; |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 1458 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | 9dfa1ba | 2016-07-13 19:33:19 -0700 | [diff] [blame] | 1459 | struct blk_plug plug; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1460 | int ret; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1461 | |
P J P | cfb185a | 2013-04-03 11:38:00 +0900 | [diff] [blame] | 1462 | /* deal with chardevs and other special file */ |
| 1463 | if (!mapping->a_ops->writepage) |
| 1464 | return 0; |
| 1465 | |
Chao Yu | 6a29054 | 2015-07-17 18:02:39 +0800 | [diff] [blame] | 1466 | /* skip writing if there is no dirty page in this inode */ |
| 1467 | if (!get_dirty_pages(inode) && wbc->sync_mode == WB_SYNC_NONE) |
| 1468 | return 0; |
| 1469 | |
Jaegeuk Kim | a125702 | 2015-10-08 10:40:07 -0700 | [diff] [blame] | 1470 | if (S_ISDIR(inode->i_mode) && wbc->sync_mode == WB_SYNC_NONE && |
| 1471 | get_dirty_pages(inode) < nr_pages_to_skip(sbi, DATA) && |
| 1472 | available_free_memory(sbi, DIRTY_DENTS)) |
| 1473 | goto skip_write; |
| 1474 | |
Chao Yu | d323d00 | 2015-10-27 09:53:45 +0800 | [diff] [blame] | 1475 | /* skip writing during file defragment */ |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 1476 | if (is_inode_flag_set(inode, FI_DO_DEFRAG)) |
Chao Yu | d323d00 | 2015-10-27 09:53:45 +0800 | [diff] [blame] | 1477 | goto skip_write; |
| 1478 | |
Jaegeuk Kim | d5669f7 | 2015-02-27 13:37:39 -0800 | [diff] [blame] | 1479 | /* during POR, we don't need to trigger writepage at all. */ |
| 1480 | if (unlikely(is_sbi_flag_set(sbi, SBI_POR_DOING))) |
| 1481 | goto skip_write; |
| 1482 | |
Yunlei He | d31c7c3 | 2016-02-04 16:14:00 +0800 | [diff] [blame] | 1483 | trace_f2fs_writepages(mapping->host, wbc, DATA); |
| 1484 | |
Jaegeuk Kim | 9dfa1ba | 2016-07-13 19:33:19 -0700 | [diff] [blame] | 1485 | blk_start_plug(&plug); |
Jaegeuk Kim | b230e6c | 2016-05-29 21:18:23 -0700 | [diff] [blame] | 1486 | ret = f2fs_write_cache_pages(mapping, wbc); |
Jaegeuk Kim | 9dfa1ba | 2016-07-13 19:33:19 -0700 | [diff] [blame] | 1487 | blk_finish_plug(&plug); |
Jaegeuk Kim | 28ea616 | 2016-05-25 17:17:56 -0700 | [diff] [blame] | 1488 | /* |
| 1489 | * if some pages were truncated, we cannot guarantee its mapping->host |
| 1490 | * to detect pending bios. |
| 1491 | */ |
| 1492 | f2fs_submit_merged_bio(sbi, DATA, WRITE); |
Jaegeuk Kim | 458e619 | 2013-12-11 13:54:01 +0900 | [diff] [blame] | 1493 | |
Chao Yu | c227f91 | 2015-12-16 13:09:20 +0800 | [diff] [blame] | 1494 | remove_dirty_inode(inode); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1495 | return ret; |
Jaegeuk Kim | d3baf95 | 2014-03-18 13:43:05 +0900 | [diff] [blame] | 1496 | |
| 1497 | skip_write: |
Jaegeuk Kim | a7ffdbe | 2014-09-12 15:53:45 -0700 | [diff] [blame] | 1498 | wbc->pages_skipped += get_dirty_pages(inode); |
Yunlei He | d31c7c3 | 2016-02-04 16:14:00 +0800 | [diff] [blame] | 1499 | trace_f2fs_writepages(mapping->host, wbc, DATA); |
Jaegeuk Kim | d3baf95 | 2014-03-18 13:43:05 +0900 | [diff] [blame] | 1500 | return 0; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1501 | } |
| 1502 | |
Chao Yu | 3aab8f8 | 2014-07-02 13:25:04 +0800 | [diff] [blame] | 1503 | static void f2fs_write_failed(struct address_space *mapping, loff_t to) |
| 1504 | { |
| 1505 | struct inode *inode = mapping->host; |
Jaegeuk Kim | 819d915 | 2015-12-28 13:48:11 -0800 | [diff] [blame] | 1506 | loff_t i_size = i_size_read(inode); |
Chao Yu | 3aab8f8 | 2014-07-02 13:25:04 +0800 | [diff] [blame] | 1507 | |
Jaegeuk Kim | 819d915 | 2015-12-28 13:48:11 -0800 | [diff] [blame] | 1508 | if (to > i_size) { |
| 1509 | truncate_pagecache(inode, i_size); |
| 1510 | truncate_blocks(inode, i_size, true); |
Chao Yu | 3aab8f8 | 2014-07-02 13:25:04 +0800 | [diff] [blame] | 1511 | } |
| 1512 | } |
| 1513 | |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1514 | static int prepare_write_begin(struct f2fs_sb_info *sbi, |
| 1515 | struct page *page, loff_t pos, unsigned len, |
| 1516 | block_t *blk_addr, bool *node_changed) |
| 1517 | { |
| 1518 | struct inode *inode = page->mapping->host; |
| 1519 | pgoff_t index = page->index; |
| 1520 | struct dnode_of_data dn; |
| 1521 | struct page *ipage; |
Jaegeuk Kim | b4d07a3 | 2015-12-23 13:48:58 -0800 | [diff] [blame] | 1522 | bool locked = false; |
| 1523 | struct extent_info ei; |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1524 | int err = 0; |
| 1525 | |
Jaegeuk Kim | 24b8491 | 2016-02-03 13:49:44 -0800 | [diff] [blame] | 1526 | /* |
| 1527 | * we already allocated all the blocks, so we don't need to get |
| 1528 | * the block addresses when there is no need to fill the page. |
| 1529 | */ |
| 1530 | if (!f2fs_has_inline_data(inode) && !f2fs_encrypted_inode(inode) && |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1531 | len == PAGE_SIZE) |
Jaegeuk Kim | 24b8491 | 2016-02-03 13:49:44 -0800 | [diff] [blame] | 1532 | return 0; |
| 1533 | |
Jaegeuk Kim | b4d07a3 | 2015-12-23 13:48:58 -0800 | [diff] [blame] | 1534 | if (f2fs_has_inline_data(inode) || |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1535 | (pos & PAGE_MASK) >= i_size_read(inode)) { |
Jaegeuk Kim | b4d07a3 | 2015-12-23 13:48:58 -0800 | [diff] [blame] | 1536 | f2fs_lock_op(sbi); |
| 1537 | locked = true; |
| 1538 | } |
| 1539 | restart: |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1540 | /* check inline_data */ |
| 1541 | ipage = get_node_page(sbi, inode->i_ino); |
| 1542 | if (IS_ERR(ipage)) { |
| 1543 | err = PTR_ERR(ipage); |
| 1544 | goto unlock_out; |
| 1545 | } |
| 1546 | |
| 1547 | set_new_dnode(&dn, inode, ipage, ipage, 0); |
| 1548 | |
| 1549 | if (f2fs_has_inline_data(inode)) { |
| 1550 | if (pos + len <= MAX_INLINE_DATA) { |
| 1551 | read_inline_data(page, ipage); |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 1552 | set_inode_flag(inode, FI_DATA_EXIST); |
Chao Yu | ab47036 | 2016-05-11 19:48:44 +0800 | [diff] [blame] | 1553 | if (inode->i_nlink) |
| 1554 | set_inline_node(ipage); |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1555 | } else { |
| 1556 | err = f2fs_convert_inline_page(&dn, page); |
| 1557 | if (err) |
Jaegeuk Kim | b4d07a3 | 2015-12-23 13:48:58 -0800 | [diff] [blame] | 1558 | goto out; |
| 1559 | if (dn.data_blkaddr == NULL_ADDR) |
| 1560 | err = f2fs_get_block(&dn, index); |
| 1561 | } |
| 1562 | } else if (locked) { |
| 1563 | err = f2fs_get_block(&dn, index); |
| 1564 | } else { |
| 1565 | if (f2fs_lookup_extent_cache(inode, index, &ei)) { |
| 1566 | dn.data_blkaddr = ei.blk + index - ei.fofs; |
| 1567 | } else { |
Jaegeuk Kim | b4d07a3 | 2015-12-23 13:48:58 -0800 | [diff] [blame] | 1568 | /* hole case */ |
| 1569 | err = get_dnode_of_data(&dn, index, LOOKUP_NODE); |
Jaegeuk Kim | 4da7bf5 | 2016-04-06 11:27:03 -0700 | [diff] [blame] | 1570 | if (err || dn.data_blkaddr == NULL_ADDR) { |
Jaegeuk Kim | b4d07a3 | 2015-12-23 13:48:58 -0800 | [diff] [blame] | 1571 | f2fs_put_dnode(&dn); |
| 1572 | f2fs_lock_op(sbi); |
| 1573 | locked = true; |
| 1574 | goto restart; |
| 1575 | } |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1576 | } |
| 1577 | } |
Jaegeuk Kim | b4d07a3 | 2015-12-23 13:48:58 -0800 | [diff] [blame] | 1578 | |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1579 | /* convert_inline_page can make node_changed */ |
| 1580 | *blk_addr = dn.data_blkaddr; |
| 1581 | *node_changed = dn.node_changed; |
Jaegeuk Kim | b4d07a3 | 2015-12-23 13:48:58 -0800 | [diff] [blame] | 1582 | out: |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1583 | f2fs_put_dnode(&dn); |
| 1584 | unlock_out: |
Jaegeuk Kim | b4d07a3 | 2015-12-23 13:48:58 -0800 | [diff] [blame] | 1585 | if (locked) |
| 1586 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1587 | return err; |
| 1588 | } |
| 1589 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1590 | static int f2fs_write_begin(struct file *file, struct address_space *mapping, |
| 1591 | loff_t pos, unsigned len, unsigned flags, |
| 1592 | struct page **pagep, void **fsdata) |
| 1593 | { |
| 1594 | struct inode *inode = mapping->host; |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 1595 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | 86531d6 | 2015-07-15 13:08:21 -0700 | [diff] [blame] | 1596 | struct page *page = NULL; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1597 | pgoff_t index = ((unsigned long long) pos) >> PAGE_SHIFT; |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1598 | bool need_balance = false; |
| 1599 | block_t blkaddr = NULL_ADDR; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1600 | int err = 0; |
| 1601 | |
Chao Yu | 62aed04 | 2014-05-06 16:46:04 +0800 | [diff] [blame] | 1602 | trace_f2fs_write_begin(inode, pos, len, flags); |
| 1603 | |
Jaegeuk Kim | 5f72739 | 2014-11-25 10:59:45 -0800 | [diff] [blame] | 1604 | /* |
| 1605 | * We should check this at this moment to avoid deadlock on inode page |
| 1606 | * and #0 page. The locking rule for inline_data conversion should be: |
| 1607 | * lock_page(page #0) -> lock_page(inode_page) |
| 1608 | */ |
| 1609 | if (index != 0) { |
| 1610 | err = f2fs_convert_inline_inode(inode); |
| 1611 | if (err) |
| 1612 | goto fail; |
| 1613 | } |
Jaegeuk Kim | afcb7ca0 | 2013-04-26 11:55:17 +0900 | [diff] [blame] | 1614 | repeat: |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1615 | page = grab_cache_page_write_begin(mapping, index, flags); |
Chao Yu | 3aab8f8 | 2014-07-02 13:25:04 +0800 | [diff] [blame] | 1616 | if (!page) { |
| 1617 | err = -ENOMEM; |
| 1618 | goto fail; |
| 1619 | } |
Jaegeuk Kim | d5f6699 | 2014-04-30 09:22:45 +0900 | [diff] [blame] | 1620 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1621 | *pagep = page; |
| 1622 | |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1623 | err = prepare_write_begin(sbi, page, pos, len, |
| 1624 | &blkaddr, &need_balance); |
Jaegeuk Kim | 9ba69cf | 2014-10-17 20:33:55 -0700 | [diff] [blame] | 1625 | if (err) |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1626 | goto fail; |
Jaegeuk Kim | 9ba69cf | 2014-10-17 20:33:55 -0700 | [diff] [blame] | 1627 | |
Jaegeuk Kim | 7f3037a | 2016-09-01 12:02:51 -0700 | [diff] [blame] | 1628 | if (need_balance && has_not_enough_free_secs(sbi, 0, 0)) { |
Jaegeuk Kim | 2a34076 | 2015-12-22 13:23:35 -0800 | [diff] [blame] | 1629 | unlock_page(page); |
Jaegeuk Kim | 2c4db1a | 2016-01-07 14:15:04 -0800 | [diff] [blame] | 1630 | f2fs_balance_fs(sbi, true); |
Jaegeuk Kim | 2a34076 | 2015-12-22 13:23:35 -0800 | [diff] [blame] | 1631 | lock_page(page); |
| 1632 | if (page->mapping != mapping) { |
| 1633 | /* The page got truncated from under us */ |
| 1634 | f2fs_put_page(page, 1); |
| 1635 | goto repeat; |
| 1636 | } |
| 1637 | } |
| 1638 | |
Jaegeuk Kim | fec1d65 | 2016-01-20 23:43:51 +0800 | [diff] [blame] | 1639 | f2fs_wait_on_page_writeback(page, DATA, false); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 1640 | |
Chao Yu | 08b39fb | 2015-10-08 13:27:34 +0800 | [diff] [blame] | 1641 | /* wait for GCed encrypted page writeback */ |
| 1642 | if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1643 | f2fs_wait_on_encrypted_page_writeback(sbi, blkaddr); |
Chao Yu | 08b39fb | 2015-10-08 13:27:34 +0800 | [diff] [blame] | 1644 | |
Jaegeuk Kim | 649d7df | 2016-09-06 11:02:03 -0700 | [diff] [blame^] | 1645 | if (len == PAGE_SIZE || PageUptodate(page)) |
| 1646 | return 0; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1647 | |
Jaegeuk Kim | 2aadac0 | 2015-12-23 11:55:18 -0800 | [diff] [blame] | 1648 | if (blkaddr == NEW_ADDR) { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1649 | zero_user_segment(page, 0, PAGE_SIZE); |
Jaegeuk Kim | 649d7df | 2016-09-06 11:02:03 -0700 | [diff] [blame^] | 1650 | SetPageUptodate(page); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1651 | } else { |
Chao Yu | 78682f7 | 2016-07-03 22:05:11 +0800 | [diff] [blame] | 1652 | struct bio *bio; |
Chao Yu | d54c795 | 2014-03-29 15:30:40 +0800 | [diff] [blame] | 1653 | |
Chao Yu | 78682f7 | 2016-07-03 22:05:11 +0800 | [diff] [blame] | 1654 | bio = f2fs_grab_bio(inode, blkaddr, 1); |
| 1655 | if (IS_ERR(bio)) { |
| 1656 | err = PTR_ERR(bio); |
Chao Yu | 3aab8f8 | 2014-07-02 13:25:04 +0800 | [diff] [blame] | 1657 | goto fail; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1658 | } |
Linus Torvalds | 4fc29c1 | 2016-07-27 10:36:31 -0700 | [diff] [blame] | 1659 | bio_set_op_attrs(bio, REQ_OP_READ, READ_SYNC); |
Chao Yu | 78682f7 | 2016-07-03 22:05:11 +0800 | [diff] [blame] | 1660 | if (bio_add_page(bio, page, PAGE_SIZE, 0) < PAGE_SIZE) { |
| 1661 | bio_put(bio); |
| 1662 | err = -EFAULT; |
| 1663 | goto fail; |
| 1664 | } |
| 1665 | |
Linus Torvalds | 4fc29c1 | 2016-07-27 10:36:31 -0700 | [diff] [blame] | 1666 | __submit_bio(sbi, bio, DATA); |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 1667 | |
Jaegeuk Kim | afcb7ca0 | 2013-04-26 11:55:17 +0900 | [diff] [blame] | 1668 | lock_page(page); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1669 | if (unlikely(page->mapping != mapping)) { |
Jaegeuk Kim | afcb7ca0 | 2013-04-26 11:55:17 +0900 | [diff] [blame] | 1670 | f2fs_put_page(page, 1); |
| 1671 | goto repeat; |
| 1672 | } |
Chao Yu | 1563ac7 | 2016-07-03 22:05:12 +0800 | [diff] [blame] | 1673 | if (unlikely(!PageUptodate(page))) { |
| 1674 | err = -EIO; |
| 1675 | goto fail; |
Jaegeuk Kim | 4375a33 | 2015-04-23 12:04:33 -0700 | [diff] [blame] | 1676 | } |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1677 | } |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1678 | return 0; |
Jaegeuk Kim | 9ba69cf | 2014-10-17 20:33:55 -0700 | [diff] [blame] | 1679 | |
Chao Yu | 3aab8f8 | 2014-07-02 13:25:04 +0800 | [diff] [blame] | 1680 | fail: |
Jaegeuk Kim | 86531d6 | 2015-07-15 13:08:21 -0700 | [diff] [blame] | 1681 | f2fs_put_page(page, 1); |
Chao Yu | 3aab8f8 | 2014-07-02 13:25:04 +0800 | [diff] [blame] | 1682 | f2fs_write_failed(mapping, pos + len); |
| 1683 | return err; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1684 | } |
| 1685 | |
Jaegeuk Kim | a1dd3c1 | 2013-06-27 13:04:08 +0900 | [diff] [blame] | 1686 | static int f2fs_write_end(struct file *file, |
| 1687 | struct address_space *mapping, |
| 1688 | loff_t pos, unsigned len, unsigned copied, |
| 1689 | struct page *page, void *fsdata) |
| 1690 | { |
| 1691 | struct inode *inode = page->mapping->host; |
| 1692 | |
Chao Yu | dfb2bf3 | 2014-05-06 16:47:23 +0800 | [diff] [blame] | 1693 | trace_f2fs_write_end(inode, pos, len, copied); |
| 1694 | |
Jaegeuk Kim | 649d7df | 2016-09-06 11:02:03 -0700 | [diff] [blame^] | 1695 | /* |
| 1696 | * This should be come from len == PAGE_SIZE, and we expect copied |
| 1697 | * should be PAGE_SIZE. Otherwise, we treat it with zero copied and |
| 1698 | * let generic_perform_write() try to copy data again through copied=0. |
| 1699 | */ |
| 1700 | if (!PageUptodate(page)) { |
| 1701 | if (unlikely(copied != PAGE_SIZE)) |
| 1702 | copied = 0; |
| 1703 | else |
| 1704 | SetPageUptodate(page); |
| 1705 | } |
| 1706 | if (!copied) |
| 1707 | goto unlock_out; |
| 1708 | |
Jaegeuk Kim | 34ba94b | 2014-10-09 13:19:53 -0700 | [diff] [blame] | 1709 | set_page_dirty(page); |
Jaegeuk Kim | 649d7df | 2016-09-06 11:02:03 -0700 | [diff] [blame^] | 1710 | clear_cold_data(page); |
Jaegeuk Kim | a1dd3c1 | 2013-06-27 13:04:08 +0900 | [diff] [blame] | 1711 | |
Jaegeuk Kim | fc9581c | 2016-05-20 09:22:03 -0700 | [diff] [blame] | 1712 | if (pos + copied > i_size_read(inode)) |
| 1713 | f2fs_i_size_write(inode, pos + copied); |
Jaegeuk Kim | 649d7df | 2016-09-06 11:02:03 -0700 | [diff] [blame^] | 1714 | unlock_out: |
Chao Yu | 3024c9a | 2016-08-06 21:09:41 +0800 | [diff] [blame] | 1715 | f2fs_put_page(page, 1); |
Jaegeuk Kim | d0239e1 | 2016-01-08 16:57:48 -0800 | [diff] [blame] | 1716 | f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); |
Jaegeuk Kim | a1dd3c1 | 2013-06-27 13:04:08 +0900 | [diff] [blame] | 1717 | return copied; |
| 1718 | } |
| 1719 | |
Omar Sandoval | 6f67376 | 2015-03-16 04:33:52 -0700 | [diff] [blame] | 1720 | static int check_direct_IO(struct inode *inode, struct iov_iter *iter, |
| 1721 | loff_t offset) |
Jaegeuk Kim | 944fcfc | 2013-12-26 20:15:09 +0900 | [diff] [blame] | 1722 | { |
| 1723 | unsigned blocksize_mask = inode->i_sb->s_blocksize - 1; |
Jaegeuk Kim | 944fcfc | 2013-12-26 20:15:09 +0900 | [diff] [blame] | 1724 | |
Jaegeuk Kim | 944fcfc | 2013-12-26 20:15:09 +0900 | [diff] [blame] | 1725 | if (offset & blocksize_mask) |
| 1726 | return -EINVAL; |
| 1727 | |
Al Viro | 5b46f25 | 2014-03-16 18:07:34 -0400 | [diff] [blame] | 1728 | if (iov_iter_alignment(iter) & blocksize_mask) |
| 1729 | return -EINVAL; |
| 1730 | |
Jaegeuk Kim | 944fcfc | 2013-12-26 20:15:09 +0900 | [diff] [blame] | 1731 | return 0; |
| 1732 | } |
| 1733 | |
Christoph Hellwig | c8b8e32 | 2016-04-07 08:51:58 -0700 | [diff] [blame] | 1734 | static ssize_t f2fs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1735 | { |
Jaegeuk Kim | b439b10 | 2016-02-03 13:09:09 -0800 | [diff] [blame] | 1736 | struct address_space *mapping = iocb->ki_filp->f_mapping; |
Chao Yu | 3aab8f8 | 2014-07-02 13:25:04 +0800 | [diff] [blame] | 1737 | struct inode *inode = mapping->host; |
| 1738 | size_t count = iov_iter_count(iter); |
Christoph Hellwig | c8b8e32 | 2016-04-07 08:51:58 -0700 | [diff] [blame] | 1739 | loff_t offset = iocb->ki_pos; |
Chao Yu | 82e0a5a | 2016-07-13 09:18:29 +0800 | [diff] [blame] | 1740 | int rw = iov_iter_rw(iter); |
Chao Yu | 3aab8f8 | 2014-07-02 13:25:04 +0800 | [diff] [blame] | 1741 | int err; |
Jaegeuk Kim | 944fcfc | 2013-12-26 20:15:09 +0900 | [diff] [blame] | 1742 | |
Jaegeuk Kim | b439b10 | 2016-02-03 13:09:09 -0800 | [diff] [blame] | 1743 | err = check_direct_IO(inode, iter, offset); |
Jaegeuk Kim | b9d777b | 2015-12-22 11:09:35 -0800 | [diff] [blame] | 1744 | if (err) |
| 1745 | return err; |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 1746 | |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 1747 | if (f2fs_encrypted_inode(inode) && S_ISREG(inode->i_mode)) |
| 1748 | return 0; |
Jaegeuk Kim | 36abef4 | 2016-06-03 19:29:38 -0700 | [diff] [blame] | 1749 | if (test_opt(F2FS_I_SB(inode), LFS)) |
| 1750 | return 0; |
Jaegeuk Kim | fcc85a4 | 2015-04-21 20:39:58 -0700 | [diff] [blame] | 1751 | |
Jaegeuk Kim | 5302fb0 | 2016-07-22 15:25:47 -0700 | [diff] [blame] | 1752 | trace_f2fs_direct_IO_enter(inode, offset, count, rw); |
Chao Yu | 70407fa | 2014-07-31 21:11:22 +0800 | [diff] [blame] | 1753 | |
Chao Yu | 82e0a5a | 2016-07-13 09:18:29 +0800 | [diff] [blame] | 1754 | down_read(&F2FS_I(inode)->dio_rwsem[rw]); |
Christoph Hellwig | c8b8e32 | 2016-04-07 08:51:58 -0700 | [diff] [blame] | 1755 | err = blockdev_direct_IO(iocb, inode, iter, get_data_block_dio); |
Chao Yu | 82e0a5a | 2016-07-13 09:18:29 +0800 | [diff] [blame] | 1756 | up_read(&F2FS_I(inode)->dio_rwsem[rw]); |
| 1757 | |
| 1758 | if (rw == WRITE) { |
Jaegeuk Kim | 6bfc491 | 2016-04-18 17:07:44 -0400 | [diff] [blame] | 1759 | if (err > 0) |
Jaegeuk Kim | 9194232 | 2016-05-20 10:13:22 -0700 | [diff] [blame] | 1760 | set_inode_flag(inode, FI_UPDATE_WRITE); |
Jaegeuk Kim | 6bfc491 | 2016-04-18 17:07:44 -0400 | [diff] [blame] | 1761 | else if (err < 0) |
| 1762 | f2fs_write_failed(mapping, offset + count); |
| 1763 | } |
Chao Yu | 70407fa | 2014-07-31 21:11:22 +0800 | [diff] [blame] | 1764 | |
Jaegeuk Kim | 5302fb0 | 2016-07-22 15:25:47 -0700 | [diff] [blame] | 1765 | trace_f2fs_direct_IO_exit(inode, offset, count, rw, err); |
Chao Yu | 70407fa | 2014-07-31 21:11:22 +0800 | [diff] [blame] | 1766 | |
Chao Yu | 3aab8f8 | 2014-07-02 13:25:04 +0800 | [diff] [blame] | 1767 | return err; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1768 | } |
| 1769 | |
Chao Yu | 487261f | 2015-02-05 17:44:29 +0800 | [diff] [blame] | 1770 | void f2fs_invalidate_page(struct page *page, unsigned int offset, |
| 1771 | unsigned int length) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1772 | { |
| 1773 | struct inode *inode = page->mapping->host; |
Chao Yu | 487261f | 2015-02-05 17:44:29 +0800 | [diff] [blame] | 1774 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | a7ffdbe | 2014-09-12 15:53:45 -0700 | [diff] [blame] | 1775 | |
Chao Yu | 487261f | 2015-02-05 17:44:29 +0800 | [diff] [blame] | 1776 | if (inode->i_ino >= F2FS_ROOT_INO(sbi) && |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1777 | (offset % PAGE_SIZE || length != PAGE_SIZE)) |
Jaegeuk Kim | a7ffdbe | 2014-09-12 15:53:45 -0700 | [diff] [blame] | 1778 | return; |
| 1779 | |
Chao Yu | 487261f | 2015-02-05 17:44:29 +0800 | [diff] [blame] | 1780 | if (PageDirty(page)) { |
| 1781 | if (inode->i_ino == F2FS_META_INO(sbi)) |
| 1782 | dec_page_count(sbi, F2FS_DIRTY_META); |
| 1783 | else if (inode->i_ino == F2FS_NODE_INO(sbi)) |
| 1784 | dec_page_count(sbi, F2FS_DIRTY_NODES); |
| 1785 | else |
| 1786 | inode_dec_dirty_pages(inode); |
| 1787 | } |
Chao Yu | decd36b | 2015-08-07 18:42:09 +0800 | [diff] [blame] | 1788 | |
| 1789 | /* This is atomic written page, keep Private */ |
| 1790 | if (IS_ATOMIC_WRITTEN_PAGE(page)) |
| 1791 | return; |
| 1792 | |
Chao Yu | 23dc974 | 2016-04-29 20:09:15 +0800 | [diff] [blame] | 1793 | set_page_private(page, 0); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1794 | ClearPagePrivate(page); |
| 1795 | } |
| 1796 | |
Chao Yu | 487261f | 2015-02-05 17:44:29 +0800 | [diff] [blame] | 1797 | int f2fs_release_page(struct page *page, gfp_t wait) |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1798 | { |
Jaegeuk Kim | f68daee | 2015-01-30 11:39:08 -0800 | [diff] [blame] | 1799 | /* If this is dirty page, keep PagePrivate */ |
| 1800 | if (PageDirty(page)) |
| 1801 | return 0; |
| 1802 | |
Chao Yu | decd36b | 2015-08-07 18:42:09 +0800 | [diff] [blame] | 1803 | /* This is atomic written page, keep Private */ |
| 1804 | if (IS_ATOMIC_WRITTEN_PAGE(page)) |
| 1805 | return 0; |
| 1806 | |
Chao Yu | 23dc974 | 2016-04-29 20:09:15 +0800 | [diff] [blame] | 1807 | set_page_private(page, 0); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1808 | ClearPagePrivate(page); |
Jaegeuk Kim | c3850aa | 2013-03-14 09:24:32 +0900 | [diff] [blame] | 1809 | return 1; |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1810 | } |
| 1811 | |
Jaegeuk Kim | fe76b79 | 2016-06-30 18:40:10 -0700 | [diff] [blame] | 1812 | /* |
| 1813 | * This was copied from __set_page_dirty_buffers which gives higher performance |
| 1814 | * in very high speed storages. (e.g., pmem) |
| 1815 | */ |
| 1816 | void f2fs_set_page_dirty_nobuffers(struct page *page) |
| 1817 | { |
| 1818 | struct address_space *mapping = page->mapping; |
| 1819 | unsigned long flags; |
| 1820 | |
| 1821 | if (unlikely(!mapping)) |
| 1822 | return; |
| 1823 | |
| 1824 | spin_lock(&mapping->private_lock); |
| 1825 | lock_page_memcg(page); |
| 1826 | SetPageDirty(page); |
| 1827 | spin_unlock(&mapping->private_lock); |
| 1828 | |
| 1829 | spin_lock_irqsave(&mapping->tree_lock, flags); |
| 1830 | WARN_ON_ONCE(!PageUptodate(page)); |
| 1831 | account_page_dirtied(page, mapping); |
| 1832 | radix_tree_tag_set(&mapping->page_tree, |
| 1833 | page_index(page), PAGECACHE_TAG_DIRTY); |
| 1834 | spin_unlock_irqrestore(&mapping->tree_lock, flags); |
| 1835 | unlock_page_memcg(page); |
| 1836 | |
| 1837 | __mark_inode_dirty(mapping->host, I_DIRTY_PAGES); |
| 1838 | return; |
| 1839 | } |
| 1840 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1841 | static int f2fs_set_data_page_dirty(struct page *page) |
| 1842 | { |
| 1843 | struct address_space *mapping = page->mapping; |
| 1844 | struct inode *inode = mapping->host; |
| 1845 | |
Jaegeuk Kim | 26c6b88 | 2013-10-24 17:53:29 +0900 | [diff] [blame] | 1846 | trace_f2fs_set_page_dirty(page, DATA); |
| 1847 | |
Jaegeuk Kim | 237c079 | 2016-06-30 18:49:15 -0700 | [diff] [blame] | 1848 | if (!PageUptodate(page)) |
| 1849 | SetPageUptodate(page); |
Jaegeuk Kim | 34ba94b | 2014-10-09 13:19:53 -0700 | [diff] [blame] | 1850 | |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 1851 | if (f2fs_is_atomic_file(inode)) { |
Chao Yu | decd36b | 2015-08-07 18:42:09 +0800 | [diff] [blame] | 1852 | if (!IS_ATOMIC_WRITTEN_PAGE(page)) { |
| 1853 | register_inmem_page(inode, page); |
| 1854 | return 1; |
| 1855 | } |
| 1856 | /* |
| 1857 | * Previously, this page has been registered, we just |
| 1858 | * return here. |
| 1859 | */ |
| 1860 | return 0; |
Jaegeuk Kim | 34ba94b | 2014-10-09 13:19:53 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1863 | if (!PageDirty(page)) { |
Jaegeuk Kim | fe76b79 | 2016-06-30 18:40:10 -0700 | [diff] [blame] | 1864 | f2fs_set_page_dirty_nobuffers(page); |
Jaegeuk Kim | a7ffdbe | 2014-09-12 15:53:45 -0700 | [diff] [blame] | 1865 | update_dirty_page(inode, page); |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1866 | return 1; |
| 1867 | } |
| 1868 | return 0; |
| 1869 | } |
| 1870 | |
Jaegeuk Kim | c01e54b | 2013-01-17 20:30:23 +0900 | [diff] [blame] | 1871 | static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) |
| 1872 | { |
Chao Yu | 454ae7e | 2014-04-22 13:34:01 +0800 | [diff] [blame] | 1873 | struct inode *inode = mapping->host; |
| 1874 | |
Jaegeuk Kim | 1d373a0 | 2015-10-19 10:29:51 -0700 | [diff] [blame] | 1875 | if (f2fs_has_inline_data(inode)) |
| 1876 | return 0; |
| 1877 | |
| 1878 | /* make sure allocating whole blocks */ |
| 1879 | if (mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) |
| 1880 | filemap_write_and_wait(mapping); |
| 1881 | |
Chao Yu | e2b4e2b | 2015-08-19 19:11:19 +0800 | [diff] [blame] | 1882 | return generic_block_bmap(mapping, block, get_data_block_bmap); |
Chao Yu | 429511c | 2015-02-05 17:54:31 +0800 | [diff] [blame] | 1883 | } |
| 1884 | |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1885 | const struct address_space_operations f2fs_dblock_aops = { |
| 1886 | .readpage = f2fs_read_data_page, |
| 1887 | .readpages = f2fs_read_data_pages, |
| 1888 | .writepage = f2fs_write_data_page, |
| 1889 | .writepages = f2fs_write_data_pages, |
| 1890 | .write_begin = f2fs_write_begin, |
Jaegeuk Kim | a1dd3c1 | 2013-06-27 13:04:08 +0900 | [diff] [blame] | 1891 | .write_end = f2fs_write_end, |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1892 | .set_page_dirty = f2fs_set_data_page_dirty, |
Chao Yu | 487261f | 2015-02-05 17:44:29 +0800 | [diff] [blame] | 1893 | .invalidatepage = f2fs_invalidate_page, |
| 1894 | .releasepage = f2fs_release_page, |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1895 | .direct_IO = f2fs_direct_IO, |
Jaegeuk Kim | c01e54b | 2013-01-17 20:30:23 +0900 | [diff] [blame] | 1896 | .bmap = f2fs_bmap, |
Jaegeuk Kim | eb47b80 | 2012-11-02 17:10:12 +0900 | [diff] [blame] | 1897 | }; |