| .. | .. |
|---|
| 21 | 21 | #include <linux/uuid.h> |
|---|
| 22 | 22 | #include <linux/file.h> |
|---|
| 23 | 23 | #include <linux/nls.h> |
|---|
| 24 | +#include <linux/sched/signal.h> |
|---|
| 24 | 25 | |
|---|
| 25 | 26 | #include "f2fs.h" |
|---|
| 26 | 27 | #include "node.h" |
|---|
| .. | .. |
|---|
| 28 | 29 | #include "xattr.h" |
|---|
| 29 | 30 | #include "acl.h" |
|---|
| 30 | 31 | #include "gc.h" |
|---|
| 31 | | -#include "trace.h" |
|---|
| 32 | 32 | #include <trace/events/f2fs.h> |
|---|
| 33 | | -#include <trace/events/android_fs.h> |
|---|
| 33 | +#include <uapi/linux/f2fs.h> |
|---|
| 34 | 34 | |
|---|
| 35 | 35 | static vm_fault_t f2fs_filemap_fault(struct vm_fault *vmf) |
|---|
| 36 | 36 | { |
|---|
| 37 | 37 | struct inode *inode = file_inode(vmf->vma->vm_file); |
|---|
| 38 | 38 | vm_fault_t ret; |
|---|
| 39 | 39 | |
|---|
| 40 | | - down_read(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 40 | + f2fs_down_read(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 41 | 41 | ret = filemap_fault(vmf); |
|---|
| 42 | | - up_read(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 42 | + f2fs_up_read(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 43 | 43 | |
|---|
| 44 | 44 | if (!ret) |
|---|
| 45 | 45 | f2fs_update_iostat(F2FS_I_SB(inode), APP_MAPPED_READ_IO, |
|---|
| .. | .. |
|---|
| 59 | 59 | bool need_alloc = true; |
|---|
| 60 | 60 | int err = 0; |
|---|
| 61 | 61 | |
|---|
| 62 | + if (unlikely(IS_IMMUTABLE(inode))) |
|---|
| 63 | + return VM_FAULT_SIGBUS; |
|---|
| 64 | + |
|---|
| 65 | + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) |
|---|
| 66 | + return VM_FAULT_SIGBUS; |
|---|
| 67 | + |
|---|
| 62 | 68 | if (unlikely(f2fs_cp_error(sbi))) { |
|---|
| 63 | 69 | err = -EIO; |
|---|
| 64 | 70 | goto err; |
|---|
| .. | .. |
|---|
| 69 | 75 | goto err; |
|---|
| 70 | 76 | } |
|---|
| 71 | 77 | |
|---|
| 78 | + err = f2fs_convert_inline_inode(inode); |
|---|
| 79 | + if (err) |
|---|
| 80 | + goto err; |
|---|
| 81 | + |
|---|
| 72 | 82 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
|---|
| 73 | 83 | if (f2fs_compressed_file(inode)) { |
|---|
| 74 | 84 | int ret = f2fs_is_compressed_cluster(inode, page->index); |
|---|
| .. | .. |
|---|
| 77 | 87 | err = ret; |
|---|
| 78 | 88 | goto err; |
|---|
| 79 | 89 | } else if (ret) { |
|---|
| 80 | | - if (ret < F2FS_I(inode)->i_cluster_size) { |
|---|
| 81 | | - err = -EAGAIN; |
|---|
| 82 | | - goto err; |
|---|
| 83 | | - } |
|---|
| 84 | 90 | need_alloc = false; |
|---|
| 85 | 91 | } |
|---|
| 86 | 92 | } |
|---|
| .. | .. |
|---|
| 94 | 100 | f2fs_bug_on(sbi, f2fs_has_inline_data(inode)); |
|---|
| 95 | 101 | |
|---|
| 96 | 102 | file_update_time(vmf->vma->vm_file); |
|---|
| 97 | | - down_read(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 103 | + f2fs_down_read(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 98 | 104 | lock_page(page); |
|---|
| 99 | 105 | if (unlikely(page->mapping != inode->i_mapping || |
|---|
| 100 | 106 | page_offset(page) > i_size_read(inode) || |
|---|
| .. | .. |
|---|
| 106 | 112 | |
|---|
| 107 | 113 | if (need_alloc) { |
|---|
| 108 | 114 | /* block allocation */ |
|---|
| 109 | | - __do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); |
|---|
| 115 | + f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, true); |
|---|
| 110 | 116 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
|---|
| 111 | 117 | err = f2fs_get_block(&dn, page->index); |
|---|
| 112 | | - f2fs_put_dnode(&dn); |
|---|
| 113 | | - __do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false); |
|---|
| 118 | + f2fs_do_map_lock(sbi, F2FS_GET_BLOCK_PRE_AIO, false); |
|---|
| 114 | 119 | } |
|---|
| 115 | 120 | |
|---|
| 116 | 121 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
|---|
| .. | .. |
|---|
| 153 | 158 | |
|---|
| 154 | 159 | trace_f2fs_vm_page_mkwrite(page, DATA); |
|---|
| 155 | 160 | out_sem: |
|---|
| 156 | | - up_read(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 161 | + f2fs_up_read(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 157 | 162 | |
|---|
| 158 | 163 | sb_end_pagefault(inode->i_sb); |
|---|
| 159 | 164 | err: |
|---|
| .. | .. |
|---|
| 164 | 169 | .fault = f2fs_filemap_fault, |
|---|
| 165 | 170 | .map_pages = filemap_map_pages, |
|---|
| 166 | 171 | .page_mkwrite = f2fs_vm_page_mkwrite, |
|---|
| 172 | +#ifdef CONFIG_SPECULATIVE_PAGE_FAULT |
|---|
| 173 | + .allow_speculation = filemap_allow_speculation, |
|---|
| 174 | +#endif |
|---|
| 167 | 175 | }; |
|---|
| 168 | 176 | |
|---|
| 169 | 177 | static int get_parent_ino(struct inode *inode, nid_t *pino) |
|---|
| .. | .. |
|---|
| 231 | 239 | struct f2fs_inode_info *fi = F2FS_I(inode); |
|---|
| 232 | 240 | nid_t pino; |
|---|
| 233 | 241 | |
|---|
| 234 | | - down_write(&fi->i_sem); |
|---|
| 242 | + f2fs_down_write(&fi->i_sem); |
|---|
| 235 | 243 | if (file_wrong_pino(inode) && inode->i_nlink == 1 && |
|---|
| 236 | 244 | get_parent_ino(inode, &pino)) { |
|---|
| 237 | 245 | f2fs_i_pino_write(inode, pino); |
|---|
| 238 | 246 | file_got_pino(inode); |
|---|
| 239 | 247 | } |
|---|
| 240 | | - up_write(&fi->i_sem); |
|---|
| 248 | + f2fs_up_write(&fi->i_sem); |
|---|
| 241 | 249 | } |
|---|
| 242 | 250 | |
|---|
| 243 | 251 | static bool f2fs_update_fsync_count(struct f2fs_sb_info *sbi, |
|---|
| .. | .. |
|---|
| 275 | 283 | }; |
|---|
| 276 | 284 | unsigned int seq_id = 0; |
|---|
| 277 | 285 | |
|---|
| 278 | | - if (unlikely(f2fs_readonly(inode->i_sb) || |
|---|
| 279 | | - is_sbi_flag_set(sbi, SBI_CP_DISABLED))) |
|---|
| 286 | + if (unlikely(f2fs_readonly(inode->i_sb))) |
|---|
| 280 | 287 | return 0; |
|---|
| 281 | 288 | |
|---|
| 282 | 289 | trace_f2fs_sync_file_enter(inode); |
|---|
| 283 | | - |
|---|
| 284 | | - if (trace_android_fs_fsync_start_enabled()) { |
|---|
| 285 | | - char *path, pathbuf[MAX_TRACE_PATHBUF_LEN]; |
|---|
| 286 | | - |
|---|
| 287 | | - path = android_fstrace_get_pathname(pathbuf, |
|---|
| 288 | | - MAX_TRACE_PATHBUF_LEN, inode); |
|---|
| 289 | | - trace_android_fs_fsync_start(inode, |
|---|
| 290 | | - current->pid, path, current->comm); |
|---|
| 291 | | - } |
|---|
| 292 | 290 | |
|---|
| 293 | 291 | if (S_ISDIR(inode->i_mode)) |
|---|
| 294 | 292 | goto go_write; |
|---|
| .. | .. |
|---|
| 300 | 298 | ret = file_write_and_wait_range(file, start, end); |
|---|
| 301 | 299 | clear_inode_flag(inode, FI_NEED_IPU); |
|---|
| 302 | 300 | |
|---|
| 303 | | - if (ret) { |
|---|
| 301 | + if (ret || is_sbi_flag_set(sbi, SBI_CP_DISABLED)) { |
|---|
| 304 | 302 | trace_f2fs_sync_file_exit(inode, cp_reason, datasync, ret); |
|---|
| 305 | 303 | return ret; |
|---|
| 306 | 304 | } |
|---|
| .. | .. |
|---|
| 331 | 329 | * Both of fdatasync() and fsync() are able to be recovered from |
|---|
| 332 | 330 | * sudden-power-off. |
|---|
| 333 | 331 | */ |
|---|
| 334 | | - down_read(&F2FS_I(inode)->i_sem); |
|---|
| 332 | + f2fs_down_read(&F2FS_I(inode)->i_sem); |
|---|
| 335 | 333 | cp_reason = need_do_checkpoint(inode); |
|---|
| 336 | | - up_read(&F2FS_I(inode)->i_sem); |
|---|
| 334 | + f2fs_up_read(&F2FS_I(inode)->i_sem); |
|---|
| 337 | 335 | |
|---|
| 338 | 336 | if (cp_reason || !f2fs_update_fsync_count(sbi, npages)) { |
|---|
| 339 | 337 | /* all the dirty node pages should be flushed for POR */ |
|---|
| .. | .. |
|---|
| 395 | 393 | f2fs_update_time(sbi, REQ_TIME); |
|---|
| 396 | 394 | out: |
|---|
| 397 | 395 | trace_f2fs_sync_file_exit(inode, cp_reason, datasync, ret); |
|---|
| 398 | | - f2fs_trace_ios(NULL, 1); |
|---|
| 399 | | - trace_android_fs_fsync_end(inode, start, end - start); |
|---|
| 400 | | - |
|---|
| 401 | 396 | return ret; |
|---|
| 402 | 397 | } |
|---|
| 403 | 398 | |
|---|
| .. | .. |
|---|
| 408 | 403 | return f2fs_do_sync_file(file, start, end, datasync, false); |
|---|
| 409 | 404 | } |
|---|
| 410 | 405 | |
|---|
| 411 | | -static pgoff_t __get_first_dirty_index(struct address_space *mapping, |
|---|
| 412 | | - pgoff_t pgofs, int whence) |
|---|
| 413 | | -{ |
|---|
| 414 | | - struct page *page; |
|---|
| 415 | | - int nr_pages; |
|---|
| 416 | | - |
|---|
| 417 | | - if (whence != SEEK_DATA) |
|---|
| 418 | | - return 0; |
|---|
| 419 | | - |
|---|
| 420 | | - /* find first dirty page index */ |
|---|
| 421 | | - nr_pages = find_get_pages_tag(mapping, &pgofs, PAGECACHE_TAG_DIRTY, |
|---|
| 422 | | - 1, &page); |
|---|
| 423 | | - if (!nr_pages) |
|---|
| 424 | | - return ULONG_MAX; |
|---|
| 425 | | - pgofs = page->index; |
|---|
| 426 | | - put_page(page); |
|---|
| 427 | | - return pgofs; |
|---|
| 428 | | -} |
|---|
| 429 | | - |
|---|
| 430 | | -static bool __found_offset(struct f2fs_sb_info *sbi, block_t blkaddr, |
|---|
| 431 | | - pgoff_t dirty, pgoff_t pgofs, int whence) |
|---|
| 406 | +static bool __found_offset(struct address_space *mapping, block_t blkaddr, |
|---|
| 407 | + pgoff_t index, int whence) |
|---|
| 432 | 408 | { |
|---|
| 433 | 409 | switch (whence) { |
|---|
| 434 | 410 | case SEEK_DATA: |
|---|
| 435 | | - if ((blkaddr == NEW_ADDR && dirty == pgofs) || |
|---|
| 436 | | - __is_valid_data_blkaddr(blkaddr)) |
|---|
| 411 | + if (__is_valid_data_blkaddr(blkaddr)) |
|---|
| 412 | + return true; |
|---|
| 413 | + if (blkaddr == NEW_ADDR && |
|---|
| 414 | + xa_get_mark(&mapping->i_pages, index, PAGECACHE_TAG_DIRTY)) |
|---|
| 437 | 415 | return true; |
|---|
| 438 | 416 | break; |
|---|
| 439 | 417 | case SEEK_HOLE: |
|---|
| .. | .. |
|---|
| 449 | 427 | struct inode *inode = file->f_mapping->host; |
|---|
| 450 | 428 | loff_t maxbytes = inode->i_sb->s_maxbytes; |
|---|
| 451 | 429 | struct dnode_of_data dn; |
|---|
| 452 | | - pgoff_t pgofs, end_offset, dirty; |
|---|
| 430 | + pgoff_t pgofs, end_offset; |
|---|
| 453 | 431 | loff_t data_ofs = offset; |
|---|
| 454 | 432 | loff_t isize; |
|---|
| 455 | 433 | int err = 0; |
|---|
| .. | .. |
|---|
| 461 | 439 | goto fail; |
|---|
| 462 | 440 | |
|---|
| 463 | 441 | /* handle inline data case */ |
|---|
| 464 | | - if (f2fs_has_inline_data(inode) || f2fs_has_inline_dentry(inode)) { |
|---|
| 465 | | - if (whence == SEEK_HOLE) |
|---|
| 442 | + if (f2fs_has_inline_data(inode)) { |
|---|
| 443 | + if (whence == SEEK_HOLE) { |
|---|
| 466 | 444 | data_ofs = isize; |
|---|
| 467 | | - goto found; |
|---|
| 445 | + goto found; |
|---|
| 446 | + } else if (whence == SEEK_DATA) { |
|---|
| 447 | + data_ofs = offset; |
|---|
| 448 | + goto found; |
|---|
| 449 | + } |
|---|
| 468 | 450 | } |
|---|
| 469 | 451 | |
|---|
| 470 | 452 | pgofs = (pgoff_t)(offset >> PAGE_SHIFT); |
|---|
| 471 | | - |
|---|
| 472 | | - dirty = __get_first_dirty_index(inode->i_mapping, pgofs, whence); |
|---|
| 473 | 453 | |
|---|
| 474 | 454 | for (; data_ofs < isize; data_ofs = (loff_t)pgofs << PAGE_SHIFT) { |
|---|
| 475 | 455 | set_new_dnode(&dn, inode, NULL, NULL, 0); |
|---|
| .. | .. |
|---|
| 503 | 483 | goto fail; |
|---|
| 504 | 484 | } |
|---|
| 505 | 485 | |
|---|
| 506 | | - if (__found_offset(F2FS_I_SB(inode), blkaddr, dirty, |
|---|
| 486 | + if (__found_offset(file->f_mapping, blkaddr, |
|---|
| 507 | 487 | pgofs, whence)) { |
|---|
| 508 | 488 | f2fs_put_dnode(&dn); |
|---|
| 509 | 489 | goto found; |
|---|
| .. | .. |
|---|
| 529 | 509 | struct inode *inode = file->f_mapping->host; |
|---|
| 530 | 510 | loff_t maxbytes = inode->i_sb->s_maxbytes; |
|---|
| 531 | 511 | |
|---|
| 512 | + if (f2fs_compressed_file(inode)) |
|---|
| 513 | + maxbytes = max_file_blocks(inode) << F2FS_BLKSIZE_BITS; |
|---|
| 514 | + |
|---|
| 532 | 515 | switch (whence) { |
|---|
| 533 | 516 | case SEEK_SET: |
|---|
| 534 | 517 | case SEEK_CUR: |
|---|
| .. | .. |
|---|
| 548 | 531 | static int f2fs_file_mmap(struct file *file, struct vm_area_struct *vma) |
|---|
| 549 | 532 | { |
|---|
| 550 | 533 | struct inode *inode = file_inode(file); |
|---|
| 551 | | - int err; |
|---|
| 552 | 534 | |
|---|
| 553 | 535 | if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) |
|---|
| 554 | 536 | return -EIO; |
|---|
| 555 | 537 | |
|---|
| 556 | 538 | if (!f2fs_is_compress_backend_ready(inode)) |
|---|
| 557 | 539 | return -EOPNOTSUPP; |
|---|
| 558 | | - |
|---|
| 559 | | - /* we don't need to use inline_data strictly */ |
|---|
| 560 | | - err = f2fs_convert_inline_inode(inode); |
|---|
| 561 | | - if (err) |
|---|
| 562 | | - return err; |
|---|
| 563 | 540 | |
|---|
| 564 | 541 | file_accessed(file); |
|---|
| 565 | 542 | vma->vm_ops = &f2fs_file_vm_ops; |
|---|
| .. | .. |
|---|
| 596 | 573 | bool compressed_cluster = false; |
|---|
| 597 | 574 | int cluster_index = 0, valid_blocks = 0; |
|---|
| 598 | 575 | int cluster_size = F2FS_I(dn->inode)->i_cluster_size; |
|---|
| 599 | | - bool released = !F2FS_I(dn->inode)->i_compr_blocks; |
|---|
| 576 | + bool released = !atomic_read(&F2FS_I(dn->inode)->i_compr_blocks); |
|---|
| 600 | 577 | |
|---|
| 601 | 578 | if (IS_INODE(dn->node_page) && f2fs_has_extra_attr(dn->inode)) |
|---|
| 602 | 579 | base = get_extra_isize(dn->inode); |
|---|
| .. | .. |
|---|
| 651 | 628 | */ |
|---|
| 652 | 629 | fofs = f2fs_start_bidx_of_node(ofs_of_node(dn->node_page), |
|---|
| 653 | 630 | dn->inode) + ofs; |
|---|
| 654 | | - f2fs_update_extent_cache_range(dn, fofs, 0, len); |
|---|
| 631 | + f2fs_update_read_extent_cache_range(dn, fofs, 0, len); |
|---|
| 632 | + f2fs_update_age_extent_cache_range(dn, fofs, nr_free); |
|---|
| 655 | 633 | dec_valid_block_count(sbi, dn->inode, nr_free); |
|---|
| 656 | 634 | } |
|---|
| 657 | 635 | dn->ofs_in_node = ofs; |
|---|
| .. | .. |
|---|
| 713 | 691 | |
|---|
| 714 | 692 | free_from = (pgoff_t)F2FS_BLK_ALIGN(from); |
|---|
| 715 | 693 | |
|---|
| 716 | | - if (free_from >= sbi->max_file_blocks) |
|---|
| 694 | + if (free_from >= max_file_blocks(inode)) |
|---|
| 717 | 695 | goto free_partial; |
|---|
| 718 | 696 | |
|---|
| 719 | 697 | if (lock) |
|---|
| .. | .. |
|---|
| 785 | 763 | return err; |
|---|
| 786 | 764 | |
|---|
| 787 | 765 | #ifdef CONFIG_F2FS_FS_COMPRESSION |
|---|
| 788 | | - if (from != free_from) |
|---|
| 766 | + if (from != free_from) { |
|---|
| 789 | 767 | err = f2fs_truncate_partial_cluster(inode, from, lock); |
|---|
| 768 | + if (err) |
|---|
| 769 | + return err; |
|---|
| 770 | + } |
|---|
| 790 | 771 | #endif |
|---|
| 791 | 772 | |
|---|
| 792 | | - return err; |
|---|
| 773 | + return 0; |
|---|
| 793 | 774 | } |
|---|
| 794 | 775 | |
|---|
| 795 | 776 | int f2fs_truncate(struct inode *inode) |
|---|
| .. | .. |
|---|
| 887 | 868 | if (ia_valid & ATTR_GID) |
|---|
| 888 | 869 | inode->i_gid = attr->ia_gid; |
|---|
| 889 | 870 | if (ia_valid & ATTR_ATIME) |
|---|
| 890 | | - inode->i_atime = timespec64_trunc(attr->ia_atime, |
|---|
| 891 | | - inode->i_sb->s_time_gran); |
|---|
| 871 | + inode->i_atime = attr->ia_atime; |
|---|
| 892 | 872 | if (ia_valid & ATTR_MTIME) |
|---|
| 893 | | - inode->i_mtime = timespec64_trunc(attr->ia_mtime, |
|---|
| 894 | | - inode->i_sb->s_time_gran); |
|---|
| 873 | + inode->i_mtime = attr->ia_mtime; |
|---|
| 895 | 874 | if (ia_valid & ATTR_CTIME) |
|---|
| 896 | | - inode->i_ctime = timespec64_trunc(attr->ia_ctime, |
|---|
| 897 | | - inode->i_sb->s_time_gran); |
|---|
| 875 | + inode->i_ctime = attr->ia_ctime; |
|---|
| 898 | 876 | if (ia_valid & ATTR_MODE) { |
|---|
| 899 | 877 | umode_t mode = attr->ia_mode; |
|---|
| 900 | 878 | |
|---|
| .. | .. |
|---|
| 915 | 893 | |
|---|
| 916 | 894 | if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) |
|---|
| 917 | 895 | return -EIO; |
|---|
| 896 | + |
|---|
| 897 | + if (unlikely(IS_IMMUTABLE(inode))) |
|---|
| 898 | + return -EPERM; |
|---|
| 899 | + |
|---|
| 900 | + if (unlikely(IS_APPEND(inode) && |
|---|
| 901 | + (attr->ia_valid & (ATTR_MODE | ATTR_UID | |
|---|
| 902 | + ATTR_GID | ATTR_TIMES_SET)))) |
|---|
| 903 | + return -EPERM; |
|---|
| 918 | 904 | |
|---|
| 919 | 905 | if ((attr->ia_valid & ATTR_SIZE) && |
|---|
| 920 | 906 | !f2fs_is_compress_backend_ready(inode)) |
|---|
| .. | .. |
|---|
| 974 | 960 | return err; |
|---|
| 975 | 961 | } |
|---|
| 976 | 962 | |
|---|
| 977 | | - down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 978 | | - down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 963 | + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 964 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 979 | 965 | |
|---|
| 980 | 966 | truncate_setsize(inode, attr->ia_size); |
|---|
| 981 | 967 | |
|---|
| .. | .. |
|---|
| 985 | 971 | * do not trim all blocks after i_size if target size is |
|---|
| 986 | 972 | * larger than i_size. |
|---|
| 987 | 973 | */ |
|---|
| 988 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 989 | | - up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 974 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 975 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 990 | 976 | if (err) |
|---|
| 991 | 977 | return err; |
|---|
| 992 | 978 | |
|---|
| .. | .. |
|---|
| 1000 | 986 | |
|---|
| 1001 | 987 | if (attr->ia_valid & ATTR_MODE) { |
|---|
| 1002 | 988 | err = posix_acl_chmod(inode, f2fs_get_inode_mode(inode)); |
|---|
| 1003 | | - if (err || is_inode_flag_set(inode, FI_ACL_MODE)) { |
|---|
| 1004 | | - inode->i_mode = F2FS_I(inode)->i_acl_mode; |
|---|
| 989 | + |
|---|
| 990 | + if (is_inode_flag_set(inode, FI_ACL_MODE)) { |
|---|
| 991 | + if (!err) |
|---|
| 992 | + inode->i_mode = F2FS_I(inode)->i_acl_mode; |
|---|
| 1005 | 993 | clear_inode_flag(inode, FI_ACL_MODE); |
|---|
| 1006 | 994 | } |
|---|
| 1007 | 995 | } |
|---|
| .. | .. |
|---|
| 1124 | 1112 | blk_start = (loff_t)pg_start << PAGE_SHIFT; |
|---|
| 1125 | 1113 | blk_end = (loff_t)pg_end << PAGE_SHIFT; |
|---|
| 1126 | 1114 | |
|---|
| 1127 | | - down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1128 | | - down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1115 | + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1116 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1129 | 1117 | |
|---|
| 1130 | 1118 | truncate_pagecache_range(inode, blk_start, blk_end - 1); |
|---|
| 1131 | 1119 | |
|---|
| .. | .. |
|---|
| 1133 | 1121 | ret = f2fs_truncate_hole(inode, pg_start, pg_end); |
|---|
| 1134 | 1122 | f2fs_unlock_op(sbi); |
|---|
| 1135 | 1123 | |
|---|
| 1136 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1137 | | - up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1124 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1125 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1138 | 1126 | } |
|---|
| 1139 | 1127 | } |
|---|
| 1140 | 1128 | |
|---|
| .. | .. |
|---|
| 1245 | 1233 | if (ret) |
|---|
| 1246 | 1234 | return ret; |
|---|
| 1247 | 1235 | |
|---|
| 1248 | | - ret = f2fs_get_node_info(sbi, dn.nid, &ni); |
|---|
| 1236 | + ret = f2fs_get_node_info(sbi, dn.nid, &ni, false); |
|---|
| 1249 | 1237 | if (ret) { |
|---|
| 1250 | 1238 | f2fs_put_dnode(&dn); |
|---|
| 1251 | 1239 | return ret; |
|---|
| .. | .. |
|---|
| 1367 | 1355 | f2fs_balance_fs(sbi, true); |
|---|
| 1368 | 1356 | |
|---|
| 1369 | 1357 | /* avoid gc operation during block exchange */ |
|---|
| 1370 | | - down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1371 | | - down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1358 | + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1359 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1372 | 1360 | |
|---|
| 1373 | 1361 | f2fs_lock_op(sbi); |
|---|
| 1374 | 1362 | f2fs_drop_extent_tree(inode); |
|---|
| .. | .. |
|---|
| 1376 | 1364 | ret = __exchange_data_block(inode, inode, end, start, nrpages - end, true); |
|---|
| 1377 | 1365 | f2fs_unlock_op(sbi); |
|---|
| 1378 | 1366 | |
|---|
| 1379 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1380 | | - up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1367 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1368 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1381 | 1369 | return ret; |
|---|
| 1382 | 1370 | } |
|---|
| 1383 | 1371 | |
|---|
| .. | .. |
|---|
| 1407 | 1395 | return ret; |
|---|
| 1408 | 1396 | |
|---|
| 1409 | 1397 | /* write out all moved pages, if possible */ |
|---|
| 1410 | | - down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1398 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1411 | 1399 | filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); |
|---|
| 1412 | 1400 | truncate_pagecache(inode, offset); |
|---|
| 1413 | 1401 | |
|---|
| 1414 | 1402 | new_size = i_size_read(inode) - len; |
|---|
| 1415 | | - truncate_pagecache(inode, new_size); |
|---|
| 1416 | | - |
|---|
| 1417 | 1403 | ret = f2fs_truncate_blocks(inode, new_size, true); |
|---|
| 1418 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1404 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1419 | 1405 | if (!ret) |
|---|
| 1420 | 1406 | f2fs_i_size_write(inode, new_size); |
|---|
| 1421 | 1407 | return ret; |
|---|
| .. | .. |
|---|
| 1451 | 1437 | ret = -ENOSPC; |
|---|
| 1452 | 1438 | break; |
|---|
| 1453 | 1439 | } |
|---|
| 1454 | | - if (dn->data_blkaddr != NEW_ADDR) { |
|---|
| 1455 | | - f2fs_invalidate_blocks(sbi, dn->data_blkaddr); |
|---|
| 1456 | | - dn->data_blkaddr = NEW_ADDR; |
|---|
| 1457 | | - f2fs_set_data_blkaddr(dn); |
|---|
| 1440 | + |
|---|
| 1441 | + if (dn->data_blkaddr == NEW_ADDR) |
|---|
| 1442 | + continue; |
|---|
| 1443 | + |
|---|
| 1444 | + if (!f2fs_is_valid_blkaddr(sbi, dn->data_blkaddr, |
|---|
| 1445 | + DATA_GENERIC_ENHANCE)) { |
|---|
| 1446 | + ret = -EFSCORRUPTED; |
|---|
| 1447 | + break; |
|---|
| 1458 | 1448 | } |
|---|
| 1449 | + |
|---|
| 1450 | + f2fs_invalidate_blocks(sbi, dn->data_blkaddr); |
|---|
| 1451 | + dn->data_blkaddr = NEW_ADDR; |
|---|
| 1452 | + f2fs_set_data_blkaddr(dn); |
|---|
| 1459 | 1453 | } |
|---|
| 1460 | 1454 | |
|---|
| 1461 | | - f2fs_update_extent_cache_range(dn, start, 0, index - start); |
|---|
| 1455 | + f2fs_update_read_extent_cache_range(dn, start, 0, index - start); |
|---|
| 1462 | 1456 | |
|---|
| 1463 | 1457 | return ret; |
|---|
| 1464 | 1458 | } |
|---|
| .. | .. |
|---|
| 1514 | 1508 | unsigned int end_offset; |
|---|
| 1515 | 1509 | pgoff_t end; |
|---|
| 1516 | 1510 | |
|---|
| 1517 | | - down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1518 | | - down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1511 | + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1512 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1519 | 1513 | |
|---|
| 1520 | 1514 | truncate_pagecache_range(inode, |
|---|
| 1521 | 1515 | (loff_t)index << PAGE_SHIFT, |
|---|
| .. | .. |
|---|
| 1527 | 1521 | ret = f2fs_get_dnode_of_data(&dn, index, ALLOC_NODE); |
|---|
| 1528 | 1522 | if (ret) { |
|---|
| 1529 | 1523 | f2fs_unlock_op(sbi); |
|---|
| 1530 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1531 | | - up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1524 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1525 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1532 | 1526 | goto out; |
|---|
| 1533 | 1527 | } |
|---|
| 1534 | 1528 | |
|---|
| .. | .. |
|---|
| 1539 | 1533 | f2fs_put_dnode(&dn); |
|---|
| 1540 | 1534 | |
|---|
| 1541 | 1535 | f2fs_unlock_op(sbi); |
|---|
| 1542 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1543 | | - up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1536 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1537 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1544 | 1538 | |
|---|
| 1545 | 1539 | f2fs_balance_fs(sbi, dn.node_changed); |
|---|
| 1546 | 1540 | |
|---|
| .. | .. |
|---|
| 1596 | 1590 | |
|---|
| 1597 | 1591 | f2fs_balance_fs(sbi, true); |
|---|
| 1598 | 1592 | |
|---|
| 1599 | | - down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1593 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1600 | 1594 | ret = f2fs_truncate_blocks(inode, i_size_read(inode), true); |
|---|
| 1601 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1595 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1602 | 1596 | if (ret) |
|---|
| 1603 | 1597 | return ret; |
|---|
| 1604 | 1598 | |
|---|
| .. | .. |
|---|
| 1613 | 1607 | idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); |
|---|
| 1614 | 1608 | |
|---|
| 1615 | 1609 | /* avoid gc operation during block exchange */ |
|---|
| 1616 | | - down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1617 | | - down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1610 | + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1611 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1618 | 1612 | truncate_pagecache(inode, offset); |
|---|
| 1619 | 1613 | |
|---|
| 1620 | 1614 | while (!ret && idx > pg_start) { |
|---|
| .. | .. |
|---|
| 1630 | 1624 | idx + delta, nr, false); |
|---|
| 1631 | 1625 | f2fs_unlock_op(sbi); |
|---|
| 1632 | 1626 | } |
|---|
| 1633 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1634 | | - up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1627 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1628 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 1635 | 1629 | |
|---|
| 1636 | 1630 | /* write out all moved pages, if possible */ |
|---|
| 1637 | | - down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1631 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1638 | 1632 | filemap_write_and_wait_range(inode->i_mapping, offset, LLONG_MAX); |
|---|
| 1639 | 1633 | truncate_pagecache(inode, offset); |
|---|
| 1640 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1634 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 1641 | 1635 | |
|---|
| 1642 | 1636 | if (!ret) |
|---|
| 1643 | 1637 | f2fs_i_size_write(inode, new_size); |
|---|
| .. | .. |
|---|
| 1651 | 1645 | struct f2fs_map_blocks map = { .m_next_pgofs = NULL, |
|---|
| 1652 | 1646 | .m_next_extent = NULL, .m_seg_type = NO_CHECK_TYPE, |
|---|
| 1653 | 1647 | .m_may_create = true }; |
|---|
| 1654 | | - pgoff_t pg_end; |
|---|
| 1648 | + pgoff_t pg_start, pg_end; |
|---|
| 1655 | 1649 | loff_t new_size = i_size_read(inode); |
|---|
| 1656 | 1650 | loff_t off_end; |
|---|
| 1651 | + block_t expanded = 0; |
|---|
| 1657 | 1652 | int err; |
|---|
| 1658 | 1653 | |
|---|
| 1659 | 1654 | err = inode_newsize_ok(inode, (len + offset)); |
|---|
| .. | .. |
|---|
| 1666 | 1661 | |
|---|
| 1667 | 1662 | f2fs_balance_fs(sbi, true); |
|---|
| 1668 | 1663 | |
|---|
| 1664 | + pg_start = ((unsigned long long)offset) >> PAGE_SHIFT; |
|---|
| 1669 | 1665 | pg_end = ((unsigned long long)offset + len) >> PAGE_SHIFT; |
|---|
| 1670 | 1666 | off_end = (offset + len) & (PAGE_SIZE - 1); |
|---|
| 1671 | 1667 | |
|---|
| 1672 | | - map.m_lblk = ((unsigned long long)offset) >> PAGE_SHIFT; |
|---|
| 1673 | | - map.m_len = pg_end - map.m_lblk; |
|---|
| 1668 | + map.m_lblk = pg_start; |
|---|
| 1669 | + map.m_len = pg_end - pg_start; |
|---|
| 1674 | 1670 | if (off_end) |
|---|
| 1675 | 1671 | map.m_len++; |
|---|
| 1676 | 1672 | |
|---|
| .. | .. |
|---|
| 1678 | 1674 | return 0; |
|---|
| 1679 | 1675 | |
|---|
| 1680 | 1676 | if (f2fs_is_pinned_file(inode)) { |
|---|
| 1681 | | - block_t len = (map.m_len >> sbi->log_blocks_per_seg) << |
|---|
| 1682 | | - sbi->log_blocks_per_seg; |
|---|
| 1683 | | - block_t done = 0; |
|---|
| 1677 | + block_t sec_blks = BLKS_PER_SEC(sbi); |
|---|
| 1678 | + block_t sec_len = roundup(map.m_len, sec_blks); |
|---|
| 1684 | 1679 | |
|---|
| 1685 | | - if (map.m_len % sbi->blocks_per_seg) |
|---|
| 1686 | | - len += sbi->blocks_per_seg; |
|---|
| 1687 | | - |
|---|
| 1688 | | - map.m_len = sbi->blocks_per_seg; |
|---|
| 1680 | + map.m_len = sec_blks; |
|---|
| 1689 | 1681 | next_alloc: |
|---|
| 1690 | 1682 | if (has_not_enough_free_secs(sbi, 0, |
|---|
| 1691 | 1683 | GET_SEC_FROM_SEG(sbi, overprovision_segments(sbi)))) { |
|---|
| 1692 | | - down_write(&sbi->gc_lock); |
|---|
| 1693 | | - err = f2fs_gc(sbi, true, false, NULL_SEGNO); |
|---|
| 1684 | + f2fs_down_write(&sbi->gc_lock); |
|---|
| 1685 | + err = f2fs_gc(sbi, true, false, false, NULL_SEGNO); |
|---|
| 1694 | 1686 | if (err && err != -ENODATA && err != -EAGAIN) |
|---|
| 1695 | 1687 | goto out_err; |
|---|
| 1696 | 1688 | } |
|---|
| 1697 | 1689 | |
|---|
| 1698 | | - down_write(&sbi->pin_sem); |
|---|
| 1699 | | - map.m_seg_type = CURSEG_COLD_DATA_PINNED; |
|---|
| 1690 | + f2fs_down_write(&sbi->pin_sem); |
|---|
| 1700 | 1691 | |
|---|
| 1701 | 1692 | f2fs_lock_op(sbi); |
|---|
| 1702 | | - f2fs_allocate_new_segments(sbi, CURSEG_COLD_DATA); |
|---|
| 1693 | + f2fs_allocate_new_section(sbi, CURSEG_COLD_DATA_PINNED, false); |
|---|
| 1703 | 1694 | f2fs_unlock_op(sbi); |
|---|
| 1704 | 1695 | |
|---|
| 1696 | + map.m_seg_type = CURSEG_COLD_DATA_PINNED; |
|---|
| 1705 | 1697 | err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_DIO); |
|---|
| 1706 | | - up_write(&sbi->pin_sem); |
|---|
| 1707 | 1698 | |
|---|
| 1708 | | - done += map.m_len; |
|---|
| 1709 | | - len -= map.m_len; |
|---|
| 1699 | + f2fs_up_write(&sbi->pin_sem); |
|---|
| 1700 | + |
|---|
| 1701 | + expanded += map.m_len; |
|---|
| 1702 | + sec_len -= map.m_len; |
|---|
| 1710 | 1703 | map.m_lblk += map.m_len; |
|---|
| 1711 | | - if (!err && len) |
|---|
| 1704 | + if (!err && sec_len) |
|---|
| 1712 | 1705 | goto next_alloc; |
|---|
| 1713 | 1706 | |
|---|
| 1714 | | - map.m_len = done; |
|---|
| 1707 | + map.m_len = expanded; |
|---|
| 1715 | 1708 | } else { |
|---|
| 1716 | 1709 | err = f2fs_map_blocks(inode, &map, 1, F2FS_GET_BLOCK_PRE_AIO); |
|---|
| 1710 | + expanded = map.m_len; |
|---|
| 1717 | 1711 | } |
|---|
| 1718 | 1712 | out_err: |
|---|
| 1719 | 1713 | if (err) { |
|---|
| 1720 | 1714 | pgoff_t last_off; |
|---|
| 1721 | 1715 | |
|---|
| 1722 | | - if (!map.m_len) |
|---|
| 1716 | + if (!expanded) |
|---|
| 1723 | 1717 | return err; |
|---|
| 1724 | 1718 | |
|---|
| 1725 | | - last_off = map.m_lblk + map.m_len - 1; |
|---|
| 1719 | + last_off = pg_start + expanded - 1; |
|---|
| 1726 | 1720 | |
|---|
| 1727 | 1721 | /* update new size to the failed position */ |
|---|
| 1728 | 1722 | new_size = (last_off == pg_end) ? offset + len : |
|---|
| .. | .. |
|---|
| 1773 | 1767 | return -EOPNOTSUPP; |
|---|
| 1774 | 1768 | |
|---|
| 1775 | 1769 | inode_lock(inode); |
|---|
| 1770 | + |
|---|
| 1771 | + ret = file_modified(file); |
|---|
| 1772 | + if (ret) |
|---|
| 1773 | + goto out; |
|---|
| 1776 | 1774 | |
|---|
| 1777 | 1775 | if (mode & FALLOC_FL_PUNCH_HOLE) { |
|---|
| 1778 | 1776 | if (offset >= inode->i_size) |
|---|
| .. | .. |
|---|
| 1846 | 1844 | struct f2fs_inode_info *fi = F2FS_I(inode); |
|---|
| 1847 | 1845 | u32 masked_flags = fi->i_flags & mask; |
|---|
| 1848 | 1846 | |
|---|
| 1849 | | - f2fs_bug_on(F2FS_I_SB(inode), (iflags & ~mask)); |
|---|
| 1847 | + /* mask can be shrunk by flags_valid selector */ |
|---|
| 1848 | + iflags &= mask; |
|---|
| 1850 | 1849 | |
|---|
| 1851 | 1850 | /* Is it quota file? Do not allow user to mess with it */ |
|---|
| 1852 | 1851 | if (IS_NOQUOTA(inode)) |
|---|
| .. | .. |
|---|
| 1868 | 1867 | |
|---|
| 1869 | 1868 | if ((iflags ^ masked_flags) & F2FS_COMPR_FL) { |
|---|
| 1870 | 1869 | if (masked_flags & F2FS_COMPR_FL) { |
|---|
| 1871 | | - if (f2fs_disable_compressed_file(inode)) |
|---|
| 1870 | + if (!f2fs_disable_compressed_file(inode)) |
|---|
| 1872 | 1871 | return -EINVAL; |
|---|
| 1873 | | - } |
|---|
| 1874 | | - if (iflags & F2FS_NOCOMP_FL) |
|---|
| 1875 | | - return -EINVAL; |
|---|
| 1876 | | - if (iflags & F2FS_COMPR_FL) { |
|---|
| 1872 | + } else { |
|---|
| 1877 | 1873 | if (!f2fs_may_compress(inode)) |
|---|
| 1878 | 1874 | return -EINVAL; |
|---|
| 1879 | | - |
|---|
| 1880 | | - set_compress_context(inode); |
|---|
| 1875 | + if (S_ISREG(inode->i_mode) && inode->i_size) |
|---|
| 1876 | + return -EINVAL; |
|---|
| 1877 | + if (set_compress_context(inode)) |
|---|
| 1878 | + return -EOPNOTSUPP; |
|---|
| 1881 | 1879 | } |
|---|
| 1882 | | - } |
|---|
| 1883 | | - if ((iflags ^ masked_flags) & F2FS_NOCOMP_FL) { |
|---|
| 1884 | | - if (masked_flags & F2FS_COMPR_FL) |
|---|
| 1885 | | - return -EINVAL; |
|---|
| 1886 | 1880 | } |
|---|
| 1887 | 1881 | |
|---|
| 1888 | 1882 | fi->i_flags = iflags | (fi->i_flags & ~mask); |
|---|
| .. | .. |
|---|
| 2071 | 2065 | |
|---|
| 2072 | 2066 | inode_lock(inode); |
|---|
| 2073 | 2067 | |
|---|
| 2074 | | - f2fs_disable_compressed_file(inode); |
|---|
| 2068 | + if (!f2fs_disable_compressed_file(inode)) { |
|---|
| 2069 | + ret = -EINVAL; |
|---|
| 2070 | + goto out; |
|---|
| 2071 | + } |
|---|
| 2075 | 2072 | |
|---|
| 2076 | 2073 | if (f2fs_is_atomic_file(inode)) { |
|---|
| 2077 | 2074 | if (is_inode_flag_set(inode, FI_ATOMIC_REVOKE_REQUEST)) |
|---|
| .. | .. |
|---|
| 2083 | 2080 | if (ret) |
|---|
| 2084 | 2081 | goto out; |
|---|
| 2085 | 2082 | |
|---|
| 2086 | | - down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 2083 | + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 2087 | 2084 | |
|---|
| 2088 | 2085 | /* |
|---|
| 2089 | 2086 | * Should wait end_io to count F2FS_WB_CP_DATA correctly by |
|---|
| .. | .. |
|---|
| 2094 | 2091 | inode->i_ino, get_dirty_pages(inode)); |
|---|
| 2095 | 2092 | ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); |
|---|
| 2096 | 2093 | if (ret) { |
|---|
| 2097 | | - up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 2094 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 2098 | 2095 | goto out; |
|---|
| 2099 | 2096 | } |
|---|
| 2100 | 2097 | |
|---|
| .. | .. |
|---|
| 2107 | 2104 | /* add inode in inmem_list first and set atomic_file */ |
|---|
| 2108 | 2105 | set_inode_flag(inode, FI_ATOMIC_FILE); |
|---|
| 2109 | 2106 | clear_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST); |
|---|
| 2110 | | - up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 2107 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 2111 | 2108 | |
|---|
| 2112 | 2109 | f2fs_update_time(F2FS_I_SB(inode), REQ_TIME); |
|---|
| 2113 | 2110 | F2FS_I(inode)->inmem_task = current; |
|---|
| .. | .. |
|---|
| 2274 | 2271 | if (ret) { |
|---|
| 2275 | 2272 | if (ret == -EROFS) { |
|---|
| 2276 | 2273 | ret = 0; |
|---|
| 2277 | | - f2fs_stop_checkpoint(sbi, false); |
|---|
| 2274 | + f2fs_stop_checkpoint(sbi, false, |
|---|
| 2275 | + STOP_CP_REASON_SHUTDOWN); |
|---|
| 2278 | 2276 | set_sbi_flag(sbi, SBI_IS_SHUTDOWN); |
|---|
| 2279 | 2277 | trace_f2fs_shutdown(sbi, in, ret); |
|---|
| 2280 | 2278 | } |
|---|
| .. | .. |
|---|
| 2284 | 2282 | |
|---|
| 2285 | 2283 | switch (in) { |
|---|
| 2286 | 2284 | case F2FS_GOING_DOWN_FULLSYNC: |
|---|
| 2287 | | - sb = freeze_bdev(sb->s_bdev); |
|---|
| 2288 | | - if (IS_ERR(sb)) { |
|---|
| 2289 | | - ret = PTR_ERR(sb); |
|---|
| 2285 | + ret = freeze_bdev(sb->s_bdev); |
|---|
| 2286 | + if (ret) |
|---|
| 2290 | 2287 | goto out; |
|---|
| 2291 | | - } |
|---|
| 2292 | | - if (sb) { |
|---|
| 2293 | | - f2fs_stop_checkpoint(sbi, false); |
|---|
| 2294 | | - set_sbi_flag(sbi, SBI_IS_SHUTDOWN); |
|---|
| 2295 | | - thaw_bdev(sb->s_bdev, sb); |
|---|
| 2296 | | - } |
|---|
| 2288 | + f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN); |
|---|
| 2289 | + set_sbi_flag(sbi, SBI_IS_SHUTDOWN); |
|---|
| 2290 | + thaw_bdev(sb->s_bdev); |
|---|
| 2297 | 2291 | break; |
|---|
| 2298 | 2292 | case F2FS_GOING_DOWN_METASYNC: |
|---|
| 2299 | 2293 | /* do checkpoint only */ |
|---|
| 2300 | 2294 | ret = f2fs_sync_fs(sb, 1); |
|---|
| 2301 | 2295 | if (ret) |
|---|
| 2302 | 2296 | goto out; |
|---|
| 2303 | | - f2fs_stop_checkpoint(sbi, false); |
|---|
| 2297 | + f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN); |
|---|
| 2304 | 2298 | set_sbi_flag(sbi, SBI_IS_SHUTDOWN); |
|---|
| 2305 | 2299 | break; |
|---|
| 2306 | 2300 | case F2FS_GOING_DOWN_NOSYNC: |
|---|
| 2307 | | - f2fs_stop_checkpoint(sbi, false); |
|---|
| 2301 | + f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN); |
|---|
| 2308 | 2302 | set_sbi_flag(sbi, SBI_IS_SHUTDOWN); |
|---|
| 2309 | 2303 | break; |
|---|
| 2310 | 2304 | case F2FS_GOING_DOWN_METAFLUSH: |
|---|
| 2311 | 2305 | f2fs_sync_meta_pages(sbi, META, LONG_MAX, FS_META_IO); |
|---|
| 2312 | | - f2fs_stop_checkpoint(sbi, false); |
|---|
| 2306 | + f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN); |
|---|
| 2313 | 2307 | set_sbi_flag(sbi, SBI_IS_SHUTDOWN); |
|---|
| 2314 | 2308 | break; |
|---|
| 2315 | 2309 | case F2FS_GOING_DOWN_NEED_FSCK: |
|---|
| .. | .. |
|---|
| 2418 | 2412 | if (err) |
|---|
| 2419 | 2413 | return err; |
|---|
| 2420 | 2414 | |
|---|
| 2421 | | - down_write(&sbi->sb_lock); |
|---|
| 2415 | + f2fs_down_write(&sbi->sb_lock); |
|---|
| 2422 | 2416 | |
|---|
| 2423 | 2417 | if (uuid_is_nonzero(sbi->raw_super->encrypt_pw_salt)) |
|---|
| 2424 | 2418 | goto got_it; |
|---|
| .. | .. |
|---|
| 2437 | 2431 | 16)) |
|---|
| 2438 | 2432 | err = -EFAULT; |
|---|
| 2439 | 2433 | out_err: |
|---|
| 2440 | | - up_write(&sbi->sb_lock); |
|---|
| 2434 | + f2fs_up_write(&sbi->sb_lock); |
|---|
| 2441 | 2435 | mnt_drop_write_file(filp); |
|---|
| 2442 | 2436 | return err; |
|---|
| 2443 | 2437 | } |
|---|
| .. | .. |
|---|
| 2514 | 2508 | return ret; |
|---|
| 2515 | 2509 | |
|---|
| 2516 | 2510 | if (!sync) { |
|---|
| 2517 | | - if (!down_write_trylock(&sbi->gc_lock)) { |
|---|
| 2511 | + if (!f2fs_down_write_trylock(&sbi->gc_lock)) { |
|---|
| 2518 | 2512 | ret = -EBUSY; |
|---|
| 2519 | 2513 | goto out; |
|---|
| 2520 | 2514 | } |
|---|
| 2521 | 2515 | } else { |
|---|
| 2522 | | - down_write(&sbi->gc_lock); |
|---|
| 2516 | + f2fs_down_write(&sbi->gc_lock); |
|---|
| 2523 | 2517 | } |
|---|
| 2524 | 2518 | |
|---|
| 2525 | | - ret = f2fs_gc(sbi, sync, true, NULL_SEGNO); |
|---|
| 2519 | + ret = f2fs_gc(sbi, sync, true, false, NULL_SEGNO); |
|---|
| 2526 | 2520 | out: |
|---|
| 2527 | 2521 | mnt_drop_write_file(filp); |
|---|
| 2528 | 2522 | return ret; |
|---|
| 2529 | 2523 | } |
|---|
| 2530 | 2524 | |
|---|
| 2531 | | -static int f2fs_ioc_gc_range(struct file *filp, unsigned long arg) |
|---|
| 2525 | +static int __f2fs_ioc_gc_range(struct file *filp, struct f2fs_gc_range *range) |
|---|
| 2532 | 2526 | { |
|---|
| 2533 | | - struct inode *inode = file_inode(filp); |
|---|
| 2534 | | - struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
|---|
| 2535 | | - struct f2fs_gc_range range; |
|---|
| 2527 | + struct f2fs_sb_info *sbi = F2FS_I_SB(file_inode(filp)); |
|---|
| 2536 | 2528 | u64 end; |
|---|
| 2537 | 2529 | int ret; |
|---|
| 2538 | 2530 | |
|---|
| 2539 | 2531 | if (!capable(CAP_SYS_ADMIN)) |
|---|
| 2540 | 2532 | return -EPERM; |
|---|
| 2541 | | - |
|---|
| 2542 | | - if (copy_from_user(&range, (struct f2fs_gc_range __user *)arg, |
|---|
| 2543 | | - sizeof(range))) |
|---|
| 2544 | | - return -EFAULT; |
|---|
| 2545 | | - |
|---|
| 2546 | 2533 | if (f2fs_readonly(sbi->sb)) |
|---|
| 2547 | 2534 | return -EROFS; |
|---|
| 2548 | 2535 | |
|---|
| 2549 | | - end = range.start + range.len; |
|---|
| 2550 | | - if (end < range.start || range.start < MAIN_BLKADDR(sbi) || |
|---|
| 2536 | + end = range->start + range->len; |
|---|
| 2537 | + if (end < range->start || range->start < MAIN_BLKADDR(sbi) || |
|---|
| 2551 | 2538 | end >= MAX_BLKADDR(sbi)) |
|---|
| 2552 | 2539 | return -EINVAL; |
|---|
| 2553 | 2540 | |
|---|
| .. | .. |
|---|
| 2556 | 2543 | return ret; |
|---|
| 2557 | 2544 | |
|---|
| 2558 | 2545 | do_more: |
|---|
| 2559 | | - if (!range.sync) { |
|---|
| 2560 | | - if (!down_write_trylock(&sbi->gc_lock)) { |
|---|
| 2546 | + if (!range->sync) { |
|---|
| 2547 | + if (!f2fs_down_write_trylock(&sbi->gc_lock)) { |
|---|
| 2561 | 2548 | ret = -EBUSY; |
|---|
| 2562 | 2549 | goto out; |
|---|
| 2563 | 2550 | } |
|---|
| 2564 | 2551 | } else { |
|---|
| 2565 | | - down_write(&sbi->gc_lock); |
|---|
| 2552 | + f2fs_down_write(&sbi->gc_lock); |
|---|
| 2566 | 2553 | } |
|---|
| 2567 | 2554 | |
|---|
| 2568 | | - ret = f2fs_gc(sbi, range.sync, true, GET_SEGNO(sbi, range.start)); |
|---|
| 2569 | | - range.start += BLKS_PER_SEC(sbi); |
|---|
| 2570 | | - if (range.start <= end) |
|---|
| 2555 | + ret = f2fs_gc(sbi, range->sync, true, false, |
|---|
| 2556 | + GET_SEGNO(sbi, range->start)); |
|---|
| 2557 | + if (ret) { |
|---|
| 2558 | + if (ret == -EBUSY) |
|---|
| 2559 | + ret = -EAGAIN; |
|---|
| 2560 | + goto out; |
|---|
| 2561 | + } |
|---|
| 2562 | + range->start += BLKS_PER_SEC(sbi); |
|---|
| 2563 | + if (range->start <= end) |
|---|
| 2571 | 2564 | goto do_more; |
|---|
| 2572 | 2565 | out: |
|---|
| 2573 | 2566 | mnt_drop_write_file(filp); |
|---|
| 2574 | 2567 | return ret; |
|---|
| 2568 | +} |
|---|
| 2569 | + |
|---|
| 2570 | +static int f2fs_ioc_gc_range(struct file *filp, unsigned long arg) |
|---|
| 2571 | +{ |
|---|
| 2572 | + struct f2fs_gc_range range; |
|---|
| 2573 | + |
|---|
| 2574 | + if (copy_from_user(&range, (struct f2fs_gc_range __user *)arg, |
|---|
| 2575 | + sizeof(range))) |
|---|
| 2576 | + return -EFAULT; |
|---|
| 2577 | + return __f2fs_ioc_gc_range(filp, &range); |
|---|
| 2575 | 2578 | } |
|---|
| 2576 | 2579 | |
|---|
| 2577 | 2580 | static int f2fs_ioc_write_checkpoint(struct file *filp, unsigned long arg) |
|---|
| .. | .. |
|---|
| 2607 | 2610 | { |
|---|
| 2608 | 2611 | struct inode *inode = file_inode(filp); |
|---|
| 2609 | 2612 | struct f2fs_map_blocks map = { .m_next_extent = NULL, |
|---|
| 2610 | | - .m_seg_type = NO_CHECK_TYPE , |
|---|
| 2613 | + .m_seg_type = NO_CHECK_TYPE, |
|---|
| 2611 | 2614 | .m_may_create = false }; |
|---|
| 2612 | | - struct extent_info ei = {0, 0, 0}; |
|---|
| 2615 | + struct extent_info ei = {}; |
|---|
| 2613 | 2616 | pgoff_t pg_start, pg_end, next_pgofs; |
|---|
| 2614 | 2617 | unsigned int blk_per_seg = sbi->blocks_per_seg; |
|---|
| 2615 | 2618 | unsigned int total = 0, sec_num; |
|---|
| .. | .. |
|---|
| 2617 | 2620 | bool fragmented = false; |
|---|
| 2618 | 2621 | int err; |
|---|
| 2619 | 2622 | |
|---|
| 2620 | | - /* if in-place-update policy is enabled, don't waste time here */ |
|---|
| 2621 | | - if (f2fs_should_update_inplace(inode, NULL)) |
|---|
| 2622 | | - return -EINVAL; |
|---|
| 2623 | | - |
|---|
| 2624 | 2623 | pg_start = range->start >> PAGE_SHIFT; |
|---|
| 2625 | 2624 | pg_end = (range->start + range->len) >> PAGE_SHIFT; |
|---|
| 2626 | 2625 | |
|---|
| 2627 | 2626 | f2fs_balance_fs(sbi, true); |
|---|
| 2628 | 2627 | |
|---|
| 2629 | 2628 | inode_lock(inode); |
|---|
| 2629 | + |
|---|
| 2630 | + /* if in-place-update policy is enabled, don't waste time here */ |
|---|
| 2631 | + set_inode_flag(inode, FI_OPU_WRITE); |
|---|
| 2632 | + if (f2fs_should_update_inplace(inode, NULL)) { |
|---|
| 2633 | + err = -EINVAL; |
|---|
| 2634 | + goto out; |
|---|
| 2635 | + } |
|---|
| 2630 | 2636 | |
|---|
| 2631 | 2637 | /* writeback all dirty pages in the range */ |
|---|
| 2632 | 2638 | err = filemap_write_and_wait_range(inode->i_mapping, range->start, |
|---|
| .. | .. |
|---|
| 2638 | 2644 | * lookup mapping info in extent cache, skip defragmenting if physical |
|---|
| 2639 | 2645 | * block addresses are continuous. |
|---|
| 2640 | 2646 | */ |
|---|
| 2641 | | - if (f2fs_lookup_extent_cache(inode, pg_start, &ei)) { |
|---|
| 2647 | + if (f2fs_lookup_read_extent_cache(inode, pg_start, &ei)) { |
|---|
| 2642 | 2648 | if (ei.fofs + ei.len >= pg_end) |
|---|
| 2643 | 2649 | goto out; |
|---|
| 2644 | 2650 | } |
|---|
| .. | .. |
|---|
| 2709 | 2715 | goto check; |
|---|
| 2710 | 2716 | } |
|---|
| 2711 | 2717 | |
|---|
| 2712 | | - set_inode_flag(inode, FI_DO_DEFRAG); |
|---|
| 2718 | + set_inode_flag(inode, FI_SKIP_WRITES); |
|---|
| 2713 | 2719 | |
|---|
| 2714 | 2720 | idx = map.m_lblk; |
|---|
| 2715 | 2721 | while (idx < map.m_lblk + map.m_len && cnt < blk_per_seg) { |
|---|
| .. | .. |
|---|
| 2734 | 2740 | if (map.m_lblk < pg_end && cnt < blk_per_seg) |
|---|
| 2735 | 2741 | goto do_map; |
|---|
| 2736 | 2742 | |
|---|
| 2737 | | - clear_inode_flag(inode, FI_DO_DEFRAG); |
|---|
| 2743 | + clear_inode_flag(inode, FI_SKIP_WRITES); |
|---|
| 2738 | 2744 | |
|---|
| 2739 | 2745 | err = filemap_fdatawrite(inode->i_mapping); |
|---|
| 2740 | 2746 | if (err) |
|---|
| 2741 | 2747 | goto out; |
|---|
| 2742 | 2748 | } |
|---|
| 2743 | 2749 | clear_out: |
|---|
| 2744 | | - clear_inode_flag(inode, FI_DO_DEFRAG); |
|---|
| 2750 | + clear_inode_flag(inode, FI_SKIP_WRITES); |
|---|
| 2745 | 2751 | out: |
|---|
| 2752 | + clear_inode_flag(inode, FI_OPU_WRITE); |
|---|
| 2746 | 2753 | inode_unlock(inode); |
|---|
| 2747 | 2754 | if (!err) |
|---|
| 2748 | 2755 | range->len = (u64)total << PAGE_SHIFT; |
|---|
| .. | .. |
|---|
| 2774 | 2781 | return -EINVAL; |
|---|
| 2775 | 2782 | |
|---|
| 2776 | 2783 | if (unlikely((range.start + range.len) >> PAGE_SHIFT > |
|---|
| 2777 | | - sbi->max_file_blocks)) |
|---|
| 2784 | + max_file_blocks(inode))) |
|---|
| 2778 | 2785 | return -EINVAL; |
|---|
| 2779 | 2786 | |
|---|
| 2780 | 2787 | err = mnt_want_write_file(filp); |
|---|
| .. | .. |
|---|
| 2817 | 2824 | |
|---|
| 2818 | 2825 | if (IS_ENCRYPTED(src) || IS_ENCRYPTED(dst)) |
|---|
| 2819 | 2826 | return -EOPNOTSUPP; |
|---|
| 2827 | + |
|---|
| 2828 | + if (pos_out < 0 || pos_in < 0) |
|---|
| 2829 | + return -EINVAL; |
|---|
| 2820 | 2830 | |
|---|
| 2821 | 2831 | if (src == dst) { |
|---|
| 2822 | 2832 | if (pos_in == pos_out) |
|---|
| .. | .. |
|---|
| 2875 | 2885 | |
|---|
| 2876 | 2886 | f2fs_balance_fs(sbi, true); |
|---|
| 2877 | 2887 | |
|---|
| 2878 | | - down_write(&F2FS_I(src)->i_gc_rwsem[WRITE]); |
|---|
| 2888 | + f2fs_down_write(&F2FS_I(src)->i_gc_rwsem[WRITE]); |
|---|
| 2879 | 2889 | if (src != dst) { |
|---|
| 2880 | 2890 | ret = -EBUSY; |
|---|
| 2881 | | - if (!down_write_trylock(&F2FS_I(dst)->i_gc_rwsem[WRITE])) |
|---|
| 2891 | + if (!f2fs_down_write_trylock(&F2FS_I(dst)->i_gc_rwsem[WRITE])) |
|---|
| 2882 | 2892 | goto out_src; |
|---|
| 2883 | 2893 | } |
|---|
| 2884 | 2894 | |
|---|
| .. | .. |
|---|
| 2896 | 2906 | f2fs_unlock_op(sbi); |
|---|
| 2897 | 2907 | |
|---|
| 2898 | 2908 | if (src != dst) |
|---|
| 2899 | | - up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]); |
|---|
| 2909 | + f2fs_up_write(&F2FS_I(dst)->i_gc_rwsem[WRITE]); |
|---|
| 2900 | 2910 | out_src: |
|---|
| 2901 | | - up_write(&F2FS_I(src)->i_gc_rwsem[WRITE]); |
|---|
| 2911 | + f2fs_up_write(&F2FS_I(src)->i_gc_rwsem[WRITE]); |
|---|
| 2902 | 2912 | out_unlock: |
|---|
| 2903 | 2913 | if (src != dst) |
|---|
| 2904 | 2914 | inode_unlock(dst); |
|---|
| .. | .. |
|---|
| 2907 | 2917 | return ret; |
|---|
| 2908 | 2918 | } |
|---|
| 2909 | 2919 | |
|---|
| 2910 | | -static int f2fs_ioc_move_range(struct file *filp, unsigned long arg) |
|---|
| 2920 | +static int __f2fs_ioc_move_range(struct file *filp, |
|---|
| 2921 | + struct f2fs_move_range *range) |
|---|
| 2911 | 2922 | { |
|---|
| 2912 | | - struct f2fs_move_range range; |
|---|
| 2913 | 2923 | struct fd dst; |
|---|
| 2914 | 2924 | int err; |
|---|
| 2915 | 2925 | |
|---|
| .. | .. |
|---|
| 2917 | 2927 | !(filp->f_mode & FMODE_WRITE)) |
|---|
| 2918 | 2928 | return -EBADF; |
|---|
| 2919 | 2929 | |
|---|
| 2920 | | - if (copy_from_user(&range, (struct f2fs_move_range __user *)arg, |
|---|
| 2921 | | - sizeof(range))) |
|---|
| 2922 | | - return -EFAULT; |
|---|
| 2923 | | - |
|---|
| 2924 | | - dst = fdget(range.dst_fd); |
|---|
| 2930 | + dst = fdget(range->dst_fd); |
|---|
| 2925 | 2931 | if (!dst.file) |
|---|
| 2926 | 2932 | return -EBADF; |
|---|
| 2927 | 2933 | |
|---|
| .. | .. |
|---|
| 2934 | 2940 | if (err) |
|---|
| 2935 | 2941 | goto err_out; |
|---|
| 2936 | 2942 | |
|---|
| 2937 | | - err = f2fs_move_file_range(filp, range.pos_in, dst.file, |
|---|
| 2938 | | - range.pos_out, range.len); |
|---|
| 2943 | + err = f2fs_move_file_range(filp, range->pos_in, dst.file, |
|---|
| 2944 | + range->pos_out, range->len); |
|---|
| 2939 | 2945 | |
|---|
| 2940 | 2946 | mnt_drop_write_file(filp); |
|---|
| 2941 | | - if (err) |
|---|
| 2942 | | - goto err_out; |
|---|
| 2943 | | - |
|---|
| 2944 | | - if (copy_to_user((struct f2fs_move_range __user *)arg, |
|---|
| 2945 | | - &range, sizeof(range))) |
|---|
| 2946 | | - err = -EFAULT; |
|---|
| 2947 | 2947 | err_out: |
|---|
| 2948 | 2948 | fdput(dst); |
|---|
| 2949 | 2949 | return err; |
|---|
| 2950 | +} |
|---|
| 2951 | + |
|---|
| 2952 | +static int f2fs_ioc_move_range(struct file *filp, unsigned long arg) |
|---|
| 2953 | +{ |
|---|
| 2954 | + struct f2fs_move_range range; |
|---|
| 2955 | + |
|---|
| 2956 | + if (copy_from_user(&range, (struct f2fs_move_range __user *)arg, |
|---|
| 2957 | + sizeof(range))) |
|---|
| 2958 | + return -EFAULT; |
|---|
| 2959 | + return __f2fs_ioc_move_range(filp, &range); |
|---|
| 2950 | 2960 | } |
|---|
| 2951 | 2961 | |
|---|
| 2952 | 2962 | static int f2fs_ioc_flush_device(struct file *filp, unsigned long arg) |
|---|
| .. | .. |
|---|
| 2993 | 3003 | end_segno = min(start_segno + range.segments, dev_end_segno); |
|---|
| 2994 | 3004 | |
|---|
| 2995 | 3005 | while (start_segno < end_segno) { |
|---|
| 2996 | | - if (!down_write_trylock(&sbi->gc_lock)) { |
|---|
| 3006 | + if (!f2fs_down_write_trylock(&sbi->gc_lock)) { |
|---|
| 2997 | 3007 | ret = -EBUSY; |
|---|
| 2998 | 3008 | goto out; |
|---|
| 2999 | 3009 | } |
|---|
| 3000 | 3010 | sm->last_victim[GC_CB] = end_segno + 1; |
|---|
| 3001 | 3011 | sm->last_victim[GC_GREEDY] = end_segno + 1; |
|---|
| 3002 | 3012 | sm->last_victim[ALLOC_NEXT] = end_segno + 1; |
|---|
| 3003 | | - ret = f2fs_gc(sbi, true, true, start_segno); |
|---|
| 3013 | + ret = f2fs_gc(sbi, true, true, true, start_segno); |
|---|
| 3004 | 3014 | if (ret == -EAGAIN) |
|---|
| 3005 | 3015 | ret = 0; |
|---|
| 3006 | 3016 | else if (ret < 0) |
|---|
| .. | .. |
|---|
| 3293 | 3303 | if (ret) |
|---|
| 3294 | 3304 | goto out; |
|---|
| 3295 | 3305 | |
|---|
| 3296 | | - if (f2fs_disable_compressed_file(inode)) { |
|---|
| 3306 | + if (!f2fs_disable_compressed_file(inode)) { |
|---|
| 3297 | 3307 | ret = -EOPNOTSUPP; |
|---|
| 3298 | 3308 | goto out; |
|---|
| 3299 | 3309 | } |
|---|
| .. | .. |
|---|
| 3334 | 3344 | map.m_next_extent = &m_next_extent; |
|---|
| 3335 | 3345 | map.m_seg_type = NO_CHECK_TYPE; |
|---|
| 3336 | 3346 | map.m_may_create = false; |
|---|
| 3337 | | - end = F2FS_I_SB(inode)->max_file_blocks; |
|---|
| 3347 | + end = max_file_blocks(inode); |
|---|
| 3338 | 3348 | |
|---|
| 3339 | 3349 | while (map.m_lblk < end) { |
|---|
| 3340 | 3350 | map.m_len = end - map.m_lblk; |
|---|
| 3341 | 3351 | |
|---|
| 3342 | | - down_write(&fi->i_gc_rwsem[WRITE]); |
|---|
| 3352 | + f2fs_down_write(&fi->i_gc_rwsem[WRITE]); |
|---|
| 3343 | 3353 | err = f2fs_map_blocks(inode, &map, 0, F2FS_GET_BLOCK_PRECACHE); |
|---|
| 3344 | | - up_write(&fi->i_gc_rwsem[WRITE]); |
|---|
| 3354 | + f2fs_up_write(&fi->i_gc_rwsem[WRITE]); |
|---|
| 3345 | 3355 | if (err) |
|---|
| 3346 | 3356 | return err; |
|---|
| 3347 | 3357 | |
|---|
| 3348 | 3358 | map.m_lblk = m_next_extent; |
|---|
| 3349 | 3359 | } |
|---|
| 3350 | 3360 | |
|---|
| 3351 | | - return err; |
|---|
| 3361 | + return 0; |
|---|
| 3352 | 3362 | } |
|---|
| 3353 | 3363 | |
|---|
| 3354 | 3364 | static int f2fs_ioc_precache_extents(struct file *filp, unsigned long arg) |
|---|
| .. | .. |
|---|
| 3382 | 3392 | |
|---|
| 3383 | 3393 | if (!f2fs_sb_has_verity(F2FS_I_SB(inode))) { |
|---|
| 3384 | 3394 | f2fs_warn(F2FS_I_SB(inode), |
|---|
| 3385 | | - "Can't enable fs-verity on inode %lu: the verity feature is not enabled on this filesystem.\n", |
|---|
| 3395 | + "Can't enable fs-verity on inode %lu: the verity feature is not enabled on this filesystem", |
|---|
| 3386 | 3396 | inode->i_ino); |
|---|
| 3387 | 3397 | return -EOPNOTSUPP; |
|---|
| 3388 | 3398 | } |
|---|
| .. | .. |
|---|
| 3398 | 3408 | return fsverity_ioctl_measure(filp, (void __user *)arg); |
|---|
| 3399 | 3409 | } |
|---|
| 3400 | 3410 | |
|---|
| 3401 | | -static int f2fs_get_volume_name(struct file *filp, unsigned long arg) |
|---|
| 3411 | +static int f2fs_ioc_read_verity_metadata(struct file *filp, unsigned long arg) |
|---|
| 3412 | +{ |
|---|
| 3413 | + if (!f2fs_sb_has_verity(F2FS_I_SB(file_inode(filp)))) |
|---|
| 3414 | + return -EOPNOTSUPP; |
|---|
| 3415 | + |
|---|
| 3416 | + return fsverity_ioctl_read_metadata(filp, (const void __user *)arg); |
|---|
| 3417 | +} |
|---|
| 3418 | + |
|---|
| 3419 | +static int f2fs_ioc_getfslabel(struct file *filp, unsigned long arg) |
|---|
| 3402 | 3420 | { |
|---|
| 3403 | 3421 | struct inode *inode = file_inode(filp); |
|---|
| 3404 | 3422 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
|---|
| .. | .. |
|---|
| 3410 | 3428 | if (!vbuf) |
|---|
| 3411 | 3429 | return -ENOMEM; |
|---|
| 3412 | 3430 | |
|---|
| 3413 | | - down_read(&sbi->sb_lock); |
|---|
| 3431 | + f2fs_down_read(&sbi->sb_lock); |
|---|
| 3414 | 3432 | count = utf16s_to_utf8s(sbi->raw_super->volume_name, |
|---|
| 3415 | 3433 | ARRAY_SIZE(sbi->raw_super->volume_name), |
|---|
| 3416 | 3434 | UTF16_LITTLE_ENDIAN, vbuf, MAX_VOLUME_NAME); |
|---|
| 3417 | | - up_read(&sbi->sb_lock); |
|---|
| 3435 | + f2fs_up_read(&sbi->sb_lock); |
|---|
| 3418 | 3436 | |
|---|
| 3419 | 3437 | if (copy_to_user((char __user *)arg, vbuf, |
|---|
| 3420 | 3438 | min(FSLABEL_MAX, count))) |
|---|
| 3421 | 3439 | err = -EFAULT; |
|---|
| 3422 | 3440 | |
|---|
| 3423 | | - kvfree(vbuf); |
|---|
| 3441 | + kfree(vbuf); |
|---|
| 3424 | 3442 | return err; |
|---|
| 3425 | 3443 | } |
|---|
| 3426 | 3444 | |
|---|
| 3427 | | -static int f2fs_set_volume_name(struct file *filp, unsigned long arg) |
|---|
| 3445 | +static int f2fs_ioc_setfslabel(struct file *filp, unsigned long arg) |
|---|
| 3428 | 3446 | { |
|---|
| 3429 | 3447 | struct inode *inode = file_inode(filp); |
|---|
| 3430 | 3448 | struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
|---|
| .. | .. |
|---|
| 3442 | 3460 | if (err) |
|---|
| 3443 | 3461 | goto out; |
|---|
| 3444 | 3462 | |
|---|
| 3445 | | - down_write(&sbi->sb_lock); |
|---|
| 3463 | + f2fs_down_write(&sbi->sb_lock); |
|---|
| 3446 | 3464 | |
|---|
| 3447 | 3465 | memset(sbi->raw_super->volume_name, 0, |
|---|
| 3448 | 3466 | sizeof(sbi->raw_super->volume_name)); |
|---|
| .. | .. |
|---|
| 3452 | 3470 | |
|---|
| 3453 | 3471 | err = f2fs_commit_super(sbi, false); |
|---|
| 3454 | 3472 | |
|---|
| 3455 | | - up_write(&sbi->sb_lock); |
|---|
| 3473 | + f2fs_up_write(&sbi->sb_lock); |
|---|
| 3456 | 3474 | |
|---|
| 3457 | 3475 | mnt_drop_write_file(filp); |
|---|
| 3458 | 3476 | out: |
|---|
| .. | .. |
|---|
| 3471 | 3489 | if (!f2fs_compressed_file(inode)) |
|---|
| 3472 | 3490 | return -EINVAL; |
|---|
| 3473 | 3491 | |
|---|
| 3474 | | - blocks = F2FS_I(inode)->i_compr_blocks; |
|---|
| 3492 | + blocks = atomic_read(&F2FS_I(inode)->i_compr_blocks); |
|---|
| 3475 | 3493 | return put_user(blocks, (u64 __user *)arg); |
|---|
| 3476 | 3494 | } |
|---|
| 3477 | 3495 | |
|---|
| .. | .. |
|---|
| 3556 | 3574 | inode_lock(inode); |
|---|
| 3557 | 3575 | |
|---|
| 3558 | 3576 | writecount = atomic_read(&inode->i_writecount); |
|---|
| 3559 | | - if ((filp->f_mode & FMODE_WRITE && writecount != 1) || writecount) { |
|---|
| 3577 | + if ((filp->f_mode & FMODE_WRITE && writecount != 1) || |
|---|
| 3578 | + (!(filp->f_mode & FMODE_WRITE) && writecount)) { |
|---|
| 3560 | 3579 | ret = -EBUSY; |
|---|
| 3561 | 3580 | goto out; |
|---|
| 3562 | 3581 | } |
|---|
| 3563 | 3582 | |
|---|
| 3564 | | - if (IS_IMMUTABLE(inode)) { |
|---|
| 3583 | + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { |
|---|
| 3565 | 3584 | ret = -EINVAL; |
|---|
| 3566 | 3585 | goto out; |
|---|
| 3567 | 3586 | } |
|---|
| .. | .. |
|---|
| 3570 | 3589 | if (ret) |
|---|
| 3571 | 3590 | goto out; |
|---|
| 3572 | 3591 | |
|---|
| 3573 | | - if (!F2FS_I(inode)->i_compr_blocks) |
|---|
| 3574 | | - goto out; |
|---|
| 3575 | | - |
|---|
| 3576 | | - F2FS_I(inode)->i_flags |= F2FS_IMMUTABLE_FL; |
|---|
| 3577 | | - f2fs_set_inode_flags(inode); |
|---|
| 3592 | + set_inode_flag(inode, FI_COMPRESS_RELEASED); |
|---|
| 3578 | 3593 | inode->i_ctime = current_time(inode); |
|---|
| 3579 | 3594 | f2fs_mark_inode_dirty_sync(inode, true); |
|---|
| 3580 | 3595 | |
|---|
| 3581 | | - down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 3582 | | - down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3596 | + if (!atomic_read(&F2FS_I(inode)->i_compr_blocks)) |
|---|
| 3597 | + goto out; |
|---|
| 3598 | + |
|---|
| 3599 | + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 3600 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3583 | 3601 | |
|---|
| 3584 | 3602 | last_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); |
|---|
| 3585 | 3603 | |
|---|
| .. | .. |
|---|
| 3614 | 3632 | released_blocks += ret; |
|---|
| 3615 | 3633 | } |
|---|
| 3616 | 3634 | |
|---|
| 3617 | | - up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 3618 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3635 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3636 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 3619 | 3637 | out: |
|---|
| 3620 | 3638 | inode_unlock(inode); |
|---|
| 3621 | 3639 | |
|---|
| .. | .. |
|---|
| 3623 | 3641 | |
|---|
| 3624 | 3642 | if (ret >= 0) { |
|---|
| 3625 | 3643 | ret = put_user(released_blocks, (u64 __user *)arg); |
|---|
| 3626 | | - } else if (released_blocks && F2FS_I(inode)->i_compr_blocks) { |
|---|
| 3644 | + } else if (released_blocks && |
|---|
| 3645 | + atomic_read(&F2FS_I(inode)->i_compr_blocks)) { |
|---|
| 3627 | 3646 | set_sbi_flag(sbi, SBI_NEED_FSCK); |
|---|
| 3628 | 3647 | f2fs_warn(sbi, "%s: partial blocks were released i_ino=%lx " |
|---|
| 3629 | | - "iblocks=%llu, released=%u, compr_blocks=%llu, " |
|---|
| 3648 | + "iblocks=%llu, released=%u, compr_blocks=%u, " |
|---|
| 3630 | 3649 | "run fsck to fix.", |
|---|
| 3631 | | - __func__, inode->i_ino, (u64)inode->i_blocks, |
|---|
| 3650 | + __func__, inode->i_ino, inode->i_blocks, |
|---|
| 3632 | 3651 | released_blocks, |
|---|
| 3633 | | - F2FS_I(inode)->i_compr_blocks); |
|---|
| 3652 | + atomic_read(&F2FS_I(inode)->i_compr_blocks)); |
|---|
| 3634 | 3653 | } |
|---|
| 3635 | 3654 | |
|---|
| 3636 | 3655 | return ret; |
|---|
| .. | .. |
|---|
| 3718 | 3737 | if (ret) |
|---|
| 3719 | 3738 | return ret; |
|---|
| 3720 | 3739 | |
|---|
| 3721 | | - if (F2FS_I(inode)->i_compr_blocks) |
|---|
| 3740 | + if (atomic_read(&F2FS_I(inode)->i_compr_blocks)) |
|---|
| 3722 | 3741 | goto out; |
|---|
| 3723 | 3742 | |
|---|
| 3724 | 3743 | f2fs_balance_fs(F2FS_I_SB(inode), true); |
|---|
| 3725 | 3744 | |
|---|
| 3726 | 3745 | inode_lock(inode); |
|---|
| 3727 | 3746 | |
|---|
| 3728 | | - if (!IS_IMMUTABLE(inode)) { |
|---|
| 3747 | + if (!is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { |
|---|
| 3729 | 3748 | ret = -EINVAL; |
|---|
| 3730 | 3749 | goto unlock_inode; |
|---|
| 3731 | 3750 | } |
|---|
| 3732 | 3751 | |
|---|
| 3733 | | - down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 3734 | | - down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3752 | + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 3753 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3735 | 3754 | |
|---|
| 3736 | 3755 | last_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); |
|---|
| 3737 | 3756 | |
|---|
| .. | .. |
|---|
| 3766 | 3785 | reserved_blocks += ret; |
|---|
| 3767 | 3786 | } |
|---|
| 3768 | 3787 | |
|---|
| 3769 | | - up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 3770 | | - up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3788 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3789 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 3771 | 3790 | |
|---|
| 3772 | 3791 | if (ret >= 0) { |
|---|
| 3773 | | - F2FS_I(inode)->i_flags &= ~F2FS_IMMUTABLE_FL; |
|---|
| 3774 | | - f2fs_set_inode_flags(inode); |
|---|
| 3792 | + clear_inode_flag(inode, FI_COMPRESS_RELEASED); |
|---|
| 3775 | 3793 | inode->i_ctime = current_time(inode); |
|---|
| 3776 | 3794 | f2fs_mark_inode_dirty_sync(inode, true); |
|---|
| 3777 | 3795 | } |
|---|
| .. | .. |
|---|
| 3782 | 3800 | |
|---|
| 3783 | 3801 | if (ret >= 0) { |
|---|
| 3784 | 3802 | ret = put_user(reserved_blocks, (u64 __user *)arg); |
|---|
| 3785 | | - } else if (reserved_blocks && F2FS_I(inode)->i_compr_blocks) { |
|---|
| 3803 | + } else if (reserved_blocks && |
|---|
| 3804 | + atomic_read(&F2FS_I(inode)->i_compr_blocks)) { |
|---|
| 3786 | 3805 | set_sbi_flag(sbi, SBI_NEED_FSCK); |
|---|
| 3787 | 3806 | f2fs_warn(sbi, "%s: partial blocks were released i_ino=%lx " |
|---|
| 3788 | | - "iblocks=%llu, reserved=%u, compr_blocks=%llu, " |
|---|
| 3807 | + "iblocks=%llu, reserved=%u, compr_blocks=%u, " |
|---|
| 3789 | 3808 | "run fsck to fix.", |
|---|
| 3790 | | - __func__, inode->i_ino, (u64)inode->i_blocks, |
|---|
| 3809 | + __func__, inode->i_ino, inode->i_blocks, |
|---|
| 3791 | 3810 | reserved_blocks, |
|---|
| 3792 | | - F2FS_I(inode)->i_compr_blocks); |
|---|
| 3811 | + atomic_read(&F2FS_I(inode)->i_compr_blocks)); |
|---|
| 3793 | 3812 | } |
|---|
| 3794 | 3813 | |
|---|
| 3795 | 3814 | return ret; |
|---|
| 3796 | 3815 | } |
|---|
| 3797 | 3816 | |
|---|
| 3798 | | -long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
|---|
| 3817 | +static int f2fs_secure_erase(struct block_device *bdev, struct inode *inode, |
|---|
| 3818 | + pgoff_t off, block_t block, block_t len, u32 flags) |
|---|
| 3799 | 3819 | { |
|---|
| 3800 | | - if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) |
|---|
| 3801 | | - return -EIO; |
|---|
| 3802 | | - if (!f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp)))) |
|---|
| 3803 | | - return -ENOSPC; |
|---|
| 3820 | + struct request_queue *q = bdev_get_queue(bdev); |
|---|
| 3821 | + sector_t sector = SECTOR_FROM_BLOCK(block); |
|---|
| 3822 | + sector_t nr_sects = SECTOR_FROM_BLOCK(len); |
|---|
| 3823 | + int ret = 0; |
|---|
| 3804 | 3824 | |
|---|
| 3825 | + if (!q) |
|---|
| 3826 | + return -ENXIO; |
|---|
| 3827 | + |
|---|
| 3828 | + if (flags & F2FS_TRIM_FILE_DISCARD) |
|---|
| 3829 | + ret = blkdev_issue_discard(bdev, sector, nr_sects, GFP_NOFS, |
|---|
| 3830 | + blk_queue_secure_erase(q) ? |
|---|
| 3831 | + BLKDEV_DISCARD_SECURE : 0); |
|---|
| 3832 | + |
|---|
| 3833 | + if (!ret && (flags & F2FS_TRIM_FILE_ZEROOUT)) { |
|---|
| 3834 | + if (IS_ENCRYPTED(inode)) |
|---|
| 3835 | + ret = fscrypt_zeroout_range(inode, off, block, len); |
|---|
| 3836 | + else |
|---|
| 3837 | + ret = blkdev_issue_zeroout(bdev, sector, nr_sects, |
|---|
| 3838 | + GFP_NOFS, 0); |
|---|
| 3839 | + } |
|---|
| 3840 | + |
|---|
| 3841 | + return ret; |
|---|
| 3842 | +} |
|---|
| 3843 | + |
|---|
| 3844 | +static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) |
|---|
| 3845 | +{ |
|---|
| 3846 | + struct inode *inode = file_inode(filp); |
|---|
| 3847 | + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
|---|
| 3848 | + struct address_space *mapping = inode->i_mapping; |
|---|
| 3849 | + struct block_device *prev_bdev = NULL; |
|---|
| 3850 | + struct f2fs_sectrim_range range; |
|---|
| 3851 | + pgoff_t index, pg_end, prev_index = 0; |
|---|
| 3852 | + block_t prev_block = 0, len = 0; |
|---|
| 3853 | + loff_t end_addr; |
|---|
| 3854 | + bool to_end = false; |
|---|
| 3855 | + int ret = 0; |
|---|
| 3856 | + |
|---|
| 3857 | + if (!(filp->f_mode & FMODE_WRITE)) |
|---|
| 3858 | + return -EBADF; |
|---|
| 3859 | + |
|---|
| 3860 | + if (copy_from_user(&range, (struct f2fs_sectrim_range __user *)arg, |
|---|
| 3861 | + sizeof(range))) |
|---|
| 3862 | + return -EFAULT; |
|---|
| 3863 | + |
|---|
| 3864 | + if (range.flags == 0 || (range.flags & ~F2FS_TRIM_FILE_MASK) || |
|---|
| 3865 | + !S_ISREG(inode->i_mode)) |
|---|
| 3866 | + return -EINVAL; |
|---|
| 3867 | + |
|---|
| 3868 | + if (((range.flags & F2FS_TRIM_FILE_DISCARD) && |
|---|
| 3869 | + !f2fs_hw_support_discard(sbi)) || |
|---|
| 3870 | + ((range.flags & F2FS_TRIM_FILE_ZEROOUT) && |
|---|
| 3871 | + IS_ENCRYPTED(inode) && f2fs_is_multi_device(sbi))) |
|---|
| 3872 | + return -EOPNOTSUPP; |
|---|
| 3873 | + |
|---|
| 3874 | + file_start_write(filp); |
|---|
| 3875 | + inode_lock(inode); |
|---|
| 3876 | + |
|---|
| 3877 | + if (f2fs_is_atomic_file(inode) || f2fs_compressed_file(inode) || |
|---|
| 3878 | + range.start >= inode->i_size) { |
|---|
| 3879 | + ret = -EINVAL; |
|---|
| 3880 | + goto err; |
|---|
| 3881 | + } |
|---|
| 3882 | + |
|---|
| 3883 | + if (range.len == 0) |
|---|
| 3884 | + goto err; |
|---|
| 3885 | + |
|---|
| 3886 | + if (inode->i_size - range.start > range.len) { |
|---|
| 3887 | + end_addr = range.start + range.len; |
|---|
| 3888 | + } else { |
|---|
| 3889 | + end_addr = range.len == (u64)-1 ? |
|---|
| 3890 | + sbi->sb->s_maxbytes : inode->i_size; |
|---|
| 3891 | + to_end = true; |
|---|
| 3892 | + } |
|---|
| 3893 | + |
|---|
| 3894 | + if (!IS_ALIGNED(range.start, F2FS_BLKSIZE) || |
|---|
| 3895 | + (!to_end && !IS_ALIGNED(end_addr, F2FS_BLKSIZE))) { |
|---|
| 3896 | + ret = -EINVAL; |
|---|
| 3897 | + goto err; |
|---|
| 3898 | + } |
|---|
| 3899 | + |
|---|
| 3900 | + index = F2FS_BYTES_TO_BLK(range.start); |
|---|
| 3901 | + pg_end = DIV_ROUND_UP(end_addr, F2FS_BLKSIZE); |
|---|
| 3902 | + |
|---|
| 3903 | + ret = f2fs_convert_inline_inode(inode); |
|---|
| 3904 | + if (ret) |
|---|
| 3905 | + goto err; |
|---|
| 3906 | + |
|---|
| 3907 | + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 3908 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3909 | + |
|---|
| 3910 | + ret = filemap_write_and_wait_range(mapping, range.start, |
|---|
| 3911 | + to_end ? LLONG_MAX : end_addr - 1); |
|---|
| 3912 | + if (ret) |
|---|
| 3913 | + goto out; |
|---|
| 3914 | + |
|---|
| 3915 | + truncate_inode_pages_range(mapping, range.start, |
|---|
| 3916 | + to_end ? -1 : end_addr - 1); |
|---|
| 3917 | + |
|---|
| 3918 | + while (index < pg_end) { |
|---|
| 3919 | + struct dnode_of_data dn; |
|---|
| 3920 | + pgoff_t end_offset, count; |
|---|
| 3921 | + int i; |
|---|
| 3922 | + |
|---|
| 3923 | + set_new_dnode(&dn, inode, NULL, NULL, 0); |
|---|
| 3924 | + ret = f2fs_get_dnode_of_data(&dn, index, LOOKUP_NODE); |
|---|
| 3925 | + if (ret) { |
|---|
| 3926 | + if (ret == -ENOENT) { |
|---|
| 3927 | + index = f2fs_get_next_page_offset(&dn, index); |
|---|
| 3928 | + continue; |
|---|
| 3929 | + } |
|---|
| 3930 | + goto out; |
|---|
| 3931 | + } |
|---|
| 3932 | + |
|---|
| 3933 | + end_offset = ADDRS_PER_PAGE(dn.node_page, inode); |
|---|
| 3934 | + count = min(end_offset - dn.ofs_in_node, pg_end - index); |
|---|
| 3935 | + for (i = 0; i < count; i++, index++, dn.ofs_in_node++) { |
|---|
| 3936 | + struct block_device *cur_bdev; |
|---|
| 3937 | + block_t blkaddr = f2fs_data_blkaddr(&dn); |
|---|
| 3938 | + |
|---|
| 3939 | + if (!__is_valid_data_blkaddr(blkaddr)) |
|---|
| 3940 | + continue; |
|---|
| 3941 | + |
|---|
| 3942 | + if (!f2fs_is_valid_blkaddr(sbi, blkaddr, |
|---|
| 3943 | + DATA_GENERIC_ENHANCE)) { |
|---|
| 3944 | + ret = -EFSCORRUPTED; |
|---|
| 3945 | + f2fs_put_dnode(&dn); |
|---|
| 3946 | + goto out; |
|---|
| 3947 | + } |
|---|
| 3948 | + |
|---|
| 3949 | + cur_bdev = f2fs_target_device(sbi, blkaddr, NULL); |
|---|
| 3950 | + if (f2fs_is_multi_device(sbi)) { |
|---|
| 3951 | + int di = f2fs_target_device_index(sbi, blkaddr); |
|---|
| 3952 | + |
|---|
| 3953 | + blkaddr -= FDEV(di).start_blk; |
|---|
| 3954 | + } |
|---|
| 3955 | + |
|---|
| 3956 | + if (len) { |
|---|
| 3957 | + if (prev_bdev == cur_bdev && |
|---|
| 3958 | + index == prev_index + len && |
|---|
| 3959 | + blkaddr == prev_block + len) { |
|---|
| 3960 | + len++; |
|---|
| 3961 | + } else { |
|---|
| 3962 | + ret = f2fs_secure_erase(prev_bdev, |
|---|
| 3963 | + inode, prev_index, prev_block, |
|---|
| 3964 | + len, range.flags); |
|---|
| 3965 | + if (ret) { |
|---|
| 3966 | + f2fs_put_dnode(&dn); |
|---|
| 3967 | + goto out; |
|---|
| 3968 | + } |
|---|
| 3969 | + |
|---|
| 3970 | + len = 0; |
|---|
| 3971 | + } |
|---|
| 3972 | + } |
|---|
| 3973 | + |
|---|
| 3974 | + if (!len) { |
|---|
| 3975 | + prev_bdev = cur_bdev; |
|---|
| 3976 | + prev_index = index; |
|---|
| 3977 | + prev_block = blkaddr; |
|---|
| 3978 | + len = 1; |
|---|
| 3979 | + } |
|---|
| 3980 | + } |
|---|
| 3981 | + |
|---|
| 3982 | + f2fs_put_dnode(&dn); |
|---|
| 3983 | + |
|---|
| 3984 | + if (fatal_signal_pending(current)) { |
|---|
| 3985 | + ret = -EINTR; |
|---|
| 3986 | + goto out; |
|---|
| 3987 | + } |
|---|
| 3988 | + cond_resched(); |
|---|
| 3989 | + } |
|---|
| 3990 | + |
|---|
| 3991 | + if (len) |
|---|
| 3992 | + ret = f2fs_secure_erase(prev_bdev, inode, prev_index, |
|---|
| 3993 | + prev_block, len, range.flags); |
|---|
| 3994 | +out: |
|---|
| 3995 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3996 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 3997 | +err: |
|---|
| 3998 | + inode_unlock(inode); |
|---|
| 3999 | + file_end_write(filp); |
|---|
| 4000 | + |
|---|
| 4001 | + return ret; |
|---|
| 4002 | +} |
|---|
| 4003 | + |
|---|
| 4004 | +static int f2fs_ioc_get_compress_option(struct file *filp, unsigned long arg) |
|---|
| 4005 | +{ |
|---|
| 4006 | + struct inode *inode = file_inode(filp); |
|---|
| 4007 | + struct f2fs_comp_option option; |
|---|
| 4008 | + |
|---|
| 4009 | + if (!f2fs_sb_has_compression(F2FS_I_SB(inode))) |
|---|
| 4010 | + return -EOPNOTSUPP; |
|---|
| 4011 | + |
|---|
| 4012 | + inode_lock_shared(inode); |
|---|
| 4013 | + |
|---|
| 4014 | + if (!f2fs_compressed_file(inode)) { |
|---|
| 4015 | + inode_unlock_shared(inode); |
|---|
| 4016 | + return -ENODATA; |
|---|
| 4017 | + } |
|---|
| 4018 | + |
|---|
| 4019 | + option.algorithm = F2FS_I(inode)->i_compress_algorithm; |
|---|
| 4020 | + option.log_cluster_size = F2FS_I(inode)->i_log_cluster_size; |
|---|
| 4021 | + |
|---|
| 4022 | + inode_unlock_shared(inode); |
|---|
| 4023 | + |
|---|
| 4024 | + if (copy_to_user((struct f2fs_comp_option __user *)arg, &option, |
|---|
| 4025 | + sizeof(option))) |
|---|
| 4026 | + return -EFAULT; |
|---|
| 4027 | + |
|---|
| 4028 | + return 0; |
|---|
| 4029 | +} |
|---|
| 4030 | + |
|---|
| 4031 | +static int f2fs_ioc_set_compress_option(struct file *filp, unsigned long arg) |
|---|
| 4032 | +{ |
|---|
| 4033 | + struct inode *inode = file_inode(filp); |
|---|
| 4034 | + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
|---|
| 4035 | + struct f2fs_comp_option option; |
|---|
| 4036 | + int ret = 0; |
|---|
| 4037 | + |
|---|
| 4038 | + if (!f2fs_sb_has_compression(sbi)) |
|---|
| 4039 | + return -EOPNOTSUPP; |
|---|
| 4040 | + |
|---|
| 4041 | + if (!(filp->f_mode & FMODE_WRITE)) |
|---|
| 4042 | + return -EBADF; |
|---|
| 4043 | + |
|---|
| 4044 | + if (copy_from_user(&option, (struct f2fs_comp_option __user *)arg, |
|---|
| 4045 | + sizeof(option))) |
|---|
| 4046 | + return -EFAULT; |
|---|
| 4047 | + |
|---|
| 4048 | + if (!f2fs_compressed_file(inode) || |
|---|
| 4049 | + option.log_cluster_size < MIN_COMPRESS_LOG_SIZE || |
|---|
| 4050 | + option.log_cluster_size > MAX_COMPRESS_LOG_SIZE || |
|---|
| 4051 | + option.algorithm >= COMPRESS_MAX) |
|---|
| 4052 | + return -EINVAL; |
|---|
| 4053 | + |
|---|
| 4054 | + file_start_write(filp); |
|---|
| 4055 | + inode_lock(inode); |
|---|
| 4056 | + |
|---|
| 4057 | + if (f2fs_is_mmap_file(inode) || get_dirty_pages(inode)) { |
|---|
| 4058 | + ret = -EBUSY; |
|---|
| 4059 | + goto out; |
|---|
| 4060 | + } |
|---|
| 4061 | + |
|---|
| 4062 | + if (inode->i_size != 0) { |
|---|
| 4063 | + ret = -EFBIG; |
|---|
| 4064 | + goto out; |
|---|
| 4065 | + } |
|---|
| 4066 | + |
|---|
| 4067 | + F2FS_I(inode)->i_compress_algorithm = option.algorithm; |
|---|
| 4068 | + F2FS_I(inode)->i_log_cluster_size = option.log_cluster_size; |
|---|
| 4069 | + F2FS_I(inode)->i_cluster_size = 1 << option.log_cluster_size; |
|---|
| 4070 | + f2fs_mark_inode_dirty_sync(inode, true); |
|---|
| 4071 | + |
|---|
| 4072 | + if (!f2fs_is_compress_backend_ready(inode)) |
|---|
| 4073 | + f2fs_warn(sbi, "compression algorithm is successfully set, " |
|---|
| 4074 | + "but current kernel doesn't support this algorithm."); |
|---|
| 4075 | +out: |
|---|
| 4076 | + inode_unlock(inode); |
|---|
| 4077 | + file_end_write(filp); |
|---|
| 4078 | + |
|---|
| 4079 | + return ret; |
|---|
| 4080 | +} |
|---|
| 4081 | + |
|---|
| 4082 | +static int redirty_blocks(struct inode *inode, pgoff_t page_idx, int len) |
|---|
| 4083 | +{ |
|---|
| 4084 | + DEFINE_READAHEAD(ractl, NULL, inode->i_mapping, page_idx); |
|---|
| 4085 | + struct address_space *mapping = inode->i_mapping; |
|---|
| 4086 | + struct page *page; |
|---|
| 4087 | + pgoff_t redirty_idx = page_idx; |
|---|
| 4088 | + int i, page_len = 0, ret = 0; |
|---|
| 4089 | + |
|---|
| 4090 | + page_cache_ra_unbounded(&ractl, len, 0); |
|---|
| 4091 | + |
|---|
| 4092 | + for (i = 0; i < len; i++, page_idx++) { |
|---|
| 4093 | + page = read_cache_page(mapping, page_idx, NULL, NULL); |
|---|
| 4094 | + if (IS_ERR(page)) { |
|---|
| 4095 | + ret = PTR_ERR(page); |
|---|
| 4096 | + break; |
|---|
| 4097 | + } |
|---|
| 4098 | + page_len++; |
|---|
| 4099 | + } |
|---|
| 4100 | + |
|---|
| 4101 | + for (i = 0; i < page_len; i++, redirty_idx++) { |
|---|
| 4102 | + page = find_lock_page(mapping, redirty_idx); |
|---|
| 4103 | + if (!page) { |
|---|
| 4104 | + ret = -ENOMEM; |
|---|
| 4105 | + break; |
|---|
| 4106 | + } |
|---|
| 4107 | + set_page_dirty(page); |
|---|
| 4108 | + f2fs_put_page(page, 1); |
|---|
| 4109 | + f2fs_put_page(page, 0); |
|---|
| 4110 | + } |
|---|
| 4111 | + |
|---|
| 4112 | + return ret; |
|---|
| 4113 | +} |
|---|
| 4114 | + |
|---|
| 4115 | +static int f2fs_ioc_decompress_file(struct file *filp, unsigned long arg) |
|---|
| 4116 | +{ |
|---|
| 4117 | + struct inode *inode = file_inode(filp); |
|---|
| 4118 | + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
|---|
| 4119 | + struct f2fs_inode_info *fi = F2FS_I(inode); |
|---|
| 4120 | + pgoff_t page_idx = 0, last_idx; |
|---|
| 4121 | + unsigned int blk_per_seg = sbi->blocks_per_seg; |
|---|
| 4122 | + int cluster_size = F2FS_I(inode)->i_cluster_size; |
|---|
| 4123 | + int count, ret; |
|---|
| 4124 | + |
|---|
| 4125 | + if (!f2fs_sb_has_compression(sbi) || |
|---|
| 4126 | + F2FS_OPTION(sbi).compress_mode != COMPR_MODE_USER) |
|---|
| 4127 | + return -EOPNOTSUPP; |
|---|
| 4128 | + |
|---|
| 4129 | + if (!(filp->f_mode & FMODE_WRITE)) |
|---|
| 4130 | + return -EBADF; |
|---|
| 4131 | + |
|---|
| 4132 | + if (!f2fs_compressed_file(inode)) |
|---|
| 4133 | + return -EINVAL; |
|---|
| 4134 | + |
|---|
| 4135 | + f2fs_balance_fs(F2FS_I_SB(inode), true); |
|---|
| 4136 | + |
|---|
| 4137 | + file_start_write(filp); |
|---|
| 4138 | + inode_lock(inode); |
|---|
| 4139 | + |
|---|
| 4140 | + if (!f2fs_is_compress_backend_ready(inode)) { |
|---|
| 4141 | + ret = -EOPNOTSUPP; |
|---|
| 4142 | + goto out; |
|---|
| 4143 | + } |
|---|
| 4144 | + |
|---|
| 4145 | + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { |
|---|
| 4146 | + ret = -EINVAL; |
|---|
| 4147 | + goto out; |
|---|
| 4148 | + } |
|---|
| 4149 | + |
|---|
| 4150 | + ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); |
|---|
| 4151 | + if (ret) |
|---|
| 4152 | + goto out; |
|---|
| 4153 | + |
|---|
| 4154 | + if (!atomic_read(&fi->i_compr_blocks)) |
|---|
| 4155 | + goto out; |
|---|
| 4156 | + |
|---|
| 4157 | + last_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); |
|---|
| 4158 | + |
|---|
| 4159 | + count = last_idx - page_idx; |
|---|
| 4160 | + while (count) { |
|---|
| 4161 | + int len = min(cluster_size, count); |
|---|
| 4162 | + |
|---|
| 4163 | + ret = redirty_blocks(inode, page_idx, len); |
|---|
| 4164 | + if (ret < 0) |
|---|
| 4165 | + break; |
|---|
| 4166 | + |
|---|
| 4167 | + if (get_dirty_pages(inode) >= blk_per_seg) |
|---|
| 4168 | + filemap_fdatawrite(inode->i_mapping); |
|---|
| 4169 | + |
|---|
| 4170 | + count -= len; |
|---|
| 4171 | + page_idx += len; |
|---|
| 4172 | + } |
|---|
| 4173 | + |
|---|
| 4174 | + if (!ret) |
|---|
| 4175 | + ret = filemap_write_and_wait_range(inode->i_mapping, 0, |
|---|
| 4176 | + LLONG_MAX); |
|---|
| 4177 | + |
|---|
| 4178 | + if (ret) |
|---|
| 4179 | + f2fs_warn(sbi, "%s: The file might be partially decompressed (errno=%d). Please delete the file.", |
|---|
| 4180 | + __func__, ret); |
|---|
| 4181 | +out: |
|---|
| 4182 | + inode_unlock(inode); |
|---|
| 4183 | + file_end_write(filp); |
|---|
| 4184 | + |
|---|
| 4185 | + return ret; |
|---|
| 4186 | +} |
|---|
| 4187 | + |
|---|
| 4188 | +static int f2fs_ioc_compress_file(struct file *filp, unsigned long arg) |
|---|
| 4189 | +{ |
|---|
| 4190 | + struct inode *inode = file_inode(filp); |
|---|
| 4191 | + struct f2fs_sb_info *sbi = F2FS_I_SB(inode); |
|---|
| 4192 | + pgoff_t page_idx = 0, last_idx; |
|---|
| 4193 | + unsigned int blk_per_seg = sbi->blocks_per_seg; |
|---|
| 4194 | + int cluster_size = F2FS_I(inode)->i_cluster_size; |
|---|
| 4195 | + int count, ret; |
|---|
| 4196 | + |
|---|
| 4197 | + if (!f2fs_sb_has_compression(sbi) || |
|---|
| 4198 | + F2FS_OPTION(sbi).compress_mode != COMPR_MODE_USER) |
|---|
| 4199 | + return -EOPNOTSUPP; |
|---|
| 4200 | + |
|---|
| 4201 | + if (!(filp->f_mode & FMODE_WRITE)) |
|---|
| 4202 | + return -EBADF; |
|---|
| 4203 | + |
|---|
| 4204 | + if (!f2fs_compressed_file(inode)) |
|---|
| 4205 | + return -EINVAL; |
|---|
| 4206 | + |
|---|
| 4207 | + f2fs_balance_fs(F2FS_I_SB(inode), true); |
|---|
| 4208 | + |
|---|
| 4209 | + file_start_write(filp); |
|---|
| 4210 | + inode_lock(inode); |
|---|
| 4211 | + |
|---|
| 4212 | + if (!f2fs_is_compress_backend_ready(inode)) { |
|---|
| 4213 | + ret = -EOPNOTSUPP; |
|---|
| 4214 | + goto out; |
|---|
| 4215 | + } |
|---|
| 4216 | + |
|---|
| 4217 | + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { |
|---|
| 4218 | + ret = -EINVAL; |
|---|
| 4219 | + goto out; |
|---|
| 4220 | + } |
|---|
| 4221 | + |
|---|
| 4222 | + ret = filemap_write_and_wait_range(inode->i_mapping, 0, LLONG_MAX); |
|---|
| 4223 | + if (ret) |
|---|
| 4224 | + goto out; |
|---|
| 4225 | + |
|---|
| 4226 | + set_inode_flag(inode, FI_ENABLE_COMPRESS); |
|---|
| 4227 | + |
|---|
| 4228 | + last_idx = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); |
|---|
| 4229 | + |
|---|
| 4230 | + count = last_idx - page_idx; |
|---|
| 4231 | + while (count) { |
|---|
| 4232 | + int len = min(cluster_size, count); |
|---|
| 4233 | + |
|---|
| 4234 | + ret = redirty_blocks(inode, page_idx, len); |
|---|
| 4235 | + if (ret < 0) |
|---|
| 4236 | + break; |
|---|
| 4237 | + |
|---|
| 4238 | + if (get_dirty_pages(inode) >= blk_per_seg) |
|---|
| 4239 | + filemap_fdatawrite(inode->i_mapping); |
|---|
| 4240 | + |
|---|
| 4241 | + count -= len; |
|---|
| 4242 | + page_idx += len; |
|---|
| 4243 | + } |
|---|
| 4244 | + |
|---|
| 4245 | + if (!ret) |
|---|
| 4246 | + ret = filemap_write_and_wait_range(inode->i_mapping, 0, |
|---|
| 4247 | + LLONG_MAX); |
|---|
| 4248 | + |
|---|
| 4249 | + clear_inode_flag(inode, FI_ENABLE_COMPRESS); |
|---|
| 4250 | + |
|---|
| 4251 | + if (ret) |
|---|
| 4252 | + f2fs_warn(sbi, "%s: The file might be partially compressed (errno=%d). Please delete the file.", |
|---|
| 4253 | + __func__, ret); |
|---|
| 4254 | +out: |
|---|
| 4255 | + inode_unlock(inode); |
|---|
| 4256 | + file_end_write(filp); |
|---|
| 4257 | + |
|---|
| 4258 | + return ret; |
|---|
| 4259 | +} |
|---|
| 4260 | + |
|---|
| 4261 | +static long __f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
|---|
| 4262 | +{ |
|---|
| 3805 | 4263 | switch (cmd) { |
|---|
| 3806 | | - case F2FS_IOC_GETFLAGS: |
|---|
| 4264 | + case FS_IOC_GETFLAGS: |
|---|
| 3807 | 4265 | return f2fs_ioc_getflags(filp, arg); |
|---|
| 3808 | | - case F2FS_IOC_SETFLAGS: |
|---|
| 4266 | + case FS_IOC_SETFLAGS: |
|---|
| 3809 | 4267 | return f2fs_ioc_setflags(filp, arg); |
|---|
| 3810 | | - case F2FS_IOC_GETVERSION: |
|---|
| 4268 | + case FS_IOC_GETVERSION: |
|---|
| 3811 | 4269 | return f2fs_ioc_getversion(filp, arg); |
|---|
| 3812 | 4270 | case F2FS_IOC_START_ATOMIC_WRITE: |
|---|
| 3813 | 4271 | return f2fs_ioc_start_atomic_write(filp); |
|---|
| .. | .. |
|---|
| 3823 | 4281 | return f2fs_ioc_shutdown(filp, arg); |
|---|
| 3824 | 4282 | case FITRIM: |
|---|
| 3825 | 4283 | return f2fs_ioc_fitrim(filp, arg); |
|---|
| 3826 | | - case F2FS_IOC_SET_ENCRYPTION_POLICY: |
|---|
| 4284 | + case FS_IOC_SET_ENCRYPTION_POLICY: |
|---|
| 3827 | 4285 | return f2fs_ioc_set_encryption_policy(filp, arg); |
|---|
| 3828 | | - case F2FS_IOC_GET_ENCRYPTION_POLICY: |
|---|
| 4286 | + case FS_IOC_GET_ENCRYPTION_POLICY: |
|---|
| 3829 | 4287 | return f2fs_ioc_get_encryption_policy(filp, arg); |
|---|
| 3830 | | - case F2FS_IOC_GET_ENCRYPTION_PWSALT: |
|---|
| 4288 | + case FS_IOC_GET_ENCRYPTION_PWSALT: |
|---|
| 3831 | 4289 | return f2fs_ioc_get_encryption_pwsalt(filp, arg); |
|---|
| 3832 | 4290 | case FS_IOC_GET_ENCRYPTION_POLICY_EX: |
|---|
| 3833 | 4291 | return f2fs_ioc_get_encryption_policy_ex(filp, arg); |
|---|
| .. | .. |
|---|
| 3855 | 4313 | return f2fs_ioc_flush_device(filp, arg); |
|---|
| 3856 | 4314 | case F2FS_IOC_GET_FEATURES: |
|---|
| 3857 | 4315 | return f2fs_ioc_get_features(filp, arg); |
|---|
| 3858 | | - case F2FS_IOC_FSGETXATTR: |
|---|
| 4316 | + case FS_IOC_FSGETXATTR: |
|---|
| 3859 | 4317 | return f2fs_ioc_fsgetxattr(filp, arg); |
|---|
| 3860 | | - case F2FS_IOC_FSSETXATTR: |
|---|
| 4318 | + case FS_IOC_FSSETXATTR: |
|---|
| 3861 | 4319 | return f2fs_ioc_fssetxattr(filp, arg); |
|---|
| 3862 | 4320 | case F2FS_IOC_GET_PIN_FILE: |
|---|
| 3863 | 4321 | return f2fs_ioc_get_pin_file(filp, arg); |
|---|
| .. | .. |
|---|
| 3871 | 4329 | return f2fs_ioc_enable_verity(filp, arg); |
|---|
| 3872 | 4330 | case FS_IOC_MEASURE_VERITY: |
|---|
| 3873 | 4331 | return f2fs_ioc_measure_verity(filp, arg); |
|---|
| 3874 | | - case F2FS_IOC_GET_VOLUME_NAME: |
|---|
| 3875 | | - return f2fs_get_volume_name(filp, arg); |
|---|
| 3876 | | - case F2FS_IOC_SET_VOLUME_NAME: |
|---|
| 3877 | | - return f2fs_set_volume_name(filp, arg); |
|---|
| 4332 | + case FS_IOC_READ_VERITY_METADATA: |
|---|
| 4333 | + return f2fs_ioc_read_verity_metadata(filp, arg); |
|---|
| 4334 | + case FS_IOC_GETFSLABEL: |
|---|
| 4335 | + return f2fs_ioc_getfslabel(filp, arg); |
|---|
| 4336 | + case FS_IOC_SETFSLABEL: |
|---|
| 4337 | + return f2fs_ioc_setfslabel(filp, arg); |
|---|
| 3878 | 4338 | case F2FS_IOC_GET_COMPRESS_BLOCKS: |
|---|
| 3879 | 4339 | return f2fs_get_compress_blocks(filp, arg); |
|---|
| 3880 | 4340 | case F2FS_IOC_RELEASE_COMPRESS_BLOCKS: |
|---|
| 3881 | 4341 | return f2fs_release_compress_blocks(filp, arg); |
|---|
| 3882 | 4342 | case F2FS_IOC_RESERVE_COMPRESS_BLOCKS: |
|---|
| 3883 | 4343 | return f2fs_reserve_compress_blocks(filp, arg); |
|---|
| 4344 | + case F2FS_IOC_SEC_TRIM_FILE: |
|---|
| 4345 | + return f2fs_sec_trim_file(filp, arg); |
|---|
| 4346 | + case F2FS_IOC_GET_COMPRESS_OPTION: |
|---|
| 4347 | + return f2fs_ioc_get_compress_option(filp, arg); |
|---|
| 4348 | + case F2FS_IOC_SET_COMPRESS_OPTION: |
|---|
| 4349 | + return f2fs_ioc_set_compress_option(filp, arg); |
|---|
| 4350 | + case F2FS_IOC_DECOMPRESS_FILE: |
|---|
| 4351 | + return f2fs_ioc_decompress_file(filp, arg); |
|---|
| 4352 | + case F2FS_IOC_COMPRESS_FILE: |
|---|
| 4353 | + return f2fs_ioc_compress_file(filp, arg); |
|---|
| 3884 | 4354 | default: |
|---|
| 3885 | 4355 | return -ENOTTY; |
|---|
| 3886 | 4356 | } |
|---|
| 4357 | +} |
|---|
| 4358 | + |
|---|
| 4359 | +long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
|---|
| 4360 | +{ |
|---|
| 4361 | + if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(filp))))) |
|---|
| 4362 | + return -EIO; |
|---|
| 4363 | + if (!f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(filp)))) |
|---|
| 4364 | + return -ENOSPC; |
|---|
| 4365 | + |
|---|
| 4366 | + return __f2fs_ioctl(filp, cmd, arg); |
|---|
| 3887 | 4367 | } |
|---|
| 3888 | 4368 | |
|---|
| 3889 | 4369 | static ssize_t f2fs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter) |
|---|
| .. | .. |
|---|
| 3926 | 4406 | } |
|---|
| 3927 | 4407 | } else { |
|---|
| 3928 | 4408 | inode_lock(inode); |
|---|
| 4409 | + } |
|---|
| 4410 | + |
|---|
| 4411 | + if (unlikely(IS_IMMUTABLE(inode))) { |
|---|
| 4412 | + ret = -EPERM; |
|---|
| 4413 | + goto unlock; |
|---|
| 4414 | + } |
|---|
| 4415 | + |
|---|
| 4416 | + if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED)) { |
|---|
| 4417 | + ret = -EPERM; |
|---|
| 4418 | + goto unlock; |
|---|
| 3929 | 4419 | } |
|---|
| 3930 | 4420 | |
|---|
| 3931 | 4421 | ret = generic_write_checks(iocb, from); |
|---|
| .. | .. |
|---|
| 3986 | 4476 | clear_inode_flag(inode, FI_NO_PREALLOC); |
|---|
| 3987 | 4477 | |
|---|
| 3988 | 4478 | /* if we couldn't write data, we should deallocate blocks. */ |
|---|
| 3989 | | - if (preallocated && i_size_read(inode) < target_size) |
|---|
| 4479 | + if (preallocated && i_size_read(inode) < target_size) { |
|---|
| 4480 | + f2fs_down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 4481 | + f2fs_down_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 3990 | 4482 | f2fs_truncate(inode); |
|---|
| 4483 | + f2fs_up_write(&F2FS_I(inode)->i_mmap_sem); |
|---|
| 4484 | + f2fs_up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); |
|---|
| 4485 | + } |
|---|
| 3991 | 4486 | |
|---|
| 3992 | 4487 | if (ret > 0) |
|---|
| 3993 | 4488 | f2fs_update_iostat(F2FS_I_SB(inode), APP_WRITE_IO, ret); |
|---|
| 3994 | 4489 | } |
|---|
| 4490 | +unlock: |
|---|
| 3995 | 4491 | inode_unlock(inode); |
|---|
| 3996 | 4492 | out: |
|---|
| 3997 | 4493 | trace_f2fs_file_write_iter(inode, iocb->ki_pos, |
|---|
| .. | .. |
|---|
| 4002 | 4498 | } |
|---|
| 4003 | 4499 | |
|---|
| 4004 | 4500 | #ifdef CONFIG_COMPAT |
|---|
| 4501 | +struct compat_f2fs_gc_range { |
|---|
| 4502 | + u32 sync; |
|---|
| 4503 | + compat_u64 start; |
|---|
| 4504 | + compat_u64 len; |
|---|
| 4505 | +}; |
|---|
| 4506 | +#define F2FS_IOC32_GARBAGE_COLLECT_RANGE _IOW(F2FS_IOCTL_MAGIC, 11,\ |
|---|
| 4507 | + struct compat_f2fs_gc_range) |
|---|
| 4508 | + |
|---|
| 4509 | +static int f2fs_compat_ioc_gc_range(struct file *file, unsigned long arg) |
|---|
| 4510 | +{ |
|---|
| 4511 | + struct compat_f2fs_gc_range __user *urange; |
|---|
| 4512 | + struct f2fs_gc_range range; |
|---|
| 4513 | + int err; |
|---|
| 4514 | + |
|---|
| 4515 | + urange = compat_ptr(arg); |
|---|
| 4516 | + err = get_user(range.sync, &urange->sync); |
|---|
| 4517 | + err |= get_user(range.start, &urange->start); |
|---|
| 4518 | + err |= get_user(range.len, &urange->len); |
|---|
| 4519 | + if (err) |
|---|
| 4520 | + return -EFAULT; |
|---|
| 4521 | + |
|---|
| 4522 | + return __f2fs_ioc_gc_range(file, &range); |
|---|
| 4523 | +} |
|---|
| 4524 | + |
|---|
| 4525 | +struct compat_f2fs_move_range { |
|---|
| 4526 | + u32 dst_fd; |
|---|
| 4527 | + compat_u64 pos_in; |
|---|
| 4528 | + compat_u64 pos_out; |
|---|
| 4529 | + compat_u64 len; |
|---|
| 4530 | +}; |
|---|
| 4531 | +#define F2FS_IOC32_MOVE_RANGE _IOWR(F2FS_IOCTL_MAGIC, 9, \ |
|---|
| 4532 | + struct compat_f2fs_move_range) |
|---|
| 4533 | + |
|---|
| 4534 | +static int f2fs_compat_ioc_move_range(struct file *file, unsigned long arg) |
|---|
| 4535 | +{ |
|---|
| 4536 | + struct compat_f2fs_move_range __user *urange; |
|---|
| 4537 | + struct f2fs_move_range range; |
|---|
| 4538 | + int err; |
|---|
| 4539 | + |
|---|
| 4540 | + urange = compat_ptr(arg); |
|---|
| 4541 | + err = get_user(range.dst_fd, &urange->dst_fd); |
|---|
| 4542 | + err |= get_user(range.pos_in, &urange->pos_in); |
|---|
| 4543 | + err |= get_user(range.pos_out, &urange->pos_out); |
|---|
| 4544 | + err |= get_user(range.len, &urange->len); |
|---|
| 4545 | + if (err) |
|---|
| 4546 | + return -EFAULT; |
|---|
| 4547 | + |
|---|
| 4548 | + return __f2fs_ioc_move_range(file, &range); |
|---|
| 4549 | +} |
|---|
| 4550 | + |
|---|
| 4005 | 4551 | long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
|---|
| 4006 | 4552 | { |
|---|
| 4553 | + if (unlikely(f2fs_cp_error(F2FS_I_SB(file_inode(file))))) |
|---|
| 4554 | + return -EIO; |
|---|
| 4555 | + if (!f2fs_is_checkpoint_ready(F2FS_I_SB(file_inode(file)))) |
|---|
| 4556 | + return -ENOSPC; |
|---|
| 4557 | + |
|---|
| 4007 | 4558 | switch (cmd) { |
|---|
| 4008 | | - case F2FS_IOC32_GETFLAGS: |
|---|
| 4009 | | - cmd = F2FS_IOC_GETFLAGS; |
|---|
| 4559 | + case FS_IOC32_GETFLAGS: |
|---|
| 4560 | + cmd = FS_IOC_GETFLAGS; |
|---|
| 4010 | 4561 | break; |
|---|
| 4011 | | - case F2FS_IOC32_SETFLAGS: |
|---|
| 4012 | | - cmd = F2FS_IOC_SETFLAGS; |
|---|
| 4562 | + case FS_IOC32_SETFLAGS: |
|---|
| 4563 | + cmd = FS_IOC_SETFLAGS; |
|---|
| 4013 | 4564 | break; |
|---|
| 4014 | | - case F2FS_IOC32_GETVERSION: |
|---|
| 4015 | | - cmd = F2FS_IOC_GETVERSION; |
|---|
| 4565 | + case FS_IOC32_GETVERSION: |
|---|
| 4566 | + cmd = FS_IOC_GETVERSION; |
|---|
| 4016 | 4567 | break; |
|---|
| 4568 | + case F2FS_IOC32_GARBAGE_COLLECT_RANGE: |
|---|
| 4569 | + return f2fs_compat_ioc_gc_range(file, arg); |
|---|
| 4570 | + case F2FS_IOC32_MOVE_RANGE: |
|---|
| 4571 | + return f2fs_compat_ioc_move_range(file, arg); |
|---|
| 4017 | 4572 | case F2FS_IOC_START_ATOMIC_WRITE: |
|---|
| 4018 | 4573 | case F2FS_IOC_COMMIT_ATOMIC_WRITE: |
|---|
| 4019 | 4574 | case F2FS_IOC_START_VOLATILE_WRITE: |
|---|
| 4020 | 4575 | case F2FS_IOC_RELEASE_VOLATILE_WRITE: |
|---|
| 4021 | 4576 | case F2FS_IOC_ABORT_VOLATILE_WRITE: |
|---|
| 4022 | 4577 | case F2FS_IOC_SHUTDOWN: |
|---|
| 4023 | | - case F2FS_IOC_SET_ENCRYPTION_POLICY: |
|---|
| 4024 | | - case F2FS_IOC_GET_ENCRYPTION_PWSALT: |
|---|
| 4025 | | - case F2FS_IOC_GET_ENCRYPTION_POLICY: |
|---|
| 4578 | + case FITRIM: |
|---|
| 4579 | + case FS_IOC_SET_ENCRYPTION_POLICY: |
|---|
| 4580 | + case FS_IOC_GET_ENCRYPTION_PWSALT: |
|---|
| 4581 | + case FS_IOC_GET_ENCRYPTION_POLICY: |
|---|
| 4026 | 4582 | case FS_IOC_GET_ENCRYPTION_POLICY_EX: |
|---|
| 4027 | 4583 | case FS_IOC_ADD_ENCRYPTION_KEY: |
|---|
| 4028 | 4584 | case FS_IOC_REMOVE_ENCRYPTION_KEY: |
|---|
| .. | .. |
|---|
| 4030 | 4586 | case FS_IOC_GET_ENCRYPTION_KEY_STATUS: |
|---|
| 4031 | 4587 | case FS_IOC_GET_ENCRYPTION_NONCE: |
|---|
| 4032 | 4588 | case F2FS_IOC_GARBAGE_COLLECT: |
|---|
| 4033 | | - case F2FS_IOC_GARBAGE_COLLECT_RANGE: |
|---|
| 4034 | 4589 | case F2FS_IOC_WRITE_CHECKPOINT: |
|---|
| 4035 | 4590 | case F2FS_IOC_DEFRAGMENT: |
|---|
| 4036 | | - case F2FS_IOC_MOVE_RANGE: |
|---|
| 4037 | 4591 | case F2FS_IOC_FLUSH_DEVICE: |
|---|
| 4038 | 4592 | case F2FS_IOC_GET_FEATURES: |
|---|
| 4039 | | - case F2FS_IOC_FSGETXATTR: |
|---|
| 4040 | | - case F2FS_IOC_FSSETXATTR: |
|---|
| 4593 | + case FS_IOC_FSGETXATTR: |
|---|
| 4594 | + case FS_IOC_FSSETXATTR: |
|---|
| 4041 | 4595 | case F2FS_IOC_GET_PIN_FILE: |
|---|
| 4042 | 4596 | case F2FS_IOC_SET_PIN_FILE: |
|---|
| 4043 | 4597 | case F2FS_IOC_PRECACHE_EXTENTS: |
|---|
| 4044 | 4598 | case F2FS_IOC_RESIZE_FS: |
|---|
| 4045 | 4599 | case FS_IOC_ENABLE_VERITY: |
|---|
| 4046 | 4600 | case FS_IOC_MEASURE_VERITY: |
|---|
| 4047 | | - case F2FS_IOC_GET_VOLUME_NAME: |
|---|
| 4048 | | - case F2FS_IOC_SET_VOLUME_NAME: |
|---|
| 4601 | + case FS_IOC_READ_VERITY_METADATA: |
|---|
| 4602 | + case FS_IOC_GETFSLABEL: |
|---|
| 4603 | + case FS_IOC_SETFSLABEL: |
|---|
| 4049 | 4604 | case F2FS_IOC_GET_COMPRESS_BLOCKS: |
|---|
| 4050 | 4605 | case F2FS_IOC_RELEASE_COMPRESS_BLOCKS: |
|---|
| 4051 | 4606 | case F2FS_IOC_RESERVE_COMPRESS_BLOCKS: |
|---|
| 4607 | + case F2FS_IOC_SEC_TRIM_FILE: |
|---|
| 4608 | + case F2FS_IOC_GET_COMPRESS_OPTION: |
|---|
| 4609 | + case F2FS_IOC_SET_COMPRESS_OPTION: |
|---|
| 4610 | + case F2FS_IOC_DECOMPRESS_FILE: |
|---|
| 4611 | + case F2FS_IOC_COMPRESS_FILE: |
|---|
| 4052 | 4612 | break; |
|---|
| 4053 | 4613 | default: |
|---|
| 4054 | 4614 | return -ENOIOCTLCMD; |
|---|
| 4055 | 4615 | } |
|---|
| 4056 | | - return f2fs_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); |
|---|
| 4616 | + return __f2fs_ioctl(file, cmd, (unsigned long) compat_ptr(arg)); |
|---|
| 4057 | 4617 | } |
|---|
| 4058 | 4618 | #endif |
|---|
| 4059 | 4619 | |
|---|