Lines Matching defs:inode
125 * - Update inode size for past EOF write
127 int btrfs_dirty_pages(struct btrfs_inode *inode, struct page **pages,
131 struct btrfs_fs_info *fs_info = inode->root->fs_info;
138 loff_t isize = i_size_read(&inode->vfs_inode);
158 clear_extent_bit(&inode->io_tree, start_pos, end_of_last_block,
162 err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block,
177 * the disk i_size. There is no need to log the inode
181 i_size_write(&inode->vfs_inode, end_pos);
194 * Note: the VFS' inode number of bytes is not updated, it's up to the caller
197 * caller can update the inode's number of bytes in an atomic way when
201 struct btrfs_root *root, struct btrfs_inode *inode,
210 u64 ino = btrfs_ino(inode);
242 btrfs_drop_extent_map_range(inode, args->start, args->end - 1, false);
244 if (args->start >= inode->disk_i_size && !args->replace_extent)
595 struct btrfs_inode *inode, u64 start, u64 end)
597 struct btrfs_root *root = inode->root;
615 u64 ino = btrfs_ino(inode);
843 static int prepare_uptodate_page(struct inode *inode,
864 * called to release the page. Here we check both inode
871 if (page->mapping != inode->i_mapping || !PagePrivate(page)) {
889 static gfp_t get_prepare_gfp_flags(struct inode *inode, bool nowait)
893 gfp = btrfs_alloc_write_mask(inode->i_mapping);
905 static noinline int prepare_pages(struct inode *inode, struct page **pages,
912 gfp_t mask = get_prepare_gfp_flags(inode, nowait);
919 pages[i] = pagecache_get_page(inode->i_mapping, index + i,
937 err = prepare_uptodate_page(inode, pages[i], pos,
940 err = prepare_uptodate_page(inode, pages[i],
976 lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages,
982 struct btrfs_fs_info *fs_info = inode->root->fs_info;
991 if (start_pos < inode->vfs_inode.i_size) {
995 if (!try_lock_extent(&inode->io_tree, start_pos, last_pos,
1006 lock_extent(&inode->io_tree, start_pos, last_pos, cached_state);
1009 ordered = btrfs_lookup_ordered_range(inode, start_pos,
1014 unlock_extent(&inode->io_tree, start_pos, last_pos,
1055 * -EAGAIN If we can't do a nocow write because snapshoting of the inode's
1061 int btrfs_check_nocow_lock(struct btrfs_inode *inode, loff_t pos,
1064 struct btrfs_fs_info *fs_info = inode->root->fs_info;
1065 struct btrfs_root *root = inode->root;
1071 if (!(inode->flags & (BTRFS_INODE_NODATACOW | BTRFS_INODE_PREALLOC)))
1083 if (!btrfs_try_lock_ordered_range(inode, lockstart, lockend,
1089 btrfs_lock_and_flush_ordered_range(inode, lockstart, lockend,
1092 ret = can_nocow_extent(&inode->vfs_inode, lockstart, &num_bytes,
1099 unlock_extent(&inode->io_tree, lockstart, lockend, &cached_state);
1104 void btrfs_check_nocow_unlock(struct btrfs_inode *inode)
1106 btrfs_drew_write_unlock(&inode->root->snapshot_lock);
1109 static void update_time_for_write(struct inode *inode)
1113 if (IS_NOCMTIME(inode))
1116 now = current_time(inode);
1117 if (!timespec64_equal(&inode->i_mtime, &now))
1118 inode->i_mtime = now;
1120 ctime = inode_get_ctime(inode);
1122 inode_set_ctime_to_ts(inode, now);
1124 if (IS_I_VERSION(inode))
1125 inode_inc_iversion(inode);
1132 struct inode *inode = file_inode(file);
1133 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
1146 !(BTRFS_I(inode)->flags & (BTRFS_INODE_NODATACOW | BTRFS_INODE_PREALLOC)))
1154 * We reserve space for updating the inode when we reserve space for the
1156 * need to start yet another transaction to update the inode as we will
1157 * update the inode when we finish writing whatever data we write.
1159 update_time_for_write(inode);
1162 oldsize = i_size_read(inode);
1167 ret = btrfs_cont_expand(BTRFS_I(inode), oldsize, end_pos);
1180 struct inode *inode = file_inode(file);
1181 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
1192 loff_t old_isize = i_size_read(inode);
1200 ret = btrfs_inode_lock(BTRFS_I(inode), ilock_flags);
1251 ret = btrfs_check_data_free_space(BTRFS_I(inode),
1267 can_nocow = btrfs_check_nocow_lock(BTRFS_I(inode), pos,
1283 ret = btrfs_delalloc_reserve_metadata(BTRFS_I(inode),
1288 btrfs_free_reserved_data_space(BTRFS_I(inode),
1292 btrfs_check_nocow_unlock(BTRFS_I(inode));
1301 ret = balance_dirty_pages_ratelimited_flags(inode->i_mapping, bdp_flags);
1303 btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes);
1312 ret = prepare_pages(inode, pages, num_pages,
1315 btrfs_delalloc_release_extents(BTRFS_I(inode),
1321 BTRFS_I(inode), pages,
1328 btrfs_delalloc_release_extents(BTRFS_I(inode),
1362 btrfs_delalloc_release_metadata(BTRFS_I(inode),
1370 btrfs_delalloc_release_space(BTRFS_I(inode),
1379 ret = btrfs_dirty_pages(BTRFS_I(inode), pages,
1391 unlock_extent(&BTRFS_I(inode)->io_tree, lockstart,
1396 btrfs_delalloc_release_extents(BTRFS_I(inode), reserve_bytes);
1404 btrfs_check_nocow_unlock(BTRFS_I(inode));
1418 btrfs_check_nocow_unlock(BTRFS_I(inode));
1419 btrfs_delalloc_release_metadata(BTRFS_I(inode),
1422 btrfs_delalloc_release_space(BTRFS_I(inode),
1431 pagecache_isize_extended(inode, old_isize, iocb->ki_pos);
1435 btrfs_inode_unlock(BTRFS_I(inode), ilock_flags);
1456 struct inode *inode = file_inode(file);
1457 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
1476 if (iocb->ki_pos + iov_iter_count(from) <= i_size_read(inode) && IS_NOSEC(inode))
1480 err = btrfs_inode_lock(BTRFS_I(inode), ilock_flags);
1485 if ((ilock_flags & BTRFS_ILOCK_SHARED) && !IS_NOSEC(inode)) {
1486 btrfs_inode_unlock(BTRFS_I(inode), ilock_flags);
1493 btrfs_inode_unlock(BTRFS_I(inode), ilock_flags);
1499 btrfs_inode_unlock(BTRFS_I(inode), ilock_flags);
1509 pos + iov_iter_count(from) > i_size_read(inode)) {
1510 btrfs_inode_unlock(BTRFS_I(inode), ilock_flags);
1516 btrfs_inode_unlock(BTRFS_I(inode), ilock_flags);
1544 * iocb, and that needs to lock the inode. So unlock it before calling
1547 btrfs_inode_unlock(BTRFS_I(inode), ilock_flags);
1563 * releasing and locking again the inode, to prevent races with
1613 err = btrfs_fdatawrite_range(inode, pos, endbyte);
1616 err = filemap_fdatawait_range(inode->i_mapping, pos, endbyte);
1631 struct inode *inode = file_inode(file);
1635 btrfs_inode_lock(BTRFS_I(inode), 0);
1654 btrfs_inode_unlock(BTRFS_I(inode), 0);
1662 struct btrfs_inode *inode = BTRFS_I(file_inode(file));
1670 if (BTRFS_FS_ERROR(inode->root->fs_info))
1687 btrfs_set_inode_last_sub_trans(inode);
1703 int btrfs_release_file(struct inode *inode, struct file *filp)
1721 &BTRFS_I(inode)->runtime_flags))
1722 filemap_flush(inode->i_mapping);
1726 static int start_ordered_ops(struct inode *inode, loff_t start, loff_t end)
1738 ret = btrfs_fdatawrite_range(inode, start, end);
1746 struct btrfs_inode *inode = BTRFS_I(ctx->inode);
1747 struct btrfs_fs_info *fs_info = inode->root->fs_info;
1749 if (btrfs_inode_in_log(inode, fs_info->generation) &&
1754 * If we are doing a fast fsync we can not bail out if the inode's
1756 * update the last_trans of the inode during ordered extent completion,
1760 if (inode->last_trans <= fs_info->last_trans_committed &&
1761 (test_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags) ||
1769 * fsync call for both files and directories. This logs the inode into
1775 * It drops the inode mutex before doing the tree log commit. This is an
1782 struct inode *inode = d_inode(dentry);
1783 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
1784 struct btrfs_root *root = BTRFS_I(inode)->root;
1793 btrfs_init_log_ctx(&ctx, inode);
1813 ret = start_ordered_ops(inode, start, end);
1817 btrfs_inode_lock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
1822 * Before we acquired the inode's lock and the mmap lock, someone may
1825 * the inode, because if it does, any of the following might happen when
1826 * we are not doing a full inode sync:
1839 ret = start_ordered_ops(inode, start, end);
1841 btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
1846 * Always check for the full sync flag while holding the inode's lock,
1854 &BTRFS_I(inode)->runtime_flags);
1872 ret = btrfs_wait_ordered_range(inode, start, len);
1879 btrfs_get_ordered_extents_for_logging(BTRFS_I(inode),
1881 ret = filemap_fdatawait_range(inode->i_mapping, start, end);
1897 &BTRFS_I(inode)->runtime_flags);
1900 * already with io errors, in which case the inode was not
1901 * updated and we end up here. So check the inode's mapping
1905 ret = filemap_check_wb_err(inode->i_mapping, file->f_wb_err);
1944 btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
1951 /* We successfully logged the inode, attempt to sync the log. */
1976 ret = btrfs_wait_ordered_range(inode, start, len);
2012 btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
2035 static int hole_mergeable(struct btrfs_inode *inode, struct extent_buffer *leaf,
2045 if (key.objectid != btrfs_ino(inode) ||
2065 struct btrfs_inode *inode,
2069 struct btrfs_root *root = inode->root;
2079 key.objectid = btrfs_ino(inode);
2095 if (hole_mergeable(inode, leaf, path->slots[0] - 1, offset, end)) {
2111 if (hole_mergeable(inode, leaf, path->slots[0], offset, end)) {
2129 ret = btrfs_insert_hole_extent(trans, root, btrfs_ino(inode), offset,
2139 btrfs_drop_extent_map_range(inode, offset, end - 1, false);
2140 btrfs_set_inode_full_sync(inode);
2153 ret = btrfs_replace_extent_map_range(inode, hole_em, true);
2156 btrfs_set_inode_full_sync(inode);
2163 * Find a hole extent on given inode and change start/len to the end of hole
2168 static int find_first_non_hole(struct btrfs_inode *inode, u64 *start, u64 *len)
2170 struct btrfs_fs_info *fs_info = inode->root->fs_info;
2174 em = btrfs_get_extent(inode, NULL, 0,
2191 static void btrfs_punch_hole_lock_range(struct inode *inode,
2208 truncate_pagecache_range(inode, lockstart, lockend);
2210 lock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend,
2214 * pages, because we have locked the inode's VFS lock in exclusive
2215 * mode, we have locked the inode's i_mmap_lock in exclusive mode,
2222 if (!filemap_range_has_page(inode->i_mapping, page_lockstart,
2226 unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend,
2230 btrfs_assert_inode_range_clean(BTRFS_I(inode), lockstart, lockend);
2234 struct btrfs_inode *inode,
2241 struct btrfs_root *root = inode->root;
2254 btrfs_update_inode_bytes(inode, 0, bytes_to_drop);
2258 key.objectid = btrfs_ino(inode);
2279 ret = btrfs_inode_set_file_extent_range(inode, extent_info->file_offset,
2286 btrfs_update_inode_bytes(inode, 0, bytes_to_drop);
2290 btrfs_update_inode_bytes(inode, replace_len, bytes_to_drop);
2297 btrfs_ino(inode),
2309 btrfs_ino(inode), ref_offset, 0, false);
2319 * The respective range must have been previously locked, as well as the inode.
2327 int btrfs_replace_file_extents(struct btrfs_inode *inode,
2334 struct btrfs_root *root = inode->root;
2337 u64 ino_size = round_up(inode->vfs_inode.i_size, fs_info->sectorsize);
2357 * 1 - update the inode
2386 ret = btrfs_drop_extents(trans, root, inode, &drop_args);
2387 /* If we are punching a hole decrement the inode's byte count */
2389 btrfs_update_inode_bytes(inode, 0,
2411 ret = fill_holes(trans, inode, path, cur_offset,
2430 ret = btrfs_inode_clear_file_extent_range(inode,
2449 ret = btrfs_insert_replace_extent(trans, inode, path,
2463 * dirty pages of the btree inode and flush delayed items, and
2467 * bump the inode's iversion and update mtime and ctime except
2473 inode_inc_iversion(&inode->vfs_inode);
2476 inode->vfs_inode.i_mtime = inode_set_ctime_current(&inode->vfs_inode);
2478 ret = btrfs_update_inode(trans, root, inode);
2501 ret = find_first_non_hole(inode, &cur_offset, &len);
2518 btrfs_set_inode_full_sync(inode);
2544 ret = fill_holes(trans, inode, path, cur_offset,
2553 ret = btrfs_inode_clear_file_extent_range(inode, cur_offset,
2562 ret = btrfs_insert_replace_extent(trans, inode, path,
2588 struct inode *inode = file_inode(file);
2589 struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
2590 struct btrfs_root *root = BTRFS_I(inode)->root;
2605 btrfs_inode_lock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
2607 ret = btrfs_wait_ordered_range(inode, offset, len);
2611 ino_size = round_up(inode->i_size, fs_info->sectorsize);
2612 ret = find_first_non_hole(BTRFS_I(inode), &offset, &len);
2640 ret = btrfs_truncate_block(BTRFS_I(inode), offset, len,
2651 ret = btrfs_truncate_block(BTRFS_I(inode), offset, 0, 0);
2653 btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
2666 ret = find_first_non_hole(BTRFS_I(inode), &offset, &len);
2680 ret = find_first_non_hole(BTRFS_I(inode), &tail_start, &tail_len);
2687 ret = btrfs_truncate_block(BTRFS_I(inode),
2701 btrfs_punch_hole_lock_range(inode, lockstart, lockend, &cached_state);
2709 ret = btrfs_replace_file_extents(BTRFS_I(inode), path, lockstart,
2716 inode_inc_iversion(inode);
2717 inode->i_mtime = inode_set_ctime_current(inode);
2718 ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
2723 unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend,
2729 * update the inode item, so that all the time fields are
2730 * updated as well as the necessary btrfs inode in memory fields
2731 * for detecting, at fsync time, if the inode isn't yet in the
2734 struct timespec64 now = inode_set_ctime_current(inode);
2736 inode_inc_iversion(inode);
2737 inode->i_mtime = now;
2744 ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
2750 btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
2792 static int btrfs_fallocate_update_isize(struct inode *inode,
2797 struct btrfs_root *root = BTRFS_I(inode)->root;
2801 if (mode & FALLOC_FL_KEEP_SIZE || end <= i_size_read(inode))
2808 inode_set_ctime_current(inode);
2809 i_size_write(inode, end);
2810 btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), 0);
2811 ret = btrfs_update_inode(trans, root, BTRFS_I(inode));
2823 static int btrfs_zero_range_check_range_boundary(struct btrfs_inode *inode,
2826 const u64 sectorsize = inode->root->fs_info->sectorsize;
2831 em = btrfs_get_extent(inode, NULL, 0, offset, sectorsize);
2846 static int btrfs_zero_range(struct inode *inode,
2851 struct btrfs_fs_info *fs_info = BTRFS_I(inode)->root->fs_info;
2862 em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, alloc_start,
2884 * do nothing except updating the inode's i_size if
2888 ret = btrfs_fallocate_update_isize(inode, offset + len,
2906 em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, alloc_start,
2915 ret = btrfs_fallocate_update_isize(inode, offset + len,
2921 ret = btrfs_truncate_block(BTRFS_I(inode), offset, len,
2924 ret = btrfs_fallocate_update_isize(inode,
2945 ret = btrfs_zero_range_check_range_boundary(BTRFS_I(inode),
2953 ret = btrfs_truncate_block(BTRFS_I(inode), offset, 0, 0);
2962 ret = btrfs_zero_range_check_range_boundary(BTRFS_I(inode),
2970 ret = btrfs_truncate_block(BTRFS_I(inode), offset + len,
2986 ret = btrfs_alloc_data_chunk_ondemand(BTRFS_I(inode),
2991 btrfs_punch_hole_lock_range(inode, lockstart, lockend,
2993 ret = btrfs_qgroup_reserve_data(BTRFS_I(inode), &data_reserved,
2996 unlock_extent(&BTRFS_I(inode)->io_tree, lockstart,
3000 ret = btrfs_prealloc_file_range(inode, mode, alloc_start,
3002 i_blocksize(inode),
3004 unlock_extent(&BTRFS_I(inode)->io_tree, lockstart, lockend,
3012 ret = btrfs_fallocate_update_isize(inode, offset + len, mode);
3015 btrfs_free_reserved_data_space(BTRFS_I(inode), data_reserved,
3025 struct inode *inode = file_inode(file);
3042 int blocksize = BTRFS_I(inode)->root->fs_info->sectorsize;
3046 if (btrfs_is_zoned(btrfs_sb(inode->i_sb)))
3061 btrfs_inode_lock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
3063 if (!(mode & FALLOC_FL_KEEP_SIZE) && offset + len > inode->i_size) {
3064 ret = inode_newsize_ok(inode, offset + len);
3080 if (alloc_start > inode->i_size) {
3081 ret = btrfs_cont_expand(BTRFS_I(inode), i_size_read(inode),
3085 } else if (offset + len > inode->i_size) {
3091 ret = btrfs_truncate_block(BTRFS_I(inode), inode->i_size, 0, 0);
3097 * We have locked the inode at the VFS level (in exclusive mode) and we
3104 ret = btrfs_wait_ordered_range(inode, alloc_start,
3110 ret = btrfs_zero_range(inode, offset, len, mode);
3111 btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
3116 lock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end,
3119 btrfs_assert_inode_range_clean(BTRFS_I(inode), alloc_start, locked_end);
3123 em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, cur_offset,
3133 (cur_offset >= inode->i_size &&
3142 ret = btrfs_qgroup_reserve_data(BTRFS_I(inode),
3160 ret = btrfs_alloc_data_chunk_ondemand(BTRFS_I(inode),
3172 ret = btrfs_prealloc_file_range(inode, mode,
3174 range->len, i_blocksize(inode),
3183 btrfs_free_reserved_data_space(BTRFS_I(inode),
3189 btrfs_qgroup_free_data(BTRFS_I(inode), data_reserved,
3201 * size of the file so we need to update i_size and the inode item.
3203 ret = btrfs_fallocate_update_isize(inode, actual_end, mode);
3205 unlock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end,
3208 btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_MMAP);
3219 static bool find_delalloc_subrange(struct btrfs_inode *inode, u64 start, u64 end,
3236 spin_lock(&inode->lock);
3237 if (inode->delalloc_bytes > 0) {
3238 spin_unlock(&inode->lock);
3240 delalloc_len = count_range_bits(&inode->io_tree,
3245 spin_unlock(&inode->lock);
3290 oe = btrfs_lookup_first_ordered_range(inode, start, len);
3326 * @inode: The inode.
3332 * searches in the inode's io_tree. Can be NULL.
3343 bool btrfs_find_delalloc_in_range(struct btrfs_inode *inode, u64 start, u64 end,
3347 u64 cur_offset = round_down(start, inode->root->fs_info->sectorsize);
3357 delalloc = find_delalloc_subrange(inode, cur_offset, end,
3387 * prealloc extent) found in the inode's subvolume btree.
3389 * @inode: The inode.
3403 static bool find_desired_extent_in_hole(struct btrfs_inode *inode, int whence,
3411 delalloc = btrfs_find_delalloc_in_range(inode, start, end, cached_state,
3456 struct btrfs_inode *inode = BTRFS_I(file->f_mapping->host);
3458 struct btrfs_fs_info *fs_info = inode->root->fs_info;
3461 const loff_t i_size = i_size_read(&inode->vfs_inode);
3462 const u64 ino = btrfs_ino(inode);
3463 struct btrfs_root *root = inode->root;
3477 * Quick path. If the inode has no prealloc extents and its number of
3481 !(inode->flags & BTRFS_INODE_PREALLOC) &&
3482 inode_get_bytes(&inode->vfs_inode) == i_size)
3524 lock_extent(&inode->io_tree, lockstart, lockend, &cached_state);
3578 found = find_desired_extent_in_hole(inode, whence,
3619 found = find_desired_extent_in_hole(inode, whence,
3662 found = find_desired_extent_in_hole(inode, whence,
3670 unlock_extent(&inode->io_tree, lockstart, lockend, &cached_state);
3684 struct inode *inode = file->f_mapping->host;
3691 btrfs_inode_lock(BTRFS_I(inode), BTRFS_ILOCK_SHARED);
3693 btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_SHARED);
3700 return vfs_setpos(file, offset, inode->i_sb->s_maxbytes);
3703 static int btrfs_file_open(struct inode *inode, struct file *filp)
3710 ret = fsverity_file_open(inode, filp);
3713 return generic_file_open(inode, filp);
3743 struct inode *inode = file_inode(iocb->ki_filp);
3748 if (fsverity_active(inode))
3751 if (check_direct_read(btrfs_sb(inode->i_sb), to, iocb->ki_pos))
3754 btrfs_inode_lock(BTRFS_I(inode), BTRFS_ILOCK_SHARED);
3765 * to lock the extent range in the inode's tree during he page reads
3803 btrfs_inode_unlock(BTRFS_I(inode), BTRFS_ILOCK_SHARED);
3840 int btrfs_fdatawrite_range(struct inode *inode, loff_t start, loff_t end)
3858 ret = filemap_fdatawrite_range(inode->i_mapping, start, end);
3860 &BTRFS_I(inode)->runtime_flags))
3861 ret = filemap_fdatawrite_range(inode->i_mapping, start, end);