/* * Check if a property should be ignored (not set) for an inode. * * @inode: The target inode. * @name: The property's name. * * The caller must be sure the given property name is valid, for example by * having previously called btrfs_validate_prop(). * * Returns: true if the property should be ignored for the given inode * false if the property must not be ignored for the given inode
*/ bool btrfs_ignore_prop(conststruct btrfs_inode *inode, constchar *name)
{ conststruct prop_handler *handler;
staticbool prop_compression_ignore(conststruct btrfs_inode *inode)
{ /* * Compression only has effect for regular files, and for directories * we set it just to propagate it to new files created inside them. * Everything else (symlinks, devices, sockets, fifos) is pointless as * it will do nothing, so don't waste metadata space on a compression * xattr for anything that is neither a file nor a directory.
*/ if (!S_ISREG(inode->vfs_inode.i_mode) &&
!S_ISDIR(inode->vfs_inode.i_mode)) returntrue;
returnfalse;
}
staticconstchar *prop_compression_extract(conststruct btrfs_inode *inode)
{ switch (inode->prop_compress) { case BTRFS_COMPRESS_ZLIB: case BTRFS_COMPRESS_LZO: case BTRFS_COMPRESS_ZSTD: return btrfs_compress_type2str(inode->prop_compress); default: break;
}
int btrfs_inode_inherit_props(struct btrfs_trans_handle *trans, struct btrfs_inode *inode, conststruct btrfs_inode *parent)
{ struct btrfs_root *root = inode->root; struct btrfs_fs_info *fs_info = root->fs_info; int ret; int i; bool need_reserve = false;
if (!test_bit(BTRFS_INODE_HAS_PROPS, &parent->runtime_flags)) return 0;
for (i = 0; i < ARRAY_SIZE(prop_handlers); i++) { conststruct prop_handler *h = &prop_handlers[i]; constchar *value;
u64 num_bytes = 0;
if (!h->inheritable) continue;
if (h->ignore(inode)) continue;
value = h->extract(parent); if (!value) continue;
/* * This is not strictly necessary as the property should be * valid, but in case it isn't, don't propagate it further.
*/
ret = h->validate(inode, value, strlen(value)); if (ret) continue;
/* * Currently callers should be reserving 1 item for properties, * since we only have 1 property that we currently support. If * we add more in the future we need to try and reserve more * space for them. But we should also revisit how we do space * reservations if we do add more properties in the future.
*/ if (need_reserve) {
num_bytes = btrfs_calc_insert_metadata_size(fs_info, 1);
ret = btrfs_block_rsv_add(fs_info, trans->block_rsv,
num_bytes,
BTRFS_RESERVE_NO_FLUSH); if (ret) return ret;
}
ret = btrfs_setxattr(trans, &inode->vfs_inode, h->xattr_name, value,
strlen(value), 0); if (!ret) {
ret = h->apply(inode, value, strlen(value)); if (ret)
btrfs_setxattr(trans, &inode->vfs_inode, h->xattr_name,
NULL, 0, 0); else
set_bit(BTRFS_INODE_HAS_PROPS, &inode->runtime_flags);
}
if (need_reserve) {
btrfs_block_rsv_release(fs_info, trans->block_rsv,
num_bytes, NULL); if (ret) return ret;
}
need_reserve = true;
}
return 0;
}
int __init btrfs_props_init(void)
{ int i;
for (i = 0; i < ARRAY_SIZE(prop_handlers); i++) { struct prop_handler *p = &prop_handlers[i];
u64 h = btrfs_name_hash(p->xattr_name, strlen(p->xattr_name));
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.