Lines Matching +full:key +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0
31 * has a lot of careful code around i_size and it seems better to make a new key
40 * fs verity items are stored under two different key types on disk.
55 * starting at offset 0 for this key type. These are also opaque to btrfs,
59 * linearly with the size of the file (with 4K pages/blocks and SHA-256, it's
61 * operation. For that reason, we guard the whole enable verity operation
76 * fs-verity, it is convenient to do size computations in terms of a file
87 u64 sz = inode->i_size; in merkle_file_pos()
90 if (rounded > inode->i_sb->s_maxbytes) in merkle_file_pos()
91 return -EFBIG; in merkle_file_pos()
103 * Before doing a verity enable we cleanup any existing verity items.
104 * This is also used to clean up if a verity enable failed half way through.
111 struct btrfs_root *root = inode->root; in drop_verity_items()
113 struct btrfs_key key; in drop_verity_items() local
119 return -ENOMEM; in drop_verity_items()
131 * isn't from our key type or objectid in drop_verity_items()
133 key.objectid = btrfs_ino(inode); in drop_verity_items()
134 key.type = key_type; in drop_verity_items()
135 key.offset = (u64)-1; in drop_verity_items()
137 ret = btrfs_search_slot(trans, root, &key, path, -1, 1); in drop_verity_items()
141 if (path->slots[0] == 0) in drop_verity_items()
143 path->slots[0]--; in drop_verity_items()
149 btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); in drop_verity_items()
152 if (key.objectid != btrfs_ino(inode) || key.type != key_type) in drop_verity_items()
161 ret = btrfs_del_items(trans, root, path, path->slots[0], 1); in drop_verity_items()
202 * Insert and write inode items with a given key type and offset.
205 * @key_type: key type to insert
211 * The inserted items will have key (ino, key_type, offset + off) where off is
221 struct btrfs_root *root = inode->root; in write_key_bytes()
223 struct btrfs_key key; in write_key_bytes() local
231 return -ENOMEM; in write_key_bytes()
241 key.objectid = btrfs_ino(inode); in write_key_bytes()
242 key.type = key_type; in write_key_bytes()
243 key.offset = offset; in write_key_bytes()
251 ret = btrfs_insert_empty_item(trans, root, path, &key, copy_bytes); in write_key_bytes()
257 leaf = path->nodes[0]; in write_key_bytes()
259 data = btrfs_item_ptr(leaf, path->slots[0], void); in write_key_bytes()
264 len -= copy_bytes; in write_key_bytes()
275 * Read inode items of the given key type and offset from the btree.
278 * @key_type: key type to read
284 * page and ignore dest, but it must still be non-NULL to avoid the
285 * counting-only behavior.
300 struct btrfs_root *root = inode->root; in read_key_bytes()
302 struct btrfs_key key; in read_key_bytes() local
315 return -ENOMEM; in read_key_bytes()
318 path->reada = READA_FORWARD; in read_key_bytes()
320 key.objectid = btrfs_ino(inode); in read_key_bytes()
321 key.type = key_type; in read_key_bytes()
322 key.offset = offset; in read_key_bytes()
324 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); in read_key_bytes()
329 if (path->slots[0] == 0) in read_key_bytes()
331 path->slots[0]--; in read_key_bytes()
335 leaf = path->nodes[0]; in read_key_bytes()
336 btrfs_item_key_to_cpu(leaf, &key, path->slots[0]); in read_key_bytes()
338 if (key.objectid != btrfs_ino(inode) || key.type != key_type) in read_key_bytes()
341 item_end = btrfs_item_size(leaf, path->slots[0]) + key.offset; in read_key_bytes()
348 if (key.offset != offset) in read_key_bytes()
355 if (key.offset > offset) in read_key_bytes()
368 copy_bytes = copy_end - offset; in read_key_bytes()
371 copy_offset = offset - key.offset; in read_key_bytes()
377 data = btrfs_item_ptr(leaf, path->slots[0], void); in read_key_bytes()
388 len -= copy_bytes; in read_key_bytes()
391 path->slots[0]++; in read_key_bytes()
392 if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) { in read_key_bytes()
427 struct btrfs_root *root = inode->root; in del_orphan()
437 if (!inode->vfs_inode.i_nlink) in del_orphan()
441 if (ret == -ENOENT) in del_orphan()
447 * Rollback in-progress verity if we encounter an error.
460 struct btrfs_root *root = inode->root; in rollback_verity()
464 truncate_inode_pages(inode->vfs_inode.i_mapping, inode->vfs_inode.i_size); in rollback_verity()
465 clear_bit(BTRFS_INODE_VERITY_IN_PROGRESS, &inode->runtime_flags); in rollback_verity()
468 btrfs_handle_fs_error(root->fs_info, ret, in rollback_verity()
470 (u64)inode->vfs_inode.i_ino); in rollback_verity()
482 btrfs_handle_fs_error(root->fs_info, ret, in rollback_verity()
484 (u64)inode->vfs_inode.i_ino); in rollback_verity()
487 inode->ro_flags &= ~BTRFS_INODE_RO_VERITY; in rollback_verity()
488 btrfs_sync_inode_flags_to_i_flags(&inode->vfs_inode); in rollback_verity()
515 * - write out the descriptor items
516 * - mark the inode with the verity flag
517 * - delete the orphan item
518 * - mark the ro compat bit
519 * - clear the in progress bit
527 struct btrfs_root *root = inode->root; in finish_verity()
554 inode->ro_flags |= BTRFS_INODE_RO_VERITY; in finish_verity()
555 btrfs_sync_inode_flags_to_i_flags(&inode->vfs_inode); in finish_verity()
562 clear_bit(BTRFS_INODE_VERITY_IN_PROGRESS, &inode->runtime_flags); in finish_verity()
563 btrfs_set_fs_compat_ro(root->fs_info, VERITY); in finish_verity()
574 * @filp: file to enable verity on
584 struct btrfs_root *root = inode->root; in btrfs_begin_enable_verity()
590 if (test_bit(BTRFS_INODE_VERITY_IN_PROGRESS, &inode->runtime_flags)) in btrfs_begin_enable_verity()
591 return -EBUSY; in btrfs_begin_enable_verity()
595 * possible that we failed to enable verity on a file, then were in btrfs_begin_enable_verity()
597 * orphan, and finally attempt to enable verity again. in btrfs_begin_enable_verity()
610 set_bit(BTRFS_INODE_VERITY_IN_PROGRESS, &inode->runtime_flags); in btrfs_begin_enable_verity()
625 * enable, and we should try to rollback. Otherwise, attempt to finish verity.
649 btrfs_err(inode->root->fs_info, in btrfs_end_enable_verity()
680 return -EUCLEAN; in btrfs_get_verity_descriptor()
684 return -EUCLEAN; in btrfs_get_verity_descriptor()
689 return -ERANGE; in btrfs_get_verity_descriptor()
696 return -EIO; in btrfs_get_verity_descriptor()
724 if (merkle_pos > inode->i_sb->s_maxbytes - off - PAGE_SIZE) in btrfs_read_merkle_tree_page()
725 return ERR_PTR(-EFBIG); in btrfs_read_merkle_tree_page()
728 folio = __filemap_get_folio(inode->i_mapping, index, FGP_ACCESSED, 0); in btrfs_read_merkle_tree_page()
738 return ERR_PTR(-EIO); in btrfs_read_merkle_tree_page()
744 folio = filemap_alloc_folio(mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS), in btrfs_read_merkle_tree_page()
747 return ERR_PTR(-ENOMEM); in btrfs_read_merkle_tree_page()
749 ret = filemap_add_folio(inode->i_mapping, folio, index, GFP_NOFS); in btrfs_read_merkle_tree_page()
753 if (ret == -EEXIST) in btrfs_read_merkle_tree_page()
797 if (merkle_pos > inode->i_sb->s_maxbytes - pos - size) in btrfs_write_merkle_tree_block()
798 return -EFBIG; in btrfs_write_merkle_tree_block()