/* * We need to subtract another sizeof(__u32) since an in-inode xattr * needs an empty 4 bytes to indicate the gap between the xattr entry * and the name/value pair.
*/ if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR)) return EXT4_XATTR_SIZE(min_offs -
EXT4_XATTR_LEN(strlen(EXT4_XATTR_SYSTEM_DATA)) -
EXT4_XATTR_ROUND - sizeof(__u32));
/* * Get the maximum size we now can store in an inode. * If we can't find the space for a xattr entry, don't use the space * of the extents since we have no space to indicate the inline data.
*/ int ext4_get_max_inline_size(struct inode *inode)
{ int error, max_inline_size; struct ext4_iloc iloc;
/* * this function does not take xattr_sem, which is OK because it is * currently only used in a code path coming form ext4_iget, before * the new inode has been unlocked
*/ int ext4_find_inline_data_nolock(struct inode *inode)
{ struct ext4_xattr_ibody_find is = {
.s = { .not_found = -ENODATA, },
}; struct ext4_xattr_info i = {
.name_index = EXT4_XATTR_INDEX_SYSTEM,
.name = EXT4_XATTR_SYSTEM_DATA,
}; int error;
if (EXT4_I(inode)->i_extra_isize == 0) return 0;
error = ext4_get_inode_loc(inode, &is.iloc); if (error) return error;
error = ext4_xattr_ibody_find(inode, &i, &is); if (error) goto out;
/* * write the buffer to the inline inode. * If 'create' is set, we don't need to do the extra copy in the xattr * value since it is already handled by ext4_xattr_ibody_set. * That saves us one memcpy.
*/ staticvoid ext4_write_inline_data(struct inode *inode, struct ext4_iloc *iloc, void *buffer, loff_t pos, unsignedint len)
{ struct ext4_xattr_entry *entry; struct ext4_xattr_ibody_header *header; struct ext4_inode *raw_inode; int cp_len = 0;
if (unlikely(ext4_emergency_state(inode->i_sb))) return;
BUG_ON(!EXT4_I(inode)->i_inline_off);
BUG_ON(pos + len > EXT4_I(inode)->i_inline_size);
int ext4_readpage_inline(struct inode *inode, struct folio *folio)
{ int ret = 0;
down_read(&EXT4_I(inode)->xattr_sem); if (!ext4_has_inline_data(inode)) {
up_read(&EXT4_I(inode)->xattr_sem); return -EAGAIN;
}
/* * Current inline data can only exist in the 1st page, * So for all the other pages, just set them uptodate.
*/ if (!folio->index)
ret = ext4_read_inline_folio(inode, folio); elseif (!folio_test_uptodate(folio)) {
folio_zero_segment(folio, 0, folio_size(folio));
folio_mark_uptodate(folio);
}
if (!ext4_has_inline_data(inode)) { /* * clear the flag so that no new write * will trap here again.
*/
ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA); return 0;
}
ret = ext4_get_inode_loc(inode, &iloc); if (ret) return ret;
retry:
handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks); if (IS_ERR(handle)) {
ret = PTR_ERR(handle);
handle = NULL; goto out;
}
/* We cannot recurse into the filesystem as the transaction is already
* started */
folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN | FGP_NOFS,
mapping_gfp_mask(mapping)); if (IS_ERR(folio)) {
ret = PTR_ERR(folio); goto out_nofolio;
}
ext4_write_lock_xattr(inode, &no_expand);
sem_held = 1; /* If some one has already done this for us, just exit. */ if (!ext4_has_inline_data(inode)) {
ret = 0; goto out;
}
from = 0;
to = ext4_get_inline_size(inode); if (!folio_test_uptodate(folio)) {
ret = ext4_read_inline_folio(inode, folio); if (ret < 0) goto out;
}
ext4_fc_track_inode(handle, inode);
ret = ext4_destroy_inline_data_nolock(handle, inode); if (ret) goto out;
if (ext4_should_dioread_nolock(inode)) {
ret = ext4_block_write_begin(handle, folio, from, to,
ext4_get_block_unwritten);
} else
ret = ext4_block_write_begin(handle, folio, from, to,
ext4_get_block);
clear_buffer_new(folio_buffers(folio));
if (!ret && ext4_should_journal_data(inode)) {
ret = ext4_walk_page_buffers(handle, inode,
folio_buffers(folio), from, to,
NULL, do_journal_get_write_access);
}
if (ret) {
folio_unlock(folio);
folio_put(folio);
folio = NULL;
ext4_orphan_add(handle, inode);
ext4_write_unlock_xattr(inode, &no_expand);
sem_held = 0;
ext4_journal_stop(handle);
handle = NULL;
ext4_truncate_failed_write(inode); /* * If truncate failed early the inode might * still be on the orphan list; we need to * make sure the inode is removed from the * orphan list in that case.
*/ if (inode->i_nlink)
ext4_orphan_del(NULL, inode);
}
if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries)) goto retry;
if (folio)
block_commit_write(folio, from, to);
out: if (folio) {
folio_unlock(folio);
folio_put(folio);
}
out_nofolio: if (sem_held)
ext4_write_unlock_xattr(inode, &no_expand); if (handle)
ext4_journal_stop(handle);
brelse(iloc.bh); return ret;
}
/* * Prepare the write for the inline data. * If the data can be written into the inode, we just read * the page and make it uptodate, and start the journal. * Otherwise read the page, makes it dirty so that it can be * handle in writepages(the i_disksize update is left to the * normal ext4_da_write_end).
*/ int ext4_generic_write_inline_data(struct address_space *mapping, struct inode *inode,
loff_t pos, unsigned len, struct folio **foliop, void **fsdata, bool da)
{ int ret;
handle_t *handle; struct folio *folio; struct ext4_iloc iloc; int retries = 0;
ret = ext4_get_inode_loc(inode, &iloc); if (ret) return ret;
retry_journal:
handle = ext4_journal_start(inode, EXT4_HT_INODE, 1); if (IS_ERR(handle)) {
ret = PTR_ERR(handle); goto out_release_bh;
}
ret = ext4_prepare_inline_data(handle, inode, pos + len); if (ret && ret != -ENOSPC) goto out_stop_journal;
if (ret == -ENOSPC) {
ext4_journal_stop(handle); if (!da) {
brelse(iloc.bh); /* Retry inside */ return ext4_convert_inline_data_to_extent(mapping, inode);
}
ret = ext4_da_convert_inline_data_to_extent(mapping, inode, fsdata); if (ret == -ENOSPC &&
ext4_should_retry_alloc(inode->i_sb, &retries)) goto retry_journal; goto out_release_bh;
}
folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN | FGP_NOFS,
mapping_gfp_mask(mapping)); if (IS_ERR(folio)) {
ret = PTR_ERR(folio); goto out_stop_journal;
}
down_read(&EXT4_I(inode)->xattr_sem); /* Someone else had converted it to extent */ if (!ext4_has_inline_data(inode)) {
ret = 0; goto out_release_folio;
}
if (!folio_test_uptodate(folio)) {
ret = ext4_read_inline_folio(inode, folio); if (ret < 0) goto out_release_folio;
}
ret = ext4_journal_get_write_access(handle, inode->i_sb, iloc.bh, EXT4_JTR_NONE); if (ret) goto out_release_folio;
*foliop = folio;
up_read(&EXT4_I(inode)->xattr_sem);
brelse(iloc.bh); return 1;
/* * Try to write data in the inode. * If the inode has inline data, check whether the new write can be * in the inode also. If not, create the page the handle, move the data * to the page make it update and let the later codes create extent for it.
*/ int ext4_try_to_write_inline_data(struct address_space *mapping, struct inode *inode,
loff_t pos, unsigned len, struct folio **foliop)
{ if (pos + len > ext4_get_max_inline_size(inode)) return ext4_convert_inline_data_to_extent(mapping, inode); return ext4_generic_write_inline_data(mapping, inode, pos, len,
foliop, NULL, false);
}
int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, unsigned copied, struct folio *folio)
{
handle_t *handle = ext4_journal_current_handle(); int no_expand; void *kaddr; struct ext4_iloc iloc; int ret = 0, ret2;
if (unlikely(copied < len) && !folio_test_uptodate(folio))
copied = 0;
if (likely(copied)) {
ret = ext4_get_inode_loc(inode, &iloc); if (ret) {
folio_unlock(folio);
folio_put(folio);
ext4_std_error(inode->i_sb, ret); goto out;
}
ext4_write_lock_xattr(inode, &no_expand);
BUG_ON(!ext4_has_inline_data(inode));
/* * ei->i_inline_off may have changed since * ext4_write_begin() called * ext4_try_to_write_inline_data()
*/
(void) ext4_find_inline_data_nolock(inode);
kaddr = kmap_local_folio(folio, 0);
ext4_write_inline_data(inode, &iloc, kaddr, pos, copied);
kunmap_local(kaddr);
folio_mark_uptodate(folio); /* clear dirty flag so that writepages wouldn't work for us. */
folio_clear_dirty(folio);
/* * It's important to update i_size while still holding folio * lock: page writeout could otherwise come in and zero * beyond i_size.
*/
ext4_update_inode_size(inode, pos + copied);
}
folio_unlock(folio);
folio_put(folio);
/* * Don't mark the inode dirty under folio lock. First, it unnecessarily * makes the holding time of folio lock longer. Second, it forces lock * ordering of folio lock and transaction start for journaling * filesystems.
*/ if (likely(copied))
mark_inode_dirty(inode);
out: /* * If we didn't copy as much data as expected, we need to trim back * size of xattr containing inline data.
*/ if (pos + len > inode->i_size && ext4_can_truncate(inode))
ext4_orphan_add(handle, inode);
ret2 = ext4_journal_stop(handle); if (!ret)
ret = ret2; if (pos + len > inode->i_size) {
ext4_truncate_failed_write(inode); /* * If truncate failed early the inode might still be * on the orphan list; we need to make sure the inode * is removed from the orphan list in that case.
*/ if (inode->i_nlink)
ext4_orphan_del(NULL, inode);
} return ret ? ret : copied;
}
/* * Try to make the page cache and handle ready for the inline data case. * We can call this function in 2 cases: * 1. The inode is created and the first write exceeds inline size. We can * clear the inode state safely. * 2. The inode has inline data, then we need to read the data, make it * update and dirty so that ext4_da_writepages can handle it. We don't * need to start the journal since the file's metadata isn't changed now.
*/ staticint ext4_da_convert_inline_data_to_extent(struct address_space *mapping, struct inode *inode, void **fsdata)
{ int ret = 0, inline_size; struct folio *folio;
folio = __filemap_get_folio(mapping, 0, FGP_WRITEBEGIN,
mapping_gfp_mask(mapping)); if (IS_ERR(folio)) return PTR_ERR(folio);
down_read(&EXT4_I(inode)->xattr_sem); if (!ext4_has_inline_data(inode)) {
ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA); goto out;
}
inline_size = ext4_get_inline_size(inode);
if (!folio_test_uptodate(folio)) {
ret = ext4_read_inline_folio(inode, folio); if (ret < 0) goto out;
}
ret = ext4_block_write_begin(NULL, folio, 0, inline_size,
ext4_da_get_block_prep); if (ret) {
up_read(&EXT4_I(inode)->xattr_sem);
folio_unlock(folio);
folio_put(folio);
ext4_truncate_failed_write(inode); return ret;
}
/* * Add a new entry into a inline dir. * It will return -ENOSPC if no space is available, and -EIO * and -EEXIST if directory entry already exists.
*/ staticint ext4_add_dirent_to_inline(handle_t *handle, struct ext4_filename *fname, struct inode *dir, struct inode *inode, struct ext4_iloc *iloc, void *inline_start, int inline_size)
{ int err; struct ext4_dir_entry_2 *de;
/* * XXX shouldn't update any times until successful * completion of syscall, but too many callers depend * on this. * * XXX similarly, too many callers depend on * ext4_new_inode() setting the times, but error * recovery deletes the inode, so the worst that can * happen is that the times are slightly out of date * and/or different from the directory change time.
*/
inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir));
ext4_update_dx_flag(dir);
inode_inc_iversion(dir); return 1;
}
/* Set the final de to cover the whole block. */ void ext4_update_final_de(void *de_buf, int old_size, int new_size)
{ struct ext4_dir_entry_2 *de, *prev_de; void *limit; int de_len;
de = de_buf; if (old_size) {
limit = de_buf + old_size; do {
prev_de = de;
de_len = ext4_rec_len_from_disk(de->rec_len, old_size);
de_buf += de_len;
de = de_buf;
} while (de_buf < limit);
prev_de->rec_len = ext4_rec_len_to_disk(de_len + new_size -
old_size, new_size);
} else { /* this is just created, so create an empty entry. */
de->inode = 0;
de->rec_len = ext4_rec_len_to_disk(new_size, new_size);
}
}
staticint ext4_update_inline_dir(handle_t *handle, struct inode *dir, struct ext4_iloc *iloc)
{ int ret; int old_size = EXT4_I(dir)->i_inline_size - EXT4_MIN_INLINE_DATA_SIZE; int new_size = get_max_inline_xattr_value_size(dir, iloc);
if (new_size - old_size <= ext4_dir_rec_len(1, NULL)) return -ENOSPC;
ret = ext4_update_inline_data(handle, dir,
new_size + EXT4_MIN_INLINE_DATA_SIZE); if (ret) return ret;
/* * Make sure the inline directory entries pass checks before we try to * convert them, so that we avoid touching stuff that needs fsck.
*/ if (S_ISDIR(inode->i_mode)) {
error = ext4_check_all_de(inode, iloc->bh,
buf + EXT4_INLINE_DOTDOT_SIZE,
inline_size - EXT4_INLINE_DOTDOT_SIZE); if (error) goto out;
}
error = ext4_destroy_inline_data_nolock(handle, inode); if (error) goto out;
out_restore: if (error)
ext4_restore_inline_data(handle, inode, iloc, buf, inline_size);
out:
brelse(data_bh);
kfree(buf); return error;
}
/* * Try to add the new entry to the inline data. * If succeeds, return 0. If not, extended the inline dir and copied data to * the new created block.
*/ int ext4_try_add_inline_entry(handle_t *handle, struct ext4_filename *fname, struct inode *dir, struct inode *inode)
{ int ret, ret2, inline_size, no_expand; void *inline_start; struct ext4_iloc iloc;
ret = ext4_get_inode_loc(dir, &iloc); if (ret) return ret;
ext4_write_lock_xattr(dir, &no_expand); if (!ext4_has_inline_data(dir)) goto out;
ret = ext4_add_dirent_to_inline(handle, fname, dir, inode, &iloc,
inline_start, inline_size); if (ret != -ENOSPC) goto out;
/* check whether it can be inserted to inline xattr space. */
inline_size = EXT4_I(dir)->i_inline_size -
EXT4_MIN_INLINE_DATA_SIZE; if (!inline_size) { /* Try to use the xattr space.*/
ret = ext4_update_inline_dir(handle, dir, &iloc); if (ret && ret != -ENOSPC) goto out;
if (inline_size) {
inline_start = ext4_get_inline_xattr_pos(dir, &iloc);
ret = ext4_add_dirent_to_inline(handle, fname, dir,
inode, &iloc, inline_start,
inline_size);
if (ret != -ENOSPC) goto out;
}
/* * The inline space is filled up, so create a new block for it. * As the extent tree will be created, we have to save the inline * dir first.
*/
ret = ext4_convert_inline_data_nolock(handle, dir, &iloc);
out:
ext4_write_unlock_xattr(dir, &no_expand);
ret2 = ext4_mark_inode_dirty(handle, dir); if (unlikely(ret2 && !ret))
ret = ret2;
brelse(iloc.bh); return ret;
}
/* * This function fills a red-black tree with information from an * inlined dir. It returns the number directory entries loaded * into the tree. If there is an error it is returned in err.
*/ int ext4_inlinedir_to_tree(struct file *dir_file, struct inode *dir, ext4_lblk_t block, struct dx_hash_info *hinfo,
__u32 start_hash, __u32 start_minor_hash, int *has_inline_data)
{ int err = 0, count = 0; unsignedint parent_ino; int pos; struct ext4_dir_entry_2 *de; struct inode *inode = file_inode(dir_file); int ret, inline_size = 0; struct ext4_iloc iloc; void *dir_buf = NULL; struct ext4_dir_entry_2 fake; struct fscrypt_str tmp_str;
ret = ext4_get_inode_loc(inode, &iloc); if (ret) return ret;
inline_size = ext4_get_inline_size(inode);
dir_buf = kmalloc(inline_size, GFP_NOFS); if (!dir_buf) {
ret = -ENOMEM;
up_read(&EXT4_I(inode)->xattr_sem); goto out;
}
ret = ext4_read_inline_data(inode, dir_buf, inline_size, &iloc);
up_read(&EXT4_I(inode)->xattr_sem); if (ret < 0) goto out;
pos = 0;
parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode); while (pos < inline_size) { /* * As inlined dir doesn't store any information about '.' and * only the inode number of '..' is stored, we have to handle * them differently.
*/ if (pos == 0) {
fake.inode = cpu_to_le32(inode->i_ino);
fake.name_len = 1;
memcpy(fake.name, ".", 2);
fake.rec_len = ext4_rec_len_to_disk(
ext4_dir_rec_len(fake.name_len, NULL),
inline_size);
ext4_set_de_type(inode->i_sb, &fake, S_IFDIR);
de = &fake;
pos = EXT4_INLINE_DOTDOT_OFFSET;
} elseif (pos == EXT4_INLINE_DOTDOT_OFFSET) {
fake.inode = cpu_to_le32(parent_ino);
fake.name_len = 2;
memcpy(fake.name, "..", 3);
fake.rec_len = ext4_rec_len_to_disk(
ext4_dir_rec_len(fake.name_len, NULL),
inline_size);
ext4_set_de_type(inode->i_sb, &fake, S_IFDIR);
de = &fake;
pos = EXT4_INLINE_DOTDOT_SIZE;
} else {
de = (struct ext4_dir_entry_2 *)(dir_buf + pos);
pos += ext4_rec_len_from_disk(de->rec_len, inline_size); if (ext4_check_dir_entry(inode, dir_file, de,
iloc.bh, dir_buf,
inline_size, pos)) {
ret = count; goto out;
}
}
if (ext4_hash_in_dirent(dir)) {
hinfo->hash = EXT4_DIRENT_HASH(de);
hinfo->minor_hash = EXT4_DIRENT_MINOR_HASH(de);
} else {
err = ext4fs_dirhash(dir, de->name, de->name_len, hinfo); if (err) {
ret = err; goto out;
}
} if ((hinfo->hash < start_hash) ||
((hinfo->hash == start_hash) &&
(hinfo->minor_hash < start_minor_hash))) continue; if (de->inode == 0) continue;
tmp_str.name = de->name;
tmp_str.len = de->name_len;
err = ext4_htree_store_dirent(dir_file, hinfo->hash,
hinfo->minor_hash, de, &tmp_str); if (err) {
ret = err; goto out;
}
count++;
}
ret = count;
out:
kfree(dir_buf);
brelse(iloc.bh); return ret;
}
/* * So this function is called when the volume is mkfsed with * dir_index disabled. In order to keep f_pos persistent * after we convert from an inlined dir to a blocked based, * we just pretend that we are a normal dir and return the * offset as if '.' and '..' really take place. *
*/ int ext4_read_inline_dir(struct file *file, struct dir_context *ctx, int *has_inline_data)
{ unsignedint offset, parent_ino; int i; struct ext4_dir_entry_2 *de; struct super_block *sb; struct inode *inode = file_inode(file); int ret, inline_size = 0; struct ext4_iloc iloc; void *dir_buf = NULL; int dotdot_offset, dotdot_size, extra_offset, extra_size; struct dir_private_info *info = file->private_data;
ret = ext4_get_inode_loc(inode, &iloc); if (ret) return ret;
/* * dotdot_offset and dotdot_size is the real offset and * size for ".." and "." if the dir is block based while * the real size for them are only EXT4_INLINE_DOTDOT_SIZE. * So we will use extra_offset and extra_size to indicate them * during the inline dir iteration.
*/
dotdot_offset = ext4_dir_rec_len(1, NULL);
dotdot_size = dotdot_offset + ext4_dir_rec_len(2, NULL);
extra_offset = dotdot_size - EXT4_INLINE_DOTDOT_SIZE;
extra_size = extra_offset + inline_size;
/* * If the cookie has changed since the last call to * readdir(2), then we might be pointing to an invalid * dirent right now. Scan from the start of the inline * dir to make sure.
*/ if (!inode_eq_iversion(inode, info->cookie)) { for (i = 0; i < extra_size && i < offset;) { /* * "." is with offset 0 and * ".." is dotdot_offset.
*/ if (!i) {
i = dotdot_offset; continue;
} elseif (i == dotdot_offset) {
i = dotdot_size; continue;
} /* for other entry, the real offset in * the buf has to be tuned accordingly.
*/
de = (struct ext4_dir_entry_2 *)
(dir_buf + i - extra_offset); /* It's too expensive to do a full * dirent test each time round this * loop, but we do have to test at * least that it is non-zero. A * failure will be detected in the
* dirent test below. */ if (ext4_rec_len_from_disk(de->rec_len, extra_size)
< ext4_dir_rec_len(1, NULL)) break;
i += ext4_rec_len_from_disk(de->rec_len,
extra_size);
}
offset = i;
ctx->pos = offset;
info->cookie = inode_query_iversion(inode);
}
while (ctx->pos < extra_size) { if (ctx->pos == 0) { if (!dir_emit(ctx, ".", 1, inode->i_ino, DT_DIR)) goto out;
ctx->pos = dotdot_offset; continue;
}
if (ctx->pos == dotdot_offset) { if (!dir_emit(ctx, "..", 2, parent_ino, DT_DIR)) goto out;
ctx->pos = dotdot_size; continue;
}
de = (struct ext4_dir_entry_2 *)
(dir_buf + ctx->pos - extra_offset); if (ext4_check_dir_entry(inode, file, de, iloc.bh, dir_buf,
extra_size, ctx->pos)) goto out; if (le32_to_cpu(de->inode)) { if (!dir_emit(ctx, de->name, de->name_len,
le32_to_cpu(de->inode),
get_dtype(sb, de->file_type))) goto out;
}
ctx->pos += ext4_rec_len_from_disk(de->rec_len, extra_size);
}
out:
kfree(dir_buf);
brelse(iloc.bh); return ret;
}
/* * Try to create the inline data for the new dir. * If it succeeds, return 0, otherwise return the error. * In case of ENOSPC, the caller should create the normal disk layout dir.
*/ int ext4_try_create_inline_dir(handle_t *handle, struct inode *parent, struct inode *inode)
{ int ret, inline_size = EXT4_MIN_INLINE_DATA_SIZE; struct ext4_iloc iloc; struct ext4_dir_entry_2 *de;
ret = ext4_get_inode_loc(inode, &iloc); if (ret) return ret;
ret = ext4_prepare_inline_data(handle, inode, inline_size); if (ret) goto out;
/* * For inline dir, we only save the inode information for the ".." * and create a fake dentry to cover the left space.
*/
de = (struct ext4_dir_entry_2 *)ext4_raw_inode(&iloc)->i_block;
de->inode = cpu_to_le32(parent->i_ino);
de = (struct ext4_dir_entry_2 *)((void *)de + EXT4_INLINE_DOTDOT_SIZE);
de->inode = 0;
de->rec_len = ext4_rec_len_to_disk(
inline_size - EXT4_INLINE_DOTDOT_SIZE,
inline_size);
set_nlink(inode, 2);
inode->i_size = EXT4_I(inode)->i_disksize = inline_size;
out:
brelse(iloc.bh); return ret;
}
struct buffer_head *ext4_find_inline_entry(struct inode *dir, struct ext4_filename *fname, struct ext4_dir_entry_2 **res_dir, int *has_inline_data)
{ struct ext4_xattr_ibody_find is = {
.s = { .not_found = -ENODATA, },
}; struct ext4_xattr_info i = {
.name_index = EXT4_XATTR_INDEX_SYSTEM,
.name = EXT4_XATTR_SYSTEM_DATA,
}; int ret; void *inline_start; int inline_size;
ret = ext4_get_inode_loc(dir, &is.iloc); if (ret) return ERR_PTR(ret);
down_read(&EXT4_I(dir)->xattr_sem);
ret = ext4_xattr_ibody_find(dir, &i, &is); if (ret) goto out;
if (!ext4_has_inline_data(dir)) {
*has_inline_data = 0; goto out;
}
if (i_size < inline_size) { /* * if there's inline data to truncate and this file was * converted to extents after that inline data was written, * the extent status cache must be cleared to avoid leaving * behind stale delayed allocated extent entries
*/ if (!ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA))
ext4_es_remove_extent(inode, 0, EXT_MAX_BLOCKS);
/* Clear the content in the xattr space. */ if (inline_size > EXT4_MIN_INLINE_DATA_SIZE) { if ((err = ext4_xattr_ibody_find(inode, &i, &is)) != 0) goto out_error;
if (is.s.not_found) {
EXT4_ERROR_INODE(inode, "missing inline data xattr");
err = -EFSCORRUPTED; goto out_error;
}
value_len = le32_to_cpu(is.s.here->e_value_size);
value = kmalloc(value_len, GFP_NOFS); if (!value) {
err = -ENOMEM; goto out_error;
}
if (err == 0) {
inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode));
err = ext4_mark_inode_dirty(handle, inode); if (IS_SYNC(inode))
ext4_handle_sync(handle);
}
ext4_journal_stop(handle); return err;
}
int ext4_convert_inline_data(struct inode *inode)
{ int error, needed_blocks, no_expand;
handle_t *handle; struct ext4_iloc iloc;
if (!ext4_has_inline_data(inode)) {
ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA); return 0;
} elseif (!ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { /* * Inode has inline data but EXT4_STATE_MAY_INLINE_DATA is * cleared. This means we are in the middle of moving of * inline data to delay allocated block. Just force writeout * here to finish conversion.
*/
error = filemap_flush(inode->i_mapping); if (error) return error; if (!ext4_has_inline_data(inode)) return 0;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.