^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 (c) 2012 Taobao.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Written by Tao Ma <boyu.mt@taobao.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) #include <linux/iomap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/fiemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/iversion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include "ext4_jbd2.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "ext4.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include "xattr.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include "truncate.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <trace/events/android_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define EXT4_XATTR_SYSTEM_DATA "data"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define EXT4_MIN_INLINE_DATA_SIZE ((sizeof(__le32) * EXT4_N_BLOCKS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define EXT4_INLINE_DOTDOT_OFFSET 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define EXT4_INLINE_DOTDOT_SIZE 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static int ext4_get_inline_size(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) if (EXT4_I(inode)->i_inline_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) return EXT4_I(inode)->i_inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static int get_max_inline_xattr_value_size(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct ext4_iloc *iloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct ext4_xattr_ibody_header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct ext4_xattr_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct ext4_inode *raw_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int free, min_offs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) min_offs = EXT4_SB(inode->i_sb)->s_inode_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) EXT4_GOOD_OLD_INODE_SIZE -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) EXT4_I(inode)->i_extra_isize -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) sizeof(struct ext4_xattr_ibody_header);
^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) * We need to subtract another sizeof(__u32) since an in-inode xattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * needs an empty 4 bytes to indicate the gap between the xattr entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * and the name/value pair.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return EXT4_XATTR_SIZE(min_offs -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) EXT4_XATTR_LEN(strlen(EXT4_XATTR_SYSTEM_DATA)) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) EXT4_XATTR_ROUND - sizeof(__u32));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) raw_inode = ext4_raw_inode(iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) header = IHDR(inode, raw_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) entry = IFIRST(header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* Compute min_offs. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (!entry->e_value_inum && entry->e_value_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) size_t offs = le16_to_cpu(entry->e_value_offs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) if (offs < min_offs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) min_offs = offs;
^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) free = min_offs -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) ((void *)entry - (void *)IFIRST(header)) - sizeof(__u32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (EXT4_I(inode)->i_inline_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) entry = (struct ext4_xattr_entry *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) ((void *)raw_inode + EXT4_I(inode)->i_inline_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) free += EXT4_XATTR_SIZE(le32_to_cpu(entry->e_value_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) free -= EXT4_XATTR_LEN(strlen(EXT4_XATTR_SYSTEM_DATA));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (free > EXT4_XATTR_ROUND)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) free = EXT4_XATTR_SIZE(free - EXT4_XATTR_ROUND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) free = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) return free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * Get the maximum size we now can store in an inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * If we can't find the space for a xattr entry, don't use the space
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * of the extents since we have no space to indicate the inline data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) int ext4_get_max_inline_size(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) int error, max_inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) if (EXT4_I(inode)->i_extra_isize == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) error = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) ext4_error_inode_err(inode, __func__, __LINE__, 0, -error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) "can't get inode location %lu",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) down_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) max_inline_size = get_max_inline_xattr_value_size(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (!max_inline_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) return max_inline_size + EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) * this function does not take xattr_sem, which is OK because it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * currently only used in a code path coming form ext4_iget, before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * the new inode has been unlocked
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int ext4_find_inline_data_nolock(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) struct ext4_xattr_ibody_find is = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .s = { .not_found = -ENODATA, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct ext4_xattr_info i = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .name_index = EXT4_XATTR_INDEX_SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .name = EXT4_XATTR_SYSTEM_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) if (EXT4_I(inode)->i_extra_isize == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) error = ext4_get_inode_loc(inode, &is.iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) error = ext4_xattr_ibody_find(inode, &i, &is);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (!is.s.not_found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (is.s.here->e_value_inum) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) EXT4_ERROR_INODE(inode, "inline data xattr refers "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) "to an external xattr inode");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) error = -EFSCORRUPTED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) EXT4_I(inode)->i_inline_off = (u16)((void *)is.s.here -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) (void *)ext4_raw_inode(&is.iloc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) EXT4_I(inode)->i_inline_size = EXT4_MIN_INLINE_DATA_SIZE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) le32_to_cpu(is.s.here->e_value_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) brelse(is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int ext4_read_inline_data(struct inode *inode, void *buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct ext4_iloc *iloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct ext4_xattr_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) struct ext4_xattr_ibody_header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) int cp_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) struct ext4_inode *raw_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (!len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) BUG_ON(len > EXT4_I(inode)->i_inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) cp_len = len < EXT4_MIN_INLINE_DATA_SIZE ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) len : EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) raw_inode = ext4_raw_inode(iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) memcpy(buffer, (void *)(raw_inode->i_block), cp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) len -= cp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) buffer += cp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) if (!len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) header = IHDR(inode, raw_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) entry = (struct ext4_xattr_entry *)((void *)raw_inode +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) EXT4_I(inode)->i_inline_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) len = min_t(unsigned int, len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) (unsigned int)le32_to_cpu(entry->e_value_size));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) memcpy(buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) (void *)IFIRST(header) + le16_to_cpu(entry->e_value_offs), len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) cp_len += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return cp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * write the buffer to the inline inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) * If 'create' is set, we don't need to do the extra copy in the xattr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) * value since it is already handled by ext4_xattr_ibody_inline_set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * That saves us one memcpy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static void ext4_write_inline_data(struct inode *inode, struct ext4_iloc *iloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) void *buffer, loff_t pos, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct ext4_xattr_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) struct ext4_xattr_ibody_header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) struct ext4_inode *raw_inode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) int cp_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) if (unlikely(ext4_forced_shutdown(EXT4_SB(inode->i_sb))))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) BUG_ON(!EXT4_I(inode)->i_inline_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) BUG_ON(pos + len > EXT4_I(inode)->i_inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) raw_inode = ext4_raw_inode(iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) buffer += pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) if (pos < EXT4_MIN_INLINE_DATA_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) cp_len = pos + len > EXT4_MIN_INLINE_DATA_SIZE ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) EXT4_MIN_INLINE_DATA_SIZE - pos : len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) memcpy((void *)raw_inode->i_block + pos, buffer, cp_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) len -= cp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) buffer += cp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) pos += cp_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (!len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) pos -= EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) header = IHDR(inode, raw_inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) entry = (struct ext4_xattr_entry *)((void *)raw_inode +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) EXT4_I(inode)->i_inline_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) memcpy((void *)IFIRST(header) + le16_to_cpu(entry->e_value_offs) + pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) buffer, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int ext4_create_inline_data(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct inode *inode, unsigned len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) void *value = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct ext4_xattr_ibody_find is = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .s = { .not_found = -ENODATA, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) struct ext4_xattr_info i = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .name_index = EXT4_XATTR_INDEX_SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .name = EXT4_XATTR_SYSTEM_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) error = ext4_get_inode_loc(inode, &is.iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) BUFFER_TRACE(is.iloc.bh, "get_write_access");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) error = ext4_journal_get_write_access(handle, is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) if (len > EXT4_MIN_INLINE_DATA_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) value = EXT4_ZERO_XATTR_VALUE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) len -= EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) value = "";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) /* Insert the xttr entry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) i.value = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) i.value_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) error = ext4_xattr_ibody_find(inode, &i, &is);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) BUG_ON(!is.s.not_found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) error = ext4_xattr_ibody_inline_set(handle, inode, &i, &is);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (error == -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) ext4_clear_inode_state(inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) EXT4_STATE_MAY_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) memset((void *)ext4_raw_inode(&is.iloc)->i_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 0, EXT4_MIN_INLINE_DATA_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) EXT4_I(inode)->i_inline_off = (u16)((void *)is.s.here -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) (void *)ext4_raw_inode(&is.iloc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) EXT4_I(inode)->i_inline_size = len + EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) ext4_clear_inode_flag(inode, EXT4_INODE_EXTENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) ext4_set_inode_flag(inode, EXT4_INODE_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) get_bh(is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) brelse(is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static int ext4_update_inline_data(handle_t *handle, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) void *value = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct ext4_xattr_ibody_find is = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .s = { .not_found = -ENODATA, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) struct ext4_xattr_info i = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) .name_index = EXT4_XATTR_INDEX_SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) .name = EXT4_XATTR_SYSTEM_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) /* If the old space is ok, write the data directly. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) if (len <= EXT4_I(inode)->i_inline_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) error = ext4_get_inode_loc(inode, &is.iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) error = ext4_xattr_ibody_find(inode, &i, &is);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) BUG_ON(is.s.not_found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) len -= EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) value = kzalloc(len, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) if (!value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) error = ext4_xattr_ibody_get(inode, i.name_index, i.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) value, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) if (error == -ENODATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) BUFFER_TRACE(is.iloc.bh, "get_write_access");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) error = ext4_journal_get_write_access(handle, is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /* Update the xattr entry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) i.value = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) i.value_len = len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) error = ext4_xattr_ibody_inline_set(handle, inode, &i, &is);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) EXT4_I(inode)->i_inline_off = (u16)((void *)is.s.here -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) (void *)ext4_raw_inode(&is.iloc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) EXT4_I(inode)->i_inline_size = EXT4_MIN_INLINE_DATA_SIZE +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) le32_to_cpu(is.s.here->e_value_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) get_bh(is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) kfree(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) brelse(is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) static int ext4_prepare_inline_data(handle_t *handle, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) int ret, size, no_expand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) struct ext4_inode_info *ei = EXT4_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (!ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) size = ext4_get_max_inline_size(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (size < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) ext4_write_lock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) if (ei->i_inline_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) ret = ext4_update_inline_data(handle, inode, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) ret = ext4_create_inline_data(handle, inode, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) ext4_write_unlock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) static int ext4_destroy_inline_data_nolock(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) struct ext4_inode_info *ei = EXT4_I(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct ext4_xattr_ibody_find is = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) .s = { .not_found = 0, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) struct ext4_xattr_info i = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) .name_index = EXT4_XATTR_INDEX_SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) .name = EXT4_XATTR_SYSTEM_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) .value = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) .value_len = 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (!ei->i_inline_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) error = ext4_get_inode_loc(inode, &is.iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) error = ext4_xattr_ibody_find(inode, &i, &is);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) BUFFER_TRACE(is.iloc.bh, "get_write_access");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) error = ext4_journal_get_write_access(handle, is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) error = ext4_xattr_ibody_inline_set(handle, inode, &i, &is);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) memset((void *)ext4_raw_inode(&is.iloc)->i_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 0, EXT4_MIN_INLINE_DATA_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) memset(ei->i_data, 0, EXT4_MIN_INLINE_DATA_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (ext4_has_feature_extents(inode->i_sb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) if (S_ISDIR(inode->i_mode) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) S_ISREG(inode->i_mode) || S_ISLNK(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) ext4_set_inode_flag(inode, EXT4_INODE_EXTENTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) ext4_ext_tree_init(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) ext4_clear_inode_flag(inode, EXT4_INODE_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) get_bh(is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) error = ext4_mark_iloc_dirty(handle, inode, &is.iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) EXT4_I(inode)->i_inline_off = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) EXT4_I(inode)->i_inline_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) brelse(is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) if (error == -ENODATA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) static int ext4_read_inline_page(struct inode *inode, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) size_t len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) BUG_ON(!PageLocked(page));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) BUG_ON(!ext4_has_inline_data(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) BUG_ON(page->index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) if (!EXT4_I(inode)->i_inline_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) ext4_warning(inode->i_sb, "inode %lu doesn't have inline data.",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) ret = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) len = min_t(size_t, ext4_get_inline_size(inode), i_size_read(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) kaddr = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) ret = ext4_read_inline_data(inode, kaddr, len, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) flush_dcache_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) zero_user_segment(page, len, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) int ext4_readpage_inline(struct inode *inode, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) down_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (!ext4_has_inline_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (trace_android_fs_dataread_start_enabled()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) char *path, pathbuf[MAX_TRACE_PATHBUF_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) path = android_fstrace_get_pathname(pathbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) MAX_TRACE_PATHBUF_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) trace_android_fs_dataread_start(inode, page_offset(page),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) PAGE_SIZE, current->pid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) path, current->comm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) * Current inline data can only exist in the 1st page,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) * So for all the other pages, just set them uptodate.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) if (!page->index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) ret = ext4_read_inline_page(inode, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) else if (!PageUptodate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) zero_user_segment(page, 0, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) trace_android_fs_dataread_end(inode, page_offset(page), PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) return ret >= 0 ? 0 : ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) static int ext4_convert_inline_data_to_extent(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) unsigned flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) int ret, needed_blocks, no_expand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) handle_t *handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) int retries = 0, sem_held = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) struct page *page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) unsigned from, to;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) if (!ext4_has_inline_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * clear the flag so that no new write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * will trap here again.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) needed_blocks = ext4_writepage_trans_blocks(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) ret = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) ret = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) /* We cannot recurse into the filesystem as the transaction is already
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * started */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) flags |= AOP_FLAG_NOFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) page = grab_cache_page_write_begin(mapping, 0, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (!page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) ext4_write_lock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) sem_held = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) /* If some one has already done this for us, just exit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) if (!ext4_has_inline_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) goto out;
^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) from = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) to = ext4_get_inline_size(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (!PageUptodate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) ret = ext4_read_inline_page(inode, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) ret = ext4_destroy_inline_data_nolock(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (ext4_should_dioread_nolock(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) ret = __block_write_begin(page, from, to,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) ext4_get_block_unwritten);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) ret = __block_write_begin(page, from, to, ext4_get_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if (!ret && ext4_should_journal_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) ret = ext4_walk_page_buffers(handle, page_buffers(page),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) from, to, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) do_journal_get_write_access);
^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) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) page = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) ext4_orphan_add(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) ext4_write_unlock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) sem_held = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) ext4_truncate_failed_write(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) * If truncate failed early the inode might
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) * still be on the orphan list; we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) * make sure the inode is removed from the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) * orphan list in that case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) if (inode->i_nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) ext4_orphan_del(NULL, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) block_commit_write(page, from, to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) if (sem_held)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) ext4_write_unlock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) }
^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) * Try to write data in the inode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) * If the inode has inline data, check whether the new write can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) * in the inode also. If not, create the page the handle, move the data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * to the page make it update and let the later codes create extent for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) int ext4_try_to_write_inline_data(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) loff_t pos, unsigned len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) unsigned flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) struct page **pagep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) if (pos + len > ext4_get_max_inline_size(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) goto convert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) ret = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) * The possible write could happen in the inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) * so try to reserve the space in inode first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) ret = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) ret = ext4_prepare_inline_data(handle, inode, pos + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) if (ret && ret != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) /* We don't have space in inline inode, so convert it to extent. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) if (ret == -ENOSPC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) goto convert;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) ret = ext4_journal_get_write_access(handle, iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) flags |= AOP_FLAG_NOFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) page = grab_cache_page_write_begin(mapping, 0, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) if (!page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) *pagep = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) down_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) if (!ext4_has_inline_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) goto out_up_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) if (!PageUptodate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) ret = ext4_read_inline_page(inode, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) goto out_up_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) handle = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) out_up_read:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) if (handle && (ret != 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) convert:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) return ext4_convert_inline_data_to_extent(mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) inode, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) unsigned copied, struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) int ret, no_expand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) if (unlikely(copied < len) && !PageUptodate(page))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) ret = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) ext4_std_error(inode->i_sb, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) ext4_write_lock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) BUG_ON(!ext4_has_inline_data(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) * ei->i_inline_off may have changed since ext4_write_begin()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) * called ext4_try_to_write_inline_data()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) (void) ext4_find_inline_data_nolock(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) kaddr = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) ext4_write_inline_data(inode, &iloc, kaddr, pos, copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) /* clear page dirty so that writepages wouldn't work for us. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) ClearPageDirty(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) ext4_write_unlock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) return copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) struct buffer_head *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) ext4_journalled_write_inline_data(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) unsigned len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) int ret, no_expand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) void *kaddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) ret = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) ext4_std_error(inode->i_sb, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) ext4_write_lock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) kaddr = kmap_atomic(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) ext4_write_inline_data(inode, &iloc, kaddr, 0, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) kunmap_atomic(kaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) ext4_write_unlock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) return iloc.bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) * Try to make the page cache and handle ready for the inline data case.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) * We can call this function in 2 cases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) * 1. The inode is created and the first write exceeds inline size. We can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) * clear the inode state safely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) * 2. The inode has inline data, then we need to read the data, make it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * update and dirty so that ext4_da_writepages can handle it. We don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) * need to start the journal since the file's metatdata isn't changed now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) static int ext4_da_convert_inline_data_to_extent(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) unsigned flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) void **fsdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) int ret = 0, inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) page = grab_cache_page_write_begin(mapping, 0, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824) if (!page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827) down_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) if (!ext4_has_inline_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) inline_size = ext4_get_inline_size(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) if (!PageUptodate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) ret = ext4_read_inline_page(inode, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) ret = __block_write_begin(page, 0, inline_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) ext4_da_get_block_prep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) ext4_truncate_failed_write(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) SetPageDirty(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) SetPageUptodate(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853) ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) *fsdata = (void *)CONVERT_INLINE_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) if (page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) * Prepare the write for the inline data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867) * If the data can be written into the inode, we just read
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) * the page and make it uptodate, and start the journal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) * Otherwise read the page, makes it dirty so that it can be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) * handle in writepages(the i_disksize update is left to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) * normal ext4_da_write_end).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) int ext4_da_write_inline_data_begin(struct address_space *mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) loff_t pos, unsigned len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) unsigned flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) struct page **pagep,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878) void **fsdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) int ret, inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) struct page *page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) int retries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) ret = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) retry_journal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) handle = ext4_journal_start(inode, EXT4_HT_INODE, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) ret = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) inline_size = ext4_get_max_inline_size(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) ret = -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) if (inline_size >= pos + len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901) ret = ext4_prepare_inline_data(handle, inode, pos + len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) if (ret && ret != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) goto out_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907) * We cannot recurse into the filesystem as the transaction
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) * is already started.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) flags |= AOP_FLAG_NOFS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) if (ret == -ENOSPC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) ret = ext4_da_convert_inline_data_to_extent(mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) flags,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) fsdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918) if (ret == -ENOSPC &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) ext4_should_retry_alloc(inode->i_sb, &retries))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) goto retry_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) page = grab_cache_page_write_begin(mapping, 0, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) if (!page) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927) goto out_journal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) down_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) if (!ext4_has_inline_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) goto out_release_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) if (!PageUptodate(page)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) ret = ext4_read_inline_page(inode, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939) goto out_release_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) ret = ext4_journal_get_write_access(handle, iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 942) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 943) goto out_release_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 944)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 945) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 946) *pagep = page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 947) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 948) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 949) out_release_page:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 950) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 951) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 952) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 953) out_journal:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 954) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 955) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 956) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 957) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 958) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 959)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 960) int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 961) unsigned len, unsigned copied,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 962) struct page *page)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 963) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 964) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 965)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 966) ret = ext4_write_inline_data_end(inode, pos, len, copied, page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 967) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 968) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 969) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 970) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 971) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 972) copied = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 973)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 974) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 975) * No need to use i_size_read() here, the i_size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 976) * cannot change under us because we hold i_mutex.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 977) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 978) * But it's important to update i_size while still holding page lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 979) * page writeout could otherwise come in and zero beyond i_size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 980) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 981) if (pos+copied > inode->i_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 982) i_size_write(inode, pos+copied);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 983) unlock_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 984) put_page(page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 985)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 986) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 987) * Don't mark the inode dirty under page lock. First, it unnecessarily
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 988) * makes the holding time of page lock longer. Second, it forces lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 989) * ordering of page lock and transaction start for journaling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 990) * filesystems.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 991) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 992) mark_inode_dirty(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 993)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 994) return copied;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 995) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 996)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 997) #ifdef INLINE_DIR_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 998) void ext4_show_inline_dir(struct inode *dir, struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 999) void *inline_start, int inline_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) unsigned short de_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) struct ext4_dir_entry_2 *de = inline_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) void *dlimit = inline_start + inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) trace_printk("inode %lu\n", dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) while ((void *)de < dlimit) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) de_len = ext4_rec_len_from_disk(de->rec_len, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) trace_printk("de: off %u rlen %u name %.*s nlen %u ino %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) offset, de_len, de->name_len, de->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) de->name_len, le32_to_cpu(de->inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) if (ext4_check_dir_entry(dir, NULL, de, bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) inline_start, inline_size, 0, offset))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) offset += de_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) de = (struct ext4_dir_entry_2 *) ((char *) de + de_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) #define ext4_show_inline_dir(dir, bh, inline_start, inline_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) * Add a new entry into a inline dir.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) * It will return -ENOSPC if no space is available, and -EIO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) * and -EEXIST if directory entry already exists.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) static int ext4_add_dirent_to_inline(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) struct ext4_filename *fname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) struct ext4_iloc *iloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) void *inline_start, int inline_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) struct ext4_dir_entry_2 *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) err = ext4_find_dest_de(dir, inode, 0, iloc->bh, inline_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) inline_size, fname, &de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) BUFFER_TRACE(iloc->bh, "get_write_access");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) err = ext4_journal_get_write_access(handle, iloc->bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) ext4_insert_dentry(dir, inode, de, inline_size, fname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) ext4_show_inline_dir(dir, iloc->bh, inline_start, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) * XXX shouldn't update any times until successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) * completion of syscall, but too many callers depend
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) * on this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) * XXX similarly, too many callers depend on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) * ext4_new_inode() setting the times, but error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) * recovery deletes the inode, so the worst that can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) * happen is that the times are slightly out of date
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) * and/or different from the directory change time.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) dir->i_mtime = dir->i_ctime = current_time(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) ext4_update_dx_flag(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) inode_inc_iversion(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) static void *ext4_get_inline_xattr_pos(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) struct ext4_iloc *iloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) struct ext4_xattr_entry *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) struct ext4_xattr_ibody_header *header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) BUG_ON(!EXT4_I(inode)->i_inline_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) header = IHDR(inode, ext4_raw_inode(iloc));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) entry = (struct ext4_xattr_entry *)((void *)ext4_raw_inode(iloc) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) EXT4_I(inode)->i_inline_off);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) return (void *)IFIRST(header) + le16_to_cpu(entry->e_value_offs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) /* Set the final de to cover the whole block. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) static void ext4_update_final_de(void *de_buf, int old_size, int new_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) struct ext4_dir_entry_2 *de, *prev_de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) void *limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) int de_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) de = (struct ext4_dir_entry_2 *)de_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) if (old_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) limit = de_buf + old_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) prev_de = de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) de_len = ext4_rec_len_from_disk(de->rec_len, old_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) de_buf += de_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) de = (struct ext4_dir_entry_2 *)de_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) } while (de_buf < limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) prev_de->rec_len = ext4_rec_len_to_disk(de_len + new_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) old_size, new_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) /* this is just created, so create an empty entry. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) de->inode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) de->rec_len = ext4_rec_len_to_disk(new_size, new_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) static int ext4_update_inline_dir(handle_t *handle, struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) struct ext4_iloc *iloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) int old_size = EXT4_I(dir)->i_inline_size - EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) int new_size = get_max_inline_xattr_value_size(dir, iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) if (new_size - old_size <= ext4_dir_rec_len(1, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) return -ENOSPC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) ret = ext4_update_inline_data(handle, dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) new_size + EXT4_MIN_INLINE_DATA_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) ext4_update_final_de(ext4_get_inline_xattr_pos(dir, iloc), old_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) EXT4_I(dir)->i_inline_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) EXT4_MIN_INLINE_DATA_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) dir->i_size = EXT4_I(dir)->i_disksize = EXT4_I(dir)->i_inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) static void ext4_restore_inline_data(handle_t *handle, struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) struct ext4_iloc *iloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) void *buf, int inline_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) ret = ext4_create_inline_data(handle, inode, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) ext4_msg(inode->i_sb, KERN_EMERG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) "error restoring inline_data for inode -- potential data loss! (inode %lu, error %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) inode->i_ino, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) ext4_write_inline_data(inode, iloc, buf, 0, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) static int ext4_finish_convert_inline_dir(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) struct buffer_head *dir_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) void *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) int inline_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) int err, csum_size = 0, header_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) struct ext4_dir_entry_2 *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) void *target = dir_block->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) * First create "." and ".." and then copy the dir information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) * back to the block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) de = (struct ext4_dir_entry_2 *)target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) de = ext4_init_dot_dotdot(inode, de,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) inode->i_sb->s_blocksize, csum_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) le32_to_cpu(((struct ext4_dir_entry_2 *)buf)->inode), 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) header_size = (void *)de - target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) memcpy((void *)de, buf + EXT4_INLINE_DOTDOT_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) inline_size - EXT4_INLINE_DOTDOT_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) if (ext4_has_metadata_csum(inode->i_sb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) csum_size = sizeof(struct ext4_dir_entry_tail);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) inode->i_size = inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) i_size_write(inode, inode->i_sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) EXT4_I(inode)->i_disksize = inode->i_sb->s_blocksize;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) ext4_update_final_de(dir_block->b_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) inline_size - EXT4_INLINE_DOTDOT_SIZE + header_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) inode->i_sb->s_blocksize - csum_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) if (csum_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) ext4_initialize_dirent_tail(dir_block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) inode->i_sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) set_buffer_uptodate(dir_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) err = ext4_handle_dirty_dirblock(handle, inode, dir_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) set_buffer_verified(dir_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) return ext4_mark_inode_dirty(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) static int ext4_convert_inline_data_nolock(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) struct ext4_iloc *iloc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) void *buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) struct buffer_head *data_bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) struct ext4_map_blocks map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) int inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) inline_size = ext4_get_inline_size(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) buf = kmalloc(inline_size, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) if (!buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) error = ext4_read_inline_data(inode, buf, inline_size, iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) * Make sure the inline directory entries pass checks before we try to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) * convert them, so that we avoid touching stuff that needs fsck.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) if (S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) error = ext4_check_all_de(inode, iloc->bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) buf + EXT4_INLINE_DOTDOT_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) inline_size - EXT4_INLINE_DOTDOT_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) error = ext4_destroy_inline_data_nolock(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) map.m_lblk = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) map.m_len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) map.m_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) error = ext4_map_blocks(handle, inode, &map, EXT4_GET_BLOCKS_CREATE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) if (error < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) goto out_restore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) if (!(map.m_flags & EXT4_MAP_MAPPED)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) goto out_restore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) data_bh = sb_getblk(inode->i_sb, map.m_pblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) if (!data_bh) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) error = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) goto out_restore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) lock_buffer(data_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) error = ext4_journal_get_create_access(handle, data_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) unlock_buffer(data_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) error = -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) goto out_restore;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) memset(data_bh->b_data, 0, inode->i_sb->s_blocksize);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) if (!S_ISDIR(inode->i_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) memcpy(data_bh->b_data, buf, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) set_buffer_uptodate(data_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) error = ext4_handle_dirty_metadata(handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) inode, data_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) error = ext4_finish_convert_inline_dir(handle, inode, data_bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) buf, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) unlock_buffer(data_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) out_restore:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) ext4_restore_inline_data(handle, inode, iloc, buf, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) brelse(data_bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) kfree(buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) * Try to add the new entry to the inline data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) * If succeeds, return 0. If not, extended the inline dir and copied data to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) * the new created block.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) int ext4_try_add_inline_entry(handle_t *handle, struct ext4_filename *fname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) struct inode *dir, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) int ret, ret2, inline_size, no_expand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) void *inline_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) ret = ext4_get_inode_loc(dir, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) ext4_write_lock_xattr(dir, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) if (!ext4_has_inline_data(dir))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) inline_start = (void *)ext4_raw_inode(&iloc)->i_block +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) EXT4_INLINE_DOTDOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) inline_size = EXT4_MIN_INLINE_DATA_SIZE - EXT4_INLINE_DOTDOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) ret = ext4_add_dirent_to_inline(handle, fname, dir, inode, &iloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) inline_start, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) if (ret != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) /* check whether it can be inserted to inline xattr space. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) inline_size = EXT4_I(dir)->i_inline_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) if (!inline_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) /* Try to use the xattr space.*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) ret = ext4_update_inline_dir(handle, dir, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) if (ret && ret != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) inline_size = EXT4_I(dir)->i_inline_size -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) if (inline_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) inline_start = ext4_get_inline_xattr_pos(dir, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) ret = ext4_add_dirent_to_inline(handle, fname, dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) inode, &iloc, inline_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) if (ret != -ENOSPC)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) * The inline space is filled up, so create a new block for it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) * As the extent tree will be created, we have to save the inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) * dir first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) ret = ext4_convert_inline_data_nolock(handle, dir, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) ext4_write_unlock_xattr(dir, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) ret2 = ext4_mark_inode_dirty(handle, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) if (unlikely(ret2 && !ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) ret = ret2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) * This function fills a red-black tree with information from an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) * inlined dir. It returns the number directory entries loaded
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) * into the tree. If there is an error it is returned in err.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) int ext4_inlinedir_to_tree(struct file *dir_file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) struct inode *dir, ext4_lblk_t block,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) struct dx_hash_info *hinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) __u32 start_hash, __u32 start_minor_hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) int *has_inline_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) int err = 0, count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) unsigned int parent_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) int pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) struct ext4_dir_entry_2 *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) struct inode *inode = file_inode(dir_file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) int ret, inline_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) void *dir_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) struct ext4_dir_entry_2 fake;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) struct fscrypt_str tmp_str;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) ret = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) down_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) if (!ext4_has_inline_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) *has_inline_data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) inline_size = ext4_get_inline_size(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) dir_buf = kmalloc(inline_size, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) if (!dir_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) ret = ext4_read_inline_data(inode, dir_buf, inline_size, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) while (pos < inline_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) * As inlined dir doesn't store any information about '.' and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) * only the inode number of '..' is stored, we have to handle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) * them differently.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) if (pos == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) fake.inode = cpu_to_le32(inode->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) fake.name_len = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) strcpy(fake.name, ".");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) fake.rec_len = ext4_rec_len_to_disk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) ext4_dir_rec_len(fake.name_len, NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) ext4_set_de_type(inode->i_sb, &fake, S_IFDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) de = &fake;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) pos = EXT4_INLINE_DOTDOT_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) } else if (pos == EXT4_INLINE_DOTDOT_OFFSET) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) fake.inode = cpu_to_le32(parent_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) fake.name_len = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) strcpy(fake.name, "..");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) fake.rec_len = ext4_rec_len_to_disk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) ext4_dir_rec_len(fake.name_len, NULL),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) ext4_set_de_type(inode->i_sb, &fake, S_IFDIR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) de = &fake;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) pos = EXT4_INLINE_DOTDOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) de = (struct ext4_dir_entry_2 *)(dir_buf + pos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) pos += ext4_rec_len_from_disk(de->rec_len, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) if (ext4_check_dir_entry(inode, dir_file, de,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) iloc.bh, dir_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) inline_size, block, pos)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) ret = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) if (ext4_hash_in_dirent(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) hinfo->hash = EXT4_DIRENT_HASH(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) hinfo->minor_hash = EXT4_DIRENT_MINOR_HASH(de);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) ext4fs_dirhash(dir, de->name, de->name_len, hinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) if ((hinfo->hash < start_hash) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) ((hinfo->hash == start_hash) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) (hinfo->minor_hash < start_minor_hash)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) if (de->inode == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) tmp_str.name = de->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) tmp_str.len = de->name_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) err = ext4_htree_store_dirent(dir_file, hinfo->hash,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) hinfo->minor_hash, de, &tmp_str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) ret = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) ret = count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) kfree(dir_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) * So this function is called when the volume is mkfsed with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) * dir_index disabled. In order to keep f_pos persistent
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) * after we convert from an inlined dir to a blocked based,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) * we just pretend that we are a normal dir and return the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) * offset as if '.' and '..' really take place.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) int ext4_read_inline_dir(struct file *file,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) struct dir_context *ctx,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) int *has_inline_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) unsigned int offset, parent_ino;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) struct ext4_dir_entry_2 *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) struct super_block *sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) struct inode *inode = file_inode(file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) int ret, inline_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) void *dir_buf = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) int dotdot_offset, dotdot_size, extra_offset, extra_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) ret = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) down_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) if (!ext4_has_inline_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) *has_inline_data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) inline_size = ext4_get_inline_size(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) dir_buf = kmalloc(inline_size, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) if (!dir_buf) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) ret = ext4_read_inline_data(inode, dir_buf, inline_size, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) sb = inode->i_sb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) offset = ctx->pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) * dotdot_offset and dotdot_size is the real offset and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) * size for ".." and "." if the dir is block based while
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) * the real size for them are only EXT4_INLINE_DOTDOT_SIZE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) * So we will use extra_offset and extra_size to indicate them
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) * during the inline dir iteration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) dotdot_offset = ext4_dir_rec_len(1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) dotdot_size = dotdot_offset + ext4_dir_rec_len(2, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) extra_offset = dotdot_size - EXT4_INLINE_DOTDOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) extra_size = extra_offset + inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) * If the version has changed since the last call to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) * readdir(2), then we might be pointing to an invalid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) * dirent right now. Scan from the start of the inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) * dir to make sure.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) if (!inode_eq_iversion(inode, file->f_version)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) for (i = 0; i < extra_size && i < offset;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) * "." is with offset 0 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) * ".." is dotdot_offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) if (!i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) i = dotdot_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) } else if (i == dotdot_offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) i = dotdot_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) /* for other entry, the real offset in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) * the buf has to be tuned accordingly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) de = (struct ext4_dir_entry_2 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) (dir_buf + i - extra_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) /* It's too expensive to do a full
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) * dirent test each time round this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) * loop, but we do have to test at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) * least that it is non-zero. A
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) * failure will be detected in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) * dirent test below. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) if (ext4_rec_len_from_disk(de->rec_len, extra_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) < ext4_dir_rec_len(1, NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) i += ext4_rec_len_from_disk(de->rec_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) extra_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) offset = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) ctx->pos = offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) file->f_version = inode_query_iversion(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) while (ctx->pos < extra_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) if (ctx->pos == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) if (!dir_emit(ctx, ".", 1, inode->i_ino, DT_DIR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) ctx->pos = dotdot_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) if (ctx->pos == dotdot_offset) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) if (!dir_emit(ctx, "..", 2, parent_ino, DT_DIR))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) ctx->pos = dotdot_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) de = (struct ext4_dir_entry_2 *)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) (dir_buf + ctx->pos - extra_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) if (ext4_check_dir_entry(inode, file, de, iloc.bh, dir_buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) extra_size, 0, ctx->pos))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) if (le32_to_cpu(de->inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) if (!dir_emit(ctx, de->name, de->name_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) le32_to_cpu(de->inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) get_dtype(sb, de->file_type)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) ctx->pos += ext4_rec_len_from_disk(de->rec_len, extra_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) kfree(dir_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) struct buffer_head *ext4_get_first_inline_block(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) struct ext4_dir_entry_2 **parent_de,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) int *retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) *retval = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) if (*retval)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) *parent_de = (struct ext4_dir_entry_2 *)ext4_raw_inode(&iloc)->i_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) return iloc.bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) * Try to create the inline data for the new dir.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) * If it succeeds, return 0, otherwise return the error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) * In case of ENOSPC, the caller should create the normal disk layout dir.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) int ext4_try_create_inline_dir(handle_t *handle, struct inode *parent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) int ret, inline_size = EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) struct ext4_dir_entry_2 *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) ret = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) ret = ext4_prepare_inline_data(handle, inode, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) * For inline dir, we only save the inode information for the ".."
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) * and create a fake dentry to cover the left space.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) de = (struct ext4_dir_entry_2 *)ext4_raw_inode(&iloc)->i_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) de->inode = cpu_to_le32(parent->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) de = (struct ext4_dir_entry_2 *)((void *)de + EXT4_INLINE_DOTDOT_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) de->inode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) de->rec_len = ext4_rec_len_to_disk(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) inline_size - EXT4_INLINE_DOTDOT_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) set_nlink(inode, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) inode->i_size = EXT4_I(inode)->i_disksize = inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) struct buffer_head *ext4_find_inline_entry(struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) struct ext4_filename *fname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) struct ext4_dir_entry_2 **res_dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) int *has_inline_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) void *inline_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) int inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) if (ext4_get_inode_loc(dir, &iloc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) down_read(&EXT4_I(dir)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) if (!ext4_has_inline_data(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) *has_inline_data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) inline_start = (void *)ext4_raw_inode(&iloc)->i_block +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) EXT4_INLINE_DOTDOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) inline_size = EXT4_MIN_INLINE_DATA_SIZE - EXT4_INLINE_DOTDOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) ret = ext4_search_dir(iloc.bh, inline_start, inline_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) dir, fname, 0, 0, res_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) if (ret == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) goto out_find;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) if (ext4_get_inline_size(dir) == EXT4_MIN_INLINE_DATA_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) inline_start = ext4_get_inline_xattr_pos(dir, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) inline_size = ext4_get_inline_size(dir) - EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) ret = ext4_search_dir(iloc.bh, inline_start, inline_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) dir, fname, 0, 0, res_dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) if (ret == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) goto out_find;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) iloc.bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) out_find:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) up_read(&EXT4_I(dir)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) return iloc.bh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) int ext4_delete_inline_entry(handle_t *handle,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) struct inode *dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) struct ext4_dir_entry_2 *de_del,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) struct buffer_head *bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) int *has_inline_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) int err, inline_size, no_expand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) void *inline_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) err = ext4_get_inode_loc(dir, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) ext4_write_lock_xattr(dir, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) if (!ext4_has_inline_data(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) *has_inline_data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) if ((void *)de_del - ((void *)ext4_raw_inode(&iloc)->i_block) <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) EXT4_MIN_INLINE_DATA_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) inline_start = (void *)ext4_raw_inode(&iloc)->i_block +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) EXT4_INLINE_DOTDOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) inline_size = EXT4_MIN_INLINE_DATA_SIZE -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) EXT4_INLINE_DOTDOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) inline_start = ext4_get_inline_xattr_pos(dir, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) inline_size = ext4_get_inline_size(dir) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) BUFFER_TRACE(bh, "get_write_access");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) err = ext4_journal_get_write_access(handle, bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) err = ext4_generic_delete_entry(dir, de_del, 0, bh,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) inline_start, inline_size, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) ext4_show_inline_dir(dir, iloc.bh, inline_start, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) ext4_write_unlock_xattr(dir, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) if (likely(err == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) err = ext4_mark_inode_dirty(handle, dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) if (err != -ENOENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) ext4_std_error(dir->i_sb, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) * Get the inline dentry at offset.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) static inline struct ext4_dir_entry_2 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) ext4_get_inline_entry(struct inode *inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) struct ext4_iloc *iloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) unsigned int offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) void **inline_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) int *inline_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) void *inline_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) BUG_ON(offset > ext4_get_inline_size(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) if (offset < EXT4_MIN_INLINE_DATA_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) inline_pos = (void *)ext4_raw_inode(iloc)->i_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) *inline_size = EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) inline_pos = ext4_get_inline_xattr_pos(inode, iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) offset -= EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) *inline_size = ext4_get_inline_size(inode) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) EXT4_MIN_INLINE_DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) if (inline_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) *inline_start = inline_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) return (struct ext4_dir_entry_2 *)(inline_pos + offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) bool empty_inline_dir(struct inode *dir, int *has_inline_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) int err, inline_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) size_t inline_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) void *inline_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) unsigned int offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) struct ext4_dir_entry_2 *de;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) bool ret = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) err = ext4_get_inode_loc(dir, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) EXT4_ERROR_INODE_ERR(dir, -err,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) "error %d getting inode %lu block",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) err, dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) down_read(&EXT4_I(dir)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) if (!ext4_has_inline_data(dir)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) *has_inline_data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) de = (struct ext4_dir_entry_2 *)ext4_raw_inode(&iloc)->i_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) if (!le32_to_cpu(de->inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) ext4_warning(dir->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) "bad inline directory (dir #%lu) - no `..'",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) dir->i_ino);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) inline_len = ext4_get_inline_size(dir);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) offset = EXT4_INLINE_DOTDOT_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) while (offset < inline_len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) de = ext4_get_inline_entry(dir, &iloc, offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) &inline_pos, &inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) if (ext4_check_dir_entry(dir, NULL, de,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) iloc.bh, inline_pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) inline_size, 0, offset)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) ext4_warning(dir->i_sb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) "bad inline directory (dir #%lu) - "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) "inode %u, rec_len %u, name_len %d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) "inline size %d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) dir->i_ino, le32_to_cpu(de->inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) le16_to_cpu(de->rec_len), de->name_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) if (le32_to_cpu(de->inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) offset += ext4_rec_len_from_disk(de->rec_len, inline_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) ret = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) up_read(&EXT4_I(dir)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) int ext4_destroy_inline_data(handle_t *handle, struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) int ret, no_expand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) ext4_write_lock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) ret = ext4_destroy_inline_data_nolock(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) ext4_write_unlock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) int ext4_inline_data_iomap(struct inode *inode, struct iomap *iomap)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) __u64 addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) int error = -EAGAIN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) down_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) if (!ext4_has_inline_data(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) error = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) addr = (__u64)iloc.bh->b_blocknr << inode->i_sb->s_blocksize_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) addr += (char *)ext4_raw_inode(&iloc) - iloc.bh->b_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) addr += offsetof(struct ext4_inode, i_block);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) iomap->addr = addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) iomap->offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) iomap->length = min_t(loff_t, ext4_get_inline_size(inode),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) i_size_read(inode));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) iomap->type = IOMAP_INLINE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) iomap->flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) up_read(&EXT4_I(inode)->xattr_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) int ext4_inline_data_truncate(struct inode *inode, int *has_inline)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) int inline_size, value_len, needed_blocks, no_expand, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) size_t i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) void *value = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) struct ext4_xattr_ibody_find is = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) .s = { .not_found = -ENODATA, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) struct ext4_xattr_info i = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) .name_index = EXT4_XATTR_INDEX_SYSTEM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) .name = EXT4_XATTR_SYSTEM_DATA,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) needed_blocks = ext4_writepage_trans_blocks(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) handle = ext4_journal_start(inode, EXT4_HT_INODE, needed_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) if (IS_ERR(handle))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) return PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) ext4_write_lock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) if (!ext4_has_inline_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) ext4_write_unlock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) *has_inline = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) if ((err = ext4_orphan_add(handle, inode)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) if ((err = ext4_get_inode_loc(inode, &is.iloc)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) down_write(&EXT4_I(inode)->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) i_size = inode->i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) inline_size = ext4_get_inline_size(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) EXT4_I(inode)->i_disksize = i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) if (i_size < inline_size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) /* Clear the content in the xattr space. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) if (inline_size > EXT4_MIN_INLINE_DATA_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) if ((err = ext4_xattr_ibody_find(inode, &i, &is)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) BUG_ON(is.s.not_found);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) value_len = le32_to_cpu(is.s.here->e_value_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) value = kmalloc(value_len, GFP_NOFS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) if (!value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) err = ext4_xattr_ibody_get(inode, i.name_index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) i.name, value, value_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) if (err <= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) i.value = value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) i.value_len = i_size > EXT4_MIN_INLINE_DATA_SIZE ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) i_size - EXT4_MIN_INLINE_DATA_SIZE : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) err = ext4_xattr_ibody_inline_set(handle, inode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) &i, &is);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) goto out_error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) /* Clear the content within i_blocks. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) if (i_size < EXT4_MIN_INLINE_DATA_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) void *p = (void *) ext4_raw_inode(&is.iloc)->i_block;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) memset(p + i_size, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) EXT4_MIN_INLINE_DATA_SIZE - i_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) EXT4_I(inode)->i_inline_size = i_size <
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) EXT4_MIN_INLINE_DATA_SIZE ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) EXT4_MIN_INLINE_DATA_SIZE : i_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) out_error:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) up_write(&EXT4_I(inode)->i_data_sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) brelse(is.iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) ext4_write_unlock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) kfree(value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) if (inode->i_nlink)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) ext4_orphan_del(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) if (err == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) inode->i_mtime = inode->i_ctime = current_time(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) err = ext4_mark_inode_dirty(handle, inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) if (IS_SYNC(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) ext4_handle_sync(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) int ext4_convert_inline_data(struct inode *inode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) int error, needed_blocks, no_expand;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) handle_t *handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) struct ext4_iloc iloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) if (!ext4_has_inline_data(inode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) needed_blocks = ext4_writepage_trans_blocks(inode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) iloc.bh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) error = ext4_get_inode_loc(inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) if (IS_ERR(handle)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) error = PTR_ERR(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) goto out_free;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) ext4_write_lock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) if (ext4_has_inline_data(inode))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) error = ext4_convert_inline_data_nolock(handle, inode, &iloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) ext4_write_unlock_xattr(inode, &no_expand);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) ext4_journal_stop(handle);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) out_free:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) brelse(iloc.bh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) }