Lines Matching refs:inode
52 static __u32 ext4_inode_csum(struct inode *inode, struct ext4_inode *raw, in ext4_inode_csum() argument
55 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_inode_csum()
67 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { in ext4_inode_csum()
78 EXT4_INODE_SIZE(inode->i_sb) - offset); in ext4_inode_csum()
84 static int ext4_inode_csum_verify(struct inode *inode, struct ext4_inode *raw, in ext4_inode_csum_verify() argument
89 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != in ext4_inode_csum_verify()
91 !ext4_has_metadata_csum(inode->i_sb)) in ext4_inode_csum_verify()
95 calculated = ext4_inode_csum(inode, raw, ei); in ext4_inode_csum_verify()
96 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE && in ext4_inode_csum_verify()
105 void ext4_inode_csum_set(struct inode *inode, struct ext4_inode *raw, in ext4_inode_csum_set() argument
110 if (EXT4_SB(inode->i_sb)->s_es->s_creator_os != in ext4_inode_csum_set()
112 !ext4_has_metadata_csum(inode->i_sb)) in ext4_inode_csum_set()
115 csum = ext4_inode_csum(inode, raw, ei); in ext4_inode_csum_set()
117 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE && in ext4_inode_csum_set()
122 static inline int ext4_begin_ordered_truncate(struct inode *inode, in ext4_begin_ordered_truncate() argument
125 trace_ext4_begin_ordered_truncate(inode, new_size); in ext4_begin_ordered_truncate()
132 if (!EXT4_I(inode)->jinode) in ext4_begin_ordered_truncate()
134 return jbd2_journal_begin_ordered_truncate(EXT4_JOURNAL(inode), in ext4_begin_ordered_truncate()
135 EXT4_I(inode)->jinode, in ext4_begin_ordered_truncate()
139 static int ext4_meta_trans_blocks(struct inode *inode, int lblocks,
146 int ext4_inode_is_fast_symlink(struct inode *inode) in ext4_inode_is_fast_symlink() argument
148 if (!(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) { in ext4_inode_is_fast_symlink()
149 int ea_blocks = EXT4_I(inode)->i_file_acl ? in ext4_inode_is_fast_symlink()
150 EXT4_CLUSTER_SIZE(inode->i_sb) >> 9 : 0; in ext4_inode_is_fast_symlink()
152 if (ext4_has_inline_data(inode)) in ext4_inode_is_fast_symlink()
155 return (S_ISLNK(inode->i_mode) && inode->i_blocks - ea_blocks == 0); in ext4_inode_is_fast_symlink()
157 return S_ISLNK(inode->i_mode) && inode->i_size && in ext4_inode_is_fast_symlink()
158 (inode->i_size < EXT4_N_BLOCKS * 4); in ext4_inode_is_fast_symlink()
164 void ext4_evict_inode(struct inode *inode) in ext4_evict_inode() argument
177 trace_ext4_evict_inode(inode); in ext4_evict_inode()
179 if (EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL) in ext4_evict_inode()
180 ext4_evict_ea_inode(inode); in ext4_evict_inode()
181 if (inode->i_nlink) { in ext4_evict_inode()
182 truncate_inode_pages_final(&inode->i_data); in ext4_evict_inode()
187 if (is_bad_inode(inode)) in ext4_evict_inode()
189 dquot_initialize(inode); in ext4_evict_inode()
191 if (ext4_should_order_data(inode)) in ext4_evict_inode()
192 ext4_begin_ordered_truncate(inode, 0); in ext4_evict_inode()
193 truncate_inode_pages_final(&inode->i_data); in ext4_evict_inode()
202 if (!list_empty_careful(&inode->i_io_list)) in ext4_evict_inode()
203 inode_io_list_del(inode); in ext4_evict_inode()
212 sb_start_intwrite(inode->i_sb); in ext4_evict_inode()
216 if (!IS_NOQUOTA(inode)) in ext4_evict_inode()
217 extra_credits += EXT4_MAXQUOTAS_DEL_BLOCKS(inode->i_sb); in ext4_evict_inode()
223 handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, in ext4_evict_inode()
224 ext4_blocks_for_truncate(inode) + extra_credits - 3); in ext4_evict_inode()
226 ext4_std_error(inode->i_sb, PTR_ERR(handle)); in ext4_evict_inode()
232 ext4_orphan_del(NULL, inode); in ext4_evict_inode()
234 sb_end_intwrite(inode->i_sb); in ext4_evict_inode()
238 if (IS_SYNC(inode)) in ext4_evict_inode()
248 if (ext4_inode_is_fast_symlink(inode)) in ext4_evict_inode()
249 memset(EXT4_I(inode)->i_data, 0, sizeof(EXT4_I(inode)->i_data)); in ext4_evict_inode()
250 inode->i_size = 0; in ext4_evict_inode()
251 err = ext4_mark_inode_dirty(handle, inode); in ext4_evict_inode()
253 ext4_warning(inode->i_sb, in ext4_evict_inode()
257 if (inode->i_blocks) { in ext4_evict_inode()
258 err = ext4_truncate(inode); in ext4_evict_inode()
260 ext4_error_err(inode->i_sb, -err, in ext4_evict_inode()
262 inode->i_ino, err); in ext4_evict_inode()
268 err = ext4_xattr_delete_inode(handle, inode, &ea_inode_array, in ext4_evict_inode()
271 ext4_warning(inode->i_sb, "xattr delete (err %d)", err); in ext4_evict_inode()
274 ext4_orphan_del(NULL, inode); in ext4_evict_inode()
276 sb_end_intwrite(inode->i_sb); in ext4_evict_inode()
289 ext4_orphan_del(handle, inode); in ext4_evict_inode()
290 EXT4_I(inode)->i_dtime = (__u32)ktime_get_real_seconds(); in ext4_evict_inode()
299 if (ext4_mark_inode_dirty(handle, inode)) in ext4_evict_inode()
301 ext4_clear_inode(inode); in ext4_evict_inode()
303 ext4_free_inode(handle, inode); in ext4_evict_inode()
306 sb_end_intwrite(inode->i_sb); in ext4_evict_inode()
314 WARN_ON_ONCE(!list_empty_careful(&inode->i_io_list)); in ext4_evict_inode()
316 if (!list_empty(&EXT4_I(inode)->i_fc_list)) in ext4_evict_inode()
317 ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_NOMEM, NULL); in ext4_evict_inode()
318 ext4_clear_inode(inode); /* We must guarantee clearing of inode... */ in ext4_evict_inode()
322 qsize_t *ext4_get_reserved_space(struct inode *inode) in ext4_get_reserved_space() argument
324 return &EXT4_I(inode)->i_reserved_quota; in ext4_get_reserved_space()
332 void ext4_da_update_reserve_space(struct inode *inode, in ext4_da_update_reserve_space() argument
335 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_da_update_reserve_space()
336 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_da_update_reserve_space()
339 trace_ext4_da_update_reserve_space(inode, used, quota_claim); in ext4_da_update_reserve_space()
341 ext4_warning(inode->i_sb, "%s: ino %lu, used %d " in ext4_da_update_reserve_space()
343 __func__, inode->i_ino, used, in ext4_da_update_reserve_space()
357 dquot_claim_block(inode, EXT4_C2B(sbi, used)); in ext4_da_update_reserve_space()
364 dquot_release_reservation_block(inode, EXT4_C2B(sbi, used)); in ext4_da_update_reserve_space()
373 !inode_is_open_for_write(inode)) in ext4_da_update_reserve_space()
374 ext4_discard_preallocations(inode, 0); in ext4_da_update_reserve_space()
377 static int __check_block_validity(struct inode *inode, const char *func, in __check_block_validity() argument
381 if (ext4_has_feature_journal(inode->i_sb) && in __check_block_validity()
382 (inode->i_ino == in __check_block_validity()
383 le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_journal_inum))) in __check_block_validity()
385 if (!ext4_inode_block_valid(inode, map->m_pblk, map->m_len)) { in __check_block_validity()
386 ext4_error_inode(inode, func, line, map->m_pblk, in __check_block_validity()
395 int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk, in ext4_issue_zeroout() argument
400 if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode)) in ext4_issue_zeroout()
401 return fscrypt_zeroout_range(inode, lblk, pblk, len); in ext4_issue_zeroout()
403 ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS); in ext4_issue_zeroout()
410 #define check_block_validity(inode, map) \ argument
411 __check_block_validity((inode), __func__, __LINE__, (map))
415 struct inode *inode, in ext4_map_blocks_es_recheck() argument
430 down_read(&EXT4_I(inode)->i_data_sem); in ext4_map_blocks_es_recheck()
431 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { in ext4_map_blocks_es_recheck()
432 retval = ext4_ext_map_blocks(handle, inode, map, 0); in ext4_map_blocks_es_recheck()
434 retval = ext4_ind_map_blocks(handle, inode, map, 0); in ext4_map_blocks_es_recheck()
436 up_read((&EXT4_I(inode)->i_data_sem)); in ext4_map_blocks_es_recheck()
448 inode->i_ino, es_map->m_lblk, es_map->m_len, in ext4_map_blocks_es_recheck()
456 static int ext4_map_query_blocks(handle_t *handle, struct inode *inode, in ext4_map_query_blocks() argument
462 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_map_query_blocks()
463 retval = ext4_ext_map_blocks(handle, inode, map, 0); in ext4_map_query_blocks()
465 retval = ext4_ind_map_blocks(handle, inode, map, 0); in ext4_map_query_blocks()
471 ext4_warning(inode->i_sb, in ext4_map_query_blocks()
474 inode->i_ino, retval, map->m_len); in ext4_map_query_blocks()
480 ext4_es_insert_extent(inode, map->m_lblk, map->m_len, in ext4_map_query_blocks()
507 int ext4_map_blocks(handle_t *handle, struct inode *inode, in ext4_map_blocks() argument
520 ext_debug(inode, "flag 0x%x, max_blocks %u, logical block %lu\n", in ext4_map_blocks()
534 if (!(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) && in ext4_map_blocks()
535 ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { in ext4_map_blocks()
559 ext4_map_blocks_es_recheck(handle, inode, map, in ext4_map_blocks()
575 down_read(&EXT4_I(inode)->i_data_sem); in ext4_map_blocks()
576 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { in ext4_map_blocks()
577 retval = ext4_ext_map_blocks(handle, inode, map, 0); in ext4_map_blocks()
579 retval = ext4_ind_map_blocks(handle, inode, map, 0); in ext4_map_blocks()
585 ext4_warning(inode->i_sb, in ext4_map_blocks()
588 inode->i_ino, retval, map->m_len); in ext4_map_blocks()
596 ext4_es_scan_range(inode, &ext4_es_is_delayed, map->m_lblk, in ext4_map_blocks()
599 ext4_es_insert_extent(inode, map->m_lblk, map->m_len, in ext4_map_blocks()
602 up_read((&EXT4_I(inode)->i_data_sem)); in ext4_map_blocks()
606 ret = check_block_validity(inode, map); in ext4_map_blocks()
643 down_write(&EXT4_I(inode)->i_data_sem); in ext4_map_blocks()
649 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { in ext4_map_blocks()
650 retval = ext4_ext_map_blocks(handle, inode, map, flags); in ext4_map_blocks()
652 retval = ext4_ind_map_blocks(handle, inode, map, flags); in ext4_map_blocks()
660 ext4_clear_inode_state(inode, EXT4_STATE_EXT_MIGRATE); in ext4_map_blocks()
668 ext4_warning(inode->i_sb, in ext4_map_blocks()
671 inode->i_ino, retval, map->m_len); in ext4_map_blocks()
685 ret = ext4_issue_zeroout(inode, map->m_lblk, in ext4_map_blocks()
698 ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { in ext4_map_blocks()
706 ext4_es_scan_range(inode, &ext4_es_is_delayed, map->m_lblk, in ext4_map_blocks()
709 ext4_es_insert_extent(inode, map->m_lblk, map->m_len, in ext4_map_blocks()
714 up_write((&EXT4_I(inode)->i_data_sem)); in ext4_map_blocks()
716 ret = check_block_validity(inode, map); in ext4_map_blocks()
728 !ext4_is_quota_file(inode) && in ext4_map_blocks()
729 ext4_should_order_data(inode)) { in ext4_map_blocks()
731 (loff_t)map->m_lblk << inode->i_blkbits; in ext4_map_blocks()
732 loff_t length = (loff_t)map->m_len << inode->i_blkbits; in ext4_map_blocks()
735 ret = ext4_jbd2_inode_add_wait(handle, inode, in ext4_map_blocks()
738 ret = ext4_jbd2_inode_add_write(handle, inode, in ext4_map_blocks()
746 ext4_fc_track_range(handle, inode, map->m_lblk, in ext4_map_blocks()
749 ext_debug(inode, "failed with err %d\n", retval); in ext4_map_blocks()
780 static int _ext4_get_block(struct inode *inode, sector_t iblock, in _ext4_get_block() argument
786 if (ext4_has_inline_data(inode)) in _ext4_get_block()
790 map.m_len = bh->b_size >> inode->i_blkbits; in _ext4_get_block()
792 ret = ext4_map_blocks(ext4_journal_current_handle(), inode, &map, in _ext4_get_block()
795 map_bh(bh, inode->i_sb, map.m_pblk); in _ext4_get_block()
797 bh->b_size = inode->i_sb->s_blocksize * map.m_len; in _ext4_get_block()
801 bh->b_size = inode->i_sb->s_blocksize * map.m_len; in _ext4_get_block()
806 int ext4_get_block(struct inode *inode, sector_t iblock, in ext4_get_block() argument
809 return _ext4_get_block(inode, iblock, bh, in ext4_get_block()
818 int ext4_get_block_unwritten(struct inode *inode, sector_t iblock, in ext4_get_block_unwritten() argument
824 inode->i_ino, create); in ext4_get_block_unwritten()
825 ret = _ext4_get_block(inode, iblock, bh_result, in ext4_get_block_unwritten()
845 struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, in ext4_getblk() argument
854 ASSERT((EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) in ext4_getblk()
860 err = ext4_map_blocks(handle, inode, &map, map_flags); in ext4_getblk()
868 return sb_find_get_block(inode->i_sb, map.m_pblk); in ext4_getblk()
870 bh = sb_getblk(inode->i_sb, map.m_pblk); in ext4_getblk()
875 ASSERT((EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) in ext4_getblk()
887 err = ext4_journal_get_create_access(handle, inode->i_sb, bh, in ext4_getblk()
894 memset(bh->b_data, 0, inode->i_sb->s_blocksize); in ext4_getblk()
899 err = ext4_handle_dirty_metadata(handle, inode, bh); in ext4_getblk()
910 struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode, in ext4_bread() argument
916 bh = ext4_getblk(handle, inode, block, map_flags); in ext4_bread()
931 int ext4_bread_batch(struct inode *inode, ext4_lblk_t block, int bh_count, in ext4_bread_batch() argument
937 bhs[i] = ext4_getblk(NULL, inode, block + i, 0 /* map_flags */); in ext4_bread_batch()
973 int ext4_walk_page_buffers(handle_t *handle, struct inode *inode, in ext4_walk_page_buffers() argument
978 int (*fn)(handle_t *handle, struct inode *inode, in ext4_walk_page_buffers()
997 err = (*fn)(handle, inode, bh); in ext4_walk_page_buffers()
1016 int do_journal_get_write_access(handle_t *handle, struct inode *inode, in do_journal_get_write_access() argument
1035 ret = ext4_journal_get_write_access(handle, inode->i_sb, bh, in do_journal_get_write_access()
1048 struct inode *inode = folio->mapping->host; in ext4_block_write_begin() local
1052 unsigned blocksize = inode->i_sb->s_blocksize; in ext4_block_write_begin()
1084 err = get_block(inode, block, bh, 1); in ext4_block_write_begin()
1122 } else if (fscrypt_inode_uses_fs_layer_crypto(inode)) { in ext4_block_write_begin()
1150 struct inode *inode = mapping->host; in ext4_write_begin() local
1158 if (unlikely(ext4_forced_shutdown(inode->i_sb))) in ext4_write_begin()
1161 trace_ext4_write_begin(inode, pos, len); in ext4_write_begin()
1166 needed_blocks = ext4_writepage_trans_blocks(inode) + 1; in ext4_write_begin()
1171 if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { in ext4_write_begin()
1172 ret = ext4_try_to_write_inline_data(mapping, inode, pos, len, in ext4_write_begin()
1197 create_empty_buffers(&folio->page, inode->i_sb->s_blocksize, 0); in ext4_write_begin()
1202 handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks); in ext4_write_begin()
1220 if (ext4_should_dioread_nolock(inode)) in ext4_write_begin()
1226 if (ext4_should_dioread_nolock(inode)) in ext4_write_begin()
1232 if (!ret && ext4_should_journal_data(inode)) { in ext4_write_begin()
1233 ret = ext4_walk_page_buffers(handle, inode, in ext4_write_begin()
1239 bool extended = (pos + len > inode->i_size) && in ext4_write_begin()
1240 !ext4_verity_in_progress(inode); in ext4_write_begin()
1251 if (extended && ext4_can_truncate(inode)) in ext4_write_begin()
1252 ext4_orphan_add(handle, inode); in ext4_write_begin()
1256 ext4_truncate_failed_write(inode); in ext4_write_begin()
1263 if (inode->i_nlink) in ext4_write_begin()
1264 ext4_orphan_del(NULL, inode); in ext4_write_begin()
1268 ext4_should_retry_alloc(inode->i_sb, &retries)) in ext4_write_begin()
1278 static int write_end_fn(handle_t *handle, struct inode *inode, in write_end_fn() argument
1305 struct inode *inode = mapping->host; in ext4_write_end() local
1306 loff_t old_size = inode->i_size; in ext4_write_end()
1309 bool verity = ext4_verity_in_progress(inode); in ext4_write_end()
1311 trace_ext4_write_end(inode, pos, len, copied); in ext4_write_end()
1313 if (ext4_has_inline_data(inode) && in ext4_write_end()
1314 ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) in ext4_write_end()
1315 return ext4_write_inline_data_end(inode, pos, len, copied, in ext4_write_end()
1327 i_size_changed = ext4_update_inode_size(inode, pos + copied); in ext4_write_end()
1332 pagecache_isize_extended(inode, old_size, pos); in ext4_write_end()
1340 ret = ext4_mark_inode_dirty(handle, inode); in ext4_write_end()
1342 if (pos + len > inode->i_size && !verity && ext4_can_truncate(inode)) in ext4_write_end()
1347 ext4_orphan_add(handle, inode); in ext4_write_end()
1353 if (pos + len > inode->i_size && !verity) { in ext4_write_end()
1354 ext4_truncate_failed_write(inode); in ext4_write_end()
1360 if (inode->i_nlink) in ext4_write_end()
1361 ext4_orphan_del(NULL, inode); in ext4_write_end()
1373 struct inode *inode, in ext4_journalled_zero_new_buffers() argument
1392 write_end_fn(handle, inode, bh); in ext4_journalled_zero_new_buffers()
1409 struct inode *inode = mapping->host; in ext4_journalled_write_end() local
1410 loff_t old_size = inode->i_size; in ext4_journalled_write_end()
1415 bool verity = ext4_verity_in_progress(inode); in ext4_journalled_write_end()
1417 trace_ext4_journalled_write_end(inode, pos, len, copied); in ext4_journalled_write_end()
1423 if (ext4_has_inline_data(inode)) in ext4_journalled_write_end()
1424 return ext4_write_inline_data_end(inode, pos, len, copied, in ext4_journalled_write_end()
1429 ext4_journalled_zero_new_buffers(handle, inode, folio, in ext4_journalled_write_end()
1433 ext4_journalled_zero_new_buffers(handle, inode, folio, in ext4_journalled_write_end()
1435 ret = ext4_walk_page_buffers(handle, inode, in ext4_journalled_write_end()
1443 size_changed = ext4_update_inode_size(inode, pos + copied); in ext4_journalled_write_end()
1444 EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid; in ext4_journalled_write_end()
1449 pagecache_isize_extended(inode, old_size, pos); in ext4_journalled_write_end()
1452 ret2 = ext4_mark_inode_dirty(handle, inode); in ext4_journalled_write_end()
1457 if (pos + len > inode->i_size && !verity && ext4_can_truncate(inode)) in ext4_journalled_write_end()
1462 ext4_orphan_add(handle, inode); in ext4_journalled_write_end()
1467 if (pos + len > inode->i_size && !verity) { in ext4_journalled_write_end()
1468 ext4_truncate_failed_write(inode); in ext4_journalled_write_end()
1474 if (inode->i_nlink) in ext4_journalled_write_end()
1475 ext4_orphan_del(NULL, inode); in ext4_journalled_write_end()
1484 static int ext4_da_reserve_space(struct inode *inode) in ext4_da_reserve_space() argument
1486 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_da_reserve_space()
1487 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_da_reserve_space()
1495 ret = dquot_reserve_block(inode, EXT4_C2B(sbi, 1)); in ext4_da_reserve_space()
1502 dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1)); in ext4_da_reserve_space()
1506 trace_ext4_da_reserve_space(inode); in ext4_da_reserve_space()
1512 void ext4_da_release_space(struct inode *inode, int to_free) in ext4_da_release_space() argument
1514 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_da_release_space()
1515 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_da_release_space()
1520 spin_lock(&EXT4_I(inode)->i_block_reservation_lock); in ext4_da_release_space()
1522 trace_ext4_da_release_space(inode, to_free); in ext4_da_release_space()
1530 ext4_warning(inode->i_sb, "ext4_da_release_space: " in ext4_da_release_space()
1532 "data blocks", inode->i_ino, to_free, in ext4_da_release_space()
1542 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); in ext4_da_release_space()
1544 dquot_release_reservation_block(inode, EXT4_C2B(sbi, to_free)); in ext4_da_release_space()
1553 struct inode *inode; member
1579 struct inode *inode = mpd->inode; in mpage_release_unused_pages() local
1580 struct address_space *mapping = inode->i_mapping; in mpage_release_unused_pages()
1591 start = index << (PAGE_SHIFT - inode->i_blkbits); in mpage_release_unused_pages()
1592 last = end << (PAGE_SHIFT - inode->i_blkbits); in mpage_release_unused_pages()
1598 down_write(&EXT4_I(inode)->i_data_sem); in mpage_release_unused_pages()
1599 ext4_es_remove_extent(inode, start, last - start + 1); in mpage_release_unused_pages()
1600 up_write(&EXT4_I(inode)->i_data_sem); in mpage_release_unused_pages()
1630 static void ext4_print_free_blocks(struct inode *inode) in ext4_print_free_blocks() argument
1632 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_print_free_blocks()
1633 struct super_block *sb = inode->i_sb; in ext4_print_free_blocks()
1634 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_print_free_blocks()
1637 EXT4_C2B(EXT4_SB(inode->i_sb), in ext4_print_free_blocks()
1663 static int ext4_insert_delayed_block(struct inode *inode, ext4_lblk_t lblk) in ext4_insert_delayed_block() argument
1665 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_insert_delayed_block()
1681 ret = ext4_da_reserve_space(inode); in ext4_insert_delayed_block()
1685 if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) { in ext4_insert_delayed_block()
1686 if (!ext4_es_scan_clu(inode, in ext4_insert_delayed_block()
1688 ret = ext4_clu_mapped(inode, in ext4_insert_delayed_block()
1693 ret = ext4_da_reserve_space(inode); in ext4_insert_delayed_block()
1705 ext4_es_insert_delayed_block(inode, lblk, allocated); in ext4_insert_delayed_block()
1715 static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, in ext4_da_map_blocks() argument
1728 if (invalid_block < ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es)) in ext4_da_map_blocks()
1732 ext_debug(inode, "max_blocks %u, logical block %lu\n", map->m_len, in ext4_da_map_blocks()
1736 if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { in ext4_da_map_blocks()
1746 map_bh(bh, inode->i_sb, invalid_block); in ext4_da_map_blocks()
1765 ext4_map_blocks_es_recheck(NULL, inode, map, &orig_map, 0); in ext4_da_map_blocks()
1774 down_read(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1775 if (ext4_has_inline_data(inode)) in ext4_da_map_blocks()
1778 retval = ext4_map_query_blocks(NULL, inode, map); in ext4_da_map_blocks()
1779 up_read(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1784 down_write(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1792 if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { in ext4_da_map_blocks()
1794 up_write(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1797 } else if (!ext4_has_inline_data(inode)) { in ext4_da_map_blocks()
1798 retval = ext4_map_query_blocks(NULL, inode, map); in ext4_da_map_blocks()
1800 up_write(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1805 retval = ext4_insert_delayed_block(inode, map->m_lblk); in ext4_da_map_blocks()
1806 up_write(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1810 map_bh(bh, inode->i_sb, invalid_block); in ext4_da_map_blocks()
1828 int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, in ext4_da_get_block_prep() argument
1835 BUG_ON(bh->b_size != inode->i_sb->s_blocksize); in ext4_da_get_block_prep()
1845 ret = ext4_da_map_blocks(inode, iblock, &map, bh); in ext4_da_get_block_prep()
1849 map_bh(bh, inode->i_sb, map.m_pblk); in ext4_da_get_block_prep()
1892 size = i_size_read(mpd->inode); in mpage_submit_folio()
1895 !ext4_verity_in_progress(mpd->inode)) in mpage_submit_folio()
1986 struct inode *inode = mpd->inode; in mpage_process_page_bufs() local
1988 ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) in mpage_process_page_bufs()
1989 >> inode->i_blkbits; in mpage_process_page_bufs()
1991 if (ext4_verity_in_progress(inode)) in mpage_process_page_bufs()
2047 int blkbits = mpd->inode->i_blkbits; in mpage_process_folio()
2112 struct inode *inode = mpd->inode; in mpage_map_and_submit_buffers() local
2113 int bpp_bits = PAGE_SHIFT - inode->i_blkbits; in mpage_map_and_submit_buffers()
2127 nr = filemap_get_folios(inode->i_mapping, &start, end, &fbatch); in mpage_map_and_submit_buffers()
2161 struct inode *inode = mpd->inode; in mpage_map_one_extent() local
2166 trace_ext4_da_write_pages_extent(inode, map); in mpage_map_one_extent()
2185 dioread_nolock = ext4_should_dioread_nolock(inode); in mpage_map_one_extent()
2191 err = ext4_map_blocks(handle, inode, map, get_blocks_flags); in mpage_map_one_extent()
2200 ext4_set_io_unwritten_flag(inode, mpd->io_submit.io_end); in mpage_map_one_extent()
2231 struct inode *inode = mpd->inode; in mpage_map_and_submit_extent() local
2242 io_end_vec->offset = ((loff_t)map->m_lblk) << inode->i_blkbits; in mpage_map_and_submit_extent()
2246 struct super_block *sb = inode->i_sb; in mpage_map_and_submit_extent()
2265 inode->i_ino, in mpage_map_and_submit_extent()
2272 ext4_print_free_blocks(inode); in mpage_map_and_submit_extent()
2293 if (disksize > READ_ONCE(EXT4_I(inode)->i_disksize)) { in mpage_map_and_submit_extent()
2297 down_write(&EXT4_I(inode)->i_data_sem); in mpage_map_and_submit_extent()
2298 i_size = i_size_read(inode); in mpage_map_and_submit_extent()
2301 if (disksize > EXT4_I(inode)->i_disksize) in mpage_map_and_submit_extent()
2302 EXT4_I(inode)->i_disksize = disksize; in mpage_map_and_submit_extent()
2303 up_write(&EXT4_I(inode)->i_data_sem); in mpage_map_and_submit_extent()
2304 err2 = ext4_mark_inode_dirty(handle, inode); in mpage_map_and_submit_extent()
2306 ext4_error_err(inode->i_sb, -err2, in mpage_map_and_submit_extent()
2308 inode->i_ino); in mpage_map_and_submit_extent()
2323 static int ext4_da_writepages_trans_blocks(struct inode *inode) in ext4_da_writepages_trans_blocks() argument
2325 int bpp = ext4_journal_blocks_per_page(inode); in ext4_da_writepages_trans_blocks()
2327 return ext4_meta_trans_blocks(inode, in ext4_da_writepages_trans_blocks()
2335 struct inode *inode = folio->mapping->host; in ext4_journal_folio_buffers() local
2338 ret = ext4_walk_page_buffers(handle, inode, page_bufs, 0, len, in ext4_journal_folio_buffers()
2340 err = ext4_walk_page_buffers(handle, inode, page_bufs, 0, len, in ext4_journal_folio_buffers()
2344 err = ext4_jbd2_inode_add_write(handle, inode, folio_pos(folio), len); in ext4_journal_folio_buffers()
2347 EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid; in ext4_journal_folio_buffers()
2356 struct inode *inode = mpd->inode; in mpage_journal_page_buffers() local
2357 loff_t size = i_size_read(inode); in mpage_journal_page_buffers()
2364 !ext4_verity_in_progress(inode)) in mpage_journal_page_buffers()
2392 struct address_space *mapping = mpd->inode->i_mapping; in mpage_prepare_extent_to_map()
2399 int blkbits = mpd->inode->i_blkbits; in mpage_prepare_extent_to_map()
2403 int bpp = ext4_journal_blocks_per_page(mpd->inode); in mpage_prepare_extent_to_map()
2412 if (ext4_should_journal_data(mpd->inode)) { in mpage_prepare_extent_to_map()
2413 handle = ext4_journal_start(mpd->inode, EXT4_HT_WRITE_PAGE, in mpage_prepare_extent_to_map()
2481 ext4_warning_inode(mpd->inode, "page %lu does not have buffers attached", folio->index); in mpage_prepare_extent_to_map()
2547 struct inode *inode = mpd->inode; in ext4_do_writepages() local
2548 struct address_space *mapping = inode->i_mapping; in ext4_do_writepages()
2554 trace_ext4_writepages(inode, wbc); in ext4_do_writepages()
2584 if (ext4_has_inline_data(inode)) { in ext4_do_writepages()
2586 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1); in ext4_do_writepages()
2591 BUG_ON(ext4_test_inode_state(inode, in ext4_do_writepages()
2593 ext4_destroy_inline_data(handle, inode); in ext4_do_writepages()
2609 if (ext4_should_journal_data(inode)) { in ext4_do_writepages()
2613 EXT4_I(inode)->i_datasync_tid); in ext4_do_writepages()
2617 if (ext4_should_dioread_nolock(inode)) { in ext4_do_writepages()
2622 rsv_blocks = 1 + ext4_chunk_trans_blocks(inode, in ext4_do_writepages()
2623 PAGE_SIZE >> inode->i_blkbits); in ext4_do_writepages()
2655 mpd->io_submit.io_end = ext4_init_io_end(inode, GFP_KERNEL); in ext4_do_writepages()
2672 mpd->io_submit.io_end = ext4_init_io_end(inode, GFP_KERNEL); in ext4_do_writepages()
2686 BUG_ON(ext4_should_journal_data(inode)); in ext4_do_writepages()
2687 needed_blocks = ext4_da_writepages_trans_blocks(inode); in ext4_do_writepages()
2690 handle = ext4_journal_start_with_reserve(inode, in ext4_do_writepages()
2694 ext4_msg(inode->i_sb, KERN_CRIT, "%s: jbd2_start: " in ext4_do_writepages()
2696 wbc->nr_to_write, inode->i_ino, ret); in ext4_do_writepages()
2704 trace_ext4_da_write_pages(inode, mpd->first_page, wbc); in ext4_do_writepages()
2775 trace_ext4_writepages_result(inode, wbc, ret, in ext4_do_writepages()
2785 .inode = mapping->host, in ext4_writepages()
2818 .inode = jinode->i_vfs_inode, in ext4_normal_submit_inode_data_buffers()
2830 struct inode *inode = mapping->host; in ext4_dax_writepages() local
2833 if (unlikely(ext4_forced_shutdown(inode->i_sb))) in ext4_dax_writepages()
2836 alloc_ctx = ext4_writepages_down_read(inode->i_sb); in ext4_dax_writepages()
2837 trace_ext4_writepages(inode, wbc); in ext4_dax_writepages()
2840 EXT4_SB(inode->i_sb)->s_daxdev, wbc); in ext4_dax_writepages()
2841 trace_ext4_writepages_result(inode, wbc, ret, in ext4_dax_writepages()
2843 ext4_writepages_up_read(inode->i_sb, alloc_ctx); in ext4_dax_writepages()
2888 struct inode *inode = mapping->host; in ext4_da_write_begin() local
2890 if (unlikely(ext4_forced_shutdown(inode->i_sb))) in ext4_da_write_begin()
2895 if (ext4_nonda_switch(inode->i_sb) || ext4_verity_in_progress(inode)) { in ext4_da_write_begin()
2901 trace_ext4_da_write_begin(inode, pos, len); in ext4_da_write_begin()
2903 if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { in ext4_da_write_begin()
2904 ret = ext4_da_write_inline_data_begin(mapping, inode, pos, len, in ext4_da_write_begin()
2931 if (pos + len > inode->i_size) in ext4_da_write_begin()
2932 ext4_truncate_failed_write(inode); in ext4_da_write_begin()
2935 ext4_should_retry_alloc(inode->i_sb, &retries)) in ext4_da_write_begin()
2952 struct inode *inode = folio->mapping->host; in ext4_da_should_update_i_disksize() local
2957 idx = offset >> inode->i_blkbits; in ext4_da_should_update_i_disksize()
2971 struct inode *inode = mapping->host; in ext4_da_do_write_end() local
2972 loff_t old_size = inode->i_size; in ext4_da_do_write_end()
3004 if (new_i_size > inode->i_size) { in ext4_da_do_write_end()
3007 i_size_write(inode, new_i_size); in ext4_da_do_write_end()
3010 ext4_update_i_disksize(inode, new_i_size); in ext4_da_do_write_end()
3019 pagecache_isize_extended(inode, old_size, pos); in ext4_da_do_write_end()
3024 handle = ext4_journal_start(inode, EXT4_HT_INODE, 2); in ext4_da_do_write_end()
3027 ext4_mark_inode_dirty(handle, inode); in ext4_da_do_write_end()
3039 struct inode *inode = mapping->host; in ext4_da_write_end() local
3047 trace_ext4_da_write_end(inode, pos, len, copied); in ext4_da_write_end()
3050 ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA) && in ext4_da_write_end()
3051 ext4_has_inline_data(inode)) in ext4_da_write_end()
3052 return ext4_write_inline_data_end(inode, pos, len, copied, in ext4_da_write_end()
3064 int ext4_alloc_da_blocks(struct inode *inode) in ext4_alloc_da_blocks() argument
3066 trace_ext4_alloc_da_blocks(inode); in ext4_alloc_da_blocks()
3068 if (!EXT4_I(inode)->i_reserved_data_blocks) in ext4_alloc_da_blocks()
3102 return filemap_flush(inode->i_mapping); in ext4_alloc_da_blocks()
3121 struct inode *inode = mapping->host; in ext4_bmap() local
3124 inode_lock_shared(inode); in ext4_bmap()
3128 if (ext4_has_inline_data(inode)) in ext4_bmap()
3132 (test_opt(inode->i_sb, DELALLOC) || in ext4_bmap()
3133 ext4_should_journal_data(inode))) { in ext4_bmap()
3145 inode_unlock_shared(inode); in ext4_bmap()
3152 struct inode *inode = folio->mapping->host; in ext4_read_folio() local
3154 trace_ext4_read_folio(inode, folio); in ext4_read_folio()
3156 if (ext4_has_inline_data(inode)) in ext4_read_folio()
3157 ret = ext4_readpage_inline(inode, folio); in ext4_read_folio()
3160 return ext4_mpage_readpages(inode, NULL, folio); in ext4_read_folio()
3167 struct inode *inode = rac->mapping->host; in ext4_readahead() local
3170 if (ext4_has_inline_data(inode)) in ext4_readahead()
3173 ext4_mpage_readpages(inode, rac, NULL); in ext4_readahead()
3213 struct inode *inode = folio->mapping->host; in ext4_release_folio() local
3214 journal_t *journal = EXT4_JOURNAL(inode); in ext4_release_folio()
3216 trace_ext4_release_folio(inode, folio); in ext4_release_folio()
3227 static bool ext4_inode_datasync_dirty(struct inode *inode) in ext4_inode_datasync_dirty() argument
3229 journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; in ext4_inode_datasync_dirty()
3233 EXT4_I(inode)->i_datasync_tid)) in ext4_inode_datasync_dirty()
3235 if (test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT)) in ext4_inode_datasync_dirty()
3236 return !list_empty(&EXT4_I(inode)->i_fc_list); in ext4_inode_datasync_dirty()
3241 if (!list_empty(&inode->i_mapping->private_list)) in ext4_inode_datasync_dirty()
3243 return inode->i_state & I_DIRTY_DATASYNC; in ext4_inode_datasync_dirty()
3246 static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, in ext4_set_iomap() argument
3250 u8 blkbits = inode->i_blkbits; in ext4_set_iomap()
3258 if (ext4_inode_datasync_dirty(inode) || in ext4_set_iomap()
3259 offset + length > i_size_read(inode)) in ext4_set_iomap()
3266 iomap->dax_dev = EXT4_SB(inode->i_sb)->s_daxdev; in ext4_set_iomap()
3268 iomap->bdev = inode->i_sb->s_bdev; in ext4_set_iomap()
3273 !ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_set_iomap()
3289 iomap->addr += EXT4_SB(inode->i_sb)->s_dax_part_off; in ext4_set_iomap()
3294 iomap->addr += EXT4_SB(inode->i_sb)->s_dax_part_off; in ext4_set_iomap()
3301 static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map, in ext4_iomap_alloc() argument
3305 u8 blkbits = inode->i_blkbits; in ext4_iomap_alloc()
3314 dio_credits = ext4_chunk_trans_blocks(inode, map->m_len); in ext4_iomap_alloc()
3323 handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, dio_credits); in ext4_iomap_alloc()
3340 else if (((loff_t)map->m_lblk << blkbits) >= i_size_read(inode)) in ext4_iomap_alloc()
3342 else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_iomap_alloc()
3345 ret = ext4_map_blocks(handle, inode, map, m_flags); in ext4_iomap_alloc()
3356 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) in ext4_iomap_alloc()
3363 static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, in ext4_iomap_begin() argument
3368 u8 blkbits = inode->i_blkbits; in ext4_iomap_begin()
3373 if (WARN_ON_ONCE(ext4_has_inline_data(inode))) in ext4_iomap_begin()
3390 if (offset + length <= i_size_read(inode)) { in ext4_iomap_begin()
3391 ret = ext4_map_blocks(NULL, inode, &map, 0); in ext4_iomap_begin()
3395 ret = ext4_iomap_alloc(inode, &map, flags); in ext4_iomap_begin()
3397 ret = ext4_map_blocks(NULL, inode, &map, 0); in ext4_iomap_begin()
3408 map.m_len = fscrypt_limit_io_blocks(inode, map.m_lblk, map.m_len); in ext4_iomap_begin()
3410 ext4_set_iomap(inode, iomap, &map, offset, length, flags); in ext4_iomap_begin()
3415 static int ext4_iomap_overwrite_begin(struct inode *inode, loff_t offset, in ext4_iomap_overwrite_begin() argument
3426 ret = ext4_iomap_begin(inode, offset, length, flags, iomap, srcmap); in ext4_iomap_overwrite_begin()
3431 static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t length, in ext4_iomap_end() argument
3457 static bool ext4_iomap_is_delalloc(struct inode *inode, in ext4_iomap_is_delalloc() argument
3463 ext4_es_find_extent_range(inode, &ext4_es_is_delayed, in ext4_iomap_is_delalloc()
3480 static int ext4_iomap_begin_report(struct inode *inode, loff_t offset, in ext4_iomap_begin_report() argument
3487 u8 blkbits = inode->i_blkbits; in ext4_iomap_begin_report()
3492 if (ext4_has_inline_data(inode)) { in ext4_iomap_begin_report()
3493 ret = ext4_inline_data_iomap(inode, iomap); in ext4_iomap_begin_report()
3514 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { in ext4_iomap_begin_report()
3515 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_iomap_begin_report()
3523 ret = ext4_map_blocks(NULL, inode, &map, 0); in ext4_iomap_begin_report()
3527 delalloc = ext4_iomap_is_delalloc(inode, &map); in ext4_iomap_begin_report()
3530 ext4_set_iomap(inode, iomap, &map, offset, length, flags); in ext4_iomap_begin_report()
3638 void ext4_set_aops(struct inode *inode) in ext4_set_aops() argument
3640 switch (ext4_inode_journal_mode(inode)) { in ext4_set_aops()
3645 inode->i_mapping->a_ops = &ext4_journalled_aops; in ext4_set_aops()
3650 if (IS_DAX(inode)) in ext4_set_aops()
3651 inode->i_mapping->a_ops = &ext4_dax_aops; in ext4_set_aops()
3652 else if (test_opt(inode->i_sb, DELALLOC)) in ext4_set_aops()
3653 inode->i_mapping->a_ops = &ext4_da_aops; in ext4_set_aops()
3655 inode->i_mapping->a_ops = &ext4_aops; in ext4_set_aops()
3665 struct inode *inode = mapping->host; in __ext4_block_zero_page_range() local
3676 blocksize = inode->i_sb->s_blocksize; in __ext4_block_zero_page_range()
3678 iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits); in __ext4_block_zero_page_range()
3699 ext4_get_block(inode, iblock, bh, 0); in __ext4_block_zero_page_range()
3715 if (fscrypt_inode_uses_fs_layer_crypto(inode)) { in __ext4_block_zero_page_range()
3717 BUG_ON(!fscrypt_has_encryption_key(inode)); in __ext4_block_zero_page_range()
3727 if (ext4_should_journal_data(inode)) { in __ext4_block_zero_page_range()
3729 err = ext4_journal_get_write_access(handle, inode->i_sb, bh, in __ext4_block_zero_page_range()
3737 if (ext4_should_journal_data(inode)) { in __ext4_block_zero_page_range()
3742 if (ext4_should_order_data(inode)) in __ext4_block_zero_page_range()
3743 err = ext4_jbd2_inode_add_write(handle, inode, from, in __ext4_block_zero_page_range()
3763 struct inode *inode = mapping->host; in ext4_block_zero_page_range() local
3765 unsigned blocksize = inode->i_sb->s_blocksize; in ext4_block_zero_page_range()
3775 if (IS_DAX(inode)) { in ext4_block_zero_page_range()
3776 return dax_zero_range(inode, from, length, NULL, in ext4_block_zero_page_range()
3794 struct inode *inode = mapping->host; in ext4_block_truncate_page() local
3797 if (IS_ENCRYPTED(inode) && !fscrypt_has_encryption_key(inode)) in ext4_block_truncate_page()
3800 blocksize = inode->i_sb->s_blocksize; in ext4_block_truncate_page()
3806 int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, in ext4_zero_partial_blocks() argument
3809 struct super_block *sb = inode->i_sb; in ext4_zero_partial_blocks()
3810 struct address_space *mapping = inode->i_mapping; in ext4_zero_partial_blocks()
3844 int ext4_can_truncate(struct inode *inode) in ext4_can_truncate() argument
3846 if (S_ISREG(inode->i_mode)) in ext4_can_truncate()
3848 if (S_ISDIR(inode->i_mode)) in ext4_can_truncate()
3850 if (S_ISLNK(inode->i_mode)) in ext4_can_truncate()
3851 return !ext4_inode_is_fast_symlink(inode); in ext4_can_truncate()
3861 int ext4_update_disksize_before_punch(struct inode *inode, loff_t offset, in ext4_update_disksize_before_punch() argument
3867 loff_t size = i_size_read(inode); in ext4_update_disksize_before_punch()
3869 WARN_ON(!inode_is_locked(inode)); in ext4_update_disksize_before_punch()
3873 if (EXT4_I(inode)->i_disksize >= size) in ext4_update_disksize_before_punch()
3876 handle = ext4_journal_start(inode, EXT4_HT_MISC, 1); in ext4_update_disksize_before_punch()
3879 ext4_update_i_disksize(inode, size); in ext4_update_disksize_before_punch()
3880 ret = ext4_mark_inode_dirty(handle, inode); in ext4_update_disksize_before_punch()
3886 static void ext4_wait_dax_page(struct inode *inode) in ext4_wait_dax_page() argument
3888 filemap_invalidate_unlock(inode->i_mapping); in ext4_wait_dax_page()
3890 filemap_invalidate_lock(inode->i_mapping); in ext4_wait_dax_page()
3893 int ext4_break_layouts(struct inode *inode) in ext4_break_layouts() argument
3898 if (WARN_ON_ONCE(!rwsem_is_locked(&inode->i_mapping->invalidate_lock))) in ext4_break_layouts()
3902 page = dax_layout_busy_page(inode->i_mapping); in ext4_break_layouts()
3909 ext4_wait_dax_page(inode)); in ext4_break_layouts()
3928 struct inode *inode = file_inode(file); in ext4_punch_hole() local
3929 struct super_block *sb = inode->i_sb; in ext4_punch_hole()
3931 struct address_space *mapping = inode->i_mapping; in ext4_punch_hole()
3933 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_punch_hole()
3938 trace_ext4_punch_hole(inode, offset, length, 0); in ext4_punch_hole()
3951 inode_lock(inode); in ext4_punch_hole()
3954 if (offset >= inode->i_size) in ext4_punch_hole()
3961 if (offset + length > inode->i_size) { in ext4_punch_hole()
3962 length = inode->i_size + in ext4_punch_hole()
3963 PAGE_SIZE - (inode->i_size & (PAGE_SIZE - 1)) - in ext4_punch_hole()
3971 max_length = sbi->s_bitmap_maxbytes - inode->i_sb->s_blocksize; in ext4_punch_hole()
3981 ret = ext4_inode_attach_jinode(inode); in ext4_punch_hole()
3988 inode_dio_wait(inode); in ext4_punch_hole()
4000 ret = ext4_break_layouts(inode); in ext4_punch_hole()
4009 ret = ext4_update_disksize_before_punch(inode, offset, length); in ext4_punch_hole()
4012 truncate_pagecache_range(inode, first_block_offset, in ext4_punch_hole()
4016 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_punch_hole()
4017 credits = ext4_writepage_trans_blocks(inode); in ext4_punch_hole()
4019 credits = ext4_blocks_for_truncate(inode); in ext4_punch_hole()
4020 handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits); in ext4_punch_hole()
4027 ret = ext4_zero_partial_blocks(handle, inode, offset, in ext4_punch_hole()
4039 down_write(&EXT4_I(inode)->i_data_sem); in ext4_punch_hole()
4040 ext4_discard_preallocations(inode, 0); in ext4_punch_hole()
4042 ext4_es_remove_extent(inode, first_block, in ext4_punch_hole()
4045 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_punch_hole()
4046 ret = ext4_ext_remove_space(inode, first_block, in ext4_punch_hole()
4049 ret = ext4_ind_remove_space(handle, inode, first_block, in ext4_punch_hole()
4052 up_write(&EXT4_I(inode)->i_data_sem); in ext4_punch_hole()
4054 ext4_fc_track_range(handle, inode, first_block, stop_block); in ext4_punch_hole()
4055 if (IS_SYNC(inode)) in ext4_punch_hole()
4058 inode->i_mtime = inode_set_ctime_current(inode); in ext4_punch_hole()
4059 ret2 = ext4_mark_inode_dirty(handle, inode); in ext4_punch_hole()
4063 ext4_update_inode_fsync_trans(handle, inode, 1); in ext4_punch_hole()
4069 inode_unlock(inode); in ext4_punch_hole()
4073 int ext4_inode_attach_jinode(struct inode *inode) in ext4_inode_attach_jinode() argument
4075 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_inode_attach_jinode()
4078 if (ei->jinode || !EXT4_SB(inode->i_sb)->s_journal) in ext4_inode_attach_jinode()
4082 spin_lock(&inode->i_lock); in ext4_inode_attach_jinode()
4085 spin_unlock(&inode->i_lock); in ext4_inode_attach_jinode()
4089 jbd2_journal_init_jbd_inode(ei->jinode, inode); in ext4_inode_attach_jinode()
4092 spin_unlock(&inode->i_lock); in ext4_inode_attach_jinode()
4126 int ext4_truncate(struct inode *inode) in ext4_truncate() argument
4128 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_truncate()
4132 struct address_space *mapping = inode->i_mapping; in ext4_truncate()
4139 if (!(inode->i_state & (I_NEW|I_FREEING))) in ext4_truncate()
4140 WARN_ON(!inode_is_locked(inode)); in ext4_truncate()
4141 trace_ext4_truncate_enter(inode); in ext4_truncate()
4143 if (!ext4_can_truncate(inode)) in ext4_truncate()
4146 if (inode->i_size == 0 && !test_opt(inode->i_sb, NO_AUTO_DA_ALLOC)) in ext4_truncate()
4147 ext4_set_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE); in ext4_truncate()
4149 if (ext4_has_inline_data(inode)) { in ext4_truncate()
4152 err = ext4_inline_data_truncate(inode, &has_inline); in ext4_truncate()
4158 if (inode->i_size & (inode->i_sb->s_blocksize - 1)) { in ext4_truncate()
4159 err = ext4_inode_attach_jinode(inode); in ext4_truncate()
4164 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_truncate()
4165 credits = ext4_writepage_trans_blocks(inode); in ext4_truncate()
4167 credits = ext4_blocks_for_truncate(inode); in ext4_truncate()
4169 handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits); in ext4_truncate()
4175 if (inode->i_size & (inode->i_sb->s_blocksize - 1)) in ext4_truncate()
4176 ext4_block_truncate_page(handle, mapping, inode->i_size); in ext4_truncate()
4187 err = ext4_orphan_add(handle, inode); in ext4_truncate()
4191 down_write(&EXT4_I(inode)->i_data_sem); in ext4_truncate()
4193 ext4_discard_preallocations(inode, 0); in ext4_truncate()
4195 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_truncate()
4196 err = ext4_ext_truncate(handle, inode); in ext4_truncate()
4198 ext4_ind_truncate(handle, inode); in ext4_truncate()
4204 if (IS_SYNC(inode)) in ext4_truncate()
4215 if (inode->i_nlink) in ext4_truncate()
4216 ext4_orphan_del(handle, inode); in ext4_truncate()
4218 inode->i_mtime = inode_set_ctime_current(inode); in ext4_truncate()
4219 err2 = ext4_mark_inode_dirty(handle, inode); in ext4_truncate()
4225 trace_ext4_truncate_exit(inode); in ext4_truncate()
4229 static inline u64 ext4_inode_peek_iversion(const struct inode *inode) in ext4_inode_peek_iversion() argument
4231 if (unlikely(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) in ext4_inode_peek_iversion()
4232 return inode_peek_iversion_raw(inode); in ext4_inode_peek_iversion()
4234 return inode_peek_iversion(inode); in ext4_inode_peek_iversion()
4240 struct inode *inode = &(ei->vfs_inode); in ext4_inode_blocks_set() local
4241 u64 i_blocks = READ_ONCE(inode->i_blocks); in ext4_inode_blocks_set()
4242 struct super_block *sb = inode->i_sb; in ext4_inode_blocks_set()
4251 ext4_clear_inode_flag(inode, EXT4_INODE_HUGE_FILE); in ext4_inode_blocks_set()
4270 ext4_clear_inode_flag(inode, EXT4_INODE_HUGE_FILE); in ext4_inode_blocks_set()
4272 ext4_set_inode_flag(inode, EXT4_INODE_HUGE_FILE); in ext4_inode_blocks_set()
4274 i_blocks = i_blocks >> (inode->i_blkbits - 9); in ext4_inode_blocks_set()
4281 static int ext4_fill_raw_inode(struct inode *inode, struct ext4_inode *raw_inode) in ext4_fill_raw_inode() argument
4283 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_fill_raw_inode()
4292 raw_inode->i_mode = cpu_to_le16(inode->i_mode); in ext4_fill_raw_inode()
4293 i_uid = i_uid_read(inode); in ext4_fill_raw_inode()
4294 i_gid = i_gid_read(inode); in ext4_fill_raw_inode()
4296 if (!(test_opt(inode->i_sb, NO_UID32))) { in ext4_fill_raw_inode()
4319 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink); in ext4_fill_raw_inode()
4321 EXT4_INODE_SET_CTIME(inode, raw_inode); in ext4_fill_raw_inode()
4322 EXT4_INODE_SET_XTIME(i_mtime, inode, raw_inode); in ext4_fill_raw_inode()
4323 EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode); in ext4_fill_raw_inode()
4328 if (likely(!test_opt2(inode->i_sb, HURD_COMPAT))) in ext4_fill_raw_inode()
4334 raw_inode->i_generation = cpu_to_le32(inode->i_generation); in ext4_fill_raw_inode()
4335 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { in ext4_fill_raw_inode()
4336 if (old_valid_dev(inode->i_rdev)) { in ext4_fill_raw_inode()
4338 cpu_to_le32(old_encode_dev(inode->i_rdev)); in ext4_fill_raw_inode()
4343 cpu_to_le32(new_encode_dev(inode->i_rdev)); in ext4_fill_raw_inode()
4346 } else if (!ext4_has_inline_data(inode)) { in ext4_fill_raw_inode()
4351 if (likely(!test_opt2(inode->i_sb, HURD_COMPAT))) { in ext4_fill_raw_inode()
4352 u64 ivers = ext4_inode_peek_iversion(inode); in ext4_fill_raw_inode()
4365 !ext4_has_feature_project(inode->i_sb)) in ext4_fill_raw_inode()
4368 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE && in ext4_fill_raw_inode()
4372 ext4_inode_csum_set(inode, raw_inode, ei); in ext4_fill_raw_inode()
4383 struct inode *inode, struct ext4_iloc *iloc, in __ext4_get_inode_loc() argument
4437 if (inode && !ext4_test_inode_state(inode, EXT4_STATE_XATTR)) { in __ext4_get_inode_loc()
4470 if (!ext4_test_inode_state(inode, EXT4_STATE_NEW)) in __ext4_get_inode_loc()
4471 ext4_fill_raw_inode(inode, raw_inode); in __ext4_get_inode_loc()
4526 static int __ext4_get_inode_loc_noinmem(struct inode *inode, in __ext4_get_inode_loc_noinmem() argument
4532 ret = __ext4_get_inode_loc(inode->i_sb, inode->i_ino, NULL, iloc, in __ext4_get_inode_loc_noinmem()
4536 ext4_error_inode_block(inode, err_blk, EIO, in __ext4_get_inode_loc_noinmem()
4542 int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc) in ext4_get_inode_loc() argument
4547 ret = __ext4_get_inode_loc(inode->i_sb, inode->i_ino, inode, iloc, in ext4_get_inode_loc()
4551 ext4_error_inode_block(inode, err_blk, EIO, in ext4_get_inode_loc()
4564 static bool ext4_should_enable_dax(struct inode *inode) in ext4_should_enable_dax() argument
4566 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_should_enable_dax()
4568 if (test_opt2(inode->i_sb, DAX_NEVER)) in ext4_should_enable_dax()
4570 if (!S_ISREG(inode->i_mode)) in ext4_should_enable_dax()
4572 if (ext4_should_journal_data(inode)) in ext4_should_enable_dax()
4574 if (ext4_has_inline_data(inode)) in ext4_should_enable_dax()
4576 if (ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT)) in ext4_should_enable_dax()
4578 if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY)) in ext4_should_enable_dax()
4582 if (test_opt(inode->i_sb, DAX_ALWAYS)) in ext4_should_enable_dax()
4585 return ext4_test_inode_flag(inode, EXT4_INODE_DAX); in ext4_should_enable_dax()
4588 void ext4_set_inode_flags(struct inode *inode, bool init) in ext4_set_inode_flags() argument
4590 unsigned int flags = EXT4_I(inode)->i_flags; in ext4_set_inode_flags()
4593 WARN_ON_ONCE(IS_DAX(inode) && init); in ext4_set_inode_flags()
4608 new_fl |= (inode->i_flags & S_DAX); in ext4_set_inode_flags()
4609 if (init && ext4_should_enable_dax(inode)) in ext4_set_inode_flags()
4618 inode_set_flags(inode, new_fl, in ext4_set_inode_flags()
4627 struct inode *inode = &(ei->vfs_inode); in ext4_inode_blocks() local
4628 struct super_block *sb = inode->i_sb; in ext4_inode_blocks()
4634 if (ext4_test_inode_flag(inode, EXT4_INODE_HUGE_FILE)) { in ext4_inode_blocks()
4636 return i_blocks << (inode->i_blkbits - 9); in ext4_inode_blocks()
4645 static inline int ext4_iget_extra_inode(struct inode *inode, in ext4_iget_extra_inode() argument
4652 if (EXT4_INODE_HAS_XATTR_SPACE(inode) && in ext4_iget_extra_inode()
4656 ext4_set_inode_state(inode, EXT4_STATE_XATTR); in ext4_iget_extra_inode()
4657 err = ext4_find_inline_data_nolock(inode); in ext4_iget_extra_inode()
4658 if (!err && ext4_has_inline_data(inode)) in ext4_iget_extra_inode()
4659 ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA); in ext4_iget_extra_inode()
4662 EXT4_I(inode)->i_inline_off = 0; in ext4_iget_extra_inode()
4666 int ext4_get_projid(struct inode *inode, kprojid_t *projid) in ext4_get_projid() argument
4668 if (!ext4_has_feature_project(inode->i_sb)) in ext4_get_projid()
4670 *projid = EXT4_I(inode)->i_projid; in ext4_get_projid()
4679 static inline void ext4_inode_set_iversion_queried(struct inode *inode, u64 val) in ext4_inode_set_iversion_queried() argument
4681 if (unlikely(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) in ext4_inode_set_iversion_queried()
4682 inode_set_iversion_raw(inode, val); in ext4_inode_set_iversion_queried()
4684 inode_set_iversion_queried(inode, val); in ext4_inode_set_iversion_queried()
4687 static const char *check_igot_inode(struct inode *inode, ext4_iget_flags flags) in check_igot_inode() argument
4691 if (!(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) in check_igot_inode()
4693 if (ext4_test_inode_state(inode, EXT4_STATE_XATTR) || in check_igot_inode()
4694 EXT4_I(inode)->i_file_acl) in check_igot_inode()
4697 if ((EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) in check_igot_inode()
4700 if (is_bad_inode(inode) && !(flags & EXT4_IGET_BAD)) in check_igot_inode()
4705 struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, in __ext4_iget()
4713 struct inode *inode; in __ext4_iget() local
4739 inode = iget_locked(sb, ino); in __ext4_iget()
4740 if (!inode) in __ext4_iget()
4742 if (!(inode->i_state & I_NEW)) { in __ext4_iget()
4743 if ((err_str = check_igot_inode(inode, flags)) != NULL) { in __ext4_iget()
4744 ext4_error_inode(inode, function, line, 0, err_str); in __ext4_iget()
4745 iput(inode); in __ext4_iget()
4748 return inode; in __ext4_iget()
4751 ei = EXT4_I(inode); in __ext4_iget()
4754 ret = __ext4_get_inode_loc_noinmem(inode, &iloc); in __ext4_iget()
4765 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { in __ext4_iget()
4768 EXT4_INODE_SIZE(inode->i_sb) || in __ext4_iget()
4770 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4774 EXT4_INODE_SIZE(inode->i_sb)); in __ext4_iget()
4783 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in __ext4_iget()
4785 __le32 inum = cpu_to_le32(inode->i_ino); in __ext4_iget()
4793 if ((!ext4_inode_csum_verify(inode, raw_inode, ei) || in __ext4_iget()
4796 ext4_error_inode_err(inode, function, line, 0, in __ext4_iget()
4802 inode->i_mode = le16_to_cpu(raw_inode->i_mode); in __ext4_iget()
4812 if (!(test_opt(inode->i_sb, NO_UID32))) { in __ext4_iget()
4816 i_uid_write(inode, i_uid); in __ext4_iget()
4817 i_gid_write(inode, i_gid); in __ext4_iget()
4819 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count)); in __ext4_iget()
4830 if (inode->i_nlink == 0) { in __ext4_iget()
4831 if ((inode->i_mode == 0 || flags & EXT4_IGET_SPECIAL || in __ext4_iget()
4832 !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) && in __ext4_iget()
4836 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4851 ext4_set_inode_flags(inode, true); in __ext4_iget()
4852 inode->i_blocks = ext4_inode_blocks(raw_inode, ei); in __ext4_iget()
4857 inode->i_size = ext4_isize(sb, raw_inode); in __ext4_iget()
4858 if ((size = i_size_read(inode)) < 0) { in __ext4_iget()
4859 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4870 ext4_test_inode_flag(inode, EXT4_INODE_INDEX)) { in __ext4_iget()
4871 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4876 ei->i_disksize = inode->i_size; in __ext4_iget()
4880 inode->i_generation = le32_to_cpu(raw_inode->i_generation); in __ext4_iget()
4917 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { in __ext4_iget()
4924 ret = ext4_iget_extra_inode(inode, raw_inode, ei); in __ext4_iget()
4930 EXT4_INODE_GET_CTIME(inode, raw_inode); in __ext4_iget()
4931 EXT4_INODE_GET_XTIME(i_mtime, inode, raw_inode); in __ext4_iget()
4932 EXT4_INODE_GET_XTIME(i_atime, inode, raw_inode); in __ext4_iget()
4935 if (likely(!test_opt2(inode->i_sb, HURD_COMPAT))) { in __ext4_iget()
4938 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { in __ext4_iget()
4943 ext4_inode_set_iversion_queried(inode, ivers); in __ext4_iget()
4948 !ext4_inode_block_valid(inode, ei->i_file_acl, 1)) { in __ext4_iget()
4949 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4954 } else if (!ext4_has_inline_data(inode)) { in __ext4_iget()
4957 (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || in __ext4_iget()
4958 (S_ISLNK(inode->i_mode) && in __ext4_iget()
4959 !ext4_inode_is_fast_symlink(inode)))) { in __ext4_iget()
4960 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in __ext4_iget()
4961 ret = ext4_ext_check_inode(inode); in __ext4_iget()
4963 ret = ext4_ind_check_inode(inode); in __ext4_iget()
4969 if (S_ISREG(inode->i_mode)) { in __ext4_iget()
4970 inode->i_op = &ext4_file_inode_operations; in __ext4_iget()
4971 inode->i_fop = &ext4_file_operations; in __ext4_iget()
4972 ext4_set_aops(inode); in __ext4_iget()
4973 } else if (S_ISDIR(inode->i_mode)) { in __ext4_iget()
4974 inode->i_op = &ext4_dir_inode_operations; in __ext4_iget()
4975 inode->i_fop = &ext4_dir_operations; in __ext4_iget()
4976 } else if (S_ISLNK(inode->i_mode)) { in __ext4_iget()
4978 if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) { in __ext4_iget()
4979 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4985 if (IS_ENCRYPTED(inode)) { in __ext4_iget()
4986 inode->i_op = &ext4_encrypted_symlink_inode_operations; in __ext4_iget()
4987 } else if (ext4_inode_is_fast_symlink(inode)) { in __ext4_iget()
4988 inode->i_link = (char *)ei->i_data; in __ext4_iget()
4989 inode->i_op = &ext4_fast_symlink_inode_operations; in __ext4_iget()
4990 nd_terminate_link(ei->i_data, inode->i_size, in __ext4_iget()
4993 inode->i_op = &ext4_symlink_inode_operations; in __ext4_iget()
4995 } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || in __ext4_iget()
4996 S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) { in __ext4_iget()
4997 inode->i_op = &ext4_special_inode_operations; in __ext4_iget()
4999 init_special_inode(inode, inode->i_mode, in __ext4_iget()
5002 init_special_inode(inode, inode->i_mode, in __ext4_iget()
5005 make_bad_inode(inode); in __ext4_iget()
5008 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
5009 "iget: bogus i_mode (%o)", inode->i_mode); in __ext4_iget()
5012 if (IS_CASEFOLDED(inode) && !ext4_has_feature_casefold(inode->i_sb)) { in __ext4_iget()
5013 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
5018 if ((err_str = check_igot_inode(inode, flags)) != NULL) { in __ext4_iget()
5019 ext4_error_inode(inode, function, line, 0, err_str); in __ext4_iget()
5025 unlock_new_inode(inode); in __ext4_iget()
5026 return inode; in __ext4_iget()
5030 iget_failed(inode); in __ext4_iget()
5039 struct inode *inode; in __ext4_update_other_inode_time() local
5041 inode = find_inode_by_ino_rcu(sb, ino); in __ext4_update_other_inode_time()
5042 if (!inode) in __ext4_update_other_inode_time()
5045 if (!inode_is_dirtytime_only(inode)) in __ext4_update_other_inode_time()
5048 spin_lock(&inode->i_lock); in __ext4_update_other_inode_time()
5049 if (inode_is_dirtytime_only(inode)) { in __ext4_update_other_inode_time()
5050 struct ext4_inode_info *ei = EXT4_I(inode); in __ext4_update_other_inode_time()
5052 inode->i_state &= ~I_DIRTY_TIME; in __ext4_update_other_inode_time()
5053 spin_unlock(&inode->i_lock); in __ext4_update_other_inode_time()
5056 EXT4_INODE_SET_CTIME(inode, raw_inode); in __ext4_update_other_inode_time()
5057 EXT4_INODE_SET_XTIME(i_mtime, inode, raw_inode); in __ext4_update_other_inode_time()
5058 EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode); in __ext4_update_other_inode_time()
5059 ext4_inode_csum_set(inode, raw_inode, ei); in __ext4_update_other_inode_time()
5061 trace_ext4_other_inode_update_time(inode, orig_ino); in __ext4_update_other_inode_time()
5064 spin_unlock(&inode->i_lock); in __ext4_update_other_inode_time()
5102 struct inode *inode, in ext4_do_update_inode() argument
5106 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_do_update_inode()
5108 struct super_block *sb = inode->i_sb; in ext4_do_update_inode()
5118 if (ext4_test_inode_state(inode, EXT4_STATE_NEW)) in ext4_do_update_inode()
5119 memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size); in ext4_do_update_inode()
5121 if (READ_ONCE(ei->i_disksize) != ext4_isize(inode->i_sb, raw_inode)) in ext4_do_update_inode()
5129 err = ext4_fill_raw_inode(inode, raw_inode); in ext4_do_update_inode()
5132 EXT4_ERROR_INODE(inode, "corrupted inode contents"); in ext4_do_update_inode()
5136 if (inode->i_sb->s_flags & SB_LAZYTIME) in ext4_do_update_inode()
5137 ext4_update_other_inodes_time(inode->i_sb, inode->i_ino, in ext4_do_update_inode()
5144 ext4_clear_inode_state(inode, EXT4_STATE_NEW); in ext4_do_update_inode()
5160 ext4_update_inode_fsync_trans(handle, inode, need_datasync); in ext4_do_update_inode()
5162 ext4_std_error(inode->i_sb, err); in ext4_do_update_inode()
5202 int ext4_write_inode(struct inode *inode, struct writeback_control *wbc) in ext4_write_inode() argument
5209 if (unlikely(ext4_forced_shutdown(inode->i_sb))) in ext4_write_inode()
5212 if (EXT4_SB(inode->i_sb)->s_journal) { in ext4_write_inode()
5227 err = ext4_fc_commit(EXT4_SB(inode->i_sb)->s_journal, in ext4_write_inode()
5228 EXT4_I(inode)->i_sync_tid); in ext4_write_inode()
5232 err = __ext4_get_inode_loc_noinmem(inode, &iloc); in ext4_write_inode()
5242 ext4_error_inode_block(inode, iloc.bh->b_blocknr, EIO, in ext4_write_inode()
5256 static void ext4_wait_for_tail_page_commit(struct inode *inode) in ext4_wait_for_tail_page_commit() argument
5259 journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; in ext4_wait_for_tail_page_commit()
5264 offset = inode->i_size & (PAGE_SIZE - 1); in ext4_wait_for_tail_page_commit()
5274 if (!offset || offset > (PAGE_SIZE - i_blocksize(inode))) in ext4_wait_for_tail_page_commit()
5277 struct folio *folio = filemap_lock_folio(inode->i_mapping, in ext4_wait_for_tail_page_commit()
5278 inode->i_size >> PAGE_SHIFT); in ext4_wait_for_tail_page_commit()
5326 struct inode *inode = d_inode(dentry); in ext4_setattr() local
5332 if (unlikely(ext4_forced_shutdown(inode->i_sb))) in ext4_setattr()
5335 if (unlikely(IS_IMMUTABLE(inode))) in ext4_setattr()
5338 if (unlikely(IS_APPEND(inode) && in ext4_setattr()
5355 if (is_quota_modification(idmap, inode, attr)) { in ext4_setattr()
5356 error = dquot_initialize(inode); in ext4_setattr()
5361 if (i_uid_needs_update(idmap, attr, inode) || in ext4_setattr()
5362 i_gid_needs_update(idmap, attr, inode)) { in ext4_setattr()
5367 handle = ext4_journal_start(inode, EXT4_HT_QUOTA, in ext4_setattr()
5368 (EXT4_MAXQUOTAS_INIT_BLOCKS(inode->i_sb) + in ext4_setattr()
5369 EXT4_MAXQUOTAS_DEL_BLOCKS(inode->i_sb)) + 3); in ext4_setattr()
5378 down_read(&EXT4_I(inode)->xattr_sem); in ext4_setattr()
5379 error = dquot_transfer(idmap, inode, attr); in ext4_setattr()
5380 up_read(&EXT4_I(inode)->xattr_sem); in ext4_setattr()
5388 i_uid_update(idmap, attr, inode); in ext4_setattr()
5389 i_gid_update(idmap, attr, inode); in ext4_setattr()
5390 error = ext4_mark_inode_dirty(handle, inode); in ext4_setattr()
5399 loff_t oldsize = inode->i_size; in ext4_setattr()
5401 int shrink = (attr->ia_size < inode->i_size); in ext4_setattr()
5403 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { in ext4_setattr()
5404 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_setattr()
5410 if (!S_ISREG(inode->i_mode)) { in ext4_setattr()
5414 if (attr->ia_size == inode->i_size) in ext4_setattr()
5418 if (ext4_should_order_data(inode)) { in ext4_setattr()
5419 error = ext4_begin_ordered_truncate(inode, in ext4_setattr()
5428 inode_dio_wait(inode); in ext4_setattr()
5431 filemap_invalidate_lock(inode->i_mapping); in ext4_setattr()
5433 rc = ext4_break_layouts(inode); in ext4_setattr()
5435 filemap_invalidate_unlock(inode->i_mapping); in ext4_setattr()
5439 if (attr->ia_size != inode->i_size) { in ext4_setattr()
5440 handle = ext4_journal_start(inode, EXT4_HT_INODE, 3); in ext4_setattr()
5446 error = ext4_orphan_add(handle, inode); in ext4_setattr()
5454 inode->i_mtime = inode_set_ctime_current(inode); in ext4_setattr()
5457 ext4_fc_track_range(handle, inode, in ext4_setattr()
5459 inode->i_sb->s_blocksize_bits, in ext4_setattr()
5463 handle, inode, in ext4_setattr()
5465 inode->i_sb->s_blocksize_bits, in ext4_setattr()
5467 inode->i_sb->s_blocksize_bits); in ext4_setattr()
5469 down_write(&EXT4_I(inode)->i_data_sem); in ext4_setattr()
5470 old_disksize = EXT4_I(inode)->i_disksize; in ext4_setattr()
5471 EXT4_I(inode)->i_disksize = attr->ia_size; in ext4_setattr()
5472 rc = ext4_mark_inode_dirty(handle, inode); in ext4_setattr()
5481 i_size_write(inode, attr->ia_size); in ext4_setattr()
5483 EXT4_I(inode)->i_disksize = old_disksize; in ext4_setattr()
5484 up_write(&EXT4_I(inode)->i_data_sem); in ext4_setattr()
5489 pagecache_isize_extended(inode, oldsize, in ext4_setattr()
5490 inode->i_size); in ext4_setattr()
5491 } else if (ext4_should_journal_data(inode)) { in ext4_setattr()
5492 ext4_wait_for_tail_page_commit(inode); in ext4_setattr()
5500 truncate_pagecache(inode, inode->i_size); in ext4_setattr()
5506 rc = ext4_truncate(inode); in ext4_setattr()
5511 filemap_invalidate_unlock(inode->i_mapping); in ext4_setattr()
5516 inode_inc_iversion(inode); in ext4_setattr()
5517 setattr_copy(idmap, inode, attr); in ext4_setattr()
5518 mark_inode_dirty(inode); in ext4_setattr()
5525 if (orphan && inode->i_nlink) in ext4_setattr()
5526 ext4_orphan_del(NULL, inode); in ext4_setattr()
5529 rc = posix_acl_chmod(idmap, dentry, inode->i_mode); in ext4_setattr()
5533 ext4_std_error(inode->i_sb, error); in ext4_setattr()
5539 u32 ext4_dio_alignment(struct inode *inode) in ext4_dio_alignment() argument
5541 if (fsverity_active(inode)) in ext4_dio_alignment()
5543 if (ext4_should_journal_data(inode)) in ext4_dio_alignment()
5545 if (ext4_has_inline_data(inode)) in ext4_dio_alignment()
5547 if (IS_ENCRYPTED(inode)) { in ext4_dio_alignment()
5548 if (!fscrypt_dio_supported(inode)) in ext4_dio_alignment()
5550 return i_blocksize(inode); in ext4_dio_alignment()
5558 struct inode *inode = d_inode(path->dentry); in ext4_getattr() local
5560 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_getattr()
5575 if ((request_mask & STATX_DIOALIGN) && S_ISREG(inode->i_mode)) { in ext4_getattr()
5576 u32 dio_align = ext4_dio_alignment(inode); in ext4_getattr()
5580 struct block_device *bdev = inode->i_sb->s_bdev; in ext4_getattr()
5612 generic_fillattr(idmap, request_mask, inode, stat); in ext4_getattr()
5620 struct inode *inode = d_inode(path->dentry); in ext4_file_getattr() local
5631 if (unlikely(ext4_has_inline_data(inode))) in ext4_file_getattr()
5644 delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb), in ext4_file_getattr()
5645 EXT4_I(inode)->i_reserved_data_blocks); in ext4_file_getattr()
5646 stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits - 9); in ext4_file_getattr()
5650 static int ext4_index_trans_blocks(struct inode *inode, int lblocks, in ext4_index_trans_blocks() argument
5653 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) in ext4_index_trans_blocks()
5654 return ext4_ind_trans_blocks(inode, lblocks); in ext4_index_trans_blocks()
5655 return ext4_ext_index_trans_blocks(inode, pextents); in ext4_index_trans_blocks()
5669 static int ext4_meta_trans_blocks(struct inode *inode, int lblocks, in ext4_meta_trans_blocks() argument
5672 ext4_group_t groups, ngroups = ext4_get_groups_count(inode->i_sb); in ext4_meta_trans_blocks()
5681 idxblocks = ext4_index_trans_blocks(inode, lblocks, pextents); in ext4_meta_trans_blocks()
5693 if (groups > EXT4_SB(inode->i_sb)->s_gdb_count) in ext4_meta_trans_blocks()
5694 gdpblocks = EXT4_SB(inode->i_sb)->s_gdb_count; in ext4_meta_trans_blocks()
5700 ret += EXT4_META_TRANS_BLOCKS(inode->i_sb); in ext4_meta_trans_blocks()
5715 int ext4_writepage_trans_blocks(struct inode *inode) in ext4_writepage_trans_blocks() argument
5717 int bpp = ext4_journal_blocks_per_page(inode); in ext4_writepage_trans_blocks()
5720 ret = ext4_meta_trans_blocks(inode, bpp, bpp); in ext4_writepage_trans_blocks()
5723 if (ext4_should_journal_data(inode)) in ext4_writepage_trans_blocks()
5737 int ext4_chunk_trans_blocks(struct inode *inode, int nrblocks) in ext4_chunk_trans_blocks() argument
5739 return ext4_meta_trans_blocks(inode, nrblocks, 1); in ext4_chunk_trans_blocks()
5747 struct inode *inode, struct ext4_iloc *iloc) in ext4_mark_iloc_dirty() argument
5751 if (unlikely(ext4_forced_shutdown(inode->i_sb))) { in ext4_mark_iloc_dirty()
5755 ext4_fc_track_inode(handle, inode); in ext4_mark_iloc_dirty()
5761 err = ext4_do_update_inode(handle, inode, iloc); in ext4_mark_iloc_dirty()
5772 ext4_reserve_inode_write(handle_t *handle, struct inode *inode, in ext4_reserve_inode_write() argument
5777 if (unlikely(ext4_forced_shutdown(inode->i_sb))) in ext4_reserve_inode_write()
5780 err = ext4_get_inode_loc(inode, iloc); in ext4_reserve_inode_write()
5783 err = ext4_journal_get_write_access(handle, inode->i_sb, in ext4_reserve_inode_write()
5790 ext4_std_error(inode->i_sb, err); in ext4_reserve_inode_write()
5794 static int __ext4_expand_extra_isize(struct inode *inode, in __ext4_expand_extra_isize() argument
5801 unsigned int inode_size = EXT4_INODE_SIZE(inode->i_sb); in __ext4_expand_extra_isize()
5802 struct ext4_inode_info *ei = EXT4_I(inode); in __ext4_expand_extra_isize()
5808 EXT4_ERROR_INODE(inode, "bad extra_isize %u (inode size %u)", in __ext4_expand_extra_isize()
5810 EXT4_INODE_SIZE(inode->i_sb)); in __ext4_expand_extra_isize()
5820 header = IHDR(inode, raw_inode); in __ext4_expand_extra_isize()
5823 if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR) || in __ext4_expand_extra_isize()
5826 EXT4_I(inode)->i_extra_isize, 0, in __ext4_expand_extra_isize()
5827 new_extra_isize - EXT4_I(inode)->i_extra_isize); in __ext4_expand_extra_isize()
5828 EXT4_I(inode)->i_extra_isize = new_extra_isize; in __ext4_expand_extra_isize()
5837 if (dquot_initialize_needed(inode)) in __ext4_expand_extra_isize()
5841 error = ext4_expand_extra_isize_ea(inode, new_extra_isize, in __ext4_expand_extra_isize()
5857 static int ext4_try_to_expand_extra_isize(struct inode *inode, in ext4_try_to_expand_extra_isize() argument
5865 if (ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) in ext4_try_to_expand_extra_isize()
5878 EXT4_DATA_TRANS_BLOCKS(inode->i_sb), 0) != 0) in ext4_try_to_expand_extra_isize()
5881 if (ext4_write_trylock_xattr(inode, &no_expand) == 0) in ext4_try_to_expand_extra_isize()
5884 error = __ext4_expand_extra_isize(inode, new_extra_isize, &iloc, in ext4_try_to_expand_extra_isize()
5886 ext4_write_unlock_xattr(inode, &no_expand); in ext4_try_to_expand_extra_isize()
5891 int ext4_expand_extra_isize(struct inode *inode, in ext4_expand_extra_isize() argument
5899 if (ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) { in ext4_expand_extra_isize()
5904 handle = ext4_journal_start(inode, EXT4_HT_INODE, in ext4_expand_extra_isize()
5905 EXT4_DATA_TRANS_BLOCKS(inode->i_sb)); in ext4_expand_extra_isize()
5912 ext4_write_lock_xattr(inode, &no_expand); in ext4_expand_extra_isize()
5915 error = ext4_journal_get_write_access(handle, inode->i_sb, iloc->bh, in ext4_expand_extra_isize()
5922 error = __ext4_expand_extra_isize(inode, new_extra_isize, iloc, in ext4_expand_extra_isize()
5925 rc = ext4_mark_iloc_dirty(handle, inode, iloc); in ext4_expand_extra_isize()
5930 ext4_write_unlock_xattr(inode, &no_expand); in ext4_expand_extra_isize()
5948 int __ext4_mark_inode_dirty(handle_t *handle, struct inode *inode, in __ext4_mark_inode_dirty() argument
5952 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in __ext4_mark_inode_dirty()
5956 trace_ext4_mark_inode_dirty(inode, _RET_IP_); in __ext4_mark_inode_dirty()
5957 err = ext4_reserve_inode_write(handle, inode, &iloc); in __ext4_mark_inode_dirty()
5961 if (EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize) in __ext4_mark_inode_dirty()
5962 ext4_try_to_expand_extra_isize(inode, sbi->s_want_extra_isize, in __ext4_mark_inode_dirty()
5965 err = ext4_mark_iloc_dirty(handle, inode, &iloc); in __ext4_mark_inode_dirty()
5968 ext4_error_inode_err(inode, func, line, 0, err, in __ext4_mark_inode_dirty()
5987 void ext4_dirty_inode(struct inode *inode, int flags) in ext4_dirty_inode() argument
5991 handle = ext4_journal_start(inode, EXT4_HT_INODE, 2); in ext4_dirty_inode()
5994 ext4_mark_inode_dirty(handle, inode); in ext4_dirty_inode()
5998 int ext4_change_inode_journal_flag(struct inode *inode, int val) in ext4_change_inode_journal_flag() argument
6015 journal = EXT4_JOURNAL(inode); in ext4_change_inode_journal_flag()
6022 inode_dio_wait(inode); in ext4_change_inode_journal_flag()
6033 filemap_invalidate_lock(inode->i_mapping); in ext4_change_inode_journal_flag()
6034 err = filemap_write_and_wait(inode->i_mapping); in ext4_change_inode_journal_flag()
6036 filemap_invalidate_unlock(inode->i_mapping); in ext4_change_inode_journal_flag()
6041 alloc_ctx = ext4_writepages_down_write(inode->i_sb); in ext4_change_inode_journal_flag()
6053 ext4_set_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); in ext4_change_inode_journal_flag()
6058 ext4_writepages_up_write(inode->i_sb, alloc_ctx); in ext4_change_inode_journal_flag()
6061 ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); in ext4_change_inode_journal_flag()
6063 ext4_set_aops(inode); in ext4_change_inode_journal_flag()
6066 ext4_writepages_up_write(inode->i_sb, alloc_ctx); in ext4_change_inode_journal_flag()
6069 filemap_invalidate_unlock(inode->i_mapping); in ext4_change_inode_journal_flag()
6073 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1); in ext4_change_inode_journal_flag()
6077 ext4_fc_mark_ineligible(inode->i_sb, in ext4_change_inode_journal_flag()
6079 err = ext4_mark_inode_dirty(handle, inode); in ext4_change_inode_journal_flag()
6082 ext4_std_error(inode->i_sb, err); in ext4_change_inode_journal_flag()
6087 static int ext4_bh_unmapped(handle_t *handle, struct inode *inode, in ext4_bh_unmapped() argument
6102 struct inode *inode = file_inode(file); in ext4_page_mkwrite() local
6103 struct address_space *mapping = inode->i_mapping; in ext4_page_mkwrite()
6108 if (unlikely(IS_IMMUTABLE(inode))) in ext4_page_mkwrite()
6111 sb_start_pagefault(inode->i_sb); in ext4_page_mkwrite()
6116 err = ext4_convert_inline_data(inode); in ext4_page_mkwrite()
6126 if (ext4_should_journal_data(inode)) in ext4_page_mkwrite()
6130 if (test_opt(inode->i_sb, DELALLOC) && in ext4_page_mkwrite()
6131 !ext4_nonda_switch(inode->i_sb)) { in ext4_page_mkwrite()
6136 ext4_should_retry_alloc(inode->i_sb, &retries)); in ext4_page_mkwrite()
6141 size = i_size_read(inode); in ext4_page_mkwrite()
6160 if (!ext4_walk_page_buffers(NULL, inode, folio_buffers(folio), in ext4_page_mkwrite()
6171 if (ext4_should_dioread_nolock(inode)) in ext4_page_mkwrite()
6176 handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, in ext4_page_mkwrite()
6177 ext4_writepage_trans_blocks(inode)); in ext4_page_mkwrite()
6187 if (!ext4_should_journal_data(inode)) { in ext4_page_mkwrite()
6191 size = i_size_read(inode); in ext4_page_mkwrite()
6212 if (err == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) in ext4_page_mkwrite()
6218 sb_end_pagefault(inode->i_sb); in ext4_page_mkwrite()