本文整理汇总了C++中btrfs_free_path函数的典型用法代码示例。如果您正苦于以下问题:C++ btrfs_free_path函数的具体用法?C++ btrfs_free_path怎么用?C++ btrfs_free_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了btrfs_free_path函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: btrfs_insert_file_extent
int btrfs_insert_file_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 objectid, u64 pos,
u64 disk_offset, u64 disk_num_bytes,
u64 num_bytes, u64 offset, u64 ram_bytes,
u8 compression, u8 encryption, u16 other_encoding)
{
int ret = 0;
struct btrfs_file_extent_item *item;
struct btrfs_key file_key;
struct btrfs_path *path;
struct extent_buffer *leaf;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
file_key.objectid = objectid;
file_key.offset = pos;
btrfs_set_key_type(&file_key, BTRFS_EXTENT_DATA_KEY);
path->leave_spinning = 1;
ret = btrfs_insert_empty_item(trans, root, path, &file_key,
sizeof(*item));
if (ret < 0)
goto out;
BUG_ON(ret); /* Can't happen */
leaf = path->nodes[0];
item = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item);
btrfs_set_file_extent_disk_bytenr(leaf, item, disk_offset);
btrfs_set_file_extent_disk_num_bytes(leaf, item, disk_num_bytes);
btrfs_set_file_extent_offset(leaf, item, offset);
btrfs_set_file_extent_num_bytes(leaf, item, num_bytes);
btrfs_set_file_extent_ram_bytes(leaf, item, ram_bytes);
btrfs_set_file_extent_generation(leaf, item, trans->transid);
btrfs_set_file_extent_type(leaf, item, BTRFS_FILE_EXTENT_REG);
btrfs_set_file_extent_compression(leaf, item, compression);
btrfs_set_file_extent_encryption(leaf, item, encryption);
btrfs_set_file_extent_other_encoding(leaf, item, other_encoding);
btrfs_mark_buffer_dirty(leaf);
out:
btrfs_free_path(path);
return ret;
}
示例2: btrfs_insert_inline_extent
int btrfs_insert_inline_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 objectid,
u64 offset, char *buffer, size_t size)
{
struct btrfs_key key;
struct btrfs_path *path;
struct extent_buffer *leaf;
unsigned long ptr;
struct btrfs_file_extent_item *ei;
u32 datasize;
int err = 0;
int ret;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
key.objectid = objectid;
key.offset = offset;
btrfs_set_key_type(&key, BTRFS_EXTENT_DATA_KEY);
datasize = btrfs_file_extent_calc_inline_size(size);
ret = btrfs_insert_empty_item(trans, root, path, &key, datasize);
if (ret) {
err = ret;
goto fail;
}
leaf = path->nodes[0];
ei = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item);
btrfs_set_file_extent_generation(leaf, ei, trans->transid);
btrfs_set_file_extent_type(leaf, ei, BTRFS_FILE_EXTENT_INLINE);
btrfs_set_file_extent_ram_bytes(leaf, ei, size);
btrfs_set_file_extent_compression(leaf, ei, 0);
btrfs_set_file_extent_encryption(leaf, ei, 0);
btrfs_set_file_extent_other_encoding(leaf, ei, 0);
ptr = btrfs_file_extent_inline_start(ei) + offset - key.offset;
write_extent_buffer(leaf, buffer, ptr, size);
btrfs_mark_buffer_dirty(leaf);
fail:
btrfs_free_path(path);
return err;
}
示例3: btrfs_find_last_root
/*
* lookup the root with the highest offset for a given objectid. The key we do
* find is copied into 'key'. If we find something return 0, otherwise 1, < 0
* on error.
*/
int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
struct btrfs_root_item *item, struct btrfs_key *key)
{
struct btrfs_path *path;
struct btrfs_key search_key;
struct btrfs_key found_key;
struct extent_buffer *l;
int ret;
int slot;
search_key.objectid = objectid;
search_key.type = BTRFS_ROOT_ITEM_KEY;
search_key.offset = (u64)-1;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
if (ret < 0)
goto out;
BUG_ON(ret == 0);
if (path->slots[0] == 0) {
ret = 1;
goto out;
}
l = path->nodes[0];
slot = path->slots[0] - 1;
btrfs_item_key_to_cpu(l, &found_key, slot);
if (found_key.objectid != objectid ||
found_key.type != BTRFS_ROOT_ITEM_KEY) {
ret = 1;
goto out;
}
if (item)
read_extent_buffer(l, item, btrfs_item_ptr_offset(l, slot),
sizeof(*item));
if (key)
memcpy(key, &found_key, sizeof(found_key));
ret = 0;
out:
btrfs_free_path(path);
return ret;
}
示例4: btrfs_dedup_resume
int btrfs_dedup_resume(struct btrfs_fs_info *fs_info,
struct btrfs_root *dedup_root)
{
struct btrfs_dedup_status_item *status;
struct btrfs_key key;
struct btrfs_path *path;
u64 blocksize;
u64 limit;
u16 type;
u16 backend;
int ret = 0;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
key.objectid = 0;
key.type = BTRFS_DEDUP_STATUS_ITEM_KEY;
key.offset = 0;
ret = btrfs_search_slot(NULL, dedup_root, &key, path, 0, 0);
if (ret > 0) {
ret = -ENOENT;
goto out;
} else if (ret < 0) {
goto out;
}
status = btrfs_item_ptr(path->nodes[0], path->slots[0],
struct btrfs_dedup_status_item);
blocksize = btrfs_dedup_status_blocksize(path->nodes[0], status);
limit = btrfs_dedup_status_limit(path->nodes[0], status);
type = btrfs_dedup_status_hash_type(path->nodes[0], status);
backend = btrfs_dedup_status_backend(path->nodes[0], status);
ret = init_dedup_info(fs_info, type, backend, blocksize, limit);
if (ret < 0)
goto out;
fs_info->dedup_info->dedup_root = dedup_root;
out:
btrfs_free_path(path);
return ret;
}
示例5: btrfs_find_orphan_item
int btrfs_find_orphan_item(struct btrfs_root *root, u64 offset)
{
struct btrfs_path *path;
struct btrfs_key key;
int ret;
key.objectid = BTRFS_ORPHAN_OBJECTID;
key.type = BTRFS_ORPHAN_ITEM_KEY;
key.offset = offset;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
btrfs_free_path(path);
return ret;
}
示例6: btrfs_insert_orphan_item
int btrfs_insert_orphan_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 offset)
{
struct btrfs_path *path;
struct btrfs_key key;
int ret = 0;
key.objectid = BTRFS_ORPHAN_OBJECTID;
btrfs_set_key_type(&key, BTRFS_ORPHAN_ITEM_KEY);
key.offset = offset;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
ret = btrfs_insert_empty_item(trans, root, path, &key, 0);
btrfs_free_path(path);
return ret;
}
示例7: clear_free_space_tree
static int clear_free_space_tree(struct btrfs_trans_handle *trans,
struct btrfs_root *root)
{
struct btrfs_path *path;
struct btrfs_key key;
int nr;
int ret;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
path->leave_spinning = 1;
key.objectid = 0;
key.type = 0;
key.offset = 0;
while (1) {
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
if (ret < 0)
goto out;
nr = btrfs_header_nritems(path->nodes[0]);
if (!nr)
break;
path->slots[0] = 0;
ret = btrfs_del_items(trans, root, path, 0, nr);
if (ret)
goto out;
btrfs_release_path(path);
}
ret = 0;
out:
btrfs_free_path(path);
return ret;
}
示例8: btrfs_search_root
/*
* search forward for a root, starting with objectid 'search_start'
* if a root key is found, the objectid we find is filled into 'found_objectid'
* and 0 is returned. < 0 is returned on error, 1 if there is nothing
* left in the tree.
*/
int btrfs_search_root(struct btrfs_root *root, u64 search_start,
u64 *found_objectid)
{
struct btrfs_path *path;
struct btrfs_key search_key;
int ret;
root = root->fs_info->tree_root;
search_key.objectid = search_start;
search_key.type = (u8)-1;
search_key.offset = (u64)-1;
path = btrfs_alloc_path();
BUG_ON(!path);
again:
ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
if (ret < 0)
goto out;
if (ret == 0) {
ret = 1;
goto out;
}
if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
ret = btrfs_next_leaf(root, path);
if (ret)
goto out;
}
btrfs_item_key_to_cpu(path->nodes[0], &search_key, path->slots[0]);
if (search_key.type != BTRFS_ROOT_ITEM_KEY) {
search_key.offset++;
btrfs_release_path(root, path);
goto again;
}
ret = 0;
*found_objectid = search_key.objectid;
out:
btrfs_free_path(path);
return ret;
}
示例9: btrfs_del_root
/* drop the root item for 'key' from 'root' */
int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_key *key)
{
struct btrfs_path *path;
int ret;
u32 refs;
struct btrfs_root_item *ri;
struct extent_buffer *leaf;
path = btrfs_alloc_path();
BUG_ON(!path);
ret = btrfs_search_slot(trans, root, key, path, -1, 1);
if (ret < 0)
goto out;
BUG_ON(ret != 0);
leaf = path->nodes[0];
ri = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_item);
refs = btrfs_disk_root_refs(leaf, ri);
BUG_ON(refs != 0);
ret = btrfs_del_item(trans, root, path);
out:
btrfs_release_path(root, path);
btrfs_free_path(path);
return ret;
}
#if 0 /* this will get used when snapshot deletion is implemented */
int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *tree_root,
u64 root_id, u8 type, u64 ref_id)
{
struct btrfs_key key;
int ret;
struct btrfs_path *path;
path = btrfs_alloc_path();
key.objectid = root_id;
key.type = type;
key.offset = ref_id;
ret = btrfs_search_slot(trans, tree_root, &key, path, -1, 1);
BUG_ON(ret);
ret = btrfs_del_item(trans, tree_root, path);
BUG_ON(ret);
btrfs_free_path(path);
return ret;
}
示例10: btrfs_del_root
/* drop the root item for 'key' from 'root' */
int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_key *key)
{
struct btrfs_path *path;
int ret;
struct btrfs_root_item *ri;
struct extent_buffer *leaf;
path = btrfs_alloc_path();
BUG_ON(!path);
ret = btrfs_search_slot(trans, root, key, path, -1, 1);
if (ret < 0)
goto out;
BUG_ON(ret != 0);
leaf = path->nodes[0];
ri = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_item);
ret = btrfs_del_item(trans, root, path);
out:
btrfs_free_path(path);
return ret;
}
示例11: btrfs_update_root
/*
* copy the data in 'item' into the btree
*/
int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
*root, struct btrfs_key *key, struct btrfs_root_item
*item)
{
struct btrfs_path *path;
struct extent_buffer *l;
int ret;
int slot;
unsigned long ptr;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
ret = btrfs_search_slot(trans, root, key, path, 0, 1);
if (ret < 0) {
btrfs_abort_transaction(trans, root, ret);
goto out;
}
if (ret != 0) {
btrfs_print_leaf(root, path->nodes[0]);
printk(KERN_CRIT "unable to update root key %llu %u %llu\n",
(unsigned long long)key->objectid, key->type,
(unsigned long long)key->offset);
BUG_ON(1);
}
l = path->nodes[0];
slot = path->slots[0];
ptr = btrfs_item_ptr_offset(l, slot);
write_extent_buffer(l, item, ptr, sizeof(*item));
btrfs_mark_buffer_dirty(path->nodes[0]);
out:
btrfs_free_path(path);
return ret;
}
示例12: btrfs_add_root_ref
/*
* add a btrfs_root_ref item. type is either BTRFS_ROOT_REF_KEY
* or BTRFS_ROOT_BACKREF_KEY.
*
* The dirid, sequence, name and name_len refer to the directory entry
* that is referencing the root.
*
* For a forward ref, the root_id is the id of the tree referencing
* the root and ref_id is the id of the subvol or snapshot.
*
* For a back ref the root_id is the id of the subvol or snapshot and
* ref_id is the id of the tree referencing it.
*/
int btrfs_add_root_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *tree_root,
u64 root_id, u8 type, u64 ref_id,
u64 dirid, u64 sequence,
const char *name, int name_len)
{
struct btrfs_key key;
int ret;
struct btrfs_path *path;
struct btrfs_root_ref *ref;
struct extent_buffer *leaf;
unsigned long ptr;
path = btrfs_alloc_path();
key.objectid = root_id;
key.type = type;
key.offset = ref_id;
ret = btrfs_insert_empty_item(trans, tree_root, path, &key,
sizeof(*ref) + name_len);
BUG_ON(ret);
leaf = path->nodes[0];
ref = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_root_ref);
btrfs_set_root_ref_dirid(leaf, ref, dirid);
btrfs_set_root_ref_sequence(leaf, ref, sequence);
btrfs_set_root_ref_name_len(leaf, ref, name_len);
ptr = (unsigned long)(ref + 1);
write_extent_buffer(leaf, name, ptr, name_len);
btrfs_mark_buffer_dirty(leaf);
btrfs_free_path(path);
return ret;
}
示例13: remove_from_free_space_tree
int remove_from_free_space_tree(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info,
u64 start, u64 size)
{
struct btrfs_block_group_cache *block_group;
struct btrfs_path *path;
int ret;
if (!btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE))
return 0;
path = btrfs_alloc_path();
if (!path) {
ret = -ENOMEM;
goto out;
}
block_group = btrfs_lookup_block_group(fs_info, start);
if (!block_group) {
ASSERT(0);
ret = -ENOENT;
goto out;
}
mutex_lock(&block_group->free_space_lock);
ret = __remove_from_free_space_tree(trans, fs_info, block_group, path,
start, size);
mutex_unlock(&block_group->free_space_lock);
btrfs_put_block_group(block_group);
out:
btrfs_free_path(path);
if (ret)
btrfs_abort_transaction(trans, ret);
return ret;
}
示例14: btrfs_punch_hole
/*
* Punch hole ranged [offset,len) for the file given by ino and root.
*
* Unlink kernel punch_hole, which will not zero/free existing extent,
* instead it will return -EEXIST if there is any extents in the hole
* range.
*/
int btrfs_punch_hole(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 ino, u64 offset, u64 len)
{
struct btrfs_path *path;
int ret = 0;
path = btrfs_alloc_path();
if (!path)
return -ENOMEM;
ret = btrfs_get_extent(NULL, root, path, ino, offset, len, 0);
if (ret < 0)
goto out;
if (ret == 0) {
ret = -EEXIST;
goto out;
}
ret = btrfs_insert_file_extent(trans, root, ino, offset, 0, 0, len);
out:
btrfs_free_path(path);
return ret;
}
示例15: btrfs_dedup_enable
int btrfs_dedup_enable(struct btrfs_fs_info *fs_info, u16 type, u16 backend,
u64 blocksize, u64 limit)
{
struct btrfs_dedup_info *dedup_info;
struct btrfs_root *dedup_root;
struct btrfs_key key;
struct btrfs_trans_handle *trans;
struct btrfs_path *path;
struct btrfs_dedup_status_item *status;
int create_tree;
u64 compat_ro_flag = btrfs_super_compat_ro_flags(fs_info->super_copy);
int ret = 0;
/* Sanity check */
if (blocksize > BTRFS_DEDUP_BLOCKSIZE_MAX ||
blocksize < BTRFS_DEDUP_BLOCKSIZE_MIN ||
blocksize < fs_info->tree_root->sectorsize ||
!is_power_of_2(blocksize))
return -EINVAL;
if (type > ARRAY_SIZE(btrfs_dedup_sizes))
return -EINVAL;
if (backend >= BTRFS_DEDUP_BACKEND_LAST)
return -EINVAL;
if (backend == BTRFS_DEDUP_BACKEND_INMEMORY && limit == 0)
limit = 4096; /* default value */
if (backend == BTRFS_DEDUP_BACKEND_ONDISK && limit != 0)
limit = 0;
/*
* If current fs doesn't support DEDUP feature, don't enable
* on-disk dedup.
*/
if (!(compat_ro_flag & BTRFS_FEATURE_COMPAT_RO_DEDUP) &&
backend == BTRFS_DEDUP_BACKEND_ONDISK)
return -EINVAL;
/* Meaningless and unable to enable dedup for RO fs */
if (fs_info->sb->s_flags & MS_RDONLY)
return -EINVAL;
if (fs_info->dedup_info) {
dedup_info = fs_info->dedup_info;
/* Check if we are re-enable for different dedup config */
if (dedup_info->blocksize != blocksize ||
dedup_info->hash_type != type ||
dedup_info->backend != backend) {
btrfs_dedup_disable(fs_info);
goto enable;
}
/* On-fly limit change is OK */
mutex_lock(&dedup_info->lock);
fs_info->dedup_info->limit_nr = limit;
mutex_unlock(&dedup_info->lock);
return 0;
}
enable:
create_tree = compat_ro_flag & BTRFS_FEATURE_COMPAT_RO_DEDUP;
ret = init_dedup_info(fs_info, type, backend, blocksize, limit);
dedup_info = fs_info->dedup_info;
if (ret < 0)
goto out;
if (!create_tree)
goto out;
/* Create dedup tree for status at least */
path = btrfs_alloc_path();
if (!path) {
ret = -ENOMEM;
goto out;
}
trans = btrfs_start_transaction(fs_info->tree_root, 2);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
btrfs_free_path(path);
goto out;
}
dedup_root = btrfs_create_tree(trans, fs_info,
BTRFS_DEDUP_TREE_OBJECTID);
if (IS_ERR(dedup_root)) {
ret = PTR_ERR(dedup_root);
btrfs_abort_transaction(trans, fs_info->tree_root, ret);
btrfs_free_path(path);
goto out;
}
dedup_info->dedup_root = dedup_root;
key.objectid = 0;
key.type = BTRFS_DEDUP_STATUS_ITEM_KEY;
key.offset = 0;
ret = btrfs_insert_empty_item(trans, dedup_root, path, &key,
sizeof(*status));
//.........这里部分代码省略.........