^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: LGPL-2.1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright IBM Corporation, 2007
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include "ext4_jbd2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include "ext4_extents.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * The contiguous blocks details which can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * represented by a single extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) struct migrate_struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) ext4_lblk_t first_block, last_block, curr_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) ext4_fsblk_t first_pblock, last_pblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static int finish_range(handle_t *handle, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct migrate_struct *lb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) int retval = 0, needed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct ext4_extent newext;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct ext4_ext_path *path;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) if (lb->first_pblock == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* Add the extent to temp inode*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) newext.ee_block = cpu_to_le32(lb->first_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) newext.ee_len = cpu_to_le16(lb->last_block - lb->first_block + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ext4_ext_store_pblock(&newext, lb->first_pblock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) /* Locking only for convinience since we are operating on temp inode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) down_write(&EXT4_I(inode)->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) path = ext4_find_extent(inode, lb->first_block, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (IS_ERR(path)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) retval = PTR_ERR(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) path = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * Calculate the credit needed to inserting this extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * Since we are doing this in loop we may accumalate extra
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * credit. But below we try to not accumalate too much
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * of them by restarting the journal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) needed = ext4_ext_calc_credits_for_single_extent(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) lb->last_block - lb->first_block + 1, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) retval = ext4_datasem_ensure_credits(handle, inode, needed, needed, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) retval = ext4_ext_insert_extent(handle, inode, &path, &newext, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) up_write((&EXT4_I(inode)->i_data_sem));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ext4_ext_drop_refs(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) kfree(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) lb->first_pblock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static int update_extent_range(handle_t *handle, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ext4_fsblk_t pblock, struct migrate_struct *lb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) * See if we can add on to the existing range (if it exists)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (lb->first_pblock &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) (lb->last_pblock+1 == pblock) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) (lb->last_block+1 == lb->curr_block)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) lb->last_pblock = pblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) lb->last_block = lb->curr_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) lb->curr_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * Start a new range.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) retval = finish_range(handle, inode, lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) lb->first_pblock = lb->last_pblock = pblock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) lb->first_block = lb->last_block = lb->curr_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) lb->curr_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static int update_ind_extent_range(handle_t *handle, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) ext4_fsblk_t pblock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct migrate_struct *lb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) __le32 *i_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int i, retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) bh = ext4_sb_bread(inode->i_sb, pblock, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (IS_ERR(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) return PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) i_data = (__le32 *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) for (i = 0; i < max_entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) if (i_data[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) retval = update_extent_range(handle, inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) le32_to_cpu(i_data[i]), lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) lb->curr_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int update_dind_extent_range(handle_t *handle, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) ext4_fsblk_t pblock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) struct migrate_struct *lb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) __le32 *i_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int i, retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) bh = ext4_sb_bread(inode->i_sb, pblock, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (IS_ERR(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) return PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) i_data = (__le32 *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) for (i = 0; i < max_entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (i_data[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) retval = update_ind_extent_range(handle, inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) le32_to_cpu(i_data[i]), lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /* Only update the file block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) lb->curr_block += max_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static int update_tind_extent_range(handle_t *handle, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ext4_fsblk_t pblock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct migrate_struct *lb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) __le32 *i_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) int i, retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) bh = ext4_sb_bread(inode->i_sb, pblock, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (IS_ERR(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) i_data = (__le32 *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) for (i = 0; i < max_entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) if (i_data[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) retval = update_dind_extent_range(handle, inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) le32_to_cpu(i_data[i]), lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* Only update the file block number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) lb->curr_block += max_entries * max_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static int free_dind_blocks(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) struct inode *inode, __le32 i_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) __le32 *tmp_idata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) struct super_block *sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) bh = ext4_sb_bread(sb, le32_to_cpu(i_data), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (IS_ERR(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) tmp_idata = (__le32 *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) for (i = 0; i < max_entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) if (tmp_idata[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) err = ext4_journal_ensure_credits(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) EXT4_RESERVE_TRANS_BLOCKS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ext4_free_metadata_revoke_credits(sb, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) ext4_free_blocks(handle, inode, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) le32_to_cpu(tmp_idata[i]), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) EXT4_FREE_BLOCKS_METADATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) EXT4_FREE_BLOCKS_FORGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) err = ext4_journal_ensure_credits(handle, EXT4_RESERVE_TRANS_BLOCKS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) ext4_free_metadata_revoke_credits(sb, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) ext4_free_blocks(handle, inode, NULL, le32_to_cpu(i_data), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) EXT4_FREE_BLOCKS_METADATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) EXT4_FREE_BLOCKS_FORGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static int free_tind_blocks(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) struct inode *inode, __le32 i_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int i, retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) __le32 *tmp_idata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) unsigned long max_entries = inode->i_sb->s_blocksize >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) bh = ext4_sb_bread(inode->i_sb, le32_to_cpu(i_data), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) if (IS_ERR(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) tmp_idata = (__le32 *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) for (i = 0; i < max_entries; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) if (tmp_idata[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) retval = free_dind_blocks(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) inode, tmp_idata[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) retval = ext4_journal_ensure_credits(handle, EXT4_RESERVE_TRANS_BLOCKS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) ext4_free_metadata_revoke_credits(inode->i_sb, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ext4_free_blocks(handle, inode, NULL, le32_to_cpu(i_data), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) EXT4_FREE_BLOCKS_METADATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) EXT4_FREE_BLOCKS_FORGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) static int free_ind_block(handle_t *handle, struct inode *inode, __le32 *i_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) int retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* ei->i_data[EXT4_IND_BLOCK] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) if (i_data[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) retval = ext4_journal_ensure_credits(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) EXT4_RESERVE_TRANS_BLOCKS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) ext4_free_metadata_revoke_credits(inode->i_sb, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ext4_free_blocks(handle, inode, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) le32_to_cpu(i_data[0]), 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) EXT4_FREE_BLOCKS_METADATA |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) EXT4_FREE_BLOCKS_FORGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* ei->i_data[EXT4_DIND_BLOCK] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (i_data[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) retval = free_dind_blocks(handle, inode, i_data[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) /* ei->i_data[EXT4_TIND_BLOCK] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (i_data[2]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) retval = free_tind_blocks(handle, inode, i_data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) struct inode *tmp_inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) int retval, retval2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) __le32 i_data[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct ext4_inode_info *ei = EXT4_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) struct ext4_inode_info *tmp_ei = EXT4_I(tmp_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * One credit accounted for writing the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) * i_data field of the original inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) retval = ext4_journal_ensure_credits(handle, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) i_data[0] = ei->i_data[EXT4_IND_BLOCK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) i_data[1] = ei->i_data[EXT4_DIND_BLOCK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) i_data[2] = ei->i_data[EXT4_TIND_BLOCK];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) down_write(&EXT4_I(inode)->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * if EXT4_STATE_EXT_MIGRATE is cleared a block allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * happened after we started the migrate. We need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * fail the migrate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) if (!ext4_test_inode_state(inode, EXT4_STATE_EXT_MIGRATE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) retval = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) up_write(&EXT4_I(inode)->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) ext4_clear_inode_state(inode, EXT4_STATE_EXT_MIGRATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) * We have the extent map build with the tmp inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) * Now copy the i_data across
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) ext4_set_inode_flag(inode, EXT4_INODE_EXTENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) memcpy(ei->i_data, tmp_ei->i_data, sizeof(ei->i_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * Update i_blocks with the new blocks that got
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * allocated while adding extents for extent index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) * blocks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * While converting to extents we need not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * update the original inode i_blocks for extent blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * via quota APIs. The quota update happened via tmp_inode already.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) spin_lock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) inode->i_blocks += tmp_inode->i_blocks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) spin_unlock(&inode->i_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) up_write(&EXT4_I(inode)->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) * We mark the inode dirty after, because we decrement the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) * i_blocks when freeing the indirect meta-data blocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) retval = free_ind_block(handle, inode, i_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) retval2 = ext4_mark_inode_dirty(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (unlikely(retval2 && !retval))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) retval = retval2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) static int free_ext_idx(handle_t *handle, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct ext4_extent_idx *ix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) int i, retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) ext4_fsblk_t block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) struct buffer_head *bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) struct ext4_extent_header *eh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) block = ext4_idx_pblock(ix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) bh = ext4_sb_bread(inode->i_sb, block, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (IS_ERR(bh))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return PTR_ERR(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) eh = (struct ext4_extent_header *)bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) if (eh->eh_depth != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) ix = EXT_FIRST_INDEX(eh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) for (i = 0; i < le16_to_cpu(eh->eh_entries); i++, ix++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) retval = free_ext_idx(handle, inode, ix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (retval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) put_bh(bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) retval = ext4_journal_ensure_credits(handle, EXT4_RESERVE_TRANS_BLOCKS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) ext4_free_metadata_revoke_credits(inode->i_sb, 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) ext4_free_blocks(handle, inode, NULL, block, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) * Free the extent meta data blocks only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) static int free_ext_block(handle_t *handle, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) int i, retval = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) struct ext4_inode_info *ei = EXT4_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) struct ext4_extent_header *eh = (struct ext4_extent_header *)ei->i_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) struct ext4_extent_idx *ix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (eh->eh_depth == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) * No extra blocks allocated for extent meta data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) ix = EXT_FIRST_INDEX(eh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) for (i = 0; i < le16_to_cpu(eh->eh_entries); i++, ix++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) retval = free_ext_idx(handle, inode, ix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) int ext4_ext_migrate(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) int retval = 0, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) __le32 *i_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) struct ext4_inode_info *ei;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) struct inode *tmp_inode = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) struct migrate_struct lb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) unsigned long max_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) __u32 goal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) uid_t owner[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) * If the filesystem does not support extents, or the inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) * already is extent-based, error out.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (!ext4_has_feature_extents(inode->i_sb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (S_ISLNK(inode->i_mode) && inode->i_blocks == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) * don't migrate fast symlink
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) percpu_down_write(&sbi->s_writepages_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * Worst case we can touch the allocation bitmaps and a block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * group descriptor block. We do need need to worry about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * credits for modifying the quota inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) handle = ext4_journal_start(inode, EXT4_HT_MIGRATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) 3 + EXT4_MAXQUOTAS_TRANS_BLOCKS(inode->i_sb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) retval = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) goal = (((inode->i_ino - 1) / EXT4_INODES_PER_GROUP(inode->i_sb)) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) EXT4_INODES_PER_GROUP(inode->i_sb)) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) owner[0] = i_uid_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) owner[1] = i_gid_read(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) tmp_inode = ext4_new_inode(handle, d_inode(inode->i_sb->s_root),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) S_IFREG, NULL, goal, owner, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) if (IS_ERR(tmp_inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) retval = PTR_ERR(tmp_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) * Use the correct seed for checksum (i.e. the seed from 'inode'). This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) * is so that the metadata blocks will have the correct checksum after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) * the migration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) ei = EXT4_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) EXT4_I(tmp_inode)->i_csum_seed = ei->i_csum_seed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) i_size_write(tmp_inode, i_size_read(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * Set the i_nlink to zero so it will be deleted later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) * when we drop inode reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) clear_nlink(tmp_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) ext4_ext_tree_init(handle, tmp_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) * start with one credit accounted for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * superblock modification.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) * For the tmp_inode we already have committed the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) * transaction that created the inode. Later as and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * when we add extents we extent the journal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) * Even though we take i_mutex we can still cause block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) * allocation via mmap write to holes. If we have allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * new blocks we fail migrate. New block allocation will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * clear EXT4_STATE_EXT_MIGRATE flag. The flag is updated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * with i_data_sem held to prevent racing with block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) * allocation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) down_read(&EXT4_I(inode)->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) ext4_set_inode_state(inode, EXT4_STATE_EXT_MIGRATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) up_read((&EXT4_I(inode)->i_data_sem));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) handle = ext4_journal_start(inode, EXT4_HT_MIGRATE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) retval = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) goto out_tmp_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) i_data = ei->i_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) memset(&lb, 0, sizeof(lb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) /* 32 bit block address 4 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) max_entries = inode->i_sb->s_blocksize >> 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) for (i = 0; i < EXT4_NDIR_BLOCKS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) if (i_data[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) retval = update_extent_range(handle, tmp_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) le32_to_cpu(i_data[i]), &lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) lb.curr_block++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (i_data[EXT4_IND_BLOCK]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) retval = update_ind_extent_range(handle, tmp_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) le32_to_cpu(i_data[EXT4_IND_BLOCK]), &lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) lb.curr_block += max_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) if (i_data[EXT4_DIND_BLOCK]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) retval = update_dind_extent_range(handle, tmp_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) le32_to_cpu(i_data[EXT4_DIND_BLOCK]), &lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) lb.curr_block += max_entries * max_entries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) if (i_data[EXT4_TIND_BLOCK]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) retval = update_tind_extent_range(handle, tmp_inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) le32_to_cpu(i_data[EXT4_TIND_BLOCK]), &lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) * Build the last extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) retval = finish_range(handle, tmp_inode, &lb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) * Failure case delete the extent information with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) * tmp_inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) free_ext_block(handle, tmp_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) retval = ext4_ext_swap_inode_data(handle, inode, tmp_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * if we fail to swap inode data free the extent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * details of the tmp inode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) free_ext_block(handle, tmp_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) /* We mark the tmp_inode dirty via ext4_ext_tree_init. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) retval = ext4_journal_ensure_credits(handle, 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (retval < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) goto out_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) * Mark the tmp_inode as of size zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) i_size_write(tmp_inode, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) * set the i_blocks count to zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) * so that the ext4_evict_inode() does the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * right job
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * We don't need to take the i_lock because
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * the inode is not visible to user space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) tmp_inode->i_blocks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) /* Reset the extent details */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) ext4_ext_tree_init(handle, tmp_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) out_stop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) out_tmp_inode:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) unlock_new_inode(tmp_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) iput(tmp_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) percpu_up_write(&sbi->s_writepages_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) * Migrate a simple extent-based inode to use the i_blocks[] array
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) int ext4_ind_migrate(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) struct ext4_extent_header *eh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) struct ext4_super_block *es = sbi->s_es;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct ext4_inode_info *ei = EXT4_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct ext4_extent *ex;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) unsigned int i, len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) ext4_lblk_t start, end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) ext4_fsblk_t blk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) int ret, ret2 = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (!ext4_has_feature_extents(inode->i_sb) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) (!ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) if (ext4_has_feature_bigalloc(inode->i_sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) return -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) * In order to get correct extent info, force all delayed allocation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) * blocks to be allocated, otherwise delayed allocation blocks may not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) * be reflected and bypass the checks on extent header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) if (test_opt(inode->i_sb, DELALLOC))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) ext4_alloc_da_blocks(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) percpu_down_write(&sbi->s_writepages_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) handle = ext4_journal_start(inode, EXT4_HT_MIGRATE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) ret = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) down_write(&EXT4_I(inode)->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) ret = ext4_ext_check_inode(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) eh = ext_inode_hdr(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) ex = EXT_FIRST_EXTENT(eh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (ext4_blocks_count(es) > EXT4_MAX_BLOCK_FILE_PHYS ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) eh->eh_depth != 0 || le16_to_cpu(eh->eh_entries) > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) if (eh->eh_entries == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) blk = len = start = end = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) len = le16_to_cpu(ex->ee_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) blk = ext4_ext_pblock(ex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) start = le32_to_cpu(ex->ee_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) end = start + len - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) if (end >= EXT4_NDIR_BLOCKS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) ret = -EOPNOTSUPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) goto errout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) ext4_clear_inode_flag(inode, EXT4_INODE_EXTENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) memset(ei->i_data, 0, sizeof(ei->i_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) for (i = start; i <= end; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) ei->i_data[i] = cpu_to_le32(blk++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) ret2 = ext4_mark_inode_dirty(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) if (unlikely(ret2 && !ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) ret = ret2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) errout:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) up_write(&EXT4_I(inode)->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) percpu_up_write(&sbi->s_writepages_rwsem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) }