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()
143 static int ext4_meta_trans_blocks(struct inode *inode, int lblocks,
150 int ext4_inode_is_fast_symlink(struct inode *inode) in ext4_inode_is_fast_symlink() argument
152 if (!(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) { in ext4_inode_is_fast_symlink()
153 int ea_blocks = EXT4_I(inode)->i_file_acl ? in ext4_inode_is_fast_symlink()
154 EXT4_CLUSTER_SIZE(inode->i_sb) >> 9 : 0; in ext4_inode_is_fast_symlink()
156 if (ext4_has_inline_data(inode)) in ext4_inode_is_fast_symlink()
159 return (S_ISLNK(inode->i_mode) && inode->i_blocks - ea_blocks == 0); in ext4_inode_is_fast_symlink()
161 return S_ISLNK(inode->i_mode) && inode->i_size && in ext4_inode_is_fast_symlink()
162 (inode->i_size < EXT4_N_BLOCKS * 4); in ext4_inode_is_fast_symlink()
168 void ext4_evict_inode(struct inode *inode) in ext4_evict_inode() argument
181 trace_ext4_evict_inode(inode); in ext4_evict_inode()
183 if (EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL) in ext4_evict_inode()
184 ext4_evict_ea_inode(inode); in ext4_evict_inode()
185 if (inode->i_nlink) { in ext4_evict_inode()
204 if (inode->i_ino != EXT4_JOURNAL_INO && in ext4_evict_inode()
205 ext4_should_journal_data(inode) && in ext4_evict_inode()
206 (S_ISLNK(inode->i_mode) || S_ISREG(inode->i_mode)) && in ext4_evict_inode()
207 inode->i_data.nrpages) { in ext4_evict_inode()
208 journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; in ext4_evict_inode()
209 tid_t commit_tid = EXT4_I(inode)->i_datasync_tid; in ext4_evict_inode()
212 filemap_write_and_wait(&inode->i_data); in ext4_evict_inode()
214 truncate_inode_pages_final(&inode->i_data); in ext4_evict_inode()
219 if (is_bad_inode(inode)) in ext4_evict_inode()
221 dquot_initialize(inode); in ext4_evict_inode()
223 if (ext4_should_order_data(inode)) in ext4_evict_inode()
224 ext4_begin_ordered_truncate(inode, 0); in ext4_evict_inode()
225 truncate_inode_pages_final(&inode->i_data); in ext4_evict_inode()
234 if (!list_empty_careful(&inode->i_io_list)) in ext4_evict_inode()
235 inode_io_list_del(inode); in ext4_evict_inode()
244 sb_start_intwrite(inode->i_sb); in ext4_evict_inode()
248 if (!IS_NOQUOTA(inode)) in ext4_evict_inode()
249 extra_credits += EXT4_MAXQUOTAS_DEL_BLOCKS(inode->i_sb); in ext4_evict_inode()
255 handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, in ext4_evict_inode()
256 ext4_blocks_for_truncate(inode) + extra_credits - 3); in ext4_evict_inode()
258 ext4_std_error(inode->i_sb, PTR_ERR(handle)); in ext4_evict_inode()
264 ext4_orphan_del(NULL, inode); in ext4_evict_inode()
266 sb_end_intwrite(inode->i_sb); in ext4_evict_inode()
270 if (IS_SYNC(inode)) in ext4_evict_inode()
280 if (ext4_inode_is_fast_symlink(inode)) in ext4_evict_inode()
281 memset(EXT4_I(inode)->i_data, 0, sizeof(EXT4_I(inode)->i_data)); in ext4_evict_inode()
282 inode->i_size = 0; in ext4_evict_inode()
283 err = ext4_mark_inode_dirty(handle, inode); in ext4_evict_inode()
285 ext4_warning(inode->i_sb, in ext4_evict_inode()
289 if (inode->i_blocks) { in ext4_evict_inode()
290 err = ext4_truncate(inode); in ext4_evict_inode()
292 ext4_error_err(inode->i_sb, -err, in ext4_evict_inode()
294 inode->i_ino, err); in ext4_evict_inode()
300 err = ext4_xattr_delete_inode(handle, inode, &ea_inode_array, in ext4_evict_inode()
303 ext4_warning(inode->i_sb, "xattr delete (err %d)", err); in ext4_evict_inode()
306 ext4_orphan_del(NULL, inode); in ext4_evict_inode()
308 sb_end_intwrite(inode->i_sb); in ext4_evict_inode()
321 ext4_orphan_del(handle, inode); in ext4_evict_inode()
322 EXT4_I(inode)->i_dtime = (__u32)ktime_get_real_seconds(); in ext4_evict_inode()
331 if (ext4_mark_inode_dirty(handle, inode)) in ext4_evict_inode()
333 ext4_clear_inode(inode); in ext4_evict_inode()
335 ext4_free_inode(handle, inode); in ext4_evict_inode()
338 sb_end_intwrite(inode->i_sb); in ext4_evict_inode()
346 WARN_ON_ONCE(!list_empty_careful(&inode->i_io_list)); in ext4_evict_inode()
348 if (!list_empty(&EXT4_I(inode)->i_fc_list)) in ext4_evict_inode()
349 ext4_fc_mark_ineligible(inode->i_sb, EXT4_FC_REASON_NOMEM); in ext4_evict_inode()
350 ext4_clear_inode(inode); /* We must guarantee clearing of inode... */ in ext4_evict_inode()
354 qsize_t *ext4_get_reserved_space(struct inode *inode) in ext4_get_reserved_space() argument
356 return &EXT4_I(inode)->i_reserved_quota; in ext4_get_reserved_space()
364 void ext4_da_update_reserve_space(struct inode *inode, in ext4_da_update_reserve_space() argument
367 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_da_update_reserve_space()
368 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_da_update_reserve_space()
371 trace_ext4_da_update_reserve_space(inode, used, quota_claim); in ext4_da_update_reserve_space()
373 ext4_warning(inode->i_sb, "%s: ino %lu, used %d " in ext4_da_update_reserve_space()
375 __func__, inode->i_ino, used, in ext4_da_update_reserve_space()
385 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); in ext4_da_update_reserve_space()
389 dquot_claim_block(inode, EXT4_C2B(sbi, used)); in ext4_da_update_reserve_space()
396 dquot_release_reservation_block(inode, EXT4_C2B(sbi, used)); in ext4_da_update_reserve_space()
405 !inode_is_open_for_write(inode)) in ext4_da_update_reserve_space()
406 ext4_discard_preallocations(inode, 0); in ext4_da_update_reserve_space()
409 static int __check_block_validity(struct inode *inode, const char *func, in __check_block_validity() argument
413 if (ext4_has_feature_journal(inode->i_sb) && in __check_block_validity()
414 (inode->i_ino == in __check_block_validity()
415 le32_to_cpu(EXT4_SB(inode->i_sb)->s_es->s_journal_inum))) in __check_block_validity()
417 if (!ext4_inode_block_valid(inode, map->m_pblk, map->m_len)) { in __check_block_validity()
418 ext4_error_inode(inode, func, line, map->m_pblk, in __check_block_validity()
427 int ext4_issue_zeroout(struct inode *inode, ext4_lblk_t lblk, ext4_fsblk_t pblk, in ext4_issue_zeroout() argument
432 if (IS_ENCRYPTED(inode) && S_ISREG(inode->i_mode)) in ext4_issue_zeroout()
433 return fscrypt_zeroout_range(inode, lblk, pblk, len); in ext4_issue_zeroout()
435 ret = sb_issue_zeroout(inode->i_sb, pblk, len, GFP_NOFS); in ext4_issue_zeroout()
442 #define check_block_validity(inode, map) \ argument
443 __check_block_validity((inode), __func__, __LINE__, (map))
447 struct inode *inode, in ext4_map_blocks_es_recheck() argument
462 down_read(&EXT4_I(inode)->i_data_sem); in ext4_map_blocks_es_recheck()
463 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { in ext4_map_blocks_es_recheck()
464 retval = ext4_ext_map_blocks(handle, inode, map, 0); in ext4_map_blocks_es_recheck()
466 retval = ext4_ind_map_blocks(handle, inode, map, 0); in ext4_map_blocks_es_recheck()
468 up_read((&EXT4_I(inode)->i_data_sem)); in ext4_map_blocks_es_recheck()
480 inode->i_ino, es_map->m_lblk, es_map->m_len, in ext4_map_blocks_es_recheck()
510 int ext4_map_blocks(handle_t *handle, struct inode *inode, in ext4_map_blocks() argument
523 ext_debug(inode, "flag 0x%x, max_blocks %u, logical block %lu\n", in ext4_map_blocks()
537 if (!(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) && in ext4_map_blocks()
538 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()
569 down_read(&EXT4_I(inode)->i_data_sem); in ext4_map_blocks()
570 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { in ext4_map_blocks()
571 retval = ext4_ext_map_blocks(handle, inode, map, 0); in ext4_map_blocks()
573 retval = ext4_ind_map_blocks(handle, inode, map, 0); in ext4_map_blocks()
579 ext4_warning(inode->i_sb, in ext4_map_blocks()
582 inode->i_ino, retval, map->m_len); in ext4_map_blocks()
590 ext4_es_scan_range(inode, &ext4_es_is_delayed, map->m_lblk, in ext4_map_blocks()
593 ext4_es_insert_extent(inode, map->m_lblk, map->m_len, in ext4_map_blocks()
596 up_read((&EXT4_I(inode)->i_data_sem)); in ext4_map_blocks()
600 ret = check_block_validity(inode, map); in ext4_map_blocks()
637 down_write(&EXT4_I(inode)->i_data_sem); in ext4_map_blocks()
643 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) { in ext4_map_blocks()
644 retval = ext4_ext_map_blocks(handle, inode, map, flags); in ext4_map_blocks()
646 retval = ext4_ind_map_blocks(handle, inode, map, flags); in ext4_map_blocks()
654 ext4_clear_inode_state(inode, EXT4_STATE_EXT_MIGRATE); in ext4_map_blocks()
662 ext4_warning(inode->i_sb, in ext4_map_blocks()
665 inode->i_ino, retval, map->m_len); in ext4_map_blocks()
679 ret = ext4_issue_zeroout(inode, map->m_lblk, in ext4_map_blocks()
692 ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) { in ext4_map_blocks()
700 ext4_es_scan_range(inode, &ext4_es_is_delayed, map->m_lblk, in ext4_map_blocks()
703 ext4_es_insert_extent(inode, map->m_lblk, map->m_len, in ext4_map_blocks()
708 up_write((&EXT4_I(inode)->i_data_sem)); in ext4_map_blocks()
710 ret = check_block_validity(inode, map); in ext4_map_blocks()
722 !ext4_is_quota_file(inode) && in ext4_map_blocks()
723 ext4_should_order_data(inode)) { in ext4_map_blocks()
725 (loff_t)map->m_lblk << inode->i_blkbits; in ext4_map_blocks()
726 loff_t length = (loff_t)map->m_len << inode->i_blkbits; in ext4_map_blocks()
729 ret = ext4_jbd2_inode_add_wait(handle, inode, in ext4_map_blocks()
732 ret = ext4_jbd2_inode_add_write(handle, inode, in ext4_map_blocks()
740 ext4_fc_track_range(handle, inode, map->m_lblk, in ext4_map_blocks()
743 ext_debug(inode, "failed with err %d\n", retval); in ext4_map_blocks()
775 static int _ext4_get_block(struct inode *inode, sector_t iblock, in _ext4_get_block() argument
781 if (ext4_has_inline_data(inode)) in _ext4_get_block()
785 map.m_len = bh->b_size >> inode->i_blkbits; in _ext4_get_block()
787 ret = ext4_map_blocks(ext4_journal_current_handle(), inode, &map, in _ext4_get_block()
790 map_bh(bh, inode->i_sb, map.m_pblk); in _ext4_get_block()
792 bh->b_size = inode->i_sb->s_blocksize * map.m_len; in _ext4_get_block()
796 bh->b_size = inode->i_sb->s_blocksize * map.m_len; in _ext4_get_block()
801 int ext4_get_block(struct inode *inode, sector_t iblock, in ext4_get_block() argument
804 return _ext4_get_block(inode, iblock, bh, in ext4_get_block()
813 int ext4_get_block_unwritten(struct inode *inode, sector_t iblock, in ext4_get_block_unwritten() argument
817 inode->i_ino, create); in ext4_get_block_unwritten()
818 return _ext4_get_block(inode, iblock, bh_result, in ext4_get_block_unwritten()
828 struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, in ext4_getblk() argument
836 J_ASSERT((EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) in ext4_getblk()
841 err = ext4_map_blocks(handle, inode, &map, map_flags); in ext4_getblk()
848 bh = sb_getblk(inode->i_sb, map.m_pblk); in ext4_getblk()
853 J_ASSERT((EXT4_SB(inode->i_sb)->s_mount_state & EXT4_FC_REPLAY) in ext4_getblk()
871 memset(bh->b_data, 0, inode->i_sb->s_blocksize); in ext4_getblk()
876 err = ext4_handle_dirty_metadata(handle, inode, bh); in ext4_getblk()
887 struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode, in ext4_bread() argument
893 bh = ext4_getblk(handle, inode, block, map_flags); in ext4_bread()
908 int ext4_bread_batch(struct inode *inode, ext4_lblk_t block, int bh_count, in ext4_bread_batch() argument
914 bhs[i] = ext4_getblk(NULL, inode, block + i, 0 /* map_flags */); in ext4_bread_batch()
1036 struct inode *inode = page->mapping->host; in ext4_block_write_begin() local
1040 unsigned blocksize = inode->i_sb->s_blocksize; in ext4_block_write_begin()
1071 err = get_block(inode, block, bh, 1); in ext4_block_write_begin()
1109 } else if (fscrypt_inode_uses_fs_layer_crypto(inode)) { in ext4_block_write_begin()
1130 struct inode *inode = mapping->host; in ext4_write_begin() local
1138 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) in ext4_write_begin()
1146 inode); in ext4_write_begin()
1147 trace_android_fs_datawrite_start(inode, pos, len, in ext4_write_begin()
1151 trace_ext4_write_begin(inode, pos, len, flags); in ext4_write_begin()
1156 needed_blocks = ext4_writepage_trans_blocks(inode) + 1; in ext4_write_begin()
1161 if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { in ext4_write_begin()
1162 ret = ext4_try_to_write_inline_data(mapping, inode, pos, len, in ext4_write_begin()
1186 create_empty_buffers(page, inode->i_sb->s_blocksize, 0); in ext4_write_begin()
1191 handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks); in ext4_write_begin()
1209 if (ext4_should_dioread_nolock(inode)) in ext4_write_begin()
1216 if (ext4_should_dioread_nolock(inode)) in ext4_write_begin()
1222 if (!ret && ext4_should_journal_data(inode)) { in ext4_write_begin()
1229 bool extended = (pos + len > inode->i_size) && in ext4_write_begin()
1230 !ext4_verity_in_progress(inode); in ext4_write_begin()
1241 if (extended && ext4_can_truncate(inode)) in ext4_write_begin()
1242 ext4_orphan_add(handle, inode); in ext4_write_begin()
1246 ext4_truncate_failed_write(inode); in ext4_write_begin()
1253 if (inode->i_nlink) in ext4_write_begin()
1254 ext4_orphan_del(NULL, inode); in ext4_write_begin()
1258 ext4_should_retry_alloc(inode->i_sb, &retries)) in ext4_write_begin()
1293 struct inode *inode = mapping->host; in ext4_write_end() local
1294 loff_t old_size = inode->i_size; in ext4_write_end()
1297 int inline_data = ext4_has_inline_data(inode); in ext4_write_end()
1298 bool verity = ext4_verity_in_progress(inode); in ext4_write_end()
1300 trace_android_fs_datawrite_end(inode, pos, len); in ext4_write_end()
1301 trace_ext4_write_end(inode, pos, len, copied); in ext4_write_end()
1303 ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { in ext4_write_end()
1304 ret = ext4_write_inline_data_end(inode, pos, len, in ext4_write_end()
1324 i_size_changed = ext4_update_inode_size(inode, pos + copied); in ext4_write_end()
1329 pagecache_isize_extended(inode, old_size, pos); in ext4_write_end()
1337 ret = ext4_mark_inode_dirty(handle, inode); in ext4_write_end()
1340 if (pos + len > inode->i_size && !verity && ext4_can_truncate(inode)) in ext4_write_end()
1345 ext4_orphan_add(handle, inode); in ext4_write_end()
1351 if (pos + len > inode->i_size && !verity) { in ext4_write_end()
1352 ext4_truncate_failed_write(inode); in ext4_write_end()
1358 if (inode->i_nlink) in ext4_write_end()
1359 ext4_orphan_del(NULL, inode); in ext4_write_end()
1405 struct inode *inode = mapping->host; in ext4_journalled_write_end() local
1406 loff_t old_size = inode->i_size; in ext4_journalled_write_end()
1411 int inline_data = ext4_has_inline_data(inode); in ext4_journalled_write_end()
1412 bool verity = ext4_verity_in_progress(inode); in ext4_journalled_write_end()
1414 trace_android_fs_datawrite_end(inode, pos, len); in ext4_journalled_write_end()
1415 trace_ext4_journalled_write_end(inode, pos, len, copied); in ext4_journalled_write_end()
1422 ret = ext4_write_inline_data_end(inode, pos, len, in ext4_journalled_write_end()
1445 size_changed = ext4_update_inode_size(inode, pos + copied); in ext4_journalled_write_end()
1446 ext4_set_inode_state(inode, EXT4_STATE_JDATA); in ext4_journalled_write_end()
1447 EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid; in ext4_journalled_write_end()
1452 pagecache_isize_extended(inode, old_size, pos); in ext4_journalled_write_end()
1455 ret2 = ext4_mark_inode_dirty(handle, inode); in ext4_journalled_write_end()
1461 if (pos + len > inode->i_size && !verity && ext4_can_truncate(inode)) in ext4_journalled_write_end()
1466 ext4_orphan_add(handle, inode); in ext4_journalled_write_end()
1471 if (pos + len > inode->i_size && !verity) { in ext4_journalled_write_end()
1472 ext4_truncate_failed_write(inode); in ext4_journalled_write_end()
1478 if (inode->i_nlink) in ext4_journalled_write_end()
1479 ext4_orphan_del(NULL, inode); in ext4_journalled_write_end()
1488 static int ext4_da_reserve_space(struct inode *inode) in ext4_da_reserve_space() argument
1490 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_da_reserve_space()
1491 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_da_reserve_space()
1499 ret = dquot_reserve_block(inode, EXT4_C2B(sbi, 1)); in ext4_da_reserve_space()
1506 dquot_release_reservation_block(inode, EXT4_C2B(sbi, 1)); in ext4_da_reserve_space()
1510 trace_ext4_da_reserve_space(inode); in ext4_da_reserve_space()
1516 void ext4_da_release_space(struct inode *inode, int to_free) in ext4_da_release_space() argument
1518 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_da_release_space()
1519 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_da_release_space()
1524 spin_lock(&EXT4_I(inode)->i_block_reservation_lock); in ext4_da_release_space()
1526 trace_ext4_da_release_space(inode, to_free); in ext4_da_release_space()
1534 ext4_warning(inode->i_sb, "ext4_da_release_space: " in ext4_da_release_space()
1536 "data blocks", inode->i_ino, to_free, in ext4_da_release_space()
1546 spin_unlock(&EXT4_I(inode)->i_block_reservation_lock); in ext4_da_release_space()
1548 dquot_release_reservation_block(inode, EXT4_C2B(sbi, to_free)); in ext4_da_release_space()
1556 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()
1625 static void ext4_print_free_blocks(struct inode *inode) in ext4_print_free_blocks() argument
1627 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_print_free_blocks()
1628 struct super_block *sb = inode->i_sb; in ext4_print_free_blocks()
1629 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_print_free_blocks()
1632 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()
1682 ret = ext4_da_reserve_space(inode); in ext4_insert_delayed_block()
1687 if (!ext4_es_scan_clu(inode, &ext4_es_is_delonly, lblk)) { in ext4_insert_delayed_block()
1688 if (!ext4_es_scan_clu(inode, in ext4_insert_delayed_block()
1690 ret = ext4_clu_mapped(inode, in ext4_insert_delayed_block()
1695 ret = ext4_da_reserve_space(inode); in ext4_insert_delayed_block()
1708 ret = ext4_es_insert_delayed_block(inode, lblk, allocated); in ext4_insert_delayed_block()
1710 ext4_da_release_space(inode, 1); in ext4_insert_delayed_block()
1722 static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, in ext4_da_map_blocks() argument
1735 if (invalid_block < ext4_blocks_count(EXT4_SB(inode->i_sb)->s_es)) in ext4_da_map_blocks()
1739 ext_debug(inode, "max_blocks %u, logical block %lu\n", map->m_len, in ext4_da_map_blocks()
1743 if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { in ext4_da_map_blocks()
1752 map_bh(bh, inode->i_sb, invalid_block); in ext4_da_map_blocks()
1771 ext4_map_blocks_es_recheck(NULL, inode, map, &orig_map, 0); in ext4_da_map_blocks()
1780 down_read(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1781 if (ext4_has_inline_data(inode)) in ext4_da_map_blocks()
1783 else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_da_map_blocks()
1784 retval = ext4_ext_map_blocks(NULL, inode, map, 0); in ext4_da_map_blocks()
1786 retval = ext4_ind_map_blocks(NULL, inode, map, 0); in ext4_da_map_blocks()
1788 up_read(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1795 ext4_warning(inode->i_sb, in ext4_da_map_blocks()
1798 inode->i_ino, retval, map->m_len); in ext4_da_map_blocks()
1804 ext4_es_insert_extent(inode, map->m_lblk, map->m_len, in ext4_da_map_blocks()
1806 up_read(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1809 up_read(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1812 down_write(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1813 retval = ext4_insert_delayed_block(inode, map->m_lblk); in ext4_da_map_blocks()
1814 up_write(&EXT4_I(inode)->i_data_sem); in ext4_da_map_blocks()
1818 map_bh(bh, inode->i_sb, invalid_block); in ext4_da_map_blocks()
1836 int ext4_da_get_block_prep(struct inode *inode, sector_t iblock, in ext4_da_get_block_prep() argument
1843 BUG_ON(bh->b_size != inode->i_sb->s_blocksize); in ext4_da_get_block_prep()
1853 ret = ext4_da_map_blocks(inode, iblock, &map, bh); in ext4_da_get_block_prep()
1857 map_bh(bh, inode->i_sb, map.m_pblk); in ext4_da_get_block_prep()
1889 struct inode *inode = mapping->host; in __ext4_journalled_writepage() local
1893 int inline_data = ext4_has_inline_data(inode); in __ext4_journalled_writepage()
1900 BUG_ON(len > ext4_get_max_inline_size(inode)); in __ext4_journalled_writepage()
1901 inode_bh = ext4_journalled_write_inline_data(inode, len, page); in __ext4_journalled_writepage()
1921 handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, in __ext4_journalled_writepage()
1922 ext4_writepage_trans_blocks(inode)); in __ext4_journalled_writepage()
1940 ret = ext4_mark_inode_dirty(handle, inode); in __ext4_journalled_writepage()
1950 err = ext4_jbd2_inode_add_write(handle, inode, page_offset(page), len); in __ext4_journalled_writepage()
1953 EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid; in __ext4_journalled_writepage()
1958 ext4_set_inode_state(inode, EXT4_STATE_JDATA); in __ext4_journalled_writepage()
2017 struct inode *inode = page->mapping->host; in ext4_writepage() local
2021 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) { in ext4_writepage()
2022 inode->i_mapping->a_ops->invalidatepage(page, 0, PAGE_SIZE); in ext4_writepage()
2028 size = i_size_read(inode); in ext4_writepage()
2030 !ext4_verity_in_progress(inode)) in ext4_writepage()
2037 ext4_warning_inode(inode, in ext4_writepage()
2066 (inode->i_sb->s_blocksize == PAGE_SIZE)) { in ext4_writepage()
2080 if (PageChecked(page) && ext4_should_journal_data(inode)) in ext4_writepage()
2088 io_submit.io_end = ext4_init_io_end(inode, GFP_NOFS); in ext4_writepage()
2122 size = i_size_read(mpd->inode); in mpage_submit_page()
2124 !ext4_verity_in_progress(mpd->inode)) in mpage_submit_page()
2218 struct inode *inode = mpd->inode; in mpage_process_page_bufs() local
2220 ext4_lblk_t blocks = (i_size_read(inode) + i_blocksize(inode) - 1) in mpage_process_page_bufs()
2221 >> inode->i_blkbits; in mpage_process_page_bufs()
2223 if (ext4_verity_in_progress(inode)) in mpage_process_page_bufs()
2277 int blkbits = mpd->inode->i_blkbits; in mpage_process_page()
2344 struct inode *inode = mpd->inode; in mpage_map_and_submit_buffers() local
2345 int bpp_bits = PAGE_SHIFT - inode->i_blkbits; in mpage_map_and_submit_buffers()
2359 nr_pages = pagevec_lookup_range(&pvec, inode->i_mapping, in mpage_map_and_submit_buffers()
2393 struct inode *inode = mpd->inode; in mpage_map_one_extent() local
2398 trace_ext4_da_write_pages_extent(inode, map); in mpage_map_one_extent()
2417 dioread_nolock = ext4_should_dioread_nolock(inode); in mpage_map_one_extent()
2423 err = ext4_map_blocks(handle, inode, map, get_blocks_flags); in mpage_map_one_extent()
2432 ext4_set_io_unwritten_flag(inode, mpd->io_submit.io_end); in mpage_map_one_extent()
2463 struct inode *inode = mpd->inode; in mpage_map_and_submit_extent() local
2474 io_end_vec->offset = ((loff_t)map->m_lblk) << inode->i_blkbits; in mpage_map_and_submit_extent()
2478 struct super_block *sb = inode->i_sb; in mpage_map_and_submit_extent()
2498 inode->i_ino, in mpage_map_and_submit_extent()
2505 ext4_print_free_blocks(inode); in mpage_map_and_submit_extent()
2526 if (disksize > READ_ONCE(EXT4_I(inode)->i_disksize)) { in mpage_map_and_submit_extent()
2530 down_write(&EXT4_I(inode)->i_data_sem); in mpage_map_and_submit_extent()
2531 i_size = i_size_read(inode); in mpage_map_and_submit_extent()
2534 if (disksize > EXT4_I(inode)->i_disksize) in mpage_map_and_submit_extent()
2535 EXT4_I(inode)->i_disksize = disksize; in mpage_map_and_submit_extent()
2536 up_write(&EXT4_I(inode)->i_data_sem); in mpage_map_and_submit_extent()
2537 err2 = ext4_mark_inode_dirty(handle, inode); in mpage_map_and_submit_extent()
2539 ext4_error_err(inode->i_sb, -err2, in mpage_map_and_submit_extent()
2541 inode->i_ino); in mpage_map_and_submit_extent()
2556 static int ext4_da_writepages_trans_blocks(struct inode *inode) in ext4_da_writepages_trans_blocks() argument
2558 int bpp = ext4_journal_blocks_per_page(inode); in ext4_da_writepages_trans_blocks()
2560 return ext4_meta_trans_blocks(inode, in ext4_da_writepages_trans_blocks()
2584 struct address_space *mapping = mpd->inode->i_mapping; in mpage_prepare_extent_to_map()
2592 int blkbits = mpd->inode->i_blkbits; in mpage_prepare_extent_to_map()
2657 ext4_warning_inode(mpd->inode, "page %lu does not have buffers attached", page->index); in mpage_prepare_extent_to_map()
2695 struct inode *inode = mapping->host; in ext4_writepages() local
2701 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) in ext4_writepages()
2705 trace_ext4_writepages(inode, wbc); in ext4_writepages()
2715 if (ext4_should_journal_data(inode)) { in ext4_writepages()
2731 ext4_test_mount_flag(inode->i_sb, EXT4_MF_FS_ABORTED))) { in ext4_writepages()
2741 if (ext4_has_inline_data(inode)) { in ext4_writepages()
2743 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1); in ext4_writepages()
2748 BUG_ON(ext4_test_inode_state(inode, in ext4_writepages()
2750 ext4_destroy_inline_data(handle, inode); in ext4_writepages()
2754 if (ext4_should_dioread_nolock(inode)) { in ext4_writepages()
2759 rsv_blocks = 1 + ext4_chunk_trans_blocks(inode, in ext4_writepages()
2760 PAGE_SIZE >> inode->i_blkbits); in ext4_writepages()
2777 mpd.inode = inode; in ext4_writepages()
2793 mpd.io_submit.io_end = ext4_init_io_end(inode, GFP_KERNEL); in ext4_writepages()
2810 mpd.io_submit.io_end = ext4_init_io_end(inode, GFP_KERNEL); in ext4_writepages()
2823 BUG_ON(ext4_should_journal_data(inode)); in ext4_writepages()
2824 needed_blocks = ext4_da_writepages_trans_blocks(inode); in ext4_writepages()
2827 handle = ext4_journal_start_with_reserve(inode, in ext4_writepages()
2831 ext4_msg(inode->i_sb, KERN_CRIT, "%s: jbd2_start: " in ext4_writepages()
2833 wbc->nr_to_write, inode->i_ino, ret); in ext4_writepages()
2841 trace_ext4_da_write_pages(inode, mpd.first_page, mpd.wbc); in ext4_writepages()
2912 trace_ext4_writepages_result(inode, wbc, ret, in ext4_writepages()
2923 struct inode *inode = mapping->host; in ext4_dax_writepages() local
2926 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) in ext4_dax_writepages()
2930 trace_ext4_writepages(inode, wbc); in ext4_dax_writepages()
2933 trace_ext4_writepages_result(inode, wbc, ret, in ext4_dax_writepages()
2974 static int ext4_da_write_credits(struct inode *inode, loff_t pos, unsigned len) in ext4_da_write_credits() argument
2976 if (likely(ext4_has_feature_large_file(inode->i_sb))) in ext4_da_write_credits()
2993 struct inode *inode = mapping->host; in ext4_da_write_begin() local
2996 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) in ext4_da_write_begin()
3001 if (ext4_nonda_switch(inode->i_sb) || S_ISLNK(inode->i_mode) || in ext4_da_write_begin()
3002 ext4_verity_in_progress(inode)) { in ext4_da_write_begin()
3013 inode); in ext4_da_write_begin()
3014 trace_android_fs_datawrite_start(inode, pos, len, in ext4_da_write_begin()
3018 trace_ext4_da_write_begin(inode, pos, len, flags); in ext4_da_write_begin()
3020 if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { in ext4_da_write_begin()
3021 ret = ext4_da_write_inline_data_begin(mapping, inode, in ext4_da_write_begin()
3050 handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, in ext4_da_write_begin()
3051 ext4_da_write_credits(inode, pos, len)); in ext4_da_write_begin()
3082 if (pos + len > inode->i_size) in ext4_da_write_begin()
3083 ext4_truncate_failed_write(inode); in ext4_da_write_begin()
3086 ext4_should_retry_alloc(inode->i_sb, &retries)) in ext4_da_write_begin()
3105 struct inode *inode = page->mapping->host; in ext4_da_should_update_i_disksize() local
3110 idx = offset >> inode->i_blkbits; in ext4_da_should_update_i_disksize()
3125 struct inode *inode = mapping->host; in ext4_da_write_end() local
3136 trace_android_fs_datawrite_end(inode, pos, len); in ext4_da_write_end()
3137 trace_ext4_da_write_end(inode, pos, len, copied); in ext4_da_write_end()
3157 if (copied && new_i_size > inode->i_size) { in ext4_da_write_end()
3158 if (ext4_has_inline_data(inode) || in ext4_da_write_end()
3160 ext4_update_i_disksize(inode, new_i_size); in ext4_da_write_end()
3164 ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA) && in ext4_da_write_end()
3165 ext4_has_inline_data(inode)) in ext4_da_write_end()
3166 ret = ext4_da_write_inline_data_end(inode, pos, len, copied, in ext4_da_write_end()
3183 int ext4_alloc_da_blocks(struct inode *inode) in ext4_alloc_da_blocks() argument
3185 trace_ext4_alloc_da_blocks(inode); in ext4_alloc_da_blocks()
3187 if (!EXT4_I(inode)->i_reserved_data_blocks) in ext4_alloc_da_blocks()
3221 return filemap_flush(inode->i_mapping); in ext4_alloc_da_blocks()
3240 struct inode *inode = mapping->host; in ext4_bmap() local
3245 inode_lock_shared(inode); in ext4_bmap()
3249 if (ext4_has_inline_data(inode)) in ext4_bmap()
3253 test_opt(inode->i_sb, DELALLOC)) { in ext4_bmap()
3262 if (EXT4_JOURNAL(inode) && in ext4_bmap()
3263 ext4_test_inode_state(inode, EXT4_STATE_JDATA)) { in ext4_bmap()
3282 ext4_clear_inode_state(inode, EXT4_STATE_JDATA); in ext4_bmap()
3283 journal = EXT4_JOURNAL(inode); in ext4_bmap()
3295 inode_unlock_shared(inode); in ext4_bmap()
3302 struct inode *inode = page->mapping->host; in ext4_readpage() local
3306 if (ext4_has_inline_data(inode)) in ext4_readpage()
3307 ret = ext4_readpage_inline(inode, page); in ext4_readpage()
3310 return ext4_mpage_readpages(inode, NULL, page); in ext4_readpage()
3317 struct inode *inode = rac->mapping->host; in ext4_readahead() local
3320 if (ext4_has_inline_data(inode)) in ext4_readahead()
3323 ext4_mpage_readpages(inode, rac, NULL); in ext4_readahead()
3377 static bool ext4_inode_datasync_dirty(struct inode *inode) in ext4_inode_datasync_dirty() argument
3379 journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; in ext4_inode_datasync_dirty()
3383 EXT4_I(inode)->i_datasync_tid)) in ext4_inode_datasync_dirty()
3385 if (test_opt2(inode->i_sb, JOURNAL_FAST_COMMIT)) in ext4_inode_datasync_dirty()
3386 return !list_empty(&EXT4_I(inode)->i_fc_list); in ext4_inode_datasync_dirty()
3391 if (!list_empty(&inode->i_mapping->private_list)) in ext4_inode_datasync_dirty()
3393 return inode->i_state & I_DIRTY_DATASYNC; in ext4_inode_datasync_dirty()
3396 static void ext4_set_iomap(struct inode *inode, struct iomap *iomap, in ext4_set_iomap() argument
3400 u8 blkbits = inode->i_blkbits; in ext4_set_iomap()
3408 if (ext4_inode_datasync_dirty(inode) || in ext4_set_iomap()
3409 offset + length > i_size_read(inode)) in ext4_set_iomap()
3415 iomap->bdev = inode->i_sb->s_bdev; in ext4_set_iomap()
3416 iomap->dax_dev = EXT4_SB(inode->i_sb)->s_daxdev; in ext4_set_iomap()
3421 !ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_set_iomap()
3445 static int ext4_iomap_alloc(struct inode *inode, struct ext4_map_blocks *map, in ext4_iomap_alloc() argument
3449 u8 blkbits = inode->i_blkbits; in ext4_iomap_alloc()
3458 dio_credits = ext4_chunk_trans_blocks(inode, map->m_len); in ext4_iomap_alloc()
3467 handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, dio_credits); in ext4_iomap_alloc()
3475 WARN_ON(!IS_DAX(inode) && !(flags & IOMAP_DIRECT)); in ext4_iomap_alloc()
3476 if (IS_DAX(inode)) in ext4_iomap_alloc()
3484 else if (((loff_t)map->m_lblk << blkbits) >= i_size_read(inode)) in ext4_iomap_alloc()
3486 else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_iomap_alloc()
3489 ret = ext4_map_blocks(handle, inode, map, m_flags); in ext4_iomap_alloc()
3500 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) in ext4_iomap_alloc()
3507 static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, in ext4_iomap_begin() argument
3512 u8 blkbits = inode->i_blkbits; in ext4_iomap_begin()
3517 if (WARN_ON_ONCE(ext4_has_inline_data(inode))) in ext4_iomap_begin()
3534 if (offset + length <= i_size_read(inode)) { in ext4_iomap_begin()
3535 ret = ext4_map_blocks(NULL, inode, &map, 0); in ext4_iomap_begin()
3539 ret = ext4_iomap_alloc(inode, &map, flags); in ext4_iomap_begin()
3541 ret = ext4_map_blocks(NULL, inode, &map, 0); in ext4_iomap_begin()
3553 map.m_len = fscrypt_limit_io_blocks(inode, map.m_lblk, map.m_len); in ext4_iomap_begin()
3555 ext4_set_iomap(inode, iomap, &map, offset, length); in ext4_iomap_begin()
3560 static int ext4_iomap_overwrite_begin(struct inode *inode, loff_t offset, in ext4_iomap_overwrite_begin() argument
3571 ret = ext4_iomap_begin(inode, offset, length, flags, iomap, srcmap); in ext4_iomap_overwrite_begin()
3576 static int ext4_iomap_end(struct inode *inode, loff_t offset, loff_t length, in ext4_iomap_end() argument
3602 static bool ext4_iomap_is_delalloc(struct inode *inode, in ext4_iomap_is_delalloc() argument
3608 ext4_es_find_extent_range(inode, &ext4_es_is_delayed, in ext4_iomap_is_delalloc()
3625 static int ext4_iomap_begin_report(struct inode *inode, loff_t offset, in ext4_iomap_begin_report() argument
3632 u8 blkbits = inode->i_blkbits; in ext4_iomap_begin_report()
3637 if (ext4_has_inline_data(inode)) { in ext4_iomap_begin_report()
3638 ret = ext4_inline_data_iomap(inode, iomap); in ext4_iomap_begin_report()
3659 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { in ext4_iomap_begin_report()
3660 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_iomap_begin_report()
3668 ret = ext4_map_blocks(NULL, inode, &map, 0); in ext4_iomap_begin_report()
3672 delalloc = ext4_iomap_is_delalloc(inode, &map); in ext4_iomap_begin_report()
3675 ext4_set_iomap(inode, iomap, &map, offset, length); in ext4_iomap_begin_report()
3781 void ext4_set_aops(struct inode *inode) in ext4_set_aops() argument
3783 switch (ext4_inode_journal_mode(inode)) { in ext4_set_aops()
3788 inode->i_mapping->a_ops = &ext4_journalled_aops; in ext4_set_aops()
3793 if (IS_DAX(inode)) in ext4_set_aops()
3794 inode->i_mapping->a_ops = &ext4_dax_aops; in ext4_set_aops()
3795 else if (test_opt(inode->i_sb, DELALLOC)) in ext4_set_aops()
3796 inode->i_mapping->a_ops = &ext4_da_aops; in ext4_set_aops()
3798 inode->i_mapping->a_ops = &ext4_aops; in ext4_set_aops()
3808 struct inode *inode = mapping->host; in __ext4_block_zero_page_range() local
3818 blocksize = inode->i_sb->s_blocksize; in __ext4_block_zero_page_range()
3820 iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits); in __ext4_block_zero_page_range()
3839 ext4_get_block(inode, iblock, bh, 0); in __ext4_block_zero_page_range()
3855 if (fscrypt_inode_uses_fs_layer_crypto(inode)) { in __ext4_block_zero_page_range()
3857 BUG_ON(!fscrypt_has_encryption_key(inode)); in __ext4_block_zero_page_range()
3866 if (ext4_should_journal_data(inode)) { in __ext4_block_zero_page_range()
3875 if (ext4_should_journal_data(inode)) { in __ext4_block_zero_page_range()
3876 err = ext4_handle_dirty_metadata(handle, inode, bh); in __ext4_block_zero_page_range()
3880 if (ext4_should_order_data(inode)) in __ext4_block_zero_page_range()
3881 err = ext4_jbd2_inode_add_write(handle, inode, from, in __ext4_block_zero_page_range()
3901 struct inode *inode = mapping->host; in ext4_block_zero_page_range() local
3903 unsigned blocksize = inode->i_sb->s_blocksize; in ext4_block_zero_page_range()
3913 if (IS_DAX(inode)) { in ext4_block_zero_page_range()
3914 return iomap_zero_range(inode, from, length, NULL, in ext4_block_zero_page_range()
3932 struct inode *inode = mapping->host; in ext4_block_truncate_page() local
3935 if (IS_ENCRYPTED(inode) && !fscrypt_has_encryption_key(inode)) in ext4_block_truncate_page()
3938 blocksize = inode->i_sb->s_blocksize; in ext4_block_truncate_page()
3944 int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode, in ext4_zero_partial_blocks() argument
3947 struct super_block *sb = inode->i_sb; in ext4_zero_partial_blocks()
3948 struct address_space *mapping = inode->i_mapping; in ext4_zero_partial_blocks()
3982 int ext4_can_truncate(struct inode *inode) in ext4_can_truncate() argument
3984 if (S_ISREG(inode->i_mode)) in ext4_can_truncate()
3986 if (S_ISDIR(inode->i_mode)) in ext4_can_truncate()
3988 if (S_ISLNK(inode->i_mode)) in ext4_can_truncate()
3989 return !ext4_inode_is_fast_symlink(inode); in ext4_can_truncate()
3999 int ext4_update_disksize_before_punch(struct inode *inode, loff_t offset, in ext4_update_disksize_before_punch() argument
4005 loff_t size = i_size_read(inode); in ext4_update_disksize_before_punch()
4007 WARN_ON(!inode_is_locked(inode)); in ext4_update_disksize_before_punch()
4011 if (EXT4_I(inode)->i_disksize >= size) in ext4_update_disksize_before_punch()
4014 handle = ext4_journal_start(inode, EXT4_HT_MISC, 1); in ext4_update_disksize_before_punch()
4017 ext4_update_i_disksize(inode, size); in ext4_update_disksize_before_punch()
4018 ret = ext4_mark_inode_dirty(handle, inode); in ext4_update_disksize_before_punch()
4031 int ext4_break_layouts(struct inode *inode) in ext4_break_layouts() argument
4033 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_break_layouts()
4041 page = dax_layout_busy_page(inode->i_mapping); in ext4_break_layouts()
4067 struct inode *inode = file_inode(file); in ext4_punch_hole() local
4068 struct super_block *sb = inode->i_sb; in ext4_punch_hole()
4070 struct address_space *mapping = inode->i_mapping; in ext4_punch_hole()
4072 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_punch_hole()
4077 trace_ext4_punch_hole(inode, offset, length, 0); in ext4_punch_hole()
4090 inode_lock(inode); in ext4_punch_hole()
4093 if (offset >= inode->i_size) in ext4_punch_hole()
4100 if (offset + length > inode->i_size) { in ext4_punch_hole()
4101 length = inode->i_size + in ext4_punch_hole()
4102 PAGE_SIZE - (inode->i_size & (PAGE_SIZE - 1)) - in ext4_punch_hole()
4110 max_length = sbi->s_bitmap_maxbytes - inode->i_sb->s_blocksize; in ext4_punch_hole()
4120 ret = ext4_inode_attach_jinode(inode); in ext4_punch_hole()
4127 inode_dio_wait(inode); in ext4_punch_hole()
4137 down_write(&EXT4_I(inode)->i_mmap_sem); in ext4_punch_hole()
4139 ret = ext4_break_layouts(inode); in ext4_punch_hole()
4148 ret = ext4_update_disksize_before_punch(inode, offset, length); in ext4_punch_hole()
4151 truncate_pagecache_range(inode, first_block_offset, in ext4_punch_hole()
4155 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_punch_hole()
4156 credits = ext4_writepage_trans_blocks(inode); in ext4_punch_hole()
4158 credits = ext4_blocks_for_truncate(inode); in ext4_punch_hole()
4159 handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits); in ext4_punch_hole()
4166 ret = ext4_zero_partial_blocks(handle, inode, offset, in ext4_punch_hole()
4178 down_write(&EXT4_I(inode)->i_data_sem); in ext4_punch_hole()
4179 ext4_discard_preallocations(inode, 0); in ext4_punch_hole()
4181 ret = ext4_es_remove_extent(inode, first_block, in ext4_punch_hole()
4184 up_write(&EXT4_I(inode)->i_data_sem); in ext4_punch_hole()
4188 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_punch_hole()
4189 ret = ext4_ext_remove_space(inode, first_block, in ext4_punch_hole()
4192 ret = ext4_ind_remove_space(handle, inode, first_block, in ext4_punch_hole()
4195 up_write(&EXT4_I(inode)->i_data_sem); in ext4_punch_hole()
4197 ext4_fc_track_range(handle, inode, first_block, stop_block); in ext4_punch_hole()
4198 if (IS_SYNC(inode)) in ext4_punch_hole()
4201 inode->i_mtime = inode->i_ctime = current_time(inode); in ext4_punch_hole()
4202 ret2 = ext4_mark_inode_dirty(handle, inode); in ext4_punch_hole()
4206 ext4_update_inode_fsync_trans(handle, inode, 1); in ext4_punch_hole()
4210 up_write(&EXT4_I(inode)->i_mmap_sem); in ext4_punch_hole()
4212 inode_unlock(inode); in ext4_punch_hole()
4216 int ext4_inode_attach_jinode(struct inode *inode) in ext4_inode_attach_jinode() argument
4218 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_inode_attach_jinode()
4221 if (ei->jinode || !EXT4_SB(inode->i_sb)->s_journal) in ext4_inode_attach_jinode()
4225 spin_lock(&inode->i_lock); in ext4_inode_attach_jinode()
4228 spin_unlock(&inode->i_lock); in ext4_inode_attach_jinode()
4232 jbd2_journal_init_jbd_inode(ei->jinode, inode); in ext4_inode_attach_jinode()
4235 spin_unlock(&inode->i_lock); in ext4_inode_attach_jinode()
4269 int ext4_truncate(struct inode *inode) in ext4_truncate() argument
4271 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_truncate()
4275 struct address_space *mapping = inode->i_mapping; in ext4_truncate()
4282 if (!(inode->i_state & (I_NEW|I_FREEING))) in ext4_truncate()
4283 WARN_ON(!inode_is_locked(inode)); in ext4_truncate()
4284 trace_ext4_truncate_enter(inode); in ext4_truncate()
4286 if (!ext4_can_truncate(inode)) in ext4_truncate()
4289 if (inode->i_size == 0 && !test_opt(inode->i_sb, NO_AUTO_DA_ALLOC)) in ext4_truncate()
4290 ext4_set_inode_state(inode, EXT4_STATE_DA_ALLOC_CLOSE); in ext4_truncate()
4292 if (ext4_has_inline_data(inode)) { in ext4_truncate()
4295 err = ext4_inline_data_truncate(inode, &has_inline); in ext4_truncate()
4301 if (inode->i_size & (inode->i_sb->s_blocksize - 1)) { in ext4_truncate()
4302 err = ext4_inode_attach_jinode(inode); in ext4_truncate()
4307 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_truncate()
4308 credits = ext4_writepage_trans_blocks(inode); in ext4_truncate()
4310 credits = ext4_blocks_for_truncate(inode); in ext4_truncate()
4312 handle = ext4_journal_start(inode, EXT4_HT_TRUNCATE, credits); in ext4_truncate()
4318 if (inode->i_size & (inode->i_sb->s_blocksize - 1)) in ext4_truncate()
4319 ext4_block_truncate_page(handle, mapping, inode->i_size); in ext4_truncate()
4330 err = ext4_orphan_add(handle, inode); in ext4_truncate()
4334 down_write(&EXT4_I(inode)->i_data_sem); in ext4_truncate()
4336 ext4_discard_preallocations(inode, 0); in ext4_truncate()
4338 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in ext4_truncate()
4339 err = ext4_ext_truncate(handle, inode); in ext4_truncate()
4341 ext4_ind_truncate(handle, inode); in ext4_truncate()
4347 if (IS_SYNC(inode)) in ext4_truncate()
4358 if (inode->i_nlink) in ext4_truncate()
4359 ext4_orphan_del(handle, inode); in ext4_truncate()
4361 inode->i_mtime = inode->i_ctime = current_time(inode); in ext4_truncate()
4362 err2 = ext4_mark_inode_dirty(handle, inode); in ext4_truncate()
4368 trace_ext4_truncate_exit(inode); in ext4_truncate()
4519 static int __ext4_get_inode_loc_noinmem(struct inode *inode, in __ext4_get_inode_loc_noinmem() argument
4525 ret = __ext4_get_inode_loc(inode->i_sb, inode->i_ino, iloc, 0, in __ext4_get_inode_loc_noinmem()
4529 ext4_error_inode_block(inode, err_blk, EIO, in __ext4_get_inode_loc_noinmem()
4535 int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc) in ext4_get_inode_loc() argument
4541 ret = __ext4_get_inode_loc(inode->i_sb, inode->i_ino, iloc, in ext4_get_inode_loc()
4542 !ext4_test_inode_state(inode, EXT4_STATE_XATTR), &err_blk); in ext4_get_inode_loc()
4545 ext4_error_inode_block(inode, err_blk, EIO, in ext4_get_inode_loc()
4558 static bool ext4_should_enable_dax(struct inode *inode) in ext4_should_enable_dax() argument
4560 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_should_enable_dax()
4562 if (test_opt2(inode->i_sb, DAX_NEVER)) in ext4_should_enable_dax()
4564 if (!S_ISREG(inode->i_mode)) in ext4_should_enable_dax()
4566 if (ext4_should_journal_data(inode)) in ext4_should_enable_dax()
4568 if (ext4_has_inline_data(inode)) in ext4_should_enable_dax()
4570 if (ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT)) in ext4_should_enable_dax()
4572 if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY)) in ext4_should_enable_dax()
4576 if (test_opt(inode->i_sb, DAX_ALWAYS)) in ext4_should_enable_dax()
4579 return ext4_test_inode_flag(inode, EXT4_INODE_DAX); in ext4_should_enable_dax()
4582 void ext4_set_inode_flags(struct inode *inode, bool init) in ext4_set_inode_flags() argument
4584 unsigned int flags = EXT4_I(inode)->i_flags; in ext4_set_inode_flags()
4587 WARN_ON_ONCE(IS_DAX(inode) && init); in ext4_set_inode_flags()
4602 new_fl |= (inode->i_flags & S_DAX); in ext4_set_inode_flags()
4603 if (init && ext4_should_enable_dax(inode)) in ext4_set_inode_flags()
4612 inode_set_flags(inode, new_fl, in ext4_set_inode_flags()
4621 struct inode *inode = &(ei->vfs_inode); in ext4_inode_blocks() local
4622 struct super_block *sb = inode->i_sb; in ext4_inode_blocks()
4628 if (ext4_test_inode_flag(inode, EXT4_INODE_HUGE_FILE)) { in ext4_inode_blocks()
4630 return i_blocks << (inode->i_blkbits - 9); in ext4_inode_blocks()
4639 static inline int ext4_iget_extra_inode(struct inode *inode, in ext4_iget_extra_inode() argument
4646 if (EXT4_INODE_HAS_XATTR_SPACE(inode) && in ext4_iget_extra_inode()
4650 ext4_set_inode_state(inode, EXT4_STATE_XATTR); in ext4_iget_extra_inode()
4651 err = ext4_find_inline_data_nolock(inode); in ext4_iget_extra_inode()
4652 if (!err && ext4_has_inline_data(inode)) in ext4_iget_extra_inode()
4653 ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA); in ext4_iget_extra_inode()
4656 EXT4_I(inode)->i_inline_off = 0; in ext4_iget_extra_inode()
4660 int ext4_get_projid(struct inode *inode, kprojid_t *projid) in ext4_get_projid() argument
4662 if (!ext4_has_feature_project(inode->i_sb)) in ext4_get_projid()
4664 *projid = EXT4_I(inode)->i_projid; in ext4_get_projid()
4673 static inline void ext4_inode_set_iversion_queried(struct inode *inode, u64 val) in ext4_inode_set_iversion_queried() argument
4675 if (unlikely(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) in ext4_inode_set_iversion_queried()
4676 inode_set_iversion_raw(inode, val); in ext4_inode_set_iversion_queried()
4678 inode_set_iversion_queried(inode, val); in ext4_inode_set_iversion_queried()
4680 static inline u64 ext4_inode_peek_iversion(const struct inode *inode) in ext4_inode_peek_iversion() argument
4682 if (unlikely(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) in ext4_inode_peek_iversion()
4683 return inode_peek_iversion_raw(inode); in ext4_inode_peek_iversion()
4685 return inode_peek_iversion(inode); in ext4_inode_peek_iversion()
4688 static const char *check_igot_inode(struct inode *inode, ext4_iget_flags flags) in check_igot_inode() argument
4692 if (!(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) in check_igot_inode()
4694 if (ext4_test_inode_state(inode, EXT4_STATE_XATTR) || in check_igot_inode()
4695 EXT4_I(inode)->i_file_acl) in check_igot_inode()
4698 if ((EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) in check_igot_inode()
4701 if (is_bad_inode(inode) && !(flags & EXT4_IGET_BAD)) in check_igot_inode()
4706 struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, in __ext4_iget()
4713 struct inode *inode; in __ext4_iget() local
4735 inode = iget_locked(sb, ino); in __ext4_iget()
4736 if (!inode) in __ext4_iget()
4738 if (!(inode->i_state & I_NEW)) { in __ext4_iget()
4739 if ((err_str = check_igot_inode(inode, flags)) != NULL) { in __ext4_iget()
4740 ext4_error_inode(inode, function, line, 0, err_str); in __ext4_iget()
4741 iput(inode); in __ext4_iget()
4744 return inode; in __ext4_iget()
4747 ei = EXT4_I(inode); in __ext4_iget()
4750 ret = __ext4_get_inode_loc_noinmem(inode, &iloc); in __ext4_iget()
4761 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { in __ext4_iget()
4764 EXT4_INODE_SIZE(inode->i_sb) || in __ext4_iget()
4766 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4770 EXT4_INODE_SIZE(inode->i_sb)); in __ext4_iget()
4779 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in __ext4_iget()
4781 __le32 inum = cpu_to_le32(inode->i_ino); in __ext4_iget()
4789 if ((!ext4_inode_csum_verify(inode, raw_inode, ei) || in __ext4_iget()
4792 ext4_error_inode_err(inode, function, line, 0, in __ext4_iget()
4798 inode->i_mode = le16_to_cpu(raw_inode->i_mode); in __ext4_iget()
4808 if (!(test_opt(inode->i_sb, NO_UID32))) { in __ext4_iget()
4812 i_uid_write(inode, i_uid); in __ext4_iget()
4813 i_gid_write(inode, i_gid); in __ext4_iget()
4815 set_nlink(inode, le16_to_cpu(raw_inode->i_links_count)); in __ext4_iget()
4826 if (inode->i_nlink == 0) { in __ext4_iget()
4827 if ((inode->i_mode == 0 || flags & EXT4_IGET_SPECIAL || in __ext4_iget()
4828 !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS)) && in __ext4_iget()
4832 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4847 ext4_set_inode_flags(inode, true); in __ext4_iget()
4848 inode->i_blocks = ext4_inode_blocks(raw_inode, ei); in __ext4_iget()
4853 inode->i_size = ext4_isize(sb, raw_inode); in __ext4_iget()
4854 if ((size = i_size_read(inode)) < 0) { in __ext4_iget()
4855 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4866 ext4_test_inode_flag(inode, EXT4_INODE_INDEX)) { in __ext4_iget()
4867 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4872 ei->i_disksize = inode->i_size; in __ext4_iget()
4876 inode->i_generation = le32_to_cpu(raw_inode->i_generation); in __ext4_iget()
4913 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { in __ext4_iget()
4920 ret = ext4_iget_extra_inode(inode, raw_inode, ei); in __ext4_iget()
4926 EXT4_INODE_GET_XTIME(i_ctime, inode, raw_inode); in __ext4_iget()
4927 EXT4_INODE_GET_XTIME(i_mtime, inode, raw_inode); in __ext4_iget()
4928 EXT4_INODE_GET_XTIME(i_atime, inode, raw_inode); in __ext4_iget()
4931 if (likely(!test_opt2(inode->i_sb, HURD_COMPAT))) { in __ext4_iget()
4934 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE) { in __ext4_iget()
4939 ext4_inode_set_iversion_queried(inode, ivers); in __ext4_iget()
4944 !ext4_inode_block_valid(inode, ei->i_file_acl, 1)) { in __ext4_iget()
4945 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4950 } else if (!ext4_has_inline_data(inode)) { in __ext4_iget()
4953 (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || in __ext4_iget()
4954 (S_ISLNK(inode->i_mode) && in __ext4_iget()
4955 !ext4_inode_is_fast_symlink(inode)))) { in __ext4_iget()
4956 if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) in __ext4_iget()
4957 ret = ext4_ext_check_inode(inode); in __ext4_iget()
4959 ret = ext4_ind_check_inode(inode); in __ext4_iget()
4965 if (S_ISREG(inode->i_mode)) { in __ext4_iget()
4966 inode->i_op = &ext4_file_inode_operations; in __ext4_iget()
4967 inode->i_fop = &ext4_file_operations; in __ext4_iget()
4968 ext4_set_aops(inode); in __ext4_iget()
4969 } else if (S_ISDIR(inode->i_mode)) { in __ext4_iget()
4970 inode->i_op = &ext4_dir_inode_operations; in __ext4_iget()
4971 inode->i_fop = &ext4_dir_operations; in __ext4_iget()
4972 } else if (S_ISLNK(inode->i_mode)) { in __ext4_iget()
4974 if (IS_APPEND(inode) || IS_IMMUTABLE(inode)) { in __ext4_iget()
4975 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
4981 if (IS_ENCRYPTED(inode)) { in __ext4_iget()
4982 inode->i_op = &ext4_encrypted_symlink_inode_operations; in __ext4_iget()
4983 ext4_set_aops(inode); in __ext4_iget()
4984 } else if (ext4_inode_is_fast_symlink(inode)) { in __ext4_iget()
4985 inode->i_link = (char *)ei->i_data; in __ext4_iget()
4986 inode->i_op = &ext4_fast_symlink_inode_operations; in __ext4_iget()
4987 nd_terminate_link(ei->i_data, inode->i_size, in __ext4_iget()
4990 inode->i_op = &ext4_symlink_inode_operations; in __ext4_iget()
4991 ext4_set_aops(inode); in __ext4_iget()
4993 inode_nohighmem(inode); in __ext4_iget()
4994 } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || in __ext4_iget()
4995 S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) { in __ext4_iget()
4996 inode->i_op = &ext4_special_inode_operations; in __ext4_iget()
4998 init_special_inode(inode, inode->i_mode, in __ext4_iget()
5001 init_special_inode(inode, inode->i_mode, in __ext4_iget()
5004 make_bad_inode(inode); in __ext4_iget()
5007 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
5008 "iget: bogus i_mode (%o)", inode->i_mode); in __ext4_iget()
5011 if (IS_CASEFOLDED(inode) && !ext4_has_feature_casefold(inode->i_sb)) in __ext4_iget()
5012 ext4_error_inode(inode, function, line, 0, in __ext4_iget()
5014 if ((err_str = check_igot_inode(inode, flags)) != NULL) { in __ext4_iget()
5015 ext4_error_inode(inode, function, line, 0, err_str); in __ext4_iget()
5021 unlock_new_inode(inode); in __ext4_iget()
5022 return inode; in __ext4_iget()
5026 iget_failed(inode); in __ext4_iget()
5034 struct inode *inode = &(ei->vfs_inode); in ext4_inode_blocks_set() local
5035 u64 i_blocks = READ_ONCE(inode->i_blocks); in ext4_inode_blocks_set()
5036 struct super_block *sb = inode->i_sb; in ext4_inode_blocks_set()
5045 ext4_clear_inode_flag(inode, EXT4_INODE_HUGE_FILE); in ext4_inode_blocks_set()
5058 ext4_clear_inode_flag(inode, EXT4_INODE_HUGE_FILE); in ext4_inode_blocks_set()
5060 ext4_set_inode_flag(inode, EXT4_INODE_HUGE_FILE); in ext4_inode_blocks_set()
5062 i_blocks = i_blocks >> (inode->i_blkbits - 9); in ext4_inode_blocks_set()
5074 struct inode *inode; in __ext4_update_other_inode_time() local
5076 inode = find_inode_by_ino_rcu(sb, ino); in __ext4_update_other_inode_time()
5077 if (!inode) in __ext4_update_other_inode_time()
5080 if ((inode->i_state & (I_FREEING | I_WILL_FREE | I_NEW | in __ext4_update_other_inode_time()
5082 ((inode->i_state & I_DIRTY_TIME) == 0)) in __ext4_update_other_inode_time()
5085 spin_lock(&inode->i_lock); in __ext4_update_other_inode_time()
5086 if (((inode->i_state & (I_FREEING | I_WILL_FREE | I_NEW | in __ext4_update_other_inode_time()
5088 (inode->i_state & I_DIRTY_TIME)) { in __ext4_update_other_inode_time()
5089 struct ext4_inode_info *ei = EXT4_I(inode); in __ext4_update_other_inode_time()
5091 inode->i_state &= ~I_DIRTY_TIME; in __ext4_update_other_inode_time()
5092 spin_unlock(&inode->i_lock); in __ext4_update_other_inode_time()
5095 EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode); in __ext4_update_other_inode_time()
5096 EXT4_INODE_SET_XTIME(i_mtime, inode, raw_inode); in __ext4_update_other_inode_time()
5097 EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode); in __ext4_update_other_inode_time()
5098 ext4_inode_csum_set(inode, raw_inode, ei); in __ext4_update_other_inode_time()
5100 trace_ext4_other_inode_update_time(inode, orig_ino); in __ext4_update_other_inode_time()
5103 spin_unlock(&inode->i_lock); in __ext4_update_other_inode_time()
5141 struct inode *inode, in ext4_do_update_inode() argument
5145 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_do_update_inode()
5147 struct super_block *sb = inode->i_sb; in ext4_do_update_inode()
5158 if (ext4_test_inode_state(inode, EXT4_STATE_NEW)) in ext4_do_update_inode()
5159 memset(raw_inode, 0, EXT4_SB(inode->i_sb)->s_inode_size); in ext4_do_update_inode()
5167 raw_inode->i_mode = cpu_to_le16(inode->i_mode); in ext4_do_update_inode()
5168 i_uid = i_uid_read(inode); in ext4_do_update_inode()
5169 i_gid = i_gid_read(inode); in ext4_do_update_inode()
5171 if (!(test_opt(inode->i_sb, NO_UID32))) { in ext4_do_update_inode()
5193 raw_inode->i_links_count = cpu_to_le16(inode->i_nlink); in ext4_do_update_inode()
5195 EXT4_INODE_SET_XTIME(i_ctime, inode, raw_inode); in ext4_do_update_inode()
5196 EXT4_INODE_SET_XTIME(i_mtime, inode, raw_inode); in ext4_do_update_inode()
5197 EXT4_INODE_SET_XTIME(i_atime, inode, raw_inode); in ext4_do_update_inode()
5202 if (likely(!test_opt2(inode->i_sb, HURD_COMPAT))) in ext4_do_update_inode()
5206 if (READ_ONCE(ei->i_disksize) != ext4_isize(inode->i_sb, raw_inode)) { in ext4_do_update_inode()
5216 raw_inode->i_generation = cpu_to_le32(inode->i_generation); in ext4_do_update_inode()
5217 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) { in ext4_do_update_inode()
5218 if (old_valid_dev(inode->i_rdev)) { in ext4_do_update_inode()
5220 cpu_to_le32(old_encode_dev(inode->i_rdev)); in ext4_do_update_inode()
5225 cpu_to_le32(new_encode_dev(inode->i_rdev)); in ext4_do_update_inode()
5228 } else if (!ext4_has_inline_data(inode)) { in ext4_do_update_inode()
5233 if (likely(!test_opt2(inode->i_sb, HURD_COMPAT))) { in ext4_do_update_inode()
5234 u64 ivers = ext4_inode_peek_iversion(inode); in ext4_do_update_inode()
5246 BUG_ON(!ext4_has_feature_project(inode->i_sb) && in ext4_do_update_inode()
5249 if (EXT4_INODE_SIZE(inode->i_sb) > EXT4_GOOD_OLD_INODE_SIZE && in ext4_do_update_inode()
5253 ext4_inode_csum_set(inode, raw_inode, ei); in ext4_do_update_inode()
5255 if (inode->i_sb->s_flags & SB_LAZYTIME) in ext4_do_update_inode()
5256 ext4_update_other_inodes_time(inode->i_sb, inode->i_ino, in ext4_do_update_inode()
5263 ext4_clear_inode_state(inode, EXT4_STATE_NEW); in ext4_do_update_inode()
5273 ext4_update_inode_fsync_trans(handle, inode, need_datasync); in ext4_do_update_inode()
5276 ext4_std_error(inode->i_sb, err); in ext4_do_update_inode()
5314 int ext4_write_inode(struct inode *inode, struct writeback_control *wbc) in ext4_write_inode() argument
5319 sb_rdonly(inode->i_sb)) in ext4_write_inode()
5322 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) in ext4_write_inode()
5325 if (EXT4_SB(inode->i_sb)->s_journal) { in ext4_write_inode()
5340 err = ext4_fc_commit(EXT4_SB(inode->i_sb)->s_journal, in ext4_write_inode()
5341 EXT4_I(inode)->i_sync_tid); in ext4_write_inode()
5345 err = __ext4_get_inode_loc_noinmem(inode, &iloc); in ext4_write_inode()
5355 ext4_error_inode_block(inode, iloc.bh->b_blocknr, EIO, in ext4_write_inode()
5369 static void ext4_wait_for_tail_page_commit(struct inode *inode) in ext4_wait_for_tail_page_commit() argument
5373 journal_t *journal = EXT4_SB(inode->i_sb)->s_journal; in ext4_wait_for_tail_page_commit()
5377 offset = inode->i_size & (PAGE_SIZE - 1); in ext4_wait_for_tail_page_commit()
5387 if (!offset || offset > (PAGE_SIZE - i_blocksize(inode))) in ext4_wait_for_tail_page_commit()
5390 page = find_lock_page(inode->i_mapping, in ext4_wait_for_tail_page_commit()
5391 inode->i_size >> PAGE_SHIFT); in ext4_wait_for_tail_page_commit()
5436 struct inode *inode = d_inode(dentry); in ext4_setattr() local
5441 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) in ext4_setattr()
5444 if (unlikely(IS_IMMUTABLE(inode))) in ext4_setattr()
5447 if (unlikely(IS_APPEND(inode) && in ext4_setattr()
5464 if (is_quota_modification(inode, attr)) { in ext4_setattr()
5465 error = dquot_initialize(inode); in ext4_setattr()
5470 if ((ia_valid & ATTR_UID && !uid_eq(attr->ia_uid, inode->i_uid)) || in ext4_setattr()
5471 (ia_valid & ATTR_GID && !gid_eq(attr->ia_gid, inode->i_gid))) { in ext4_setattr()
5476 handle = ext4_journal_start(inode, EXT4_HT_QUOTA, in ext4_setattr()
5477 (EXT4_MAXQUOTAS_INIT_BLOCKS(inode->i_sb) + in ext4_setattr()
5478 EXT4_MAXQUOTAS_DEL_BLOCKS(inode->i_sb)) + 3); in ext4_setattr()
5487 down_read(&EXT4_I(inode)->xattr_sem); in ext4_setattr()
5488 error = dquot_transfer(inode, attr); in ext4_setattr()
5489 up_read(&EXT4_I(inode)->xattr_sem); in ext4_setattr()
5498 inode->i_uid = attr->ia_uid; in ext4_setattr()
5500 inode->i_gid = attr->ia_gid; in ext4_setattr()
5501 error = ext4_mark_inode_dirty(handle, inode); in ext4_setattr()
5510 loff_t oldsize = inode->i_size; in ext4_setattr()
5512 int shrink = (attr->ia_size < inode->i_size); in ext4_setattr()
5514 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { in ext4_setattr()
5515 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_setattr()
5521 if (!S_ISREG(inode->i_mode)) { in ext4_setattr()
5525 if (IS_I_VERSION(inode) && attr->ia_size != inode->i_size) in ext4_setattr()
5526 inode_inc_iversion(inode); in ext4_setattr()
5529 if (ext4_should_order_data(inode)) { in ext4_setattr()
5530 error = ext4_begin_ordered_truncate(inode, in ext4_setattr()
5539 inode_dio_wait(inode); in ext4_setattr()
5542 down_write(&EXT4_I(inode)->i_mmap_sem); in ext4_setattr()
5544 rc = ext4_break_layouts(inode); in ext4_setattr()
5546 up_write(&EXT4_I(inode)->i_mmap_sem); in ext4_setattr()
5550 if (attr->ia_size != inode->i_size) { in ext4_setattr()
5551 handle = ext4_journal_start(inode, EXT4_HT_INODE, 3); in ext4_setattr()
5557 error = ext4_orphan_add(handle, inode); in ext4_setattr()
5565 inode->i_mtime = current_time(inode); in ext4_setattr()
5566 inode->i_ctime = inode->i_mtime; in ext4_setattr()
5570 ext4_fc_track_range(handle, inode, in ext4_setattr()
5572 inode->i_sb->s_blocksize_bits, in ext4_setattr()
5576 handle, inode, in ext4_setattr()
5578 inode->i_sb->s_blocksize_bits, in ext4_setattr()
5580 inode->i_sb->s_blocksize_bits); in ext4_setattr()
5582 down_write(&EXT4_I(inode)->i_data_sem); in ext4_setattr()
5583 old_disksize = EXT4_I(inode)->i_disksize; in ext4_setattr()
5584 EXT4_I(inode)->i_disksize = attr->ia_size; in ext4_setattr()
5585 rc = ext4_mark_inode_dirty(handle, inode); in ext4_setattr()
5594 i_size_write(inode, attr->ia_size); in ext4_setattr()
5596 EXT4_I(inode)->i_disksize = old_disksize; in ext4_setattr()
5597 up_write(&EXT4_I(inode)->i_data_sem); in ext4_setattr()
5602 pagecache_isize_extended(inode, oldsize, in ext4_setattr()
5603 inode->i_size); in ext4_setattr()
5604 } else if (ext4_should_journal_data(inode)) { in ext4_setattr()
5605 ext4_wait_for_tail_page_commit(inode); in ext4_setattr()
5613 truncate_pagecache(inode, inode->i_size); in ext4_setattr()
5619 rc = ext4_truncate(inode); in ext4_setattr()
5624 up_write(&EXT4_I(inode)->i_mmap_sem); in ext4_setattr()
5628 setattr_copy(inode, attr); in ext4_setattr()
5629 mark_inode_dirty(inode); in ext4_setattr()
5636 if (orphan && inode->i_nlink) in ext4_setattr()
5637 ext4_orphan_del(NULL, inode); in ext4_setattr()
5640 rc = posix_acl_chmod(inode, inode->i_mode); in ext4_setattr()
5644 ext4_std_error(inode->i_sb, error); in ext4_setattr()
5653 struct inode *inode = d_inode(path->dentry); in ext4_getattr() local
5655 struct ext4_inode_info *ei = EXT4_I(inode); in ext4_getattr()
5686 generic_fillattr(inode, stat); in ext4_getattr()
5693 struct inode *inode = d_inode(path->dentry); in ext4_file_getattr() local
5704 if (unlikely(ext4_has_inline_data(inode))) in ext4_file_getattr()
5717 delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb), in ext4_file_getattr()
5718 EXT4_I(inode)->i_reserved_data_blocks); in ext4_file_getattr()
5719 stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits - 9); in ext4_file_getattr()
5723 static int ext4_index_trans_blocks(struct inode *inode, int lblocks, in ext4_index_trans_blocks() argument
5726 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) in ext4_index_trans_blocks()
5727 return ext4_ind_trans_blocks(inode, lblocks); in ext4_index_trans_blocks()
5728 return ext4_ext_index_trans_blocks(inode, pextents); in ext4_index_trans_blocks()
5742 static int ext4_meta_trans_blocks(struct inode *inode, int lblocks, in ext4_meta_trans_blocks() argument
5745 ext4_group_t groups, ngroups = ext4_get_groups_count(inode->i_sb); in ext4_meta_trans_blocks()
5754 idxblocks = ext4_index_trans_blocks(inode, lblocks, pextents); in ext4_meta_trans_blocks()
5766 if (groups > EXT4_SB(inode->i_sb)->s_gdb_count) in ext4_meta_trans_blocks()
5767 gdpblocks = EXT4_SB(inode->i_sb)->s_gdb_count; in ext4_meta_trans_blocks()
5773 ret += EXT4_META_TRANS_BLOCKS(inode->i_sb); in ext4_meta_trans_blocks()
5788 int ext4_writepage_trans_blocks(struct inode *inode) in ext4_writepage_trans_blocks() argument
5790 int bpp = ext4_journal_blocks_per_page(inode); in ext4_writepage_trans_blocks()
5793 ret = ext4_meta_trans_blocks(inode, bpp, bpp); in ext4_writepage_trans_blocks()
5796 if (ext4_should_journal_data(inode)) in ext4_writepage_trans_blocks()
5810 int ext4_chunk_trans_blocks(struct inode *inode, int nrblocks) in ext4_chunk_trans_blocks() argument
5812 return ext4_meta_trans_blocks(inode, nrblocks, 1); in ext4_chunk_trans_blocks()
5820 struct inode *inode, struct ext4_iloc *iloc) in ext4_mark_iloc_dirty() argument
5824 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) { in ext4_mark_iloc_dirty()
5828 ext4_fc_track_inode(handle, inode); in ext4_mark_iloc_dirty()
5834 if (IS_I_VERSION(inode) && in ext4_mark_iloc_dirty()
5835 !(EXT4_I(inode)->i_flags & EXT4_EA_INODE_FL)) in ext4_mark_iloc_dirty()
5836 inode_inc_iversion(inode); in ext4_mark_iloc_dirty()
5842 err = ext4_do_update_inode(handle, inode, iloc); in ext4_mark_iloc_dirty()
5853 ext4_reserve_inode_write(handle_t *handle, struct inode *inode, in ext4_reserve_inode_write() argument
5858 if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb)))) in ext4_reserve_inode_write()
5861 err = ext4_get_inode_loc(inode, iloc); in ext4_reserve_inode_write()
5870 ext4_std_error(inode->i_sb, err); in ext4_reserve_inode_write()
5874 static int __ext4_expand_extra_isize(struct inode *inode, in __ext4_expand_extra_isize() argument
5881 unsigned int inode_size = EXT4_INODE_SIZE(inode->i_sb); in __ext4_expand_extra_isize()
5882 struct ext4_inode_info *ei = EXT4_I(inode); in __ext4_expand_extra_isize()
5888 EXT4_ERROR_INODE(inode, "bad extra_isize %u (inode size %u)", in __ext4_expand_extra_isize()
5890 EXT4_INODE_SIZE(inode->i_sb)); in __ext4_expand_extra_isize()
5900 header = IHDR(inode, raw_inode); in __ext4_expand_extra_isize()
5903 if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR) || in __ext4_expand_extra_isize()
5906 EXT4_I(inode)->i_extra_isize, 0, in __ext4_expand_extra_isize()
5907 new_extra_isize - EXT4_I(inode)->i_extra_isize); in __ext4_expand_extra_isize()
5908 EXT4_I(inode)->i_extra_isize = new_extra_isize; in __ext4_expand_extra_isize()
5917 if (dquot_initialize_needed(inode)) in __ext4_expand_extra_isize()
5921 error = ext4_expand_extra_isize_ea(inode, new_extra_isize, in __ext4_expand_extra_isize()
5937 static int ext4_try_to_expand_extra_isize(struct inode *inode, in ext4_try_to_expand_extra_isize() argument
5945 if (ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) in ext4_try_to_expand_extra_isize()
5958 EXT4_DATA_TRANS_BLOCKS(inode->i_sb), 0) != 0) in ext4_try_to_expand_extra_isize()
5961 if (ext4_write_trylock_xattr(inode, &no_expand) == 0) in ext4_try_to_expand_extra_isize()
5964 error = __ext4_expand_extra_isize(inode, new_extra_isize, &iloc, in ext4_try_to_expand_extra_isize()
5966 ext4_write_unlock_xattr(inode, &no_expand); in ext4_try_to_expand_extra_isize()
5971 int ext4_expand_extra_isize(struct inode *inode, in ext4_expand_extra_isize() argument
5979 if (ext4_test_inode_state(inode, EXT4_STATE_NO_EXPAND)) { in ext4_expand_extra_isize()
5984 handle = ext4_journal_start(inode, EXT4_HT_INODE, in ext4_expand_extra_isize()
5985 EXT4_DATA_TRANS_BLOCKS(inode->i_sb)); in ext4_expand_extra_isize()
5992 ext4_write_lock_xattr(inode, &no_expand); in ext4_expand_extra_isize()
6001 error = __ext4_expand_extra_isize(inode, new_extra_isize, iloc, in ext4_expand_extra_isize()
6004 rc = ext4_mark_iloc_dirty(handle, inode, iloc); in ext4_expand_extra_isize()
6009 ext4_write_unlock_xattr(inode, &no_expand); in ext4_expand_extra_isize()
6027 int __ext4_mark_inode_dirty(handle_t *handle, struct inode *inode, in __ext4_mark_inode_dirty() argument
6031 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in __ext4_mark_inode_dirty()
6035 trace_ext4_mark_inode_dirty(inode, _RET_IP_); in __ext4_mark_inode_dirty()
6036 err = ext4_reserve_inode_write(handle, inode, &iloc); in __ext4_mark_inode_dirty()
6040 if (EXT4_I(inode)->i_extra_isize < sbi->s_want_extra_isize) in __ext4_mark_inode_dirty()
6041 ext4_try_to_expand_extra_isize(inode, sbi->s_want_extra_isize, in __ext4_mark_inode_dirty()
6044 err = ext4_mark_iloc_dirty(handle, inode, &iloc); in __ext4_mark_inode_dirty()
6047 ext4_error_inode_err(inode, func, line, 0, err, in __ext4_mark_inode_dirty()
6070 void ext4_dirty_inode(struct inode *inode, int flags) in ext4_dirty_inode() argument
6076 handle = ext4_journal_start(inode, EXT4_HT_INODE, 2); in ext4_dirty_inode()
6080 ext4_mark_inode_dirty(handle, inode); in ext4_dirty_inode()
6087 int ext4_change_inode_journal_flag(struct inode *inode, int val) in ext4_change_inode_journal_flag() argument
6092 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); in ext4_change_inode_journal_flag()
6104 journal = EXT4_JOURNAL(inode); in ext4_change_inode_journal_flag()
6111 inode_dio_wait(inode); in ext4_change_inode_journal_flag()
6122 down_write(&EXT4_I(inode)->i_mmap_sem); in ext4_change_inode_journal_flag()
6123 err = filemap_write_and_wait(inode->i_mapping); in ext4_change_inode_journal_flag()
6125 up_write(&EXT4_I(inode)->i_mmap_sem); in ext4_change_inode_journal_flag()
6142 ext4_set_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); in ext4_change_inode_journal_flag()
6150 ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA); in ext4_change_inode_journal_flag()
6152 ext4_set_aops(inode); in ext4_change_inode_journal_flag()
6158 up_write(&EXT4_I(inode)->i_mmap_sem); in ext4_change_inode_journal_flag()
6162 handle = ext4_journal_start(inode, EXT4_HT_INODE, 1); in ext4_change_inode_journal_flag()
6166 ext4_fc_mark_ineligible(inode->i_sb, in ext4_change_inode_journal_flag()
6168 err = ext4_mark_inode_dirty(handle, inode); in ext4_change_inode_journal_flag()
6171 ext4_std_error(inode->i_sb, err); in ext4_change_inode_journal_flag()
6190 struct inode *inode = file_inode(file); in ext4_page_mkwrite() local
6191 struct address_space *mapping = inode->i_mapping; in ext4_page_mkwrite()
6196 if (unlikely(IS_IMMUTABLE(inode))) in ext4_page_mkwrite()
6199 sb_start_pagefault(inode->i_sb); in ext4_page_mkwrite()
6202 down_read(&EXT4_I(inode)->i_mmap_sem); in ext4_page_mkwrite()
6204 err = ext4_convert_inline_data(inode); in ext4_page_mkwrite()
6214 if (ext4_should_journal_data(inode)) in ext4_page_mkwrite()
6218 if (test_opt(inode->i_sb, DELALLOC) && in ext4_page_mkwrite()
6219 !ext4_nonda_switch(inode->i_sb)) { in ext4_page_mkwrite()
6224 ext4_should_retry_alloc(inode->i_sb, &retries)); in ext4_page_mkwrite()
6229 size = i_size_read(inode); in ext4_page_mkwrite()
6260 if (ext4_should_dioread_nolock(inode)) in ext4_page_mkwrite()
6265 handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, in ext4_page_mkwrite()
6266 ext4_writepage_trans_blocks(inode)); in ext4_page_mkwrite()
6276 if (!ext4_should_journal_data(inode)) { in ext4_page_mkwrite()
6280 size = i_size_read(inode); in ext4_page_mkwrite()
6301 if (ext4_jbd2_inode_add_write(handle, inode, in ext4_page_mkwrite()
6304 ext4_set_inode_state(inode, EXT4_STATE_JDATA); in ext4_page_mkwrite()
6310 if (err == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) in ext4_page_mkwrite()
6315 up_read(&EXT4_I(inode)->i_mmap_sem); in ext4_page_mkwrite()
6316 sb_end_pagefault(inode->i_sb); in ext4_page_mkwrite()
6326 struct inode *inode = file_inode(vmf->vma->vm_file); in ext4_filemap_fault() local
6329 down_read(&EXT4_I(inode)->i_mmap_sem); in ext4_filemap_fault()
6331 up_read(&EXT4_I(inode)->i_mmap_sem); in ext4_filemap_fault()