Jaegeuk Kim | 0a8165d | 2012-11-29 13:28:09 +0900 | [diff] [blame] | 1 | /* |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 2 | * fs/f2fs/file.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/stat.h> |
| 14 | #include <linux/buffer_head.h> |
| 15 | #include <linux/writeback.h> |
Jaegeuk Kim | ae51fb3 | 2013-03-16 11:13:04 +0900 | [diff] [blame] | 16 | #include <linux/blkdev.h> |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 17 | #include <linux/falloc.h> |
| 18 | #include <linux/types.h> |
Namjae Jeon | e975082 | 2013-02-04 23:41:41 +0900 | [diff] [blame] | 19 | #include <linux/compat.h> |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 20 | #include <linux/uaccess.h> |
| 21 | #include <linux/mount.h> |
Jaegeuk Kim | 7f7670f | 2014-04-28 18:12:36 +0900 | [diff] [blame] | 22 | #include <linux/pagevec.h> |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 23 | |
| 24 | #include "f2fs.h" |
| 25 | #include "node.h" |
| 26 | #include "segment.h" |
| 27 | #include "xattr.h" |
| 28 | #include "acl.h" |
Jaegeuk Kim | db9f7c1 | 2014-12-17 20:04:08 -0800 | [diff] [blame] | 29 | #include "trace.h" |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 30 | #include <trace/events/f2fs.h> |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 31 | |
| 32 | static int f2fs_vm_page_mkwrite(struct vm_area_struct *vma, |
| 33 | struct vm_fault *vmf) |
| 34 | { |
| 35 | struct page *page = vmf->page; |
Al Viro | 6131ffa | 2013-02-27 16:59:05 -0500 | [diff] [blame] | 36 | struct inode *inode = file_inode(vma->vm_file); |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 37 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 38 | struct dnode_of_data dn; |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 39 | int err; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 40 | |
| 41 | f2fs_balance_fs(sbi); |
| 42 | |
| 43 | sb_start_pagefault(inode->i_sb); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 44 | |
| 45 | f2fs_bug_on(sbi, f2fs_has_inline_data(inode)); |
Jaegeuk Kim | b067ba1f | 2014-08-07 16:32:25 -0700 | [diff] [blame] | 46 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 47 | /* block allocation */ |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 48 | f2fs_lock_op(sbi); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 49 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
Jaegeuk Kim | 9ba69cf | 2014-10-17 20:33:55 -0700 | [diff] [blame] | 50 | err = f2fs_reserve_block(&dn, page->index); |
| 51 | if (err) { |
| 52 | f2fs_unlock_op(sbi); |
| 53 | goto out; |
| 54 | } |
| 55 | f2fs_put_dnode(&dn); |
| 56 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 57 | |
Namjae Jeon | 9851e6e | 2013-04-28 09:04:18 +0900 | [diff] [blame] | 58 | file_update_time(vma->vm_file); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 59 | lock_page(page); |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 60 | if (unlikely(page->mapping != inode->i_mapping || |
Namjae Jeon | 9851e6e | 2013-04-28 09:04:18 +0900 | [diff] [blame] | 61 | page_offset(page) > i_size_read(inode) || |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 62 | !PageUptodate(page))) { |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 63 | unlock_page(page); |
| 64 | err = -EFAULT; |
| 65 | goto out; |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * check to see if the page is mapped already (no holes) |
| 70 | */ |
| 71 | if (PageMappedToDisk(page)) |
Namjae Jeon | 9851e6e | 2013-04-28 09:04:18 +0900 | [diff] [blame] | 72 | goto mapped; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 73 | |
| 74 | /* page is wholly or partially inside EOF */ |
| 75 | if (((page->index + 1) << PAGE_CACHE_SHIFT) > i_size_read(inode)) { |
| 76 | unsigned offset; |
| 77 | offset = i_size_read(inode) & ~PAGE_CACHE_MASK; |
| 78 | zero_user_segment(page, offset, PAGE_CACHE_SIZE); |
| 79 | } |
| 80 | set_page_dirty(page); |
| 81 | SetPageUptodate(page); |
| 82 | |
Jaegeuk Kim | e943a10 | 2013-10-25 14:26:31 +0900 | [diff] [blame] | 83 | trace_f2fs_vm_page_mkwrite(page, DATA); |
Namjae Jeon | 9851e6e | 2013-04-28 09:04:18 +0900 | [diff] [blame] | 84 | mapped: |
| 85 | /* fill the page */ |
Jaegeuk Kim | 3cb5ad1 | 2014-03-18 13:29:07 +0900 | [diff] [blame] | 86 | f2fs_wait_on_page_writeback(page, DATA); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 87 | out: |
| 88 | sb_end_pagefault(inode->i_sb); |
| 89 | return block_page_mkwrite_return(err); |
| 90 | } |
| 91 | |
| 92 | static const struct vm_operations_struct f2fs_file_vm_ops = { |
Jaegeuk Kim | 692bb55 | 2013-01-17 18:37:41 +0900 | [diff] [blame] | 93 | .fault = filemap_fault, |
Kirill A. Shutemov | f182036 | 2014-04-07 15:37:19 -0700 | [diff] [blame] | 94 | .map_pages = filemap_map_pages, |
Jaegeuk Kim | 692bb55 | 2013-01-17 18:37:41 +0900 | [diff] [blame] | 95 | .page_mkwrite = f2fs_vm_page_mkwrite, |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 96 | }; |
| 97 | |
Jaegeuk Kim | 354a339 | 2013-06-14 08:52:35 +0900 | [diff] [blame] | 98 | static int get_parent_ino(struct inode *inode, nid_t *pino) |
| 99 | { |
| 100 | struct dentry *dentry; |
| 101 | |
| 102 | inode = igrab(inode); |
| 103 | dentry = d_find_any_alias(inode); |
| 104 | iput(inode); |
| 105 | if (!dentry) |
| 106 | return 0; |
| 107 | |
Jaegeuk Kim | f0947e5 | 2013-07-22 22:12:56 +0900 | [diff] [blame] | 108 | if (update_dent_inode(inode, &dentry->d_name)) { |
| 109 | dput(dentry); |
| 110 | return 0; |
| 111 | } |
Jaegeuk Kim | 354a339 | 2013-06-14 08:52:35 +0900 | [diff] [blame] | 112 | |
Jaegeuk Kim | f0947e5 | 2013-07-22 22:12:56 +0900 | [diff] [blame] | 113 | *pino = parent_ino(dentry); |
| 114 | dput(dentry); |
Jaegeuk Kim | 354a339 | 2013-06-14 08:52:35 +0900 | [diff] [blame] | 115 | return 1; |
| 116 | } |
| 117 | |
Chao Yu | 9d1589e | 2014-08-20 18:37:35 +0800 | [diff] [blame] | 118 | static inline bool need_do_checkpoint(struct inode *inode) |
| 119 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 120 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Chao Yu | 9d1589e | 2014-08-20 18:37:35 +0800 | [diff] [blame] | 121 | bool need_cp = false; |
| 122 | |
| 123 | if (!S_ISREG(inode->i_mode) || inode->i_nlink != 1) |
| 124 | need_cp = true; |
| 125 | else if (file_wrong_pino(inode)) |
| 126 | need_cp = true; |
| 127 | else if (!space_for_roll_forward(sbi)) |
| 128 | need_cp = true; |
| 129 | else if (!is_checkpointed_node(sbi, F2FS_I(inode)->i_pino)) |
| 130 | need_cp = true; |
| 131 | else if (F2FS_I(inode)->xattr_ver == cur_cp_version(F2FS_CKPT(sbi))) |
| 132 | need_cp = true; |
Jaegeuk Kim | d5053a34 | 2014-10-30 22:47:03 -0700 | [diff] [blame] | 133 | else if (test_opt(sbi, FASTBOOT)) |
| 134 | need_cp = true; |
Jaegeuk Kim | a344b9f | 2014-11-05 20:05:53 -0800 | [diff] [blame] | 135 | else if (sbi->active_logs == 2) |
| 136 | need_cp = true; |
Chao Yu | 9d1589e | 2014-08-20 18:37:35 +0800 | [diff] [blame] | 137 | |
| 138 | return need_cp; |
| 139 | } |
| 140 | |
Changman Lee | 9c7bb70 | 2014-12-08 15:29:40 +0900 | [diff] [blame] | 141 | static bool need_inode_page_update(struct f2fs_sb_info *sbi, nid_t ino) |
| 142 | { |
| 143 | struct page *i = find_get_page(NODE_MAPPING(sbi), ino); |
| 144 | bool ret = false; |
| 145 | /* But we need to avoid that there are some inode updates */ |
| 146 | if ((i && PageDirty(i)) || need_inode_block_update(sbi, ino)) |
| 147 | ret = true; |
| 148 | f2fs_put_page(i, 0); |
| 149 | return ret; |
| 150 | } |
| 151 | |
Changman Lee | 51455b1 | 2014-12-08 15:29:41 +0900 | [diff] [blame] | 152 | static void try_to_fix_pino(struct inode *inode) |
| 153 | { |
| 154 | struct f2fs_inode_info *fi = F2FS_I(inode); |
| 155 | nid_t pino; |
| 156 | |
| 157 | down_write(&fi->i_sem); |
| 158 | fi->xattr_ver = 0; |
| 159 | if (file_wrong_pino(inode) && inode->i_nlink == 1 && |
| 160 | get_parent_ino(inode, &pino)) { |
| 161 | fi->i_pino = pino; |
| 162 | file_got_pino(inode); |
| 163 | up_write(&fi->i_sem); |
| 164 | |
| 165 | mark_inode_dirty_sync(inode); |
| 166 | f2fs_write_inode(inode, NULL); |
| 167 | } else { |
| 168 | up_write(&fi->i_sem); |
| 169 | } |
| 170 | } |
| 171 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 172 | int f2fs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) |
| 173 | { |
| 174 | struct inode *inode = file->f_mapping->host; |
Jaegeuk Kim | d928bfb | 2014-03-20 19:10:08 +0900 | [diff] [blame] | 175 | struct f2fs_inode_info *fi = F2FS_I(inode); |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 176 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | 2403c15 | 2014-09-10 14:58:18 -0700 | [diff] [blame] | 177 | nid_t ino = inode->i_ino; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 178 | int ret = 0; |
| 179 | bool need_cp = false; |
| 180 | struct writeback_control wbc = { |
Jaegeuk Kim | c81bf1c | 2014-03-03 11:28:40 +0900 | [diff] [blame] | 181 | .sync_mode = WB_SYNC_ALL, |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 182 | .nr_to_write = LONG_MAX, |
| 183 | .for_reclaim = 0, |
| 184 | }; |
| 185 | |
Jaegeuk Kim | 6bacf52 | 2013-12-06 15:00:58 +0900 | [diff] [blame] | 186 | if (unlikely(f2fs_readonly(inode->i_sb))) |
Namjae Jeon | 1fa95b0 | 2012-12-01 10:56:01 +0900 | [diff] [blame] | 187 | return 0; |
| 188 | |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 189 | trace_f2fs_sync_file_enter(inode); |
Jaegeuk Kim | ea1aa12 | 2014-07-24 19:11:43 -0700 | [diff] [blame] | 190 | |
| 191 | /* if fdatasync is triggered, let's do in-place-update */ |
Jaegeuk Kim | c1ce1b0 | 2014-09-10 16:53:02 -0700 | [diff] [blame] | 192 | if (get_dirty_pages(inode) <= SM_I(sbi)->min_fsync_blocks) |
Jaegeuk Kim | ea1aa12 | 2014-07-24 19:11:43 -0700 | [diff] [blame] | 193 | set_inode_flag(fi, FI_NEED_IPU); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 194 | ret = filemap_write_and_wait_range(inode->i_mapping, start, end); |
Jaegeuk Kim | c1ce1b0 | 2014-09-10 16:53:02 -0700 | [diff] [blame] | 195 | clear_inode_flag(fi, FI_NEED_IPU); |
| 196 | |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 197 | if (ret) { |
| 198 | trace_f2fs_sync_file_exit(inode, need_cp, datasync, ret); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 199 | return ret; |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 200 | } |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 201 | |
Changman Lee | 9c7bb70 | 2014-12-08 15:29:40 +0900 | [diff] [blame] | 202 | /* if the inode is dirty, let's recover all the time */ |
| 203 | if (!datasync && is_inode_flag_set(fi, FI_DIRTY_INODE)) { |
| 204 | update_inode_page(inode); |
| 205 | goto go_write; |
| 206 | } |
| 207 | |
Jaegeuk Kim | 6d99ba41 | 2014-07-24 19:08:02 -0700 | [diff] [blame] | 208 | /* |
| 209 | * if there is no written data, don't waste time to write recovery info. |
| 210 | */ |
| 211 | if (!is_inode_flag_set(fi, FI_APPEND_WRITE) && |
Jaegeuk Kim | 2403c15 | 2014-09-10 14:58:18 -0700 | [diff] [blame] | 212 | !exist_written_data(sbi, ino, APPEND_INO)) { |
Jaegeuk Kim | 19c9c46 | 2014-09-10 15:04:03 -0700 | [diff] [blame] | 213 | |
Changman Lee | 9c7bb70 | 2014-12-08 15:29:40 +0900 | [diff] [blame] | 214 | /* it may call write_inode just prior to fsync */ |
| 215 | if (need_inode_page_update(sbi, ino)) |
Jaegeuk Kim | 19c9c46 | 2014-09-10 15:04:03 -0700 | [diff] [blame] | 216 | goto go_write; |
Jaegeuk Kim | 19c9c46 | 2014-09-10 15:04:03 -0700 | [diff] [blame] | 217 | |
Jaegeuk Kim | 6d99ba41 | 2014-07-24 19:08:02 -0700 | [diff] [blame] | 218 | if (is_inode_flag_set(fi, FI_UPDATE_WRITE) || |
Jaegeuk Kim | 2403c15 | 2014-09-10 14:58:18 -0700 | [diff] [blame] | 219 | exist_written_data(sbi, ino, UPDATE_INO)) |
Jaegeuk Kim | 6d99ba41 | 2014-07-24 19:08:02 -0700 | [diff] [blame] | 220 | goto flush_out; |
| 221 | goto out; |
| 222 | } |
Jaegeuk Kim | 19c9c46 | 2014-09-10 15:04:03 -0700 | [diff] [blame] | 223 | go_write: |
Jaegeuk Kim | 7d82db8 | 2013-01-11 13:10:49 +0900 | [diff] [blame] | 224 | /* guarantee free sections for fsync */ |
| 225 | f2fs_balance_fs(sbi); |
| 226 | |
Jaegeuk Kim | e5d2385 | 2013-07-03 10:55:52 +0900 | [diff] [blame] | 227 | /* |
| 228 | * Both of fdatasync() and fsync() are able to be recovered from |
| 229 | * sudden-power-off. |
| 230 | */ |
Chao Yu | 9d1589e | 2014-08-20 18:37:35 +0800 | [diff] [blame] | 231 | down_read(&fi->i_sem); |
| 232 | need_cp = need_do_checkpoint(inode); |
Jaegeuk Kim | d928bfb | 2014-03-20 19:10:08 +0900 | [diff] [blame] | 233 | up_read(&fi->i_sem); |
| 234 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 235 | if (need_cp) { |
| 236 | /* all the dirty node pages should be flushed for POR */ |
| 237 | ret = f2fs_sync_fs(inode->i_sb, 1); |
Jaegeuk Kim | d928bfb | 2014-03-20 19:10:08 +0900 | [diff] [blame] | 238 | |
Changman Lee | 51455b1 | 2014-12-08 15:29:41 +0900 | [diff] [blame] | 239 | /* |
| 240 | * We've secured consistency through sync_fs. Following pino |
| 241 | * will be used only for fsynced inodes after checkpoint. |
| 242 | */ |
| 243 | try_to_fix_pino(inode); |
Jaegeuk Kim | cff2852 | 2015-03-02 10:48:56 -0800 | [diff] [blame] | 244 | clear_inode_flag(fi, FI_APPEND_WRITE); |
| 245 | clear_inode_flag(fi, FI_UPDATE_WRITE); |
Changman Lee | 51455b1 | 2014-12-08 15:29:41 +0900 | [diff] [blame] | 246 | goto out; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 247 | } |
Changman Lee | 51455b1 | 2014-12-08 15:29:41 +0900 | [diff] [blame] | 248 | sync_nodes: |
| 249 | sync_node_pages(sbi, ino, &wbc); |
| 250 | |
Jaegeuk Kim | 871f599 | 2015-01-09 16:27:17 -0800 | [diff] [blame] | 251 | /* if cp_error was enabled, we should avoid infinite loop */ |
| 252 | if (unlikely(f2fs_cp_error(sbi))) |
| 253 | goto out; |
| 254 | |
Changman Lee | 51455b1 | 2014-12-08 15:29:41 +0900 | [diff] [blame] | 255 | if (need_inode_block_update(sbi, ino)) { |
| 256 | mark_inode_dirty_sync(inode); |
| 257 | f2fs_write_inode(inode, NULL); |
| 258 | goto sync_nodes; |
| 259 | } |
| 260 | |
| 261 | ret = wait_on_node_pages_writeback(sbi, ino); |
| 262 | if (ret) |
| 263 | goto out; |
| 264 | |
| 265 | /* once recovery info is written, don't need to tack this */ |
| 266 | remove_dirty_inode(sbi, ino, APPEND_INO); |
| 267 | clear_inode_flag(fi, FI_APPEND_WRITE); |
| 268 | flush_out: |
| 269 | remove_dirty_inode(sbi, ino, UPDATE_INO); |
| 270 | clear_inode_flag(fi, FI_UPDATE_WRITE); |
| 271 | ret = f2fs_issue_flush(sbi); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 272 | out: |
Namjae Jeon | a2a4a7e | 2013-04-20 01:28:40 +0900 | [diff] [blame] | 273 | trace_f2fs_sync_file_exit(inode, need_cp, datasync, ret); |
Jaegeuk Kim | 05ca363 | 2015-04-23 14:38:15 -0700 | [diff] [blame] | 274 | f2fs_trace_ios(NULL, 1); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 275 | return ret; |
| 276 | } |
| 277 | |
Jaegeuk Kim | 7f7670f | 2014-04-28 18:12:36 +0900 | [diff] [blame] | 278 | static pgoff_t __get_first_dirty_index(struct address_space *mapping, |
| 279 | pgoff_t pgofs, int whence) |
| 280 | { |
| 281 | struct pagevec pvec; |
| 282 | int nr_pages; |
| 283 | |
| 284 | if (whence != SEEK_DATA) |
| 285 | return 0; |
| 286 | |
| 287 | /* find first dirty page index */ |
| 288 | pagevec_init(&pvec, 0); |
Jaegeuk Kim | 65b85cc | 2014-07-30 17:25:54 -0700 | [diff] [blame] | 289 | nr_pages = pagevec_lookup_tag(&pvec, mapping, &pgofs, |
| 290 | PAGECACHE_TAG_DIRTY, 1); |
| 291 | pgofs = nr_pages ? pvec.pages[0]->index : LONG_MAX; |
Jaegeuk Kim | 7f7670f | 2014-04-28 18:12:36 +0900 | [diff] [blame] | 292 | pagevec_release(&pvec); |
| 293 | return pgofs; |
| 294 | } |
| 295 | |
| 296 | static bool __found_offset(block_t blkaddr, pgoff_t dirty, pgoff_t pgofs, |
| 297 | int whence) |
| 298 | { |
| 299 | switch (whence) { |
| 300 | case SEEK_DATA: |
| 301 | if ((blkaddr == NEW_ADDR && dirty == pgofs) || |
| 302 | (blkaddr != NEW_ADDR && blkaddr != NULL_ADDR)) |
| 303 | return true; |
| 304 | break; |
| 305 | case SEEK_HOLE: |
| 306 | if (blkaddr == NULL_ADDR) |
| 307 | return true; |
| 308 | break; |
| 309 | } |
| 310 | return false; |
| 311 | } |
| 312 | |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 313 | static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) |
| 314 | { |
| 315 | struct inode *inode = file->f_mapping->host; |
| 316 | loff_t maxbytes = inode->i_sb->s_maxbytes; |
| 317 | struct dnode_of_data dn; |
Jaegeuk Kim | 7f7670f | 2014-04-28 18:12:36 +0900 | [diff] [blame] | 318 | pgoff_t pgofs, end_offset, dirty; |
| 319 | loff_t data_ofs = offset; |
| 320 | loff_t isize; |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 321 | int err = 0; |
| 322 | |
| 323 | mutex_lock(&inode->i_mutex); |
| 324 | |
| 325 | isize = i_size_read(inode); |
| 326 | if (offset >= isize) |
| 327 | goto fail; |
| 328 | |
| 329 | /* handle inline data case */ |
Chao Yu | 622f28a | 2014-09-24 18:19:10 +0800 | [diff] [blame] | 330 | if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode)) { |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 331 | if (whence == SEEK_HOLE) |
| 332 | data_ofs = isize; |
| 333 | goto found; |
| 334 | } |
| 335 | |
| 336 | pgofs = (pgoff_t)(offset >> PAGE_CACHE_SHIFT); |
| 337 | |
Jaegeuk Kim | 7f7670f | 2014-04-28 18:12:36 +0900 | [diff] [blame] | 338 | dirty = __get_first_dirty_index(inode->i_mapping, pgofs, whence); |
| 339 | |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 340 | for (; data_ofs < isize; data_ofs = pgofs << PAGE_CACHE_SHIFT) { |
| 341 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
| 342 | err = get_dnode_of_data(&dn, pgofs, LOOKUP_NODE_RA); |
| 343 | if (err && err != -ENOENT) { |
| 344 | goto fail; |
| 345 | } else if (err == -ENOENT) { |
arter97 | e1c4204 | 2014-08-06 23:22:50 +0900 | [diff] [blame] | 346 | /* direct node does not exists */ |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 347 | if (whence == SEEK_DATA) { |
| 348 | pgofs = PGOFS_OF_NEXT_DNODE(pgofs, |
| 349 | F2FS_I(inode)); |
| 350 | continue; |
| 351 | } else { |
| 352 | goto found; |
| 353 | } |
| 354 | } |
| 355 | |
Chao Yu | 6b2920a | 2014-07-07 11:21:59 +0800 | [diff] [blame] | 356 | end_offset = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode)); |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 357 | |
| 358 | /* find data/hole in dnode block */ |
| 359 | for (; dn.ofs_in_node < end_offset; |
| 360 | dn.ofs_in_node++, pgofs++, |
Chao Yu | 2e02317 | 2015-02-09 11:23:58 +0800 | [diff] [blame] | 361 | data_ofs = (loff_t)pgofs << PAGE_CACHE_SHIFT) { |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 362 | block_t blkaddr; |
| 363 | blkaddr = datablock_addr(dn.node_page, dn.ofs_in_node); |
| 364 | |
Jaegeuk Kim | 7f7670f | 2014-04-28 18:12:36 +0900 | [diff] [blame] | 365 | if (__found_offset(blkaddr, dirty, pgofs, whence)) { |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 366 | f2fs_put_dnode(&dn); |
| 367 | goto found; |
| 368 | } |
| 369 | } |
| 370 | f2fs_put_dnode(&dn); |
| 371 | } |
| 372 | |
| 373 | if (whence == SEEK_DATA) |
| 374 | goto fail; |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 375 | found: |
Jaegeuk Kim | fe369bc | 2014-04-28 17:02:48 +0900 | [diff] [blame] | 376 | if (whence == SEEK_HOLE && data_ofs > isize) |
| 377 | data_ofs = isize; |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 378 | mutex_unlock(&inode->i_mutex); |
| 379 | return vfs_setpos(file, data_ofs, maxbytes); |
| 380 | fail: |
| 381 | mutex_unlock(&inode->i_mutex); |
| 382 | return -ENXIO; |
| 383 | } |
| 384 | |
| 385 | static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence) |
| 386 | { |
| 387 | struct inode *inode = file->f_mapping->host; |
| 388 | loff_t maxbytes = inode->i_sb->s_maxbytes; |
| 389 | |
| 390 | switch (whence) { |
| 391 | case SEEK_SET: |
| 392 | case SEEK_CUR: |
| 393 | case SEEK_END: |
| 394 | return generic_file_llseek_size(file, offset, whence, |
| 395 | maxbytes, i_size_read(inode)); |
| 396 | case SEEK_DATA: |
| 397 | case SEEK_HOLE: |
Jaegeuk Kim | 0b4c5afde | 2014-09-08 10:59:43 -0700 | [diff] [blame] | 398 | if (offset < 0) |
| 399 | return -ENXIO; |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 400 | return f2fs_seek_block(file, offset, whence); |
| 401 | } |
| 402 | |
| 403 | return -EINVAL; |
| 404 | } |
| 405 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 406 | static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma) |
| 407 | { |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 408 | struct inode *inode = file_inode(file); |
| 409 | |
| 410 | /* we don't need to use inline_data strictly */ |
| 411 | if (f2fs_has_inline_data(inode)) { |
| 412 | int err = f2fs_convert_inline_inode(inode); |
| 413 | if (err) |
| 414 | return err; |
| 415 | } |
| 416 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 417 | file_accessed(file); |
| 418 | vma->vm_ops = &f2fs_file_vm_ops; |
| 419 | return 0; |
| 420 | } |
| 421 | |
Jaegeuk Kim | b292dcab | 2013-05-22 08:02:02 +0900 | [diff] [blame] | 422 | int truncate_data_blocks_range(struct dnode_of_data *dn, int count) |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 423 | { |
| 424 | int nr_free = 0, ofs = dn->ofs_in_node; |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 425 | struct f2fs_sb_info *sbi = F2FS_I_SB(dn->inode); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 426 | struct f2fs_node *raw_node; |
| 427 | __le32 *addr; |
| 428 | |
Gu Zheng | 4559071 | 2013-07-15 17:57:38 +0800 | [diff] [blame] | 429 | raw_node = F2FS_NODE(dn->node_page); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 430 | addr = blkaddr_in_node(raw_node) + ofs; |
| 431 | |
Chris Fries | 6c311ec | 2014-01-17 14:44:39 -0600 | [diff] [blame] | 432 | for (; count > 0; count--, addr++, dn->ofs_in_node++) { |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 433 | block_t blkaddr = le32_to_cpu(*addr); |
| 434 | if (blkaddr == NULL_ADDR) |
| 435 | continue; |
| 436 | |
Jaegeuk Kim | e1509cf | 2014-12-30 22:57:55 -0800 | [diff] [blame] | 437 | dn->data_blkaddr = NULL_ADDR; |
Chao Yu | 216a620 | 2015-03-19 19:23:32 +0800 | [diff] [blame] | 438 | set_data_blkaddr(dn); |
Chao Yu | 7e4dde7 | 2015-02-05 17:51:34 +0800 | [diff] [blame] | 439 | f2fs_update_extent_cache(dn); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 440 | invalidate_blocks(sbi, blkaddr); |
Jaegeuk Kim | 3c6c2be | 2015-03-17 17:16:35 -0700 | [diff] [blame] | 441 | if (dn->ofs_in_node == 0 && IS_INODE(dn->node_page)) |
| 442 | clear_inode_flag(F2FS_I(dn->inode), |
| 443 | FI_FIRST_BLOCK_WRITTEN); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 444 | nr_free++; |
| 445 | } |
| 446 | if (nr_free) { |
Namjae Jeon | d7cc950 | 2013-06-08 21:25:40 +0900 | [diff] [blame] | 447 | dec_valid_block_count(sbi, dn->inode, nr_free); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 448 | set_page_dirty(dn->node_page); |
| 449 | sync_inode_page(dn); |
| 450 | } |
| 451 | dn->ofs_in_node = ofs; |
Namjae Jeon | 51dd624 | 2013-04-20 01:28:52 +0900 | [diff] [blame] | 452 | |
| 453 | trace_f2fs_truncate_data_blocks_range(dn->inode, dn->nid, |
| 454 | dn->ofs_in_node, nr_free); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 455 | return nr_free; |
| 456 | } |
| 457 | |
| 458 | void truncate_data_blocks(struct dnode_of_data *dn) |
| 459 | { |
| 460 | truncate_data_blocks_range(dn, ADDRS_PER_BLOCK); |
| 461 | } |
| 462 | |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 463 | static int truncate_partial_data_page(struct inode *inode, u64 from, |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 464 | bool cache_only) |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 465 | { |
| 466 | unsigned offset = from & (PAGE_CACHE_SIZE - 1); |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 467 | pgoff_t index = from >> PAGE_CACHE_SHIFT; |
| 468 | struct address_space *mapping = inode->i_mapping; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 469 | struct page *page; |
| 470 | |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 471 | if (!offset && !cache_only) |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 472 | return 0; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 473 | |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 474 | if (cache_only) { |
| 475 | page = grab_cache_page(mapping, index); |
| 476 | if (page && PageUptodate(page)) |
| 477 | goto truncate_out; |
| 478 | f2fs_put_page(page, 1); |
| 479 | return 0; |
| 480 | } |
| 481 | |
| 482 | page = get_lock_data_page(inode, index); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 483 | if (IS_ERR(page)) |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 484 | return 0; |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 485 | truncate_out: |
Jaegeuk Kim | 3cb5ad1 | 2014-03-18 13:29:07 +0900 | [diff] [blame] | 486 | f2fs_wait_on_page_writeback(page, DATA); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 487 | zero_user(page, offset, PAGE_CACHE_SIZE - offset); |
Jaegeuk Kim | 43f3eae | 2015-04-30 17:00:33 -0700 | [diff] [blame] | 488 | if (!cache_only) |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 489 | set_page_dirty(page); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 490 | f2fs_put_page(page, 1); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 491 | return 0; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 492 | } |
| 493 | |
Jaegeuk Kim | 764aa3e | 2014-08-14 16:32:54 -0700 | [diff] [blame] | 494 | int truncate_blocks(struct inode *inode, u64 from, bool lock) |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 495 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 496 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 497 | unsigned int blocksize = inode->i_sb->s_blocksize; |
| 498 | struct dnode_of_data dn; |
| 499 | pgoff_t free_from; |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 500 | int count = 0, err = 0; |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 501 | struct page *ipage; |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 502 | bool truncate_page = false; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 503 | |
Namjae Jeon | 51dd624 | 2013-04-20 01:28:52 +0900 | [diff] [blame] | 504 | trace_f2fs_truncate_blocks_enter(inode, from); |
| 505 | |
Jaegeuk Kim | f7ef9b8 | 2015-02-09 12:02:44 -0800 | [diff] [blame] | 506 | free_from = (pgoff_t)F2FS_BYTES_TO_BLK(from + blocksize - 1); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 507 | |
Jaegeuk Kim | 764aa3e | 2014-08-14 16:32:54 -0700 | [diff] [blame] | 508 | if (lock) |
| 509 | f2fs_lock_op(sbi); |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 510 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 511 | ipage = get_node_page(sbi, inode->i_ino); |
| 512 | if (IS_ERR(ipage)) { |
| 513 | err = PTR_ERR(ipage); |
| 514 | goto out; |
| 515 | } |
| 516 | |
| 517 | if (f2fs_has_inline_data(inode)) { |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 518 | if (truncate_inline_inode(ipage, from)) |
| 519 | set_page_dirty(ipage); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 520 | f2fs_put_page(ipage, 1); |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 521 | truncate_page = true; |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 522 | goto out; |
| 523 | } |
| 524 | |
| 525 | set_new_dnode(&dn, inode, ipage, NULL, 0); |
Jaegeuk Kim | 266e97a | 2013-02-26 13:10:46 +0900 | [diff] [blame] | 526 | err = get_dnode_of_data(&dn, free_from, LOOKUP_NODE); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 527 | if (err) { |
| 528 | if (err == -ENOENT) |
| 529 | goto free_next; |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 530 | goto out; |
Jaegeuk Kim | 1ce86bf | 2014-10-15 10:24:34 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Chao Yu | 6403eb1 | 2014-04-26 19:59:52 +0800 | [diff] [blame] | 533 | count = ADDRS_PER_PAGE(dn.node_page, F2FS_I(inode)); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 534 | |
| 535 | count -= dn.ofs_in_node; |
Jaegeuk Kim | 9850cf4 | 2014-09-02 15:52:58 -0700 | [diff] [blame] | 536 | f2fs_bug_on(sbi, count < 0); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 537 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 538 | if (dn.ofs_in_node || IS_INODE(dn.node_page)) { |
| 539 | truncate_data_blocks_range(&dn, count); |
| 540 | free_from += count; |
| 541 | } |
| 542 | |
| 543 | f2fs_put_dnode(&dn); |
| 544 | free_next: |
| 545 | err = truncate_inode_blocks(inode, free_from); |
Jaegeuk Kim | 764d2c8 | 2014-11-11 11:01:01 -0800 | [diff] [blame] | 546 | out: |
| 547 | if (lock) |
| 548 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 549 | |
| 550 | /* lastly zero out the first data page */ |
| 551 | if (!err) |
Chao Yu | 0bfcfcc | 2015-03-10 13:16:25 +0800 | [diff] [blame] | 552 | err = truncate_partial_data_page(inode, from, truncate_page); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 553 | |
Namjae Jeon | 51dd624 | 2013-04-20 01:28:52 +0900 | [diff] [blame] | 554 | trace_f2fs_truncate_blocks_exit(inode, err); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 555 | return err; |
| 556 | } |
| 557 | |
| 558 | void f2fs_truncate(struct inode *inode) |
| 559 | { |
| 560 | if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || |
| 561 | S_ISLNK(inode->i_mode))) |
| 562 | return; |
| 563 | |
Namjae Jeon | 51dd624 | 2013-04-20 01:28:52 +0900 | [diff] [blame] | 564 | trace_f2fs_truncate(inode); |
| 565 | |
Jaegeuk Kim | 92dffd0 | 2014-11-11 14:10:01 -0800 | [diff] [blame] | 566 | /* we should check inline_data size */ |
Jaegeuk Kim | 01b960e | 2015-04-23 10:27:21 -0700 | [diff] [blame] | 567 | if (f2fs_has_inline_data(inode) && !f2fs_may_inline_data(inode)) { |
Jaegeuk Kim | 92dffd0 | 2014-11-11 14:10:01 -0800 | [diff] [blame] | 568 | if (f2fs_convert_inline_inode(inode)) |
| 569 | return; |
| 570 | } |
| 571 | |
Jaegeuk Kim | 764aa3e | 2014-08-14 16:32:54 -0700 | [diff] [blame] | 572 | if (!truncate_blocks(inode, i_size_read(inode), true)) { |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 573 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 574 | mark_inode_dirty(inode); |
| 575 | } |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 576 | } |
| 577 | |
Jaegeuk Kim | 2d4d9fb5 | 2013-06-07 16:33:07 +0900 | [diff] [blame] | 578 | int f2fs_getattr(struct vfsmount *mnt, |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 579 | struct dentry *dentry, struct kstat *stat) |
| 580 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 581 | struct inode *inode = d_inode(dentry); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 582 | generic_fillattr(inode, stat); |
| 583 | stat->blocks <<= 3; |
| 584 | return 0; |
| 585 | } |
| 586 | |
| 587 | #ifdef CONFIG_F2FS_FS_POSIX_ACL |
| 588 | static void __setattr_copy(struct inode *inode, const struct iattr *attr) |
| 589 | { |
| 590 | struct f2fs_inode_info *fi = F2FS_I(inode); |
| 591 | unsigned int ia_valid = attr->ia_valid; |
| 592 | |
| 593 | if (ia_valid & ATTR_UID) |
| 594 | inode->i_uid = attr->ia_uid; |
| 595 | if (ia_valid & ATTR_GID) |
| 596 | inode->i_gid = attr->ia_gid; |
| 597 | if (ia_valid & ATTR_ATIME) |
| 598 | inode->i_atime = timespec_trunc(attr->ia_atime, |
| 599 | inode->i_sb->s_time_gran); |
| 600 | if (ia_valid & ATTR_MTIME) |
| 601 | inode->i_mtime = timespec_trunc(attr->ia_mtime, |
| 602 | inode->i_sb->s_time_gran); |
| 603 | if (ia_valid & ATTR_CTIME) |
| 604 | inode->i_ctime = timespec_trunc(attr->ia_ctime, |
| 605 | inode->i_sb->s_time_gran); |
| 606 | if (ia_valid & ATTR_MODE) { |
| 607 | umode_t mode = attr->ia_mode; |
| 608 | |
| 609 | if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID)) |
| 610 | mode &= ~S_ISGID; |
| 611 | set_acl_inode(fi, mode); |
| 612 | } |
| 613 | } |
| 614 | #else |
| 615 | #define __setattr_copy setattr_copy |
| 616 | #endif |
| 617 | |
| 618 | int f2fs_setattr(struct dentry *dentry, struct iattr *attr) |
| 619 | { |
David Howells | 2b0143b | 2015-03-17 22:25:59 +0000 | [diff] [blame] | 620 | struct inode *inode = d_inode(dentry); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 621 | struct f2fs_inode_info *fi = F2FS_I(inode); |
| 622 | int err; |
| 623 | |
| 624 | err = inode_change_ok(inode, attr); |
| 625 | if (err) |
| 626 | return err; |
| 627 | |
Chao Yu | 09db6a2 | 2014-09-15 18:02:09 +0800 | [diff] [blame] | 628 | if (attr->ia_valid & ATTR_SIZE) { |
Chao Yu | 09db6a2 | 2014-09-15 18:02:09 +0800 | [diff] [blame] | 629 | if (attr->ia_size != i_size_read(inode)) { |
| 630 | truncate_setsize(inode, attr->ia_size); |
| 631 | f2fs_truncate(inode); |
| 632 | f2fs_balance_fs(F2FS_I_SB(inode)); |
| 633 | } else { |
| 634 | /* |
| 635 | * giving a chance to truncate blocks past EOF which |
| 636 | * are fallocated with FALLOC_FL_KEEP_SIZE. |
| 637 | */ |
| 638 | f2fs_truncate(inode); |
| 639 | } |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 640 | } |
| 641 | |
| 642 | __setattr_copy(inode, attr); |
| 643 | |
| 644 | if (attr->ia_valid & ATTR_MODE) { |
Christoph Hellwig | a6dda0e | 2013-12-20 05:16:45 -0800 | [diff] [blame] | 645 | err = posix_acl_chmod(inode, get_inode_mode(inode)); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 646 | if (err || is_inode_flag_set(fi, FI_ACL_MODE)) { |
| 647 | inode->i_mode = fi->i_acl_mode; |
| 648 | clear_inode_flag(fi, FI_ACL_MODE); |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | mark_inode_dirty(inode); |
| 653 | return err; |
| 654 | } |
| 655 | |
| 656 | const struct inode_operations f2fs_file_inode_operations = { |
| 657 | .getattr = f2fs_getattr, |
| 658 | .setattr = f2fs_setattr, |
| 659 | .get_acl = f2fs_get_acl, |
Christoph Hellwig | a6dda0e | 2013-12-20 05:16:45 -0800 | [diff] [blame] | 660 | .set_acl = f2fs_set_acl, |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 661 | #ifdef CONFIG_F2FS_FS_XATTR |
| 662 | .setxattr = generic_setxattr, |
| 663 | .getxattr = generic_getxattr, |
| 664 | .listxattr = f2fs_listxattr, |
| 665 | .removexattr = generic_removexattr, |
| 666 | #endif |
Jaegeuk Kim | 9ab7013 | 2014-06-08 04:30:14 +0900 | [diff] [blame] | 667 | .fiemap = f2fs_fiemap, |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 668 | }; |
| 669 | |
| 670 | static void fill_zero(struct inode *inode, pgoff_t index, |
| 671 | loff_t start, loff_t len) |
| 672 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 673 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 674 | struct page *page; |
| 675 | |
| 676 | if (!len) |
| 677 | return; |
| 678 | |
Jaegeuk Kim | bd43df0 | 2013-01-25 18:33:41 +0900 | [diff] [blame] | 679 | f2fs_balance_fs(sbi); |
| 680 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 681 | f2fs_lock_op(sbi); |
Jaegeuk Kim | 64aa7ed | 2013-05-20 09:55:50 +0900 | [diff] [blame] | 682 | page = get_new_data_page(inode, NULL, index, false); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 683 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 684 | |
| 685 | if (!IS_ERR(page)) { |
Jaegeuk Kim | 3cb5ad1 | 2014-03-18 13:29:07 +0900 | [diff] [blame] | 686 | f2fs_wait_on_page_writeback(page, DATA); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 687 | zero_user(page, start, len); |
| 688 | set_page_dirty(page); |
| 689 | f2fs_put_page(page, 1); |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | int truncate_hole(struct inode *inode, pgoff_t pg_start, pgoff_t pg_end) |
| 694 | { |
| 695 | pgoff_t index; |
| 696 | int err; |
| 697 | |
| 698 | for (index = pg_start; index < pg_end; index++) { |
| 699 | struct dnode_of_data dn; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 700 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 701 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
Jaegeuk Kim | 266e97a | 2013-02-26 13:10:46 +0900 | [diff] [blame] | 702 | err = get_dnode_of_data(&dn, index, LOOKUP_NODE); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 703 | if (err) { |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 704 | if (err == -ENOENT) |
| 705 | continue; |
| 706 | return err; |
| 707 | } |
| 708 | |
| 709 | if (dn.data_blkaddr != NULL_ADDR) |
| 710 | truncate_data_blocks_range(&dn, 1); |
| 711 | f2fs_put_dnode(&dn); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 712 | } |
| 713 | return 0; |
| 714 | } |
| 715 | |
Chao Yu | a66c7b2 | 2013-11-22 16:52:50 +0800 | [diff] [blame] | 716 | static int punch_hole(struct inode *inode, loff_t offset, loff_t len) |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 717 | { |
| 718 | pgoff_t pg_start, pg_end; |
| 719 | loff_t off_start, off_end; |
| 720 | int ret = 0; |
| 721 | |
Chao Yu | 14cecc5 | 2014-09-15 18:03:32 +0800 | [diff] [blame] | 722 | if (!S_ISREG(inode->i_mode)) |
| 723 | return -EOPNOTSUPP; |
| 724 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 725 | if (f2fs_has_inline_data(inode)) { |
| 726 | ret = f2fs_convert_inline_inode(inode); |
| 727 | if (ret) |
| 728 | return ret; |
| 729 | } |
Huajun Li | 9ffe0fb | 2013-11-10 23:13:20 +0800 | [diff] [blame] | 730 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 731 | pg_start = ((unsigned long long) offset) >> PAGE_CACHE_SHIFT; |
| 732 | pg_end = ((unsigned long long) offset + len) >> PAGE_CACHE_SHIFT; |
| 733 | |
| 734 | off_start = offset & (PAGE_CACHE_SIZE - 1); |
| 735 | off_end = (offset + len) & (PAGE_CACHE_SIZE - 1); |
| 736 | |
| 737 | if (pg_start == pg_end) { |
| 738 | fill_zero(inode, pg_start, off_start, |
| 739 | off_end - off_start); |
| 740 | } else { |
| 741 | if (off_start) |
| 742 | fill_zero(inode, pg_start++, off_start, |
| 743 | PAGE_CACHE_SIZE - off_start); |
| 744 | if (off_end) |
| 745 | fill_zero(inode, pg_end, 0, off_end); |
| 746 | |
| 747 | if (pg_start < pg_end) { |
| 748 | struct address_space *mapping = inode->i_mapping; |
| 749 | loff_t blk_start, blk_end; |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 750 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jason Hrycay | 1127a3d | 2013-04-08 20:16:44 -0500 | [diff] [blame] | 751 | |
| 752 | f2fs_balance_fs(sbi); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 753 | |
| 754 | blk_start = pg_start << PAGE_CACHE_SHIFT; |
| 755 | blk_end = pg_end << PAGE_CACHE_SHIFT; |
| 756 | truncate_inode_pages_range(mapping, blk_start, |
| 757 | blk_end - 1); |
Jaegeuk Kim | 3993683 | 2012-11-22 16:21:29 +0900 | [diff] [blame] | 758 | |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 759 | f2fs_lock_op(sbi); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 760 | ret = truncate_hole(inode, pg_start, pg_end); |
Gu Zheng | e479556 | 2013-09-27 18:08:30 +0800 | [diff] [blame] | 761 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 765 | return ret; |
| 766 | } |
| 767 | |
Chao Yu | b4ace33 | 2015-05-06 13:09:46 +0800 | [diff] [blame] | 768 | static int f2fs_do_collapse(struct inode *inode, pgoff_t start, pgoff_t end) |
| 769 | { |
| 770 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 771 | struct dnode_of_data dn; |
| 772 | pgoff_t nrpages = (i_size_read(inode) + PAGE_SIZE - 1) / PAGE_SIZE; |
| 773 | int ret = 0; |
| 774 | |
| 775 | f2fs_lock_op(sbi); |
| 776 | |
| 777 | for (; end < nrpages; start++, end++) { |
| 778 | block_t new_addr, old_addr; |
| 779 | |
| 780 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
| 781 | ret = get_dnode_of_data(&dn, end, LOOKUP_NODE_RA); |
| 782 | if (ret && ret != -ENOENT) { |
| 783 | goto out; |
| 784 | } else if (ret == -ENOENT) { |
| 785 | new_addr = NULL_ADDR; |
| 786 | } else { |
| 787 | new_addr = dn.data_blkaddr; |
| 788 | truncate_data_blocks_range(&dn, 1); |
| 789 | f2fs_put_dnode(&dn); |
| 790 | } |
| 791 | |
| 792 | if (new_addr == NULL_ADDR) { |
| 793 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
| 794 | ret = get_dnode_of_data(&dn, start, LOOKUP_NODE_RA); |
| 795 | if (ret && ret != -ENOENT) |
| 796 | goto out; |
| 797 | else if (ret == -ENOENT) |
| 798 | continue; |
| 799 | |
| 800 | if (dn.data_blkaddr == NULL_ADDR) { |
| 801 | f2fs_put_dnode(&dn); |
| 802 | continue; |
| 803 | } else { |
| 804 | truncate_data_blocks_range(&dn, 1); |
| 805 | } |
| 806 | |
| 807 | f2fs_put_dnode(&dn); |
| 808 | } else { |
| 809 | struct page *ipage; |
| 810 | |
| 811 | ipage = get_node_page(sbi, inode->i_ino); |
| 812 | if (IS_ERR(ipage)) { |
| 813 | ret = PTR_ERR(ipage); |
| 814 | goto out; |
| 815 | } |
| 816 | |
| 817 | set_new_dnode(&dn, inode, ipage, NULL, 0); |
| 818 | ret = f2fs_reserve_block(&dn, start); |
| 819 | if (ret) |
| 820 | goto out; |
| 821 | |
| 822 | old_addr = dn.data_blkaddr; |
| 823 | if (old_addr != NEW_ADDR && new_addr == NEW_ADDR) { |
| 824 | dn.data_blkaddr = NULL_ADDR; |
| 825 | f2fs_update_extent_cache(&dn); |
| 826 | invalidate_blocks(sbi, old_addr); |
| 827 | |
| 828 | dn.data_blkaddr = new_addr; |
| 829 | set_data_blkaddr(&dn); |
| 830 | } else if (new_addr != NEW_ADDR) { |
| 831 | struct node_info ni; |
| 832 | struct f2fs_summary sum; |
| 833 | |
| 834 | get_node_info(sbi, dn.nid, &ni); |
| 835 | set_summary(&sum, dn.nid, dn.ofs_in_node, |
| 836 | ni.version); |
| 837 | |
| 838 | f2fs_replace_block(sbi, &sum, old_addr, |
| 839 | new_addr, true); |
| 840 | |
| 841 | dn.data_blkaddr = new_addr; |
| 842 | set_data_blkaddr(&dn); |
| 843 | f2fs_update_extent_cache(&dn); |
| 844 | } |
| 845 | |
| 846 | f2fs_put_dnode(&dn); |
| 847 | } |
| 848 | } |
| 849 | ret = 0; |
| 850 | out: |
| 851 | f2fs_unlock_op(sbi); |
| 852 | return ret; |
| 853 | } |
| 854 | |
| 855 | static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len) |
| 856 | { |
| 857 | pgoff_t pg_start, pg_end; |
| 858 | loff_t new_size; |
| 859 | int ret; |
| 860 | |
| 861 | if (!S_ISREG(inode->i_mode)) |
| 862 | return -EINVAL; |
| 863 | |
| 864 | if (offset + len >= i_size_read(inode)) |
| 865 | return -EINVAL; |
| 866 | |
| 867 | /* collapse range should be aligned to block size of f2fs. */ |
| 868 | if (offset & (F2FS_BLKSIZE - 1) || len & (F2FS_BLKSIZE - 1)) |
| 869 | return -EINVAL; |
| 870 | |
| 871 | pg_start = offset >> PAGE_CACHE_SHIFT; |
| 872 | pg_end = (offset + len) >> PAGE_CACHE_SHIFT; |
| 873 | |
| 874 | /* write out all dirty pages from offset */ |
| 875 | ret = filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); |
| 876 | if (ret) |
| 877 | return ret; |
| 878 | |
| 879 | truncate_pagecache(inode, offset); |
| 880 | |
| 881 | ret = f2fs_do_collapse(inode, pg_start, pg_end); |
| 882 | if (ret) |
| 883 | return ret; |
| 884 | |
| 885 | new_size = i_size_read(inode) - len; |
| 886 | |
| 887 | ret = truncate_blocks(inode, new_size, true); |
| 888 | if (!ret) |
| 889 | i_size_write(inode, new_size); |
| 890 | |
| 891 | return ret; |
| 892 | } |
| 893 | |
Chao Yu | 75cd4e0 | 2015-05-06 13:11:13 +0800 | [diff] [blame^] | 894 | static int f2fs_zero_range(struct inode *inode, loff_t offset, loff_t len, |
| 895 | int mode) |
| 896 | { |
| 897 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 898 | struct address_space *mapping = inode->i_mapping; |
| 899 | pgoff_t index, pg_start, pg_end; |
| 900 | loff_t new_size = i_size_read(inode); |
| 901 | loff_t off_start, off_end; |
| 902 | int ret = 0; |
| 903 | |
| 904 | if (!S_ISREG(inode->i_mode)) |
| 905 | return -EINVAL; |
| 906 | |
| 907 | ret = inode_newsize_ok(inode, (len + offset)); |
| 908 | if (ret) |
| 909 | return ret; |
| 910 | |
| 911 | f2fs_balance_fs(sbi); |
| 912 | |
| 913 | if (f2fs_has_inline_data(inode)) { |
| 914 | ret = f2fs_convert_inline_inode(inode); |
| 915 | if (ret) |
| 916 | return ret; |
| 917 | } |
| 918 | |
| 919 | ret = filemap_write_and_wait_range(mapping, offset, offset + len - 1); |
| 920 | if (ret) |
| 921 | return ret; |
| 922 | |
| 923 | truncate_pagecache_range(inode, offset, offset + len - 1); |
| 924 | |
| 925 | pg_start = ((unsigned long long) offset) >> PAGE_CACHE_SHIFT; |
| 926 | pg_end = ((unsigned long long) offset + len) >> PAGE_CACHE_SHIFT; |
| 927 | |
| 928 | off_start = offset & (PAGE_CACHE_SIZE - 1); |
| 929 | off_end = (offset + len) & (PAGE_CACHE_SIZE - 1); |
| 930 | |
| 931 | if (pg_start == pg_end) { |
| 932 | fill_zero(inode, pg_start, off_start, off_end - off_start); |
| 933 | if (offset + len > new_size) |
| 934 | new_size = offset + len; |
| 935 | new_size = max_t(loff_t, new_size, offset + len); |
| 936 | } else { |
| 937 | if (off_start) { |
| 938 | fill_zero(inode, pg_start++, off_start, |
| 939 | PAGE_CACHE_SIZE - off_start); |
| 940 | new_size = max_t(loff_t, new_size, |
| 941 | pg_start << PAGE_CACHE_SHIFT); |
| 942 | } |
| 943 | |
| 944 | for (index = pg_start; index < pg_end; index++) { |
| 945 | struct dnode_of_data dn; |
| 946 | struct page *ipage; |
| 947 | |
| 948 | f2fs_lock_op(sbi); |
| 949 | |
| 950 | ipage = get_node_page(sbi, inode->i_ino); |
| 951 | if (IS_ERR(ipage)) { |
| 952 | ret = PTR_ERR(ipage); |
| 953 | f2fs_unlock_op(sbi); |
| 954 | goto out; |
| 955 | } |
| 956 | |
| 957 | set_new_dnode(&dn, inode, ipage, NULL, 0); |
| 958 | ret = f2fs_reserve_block(&dn, index); |
| 959 | if (ret) { |
| 960 | f2fs_unlock_op(sbi); |
| 961 | goto out; |
| 962 | } |
| 963 | |
| 964 | if (dn.data_blkaddr != NEW_ADDR) { |
| 965 | invalidate_blocks(sbi, dn.data_blkaddr); |
| 966 | |
| 967 | dn.data_blkaddr = NEW_ADDR; |
| 968 | set_data_blkaddr(&dn); |
| 969 | |
| 970 | dn.data_blkaddr = NULL_ADDR; |
| 971 | f2fs_update_extent_cache(&dn); |
| 972 | } |
| 973 | f2fs_put_dnode(&dn); |
| 974 | f2fs_unlock_op(sbi); |
| 975 | |
| 976 | new_size = max_t(loff_t, new_size, |
| 977 | (index + 1) << PAGE_CACHE_SHIFT); |
| 978 | } |
| 979 | |
| 980 | if (off_end) { |
| 981 | fill_zero(inode, pg_end, 0, off_end); |
| 982 | new_size = max_t(loff_t, new_size, offset + len); |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | out: |
| 987 | if (!(mode & FALLOC_FL_KEEP_SIZE) && i_size_read(inode) < new_size) { |
| 988 | i_size_write(inode, new_size); |
| 989 | mark_inode_dirty(inode); |
| 990 | update_inode_page(inode); |
| 991 | } |
| 992 | |
| 993 | return ret; |
| 994 | } |
| 995 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 996 | static int expand_inode_data(struct inode *inode, loff_t offset, |
| 997 | loff_t len, int mode) |
| 998 | { |
Jaegeuk Kim | 4081363 | 2014-09-02 15:31:18 -0700 | [diff] [blame] | 999 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1000 | pgoff_t index, pg_start, pg_end; |
| 1001 | loff_t new_size = i_size_read(inode); |
| 1002 | loff_t off_start, off_end; |
| 1003 | int ret = 0; |
| 1004 | |
Chao Yu | 497a093 | 2014-08-04 10:11:17 +0800 | [diff] [blame] | 1005 | f2fs_balance_fs(sbi); |
| 1006 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1007 | ret = inode_newsize_ok(inode, (len + offset)); |
| 1008 | if (ret) |
| 1009 | return ret; |
| 1010 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 1011 | if (f2fs_has_inline_data(inode)) { |
| 1012 | ret = f2fs_convert_inline_inode(inode); |
| 1013 | if (ret) |
| 1014 | return ret; |
| 1015 | } |
Jaegeuk Kim | 9e09fc8 | 2013-12-27 12:28:59 +0900 | [diff] [blame] | 1016 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1017 | pg_start = ((unsigned long long) offset) >> PAGE_CACHE_SHIFT; |
| 1018 | pg_end = ((unsigned long long) offset + len) >> PAGE_CACHE_SHIFT; |
| 1019 | |
| 1020 | off_start = offset & (PAGE_CACHE_SIZE - 1); |
| 1021 | off_end = (offset + len) & (PAGE_CACHE_SIZE - 1); |
| 1022 | |
Jaegeuk Kim | ead4327 | 2014-06-13 13:05:55 +0900 | [diff] [blame] | 1023 | f2fs_lock_op(sbi); |
| 1024 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1025 | for (index = pg_start; index <= pg_end; index++) { |
| 1026 | struct dnode_of_data dn; |
| 1027 | |
Jaegeuk Kim | 98397ff | 2014-06-13 13:07:31 +0900 | [diff] [blame] | 1028 | if (index == pg_end && !off_end) |
| 1029 | goto noalloc; |
| 1030 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1031 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
Huajun Li | b600965 | 2013-11-10 23:13:18 +0800 | [diff] [blame] | 1032 | ret = f2fs_reserve_block(&dn, index); |
Huajun Li | b600965 | 2013-11-10 23:13:18 +0800 | [diff] [blame] | 1033 | if (ret) |
| 1034 | break; |
Jaegeuk Kim | 98397ff | 2014-06-13 13:07:31 +0900 | [diff] [blame] | 1035 | noalloc: |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1036 | if (pg_start == pg_end) |
| 1037 | new_size = offset + len; |
| 1038 | else if (index == pg_start && off_start) |
| 1039 | new_size = (index + 1) << PAGE_CACHE_SHIFT; |
| 1040 | else if (index == pg_end) |
| 1041 | new_size = (index << PAGE_CACHE_SHIFT) + off_end; |
| 1042 | else |
| 1043 | new_size += PAGE_CACHE_SIZE; |
| 1044 | } |
| 1045 | |
| 1046 | if (!(mode & FALLOC_FL_KEEP_SIZE) && |
| 1047 | i_size_read(inode) < new_size) { |
| 1048 | i_size_write(inode, new_size); |
| 1049 | mark_inode_dirty(inode); |
Jaegeuk Kim | ead4327 | 2014-06-13 13:05:55 +0900 | [diff] [blame] | 1050 | update_inode_page(inode); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1051 | } |
Jaegeuk Kim | ead4327 | 2014-06-13 13:05:55 +0900 | [diff] [blame] | 1052 | f2fs_unlock_op(sbi); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1053 | |
| 1054 | return ret; |
| 1055 | } |
| 1056 | |
| 1057 | static long f2fs_fallocate(struct file *file, int mode, |
| 1058 | loff_t offset, loff_t len) |
| 1059 | { |
Al Viro | 6131ffa | 2013-02-27 16:59:05 -0500 | [diff] [blame] | 1060 | struct inode *inode = file_inode(file); |
Taehee Yoo | 587c0a4 | 2015-04-21 15:59:12 +0900 | [diff] [blame] | 1061 | long ret = 0; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1062 | |
Chao Yu | b4ace33 | 2015-05-06 13:09:46 +0800 | [diff] [blame] | 1063 | if (mode & ~(FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE | |
Chao Yu | 75cd4e0 | 2015-05-06 13:11:13 +0800 | [diff] [blame^] | 1064 | FALLOC_FL_COLLAPSE_RANGE | FALLOC_FL_ZERO_RANGE)) |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1065 | return -EOPNOTSUPP; |
| 1066 | |
Chao Yu | 3375f69 | 2014-01-28 10:29:26 +0800 | [diff] [blame] | 1067 | mutex_lock(&inode->i_mutex); |
| 1068 | |
Taehee Yoo | 587c0a4 | 2015-04-21 15:59:12 +0900 | [diff] [blame] | 1069 | if (mode & FALLOC_FL_PUNCH_HOLE) { |
| 1070 | if (offset >= inode->i_size) |
| 1071 | goto out; |
| 1072 | |
Chao Yu | a66c7b2 | 2013-11-22 16:52:50 +0800 | [diff] [blame] | 1073 | ret = punch_hole(inode, offset, len); |
Chao Yu | b4ace33 | 2015-05-06 13:09:46 +0800 | [diff] [blame] | 1074 | } else if (mode & FALLOC_FL_COLLAPSE_RANGE) { |
| 1075 | ret = f2fs_collapse_range(inode, offset, len); |
Chao Yu | 75cd4e0 | 2015-05-06 13:11:13 +0800 | [diff] [blame^] | 1076 | } else if (mode & FALLOC_FL_ZERO_RANGE) { |
| 1077 | ret = f2fs_zero_range(inode, offset, len, mode); |
Chao Yu | b4ace33 | 2015-05-06 13:09:46 +0800 | [diff] [blame] | 1078 | } else { |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1079 | ret = expand_inode_data(inode, offset, len, mode); |
Chao Yu | b4ace33 | 2015-05-06 13:09:46 +0800 | [diff] [blame] | 1080 | } |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1081 | |
Namjae Jeon | 3af60a4 | 2012-12-30 14:52:37 +0900 | [diff] [blame] | 1082 | if (!ret) { |
| 1083 | inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 1084 | mark_inode_dirty(inode); |
| 1085 | } |
Chao Yu | 3375f69 | 2014-01-28 10:29:26 +0800 | [diff] [blame] | 1086 | |
Taehee Yoo | 587c0a4 | 2015-04-21 15:59:12 +0900 | [diff] [blame] | 1087 | out: |
Chao Yu | 3375f69 | 2014-01-28 10:29:26 +0800 | [diff] [blame] | 1088 | mutex_unlock(&inode->i_mutex); |
| 1089 | |
Namjae Jeon | c01e285 | 2013-04-23 17:00:52 +0900 | [diff] [blame] | 1090 | trace_f2fs_fallocate(inode, mode, offset, len, ret); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1091 | return ret; |
| 1092 | } |
| 1093 | |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 1094 | static int f2fs_release_file(struct inode *inode, struct file *filp) |
| 1095 | { |
| 1096 | /* some remained atomic pages should discarded */ |
| 1097 | if (f2fs_is_atomic_file(inode)) |
| 1098 | commit_inmem_pages(inode, true); |
| 1099 | if (f2fs_is_volatile_file(inode)) { |
| 1100 | set_inode_flag(F2FS_I(inode), FI_DROP_CACHE); |
| 1101 | filemap_fdatawrite(inode->i_mapping); |
| 1102 | clear_inode_flag(F2FS_I(inode), FI_DROP_CACHE); |
| 1103 | } |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1107 | #define F2FS_REG_FLMASK (~(FS_DIRSYNC_FL | FS_TOPDIR_FL)) |
| 1108 | #define F2FS_OTHER_FLMASK (FS_NODUMP_FL | FS_NOATIME_FL) |
| 1109 | |
| 1110 | static inline __u32 f2fs_mask_flags(umode_t mode, __u32 flags) |
| 1111 | { |
| 1112 | if (S_ISDIR(mode)) |
| 1113 | return flags; |
| 1114 | else if (S_ISREG(mode)) |
| 1115 | return flags & F2FS_REG_FLMASK; |
| 1116 | else |
| 1117 | return flags & F2FS_OTHER_FLMASK; |
| 1118 | } |
| 1119 | |
Jaegeuk Kim | 52656e6 | 2014-09-24 15:37:02 -0700 | [diff] [blame] | 1120 | static int f2fs_ioc_getflags(struct file *filp, unsigned long arg) |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1121 | { |
Al Viro | 6131ffa | 2013-02-27 16:59:05 -0500 | [diff] [blame] | 1122 | struct inode *inode = file_inode(filp); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1123 | struct f2fs_inode_info *fi = F2FS_I(inode); |
Jaegeuk Kim | 52656e6 | 2014-09-24 15:37:02 -0700 | [diff] [blame] | 1124 | unsigned int flags = fi->i_flags & FS_FL_USER_VISIBLE; |
| 1125 | return put_user(flags, (int __user *)arg); |
| 1126 | } |
| 1127 | |
| 1128 | static int f2fs_ioc_setflags(struct file *filp, unsigned long arg) |
| 1129 | { |
| 1130 | struct inode *inode = file_inode(filp); |
| 1131 | struct f2fs_inode_info *fi = F2FS_I(inode); |
| 1132 | unsigned int flags = fi->i_flags & FS_FL_USER_VISIBLE; |
| 1133 | unsigned int oldflags; |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1134 | int ret; |
| 1135 | |
Jaegeuk Kim | 52656e6 | 2014-09-24 15:37:02 -0700 | [diff] [blame] | 1136 | ret = mnt_want_write_file(filp); |
| 1137 | if (ret) |
| 1138 | return ret; |
| 1139 | |
| 1140 | if (!inode_owner_or_capable(inode)) { |
| 1141 | ret = -EACCES; |
| 1142 | goto out; |
| 1143 | } |
| 1144 | |
| 1145 | if (get_user(flags, (int __user *)arg)) { |
| 1146 | ret = -EFAULT; |
| 1147 | goto out; |
| 1148 | } |
| 1149 | |
| 1150 | flags = f2fs_mask_flags(inode->i_mode, flags); |
| 1151 | |
| 1152 | mutex_lock(&inode->i_mutex); |
| 1153 | |
| 1154 | oldflags = fi->i_flags; |
| 1155 | |
| 1156 | if ((flags ^ oldflags) & (FS_APPEND_FL | FS_IMMUTABLE_FL)) { |
| 1157 | if (!capable(CAP_LINUX_IMMUTABLE)) { |
| 1158 | mutex_unlock(&inode->i_mutex); |
| 1159 | ret = -EPERM; |
| 1160 | goto out; |
| 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | flags = flags & FS_FL_USER_MODIFIABLE; |
| 1165 | flags |= oldflags & ~FS_FL_USER_MODIFIABLE; |
| 1166 | fi->i_flags = flags; |
| 1167 | mutex_unlock(&inode->i_mutex); |
| 1168 | |
| 1169 | f2fs_set_inode_flags(inode); |
| 1170 | inode->i_ctime = CURRENT_TIME; |
| 1171 | mark_inode_dirty(inode); |
| 1172 | out: |
| 1173 | mnt_drop_write_file(filp); |
| 1174 | return ret; |
| 1175 | } |
| 1176 | |
Chao Yu | d49f3e8 | 2015-01-23 20:36:04 +0800 | [diff] [blame] | 1177 | static int f2fs_ioc_getversion(struct file *filp, unsigned long arg) |
| 1178 | { |
| 1179 | struct inode *inode = file_inode(filp); |
| 1180 | |
| 1181 | return put_user(inode->i_generation, (int __user *)arg); |
| 1182 | } |
| 1183 | |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 1184 | static int f2fs_ioc_start_atomic_write(struct file *filp) |
| 1185 | { |
| 1186 | struct inode *inode = file_inode(filp); |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 1187 | |
| 1188 | if (!inode_owner_or_capable(inode)) |
| 1189 | return -EACCES; |
| 1190 | |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 1191 | f2fs_balance_fs(F2FS_I_SB(inode)); |
| 1192 | |
| 1193 | if (f2fs_is_atomic_file(inode)) |
| 1194 | return 0; |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 1195 | |
| 1196 | set_inode_flag(F2FS_I(inode), FI_ATOMIC_FILE); |
| 1197 | |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 1198 | return f2fs_convert_inline_inode(inode); |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | static int f2fs_ioc_commit_atomic_write(struct file *filp) |
| 1202 | { |
| 1203 | struct inode *inode = file_inode(filp); |
| 1204 | int ret; |
| 1205 | |
| 1206 | if (!inode_owner_or_capable(inode)) |
| 1207 | return -EACCES; |
| 1208 | |
Jaegeuk Kim | 02a1335 | 2014-10-06 16:11:16 -0700 | [diff] [blame] | 1209 | if (f2fs_is_volatile_file(inode)) |
| 1210 | return 0; |
| 1211 | |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 1212 | ret = mnt_want_write_file(filp); |
| 1213 | if (ret) |
| 1214 | return ret; |
| 1215 | |
| 1216 | if (f2fs_is_atomic_file(inode)) |
| 1217 | commit_inmem_pages(inode, false); |
| 1218 | |
| 1219 | ret = f2fs_sync_file(filp, 0, LONG_MAX, 0); |
| 1220 | mnt_drop_write_file(filp); |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 1221 | clear_inode_flag(F2FS_I(inode), FI_ATOMIC_FILE); |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 1222 | return ret; |
| 1223 | } |
| 1224 | |
Jaegeuk Kim | 02a1335 | 2014-10-06 16:11:16 -0700 | [diff] [blame] | 1225 | static int f2fs_ioc_start_volatile_write(struct file *filp) |
| 1226 | { |
| 1227 | struct inode *inode = file_inode(filp); |
| 1228 | |
| 1229 | if (!inode_owner_or_capable(inode)) |
| 1230 | return -EACCES; |
| 1231 | |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 1232 | if (f2fs_is_volatile_file(inode)) |
| 1233 | return 0; |
| 1234 | |
Jaegeuk Kim | 02a1335 | 2014-10-06 16:11:16 -0700 | [diff] [blame] | 1235 | set_inode_flag(F2FS_I(inode), FI_VOLATILE_FILE); |
Jaegeuk Kim | b3d208f | 2014-10-23 19:48:09 -0700 | [diff] [blame] | 1236 | |
| 1237 | return f2fs_convert_inline_inode(inode); |
Jaegeuk Kim | 02a1335 | 2014-10-06 16:11:16 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 1240 | static int f2fs_ioc_release_volatile_write(struct file *filp) |
| 1241 | { |
| 1242 | struct inode *inode = file_inode(filp); |
| 1243 | |
| 1244 | if (!inode_owner_or_capable(inode)) |
| 1245 | return -EACCES; |
| 1246 | |
| 1247 | if (!f2fs_is_volatile_file(inode)) |
| 1248 | return 0; |
| 1249 | |
Jaegeuk Kim | 3c6c2be | 2015-03-17 17:16:35 -0700 | [diff] [blame] | 1250 | if (!f2fs_is_first_block_written(inode)) |
| 1251 | return truncate_partial_data_page(inode, 0, true); |
| 1252 | |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 1253 | punch_hole(inode, 0, F2FS_BLKSIZE); |
| 1254 | return 0; |
| 1255 | } |
| 1256 | |
| 1257 | static int f2fs_ioc_abort_volatile_write(struct file *filp) |
| 1258 | { |
| 1259 | struct inode *inode = file_inode(filp); |
| 1260 | int ret; |
| 1261 | |
| 1262 | if (!inode_owner_or_capable(inode)) |
| 1263 | return -EACCES; |
| 1264 | |
| 1265 | ret = mnt_want_write_file(filp); |
| 1266 | if (ret) |
| 1267 | return ret; |
| 1268 | |
| 1269 | f2fs_balance_fs(F2FS_I_SB(inode)); |
| 1270 | |
| 1271 | if (f2fs_is_atomic_file(inode)) { |
| 1272 | commit_inmem_pages(inode, false); |
| 1273 | clear_inode_flag(F2FS_I(inode), FI_ATOMIC_FILE); |
| 1274 | } |
| 1275 | |
| 1276 | if (f2fs_is_volatile_file(inode)) { |
| 1277 | clear_inode_flag(F2FS_I(inode), FI_VOLATILE_FILE); |
| 1278 | filemap_fdatawrite(inode->i_mapping); |
| 1279 | set_inode_flag(F2FS_I(inode), FI_VOLATILE_FILE); |
| 1280 | } |
| 1281 | mnt_drop_write_file(filp); |
| 1282 | return ret; |
| 1283 | } |
| 1284 | |
Jaegeuk Kim | 1abff93 | 2015-01-08 19:15:53 -0800 | [diff] [blame] | 1285 | static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) |
| 1286 | { |
| 1287 | struct inode *inode = file_inode(filp); |
| 1288 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
| 1289 | struct super_block *sb = sbi->sb; |
| 1290 | __u32 in; |
| 1291 | |
| 1292 | if (!capable(CAP_SYS_ADMIN)) |
| 1293 | return -EPERM; |
| 1294 | |
| 1295 | if (get_user(in, (__u32 __user *)arg)) |
| 1296 | return -EFAULT; |
| 1297 | |
| 1298 | switch (in) { |
| 1299 | case F2FS_GOING_DOWN_FULLSYNC: |
| 1300 | sb = freeze_bdev(sb->s_bdev); |
| 1301 | if (sb && !IS_ERR(sb)) { |
| 1302 | f2fs_stop_checkpoint(sbi); |
| 1303 | thaw_bdev(sb->s_bdev, sb); |
| 1304 | } |
| 1305 | break; |
| 1306 | case F2FS_GOING_DOWN_METASYNC: |
| 1307 | /* do checkpoint only */ |
| 1308 | f2fs_sync_fs(sb, 1); |
| 1309 | f2fs_stop_checkpoint(sbi); |
| 1310 | break; |
| 1311 | case F2FS_GOING_DOWN_NOSYNC: |
| 1312 | f2fs_stop_checkpoint(sbi); |
| 1313 | break; |
| 1314 | default: |
| 1315 | return -EINVAL; |
| 1316 | } |
| 1317 | return 0; |
| 1318 | } |
| 1319 | |
Jaegeuk Kim | 52656e6 | 2014-09-24 15:37:02 -0700 | [diff] [blame] | 1320 | static int f2fs_ioc_fitrim(struct file *filp, unsigned long arg) |
| 1321 | { |
| 1322 | struct inode *inode = file_inode(filp); |
| 1323 | struct super_block *sb = inode->i_sb; |
| 1324 | struct request_queue *q = bdev_get_queue(sb->s_bdev); |
| 1325 | struct fstrim_range range; |
| 1326 | int ret; |
| 1327 | |
| 1328 | if (!capable(CAP_SYS_ADMIN)) |
| 1329 | return -EPERM; |
| 1330 | |
| 1331 | if (!blk_queue_discard(q)) |
| 1332 | return -EOPNOTSUPP; |
| 1333 | |
| 1334 | if (copy_from_user(&range, (struct fstrim_range __user *)arg, |
| 1335 | sizeof(range))) |
| 1336 | return -EFAULT; |
| 1337 | |
| 1338 | range.minlen = max((unsigned int)range.minlen, |
| 1339 | q->limits.discard_granularity); |
| 1340 | ret = f2fs_trim_fs(F2FS_SB(sb), &range); |
| 1341 | if (ret < 0) |
| 1342 | return ret; |
| 1343 | |
| 1344 | if (copy_to_user((struct fstrim_range __user *)arg, &range, |
| 1345 | sizeof(range))) |
| 1346 | return -EFAULT; |
| 1347 | return 0; |
| 1348 | } |
| 1349 | |
| 1350 | long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
| 1351 | { |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1352 | switch (cmd) { |
Namjae Jeon | 6a3e8ef | 2013-06-08 21:25:28 +0900 | [diff] [blame] | 1353 | case F2FS_IOC_GETFLAGS: |
Jaegeuk Kim | 52656e6 | 2014-09-24 15:37:02 -0700 | [diff] [blame] | 1354 | return f2fs_ioc_getflags(filp, arg); |
Namjae Jeon | 6a3e8ef | 2013-06-08 21:25:28 +0900 | [diff] [blame] | 1355 | case F2FS_IOC_SETFLAGS: |
Jaegeuk Kim | 52656e6 | 2014-09-24 15:37:02 -0700 | [diff] [blame] | 1356 | return f2fs_ioc_setflags(filp, arg); |
Chao Yu | d49f3e8 | 2015-01-23 20:36:04 +0800 | [diff] [blame] | 1357 | case F2FS_IOC_GETVERSION: |
| 1358 | return f2fs_ioc_getversion(filp, arg); |
Jaegeuk Kim | 88b88a6 | 2014-10-06 17:39:50 -0700 | [diff] [blame] | 1359 | case F2FS_IOC_START_ATOMIC_WRITE: |
| 1360 | return f2fs_ioc_start_atomic_write(filp); |
| 1361 | case F2FS_IOC_COMMIT_ATOMIC_WRITE: |
| 1362 | return f2fs_ioc_commit_atomic_write(filp); |
Jaegeuk Kim | 02a1335 | 2014-10-06 16:11:16 -0700 | [diff] [blame] | 1363 | case F2FS_IOC_START_VOLATILE_WRITE: |
| 1364 | return f2fs_ioc_start_volatile_write(filp); |
Jaegeuk Kim | 1e84371 | 2014-12-09 06:08:59 -0800 | [diff] [blame] | 1365 | case F2FS_IOC_RELEASE_VOLATILE_WRITE: |
| 1366 | return f2fs_ioc_release_volatile_write(filp); |
| 1367 | case F2FS_IOC_ABORT_VOLATILE_WRITE: |
| 1368 | return f2fs_ioc_abort_volatile_write(filp); |
Jaegeuk Kim | 1abff93 | 2015-01-08 19:15:53 -0800 | [diff] [blame] | 1369 | case F2FS_IOC_SHUTDOWN: |
| 1370 | return f2fs_ioc_shutdown(filp, arg); |
Jaegeuk Kim | 4b2fecc | 2014-09-20 22:06:39 -0700 | [diff] [blame] | 1371 | case FITRIM: |
Jaegeuk Kim | 52656e6 | 2014-09-24 15:37:02 -0700 | [diff] [blame] | 1372 | return f2fs_ioc_fitrim(filp, arg); |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1373 | default: |
| 1374 | return -ENOTTY; |
| 1375 | } |
| 1376 | } |
| 1377 | |
Namjae Jeon | e975082 | 2013-02-04 23:41:41 +0900 | [diff] [blame] | 1378 | #ifdef CONFIG_COMPAT |
| 1379 | long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 1380 | { |
| 1381 | switch (cmd) { |
| 1382 | case F2FS_IOC32_GETFLAGS: |
| 1383 | cmd = F2FS_IOC_GETFLAGS; |
| 1384 | break; |
| 1385 | case F2FS_IOC32_SETFLAGS: |
| 1386 | cmd = F2FS_IOC_SETFLAGS; |
| 1387 | break; |
| 1388 | default: |
| 1389 | return -ENOIOCTLCMD; |
| 1390 | } |
| 1391 | return f2fs_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); |
| 1392 | } |
| 1393 | #endif |
| 1394 | |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1395 | const struct file_operations f2fs_file_operations = { |
Chao Yu | 267378d | 2014-04-23 14:10:24 +0800 | [diff] [blame] | 1396 | .llseek = f2fs_llseek, |
Al Viro | aad4f8b | 2014-04-02 14:33:16 -0400 | [diff] [blame] | 1397 | .read_iter = generic_file_read_iter, |
Al Viro | 8174202 | 2014-04-03 03:17:43 -0400 | [diff] [blame] | 1398 | .write_iter = generic_file_write_iter, |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1399 | .open = generic_file_open, |
Jaegeuk Kim | 1266223 | 2014-12-05 14:37:37 -0800 | [diff] [blame] | 1400 | .release = f2fs_release_file, |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1401 | .mmap = f2fs_file_mmap, |
| 1402 | .fsync = f2fs_sync_file, |
| 1403 | .fallocate = f2fs_fallocate, |
| 1404 | .unlocked_ioctl = f2fs_ioctl, |
Namjae Jeon | e975082 | 2013-02-04 23:41:41 +0900 | [diff] [blame] | 1405 | #ifdef CONFIG_COMPAT |
| 1406 | .compat_ioctl = f2fs_compat_ioctl, |
| 1407 | #endif |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1408 | .splice_read = generic_file_splice_read, |
Al Viro | 8d02076 | 2014-04-05 04:27:08 -0400 | [diff] [blame] | 1409 | .splice_write = iter_file_splice_write, |
Jaegeuk Kim | fbfa2cc | 2012-11-02 17:09:44 +0900 | [diff] [blame] | 1410 | }; |